caelum0x 03c7e2c397 fix(license): consistent Apache-2.0/MIT split + migrate 3 examples from private audit
- Root LICENSE: replace the short-form notice with the full canonical
  Apache-2.0 text (fixes GitHub's "Other" license detection); update the
  OpenJev -> Umpirix copyright line in LICENSE/NOTICE, otsone/NOTICE and
  sdk/python/LICENSE+NOTICE (missed by the rebrand pass).
- sdk/ai-sdk: was MIT with no LICENSE/NOTICE and no upstream fork trail
  (unlike sdk/js, sdk/python, adapters/python, skills, which are real
  TypeSafe AI SDK forks and correctly keep MIT per their NOTICE). It is
  original Umpirix code, so switch it to Apache-2.0 with its own
  LICENSE/NOTICE, matching the root.
- README Licensing section: list sdk/ai-sdk under Apache-2.0 and
  sdk/scribase-decisions under MIT, and spell out why the TypeSafe-forked
  directories stay MIT (their MIT terms require preserving the notice).
- Audited caelum0x/openjev-private (read-only clone): it's an older,
  mostly-superseded snapshot of this repo. Migrated the 3 self-contained,
  secret-free example scripts it had that this repo didn't (raw-HTTP, no
  SDK dependency): content-moderation, lead-scoring, support-ticket-routing
  (Python + Node.js, each with a sample JSONL), plus
  scripts/reproduce-leaderboard.mjs (wired to a new `npm run
  bench:reproduce`) for leaderboard reproducibility. Left behind in
  private: src/lib/seo/retired.ts (a reversed decision - this repo now has
  live /compare pages) and the hosted-SaaS pieces already superseded by
  this repo's own, newer versions of the same files.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-11-11 19:08:57 +03:00

103 lines
4.5 KiB
TypeScript

// Lead scoring with OpenJev typed decisions.
//
// Each inbound lead (company + message) gets three typed judgments in one request:
// buying stage (score), company segment (choice) and whether it is a real inquiry or
// a vendor pitch (choice). The points formula below is ordinary code, so sales can re-weight it
// without re-running inference, and uncertain leads are flagged for a human look.
//
// npm run dev # in the repo root (or: docker compose up -> port 3000)
// OPENJEV_BASE_URL=http://localhost:8080 node --experimental-strip-types examples/lead-scoring/score.ts
//
// Zero dependencies: Node 22.6+ (built-in fetch and type stripping).
import { readFileSync } from "node:fs";
const BASE_URL = (process.env.OPENJEV_BASE_URL ?? "http://localhost:8080").replace(/\/$/, "");
const MODEL = process.env.OPENJEV_MODEL ?? "system-one";
const KEY = process.env.OPENJEV_API_KEY;
type Lead = { id: string; company: string; message: string; expected: "hot" | "warm" | "cold" | "junk" };
type ChoiceAnswer = { type: "choice"; choice: string; confidence: number; ood: number };
type ScoreAnswer = { type: "score"; score: number; confidence: number; ood: number };
const STAGES = ["just curious", "researching", "evaluating vendors", "ready to buy"];
const QUESTIONS = {
stage: {
type: "score",
instructions: "How close is this lead to buying?",
criteria: STAGES,
},
segment: {
type: "choice",
instructions: "What kind of organisation is this lead from?",
criteria: {
enterprise: "large company, hundreds or thousands of employees, procurement",
smb: "small or mid-sized business, startup, SaaS team",
individual: "hobbyist, indie developer, student, personal email",
},
},
kind: {
type: "choice",
instructions: "What is this inbound message?",
criteria: {
inquiry: "a potential customer asking about our product, pricing, demo, evaluation or use",
vendor_pitch: "someone advertising their own services to us: SEO, outsourcing, developers for hire, marketing",
},
},
} as const;
// Scoring policy: plain code, easy to re-weight.
const SEGMENT_POINTS: Record<string, number> = { enterprise: 30, smb: 20, individual: 0 };
const PITCH_MIN_CONFIDENCE = 0.7; // only a confident "vendor_pitch" marks a lead as junk
const REVIEW_BELOW = 0.7; // uncertain segment or kind -> a person takes a look
function grade(points: number): "hot" | "warm" | "cold" {
if (points >= 70) return "hot";
if (points >= 45) return "warm";
return "cold";
}
async function judge(lead: Lead) {
const state = `Company: ${lead.company}\nMessage: ${lead.message}`;
const res = await fetch(`${BASE_URL}/v1/systemone`, {
method: "POST",
headers: { "content-type": "application/json", ...(KEY ? { authorization: `Bearer ${KEY}` } : {}) },
body: JSON.stringify({ model: MODEL, state, questions: QUESTIONS }),
});
if (!res.ok) throw new Error(`OpenJev ${res.status}: ${await res.text()}`);
return (await res.json()) as {
engine?: { kind: string };
answers: { stage: ScoreAnswer; segment: ChoiceAnswer; kind: ChoiceAnswer };
};
}
const leads: Lead[] = readFileSync(new URL("./leads.jsonl", import.meta.url), "utf8")
.split("\n")
.filter((line) => line.trim())
.map((line) => JSON.parse(line));
let agree = 0;
let engine = "unknown";
const ranked: { lead: Lead; points: number; label: string; review: boolean }[] = [];
for (const lead of leads) {
const { engine: e, answers } = await judge(lead);
engine = e?.kind ?? engine;
const { stage, segment, kind } = answers;
// stage.score is the expected position on the 0..3 scale, so it is already a smooth value.
const stagePoints = (stage.score / (STAGES.length - 1)) * 70;
const points = Math.round(stagePoints + (SEGMENT_POINTS[segment.choice] ?? 0));
const isPitch = kind.choice === "vendor_pitch" && kind.confidence >= PITCH_MIN_CONFIDENCE;
const label = isPitch ? "junk" : grade(points);
const review = segment.confidence < REVIEW_BELOW || kind.confidence < REVIEW_BELOW || stage.ood >= 0.6;
if (label === lead.expected) agree++;
ranked.push({ lead, points: label === "junk" ? -1 : points, label, review });
}
ranked.sort((a, b) => b.points - a.points);
for (const r of ranked) {
console.log(
`${r.lead.id} ${r.label.padEnd(5)} ${String(Math.max(r.points, 0)).padStart(3)} pts ${r.lead.company}` +
(r.review ? " [check by hand]" : "") +
(r.label === r.lead.expected ? "" : ` (labelled ${r.lead.expected})`),
);
}
console.log(`\nengine=${engine} agrees with the hand labels on ${agree}/${leads.length} sample leads`);