@parcha/agentrun-serve 0.1.0-beta.44 → 0.1.0-beta.46
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 +148 -5
- package/README.md +385 -305
- package/dist/acp-package.d.ts +28 -0
- package/dist/acp-package.js +23 -0
- package/dist/adapter-facts.d.ts +8 -1
- package/dist/adapter-facts.js +9 -1
- package/dist/adapters.d.ts +5 -0
- package/dist/adapters.js +36 -3
- package/dist/agent-delete.d.ts +50 -0
- package/dist/agent-delete.js +125 -0
- package/dist/agents-store.d.ts +9 -3
- package/dist/agents-store.js +22 -8
- package/dist/agents.d.ts +5 -1
- package/dist/agents.js +8 -4
- package/dist/api-only.d.ts +8 -3
- package/dist/api-only.js +10 -4
- package/dist/archil-routes.d.ts +5 -1
- package/dist/archil-routes.js +57 -2
- package/dist/browser-wait-ended.d.ts +2 -0
- package/dist/browser-wait-ended.js +2 -0
- package/dist/calendar/ics-faux.d.ts +3 -1
- package/dist/calendar/ics-faux.js +12 -2
- package/dist/calendar/tools.js +5 -2
- package/dist/chatgpt-plan.js +3 -1
- package/dist/claude-login.d.ts +135 -0
- package/dist/claude-login.js +244 -0
- package/dist/cli.js +62 -19
- package/dist/composio-preset.js +69 -7
- package/dist/composio-triggers.d.ts +14 -0
- package/dist/composio-triggers.js +79 -15
- package/dist/computer-attach.d.ts +40 -5
- package/dist/computer-attach.js +130 -15
- package/dist/computer-keys.d.ts +3 -0
- package/dist/computer-keys.js +7 -1
- package/dist/computer-live.js +3 -2
- package/dist/computers.d.ts +21 -10
- package/dist/computers.js +39 -28
- package/dist/console/assets/index-C2MYaUBa.css +1 -0
- package/dist/console/assets/index-CZZeCReB.js +701 -0
- package/dist/console/index.html +2 -2
- package/dist/decisions.d.ts +1 -1
- package/dist/dial-relay.d.ts +29 -0
- package/dist/dial-relay.js +94 -0
- package/dist/email/tools.js +10 -5
- package/dist/env-proxy.d.ts +2 -0
- package/dist/env-proxy.js +35 -0
- package/dist/errors.d.ts +3 -1
- package/dist/errors.js +7 -4
- package/dist/faux-computers.d.ts +8 -2
- package/dist/faux-computers.js +83 -6
- package/dist/harness-archive.d.ts +67 -0
- package/dist/harness-archive.js +177 -0
- package/dist/harness-goose.d.ts +34 -0
- package/dist/harness-goose.js +87 -0
- package/dist/harness-install.d.ts +21 -0
- package/dist/harness-install.js +24 -11
- package/dist/harness-opencode/adapter.js +1 -1
- package/dist/harness-table.d.ts +9 -1
- package/dist/harness-table.js +20 -3
- package/dist/harness.d.ts +1 -2
- package/dist/harness.js +3 -4
- package/dist/host.js +2 -1
- package/dist/import.d.ts +10 -0
- package/dist/import.js +28 -8
- package/dist/key-check.js +3 -0
- package/dist/learn/audit.d.ts +6 -6
- package/dist/learn/audit.js +3 -7
- package/dist/learn/check.d.ts +23 -89
- package/dist/learn/check.js +57 -335
- package/dist/learn/commit.d.ts +63 -90
- package/dist/learn/commit.js +124 -316
- package/dist/learn/compile.d.ts +53 -50
- package/dist/learn/compile.js +89 -104
- package/dist/learn/corrections.d.ts +13 -0
- package/dist/learn/corrections.js +23 -0
- package/dist/learn/delete.d.ts +5 -5
- package/dist/learn/delete.js +8 -10
- package/dist/learn/folder.d.ts +35 -47
- package/dist/learn/folder.js +118 -134
- package/dist/learn/index.d.ts +3 -5
- package/dist/learn/index.js +6 -9
- package/dist/learn/learning.sh +45 -15
- package/dist/learn/promote.d.ts +23 -5
- package/dist/learn/promote.js +40 -2
- package/dist/learn/{skills.d.ts → workflow-draft.d.ts} +30 -38
- package/dist/learn/{skills.js → workflow-draft.js} +48 -58
- package/dist/learn/workflow-nodes.js +1 -1
- package/dist/learned-workflow.js +2 -2
- package/dist/learning-cost.d.ts +38 -24
- package/dist/learning-cost.js +41 -24
- package/dist/learning-routes.d.ts +91 -170
- package/dist/learning-routes.js +183 -421
- package/dist/learning-run.d.ts +19 -40
- package/dist/learning-run.js +23 -93
- package/dist/learning-setting.d.ts +21 -10
- package/dist/learning-setting.js +47 -11
- package/dist/learning-words.d.ts +28 -74
- package/dist/learning-words.js +64 -162
- package/dist/learning.d.ts +61 -392
- package/dist/learning.js +101 -651
- package/dist/live-reach.d.ts +25 -2
- package/dist/live-reach.js +46 -4
- package/dist/llms.txt +1 -1
- package/dist/local-models.d.ts +3 -11
- package/dist/local-models.js +5 -6
- package/dist/mcp-servers-store.d.ts +4 -4
- package/dist/model-form.js +6 -5
- package/dist/model.d.ts +4 -0
- package/dist/model.js +26 -9
- package/dist/native/binding.js +1 -1
- package/dist/native/connection.js +1 -1
- package/dist/native/discovery.js +1 -1
- package/dist/native/instructions.d.ts +3 -0
- package/dist/native/instructions.js +5 -3
- package/dist/native/remote-worker-bridge.js +9 -43
- package/dist/native/remote.d.ts +8 -15
- package/dist/native/remote.js +3 -3
- package/dist/native/schema.js +1 -1
- package/dist/native/types.d.ts +2 -2
- package/dist/openapi.js +273 -319
- package/dist/paid-calls.d.ts +8 -0
- package/dist/paid-calls.js +20 -0
- package/dist/particle-provider.d.ts +11 -0
- package/dist/particle-provider.js +135 -0
- package/dist/port-models.d.ts +12 -4
- package/dist/port-models.js +28 -11
- package/dist/print.d.ts +27 -0
- package/dist/print.js +21 -0
- package/dist/provider.d.ts +7 -0
- package/dist/provider.js +15 -1
- package/dist/reflect-range.js +2 -3
- package/dist/run-launch.d.ts +14 -28
- package/dist/run-launch.js +9 -12
- package/dist/run-learning-served.d.ts +15 -89
- package/dist/run-listing.d.ts +34 -0
- package/dist/run-listing.js +128 -0
- package/dist/run-model-key.js +1 -1
- package/dist/run-timeline-served.js +5 -3
- package/dist/run-trace.d.ts +97 -0
- package/dist/run-trace.js +253 -0
- package/dist/run-view.d.ts +15 -0
- package/dist/run-view.js +9 -0
- package/dist/runnable.js +2 -1
- package/dist/runner/adapter-loop.d.ts +8 -6
- package/dist/runner/adapter-loop.js +16 -12
- package/dist/runner/adapter-run-spec.d.ts +16 -4
- package/dist/runner/adapter-run-spec.js +64 -58
- package/dist/runner/adapters/index.js +22 -0
- package/dist/runner/adapters/pi.d.ts +4 -12
- package/dist/runner/adapters/pi.js +2 -2
- package/dist/runner/audit.d.ts +1 -1
- package/dist/runner/audit.js +30 -13
- package/dist/runner/beside.d.ts +6 -2
- package/dist/runner/beside.js +38 -9
- package/dist/runner/claim-secrets.d.ts +18 -2
- package/dist/runner/claim-secrets.js +42 -18
- package/dist/runner/cli-run-spec.js +55 -51
- package/dist/runner/conformance/harness.d.ts +6 -0
- package/dist/runner/conformance/harness.js +35 -13
- package/dist/runner/conformance/subject.d.ts +6 -0
- package/dist/runner/dispatch.d.ts +2 -2
- package/dist/runner/end-of-run.d.ts +6 -14
- package/dist/runner/end-of-run.js +8 -33
- package/dist/runner/feedback-round.d.ts +2 -2
- package/dist/runner/feedback-round.js +7 -7
- package/dist/runner/github-app.js +3 -1
- package/dist/runner/harness-loops.d.ts +0 -8
- package/dist/runner/harness-loops.js +11 -59
- package/dist/runner/held.d.ts +170 -0
- package/dist/runner/held.js +57 -0
- package/dist/runner/journal-kinds.d.ts +2 -3
- package/dist/runner/journal-kinds.js +2 -3
- package/dist/runner/learned-first.d.ts +40 -0
- package/dist/runner/learned-first.js +32 -0
- package/dist/runner/learning-end.d.ts +77 -69
- package/dist/runner/learning-end.js +250 -303
- package/dist/runner/learning-seed.d.ts +15 -33
- package/dist/runner/learning-seed.js +24 -45
- package/dist/runner/loop-contract.d.ts +2 -3
- package/dist/runner/main.d.ts +17 -9
- package/dist/runner/main.js +82 -20
- package/dist/runner/mcp-run.d.ts +11 -0
- package/dist/runner/mcp-run.js +67 -0
- package/dist/runner/memory-claim.d.ts +10 -5
- package/dist/runner/memory-claim.js +12 -6
- package/dist/runner/model-route.d.ts +7 -4
- package/dist/runner/model-route.js +22 -10
- package/dist/runner/native-loop.d.ts +0 -7
- package/dist/runner/native-loop.js +9 -101
- package/dist/runner/promotion.d.ts +12 -8
- package/dist/runner/promotion.js +37 -28
- package/dist/runner/reflect-hook.d.ts +64 -95
- package/dist/runner/reflect-hook.js +112 -225
- package/dist/runner/run-channel.d.ts +43 -0
- package/dist/runner/run-channel.js +467 -0
- package/dist/runner/run-child-host.d.ts +169 -0
- package/dist/runner/run-child-host.js +1230 -0
- package/dist/runner/run-child.d.ts +1 -0
- package/dist/runner/run-child.js +254 -0
- package/dist/runner/run-errors.d.ts +2 -0
- package/dist/runner/run-errors.js +20 -0
- package/dist/runner/runner.js +1 -5
- package/dist/runner/sdk-ask.d.ts +78 -0
- package/dist/runner/sdk-ask.js +158 -0
- package/dist/runner/sdk-loop.d.ts +2 -4
- package/dist/runner/sdk-loop.js +29 -49
- package/dist/runner/store-secrets.d.ts +5 -3
- package/dist/runner/store-secrets.js +5 -1
- package/dist/runner/workflow-first.d.ts +5 -0
- package/dist/runner/workflow-first.js +4 -0
- package/dist/runner/workflow-spec.js +7 -2
- package/dist/runs-over-store.d.ts +16 -28
- package/dist/runs-over-store.js +31 -38
- package/dist/sdk/runs.d.ts +6 -11
- package/dist/sdk/runs.js +20 -41
- package/dist/sdk/schema.js +3 -4
- package/dist/seal-key.d.ts +5 -0
- package/dist/seal-key.js +7 -0
- package/dist/secrets.d.ts +3 -0
- package/dist/secrets.js +16 -3
- package/dist/server.d.ts +55 -33
- package/dist/server.js +689 -322
- package/dist/sign-ins-store.d.ts +8 -0
- package/dist/sign-ins-store.js +36 -1
- package/dist/skills.js +1 -1
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +1 -1
- package/dist/store/journal/storage.js +3 -0
- package/dist/store/postgres/migrations/0017_run_listing.sql +83 -0
- package/dist/store/postgres/migrations/0018_trigger_template.sql +6 -0
- package/dist/store/postgres/migrations/0019_runner_relays.sql +28 -0
- package/dist/store/schema.d.ts +53 -4
- package/dist/store/schema.js +137 -6
- package/dist/store/sqlite/connection.d.ts +2 -0
- package/dist/store/sqlite/connection.js +3 -1
- package/dist/store/sqlite/run-patch.d.ts +0 -17
- package/dist/store/sqlite/run-patch.js +4 -33
- package/dist/store/sqlite/store.js +246 -63
- package/dist/store/sqlite/worker.js +25 -0
- package/dist/store/store.d.ts +193 -36
- package/dist/store/store.js +25 -3
- package/dist/store-reads/learning.d.ts +102 -204
- package/dist/store-reads/learning.js +159 -321
- package/dist/store-reads/loop.d.ts +0 -1
- package/dist/store-reads/loop.js +1 -1
- package/dist/store-view.d.ts +29 -1
- package/dist/store-view.js +97 -31
- package/dist/template-eval.d.ts +3 -6
- package/dist/template-eval.js +22 -36
- package/dist/templates.d.ts +8 -4
- package/dist/templates.js +44 -6
- package/dist/timeline/index.d.ts +1 -1
- package/dist/timeline/index.js +1 -1
- package/dist/timeline/timeline.d.ts +5 -1
- package/dist/timeline/timeline.js +16 -0
- package/dist/tool-gate.d.ts +0 -7
- package/dist/tool-gate.js +1 -15
- package/dist/tool-keys-store.d.ts +1 -1
- package/dist/tool-keys.d.ts +6 -4
- package/dist/tool-keys.js +12 -6
- package/dist/tools.d.ts +2 -2
- package/dist/tools.js +11 -4
- package/dist/triggers.d.ts +65 -6
- package/dist/triggers.js +125 -19
- package/dist/validate.js +1 -1
- package/dist/webhooks.d.ts +7 -2
- package/dist/webhooks.js +12 -5
- package/dist/workspace/agent-computer.d.ts +2 -0
- package/dist/workspace/agent-computer.js +2 -0
- package/dist/workspace/archil-claim.d.ts +7 -0
- package/dist/workspace/archil-claim.js +29 -0
- package/dist/workspace/archil.d.ts +9 -1
- package/dist/workspace/archil.js +165 -3
- package/dist/workspace/attach.d.ts +3 -1
- package/dist/workspace/attach.js +2 -0
- package/dist/workspace/attached-computers.d.ts +16 -5
- package/dist/workspace/attached-computers.js +25 -9
- package/dist/workspace/computer-deps.js +1 -1
- package/dist/workspace/computer-for-claim.d.ts +7 -3
- package/dist/workspace/computer-for-claim.js +119 -22
- package/dist/workspace/computer-hold.js +2 -1
- package/dist/workspace/computer-kept.d.ts +11 -1
- package/dist/workspace/computer-kept.js +24 -3
- package/dist/workspace/resolve-computer.d.ts +33 -19
- package/dist/workspace/resolve-computer.js +172 -64
- package/dist/workspace/revision-skills.d.ts +1 -2
- package/dist/workspace/revision-skills.js +3 -4
- package/dist/workspace/run-workspace.d.ts +1 -1
- package/dist/workspace/run-workspace.js +5 -0
- package/dist/workspace/synced-folder.d.ts +85 -0
- package/dist/workspace/synced-folder.js +230 -0
- package/dist/workspace/workspace.d.ts +4 -0
- package/launcher/agentrun-serve +1 -1
- package/package.json +10 -10
- package/templates/README.md +8 -8
- package/templates/inbound-lead/agent.md +5 -4
- package/templates/inbound-lead/evals/learned-correction/case.yaml +3 -3
- package/templates/inbound-lead/evals/learned-correction/fixtures/corrections.md +1 -0
- package/templates/inbound-lead/evals/learned-correction/graders/applies-correction.md +22 -0
- package/templates/inbound-lead/evals/learned-correction/graders/learned-origin.md +1 -1
- package/templates/inbound-lead/evals/learned-correction/prompt.md +1 -1
- package/templates/inbound-lead/lead.schema.json +6 -5
- package/templates/inbound-lead/rules/RUBRIC.md +4 -4
- package/templates/inbound-lead/skills/lead/SKILL.md +4 -4
- package/templates/kyb/agent.md +2 -1
- package/templates/market-monitor/evals/learned-preference/case.yaml +4 -4
- package/templates/market-monitor/evals/learned-preference/fixtures/corrections.md +1 -0
- package/templates/market-monitor/evals/learned-preference/graders/omits-junior-post.md +3 -3
- package/templates/market-monitor/evals/learned-preference/prompt.md +1 -1
- package/templates/release-notes/evals/learned-style/case.yaml +4 -4
- package/templates/release-notes/evals/learned-style/fixtures/corrections.md +1 -0
- package/templates/release-notes/evals/learned-style/graders/same-changes.md +2 -2
- package/templates/release-notes/evals/learned-style/prompt.md +1 -1
- package/dist/console/assets/index-BUktRvS-.css +0 -1
- package/dist/console/assets/index-nB9kTfIN.js +0 -711
- package/dist/learn/grade.d.ts +0 -138
- package/dist/learn/grade.js +0 -682
- package/dist/learn/notes.d.ts +0 -81
- package/dist/learn/notes.js +0 -178
- package/dist/learn/reflect.d.ts +0 -77
- package/dist/learn/reflect.js +0 -228
- package/dist/learn/relevance.d.ts +0 -24
- package/dist/learn/relevance.js +0 -91
- package/dist/learn/seed-check.d.ts +0 -74
- package/dist/learn/seed-check.js +0 -103
- package/dist/learning-batch.d.ts +0 -291
- package/dist/learning-batch.js +0 -600
- package/dist/learning-evals.d.ts +0 -35
- package/dist/learning-evals.js +0 -99
- package/dist/native/context.d.ts +0 -6
- package/dist/native/context.js +0 -22
- package/dist/propose.d.ts +0 -52
- package/dist/propose.js +0 -224
- package/dist/runner/learning-ask.d.ts +0 -47
- package/dist/runner/learning-ask.js +0 -128
- package/dist/runner/learning-dispatch.d.ts +0 -45
- package/dist/runner/learning-dispatch.js +0 -99
- package/dist/runner/learning-factory.d.ts +0 -16
- package/dist/runner/learning-factory.js +0 -50
- package/dist/runner/learning-loop.d.ts +0 -273
- package/dist/runner/learning-loop.js +0 -521
- package/dist/usage.d.ts +0 -11
- package/dist/usage.js +0 -11
- package/templates/inbound-lead/evals/learned-correction/fixtures/learning/MEMORY.md +0 -1
- package/templates/inbound-lead/evals/learned-correction/fixtures/learning/no-agencies.md +0 -14
- package/templates/inbound-lead/evals/learned-correction/graders/applies-note.md +0 -21
- package/templates/market-monitor/evals/learned-preference/fixtures/learning/MEMORY.md +0 -1
- package/templates/market-monitor/evals/learned-preference/fixtures/learning/skip-junior-job-posts.md +0 -8
- package/templates/release-notes/evals/learned-style/fixtures/learning/MEMORY.md +0 -1
- package/templates/release-notes/evals/learned-style/fixtures/learning/say-agent-not-bot.md +0 -13
package/dist/live-reach.d.ts
CHANGED
|
@@ -33,5 +33,28 @@ export declare function runnerLiveOf(env: {
|
|
|
33
33
|
readonly AGENTRUN_RUNNER_LIVE_HOST?: string | undefined;
|
|
34
34
|
readonly AGENTRUN_RUNNER_LIVE_BIND?: string | undefined;
|
|
35
35
|
}, sealKey: Buffer): RunnerLive | undefined;
|
|
36
|
-
/**
|
|
37
|
-
export declare
|
|
36
|
+
/** The server's reach for run `runId`'s viewers: its hosts, under that run's key. */
|
|
37
|
+
export declare const reachForRun: (reach: LiveReach, runId: string) => LiveReach;
|
|
38
|
+
/** A runner's live address for run `runId`'s viewers: its host and bind, under that run's key. */
|
|
39
|
+
export declare const liveForRun: (live: RunnerLive, runId: string) => RunnerLive;
|
|
40
|
+
/** Whether `req` carries a good, fresh proof for viewer `viewerId` under `live`'s key: its time within `windowMs` of
|
|
41
|
+
* the endpoint's clock (LIVE_PROOF_MS by default). */
|
|
42
|
+
export declare function provenFor(req: Pick<IncomingMessage, "headers">, live: Pick<RunnerLive, "key">, viewerId: string, now?: number, windowMs?: number): boolean;
|
|
43
|
+
/** How far a relay's proof's time may be from the runner's clock: the one hop's time, and no more. */
|
|
44
|
+
export declare const RELAY_PROOF_MS = 10000;
|
|
45
|
+
/** What a relay's proof binds: the machine's token (its SHA-256), the runner its row names, and that runner's
|
|
46
|
+
* incarnation. A viewer's id has no newline, so no relay subject is ever a viewer's. */
|
|
47
|
+
export type RelayTo = {
|
|
48
|
+
readonly tokenSha256: string;
|
|
49
|
+
readonly runner: string;
|
|
50
|
+
readonly incarnation: string;
|
|
51
|
+
};
|
|
52
|
+
/** The server's proof for relaying the dial of token `to.tokenSha256` to runner `to.runner`, at `at` (ms). */
|
|
53
|
+
export declare const relayProof: (reach: Pick<LiveReach, "key">, to: RelayTo, at?: number) => string;
|
|
54
|
+
/** The proof's key, from the seal key, for a runner's attach listener (whatever host it answers on). */
|
|
55
|
+
export declare const relayKeyOf: (sealKey: Buffer) => Pick<LiveReach, "key">;
|
|
56
|
+
/** A runner's check of the relay's proofs: good, fresh (RELAY_PROOF_MS) and for `to`, and never one it took before, so
|
|
57
|
+
* a proof read off the hop opens no second socket. A proof is taken once by its MAC, not by the header as sent: the
|
|
58
|
+
* time reads as a number, so `0<ms>.<mac>` is the same signed proof as `<ms>.<mac>`, while the MAC (lower-case hex
|
|
59
|
+
* only) has one spelling for each subject and time. */
|
|
60
|
+
export declare function relayProofs(live: Pick<LiveReach, "key">, now?: () => number): (req: Pick<IncomingMessage, "headers">, to: RelayTo) => boolean;
|
package/dist/live-reach.js
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
// host only when it is one of its runners' (AGENTRUN_RUNNER_HOSTS, a comma list), else the row reads as no viewer: a
|
|
5
5
|
// store writer that is no runner can't aim the server's socket elsewhere. Each request the server makes of a runner's
|
|
6
6
|
// viewer (the HEAD that asks whether it answers, and the proxied WebSocket) carries the proxy's proof: an HMAC of the
|
|
7
|
-
// viewer's id and the time, under
|
|
7
|
+
// viewer's id and the time, under the viewer's run's key (reachForRun, liveForRun), derived from a key derived from the
|
|
8
|
+
// seal key the server and its runners already share. A runner's
|
|
8
9
|
// endpoint off loopback takes no request without a good, fresh proof for its own viewer. The proof is not the viewer's:
|
|
9
10
|
// the hello's token still decides who watches. The hop is plain HTTP, for a private network (the server and its
|
|
10
11
|
// runners' own); TLS on it is a later step.
|
|
@@ -47,16 +48,57 @@ export function runnerLiveOf(env, sealKey) {
|
|
|
47
48
|
const bind = env.AGENTRUN_RUNNER_LIVE_BIND?.trim().toLowerCase();
|
|
48
49
|
return { host, bind: bind && (isLiveHost(bind) || bind === "0.0.0.0") ? bind : host, key: proofKey(sealKey) };
|
|
49
50
|
}
|
|
50
|
-
/**
|
|
51
|
-
|
|
51
|
+
/** A run's own proof key, from the runners' shared one: what proves a request for one run's viewers and no other's. A
|
|
52
|
+
* run's own process is handed its run's (held.ts liveAt), never the shared key, so it can open no other run's viewer. */
|
|
53
|
+
const runKey = (key, runId) => createHmac("sha256", key).update(`${RUN_LABEL}\n${runId}`).digest();
|
|
54
|
+
/** The run label of runKey: another MAC than the proof's own. */
|
|
55
|
+
const RUN_LABEL = "agentrun live run v1";
|
|
56
|
+
/** The server's reach for run `runId`'s viewers: its hosts, under that run's key. */
|
|
57
|
+
export const reachForRun = (reach, runId) => ({ hosts: reach.hosts, key: runKey(reach.key, runId) });
|
|
58
|
+
/** A runner's live address for run `runId`'s viewers: its host and bind, under that run's key. */
|
|
59
|
+
export const liveForRun = (live, runId) => ({ host: live.host, bind: live.bind, key: runKey(live.key, runId) });
|
|
60
|
+
/** Whether `req` carries a good, fresh proof for viewer `viewerId` under `live`'s key: its time within `windowMs` of
|
|
61
|
+
* the endpoint's clock (LIVE_PROOF_MS by default). */
|
|
62
|
+
export function provenFor(req, live, viewerId, now = Date.now(), windowMs = LIVE_PROOF_MS) {
|
|
52
63
|
const said = req.headers[LIVE_PROOF_HEADER];
|
|
53
64
|
const match = typeof said === "string" ? /^(\d{1,16})\.([0-9a-f]{64})$/.exec(said) : null;
|
|
54
65
|
if (!match)
|
|
55
66
|
return false;
|
|
56
67
|
const at = Number(match[1]);
|
|
57
|
-
if (!Number.isSafeInteger(at) || Math.abs(now - at) >
|
|
68
|
+
if (!Number.isSafeInteger(at) || Math.abs(now - at) > windowMs)
|
|
58
69
|
return false;
|
|
59
70
|
const want = Buffer.from(mac(live.key, viewerId, at), "hex");
|
|
60
71
|
const got = Buffer.from(match[2], "hex");
|
|
61
72
|
return got.length === want.length && timingSafeEqual(got, want);
|
|
62
73
|
}
|
|
74
|
+
// A dial relayed to its runner (dial-relay.ts): a machine a runner in a process of its own made dials the server's
|
|
75
|
+
// attach route, and the server proxies its socket to that runner's attach listener with the same proof, under the same
|
|
76
|
+
// key, over a subject of its own. The subject binds the machine's token (its SHA-256), the runner the token's row names
|
|
77
|
+
// and that runner's incarnation (its process since its start), so a proof opens that one token's socket on that one
|
|
78
|
+
// runner and nowhere else. Its window is RELAY_PROOF_MS, and the runner takes each proof once (relayProofs).
|
|
79
|
+
/** How far a relay's proof's time may be from the runner's clock: the one hop's time, and no more. */
|
|
80
|
+
export const RELAY_PROOF_MS = 10_000;
|
|
81
|
+
const relaySubject = (to) => `attach relay\n${to.tokenSha256}\n${to.runner}\n${to.incarnation}`;
|
|
82
|
+
/** The server's proof for relaying the dial of token `to.tokenSha256` to runner `to.runner`, at `at` (ms). */
|
|
83
|
+
export const relayProof = (reach, to, at = Date.now()) => liveProof(reach, relaySubject(to), at);
|
|
84
|
+
/** The proof's key, from the seal key, for a runner's attach listener (whatever host it answers on). */
|
|
85
|
+
export const relayKeyOf = (sealKey) => ({ key: proofKey(sealKey) });
|
|
86
|
+
/** A runner's check of the relay's proofs: good, fresh (RELAY_PROOF_MS) and for `to`, and never one it took before, so
|
|
87
|
+
* a proof read off the hop opens no second socket. A proof is taken once by its MAC, not by the header as sent: the
|
|
88
|
+
* time reads as a number, so `0<ms>.<mac>` is the same signed proof as `<ms>.<mac>`, while the MAC (lower-case hex
|
|
89
|
+
* only) has one spelling for each subject and time. */
|
|
90
|
+
export function relayProofs(live, now = Date.now) {
|
|
91
|
+
const taken = new Map();
|
|
92
|
+
return (req, to) => {
|
|
93
|
+
const at = now();
|
|
94
|
+
for (const [proof, until] of taken)
|
|
95
|
+
if (until < at)
|
|
96
|
+
taken.delete(proof);
|
|
97
|
+
const said = req.headers[LIVE_PROOF_HEADER];
|
|
98
|
+
const signed = typeof said === "string" ? said.slice(said.indexOf(".") + 1) : undefined;
|
|
99
|
+
if (signed === undefined || taken.has(signed) || !provenFor(req, live, relaySubject(to), at, RELAY_PROOF_MS))
|
|
100
|
+
return false;
|
|
101
|
+
taken.set(signed, at + 2 * RELAY_PROOF_MS);
|
|
102
|
+
return true;
|
|
103
|
+
};
|
|
104
|
+
}
|
package/dist/llms.txt
CHANGED
|
@@ -18,7 +18,7 @@ Auth: the API's routes take `Authorization: Bearer <token>`, all but `GET /v2/he
|
|
|
18
18
|
- `POST /v2/agents/{id}/runs` with `{input, file_ids?, effort?, revision?}` starts a run, answered at once, queued. An agentic run's input is `{content: "the first message"}`. An `Idempotency-Key` header makes a retry safe.
|
|
19
19
|
- `POST /v2/files?path=notes.md` with the file's bytes as the body (`curl --data-binary @notes.md`) uploads a file, answered `201` with the file, ready, its `file_id` under `file`. Name it in a run's `file_ids`, and the run finds it at `inputs/notes.md`. `GET /v2/files` lists the uploads, `DELETE /v2/files/{id}` removes one.
|
|
20
20
|
- `GET /v2/runs/{id}`: status (`queued`, `working`, `input_required`, `completed`, `failed`, `cancelled`, `paused`), `result` (`final_answer`, or a workflow's `output`), `error`, `cost` (`usd` is null while unknown, never $0), `path` (`agent`, `workflow`, `handed_back`; null until it ends).
|
|
21
|
-
- An agent that learns: a run its learned workflow served (`path` `workflow`) has the workflow's answer as `result.final_answer`; one handed back (`handed_back`) has the agent's. Its timeline is its `user_message`, the learned_workflow `tool_use` and `tool_result` (its nodes in `learned_nodes`; they write no `decision` rows), then `final_answer` and `usage`; a hand-back puts a `phase` row and the agent's own rows before them. Learning spends on the agent's own model route, key and cap: on `GET /v2/runs/{id}`, `cost.usd` is the run's own spend, the job's; `cost.learning_usd` what learning spent for it (its
|
|
21
|
+
- An agent that learns: a run its learned workflow served (`path` `workflow`) has the workflow's answer as `result.final_answer`; one handed back (`handed_back`) has the agent's. Its timeline is its `user_message`, the learned_workflow `tool_use` and `tool_result` (its nodes in `learned_nodes`; they write no `decision` rows), then `final_answer` and `usage`; a hand-back puts a `phase` row and the agent's own rows before them. Learning spends on the agent's own model route, key and cap: on `GET /v2/runs/{id}`, `cost.usd` is the run's own spend, the job's; `cost.learning_usd` what learning spent for it (its audit's shadow run and its share of its workflow revision's compile turn and check, spread over the revision's first `compile_after` served runs; a compile that kept no draft is on no run, in the bill's `unattributed_usd`), `cost.all_in_usd` both. A shadow run is in no run list and sends no webhook. `GET /v2/agents/{id}/learning/cost` has the agent's whole bill (`bill`).
|
|
22
22
|
- `GET /v2/runs/{id}/timeline?after=0&limit=100` pages its steps; follow `next_after` until a page is `final` with `has_more` false.
|
|
23
23
|
- `GET /v2/runs/{id}/files`, then `GET /v2/runs/{id}/files/{path}`: what it wrote.
|
|
24
24
|
- `POST /v2/runs/{id}/messages` with `{content}` answers a run that asked a question (`input_required`), or follows up; `POST /v2/runs/{id}/cancel` ends one.
|
package/dist/local-models.d.ts
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
import type { Api, Model, MutableModels } from "@earendil-works/pi-ai";
|
|
2
2
|
import { type ModelPrice } from "@parcha/agentrun-kernel/kernel/cap";
|
|
3
|
-
|
|
4
|
-
* 2026-11-07: $0.25 input, $0.03 cached input, $1.00 output; no cache-write price, so $0). */
|
|
5
|
-
export declare const PARTICLE_1_PRICE: {
|
|
6
|
-
readonly input: 0.25;
|
|
7
|
-
readonly output: 1;
|
|
8
|
-
readonly cacheRead: 0.03;
|
|
9
|
-
readonly cacheWrite: 0;
|
|
10
|
-
};
|
|
3
|
+
export { PARTICLE_1_PRICE } from "./particle-provider.js";
|
|
11
4
|
/** How a model takes its tools: "native", the request's own tools parameter (every model pi-ai lists), or "text", the
|
|
12
5
|
* tools described in its system prompt and its calls read back from its reply (runner/text-tools.ts, on the runner's
|
|
13
6
|
* translated route, runner/model-route.ts). A wire format of the model's provider, not a choice of a task's. */
|
|
@@ -60,7 +53,6 @@ export declare function isFree(model: {
|
|
|
60
53
|
api?: string;
|
|
61
54
|
cost?: ModelPrice | null;
|
|
62
55
|
}): boolean;
|
|
63
|
-
/** `models`
|
|
64
|
-
* ADDED_MODELS
|
|
65
|
-
* overridden price, with its toolsAs, and an added model as if the catalog listed it. */
|
|
56
|
+
/** `models` with serve's direct Particle provider registered, PRICE_OVERRIDES on the built-in providers' entries,
|
|
57
|
+
* and ADDED_MODELS beside them. Requests, prices and capability reads use this same catalog. */
|
|
66
58
|
export declare function withLocalModels<M extends MutableModels>(models: M): M;
|
package/dist/local-models.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { freeModel, ROUTERS } from "@parcha/agentrun-kernel/kernel/cap";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export const PARTICLE_1_PRICE = { input: 0.25, output: 1, cacheRead: 0.03, cacheWrite: 0 };
|
|
2
|
+
import { PARTICLE_1_PRICE, particleProvider } from "./particle-provider.js";
|
|
3
|
+
export { PARTICLE_1_PRICE } from "./particle-provider.js";
|
|
5
4
|
/** What serve sets over pi-ai's own catalog entries, by provider and id: a price (`cost`), and how the model takes its
|
|
6
5
|
* tools (`toolsAs`, absent: native). pi-ai 1.5.0 lists particle-ai/particle-1 at
|
|
7
6
|
* OpenRouter's current promotional price ($0.05 input, $0.003 cache read, $0.50 output). A run's cap holds each request
|
|
@@ -64,10 +63,10 @@ export const isRouter = (provider, id) => provider === "openrouter" && ROUTERS.h
|
|
|
64
63
|
export function isFree(model) {
|
|
65
64
|
return freeModel({ id: model.id, api: model.api ?? "", price: model.cost ?? null, outputCeiling: null });
|
|
66
65
|
}
|
|
67
|
-
/** `models`
|
|
68
|
-
* ADDED_MODELS
|
|
69
|
-
* overridden price, with its toolsAs, and an added model as if the catalog listed it. */
|
|
66
|
+
/** `models` with serve's direct Particle provider registered, PRICE_OVERRIDES on the built-in providers' entries,
|
|
67
|
+
* and ADDED_MODELS beside them. Requests, prices and capability reads use this same catalog. */
|
|
70
68
|
export function withLocalModels(models) {
|
|
69
|
+
models.setProvider(particleProvider());
|
|
71
70
|
for (const providerId of new Set([...PRICE_OVERRIDES, ...ADDED_MODELS].map((entry) => entry.provider))) {
|
|
72
71
|
const own = models.getProvider(providerId);
|
|
73
72
|
if (!own)
|
|
@@ -144,7 +144,7 @@ export declare class McpServersOverStore {
|
|
|
144
144
|
headers?: string[] | undefined;
|
|
145
145
|
type: string;
|
|
146
146
|
};
|
|
147
|
-
credential: "sealed" | "
|
|
147
|
+
credential: "sealed" | "unreadable" | "expired" | null;
|
|
148
148
|
not_metered?: string[] | undefined;
|
|
149
149
|
tools: {
|
|
150
150
|
grant_problems?: Record<string, string>;
|
|
@@ -185,7 +185,7 @@ export declare class McpServersOverStore {
|
|
|
185
185
|
headers?: string[] | undefined;
|
|
186
186
|
type: string;
|
|
187
187
|
};
|
|
188
|
-
credential: "sealed" | "
|
|
188
|
+
credential: "sealed" | "unreadable" | "expired" | null;
|
|
189
189
|
not_metered?: string[] | undefined;
|
|
190
190
|
tools: {
|
|
191
191
|
grant_problems?: Record<string, string>;
|
|
@@ -255,7 +255,7 @@ export declare class McpServersOverStore {
|
|
|
255
255
|
headers?: string[] | undefined;
|
|
256
256
|
type: string;
|
|
257
257
|
};
|
|
258
|
-
credential: "sealed" | "
|
|
258
|
+
credential: "sealed" | "unreadable" | "expired" | null;
|
|
259
259
|
not_metered?: string[] | undefined;
|
|
260
260
|
tools: {
|
|
261
261
|
grant_problems?: Record<string, string>;
|
|
@@ -300,7 +300,7 @@ export declare class McpServersOverStore {
|
|
|
300
300
|
headers?: string[] | undefined;
|
|
301
301
|
type: string;
|
|
302
302
|
};
|
|
303
|
-
credential: "sealed" | "
|
|
303
|
+
credential: "sealed" | "unreadable" | "expired" | null;
|
|
304
304
|
not_metered?: string[] | undefined;
|
|
305
305
|
tools: {
|
|
306
306
|
grant_problems?: Record<string, string>;
|
package/dist/model-form.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// uses when a model is named in a form it does not take. One list, served in capabilities (`harnesses[].models`) and read
|
|
3
3
|
// by the console's Model picker, so the picker, the save's refusal and a run's refusal never name different forms.
|
|
4
4
|
// A leaf of model.ts and provider.ts (it reads their tables only when called, never as it loads).
|
|
5
|
-
import {
|
|
5
|
+
import { adapterFactsOf } from "./adapter-facts.js";
|
|
6
6
|
import { FAUX_ENV, MODEL_KEYS } from "./model.js";
|
|
7
7
|
import { openRouterName } from "./provider.js";
|
|
8
8
|
import { WIRES } from "./wires.js";
|
|
@@ -15,10 +15,11 @@ import { PLAN_HARNESSES } from "./harness.js";
|
|
|
15
15
|
export const PICKABLE = Object.freeze([
|
|
16
16
|
{ vendor: "anthropic", ids: Object.freeze(["claude-sonnet-5-5", "claude-opus-5-5", "claude-haiku-5-5", "claude-fable-5-2"]) },
|
|
17
17
|
{ vendor: "openai", ids: Object.freeze(["gpt-6.1-sol", "gpt-6.1-terra", "gpt-6-luna"]) },
|
|
18
|
+
{ vendor: "particle", ids: Object.freeze(["particle-1"]) },
|
|
18
19
|
]);
|
|
19
20
|
/** The vendors whose models `harness` runs: pi any; an adapter harness, its wire's vendor. */
|
|
20
21
|
const vendorsOf = (harness) => {
|
|
21
|
-
const facts =
|
|
22
|
+
const facts = adapterFactsOf(harness);
|
|
22
23
|
return facts ? [WIRES[facts.wire].vendor] : PICKABLE.map((p) => p.vendor);
|
|
23
24
|
};
|
|
24
25
|
/** `vendor`'s model `id` in the form this server runs it: `vendor/id` on the vendor's own key, or through OpenRouter
|
|
@@ -26,7 +27,7 @@ const vendorsOf = (harness) => {
|
|
|
26
27
|
export function formOf(env, vendor, id) {
|
|
27
28
|
const row = MODEL_KEYS.find((r) => r.id === vendor);
|
|
28
29
|
if (row && !env[row.field] && env.OPENROUTER_API_KEY)
|
|
29
|
-
return `openrouter/${vendor}/${vendor === "anthropic" ? openRouterName(id) : id}`;
|
|
30
|
+
return `openrouter/${vendor === "particle" ? "particle-ai" : vendor}/${vendor === "anthropic" ? openRouterName(id) : id}`;
|
|
30
31
|
return `${vendor}/${id}`;
|
|
31
32
|
}
|
|
32
33
|
/** The models offered for `harness` on this server, each in the form it takes, before the harness's own catalog is asked
|
|
@@ -37,7 +38,7 @@ export function pickerCandidates(env, harness) {
|
|
|
37
38
|
return [];
|
|
38
39
|
// The gateway serves the harnesses whose wire goes through it (pi, and the OpenAI Responses wire: providerFor); the
|
|
39
40
|
// Anthropic Messages wire never does, so Claude is offered Anthropic's models on its own key.
|
|
40
|
-
const facts =
|
|
41
|
+
const facts = adapterFactsOf(harness);
|
|
41
42
|
if (env.AGENT_MODEL_BASE_URL && facts?.wire !== "anthropic-messages")
|
|
42
43
|
return [...new Set([env.AGENT_MODEL, env.AGENT_MODEL_FAST, env.AGENT_MODEL_STRONG].filter((id) => Boolean(id)))];
|
|
43
44
|
const vendors = vendorsOf(harness);
|
|
@@ -50,7 +51,7 @@ export function pickerCandidates(env, harness) {
|
|
|
50
51
|
* pi with OpenRouter's key, by id. None for an adapter harness (each runs its own wire's vendor), behind a gateway (its
|
|
51
52
|
* ids are its own) or with the faux model. */
|
|
52
53
|
export async function freeCandidates(env, harness) {
|
|
53
|
-
if (env[FAUX_ENV] || env.AGENT_MODEL_BASE_URL || !env.OPENROUTER_API_KEY ||
|
|
54
|
+
if (env[FAUX_ENV] || env.AGENT_MODEL_BASE_URL || !env.OPENROUTER_API_KEY || adapterFactsOf(harness))
|
|
54
55
|
return [];
|
|
55
56
|
const [{ builtinModels }, { withLocalModels, isFree }] = await Promise.all([import("@earendil-works/pi-ai/providers/all"), import("./local-models.js")]);
|
|
56
57
|
return withLocalModels(builtinModels()).getModels("openrouter").filter(isFree)
|
package/dist/model.d.ts
CHANGED
|
@@ -53,6 +53,10 @@ export declare const MODEL_KEYS: readonly {
|
|
|
53
53
|
harnesses: readonly string[];
|
|
54
54
|
byVendor?: Readonly<Record<string, string>>;
|
|
55
55
|
}[];
|
|
56
|
+
/** The harnesses `row`'s key runs on `env`'s server: its own (`harnesses`), then each harness this server lists only once its
|
|
57
|
+
* owner installs it (Goose: harness-table.ts hidden, listed by harnessIds) whose wire runs the row's vendor's models, or
|
|
58
|
+
* any, on OpenRouter's. One not installed here is never named. */
|
|
59
|
+
export declare function keyHarnesses(row: (typeof MODEL_KEYS)[number], env: NodeJS.ProcessEnv): readonly string[];
|
|
56
60
|
/** What a person does when no model runs here: add a model provider's key in the console, or set one where AgentRun
|
|
57
61
|
* starts (MODEL_KEYS' fields), OpenRouter's named first, as its one key runs every harness. The order a default is
|
|
58
62
|
* taken in is MODEL_KEYS' own. */
|
package/dist/model.js
CHANGED
|
@@ -8,14 +8,15 @@
|
|
|
8
8
|
import { isRouter, withLocalModels } from "./local-models.js";
|
|
9
9
|
import { pathToFileURL } from "node:url";
|
|
10
10
|
import { DEFAULT_HARNESS, PLAN_HARNESSES } from "./harness.js";
|
|
11
|
-
import { HARNESS_MODULES_ENV, HARNESS_TABLE_ENV, harnessOf } from "./harness-table.js";
|
|
12
|
-
import { gatewayBase } from "./provider.js";
|
|
11
|
+
import { builtinHarness, HARNESS_MODULES_ENV, HARNESS_TABLE_ENV, harnessIds, harnessOf } from "./harness-table.js";
|
|
12
|
+
import { gatewayBase, modelGatewayBase } from "./provider.js";
|
|
13
13
|
import { modelFormWhy } from "./model-form.js";
|
|
14
14
|
// Leaves, which the key rows below read as this module loads, in any import order (wires.ts, adapter-facts.ts).
|
|
15
|
-
import { ADAPTER_FACTS } from "./adapter-facts.js";
|
|
15
|
+
import { ADAPTER_FACTS, adapterFactsOf } from "./adapter-facts.js";
|
|
16
16
|
import { WIRES } from "./wires.js";
|
|
17
17
|
import { authContextOf } from "./secrets.js";
|
|
18
18
|
import { EXPIRED, PLAN_DEFAULT_MODEL, PLAN_ORIGIN, PLAN_PROVIDER, planOf, signedIn, SIGNED_OUT } from "./chatgpt-plan.js";
|
|
19
|
+
import { LOGIN_DEFAULT_MODEL, onClaudeLogin } from "./claude-login.js";
|
|
19
20
|
/** The child's environment names the faux module by absolute path. */
|
|
20
21
|
export const FAUX_ENV = "AGENTRUN_SERVE_FAUX";
|
|
21
22
|
/** Every test hook's name starts so (AGENTRUN_SERVE_FAUX, AGENTRUN_SERVE_FAUX_WEB, ...), but the harness table's
|
|
@@ -59,16 +60,28 @@ export const MODEL_NODES = ["agent", "decide", "extract", "report"];
|
|
|
59
60
|
export const MODEL_KEYS = Object.freeze([
|
|
60
61
|
{ id: "anthropic", label: "Anthropic", field: "ANTHROPIC_API_KEY", model: "anthropic/claude-sonnet-5-5", harnesses: onVendor("anthropic") },
|
|
61
62
|
{ id: "openai", label: "OpenAI", field: "OPENAI_API_KEY", model: "openai/gpt-6.1-sol", harnesses: onVendor("openai") },
|
|
63
|
+
// Particle's direct API is Chat Completions; the adapter harnesses need Messages or HTTP Responses.
|
|
64
|
+
{ id: "particle", label: "Particle", field: "PARTICLE_API_KEY", model: "particle/particle-1", harnesses: [DEFAULT_HARNESS] },
|
|
62
65
|
// OpenRouter serves both wires: every harness runs on its key, an adapter harness on its wire's vendor's model there.
|
|
63
66
|
{ id: "openrouter", label: "OpenRouter", field: "OPENROUTER_API_KEY", model: "openrouter/openai/gpt-6.1-sol", harnesses: [DEFAULT_HARNESS, ...ADAPTER_FACTS.map((facts) => facts.id)], byVendor: { anthropic: "anthropic/claude-sonnet-5.5", openai: "openai/gpt-6.1-sol" } },
|
|
64
67
|
]);
|
|
65
|
-
/** pi, and the adapter harnesses whose wire (their facts') runs `vendor`'s models: those that talk to its own API. */
|
|
68
|
+
/** pi, and the built-in adapter harnesses whose wire (their facts') runs `vendor`'s models: those that talk to its own API. */
|
|
66
69
|
function onVendor(vendor) {
|
|
67
70
|
return [DEFAULT_HARNESS, ...ADAPTER_FACTS.filter((facts) => WIRES[facts.wire].vendor === vendor).map((facts) => facts.id)];
|
|
68
71
|
}
|
|
72
|
+
/** The harnesses `row`'s key runs on `env`'s server: its own (`harnesses`), then each harness this server lists only once its
|
|
73
|
+
* owner installs it (Goose: harness-table.ts hidden, listed by harnessIds) whose wire runs the row's vendor's models, or
|
|
74
|
+
* any, on OpenRouter's. One not installed here is never named. */
|
|
75
|
+
export function keyHarnesses(row, env) {
|
|
76
|
+
const installed = harnessIds(env).filter((id) => !row.harnesses.includes(id) && builtinHarness(id)?.hidden !== undefined);
|
|
77
|
+
return [...row.harnesses, ...installed.filter((id) => {
|
|
78
|
+
const facts = adapterFactsOf(id);
|
|
79
|
+
return facts !== undefined && (row.id === "openrouter" || WIRES[facts.wire].vendor === row.id);
|
|
80
|
+
})];
|
|
81
|
+
}
|
|
69
82
|
/** `row`'s default for `harness`: the one for its wire's vendor (`byVendor`, OpenRouter's), else the row's. */
|
|
70
83
|
const rowModel = (row, harness) => {
|
|
71
|
-
const facts =
|
|
84
|
+
const facts = adapterFactsOf(harness);
|
|
72
85
|
return (facts && row.byVendor?.[WIRES[facts.wire].vendor]) ?? row.model;
|
|
73
86
|
};
|
|
74
87
|
/** What a person does when no model runs here: add a model provider's key in the console, or set one where AgentRun
|
|
@@ -112,7 +125,10 @@ export function hostModel(env, tier = "default", harness = DEFAULT_HARNESS) {
|
|
|
112
125
|
// Signed in to a ChatGPT plan, codex and pi run on it by default: a key's model is then named (`openai/<id>`).
|
|
113
126
|
if (PLAN_HARNESSES.includes(harness) && signedIn(env) && !env.AGENT_MODEL_BASE_URL)
|
|
114
127
|
return `${PLAN_PROVIDER}/${planModel(env)}`;
|
|
115
|
-
|
|
128
|
+
// On Claude Code's login on this machine, claude-agent runs Anthropic's model on it by default (provider.ts).
|
|
129
|
+
if (onClaudeLogin(env, harness))
|
|
130
|
+
return LOGIN_DEFAULT_MODEL;
|
|
131
|
+
const row = MODEL_KEYS.find((row) => env[row.field] && (row.harnesses.includes(harness) || keyHarnesses(row, env).includes(harness)));
|
|
116
132
|
return row ? rowModel(row, harness) : env[DEFAULT_MODEL_ENV] || undefined;
|
|
117
133
|
}
|
|
118
134
|
/** The plan's model a run that names none takes: GPT-6.1 Sol where the plan lists it, else the plan's first. */
|
|
@@ -196,7 +212,7 @@ export async function chooseModel(env, ref, tier = "default", harness = DEFAULT_
|
|
|
196
212
|
// A gateway its key may not go to (the one base rule, gatewayBase) runs no model, in its words: capabilities read it
|
|
197
213
|
// not ready, a save warns, and a run is refused before its process starts, so the key is never handed to one.
|
|
198
214
|
try {
|
|
199
|
-
|
|
215
|
+
modelGatewayBase(env.AGENT_MODEL_BASE_URL);
|
|
200
216
|
}
|
|
201
217
|
catch (error) {
|
|
202
218
|
return { why: error.message, host: true, needs: "key" };
|
|
@@ -257,7 +273,7 @@ async function pinnedChoice(env, { pinned, ref }, tier, harness) {
|
|
|
257
273
|
return { why: "This run started on the model gateway, and AGENT_MODEL_BASE_URL names none here.", host: true, needs: "key" };
|
|
258
274
|
// The one base rule (gatewayBase) holds for a pinned run as for any: its key never goes to a gateway it may not.
|
|
259
275
|
try {
|
|
260
|
-
|
|
276
|
+
modelGatewayBase(env.AGENT_MODEL_BASE_URL);
|
|
261
277
|
}
|
|
262
278
|
catch (error) {
|
|
263
279
|
return { why: error.message, host: true, needs: "key" };
|
|
@@ -301,6 +317,7 @@ export const PROVIDER_KEYS = {
|
|
|
301
317
|
opencode: ["OPENCODE_API_KEY"],
|
|
302
318
|
"opencode-go": ["OPENCODE_API_KEY"],
|
|
303
319
|
openrouter: ["OPENROUTER_API_KEY"],
|
|
320
|
+
particle: ["PARTICLE_API_KEY"],
|
|
304
321
|
"qwen-token-plan": ["QWEN_TOKEN_PLAN_API_KEY"],
|
|
305
322
|
"qwen-token-plan-cn": ["QWEN_TOKEN_PLAN_CN_API_KEY"],
|
|
306
323
|
"qwen-token-plan-individual": ["QWEN_TOKEN_PLAN_API_KEY"],
|
|
@@ -437,7 +454,7 @@ export async function runModels(env, ref, tiers = ["default"], harness = DEFAULT
|
|
|
437
454
|
// One base rule for every harness (provider.ts' gatewayBase): one trailing /v1 off, then the API under <base>/v1, so
|
|
438
455
|
// <gw>/api and <gw>/api/v1 both reach <gw>/api/v1/responses and <gw>/api/v1/messages, as OpenRouter serves them. pi-ai's
|
|
439
456
|
// Responses client takes the base with its /v1, its Messages client adds /v1/messages itself.
|
|
440
|
-
const base =
|
|
457
|
+
const base = modelGatewayBase(env.AGENT_MODEL_BASE_URL);
|
|
441
458
|
const baseUrl = `${base}/v1`;
|
|
442
459
|
const [{ openAIResponsesApi }, { anthropicMessagesApi }] = await Promise.all([import("@earendil-works/pi-ai/api/openai-responses.lazy"), import("@earendil-works/pi-ai/api/anthropic-messages.lazy")]);
|
|
443
460
|
const catalog = await catalogPrices();
|
package/dist/native/binding.js
CHANGED
|
@@ -49,7 +49,7 @@ export function nativeBindingOf(value) {
|
|
|
49
49
|
if (!b || typeof b !== 'object' || !['claude-code', 'codex'].includes(b.runtime) || typeof b.project !== 'string' || !isAbsolute(b.project) || b.project.includes('\0') || typeof b.machine_id !== 'string' || !b.machine_id || !b.selector || !['project', 'agent', 'profile'].includes(b.selector.kind) || (b.selector.kind !== 'project' && (typeof b.selector.name !== 'string' || !/^[\w.@+-]{1,160}$/.test(b.selector.name))) || typeof b.connected !== 'boolean' || typeof b.fingerprint !== 'string' || !Array.isArray(b.configuration) || !Array.isArray(b.skills) || !Array.isArray(b.mcp_servers) || !Array.isArray(b.issues) || !b.capabilities)
|
|
50
50
|
throw new Error('Invalid native connection: connect the source project using /native/connect.');
|
|
51
51
|
// Keep the defined metadata only. Never persist arbitrary configuration, environment or credentials.
|
|
52
|
-
return { runtime: b.runtime, project: b.project, selector: { kind: b.selector.kind, ...(b.selector.name ? { name: b.selector.name } : {}) }, machine_id: b.machine_id, version: typeof b.version === 'string' ? b.version : null, model: typeof b.model === 'string' ? b.model : null, fingerprint: b.fingerprint, configuration: b.configuration.map(c => ({ path: c.path, sha256: c.sha256 })), skills: b.skills.filter(x => typeof x === 'string'), mcp_servers: b.mcp_servers.filter(x => typeof x === 'string'), state: b.state, issues: b.issues.filter(x => typeof x === 'string'), capabilities: { launch: !!b.capabilities.launch,
|
|
52
|
+
return { runtime: b.runtime, project: b.project, selector: { kind: b.selector.kind, ...(b.selector.name ? { name: b.selector.name } : {}) }, machine_id: b.machine_id, version: typeof b.version === 'string' ? b.version : null, model: typeof b.model === 'string' ? b.model : null, fingerprint: b.fingerprint, configuration: b.configuration.map(c => ({ path: c.path, sha256: c.sha256 })), skills: b.skills.filter(x => typeof x === 'string'), mcp_servers: b.mcp_servers.filter(x => typeof x === 'string'), state: b.state, issues: b.issues.filter(x => typeof x === 'string'), capabilities: { launch: !!b.capabilities.launch, learning: !!b.capabilities.learning, workflows: false, approval: b.capabilities.approval === 'native' ? 'native' : 'unavailable', usage: !!b.capabilities.usage }, connected: b.connected, ...(typeof b.verified_at === 'string' ? { verified_at: b.verified_at } : {}), ...(b.remote ? { remote: { connector_id: b.remote.connector_id, target_id: b.remote.target_id } } : {}) };
|
|
53
53
|
}
|
|
54
54
|
export function nativeOf(body) {
|
|
55
55
|
const value = body?.native;
|
|
@@ -73,7 +73,7 @@ export async function verifyConnection(store, entry, env = nativeEnvironment())
|
|
|
73
73
|
if (native.state === 'ready') {
|
|
74
74
|
const snapshot = await snapshotNativeInstructions(native);
|
|
75
75
|
if (snapshot.incomplete || snapshot.truncated) {
|
|
76
|
-
native.capabilities = { ...native.capabilities,
|
|
76
|
+
native.capabilities = { ...native.capabilities, learning: false };
|
|
77
77
|
native.issues.push(`Self-improvement is unavailable: ${snapshot.incomplete ?? 'the declared native instruction files exceed the 64 KiB grading evidence limit.'} Native jobs remain available; no incomplete policy is automatically graded.`);
|
|
78
78
|
}
|
|
79
79
|
}
|
package/dist/native/discovery.js
CHANGED
|
@@ -371,7 +371,7 @@ export async function discoverNative(options) {
|
|
|
371
371
|
const config = (NATIVE_RUNTIME_FACTS[runtime].protocol === "claude-json" ? [...configuration] : [...configuration].sort(([a], [b]) => a.localeCompare(b))).map(([path, sha256]) => ({ path, sha256 }));
|
|
372
372
|
for (const selected of selectors) {
|
|
373
373
|
const ownModel = policyUnresolved ? null : selected.model === "inherit" ? model : selected.model ?? model;
|
|
374
|
-
const target = { runtime, project, selector: selected.selector, machine_id, version, model: ownModel, fingerprint: hash(JSON.stringify([runtime, version, selected.selector, config, ...(policyUnresolved ? [NATIVE_CLAUDE_POLICY_UNRESOLVED] : []), ...(additionalPolicyUnresolved ? [NATIVE_CLAUDE_ADDITIONAL_POLICY_UNRESOLVED] : [])])), configuration: config, skills: [...skills].sort(), mcp_servers: [...mcp].sort(), state: needsAttention ? "needs_attention" : "needs_verification", issues: [...issues], capabilities: { launch: supported,
|
|
374
|
+
const target = { runtime, project, selector: selected.selector, machine_id, version, model: ownModel, fingerprint: hash(JSON.stringify([runtime, version, selected.selector, config, ...(policyUnresolved ? [NATIVE_CLAUDE_POLICY_UNRESOLVED] : []), ...(additionalPolicyUnresolved ? [NATIVE_CLAUDE_ADDITIONAL_POLICY_UNRESOLVED] : [])])), configuration: config, skills: [...skills].sort(), mcp_servers: [...mcp].sort(), state: needsAttention ? "needs_attention" : "needs_verification", issues: [...issues], capabilities: { launch: supported, learning: supported && !policyUnresolved && !additionalPolicyUnresolved, workflows: false, approval: "unavailable", usage: supported } };
|
|
375
375
|
targets.push(target);
|
|
376
376
|
}
|
|
377
377
|
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import type { NativeBinding, NativeTarget } from "./types.js";
|
|
2
|
+
/** The most bytes (UTF-8) of a native or SDK run's standing instructions kept as its learning's evidence: a source policy
|
|
3
|
+
* past it is cut, and learning is skipped for the run. */
|
|
4
|
+
export declare const INSTRUCTION_EVIDENCE_BYTES = 65536;
|
|
2
5
|
export type NativeInstructionSnapshot = {
|
|
3
6
|
text: string;
|
|
4
7
|
files: {
|
|
@@ -2,8 +2,10 @@ import { readFile } from "node:fs/promises";
|
|
|
2
2
|
import { createHash } from "node:crypto";
|
|
3
3
|
import { basename, dirname, sep } from "node:path";
|
|
4
4
|
import { parse as parseToml } from "smol-toml";
|
|
5
|
-
import { NATIVE_GRADE_INSTRUCTION_BYTES } from "../learn/grade.js";
|
|
6
5
|
import { NATIVE_RUNTIME_FACTS, NATIVE_CLAUDE_POLICY_UNRESOLVED, NATIVE_CLAUDE_ADDITIONAL_POLICY_UNRESOLVED } from './runtimes.js';
|
|
6
|
+
/** The most bytes (UTF-8) of a native or SDK run's standing instructions kept as its learning's evidence: a source policy
|
|
7
|
+
* past it is cut, and learning is skipped for the run. */
|
|
8
|
+
export const INSTRUCTION_EVIDENCE_BYTES = 65_536;
|
|
7
9
|
const depth = (path) => path.split(sep).length;
|
|
8
10
|
const scopeOf = (path) => basename(dirname(path)) === ".claude" ? dirname(dirname(path)) : dirname(path);
|
|
9
11
|
/** Read-only, bounded policy evidence for grading. This text is never installed as grader runtime instructions. */
|
|
@@ -107,10 +109,10 @@ export function withSavedNativeInstructions(snapshot, instructions, redact) {
|
|
|
107
109
|
}
|
|
108
110
|
function boundedSnapshot(text, files, truncated, incomplete) {
|
|
109
111
|
const bytes = Buffer.from(text, "utf8");
|
|
110
|
-
if (bytes.length <=
|
|
112
|
+
if (bytes.length <= INSTRUCTION_EVIDENCE_BYTES)
|
|
111
113
|
return { text, files, truncated, ...(incomplete ? { incomplete } : {}) };
|
|
112
114
|
const marker = "\n\n[Native instruction snapshot truncated: additional standing policy was omitted. Do not assume the excerpt is complete.]";
|
|
113
|
-
let end =
|
|
115
|
+
let end = INSTRUCTION_EVIDENCE_BYTES - Buffer.byteLength(marker, "utf8"), prefix = "";
|
|
114
116
|
const decoder = new TextDecoder("utf-8", { fatal: true });
|
|
115
117
|
// A prefix must end on a whole UTF8 codepoint, including when a policy uses non-ASCII text.
|
|
116
118
|
for (let trim = 0; trim < 4; trim++) {
|
|
@@ -5,13 +5,11 @@ import { createHash } from 'node:crypto';
|
|
|
5
5
|
import { mkdir, mkdtemp, rm } from 'node:fs/promises';
|
|
6
6
|
import { tmpdir } from 'node:os';
|
|
7
7
|
import { join } from 'node:path';
|
|
8
|
-
import {
|
|
9
|
-
import { promisify, types } from 'node:util';
|
|
8
|
+
import { types } from 'node:util';
|
|
10
9
|
import { discoverNative, nativeIdentity, verifyNative } from './discovery.js';
|
|
11
10
|
import { nativeEnvironment } from './environment.js';
|
|
12
11
|
import { openNativeSession } from './runtime.js';
|
|
13
12
|
import { snapshotNativeInstructions } from './instructions.js';
|
|
14
|
-
import { nativeSkillContext } from './context.js';
|
|
15
13
|
import { exportRemoteHistory } from '../import.js';
|
|
16
14
|
import { runnerSecrets, secretRedactor } from '../runner/redact.js';
|
|
17
15
|
import { redactedOutput } from '../key-refusal.js';
|
|
@@ -156,19 +154,19 @@ export async function runRemoteWorkerBridge(options = {}) {
|
|
|
156
154
|
expireIdle(sessionKey);
|
|
157
155
|
}
|
|
158
156
|
}
|
|
159
|
-
if (type !== 'open'
|
|
157
|
+
if (type !== 'open')
|
|
160
158
|
throw new Error('Unsupported remote operation.');
|
|
161
159
|
const approved = await current(message.target), identity = nativeIdentity(approved);
|
|
162
|
-
const sessionKey =
|
|
160
|
+
const sessionKey = key(message.session_key);
|
|
163
161
|
if (sessions.has(sessionKey) || sessions.size >= 8)
|
|
164
162
|
throw new Error('The native session already exists or the source session limit was reached.');
|
|
165
163
|
signal.throwIfAborted();
|
|
166
|
-
if (
|
|
164
|
+
if ((typeof payload.expected_fingerprint !== 'string' || payload.expected_fingerprint !== approved.fingerprint))
|
|
167
165
|
throw new Error('The source configuration changed after preparation. Start a new run after reviewing it.');
|
|
168
166
|
const root = await mkdtemp(join(tmpdir(), 'agentrun-remote-'));
|
|
169
167
|
const locks = join(tmpdir(), `agentrun-native-locks-${process.getuid?.() ?? 'user'}`);
|
|
170
168
|
await mkdir(locks, { mode: 0o700, recursive: true });
|
|
171
|
-
const lock = join(locks, createHash('sha256').update(
|
|
169
|
+
const lock = join(locks, createHash('sha256').update(approved.project).digest('hex'));
|
|
172
170
|
try {
|
|
173
171
|
await mkdir(lock, { mode: 0o700 });
|
|
174
172
|
}
|
|
@@ -178,45 +176,13 @@ export async function runRemoteWorkerBridge(options = {}) {
|
|
|
178
176
|
}
|
|
179
177
|
let opened;
|
|
180
178
|
try {
|
|
181
|
-
|
|
182
|
-
if (type === 'grade') {
|
|
183
|
-
await promisify(execFile)('git', ['init', '--quiet', root], { timeout: 10_000 });
|
|
184
|
-
const report = await discoverNative({ project: root, runtime: approved.runtime, env });
|
|
185
|
-
target = { ...report.targets.find(item => item.selector.kind === 'project'), connected: true };
|
|
186
|
-
if (!target.runtime)
|
|
187
|
-
throw new Error('The native grading runtime is unavailable.');
|
|
188
|
-
context = '';
|
|
189
|
-
}
|
|
190
|
-
else if (payload.skills !== undefined) {
|
|
191
|
-
if (!Array.isArray(payload.skills) || payload.skills.length > 64)
|
|
192
|
-
throw new Error('Invalid learned skills.');
|
|
193
|
-
const skills = payload.skills.map(value => {
|
|
194
|
-
const skill = object(value), files = object(skill.files);
|
|
195
|
-
if (Object.keys(files).length > 128)
|
|
196
|
-
throw new Error('Too many learned skill resources.');
|
|
197
|
-
const read = {};
|
|
198
|
-
for (const [path, value] of Object.entries(files))
|
|
199
|
-
read[path] = text(value);
|
|
200
|
-
return { name: text(skill.name, 128), files: read };
|
|
201
|
-
});
|
|
202
|
-
if (Buffer.byteLength(JSON.stringify(skills)) > 2_000_000)
|
|
203
|
-
throw new Error('Learned skills exceed the source limit.');
|
|
204
|
-
context = [context, await nativeSkillContext(join(root, 'skills'), skills)].filter(Boolean).join('\n\n');
|
|
205
|
-
}
|
|
179
|
+
const context = payload.context === undefined ? '' : text(payload.context);
|
|
206
180
|
signal.throwIfAborted();
|
|
207
|
-
const session = opened = await openNativeSession({ target, context, env, signal, onEvent: event => { output({ event, session_key: sessionKey }); } });
|
|
181
|
+
const session = opened = await openNativeSession({ target: approved, context, env, signal, onEvent: event => { output({ event, session_key: sessionKey }); } });
|
|
208
182
|
signal.throwIfAborted();
|
|
209
183
|
sessions.set(sessionKey, { session, root, lock, identity });
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
return {};
|
|
213
|
-
}
|
|
214
|
-
try {
|
|
215
|
-
return await session.send(text(payload.prompt), { signal, reflection: true, timeoutMs: timeout(payload.timeout_ms) });
|
|
216
|
-
}
|
|
217
|
-
finally {
|
|
218
|
-
await close(sessionKey);
|
|
219
|
-
}
|
|
184
|
+
expireIdle(sessionKey);
|
|
185
|
+
return {};
|
|
220
186
|
}
|
|
221
187
|
catch (error) {
|
|
222
188
|
try {
|
package/dist/native/remote.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { Store } from '../store/store.js';
|
|
|
3
3
|
import type { NativeBinding, NativeEvent, NativeResult, NativeSession } from './types.js';
|
|
4
4
|
import type { NativeInstructionSnapshot } from './instructions.js';
|
|
5
5
|
export declare const REMOTE_COMPLETION_BODY_BYTES = 4000000;
|
|
6
|
-
export type RemoteCommandType = 'prepare' | 'open' | 'send' | 'close'
|
|
6
|
+
export type RemoteCommandType = 'prepare' | 'open' | 'send' | 'close';
|
|
7
7
|
export declare class RemoteConnectors {
|
|
8
8
|
readonly store: Store;
|
|
9
9
|
readonly now: () => number;
|
|
@@ -31,12 +31,11 @@ export declare class RemoteConnectors {
|
|
|
31
31
|
history_only: boolean;
|
|
32
32
|
runtime: "codex" | "claude-code";
|
|
33
33
|
machine_id: string;
|
|
34
|
-
state: "
|
|
34
|
+
state: "ready" | "needs_verification" | "needs_attention";
|
|
35
35
|
issues: string[];
|
|
36
36
|
capabilities: {
|
|
37
37
|
launch: boolean;
|
|
38
|
-
|
|
39
|
-
skills: boolean;
|
|
38
|
+
learning: boolean;
|
|
40
39
|
workflows: false;
|
|
41
40
|
approval: "native" | "unavailable";
|
|
42
41
|
usage: boolean;
|
|
@@ -69,12 +68,11 @@ export declare class RemoteConnectors {
|
|
|
69
68
|
history_only: boolean;
|
|
70
69
|
runtime: "codex" | "claude-code";
|
|
71
70
|
machine_id: string;
|
|
72
|
-
state: "
|
|
71
|
+
state: "ready" | "needs_verification" | "needs_attention";
|
|
73
72
|
issues: string[];
|
|
74
73
|
capabilities: {
|
|
75
74
|
launch: boolean;
|
|
76
|
-
|
|
77
|
-
skills: boolean;
|
|
75
|
+
learning: boolean;
|
|
78
76
|
workflows: false;
|
|
79
77
|
approval: "native" | "unavailable";
|
|
80
78
|
usage: boolean;
|
|
@@ -105,12 +103,11 @@ export declare class RemoteConnectors {
|
|
|
105
103
|
history_only: boolean;
|
|
106
104
|
runtime: "codex" | "claude-code";
|
|
107
105
|
machine_id: string;
|
|
108
|
-
state: "
|
|
106
|
+
state: "ready" | "needs_verification" | "needs_attention";
|
|
109
107
|
issues: string[];
|
|
110
108
|
capabilities: {
|
|
111
109
|
launch: boolean;
|
|
112
|
-
|
|
113
|
-
skills: boolean;
|
|
110
|
+
learning: boolean;
|
|
114
111
|
workflows: false;
|
|
115
112
|
approval: "native" | "unavailable";
|
|
116
113
|
usage: boolean;
|
|
@@ -174,14 +171,10 @@ export declare function checkedPrepared(before: NativeBinding, result: unknown):
|
|
|
174
171
|
};
|
|
175
172
|
export declare function remoteResult(value: unknown): NativeResult;
|
|
176
173
|
export declare function verifyRemote(store: Store, entry: AgentEntry): Promise<AgentEntry>;
|
|
177
|
-
/** A session transport only. Task
|
|
174
|
+
/** A session transport only. Task and end-of-run policy remains in the native loop and source runtime. */
|
|
178
175
|
export declare function openRemoteSession(broker: RemoteConnectors, target: NativeBinding, options: {
|
|
179
176
|
signal?: AbortSignal;
|
|
180
177
|
context?: string;
|
|
181
|
-
skills?: readonly {
|
|
182
|
-
name: string;
|
|
183
|
-
files?: Record<string, string>;
|
|
184
|
-
}[];
|
|
185
178
|
runId: string;
|
|
186
179
|
onEvent?: (event: NativeEvent) => Promise<void> | void;
|
|
187
180
|
}): Promise<NativeSession>;
|