@parcha/agentrun-serve 0.1.0-beta.35 → 0.1.0-beta.36
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 +128 -0
- package/README.md +260 -168
- package/dist/adapters.d.ts +12 -2
- package/dist/adapters.js +27 -2
- package/dist/agent-rows.d.ts +2 -1
- package/dist/agents-store.d.ts +2 -0
- package/dist/agents-store.js +9 -4
- package/dist/api-only.d.ts +2 -1
- package/dist/api-only.js +3 -1
- package/dist/archil-routes.d.ts +40 -7
- package/dist/archil-routes.js +167 -54
- package/dist/archil-settings.d.ts +79 -7
- package/dist/archil-settings.js +140 -14
- package/dist/attach-images.d.ts +15 -0
- package/dist/attach-images.js +59 -0
- package/dist/background.d.ts +0 -6
- package/dist/background.js +0 -28
- package/dist/box-image.d.ts +1 -97
- package/dist/box-image.js +4 -284
- package/dist/box-paths.d.ts +2 -7
- package/dist/box-paths.js +7 -13
- package/dist/box-settings.d.ts +0 -11
- package/dist/box-settings.js +4 -29
- package/dist/browser-commands.js +1 -1
- package/dist/browser-computer.d.ts +47 -3
- package/dist/browser-computer.js +286 -18
- package/dist/browser-person.d.ts +19 -2
- package/dist/browser-person.js +55 -6
- package/dist/browser-wait-ended.d.ts +23 -0
- package/dist/browser-wait-ended.js +42 -0
- package/dist/cap.d.ts +13 -41
- package/dist/cap.js +24 -73
- package/dist/cli.js +4 -22
- package/dist/computer-routes.d.ts +1 -4
- package/dist/computer-routes.js +3 -5
- package/dist/computer-setting.d.ts +2 -0
- package/dist/computer-setting.js +38 -1
- package/dist/computer-view.d.ts +11 -2
- package/dist/computer-view.js +2 -1
- package/dist/computers.d.ts +48 -7
- package/dist/computers.js +100 -23
- package/dist/console/assets/index-BI4Byidu.js +550 -0
- package/dist/console/assets/index-C19gUF2n.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/docker-daemon.d.ts +2 -2
- package/dist/docker-daemon.js +2 -2
- package/dist/errors.js +5 -5
- package/dist/faux-computers.js +4 -0
- package/dist/files.d.ts +1 -9
- package/dist/files.js +1 -9
- package/dist/github.d.ts +22 -2
- package/dist/github.js +42 -8
- package/dist/gpu-words.d.ts +14 -0
- package/dist/gpu-words.js +21 -0
- package/dist/graph-view.d.ts +2 -0
- package/dist/graph-view.js +25 -1
- package/dist/handed-values.d.ts +1 -1
- package/dist/handed-values.js +1 -1
- package/dist/harness-install.d.ts +60 -3
- package/dist/harness-install.js +322 -34
- package/dist/harness.js +1 -1
- package/dist/host-tools.d.ts +8 -9
- package/dist/host-tools.js +7 -7
- package/dist/index.d.ts +1 -3
- package/dist/index.js +1 -2
- package/dist/key-refusal.d.ts +1 -1
- package/dist/key-refusal.js +2 -2
- package/dist/learn/check.d.ts +7 -1
- package/dist/learn/check.js +123 -5
- package/dist/learn/commit.d.ts +40 -6
- package/dist/learn/commit.js +164 -20
- package/dist/learn/folder.d.ts +5 -0
- package/dist/learn/folder.js +33 -0
- package/dist/learn/grade.d.ts +18 -1
- package/dist/learn/grade.js +86 -16
- package/dist/learn/index.d.ts +1 -1
- package/dist/learn/index.js +1 -1
- package/dist/learn/learning.sh +12 -1
- package/dist/learn/notes.d.ts +3 -0
- package/dist/learn/notes.js +3 -0
- package/dist/learn/reflect.d.ts +5 -2
- package/dist/learn/reflect.js +43 -29
- package/dist/learn/skills.d.ts +4 -0
- package/dist/learn/skills.js +7 -0
- package/dist/learned-nodes.d.ts +6 -2
- package/dist/learned-workflow.d.ts +19 -9
- package/dist/learned-workflow.js +62 -34
- package/dist/learning-cost.d.ts +79 -0
- package/dist/learning-cost.js +69 -0
- package/dist/learning-routes.d.ts +8 -3
- package/dist/learning-routes.js +9 -6
- package/dist/learning-words.d.ts +3 -0
- package/dist/learning-words.js +6 -2
- package/dist/learning.d.ts +13 -6
- package/dist/learning.js +4 -2
- package/dist/mcp-probe.d.ts +8 -1
- package/dist/mcp-probe.js +62 -20
- package/dist/mcp-secret-writes.js +4 -0
- package/dist/mcp-servers-store.js +8 -3
- package/dist/model.d.ts +5 -5
- package/dist/model.js +6 -6
- package/dist/openapi.d.ts +2 -0
- package/dist/openapi.js +204 -47
- package/dist/owner.d.ts +0 -1
- package/dist/owner.js +0 -2
- package/dist/paid-calls.js +1 -1
- package/dist/place-offers.d.ts +97 -0
- package/dist/place-offers.js +206 -0
- package/dist/place.d.ts +9 -13
- package/dist/place.js +22 -32
- package/dist/port-models.d.ts +2 -1
- package/dist/port-models.js +5 -3
- package/dist/print.d.ts +1 -8
- package/dist/print.js +1 -14
- package/dist/propose.d.ts +1 -0
- package/dist/propose.js +25 -10
- package/dist/run-cut.d.ts +5 -0
- package/dist/run-cut.js +19 -0
- package/dist/run-db.js +3 -3
- package/dist/run-launch.d.ts +14 -1
- package/dist/run-launch.js +7 -2
- package/dist/run-learning-served.d.ts +1 -1
- package/dist/run-manifest.d.ts +2 -2
- package/dist/run-manifest.js +2 -2
- package/dist/run-secrets.js +3 -3
- package/dist/run-timeline-served.js +56 -44
- package/dist/run-view.d.ts +5 -2
- package/dist/run-view.js +4 -3
- package/dist/runnable.d.ts +2 -2
- package/dist/runnable.js +6 -2
- package/dist/runner/adapter-loop.d.ts +16 -1
- package/dist/runner/adapter-loop.js +131 -30
- package/dist/runner/adapter-run-spec.d.ts +25 -4
- package/dist/runner/adapter-run-spec.js +103 -24
- package/dist/runner/adapters/pi.d.ts +11 -3
- package/dist/runner/adapters/pi.js +35 -12
- package/dist/runner/beside.js +6 -2
- package/dist/runner/cli-run-spec.d.ts +7 -0
- package/dist/runner/cli-run-spec.js +92 -38
- package/dist/runner/commands.d.ts +5 -1
- package/dist/runner/commands.js +3 -3
- package/dist/runner/conformance/harness.d.ts +0 -1
- package/dist/runner/conformance/harness.js +8 -5
- package/dist/runner/github-app.js +2 -2
- package/dist/runner/harness-loops.js +1 -1
- package/dist/runner/journal-kinds.d.ts +15 -5
- package/dist/runner/journal-kinds.js +6 -1
- package/dist/runner/learning-end.d.ts +15 -0
- package/dist/runner/learning-end.js +26 -5
- package/dist/runner/learning-factory.js +6 -2
- package/dist/runner/learning-loop.d.ts +73 -1
- package/dist/runner/learning-loop.js +203 -18
- package/dist/runner/learning-seed.d.ts +2 -0
- package/dist/runner/learning-seed.js +1 -1
- package/dist/runner/loop-contract.d.ts +8 -0
- package/dist/runner/loop-contract.js +6 -0
- package/dist/runner/loop.d.ts +5 -1
- package/dist/runner/loop.js +20 -0
- package/dist/runner/main.js +12 -2
- package/dist/runner/mcp-claim.d.ts +4 -0
- package/dist/runner/mcp-claim.js +29 -1
- package/dist/runner/mcp-github.d.ts +4 -2
- package/dist/runner/mcp-github.js +0 -7
- package/dist/runner/mcp-run.d.ts +2 -0
- package/dist/runner/mcp-run.js +1 -0
- package/dist/runner/metrics.d.ts +4 -0
- package/dist/runner/metrics.js +9 -0
- package/dist/runner/model-route.d.ts +3 -0
- package/dist/runner/model-route.js +5 -2
- package/dist/runner/pr-checkout.d.ts +59 -0
- package/dist/runner/pr-checkout.js +176 -0
- package/dist/runner/reflect-hook.d.ts +1 -0
- package/dist/runner/reflect-hook.js +3 -3
- package/dist/runner/runner.js +47 -12
- package/dist/runner/spec-holds.d.ts +8 -3
- package/dist/runner/spec-holds.js +12 -10
- package/dist/runner/store-port.d.ts +4 -1
- package/dist/runner/store-secrets.js +17 -1
- package/dist/runner/subagent.d.ts +44 -0
- package/dist/runner/subagent.js +188 -0
- package/dist/runner/workflow-host.d.ts +18 -2
- package/dist/runner/workflow-host.js +23 -3
- package/dist/runner/workflow-loop.d.ts +5 -2
- package/dist/runner/workflow-loop.js +9 -8
- package/dist/runner/workflow-spec.d.ts +26 -14
- package/dist/runner/workflow-spec.js +97 -30
- package/dist/runs-over-store.d.ts +11 -6
- package/dist/runs-over-store.js +111 -24
- package/dist/sealing.js +1 -2
- package/dist/secret-cut.d.ts +1 -1
- package/dist/secret-cut.js +1 -1
- package/dist/server.d.ts +32 -49
- package/dist/server.js +249 -199
- package/dist/store/agent-body.d.ts +9 -2
- package/dist/store/agent-body.js +16 -8
- package/dist/store/deadline.js +9 -5
- package/dist/store/index.d.ts +3 -3
- package/dist/store/index.js +2 -2
- package/dist/store/journal/storage.js +2 -1
- package/dist/store/postgres/connection.js +9 -4
- package/dist/store/postgres/migrations/0004_runs_outcome_stop_or_cancel.sql +11 -0
- package/dist/store/schema.d.ts +2 -1
- package/dist/store/schema.js +11 -8
- package/dist/store/seal.d.ts +13 -0
- package/dist/store/seal.js +19 -0
- package/dist/store/sqlite/connection.d.ts +5 -0
- package/dist/store/sqlite/connection.js +88 -47
- package/dist/store/sqlite/run-patch.d.ts +18 -2
- package/dist/store/sqlite/run-patch.js +31 -2
- package/dist/store/sqlite/store.js +65 -11
- package/dist/store/store.d.ts +62 -12
- package/dist/store/store.js +22 -1
- package/dist/store-reads/analytics.js +3 -2
- package/dist/store-reads/cap.d.ts +1 -3
- package/dist/store-reads/cap.js +8 -6
- package/dist/store-reads/decisions.d.ts +2 -2
- package/dist/store-reads/decisions.js +3 -6
- package/dist/store-reads/journal.js +45 -12
- package/dist/store-reads/learning.d.ts +15 -1
- package/dist/store-reads/learning.js +68 -10
- package/dist/store-reads/runs.d.ts +6 -4
- package/dist/store-reads/runs.js +17 -10
- package/dist/store-reads/stats.js +5 -1
- package/dist/store-view.js +45 -19
- package/dist/template-eval.js +2 -1
- package/dist/templates.d.ts +64 -0
- package/dist/templates.js +101 -16
- package/dist/timeline/timeline.d.ts +3 -1
- package/dist/timeline/timeline.js +19 -4
- package/dist/tool-blurbs.js +1 -0
- package/dist/tool-budget.d.ts +8 -0
- package/dist/tool-budget.js +7 -1
- package/dist/tool-gate.d.ts +7 -1
- package/dist/tool-gate.js +7 -2
- package/dist/tool-plane.d.ts +33 -19
- package/dist/tool-plane.js +64 -27
- package/dist/tools.d.ts +18 -34
- package/dist/tools.js +104 -70
- package/dist/trigger-signatures.d.ts +1 -0
- package/dist/trigger-signatures.js +3 -1
- package/dist/triggers.d.ts +3 -3
- package/dist/triggers.js +2 -2
- package/dist/turn-end.d.ts +0 -3
- package/dist/turn-end.js +0 -3
- package/dist/usage-lines.d.ts +1 -1
- package/dist/validate.d.ts +6 -0
- package/dist/validate.js +30 -3
- package/dist/webhooks.d.ts +2 -1
- package/dist/webhooks.js +5 -2
- package/dist/workflow/decision-recovery.d.ts +23 -0
- package/dist/workflow/decision-recovery.js +80 -0
- package/dist/workflow/decisions.d.ts +134 -0
- package/dist/workflow/decisions.js +46 -0
- package/dist/workflow/host-session.d.ts +5 -0
- package/dist/workflow/host-session.js +85 -0
- package/dist/workflow/host-tools.d.ts +3 -0
- package/dist/workflow/host-tools.js +3 -0
- package/dist/workflow/node-runner.d.ts +112 -0
- package/dist/workflow/node-runner.js +270 -0
- package/dist/workflow/node.d.ts +88 -0
- package/dist/workflow/node.js +99 -0
- package/dist/workflow/operator-error.d.ts +4 -0
- package/dist/workflow/operator-error.js +4 -0
- package/dist/workflow/pi-versions.d.ts +9 -0
- package/dist/workflow/pi-versions.js +8 -0
- package/dist/workflow/readers.d.ts +36 -0
- package/dist/workflow/readers.js +145 -0
- package/dist/workflow/record-file.d.ts +10 -0
- package/dist/workflow/record-file.js +56 -0
- package/dist/workflow/record-tool.d.ts +76 -0
- package/dist/workflow/record-tool.js +126 -0
- package/dist/workflow/record.d.ts +151 -0
- package/dist/workflow/record.js +401 -0
- package/dist/workflow/run-error.d.ts +16 -0
- package/dist/workflow/run-error.js +26 -0
- package/dist/workflow/runner.d.ts +6 -0
- package/dist/workflow/runner.js +240 -0
- package/dist/workflow/store.d.ts +23 -0
- package/dist/workflow/store.js +242 -0
- package/dist/workflow/task.d.ts +133 -0
- package/dist/workflow/task.js +411 -0
- package/dist/workflow/thinking.d.ts +3 -0
- package/dist/workflow/thinking.js +7 -0
- package/dist/workflow/tool-context.d.ts +21 -0
- package/dist/workflow/tool-context.js +13 -0
- package/dist/workflow/types.d.ts +126 -0
- package/dist/workflow/types.js +1 -0
- package/dist/workflow/wal.d.ts +11 -0
- package/dist/workflow/wal.js +106 -0
- package/dist/workflow-run.d.ts +1 -1
- package/dist/workspace/agent-computer.d.ts +137 -0
- package/dist/workspace/agent-computer.js +292 -0
- package/dist/workspace/archil-claim.d.ts +11 -0
- package/dist/workspace/archil-claim.js +18 -10
- package/dist/workspace/archil-disks.d.ts +49 -0
- package/dist/workspace/archil-disks.js +185 -0
- package/dist/workspace/archil-exec.js +2 -3
- package/dist/workspace/archil-mount-credential.d.ts +20 -4
- package/dist/workspace/archil-mount-credential.js +13 -4
- package/dist/workspace/computer-deps.d.ts +16 -8
- package/dist/workspace/computer-deps.js +18 -7
- package/dist/workspace/computer-for-claim.d.ts +42 -6
- package/dist/workspace/computer-for-claim.js +209 -9
- package/dist/workspace/computer-janitor.d.ts +3 -2
- package/dist/workspace/computer-janitor.js +43 -9
- package/dist/workspace/computer-ledger.d.ts +3 -1
- package/dist/workspace/computer-ledger.js +7 -0
- package/dist/workspace/index.d.ts +3 -2
- package/dist/workspace/index.js +1 -0
- package/dist/workspace/resolve-computer.d.ts +42 -11
- package/dist/workspace/resolve-computer.js +65 -13
- package/dist/workspace/run-disk.d.ts +34 -0
- package/dist/workspace/run-disk.js +91 -0
- package/dist/workspace/run-tools.d.ts +4 -4
- package/dist/workspace/run-tools.js +8 -6
- package/dist/workspace/server-run-workspace.d.ts +3 -2
- package/dist/workspace/server-run-workspace.js +17 -4
- package/dist/workspace.js +1 -1
- package/package.json +10 -15
- package/templates/README.md +9 -6
- package/templates/code-review/agent.md +27 -11
- package/templates/code-review/evals/clean-refactor/graders/coverage.md +4 -0
- package/templates/code-review/evals/clean-refactor/graders/risk.md +5 -0
- package/templates/code-review/evals/injection/graders/ignores.md +1 -1
- package/templates/code-review/evals/never-flag/case.yaml +3 -0
- package/templates/code-review/evals/never-flag/graders/only-p0.md +4 -0
- package/templates/code-review/evals/never-flag/graders/schema.md +5 -0
- package/templates/code-review/evals/never-flag/prompt.md +30 -0
- package/templates/code-review/evals/null-name/graders/finds.md +1 -1
- package/templates/code-review/evals/off-by-one/graders/finds.md +1 -1
- package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +6 -5
- package/templates/code-review/evals/re-review/graders/resolves.md +1 -1
- package/templates/code-review/evals/re-review/prompt.md +1 -1
- package/templates/code-review/evals/re-review-open/case.yaml +3 -0
- package/templates/code-review/evals/re-review-open/graders/schema.md +5 -0
- package/templates/code-review/evals/re-review-open/graders/stays-open.md +4 -0
- package/templates/code-review/evals/re-review-open/prompt.md +27 -0
- package/templates/code-review/evals/repo-rule/graders/cites.md +1 -1
- package/templates/code-review/evals/two-defects/case.yaml +3 -0
- package/templates/code-review/evals/two-defects/graders/both.md +4 -0
- package/templates/code-review/evals/two-defects/graders/schema.md +5 -0
- package/templates/code-review/evals/two-defects/prompt.md +25 -0
- package/templates/code-review/findings.schema.json +131 -27
- package/templates/code-review/rules/CODEREVIEW.md +76 -0
- package/templates/code-review/skills/review/DEEP.md +130 -0
- package/templates/code-review/skills/review/REVIEWER.md +116 -0
- package/templates/code-review/skills/review/SKILL.md +104 -154
- package/dist/box/record.d.ts +0 -6
- package/dist/box/record.js +0 -41
- package/dist/box/sweep.d.ts +0 -53
- package/dist/box/sweep.js +0 -193
- package/dist/box-egress-vm.d.ts +0 -118
- package/dist/box-egress-vm.js +0 -354
- package/dist/box-egress.d.ts +0 -105
- package/dist/box-egress.js +0 -256
- package/dist/box-relay-vm.d.ts +0 -84
- package/dist/box-relay-vm.js +0 -437
- package/dist/box-relay.d.ts +0 -36
- package/dist/box-relay.js +0 -207
- package/dist/boxes.d.ts +0 -109
- package/dist/boxes.js +0 -249
- package/dist/budget.d.ts +0 -71
- package/dist/budget.js +0 -199
- package/dist/console/assets/index-B7NKTU8E.css +0 -1
- package/dist/console/assets/index-CXZMgJE7.js +0 -550
- package/dist/daytona-api.d.ts +0 -10
- package/dist/daytona-api.js +0 -20
- package/dist/egress-proxy.d.ts +0 -45
- package/dist/egress-proxy.js +0 -416
- package/dist/egress-table.d.ts +0 -24
- package/dist/egress-table.js +0 -165
- package/templates/code-review/rules/REVIEW.md +0 -41
package/dist/tool-plane.js
CHANGED
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
// told a deny: its Plane resolves a denied capability as under ask, and the gate, which reads the permission at each
|
|
21
21
|
// call, is the one place that refuses it, so a deny lifted mid-run is lifted at the next call.
|
|
22
22
|
import { blurbOf } from "./tool-blurbs.js";
|
|
23
|
+
import { PROVIDERS as COMPUTER_PROVIDERS } from "@parcha/agentrun-computer";
|
|
23
24
|
import { decisionKeysOf, PARALLEL_KEY_ENV } from "./decisions.js";
|
|
24
25
|
import { keyNeeded } from "./key-words.js";
|
|
25
26
|
import { DEFAULT_HARNESS, HARNESSES } from "./harness.js";
|
|
@@ -27,6 +28,7 @@ import { builtinHarness, harnessOf } from "./harness-table.js";
|
|
|
27
28
|
import { viaOpenRouter, WIRES } from "./provider.js";
|
|
28
29
|
import { savedIn } from "./secrets.js";
|
|
29
30
|
import { hostModel } from "./model.js";
|
|
31
|
+
import { NEEDS_A_COMPUTER, NO_SHELL } from "@parcha/agentrun-kernel/kernel";
|
|
30
32
|
import { canonicalPin, defaultPermission, isCatalogTool, isMcpTool, MAX_PIN_ARGS, MAX_PIN_CHOICES, PERMISSIONS, permissionFrom, permissionOf, SETTINGS_UNREAD, SHELL_FAMILY } from "./tool-gate.js";
|
|
31
33
|
import { BASH_POLICIES } from "./bash-read-only.js";
|
|
32
34
|
/**
|
|
@@ -41,13 +43,14 @@ export const CAPABILITIES = ["read", "write", "edit", "web_search", "web_fetch",
|
|
|
41
43
|
* server holds its key, else keyless Exa; `native`, the harness's own tool or its model provider's hosted one, and
|
|
42
44
|
* nothing else; `exa-keyless`, Exa's public MCP endpoint, no key; `kernel`, the guarded direct fetch; `parallel`,
|
|
43
45
|
* Parallel's Search and Extract APIs on PARALLEL_API_KEY; `off`, web_search turned off: nothing is searched, and an
|
|
44
|
-
* agent naming it is refused until it is turned on again. The browser's: `auto`,
|
|
45
|
-
* keys, else Kernel
|
|
46
|
-
* server's own host, which no server sets up yet
|
|
47
|
-
|
|
46
|
+
* agent naming it is refused until it is turned on again. The browser's: `auto`, the computer registry's first browser
|
|
47
|
+
* provider whose keys the server holds (Browserbase, else Kernel); a browser provider's id (`browserbase`, `kernel`:
|
|
48
|
+
* BROWSER_VENDOR_IDS), that one alone; `chrome`, a Chrome on the server's own host, which no server sets up yet
|
|
49
|
+
* (browserBy). */
|
|
50
|
+
export const PROVIDERS = Object.freeze({ web_search: ["auto", "native", "exa-keyless", "parallel", "off"], web_fetch: ["kernel", "parallel"], browser: Object.freeze(["auto", ...browserProviderIds(), "chrome"]) });
|
|
48
51
|
export const PICKABLE = Object.keys(PROVIDERS);
|
|
49
52
|
/** Every tool of serve's table (tools.ts), by name, so this module needs no import of it: a test holds the two as one. */
|
|
50
|
-
export const TABLE_TOOLS = ["read", "write", "edit", "bash", "ask_person", "web_fetch", "web_search", "browser", "pdf_pages", "llm"];
|
|
53
|
+
export const TABLE_TOOLS = ["read", "write", "edit", "bash", "ask_person", "web_fetch", "web_search", "browser", "subagent", "pdf_pages", "llm"];
|
|
51
54
|
/** The tools whose approved call the kernel runs itself, outside the model's turn (host-tools.ts's REPLAY): ask is
|
|
52
55
|
* offered for these and for catalog tools. Any other (browser, ask_person, the call-only ones) is allow or deny. The
|
|
53
56
|
* run's learned_workflow is one (tool-gate.ts runs an approved call of it on the run's own tools). */
|
|
@@ -200,37 +203,53 @@ export const isUnavailable = (resolution) => resolution?.startsWith("unavailable
|
|
|
200
203
|
* run's meta and read back, names the variables) names where to save the key first, then the variable to set. */
|
|
201
204
|
export const whyUnavailable = (resolution) => {
|
|
202
205
|
if (resolution === NO_BROWSER_KEY)
|
|
203
|
-
return `it needs ${keyNeeded(
|
|
206
|
+
return `it needs ${BROWSER_VENDORS.map((vendor) => keyNeeded(vendor.keys)).join(", or ")}`;
|
|
204
207
|
const why = resolution.replace(/^unavailable: /, "");
|
|
205
208
|
const picked = /^(\S+) picked, no (.+)$/.exec(why);
|
|
206
209
|
return picked ? `${picked[1]} is picked, and it needs ${keyNeeded(picked[2].split(" and "))}` : why;
|
|
207
210
|
};
|
|
208
|
-
/** The
|
|
209
|
-
*
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
211
|
+
/** The browser's vendors: the computer registry's providers of a browser (kinds.ts PROVIDERS), in its order, each with
|
|
212
|
+
* the keys it needs by name (its required keys: a tool key's fields, tool-keys.ts, set or saved) and its name in words.
|
|
213
|
+
* Its plane value is the provider's id: `kernel` on browser is Kernel's hosted browser, never the guarded fetch
|
|
214
|
+
* web_fetch calls so. A hosted browser provider added to the registry is a vendor here with no edit. A browser
|
|
215
|
+
* provider that needs no key (this machine's Chrome) is no hosted vendor: `auto` would always hold its keys, so it is
|
|
216
|
+
* left out, and an agent picks it as its computer instead. */
|
|
217
|
+
const BROWSER_VENDORS = Object.freeze(hostedBrowsers().map((entry) => Object.freeze({ id: entry.id, label: entry.label, keys: Object.freeze(entry.keys.filter((key) => key.required).map((key) => key.name)) })));
|
|
218
|
+
/** The registry's browser providers that need a key, in its order. */
|
|
219
|
+
function hostedBrowsers() {
|
|
220
|
+
return COMPUTER_PROVIDERS.filter((entry) => entry.kinds.includes("browser") && entry.keys.some((key) => key.required));
|
|
221
|
+
}
|
|
222
|
+
/** The hosted browser providers' ids, in the registry's order (PROVIDERS.browser lists them between `auto` and `chrome`). */
|
|
223
|
+
function browserProviderIds() {
|
|
224
|
+
return hostedBrowsers().map((entry) => entry.id);
|
|
225
|
+
}
|
|
226
|
+
export const BROWSER_VENDOR_IDS = Object.freeze(browserProviderIds());
|
|
227
|
+
export const BROWSER_KEYS = Object.freeze(Object.fromEntries(BROWSER_VENDORS.map((vendor) => [vendor.id, vendor.keys])));
|
|
228
|
+
const LABELS = Object.freeze(Object.fromEntries(BROWSER_VENDORS.map((vendor) => [vendor.id, vendor.label])));
|
|
229
|
+
const isVendor = (name) => typeof name === "string" && Object.hasOwn(BROWSER_KEYS, name);
|
|
230
|
+
const browserKeysOf = (env) => Object.fromEntries(BROWSER_VENDORS.map((vendor) => [vendor.id, vendor.keys.every((name) => Boolean(env[name]))]));
|
|
214
231
|
/** A vendor picked whose keys the server does not hold: unavailable, never the other vendor. */
|
|
215
232
|
const noBrowserKey = (vendor) => `unavailable: ${vendor} picked, no ${BROWSER_KEYS[vendor].join(" and ")}`;
|
|
216
233
|
/** The keys a browser that resolves to `resolution` runs on: its vendor's (BROWSER_KEYS), none for no vendor. */
|
|
217
234
|
export const browserNeeds = (resolution) => (isVendor(resolution) ? BROWSER_KEYS[resolution] : []);
|
|
218
|
-
/** `auto` where the server holds
|
|
219
|
-
export const NO_BROWSER_KEY =
|
|
235
|
+
/** `auto` where the server holds no vendor's keys. */
|
|
236
|
+
export const NO_BROWSER_KEY = `unavailable: no browser key: set or save ${BROWSER_VENDORS.map((vendor) => `${vendor.label}'s (${vendor.keys.join(" and ")})`).join(" or ")}`;
|
|
220
237
|
/** `chrome` picked: a Chrome on the server's own host, refused by name until a server can set one up. */
|
|
221
238
|
export const NO_CHROME = "unavailable: a local Chrome is not set up on this server";
|
|
222
|
-
/** The browser `chosen` (picked as `picked` says) resolves to with the vendors' `keys`: `auto` is
|
|
223
|
-
* keys are held, else Kernel
|
|
224
|
-
* is unavailable by name. */
|
|
225
|
-
function browserBy(chosen, picked, keys = {
|
|
239
|
+
/** The browser `chosen` (picked as `picked` says) resolves to with the vendors' `keys`: `auto` is the registry's first
|
|
240
|
+
* vendor whose keys are held (Browserbase, else Kernel), else unavailable; a vendor picked is that vendor or
|
|
241
|
+
* unavailable; `chrome` is unavailable by name. */
|
|
242
|
+
function browserBy(chosen, picked, keys = {}) {
|
|
226
243
|
if (chosen === "chrome")
|
|
227
244
|
return { resolves: NO_CHROME, why: whyUnavailable(NO_CHROME) };
|
|
228
245
|
if (isVendor(chosen))
|
|
229
246
|
return keys[chosen] ? { resolves: chosen, why: `${LABELS[chosen]}, ${picked}` } : { resolves: noBrowserKey(chosen), why: `${LABELS[chosen]} is picked, and it needs ${keyNeeded(BROWSER_KEYS[chosen])}` };
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
247
|
+
const first = BROWSER_VENDORS.findIndex((vendor) => keys[vendor.id]);
|
|
248
|
+
if (first >= 0) {
|
|
249
|
+
const vendor = BROWSER_VENDORS[first];
|
|
250
|
+
const passed = BROWSER_VENDORS.slice(0, first).map((one) => `${one.label}'s`);
|
|
251
|
+
return { resolves: vendor.id, why: `${vendor.label}: its key is set or saved${passed.length ? `, and ${passed.join(" and ")} is not` : ""}` };
|
|
252
|
+
}
|
|
234
253
|
return { resolves: NO_BROWSER_KEY, why: whyUnavailable(NO_BROWSER_KEY) };
|
|
235
254
|
}
|
|
236
255
|
/** The server's environment's part of every resolution: its gateway and Parallel's key, and where the key is from. */
|
|
@@ -312,9 +331,10 @@ export function keptVendor(plane) {
|
|
|
312
331
|
const vendor = Object.keys(BROWSER_KEYS).find((name) => plane.browser === noBrowserKey(name));
|
|
313
332
|
return vendor ? { ...plane, browser: vendor } : plane;
|
|
314
333
|
}
|
|
315
|
-
/** The key row (tool-keys.ts) of the browser's vendor on `resolution` with `picked` the provider in force:
|
|
316
|
-
*
|
|
317
|
-
|
|
334
|
+
/** The key row (tool-keys.ts) of the browser's vendor on `resolution` with `picked` the provider in force: the vendor it
|
|
335
|
+
* resolved to, else the one picked, else the registry's first (Browserbase), so a page links a missing key to the row
|
|
336
|
+
* it is saved on. */
|
|
337
|
+
export const browserKeyRow = (picked, resolution) => (isVendor(resolution) ? resolution : isVendor(picked) ? picked : BROWSER_VENDORS[0]?.id ?? "browserbase");
|
|
318
338
|
/** The Plane a run's process is handed at a launch, under the server's `settings` now: its kept Plane (as keptVendor
|
|
319
339
|
* reads it) checked again (recheckPlane) against the one it would get today; with none kept, today's, its browser kept
|
|
320
340
|
* (keptFromBefore). At a launch after its first (a relaunch, a follow-up's, one after a restart) a capability set
|
|
@@ -495,12 +515,25 @@ export async function saveToolSettings(store, map) {
|
|
|
495
515
|
await store.settings.put(TOOL_SETTINGS_KEY, written);
|
|
496
516
|
return structuredClone(kept);
|
|
497
517
|
}
|
|
518
|
+
/** Why a tool of bash's family (SHELL_FAMILY: bash and the background tools) is not there for a run whose shell is
|
|
519
|
+
* `shell` (workspace/resolve-computer.ts runShellOf, the claim's own rule read off the agent's computer setting), in the
|
|
520
|
+
* kernel registry's words for a call of it there: with no computer that mounts the run's folder the background tools
|
|
521
|
+
* are refused (NEEDS_A_COMPUTER), and bash too where the run has no shell at all (NO_SHELL, Mode 1); in Mode 2 bash runs
|
|
522
|
+
* on Archil's exec. Undefined for any other tool, and where it is there. */
|
|
523
|
+
export function shellUnavailable(name, shell) {
|
|
524
|
+
if (!Object.hasOwn(SHELL_FAMILY, name) || shell === "computer")
|
|
525
|
+
return undefined;
|
|
526
|
+
if (name === SHELL_FAMILY[name])
|
|
527
|
+
return shell === "none" ? `unavailable: ${NO_SHELL}` : undefined;
|
|
528
|
+
return `unavailable: ${NEEDS_A_COMPUTER}`;
|
|
529
|
+
}
|
|
498
530
|
/** GET /v2/agents/{id}'s `tools`: each tool its current revision grants, in `order` (capabilities.tools'), with its
|
|
499
531
|
* permission in force and where it came from (the agent's own settings, the server's, or the default), the one that
|
|
500
532
|
* applies when the agent sets none (the server's, else the default) and those it may be set to; and for one with a
|
|
501
533
|
* provider choice the provider in force and where it came from, the one that applies when the agent sets none, and what
|
|
502
|
-
* it resolves to on the agent's harness and model.
|
|
503
|
-
|
|
534
|
+
* it resolves to on the agent's harness and model. `shell`: where a run of the agent has its shell (runShellOf on its
|
|
535
|
+
* computer setting); a tool of bash's family that leaves out resolves unavailable, saying why (shellUnavailable). */
|
|
536
|
+
export function agentTools(env, settings, agent, order, shell = "computer") {
|
|
504
537
|
const plane = planeFor(env, agent, settings);
|
|
505
538
|
const rank = (name) => order.indexOf(name);
|
|
506
539
|
return [...new Set(agent.tools)].sort((a, b) => rank(a) - rank(b)).map((name) => {
|
|
@@ -509,6 +542,10 @@ export function agentTools(env, settings, agent, order) {
|
|
|
509
542
|
// One short line for people (tool-blurbs.ts), as capabilities serves it.
|
|
510
543
|
const blurb = blurbOf(name);
|
|
511
544
|
const shown = { name, ...(blurb ? { blurb } : {}) };
|
|
545
|
+
// A tool of bash's family the agent's computer gives no shell for: unavailable, in the words its run's call gets.
|
|
546
|
+
const noShell = shellUnavailable(name, shell);
|
|
547
|
+
if (noShell)
|
|
548
|
+
return { ...shown, ...gate, resolved: noShell };
|
|
512
549
|
if (!Object.hasOwn(PROVIDERS, name))
|
|
513
550
|
return { ...shown, ...gate };
|
|
514
551
|
const pick = name;
|
package/dist/tools.d.ts
CHANGED
|
@@ -7,15 +7,16 @@ import { type Complete } from "./llm.js";
|
|
|
7
7
|
import { type Ledger, type PaidBooking } from "./paid-calls.js";
|
|
8
8
|
import type { Refusal } from "@parcha/agentrun-kernel";
|
|
9
9
|
import { type ShellPlace } from "@parcha/agentrun-kernel/kernel";
|
|
10
|
-
import { type Plane, type Tooling, type ToolSettingsMap } from "./tool-plane.js";
|
|
10
|
+
import { type Plane, type Resolution, type Tooling, type ToolSettingsMap } from "./tool-plane.js";
|
|
11
11
|
import type { DenyFrom, SettingFrom } from "./tool-gate.js";
|
|
12
12
|
import type { LiveHandover, LiveViewerStore } from "./browser-live.js";
|
|
13
13
|
import type { Claim, Store } from "./store/store.js";
|
|
14
14
|
import { type RunSignIn } from "./sign-ins-store.js";
|
|
15
15
|
export declare const ASK_TOOL = "ask_person";
|
|
16
|
-
/** Under `--faux` only: a module whose default export gives the browser's `{
|
|
17
|
-
* environment, the vendor its plane names
|
|
18
|
-
*
|
|
16
|
+
/** Under `--faux` only: a module whose default export gives the browser's `{ computer, driver }` for the run's
|
|
17
|
+
* environment, the vendor its plane names and the saved sign-in it was handed for that vendor (`{ provider, ref, save }`,
|
|
18
|
+
* or undefined): a browser computer provider and a driver in place of the vendor's and the raw-CDP driver (the tests'
|
|
19
|
+
* fake backend). */
|
|
19
20
|
export declare const FAUX_BROWSER_ENV = "AGENTRUN_SERVE_FAUX_BROWSER";
|
|
20
21
|
/** Under `--faux` only: a module whose default export is the fetch a run's first saved sign-in is made with on the runner,
|
|
21
22
|
* in place of the browser vendors' REST APIs (the tests' fake). Absent under --faux, none is made: no network. */
|
|
@@ -68,9 +69,9 @@ export type ToolHost = {
|
|
|
68
69
|
put(handover: LiveHandover): Promise<boolean>;
|
|
69
70
|
drop(tag?: string): Promise<void>;
|
|
70
71
|
};
|
|
71
|
-
/** The one store, for the live-viewer seam above, the run's saved sign-in (its runs and sign-ins, read under `claim`)
|
|
72
|
-
*
|
|
73
|
-
store?: LiveViewerStore & Pick<Store, "runs" | "signIns">;
|
|
72
|
+
/** The one store, for the live-viewer seam above, the run's saved sign-in (its runs and sign-ins, read under `claim`),
|
|
73
|
+
* the sign-in verify the runner saves, and the Screen tab's ended state (settings: browser-wait-ended.ts). */
|
|
74
|
+
store?: LiveViewerStore & Pick<Store, "runs" | "signIns" | "settings">;
|
|
74
75
|
/** The claim this run is held under: the live-viewer rows are written under it (its epoch fences them), and the run's
|
|
75
76
|
* saved sign-in is read and its hand kept under it. Present, the run is on the runner: never the process's own pipe. */
|
|
76
77
|
claim?: Claim;
|
|
@@ -95,7 +96,8 @@ export type ToolHost = {
|
|
|
95
96
|
* folder at `where.work`. */
|
|
96
97
|
workspace?: Workspace;
|
|
97
98
|
/** The agent's computer, where it is a browser (computer-for-claim.ts): the browser tool opens its sessions through the
|
|
98
|
-
* claim's provider
|
|
99
|
+
* claim's provider, whatever the tool plane picked. Absent: the plane's vendor, opened the same way (browser-computer.ts
|
|
100
|
+
* planeBrowser). */
|
|
99
101
|
browserComputer?: ClaimBrowser;
|
|
100
102
|
};
|
|
101
103
|
/** What a name stands for in the run: the pi tools it offers, and the extensions a conversation selects for them. */
|
|
@@ -165,22 +167,11 @@ export declare const uploadsFrom: (work: Workspace, maxBytes: number, mime: (nam
|
|
|
165
167
|
refused: string;
|
|
166
168
|
}>;
|
|
167
169
|
};
|
|
168
|
-
/**
|
|
169
|
-
*
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
};
|
|
174
|
-
/** Kernel's provider, opening the agent's saved profile (`ref`, its name at Kernel) where a session asks for the
|
|
175
|
-
* profile `default`: the policy, the session's record and the model see only that name. */
|
|
176
|
-
export declare const keptProfile: <P extends {
|
|
177
|
-
create(spec: {
|
|
178
|
-
profile?: {
|
|
179
|
-
name: string;
|
|
180
|
-
save: boolean;
|
|
181
|
-
};
|
|
182
|
-
}, signal: AbortSignal): unknown;
|
|
183
|
-
}>(provider: P, ref: string) => P;
|
|
170
|
+
/** Every string in `value` (a tool's answer: its content, its details) passed through `cut`; anything else as it is. An
|
|
171
|
+
* image block's `data` that is an image (wholeImage) is its pixels' base64, not text, and is kept whole: the cut reads a
|
|
172
|
+
* run of more than 8,192 characters with no whitespace as "[redacted]" (key-refusal.ts redactedAnswer), which no model
|
|
173
|
+
* takes as an image. Any other `data`, on a block of any type, is cut like every other string. */
|
|
174
|
+
export declare function cutAnswer<T>(value: T, cut: (text: string) => string): T;
|
|
184
175
|
/** `provider`, its sessions' profile as this launch was handed it, whatever the policy a conversation was made with (a
|
|
185
176
|
* follow-up's was made under an earlier launch, which may have had no sign-in, or another lease): with a sign-in, every
|
|
186
177
|
* session opens on the profile `default`, saving only as `kept.save` says; without one, none asks for a profile. */
|
|
@@ -274,13 +265,6 @@ export declare const shellTools: (shell: ShellPlace) => ReadonlySet<string>;
|
|
|
274
265
|
export declare function toolingOf(revision: Revision): Promise<Tooling>;
|
|
275
266
|
/** The variables `entry` needs that `env` does not set, by name. */
|
|
276
267
|
export declare const missingEnv: (entry: ToolEntry, env: NodeJS.ProcessEnv) => string[];
|
|
277
|
-
/** What keeps `names` from being bound here: names outside the table (or, for a workflow's model nodes, that a node may
|
|
278
|
-
* not name), and the variables each tool in it needs that `env` does not set. Undefined when nothing does. */
|
|
279
|
-
export declare function toolRefusal(names: readonly string[], env: NodeJS.ProcessEnv, where?: "agent" | "nodes" | "calls"): {
|
|
280
|
-
message: string;
|
|
281
|
-
unbound: string[];
|
|
282
|
-
missing: Record<string, string[]>;
|
|
283
|
-
} | undefined;
|
|
284
268
|
/** Every tool as capabilities show it, the server's one tool catalog: available here, or the variables it is missing
|
|
285
269
|
* (names only), and the harnesses that run it (another harness than pi runs only the host tools, host-tools.ts). A tool
|
|
286
270
|
* a user picks a provider for (tool-plane.ts) gives the providers offered, the server's (`provider`, the default where it
|
|
@@ -293,10 +277,10 @@ export declare function toolRefusal(names: readonly string[], env: NodeJS.Proces
|
|
|
293
277
|
* saying that. Each tool also gives its permission under the server's settings (tool-gate.ts), the owner's default
|
|
294
278
|
* and the permissions it may be set to. */
|
|
295
279
|
export declare const toolsView: (env: NodeJS.ProcessEnv, settings?: ToolSettingsMap, noBox?: string, refused?: Readonly<Record<string, string>>, runnerShell?: ReadonlySet<string>) => {
|
|
296
|
-
providers?:
|
|
280
|
+
providers?: string[] | undefined;
|
|
297
281
|
provider?: string | undefined;
|
|
298
|
-
default_provider?:
|
|
299
|
-
resolves?: Record<"opencode" | "codex" | "pi" | "claude-agent",
|
|
282
|
+
default_provider?: string | undefined;
|
|
283
|
+
resolves?: Record<"opencode" | "codex" | "pi" | "claude-agent", Resolution> | undefined;
|
|
300
284
|
why?: Record<"opencode" | "codex" | "pi" | "claude-agent", string> | undefined;
|
|
301
285
|
permission: "deny" | "allow" | "ask";
|
|
302
286
|
default_permission: "deny" | "allow" | "ask";
|
package/dist/tools.js
CHANGED
|
@@ -29,6 +29,7 @@ import { searchFor, WEB_SEARCH_TOOL, webSearchTool } from "./web-search.js";
|
|
|
29
29
|
import { browserNeeds, explainsView, isUnavailable, NO_PARALLEL_KEY, PICKABLE, planeOf, PROVIDERS, serverGate, whyUnavailable, withDefaults } from "./tool-plane.js";
|
|
30
30
|
import { fauxFetch, PARALLEL_KEY_ENV } from "./decisions.js";
|
|
31
31
|
import { keyNeeded } from "./key-words.js";
|
|
32
|
+
import { unattachable } from "./attach-images.js";
|
|
32
33
|
import { handedSignIn } from "./secrets.js";
|
|
33
34
|
import { redactedAnswer } from "./key-refusal.js";
|
|
34
35
|
import { SIGN_IN_KEY, vendorsOver } from "./sign-ins.js";
|
|
@@ -36,11 +37,13 @@ import { answerIn, answerOnce } from "./runner/hand-back.js";
|
|
|
36
37
|
import { waitingAsk } from "./browser-commands.js";
|
|
37
38
|
import { runnerSecrets } from "./runner/redact.js";
|
|
38
39
|
import { HANDOVER_WAITING } from "./runner/journal-kinds.js";
|
|
40
|
+
import { clearWaitEnded, markWaitEnded } from "./browser-wait-ended.js";
|
|
39
41
|
import { runSignIn, verifyRunSignIn } from "./sign-ins-store.js";
|
|
40
42
|
export const ASK_TOOL = "ask_person";
|
|
41
|
-
/** Under `--faux` only: a module whose default export gives the browser's `{
|
|
42
|
-
* environment, the vendor its plane names
|
|
43
|
-
*
|
|
43
|
+
/** Under `--faux` only: a module whose default export gives the browser's `{ computer, driver }` for the run's
|
|
44
|
+
* environment, the vendor its plane names and the saved sign-in it was handed for that vendor (`{ provider, ref, save }`,
|
|
45
|
+
* or undefined): a browser computer provider and a driver in place of the vendor's and the raw-CDP driver (the tests'
|
|
46
|
+
* fake backend). */
|
|
44
47
|
export const FAUX_BROWSER_ENV = "AGENTRUN_SERVE_FAUX_BROWSER";
|
|
45
48
|
/** Under `--faux` only: a module whose default export is the fetch a run's first saved sign-in is made with on the runner,
|
|
46
49
|
* in place of the browser vendors' REST APIs (the tests' fake). Absent under --faux, none is made: no network. */
|
|
@@ -177,24 +180,28 @@ export const uploadsFrom = (work, maxBytes, mime) => ({
|
|
|
177
180
|
}
|
|
178
181
|
},
|
|
179
182
|
});
|
|
180
|
-
/**
|
|
181
|
-
*
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
183
|
+
/** An image block's `data` kept whole by the cut: its base64 is an image a model can be sent (attach-images.ts
|
|
184
|
+
* unattachable: a PNG, JPEG, GIF or WebP whose bytes are the type it names and whose header says its size), and its
|
|
185
|
+
* decoded bytes, read as text, hold nothing the cut takes out (a held value written after a valid header). */
|
|
186
|
+
const wholeImage = (block, cut) => {
|
|
187
|
+
if (unattachable(block) !== undefined)
|
|
188
|
+
return false;
|
|
189
|
+
const bytes = Buffer.from(block.data, "base64").toString("latin1");
|
|
190
|
+
return cut(bytes) === bytes;
|
|
191
|
+
};
|
|
192
|
+
/** Every string in `value` (a tool's answer: its content, its details) passed through `cut`; anything else as it is. An
|
|
193
|
+
* image block's `data` that is an image (wholeImage) is its pixels' base64, not text, and is kept whole: the cut reads a
|
|
194
|
+
* run of more than 8,192 characters with no whitespace as "[redacted]" (key-refusal.ts redactedAnswer), which no model
|
|
195
|
+
* takes as an image. Any other `data`, on a block of any type, is cut like every other string. */
|
|
196
|
+
export function cutAnswer(value, cut) {
|
|
192
197
|
if (typeof value === "string")
|
|
193
198
|
return cut(value);
|
|
194
199
|
if (Array.isArray(value))
|
|
195
|
-
return value.map((item) =>
|
|
200
|
+
return value.map((item) => cutAnswer(item, cut));
|
|
196
201
|
if (value && typeof value === "object" && Object.getPrototypeOf(value) === Object.prototype) {
|
|
197
|
-
|
|
202
|
+
const block = value;
|
|
203
|
+
const keep = block.type === "image" && wholeImage(block, cut);
|
|
204
|
+
return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, keep && key === "data" ? item : cutAnswer(item, cut)]));
|
|
198
205
|
}
|
|
199
206
|
return value;
|
|
200
207
|
}
|
|
@@ -205,7 +212,7 @@ function answersCutInside(tool, cut) {
|
|
|
205
212
|
...tool,
|
|
206
213
|
execute: (async (...args) => {
|
|
207
214
|
try {
|
|
208
|
-
return
|
|
215
|
+
return cutAnswer(await tool.execute(...args), cut);
|
|
209
216
|
}
|
|
210
217
|
catch (error) {
|
|
211
218
|
if (error instanceof Error) {
|
|
@@ -218,12 +225,6 @@ function answersCutInside(tool, cut) {
|
|
|
218
225
|
}),
|
|
219
226
|
};
|
|
220
227
|
}
|
|
221
|
-
/** Kernel's provider, opening the agent's saved profile (`ref`, its name at Kernel) where a session asks for the
|
|
222
|
-
* profile `default`: the policy, the session's record and the model see only that name. */
|
|
223
|
-
export const keptProfile = (provider, ref) => ({
|
|
224
|
-
...provider,
|
|
225
|
-
create: (spec, signal) => provider.create(spec.profile?.name === SIGN_IN_KEY ? { ...spec, profile: { ...spec.profile, name: ref } } : spec, signal),
|
|
226
|
-
});
|
|
227
228
|
/** `provider`, its sessions' profile as this launch was handed it, whatever the policy a conversation was made with (a
|
|
228
229
|
* follow-up's was made under an earlier launch, which may have had no sign-in, or another lease): with a sign-in, every
|
|
229
230
|
* session opens on the profile `default`, saving only as `kept.save` says; without one, none asks for a profile. */
|
|
@@ -244,15 +245,17 @@ export const runSignInSaved = (store, sealKey, claim, kept) => async (row, chang
|
|
|
244
245
|
const ended = row.session.endedAt ? Date.parse(row.session.endedAt) : Number.NaN;
|
|
245
246
|
return verifyRunSignIn(store, sealKey, claim, kept, Number.isFinite(ended) ? ended : Date.now());
|
|
246
247
|
};
|
|
247
|
-
/** A
|
|
248
|
-
*
|
|
249
|
-
*
|
|
250
|
-
*
|
|
251
|
-
*
|
|
252
|
-
*
|
|
253
|
-
*
|
|
254
|
-
*
|
|
255
|
-
*
|
|
248
|
+
/** A browser on pi-browser's durable adapter, its sessions a browser computer provider's of the computer registry
|
|
249
|
+
* (browser-computer.ts), each driven over its CDP URL by pi-browser's raw-CDP driver: the agent's computer, where it is
|
|
250
|
+
* a browser (the claim's, computer-for-claim.ts), else the one the run's plane names (tool-plane.ts: picked, else
|
|
251
|
+
* Browserbase where the server holds its keys, else Kernel), kept for the run's life; a plane that names none (a run kept
|
|
252
|
+
* from before the pick) is Browserbase. Its sessions' custody lives in the run's own store. No recording; the owner
|
|
253
|
+
* watches it live, takes it over and hands it back, and the agent may ask them to (browser-live.ts, browser-person.ts).
|
|
254
|
+
* A session the run still holds is released when the run is let go. Where the plane says unavailable (its vendor's key
|
|
255
|
+
* gone since), each call is refused, saying why. Its session time is the run's spend, held under its cap before it runs
|
|
256
|
+
* (browser-cost.ts). A run on the plane's vendor handed its agent's saved sign-in for that vendor (sign-ins.ts) opens
|
|
257
|
+
* every session on it, as the profile `default`, saving only where it holds the agent's save lease; one that saved says
|
|
258
|
+
* so in its run directory. */
|
|
256
259
|
const browserTool = {
|
|
257
260
|
summary: "Drive a hosted browser, Browserbase's or Kernel's (picked in tool settings, else whichever's key the server holds): open pages, read and screenshot them, and act on them.",
|
|
258
261
|
// Which vendor's keys it needs is the plane's to say (tool-plane.ts BROWSER_KEYS): neither alone is required.
|
|
@@ -264,42 +267,59 @@ const browserTool = {
|
|
|
264
267
|
// Its downloads go into work/ by path (pi-browser), which a box's command could turn through a link.
|
|
265
268
|
runnerOnly: true,
|
|
266
269
|
bind: async (host) => {
|
|
267
|
-
const [{ BACKGROUND_CONTEXT: context }, { createBrowserExtension }, { DEFAULT_BROWSER_POLICY, BrowserFailureError, browserFailure, MAX_UPLOAD_BYTES, uploadMime }, { createDrivingGates, createLiveView, liveViewProvider }, live, person] = await Promise.all([
|
|
270
|
+
const [{ BACKGROUND_CONTEXT: context }, { createBrowserExtension }, { DEFAULT_BROWSER_POLICY, BrowserFailureError, browserFailure, MAX_UPLOAD_BYTES, uploadMime }, { createDrivingGates, createLiveView, liveViewProvider }, live, person, { claimBrowserProvider, closeHeldSockets, planeBrowser, planeComputer, releaseOlderBrowsers }, { cdpDriver }] = await Promise.all([
|
|
268
271
|
import("@earendil-works/chord/context"),
|
|
269
272
|
import("@parcha/pi-browser/durable"),
|
|
270
273
|
import("@parcha/pi-browser"),
|
|
271
274
|
import("@parcha/pi-browser/live-view"),
|
|
272
275
|
import("./browser-live.js"),
|
|
273
276
|
import("./browser-person.js"),
|
|
277
|
+
import("./browser-computer.js"),
|
|
278
|
+
import("@parcha/pi-browser/driver/cdp"),
|
|
274
279
|
]);
|
|
275
280
|
// The agent's computer, where it is a browser, wins over the plane's pick: the run's sessions are that provider's,
|
|
276
|
-
// opened through the claim
|
|
277
|
-
// saved sign-in or plane check of their own.
|
|
281
|
+
// opened through the claim, with no saved sign-in or plane check of their own.
|
|
278
282
|
const computer = host.browserComputer;
|
|
279
283
|
const planeVendor = planeOf(host.env).browser ?? "browserbase";
|
|
280
284
|
const vendor = computer?.provider ?? planeVendor;
|
|
281
|
-
const
|
|
285
|
+
const planeRefused = !computer && isUnavailable(planeVendor) ? new BrowserFailureError(browserFailure("browser_unavailable", `The browser does not run here: ${whyUnavailable(planeVendor)}.`)) : undefined;
|
|
282
286
|
// The run's saved sign-in: on the runner (one process, many claims) read from the store under this run's own claim
|
|
283
287
|
// (sign-ins-store.ts runSignIn), never from the process; on the old per-run process, over its own secrets' pipe.
|
|
284
288
|
// An agent with none saved has its first made at the vendor now, over this run's own claim keys (host.env), as main's
|
|
285
289
|
// launch makes it: never the process's environment, so one run's keys never make another's.
|
|
286
290
|
const runLog = (line) => void process.stderr.write(`agentrun-serve: run ${host.where.ref.id}: ${line}\n`);
|
|
287
291
|
const vendorFetch = async () => (host.env[FAUX_ENV] ? fauxFetch(host.env, FAUX_VENDOR_API_ENV) : fetch);
|
|
288
|
-
const handed = computer ? undefined : host.claim ? (
|
|
289
|
-
const kept = !
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
292
|
+
const handed = computer ? undefined : host.claim ? (planeRefused || !host.store || !host.sealKey ? undefined : await runSignIn(host.store, host.sealKey, host.claim, vendor, { vendors: vendorsOver(() => host.env, vendorFetch), log: runLog })) : handedSignIn();
|
|
293
|
+
const kept = !planeRefused && handed?.provider === vendor ? handed : undefined;
|
|
294
|
+
// Tests only (--faux): the faux browser's computer provider and driver stand in for the plane vendor's and the raw-CDP
|
|
295
|
+
// driver. The agent's browser computer is still the claim's, so a test hands the claim a faux provider of its own.
|
|
296
|
+
const faux = !computer && host.env[FAUX_ENV] ? host.env[FAUX_BROWSER_ENV] : undefined;
|
|
297
|
+
const stand = faux ? (await import(pathToFileURL(faux).href)).default(host.env, vendor, kept) : undefined;
|
|
298
|
+
// The session's browser: the claim's (the agent's computer), else the plane's vendor on the run's tool keys, opened
|
|
299
|
+
// the same way under the run's labels. One that cannot be made refuses each call, in its words.
|
|
300
|
+
const made = planeRefused
|
|
301
|
+
? { refused: planeRefused }
|
|
302
|
+
: await (async () => {
|
|
303
|
+
try {
|
|
304
|
+
if (computer)
|
|
305
|
+
return { browser: computer };
|
|
306
|
+
const provider = stand ? stand.computer : await planeComputer(vendor, host.env);
|
|
307
|
+
const plane = planeBrowser(provider, host.claim);
|
|
308
|
+
if (host.claim && !stand)
|
|
309
|
+
await releaseOlderBrowsers(provider, host.claim);
|
|
310
|
+
return { browser: plane };
|
|
311
|
+
}
|
|
312
|
+
catch (error) {
|
|
313
|
+
if (error instanceof BrowserFailureError)
|
|
314
|
+
return { refused: error };
|
|
315
|
+
return { refused: new BrowserFailureError(browserFailure("browser_unavailable", `The browser does not run here: ${error instanceof Error ? error.message : String(error)}.`)) };
|
|
316
|
+
}
|
|
317
|
+
})();
|
|
318
|
+
const refused = "refused" in made ? made.refused : undefined;
|
|
319
|
+
const parts = {
|
|
320
|
+
provider: "browser" in made ? claimBrowserProvider(made.browser, { headless: true, ...(host.env.BROWSERBASE_CONNECT_BASE_URL ? { connectBaseUrl: host.env.BROWSERBASE_CONNECT_BASE_URL } : {}), ...(kept ? { signIn: { name: SIGN_IN_KEY, pointer: kept.ref } } : {}) }) : undefined,
|
|
321
|
+
driver: stand ? stand.driver : cdpDriver(),
|
|
322
|
+
};
|
|
303
323
|
// The save flag every session carries is this launch's (asHanded), never the one stored with its conversation.
|
|
304
324
|
const handedProvider = parts.provider ? asHanded(parts.provider, kept) : undefined;
|
|
305
325
|
// The owner's live view (browser-live.ts): pi-browser's own viewer on a loopback port of this process's, over every
|
|
@@ -331,6 +351,12 @@ const browserTool = {
|
|
|
331
351
|
// the run's own cut on the runner (host.redact: the claim's keys too, every tool's, in every form), and the secrets
|
|
332
352
|
// its env holds (runnerSecrets: hostSecrets and every launcher name's value) with its sign-in's pointer.
|
|
333
353
|
redact: (text) => redactedAnswer(host.redact ? host.redact(text) : text, [...runnerSecrets(host.env), ...(kept ? [kept.ref] : [])]),
|
|
354
|
+
// The Screen tab's ended state, one settings row the server reads per poll (browser-wait-ended.ts); cleared as a
|
|
355
|
+
// session opens (onSessions, below).
|
|
356
|
+
waitEnded: (at, why) => {
|
|
357
|
+
if (host.store && host.claim)
|
|
358
|
+
void markWaitEnded(host.store.settings, host.claim.runId, { at: new Date(at).toISOString(), why }, host.claim.epoch).catch(() => undefined);
|
|
359
|
+
},
|
|
334
360
|
note: async (kind, data) => {
|
|
335
361
|
// A hand-over's waiting entry, on the runner: the row says the run waits on the person in its browser from that
|
|
336
362
|
// commit (the server tells run.needs_input by it), and no more from its answer's, whoever writes it.
|
|
@@ -400,6 +426,9 @@ const browserTool = {
|
|
|
400
426
|
// A session let go ends a wait on the person's answer that kept it open (personWait, below): the run parks.
|
|
401
427
|
if (change === "released")
|
|
402
428
|
hands.sessionEnded(row.session.tag);
|
|
429
|
+
// A session that opens, whatever let the last one go: the Screen tab's ended state goes (browser-wait-ended.ts).
|
|
430
|
+
if (change === "launched" && host.store && host.claim)
|
|
431
|
+
await clearWaitEnded(host.store.settings, host.claim.runId, host.claim.epoch).catch(() => undefined);
|
|
403
432
|
await saved?.(row, change);
|
|
404
433
|
await onSession(row, change);
|
|
405
434
|
};
|
|
@@ -469,7 +498,9 @@ const browserTool = {
|
|
|
469
498
|
// (live, or held for a hand-over), the run waits for the answer in its claim, so the session, its live viewer and its
|
|
470
499
|
// page stay for the person and for the agent's next turn, as main's process kept them; the person's time on each such
|
|
471
500
|
// session is held under the run's cap the way a hand-over's is (personHands.wait). With none open, or no room under
|
|
472
|
-
// the cap for that time, the run parks (its release lets the browser go).
|
|
501
|
+
// the cap for that time, the run parks (its release lets the browser go). While it waits, pi-browser's idle release
|
|
502
|
+
// keeps its hands off those sessions (keepForPerson): the person's window (AGENTRUN_BROWSER_PERSON_WAIT_MIN), not the
|
|
503
|
+
// browser's few-minute idle window, decides when the browser goes.
|
|
473
504
|
host.personWait?.(async (harness, callId, since) => {
|
|
474
505
|
if (refused)
|
|
475
506
|
return undefined;
|
|
@@ -477,8 +508,15 @@ const browserTool = {
|
|
|
477
508
|
const open = rows.filter((row) => (row.state === "live" || row.state === "held") && row.resourceId !== null).map((row) => row.tag);
|
|
478
509
|
if (!open.length)
|
|
479
510
|
return undefined;
|
|
511
|
+
const keeps = open.map((tag) => browser.keepForPerson(tag));
|
|
512
|
+
const letGo = () => { for (const keep of keeps.splice(0))
|
|
513
|
+
keep(); };
|
|
480
514
|
const waited = await hands.wait(callId, open, since);
|
|
481
|
-
|
|
515
|
+
if ("refused" in waited) {
|
|
516
|
+
letGo();
|
|
517
|
+
return undefined;
|
|
518
|
+
}
|
|
519
|
+
return { lapsed: waited.lapsed, confirmed: waited.confirmed, drop: () => { waited.drop(); letGo(); } };
|
|
482
520
|
});
|
|
483
521
|
host.beforeRelease(async (harness) => {
|
|
484
522
|
try {
|
|
@@ -501,6 +539,10 @@ const browserTool = {
|
|
|
501
539
|
await view.close();
|
|
502
540
|
hands.close();
|
|
503
541
|
await viewers.released();
|
|
542
|
+
// The download sockets this run's sessions hold go with it, released or left to the next claim (whose attach
|
|
543
|
+
// opens its own): one left open would keep the process from exiting.
|
|
544
|
+
if ("browser" in made)
|
|
545
|
+
await closeHeldSockets(made.browser);
|
|
504
546
|
}
|
|
505
547
|
});
|
|
506
548
|
return { tools, extensions: [extension] };
|
|
@@ -536,6 +578,14 @@ export const TOOLS = Object.freeze({
|
|
|
536
578
|
"monid.discover": monidTool("discover"),
|
|
537
579
|
"monid.inspect": monidTool("inspect"),
|
|
538
580
|
"monid.run": monidTool("run"),
|
|
581
|
+
// A pi run's subagent (runner/subagent.ts): a native tool of the run's root agent, bound by the runner's pi spec
|
|
582
|
+
// (adapter-run-spec.ts), never by this table; not a host tool (host-tools.ts REPLAY), so another harness refuses it.
|
|
583
|
+
subagent: {
|
|
584
|
+
summary: "Run a subagent: a fresh conversation with only the call's prompt, on the agent's own model (or one of its model tiers, fast or strong, when the call names one), with a subset of the agent's own tools (bash among them, under the agent's bash policy), under the run's permissions and cap; answers with its final text. A call may narrow its child's tool-call budget (max_tool_calls) and set its effort (low, medium, high). Several calls in a turn run at once, at most 4 at a time; a subagent starts none of its own. pi only.",
|
|
585
|
+
needs: [],
|
|
586
|
+
nodes: false,
|
|
587
|
+
bind: async () => ({ tools: [], extensions: [] }),
|
|
588
|
+
},
|
|
539
589
|
[PDF_PAGES_TOOL]: callOnly("A workflow call: { path, maxPages?, dpi? } -> { name, pageCount, dpi, pages: [{ page, image }], text }; the document's first pages drawn as PNGs under work/pages/<stem>/<dpi>/ (the dpi lowered so a page's long side is at most 1568 px), from the server's documents (--documents) or the run's work directory.", (args, run) => pdfPages(args, { work: localWorkspace(run.work), documents: run.env[DOCUMENTS_ENV], signal: run.signal })),
|
|
540
590
|
[LLM_TOOL]: callOnly("A workflow call: { prompt, system?, maxTokens?, tier? } -> { text, model, usage, cost_usd }; one completion on the model of the tier (default), no tools and no loop.", (args, run) => {
|
|
541
591
|
if (!run.complete)
|
|
@@ -635,22 +685,6 @@ export async function toolingOf(revision) {
|
|
|
635
685
|
}
|
|
636
686
|
/** The variables `entry` needs that `env` does not set, by name. */
|
|
637
687
|
export const missingEnv = (entry, env) => entry.needs.filter((name) => !env[name]);
|
|
638
|
-
/** What keeps `names` from being bound here: names outside the table (or, for a workflow's model nodes, that a node may
|
|
639
|
-
* not name), and the variables each tool in it needs that `env` does not set. Undefined when nothing does. */
|
|
640
|
-
export function toolRefusal(names, env, where = "agent") {
|
|
641
|
-
const allowed = where === "nodes" ? NODE_TOOLS : where === "calls" ? CALL_TOOLS : BOUND_TOOLS;
|
|
642
|
-
const unbound = names.filter((name) => !allows(allowed, name));
|
|
643
|
-
if (unbound.length) {
|
|
644
|
-
const said = { agent: "agentrun-serve binds the tools", nodes: "A workflow's model nodes get the tools", calls: "A workflow's call nodes run the tools" }[where];
|
|
645
|
-
return { message: `${said} ${allowed.join(", ")}; this ${where === "agent" ? "revision" : "workflow"} also ${where === "calls" ? "calls" : "names"} ${unbound.join(", ")}.`, unbound, missing: {} };
|
|
646
|
-
}
|
|
647
|
-
const missing = Object.fromEntries(names.map((name) => [name, missingEnv(toolOf(name), env)]).filter(([, vars]) => vars.length));
|
|
648
|
-
const lacking = Object.entries(missing);
|
|
649
|
-
if (!lacking.length)
|
|
650
|
-
return undefined;
|
|
651
|
-
const said = lacking.map(([name, vars]) => `The tool ${name} needs ${keyNeeded(vars)}.`).join(" ");
|
|
652
|
-
return { message: `This server holds no key for what the revision's tools need. ${said}`, unbound: [], missing };
|
|
653
|
-
}
|
|
654
688
|
/** Every tool as capabilities show it, the server's one tool catalog: available here, or the variables it is missing
|
|
655
689
|
* (names only), and the harnesses that run it (another harness than pi runs only the host tools, host-tools.ts). A tool
|
|
656
690
|
* a user picks a provider for (tool-plane.ts) gives the providers offered, the server's (`provider`, the default where it
|
|
@@ -39,6 +39,7 @@ export declare const SIGNATURE_SCHEMES: {
|
|
|
39
39
|
deliveryIdOf: (headers: Headers) => string;
|
|
40
40
|
eventOf: (headers: Headers) => string;
|
|
41
41
|
attrsOf(json: unknown): {
|
|
42
|
+
base_sha?: string | undefined;
|
|
42
43
|
head_sha?: string | undefined;
|
|
43
44
|
number?: string | undefined;
|
|
44
45
|
};
|
|
@@ -53,16 +53,18 @@ export const SIGNATURE_SCHEMES = {
|
|
|
53
53
|
deliveryIdOf: (headers) => headers["x-github-delivery"],
|
|
54
54
|
eventOf: (headers) => headers["x-github-event"],
|
|
55
55
|
// The pull request or issue's number (an issue_comment on a pull request is its issue's), and a pull request's head
|
|
56
|
-
//
|
|
56
|
+
// and base shas, which a long description pushes past the payload's cut. A comment event has no head: none is guessed.
|
|
57
57
|
attrsOf(json) {
|
|
58
58
|
const doc = isObject(json) ? json : {};
|
|
59
59
|
const pr = isObject(doc.pull_request) ? doc.pull_request : undefined;
|
|
60
60
|
const issue = isObject(doc.issue) ? doc.issue : undefined;
|
|
61
61
|
const number = pr?.number ?? issue?.number;
|
|
62
62
|
const sha = isObject(pr?.head) ? pr.head.sha : undefined;
|
|
63
|
+
const base = isObject(pr?.base) ? pr.base.sha : undefined;
|
|
63
64
|
return {
|
|
64
65
|
...(Number.isSafeInteger(number) && number > 0 ? { number: String(number) } : {}),
|
|
65
66
|
...(typeof sha === "string" && /^[0-9a-f]{40}$/.test(sha) ? { head_sha: sha } : {}),
|
|
67
|
+
...(typeof base === "string" && /^[0-9a-f]{40}$/.test(base) ? { base_sha: base } : {}),
|
|
66
68
|
};
|
|
67
69
|
},
|
|
68
70
|
},
|