@parcha/agentrun-serve 0.0.0-stage → 0.1.0-beta.29
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 +560 -0
- package/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +1723 -2
- package/dist/adapters.d.ts +205 -0
- package/dist/adapters.js +459 -0
- package/dist/agents.d.ts +124 -0
- package/dist/agents.js +302 -0
- package/dist/app.d.ts +7 -0
- package/dist/app.js +324 -0
- package/dist/bound-files.d.ts +4 -0
- package/dist/bound-files.js +164 -0
- package/dist/box/record.d.ts +6 -0
- package/dist/box/record.js +41 -0
- package/dist/box/sweep.d.ts +53 -0
- package/dist/box/sweep.js +193 -0
- package/dist/box-image.d.ts +98 -0
- package/dist/box-image.js +283 -0
- package/dist/box-relay.d.ts +42 -0
- package/dist/box-relay.js +222 -0
- package/dist/boxes.d.ts +54 -0
- package/dist/boxes.js +182 -0
- package/dist/cap.d.ts +224 -0
- package/dist/cap.js +721 -0
- package/dist/catalog.d.ts +20 -0
- package/dist/catalog.js +53 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +167 -0
- package/dist/coding-tools.d.ts +31 -0
- package/dist/coding-tools.js +81 -0
- package/dist/console/THIRD-PARTY-NOTICES.txt +1141 -0
- package/dist/console/assets/index-BN7oVcO4.js +445 -0
- package/dist/console/assets/index-By-jkqki.css +1 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-400-normal-BEIGL1Tu.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-400-normal-CIEtRijs.woff +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-600-normal-BB5xRk30.woff +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-600-normal-EVf6-Yzo.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-ext-400-normal-BHyURHCj.woff +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-ext-400-normal-C_uLvvQ5.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-ext-600-normal-Dj6eZy5f.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-ext-600-normal-DpeVePZf.woff +0 -0
- package/dist/console/assets/jetbrains-mono-greek-400-normal-C190GLew.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-greek-400-normal-CNojz0t3.woff +0 -0
- package/dist/console/assets/jetbrains-mono-greek-600-normal-3KAm9r92.woff +0 -0
- package/dist/console/assets/jetbrains-mono-greek-600-normal-H7WoG9Et.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-400-normal-B11XCQ5g.woff +0 -0
- package/dist/console/assets/jetbrains-mono-latin-400-normal-V6pRDFza.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-600-normal-C8RAYTDA.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-600-normal-DXv3JcnD.woff +0 -0
- package/dist/console/assets/jetbrains-mono-latin-ext-400-normal-Bc8Ftmh3.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-ext-400-normal-DHMOLxAi.woff +0 -0
- package/dist/console/assets/jetbrains-mono-latin-ext-600-normal-BfB_LPfz.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-ext-600-normal-DiQlUoE6.woff +0 -0
- package/dist/console/assets/jetbrains-mono-vietnamese-400-normal-BeU3T8wf.woff +0 -0
- package/dist/console/assets/jetbrains-mono-vietnamese-400-normal-ByoDsISC.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-vietnamese-600-normal-CSpzN4cI.woff +0 -0
- package/dist/console/assets/jetbrains-mono-vietnamese-600-normal-Dtizs43-.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-400-normal-Cph9ettZ.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-400-normal-DfGZKnlb.woff +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-600-normal-BGBUNdzT.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-600-normal-COje25QW.woff +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-ext-400-normal-4l4lq8zr.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-ext-400-normal-BGzXWJeR.woff +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-ext-600-normal-8_E36CQj.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-ext-600-normal-C27an7Zc.woff +0 -0
- package/dist/console/index.html +15 -0
- package/dist/daytona-api.d.ts +21 -0
- package/dist/daytona-api.js +101 -0
- package/dist/decision-rows.d.ts +11 -0
- package/dist/decision-rows.js +116 -0
- package/dist/decisions.d.ts +94 -0
- package/dist/decisions.js +184 -0
- package/dist/effort-guidance.d.ts +5 -0
- package/dist/effort-guidance.js +14 -0
- package/dist/environment.d.ts +5 -0
- package/dist/environment.js +11 -0
- package/dist/errors.d.ts +72 -0
- package/dist/errors.js +66 -0
- package/dist/exa-keyless.d.ts +35 -0
- package/dist/exa-keyless.js +202 -0
- package/dist/fetch-page.d.ts +114 -0
- package/dist/fetch-page.js +182 -0
- package/dist/files.d.ts +60 -0
- package/dist/files.js +153 -0
- package/dist/grade.d.ts +96 -0
- package/dist/grade.js +348 -0
- package/dist/graph-view.d.ts +100 -0
- package/dist/graph-view.js +212 -0
- package/dist/harness-app.d.ts +38 -0
- package/dist/harness-app.js +626 -0
- package/dist/harness.d.ts +53 -0
- package/dist/harness.js +74 -0
- package/dist/home-path.d.ts +27 -0
- package/dist/home-path.js +78 -0
- package/dist/host-tools.d.ts +20 -0
- package/dist/host-tools.js +140 -0
- package/dist/host.d.ts +39 -0
- package/dist/host.js +81 -0
- package/dist/hosted-search.d.ts +27 -0
- package/dist/hosted-search.js +129 -0
- package/dist/import-sources.d.ts +104 -0
- package/dist/import-sources.js +629 -0
- package/dist/import-summary.d.ts +25 -0
- package/dist/import-summary.js +75 -0
- package/dist/import-worker.d.ts +26 -0
- package/dist/import-worker.js +41 -0
- package/dist/import.d.ts +145 -0
- package/dist/import.js +1221 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +6 -0
- package/dist/key-check.d.ts +36 -0
- package/dist/key-check.js +108 -0
- package/dist/key-refusal.d.ts +51 -0
- package/dist/key-refusal.js +187 -0
- package/dist/learn/check.d.ts +99 -0
- package/dist/learn/check.js +259 -0
- package/dist/learn/grade.d.ts +79 -0
- package/dist/learn/grade.js +433 -0
- package/dist/learn/index.d.ts +7 -0
- package/dist/learn/index.js +11 -0
- package/dist/learn/invisible.d.ts +5 -0
- package/dist/learn/invisible.js +42 -0
- package/dist/learn/notes.d.ts +59 -0
- package/dist/learn/notes.js +146 -0
- package/dist/learn/reflect.d.ts +49 -0
- package/dist/learn/reflect.js +167 -0
- package/dist/learn/secrets.d.ts +18 -0
- package/dist/learn/secrets.js +111 -0
- package/dist/learn/skills.d.ts +84 -0
- package/dist/learn/skills.js +198 -0
- package/dist/learning-routes.d.ts +196 -0
- package/dist/learning-routes.js +609 -0
- package/dist/learning-run.d.ts +304 -0
- package/dist/learning-run.js +797 -0
- package/dist/learning-words.d.ts +73 -0
- package/dist/learning-words.js +171 -0
- package/dist/learning.d.ts +377 -0
- package/dist/learning.js +801 -0
- package/dist/llm.d.ts +40 -0
- package/dist/llm.js +37 -0
- package/dist/llms.txt +37 -0
- package/dist/mcp-servers.d.ts +115 -0
- package/dist/mcp-servers.js +445 -0
- package/dist/mcp.d.ts +51 -0
- package/dist/mcp.js +392 -0
- package/dist/model.d.ts +184 -0
- package/dist/model.js +484 -0
- package/dist/monid.d.ts +74 -0
- package/dist/monid.js +277 -0
- package/dist/openapi/agentrun-v2.openapi.json +4805 -0
- package/dist/openapi.d.ts +10 -0
- package/dist/openapi.js +1417 -0
- package/dist/owner.d.ts +55 -0
- package/dist/owner.js +222 -0
- package/dist/packs.d.ts +71 -0
- package/dist/packs.js +180 -0
- package/dist/page.d.ts +32 -0
- package/dist/page.js +133 -0
- package/dist/paid-calls.d.ts +46 -0
- package/dist/paid-calls.js +110 -0
- package/dist/pause.d.ts +68 -0
- package/dist/pause.js +97 -0
- package/dist/pdf-pages.d.ts +44 -0
- package/dist/pdf-pages.js +147 -0
- package/dist/place.d.ts +46 -0
- package/dist/place.js +105 -0
- package/dist/print.d.ts +20 -0
- package/dist/print.js +29 -0
- package/dist/propose.d.ts +38 -0
- package/dist/propose.js +82 -0
- package/dist/quiet-sqlite-warning.d.ts +1 -0
- package/dist/quiet-sqlite-warning.js +14 -0
- package/dist/request-start.d.ts +14 -0
- package/dist/request-start.js +226 -0
- package/dist/result.d.ts +3 -0
- package/dist/result.js +5 -0
- package/dist/rows.d.ts +46 -0
- package/dist/rows.js +121 -0
- package/dist/run-box.d.ts +134 -0
- package/dist/run-box.js +440 -0
- package/dist/run-manifest.d.ts +27 -0
- package/dist/run-manifest.js +60 -0
- package/dist/runnable.d.ts +80 -0
- package/dist/runnable.js +162 -0
- package/dist/runs.d.ts +840 -0
- package/dist/runs.js +2279 -0
- package/dist/secret-cut.d.ts +27 -0
- package/dist/secret-cut.js +109 -0
- package/dist/secrets.d.ts +50 -0
- package/dist/secrets.js +140 -0
- package/dist/server-lock.d.ts +44 -0
- package/dist/server-lock.js +140 -0
- package/dist/server.d.ts +626 -0
- package/dist/server.js +1756 -0
- package/dist/sessions.d.ts +4 -0
- package/dist/sessions.js +105 -0
- package/dist/skills.d.ts +31 -0
- package/dist/skills.js +68 -0
- package/dist/stats.d.ts +101 -0
- package/dist/stats.js +82 -0
- package/dist/tool-keys.d.ts +151 -0
- package/dist/tool-keys.js +273 -0
- package/dist/tool-plane.d.ts +143 -0
- package/dist/tool-plane.js +242 -0
- package/dist/tools.d.ts +147 -0
- package/dist/tools.js +253 -0
- package/dist/turn-end.d.ts +23 -0
- package/dist/turn-end.js +14 -0
- package/dist/turns.d.ts +34 -0
- package/dist/turns.js +202 -0
- package/dist/uploads.d.ts +104 -0
- package/dist/uploads.js +474 -0
- package/dist/usage.d.ts +29 -0
- package/dist/usage.js +58 -0
- package/dist/validate.d.ts +55 -0
- package/dist/validate.js +175 -0
- package/dist/web-fetch.d.ts +64 -0
- package/dist/web-fetch.js +262 -0
- package/dist/web-search.d.ts +54 -0
- package/dist/web-search.js +136 -0
- package/dist/webhooks.d.ts +182 -0
- package/dist/webhooks.js +487 -0
- package/dist/workspace-paths.d.ts +33 -0
- package/dist/workspace-paths.js +104 -0
- package/dist/workspace.d.ts +88 -0
- package/dist/workspace.js +369 -0
- package/launcher/agentrun-serve +109 -0
- package/package.json +94 -4
- package/skills/agentrun-serve/SKILL.md +128 -0
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
// The tool plane: the capabilities a pack or a revision may grant, the providers a user may pick for the two that reach
|
|
2
|
+
// the web, and what each resolves to on a run. A capability resolves in one order: (1) the provider the user picked, the
|
|
3
|
+
// agent's own (`definition.tool_settings`) over the server's (`PUT /v2/settings/tools`), optional; (2) the native tool:
|
|
4
|
+
// the harness's own (claude-agent's WebSearch), or on pi one request to the run's own model provider with its hosted
|
|
5
|
+
// search (hosted-search.ts); (3) for web_search, Parallel where the server holds its key (env or saved, which then bills
|
|
6
|
+
// it); (4) the kernel's keyless fallback: web_fetch's guarded direct fetch, and web_search on Exa's public keyless MCP
|
|
7
|
+
// endpoint (exa-keyless.ts). On claude-agent `auto` skips (2): Claude's own search is an explicit pick, `native`. Codex's
|
|
8
|
+
// own search on codex, Parallel or keyless Exa behind a gateway, on OpenRouter or under a spend cap;
|
|
9
|
+
// `off` turns web_search off. web_search's default, `auto`, is that order; a pick of `native` is native only,
|
|
10
|
+
// unavailable where there is none, never Exa. A grant names a capability, never a provider. A pick of parallel without
|
|
11
|
+
// PARALLEL_API_KEY resolves unavailable, never to something else. The server resolves a run's tools at its first
|
|
12
|
+
// launch, from its pinned revision and the settings then, keeps them for the run's life (runs.ts), and hands the run's
|
|
13
|
+
// process the outcome as a non-secret description (TOOL_PLANE_ENV): the run reads its tools' providers there, never from
|
|
14
|
+
// a request.
|
|
15
|
+
import { readFileSync } from "node:fs";
|
|
16
|
+
import { join } from "node:path";
|
|
17
|
+
import { decisionKeysOf, PARALLEL_KEY_ENV } from "./decisions.js";
|
|
18
|
+
import { writeDurableSync } from "./files.js";
|
|
19
|
+
import { DEFAULT_HARNESS, HARNESSES } from "./harness.js";
|
|
20
|
+
import { savedIn } from "./secrets.js";
|
|
21
|
+
import { hostModel, viaOpenRouter } from "./model.js";
|
|
22
|
+
/**
|
|
23
|
+
* The capabilities a pack or a revision may grant, by name: the tools the kernel gives a run, bound from serve's closed
|
|
24
|
+
* table (tools.ts) and named the same on every harness that runs them. `web_search` and `web_fetch` resolve to a
|
|
25
|
+
* provider (PROVIDERS); the rest are the kernel's own. Not capabilities: `fetch_page` (legacy: web_fetch's guarded fetch
|
|
26
|
+
* with no provider behind it), the workflow call nodes' `pdf_pages` and `llm` (a workflow's call node names them, a grant
|
|
27
|
+
* never does), and a catalog's tools (`monid.*`, `mcp:<server>/<tool>`: catalog tools, which their catalog grants).
|
|
28
|
+
*/
|
|
29
|
+
export const CAPABILITIES = ["read", "write", "edit", "web_search", "web_fetch", "browser", "ask_person"];
|
|
30
|
+
/** The providers a user may pick for each capability that has a choice, its default first: `auto`, the native search
|
|
31
|
+
* where there is one (never on claude-agent, where Claude's own search is picked as `native`), else Parallel where the
|
|
32
|
+
* server holds its key, else keyless Exa; `native`, the harness's own tool or its model provider's hosted one, and
|
|
33
|
+
* nothing else; `exa-keyless`, Exa's public MCP endpoint, no key; `kernel`, the guarded direct fetch; `parallel`,
|
|
34
|
+
* Parallel's Search and Extract APIs on PARALLEL_API_KEY; `off`, web_search turned off: nothing is searched, and an
|
|
35
|
+
* agent naming it is refused until it is turned on again. */
|
|
36
|
+
export const PROVIDERS = Object.freeze({ web_search: ["auto", "native", "exa-keyless", "parallel", "off"], web_fetch: ["kernel", "parallel"] });
|
|
37
|
+
export const PICKABLE = Object.keys(PROVIDERS);
|
|
38
|
+
/** Older names a revision may still grant, and the capability each one is: `fetch_page` runs web_fetch, under its own
|
|
39
|
+
* name, and resolves as web_fetch does. */
|
|
40
|
+
export const LEGACY_NAMES = Object.freeze({ fetch_page: "web_fetch" });
|
|
41
|
+
/** The capability a granted name runs: its legacy target, else itself. */
|
|
42
|
+
export const capabilityOf = (name) => LEGACY_NAMES[name] ?? name;
|
|
43
|
+
export const NO_PARALLEL_KEY = "unavailable: parallel picked, no PARALLEL_API_KEY";
|
|
44
|
+
/** web_search with `off` picked: no search leaves the server. */
|
|
45
|
+
export const SEARCH_OFF = "unavailable: web_search is turned off in settings";
|
|
46
|
+
/** The model providers whose hosted web search pi's web_search asks (hosted-search.ts), by pi-ai's provider id. */
|
|
47
|
+
export const HOSTED_SEARCH_PROVIDERS = ["anthropic", "openai"];
|
|
48
|
+
/** Why claude-agent has no native search under a spend cap, and what works there instead. */
|
|
49
|
+
const CLAUDE_CAPPED = "claude-agent under a spend cap: Claude's own search has per-use fees a spend cap cannot reserve yet, so web_search works under a cap through the default provider, auto";
|
|
50
|
+
/** Why a run of `input` has no native search, where it has none: `id`, as the unavailable text names it, and `why`, the
|
|
51
|
+
* same in a sentence (capabilities' `why`). */
|
|
52
|
+
function noNative(input) {
|
|
53
|
+
// Native, where there is one. Claude's model goes to Anthropic's Messages API (or its own ANTHROPIC_BASE_URL), never
|
|
54
|
+
// through the other harnesses' gateway; Codex's own search goes to OpenAI with its request, except behind a gateway
|
|
55
|
+
// (no known hosted search), on OpenRouter (which runs neither harness's own search, nor counts its searches) or
|
|
56
|
+
// under a spend cap (its request has no input bound, which a cap cannot admit); pi asks
|
|
57
|
+
// Anthropic's or OpenAI's. Under a spend cap Claude's own search is not offered either: each search has a per-use fee
|
|
58
|
+
// the cap cannot reserve yet (its request's bound holds the pages' input tokens, not the fees). Where there is none,
|
|
59
|
+
// `native` is unavailable, and `auto` goes to Parallel on the server's key (its fee booked and held by a cap, paid-calls.ts),
|
|
60
|
+
// else to keyless Exa.
|
|
61
|
+
const vendor = input.model?.slice(0, Math.max(0, input.model.indexOf("/")));
|
|
62
|
+
if ((input.harness === "claude-agent" || input.harness === "codex") && input.openRouter)
|
|
63
|
+
return { id: `${input.harness} on OpenRouter`, why: `through OpenRouter ${input.harness === "codex" ? "Codex" : "Claude"}'s own search is not run, and its searches are not counted to price` };
|
|
64
|
+
if (input.harness === "claude-agent")
|
|
65
|
+
return input.capped ? { id: CLAUDE_CAPPED, why: "under a spend cap Claude's own search is not offered, since a cap cannot reserve its per-use fees yet" } : undefined;
|
|
66
|
+
if (input.harness === "codex")
|
|
67
|
+
return input.gateway ? { id: "codex behind a gateway", why: "behind a gateway Codex has no own search" } : input.capped ? { id: "codex under a spend cap", why: "under a spend cap Codex's own search is not offered, since its request has no input bound" } : undefined;
|
|
68
|
+
if (input.gateway)
|
|
69
|
+
return { id: `${input.harness} behind a gateway`, why: `behind a gateway ${input.harness} has no hosted search` };
|
|
70
|
+
if (vendor && HOSTED_SEARCH_PROVIDERS.includes(vendor))
|
|
71
|
+
return undefined;
|
|
72
|
+
return input.model ? { id: input.model, why: `${input.model} has no hosted search here` } : { id: "a model with none named", why: "no model is named, so there is no hosted search" };
|
|
73
|
+
}
|
|
74
|
+
/** The native search of a run that has one, in a sentence. */
|
|
75
|
+
const nativeWhy = (input) => input.harness === "claude-agent" ? "Claude's own search" : input.harness === "codex" ? "Codex's own search" : `${input.model?.startsWith("openai/") ? "OpenAI" : "Anthropic"}'s hosted search, for ${input.model}`;
|
|
76
|
+
/** What `capability` resolves to on a run of `input`, and why in a plain sentence (capabilities' `why`): one rule, so
|
|
77
|
+
* the two never disagree. */
|
|
78
|
+
export function explainCapability(capability, input) {
|
|
79
|
+
const chosen = input.override ?? input.pick ?? PROVIDERS[capability][0];
|
|
80
|
+
const picked = input.override !== undefined ? "picked for this agent" : "picked in settings";
|
|
81
|
+
const key = `your Parallel key (${input.parallelKeyFrom ?? "server"})`;
|
|
82
|
+
if (chosen === "off")
|
|
83
|
+
return { resolves: SEARCH_OFF, why: "turned off in settings" };
|
|
84
|
+
if (chosen === "parallel")
|
|
85
|
+
return input.parallelKey ? { resolves: "parallel", why: `Parallel, ${picked}: ${key}` } : { resolves: NO_PARALLEL_KEY, why: "Parallel is picked, and no PARALLEL_API_KEY is set or saved" };
|
|
86
|
+
if (capability === "web_fetch")
|
|
87
|
+
return { resolves: "kernel", why: "the guarded direct fetch" };
|
|
88
|
+
if (chosen === "exa-keyless")
|
|
89
|
+
return { resolves: "exa-keyless", why: `keyless Exa, ${picked}: Exa's free search, no key` };
|
|
90
|
+
const none = noNative(input);
|
|
91
|
+
if (chosen === "native")
|
|
92
|
+
return none === undefined ? { resolves: "native", why: nativeWhy(input) } : { resolves: `unavailable: no native search for ${none.id}`, why: `no native search for ${none.id}` };
|
|
93
|
+
// On claude-agent `auto` skips Claude's own search, an explicit pick (`native`): Parallel on the server's key, else
|
|
94
|
+
// keyless Exa.
|
|
95
|
+
if (input.harness === "claude-agent")
|
|
96
|
+
return input.parallelKey ? { resolves: "parallel", why: key } : { resolves: "exa-keyless", why: "Exa's free keyless search, no key; Claude's own search is an explicit pick" };
|
|
97
|
+
if (none === undefined)
|
|
98
|
+
return { resolves: "native", why: nativeWhy(input) };
|
|
99
|
+
return input.parallelKey ? { resolves: "parallel", why: `${none.why}; ${key}` } : { resolves: "exa-keyless", why: `${none.why}; Exa's free keyless search, no key` };
|
|
100
|
+
}
|
|
101
|
+
/** What `capability` resolves to on a run of `input`. */
|
|
102
|
+
export const resolveCapability = (capability, input) => explainCapability(capability, input).resolves;
|
|
103
|
+
export const isUnavailable = (resolution) => resolution?.startsWith("unavailable: ") === true;
|
|
104
|
+
/** Why a resolution is unavailable: its words after "unavailable: " (any other resolution as it is). */
|
|
105
|
+
export const whyUnavailable = (resolution) => resolution.replace(/^unavailable: /, "");
|
|
106
|
+
/** The server's environment's part of every resolution: its gateway and Parallel's key, and where the key is from. */
|
|
107
|
+
const served = (env) => {
|
|
108
|
+
const parallelKey = PARALLEL_KEY_ENV in decisionKeysOf(env);
|
|
109
|
+
return { gateway: Boolean(env.AGENT_MODEL_BASE_URL), parallelKey, ...(parallelKey ? { parallelKeyFrom: savedIn(env).has(PARALLEL_KEY_ENV) ? "saved" : "server" } : {}) };
|
|
110
|
+
};
|
|
111
|
+
/** Each pickable capability on each harness under the server's `settings` and an agent's `overrides`, on `model`
|
|
112
|
+
* (default each harness's host model, the one a run that names none runs on: hostModel): what it resolves to and why, as
|
|
113
|
+
* capabilities and the tool catalog show them. */
|
|
114
|
+
export function explainsView(env, settings, overrides = {}, model) {
|
|
115
|
+
return Object.fromEntries(PICKABLE.map((name) => {
|
|
116
|
+
const input = { ...served(env), ...picked(name, settings, overrides) };
|
|
117
|
+
const each = HARNESSES.map((harness) => {
|
|
118
|
+
const on = model ?? hostModel(env, "default", harness);
|
|
119
|
+
return [harness, explainCapability(name, { ...input, ...(on ? { model: on } : {}), harness, openRouter: viaOpenRouter(env, harness, on) })];
|
|
120
|
+
});
|
|
121
|
+
return [name, { resolves: Object.fromEntries(each.map(([harness, said]) => [harness, said.resolves])), why: Object.fromEntries(each.map(([harness, said]) => [harness, said.why])) }];
|
|
122
|
+
}));
|
|
123
|
+
}
|
|
124
|
+
const picked = (name, settings, overrides = {}) => ({
|
|
125
|
+
...(overrides[name]?.provider ? { override: overrides[name].provider } : {}),
|
|
126
|
+
...(settings[name]?.provider ? { pick: settings[name].provider } : {}),
|
|
127
|
+
});
|
|
128
|
+
/** The run's process's description of its tools' providers: JSON of its Plane. */
|
|
129
|
+
export const TOOL_PLANE_ENV = "AGENTRUN_SERVE_TOOL_PLANE";
|
|
130
|
+
/** The Plane of a run of `tooling`, in the server's `env` (with its secrets) under its `settings`. */
|
|
131
|
+
export function planeFor(env, tooling, settings, { capped = false } = {}) {
|
|
132
|
+
const harness = tooling.harness ?? DEFAULT_HARNESS;
|
|
133
|
+
// A workflow's model nodes may each run on another tier's model, and a native search asks one model's provider: a
|
|
134
|
+
// workflow's search resolves with no model (keyless Exa, or Parallel where picked), never on a model a node may not use.
|
|
135
|
+
// A run that names no model runs on the host's for its harness (hostModel: a model key's default when no AGENT_MODEL
|
|
136
|
+
// it runs is set), so its search resolves on that one.
|
|
137
|
+
const model = tooling.workflow ? undefined : (tooling.model ?? hostModel(env, "default", harness));
|
|
138
|
+
const plane = {};
|
|
139
|
+
const granted = tooling.tools.map(capabilityOf);
|
|
140
|
+
for (const name of PICKABLE) {
|
|
141
|
+
if (granted.includes(name))
|
|
142
|
+
plane[name] = resolveCapability(name, { ...served(env), harness, capped, openRouter: viaOpenRouter(env, harness, model), ...(model ? { model } : {}), ...picked(name, settings, tooling.overrides) });
|
|
143
|
+
}
|
|
144
|
+
if (plane.web_search === "native" && harness === DEFAULT_HARNESS && model)
|
|
145
|
+
plane.model = model;
|
|
146
|
+
return plane;
|
|
147
|
+
}
|
|
148
|
+
/** A run's kept Plane at a later launch: as it was, but Parallel where the server no longer holds its key, which is
|
|
149
|
+
* unavailable, never another provider. */
|
|
150
|
+
export function recheckPlane(plane, env) {
|
|
151
|
+
const keyed = served(env).parallelKey;
|
|
152
|
+
return Object.fromEntries(Object.entries(plane).map(([name, value]) => [name, value === "parallel" && !keyed ? NO_PARALLEL_KEY : value]));
|
|
153
|
+
}
|
|
154
|
+
/** The Plane the server handed this run's process; empty when it handed none. */
|
|
155
|
+
export function planeOf(env) {
|
|
156
|
+
try {
|
|
157
|
+
const plane = JSON.parse(env[TOOL_PLANE_ENV] ?? "{}");
|
|
158
|
+
return typeof plane === "object" && plane !== null && !Array.isArray(plane) ? plane : {};
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
return {};
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/** Whether a run is handed Parallel's key: one of its capabilities resolves to Parallel. */
|
|
165
|
+
export const handsParallel = (plane) => PICKABLE.some((name) => plane[name] === "parallel");
|
|
166
|
+
/** What a save of `permission` answers until the tool gate lands, so no one keeps a deny that nothing enforces. */
|
|
167
|
+
export const NOT_YET = "permissions arrive with the tool gate";
|
|
168
|
+
/** The issues of `value` as a settings map, its fields under `at` (none: a body's own): each capability that has a
|
|
169
|
+
* choice to `{provider?}`, the provider one offered for it. */
|
|
170
|
+
export function settingsIssues(value, at = "") {
|
|
171
|
+
const field = (...names) => [at, ...names].filter(Boolean).join(".");
|
|
172
|
+
const isPlain = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
173
|
+
if (!isPlain(value))
|
|
174
|
+
return [{ field: at || "body", reason: "wrong_type", message: `${at || "the body"} is an object of ${PICKABLE.join(", ")} to their settings` }];
|
|
175
|
+
return Object.entries(value).flatMap(([name, setting]) => {
|
|
176
|
+
if (!Object.hasOwn(PROVIDERS, name))
|
|
177
|
+
return [{ field: field(name), reason: "not_allowed", message: `Tool settings are kept for ${PICKABLE.join(" and ")}; ${name} is not one of them.` }];
|
|
178
|
+
if (!isPlain(setting))
|
|
179
|
+
return [{ field: field(name), reason: "wrong_type", message: `${field(name)} is an object, {provider}` }];
|
|
180
|
+
return Object.entries(setting).flatMap(([key, given]) => {
|
|
181
|
+
if (key === "permission")
|
|
182
|
+
return [{ field: field(name, key), reason: "not_yet", message: NOT_YET }];
|
|
183
|
+
if (key !== "provider")
|
|
184
|
+
return [{ field: field(name, key), reason: "not_allowed", message: `${field(name)} keeps no field ${key}.` }];
|
|
185
|
+
const offered = PROVIDERS[name];
|
|
186
|
+
return offered.includes(given) ? [] : [{ field: field(name, key), reason: "not_an_option", message: `${field(name, key)} is one of ${offered.join(", ")}` }];
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
/** `map` with each capability's provider, its default where none is picked. */
|
|
191
|
+
export const withDefaults = (map) => Object.fromEntries(PICKABLE.map((name) => [name, { provider: map[name]?.provider ?? PROVIDERS[name][0] }]));
|
|
192
|
+
/** The server's tool settings, beside the agent store in its data directory: not a secret, and not in store.sqlite,
|
|
193
|
+
* which runs hold open. Read once at the start, written whole and durably (0600) at each PUT; a missing file is every
|
|
194
|
+
* default, and so is one it cannot read, which it says in one line. */
|
|
195
|
+
export class ToolSettings {
|
|
196
|
+
dir;
|
|
197
|
+
static FILE = "tool-settings.json";
|
|
198
|
+
current;
|
|
199
|
+
constructor(dir, warn = (line) => void process.stderr.write(`${line}\n`)) {
|
|
200
|
+
this.dir = dir;
|
|
201
|
+
const file = join(dir, ToolSettings.FILE);
|
|
202
|
+
let read = {};
|
|
203
|
+
try {
|
|
204
|
+
read = JSON.parse(readFileSync(file, "utf8"));
|
|
205
|
+
}
|
|
206
|
+
catch (error) {
|
|
207
|
+
if (error.code !== "ENOENT")
|
|
208
|
+
read = undefined;
|
|
209
|
+
}
|
|
210
|
+
const bad = read === undefined || settingsIssues(read).length > 0;
|
|
211
|
+
if (bad)
|
|
212
|
+
warn(`agentrun-serve: ${file} is not tool settings this server reads; every tool takes its default provider until a PUT /v2/settings/tools`);
|
|
213
|
+
this.current = bad ? {} : read;
|
|
214
|
+
}
|
|
215
|
+
get() {
|
|
216
|
+
return structuredClone(this.current);
|
|
217
|
+
}
|
|
218
|
+
/** Replaces the settings: a capability `map` leaves out takes its default. Durable before it returns. */
|
|
219
|
+
put(map) {
|
|
220
|
+
const kept = Object.fromEntries(PICKABLE.flatMap((name) => (map[name]?.provider ? [[name, { provider: map[name].provider }]] : [])));
|
|
221
|
+
writeDurableSync(join(this.dir, ToolSettings.FILE), `${JSON.stringify(kept)}\n`);
|
|
222
|
+
this.current = kept;
|
|
223
|
+
return this.get();
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
/** GET /v2/agents/{id}'s `tools`: each tool its current revision grants, in `order` (capabilities.tools'), and for one
|
|
227
|
+
* with a provider choice the provider in force and where it came from (the agent's own settings, the server's, or the
|
|
228
|
+
* default), the one that applies when the agent sets none (the server's), and what it resolves to on the agent's
|
|
229
|
+
* harness and model. A tool with no choice is its name alone. */
|
|
230
|
+
export function agentTools(env, settings, agent, order) {
|
|
231
|
+
const plane = planeFor(env, agent, settings);
|
|
232
|
+
const rank = (name) => order.indexOf(capabilityOf(name)) + (name in LEGACY_NAMES ? 0.5 : 0);
|
|
233
|
+
return [...new Set(agent.tools)].sort((a, b) => rank(a) - rank(b)).map((name) => {
|
|
234
|
+
const capability = capabilityOf(name);
|
|
235
|
+
if (!Object.hasOwn(PROVIDERS, capability))
|
|
236
|
+
return { name };
|
|
237
|
+
const pick = capability;
|
|
238
|
+
const own = agent.overrides?.[pick]?.provider;
|
|
239
|
+
const server = settings[pick]?.provider;
|
|
240
|
+
return { name, provider: own ?? server ?? PROVIDERS[pick][0], provider_from: own ? "agent" : server ? "server" : "default", default_provider: server ?? PROVIDERS[pick][0], resolved: plane[pick] };
|
|
241
|
+
});
|
|
242
|
+
}
|
package/dist/tools.d.ts
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import type { TSchema } from "@earendil-works/pi-ai";
|
|
2
|
+
import { type Extension, type Harness, type ToolRegistration, type Tx } from "@earendil-works/pi-durable";
|
|
3
|
+
import type { AppContext } from "@parcha/pi-durable-disk";
|
|
4
|
+
import type { Revision } from "@parcha/pi-durable-agent";
|
|
5
|
+
import type { CodingSource } from "./coding-tools.js";
|
|
6
|
+
import { type Complete } from "./llm.js";
|
|
7
|
+
import { type Ledger } from "./paid-calls.js";
|
|
8
|
+
import { type Tooling, type ToolSettingsMap } from "./tool-plane.js";
|
|
9
|
+
export declare const ASK_TOOL = "ask_person";
|
|
10
|
+
/** Under `--faux` only: a module whose default export gives the browser's `{ provider, driver }`, in place of
|
|
11
|
+
* Browserbase's (the tests' fake backend). */
|
|
12
|
+
export declare const FAUX_BROWSER_ENV = "AGENTRUN_SERVE_FAUX_BROWSER";
|
|
13
|
+
/** What the result of `ask_person` says; the person's page shows the question as a waiting row. */
|
|
14
|
+
export declare const asked: (question: string) => string;
|
|
15
|
+
export declare const askPerson: ToolRegistration<TSchema, import("@earendil-works/chord").JsonValue>;
|
|
16
|
+
/** What a tool's binding gets from the run's process. */
|
|
17
|
+
export type ToolHost = {
|
|
18
|
+
where: AppContext;
|
|
19
|
+
/** The run's environment: the server's, without the server's token. */
|
|
20
|
+
env: NodeJS.ProcessEnv;
|
|
21
|
+
/** The run's coding tools, by its place (coding-tools.ts codingSource). */
|
|
22
|
+
coding: CodingSource;
|
|
23
|
+
/** Installs an extension in the run's registry, before the run opens. */
|
|
24
|
+
install(extension: Extension): void;
|
|
25
|
+
/** Runs in the commit that creates each of the run's conversations. */
|
|
26
|
+
onConversation(write: (tx: Tx, conversationId: number) => void | Promise<void>): void;
|
|
27
|
+
/** Runs once the run's Harness is open, before anything in it resumes. */
|
|
28
|
+
beforeResume(settle: (harness: Harness) => void | Promise<void>): void;
|
|
29
|
+
/** Runs when the run's process lets the run go (its work done, or a SIGTERM), while the Harness is still open. */
|
|
30
|
+
beforeRelease(stop: (harness: Harness) => void | Promise<void>): void;
|
|
31
|
+
};
|
|
32
|
+
/** What a name stands for in the run: the pi tools it offers, and the extensions a conversation selects for them. */
|
|
33
|
+
export type ToolBinding = {
|
|
34
|
+
tools: readonly ToolRegistration[];
|
|
35
|
+
extensions: readonly Extension[];
|
|
36
|
+
};
|
|
37
|
+
/** What a call node's effect gets from the run's process: its signal, environment and work directory, one completion
|
|
38
|
+
* on the run's models (the `llm` tool's), and the ledger its paid requests are booked in (paid-calls.ts). */
|
|
39
|
+
export type EffectRun = {
|
|
40
|
+
signal: AbortSignal;
|
|
41
|
+
env: NodeJS.ProcessEnv;
|
|
42
|
+
work: string;
|
|
43
|
+
complete?: Complete;
|
|
44
|
+
ledger?: Ledger;
|
|
45
|
+
};
|
|
46
|
+
export type ToolEntry = {
|
|
47
|
+
/** One line, for capabilities. */
|
|
48
|
+
summary: string;
|
|
49
|
+
/** The environment variables it needs, by name. */
|
|
50
|
+
needs: readonly string[];
|
|
51
|
+
/** Whether a workflow's model node may name it. */
|
|
52
|
+
nodes: boolean;
|
|
53
|
+
/** What the name stands for, bound in the run's process once. */
|
|
54
|
+
bind(host: ToolHost): Promise<ToolBinding>;
|
|
55
|
+
/** What a workflow's `call` node `via: "tool"` naming it runs: its interpolated `args` in, the value its `out` schema
|
|
56
|
+
* checks out. Absent, no call node may name it. */
|
|
57
|
+
effect?(args: Record<string, unknown>, run: EffectRun): Promise<unknown>;
|
|
58
|
+
/** Only a workflow's call node runs it: no agent and no model node may name it. */
|
|
59
|
+
callOnly?: true;
|
|
60
|
+
/** Only an agent whose place is a sandbox may name it: it runs in the box (runnable.ts). */
|
|
61
|
+
sandboxOnly?: true;
|
|
62
|
+
/** No agent whose place is a sandbox may name it: it writes the run's work/ from this machine by paths a box's command
|
|
63
|
+
* could turn through a link (runnable.ts). */
|
|
64
|
+
runnerOnly?: true;
|
|
65
|
+
};
|
|
66
|
+
/** Where the browser files what it reads: `work/evidence/`, so the run's files show it and the agent can read it back. A
|
|
67
|
+
* text body follows one line of the read's facts; a capture's bytes go beside its facts. Each read takes the next free
|
|
68
|
+
* number, reserved by an exclusive create, so reads at once (parallel nodes, one turn's calls) and the reads of a later
|
|
69
|
+
* process never overwrite one another. */
|
|
70
|
+
export declare const evidenceIn: (work: string) => {
|
|
71
|
+
file: (label: string, record: {
|
|
72
|
+
tool: string;
|
|
73
|
+
facts: Record<string, unknown>;
|
|
74
|
+
body: string | Uint8Array;
|
|
75
|
+
ext?: string;
|
|
76
|
+
}) => Promise<{
|
|
77
|
+
path: string;
|
|
78
|
+
bodyLine: number;
|
|
79
|
+
bodyPath?: undefined;
|
|
80
|
+
} | {
|
|
81
|
+
path: string;
|
|
82
|
+
bodyPath: string;
|
|
83
|
+
bodyLine?: undefined;
|
|
84
|
+
}>;
|
|
85
|
+
};
|
|
86
|
+
export declare const TOOLS: Readonly<Record<string, ToolEntry>>;
|
|
87
|
+
/** Every name a revision may name, those a workflow's model node may, and those a workflow's call node may run. */
|
|
88
|
+
export declare const BOUND_TOOLS: readonly string[];
|
|
89
|
+
export declare const NODE_TOOLS: readonly string[];
|
|
90
|
+
export declare const CALL_TOOLS: readonly string[];
|
|
91
|
+
/** Whether `name` is one of `allowed`, or a legacy name for one (fetch_page, web_fetch's): a revision that names it
|
|
92
|
+
* still saves and runs, though the table lists it no more. */
|
|
93
|
+
export declare const allows: (allowed: readonly string[], name: string) => boolean;
|
|
94
|
+
/** The tools a run's learned workflow draft may name (learn/check.ts): those of the agent's `granted` tools a workflow's
|
|
95
|
+
* model or call node runs here (NODE_TOOLS, CALL_TOOLS), each as granted and by its capability's name. A harness's own
|
|
96
|
+
* tool (Bash, exec_command, apply_patch) is never one, so the DSL refuses a draft that names it. */
|
|
97
|
+
export declare const learnedWorkflowTools: (granted: readonly string[]) => string[];
|
|
98
|
+
/** The tools a workflow names (`nodes` from workflowNodes): on its model nodes (`tools`), and on its `call` nodes
|
|
99
|
+
* `via: "tool"` (`tool`). */
|
|
100
|
+
export declare function workflowTools(nodes: readonly Record<string, unknown>[]): {
|
|
101
|
+
nodes: string[];
|
|
102
|
+
calls: string[];
|
|
103
|
+
};
|
|
104
|
+
/** The tools a revision grants its run: an agentic revision's `tools`; a workflow revision's `tools` with those its model
|
|
105
|
+
* and call nodes name, which its run binds whether `tools` lists them or not. */
|
|
106
|
+
export declare function grantedTools(revision: {
|
|
107
|
+
kind: string;
|
|
108
|
+
tools?: readonly string[];
|
|
109
|
+
workflow?: unknown;
|
|
110
|
+
}): Promise<string[]>;
|
|
111
|
+
/** The table's entry for `name`, or undefined for a name it does not hold. */
|
|
112
|
+
export declare const toolOf: (name: string) => ToolEntry | undefined;
|
|
113
|
+
/** What a stored revision's tools resolve from (tool-plane.ts): the tools it grants, its harness, model and settings. */
|
|
114
|
+
export declare function toolingOf(revision: Revision): Promise<Tooling>;
|
|
115
|
+
/** The variables `entry` needs that `env` does not set, by name. */
|
|
116
|
+
export declare const missingEnv: (entry: ToolEntry, env: NodeJS.ProcessEnv) => string[];
|
|
117
|
+
/** What keeps `names` from being bound here: names outside the table (or, for a workflow's model nodes, that a node may
|
|
118
|
+
* not name), and the variables each tool in it needs that `env` does not set. Undefined when nothing does. */
|
|
119
|
+
export declare function toolRefusal(names: readonly string[], env: NodeJS.ProcessEnv, where?: "agent" | "nodes" | "calls"): {
|
|
120
|
+
message: string;
|
|
121
|
+
unbound: string[];
|
|
122
|
+
missing: Record<string, string[]>;
|
|
123
|
+
} | undefined;
|
|
124
|
+
/** Every tool as capabilities show it, the server's one tool catalog: available here, or the variables it is missing
|
|
125
|
+
* (names only), and the harnesses that run it (another harness than pi runs only the host tools, host-tools.ts). A tool
|
|
126
|
+
* a user picks a provider for (tool-plane.ts) gives the providers offered, the server's (`provider`, the default where it
|
|
127
|
+
* sets none), the default, and what it resolves to on each harness under the server's `settings`: available where any
|
|
128
|
+
* is not unavailable, and missing PARALLEL_API_KEY where Parallel is picked without it. An unavailable tool says why
|
|
129
|
+
* (`reason`). `noBox`: why no box can run a sandbox-only tool here (place.ts noBoxReason), which leaves it
|
|
130
|
+
* unavailable with that reason; undefined, a box can. */
|
|
131
|
+
export declare const toolsView: (env: NodeJS.ProcessEnv, settings?: ToolSettingsMap, noBox?: string) => {
|
|
132
|
+
providers?: ("auto" | "off" | "parallel" | "native" | "exa-keyless" | "kernel")[] | undefined;
|
|
133
|
+
provider?: string | undefined;
|
|
134
|
+
default_provider?: "auto" | "kernel" | undefined;
|
|
135
|
+
resolves?: Record<"pi" | "claude-agent" | "codex", import("./tool-plane.js").Resolution> | undefined;
|
|
136
|
+
why?: Record<"pi" | "claude-agent" | "codex", string> | undefined;
|
|
137
|
+
harnesses: ("pi" | "claude-agent" | "codex")[];
|
|
138
|
+
missing?: string[] | undefined;
|
|
139
|
+
reason?: string | undefined;
|
|
140
|
+
available: boolean;
|
|
141
|
+
sandbox_only?: boolean | undefined;
|
|
142
|
+
call_only?: boolean | undefined;
|
|
143
|
+
name: string;
|
|
144
|
+
summary: string;
|
|
145
|
+
nodes: boolean;
|
|
146
|
+
calls: boolean;
|
|
147
|
+
}[];
|