@parcha/agentrun-serve 0.1.0-beta.38 → 0.1.0-beta.39
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 +418 -0
- package/README.md +325 -124
- 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-BNhZs-jp.css +1 -0
- package/dist/console/assets/index-BQv5aOGB.js +700 -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 +84 -0
- package/dist/email/account.js +159 -0
- package/dist/email/answer.d.ts +10 -0
- package/dist/email/answer.js +182 -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 +380 -0
- package/dist/email/names.d.ts +20 -0
- package/dist/email/names.js +40 -0
- package/dist/email/routes.d.ts +9 -0
- package/dist/email/routes.js +50 -0
- package/dist/email/tools.d.ts +20 -0
- package/dist/email/tools.js +517 -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 +9 -2
- package/dist/learn/compile.js +52 -16
- package/dist/learn/grade.d.ts +4 -0
- package/dist/learn/grade.js +4 -1
- package/dist/learn/promote.d.ts +106 -51
- package/dist/learn/promote.js +82 -189
- 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 +26 -8
- package/dist/learning-cost.js +17 -7
- 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 +33 -2
- package/dist/local-models.js +43 -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 +1 -0
- package/dist/openapi.js +394 -85
- 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 +7 -2
- package/dist/port-models.js +5 -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 +11 -0
- package/dist/refusal-words.js +13 -2
- package/dist/run-launch.d.ts +10 -1
- package/dist/run-launch.js +11 -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 +42 -35
- package/dist/run-view.js +79 -44
- package/dist/runnable.d.ts +13 -5
- package/dist/runnable.js +69 -60
- package/dist/runner/adapter-loop.d.ts +42 -11
- package/dist/runner/adapter-loop.js +651 -247
- package/dist/runner/adapter-run-spec.d.ts +37 -12
- package/dist/runner/adapter-run-spec.js +139 -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 +94 -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 +37 -13
- package/dist/runner/journal-kinds.js +9 -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 +12 -3
- package/dist/runner/model-route.js +139 -18
- 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 +74 -8
- package/dist/runner/promotion.js +365 -124
- 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 +554 -130
- 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/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/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.js +3 -0
- package/dist/store/schema.d.ts +7 -0
- package/dist/store/schema.js +20 -1
- 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 +133 -18
- package/dist/store/store.d.ts +52 -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 +85 -5
- package/dist/store-reads/learning.js +45 -17
- 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 +70 -20
- package/dist/templates.js +191 -34
- 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 +42 -42
- package/dist/tool-gate.js +97 -91
- 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 +44 -16
- package/dist/tools.js +28 -28
- package/dist/trigger-adapter.d.ts +85 -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 +228 -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 +94 -9
- package/dist/triggers.js +263 -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/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
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
import { BROWSER_OPENERS, BROWSER_STEPS, callFailed, endsTurn, failedWith, inputPreview, labelOf, outcomeOf, refusedLabel, savedPaths, saysFailure } from "./labels.js";
|
|
2
2
|
import { cut, firstLine, firstSentence, json, obj, saidSummary, scrubUrls, str, utf8Bytes } from "./util.js";
|
|
3
3
|
import { BESIDE_SUFFIX, NOTE_SUFFIX, originMatcher, TRIGGER_LABELS } from "./origin.js";
|
|
4
|
+
import { webShownOf, webWithin } from "./web-calls.js";
|
|
5
|
+
/** The call a nested call (the kernel's NestedCalls: a script's, tools_call's) was made in, read off its id
|
|
6
|
+
* (`<callId>/<key>`); undefined for a call the model made itself. */
|
|
7
|
+
export const nestingCallOf = (callId) => {
|
|
8
|
+
const at = callId.lastIndexOf("/");
|
|
9
|
+
return at > 0 ? callId.slice(0, at) : undefined;
|
|
10
|
+
};
|
|
4
11
|
/** Grep's caps, so a row is the same on both sides. `thinking` cuts the first sentence of a thinking summary. */
|
|
5
12
|
export const CAPS = { summary: 500, preview: 500, text: 2000, thinking: 100 };
|
|
13
|
+
/** The most of a call's output a read for a grader shows (`calls`, tool_result_text): a tool's output's head, still one
|
|
14
|
+
* redaction pass of the size an answer's pieces take (key-refusal.ts ANSWER_PIECE). A web call's is not its head: a
|
|
15
|
+
* web_search's every result keeps its url, title and published date, and a web_fetch its url and title, their snippets
|
|
16
|
+
* and page text cut to fit (web-calls.ts), past this only when its urls alone pass it (25 results, long titles). */
|
|
17
|
+
export const CALL_RESULT_CHARS = 8000;
|
|
6
18
|
/** A host's marks of a model request: as it leaves (written before it does), and as its stream ends aborted. A request
|
|
7
19
|
* that answered or failed has a `pi.assistant` entry; one aborted before its first content has none; a start with no
|
|
8
20
|
* end and no entry is in flight when it is the latest, unless the run is settled, and was cut by a crash when a later
|
|
@@ -22,6 +34,10 @@ export const REQUEST_REFUSED = "agentrun.request_refused";
|
|
|
22
34
|
* call was refused before it ran (a gate's deny, a person's): `{ [CALL_REFUSED]: true }`. Its rows read as refused, the
|
|
23
35
|
* call in plain words ("Refused: write deny.md"), never as a call that ran and failed ("Wrote deny.md failed"). */
|
|
24
36
|
export const CALL_REFUSED = "agentrun.refused";
|
|
37
|
+
/** The key a host sets in a tool result's `details` when nothing ended the call and the run's end closed it (a harness's
|
|
38
|
+
* call that only nests calls, open when the run stopped: Codex's `exec`): `{ [CALL_ENDED_WITH_RUN]: true }`. It has no
|
|
39
|
+
* outcome, so its row reads interrupted with no status (`tool_status` null), never failed. */
|
|
40
|
+
export const CALL_ENDED_WITH_RUN = "agentrun.ended-with-run";
|
|
25
41
|
/** Whether pi's error for a request is the model proxy's own refusal of it for the run's spend cap, before it was sent:
|
|
26
42
|
* the proxy's JSON body after the HTTP status pi-ai puts first, read by its fields (`type` "agentrun_proxy", `code`
|
|
27
43
|
* "spend_cap_reached", as the proxy writes them), never by its words. Any other error, a provider's 400 included, is not.
|
|
@@ -29,23 +45,33 @@ export const CALL_REFUSED = "agentrun.refused";
|
|
|
29
45
|
* `error`, or the Messages client's "<api> API error (400): {...}" with them at the top (the runner's pi route speaks
|
|
30
46
|
* Messages to the session's proxy). */
|
|
31
47
|
function proxyCapRefusal(errorMessage) {
|
|
48
|
+
return proxyAnswerOf(errorMessage)?.code === "spend_cap_reached";
|
|
49
|
+
}
|
|
50
|
+
/** The code of the model proxy's answer once a ChatGPT plan's limit is reached (the kernel's PLAN_LIMIT_CODE): its words
|
|
51
|
+
* are the run's error as they are. */
|
|
52
|
+
const PLAN_LIMIT_CODE = "plan_limit_reached";
|
|
53
|
+
/** The model proxy's own answer in pi's error for a request (`type` "agentrun_proxy"), its code and words, read by its
|
|
54
|
+
* fields after the HTTP status pi-ai puts first (proxyCapRefusal says the two forms); undefined for any other error. */
|
|
55
|
+
function proxyAnswerOf(errorMessage) {
|
|
32
56
|
if (typeof errorMessage !== "string")
|
|
33
|
-
return
|
|
57
|
+
return undefined;
|
|
34
58
|
const at = errorMessage.indexOf("{");
|
|
35
59
|
if (at < 0)
|
|
36
|
-
return
|
|
60
|
+
return undefined;
|
|
37
61
|
const head = errorMessage.slice(0, at);
|
|
38
62
|
// The provider's name is any word with no space (agentrun-session today; a route's own, such as openrouter/anthropic):
|
|
39
63
|
// the body's fields, never the name, say whose refusal it is.
|
|
40
64
|
if (!/^\d{3}\s*$/.test(head) && !/^\S+ API error \(\d{3}\):\s*$/.test(head))
|
|
41
|
-
return
|
|
65
|
+
return undefined;
|
|
42
66
|
try {
|
|
43
67
|
const body = JSON.parse(errorMessage.slice(at));
|
|
44
68
|
const error = body?.error ?? body;
|
|
45
|
-
|
|
69
|
+
if (error?.type !== "agentrun_proxy")
|
|
70
|
+
return undefined;
|
|
71
|
+
return { ...(typeof error.code === "string" ? { code: error.code } : {}), ...(typeof error.message === "string" ? { message: error.message } : {}) };
|
|
46
72
|
}
|
|
47
73
|
catch {
|
|
48
|
-
return
|
|
74
|
+
return undefined;
|
|
49
75
|
}
|
|
50
76
|
}
|
|
51
77
|
/** Written right after an answer whose cost was not in when it was written (a harness's proxy books a response after
|
|
@@ -72,8 +98,13 @@ export const BROWSER_CHARGE = "browser";
|
|
|
72
98
|
* undefined for any other row: another tool's call row, whatever it carries, and the usage row. */
|
|
73
99
|
export const chargedTool = (row) => !row.usage ? undefined : row.kind === "phase" ? (row.tool_name ?? undefined) : row.kind === "tool_use" && row.tool_name !== null && BROWSER_STEPS.has(row.tool_name) ? BROWSER_CHARGE : undefined;
|
|
74
100
|
/** The spend cap's wrap-up (serve's cap.ts): the run's model was told once, near its cap, to finish (`words`, what it was
|
|
75
|
-
* told). A row of its own, the server's ("AgentRun: …"
|
|
101
|
+
* told after the note's "AgentRun server note:" label). A row of its own, the server's ("AgentRun: …", labelled once);
|
|
102
|
+
* no request, no cost. */
|
|
76
103
|
export const CAP_WRAPUP = "agentrun.cap_wrapup";
|
|
104
|
+
/** The run's model was told once, on its first request after its claim gave it a computer in place of an earlier
|
|
105
|
+
* claim's, that the old one is gone with what was on it (`words`, what it was told after the label, as the wrap-up's).
|
|
106
|
+
* A row of its own, the server's, as the wrap-up's; no request, no cost. */
|
|
107
|
+
export const COMPUTER_NOTE = "agentrun.computer_note";
|
|
77
108
|
/** A tool call with no price, run outside the run's cost and its cap (an MCP tool its owner set no price for): `tool`,
|
|
78
109
|
* `charged_by` and `call` name it. It shows as a row of its own, "not metered", and the usage row counts it
|
|
79
110
|
* (`not_metered`); it is no charge and never makes the cost unknown. */
|
|
@@ -193,6 +224,19 @@ function createMeter() {
|
|
|
193
224
|
// Answers to marked requests: those after the first mark (a request is marked before it leaves, so before its
|
|
194
225
|
// answer). Earlier answers are a run's from before requests were marked.
|
|
195
226
|
let answered = 0;
|
|
227
|
+
// Marked requests that ended with no answer on a free model (their end mark's `free`: booked a known $0), never a cost
|
|
228
|
+
// unknown: one counted once the next request leaves with no answer between (pi tried it again), and whether the latest
|
|
229
|
+
// end was one (its answer, an error's entry, may still come).
|
|
230
|
+
let freeUnanswered = 0;
|
|
231
|
+
let freeEnded = false;
|
|
232
|
+
// Marked requests cut with no answer and booked at their hold (their end mark's `atMostUsd`, runner.ts CUT_AT_HOLD):
|
|
233
|
+
// counted at that figure, the most each can have cost, never a cost unknown; and the latest end's figure while its
|
|
234
|
+
// request is still the newest (the next request's mark counts it).
|
|
235
|
+
let atMostUnanswered = 0;
|
|
236
|
+
let atMostKnown = 0;
|
|
237
|
+
let atMostEnded;
|
|
238
|
+
// Whether the latest answer's cost was counted unknown (a cut answer's): a free end mark written after it makes it $0.
|
|
239
|
+
let lastUnknown = false;
|
|
196
240
|
// Side requests (compactions, a tool's own requests), apart: one may run beside a generation. Each closes with its
|
|
197
241
|
// cost, or with an end when aborted.
|
|
198
242
|
let compactions = 0;
|
|
@@ -270,6 +314,7 @@ function createMeter() {
|
|
|
270
314
|
// The answer just before it was counted as a cost unknown: it is one still to come.
|
|
271
315
|
if (unknown > 0)
|
|
272
316
|
(unknown -= 1), pending.push(lastUnmetered);
|
|
317
|
+
lastUnknown = false;
|
|
273
318
|
}
|
|
274
319
|
else if (entry.kind === REQUEST_COST_LATE) {
|
|
275
320
|
// The answer it prices was written before its usage came in: its usage, when it has one, is that answer's tokens.
|
|
@@ -295,6 +340,13 @@ function createMeter() {
|
|
|
295
340
|
}
|
|
296
341
|
else if (entry.kind === REQUEST_STARTED) {
|
|
297
342
|
capRefusals = 0;
|
|
343
|
+
if (freeEnded)
|
|
344
|
+
freeUnanswered += 1;
|
|
345
|
+
freeEnded = false;
|
|
346
|
+
if (atMostEnded !== undefined)
|
|
347
|
+
(atMostUnanswered += 1), (atMostKnown += atMostEnded);
|
|
348
|
+
atMostEnded = undefined;
|
|
349
|
+
lastUnknown = false;
|
|
298
350
|
marked += 1;
|
|
299
351
|
inFlight = true;
|
|
300
352
|
lastClamp = clampOf(data?.clamp);
|
|
@@ -303,11 +355,22 @@ function createMeter() {
|
|
|
303
355
|
if (unsent(entry))
|
|
304
356
|
marked -= 1;
|
|
305
357
|
inFlight = false;
|
|
358
|
+
// For a request still unanswered; one written after pi's entry for it (a cut answer's) makes that answer's cost $0.
|
|
359
|
+
freeEnded = data?.free === true && marked - answered - freeUnanswered - atMostUnanswered > 0;
|
|
360
|
+
if (data?.free === true && !freeEnded && lastUnknown)
|
|
361
|
+
(unknown -= 1), (lastUnknown = false);
|
|
362
|
+
const atMost = data?.atMostUsd;
|
|
363
|
+
atMostEnded = typeof atMost === "number" && Number.isFinite(atMost) && atMost >= 0 && marked - answered - freeUnanswered - atMostUnanswered > 0 ? atMost : undefined;
|
|
306
364
|
}
|
|
307
365
|
else if (entry.kind === "pi.assistant" && message) {
|
|
308
366
|
requests += 1;
|
|
309
367
|
if (marked > 0)
|
|
310
368
|
answered += 1;
|
|
369
|
+
// Its request's free end mark came first: whatever it answered costs nothing.
|
|
370
|
+
const free = freeEnded;
|
|
371
|
+
freeEnded = false;
|
|
372
|
+
// An answer is no cut: its own cost counts, never the hold a cut mark before it named.
|
|
373
|
+
atMostEnded = undefined;
|
|
311
374
|
const name = str(message.model);
|
|
312
375
|
if (name) {
|
|
313
376
|
const key = metricName(str(message.provider) ? `${str(message.provider)}/${name}` : name);
|
|
@@ -316,7 +379,9 @@ function createMeter() {
|
|
|
316
379
|
// A request cut before its end has no final usage: its stream had reported none (the Responses API reports it at
|
|
317
380
|
// the end) or only the start (Anthropic's input and first token), never what the provider charged. Unknown.
|
|
318
381
|
const aborted = message.stopReason === "aborted";
|
|
319
|
-
|
|
382
|
+
const before = unknown;
|
|
383
|
+
addCost(free ? 0 : aborted ? undefined : obj(obj(message.usage)?.cost)?.total);
|
|
384
|
+
lastUnknown = marked > 0 && unknown > before;
|
|
320
385
|
const counted = aborted ? undefined : tokensOf(message.usage, message.stopReason === "error");
|
|
321
386
|
lastUnmetered = !counted;
|
|
322
387
|
addTokens(counted);
|
|
@@ -329,23 +394,42 @@ function createMeter() {
|
|
|
329
394
|
/** The usage row's count and cost; undefined while there is nothing to count. `settled`: nothing is running. While the
|
|
330
395
|
* cost is unknown, `so_far_usd` is the sum of the charges whose cost is known and `unpriced` how many have none: each
|
|
331
396
|
* cost no one knows (an answer or summary with none, a stopped request's, a paid tool charge), each still pending, each
|
|
332
|
-
* request cut before any answer, and each paid tool call a settled run never settled.
|
|
333
|
-
|
|
397
|
+
* request cut before any answer, and each paid tool call a settled run never settled. A request cut and booked at its
|
|
398
|
+
* hold (its end mark's `atMostUsd`) counts at that figure, the most it can have cost, kept apart from the exact
|
|
399
|
+
* charges by the kernel's rule (costOfParts): with every charge counted the cost is their sum, `upper_bound`, with the
|
|
400
|
+
* exact charges as `so_far_usd` and the holds as `unpriced` beside it; with one
|
|
401
|
+
* of no known cost, the hold is a ceiling that bounds nothing, so it joins no `so_far_usd` and counts as `unpriced`.
|
|
402
|
+
* `beside`: requests booked beside the entries (a pi run's side requests, TimelineOptions.side), joined by that rule. */
|
|
403
|
+
function usage(settled, beside, holdsUnpriced = false) {
|
|
334
404
|
// A request marked as it left with no entry for it, other than one still in flight: counted, at a cost no one knows.
|
|
335
405
|
// One in flight alone makes no row yet, so the row appears where it did before requests were marked.
|
|
336
406
|
// A settled run has nothing in flight: its last request with no entry, or its open compaction, was cut by the
|
|
337
407
|
// process that ended.
|
|
338
408
|
const open = (flying) => (flying && !settled ? 1 : 0);
|
|
339
|
-
|
|
409
|
+
// Those on a free model ended at a known $0, and those cut and booked at their hold at that figure: counted, never cut.
|
|
410
|
+
const free = freeUnanswered + (freeEnded ? 1 : 0);
|
|
411
|
+
const atMost = atMostUnanswered + (atMostEnded !== undefined ? 1 : 0);
|
|
412
|
+
const cut = marked - open(inFlight) - free - atMost > answered || compacting - (settled ? 0 : sidesOpen) > compactions;
|
|
340
413
|
// A paid tool call cut by a crash: its charge is unknown, so the cost is.
|
|
341
414
|
const cutCalls = settled ? held.size : 0;
|
|
342
415
|
const unmetered = notMetered ? { not_metered: notMetered } : {};
|
|
343
|
-
|
|
416
|
+
const sides = beside?.requests ?? 0;
|
|
417
|
+
if (!requests && !free && !atMost && !compactions && !cut && !paidCalls.size && !cutCalls && !sides)
|
|
344
418
|
return refusedAny || notMetered ? { usd: 0, requests: 0, charges: 0, ...unmetered } : undefined;
|
|
345
|
-
const count = requests + Math.max(0, marked - answered) + Math.max(compactions, compacting);
|
|
346
|
-
|
|
347
|
-
const
|
|
348
|
-
|
|
419
|
+
const count = requests + Math.max(0, marked - answered) + Math.max(compactions, compacting) + sides;
|
|
420
|
+
// The parts: the exact charges, the holds of cut requests (and how many), and the charges of no known cost.
|
|
421
|
+
const exact = known + (beside?.known ?? 0);
|
|
422
|
+
const bounded = atMostKnown + (atMostEnded ?? 0) + (beside?.bounded ?? 0);
|
|
423
|
+
const holds = atMost + (beside?.atMost ?? 0);
|
|
424
|
+
const unpriced = unknown + pending.length + Math.max(0, marked - open(inFlight) - free - atMost - answered) + Math.max(0, compacting - (settled ? 0 : sidesOpen) - compactions) + cutCalls + (beside?.unpriced ?? 0);
|
|
425
|
+
const round = (usd) => Math.round(usd * 1e6) / 1e6;
|
|
426
|
+
const charges = paidCalls.size + cutCalls;
|
|
427
|
+
// A reader that says no "at most" (TimelineOptions.holdsUnpriced) reads a hold as a cost no one knows.
|
|
428
|
+
if (unpriced > 0 || (holdsUnpriced && holds > 0))
|
|
429
|
+
return { usd: null, requests: count, charges, so_far_usd: round(exact), unpriced: unpriced + holds, ...unmetered };
|
|
430
|
+
// A bound says its exact part and how many holds it counts beside it, so a reader that joins this row with more
|
|
431
|
+
// charges (serve's costWordsOf over usageParts) never takes the hold for spend.
|
|
432
|
+
return { usd: round(exact + bounded), requests: count, charges, ...(holds > 0 ? { so_far_usd: round(exact), unpriced: holds, upper_bound: true } : {}), ...unmetered };
|
|
349
433
|
}
|
|
350
434
|
// A workflow's decision requests (Jev, Parallel), from its receipts: requests of their own, beside its entries'.
|
|
351
435
|
let decided = 0;
|
|
@@ -382,6 +466,22 @@ const blocksOf = (message) => {
|
|
|
382
466
|
const textOf = (message, type = "text", field = "text") => blocksOf(message).filter((block) => block.type === type).map((block) => str(block[field]) ?? "").join("\n").trim();
|
|
383
467
|
/** Every string a row shows goes through here: a URL keeps its origin, path and query keys, then the text is cut. */
|
|
384
468
|
const clean = (text, max) => cut(scrubUrls(text), max);
|
|
469
|
+
/** A call's arguments as `tool_input` carries them, their values already redacted (argsOf): each string cut at `max`, and
|
|
470
|
+
* each property name through `redact` too, as only this field shows them, and each number `held` names as
|
|
471
|
+
* "[redacted]". An object two of whose names come out the same is withheld whole, as "[redacted]", never one value
|
|
472
|
+
* merged over the other. */
|
|
473
|
+
const inputShown = (value, max, redact = (text) => text, held = () => false) => {
|
|
474
|
+
if (typeof value === "string")
|
|
475
|
+
return cut(value, max);
|
|
476
|
+
if (typeof value === "number" || typeof value === "bigint")
|
|
477
|
+
return held(value) ? "[redacted]" : value;
|
|
478
|
+
if (Array.isArray(value))
|
|
479
|
+
return value.map((item) => inputShown(item, max, redact, held));
|
|
480
|
+
if (!value || typeof value !== "object")
|
|
481
|
+
return value;
|
|
482
|
+
const entries = Object.entries(value).map(([key, item]) => [redact(key), inputShown(item, max, redact, held)]);
|
|
483
|
+
return new Set(entries.map(([key]) => key)).size === entries.length ? Object.fromEntries(entries) : "[redacted]";
|
|
484
|
+
};
|
|
385
485
|
/** The rows that show words as a person or the agent wrote them: cut, never scrubbed. */
|
|
386
486
|
const WHOLE = new Set(["user_message", "text_block", "final_answer"]);
|
|
387
487
|
/** An error's whole text as the host's `redact` makes it, before its first line becomes a summary or either is cut, so
|
|
@@ -447,7 +547,9 @@ function createProjector(options) {
|
|
|
447
547
|
const named = (value) => (typeof value === "string" && value ? options.path(value) : value);
|
|
448
548
|
return "path" in args || "file_path" in args ? { ...args, ...("path" in args ? { path: named(args.path) } : {}), ...("file_path" in args ? { file_path: named(args.file_path) } : {}) } : args;
|
|
449
549
|
};
|
|
450
|
-
|
|
550
|
+
/** The name a call's label reads its tool by: its catalog name when the run has one for it (options.catalog). */
|
|
551
|
+
const labelled = (tool) => options.catalog?.get(tool) ?? tool;
|
|
552
|
+
const label = (tool, args, result) => (pageChanged(tool, result) ? PAGE_CHANGED_ROW : waitedFirst(tool, result, labelOf(labelled(tool), shown(args), result, options.labels)));
|
|
451
553
|
const seen = new Set();
|
|
452
554
|
const calls = new Map();
|
|
453
555
|
// Results stored before their call (a harness bridge once wrote a result before the answer holding its call), by
|
|
@@ -548,10 +650,27 @@ function createProjector(options) {
|
|
|
548
650
|
/** Whether a result is a call's refusal before it ran: an error its host marked so in its details (CALL_REFUSED),
|
|
549
651
|
* read by that field, never by its words. */
|
|
550
652
|
const refused = (view) => view.isError && obj(view.details)?.[CALL_REFUSED] === true;
|
|
653
|
+
/** Whether a result is the run's end closing a call nothing ended (CALL_ENDED_WITH_RUN): no outcome, read by that field. */
|
|
654
|
+
const endedWithRun = (view) => view.isError && obj(view.details)?.[CALL_ENDED_WITH_RUN] === true;
|
|
551
655
|
/** A call's name on its rows: a refused one's in plain words (refusedLabel), else its label. */
|
|
552
|
-
const nameFor = (tool, args, view, result) => (refused(view) ? refusedLabel(tool, shown(args)) : label(tool, args, result));
|
|
656
|
+
const nameFor = (tool, args, view, result) => (refused(view) ? refusedLabel(labelled(tool), shown(args)) : label(tool, args, result));
|
|
553
657
|
/** The `tool_use` row of a call; `fields` is what differs between a stored call and a nested one. */
|
|
554
|
-
const useRow = (conv, rowId, callId, name, args, fields) => make("tool_use", conv, rowId, { summary: label(name, args), tool_name: name, tool_use_id: callId, tool_input_preview: inputPreview(args, caps.preview), ...fields });
|
|
658
|
+
const useRow = (conv, rowId, callId, name, args, fields) => make("tool_use", conv, rowId, { summary: label(name, args), tool_name: name, tool_use_id: callId, tool_input_preview: inputPreview(args, caps.preview), ...inputOf(args), ...fields });
|
|
659
|
+
/** A `calls` read's `tool_input` (inputShown); none when the arguments themselves are withheld. */
|
|
660
|
+
const inputOf = (args) => {
|
|
661
|
+
const shown = options.calls ? obj(inputShown(args, caps.text, options.redact, options.calls.held)) : undefined;
|
|
662
|
+
return shown ? { tool_input: shown } : {};
|
|
663
|
+
};
|
|
664
|
+
/** A call's output as a `calls` read shows it (tool_result_text): redacted by its redactor, else the rows' own, its
|
|
665
|
+
* URLs' query values elided, cut at `calls.result`; a web call's every url whole, only its long texts cut (web-calls.ts). */
|
|
666
|
+
const wholeRedact = options.calls?.redact ?? options.redact;
|
|
667
|
+
const callShown = (text) => scrubUrls(wholeRedact ? wholeRedact(text) : text);
|
|
668
|
+
const resultText = (tool, text) => {
|
|
669
|
+
if (!text)
|
|
670
|
+
return null;
|
|
671
|
+
const web = webShownOf(tool, text, callShown);
|
|
672
|
+
return web ? webWithin(web, options.calls.result) : cut(callShown(text), options.calls.result);
|
|
673
|
+
};
|
|
555
674
|
/** The `tool_result` row of a finished call, named `named`; `parent` is a nested call's caller. */
|
|
556
675
|
/** A call that returned but whose result says it did not do its work (a refused fetch) reads as that, failed. Its
|
|
557
676
|
* outcome is read once, for the summary and the status both. */
|
|
@@ -570,10 +689,13 @@ function createProjector(options) {
|
|
|
570
689
|
// A call refused before it ran is named refused already (refusedLabel), and a computer step's label says it could not
|
|
571
690
|
// (saysFailure): its row says why, never that it failed.
|
|
572
691
|
const failedSummary = refused(view) || saysFailure(tool.name) ? `${named}: ${failure(shown.text)}` : `${named} failed: ${failure(shown.text)}`;
|
|
692
|
+
// One the run's end closed has no outcome: interrupted, as a call cut off reads (interrupt), with no status.
|
|
693
|
+
const unended = endedWithRun(view);
|
|
573
694
|
return make("tool_result", conv, rowId, {
|
|
574
|
-
summary: !view.isError && pageChanged(tool.name, view) ? PAGE_CHANGED_ROW : view.isError ? failedSummary : worded ? `${named}: ${saidOf(worded.text)}` : outcome?.failed ? `${named}: failed` : `${named}: ok`, tool_name: tool.name, tool_use_id: tool.callId,
|
|
575
|
-
tool_status: failedWith(view, outcome) ? "failed" : "success", tool_result_preview: shown.text ? cut(scrubUrls(shown.text), caps.preview) : null,
|
|
695
|
+
summary: unended ? `${named} interrupted` : !view.isError && pageChanged(tool.name, view) ? PAGE_CHANGED_ROW : view.isError ? failedSummary : worded ? `${named}: ${saidOf(worded.text)}` : outcome?.failed ? `${named}: failed` : `${named}: ok`, tool_name: tool.name, tool_use_id: tool.callId,
|
|
696
|
+
tool_status: unended ? null : failedWith(view, outcome) ? "failed" : "success", tool_result_preview: shown.text ? cut(scrubUrls(shown.text), caps.preview) : null,
|
|
576
697
|
tool_result_size_bytes: utf8Bytes(view.text), round: tool.round, parent_tool_use_id: parent, ...(refused(view) ? { refused: true } : {}),
|
|
698
|
+
...(options.calls ? { tool_result_text: resultText(tool.name, view.text) } : {}),
|
|
577
699
|
});
|
|
578
700
|
};
|
|
579
701
|
/** The call a browser charge belongs to (BROWSER_CHARGE): the one it names, else its session's last charged call, else
|
|
@@ -636,9 +758,10 @@ function createProjector(options) {
|
|
|
636
758
|
const add = (row) => { rows.push(row); out.push(row); };
|
|
637
759
|
const touch = (row) => { if (!out.includes(row))
|
|
638
760
|
out.push(row); };
|
|
639
|
-
if (entry.kind === CAP_WRAPUP) {
|
|
640
|
-
// What the run's model was told near its cap: the server's row (`origin:
|
|
641
|
-
// no request, no cost, and no message any turn took (its id ends in
|
|
761
|
+
if (entry.kind === CAP_WRAPUP || entry.kind === COMPUTER_NOTE) {
|
|
762
|
+
// What the run's model was told near its cap, or after its computer was replaced: the server's row (`origin:
|
|
763
|
+
// "server"`, in the words of its other rows), no request, no cost, and no message any turn took (its id ends in
|
|
764
|
+
// NOTE_SUFFIX, which isMessageRow passes over).
|
|
642
765
|
const words = str(obj(entry.data)?.words);
|
|
643
766
|
if (words)
|
|
644
767
|
add(make("phase", conv, `${base}${NOTE_SUFFIX}`, { summary: `AgentRun: ${words}`, text: words, origin: "server" }));
|
|
@@ -679,7 +802,9 @@ function createProjector(options) {
|
|
|
679
802
|
if (metered !== "continued")
|
|
680
803
|
answers.set(conv, entry.id);
|
|
681
804
|
if (message.stopReason === "error") {
|
|
682
|
-
|
|
805
|
+
// A ChatGPT plan's limit reached (the model proxy's own answer, by its code) reads in its own words alone.
|
|
806
|
+
const proxied = proxyAnswerOf(message.errorMessage);
|
|
807
|
+
const why = redactedWhy(proxied?.code === PLAN_LIMIT_CODE && proxied.message ? proxied.message : (str(message.errorMessage) ?? "unknown error"));
|
|
683
808
|
// One with no price of its own (a provider's refusal sends none) is a cost unknown, never $0: the provider may
|
|
684
809
|
// still bill it (run-adapters answeredUnpriced). Its row says so, as the usage row counts it "not priced".
|
|
685
810
|
const priced = Number.isFinite(obj(obj(message.usage)?.cost)?.total);
|
|
@@ -729,7 +854,11 @@ function createProjector(options) {
|
|
|
729
854
|
browsers.add(conv);
|
|
730
855
|
add(make("phase", conv, `${base}:${index}:session`, { summary: "A live browser session started" }));
|
|
731
856
|
}
|
|
732
|
-
|
|
857
|
+
// A call the loop's record kept for a tool that nests (a script's, tools_call's) sits under that tool's call; one
|
|
858
|
+
// made inside a call of the harness's own (Codex's `exec`) under that call, which its record names. SDK calls keep
|
|
859
|
+
// their validated explicit parent.
|
|
860
|
+
const nesting = (entry.recordedCall ? (entry.parentCall ?? nestingCallOf(id)) : undefined) ?? str(obj(entry.data)?.parentCallId);
|
|
861
|
+
const use = useRow(conv, `${base}:${index}`, id, name, args, { round, ...(nesting ? { parent_tool_use_id: nesting } : {}) });
|
|
733
862
|
const before = early.get(`${conv}:${id}`);
|
|
734
863
|
const opened = { conv, name, args, round, use, done: before !== undefined };
|
|
735
864
|
calls.set(`${conv}:${id}`, opened);
|
|
@@ -771,7 +900,7 @@ function createProjector(options) {
|
|
|
771
900
|
call.use.summary = clean(named, caps.summary);
|
|
772
901
|
touch(call.use);
|
|
773
902
|
}
|
|
774
|
-
const row = resultRow(conv, base, { name, callId: id || null, round: call?.round }, named, view, shown);
|
|
903
|
+
const row = resultRow(conv, base, { name, callId: id || null, round: call?.round }, named, view, shown, call?.use.parent_tool_use_id);
|
|
775
904
|
if (!call && id)
|
|
776
905
|
early.set(`${conv}:${id}`, { row, view, shown });
|
|
777
906
|
add(row);
|
|
@@ -930,17 +1059,18 @@ function createProjector(options) {
|
|
|
930
1059
|
/** The usage row. `nothingInFlight`: read as a settled run is, a request marked with no answer being cut, for a host that
|
|
931
1060
|
* knows its turn is over while its process lives on (a stopped turn). */
|
|
932
1061
|
function usage(nothingInFlight = false) {
|
|
933
|
-
const counted = meter.usage(options.settled === true || nothingInFlight);
|
|
1062
|
+
const counted = meter.usage(options.settled === true || nothingInFlight, options.side, options.holdsUnpriced === true);
|
|
934
1063
|
if (!counted || root === undefined)
|
|
935
1064
|
return undefined;
|
|
936
|
-
const { usd, requests, charges, so_far_usd, unpriced, not_metered } = counted;
|
|
1065
|
+
const { usd, requests, charges, so_far_usd, unpriced, not_metered, upper_bound } = counted;
|
|
937
1066
|
const paid = toolCallWords(charges, not_metered);
|
|
938
|
-
|
|
1067
|
+
// A cost that counts a cut request at its hold is the most the run can have cost: said so.
|
|
1068
|
+
const spent = usd !== null ? `${upper_bound ? "at most " : ""}${dollars(usd)}` : so_far_usd !== undefined && unpriced !== undefined ? `${dollars(so_far_usd)} known, ${unpriced} not priced,` : "unknown";
|
|
939
1069
|
return make("usage", root, `${root}:usage`, {
|
|
940
1070
|
// A run whose only request its cap refused sent none, and says so; otherwise what is known so far (costsofar/1).
|
|
941
1071
|
summary: requests === 0 && !charges ? "no model request sent" : `${costLabel(options.ended === true)}: ${spent} over ${requests} model request${requests === 1 ? "" : "s"}${paid}`,
|
|
942
1072
|
// The contract's TimelineUsage and its costsofar/1 fields, while the cost is unknown: no other of the meter's reaches it.
|
|
943
|
-
usage: { usd, requests, ...(so_far_usd !== undefined && unpriced !== undefined ? { so_far_usd, unpriced } : {}), ...(not_metered ? { not_metered } : {}) },
|
|
1073
|
+
usage: { usd, requests, ...(so_far_usd !== undefined && unpriced !== undefined ? { so_far_usd, unpriced } : {}), ...(not_metered ? { not_metered } : {}), ...(upper_bound ? { upper_bound } : {}) },
|
|
944
1074
|
});
|
|
945
1075
|
}
|
|
946
1076
|
return {
|
package/dist/timeline/util.d.ts
CHANGED
|
@@ -17,5 +17,10 @@ export declare function where(url: string): string;
|
|
|
17
17
|
* userinfo are dropped, the rule pi-browser applies to the URLs a model sees.
|
|
18
18
|
*/
|
|
19
19
|
export declare function scrubUrls(text: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* One http(s) URL, as scrubUrls shows each it finds: its origin, its path and its query keys alone. Trailing punctuation
|
|
22
|
+
* (a closing quote's among it) is kept as it was, outside the URL.
|
|
23
|
+
*/
|
|
24
|
+
export declare function scrubUrl(raw: string): string;
|
|
20
25
|
/** `a, b, +2 more`. */
|
|
21
26
|
export declare const list: (items: readonly string[]) => string;
|
package/dist/timeline/util.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SCRUBBED_URL, trimmed } from "../text-urls.js";
|
|
1
2
|
export const obj = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : undefined;
|
|
2
3
|
export const str = (value) => (typeof value === "string" ? value : undefined);
|
|
3
4
|
export const cut = (text, max) => (text.length > max ? `${text.slice(0, max - 3)}...` : text);
|
|
@@ -43,21 +44,56 @@ export function where(url) {
|
|
|
43
44
|
return cut(parts ? `${parts[1]}${parts[2] === "/" ? "" : parts[2]}` : (url.split(/[?#]/)[0] ?? ""), 80);
|
|
44
45
|
}
|
|
45
46
|
const ELIDED = "\u2026";
|
|
46
|
-
|
|
47
|
+
// An apostrophe is part of a URL (a path's O'Reilly, a query's quoted word): a URL that stopped at one would leave the query
|
|
48
|
+
// after it unscrubbed. One that closes a quote around the URL is in its tail, as a sentence's punctuation is (trimmed).
|
|
49
|
+
// Where a URL ends and what tail is not its own are text-urls.ts's, the link check's and a fetched page's links' too.
|
|
50
|
+
const SCHEME = /https?:\/\//gi;
|
|
47
51
|
const URL_PARTS = /^(https?:\/\/)(?:[^@/?#]*@)?([^/?#]*)([^?#]*)(?:\?([^#]*))?/i;
|
|
52
|
+
/** The userinfo of a URL run into another's host, path or query key. */
|
|
53
|
+
const INNER_USERINFO = /(https?:\/\/)[^@/?#\s]*@/gi;
|
|
54
|
+
const ALNUM = /[A-Za-z0-9]/;
|
|
48
55
|
/**
|
|
49
56
|
* Every http(s) URL in `text` keeps its origin, its path and its query keys. Query values, the fragment and the
|
|
50
57
|
* userinfo are dropped, the rule pi-browser applies to the URLs a model sees.
|
|
51
58
|
*/
|
|
52
59
|
export function scrubUrls(text) {
|
|
53
|
-
return text.replace(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
+
return text.replace(SCRUBBED_URL, (raw) => {
|
|
61
|
+
// A URL that starts after nothing but punctuation holding an apostrophe is the next of a compact quoted list
|
|
62
|
+
// (`'https://a','https://b'`): each is scrubbed alone. Never one past a "?" or "#" of the URL before it: that one is
|
|
63
|
+
// in its query or fragment (`?next='https://b/...'`), a value dropped with it. Each look back stops at a letter or a
|
|
64
|
+
// digit, and the scan for "?" and "#" goes once through `raw`, so this is linear.
|
|
65
|
+
const starts = [0];
|
|
66
|
+
let [scanned, valued] = [0, false];
|
|
67
|
+
for (const found of raw.matchAll(SCHEME)) {
|
|
68
|
+
if (found.index === 0)
|
|
69
|
+
continue;
|
|
70
|
+
for (; scanned < found.index; scanned++)
|
|
71
|
+
valued ||= raw[scanned] === "?" || raw[scanned] === "#";
|
|
72
|
+
if (valued)
|
|
73
|
+
continue;
|
|
74
|
+
let quoted = false;
|
|
75
|
+
for (let i = found.index - 1; i > starts.at(-1) && !ALNUM.test(raw[i]); i--)
|
|
76
|
+
quoted ||= raw[i] === "'";
|
|
77
|
+
if (quoted)
|
|
78
|
+
starts.push(found.index);
|
|
79
|
+
}
|
|
80
|
+
return starts.map((start, i) => scrubUrl(raw.slice(start, starts[i + 1] ?? raw.length))).join("");
|
|
60
81
|
});
|
|
61
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* One http(s) URL, as scrubUrls shows each it finds: its origin, its path and its query keys alone. Trailing punctuation
|
|
85
|
+
* (a closing quote's among it) is kept as it was, outside the URL.
|
|
86
|
+
*/
|
|
87
|
+
export function scrubUrl(raw) {
|
|
88
|
+
const end = trimmed(raw).length;
|
|
89
|
+
const parts = URL_PARTS.exec(raw.slice(0, end));
|
|
90
|
+
if (!parts)
|
|
91
|
+
return raw;
|
|
92
|
+
// Another URL run into this one, in its host, its path or a query key with no "=" (after a comma or a quote, say),
|
|
93
|
+
// loses its userinfo; what follows a "=" or a "#" of either is dropped as this one's.
|
|
94
|
+
const bare = (text) => text.replace(INNER_USERINFO, "$1");
|
|
95
|
+
const keys = [...new Set((parts[4] ?? "").split("&").map((pair) => bare(pair.split("=")[0])).filter(Boolean))];
|
|
96
|
+
return `${parts[1]}${bare(`${parts[2]}${parts[3]}`)}${keys.length ? `?${keys.map((key) => `${key}=${ELIDED}`).join("&")}` : ""}${raw.slice(end)}`;
|
|
97
|
+
}
|
|
62
98
|
/** `a, b, +2 more`. */
|
|
63
99
|
export const list = (items) => items.length > 2 ? `${items.slice(0, 2).join(", ")}, +${items.length - 2} more` : items.join(", ");
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** A web call's output with each text that gives way cut to `keep` characters (a cut one ending "…"), the rest whole. */
|
|
2
|
+
export type WebShown = (keep: number) => string;
|
|
3
|
+
/** `text`, a call of `tool`'s output, with `cut` (the run's redactor) applied to each string of its JSON by itself and to
|
|
4
|
+
* the lines after it, never to its JSON line whole: the redactor reads a run of more than 8,192 characters with no
|
|
5
|
+
* whitespace as "[redacted]" (key-refusal.ts redactedAnswer), and a JSON line, whose newlines are escapes, is one such
|
|
6
|
+
* run from its text's last space through its links, so cut whole it loses its links and no longer parses. Undefined for
|
|
7
|
+
* a tool other than web_search and web_fetch, or an output whose first line is not a JSON object: that one is cut as
|
|
8
|
+
* any other tool's. */
|
|
9
|
+
export declare function webCut(tool: string, text: string, cut: (text: string) => string): string | undefined;
|
|
10
|
+
/** `text`, a call of `tool`'s output, as a grader reads it (WebShown), each of its strings through `each` first (the
|
|
11
|
+
* run's redaction, its URLs' query values elided), so a cut never falls inside what that takes out. Undefined for a
|
|
12
|
+
* tool other than web_search and web_fetch, or an output that is not its JSON. A page's links past a cut are counted
|
|
13
|
+
* in `links_cut`. */
|
|
14
|
+
export declare function webShownOf(tool: string, text: string, each?: (text: string) => string): WebShown | undefined;
|
|
15
|
+
/** `shown` in `room` characters: whole when it fits, else each text that gives way cut to the longest length that
|
|
16
|
+
* fits, the same for each; past `room` only when its url lists alone pass it, every such text then cut to nothing. */
|
|
17
|
+
export declare function webWithin(shown: WebShown, room: number): string;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
const WEB_SEARCH = "web_search";
|
|
2
|
+
const WEB_FETCH = "web_fetch";
|
|
3
|
+
const isObj = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4
|
+
/** `text` cut to `keep` characters and marked, never splitting a surrogate pair. */
|
|
5
|
+
function clip(text, keep) {
|
|
6
|
+
if (text.length <= keep)
|
|
7
|
+
return text;
|
|
8
|
+
const code = keep > 0 ? text.charCodeAt(keep - 1) : 0;
|
|
9
|
+
return `${text.slice(0, code >= 0xd800 && code <= 0xdbff ? keep - 1 : keep)}…`;
|
|
10
|
+
}
|
|
11
|
+
/** Every string in `value`, property names aside, through `each`. */
|
|
12
|
+
function eachString(value, each) {
|
|
13
|
+
if (typeof value === "string")
|
|
14
|
+
return each(value);
|
|
15
|
+
if (Array.isArray(value))
|
|
16
|
+
return value.map((item) => eachString(item, each));
|
|
17
|
+
if (isObj(value))
|
|
18
|
+
return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, eachString(item, each)]));
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
/** How many of `links`, in order, fit in `keep` characters of JSON. */
|
|
22
|
+
function linksWithin(links, keep) {
|
|
23
|
+
let used = 0;
|
|
24
|
+
for (const [i, link] of links.entries()) {
|
|
25
|
+
used += JSON.stringify(link).length + 1;
|
|
26
|
+
if (used > keep)
|
|
27
|
+
return i;
|
|
28
|
+
}
|
|
29
|
+
return links.length;
|
|
30
|
+
}
|
|
31
|
+
/** `text`, a call of `tool`'s output, with `cut` (the run's redactor) applied to each string of its JSON by itself and to
|
|
32
|
+
* the lines after it, never to its JSON line whole: the redactor reads a run of more than 8,192 characters with no
|
|
33
|
+
* whitespace as "[redacted]" (key-refusal.ts redactedAnswer), and a JSON line, whose newlines are escapes, is one such
|
|
34
|
+
* run from its text's last space through its links, so cut whole it loses its links and no longer parses. Undefined for
|
|
35
|
+
* a tool other than web_search and web_fetch, or an output whose first line is not a JSON object: that one is cut as
|
|
36
|
+
* any other tool's. */
|
|
37
|
+
export function webCut(tool, text, cut) {
|
|
38
|
+
if (tool !== WEB_SEARCH && tool !== WEB_FETCH)
|
|
39
|
+
return undefined;
|
|
40
|
+
const end = text.indexOf("\n");
|
|
41
|
+
let read;
|
|
42
|
+
try {
|
|
43
|
+
read = JSON.parse(end < 0 ? text : text.slice(0, end));
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
if (!isObj(read))
|
|
49
|
+
return undefined;
|
|
50
|
+
return `${JSON.stringify(eachString(read, cut))}${end < 0 ? "" : cut(text.slice(end))}`;
|
|
51
|
+
}
|
|
52
|
+
/** `text`, a call of `tool`'s output, as a grader reads it (WebShown), each of its strings through `each` first (the
|
|
53
|
+
* run's redaction, its URLs' query values elided), so a cut never falls inside what that takes out. Undefined for a
|
|
54
|
+
* tool other than web_search and web_fetch, or an output that is not its JSON. A page's links past a cut are counted
|
|
55
|
+
* in `links_cut`. */
|
|
56
|
+
export function webShownOf(tool, text, each = (part) => part) {
|
|
57
|
+
if (tool !== WEB_SEARCH && tool !== WEB_FETCH)
|
|
58
|
+
return undefined;
|
|
59
|
+
const end = text.indexOf("\n");
|
|
60
|
+
let read;
|
|
61
|
+
try {
|
|
62
|
+
read = JSON.parse(end < 0 ? text : text.slice(0, end));
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
const shown = eachString(read, each);
|
|
68
|
+
if (!isObj(shown))
|
|
69
|
+
return undefined;
|
|
70
|
+
const after = end < 0 ? "" : each(text.slice(end));
|
|
71
|
+
if (tool === WEB_SEARCH) {
|
|
72
|
+
const results = shown.results;
|
|
73
|
+
if (!Array.isArray(results) || !results.every(isObj))
|
|
74
|
+
return undefined;
|
|
75
|
+
return (keep) => {
|
|
76
|
+
const hits = results.map((hit) => (typeof hit.snippet === "string" ? { ...hit, snippet: clip(hit.snippet, keep) } : hit));
|
|
77
|
+
return `${JSON.stringify({ ...shown, ...(typeof shown.text === "string" ? { text: clip(shown.text, keep) } : {}), results: hits })}${after}`;
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
if (typeof shown.url !== "string" || typeof shown.text !== "string")
|
|
81
|
+
return undefined;
|
|
82
|
+
const page = shown;
|
|
83
|
+
const links = Array.isArray(page.links) ? page.links : undefined;
|
|
84
|
+
return (keep) => {
|
|
85
|
+
const kept = links ? linksWithin(links, keep) : 0;
|
|
86
|
+
const cut = links ? links.length - kept : 0;
|
|
87
|
+
const before = typeof page.links_cut === "number" ? page.links_cut : 0;
|
|
88
|
+
return `${JSON.stringify({ ...page, text: clip(page.text, keep), ...(links ? { links: links.slice(0, kept) } : {}), ...(cut ? { links_cut: before + cut } : {}) })}${after}`;
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/** `shown` in `room` characters: whole when it fits, else each text that gives way cut to the longest length that
|
|
92
|
+
* fits, the same for each; past `room` only when its url lists alone pass it, every such text then cut to nothing. */
|
|
93
|
+
export function webWithin(shown, room) {
|
|
94
|
+
const whole = shown(Number.POSITIVE_INFINITY);
|
|
95
|
+
if (whole.length <= room)
|
|
96
|
+
return whole;
|
|
97
|
+
let [low, high] = [0, whole.length];
|
|
98
|
+
while (low < high) {
|
|
99
|
+
const mid = Math.ceil((low + high) / 2);
|
|
100
|
+
if (shown(mid).length <= room)
|
|
101
|
+
low = mid;
|
|
102
|
+
else
|
|
103
|
+
high = mid - 1;
|
|
104
|
+
}
|
|
105
|
+
return shown(low);
|
|
106
|
+
}
|