@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
|
@@ -15,7 +15,7 @@ import { defineExtension, ROOT_CONVERSATION_ID, wrapTool } from "@earendil-works
|
|
|
15
15
|
import { chargedCost, DecisionProviderError, EffectFailure, inspectWorkflow } from "@parcha/agentrun-dsl";
|
|
16
16
|
import { modelPortFor } from "@parcha/agentrun-kernel";
|
|
17
17
|
import { startModelProxy } from "@parcha/agentrun-kernel/host";
|
|
18
|
-
import { CapRefused, checkRaise, DecisionPriceUnreadable, DECISION_SESSION, followUpOf, parkOf, runCap } from "@parcha/agentrun-kernel/kernel/cap";
|
|
18
|
+
import { CapRefused, checkRaise, DecisionPriceUnreadable, DECISION_SESSION, followUpOf, freeCeilingMessage, freeModelRequestsOf, parkOf, runCap } from "@parcha/agentrun-kernel/kernel/cap";
|
|
19
19
|
import { completer } from "../llm.js";
|
|
20
20
|
// The decision providers' list prices, the catalog's read and the replay check (decision-cap.ts), with holdOf, which the
|
|
21
21
|
// parity tests hold this cap's figures to.
|
|
@@ -35,19 +35,20 @@ import { searchArgs, WEB_SEARCH_TOOL } from "../web-search.js";
|
|
|
35
35
|
import { money, pricingOf, requestPrice, TOOL_SESSION } from "@parcha/agentrun-kernel/kernel/cap";
|
|
36
36
|
import { claimSecrets, withModelKeys } from "./claim-secrets.js";
|
|
37
37
|
import { routeOf } from "./model-route.js";
|
|
38
|
-
import { PI_WIRES, storeSettings } from "./adapter-run-spec.js";
|
|
38
|
+
import { capModelOf, PI_WIRES, storeSettings } from "./adapter-run-spec.js";
|
|
39
39
|
import { policyFor } from "./adapters/pi.js";
|
|
40
40
|
import { sessionProvider } from "../port-models.js";
|
|
41
41
|
import { journalSessions } from "./sessions.js";
|
|
42
42
|
import { KINDS, NODE_LOG_SESSION, WORKFLOW_SESSION } from "./journal-kinds.js";
|
|
43
43
|
import { cutStrings } from "../key-refusal.js";
|
|
44
|
-
import { CLOSE_MS
|
|
44
|
+
import { CLOSE_MS } from "./loop.js";
|
|
45
45
|
import { PAUSED_WORDS } from "./workflow-loop.js";
|
|
46
46
|
import { heldRedactor, holdClaimed } from "./redact.js";
|
|
47
47
|
import { holdStored } from "./store-secrets.js";
|
|
48
48
|
import { workflowHost } from "./workflow-host.js";
|
|
49
49
|
import { SUBMIT_TOOL } from "../workflow/host-tools.js";
|
|
50
|
-
import {
|
|
50
|
+
import { endCostOf, runCostOf } from "./metrics.js";
|
|
51
|
+
import { journalEntries } from "./journal-reader.js";
|
|
51
52
|
/** The one session key the workflow's model requests book under (the run's one booking sums it, runBooking). */
|
|
52
53
|
const SESSION = WORKFLOW_SESSION;
|
|
53
54
|
/** A call node's tool failure and a cap-held effect, as the runner's effect completed them (the loop's `failing` reads the
|
|
@@ -76,8 +77,12 @@ export async function providerFromRoute(route) {
|
|
|
76
77
|
...(route.provider.headers ? { headers: route.provider.headers } : {}),
|
|
77
78
|
policy: await policyFor(route.provider, route.model, []),
|
|
78
79
|
price: (route.price ?? (() => null)),
|
|
79
|
-
|
|
80
|
+
// As a pi turn's (capModelOf): a ChatGPT plan's route is billed to the plan (CapModel.plan), and a model serve has no
|
|
81
|
+
// price for (a router's zeros, a gateway model nothing prices) has none, never its placeholder's $0: a cap refuses it.
|
|
82
|
+
capModel: capModelOf(route),
|
|
80
83
|
...(route.fetch ? { fetch: route.fetch } : {}),
|
|
84
|
+
...(route.provider.plan ? { plan: true } : {}),
|
|
85
|
+
...(route.provider.refused ? { refused: route.provider.refused } : {}),
|
|
81
86
|
};
|
|
82
87
|
}
|
|
83
88
|
/** The newest raise's cap on the run's root, else none: the effective cap after takeRaises wrote this claim's raise, read
|
|
@@ -116,7 +121,6 @@ function capRuleOf(capUsd) {
|
|
|
116
121
|
/** The claim-time builder: `specOf(claim)` the loop calls. Reads the run's launch and revision, resolves each tier's
|
|
117
122
|
* provider, and returns the spec. The model proxies and the booking are started per claim (release closes them). */
|
|
118
123
|
export function workflowSpecOf(deps) {
|
|
119
|
-
const now = deps.now ?? Date.now;
|
|
120
124
|
// The proxies a claim started: closed by the spec's release once the claim is done, or here when the claim fails before
|
|
121
125
|
// its spec is returned (the loop then has no spec to release), so a failed claim leaves no proxy listening.
|
|
122
126
|
return async (claim, run) => {
|
|
@@ -183,7 +187,10 @@ export function workflowSpecOf(deps) {
|
|
|
183
187
|
const offered = nodeOffer(claimed.workflow);
|
|
184
188
|
for (const [tier, provider] of providers) {
|
|
185
189
|
const proxy = await startModelProxy({
|
|
186
|
-
|
|
190
|
+
// Each request names its tier's route (ModelRequest.route), so the cap prices it as that tier books it: two tiers
|
|
191
|
+
// on one model id (a plan's and a paid one) are held apart, never at the other's price (capModelOf).
|
|
192
|
+
route: providerId(tier),
|
|
193
|
+
policy: await policyFor({ api: provider.api, origin: provider.origin, credential: provider.credential, ...(provider.headers ? { headers: provider.headers } : {}), ...(provider.plan ? { plan: true } : {}) }, provider.modelId, offered),
|
|
187
194
|
hooks: hooks.port,
|
|
188
195
|
model: provider.modelId,
|
|
189
196
|
origin: provider.origin,
|
|
@@ -191,6 +198,7 @@ export function workflowSpecOf(deps) {
|
|
|
191
198
|
price: provider.price,
|
|
192
199
|
...(provider.headers ? { headers: provider.headers } : {}),
|
|
193
200
|
...(provider.fetch ? { fetch: provider.fetch } : {}),
|
|
201
|
+
...(provider.refused ? { credentialRefused: provider.refused } : {}),
|
|
194
202
|
}, randomBytes(32).toString("base64url"));
|
|
195
203
|
proxies.push(proxy);
|
|
196
204
|
// pi-ai's client of the provider's wire at its proxy (port-models.ts sessionProvider), as pi's session reaches its own.
|
|
@@ -203,11 +211,25 @@ export function workflowSpecOf(deps) {
|
|
|
203
211
|
throw new Error(`the workflow names tier ${String(tier)}, which this run has no model for`);
|
|
204
212
|
return { provider: providerId(providers.has(resolved) ? resolved : "default"), modelId: provider.modelId, ...(provider.named ? { named: provider.named } : {}) };
|
|
205
213
|
};
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
214
|
+
// The cap's model of a request, by the route its tier's proxy names (the key its request is routed by), never by its
|
|
215
|
+
// bare id: a ChatGPT plan's tier and a paid tier of one model id are priced apart. A request read with no route takes
|
|
216
|
+
// the paid model of its id over a plan's, so a clash is never priced at the plan's $0.
|
|
217
|
+
const capModelOf = (id, route) => {
|
|
218
|
+
if (route !== undefined) {
|
|
219
|
+
for (const [tier, provider] of providers)
|
|
220
|
+
if (providerId(tier) === route)
|
|
221
|
+
return provider.capModel.id === id ? provider.capModel : undefined;
|
|
222
|
+
return undefined;
|
|
223
|
+
}
|
|
224
|
+
let plan;
|
|
225
|
+
for (const provider of providers.values()) {
|
|
226
|
+
if (provider.capModel.id !== id)
|
|
227
|
+
continue;
|
|
228
|
+
if (!provider.capModel.plan)
|
|
209
229
|
return provider.capModel;
|
|
210
|
-
|
|
230
|
+
plan ??= provider.capModel;
|
|
231
|
+
}
|
|
232
|
+
return plan;
|
|
211
233
|
};
|
|
212
234
|
// The cap read against every request: the run's cap, raised in place once harnessReady reads this claim's raise.
|
|
213
235
|
let effectiveCapUsd = claimed.capUsd;
|
|
@@ -262,7 +284,7 @@ export function workflowSpecOf(deps) {
|
|
|
262
284
|
agentId: claimed.agentId,
|
|
263
285
|
revisionId: claimed.revisionId,
|
|
264
286
|
...(claimed.capUsd !== undefined ? { cap: capRuleOf(() => effectiveCapUsd ?? claimed.capUsd) } : {}),
|
|
265
|
-
endPatch: async () => endPatchOf(booking,
|
|
287
|
+
endPatch: async () => endPatchOf(booking, run?.journal),
|
|
266
288
|
build: (loopHooks) => {
|
|
267
289
|
hooks.setPark(loopHooks);
|
|
268
290
|
const hostDeps = {
|
|
@@ -309,7 +331,9 @@ export function workflowSpecOf(deps) {
|
|
|
309
331
|
// refusal's figures are the run's. Wired now the Harness is open; the proxies' hooks forward to the model booking.
|
|
310
332
|
const sessions = journalSessions(harness, context, { flush: () => deps.store.flush(), ...(claim.runner === undefined ? {} : { claim: { runId: claim.runId, runner: claim.runner } }) });
|
|
311
333
|
const writer = await sessions.open(SESSION);
|
|
312
|
-
|
|
334
|
+
// Its model nodes' requests on free models count toward the run's limit of them, capped or not. A step waiting for
|
|
335
|
+
// room under it (a map's branch, beside its siblings' holds) leaves at the run's stop or park, unsent.
|
|
336
|
+
const run = runCap({ sessions: sessions, capUsd: () => effectiveCapUsd, modelOf: capModelOf, freeRequests: freeModelRequestsOf(deps.env ?? process.env), ...(context.abortSignal ? { stopped: context.abortSignal } : {}) });
|
|
313
337
|
booking = await modelPortFor(writer, {
|
|
314
338
|
key: SESSION,
|
|
315
339
|
label: SESSION,
|
|
@@ -365,8 +389,11 @@ export function parkOnRefusal(before, hooks, flight = { count: 0 }, steps) {
|
|
|
365
389
|
const verdict = await before(request);
|
|
366
390
|
// A refusal parks the run, as main's does, unless the request is a call node's (an `llm` call's) in flight: that
|
|
367
391
|
// effect is admitted, and parked unfinished it would be left unknown; refused unsent, its call fails in the cap's
|
|
368
|
-
// words instead (the net under the call's hold, holdAtEffects).
|
|
369
|
-
|
|
392
|
+
// words instead (the net under the call's hold, holdAtEffects). The limit on free-model requests (freeCeilingEnd)
|
|
393
|
+
// ends the run even there: it is for good, every free request after it is refused too, and the run never resumes,
|
|
394
|
+
// so no effect is left to resume; its call's failure would end the run as the call's ("failed at <node>"), not in
|
|
395
|
+
// the limit's words and code.
|
|
396
|
+
if (verdict && "refuse" in verdict && (flight.count === 0 || freeCeilingMessage(verdict.refuse) !== undefined)) {
|
|
370
397
|
const refusal = verdict;
|
|
371
398
|
// Its node: the one workflow step under way (every model request goes through the run's one port, which names no
|
|
372
399
|
// node); none when several run at once, as a map's items do.
|
|
@@ -497,7 +524,7 @@ export function callHoldOf(tool, input, env, modelOfTier) {
|
|
|
497
524
|
const bytes = (text) => (typeof text === "string" ? Buffer.byteLength(text, "utf8") : 0);
|
|
498
525
|
const bound = bytes(input.prompt) + bytes(input.system) + LLM_FRAMING_BYTES;
|
|
499
526
|
const output = typeof input.maxTokens === "number" ? input.maxTokens : Math.max(LLM_DEFAULT_OUTPUT, model.outputCeiling ?? 0);
|
|
500
|
-
const usd = requestPrice(pricingOf(model.price), bound
|
|
527
|
+
const usd = requestPrice(pricingOf(model.price), bound)(output);
|
|
501
528
|
return { usd, name: `the ${model.id} answer`, basis: `${model.id}'s worst price for ${bound} input and ${output} output tokens`, llm: { price: model.price } };
|
|
502
529
|
}
|
|
503
530
|
return NO_HOLD(tool);
|
|
@@ -633,7 +660,7 @@ export function holdAtEffects(cap, deps) {
|
|
|
633
660
|
// The net: an `llm` answer priced at its own usage above what was held for it.
|
|
634
661
|
const usage = hold.llm?.price && value && typeof value === "object" ? value.usage : undefined;
|
|
635
662
|
if (usage && hold.llm?.price) {
|
|
636
|
-
const charged = pricingOf(hold.llm.price)(
|
|
663
|
+
const charged = pricingOf(hold.llm.price)(usage.input_tokens ?? 0, usage.output_tokens ?? 0);
|
|
637
664
|
if (charged > hold.usd + 1e-12)
|
|
638
665
|
return failed(params.node.label, `its answer cost ${money(charged)}, above the ${money(hold.usd)} it held before it ran.`);
|
|
639
666
|
}
|
|
@@ -740,32 +767,18 @@ function runEffectOf(claimed, complete, env, policy, paidTools, log) {
|
|
|
740
767
|
}
|
|
741
768
|
});
|
|
742
769
|
}
|
|
743
|
-
/** The end's cost
|
|
744
|
-
*
|
|
745
|
-
*
|
|
746
|
-
|
|
747
|
-
*
|
|
748
|
-
|
|
749
|
-
async function decisionsBooked(journal) {
|
|
750
|
-
const root = await entriesOf(journal, ROOT_CONVERSATION_ID, BACKGROUND_CONTEXT);
|
|
751
|
-
const key = root.find((entry) => entry.kind === KINDS.sessionKey && entry.data?.key === DECISION_SESSION);
|
|
752
|
-
const conversation = key?.data?.conversation;
|
|
753
|
-
if (conversation == null)
|
|
754
|
-
return 0;
|
|
755
|
-
const decisions = await entriesOf(journal, conversation, BACKGROUND_CONTEXT);
|
|
756
|
-
return bookedSpend([key, ...decisions], "decisions").usd;
|
|
757
|
-
}
|
|
758
|
-
async function endPatchOf(booking, decisionCap, paidTools, journalOf) {
|
|
770
|
+
/** The end's cost: its booking's, by the one rule every reader of an ended run's cost takes (metrics.ts runCostOf, as the
|
|
771
|
+
* pi and CLI specs store it): every model request of its sessions, its call nodes' paid requests and its decisions, each
|
|
772
|
+
* at what it was booked at, never the cap's figure for it (an answer with no price of its own is unknown, never its
|
|
773
|
+
* hold). Unknown once any one is, written as null, never left out (an end that says nothing leaves the $0 the run read
|
|
774
|
+
* before a response). With no journal to read, unknown. */
|
|
775
|
+
async function endPatchOf(booking, journalOf) {
|
|
759
776
|
if (!booking)
|
|
760
777
|
return {};
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
//
|
|
764
|
-
|
|
765
|
-
const decision = !decisionCap ? 0 : journalOf ? await decisionsBooked(journalOf()) : null;
|
|
766
|
-
const paid = paidTools ? paidTools.spentUsd() : 0;
|
|
767
|
-
// Unknown is written as null, never left out (an end that says nothing leaves the $0 the run read before a response).
|
|
768
|
-
return { costUsd: model === null || decision === null || paid === null ? null : model + decision + paid };
|
|
778
|
+
if (!journalOf)
|
|
779
|
+
return { costUsd: null };
|
|
780
|
+
// With whether the figure is the most it can have cost (a request cut at its hold counted in it), stored beside it.
|
|
781
|
+
return endCostOf(runCostOf((await journalEntries(journalOf(), BACKGROUND_CONTEXT))));
|
|
769
782
|
}
|
|
770
783
|
/** The run's one cap as a WorkflowCap: model nodes and call nodes pass through (their money is on the proxy), and a
|
|
771
784
|
* decision node is priced before the DSL driver admits its request (`judge`) and held, sent and settled through the run's
|
|
@@ -886,9 +899,8 @@ export function decisionJudge(inner, deps) {
|
|
|
886
899
|
async function decisionRequestOf(provider, params) {
|
|
887
900
|
const id = params.decisionId ?? `decision:${params.executionPath ?? ""}:${params.label}${params.item ? `:${params.item.index}` : ""}`;
|
|
888
901
|
const inputTokens = Buffer.byteLength(JSON.stringify({ state: params.state ?? null, questions: params.questions }), "utf8");
|
|
889
|
-
const questions = Object.keys(params.questions).length;
|
|
890
902
|
const images = Object.keys(params.images ?? {}).length;
|
|
891
|
-
const base = { kind: "decision", id, inputTokens,
|
|
903
|
+
const base = { kind: "decision", id, inputTokens, images };
|
|
892
904
|
// Parallel charges by the request, nothing by the token: priced at $0 a token and its request price, never as a model
|
|
893
905
|
// with no price (which the cap refuses, failing every capped workflow's Parallel decision).
|
|
894
906
|
if (provider.id === "parallel")
|
|
@@ -1021,8 +1033,7 @@ async function readClaim(deps, runId) {
|
|
|
1021
1033
|
const launch = launchRow.body;
|
|
1022
1034
|
const input = launch && typeof launch.input === "object" && launch.input !== null ? launch.input : {};
|
|
1023
1035
|
const capUsd = typeof launch?.max_cost_usd === "number" ? launch.max_cost_usd : undefined;
|
|
1024
|
-
const mode = launch?.cap_mode === "strict" ? "strict" : "expected";
|
|
1025
1036
|
const workRoot = typeof launch?.documents === "string" ? launch.documents : "/tmp";
|
|
1026
|
-
return { agentId: run.agentId, revisionId: run.revisionId, revision: revision, workflow: revision.body.workflow, input, capUsd,
|
|
1037
|
+
return { agentId: run.agentId, revisionId: run.revisionId, revision: revision, workflow: revision.body.workflow, input, capUsd, workRoot, plane: launch?.plane };
|
|
1027
1038
|
}
|
|
1028
1039
|
export { BACKGROUND_CONTEXT };
|
|
@@ -2,10 +2,10 @@ import type { Revision } from "./agent-rows.js";
|
|
|
2
2
|
import type { MessageOrigin } from "./timeline/index.js";
|
|
3
3
|
import { type AgentEntry, type ExternalRef } from "./agents-store.js";
|
|
4
4
|
import { ApiError, type InputIssue } from "./errors.js";
|
|
5
|
-
import { type LearningMode, type Seed, type Shown } from "./learning.js";
|
|
5
|
+
import { type LearningMode, type NoteUsed, type Seed, type Shown } from "./learning.js";
|
|
6
6
|
import { type Place } from "./place.js";
|
|
7
7
|
import { type RepoBinding } from "./run-repo.js";
|
|
8
|
-
import { type LaunchDisk, type RunLaunch } from "./run-launch.js";
|
|
8
|
+
import { type LaunchDisk, type RunLaunch, type SeedFailed } from "./run-launch.js";
|
|
9
9
|
import { type ApprovalDecision, type RunMoment } from "./run-view.js";
|
|
10
10
|
import { type NewRevision, type RevisionRow, type RunOrigin, type RunRow, type Store } from "./store/index.js";
|
|
11
11
|
import { type ToolSettingsMap } from "./tool-plane.js";
|
|
@@ -88,6 +88,15 @@ export declare function raiseCap(store: RunsStore, moment: RunMoment, cap: numbe
|
|
|
88
88
|
export declare function approve(store: RunsStore, moment: RunMoment, id: string, decision: "allow" | "deny", note?: string, confirmed?: boolean): Promise<void>;
|
|
89
89
|
/** A UUIDv7 run id: time-ordered, so a listing by start time is stable, and unique per run. */
|
|
90
90
|
export declare function uuidv7(now?: number): string;
|
|
91
|
+
/** The revision's body fields a start reads: its default cap, its place, and (agentic) its tools, for the place
|
|
92
|
+
* fallback. Read with the shapes the old start read them with. */
|
|
93
|
+
type StartBody = {
|
|
94
|
+
readonly maxCostUsd?: number;
|
|
95
|
+
readonly place?: unknown;
|
|
96
|
+
readonly tools?: readonly unknown[];
|
|
97
|
+
readonly learning?: boolean | "notes";
|
|
98
|
+
readonly thinking?: unknown;
|
|
99
|
+
};
|
|
91
100
|
/** The pieces a start needs that live in the server's request layer, not here: the leaf validators (the create body's field
|
|
92
101
|
* issues, the revision a run pins, a run's input against its schema, the hint told from the revision, a revision this host
|
|
93
102
|
* cannot run), the uploads check, the place fallback, the title's redaction, the plane's settings and key environment, and
|
|
@@ -189,6 +198,25 @@ export interface StartOptions {
|
|
|
189
198
|
readonly capped?: boolean;
|
|
190
199
|
readonly from?: MessageOrigin;
|
|
191
200
|
}
|
|
201
|
+
/** The run's learning start as the old start decided it (learning-run.ts onStart): undefined when the run does not learn (the
|
|
202
|
+
* server's learning off, a workflow revision, or its revision does not say learning), else the notes its # Learned section
|
|
203
|
+
* names and the # Learned text (learnedParts, the one decision the runner puts in the prompt), the seed sha it starts
|
|
204
|
+
* from and the count of all the seed's notes before the budget picked `given` (seedNotes) — or given empty, seed null and no
|
|
205
|
+
* seedNotes when its seed cannot be read (a learning fault never refuses a run). `use`: the run's start said `learning:
|
|
206
|
+
* "use"`, so it starts from what its agent learned, its revision's own learning aside, and keeps nothing. */
|
|
207
|
+
export declare function learningStartFor(deps: StartDeps, entry: AgentEntry, revision: Revision, rbody: StartBody, input: unknown, use?: boolean): Promise<{
|
|
208
|
+
given: NoteUsed[];
|
|
209
|
+
seed: string | null;
|
|
210
|
+
section: string;
|
|
211
|
+
seedNotes?: number;
|
|
212
|
+
notesLeftOut?: string[];
|
|
213
|
+
skills?: string[];
|
|
214
|
+
workflows?: string[];
|
|
215
|
+
notesOnly?: true;
|
|
216
|
+
gradeModel?: string;
|
|
217
|
+
seedFailed?: SeedFailed;
|
|
218
|
+
use?: true;
|
|
219
|
+
} | undefined>;
|
|
192
220
|
/** Starts a run of `entry`'s agent from a create body, as POST /agents/{id}/runs starts it: every check the old start made
|
|
193
221
|
* before a run started (prepareLaunch), then an INSERT — a queued run and its launch body in one transaction
|
|
194
222
|
* (store.runs.create), which a runner reads at its claim. No process, no door, no setup file: where the run runs is the
|
package/dist/runs-over-store.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { nativeOf } from "./native/binding.js";
|
|
2
|
+
import { launchNative } from "./native/connection.js";
|
|
1
3
|
// The write half of the run's server cut (design 2.1, "the runner takes every run"): the functions the v2 routes call to
|
|
2
4
|
// start a run and to act on one (message, stop, raise, approve, archive), over the one store (A). The old per-run-process
|
|
3
5
|
// model (runs.ts: a child process, an HTTP door, serve.json, carry-back) is gone; the server only writes rows. A start is an
|
|
@@ -25,7 +27,7 @@ import { repoOf } from "./run-repo.js";
|
|
|
25
27
|
import { launchBody } from "./run-launch.js";
|
|
26
28
|
import { raiseFollowUpId } from "./run-view.js";
|
|
27
29
|
import { sendCommand } from "./runner/commands.js";
|
|
28
|
-
import { AnswerTaken, ExternalBodyConflict, RunFinal, StoreConstraint } from "./store/index.js";
|
|
30
|
+
import { AnswerTaken, ExternalBodyConflict, RunFinal, StoreConstraint, StoreLaunchMissing } from "./store/index.js";
|
|
29
31
|
import { canonical } from "./store/agent-body.js";
|
|
30
32
|
import { toolingOf } from "./tools.js";
|
|
31
33
|
import { planeFor } from "./tool-plane.js";
|
|
@@ -78,6 +80,7 @@ export async function stop(store, runId) {
|
|
|
78
80
|
const row = await store.runs.get(runId);
|
|
79
81
|
if (!row || row.importedFrom)
|
|
80
82
|
return false;
|
|
83
|
+
await refuseSdkStop(store, runId);
|
|
81
84
|
try {
|
|
82
85
|
await sendCommand(store, runId, { kind: "stop", body: {} });
|
|
83
86
|
return true;
|
|
@@ -95,6 +98,7 @@ export async function stop(store, runId) {
|
|
|
95
98
|
export async function cancel(store, moment) {
|
|
96
99
|
if (moment.importedSource !== undefined)
|
|
97
100
|
return false;
|
|
101
|
+
await refuseSdkStop(store, moment.id);
|
|
98
102
|
// Already ended, or already ending (an outcome being written, or a cancel in flight): a run's first end is its last.
|
|
99
103
|
if (moment.terminal || moment.cancelled)
|
|
100
104
|
return false;
|
|
@@ -108,6 +112,24 @@ export async function cancel(store, moment) {
|
|
|
108
112
|
throw error;
|
|
109
113
|
}
|
|
110
114
|
}
|
|
115
|
+
/** Older rows can lack launch metadata. Only that typed absence leaves their controls unchanged; a failed read
|
|
116
|
+
* must still fail the command, since it could be hiding native or SDK execution constraints. */
|
|
117
|
+
async function controlLaunchBody(store, runId) {
|
|
118
|
+
try {
|
|
119
|
+
return (await store.runs.launch(runId)).body;
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
if (error instanceof StoreLaunchMissing)
|
|
123
|
+
return undefined;
|
|
124
|
+
throw error;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/** Only the application can abort its SDK and tools. An HTTP acknowledgement must not pretend that it did. */
|
|
128
|
+
async function refuseSdkStop(store, runId) {
|
|
129
|
+
const launch = await controlLaunchBody(store, runId);
|
|
130
|
+
if (isObject(launch) && launch.sdk)
|
|
131
|
+
throw new ApiError("not_continuable", "This agent runs in your backend SDK. Cancel it using the original application's cancellation signal; its wrapper will report that outcome here.");
|
|
132
|
+
}
|
|
111
133
|
/** Pauses a workflow run, or resumes it (pauseRun/resumeRun): a pause or resume command the run's runner reads and applies.
|
|
112
134
|
* Verbatim from runs.ts pause: an agentic run has no pause here (501, a turn is stopped instead), an ended or cancelling one
|
|
113
135
|
* takes none (409). Returns the run id and whether it is paused; the route adds the run's status from its view. The runner
|
|
@@ -134,6 +156,11 @@ export const resume = (store, moment) => pauseOrResume(store, moment, false);
|
|
|
134
156
|
export async function message(store, moment, content, { requestId, answers = true, origin, queue, launchSealed, beforeSubmit } = {}) {
|
|
135
157
|
if (moment.importedSource !== undefined)
|
|
136
158
|
throw importedRefusal(moment);
|
|
159
|
+
const launchBody = await controlLaunchBody(store, moment.id);
|
|
160
|
+
if (isObject(launchBody) && launchBody.sdk)
|
|
161
|
+
throw new ApiError("not_continuable", "Backend SDK runs are single-task sessions. Start a new SDK call for another task.");
|
|
162
|
+
if (nativeOf(launchBody))
|
|
163
|
+
throw new ApiError("input_invalid", "Native jobs do not support in-session steering or follow-up messages. Start a new native run.");
|
|
137
164
|
// Archiving closes a run: it, or a run of its archived agent, takes no message, said as archived (never as finished).
|
|
138
165
|
if (moment.archived !== undefined)
|
|
139
166
|
throw archivedRefusal(moment);
|
|
@@ -316,9 +343,10 @@ export async function approve(store, moment, id, decision, note, confirmed = fal
|
|
|
316
343
|
}
|
|
317
344
|
if (!(moment.approvalIds?.has(id) ?? false))
|
|
318
345
|
throw new ApiError("not_found", `The run ${moment.id} has no tool call ${id} waiting for approval.`);
|
|
319
|
-
// A call its run's pin marks destructive takes a second, explicit confirm to allow: nothing is written without it.
|
|
346
|
+
// A call its run's pin marks destructive takes a second, explicit confirm to allow: nothing is written without it. The
|
|
347
|
+
// issue carries its own example, so the 422's telling (explain.ts) adds none to a sentence that already says what to send.
|
|
320
348
|
if (decision === "allow" && !confirmed && moment.destructiveIds?.has(id))
|
|
321
|
-
throw invalid([{ field: "confirm_destructive", reason: "missing", message: `The tool call ${id} is one its MCP server marks destructive
|
|
349
|
+
throw invalid([{ field: "confirm_destructive", reason: "missing", message: `The tool call ${id} is one its MCP server marks destructive. To allow it, confirm a second time and send the allow again with confirm_destructive: true.`, example: true }]);
|
|
322
350
|
const ending = await endBefore(store, moment.id);
|
|
323
351
|
if (ending)
|
|
324
352
|
throw alreadyAnswered(id, ending.decision);
|
|
@@ -372,12 +400,12 @@ const noShown = { text: (text) => text, name: (name) => name, holds: () => false
|
|
|
372
400
|
* from and the count of all the seed's notes before the budget picked `given` (seedNotes) — or given empty, seed null and no
|
|
373
401
|
* seedNotes when its seed cannot be read (a learning fault never refuses a run). `use`: the run's start said `learning:
|
|
374
402
|
* "use"`, so it starts from what its agent learned, its revision's own learning aside, and keeps nothing. */
|
|
375
|
-
async function learningStartFor(deps, entry, revision, rbody, input, use) {
|
|
403
|
+
export async function learningStartFor(deps, entry, revision, rbody, input, use = false) {
|
|
376
404
|
// A run started with `learning: "use"` starts from what its agent learned whatever its revision says, and keeps nothing
|
|
377
405
|
// (no grade model: nothing is graded); the server's learning off still gives it nothing.
|
|
378
406
|
const learns = deps.learning !== undefined && deps.learning !== "off" && revision.kind === "agentic" && (learnsOf(rbody.learning) || use);
|
|
379
407
|
// `learning: "notes"`: its notes and skills, never a learned workflow (none offered, none asked for at its end).
|
|
380
|
-
const notesOnly = rbody.learning === "notes" ? { notesOnly: true } : {};
|
|
408
|
+
const notesOnly = rbody.learning === "notes" || nativeOf(revision.body) ? { notesOnly: true } : {};
|
|
381
409
|
if (!learns || !deps.seedFor)
|
|
382
410
|
return undefined;
|
|
383
411
|
const grade = use ? { use: true } : deps.gradeModel ? { gradeModel: deps.gradeModel } : {};
|
|
@@ -414,6 +442,8 @@ async function learningStartFor(deps, entry, revision, rbody, input, use) {
|
|
|
414
442
|
* runner's. Under `origin`, a key that already started a run gets that run (the store's one-run-per-key), so a retry never
|
|
415
443
|
* starts a second. */
|
|
416
444
|
export async function startRun(store, deps, entry, body, { trigger, origin, capped = false, from, title, sealed } = {}) {
|
|
445
|
+
if (entry.revision?.body?.sdk)
|
|
446
|
+
throw new ApiError("agent_not_runnable", "This agent runs in your backend SDK. Start it through its SDK learning wrapper; AgentRun does not launch its tools or credentials.");
|
|
417
447
|
const { launch, revision } = await prepareLaunch(deps, entry, body, { ...(trigger ? { trigger } : {}), capped, ...(from ? { from } : {}), ...(title !== undefined ? { title } : {}) });
|
|
418
448
|
const runId = (deps.newRunId ?? uuidv7)();
|
|
419
449
|
try {
|
|
@@ -481,7 +511,7 @@ export async function startInline(store, deps, inline, body, { origin, sealed }
|
|
|
481
511
|
try {
|
|
482
512
|
return await withHeldFiles(deps, runId, launch, () => store.runs.createInline({
|
|
483
513
|
agent: { id: entry.agent.id, name: inline.name, description: inline.description, ref },
|
|
484
|
-
revision: { id: revision.id, version: external.version, kind: revision.kind, body: revision.body, skills: revision.skills, ...(revision.note !== undefined ? { note: revision.note } : {}), ...(revision.mcpPin !== undefined ? { mcpPin: revision.mcpPin } : {}) },
|
|
514
|
+
revision: { id: revision.id, version: external.version, kind: revision.kind, body: revision.body, skills: revision.skills, ...(revision.note !== undefined ? { note: revision.note } : {}), ...(revision.mcpPin !== undefined ? { mcpPin: revision.mcpPin } : {}), ...(revision.monidPin !== undefined ? { monidPin: revision.monidPin } : {}) },
|
|
485
515
|
run: { id: runId, ...(origin ? { origin } : {}) },
|
|
486
516
|
launch: { body: launchBody(launch), ...(sealed ? { sealed: sealed(runId) } : {}) },
|
|
487
517
|
}));
|
|
@@ -518,12 +548,17 @@ export async function prepareLaunch(deps, entry, body, { trigger, capped = false
|
|
|
518
548
|
// Each a ready file, before anything starts: checked ready here, then named in the launch (in order) for the runner to
|
|
519
549
|
// copy into the run's work/inputs/ at its claim.
|
|
520
550
|
const fileIds = Array.isArray(body.file_ids) ? body.file_ids : [];
|
|
521
|
-
if (fileIds.length)
|
|
522
|
-
await deps.readyFiles(fileIds);
|
|
523
551
|
const pinned = await pinnedOf();
|
|
524
552
|
if (!pinned)
|
|
525
553
|
throw invalid([{ field: "revision", reason: "not_an_option", message: typeof body.revision === "string" ? `${body.revision} is not a revision of the agent ${entry.agent.id}` : `the agent ${entry.agent.id} has no current revision` }]);
|
|
526
554
|
const { revision } = pinned;
|
|
555
|
+
const native = nativeOf(revision.body);
|
|
556
|
+
if (native && !nativeOf(entry.revision?.body)?.connected)
|
|
557
|
+
throw new ApiError("agent_not_runnable", "This native connection is disconnected. Reconnect its source project before starting any revision.");
|
|
558
|
+
if (native && (body.effort !== undefined || fileIds.length || body.archil_disk !== undefined))
|
|
559
|
+
throw new ApiError("input_invalid", "Native jobs use their original effort and project files. Run effort overrides, uploaded file_ids and Archil disks are unavailable; edit the native configuration or source project instead.");
|
|
560
|
+
if (fileIds.length)
|
|
561
|
+
await deps.readyFiles(fileIds);
|
|
527
562
|
const rbody = revision.body;
|
|
528
563
|
const input = body.input;
|
|
529
564
|
const wrong = await deps.inputIssuesOf(revision, input);
|
|
@@ -533,10 +568,6 @@ export async function prepareLaunch(deps, entry, body, { trigger, capped = false
|
|
|
533
568
|
const cap = typeof body.max_cost_usd === "number" ? body.max_cost_usd : rbody.maxCostUsd;
|
|
534
569
|
if (capped && cap === undefined)
|
|
535
570
|
throw invalid([{ field: "max_cost_usd", reason: "missing", message: "Every run a trigger starts is capped: give the trigger's target a max_cost_usd or set the agent's." }]);
|
|
536
|
-
// How its cap prices a request: the run's own, else the agent's, else expected (cap.ts). Only a run with a cap has one.
|
|
537
|
-
if (body.cap_mode !== undefined && cap === undefined)
|
|
538
|
-
throw invalid([{ field: "cap_mode", reason: "not_allowed", message: "cap_mode says how a run's cap prices its requests, and this run has no cap: give it a max_cost_usd, or set the agent's." }]);
|
|
539
|
-
const capMode = cap === undefined ? undefined : typeof body.cap_mode === "string" ? body.cap_mode : rbody.capMode;
|
|
540
571
|
const place = resolvePlace(rbody.place, deps.fallbackPlace(revision.kind, revision.kind === "agentic" ? (rbody.tools ?? []) : []));
|
|
541
572
|
// Checked as pinned: an earlier revision with no pin is pinned now, once (StartDeps.pinFirst); one that could not be, as
|
|
542
573
|
// its server could not be listed, is refused with the rest (runnable).
|
|
@@ -574,7 +605,8 @@ export async function prepareLaunch(deps, entry, body, { trigger, capped = false
|
|
|
574
605
|
// The run's effort: its own, else its revision's saved thinking, else the host's AGENT_THINKING (each a thinking level,
|
|
575
606
|
// else none). Nothing set: none, so the run gets no effort note and its harness's own default. Kept in its launch, so
|
|
576
607
|
// its harness's thinking, its guidance and its metrics all read the one value.
|
|
577
|
-
const effort = typeof body.effort === "string" ? body.effort : (thinkingLevel(rbody.thinking) ?? thinkingLevel(deps.planeEnv().AGENT_THINKING));
|
|
608
|
+
const effort = native ? undefined : typeof body.effort === "string" ? body.effort : (thinkingLevel(rbody.thinking) ?? thinkingLevel(deps.planeEnv().AGENT_THINKING));
|
|
609
|
+
const nativeLaunch = native?.remote ? native : native ? await launchNative(native) : undefined;
|
|
578
610
|
// The repository a person's run reaches (run-repo.ts): the one the body names when the agent is bound to it, else the
|
|
579
611
|
// agent's one repository when the first message names none. A trigger's run takes its repository from its event.
|
|
580
612
|
const namedRepo = typeof body.repo === "string" ? body.repo : undefined;
|
|
@@ -584,6 +616,7 @@ export async function prepareLaunch(deps, entry, body, { trigger, capped = false
|
|
|
584
616
|
if (picked.refused)
|
|
585
617
|
throw invalid([{ field: "repo", reason: "not_allowed", message: picked.refused }]);
|
|
586
618
|
const launch = {
|
|
619
|
+
...(nativeLaunch ? { native: nativeLaunch } : {}),
|
|
587
620
|
input,
|
|
588
621
|
...(picked.repo !== undefined ? { repo: picked.repo } : {}),
|
|
589
622
|
title: clip(redacted(title.trim().replace(/\s+/g, " "), deps.serverSecrets()), 80),
|
|
@@ -591,7 +624,6 @@ export async function prepareLaunch(deps, entry, body, { trigger, capped = false
|
|
|
591
624
|
harness: harnessOfBody(revision.body),
|
|
592
625
|
...(effort !== undefined ? { effort } : {}),
|
|
593
626
|
...(cap !== undefined ? { maxCostUsd: cap } : {}),
|
|
594
|
-
...(capMode !== undefined ? { capMode } : {}),
|
|
595
627
|
...(Object.keys(plane).length ? { plane } : {}),
|
|
596
628
|
...(deps.approvers !== undefined ? { approvers: deps.approvers } : {}),
|
|
597
629
|
...(deps.documents !== undefined ? { documents: deps.documents } : {}),
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type { Claim, RunOrigin, Store } from "../store/store.js";
|
|
2
|
+
import type { AgentEntry } from "../agents-store.js";
|
|
3
|
+
import { type StartDeps } from "../runs-over-store.js";
|
|
4
|
+
import { type LearnedWorkflow } from "../learning.js";
|
|
5
|
+
export type SdkRuntime = "claude-agent-sdk" | "codex-sdk";
|
|
6
|
+
export type SdkUsage = {
|
|
7
|
+
input_tokens: number | null;
|
|
8
|
+
output_tokens: number | null;
|
|
9
|
+
cache_read_tokens: number | null;
|
|
10
|
+
cache_write_tokens: number | null;
|
|
11
|
+
cost_usd: number | null;
|
|
12
|
+
};
|
|
13
|
+
export type SdkEvent = {
|
|
14
|
+
type: "text";
|
|
15
|
+
text: string;
|
|
16
|
+
} | {
|
|
17
|
+
type: "session";
|
|
18
|
+
session_id: string;
|
|
19
|
+
} | {
|
|
20
|
+
type: "tool";
|
|
21
|
+
id: string;
|
|
22
|
+
name: string;
|
|
23
|
+
status: "started" | "completed" | "failed";
|
|
24
|
+
input?: unknown;
|
|
25
|
+
output?: unknown;
|
|
26
|
+
parent_tool_use_id?: string;
|
|
27
|
+
};
|
|
28
|
+
export type SdkCompletion = {
|
|
29
|
+
status: "completed" | "failed" | "cancelled";
|
|
30
|
+
answer: string;
|
|
31
|
+
error?: string;
|
|
32
|
+
evidence_complete?: boolean;
|
|
33
|
+
model?: string;
|
|
34
|
+
session_id?: string;
|
|
35
|
+
usage?: SdkUsage;
|
|
36
|
+
};
|
|
37
|
+
export type SdkInbox = {
|
|
38
|
+
run_id: string;
|
|
39
|
+
created_at: number;
|
|
40
|
+
expires_at: number;
|
|
41
|
+
batches: {
|
|
42
|
+
sequence: number;
|
|
43
|
+
events: SdkEvent[];
|
|
44
|
+
}[];
|
|
45
|
+
/** Exact approved skill files delivered by the start receipt; absent on older SDK runs. */
|
|
46
|
+
learning_skills?: SdkSeedSkill[];
|
|
47
|
+
/** Exact approved executable workflows delivered by the start receipt. */
|
|
48
|
+
learning_workflows?: LearnedWorkflow[];
|
|
49
|
+
completion?: SdkCompletion;
|
|
50
|
+
/** Internal terminal admission fence. No later evidence can be newly acknowledged after this CAS wins. */
|
|
51
|
+
closed?: "expired" | "failed" | "cancelled";
|
|
52
|
+
};
|
|
53
|
+
type SdkSeedSkill = {
|
|
54
|
+
name: string;
|
|
55
|
+
files: Record<string, string>;
|
|
56
|
+
};
|
|
57
|
+
export declare const sdkOf: (body: unknown) => {
|
|
58
|
+
runtime: SdkRuntime;
|
|
59
|
+
} | undefined;
|
|
60
|
+
export declare function sdkInbox(store: Pick<Store, "settings">, runId: string): Promise<SdkInbox>;
|
|
61
|
+
/** Completion and closure compete on the same inbox. A stale runner cannot close it, and a completion that won
|
|
62
|
+
* remains available to the next claim even if this one cannot read or journal it. No external SDK call is replayed. */
|
|
63
|
+
export declare function closeSdkInbox(store: Pick<Store, "settings">, claim: Claim, reason: NonNullable<SdkInbox["closed"]>): Promise<SdkInbox>;
|
|
64
|
+
export declare class SdkRuns {
|
|
65
|
+
private readonly store;
|
|
66
|
+
private readonly data;
|
|
67
|
+
private readonly secret;
|
|
68
|
+
private readonly secrets;
|
|
69
|
+
constructor(store: Store, data: string, secret: string, secrets?: () => readonly string[]);
|
|
70
|
+
token(runId: string): string;
|
|
71
|
+
authenticate(runId: string, token: string): Promise<void>;
|
|
72
|
+
private clean;
|
|
73
|
+
start(entry: AgentEntry, body: Record<string, unknown>, deps: StartDeps, origin: RunOrigin | undefined, checkGrade: (model: string) => Promise<void>, consoleOrigin: string): Promise<{
|
|
74
|
+
run_id: string;
|
|
75
|
+
agent_id: string;
|
|
76
|
+
console_url: string;
|
|
77
|
+
token: string;
|
|
78
|
+
learning: {
|
|
79
|
+
enabled: boolean;
|
|
80
|
+
revision: string | null;
|
|
81
|
+
context: string;
|
|
82
|
+
skills: SdkSeedSkill[];
|
|
83
|
+
workflows: LearnedWorkflow[];
|
|
84
|
+
};
|
|
85
|
+
}>;
|
|
86
|
+
receipt(runId: string, consoleOrigin: string): Promise<{
|
|
87
|
+
run_id: string;
|
|
88
|
+
agent_id: string;
|
|
89
|
+
console_url: string;
|
|
90
|
+
token: string;
|
|
91
|
+
learning: {
|
|
92
|
+
enabled: boolean;
|
|
93
|
+
revision: string | null;
|
|
94
|
+
context: string;
|
|
95
|
+
skills: SdkSeedSkill[];
|
|
96
|
+
workflows: LearnedWorkflow[];
|
|
97
|
+
};
|
|
98
|
+
}>;
|
|
99
|
+
private selectedWorkflows;
|
|
100
|
+
private selectedSkills;
|
|
101
|
+
private modify;
|
|
102
|
+
private writable;
|
|
103
|
+
events(runId: string, body: Record<string, unknown>): Promise<{
|
|
104
|
+
accepted: boolean;
|
|
105
|
+
}>;
|
|
106
|
+
complete(runId: string, body: Record<string, unknown>): Promise<{
|
|
107
|
+
accepted: boolean;
|
|
108
|
+
}>;
|
|
109
|
+
status(runId: string): Promise<{
|
|
110
|
+
learning_run_id?: string | undefined;
|
|
111
|
+
run_id: string;
|
|
112
|
+
state: string;
|
|
113
|
+
}>;
|
|
114
|
+
}
|
|
115
|
+
export {};
|