@parcha/agentrun-serve 0.1.0-beta.33 → 0.1.0-beta.35
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 +368 -0
- package/README.md +341 -208
- package/dist/adapters.d.ts +3 -4
- package/dist/adapters.js +18 -15
- package/dist/agent-rows.d.ts +99 -0
- package/dist/agent-rows.js +1 -0
- package/dist/agents-store.d.ts +6 -2
- package/dist/agents-store.js +75 -25
- package/dist/agents.d.ts +9 -125
- package/dist/agents.js +15 -305
- package/dist/answer-json.d.ts +23 -0
- package/dist/answer-json.js +58 -0
- package/dist/api-only.d.ts +1 -1
- package/dist/api-only.js +2 -2
- package/dist/archil-settings.d.ts +11 -1
- package/dist/archil-settings.js +10 -0
- package/dist/bash-read-only.d.ts +35 -0
- package/dist/bash-read-only.js +778 -0
- package/dist/box-settings.d.ts +3 -23
- package/dist/box-settings.js +7 -51
- package/dist/boxes.d.ts +17 -0
- package/dist/boxes.js +27 -20
- package/dist/browser-commands.d.ts +5 -2
- package/dist/browser-commands.js +4 -4
- package/dist/browser-computer.d.ts +5 -0
- package/dist/browser-computer.js +21 -0
- package/dist/browser-cost.d.ts +9 -6
- package/dist/browser-cost.js +95 -51
- package/dist/browser-live.d.ts +7 -20
- package/dist/browser-live.js +15 -93
- package/dist/browser-person.d.ts +18 -51
- package/dist/browser-person.js +94 -277
- package/dist/budget.d.ts +0 -5
- package/dist/budget.js +0 -5
- package/dist/cap.d.ts +14 -8
- package/dist/cap.js +19 -9
- package/dist/cli.js +71 -18
- package/dist/closed-pipes.d.ts +2 -0
- package/dist/closed-pipes.js +13 -0
- package/dist/computer-commands.d.ts +2 -0
- package/dist/computer-commands.js +2 -0
- package/dist/computer-keys.d.ts +20 -10
- package/dist/computer-keys.js +36 -54
- package/dist/computer-setting.d.ts +20 -3
- package/dist/computer-setting.js +58 -10
- package/dist/computers.d.ts +35 -2
- package/dist/computers.js +72 -11
- package/dist/confine.d.ts +120 -0
- package/dist/confine.js +436 -0
- package/dist/console/assets/index-B7NKTU8E.css +1 -0
- package/dist/console/assets/index-CXZMgJE7.js +550 -0
- package/dist/console/index.html +2 -2
- package/dist/content-filter.d.ts +7 -0
- package/dist/content-filter.js +23 -0
- package/dist/decision-cap.d.ts +7 -29
- package/dist/decision-cap.js +3 -94
- package/dist/decision-rows.d.ts +1 -1
- package/dist/decision-rows.js +1 -1
- package/dist/docker-daemon.d.ts +31 -0
- package/dist/docker-daemon.js +56 -0
- package/dist/effort-guidance.js +4 -3
- package/dist/environment.d.ts +0 -3
- package/dist/environment.js +3 -5
- package/dist/errors.d.ts +1 -2
- package/dist/errors.js +9 -9
- package/dist/explain.js +3 -1
- package/dist/filed-answer.d.ts +32 -0
- package/dist/filed-answer.js +160 -0
- package/dist/files.d.ts +1 -3
- package/dist/files.js +2 -4
- package/dist/github-connection.d.ts +1 -1
- package/dist/github-connection.js +25 -7
- package/dist/github-faux.d.ts +26 -0
- package/dist/github-faux.js +76 -0
- package/dist/github.d.ts +6 -2
- package/dist/github.js +5 -3
- package/dist/graph-served.d.ts +5 -3
- package/dist/graph-served.js +14 -6
- package/dist/graph-view.d.ts +3 -5
- package/dist/graph-view.js +9 -16
- package/dist/handed-values.d.ts +9 -0
- package/dist/handed-values.js +26 -0
- package/dist/harness-install.d.ts +1 -7
- package/dist/harness-install.js +1 -18
- package/dist/harness-opencode/adapter.d.ts +7 -0
- package/dist/harness-opencode/adapter.js +23 -6
- package/dist/harness-opencode/harness.js +0 -1
- package/dist/harness-opencode/host/policy.js +2 -2
- package/dist/harness-opencode/index.d.ts +1 -1
- package/dist/harness-opencode/index.js +1 -1
- package/dist/harness-opencode/verify.d.ts +17 -0
- package/dist/harness-opencode/verify.js +30 -10
- package/dist/harness-table.js +6 -1
- package/dist/heard.js +1 -1
- package/dist/held-fd.d.ts +5 -0
- package/dist/held-fd.js +14 -0
- package/dist/host-calls.d.ts +20 -0
- package/dist/host-calls.js +12 -0
- package/dist/host-tools.d.ts +4 -21
- package/dist/host-tools.js +4 -61
- package/dist/host.d.ts +2 -4
- package/dist/host.js +2 -7
- package/dist/import-summary.d.ts +1 -5
- package/dist/import-summary.js +0 -21
- package/dist/import.d.ts +6 -6
- package/dist/import.js +14 -15
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/key-refusal.d.ts +5 -1
- package/dist/key-refusal.js +19 -4
- package/dist/learn/check.d.ts +8 -2
- package/dist/learn/check.js +85 -31
- package/dist/learn/folder.d.ts +11 -4
- package/dist/learn/folder.js +17 -19
- package/dist/learn/grade.d.ts +18 -1
- package/dist/learn/grade.js +108 -14
- package/dist/learn/index.d.ts +5 -5
- package/dist/learn/index.js +5 -5
- package/dist/learn/learning.sh +1 -14
- package/dist/learn/notes.d.ts +14 -3
- package/dist/learn/notes.js +16 -6
- package/dist/learn/reflect.d.ts +31 -2
- package/dist/learn/reflect.js +83 -6
- package/dist/learn/relevance.d.ts +24 -0
- package/dist/learn/relevance.js +91 -0
- package/dist/learn/secrets.d.ts +7 -1
- package/dist/learn/secrets.js +86 -19
- package/dist/learn/skills.d.ts +159 -18
- package/dist/learn/skills.js +644 -64
- package/dist/learned-nodes.d.ts +14 -0
- package/dist/learned-nodes.js +8 -0
- package/dist/learned-workflow.d.ts +41 -6
- package/dist/learned-workflow.js +153 -18
- package/dist/learning-routes.d.ts +49 -4
- package/dist/learning-routes.js +113 -31
- package/dist/learning-run.d.ts +16 -31
- package/dist/learning-run.js +31 -38
- package/dist/learning-words.d.ts +12 -5
- package/dist/learning-words.js +18 -9
- package/dist/learning.d.ts +91 -97
- package/dist/learning.js +176 -320
- package/dist/live/stream.js +1 -1
- package/dist/live/translate.js +12 -2
- package/dist/llm.d.ts +4 -1
- package/dist/llm.js +4 -2
- package/dist/local-models.d.ts +11 -5
- package/dist/local-models.js +13 -8
- package/dist/mcp-gateway.d.ts +17 -49
- package/dist/mcp-gateway.js +55 -136
- package/dist/mcp-oauth.d.ts +10 -14
- package/dist/mcp-oauth.js +14 -32
- package/dist/mcp-probe.d.ts +0 -7
- package/dist/mcp-probe.js +4 -10
- package/dist/mcp-servers-store.d.ts +18 -18
- package/dist/mcp-servers-store.js +12 -14
- package/dist/mcp-store.js +3 -4
- package/dist/mcp.js +4 -3
- package/dist/model.d.ts +9 -7
- package/dist/model.js +51 -27
- package/dist/monid.d.ts +0 -2
- package/dist/monid.js +3 -6
- package/dist/openapi.d.ts +8 -1
- package/dist/openapi.js +156 -58
- package/dist/page.d.ts +1 -3
- package/dist/page.js +6 -18
- package/dist/paid-calls.d.ts +21 -27
- package/dist/paid-calls.js +26 -61
- package/dist/pause.d.ts +2 -19
- package/dist/pause.js +5 -74
- package/dist/port-models.d.ts +10 -3
- package/dist/port-models.js +26 -6
- package/dist/propose.d.ts +2 -0
- package/dist/propose.js +80 -45
- package/dist/push-handler.d.ts +1 -1
- package/dist/reflect-range.d.ts +25 -0
- package/dist/reflect-range.js +30 -0
- package/dist/refusal-words.d.ts +5 -1
- package/dist/refusal-words.js +5 -1
- package/dist/rows.d.ts +1 -1
- package/dist/run-cut.d.ts +0 -6
- package/dist/run-cut.js +0 -6
- package/dist/run-db.d.ts +2 -11
- package/dist/run-db.js +2 -37
- package/dist/run-launch.d.ts +21 -2
- package/dist/run-launch.js +14 -5
- package/dist/run-learning-served.d.ts +21 -4
- package/dist/run-learning-served.js +23 -13
- package/dist/run-reads-over-store.d.ts +5 -3
- package/dist/run-reads-over-store.js +25 -14
- package/dist/run-secrets.d.ts +1 -1
- package/dist/run-timeline-served.d.ts +5 -1
- package/dist/run-timeline-served.js +27 -6
- package/dist/run-view.d.ts +37 -22
- package/dist/run-view.js +85 -38
- package/dist/runnable.d.ts +21 -10
- package/dist/runnable.js +35 -12
- package/dist/runner/adapter-loop.d.ts +36 -5
- package/dist/runner/adapter-loop.js +663 -69
- package/dist/runner/adapter-run-spec.d.ts +42 -8
- package/dist/runner/adapter-run-spec.js +186 -52
- package/dist/runner/adapters/index.js +11 -1
- package/dist/runner/adapters/pi.d.ts +40 -2
- package/dist/runner/adapters/pi.js +110 -27
- package/dist/runner/beside.d.ts +38 -3
- package/dist/runner/beside.js +54 -5
- package/dist/runner/claim-secrets.d.ts +16 -1
- package/dist/runner/claim-secrets.js +62 -14
- package/dist/runner/cli-run-spec.d.ts +5 -0
- package/dist/runner/cli-run-spec.js +159 -41
- package/dist/runner/commands.js +1 -1
- package/dist/runner/computer-journal.d.ts +15 -2
- package/dist/runner/computer-journal.js +41 -5
- package/dist/runner/conformance/harness.d.ts +1 -0
- package/dist/runner/conformance/harness.js +123 -13
- package/dist/runner/conformance/subject.d.ts +4 -1
- package/dist/runner/dispatch.d.ts +8 -1
- package/dist/runner/dispatch.js +81 -7
- package/dist/runner/end-of-run.d.ts +8 -2
- package/dist/runner/end-of-run.js +10 -4
- package/dist/runner/github-app.d.ts +7 -2
- package/dist/runner/github-app.js +47 -16
- package/dist/runner/harness-loops.d.ts +15 -2
- package/dist/runner/harness-loops.js +38 -2
- package/dist/runner/journal-kinds.d.ts +60 -6
- package/dist/runner/journal-kinds.js +43 -5
- package/dist/runner/journal-reader.d.ts +1 -1
- package/dist/runner/journal-reader.js +2 -2
- package/dist/runner/learning-ask.d.ts +4 -0
- package/dist/runner/learning-ask.js +15 -1
- package/dist/runner/learning-end.d.ts +18 -3
- package/dist/runner/learning-end.js +194 -20
- package/dist/runner/learning-loop.d.ts +7 -0
- package/dist/runner/learning-loop.js +36 -8
- package/dist/runner/learning-seed.d.ts +6 -0
- package/dist/runner/learning-seed.js +6 -0
- package/dist/runner/loop-contract.d.ts +4 -0
- package/dist/runner/main.d.ts +61 -9
- package/dist/runner/main.js +144 -20
- package/dist/runner/mcp-claim.d.ts +3 -0
- package/dist/runner/mcp-claim.js +7 -3
- package/dist/runner/mcp-github.d.ts +11 -2
- package/dist/runner/mcp-github.js +55 -4
- package/dist/runner/mcp-run.d.ts +2 -0
- package/dist/runner/mcp-run.js +16 -5
- package/dist/runner/memory-claim.d.ts +9 -0
- package/dist/runner/memory-claim.js +25 -0
- package/dist/runner/metrics.d.ts +46 -1
- package/dist/runner/metrics.js +156 -1
- package/dist/runner/model-route.d.ts +16 -0
- package/dist/runner/model-route.js +134 -10
- package/dist/runner/reflect-hook.d.ts +12 -1
- package/dist/runner/reflect-hook.js +33 -3
- package/dist/runner/runner.d.ts +20 -0
- package/dist/runner/runner.js +146 -18
- package/dist/runner/spec-holds.d.ts +7 -2
- package/dist/runner/spec-holds.js +4 -3
- package/dist/runner/store-port.d.ts +1 -1
- package/dist/runner/store-secrets.d.ts +3 -3
- package/dist/runner/store-secrets.js +8 -12
- package/dist/runner/text-tools.d.ts +44 -0
- package/dist/runner/text-tools.js +237 -0
- package/dist/runner/workflow-host.d.ts +7 -2
- package/dist/runner/workflow-host.js +3 -1
- package/dist/runner/workflow-loop.d.ts +10 -1
- package/dist/runner/workflow-loop.js +14 -6
- package/dist/runner/workflow-spec.d.ts +21 -0
- package/dist/runner/workflow-spec.js +217 -93
- package/dist/runs-over-store.d.ts +14 -3
- package/dist/runs-over-store.js +100 -23
- package/dist/seal-key.d.ts +0 -2
- package/dist/seal-key.js +5 -45
- package/dist/sealed-settings-store.d.ts +19 -4
- package/dist/sealed-settings-store.js +9 -9
- package/dist/sealing.d.ts +4 -0
- package/dist/sealing.js +20 -0
- package/dist/secret-cut.d.ts +1 -1
- package/dist/secret-cut.js +1 -1
- package/dist/secret-name.d.ts +9 -0
- package/dist/secret-name.js +15 -0
- package/dist/secret-writes.d.ts +0 -1
- package/dist/secret-writes.js +0 -1
- package/dist/server-fs.d.ts +4 -0
- package/dist/server-fs.js +8 -2
- package/dist/server-lock.d.ts +0 -24
- package/dist/server-lock.js +5 -85
- package/dist/server-secrets-store.d.ts +4 -4
- package/dist/server-secrets-store.js +9 -31
- package/dist/server-secrets.d.ts +4 -9
- package/dist/server-secrets.js +12 -36
- package/dist/server.d.ts +37 -56
- package/dist/server.js +322 -134
- package/dist/sign-ins-store.d.ts +34 -36
- package/dist/sign-ins-store.js +27 -38
- package/dist/sign-ins.d.ts +2 -119
- package/dist/sign-ins.js +5 -311
- package/dist/standard-webhooks.d.ts +1 -1
- package/dist/standard-webhooks.js +1 -1
- package/dist/stats.d.ts +3 -2
- package/dist/stats.js +1 -1
- package/dist/stop-signals.d.ts +4 -2
- package/dist/stop-signals.js +5 -3
- package/dist/store/agent-body.d.ts +12 -2
- package/dist/store/agent-body.js +22 -4
- package/dist/store/deadline.d.ts +18 -0
- package/dist/store/deadline.js +45 -0
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +2 -2
- package/dist/store/open.d.ts +6 -3
- package/dist/store/open.js +2 -2
- package/dist/store/postgres/connection.d.ts +22 -2
- package/dist/store/postgres/connection.js +211 -41
- package/dist/store/postgres/migrate.d.ts +4 -0
- package/dist/store/postgres/migrate.js +9 -2
- package/dist/store/postgres/migrations/0003_commands_one_answer.check.sql +19 -0
- package/dist/store/postgres/migrations/0003_commands_one_answer.sql +13 -0
- package/dist/store/postgres/store.d.ts +9 -2
- package/dist/store/postgres/store.js +9 -0
- package/dist/store/schema.js +1 -1
- package/dist/store/seal.js +2 -2
- package/dist/store/sqlite/connection.js +14 -5
- package/dist/store/sqlite/run-patch.d.ts +3 -0
- package/dist/store/sqlite/run-patch.js +3 -0
- package/dist/store/sqlite/store.js +41 -12
- package/dist/store/store.d.ts +35 -6
- package/dist/store/store.js +12 -2
- package/dist/store-reads/cap.d.ts +1 -1
- package/dist/store-reads/cap.js +22 -4
- package/dist/store-reads/journal.d.ts +9 -6
- package/dist/store-reads/journal.js +129 -18
- package/dist/store-reads/learning.d.ts +82 -8
- package/dist/store-reads/learning.js +184 -11
- package/dist/store-reads/workflow.d.ts +1 -1
- package/dist/store-reads/workflow.js +1 -1
- package/dist/store-view.d.ts +19 -1
- package/dist/store-view.js +95 -27
- package/dist/template-eval.d.ts +60 -4
- package/dist/template-eval.js +120 -54
- package/dist/templates.d.ts +33 -14
- package/dist/templates.js +82 -46
- package/dist/timeline/group.d.ts +33 -0
- package/dist/timeline/group.js +77 -0
- package/dist/timeline/index.d.ts +7 -0
- package/dist/timeline/index.js +7 -0
- package/dist/timeline/labels.d.ts +79 -0
- package/dist/timeline/labels.js +150 -0
- package/dist/timeline/origin.d.ts +56 -0
- package/dist/timeline/origin.js +92 -0
- package/dist/timeline/render-text.d.ts +11 -0
- package/dist/timeline/render-text.js +62 -0
- package/dist/timeline/timeline.d.ts +282 -0
- package/dist/timeline/timeline.js +1308 -0
- package/dist/timeline/util.d.ts +17 -0
- package/dist/timeline/util.js +49 -0
- package/dist/tool-budget.d.ts +18 -0
- package/dist/tool-budget.js +50 -0
- package/dist/tool-gate.d.ts +47 -218
- package/dist/tool-gate.js +87 -545
- package/dist/tool-keys-store.d.ts +11 -12
- package/dist/tool-keys-store.js +24 -31
- package/dist/tool-keys.d.ts +5 -101
- package/dist/tool-keys.js +8 -267
- package/dist/tool-plane.d.ts +23 -52
- package/dist/tool-plane.js +23 -81
- package/dist/tool-settings-store.d.ts +1 -2
- package/dist/tool-settings-store.js +5 -8
- package/dist/tools.d.ts +67 -25
- package/dist/tools.js +170 -119
- package/dist/trigger-adapter.d.ts +2 -2
- package/dist/trigger-targets.d.ts +13 -1
- package/dist/trigger-targets.js +31 -1
- package/dist/triggers.d.ts +2 -2
- package/dist/triggers.js +3 -3
- package/dist/turn-end.d.ts +1 -1
- package/dist/turn-end.js +1 -1
- package/dist/turns.d.ts +0 -6
- package/dist/turns.js +0 -19
- package/dist/uploads.d.ts +28 -5
- package/dist/uploads.js +83 -10
- package/dist/usage.d.ts +1 -49
- package/dist/usage.js +3 -84
- package/dist/validate.d.ts +4 -0
- package/dist/validate.js +33 -14
- package/dist/webhooks.d.ts +102 -76
- package/dist/webhooks.js +266 -233
- package/dist/workflow-run.d.ts +114 -0
- package/dist/workflow-run.js +144 -0
- package/dist/workspace/archil-claim.d.ts +2 -2
- package/dist/workspace/archil-claim.js +4 -3
- package/dist/workspace/archil-disk.d.ts +10 -1
- package/dist/workspace/archil-disk.js +4 -0
- package/dist/workspace/archil-exec.d.ts +12 -2
- package/dist/workspace/archil-exec.js +16 -0
- package/dist/workspace/archil.d.ts +2 -2
- package/dist/workspace/archil.js +25 -5
- package/dist/workspace/attach.js +2 -0
- package/dist/workspace/beneath.d.ts +19 -0
- package/dist/workspace/beneath.js +106 -0
- package/dist/workspace/computer-deps.d.ts +26 -9
- package/dist/workspace/computer-deps.js +144 -43
- package/dist/workspace/computer-for-claim.d.ts +17 -14
- package/dist/workspace/computer-for-claim.js +99 -26
- package/dist/workspace/computer-hold.d.ts +6 -1
- package/dist/workspace/computer-hold.js +6 -1
- package/dist/workspace/computer-janitor.d.ts +47 -0
- package/dist/workspace/computer-janitor.js +182 -0
- package/dist/workspace/computer-ledger.d.ts +1 -8
- package/dist/workspace/computer-ledger.js +0 -3
- package/dist/workspace/computer-providers.d.ts +5 -3
- package/dist/workspace/computer-providers.js +11 -9
- package/dist/workspace/grep-worker.d.ts +5 -0
- package/dist/workspace/grep-worker.js +9 -6
- package/dist/workspace/hands.d.ts +5 -2
- package/dist/workspace/hands.js +4 -3
- package/dist/workspace/index.d.ts +6 -5
- package/dist/workspace/index.js +4 -4
- package/dist/workspace/local.d.ts +14 -2
- package/dist/workspace/local.js +170 -43
- package/dist/workspace/paths.js +3 -2
- package/dist/workspace/pi-env.d.ts +4 -0
- package/dist/workspace/pi-env.js +3 -2
- package/dist/workspace/resolve-computer.d.ts +55 -10
- package/dist/workspace/resolve-computer.js +66 -14
- package/dist/workspace/run-tools.d.ts +15 -31
- package/dist/workspace/run-tools.js +19 -30
- package/dist/workspace/workspace.d.ts +5 -0
- package/dist/workspace-paths.d.ts +0 -17
- package/dist/workspace-paths.js +1 -41
- package/dist/workspace.d.ts +0 -17
- package/dist/workspace.js +4 -110
- package/package.json +14 -14
- package/skills/agentrun-serve/SKILL.md +1 -1
- package/templates/README.md +11 -5
- package/templates/code-review/evals/mentions-defused/case.yaml +15 -0
- package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +254 -0
- package/templates/code-review/evals/mentions-defused/graders/no-pings.md +16 -0
- package/templates/code-review/evals/mentions-defused/graders/posted-a-review.md +5 -0
- package/templates/code-review/evals/mentions-defused/graders/schema.md +5 -0
- package/templates/code-review/evals/mentions-defused/prompt.md +10 -0
- package/templates/kyb/evals/clean-public-company/graders/no-opensanctions.md +5 -0
- package/templates/kyb/evals/opensanctions-on/case.yaml +5 -0
- package/templates/kyb/evals/opensanctions-on/graders/licence-and-evidence.md +18 -0
- package/templates/kyb/evals/opensanctions-on/graders/schema.md +5 -0
- package/templates/kyb/evals/opensanctions-on/prompt.md +11 -0
- package/templates/market-monitor/agent.md +2 -2
- package/templates/market-monitor/skills/monitor/SKILL.md +6 -4
- package/templates/release-notes/agent.md +11 -0
- package/dist/bound-files.d.ts +0 -4
- package/dist/bound-files.js +0 -164
- package/dist/coding-tools.d.ts +0 -47
- package/dist/coding-tools.js +0 -189
- package/dist/computer-adb.d.ts +0 -12
- package/dist/computer-adb.js +0 -14
- package/dist/console/assets/index-Dn0ngwG9.js +0 -535
- package/dist/console/assets/index-DvW6Aled.css +0 -1
- package/dist/grade.d.ts +0 -63
- package/dist/grade.js +0 -150
- package/dist/mcp-servers.d.ts +0 -269
- package/dist/mcp-servers.js +0 -456
- package/dist/packs.d.ts +0 -71
- package/dist/packs.js +0 -180
- package/dist/sealed-settings.d.ts +0 -60
- package/dist/sealed-settings.js +0 -171
- package/dist/sessions.d.ts +0 -6
- package/dist/sessions.js +0 -109
- package/dist/workspace/computer-serves.d.ts +0 -12
- package/dist/workspace/computer-serves.js +0 -15
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
// Tools as text, for a model whose provider caches no prefix of a request that carries a `tools` parameter (a catalog
|
|
2
|
+
// entry's 'toolsAs: "text"', local-models.ts; the translated route, model-route.ts, reads it). Measured
|
|
3
|
+
// 2026-11-11 on OpenRouter's particle-1 (one provider, Particle AI): the same request with `tools` renders to a prompt
|
|
4
|
+
// whose token count varies by request (58,791 vs 58,793) and is cached 0-30% of the time; with its tools described in
|
|
5
|
+
// the system prompt and its calls and results written as text it is cached whole from the second send on (57,088 of
|
|
6
|
+
// 57,188 tokens). A tool-using review sends its whole history every turn, so that is the difference between paying
|
|
7
|
+
// $0.25/M (list) and $0.03/M for nearly all of its input. The text protocol is DeepSeek's DSML without its marker
|
|
8
|
+
// ("<function_calls><invoke name><parameter name string>"), the shape particle-1 writes on its own when given tools as
|
|
9
|
+
// text (DeepSeek V3.2's chat template words it so; the provider drops or breaks the `|DSML|` marker in what it streams);
|
|
10
|
+
// a reply with the marker, or a `<tool_call>{json}</tool_call>` block, is read too. Calls and results are rebuilt from
|
|
11
|
+
// history the same way every turn, so each request's prefix is byte for byte the last one's.
|
|
12
|
+
const OPEN = "<tool_call>";
|
|
13
|
+
const CLOSE = "</tool_call>";
|
|
14
|
+
/** The system prompt's tools section, in DeepSeek V3.2's own words: how to call, then each tool's schema. */
|
|
15
|
+
export function toolsSection(tools) {
|
|
16
|
+
return [
|
|
17
|
+
"## Tools",
|
|
18
|
+
"You have access to a set of tools you can use to answer the user's question.",
|
|
19
|
+
'You can invoke functions by writing a "<function_calls>" block like the following as part of your reply to the user:',
|
|
20
|
+
"<function_calls>",
|
|
21
|
+
'<invoke name="$FUNCTION_NAME">',
|
|
22
|
+
'<parameter name="$PARAMETER_NAME" string="true|false">$PARAMETER_VALUE</parameter>',
|
|
23
|
+
"...",
|
|
24
|
+
"</invoke>",
|
|
25
|
+
'<invoke name="$FUNCTION_NAME2">',
|
|
26
|
+
"...",
|
|
27
|
+
"</invoke>",
|
|
28
|
+
"</function_calls>",
|
|
29
|
+
"",
|
|
30
|
+
'String and scalar parameters should be specified as is without any escaping or quotes, while lists and objects should use JSON format. The "string" attribute should be set to "true" for string type parameters and "false" for other types (numbers, booleans, arrays, objects).',
|
|
31
|
+
"Several invokes in one block run together, in order. Write nothing after the block; the results come back to you in a <function_results> block. A reply with no block is your final answer.",
|
|
32
|
+
"",
|
|
33
|
+
"### Available Tool Schemas",
|
|
34
|
+
"",
|
|
35
|
+
"<functions>",
|
|
36
|
+
...tools.map((tool) => JSON.stringify({ name: tool.name, description: (tool.description ?? "").trim(), parameters: tool.parameters ?? { type: "object", properties: {} } })),
|
|
37
|
+
"</functions>",
|
|
38
|
+
"",
|
|
39
|
+
"You MUST strictly follow the above defined tool name and parameter schemas to invoke tool calls.",
|
|
40
|
+
].join("\n");
|
|
41
|
+
}
|
|
42
|
+
/** One call as a DSML invoke, as `toolsSection` asks for it. */
|
|
43
|
+
const invokeOf = (name, args) => {
|
|
44
|
+
const params = Object.entries((args && typeof args === "object" ? args : {})).map(([key, value]) => `<parameter name="${key}" string="${typeof value === "string"}">${typeof value === "string" ? value : JSON.stringify(value)}</parameter>`);
|
|
45
|
+
return [`<invoke name="${name}">`, ...params, "</invoke>"].join("\n");
|
|
46
|
+
};
|
|
47
|
+
/** `context` with its tools in its system prompt and every tool call and result in its history written as text. */
|
|
48
|
+
export function toolsAsText(context) {
|
|
49
|
+
const tools = context.tools ?? [];
|
|
50
|
+
const messages = [];
|
|
51
|
+
for (const message of context.messages) {
|
|
52
|
+
if (message.role === "assistant" && Array.isArray(message.content)) {
|
|
53
|
+
const said = message.content.filter((part) => part.type === "text").map((part) => part.text ?? "").join("").trim();
|
|
54
|
+
const calls = message.content.filter((part) => part.type === "toolCall").map((part) => invokeOf(part.name ?? "", part.arguments));
|
|
55
|
+
const text = [said, calls.length ? ["<function_calls>", ...calls, "</function_calls>"].join("\n") : ""].filter(Boolean).join("\n\n");
|
|
56
|
+
messages.push({ ...message, content: [{ type: "text", text: text || "(no text)" }] });
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (message.role === "toolResult") {
|
|
60
|
+
const parts = Array.isArray(message.content) ? message.content : [{ type: "text", text: String(message.content) }];
|
|
61
|
+
const body = parts.filter((part) => part.type === "text").map((part) => part.text ?? "").join("\n");
|
|
62
|
+
const images = parts.filter((part) => part.type === "image");
|
|
63
|
+
const text = `<result tool="${message.toolName ?? ""}"${message.isError ? ' error="true"' : ""}>\n${body}\n</result>`;
|
|
64
|
+
// Results of one turn's calls go together, as one user message, in the order called.
|
|
65
|
+
const last = messages[messages.length - 1];
|
|
66
|
+
if (last?.role === "user" && last.fromTools === true && Array.isArray(last.content))
|
|
67
|
+
last.content.push({ type: "text", text: `\n${text}` }, ...images);
|
|
68
|
+
else
|
|
69
|
+
messages.push({ role: "user", content: [{ type: "text", text: `<function_results>\n${text}` }, ...images], timestamp: message.timestamp, fromTools: true });
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
messages.push(message);
|
|
73
|
+
}
|
|
74
|
+
for (const message of messages) {
|
|
75
|
+
if (message.fromTools === true && Array.isArray(message.content))
|
|
76
|
+
message.content.push({ type: "text", text: "\n</function_results>" });
|
|
77
|
+
delete message.fromTools;
|
|
78
|
+
}
|
|
79
|
+
const system = [context.systemPrompt ?? "", tools.length ? toolsSection(tools) : ""].filter(Boolean).join("\n\n");
|
|
80
|
+
return { ...(system ? { systemPrompt: system } : {}), messages };
|
|
81
|
+
}
|
|
82
|
+
/** A reply's text read as text and calls: each `<tool_call>` block whose JSON names a tool, in order; the rest is
|
|
83
|
+
* text. A block whose JSON does not parse stays text. */
|
|
84
|
+
export function callsOfText(said, tools = []) {
|
|
85
|
+
const calls = [];
|
|
86
|
+
// DSML with its marker or without (the provider may drop it, or put zero-width spaces in its tags), as the model
|
|
87
|
+
// writes it: `<function_calls>` (or "<calls>"), each `<invoke name="...">` with `<parameter name="..." string="...">`
|
|
88
|
+
// values, or `<invoke name="...", "arguments": {...}}`. The slips particle-1 makes are read too: the tool named by a
|
|
89
|
+
// '<parameter name="invoke">', a `<name>value</parameter>` parameter, and an invoke with no name (the one tool whose
|
|
90
|
+
// schema takes every parameter given and all its required ones).
|
|
91
|
+
const text = said.replace(/\u200b/g, "").replace(/|DSML|\s*/g, "");
|
|
92
|
+
const first = text.search(/<(?:function_calls|calls|invoke\b|parameter\b)/);
|
|
93
|
+
const groups = [];
|
|
94
|
+
const current = () => groups[groups.length - 1] ?? (groups.push({ args: {} }), groups[0]);
|
|
95
|
+
// A string is written unescaped, so a value may hold "</parameter>" itself (a file that writes this protocol, an
|
|
96
|
+
// example in a comment): a value ends at the closing tag that the call's next tag, or the reply's end, follows.
|
|
97
|
+
const token = /<invoke\s+name="([^"]+)"(\s*,\s*"arguments"\s*:\s*)?|<\/invoke>|<parameter\s+name="([^"]+)"(?:\s+string="(true|false)")?\s*>([\s\S]*?)<\/(?:parameter|invoke)>(?=\s*(?:<parameter\s+name=|<\/?invoke\b|<\/function_calls>|<\/calls>|<[A-Za-z_][\w-]*>[^<]*<\/parameter>|$))|<([A-Za-z_][\w-]*)>([^<]*)<\/parameter>/g;
|
|
98
|
+
const block = first < 0 ? "" : text.slice(first);
|
|
99
|
+
let closed = false;
|
|
100
|
+
// A call the reply did not finish (cut off, or a tag opened and never closed) is never run on what it holds so far:
|
|
101
|
+
// the reply is broken, and asked again.
|
|
102
|
+
let unfinished = false;
|
|
103
|
+
let end = 0;
|
|
104
|
+
for (const match of block.matchAll(token)) {
|
|
105
|
+
const [whole, invoked, jsonArgs, key, isString, value, slipKey, slipValue] = match;
|
|
106
|
+
if (/<(?:invoke|parameter)\b/.test(block.slice(end, match.index)))
|
|
107
|
+
unfinished = true;
|
|
108
|
+
end = match.index + whole.length;
|
|
109
|
+
if (invoked !== undefined) {
|
|
110
|
+
groups.push({ name: invoked, args: {} });
|
|
111
|
+
closed = false;
|
|
112
|
+
if (jsonArgs) {
|
|
113
|
+
const object = objectAt(block, end);
|
|
114
|
+
if (object === undefined)
|
|
115
|
+
unfinished = true;
|
|
116
|
+
else {
|
|
117
|
+
end += object.length;
|
|
118
|
+
try {
|
|
119
|
+
Object.assign(groups[groups.length - 1].args, JSON.parse(object));
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
unfinished = true;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
else if (whole === "</invoke>")
|
|
128
|
+
closed = true;
|
|
129
|
+
else if (key === "invoke" && value.includes("<parameter")) {
|
|
130
|
+
// `<parameter name="invoke">` opening a call whose name never came: its first parameter is inside.
|
|
131
|
+
groups.push({ args: {} });
|
|
132
|
+
closed = false;
|
|
133
|
+
const inner = /<parameter\s+name="([^"]+)"(?:\s+string="(true|false)")?\s*>([\s\S]*)$/.exec(value);
|
|
134
|
+
if (inner)
|
|
135
|
+
current().args[inner[1]] = valueOf(inner[3], inner[2]);
|
|
136
|
+
}
|
|
137
|
+
else if (key === "invoke" || key === "name" && current().name === undefined && tools.some((tool) => tool.name === value)) {
|
|
138
|
+
groups.push({ name: value.trim(), args: {} });
|
|
139
|
+
closed = false;
|
|
140
|
+
}
|
|
141
|
+
else if (key !== undefined) {
|
|
142
|
+
if (closed)
|
|
143
|
+
groups.push({ args: {} });
|
|
144
|
+
closed = false;
|
|
145
|
+
current().args[key] = valueOf(value, isString);
|
|
146
|
+
}
|
|
147
|
+
else if (slipKey !== undefined && !["function_calls", "calls", "invoke", "parameter"].includes(slipKey) && !(slipKey in current().args))
|
|
148
|
+
current().args[slipKey] = valueOf(slipValue, undefined);
|
|
149
|
+
}
|
|
150
|
+
if (first >= 0 && /<(?:invoke|parameter)\b/.test(block.slice(end)))
|
|
151
|
+
unfinished = true;
|
|
152
|
+
if (unfinished)
|
|
153
|
+
return { text: text.trim(), calls: [], broken: true };
|
|
154
|
+
for (const group of groups) {
|
|
155
|
+
const name = group.name ?? nameOf(group.args, tools);
|
|
156
|
+
if (name !== undefined)
|
|
157
|
+
calls.push({ name, arguments: group.args });
|
|
158
|
+
}
|
|
159
|
+
if (calls.length)
|
|
160
|
+
return { text: text.slice(0, first).trim(), calls };
|
|
161
|
+
if (first >= 0 && /<(?:function_calls|calls|invoke|parameter)\b/.test(text))
|
|
162
|
+
return { text: text.trim(), calls, broken: true };
|
|
163
|
+
// A `<tool_call>{"name": ..., "arguments": ...}</tool_call>` block.
|
|
164
|
+
let rest = "";
|
|
165
|
+
let at = 0;
|
|
166
|
+
for (;;) {
|
|
167
|
+
const open = text.indexOf(OPEN, at);
|
|
168
|
+
if (open < 0)
|
|
169
|
+
break;
|
|
170
|
+
const close = text.indexOf(CLOSE, open + OPEN.length);
|
|
171
|
+
const raw = text.slice(open + OPEN.length, close < 0 ? undefined : close).trim();
|
|
172
|
+
let call;
|
|
173
|
+
try {
|
|
174
|
+
call = JSON.parse(raw);
|
|
175
|
+
}
|
|
176
|
+
catch {
|
|
177
|
+
call = undefined;
|
|
178
|
+
}
|
|
179
|
+
rest += text.slice(at, open);
|
|
180
|
+
if (call && typeof call.name === "string") {
|
|
181
|
+
const args = typeof call.arguments === "string" ? valueOf(call.arguments, "false") : call.arguments;
|
|
182
|
+
calls.push({ name: call.name, arguments: (args && typeof args === "object" && !Array.isArray(args) ? args : {}) });
|
|
183
|
+
}
|
|
184
|
+
else
|
|
185
|
+
rest += text.slice(open, close < 0 ? undefined : close + CLOSE.length);
|
|
186
|
+
if (close < 0) {
|
|
187
|
+
at = text.length;
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
at = close + CLOSE.length;
|
|
191
|
+
}
|
|
192
|
+
rest += text.slice(at);
|
|
193
|
+
return { text: rest.trim(), calls };
|
|
194
|
+
}
|
|
195
|
+
/** The one tool whose schema takes every argument given and all its required ones, or undefined. */
|
|
196
|
+
function nameOf(args, tools) {
|
|
197
|
+
const keys = Object.keys(args);
|
|
198
|
+
if (!keys.length)
|
|
199
|
+
return undefined;
|
|
200
|
+
const fits = tools.filter((tool) => {
|
|
201
|
+
const schema = (tool.parameters ?? {});
|
|
202
|
+
const known = Object.keys(schema.properties ?? {});
|
|
203
|
+
const props = (schema.properties ?? {});
|
|
204
|
+
return keys.every((key) => known.includes(key) && (!props[key]?.enum || props[key].enum.includes(args[key]))) && (schema.required ?? []).every((key) => keys.includes(key));
|
|
205
|
+
});
|
|
206
|
+
return fits.length === 1 ? fits[0].name : undefined;
|
|
207
|
+
}
|
|
208
|
+
/** A parameter's value: as written when it is a string, else its JSON (a number, a list, an object), else as written. */
|
|
209
|
+
function valueOf(value, isString) {
|
|
210
|
+
if (isString === "true")
|
|
211
|
+
return value;
|
|
212
|
+
try {
|
|
213
|
+
return JSON.parse(value.trim());
|
|
214
|
+
}
|
|
215
|
+
catch {
|
|
216
|
+
return value;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
/** The JSON object that starts at `at` in `text` (its braces matched, strings skipped), or undefined. */
|
|
220
|
+
function objectAt(text, at) {
|
|
221
|
+
if (text[at] !== "{")
|
|
222
|
+
return undefined;
|
|
223
|
+
let depth = 0;
|
|
224
|
+
for (let i = at; i < text.length; i++) {
|
|
225
|
+
const c = text[i];
|
|
226
|
+
if (c === '"') {
|
|
227
|
+
for (i++; i < text.length && text[i] !== '"'; i++)
|
|
228
|
+
if (text[i] === "\\")
|
|
229
|
+
i++;
|
|
230
|
+
}
|
|
231
|
+
else if (c === "{")
|
|
232
|
+
depth++;
|
|
233
|
+
else if (c === "}" && --depth === 0)
|
|
234
|
+
return text.slice(at, i + 1);
|
|
235
|
+
}
|
|
236
|
+
return undefined;
|
|
237
|
+
}
|
|
@@ -30,6 +30,8 @@ export interface DecisionDriver {
|
|
|
30
30
|
decisionRequests(): Record<string, {
|
|
31
31
|
status: string;
|
|
32
32
|
}>;
|
|
33
|
+
/** Resolves once the driver's commits so far are durable (a request it ended, before the run parks on it). */
|
|
34
|
+
flush(): Promise<void>;
|
|
33
35
|
}
|
|
34
36
|
/** The run's spend cap over the workflow's adapters (app.ts's budget: stepped/failing/capStopped and the decision cap),
|
|
35
37
|
* injected so this module holds no money of its own. Each wrapper is applied to its adapter where app.ts applied it; a run
|
|
@@ -40,9 +42,12 @@ export interface WorkflowCap {
|
|
|
40
42
|
node<F>(fn: F): F;
|
|
41
43
|
/** stepped(failing(·)): a call node, which waits for a raise on a held effect and goes again. */
|
|
42
44
|
effect<F>(fn: F): F;
|
|
43
|
-
/**
|
|
44
|
-
*
|
|
45
|
+
/** A decision, before the driver admits its request: priced, or parked by a pause. The driver tells a replayed request,
|
|
46
|
+
* which holds nothing. */
|
|
45
47
|
judge<F>(fn: F, driver?: DecisionDriver): F;
|
|
48
|
+
/** A decision's judge once the driver has admitted its request: held through the kernel cap, sent, and settled. Absent:
|
|
49
|
+
* the judge runs as given. */
|
|
50
|
+
admitted?<F>(fn: F): F;
|
|
46
51
|
/** A call node's wait on a raise (deps.held), left out of its deadline. */
|
|
47
52
|
held?(path: string): number;
|
|
48
53
|
}
|
|
@@ -6,6 +6,7 @@ const identityCap = { node: (fn) => fn, effect: (fn) => fn, judge: (fn) => fn };
|
|
|
6
6
|
* Pass the result to createWorkflowLoop's spec.build. */
|
|
7
7
|
export function workflowHost(deps) {
|
|
8
8
|
const cap = deps.cap ?? identityCap;
|
|
9
|
+
const admitted = (fn) => (cap.admitted ? cap.admitted(fn) : fn);
|
|
9
10
|
/** A model node's agent: its tier's model, the tools it names, and the extensions they come from (app.ts nodeAgent). */
|
|
10
11
|
const nodeAgent = (node) => {
|
|
11
12
|
const bindings = (node.tools ?? []).flatMap((name) => deps.nodeTool(name) ?? []);
|
|
@@ -38,7 +39,8 @@ export function workflowHost(deps) {
|
|
|
38
39
|
const recovered = withRecovery(driver, {
|
|
39
40
|
runNode: nodes.on(taskScope(runtime), context).runNode,
|
|
40
41
|
runEffect: deps.runEffect,
|
|
41
|
-
|
|
42
|
+
// The judge the driver asks once it has admitted a request: the cap holds, sends and settles it there (admitted).
|
|
43
|
+
...(deps.decisionProviders ? { runJudge: admitted(judgeFromProviders({ ...deps.decisionProviders, loadImage: deps.loadImage })), decisionProviders: deps.decisionProviders } : {}),
|
|
42
44
|
recordDecision: async (receipt, exchange) => {
|
|
43
45
|
await decisions.recordDecision(receipt, exchange);
|
|
44
46
|
deps.onReceipt?.(receipt);
|
|
@@ -4,7 +4,7 @@ import type { Models } from "@earendil-works/pi-ai";
|
|
|
4
4
|
import type { Workflow } from "@parcha/agentrun-dsl";
|
|
5
5
|
import { type WorkflowTaskHost } from "@parcha/agentrun-pi/durable";
|
|
6
6
|
import { type BudgetData, type EndData } from "./journal-kinds.js";
|
|
7
|
-
import { type Claim, type LoopFactory } from "./loop-contract.js";
|
|
7
|
+
import { type Claim, type Journal, type LoopFactory } from "./loop-contract.js";
|
|
8
8
|
/** A cap refusal, as the kernel cap hands one to parkOf/checkRaise (the loop never imports the cap; its rule is handed in
|
|
9
9
|
* via the spec, so flat or tiered pricing is the cap's, not this loop's). */
|
|
10
10
|
export type CapRefusal = {
|
|
@@ -94,6 +94,12 @@ export interface WorkflowRunSpec {
|
|
|
94
94
|
* once, however the run ended (ended, stopped, failed, parked or interrupted), so a parked or resumed run starts fresh
|
|
95
95
|
* proxies on its next claim. Never throws out. Absent: nothing to let go. */
|
|
96
96
|
readonly release?: () => Promise<void>;
|
|
97
|
+
/** Resolves once every model request the spec admitted has been booked, or a bound has passed (then a request left
|
|
98
|
+
* unbooked reads at its hold and bound). A request its node let go of (a stop) is booked only once the provider's side
|
|
99
|
+
* ends, which can be after the node ended: once the workflow's task is over, the loop waits for this before it closes
|
|
100
|
+
* the Harness the bookings are written through. Not on a park or a lost claim: the next claim books a request left
|
|
101
|
+
* open there as cut. Absent: nothing to wait for. */
|
|
102
|
+
readonly settle?: () => Promise<void>;
|
|
97
103
|
}
|
|
98
104
|
/** What the interpreter's host may ask of the loop while it runs. */
|
|
99
105
|
export interface WorkflowHostHooks {
|
|
@@ -121,6 +127,9 @@ export declare const isWorkflowRevision: (revision: {
|
|
|
121
127
|
* the claim opens from the store (redact.ts holdClaimed). */
|
|
122
128
|
export interface WorkflowSpecRun {
|
|
123
129
|
readonly redact?: (text: string) => string;
|
|
130
|
+
/** A fresh journal of the claim, for what the spec reads from the run's records at its end (its decisions' booked
|
|
131
|
+
* cost): a fresh one, since the Harness closes its own before the end is written. */
|
|
132
|
+
readonly journal?: () => Journal;
|
|
124
133
|
}
|
|
125
134
|
/** Loops for workflow runs: `spec(claim)` gives each claim's run what it runs (its workflow, input, models and host). */
|
|
126
135
|
export declare function createWorkflowLoop(specOf: (claim: Claim, run: WorkflowSpecRun) => WorkflowRunSpec | Promise<WorkflowRunSpec>): LoopFactory;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// The workflow loop on the runner (design: "Runners carry many loops"; the lead's ruling, workflow agents keep running
|
|
2
2
|
// after the cutover). A run of a workflow revision, which the runner claims like any run: this loop is its driver, so the
|
|
3
|
-
// claim, the fence, a cancel and the end commit are its. The DSL's durable runner (
|
|
3
|
+
// claim, the fence, a cancel and the end commit are its. The DSL's durable runner (workflow-run.ts
|
|
4
4
|
// startWorkflowRevision over agentrun-pi's workflow task) runs the revision's workflow UNCHANGED — the same nodes,
|
|
5
5
|
// decisions, call tools and cap it ran with in the per-run process — on the run's journal in the one store (A,
|
|
6
6
|
// deps.journal(claim)) in place of a per-run store file. The interpreter's host (model nodes on the run's models, call
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
import { BACKGROUND_CONTEXT, withAbortSignal } from "@earendil-works/chord/context";
|
|
21
21
|
import { createRegistry, Harness, ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
|
|
22
22
|
import { createWorkflowExtension } from "@parcha/agentrun-pi/durable";
|
|
23
|
-
import { readWorkflowRun, startWorkflowRevision, workflowCarry } from "
|
|
23
|
+
import { readWorkflowRun, startWorkflowRevision, workflowCarry } from "../workflow-run.js";
|
|
24
24
|
import { KINDS } from "./journal-kinds.js";
|
|
25
25
|
import { endedBy } from "./loop-contract.js";
|
|
26
26
|
/** The most the end's patch (cost and metrics) may take before the end is written without it (the pi loop's CUT_STEP_MS). */
|
|
@@ -213,7 +213,7 @@ function workflowLoop(specOf, deps) {
|
|
|
213
213
|
const parkController = new AbortController();
|
|
214
214
|
let heldRefusal;
|
|
215
215
|
const context = withAbortSignal(AbortSignal.any([deps.signal, parkController.signal]), BACKGROUND_CONTEXT);
|
|
216
|
-
spec = await specOf(claim, deps.redact ? { redact: deps.redact } : {});
|
|
216
|
+
spec = await specOf(claim, { ...(deps.redact ? { redact: deps.redact } : {}), journal: () => deps.journal(claim) });
|
|
217
217
|
claimNow = claim;
|
|
218
218
|
specReady();
|
|
219
219
|
const revision = { id: spec.revisionId, kind: "workflow", body: { workflow: spec.workflow, tools: [...spec.tools] } };
|
|
@@ -263,8 +263,10 @@ function workflowLoop(specOf, deps) {
|
|
|
263
263
|
void error;
|
|
264
264
|
return { state: "interrupted" };
|
|
265
265
|
}
|
|
266
|
-
// The task is terminal.
|
|
267
|
-
//
|
|
266
|
+
// The task is terminal. Its model requests booked (a stopped one books once its provider's side ends, after the node
|
|
267
|
+
// let go of it), close the Harness, then read the run's view from its journal and write the end, both on a fresh
|
|
268
|
+
// journal of the same claim (the Harness closed its own).
|
|
269
|
+
await spec.settle?.().catch(() => undefined);
|
|
268
270
|
await closeHarness();
|
|
269
271
|
const endJournal = deps.journal(claim);
|
|
270
272
|
// A person stopped or cancelled: the run ends stopped whatever the workflow's own outcome (its last node may have
|
|
@@ -279,6 +281,12 @@ function workflowLoop(specOf, deps) {
|
|
|
279
281
|
const { output } = await readWorkflowRun({ runId: claim.runId, storage: endJournal, revision }, { context });
|
|
280
282
|
return await writeEnd(endJournal, context, { ...carry, output: output ?? null });
|
|
281
283
|
}
|
|
284
|
+
// An escalated run's review, as main's server kept it (runs.ts): the escalation's kind, the escalate node's label (else
|
|
285
|
+
// the node it escalated at), and its summary (else the run's), kept on its end for the run's `review`.
|
|
286
|
+
if (carry.state === "escalated") {
|
|
287
|
+
const { escalation, escalatedAt } = await readWorkflowRun({ runId: claim.runId, storage: endJournal, revision }, { context });
|
|
288
|
+
return await writeEnd(endJournal, context, { ...carry, review: { kind: escalation?.kind ?? null, node: escalation?.label ?? escalatedAt?.label ?? null, reason: escalation?.summary ?? carry.summary } });
|
|
289
|
+
}
|
|
282
290
|
return await writeEnd(endJournal, context, carry);
|
|
283
291
|
}
|
|
284
292
|
finally {
|
|
@@ -303,7 +311,7 @@ function workflowLoop(specOf, deps) {
|
|
|
303
311
|
async function writeEnd(journal, context, carry) {
|
|
304
312
|
const state = carry.state === "failed" ? "failed" : carry.state === "stopped" ? "stopped" : "ended";
|
|
305
313
|
const outcome = carry.state === "escalated" ? "escalated" : undefined;
|
|
306
|
-
const base = { state, summary: carry.summary, ...(outcome ? { outcome } : {}), ...(carry.output !== undefined ? { output: carry.output } : {}) };
|
|
314
|
+
const base = { state, summary: carry.summary, ...(outcome ? { outcome } : {}), ...(carry.output !== undefined ? { output: carry.output } : {}), ...(carry.review ? { review: carry.review } : {}) };
|
|
307
315
|
const patch = await endPatchOf(spec, base);
|
|
308
316
|
const data = { ...base, ...(patch.costUsd !== undefined ? { costUsd: patch.costUsd } : {}), ...(patch.metrics !== undefined ? { metrics: patch.metrics } : {}) };
|
|
309
317
|
const runPatch = {
|
|
@@ -4,6 +4,7 @@ import { type BeforeRequest, type Wire } from "@parcha/agentrun-kernel";
|
|
|
4
4
|
import { type ProviderPolicy, type ProxyUsage } from "@parcha/agentrun-kernel/host";
|
|
5
5
|
import { type CapModel } from "@parcha/agentrun-kernel/kernel/cap";
|
|
6
6
|
import { type Tier } from "../model.js";
|
|
7
|
+
import { deniedText } from "../refusal-words.js";
|
|
7
8
|
import { type PaidBooking } from "../paid-calls.js";
|
|
8
9
|
import { type RunTools } from "@parcha/agentrun-kernel/kernel/cap";
|
|
9
10
|
import { type ModelRoute } from "./model-route.js";
|
|
@@ -20,6 +21,8 @@ export declare const SUBMIT_TOOL = "submit";
|
|
|
20
21
|
export interface WorkflowProvider {
|
|
21
22
|
/** The model id the node asks for (the tier's model). */
|
|
22
23
|
readonly modelId: string;
|
|
24
|
+
/** The model as the run names it (`provider/model-id`): what an `llm` call's answer says it ran on. Absent: `modelId`. */
|
|
25
|
+
readonly named?: string;
|
|
23
26
|
/** The wire the proxy forwards on, and pi-ai's client of it speaks to the proxy (port-models.ts sessionProvider). */
|
|
24
27
|
readonly api: Wire;
|
|
25
28
|
/** The catalog's entry for the model (whether it reasons, its window), as pi's session takes it (model-route.ts). */
|
|
@@ -107,6 +110,7 @@ export declare function pauseAtEffects(cap: WorkflowCap, hooks: Pick<WorkflowHos
|
|
|
107
110
|
export type CallHold = {
|
|
108
111
|
readonly usd: number;
|
|
109
112
|
readonly name: string;
|
|
113
|
+
readonly tool?: string;
|
|
110
114
|
readonly basis: string;
|
|
111
115
|
readonly chargedBy?: string;
|
|
112
116
|
readonly llm?: {
|
|
@@ -138,6 +142,16 @@ export declare const heldBooking: () => {
|
|
|
138
142
|
readonly paid: PaidBooking;
|
|
139
143
|
} | undefined;
|
|
140
144
|
export declare const releaseCallHold: () => Promise<void>;
|
|
145
|
+
/** A call tool's permission now, as main's per-run process read it at each call node (app.ts:382-384, the gate's
|
|
146
|
+
* policy): the revision's tool settings and approvals over the server's, the server's read again from the store at each
|
|
147
|
+
* call, so a deny or an ask set while the run goes reaches its next call. A read that fails is unread, as the agentic
|
|
148
|
+
* gate's is (adapter-run-spec.ts storeSettings): with no good read before it every tool asks, so a call node is refused
|
|
149
|
+
* (the revision's own allow never stands alone over settings no read has seen); after one, the gate holds to that read
|
|
150
|
+
* marked unread (RunGate.serverSettings), so its denies still refuse. */
|
|
151
|
+
type CallPolicy = (tool: string) => Promise<{
|
|
152
|
+
permission: "allow" | "ask" | "deny";
|
|
153
|
+
denyFrom: Parameters<typeof deniedText>[2];
|
|
154
|
+
}>;
|
|
141
155
|
/** `cap` with a call node's recorded tool failure thrown as the node's failure, as main's `failing` (app.ts:417-420):
|
|
142
156
|
* the driver records the effect's outcome ({ TOOL_FAILED: words }) as its receipt, and this, past the driver, throws it
|
|
143
157
|
* as an EffectFailure in those words, so the call node fails and the run with it in the tool's words. Applied outside
|
|
@@ -151,6 +165,13 @@ export declare const RUNNER_NODE_TOOLS: readonly string[];
|
|
|
151
165
|
/** A node naming a tool the runner does not bind for a model node yet: the run is refused at its claim in these words,
|
|
152
166
|
* the tool never offered and never silently dropped. */
|
|
153
167
|
export declare const nodeToolUnboundText: (tool: string) => string;
|
|
168
|
+
/** A model node's tool call as its pi-durable task runs it: its args, the task's api and the call's context. */
|
|
169
|
+
type GatedExecute = (args: never, api: never, context: never) => Promise<unknown>;
|
|
170
|
+
/** `execute` behind the gate, for the tool `name`. A call it lets through is marked so in its task first, so when
|
|
171
|
+
* pi-durable's recovery runs the same call again on a later claim (the first attempt cut with its claim, maybe after it
|
|
172
|
+
* was sent) and the tool is now denied or set to ask, the refusal says that whether it took effect is not known
|
|
173
|
+
* (RAN_UNKNOWN), never that it was not run or that nothing was sent and nothing was charged. */
|
|
174
|
+
export declare function gatedNodeCall(name: string, policy: CallPolicy, execute: GatedExecute): GatedExecute;
|
|
154
175
|
/** The tool names a workflow's model node offers its model: the node's `submit` (pi's SUBMIT_TOOL) and every tool the
|
|
155
176
|
* workflow's model nodes name. */
|
|
156
177
|
export declare function nodeOffer(workflow: Workflow): string[];
|