@parcha/agentrun-serve 0.1.0-beta.36 → 0.1.0-beta.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +170 -0
- package/README.md +158 -52
- package/dist/attach-conformance-cli.d.ts +1 -0
- package/dist/attach-conformance-cli.js +18 -0
- package/dist/attach-conformance.d.ts +25 -0
- package/dist/attach-conformance.js +343 -0
- package/dist/browser-cost.d.ts +1 -1
- package/dist/browser-live.d.ts +20 -8
- package/dist/browser-live.js +50 -27
- package/dist/cap.d.ts +0 -17
- package/dist/cap.js +0 -91
- package/dist/catalog.d.ts +1 -12
- package/dist/catalog.js +3 -33
- package/dist/cli.js +13 -4
- package/dist/composio-preset.d.ts +36 -0
- package/dist/composio-preset.js +179 -0
- package/dist/computer-attach.d.ts +125 -0
- package/dist/computer-attach.js +330 -0
- package/dist/computer-calls.d.ts +48 -0
- package/dist/computer-calls.js +126 -0
- package/dist/computer-channel.d.ts +57 -0
- package/dist/computer-channel.js +115 -0
- package/dist/computer-commands.d.ts +1 -1
- package/dist/computer-held-routes.d.ts +35 -0
- package/dist/computer-held-routes.js +106 -0
- package/dist/computer-held.d.ts +48 -0
- package/dist/computer-held.js +87 -0
- package/dist/computer-keys.d.ts +21 -1
- package/dist/computer-keys.js +53 -11
- package/dist/computer-live.d.ts +160 -0
- package/dist/computer-live.js +643 -0
- package/dist/computer-view.d.ts +13 -0
- package/dist/computer-view.js +50 -3
- package/dist/computer-viewer.d.ts +6 -0
- package/dist/computer-viewer.js +297 -0
- package/dist/computers.d.ts +33 -7
- package/dist/computers.js +50 -8
- package/dist/console/assets/index-Cn6JX1uH.js +563 -0
- package/dist/console/assets/index-DRN62V5v.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/faux-computers.d.ts +9 -20
- package/dist/faux-computers.js +53 -25
- package/dist/github-connection.d.ts +10 -2
- package/dist/github-connection.js +65 -2
- package/dist/github-faux.js +1 -1
- package/dist/graph-view.d.ts +1 -1
- package/dist/harness.d.ts +1 -0
- package/dist/harness.js +35 -1
- package/dist/host-tools.d.ts +1 -1
- package/dist/hosted-search.d.ts +5 -4
- package/dist/hosted-search.js +2 -7
- package/dist/import-sources.d.ts +10 -0
- package/dist/import-sources.js +44 -2
- package/dist/import.d.ts +3 -3
- package/dist/import.js +37 -6
- package/dist/learn/check.d.ts +4 -1
- package/dist/learn/check.js +1 -1
- package/dist/learn/commit.d.ts +4 -2
- package/dist/learn/commit.js +5 -5
- package/dist/learn/folder.d.ts +6 -0
- package/dist/learn/folder.js +4 -1
- package/dist/learn/general.d.ts +66 -0
- package/dist/learn/general.js +73 -0
- package/dist/learn/grade.d.ts +4 -0
- package/dist/learn/grade.js +22 -1
- package/dist/learn/reflect.d.ts +10 -1
- package/dist/learn/reflect.js +14 -4
- package/dist/learn/skills.d.ts +33 -5
- package/dist/learn/skills.js +53 -7
- package/dist/learned-workflow.d.ts +24 -0
- package/dist/learned-workflow.js +66 -3
- package/dist/learning-batch.d.ts +283 -0
- package/dist/learning-batch.js +574 -0
- package/dist/learning-evals.d.ts +33 -0
- package/dist/learning-evals.js +98 -0
- package/dist/learning-routes.d.ts +25 -2
- package/dist/learning-routes.js +39 -6
- package/dist/learning-words.d.ts +6 -0
- package/dist/learning-words.js +6 -0
- package/dist/learning.d.ts +28 -15
- package/dist/learning.js +84 -44
- package/dist/live/stream.js +6 -3
- package/dist/live/translate.d.ts +4 -3
- package/dist/live/translate.js +8 -4
- package/dist/live-reach.d.ts +37 -0
- package/dist/live-reach.js +62 -0
- package/dist/mcp-gateway.d.ts +9 -0
- package/dist/mcp-gateway.js +60 -11
- package/dist/mcp-oauth.d.ts +57 -7
- package/dist/mcp-oauth.js +133 -18
- package/dist/mcp-private-hosts.d.ts +4 -4
- package/dist/mcp-private-hosts.js +20 -12
- package/dist/mcp-probe.d.ts +19 -2
- package/dist/mcp-probe.js +44 -9
- package/dist/mcp-secret-writes.js +4 -0
- package/dist/mcp-servers-store.d.ts +38 -15
- package/dist/mcp-servers-store.js +112 -20
- package/dist/mcp-store.d.ts +10 -4
- package/dist/mcp-store.js +17 -6
- package/dist/model-form.d.ts +26 -0
- package/dist/model-form.js +80 -0
- package/dist/model.js +23 -10
- package/dist/openapi.js +386 -21
- package/dist/page.d.ts +18 -0
- package/dist/page.js +48 -20
- package/dist/paid-calls.d.ts +1 -1
- package/dist/place-offers.d.ts +2 -3
- package/dist/place-offers.js +3 -7
- package/dist/place.js +1 -2
- package/dist/print.d.ts +15 -1
- package/dist/print.js +14 -3
- package/dist/propose.d.ts +3 -0
- package/dist/propose.js +13 -5
- package/dist/provider.js +3 -2
- package/dist/reflect-range.d.ts +8 -1
- package/dist/reflect-range.js +1 -1
- package/dist/run-launch.d.ts +14 -2
- package/dist/run-launch.js +9 -4
- package/dist/run-learning-served.d.ts +2 -2
- package/dist/run-reads-over-store.d.ts +1 -1
- package/dist/run-repo.d.ts +20 -0
- package/dist/run-repo.js +63 -0
- package/dist/run-timeline-served.d.ts +1 -1
- package/dist/run-view.d.ts +3 -3
- package/dist/run-view.js +14 -7
- package/dist/runner/adapter-loop.d.ts +23 -7
- package/dist/runner/adapter-loop.js +648 -62
- package/dist/runner/adapter-run-spec.d.ts +11 -3
- package/dist/runner/adapter-run-spec.js +77 -22
- package/dist/runner/adapters/pi-computer.d.ts +7 -0
- package/dist/runner/adapters/pi-computer.js +43 -0
- package/dist/runner/adapters/pi.d.ts +9 -4
- package/dist/runner/adapters/pi.js +76 -14
- package/dist/runner/beside.d.ts +7 -3
- package/dist/runner/beside.js +21 -11
- package/dist/runner/claim-secrets.d.ts +4 -0
- package/dist/runner/claim-secrets.js +6 -1
- package/dist/runner/cli-run-spec.d.ts +20 -3
- package/dist/runner/cli-run-spec.js +113 -43
- package/dist/runner/commands.d.ts +3 -1
- package/dist/runner/commands.js +28 -3
- package/dist/runner/computer-channel.d.ts +34 -0
- package/dist/runner/computer-channel.js +61 -0
- package/dist/runner/conformance/harness.js +80 -14
- package/dist/runner/conformance/subject.d.ts +1 -1
- package/dist/runner/dispatch.js +3 -0
- package/dist/runner/end-of-run.d.ts +22 -12
- package/dist/runner/end-of-run.js +38 -16
- package/dist/runner/github-app.d.ts +2 -1
- package/dist/runner/github-app.js +4 -2
- package/dist/runner/harness-loops.js +15 -1
- package/dist/runner/held-run.d.ts +65 -0
- package/dist/runner/held-run.js +158 -0
- package/dist/runner/journal-kinds.d.ts +20 -1
- package/dist/runner/journal-kinds.js +14 -0
- package/dist/runner/journal-reader.d.ts +5 -4
- package/dist/runner/journal-reader.js +12 -10
- package/dist/runner/learning-ask.d.ts +7 -1
- package/dist/runner/learning-ask.js +21 -6
- package/dist/runner/learning-dispatch.d.ts +22 -0
- package/dist/runner/learning-dispatch.js +77 -10
- package/dist/runner/learning-end.d.ts +22 -1
- package/dist/runner/learning-end.js +92 -12
- package/dist/runner/learning-factory.d.ts +1 -1
- package/dist/runner/learning-factory.js +11 -5
- package/dist/runner/learning-loop.d.ts +67 -7
- package/dist/runner/learning-loop.js +173 -21
- package/dist/runner/learning-seed.d.ts +7 -0
- package/dist/runner/learning-seed.js +13 -0
- package/dist/runner/live-ticker.js +1 -0
- package/dist/runner/loop-contract.d.ts +8 -1
- package/dist/runner/loop.d.ts +5 -1
- package/dist/runner/loop.js +2 -1
- package/dist/runner/main.d.ts +13 -1
- package/dist/runner/main.js +27 -5
- package/dist/runner/mcp-claim.d.ts +10 -7
- package/dist/runner/mcp-claim.js +113 -24
- package/dist/runner/mcp-github.js +1 -1
- package/dist/runner/mcp-run.d.ts +5 -5
- package/dist/runner/mcp-run.js +15 -3
- package/dist/runner/metrics.d.ts +11 -2
- package/dist/runner/metrics.js +12 -2
- package/dist/runner/pr-checkout.d.ts +1 -0
- package/dist/runner/pr-checkout.js +1 -1
- package/dist/runner/reflect-hook.d.ts +18 -0
- package/dist/runner/reflect-hook.js +20 -8
- package/dist/runner/runner.d.ts +26 -0
- package/dist/runner/runner.js +184 -15
- package/dist/runner/scratch-sweep.d.ts +13 -0
- package/dist/runner/scratch-sweep.js +62 -0
- package/dist/runner/sessions.d.ts +1 -1
- package/dist/runner/store-port.d.ts +4 -2
- package/dist/runner/store-secrets.js +4 -3
- package/dist/runner/subagent.js +3 -1
- package/dist/runner/workflow-host.d.ts +6 -1
- package/dist/runner/workflow-host.js +1 -1
- package/dist/runner/workflow-loop.d.ts +1 -1
- package/dist/runner/workflow-spec.d.ts +14 -2
- package/dist/runner/workflow-spec.js +56 -20
- package/dist/runs-over-store.d.ts +6 -1
- package/dist/runs-over-store.js +38 -9
- package/dist/seal-key.js +3 -3
- package/dist/sealed-settings-store.d.ts +5 -2
- package/dist/sealed-settings-store.js +10 -4
- package/dist/secret-writes.d.ts +5 -4
- package/dist/secret-writes.js +5 -4
- package/dist/server-secrets-store.d.ts +4 -3
- package/dist/server-secrets-store.js +15 -9
- package/dist/server-secrets.js +3 -2
- package/dist/server.d.ts +43 -14
- package/dist/server.js +472 -126
- package/dist/settings-wake.d.ts +21 -0
- package/dist/settings-wake.js +59 -0
- package/dist/standard-webhooks.d.ts +4 -1
- package/dist/standard-webhooks.js +8 -4
- package/dist/store/command-wake.d.ts +12 -0
- package/dist/store/command-wake.js +37 -0
- package/dist/store/dialect.d.ts +6 -0
- package/dist/store/dialect.js +5 -0
- package/dist/store/index.d.ts +1 -1
- package/dist/store/journal/storage.d.ts +3 -2
- package/dist/store/journal/storage.js +13 -5
- package/dist/store/postgres/dialect.js +4 -0
- package/dist/store/postgres/migrations/0005_learning_rounds.sql +14 -0
- package/dist/store/postgres/migrations/0006_run_changes_channel_attempts.sql +57 -0
- package/dist/store/postgres/migrations/0007_viewer_host.sql +11 -0
- package/dist/store/postgres/migrations/0008_paired_computers.sql +30 -0
- package/dist/store/postgres/migrations/0009_commands_answer.sql +10 -0
- package/dist/store/schema.d.ts +1 -1
- package/dist/store/schema.js +77 -8
- package/dist/store/sqlite/run-patch.d.ts +7 -5
- package/dist/store/sqlite/run-patch.js +28 -13
- package/dist/store/sqlite/store.js +272 -54
- package/dist/store/store.d.ts +268 -9
- package/dist/store/store.js +12 -1
- package/dist/store-reads/cap.d.ts +1 -1
- package/dist/store-reads/cap.js +8 -1
- package/dist/store-reads/decisions.d.ts +2 -2
- package/dist/store-reads/decisions.js +1 -1
- package/dist/store-reads/import-summary.d.ts +1 -1
- package/dist/store-reads/journal.d.ts +5 -4
- package/dist/store-reads/journal.js +73 -15
- package/dist/store-reads/learning.d.ts +20 -4
- package/dist/store-reads/learning.js +74 -18
- package/dist/store-reads/runs.d.ts +1 -1
- package/dist/store-reads/workflow.d.ts +1 -1
- package/dist/store-view.d.ts +5 -0
- package/dist/store-view.js +26 -11
- package/dist/template-eval.js +6 -4
- package/dist/template-github-permissions.d.ts +22 -8
- package/dist/template-github-permissions.js +35 -15
- package/dist/timeline/timeline.d.ts +27 -0
- package/dist/timeline/timeline.js +10 -9
- package/dist/timeline/util.d.ts +4 -0
- package/dist/timeline/util.js +14 -0
- package/dist/tool-budget.d.ts +19 -7
- package/dist/tool-budget.js +14 -8
- package/dist/tool-gate.d.ts +16 -9
- package/dist/tool-gate.js +53 -42
- package/dist/tool-plane.d.ts +16 -12
- package/dist/tool-plane.js +9 -4
- package/dist/tools.d.ts +13 -4
- package/dist/tools.js +13 -4
- package/dist/trigger-adapter.d.ts +4 -0
- package/dist/trigger-secrets-shown.d.ts +2 -2
- package/dist/trigger-secrets-shown.js +1 -1
- package/dist/trigger-signatures.d.ts +25 -6
- package/dist/trigger-signatures.js +41 -7
- package/dist/trigger-targets.d.ts +2 -0
- package/dist/trigger-targets.js +1 -0
- package/dist/trigger-webhook.js +5 -2
- package/dist/triggers.d.ts +7 -3
- package/dist/triggers.js +35 -5
- package/dist/turns.js +16 -1
- package/dist/validate.js +11 -1
- package/dist/web-fetch.d.ts +1 -1
- package/dist/web-search.d.ts +10 -5
- package/dist/web-search.js +7 -6
- package/dist/webhooks.d.ts +145 -102
- package/dist/webhooks.js +559 -322
- package/dist/workflow/decisions.d.ts +1 -1
- package/dist/workflow/node-runner.d.ts +2 -1
- package/dist/workflow/node.d.ts +2 -1
- package/dist/workflow/node.js +3 -1
- package/dist/workflow/pi-versions.d.ts +23 -0
- package/dist/workflow/pi-versions.js +57 -0
- package/dist/workflow/record-tool.d.ts +2 -1
- package/dist/workflow/store.d.ts +1 -1
- package/dist/workflow/task.js +3 -2
- package/dist/workflow-run.d.ts +1 -1
- package/dist/workspace/attached-computers.d.ts +41 -0
- package/dist/workspace/attached-computers.js +114 -0
- package/dist/workspace/computer-deps.d.ts +16 -9
- package/dist/workspace/computer-deps.js +19 -7
- package/dist/workspace/computer-for-claim.d.ts +17 -8
- package/dist/workspace/computer-for-claim.js +62 -21
- package/dist/workspace/computer-hold.d.ts +11 -27
- package/dist/workspace/computer-hold.js +36 -56
- package/dist/workspace/computer-ledger.d.ts +3 -1
- package/dist/workspace/computer-ledger.js +4 -0
- package/dist/workspace/computer-mcp.d.ts +25 -0
- package/dist/workspace/computer-mcp.js +41 -0
- package/dist/workspace/computer-ports.d.ts +4 -13
- package/dist/workspace/computer-ports.js +4 -107
- package/dist/workspace/computer-script.d.ts +37 -0
- package/dist/workspace/computer-script.js +138 -0
- package/dist/workspace/executors.d.ts +1 -1
- package/dist/workspace/index.d.ts +4 -2
- package/dist/workspace/index.js +3 -1
- package/dist/workspace/kind-skills/desktop/SKILL.md +119 -84
- package/dist/workspace/kind-skills/phone/SKILL.md +100 -85
- package/dist/workspace/resolve-computer.d.ts +3 -0
- package/dist/workspace/resolve-computer.js +8 -2
- package/dist/workspace/run-tools.d.ts +32 -15
- package/dist/workspace/run-tools.js +23 -30
- package/package.json +19 -16
- package/templates/market-monitor/agent.md +1 -1
- package/dist/console/assets/index-BI4Byidu.js +0 -550
- package/dist/console/assets/index-C19gUF2n.css +0 -1
- package/dist/run-db.d.ts +0 -53
- package/dist/run-db.js +0 -116
- package/dist/workflow/readers.d.ts +0 -36
- package/dist/workflow/readers.js +0 -145
- package/dist/workflow/wal.d.ts +0 -11
- package/dist/workflow/wal.js +0 -106
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// The models a person is offered to pick for each harness, in the exact form that harness takes, and the words a refusal
|
|
2
|
+
// uses when a model is named in a form it does not take. One list, served in capabilities (`harnesses[].models`) and read
|
|
3
|
+
// by the console's Model picker, so the picker, the save's refusal and a run's refusal never name different forms.
|
|
4
|
+
// A leaf of model.ts and provider.ts (it reads their tables only when called, never as it loads).
|
|
5
|
+
import { ADAPTER_FACTS } from "./adapter-facts.js";
|
|
6
|
+
import { FAUX_ENV, MODEL_KEYS } from "./model.js";
|
|
7
|
+
import { openRouterName } from "./provider.js";
|
|
8
|
+
import { WIRES } from "./wires.js";
|
|
9
|
+
/** The current models a person may pick, by vendor, in the vendor's own ids (Anthropic's dashes; OpenRouter's dotted name
|
|
10
|
+
* for the same model is derived, provider.ts openRouterName). The everyday model first: it is the example a refusal gives.
|
|
11
|
+
* A candidate a harness cannot run on this server (one pi-ai's catalog does not list) is dropped before it is served
|
|
12
|
+
* (harness.ts harnessOffers). */
|
|
13
|
+
export const PICKABLE = Object.freeze([
|
|
14
|
+
{ vendor: "anthropic", ids: Object.freeze(["claude-sonnet-5-5", "claude-opus-5-5", "claude-haiku-5-5", "claude-fable-5-2"]) },
|
|
15
|
+
{ vendor: "openai", ids: Object.freeze(["gpt-6.1-sol", "gpt-6.1-terra", "gpt-6-luna"]) },
|
|
16
|
+
]);
|
|
17
|
+
/** The vendors whose models `harness` runs: pi any; an adapter harness, its wire's vendor. */
|
|
18
|
+
const vendorsOf = (harness) => {
|
|
19
|
+
const facts = ADAPTER_FACTS.find((f) => f.id === harness);
|
|
20
|
+
return facts ? [WIRES[facts.wire].vendor] : PICKABLE.map((p) => p.vendor);
|
|
21
|
+
};
|
|
22
|
+
/** `vendor`'s model `id` in the form this server runs it: `vendor/id` on the vendor's own key, or through OpenRouter
|
|
23
|
+
* (`openrouter/vendor/id`, Anthropic's id in OpenRouter's dotted name) when OpenRouter's key is the only one here. */
|
|
24
|
+
export function formOf(env, vendor, id) {
|
|
25
|
+
const row = MODEL_KEYS.find((r) => r.id === vendor);
|
|
26
|
+
if (row && !env[row.field] && env.OPENROUTER_API_KEY)
|
|
27
|
+
return `openrouter/${vendor}/${vendor === "anthropic" ? openRouterName(id) : id}`;
|
|
28
|
+
return `${vendor}/${id}`;
|
|
29
|
+
}
|
|
30
|
+
/** The models offered for `harness` on this server, each in the form it takes, before the harness's own catalog is asked
|
|
31
|
+
* (harness.ts harnessOffers drops those it does not run). Behind serve's gateway every id is the gateway's own string, so
|
|
32
|
+
* the host's tier models stand for what it runs; with the faux model none is offered. */
|
|
33
|
+
export function pickerCandidates(env, harness) {
|
|
34
|
+
if (env[FAUX_ENV])
|
|
35
|
+
return [];
|
|
36
|
+
// The gateway serves the harnesses whose wire goes through it (pi, and the OpenAI Responses wire: providerFor); the
|
|
37
|
+
// Anthropic Messages wire never does, so Claude is offered Anthropic's models on its own key.
|
|
38
|
+
const facts = ADAPTER_FACTS.find((f) => f.id === harness);
|
|
39
|
+
if (env.AGENT_MODEL_BASE_URL && facts?.wire !== "anthropic-messages")
|
|
40
|
+
return [...new Set([env.AGENT_MODEL, env.AGENT_MODEL_FAST, env.AGENT_MODEL_STRONG].filter((id) => Boolean(id)))];
|
|
41
|
+
const vendors = vendorsOf(harness);
|
|
42
|
+
return PICKABLE.filter((p) => vendors.includes(p.vendor)).flatMap((p) => p.ids.map((id) => formOf(env, p.vendor, id)));
|
|
43
|
+
}
|
|
44
|
+
/** A model id with its spelling taken out (case, spaces, dots, dashes), and the provider's segments off. */
|
|
45
|
+
const spelled = (given) => (given.split("/").pop() ?? "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
|
|
46
|
+
/** The model `given` most likely means, in the form this harness takes, or undefined when none is obvious: the same id
|
|
47
|
+
* with a dot for a dash or the other way, a missing provider, or a name without its `claude-` ("Sonnet 5.5"). */
|
|
48
|
+
export function likelyModel(env, harness, given) {
|
|
49
|
+
const wanted = spelled(given);
|
|
50
|
+
if (!wanted)
|
|
51
|
+
return undefined;
|
|
52
|
+
const vendors = vendorsOf(harness);
|
|
53
|
+
for (const { vendor, ids } of PICKABLE) {
|
|
54
|
+
if (!vendors.includes(vendor))
|
|
55
|
+
continue;
|
|
56
|
+
const id = ids.find((each) => spelled(each) === wanted || spelled(each).endsWith(`-${wanted}`));
|
|
57
|
+
if (id)
|
|
58
|
+
return formOf(env, vendor, id);
|
|
59
|
+
}
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
/** What a refusal says of a model named in a form `harness` does not take: the form it takes, with examples this server
|
|
63
|
+
* can run, and the likely id when one is obvious. `host`: the name is the server's own default, not the revision's. No
|
|
64
|
+
* word of the catalog behind it: a person's words. */
|
|
65
|
+
export function modelFormWhy(env, harness, named, host) {
|
|
66
|
+
const likely = likelyModel(env, harness, named);
|
|
67
|
+
const subject = host ? `The server's default model ${named} is not one` : `${named} is not a model`;
|
|
68
|
+
return `${modelShape(env, harness)}: ${subject} ${harness} runs here.${likely && likely !== named ? ` Did you mean ${likely}?` : ""}`;
|
|
69
|
+
}
|
|
70
|
+
/** "On pi, a model is <provider>/<model id>, like A or B": the forms this server can run, each of the harness's first
|
|
71
|
+
* vendor's everyday model, the vendor's own and OpenRouter's. Only the forms a key here runs; with neither key both, since
|
|
72
|
+
* either key makes one run. */
|
|
73
|
+
export function modelShape(env, harness) {
|
|
74
|
+
const first = PICKABLE.find((p) => vendorsOf(harness).includes(p.vendor));
|
|
75
|
+
const id = first.ids[0];
|
|
76
|
+
const own = Boolean(env[MODEL_KEYS.find((r) => r.id === first.vendor).field]);
|
|
77
|
+
const router = Boolean(env.OPENROUTER_API_KEY);
|
|
78
|
+
const shown = [...(own || !router ? [`${first.vendor}/${id}`] : []), ...(router || !own ? [`openrouter/${first.vendor}/${first.vendor === "anthropic" ? openRouterName(id) : id}`] : [])];
|
|
79
|
+
return `On ${harness}, a model is <provider>/<model id>, like ${shown.join(" or ")}`;
|
|
80
|
+
}
|
package/dist/model.js
CHANGED
|
@@ -9,6 +9,7 @@ import { pathToFileURL } from "node:url";
|
|
|
9
9
|
import { DEFAULT_HARNESS } from "./harness.js";
|
|
10
10
|
import { HARNESS_TABLE_ENV, harnessOf } from "./harness-table.js";
|
|
11
11
|
import { gatewayBase } from "./provider.js";
|
|
12
|
+
import { modelFormWhy } from "./model-form.js";
|
|
12
13
|
// Leaves, which the key rows below read as this module loads, in any import order (wires.ts, adapter-facts.ts).
|
|
13
14
|
import { ADAPTER_FACTS } from "./adapter-facts.js";
|
|
14
15
|
import { WIRES } from "./wires.js";
|
|
@@ -165,21 +166,24 @@ export async function chooseModel(env, ref, tier = "default", harness = DEFAULT_
|
|
|
165
166
|
return { why: `${none}: name the gateway's model in AGENT_MODEL where AgentRun starts, or add a model key in Settings → Model keys.`, host: true, needs: "key" };
|
|
166
167
|
// A revision's model, and a key's default (MODEL_KEYS: "provider/model"), go as the gateway takes its ids (bare: the
|
|
167
168
|
// part after the provider), that provider pricing them; the host's own AGENT_MODEL or tier id goes as configured.
|
|
168
|
-
|
|
169
|
+
// A name equal to one of the host's configured ids (the picker lists them: model-form.ts pickerCandidates) is that
|
|
170
|
+
// host id whoever names it, so a revision that picks it is sent what the host configured, never a cut of it.
|
|
171
|
+
const configured = [env.AGENT_MODEL, env.AGENT_MODEL_FAST, env.AGENT_MODEL_STRONG].includes(named);
|
|
172
|
+
const id = ref ?? (configured ? undefined : named);
|
|
169
173
|
const slash = id?.indexOf("/") ?? -1;
|
|
170
|
-
const sent = id && env.AGENT_MODEL_GATEWAY_IDS === "bare" ? id.slice(slash + 1) : named;
|
|
174
|
+
const sent = id && !configured && env.AGENT_MODEL_GATEWAY_IDS === "bare" ? id.slice(slash + 1) : named;
|
|
171
175
|
return { model: { provider: MODEL_PROVIDER, modelId: sent }, ...(id && slash > 0 ? { namedProvider: id.slice(0, slash) } : {}) };
|
|
172
176
|
}
|
|
173
177
|
if (!named)
|
|
174
178
|
return { why: `${none}: ${ADD_A_KEY}`, host: true, needs: "key" };
|
|
175
179
|
const slash = named.indexOf("/");
|
|
176
180
|
if (slash < 1)
|
|
177
|
-
return { why:
|
|
181
|
+
return { why: modelFormWhy(env, harness, named, ref === undefined), host: ref === undefined, needs: "model" };
|
|
178
182
|
const [provider, modelId] = [named.slice(0, slash), named.slice(slash + 1)];
|
|
179
183
|
const models = await providerModels(env);
|
|
180
184
|
const model = models.getModel(provider, modelId);
|
|
181
185
|
if (!model)
|
|
182
|
-
return { why:
|
|
186
|
+
return { why: modelFormWhy(env, harness, named, ref === undefined), host: ref === undefined, needs: "model" };
|
|
183
187
|
// A gateway ANTHROPIC_BASE_URL names that a key may not go to (gatewayBase): no Anthropic model runs, by its words.
|
|
184
188
|
const refused = provider === "anthropic" ? anthropicRefusal(models) : undefined;
|
|
185
189
|
if (refused)
|
|
@@ -249,6 +253,7 @@ export const PROVIDER_KEYS = {
|
|
|
249
253
|
"qwen-token-plan": ["QWEN_TOKEN_PLAN_API_KEY"],
|
|
250
254
|
"qwen-token-plan-cn": ["QWEN_TOKEN_PLAN_CN_API_KEY"],
|
|
251
255
|
"qwen-token-plan-individual": ["QWEN_TOKEN_PLAN_API_KEY"],
|
|
256
|
+
"qwen-token-plan-individual-cn": ["QWEN_TOKEN_PLAN_CN_API_KEY"],
|
|
252
257
|
radius: ["RADIUS_API_KEY"],
|
|
253
258
|
together: ["TOGETHER_API_KEY"],
|
|
254
259
|
typesafe: ["TYPESAFE_API_KEY"],
|
|
@@ -598,12 +603,14 @@ export function catalogPrice(catalog, id, named) {
|
|
|
598
603
|
return catalogEntries(catalog, id, undefined);
|
|
599
604
|
return catalogEntries(catalog, id.slice(slash + 1), id.slice(0, slash));
|
|
600
605
|
}
|
|
601
|
-
/** The forms of `id` with its version's separators written the other way: each digit-dash-digit as a dot (gpt-
|
|
602
|
-
* gpt-
|
|
603
|
-
* claude-haiku-
|
|
606
|
+
/** The forms of `id` with its version's separators written the other way: each digit-dash-digit as a dot (gpt-6-1-terra,
|
|
607
|
+
* gpt-6.1-terra; pair by pair, so llama-3-1-8b is llama-3.1-8b), and each digit-dot-digit as a dash (claude-haiku-5.5,
|
|
608
|
+
* claude-haiku-5-5). Not `id` itself. */
|
|
604
609
|
const flippedForms = (id) => [...new Set([id.replace(/(\d)-(\d)/g, "$1.$2"), id.replace(/(\d)\.(\d)/g, "$1-$2")])].filter((form) => form !== id);
|
|
605
610
|
/** `id`'s price in `catalog` (listedPrice): its own entries' metered price when the catalog lists one; else its flipped
|
|
606
|
-
* forms' (flippedForms), only when every metered entry they hold has one
|
|
611
|
+
* forms' (flippedForms), only when every metered entry they hold has one base price (input, output, cacheRead,
|
|
612
|
+
* cacheWrite; a long-context `tiers` table is not part of the comparison), the entry that carries `tiers` when one does
|
|
613
|
+
* (a long prompt is priced at the higher tier, erring high; entries with different `tiers` tables stay unpriced), else the first; else the metered price a gateway lists
|
|
607
614
|
* under a vendor's id for it (`<vendor>/<id>`, the named vendor's first: pi-ai lists the bare id of some models only
|
|
608
615
|
* under subscription plans, at $0, and the gateways that meter them under the vendor's). A flip that finds different
|
|
609
616
|
* prices leaves the model unpriced, and so does an id with no metered entry anywhere (#2339: a plan's $0 never prices a
|
|
@@ -615,8 +622,14 @@ function catalogEntries(catalog, id, named) {
|
|
|
615
622
|
return listed;
|
|
616
623
|
const flipped = flippedForms(id).flatMap((form) => (catalog.get(form) ?? []).filter(({ cost }) => cost.input + cost.output > 0));
|
|
617
624
|
if (flipped.length) {
|
|
618
|
-
const
|
|
619
|
-
|
|
625
|
+
const base = ({ input, output, cacheRead, cacheWrite }) => JSON.stringify([input, output, cacheRead, cacheWrite]);
|
|
626
|
+
const one = base(flipped[0].cost);
|
|
627
|
+
if (!flipped.every((entry) => base(entry.cost) === one))
|
|
628
|
+
return undefined;
|
|
629
|
+
const tiered = flipped.filter((entry) => entry.cost.tiers?.length);
|
|
630
|
+
if (tiered.some((entry) => JSON.stringify(entry.cost.tiers) !== JSON.stringify(tiered[0].cost.tiers)))
|
|
631
|
+
return undefined;
|
|
632
|
+
return (tiered[0] ?? flipped[0]).cost;
|
|
620
633
|
}
|
|
621
634
|
return vendorPrice(catalog, id, named);
|
|
622
635
|
}
|