@parcha/agentrun-serve 0.0.0-stage → 0.1.0-beta.29
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 +560 -0
- package/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +1723 -2
- package/dist/adapters.d.ts +205 -0
- package/dist/adapters.js +459 -0
- package/dist/agents.d.ts +124 -0
- package/dist/agents.js +302 -0
- package/dist/app.d.ts +7 -0
- package/dist/app.js +324 -0
- package/dist/bound-files.d.ts +4 -0
- package/dist/bound-files.js +164 -0
- package/dist/box/record.d.ts +6 -0
- package/dist/box/record.js +41 -0
- package/dist/box/sweep.d.ts +53 -0
- package/dist/box/sweep.js +193 -0
- package/dist/box-image.d.ts +98 -0
- package/dist/box-image.js +283 -0
- package/dist/box-relay.d.ts +42 -0
- package/dist/box-relay.js +222 -0
- package/dist/boxes.d.ts +54 -0
- package/dist/boxes.js +182 -0
- package/dist/cap.d.ts +224 -0
- package/dist/cap.js +721 -0
- package/dist/catalog.d.ts +20 -0
- package/dist/catalog.js +53 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +167 -0
- package/dist/coding-tools.d.ts +31 -0
- package/dist/coding-tools.js +81 -0
- package/dist/console/THIRD-PARTY-NOTICES.txt +1141 -0
- package/dist/console/assets/index-BN7oVcO4.js +445 -0
- package/dist/console/assets/index-By-jkqki.css +1 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-400-normal-BEIGL1Tu.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-400-normal-CIEtRijs.woff +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-600-normal-BB5xRk30.woff +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-600-normal-EVf6-Yzo.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-ext-400-normal-BHyURHCj.woff +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-ext-400-normal-C_uLvvQ5.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-ext-600-normal-Dj6eZy5f.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-ext-600-normal-DpeVePZf.woff +0 -0
- package/dist/console/assets/jetbrains-mono-greek-400-normal-C190GLew.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-greek-400-normal-CNojz0t3.woff +0 -0
- package/dist/console/assets/jetbrains-mono-greek-600-normal-3KAm9r92.woff +0 -0
- package/dist/console/assets/jetbrains-mono-greek-600-normal-H7WoG9Et.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-400-normal-B11XCQ5g.woff +0 -0
- package/dist/console/assets/jetbrains-mono-latin-400-normal-V6pRDFza.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-600-normal-C8RAYTDA.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-600-normal-DXv3JcnD.woff +0 -0
- package/dist/console/assets/jetbrains-mono-latin-ext-400-normal-Bc8Ftmh3.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-ext-400-normal-DHMOLxAi.woff +0 -0
- package/dist/console/assets/jetbrains-mono-latin-ext-600-normal-BfB_LPfz.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-ext-600-normal-DiQlUoE6.woff +0 -0
- package/dist/console/assets/jetbrains-mono-vietnamese-400-normal-BeU3T8wf.woff +0 -0
- package/dist/console/assets/jetbrains-mono-vietnamese-400-normal-ByoDsISC.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-vietnamese-600-normal-CSpzN4cI.woff +0 -0
- package/dist/console/assets/jetbrains-mono-vietnamese-600-normal-Dtizs43-.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-400-normal-Cph9ettZ.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-400-normal-DfGZKnlb.woff +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-600-normal-BGBUNdzT.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-600-normal-COje25QW.woff +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-ext-400-normal-4l4lq8zr.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-ext-400-normal-BGzXWJeR.woff +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-ext-600-normal-8_E36CQj.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-ext-600-normal-C27an7Zc.woff +0 -0
- package/dist/console/index.html +15 -0
- package/dist/daytona-api.d.ts +21 -0
- package/dist/daytona-api.js +101 -0
- package/dist/decision-rows.d.ts +11 -0
- package/dist/decision-rows.js +116 -0
- package/dist/decisions.d.ts +94 -0
- package/dist/decisions.js +184 -0
- package/dist/effort-guidance.d.ts +5 -0
- package/dist/effort-guidance.js +14 -0
- package/dist/environment.d.ts +5 -0
- package/dist/environment.js +11 -0
- package/dist/errors.d.ts +72 -0
- package/dist/errors.js +66 -0
- package/dist/exa-keyless.d.ts +35 -0
- package/dist/exa-keyless.js +202 -0
- package/dist/fetch-page.d.ts +114 -0
- package/dist/fetch-page.js +182 -0
- package/dist/files.d.ts +60 -0
- package/dist/files.js +153 -0
- package/dist/grade.d.ts +96 -0
- package/dist/grade.js +348 -0
- package/dist/graph-view.d.ts +100 -0
- package/dist/graph-view.js +212 -0
- package/dist/harness-app.d.ts +38 -0
- package/dist/harness-app.js +626 -0
- package/dist/harness.d.ts +53 -0
- package/dist/harness.js +74 -0
- package/dist/home-path.d.ts +27 -0
- package/dist/home-path.js +78 -0
- package/dist/host-tools.d.ts +20 -0
- package/dist/host-tools.js +140 -0
- package/dist/host.d.ts +39 -0
- package/dist/host.js +81 -0
- package/dist/hosted-search.d.ts +27 -0
- package/dist/hosted-search.js +129 -0
- package/dist/import-sources.d.ts +104 -0
- package/dist/import-sources.js +629 -0
- package/dist/import-summary.d.ts +25 -0
- package/dist/import-summary.js +75 -0
- package/dist/import-worker.d.ts +26 -0
- package/dist/import-worker.js +41 -0
- package/dist/import.d.ts +145 -0
- package/dist/import.js +1221 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +6 -0
- package/dist/key-check.d.ts +36 -0
- package/dist/key-check.js +108 -0
- package/dist/key-refusal.d.ts +51 -0
- package/dist/key-refusal.js +187 -0
- package/dist/learn/check.d.ts +99 -0
- package/dist/learn/check.js +259 -0
- package/dist/learn/grade.d.ts +79 -0
- package/dist/learn/grade.js +433 -0
- package/dist/learn/index.d.ts +7 -0
- package/dist/learn/index.js +11 -0
- package/dist/learn/invisible.d.ts +5 -0
- package/dist/learn/invisible.js +42 -0
- package/dist/learn/notes.d.ts +59 -0
- package/dist/learn/notes.js +146 -0
- package/dist/learn/reflect.d.ts +49 -0
- package/dist/learn/reflect.js +167 -0
- package/dist/learn/secrets.d.ts +18 -0
- package/dist/learn/secrets.js +111 -0
- package/dist/learn/skills.d.ts +84 -0
- package/dist/learn/skills.js +198 -0
- package/dist/learning-routes.d.ts +196 -0
- package/dist/learning-routes.js +609 -0
- package/dist/learning-run.d.ts +304 -0
- package/dist/learning-run.js +797 -0
- package/dist/learning-words.d.ts +73 -0
- package/dist/learning-words.js +171 -0
- package/dist/learning.d.ts +377 -0
- package/dist/learning.js +801 -0
- package/dist/llm.d.ts +40 -0
- package/dist/llm.js +37 -0
- package/dist/llms.txt +37 -0
- package/dist/mcp-servers.d.ts +115 -0
- package/dist/mcp-servers.js +445 -0
- package/dist/mcp.d.ts +51 -0
- package/dist/mcp.js +392 -0
- package/dist/model.d.ts +184 -0
- package/dist/model.js +484 -0
- package/dist/monid.d.ts +74 -0
- package/dist/monid.js +277 -0
- package/dist/openapi/agentrun-v2.openapi.json +4805 -0
- package/dist/openapi.d.ts +10 -0
- package/dist/openapi.js +1417 -0
- package/dist/owner.d.ts +55 -0
- package/dist/owner.js +222 -0
- package/dist/packs.d.ts +71 -0
- package/dist/packs.js +180 -0
- package/dist/page.d.ts +32 -0
- package/dist/page.js +133 -0
- package/dist/paid-calls.d.ts +46 -0
- package/dist/paid-calls.js +110 -0
- package/dist/pause.d.ts +68 -0
- package/dist/pause.js +97 -0
- package/dist/pdf-pages.d.ts +44 -0
- package/dist/pdf-pages.js +147 -0
- package/dist/place.d.ts +46 -0
- package/dist/place.js +105 -0
- package/dist/print.d.ts +20 -0
- package/dist/print.js +29 -0
- package/dist/propose.d.ts +38 -0
- package/dist/propose.js +82 -0
- package/dist/quiet-sqlite-warning.d.ts +1 -0
- package/dist/quiet-sqlite-warning.js +14 -0
- package/dist/request-start.d.ts +14 -0
- package/dist/request-start.js +226 -0
- package/dist/result.d.ts +3 -0
- package/dist/result.js +5 -0
- package/dist/rows.d.ts +46 -0
- package/dist/rows.js +121 -0
- package/dist/run-box.d.ts +134 -0
- package/dist/run-box.js +440 -0
- package/dist/run-manifest.d.ts +27 -0
- package/dist/run-manifest.js +60 -0
- package/dist/runnable.d.ts +80 -0
- package/dist/runnable.js +162 -0
- package/dist/runs.d.ts +840 -0
- package/dist/runs.js +2279 -0
- package/dist/secret-cut.d.ts +27 -0
- package/dist/secret-cut.js +109 -0
- package/dist/secrets.d.ts +50 -0
- package/dist/secrets.js +140 -0
- package/dist/server-lock.d.ts +44 -0
- package/dist/server-lock.js +140 -0
- package/dist/server.d.ts +626 -0
- package/dist/server.js +1756 -0
- package/dist/sessions.d.ts +4 -0
- package/dist/sessions.js +105 -0
- package/dist/skills.d.ts +31 -0
- package/dist/skills.js +68 -0
- package/dist/stats.d.ts +101 -0
- package/dist/stats.js +82 -0
- package/dist/tool-keys.d.ts +151 -0
- package/dist/tool-keys.js +273 -0
- package/dist/tool-plane.d.ts +143 -0
- package/dist/tool-plane.js +242 -0
- package/dist/tools.d.ts +147 -0
- package/dist/tools.js +253 -0
- package/dist/turn-end.d.ts +23 -0
- package/dist/turn-end.js +14 -0
- package/dist/turns.d.ts +34 -0
- package/dist/turns.js +202 -0
- package/dist/uploads.d.ts +104 -0
- package/dist/uploads.js +474 -0
- package/dist/usage.d.ts +29 -0
- package/dist/usage.js +58 -0
- package/dist/validate.d.ts +55 -0
- package/dist/validate.js +175 -0
- package/dist/web-fetch.d.ts +64 -0
- package/dist/web-fetch.js +262 -0
- package/dist/web-search.d.ts +54 -0
- package/dist/web-search.js +136 -0
- package/dist/webhooks.d.ts +182 -0
- package/dist/webhooks.js +487 -0
- package/dist/workspace-paths.d.ts +33 -0
- package/dist/workspace-paths.js +104 -0
- package/dist/workspace.d.ts +88 -0
- package/dist/workspace.js +369 -0
- package/launcher/agentrun-serve +109 -0
- package/package.json +94 -4
- package/skills/agentrun-serve/SKILL.md +128 -0
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
// GET /v2/runs/{id}/graph: a workflow run drawn from what it has written so far. The graph is the DSL's `workflowGraph`
|
|
2
|
+
// of the revision's workflow; each node's state is `nodeStatus` over the journal's frame (and, once the run ended,
|
|
3
|
+
// `readWorkflowRun`'s, with the task's end); a map's items, a route's branch taken and the interrupted decisions come
|
|
4
|
+
// from the frame; the decisions are the receipts, each joined to its graph node by its execution path (`graphNodeOf`);
|
|
5
|
+
// the calls and the nodes' times are the run process's node log (pause.ts).
|
|
6
|
+
//
|
|
7
|
+
// Where the frame and the receipts come from: while the run goes its process holds its store exclusively, so they are
|
|
8
|
+
// the process's live view (pause.ts `live.json`), and the store is never opened (an open racing the process's own would
|
|
9
|
+
// fail it). Once the run ended, the store.
|
|
10
|
+
import { llmAnswers, readLiveView, readNodeLog } from "./pause.js";
|
|
11
|
+
const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
12
|
+
const escape = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
13
|
+
const at = (state, path) => path.split(".").reduce((value, key) => (isObject(value) ? value[key] : undefined), state);
|
|
14
|
+
const labelOf = (item) => {
|
|
15
|
+
if (typeof item === "string")
|
|
16
|
+
return item.slice(0, 200);
|
|
17
|
+
if (typeof item === "number")
|
|
18
|
+
return String(item);
|
|
19
|
+
if (!isObject(item))
|
|
20
|
+
return undefined;
|
|
21
|
+
const named = item.name ?? item.label ?? item.title ?? item.id ?? item.file ?? item.path ?? item.url;
|
|
22
|
+
return typeof named === "string" || typeof named === "number" ? String(named).slice(0, 200) : undefined;
|
|
23
|
+
};
|
|
24
|
+
export async function runGraph(given) {
|
|
25
|
+
const [{ graphNodeOf, nodeStatus, workflowGraph }, { readWorkflowRun }, { durableDecisions, readJournal }] = await Promise.all([
|
|
26
|
+
import("@parcha/agentrun-dsl/graph"),
|
|
27
|
+
import("@parcha/pi-durable-agent/workflow"),
|
|
28
|
+
import("@parcha/agentrun-pi/durable"),
|
|
29
|
+
]);
|
|
30
|
+
const { id } = given.run;
|
|
31
|
+
const graph = workflowGraph(given.workflow);
|
|
32
|
+
let view;
|
|
33
|
+
let pin;
|
|
34
|
+
let receipts;
|
|
35
|
+
let readAt = new Date().toISOString();
|
|
36
|
+
if (given.ended && !given.liveOnly) {
|
|
37
|
+
view = await readWorkflowRun({ runId: id, storePath: given.storeFile, revision: { body: { workflow: given.workflow } } });
|
|
38
|
+
pin = (readJournal(given.storeFile, id)?.state?.pin) ?? {};
|
|
39
|
+
receipts = durableDecisions(given.storeFile);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
const live = await readLiveView(given.root);
|
|
43
|
+
pin = live?.pin ?? {};
|
|
44
|
+
receipts = live?.receipts ?? [];
|
|
45
|
+
if (live?.at)
|
|
46
|
+
readAt = live.at;
|
|
47
|
+
view = { status: nodeStatus(graph, { pin: pin, result: null }) };
|
|
48
|
+
}
|
|
49
|
+
const lines = await readNodeLog(given.root);
|
|
50
|
+
const nodeAt = (path) => (typeof path === "string" ? (graphNodeOf(graph, path)?.path ?? (graph.nodes.some((n) => n.path === path) ? path : undefined)) : undefined);
|
|
51
|
+
const kinds = new Map(graph.nodes.map((node) => [node.path, node.kind]));
|
|
52
|
+
// Each node's state, `not-run` read as pending until the run ends.
|
|
53
|
+
const nodes = {};
|
|
54
|
+
for (const node of graph.nodes) {
|
|
55
|
+
const state = view.status[node.path] ?? "not-run";
|
|
56
|
+
nodes[node.path] = { status: state === "not-run" ? (given.ended ? "not_run" : "pending") : state };
|
|
57
|
+
}
|
|
58
|
+
// A decision a later process found asked and never answered goes to review, never asked again.
|
|
59
|
+
const interrupted = new Set();
|
|
60
|
+
for (const [where, requests] of Object.entries(pin.decisions ?? {})) {
|
|
61
|
+
if (isObject(requests) && Object.values(requests).some((r) => isObject(r) && r.status === "interrupted"))
|
|
62
|
+
interrupted.add(where);
|
|
63
|
+
}
|
|
64
|
+
for (const where of interrupted) {
|
|
65
|
+
const path = nodeAt(where);
|
|
66
|
+
if (path && nodes[path])
|
|
67
|
+
nodes[path].status = "needs_review";
|
|
68
|
+
}
|
|
69
|
+
if (view.escalation?.kind === "decision_interrupted" && view.escalatedAt && nodes[view.escalatedAt.path])
|
|
70
|
+
nodes[view.escalatedAt.path].status = "needs_review";
|
|
71
|
+
// Times: a node's first start and, once it ended, its last end, over all its instances; a container's from what is in it.
|
|
72
|
+
const starts = new Map();
|
|
73
|
+
const ends = new Map();
|
|
74
|
+
for (const line of lines) {
|
|
75
|
+
if (line.t !== "node.start" && line.t !== "node.end")
|
|
76
|
+
continue;
|
|
77
|
+
const path = nodeAt(line.path);
|
|
78
|
+
if (!path)
|
|
79
|
+
continue;
|
|
80
|
+
if (line.t === "node.start" && (!starts.has(path) || line.at < starts.get(path)))
|
|
81
|
+
starts.set(path, line.at);
|
|
82
|
+
if (line.t === "node.end" && (!ends.has(path) || line.at > ends.get(path)))
|
|
83
|
+
ends.set(path, line.at);
|
|
84
|
+
}
|
|
85
|
+
for (const node of graph.nodes) {
|
|
86
|
+
const own = nodes[node.path];
|
|
87
|
+
const inside = [...starts.keys()].filter((path) => path === node.path || path.startsWith(`${node.path}/`));
|
|
88
|
+
const first = inside.map((path) => starts.get(path)).sort()[0];
|
|
89
|
+
const last = [...ends.entries()].filter(([path]) => path === node.path || path.startsWith(`${node.path}/`)).map(([, when]) => when).sort().at(-1);
|
|
90
|
+
if (first)
|
|
91
|
+
own.startedAt = first;
|
|
92
|
+
if (last && ["done", "failed", "escalated", "stopped", "needs_review"].includes(own.status))
|
|
93
|
+
own.endedAt = last;
|
|
94
|
+
}
|
|
95
|
+
// A route's branch taken: its committed decision, else the branch whose body ran (a route by value).
|
|
96
|
+
for (const node of graph.nodes.filter((n) => n.kind === "route")) {
|
|
97
|
+
const decided = Object.entries(pin.routes ?? {}).filter(([where]) => nodeAt(where) === node.path);
|
|
98
|
+
const top = decided.find(([where]) => where === node.path) ?? decided.at(-1);
|
|
99
|
+
if (top?.[1]?.branch)
|
|
100
|
+
nodes[node.path].branch = top[1].branch;
|
|
101
|
+
else {
|
|
102
|
+
const prefix = `${node.path}/branches/`;
|
|
103
|
+
const ran = graph.nodes.find((n) => n.path.startsWith(prefix) && n.path.endsWith("/body") && n.path.split("/").length === prefix.split("/").length + 1 && !["pending", "not_run"].includes(nodes[n.path].status));
|
|
104
|
+
if (ran)
|
|
105
|
+
nodes[node.path].branch = ran.path.slice(prefix.length, -"/body".length).replace(/~1/g, "/").replace(/~0/g, "~");
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
// A map's items, for a map that runs once (not inside another map or loop): one cell per item of its list.
|
|
109
|
+
const workflow = given.workflow;
|
|
110
|
+
const definition = (path) => path.split("/").slice(1).reduce((value, part) => (typeof value === "object" && value !== null ? value[part.replace(/~1/g, "/").replace(/~0/g, "~")] : undefined), workflow);
|
|
111
|
+
const keys = [...(pin.done ?? []), ...Object.keys(pin.states ?? {}), ...Object.keys(pin.inputs ?? {}), ...Object.keys(pin.steps ?? {}), ...Object.keys(pin.failures ?? {}), ...Object.keys(pin.decisions ?? {}), ...Object.keys(pin.routes ?? {}),
|
|
112
|
+
...lines.flatMap((line) => (typeof line.path === "string" ? [line.path] : [])), ...receipts.map((r) => String(r.execution_path ?? ""))];
|
|
113
|
+
const done = new Set(pin.done ?? []);
|
|
114
|
+
// The run's real input first: a map over an input list has its whole list, in order, from the start.
|
|
115
|
+
const candidates = [given.input, ...Object.values(pin.states ?? {})];
|
|
116
|
+
for (const node of graph.nodes.filter((n) => n.kind === "map" && graphNodeOf(graph, n.path)?.at.length === 0)) {
|
|
117
|
+
const map = node.path;
|
|
118
|
+
const own = nodes[map];
|
|
119
|
+
const def = definition(map);
|
|
120
|
+
const list = typeof def?.itemsPath === "string" ? candidates.map((state) => at(state, def.itemsPath)).find(Array.isArray) : undefined;
|
|
121
|
+
const seen = new Set();
|
|
122
|
+
const pattern = new RegExp(`^${escape(map)}/items/(\\d+)(?:/|$)`);
|
|
123
|
+
for (const key of keys) {
|
|
124
|
+
const index = pattern.exec(key)?.[1];
|
|
125
|
+
if (index !== undefined)
|
|
126
|
+
seen.add(Number(index));
|
|
127
|
+
}
|
|
128
|
+
const count = Math.max(list?.length ?? 0, seen.size ? Math.max(...seen) + 1 : 0);
|
|
129
|
+
const body = `${map}/body`;
|
|
130
|
+
const steps = kinds.get(body) === "chain" ? graph.nodes.filter((n) => n.path.startsWith(`${body}/steps/`) && /^\d+$/.test(n.path.slice(`${body}/steps/`.length))).map((n) => n.path.slice(body.length)) : [""];
|
|
131
|
+
const items = [];
|
|
132
|
+
const routesIn = graph.nodes.filter((n) => n.kind === "route" && n.path.startsWith(`${body}/`) || n.kind === "route" && n.path === body).map((n) => n.path);
|
|
133
|
+
for (let index = 0; index < count; index++) {
|
|
134
|
+
const exec = `${map}/items/${index}`;
|
|
135
|
+
const inside = (key) => key === exec || key.startsWith(`${exec}/`);
|
|
136
|
+
let status;
|
|
137
|
+
if (pin.failures && Object.hasOwn(pin.failures, exec))
|
|
138
|
+
status = "failed";
|
|
139
|
+
else if ([...interrupted].some(inside))
|
|
140
|
+
status = "needs_review";
|
|
141
|
+
else if (own.status === "done" || steps.every((step) => done.has(`${exec}/body${step}`)) || isObject(pin.states) && (Object.hasOwn(pin.states, exec) || Object.hasOwn(pin.states, `${exec}/body`)))
|
|
142
|
+
status = "done";
|
|
143
|
+
else if (Object.values(pin.steps ?? {}).some((step, i) => isObject(step) && step.status === "failed" && inside(Object.keys(pin.steps)[i])))
|
|
144
|
+
status = "failed";
|
|
145
|
+
else if (seen.has(index))
|
|
146
|
+
status = given.ended ? (own.status === "failed" ? "failed" : own.status === "escalated" ? "escalated" : "stopped") : "working";
|
|
147
|
+
else
|
|
148
|
+
status = given.ended ? "not_run" : "pending";
|
|
149
|
+
const label = labelOf(list?.[index]);
|
|
150
|
+
// Each route in the body that ran for this item, and its branch: the committed decision, else the branch that ran.
|
|
151
|
+
const branches = {};
|
|
152
|
+
for (const route of routesIn) {
|
|
153
|
+
const at = `${exec}/body${route.slice(body.length)}`;
|
|
154
|
+
const decided = pin.routes?.[at]?.branch;
|
|
155
|
+
const ran = decided ?? keys.map((key) => (key.startsWith(`${at}/branches/`) ? key.slice(at.length + "/branches/".length).split("/")[0] : undefined)).find((name) => name !== undefined);
|
|
156
|
+
if (ran)
|
|
157
|
+
branches[route] = ran.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
158
|
+
}
|
|
159
|
+
items.push({ index, status, executionPath: exec, ...(label !== undefined ? { label } : {}), ...(Object.keys(branches).length ? { branches } : {}) });
|
|
160
|
+
}
|
|
161
|
+
own.items = items;
|
|
162
|
+
}
|
|
163
|
+
const runFile = (ref) => `/v2/runs/${encodeURIComponent(id)}/files/${ref.split("/").map(encodeURIComponent).join("/")}`;
|
|
164
|
+
const decisions = receipts.map((r) => {
|
|
165
|
+
const images = Array.isArray(r.images) ? r.images : [];
|
|
166
|
+
return {
|
|
167
|
+
id: r.decision_id ?? r.id ?? null, node: nodeAt(r.execution_path) ?? null, executionPath: r.execution_path ?? null, item: r.item ?? null, kind: r.kind ?? null,
|
|
168
|
+
provider: r.provider ?? null, model: r.model ?? null, status: r.status ?? null,
|
|
169
|
+
questions: r.questions ?? null, answers: r.answers ?? null, evidence: r.evidence ?? [], rule: r.rule ?? null, action: r.action ?? null,
|
|
170
|
+
cost_usd: typeof r.cost_usd === "number" ? r.cost_usd : null, cost_basis: r.cost_basis ?? null, latency_ms: r.latency_ms ?? null,
|
|
171
|
+
state: r.state ?? null, state_truncated: r.state_truncated === true, error: typeof r.error === "string" ? r.error : null,
|
|
172
|
+
images: images.map((image) => ({ token: image.token ?? null, ref: image.ref ?? null, url: typeof image.ref === "string" ? runFile(image.ref) : null })),
|
|
173
|
+
};
|
|
174
|
+
});
|
|
175
|
+
// The calls, each start paired with its end in order.
|
|
176
|
+
const open = new Map();
|
|
177
|
+
const effects = [];
|
|
178
|
+
const placeOf = new Map();
|
|
179
|
+
for (const line of lines) {
|
|
180
|
+
if (line.t === "effect.start") {
|
|
181
|
+
const key = `${line.path}\n${line.tool}\n${line.label}`;
|
|
182
|
+
(open.get(key) ?? open.set(key, []).get(key)).push(line);
|
|
183
|
+
placeOf.set(line, effects.length);
|
|
184
|
+
effects.push({ node: nodeAt(line.path) ?? null, executionPath: line.path, item: line.item, tool: line.tool, status: given.ended ? "stopped" : "working", input: line.input, output: null, error: null, startedAt: line.at, endedAt: null });
|
|
185
|
+
}
|
|
186
|
+
else if (line.t === "effect.end") {
|
|
187
|
+
const start = open.get(`${line.path}\n${line.tool}\n${line.label}`)?.shift();
|
|
188
|
+
if (!start)
|
|
189
|
+
continue;
|
|
190
|
+
const effect = effects[placeOf.get(start)];
|
|
191
|
+
Object.assign(effect, { status: line.status, output: line.output ?? null, error: line.error ?? null, endedAt: line.at });
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
// The run's spend: its decisions', its llm calls' and its model nodes'; one unknown makes it unknown. An llm call's cost
|
|
195
|
+
// is a REQUEST_COST entry, in `modelCost` once the run's rows hold it: the first `llmRead` answers of the node log (an
|
|
196
|
+
// answer is logged after its cost is committed). Only the later ones are counted from the node log.
|
|
197
|
+
const calls = llmAnswers(lines).slice(given.llmRead ?? 0).map((line) => (isObject(line.output) && typeof line.output.cost_usd === "number" ? line.output.cost_usd : null));
|
|
198
|
+
const costs = [...decisions.map((d) => d.cost_usd), ...calls, given.modelCost];
|
|
199
|
+
const cost = costs.some((c) => c === null) ? null : Math.round(costs.reduce((a, b) => a + b, 0) * 1e8) / 1e8;
|
|
200
|
+
const startedMs = Date.parse(given.run.startedAt);
|
|
201
|
+
const endMs = given.run.endedAt ? Date.parse(given.run.endedAt) : Date.now();
|
|
202
|
+
return {
|
|
203
|
+
read_at: readAt,
|
|
204
|
+
run: given.run,
|
|
205
|
+
workflow: given.workflow,
|
|
206
|
+
graph,
|
|
207
|
+
nodes,
|
|
208
|
+
decisions,
|
|
209
|
+
effects,
|
|
210
|
+
totals: { cost_usd: cost, decisions: decisions.length, effects: effects.length, elapsed_ms: Number.isFinite(startedMs) ? Math.max(0, endMs - startedMs) : null },
|
|
211
|
+
};
|
|
212
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Context } from "@earendil-works/chord";
|
|
2
|
+
import { type ToolRegistration } from "@earendil-works/pi-durable";
|
|
3
|
+
import { type AgentAdapter, type SessionSpec } from "@parcha/agentrun-kernel";
|
|
4
|
+
import type { DoorHook, DurableRun } from "@parcha/pi-durable-disk";
|
|
5
|
+
import { type ConfineChild } from "./adapters.js";
|
|
6
|
+
import { type CapGuard } from "./cap.js";
|
|
7
|
+
/** The root's marker of a paid request already written as a pi.assistant entry. */
|
|
8
|
+
export declare const BOOKED = "adapter.request";
|
|
9
|
+
/** The cost of a request whose answer was written at unknown cost, and its tokens, written once it came in: the timeline
|
|
10
|
+
* adds it to the run's cost without counting a request, and a later open reads it as that request's cost being in. */
|
|
11
|
+
export declare const PRICED_LATE = "agentrun.request_cost_late";
|
|
12
|
+
/** How long a turn's end waits for its requests' costs, booked once the proxy has answered the harness. */
|
|
13
|
+
export declare const BOOKING_WAIT_MS = 2000;
|
|
14
|
+
/** The root's record of a message the door accepted, and of its end: `sent` to the session, or dropped by a stop. */
|
|
15
|
+
export { MESSAGE, MESSAGE_END } from "./turn-end.js";
|
|
16
|
+
/** A turn's end on the root (turn-end.ts): the message it took, the session's own outcome (`completed`, `interrupted`,
|
|
17
|
+
* `failed`) and the turn's answer, in the commit of the turn's last entries (its answer, its costs, any error). The only
|
|
18
|
+
* record that a turn which took the person's message is over: a request without content is written alike whether it
|
|
19
|
+
* ended the turn or not. */
|
|
20
|
+
export { TURN_END } from "./turn-end.js";
|
|
21
|
+
/** The run's stop record as serve keeps it (serve.json, runs.ts stopTurn, saved before the stop's abort): the person's
|
|
22
|
+
* newest message when they stopped the turn, by its row id (`<conversation>:<entry>`), or, from an older server, how many
|
|
23
|
+
* messages they had sent then. */
|
|
24
|
+
export type StopRecord = {
|
|
25
|
+
stopped_at?: string;
|
|
26
|
+
stopped_after?: number;
|
|
27
|
+
};
|
|
28
|
+
export interface AdapterRun {
|
|
29
|
+
readonly door: DoorHook;
|
|
30
|
+
onOpen(run: DurableRun): Promise<void>;
|
|
31
|
+
}
|
|
32
|
+
/** The door and the open of a run whose session is `spec` on `adapter`, with the host tools `tools` names (built at the
|
|
33
|
+
* open, over the run's environment; its coding tools from `coding`, the run's coding source, host-tools.ts).
|
|
34
|
+
* `budgetUsd`: the run's spend cap. `cancelled`: whether the run was cancelled (request-start.ts `cancelledIn`): once it
|
|
35
|
+
* says so, no model request leaves, as on pi. `cwd`: the run's workspace, the directory its file tools confine to, where
|
|
36
|
+
* the harness works too (the adapter's io.cwd), so a path the model builds from its working directory is one the tools
|
|
37
|
+
* take (in a box, coding-tools.ts names it at the box's work dir). */
|
|
38
|
+
export declare function adapterRun(make: (confine?: ConfineChild) => Promise<AgentAdapter>, harness: string, spec: Omit<SessionSpec, "tools">, context: Context, budgetUsd?: number, tools?: readonly string[], dir?: string, cap?: CapGuard, cancelled?: () => boolean, cwd?: string, coding?: readonly ToolRegistration[], stopRecord?: StopRecord): AdapterRun;
|