{"file":"scripts/autosettle/clef.ts","version":318,"total":45,"from":1,"to":45,"lines":[{"n":1,"text":"// Ask Clef, Cloudflare's decision model on Workers AI, how a hold should be settled (#19). Clef takes Jev's","atom":"a2217","author":"autosettle","version":198},{"n":2,"text":"// System One request (state and typed questions) and answers with a probability per option, so the questions are","atom":"a2217","author":"autosettle","version":198},{"n":3,"text":"// jev.ts's own; it goes through the local Worker (workers-ai/, wrangler dev), which has the AI binding.","atom":"a2217","author":"autosettle","version":198},{"n":4,"text":"","atom":"a2217","author":"autosettle","version":198},{"n":5,"text":"import { type Hold, type SystemOneAnswer, systemOneBody, type Verdict, verdictOf } from \"./jev.ts\";","atom":"a2219","author":"autosettle","version":198},{"n":6,"text":"import { refused, ruled } from \"./rules.ts\";","atom":"a2217","author":"autosettle","version":198},{"n":7,"text":"import { WORKER } from \"./workers-ai.ts\";","atom":"a2217","author":"autosettle","version":198},{"n":8,"text":"","atom":"a2217","author":"autosettle","version":198},{"n":9,"text":"export interface ClefVerdict extends Verdict {","atom":"a2217","author":"autosettle","version":198},{"n":10,"text":"\treadonly reason?: string;","atom":"a2217","author":"autosettle","version":198},{"n":11,"text":"\treadonly by: \"rule\" | \"model\" | \"turned down\";","atom":"a2217","author":"autosettle","version":198},{"n":12,"text":"\treadonly modelPick?: Verdict[\"pick\"];","atom":"a2217","author":"autosettle","version":198},{"n":13,"text":"}","atom":"a2217","author":"autosettle","version":198},{"n":14,"text":"","atom":"a2217","author":"autosettle","version":198},{"n":15,"text":"/** Code's rules first, then Clef, then code's check on its pick, as for the Workers AI text model. */","atom":"a2217","author":"autosettle","version":198},{"n":16,"text":"export async function askClef(","atom":"a2219","author":"autosettle","version":198},{"n":17,"text":"\th: Hold,","atom":"a2219","author":"autosettle","version":198},{"n":18,"text":"\topts: { model?: \"clef\" | \"clef-flash\"; url?: string } = {},","atom":"a2219","author":"autosettle","version":198},{"n":19,"text":"): Promise<ClefVerdict> {","atom":"a2219","author":"autosettle","version":198},{"n":20,"text":"\tconst rule = ruled(h);","atom":"a2217","author":"autosettle","version":198},{"n":21,"text":"\tif (rule)","atom":"a2217","author":"autosettle","version":198},{"n":22,"text":"\t\treturn {","atom":"a2217","author":"autosettle","version":198},{"n":23,"text":"\t\t\tpick: rule.pick,","atom":"a2217","author":"autosettle","version":198},{"n":24,"text":"\t\t\treason: rule.reason,","atom":"a2217","author":"autosettle","version":198},{"n":25,"text":"\t\t\tconfidence: 1,","atom":"a2217","author":"autosettle","version":198},{"n":26,"text":"\t\t\tprobabilities: { yours: 0, theirs: 0, both: 0, agent: 0, [rule.pick]: 1 },","atom":"a2217","author":"autosettle","version":198},{"n":27,"text":"\t\t\torders: [],","atom":"a2217","author":"autosettle","version":198},{"n":28,"text":"\t\t\tsigns: {},","atom":"a2217","author":"autosettle","version":198},{"n":29,"text":"\t\t\tmodel: \"rule\",","atom":"a2217","author":"autosettle","version":198},{"n":30,"text":"\t\t\tms: 0,","atom":"a2217","author":"autosettle","version":198},{"n":31,"text":"\t\t\tinputTokens: 0,","atom":"a2217","author":"autosettle","version":198},{"n":32,"text":"\t\t\tby: \"rule\",","atom":"a2217","author":"autosettle","version":198},{"n":33,"text":"\t\t};","atom":"a2217","author":"autosettle","version":198},{"n":34,"text":"\tconst started = performance.now();","atom":"a2217","author":"autosettle","version":198},{"n":35,"text":"\tconst res = await fetch(`${opts.url ?? WORKER}/system-one`, {","atom":"a2217","author":"autosettle","version":198},{"n":36,"text":"\t\tmethod: \"POST\",","atom":"a2217","author":"autosettle","version":198},{"n":37,"text":"\t\theaders: { \"content-type\": \"application/json\" },","atom":"a2217","author":"autosettle","version":198},{"n":38,"text":"\t\tbody: JSON.stringify(systemOneBody(h, opts.model ?? \"clef\")),","atom":"a2217","author":"autosettle","version":198},{"n":39,"text":"\t});","atom":"a2217","author":"autosettle","version":198},{"n":40,"text":"\tconst out = (await res.json()) as SystemOneAnswer & { error?: string };","atom":"a2217","author":"autosettle","version":198},{"n":41,"text":"\tif (!res.ok || out.error || !out.answers) throw new Error(`Clef: ${out.error ?? res.status}`);","atom":"a2217","author":"autosettle","version":198},{"n":42,"text":"\tconst v = verdictOf({ ...out, model: out.model ?? opts.model ?? \"clef\" }, performance.now() - started);","atom":"a2217","author":"autosettle","version":198},{"n":43,"text":"\tconst no = refused(h, v.pick);","atom":"a2217","author":"autosettle","version":198},{"n":44,"text":"\treturn no ? { ...v, pick: \"agent\", reason: no, by: \"turned down\", modelPick: v.pick } : { ...v, by: \"model\" };","atom":"a2217","author":"autosettle","version":198},{"n":45,"text":"}","atom":"a2217","author":"autosettle","version":198}],"atoms":[{"atom":"a2217","author":"autosettle","message":"","time":1792023820043,"timeIso":"2026-10-15T00:23:40.043Z","publish":{"draft":null,"version":198,"agent":"autosettle","message":"Auto-settle (#19): Clef, Cloudflare's decision model on Workers AI, as a settler. Clef takes Jev's System One request, so clef.ts sends jev.ts's own questions through the local Worker's new /system-one route, with the same code checks before and after. score.ts and settle-one.ts take --via clef (--model clef or clef-flash). Six local holds: 6 of 6 right, 0.4 to 0.6 s each.","time":1792023876571,"timeIso":"2026-10-15T00:24:36.571Z"}},{"atom":"a2219","author":"autosettle","message":"","time":1792023875852,"timeIso":"2026-10-15T00:24:35.852Z","publish":{"draft":null,"version":198,"agent":"autosettle","message":"Auto-settle (#19): Clef, Cloudflare's decision model on Workers AI, as a settler. Clef takes Jev's System One request, so clef.ts sends jev.ts's own questions through the local Worker's new /system-one route, with the same code checks before and after. score.ts and settle-one.ts take --via clef (--model clef or clef-flash). Six local holds: 6 of 6 right, 0.4 to 0.6 s each.","time":1792023876571,"timeIso":"2026-10-15T00:24:36.571Z"}}]}