@parcha/agentrun-serve 0.1.0-beta.49 → 0.1.0-beta.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +173 -9
- package/README.md +246 -39
- package/dist/agent-delete.d.ts +3 -2
- package/dist/agent-delete.js +29 -4
- package/dist/agents-store.js +7 -3
- package/dist/api-only.d.ts +8 -10
- package/dist/api-only.js +11 -12
- package/dist/capacity.d.ts +50 -0
- package/dist/capacity.js +49 -0
- package/dist/cli-learning/claude-wire.d.ts +41 -0
- package/dist/cli-learning/claude-wire.js +258 -0
- package/dist/cli-learning/cli.d.ts +11 -0
- package/dist/cli-learning/cli.js +241 -0
- package/dist/cli-learning/codex-worktree.d.ts +10 -0
- package/dist/cli-learning/codex-worktree.js +119 -0
- package/dist/cli-learning/connections.d.ts +62 -0
- package/dist/cli-learning/connections.js +87 -0
- package/dist/cli-learning/entry.d.ts +1 -0
- package/dist/cli-learning/entry.js +4 -0
- package/dist/cli-learning/evidence.d.ts +78 -0
- package/dist/cli-learning/evidence.js +492 -0
- package/dist/cli-learning/hook.d.ts +33 -0
- package/dist/cli-learning/hook.js +544 -0
- package/dist/cli-learning/install.d.ts +33 -0
- package/dist/cli-learning/install.js +335 -0
- package/dist/cli-learning/observation-proof.d.ts +14 -0
- package/dist/cli-learning/observation-proof.js +10 -0
- package/dist/cli-learning/policy.d.ts +48 -0
- package/dist/cli-learning/policy.js +363 -0
- package/dist/cli-learning/schema.d.ts +16 -0
- package/dist/cli-learning/schema.js +27 -0
- package/dist/cli-learning/state.d.ts +23 -0
- package/dist/cli-learning/state.js +61 -0
- package/dist/cli.js +24 -2
- package/dist/compute-cost.d.ts +101 -0
- package/dist/compute-cost.js +250 -0
- package/dist/console/assets/index-Bt1B51b7.js +733 -0
- package/dist/console/assets/index-sVftE9Ht.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/email/email-faux.d.ts +3 -1
- package/dist/email/email-faux.js +3 -2
- package/dist/email/routes.js +22 -12
- package/dist/eval-previous.d.ts +52 -0
- package/dist/eval-previous.js +164 -0
- package/dist/file-types.d.ts +2 -0
- package/dist/file-types.js +3 -1
- package/dist/harness-install.d.ts +6 -2
- package/dist/harness-install.js +40 -8
- package/dist/harness.d.ts +1 -1
- package/dist/harness.js +3 -2
- package/dist/learn/check.d.ts +8 -5
- package/dist/learn/check.js +25 -24
- package/dist/learn/repick.d.ts +22 -13
- package/dist/learn/repick.js +57 -56
- package/dist/learn/secrets.js +14 -3
- package/dist/learn/workflow-draft.d.ts +4 -0
- package/dist/learn/workflow-draft.js +10 -7
- package/dist/learned-workflow.js +8 -8
- package/dist/learning-setting.js +2 -2
- package/dist/learning-words.d.ts +1 -1
- package/dist/learning-words.js +1 -1
- package/dist/mcp-pin-first.js +2 -1
- package/dist/mcp-private-hosts.d.ts +24 -3
- package/dist/mcp-private-hosts.js +53 -3
- package/dist/model-gateway.d.ts +2 -0
- package/dist/model-gateway.js +3 -1
- package/dist/native/runtimes.d.ts +2 -0
- package/dist/native/runtimes.js +2 -0
- package/dist/observation/learning.d.ts +32 -0
- package/dist/observation/learning.js +66 -0
- package/dist/observation/observer.d.ts +8 -1
- package/dist/observation/observer.js +89 -9
- package/dist/observation/schema.js +12 -4
- package/dist/observation/usage-identity.d.ts +9 -0
- package/dist/observation/usage-identity.js +11 -0
- package/dist/openapi.js +113 -29
- package/dist/paid-calls.d.ts +13 -6
- package/dist/paid-calls.js +14 -8
- package/dist/run-launch.d.ts +16 -2
- package/dist/run-launch.js +6 -1
- package/dist/run-timeline-served.js +5 -3
- package/dist/run-usage.d.ts +23 -8
- package/dist/run-usage.js +100 -18
- package/dist/run-view.d.ts +2 -0
- package/dist/run-view.js +12 -7
- package/dist/runner/adapter-loop.d.ts +4 -0
- package/dist/runner/adapter-loop.js +44 -27
- package/dist/runner/adapter-run-spec.d.ts +8 -3
- package/dist/runner/adapter-run-spec.js +15 -8
- package/dist/runner/beside.d.ts +13 -0
- package/dist/runner/beside.js +27 -8
- package/dist/runner/big-writes.d.ts +33 -0
- package/dist/runner/big-writes.js +105 -0
- package/dist/runner/cli-run-spec.js +16 -8
- package/dist/runner/disk-free.d.ts +44 -0
- package/dist/runner/disk-free.js +96 -0
- package/dist/runner/feedback-round.d.ts +12 -8
- package/dist/runner/feedback-round.js +16 -30
- package/dist/runner/harness-loops.js +3 -1
- package/dist/runner/held.d.ts +4 -1
- package/dist/runner/journal-kinds.d.ts +1 -1
- package/dist/runner/learning-end.js +13 -4
- package/dist/runner/main.d.ts +17 -6
- package/dist/runner/main.js +187 -45
- package/dist/runner/metrics.d.ts +4 -0
- package/dist/runner/metrics.js +9 -0
- package/dist/runner/presence.d.ts +11 -2
- package/dist/runner/presence.js +31 -3
- package/dist/runner/run-child-host.d.ts +27 -17
- package/dist/runner/run-child-host.js +70 -116
- package/dist/runner/run-child.js +3 -0
- package/dist/runner/run-errors.js +2 -0
- package/dist/runner/runner-check.d.ts +51 -0
- package/dist/runner/runner-check.js +206 -0
- package/dist/runner/runner-metrics.d.ts +19 -0
- package/dist/runner/runner-metrics.js +49 -0
- package/dist/runner/runner.d.ts +37 -0
- package/dist/runner/runner.js +43 -3
- package/dist/runner/save-slots.d.ts +9 -0
- package/dist/runner/save-slots.js +91 -0
- package/dist/runner/sdk-loop.js +34 -22
- package/dist/runs-over-store.d.ts +8 -1
- package/dist/runs-over-store.js +57 -9
- package/dist/sdk/runs.d.ts +25 -6
- package/dist/sdk/runs.js +107 -35
- package/dist/sdk/runtimes.d.ts +19 -0
- package/dist/sdk/runtimes.js +23 -0
- package/dist/sdk/schema.d.ts +14 -8
- package/dist/sdk/schema.js +18 -6
- package/dist/server.d.ts +7 -0
- package/dist/server.js +151 -28
- package/dist/skills/agentrun-serve/SKILL.md +52 -7
- package/dist/start-switches.js +2 -0
- package/dist/stats.d.ts +4 -0
- package/dist/stats.js +1 -1
- package/dist/store/agent-body.d.ts +13 -2
- package/dist/store/agent-body.js +19 -4
- package/dist/store/dialect.d.ts +2 -0
- package/dist/store/dialect.js +1 -0
- package/dist/store/index.d.ts +3 -3
- package/dist/store/index.js +2 -2
- package/dist/store/postgres/connection.d.ts +5 -2
- package/dist/store/postgres/connection.js +19 -7
- package/dist/store/postgres/dialect.js +1 -0
- package/dist/store/postgres/migrate.d.ts +30 -0
- package/dist/store/postgres/migrate.js +72 -5
- package/dist/store/postgres/migration-lint.d.ts +8 -0
- package/dist/store/postgres/migration-lint.js +119 -0
- package/dist/store/postgres/migrations/0023_computer_interval_resources.sql +14 -0
- package/dist/store/postgres/migrations/0024_runner_capacity.sql +28 -0
- package/dist/store/postgres/store.d.ts +8 -3
- package/dist/store/postgres/store.js +31 -11
- package/dist/store/schema.d.ts +26 -4
- package/dist/store/schema.js +45 -4
- package/dist/store/sqlite/connection.d.ts +3 -3
- package/dist/store/sqlite/connection.js +3 -3
- package/dist/store/sqlite/run-launch.d.ts +9 -1
- package/dist/store/sqlite/run-launch.js +44 -0
- package/dist/store/sqlite/store.d.ts +19 -4
- package/dist/store/sqlite/store.js +180 -93
- package/dist/store/store-schema.d.ts +34 -0
- package/dist/store/store-schema.js +125 -0
- package/dist/store/store.d.ts +61 -2
- package/dist/store/store.js +13 -0
- package/dist/store-reads/analytics.d.ts +3 -2
- package/dist/store-reads/analytics.js +20 -8
- package/dist/store-reads/cap.d.ts +9 -5
- package/dist/store-reads/cap.js +28 -2
- package/dist/store-reads/decisions.d.ts +21 -0
- package/dist/store-reads/decisions.js +22 -0
- package/dist/store-reads/journal.d.ts +8 -2
- package/dist/store-reads/journal.js +27 -8
- package/dist/store-view.d.ts +9 -4
- package/dist/store-view.js +48 -25
- package/dist/template-eval.d.ts +15 -1
- package/dist/template-eval.js +92 -13
- package/dist/templates.d.ts +4 -3
- package/dist/templates.js +4 -3
- package/dist/timeline/labels.js +17 -0
- package/dist/tool-gate.d.ts +4 -2
- package/dist/tool-list.js +1 -0
- package/dist/tools.d.ts +6 -2
- package/dist/tools.js +13 -1
- package/dist/trigger-targets.d.ts +21 -5
- package/dist/trigger-targets.js +13 -10
- package/dist/unified-usage.d.ts +24 -0
- package/dist/unified-usage.js +400 -0
- package/dist/uploads-archil.d.ts +100 -0
- package/dist/uploads-archil.js +430 -0
- package/dist/uploads.d.ts +55 -1
- package/dist/uploads.js +185 -98
- package/dist/validate.js +1 -1
- package/dist/web-fake.d.ts +25 -0
- package/dist/web-fake.js +38 -1
- package/dist/web-save.d.ts +75 -0
- package/dist/web-save.js +235 -0
- package/dist/workspace/archil-claim.d.ts +5 -2
- package/dist/workspace/archil-claim.js +5 -2
- package/dist/workspace/archil-disk.d.ts +11 -1
- package/dist/workspace/archil-disk.js +43 -10
- package/dist/workspace/archil.d.ts +3 -0
- package/dist/workspace/archil.js +102 -16
- package/dist/workspace/computer-for-claim.d.ts +14 -0
- package/dist/workspace/computer-for-claim.js +46 -7
- package/dist/workspace/computer-intervals.d.ts +9 -3
- package/dist/workspace/computer-intervals.js +17 -8
- package/dist/workspace/pieced.d.ts +14 -0
- package/dist/workspace/pieced.js +23 -0
- package/dist/workspace/run-disk.js +32 -12
- package/dist/workspace/run-workspace.d.ts +1 -1
- package/dist/workspace/run-workspace.js +11 -6
- package/package.json +10 -10
- package/skills/agentrun-serve/SKILL.md +52 -7
- package/templates/README.md +36 -7
- package/dist/console/assets/index-Bzn4eUYF.js +0 -715
- package/dist/console/assets/index-CR2ZGei1.css +0 -1
package/dist/run-usage.d.ts
CHANGED
|
@@ -3,9 +3,11 @@ import { type CostBasis, type CostWords } from "./runner/metrics.js";
|
|
|
3
3
|
import type { RunLaunch } from "./run-launch.js";
|
|
4
4
|
import { type SignInReader } from "./run-view.js";
|
|
5
5
|
import { type ComputerIntervalRow, type Store } from "./store/index.js";
|
|
6
|
+
import { type ComputeResource, type ComputeUnit } from "./compute-cost.js";
|
|
6
7
|
import { type EntryLike } from "./timeline/index.js";
|
|
7
|
-
/** The meters a run's lines are on: the contract's `tokens` and `browser_time`, and this server's `tools
|
|
8
|
-
|
|
8
|
+
/** The meters a run's lines are on: the contract's `tokens` and `browser_time`, and this server's `tools` and
|
|
9
|
+
* `compute_time`. */
|
|
10
|
+
export type UsageMeter = "tokens" | "tools" | "browser_time" | "compute_time";
|
|
9
11
|
/** One line of a run's cost: one model, one charger or one browser provider on a meter. Which it is: `model` and
|
|
10
12
|
* `provider` on `tokens` (the model the requests were sent on; the provider they went to, named only when the server
|
|
11
13
|
* sent them there itself, null behind a gateway, whose upstream the server does not know), `charged_by` on `tools` (who
|
|
@@ -22,8 +24,15 @@ export type RunUsageLine = {
|
|
|
22
24
|
provider: string | null;
|
|
23
25
|
charged_by: string | null;
|
|
24
26
|
quantity: number | null;
|
|
25
|
-
unit: "token" | "call" | "second";
|
|
27
|
+
unit: "token" | "call" | "second" | ComputeUnit;
|
|
26
28
|
basis: CostBasis;
|
|
29
|
+
/** On `compute_time`: the resource (vcpu, memory, gpu, disk), a GPU's type, the part of `quantity` no claim held (in
|
|
30
|
+
* no cost), and how many of its computers are still open, their time counted up to `measured_to`. */
|
|
31
|
+
resource?: ComputeResource;
|
|
32
|
+
gpu_type?: string | null;
|
|
33
|
+
unheld_quantity?: number | null;
|
|
34
|
+
open_computers?: number;
|
|
35
|
+
measured_to?: string;
|
|
27
36
|
requests?: number;
|
|
28
37
|
tokens?: {
|
|
29
38
|
input: number;
|
|
@@ -59,10 +68,11 @@ export type RunUsage = {
|
|
|
59
68
|
reason: UsageReason | null;
|
|
60
69
|
};
|
|
61
70
|
/** One computer the run made through its provider (a sandbox, a desktop, a phone), as GET /runs/{run_id}/usage serves
|
|
62
|
-
* it: the provider (this server's id for it) and the provider's own id for the computer, its kind, what
|
|
63
|
-
*
|
|
64
|
-
* (`ended_at`, null while none did: still running, or its delete failed or was
|
|
65
|
-
* kept it past its claim
|
|
71
|
+
* it: the provider (this server's id for it) and the provider's own id for the computer, its kind, what it was made with
|
|
72
|
+
* (its provider's own figures where it gave them, else what its create asked; null where neither says), when it was made,
|
|
73
|
+
* when its provider's delete answered ok (`ended_at`, null while none did: still running, or its delete failed or was
|
|
74
|
+
* never asked), whether the run's park kept it past its claim, and how much of its time a claim of the run booked
|
|
75
|
+
* (`booked_seconds`; the rest is time no claim held). */
|
|
66
76
|
export type ComputerIntervalLine = {
|
|
67
77
|
provider: string;
|
|
68
78
|
provider_id: string;
|
|
@@ -73,9 +83,11 @@ export type ComputerIntervalLine = {
|
|
|
73
83
|
} | null;
|
|
74
84
|
cpus: number | null;
|
|
75
85
|
memory_mb: number | null;
|
|
86
|
+
disk_gb: number | null;
|
|
76
87
|
started_at: string;
|
|
77
88
|
ended_at: string | null;
|
|
78
89
|
kept: boolean;
|
|
90
|
+
booked_seconds: number;
|
|
79
91
|
};
|
|
80
92
|
/** The run's computer rows as served (ComputerIntervalLine), in the order the store reads them (by when each was made). */
|
|
81
93
|
export declare function computerIntervalsOf(rows: readonly ComputerIntervalRow[]): ComputerIntervalLine[];
|
|
@@ -92,7 +104,10 @@ export type DecisionReceiptLike = {
|
|
|
92
104
|
* provider (`browser_time`); and their join, `total`. A meter with nothing booked has no line. `launch` names the
|
|
93
105
|
* run's own model's provider; `receipts`, a workflow's decisions by id, the model and provider each was answered on
|
|
94
106
|
* (its booking names the decision alone), which this server called itself. */
|
|
95
|
-
export declare function usageLinesOf(entries: readonly EntryLike[], launch?: Pick<RunLaunch, "model">, receipts?: ReadonlyMap<string, DecisionReceiptLike
|
|
107
|
+
export declare function usageLinesOf(entries: readonly EntryLike[], launch?: Pick<RunLaunch, "model">, receipts?: ReadonlyMap<string, DecisionReceiptLike>, computers?: {
|
|
108
|
+
readonly rows: readonly ComputerIntervalRow[];
|
|
109
|
+
readonly at: number;
|
|
110
|
+
}): {
|
|
96
111
|
lines: RunUsageLine[];
|
|
97
112
|
total: CostWords;
|
|
98
113
|
};
|
package/dist/run-usage.js
CHANGED
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
//
|
|
7
7
|
// Nothing is measured again. The lines are the run's booking (runner/metrics.ts bookedSpend) split by what each charge
|
|
8
8
|
// was: its model requests and its decisions by the model each was sent on (`tokens`), its paid tool calls by who charged
|
|
9
|
-
// for them (`tools`, with the calls that ran unpriced beside them
|
|
9
|
+
// for them (`tools`, with the calls that ran unpriced beside them; a decision Parallel answered on its own API is one,
|
|
10
|
+
// Parallel's, beside its web tools' calls), and its browser session time by its provider
|
|
10
11
|
// (`browser_time`, with the seconds its BROWSER_CHARGED records keep). Each part is read by bookedSpend itself, over the
|
|
11
12
|
// run's entries with only that part's requests left in, so a line's figure follows the one rule its sum does; and the
|
|
12
13
|
// lines join (costWordsOf) to `total`, which is the run's `cost.usd`: the same booking outside its end-of-run (learning)
|
|
@@ -15,8 +16,12 @@
|
|
|
15
16
|
// so (`usd` null, what is known beside it), and a run the server cannot split says why (`reason`) with no lines.
|
|
16
17
|
//
|
|
17
18
|
// Beside the lines, each computer the run made (`computer_intervals`, store computer_intervals): its provider's own id,
|
|
18
|
-
// what it was made with, when it was made and when its provider's delete answered ok (null while none did).
|
|
19
|
-
//
|
|
19
|
+
// what it was made with, when it was made and when its provider's delete answered ok (null while none did). Its time is on
|
|
20
|
+
// `compute_time` lines (compute-cost.ts), one per provider and resource (vCPU, memory, a GPU type, disk): the quantity is
|
|
21
|
+
// every second of each such computer of the run's at its figure (an open one's up to the read), and `usd` is what the
|
|
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
|
+
// kept for a follow-up, one deleted after its run, one whose delete failed) is said apart (`unheld_quantity`) and costs
|
|
24
|
+
// nothing on the line or in `total`. A resource with no price is `unpriced`, its `usd` null.
|
|
20
25
|
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
21
26
|
import { RUNNER_RECORDS } from "@parcha/agentrun-kernel";
|
|
22
27
|
import { TOOL_SESSION } from "@parcha/agentrun-kernel/kernel/cap";
|
|
@@ -28,7 +33,7 @@ import { journalRecords } from "./runner/journal-reader.js";
|
|
|
28
33
|
import { KINDS } from "./runner/journal-kinds.js";
|
|
29
34
|
import { bookedSpend, costBasisOf, costWordsOf } from "./runner/metrics.js";
|
|
30
35
|
import { unbookedCli } from "./store-reads/cap.js";
|
|
31
|
-
import { decisionsOverStore } from "./store-reads/decisions.js";
|
|
36
|
+
import { booksDecisions, chargedByParallel, decisionsOverStore, PARALLEL_CHARGER, receiptIdOf } from "./store-reads/decisions.js";
|
|
32
37
|
import { roundsOf } from "./store-reads/learning.js";
|
|
33
38
|
import { MODEL_PROVIDER } from "./model.js";
|
|
34
39
|
import { ApiError } from "./errors.js";
|
|
@@ -36,6 +41,7 @@ import { redacted } from "./key-refusal.js";
|
|
|
36
41
|
import { runCutValues } from "./run-cut.js";
|
|
37
42
|
import { WITHHELD_SIGN_IN } from "./run-view.js";
|
|
38
43
|
import { FINAL_STATES } from "./store/index.js";
|
|
44
|
+
import { COMPUTE_TOOL, COMPUTE_UNITS, computeTag, resourcesOf, unmetered } from "./compute-cost.js";
|
|
39
45
|
import { TOOL_UNMETERED } from "./timeline/index.js";
|
|
40
46
|
/** The run's computer rows as served (ComputerIntervalLine), in the order the store reads them (by when each was made). */
|
|
41
47
|
export function computerIntervalsOf(rows) {
|
|
@@ -46,9 +52,11 @@ export function computerIntervalsOf(rows) {
|
|
|
46
52
|
gpu: row.gpuType === null && row.gpuCount === null ? null : { type: row.gpuType, count: row.gpuCount },
|
|
47
53
|
cpus: row.cpus,
|
|
48
54
|
memory_mb: row.memoryMb,
|
|
55
|
+
disk_gb: row.diskGb,
|
|
49
56
|
started_at: new Date(row.startedAt).toISOString(),
|
|
50
57
|
ended_at: row.endedAt === null ? null : new Date(row.endedAt).toISOString(),
|
|
51
58
|
kept: row.kept,
|
|
59
|
+
booked_seconds: row.bookedMs / 1000,
|
|
52
60
|
}));
|
|
53
61
|
}
|
|
54
62
|
/** `entries` with the run's booked requests (runner.request and runner.turn) left in only where `keep` says so of its
|
|
@@ -72,7 +80,7 @@ function joined(parts) {
|
|
|
72
80
|
}
|
|
73
81
|
return { parts: [...parts], requests, unmetered, tokens, priced };
|
|
74
82
|
}
|
|
75
|
-
const ORDER = { tokens: 0, tools: 1, browser_time: 2 };
|
|
83
|
+
const ORDER = { tokens: 0, tools: 1, browser_time: 2, compute_time: 3 };
|
|
76
84
|
const named = (value) => (typeof value === "string" && value !== "" ? value : null);
|
|
77
85
|
/** The provider a run's model requests on `model` went to, where this server sent them there itself: the run's own
|
|
78
86
|
* model's provider (its launch's), on a direct route. Null behind a gateway, whose upstream the server does not know,
|
|
@@ -88,18 +96,20 @@ function upstreamOf(model, launch) {
|
|
|
88
96
|
* provider (`browser_time`); and their join, `total`. A meter with nothing booked has no line. `launch` names the
|
|
89
97
|
* run's own model's provider; `receipts`, a workflow's decisions by id, the model and provider each was answered on
|
|
90
98
|
* (its booking names the decision alone), which this server called itself. */
|
|
91
|
-
export function usageLinesOf(entries, launch, receipts = new Map()) {
|
|
99
|
+
export function usageLinesOf(entries, launch, receipts = new Map(), computers = { rows: [], at: 0 }) {
|
|
92
100
|
const conversation = (key) => entries.find((e) => e.kind === KINDS.sessionKey && e.data?.key === key)?.data;
|
|
93
101
|
const paidConv = Number(conversation(TOOL_SESSION)?.conversation ?? Number.NaN);
|
|
94
102
|
const conv = (e) => Number(e.conversationId);
|
|
95
103
|
const turnOf = (e) => `${String(e.conversationId)}:${String(e.data?.turn)}`;
|
|
96
104
|
// A line is one meter, one name and, on `tokens`, one route: a model reached two ways (the run's own requests behind a
|
|
97
105
|
// gateway, a decision on its provider) is two lines, never one labelled with either's provider.
|
|
98
|
-
const keyOf = (group) => `${group.meter}\u0000${group.name ?? ""}\u0000${group.provider ?? ""}`;
|
|
106
|
+
const keyOf = (group) => `${group.meter}\u0000${group.name ?? ""}\u0000${group.provider ?? ""}\u0000${group.tag ?? ""}`;
|
|
99
107
|
// Each booked request's group, by its turn: a model request's or a decision's, the model its runner.request was sent on;
|
|
100
108
|
// a paid charge's, who charged for it (`charged_by`), on browser_time when it is the browser's session time. A paid
|
|
101
109
|
// charge settled at its provider's own figure says so on its request (`reported`). A decision's request names the
|
|
102
110
|
// decision (`decision:<id>`): its receipt names the model and provider that answered it, and how its cost was reached.
|
|
111
|
+
// A decision Parallel answered on its own API (chargedByParallel) is a paid call Parallel charged at its list price, on
|
|
112
|
+
// Parallel's `tools` line beside its web tools' calls, not a model's tokens: it is on one line, never on both.
|
|
103
113
|
const groups = new Map();
|
|
104
114
|
const reported = new Set();
|
|
105
115
|
const estimated = new Set();
|
|
@@ -109,10 +119,15 @@ export function usageLinesOf(entries, launch, receipts = new Map()) {
|
|
|
109
119
|
if (e.kind !== RUNNER_RECORDS.request)
|
|
110
120
|
continue;
|
|
111
121
|
const d = (e.data ?? {});
|
|
122
|
+
// A computer's time (compute-cost.ts) by its provider and resource (its tag); a browser's by its provider.
|
|
112
123
|
if (conv(e) === paidConv)
|
|
113
|
-
groups.set(turnOf(e), { meter: d.tool === "browser" ? "browser_time" : "tools", name: named(d.charged_by) });
|
|
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) });
|
|
114
125
|
else if (named(d.model)?.startsWith("decision:")) {
|
|
115
126
|
const receipt = receipts.get(String(d.model).slice("decision:".length));
|
|
127
|
+
if (receipt && chargedByParallel(receipt)) {
|
|
128
|
+
groups.set(turnOf(e), { meter: "tools", name: PARALLEL_CHARGER });
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
116
131
|
// A receipt that names no model leaves `model` null: its provider is said as the provider, never as a model.
|
|
117
132
|
groups.set(turnOf(e), receipt ? { meter: "tokens", name: named(receipt.model), provider: named(receipt.provider) } : { meter: "tokens", name: null, provider: null });
|
|
118
133
|
if (receipt?.cost_basis === "reported")
|
|
@@ -173,10 +188,19 @@ export function usageLinesOf(entries, launch, receipts = new Map()) {
|
|
|
173
188
|
found.set(keyOf(group), group);
|
|
174
189
|
}
|
|
175
190
|
const lines = [];
|
|
191
|
+
/** What the ledger booked for each computer provider and resource (computeLinesOf), by its line's key. */
|
|
192
|
+
const computeBooked = new Map();
|
|
176
193
|
for (const group of found.values()) {
|
|
177
194
|
const key = keyOf(group);
|
|
178
195
|
const part = onlyRequests(entries, turnOf, (turn) => turnKeys.get(turn) === key);
|
|
179
|
-
|
|
196
|
+
// A `tools` line's part holds its charger's paid calls and, on Parallel's, the decisions Parallel charged.
|
|
197
|
+
const booked = joined(group.meter === "tokens" ? [bookedSpend(part, "model"), bookedSpend(part, "decisions")] : group.meter === "tools" ? [bookedSpend(part, "paid"), bookedSpend(part, "decisions")] : [bookedSpend(part, "paid")]);
|
|
198
|
+
if (group.meter === "compute_time") {
|
|
199
|
+
// A hold for a stretch names no resource (no tag) and books nothing: it is given back.
|
|
200
|
+
if (group.tag !== null && group.tag !== undefined)
|
|
201
|
+
computeBooked.set(computeKey(group.name ?? "", group.tag), booked);
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
180
204
|
const notMetered = unpricedCalls.get(key);
|
|
181
205
|
// A part whose every request was given back (never sent) used nothing: no line, unless calls ran on it unpriced.
|
|
182
206
|
if (booked.requests === 0 && group.meter !== "browser_time" && !notMetered)
|
|
@@ -196,7 +220,8 @@ export function usageLinesOf(entries, launch, receipts = new Map()) {
|
|
|
196
220
|
}
|
|
197
221
|
else if (group.meter === "tools") {
|
|
198
222
|
// `reported` when every charge with a figure was settled at its provider's own (monid's answer says what it
|
|
199
|
-
// charged); `estimate` when any was settled at a price this server holds (an MCP tool's owner's, Parallel's
|
|
223
|
+
// charged); `estimate` when any was settled at a price this server holds (an MCP tool's owner's, Parallel's, a
|
|
224
|
+
// Parallel decision's list price).
|
|
200
225
|
const basis = priced <= 0 ? "unpriced" : turns.every((turn) => reported.has(turn)) ? "reported" : "estimate";
|
|
201
226
|
// Calls that ran unpriced only: none booked, so nothing is charged on the line, by its owner's choice of no price.
|
|
202
227
|
const words = booked.requests === 0 ? { usd: 0 } : costWordsOf(booked.parts);
|
|
@@ -213,8 +238,16 @@ export function usageLinesOf(entries, launch, receipts = new Map()) {
|
|
|
213
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 });
|
|
214
239
|
}
|
|
215
240
|
}
|
|
216
|
-
|
|
217
|
-
|
|
241
|
+
lines.push(...computeLinesOf(computers.rows, computers.at, computeBooked));
|
|
242
|
+
// Each meter by its name (a model, a charger, a browser provider; none first), `tokens` then by its route's provider,
|
|
243
|
+
// `compute_time` then by its resource in compute-cost.ts's order and a GPU's type.
|
|
244
|
+
const sortKey = (line) => line.meter === "tokens"
|
|
245
|
+
? `${line.model ?? ""}\u0000${line.provider ?? ""}`
|
|
246
|
+
: line.meter === "tools"
|
|
247
|
+
? line.charged_by ?? ""
|
|
248
|
+
: line.meter === "compute_time"
|
|
249
|
+
? `${line.provider ?? ""}\u0000${RESOURCE_ORDER[line.resource ?? "vcpu"]}\u0000${line.gpu_type ?? ""}`
|
|
250
|
+
: line.provider ?? "";
|
|
218
251
|
lines.sort((a, b) => ORDER[a.meter] - ORDER[b.meter] || (sortKey(a) < sortKey(b) ? -1 : sortKey(a) > sortKey(b) ? 1 : 0));
|
|
219
252
|
// The join over the whole booking, never the lines' rounded figures: the same figure cost.usd is. A browser line whose
|
|
220
253
|
// time no charge booked is unknown beside it: the total is too, with the booking's figure as what is known.
|
|
@@ -225,6 +258,54 @@ export function usageLinesOf(entries, launch, receipts = new Map()) {
|
|
|
225
258
|
const known = total.usd ?? total.so_far_usd ?? 0;
|
|
226
259
|
return { lines, total: { usd: null, so_far_usd: known, unpriced: (total.usd === null ? (total.unpriced ?? 0) : 0) + unbooked } };
|
|
227
260
|
}
|
|
261
|
+
/** A compute line's key: its provider and its resource's tag (computeTag). */
|
|
262
|
+
const computeKey = (provider, tag) => `${provider}\u0000${tag}`;
|
|
263
|
+
const RESOURCE_ORDER = { vcpu: 0, memory: 1, gpu: 2, disk: 3 };
|
|
264
|
+
/** Up to the millionth, as the browser's seconds are. */
|
|
265
|
+
const micro = (value) => Math.round(value * 1e6) / 1e6;
|
|
266
|
+
/** The run's `compute_time` lines: one per provider and resource of the computers it made (`rows`), each second of each at
|
|
267
|
+
* 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
|
+
* `unheld_quantity`. Its money is what the run's ledger booked for it (`booked`, by computeKey): `estimate` when any was;
|
|
269
|
+
* $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) {
|
|
271
|
+
const sums = new Map();
|
|
272
|
+
for (const row of rows) {
|
|
273
|
+
const livedS = Math.max(0, (row.endedAt ?? at) - row.startedAt) / 1000;
|
|
274
|
+
const unheldS = Math.max(0, livedS - row.bookedMs / 1000);
|
|
275
|
+
for (const one of resourcesOf(row)) {
|
|
276
|
+
const key = computeKey(row.provider, computeTag(one));
|
|
277
|
+
const sum = sums.get(key) ?? { provider: row.provider, resource: one.resource, gpuType: one.gpuType, quantity: 0, unheld: 0, open: 0 };
|
|
278
|
+
sum.quantity = sum.quantity === null || one.perSecond === null ? null : sum.quantity + one.perSecond * livedS;
|
|
279
|
+
sum.unheld = sum.unheld === null || one.perSecond === null ? null : sum.unheld + one.perSecond * unheldS;
|
|
280
|
+
if (row.endedAt === null)
|
|
281
|
+
sum.open += 1;
|
|
282
|
+
sums.set(key, sum);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
// 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.keys()) {
|
|
287
|
+
if (sums.has(key))
|
|
288
|
+
continue;
|
|
289
|
+
const [provider = "", tag = ""] = key.split("\u0000");
|
|
290
|
+
const gpu = tag.startsWith("gpu:");
|
|
291
|
+
const resource = (gpu ? "gpu" : tag);
|
|
292
|
+
if (!Object.hasOwn(COMPUTE_UNITS, resource))
|
|
293
|
+
continue;
|
|
294
|
+
sums.set(key, { provider, resource, gpuType: gpu ? tag.slice("gpu:".length) : null, quantity: null, unheld: null, open: 0 });
|
|
295
|
+
}
|
|
296
|
+
return [...sums.entries()].map(([key, sum]) => {
|
|
297
|
+
const spend = booked.get(key);
|
|
298
|
+
const charged = spend !== undefined && spend.requests > 0;
|
|
299
|
+
const free = !charged && unmetered(sum.provider);
|
|
300
|
+
const words = charged ? costWordsOf(spend.parts) : free ? { usd: 0 } : { usd: null };
|
|
301
|
+
return {
|
|
302
|
+
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,
|
|
304
|
+
resource: sum.resource, gpu_type: sum.gpuType, unheld_quantity: sum.unheld === null ? null : micro(sum.unheld), open_computers: sum.open,
|
|
305
|
+
...(sum.open > 0 ? { measured_to: new Date(at).toISOString() } : {}),
|
|
306
|
+
};
|
|
307
|
+
});
|
|
308
|
+
}
|
|
228
309
|
/** The run's own browser sessions: those its job opened or charged (`job`, the journal less the end-of-run learning
|
|
229
310
|
* turn), each with its end read from the whole journal (`all`). The run's end lets its browsers go inside the learning
|
|
230
311
|
* turn's range (reflectRanges runs to the run's end), so an end read from `job` alone would be missing for a session
|
|
@@ -263,11 +344,12 @@ export async function runUsageOverStore(store, runId) {
|
|
|
263
344
|
const turns = reflectRanges(records.submissions ?? [], records.entries);
|
|
264
345
|
const entries = records.entries.filter((entry) => !inReflect(turns, Number(entry.id)));
|
|
265
346
|
// A workflow's decision receipts, read only when it made a decision: the model and provider each was answered on.
|
|
266
|
-
const
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
const
|
|
347
|
+
const receipts = booksDecisions(entries) ? new Map((await decisionsOverStore(snapshot, runId, BACKGROUND_CONTEXT)).map((receipt) => [receiptIdOf(receipt), receipt])) : undefined;
|
|
348
|
+
// 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
|
+
// as none made.
|
|
350
|
+
const rows = snapshot.computerIntervals ? await snapshot.computerIntervals.forRun(runId) : [];
|
|
351
|
+
const { lines, total } = usageLinesOf(entries, launch, receipts, { rows, at: Date.now() });
|
|
352
|
+
const computers = computerIntervalsOf(rows);
|
|
271
353
|
return { run_id: runId, ended_at: ended, currency: "USD", total, lines, browser_sessions: jobSessions(entries, records.entries), computer_intervals: computers, reason: null };
|
|
272
354
|
});
|
|
273
355
|
}
|
|
@@ -298,7 +380,7 @@ export async function servedRunUsage(deps, store, runId) {
|
|
|
298
380
|
});
|
|
299
381
|
return {
|
|
300
382
|
...usage,
|
|
301
|
-
lines: usage.lines.map((line) => ({ ...line, model: said(line.model), provider: said(line.provider), charged_by: said(line.charged_by) })),
|
|
383
|
+
lines: usage.lines.map((line) => ({ ...line, model: said(line.model), provider: said(line.provider), charged_by: said(line.charged_by), ...(line.gpu_type === undefined ? {} : { gpu_type: said(line.gpu_type) }) })),
|
|
302
384
|
browser_sessions: usage.browser_sessions && usage.browser_sessions.map(session),
|
|
303
385
|
// A computer's words too: its provider's id for it is the provider's, which a run's own tools can name.
|
|
304
386
|
computer_intervals: usage.computer_intervals && usage.computer_intervals.map((one) => ({
|
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 card's ASKED_BECAUSE), kept out of `args_json`. */
|
|
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
|
@@ -18,6 +18,7 @@ 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
20
|
import { ASKED_BECAUSE, ENDED_WHILE_WAITING, STOPPED_WHILE_WAITING } from "./refusal-words.js";
|
|
21
|
+
import { isObject } from "./validate.js";
|
|
21
22
|
/** The run's newest usage row, which carries its cost. */
|
|
22
23
|
const usageOf = (rows) => rows.findLast((r) => r.kind === "usage");
|
|
23
24
|
/** The run's cost from its usage row: null when a response's cost is unknown, 0 before any request. */
|
|
@@ -135,11 +136,15 @@ export function asksOf(entries) {
|
|
|
135
136
|
if (typeof d?.callId !== "string" || map.has(d.callId))
|
|
136
137
|
continue;
|
|
137
138
|
const price = priceOfAsk(d.price);
|
|
139
|
+
// The card's reason for asking a call its setting allows is the gate's, never one of the call's arguments.
|
|
140
|
+
const raw = d.args ?? {};
|
|
141
|
+
const { [ASKED_BECAUSE]: because, ...args } = isObject(raw) ? raw : {};
|
|
138
142
|
map.set(d.callId, {
|
|
139
143
|
id: d.callId,
|
|
140
144
|
tool: d.tool,
|
|
141
145
|
call_id: d.callId,
|
|
142
|
-
args_json: JSON.stringify(
|
|
146
|
+
args_json: JSON.stringify(isObject(raw) ? args : raw) ?? "{}",
|
|
147
|
+
...(typeof because === "string" ? { asks_because: because } : {}),
|
|
143
148
|
requested_at: d.requestedAt,
|
|
144
149
|
...(price !== undefined ? { price } : {}),
|
|
145
150
|
...(d.destructive === true ? { destructive: true } : {}),
|
|
@@ -372,10 +377,11 @@ export const pendingOf = (rows) => {
|
|
|
372
377
|
return last?.kind === "waiting" ? { kind: "question", question: last.text ?? last.summary ?? "", asked_at: last.timestamp } : null;
|
|
373
378
|
};
|
|
374
379
|
/** 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. */
|
|
380
|
+
/** A call's approval summary, where its tool has one (tools.ts ToolEntry.approvalSummary), redacted as its arguments are. */
|
|
377
381
|
function summaryOf(approval, redact) {
|
|
378
382
|
const summarize = toolOf(approval.tool)?.approvalSummary;
|
|
383
|
+
if (!summarize)
|
|
384
|
+
return {};
|
|
379
385
|
let args;
|
|
380
386
|
try {
|
|
381
387
|
args = JSON.parse(approval.args_json);
|
|
@@ -383,13 +389,12 @@ function summaryOf(approval, redact) {
|
|
|
383
389
|
catch {
|
|
384
390
|
return {};
|
|
385
391
|
}
|
|
386
|
-
const
|
|
387
|
-
|
|
388
|
-
return parts.length ? { summary: redact(parts.join("\n\n")) } : {};
|
|
392
|
+
const summary = summarize(args);
|
|
393
|
+
return summary === undefined ? {} : { summary: redact(summary) };
|
|
389
394
|
}
|
|
390
395
|
export const approvalOf = (run, redact) => {
|
|
391
396
|
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;
|
|
397
|
+
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
398
|
};
|
|
394
399
|
/** 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
400
|
* 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
|
|
@@ -319,6 +319,10 @@ export interface RunLedger {
|
|
|
319
319
|
/** The store's flush (what the runner's flush before a side effect runs): a record a tool writes during its call that
|
|
320
320
|
* must be on disk before the call's next step leaves the box (a browser session's open, before its vendor is asked). */
|
|
321
321
|
flush(): Promise<void>;
|
|
322
|
+
/** Whether the run's cap can judge a paid step now. False while the run's spec is built (its cap is the spec's): a paid
|
|
323
|
+
* step asked then waits for the spec, so a step the build itself waits on (a computer's hold before its create,
|
|
324
|
+
* compute-cost.ts) is not asked until this is true. Absent: it always can. */
|
|
325
|
+
judges?(): boolean;
|
|
322
326
|
}
|
|
323
327
|
/** pi's retry of a model request that failed in a way it retries (a provider's 429, overload or 5xx, a dropped connection,
|
|
324
328
|
* a stream cut mid-answer): up to 8 more attempts, 2s doubling to at most 30s apart (about two and a half minutes in all),
|
|
@@ -1101,13 +1101,19 @@ function adapterLoop(specOf, options, deps) {
|
|
|
1101
1101
|
return { later: "the run is waiting on a person: the message runs as a turn of its own after the answer" };
|
|
1102
1102
|
// A grade's feedback round (feedback-round.ts): the run opened again on the grade's words, which are never a turn of
|
|
1103
1103
|
// the job's. Kept on the root as a FEEDBACK entry, whose commit takes the row; the claim goes to its end-of-run turn.
|
|
1104
|
+
// The same commit keeps the end the run had when the grade opened it as its job's end (KINDS.jobEnd): from the taking
|
|
1105
|
+
// on, the round is a look-back with its job's end kept, which every reader serves and its claim ends on (jobEndKept).
|
|
1104
1106
|
const fed = reopen && !reopen.sent && (session.state === "idle" || session.state === "new") ? feedbackOf(command.body) : undefined;
|
|
1105
1107
|
if (fed && reopen && harness && root) {
|
|
1106
1108
|
const [on, theRoot, mine] = [harness, root, reopen];
|
|
1107
1109
|
const taken = gate.expect(writesEntry(KINDS.feedback, (data) => data.requestId === requestId), { take: [command.id] });
|
|
1108
1110
|
taken.catch(() => undefined);
|
|
1109
|
-
|
|
1110
|
-
mine.
|
|
1111
|
+
const { kept: { endedAt, ...end }, ...round } = fed;
|
|
1112
|
+
mine.feedback = round;
|
|
1113
|
+
mine.sent = on.commit(async (tx) => {
|
|
1114
|
+
await tx.appendEntry(theRoot.id, { kind: KINDS.feedback, data: { ...round, requestId, at: now() } });
|
|
1115
|
+
await tx.appendEntry(theRoot.id, { kind: KINDS.jobEnd, data: jobEndOf(end, undefined, endedAt) });
|
|
1116
|
+
}, context).then(() => undefined);
|
|
1111
1117
|
mine.placed?.();
|
|
1112
1118
|
try {
|
|
1113
1119
|
await mine.sent;
|
|
@@ -1391,7 +1397,15 @@ function adapterLoop(specOf, options, deps) {
|
|
|
1391
1397
|
const decisionsOf = () => (decisionsOpen ??= sessions.open(DECISION_SESSION).then((w) => theCap().decisions(w, flushed)).then((d) => (decisionsReady = d)));
|
|
1392
1398
|
let paidReady;
|
|
1393
1399
|
let paidOpen;
|
|
1394
|
-
|
|
1400
|
+
// The run's cap is its spec's (theCap): a paid step asked while the spec is still built (a computer's time, metered
|
|
1401
|
+
// from its create, compute-cost.ts) waits for it, and fails as the spec's build does. `capJudges` says whether it
|
|
1402
|
+
// can judge now, so a caller inside the build never waits on itself.
|
|
1403
|
+
let capJudges = false;
|
|
1404
|
+
let specBuilt;
|
|
1405
|
+
let specFailed;
|
|
1406
|
+
const specSet = new Promise((resolve, reject) => ((specBuilt = resolve), (specFailed = reject)));
|
|
1407
|
+
specSet.catch(() => undefined);
|
|
1408
|
+
const paidOf = () => (paidOpen ??= specSet.then(() => sessions.open(TOOL_SESSION)).then((w) => theCap().tools(w, flushed)).then((p) => (paidReady = p)));
|
|
1395
1409
|
/** The pause of a paid call the cap refused (ledger.pause), set once the claim's booking is: below. */
|
|
1396
1410
|
let pauseFor;
|
|
1397
1411
|
const ledger = {
|
|
@@ -1414,6 +1428,7 @@ function adapterLoop(specOf, options, deps) {
|
|
|
1414
1428
|
await pauseFor?.(refusal);
|
|
1415
1429
|
},
|
|
1416
1430
|
flush: () => deps.flush(),
|
|
1431
|
+
judges: () => capJudges,
|
|
1417
1432
|
};
|
|
1418
1433
|
// A phase of the host's, on the run's timeline while its step runs. Said before the root exists (the claim's computer
|
|
1419
1434
|
// waiting on its image build, inside specOf), it makes the root then, the row in its creating commit (above), so a
|
|
@@ -1455,6 +1470,8 @@ function adapterLoop(specOf, options, deps) {
|
|
|
1455
1470
|
spec = await specOf(claim, runOf);
|
|
1456
1471
|
}
|
|
1457
1472
|
catch (error) {
|
|
1473
|
+
// A paid step that waited on the spec (paidOf) fails with it: nothing was booked.
|
|
1474
|
+
specFailed(error);
|
|
1458
1475
|
if (error instanceof Fenced)
|
|
1459
1476
|
return await interrupted("its claim was lost while its MCP credentials were made fresh");
|
|
1460
1477
|
if (error instanceof McpClaimRefused)
|
|
@@ -1479,6 +1496,9 @@ function adapterLoop(specOf, options, deps) {
|
|
|
1479
1496
|
mcp = spec.mcp;
|
|
1480
1497
|
specNow = spec;
|
|
1481
1498
|
specKnown = true;
|
|
1499
|
+
// The run's cap can judge from here: a paid step that waited on the spec goes on.
|
|
1500
|
+
capJudges = true;
|
|
1501
|
+
specBuilt();
|
|
1482
1502
|
// The spec's resources are the pass's from here: a claim lost in any write below still lets them go (closeSession).
|
|
1483
1503
|
releaseNow = spec.release;
|
|
1484
1504
|
// A root a phase made while the spec was built (on this claim or an earlier one lost before this point) took none
|
|
@@ -2742,16 +2762,11 @@ function adapterLoop(specOf, options, deps) {
|
|
|
2742
2762
|
let parkOn;
|
|
2743
2763
|
/** The ask_person call the run waits on in its claim, while it does. */
|
|
2744
2764
|
let waitingOn;
|
|
2745
|
-
/** When the job's end was, once it is kept (keepJobEnd
|
|
2746
|
-
*
|
|
2765
|
+
/** When the job's end was, once it is kept (keepJobEnd; a grade's round's, by its steer's taking): the look-back
|
|
2766
|
+
* after it never moves it, and its end is written at that time. */
|
|
2747
2767
|
let keptAt;
|
|
2748
|
-
if (alone && lookingBack)
|
|
2768
|
+
if (alone && (lookingBack || feedbackNow))
|
|
2749
2769
|
({ end: data, failedWith, endedAt: keptAt } = await jobEndKept(root));
|
|
2750
|
-
else if (alone && feedbackNow?.kept) {
|
|
2751
|
-
const { endedAt, ...end } = feedbackNow.kept;
|
|
2752
|
-
data = end;
|
|
2753
|
-
keptAt = endedAt;
|
|
2754
|
-
}
|
|
2755
2770
|
else if (alone)
|
|
2756
2771
|
data = { state: "ended" };
|
|
2757
2772
|
else
|
|
@@ -2987,15 +3002,14 @@ function adapterLoop(specOf, options, deps) {
|
|
|
2987
3002
|
// takes the run past its cap is the learning's (askEndOfRun reads overCap after each of its turns), never the run's.
|
|
2988
3003
|
// That end is kept before the step's first ask, so a claim that finds its turn open ends the run on it (jobEndKept).
|
|
2989
3004
|
// Kept with its time: from then on every reader serves it, and the run's end is written at it (writeEnd `keptAt`).
|
|
2990
|
-
if (!lookingBack)
|
|
2991
|
-
keptAt = await keepJobEnd(harness, root, spec, data, failedWith
|
|
3005
|
+
if (!lookingBack && !feedbackNow)
|
|
3006
|
+
keptAt = await keepJobEnd(harness, root, spec, data, failedWith);
|
|
2992
3007
|
const step = await endOfRunStep(claim, spec, data.state === "failed" ? "failed" : "completed", overCap, keptAt);
|
|
2993
3008
|
// A stop or cancel the runner took during the step (one that raced the read refusing it, its row written while the
|
|
2994
3009
|
// run still read as going on) cuts the look-back alone: the run ends on its job's end, the row taken by that end.
|
|
2995
|
-
|
|
2996
|
-
return await writeEnd(harness, root, gate, data, [step.commandId], await cutRows(claim, spec, "stopped-looking"), failedWith, keptAt);
|
|
3010
|
+
// A step that runs always has its job's end kept (`keptAt`), so a stop there never ends the run stopped.
|
|
2997
3011
|
if (step.kind === "stopped")
|
|
2998
|
-
return await writeEnd(harness, root, gate,
|
|
3012
|
+
return await writeEnd(harness, root, gate, data, [step.commandId], await cutRows(claim, spec, "stopped-looking"), failedWith, keptAt);
|
|
2999
3013
|
if (step.kind === "interrupted")
|
|
3000
3014
|
return await interrupted(stopReason?.kind ?? "its claim's signal aborted");
|
|
3001
3015
|
return await writeEnd(harness, root, gate, data, [], step.also, failedWith, keptAt);
|
|
@@ -3382,20 +3396,23 @@ function adapterLoop(specOf, options, deps) {
|
|
|
3382
3396
|
return turnOfRequest(on, conversation, last.requestId);
|
|
3383
3397
|
}
|
|
3384
3398
|
/** How the job's own turn ended (`data`, and a CLI's error answer `failedWith`), as this claim decided it, kept on the
|
|
3385
|
-
* root before the end-of-run step asks its first turn (KINDS.jobEnd), for a run with a step to ask (stepOf).
|
|
3386
|
-
*
|
|
3387
|
-
|
|
3388
|
-
async function keepJobEnd(on, conversation, spec, data, failedWith, at) {
|
|
3399
|
+
* root before the end-of-run step asks its first turn (KINDS.jobEnd), for a run with a step to ask (stepOf). Kept with
|
|
3400
|
+
* its time, now, which it answers; with no step to ask, nothing is kept. */
|
|
3401
|
+
async function keepJobEnd(on, conversation, spec, data, failedWith) {
|
|
3389
3402
|
if (!stepOf(spec))
|
|
3390
|
-
return
|
|
3391
|
-
const
|
|
3392
|
-
const endedAt = at ?? now();
|
|
3393
|
-
const kept = { end, ...(failedWith !== undefined ? { failedWith } : {}), endedAt };
|
|
3403
|
+
return undefined;
|
|
3404
|
+
const kept = jobEndOf(data, failedWith, now());
|
|
3394
3405
|
await on.commit((tx) => tx.appendEntry(conversation.id, { kind: KINDS.jobEnd, data: kept }), context);
|
|
3395
|
-
return endedAt;
|
|
3406
|
+
return kept.endedAt;
|
|
3407
|
+
}
|
|
3408
|
+
/** A job's end as KINDS.jobEnd keeps it: its summary cut of every secret the runner holds, as every summary is when
|
|
3409
|
+
* served. */
|
|
3410
|
+
function jobEndOf(data, failedWith, endedAt) {
|
|
3411
|
+
const end = data.summary !== undefined && deps.redact ? { ...data, summary: deps.redact(data.summary) } : data;
|
|
3412
|
+
return { end, ...(failedWith !== undefined ? { failedWith } : {}), endedAt };
|
|
3396
3413
|
}
|
|
3397
|
-
/** The job's end for a claim that found the end-of-run turn open (lookingBackOpen)
|
|
3398
|
-
* follow-up's round keeps its own), never worked out again. */
|
|
3414
|
+
/** The job's end for a claim that found the end-of-run turn open (lookingBackOpen), or a grade's round (its steer's
|
|
3415
|
+
* taking kept it): the newest one kept (a follow-up's round keeps its own), never worked out again. */
|
|
3399
3416
|
async function jobEndKept(conversation) {
|
|
3400
3417
|
const kept = (await entriesOf(gate.journal, conversation.id, context)).filter((entry) => entry.kind === KINDS.jobEnd).at(-1);
|
|
3401
3418
|
if (!kept)
|
|
@@ -11,6 +11,7 @@ import type { Store } from "../store/store.js";
|
|
|
11
11
|
import { type ArgumentsOf, type Permission, type RunFiles, type SettingFrom, type ToolEffect } from "../tool-gate.js";
|
|
12
12
|
import { loadToolSettings } from "../tool-plane.js";
|
|
13
13
|
import { type EmailFake, type ToolHost } from "../tools.js";
|
|
14
|
+
import type { SaveSlots } from "../web-save.js";
|
|
14
15
|
import type { WebFake } from "../web-fake.js";
|
|
15
16
|
import { type HostToolCtx } from "../host-tools.js";
|
|
16
17
|
import { type LearnedWorkflow } from "../learning.js";
|
|
@@ -108,8 +109,8 @@ export interface AdapterSpecDeps {
|
|
|
108
109
|
readonly computerDeps: ComputerDeps;
|
|
109
110
|
/** A Mode 2 claim's Archil disk (a test's fake); absent, the real disk the Archil settings name. */
|
|
110
111
|
readonly makeArchilDisk?: ArchilClaimOptions["makeDisk"];
|
|
111
|
-
/**
|
|
112
|
-
*
|
|
112
|
+
/** Archil's control plane, for a test's loopback fake (archilControlFake): its base URL and the fetch to call it with,
|
|
113
|
+
* the claim's control (where the run's disk is read and its mount credential minted). Absent, the region's own. No
|
|
113
114
|
* test ever reaches the real Archil control plane. */
|
|
114
115
|
readonly mountControl?: {
|
|
115
116
|
readonly baseUrl?: string;
|
|
@@ -155,8 +156,10 @@ export interface AdapterSpecDeps {
|
|
|
155
156
|
* on purpose does not wait out MODEL_RETRY's two and a half minutes. No environment variable, flag or setting maps onto
|
|
156
157
|
* it; absent, MODEL_RETRY and MODEL_STREAM. */
|
|
157
158
|
readonly modelRetry?: Pick<AdapterLoopOptions, "retry" | "stream">;
|
|
159
|
+
/** web_save's download slots (ToolHost.saveSlots): in a run's own process, its runner's (run-child.ts). */
|
|
160
|
+
readonly saveSlots?: SaveSlots;
|
|
158
161
|
}
|
|
159
|
-
/** One run's template eval fakes (template-eval.ts, from its case). `web`: its web_search and
|
|
162
|
+
/** One run's template eval fakes (template-eval.ts, from its case). `web`: its web_search, web_fetch and web_save answer from the
|
|
160
163
|
* case, and its harness's own search is never offered (web-fake.ts, fakedPlane). `now`: its clock, the date and time it
|
|
161
164
|
* is told wherever it reads "now" (environment.ts environmentLine, claude-agent's turn date); absent, the real clock.
|
|
162
165
|
* `monid`: its monid endpoints answer as monid unreachable does, never sent (monid-run.ts monidForClaim). `email`: the
|
|
@@ -347,6 +350,8 @@ export declare function buildToolHost(opts: {
|
|
|
347
350
|
readonly own?: readonly string[];
|
|
348
351
|
/** A runner on another host than its server: where the run's viewers answer, under its run's key (claimLiveAt). */
|
|
349
352
|
readonly liveAt?: RunnerLive;
|
|
353
|
+
/** web_save's download slots (AdapterSpecDeps.saveSlots). */
|
|
354
|
+
readonly saveSlots?: SaveSlots;
|
|
350
355
|
}): ToolHost;
|
|
351
356
|
/** Where the claim's viewers answer on a runner on another host than its server (live-reach.ts runnerLiveOf), under the
|
|
352
357
|
* claim's run's own proof key (liveForRun); none on the server's machine. In a run's own process its runner's
|