@parcha/agentrun-serve 0.1.0-beta.38 → 0.1.0-beta.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +455 -0
- package/README.md +376 -125
- package/dist/adapters.d.ts +4 -1
- package/dist/adapters.js +4 -2
- package/dist/agent-rows.d.ts +0 -2
- package/dist/agents-store.d.ts +5 -5
- package/dist/agents-store.js +14 -14
- package/dist/bash-read-only.js +2 -1
- package/dist/cap-short.d.ts +12 -0
- package/dist/cap-short.js +60 -0
- package/dist/cap.d.ts +3 -10
- package/dist/cap.js +2 -5
- package/dist/catalog.d.ts +0 -5
- package/dist/catalog.js +1 -5
- package/dist/chatgpt-plan.d.ts +163 -0
- package/dist/chatgpt-plan.js +549 -0
- package/dist/cli.js +26 -6
- package/dist/composio-preset.d.ts +8 -0
- package/dist/composio-preset.js +8 -7
- package/dist/composio-triggers.d.ts +113 -0
- package/dist/composio-triggers.js +411 -0
- package/dist/computer-calls.js +2 -2
- package/dist/computer-commands.d.ts +2 -0
- package/dist/computer-commands.js +7 -3
- package/dist/computer-live.d.ts +7 -2
- package/dist/computer-live.js +9 -5
- package/dist/computer-routes.d.ts +2 -2
- package/dist/computer-routes.js +2 -2
- package/dist/computer-setting.d.ts +3 -3
- package/dist/computer-setting.js +5 -5
- package/dist/computer-view.d.ts +15 -0
- package/dist/computer-view.js +16 -2
- package/dist/computer-viewer.js +14 -1
- package/dist/computers.d.ts +5 -2
- package/dist/computers.js +9 -5
- package/dist/console/assets/index-B8Zn1Iqn.css +1 -0
- package/dist/console/assets/index-Jbxjcmdp.js +705 -0
- package/dist/console/index.html +2 -2
- package/dist/console-links.js +3 -3
- package/dist/decision-cap.d.ts +2 -5
- package/dist/decision-cap.js +3 -6
- package/dist/decision-rows.js +11 -11
- package/dist/email/account.d.ts +83 -0
- package/dist/email/account.js +159 -0
- package/dist/email/answer.d.ts +15 -0
- package/dist/email/answer.js +217 -0
- package/dist/email/email-faux.d.ts +95 -0
- package/dist/email/email-faux.js +849 -0
- package/dist/email/labels.d.ts +1 -0
- package/dist/email/labels.js +84 -0
- package/dist/email/mail.d.ts +186 -0
- package/dist/email/mail.js +373 -0
- package/dist/email/names.d.ts +50 -0
- package/dist/email/names.js +74 -0
- package/dist/email/routes.d.ts +10 -0
- package/dist/email/routes.js +50 -0
- package/dist/email/tools.d.ts +27 -0
- package/dist/email/tools.js +562 -0
- package/dist/environment.d.ts +17 -2
- package/dist/environment.js +36 -8
- package/dist/errors.d.ts +6 -0
- package/dist/errors.js +12 -0
- package/dist/eval-mailbox.d.ts +103 -0
- package/dist/eval-mailbox.js +236 -0
- package/dist/graph-view.d.ts +9 -2
- package/dist/graph-view.js +6 -2
- package/dist/harness-install.d.ts +28 -2
- package/dist/harness-install.js +147 -59
- package/dist/harness-opencode/adapter.js +2 -26
- package/dist/harness-opencode/facts.js +5 -2
- package/dist/harness-opencode/host/policy.d.ts +2 -0
- package/dist/harness-opencode/host/policy.js +10 -5
- package/dist/harness-opencode/index.d.ts +1 -1
- package/dist/harness-opencode/index.js +1 -1
- package/dist/harness-opencode/versions.d.ts +6 -0
- package/dist/harness-opencode/versions.js +6 -0
- package/dist/harness-table.js +8 -5
- package/dist/harness.d.ts +12 -0
- package/dist/harness.js +15 -3
- package/dist/hosted-search.d.ts +3 -1
- package/dist/hosted-search.js +51 -11
- package/dist/import-sources.d.ts +1 -1
- package/dist/import-sources.js +3 -3
- package/dist/import.d.ts +21 -0
- package/dist/import.js +186 -1
- package/dist/key-check.d.ts +0 -2
- package/dist/key-check.js +3 -4
- package/dist/key-refusal.d.ts +8 -2
- package/dist/key-refusal.js +16 -13
- package/dist/learn/check.d.ts +18 -3
- package/dist/learn/check.js +328 -3
- package/dist/learn/compile.d.ts +12 -4
- package/dist/learn/compile.js +57 -20
- package/dist/learn/grade.d.ts +4 -0
- package/dist/learn/grade.js +4 -1
- package/dist/learn/promote.d.ts +130 -64
- package/dist/learn/promote.js +113 -202
- package/dist/learn/refit.d.ts +21 -12
- package/dist/learn/refit.js +51 -23
- package/dist/learn/replay-calls.js +1 -1
- package/dist/learn/skills.d.ts +2 -7
- package/dist/learn/skills.js +28 -14
- package/dist/learned-nodes.d.ts +15 -7
- package/dist/learned-nodes.js +29 -5
- package/dist/learned-workflow.d.ts +41 -31
- package/dist/learned-workflow.js +122 -63
- package/dist/learning-batch.js +3 -3
- package/dist/learning-cost.d.ts +35 -8
- package/dist/learning-cost.js +27 -9
- package/dist/learning-routes.d.ts +2 -4
- package/dist/learning-routes.js +20 -3
- package/dist/learning-words.d.ts +1 -1
- package/dist/learning-words.js +4 -1
- package/dist/learning.d.ts +5 -5
- package/dist/link-check.d.ts +27 -0
- package/dist/link-check.js +164 -0
- package/dist/local-models.d.ts +39 -2
- package/dist/local-models.js +49 -5
- package/dist/mcp-pin-first.js +6 -0
- package/dist/mcp-secret-writes.js +3 -0
- package/dist/mcp-servers-store.d.ts +25 -16
- package/dist/mcp-servers-store.js +23 -3
- package/dist/model-form.d.ts +11 -0
- package/dist/model-form.js +17 -1
- package/dist/model.d.ts +26 -6
- package/dist/model.js +126 -18
- package/dist/monid.d.ts +26 -31
- package/dist/monid.js +84 -79
- package/dist/native/binding.d.ts +13 -0
- package/dist/native/binding.js +57 -0
- package/dist/native/cli.d.ts +2 -0
- package/dist/native/cli.js +48 -0
- package/dist/native/connection.d.ts +8 -0
- package/dist/native/connection.js +94 -0
- package/dist/native/context.d.ts +6 -0
- package/dist/native/context.js +22 -0
- package/dist/native/discovery.d.ts +27 -0
- package/dist/native/discovery.js +404 -0
- package/dist/native/environment.d.ts +4 -0
- package/dist/native/environment.js +18 -0
- package/dist/native/history.d.ts +20 -0
- package/dist/native/history.js +147 -0
- package/dist/native/instructions.d.ts +21 -0
- package/dist/native/instructions.js +173 -0
- package/dist/native/remote-worker-bridge.d.ts +3 -0
- package/dist/native/remote-worker-bridge.js +278 -0
- package/dist/native/remote.d.ts +187 -0
- package/dist/native/remote.js +492 -0
- package/dist/native/runtime.d.ts +17 -0
- package/dist/native/runtime.js +316 -0
- package/dist/native/runtimes.d.ts +66 -0
- package/dist/native/runtimes.js +41 -0
- package/dist/native/schema.d.ts +46 -0
- package/dist/native/schema.js +41 -0
- package/dist/native/types.d.ts +87 -0
- package/dist/native/types.js +1 -0
- package/dist/observation/http.d.ts +4 -0
- package/dist/observation/http.js +140 -0
- package/dist/observation/observer.d.ts +301 -0
- package/dist/observation/observer.js +919 -0
- package/dist/observation/schema.d.ts +52 -0
- package/dist/observation/schema.js +154 -0
- package/dist/openapi.d.ts +2 -1
- package/dist/openapi.js +404 -93
- package/dist/paid-calls.d.ts +8 -3
- package/dist/paid-calls.js +6 -2
- package/dist/place-offers.d.ts +4 -8
- package/dist/place-offers.js +4 -9
- package/dist/port-models.d.ts +10 -2
- package/dist/port-models.js +6 -2
- package/dist/print.d.ts +4 -2
- package/dist/print.js +4 -3
- package/dist/propose.d.ts +1 -2
- package/dist/propose.js +10 -1
- package/dist/provider.d.ts +5 -1
- package/dist/provider.js +8 -0
- package/dist/push-handler.d.ts +3 -2
- package/dist/push-handler.js +20 -6
- package/dist/refusal-words.d.ts +14 -0
- package/dist/refusal-words.js +16 -2
- package/dist/run-launch.d.ts +12 -1
- package/dist/run-launch.js +13 -4
- package/dist/run-learning-served.d.ts +75 -2
- package/dist/run-manifest.d.ts +3 -0
- package/dist/run-manifest.js +13 -1
- package/dist/run-reads-over-store.d.ts +3 -3
- package/dist/run-reads-over-store.js +13 -10
- package/dist/run-timeline-served.d.ts +3 -2
- package/dist/run-timeline-served.js +8 -9
- package/dist/run-view.d.ts +44 -38
- package/dist/run-view.js +93 -56
- package/dist/runnable.d.ts +13 -5
- package/dist/runnable.js +69 -60
- package/dist/runner/adapter-loop.d.ts +48 -13
- package/dist/runner/adapter-loop.js +691 -254
- package/dist/runner/adapter-run-spec.d.ts +38 -12
- package/dist/runner/adapter-run-spec.js +175 -106
- package/dist/runner/adapters/pi.d.ts +24 -0
- package/dist/runner/adapters/pi.js +59 -9
- package/dist/runner/beside.d.ts +3 -1
- package/dist/runner/beside.js +24 -8
- package/dist/runner/claim-secrets.d.ts +3 -1
- package/dist/runner/claim-secrets.js +28 -4
- package/dist/runner/cli-run-spec.d.ts +30 -0
- package/dist/runner/cli-run-spec.js +95 -50
- package/dist/runner/computer-channel.d.ts +5 -2
- package/dist/runner/computer-channel.js +3 -2
- package/dist/runner/computer-journal.d.ts +6 -0
- package/dist/runner/computer-journal.js +8 -10
- package/dist/runner/conformance/harness.js +6 -3
- package/dist/runner/end-of-run.d.ts +2 -0
- package/dist/runner/end-of-run.js +3 -1
- package/dist/runner/feedback-round.d.ts +40 -13
- package/dist/runner/feedback-round.js +64 -16
- package/dist/runner/harness-loops.js +17 -0
- package/dist/runner/journal-kinds.d.ts +59 -13
- package/dist/runner/journal-kinds.js +48 -5
- package/dist/runner/learning-dispatch.d.ts +3 -2
- package/dist/runner/learning-dispatch.js +6 -6
- package/dist/runner/learning-end.d.ts +4 -0
- package/dist/runner/learning-end.js +64 -36
- package/dist/runner/learning-factory.d.ts +3 -0
- package/dist/runner/learning-factory.js +8 -2
- package/dist/runner/learning-loop.d.ts +2 -0
- package/dist/runner/learning-loop.js +19 -4
- package/dist/runner/loop.d.ts +18 -0
- package/dist/runner/loop.js +34 -0
- package/dist/runner/main.d.ts +6 -1
- package/dist/runner/main.js +26 -4
- package/dist/runner/mcp-run.d.ts +4 -1
- package/dist/runner/mcp-run.js +11 -5
- package/dist/runner/meta-tools.d.ts +10 -3
- package/dist/runner/meta-tools.js +112 -36
- package/dist/runner/metrics.d.ts +80 -21
- package/dist/runner/metrics.js +114 -39
- package/dist/runner/model-route.d.ts +14 -3
- package/dist/runner/model-route.js +155 -19
- package/dist/runner/monid-run.d.ts +8 -6
- package/dist/runner/monid-run.js +117 -43
- package/dist/runner/native-loop.d.ts +11 -0
- package/dist/runner/native-loop.js +438 -0
- package/dist/runner/promotion.d.ts +76 -10
- package/dist/runner/promotion.js +476 -154
- package/dist/runner/redact.js +3 -0
- package/dist/runner/reflect-hook.js +9 -0
- package/dist/runner/runner.d.ts +7 -1
- package/dist/runner/runner.js +8 -4
- package/dist/runner/sdk-loop.d.ts +7 -0
- package/dist/runner/sdk-loop.js +470 -0
- package/dist/runner/spec-holds.d.ts +16 -2
- package/dist/runner/spec-holds.js +42 -14
- package/dist/runner/store-secrets.js +17 -2
- package/dist/runner/workflow-first.d.ts +30 -20
- package/dist/runner/workflow-first.js +22 -32
- package/dist/runner/workflow-loop.d.ts +1 -1
- package/dist/runner/workflow-loop.js +18 -12
- package/dist/runner/workflow-spec.d.ts +4 -1
- package/dist/runner/workflow-spec.js +56 -45
- package/dist/runs-over-store.d.ts +30 -2
- package/dist/runs-over-store.js +46 -14
- package/dist/sdk/runs.d.ts +115 -0
- package/dist/sdk/runs.js +422 -0
- package/dist/sdk/schema.d.ts +175 -0
- package/dist/sdk/schema.js +138 -0
- package/dist/sdk/workflows.d.ts +22 -0
- package/dist/sdk/workflows.js +39 -0
- package/dist/secrets.d.ts +2 -0
- package/dist/secrets.js +19 -1
- package/dist/server.d.ts +48 -32
- package/dist/server.js +568 -137
- package/dist/skill-route.d.ts +3 -0
- package/dist/skill-route.js +16 -0
- package/dist/skills/agentrun-serve/SKILL.md +368 -0
- package/dist/stats.d.ts +10 -10
- package/dist/store/agent-body.d.ts +12 -8
- package/dist/store/agent-body.js +9 -4
- package/dist/store/dialect.d.ts +3 -0
- package/dist/store/dialect.js +1 -0
- package/dist/store/index.d.ts +1 -1
- package/dist/store/native-command-owner.d.ts +10 -0
- package/dist/store/native-command-owner.js +47 -0
- package/dist/store/postgres/connection.d.ts +11 -5
- package/dist/store/postgres/connection.js +44 -17
- package/dist/store/postgres/dialect.js +5 -0
- package/dist/store/postgres/migrations/0012_revision_monid_pin.sql +4 -0
- package/dist/store/postgres/migrations/0013_native_command_owner.sql +6 -0
- package/dist/store/postgres/migrations/0014_run_cost_upper_bound.sql +6 -0
- package/dist/store/postgres/store.d.ts +7 -3
- package/dist/store/postgres/store.js +4 -0
- package/dist/store/schema.d.ts +7 -0
- package/dist/store/schema.js +20 -1
- package/dist/store/sqlite/connection.js +72 -8
- package/dist/store/sqlite/run-launch.d.ts +11 -0
- package/dist/store/sqlite/run-launch.js +8 -0
- package/dist/store/sqlite/run-patch.d.ts +8 -1
- package/dist/store/sqlite/run-patch.js +14 -3
- package/dist/store/sqlite/store.js +170 -34
- package/dist/store/sqlite/worker.d.ts +2 -0
- package/dist/store/sqlite/worker.js +13 -10
- package/dist/store/store.d.ts +67 -7
- package/dist/store-reads/analytics.d.ts +7 -7
- package/dist/store-reads/analytics.js +23 -5
- package/dist/store-reads/cap.js +8 -6
- package/dist/store-reads/journal.d.ts +5 -0
- package/dist/store-reads/journal.js +85 -41
- package/dist/store-reads/learning.d.ts +115 -18
- package/dist/store-reads/learning.js +170 -68
- package/dist/store-reads/runs.d.ts +5 -0
- package/dist/store-reads/runs.js +3 -2
- package/dist/store-view.js +75 -21
- package/dist/template-eval.d.ts +73 -11
- package/dist/template-eval.js +535 -75
- package/dist/templates.d.ts +84 -21
- package/dist/templates.js +254 -47
- package/dist/text-urls.d.ts +38 -0
- package/dist/text-urls.js +170 -0
- package/dist/timeline/index.d.ts +3 -2
- package/dist/timeline/index.js +3 -2
- package/dist/timeline/labels.d.ts +5 -2
- package/dist/timeline/labels.js +29 -6
- package/dist/timeline/origin.d.ts +1 -1
- package/dist/timeline/origin.js +2 -2
- package/dist/timeline/render-text.js +1 -1
- package/dist/timeline/timeline.d.ts +66 -4
- package/dist/timeline/timeline.js +160 -30
- package/dist/timeline/util.d.ts +5 -0
- package/dist/timeline/util.js +44 -8
- package/dist/timeline/web-calls.d.ts +17 -0
- package/dist/timeline/web-calls.js +106 -0
- package/dist/tool-gate.d.ts +46 -44
- package/dist/tool-gate.js +101 -92
- package/dist/tool-list.d.ts +4 -1
- package/dist/tool-list.js +8 -1
- package/dist/tool-names.d.ts +18 -13
- package/dist/tool-names.js +19 -17
- package/dist/tool-plane.d.ts +17 -13
- package/dist/tool-plane.js +12 -5
- package/dist/tools.d.ts +57 -16
- package/dist/tools.js +33 -28
- package/dist/trigger-adapter.d.ts +56 -5
- package/dist/trigger-adapter.js +6 -0
- package/dist/trigger-adapters.js +3 -1
- package/dist/trigger-composio.d.ts +10 -0
- package/dist/trigger-composio.js +122 -0
- package/dist/trigger-email.d.ts +4 -0
- package/dist/trigger-email.js +181 -0
- package/dist/trigger-signatures.d.ts +6 -10
- package/dist/trigger-signatures.js +16 -16
- package/dist/trigger-targets.d.ts +1 -1
- package/dist/trigger-targets.js +4 -3
- package/dist/trigger-webhook.js +6 -4
- package/dist/triggers.d.ts +105 -8
- package/dist/triggers.js +286 -62
- package/dist/uploads.d.ts +9 -0
- package/dist/uploads.js +27 -0
- package/dist/validate.js +1 -7
- package/dist/web-fake.d.ts +56 -0
- package/dist/web-fake.js +102 -0
- package/dist/web-fetch-direct.d.ts +3 -0
- package/dist/web-fetch-direct.js +4 -1
- package/dist/web-fetch.d.ts +5 -1
- package/dist/web-fetch.js +8 -31
- package/dist/web-search.d.ts +51 -2
- package/dist/web-search.js +116 -18
- package/dist/webhooks.d.ts +2 -1
- package/dist/webhooks.js +5 -1
- package/dist/workflow/decision-recovery.js +5 -2
- package/dist/workflow/decisions.d.ts +7 -0
- package/dist/workflow/node-runner.js +10 -2
- package/dist/workspace/archil-claim.d.ts +3 -0
- package/dist/workspace/archil-claim.js +9 -2
- package/dist/workspace/computer-deps.d.ts +22 -9
- package/dist/workspace/computer-deps.js +78 -37
- package/dist/workspace/computer-for-claim.d.ts +54 -4
- package/dist/workspace/computer-for-claim.js +179 -39
- package/dist/workspace/computer-janitor.d.ts +10 -3
- package/dist/workspace/computer-janitor.js +96 -29
- package/dist/workspace/computer-kept.d.ts +82 -0
- package/dist/workspace/computer-kept.js +147 -0
- package/dist/workspace/computer-mcp.js +4 -3
- package/dist/workspace/computer-ports.d.ts +23 -3
- package/dist/workspace/computer-ports.js +115 -5
- package/dist/workspace/index.d.ts +1 -2
- package/dist/workspace/index.js +1 -2
- package/dist/workspace/kind-skills/desktop/SKILL.md +25 -18
- package/dist/workspace/kind-skills/phone/SKILL.md +28 -17
- package/dist/workspace/resolve-computer.d.ts +15 -3
- package/dist/workspace/resolve-computer.js +10 -7
- package/dist/workspace/revision-skills.d.ts +6 -2
- package/dist/workspace/revision-skills.js +12 -5
- package/dist/workspace/run-end-computers.d.ts +30 -0
- package/dist/workspace/run-end-computers.js +137 -0
- package/dist/workspace/run-tools.d.ts +28 -29
- package/dist/workspace/run-tools.js +29 -30
- package/dist/wrap-up.d.ts +19 -5
- package/dist/wrap-up.js +31 -4
- package/package.json +13 -9
- package/skills/agentrun-serve/SKILL.md +248 -10
- package/templates/README.md +117 -23
- package/templates/TOOLS.md +168 -0
- package/templates/code-review/agent.md +18 -4
- package/templates/code-review/evals/mentions-defused/case.yaml +1 -1
- package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +2 -1
- package/templates/code-review/evals/other-repo/case.yaml +1 -1
- package/templates/code-review/evals/pasted-by-reference/case.yaml +5 -0
- package/templates/code-review/evals/pasted-by-reference/graders/by-reference.md +15 -0
- package/templates/code-review/evals/pasted-by-reference/graders/head-sha.md +6 -0
- package/templates/code-review/evals/pasted-by-reference/prompt.md +31 -0
- package/templates/code-review/skills/review/DEEP.md +2 -2
- package/templates/code-review/skills/review/REVIEWER.md +2 -2
- package/templates/code-review/skills/review/SKILL.md +7 -3
- package/templates/release-notes/evals/draft-not-publish/case.yaml +1 -1
- package/templates/release-notes/evals/issue-write-refused/case.yaml +1 -1
- package/templates/release-notes/evals/late-arrival/case.yaml +1 -1
- package/templates/release-notes/evals/other-repo/case.yaml +1 -1
- package/dist/console/assets/index-CjqQirbo.css +0 -1
- package/dist/console/assets/index-b6-XY5A9.js +0 -576
- package/dist/host-calls.d.ts +0 -20
- package/dist/host-calls.js +0 -12
- package/dist/runner/adapters/pi-computer.d.ts +0 -9
- package/dist/runner/adapters/pi-computer.js +0 -51
- package/dist/workspace/computer-script.d.ts +0 -53
- package/dist/workspace/computer-script.js +0 -172
package/dist/uploads.js
CHANGED
|
@@ -18,6 +18,11 @@ export const MAX_UPLOAD_BYTES = 50 * 2 ** 20;
|
|
|
18
18
|
export const MAX_FILES_PER_RUN = 20;
|
|
19
19
|
/** Where a run finds its files: `work/inputs/<path>`, each file's `path` with its folders. */
|
|
20
20
|
export const INPUTS_DIR = "inputs";
|
|
21
|
+
/** The run's opening message as a file of its inputs/ (`inputs/message.md`): the start's text `content` byte for byte,
|
|
22
|
+
* so a long one (a pasted diff) is read by its path and named to a subagent, never copied into a call. The name is the
|
|
23
|
+
* message's alone: an upload at that path takes the next free one (`message-2.md`), with a message or without, and a
|
|
24
|
+
* run with no text message has no such file. */
|
|
25
|
+
export const MESSAGE_FILE = "message.md";
|
|
21
26
|
/** The data directory's folder of uploads. */
|
|
22
27
|
export const UPLOADS_DIR = "files";
|
|
23
28
|
const RECORD = "file.json";
|
|
@@ -435,6 +440,10 @@ export class Uploads {
|
|
|
435
440
|
const workspace = workspaceAt(work);
|
|
436
441
|
await uploadTestHooks.beforeCopy?.(workspace);
|
|
437
442
|
const names = takenNames(workspace);
|
|
443
|
+
// inputs/message.md is the run's message's (MESSAGE_FILE), never an upload's.
|
|
444
|
+
const top = await names(INPUTS_DIR);
|
|
445
|
+
if (!top.has(MESSAGE_FILE))
|
|
446
|
+
top.set(MESSAGE_FILE, "file");
|
|
438
447
|
for (const file of files) {
|
|
439
448
|
const segments = file.path.split("/");
|
|
440
449
|
let dir = INPUTS_DIR;
|
|
@@ -494,6 +503,24 @@ export class Uploads {
|
|
|
494
503
|
}
|
|
495
504
|
/** The words a run fails in when its files cannot be copied into its workspace at its claim. */
|
|
496
505
|
export const notCopied = (why) => `The run's files could not be copied into its workspace: ${why}`;
|
|
506
|
+
/** At a run's claim: its opening message (`message`, the start's text content) saved as inputs/message.md
|
|
507
|
+
* (MESSAGE_FILE) when it has one and the file is not there yet, then its uploaded files (`ids`) copied in as
|
|
508
|
+
* copyRunFiles copies them. Neither, and nothing is written. */
|
|
509
|
+
export async function placeRunInputs(data, runId, workspace, ids, message) {
|
|
510
|
+
if (ids.length)
|
|
511
|
+
await copyRunFiles(data, runId, workspace, ids);
|
|
512
|
+
if (!message)
|
|
513
|
+
return;
|
|
514
|
+
const there = await workspace.list(INPUTS_DIR).then((entries) => entries.some((entry) => entry.name === MESSAGE_FILE), () => false);
|
|
515
|
+
if (there)
|
|
516
|
+
return;
|
|
517
|
+
try {
|
|
518
|
+
await workspace.write(`${INPUTS_DIR}/${MESSAGE_FILE}`, Buffer.from(message, "utf8"));
|
|
519
|
+
}
|
|
520
|
+
catch (error) {
|
|
521
|
+
throw new Error(`The run's message could not be saved in its workspace as ${INPUTS_DIR}/${MESSAGE_FILE}: ${error.message}`, { cause: error });
|
|
522
|
+
}
|
|
523
|
+
}
|
|
497
524
|
/** At a run's claim: its uploaded files (`ids`, the launch's file_ids) copied into its work/inputs/ once, from its hold
|
|
498
525
|
* (Uploads.hold), and the hold let go. A resumed claim finds inputs/ there and copies nothing, so the copy's suffixes
|
|
499
526
|
* never duplicate a file across claims. A copy that fails throws in notCopied's words: the run ends failed, saying why. */
|
package/dist/validate.js
CHANGED
|
@@ -6,7 +6,6 @@ import { likelyModel, modelShape } from "./model-form.js";
|
|
|
6
6
|
import { placeIssues } from "./place.js";
|
|
7
7
|
import { computerIssues, settingConflict } from "./computer-setting.js";
|
|
8
8
|
import { settingsIssues } from "./tool-plane.js";
|
|
9
|
-
import { CAP_MODES } from "./cap.js";
|
|
10
9
|
import { APPROVALS } from "./approvals.js";
|
|
11
10
|
import { schemaCheck } from "./answer-json.js";
|
|
12
11
|
export const ID = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
@@ -18,7 +17,7 @@ export const isObject = (value) => typeof value === "object" && value !== null &
|
|
|
18
17
|
/** How long an Idempotency-Key answers with its first answer (capabilities' limits.idempotency_ttl_s). */
|
|
19
18
|
export const IDEMPOTENCY_TTL_S = 86_400;
|
|
20
19
|
export const stable = (value) => Array.isArray(value) ? `[${value.map(stable).join(",")}]` : isObject(value) ? `{${Object.keys(value).sort().map((k) => `${JSON.stringify(k)}:${stable(value[k])}`).join(",")}}` : JSON.stringify(value);
|
|
21
|
-
export const DEFINITION_FIELDS = ["id", "version", "name", "description", "instructions", "workflow", "model", "model_tiers", "thinking", "harness", "place", "computer", "learning", "skills", "tools", "tool_settings", "approvals", "max_cost_usd", "
|
|
20
|
+
export const DEFINITION_FIELDS = ["id", "version", "name", "description", "instructions", "workflow", "model", "model_tiers", "thinking", "harness", "place", "computer", "learning", "skills", "tools", "tool_settings", "approvals", "max_cost_usd", "input_schema", "output_schema", "checkout", "native", "sdk"];
|
|
22
21
|
/** What an agentic definition may ask the server to check out in each run's folder before its first turn
|
|
23
22
|
* (runner/pr-checkout.ts): `pull_request`, the pull request the run's GitHub event names, at its head, read-only, in
|
|
24
23
|
* `repo/`; `none` clears it on an edit. */
|
|
@@ -173,11 +172,6 @@ export function definitionIssues(definition, { at = "definition", creating = tru
|
|
|
173
172
|
else if (!CHECKOUTS.includes(d.checkout))
|
|
174
173
|
out.push(issue(`${at}.checkout`, "not_an_option", `${at}.checkout is one of ${CHECKOUTS.join(", ")}: pull_request checks out the pull request the run's GitHub event names, at its head, in repo/ before the first turn; none clears it`));
|
|
175
174
|
}
|
|
176
|
-
// How a run's cap prices its requests (cap.ts CapMode): kept, as the default cap is, by an edit that leaves it out.
|
|
177
|
-
if (d.cap_mode !== undefined) {
|
|
178
|
-
if (!CAP_MODES.includes(d.cap_mode))
|
|
179
|
-
out.push(issue(`${at}.cap_mode`, "not_an_option", `${at}.cap_mode is one of ${CAP_MODES.join(", ")}: expected prices a request's input from the previous request's cache, strict prices all of it uncached`));
|
|
180
|
-
}
|
|
181
175
|
return out;
|
|
182
176
|
}
|
|
183
177
|
/** The skill files a body names: an object of relative paths inside `.agents/skills/` to text. */
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { type Page, type Part } from "./web-fetch-direct.js";
|
|
2
|
+
import { type WebPage } from "./web-fetch.js";
|
|
3
|
+
import { type Hit, type Search } from "./web-search.js";
|
|
4
|
+
import type { Plane } from "./tool-plane.js";
|
|
5
|
+
export type SearchAnswer = {
|
|
6
|
+
query: string;
|
|
7
|
+
results: Hit[];
|
|
8
|
+
} | {
|
|
9
|
+
query: string;
|
|
10
|
+
error: string;
|
|
11
|
+
};
|
|
12
|
+
export type FetchAnswer = {
|
|
13
|
+
url: string;
|
|
14
|
+
status?: number;
|
|
15
|
+
title?: string;
|
|
16
|
+
text: string;
|
|
17
|
+
} | {
|
|
18
|
+
url: string;
|
|
19
|
+
error: string;
|
|
20
|
+
};
|
|
21
|
+
export type WebFixture = {
|
|
22
|
+
search: {
|
|
23
|
+
answers: SearchAnswer[];
|
|
24
|
+
default: {
|
|
25
|
+
results: Hit[];
|
|
26
|
+
} | {
|
|
27
|
+
error: string;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
fetch: {
|
|
31
|
+
answers: FetchAnswer[];
|
|
32
|
+
default: {
|
|
33
|
+
status?: number;
|
|
34
|
+
title?: string;
|
|
35
|
+
text: string;
|
|
36
|
+
} | {
|
|
37
|
+
error: string;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
/** A case's web fake: every web call failing, or a fixture. */
|
|
42
|
+
export type WebFake = "unavailable" | WebFixture;
|
|
43
|
+
/** `value` checked as a web fixture: the fixture, else each problem said through `bad`, `at` naming the file. */
|
|
44
|
+
export declare function webFixtureOf(value: unknown, at: string, bad: (message: string) => void): WebFixture | undefined;
|
|
45
|
+
/** `args` searched in `fake`, as the run's web_search answers: `provider`, the one the run's plane names. */
|
|
46
|
+
export declare function fakeSearch(fake: WebFake, args: Record<string, unknown>, provider: Exclude<Search, {
|
|
47
|
+
error: string;
|
|
48
|
+
}>["provider"]): Search;
|
|
49
|
+
/** The part `part` names of the page at `url` in `fake`, as the run's web_fetch answers, through the guarded direct
|
|
50
|
+
* fetch's own path with the fake standing in for the network. */
|
|
51
|
+
export declare function fakeFetch(fake: WebFake, url: unknown, part?: Part & {
|
|
52
|
+
signal?: AbortSignal;
|
|
53
|
+
}): Promise<WebPage | Page>;
|
|
54
|
+
/** A faked run's plane: web_search never a harness's own search (Claude's or Codex's, which would answer in its stead), so
|
|
55
|
+
* the run's own web_search tool, the one the fake answers through, is the one its harness offers. */
|
|
56
|
+
export declare function fakedPlane(plane: Plane | undefined): Plane | undefined;
|
package/dist/web-fake.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// A template eval's fake of the web tools for one case (template-eval.ts, `web:` in a case's case.yaml): its runs'
|
|
2
|
+
// web_search and web_fetch answer from the case, never from the network, in the shapes and through the tool names the
|
|
3
|
+
// model sees live. `unavailable`: every search fails as keyless search past its free limit does (exa-keyless.ts
|
|
4
|
+
// RATE_LIMITED), and every page fails as a fetch whose connection is refused does (the guarded direct fetch's own words,
|
|
5
|
+
// web-fetch-direct.ts readDirect). A fixture: each search answered by the first answer whose `query` (a regular
|
|
6
|
+
// expression, case-insensitive) matches the query, else its default; each page by the answer for exactly its URL, else
|
|
7
|
+
// its default, read through the guarded direct fetch's own path (its URL, port and status checks, its parts).
|
|
8
|
+
//
|
|
9
|
+
// Only the eval's own in-process runner binds it (runner/beside.ts `evalFakes`, by the agent the eval made for the run):
|
|
10
|
+
// no package field, API field, setting or environment variable reaches it, so no other server's runs ever see a fake.
|
|
11
|
+
import { RATE_LIMITED } from "./exa-keyless.js";
|
|
12
|
+
import { clip, partProblem, TITLE_CAP, URL_MAX } from "./web-fetch-direct.js";
|
|
13
|
+
import { webFetch } from "./web-fetch.js";
|
|
14
|
+
import { searchArgs, snippetOf } from "./web-search.js";
|
|
15
|
+
/** A public address the fake's lookup answers: the guard checks it is public, and no connection is ever made to it. */
|
|
16
|
+
const PUBLIC_ADDRESS = "203.0.114.1";
|
|
17
|
+
/** The statuses whose answer carries no body (a Response refuses one). */
|
|
18
|
+
const NULL_BODY = new Set([204, 205, 304]);
|
|
19
|
+
const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
20
|
+
const isText = (value) => typeof value === "string";
|
|
21
|
+
/** `value` checked as a web fixture: the fixture, else each problem said through `bad`, `at` naming the file. */
|
|
22
|
+
export function webFixtureOf(value, at, bad) {
|
|
23
|
+
const problems = [];
|
|
24
|
+
const say = (message) => void problems.push(`${at}: ${message}`);
|
|
25
|
+
if (!isObject(value) || !isObject(value.search) || !isObject(value.fetch)) {
|
|
26
|
+
bad(`${at}: a web fixture is {search: {answers, default}, fetch: {answers, default}}`);
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
const hitOk = (hit) => isObject(hit) && isText(hit.url) && URL.canParse(hit.url) && isText(hit.title) && isText(hit.snippet) && (hit.published === undefined || isText(hit.published));
|
|
30
|
+
const searchOk = (answer, keyed) => isObject(answer) && (!keyed || isText(answer.query)) && (Array.isArray(answer.results) ? answer.results.every(hitOk) && answer.error === undefined : isText(answer.error));
|
|
31
|
+
const pageOk = (answer, keyed) => isObject(answer) && (!keyed || (isText(answer.url) && URL.canParse(answer.url))) && (isText(answer.text) ? answer.error === undefined && (answer.title === undefined || isText(answer.title)) && (answer.status === undefined || (Number.isInteger(answer.status) && answer.status >= 200 && answer.status <= 599)) : isText(answer.error));
|
|
32
|
+
const search = value.search;
|
|
33
|
+
const fetch = value.fetch;
|
|
34
|
+
if (!Array.isArray(search.answers))
|
|
35
|
+
say("search.answers is a list of {query, results} or {query, error}");
|
|
36
|
+
else
|
|
37
|
+
search.answers.forEach((answer, i) => {
|
|
38
|
+
if (!searchOk(answer, true))
|
|
39
|
+
return void say(`search.answers.${i} is {query, results} or {query, error}, each result {url, title, snippet, published?}`);
|
|
40
|
+
try {
|
|
41
|
+
new RegExp(answer.query, "i");
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
say(`search.answers.${i}.query does not compile as a regular expression`);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
if (!searchOk(search.default, false))
|
|
48
|
+
say("search.default is {results} or {error}, each result {url, title, snippet, published?}");
|
|
49
|
+
if (!Array.isArray(fetch.answers))
|
|
50
|
+
say("fetch.answers is a list of {url, status?, title?, text} or {url, error}");
|
|
51
|
+
else
|
|
52
|
+
fetch.answers.forEach((answer, i) => {
|
|
53
|
+
if (!pageOk(answer, true))
|
|
54
|
+
say(`fetch.answers.${i} is {url, status?, title?, text} or {url, error}, its url absolute and its status 200 to 599`);
|
|
55
|
+
});
|
|
56
|
+
if (!pageOk(fetch.default, false))
|
|
57
|
+
say("fetch.default is {status?, title?, text} or {error}");
|
|
58
|
+
for (const problem of problems)
|
|
59
|
+
bad(problem);
|
|
60
|
+
return problems.length ? undefined : value;
|
|
61
|
+
}
|
|
62
|
+
/** `args` searched in `fake`, as the run's web_search answers: `provider`, the one the run's plane names. */
|
|
63
|
+
export function fakeSearch(fake, args, provider) {
|
|
64
|
+
const { query, n } = searchArgs(args);
|
|
65
|
+
if (!query)
|
|
66
|
+
return { error: "web_search needs a query" };
|
|
67
|
+
if (fake === "unavailable")
|
|
68
|
+
return { error: RATE_LIMITED };
|
|
69
|
+
const answer = fake.search.answers.find((one) => new RegExp(one.query, "i").test(query)) ?? fake.search.default;
|
|
70
|
+
if ("error" in answer)
|
|
71
|
+
return { error: answer.error };
|
|
72
|
+
const results = answer.results.slice(0, n).map((hit) => ({ url: hit.url, title: clip(hit.title, TITLE_CAP), snippet: snippetOf(hit.snippet), ...(hit.published === undefined ? {} : { published: hit.published }) }));
|
|
73
|
+
return { provider, query, results };
|
|
74
|
+
}
|
|
75
|
+
/** The part `part` names of the page at `url` in `fake`, as the run's web_fetch answers, through the guarded direct
|
|
76
|
+
* fetch's own path with the fake standing in for the network. */
|
|
77
|
+
export async function fakeFetch(fake, url, part = {}) {
|
|
78
|
+
const problem = partProblem(part);
|
|
79
|
+
if (problem)
|
|
80
|
+
return { ok: false, url: typeof url === "string" ? clip(url, URL_MAX) : "", status: 0, title: "", text: "", links: [], error: problem };
|
|
81
|
+
const answer = fake === "unavailable" ? undefined : (fake.fetch.answers.find((one) => one.url === url) ?? fake.fetch.default);
|
|
82
|
+
const page = await webFetch(url, {
|
|
83
|
+
...part,
|
|
84
|
+
lookup: async () => [PUBLIC_ADDRESS],
|
|
85
|
+
fetchImpl: async () => {
|
|
86
|
+
// As undici's fetch rejects when a connection is refused: the guarded fetch says it in its own words.
|
|
87
|
+
if (answer === undefined)
|
|
88
|
+
throw new TypeError("fetch failed", { cause: Object.assign(new Error("connect ECONNREFUSED"), { code: "ECONNREFUSED" }) });
|
|
89
|
+
if ("error" in answer)
|
|
90
|
+
throw new TypeError(answer.error);
|
|
91
|
+
const status = answer.status ?? 200;
|
|
92
|
+
return new Response(NULL_BODY.has(status) ? null : answer.text, { status, headers: { "content-type": "text/plain; charset=utf-8" } });
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
// A page served as text has no title of its own: the fixture's.
|
|
96
|
+
return page.ok && answer && !("error" in answer) && answer.title ? { ...page, title: clip(answer.title, TITLE_CAP) } : page;
|
|
97
|
+
}
|
|
98
|
+
/** A faked run's plane: web_search never a harness's own search (Claude's or Codex's, which would answer in its stead), so
|
|
99
|
+
* the run's own web_search tool, the one the fake answers through, is the one its harness offers. */
|
|
100
|
+
export function fakedPlane(plane) {
|
|
101
|
+
return plane?.web_search === "native" ? { ...plane, web_search: "exa-keyless" } : plane;
|
|
102
|
+
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import type { TSchema } from "typebox";
|
|
2
2
|
import type { PublicFetchOptions } from "@parcha/pi-browser";
|
|
3
|
+
import { linksOf } from "./text-urls.js";
|
|
4
|
+
/** A page's text read for its links (text-urls.ts): web_fetch's Parallel read takes it from here. */
|
|
5
|
+
export { linksOf };
|
|
3
6
|
/** On a page that was read, `chars`: the length of `text`, the part of the page's text this answer holds. `truncated`
|
|
4
7
|
* while more of it follows this part, and `next_offset` where that begins; `offset` where this part begins, when not 0;
|
|
5
8
|
* `original_chars` the whole text's length in characters, when it is known and this part is not all of it;
|
package/dist/web-fetch-direct.js
CHANGED
|
@@ -12,6 +12,9 @@
|
|
|
12
12
|
// Every field of a Page is held to a cap (its text, its title, its URL, its links), so one answer is too: serve's
|
|
13
13
|
// host-bounds test holds it to the host's result bound.
|
|
14
14
|
import { pathToFileURL } from "node:url";
|
|
15
|
+
import { linksOf } from "./text-urls.js";
|
|
16
|
+
/** A page's text read for its links (text-urls.ts): web_fetch's Parallel read takes it from here. */
|
|
17
|
+
export { linksOf };
|
|
15
18
|
/** Under `--faux` only: a module whose default export gives `{ lookup, fetchImpl }` for the fetch (the tests' fake
|
|
16
19
|
* network), in place of the system's resolver and undici. */
|
|
17
20
|
export const FAUX_WEB_ENV = "AGENTRUN_SERVE_FAUX_WEB";
|
|
@@ -146,7 +149,7 @@ export async function readDirect(url, options = {}) {
|
|
|
146
149
|
return failed({ url: clip(answer.url, URL_MAX), status: answer.status, error: `the page answered ${answer.status}` });
|
|
147
150
|
// The caller's stop reaches the read too; the timeout is the network's, and readPage keeps its own deadline.
|
|
148
151
|
const read = /html/i.test(answer.contentType) ? await readPage(answer.body, answer.url, options.signal ? { signal: options.signal } : {}) : null;
|
|
149
|
-
const page = read ?? { title: "", text: answer.body, links:
|
|
152
|
+
const page = read ?? { title: "", text: answer.body, links: linksOf(answer.body) };
|
|
150
153
|
return { ok: true, url: clip(answer.url, URL_MAX), status: answer.status, title: clip(page.title, TITLE_CAP), ...textOf(page.text, !read?.truncated), ...(read?.truncated ? { html_chars: read.html_chars } : {}), ...(read?.converted === "text" ? { converted: "text" } : {}), ...linksWithin(page.links) };
|
|
151
154
|
}
|
|
152
155
|
catch (error) {
|
package/dist/web-fetch.d.ts
CHANGED
|
@@ -62,5 +62,9 @@ export declare function webFetchText(page: WebPage | Page, name?: string): strin
|
|
|
62
62
|
/** The agent's tool: the WebPage as JSON text (webFetchText), named `name`. A
|
|
63
63
|
* run whose web_fetch resolves to Parallel reads its key as the tool is made, when the run opens. */
|
|
64
64
|
/** Typed here, so its declaration names the schema type by a package serve declares (pi-ai), whatever else the build loads. */
|
|
65
|
-
|
|
65
|
+
/** `fake`: what reads each page in the provider's place (a template eval's web fake, web-fake.ts), the tool otherwise
|
|
66
|
+
* the same. */
|
|
67
|
+
export declare function webFetchTool(env: NodeJS.ProcessEnv, name?: string, fake?: (url: unknown, part: Part & {
|
|
68
|
+
signal?: AbortSignal;
|
|
69
|
+
}) => Promise<WebPage | Page>): ToolRegistration<TSchema, JsonValue>;
|
|
66
70
|
export {};
|
package/dist/web-fetch.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineTool } from "@earendil-works/pi-durable";
|
|
2
2
|
import { FAUX_PARALLEL_ENV, fauxFetch, parallelKeyOf } from "./decisions.js";
|
|
3
|
-
import { clip, fetchOptions, HTML_READ_CHARS, linksWithin, MAX_CHARS_MIN, PAGE_CHARS, PAGE_READ_MAX_CHARS, partOfRead, partProblem, readDirect, TEXT_CAP, TIMEOUT_MS, TITLE_CAP, textOf, URL_MAX, URL_PARAMETERS } from "./web-fetch-direct.js";
|
|
3
|
+
import { clip, fetchOptions, HTML_READ_CHARS, linksOf, linksWithin, MAX_CHARS_MIN, PAGE_CHARS, PAGE_READ_MAX_CHARS, partOfRead, partProblem, readDirect, TEXT_CAP, TIMEOUT_MS, TITLE_CAP, textOf, URL_MAX, URL_PARAMETERS } from "./web-fetch-direct.js";
|
|
4
4
|
import { FAUX_ENV } from "./model.js";
|
|
5
5
|
import { PaidRefused, paidRequest, parallelFeeOf } from "./paid-calls.js";
|
|
6
6
|
import { forModel } from "./result.js";
|
|
@@ -11,32 +11,6 @@ const PARALLEL_TIMEOUT_MS = 60_000;
|
|
|
11
11
|
const PORTS = new Set(["", "80", "443"]);
|
|
12
12
|
/** How many pages a run keeps what it read of (Pages): each at most PAGE_READ_MAX_CHARS characters of text. */
|
|
13
13
|
export const PAGES_HELD = 8;
|
|
14
|
-
/** The absolute http(s) URLs a markdown text links to (`[text](url)`), each once and without its fragment, in order, as
|
|
15
|
-
* they are read (linksWithin keeps those within the caps and counts the rest). A URL ends at whitespace or at the ")"
|
|
16
|
-
* that closes the link, so parentheses it holds in pairs (a wiki title's) stay. */
|
|
17
|
-
function* linksOf(markdown) {
|
|
18
|
-
const seen = new Set();
|
|
19
|
-
// The next "](" is looked for from where this one's URL ended, so no character is scanned twice: one pass, however
|
|
20
|
-
// many unclosed "](" a hostile page holds.
|
|
21
|
-
for (let at = markdown.indexOf("]("), end = 0; at !== -1; at = markdown.indexOf("](", Math.max(at + 2, end))) {
|
|
22
|
-
end = at + 2;
|
|
23
|
-
for (let depth = 0; end < markdown.length && !/\s/.test(markdown[end]); end++) {
|
|
24
|
-
if (markdown[end] === "(")
|
|
25
|
-
depth++;
|
|
26
|
-
else if (markdown[end] === ")" && depth-- === 0)
|
|
27
|
-
break;
|
|
28
|
-
}
|
|
29
|
-
const href = markdown.slice(at + 2, end);
|
|
30
|
-
const link = /^https?:\/\//i.test(href) ? URL.parse(href) : null;
|
|
31
|
-
if (!link)
|
|
32
|
-
continue;
|
|
33
|
-
link.hash = "";
|
|
34
|
-
if (seen.has(link.href))
|
|
35
|
-
continue;
|
|
36
|
-
seen.add(link.href);
|
|
37
|
-
yield link.href;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
14
|
/** Parallel's extract on `apiKey`: one URL a request, each a billed extract, its full content to the most of a page
|
|
41
15
|
* web_fetch reads as the page's text (markdown), its links read from it, status 200 (Parallel answers a page it could
|
|
42
16
|
* not read in `errors`, with no content). */
|
|
@@ -260,17 +234,20 @@ export function webFetchText(page, name = WEB_FETCH_TOOL) {
|
|
|
260
234
|
/** The agent's tool: the WebPage as JSON text (webFetchText), named `name`. A
|
|
261
235
|
* run whose web_fetch resolves to Parallel reads its key as the tool is made, when the run opens. */
|
|
262
236
|
/** Typed here, so its declaration names the schema type by a package serve declares (pi-ai), whatever else the build loads. */
|
|
263
|
-
|
|
264
|
-
|
|
237
|
+
/** `fake`: what reads each page in the provider's place (a template eval's web fake, web-fake.ts), the tool otherwise
|
|
238
|
+
* the same. */
|
|
239
|
+
export function webFetchTool(env, name = WEB_FETCH_TOOL, fake) {
|
|
240
|
+
if (planeOf(env).web_fetch === "parallel" && !fake)
|
|
265
241
|
parallelOf(env);
|
|
266
242
|
return defineTool({
|
|
267
243
|
name,
|
|
268
|
-
description: `Read one web page from a public host, a part at a time. It has no cookies, sign-ins or session: it reads one page cold, so a page behind a sign-in, or one that depends on an earlier page, needs the browser tool, where this run has it. Answers JSON: ok, the final url, the HTTP status, the page's title, text (a part of its readable text as markdown: about max_chars characters from offset, ${PAGE_CHARS.toLocaleString("en-US")} by default, at least ${MAX_CHARS_MIN} and at most ${TEXT_CAP.toLocaleString("en-US")}) and chars (that part's length), the absolute links the page holds (with the part at offset 0; links_omitted counts those its caps left out), and via: parallel when Parallel's extract read it, direct when it was fetched from the host (with parallel saying why, where Parallel was picked and gave no page), stopped when the call was stopped before its page arrived. A part that is not the whole page says so: truncated is true while more follows, next_offset is where the rest begins, original_chars is the page's whole length where it is known, and a line after the JSON says which characters these are; call again with offset to read on. A page whose HTML is longer than ${HTML_READ_CHARS.toLocaleString("en-US")} characters (scripts and styles aside) is cut before it is read: html_chars gives its whole length on every part, its text is only the start of the page, and the last part's line says it was cut. converted is "text" when the text is the page's plain text, its conversion to markdown having run out of time. A page is read to its first ${PAGE_READ_MAX_CHARS.toLocaleString("en-US")} characters (beyond_read on the last part says it goes on). A page is fetched once a run, at its first call: its later parts come from that read, with no request (through Parallel, one billed extract a page). A private or local address, a port other than 80 or 443, or a scheme other than http(s) is refused and never read (ok false, with refused saying why); so is a page fetched directly that is not text.`,
|
|
244
|
+
description: `Read one web page from a public host, a part at a time. It has no cookies, sign-ins or session: it reads one page cold, so a page behind a sign-in, or one that depends on an earlier page, needs the browser tool, where this run has it. Answers JSON: ok, the final url, the HTTP status, the page's title, text (a part of its readable text as markdown: about max_chars characters from offset, ${PAGE_CHARS.toLocaleString("en-US")} by default, at least ${MAX_CHARS_MIN} and at most ${TEXT_CAP.toLocaleString("en-US")}) and chars (that part's length), the absolute links the page holds (its link targets and the URLs written out in its text, a JSON body's strings and an XML feed's links among them, where an HTML page fetched directly gives its link targets alone; with the part at offset 0; links_omitted counts those its caps left out), and via: parallel when Parallel's extract read it, direct when it was fetched from the host (with parallel saying why, where Parallel was picked and gave no page), stopped when the call was stopped before its page arrived. A part that is not the whole page says so: truncated is true while more follows, next_offset is where the rest begins, original_chars is the page's whole length where it is known, and a line after the JSON says which characters these are; call again with offset to read on. A page whose HTML is longer than ${HTML_READ_CHARS.toLocaleString("en-US")} characters (scripts and styles aside) is cut before it is read: html_chars gives its whole length on every part, its text is only the start of the page, and the last part's line says it was cut. converted is "text" when the text is the page's plain text, its conversion to markdown having run out of time. A page is read to its first ${PAGE_READ_MAX_CHARS.toLocaleString("en-US")} characters (beyond_read on the last part says it goes on). A page is fetched once a run, at its first call: its later parts come from that read, with no request (through Parallel, one billed extract a page). A private or local address, a port other than 80 or 443, or a scheme other than http(s) is refused and never read (ok false, with refused saying why); so is a page fetched directly that is not text.`,
|
|
269
245
|
parameters: URL_PARAMETERS,
|
|
270
246
|
replay: "safe",
|
|
271
247
|
execute: async (args, _api, context) => {
|
|
272
248
|
const { url, offset, max_chars } = args;
|
|
273
|
-
const
|
|
249
|
+
const signal = context?.abortSignal ? { signal: context.abortSignal } : {};
|
|
250
|
+
const page = fake ? await fake(url, { offset, maxChars: max_chars, ...signal }) : await fetchFor(env, url, { ...(await fetchOptions(env, FAUX_ENV)), offset, maxChars: max_chars, pages: pagesOf(env), ...signal });
|
|
274
251
|
return forModel(webFetchText(page, name), { details: page });
|
|
275
252
|
},
|
|
276
253
|
});
|
package/dist/web-search.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { TSchema } from "typebox";
|
|
2
2
|
import type { JsonValue } from "@earendil-works/chord/json";
|
|
3
3
|
import { type ToolRegistration } from "@earendil-works/pi-durable";
|
|
4
|
+
import { type ExaLimited } from "./exa-keyless.js";
|
|
4
5
|
import { type SearchModels } from "./hosted-search.js";
|
|
5
6
|
import { type Extract } from "./web-fetch.js";
|
|
6
7
|
export declare const WEB_SEARCH_TOOL = "web_search";
|
|
@@ -16,6 +17,11 @@ export declare const ANSWER_MAX = 4000;
|
|
|
16
17
|
/** The most characters a search's answer takes, its citing line included: about RESULTS_MAX results with whole snippets,
|
|
17
18
|
* under the host's result bound (HOST_RESULT_MAX_CHARS), which the host-bounds test holds it to. */
|
|
18
19
|
export declare const SEARCH_MAX_CHARS = 100000;
|
|
20
|
+
/** What every later web_search call of a run answers once its provider said the run is out of quota (a Limit of kind
|
|
21
|
+
* quota): the provider is not asked again in that run. */
|
|
22
|
+
export declare const SEARCH_UNAVAILABLE = "search is unavailable for the rest of this run; answer from what you have";
|
|
23
|
+
/** What a call answers while a rate limit's wait holds, `seconds` of it left. */
|
|
24
|
+
export declare const searchBusy: (seconds: number) => string;
|
|
19
25
|
export type Hit = {
|
|
20
26
|
url: string;
|
|
21
27
|
title: string;
|
|
@@ -31,6 +37,41 @@ export type Search = {
|
|
|
31
37
|
} | {
|
|
32
38
|
error: string;
|
|
33
39
|
};
|
|
40
|
+
/** What a provider's failure said of the run's search: out of quota, or rate-limited, with the wait it named as it
|
|
41
|
+
* handed it back (a Retry-After header's value, delta-seconds or an HTTP date, or Exa's seconds). `repeatIsQuota`, the
|
|
42
|
+
* server's mark on keyless Exa's limit naming no wait alone (exaLimitOf): Exa answers its daily count running out as
|
|
43
|
+
* that limit, so the same answer again once a wait has passed is that count (searchBreaker). */
|
|
44
|
+
export type Limit = {
|
|
45
|
+
kind: "quota";
|
|
46
|
+
} | {
|
|
47
|
+
kind: "rate";
|
|
48
|
+
retryAfter?: string | number;
|
|
49
|
+
repeatIsQuota?: true;
|
|
50
|
+
};
|
|
51
|
+
/** A Search, and the limit its provider answered, if any: the run's breaker reads `limit` (searchBreaker), the model the
|
|
52
|
+
* Search alone. */
|
|
53
|
+
export type Searched = {
|
|
54
|
+
answer: Search;
|
|
55
|
+
limit?: Limit;
|
|
56
|
+
};
|
|
57
|
+
/** The wait `retryAfter` names, in ms from `nowMs`: delta-seconds, an HTTP date, or Exa's seconds. None, or words that
|
|
58
|
+
* read as neither, 60 s; a date already passed, none; never more than 15 minutes (MAX_WAIT_MS). */
|
|
59
|
+
export declare function waitOf(retryAfter: string | number | undefined, nowMs: number): number;
|
|
60
|
+
/** A run's breaker on its web_search, read at `now`. `held` is what a call answers unsent while it holds: SEARCH_UNAVAILABLE
|
|
61
|
+
* for the rest of the run once a quota answer came, or searchBusy with the seconds left of a rate limit's wait (rounded
|
|
62
|
+
* up, so at least 1); else undefined, and the call asks the provider. `read` takes a search's own answer and its limit:
|
|
63
|
+
* a quota answer turns search off for good, a rate limit holds search for its wait from now, or for the wait already
|
|
64
|
+
* open when that ends later (two calls in flight: a short wait never shrinks a long one), anything else leaves it as it
|
|
65
|
+
* is. A rate limit marked repeatIsQuota (keyless Exa's, naming no wait) after an earlier marked one whose wait has
|
|
66
|
+
* passed counts as a quota answer: off for the run, and that call answers SEARCH_UNAVAILABLE in place of its own words
|
|
67
|
+
* (Exa's "try again in a minute"). A quota answer keeps the call's own answer, which names no retry. One that comes
|
|
68
|
+
* while a wait is open (in flight with the first) only holds it, and a search that succeeds in between resets the
|
|
69
|
+
* count: once Exa's daily count is spent every keyless call is limited, so a success means it is not. A failed search
|
|
70
|
+
* that is no limit resets nothing. */
|
|
71
|
+
export declare function searchBreaker(now?: () => number): {
|
|
72
|
+
held(): Search | undefined;
|
|
73
|
+
read(searched: Searched): Search;
|
|
74
|
+
};
|
|
34
75
|
/** The line that ends a search's answer to the model, as Claude Code's WebSearch ends its own. */
|
|
35
76
|
export declare const CITE = "Cite the URL of each result you rely on.";
|
|
36
77
|
/** `answer` within SEARCH_MAX_CHARS, as searchText writes it: whole when it fits, else without its least relevant results
|
|
@@ -54,6 +95,14 @@ export type SearchOn = () => Promise<SearchModels | undefined>;
|
|
|
54
95
|
/** `{query, n?}` searched by the provider the run's plane resolves web_search to, as a Search. `models`: the run's own
|
|
55
96
|
* models a native search goes through (none: a native search has no model to search on). */
|
|
56
97
|
export declare function searchFor(env: NodeJS.ProcessEnv, args: Record<string, unknown>, signal?: AbortSignal, models?: SearchOn): Promise<Search>;
|
|
98
|
+
/** Keyless Exa's refusal as the run's breaker reads it: a rate limit, with the wait it named. One naming no wait (its MCP
|
|
99
|
+
* notice, as its daily count running out answers) is marked repeatIsQuota, so a second one past a wait is that count; a
|
|
100
|
+
* 429 with Retry-After is a timed limit, unmarked. A refused connection is no limit (a 403 no wait lifts). */
|
|
101
|
+
export declare function exaLimitOf(found: ExaLimited): Limit | undefined;
|
|
57
102
|
/** The agent's tool: the Search as JSON text. A run whose web_search resolves to Parallel reads its key as the tool is
|
|
58
|
-
* made, when the run opens; one that resolves native searches through `models`, the run's own (ToolHost.search).
|
|
59
|
-
|
|
103
|
+
* made, when the run opens; one that resolves native searches through `models`, the run's own (ToolHost.search).
|
|
104
|
+
* `fake`: what answers each search in the provider's place (a template eval's web fake, web-fake.ts), the provider
|
|
105
|
+
* the run's plane names given it, the tool otherwise the same. */
|
|
106
|
+
export declare function webSearchTool(env: NodeJS.ProcessEnv, models?: SearchOn, fake?: (args: Record<string, unknown>, provider: Exclude<Search, {
|
|
107
|
+
error: string;
|
|
108
|
+
}>["provider"]) => Search): ToolRegistration<TSchema, JsonValue>;
|