@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
package/dist/store/store.d.ts
CHANGED
|
@@ -241,6 +241,20 @@ export interface Learning {
|
|
|
241
241
|
proposals(agentId: string, options?: {
|
|
242
242
|
limit?: number;
|
|
243
243
|
}): Promise<LearningProposal[]>;
|
|
244
|
+
/** What learning spent outside any run, in one read: each run (not imported) whose learning ended in [from, to) (ms),
|
|
245
|
+
* its agent, when its learning ended and what its grade cost (null: unknown; 0: nothing graded). A learning dropped
|
|
246
|
+
* before it was proposed ended when it was kept; a proposal ended when its learning run ended (ended or failed), whose
|
|
247
|
+
* row keeps the grade's spend as its cost. One still waiting for its grade is none of them. */
|
|
248
|
+
spend(window: {
|
|
249
|
+
from: number;
|
|
250
|
+
to: number;
|
|
251
|
+
}): Promise<LearningSpend[]>;
|
|
252
|
+
}
|
|
253
|
+
/** One run's learning end as GET /usage's learning meter counts it (Learning.spend). */
|
|
254
|
+
export interface LearningSpend {
|
|
255
|
+
readonly agentId: string;
|
|
256
|
+
readonly at: number;
|
|
257
|
+
readonly costUsd: number | null;
|
|
244
258
|
}
|
|
245
259
|
/** A command a journal commit takes, with the id of the record that is its effect, an id the effect's batch newly
|
|
246
260
|
* allocates (an entry, a created document, a new task): written only by the commit that newly writes that record, in its
|
|
@@ -452,9 +466,13 @@ export interface Agents {
|
|
|
452
466
|
id: string;
|
|
453
467
|
name: string;
|
|
454
468
|
}[]>;
|
|
455
|
-
/** Adds a revision and makes it the agent's current one, in one commit.
|
|
469
|
+
/** Adds a revision and makes it the agent's current one, in one commit. With `ifCurrent` (a revision id, or null for
|
|
470
|
+
* none), only while that is still the agent's current revision, compared in the same transaction under the agent row's
|
|
471
|
+
* lock: RevisionMoved, and nothing written, when another writer (this server's, or another server's on the same store)
|
|
472
|
+
* moved it first. */
|
|
456
473
|
addRevision(revision: NewRevision & {
|
|
457
474
|
agentId: string;
|
|
475
|
+
ifCurrent?: string | null;
|
|
458
476
|
}): Promise<void>;
|
|
459
477
|
/** Makes `revisionId`, one of the agent's own, its current one. StoreConstraint when it is not a revision of `agentId`. */
|
|
460
478
|
setCurrent(agentId: string, revisionId: string): Promise<void>;
|
|
@@ -615,7 +633,7 @@ export interface Runs {
|
|
|
615
633
|
* none (it was not started with one), never a default. */
|
|
616
634
|
launch(runId: string): Promise<RunLaunchRow>;
|
|
617
635
|
/** Newest first, at most `limit` (no limit: all). `archived` filters on the run's own archive time (true: archived,
|
|
618
|
-
* false: not); its agent's archive is read apart. */
|
|
636
|
+
* false: not); its agent's archive is read apart. A built-in learning run (one a kept learning names) is never listed. */
|
|
619
637
|
list(filter: {
|
|
620
638
|
agentId?: string;
|
|
621
639
|
revisionId?: string;
|
|
@@ -641,6 +659,10 @@ export interface Runs {
|
|
|
641
659
|
claimable(options?: {
|
|
642
660
|
limit?: number;
|
|
643
661
|
}): Promise<string[]>;
|
|
662
|
+
/** The epoch a runner's claim holds run `runId` at now, judged by the store's own clock (the one claims are stamped
|
|
663
|
+
* and fenced by), never a reader's; undefined when no claim holds it (none, released, or run out) or there is no
|
|
664
|
+
* such run. */
|
|
665
|
+
heldAt(runId: string): Promise<number | undefined>;
|
|
644
666
|
/** Claims up to `k` claimable runs for `runner`, oldest first, in one transaction: each at its own epoch + 1, with its
|
|
645
667
|
* `from`. A runner fills its free loops with one call. */
|
|
646
668
|
claimMany(runner: string, k: number, options?: {
|
|
@@ -946,15 +968,15 @@ export interface SignInRow {
|
|
|
946
968
|
readonly verifiedAt: number | null;
|
|
947
969
|
}
|
|
948
970
|
/** A forgotten sign-in's pointer, kept sealed byte for byte as its live row held it (so it still opens under the same
|
|
949
|
-
* binding), only so a server started later can cut it from what a run it was handed shows
|
|
971
|
+
* binding), only so a server started later can cut it from what a run it was handed shows and from what its agent
|
|
972
|
+
* learned. Every one is kept, never only the newest: a note may quote the agent's first pointer, and a shorter list
|
|
973
|
+
* would show it. */
|
|
950
974
|
export interface SignInTombstoneRow {
|
|
951
975
|
readonly agentId: string;
|
|
952
976
|
readonly provider: string;
|
|
953
977
|
readonly pointerSealed: Uint8Array;
|
|
954
978
|
readonly forgottenAt: number;
|
|
955
979
|
}
|
|
956
|
-
/** How many forgotten pointers an agent keeps per store, the oldest dropped first. */
|
|
957
|
-
export declare const SIGN_IN_TOMBSTONES_KEPT = 32;
|
|
958
980
|
export interface SignIns {
|
|
959
981
|
/** Saves the one live sign-in for the agent and provider, its pointer already sealed by the caller: inserted, or replaced
|
|
960
982
|
* in place when one is saved already (one per agent and provider). */
|
|
@@ -993,7 +1015,7 @@ export interface SignIns {
|
|
|
993
1015
|
/** Forgets the agent's live sign-in for the provider, in the one transaction a launch shares as its lock: when a running
|
|
994
1016
|
* run holds `hash` in its sign_in_handed (or, with `heldUnreadable`, when any running run was handed a sign-in at all),
|
|
995
1017
|
* the forget is refused (SignInHandedTo, naming the run) and nothing is written; otherwise the live row's sealed pointer
|
|
996
|
-
* moves to a tombstone (
|
|
1018
|
+
* moves to a tombstone (every one kept) and the live row goes. SignInMissing when the agent has
|
|
997
1019
|
* no live sign-in for the provider. */
|
|
998
1020
|
forget(agentId: string, provider: string, held: {
|
|
999
1021
|
hash?: string;
|
|
@@ -1245,6 +1267,13 @@ export declare class StoreConstraint extends Error {
|
|
|
1245
1267
|
};
|
|
1246
1268
|
});
|
|
1247
1269
|
}
|
|
1270
|
+
/** An agent's current revision is not the one a conditional write expected (addRevision's `ifCurrent`): another write
|
|
1271
|
+
* moved it first. `current` is the agent's current revision now. Nothing was written. */
|
|
1272
|
+
export declare class RevisionMoved extends Error {
|
|
1273
|
+
readonly agentId: string;
|
|
1274
|
+
readonly current: string | null;
|
|
1275
|
+
constructor(agentId: string, current: string | null);
|
|
1276
|
+
}
|
|
1248
1277
|
/** Forgetting a sign-in a running run was handed: refused, nothing written. `runId` is the run that holds it. */
|
|
1249
1278
|
export declare class SignInHandedTo extends Error {
|
|
1250
1279
|
readonly runId: string;
|
package/dist/store/store.js
CHANGED
|
@@ -48,8 +48,6 @@ export const STORE_WRITE_DEADLINE_MS = 10_000;
|
|
|
48
48
|
* slow commit is still landing a set whose token the provider already spent, and a waiter then takes over and refreshes
|
|
49
49
|
* with the spent one. Made from the two bounds so it cannot drift. */
|
|
50
50
|
export const MCP_REFRESH_LEASE_MS = MCP_REFRESH_CALL_MS + STORE_WRITE_DEADLINE_MS + 2_000;
|
|
51
|
-
/** How many forgotten pointers an agent keeps per store, the oldest dropped first. */
|
|
52
|
-
export const SIGN_IN_TOMBSTONES_KEPT = 32;
|
|
53
51
|
/** A write under a claim whose epoch is no longer the run's: refused, and nothing written. */
|
|
54
52
|
export class Fenced extends Error {
|
|
55
53
|
runId;
|
|
@@ -172,6 +170,18 @@ export class StoreConstraint extends Error {
|
|
|
172
170
|
this.unique = details.unique;
|
|
173
171
|
}
|
|
174
172
|
}
|
|
173
|
+
/** An agent's current revision is not the one a conditional write expected (addRevision's `ifCurrent`): another write
|
|
174
|
+
* moved it first. `current` is the agent's current revision now. Nothing was written. */
|
|
175
|
+
export class RevisionMoved extends Error {
|
|
176
|
+
agentId;
|
|
177
|
+
current;
|
|
178
|
+
constructor(agentId, current) {
|
|
179
|
+
super(`the current revision of agent ${agentId} moved (now ${current ?? "none"})`);
|
|
180
|
+
this.agentId = agentId;
|
|
181
|
+
this.current = current;
|
|
182
|
+
this.name = "RevisionMoved";
|
|
183
|
+
}
|
|
184
|
+
}
|
|
175
185
|
/** Forgetting a sign-in a running run was handed: refused, nothing written. `runId` is the run that holds it. */
|
|
176
186
|
export class SignInHandedTo extends Error {
|
|
177
187
|
runId;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Context } from "@earendil-works/chord";
|
|
2
2
|
import { type Meters } from "../cap.js";
|
|
3
3
|
import type { Store } from "../store/store.js";
|
|
4
|
-
/** What a run
|
|
4
|
+
/** What a run has spent, as the cap reads it, from the one store's journal: its model requests and its paid tool calls. */
|
|
5
5
|
export declare function spentOverStore(store: Store, runId: string, context: Context): Promise<number | null>;
|
|
6
6
|
/** /usage's meters for a run that ended, over the one store's journal (design 2.1): cap.ts meterFiguresFrom over A's
|
|
7
7
|
* entries, with the run's paid tool charges folded back from its paid-tools session (journal.ts withPaidCosts) as the
|
package/dist/store-reads/cap.js
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
import { meterFiguresFrom, spentFrom } from "../cap.js";
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { bookedCapSpend, bookedSpend, costIsBooked } from "../runner/metrics.js";
|
|
3
|
+
import { isCliRecord, runEntries, withPaidCosts } from "./journal.js";
|
|
4
|
+
/** What a run has spent, as the cap reads it, from the one store's journal: its model requests and its paid tool calls. */
|
|
4
5
|
export async function spentOverStore(store, runId, context) {
|
|
5
|
-
|
|
6
|
+
const entries = await runEntries(store, runId, context);
|
|
7
|
+
// A run whose record carries no cost of its own (a CLI harness's, a workflow's) reads what its sessions booked, the
|
|
8
|
+
// figure its cap holds it to (metrics.ts bookedCapSpend), its record's answers reading $0: 0 before any request, an
|
|
9
|
+
// unknown booked spend unknown (null).
|
|
10
|
+
if (costIsBooked(entries, isCliRecord(entries)))
|
|
11
|
+
return bookedCapSpend(entries);
|
|
12
|
+
// A pi run's paid tool calls (a browser's time, a search, a monid call) are booked on the run's one ledger, not its root:
|
|
13
|
+
// folded back as the charges the file-backed root held (withPaidCosts), as metersOverStore reads them, so a live run's
|
|
14
|
+
// listed spend counts them.
|
|
15
|
+
return spentFrom(withPaidCosts(entries));
|
|
6
16
|
}
|
|
7
17
|
/** /usage's meters for a run that ended, over the one store's journal (design 2.1): cap.ts meterFiguresFrom over A's
|
|
8
18
|
* entries, with the run's paid tool charges folded back from its paid-tools session (journal.ts withPaidCosts) as the
|
|
@@ -13,5 +23,13 @@ export async function metersOverStore(store, runId, context) {
|
|
|
13
23
|
const raw = await runEntries(store, runId, context);
|
|
14
24
|
if (!raw.length)
|
|
15
25
|
return { tools: 0, tokens: null, browser: { usd: 0, seconds: 0 }, others: 0, known: { tokens: 0, browser: 0, others: 0 } };
|
|
16
|
-
|
|
26
|
+
const figures = meterFiguresFrom(withPaidCosts(raw).map((entry) => ({ conversation: Number(entry.conversationId ?? 0), entry })));
|
|
27
|
+
// A run whose record carries no cost of its own (a CLI harness's, a workflow's): its tokens meter is its model requests
|
|
28
|
+
// at what they were booked at (metrics.ts bookedSpend, the one reader), never the $0 its record reads.
|
|
29
|
+
if (!costIsBooked(raw, isCliRecord(raw)))
|
|
30
|
+
return figures;
|
|
31
|
+
const model = bookedSpend(raw, "model");
|
|
32
|
+
if (!model.requests)
|
|
33
|
+
return figures;
|
|
34
|
+
return { ...figures, tokens: model.usd, known: { ...figures.known, tokens: model.known } };
|
|
17
35
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Context } from "@earendil-works/chord";
|
|
2
|
-
import type { EntryLike, TimelineEvent, TimelineOptions } from "
|
|
2
|
+
import type { EntryLike, TimelineEvent, TimelineOptions } from "../timeline/index.js";
|
|
3
3
|
import { Hearing } from "../heard.js";
|
|
4
|
-
import { type Reflect } from "../
|
|
4
|
+
import { type Reflect } from "../reflect-range.js";
|
|
5
5
|
import type { Store } from "../store/store.js";
|
|
6
6
|
/** A run's entries from the one store, in log order (by id across every conversation), as the old "SELECT record FROM
|
|
7
7
|
* entries ORDER BY id" read them for a settled run. A run with no journal reads as none. */
|
|
@@ -18,12 +18,15 @@ export declare function runReflect(store: Store, runId: string, context: Context
|
|
|
18
18
|
* given back unused shows nothing. Each charge is placed right after its call's result, joined by `call`, as the ledger
|
|
19
19
|
* wrote it there. A run with no paid-tools session reads unchanged. */
|
|
20
20
|
export declare function withPaidCosts(entries: readonly EntryLike[]): EntryLike[];
|
|
21
|
+
/** Whether `entries` are a CLI harness's record (its loop's calls and messages). */
|
|
22
|
+
export declare const isCliRecord: (entries: readonly EntryLike[]) => boolean;
|
|
21
23
|
/** A run's timeline rows, the renderer (timelineOf) unchanged, over the one store's entries, with a CLI harness's record
|
|
22
24
|
* rendered as its pi-shaped entries (piShaped) and its paid tool charges read back from the paid-tools session
|
|
23
|
-
* (withPaidCosts).
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* (
|
|
25
|
+
* (withPaidCosts). A run whose record carries no per-request cost (a CLI harness's, a workflow's: metrics.ts
|
|
26
|
+
* costIsBooked) has the usage row the renderer folds from its model turns put in its booking's words (bookedUsage): its
|
|
27
|
+
* model requests at what the run's model proxy booked them at, and its paid tool calls at what they charged, as a pi
|
|
28
|
+
* run's usage row counts them; its decisions' rows and cost come from their receipts (decision-rows.ts withDecisions),
|
|
29
|
+
* once. The end-of-run turn's rows are labelled as the server labels them (reflect-range.ts labelled). */
|
|
27
30
|
export declare function runTimeline(store: Store, runId: string, context: Context, options?: TimelineOptions): Promise<TimelineEvent[]>;
|
|
28
31
|
/** How a reader serves an answer whole: its redactor over the whole text (key-refusal.ts redactedAnswer with the run's
|
|
29
32
|
* values), and a key for those values (their digest), so an answer is read once per held value set. */
|
|
@@ -3,15 +3,17 @@
|
|
|
3
3
|
// its own database file ("SELECT record FROM entries ORDER BY id") and fed the same pure renderer; these read the one store instead.
|
|
4
4
|
// The renderer and the hearing keep their words; only where the entries come from changes.
|
|
5
5
|
import { createHash } from "node:crypto";
|
|
6
|
-
import { CAPS, timelineOf, TOOL_COST } from "
|
|
6
|
+
import { CAPS, costLabel, timelineOf, TOOL_COST } from "../timeline/index.js";
|
|
7
7
|
import { RUNNER_RECORDS } from "@parcha/agentrun-kernel";
|
|
8
8
|
import { TOOL_SESSION } from "@parcha/agentrun-kernel/kernel/cap";
|
|
9
9
|
import { Hearing } from "../heard.js";
|
|
10
10
|
import { redactedAnswer } from "../key-refusal.js";
|
|
11
|
-
import { labelled } from "../
|
|
11
|
+
import { labelled } from "../reflect-range.js";
|
|
12
12
|
import { reflectFrom } from "../runner/end-of-run.js";
|
|
13
13
|
import { journalEntries, journalRecords } from "../runner/journal-reader.js";
|
|
14
|
-
import { KINDS } from "../runner/journal-kinds.js";
|
|
14
|
+
import { endedAnswer, KINDS } from "../runner/journal-kinds.js";
|
|
15
|
+
import { bookedSpend, costIsBooked } from "../runner/metrics.js";
|
|
16
|
+
import { waitingText } from "../tool-gate.js";
|
|
15
17
|
/** A run's entries from the one store, in log order (by id across every conversation), as the old "SELECT record FROM
|
|
16
18
|
* entries ORDER BY id" read them for a settled run. A run with no journal reads as none. */
|
|
17
19
|
export async function runEntries(store, runId, context) {
|
|
@@ -22,7 +24,7 @@ export async function runEntries(store, runId, context) {
|
|
|
22
24
|
* before its input; `until`, the run's end entry once written. Undefined for a run that asked none. */
|
|
23
25
|
export async function runReflect(store, runId, context) {
|
|
24
26
|
const records = await journalRecords(store.readJournal(runId), context);
|
|
25
|
-
const from = reflectFrom(records.submissions ?? []);
|
|
27
|
+
const from = reflectFrom(records.submissions ?? [], records.entries);
|
|
26
28
|
if (from === undefined)
|
|
27
29
|
return undefined;
|
|
28
30
|
const end = records.entries.find((entry) => entry.kind === KINDS.end && Number(entry.id) >= from);
|
|
@@ -33,9 +35,39 @@ export async function runReflect(store, runId, context) {
|
|
|
33
35
|
* tool call its assistant tool-call and its result. So a claude-agent / codex / opencode run reads the same rows, words
|
|
34
36
|
* and final answer as a pi run of the same conversation. A run's own pi entries and its end-of-run turn (already model
|
|
35
37
|
* shaped) pass through unchanged, so a pi run is untouched. */
|
|
38
|
+
/** The calls the CLI record holds parked at their gate (a start marked parked) with no sent mark and no end. */
|
|
39
|
+
function parkedUnsent(entries) {
|
|
40
|
+
const parked = new Set();
|
|
41
|
+
const past = new Set();
|
|
42
|
+
for (const entry of entries) {
|
|
43
|
+
const callId = entry.data?.callId;
|
|
44
|
+
if (typeof callId !== "string")
|
|
45
|
+
continue;
|
|
46
|
+
if (entry.kind === KINDS.callStart && entry.data.parked === true)
|
|
47
|
+
parked.add(callId);
|
|
48
|
+
else if (entry.kind === KINDS.callSent || entry.kind === KINDS.callEnd)
|
|
49
|
+
past.add(callId);
|
|
50
|
+
}
|
|
51
|
+
for (const callId of past)
|
|
52
|
+
parked.delete(callId);
|
|
53
|
+
return parked;
|
|
54
|
+
}
|
|
36
55
|
function piShaped(entries) {
|
|
37
|
-
|
|
56
|
+
const waiting = parkedUnsent(entries);
|
|
57
|
+
return entries.flatMap((entry) => {
|
|
38
58
|
const data = (entry.data ?? {});
|
|
59
|
+
// A call through a CLI's own MCP client that its gate parked (adapter-loop.ts park): the CLI was answered the gate's
|
|
60
|
+
// waiting words (mcp-run.ts), which the record never keeps as the call's end, since an end is its outcome and the call
|
|
61
|
+
// is answered from it. While the call is parked and unsent, those words show as its result row from its ask on, as pi's
|
|
62
|
+
// parked call shows them; its sent mark or its end (run, refused, withdrawn) ends that.
|
|
63
|
+
// Once per call, at its first ask: a call asked again (a resume, a raise while it waits) shows one waiting result.
|
|
64
|
+
if (entry.kind === KINDS.ask && typeof data.callId === "string" && waiting.delete(data.callId)) {
|
|
65
|
+
const tool = typeof data.tool === "string" ? data.tool : "tool";
|
|
66
|
+
const timestamp = typeof data.requestedAt === "string" && Number.isFinite(Date.parse(data.requestedAt)) ? { timestamp: Date.parse(data.requestedAt) } : {};
|
|
67
|
+
// Its own id (the ask's, marked), so the renderer never takes it for the ask entry seen twice.
|
|
68
|
+
const result = { ...entry, id: `${String(entry.id)}:parked`, kind: "pi.tool-result", data: {}, model: [{ role: "tool", toolCallId: data.callId, content: waitingText(tool), ...timestamp }] };
|
|
69
|
+
return [entry, result];
|
|
70
|
+
}
|
|
39
71
|
// When the record's entry was written (`at`), as pi's own message carries its timestamp: the Timeline dates the row by it.
|
|
40
72
|
const timestamp = typeof data.at === "number" ? { timestamp: data.at } : {};
|
|
41
73
|
if (entry.kind === KINDS.message) {
|
|
@@ -46,13 +78,22 @@ function piShaped(entries) {
|
|
|
46
78
|
const stopReason = data.stopReason === "length" ? "length" : "stop";
|
|
47
79
|
return { ...entry, kind: "pi.assistant", model: [{ role: "assistant", stopReason, content: [{ type: "text", text }], ...(typeof data.outputTokens === "number" ? { usage: { output: data.outputTokens } } : {}), ...timestamp }] };
|
|
48
80
|
}
|
|
81
|
+
// The end-of-run turn's answer, as the CLI record keeps it (adapter-loop.ts answered): a model turn that ended, so the
|
|
82
|
+
// timeline shows it as pi's end-of-run turn shows its own (labelled then marks it the learning's).
|
|
83
|
+
if (entry.kind === KINDS.endOfRunTurn && data.role === "model") {
|
|
84
|
+
const text = typeof data.text === "string" ? data.text : "";
|
|
85
|
+
return { ...entry, kind: "pi.assistant", model: [{ role: "assistant", stopReason: "stop", content: [{ type: "text", text }] }] };
|
|
86
|
+
}
|
|
49
87
|
if (entry.kind === KINDS.callStart) {
|
|
50
88
|
return { ...entry, kind: "pi.assistant", model: [{ role: "assistant", stopReason: "tool_use", content: [{ type: "toolCall", id: String(data.callId ?? ""), name: String(data.tool ?? "tool"), arguments: data.input ?? {} }], ...timestamp }] };
|
|
51
89
|
}
|
|
52
90
|
if (entry.kind === KINDS.callEnd) {
|
|
53
|
-
// A call that did not finish done is an error result, as a failed pi tool call is; its output is the result's text.
|
|
91
|
+
// A call that did not finish done is an error result, as a failed pi tool call is; its output is the result's text. One
|
|
92
|
+
// a crash cut, written with no output, reads in the words its model was given (endedAnswer: the kernel's interrupted
|
|
93
|
+
// text), as pi's own interrupted result does, never an empty failure.
|
|
54
94
|
const failed = data.status !== undefined && data.status !== "done";
|
|
55
|
-
|
|
95
|
+
const content = data.output === undefined && data.status === "interrupted" ? endedAnswer("", { status: "interrupted" }).text : (data.output ?? "");
|
|
96
|
+
return { ...entry, kind: "pi.tool-result", model: [{ role: "tool", toolCallId: String(data.callId ?? ""), content, ...(failed ? { isError: true } : {}), ...timestamp }] };
|
|
56
97
|
}
|
|
57
98
|
return entry;
|
|
58
99
|
});
|
|
@@ -71,13 +112,15 @@ export function withPaidCosts(entries) {
|
|
|
71
112
|
if (typeof conv !== "number")
|
|
72
113
|
return [...entries];
|
|
73
114
|
// Each paid request's tool and the call it ran under, by its turn; then each turn's cost, paired by turn.
|
|
115
|
+
// Its tool: the one the request names (`tool`: a browser step's "browser", which the renderer folds into its call's row
|
|
116
|
+
// with its session `tag`, as main's browser charge), else its paid name.
|
|
74
117
|
const named = new Map();
|
|
75
118
|
for (const e of entries) {
|
|
76
119
|
if (e.conversationId !== conv || e.kind !== RUNNER_RECORDS.request)
|
|
77
120
|
continue;
|
|
78
121
|
const d = (e.data ?? {});
|
|
79
122
|
if (typeof d.turn === "number" && typeof d.model === "string" && d.model.startsWith("paid:"))
|
|
80
|
-
named.set(d.turn, { tool: d.model.slice("paid:".length), ...(typeof d.call === "string" ? { call: d.call } : {}), ...(typeof d.charged_by === "string" && d.charged_by ? { chargedBy: d.charged_by } : {}) });
|
|
123
|
+
named.set(d.turn, { tool: typeof d.tool === "string" && d.tool ? d.tool : d.model.slice("paid:".length), ...(typeof d.call === "string" ? { call: d.call } : {}), ...(typeof d.charged_by === "string" && d.charged_by ? { chargedBy: d.charged_by } : {}), ...(typeof d.tag === "string" && d.tag ? { tag: d.tag } : {}) });
|
|
81
124
|
}
|
|
82
125
|
const charges = [];
|
|
83
126
|
for (const e of entries) {
|
|
@@ -90,7 +133,7 @@ export function withPaidCosts(entries) {
|
|
|
90
133
|
// is unknown (null) is a charge of an unknown amount (main's TOOL_COST with no usd).
|
|
91
134
|
if (!req || d.givenBack === true)
|
|
92
135
|
continue;
|
|
93
|
-
charges.push({ ...req, usd: typeof d.usd === "number" && Number.isFinite(d.usd) && d.usd >= 0 ? d.usd : null });
|
|
136
|
+
charges.push({ ...req, turn: d.turn, usd: typeof d.usd === "number" && Number.isFinite(d.usd) && d.usd >= 0 ? d.usd : null });
|
|
94
137
|
}
|
|
95
138
|
if (!charges.length)
|
|
96
139
|
return [...entries];
|
|
@@ -100,24 +143,57 @@ export function withPaidCosts(entries) {
|
|
|
100
143
|
// MCP server, a browser vendor).
|
|
101
144
|
const by = charge.chargedBy;
|
|
102
145
|
const at = charge.call === undefined ? -1 : out.findIndex((e) => e.kind === "pi.tool-result" && String(e.model?.[0]?.toolCallId ?? "") === charge.call);
|
|
103
|
-
const data = { tool: charge.tool, ...(by ? { charged_by: by } : {}), ...(charge.call ? { call: charge.call } : {}), ...(charge.usd !== null ? { usd: charge.usd } : {}) };
|
|
104
|
-
const entry = { conversationId: at >= 0 ? out[at].conversationId : conv, kind: TOOL_COST, data, id: `paid:${charge.call ?? charge.tool}` };
|
|
146
|
+
const data = { tool: charge.tool, ...(by ? { charged_by: by } : {}), ...(charge.call ? { call: charge.call } : {}), ...(charge.tag ? { tag: charge.tag } : {}), ...(charge.usd !== null ? { usd: charge.usd } : {}) };
|
|
147
|
+
const entry = { conversationId: at >= 0 ? out[at].conversationId : conv, kind: TOOL_COST, data, id: `paid:${charge.call ?? charge.tool}#${charge.turn}` };
|
|
105
148
|
out.splice(at >= 0 ? at + 1 : out.length, 0, entry);
|
|
106
149
|
}
|
|
107
150
|
return out;
|
|
108
151
|
}
|
|
152
|
+
/** Whether `entries` are a CLI harness's record (its loop's calls and messages). */
|
|
153
|
+
export const isCliRecord = (entries) => entries.some((entry) => entry.kind === KINDS.message || entry.kind === KINDS.callStart || entry.kind === KINDS.callEnd);
|
|
109
154
|
/** A run's timeline rows, the renderer (timelineOf) unchanged, over the one store's entries, with a CLI harness's record
|
|
110
155
|
* rendered as its pi-shaped entries (piShaped) and its paid tool charges read back from the paid-tools session
|
|
111
|
-
* (withPaidCosts).
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
* (
|
|
156
|
+
* (withPaidCosts). A run whose record carries no per-request cost (a CLI harness's, a workflow's: metrics.ts
|
|
157
|
+
* costIsBooked) has the usage row the renderer folds from its model turns put in its booking's words (bookedUsage): its
|
|
158
|
+
* model requests at what the run's model proxy booked them at, and its paid tool calls at what they charged, as a pi
|
|
159
|
+
* run's usage row counts them; its decisions' rows and cost come from their receipts (decision-rows.ts withDecisions),
|
|
160
|
+
* once. The end-of-run turn's rows are labelled as the server labels them (reflect-range.ts labelled). */
|
|
115
161
|
export async function runTimeline(store, runId, context, options = {}) {
|
|
116
162
|
const entries = await runEntries(store, runId, context);
|
|
117
|
-
const cli = entries
|
|
118
|
-
const
|
|
163
|
+
const cli = isCliRecord(entries);
|
|
164
|
+
const rendered = timelineOf(withPaidCosts(cli ? piShaped(entries) : entries), options);
|
|
165
|
+
const rows = costIsBooked(entries, cli) ? bookedUsage(rendered, entries, options) : rendered;
|
|
119
166
|
return labelled((await runReflect(store, runId, context)), await datedRows(store, runId, rows));
|
|
120
167
|
}
|
|
168
|
+
/** A CLI or workflow run's `rows` with its usage row in its booking's words (runner/metrics.ts bookedSpend over every
|
|
169
|
+
* session of the run but its decisions'): its model requests and its paid tool calls, their sum (unknown while one's cost is, with what is known so far,
|
|
170
|
+
* costsofar/1), in the renderer's words (`Cost` once ended, else `Cost so far`). The renderer's own row is replaced in
|
|
171
|
+
* place; a run that booked a request and rendered none gets one at the end. One that booked none keeps its rows, with no
|
|
172
|
+
* usage row. */
|
|
173
|
+
function bookedUsage(rows, entries, options) {
|
|
174
|
+
const model = bookedSpend(entries, "model");
|
|
175
|
+
const paid = bookedSpend(entries, "paid");
|
|
176
|
+
const at = rows.findIndex((row) => row.kind === "usage");
|
|
177
|
+
const kept = rows.filter((row) => row.kind !== "usage");
|
|
178
|
+
if (!model.requests && !paid.requests)
|
|
179
|
+
return kept;
|
|
180
|
+
const usd = model.usd === null || paid.usd === null ? null : model.usd + paid.usd;
|
|
181
|
+
const unpriced = model.unpriced + paid.unpriced;
|
|
182
|
+
const dollars = (value) => (value === 0 ? "$0" : `$${value.toFixed(4)}`);
|
|
183
|
+
const spent = usd !== null ? dollars(usd) : `${dollars(model.known + paid.known)} known, ${unpriced} not priced,`;
|
|
184
|
+
const charges = paid.requests ? ` and ${paid.requests} paid tool call${paid.requests === 1 ? "" : "s"}` : "";
|
|
185
|
+
const summary = `${costLabel(options.ended === true)}: ${spent} over ${model.requests} model request${model.requests === 1 ? "" : "s"}${charges}`;
|
|
186
|
+
const usage = { usd, requests: model.requests, ...(usd === null ? { so_far_usd: model.known + paid.known, unpriced } : {}) };
|
|
187
|
+
const last = rows[rows.length - 1];
|
|
188
|
+
const base = at >= 0 ? rows[at] : {
|
|
189
|
+
...last, id: `${last?.conversation_id ?? 0}:usage`, agent_label: null, text: null,
|
|
190
|
+
tool_name: null, tool_use_id: null, tool_status: null, tool_input_preview: null, tool_result_preview: null, tool_result_size_bytes: null,
|
|
191
|
+
};
|
|
192
|
+
const row = { ...base, kind: "usage", summary, usage };
|
|
193
|
+
const out = [...kept];
|
|
194
|
+
out.splice(at >= 0 ? at : out.length, 0, row);
|
|
195
|
+
return out;
|
|
196
|
+
}
|
|
121
197
|
/** `rows` with none dated 1970: a row the renderer found no time for (an entry of a CLI record written before its entries
|
|
122
198
|
* carried `at`; the store's entry rows keep no write time of their own) reads the run's start, the earliest time it can
|
|
123
199
|
* have, never epoch 0. Every other row is as the renderer dated it. */
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { type Learning, type NoteUsed, type Shown } from "../learning.js";
|
|
1
|
+
import { type ItemStatus, type Learning, type NoteUsed, type Shown } from "../learning.js";
|
|
2
2
|
import { type RunLaunch } from "../run-launch.js";
|
|
3
|
-
import { type Impact
|
|
3
|
+
import { type Impact } from "../learning-run.js";
|
|
4
|
+
import type { Reflect } from "../reflect-range.js";
|
|
4
5
|
import type { NoteRuns } from "../learning.js";
|
|
5
|
-
import type { TimelineEvent } from "
|
|
6
|
+
import type { TimelineEvent } from "../timeline/index.js";
|
|
6
7
|
import type { AnalyticsFilter } from "./analytics.js";
|
|
7
8
|
import type { Store } from "../store/store.js";
|
|
8
9
|
/** A run's learning end: the Learning fields its end sets. */
|
|
@@ -23,6 +24,18 @@ export type LearningCounts = {
|
|
|
23
24
|
* read as the run's view reads it (runLearningEnd). A workflow's run, and one with no learning, is not counted; nor is
|
|
24
25
|
* one whose reason this server does not give (an older server's). An imported run keeps no learning in the store. */
|
|
25
26
|
export declare function learningCountsOverStore(store: Store, filter: AnalyticsFilter): Promise<LearningCounts>;
|
|
27
|
+
/** What learning spent outside any run (GET /usage's `learning` meter) in [from, to) (ms), one entry per run whose
|
|
28
|
+
* learning ended then, as the learning ledger's lines gave it: its agent, when its learning ended, and what its grade
|
|
29
|
+
* cost: 0 for a run never graded, null when the grade's spend is unknown (a grade that failed), never $0 then. One read
|
|
30
|
+
* of the store (Learning.spend), whatever the number of runs. */
|
|
31
|
+
export declare function learningSpendOverStore(store: Store, window: {
|
|
32
|
+
from: number;
|
|
33
|
+
to: number;
|
|
34
|
+
}): Promise<{
|
|
35
|
+
agent: string;
|
|
36
|
+
at: string;
|
|
37
|
+
cost: number | null;
|
|
38
|
+
}[]>;
|
|
26
39
|
/** An agent's learning counts as its learning view gives them (GET /agents/{id}/learning, learning-run.ts ofAgent's
|
|
27
40
|
* counts): how its runs that tried to learn fared, less `runs`, from the one store. Its notes' runs and its impact are
|
|
28
41
|
* agentLearningOverStore's. */
|
|
@@ -52,9 +65,10 @@ export declare function notesReadOf(given: readonly NoteUsed[] | undefined, refl
|
|
|
52
65
|
export declare function withNotes(end: RunLearningEnd, started: RunLaunch["learning"], read: readonly NoteUsed[]): RunLearning;
|
|
53
66
|
/** GET /runs/{id}/learning from the one store, in the shape the route gives (learning-routes.ts runLearningBody): the
|
|
54
67
|
* run's learning end (runLearningEnd), the notes it was given and the seed it started from as its launch records them,
|
|
55
|
-
* what it held for its owner's OK as
|
|
56
|
-
* once the run is final. Null when the run kept
|
|
57
|
-
|
|
68
|
+
* what it held for its owner's OK as it stands on its agent's folder's main (`statuses`, learning-routes.ts statusesOf,
|
|
69
|
+
* read only when it held something; none: as the merge wrote it), settled once the run is final. Null when the run kept
|
|
70
|
+
* no learning. */
|
|
71
|
+
export declare function runLearningOverStore(store: Store, runId: string, shown: Shown, secrets: readonly string[], statuses?: (agentId: string) => Promise<ReadonlyMap<string, ItemStatus> | undefined>): Promise<{
|
|
58
72
|
seed: string | null;
|
|
59
73
|
merged: string | null;
|
|
60
74
|
pending: {
|
|
@@ -73,7 +87,11 @@ export declare function runLearningOverStore(store: Store, runId: string, shown:
|
|
|
73
87
|
keep: boolean;
|
|
74
88
|
}[];
|
|
75
89
|
} | null;
|
|
76
|
-
problems:
|
|
90
|
+
problems: {
|
|
91
|
+
detail: string;
|
|
92
|
+
path?: string | undefined;
|
|
93
|
+
rule: import("../learn/check.js").Rule;
|
|
94
|
+
}[];
|
|
77
95
|
cost_usd: {
|
|
78
96
|
grade: number | null;
|
|
79
97
|
};
|
|
@@ -87,7 +105,7 @@ export declare function runLearningOverStore(store: Store, runId: string, shown:
|
|
|
87
105
|
workflows?: import("../learning.js").LearnedFile[];
|
|
88
106
|
run: string;
|
|
89
107
|
state: "proposed" | "merged" | "seeded" | "reflecting" | "dropped";
|
|
90
|
-
reason: "empty" | "
|
|
108
|
+
reason: "empty" | "cancelled" | "unparsed" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "grader" | "grade_failed" | null;
|
|
91
109
|
detail: string | null;
|
|
92
110
|
at: string;
|
|
93
111
|
} | null>;
|
|
@@ -109,6 +109,13 @@ export async function learningCountsOverStore(store, filter) {
|
|
|
109
109
|
}
|
|
110
110
|
return out;
|
|
111
111
|
}
|
|
112
|
+
/** What learning spent outside any run (GET /usage's `learning` meter) in [from, to) (ms), one entry per run whose
|
|
113
|
+
* learning ended then, as the learning ledger's lines gave it: its agent, when its learning ended, and what its grade
|
|
114
|
+
* cost: 0 for a run never graded, null when the grade's spend is unknown (a grade that failed), never $0 then. One read
|
|
115
|
+
* of the store (Learning.spend), whatever the number of runs. */
|
|
116
|
+
export async function learningSpendOverStore(store, window) {
|
|
117
|
+
return (await store.learning.spend(window)).map((one) => ({ agent: one.agentId, at: timeOf(one.at), cost: one.costUsd }));
|
|
118
|
+
}
|
|
112
119
|
/** An agent's learning counts as its learning view gives them (GET /agents/{id}/learning, learning-run.ts ofAgent's
|
|
113
120
|
* counts): how its runs that tried to learn fared, less `runs`, from the one store. Its notes' runs and its impact are
|
|
114
121
|
* agentLearningOverStore's. */
|
|
@@ -186,9 +193,10 @@ async function learningStartOfRun(store, runId) {
|
|
|
186
193
|
}
|
|
187
194
|
/** GET /runs/{id}/learning from the one store, in the shape the route gives (learning-routes.ts runLearningBody): the
|
|
188
195
|
* run's learning end (runLearningEnd), the notes it was given and the seed it started from as its launch records them,
|
|
189
|
-
* what it held for its owner's OK as
|
|
190
|
-
* once the run is final. Null when the run kept
|
|
191
|
-
|
|
196
|
+
* what it held for its owner's OK as it stands on its agent's folder's main (`statuses`, learning-routes.ts statusesOf,
|
|
197
|
+
* read only when it held something; none: as the merge wrote it), settled once the run is final. Null when the run kept
|
|
198
|
+
* no learning. */
|
|
199
|
+
export async function runLearningOverStore(store, runId, shown, secrets, statuses) {
|
|
192
200
|
const end = await runLearningEnd(store, runId);
|
|
193
201
|
if (!end)
|
|
194
202
|
return null;
|
|
@@ -197,6 +205,6 @@ export async function runLearningOverStore(store, runId, shown, secrets) {
|
|
|
197
205
|
const settled = row !== undefined && FINAL_STATES.includes(row.state);
|
|
198
206
|
const read = started?.given.length ? notesReadOf(started.given, await runReflect(store, runId, BACKGROUND_CONTEXT), await runTimeline(store, runId, BACKGROUND_CONTEXT, { settled })) : [];
|
|
199
207
|
const learning = withNotes(end, started, read);
|
|
200
|
-
const current = holdsForOk(learning) ? currentLearning(learning,
|
|
208
|
+
const current = holdsForOk(learning) && row && statuses ? currentLearning(learning, await statuses(row.agentId)) : learning;
|
|
201
209
|
return runLearningBody({ id: runId, learning: current, seed: started?.seed ?? null, settled }, shown, secrets);
|
|
202
210
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Context } from "@earendil-works/chord";
|
|
2
|
-
import { type WorkflowRunView } from "
|
|
2
|
+
import { type WorkflowRunView } from "../workflow-run.js";
|
|
3
3
|
import type { Store } from "../store/store.js";
|
|
4
4
|
/** The workflow run `runId`'s view from A: its graph's node status, and, once it ended, its outcome, the node it escalated
|
|
5
5
|
* at and its output, read from the run's journal (no claim). Undefined when there is no such run, or its revision is gone
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
2
|
-
import { readWorkflowRun } from "
|
|
2
|
+
import { readWorkflowRun } from "../workflow-run.js";
|
|
3
3
|
/** The workflow run `runId`'s view from A: its graph's node status, and, once it ended, its outcome, the node it escalated
|
|
4
4
|
* at and its output, read from the run's journal (no claim). Undefined when there is no such run, or its revision is gone
|
|
5
5
|
* or is not a workflow. A read never writes or fences. */
|
package/dist/store-view.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { TimelineEvent } from "
|
|
1
|
+
import type { TimelineEvent } from "./timeline/index.js";
|
|
2
|
+
import { type ItemStatus } from "./learning.js";
|
|
2
3
|
import { type RunMoment, type SignInReader } from "./run-view.js";
|
|
3
4
|
import { type Store } from "./store/store.js";
|
|
4
5
|
/** What the store-backed view needs beside the store: where its console lives, every secret it never shows (read now, so
|
|
@@ -15,6 +16,9 @@ export interface ViewDeps {
|
|
|
15
16
|
* run's error names a refused key in plain words, as its Timeline's error row does. Default: this process's
|
|
16
17
|
* environment (the server passes it with the keys a person saved). */
|
|
17
18
|
readonly keyEnv?: () => NodeJS.ProcessEnv;
|
|
19
|
+
/** Each learned item's status on agent `agentId`'s learning folder's main (learning-routes.ts statusesOf): what a run held
|
|
20
|
+
* for its owner's OK reads as it stands there. None: as the merge wrote it. */
|
|
21
|
+
readonly statuses?: (agentId: string) => Promise<ReadonlyMap<string, ItemStatus> | undefined>;
|
|
18
22
|
}
|
|
19
23
|
/** GET /runs/{id}'s answer from the store, byte-identical to runs.ts's view for the same run. Undefined for an unknown run. */
|
|
20
24
|
export declare function viewOverStore(store: Store, runId: string, deps: ViewDeps): Promise<Record<string, unknown> | undefined>;
|