@parcha/agentrun-serve 0.1.0-beta.39 → 0.1.0-beta.41
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 +114 -0
- package/README.md +129 -16
- package/dist/api-only.d.ts +3 -1
- package/dist/api-only.js +4 -2
- package/dist/api-token.d.ts +30 -0
- package/dist/api-token.js +89 -0
- package/dist/cli.js +19 -5
- package/dist/composio-made.d.ts +54 -0
- package/dist/composio-made.js +83 -0
- package/dist/composio-preset.d.ts +16 -8
- package/dist/composio-preset.js +106 -43
- package/dist/composio-triggers.d.ts +7 -2
- package/dist/composio-triggers.js +13 -7
- package/dist/computer-attach.d.ts +29 -11
- package/dist/computer-attach.js +141 -47
- package/dist/computer-keys.d.ts +4 -0
- package/dist/computer-keys.js +5 -0
- package/dist/computers.d.ts +11 -1
- package/dist/computers.js +21 -12
- package/dist/console/assets/index-C3gNPz58.css +1 -0
- package/dist/console/assets/index-COGhx_2Z.js +711 -0
- package/dist/console/index.html +2 -2
- package/dist/decisions.js +9 -2
- package/dist/email/account.d.ts +0 -1
- package/dist/email/account.js +3 -3
- package/dist/email/answer.d.ts +5 -0
- package/dist/email/answer.js +35 -0
- package/dist/email/mail.js +19 -26
- package/dist/email/names.d.ts +30 -0
- package/dist/email/names.js +34 -0
- package/dist/email/routes.d.ts +1 -0
- package/dist/email/routes.js +1 -1
- package/dist/email/tools.d.ts +11 -4
- package/dist/email/tools.js +91 -46
- package/dist/eval-feed.d.ts +26 -0
- package/dist/eval-feed.js +68 -0
- package/dist/eval-mailbox.d.ts +5 -2
- package/dist/eval-mailbox.js +14 -6
- package/dist/exa-keyless.d.ts +1 -1
- package/dist/exa-keyless.js +1 -1
- package/dist/feed/feed-faux.d.ts +62 -0
- package/dist/feed/feed-faux.js +123 -0
- package/dist/feed/fetch.d.ts +41 -0
- package/dist/feed/fetch.js +128 -0
- package/dist/feed/parse.d.ts +41 -0
- package/dist/feed/parse.js +300 -0
- package/dist/learn/check.d.ts +3 -1
- package/dist/learn/check.js +57 -2
- package/dist/learn/compile.d.ts +3 -2
- package/dist/learn/compile.js +7 -6
- package/dist/learn/promote.d.ts +25 -14
- package/dist/learn/promote.js +32 -14
- package/dist/learned-nodes.d.ts +21 -4
- package/dist/learned-nodes.js +21 -8
- package/dist/learned-workflow.d.ts +3 -3
- package/dist/learned-workflow.js +14 -5
- package/dist/learning-cost.d.ts +17 -8
- package/dist/learning-cost.js +12 -4
- package/dist/local-models.d.ts +7 -1
- package/dist/local-models.js +11 -5
- package/dist/mcp-oauth.d.ts +15 -1
- package/dist/mcp-oauth.js +39 -5
- package/dist/mcp-pin-first.d.ts +4 -2
- package/dist/mcp-pin-first.js +4 -3
- package/dist/mcp-servers-store.d.ts +58 -5
- package/dist/mcp-servers-store.js +136 -17
- package/dist/mcp.d.ts +2 -2
- package/dist/mcp.js +2 -2
- package/dist/observation/http.d.ts +4 -1
- package/dist/observation/http.js +5 -4
- package/dist/openapi.d.ts +1 -1
- package/dist/openapi.js +63 -27
- package/dist/port-models.d.ts +4 -1
- package/dist/port-models.js +1 -0
- package/dist/print.d.ts +6 -3
- package/dist/print.js +4 -2
- package/dist/refusal-words.d.ts +3 -0
- package/dist/refusal-words.js +3 -0
- package/dist/run-labels.d.ts +23 -0
- package/dist/run-labels.js +79 -0
- package/dist/run-launch.d.ts +2 -0
- package/dist/run-launch.js +2 -0
- package/dist/run-secrets.js +12 -4
- package/dist/run-view.d.ts +3 -4
- package/dist/run-view.js +26 -24
- package/dist/runner/adapter-loop.d.ts +6 -2
- package/dist/runner/adapter-loop.js +136 -22
- package/dist/runner/adapter-run-spec.d.ts +5 -0
- package/dist/runner/adapter-run-spec.js +75 -32
- package/dist/runner/beside.d.ts +6 -3
- package/dist/runner/beside.js +9 -7
- package/dist/runner/cli-run-spec.js +33 -26
- package/dist/runner/conformance/harness.js +69 -14
- package/dist/runner/conformance/subject.d.ts +4 -1
- package/dist/runner/journal-kinds.d.ts +22 -0
- package/dist/runner/journal-kinds.js +39 -0
- package/dist/runner/main.d.ts +1 -1
- package/dist/runner/main.js +2 -2
- package/dist/runner/mcp-claim.d.ts +3 -0
- package/dist/runner/mcp-claim.js +1 -1
- package/dist/runner/mcp-run.d.ts +4 -0
- package/dist/runner/mcp-run.js +5 -3
- package/dist/runner/model-route.d.ts +7 -3
- package/dist/runner/model-route.js +24 -9
- package/dist/runner/promotion.d.ts +16 -8
- package/dist/runner/promotion.js +178 -55
- package/dist/runner/workflow-first.d.ts +6 -5
- package/dist/runner/workflow-first.js +9 -7
- package/dist/runs-over-store.js +5 -2
- package/dist/sdk/runs.d.ts +7 -1
- package/dist/sdk/runs.js +19 -6
- package/dist/secret-cut.js +3 -1
- package/dist/secrets.js +3 -1
- package/dist/server.d.ts +27 -2
- package/dist/server.js +181 -56
- package/dist/store/dialect.d.ts +6 -0
- package/dist/store/dialect.js +2 -0
- package/dist/store/index.d.ts +1 -1
- package/dist/store/postgres/connection.d.ts +11 -5
- package/dist/store/postgres/connection.js +44 -17
- package/dist/store/postgres/dialect.js +6 -0
- package/dist/store/postgres/migrations/0015_run_labels.sql +5 -0
- package/dist/store/postgres/migrations/0016_minted_tokens.sql +21 -0
- package/dist/store/postgres/store.d.ts +7 -3
- package/dist/store/postgres/store.js +1 -0
- package/dist/store/schema.d.ts +9 -0
- package/dist/store/schema.js +26 -2
- package/dist/store/sqlite/connection.js +80 -8
- package/dist/store/sqlite/run-launch.d.ts +11 -0
- package/dist/store/sqlite/run-launch.js +8 -0
- package/dist/store/sqlite/run-patch.d.ts +2 -1
- package/dist/store/sqlite/run-patch.js +3 -2
- package/dist/store/sqlite/store.js +101 -26
- package/dist/store/sqlite/worker.d.ts +2 -0
- package/dist/store/sqlite/worker.js +13 -10
- package/dist/store/store.d.ts +53 -1
- package/dist/store-reads/journal.js +2 -1
- package/dist/store-reads/learning.d.ts +30 -13
- package/dist/store-reads/learning.js +130 -51
- package/dist/store-reads/runs.d.ts +4 -3
- package/dist/store-reads/runs.js +3 -2
- package/dist/store-view.js +4 -2
- package/dist/template-eval.d.ts +4 -0
- package/dist/template-eval.js +127 -50
- package/dist/templates.d.ts +24 -1
- package/dist/templates.js +129 -21
- package/dist/timeline/origin.d.ts +1 -1
- package/dist/timeline/origin.js +2 -2
- package/dist/tool-gate.d.ts +5 -3
- package/dist/tool-gate.js +5 -2
- package/dist/tools.d.ts +13 -0
- package/dist/tools.js +15 -10
- package/dist/trigger-adapter.d.ts +12 -36
- package/dist/trigger-adapters.js +2 -1
- package/dist/trigger-email.js +30 -77
- package/dist/trigger-feed.d.ts +12 -0
- package/dist/trigger-feed.js +371 -0
- package/dist/triggers.d.ts +27 -14
- package/dist/triggers.js +121 -80
- package/dist/webhooks.js +9 -5
- package/dist/workflow/decision-recovery.js +5 -2
- package/dist/workflow/decisions.d.ts +7 -0
- package/dist/workspace/computer-deps.d.ts +5 -1
- package/dist/workspace/computer-deps.js +2 -2
- package/dist/workspace/index.d.ts +1 -0
- package/dist/workspace/index.js +2 -0
- package/dist/workspace/resolve-computer.d.ts +32 -3
- package/dist/workspace/resolve-computer.js +47 -9
- package/launcher/agentrun-serve +6 -1
- package/package.json +10 -9
- package/templates/README.md +27 -2
- package/dist/console/assets/index-BNhZs-jp.css +0 -1
- package/dist/console/assets/index-BQv5aOGB.js +0 -700
|
@@ -11,7 +11,7 @@ import { backfillNativeCommandOwners, nativeCommandOwner, validConnectorId } fro
|
|
|
11
11
|
import { watchCommandsAt, wakeCommands } from "../command-wake.js";
|
|
12
12
|
import { claimFence, storeNow } from "../fence.js";
|
|
13
13
|
import { RunStorage } from "../journal/storage.js";
|
|
14
|
-
import { COMMANDS_ONE_ANSWER, DDL, IMPORTED_TEMPLATES, NATIVE_COMMANDS_INDEX, REVISIONS_MCP_PIN, REVISIONS_MONID_PIN, RUNS_COST_UPPER_BOUND, SCHEMA_VERSION } from "../schema.js";
|
|
14
|
+
import { COMMANDS_ONE_ANSWER, DDL, IMPORTED_TEMPLATES, MINTED_TOKENS, NATIVE_COMMANDS_INDEX, REVISIONS_MCP_PIN, REVISIONS_MONID_PIN, RUNS_COST_UPPER_BOUND, RUNS_LABELS, SCHEMA_VERSION } from "../schema.js";
|
|
15
15
|
import { AgentArchived, CommandTaken, ExternalBodyConflict, Fenced, RunFinal, SchemaVersionUnknown, STORE_WRITE_DEADLINE_MS, StoreConstraint, StoreFromEarlierVersion, TriggerFull, FINAL_STATES, MCP_REFRESH_CALL_MS, MCP_REFRESH_LEASE_MS, RevisionMoved, SignInHandedTo, SignInMissing, RUN_CHANGES_PAGE, } from "../store.js";
|
|
16
16
|
/** The seq a run-change cursor names (Runs.changedSince): only a cursor this store handed back, a whole number. */
|
|
17
17
|
const seqOf = (cursor) => {
|
|
@@ -19,10 +19,10 @@ const seqOf = (cursor) => {
|
|
|
19
19
|
throw new TypeError(`${JSON.stringify(cursor)} is not a run-change cursor this store gave`);
|
|
20
20
|
return Number(cursor);
|
|
21
21
|
};
|
|
22
|
-
import { settledBody } from "../dialect.js";
|
|
22
|
+
import { cleanText, settledBody } from "../dialect.js";
|
|
23
23
|
import { Connection } from "./connection.js";
|
|
24
24
|
import { applyRunPatch, EXACT_COST_USD, NOT_A_LEARNING_RUN, refuseLeftovers, REOPEN_SET, reopenableWhere, RUN_COLUMNS, runOf, SIGN_IN_HANDED_LOCK } from "./run-patch.js";
|
|
25
|
-
import { readLaunch, writeLaunch } from "./run-launch.js";
|
|
25
|
+
import { readLaunch, readLearningStarts, writeLaunch } from "./run-launch.js";
|
|
26
26
|
import { canonical } from "../agent-body.js";
|
|
27
27
|
import { aadOf, sealedAt } from "../seal.js";
|
|
28
28
|
/** A claim's length when the caller names none. */
|
|
@@ -107,6 +107,19 @@ const triggerOf = (r) => ({
|
|
|
107
107
|
createdAt: r.created_at, updatedAt: r.updated_at,
|
|
108
108
|
});
|
|
109
109
|
const json = (value) => JSON.stringify(value ?? null);
|
|
110
|
+
/** A UTF-16 surrogate standing alone (in `u` mode a whole pair is one code point, so only a lone half matches). */
|
|
111
|
+
const LONE_SURROGATE = /[\ud800-\udfff]/u;
|
|
112
|
+
/** A run's labels as its column holds them: keys sorted, so the same labels are the same text; null for none. A key or value
|
|
113
|
+
* holding a lone surrogate is refused (TypeError), nothing written: JSON.stringify keeps it as a `\ud800` escape that
|
|
114
|
+
* Postgres' json check takes but json_each_text cannot decode, so every later label search scanning the run would fail. */
|
|
115
|
+
const labelsColumn = (labels) => {
|
|
116
|
+
for (const [key, value] of Object.entries(labels ?? {})) {
|
|
117
|
+
if (LONE_SURROGATE.test(key) || LONE_SURROGATE.test(value))
|
|
118
|
+
throw new TypeError(`a run's label ${JSON.stringify(key)} holds a lone UTF-16 surrogate: a label is whole Unicode characters`);
|
|
119
|
+
}
|
|
120
|
+
const keys = Object.keys(labels ?? {}).sort();
|
|
121
|
+
return keys.length === 0 ? null : JSON.stringify(Object.fromEntries(keys.map((key) => [key, labels[key]])));
|
|
122
|
+
};
|
|
110
123
|
/** A revision's MCP pin as its column keeps it: JSON, or null for none. */
|
|
111
124
|
const pinText = (pin) => (pin === undefined || pin === null ? null : JSON.stringify(pin));
|
|
112
125
|
const removedOf = (r) => r && { url: r.url, sealed: r.sealed === null ? null : Uint8Array.from(r.sealed) };
|
|
@@ -131,6 +144,7 @@ const settingOf = (r) => ({ key: r.key, value: JSON.parse(r.value), updatedAt: r
|
|
|
131
144
|
const sealedKeyOf = (r) => ({ name: r.name, sealed: Uint8Array.from(r.sealed), updatedAt: r.updated_at });
|
|
132
145
|
const ledgerRowOf = (r) => ({ provider: r.provider, sessionId: r.session_id, labels: JSON.parse(r.labels), detail: JSON.parse(r.detail), updatedAt: r.updated_at });
|
|
133
146
|
const pairedOf = (r) => ({ id: r.id, name: r.name, hello: JSON.parse(r.hello), driver: r.driver, labels: JSON.parse(r.labels), pairingId: r.pairing_id, createdAt: r.created_at, seenAt: r.seen_at, revokedAt: r.revoked_at });
|
|
147
|
+
const mintedOf = (r) => ({ machine: r.machine, kind: r.kind, os: r.os, arch: r.arch, expiresAt: r.expires_at, revokedAt: r.revoked_at, createdAt: r.created_at });
|
|
134
148
|
const triggerSettingOf = (r) => ({ adapter: r.adapter, scope: r.scope, field: r.field, sealed: r.sealed, updatedAt: r.updated_at });
|
|
135
149
|
const mcpOauthOf = (r) => ({ state: r.state, server: r.server, sealed: Uint8Array.from(r.sealed), working: r.working === null ? null : JSON.parse(r.working), expiresAt: r.expires_at });
|
|
136
150
|
const SIGN_IN_COLUMNS = "agent_id, provider, name, pointer_sealed, saved_at, save, verified_at";
|
|
@@ -258,12 +272,19 @@ export async function openSqliteStore(options) {
|
|
|
258
272
|
}
|
|
259
273
|
// An earlier build of this version kept no bound beside a run's cost (schema.ts RUNS_COST_UPPER_BOUND): the server adds
|
|
260
274
|
// it, every run it ended reading 0, and a runner, which writes it at each end, waits for that server.
|
|
261
|
-
const
|
|
262
|
-
if (!
|
|
275
|
+
const runColumns = new Set((await connection.all("SELECT name FROM pragma_table_info('runs')")).map((column) => column.name));
|
|
276
|
+
if (!runColumns.has("cost_upper_bound")) {
|
|
263
277
|
if (role === "runner")
|
|
264
278
|
throw new Error("Start the AgentRun server to add the bound beside each run's cost before opening a runner. The runner does not upgrade this store.");
|
|
265
279
|
await connection.write([{ sql: RUNS_COST_UPPER_BOUND }], { full: true });
|
|
266
280
|
}
|
|
281
|
+
// An earlier build of this version kept no labels on a run (schema.ts RUNS_LABELS): the server adds the column, nullable,
|
|
282
|
+
// every run it started reading as given none. A runner reads each run through it, so it waits for that server.
|
|
283
|
+
if (!runColumns.has("labels")) {
|
|
284
|
+
if (role === "runner")
|
|
285
|
+
throw new Error("Start the AgentRun server to add each run's labels before opening a runner. The runner does not upgrade this store.");
|
|
286
|
+
await connection.write([{ sql: RUNS_LABELS }], { full: true });
|
|
287
|
+
}
|
|
267
288
|
// The per-run viewer table was renamed browser_viewers → computer_viewers (schema.ts). Its rows are ephemeral, so none
|
|
268
289
|
// migrate; the server drops a stale browser_viewers an earlier build of this version left, so none lingers beside it.
|
|
269
290
|
// An earlier build of this version made no one-answer index on commands (schema.ts COMMANDS_ONE_ANSWER), or one that
|
|
@@ -285,6 +306,8 @@ export async function openSqliteStore(options) {
|
|
|
285
306
|
{ sql: COMMANDS_ONE_ANSWER },
|
|
286
307
|
// An earlier build of this version kept no imported template packages (schema.ts IMPORTED_TEMPLATES).
|
|
287
308
|
{ sql: IMPORTED_TEMPLATES },
|
|
309
|
+
// Nor any hosted machine's minted token (schema.ts MINTED_TOKENS).
|
|
310
|
+
{ sql: MINTED_TOKENS },
|
|
288
311
|
{ sql: NATIVE_COMMANDS_INDEX },
|
|
289
312
|
], { full: true });
|
|
290
313
|
await backfillNativeCommandOwners(connection);
|
|
@@ -302,6 +325,13 @@ const SECOND_ANSWERS_REFUSED = `UPDATE commands SET taken_at = COALESCE(taken_at
|
|
|
302
325
|
AND id NOT IN (SELECT MIN(id) FROM commands WHERE kind IN ('approve', 'deny') AND refused IS NULL AND json_extract(body, '$.approval') IS NOT NULL GROUP BY run_id, json_extract(body, '$.approval'))`;
|
|
303
326
|
/** How many released claims a store remembers, to refuse their journals. */
|
|
304
327
|
const RELEASED_KEPT = 1024;
|
|
328
|
+
/** The most claims one statement of renewMany renews. Its WHERE joins each claim's fence with OR, and each OR is one more
|
|
329
|
+
* level of the expression tree, whose depth SQLite bounds at 1,000 (SQLITE_MAX_EXPR_DEPTH: 997 claims already fail). 250
|
|
330
|
+
* stays a quarter of that, and a runner's 300 claims are still two statements on a database a few ms away. */
|
|
331
|
+
const RENEW_CHUNK = 250;
|
|
332
|
+
/** A claim as renewMany matches it to the rows its update returned: its run, epoch and runner, each string as the store
|
|
333
|
+
* writes text (cleanText: a NUL as U+FFFD), so a claim and the row the database wrote for it make one key. */
|
|
334
|
+
const renewKey = (runId, epoch, runner) => `${cleanText(runId)}\u0000${epoch}\u0000${cleanText(runner)}`;
|
|
305
335
|
/** The key of a claim's one journal: its run and epoch. */
|
|
306
336
|
const journalKey = (claim) => `${claim.runId}\u0000${claim.epoch}`;
|
|
307
337
|
/** A statement under `claim`: one that changes no row means the run's epoch moved on, and the transaction rolls back. */
|
|
@@ -365,6 +395,7 @@ class SqliteStore {
|
|
|
365
395
|
sealedKeys;
|
|
366
396
|
computerLedger;
|
|
367
397
|
pairedComputers;
|
|
398
|
+
mintedTokens;
|
|
368
399
|
importedTemplates;
|
|
369
400
|
triggerSettings;
|
|
370
401
|
channels;
|
|
@@ -766,15 +797,16 @@ class SqliteStore {
|
|
|
766
797
|
})),
|
|
767
798
|
};
|
|
768
799
|
this.runs = {
|
|
769
|
-
create: async ({ id, agentId, revisionId, origin }, launch) => {
|
|
800
|
+
create: async ({ id, agentId, revisionId, origin, labels }, launch) => {
|
|
770
801
|
// sign_in_handed is not written here: the runner writes it at its claim (runs.update under the epoch fence).
|
|
771
|
-
const insert = `INSERT INTO runs (id, agent_id, revision_id, state, epoch, started_at) VALUES (?, ?, ?, 'queued', 0, ?) RETURNING ${RUN_COLUMNS}`;
|
|
802
|
+
const insert = `INSERT INTO runs (id, agent_id, revision_id, state, epoch, labels, started_at) VALUES (?, ?, ?, 'queued', 0, ?, ?) RETURNING ${RUN_COLUMNS}`;
|
|
803
|
+
const labelled = labelsColumn(labels);
|
|
772
804
|
if (origin || launch) {
|
|
773
805
|
// The run, its origin and its launch row in one transaction: the key -> run link holds even if the kept response
|
|
774
806
|
// never lands, and a run never exists without the launch it was started with.
|
|
775
807
|
return this.#queued(await db.transaction(async (tx) => {
|
|
776
808
|
const at = now();
|
|
777
|
-
const row = await tx.get(insert, id, agentId, revisionId, at);
|
|
809
|
+
const row = await tx.get(insert, id, agentId, revisionId, labelled, at);
|
|
778
810
|
if (origin)
|
|
779
811
|
await tx.run("INSERT INTO run_origins (key, run_id, fingerprint, created_at) VALUES (?, ?, ?, ?)", origin.key, id, origin.fingerprint ?? null, at);
|
|
780
812
|
if (launch)
|
|
@@ -782,11 +814,11 @@ class SqliteStore {
|
|
|
782
814
|
return runOf(row);
|
|
783
815
|
}));
|
|
784
816
|
}
|
|
785
|
-
const [result] = await db.write([{ sql: insert, params: [id, agentId, revisionId, now()] }]);
|
|
817
|
+
const [result] = await db.write([{ sql: insert, params: [id, agentId, revisionId, labelled, now()] }]);
|
|
786
818
|
return this.#queued(runOf(result.rows[0]));
|
|
787
819
|
},
|
|
788
820
|
createInline: async ({ agent, revision, run, launch }) => {
|
|
789
|
-
const insert = `INSERT INTO runs (id, agent_id, revision_id, state, epoch, started_at) VALUES (?, ?, ?, 'queued', 0, ?) RETURNING ${RUN_COLUMNS}`;
|
|
821
|
+
const insert = `INSERT INTO runs (id, agent_id, revision_id, state, epoch, labels, started_at) VALUES (?, ?, ?, 'queued', 0, ?, ?) RETURNING ${RUN_COLUMNS}`;
|
|
790
822
|
const made = await db.transaction(async (tx) => {
|
|
791
823
|
const at = now();
|
|
792
824
|
// Hold the external reference, so two first uses of the same expert serialize (SQLite's one writer already does).
|
|
@@ -809,7 +841,7 @@ class SqliteStore {
|
|
|
809
841
|
await tx.run("UPDATE agents SET current_revision = ?, name = ?, description = ? WHERE id = ?", revisionId, agent.name, agent.description ?? null, mapped.id);
|
|
810
842
|
}
|
|
811
843
|
// The run, its origin and its launch, in the same transaction as the agent and the revision.
|
|
812
|
-
const row = await tx.get(insert, run.id, mapped.id, revisionId, at);
|
|
844
|
+
const row = await tx.get(insert, run.id, mapped.id, revisionId, labelsColumn(run.labels), at);
|
|
813
845
|
if (run.origin)
|
|
814
846
|
await tx.run("INSERT INTO run_origins (key, run_id, fingerprint, created_at) VALUES (?, ?, ?, ?)", run.origin.key, run.id, run.origin.fingerprint ?? null, at);
|
|
815
847
|
await writeLaunch(tx, run.id, launch, at);
|
|
@@ -822,7 +854,8 @@ class SqliteStore {
|
|
|
822
854
|
return row && runOf(row);
|
|
823
855
|
},
|
|
824
856
|
launch: (runId) => readLaunch(db, runId),
|
|
825
|
-
|
|
857
|
+
learningStarts: (agentId) => readLearningStarts(db, agentId, NOT_A_LEARNING_RUN),
|
|
858
|
+
list: async ({ agentId, revisionId, state, archived, labels, limit }) => {
|
|
826
859
|
// A built-in learning run (a run's grade and merge, queued with its kept learning) is no run of a person's: no list,
|
|
827
860
|
// count, stat or notice names it.
|
|
828
861
|
const where = [NOT_A_LEARNING_RUN];
|
|
@@ -835,6 +868,9 @@ class SqliteStore {
|
|
|
835
868
|
(where.push("state = ?"), params.push(state));
|
|
836
869
|
if (archived !== undefined)
|
|
837
870
|
where.push(`archived_at IS ${archived ? "NOT NULL" : "NULL"}`);
|
|
871
|
+
// Each label, key and value bound as parameters (never spliced into a JSON path), all of them held.
|
|
872
|
+
for (const [key, value] of Object.entries(labels ?? {}))
|
|
873
|
+
(where.push(d.jsonObjectHas("labels")), params.push(key, value));
|
|
838
874
|
const bounded = typeof limit === "number" && Number.isSafeInteger(limit) && limit >= 0;
|
|
839
875
|
if (bounded)
|
|
840
876
|
params.push(limit);
|
|
@@ -1131,6 +1167,11 @@ class SqliteStore {
|
|
|
1131
1167
|
return row ? proposalOf(row) : undefined;
|
|
1132
1168
|
},
|
|
1133
1169
|
proposals: async (agentId, { limit = 100 } = {}) => (await db.all(`SELECT ${PROPOSAL_COLUMNS} FROM learning_proposals WHERE agent_id = ? ORDER BY created_at DESC, run_id DESC, round DESC LIMIT ?`, agentId, limit)).map(proposalOf),
|
|
1170
|
+
kept: async (agentId) => {
|
|
1171
|
+
const proposals = (await db.all(`SELECT ${PROPOSAL_COLUMNS} FROM learning_proposals WHERE agent_id = ? ORDER BY run_id, round`, agentId)).map(proposalOf);
|
|
1172
|
+
const learningRuns = (await db.all(`SELECT ${RUN_COLUMNS} FROM runs WHERE id IN (SELECT learning_run_id FROM learning_proposals WHERE agent_id = ? AND learning_run_id IS NOT NULL)`, agentId)).map(runOf);
|
|
1173
|
+
return { proposals, learningRuns };
|
|
1174
|
+
},
|
|
1134
1175
|
spend: async ({ from, to }) => {
|
|
1135
1176
|
const rows = await db.all(`SELECT lp.agent_id, lp.proposal, lp.created_at, lp.learning_run_id, lr.state AS run_state, lr.ended_at AS run_ended_at, ${EXACT_COST_USD("lr")} AS run_cost_usd
|
|
1136
1177
|
FROM learning_proposals lp
|
|
@@ -1349,6 +1390,32 @@ class SqliteStore {
|
|
|
1349
1390
|
return (result?.changes ?? 0) === 1;
|
|
1350
1391
|
},
|
|
1351
1392
|
};
|
|
1393
|
+
const MINTED = "SELECT machine, kind, os, arch, expires_at, revoked_at, created_at FROM minted_tokens";
|
|
1394
|
+
this.mintedTokens = {
|
|
1395
|
+
// A mint for a machine that has one replaces it: its older token dials no more.
|
|
1396
|
+
mint: async ({ machine, tokenSha256, kind, os, arch, expiresAt }) => {
|
|
1397
|
+
const at = now();
|
|
1398
|
+
await db.write([
|
|
1399
|
+
{ sql: "DELETE FROM minted_tokens WHERE expires_at <= ?", params: [at] },
|
|
1400
|
+
{
|
|
1401
|
+
sql: "INSERT INTO minted_tokens (machine, token_sha256, kind, os, arch, expires_at, created_at) VALUES (?, ?, ?, ?, ?, ?, ?) ON CONFLICT (machine) DO UPDATE SET token_sha256 = excluded.token_sha256, kind = excluded.kind, os = excluded.os, arch = excluded.arch, expires_at = excluded.expires_at, revoked_at = NULL, created_at = excluded.created_at",
|
|
1402
|
+
params: [machine, tokenSha256, kind, os, arch, expiresAt, at],
|
|
1403
|
+
},
|
|
1404
|
+
]);
|
|
1405
|
+
},
|
|
1406
|
+
byToken: async (tokenSha256) => {
|
|
1407
|
+
const row = await db.get(`${MINTED} WHERE token_sha256 = ? AND revoked_at IS NULL AND expires_at > ?`, tokenSha256, now());
|
|
1408
|
+
return row === undefined ? undefined : mintedOf(row);
|
|
1409
|
+
},
|
|
1410
|
+
get: async (machine) => {
|
|
1411
|
+
const row = await db.get(`${MINTED} WHERE machine = ?`, machine);
|
|
1412
|
+
return row === undefined ? undefined : mintedOf(row);
|
|
1413
|
+
},
|
|
1414
|
+
revoke: async (machine) => {
|
|
1415
|
+
const [result] = await db.write([{ sql: "UPDATE minted_tokens SET revoked_at = ? WHERE machine = ? AND revoked_at IS NULL", params: [now(), machine] }]);
|
|
1416
|
+
return (result?.changes ?? 0) === 1;
|
|
1417
|
+
},
|
|
1418
|
+
};
|
|
1352
1419
|
this.importedTemplates = {
|
|
1353
1420
|
list: async () => (await db.all("SELECT id, source, sha, publisher, files, imported_at FROM imported_templates ORDER BY id")).map((row) => ({
|
|
1354
1421
|
id: row.id, source: row.source, sha: row.sha, publisher: row.publisher, files: JSON.parse(row.files), importedAt: row.imported_at,
|
|
@@ -1581,9 +1648,10 @@ class SqliteStore {
|
|
|
1581
1648
|
const rows = await tx.all(`UPDATE runs SET ${claimSet(stamp)} WHERE id IN (${picked.map(() => "?").join(", ")}) RETURNING id, epoch, claimed_until`, runner, ...stamp.params, leaseMs, ...picked.map((row) => row.id));
|
|
1582
1649
|
const epochs = new Map(rows.map((row) => [row.id, row.epoch]));
|
|
1583
1650
|
const untils = new Map(rows.map((row) => [row.id, Number(row.claimed_until)]));
|
|
1584
|
-
// A take or reclaim leaves no viewer of an older claim behind: its rows go in this transaction, every kind
|
|
1585
|
-
for (
|
|
1586
|
-
|
|
1651
|
+
// A take or reclaim leaves no viewer of an older claim behind: its rows go in this transaction, every kind, in one
|
|
1652
|
+
// statement for the whole batch (each run's epoch is the one just moved to), never one round trip a run.
|
|
1653
|
+
if (rows.length > 0)
|
|
1654
|
+
await tx.run(`DELETE FROM computer_viewers WHERE run_id IN (${rows.map(() => "?").join(", ")}) AND epoch < (SELECT epoch FROM runs WHERE runs.id = computer_viewers.run_id)`, ...rows.map((row) => row.id));
|
|
1587
1655
|
// A newer claim of a run supersedes its release here: journal() refuses by epoch, and the newer epoch passes.
|
|
1588
1656
|
for (const { id } of picked)
|
|
1589
1657
|
this.#released.delete(id);
|
|
@@ -1613,21 +1681,28 @@ class SqliteStore {
|
|
|
1613
1681
|
async renewMany(claims, { leaseMs = DEFAULT_LEASE_MS } = {}) {
|
|
1614
1682
|
if (claims.length === 0)
|
|
1615
1683
|
return [];
|
|
1616
|
-
// One transaction for every claim,
|
|
1617
|
-
//
|
|
1684
|
+
// One transaction for every claim, in a few statements whatever their count: the rows held in one, then one update
|
|
1685
|
+
// for each RENEW_CHUNK claims, each claim under its own fence. A runner's 300 claims are never 300 round trips with
|
|
1686
|
+
// their rows held, which on a database a few ms away outlast the lease's margin and lose every claim at once. A claim
|
|
1687
|
+
// another runner took changes no row and is answered Fenced, never rolling the others back.
|
|
1618
1688
|
return this.#db.transaction(async (tx) => {
|
|
1619
|
-
//
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
const
|
|
1623
|
-
for (
|
|
1689
|
+
// Every row held first, in one order (the dialect's, by run id), so two renews of overlapping runs never wait on
|
|
1690
|
+
// each other in a cycle, and the clock below is read once the rows are held.
|
|
1691
|
+
await this.#db.dialect.lockRows(tx, "runs", "id", [...new Set(claims.map((claim) => claim.runId))]);
|
|
1692
|
+
const renewed = new Map();
|
|
1693
|
+
for (let at = 0; at < claims.length; at += RENEW_CHUNK) {
|
|
1694
|
+
const chunk = claims.slice(at, at + RENEW_CHUNK);
|
|
1624
1695
|
// The deadlines' clock (the database's on Postgres) judges each lease and stamps the next one.
|
|
1625
1696
|
const now = this.#clock();
|
|
1626
|
-
const
|
|
1627
|
-
const
|
|
1628
|
-
|
|
1697
|
+
const fences = chunk.map((claim) => claimFence(claim, now));
|
|
1698
|
+
const rows = await tx.all(`UPDATE runs SET claimed_until = ${now.sql} + ? WHERE ${fences.map((fence) => `(${fence.where} AND runner = ?)`).join(" OR ")} RETURNING id, epoch, runner, claimed_until`, ...now.params, leaseMs, ...fences.flatMap((fence, i) => [...fence.params, chunk[i].runner]));
|
|
1699
|
+
for (const row of rows)
|
|
1700
|
+
renewed.set(renewKey(row.id, Number(row.epoch), row.runner), Number(row.claimed_until));
|
|
1629
1701
|
}
|
|
1630
|
-
return
|
|
1702
|
+
return claims.map((claim) => {
|
|
1703
|
+
const until = renewed.get(renewKey(claim.runId, claim.epoch, claim.runner));
|
|
1704
|
+
return until === undefined ? new Fenced(claim.runId, claim.epoch) : { ...claim, until };
|
|
1705
|
+
});
|
|
1631
1706
|
// On the lease connection (TransactionOptions.lease): a runner whose loops hold every pool client still renews.
|
|
1632
1707
|
}, { lease: true });
|
|
1633
1708
|
}
|
|
@@ -9,12 +9,13 @@
|
|
|
9
9
|
// server per store file): an exclusive lock on `<file>.owner`, held until close,
|
|
10
10
|
// let go by the OS when the process dies
|
|
11
11
|
// exec {sql} SQL text, maybe several statements, no bindings
|
|
12
|
-
// stmt {statement, mode}
|
|
12
|
+
// stmt {statement, mode, busyMs} one statement: run, count (its changes), get (first row) or all. Outside a
|
|
13
13
|
// transaction, a run or count is its own BEGIN IMMEDIATE transaction
|
|
14
|
-
// write {statements, full}
|
|
14
|
+
// write {statements, full, busyMs} one transaction: BEGIN IMMEDIATE, each statement in order, COMMIT; `full` makes it
|
|
15
15
|
// a FULL commit (flush). A statement's `expect` checks it changed a row; a miss
|
|
16
16
|
// rolls the whole transaction back with its `miss` (fenced, or a final run)
|
|
17
|
-
// begin {full} / commit / rollback
|
|
17
|
+
// begin {full, busyMs} / commit / rollback
|
|
18
|
+
// an interactive transaction (connection.ts transaction()), its statements sent
|
|
18
19
|
// as stmt, or as step (one statement, its changes and rows, its `expect` checked)
|
|
19
20
|
// in between
|
|
20
21
|
// close
|
|
@@ -65,8 +66,9 @@ function step(statement) {
|
|
|
65
66
|
/** The connection's own busy wait (its open's busyTimeoutMs): what a begin given a shorter one goes back to. */
|
|
66
67
|
let busyTimeout = 0;
|
|
67
68
|
/** A transaction: BEGIN IMMEDIATE for a write; for `read`, a deferred one that takes no writer lock (one snapshot).
|
|
68
|
-
* `busyMs`: the most this begin waits for the database's write lock, when the
|
|
69
|
-
*
|
|
69
|
+
* `busyMs`: the most this begin waits for the database's write lock, when less than the connection's own busy wait is
|
|
70
|
+
* left (a `fromCall` transaction's deadline, or a wait sent again with its held-up time given back: connection.ts
|
|
71
|
+
* lockWait); the connection's own is set back after it. */
|
|
70
72
|
function begin(full, read = false, busyMs) {
|
|
71
73
|
const conn = opened();
|
|
72
74
|
if (full)
|
|
@@ -114,11 +116,12 @@ function end(commit) {
|
|
|
114
116
|
txFull = false;
|
|
115
117
|
}
|
|
116
118
|
}
|
|
117
|
-
/** `work` inside its own BEGIN IMMEDIATE transaction when none is open
|
|
118
|
-
|
|
119
|
+
/** `work` inside its own BEGIN IMMEDIATE transaction when none is open (its begin waiting `busyMs` at most, as begin's);
|
|
120
|
+
* inside the open one otherwise. */
|
|
121
|
+
function written(work, busyMs) {
|
|
119
122
|
if (inTx)
|
|
120
123
|
return work();
|
|
121
|
-
begin(false);
|
|
124
|
+
begin(false, false, busyMs);
|
|
122
125
|
try {
|
|
123
126
|
const value = work();
|
|
124
127
|
end(true);
|
|
@@ -190,10 +193,10 @@ function handle(request) {
|
|
|
190
193
|
const prepared = opened().prepare(statement.sql);
|
|
191
194
|
return mode === "all" ? prepared.all(...(statement.params ?? [])) : (prepared.get(...(statement.params ?? [])) ?? null);
|
|
192
195
|
}
|
|
193
|
-
return written(() => step(statement).changes);
|
|
196
|
+
return written(() => step(statement).changes, request.busyMs);
|
|
194
197
|
}
|
|
195
198
|
case "write": {
|
|
196
|
-
begin(request.full === true);
|
|
199
|
+
begin(request.full === true, false, request.busyMs);
|
|
197
200
|
try {
|
|
198
201
|
const results = request.statements.map(step);
|
|
199
202
|
end(true);
|
package/dist/store/store.d.ts
CHANGED
|
@@ -129,6 +129,9 @@ export interface RunOrigin {
|
|
|
129
129
|
readonly key: string;
|
|
130
130
|
readonly fingerprint?: string | null;
|
|
131
131
|
}
|
|
132
|
+
/** A run's labels: a small map of the caller's own strings, set once at its start, never read by the server (only
|
|
133
|
+
* filtered on). Bounds: run-labels.ts. */
|
|
134
|
+
export type RunLabels = Readonly<Record<string, string>>;
|
|
132
135
|
export interface RunRow {
|
|
133
136
|
readonly id: string;
|
|
134
137
|
readonly agentId: string;
|
|
@@ -158,6 +161,8 @@ export interface RunRow {
|
|
|
158
161
|
/** The SHA-256 hashes of the browser sign-in pointers handed to the run at its launch (never the pointers), or null when
|
|
159
162
|
* it was handed none. A sign-in whose pointer hashes to one of these cannot be forgotten while the run runs. */
|
|
160
163
|
readonly signInHanded: readonly string[] | null;
|
|
164
|
+
/** The caller's labels, given at its start (RunLabels): opaque to the server, kept as given, {} when none. */
|
|
165
|
+
readonly labels: RunLabels;
|
|
161
166
|
readonly startedAt: number;
|
|
162
167
|
readonly endedAt: number | null;
|
|
163
168
|
}
|
|
@@ -292,6 +297,13 @@ export interface Learning {
|
|
|
292
297
|
proposals(agentId: string, options?: {
|
|
293
298
|
limit?: number;
|
|
294
299
|
}): Promise<LearningProposal[]>;
|
|
300
|
+
/** Everything agent `agentId`'s runs' learning kept, in two reads whatever the number of its runs: every round of every
|
|
301
|
+
* run's kept proposal (oldest round first within a run), and the rows of the learning runs they name (as runs.get
|
|
302
|
+
* reads one; a learning run named and never written has none). An agent-wide read's, never a read a run. */
|
|
303
|
+
kept(agentId: string): Promise<{
|
|
304
|
+
proposals: LearningProposal[];
|
|
305
|
+
learningRuns: RunRow[];
|
|
306
|
+
}>;
|
|
295
307
|
/** What learning spent outside any run, in one read: each run (not imported) whose learning ended in [from, to) (ms),
|
|
296
308
|
* its agent, when its learning ended and what its grade cost (null: unknown; 0: nothing graded). A learning dropped
|
|
297
309
|
* before it was proposed ended when it was kept; a proposal ended when its learning run ended (ended or failed), whose
|
|
@@ -767,6 +779,7 @@ export interface Runs {
|
|
|
767
779
|
agentId: string;
|
|
768
780
|
revisionId: string;
|
|
769
781
|
origin?: RunOrigin;
|
|
782
|
+
labels?: RunLabels;
|
|
770
783
|
}, launch?: RunLaunchInput): Promise<RunRow>;
|
|
771
784
|
/** A run whose agent is given inline and mapped to a source system by `agent.ref` and `revision.version`. In one
|
|
772
785
|
* transaction: the agent (one per `ref`, written on its first run, its name and description brought up to the version
|
|
@@ -794,6 +807,7 @@ export interface Runs {
|
|
|
794
807
|
run: {
|
|
795
808
|
id: string;
|
|
796
809
|
origin?: RunOrigin;
|
|
810
|
+
labels?: RunLabels;
|
|
797
811
|
};
|
|
798
812
|
launch: RunLaunchInput;
|
|
799
813
|
}): Promise<RunRow>;
|
|
@@ -801,13 +815,22 @@ export interface Runs {
|
|
|
801
815
|
/** The run's launch row (the runner reads it at its claim; the server for views). StoreLaunchMissing when the run has
|
|
802
816
|
* none (it was not started with one), never a default. */
|
|
803
817
|
launch(runId: string): Promise<RunLaunchRow>;
|
|
818
|
+
/** The learning start (the launch body's `learning` member, as stored: undefined when the body names none) of every run of
|
|
819
|
+
* agent `agentId` (no built-in learning run's) that has a launch row, in one read: what an agent-wide read (its cost per
|
|
820
|
+
* 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
|
|
821
|
+
* sealed bytes. A run with no launch row has no entry. */
|
|
822
|
+
learningStarts(agentId: string): Promise<{
|
|
823
|
+
runId: string;
|
|
824
|
+
learning: unknown;
|
|
825
|
+
}[]>;
|
|
804
826
|
/** Newest first, at most `limit` (no limit: all). `archived` filters on the run's own archive time (true: archived,
|
|
805
|
-
* false: not); its agent's archive is read apart. A built-in learning run (one a kept learning names) is never listed. */
|
|
827
|
+
* 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. */
|
|
806
828
|
list(filter: {
|
|
807
829
|
agentId?: string;
|
|
808
830
|
revisionId?: string;
|
|
809
831
|
state?: RunState;
|
|
810
832
|
archived?: boolean;
|
|
833
|
+
labels?: RunLabels;
|
|
811
834
|
limit?: number;
|
|
812
835
|
}): Promise<RunRow[]>;
|
|
813
836
|
/** Archives the run (its own archive time), or unarchives it: idempotent. */
|
|
@@ -1224,6 +1247,33 @@ export interface PairedComputers {
|
|
|
1224
1247
|
/** Removes the computer: its token dials no more. False when it was not paired (unknown, or removed already). */
|
|
1225
1248
|
revoke(id: string): Promise<boolean>;
|
|
1226
1249
|
}
|
|
1250
|
+
/** A hosted machine's minted token (store schema `minted_tokens`): what the machine must say it is at hello, and the
|
|
1251
|
+
* token's life. The token is not here: the store keeps its SHA-256 alone. */
|
|
1252
|
+
export interface MintedTokenRow {
|
|
1253
|
+
/** The machine's name (from its create's request id): its id in the attach hub. */
|
|
1254
|
+
readonly machine: string;
|
|
1255
|
+
readonly kind: string;
|
|
1256
|
+
readonly os: string;
|
|
1257
|
+
readonly arch: string;
|
|
1258
|
+
/** When the token ends: the machine's backstop. */
|
|
1259
|
+
readonly expiresAt: number;
|
|
1260
|
+
/** When it was revoked (the machine's delete); null while it is good. */
|
|
1261
|
+
readonly revokedAt: number | null;
|
|
1262
|
+
readonly createdAt: number;
|
|
1263
|
+
}
|
|
1264
|
+
/** The tokens minted for hosted machines that dial this server (a dial provider's create, spec/computer/attach.md). */
|
|
1265
|
+
export interface MintedTokens {
|
|
1266
|
+
/** Keeps the token's SHA-256 for `machine`, replacing one minted for it before. Rows past their end go in the same write. */
|
|
1267
|
+
mint(token: Pick<MintedTokenRow, "machine" | "kind" | "os" | "arch" | "expiresAt"> & {
|
|
1268
|
+
readonly tokenSha256: string;
|
|
1269
|
+
}): Promise<void>;
|
|
1270
|
+
/** The row whose token has this SHA-256, while it is good: neither revoked nor past its end. */
|
|
1271
|
+
byToken(tokenSha256: string): Promise<MintedTokenRow | undefined>;
|
|
1272
|
+
/** The machine's row, good or not; undefined when it has none (never minted, or gone past its end). */
|
|
1273
|
+
get(machine: string): Promise<MintedTokenRow | undefined>;
|
|
1274
|
+
/** Revokes the machine's token. False when it had none good. */
|
|
1275
|
+
revoke(machine: string): Promise<boolean>;
|
|
1276
|
+
}
|
|
1227
1277
|
/** A template package imported from GitHub (store schema `imported_templates`, POST /v2/templates/import): its id
|
|
1228
1278
|
* (`github:<owner>/<repo>[/<path>]`), its source as given, the commit SHA read, its publisher (the GitHub account), and
|
|
1229
1279
|
* its files as they were read, by path, base64. The server checks them again (templates.ts readPackage) as it loads them
|
|
@@ -1460,6 +1510,8 @@ export interface Store {
|
|
|
1460
1510
|
readonly computerLedger: ComputerLedger;
|
|
1461
1511
|
/** The people's own machines paired with this server, and the codes that pair them (spec/computer/attach.md). */
|
|
1462
1512
|
readonly pairedComputers: PairedComputers;
|
|
1513
|
+
/** The tokens minted for hosted machines that dial this server, each kept as its SHA-256. */
|
|
1514
|
+
readonly mintedTokens: MintedTokens;
|
|
1463
1515
|
/** The template packages imported from GitHub, their files kept as read. */
|
|
1464
1516
|
readonly importedTemplates: ImportedTemplates;
|
|
1465
1517
|
/** Each trigger source's sealed settings (design 2.1): a value per adapter, scope and field. */
|
|
@@ -51,7 +51,8 @@ export function piShaped(entries) {
|
|
|
51
51
|
const timestamp = typeof data.at === "number" ? { timestamp: data.at } : {};
|
|
52
52
|
if (entry.kind === KINDS.message) {
|
|
53
53
|
const text = typeof data.text === "string" ? data.text : "";
|
|
54
|
-
|
|
54
|
+
// The person's message, and one they steered into a turn in flight (claude-agent's), as pi writes both: a user turn.
|
|
55
|
+
if (data.role === "person" || data.role === "steer")
|
|
55
56
|
return { ...entry, kind: "pi.user", model: [{ role: "user", content: text, ...timestamp }] };
|
|
56
57
|
// A model turn's text; its stop reason is the answer's (a cut at the output limit reads "length", as pi's does).
|
|
57
58
|
const stopReason = data.stopReason === "length" ? "length" : "stop";
|
|
@@ -27,8 +27,22 @@ type KeptRow = {
|
|
|
27
27
|
};
|
|
28
28
|
/** What a kept row says of a run that looked back (learning-run.ts closeLearning's fields): none for one that did not. */
|
|
29
29
|
declare function answeredOf(row: KeptRow): Pick<Learning, "answered_at" | "job_cost_usd" | "look_back_usd">;
|
|
30
|
-
/**
|
|
31
|
-
|
|
30
|
+
/** The reads of a run's records a learning read makes: its launch, a round of its kept learning, a run's row (its
|
|
31
|
+
* learning run's). The store's own reads, one a run, or an agent's read at once (agentRecordsOf). */
|
|
32
|
+
export type RunRecords = {
|
|
33
|
+
/** `learningStart`: a run's learning start read from the agent's one narrow read (agentRecordsOf), when it was; absent, the run's launch is read. */
|
|
34
|
+
readonly runs: Pick<Store["runs"], "launch" | "get"> & {
|
|
35
|
+
readonly learningStart?: (runId: string) => Promise<RunLaunch["learning"]>;
|
|
36
|
+
};
|
|
37
|
+
readonly learning: Pick<Store["learning"], "proposal">;
|
|
38
|
+
};
|
|
39
|
+
/** Agent `agentId`'s runs' records read at once, whatever their number: its runs' launches (Store.runs.launches) and every
|
|
40
|
+
* round its runs' learning kept with the learning runs they name (Store.learning.kept), two reads beside `listed` (its
|
|
41
|
+
* runs, as runs.list read them). Each answers as the store's per-run read does: a run of `listed` with no launch row is
|
|
42
|
+
* StoreLaunchMissing, one that kept no learning has no round. A run not of `listed` is read from the store. */
|
|
43
|
+
export declare function agentRecordsOf(store: Store, agentId: string, listed: readonly RunRecord[]): Promise<RunRecords>;
|
|
44
|
+
/** Run `runId`'s learning end (its newest round's, or round `round`'s); null when the run kept no learning. Proposed while its learning run has not ended. `records`: where its rows are read (the store's per-run reads by default). */
|
|
45
|
+
export declare function runLearningEnd(store: Store, runId: string, round?: number, records?: RunRecords): Promise<RunLearningEnd | null>;
|
|
32
46
|
/** How the runs that tried to learn fared (GET /stats's `learning`): `runs` with a learning end, `merged`, `dropped` by
|
|
33
47
|
* reason, and `in_progress` (proposed, its learning run not ended). The shape today's counts give (learning-run.ts
|
|
34
48
|
* learningStats). */
|
|
@@ -41,8 +55,9 @@ export type LearningCounts = {
|
|
|
41
55
|
/** GET /stats's learning counts from the one store, over the runs `filter` picks as the analytics pick them (not archived,
|
|
42
56
|
* their own or their agent's; started in [from, to); of `agent`): an agentic run with a learning end counts, its end
|
|
43
57
|
* read as the run's view reads it (runLearningEnd). A workflow's run, and one with no learning, is not counted; nor is
|
|
44
|
-
* one whose reason this server does not give (an older server's). An imported run keeps no learning in the store.
|
|
45
|
-
|
|
58
|
+
* one whose reason this server does not give (an older server's). An imported run keeps no learning in the store. Each
|
|
59
|
+
* agent's runs' records are read at once (agentRecordsOf; `records`, already read for `filter.agent`), never a read a run. */
|
|
60
|
+
export declare function learningCountsOverStore(store: Store, filter: AnalyticsFilter, records?: RunRecords): Promise<LearningCounts>;
|
|
46
61
|
/** What learning spent outside any run (GET /usage's `learning` meter) in [from, to) (ms), one entry per run whose
|
|
47
62
|
* learning ended then, as the learning ledger's lines gave it: its agent, when its learning ended, and what its grade
|
|
48
63
|
* cost: 0 for a run never graded, null when the grade's spend is unknown (a grade that failed), never $0 then. One read
|
|
@@ -58,13 +73,15 @@ export declare function learningSpendOverStore(store: Store, window: {
|
|
|
58
73
|
/** An agent's learning counts as its learning view gives them (GET /agents/{id}/learning, learning-run.ts ofAgent's
|
|
59
74
|
* counts): how its runs that tried to learn fared, less `runs`, from the one store. Its notes' runs and its impact are
|
|
60
75
|
* agentLearningOverStore's. */
|
|
61
|
-
export declare function agentLearningCountsOverStore(store: Store, agentId: string): Promise<Omit<LearningCounts, "runs">>;
|
|
76
|
+
export declare function agentLearningCountsOverStore(store: Store, agentId: string, records?: RunRecords): Promise<Omit<LearningCounts, "runs">>;
|
|
62
77
|
/** Agent `agentId`'s learning view from the one store (GET /agents/{id}/learning, learning-run.ts ofAgent): its counts
|
|
63
78
|
* (agentLearningCountsOverStore), each note's runs given it and that read it (noteRuns over notesOf), and what learning
|
|
64
79
|
* changed (learningImpact), never a run's files. Each run's part is read from its launch (the notes it was given,
|
|
65
80
|
* learningStartOf), its journal once final (the notes its job read, notesReadOf) and its learning end (when its job
|
|
66
81
|
* answered and what it and looking back cost, its grade's cost). `seed_notes`, the notes a run started from, is its
|
|
67
|
-
* launch's seedNotes: every note in its seed, before the budget picked the given ones (main's seed_notes).
|
|
82
|
+
* launch's seedNotes: every note in its seed, before the budget picked the given ones (main's seed_notes). Its runs'
|
|
83
|
+
* launches and learning are read at once (agentRecordsOf), and a settled run's journal once a server (settledCache):
|
|
84
|
+
* a read a run only the first time it is seen. */
|
|
68
85
|
export declare function agentLearningOverStore(store: Store, agentId: string): Promise<{
|
|
69
86
|
counts: Omit<LearningCounts, "runs">;
|
|
70
87
|
impact: Impact;
|
|
@@ -99,28 +116,28 @@ export declare function servingReplayOf(records: readonly PromotionRecord[], run
|
|
|
99
116
|
* (roundsSpendOf's figures): its job is what it had cost when its first round answered, and everything after (each
|
|
100
117
|
* later round's follow-up turn and every round's look-back: feedback the run was given is learning, never the job) is
|
|
101
118
|
* its look-back here, `rowUsd` (the run's row cost) less that job (roundsLooked). */
|
|
102
|
-
export declare function learningSpendOf(store:
|
|
119
|
+
export declare function learningSpendOf(store: RunRecords, runId: string, rowUsd: number | null): Promise<{
|
|
103
120
|
looked: ReturnType<typeof answeredOf> | null;
|
|
104
121
|
grade: number | null;
|
|
105
122
|
}>;
|
|
106
123
|
/** Every round run `runId` kept (one a follow-up opened again is a round past its first), oldest first: none when it kept
|
|
107
124
|
* no learning. The store's proposal(runId) is the newest round alone; a read of what the run's learning did or spent
|
|
108
125
|
* reads them all. */
|
|
109
|
-
export declare function roundsOf(store: Pick<
|
|
126
|
+
export declare function roundsOf(store: Pick<RunRecords, "learning">, runId: string): Promise<LearningProposal[]>;
|
|
110
127
|
type RunRecord = NonNullable<Awaited<ReturnType<Store["runs"]["get"]>>>;
|
|
111
128
|
/** A run's own cost and what learning added for it (runCostOf): its row's cost, every round of its learning (a run a
|
|
112
129
|
* follow-up opened again, a review's or a person's, learned in rounds: every round's look-back and grade, roundsSpendOf,
|
|
113
130
|
* never the newest round's alone), else its one round's (learningSpendOf). `total_usd` is the run's all-in cost, the one
|
|
114
131
|
* the cost page shows and the money rule reads (pastRunsOverStore); null when any part is unknown. */
|
|
115
|
-
export declare function allInOf(store:
|
|
132
|
+
export declare function allInOf(store: RunRecords, run: RunRecord): Promise<ReturnType<typeof runCostOf>>;
|
|
116
133
|
/** One run of the cost series, as number `n` of it: its figures (allInOf) and its path (agentCostOverStore's loop body,
|
|
117
134
|
* and a learning batch's row once the run's learning has settled). */
|
|
118
|
-
export declare function costRunOf(store:
|
|
135
|
+
export declare function costRunOf(store: RunRecords, run: RunRecord, n: number): Promise<CostRun>;
|
|
119
136
|
/** The runs the money rule reads for agent `agentId` (runner/workflow-first.ts costLineOf), one set for the run's launch
|
|
120
137
|
* and the cost page: of its newest PAST_RUNS runs, each that ended (ended, stopped or failed), is neither imported nor
|
|
121
138
|
* archived nor a workflow revision's run, with its all-in cost (allInOf). `known`: all-in costs already read, by run id
|
|
122
|
-
* (the cost page's series), read again for no run. */
|
|
123
|
-
export declare function pastRunsOverStore(store: Store, agentId: string, known?: ReadonlyMap<string, number | null
|
|
139
|
+
* (the cost page's series), read again for no run; `records`, where any other's rows are read (the store's by default). */
|
|
140
|
+
export declare function pastRunsOverStore(store: Store, agentId: string, known?: ReadonlyMap<string, number | null>, records?: RunRecords): Promise<PastRun[]>;
|
|
124
141
|
/** The path run `runId` took and the learned workflow it ran, the one classifier its run record keeps (metrics.path,
|
|
125
142
|
* metrics.workflow, metrics.workflow_digest: workflow-first.ts pathMetrics, written at the run's end) and its cost per run
|
|
126
143
|
* reads (pathOfRow). A run its learned workflow served first (its WORKFLOW_FIRST entry, servedOf): `workflow` when it
|
|
@@ -164,7 +181,7 @@ export declare function roundsLooked(rounds: RoundsSpend, rowUsd: number | null)
|
|
|
164
181
|
job_cost_usd: number | null;
|
|
165
182
|
look_back_usd: number | null;
|
|
166
183
|
};
|
|
167
|
-
export declare function roundsSpendOf(store:
|
|
184
|
+
export declare function roundsSpendOf(store: RunRecords, runId: string): Promise<RoundsSpend | undefined>;
|
|
168
185
|
/** What a run's learning end tells its impact, as ofAgent's learningOf read a held run: how it ended and when, the notes
|
|
169
186
|
* it started from; when its job answered and its costs once it looked back (a look-back of 0 for an ended one that did
|
|
170
187
|
* not); its grade's cost once it ended (0 when nothing was graded). */
|