Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed

Versions 4 to 318

Compare

+67 −0 in 1 place
new file, 67 lines
1+// Ask the local auto-settle Worker (workers-ai/, run with wrangler dev) how a hold should be settled (#19).
2+
3+import type { Hold, Pick } from "./jev.ts";
4+import { refused, ruled } from "./rules.ts";
5+
6+export const WORKER = process.env.AUTOSETTLE_WORKER ?? "http://127.0.0.1:8845";
7+
8+export interface ModelVerdict {
9+ readonly pick: Pick;
10+ readonly confidence: number;
11+ readonly reason: string;
12+ readonly model: string;
13+ /** Round trip from here, through wrangler dev, to Workers AI and back. */
14+ readonly ms: number;
15+ /** The model's own time, as the Worker measured it. */
16+ readonly modelMs: number;
17+ readonly inputTokens: number;
18+ /** rule: code decided without the model. turned down: the model's pick would break the file, so an agent settles. */
19+ readonly by: "rule" | "model" | "turned down";
20+ /** The model's own pick, when it was turned down. */
21+ readonly modelPick?: Pick;
22+}
24+/** Code's rules first, then the model, then code's check on what the model picked. */
25+export async function askWorkersAi(
26+ h: Hold,
27+ opts: { model?: string; url?: string; samples?: number } = {},
28+): Promise<ModelVerdict> {
29+ const rule = ruled(h);
30+ if (rule) return { ...rule, confidence: 1, model: "rule", ms: 0, modelMs: 0, inputTokens: 0, by: "rule" };
31+ const v = await askModel(h, opts);
32+ const no = refused(h, v.pick);
33+ return no ? { ...v, pick: "agent", reason: no, by: "turned down", modelPick: v.pick } : v;
34+}
36+async function askModel(h: Hold, opts: { model?: string; url?: string; samples?: number }): Promise<ModelVerdict> {
37+ const started = performance.now();
38+ const res = await fetch(opts.url ?? WORKER, {
39+ method: "POST",
40+ headers: { "content-type": "application/json" },
41+ body: JSON.stringify({
42+ hold: h,
43+ ...(opts.model ? { model: opts.model } : {}),
44+ samples: opts.samples ?? Number(process.env.AUTOSETTLE_SAMPLES ?? 1),
45+ }),
46+ });
47+ const out = (await res.json()) as {
48+ pick?: Pick;
49+ confidence?: number;
50+ reason?: string;
51+ model: string;
52+ ms: number;
53+ error?: string;
54+ usage?: { prompt_tokens?: number } | null;
55+ };
56+ if (!res.ok || out.error || !out.pick) throw new Error(`Workers AI: ${out.error ?? res.status}`);
57+ return {
58+ pick: out.pick,
59+ confidence: Math.min(1, Math.max(0, out.confidence ?? 0)),
60+ reason: out.reason ?? "",
61+ model: out.model,
62+ ms: performance.now() - started,
63+ modelMs: out.ms,
64+ inputTokens: out.usage?.prompt_tokens ?? 0,
65+ by: "model",
66+ };
67+}
MCP
compare on this site's /mcp
CLI
abso diff 4 318 scripts/autosettle/workers-ai.ts --json
JSON
/christopher/abso-core/compare/4..318?file=scripts%2Fautosettle%2Fworkers-ai.ts&format=json