@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,125 @@
|
|
|
1
|
+
// `agentrun-serve store-schema [--data DIR]`: the live store's schema version and runner floor, beside the version this
|
|
2
|
+
// build knows, as one line of JSON, for a deploy pipeline's skew guard. It reads, and nothing else: no owner lock, no
|
|
3
|
+
// migration, no schema made, no runner presence. The store is the one the server and a runner open (store/open.ts:
|
|
4
|
+
// Postgres when AGENTRUN_STORE_URL names one, in AGENTRUN_STORE_SCHEMA; else SQLite in --data), and its URL is never
|
|
5
|
+
// printed. Exit 0 once read (whatever it says), 1 when the store could not be read, 2 for bad arguments. `--build` reads no
|
|
6
|
+
// store: it prints the versions this build knows, `{"build":{"postgres":N,"sqlite":M}}`, for a label an image build stamps.
|
|
7
|
+
//
|
|
8
|
+
// What the line says, run with the build about to be deployed:
|
|
9
|
+
// schema the store's version now (null: none set up yet)
|
|
10
|
+
// runnerFloor the oldest version a runner's build must know to run on it (null: none set up yet)
|
|
11
|
+
// build the version this build knows
|
|
12
|
+
// server what this build's server does at its start: "sets up", "opens", "migrates", or "refuses" (the store is
|
|
13
|
+
// ahead of this build: a rollback across a migration, which the skew guard refuses)
|
|
14
|
+
// runner what this build's runner does: "opens", "waits" (for the server to migrate), or "refused" (none set up,
|
|
15
|
+
// or the floor is above this build)
|
|
16
|
+
import { existsSync } from "node:fs";
|
|
17
|
+
import { join } from "node:path";
|
|
18
|
+
import { DatabaseSync } from "node:sqlite";
|
|
19
|
+
import { parseArgs } from "node:util";
|
|
20
|
+
import { migrationsIn, runnerFloorOf, runnerOn } from "./postgres/migrate.js";
|
|
21
|
+
import { STORE_CONNECT_TIMEOUT_MS } from "./postgres/connection.js";
|
|
22
|
+
import { storePlace, storeTarget } from "./open.js";
|
|
23
|
+
import { SCHEMA_VERSION } from "./schema.js";
|
|
24
|
+
import { earlierVersionIn, runnerWaitsFor, STORE_FILE } from "./sqlite/store.js";
|
|
25
|
+
/** The SQLite store's versions the server upgrades in place (sqlite/store.ts openSqliteStore). */
|
|
26
|
+
const SQLITE_UPGRADES = new Set([11, 12, 13, 14]);
|
|
27
|
+
/** What a build that knows `build` does with a store at `state`, on `kind`. `earlier`: the data directory holds an earlier
|
|
28
|
+
* version's files (SQLite only), which this build's server refuses to start beside (StoreFromEarlierVersion). `awaits`:
|
|
29
|
+
* on SQLite at this build's version, a column this build's runner needs that the file lacks (SQLITE_RUNNER_NEEDS), which
|
|
30
|
+
* its server adds at its start: the runner waits for it, as openSqliteStore makes it. */
|
|
31
|
+
export function storeSchemaReport(target, state, build, earlier = false, awaits = false) {
|
|
32
|
+
const { version } = state;
|
|
33
|
+
const server = earlier
|
|
34
|
+
? "refuses"
|
|
35
|
+
: version === null ? "sets up" : version === build ? "opens" : version > build ? "refuses" : target.kind === "postgres" || SQLITE_UPGRADES.has(version) ? "migrates" : "refuses";
|
|
36
|
+
// A SQLite runner opens only its own version: its floor is the version (sqlite/store.ts schemaState).
|
|
37
|
+
// On SQLite a runner waits only for a version its server upgrades in place (11-14), and refuses any other earlier one.
|
|
38
|
+
const runner = target.kind === "sqlite" && version !== null && version < build && !SQLITE_UPGRADES.has(version)
|
|
39
|
+
? "refused"
|
|
40
|
+
: awaits && version === build ? "waits" : runnerOn(target.kind === "sqlite" ? { version, runnerFloor: version } : state, build);
|
|
41
|
+
return { store: target.kind, where: storePlace(target), schema: version, runnerFloor: state.runnerFloor, build, server, runner };
|
|
42
|
+
}
|
|
43
|
+
/** The SQLite store's version in `dataDir`, read-only: null when there is no file, or no schema in it; and whether a
|
|
44
|
+
* runner of this build would wait for its server to add a column (SQLITE_RUNNER_NEEDS). */
|
|
45
|
+
async function sqliteState(dataDir) {
|
|
46
|
+
const file = join(dataDir, STORE_FILE);
|
|
47
|
+
if (!existsSync(file))
|
|
48
|
+
return { version: null, runnerFloor: null, awaits: false };
|
|
49
|
+
const db = new DatabaseSync(file, { readOnly: true, timeout: 5_000 });
|
|
50
|
+
try {
|
|
51
|
+
const table = db.prepare("SELECT name FROM sqlite_schema WHERE type = 'table' AND name = 'store_meta'").get();
|
|
52
|
+
const row = table ? db.prepare("SELECT schema_version FROM store_meta WHERE singleton = 1").get() : undefined;
|
|
53
|
+
const version = row?.schema_version ?? null;
|
|
54
|
+
const columnsOf = (name) => new Set(db.prepare("SELECT name FROM pragma_table_info(?)").all(name).map((column) => column.name));
|
|
55
|
+
const awaits = version !== null && (await runnerWaitsFor(columnsOf)) !== undefined;
|
|
56
|
+
return { version, runnerFloor: version, awaits };
|
|
57
|
+
}
|
|
58
|
+
finally {
|
|
59
|
+
db.close();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/** How long the read waits on Postgres (ms): for a lock (a server migrating holds the ledger's), for its one statement, and
|
|
63
|
+
* for any answer at all (a database that took the connection and went silent). Past one, the read fails: exit 1. */
|
|
64
|
+
export const STORE_SCHEMA_LOCK_MS = 2_000;
|
|
65
|
+
export const STORE_SCHEMA_STATEMENT_MS = 5_000;
|
|
66
|
+
export const STORE_SCHEMA_ANSWER_MS = 6_000;
|
|
67
|
+
/** The Postgres schema's version and floor, on a connection of its own that writes nothing and is ended at once. Its
|
|
68
|
+
* session's timeouts bound it: a deploy check never waits on a server's migration or on a silent database. */
|
|
69
|
+
async function postgresState(url, schema) {
|
|
70
|
+
const { default: pg } = await import("pg");
|
|
71
|
+
const client = new pg.Client({
|
|
72
|
+
connectionString: url,
|
|
73
|
+
connectionTimeoutMillis: STORE_CONNECT_TIMEOUT_MS,
|
|
74
|
+
lock_timeout: STORE_SCHEMA_LOCK_MS,
|
|
75
|
+
statement_timeout: STORE_SCHEMA_STATEMENT_MS,
|
|
76
|
+
query_timeout: STORE_SCHEMA_ANSWER_MS,
|
|
77
|
+
application_name: "agentrun-store-schema",
|
|
78
|
+
});
|
|
79
|
+
client.on("error", () => undefined);
|
|
80
|
+
await client.connect();
|
|
81
|
+
try {
|
|
82
|
+
return await runnerFloorOf(client, schema);
|
|
83
|
+
}
|
|
84
|
+
finally {
|
|
85
|
+
await client.end().catch(() => undefined);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/** Reads the store `dataDir` and `env` name (and the URL, this process's AGENTRUN_STORE_URL secret unless given). */
|
|
89
|
+
export async function readStoreSchema(dataDir, env = process.env, url) {
|
|
90
|
+
const target = url === undefined ? storeTarget(dataDir, env) : storeTarget(dataDir, env, url);
|
|
91
|
+
if (target.kind === "sqlite") {
|
|
92
|
+
const { awaits, ...state } = await sqliteState(dataDir);
|
|
93
|
+
return storeSchemaReport(target, state, SCHEMA_VERSION, earlierVersionIn(dataDir, 5_000).length > 0, awaits);
|
|
94
|
+
}
|
|
95
|
+
return storeSchemaReport(target, await postgresState(target.url, target.schema), migrationsIn().at(-1).version);
|
|
96
|
+
}
|
|
97
|
+
/** The versions this build knows, read from its own files, with no store: `postgres`, its newest migration; `sqlite`,
|
|
98
|
+
* SCHEMA_VERSION. */
|
|
99
|
+
export const buildSchema = () => ({ postgres: migrationsIn().at(-1).version, sqlite: SCHEMA_VERSION });
|
|
100
|
+
/** `agentrun-serve store-schema [--data DIR]`, or `--build` (this build's versions, no store read): the exit code (the
|
|
101
|
+
* file's head). */
|
|
102
|
+
export async function storeSchemaMain(argv, defaultDataDir, usage) {
|
|
103
|
+
let data;
|
|
104
|
+
let build;
|
|
105
|
+
try {
|
|
106
|
+
({ data, build } = parseArgs({ args: [...argv], options: { data: { type: "string" }, build: { type: "boolean" } } }).values);
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
console.error(`agentrun-serve store-schema: ${error.message}\n\n${usage}`);
|
|
110
|
+
return 2;
|
|
111
|
+
}
|
|
112
|
+
if (build) {
|
|
113
|
+
console.log(JSON.stringify({ build: buildSchema() }));
|
|
114
|
+
return 0;
|
|
115
|
+
}
|
|
116
|
+
try {
|
|
117
|
+
console.log(JSON.stringify(await readStoreSchema(data ?? defaultDataDir)));
|
|
118
|
+
return 0;
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
// Never the URL: a connection error's own words name the host at most.
|
|
122
|
+
console.error(`agentrun-serve store-schema: the store could not be read: ${error?.message ?? String(error)}`);
|
|
123
|
+
return 1;
|
|
124
|
+
}
|
|
125
|
+
}
|
package/dist/store/store.d.ts
CHANGED
|
@@ -26,6 +26,47 @@ export interface Claim {
|
|
|
26
26
|
readonly lost?: {
|
|
27
27
|
readonly runner: string;
|
|
28
28
|
};
|
|
29
|
+
/** Which turn of the run this claim works and which attempt at it (run_attempts, RunAttemptRow): set by the claim that
|
|
30
|
+
* took the run, absent on a claim read back (claimsOf) and on a store that keeps none (a test's). */
|
|
31
|
+
readonly turn?: number;
|
|
32
|
+
readonly attempt?: number;
|
|
33
|
+
}
|
|
34
|
+
/** Why a claim let its run go while the run was still at work, so another claim does that work again: `drain`, its
|
|
35
|
+
* runner closed (a deploy, a scale-down) and handed the run back; `retry`, its loop ended interrupted on its own (or its
|
|
36
|
+
* end was refused) and the run was released to be tried again; `lease_lapse`, its runner was there but could not renew
|
|
37
|
+
* the claim before it ran out; `crash`, the claim's lease ran out with nothing said of it (its runner died). */
|
|
38
|
+
export type AttemptCause = "drain" | "crash" | "lease_lapse" | "retry";
|
|
39
|
+
/** One claim of a run (store schema `run_attempts`), written by the claim itself: the turn it works and its attempt at
|
|
40
|
+
* it. A turn is the work one claim starts afresh: the run's first, a follow-up's, a resume after a park. A claim that
|
|
41
|
+
* takes over a turn another claim was cut from (its run still running, and that claim let it go for `cut`, or its lease
|
|
42
|
+
* ran out) works the same turn again: its attempt is one more, and `cause` says why the one before was cut. Infra's
|
|
43
|
+
* work, not the run's: every request the cut attempt made is made again. `journalFrom`: the first journal entry id this
|
|
44
|
+
* claim could write (the run's next id when it claimed), so each entry of the run's journal is read as its claim's. */
|
|
45
|
+
export interface RunAttemptRow {
|
|
46
|
+
readonly runId: string;
|
|
47
|
+
readonly epoch: number;
|
|
48
|
+
readonly turn: number;
|
|
49
|
+
readonly attempt: number;
|
|
50
|
+
/** Why the attempt before was cut; null on a turn's first attempt. */
|
|
51
|
+
readonly cause: AttemptCause | null;
|
|
52
|
+
/** Why this claim let the run go with its turn unfinished (`drain`, `retry`, `lease_lapse`); null while it holds the
|
|
53
|
+
* run, and when it ended the turn (an answer, a park, the run's end) or died without a word. */
|
|
54
|
+
readonly cut: Exclude<AttemptCause, "crash"> | null;
|
|
55
|
+
readonly runner: string;
|
|
56
|
+
readonly from: RunState;
|
|
57
|
+
readonly journalFrom: number;
|
|
58
|
+
/** When the claim took the run, on the store's clock (ms). */
|
|
59
|
+
readonly claimedAt: number;
|
|
60
|
+
}
|
|
61
|
+
/** Each claim of a run, its turn and attempt (RunAttemptRow): written in the claim's own transaction, its `cut` in its
|
|
62
|
+
* release's. Data only: nothing reads it to decide what a run does. */
|
|
63
|
+
export interface RunAttempts {
|
|
64
|
+
/** The claim at `epoch` lost its lease while its runner was there (runner.ts loseClaim): its cut, and the cause of the
|
|
65
|
+
* claim that took the run over from it if that one was read as a crash. Unfenced and idempotent: a cut already said, or
|
|
66
|
+
* a claim with no row, is left as it is. */
|
|
67
|
+
lapsed(runId: string, epoch: number): Promise<void>;
|
|
68
|
+
/** The run's claims, by epoch. */
|
|
69
|
+
forRun(runId: string): Promise<RunAttemptRow[]>;
|
|
29
70
|
}
|
|
30
71
|
/** A command the server wrote for a run (stop, cancel, steer, approve, deny, raise): one row, read by the run's runner in id order
|
|
31
72
|
* and marked taken, or refused with why. `body` is JSON. */
|
|
@@ -216,6 +257,10 @@ export interface RunRow {
|
|
|
216
257
|
readonly signInHanded: readonly string[] | null;
|
|
217
258
|
/** The caller's labels, given at its start (RunLabels): opaque to the server, kept as given, {} when none. */
|
|
218
259
|
readonly labels: RunLabels;
|
|
260
|
+
/** The disk the run's launch named as its own (a customer's Archil disk: the launch body's `archil_disk` of kind "launch"),
|
|
261
|
+
* by its id, written once with the queued run; null for a run on the default disk (its launch named none, or its agent's
|
|
262
|
+
* own). A run on a named disk learns nothing, so learning reads only runs with none (learn/learning-of.ts). */
|
|
263
|
+
readonly disk: string | null;
|
|
219
264
|
readonly startedAt: number;
|
|
220
265
|
readonly endedAt: number | null;
|
|
221
266
|
/** When the run was purged (Runs.purge): its row is then a tombstone, its cost and times kept, everything else of it
|
|
@@ -947,6 +992,17 @@ export interface Runs {
|
|
|
947
992
|
/** The run's launch row (the runner reads it at its claim; the server for views). StoreLaunchMissing when the run has
|
|
948
993
|
* none (it was not started with one), never a default. */
|
|
949
994
|
launch(runId: string): Promise<RunLaunchRow>;
|
|
995
|
+
/** Only the immutable CLI accounting identity/turn and (when requested) SDK completion usage. Projects these JSON
|
|
996
|
+
* members in the database: no launch input, policy, sealed bytes, completion answer or replay events are returned.
|
|
997
|
+
* Undefined for an absent run; absent members stay undefined. Historical identity may be read without completion.
|
|
998
|
+
* An ordinary-store analytics read, not for Store.snapshot: PostgreSQL's specific NUL/surrogate extraction refusal falls back
|
|
999
|
+
* to JS parsing that row's text at the prior full-row cost (never sealed bytes); other database failures propagate. */
|
|
1000
|
+
usageMetadata(runId: string, options: {
|
|
1001
|
+
completion: boolean;
|
|
1002
|
+
}): Promise<{
|
|
1003
|
+
cli: Readonly<Record<string, unknown>>;
|
|
1004
|
+
completionUsage?: unknown;
|
|
1005
|
+
} | undefined>;
|
|
950
1006
|
/** The learning start (the launch body's `learning` member, as stored: undefined when the body names none) of every run of
|
|
951
1007
|
* agent `agentId` (no built-in learning run's) that has a launch row, in one read: what an agent-wide read (its cost per
|
|
952
1008
|
* run, its learning view) needs of its runs at once, never a read a run. Only that member is read: no run's input, no
|
|
@@ -955,8 +1011,13 @@ export interface Runs {
|
|
|
955
1011
|
runId: string;
|
|
956
1012
|
learning: unknown;
|
|
957
1013
|
}[]>;
|
|
1014
|
+
/** The ids of agent `agentId`'s runs started after `at` whose learning seed was read at or before it (the launch body's
|
|
1015
|
+
* `learning.seededAt`): a reset's watermark (learn/compile.ts sinceReset). Reads that one number of the runs started
|
|
1016
|
+
* after `at` alone. */
|
|
1017
|
+
seededBefore(agentId: string, at: number): Promise<string[]>;
|
|
958
1018
|
/** Newest first, at most `limit` (no limit: all). `archived` filters on the run's own archive time (true: archived,
|
|
959
1019
|
* false: not); its agent's archive is read apart. A built-in learning run (one a kept learning names) is never listed. `labels`: only runs holding every one of these labels, key and value.
|
|
1020
|
+
* `disk`: only the runs on that disk (RunRow.disk), null for the default disk's; not given, every disk's.
|
|
960
1021
|
* A purged run (Runs.purge) only with `purged`: the readers of money and counts (usage, stats, analytics) and an
|
|
961
1022
|
* import's read of the sessions it holds, never a reader of a run's content. */
|
|
962
1023
|
list(filter: {
|
|
@@ -965,6 +1026,7 @@ export interface Runs {
|
|
|
965
1026
|
state?: RunState;
|
|
966
1027
|
archived?: boolean;
|
|
967
1028
|
labels?: RunLabels;
|
|
1029
|
+
disk?: string | null;
|
|
968
1030
|
limit?: number;
|
|
969
1031
|
purged?: boolean;
|
|
970
1032
|
}): Promise<RunRow[]>;
|
|
@@ -1033,13 +1095,15 @@ export interface Runs {
|
|
|
1033
1095
|
}): Promise<string[]>;
|
|
1034
1096
|
/** Archives the run (its own archive time), or unarchives it: idempotent. */
|
|
1035
1097
|
archive(runId: string, archived: boolean): Promise<void>;
|
|
1036
|
-
/** Every run of agent `agentId` with its state, oldest first, its built-in learning runs
|
|
1037
|
-
* out): what deleting the agent stops and removes, with the runner that holds each (null: none)
|
|
1098
|
+
/** Every run of agent `agentId` with its state, oldest first, its built-in learning runs and purged runs included
|
|
1099
|
+
* (which list leaves out): what deleting the agent stops and removes, with the runner that holds each (null: none),
|
|
1100
|
+
* its purge time and its disk (RunRow.disk: where a learning folder of the agent may be, learn/learning-of.ts namedDisksOf). */
|
|
1038
1101
|
every(agentId: string): Promise<{
|
|
1039
1102
|
id: string;
|
|
1040
1103
|
state: RunState;
|
|
1041
1104
|
runner: string | null;
|
|
1042
1105
|
purgedAt: number | null;
|
|
1106
|
+
disk: string | null;
|
|
1043
1107
|
}[]>;
|
|
1044
1108
|
/** The runs made from run `runId` that hold what it was given or did, by id: each run whose launch replays its input
|
|
1045
1109
|
* (the launch body's `replay.of`) or audits it (`audit.of`: its audit's shadow run), and each learning run its kept
|
|
@@ -1057,8 +1121,9 @@ export interface Runs {
|
|
|
1057
1121
|
* purged first, and Runs.create, under the same row lock, makes none once it is purged. A run with no row, or one
|
|
1058
1122
|
* purged already, is no write. On SQLite, once it commits, a WAL checkpoint (TRUNCATE): with secure_delete on in every
|
|
1059
1123
|
* connection, neither the file nor its WAL keeps the purged bytes after it. A checkpoint another connection holds back
|
|
1060
|
-
*
|
|
1061
|
-
* database's until
|
|
1124
|
+
* leaves the scrub's marker, for the next start's scrub; a marker that cannot be written throws, the purge committed,
|
|
1125
|
+
* and the retried DELETE arranges it again (Store.purgeScrub). Postgres: the old row versions are the database's until
|
|
1126
|
+
* its VACUUM. */
|
|
1062
1127
|
purge(runId: string, kept: PurgeKept): Promise<void>;
|
|
1063
1128
|
/** The run's rows gone, in one transaction: its journal, commands, origin, launch, live view and viewers, its channel
|
|
1064
1129
|
* posts with their tries and what each channel was told of it, its kept learning, its changes in the run-change feed,
|
|
@@ -1585,6 +1650,23 @@ export interface RunnerRow {
|
|
|
1585
1650
|
readonly host: string | null;
|
|
1586
1651
|
readonly port: number | null;
|
|
1587
1652
|
readonly seenAt: number;
|
|
1653
|
+
/** The runner's build (the serve package's version), and the most runs it holds at once (its loops): each null on a
|
|
1654
|
+
* row a runner of an earlier build wrote, or one that said neither (a refusing runner says no slots). */
|
|
1655
|
+
readonly version: string | null;
|
|
1656
|
+
readonly slots: number | null;
|
|
1657
|
+
}
|
|
1658
|
+
/** The store's runs and hand-backs as the capacity read counts them (GET /v2/capacity, capacity.ts), on the deadlines'
|
|
1659
|
+
* clock (fence.ts storeNow), read once for the whole answer. Counts and runner names only. */
|
|
1660
|
+
export interface RunCapacity {
|
|
1661
|
+
/** The deadlines' clock when it was read. */
|
|
1662
|
+
readonly at: number;
|
|
1663
|
+
/** Runs a runner may claim now, by the claim's own rule (queued; handed back or its claim run out, past any backoff; a
|
|
1664
|
+
* parked run something wakes). */
|
|
1665
|
+
readonly queued: number;
|
|
1666
|
+
/** Runs a claim holds now (its lease not run out), by the runner that holds them. */
|
|
1667
|
+
readonly held: ReadonlyMap<string, number>;
|
|
1668
|
+
/** The hand-backs (hand_backs) within the window asked for. */
|
|
1669
|
+
readonly handBacks: number;
|
|
1588
1670
|
}
|
|
1589
1671
|
/** How long a runner's row is kept once it stopped saying it is there (a runner that died without its close): its next
|
|
1590
1672
|
* put removes every row older than this. */
|
|
@@ -1596,9 +1678,11 @@ export interface Runners {
|
|
|
1596
1678
|
* `unlessLiveMs`, not over another incarnation's row of the same name seen within that: a process's put again of a row
|
|
1597
1679
|
* that went (pruned, a store restored) never takes back a later process's live one. False when such a row is there and
|
|
1598
1680
|
* nothing was written. */
|
|
1599
|
-
put(row: Omit<RunnerRow, "seenAt" | "host" | "port"> & {
|
|
1681
|
+
put(row: Omit<RunnerRow, "seenAt" | "host" | "port" | "version" | "slots"> & {
|
|
1600
1682
|
readonly host?: string | null;
|
|
1601
1683
|
readonly port?: number | null;
|
|
1684
|
+
readonly version?: string | null;
|
|
1685
|
+
readonly slots?: number | null;
|
|
1602
1686
|
}, options?: {
|
|
1603
1687
|
readonly unlessLiveMs?: number;
|
|
1604
1688
|
}): Promise<boolean>;
|
|
@@ -1615,6 +1699,8 @@ export interface Runners {
|
|
|
1615
1699
|
live(staleMs: number): Promise<RunnerRow[]>;
|
|
1616
1700
|
/** The runner's row gone, while it is still this incarnation's. */
|
|
1617
1701
|
remove(runner: string, incarnation: string): Promise<void>;
|
|
1702
|
+
/** The runs waiting for a runner and held by one, and the hand-backs within the last `windowMs` (RunCapacity). */
|
|
1703
|
+
capacity(windowMs: number): Promise<RunCapacity>;
|
|
1618
1704
|
}
|
|
1619
1705
|
/** A template package imported from GitHub (store schema `imported_templates`, POST /v2/templates/import): its id
|
|
1620
1706
|
* (`github:<owner>/<repo>[/<path>]`), its source as given, the commit SHA read, its publisher (the GitHub account), and
|
|
@@ -1867,6 +1953,8 @@ export interface Store {
|
|
|
1867
1953
|
readonly computerLedger: ComputerLedger;
|
|
1868
1954
|
/** Each computer a run made, from its create to its proven delete. */
|
|
1869
1955
|
readonly computerIntervals: ComputerIntervals;
|
|
1956
|
+
/** Each claim of a run: the turn it works and its attempt at it, and why it let the run go unfinished. */
|
|
1957
|
+
readonly runAttempts: RunAttempts;
|
|
1870
1958
|
/** The people's own machines paired with this server, and the codes that pair them (spec/computer/attach.md). */
|
|
1871
1959
|
readonly pairedComputers: PairedComputers;
|
|
1872
1960
|
/** The tokens minted for hosted machines that dial this server, each kept as its SHA-256. */
|
|
@@ -1894,6 +1982,15 @@ export interface Store {
|
|
|
1894
1982
|
* done; `left` says why it was kept, for the next start to finish. Postgres: `work` alone (a replaced row version is
|
|
1895
1983
|
* the database's until its vacuum). */
|
|
1896
1984
|
secureRewrite?(work: () => Promise<number>, options?: SecureRewriteOptions): Promise<SecureRewrite>;
|
|
1985
|
+
/** A DELETE of a run or agent already purged (agent-delete.ts): a purge can commit and then fail to write the scrub's
|
|
1986
|
+
* marker (Runs.purge), and its retry finds the row purged. SQLite with a file, when no marker is there: the purge's
|
|
1987
|
+
* WAL checkpoint again, and the marker when another connection still holds the log back; with the marker there, no
|
|
1988
|
+
* write, but the marker is the purge's too, so a rewrite under way that wrote it removes it only after a checkpoint
|
|
1989
|
+
* that truncates the log. Postgres and a store with no file: nothing. */
|
|
1990
|
+
purgeScrub(): Promise<void>;
|
|
1991
|
+
/** Reads the store's schema version and its runner floor now, without a lock or a write: a runner reads it at each
|
|
1992
|
+
* renewal (runner/main.ts), and stops once the floor is above the version its build knows. */
|
|
1993
|
+
schemaState?(): Promise<StoreSchemaState>;
|
|
1897
1994
|
/** Claims the run for `runner` until now + `leaseMs`: the run's epoch + 1 when it is claimable (runs.claimable); null when
|
|
1898
1995
|
* another claim holds it, or it is final, or parked with nothing to wake it. A queued or parked run becomes running. */
|
|
1899
1996
|
claim(runId: string, runner: string, options?: {
|
|
@@ -1915,6 +2012,7 @@ export interface Store {
|
|
|
1915
2012
|
state?: ReleasedState;
|
|
1916
2013
|
wakeAt?: number | null;
|
|
1917
2014
|
backoffUntil?: number | null;
|
|
2015
|
+
cut?: "drain" | "retry";
|
|
1918
2016
|
}): Promise<void>;
|
|
1919
2017
|
/** The run's journal: pi-durable's Storage for this one run, every commit fenced by the claim (store/journal). Its commit
|
|
1920
2018
|
* holds the store's one connection while it runs, so it awaits nothing but its own statements, under a deadline. */
|
|
@@ -2038,6 +2136,23 @@ export declare class SchemaVersionUnknown extends Error {
|
|
|
2038
2136
|
readonly known: number;
|
|
2039
2137
|
constructor(file: string, found: number | null, known: number);
|
|
2040
2138
|
}
|
|
2139
|
+
/** A store a later build migrated past what this runner can run beside: its schema is ahead of the version this build
|
|
2140
|
+
* knows, and its runner floor (a breaking migration's version) is above it. Run a runner of the server's release. A
|
|
2141
|
+
* SchemaVersionUnknown, so every caller that refuses an unknown schema refuses this one the same way (a runner's exit 3). */
|
|
2142
|
+
export declare class RunnerBelowFloor extends SchemaVersionUnknown {
|
|
2143
|
+
readonly floor: number;
|
|
2144
|
+
constructor(place: string, found: number, known: number, floor: number);
|
|
2145
|
+
}
|
|
2146
|
+
/** A store's schema version and its runner floor (Store.schemaState). */
|
|
2147
|
+
export interface StoreSchemaState {
|
|
2148
|
+
/** The store's schema version; null when none is set up. */
|
|
2149
|
+
readonly version: number | null;
|
|
2150
|
+
/** The oldest schema version a runner's build must know to run on this store: a runner whose build knows less stops
|
|
2151
|
+
* claiming, hands its runs back and exits. On SQLite the version itself (a SQLite runner opens only its own version). */
|
|
2152
|
+
readonly runnerFloor: number | null;
|
|
2153
|
+
/** The version this build knows (its newest migration on Postgres, SCHEMA_VERSION on SQLite). */
|
|
2154
|
+
readonly known: number;
|
|
2155
|
+
}
|
|
2041
2156
|
/** A command for a run that is final, or that does not exist. */
|
|
2042
2157
|
export declare class RunFinal extends Error {
|
|
2043
2158
|
readonly runId: string;
|
package/dist/store/store.js
CHANGED
|
@@ -224,6 +224,19 @@ export class SchemaVersionUnknown extends Error {
|
|
|
224
224
|
this.known = known;
|
|
225
225
|
}
|
|
226
226
|
}
|
|
227
|
+
/** A store a later build migrated past what this runner can run beside: its schema is ahead of the version this build
|
|
228
|
+
* knows, and its runner floor (a breaking migration's version) is above it. Run a runner of the server's release. A
|
|
229
|
+
* SchemaVersionUnknown, so every caller that refuses an unknown schema refuses this one the same way (a runner's exit 3). */
|
|
230
|
+
export class RunnerBelowFloor extends SchemaVersionUnknown {
|
|
231
|
+
floor;
|
|
232
|
+
constructor(place, found, known, floor) {
|
|
233
|
+
super(place, found, known);
|
|
234
|
+
const store = place.startsWith("the ") ? place : `the store at ${place}`;
|
|
235
|
+
this.message = `${store} is schema version ${found}, and a runner on it must know version ${floor} or later (its runner floor: a later release changed the schema in a way an earlier runner cannot run beside); this runner knows ${known}. Run a runner of the server's release.`;
|
|
236
|
+
this.name = "RunnerBelowFloor";
|
|
237
|
+
this.floor = floor;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
227
240
|
/** A command for a run that is final, or that does not exist. */
|
|
228
241
|
export class RunFinal extends Error {
|
|
229
242
|
runId;
|
|
@@ -8,14 +8,15 @@ export type AnalyticsFilter = {
|
|
|
8
8
|
agent?: string;
|
|
9
9
|
pending?: Readonly<Record<string, PendingEnd>>;
|
|
10
10
|
};
|
|
11
|
-
/** Runs counted together: how many
|
|
12
|
-
*
|
|
11
|
+
/** Runs counted together: how many completed (escalated included) and failed, how many have metrics and how many
|
|
12
|
+
* report every token counter, their known token total, and their cost (null when none ended with one). */
|
|
13
13
|
export type AnalyticsGroup = {
|
|
14
14
|
runs: number;
|
|
15
15
|
completed: number;
|
|
16
16
|
needsReview: number;
|
|
17
17
|
failed: number;
|
|
18
18
|
runsWithMetrics: number;
|
|
19
|
+
runsWithTokenMetrics: number;
|
|
19
20
|
tokens: number | null;
|
|
20
21
|
costUsd: number | null;
|
|
21
22
|
unknownCostRuns: number;
|
|
@@ -4,13 +4,21 @@
|
|
|
4
4
|
// given. A pending run (its end on the caller's way, not yet in the store) is counted at the state its end will have, in
|
|
5
5
|
// the totals alone; its metrics, cost and effort wait for its end. No journal is read: the figures are the row's.
|
|
6
6
|
import { sdkOf } from "../sdk/runs.js";
|
|
7
|
+
import { cliLearningOf } from "../store/agent-body.js";
|
|
8
|
+
import { NATIVE_RUNTIME_FACTS } from "../native/runtimes.js";
|
|
7
9
|
import { DEFAULT_HARNESS } from "../harness.js";
|
|
8
10
|
import { costOfRun, runReadState } from "./runs.js";
|
|
9
11
|
import { isShadowRun, shadowRunId } from "../learn/audit.js";
|
|
10
12
|
const PENDING_ENDS = new Set(["completed", "escalated", "failed", "stopped"]);
|
|
11
13
|
const num = (value) => (typeof value === "number" && Number.isFinite(value) ? value : 0);
|
|
12
14
|
const metricsOf = (run) => (run.metrics !== null && typeof run.metrics === "object" && !Array.isArray(run.metrics) ? run.metrics : null);
|
|
13
|
-
const
|
|
15
|
+
const TOKEN_KEYS = ["input", "cacheRead", "cacheWrite", "output"];
|
|
16
|
+
/** A metrics object may hold only tools or null native counters. Count coverage only when its whole total is known. */
|
|
17
|
+
const tokensOf = (m) => {
|
|
18
|
+
if (!TOKEN_KEYS.every((key) => typeof m[key] === "number" && Number.isSafeInteger(m[key]) && m[key] >= 0))
|
|
19
|
+
return null;
|
|
20
|
+
return num(m.input) + num(m.cacheRead) + num(m.cacheWrite) + num(m.output);
|
|
21
|
+
};
|
|
14
22
|
/** The runs and their metrics summed (the old AgentStoreReader.analytics), from A's run rows. */
|
|
15
23
|
export async function analytics(store, filter = {}) {
|
|
16
24
|
const pending = {};
|
|
@@ -41,7 +49,10 @@ export async function analytics(store, filter = {}) {
|
|
|
41
49
|
continue;
|
|
42
50
|
if (!harnessOf.has(run.revisionId)) {
|
|
43
51
|
const revision = await store.agents.revision(run.revisionId);
|
|
44
|
-
|
|
52
|
+
const cli = cliLearningOf(revision?.body);
|
|
53
|
+
harnessOf.set(run.revisionId, revision?.kind === "workflow" ? "workflow" : cli
|
|
54
|
+
? NATIVE_RUNTIME_FACTS[cli.runtime].captureRuntime
|
|
55
|
+
: sdkOf(revision?.body)?.runtime ?? revision?.body?.harness ?? DEFAULT_HARNESS);
|
|
45
56
|
}
|
|
46
57
|
const read = runReadState(run, harnessOf.get(run.revisionId) === "workflow" ? "workflow" : "agentic");
|
|
47
58
|
const running = read === "running";
|
|
@@ -67,8 +78,7 @@ export async function analytics(store, filter = {}) {
|
|
|
67
78
|
});
|
|
68
79
|
}
|
|
69
80
|
const counted = (group) => {
|
|
70
|
-
let
|
|
71
|
-
let runsN = 0, completed = 0, needsReview = 0, failed = 0, metered = 0, tokens = 0, costUsd = 0, known = 0, pend = 0;
|
|
81
|
+
let runsN = 0, completed = 0, needsReview = 0, failed = 0, metered = 0, tokenMetered = 0, tokens = 0, costUsd = 0, known = 0, pend = 0;
|
|
72
82
|
let shadowUsd = 0;
|
|
73
83
|
for (const f of group) {
|
|
74
84
|
shadowUsd += f.shadowUsd;
|
|
@@ -81,16 +91,18 @@ export async function analytics(store, filter = {}) {
|
|
|
81
91
|
failed += 1;
|
|
82
92
|
if (f.metered) {
|
|
83
93
|
metered += 1;
|
|
84
|
-
|
|
85
|
-
if (
|
|
86
|
-
|
|
94
|
+
const reported = tokensOf(f.metrics);
|
|
95
|
+
if (reported !== null) {
|
|
96
|
+
tokenMetered += 1;
|
|
97
|
+
tokens += reported;
|
|
98
|
+
}
|
|
87
99
|
}
|
|
88
100
|
if (!f.running && !f.pending && f.costUsd !== null)
|
|
89
101
|
(costUsd += f.costUsd, (known += 1));
|
|
90
102
|
if (f.pending)
|
|
91
103
|
pend += 1;
|
|
92
104
|
}
|
|
93
|
-
return { runs: runsN, completed, needsReview, failed, runsWithMetrics: metered, tokens:
|
|
105
|
+
return { runs: runsN, completed, needsReview, failed, runsWithMetrics: metered, runsWithTokenMetrics: tokenMetered, tokens: tokenMetered > 0 || runsN === 0 ? tokens : null, costUsd: known > 0 || shadowUsd > 0 ? costUsd + shadowUsd : null, unknownCostRuns: runsN - known - pend };
|
|
94
106
|
};
|
|
95
107
|
// Totals over the whole scope: the group counts, the token sums, and the time figures.
|
|
96
108
|
let input = 0, cacheRead = 0, cacheWrite = 0, output = 0, requests = 0, unmetered = 0;
|
|
@@ -6,7 +6,7 @@ import { type PastRun, workflowCostsOf } from "../runner/workflow-first.js";
|
|
|
6
6
|
import { type Reflect } from "../reflect-range.js";
|
|
7
7
|
import type { EntryLike, TimelineEvent } from "../timeline/index.js";
|
|
8
8
|
import type { AnalyticsFilter } from "./analytics.js";
|
|
9
|
-
import { type PromotionRecord } from "../learn/promote.js";
|
|
9
|
+
import { type PromotionRecord, type ResetRevision } from "../learn/promote.js";
|
|
10
10
|
import type { LearningProposal, Store } from "../store/store.js";
|
|
11
11
|
/** A run's learning end: the Learning fields its end sets. */
|
|
12
12
|
export type RunLearningEnd = Learning;
|
|
@@ -120,8 +120,10 @@ export type CompileSpend = {
|
|
|
120
120
|
* its own) and its check (the replay runs that ran it: metrics.path `replay` of its workflow at its digest); unknown
|
|
121
121
|
* once a part's cost is (null, or only a bound). A compile whose drafts all failed drafted none: no revision carries it
|
|
122
122
|
* (the bill's unattributed does). It is spread over its first K served runs (`workflow` or `handed_back` of its workflow
|
|
123
|
-
* at its digest), K its check's compile_after; `state` from its newest record.
|
|
124
|
-
|
|
123
|
+
* at its digest), K its check's compile_after; `state` from its newest record. A revision an earlier reset of the agent's
|
|
124
|
+
* learning deleted (`reset`, learn/promote.ts keepResetLedger) is one too, first, stopped, at the K it was kept with,
|
|
125
|
+
* unless the records name it again. */
|
|
126
|
+
export declare function revisionLedgerOf(records: readonly PromotionRecord[], rows: readonly LedgerRow[], compiles?: readonly CompileSpend[], reset?: readonly ResetRevision[]): ReturnType<typeof amortize>;
|
|
125
127
|
/** Run `runId`'s path and its costs as GET /runs/{id} shows them (A8): `path` its record's (metrics.path, RUN_PATHS:
|
|
126
128
|
* `agent` for a run that does not learn; null while it has not ended, for a workflow revision's run, and for a run that
|
|
127
129
|
* learns whose end named none); `usd` its own spend, the job's (runCostOf's `cost_usd`: its row's cost, `rowUsd` when
|
|
@@ -177,9 +179,11 @@ export declare function costRunOf(store: RunRecords, run: RunRecord, n: number |
|
|
|
177
179
|
workflow: string | null;
|
|
178
180
|
}): Promise<Omit<CostRun, "took_over">>;
|
|
179
181
|
/** The runs the money rule reads for agent `agentId` (runner/workflow-first.ts costLineOf), one set for the run's launch
|
|
180
|
-
* and the cost page: of its newest PAST_RUNS runs
|
|
181
|
-
*
|
|
182
|
-
*
|
|
182
|
+
* and the cost page: of its newest PAST_RUNS runs on no named disk (learn/learning-of.ts: one on a named disk learns
|
|
183
|
+
* nothing), each that ended (ended, stopped or failed) since its learning's reset (learn/compile.ts sinceReset: a
|
|
184
|
+
* workflow before it is not the one it learned after, whatever its name), is neither imported nor archived nor a
|
|
185
|
+
* workflow revision's run, with its all-in cost (allInOf). `known`: all-in costs already read, by run id (the cost
|
|
186
|
+
* page's series), read again for no run; `records`, where any other's rows are read (the store's by default). */
|
|
183
187
|
export declare function pastRunsOverStore(store: Store, agentId: string, known?: ReadonlyMap<string, number | null>, records?: RunRecords): Promise<PastRun[]>;
|
|
184
188
|
/** The money rule's decision for agent `agentId` (runner/workflow-first.ts costStopOf) over the runs a run's launch reads
|
|
185
189
|
* (pastRunsOverStore), as the launch reads them: runs that can't be read now stop nothing (workflowFirstOf serves). What
|
|
@@ -273,7 +277,7 @@ export declare function usedOnly(started: NonNullable<RunLaunch["learning"]>, te
|
|
|
273
277
|
export declare function runLearningOverStore(store: Store, runId: string, shown: Shown, secrets: readonly string[], statuses?: (agentId: string) => Promise<ReadonlyMap<string, ItemStatus> | undefined>): Promise<{
|
|
274
278
|
run: string;
|
|
275
279
|
state: "dropped" | "merged" | "seeded" | "reflecting";
|
|
276
|
-
reason: "cancelled" | "use" | "empty" | "crashed" | "reflect_failed" | "no_budget" | "checker" | "unknown_cost" | "seed_failed" | null;
|
|
280
|
+
reason: "cancelled" | "reset" | "use" | "empty" | "crashed" | "reflect_failed" | "no_budget" | "checker" | "unknown_cost" | "seed_failed" | null;
|
|
277
281
|
detail: string | null;
|
|
278
282
|
at: string;
|
|
279
283
|
workflows: import("../learning.js").LearnedFile[];
|
|
@@ -316,7 +320,7 @@ export declare function runLearningOverStore(store: Store, runId: string, shown:
|
|
|
316
320
|
};
|
|
317
321
|
run: string;
|
|
318
322
|
state: "dropped" | "merged" | "seeded" | "reflecting";
|
|
319
|
-
reason: "cancelled" | "use" | "empty" | "crashed" | "reflect_failed" | "no_budget" | "checker" | "unknown_cost" | "seed_failed" | null;
|
|
323
|
+
reason: "cancelled" | "reset" | "use" | "empty" | "crashed" | "reflect_failed" | "no_budget" | "checker" | "unknown_cost" | "seed_failed" | null;
|
|
320
324
|
detail: string | null;
|
|
321
325
|
at: string;
|
|
322
326
|
workflows: import("../learning.js").LearnedFile[];
|