@parcha/agentrun-serve 0.1.0-beta.33 → 0.1.0-beta.34
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 +233 -0
- package/README.md +266 -201
- package/dist/adapters.d.ts +0 -4
- package/dist/adapters.js +11 -15
- package/dist/agent-rows.d.ts +98 -0
- package/dist/agent-rows.js +1 -0
- package/dist/agents-store.d.ts +6 -2
- package/dist/agents-store.js +60 -25
- package/dist/agents.d.ts +9 -125
- package/dist/agents.js +15 -305
- package/dist/answer-json.d.ts +23 -0
- package/dist/answer-json.js +58 -0
- package/dist/api-only.d.ts +1 -1
- package/dist/api-only.js +2 -2
- package/dist/bash-read-only.d.ts +22 -0
- package/dist/bash-read-only.js +701 -0
- package/dist/box-settings.d.ts +3 -23
- package/dist/box-settings.js +7 -51
- package/dist/boxes.d.ts +17 -0
- package/dist/boxes.js +27 -20
- package/dist/browser-commands.d.ts +5 -2
- package/dist/browser-commands.js +4 -4
- package/dist/browser-computer.d.ts +5 -0
- package/dist/browser-computer.js +21 -0
- package/dist/browser-cost.d.ts +9 -6
- package/dist/browser-cost.js +92 -50
- package/dist/browser-live.d.ts +7 -20
- package/dist/browser-live.js +15 -93
- package/dist/browser-person.d.ts +18 -51
- package/dist/browser-person.js +94 -277
- package/dist/cap.d.ts +8 -5
- package/dist/cap.js +12 -5
- package/dist/cli.js +39 -13
- package/dist/closed-pipes.d.ts +2 -0
- package/dist/closed-pipes.js +13 -0
- package/dist/computer-commands.d.ts +2 -0
- package/dist/computer-commands.js +2 -0
- package/dist/computer-keys.js +5 -2
- package/dist/computer-setting.d.ts +20 -4
- package/dist/computer-setting.js +25 -5
- package/dist/computers.d.ts +30 -2
- package/dist/computers.js +70 -11
- package/dist/confine.d.ts +120 -0
- package/dist/confine.js +436 -0
- package/dist/console/assets/index-RPHGlXmM.js +540 -0
- package/dist/console/assets/index-opTN5Naq.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/decision-rows.d.ts +1 -1
- package/dist/decision-rows.js +1 -1
- package/dist/docker-daemon.d.ts +31 -0
- package/dist/docker-daemon.js +56 -0
- package/dist/effort-guidance.js +4 -3
- package/dist/environment.d.ts +0 -3
- package/dist/environment.js +3 -5
- package/dist/errors.d.ts +0 -2
- package/dist/errors.js +6 -9
- package/dist/filed-answer.d.ts +32 -0
- package/dist/filed-answer.js +160 -0
- package/dist/files.d.ts +1 -3
- package/dist/files.js +2 -4
- package/dist/github-connection.d.ts +1 -1
- package/dist/graph-view.d.ts +3 -5
- package/dist/graph-view.js +4 -14
- package/dist/handed-values.d.ts +9 -0
- package/dist/handed-values.js +26 -0
- package/dist/harness-install.d.ts +1 -7
- package/dist/harness-install.js +1 -18
- package/dist/harness-opencode/adapter.d.ts +7 -0
- package/dist/harness-opencode/adapter.js +23 -6
- package/dist/harness-opencode/index.d.ts +1 -1
- package/dist/harness-opencode/index.js +1 -1
- package/dist/harness-opencode/verify.d.ts +17 -0
- package/dist/harness-opencode/verify.js +30 -10
- package/dist/harness-table.js +6 -1
- package/dist/heard.js +1 -1
- package/dist/held-fd.d.ts +5 -0
- package/dist/held-fd.js +14 -0
- package/dist/host-calls.d.ts +20 -0
- package/dist/host-calls.js +12 -0
- package/dist/host-tools.d.ts +4 -21
- package/dist/host-tools.js +4 -61
- package/dist/host.d.ts +2 -4
- package/dist/host.js +2 -7
- package/dist/import-summary.d.ts +1 -5
- package/dist/import-summary.js +0 -21
- package/dist/import.d.ts +6 -6
- package/dist/import.js +14 -15
- package/dist/key-refusal.d.ts +5 -1
- package/dist/key-refusal.js +19 -4
- package/dist/learn/check.d.ts +6 -2
- package/dist/learn/check.js +83 -29
- package/dist/learn/folder.d.ts +5 -1
- package/dist/learn/folder.js +10 -3
- package/dist/learn/grade.d.ts +14 -0
- package/dist/learn/grade.js +68 -12
- package/dist/learn/index.d.ts +4 -4
- package/dist/learn/index.js +4 -4
- package/dist/learn/reflect.d.ts +31 -2
- package/dist/learn/reflect.js +79 -4
- package/dist/learn/relevance.d.ts +24 -0
- package/dist/learn/relevance.js +91 -0
- package/dist/learn/secrets.d.ts +7 -1
- package/dist/learn/secrets.js +86 -19
- package/dist/learn/skills.d.ts +112 -14
- package/dist/learn/skills.js +556 -52
- package/dist/learned-workflow.d.ts +32 -1
- package/dist/learned-workflow.js +100 -9
- package/dist/learning-routes.d.ts +8 -4
- package/dist/learning-routes.js +23 -9
- package/dist/learning-run.d.ts +9 -26
- package/dist/learning-run.js +22 -32
- package/dist/learning-words.d.ts +12 -5
- package/dist/learning-words.js +18 -9
- package/dist/learning.d.ts +93 -77
- package/dist/learning.js +176 -304
- package/dist/live/stream.js +1 -1
- package/dist/live/translate.js +12 -2
- package/dist/local-models.d.ts +11 -5
- package/dist/local-models.js +13 -8
- package/dist/mcp-gateway.d.ts +11 -49
- package/dist/mcp-gateway.js +44 -135
- package/dist/mcp-oauth.d.ts +10 -14
- package/dist/mcp-oauth.js +14 -32
- package/dist/mcp-probe.d.ts +0 -7
- package/dist/mcp-probe.js +4 -10
- package/dist/mcp-servers-store.d.ts +6 -6
- package/dist/mcp-servers-store.js +12 -14
- package/dist/mcp-store.js +3 -4
- package/dist/mcp.js +4 -3
- package/dist/model.d.ts +6 -7
- package/dist/model.js +43 -27
- package/dist/monid.d.ts +0 -2
- package/dist/monid.js +3 -6
- package/dist/openapi.d.ts +8 -1
- package/dist/openapi.js +121 -47
- package/dist/page.d.ts +1 -3
- package/dist/page.js +6 -18
- package/dist/paid-calls.d.ts +21 -27
- package/dist/paid-calls.js +25 -60
- package/dist/propose.js +83 -39
- package/dist/push-handler.d.ts +1 -1
- package/dist/reflect-range.d.ts +25 -0
- package/dist/reflect-range.js +30 -0
- package/dist/refusal-words.d.ts +5 -1
- package/dist/refusal-words.js +5 -1
- package/dist/rows.d.ts +1 -1
- package/dist/run-cut.d.ts +0 -6
- package/dist/run-cut.js +0 -6
- package/dist/run-db.d.ts +2 -11
- package/dist/run-db.js +2 -37
- package/dist/run-launch.d.ts +19 -2
- package/dist/run-launch.js +13 -5
- package/dist/run-learning-served.d.ts +10 -4
- package/dist/run-learning-served.js +23 -13
- package/dist/run-reads-over-store.d.ts +1 -1
- package/dist/run-reads-over-store.js +15 -6
- package/dist/run-secrets.d.ts +1 -1
- package/dist/run-timeline-served.d.ts +5 -1
- package/dist/run-timeline-served.js +15 -4
- package/dist/run-view.d.ts +7 -8
- package/dist/run-view.js +26 -7
- package/dist/runnable.d.ts +18 -10
- package/dist/runnable.js +21 -10
- package/dist/runner/adapter-loop.d.ts +6 -1
- package/dist/runner/adapter-loop.js +423 -53
- package/dist/runner/adapter-run-spec.d.ts +21 -8
- package/dist/runner/adapter-run-spec.js +90 -32
- package/dist/runner/adapters/index.js +11 -1
- package/dist/runner/adapters/pi.d.ts +12 -2
- package/dist/runner/adapters/pi.js +16 -5
- package/dist/runner/beside.d.ts +30 -3
- package/dist/runner/beside.js +36 -5
- package/dist/runner/claim-secrets.d.ts +10 -1
- package/dist/runner/claim-secrets.js +48 -14
- package/dist/runner/cli-run-spec.d.ts +2 -0
- package/dist/runner/cli-run-spec.js +45 -16
- package/dist/runner/commands.js +1 -1
- package/dist/runner/computer-journal.d.ts +15 -2
- package/dist/runner/computer-journal.js +41 -5
- package/dist/runner/conformance/harness.js +118 -8
- package/dist/runner/conformance/subject.d.ts +4 -1
- package/dist/runner/dispatch.d.ts +8 -1
- package/dist/runner/dispatch.js +81 -7
- package/dist/runner/end-of-run.d.ts +8 -2
- package/dist/runner/end-of-run.js +10 -4
- package/dist/runner/github-app.js +1 -1
- package/dist/runner/harness-loops.d.ts +9 -1
- package/dist/runner/harness-loops.js +15 -2
- package/dist/runner/journal-kinds.d.ts +24 -6
- package/dist/runner/journal-kinds.js +20 -5
- package/dist/runner/journal-reader.d.ts +1 -1
- package/dist/runner/journal-reader.js +2 -2
- package/dist/runner/learning-ask.d.ts +4 -0
- package/dist/runner/learning-ask.js +15 -1
- package/dist/runner/learning-end.d.ts +18 -3
- package/dist/runner/learning-end.js +113 -11
- package/dist/runner/learning-loop.d.ts +5 -0
- package/dist/runner/learning-loop.js +26 -6
- package/dist/runner/main.d.ts +56 -9
- package/dist/runner/main.js +127 -18
- package/dist/runner/mcp-claim.js +1 -2
- package/dist/runner/mcp-run.d.ts +2 -0
- package/dist/runner/mcp-run.js +15 -5
- package/dist/runner/memory-claim.d.ts +9 -0
- package/dist/runner/memory-claim.js +25 -0
- package/dist/runner/metrics.d.ts +33 -1
- package/dist/runner/metrics.js +85 -1
- package/dist/runner/model-route.d.ts +13 -0
- package/dist/runner/model-route.js +133 -9
- package/dist/runner/reflect-hook.d.ts +12 -1
- package/dist/runner/reflect-hook.js +33 -3
- package/dist/runner/runner.d.ts +20 -0
- package/dist/runner/runner.js +56 -10
- package/dist/runner/store-port.d.ts +1 -1
- package/dist/runner/store-secrets.d.ts +3 -3
- package/dist/runner/store-secrets.js +8 -12
- package/dist/runner/text-tools.d.ts +44 -0
- package/dist/runner/text-tools.js +237 -0
- package/dist/runner/workflow-loop.d.ts +6 -0
- package/dist/runner/workflow-loop.js +6 -4
- package/dist/runner/workflow-spec.d.ts +18 -0
- package/dist/runner/workflow-spec.js +63 -17
- package/dist/runs-over-store.d.ts +7 -2
- package/dist/runs-over-store.js +60 -14
- package/dist/seal-key.js +5 -43
- package/dist/sealed-settings-store.d.ts +19 -4
- package/dist/sealed-settings-store.js +9 -9
- package/dist/sealing.d.ts +4 -0
- package/dist/sealing.js +20 -0
- package/dist/secret-cut.d.ts +1 -1
- package/dist/secret-cut.js +1 -1
- package/dist/secret-name.d.ts +9 -0
- package/dist/secret-name.js +15 -0
- package/dist/secret-writes.d.ts +0 -1
- package/dist/secret-writes.js +0 -1
- package/dist/server-fs.d.ts +4 -0
- package/dist/server-fs.js +8 -2
- package/dist/server-lock.d.ts +0 -24
- package/dist/server-lock.js +1 -80
- package/dist/server-secrets-store.d.ts +4 -4
- package/dist/server-secrets-store.js +9 -31
- package/dist/server-secrets.d.ts +4 -9
- package/dist/server-secrets.js +12 -36
- package/dist/server.d.ts +16 -38
- package/dist/server.js +145 -106
- package/dist/sign-ins-store.d.ts +34 -36
- package/dist/sign-ins-store.js +27 -38
- package/dist/sign-ins.d.ts +2 -119
- package/dist/sign-ins.js +5 -311
- package/dist/standard-webhooks.d.ts +1 -1
- package/dist/standard-webhooks.js +1 -1
- package/dist/stats.d.ts +3 -2
- package/dist/stats.js +1 -1
- package/dist/store/agent-body.d.ts +8 -2
- package/dist/store/agent-body.js +16 -4
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +2 -2
- package/dist/store/open.d.ts +6 -3
- package/dist/store/open.js +2 -2
- package/dist/store/postgres/connection.d.ts +18 -2
- package/dist/store/postgres/connection.js +156 -32
- package/dist/store/postgres/migrate.d.ts +4 -0
- package/dist/store/postgres/migrate.js +9 -2
- package/dist/store/postgres/migrations/0003_commands_one_answer.check.sql +19 -0
- package/dist/store/postgres/migrations/0003_commands_one_answer.sql +13 -0
- package/dist/store/postgres/store.d.ts +9 -2
- package/dist/store/postgres/store.js +9 -0
- package/dist/store/schema.js +1 -1
- package/dist/store/seal.js +2 -2
- package/dist/store/sqlite/connection.js +49 -5
- package/dist/store/sqlite/run-patch.d.ts +3 -0
- package/dist/store/sqlite/run-patch.js +3 -0
- package/dist/store/sqlite/store.js +41 -12
- package/dist/store/store.d.ts +35 -6
- package/dist/store/store.js +12 -2
- package/dist/store-reads/cap.d.ts +1 -1
- package/dist/store-reads/cap.js +22 -4
- package/dist/store-reads/journal.d.ts +9 -6
- package/dist/store-reads/journal.js +93 -17
- package/dist/store-reads/learning.d.ts +26 -8
- package/dist/store-reads/learning.js +12 -4
- package/dist/store-reads/workflow.d.ts +1 -1
- package/dist/store-reads/workflow.js +1 -1
- package/dist/store-view.d.ts +5 -1
- package/dist/store-view.js +53 -18
- package/dist/template-eval.d.ts +60 -4
- package/dist/template-eval.js +120 -54
- package/dist/templates.d.ts +24 -10
- package/dist/templates.js +69 -38
- package/dist/timeline/group.d.ts +33 -0
- package/dist/timeline/group.js +77 -0
- package/dist/timeline/index.d.ts +7 -0
- package/dist/timeline/index.js +7 -0
- package/dist/timeline/labels.d.ts +79 -0
- package/dist/timeline/labels.js +150 -0
- package/dist/timeline/origin.d.ts +56 -0
- package/dist/timeline/origin.js +92 -0
- package/dist/timeline/render-text.d.ts +11 -0
- package/dist/timeline/render-text.js +62 -0
- package/dist/timeline/timeline.d.ts +274 -0
- package/dist/timeline/timeline.js +1308 -0
- package/dist/timeline/util.d.ts +17 -0
- package/dist/timeline/util.js +49 -0
- package/dist/tool-gate.d.ts +41 -216
- package/dist/tool-gate.js +79 -540
- package/dist/tool-keys-store.d.ts +11 -12
- package/dist/tool-keys-store.js +24 -31
- package/dist/tool-keys.d.ts +5 -101
- package/dist/tool-keys.js +8 -267
- package/dist/tool-plane.d.ts +14 -42
- package/dist/tool-plane.js +23 -81
- package/dist/tool-settings-store.d.ts +1 -2
- package/dist/tool-settings-store.js +5 -8
- package/dist/tools.d.ts +30 -18
- package/dist/tools.js +97 -107
- package/dist/trigger-adapter.d.ts +2 -2
- package/dist/trigger-targets.d.ts +13 -1
- package/dist/trigger-targets.js +31 -1
- package/dist/triggers.d.ts +2 -2
- package/dist/triggers.js +3 -3
- package/dist/turn-end.d.ts +1 -1
- package/dist/turn-end.js +1 -1
- package/dist/turns.d.ts +0 -6
- package/dist/turns.js +0 -19
- package/dist/uploads.js +1 -1
- package/dist/usage.d.ts +0 -2
- package/dist/usage.js +0 -2
- package/dist/validate.d.ts +2 -0
- package/dist/validate.js +23 -14
- package/dist/webhooks.d.ts +102 -76
- package/dist/webhooks.js +266 -233
- package/dist/workflow-run.d.ts +114 -0
- package/dist/workflow-run.js +144 -0
- package/dist/workspace/beneath.d.ts +19 -0
- package/dist/workspace/beneath.js +106 -0
- package/dist/workspace/computer-deps.d.ts +24 -6
- package/dist/workspace/computer-deps.js +108 -20
- package/dist/workspace/computer-for-claim.d.ts +12 -11
- package/dist/workspace/computer-for-claim.js +76 -15
- package/dist/workspace/computer-hold.d.ts +6 -1
- package/dist/workspace/computer-hold.js +6 -1
- package/dist/workspace/computer-janitor.d.ts +47 -0
- package/dist/workspace/computer-janitor.js +182 -0
- package/dist/workspace/grep-worker.d.ts +5 -0
- package/dist/workspace/grep-worker.js +9 -6
- package/dist/workspace/index.d.ts +3 -2
- package/dist/workspace/index.js +3 -3
- package/dist/workspace/local.d.ts +11 -2
- package/dist/workspace/local.js +161 -43
- package/dist/workspace/resolve-computer.d.ts +50 -10
- package/dist/workspace/resolve-computer.js +46 -11
- package/dist/workspace/run-tools.d.ts +13 -31
- package/dist/workspace/run-tools.js +10 -27
- package/dist/workspace-paths.d.ts +0 -17
- package/dist/workspace-paths.js +1 -41
- package/dist/workspace.d.ts +0 -14
- package/dist/workspace.js +3 -96
- package/package.json +13 -13
- package/templates/README.md +9 -3
- package/templates/market-monitor/agent.md +2 -2
- package/templates/market-monitor/skills/monitor/SKILL.md +6 -4
- package/dist/bound-files.d.ts +0 -4
- package/dist/bound-files.js +0 -164
- package/dist/coding-tools.d.ts +0 -47
- package/dist/coding-tools.js +0 -189
- package/dist/computer-adb.d.ts +0 -12
- package/dist/computer-adb.js +0 -14
- package/dist/console/assets/index-Dn0ngwG9.js +0 -535
- package/dist/console/assets/index-DvW6Aled.css +0 -1
- package/dist/grade.d.ts +0 -63
- package/dist/grade.js +0 -150
- package/dist/mcp-servers.d.ts +0 -269
- package/dist/mcp-servers.js +0 -456
- package/dist/packs.d.ts +0 -71
- package/dist/packs.js +0 -180
- package/dist/sealed-settings.d.ts +0 -60
- package/dist/sealed-settings.js +0 -171
- package/dist/sessions.d.ts +0 -6
- package/dist/sessions.js +0 -109
- package/dist/workspace/computer-serves.d.ts +0 -12
- package/dist/workspace/computer-serves.js +0 -15
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { EntryLike } from "./timeline.js";
|
|
2
|
+
/** What fired a trigger: its definition's kind, never what its payload says. */
|
|
3
|
+
export declare const TRIGGER_SOURCES: readonly ["schedule", "webhook", "slack", "github"];
|
|
4
|
+
export type TriggerSource = (typeof TRIGGER_SOURCES)[number];
|
|
5
|
+
/** How a trigger's Timeline row names its source: "<label> <trigger>: <its first line>". */
|
|
6
|
+
export declare const TRIGGER_LABELS: Readonly<Record<TriggerSource, string>>;
|
|
7
|
+
/** Who wrote a user-role message that the person did not type. The model reads the message as it reads any; only its
|
|
8
|
+
* attribution differs, so the Timeline never shows it as "You".
|
|
9
|
+
* - `server`, for a reason. `approval_declined`: a person's message that declined a call waiting for approval, which the
|
|
10
|
+
* server's resume carries as the deny note; `said` is their words, whole, which the Timeline shows as theirs beside
|
|
11
|
+
* the server's row.
|
|
12
|
+
* - `trigger`: a trigger's firing (its first input, or its message), `trigger_id` the trigger's. `owner` is decided by
|
|
13
|
+
* the trigger's definition when it fires, never by its payload: true for a schedule (its owner wrote the words when
|
|
14
|
+
* they set it up), false for a webhook, Slack or GitHub firing, whose words come from outside. */
|
|
15
|
+
export type MessageOrigin = {
|
|
16
|
+
kind: "server";
|
|
17
|
+
reason: "cap_raised" | "approval";
|
|
18
|
+
} | {
|
|
19
|
+
kind: "server";
|
|
20
|
+
reason: "approval_declined";
|
|
21
|
+
said: string;
|
|
22
|
+
} | {
|
|
23
|
+
kind: "trigger";
|
|
24
|
+
trigger_id: string;
|
|
25
|
+
source: TriggerSource;
|
|
26
|
+
owner: boolean;
|
|
27
|
+
};
|
|
28
|
+
/** An entry kind that names the origin of the next user entry in its conversation whose text is exactly `text`: written
|
|
29
|
+
* just before the input it names (pi-durable writes a user entry with no data of its own), placed in the same queue.
|
|
30
|
+
* One with `withdrawn: true` takes back the last open marker of the same text and origin: its input was refused. */
|
|
31
|
+
export declare const MESSAGE_ORIGIN = "agentrun.message_origin";
|
|
32
|
+
/** `value` as an origin, or undefined when it is not one. */
|
|
33
|
+
export declare function originOf(value: unknown): MessageOrigin | undefined;
|
|
34
|
+
/** Whether `entry` is a user-role message the Timeline shows (a pi user entry, or a host's user entry). */
|
|
35
|
+
export declare const isUserEntry: (entry: EntryLike) => boolean;
|
|
36
|
+
/** Reads entries in order and says, for each user entry, its origin: its own `data.origin` (a host that writes the entry),
|
|
37
|
+
* else the first marker (MESSAGE_ORIGIN) still open in its conversation whose text is exactly the entry's. Each marker
|
|
38
|
+
* names one entry. Undefined for a person's own message. */
|
|
39
|
+
export declare function originMatcher(): (entry: EntryLike) => MessageOrigin | undefined;
|
|
40
|
+
/** Whether a Timeline row is a message its run took: a person's (`user_message`), the server's (`origin: "server"`), or a
|
|
41
|
+
* trigger's (`origin: "trigger"`); never the server's row beside the person's words (BESIDE_SUFFIX) or a note it told the
|
|
42
|
+
* model (NOTE_SUFFIX). A host that counts a run's messages (their arrival, where a stop stands) counts these, never the
|
|
43
|
+
* kind alone. */
|
|
44
|
+
export declare const isMessageRow: (row: {
|
|
45
|
+
id?: string;
|
|
46
|
+
kind: string;
|
|
47
|
+
origin?: string;
|
|
48
|
+
}) => boolean;
|
|
49
|
+
/** The id suffix of a server's row shown beside a person's message that its turn took (a declined approval's resume):
|
|
50
|
+
* the server's, as its origin says, and never a second message of that turn. */
|
|
51
|
+
export declare const BESIDE_SUFFIX = ":server";
|
|
52
|
+
/** The id suffix of the server's row for a note it told the run's model (the spend cap's wrap-up, CAP_WRAPUP): the
|
|
53
|
+
* server's, as its origin says, and never a message any turn took. */
|
|
54
|
+
export declare const NOTE_SUFFIX = ":note";
|
|
55
|
+
/** The user entries of `entries` that the server wrote, with their origin (originMatcher, read in order). */
|
|
56
|
+
export declare function messageOrigins(entries: readonly EntryLike[]): Map<EntryLike, MessageOrigin>;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { obj, str } from "./util.js";
|
|
2
|
+
/** What fired a trigger: its definition's kind, never what its payload says. */
|
|
3
|
+
export const TRIGGER_SOURCES = ["schedule", "webhook", "slack", "github"];
|
|
4
|
+
/** How a trigger's Timeline row names its source: "<label> <trigger>: <its first line>". */
|
|
5
|
+
export const TRIGGER_LABELS = { schedule: "Schedule", webhook: "Webhook", slack: "Slack", github: "GitHub" };
|
|
6
|
+
const REASONS = new Set(["cap_raised", "approval"]);
|
|
7
|
+
const SOURCES = new Set(TRIGGER_SOURCES);
|
|
8
|
+
/** An entry kind that names the origin of the next user entry in its conversation whose text is exactly `text`: written
|
|
9
|
+
* just before the input it names (pi-durable writes a user entry with no data of its own), placed in the same queue.
|
|
10
|
+
* One with `withdrawn: true` takes back the last open marker of the same text and origin: its input was refused. */
|
|
11
|
+
export const MESSAGE_ORIGIN = "agentrun.message_origin";
|
|
12
|
+
/** `value` as an origin, or undefined when it is not one. */
|
|
13
|
+
export function originOf(value) {
|
|
14
|
+
const at = obj(value);
|
|
15
|
+
if (at?.kind === "trigger") {
|
|
16
|
+
const { trigger_id, source, owner } = at;
|
|
17
|
+
return typeof trigger_id === "string" && trigger_id !== "" && typeof source === "string" && SOURCES.has(source) && typeof owner === "boolean" ? { kind: "trigger", trigger_id, source: source, owner } : undefined;
|
|
18
|
+
}
|
|
19
|
+
if (!at || at.kind !== "server" || typeof at.reason !== "string")
|
|
20
|
+
return undefined;
|
|
21
|
+
if (at.reason === "approval_declined")
|
|
22
|
+
return typeof at.said === "string" && at.said.trim() ? { kind: "server", reason: "approval_declined", said: at.said } : undefined;
|
|
23
|
+
return REASONS.has(at.reason) ? { kind: "server", reason: at.reason } : undefined;
|
|
24
|
+
}
|
|
25
|
+
const textOf = (message) => {
|
|
26
|
+
const content = message?.content;
|
|
27
|
+
const blocks = Array.isArray(content) ? content.map((block) => obj(block)).filter((block) => block !== undefined) : typeof content === "string" ? [{ type: "text", text: content }] : [];
|
|
28
|
+
return blocks.filter((block) => block.type === "text").map((block) => str(block.text) ?? "").join("\n").trim();
|
|
29
|
+
};
|
|
30
|
+
/** Whether `entry` is a user-role message the Timeline shows (a pi user entry, or a host's user entry). */
|
|
31
|
+
export const isUserEntry = (entry) => obj(entry.model?.[0])?.role === "user" && (entry.kind === "pi.user" || !entry.kind.startsWith("pi."));
|
|
32
|
+
/** Reads entries in order and says, for each user entry, its origin: its own `data.origin` (a host that writes the entry),
|
|
33
|
+
* else the first marker (MESSAGE_ORIGIN) still open in its conversation whose text is exactly the entry's. Each marker
|
|
34
|
+
* names one entry. Undefined for a person's own message. */
|
|
35
|
+
export function originMatcher() {
|
|
36
|
+
const open = new Map();
|
|
37
|
+
return (entry) => {
|
|
38
|
+
const conv = entry.conversationId ?? 0;
|
|
39
|
+
if (entry.kind === MESSAGE_ORIGIN) {
|
|
40
|
+
const data = obj(entry.data);
|
|
41
|
+
const origin = originOf(data?.origin);
|
|
42
|
+
const text = str(data?.text);
|
|
43
|
+
if (!origin || text === undefined)
|
|
44
|
+
return undefined;
|
|
45
|
+
const markers = open.get(conv) ?? [];
|
|
46
|
+
if (data?.withdrawn === true) {
|
|
47
|
+
const at = markers.findLastIndex((marker) => marker.text === text.trim() && JSON.stringify(marker.origin) === JSON.stringify(origin));
|
|
48
|
+
if (at >= 0)
|
|
49
|
+
markers.splice(at, 1);
|
|
50
|
+
}
|
|
51
|
+
else
|
|
52
|
+
open.set(conv, [...markers, { text: text.trim(), origin }]);
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
if (!isUserEntry(entry))
|
|
56
|
+
return undefined;
|
|
57
|
+
const own = originOf(obj(entry.data)?.origin);
|
|
58
|
+
if (own)
|
|
59
|
+
return own;
|
|
60
|
+
const markers = open.get(conv);
|
|
61
|
+
if (!markers?.length)
|
|
62
|
+
return undefined;
|
|
63
|
+
const text = textOf(obj(entry.model?.[0]));
|
|
64
|
+
const at = markers.findIndex((marker) => marker.text === text);
|
|
65
|
+
if (at < 0)
|
|
66
|
+
return undefined;
|
|
67
|
+
const [{ origin }] = markers.splice(at, 1);
|
|
68
|
+
return origin;
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/** Whether a Timeline row is a message its run took: a person's (`user_message`), the server's (`origin: "server"`), or a
|
|
72
|
+
* trigger's (`origin: "trigger"`); never the server's row beside the person's words (BESIDE_SUFFIX) or a note it told the
|
|
73
|
+
* model (NOTE_SUFFIX). A host that counts a run's messages (their arrival, where a stop stands) counts these, never the
|
|
74
|
+
* kind alone. */
|
|
75
|
+
export const isMessageRow = (row) => row.kind === "user_message" || ((row.origin === "server" || row.origin === "trigger") && !row.id?.endsWith(BESIDE_SUFFIX) && !row.id?.endsWith(NOTE_SUFFIX));
|
|
76
|
+
/** The id suffix of a server's row shown beside a person's message that its turn took (a declined approval's resume):
|
|
77
|
+
* the server's, as its origin says, and never a second message of that turn. */
|
|
78
|
+
export const BESIDE_SUFFIX = ":server";
|
|
79
|
+
/** The id suffix of the server's row for a note it told the run's model (the spend cap's wrap-up, CAP_WRAPUP): the
|
|
80
|
+
* server's, as its origin says, and never a message any turn took. */
|
|
81
|
+
export const NOTE_SUFFIX = ":note";
|
|
82
|
+
/** The user entries of `entries` that the server wrote, with their origin (originMatcher, read in order). */
|
|
83
|
+
export function messageOrigins(entries) {
|
|
84
|
+
const match = originMatcher();
|
|
85
|
+
const found = new Map();
|
|
86
|
+
for (const entry of entries) {
|
|
87
|
+
const origin = match(entry);
|
|
88
|
+
if (origin)
|
|
89
|
+
found.set(entry, origin);
|
|
90
|
+
}
|
|
91
|
+
return found;
|
|
92
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type Group } from "./group.js";
|
|
2
|
+
import type { TimelineEvent } from "./timeline.js";
|
|
3
|
+
/** How the text names a file path a call gave: the host's own name for it (`TimelineOptions.path`). */
|
|
4
|
+
type PathName = {
|
|
5
|
+
path?: (path: string) => string;
|
|
6
|
+
};
|
|
7
|
+
/** Plain text, one line per row or group: `HH:MM:SS text`. `fold: false` shows every call on its own line. */
|
|
8
|
+
export declare function renderText(input: readonly (TimelineEvent | Group)[], options?: {
|
|
9
|
+
fold?: boolean;
|
|
10
|
+
} & PathName): string;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { foldCalls, groupTimeline } from "./group.js";
|
|
2
|
+
import { foldLabel } from "./labels.js";
|
|
3
|
+
const clock = (row) => row.timestamp.slice(11, 19);
|
|
4
|
+
const statusOf = (call) => !call.result ? "running" : call.result.tool_status === "success" ? "ok" : call.result.tool_result_size_bytes === null ? "interrupted" : "failed";
|
|
5
|
+
function rowText(row) {
|
|
6
|
+
const summary = row.summary ?? row.kind;
|
|
7
|
+
return row.kind === "text_block" ? `Agent: ${summary}` : row.kind === "final_answer" ? `Answer: ${summary}` : summary;
|
|
8
|
+
}
|
|
9
|
+
function foldEntry(fold, options) {
|
|
10
|
+
const [only] = fold.calls;
|
|
11
|
+
if (fold.calls.length === 1 && only)
|
|
12
|
+
return { text: only.use.summary ?? fold.tool, status: statusOf(only), reasons: statusOf(only) === "failed" ? [only] : [] };
|
|
13
|
+
const counts = new Map();
|
|
14
|
+
for (const call of fold.calls)
|
|
15
|
+
counts.set(statusOf(call), (counts.get(statusOf(call)) ?? 0) + 1);
|
|
16
|
+
const status = [...counts].map(([name, count]) => `${count} ${name}`).join(", ");
|
|
17
|
+
const text = foldLabel(fold.tool, fold.calls.map((call) => ({ input: call.use.tool_input_preview, output: call.result?.tool_result_preview ?? null })), options);
|
|
18
|
+
return { text, status, reasons: fold.calls.filter((call) => statusOf(call) === "failed") };
|
|
19
|
+
}
|
|
20
|
+
/** What the calls' rows say their browser charges came to (TimelineEvent.usage on a call's row): " · $0.0018", or
|
|
21
|
+
* " · cost unknown" when one is; "" when none carries one. */
|
|
22
|
+
function chargeOf(calls) {
|
|
23
|
+
const usages = calls.flatMap((call) => (call.use.kind === "tool_use" && call.use.usage ? [call.use.usage] : []));
|
|
24
|
+
if (!usages.length)
|
|
25
|
+
return "";
|
|
26
|
+
if (usages.some((usage) => usage.usd === null))
|
|
27
|
+
return " · cost unknown";
|
|
28
|
+
const usd = usages.reduce((sum, usage) => sum + (usage.usd ?? 0), 0);
|
|
29
|
+
return ` · ${usd === 0 ? "$0" : `$${usd.toFixed(4)}`}`;
|
|
30
|
+
}
|
|
31
|
+
function linesOf(groups, depth, fold, options = {}) {
|
|
32
|
+
const lines = [];
|
|
33
|
+
for (const group of groups) {
|
|
34
|
+
if (group.type === "row") {
|
|
35
|
+
lines.push({ at: clock(group.row), depth, text: rowText(group.row) });
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
const folds = fold ? foldCalls(group.calls) : group.calls.map((call) => ({ tool: call.use.tool_name ?? "", calls: [call] }));
|
|
39
|
+
const at = clock(group.calls[0].use);
|
|
40
|
+
const nested = folds.length > 1;
|
|
41
|
+
if (nested)
|
|
42
|
+
lines.push({ at, depth, text: `Ran ${group.calls.length} tools` });
|
|
43
|
+
for (const entry of folds) {
|
|
44
|
+
const { text, status, reasons } = foldEntry(entry, options);
|
|
45
|
+
const inner = nested ? depth + 1 : depth;
|
|
46
|
+
lines.push({ at: nested ? undefined : at, depth: inner, text: `${(text + chargeOf(entry.calls)).padEnd(58)} ${status}` });
|
|
47
|
+
for (const call of reasons)
|
|
48
|
+
lines.push({ depth: inner + 1, text: call.result?.summary ?? statusOf(call) });
|
|
49
|
+
for (const call of entry.calls)
|
|
50
|
+
lines.push(...linesOf(call.inner, inner + 1, fold, options));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return lines;
|
|
54
|
+
}
|
|
55
|
+
const isRows = (input) => input.every((item) => "kind" in item);
|
|
56
|
+
/** Plain text, one line per row or group: `HH:MM:SS text`. `fold: false` shows every call on its own line. */
|
|
57
|
+
export function renderText(input, options = {}) {
|
|
58
|
+
const groups = isRows(input) ? groupTimeline(input) : input;
|
|
59
|
+
return linesOf(groups, 0, options.fold !== false, options)
|
|
60
|
+
.map((line) => `${(line.at ?? "").padEnd(8)} ${" ".repeat(line.depth)}${line.text}`.trimEnd())
|
|
61
|
+
.join("\n");
|
|
62
|
+
}
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import { type LabelFn } from "./labels.js";
|
|
2
|
+
import { type Obj } from "./util.js";
|
|
3
|
+
import { type TriggerSource } from "./origin.js";
|
|
4
|
+
export type TimelineKind = "thinking" | "text_block" | "tool_use" | "tool_result" | "phase" | "subagent_started" | "subagent_progress" | "subagent_completed" | "final_answer" | "error" | "user_message" | "waiting" | "usage"
|
|
5
|
+
/** A workflow decision: a judge's answers or a route's branch (serve's decision rows). */
|
|
6
|
+
| "decision"
|
|
7
|
+
/** Where a run's learning ended: proposed, merged or dropped (serve's learning row). */
|
|
8
|
+
| "learning"
|
|
9
|
+
/** A tool call that waited for a person's approval, after its result's row (serve's tool gate). */
|
|
10
|
+
| "tool_approval_requested";
|
|
11
|
+
/** Grep's public `TimelineEvent` (its 13 fields) plus the open additions, all optional. */
|
|
12
|
+
export type TimelineEvent = {
|
|
13
|
+
id: string;
|
|
14
|
+
timestamp: string;
|
|
15
|
+
created_at: string;
|
|
16
|
+
kind: TimelineKind;
|
|
17
|
+
summary: string | null;
|
|
18
|
+
agent_label: string | null;
|
|
19
|
+
tool_name: string | null;
|
|
20
|
+
tool_use_id: string | null;
|
|
21
|
+
tool_status: "success" | "failed" | null;
|
|
22
|
+
tool_input_preview: string | null;
|
|
23
|
+
tool_result_preview: string | null;
|
|
24
|
+
tool_result_size_bytes: number | null;
|
|
25
|
+
text: string | null;
|
|
26
|
+
/** Log order inside the run; a page sorts by it, never by time. */
|
|
27
|
+
seq?: number;
|
|
28
|
+
conversation_id?: number;
|
|
29
|
+
/** The assistant entry whose calls these are. */
|
|
30
|
+
round?: number;
|
|
31
|
+
/** A nested call's caller, or a subagent's spawning call. */
|
|
32
|
+
parent_tool_use_id?: string;
|
|
33
|
+
/** The browser session a hand-over is about, as a tag; never a URL. */
|
|
34
|
+
session?: string;
|
|
35
|
+
/** The file a "Saved" phase row is about. */
|
|
36
|
+
path?: string;
|
|
37
|
+
/** `server` on the row of a message the server wrote into the run, `trigger` on a trigger's (origin.ts): a `phase` row,
|
|
38
|
+
* which counts, as a person's `user_message` does, as the message its turn took (`isMessageRow`). */
|
|
39
|
+
origin?: "server" | "trigger";
|
|
40
|
+
/** On a trigger's row (`origin: "trigger"`) alone: its trigger, from the message's origin, so a client labels the row
|
|
41
|
+
* by its source without reading its summary. `name`, the trigger's name as it is now, is serve's to add (this
|
|
42
|
+
* projector writes its id): the one the summary shows, so a client drops exactly that prefix, colons and all. */
|
|
43
|
+
trigger?: {
|
|
44
|
+
id: string;
|
|
45
|
+
source: TriggerSource;
|
|
46
|
+
owner: boolean;
|
|
47
|
+
name?: string;
|
|
48
|
+
};
|
|
49
|
+
/** `true` on the server's `phase` row of a spend cap's refusal for room (serve), "Paused at the run's cap", origin
|
|
50
|
+
* server and its id ending NOTE_SUFFIX: the request was not sent and the run paused for a raise; a pause, never a
|
|
51
|
+
* failure, whether the run waits on its cap now or was raised since. */
|
|
52
|
+
paused?: true;
|
|
53
|
+
/** On the usage row, the run's cost. On a paid tool's charge row (a `phase` naming the tool), that charge alone. On a
|
|
54
|
+
* browser call's `tool_use` row, every browser charge booked under that call (BROWSER_CHARGE): its session's time
|
|
55
|
+
* since its last charge, and its release's when it was the session's last call. `requests` is 0 on all but the usage
|
|
56
|
+
* row. `so_far_usd` and `unpriced` (costsofar/1): while `usd` is null, the sum of every charge whose cost is known, and how
|
|
57
|
+
* many charges have no known cost (model requests cut, stopped, still pending or with no price, and paid tool calls
|
|
58
|
+
* charged an unknown amount or cut). Absent when `usd` is known. */
|
|
59
|
+
usage?: {
|
|
60
|
+
usd: number | null;
|
|
61
|
+
requests: number;
|
|
62
|
+
so_far_usd?: number;
|
|
63
|
+
unpriced?: number;
|
|
64
|
+
not_metered?: number;
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
/** A pi conversation entry as stored: `pi.assistant`, `pi.tool-result`, a host's own kind. */
|
|
68
|
+
export type EntryLike = {
|
|
69
|
+
kind: string;
|
|
70
|
+
id?: number;
|
|
71
|
+
conversationId?: number;
|
|
72
|
+
model?: readonly Obj[];
|
|
73
|
+
data?: unknown;
|
|
74
|
+
};
|
|
75
|
+
/** A pi `AgentEvent`, as `watchEvents` yields it and `GET /events` serves it. */
|
|
76
|
+
export type AgentEventLike = {
|
|
77
|
+
type: string;
|
|
78
|
+
[key: string]: unknown;
|
|
79
|
+
};
|
|
80
|
+
/** Grep's caps, so a row is the same on both sides. `thinking` cuts the first sentence of a thinking summary. */
|
|
81
|
+
export declare const CAPS: {
|
|
82
|
+
summary: number;
|
|
83
|
+
preview: number;
|
|
84
|
+
text: number;
|
|
85
|
+
thinking: number;
|
|
86
|
+
};
|
|
87
|
+
/** A host's marks of a model request: as it leaves (written before it does), and as its stream ends aborted. A request
|
|
88
|
+
* that answered or failed has a `pi.assistant` entry; one aborted before its first content has none; a start with no
|
|
89
|
+
* end and no entry is in flight when it is the latest, unless the run is settled, and was cut by a crash when a later
|
|
90
|
+
* one followed it or the run settled without it. A cut request's cost is unknown. */
|
|
91
|
+
export declare const REQUEST_STARTED = "agentrun.request_started";
|
|
92
|
+
/** An end with `unsent: true` withdraws its start: the request was refused after its mark, and never left. */
|
|
93
|
+
export declare const REQUEST_ENDED = "agentrun.request_ended";
|
|
94
|
+
/** What a request with no `pi.assistant` entry of its own cost (a side request, marked with a `request` label: pi's
|
|
95
|
+
* compaction summary, `"compaction"`, or a tool's own model request, such as a web search's): `usd`, or null when
|
|
96
|
+
* unknown. It closes that request, as an entry closes a generation's. `failed`: the request failed, and its counts are
|
|
97
|
+
* taken as they are, as a failed answer's are. */
|
|
98
|
+
export declare const REQUEST_COST = "agentrun.request_cost";
|
|
99
|
+
/** A request the host refused before it left (the run was cancelled): pi answers it with an error entry, which is not a
|
|
100
|
+
* request and not a failure to show, so the timeline skips the error entry that answers each refusal. */
|
|
101
|
+
export declare const REQUEST_REFUSED = "agentrun.request_refused";
|
|
102
|
+
/** The key a host sets in a tool result's `details` (which only a reader of the result sees, never the model) when the
|
|
103
|
+
* call was refused before it ran (a gate's deny, a person's): `{ [CALL_REFUSED]: true }`. Its rows read as refused, the
|
|
104
|
+
* call in plain words ("Refused: write deny.md"), never as a call that ran and failed ("Wrote deny.md failed"). */
|
|
105
|
+
export declare const CALL_REFUSED = "agentrun.refused";
|
|
106
|
+
/** Written right after an answer whose cost was not in when it was written (a harness's proxy books a response after
|
|
107
|
+
* answering it): that answer's cost is still to come, as a REQUEST_COST_LATE. Until it comes the cost is unknown. */
|
|
108
|
+
export declare const REQUEST_COST_PENDING = "agentrun.request_cost_pending";
|
|
109
|
+
/** The cost (`usd`, or null when unknown) of an answer written earlier with its cost pending: it closes one pending cost
|
|
110
|
+
* and adds to the run's cost. It is not a request of its own: the answer already counted that. */
|
|
111
|
+
export declare const REQUEST_COST_LATE = "agentrun.request_cost_late";
|
|
112
|
+
/** What a paid tool's call charged, written apart from any request as the tool reports it: `tool` and `charged_by` name
|
|
113
|
+
* it, `usd` is the charge, or null when the call may have charged and did not say how much. It adds to the run's cost,
|
|
114
|
+
* which is then unknown on a null, and shows as a row of its own; it is no model request. The usage row counts paid
|
|
115
|
+
* tool calls by `call`: a call that books several charges (a browser call, and its session's release under it) is one
|
|
116
|
+
* paid tool call, and one charge not priced when any of them is unknown. A browser charge (BROWSER_CHARGE) shows on its
|
|
117
|
+
* call's row instead. */
|
|
118
|
+
export declare const TOOL_COST = "agentrun.tool_cost";
|
|
119
|
+
/** The `tool` of a browser session's charge (serve's browser-cost.ts: `call`, the call it ran under, or for a release the
|
|
120
|
+
* session's last call; `tag`, the session; `conversation`, the browser's conversation). It makes no row: it folds into
|
|
121
|
+
* that call's `tool_use` row, as its `usage`, else into the last browser call charged for its session, else into its
|
|
122
|
+
* conversation's last browser call; only a charge with none of these (its calls compacted away) keeps a row of its own.
|
|
123
|
+
* A charge booked after the row was shown (a release after the answer) changes that row, by its id. */
|
|
124
|
+
export declare const BROWSER_CHARGE = "browser";
|
|
125
|
+
/** The tool whose charge a row carries, for a host that sums a run's paid tools from its rows: a charge row's tool (a
|
|
126
|
+
* `phase` with `usage`), `browser` for a browser step's call row (`tool_name` in BROWSER_STEPS) with its folded charges;
|
|
127
|
+
* undefined for any other row: another tool's call row, whatever it carries, and the usage row. */
|
|
128
|
+
export declare const chargedTool: (row: TimelineEvent) => string | undefined;
|
|
129
|
+
/** The spend cap's wrap-up (serve's cap.ts): the run's model was told once, near its cap, to finish (`words`, what it was
|
|
130
|
+
* told). A row of its own, the server's ("AgentRun: …"); no request, no cost. */
|
|
131
|
+
export declare const CAP_WRAPUP = "agentrun.cap_wrapup";
|
|
132
|
+
/** A tool call with no price, run outside the run's cost and its cap (an MCP tool its owner set no price for): `tool`,
|
|
133
|
+
* `charged_by` and `call` name it. It shows as a row of its own, "not metered", and the usage row counts it
|
|
134
|
+
* (`not_metered`); it is no charge and never makes the cost unknown. */
|
|
135
|
+
export declare const TOOL_UNMETERED = "agentrun.tool_unmetered";
|
|
136
|
+
/** A paid tool's call marked before it is sent (`call`, and `heldUsd`, the most it is held to charge): the TOOL_COST of
|
|
137
|
+
* the same `call` settles it. Unsettled, it is in flight while the run is; once the run is settled it was cut (a crash),
|
|
138
|
+
* and the cost is unknown, as for a cut model request: what it charged no one knows, and its held figure is the cap's
|
|
139
|
+
* bound (serve's cap.ts), never a charge. */
|
|
140
|
+
export declare const TOOL_STARTED = "agentrun.tool_started";
|
|
141
|
+
/** Written right before a `pi.assistant` that continues the answer before it: a call that answer asked for, written once
|
|
142
|
+
* the answer's own entry was already in (a harness reports each call as it runs it, and its host writes an answer at its
|
|
143
|
+
* first call's end). It shows as that answer's, and is no request: no count, no cost, no tokens. */
|
|
144
|
+
export declare const REQUEST_CONTINUED = "agentrun.request_continued";
|
|
145
|
+
/** A host's own step, in its words (`summary`), such as a box waiting for its image: one `phase` row with that summary,
|
|
146
|
+
* cut at CAPS.summary, at `at` (ms) when the host gave the time it happened, else at the time of the log before it. No
|
|
147
|
+
* request, no cost; one without a summary shows nothing. */
|
|
148
|
+
export declare const HOST_PHASE = "agentrun.phase";
|
|
149
|
+
/** Written on the root as a run's process opens to go on with a run its last process left unfinished: `after` is `crash`
|
|
150
|
+
* (that process died holding the run), `server_stop` (it drained as the server stopped) or `runner_lost` (a runner took
|
|
151
|
+
* the run over once the runner holding it, named by `runner`, let its lease run out), `generation` the new process's,
|
|
152
|
+
* `at` when it opened. A phase row of its own, at that time; no request. */
|
|
153
|
+
export declare const RUN_RESUMED = "agentrun.run_resumed";
|
|
154
|
+
/** The end of a turn on another harness (claude-agent, codex), written on a run's root by serve as the turn's last entry:
|
|
155
|
+
* `{ key, status, ... }`. No row. The turn is over, so the next message is the person's next one, never a steer, even
|
|
156
|
+
* when the turn's last entry was a tool's result (a stop that came after it, before the next model request). */
|
|
157
|
+
export declare const TURN_END = "adapter.turn_end";
|
|
158
|
+
export type TimelineOptions = {
|
|
159
|
+
/** For entries and events that carry no conversation id. */
|
|
160
|
+
conversationId?: number;
|
|
161
|
+
agentLabel?: (conversationId: number) => string | null | undefined;
|
|
162
|
+
/** Labels for this call only; `registerLabel` adds them for every call. */
|
|
163
|
+
labels?: Record<string, LabelFn>;
|
|
164
|
+
caps?: Partial<typeof CAPS>;
|
|
165
|
+
/** Nothing is running: a call with no result is interrupted. */
|
|
166
|
+
settled?: boolean;
|
|
167
|
+
/** The run has ended (completed, failed, cancelled): its usage row says its cost ("Cost: …"), never what it has cost
|
|
168
|
+
* "so far". A run settled and not ended (paused, its process let go) keeps "Cost so far". */
|
|
169
|
+
ended?: boolean;
|
|
170
|
+
/** The clock for retry and poll waits; live only. */
|
|
171
|
+
now?: () => number;
|
|
172
|
+
/** How a row names a file path a call gave (`path`, `file_path`) or saved: a host's name for it, such as one relative
|
|
173
|
+
* to its workspace. The entries, the call's arguments and its input preview, are not changed. Default: as given. */
|
|
174
|
+
path?: (path: string) => string;
|
|
175
|
+
/** What a row shows, made safe by the host before the row is cut (its secrets taken out): an error row's summary and
|
|
176
|
+
* text; a tool's whole output and its details before its label, summary and preview are taken from them; each string
|
|
177
|
+
* of a call's arguments where the call is first seen; a thinking block and a text block whole once settled. So a cut
|
|
178
|
+
* never falls inside what it takes out. Default: as given. */
|
|
179
|
+
redact?: (text: string) => string;
|
|
180
|
+
/** What a thinking or text block shows while it streams, given all of it that has streamed so far: the host's redacted
|
|
181
|
+
* prefix of it. A key whose head has streamed but not its tail cannot be found yet, and one a stream wraps is found
|
|
182
|
+
* only in the whole, so the host redacts the whole stream and holds back a tail as long as a key can take; the
|
|
183
|
+
* settled row replaces the live one whole when the block ends. Default: `redact` over the whole stream, with its
|
|
184
|
+
* trailing word held back until whitespace follows it or the block ends. A host that knows its held values should pass
|
|
185
|
+
* this for the full protection: a key a stream wraps with only part of its tail streamed is covered by a held-back
|
|
186
|
+
* tail as long as a key, not by the word holdback. */
|
|
187
|
+
redactLive?: (text: string) => string;
|
|
188
|
+
};
|
|
189
|
+
/** A tool's calls in a run, and how many failed. */
|
|
190
|
+
export type ToolMetrics = {
|
|
191
|
+
calls: number;
|
|
192
|
+
errors: number;
|
|
193
|
+
};
|
|
194
|
+
/** What a run's entries say it used (`runMetricsOf`). Tokens as pi counts them: `input` is the input neither read from
|
|
195
|
+
* nor written to the cache, so the whole input is `input + cacheRead + cacheWrite`. */
|
|
196
|
+
export type RunMetrics = {
|
|
197
|
+
input: number;
|
|
198
|
+
cacheRead: number;
|
|
199
|
+
cacheWrite: number;
|
|
200
|
+
output: number;
|
|
201
|
+
/** Model requests, as the usage row of a run that ended counts them. */
|
|
202
|
+
requests: number;
|
|
203
|
+
/** Of `requests`, those whose tokens are unknown: in no sum. A request cut before its end, a usage with no input or
|
|
204
|
+
* output count, and one that reports no input at all (a writer's zeros for a request it did not measure). */
|
|
205
|
+
unmetered: number;
|
|
206
|
+
/** Requests by `provider/model`; `model` is the one with the most (the first seen of a tie), absent when none names one. */
|
|
207
|
+
models: Record<string, number>;
|
|
208
|
+
model?: string;
|
|
209
|
+
/** By tool name. A call with no result was interrupted: it counts as failed. */
|
|
210
|
+
tools: Record<string, ToolMetrics>;
|
|
211
|
+
};
|
|
212
|
+
/** How runMetricsOf keeps the names a run's entries hold, which a model writes and may make up: each is one the agent
|
|
213
|
+
* store takes (non-empty, at most `max` UTF-16 units, no lone surrogate), the same name always the same key. A longer
|
|
214
|
+
* one is cut to its first `max - 1` units and "…". A run keeps its `kept` busiest tools and models (the first seen of a
|
|
215
|
+
* tie); the rest are summed under `otherTools` or `otherModels`, and a tool result with no name counts under
|
|
216
|
+
* `unnamedTool`. Those three start with one "…", and no entry's name does: one that starts with "…" gets another. */
|
|
217
|
+
export declare const METRIC_NAMES: Readonly<{
|
|
218
|
+
max: 256;
|
|
219
|
+
kept: 100;
|
|
220
|
+
otherTools: "…other tools";
|
|
221
|
+
otherModels: "…other models";
|
|
222
|
+
unnamedTool: "…unnamed tool";
|
|
223
|
+
}>;
|
|
224
|
+
export declare const PAGE_CHANGED_ROW = "The page changed while you had the browser; the agent takes a new look";
|
|
225
|
+
/** The usage row's label: a run that has ended says its cost, one still going (or paused) what it has cost so far. */
|
|
226
|
+
export declare const COST_SO_FAR = "Cost so far";
|
|
227
|
+
export declare const COST_ENDED = "Cost";
|
|
228
|
+
export declare const costLabel: (ended: boolean) => string;
|
|
229
|
+
/** `row` as an ended run's: a usage row made while it ran ("Cost so far: …") says its cost ("Cost: …"); any other row as
|
|
230
|
+
* it is. For a host that keeps rows read before the run ended. */
|
|
231
|
+
export declare function endedUsage<T extends {
|
|
232
|
+
kind: string;
|
|
233
|
+
summary?: string | null;
|
|
234
|
+
}>(row: T): T;
|
|
235
|
+
/** Rows of a stored conversation, in log order. Pure: the same entries give the same rows. */
|
|
236
|
+
export declare function timelineOf(entries: readonly EntryLike[], options?: TimelineOptions): TimelineEvent[];
|
|
237
|
+
/** The id of the call a run's turn ended waiting on a person by, or undefined: its last meaningful row is a successful tool
|
|
238
|
+
* result for a tool that ends its turn (registerTurnEnding — ask_person is serve's). This is the one rule the view reads a
|
|
239
|
+
* run `input_required` on a question by (the waiting row withAsks appends sits right after this same result), so the
|
|
240
|
+
* runner's loop parks on exactly the turn ends the view would call waiting, and the two can never disagree; the id is the
|
|
241
|
+
* call the park entry names. Truthy when it waits, undefined when it does not. */
|
|
242
|
+
export declare function endedOnTurnEndingTool(entries: readonly EntryLike[]): string | undefined;
|
|
243
|
+
/** A workflow's decision receipt as its run's store keeps it (`@parcha/agentrun-pi/durable`'s DecisionRow): the fields
|
|
244
|
+
* runMetricsOf reads. */
|
|
245
|
+
export type DecisionLike = {
|
|
246
|
+
usage?: unknown;
|
|
247
|
+
model?: unknown;
|
|
248
|
+
provider?: unknown;
|
|
249
|
+
status?: unknown;
|
|
250
|
+
driver_spend?: unknown;
|
|
251
|
+
};
|
|
252
|
+
/** What a run that ended used, from the entries of every conversation of its store, in log order (`SELECT record FROM
|
|
253
|
+
* entries ORDER BY id`): its model requests and their tokens, counted as its usage row counts them (a cut request's
|
|
254
|
+
* tokens are unknown), and its tool calls. One parameter, so `.map(runMetricsOf)` is safe. Pure, like timelineOf. */
|
|
255
|
+
export declare function runMetricsOf(records: readonly EntryLike[]): RunMetrics;
|
|
256
|
+
/** runMetricsOf, with a workflow run's decision receipts beside its entries: each a request, its `usage`
|
|
257
|
+
* (`input_tokens`, `output_tokens`) in the token sums, and one with none, or cancelled, unmetered. */
|
|
258
|
+
export declare function runMetricsWithDecisions(records: readonly EntryLike[], decisions: readonly DecisionLike[]): RunMetrics;
|
|
259
|
+
/** Live rows from `watchEvents` batches. Committed entries go through the same projector `timelineOf` uses. */
|
|
260
|
+
export declare function timelineReducer(options?: TimelineOptions): {
|
|
261
|
+
apply: (events: readonly AgentEventLike[]) => {
|
|
262
|
+
rows: TimelineEvent[];
|
|
263
|
+
drop: string[];
|
|
264
|
+
};
|
|
265
|
+
/** Every row now, in log order. */
|
|
266
|
+
rows: () => TimelineEvent[];
|
|
267
|
+
/** The usage row read with nothing in flight, put in place of the live one: for a host whose turn was stopped and is
|
|
268
|
+
* over, so a request it cut counts as a charge with no price, as a settled read counts it. Undefined with no row. */
|
|
269
|
+
idle: () => TimelineEvent | undefined;
|
|
270
|
+
/** Whether `id` is a live row (one the events made: a stream, a wait, a phase), not one a committed entry made.
|
|
271
|
+
* A live row ends when it is gone; a committed one was shown and stays, though a snapshot of a compacted
|
|
272
|
+
* conversation no longer holds it. */
|
|
273
|
+
isLive: (id: string) => boolean;
|
|
274
|
+
};
|