@parcha/agentrun-serve 0.1.0-beta.49 → 0.1.0-beta.51
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 +173 -9
- package/README.md +246 -39
- package/dist/agent-delete.d.ts +3 -2
- package/dist/agent-delete.js +29 -4
- package/dist/agents-store.js +7 -3
- package/dist/api-only.d.ts +8 -10
- package/dist/api-only.js +11 -12
- package/dist/capacity.d.ts +50 -0
- package/dist/capacity.js +49 -0
- package/dist/cli-learning/claude-wire.d.ts +41 -0
- package/dist/cli-learning/claude-wire.js +258 -0
- package/dist/cli-learning/cli.d.ts +11 -0
- package/dist/cli-learning/cli.js +241 -0
- package/dist/cli-learning/codex-worktree.d.ts +10 -0
- package/dist/cli-learning/codex-worktree.js +119 -0
- package/dist/cli-learning/connections.d.ts +62 -0
- package/dist/cli-learning/connections.js +87 -0
- package/dist/cli-learning/entry.d.ts +1 -0
- package/dist/cli-learning/entry.js +4 -0
- package/dist/cli-learning/evidence.d.ts +78 -0
- package/dist/cli-learning/evidence.js +492 -0
- package/dist/cli-learning/hook.d.ts +33 -0
- package/dist/cli-learning/hook.js +544 -0
- package/dist/cli-learning/install.d.ts +33 -0
- package/dist/cli-learning/install.js +335 -0
- package/dist/cli-learning/observation-proof.d.ts +14 -0
- package/dist/cli-learning/observation-proof.js +10 -0
- package/dist/cli-learning/policy.d.ts +48 -0
- package/dist/cli-learning/policy.js +363 -0
- package/dist/cli-learning/schema.d.ts +16 -0
- package/dist/cli-learning/schema.js +27 -0
- package/dist/cli-learning/state.d.ts +23 -0
- package/dist/cli-learning/state.js +61 -0
- package/dist/cli.js +24 -2
- package/dist/compute-cost.d.ts +101 -0
- package/dist/compute-cost.js +250 -0
- package/dist/console/assets/index-Bt1B51b7.js +733 -0
- package/dist/console/assets/index-sVftE9Ht.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/email/email-faux.d.ts +3 -1
- package/dist/email/email-faux.js +3 -2
- package/dist/email/routes.js +22 -12
- package/dist/eval-previous.d.ts +52 -0
- package/dist/eval-previous.js +164 -0
- package/dist/file-types.d.ts +2 -0
- package/dist/file-types.js +3 -1
- package/dist/harness-install.d.ts +6 -2
- package/dist/harness-install.js +40 -8
- package/dist/harness.d.ts +1 -1
- package/dist/harness.js +3 -2
- package/dist/learn/check.d.ts +8 -5
- package/dist/learn/check.js +25 -24
- package/dist/learn/repick.d.ts +22 -13
- package/dist/learn/repick.js +57 -56
- package/dist/learn/secrets.js +14 -3
- package/dist/learn/workflow-draft.d.ts +4 -0
- package/dist/learn/workflow-draft.js +10 -7
- package/dist/learned-workflow.js +8 -8
- package/dist/learning-setting.js +2 -2
- package/dist/learning-words.d.ts +1 -1
- package/dist/learning-words.js +1 -1
- package/dist/mcp-pin-first.js +2 -1
- package/dist/mcp-private-hosts.d.ts +24 -3
- package/dist/mcp-private-hosts.js +53 -3
- package/dist/model-gateway.d.ts +2 -0
- package/dist/model-gateway.js +3 -1
- package/dist/native/runtimes.d.ts +2 -0
- package/dist/native/runtimes.js +2 -0
- package/dist/observation/learning.d.ts +32 -0
- package/dist/observation/learning.js +66 -0
- package/dist/observation/observer.d.ts +8 -1
- package/dist/observation/observer.js +89 -9
- package/dist/observation/schema.js +12 -4
- package/dist/observation/usage-identity.d.ts +9 -0
- package/dist/observation/usage-identity.js +11 -0
- package/dist/openapi.js +113 -29
- package/dist/paid-calls.d.ts +13 -6
- package/dist/paid-calls.js +14 -8
- package/dist/run-launch.d.ts +16 -2
- package/dist/run-launch.js +6 -1
- package/dist/run-timeline-served.js +5 -3
- package/dist/run-usage.d.ts +23 -8
- package/dist/run-usage.js +100 -18
- package/dist/run-view.d.ts +2 -0
- package/dist/run-view.js +12 -7
- package/dist/runner/adapter-loop.d.ts +4 -0
- package/dist/runner/adapter-loop.js +44 -27
- package/dist/runner/adapter-run-spec.d.ts +8 -3
- package/dist/runner/adapter-run-spec.js +15 -8
- package/dist/runner/beside.d.ts +13 -0
- package/dist/runner/beside.js +27 -8
- package/dist/runner/big-writes.d.ts +33 -0
- package/dist/runner/big-writes.js +105 -0
- package/dist/runner/cli-run-spec.js +16 -8
- package/dist/runner/disk-free.d.ts +44 -0
- package/dist/runner/disk-free.js +96 -0
- package/dist/runner/feedback-round.d.ts +12 -8
- package/dist/runner/feedback-round.js +16 -30
- package/dist/runner/harness-loops.js +3 -1
- package/dist/runner/held.d.ts +4 -1
- package/dist/runner/journal-kinds.d.ts +1 -1
- package/dist/runner/learning-end.js +13 -4
- package/dist/runner/main.d.ts +17 -6
- package/dist/runner/main.js +187 -45
- package/dist/runner/metrics.d.ts +4 -0
- package/dist/runner/metrics.js +9 -0
- package/dist/runner/presence.d.ts +11 -2
- package/dist/runner/presence.js +31 -3
- package/dist/runner/run-child-host.d.ts +27 -17
- package/dist/runner/run-child-host.js +70 -116
- package/dist/runner/run-child.js +3 -0
- package/dist/runner/run-errors.js +2 -0
- package/dist/runner/runner-check.d.ts +51 -0
- package/dist/runner/runner-check.js +206 -0
- package/dist/runner/runner-metrics.d.ts +19 -0
- package/dist/runner/runner-metrics.js +49 -0
- package/dist/runner/runner.d.ts +37 -0
- package/dist/runner/runner.js +43 -3
- package/dist/runner/save-slots.d.ts +9 -0
- package/dist/runner/save-slots.js +91 -0
- package/dist/runner/sdk-loop.js +34 -22
- package/dist/runs-over-store.d.ts +8 -1
- package/dist/runs-over-store.js +57 -9
- package/dist/sdk/runs.d.ts +25 -6
- package/dist/sdk/runs.js +107 -35
- package/dist/sdk/runtimes.d.ts +19 -0
- package/dist/sdk/runtimes.js +23 -0
- package/dist/sdk/schema.d.ts +14 -8
- package/dist/sdk/schema.js +18 -6
- package/dist/server.d.ts +7 -0
- package/dist/server.js +151 -28
- package/dist/skills/agentrun-serve/SKILL.md +52 -7
- package/dist/start-switches.js +2 -0
- package/dist/stats.d.ts +4 -0
- package/dist/stats.js +1 -1
- package/dist/store/agent-body.d.ts +13 -2
- package/dist/store/agent-body.js +19 -4
- package/dist/store/dialect.d.ts +2 -0
- package/dist/store/dialect.js +1 -0
- package/dist/store/index.d.ts +3 -3
- package/dist/store/index.js +2 -2
- package/dist/store/postgres/connection.d.ts +5 -2
- package/dist/store/postgres/connection.js +19 -7
- package/dist/store/postgres/dialect.js +1 -0
- package/dist/store/postgres/migrate.d.ts +30 -0
- package/dist/store/postgres/migrate.js +72 -5
- package/dist/store/postgres/migration-lint.d.ts +8 -0
- package/dist/store/postgres/migration-lint.js +119 -0
- package/dist/store/postgres/migrations/0023_computer_interval_resources.sql +14 -0
- package/dist/store/postgres/migrations/0024_runner_capacity.sql +28 -0
- package/dist/store/postgres/store.d.ts +8 -3
- package/dist/store/postgres/store.js +31 -11
- package/dist/store/schema.d.ts +26 -4
- package/dist/store/schema.js +45 -4
- package/dist/store/sqlite/connection.d.ts +3 -3
- package/dist/store/sqlite/connection.js +3 -3
- package/dist/store/sqlite/run-launch.d.ts +9 -1
- package/dist/store/sqlite/run-launch.js +44 -0
- package/dist/store/sqlite/store.d.ts +19 -4
- package/dist/store/sqlite/store.js +180 -93
- package/dist/store/store-schema.d.ts +34 -0
- package/dist/store/store-schema.js +125 -0
- package/dist/store/store.d.ts +61 -2
- package/dist/store/store.js +13 -0
- package/dist/store-reads/analytics.d.ts +3 -2
- package/dist/store-reads/analytics.js +20 -8
- package/dist/store-reads/cap.d.ts +9 -5
- package/dist/store-reads/cap.js +28 -2
- package/dist/store-reads/decisions.d.ts +21 -0
- package/dist/store-reads/decisions.js +22 -0
- package/dist/store-reads/journal.d.ts +8 -2
- package/dist/store-reads/journal.js +27 -8
- package/dist/store-view.d.ts +9 -4
- package/dist/store-view.js +48 -25
- package/dist/template-eval.d.ts +15 -1
- package/dist/template-eval.js +92 -13
- package/dist/templates.d.ts +4 -3
- package/dist/templates.js +4 -3
- package/dist/timeline/labels.js +17 -0
- package/dist/tool-gate.d.ts +4 -2
- package/dist/tool-list.js +1 -0
- package/dist/tools.d.ts +6 -2
- package/dist/tools.js +13 -1
- package/dist/trigger-targets.d.ts +21 -5
- package/dist/trigger-targets.js +13 -10
- package/dist/unified-usage.d.ts +24 -0
- package/dist/unified-usage.js +400 -0
- package/dist/uploads-archil.d.ts +100 -0
- package/dist/uploads-archil.js +430 -0
- package/dist/uploads.d.ts +55 -1
- package/dist/uploads.js +185 -98
- package/dist/validate.js +1 -1
- package/dist/web-fake.d.ts +25 -0
- package/dist/web-fake.js +38 -1
- package/dist/web-save.d.ts +75 -0
- package/dist/web-save.js +235 -0
- package/dist/workspace/archil-claim.d.ts +5 -2
- package/dist/workspace/archil-claim.js +5 -2
- package/dist/workspace/archil-disk.d.ts +11 -1
- package/dist/workspace/archil-disk.js +43 -10
- package/dist/workspace/archil.d.ts +3 -0
- package/dist/workspace/archil.js +102 -16
- package/dist/workspace/computer-for-claim.d.ts +14 -0
- package/dist/workspace/computer-for-claim.js +46 -7
- package/dist/workspace/computer-intervals.d.ts +9 -3
- package/dist/workspace/computer-intervals.js +17 -8
- package/dist/workspace/pieced.d.ts +14 -0
- package/dist/workspace/pieced.js +23 -0
- package/dist/workspace/run-disk.js +32 -12
- package/dist/workspace/run-workspace.d.ts +1 -1
- package/dist/workspace/run-workspace.js +11 -6
- package/package.json +10 -10
- package/skills/agentrun-serve/SKILL.md +52 -7
- package/templates/README.md +36 -7
- package/dist/console/assets/index-Bzn4eUYF.js +0 -715
- package/dist/console/assets/index-CR2ZGei1.css +0 -1
package/dist/sdk/runs.js
CHANGED
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
import { createHash, createHmac, timingSafeEqual } from "node:crypto";
|
|
4
4
|
import { inspectWorkflow, resolveSchemaForWorkflow } from "@parcha/agentrun-dsl";
|
|
5
5
|
import { ApiError } from "../errors.js";
|
|
6
|
-
import { canonical, isObject } from "../store/agent-body.js";
|
|
6
|
+
import { canonical, isObject, cliLearningOf, learningSettingForBody } from "../store/agent-body.js";
|
|
7
7
|
import { uuidv7 } from "../agents-store.js";
|
|
8
8
|
import { launchBody } from "../run-launch.js";
|
|
9
9
|
import { learningStartFor } from "../runs-over-store.js";
|
|
10
10
|
import { chooseWorkflows, learningFolderOf, seedAt, secretsShown } from "../learning.js";
|
|
11
11
|
import { INSTRUCTION_EVIDENCE_BYTES } from "../native/instructions.js";
|
|
12
|
+
import { CLI_POLICY_BYTES } from "../cli-learning/policy.js";
|
|
12
13
|
import { refuseWhileNoRunner } from "../runner/presence.js";
|
|
13
14
|
import { secretRedactor } from "../runner/redact.js";
|
|
14
15
|
import { redactedOutput } from "../key-refusal.js";
|
|
@@ -17,6 +18,15 @@ import { sdkWorkflowManifest, sdkDraftTools } from "./workflows.js";
|
|
|
17
18
|
import { promotionOf, promotionsOf } from "../learn/promote.js";
|
|
18
19
|
import { championTextOf, releaseSdkCheck, reserveSdkCheck } from "../runner/promotion.js";
|
|
19
20
|
import { fits, workflowDigest } from "../runner/workflow-first.js";
|
|
21
|
+
import { SDK_WORKFLOW_RUNTIMES, sdkBindingOf } from "./runtimes.js";
|
|
22
|
+
export { SDK_RUNTIMES, isSdkRuntime } from "./runtimes.js";
|
|
23
|
+
/** Claude's begin snapshot is provisional; only its immutable same-window completion can establish policy. */
|
|
24
|
+
export function cliPolicyOf(launch, completion) {
|
|
25
|
+
const cli = launch.cli_learning;
|
|
26
|
+
if (!cli)
|
|
27
|
+
return undefined;
|
|
28
|
+
return cli.runtime === "claude-code-cli" ? completion?.source_policy ?? { instructions: "The current Claude prompt policy was not captured.", complete: false } : { instructions: cli.instructions, complete: cli.policy_complete };
|
|
29
|
+
}
|
|
20
30
|
const keyOf = (id) => `sdk-run:${id}`;
|
|
21
31
|
/** The settings key an SDK run's record is kept under (the run's delete with its agent's: agent-delete.ts). */
|
|
22
32
|
export const sdkRunKey = keyOf;
|
|
@@ -51,9 +61,7 @@ const usageOf = (value) => {
|
|
|
51
61
|
}
|
|
52
62
|
return result;
|
|
53
63
|
};
|
|
54
|
-
export const sdkOf = (body) => isObject(body)
|
|
55
|
-
? { runtime: body.sdk.runtime }
|
|
56
|
-
: undefined;
|
|
64
|
+
export const sdkOf = (body) => isObject(body) ? sdkBindingOf(body.sdk) : undefined;
|
|
57
65
|
export async function sdkInbox(store, runId) {
|
|
58
66
|
const row = await store.settings.get(keyOf(runId));
|
|
59
67
|
if (!isObject(row))
|
|
@@ -126,7 +134,7 @@ function checkToolParents(row, events) {
|
|
|
126
134
|
/** The key a server signs its SDK runs' credentials with: derived from its seal key (seal-key.ts), which stays the
|
|
127
135
|
* store's for its life, so adding, reordering or removing an API token (api-token.ts) never changes a run's credential. */
|
|
128
136
|
export const sdkRunSecret = (sealKey) => createHmac("sha256", sealKey).update("agentrun sdk-run credentials").digest("base64url");
|
|
129
|
-
const sign = (secret, runId) =>
|
|
137
|
+
const sign = (secret, runId, lane = "sdk") => `${lane === "cli" ? "ar_cli_run_" : "ar_sdk_"}${createHmac("sha256", secret).update(`${lane}-run\0${runId}`).digest("base64url")}`;
|
|
130
138
|
const digest = (text) => createHash("sha256").update(text).digest();
|
|
131
139
|
export class SdkRuns {
|
|
132
140
|
store;
|
|
@@ -134,47 +142,61 @@ export class SdkRuns {
|
|
|
134
142
|
secret;
|
|
135
143
|
secrets;
|
|
136
144
|
earlier;
|
|
145
|
+
lane;
|
|
137
146
|
/** `earlier` are the keys credentials were once signed with (the server's API tokens, before `secret` was its seal
|
|
138
147
|
* key's): a credential any of them signed is still taken, so a run started before an upgrade keeps its credential. */
|
|
139
|
-
constructor(store, data, secret, secrets = () => [], earlier = []) {
|
|
148
|
+
constructor(store, data, secret, secrets = () => [], earlier = [], lane = "sdk") {
|
|
140
149
|
this.store = store;
|
|
141
150
|
this.data = data;
|
|
142
151
|
this.secret = secret;
|
|
143
152
|
this.secrets = secrets;
|
|
144
153
|
this.earlier = earlier;
|
|
154
|
+
this.lane = lane;
|
|
145
155
|
}
|
|
146
156
|
token(runId) {
|
|
147
|
-
return sign(this.secret, runId);
|
|
157
|
+
return sign(this.secret, runId, this.lane);
|
|
148
158
|
}
|
|
149
159
|
async authenticate(runId, token) {
|
|
150
160
|
// Every key compared, on equal-length digests, with no early return.
|
|
151
161
|
const given = digest(token);
|
|
152
162
|
let ok = false;
|
|
153
163
|
for (const key of [this.secret, ...this.earlier])
|
|
154
|
-
ok = timingSafeEqual(given, digest(sign(key, runId))) || ok;
|
|
164
|
+
ok = timingSafeEqual(given, digest(sign(key, runId, this.lane))) || ok;
|
|
155
165
|
if (!ok)
|
|
156
166
|
throw new ApiError("unauthenticated", "This credential is scoped to a different SDK run.");
|
|
157
167
|
await sdkInbox(this.store, runId);
|
|
158
168
|
}
|
|
159
169
|
clean(body, runId) {
|
|
160
|
-
const redact = secretRedactor([...this.secrets(), ...(runId ? [this.secret, ...this.earlier].map((key) => sign(key, runId)) : [])]);
|
|
170
|
+
const redact = secretRedactor([...this.secrets(), ...(runId ? [this.secret, ...this.earlier].map((key) => sign(key, runId, this.lane)) : [])]);
|
|
161
171
|
// Redact values structurally: a long string or encoded credential can be withheld whole,
|
|
162
172
|
// so treating serialized JSON as prose could remove its delimiters and corrupt the envelope.
|
|
163
173
|
return redactedOutput(body, redact.heldValues?.() ?? []);
|
|
164
174
|
}
|
|
165
|
-
async start(entry, body, deps, origin, compile, consoleOrigin) {
|
|
166
|
-
|
|
167
|
-
|
|
175
|
+
async start(entry, body, deps, origin, compile, consoleOrigin, cli) {
|
|
176
|
+
if (this.lane !== (cli ? "cli" : "sdk"))
|
|
177
|
+
refuse("The run must use its enrolled credential lane.");
|
|
178
|
+
only(body, cli ? ["runtime", "input", "instructions", "model"] : ["runtime", "platform", "input", "instructions", "model", "workflow_tools", "workflow_adapters"]);
|
|
179
|
+
const source = cli ? undefined : sdkBindingOf(body) ?? refuse("The SDK source needs a supported runtime; external requires a platform label of 1–80 characters without surrounding whitespace, controls or lone surrogates. Other runtimes do not take platform.");
|
|
180
|
+
if (source && !SDK_WORKFLOW_RUNTIMES.includes(source.runtime) && (body.workflow_tools !== undefined || body.workflow_adapters !== undefined))
|
|
181
|
+
refuse("External runs receive owner corrections; workflow_tools and workflow_adapters require a backend workflow bridge.");
|
|
182
|
+
const workflow = cli ? undefined : sdkWorkflowManifest(body.workflow_tools, body.workflow_adapters);
|
|
168
183
|
if (workflow && canonical(this.clean(workflow)) !== canonical(workflow))
|
|
169
184
|
refuse("The workflow manifest contains a protected value; keep credentials in the backend.");
|
|
170
185
|
const binding = sdkOf(entry.revision?.body);
|
|
171
|
-
if (
|
|
172
|
-
|
|
186
|
+
if (cli) {
|
|
187
|
+
if (cliLearningOf(entry.revision?.body)?.connection_id !== cli.connection_id)
|
|
188
|
+
refuse("CLI connection does not match the enrolled agent.");
|
|
189
|
+
if (body.runtime !== cli.runtime)
|
|
190
|
+
refuse("The CLI runtime must match the enrolled agent.");
|
|
191
|
+
}
|
|
192
|
+
else if (!binding || source.runtime !== binding.runtime || source.platform !== binding.platform) {
|
|
193
|
+
refuse("The SDK runtime and platform must match the registered agent.");
|
|
194
|
+
}
|
|
195
|
+
if (!entry.revision)
|
|
196
|
+
throw new ApiError("agent_not_runnable", "This agent has no current registered revision.");
|
|
173
197
|
if (entry.agent.archivedAt !== null)
|
|
174
198
|
throw new ApiError("agent_archived", "This SDK agent is archived.");
|
|
175
|
-
|
|
176
|
-
refuse("The SDK runtime must match the registered agent.");
|
|
177
|
-
const input = text(body.input, "input"), instructions = text(body.instructions, "instructions");
|
|
199
|
+
const input = text(body.input, "input"), instructions = text(body.instructions, "instructions", cli ? CLI_POLICY_BYTES : TEXT_LIMIT);
|
|
178
200
|
const model = body.model === undefined ? undefined : text(body.model, "model", 256);
|
|
179
201
|
if (origin) {
|
|
180
202
|
const known = await this.store.runOfOrigin(origin.key);
|
|
@@ -194,16 +216,17 @@ export class SdkRuns {
|
|
|
194
216
|
// A runner keeps an SDK run's evidence and ends it: while every runner here refused to claim, the start is refused in
|
|
195
217
|
// their words, as any start is (prepareLaunch), before the caller holds a receipt it would run on.
|
|
196
218
|
await refuseWhileNoRunner(this.store.runners);
|
|
197
|
-
const learning = await learningStartFor(deps, entry, pinned.revision, revisionBody, {
|
|
219
|
+
const learning = await learningStartFor(deps, entry, pinned.revision, { ...revisionBody, learning: learningSettingForBody(revisionBody) }, {
|
|
198
220
|
noWorkflows: !workflow,
|
|
199
221
|
...(compile.model ? { model: compile.model } : {}),
|
|
200
222
|
});
|
|
201
223
|
if (learning) {
|
|
202
|
-
if (Buffer.byteLength(instructions) > INSTRUCTION_EVIDENCE_BYTES)
|
|
203
|
-
refuse("Original SDK instructions exceed the 64 KiB learning evidence limit. Keep learning off or provide a complete policy within that limit.");
|
|
204
|
-
if (!learning.model)
|
|
224
|
+
if (Buffer.byteLength(instructions) > (cli ? CLI_POLICY_BYTES : INSTRUCTION_EVIDENCE_BYTES))
|
|
225
|
+
refuse(cli ? "Original CLI instructions exceed the 256 KiB evidence limit. Keep capture off or provide a complete policy within that limit." : "Original SDK instructions exceed the 64 KiB learning evidence limit. Keep learning off or provide a complete policy within that limit.");
|
|
226
|
+
if (!cli && !learning.model)
|
|
205
227
|
throw new ApiError("agent_not_runnable", "Self-improving SDK runs need a server model and its model key to compile workflows. Configure the model or turn self-improving off.");
|
|
206
|
-
|
|
228
|
+
if (!cli)
|
|
229
|
+
await compile.check(learning.model);
|
|
207
230
|
if (learning.seedFailed)
|
|
208
231
|
throw new ApiError("unavailable", "The learning seed could not be read. Retry after restoring the agent learning folder.");
|
|
209
232
|
}
|
|
@@ -229,13 +252,13 @@ export class SdkRuns {
|
|
|
229
252
|
input: { content: cleanedInput },
|
|
230
253
|
title: cleanedInput.trim().replace(/\s+/g, " ").slice(0, 80),
|
|
231
254
|
place: { mode: "runner" },
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
...(cleaned.model ? { model: cleaned.model } : {}),
|
|
238
|
-
},
|
|
255
|
+
...(cli ? {
|
|
256
|
+
harness: "cli",
|
|
257
|
+
cli_learning: { ...cli, instructions: cleaned.instructions, policy_complete: cli.policy_complete && cleaned.instructions === instructions, ...(cleaned.model ? { model: cleaned.model } : {}) },
|
|
258
|
+
} : {
|
|
259
|
+
harness: "sdk",
|
|
260
|
+
sdk: { ...binding, ...workflow, instructions: cleaned.instructions, ...(cleaned.model ? { model: cleaned.model } : {}) },
|
|
261
|
+
}),
|
|
239
262
|
...(learning ? { learning: { ...learning, workflows: workflows.map((flow) => flow.name) } } : {}),
|
|
240
263
|
};
|
|
241
264
|
const now = Date.now();
|
|
@@ -243,11 +266,12 @@ export class SdkRuns {
|
|
|
243
266
|
await this.store.settings.put(keyOf(runId), {
|
|
244
267
|
run_id: runId,
|
|
245
268
|
created_at: now,
|
|
246
|
-
expires_at: now + 3_600_000,
|
|
269
|
+
expires_at: now + (cli ? 86_400_000 : 3_600_000),
|
|
247
270
|
batches: [],
|
|
248
271
|
learning_workflows: workflows,
|
|
249
272
|
...(check ? { learning_check: check } : {}),
|
|
250
273
|
...(redacted ? { check_redacted: true } : {}),
|
|
274
|
+
...(cli && cleanedInput !== input ? { evidence_incomplete: true } : {}),
|
|
251
275
|
});
|
|
252
276
|
await this.store.runs.create({ id: runId, agentId: entry.agent.id, revisionId: entry.revision.id, ...(origin ? { origin } : {}) }, { body: launchBody(launch) });
|
|
253
277
|
}
|
|
@@ -260,6 +284,16 @@ export class SdkRuns {
|
|
|
260
284
|
if (record?.decided === "replaying" && record.replay_id === check.id)
|
|
261
285
|
await releaseSdkCheck(checkDeps, record, "its start could not be admitted", false).catch(() => undefined);
|
|
262
286
|
}
|
|
287
|
+
// Two source hooks may admit the same immutable prompt window under different transport keys.
|
|
288
|
+
// The store's origin constraint chooses one; recover its receipt without creating another run.
|
|
289
|
+
if (origin) {
|
|
290
|
+
const known = await this.store.runOfOrigin(origin.key);
|
|
291
|
+
if (known) {
|
|
292
|
+
if (known.fingerprint !== origin.fingerprint)
|
|
293
|
+
throw new ApiError("idempotency_mismatch", "The key was used with another SDK start.");
|
|
294
|
+
return this.receipt(known.runId, consoleOrigin);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
263
297
|
throw error;
|
|
264
298
|
}
|
|
265
299
|
return this.receipt(runId, consoleOrigin);
|
|
@@ -351,9 +385,16 @@ export class SdkRuns {
|
|
|
351
385
|
refuse("Supply a positive sequence and at most 100 events.");
|
|
352
386
|
if (Buffer.byteLength(JSON.stringify(body)) > BATCH_LIMIT)
|
|
353
387
|
throw new ApiError("payload_too_large", "An SDK event batch exceeds 256 KB.");
|
|
388
|
+
const launch = (await this.store.runs.launch(runId)).body;
|
|
354
389
|
const events = body.events.map((value) => {
|
|
355
390
|
if (!isObject(value))
|
|
356
391
|
return refuse("An SDK event must be an object.");
|
|
392
|
+
if (value.type === "message" && launch.cli_learning) {
|
|
393
|
+
only(value, ["type", "role", "text"]);
|
|
394
|
+
if (value.role !== "user" && value.role !== "assistant")
|
|
395
|
+
return refuse("A dialogue message role must be user or assistant.");
|
|
396
|
+
return { type: "message", role: value.role, text: text(value.text, "text") };
|
|
397
|
+
}
|
|
357
398
|
if (value.type === "text") {
|
|
358
399
|
only(value, ["type", "text"]);
|
|
359
400
|
return { type: "text", text: text(value.text, "text") };
|
|
@@ -431,25 +472,56 @@ export class SdkRuns {
|
|
|
431
472
|
for (const check of checks)
|
|
432
473
|
if (!row.learning_check || check.id !== row.learning_check.id || check.digest !== row.learning_check.digest)
|
|
433
474
|
refuse("The workflow check must name this SDK run's reserved candidate.");
|
|
434
|
-
return { ...row, batches: [...row.batches, batch], ...(checkRedacted ? { check_redacted: true } : {}) };
|
|
475
|
+
return { ...row, batches: [...row.batches, batch], ...(checkRedacted ? { check_redacted: true, ...(launch.cli_learning ? { evidence_incomplete: true } : {}) } : {}) };
|
|
435
476
|
}, EVIDENCE_LIMIT);
|
|
436
477
|
return { accepted: true };
|
|
437
478
|
}
|
|
438
479
|
async complete(runId, body) {
|
|
439
|
-
|
|
480
|
+
const launch = (await this.store.runs.launch(runId)).body;
|
|
481
|
+
only(body, ["status", "answer", "error", "model", "session_id", "usage", "evidence_complete", ...(launch.cli_learning ? ["seed_observed", "seed_revision"] : []), ...(launch.cli_learning?.runtime === "claude-code-cli" ? ["source_policy"] : [])]);
|
|
482
|
+
if (body.seed_observed !== undefined && typeof body.seed_observed !== "boolean")
|
|
483
|
+
refuse("seed_observed must be a boolean.");
|
|
484
|
+
if (body.seed_observed === true && (!launch.learning?.seed || !launch.learning.section.trim() || body.seed_revision !== launch.learning.seed))
|
|
485
|
+
refuse("An observed seed requires pinned owner corrections and the matching revision from this prompt window receipt.");
|
|
440
486
|
if (body.evidence_complete !== undefined && typeof body.evidence_complete !== "boolean")
|
|
441
487
|
refuse("evidence_complete must be a boolean.");
|
|
442
488
|
if (!["completed", "failed", "cancelled"].includes(String(body.status)))
|
|
443
489
|
refuse("SDK completion status is completed, failed or cancelled.");
|
|
444
|
-
|
|
490
|
+
if (launch.cli_learning && body.session_id !== undefined && body.session_id !== launch.cli_learning.session_id)
|
|
491
|
+
refuse("The completion session_id must match this CLI prompt window.");
|
|
492
|
+
let sourcePolicy;
|
|
493
|
+
if (body.source_policy !== undefined) {
|
|
494
|
+
if (!isObject(body.source_policy))
|
|
495
|
+
refuse("source_policy must be the current Claude prompt snapshot.");
|
|
496
|
+
const policy = body.source_policy;
|
|
497
|
+
only(policy, ["instructions", "complete"]);
|
|
498
|
+
if (typeof policy.complete !== "boolean")
|
|
499
|
+
refuse("source_policy.complete must be explicit.");
|
|
500
|
+
const instructions = text(policy.instructions, "source_policy.instructions", CLI_POLICY_BYTES);
|
|
501
|
+
if (Buffer.byteLength(instructions) > CLI_POLICY_BYTES)
|
|
502
|
+
refuse("The CLI source policy exceeds 256 KiB; mark capture incomplete rather than truncating it.");
|
|
503
|
+
sourcePolicy = { instructions, complete: policy.complete };
|
|
504
|
+
}
|
|
505
|
+
const submitted = {
|
|
445
506
|
status: body.status,
|
|
507
|
+
...(sourcePolicy ? { source_policy: sourcePolicy } : {}),
|
|
446
508
|
answer: text(body.answer, "answer"),
|
|
447
509
|
...(body.evidence_complete !== undefined ? { evidence_complete: body.evidence_complete } : {}),
|
|
510
|
+
...(body.seed_observed !== undefined ? { seed_observed: body.seed_observed } : {}),
|
|
511
|
+
...(body.seed_revision !== undefined ? { seed_revision: text(body.seed_revision, "seed_revision", 128) } : {}),
|
|
448
512
|
...(body.error !== undefined ? { error: text(body.error, "error", 8000) } : {}),
|
|
449
513
|
...(body.model !== undefined ? { model: text(body.model, "model", 256) } : {}),
|
|
450
514
|
...(body.session_id !== undefined ? { session_id: text(body.session_id, "session_id", 256) } : {}),
|
|
451
515
|
...(body.usage !== undefined ? { usage: usageOf(body.usage) } : {}),
|
|
452
|
-
}
|
|
516
|
+
};
|
|
517
|
+
const completion = this.clean(submitted, runId);
|
|
518
|
+
// Source policy has its own completeness flag; redacted execution evidence cannot
|
|
519
|
+
// be represented as complete even when the source explicitly claimed it was.
|
|
520
|
+
const { source_policy: _submittedPolicy, ...submittedEvidence } = submitted;
|
|
521
|
+
const { source_policy: _cleanedPolicy, ...cleanedEvidence } = completion;
|
|
522
|
+
const evidenceIncomplete = !!launch.cli_learning && canonical(submittedEvidence) !== canonical(cleanedEvidence);
|
|
523
|
+
if (completion.source_policy && completion.source_policy.instructions !== sourcePolicy.instructions)
|
|
524
|
+
completion.source_policy.complete = false;
|
|
453
525
|
const known = (await sdkInbox(this.store, runId)).completion;
|
|
454
526
|
if (known) {
|
|
455
527
|
if (canonical(known) !== canonical(completion))
|
|
@@ -464,7 +536,7 @@ export class SdkRuns {
|
|
|
464
536
|
return row;
|
|
465
537
|
}
|
|
466
538
|
writableInbox(row);
|
|
467
|
-
return { ...row, completion, ...(completion.answer !== body.answer ? { check_redacted: true } : {}) };
|
|
539
|
+
return { ...row, completion, ...(evidenceIncomplete ? { evidence_incomplete: true } : {}), ...(completion.answer !== body.answer ? { check_redacted: true } : {}) };
|
|
468
540
|
});
|
|
469
541
|
return { accepted: true };
|
|
470
542
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Execution stays with the caller. External platforms report through the same API without becoming a managed
|
|
2
|
+
* harness or acquiring a workflow bridge. Their platform is a display label, never a capability selector. */
|
|
3
|
+
export declare const SDK_RUNTIMES: readonly ["claude-agent-sdk", "codex-sdk", "eve", "external"];
|
|
4
|
+
export type SdkRuntime = (typeof SDK_RUNTIMES)[number];
|
|
5
|
+
export type SdkBinding = {
|
|
6
|
+
runtime: Exclude<SdkRuntime, "external">;
|
|
7
|
+
platform?: never;
|
|
8
|
+
} | {
|
|
9
|
+
runtime: "external";
|
|
10
|
+
platform: string;
|
|
11
|
+
};
|
|
12
|
+
/** Only these integrations supply a backend workflow bridge. */
|
|
13
|
+
export declare const SDK_WORKFLOW_RUNTIMES: readonly SdkRuntime[];
|
|
14
|
+
export declare const isSdkRuntime: (value: unknown) => value is SdkRuntime;
|
|
15
|
+
export declare const SDK_PLATFORM_MAX_LENGTH = 80;
|
|
16
|
+
export declare const SDK_PLATFORM_PATTERN = "^(?!\\s)(?![\\s\\S]*\\s$)[^\\u0000-\\u001f\\u007f-\\u009f\\ud800-\\udfff]+$";
|
|
17
|
+
export declare const isSdkPlatform: (value: unknown) => value is string;
|
|
18
|
+
/** Read just the source identity from a binding, start body or persisted launch. Callers check their own extra keys. */
|
|
19
|
+
export declare function sdkBindingOf(value: unknown): SdkBinding | undefined;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** Execution stays with the caller. External platforms report through the same API without becoming a managed
|
|
2
|
+
* harness or acquiring a workflow bridge. Their platform is a display label, never a capability selector. */
|
|
3
|
+
export const SDK_RUNTIMES = ["claude-agent-sdk", "codex-sdk", "eve", "external"];
|
|
4
|
+
/** Only these integrations supply a backend workflow bridge. */
|
|
5
|
+
export const SDK_WORKFLOW_RUNTIMES = ["claude-agent-sdk", "codex-sdk", "eve"];
|
|
6
|
+
export const isSdkRuntime = (value) => typeof value === "string" && SDK_RUNTIMES.includes(value);
|
|
7
|
+
export const SDK_PLATFORM_MAX_LENGTH = 80;
|
|
8
|
+
// Unicode mode treats a surrogate pair as one character; the range rejects only a lone half. Keep the schema and
|
|
9
|
+
// runtime check identical, including the refusal to trim a label that participates in an agent's identity.
|
|
10
|
+
export const SDK_PLATFORM_PATTERN = "^(?!\\s)(?![\\s\\S]*\\s$)[^\\u0000-\\u001f\\u007f-\\u009f\\ud800-\\udfff]+$";
|
|
11
|
+
const platformPattern = new RegExp(SDK_PLATFORM_PATTERN, "u");
|
|
12
|
+
export const isSdkPlatform = (value) => typeof value === "string" && [...value].length <= SDK_PLATFORM_MAX_LENGTH && platformPattern.test(value);
|
|
13
|
+
/** Read just the source identity from a binding, start body or persisted launch. Callers check their own extra keys. */
|
|
14
|
+
export function sdkBindingOf(value) {
|
|
15
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
16
|
+
return undefined;
|
|
17
|
+
const { runtime, platform } = value;
|
|
18
|
+
if (!isSdkRuntime(runtime))
|
|
19
|
+
return undefined;
|
|
20
|
+
if (runtime === "external")
|
|
21
|
+
return isSdkPlatform(platform) ? { runtime, platform } : undefined;
|
|
22
|
+
return platform === undefined ? { runtime } : undefined;
|
|
23
|
+
}
|
package/dist/sdk/schema.d.ts
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
export declare const SDK_BINDING: {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
"x-agentrun-python-preserve-object": boolean;
|
|
3
|
+
oneOf: {
|
|
4
|
+
type: string;
|
|
5
|
+
additionalProperties: boolean;
|
|
6
|
+
properties: Record<string, unknown>;
|
|
7
|
+
required: string[];
|
|
8
|
+
}[];
|
|
6
9
|
};
|
|
7
10
|
export declare const SDK_RUN: {
|
|
8
11
|
"x-agentrun-serve": string;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
"x-agentrun-python-preserve-object": boolean;
|
|
13
|
+
oneOf: {
|
|
14
|
+
type: string;
|
|
15
|
+
additionalProperties: boolean;
|
|
16
|
+
properties: Record<string, unknown>;
|
|
17
|
+
required: string[];
|
|
18
|
+
}[];
|
|
13
19
|
};
|
|
14
20
|
export declare const SDK_PATHS: {
|
|
15
21
|
"/agents/{agent_id}/sdk-runs": {
|
package/dist/sdk/schema.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { MCP_TOOL_KEY_PATTERN } from "../tool-names.js";
|
|
2
|
+
import { SDK_RUNTIMES, SDK_PLATFORM_MAX_LENGTH, SDK_PLATFORM_PATTERN } from "./runtimes.js";
|
|
2
3
|
const text = { type: "string" };
|
|
3
4
|
const object = (properties, required = Object.keys(properties)) => ({
|
|
4
5
|
type: "object",
|
|
@@ -6,14 +7,26 @@ const object = (properties, required = Object.keys(properties)) => ({
|
|
|
6
7
|
properties,
|
|
7
8
|
required,
|
|
8
9
|
});
|
|
9
|
-
|
|
10
|
+
const platform = {
|
|
11
|
+
...text, minLength: 1, maxLength: SDK_PLATFORM_MAX_LENGTH, pattern: SDK_PLATFORM_PATTERN,
|
|
12
|
+
description: "External source's display label, such as openclaw or capy. Preserved exactly; no surrounding whitespace, controls or lone surrogates. Never selects a managed harness or workflow capability.",
|
|
13
|
+
};
|
|
14
|
+
/** Closed alternatives keep platform required only for external sources in every generated client. External starts
|
|
15
|
+
* do not accept bridge fields, even an empty catalog: a platform name never confers an integration's capabilities. */
|
|
16
|
+
const sdkObject = (properties = {}, required = Object.keys(properties)) => ({
|
|
17
|
+
"x-agentrun-python-preserve-object": true,
|
|
18
|
+
oneOf: [
|
|
19
|
+
object({ runtime: { enum: SDK_RUNTIMES.filter(runtime => runtime !== "external") }, ...properties }, ["runtime", ...required]),
|
|
20
|
+
object({ runtime: { const: "external" }, platform, ...Object.fromEntries(Object.entries(properties).filter(([key]) => key !== "workflow_tools" && key !== "workflow_adapters")) }, ["runtime", "platform", ...required]),
|
|
21
|
+
],
|
|
22
|
+
});
|
|
23
|
+
export const SDK_BINDING = sdkObject();
|
|
10
24
|
const usage = object(Object.fromEntries(["input_tokens", "output_tokens", "cache_read_tokens", "cache_write_tokens", "cost_usd"].map((key) => [
|
|
11
25
|
key,
|
|
12
26
|
{ type: [key === "cost_usd" ? "number" : "integer", "null"], minimum: 0 },
|
|
13
27
|
])), []);
|
|
14
28
|
export const SDK_RUN = {
|
|
15
|
-
...
|
|
16
|
-
runtime: SDK_BINDING.properties.runtime,
|
|
29
|
+
...sdkObject({
|
|
17
30
|
model: { type: ["string", "null"] },
|
|
18
31
|
session_id: { type: ["string", "null"] },
|
|
19
32
|
learning_revision: { type: ["string", "null"] },
|
|
@@ -67,8 +80,7 @@ export const SDK_PATHS = {
|
|
|
67
80
|
summary: "Register a task executed by an existing backend SDK",
|
|
68
81
|
description: "Requires an SDK agent definition. Captures the actual original policy and input, pins promoted workflows and any compiled shadow-check candidate separately, and returns a credential scoped to this run. The backend retains all model/tool/auth settings. Learning requires a configured server reflection/grading model; learning Off needs no server model key.",
|
|
69
82
|
parameters: [id("agent_id"), { ...key, required: true }],
|
|
70
|
-
requestBody: body(
|
|
71
|
-
runtime: SDK_BINDING.properties.runtime,
|
|
83
|
+
requestBody: body(sdkObject({
|
|
72
84
|
input: { ...text, maxLength: 128000 },
|
|
73
85
|
instructions: { ...text, maxLength: 128000 },
|
|
74
86
|
model: { ...text, maxLength: 256 },
|
|
@@ -81,7 +93,7 @@ export const SDK_PATHS = {
|
|
|
81
93
|
price_usd: { type: "number", minimum: 0 },
|
|
82
94
|
}, ["name", "description", "input_schema", "permission"]) },
|
|
83
95
|
workflow_adapters: { type: "array", maxItems: 2, uniqueItems: true, items: { enum: ["runNode", "runJudge"] }, description: "Optional backend callbacks available for workflow model and decision nodes. Default empty; requires workflow_tools." },
|
|
84
|
-
}, ["
|
|
96
|
+
}, ["input", "instructions"])),
|
|
85
97
|
responses: {
|
|
86
98
|
201: response(object({
|
|
87
99
|
run_id: text,
|
package/dist/server.d.ts
CHANGED
|
@@ -92,6 +92,9 @@ export type ServeOptions = {
|
|
|
92
92
|
* test's fakes, for the server's own Archil calls (a launch's disk read, the settings' test, an agent's disk removed,
|
|
93
93
|
* a deleted agent's run folder removed from a disk its launch named). */
|
|
94
94
|
archilControl?: ArchilRoutesOptions["control"];
|
|
95
|
+
/** How long an uploaded file no run names is kept on the uploads disk in Mode 2 (uploads-archil.ts): a duration such
|
|
96
|
+
* as 7d, or "off". Default AGENTRUN_UPLOAD_RETENTION, else 7d. */
|
|
97
|
+
uploadRetention?: string;
|
|
95
98
|
/** Another Composio than the real one, and its fetch: a test's fake, for the Composio preset's calls (composio-preset.ts). */
|
|
96
99
|
composioControl?: ComposioControl;
|
|
97
100
|
/** With `faux` only: a module whose default export gives the `browser` tool's `{ provider, driver }` (the tests' fake
|
|
@@ -211,6 +214,10 @@ export type ServeOptions = {
|
|
|
211
214
|
/** A test's seam: awaited at each step's point of DELETE /agents/{id} and DELETE /runs/{id} (agent-delete.ts
|
|
212
215
|
* AgentDeleteStep), with the agent's id or the run's, so a throw there stops the delete as a crash would. */
|
|
213
216
|
agentDeleteAt?: (step: AgentDeleteStep, id: string) => void | Promise<void>;
|
|
217
|
+
/** A test's seam: told each time a request waits in an agent's delete turn behind another (agent-delete.ts oneAtATime),
|
|
218
|
+
* with the agent's id and how many of its requests wait there now, so a test knows a write sent while a DELETE is
|
|
219
|
+
* held is queued behind it before it lets the DELETE go. */
|
|
220
|
+
deleteTurnQueued?: (agentId: string, waiting: number) => void;
|
|
214
221
|
/** A test's seam: awaited with a request's path and answer once its work under an Idempotency-Key is done, before the
|
|
215
222
|
* answer is kept, so a test can hold a request there while a DELETE /agents/{id} runs. */
|
|
216
223
|
beforeKeep?: (path: string, answer: unknown) => void | Promise<void>;
|