@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
|
@@ -9,7 +9,7 @@ import { posix } from "node:path";
|
|
|
9
9
|
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
10
10
|
import { currentLearning, holdsForOk, LEARNING_REASONS } from "../learning.js";
|
|
11
11
|
import { runLearningBody } from "../learning-routes.js";
|
|
12
|
-
import { learningStartOf, readLaunchBody, seedFailed } from "../run-launch.js";
|
|
12
|
+
import { learningStartOf, learningStartOfStored, readLaunchBody, seedFailed } from "../run-launch.js";
|
|
13
13
|
import { said, STOPPED } from "../learning-words.js";
|
|
14
14
|
import { learningImpact, noteRuns, notesRead } from "../learning-run.js";
|
|
15
15
|
import { costSummary, RUN_PATHS, runCostOf } from "../learning-cost.js";
|
|
@@ -19,7 +19,7 @@ import { PAST_RUNS, servedAnswerOf, servedAnswerStands, servedOf, workflowCostsO
|
|
|
19
19
|
import { reflects } from "../reflect-range.js";
|
|
20
20
|
import { notesOf } from "../usage.js";
|
|
21
21
|
import { runEntries, runReflect, runTimeline, withoutFeedbackRounds } from "./journal.js";
|
|
22
|
-
import { FINAL_STATES } from "../store/store.js";
|
|
22
|
+
import { FINAL_STATES, StoreLaunchMissing } from "../store/store.js";
|
|
23
23
|
import { journalEntries } from "../runner/journal-reader.js";
|
|
24
24
|
import { KINDS } from "../runner/journal-kinds.js";
|
|
25
25
|
import { keptOf, learnedOf, lostOf } from "../runner/learning-loop.js";
|
|
@@ -34,13 +34,48 @@ function answeredOf(row) {
|
|
|
34
34
|
return {};
|
|
35
35
|
return { answered_at: row.answered_at, job_cost_usd: usdOrNull(row.job_cost_usd), look_back_usd: usdOrNull(row.look_back_usd) };
|
|
36
36
|
}
|
|
37
|
-
/**
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
/** Agent `agentId`'s runs' records read at once, whatever their number: its runs' launches (Store.runs.launches) and every
|
|
38
|
+
* round its runs' learning kept with the learning runs they name (Store.learning.kept), two reads beside `listed` (its
|
|
39
|
+
* 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
|
|
40
|
+
* StoreLaunchMissing, one that kept no learning has no round. A run not of `listed` is read from the store. */
|
|
41
|
+
export async function agentRecordsOf(store, agentId, listed) {
|
|
42
|
+
const [starts, kept] = await Promise.all([store.runs.learningStarts(agentId), store.learning.kept(agentId)]);
|
|
43
|
+
const ours = new Set(listed.map((run) => run.id));
|
|
44
|
+
const startOf = new Map(starts.map((row) => [row.runId, row.learning]));
|
|
45
|
+
// Each run's rounds, oldest first (the store reads them so).
|
|
46
|
+
const rounds = new Map();
|
|
47
|
+
for (const one of kept.proposals)
|
|
48
|
+
rounds.set(one.runId, [...(rounds.get(one.runId) ?? []), one]);
|
|
49
|
+
const rows = new Map([...listed, ...kept.learningRuns].map((run) => [run.id, run]));
|
|
50
|
+
return {
|
|
51
|
+
runs: {
|
|
52
|
+
launch: (runId) => store.runs.launch(runId),
|
|
53
|
+
learningStart: async (runId) => {
|
|
54
|
+
if (!ours.has(runId))
|
|
55
|
+
return learningStartOfRun(store, runId);
|
|
56
|
+
if (!startOf.has(runId))
|
|
57
|
+
throw new StoreLaunchMissing(runId);
|
|
58
|
+
return learningStartOfStored(startOf.get(runId));
|
|
59
|
+
},
|
|
60
|
+
get: async (id) => rows.get(id) ?? store.runs.get(id),
|
|
61
|
+
},
|
|
62
|
+
learning: {
|
|
63
|
+
proposal: async (runId, round) => {
|
|
64
|
+
if (!ours.has(runId))
|
|
65
|
+
return store.learning.proposal(runId, round);
|
|
66
|
+
const list = rounds.get(runId);
|
|
67
|
+
return round === undefined ? list?.at(-1) : list?.find((one) => one.round === round);
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/** 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). */
|
|
73
|
+
export async function runLearningEnd(store, runId, round, records = store) {
|
|
74
|
+
const kept = await records.learning.proposal(runId, round);
|
|
40
75
|
if (!kept)
|
|
41
76
|
return null;
|
|
42
77
|
const row = (kept.proposal ?? {});
|
|
43
|
-
return { ...(await endOfKept(store, kept, row)), ...answeredOf(row), ...compiledOf(row) };
|
|
78
|
+
return { ...(await endOfKept(store, kept, row, records)), ...answeredOf(row), ...compiledOf(row) };
|
|
44
79
|
}
|
|
45
80
|
/** What a kept row says of its compile turn (runner/reflect-hook.ts): the record, and a failed draft's errors; read as
|
|
46
81
|
* untrusted, an entry out of shape left out. */
|
|
@@ -59,7 +94,7 @@ function compiledOf(row) {
|
|
|
59
94
|
return out;
|
|
60
95
|
}
|
|
61
96
|
/** The learning end a kept row and its learning run's journal say. */
|
|
62
|
-
async function endOfKept(store, kept, row) {
|
|
97
|
+
async function endOfKept(store, kept, row, records = store) {
|
|
63
98
|
const at = timeOf(kept.createdAt);
|
|
64
99
|
// Dropped before it was proposed (a cut run, nothing to keep, the checks): its end is the kept row's.
|
|
65
100
|
if (row.state !== "proposed" || !row.proposal) {
|
|
@@ -70,14 +105,15 @@ async function endOfKept(store, kept, row) {
|
|
|
70
105
|
const proposed = { state: "proposed", reason: null, detail: row.detail ?? null, at, ...left };
|
|
71
106
|
if (!kept.learningRunId)
|
|
72
107
|
return proposed;
|
|
73
|
-
|
|
74
|
-
const
|
|
75
|
-
const merged = dataOf(KINDS.learningMerged);
|
|
76
|
-
const dropped = dataOf(KINDS.learningDropped);
|
|
108
|
+
let learningRun = await records.runs.get(kept.learningRunId);
|
|
109
|
+
const { merged, dropped, graded } = await learningEndEntries(store, kept.learningRunId, learningRun);
|
|
77
110
|
if (!merged && !dropped)
|
|
78
111
|
return proposed;
|
|
79
|
-
|
|
80
|
-
|
|
112
|
+
// The loop saves its end entry and the learning run's end (state, ended_at) in one transaction, and the row was read
|
|
113
|
+
// before the journal: an end the row had not seen landed between the two reads. The row read again from the store (past
|
|
114
|
+
// any list read before) is the ended one, so the end is at its ended_at, never once at the proposal's time.
|
|
115
|
+
if (!(learningRun && FINAL_STATES.includes(learningRun.state)))
|
|
116
|
+
learningRun = await store.runs.get(kept.learningRunId);
|
|
81
117
|
const endedAt = learningRun?.endedAt ? timeOf(learningRun.endedAt) : at;
|
|
82
118
|
// What the grade spent: the graded entry's, or what a grade that failed spent before it did.
|
|
83
119
|
const spent = graded ?? (dropped && "usd" in dropped ? { usd: dropped.usd ?? null, tokens: dropped.tokens ?? null } : undefined);
|
|
@@ -110,14 +146,33 @@ async function endOfKept(store, kept, row) {
|
|
|
110
146
|
/** GET /stats's learning counts from the one store, over the runs `filter` picks as the analytics pick them (not archived,
|
|
111
147
|
* their own or their agent's; started in [from, to); of `agent`): an agentic run with a learning end counts, its end
|
|
112
148
|
* read as the run's view reads it (runLearningEnd). A workflow's run, and one with no learning, is not counted; nor is
|
|
113
|
-
* one whose reason this server does not give (an older server's). An imported run keeps no learning in the store.
|
|
114
|
-
|
|
149
|
+
* one whose reason this server does not give (an older server's). An imported run keeps no learning in the store. Each
|
|
150
|
+
* agent's runs' records are read at once (agentRecordsOf; `records`, already read for `filter.agent`), never a read a run. */
|
|
151
|
+
export async function learningCountsOverStore(store, filter, records) {
|
|
115
152
|
const from = filter.from === undefined ? -Infinity : Date.parse(filter.from);
|
|
116
153
|
const to = filter.to === undefined ? Infinity : Date.parse(filter.to);
|
|
117
154
|
const out = { runs: 0, merged: 0, dropped: {}, in_progress: 0 };
|
|
118
155
|
const agentArchived = new Map();
|
|
119
156
|
const workflow = new Map();
|
|
120
|
-
|
|
157
|
+
const listed = await store.runs.list(filter.agent !== undefined ? { agentId: filter.agent } : {});
|
|
158
|
+
const byAgent = new Map();
|
|
159
|
+
for (const run of listed) {
|
|
160
|
+
const runs = byAgent.get(run.agentId);
|
|
161
|
+
if (runs)
|
|
162
|
+
runs.push(run);
|
|
163
|
+
else
|
|
164
|
+
byAgent.set(run.agentId, [run]);
|
|
165
|
+
}
|
|
166
|
+
const read = new Map();
|
|
167
|
+
const recordsOf = (agentId) => {
|
|
168
|
+
if (records && agentId === filter.agent)
|
|
169
|
+
return Promise.resolve(records);
|
|
170
|
+
let one = read.get(agentId);
|
|
171
|
+
if (!one)
|
|
172
|
+
read.set(agentId, (one = agentRecordsOf(store, agentId, byAgent.get(agentId) ?? [])));
|
|
173
|
+
return one;
|
|
174
|
+
};
|
|
175
|
+
for (const run of listed) {
|
|
121
176
|
if (filter.agent !== undefined && run.agentId !== filter.agent)
|
|
122
177
|
continue;
|
|
123
178
|
if (run.importedFrom || run.archivedAt !== null || !(run.startedAt >= from && run.startedAt < to))
|
|
@@ -130,7 +185,7 @@ export async function learningCountsOverStore(store, filter) {
|
|
|
130
185
|
workflow.set(run.revisionId, (await store.agents.revision(run.revisionId))?.kind === "workflow");
|
|
131
186
|
if (workflow.get(run.revisionId))
|
|
132
187
|
continue;
|
|
133
|
-
const learning = await runLearningEnd(store, run.id);
|
|
188
|
+
const learning = await runLearningEnd(store, run.id, undefined, await recordsOf(run.agentId));
|
|
134
189
|
// A reason this server does not give (an older server's) is not counted.
|
|
135
190
|
if (!learning || (learning.reason !== null && !LEARNING_REASONS.includes(learning.reason)))
|
|
136
191
|
continue;
|
|
@@ -154,8 +209,8 @@ export async function learningSpendOverStore(store, window) {
|
|
|
154
209
|
/** An agent's learning counts as its learning view gives them (GET /agents/{id}/learning, learning-run.ts ofAgent's
|
|
155
210
|
* counts): how its runs that tried to learn fared, less `runs`, from the one store. Its notes' runs and its impact are
|
|
156
211
|
* agentLearningOverStore's. */
|
|
157
|
-
export async function agentLearningCountsOverStore(store, agentId) {
|
|
158
|
-
const { runs: _, ...counts } = await learningCountsOverStore(store, { agent: agentId });
|
|
212
|
+
export async function agentLearningCountsOverStore(store, agentId, records) {
|
|
213
|
+
const { runs: _, ...counts } = await learningCountsOverStore(store, { agent: agentId }, records);
|
|
159
214
|
return counts;
|
|
160
215
|
}
|
|
161
216
|
/** Agent `agentId`'s learning view from the one store (GET /agents/{id}/learning, learning-run.ts ofAgent): its counts
|
|
@@ -163,22 +218,24 @@ export async function agentLearningCountsOverStore(store, agentId) {
|
|
|
163
218
|
* changed (learningImpact), never a run's files. Each run's part is read from its launch (the notes it was given,
|
|
164
219
|
* learningStartOf), its journal once final (the notes its job read, notesReadOf) and its learning end (when its job
|
|
165
220
|
* answered and what it and looking back cost, its grade's cost). `seed_notes`, the notes a run started from, is its
|
|
166
|
-
* launch's seedNotes: every note in its seed, before the budget picked the given ones (main's seed_notes).
|
|
221
|
+
* launch's seedNotes: every note in its seed, before the budget picked the given ones (main's seed_notes). Its runs'
|
|
222
|
+
* launches and learning are read at once (agentRecordsOf), and a settled run's journal once a server (settledCache):
|
|
223
|
+
* a read a run only the first time it is seen. */
|
|
167
224
|
export async function agentLearningOverStore(store, agentId) {
|
|
168
|
-
const
|
|
225
|
+
const listed = (await store.runs.list({ agentId })).filter((run) => run.agentId === agentId);
|
|
226
|
+
const records = await agentRecordsOf(store, agentId, listed);
|
|
227
|
+
const counts = await agentLearningCountsOverStore(store, agentId, records);
|
|
169
228
|
const kinds = new Map();
|
|
170
229
|
const rows = [];
|
|
171
230
|
const learnings = new Map();
|
|
172
231
|
const files = [];
|
|
173
|
-
for (const run of
|
|
174
|
-
if (run.agentId !== agentId)
|
|
175
|
-
continue;
|
|
232
|
+
for (const run of listed) {
|
|
176
233
|
if (!kinds.has(run.revisionId))
|
|
177
234
|
kinds.set(run.revisionId, (await store.agents.revision(run.revisionId))?.kind);
|
|
178
235
|
const final = FINAL_STATES.includes(run.state);
|
|
179
|
-
const started = await learningStartOfRun(
|
|
236
|
+
const started = await learningStartOfRun(records, run.id);
|
|
180
237
|
// A run that only uses what its agent learned keeps no proposal: its end is its start's (usedOnly), as its run reads give it.
|
|
181
|
-
const end = (await runLearningEnd(store, run.id)) ?? (started?.use ? usedOnly(started, final, timeOf(run.endedAt ?? run.startedAt)) : null);
|
|
238
|
+
const end = (await runLearningEnd(store, run.id, undefined, records)) ?? (started?.use ? usedOnly(started, final, timeOf(run.endedAt ?? run.startedAt)) : null);
|
|
182
239
|
const { read, laid } = await journalReadsOf(store, run, started);
|
|
183
240
|
if (started || end)
|
|
184
241
|
files.push(notesOf({ given: started?.given ?? [], read }));
|
|
@@ -190,7 +247,7 @@ export async function agentLearningOverStore(store, agentId) {
|
|
|
190
247
|
});
|
|
191
248
|
// What its claims laid of the skills and workflows it was offered (every learningLaid entry, laidOf): the run started
|
|
192
249
|
// from those alone.
|
|
193
|
-
learnings.set(run.id, end ? impactLearningOf(end, started, laid, await roundsSpendOf(
|
|
250
|
+
learnings.set(run.id, end ? impactLearningOf(end, started, laid, await roundsSpendOf(records, run.id), run.costUsd) : null);
|
|
194
251
|
}
|
|
195
252
|
return { counts, impact: learningImpact(rows, (row) => learnings.get(row.id) ?? null), notes: noteRuns(files) };
|
|
196
253
|
}
|
|
@@ -205,7 +262,10 @@ export async function agentLearningOverStore(store, agentId) {
|
|
|
205
262
|
* `limit`: the latest runs shown, each keeping its number; the summary is over every run. */
|
|
206
263
|
export async function agentCostOverStore(store, agentId, limit = Infinity) {
|
|
207
264
|
const kinds = new Map();
|
|
208
|
-
const
|
|
265
|
+
const listed = (await store.runs.list({ agentId })).filter((run) => run.agentId === agentId);
|
|
266
|
+
// Every run's launch and learning in a few reads (agentRecordsOf), never a read a run.
|
|
267
|
+
const records = await agentRecordsOf(store, agentId, listed);
|
|
268
|
+
const ended = listed.filter((run) => FINAL_STATES.includes(run.state) && !run.importedFrom && run.archivedAt === null).sort((a, b) => a.startedAt - b.startedAt || (a.id < b.id ? -1 : 1));
|
|
209
269
|
const runs = [];
|
|
210
270
|
let unknownPath = 0;
|
|
211
271
|
for (const run of ended) {
|
|
@@ -214,16 +274,16 @@ export async function agentCostOverStore(store, agentId, limit = Infinity) {
|
|
|
214
274
|
if (kinds.get(run.revisionId) === "workflow")
|
|
215
275
|
continue;
|
|
216
276
|
// A run that learns whose record names no path is left out and counted, never `agent` at $0.
|
|
217
|
-
if (!pathOfRow(run.metrics, await learningStartOfRun(
|
|
277
|
+
if (!pathOfRow(run.metrics, await learningStartOfRun(records, run.id))) {
|
|
218
278
|
unknownPath += 1;
|
|
219
279
|
continue;
|
|
220
280
|
}
|
|
221
|
-
runs.push(await costRunOf(
|
|
281
|
+
runs.push(await costRunOf(records, run, runs.length + 1));
|
|
222
282
|
}
|
|
223
283
|
// Each learned workflow that ran first, where it stands against the money rule (workflow-first.ts workflowCostsOf), over
|
|
224
284
|
// the runs the run's launch reads (pastRunsOverStore) at the all-in cost this series shows: a workflow over the line
|
|
225
285
|
// shows `needs_revision` with its two numbers, so the page and the launch's decision agree.
|
|
226
|
-
const workflows = workflowCostsOf(await pastRunsOverStore(store, agentId, new Map(runs.map((run) => [run.run_id, run.total_usd]))));
|
|
286
|
+
const workflows = workflowCostsOf(await pastRunsOverStore(store, agentId, new Map(runs.map((run) => [run.run_id, run.total_usd])), records));
|
|
227
287
|
const replay = servingReplayOf(await promotionsOf(store.settings, agentId), runs);
|
|
228
288
|
return { runs: runs.slice(Math.max(0, runs.length - limit)), summary: costSummary(runs, replay), total_runs: runs.length, unknown_cost_runs: runs.filter((run) => run.total_usd === null).length, unknown_path_runs: unknownPath, workflows };
|
|
229
289
|
}
|
|
@@ -311,8 +371,8 @@ export async function costRunOf(store, run, n) {
|
|
|
311
371
|
/** The runs the money rule reads for agent `agentId` (runner/workflow-first.ts costLineOf), one set for the run's launch
|
|
312
372
|
* and the cost page: of its newest PAST_RUNS runs, each that ended (ended, stopped or failed), is neither imported nor
|
|
313
373
|
* archived nor a workflow revision's run, with its all-in cost (allInOf). `known`: all-in costs already read, by run id
|
|
314
|
-
* (the cost page's series), read again for no run. */
|
|
315
|
-
export async function pastRunsOverStore(store, agentId, known) {
|
|
374
|
+
* (the cost page's series), read again for no run; `records`, where any other's rows are read (the store's by default). */
|
|
375
|
+
export async function pastRunsOverStore(store, agentId, known, records = store) {
|
|
316
376
|
const kinds = new Map();
|
|
317
377
|
const kept = [];
|
|
318
378
|
for (const run of await store.runs.list({ agentId, limit: PAST_RUNS })) {
|
|
@@ -326,7 +386,7 @@ export async function pastRunsOverStore(store, agentId, known) {
|
|
|
326
386
|
// A few reads a run, a batch at a time: a launch reads up to PAST_RUNS of them.
|
|
327
387
|
const past = [];
|
|
328
388
|
for (let at = 0; at < kept.length; at += 16) {
|
|
329
|
-
past.push(...(await Promise.all(kept.slice(at, at + 16).map(async (run) => ({ metrics: run.metrics, startedAt: run.startedAt, allInUsd: known?.has(run.id) ? known.get(run.id) : (await allInOf(
|
|
389
|
+
past.push(...(await Promise.all(kept.slice(at, at + 16).map(async (run) => ({ metrics: run.metrics, startedAt: run.startedAt, allInUsd: known?.has(run.id) ? known.get(run.id) : (await allInOf(records, run)).total_usd })))));
|
|
330
390
|
}
|
|
331
391
|
return past;
|
|
332
392
|
}
|
|
@@ -389,24 +449,40 @@ async function journalReadsOf(store, run, started) {
|
|
|
389
449
|
}
|
|
390
450
|
/** `name` when it is one of the learned workflows the run's launch offered, else null. */
|
|
391
451
|
const offeredName = (name, offered) => (name !== null && offered?.includes(name) ? name : null);
|
|
392
|
-
/** What a settled run's journal tells the agent's learning view, kept by store and run id with the run's epoch: a claim
|
|
393
|
-
* and a run's end each move the epoch, and only a claim writes to its journal, so a settled run's reads hold until the
|
|
394
|
-
* next claim of it. At most SETTLED_READS_MAX runs a store, the oldest read dropped first. */
|
|
395
|
-
const settledReads = new WeakMap();
|
|
396
452
|
const SETTLED_READS_MAX = 4096;
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
const
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
453
|
+
/** A cache of what a settled run's journal says, by store and run id with the run's epoch (see above), at most
|
|
454
|
+
* SETTLED_READS_MAX runs a store, the oldest read dropped first. A read in flight is kept too, so two reads of the
|
|
455
|
+
* agent at once (its page and its tab) walk a run's journal once; one that fails is dropped, for the next to read. */
|
|
456
|
+
function settledCache() {
|
|
457
|
+
const byStore = new WeakMap();
|
|
458
|
+
return (store, runId, epoch, read) => {
|
|
459
|
+
const runs = byStore.get(store) ?? new Map();
|
|
460
|
+
byStore.set(store, runs);
|
|
461
|
+
const kept = runs.get(runId);
|
|
462
|
+
if (kept && kept.epoch === epoch)
|
|
463
|
+
return kept.value;
|
|
464
|
+
const value = read();
|
|
465
|
+
const entry = { epoch, value };
|
|
466
|
+
runs.delete(runId);
|
|
467
|
+
runs.set(runId, entry);
|
|
468
|
+
if (runs.size > SETTLED_READS_MAX)
|
|
469
|
+
runs.delete(runs.keys().next().value);
|
|
470
|
+
value.catch(() => { if (runs.get(runId) === entry)
|
|
471
|
+
runs.delete(runId); });
|
|
472
|
+
return value;
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
const settledJournalReads = settledCache();
|
|
476
|
+
const settledLearningEnds = settledCache();
|
|
477
|
+
/** Learning run `id`'s end entries (`run`: its row): read once it is final and kept (settledCache), so an agent's
|
|
478
|
+
* learning view reads each of its learning runs' journals once, not at every read; read now while it runs. */
|
|
479
|
+
async function learningEndEntries(store, id, run) {
|
|
480
|
+
const read = async () => {
|
|
481
|
+
const entries = await journalEntries(store.readJournal(id), BACKGROUND_CONTEXT);
|
|
482
|
+
const dataOf = (kind) => entries.find((entry) => entry.kind === kind)?.data;
|
|
483
|
+
return { merged: dataOf(KINDS.learningMerged), dropped: dataOf(KINDS.learningDropped), graded: dataOf(KINDS.learningGraded) };
|
|
484
|
+
};
|
|
485
|
+
return run && FINAL_STATES.includes(run.state) ? settledLearningEnds(store, id, run.epoch, read) : read();
|
|
410
486
|
}
|
|
411
487
|
/** What every claim of a run laid, from its learningLaid entries, each name once: a resumed claim finds an earlier
|
|
412
488
|
* claim's skill folders there already and lays none of them again, though the run still has them. None laid when it has
|
|
@@ -593,6 +669,9 @@ export function withNotes(end, started, read) {
|
|
|
593
669
|
/** Run `runId`'s learning start as its launch records it (run-launch.ts learningStartOf, the one reader): its given notes,
|
|
594
670
|
* its seed sha and its # Learned section; undefined when the run does not learn or has no launch. */
|
|
595
671
|
async function learningStartOfRun(store, runId) {
|
|
672
|
+
// The agent's narrow read (agentRecordsOf) answers when the run is in it; a missing launch reads as a run that does not learn.
|
|
673
|
+
if (store.runs.learningStart)
|
|
674
|
+
return store.runs.learningStart(runId).catch(() => undefined);
|
|
596
675
|
const row = await store.runs.launch(runId).catch(() => undefined);
|
|
597
676
|
const launch = row ? readLaunchBody(row.body) : undefined;
|
|
598
677
|
return launch ? learningStartOf(launch) : undefined;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Context } from "@earendil-works/chord/context";
|
|
2
|
-
import { type ImportedFrom, type RunRow, type Store } from "../store/store.js";
|
|
2
|
+
import { type ImportedFrom, type RunLabels, type RunRow, type Store } from "../store/store.js";
|
|
3
3
|
/** A revision's kind, as the row names it. */
|
|
4
4
|
export type RevisionKind = "agentic" | "workflow";
|
|
5
5
|
/** The run state the v2 API serves, as the old store kept it: a non-terminal run is 'running' (the live view refines its
|
|
@@ -29,11 +29,12 @@ export interface RunRowView {
|
|
|
29
29
|
* stopped (`kind`: its revision's), whose turn ended and never the run, as main's stop leaves one (runs.ts statusOf: a
|
|
30
30
|
* stopped run is input_required and idle). A cancel, a workflow's stop and an imported run's read 'stopped'. */
|
|
31
31
|
export declare function runReadState(run: RunRow, kind: RevisionKind): RunReadState;
|
|
32
|
-
/** The runs, newest first; `agent` and `
|
|
33
|
-
* the archive time coalesced onto each row, and a not-ended run's cost its booked-so-far spend. */
|
|
32
|
+
/** The runs, newest first; `agent`, `revision` and `labels` (every one held) narrow it. Archived runs are listed too (the
|
|
33
|
+
* server filters them), with the archive time coalesced onto each row, and a not-ended run's cost its booked-so-far spend. */
|
|
34
34
|
export declare function listRuns(store: Store, filter: {
|
|
35
35
|
agent?: string;
|
|
36
36
|
revision?: string;
|
|
37
|
+
labels?: RunLabels;
|
|
37
38
|
}, context: Context): Promise<RunRowView[]>;
|
|
38
39
|
/** One run with its agent's name; undefined for an unknown run. */
|
|
39
40
|
export declare function readRun(store: Store, runId: string, context: Context): Promise<(RunRowView & {
|
package/dist/store-reads/runs.js
CHANGED
|
@@ -60,12 +60,13 @@ function joins(store, context) {
|
|
|
60
60
|
},
|
|
61
61
|
};
|
|
62
62
|
}
|
|
63
|
-
/** The runs, newest first; `agent` and `
|
|
64
|
-
* the archive time coalesced onto each row, and a not-ended run's cost its booked-so-far spend. */
|
|
63
|
+
/** The runs, newest first; `agent`, `revision` and `labels` (every one held) narrow it. Archived runs are listed too (the
|
|
64
|
+
* server filters them), with the archive time coalesced onto each row, and a not-ended run's cost its booked-so-far spend. */
|
|
65
65
|
export async function listRuns(store, filter, context) {
|
|
66
66
|
const runs = await store.runs.list({
|
|
67
67
|
...(filter.agent !== undefined ? { agentId: filter.agent } : {}),
|
|
68
68
|
...(filter.revision !== undefined ? { revisionId: filter.revision } : {}),
|
|
69
|
+
...(filter.labels !== undefined ? { labels: filter.labels } : {}),
|
|
69
70
|
});
|
|
70
71
|
const join = joins(store, context);
|
|
71
72
|
const views = [];
|
package/dist/store-view.js
CHANGED
|
@@ -459,6 +459,8 @@ export async function viewOverStore(store, runId, deps) {
|
|
|
459
459
|
// Only what an imported run shows: never the server's internal file stamp (importedFrom.file).
|
|
460
460
|
imported_from: runRow.importedFrom ? { source: runRow.importedFrom.source, session: runRow.importedFrom.session } : null,
|
|
461
461
|
trigger: launch?.trigger ? { id: launch.trigger.id, firing_key: launch.trigger.firing_key } : null,
|
|
462
|
+
// The caller's labels, as given at the start ({} when none): its own strings, never cut.
|
|
463
|
+
labels: runRow.labels,
|
|
462
464
|
// Cut by the run's one cut (the pointers it was handed among them), and none for a withheld run, as its words.
|
|
463
465
|
learning: unshown ? null : learningViewOf(run.learningEnd, secretsShown(values), settled),
|
|
464
466
|
poll_after_ms: settled ? 0 : 1000,
|
|
@@ -470,13 +472,13 @@ export async function summaryOverStore(store, runId, deps) {
|
|
|
470
472
|
const view = await viewOverStore(store, runId, deps);
|
|
471
473
|
if (!view)
|
|
472
474
|
return undefined;
|
|
473
|
-
const { run_id, agent_id, agent_version, console_url, revision, kind, sha, status, state, title, effort, created_at, ended_at, error, review, pending, cost, archived_at, imported_from, trigger, learning } = view;
|
|
475
|
+
const { run_id, agent_id, agent_version, console_url, revision, kind, sha, status, state, title, effort, created_at, ended_at, error, review, pending, cost, archived_at, imported_from, trigger, labels, learning } = view;
|
|
474
476
|
return {
|
|
475
477
|
run_id, agent_id, agent_version, console_url, revision, kind, sha, status, state, title,
|
|
476
478
|
...(view.sdk ? { sdk: view.sdk } : {}),
|
|
477
479
|
...(view.native ? { native: view.native } : {}),
|
|
478
480
|
...(effort ? { effort } : {}),
|
|
479
|
-
created_at, ended_at, error, review, pending, cost, archived_at, imported_from, trigger,
|
|
481
|
+
created_at, ended_at, error, review, pending, cost, archived_at, imported_from, trigger, labels,
|
|
480
482
|
learning: learning ? shortOf(learning) : null,
|
|
481
483
|
};
|
|
482
484
|
}
|
package/dist/template-eval.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type Layout, type MailboxAfter, type MailboxFixture, type MailboxRecord } from "./eval-mailbox.js";
|
|
2
|
+
import { type FeedFixture } from "./eval-feed.js";
|
|
2
3
|
import type { MonidFake } from "./runner/monid-run.js";
|
|
3
4
|
import { type WebFake } from "./web-fake.js";
|
|
4
5
|
import { type Package } from "./templates.js";
|
|
@@ -121,6 +122,9 @@ export type EvalCase = {
|
|
|
121
122
|
/** The case's fake mailbox (eval-mailbox.ts): each run on each of its layouts gets a fake account seeded from it, and is
|
|
122
123
|
* started by the package's trigger as it would be. Absent: the server's account, if any. */
|
|
123
124
|
email?: MailboxFixture;
|
|
125
|
+
/** The case's fake feed (eval-feed.ts): each run gets fake feeds served from it, read in place of the URLs the
|
|
126
|
+
* package's feed trigger names, and is started by that trigger as it would be. */
|
|
127
|
+
feed?: FeedFixture;
|
|
124
128
|
};
|
|
125
129
|
/** Cases that do not check: every problem, each naming its file. */
|
|
126
130
|
export declare class CaseError extends Error {
|