@parcha/agentrun-serve 0.1.0-beta.34 → 0.1.0-beta.35
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 +135 -0
- package/README.md +84 -16
- package/dist/adapters.d.ts +3 -0
- package/dist/adapters.js +7 -0
- package/dist/agent-rows.d.ts +1 -0
- package/dist/agents-store.js +17 -2
- package/dist/archil-settings.d.ts +11 -1
- package/dist/archil-settings.js +10 -0
- package/dist/bash-read-only.d.ts +13 -0
- package/dist/bash-read-only.js +77 -0
- package/dist/browser-cost.d.ts +2 -2
- package/dist/browser-cost.js +6 -4
- package/dist/budget.d.ts +0 -5
- package/dist/budget.js +0 -5
- package/dist/cap.d.ts +6 -3
- package/dist/cap.js +7 -4
- package/dist/cli.js +32 -5
- package/dist/computer-keys.d.ts +20 -10
- package/dist/computer-keys.js +36 -57
- package/dist/computer-setting.d.ts +6 -5
- package/dist/computer-setting.js +54 -26
- package/dist/computers.d.ts +9 -4
- package/dist/computers.js +4 -2
- package/dist/console/assets/index-B7NKTU8E.css +1 -0
- package/dist/console/assets/index-CXZMgJE7.js +550 -0
- package/dist/console/index.html +2 -2
- package/dist/content-filter.d.ts +7 -0
- package/dist/content-filter.js +23 -0
- package/dist/decision-cap.d.ts +7 -29
- package/dist/decision-cap.js +3 -94
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +3 -0
- package/dist/explain.js +3 -1
- package/dist/github-connection.js +25 -7
- package/dist/github-faux.d.ts +26 -0
- package/dist/github-faux.js +76 -0
- package/dist/github.d.ts +6 -2
- package/dist/github.js +5 -3
- package/dist/graph-served.d.ts +5 -3
- package/dist/graph-served.js +14 -6
- package/dist/graph-view.js +5 -2
- package/dist/harness-opencode/harness.js +0 -1
- package/dist/harness-opencode/host/policy.js +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/learn/check.d.ts +3 -1
- package/dist/learn/check.js +3 -3
- package/dist/learn/folder.d.ts +6 -3
- package/dist/learn/folder.js +7 -16
- package/dist/learn/grade.d.ts +4 -1
- package/dist/learn/grade.js +43 -5
- package/dist/learn/index.d.ts +2 -2
- package/dist/learn/index.js +2 -2
- package/dist/learn/learning.sh +1 -14
- package/dist/learn/notes.d.ts +14 -3
- package/dist/learn/notes.js +16 -6
- package/dist/learn/reflect.js +5 -3
- package/dist/learn/skills.d.ts +48 -5
- package/dist/learn/skills.js +97 -21
- package/dist/learned-nodes.d.ts +14 -0
- package/dist/learned-nodes.js +8 -0
- package/dist/learned-workflow.d.ts +9 -5
- package/dist/learned-workflow.js +53 -9
- package/dist/learning-routes.d.ts +41 -0
- package/dist/learning-routes.js +94 -26
- package/dist/learning-run.d.ts +7 -5
- package/dist/learning-run.js +9 -6
- package/dist/learning.d.ts +0 -22
- package/dist/learning.js +0 -16
- package/dist/llm.d.ts +4 -1
- package/dist/llm.js +4 -2
- package/dist/mcp-gateway.d.ts +6 -0
- package/dist/mcp-gateway.js +11 -1
- package/dist/mcp-servers-store.d.ts +12 -12
- package/dist/model.d.ts +3 -0
- package/dist/model.js +8 -0
- package/dist/openapi.js +37 -13
- package/dist/paid-calls.js +1 -1
- package/dist/pause.d.ts +2 -19
- package/dist/pause.js +5 -74
- package/dist/port-models.d.ts +10 -3
- package/dist/port-models.js +26 -6
- package/dist/propose.d.ts +2 -0
- package/dist/propose.js +1 -10
- package/dist/run-launch.d.ts +5 -3
- package/dist/run-launch.js +6 -5
- package/dist/run-learning-served.d.ts +11 -0
- package/dist/run-reads-over-store.d.ts +4 -2
- package/dist/run-reads-over-store.js +10 -8
- package/dist/run-timeline-served.js +12 -2
- package/dist/run-view.d.ts +30 -14
- package/dist/run-view.js +60 -32
- package/dist/runnable.d.ts +4 -1
- package/dist/runnable.js +14 -2
- package/dist/runner/adapter-loop.d.ts +30 -4
- package/dist/runner/adapter-loop.js +253 -29
- package/dist/runner/adapter-run-spec.d.ts +21 -0
- package/dist/runner/adapter-run-spec.js +104 -28
- package/dist/runner/adapters/pi.d.ts +29 -1
- package/dist/runner/adapters/pi.js +95 -23
- package/dist/runner/beside.d.ts +8 -0
- package/dist/runner/beside.js +18 -0
- package/dist/runner/claim-secrets.d.ts +6 -0
- package/dist/runner/claim-secrets.js +15 -1
- package/dist/runner/cli-run-spec.d.ts +3 -0
- package/dist/runner/cli-run-spec.js +123 -34
- package/dist/runner/conformance/harness.d.ts +1 -0
- package/dist/runner/conformance/harness.js +5 -5
- package/dist/runner/github-app.d.ts +7 -2
- package/dist/runner/github-app.js +46 -15
- package/dist/runner/harness-loops.d.ts +6 -1
- package/dist/runner/harness-loops.js +23 -0
- package/dist/runner/journal-kinds.d.ts +38 -2
- package/dist/runner/journal-kinds.js +23 -0
- package/dist/runner/learning-end.js +88 -16
- package/dist/runner/learning-loop.d.ts +2 -0
- package/dist/runner/learning-loop.js +13 -5
- package/dist/runner/learning-seed.d.ts +6 -0
- package/dist/runner/learning-seed.js +6 -0
- package/dist/runner/loop-contract.d.ts +4 -0
- package/dist/runner/main.d.ts +9 -4
- package/dist/runner/main.js +26 -11
- package/dist/runner/mcp-claim.d.ts +3 -0
- package/dist/runner/mcp-claim.js +6 -1
- package/dist/runner/mcp-github.d.ts +11 -2
- package/dist/runner/mcp-github.js +55 -4
- package/dist/runner/mcp-run.js +1 -0
- package/dist/runner/metrics.d.ts +14 -1
- package/dist/runner/metrics.js +72 -1
- package/dist/runner/model-route.d.ts +3 -0
- package/dist/runner/model-route.js +1 -1
- package/dist/runner/runner.js +90 -8
- package/dist/runner/spec-holds.d.ts +7 -2
- package/dist/runner/spec-holds.js +4 -3
- package/dist/runner/workflow-host.d.ts +7 -2
- package/dist/runner/workflow-host.js +3 -1
- package/dist/runner/workflow-loop.d.ts +4 -1
- package/dist/runner/workflow-loop.js +8 -2
- package/dist/runner/workflow-spec.d.ts +3 -0
- package/dist/runner/workflow-spec.js +156 -78
- package/dist/runs-over-store.d.ts +7 -1
- package/dist/runs-over-store.js +42 -11
- package/dist/seal-key.d.ts +0 -2
- package/dist/seal-key.js +0 -2
- package/dist/server-lock.js +4 -5
- package/dist/server.d.ts +21 -18
- package/dist/server.js +183 -34
- package/dist/stop-signals.d.ts +4 -2
- package/dist/stop-signals.js +5 -3
- package/dist/store/agent-body.d.ts +5 -1
- package/dist/store/agent-body.js +11 -5
- package/dist/store/deadline.d.ts +18 -0
- package/dist/store/deadline.js +45 -0
- package/dist/store/postgres/connection.d.ts +4 -0
- package/dist/store/postgres/connection.js +55 -9
- package/dist/store/sqlite/connection.js +3 -38
- package/dist/store-reads/journal.js +39 -4
- package/dist/store-reads/learning.d.ts +58 -2
- package/dist/store-reads/learning.js +172 -7
- package/dist/store-view.d.ts +15 -1
- package/dist/store-view.js +45 -12
- package/dist/templates.d.ts +9 -4
- package/dist/templates.js +14 -9
- package/dist/timeline/timeline.d.ts +8 -0
- package/dist/tool-budget.d.ts +18 -0
- package/dist/tool-budget.js +50 -0
- package/dist/tool-gate.d.ts +6 -2
- package/dist/tool-gate.js +8 -5
- package/dist/tool-plane.d.ts +9 -10
- package/dist/tools.d.ts +37 -7
- package/dist/tools.js +73 -12
- package/dist/uploads.d.ts +28 -5
- package/dist/uploads.js +82 -9
- package/dist/usage.d.ts +1 -47
- package/dist/usage.js +3 -82
- package/dist/validate.d.ts +2 -0
- package/dist/validate.js +11 -1
- package/dist/workspace/archil-claim.d.ts +2 -2
- package/dist/workspace/archil-claim.js +4 -3
- package/dist/workspace/archil-disk.d.ts +10 -1
- package/dist/workspace/archil-disk.js +4 -0
- package/dist/workspace/archil-exec.d.ts +12 -2
- package/dist/workspace/archil-exec.js +16 -0
- package/dist/workspace/archil.d.ts +2 -2
- package/dist/workspace/archil.js +25 -5
- package/dist/workspace/attach.js +2 -0
- package/dist/workspace/computer-deps.d.ts +9 -10
- package/dist/workspace/computer-deps.js +53 -40
- package/dist/workspace/computer-for-claim.d.ts +5 -3
- package/dist/workspace/computer-for-claim.js +28 -16
- package/dist/workspace/computer-ledger.d.ts +1 -8
- package/dist/workspace/computer-ledger.js +0 -3
- package/dist/workspace/computer-providers.d.ts +5 -3
- package/dist/workspace/computer-providers.js +11 -9
- package/dist/workspace/hands.d.ts +5 -2
- package/dist/workspace/hands.js +4 -3
- package/dist/workspace/index.d.ts +3 -3
- package/dist/workspace/index.js +1 -1
- package/dist/workspace/local.d.ts +3 -0
- package/dist/workspace/local.js +9 -0
- package/dist/workspace/paths.js +3 -2
- package/dist/workspace/pi-env.d.ts +4 -0
- package/dist/workspace/pi-env.js +3 -2
- package/dist/workspace/resolve-computer.d.ts +8 -3
- package/dist/workspace/resolve-computer.js +28 -11
- package/dist/workspace/run-tools.d.ts +2 -0
- package/dist/workspace/run-tools.js +9 -3
- package/dist/workspace/workspace.d.ts +5 -0
- package/dist/workspace.d.ts +0 -3
- package/dist/workspace.js +1 -14
- package/package.json +14 -14
- package/skills/agentrun-serve/SKILL.md +1 -1
- package/templates/README.md +2 -2
- package/templates/code-review/evals/mentions-defused/case.yaml +15 -0
- package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +254 -0
- package/templates/code-review/evals/mentions-defused/graders/no-pings.md +16 -0
- package/templates/code-review/evals/mentions-defused/graders/posted-a-review.md +5 -0
- package/templates/code-review/evals/mentions-defused/graders/schema.md +5 -0
- package/templates/code-review/evals/mentions-defused/prompt.md +10 -0
- package/templates/kyb/evals/clean-public-company/graders/no-opensanctions.md +5 -0
- package/templates/kyb/evals/opensanctions-on/case.yaml +5 -0
- package/templates/kyb/evals/opensanctions-on/graders/licence-and-evidence.md +18 -0
- package/templates/kyb/evals/opensanctions-on/graders/schema.md +5 -0
- package/templates/kyb/evals/opensanctions-on/prompt.md +11 -0
- package/templates/release-notes/agent.md +11 -0
- package/dist/console/assets/index-RPHGlXmM.js +0 -540
- package/dist/console/assets/index-opTN5Naq.css +0 -1
|
@@ -15,11 +15,11 @@ import { defineExtension, ROOT_CONVERSATION_ID, wrapTool } from "@earendil-works
|
|
|
15
15
|
import { chargedCost, DecisionProviderError, EffectFailure, inspectWorkflow } from "@parcha/agentrun-dsl";
|
|
16
16
|
import { modelPortFor } from "@parcha/agentrun-kernel";
|
|
17
17
|
import { startModelProxy } from "@parcha/agentrun-kernel/host";
|
|
18
|
-
import { CapRefused, checkRaise, DECISION_SESSION, followUpOf, parkOf, runCap } from "@parcha/agentrun-kernel/kernel/cap";
|
|
18
|
+
import { CapRefused, checkRaise, DecisionPriceUnreadable, DECISION_SESSION, followUpOf, parkOf, runCap } from "@parcha/agentrun-kernel/kernel/cap";
|
|
19
19
|
import { completer } from "../llm.js";
|
|
20
|
-
// The
|
|
21
|
-
//
|
|
22
|
-
import { askedBefore, JEV_INPUT_USD, PARALLEL_DECISION_USD } from "../decision-cap.js";
|
|
20
|
+
// The decision providers' list prices, the catalog's read and the replay check (decision-cap.ts), with holdOf, which the
|
|
21
|
+
// parity tests hold this cap's figures to.
|
|
22
|
+
import { askedBefore, catalogPrice, JEV_INPUT_USD, PARALLEL_DECISION_USD } from "../decision-cap.js";
|
|
23
23
|
import { decisionProvidersIn } from "../decisions.js";
|
|
24
24
|
import { imageLoader } from "../pdf-pages.js";
|
|
25
25
|
import { llmTiers, nodeTiers, workflowNodes } from "../model.js";
|
|
@@ -39,21 +39,22 @@ import { PI_WIRES, storeSettings } from "./adapter-run-spec.js";
|
|
|
39
39
|
import { policyFor } from "./adapters/pi.js";
|
|
40
40
|
import { sessionProvider } from "../port-models.js";
|
|
41
41
|
import { journalSessions } from "./sessions.js";
|
|
42
|
-
import { KINDS, WORKFLOW_SESSION } from "./journal-kinds.js";
|
|
43
|
-
import {
|
|
42
|
+
import { KINDS, NODE_LOG_SESSION, WORKFLOW_SESSION } from "./journal-kinds.js";
|
|
43
|
+
import { cutStrings } from "../key-refusal.js";
|
|
44
|
+
import { CLOSE_MS, entriesOf } from "./loop.js";
|
|
44
45
|
import { PAUSED_WORDS } from "./workflow-loop.js";
|
|
45
46
|
import { heldRedactor, holdClaimed } from "./redact.js";
|
|
46
47
|
import { holdStored } from "./store-secrets.js";
|
|
47
48
|
import { workflowHost } from "./workflow-host.js";
|
|
49
|
+
import { bookedSpend } from "./metrics.js";
|
|
48
50
|
/** A model node's submit tool, by name: pi's SUBMIT_TOOL (packages/pi/src/host-tools.ts). Named here, not imported from
|
|
49
51
|
* @parcha/agentrun-pi, whose root loads its runner and with it pi-coding-agent, an optional peer an installed server
|
|
50
52
|
* does not have: importing it here stopped the runner from starting. workflow-submit-name.test.mjs holds the two equal. */
|
|
51
53
|
export const SUBMIT_TOOL = "submit";
|
|
52
54
|
/** The one session key the workflow's model requests book under (the run's one booking sums it, runBooking). */
|
|
53
55
|
const SESSION = WORKFLOW_SESSION;
|
|
54
|
-
/** A call node's tool failure
|
|
56
|
+
/** A call node's tool failure, as app.ts's runEffect completed it (the loop's `failing` reads it). */
|
|
55
57
|
const TOOL_FAILED = "agentrun_serve_tool_failed";
|
|
56
|
-
const CAP_HELD = "agentrun_serve_cap_held";
|
|
57
58
|
/** A tier's provider from the runner's model route (model-route.ts routeOf), the one way the runner resolves a model
|
|
58
59
|
* (the pi adapter's path): the route's provider, model and price for the proxy's booking, and the catalog's cost and
|
|
59
60
|
* output ceiling as the cap prices the hold. So a workflow model node and a pi turn book the same model the same way. */
|
|
@@ -68,6 +69,7 @@ export function routeProviderOf(env) {
|
|
|
68
69
|
export async function providerFromRoute(route) {
|
|
69
70
|
return {
|
|
70
71
|
modelId: route.model,
|
|
72
|
+
...(route.named ? { named: route.named } : {}),
|
|
71
73
|
api: route.provider.api,
|
|
72
74
|
...(route.like ? { like: route.like } : {}),
|
|
73
75
|
origin: route.provider.origin,
|
|
@@ -97,11 +99,13 @@ async function raisedCapOf(harness, context) {
|
|
|
97
99
|
}
|
|
98
100
|
return capUsd;
|
|
99
101
|
}
|
|
100
|
-
/** The run's cap rule, handed to the loop so it parks and takes raises by the kernel cap without importing it.
|
|
102
|
+
/** The run's cap rule, handed to the loop so it parks and takes raises by the kernel cap without importing it. A park
|
|
103
|
+
* names the cap the run is held to when it parks (`capUsd()`: this claim's raise, else the launch's), so a raise too small
|
|
104
|
+
* for the step that parked shows the new pause at the raised cap, and the next raise is checked against that. */
|
|
101
105
|
function capRuleOf(capUsd) {
|
|
102
106
|
return {
|
|
103
107
|
park: (refusal) => {
|
|
104
|
-
const park = parkOf({ message: refusal.message, forGood: refusal.forGood, ...(refusal.figures ? { figures: refusal.figures } : {}) }, capUsd);
|
|
108
|
+
const park = parkOf({ message: refusal.message, forGood: refusal.forGood, ...(refusal.figures ? { figures: refusal.figures } : {}) }, capUsd());
|
|
105
109
|
return park.outcome === "parked"
|
|
106
110
|
? { outcome: "parked", pending: park.pending, words: park.words }
|
|
107
111
|
: { outcome: "failed", error: park.error };
|
|
@@ -190,7 +194,7 @@ export function workflowSpecOf(deps) {
|
|
|
190
194
|
const provider = providers.get(resolved) ?? providers.get("default");
|
|
191
195
|
if (!provider)
|
|
192
196
|
throw new Error(`the workflow names tier ${String(tier)}, which this run has no model for`);
|
|
193
|
-
return { provider: providerId(providers.has(resolved) ? resolved : "default"), modelId: provider.modelId };
|
|
197
|
+
return { provider: providerId(providers.has(resolved) ? resolved : "default"), modelId: provider.modelId, ...(provider.named ? { named: provider.named } : {}) };
|
|
194
198
|
};
|
|
195
199
|
const capModelOf = (id) => {
|
|
196
200
|
for (const provider of providers.values())
|
|
@@ -212,6 +216,9 @@ export function workflowSpecOf(deps) {
|
|
|
212
216
|
let decisionCap;
|
|
213
217
|
// The run's paid tool calls on its one cap (TOOL_SESSION), wired at harnessReady: a call node's hold and its request.
|
|
214
218
|
let paidTools;
|
|
219
|
+
// The call nodes' effects as they run (KINDS.nodeEffect on NODE_LOG_SESSION), opened at harnessReady: the run's graph
|
|
220
|
+
// lists its effects from them.
|
|
221
|
+
let nodeLog;
|
|
215
222
|
// The run's own keys with its plane, as an agentic run's tool host gets them: the call nodes' effects and the model
|
|
216
223
|
// nodes' tools run on these.
|
|
217
224
|
const callEnv = callEnvOf(claimedEnv, claimed);
|
|
@@ -247,8 +254,8 @@ export function workflowSpecOf(deps) {
|
|
|
247
254
|
tools: [...new Set([...toolsOf(claimed.workflow), ...nodeNames])],
|
|
248
255
|
agentId: claimed.agentId,
|
|
249
256
|
revisionId: claimed.revisionId,
|
|
250
|
-
...(claimed.capUsd !== undefined ? { cap: capRuleOf(claimed.capUsd) } : {}),
|
|
251
|
-
endPatch: async () => endPatchOf(booking, decisionCap, paidTools),
|
|
257
|
+
...(claimed.capUsd !== undefined ? { cap: capRuleOf(() => effectiveCapUsd ?? claimed.capUsd) } : {}),
|
|
258
|
+
endPatch: async () => endPatchOf(booking, decisionCap, paidTools, run?.journal),
|
|
252
259
|
build: (loopHooks) => {
|
|
253
260
|
hooks.setPark(loopHooks);
|
|
254
261
|
const hostDeps = {
|
|
@@ -257,7 +264,7 @@ export function workflowSpecOf(deps) {
|
|
|
257
264
|
// would book beside the run's ledger), and the run's gate over them by name (main's registry.install).
|
|
258
265
|
sharedExtensions: [nodeToolGate(nodeNames, nodePolicy), ...[...nodeTools.values()].flatMap((binding) => binding.extensions)],
|
|
259
266
|
nodeTool: (name) => nodeTools.get(name),
|
|
260
|
-
runEffect: runEffectOf(claimed, complete, callEnv, callPolicyOf(deps.store, claim.runId, claimed), () => paidTools),
|
|
267
|
+
runEffect: runEffectOf(claimed, complete, callEnv, callPolicyOf(deps.store, claim.runId, claimed), () => paidTools, (line) => nodeLog?.append([{ kind: KINDS.nodeEffect, data: (run?.redact ? cutStrings(line, run.redact) : line) }]) ?? Promise.resolve()),
|
|
261
268
|
workRoot: claimed.workRoot,
|
|
262
269
|
flush: () => deps.store.flush(),
|
|
263
270
|
// A decision node books through the run's one cap (admitted and settled as main holds it); a cap refusal for room
|
|
@@ -304,6 +311,7 @@ export function workflowSpecOf(deps) {
|
|
|
304
311
|
// The run's paid tool calls on the same cap (TOOL_SESSION): a call node's hold before its admission, and the paid
|
|
305
312
|
// request it makes, as an agentic run's tool calls book (paidStep).
|
|
306
313
|
paidTools = await run.tools(await sessions.open(TOOL_SESSION), { flush: () => deps.store.flush() });
|
|
314
|
+
nodeLog = await sessions.open(NODE_LOG_SESSION);
|
|
307
315
|
hooks.setPort(booking.models);
|
|
308
316
|
},
|
|
309
317
|
settle: async () => {
|
|
@@ -442,7 +450,7 @@ export function callHoldOf(tool, input, env, modelOfTier) {
|
|
|
442
450
|
return NO_HOLD(tool);
|
|
443
451
|
const fee = tool === "web_search" ? parallelSearchFee(searchArgs(input).n) : parallelExtractFee(1);
|
|
444
452
|
// Who charges for it (main's charge row's charged_by), as paidOn names it: the hold is the record its request books under.
|
|
445
|
-
return { usd: fee.usd, name: fee.name, basis: fee.basis, chargedBy: fee.by };
|
|
453
|
+
return { usd: fee.usd, name: fee.name, tool, basis: fee.basis, chargedBy: fee.by };
|
|
446
454
|
}
|
|
447
455
|
if (tool === "llm") {
|
|
448
456
|
const model = modelOfTier(typeof input.tier === "string" ? input.tier : undefined);
|
|
@@ -513,7 +521,7 @@ export function holdAtEffects(cap, deps) {
|
|
|
513
521
|
const call = `${params.node.label}@${params.executionPath ?? ""}`;
|
|
514
522
|
const id = `${call}#hold${(seq += 1)}`;
|
|
515
523
|
try {
|
|
516
|
-
await paid.admit({ id, name: hold.name, holdUsd: hold.usd, basis: hold.basis, call, ...(hold.chargedBy ? { chargedBy: hold.chargedBy } : {}) });
|
|
524
|
+
await paid.admit({ id, name: hold.name, ...(hold.tool ? { tool: hold.tool } : {}), holdUsd: hold.usd, basis: hold.basis, call, ...(hold.chargedBy ? { chargedBy: hold.chargedBy } : {}) });
|
|
517
525
|
}
|
|
518
526
|
catch (error) {
|
|
519
527
|
if (error instanceof CapRefused && !error.forGood) {
|
|
@@ -595,13 +603,15 @@ export function failingEffects(cap) {
|
|
|
595
603
|
},
|
|
596
604
|
};
|
|
597
605
|
}
|
|
598
|
-
function runEffectOf(claimed, complete, env, policy, paidTools) {
|
|
606
|
+
function runEffectOf(claimed, complete, env, policy, paidTools, log) {
|
|
599
607
|
// An `llm` call gives its call's hold back as its own model request is judged (the cap holds that request itself).
|
|
600
608
|
const completeHeld = async (args, signal) => {
|
|
601
609
|
await releaseCallHold();
|
|
602
610
|
return complete(args, signal);
|
|
603
611
|
};
|
|
604
|
-
|
|
612
|
+
// A line the node log could not take (the claim lost meanwhile) costs the graph a line, never the call.
|
|
613
|
+
const logged = (line) => log(line).catch(() => undefined);
|
|
614
|
+
return (async ({ node, input, signal, executionPath, item }) => {
|
|
605
615
|
// The call's ledger: its paid request books on the run's one ledger, on the hold taken before the call (holdAtEffects)
|
|
606
616
|
// when it has one. No pause: a refusal inside an admitted effect fails the call, never parks the run there.
|
|
607
617
|
const held = heldBooking();
|
|
@@ -610,6 +620,9 @@ function runEffectOf(claimed, complete, env, policy, paidTools) {
|
|
|
610
620
|
const effect = node.via === "tool" && node.tool ? toolOf(node.tool)?.effect : undefined;
|
|
611
621
|
if (!effect)
|
|
612
622
|
throw new Error(`call node "${node.label}": agentrun-serve runs no tool ${node.tool ?? `via ${node.via}`}`);
|
|
623
|
+
// Its start and its end on the run's node log (main's app.ts), which the run's graph lists as its effects.
|
|
624
|
+
const at = { path: executionPath ?? null, item: item?.index ?? null, tool: node.tool, label: node.label };
|
|
625
|
+
await logged({ t: "effect.start", ...at, input, at: new Date().toISOString() });
|
|
613
626
|
// Its tool's permission now (main's app.ts:382-384): a deny set since the run started is refused in the gate's words,
|
|
614
627
|
// and an ask too, since a call node cannot wait for an approval. Neither runs.
|
|
615
628
|
try {
|
|
@@ -618,10 +631,15 @@ function runEffectOf(claimed, complete, env, policy, paidTools) {
|
|
|
618
631
|
throw new Error(deniedText(node.tool, undefined, denyFrom));
|
|
619
632
|
if (permission === "ask")
|
|
620
633
|
throw new Error(callNodeAskText(node.tool));
|
|
621
|
-
|
|
634
|
+
const output = await effect(input, { signal, env, work: claimed.workRoot, complete: completeHeld, ...(ledger ? { ledger } : {}) });
|
|
635
|
+
await logged({ t: "effect.end", ...at, status: "done", output, at: new Date().toISOString() });
|
|
636
|
+
return output;
|
|
622
637
|
}
|
|
623
638
|
catch (error) {
|
|
624
639
|
const message = String(error?.message ?? error);
|
|
640
|
+
// Whole up to 64 KB, so the server redacts it before it cuts it for the graph (graph-served.ts); a longer one is
|
|
641
|
+
// marked cut.
|
|
642
|
+
await logged({ t: "effect.end", ...at, status: "failed", error: message.slice(0, 65_536), ...(message.length > 65_536 ? { error_truncated: true } : {}), at: new Date().toISOString() });
|
|
625
643
|
if (signal.aborted || error?.name === "AbortError")
|
|
626
644
|
throw error;
|
|
627
645
|
return { [TOOL_FAILED]: `call node "${node.label}": ${node.tool} failed: ${message.slice(0, 500)}` };
|
|
@@ -631,71 +649,130 @@ function runEffectOf(claimed, complete, env, policy, paidTools) {
|
|
|
631
649
|
/** The end's cost and metrics: what every model request of the run cost (the booking) plus what its decisions and its
|
|
632
650
|
* call nodes' paid requests cost (the decision cap, the paid tools), one spend for the run. Unknown (no figure) once any
|
|
633
651
|
* part is unknown. */
|
|
634
|
-
|
|
652
|
+
/** What the run's decisions cost by their booking (bookedSpend, "decisions"), read from only what that needs: the root's
|
|
653
|
+
* session keys (journalSessions writes them there) and the decisions session's own conversation, never the run's model
|
|
654
|
+
* or tool records, so the read stays small within the end patch's bound. No decisions session: none, $0. */
|
|
655
|
+
async function decisionsBooked(journal) {
|
|
656
|
+
const root = await entriesOf(journal, ROOT_CONVERSATION_ID, BACKGROUND_CONTEXT);
|
|
657
|
+
const key = root.find((entry) => entry.kind === KINDS.sessionKey && entry.data?.key === DECISION_SESSION);
|
|
658
|
+
const conversation = key?.data?.conversation;
|
|
659
|
+
if (conversation == null)
|
|
660
|
+
return 0;
|
|
661
|
+
const decisions = await entriesOf(journal, conversation, BACKGROUND_CONTEXT);
|
|
662
|
+
return bookedSpend([key, ...decisions], "decisions").usd;
|
|
663
|
+
}
|
|
664
|
+
async function endPatchOf(booking, decisionCap, paidTools, journalOf) {
|
|
635
665
|
if (!booking)
|
|
636
666
|
return {};
|
|
637
667
|
const model = booking.spentUsd();
|
|
638
|
-
|
|
668
|
+
// A decision's cost is what its booking says it charged (bookedSpend over the decisions session's records, as the pi and
|
|
669
|
+
// CLI specs read it): one its provider reported no cost for is unknown, never the hold the cap counts it at
|
|
670
|
+
// (decisionCap.spentUsd, which stays the cap's own figure). With no journal to read, any decision is unknown.
|
|
671
|
+
const decision = !decisionCap ? 0 : journalOf ? await decisionsBooked(journalOf()) : null;
|
|
639
672
|
const paid = paidTools ? paidTools.spentUsd() : 0;
|
|
640
673
|
return model === null || decision === null || paid === null ? {} : { costUsd: model + decision + paid };
|
|
641
674
|
}
|
|
642
675
|
/** The run's one cap as a WorkflowCap: model nodes and call nodes pass through (their money is on the proxy), and a
|
|
643
|
-
* decision node is
|
|
644
|
-
* holds it. The reference is deferred because the cap is not
|
|
676
|
+
* decision node is priced before the DSL driver admits its request (`judge`) and held, sent and settled through the run's
|
|
677
|
+
* decisions once it is admitted (`admitted`), priced as main holds it. The reference is deferred because the cap is not
|
|
678
|
+
* built until the Harness opens. */
|
|
645
679
|
function decisionWorkflowCap(getCap, providers, hooks) {
|
|
646
|
-
|
|
680
|
+
const judging = decisionJudging({ getCap, providers, park: hooks.park, hooks });
|
|
681
|
+
return { node: (fn) => fn, effect: (fn) => fn, judge: judging.before, admitted: judging.admitted };
|
|
647
682
|
}
|
|
648
|
-
/** A decision
|
|
649
|
-
*
|
|
650
|
-
*
|
|
651
|
-
*
|
|
652
|
-
*
|
|
653
|
-
*
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
deps.
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
683
|
+
/** A decision under the run's cap, in two halves around the DSL driver's admission of its request (dsl withRecovery: the
|
|
684
|
+
* request is committed, `decision.request`, before the judge is asked; one asked and never answered is never asked again):
|
|
685
|
+
* - `before`, outside the admission: a request the driver answers from what it decided before (a route's, or one an
|
|
686
|
+
* earlier process admitted that did not fail) holds nothing (askedBefore); a person's pause parks the run; the
|
|
687
|
+
* request is priced as main prices it (holdOf), its catalog read again on a moment's outage.
|
|
688
|
+
* - `admitted`, the judge the driver asks once it has admitted the request: the hold is taken through the kernel cap (its
|
|
689
|
+
* record made durable before the send), the provider is asked, and the hold is settled at what the answer charged (its
|
|
690
|
+
* hold when it reports none). So a hold is never kept for a request the driver did not admit: a process that dies
|
|
691
|
+
* before the admission leaves nothing for the next claim to count beside asking it again. A refusal for room or for no
|
|
692
|
+
* price ends the admitted request failed, unsent, in the driver's commit (asked again by the next claim), and then parks
|
|
693
|
+
* the run, or fails it, through the loop's hook, as a model node's refusal does. A price the catalog still could not
|
|
694
|
+
* read fails the decision node as an unsent connection error, never the cap's stop. */
|
|
695
|
+
function decisionJudging(deps) {
|
|
696
|
+
/** Each request `before` priced, by the params object the driver hands on to `admitted`; and the cap's refusal of one. */
|
|
697
|
+
const priced = new WeakMap();
|
|
698
|
+
const refused = new WeakMap();
|
|
699
|
+
return {
|
|
700
|
+
before(inner, driver) {
|
|
701
|
+
const judge = inner;
|
|
702
|
+
return (async (params) => {
|
|
703
|
+
if (driver && askedBefore(driver, params))
|
|
704
|
+
return judge(params);
|
|
705
|
+
// A person's pause in force parks the run before a new decision is held or sent, as a refusal for room does.
|
|
706
|
+
if (deps.hooks?.paused()) {
|
|
707
|
+
deps.hooks.pause();
|
|
708
|
+
throw new Error(PAUSED_WORDS);
|
|
709
|
+
}
|
|
710
|
+
const id = params.provider ?? deps.providers.default;
|
|
711
|
+
const provider = Object.hasOwn(deps.providers.providers, id) ? deps.providers.providers[id] : undefined;
|
|
712
|
+
// A provider the host lacks is refused by the judge itself (configuration), before anything is held.
|
|
713
|
+
if (!provider)
|
|
714
|
+
return judge(params);
|
|
715
|
+
// The cap is wired at harnessReady, before any node runs; a decision reaching here without it is a bug.
|
|
716
|
+
if (!deps.getCap())
|
|
717
|
+
throw new Error(`decision "${params.label}": the run's decision cap was not wired before the workflow ran`);
|
|
718
|
+
priced.set(params, await decisionRequestOf(provider, params));
|
|
719
|
+
try {
|
|
720
|
+
return await judge(params);
|
|
721
|
+
}
|
|
722
|
+
catch (error) {
|
|
723
|
+
const refusal = refused.get(params);
|
|
724
|
+
if (!refusal)
|
|
725
|
+
throw error;
|
|
726
|
+
// The cap refused the admitted request: the driver ended it failed, unsent; that commit lands before the run
|
|
727
|
+
// parks, so the next claim asks it again rather than finding it asked and never answered. A commit the store
|
|
728
|
+
// refused is thrown, never a park: parked with the request still asked, the next claim would refuse to ask it.
|
|
729
|
+
await driver?.flush();
|
|
730
|
+
deps.park({ message: refusal.message, forGood: refusal.forGood, ...(refusal.figures ? { figures: refusal.figures } : {}) });
|
|
731
|
+
throw refusal;
|
|
732
|
+
}
|
|
733
|
+
finally {
|
|
734
|
+
priced.delete(params);
|
|
735
|
+
refused.delete(params);
|
|
736
|
+
}
|
|
737
|
+
});
|
|
738
|
+
},
|
|
739
|
+
admitted(inner) {
|
|
740
|
+
const judge = inner;
|
|
741
|
+
return (async (params) => {
|
|
742
|
+
const request = priced.get(params);
|
|
743
|
+
const cap = deps.getCap();
|
|
744
|
+
if (!request || !cap)
|
|
745
|
+
return judge(params);
|
|
746
|
+
try {
|
|
747
|
+
await cap.admit(request);
|
|
748
|
+
}
|
|
749
|
+
catch (error) {
|
|
750
|
+
// A refusal the cap read: told to `before` (which parks or fails the run once the driver has ended the request),
|
|
751
|
+
// and thrown here as a request that never left, so the driver ends it failed with nothing spent.
|
|
752
|
+
if (error instanceof CapRefused) {
|
|
753
|
+
refused.set(params, error);
|
|
754
|
+
throw new DecisionProviderError("connection", `${params.label}'s decision was not sent: ${error.message}`, { unsent: true, cause: error });
|
|
755
|
+
}
|
|
756
|
+
// A price the catalog could not read: the decision node fails unsent, as a connection error, never the cap.
|
|
757
|
+
if (error instanceof DecisionPriceUnreadable)
|
|
758
|
+
throw new DecisionProviderError("connection", `${params.label}'s decision was not sent: ${error.message}`, { unsent: true, cause: error });
|
|
759
|
+
throw error;
|
|
760
|
+
}
|
|
761
|
+
try {
|
|
762
|
+
const result = await judge(params);
|
|
763
|
+
await cap.settle(request.id, { end: "charged", usd: finiteUsd(result?.cost_usd) });
|
|
764
|
+
return result;
|
|
765
|
+
}
|
|
766
|
+
catch (error) {
|
|
767
|
+
// Sent and maybe billed (its outcome lost, its answer rejected): at what it was charged, else at its hold (null).
|
|
768
|
+
// One its provider refused unbilled, or that never left, charged nothing: booked at $0 so no later process counts it.
|
|
769
|
+
const charged = chargedCost(error);
|
|
770
|
+
await cap.settle(request.id, { end: "charged", usd: charged !== undefined ? charged : unbilled(error) ? 0 : null });
|
|
771
|
+
throw error;
|
|
772
|
+
}
|
|
773
|
+
});
|
|
774
|
+
},
|
|
775
|
+
};
|
|
699
776
|
}
|
|
700
777
|
/** A decision's request for the kernel cap, priced as main holds it (serve decision-cap.ts holdOf): Parallel's list price
|
|
701
778
|
* for one request; Jev's published per-input-token price; an OpenRouter Decisions model at its catalog price (per request,
|
|
@@ -720,11 +797,12 @@ async function decisionRequestOf(provider, params) {
|
|
|
720
797
|
return { ...base, model: openrouterModel(model ?? provider.id, null, null) };
|
|
721
798
|
let price;
|
|
722
799
|
try {
|
|
723
|
-
|
|
800
|
+
// Read again on a moment's outage (catalogPrice, CATALOG_TRIES reads), as main reads it.
|
|
801
|
+
price = await catalogPrice(priced, model, params.signal);
|
|
724
802
|
}
|
|
725
803
|
catch {
|
|
726
|
-
// The catalog could not be read: the decision fails unsent as a connection error, never the cap's stop (asModel
|
|
727
|
-
// DecisionPriceUnreadable for "unreadable").
|
|
804
|
+
// The catalog still could not be read: the decision fails unsent as a connection error, never the cap's stop (asModel
|
|
805
|
+
// throws DecisionPriceUnreadable for "unreadable").
|
|
728
806
|
return { ...base, model: "unreadable" };
|
|
729
807
|
}
|
|
730
808
|
if (!price)
|
|
@@ -5,7 +5,7 @@ import { ApiError, type InputIssue } from "./errors.js";
|
|
|
5
5
|
import { type LearningMode, type Seed, type Shown } from "./learning.js";
|
|
6
6
|
import { type Place } from "./place.js";
|
|
7
7
|
import { type RunLaunch } from "./run-launch.js";
|
|
8
|
-
import type
|
|
8
|
+
import { type ApprovalDecision, type RunMoment } from "./run-view.js";
|
|
9
9
|
import { type NewRevision, type RunOrigin, type RunRow, type Store } from "./store/index.js";
|
|
10
10
|
import { type ToolSettingsMap } from "./tool-plane.js";
|
|
11
11
|
import type { RunTrigger } from "./triggers.js";
|
|
@@ -111,6 +111,12 @@ export interface StartDeps {
|
|
|
111
111
|
/** The uploaded files named by file_ids, ready to copy; throws when one is not ready (server.ts uploads.readyFiles). The
|
|
112
112
|
* copy into the run's work/ is the runner's at its claim; this only checks they are ready before the run starts. */
|
|
113
113
|
readyFiles(ids: readonly unknown[]): Promise<unknown>;
|
|
114
|
+
/** Holds the run's files for it (uploads.ts Uploads.hold) before its row is written, so a file deleted after the start
|
|
115
|
+
* is still the run's at its claim; `release` lets go of a hold whose run was never written (or was another's). */
|
|
116
|
+
readonly files?: {
|
|
117
|
+
hold(runId: string, ids: readonly string[]): Promise<void>;
|
|
118
|
+
release(runId: string): Promise<void>;
|
|
119
|
+
};
|
|
114
120
|
/** Where a revision naming these tools and no place runs here (server.ts fallbackPlace). */
|
|
115
121
|
fallbackPlace(kind: "agentic" | "workflow", tools: readonly unknown[]): Place;
|
|
116
122
|
/** A run's title from its input (server.ts workflowTitle), for a workflow run's title. */
|
package/dist/runs-over-store.js
CHANGED
|
@@ -15,10 +15,11 @@ import { CAP_TOLERANCE, money } from "./cap.js";
|
|
|
15
15
|
import { ApiError, invalid, unsupported } from "./errors.js";
|
|
16
16
|
import { harnessOfBody } from "./harness.js";
|
|
17
17
|
import { redacted, redactedOutput } from "./key-refusal.js";
|
|
18
|
-
import { LEARNING_BUDGET, learnedParts } from "./learning.js";
|
|
18
|
+
import { chooseWorkflows, LEARNING_BUDGET, learnedParts } from "./learning.js";
|
|
19
19
|
import { thinkingLevel } from "./model.js";
|
|
20
20
|
import { resolvePlace } from "./place.js";
|
|
21
21
|
import { launchBody } from "./run-launch.js";
|
|
22
|
+
import { raiseFollowUpId } from "./run-view.js";
|
|
22
23
|
import { sendCommand } from "./runner/commands.js";
|
|
23
24
|
import { ExternalBodyConflict, RunFinal, StoreConstraint } from "./store/index.js";
|
|
24
25
|
import { toolingOf } from "./tools.js";
|
|
@@ -156,9 +157,12 @@ export async function message(store, moment, content, { requestId, answers = tru
|
|
|
156
157
|
await sendCommand(store, moment.id, { kind: "steer", body });
|
|
157
158
|
return { mode, messageId };
|
|
158
159
|
}
|
|
159
|
-
/** The raise command rows this run already has, newest last
|
|
160
|
+
/** The raise command rows this run already has, newest last: the cap each names, and whether its runner has taken it. */
|
|
160
161
|
async function raiseRows(store, runId) {
|
|
161
|
-
return (await store.commands(runId, 0))
|
|
162
|
+
return (await store.commands(runId, 0))
|
|
163
|
+
.filter((c) => c.kind === "raise")
|
|
164
|
+
.map((c) => ({ capUsd: Number(c.body?.capUsd), taken: c.takenAt !== null }))
|
|
165
|
+
.filter((row) => Number.isFinite(row.capUsd));
|
|
162
166
|
}
|
|
163
167
|
/** Raises the cap of an agentic or workflow run that names one, to `cap`: above its own (by more than CAP_TOLERANCE), or the
|
|
164
168
|
* same as its newest raise (a retry, which changes nothing). A raise command row the run's runner reads: it resumes a run
|
|
@@ -174,9 +178,15 @@ export async function raiseCap(store, moment, cap) {
|
|
|
174
178
|
throw invalid([{ field: "max_cost_usd", reason: "not_allowed", message: "This run has no cap to raise: a cap is named when a run starts." }]);
|
|
175
179
|
const raises = await raiseRows(store, moment.id);
|
|
176
180
|
const last = raises.at(-1);
|
|
177
|
-
//
|
|
178
|
-
|
|
179
|
-
|
|
181
|
+
// An agentic run paused at its cap goes on with one follow-up turn the runner sends under its pause's id
|
|
182
|
+
// (raiseFollowUpId): the answer names it, so every raise of this pause (a retry, two sent at once) names the same message.
|
|
183
|
+
// A workflow run sends none (the step that waits is judged again), so its answer names no message.
|
|
184
|
+
const resumed = () => ({ resumed: true, ...(moment.kind === "agentic" && moment.pause !== undefined ? { messageId: raiseFollowUpId(moment.pause) } : {}) });
|
|
185
|
+
// The same raise again (a retry): what the first one did stands, no second row. It resumes the run only while that raise
|
|
186
|
+
// is still on its way (its row untaken): once taken, a pause the run stands at now is a new one, under the raised cap,
|
|
187
|
+
// which this retry does not raise (it answers resumed false, and the run stays paused).
|
|
188
|
+
if (Math.abs(cap - from) <= CAP_TOLERANCE && last !== undefined && Math.abs(last.capUsd - cap) <= CAP_TOLERANCE) {
|
|
189
|
+
return moment.paused && !last.taken ? resumed() : { resumed: false };
|
|
180
190
|
}
|
|
181
191
|
if (!(cap > from + CAP_TOLERANCE))
|
|
182
192
|
throw invalid([{ field: "max_cost_usd", reason: "invalid", message: `A cap is only raised: name more than the run's ${money(from)}.` }]);
|
|
@@ -193,7 +203,7 @@ export async function raiseCap(store, moment, cap) {
|
|
|
193
203
|
}
|
|
194
204
|
// A run paused at its cap is brought back by the raise (its runner claims it and sends its continuation).
|
|
195
205
|
if (moment.paused)
|
|
196
|
-
return
|
|
206
|
+
return resumed();
|
|
197
207
|
// A run its runner holds takes the raise as its next command: its next step is admitted under the raised cap (the
|
|
198
208
|
// runner's loop holds the run to its newest raise), and a step already under way keeps the cap it was admitted at.
|
|
199
209
|
return { resumed: false, ...(moment.live ? { note: `The ${money(cap)} cap holds from the run's next step; a step already under way keeps the ${money(from)} cap it was admitted at.` } : {}) };
|
|
@@ -301,7 +311,10 @@ async function learningStartFor(deps, entry, revision, rbody, input) {
|
|
|
301
311
|
// by its size and never laid) and no host secret in it, as chooseSkills leaves them out. The claim lays them; the
|
|
302
312
|
// end-of-run turn counts the runs each served (runner/learning-end.ts draftForOf).
|
|
303
313
|
const skills = (seeded.seed.skills ?? []).flatMap(({ name, files }) => (files && !options.shown.holds(name) && !Object.entries(files).some(([path, text]) => options.shown.holds(path) || options.shown.holds(text)) ? [name] : []));
|
|
304
|
-
|
|
314
|
+
// The learned workflows its learned_workflow tool runs, by name, as the claim chooses them (chooseWorkflows): what the
|
|
315
|
+
// agent's impact counts a run as started from, beside its notes and skills.
|
|
316
|
+
const workflows = chooseWorkflows(seeded.seed, options.shown).flows.map(({ name }) => name);
|
|
317
|
+
return { given: given.map(({ file, name }) => ({ file, name })), seed: seeded.seed.sha, section: section ?? "", seedNotes: Object.keys(seeded.seed.notes).length, ...(skills.length ? { skills } : {}), ...(workflows.length ? { workflows } : {}), ...grade };
|
|
305
318
|
}
|
|
306
319
|
catch {
|
|
307
320
|
return { given: [], seed: null, section: "", seedFailed: "not_copied", ...grade };
|
|
@@ -316,7 +329,7 @@ export async function startRun(store, deps, entry, body, { trigger, origin, capp
|
|
|
316
329
|
const { launch, revision } = await prepareLaunch(deps, entry, body, { ...(trigger ? { trigger } : {}), capped, ...(from ? { from } : {}), ...(title !== undefined ? { title } : {}) });
|
|
317
330
|
const runId = (deps.newRunId ?? uuidv7)();
|
|
318
331
|
try {
|
|
319
|
-
return await store.runs.create({ id: runId, agentId: entry.agent.id, revisionId: revision.id, ...(origin ? { origin } : {}) }, { body: launchBody(launch) });
|
|
332
|
+
return await withHeldFiles(deps, runId, launch, () => store.runs.create({ id: runId, agentId: entry.agent.id, revisionId: revision.id, ...(origin ? { origin } : {}) }, { body: launchBody(launch) }));
|
|
320
333
|
}
|
|
321
334
|
catch (error) {
|
|
322
335
|
// Only another writer of the store got here first under the same origin key: its run is the one asked for.
|
|
@@ -329,6 +342,24 @@ export async function startRun(store, deps, entry, body, { trigger, origin, capp
|
|
|
329
342
|
throw error;
|
|
330
343
|
}
|
|
331
344
|
}
|
|
345
|
+
/** Writes run `runId` with `write`, its files (launch.files) held for it first (StartDeps.files): a hold that fails part
|
|
346
|
+
* way, a write that fails, or one that answers another run (an origin key's run started before), lets go of the hold. */
|
|
347
|
+
async function withHeldFiles(deps, runId, launch, write) {
|
|
348
|
+
const ids = launch.files ?? [];
|
|
349
|
+
if (!ids.length || !deps.files)
|
|
350
|
+
return await write();
|
|
351
|
+
try {
|
|
352
|
+
await deps.files.hold(runId, ids);
|
|
353
|
+
const row = await write();
|
|
354
|
+
if (row.id !== runId)
|
|
355
|
+
await deps.files.release(runId);
|
|
356
|
+
return row;
|
|
357
|
+
}
|
|
358
|
+
catch (error) {
|
|
359
|
+
await deps.files.release(runId).catch(() => undefined);
|
|
360
|
+
throw error;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
332
363
|
/** Starts a run of an agent given inline, as POST /agents/{id}/runs starts a run of a stored one: the same checks over the
|
|
333
364
|
* revision the definition makes (prepareLaunch), then ONE transaction (store.runs.createInline) that writes the agent on
|
|
334
365
|
* its reference's first run and the revision on its version's first run, or reads them, then the run and its launch. The
|
|
@@ -348,12 +379,12 @@ export async function startInline(store, deps, inline, body, { origin } = {}) {
|
|
|
348
379
|
const { launch } = await prepareLaunch(deps, entry, body, { revision: revision });
|
|
349
380
|
const runId = (deps.newRunId ?? uuidv7)();
|
|
350
381
|
try {
|
|
351
|
-
return await store.runs.createInline({
|
|
382
|
+
return await withHeldFiles(deps, runId, launch, () => store.runs.createInline({
|
|
352
383
|
agent: { id: entry.agent.id, name: inline.name, description: inline.description, ref },
|
|
353
384
|
revision: { id: revision.id, version: external.version, kind: revision.kind, body: revision.body, skills: revision.skills, ...(revision.note !== undefined ? { note: revision.note } : {}) },
|
|
354
385
|
run: { id: runId, ...(origin ? { origin } : {}) },
|
|
355
386
|
launch: { body: launchBody(launch) },
|
|
356
|
-
});
|
|
387
|
+
}));
|
|
357
388
|
}
|
|
358
389
|
catch (error) {
|
|
359
390
|
if (error instanceof ExternalBodyConflict) {
|
package/dist/seal-key.d.ts
CHANGED
|
@@ -26,8 +26,6 @@ export type SealKey = {
|
|
|
26
26
|
export type BootedSealKey = SealKey & {
|
|
27
27
|
readonly release: () => void;
|
|
28
28
|
};
|
|
29
|
-
/** Where the data directory `dataDir` keeps its seal key. */
|
|
30
|
-
export declare const sealKeyPath: (dataDir: string) => string;
|
|
31
29
|
/** The key file's rules alone, with no store to check against: `given` (AGENTRUN_SEAL_KEY as it was handed) when set,
|
|
32
30
|
* else the one kept in `dataDir`, made there when there is none. A start never calls this by itself: bootSealKey checks
|
|
33
31
|
* the key against the store first, and makes one only for a store that holds no secret. */
|
package/dist/seal-key.js
CHANGED
|
@@ -38,8 +38,6 @@ export class SealKeyRefused extends Error {
|
|
|
38
38
|
export class SealKeyNotTheStores extends SealKeyRefused {
|
|
39
39
|
name = "SealKeyNotTheStores";
|
|
40
40
|
}
|
|
41
|
-
/** Where the data directory `dataDir` keeps its seal key. */
|
|
42
|
-
export const sealKeyPath = (dataDir) => join(dataDir, SEAL_KEY_DIR, SEAL_KEY_FILE);
|
|
43
41
|
const HOW = `Hand the server ${SEAL_KEY_ENV} (32 random bytes in base64, e.g. \`openssl rand -base64 32\`), or let it keep one in ${SEAL_KEY_DIR}/${SEAL_KEY_FILE} in its data directory, made at the first start.`;
|
|
44
42
|
const refused = (why) => new SealKeyRefused(`No seal key: ${why}. ${HOW}`);
|
|
45
43
|
function lstatOf(path) {
|
package/dist/server-lock.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
// One server per data root, written for AgentRun. A server takes <data>/server.lock
|
|
2
|
-
//
|
|
1
|
+
// One server per data root, written for AgentRun. A server takes <data>/server.lock once it holds its store (server.ts
|
|
2
|
+
// dataRootLock), and holds it until it closes; a second server on the same root is refused by name. The store's owner
|
|
3
|
+
// lock holds one store; this one holds the data root beside it (the token, the seal key, uploads, harness installs), which
|
|
4
|
+
// two servers on two stores (two Postgres schemas, or SQLite and Postgres) would otherwise share.
|
|
3
5
|
//
|
|
4
6
|
// The lock is SQLite's EXCLUSIVE lock, as a run's store holds it: held on one connection for the server's life,
|
|
5
7
|
// dropped by the kernel when the process dies (a crashed server's file is reused by the next start, never refused for
|
|
6
8
|
// existing), and refused to a second connection whether it is in another process or in this one. The file is opened by
|
|
7
9
|
// SQLite alone: a POSIX lock is dropped when any descriptor the process holds on the file is closed, so no other code
|
|
8
10
|
// may open it (its mode is set by path).
|
|
9
|
-
//
|
|
10
|
-
// pi-durable-disk forgets a command record written in another pid namespace only under the precondition this lock
|
|
11
|
-
// keeps: two servers never hold one data root at once.
|
|
12
11
|
import { chmodSync } from "node:fs";
|
|
13
12
|
import { join } from "node:path";
|
|
14
13
|
import { DatabaseSync } from "node:sqlite";
|