@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
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** The env name a claim's model routes read the metadata from: the JSON the header carries. */
|
|
2
|
+
export const REQUEST_METADATA_ENV = "AGENTRUN_REQUEST_METADATA";
|
|
3
|
+
/** LiteLLM's header for metadata it keeps on a call's spend-log row (LiteLLM v1.110.0 and later). */
|
|
4
|
+
export const SPEND_LOGS_METADATA_HEADER = "x-litellm-spend-logs-metadata";
|
|
5
|
+
/** The metadata of `claim`'s requests: its run, and its turn and attempt where its store keeps them. */
|
|
6
|
+
export function requestMetadataOf(claim) {
|
|
7
|
+
return { agentrun_run_id: claim.runId, ...(claim.turn !== undefined ? { agentrun_turn: claim.turn } : {}), ...(claim.attempt !== undefined ? { agentrun_attempt: claim.attempt } : {}) };
|
|
8
|
+
}
|
|
9
|
+
/** `env` with `claim`'s request metadata on it, by name and never enumerable (as a model key is); `env` itself when there
|
|
10
|
+
* is no claim. The same object is changed and returned: a claim's model env is its own (claimModelEnv makes it). */
|
|
11
|
+
export function withRequestMetadata(env, claim) {
|
|
12
|
+
if (!claim)
|
|
13
|
+
return env;
|
|
14
|
+
Object.defineProperty(env, REQUEST_METADATA_ENV, { value: JSON.stringify(requestMetadataOf(claim)), enumerable: false, writable: true, configurable: true });
|
|
15
|
+
return env;
|
|
16
|
+
}
|
|
17
|
+
/** The headers a request to serve's gateway carries from `env`: the spend-logs metadata, when the claim set it and it is
|
|
18
|
+
* one line of JSON an HTTP header can carry (the proxy's own bound on a host's header, 1024 characters). None else. */
|
|
19
|
+
export function gatewayHeadersOf(env) {
|
|
20
|
+
const value = env[REQUEST_METADATA_ENV];
|
|
21
|
+
if (typeof value !== "string" || value.length === 0 || value.length > 1024 || /[^\x20-\x7e]/.test(value))
|
|
22
|
+
return undefined;
|
|
23
|
+
return { [SPEND_LOGS_METADATA_HEADER]: value };
|
|
24
|
+
}
|
package/dist/run-launch.d.ts
CHANGED
|
@@ -19,6 +19,16 @@ export interface RunLaunch {
|
|
|
19
19
|
workflow_tools?: SdkWorkflowTool[];
|
|
20
20
|
workflow_adapters?: SdkWorkflowAdapter[];
|
|
21
21
|
};
|
|
22
|
+
readonly cli_learning?: {
|
|
23
|
+
runtime: "codex-cli" | "claude-code-cli";
|
|
24
|
+
connection_id: string;
|
|
25
|
+
connection_generation: string;
|
|
26
|
+
session_id: string;
|
|
27
|
+
turn_id: string;
|
|
28
|
+
instructions: string;
|
|
29
|
+
policy_complete: boolean;
|
|
30
|
+
model?: string;
|
|
31
|
+
};
|
|
22
32
|
readonly native?: NativeBinding;
|
|
23
33
|
/** The start request's body, as the person or trigger gave it, or an object a built-in run names. */
|
|
24
34
|
readonly input: unknown;
|
|
@@ -50,6 +60,10 @@ export interface RunLaunch {
|
|
|
50
60
|
/** The uploaded file ids the run was started with, in order (the create body's file_ids, already checked ready): the
|
|
51
61
|
* runner copies them into the run's work/inputs/ at its claim, as the old start copied them before the process ran. */
|
|
52
62
|
readonly files?: readonly string[];
|
|
63
|
+
/** The server copied `files` into the run's folder (work/inputs/) when it started the run, before its row was written:
|
|
64
|
+
* a run on an Archil disk (Mode 2, uploads-archil.ts placeRunFiles). Its claim reads no upload (uploads.ts
|
|
65
|
+
* filesToCopy). Absent: the claim copies them from the server's data directory, as before. */
|
|
66
|
+
readonly filesPlaced?: true;
|
|
53
67
|
/** The run's learning start, when its agent learns and the server's learning is on, decided once here so the runner reads
|
|
54
68
|
* no learning folder or git: `seed`, the learning commit's sha (or null when the seed could not be read); `section`,
|
|
55
69
|
* the exact # Learned text to lay into the prompt (its owner's corrections, learning.ts learnedSection); `workflows`,
|
|
@@ -57,7 +71,8 @@ export interface RunLaunch {
|
|
|
57
71
|
* never answered by a learned workflow and asked for no workflow draft at its end (a native run, an SDK run with no
|
|
58
72
|
* workflow binding); `model`, the model an SDK run's compile turn is asked on (its agent's own); `seedFailed`, why it
|
|
59
73
|
* starts with nothing learned when it does (SeedFailed); `use`, a run started with `learning: "use"` (learning.ts
|
|
60
|
-
* RUN_LEARNING_USE): it starts from all of the above and keeps nothing
|
|
74
|
+
* RUN_LEARNING_USE): it starts from all of the above and keeps nothing; `seededAt`, when its seed was read (learning.ts
|
|
75
|
+
* Seed.at), which the agent's reset watermark is read against. Absent when the run does not learn. */
|
|
61
76
|
readonly learning?: {
|
|
62
77
|
readonly seed: string | null;
|
|
63
78
|
readonly section: string;
|
|
@@ -66,6 +81,7 @@ export interface RunLaunch {
|
|
|
66
81
|
readonly model?: string;
|
|
67
82
|
readonly seedFailed?: SeedFailed;
|
|
68
83
|
readonly use?: true;
|
|
84
|
+
readonly seededAt?: number;
|
|
69
85
|
};
|
|
70
86
|
/** `false`: the run never starts on a learned workflow, even one that fits its input (RunCreate `workflow_first`,
|
|
71
87
|
* runner/workflow-first.ts); its agent takes it from its first turn. Absent: a fitting one serves first. */
|
|
@@ -112,6 +128,12 @@ export declare function keepInputOrigin(stored: unknown, trigger: RunTrigger | n
|
|
|
112
128
|
/** The JSON body the server stores for a run's launch. `harness` is a top-level field, so the loop factory reads it from the
|
|
113
129
|
* stored body without parsing the rest. */
|
|
114
130
|
export declare function launchBody(launch: RunLaunch): Json;
|
|
131
|
+
/** The launch a runner runs (runner/dispatch.ts, run-child-host.ts): on a disk the launch names as its own (kind
|
|
132
|
+
* "launch"), its learning start holds no seed, # Learned section or learned workflow, whatever the body says (a start
|
|
133
|
+
* made before its run's disk was read, or written by hand), as the server's seed is the default disk's, never that
|
|
134
|
+
* disk's (learn/learning-of.ts): the run starts with nothing learned (`other_disk`), its flags kept. Any other launch as
|
|
135
|
+
* read. readLaunchBody keeps the body as written: a finished run's views show what it ran. */
|
|
136
|
+
export declare function launchOnItsDisk(launch: RunLaunch): RunLaunch;
|
|
115
137
|
/** A launch body read back into a `RunLaunch`, with the input-origin fail-safe applied through the body's own trigger, or
|
|
116
138
|
* undefined when the body is not one (not an object, or it names no place: a damaged or hand-edited body). */
|
|
117
139
|
export declare function readLaunchBody(stored: unknown): RunLaunch | undefined;
|
|
@@ -121,9 +143,10 @@ export declare const learningStartOf: (launch: RunLaunch) => RunLaunch["learning
|
|
|
121
143
|
/** The same start read from a launch body's `learning` member alone (Store.runs.learningStarts), as readLaunchBody reads it. */
|
|
122
144
|
export declare const learningStartOfStored: (stored: unknown) => RunLaunch["learning"];
|
|
123
145
|
/** Why a learning run starts with nothing learned, as main says it: its agent's learning folder could not be read
|
|
124
|
-
* (`unreadable`, STOPPED.unreadable),
|
|
125
|
-
* STOPPED.notCopied)
|
|
126
|
-
|
|
146
|
+
* (`unreadable`, STOPPED.unreadable), what was read could not be made into its start (`not_copied`,
|
|
147
|
+
* STOPPED.notCopied), or its launch names a disk of its own, whose learning folder the server does not read
|
|
148
|
+
* (`other_disk`, STOPPED.otherDisk): a run on a named disk learns nothing (learn/learning-of.ts). */
|
|
149
|
+
export type SeedFailed = "unreadable" | "not_copied" | "other_disk";
|
|
127
150
|
/** A learning start with no seed (no commit of main, runs-over-store.ts learningStartFor): the run learns nothing, is
|
|
128
151
|
* never asked what to keep, and so is never told it learns. Why is its `seedFailed`, when its start records one. */
|
|
129
152
|
export declare const seedFailed: (start: NonNullable<RunLaunch["learning"]>) => boolean;
|
package/dist/run-launch.js
CHANGED
|
@@ -54,6 +54,7 @@ export function launchBody(launch) {
|
|
|
54
54
|
return {
|
|
55
55
|
input: launch.input,
|
|
56
56
|
...(launch.sdk ? { sdk: launch.sdk } : {}),
|
|
57
|
+
...(launch.cli_learning ? { cli_learning: launch.cli_learning } : {}),
|
|
57
58
|
...(launch.native ? { native: launch.native } : {}),
|
|
58
59
|
title: launch.title,
|
|
59
60
|
...(launch.repo !== undefined ? { repo: launch.repo } : {}),
|
|
@@ -68,7 +69,8 @@ export function launchBody(launch) {
|
|
|
68
69
|
...(launch.boxAllow !== undefined ? { box_allow: launch.boxAllow } : {}),
|
|
69
70
|
...(launch.boxAllowSet ? { box_allow_set: true } : {}),
|
|
70
71
|
...(launch.files?.length ? { files: launch.files } : {}),
|
|
71
|
-
...(launch.
|
|
72
|
+
...(launch.filesPlaced ? { files_placed: true } : {}),
|
|
73
|
+
...(launch.learning ? { learning: { seed: launch.learning.seed, section: launch.learning.section, ...(launch.learning.workflows?.length ? { workflows: [...launch.learning.workflows] } : {}), ...(launch.learning.noWorkflows ? { noWorkflows: true } : {}), ...(launch.learning.model ? { model: launch.learning.model } : {}), ...(launch.learning.seedFailed ? { seedFailed: launch.learning.seedFailed } : {}), ...(launch.learning.use ? { use: true } : {}), ...(launch.learning.seededAt !== undefined ? { seededAt: launch.learning.seededAt } : {}) } } : {}),
|
|
72
74
|
...(launch.workflowFirst === false ? { workflow_first: false } : {}),
|
|
73
75
|
...(launch.replay ? { replay: { of: launch.replay.of, workflow: launch.replay.workflow, digest: launch.replay.digest } } : {}),
|
|
74
76
|
...(launch.audit ? { audit: { of: launch.audit.of, workflow: launch.audit.workflow, digest: launch.audit.digest } } : {}),
|
|
@@ -88,7 +90,18 @@ function readLearning(value) {
|
|
|
88
90
|
const seed = typeof value.seed === "string" ? value.seed : null;
|
|
89
91
|
const section = typeof value.section === "string" ? value.section : "";
|
|
90
92
|
const workflows = Array.isArray(value.workflows) ? value.workflows.filter((name) => typeof name === "string") : [];
|
|
91
|
-
return { seed, section, ...(workflows.length ? { workflows } : {}), ...(value.noWorkflows === true ? { noWorkflows: true } : {}), ...(typeof value.model === "string" && value.model !== "" ? { model: value.model } : {}), ...(typeof value.seedFailed === "string" && SEED_FAILURES.includes(value.seedFailed) ? { seedFailed: value.seedFailed } : {}), ...(value.use === true ? { use: true } : {}) };
|
|
93
|
+
return { seed, section, ...(workflows.length ? { workflows } : {}), ...(value.noWorkflows === true ? { noWorkflows: true } : {}), ...(typeof value.model === "string" && value.model !== "" ? { model: value.model } : {}), ...(typeof value.seedFailed === "string" && SEED_FAILURES.includes(value.seedFailed) ? { seedFailed: value.seedFailed } : {}), ...(value.use === true ? { use: true } : {}), ...(typeof value.seededAt === "number" && Number.isFinite(value.seededAt) ? { seededAt: value.seededAt } : {}) };
|
|
94
|
+
}
|
|
95
|
+
/** The launch a runner runs (runner/dispatch.ts, run-child-host.ts): on a disk the launch names as its own (kind
|
|
96
|
+
* "launch"), its learning start holds no seed, # Learned section or learned workflow, whatever the body says (a start
|
|
97
|
+
* made before its run's disk was read, or written by hand), as the server's seed is the default disk's, never that
|
|
98
|
+
* disk's (learn/learning-of.ts): the run starts with nothing learned (`other_disk`), its flags kept. Any other launch as
|
|
99
|
+
* read. readLaunchBody keeps the body as written: a finished run's views show what it ran. */
|
|
100
|
+
export function launchOnItsDisk(launch) {
|
|
101
|
+
if (!launch.learning || launch.archilDisk?.kind !== "launch")
|
|
102
|
+
return launch;
|
|
103
|
+
const { noWorkflows, model, use } = launch.learning;
|
|
104
|
+
return { ...launch, learning: { seed: null, section: "", seedFailed: "other_disk", ...(noWorkflows ? { noWorkflows } : {}), ...(model ? { model } : {}), ...(use ? { use } : {}) } };
|
|
92
105
|
}
|
|
93
106
|
/** A launch body read back into a `RunLaunch`, with the input-origin fail-safe applied through the body's own trigger, or
|
|
94
107
|
* undefined when the body is not one (not an object, or it names no place: a damaged or hand-edited body). */
|
|
@@ -107,6 +120,7 @@ export function readLaunchBody(stored) {
|
|
|
107
120
|
input: stored.input,
|
|
108
121
|
...(isObject(stored.sdk) && sdkBindingOf(stored.sdk) && typeof stored.sdk.instructions === "string" ? { sdk: stored.sdk } : {}),
|
|
109
122
|
...(nativeOf(stored) ? { native: nativeOf(stored) } : {}),
|
|
123
|
+
...(isObject(stored.cli_learning) && ["codex-cli", "claude-code-cli"].includes(String(stored.cli_learning.runtime)) && typeof stored.cli_learning.instructions === "string" ? { cli_learning: stored.cli_learning } : {}),
|
|
110
124
|
title: typeof stored.title === "string" ? stored.title : "",
|
|
111
125
|
...(typeof stored.repo === "string" ? { repo: stored.repo } : {}),
|
|
112
126
|
place,
|
|
@@ -120,6 +134,7 @@ export function readLaunchBody(stored) {
|
|
|
120
134
|
...(boxAllow !== undefined ? { boxAllow } : {}),
|
|
121
135
|
...(stored.box_allow_set === true ? { boxAllowSet: true } : {}),
|
|
122
136
|
...(Array.isArray(stored.files) && stored.files.every((id) => typeof id === "string") ? { files: stored.files } : {}),
|
|
137
|
+
...(stored.files_placed === true ? { filesPlaced: true } : {}),
|
|
123
138
|
...(stored.learning !== undefined ? { learning: readLearning(stored.learning) ?? { seed: null, section: "" } } : {}),
|
|
124
139
|
...(stored.workflow_first === false ? { workflowFirst: false } : {}),
|
|
125
140
|
...(readReplay(stored.replay) ? { replay: readReplay(stored.replay) } : {}),
|
|
@@ -136,7 +151,7 @@ export function readLaunchBody(stored) {
|
|
|
136
151
|
export const learningStartOf = (launch) => launch.learning;
|
|
137
152
|
/** The same start read from a launch body's `learning` member alone (Store.runs.learningStarts), as readLaunchBody reads it. */
|
|
138
153
|
export const learningStartOfStored = (stored) => (stored === undefined ? undefined : readLearning(stored) ?? { seed: null, section: "" });
|
|
139
|
-
const SEED_FAILURES = ["unreadable", "not_copied"];
|
|
154
|
+
const SEED_FAILURES = ["unreadable", "not_copied", "other_disk"];
|
|
140
155
|
/** A learning start with no seed (no commit of main, runs-over-store.ts learningStartFor): the run learns nothing, is
|
|
141
156
|
* never asked what to keep, and so is never told it learns. Why is its `seedFailed`, when its start records one. */
|
|
142
157
|
export const seedFailed = (start) => start.seed === null;
|
|
@@ -9,7 +9,7 @@ export declare function servedRunLearning(deps: {
|
|
|
9
9
|
}, store: Store, runId: string): Promise<{
|
|
10
10
|
run: string;
|
|
11
11
|
state: "dropped" | "merged" | "seeded" | "reflecting";
|
|
12
|
-
reason: "cancelled" | "use" | "empty" | "crashed" | "reflect_failed" | "no_budget" | "checker" | "unknown_cost" | "seed_failed" | null;
|
|
12
|
+
reason: "cancelled" | "reset" | "use" | "empty" | "crashed" | "reflect_failed" | "no_budget" | "checker" | "unknown_cost" | "seed_failed" | null;
|
|
13
13
|
detail: string | null;
|
|
14
14
|
at: string;
|
|
15
15
|
workflows: import("./learning.js").LearnedFile[];
|
|
@@ -52,7 +52,7 @@ export declare function servedRunLearning(deps: {
|
|
|
52
52
|
};
|
|
53
53
|
run: string;
|
|
54
54
|
state: "dropped" | "merged" | "seeded" | "reflecting";
|
|
55
|
-
reason: "cancelled" | "use" | "empty" | "crashed" | "reflect_failed" | "no_budget" | "checker" | "unknown_cost" | "seed_failed" | null;
|
|
55
|
+
reason: "cancelled" | "reset" | "use" | "empty" | "crashed" | "reflect_failed" | "no_budget" | "checker" | "unknown_cost" | "seed_failed" | null;
|
|
56
56
|
detail: string | null;
|
|
57
57
|
at: string;
|
|
58
58
|
workflows: import("./learning.js").LearnedFile[];
|
package/dist/run-usage.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { type BrowserSessionLine } from "./browser-sessions.js";
|
|
|
2
2
|
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
|
-
import { type ComputerIntervalRow, type Store } from "./store/index.js";
|
|
5
|
+
import { type ComputerIntervalRow, type RunAttemptRow, type Store } from "./store/index.js";
|
|
6
6
|
import { type ComputeResource, type ComputeUnit } from "./compute-cost.js";
|
|
7
7
|
import { type EntryLike } from "./timeline/index.js";
|
|
8
8
|
/** The meters a run's lines are on: the contract's `tokens` and `browser_time`, and this server's `tools` and
|
|
@@ -26,6 +26,12 @@ export type RunUsageLine = {
|
|
|
26
26
|
quantity: number | null;
|
|
27
27
|
unit: "token" | "call" | "second" | ComputeUnit;
|
|
28
28
|
basis: CostBasis;
|
|
29
|
+
/** The attempt at its turn the line's requests were made in (1 the first, 2 its first redo, …); null for a run whose
|
|
30
|
+
* claims kept no attempt. */
|
|
31
|
+
attempt: number | null;
|
|
32
|
+
/** False for an attempt that was cut and whose turn another attempt worked again: its requests were made again, the
|
|
33
|
+
* infrastructure's cost (the run's `infra_usd`), not the task's. Charging does not read it yet. */
|
|
34
|
+
billable: boolean;
|
|
29
35
|
/** On `compute_time`: the resource (vcpu, memory, gpu, disk), a GPU's type, the part of `quantity` no claim held (in
|
|
30
36
|
* no cost), and how many of its computers are still open, their time counted up to `measured_to`. */
|
|
31
37
|
resource?: ComputeResource;
|
|
@@ -61,10 +67,14 @@ export type RunUsage = {
|
|
|
61
67
|
lines: RunUsageLine[] | null;
|
|
62
68
|
/** One record per browser session the run opened (browser-sessions.ts), for matching `browser_time` to the provider's
|
|
63
69
|
* own records by its session id; null exactly when `lines` is. */
|
|
64
|
-
browser_sessions:
|
|
70
|
+
browser_sessions: RunBrowserSession[] | null;
|
|
65
71
|
/** One record per computer the run made (computerIntervalsOf), by when each was made; null exactly when `lines` is.
|
|
66
72
|
* Computer time is not priced: its cost is in no line and not in `total`. */
|
|
67
73
|
computer_intervals: ComputerIntervalLine[] | null;
|
|
74
|
+
/** The sum of the lines that are not billable (`billable: false`): what the infrastructure's redo of cut attempts cost.
|
|
75
|
+
* 0 for a run no attempt of which was cut; null with no lines, and when one such line's cost is unknown. Inside
|
|
76
|
+
* `total`, never beside it. */
|
|
77
|
+
infra_usd: number | null;
|
|
68
78
|
reason: UsageReason | null;
|
|
69
79
|
};
|
|
70
80
|
/** One computer the run made through its provider (a sandbox, a desktop, a phone), as GET /runs/{run_id}/usage serves
|
|
@@ -88,9 +98,38 @@ export type ComputerIntervalLine = {
|
|
|
88
98
|
ended_at: string | null;
|
|
89
99
|
kept: boolean;
|
|
90
100
|
booked_seconds: number;
|
|
101
|
+
/** The attempt whose claim made the computer, and whether that attempt is billable (RunUsageLine). */
|
|
102
|
+
attempt: number | null;
|
|
103
|
+
billable: boolean;
|
|
91
104
|
};
|
|
92
105
|
/** The run's computer rows as served (ComputerIntervalLine), in the order the store reads them (by when each was made). */
|
|
93
|
-
export declare function computerIntervalsOf(rows: readonly ComputerIntervalRow[]): ComputerIntervalLine[];
|
|
106
|
+
export declare function computerIntervalsOf(rows: readonly ComputerIntervalRow[], attempts?: readonly RunAttemptRow[]): ComputerIntervalLine[];
|
|
107
|
+
/** Which attempt a part of a run's usage was made in, and whether it is billable. */
|
|
108
|
+
export type AttemptTag = {
|
|
109
|
+
attempt: number | null;
|
|
110
|
+
billable: boolean;
|
|
111
|
+
};
|
|
112
|
+
/** A run's attempts (`rows`, by epoch) as tags: the attempt a journal entry was written in (the last claim whose first
|
|
113
|
+
* 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
|
|
114
|
+
* store's clock: a computer is made a moment after its claim). `spans` splits a stretch of time across the claims whose
|
|
115
|
+
* windows it falls in (each claim's window runs from its claim to the next claim's). Every part is billable: a claim
|
|
116
|
+
* that takes over a cut turn resumes from what the cut one saved (its answered requests, its finished calls), so that
|
|
117
|
+
* work is the task's, done once. `redoneAt` is the one exception: the attempt an entry was written in, billable unless
|
|
118
|
+
* another claim worked its turn again after it (the same turn, one attempt more), for a model request that attempt sent
|
|
119
|
+
* and never finished (usageLinesOf), which the claim after it sends again. With no rows (a run from before
|
|
120
|
+
* them), every part is NO_ATTEMPT: attempt null, billable. A part before the first row is NO_ATTEMPT too, unless that
|
|
121
|
+
* row is the run's first claim (taken from queued): then nothing came before it, and a part read a moment early (a
|
|
122
|
+
* runner's clock behind the store's) is that claim's. A run that took its first row after the change that writes them
|
|
123
|
+
* (an older run's follow-up) never counts what it did before as any attempt's. */
|
|
124
|
+
export declare function attemptTags(rows: readonly RunAttemptRow[]): {
|
|
125
|
+
atEntry(id: unknown): AttemptTag;
|
|
126
|
+
redoneAt(id: unknown): AttemptTag;
|
|
127
|
+
atTime(ms: number): AttemptTag;
|
|
128
|
+
spans(from: number, to: number): {
|
|
129
|
+
at: AttemptTag;
|
|
130
|
+
ms: number;
|
|
131
|
+
}[];
|
|
132
|
+
};
|
|
94
133
|
/** A workflow decision's receipt as the lines read it (store-reads/decisions.ts): by its `decision_id`, which its
|
|
95
134
|
* request's booking names (`decision:<id>`), the model and provider that answered it, and how its cost was reached. */
|
|
96
135
|
export type DecisionReceiptLike = {
|
|
@@ -107,10 +146,15 @@ export type DecisionReceiptLike = {
|
|
|
107
146
|
export declare function usageLinesOf(entries: readonly EntryLike[], launch?: Pick<RunLaunch, "model">, receipts?: ReadonlyMap<string, DecisionReceiptLike>, computers?: {
|
|
108
147
|
readonly rows: readonly ComputerIntervalRow[];
|
|
109
148
|
readonly at: number;
|
|
110
|
-
}): {
|
|
149
|
+
}, attempts?: readonly RunAttemptRow[]): {
|
|
111
150
|
lines: RunUsageLine[];
|
|
112
151
|
total: CostWords;
|
|
113
152
|
};
|
|
153
|
+
/** A browser session as the usage read serves it: its record (BrowserSessionLine), and the attempt whose claim opened it
|
|
154
|
+
* and whether that attempt is billable (RunUsageLine). */
|
|
155
|
+
export type RunBrowserSession = BrowserSessionLine & AttemptTag;
|
|
156
|
+
/** The sum of the lines no customer is charged for (`billable: false`): null when one of them has no known figure. */
|
|
157
|
+
export declare function infraUsdOf(lines: readonly RunUsageLine[]): number | null;
|
|
114
158
|
/** Run `runId`'s usage lines (GET /runs/{run_id}/usage); undefined for an unknown run. No lines (`reason`) while it is at
|
|
115
159
|
* work, for a run whose figure is not its booking's, and for a learning run a follow-up opened again: the cases where
|
|
116
160
|
* `cost.tools_usd` is null for the same reasons. Its state, launch, learning rounds and journal are read in one snapshot
|