@parcha/agentrun-serve 0.1.0-beta.50 → 0.1.0-beta.52
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 +185 -0
- package/README.md +236 -30
- package/dist/adapters.js +1 -1
- package/dist/agent-delete.d.ts +13 -2
- package/dist/agent-delete.js +14 -5
- package/dist/agents-store.d.ts +5 -1
- package/dist/agents-store.js +17 -7
- package/dist/api-only.d.ts +6 -3
- package/dist/api-only.js +8 -5
- package/dist/archil-routes.d.ts +1 -0
- package/dist/archil-routes.js +28 -2
- package/dist/capacity.d.ts +50 -0
- package/dist/capacity.js +49 -0
- package/dist/cli-learning/claude-wire.d.ts +41 -0
- package/dist/cli-learning/claude-wire.js +258 -0
- package/dist/cli-learning/cli.d.ts +11 -0
- package/dist/cli-learning/cli.js +241 -0
- package/dist/cli-learning/codex-worktree.d.ts +10 -0
- package/dist/cli-learning/codex-worktree.js +119 -0
- package/dist/cli-learning/connections.d.ts +62 -0
- package/dist/cli-learning/connections.js +87 -0
- package/dist/cli-learning/entry.d.ts +1 -0
- package/dist/cli-learning/entry.js +4 -0
- package/dist/cli-learning/evidence.d.ts +78 -0
- package/dist/cli-learning/evidence.js +492 -0
- package/dist/cli-learning/hook.d.ts +33 -0
- package/dist/cli-learning/hook.js +544 -0
- package/dist/cli-learning/install.d.ts +33 -0
- package/dist/cli-learning/install.js +335 -0
- package/dist/cli-learning/observation-proof.d.ts +14 -0
- package/dist/cli-learning/observation-proof.js +10 -0
- package/dist/cli-learning/policy.d.ts +48 -0
- package/dist/cli-learning/policy.js +363 -0
- package/dist/cli-learning/schema.d.ts +16 -0
- package/dist/cli-learning/schema.js +27 -0
- package/dist/cli-learning/state.d.ts +23 -0
- package/dist/cli-learning/state.js +61 -0
- package/dist/cli.js +24 -2
- package/dist/computer-setting.d.ts +8 -0
- package/dist/computer-setting.js +11 -0
- package/dist/computers.d.ts +6 -2
- package/dist/computers.js +2 -2
- package/dist/console/assets/index-B-D0EM3j.js +733 -0
- package/dist/console/assets/{index-D0mr9wfZ.css → index-DlQepP2J.css} +1 -1
- package/dist/console/index.html +2 -2
- package/dist/email/email-faux.d.ts +3 -1
- package/dist/email/email-faux.js +3 -2
- package/dist/email/routes.js +22 -12
- package/dist/fal-price.d.ts +76 -0
- package/dist/fal-price.js +368 -0
- package/dist/harness-install.d.ts +6 -2
- package/dist/harness-install.js +40 -8
- package/dist/harness.d.ts +1 -1
- package/dist/harness.js +2 -2
- package/dist/learn/commit.d.ts +5 -0
- package/dist/learn/commit.js +4 -1
- package/dist/learn/compile.d.ts +13 -5
- package/dist/learn/compile.js +24 -7
- package/dist/learn/delete.d.ts +12 -6
- package/dist/learn/delete.js +17 -11
- package/dist/learn/folder.d.ts +11 -0
- package/dist/learn/folder.js +20 -3
- package/dist/learn/learning-of.d.ts +8 -0
- package/dist/learn/learning-of.js +8 -0
- package/dist/learn/learning.sh +14 -1
- package/dist/learn/promote.d.ts +51 -7
- package/dist/learn/promote.js +51 -8
- package/dist/learn/secrets.js +14 -3
- package/dist/learning-reset.d.ts +18 -0
- package/dist/learning-reset.js +115 -0
- package/dist/learning-routes.d.ts +1 -1
- package/dist/learning-words.d.ts +6 -1
- package/dist/learning-words.js +6 -1
- package/dist/learning.d.ts +8 -6
- package/dist/learning.js +5 -4
- package/dist/llms.txt +1 -0
- package/dist/mcp-gateway.d.ts +39 -2
- package/dist/mcp-gateway.js +41 -10
- package/dist/mcp-pin-first.js +3 -2
- package/dist/mcp-private-hosts.d.ts +24 -3
- package/dist/mcp-private-hosts.js +53 -3
- package/dist/mcp-servers-store.d.ts +1 -0
- package/dist/mcp-servers-store.js +2 -1
- package/dist/media-duration.d.ts +2 -0
- package/dist/media-duration.js +136 -0
- package/dist/model-gateway.d.ts +2 -0
- package/dist/model-gateway.js +3 -1
- package/dist/native/runtimes.d.ts +2 -0
- package/dist/native/runtimes.js +2 -0
- package/dist/observation/learning.d.ts +32 -0
- package/dist/observation/learning.js +66 -0
- package/dist/observation/observer.d.ts +8 -1
- package/dist/observation/observer.js +89 -9
- package/dist/observation/schema.js +12 -4
- package/dist/observation/usage-identity.d.ts +9 -0
- package/dist/observation/usage-identity.js +11 -0
- package/dist/openapi.js +133 -24
- package/dist/provider.d.ts +8 -0
- package/dist/provider.js +14 -2
- package/dist/refusal-words.d.ts +0 -3
- package/dist/refusal-words.js +0 -3
- package/dist/request-metadata.d.ts +20 -0
- package/dist/request-metadata.js +24 -0
- package/dist/run-launch.d.ts +27 -4
- package/dist/run-launch.js +18 -3
- package/dist/run-learning-served.d.ts +2 -2
- package/dist/run-usage.d.ts +48 -4
- package/dist/run-usage.js +156 -39
- package/dist/run-view.d.ts +2 -0
- package/dist/run-view.js +8 -7
- package/dist/runner/adapter-loop.d.ts +3 -1
- package/dist/runner/adapter-loop.js +41 -35
- package/dist/runner/adapter-run-spec.d.ts +1 -1
- package/dist/runner/adapter-run-spec.js +15 -15
- package/dist/runner/audit.d.ts +8 -3
- package/dist/runner/audit.js +21 -6
- package/dist/runner/beside.d.ts +13 -0
- package/dist/runner/beside.js +27 -8
- package/dist/runner/claim-secrets.d.ts +2 -1
- package/dist/runner/claim-secrets.js +5 -3
- package/dist/runner/cli-run-spec.d.ts +1 -1
- package/dist/runner/cli-run-spec.js +14 -13
- package/dist/runner/conformance/harness.js +4 -2
- package/dist/runner/disk-free.d.ts +44 -0
- package/dist/runner/disk-free.js +96 -0
- package/dist/runner/dispatch.js +4 -2
- package/dist/runner/feedback-round.d.ts +12 -8
- package/dist/runner/feedback-round.js +16 -30
- package/dist/runner/harness-loops.js +8 -3
- package/dist/runner/journal-kinds.d.ts +4 -1
- package/dist/runner/learning-end.d.ts +2 -1
- package/dist/runner/learning-end.js +51 -22
- package/dist/runner/main.d.ts +17 -6
- package/dist/runner/main.js +187 -45
- package/dist/runner/mcp-claim.js +1 -1
- package/dist/runner/mcp-run.d.ts +9 -0
- package/dist/runner/mcp-run.js +16 -1
- package/dist/runner/model-route.js +7 -4
- package/dist/runner/presence.d.ts +11 -2
- package/dist/runner/presence.js +31 -3
- package/dist/runner/promotion.d.ts +40 -21
- package/dist/runner/promotion.js +130 -59
- package/dist/runner/run-child-host.d.ts +12 -15
- package/dist/runner/run-child-host.js +52 -112
- package/dist/runner/run-errors.js +2 -0
- package/dist/runner/runner-check.d.ts +51 -0
- package/dist/runner/runner-check.js +206 -0
- package/dist/runner/runner-metrics.d.ts +19 -0
- package/dist/runner/runner-metrics.js +49 -0
- package/dist/runner/runner.d.ts +37 -0
- package/dist/runner/runner.js +58 -6
- package/dist/runner/sdk-loop.d.ts +2 -2
- package/dist/runner/sdk-loop.js +37 -25
- package/dist/runner/store-port.d.ts +3 -0
- package/dist/runner/workflow-spec.js +3 -3
- package/dist/runs-over-store.d.ts +13 -3
- package/dist/runs-over-store.js +71 -16
- package/dist/sdk/check.d.ts +6 -5
- package/dist/sdk/check.js +17 -16
- package/dist/sdk/runs.d.ts +22 -2
- package/dist/sdk/runs.js +167 -82
- package/dist/server.d.ts +3 -0
- package/dist/server.js +230 -43
- package/dist/skills/agentrun-serve/SKILL.md +52 -7
- package/dist/start-switches.js +2 -0
- package/dist/stats.d.ts +4 -0
- package/dist/stats.js +1 -1
- package/dist/store/agent-body.d.ts +16 -0
- package/dist/store/agent-body.js +20 -3
- package/dist/store/dialect.d.ts +2 -0
- package/dist/store/dialect.js +1 -0
- package/dist/store/index.d.ts +3 -3
- package/dist/store/index.js +2 -2
- package/dist/store/journal/storage.d.ts +2 -0
- package/dist/store/journal/storage.js +2 -1
- package/dist/store/postgres/connection.d.ts +5 -2
- package/dist/store/postgres/connection.js +19 -7
- package/dist/store/postgres/dialect.js +1 -0
- package/dist/store/postgres/migrate.d.ts +30 -0
- package/dist/store/postgres/migrate.js +72 -5
- package/dist/store/postgres/migration-lint.d.ts +8 -0
- package/dist/store/postgres/migration-lint.js +119 -0
- package/dist/store/postgres/migrations/0024_runner_capacity.sql +28 -0
- package/dist/store/postgres/migrations/0025_run_attempts.sql +27 -0
- package/dist/store/postgres/migrations/0026_run_disk.sql +23 -0
- package/dist/store/postgres/store.d.ts +8 -3
- package/dist/store/postgres/store.js +31 -11
- package/dist/store/schema.d.ts +32 -2
- package/dist/store/schema.js +74 -5
- package/dist/store/sqlite/run-launch.d.ts +31 -1
- package/dist/store/sqlite/run-launch.js +111 -2
- package/dist/store/sqlite/run-patch.d.ts +2 -1
- package/dist/store/sqlite/run-patch.js +4 -3
- package/dist/store/sqlite/store.d.ts +17 -0
- package/dist/store/sqlite/store.js +226 -37
- package/dist/store/store-schema.d.ts +34 -0
- package/dist/store/store-schema.js +125 -0
- package/dist/store/store.d.ts +120 -5
- package/dist/store/store.js +13 -0
- package/dist/store-reads/analytics.d.ts +3 -2
- package/dist/store-reads/analytics.js +20 -8
- package/dist/store-reads/learning.d.ts +12 -8
- package/dist/store-reads/learning.js +33 -24
- package/dist/store-reads/loop.d.ts +4 -3
- package/dist/store-reads/loop.js +7 -5
- package/dist/store-view.d.ts +4 -3
- package/dist/store-view.js +11 -7
- package/dist/template-eval.js +4 -4
- package/dist/templates.d.ts +6 -2
- package/dist/templates.js +7 -5
- package/dist/timeline/labels.js +1 -1
- package/dist/tool-gate.d.ts +4 -2
- package/dist/tools.js +1 -1
- package/dist/unified-usage.d.ts +24 -0
- package/dist/unified-usage.js +400 -0
- package/dist/uploads-archil.d.ts +100 -0
- package/dist/uploads-archil.js +431 -0
- package/dist/uploads.d.ts +52 -1
- package/dist/uploads.js +186 -108
- package/dist/validate.js +5 -1
- package/dist/web-save.d.ts +3 -0
- package/dist/web-save.js +17 -2
- package/dist/workspace/archil-disk.d.ts +6 -5
- package/dist/workspace/archil-disk.js +27 -12
- package/dist/workspace/archil-exec.js +1 -1
- package/dist/workspace/archil.js +4 -3
- package/dist/workspace/revision-skills.js +24 -11
- package/dist/workspace/synced-folder.d.ts +3 -3
- package/dist/workspace/synced-folder.js +7 -6
- package/package.json +10 -10
- package/skills/agentrun-serve/SKILL.md +52 -7
- package/dist/console/assets/index-D7G6o-1E.js +0 -720
package/dist/run-usage.js
CHANGED
|
@@ -22,6 +22,13 @@
|
|
|
22
22
|
// run's ledger booked for it while a claim held it, so `total` stays the run's `cost.usd`. Time no claim held (a computer
|
|
23
23
|
// kept for a follow-up, one deleted after its run, one whose delete failed) is said apart (`unheld_quantity`) and costs
|
|
24
24
|
// nothing on the line or in `total`. A resource with no price is `unpriced`, its `usd` null.
|
|
25
|
+
//
|
|
26
|
+
// Each line is one attempt's (store run_attempts): a claim that was cut (its runner drained, crashed or lost its lease, or
|
|
27
|
+
// its turn was tried again) and whose turn another claim worked again made every request and paid call of it again. Its
|
|
28
|
+
// lines say so (`billable: false`, its `attempt` beside it), apart from the attempt that finished the turn, and the run's
|
|
29
|
+
// `infra_usd` is their sum: the cost of the infrastructure's own redo, not of the run's task. Data only: `total` and
|
|
30
|
+
// `cost.usd` still hold every line, billable or not, as the run was charged before. A run whose claims kept no attempt
|
|
31
|
+
// (one made before them) reads each line's `attempt` as null and every line billable.
|
|
25
32
|
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
26
33
|
import { RUNNER_RECORDS } from "@parcha/agentrun-kernel";
|
|
27
34
|
import { TOOL_SESSION } from "@parcha/agentrun-kernel/kernel/cap";
|
|
@@ -44,7 +51,8 @@ import { FINAL_STATES } from "./store/index.js";
|
|
|
44
51
|
import { COMPUTE_TOOL, COMPUTE_UNITS, computeTag, resourcesOf, unmetered } from "./compute-cost.js";
|
|
45
52
|
import { TOOL_UNMETERED } from "./timeline/index.js";
|
|
46
53
|
/** The run's computer rows as served (ComputerIntervalLine), in the order the store reads them (by when each was made). */
|
|
47
|
-
export function computerIntervalsOf(rows) {
|
|
54
|
+
export function computerIntervalsOf(rows, attempts = []) {
|
|
55
|
+
const tags = attemptTags(attempts);
|
|
48
56
|
return rows.map((row) => ({
|
|
49
57
|
provider: row.provider,
|
|
50
58
|
provider_id: row.providerId,
|
|
@@ -57,8 +65,55 @@ export function computerIntervalsOf(rows) {
|
|
|
57
65
|
ended_at: row.endedAt === null ? null : new Date(row.endedAt).toISOString(),
|
|
58
66
|
kept: row.kept,
|
|
59
67
|
booked_seconds: row.bookedMs / 1000,
|
|
68
|
+
...tags.atTime(row.startedAt),
|
|
60
69
|
}));
|
|
61
70
|
}
|
|
71
|
+
const NO_ATTEMPT = { attempt: null, billable: true };
|
|
72
|
+
/** A run's attempts (`rows`, by epoch) as tags: the attempt a journal entry was written in (the last claim whose first
|
|
73
|
+
* entry id is at or below the entry's), and the one a time falls in (the last claim made at or before it, on the
|
|
74
|
+
* store's clock: a computer is made a moment after its claim). `spans` splits a stretch of time across the claims whose
|
|
75
|
+
* windows it falls in (each claim's window runs from its claim to the next claim's). Every part is billable: a claim
|
|
76
|
+
* that takes over a cut turn resumes from what the cut one saved (its answered requests, its finished calls), so that
|
|
77
|
+
* work is the task's, done once. `redoneAt` is the one exception: the attempt an entry was written in, billable unless
|
|
78
|
+
* another claim worked its turn again after it (the same turn, one attempt more), for a model request that attempt sent
|
|
79
|
+
* and never finished (usageLinesOf), which the claim after it sends again. With no rows (a run from before
|
|
80
|
+
* them), every part is NO_ATTEMPT: attempt null, billable. A part before the first row is NO_ATTEMPT too, unless that
|
|
81
|
+
* row is the run's first claim (taken from queued): then nothing came before it, and a part read a moment early (a
|
|
82
|
+
* runner's clock behind the store's) is that claim's. A run that took its first row after the change that writes them
|
|
83
|
+
* (an older run's follow-up) never counts what it did before as any attempt's. */
|
|
84
|
+
export function attemptTags(rows) {
|
|
85
|
+
const sorted = [...rows].sort((a, b) => a.epoch - b.epoch);
|
|
86
|
+
const tagOf = (row) => (row === undefined ? NO_ATTEMPT : { attempt: row.attempt, billable: true });
|
|
87
|
+
const redoneOf = (row) => row === undefined ? NO_ATTEMPT : { attempt: row.attempt, billable: !sorted.some((later) => later.epoch > row.epoch && later.turn === row.turn && later.attempt === row.attempt + 1) };
|
|
88
|
+
const last = (fits) => sorted.filter(fits).at(-1);
|
|
89
|
+
const before = sorted[0]?.from === "queued" ? sorted[0] : undefined;
|
|
90
|
+
const entryRow = (id) => {
|
|
91
|
+
const n = Number(id);
|
|
92
|
+
return Number.isFinite(n) ? last((row) => row.journalFrom <= n) ?? before : sorted.at(-1);
|
|
93
|
+
};
|
|
94
|
+
return {
|
|
95
|
+
atEntry: (id) => tagOf(entryRow(id)),
|
|
96
|
+
redoneAt: (id) => redoneOf(entryRow(id)),
|
|
97
|
+
atTime: (ms) => tagOf(last((row) => row.claimedAt <= ms) ?? before),
|
|
98
|
+
spans: (from, to) => {
|
|
99
|
+
if (!(to > from))
|
|
100
|
+
return [{ at: tagOf(last((row) => row.claimedAt <= from) ?? before), ms: 0 }];
|
|
101
|
+
const out = [];
|
|
102
|
+
// The edges of each claim's window, the first one's reaching back to `from` when it is the run's first claim.
|
|
103
|
+
const edges = sorted.map((row, i) => ({ row, start: i === 0 && before ? Number.NEGATIVE_INFINITY : row.claimedAt, end: sorted[i + 1]?.claimedAt ?? Number.POSITIVE_INFINITY }));
|
|
104
|
+
const firstStart = edges[0]?.start ?? Number.POSITIVE_INFINITY;
|
|
105
|
+
if (from < firstStart)
|
|
106
|
+
out.push({ at: NO_ATTEMPT, ms: Math.min(to, firstStart) - from });
|
|
107
|
+
for (const edge of edges) {
|
|
108
|
+
const ms = Math.min(to, edge.end) - Math.max(from, edge.start);
|
|
109
|
+
if (ms > 0)
|
|
110
|
+
out.push({ at: tagOf(edge.row), ms });
|
|
111
|
+
}
|
|
112
|
+
return out;
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
const attemptKey = (at) => `${at.attempt ?? ""}:${at.billable ? 1 : 0}`;
|
|
62
117
|
/** `entries` with the run's booked requests (runner.request and runner.turn) left in only where `keep` says so of its
|
|
63
118
|
* turn; every other entry (each session's key among them) kept, so bookedSpend reads that part alone. */
|
|
64
119
|
function onlyRequests(entries, turnOf, keep) {
|
|
@@ -96,14 +151,42 @@ function upstreamOf(model, launch) {
|
|
|
96
151
|
* provider (`browser_time`); and their join, `total`. A meter with nothing booked has no line. `launch` names the
|
|
97
152
|
* run's own model's provider; `receipts`, a workflow's decisions by id, the model and provider each was answered on
|
|
98
153
|
* (its booking names the decision alone), which this server called itself. */
|
|
99
|
-
export function usageLinesOf(entries, launch, receipts = new Map(), computers = { rows: [], at: 0 }) {
|
|
154
|
+
export function usageLinesOf(entries, launch, receipts = new Map(), computers = { rows: [], at: 0 }, attempts = []) {
|
|
100
155
|
const conversation = (key) => entries.find((e) => e.kind === KINDS.sessionKey && e.data?.key === key)?.data;
|
|
101
156
|
const paidConv = Number(conversation(TOOL_SESSION)?.conversation ?? Number.NaN);
|
|
102
157
|
const conv = (e) => Number(e.conversationId);
|
|
103
158
|
const turnOf = (e) => `${String(e.conversationId)}:${String(e.data?.turn)}`;
|
|
104
159
|
// A line is one meter, one name and, on `tokens`, one route: a model reached two ways (the run's own requests behind a
|
|
105
160
|
// gateway, a decision on its provider) is two lines, never one labelled with either's provider.
|
|
106
|
-
const keyOf = (group) => `${group.meter}\u0000${group.name ?? ""}\u0000${group.provider ?? ""}\u0000${group.tag ?? ""}`;
|
|
161
|
+
const keyOf = (group) => `${group.meter}\u0000${group.name ?? ""}\u0000${group.provider ?? ""}\u0000${group.tag ?? ""}\u0000${attemptKey(group.at)}`;
|
|
162
|
+
// Each booked request's attempt: the claim that wrote its first record (its hold, or its booking), never a later
|
|
163
|
+
// claim's settling of it.
|
|
164
|
+
const tags = attemptTags(attempts);
|
|
165
|
+
// A browser charge is the attempt's whose claim wrote it on the root (BROWSER_CHARGED), even when its booking landed
|
|
166
|
+
// under a later claim (browser-cost.ts bookRootCharges books one its process lost): the booking names it by its ref.
|
|
167
|
+
const chargeAt = new Map();
|
|
168
|
+
for (const e of entries) {
|
|
169
|
+
const d = (e.data ?? {});
|
|
170
|
+
if (e.kind === BROWSER_CHARGED && typeof d.tag === "string")
|
|
171
|
+
chargeAt.set(`browser:${d.tag}@${String(d.at)}${d.final ? "/final" : ""}`, tags.atEntry(e.id));
|
|
172
|
+
}
|
|
173
|
+
// A model request its attempt sent and never finished: no answer booked (a crash cut it off), or booked as cut (a stop
|
|
174
|
+
// cut it, at its hold). The claim that takes the turn over sends it again, so when a later claim redid that turn it is
|
|
175
|
+
// the infrastructure's (redoneAt). An answered request, and every paid call, is the task's: the next claim reuses it.
|
|
176
|
+
const answered = new Set();
|
|
177
|
+
for (const e of entries) {
|
|
178
|
+
if (e.kind === RUNNER_RECORDS.turn && e.data?.cut !== true)
|
|
179
|
+
answered.add(turnOf(e));
|
|
180
|
+
}
|
|
181
|
+
const unfinished = (e) => conv(e) !== paidConv && !answered.has(turnOf(e));
|
|
182
|
+
const atOf = new Map();
|
|
183
|
+
for (const e of entries) {
|
|
184
|
+
if (!(e.kind === RUNNER_RECORDS.request || e.kind === RUNNER_RECORDS.turn) || atOf.has(turnOf(e)))
|
|
185
|
+
continue;
|
|
186
|
+
const ref = e.data?.ref;
|
|
187
|
+
atOf.set(turnOf(e), (typeof ref === "string" ? chargeAt.get(ref) : undefined) ?? (unfinished(e) ? tags.redoneAt(e.id) : tags.atEntry(e.id)));
|
|
188
|
+
}
|
|
189
|
+
const at = (e) => atOf.get(turnOf(e)) ?? tags.atEntry(e.id);
|
|
107
190
|
// Each booked request's group, by its turn: a model request's or a decision's, the model its runner.request was sent on;
|
|
108
191
|
// a paid charge's, who charged for it (`charged_by`), on browser_time when it is the browser's session time. A paid
|
|
109
192
|
// charge settled at its provider's own figure says so on its request (`reported`). A decision's request names the
|
|
@@ -121,15 +204,15 @@ export function usageLinesOf(entries, launch, receipts = new Map(), computers =
|
|
|
121
204
|
const d = (e.data ?? {});
|
|
122
205
|
// A computer's time (compute-cost.ts) by its provider and resource (its tag); a browser's by its provider.
|
|
123
206
|
if (conv(e) === paidConv)
|
|
124
|
-
groups.set(turnOf(e), d.tool === COMPUTE_TOOL ? { meter: "compute_time", name: named(d.charged_by), tag: named(d.tag) } : { meter: d.tool === "browser" ? "browser_time" : "tools", name: named(d.charged_by) });
|
|
207
|
+
groups.set(turnOf(e), d.tool === COMPUTE_TOOL ? { meter: "compute_time", name: named(d.charged_by), tag: named(d.tag), at: at(e) } : { meter: d.tool === "browser" ? "browser_time" : "tools", name: named(d.charged_by), at: at(e) });
|
|
125
208
|
else if (named(d.model)?.startsWith("decision:")) {
|
|
126
209
|
const receipt = receipts.get(String(d.model).slice("decision:".length));
|
|
127
210
|
if (receipt && chargedByParallel(receipt)) {
|
|
128
|
-
groups.set(turnOf(e), { meter: "tools", name: PARALLEL_CHARGER });
|
|
211
|
+
groups.set(turnOf(e), { meter: "tools", name: PARALLEL_CHARGER, at: at(e) });
|
|
129
212
|
continue;
|
|
130
213
|
}
|
|
131
214
|
// A receipt that names no model leaves `model` null: its provider is said as the provider, never as a model.
|
|
132
|
-
groups.set(turnOf(e), receipt ? { meter: "tokens", name: named(receipt.model), provider: named(receipt.provider) } : { meter: "tokens", name: null, provider: null });
|
|
215
|
+
groups.set(turnOf(e), receipt ? { meter: "tokens", name: named(receipt.model), provider: named(receipt.provider), at: at(e) } : { meter: "tokens", name: null, provider: null, at: at(e) });
|
|
133
216
|
if (receipt?.cost_basis === "reported")
|
|
134
217
|
reported.add(turnOf(e));
|
|
135
218
|
else if (receipt?.cost_basis === "estimate")
|
|
@@ -141,7 +224,7 @@ export function usageLinesOf(entries, launch, receipts = new Map(), computers =
|
|
|
141
224
|
decisionTokens.set(turnOf(e), { input, output });
|
|
142
225
|
}
|
|
143
226
|
else
|
|
144
|
-
groups.set(turnOf(e), { meter: "tokens", name: named(d.model), provider: upstreamOf(named(d.model), launch) });
|
|
227
|
+
groups.set(turnOf(e), { meter: "tokens", name: named(d.model), provider: upstreamOf(named(d.model), launch), at: at(e) });
|
|
145
228
|
if (d.reported === true)
|
|
146
229
|
reported.add(turnOf(e));
|
|
147
230
|
}
|
|
@@ -155,7 +238,7 @@ export function usageLinesOf(entries, launch, receipts = new Map(), computers =
|
|
|
155
238
|
for (const e of entries) {
|
|
156
239
|
if (e.kind !== RUNNER_RECORDS.request && e.kind !== RUNNER_RECORDS.turn)
|
|
157
240
|
continue;
|
|
158
|
-
const group = groups.get(turnOf(e)) ?? (conv(e) === paidConv ? { meter: "tools", name: null } : { meter: "tokens", name: null, provider: null });
|
|
241
|
+
const group = groups.get(turnOf(e)) ?? (conv(e) === paidConv ? { meter: "tools", name: null, at: at(e) } : { meter: "tokens", name: null, provider: null, at: at(e) });
|
|
159
242
|
if (!found.has(keyOf(group)))
|
|
160
243
|
found.set(keyOf(group), group);
|
|
161
244
|
turnKeys.set(turnOf(e), keyOf(group));
|
|
@@ -174,7 +257,7 @@ export function usageLinesOf(entries, launch, receipts = new Map(), computers =
|
|
|
174
257
|
for (const e of entries) {
|
|
175
258
|
const d = (e.data ?? {});
|
|
176
259
|
if (e.kind === TOOL_UNMETERED) {
|
|
177
|
-
const group = { meter: "tools", name: named(d.charged_by) };
|
|
260
|
+
const group = { meter: "tools", name: named(d.charged_by), at: tags.atEntry(e.id) };
|
|
178
261
|
unpricedCalls.set(keyOf(group), (unpricedCalls.get(keyOf(group)) ?? 0) + 1);
|
|
179
262
|
if (!found.has(keyOf(group)))
|
|
180
263
|
found.set(keyOf(group), group);
|
|
@@ -182,7 +265,7 @@ export function usageLinesOf(entries, launch, receipts = new Map(), computers =
|
|
|
182
265
|
}
|
|
183
266
|
if (e.kind !== BROWSER_CHARGED || d.tool !== "browser" || typeof d.seconds !== "number" || !Number.isFinite(d.seconds))
|
|
184
267
|
continue;
|
|
185
|
-
const group = { meter: "browser_time", name: named(d.charged_by) };
|
|
268
|
+
const group = { meter: "browser_time", name: named(d.charged_by), at: tags.atEntry(e.id) };
|
|
186
269
|
seconds.set(keyOf(group), (seconds.get(keyOf(group)) ?? 0) + d.seconds);
|
|
187
270
|
if (!found.has(keyOf(group)))
|
|
188
271
|
found.set(keyOf(group), group);
|
|
@@ -198,7 +281,7 @@ export function usageLinesOf(entries, launch, receipts = new Map(), computers =
|
|
|
198
281
|
if (group.meter === "compute_time") {
|
|
199
282
|
// A hold for a stretch names no resource (no tag) and books nothing: it is given back.
|
|
200
283
|
if (group.tag !== null && group.tag !== undefined)
|
|
201
|
-
computeBooked.set(computeKey(group.name ?? "", group.tag), booked);
|
|
284
|
+
computeBooked.set(computeKey(group.name ?? "", group.tag, group.at), { booked, at: group.at });
|
|
202
285
|
continue;
|
|
203
286
|
}
|
|
204
287
|
const notMetered = unpricedCalls.get(key);
|
|
@@ -216,7 +299,7 @@ export function usageLinesOf(entries, launch, receipts = new Map(), computers =
|
|
|
216
299
|
const unmetered = Math.max(0, booked.unmetered - told.filter((turn) => noUsage.has(turn)).length);
|
|
217
300
|
// A decision's booking keeps no price table's mark: its receipt says how its cost was reached.
|
|
218
301
|
const priced = { reported: booked.priced.reported + turns.filter((turn) => reported.has(turn)).length, estimated: booked.priced.estimated + turns.filter((turn) => estimated.has(turn)).length };
|
|
219
|
-
lines.push({ meter: "tokens", model: group.name, provider: group.provider ?? null, charged_by: null, quantity: input + output + cacheRead + cacheWrite, unit: "token", basis: costBasisOf({ priced }), ...costWordsOf(booked.parts), requests: booked.requests, tokens: { input, output, cache_read: cacheRead, cache_write: cacheWrite }, unmetered_requests: unmetered });
|
|
302
|
+
lines.push({ meter: "tokens", model: group.name, provider: group.provider ?? null, charged_by: null, quantity: input + output + cacheRead + cacheWrite, unit: "token", basis: costBasisOf({ priced }), ...group.at, ...costWordsOf(booked.parts), requests: booked.requests, tokens: { input, output, cache_read: cacheRead, cache_write: cacheWrite }, unmetered_requests: unmetered });
|
|
220
303
|
}
|
|
221
304
|
else if (group.meter === "tools") {
|
|
222
305
|
// `reported` when every charge with a figure was settled at its provider's own (monid's answer says what it
|
|
@@ -225,7 +308,7 @@ export function usageLinesOf(entries, launch, receipts = new Map(), computers =
|
|
|
225
308
|
const basis = priced <= 0 ? "unpriced" : turns.every((turn) => reported.has(turn)) ? "reported" : "estimate";
|
|
226
309
|
// Calls that ran unpriced only: none booked, so nothing is charged on the line, by its owner's choice of no price.
|
|
227
310
|
const words = booked.requests === 0 ? { usd: 0 } : costWordsOf(booked.parts);
|
|
228
|
-
lines.push({ meter: "tools", model: null, provider: group.name, charged_by: group.name, quantity: booked.requests, unit: "call", basis, ...words, ...(notMetered ? { not_metered_calls: notMetered } : {}) });
|
|
311
|
+
lines.push({ meter: "tools", model: null, provider: group.name, charged_by: group.name, quantity: booked.requests, unit: "call", basis, ...group.at, ...words, ...(notMetered ? { not_metered_calls: notMetered } : {}) });
|
|
229
312
|
}
|
|
230
313
|
else {
|
|
231
314
|
const s = seconds.get(key);
|
|
@@ -235,10 +318,10 @@ export function usageLinesOf(entries, launch, receipts = new Map(), computers =
|
|
|
235
318
|
continue;
|
|
236
319
|
// A browser provider whose time no charge booked (none, or each given back) still ran: its seconds with no figure.
|
|
237
320
|
const words = booked.requests === 0 ? { usd: null } : costWordsOf(booked.parts);
|
|
238
|
-
lines.push({ meter: "browser_time", model: null, provider: group.name, charged_by: null, quantity: s === undefined ? null : Math.round(s * 1e6) / 1e6, unit: "second", basis: priced > 0 ? "estimate" : "unpriced", ...words });
|
|
321
|
+
lines.push({ meter: "browser_time", model: null, provider: group.name, charged_by: null, quantity: s === undefined ? null : Math.round(s * 1e6) / 1e6, unit: "second", basis: priced > 0 ? "estimate" : "unpriced", ...group.at, ...words });
|
|
239
322
|
}
|
|
240
323
|
}
|
|
241
|
-
lines.push(...computeLinesOf(computers.rows, computers.at, computeBooked));
|
|
324
|
+
lines.push(...computeLinesOf(computers.rows, computers.at, computeBooked, tags.spans));
|
|
242
325
|
// Each meter by its name (a model, a charger, a browser provider; none first), `tokens` then by its route's provider,
|
|
243
326
|
// `compute_time` then by its resource in compute-cost.ts's order and a GPU's type.
|
|
244
327
|
const sortKey = (line) => line.meter === "tokens"
|
|
@@ -248,7 +331,9 @@ export function usageLinesOf(entries, launch, receipts = new Map(), computers =
|
|
|
248
331
|
: line.meter === "compute_time"
|
|
249
332
|
? `${line.provider ?? ""}\u0000${RESOURCE_ORDER[line.resource ?? "vcpu"]}\u0000${line.gpu_type ?? ""}`
|
|
250
333
|
: line.provider ?? "";
|
|
251
|
-
|
|
334
|
+
// Then by attempt, a line of no attempt first, and a cut attempt's before the billable one of the same number.
|
|
335
|
+
const attemptOrder = (line) => (line.attempt ?? 0) * 2 + (line.billable ? 1 : 0);
|
|
336
|
+
lines.sort((a, b) => ORDER[a.meter] - ORDER[b.meter] || (sortKey(a) < sortKey(b) ? -1 : sortKey(a) > sortKey(b) ? 1 : 0) || attemptOrder(a) - attemptOrder(b));
|
|
252
337
|
// The join over the whole booking, never the lines' rounded figures: the same figure cost.usd is. A browser line whose
|
|
253
338
|
// time no charge booked is unknown beside it: the total is too, with the booking's figure as what is known.
|
|
254
339
|
const total = costWordsOf([bookedSpend(entries, "model"), bookedSpend(entries, "paid"), bookedSpend(entries, "decisions")]);
|
|
@@ -258,8 +343,8 @@ export function usageLinesOf(entries, launch, receipts = new Map(), computers =
|
|
|
258
343
|
const known = total.usd ?? total.so_far_usd ?? 0;
|
|
259
344
|
return { lines, total: { usd: null, so_far_usd: known, unpriced: (total.usd === null ? (total.unpriced ?? 0) : 0) + unbooked } };
|
|
260
345
|
}
|
|
261
|
-
/** A compute line's key: its provider
|
|
262
|
-
const computeKey = (provider, tag) => `${provider}\u0000${tag}`;
|
|
346
|
+
/** A compute line's key: its provider, its resource's tag (computeTag) and its attempt. */
|
|
347
|
+
const computeKey = (provider, tag, at) => `${provider}\u0000${tag}\u0000${attemptKey(at)}`;
|
|
263
348
|
const RESOURCE_ORDER = { vcpu: 0, memory: 1, gpu: 2, disk: 3 };
|
|
264
349
|
/** Up to the millionth, as the browser's seconds are. */
|
|
265
350
|
const micro = (value) => Math.round(value * 1e6) / 1e6;
|
|
@@ -267,23 +352,32 @@ const micro = (value) => Math.round(value * 1e6) / 1e6;
|
|
|
267
352
|
* its figure, an open one's up to `at` (the read), and the part no claim held (its life less its booked time) apart in
|
|
268
353
|
* `unheld_quantity`. Its money is what the run's ledger booked for it (`booked`, by computeKey): `estimate` when any was;
|
|
269
354
|
* $0 for a provider that bills nothing; else `unpriced`, its usd null. A figure no one said makes its quantity null. */
|
|
270
|
-
function computeLinesOf(rows, at, booked) {
|
|
355
|
+
function computeLinesOf(rows, at, booked, spans) {
|
|
271
356
|
const sums = new Map();
|
|
272
357
|
for (const row of rows) {
|
|
273
|
-
const
|
|
358
|
+
const end = row.endedAt ?? at;
|
|
359
|
+
const livedS = Math.max(0, end - row.startedAt) / 1000;
|
|
274
360
|
const unheldS = Math.max(0, livedS - row.bookedMs / 1000);
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
361
|
+
// Its time is the claims' that held it, by each claim's window (a computer kept across a park is billed by the claim
|
|
362
|
+
// that resumed it), so each stretch sits with the attempt whose bookings paid for it. The part no claim held is kept
|
|
363
|
+
// per computer alone: it is spread over the windows by their share of its life.
|
|
364
|
+
const pieces = spans(row.startedAt, end);
|
|
365
|
+
for (const span of pieces) {
|
|
366
|
+
const share = livedS > 0 ? span.ms / 1000 / livedS : 1;
|
|
367
|
+
for (const one of resourcesOf(row)) {
|
|
368
|
+
const key = computeKey(row.provider, computeTag(one), span.at);
|
|
369
|
+
const sum = sums.get(key) ?? { provider: row.provider, resource: one.resource, gpuType: one.gpuType, quantity: 0, unheld: 0, open: 0, at: span.at };
|
|
370
|
+
sum.quantity = sum.quantity === null || one.perSecond === null ? null : sum.quantity + one.perSecond * (span.ms / 1000);
|
|
371
|
+
sum.unheld = sum.unheld === null || one.perSecond === null ? null : sum.unheld + one.perSecond * unheldS * share;
|
|
372
|
+
// An open computer counts once, on the line of the window it is in now.
|
|
373
|
+
if (row.endedAt === null && span === pieces.at(-1))
|
|
374
|
+
sum.open += 1;
|
|
375
|
+
sums.set(key, sum);
|
|
376
|
+
}
|
|
283
377
|
}
|
|
284
378
|
}
|
|
285
379
|
// A booking whose computer has no row here (one made before this server kept them): its money, with no quantity.
|
|
286
|
-
for (const key of booked
|
|
380
|
+
for (const [key, one] of booked) {
|
|
287
381
|
if (sums.has(key))
|
|
288
382
|
continue;
|
|
289
383
|
const [provider = "", tag = ""] = key.split("\u0000");
|
|
@@ -291,16 +385,16 @@ function computeLinesOf(rows, at, booked) {
|
|
|
291
385
|
const resource = (gpu ? "gpu" : tag);
|
|
292
386
|
if (!Object.hasOwn(COMPUTE_UNITS, resource))
|
|
293
387
|
continue;
|
|
294
|
-
sums.set(key, { provider, resource, gpuType: gpu ? tag.slice("gpu:".length) : null, quantity: null, unheld: null, open: 0 });
|
|
388
|
+
sums.set(key, { provider, resource, gpuType: gpu ? tag.slice("gpu:".length) : null, quantity: null, unheld: null, open: 0, at: one.at });
|
|
295
389
|
}
|
|
296
390
|
return [...sums.entries()].map(([key, sum]) => {
|
|
297
|
-
const spend = booked.get(key);
|
|
391
|
+
const spend = booked.get(key)?.booked;
|
|
298
392
|
const charged = spend !== undefined && spend.requests > 0;
|
|
299
393
|
const free = !charged && unmetered(sum.provider);
|
|
300
394
|
const words = charged ? costWordsOf(spend.parts) : free ? { usd: 0 } : { usd: null };
|
|
301
395
|
return {
|
|
302
396
|
meter: "compute_time", model: null, provider: sum.provider, charged_by: sum.provider,
|
|
303
|
-
quantity: sum.quantity === null ? null : micro(sum.quantity), unit: COMPUTE_UNITS[sum.resource], basis: charged || free ? "estimate" : "unpriced", ...words,
|
|
397
|
+
quantity: sum.quantity === null ? null : micro(sum.quantity), unit: COMPUTE_UNITS[sum.resource], basis: charged || free ? "estimate" : "unpriced", ...sum.at, ...words,
|
|
304
398
|
resource: sum.resource, gpu_type: sum.gpuType, unheld_quantity: sum.unheld === null ? null : micro(sum.unheld), open_computers: sum.open,
|
|
305
399
|
...(sum.open > 0 ? { measured_to: new Date(at).toISOString() } : {}),
|
|
306
400
|
};
|
|
@@ -310,16 +404,37 @@ function computeLinesOf(rows, at, booked) {
|
|
|
310
404
|
* turn), each with its end read from the whole journal (`all`). The run's end lets its browsers go inside the learning
|
|
311
405
|
* turn's range (reflectRanges runs to the run's end), so an end read from `job` alone would be missing for a session
|
|
312
406
|
* released there. A session the learning turn opened is not the job's, as its cost is not. */
|
|
313
|
-
function jobSessions(job, all) {
|
|
407
|
+
function jobSessions(job, all, attempts = []) {
|
|
314
408
|
const ends = new Map(browserSessionsOf(all).map((one) => [one.tag, one]));
|
|
409
|
+
// A session is the attempt's whose claim first wrote of it (its open, else its first charge).
|
|
410
|
+
const tags = attemptTags(attempts);
|
|
411
|
+
const first = new Map();
|
|
412
|
+
for (const e of job) {
|
|
413
|
+
const tag = e.data?.tag;
|
|
414
|
+
if (typeof tag === "string" && !first.has(tag))
|
|
415
|
+
first.set(tag, tags.atEntry(e.id));
|
|
416
|
+
}
|
|
315
417
|
return browserSessionsOf(job).map((one) => {
|
|
418
|
+
const at = first.get(one.tag) ?? NO_ATTEMPT;
|
|
316
419
|
const whole = ends.get(one.tag);
|
|
317
420
|
if (one.ended_at !== null || !whole || whole.ended_at === null)
|
|
318
|
-
return one;
|
|
421
|
+
return { ...one, ...at };
|
|
319
422
|
const { provider_session_id, started_at, ended_at, release_reason, provider_record, provider_record_status } = whole;
|
|
320
|
-
return { ...one, provider: one.provider || whole.provider, provider_session_id, started_at, ended_at, release_reason, provider_record, provider_record_status };
|
|
423
|
+
return { ...one, provider: one.provider || whole.provider, provider_session_id, started_at, ended_at, release_reason, provider_record, provider_record_status, ...at };
|
|
321
424
|
});
|
|
322
425
|
}
|
|
426
|
+
/** The sum of the lines no customer is charged for (`billable: false`): null when one of them has no known figure. */
|
|
427
|
+
export function infraUsdOf(lines) {
|
|
428
|
+
let sum = 0;
|
|
429
|
+
for (const line of lines) {
|
|
430
|
+
if (line.billable)
|
|
431
|
+
continue;
|
|
432
|
+
if (line.usd === null)
|
|
433
|
+
return null;
|
|
434
|
+
sum += line.usd;
|
|
435
|
+
}
|
|
436
|
+
return Math.round(sum * 1e12) / 1e12;
|
|
437
|
+
}
|
|
323
438
|
/** Run `runId`'s usage lines (GET /runs/{run_id}/usage); undefined for an unknown run. No lines (`reason`) while it is at
|
|
324
439
|
* work, for a run whose figure is not its booking's, and for a learning run a follow-up opened again: the cases where
|
|
325
440
|
* `cost.tools_usd` is null for the same reasons. Its state, launch, learning rounds and journal are read in one snapshot
|
|
@@ -330,7 +445,7 @@ export async function runUsageOverStore(store, runId) {
|
|
|
330
445
|
if (!run)
|
|
331
446
|
return undefined;
|
|
332
447
|
const ended = FINAL_STATES.includes(run.state) && run.endedAt !== null ? new Date(run.endedAt).toISOString() : null;
|
|
333
|
-
const none = (reason) => ({ run_id: runId, ended_at: reason === "running" ? null : ended, currency: "USD", total: null, lines: null, browser_sessions: null, computer_intervals: null, reason });
|
|
448
|
+
const none = (reason) => ({ run_id: runId, ended_at: reason === "running" ? null : ended, currency: "USD", total: null, lines: null, browser_sessions: null, computer_intervals: null, infra_usd: null, reason });
|
|
334
449
|
if (!FINAL_STATES.includes(run.state))
|
|
335
450
|
return none("running");
|
|
336
451
|
const launch = await launchOf(snapshot, runId);
|
|
@@ -348,9 +463,11 @@ export async function runUsageOverStore(store, runId) {
|
|
|
348
463
|
// Its computers in the same snapshot, an open one's time counted up to now; a store that keeps none (a test's) reads
|
|
349
464
|
// as none made.
|
|
350
465
|
const rows = snapshot.computerIntervals ? await snapshot.computerIntervals.forRun(runId) : [];
|
|
351
|
-
|
|
352
|
-
const
|
|
353
|
-
|
|
466
|
+
// Its claims' attempts in the same snapshot; a store that keeps none (a test's) reads as a run of no attempts.
|
|
467
|
+
const attempts = snapshot.runAttempts ? await snapshot.runAttempts.forRun(runId) : [];
|
|
468
|
+
const { lines, total } = usageLinesOf(entries, launch, receipts, { rows, at: Date.now() }, attempts);
|
|
469
|
+
const computers = computerIntervalsOf(rows, attempts);
|
|
470
|
+
return { run_id: runId, ended_at: ended, currency: "USD", total, lines, browser_sessions: jobSessions(entries, records.entries, attempts), computer_intervals: computers, infra_usd: infraUsdOf(lines), reason: null };
|
|
354
471
|
});
|
|
355
472
|
}
|
|
356
473
|
/** Run `runId`'s usage lines as served: each name taken from its record (a model, its provider, a tool's charger) through
|
package/dist/run-view.d.ts
CHANGED
|
@@ -55,11 +55,13 @@ export type Status = "queued" | "working" | "paused" | "input_required" | "compl
|
|
|
55
55
|
export type State = "working" | "waiting" | "idle";
|
|
56
56
|
/** A tool call that waited for a person's approval, as the run's store has it (tool-gate.ts): `resolved` once the run's
|
|
57
57
|
* process acted on the answer. */
|
|
58
|
+
/** `asks_because`: why the gate asked a call its setting allows (its ask's own `because`, never one of the call's arguments). */
|
|
58
59
|
export type Approval = {
|
|
59
60
|
id: string;
|
|
60
61
|
tool: string;
|
|
61
62
|
call_id: string;
|
|
62
63
|
args_json: string;
|
|
64
|
+
asks_because?: string;
|
|
63
65
|
requested_at: string;
|
|
64
66
|
price?: ApprovalPrice;
|
|
65
67
|
destructive?: true;
|
package/dist/run-view.js
CHANGED
|
@@ -17,7 +17,7 @@ import { pointerHash } from "./sign-ins-store.js";
|
|
|
17
17
|
import { MIN_SECRET } from "./learn/secrets.js";
|
|
18
18
|
import { costWordsOf, usageParts } from "./runner/metrics.js";
|
|
19
19
|
import { KINDS } from "./runner/journal-kinds.js";
|
|
20
|
-
import {
|
|
20
|
+
import { ENDED_WHILE_WAITING, STOPPED_WHILE_WAITING } from "./refusal-words.js";
|
|
21
21
|
/** The run's newest usage row, which carries its cost. */
|
|
22
22
|
const usageOf = (rows) => rows.findLast((r) => r.kind === "usage");
|
|
23
23
|
/** The run's cost from its usage row: null when a response's cost is unknown, 0 before any request. */
|
|
@@ -140,6 +140,7 @@ export function asksOf(entries) {
|
|
|
140
140
|
tool: d.tool,
|
|
141
141
|
call_id: d.callId,
|
|
142
142
|
args_json: JSON.stringify(d.args ?? {}) ?? "{}",
|
|
143
|
+
...(typeof d.because === "string" ? { asks_because: d.because } : {}),
|
|
143
144
|
requested_at: d.requestedAt,
|
|
144
145
|
...(price !== undefined ? { price } : {}),
|
|
145
146
|
...(d.destructive === true ? { destructive: true } : {}),
|
|
@@ -372,10 +373,11 @@ export const pendingOf = (rows) => {
|
|
|
372
373
|
return last?.kind === "waiting" ? { kind: "question", question: last.text ?? last.summary ?? "", asked_at: last.timestamp } : null;
|
|
373
374
|
};
|
|
374
375
|
/** The run's pending approval (`pending`, kind approval): the call that waits; else undefined. */
|
|
375
|
-
/** A call's approval summary, where its tool has one (tools.ts ToolEntry.approvalSummary),
|
|
376
|
-
* asked about it itself (the card's ASKED_BECAUSE, the gate's), redacted as its arguments are. */
|
|
376
|
+
/** A call's approval summary, where its tool has one (tools.ts ToolEntry.approvalSummary), redacted as its arguments are. */
|
|
377
377
|
function summaryOf(approval, redact) {
|
|
378
378
|
const summarize = toolOf(approval.tool)?.approvalSummary;
|
|
379
|
+
if (!summarize)
|
|
380
|
+
return {};
|
|
379
381
|
let args;
|
|
380
382
|
try {
|
|
381
383
|
args = JSON.parse(approval.args_json);
|
|
@@ -383,13 +385,12 @@ function summaryOf(approval, redact) {
|
|
|
383
385
|
catch {
|
|
384
386
|
return {};
|
|
385
387
|
}
|
|
386
|
-
const
|
|
387
|
-
|
|
388
|
-
return parts.length ? { summary: redact(parts.join("\n\n")) } : {};
|
|
388
|
+
const summary = summarize(args);
|
|
389
|
+
return summary === undefined ? {} : { summary: redact(summary) };
|
|
389
390
|
}
|
|
390
391
|
export const approvalOf = (run, redact) => {
|
|
391
392
|
const waiting = waitingApproval(run);
|
|
392
|
-
return waiting ? { kind: "approval", id: waiting.id, tool: waiting.tool, call_id: waiting.call_id, args_preview: shownArgs(waiting, redact), ...summaryOf(waiting, redact), requested_at: waiting.requested_at, ...(waiting.price !== undefined ? { price: waiting.price } : {}), ...(waiting.destructive ? { destructive: true } : {}) } : undefined;
|
|
393
|
+
return waiting ? { kind: "approval", id: waiting.id, tool: waiting.tool, call_id: waiting.call_id, args_preview: shownArgs(waiting, redact), ...summaryOf(waiting, redact), ...(waiting.asks_because !== undefined ? { asks_because: redact(waiting.asks_because) } : {}), requested_at: waiting.requested_at, ...(waiting.price !== undefined ? { price: waiting.price } : {}), ...(waiting.destructive ? { destructive: true } : {}) } : undefined;
|
|
393
394
|
};
|
|
394
395
|
/** A run whose agent asked for the person in its browser waits on their hand-back: what it asked them to do, when it is
|
|
395
396
|
* done, and when the ask expires. Never the session's tag or the live view's link. The two texts are the model's, so
|
|
@@ -56,11 +56,13 @@ export type RaiseCheck = {
|
|
|
56
56
|
retry?: undefined;
|
|
57
57
|
};
|
|
58
58
|
/** The gate's answer for a call: run it, ask a person (`ask` with fields its card shows before the call's input: a
|
|
59
|
-
* learned workflow's MCP actions
|
|
59
|
+
* learned workflow's MCP actions; `because`, why a call its setting allows asks anyway, its ask's own field and never
|
|
60
|
+
* one of the call's arguments), or refuse it (with the words the model reads, or generic ones). */
|
|
60
61
|
export type GateAnswer = "allow" | "ask" | "deny" | {
|
|
61
62
|
readonly deny: string;
|
|
62
63
|
} | {
|
|
63
64
|
readonly ask: Readonly<Record<string, unknown>>;
|
|
65
|
+
readonly because?: string;
|
|
64
66
|
};
|
|
65
67
|
/** The gate before a call's intent; `askedAs`, when it has one, names a call as a person is asked about it (its settings
|
|
66
68
|
* key, as main's pending approval names it), else the call is asked about by its own name. `replayed`: asked again for a
|