@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
package/dist/runner/metrics.d.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { type DecisionLike, type EntryLike, type RunMetrics } from "../timeline/index.js";
|
|
2
2
|
/** What a run's booking says one of its sessions spent: its requests (a hold given back unused is none), their known
|
|
3
|
-
* sum, how many have no known cost, and
|
|
3
|
+
* sum, how many have no known cost, their tokens, and how many of the requests have no known tokens (`unmetered`: booked
|
|
4
|
+
* with no usage, or sent and never answered), in no token sum; and its requests by the model each was sent on (`models`:
|
|
5
|
+
* its runner.request's model, "" for one that names none). */
|
|
4
6
|
export type BookedSpend = {
|
|
5
7
|
readonly usd: number | null;
|
|
6
8
|
readonly known: number;
|
|
7
9
|
readonly unpriced: number;
|
|
8
10
|
readonly requests: number;
|
|
11
|
+
readonly unmetered: number;
|
|
12
|
+
readonly models: Readonly<Record<string, number>>;
|
|
9
13
|
readonly tokens: {
|
|
10
14
|
input: number;
|
|
11
15
|
output: number;
|
|
@@ -31,6 +35,11 @@ export declare function costIsBooked(entries: readonly EntryLike[], cli: boolean
|
|
|
31
35
|
* out at its hold and bound), for a run whose cost is its booking: the runs list's figure while it runs. Null when one
|
|
32
36
|
* session's is unknown, never 0 for it. */
|
|
33
37
|
export declare function bookedCapSpend(entries: readonly EntryLike[]): number | null;
|
|
38
|
+
/** The bound of a run's requests since its spend last fit under `capUsd`, as the kernel's overCapOf reads it: each model
|
|
39
|
+
* request, in each model session's order, at the figure the cap counts it at, after what the paid tools and decisions
|
|
40
|
+
* spent; reset to 0 whenever the spend fits, else grown by each request's bound. What its over-cap row (run-view.ts
|
|
41
|
+
* withOverCap) reads to tell a cache miss within that bound from a run that spent past its cap. 0 when nothing ran. */
|
|
42
|
+
export declare function overCapBound(entries: readonly EntryLike[], capUsd: number): number;
|
|
34
43
|
/** A run's metrics as the end commit writes them (the StoredMetrics JSON on the run row): the timeline's count, with the
|
|
35
44
|
* effort the run ran at and, on a harness other than pi, the model its revision named. */
|
|
36
45
|
export type RunMetricsStored = RunMetrics & {
|
|
@@ -48,3 +57,7 @@ export declare function runMetrics(entries: readonly EntryLike[], options?: {
|
|
|
48
57
|
metrics: RunMetricsStored;
|
|
49
58
|
costUsd: number | null;
|
|
50
59
|
};
|
|
60
|
+
export declare function cliRunMetrics(rootEntries: readonly EntryLike[], booked: BookedSpend, options: {
|
|
61
|
+
readonly effort?: string;
|
|
62
|
+
readonly model: string;
|
|
63
|
+
}): RunMetricsStored;
|
package/dist/runner/metrics.js
CHANGED
|
@@ -11,6 +11,7 @@ import { runMetricsWithDecisions, timelineOf } from "../timeline/index.js";
|
|
|
11
11
|
import { answeredUnpriced, RUNNER_RECORDS, sessionSpendOf } from "@parcha/agentrun-kernel";
|
|
12
12
|
import { DECISION_SESSION, TOOL_SESSION } from "@parcha/agentrun-kernel/kernel/cap";
|
|
13
13
|
import { KINDS, WORKFLOW_SESSION } from "./journal-kinds.js";
|
|
14
|
+
import { anthropicModelId } from "../provider.js";
|
|
14
15
|
/** The conversation each of the run's sessions books in, by its key: the first `agentrun.session.key` entry naming it. */
|
|
15
16
|
function sessionConversations(entries) {
|
|
16
17
|
const out = new Map();
|
|
@@ -40,16 +41,27 @@ export function bookedSpend(entries, which) {
|
|
|
40
41
|
const chosen = (e) => (which === "paid" ? conv(e) === paidConv : which === "decisions" ? conv(e) === decisionsConv : conv(e) !== paidConv && conv(e) !== decisionsConv);
|
|
41
42
|
const turnOf = (e) => `${String(e.conversationId)}:${String(e.data?.turn)}`;
|
|
42
43
|
const answered = new Set(entries.filter((e) => e.kind === RUNNER_RECORDS.turn && chosen(e)).map(turnOf));
|
|
44
|
+
// The model each request was sent on, by its turn (its runner.request's `model`).
|
|
45
|
+
const sentOn = new Map(entries.filter((e) => e.kind === RUNNER_RECORDS.request && chosen(e)).map((e) => [turnOf(e), e.data?.model]));
|
|
46
|
+
const models = {};
|
|
47
|
+
const count = (e) => {
|
|
48
|
+
const model = sentOn.get(turnOf(e));
|
|
49
|
+
const name = typeof model === "string" ? model : "";
|
|
50
|
+
models[name] = (models[name] ?? 0) + 1;
|
|
51
|
+
};
|
|
43
52
|
let known = 0;
|
|
44
53
|
let unpriced = 0;
|
|
45
54
|
let requests = 0;
|
|
55
|
+
let unmetered = 0;
|
|
46
56
|
const tokens = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 };
|
|
47
57
|
for (const e of entries) {
|
|
48
58
|
if (!chosen(e))
|
|
49
59
|
continue;
|
|
50
60
|
if (e.kind === RUNNER_RECORDS.request && !answered.has(turnOf(e))) {
|
|
51
61
|
requests += 1;
|
|
62
|
+
count(e);
|
|
52
63
|
unpriced += 1;
|
|
64
|
+
unmetered += 1;
|
|
53
65
|
continue;
|
|
54
66
|
}
|
|
55
67
|
if (e.kind !== RUNNER_RECORDS.turn)
|
|
@@ -58,17 +70,21 @@ export function bookedSpend(entries, which) {
|
|
|
58
70
|
if (d.givenBack === true || d.unsent === true)
|
|
59
71
|
continue;
|
|
60
72
|
requests += 1;
|
|
73
|
+
count(e);
|
|
61
74
|
// An answer with no price of its own was booked at its hold for the cap (answeredUnpriced): as a cost it is unknown.
|
|
62
75
|
const usd = answeredUnpriced(d) ? null : typeof d.bookedUsd === "number" && Number.isFinite(d.bookedUsd) ? d.bookedUsd : typeof d.usd === "number" && Number.isFinite(d.usd) ? d.usd : null;
|
|
63
76
|
if (usd === null)
|
|
64
77
|
unpriced += 1;
|
|
65
78
|
else
|
|
66
79
|
known += usd;
|
|
80
|
+
// The booking keeps a request's usage only when it reported some (runner.ts tokensOf): one with none is unmetered.
|
|
81
|
+
if (d.usage === undefined)
|
|
82
|
+
unmetered += 1;
|
|
67
83
|
for (const key of Object.keys(tokens))
|
|
68
84
|
if (typeof d.usage?.[key] === "number")
|
|
69
85
|
tokens[key] += d.usage[key];
|
|
70
86
|
}
|
|
71
|
-
return { usd: unpriced ? null : known, known, unpriced, requests, tokens };
|
|
87
|
+
return { usd: unpriced ? null : known, known, unpriced, requests, unmetered, models, tokens };
|
|
72
88
|
}
|
|
73
89
|
/** Whether a run's record carries no cost of its own, so its usage row and its live spend are its booking's: a CLI
|
|
74
90
|
* harness's record (`cli`), or a workflow's (its model nodes' answers carry pi-ai's $0). A pi run's answers carry their
|
|
@@ -92,6 +108,36 @@ export function bookedCapSpend(entries) {
|
|
|
92
108
|
}
|
|
93
109
|
return spent;
|
|
94
110
|
}
|
|
111
|
+
/** The bound of a run's requests since its spend last fit under `capUsd`, as the kernel's overCapOf reads it: each model
|
|
112
|
+
* request, in each model session's order, at the figure the cap counts it at, after what the paid tools and decisions
|
|
113
|
+
* spent; reset to 0 whenever the spend fits, else grown by each request's bound. What its over-cap row (run-view.ts
|
|
114
|
+
* withOverCap) reads to tell a cache miss within that bound from a run that spent past its cap. 0 when nothing ran. */
|
|
115
|
+
export function overCapBound(entries, capUsd) {
|
|
116
|
+
const keyed = sessionConversations(entries);
|
|
117
|
+
const paidConv = keyed.get(TOOL_SESSION);
|
|
118
|
+
const decisionsConv = keyed.get(DECISION_SESSION);
|
|
119
|
+
const others = [paidConv, decisionsConv].reduce((sum, conversation) => {
|
|
120
|
+
if (conversation === undefined)
|
|
121
|
+
return sum;
|
|
122
|
+
const read = sessionSpendOf(recordsIn(entries, conversation)).spentUsd;
|
|
123
|
+
return sum + (read ?? 0);
|
|
124
|
+
}, 0);
|
|
125
|
+
const booking = new Set(entries.filter((e) => e.kind === RUNNER_RECORDS.request || e.kind === RUNNER_RECORDS.turn).map((e) => Number(e.conversationId)));
|
|
126
|
+
let running = others;
|
|
127
|
+
let bound = 0;
|
|
128
|
+
for (const conversation of booking) {
|
|
129
|
+
if (conversation === paidConv || conversation === decisionsConv)
|
|
130
|
+
continue;
|
|
131
|
+
const read = sessionSpendOf(recordsIn(entries, conversation));
|
|
132
|
+
for (const { turn, usd } of read.figures) {
|
|
133
|
+
running += usd ?? 0;
|
|
134
|
+
bound = running <= capUsd ? 0 : bound + (read.bounds.get(turn) ?? 0);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return bound;
|
|
138
|
+
}
|
|
139
|
+
/** The booking records of `conversation`, as the kernel's session readers take them. */
|
|
140
|
+
const recordsIn = (entries, conversation) => entries.filter((e) => Number(e.conversationId) === conversation && e.kind !== KINDS.sessionKey).map((e) => ({ kind: e.kind, data: (e.data ?? null) }));
|
|
95
141
|
/** The run's metrics and cost from its journal `entries`. `decisions`: a workflow run's receipts (none for pi).
|
|
96
142
|
* `effort`/`model`: the enrichment the old storedMetrics added. `costUsd` is the usage row's cost: null when a
|
|
97
143
|
* response's cost is unknown, 0 before any request (costOf). */
|
|
@@ -106,3 +152,28 @@ export function runMetrics(entries, options = {}) {
|
|
|
106
152
|
costUsd,
|
|
107
153
|
};
|
|
108
154
|
}
|
|
155
|
+
/** A CLI harness's run (its record the loop's: claude-agent, codex, opencode): its metrics from `rootEntries`, its root
|
|
156
|
+
* conversation's record (its tools), with its tokens and model requests those of `booked`, its booking's (bookedSpend
|
|
157
|
+
* "model", which the caller reads once for the run's cost too: what its model proxy booked each request at,
|
|
158
|
+
* runner.turn's usage), since the harness's own record carries none; each request counted at `model`, the model its
|
|
159
|
+
* run chose. Tokens are not a price: a request answered at no known price, with its usage, is metered all the same. */
|
|
160
|
+
/** `byModel` (a booking's requests by the model each was sent on) under the names a run's metrics use: the run's own
|
|
161
|
+
* model, and a request that names none, as `run` (the model it chose, `provider/model`, through OpenRouter or dotted
|
|
162
|
+
* too); any other (a learned node's tier, the hosted search's model) as its request names it. A booked name is the run's
|
|
163
|
+
* when it is one model by the router's match: its last segment, dots as dashes (provider.ts anthropicModelId: the
|
|
164
|
+
* booking names Anthropic's id, claude-haiku-4-5, for a run that chose openrouter/anthropic/claude-haiku-4.5). */
|
|
165
|
+
function modelsOf(byModel, run) {
|
|
166
|
+
const same = (name) => anthropicModelId({ provider: "anthropic", modelId: name.slice(name.lastIndexOf("/") + 1) });
|
|
167
|
+
const own = same(run);
|
|
168
|
+
const out = {};
|
|
169
|
+
for (const [model, n] of Object.entries(byModel)) {
|
|
170
|
+
const name = model === "" || same(model) === own ? run : model;
|
|
171
|
+
out[name] = (out[name] ?? 0) + n;
|
|
172
|
+
}
|
|
173
|
+
return out;
|
|
174
|
+
}
|
|
175
|
+
export function cliRunMetrics(rootEntries, booked, options) {
|
|
176
|
+
const { metrics: counted } = runMetrics(rootEntries, options);
|
|
177
|
+
const { tokens } = booked;
|
|
178
|
+
return { ...counted, input: tokens.input, output: tokens.output, cacheRead: tokens.cacheRead, cacheWrite: tokens.cacheWrite, requests: booked.requests, unmetered: booked.unmetered, models: modelsOf(booked.models, options.model) };
|
|
179
|
+
}
|
|
@@ -36,6 +36,9 @@ export interface ModelRoute {
|
|
|
36
36
|
readonly auth?: "bearer" | "x-api-key";
|
|
37
37
|
};
|
|
38
38
|
readonly model: string;
|
|
39
|
+
/** The model as the run names it (`provider/model-id`, chooseModel's): what the `llm` tool's answer says it ran on,
|
|
40
|
+
* never the session provider the runner reaches it through. */
|
|
41
|
+
readonly named?: string;
|
|
39
42
|
/** The catalog's entry for the model, as pi-ai's model of it takes it: on every wire, what it takes as input (whether it
|
|
40
43
|
* takes images) and its input limits (an image's most size), which pi's session and its read size an image by; on a
|
|
41
44
|
* wire that carries its reasoning (Responses), also whether it reasons, its window and its output ceiling. */
|
|
@@ -43,7 +43,7 @@ export async function routeOf(model, env = process.env, tier = "default", wires
|
|
|
43
43
|
// What the model takes as input and its input limits, on every wire: pi's session sends a model that takes no images
|
|
44
44
|
// pi-ai's placeholder in place of one, and pi's read holds an image to the model's limits (port-models.ts sessionModel).
|
|
45
45
|
const sees = { ...(target.input ? { input: target.input } : {}), ...(target.inputLimits ? { inputLimits: target.inputLimits } : {}) };
|
|
46
|
-
const route = { model: chosen.model.modelId, price, cost: target.cost, outputCeiling: target.maxTokens ?? null, like: sees };
|
|
46
|
+
const route = { model: chosen.model.modelId, named: `${chosen.model.provider}/${chosen.model.modelId}`, price, cost: target.cost, outputCeiling: target.maxTokens ?? null, like: sees };
|
|
47
47
|
// An Anthropic model speaks Messages itself: the network, at its catalog origin, its key read by name per request.
|
|
48
48
|
if (chosen.model.provider === "anthropic") {
|
|
49
49
|
return { ...route, provider: { api: "anthropic-messages", origin: target.baseUrl ?? "https://api.anthropic.com", credential: () => env.ANTHROPIC_API_KEY ?? env.ANTHROPIC_AUTH_TOKEN ?? "" } };
|
package/dist/runner/runner.js
CHANGED
|
@@ -12,7 +12,7 @@ import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
|
12
12
|
import { COMMAND_KINDS, endedReason } from "./commands.js";
|
|
13
13
|
import { KINDS, withdrawnAnswers } from "./journal-kinds.js";
|
|
14
14
|
import { journalEntries } from "./journal-reader.js";
|
|
15
|
-
import { endedBy } from "./loop-contract.js";
|
|
15
|
+
import { ClaimRefused, endedBy } from "./loop-contract.js";
|
|
16
16
|
import { isFenced } from "./store-port.js";
|
|
17
17
|
import { heldRedactor, processSecretRedactor } from "./redact.js";
|
|
18
18
|
import { withLiveTicker } from "./live-ticker.js";
|
|
@@ -30,6 +30,8 @@ export const runnerCloseBoundMs = (drainMs) => drainMs + RUNNER_LEASE_MS - RUNNE
|
|
|
30
30
|
export const RUNNER_RENEW_EVERY_MS = 10_000;
|
|
31
31
|
/** A runner's name when none is given: its host, its process and a part of a random id. */
|
|
32
32
|
export const runnerName = () => `${hostname()}:${process.pid}:${randomUUID().slice(0, 8)}`;
|
|
33
|
+
/** A failed end's code when the claim was refused for good before any loop started (loop-contract's ClaimRefused). */
|
|
34
|
+
const CLAIM_REFUSED = "claim-refused";
|
|
33
35
|
/** The untaken row a run ends on when no loop can: a cancel before a stop (it ends the run for good, in its words). */
|
|
34
36
|
const endingRow = (untaken) => untaken.find((row) => row.kind === "cancel") ?? untaken.find((row) => row.kind === "stop");
|
|
35
37
|
/** A commit by a loop whose claim this runner gave up: refused before it reaches the store. */
|
|
@@ -425,7 +427,8 @@ export function startRunner(options) {
|
|
|
425
427
|
// with why, and a person can raise again or stop it (#1944-5). A claim its spec refuses (ClaimRefused: a handed
|
|
426
428
|
// sign-in that won't read back, an MCP pin refused) never comes here: the loop writes that end itself, final, the run
|
|
427
429
|
// failed in the refusal's words.
|
|
428
|
-
|
|
430
|
+
// A claim refused for good (CLAIM_REFUSED) is no resume to try again: it fails the run below, parked or not.
|
|
431
|
+
if (threw && end.state === "failed" && claim.from === "parked" && end.error.code !== CLAIM_REFUSED)
|
|
429
432
|
return await resumeFailed(held, end.error.message);
|
|
430
433
|
if (threw && end.state === "failed") {
|
|
431
434
|
// A loop that failed with no end written: a person's stop waiting now is the run's end (stopped, its row taken),
|
|
@@ -515,14 +518,24 @@ export function startRunner(options) {
|
|
|
515
518
|
const delivered = new Promise((resolve) => (firstDelivered = resolve));
|
|
516
519
|
// Set below, once held is made: the loop's end commit lands only after start(), well after.
|
|
517
520
|
let ending = () => { };
|
|
521
|
+
// Set below, once held is made: the loop asks deliverNow only once its first turn has ended, well after.
|
|
522
|
+
let heldNow;
|
|
518
523
|
const loop = loopsOf({
|
|
519
524
|
journal: (forClaim) => fenced(store.journal(forClaim), fence, forClaim.runId, () => ending()),
|
|
520
525
|
flush: () => store.flush(),
|
|
521
526
|
signal: abort.signal,
|
|
522
527
|
delivered,
|
|
528
|
+
// A delivery under way first (its rows are the loop's already), then one more read of the run's new rows.
|
|
529
|
+
deliverNow: async () => {
|
|
530
|
+
if (!heldNow)
|
|
531
|
+
return;
|
|
532
|
+
await heldNow.inFlight?.catch(() => undefined);
|
|
533
|
+
await deliver(heldNow);
|
|
534
|
+
},
|
|
523
535
|
redact,
|
|
524
536
|
});
|
|
525
537
|
const held = { claim, loop, fence, abort, cursor: 0, stopping: false, ending: false, sealed: false, renewing: false, delivering: false, mib };
|
|
538
|
+
heldNow = held;
|
|
526
539
|
// The loop's own end landed: the run is ending from here, its teardown included (no renew, no lost claim).
|
|
527
540
|
ending = () => {
|
|
528
541
|
held.ending = true;
|
|
@@ -539,7 +552,9 @@ export function startRunner(options) {
|
|
|
539
552
|
}
|
|
540
553
|
catch (error) {
|
|
541
554
|
threw = true;
|
|
542
|
-
|
|
555
|
+
// A claim refused before any loop could start (the dispatch's ClaimRefused: a harness this host never holds) is
|
|
556
|
+
// for good: the run fails in its words, whatever woke it.
|
|
557
|
+
end = { state: "failed", error: { code: error instanceof ClaimRefused ? CLAIM_REFUSED : "loop-threw", message: message(error) } };
|
|
543
558
|
}
|
|
544
559
|
await finish(held, end, threw);
|
|
545
560
|
})();
|
|
@@ -658,6 +673,52 @@ export function startRunner(options) {
|
|
|
658
673
|
};
|
|
659
674
|
poll();
|
|
660
675
|
commandTimer = setTimeout(deliverAll, commandPollMs);
|
|
676
|
+
/** The untaken stop or cancel row each of `going` ends on (endingRow: a cancel before a stop), past its cursor, by run id:
|
|
677
|
+
* the close's one read of their rows (store.commandsOf), after the deliveries in flight. The whole of it is bounded by
|
|
678
|
+
* the stop margin, so a store that stalls never holds the shutdown: a read that fails or runs past it is said, and those
|
|
679
|
+
* runs are released for a shutdown as before, their rows untaken for the next claim. */
|
|
680
|
+
const closingEnds = async (going) => {
|
|
681
|
+
const ends = new Map();
|
|
682
|
+
if (going.length === 0)
|
|
683
|
+
return ends;
|
|
684
|
+
const read = async () => {
|
|
685
|
+
// A delivery in flight finishes first: it may be handing on that same row.
|
|
686
|
+
await Promise.all(going.map((held) => held.inFlight?.catch(() => undefined)));
|
|
687
|
+
const still = going.filter((held) => !held.stopping && !held.ending && !held.fence.lost);
|
|
688
|
+
if (still.length === 0)
|
|
689
|
+
return ends;
|
|
690
|
+
const rows = await store.commandsOf(still.map((held) => ({ runId: held.claim.runId, after: held.cursor })));
|
|
691
|
+
const found = new Map();
|
|
692
|
+
for (const held of still) {
|
|
693
|
+
const end = endingRow((rows.get(held.claim.runId) ?? []).filter((row) => row.takenAt === null));
|
|
694
|
+
if (end)
|
|
695
|
+
found.set(held.claim.runId, end);
|
|
696
|
+
}
|
|
697
|
+
return found;
|
|
698
|
+
};
|
|
699
|
+
let bound;
|
|
700
|
+
// Within the close's stop window (the lease less its margin), whatever the margin.
|
|
701
|
+
const boundMs = Math.min(stopMarginMs, leaseMs - stopMarginMs);
|
|
702
|
+
const late = new Promise((resolve) => (bound = setTimeout(() => resolve("late"), boundMs)));
|
|
703
|
+
// A read that fails after the bound is never an unhandled rejection: the close has moved on without it.
|
|
704
|
+
const reading = read();
|
|
705
|
+
reading.catch(() => undefined);
|
|
706
|
+
try {
|
|
707
|
+
const found = await Promise.race([reading, late]);
|
|
708
|
+
if (found !== "late")
|
|
709
|
+
return found;
|
|
710
|
+
for (const held of going)
|
|
711
|
+
emit({ type: "error", runId: held.claim.runId, step: "commands", message: `the close's read of its stop rows took longer than ${boundMs} ms: released for the next claim` });
|
|
712
|
+
}
|
|
713
|
+
catch (error) {
|
|
714
|
+
for (const held of going)
|
|
715
|
+
emit({ type: "error", runId: held.claim.runId, step: "commands", message: message(error) });
|
|
716
|
+
}
|
|
717
|
+
finally {
|
|
718
|
+
clearTimeout(bound);
|
|
719
|
+
}
|
|
720
|
+
return ends;
|
|
721
|
+
};
|
|
661
722
|
const stopTimers = () => {
|
|
662
723
|
clearTimeout(pollTimer);
|
|
663
724
|
clearTimeout(commandTimer);
|
|
@@ -689,17 +750,38 @@ export function startRunner(options) {
|
|
|
689
750
|
draining = false;
|
|
690
751
|
clearTimeout(commandTimer);
|
|
691
752
|
const live = [...runs.values()].filter((held) => !held.fence.lost);
|
|
753
|
+
// One window for the stop after the drain, the one runnerCloseBoundMs counts (the lease less its margin): the read
|
|
754
|
+
// below and the loops' stop share it, so the close is never longer than a deployment's stop grace allows for.
|
|
755
|
+
const stopBy = Date.now() + leaseMs - stopMarginMs;
|
|
756
|
+
// A stop or cancel a person sent before the close is the run's end, never a resume: one no delivery has handed on
|
|
757
|
+
// yet (the command poll's tick had not come) is read here, once, for every run still going, and stops its loop as
|
|
758
|
+
// its delivery would. Its end is in the store when the close is done, and the next start never resumes the turn.
|
|
759
|
+
const ends = await closingEnds(live.filter((held) => !held.ending && !held.stopping));
|
|
692
760
|
for (const held of live) {
|
|
693
|
-
if (
|
|
694
|
-
|
|
695
|
-
|
|
761
|
+
if (held.ending)
|
|
762
|
+
continue;
|
|
763
|
+
const end = ends.get(held.claim.runId);
|
|
764
|
+
if (end && !held.stopping) {
|
|
765
|
+
held.cursor = Math.max(held.cursor, end.id);
|
|
766
|
+
stopLoop(held, { kind: "command", commandId: end.id, ...(end.kind === "cancel" ? { cancel: true } : {}) });
|
|
696
767
|
}
|
|
768
|
+
// A loop a stop or cancel already stops writes that end: it is never cut for the close.
|
|
769
|
+
if (held.stopping)
|
|
770
|
+
continue;
|
|
771
|
+
stopLoop(held, { kind: "shutdown" });
|
|
772
|
+
held.abort.abort(new Error("the runner is closing"));
|
|
697
773
|
}
|
|
698
|
-
// Claims are renewed while the loops stop; a loop that never stops is given up when its claim would run out
|
|
774
|
+
// Claims are renewed while the loops stop; a loop that never stops is given up when its claim would run out (the end
|
|
775
|
+
// of the window the read above began).
|
|
699
776
|
let timeout;
|
|
700
|
-
const late = new Promise((resolve) => (timeout = setTimeout(resolve,
|
|
777
|
+
const late = new Promise((resolve) => (timeout = setTimeout(resolve, Math.max(0, stopBy - Date.now()))));
|
|
701
778
|
await Promise.race([Promise.all([...live.map((held) => held.done), ...endings]), late]);
|
|
702
779
|
clearTimeout(timeout);
|
|
780
|
+
// A loop still going at the window's end (one a stop row stops, whose signal was kept whole for its end) has its
|
|
781
|
+
// signal aborted before its claim is given up: no request of it outlives the close.
|
|
782
|
+
for (const held of live)
|
|
783
|
+
if (!held.ending && !held.abort.signal.aborted)
|
|
784
|
+
held.abort.abort(new Error("the runner is closing"));
|
|
703
785
|
for (const held of runs.values())
|
|
704
786
|
held.fence.lost = true;
|
|
705
787
|
stopTimers();
|
|
@@ -16,6 +16,11 @@ type Held = {
|
|
|
16
16
|
readonly keys?: {
|
|
17
17
|
release(): void;
|
|
18
18
|
} | undefined;
|
|
19
|
+
/** The CLI's files on this machine for this claim (its private folder in the run's scratch), swept once the rest is let
|
|
20
|
+
* go: every claim lays its own again, the harness's state coming back from the run's journal. */
|
|
21
|
+
readonly scratch?: {
|
|
22
|
+
sweep(): Promise<void>;
|
|
23
|
+
} | undefined;
|
|
19
24
|
/** What the spec hands the loop, which lets it go itself (the claim's MCP): let go here only when the build throws. */
|
|
20
25
|
readonly passed?: {
|
|
21
26
|
release(): void;
|
|
@@ -29,8 +34,8 @@ export declare class SpecHolds {
|
|
|
29
34
|
/** `parts`, held from now until the release. */
|
|
30
35
|
hold(parts: Held): void;
|
|
31
36
|
/** Everything held let go, once: the tools' end (background processes ended, scratch swept), the computer, the Archil
|
|
32
|
-
* mount credential (idempotent: the computer's release revokes it too), the Workspace's end,
|
|
33
|
-
* where they are held. A second call waits for the first and does nothing more. */
|
|
37
|
+
* mount credential (idempotent: the computer's release revokes it too), the Workspace's end, the CLI's scratch, then
|
|
38
|
+
* the claim's keys where they are held. A second call waits for the first and does nothing more. */
|
|
34
39
|
release(): Promise<void>;
|
|
35
40
|
/** What the spec would have handed the loop, let go: only a build that throws calls it. */
|
|
36
41
|
releasePassed(): void;
|
|
@@ -19,18 +19,19 @@ export class SpecHolds {
|
|
|
19
19
|
this.#held = { ...this.#held, ...parts };
|
|
20
20
|
}
|
|
21
21
|
/** Everything held let go, once: the tools' end (background processes ended, scratch swept), the computer, the Archil
|
|
22
|
-
* mount credential (idempotent: the computer's release revokes it too), the Workspace's end,
|
|
23
|
-
* where they are held. A second call waits for the first and does nothing more. */
|
|
22
|
+
* mount credential (idempotent: the computer's release revokes it too), the Workspace's end, the CLI's scratch, then
|
|
23
|
+
* the claim's keys where they are held. A second call waits for the first and does nothing more. */
|
|
24
24
|
release() {
|
|
25
25
|
return (this.#released ??= this.#releaseAll());
|
|
26
26
|
}
|
|
27
27
|
async #releaseAll() {
|
|
28
|
-
const { tools, computer, archil, ws, keys } = this.#held;
|
|
28
|
+
const { tools, computer, archil, ws, scratch, keys } = this.#held;
|
|
29
29
|
const log = this.#log;
|
|
30
30
|
await tools?.end().catch((error) => log(`the run's tools' end failed: ${words(error)}`));
|
|
31
31
|
await computer?.release().catch((error) => log(`the run's computer could not be let go: ${words(error)}`));
|
|
32
32
|
await archil?.revoke().catch((error) => log(`the run's Archil mount credential could not be revoked: ${words(error)}`));
|
|
33
33
|
await ws?.end().catch((error) => log(`the run's workspace end failed: ${words(error)}`));
|
|
34
|
+
await scratch?.sweep().catch((error) => log(`the run's scratch folder could not be swept: ${words(error)}`));
|
|
34
35
|
keys?.release();
|
|
35
36
|
}
|
|
36
37
|
/** What the spec would have handed the loop, let go: only a build that throws calls it. */
|
|
@@ -30,6 +30,8 @@ export interface DecisionDriver {
|
|
|
30
30
|
decisionRequests(): Record<string, {
|
|
31
31
|
status: string;
|
|
32
32
|
}>;
|
|
33
|
+
/** Resolves once the driver's commits so far are durable (a request it ended, before the run parks on it). */
|
|
34
|
+
flush(): Promise<void>;
|
|
33
35
|
}
|
|
34
36
|
/** The run's spend cap over the workflow's adapters (app.ts's budget: stepped/failing/capStopped and the decision cap),
|
|
35
37
|
* injected so this module holds no money of its own. Each wrapper is applied to its adapter where app.ts applied it; a run
|
|
@@ -40,9 +42,12 @@ export interface WorkflowCap {
|
|
|
40
42
|
node<F>(fn: F): F;
|
|
41
43
|
/** stepped(failing(·)): a call node, which waits for a raise on a held effect and goes again. */
|
|
42
44
|
effect<F>(fn: F): F;
|
|
43
|
-
/**
|
|
44
|
-
*
|
|
45
|
+
/** A decision, before the driver admits its request: priced, or parked by a pause. The driver tells a replayed request,
|
|
46
|
+
* which holds nothing. */
|
|
45
47
|
judge<F>(fn: F, driver?: DecisionDriver): F;
|
|
48
|
+
/** A decision's judge once the driver has admitted its request: held through the kernel cap, sent, and settled. Absent:
|
|
49
|
+
* the judge runs as given. */
|
|
50
|
+
admitted?<F>(fn: F): F;
|
|
46
51
|
/** A call node's wait on a raise (deps.held), left out of its deadline. */
|
|
47
52
|
held?(path: string): number;
|
|
48
53
|
}
|
|
@@ -6,6 +6,7 @@ const identityCap = { node: (fn) => fn, effect: (fn) => fn, judge: (fn) => fn };
|
|
|
6
6
|
* Pass the result to createWorkflowLoop's spec.build. */
|
|
7
7
|
export function workflowHost(deps) {
|
|
8
8
|
const cap = deps.cap ?? identityCap;
|
|
9
|
+
const admitted = (fn) => (cap.admitted ? cap.admitted(fn) : fn);
|
|
9
10
|
/** A model node's agent: its tier's model, the tools it names, and the extensions they come from (app.ts nodeAgent). */
|
|
10
11
|
const nodeAgent = (node) => {
|
|
11
12
|
const bindings = (node.tools ?? []).flatMap((name) => deps.nodeTool(name) ?? []);
|
|
@@ -38,7 +39,8 @@ export function workflowHost(deps) {
|
|
|
38
39
|
const recovered = withRecovery(driver, {
|
|
39
40
|
runNode: nodes.on(taskScope(runtime), context).runNode,
|
|
40
41
|
runEffect: deps.runEffect,
|
|
41
|
-
|
|
42
|
+
// The judge the driver asks once it has admitted a request: the cap holds, sends and settles it there (admitted).
|
|
43
|
+
...(deps.decisionProviders ? { runJudge: admitted(judgeFromProviders({ ...deps.decisionProviders, loadImage: deps.loadImage })), decisionProviders: deps.decisionProviders } : {}),
|
|
42
44
|
recordDecision: async (receipt, exchange) => {
|
|
43
45
|
await decisions.recordDecision(receipt, exchange);
|
|
44
46
|
deps.onReceipt?.(receipt);
|
|
@@ -4,7 +4,7 @@ import type { Models } from "@earendil-works/pi-ai";
|
|
|
4
4
|
import type { Workflow } from "@parcha/agentrun-dsl";
|
|
5
5
|
import { type WorkflowTaskHost } from "@parcha/agentrun-pi/durable";
|
|
6
6
|
import { type BudgetData, type EndData } from "./journal-kinds.js";
|
|
7
|
-
import { type Claim, type LoopFactory } from "./loop-contract.js";
|
|
7
|
+
import { type Claim, type Journal, type LoopFactory } from "./loop-contract.js";
|
|
8
8
|
/** A cap refusal, as the kernel cap hands one to parkOf/checkRaise (the loop never imports the cap; its rule is handed in
|
|
9
9
|
* via the spec, so flat or tiered pricing is the cap's, not this loop's). */
|
|
10
10
|
export type CapRefusal = {
|
|
@@ -127,6 +127,9 @@ export declare const isWorkflowRevision: (revision: {
|
|
|
127
127
|
* the claim opens from the store (redact.ts holdClaimed). */
|
|
128
128
|
export interface WorkflowSpecRun {
|
|
129
129
|
readonly redact?: (text: string) => string;
|
|
130
|
+
/** A fresh journal of the claim, for what the spec reads from the run's records at its end (its decisions' booked
|
|
131
|
+
* cost): a fresh one, since the Harness closes its own before the end is written. */
|
|
132
|
+
readonly journal?: () => Journal;
|
|
130
133
|
}
|
|
131
134
|
/** Loops for workflow runs: `spec(claim)` gives each claim's run what it runs (its workflow, input, models and host). */
|
|
132
135
|
export declare function createWorkflowLoop(specOf: (claim: Claim, run: WorkflowSpecRun) => WorkflowRunSpec | Promise<WorkflowRunSpec>): LoopFactory;
|
|
@@ -213,7 +213,7 @@ function workflowLoop(specOf, deps) {
|
|
|
213
213
|
const parkController = new AbortController();
|
|
214
214
|
let heldRefusal;
|
|
215
215
|
const context = withAbortSignal(AbortSignal.any([deps.signal, parkController.signal]), BACKGROUND_CONTEXT);
|
|
216
|
-
spec = await specOf(claim, deps.redact ? { redact: deps.redact } : {});
|
|
216
|
+
spec = await specOf(claim, { ...(deps.redact ? { redact: deps.redact } : {}), journal: () => deps.journal(claim) });
|
|
217
217
|
claimNow = claim;
|
|
218
218
|
specReady();
|
|
219
219
|
const revision = { id: spec.revisionId, kind: "workflow", body: { workflow: spec.workflow, tools: [...spec.tools] } };
|
|
@@ -281,6 +281,12 @@ function workflowLoop(specOf, deps) {
|
|
|
281
281
|
const { output } = await readWorkflowRun({ runId: claim.runId, storage: endJournal, revision }, { context });
|
|
282
282
|
return await writeEnd(endJournal, context, { ...carry, output: output ?? null });
|
|
283
283
|
}
|
|
284
|
+
// An escalated run's review, as main's server kept it (runs.ts): the escalation's kind, the escalate node's label (else
|
|
285
|
+
// the node it escalated at), and its summary (else the run's), kept on its end for the run's `review`.
|
|
286
|
+
if (carry.state === "escalated") {
|
|
287
|
+
const { escalation, escalatedAt } = await readWorkflowRun({ runId: claim.runId, storage: endJournal, revision }, { context });
|
|
288
|
+
return await writeEnd(endJournal, context, { ...carry, review: { kind: escalation?.kind ?? null, node: escalation?.label ?? escalatedAt?.label ?? null, reason: escalation?.summary ?? carry.summary } });
|
|
289
|
+
}
|
|
284
290
|
return await writeEnd(endJournal, context, carry);
|
|
285
291
|
}
|
|
286
292
|
finally {
|
|
@@ -305,7 +311,7 @@ function workflowLoop(specOf, deps) {
|
|
|
305
311
|
async function writeEnd(journal, context, carry) {
|
|
306
312
|
const state = carry.state === "failed" ? "failed" : carry.state === "stopped" ? "stopped" : "ended";
|
|
307
313
|
const outcome = carry.state === "escalated" ? "escalated" : undefined;
|
|
308
|
-
const base = { state, summary: carry.summary, ...(outcome ? { outcome } : {}), ...(carry.output !== undefined ? { output: carry.output } : {}) };
|
|
314
|
+
const base = { state, summary: carry.summary, ...(outcome ? { outcome } : {}), ...(carry.output !== undefined ? { output: carry.output } : {}), ...(carry.review ? { review: carry.review } : {}) };
|
|
309
315
|
const patch = await endPatchOf(spec, base);
|
|
310
316
|
const data = { ...base, ...(patch.costUsd !== undefined ? { costUsd: patch.costUsd } : {}), ...(patch.metrics !== undefined ? { metrics: patch.metrics } : {}) };
|
|
311
317
|
const runPatch = {
|
|
@@ -21,6 +21,8 @@ export declare const SUBMIT_TOOL = "submit";
|
|
|
21
21
|
export interface WorkflowProvider {
|
|
22
22
|
/** The model id the node asks for (the tier's model). */
|
|
23
23
|
readonly modelId: string;
|
|
24
|
+
/** The model as the run names it (`provider/model-id`): what an `llm` call's answer says it ran on. Absent: `modelId`. */
|
|
25
|
+
readonly named?: string;
|
|
24
26
|
/** The wire the proxy forwards on, and pi-ai's client of it speaks to the proxy (port-models.ts sessionProvider). */
|
|
25
27
|
readonly api: Wire;
|
|
26
28
|
/** The catalog's entry for the model (whether it reasons, its window), as pi's session takes it (model-route.ts). */
|
|
@@ -108,6 +110,7 @@ export declare function pauseAtEffects(cap: WorkflowCap, hooks: Pick<WorkflowHos
|
|
|
108
110
|
export type CallHold = {
|
|
109
111
|
readonly usd: number;
|
|
110
112
|
readonly name: string;
|
|
113
|
+
readonly tool?: string;
|
|
111
114
|
readonly basis: string;
|
|
112
115
|
readonly chargedBy?: string;
|
|
113
116
|
readonly llm?: {
|