@parcha/agentrun-serve 0.1.0-beta.38 → 0.1.0-beta.40
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 +455 -0
- package/README.md +376 -125
- package/dist/adapters.d.ts +4 -1
- package/dist/adapters.js +4 -2
- package/dist/agent-rows.d.ts +0 -2
- package/dist/agents-store.d.ts +5 -5
- package/dist/agents-store.js +14 -14
- package/dist/bash-read-only.js +2 -1
- package/dist/cap-short.d.ts +12 -0
- package/dist/cap-short.js +60 -0
- package/dist/cap.d.ts +3 -10
- package/dist/cap.js +2 -5
- package/dist/catalog.d.ts +0 -5
- package/dist/catalog.js +1 -5
- package/dist/chatgpt-plan.d.ts +163 -0
- package/dist/chatgpt-plan.js +549 -0
- package/dist/cli.js +26 -6
- package/dist/composio-preset.d.ts +8 -0
- package/dist/composio-preset.js +8 -7
- package/dist/composio-triggers.d.ts +113 -0
- package/dist/composio-triggers.js +411 -0
- package/dist/computer-calls.js +2 -2
- package/dist/computer-commands.d.ts +2 -0
- package/dist/computer-commands.js +7 -3
- package/dist/computer-live.d.ts +7 -2
- package/dist/computer-live.js +9 -5
- package/dist/computer-routes.d.ts +2 -2
- package/dist/computer-routes.js +2 -2
- package/dist/computer-setting.d.ts +3 -3
- package/dist/computer-setting.js +5 -5
- package/dist/computer-view.d.ts +15 -0
- package/dist/computer-view.js +16 -2
- package/dist/computer-viewer.js +14 -1
- package/dist/computers.d.ts +5 -2
- package/dist/computers.js +9 -5
- package/dist/console/assets/index-B8Zn1Iqn.css +1 -0
- package/dist/console/assets/index-Jbxjcmdp.js +705 -0
- package/dist/console/index.html +2 -2
- package/dist/console-links.js +3 -3
- package/dist/decision-cap.d.ts +2 -5
- package/dist/decision-cap.js +3 -6
- package/dist/decision-rows.js +11 -11
- package/dist/email/account.d.ts +83 -0
- package/dist/email/account.js +159 -0
- package/dist/email/answer.d.ts +15 -0
- package/dist/email/answer.js +217 -0
- package/dist/email/email-faux.d.ts +95 -0
- package/dist/email/email-faux.js +849 -0
- package/dist/email/labels.d.ts +1 -0
- package/dist/email/labels.js +84 -0
- package/dist/email/mail.d.ts +186 -0
- package/dist/email/mail.js +373 -0
- package/dist/email/names.d.ts +50 -0
- package/dist/email/names.js +74 -0
- package/dist/email/routes.d.ts +10 -0
- package/dist/email/routes.js +50 -0
- package/dist/email/tools.d.ts +27 -0
- package/dist/email/tools.js +562 -0
- package/dist/environment.d.ts +17 -2
- package/dist/environment.js +36 -8
- package/dist/errors.d.ts +6 -0
- package/dist/errors.js +12 -0
- package/dist/eval-mailbox.d.ts +103 -0
- package/dist/eval-mailbox.js +236 -0
- package/dist/graph-view.d.ts +9 -2
- package/dist/graph-view.js +6 -2
- package/dist/harness-install.d.ts +28 -2
- package/dist/harness-install.js +147 -59
- package/dist/harness-opencode/adapter.js +2 -26
- package/dist/harness-opencode/facts.js +5 -2
- package/dist/harness-opencode/host/policy.d.ts +2 -0
- package/dist/harness-opencode/host/policy.js +10 -5
- package/dist/harness-opencode/index.d.ts +1 -1
- package/dist/harness-opencode/index.js +1 -1
- package/dist/harness-opencode/versions.d.ts +6 -0
- package/dist/harness-opencode/versions.js +6 -0
- package/dist/harness-table.js +8 -5
- package/dist/harness.d.ts +12 -0
- package/dist/harness.js +15 -3
- package/dist/hosted-search.d.ts +3 -1
- package/dist/hosted-search.js +51 -11
- package/dist/import-sources.d.ts +1 -1
- package/dist/import-sources.js +3 -3
- package/dist/import.d.ts +21 -0
- package/dist/import.js +186 -1
- package/dist/key-check.d.ts +0 -2
- package/dist/key-check.js +3 -4
- package/dist/key-refusal.d.ts +8 -2
- package/dist/key-refusal.js +16 -13
- package/dist/learn/check.d.ts +18 -3
- package/dist/learn/check.js +328 -3
- package/dist/learn/compile.d.ts +12 -4
- package/dist/learn/compile.js +57 -20
- package/dist/learn/grade.d.ts +4 -0
- package/dist/learn/grade.js +4 -1
- package/dist/learn/promote.d.ts +130 -64
- package/dist/learn/promote.js +113 -202
- package/dist/learn/refit.d.ts +21 -12
- package/dist/learn/refit.js +51 -23
- package/dist/learn/replay-calls.js +1 -1
- package/dist/learn/skills.d.ts +2 -7
- package/dist/learn/skills.js +28 -14
- package/dist/learned-nodes.d.ts +15 -7
- package/dist/learned-nodes.js +29 -5
- package/dist/learned-workflow.d.ts +41 -31
- package/dist/learned-workflow.js +122 -63
- package/dist/learning-batch.js +3 -3
- package/dist/learning-cost.d.ts +35 -8
- package/dist/learning-cost.js +27 -9
- package/dist/learning-routes.d.ts +2 -4
- package/dist/learning-routes.js +20 -3
- package/dist/learning-words.d.ts +1 -1
- package/dist/learning-words.js +4 -1
- package/dist/learning.d.ts +5 -5
- package/dist/link-check.d.ts +27 -0
- package/dist/link-check.js +164 -0
- package/dist/local-models.d.ts +39 -2
- package/dist/local-models.js +49 -5
- package/dist/mcp-pin-first.js +6 -0
- package/dist/mcp-secret-writes.js +3 -0
- package/dist/mcp-servers-store.d.ts +25 -16
- package/dist/mcp-servers-store.js +23 -3
- package/dist/model-form.d.ts +11 -0
- package/dist/model-form.js +17 -1
- package/dist/model.d.ts +26 -6
- package/dist/model.js +126 -18
- package/dist/monid.d.ts +26 -31
- package/dist/monid.js +84 -79
- package/dist/native/binding.d.ts +13 -0
- package/dist/native/binding.js +57 -0
- package/dist/native/cli.d.ts +2 -0
- package/dist/native/cli.js +48 -0
- package/dist/native/connection.d.ts +8 -0
- package/dist/native/connection.js +94 -0
- package/dist/native/context.d.ts +6 -0
- package/dist/native/context.js +22 -0
- package/dist/native/discovery.d.ts +27 -0
- package/dist/native/discovery.js +404 -0
- package/dist/native/environment.d.ts +4 -0
- package/dist/native/environment.js +18 -0
- package/dist/native/history.d.ts +20 -0
- package/dist/native/history.js +147 -0
- package/dist/native/instructions.d.ts +21 -0
- package/dist/native/instructions.js +173 -0
- package/dist/native/remote-worker-bridge.d.ts +3 -0
- package/dist/native/remote-worker-bridge.js +278 -0
- package/dist/native/remote.d.ts +187 -0
- package/dist/native/remote.js +492 -0
- package/dist/native/runtime.d.ts +17 -0
- package/dist/native/runtime.js +316 -0
- package/dist/native/runtimes.d.ts +66 -0
- package/dist/native/runtimes.js +41 -0
- package/dist/native/schema.d.ts +46 -0
- package/dist/native/schema.js +41 -0
- package/dist/native/types.d.ts +87 -0
- package/dist/native/types.js +1 -0
- package/dist/observation/http.d.ts +4 -0
- package/dist/observation/http.js +140 -0
- package/dist/observation/observer.d.ts +301 -0
- package/dist/observation/observer.js +919 -0
- package/dist/observation/schema.d.ts +52 -0
- package/dist/observation/schema.js +154 -0
- package/dist/openapi.d.ts +2 -1
- package/dist/openapi.js +404 -93
- package/dist/paid-calls.d.ts +8 -3
- package/dist/paid-calls.js +6 -2
- package/dist/place-offers.d.ts +4 -8
- package/dist/place-offers.js +4 -9
- package/dist/port-models.d.ts +10 -2
- package/dist/port-models.js +6 -2
- package/dist/print.d.ts +4 -2
- package/dist/print.js +4 -3
- package/dist/propose.d.ts +1 -2
- package/dist/propose.js +10 -1
- package/dist/provider.d.ts +5 -1
- package/dist/provider.js +8 -0
- package/dist/push-handler.d.ts +3 -2
- package/dist/push-handler.js +20 -6
- package/dist/refusal-words.d.ts +14 -0
- package/dist/refusal-words.js +16 -2
- package/dist/run-launch.d.ts +12 -1
- package/dist/run-launch.js +13 -4
- package/dist/run-learning-served.d.ts +75 -2
- package/dist/run-manifest.d.ts +3 -0
- package/dist/run-manifest.js +13 -1
- package/dist/run-reads-over-store.d.ts +3 -3
- package/dist/run-reads-over-store.js +13 -10
- package/dist/run-timeline-served.d.ts +3 -2
- package/dist/run-timeline-served.js +8 -9
- package/dist/run-view.d.ts +44 -38
- package/dist/run-view.js +93 -56
- package/dist/runnable.d.ts +13 -5
- package/dist/runnable.js +69 -60
- package/dist/runner/adapter-loop.d.ts +48 -13
- package/dist/runner/adapter-loop.js +691 -254
- package/dist/runner/adapter-run-spec.d.ts +38 -12
- package/dist/runner/adapter-run-spec.js +175 -106
- package/dist/runner/adapters/pi.d.ts +24 -0
- package/dist/runner/adapters/pi.js +59 -9
- package/dist/runner/beside.d.ts +3 -1
- package/dist/runner/beside.js +24 -8
- package/dist/runner/claim-secrets.d.ts +3 -1
- package/dist/runner/claim-secrets.js +28 -4
- package/dist/runner/cli-run-spec.d.ts +30 -0
- package/dist/runner/cli-run-spec.js +95 -50
- package/dist/runner/computer-channel.d.ts +5 -2
- package/dist/runner/computer-channel.js +3 -2
- package/dist/runner/computer-journal.d.ts +6 -0
- package/dist/runner/computer-journal.js +8 -10
- package/dist/runner/conformance/harness.js +6 -3
- package/dist/runner/end-of-run.d.ts +2 -0
- package/dist/runner/end-of-run.js +3 -1
- package/dist/runner/feedback-round.d.ts +40 -13
- package/dist/runner/feedback-round.js +64 -16
- package/dist/runner/harness-loops.js +17 -0
- package/dist/runner/journal-kinds.d.ts +59 -13
- package/dist/runner/journal-kinds.js +48 -5
- package/dist/runner/learning-dispatch.d.ts +3 -2
- package/dist/runner/learning-dispatch.js +6 -6
- package/dist/runner/learning-end.d.ts +4 -0
- package/dist/runner/learning-end.js +64 -36
- package/dist/runner/learning-factory.d.ts +3 -0
- package/dist/runner/learning-factory.js +8 -2
- package/dist/runner/learning-loop.d.ts +2 -0
- package/dist/runner/learning-loop.js +19 -4
- package/dist/runner/loop.d.ts +18 -0
- package/dist/runner/loop.js +34 -0
- package/dist/runner/main.d.ts +6 -1
- package/dist/runner/main.js +26 -4
- package/dist/runner/mcp-run.d.ts +4 -1
- package/dist/runner/mcp-run.js +11 -5
- package/dist/runner/meta-tools.d.ts +10 -3
- package/dist/runner/meta-tools.js +112 -36
- package/dist/runner/metrics.d.ts +80 -21
- package/dist/runner/metrics.js +114 -39
- package/dist/runner/model-route.d.ts +14 -3
- package/dist/runner/model-route.js +155 -19
- package/dist/runner/monid-run.d.ts +8 -6
- package/dist/runner/monid-run.js +117 -43
- package/dist/runner/native-loop.d.ts +11 -0
- package/dist/runner/native-loop.js +438 -0
- package/dist/runner/promotion.d.ts +76 -10
- package/dist/runner/promotion.js +476 -154
- package/dist/runner/redact.js +3 -0
- package/dist/runner/reflect-hook.js +9 -0
- package/dist/runner/runner.d.ts +7 -1
- package/dist/runner/runner.js +8 -4
- package/dist/runner/sdk-loop.d.ts +7 -0
- package/dist/runner/sdk-loop.js +470 -0
- package/dist/runner/spec-holds.d.ts +16 -2
- package/dist/runner/spec-holds.js +42 -14
- package/dist/runner/store-secrets.js +17 -2
- package/dist/runner/workflow-first.d.ts +30 -20
- package/dist/runner/workflow-first.js +22 -32
- package/dist/runner/workflow-loop.d.ts +1 -1
- package/dist/runner/workflow-loop.js +18 -12
- package/dist/runner/workflow-spec.d.ts +4 -1
- package/dist/runner/workflow-spec.js +56 -45
- package/dist/runs-over-store.d.ts +30 -2
- package/dist/runs-over-store.js +46 -14
- package/dist/sdk/runs.d.ts +115 -0
- package/dist/sdk/runs.js +422 -0
- package/dist/sdk/schema.d.ts +175 -0
- package/dist/sdk/schema.js +138 -0
- package/dist/sdk/workflows.d.ts +22 -0
- package/dist/sdk/workflows.js +39 -0
- package/dist/secrets.d.ts +2 -0
- package/dist/secrets.js +19 -1
- package/dist/server.d.ts +48 -32
- package/dist/server.js +568 -137
- package/dist/skill-route.d.ts +3 -0
- package/dist/skill-route.js +16 -0
- package/dist/skills/agentrun-serve/SKILL.md +368 -0
- package/dist/stats.d.ts +10 -10
- package/dist/store/agent-body.d.ts +12 -8
- package/dist/store/agent-body.js +9 -4
- package/dist/store/dialect.d.ts +3 -0
- package/dist/store/dialect.js +1 -0
- package/dist/store/index.d.ts +1 -1
- package/dist/store/native-command-owner.d.ts +10 -0
- package/dist/store/native-command-owner.js +47 -0
- package/dist/store/postgres/connection.d.ts +11 -5
- package/dist/store/postgres/connection.js +44 -17
- package/dist/store/postgres/dialect.js +5 -0
- package/dist/store/postgres/migrations/0012_revision_monid_pin.sql +4 -0
- package/dist/store/postgres/migrations/0013_native_command_owner.sql +6 -0
- package/dist/store/postgres/migrations/0014_run_cost_upper_bound.sql +6 -0
- package/dist/store/postgres/store.d.ts +7 -3
- package/dist/store/postgres/store.js +4 -0
- package/dist/store/schema.d.ts +7 -0
- package/dist/store/schema.js +20 -1
- package/dist/store/sqlite/connection.js +72 -8
- package/dist/store/sqlite/run-launch.d.ts +11 -0
- package/dist/store/sqlite/run-launch.js +8 -0
- package/dist/store/sqlite/run-patch.d.ts +8 -1
- package/dist/store/sqlite/run-patch.js +14 -3
- package/dist/store/sqlite/store.js +170 -34
- package/dist/store/sqlite/worker.d.ts +2 -0
- package/dist/store/sqlite/worker.js +13 -10
- package/dist/store/store.d.ts +67 -7
- package/dist/store-reads/analytics.d.ts +7 -7
- package/dist/store-reads/analytics.js +23 -5
- package/dist/store-reads/cap.js +8 -6
- package/dist/store-reads/journal.d.ts +5 -0
- package/dist/store-reads/journal.js +85 -41
- package/dist/store-reads/learning.d.ts +115 -18
- package/dist/store-reads/learning.js +170 -68
- package/dist/store-reads/runs.d.ts +5 -0
- package/dist/store-reads/runs.js +3 -2
- package/dist/store-view.js +75 -21
- package/dist/template-eval.d.ts +73 -11
- package/dist/template-eval.js +535 -75
- package/dist/templates.d.ts +84 -21
- package/dist/templates.js +254 -47
- package/dist/text-urls.d.ts +38 -0
- package/dist/text-urls.js +170 -0
- package/dist/timeline/index.d.ts +3 -2
- package/dist/timeline/index.js +3 -2
- package/dist/timeline/labels.d.ts +5 -2
- package/dist/timeline/labels.js +29 -6
- package/dist/timeline/origin.d.ts +1 -1
- package/dist/timeline/origin.js +2 -2
- package/dist/timeline/render-text.js +1 -1
- package/dist/timeline/timeline.d.ts +66 -4
- package/dist/timeline/timeline.js +160 -30
- package/dist/timeline/util.d.ts +5 -0
- package/dist/timeline/util.js +44 -8
- package/dist/timeline/web-calls.d.ts +17 -0
- package/dist/timeline/web-calls.js +106 -0
- package/dist/tool-gate.d.ts +46 -44
- package/dist/tool-gate.js +101 -92
- package/dist/tool-list.d.ts +4 -1
- package/dist/tool-list.js +8 -1
- package/dist/tool-names.d.ts +18 -13
- package/dist/tool-names.js +19 -17
- package/dist/tool-plane.d.ts +17 -13
- package/dist/tool-plane.js +12 -5
- package/dist/tools.d.ts +57 -16
- package/dist/tools.js +33 -28
- package/dist/trigger-adapter.d.ts +56 -5
- package/dist/trigger-adapter.js +6 -0
- package/dist/trigger-adapters.js +3 -1
- package/dist/trigger-composio.d.ts +10 -0
- package/dist/trigger-composio.js +122 -0
- package/dist/trigger-email.d.ts +4 -0
- package/dist/trigger-email.js +181 -0
- package/dist/trigger-signatures.d.ts +6 -10
- package/dist/trigger-signatures.js +16 -16
- package/dist/trigger-targets.d.ts +1 -1
- package/dist/trigger-targets.js +4 -3
- package/dist/trigger-webhook.js +6 -4
- package/dist/triggers.d.ts +105 -8
- package/dist/triggers.js +286 -62
- package/dist/uploads.d.ts +9 -0
- package/dist/uploads.js +27 -0
- package/dist/validate.js +1 -7
- package/dist/web-fake.d.ts +56 -0
- package/dist/web-fake.js +102 -0
- package/dist/web-fetch-direct.d.ts +3 -0
- package/dist/web-fetch-direct.js +4 -1
- package/dist/web-fetch.d.ts +5 -1
- package/dist/web-fetch.js +8 -31
- package/dist/web-search.d.ts +51 -2
- package/dist/web-search.js +116 -18
- package/dist/webhooks.d.ts +2 -1
- package/dist/webhooks.js +5 -1
- package/dist/workflow/decision-recovery.js +5 -2
- package/dist/workflow/decisions.d.ts +7 -0
- package/dist/workflow/node-runner.js +10 -2
- package/dist/workspace/archil-claim.d.ts +3 -0
- package/dist/workspace/archil-claim.js +9 -2
- package/dist/workspace/computer-deps.d.ts +22 -9
- package/dist/workspace/computer-deps.js +78 -37
- package/dist/workspace/computer-for-claim.d.ts +54 -4
- package/dist/workspace/computer-for-claim.js +179 -39
- package/dist/workspace/computer-janitor.d.ts +10 -3
- package/dist/workspace/computer-janitor.js +96 -29
- package/dist/workspace/computer-kept.d.ts +82 -0
- package/dist/workspace/computer-kept.js +147 -0
- package/dist/workspace/computer-mcp.js +4 -3
- package/dist/workspace/computer-ports.d.ts +23 -3
- package/dist/workspace/computer-ports.js +115 -5
- package/dist/workspace/index.d.ts +1 -2
- package/dist/workspace/index.js +1 -2
- package/dist/workspace/kind-skills/desktop/SKILL.md +25 -18
- package/dist/workspace/kind-skills/phone/SKILL.md +28 -17
- package/dist/workspace/resolve-computer.d.ts +15 -3
- package/dist/workspace/resolve-computer.js +10 -7
- package/dist/workspace/revision-skills.d.ts +6 -2
- package/dist/workspace/revision-skills.js +12 -5
- package/dist/workspace/run-end-computers.d.ts +30 -0
- package/dist/workspace/run-end-computers.js +137 -0
- package/dist/workspace/run-tools.d.ts +28 -29
- package/dist/workspace/run-tools.js +29 -30
- package/dist/wrap-up.d.ts +19 -5
- package/dist/wrap-up.js +31 -4
- package/package.json +13 -9
- package/skills/agentrun-serve/SKILL.md +248 -10
- package/templates/README.md +117 -23
- package/templates/TOOLS.md +168 -0
- package/templates/code-review/agent.md +18 -4
- package/templates/code-review/evals/mentions-defused/case.yaml +1 -1
- package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +2 -1
- package/templates/code-review/evals/other-repo/case.yaml +1 -1
- package/templates/code-review/evals/pasted-by-reference/case.yaml +5 -0
- package/templates/code-review/evals/pasted-by-reference/graders/by-reference.md +15 -0
- package/templates/code-review/evals/pasted-by-reference/graders/head-sha.md +6 -0
- package/templates/code-review/evals/pasted-by-reference/prompt.md +31 -0
- package/templates/code-review/skills/review/DEEP.md +2 -2
- package/templates/code-review/skills/review/REVIEWER.md +2 -2
- package/templates/code-review/skills/review/SKILL.md +7 -3
- package/templates/release-notes/evals/draft-not-publish/case.yaml +1 -1
- package/templates/release-notes/evals/issue-write-refused/case.yaml +1 -1
- package/templates/release-notes/evals/late-arrival/case.yaml +1 -1
- package/templates/release-notes/evals/other-repo/case.yaml +1 -1
- package/dist/console/assets/index-CjqQirbo.css +0 -1
- package/dist/console/assets/index-b6-XY5A9.js +0 -576
- package/dist/host-calls.d.ts +0 -20
- package/dist/host-calls.js +0 -12
- package/dist/runner/adapters/pi-computer.d.ts +0 -9
- package/dist/runner/adapters/pi-computer.js +0 -51
- package/dist/workspace/computer-script.d.ts +0 -53
- package/dist/workspace/computer-script.js +0 -172
|
@@ -9,21 +9,22 @@ import { posix } from "node:path";
|
|
|
9
9
|
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
10
10
|
import { currentLearning, holdsForOk, LEARNING_REASONS } from "../learning.js";
|
|
11
11
|
import { runLearningBody } from "../learning-routes.js";
|
|
12
|
-
import { learningStartOf, readLaunchBody, seedFailed } from "../run-launch.js";
|
|
12
|
+
import { learningStartOf, learningStartOfStored, readLaunchBody, seedFailed } from "../run-launch.js";
|
|
13
13
|
import { said, STOPPED } from "../learning-words.js";
|
|
14
14
|
import { learningImpact, noteRuns, notesRead } from "../learning-run.js";
|
|
15
15
|
import { costSummary, RUN_PATHS, runCostOf } from "../learning-cost.js";
|
|
16
|
-
import { runPathOf, workflowNameOf } from "../runner/learning-end.js";
|
|
16
|
+
import { modelsOwn, runPathOf, workflowNameOf } from "../runner/learning-end.js";
|
|
17
|
+
import { feedbackStatus } from "../runner/feedback-round.js";
|
|
17
18
|
import { PAST_RUNS, servedAnswerOf, servedAnswerStands, servedOf, workflowCostsOf } from "../runner/workflow-first.js";
|
|
18
19
|
import { reflects } from "../reflect-range.js";
|
|
19
20
|
import { notesOf } from "../usage.js";
|
|
20
21
|
import { runEntries, runReflect, runTimeline, withoutFeedbackRounds } from "./journal.js";
|
|
21
|
-
import { FINAL_STATES } from "../store/store.js";
|
|
22
|
+
import { FINAL_STATES, StoreLaunchMissing } from "../store/store.js";
|
|
22
23
|
import { journalEntries } from "../runner/journal-reader.js";
|
|
23
24
|
import { KINDS } from "../runner/journal-kinds.js";
|
|
24
25
|
import { keptOf, learnedOf, lostOf } from "../runner/learning-loop.js";
|
|
25
26
|
import { promotedOf } from "../learn/compile.js";
|
|
26
|
-
import { promotionsOf } from "../learn/promote.js";
|
|
27
|
+
import { championOf, gradesOf, gradeView, promotionsOf, withinBar } from "../learn/promote.js";
|
|
27
28
|
import { GENERAL_NO_BUDGET, GENERAL_NO_ROOM, GENERAL_UNCHECKED } from "../learn/general.js";
|
|
28
29
|
const timeOf = (ms) => new Date(ms).toISOString();
|
|
29
30
|
const usdOrNull = (value) => (typeof value === "number" && Number.isFinite(value) ? value : null);
|
|
@@ -33,13 +34,48 @@ function answeredOf(row) {
|
|
|
33
34
|
return {};
|
|
34
35
|
return { answered_at: row.answered_at, job_cost_usd: usdOrNull(row.job_cost_usd), look_back_usd: usdOrNull(row.look_back_usd) };
|
|
35
36
|
}
|
|
36
|
-
/**
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
/** Agent `agentId`'s runs' records read at once, whatever their number: its runs' launches (Store.runs.launches) and every
|
|
38
|
+
* round its runs' learning kept with the learning runs they name (Store.learning.kept), two reads beside `listed` (its
|
|
39
|
+
* runs, as runs.list read them). Each answers as the store's per-run read does: a run of `listed` with no launch row is
|
|
40
|
+
* StoreLaunchMissing, one that kept no learning has no round. A run not of `listed` is read from the store. */
|
|
41
|
+
export async function agentRecordsOf(store, agentId, listed) {
|
|
42
|
+
const [starts, kept] = await Promise.all([store.runs.learningStarts(agentId), store.learning.kept(agentId)]);
|
|
43
|
+
const ours = new Set(listed.map((run) => run.id));
|
|
44
|
+
const startOf = new Map(starts.map((row) => [row.runId, row.learning]));
|
|
45
|
+
// Each run's rounds, oldest first (the store reads them so).
|
|
46
|
+
const rounds = new Map();
|
|
47
|
+
for (const one of kept.proposals)
|
|
48
|
+
rounds.set(one.runId, [...(rounds.get(one.runId) ?? []), one]);
|
|
49
|
+
const rows = new Map([...listed, ...kept.learningRuns].map((run) => [run.id, run]));
|
|
50
|
+
return {
|
|
51
|
+
runs: {
|
|
52
|
+
launch: (runId) => store.runs.launch(runId),
|
|
53
|
+
learningStart: async (runId) => {
|
|
54
|
+
if (!ours.has(runId))
|
|
55
|
+
return learningStartOfRun(store, runId);
|
|
56
|
+
if (!startOf.has(runId))
|
|
57
|
+
throw new StoreLaunchMissing(runId);
|
|
58
|
+
return learningStartOfStored(startOf.get(runId));
|
|
59
|
+
},
|
|
60
|
+
get: async (id) => rows.get(id) ?? store.runs.get(id),
|
|
61
|
+
},
|
|
62
|
+
learning: {
|
|
63
|
+
proposal: async (runId, round) => {
|
|
64
|
+
if (!ours.has(runId))
|
|
65
|
+
return store.learning.proposal(runId, round);
|
|
66
|
+
const list = rounds.get(runId);
|
|
67
|
+
return round === undefined ? list?.at(-1) : list?.find((one) => one.round === round);
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/** Run `runId`'s learning end (its newest round's, or round `round`'s); null when the run kept no learning. Proposed while its learning run has not ended. `records`: where its rows are read (the store's per-run reads by default). */
|
|
73
|
+
export async function runLearningEnd(store, runId, round, records = store) {
|
|
74
|
+
const kept = await records.learning.proposal(runId, round);
|
|
39
75
|
if (!kept)
|
|
40
76
|
return null;
|
|
41
77
|
const row = (kept.proposal ?? {});
|
|
42
|
-
return { ...(await endOfKept(store, kept, row)), ...answeredOf(row), ...compiledOf(row) };
|
|
78
|
+
return { ...(await endOfKept(store, kept, row, records)), ...answeredOf(row), ...compiledOf(row) };
|
|
43
79
|
}
|
|
44
80
|
/** What a kept row says of its compile turn (runner/reflect-hook.ts): the record, and a failed draft's errors; read as
|
|
45
81
|
* untrusted, an entry out of shape left out. */
|
|
@@ -58,7 +94,7 @@ function compiledOf(row) {
|
|
|
58
94
|
return out;
|
|
59
95
|
}
|
|
60
96
|
/** The learning end a kept row and its learning run's journal say. */
|
|
61
|
-
async function endOfKept(store, kept, row) {
|
|
97
|
+
async function endOfKept(store, kept, row, records = store) {
|
|
62
98
|
const at = timeOf(kept.createdAt);
|
|
63
99
|
// Dropped before it was proposed (a cut run, nothing to keep, the checks): its end is the kept row's.
|
|
64
100
|
if (row.state !== "proposed" || !row.proposal) {
|
|
@@ -69,14 +105,10 @@ async function endOfKept(store, kept, row) {
|
|
|
69
105
|
const proposed = { state: "proposed", reason: null, detail: row.detail ?? null, at, ...left };
|
|
70
106
|
if (!kept.learningRunId)
|
|
71
107
|
return proposed;
|
|
72
|
-
const
|
|
73
|
-
const
|
|
74
|
-
const merged = dataOf(KINDS.learningMerged);
|
|
75
|
-
const dropped = dataOf(KINDS.learningDropped);
|
|
108
|
+
const learningRun = await records.runs.get(kept.learningRunId);
|
|
109
|
+
const { merged, dropped, graded } = await learningEndEntries(store, kept.learningRunId, learningRun);
|
|
76
110
|
if (!merged && !dropped)
|
|
77
111
|
return proposed;
|
|
78
|
-
const graded = dataOf(KINDS.learningGraded);
|
|
79
|
-
const learningRun = await store.runs.get(kept.learningRunId);
|
|
80
112
|
const endedAt = learningRun?.endedAt ? timeOf(learningRun.endedAt) : at;
|
|
81
113
|
// What the grade spent: the graded entry's, or what a grade that failed spent before it did.
|
|
82
114
|
const spent = graded ?? (dropped && "usd" in dropped ? { usd: dropped.usd ?? null, tokens: dropped.tokens ?? null } : undefined);
|
|
@@ -109,14 +141,33 @@ async function endOfKept(store, kept, row) {
|
|
|
109
141
|
/** GET /stats's learning counts from the one store, over the runs `filter` picks as the analytics pick them (not archived,
|
|
110
142
|
* their own or their agent's; started in [from, to); of `agent`): an agentic run with a learning end counts, its end
|
|
111
143
|
* read as the run's view reads it (runLearningEnd). A workflow's run, and one with no learning, is not counted; nor is
|
|
112
|
-
* one whose reason this server does not give (an older server's). An imported run keeps no learning in the store.
|
|
113
|
-
|
|
144
|
+
* one whose reason this server does not give (an older server's). An imported run keeps no learning in the store. Each
|
|
145
|
+
* agent's runs' records are read at once (agentRecordsOf; `records`, already read for `filter.agent`), never a read a run. */
|
|
146
|
+
export async function learningCountsOverStore(store, filter, records) {
|
|
114
147
|
const from = filter.from === undefined ? -Infinity : Date.parse(filter.from);
|
|
115
148
|
const to = filter.to === undefined ? Infinity : Date.parse(filter.to);
|
|
116
149
|
const out = { runs: 0, merged: 0, dropped: {}, in_progress: 0 };
|
|
117
150
|
const agentArchived = new Map();
|
|
118
151
|
const workflow = new Map();
|
|
119
|
-
|
|
152
|
+
const listed = await store.runs.list(filter.agent !== undefined ? { agentId: filter.agent } : {});
|
|
153
|
+
const byAgent = new Map();
|
|
154
|
+
for (const run of listed) {
|
|
155
|
+
const runs = byAgent.get(run.agentId);
|
|
156
|
+
if (runs)
|
|
157
|
+
runs.push(run);
|
|
158
|
+
else
|
|
159
|
+
byAgent.set(run.agentId, [run]);
|
|
160
|
+
}
|
|
161
|
+
const read = new Map();
|
|
162
|
+
const recordsOf = (agentId) => {
|
|
163
|
+
if (records && agentId === filter.agent)
|
|
164
|
+
return Promise.resolve(records);
|
|
165
|
+
let one = read.get(agentId);
|
|
166
|
+
if (!one)
|
|
167
|
+
read.set(agentId, (one = agentRecordsOf(store, agentId, byAgent.get(agentId) ?? [])));
|
|
168
|
+
return one;
|
|
169
|
+
};
|
|
170
|
+
for (const run of listed) {
|
|
120
171
|
if (filter.agent !== undefined && run.agentId !== filter.agent)
|
|
121
172
|
continue;
|
|
122
173
|
if (run.importedFrom || run.archivedAt !== null || !(run.startedAt >= from && run.startedAt < to))
|
|
@@ -129,7 +180,7 @@ export async function learningCountsOverStore(store, filter) {
|
|
|
129
180
|
workflow.set(run.revisionId, (await store.agents.revision(run.revisionId))?.kind === "workflow");
|
|
130
181
|
if (workflow.get(run.revisionId))
|
|
131
182
|
continue;
|
|
132
|
-
const learning = await runLearningEnd(store, run.id);
|
|
183
|
+
const learning = await runLearningEnd(store, run.id, undefined, await recordsOf(run.agentId));
|
|
133
184
|
// A reason this server does not give (an older server's) is not counted.
|
|
134
185
|
if (!learning || (learning.reason !== null && !LEARNING_REASONS.includes(learning.reason)))
|
|
135
186
|
continue;
|
|
@@ -153,8 +204,8 @@ export async function learningSpendOverStore(store, window) {
|
|
|
153
204
|
/** An agent's learning counts as its learning view gives them (GET /agents/{id}/learning, learning-run.ts ofAgent's
|
|
154
205
|
* counts): how its runs that tried to learn fared, less `runs`, from the one store. Its notes' runs and its impact are
|
|
155
206
|
* agentLearningOverStore's. */
|
|
156
|
-
export async function agentLearningCountsOverStore(store, agentId) {
|
|
157
|
-
const { runs: _, ...counts } = await learningCountsOverStore(store, { agent: agentId });
|
|
207
|
+
export async function agentLearningCountsOverStore(store, agentId, records) {
|
|
208
|
+
const { runs: _, ...counts } = await learningCountsOverStore(store, { agent: agentId }, records);
|
|
158
209
|
return counts;
|
|
159
210
|
}
|
|
160
211
|
/** Agent `agentId`'s learning view from the one store (GET /agents/{id}/learning, learning-run.ts ofAgent): its counts
|
|
@@ -162,22 +213,24 @@ export async function agentLearningCountsOverStore(store, agentId) {
|
|
|
162
213
|
* changed (learningImpact), never a run's files. Each run's part is read from its launch (the notes it was given,
|
|
163
214
|
* learningStartOf), its journal once final (the notes its job read, notesReadOf) and its learning end (when its job
|
|
164
215
|
* answered and what it and looking back cost, its grade's cost). `seed_notes`, the notes a run started from, is its
|
|
165
|
-
* launch's seedNotes: every note in its seed, before the budget picked the given ones (main's seed_notes).
|
|
216
|
+
* launch's seedNotes: every note in its seed, before the budget picked the given ones (main's seed_notes). Its runs'
|
|
217
|
+
* launches and learning are read at once (agentRecordsOf), and a settled run's journal once a server (settledCache):
|
|
218
|
+
* a read a run only the first time it is seen. */
|
|
166
219
|
export async function agentLearningOverStore(store, agentId) {
|
|
167
|
-
const
|
|
220
|
+
const listed = (await store.runs.list({ agentId })).filter((run) => run.agentId === agentId);
|
|
221
|
+
const records = await agentRecordsOf(store, agentId, listed);
|
|
222
|
+
const counts = await agentLearningCountsOverStore(store, agentId, records);
|
|
168
223
|
const kinds = new Map();
|
|
169
224
|
const rows = [];
|
|
170
225
|
const learnings = new Map();
|
|
171
226
|
const files = [];
|
|
172
|
-
for (const run of
|
|
173
|
-
if (run.agentId !== agentId)
|
|
174
|
-
continue;
|
|
227
|
+
for (const run of listed) {
|
|
175
228
|
if (!kinds.has(run.revisionId))
|
|
176
229
|
kinds.set(run.revisionId, (await store.agents.revision(run.revisionId))?.kind);
|
|
177
230
|
const final = FINAL_STATES.includes(run.state);
|
|
178
|
-
const started = await learningStartOfRun(
|
|
231
|
+
const started = await learningStartOfRun(records, run.id);
|
|
179
232
|
// A run that only uses what its agent learned keeps no proposal: its end is its start's (usedOnly), as its run reads give it.
|
|
180
|
-
const end = (await runLearningEnd(store, run.id)) ?? (started?.use ? usedOnly(started, final, timeOf(run.endedAt ?? run.startedAt)) : null);
|
|
233
|
+
const end = (await runLearningEnd(store, run.id, undefined, records)) ?? (started?.use ? usedOnly(started, final, timeOf(run.endedAt ?? run.startedAt)) : null);
|
|
181
234
|
const { read, laid } = await journalReadsOf(store, run, started);
|
|
182
235
|
if (started || end)
|
|
183
236
|
files.push(notesOf({ given: started?.given ?? [], read }));
|
|
@@ -189,7 +242,7 @@ export async function agentLearningOverStore(store, agentId) {
|
|
|
189
242
|
});
|
|
190
243
|
// What its claims laid of the skills and workflows it was offered (every learningLaid entry, laidOf): the run started
|
|
191
244
|
// from those alone.
|
|
192
|
-
learnings.set(run.id, end ? impactLearningOf(end, started, laid, await roundsSpendOf(
|
|
245
|
+
learnings.set(run.id, end ? impactLearningOf(end, started, laid, await roundsSpendOf(records, run.id), run.costUsd) : null);
|
|
193
246
|
}
|
|
194
247
|
return { counts, impact: learningImpact(rows, (row) => learnings.get(row.id) ?? null), notes: noteRuns(files) };
|
|
195
248
|
}
|
|
@@ -204,7 +257,10 @@ export async function agentLearningOverStore(store, agentId) {
|
|
|
204
257
|
* `limit`: the latest runs shown, each keeping its number; the summary is over every run. */
|
|
205
258
|
export async function agentCostOverStore(store, agentId, limit = Infinity) {
|
|
206
259
|
const kinds = new Map();
|
|
207
|
-
const
|
|
260
|
+
const listed = (await store.runs.list({ agentId })).filter((run) => run.agentId === agentId);
|
|
261
|
+
// Every run's launch and learning in a few reads (agentRecordsOf), never a read a run.
|
|
262
|
+
const records = await agentRecordsOf(store, agentId, listed);
|
|
263
|
+
const ended = listed.filter((run) => FINAL_STATES.includes(run.state) && !run.importedFrom && run.archivedAt === null).sort((a, b) => a.startedAt - b.startedAt || (a.id < b.id ? -1 : 1));
|
|
208
264
|
const runs = [];
|
|
209
265
|
let unknownPath = 0;
|
|
210
266
|
for (const run of ended) {
|
|
@@ -213,17 +269,30 @@ export async function agentCostOverStore(store, agentId, limit = Infinity) {
|
|
|
213
269
|
if (kinds.get(run.revisionId) === "workflow")
|
|
214
270
|
continue;
|
|
215
271
|
// A run that learns whose record names no path is left out and counted, never `agent` at $0.
|
|
216
|
-
if (!pathOfRow(run.metrics, await learningStartOfRun(
|
|
272
|
+
if (!pathOfRow(run.metrics, await learningStartOfRun(records, run.id))) {
|
|
217
273
|
unknownPath += 1;
|
|
218
274
|
continue;
|
|
219
275
|
}
|
|
220
|
-
runs.push(await costRunOf(
|
|
276
|
+
runs.push(await costRunOf(records, run, runs.length + 1));
|
|
221
277
|
}
|
|
222
278
|
// Each learned workflow that ran first, where it stands against the money rule (workflow-first.ts workflowCostsOf), over
|
|
223
279
|
// the runs the run's launch reads (pastRunsOverStore) at the all-in cost this series shows: a workflow over the line
|
|
224
280
|
// shows `needs_revision` with its two numbers, so the page and the launch's decision agree.
|
|
225
|
-
const workflows = workflowCostsOf(await pastRunsOverStore(store, agentId, new Map(runs.map((run) => [run.run_id, run.total_usd]))));
|
|
226
|
-
|
|
281
|
+
const workflows = workflowCostsOf(await pastRunsOverStore(store, agentId, new Map(runs.map((run) => [run.run_id, run.total_usd])), records));
|
|
282
|
+
const replay = servingReplayOf(await promotionsOf(store.settings, agentId), runs);
|
|
283
|
+
return { runs: runs.slice(Math.max(0, runs.length - limit)), summary: costSummary(runs, replay), total_runs: runs.length, unknown_cost_runs: runs.filter((run) => run.total_usd === null).length, unknown_path_runs: unknownPath, workflows };
|
|
284
|
+
}
|
|
285
|
+
/** The replay the serving promotion was decided on, as the cost summary says it: the champion (championOf) of the learned
|
|
286
|
+
* workflow the newest run a learned workflow ran first on ran (`workflow` or `handed_back`), its record's `replay` numbers
|
|
287
|
+
* and whether they cleared the bar (withinBar, promotion's own). Null when no run was served, nothing serves now (held,
|
|
288
|
+
* or never promoted), or it was promoted with no replay (a dry run). */
|
|
289
|
+
export function servingReplayOf(records, runs) {
|
|
290
|
+
const name = runs.findLast((run) => (run.path === "workflow" || run.path === "handed_back") && run.workflow !== null)?.workflow;
|
|
291
|
+
const score = name ? championOf(records, name)?.replay : undefined;
|
|
292
|
+
if (!score)
|
|
293
|
+
return null;
|
|
294
|
+
const pct = (acc) => Math.round(acc * 1000) / 10;
|
|
295
|
+
return { n: score.n, workflow_pct: pct(score.wf_acc), agent_pct: pct(score.agent_acc), cleared: withinBar(score) };
|
|
227
296
|
}
|
|
228
297
|
/** What run `runId`'s learning spent, as its cost per run counts it, over every round a follow-up opened (roundsOf): what
|
|
229
298
|
* it kept as it answered (`looked`: answeredOf), and its grades' spend (`grade`): each round's learning run's cost once
|
|
@@ -237,10 +306,8 @@ export async function learningSpendOf(store, runId, rowUsd) {
|
|
|
237
306
|
if (!rounds.length)
|
|
238
307
|
return { looked: null, grade: 0 };
|
|
239
308
|
const spent = await roundsSpentOf(store, rounds);
|
|
240
|
-
const
|
|
241
|
-
|
|
242
|
-
return { looked: roundsLooked({ answered_at: first.answered_at, job_cost_usd: first.job_cost_usd ?? null, look_back_usd: spent.look, grade_usd: spent.grade }, rowUsd), grade: spent.grade };
|
|
243
|
-
return { looked: answeredOf((rounds.at(-1).proposal ?? {})), grade: spent.grade };
|
|
309
|
+
const more = roundsSpendIn(rounds, spent);
|
|
310
|
+
return { looked: more ? roundsLooked(more, rowUsd) : answeredOf((rounds.at(-1).proposal ?? {})), grade: spent.grade };
|
|
244
311
|
}
|
|
245
312
|
/** Every round run `runId` kept (one a follow-up opened again is a round past its first), oldest first: none when it kept
|
|
246
313
|
* no learning. The store's proposal(runId) is the newest round alone; a read of what the run's learning did or spent
|
|
@@ -291,13 +358,16 @@ export async function costRunOf(store, run, n) {
|
|
|
291
358
|
const started = await learningStartOfRun(store, run.id);
|
|
292
359
|
// Its figures are what the batch reads: a run with no path named is placed as the agent's here, and left out by the series.
|
|
293
360
|
const { path, workflow } = pathOfRow(run.metrics, started) ?? { path: "agent", workflow: null };
|
|
294
|
-
|
|
361
|
+
const { cost_usd, learning_usd, total_usd } = await allInOf(store, run);
|
|
362
|
+
// The run row's stored bound (RunRow.costAtMostUsd, written with a null cost_usd): its cost counts a request cut at what its cap held.
|
|
363
|
+
const cost_upper_bound = typeof run.costAtMostUsd === "number";
|
|
364
|
+
return { n, run_id: run.id, started_at: new Date(run.startedAt).toISOString(), path, workflow, learned_revision: started?.seed ?? null, cost_usd, cost_upper_bound, learning_usd, total_usd };
|
|
295
365
|
}
|
|
296
366
|
/** The runs the money rule reads for agent `agentId` (runner/workflow-first.ts costLineOf), one set for the run's launch
|
|
297
367
|
* and the cost page: of its newest PAST_RUNS runs, each that ended (ended, stopped or failed), is neither imported nor
|
|
298
368
|
* archived nor a workflow revision's run, with its all-in cost (allInOf). `known`: all-in costs already read, by run id
|
|
299
|
-
* (the cost page's series), read again for no run. */
|
|
300
|
-
export async function pastRunsOverStore(store, agentId, known) {
|
|
369
|
+
* (the cost page's series), read again for no run; `records`, where any other's rows are read (the store's by default). */
|
|
370
|
+
export async function pastRunsOverStore(store, agentId, known, records = store) {
|
|
301
371
|
const kinds = new Map();
|
|
302
372
|
const kept = [];
|
|
303
373
|
for (const run of await store.runs.list({ agentId, limit: PAST_RUNS })) {
|
|
@@ -311,7 +381,7 @@ export async function pastRunsOverStore(store, agentId, known) {
|
|
|
311
381
|
// A few reads a run, a batch at a time: a launch reads up to PAST_RUNS of them.
|
|
312
382
|
const past = [];
|
|
313
383
|
for (let at = 0; at < kept.length; at += 16) {
|
|
314
|
-
past.push(...(await Promise.all(kept.slice(at, at + 16).map(async (run) => ({ metrics: run.metrics, startedAt: run.startedAt, allInUsd: known?.has(run.id) ? known.get(run.id) : (await allInOf(
|
|
384
|
+
past.push(...(await Promise.all(kept.slice(at, at + 16).map(async (run) => ({ metrics: run.metrics, startedAt: run.startedAt, allInUsd: known?.has(run.id) ? known.get(run.id) : (await allInOf(records, run)).total_usd })))));
|
|
315
385
|
}
|
|
316
386
|
return past;
|
|
317
387
|
}
|
|
@@ -338,7 +408,7 @@ export async function runPathOverStore(store, runId, started, redact) {
|
|
|
338
408
|
// runner's `redact`, adapter-loop.ts servedAnswerText): an agent that says it again leaves the path the workflow's.
|
|
339
409
|
const answer = servedAnswerOf(entries)?.answer ?? "";
|
|
340
410
|
const alone = served.outcome === "answered" && servedAnswerStands(answer, rows, redact ? redact(answer) : undefined);
|
|
341
|
-
return { path: alone ? "workflow" : "handed_back", workflow: served.workflow, ...(served.digest ? { digest: served.digest } : {}) };
|
|
411
|
+
return { path: alone ? "workflow" : "handed_back", workflow: served.workflow, ...(served.digest ? { digest: served.digest } : {}), ...(served.promotion !== undefined ? { promotion: served.promotion } : {}) };
|
|
342
412
|
}
|
|
343
413
|
const path = runPathOf(rows);
|
|
344
414
|
// Only a name the launch offered: a call's raw `name` (a failed call's included) is the model's text, never shown.
|
|
@@ -374,24 +444,40 @@ async function journalReadsOf(store, run, started) {
|
|
|
374
444
|
}
|
|
375
445
|
/** `name` when it is one of the learned workflows the run's launch offered, else null. */
|
|
376
446
|
const offeredName = (name, offered) => (name !== null && offered?.includes(name) ? name : null);
|
|
377
|
-
/** What a settled run's journal tells the agent's learning view, kept by store and run id with the run's epoch: a claim
|
|
378
|
-
* and a run's end each move the epoch, and only a claim writes to its journal, so a settled run's reads hold until the
|
|
379
|
-
* next claim of it. At most SETTLED_READS_MAX runs a store, the oldest read dropped first. */
|
|
380
|
-
const settledReads = new WeakMap();
|
|
381
447
|
const SETTLED_READS_MAX = 4096;
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
const
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
448
|
+
/** A cache of what a settled run's journal says, by store and run id with the run's epoch (see above), at most
|
|
449
|
+
* SETTLED_READS_MAX runs a store, the oldest read dropped first. A read in flight is kept too, so two reads of the
|
|
450
|
+
* agent at once (its page and its tab) walk a run's journal once; one that fails is dropped, for the next to read. */
|
|
451
|
+
function settledCache() {
|
|
452
|
+
const byStore = new WeakMap();
|
|
453
|
+
return (store, runId, epoch, read) => {
|
|
454
|
+
const runs = byStore.get(store) ?? new Map();
|
|
455
|
+
byStore.set(store, runs);
|
|
456
|
+
const kept = runs.get(runId);
|
|
457
|
+
if (kept && kept.epoch === epoch)
|
|
458
|
+
return kept.value;
|
|
459
|
+
const value = read();
|
|
460
|
+
const entry = { epoch, value };
|
|
461
|
+
runs.delete(runId);
|
|
462
|
+
runs.set(runId, entry);
|
|
463
|
+
if (runs.size > SETTLED_READS_MAX)
|
|
464
|
+
runs.delete(runs.keys().next().value);
|
|
465
|
+
value.catch(() => { if (runs.get(runId) === entry)
|
|
466
|
+
runs.delete(runId); });
|
|
467
|
+
return value;
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
const settledJournalReads = settledCache();
|
|
471
|
+
const settledLearningEnds = settledCache();
|
|
472
|
+
/** Learning run `id`'s end entries (`run`: its row): read once it is final and kept (settledCache), so an agent's
|
|
473
|
+
* learning view reads each of its learning runs' journals once, not at every read; read now while it runs. */
|
|
474
|
+
async function learningEndEntries(store, id, run) {
|
|
475
|
+
const read = async () => {
|
|
476
|
+
const entries = await journalEntries(store.readJournal(id), BACKGROUND_CONTEXT);
|
|
477
|
+
const dataOf = (kind) => entries.find((entry) => entry.kind === kind)?.data;
|
|
478
|
+
return { merged: dataOf(KINDS.learningMerged), dropped: dataOf(KINDS.learningDropped), graded: dataOf(KINDS.learningGraded) };
|
|
479
|
+
};
|
|
480
|
+
return run && FINAL_STATES.includes(run.state) ? settledLearningEnds(store, id, run.epoch, read) : read();
|
|
395
481
|
}
|
|
396
482
|
/** What every claim of a run laid, from its learningLaid entries, each name once: a resumed claim finds an earlier
|
|
397
483
|
* claim's skill folders there already and lays none of them again, though the run still has them. None laid when it has
|
|
@@ -423,13 +509,11 @@ export function roundsLooked(rounds, rowUsd) {
|
|
|
423
509
|
}
|
|
424
510
|
export async function roundsSpendOf(store, runId) {
|
|
425
511
|
const rounds = await roundsOf(store, runId);
|
|
426
|
-
|
|
427
|
-
return undefined;
|
|
428
|
-
const { first, look, grade } = await roundsSpentOf(store, rounds);
|
|
429
|
-
if (!first || typeof first.answered_at !== "string")
|
|
430
|
-
return undefined;
|
|
431
|
-
return { answered_at: first.answered_at, job_cost_usd: first.job_cost_usd ?? null, look_back_usd: look, grade_usd: grade };
|
|
512
|
+
return rounds.length < 2 ? undefined : roundsSpendIn(rounds, await roundsSpentOf(store, rounds));
|
|
432
513
|
}
|
|
514
|
+
/** The one reader of a run's rounds' spend (roundsSpendOf, learningSpendOf): undefined for fewer than two rounds, or when
|
|
515
|
+
* the first one's answer time is unknown. */
|
|
516
|
+
const roundsSpendIn = (rounds, { first, look, grade }) => rounds.length > 1 && first && typeof first.answered_at === "string" ? { answered_at: first.answered_at, job_cost_usd: first.job_cost_usd ?? null, look_back_usd: look, grade_usd: grade } : undefined;
|
|
433
517
|
/** What a run's learning end tells its impact, as ofAgent's learningOf read a held run: how it ended and when, the notes
|
|
434
518
|
* it started from; when its job answered and its costs once it looked back (a look-back of 0 for an ended one that did
|
|
435
519
|
* not); its grade's cost once it ended (0 when nothing was graded). */
|
|
@@ -549,7 +633,8 @@ function readsSkill(call, name) {
|
|
|
549
633
|
export function learnedUseOf(started, reflect, rows, args = new Map(), laid = { skills: [] }, loads = []) {
|
|
550
634
|
const job = rows.filter((row) => !reflects(reflect, row.id));
|
|
551
635
|
const results = new Map(job.flatMap((row) => (row.kind === "tool_result" && row.tool_use_id ? [[row.tool_use_id, row.tool_status]] : [])));
|
|
552
|
-
const
|
|
636
|
+
const models = modelsOwn(job);
|
|
637
|
+
const calls = job.filter((row) => row.kind === "tool_use" && models(row) && row.tool_use_id).flatMap((row) => {
|
|
553
638
|
const call = args.get(row.tool_use_id);
|
|
554
639
|
return call ? [{ id: row.tool_use_id, ...call }] : [];
|
|
555
640
|
});
|
|
@@ -579,6 +664,9 @@ export function withNotes(end, started, read) {
|
|
|
579
664
|
/** Run `runId`'s learning start as its launch records it (run-launch.ts learningStartOf, the one reader): its given notes,
|
|
580
665
|
* its seed sha and its # Learned section; undefined when the run does not learn or has no launch. */
|
|
581
666
|
async function learningStartOfRun(store, runId) {
|
|
667
|
+
// The agent's narrow read (agentRecordsOf) answers when the run is in it; a missing launch reads as a run that does not learn.
|
|
668
|
+
if (store.runs.learningStart)
|
|
669
|
+
return store.runs.learningStart(runId).catch(() => undefined);
|
|
582
670
|
const row = await store.runs.launch(runId).catch(() => undefined);
|
|
583
671
|
const launch = row ? readLaunchBody(row.body) : undefined;
|
|
584
672
|
return launch ? learningStartOf(launch) : undefined;
|
|
@@ -619,5 +707,19 @@ export async function runLearningOverStore(store, runId, shown, secrets, statuse
|
|
|
619
707
|
const read = started?.given.length ? notesReadOf(started.given, reflect, rows) : [];
|
|
620
708
|
const learning = withNotes(end, started, read);
|
|
621
709
|
const current = holdsForOk(learning) && row && statuses ? currentLearning(learning, await statuses(row.agentId)) : learning;
|
|
622
|
-
|
|
710
|
+
const body = runLearningBody({ id: runId, learning: current, seed: started?.seed ?? null, settled, used: learnedUseOf(started, reflect, rows, callArgsOf(entries), laidOf(entries), nativeSkillLoads(entries)) }, shown, secrets);
|
|
711
|
+
// The run's own grade (PUT /runs/{id}/grade), as its agent keeps it and the PUT answered it, with the round it opened.
|
|
712
|
+
// Never its `expected` (a person's words, uncut), nor its label (not kept). Its workflow's name is cut as every other
|
|
713
|
+
// learning name is (`shown.name`): a secret registered after the grade never shows here.
|
|
714
|
+
const grade = row ? (await gradesOf(store.settings, row.agentId).catch(() => [])).find((one) => one.run === runId) : undefined;
|
|
715
|
+
if (!grade)
|
|
716
|
+
return body;
|
|
717
|
+
const { expected: _, ...graded } = gradeView(grade);
|
|
718
|
+
// How that round stands, from the run's journal and its steer's row (feedbackStatus: its words taken, then the run's
|
|
719
|
+
// end; or the steer refused by an end that came first), never the API server's `graded_at` against the runner's
|
|
720
|
+
// `ended_at`. A journal or a row that can't be read fails the read (the console retries it), never says running.
|
|
721
|
+
// null for a grade that opened none.
|
|
722
|
+
const command = grade.feedback ? grade.feedbackCommand : undefined;
|
|
723
|
+
const status = command === undefined ? null : feedbackStatus(used ? entries : await runEntries(store, runId, BACKGROUND_CONTEXT), await store.commands(runId, command - 1).then((rows) => rows.find((one) => one.id === command)));
|
|
724
|
+
return { ...body, graded: { ...graded, workflow: graded.workflow === null ? null : shown.name(graded.workflow), feedback_status: status } };
|
|
623
725
|
}
|
|
@@ -14,7 +14,12 @@ export interface RunRowView {
|
|
|
14
14
|
readonly state: RunReadState;
|
|
15
15
|
readonly startedAt: string;
|
|
16
16
|
readonly endedAt?: string;
|
|
17
|
+
/** What the run cost (a run still going: its booked-so-far spend); absent when unknown, and absent when an ended run's
|
|
18
|
+
* stored cost is only the most it can have cost (`costAtMostUsd`), as the store's row reads it (RunRow.costUsd). */
|
|
17
19
|
readonly costUsd?: number;
|
|
20
|
+
/** An ended run's stored cost when that is the most it can have cost, not its cost (RunRow.costAtMostUsd): said "at
|
|
21
|
+
* most", never summed as spend. Absent otherwise. */
|
|
22
|
+
readonly costAtMostUsd?: number;
|
|
18
23
|
readonly summary?: string;
|
|
19
24
|
readonly archivedAt?: string;
|
|
20
25
|
readonly importedFrom?: ImportedFrom;
|
package/dist/store-reads/runs.js
CHANGED
|
@@ -37,6 +37,7 @@ function viewOf(run, agentArchivedAt, kind, cost) {
|
|
|
37
37
|
startedAt: isoOf(run.startedAt),
|
|
38
38
|
...(over && run.endedAt !== null ? { endedAt: isoOf(run.endedAt) } : {}),
|
|
39
39
|
...(cost !== null ? { costUsd: cost } : {}),
|
|
40
|
+
...(over && run.costAtMostUsd !== null ? { costAtMostUsd: run.costAtMostUsd } : {}),
|
|
40
41
|
...(over && run.summary !== null ? { summary: run.summary } : {}),
|
|
41
42
|
...(archivedAt !== null ? { archivedAt: isoOf(archivedAt) } : {}),
|
|
42
43
|
...(run.importedFrom !== null ? { importedFrom: { source: run.importedFrom.source, session: run.importedFrom.session } } : {}),
|
|
@@ -52,8 +53,8 @@ function joins(store, context) {
|
|
|
52
53
|
agentArchived.set(run.agentId, (await store.agents.get(run.agentId))?.archivedAt ?? null);
|
|
53
54
|
if (!kinds.has(run.revisionId))
|
|
54
55
|
kinds.set(run.revisionId, (await store.agents.revision(run.revisionId))?.kind ?? "agentic");
|
|
55
|
-
// A run that has not ended shows
|
|
56
|
-
//
|
|
56
|
+
// A run that has not ended shows what it has spent so far over the journal (spentOverStore: never the hold of a step
|
|
57
|
+
// still running), since cost_usd is written only at the end; an ended run shows its stored cost.
|
|
57
58
|
const cost = runReadState(run, kinds.get(run.revisionId)) === "running" ? await spentOverStore(store, run.id, context) : run.costUsd;
|
|
58
59
|
return viewOf(run, agentArchived.get(run.agentId), kinds.get(run.revisionId), cost);
|
|
59
60
|
},
|