@parcha/agentrun-serve 0.1.0-beta.51 → 0.1.0-beta.53
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 +160 -1
- package/README.md +306 -36
- package/dist/adapters.js +1 -1
- package/dist/agent-delete.d.ts +14 -4
- package/dist/agent-delete.js +30 -58
- package/dist/agent-package.d.ts +71 -0
- package/dist/agent-package.js +345 -0
- package/dist/agents-store.d.ts +28 -18
- package/dist/agents-store.js +48 -34
- package/dist/api-only.d.ts +30 -8
- package/dist/api-only.js +40 -16
- package/dist/archil-routes.d.ts +1 -0
- package/dist/archil-routes.js +28 -2
- package/dist/claude-login.d.ts +1 -0
- package/dist/claude-login.js +1 -1
- package/dist/cli-learning/cli.d.ts +3 -0
- package/dist/cli-learning/cli.js +17 -3
- package/dist/cli-learning/connections.js +3 -2
- package/dist/cli-learning/schema.js +2 -1
- package/dist/cli.js +70 -7
- package/dist/composio-preset.d.ts +2 -1
- package/dist/composio-preset.js +4 -3
- package/dist/composio-triggers.d.ts +4 -0
- package/dist/composio-triggers.js +4 -1
- package/dist/computer-needs.d.ts +32 -0
- package/dist/computer-needs.js +80 -0
- package/dist/computer-setting.d.ts +9 -0
- package/dist/computer-setting.js +19 -1
- package/dist/computers.d.ts +6 -2
- package/dist/computers.js +2 -2
- package/dist/console/assets/index-BFgyZzF_.js +734 -0
- package/dist/console/assets/index-DbilxljH.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/console-links.d.ts +1 -0
- package/dist/console-links.js +2 -0
- package/dist/env-switch.d.ts +14 -0
- package/dist/env-switch.js +23 -0
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +3 -0
- package/dist/eval-previous.js +4 -3
- package/dist/fal-price.d.ts +76 -0
- package/dist/fal-price.js +365 -0
- package/dist/handed-secret.d.ts +4 -0
- package/dist/handed-secret.js +10 -0
- package/dist/harness-archive.d.ts +15 -5
- package/dist/harness-archive.js +71 -34
- package/dist/harness-check.d.ts +2 -1
- package/dist/harness-check.js +36 -95
- package/dist/harness-egress.d.ts +23 -0
- package/dist/harness-egress.js +69 -0
- package/dist/harness-recipe-entry.d.ts +71 -0
- package/dist/harness-recipe-entry.js +184 -0
- package/dist/harness-recipe.d.ts +73 -6
- package/dist/harness-recipe.js +185 -31
- package/dist/harness-sign-in.d.ts +29 -0
- package/dist/harness-sign-in.js +122 -0
- package/dist/harness-table.d.ts +21 -0
- package/dist/harness-table.js +58 -3
- package/dist/harness-zip.d.ts +6 -0
- package/dist/harness-zip.js +203 -0
- package/dist/ids.d.ts +11 -0
- package/dist/ids.js +36 -0
- package/dist/learn/commit.d.ts +19 -1
- package/dist/learn/commit.js +160 -2
- package/dist/learn/compile.d.ts +13 -5
- package/dist/learn/compile.js +46 -15
- package/dist/learn/delete.d.ts +12 -6
- package/dist/learn/delete.js +17 -11
- package/dist/learn/folder.d.ts +16 -0
- package/dist/learn/folder.js +30 -4
- package/dist/learn/learning-of.d.ts +8 -0
- package/dist/learn/learning-of.js +8 -0
- package/dist/learn/learning.sh +29 -4
- package/dist/learn/promote.d.ts +51 -7
- package/dist/learn/promote.js +51 -8
- package/dist/learn/secrets.js +30 -7
- package/dist/learning-reset.d.ts +18 -0
- package/dist/learning-reset.js +115 -0
- package/dist/learning-routes.d.ts +23 -11
- package/dist/learning-routes.js +110 -20
- package/dist/learning-words.d.ts +5 -0
- package/dist/learning-words.js +5 -0
- package/dist/learning.d.ts +15 -10
- package/dist/learning.js +14 -8
- package/dist/llms.txt +1 -0
- package/dist/mcp-gateway.d.ts +39 -2
- package/dist/mcp-gateway.js +56 -12
- package/dist/mcp-pin-first.js +1 -1
- package/dist/mcp-probe.d.ts +3 -0
- package/dist/mcp-probe.js +7 -2
- package/dist/mcp-resources.d.ts +44 -0
- package/dist/mcp-resources.js +100 -0
- package/dist/mcp-servers-store.d.ts +17 -12
- package/dist/mcp-servers-store.js +2 -1
- package/dist/media-duration.d.ts +2 -0
- package/dist/media-duration.js +136 -0
- package/dist/model.d.ts +4 -4
- package/dist/model.js +6 -6
- package/dist/native/cli.js +9 -2
- package/dist/native/connection.d.ts +2 -2
- package/dist/native/connection.js +5 -2
- package/dist/native/discovery.d.ts +2 -0
- package/dist/native/discovery.js +10 -6
- package/dist/native/remote-worker-bridge.js +36 -4
- package/dist/native/remote.d.ts +18 -1
- package/dist/native/remote.js +126 -37
- package/dist/native/schema.d.ts +6 -0
- package/dist/native/schema.js +31 -6
- package/dist/native/source-account.d.ts +13 -0
- package/dist/native/source-account.js +114 -0
- package/dist/native/source-capture-hooks.d.ts +5 -0
- package/dist/native/source-capture-hooks.js +102 -0
- package/dist/native/source-mcp-selection.d.ts +13 -0
- package/dist/native/source-mcp-selection.js +72 -0
- package/dist/native/source-runtime-tools.d.ts +19 -0
- package/dist/native/source-runtime-tools.js +103 -0
- package/dist/native/source-snapshot-types.d.ts +138 -0
- package/dist/native/source-snapshot-types.js +12 -0
- package/dist/native/source-snapshot.d.ts +8 -0
- package/dist/native/source-snapshot.js +1201 -0
- package/dist/observation/learning.js +3 -2
- package/dist/openapi.js +211 -47
- package/dist/print.js +1 -1
- package/dist/provider.d.ts +8 -0
- package/dist/provider.js +14 -2
- package/dist/purged-workflow.d.ts +12 -0
- package/dist/purged-workflow.js +43 -0
- package/dist/refusal-words.d.ts +0 -3
- package/dist/refusal-words.js +0 -3
- package/dist/request-metadata.d.ts +20 -0
- package/dist/request-metadata.js +24 -0
- package/dist/run-keys.d.ts +46 -0
- package/dist/run-keys.js +109 -0
- package/dist/run-launch.d.ts +29 -5
- package/dist/run-launch.js +44 -4
- package/dist/run-learning-served.d.ts +2 -2
- package/dist/run-model-key.d.ts +2 -2
- package/dist/run-model-key.js +5 -5
- package/dist/run-secrets.d.ts +2 -0
- package/dist/run-secrets.js +7 -4
- package/dist/run-usage.d.ts +48 -4
- package/dist/run-usage.js +156 -39
- package/dist/run-view.d.ts +18 -1
- package/dist/run-view.js +28 -8
- package/dist/runner/adapter-loop.d.ts +14 -4
- package/dist/runner/adapter-loop.js +150 -31
- package/dist/runner/adapter-run-spec.d.ts +1 -1
- package/dist/runner/adapter-run-spec.js +35 -22
- package/dist/runner/audit.d.ts +10 -3
- package/dist/runner/audit.js +30 -7
- package/dist/runner/beside.js +2 -1
- package/dist/runner/claim-secrets.d.ts +31 -4
- package/dist/runner/claim-secrets.js +43 -7
- package/dist/runner/cli-run-spec.d.ts +1 -1
- package/dist/runner/cli-run-spec.js +32 -20
- package/dist/runner/conformance/harness.js +4 -2
- package/dist/runner/dispatch.js +4 -2
- package/dist/runner/harness-loops.d.ts +6 -0
- package/dist/runner/harness-loops.js +16 -3
- package/dist/runner/held.d.ts +4 -0
- package/dist/runner/journal-kinds.d.ts +5 -0
- package/dist/runner/learned-first.d.ts +2 -0
- package/dist/runner/learned-first.js +1 -1
- package/dist/runner/learning-end.d.ts +9 -3
- package/dist/runner/learning-end.js +66 -29
- package/dist/runner/learning-seed.d.ts +9 -3
- package/dist/runner/learning-seed.js +2 -2
- package/dist/runner/main.d.ts +1 -0
- package/dist/runner/main.js +20 -13
- package/dist/runner/mcp-claim.js +7 -2
- package/dist/runner/mcp-run.d.ts +12 -0
- package/dist/runner/mcp-run.js +14 -1
- package/dist/runner/model-route.js +7 -4
- package/dist/runner/monid-run.js +9 -11
- package/dist/runner/project-checkpoint.d.ts +35 -0
- package/dist/runner/project-checkpoint.js +116 -0
- package/dist/runner/project-drain.d.ts +8 -0
- package/dist/runner/project-drain.js +25 -0
- package/dist/runner/project-host.d.ts +10 -0
- package/dist/runner/project-host.js +52 -0
- package/dist/runner/promotion.d.ts +51 -24
- package/dist/runner/promotion.js +206 -78
- package/dist/runner/redact.d.ts +13 -0
- package/dist/runner/redact.js +67 -1
- package/dist/runner/run-channel.d.ts +9 -0
- package/dist/runner/run-channel.js +15 -2
- package/dist/runner/run-child-host.d.ts +8 -4
- package/dist/runner/run-child-host.js +174 -42
- package/dist/runner/run-errors.js +2 -2
- package/dist/runner/runner-check.js +5 -2
- package/dist/runner/runner.js +41 -12
- package/dist/runner/sdk-loop.d.ts +2 -2
- package/dist/runner/sdk-loop.js +3 -3
- package/dist/runner/store-port.d.ts +3 -0
- package/dist/runner/store-secrets.js +7 -3
- package/dist/runner/workflow-first.d.ts +4 -0
- package/dist/runner/workflow-first.js +13 -0
- package/dist/runner/workflow-loop.d.ts +2 -1
- package/dist/runner/workflow-loop.js +2 -1
- package/dist/runner/workflow-spec.js +4 -4
- package/dist/runs-over-store.d.ts +39 -8
- package/dist/runs-over-store.js +147 -32
- package/dist/sdk/check.d.ts +6 -5
- package/dist/sdk/check.js +17 -16
- package/dist/sdk/runs.d.ts +11 -1
- package/dist/sdk/runs.js +185 -78
- package/dist/sdk/schema.js +12 -2
- package/dist/sdk/workflows.d.ts +1 -1
- package/dist/server.d.ts +68 -32
- package/dist/server.js +678 -124
- package/dist/skills/agentrun-serve/SKILL.md +2 -1
- package/dist/source-sync/adoption.d.ts +15 -0
- package/dist/source-sync/adoption.js +36 -0
- package/dist/source-sync/auxiliary.d.ts +23 -0
- package/dist/source-sync/auxiliary.js +64 -0
- package/dist/source-sync/capture-git.d.ts +5 -0
- package/dist/source-sync/capture-git.js +272 -0
- package/dist/source-sync/capture-project.d.ts +53 -0
- package/dist/source-sync/capture-project.js +206 -0
- package/dist/source-sync/capture-refusal.d.ts +7 -0
- package/dist/source-sync/capture-refusal.js +16 -0
- package/dist/source-sync/capture.d.ts +11 -0
- package/dist/source-sync/capture.js +22 -0
- package/dist/source-sync/checkpoint-gate.d.ts +21 -0
- package/dist/source-sync/checkpoint-gate.js +52 -0
- package/dist/source-sync/checkpoints.d.ts +66 -0
- package/dist/source-sync/checkpoints.js +168 -0
- package/dist/source-sync/claim.d.ts +11 -0
- package/dist/source-sync/claim.js +48 -0
- package/dist/source-sync/destination.d.ts +47 -0
- package/dist/source-sync/destination.js +239 -0
- package/dist/source-sync/io.d.ts +15 -0
- package/dist/source-sync/io.js +52 -0
- package/dist/source-sync/local.d.ts +43 -0
- package/dist/source-sync/local.js +229 -0
- package/dist/source-sync/prepare.d.ts +59 -0
- package/dist/source-sync/prepare.js +93 -0
- package/dist/source-sync/projects.d.ts +61 -0
- package/dist/source-sync/projects.js +130 -0
- package/dist/source-sync/registry.d.ts +95 -0
- package/dist/source-sync/registry.js +226 -0
- package/dist/source-sync/service.d.ts +33 -0
- package/dist/source-sync/service.js +118 -0
- package/dist/source-sync/skill-edits.d.ts +12 -0
- package/dist/source-sync/skill-edits.js +122 -0
- package/dist/source-sync/snapshots.d.ts +48 -0
- package/dist/source-sync/snapshots.js +448 -0
- package/dist/source-sync/types.d.ts +9 -0
- package/dist/source-sync/types.js +14 -0
- package/dist/source-sync/workspace.d.ts +66 -0
- package/dist/source-sync/workspace.js +273 -0
- package/dist/store/agent-body.d.ts +8 -0
- package/dist/store/agent-body.js +20 -6
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +1 -1
- package/dist/store/journal/storage.d.ts +2 -0
- package/dist/store/journal/storage.js +2 -1
- package/dist/store/postgres/migrations/0025_run_attempts.sql +27 -0
- package/dist/store/postgres/migrations/0026_run_disk.sql +23 -0
- package/dist/store/schema.d.ts +15 -1
- package/dist/store/schema.js +43 -4
- package/dist/store/seal.d.ts +5 -1
- package/dist/store/seal.js +12 -3
- package/dist/store/sqlite/project-checkpoints.d.ts +11 -0
- package/dist/store/sqlite/project-checkpoints.js +70 -0
- package/dist/store/sqlite/run-launch.d.ts +14 -0
- package/dist/store/sqlite/run-launch.js +58 -7
- package/dist/store/sqlite/run-patch.d.ts +2 -1
- package/dist/store/sqlite/run-patch.js +4 -3
- package/dist/store/sqlite/store.js +319 -153
- package/dist/store/store-schema.js +2 -2
- package/dist/store/store.d.ts +173 -33
- package/dist/store/store.js +14 -1
- package/dist/store-reads/learning.d.ts +12 -8
- package/dist/store-reads/learning.js +33 -24
- package/dist/store-reads/loop.d.ts +4 -3
- package/dist/store-reads/loop.js +7 -5
- package/dist/store-view.d.ts +3 -1
- package/dist/store-view.js +17 -5
- package/dist/template-eval.js +4 -4
- package/dist/template-import.d.ts +10 -2
- package/dist/template-import.js +116 -13
- package/dist/templates.d.ts +29 -5
- package/dist/templates.js +68 -14
- package/dist/timeline/index.d.ts +1 -1
- package/dist/timeline/index.js +1 -1
- package/dist/timeline/labels.js +1 -1
- package/dist/timeline/timeline.d.ts +5 -0
- package/dist/timeline/timeline.js +8 -0
- package/dist/tool-plane.d.ts +12 -12
- package/dist/tools.d.ts +8 -8
- package/dist/tools.js +1 -1
- package/dist/trigger-launch-hook.d.ts +47 -0
- package/dist/trigger-launch-hook.js +90 -0
- package/dist/trigger-targets.d.ts +14 -1
- package/dist/trigger-targets.js +20 -0
- package/dist/triggers.d.ts +54 -5
- package/dist/triggers.js +143 -8
- package/dist/uploads-archil.js +2 -1
- package/dist/uploads.d.ts +0 -3
- package/dist/uploads.js +2 -11
- package/dist/validate.js +4 -1
- package/dist/web-save.d.ts +3 -0
- package/dist/web-save.js +17 -2
- package/dist/workspace/archil-exec.js +1 -1
- package/dist/workspace/archil.js +1 -1
- package/dist/workspace/computer-for-claim.d.ts +2 -0
- package/dist/workspace/computer-for-claim.js +43 -0
- package/dist/workspace/paths.d.ts +6 -0
- package/dist/workspace/paths.js +6 -0
- package/dist/workspace/resolve-computer.d.ts +1 -0
- package/dist/workspace/revision-skills.js +24 -11
- package/dist/workspace/run-tools.d.ts +2 -0
- package/dist/workspace/run-tools.js +8 -0
- package/dist/workspace/synced-folder.d.ts +3 -3
- package/dist/workspace/synced-folder.js +7 -6
- package/launcher/agentrun-serve +1 -1
- package/package.json +10 -10
- package/skills/agentrun-serve/SKILL.md +2 -1
- package/templates/README.md +5 -2
- package/dist/console/assets/index-Bt1B51b7.js +0 -733
- package/dist/console/assets/index-sVftE9Ht.css +0 -1
package/dist/print.js
CHANGED
|
@@ -16,7 +16,7 @@ export function banner(o) {
|
|
|
16
16
|
`AGENTRUN_API_KEY=${key}`,
|
|
17
17
|
...(o.tokenIds && (o.tokenIds.length > 1 || o.source === "list") ? [`API tokens taken (ids): ${o.tokenIds.join(", ")}`] : []),
|
|
18
18
|
o.apiOnly
|
|
19
|
-
? "API only (AGENTRUN_API_ONLY=1): the run routes are served; the console, sign-in, setup, settings, MCP, triggers and hooks are refused."
|
|
19
|
+
? "API only (AGENTRUN_API_ONLY=1): the run and deploy routes are served; the console, sign-in, setup, settings, MCP, triggers and hooks are refused."
|
|
20
20
|
: o.accounts || o.launchCode === undefined ? `Open ${o.publicUrl ?? o.url}/` : `Open ${o.publicUrl ?? o.url}/?launch=${o.launchCode}`,
|
|
21
21
|
...(o.boxes ? [o.boxes] : []),
|
|
22
22
|
];
|
package/dist/provider.d.ts
CHANGED
|
@@ -32,6 +32,11 @@ export declare function gatewayBase(setting: string, value: string): string;
|
|
|
32
32
|
/** The generic gateway must speak HTTP Responses (or Messages). Particle exposes Chat Completions
|
|
33
33
|
* and a WebSocket-only Responses subset, so a direct API base is not a compatible gateway. */
|
|
34
34
|
export declare function modelGatewayBase(value: string): string;
|
|
35
|
+
/** Whether `base` (a gatewayBase answer) is on the origin of serve's own gateway (AGENT_MODEL_BASE_URL): there a run's own
|
|
36
|
+
* model key (run-model-key.ts) is sent, so the endpoint needs no standing key of the server's. */
|
|
37
|
+
/** The headers a request to `origin` carries for serve's gateway (gatewayHeadersOf), when `origin` is that gateway's own
|
|
38
|
+
* (AGENT_MODEL_BASE_URL's origin): none to any other origin, a vendor's own included. */
|
|
39
|
+
export declare function gatewayHeadersAt(env: NodeJS.ProcessEnv, origin: string): Readonly<Record<string, string>> | undefined;
|
|
35
40
|
/**
|
|
36
41
|
* Whether `wire` reaches its vendor's models here only through OpenRouter: OPENROUTER_API_KEY is set and none of the
|
|
37
42
|
* wire's own settings is. Those win, as on a host with no OpenRouter key: the endpoint the host names (ANTHROPIC_BASE_URL
|
|
@@ -59,6 +64,8 @@ export declare function anthropicModelId(model: ModelRef): string;
|
|
|
59
64
|
* the plan's token, asked at each request, and `refused` tells the plan OpenAI answered 401 to one it sent. */
|
|
60
65
|
/** `login`: claude-agent on Claude Code's login on this machine (claude-login.ts): billed to the person's plan, its CLI
|
|
61
66
|
* calling Anthropic itself; `origin` and `credential` are never read (no proxy, no key). */
|
|
67
|
+
/** `headers`: what each request on serve's own gateway carries beside its key (request-metadata.ts: the run, turn and
|
|
68
|
+
* attempt it was made for, as LiteLLM's spend-logs metadata); none on any other endpoint. */
|
|
62
69
|
export type Provider = {
|
|
63
70
|
origin: string;
|
|
64
71
|
credential: () => string | Promise<string>;
|
|
@@ -68,6 +75,7 @@ export type Provider = {
|
|
|
68
75
|
billing?: "plan";
|
|
69
76
|
refused?: (credential: string) => Promise<void>;
|
|
70
77
|
login?: ClaudeAgentLogin;
|
|
78
|
+
headers?: Readonly<Record<string, string>>;
|
|
71
79
|
};
|
|
72
80
|
export declare function providerFor(wire: Wire, env: NodeJS.ProcessEnv, model: ModelRef, who: string): Provider;
|
|
73
81
|
/** The catalog entry a run on `wire` of `model` is capped and priced by: providerFor's, or the model's own (normalized)
|
package/dist/provider.js
CHANGED
|
@@ -2,6 +2,7 @@ import { CLAUDE_LOGIN_PROVIDER, onClaudeLogin, claudeLoginOf } from "./claude-lo
|
|
|
2
2
|
import { chooseModel, FAUX_ENV, hostModel, MODEL_PROVIDER } from "./model.js";
|
|
3
3
|
import { modelWire, WIRES, wireOf } from "./wires.js";
|
|
4
4
|
import { modelFormWhy } from "./model-form.js";
|
|
5
|
+
import { gatewayHeadersOf } from "./request-metadata.js";
|
|
5
6
|
import { EXPIRED, PLAN_ORIGIN, PLAN_PROVIDER, planOf, SIGNED_OUT } from "./chatgpt-plan.js";
|
|
6
7
|
// Each wire's own settings live in a leaf module (wires.ts), which the harness table reads as it loads.
|
|
7
8
|
export { modelWire, WIRES, wireOf };
|
|
@@ -71,6 +72,11 @@ export function modelGatewayBase(value) {
|
|
|
71
72
|
}
|
|
72
73
|
/** Whether `base` (a gatewayBase answer) is on the origin of serve's own gateway (AGENT_MODEL_BASE_URL): there a run's own
|
|
73
74
|
* model key (run-model-key.ts) is sent, so the endpoint needs no standing key of the server's. */
|
|
75
|
+
/** The headers a request to `origin` carries for serve's gateway (gatewayHeadersOf), when `origin` is that gateway's own
|
|
76
|
+
* (AGENT_MODEL_BASE_URL's origin): none to any other origin, a vendor's own included. */
|
|
77
|
+
export function gatewayHeadersAt(env, origin) {
|
|
78
|
+
return onServeGateway(env, origin) ? gatewayHeadersOf(env) : undefined;
|
|
79
|
+
}
|
|
74
80
|
function onServeGateway(env, base) {
|
|
75
81
|
if (!env.AGENT_MODEL_BASE_URL)
|
|
76
82
|
return false;
|
|
@@ -111,6 +117,11 @@ export const openRouterName = (id) => id.replace(/-(\d+)-(\d+)$/, "-$1.$2");
|
|
|
111
117
|
export function anthropicModelId(model) {
|
|
112
118
|
return model.provider === WIRES["anthropic-messages"].vendor ? model.modelId.replaceAll(".", "-") : model.modelId;
|
|
113
119
|
}
|
|
120
|
+
/** `env`'s gateway headers (gatewayHeadersOf), as a Provider's optional field. */
|
|
121
|
+
const onGateway = (env) => {
|
|
122
|
+
const headers = gatewayHeadersOf(env);
|
|
123
|
+
return headers ? { headers } : {};
|
|
124
|
+
};
|
|
114
125
|
/** OpenRouter's key, read per request, refused by name where it is not set. */
|
|
115
126
|
function openRouterKey(env, who, named) {
|
|
116
127
|
if (!env.OPENROUTER_API_KEY)
|
|
@@ -119,7 +130,7 @@ function openRouterKey(env, who, named) {
|
|
|
119
130
|
}
|
|
120
131
|
/** Serve's gateway (AGENT_MODEL_BASE_URL) on either wire: its base, its key (AGENT_MODEL_API_KEY, or none) as a bearer
|
|
121
132
|
* token, the model id as model.ts chose it, priced as runModels prices it. */
|
|
122
|
-
const gatewayProvider = (env, model) => ({ origin: modelGatewayBase(env.AGENT_MODEL_BASE_URL), credential: () => env.AGENT_MODEL_API_KEY || "none", auth: "bearer", modelId: model.modelId, priceModel: model });
|
|
133
|
+
const gatewayProvider = (env, model) => ({ origin: modelGatewayBase(env.AGENT_MODEL_BASE_URL), credential: () => env.AGENT_MODEL_API_KEY || "none", auth: "bearer", modelId: model.modelId, priceModel: model, ...onGateway(env) });
|
|
123
134
|
export function providerFor(wire, env, model, who) {
|
|
124
135
|
const named = `${model.provider}/${model.modelId}`;
|
|
125
136
|
// A harness on its own plan (Cursor's) calls its vendor itself, on its owner's key: no route of ours is its.
|
|
@@ -150,7 +161,8 @@ export function providerFor(wire, env, model, who) {
|
|
|
150
161
|
// the harness runs here with no standing key, and a run with no key to spend is refused at its start.
|
|
151
162
|
if (!env.ANTHROPIC_API_KEY && !onServeGateway(env, origin))
|
|
152
163
|
throw env.ANTHROPIC_BASE_URL ? new HarnessUnavailable(`${who} needs ANTHROPIC_API_KEY.`, undefined, ["ANTHROPIC_API_KEY"]) : new HarnessUnavailable(`${who} needs ANTHROPIC_API_KEY or OPENROUTER_API_KEY.`, undefined, ["ANTHROPIC_API_KEY", "OPENROUTER_API_KEY"]);
|
|
153
|
-
|
|
164
|
+
// On serve's own gateway's origin, the claim's request metadata goes with each request (request-metadata.ts).
|
|
165
|
+
return { origin, credential: () => env.ANTHROPIC_API_KEY ?? "", auth: "x-api-key", modelId: own, priceModel: { provider: "anthropic", modelId: own }, ...(onServeGateway(env, origin) ? onGateway(env) : {}) };
|
|
154
166
|
}
|
|
155
167
|
// A ChatGPT plan's model: OpenAI's Responses API on the plan's token, whatever else is set.
|
|
156
168
|
if (model.provider === PLAN_PROVIDER) {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ApiError } from "./errors.js";
|
|
2
|
+
import type { Snapshot } from "./learn/folder.js";
|
|
3
|
+
import type { RunRow, Store } from "./store/index.js";
|
|
4
|
+
/** 410 purged for a route of a purged run (Runs.purge): its tombstone, what is kept of it. `tools_usd`: its paid tools'
|
|
5
|
+
* meter as /usage read it at its purge (null: unknown, or none read). */
|
|
6
|
+
export declare function purgedRun(row: RunRow): ApiError;
|
|
7
|
+
/** The learned workflows of `snapshot` (main's, or a commit's: learn/folder.ts snapshotAt, folderAt) whose
|
|
8
|
+
* workflow.json a purged run wrote, by name, each with that run's row. Its writer is the snapshot's own
|
|
9
|
+
* (SnapLearned.run): the run of the newest commit that changed the file, read from the commits' Run-Id trailers over
|
|
10
|
+
* main's whole history, never only the log's newest LOG_KEEP changes; purged by its row's purge time. The one answer
|
|
11
|
+
* every read of a learned workflow's text asks. */
|
|
12
|
+
export declare function purgedWorkflows(snapshot: Snapshot | undefined, store: Pick<Store, "runs">): Promise<ReadonlyMap<string, RunRow>>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// What a purged run (DELETE /v2/runs/{id}, agent-delete.ts purgeRun) answers, and the one rule for a learned workflow
|
|
2
|
+
// whose text it wrote: its purge takes it off main (learn/commit.ts forgetRunText), and every read at a past commit
|
|
3
|
+
// refuses it, so it is never served or executed.
|
|
4
|
+
// - The learned file read (GET .../learning/files/workflows/<name>/workflow.json) of one still on main (its run
|
|
5
|
+
// purged before purges took it off) is 410 purged with the run's tombstone, as every route of the run is (purgedRun).
|
|
6
|
+
// - The champion read by digest (GET .../learning/promotions) reads no commit for it.
|
|
7
|
+
// - A later merge's diff (GET /runs/{id}/learning/diff) serves that file against nothing: never the purged text.
|
|
8
|
+
// - An SDK start sent again (sdk/runs.ts receipt) whose receipt pinned it is 410 purged, as the file read.
|
|
9
|
+
// - A run's seed (learning.ts seedAt) leaves it out, so no claim lays, checks, replays or serves it, and a champion
|
|
10
|
+
// read at its commit finds none: the run goes on as it does when no champion serves.
|
|
11
|
+
import { ApiError } from "./errors.js";
|
|
12
|
+
const isoOrNull = (ms) => (ms === null ? null : new Date(ms).toISOString());
|
|
13
|
+
/** 410 purged for a route of a purged run (Runs.purge): its tombstone, what is kept of it. `tools_usd`: its paid tools'
|
|
14
|
+
* meter as /usage read it at its purge (null: unknown, or none read). */
|
|
15
|
+
export function purgedRun(row) {
|
|
16
|
+
const meters = row.metrics?.purged?.meters;
|
|
17
|
+
return new ApiError("purged", `The run ${row.id} was purged: what it was given and did is gone, and its cost stays in every total.`, {
|
|
18
|
+
details: {
|
|
19
|
+
run_id: row.id, agent_id: row.agentId, state: row.state, started_at: isoOrNull(row.startedAt), ended_at: isoOrNull(row.endedAt),
|
|
20
|
+
cost_usd: row.costUsd ?? row.costAtMostUsd, cost_upper_bound: row.costUsd === null && row.costAtMostUsd !== null, tools_usd: typeof meters?.tools === "number" ? meters.tools : null,
|
|
21
|
+
purged_at: isoOrNull(row.purgedAt),
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
/** The learned workflows of `snapshot` (main's, or a commit's: learn/folder.ts snapshotAt, folderAt) whose
|
|
26
|
+
* workflow.json a purged run wrote, by name, each with that run's row. Its writer is the snapshot's own
|
|
27
|
+
* (SnapLearned.run): the run of the newest commit that changed the file, read from the commits' Run-Id trailers over
|
|
28
|
+
* main's whole history, never only the log's newest LOG_KEEP changes; purged by its row's purge time. The one answer
|
|
29
|
+
* every read of a learned workflow's text asks. */
|
|
30
|
+
export async function purgedWorkflows(snapshot, store) {
|
|
31
|
+
const writers = new Map();
|
|
32
|
+
for (const item of snapshot?.workflows ?? [])
|
|
33
|
+
if (item.run)
|
|
34
|
+
writers.set(item.name, item.run);
|
|
35
|
+
const rows = new Map(await Promise.all([...new Set(writers.values())].map(async (run) => [run, await store.runs.get(run)])));
|
|
36
|
+
const purged = new Map();
|
|
37
|
+
for (const [name, run] of writers) {
|
|
38
|
+
const row = rows.get(run);
|
|
39
|
+
if (row && row.purgedAt !== null)
|
|
40
|
+
purged.set(name, row);
|
|
41
|
+
}
|
|
42
|
+
return purged;
|
|
43
|
+
}
|
package/dist/refusal-words.d.ts
CHANGED
|
@@ -9,9 +9,6 @@ export declare const STOPPED_WHILE_WAITING = "Not run: the run was stopped while
|
|
|
9
9
|
export declare const ENDED_WHILE_WAITING = "Not run: the run ended while it waited";
|
|
10
10
|
/** How a refusal of a setting's deny, or of an ask no one can approve, opens (deniedText, noApproverText). */
|
|
11
11
|
export declare const DENIED_OPENING = "Permission denied: ";
|
|
12
|
-
/** The field of an asked call's card that says why a call its setting allows asks a person anyway (a tool's own ask,
|
|
13
|
-
* tools.ts ToolEntry.asks): written by the gate alone, so the model's own arguments never carry it onto the card. */
|
|
14
|
-
export declare const ASKED_BECAUSE = "asked_because";
|
|
15
12
|
/** How a person's deny opens (refusedText). */
|
|
16
13
|
export declare const USER_DENIED_OPENING = "The user denied this ";
|
|
17
14
|
/** What a read-only bash policy's refusal says after the tool's name (bash-read-only.ts readOnlyText). */
|
package/dist/refusal-words.js
CHANGED
|
@@ -11,9 +11,6 @@ export const STOPPED_WHILE_WAITING = "Not run: the run was stopped while it wait
|
|
|
11
11
|
export const ENDED_WHILE_WAITING = "Not run: the run ended while it waited";
|
|
12
12
|
/** How a refusal of a setting's deny, or of an ask no one can approve, opens (deniedText, noApproverText). */
|
|
13
13
|
export const DENIED_OPENING = "Permission denied: ";
|
|
14
|
-
/** The field of an asked call's card that says why a call its setting allows asks a person anyway (a tool's own ask,
|
|
15
|
-
* tools.ts ToolEntry.asks): written by the gate alone, so the model's own arguments never carry it onto the card. */
|
|
16
|
-
export const ASKED_BECAUSE = "asked_because";
|
|
17
14
|
/** How a person's deny opens (refusedText). */
|
|
18
15
|
export const USER_DENIED_OPENING = "The user denied this ";
|
|
19
16
|
/** What a read-only bash policy's refusal says after the tool's name (bash-read-only.ts readOnlyText). */
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Claim } from "./store/index.js";
|
|
2
|
+
/** The env name a claim's model routes read the metadata from: the JSON the header carries. */
|
|
3
|
+
export declare const REQUEST_METADATA_ENV = "AGENTRUN_REQUEST_METADATA";
|
|
4
|
+
/** LiteLLM's header for metadata it keeps on a call's spend-log row (LiteLLM v1.110.0 and later). */
|
|
5
|
+
export declare const SPEND_LOGS_METADATA_HEADER = "x-litellm-spend-logs-metadata";
|
|
6
|
+
/** What one claim's requests say of themselves: the run, the turn the claim works and its attempt at it (store
|
|
7
|
+
* run_attempts). Keys are prefixed, as a spend log row holds the metadata of every caller of the gateway. */
|
|
8
|
+
export type RequestMetadata = {
|
|
9
|
+
agentrun_run_id: string;
|
|
10
|
+
agentrun_turn?: number;
|
|
11
|
+
agentrun_attempt?: number;
|
|
12
|
+
};
|
|
13
|
+
/** The metadata of `claim`'s requests: its run, and its turn and attempt where its store keeps them. */
|
|
14
|
+
export declare function requestMetadataOf(claim: Pick<Claim, "runId" | "turn" | "attempt">): RequestMetadata;
|
|
15
|
+
/** `env` with `claim`'s request metadata on it, by name and never enumerable (as a model key is); `env` itself when there
|
|
16
|
+
* is no claim. The same object is changed and returned: a claim's model env is its own (claimModelEnv makes it). */
|
|
17
|
+
export declare function withRequestMetadata(env: NodeJS.ProcessEnv, claim: Pick<Claim, "runId" | "turn" | "attempt"> | undefined): NodeJS.ProcessEnv;
|
|
18
|
+
/** The headers a request to serve's gateway carries from `env`: the spend-logs metadata, when the claim set it and it is
|
|
19
|
+
* one line of JSON an HTTP header can carry (the proxy's own bound on a host's header, 1024 characters). None else. */
|
|
20
|
+
export declare function gatewayHeadersOf(env: NodeJS.ProcessEnv): Readonly<Record<string, string>> | undefined;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** The env name a claim's model routes read the metadata from: the JSON the header carries. */
|
|
2
|
+
export const REQUEST_METADATA_ENV = "AGENTRUN_REQUEST_METADATA";
|
|
3
|
+
/** LiteLLM's header for metadata it keeps on a call's spend-log row (LiteLLM v1.110.0 and later). */
|
|
4
|
+
export const SPEND_LOGS_METADATA_HEADER = "x-litellm-spend-logs-metadata";
|
|
5
|
+
/** The metadata of `claim`'s requests: its run, and its turn and attempt where its store keeps them. */
|
|
6
|
+
export function requestMetadataOf(claim) {
|
|
7
|
+
return { agentrun_run_id: claim.runId, ...(claim.turn !== undefined ? { agentrun_turn: claim.turn } : {}), ...(claim.attempt !== undefined ? { agentrun_attempt: claim.attempt } : {}) };
|
|
8
|
+
}
|
|
9
|
+
/** `env` with `claim`'s request metadata on it, by name and never enumerable (as a model key is); `env` itself when there
|
|
10
|
+
* is no claim. The same object is changed and returned: a claim's model env is its own (claimModelEnv makes it). */
|
|
11
|
+
export function withRequestMetadata(env, claim) {
|
|
12
|
+
if (!claim)
|
|
13
|
+
return env;
|
|
14
|
+
Object.defineProperty(env, REQUEST_METADATA_ENV, { value: JSON.stringify(requestMetadataOf(claim)), enumerable: false, writable: true, configurable: true });
|
|
15
|
+
return env;
|
|
16
|
+
}
|
|
17
|
+
/** The headers a request to serve's gateway carries from `env`: the spend-logs metadata, when the claim set it and it is
|
|
18
|
+
* one line of JSON an HTTP header can carry (the proxy's own bound on a host's header, 1024 characters). None else. */
|
|
19
|
+
export function gatewayHeadersOf(env) {
|
|
20
|
+
const value = env[REQUEST_METADATA_ENV];
|
|
21
|
+
if (typeof value !== "string" || value.length === 0 || value.length > 1024 || /[^\x20-\x7e]/.test(value))
|
|
22
|
+
return undefined;
|
|
23
|
+
return { [SPEND_LOGS_METADATA_HEADER]: value };
|
|
24
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ApiError, type InputIssue } from "./errors.js";
|
|
2
|
+
import type { Revision } from "./agent-rows.js";
|
|
3
|
+
import { type RunNeeds } from "./run-secrets.js";
|
|
4
|
+
/** A run's own tool keys, by name. */
|
|
5
|
+
export type RunKeys = Readonly<Record<string, string>>;
|
|
6
|
+
/** The tool keys a run of `tools` reads (run-secrets.ts unlockedFields, over tool-keys.ts TOOL_KEYS). */
|
|
7
|
+
export declare const keysOfTools: (tools: readonly string[]) => string[];
|
|
8
|
+
/** The tool keys a template's apply made `revision` with (its package's `secrets`, kept on the revision): the ones a run
|
|
9
|
+
* can carry. A model key is not one. */
|
|
10
|
+
export declare const packageKeysOf: (revision: object) => string[];
|
|
11
|
+
/** The names a run of `revision`, whose needs are `needs` (run-secrets.ts needsOf), may carry in `keys`: each tool key its
|
|
12
|
+
* tools read (an agentic revision's tools, a workflow's on its nodes and calls, and its decision providers'), and its
|
|
13
|
+
* template's tool keys. */
|
|
14
|
+
export declare const declaredFrom: (needs: RunNeeds, revision: object) => string[];
|
|
15
|
+
/** The names a run of `revision` may carry in `keys` (declaredFrom). */
|
|
16
|
+
export declare function declaredKeys(revision: Pick<Revision, "kind" | "body"> & object): Promise<string[]>;
|
|
17
|
+
/** The longest key value taken. */
|
|
18
|
+
export declare const MAX_KEY = 8192;
|
|
19
|
+
/** `keys` as a body gives it, checked: tool key names (TOOL_FIELDS) to their values, each checked as every handed key is
|
|
20
|
+
* (handed-secret.ts), up to MAX_KEY. Each problem goes to `issues` by name, never with its value. */
|
|
21
|
+
export declare function runKeysOf(value: unknown, issues: InputIssue[]): RunKeys;
|
|
22
|
+
/** Each of `names` that `declared` leaves out, as a 422 issue at keys.<NAME>. */
|
|
23
|
+
export declare function undeclaredKeys(names: readonly string[], declared: readonly string[]): InputIssue[];
|
|
24
|
+
/** `env` with each of `names` set, for the checks a start makes and the tool plane it resolves (never a process's
|
|
25
|
+
* environment): a key the run carries counts as one this server holds. Every property of `env` is kept, its symbols
|
|
26
|
+
* among them. */
|
|
27
|
+
export declare function withCarried(env: NodeJS.ProcessEnv, names: readonly string[]): NodeJS.ProcessEnv;
|
|
28
|
+
/** Under the run-keys setting, each tool key `revision`'s template declared that `env` (the server's) does not hold and
|
|
29
|
+
* the run does not carry, as a 409 issue at keys.<NAME>: the apply made it on the promise each run brings it. */
|
|
30
|
+
export declare function keysOwed(revision: object, env: NodeJS.ProcessEnv, carried: readonly string[]): InputIssue[];
|
|
31
|
+
/** The 409 a run that owes `owed` (keysOwed) gets at its start, and a trigger that could only start or message such runs
|
|
32
|
+
* gets when it is made or moved (firingsOwe). */
|
|
33
|
+
export declare const keysOwedRefusal: (owed: readonly InputIssue[]) => ApiError;
|
|
34
|
+
/** Under the run-keys setting, whether a trigger's firings could never bring the keys runs of its agent owe (`owed`,
|
|
35
|
+
* keysOwed with nothing carried): a message_run's never do, hook or not; a start_run's do only through the launch hook,
|
|
36
|
+
* which hands each firing to the backend in front of this server to start the run with its keys (trigger-launch-hook.ts). */
|
|
37
|
+
export declare const firingsOwe: (owed: readonly unknown[], target: "start_run" | "message_run", hooked: boolean) => boolean;
|
|
38
|
+
/** Why an apply under the run-keys setting does not make `trigger` of the `packageName` template (a start_run's) for an
|
|
39
|
+
* agent whose runs owe `owed`, or undefined when it makes it (firingsOwe). */
|
|
40
|
+
export declare function runKeysTriggerSkipped(packageName: string, trigger: {
|
|
41
|
+
name?: unknown;
|
|
42
|
+
source?: unknown;
|
|
43
|
+
}, owed: readonly string[], hooked: boolean): {
|
|
44
|
+
reason: "not_set_up_here";
|
|
45
|
+
message: string;
|
|
46
|
+
} | undefined;
|
package/dist/run-keys.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// A run's own tool keys: `keys` on a run's start (POST /agents/{id}/runs, POST /runs) or on a message, by name, for the tool
|
|
2
|
+
// keys its revision declares (declaredKeys). They are taken out of the body before anything reads it, as model_key is
|
|
3
|
+
// (server.ts handedLaunchSecrets), sealed with the run's launch secrets (store/seal.ts sealRunLaunch), opened by its
|
|
4
|
+
// claim for its tools alone (runner/claim-secrets.ts), and erased with the rest when the run's turn ends. Stored only
|
|
5
|
+
// sealed with the run's launch, until its turn ends; never logged or answered: only their names are read before the seal,
|
|
6
|
+
// for the checks a start makes.
|
|
7
|
+
//
|
|
8
|
+
// AGENTRUN_RUN_KEYS=1 (env-switch.ts): an install whose runs bring the tool keys it does not hold. A template's
|
|
9
|
+
// apply then makes its agent though a tool key the template declares is not set here, and says so in a warning; a run of
|
|
10
|
+
// that revision that does not carry the key is refused (409 agent_not_runnable, at keys.<NAME>), and no trigger is made
|
|
11
|
+
// whose firings could not carry it (firingsOwe). Off, nothing changes.
|
|
12
|
+
import { ApiError } from "./errors.js";
|
|
13
|
+
import { handedSecretOf } from "./handed-secret.js";
|
|
14
|
+
import { LAUNCH_HOOK_SECRET_ENV, LAUNCH_HOOK_URL_ENV } from "./trigger-launch-hook.js";
|
|
15
|
+
import { needsOf, unlockedFields } from "./run-secrets.js";
|
|
16
|
+
import { TOOL_FIELDS } from "./tool-keys.js";
|
|
17
|
+
import { isObject } from "./validate.js";
|
|
18
|
+
import { RUN_KEYS_ENV } from "./env-switch.js";
|
|
19
|
+
/** The tool keys a run of `tools` reads (run-secrets.ts unlockedFields, over tool-keys.ts TOOL_KEYS). */
|
|
20
|
+
export const keysOfTools = (tools) => unlockedFields(tools);
|
|
21
|
+
/** The tool keys a template's apply made `revision` with (its package's `secrets`, kept on the revision): the ones a run
|
|
22
|
+
* can carry. A model key is not one. */
|
|
23
|
+
export const packageKeysOf = (revision) => (revision.package?.secrets ?? []).filter((name) => TOOL_FIELDS.includes(name));
|
|
24
|
+
/** The names a run of `revision`, whose needs are `needs` (run-secrets.ts needsOf), may carry in `keys`: each tool key its
|
|
25
|
+
* tools read (an agentic revision's tools, a workflow's on its nodes and calls, and its decision providers'), and its
|
|
26
|
+
* template's tool keys. */
|
|
27
|
+
export const declaredFrom = (needs, revision) => [...new Set([...keysOfTools([...needs.tools, ...needs.decisionProviders.map((provider) => `decisions.${provider}`)]), ...packageKeysOf(revision)])];
|
|
28
|
+
/** The names a run of `revision` may carry in `keys` (declaredFrom). */
|
|
29
|
+
export async function declaredKeys(revision) {
|
|
30
|
+
return declaredFrom(await needsOf(revision), revision);
|
|
31
|
+
}
|
|
32
|
+
/** The longest key value taken. */
|
|
33
|
+
export const MAX_KEY = 8192;
|
|
34
|
+
/** `keys` as a body gives it, checked: tool key names (TOOL_FIELDS) to their values, each checked as every handed key is
|
|
35
|
+
* (handed-secret.ts), up to MAX_KEY. Each problem goes to `issues` by name, never with its value. */
|
|
36
|
+
export function runKeysOf(value, issues) {
|
|
37
|
+
if (!isObject(value)) {
|
|
38
|
+
issues.push({ field: "keys", reason: "wrong_type", message: 'keys is an object of tool key names to their values, such as {"PARALLEL_API_KEY": "..."}.' });
|
|
39
|
+
return {};
|
|
40
|
+
}
|
|
41
|
+
const out = {};
|
|
42
|
+
for (const [name, given] of Object.entries(value)) {
|
|
43
|
+
const field = `keys.${name}`;
|
|
44
|
+
if (!TOOL_FIELDS.includes(name))
|
|
45
|
+
issues.push({ field, reason: "not_an_option", message: `${name} is not a tool key a run can carry: one of ${TOOL_FIELDS.join(", ")}.` });
|
|
46
|
+
else if (typeof given !== "string")
|
|
47
|
+
issues.push({ field, reason: "wrong_type", message: `${field} is the key's value, as text.` });
|
|
48
|
+
else {
|
|
49
|
+
const wrong = handedSecretOf(given, field, MAX_KEY);
|
|
50
|
+
if (wrong)
|
|
51
|
+
issues.push(wrong);
|
|
52
|
+
else
|
|
53
|
+
out[name] = given;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return out;
|
|
57
|
+
}
|
|
58
|
+
/** Each of `names` that `declared` leaves out, as a 422 issue at keys.<NAME>. */
|
|
59
|
+
export function undeclaredKeys(names, declared) {
|
|
60
|
+
const reads = declared.length ? `it reads ${declared.join(", ")}` : "it reads none";
|
|
61
|
+
return names.filter((name) => !declared.includes(name)).map((name) => ({ field: `keys.${name}`, reason: "not_an_option", message: `${name} is a key no tool of this run's revision reads: ${reads}.` }));
|
|
62
|
+
}
|
|
63
|
+
/** What the start's checks read for a key a run carries: never a value, only that one is set. */
|
|
64
|
+
const CARRIED = "(carried by the run)";
|
|
65
|
+
/** `env` with each of `names` set, for the checks a start makes and the tool plane it resolves (never a process's
|
|
66
|
+
* environment): a key the run carries counts as one this server holds. Every property of `env` is kept, its symbols
|
|
67
|
+
* among them. */
|
|
68
|
+
export function withCarried(env, names) {
|
|
69
|
+
if (!names.length)
|
|
70
|
+
return env;
|
|
71
|
+
// A held secret is a fixed property (secrets.ts withSecrets), set even when empty: one the run carries and `env` holds
|
|
72
|
+
// empty is left out of the copy, then marked carried.
|
|
73
|
+
const owed = names.filter((name) => !env[name]);
|
|
74
|
+
const descriptors = Object.getOwnPropertyDescriptors(env);
|
|
75
|
+
for (const name of owed)
|
|
76
|
+
delete descriptors[name];
|
|
77
|
+
const out = Object.defineProperties({}, descriptors);
|
|
78
|
+
for (const name of owed)
|
|
79
|
+
Object.defineProperty(out, name, { value: CARRIED, enumerable: false, configurable: true });
|
|
80
|
+
return out;
|
|
81
|
+
}
|
|
82
|
+
/** Under the run-keys setting, each tool key `revision`'s template declared that `env` (the server's) does not hold and
|
|
83
|
+
* the run does not carry, as a 409 issue at keys.<NAME>: the apply made it on the promise each run brings it. */
|
|
84
|
+
export function keysOwed(revision, env, carried) {
|
|
85
|
+
return packageKeysOf(revision).filter((name) => !env[name] && !carried.includes(name)).map((name) => ({
|
|
86
|
+
field: `keys.${name}`,
|
|
87
|
+
reason: "not_set_up_here",
|
|
88
|
+
message: `This agent's template needs ${name}, which this server does not hold: it takes it from each run (${RUN_KEYS_ENV}=1).`,
|
|
89
|
+
fix: `Send keys.${name} with the run.`,
|
|
90
|
+
}));
|
|
91
|
+
}
|
|
92
|
+
/** The 409 a run that owes `owed` (keysOwed) gets at its start, and a trigger that could only start or message such runs
|
|
93
|
+
* gets when it is made or moved (firingsOwe). */
|
|
94
|
+
export const keysOwedRefusal = (owed) => new ApiError("agent_not_runnable", owed.map((one) => one.message).join(" "), { fields: [...owed], details: { unbound: [], missing: {} } });
|
|
95
|
+
/** Under the run-keys setting, whether a trigger's firings could never bring the keys runs of its agent owe (`owed`,
|
|
96
|
+
* keysOwed with nothing carried): a message_run's never do, hook or not; a start_run's do only through the launch hook,
|
|
97
|
+
* which hands each firing to the backend in front of this server to start the run with its keys (trigger-launch-hook.ts). */
|
|
98
|
+
export const firingsOwe = (owed, target, hooked) => owed.length > 0 && (target === "message_run" || !hooked);
|
|
99
|
+
/** Why an apply under the run-keys setting does not make `trigger` of the `packageName` template (a start_run's) for an
|
|
100
|
+
* agent whose runs owe `owed`, or undefined when it makes it (firingsOwe). */
|
|
101
|
+
export function runKeysTriggerSkipped(packageName, trigger, owed, hooked) {
|
|
102
|
+
if (!firingsOwe(owed, "start_run", hooked))
|
|
103
|
+
return undefined;
|
|
104
|
+
const kind = isObject(trigger.source) ? String(trigger.source.kind) : "";
|
|
105
|
+
return {
|
|
106
|
+
reason: "not_set_up_here",
|
|
107
|
+
message: `The ${packageName} template's trigger ${String(trigger.name).trim()} (${kind}) was not made: each run of its agent must carry ${owed.join(" and ")} in keys (${RUN_KEYS_ENV}=1), and its firings would start runs without them. Start its runs through the API with keys, or set the launch hook (${LAUNCH_HOOK_URL_ENV} and ${LAUNCH_HOOK_SECRET_ENV}) and apply again: each firing then goes to the backend in front of this server, which starts the run with its keys.`,
|
|
108
|
+
};
|
|
109
|
+
}
|
package/dist/run-launch.d.ts
CHANGED
|
@@ -61,9 +61,12 @@ export interface RunLaunch {
|
|
|
61
61
|
* runner copies them into the run's work/inputs/ at its claim, as the old start copied them before the process ran. */
|
|
62
62
|
readonly files?: readonly string[];
|
|
63
63
|
/** The server copied `files` into the run's folder (work/inputs/) when it started the run, before its row was written:
|
|
64
|
-
* a run on an Archil disk (Mode 2, uploads-archil.ts placeRunFiles). Its claim reads no upload (uploads.ts
|
|
64
|
+
* a run on an Archil disk (Mode 2, uploads-archil.ts placeRunFiles), or a moved project's local placement. Its claim reads no upload (uploads.ts
|
|
65
65
|
* filesToCopy). Absent: the claim copies them from the server's data directory, as before. */
|
|
66
66
|
readonly filesPlaced?: true;
|
|
67
|
+
/** A moved project's completed, private pre-admission placement. Claims verify this receipt; they never seed again.
|
|
68
|
+
* The control marker is outside the run's tool workspace. No source path or credential is kept in this record. */
|
|
69
|
+
readonly sourceProject?: SourceProjectLaunch;
|
|
67
70
|
/** The run's learning start, when its agent learns and the server's learning is on, decided once here so the runner reads
|
|
68
71
|
* no learning folder or git: `seed`, the learning commit's sha (or null when the seed could not be read); `section`,
|
|
69
72
|
* the exact # Learned text to lay into the prompt (its owner's corrections, learning.ts learnedSection); `workflows`,
|
|
@@ -71,7 +74,8 @@ export interface RunLaunch {
|
|
|
71
74
|
* never answered by a learned workflow and asked for no workflow draft at its end (a native run, an SDK run with no
|
|
72
75
|
* workflow binding); `model`, the model an SDK run's compile turn is asked on (its agent's own); `seedFailed`, why it
|
|
73
76
|
* starts with nothing learned when it does (SeedFailed); `use`, a run started with `learning: "use"` (learning.ts
|
|
74
|
-
* RUN_LEARNING_USE): it starts from all of the above and keeps nothing
|
|
77
|
+
* RUN_LEARNING_USE): it starts from all of the above and keeps nothing; `seededAt`, when its seed was read (learning.ts
|
|
78
|
+
* Seed.at), which the agent's reset watermark is read against. Absent when the run does not learn. */
|
|
75
79
|
readonly learning?: {
|
|
76
80
|
readonly seed: string | null;
|
|
77
81
|
readonly section: string;
|
|
@@ -80,6 +84,7 @@ export interface RunLaunch {
|
|
|
80
84
|
readonly model?: string;
|
|
81
85
|
readonly seedFailed?: SeedFailed;
|
|
82
86
|
readonly use?: true;
|
|
87
|
+
readonly seededAt?: number;
|
|
83
88
|
};
|
|
84
89
|
/** `false`: the run never starts on a learned workflow, even one that fits its input (RunCreate `workflow_first`,
|
|
85
90
|
* runner/workflow-first.ts); its agent takes it from its first turn. Absent: a fitting one serves first. */
|
|
@@ -108,6 +113,18 @@ export interface RunLaunch {
|
|
|
108
113
|
readonly minutes: number;
|
|
109
114
|
};
|
|
110
115
|
}
|
|
116
|
+
/** Immutable placement identity for a project copied before admission. */
|
|
117
|
+
export interface SourceProjectLaunch {
|
|
118
|
+
readonly version: 1;
|
|
119
|
+
readonly sourceId: string;
|
|
120
|
+
readonly baselineRevision: string;
|
|
121
|
+
readonly digest: string;
|
|
122
|
+
/** SHA-256 of the private complete marker's exact bytes. */
|
|
123
|
+
readonly receipt: string;
|
|
124
|
+
/** Exact preplaced upload paths, pinned in the private marker; never a whole inputs/ exclusion. */
|
|
125
|
+
readonly inputs?: readonly string[];
|
|
126
|
+
}
|
|
127
|
+
export declare function sourceProjectOf(value: unknown): SourceProjectLaunch | undefined;
|
|
111
128
|
/** What a replay run replays: the graded run, and the learned workflow at the digest it decides. */
|
|
112
129
|
export interface Replay {
|
|
113
130
|
readonly of: string;
|
|
@@ -126,6 +143,12 @@ export declare function keepInputOrigin(stored: unknown, trigger: RunTrigger | n
|
|
|
126
143
|
/** The JSON body the server stores for a run's launch. `harness` is a top-level field, so the loop factory reads it from the
|
|
127
144
|
* stored body without parsing the rest. */
|
|
128
145
|
export declare function launchBody(launch: RunLaunch): Json;
|
|
146
|
+
/** The launch a runner runs (runner/dispatch.ts, run-child-host.ts): on a disk the launch names as its own (kind
|
|
147
|
+
* "launch"), its learning start holds no seed, # Learned section or learned workflow, whatever the body says (a start
|
|
148
|
+
* made before its run's disk was read, or written by hand), as the server's seed is the default disk's, never that
|
|
149
|
+
* disk's (learn/learning-of.ts): the run starts with nothing learned (`other_disk`), its flags kept. Any other launch as
|
|
150
|
+
* read. readLaunchBody keeps the body as written: a finished run's views show what it ran. */
|
|
151
|
+
export declare function launchOnItsDisk(launch: RunLaunch): RunLaunch;
|
|
129
152
|
/** A launch body read back into a `RunLaunch`, with the input-origin fail-safe applied through the body's own trigger, or
|
|
130
153
|
* undefined when the body is not one (not an object, or it names no place: a damaged or hand-edited body). */
|
|
131
154
|
export declare function readLaunchBody(stored: unknown): RunLaunch | undefined;
|
|
@@ -135,9 +158,10 @@ export declare const learningStartOf: (launch: RunLaunch) => RunLaunch["learning
|
|
|
135
158
|
/** The same start read from a launch body's `learning` member alone (Store.runs.learningStarts), as readLaunchBody reads it. */
|
|
136
159
|
export declare const learningStartOfStored: (stored: unknown) => RunLaunch["learning"];
|
|
137
160
|
/** Why a learning run starts with nothing learned, as main says it: its agent's learning folder could not be read
|
|
138
|
-
* (`unreadable`, STOPPED.unreadable),
|
|
139
|
-
* STOPPED.notCopied)
|
|
140
|
-
|
|
161
|
+
* (`unreadable`, STOPPED.unreadable), what was read could not be made into its start (`not_copied`,
|
|
162
|
+
* STOPPED.notCopied), or its launch names a disk of its own, whose learning folder the server does not read
|
|
163
|
+
* (`other_disk`, STOPPED.otherDisk): a run on a named disk learns nothing (learn/learning-of.ts). */
|
|
164
|
+
export type SeedFailed = "unreadable" | "not_copied" | "other_disk";
|
|
141
165
|
/** A learning start with no seed (no commit of main, runs-over-store.ts learningStartFor): the run learns nothing, is
|
|
142
166
|
* never asked what to keep, and so is never told it learns. Why is its `seedFailed`, when its start records one. */
|
|
143
167
|
export declare const seedFailed: (start: NonNullable<RunLaunch["learning"]>) => boolean;
|
package/dist/run-launch.js
CHANGED
|
@@ -9,7 +9,31 @@ import { nativeOf } from "./native/binding.js";
|
|
|
9
9
|
// the run's own trigger with owner === (the source is a schedule, whose words its owner wrote when they set it up), else
|
|
10
10
|
// that trigger's own with owner false, so a forged or lost origin never reads as the person's or the owner's.
|
|
11
11
|
import { originOf } from "./timeline/index.js";
|
|
12
|
-
import { isObject } from "./validate.js";
|
|
12
|
+
import { ID, isObject } from "./validate.js";
|
|
13
|
+
import { relativeSegments } from "./workspace/paths.js";
|
|
14
|
+
export function sourceProjectOf(value) {
|
|
15
|
+
if (!isObject(value) || value.version !== 1 || Object.keys(value).length !== (value.inputs === undefined ? 5 : 6)
|
|
16
|
+
|| typeof value.baselineRevision !== "string" || !ID.test(value.baselineRevision))
|
|
17
|
+
return undefined;
|
|
18
|
+
for (const key of ["sourceId", "digest", "receipt"])
|
|
19
|
+
if (typeof value[key] !== "string" || !/^[a-f0-9]{64}$/.test(value[key]))
|
|
20
|
+
return undefined;
|
|
21
|
+
if (value.inputs !== undefined) {
|
|
22
|
+
if (!Array.isArray(value.inputs) || value.inputs.length > 20 || !value.inputs.length || new Set(value.inputs).size !== value.inputs.length)
|
|
23
|
+
return undefined;
|
|
24
|
+
for (const input of value.inputs) {
|
|
25
|
+
if (typeof input !== "string" || input.length > 4096 || /[\x00-\x1f\x7f]/.test(input) || !input.startsWith("inputs/") || input === "inputs/message.md")
|
|
26
|
+
return undefined;
|
|
27
|
+
try {
|
|
28
|
+
relativeSegments(input);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
13
37
|
/** The disk a launch body names, as read back, or undefined. */
|
|
14
38
|
const readDisk = (value) => isObject(value) && typeof value.disk_id === "string" && (value.kind === "launch" || value.kind === "agent") ? { diskId: value.disk_id, kind: value.kind } : undefined;
|
|
15
39
|
/** The replay a launch body names, as read back, or undefined. */
|
|
@@ -70,7 +94,8 @@ export function launchBody(launch) {
|
|
|
70
94
|
...(launch.boxAllowSet ? { box_allow_set: true } : {}),
|
|
71
95
|
...(launch.files?.length ? { files: launch.files } : {}),
|
|
72
96
|
...(launch.filesPlaced ? { files_placed: true } : {}),
|
|
73
|
-
...(launch.
|
|
97
|
+
...(launch.sourceProject ? { source_project: launch.sourceProject } : {}),
|
|
98
|
+
...(launch.learning ? { learning: { seed: launch.learning.seed, section: launch.learning.section, ...(launch.learning.workflows?.length ? { workflows: [...launch.learning.workflows] } : {}), ...(launch.learning.noWorkflows ? { noWorkflows: true } : {}), ...(launch.learning.model ? { model: launch.learning.model } : {}), ...(launch.learning.seedFailed ? { seedFailed: launch.learning.seedFailed } : {}), ...(launch.learning.use ? { use: true } : {}), ...(launch.learning.seededAt !== undefined ? { seededAt: launch.learning.seededAt } : {}) } } : {}),
|
|
74
99
|
...(launch.workflowFirst === false ? { workflow_first: false } : {}),
|
|
75
100
|
...(launch.replay ? { replay: { of: launch.replay.of, workflow: launch.replay.workflow, digest: launch.replay.digest } } : {}),
|
|
76
101
|
...(launch.audit ? { audit: { of: launch.audit.of, workflow: launch.audit.workflow, digest: launch.audit.digest } } : {}),
|
|
@@ -90,13 +115,27 @@ function readLearning(value) {
|
|
|
90
115
|
const seed = typeof value.seed === "string" ? value.seed : null;
|
|
91
116
|
const section = typeof value.section === "string" ? value.section : "";
|
|
92
117
|
const workflows = Array.isArray(value.workflows) ? value.workflows.filter((name) => typeof name === "string") : [];
|
|
93
|
-
return { seed, section, ...(workflows.length ? { workflows } : {}), ...(value.noWorkflows === true ? { noWorkflows: true } : {}), ...(typeof value.model === "string" && value.model !== "" ? { model: value.model } : {}), ...(typeof value.seedFailed === "string" && SEED_FAILURES.includes(value.seedFailed) ? { seedFailed: value.seedFailed } : {}), ...(value.use === true ? { use: true } : {}) };
|
|
118
|
+
return { seed, section, ...(workflows.length ? { workflows } : {}), ...(value.noWorkflows === true ? { noWorkflows: true } : {}), ...(typeof value.model === "string" && value.model !== "" ? { model: value.model } : {}), ...(typeof value.seedFailed === "string" && SEED_FAILURES.includes(value.seedFailed) ? { seedFailed: value.seedFailed } : {}), ...(value.use === true ? { use: true } : {}), ...(typeof value.seededAt === "number" && Number.isFinite(value.seededAt) ? { seededAt: value.seededAt } : {}) };
|
|
119
|
+
}
|
|
120
|
+
/** The launch a runner runs (runner/dispatch.ts, run-child-host.ts): on a disk the launch names as its own (kind
|
|
121
|
+
* "launch"), its learning start holds no seed, # Learned section or learned workflow, whatever the body says (a start
|
|
122
|
+
* made before its run's disk was read, or written by hand), as the server's seed is the default disk's, never that
|
|
123
|
+
* disk's (learn/learning-of.ts): the run starts with nothing learned (`other_disk`), its flags kept. Any other launch as
|
|
124
|
+
* read. readLaunchBody keeps the body as written: a finished run's views show what it ran. */
|
|
125
|
+
export function launchOnItsDisk(launch) {
|
|
126
|
+
if (!launch.learning || launch.archilDisk?.kind !== "launch")
|
|
127
|
+
return launch;
|
|
128
|
+
const { noWorkflows, model, use } = launch.learning;
|
|
129
|
+
return { ...launch, learning: { seed: null, section: "", seedFailed: "other_disk", ...(noWorkflows ? { noWorkflows } : {}), ...(model ? { model } : {}), ...(use ? { use } : {}) } };
|
|
94
130
|
}
|
|
95
131
|
/** A launch body read back into a `RunLaunch`, with the input-origin fail-safe applied through the body's own trigger, or
|
|
96
132
|
* undefined when the body is not one (not an object, or it names no place: a damaged or hand-edited body). */
|
|
97
133
|
export function readLaunchBody(stored) {
|
|
98
134
|
if (!isObject(stored))
|
|
99
135
|
return undefined;
|
|
136
|
+
const sourceProject = sourceProjectOf(stored.source_project);
|
|
137
|
+
if (stored.source_project !== undefined && !sourceProject)
|
|
138
|
+
return undefined;
|
|
100
139
|
const place = readPlace(stored.place);
|
|
101
140
|
if (!place)
|
|
102
141
|
return undefined;
|
|
@@ -124,6 +163,7 @@ export function readLaunchBody(stored) {
|
|
|
124
163
|
...(stored.box_allow_set === true ? { boxAllowSet: true } : {}),
|
|
125
164
|
...(Array.isArray(stored.files) && stored.files.every((id) => typeof id === "string") ? { files: stored.files } : {}),
|
|
126
165
|
...(stored.files_placed === true ? { filesPlaced: true } : {}),
|
|
166
|
+
...(sourceProject ? { sourceProject } : {}),
|
|
127
167
|
...(stored.learning !== undefined ? { learning: readLearning(stored.learning) ?? { seed: null, section: "" } } : {}),
|
|
128
168
|
...(stored.workflow_first === false ? { workflowFirst: false } : {}),
|
|
129
169
|
...(readReplay(stored.replay) ? { replay: readReplay(stored.replay) } : {}),
|
|
@@ -140,7 +180,7 @@ export function readLaunchBody(stored) {
|
|
|
140
180
|
export const learningStartOf = (launch) => launch.learning;
|
|
141
181
|
/** The same start read from a launch body's `learning` member alone (Store.runs.learningStarts), as readLaunchBody reads it. */
|
|
142
182
|
export const learningStartOfStored = (stored) => (stored === undefined ? undefined : readLearning(stored) ?? { seed: null, section: "" });
|
|
143
|
-
const SEED_FAILURES = ["unreadable", "not_copied"];
|
|
183
|
+
const SEED_FAILURES = ["unreadable", "not_copied", "other_disk"];
|
|
144
184
|
/** A learning start with no seed (no commit of main, runs-over-store.ts learningStartFor): the run learns nothing, is
|
|
145
185
|
* never asked what to keep, and so is never told it learns. Why is its `seedFailed`, when its start records one. */
|
|
146
186
|
export const seedFailed = (start) => start.seed === null;
|
|
@@ -9,7 +9,7 @@ export declare function servedRunLearning(deps: {
|
|
|
9
9
|
}, store: Store, runId: string): Promise<{
|
|
10
10
|
run: string;
|
|
11
11
|
state: "dropped" | "merged" | "seeded" | "reflecting";
|
|
12
|
-
reason: "cancelled" | "use" | "empty" | "
|
|
12
|
+
reason: "cancelled" | "reset" | "use" | "empty" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_failed" | "checker" | null;
|
|
13
13
|
detail: string | null;
|
|
14
14
|
at: string;
|
|
15
15
|
workflows: import("./learning.js").LearnedFile[];
|
|
@@ -52,7 +52,7 @@ export declare function servedRunLearning(deps: {
|
|
|
52
52
|
};
|
|
53
53
|
run: string;
|
|
54
54
|
state: "dropped" | "merged" | "seeded" | "reflecting";
|
|
55
|
-
reason: "cancelled" | "use" | "empty" | "
|
|
55
|
+
reason: "cancelled" | "reset" | "use" | "empty" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_failed" | "checker" | null;
|
|
56
56
|
detail: string | null;
|
|
57
57
|
at: string;
|
|
58
58
|
workflows: import("./learning.js").LearnedFile[];
|
package/dist/run-model-key.d.ts
CHANGED
|
@@ -7,8 +7,8 @@ export declare function runModelOrigin(env: NodeJS.ProcessEnv): string | undefin
|
|
|
7
7
|
/** The variables a run's model key fills in a model route's env, for a gateway at `origin`: the gateway's key, and
|
|
8
8
|
* ANTHROPIC_API_KEY where ANTHROPIC_BASE_URL is that same gateway. */
|
|
9
9
|
export declare function runKeyNames(env: NodeJS.ProcessEnv, origin: string): string[];
|
|
10
|
-
/** A model key `body` hands, checked
|
|
11
|
-
*
|
|
10
|
+
/** A model key `body` hands, checked as every handed key is (handed-secret.ts), up to MAX_MODEL_KEY_CHARS. Issues are
|
|
11
|
+
* pushed at `model_key`. */
|
|
12
12
|
export declare function modelKeyOf(value: unknown, issues: InputIssue[]): string | undefined;
|
|
13
13
|
/** 422 model_key_required: a run start, or a message that would start a turn, with no model key to spend: none handed,
|
|
14
14
|
* none the run holds, and none the server holds for its route. */
|
package/dist/run-model-key.js
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
// to spend is 422 model_key_required, never a failure at the first model call. Spend after a run's turn ended (its key
|
|
16
16
|
// erased with that end, and revoked by its caller) or tied to no run, with no key to spend, is skipped or refused in words.
|
|
17
17
|
import { ApiError } from "./errors.js";
|
|
18
|
+
import { handedSecretOf } from "./handed-secret.js";
|
|
18
19
|
import { FAUX_ENV, GATEWAY_KEY_ENV, MODEL_PROVIDER, PROVIDER_KEYS } from "./model.js";
|
|
19
20
|
import { gatewayBase } from "./provider.js";
|
|
20
21
|
/** The longest model key a run takes: a header value, never a document. */
|
|
@@ -50,14 +51,13 @@ export function runKeyNames(env, origin) {
|
|
|
50
51
|
}
|
|
51
52
|
/** Every model key a model route reads by name: each of pi-ai's providers' and the gateway's. */
|
|
52
53
|
const MODEL_KEY_NAMES = new Set([...Object.values(PROVIDER_KEYS).flat(), GATEWAY_KEY_ENV]);
|
|
53
|
-
/** A model key `body` hands, checked
|
|
54
|
-
*
|
|
54
|
+
/** A model key `body` hands, checked as every handed key is (handed-secret.ts), up to MAX_MODEL_KEY_CHARS. Issues are
|
|
55
|
+
* pushed at `model_key`. */
|
|
55
56
|
export function modelKeyOf(value, issues) {
|
|
56
57
|
if (typeof value !== "string")
|
|
57
58
|
return void issues.push({ field: "model_key", reason: "wrong_type", message: "model_key is the run's model key as text, such as a LiteLLM virtual key minted for this run." });
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return value;
|
|
59
|
+
const wrong = handedSecretOf(value, "model_key", MAX_MODEL_KEY_CHARS);
|
|
60
|
+
return wrong ? void issues.push(wrong) : value;
|
|
61
61
|
}
|
|
62
62
|
/** 422 model_key_required: a run start, or a message that would start a turn, with no model key to spend: none handed,
|
|
63
63
|
* none the run holds, and none the server holds for its route. */
|