@parcha/agentrun-serve 0.0.0-bootstrap.0 → 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 +1724 -0
- 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 +96 -1
- package/skills/agentrun-serve/SKILL.md +128 -0
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
// The keys a person saves for this server's tools, by name, through /v2/settings/tool-keys. DIR/tool-keys.json (0600,
|
|
2
|
+
// written whole and synced, then renamed) holds them only as AES-256-GCM ciphertext (pi-durable-agent's `seal`) under the seal
|
|
3
|
+
// key the launcher hands the server (AGENTRUN_SEAL_KEY), which is never in the data directory: a copy of the directory
|
|
4
|
+
// holds ciphertext alone. Each value is bound to its field's name and this format, so one moved to another name does
|
|
5
|
+
// not open, and carries a check of the key it was sealed under (an HMAC of a fixed label, neither the key nor a hash of
|
|
6
|
+
// it), so a value sealed under another key reads as that, told apart from a damaged one. Only this process opens a
|
|
7
|
+
// value, when it is asked for. One that does not open is never a crash and never a clear fallback: it reads as not
|
|
8
|
+
// set, to be entered again, and the log says why once, naming the file, never a value. The server reads a saved value by
|
|
9
|
+
// name as it reads a launcher's secret (secrets.ts' `secret`), the launcher's winning: a run gets it over its pipe (a
|
|
10
|
+
// decision key on its decision descriptor) at its launch, and capabilities and checks see it once it is saved. A key is
|
|
11
|
+
// checked against its provider before it is kept (key-check.ts): one the provider refuses is never kept, and the file
|
|
12
|
+
// keeps, beside the sealed values, whether each key was accepted or kept not checked, and why (never any of a value).
|
|
13
|
+
import { createHmac } from "node:crypto";
|
|
14
|
+
import { readFileSync } from "node:fs";
|
|
15
|
+
import { join } from "node:path";
|
|
16
|
+
import { seal, unseal } from "@parcha/pi-durable-agent";
|
|
17
|
+
import { decisionsOf } from "./decisions.js";
|
|
18
|
+
import { ApiError, invalid } from "./errors.js";
|
|
19
|
+
import { writeDurableSync } from "./files.js";
|
|
20
|
+
import { HARNESSES } from "./harness.js";
|
|
21
|
+
import { checkKey } from "./key-check.js";
|
|
22
|
+
import { toolsView } from "./tools.js";
|
|
23
|
+
import { MODEL_KEYS } from "./model.js";
|
|
24
|
+
import { isObject, unknownFields } from "./validate.js";
|
|
25
|
+
export const TOOL_KEYS_FILE = "tool-keys.json";
|
|
26
|
+
export const SEAL_KEY_ENV = "AGENTRUN_SEAL_KEY";
|
|
27
|
+
const FORMAT = "tool-keys/1";
|
|
28
|
+
const MAX_VALUE_BYTES = 1024;
|
|
29
|
+
const CONTROL = /[\u0000-\u001f\u007f-\u009f]/;
|
|
30
|
+
/** Each key a person may save, fixed here: its kind, the fields it is entered as (BROWSERBASE_PROJECT_ID is no secret,
|
|
31
|
+
* and is kept the same way), and what it may unlock: tools by name, and `decisions.<id>`, a workflow's decision
|
|
32
|
+
* provider. GET lists only those this server binds (unlockedBy), so a name here the server does not bind is never
|
|
33
|
+
* promised, and one shows by itself once the server binds it. A `tool` key's fields reach only the runs that name a
|
|
34
|
+
* tool it unlocks (runs.ts' secretsFor); a key of any other kind (a model's) reaches every run. */
|
|
35
|
+
export const TOOL_KEYS = [
|
|
36
|
+
{ id: "parallel", kind: "tool", label: "Parallel", fields: ["PARALLEL_API_KEY"], unlocks: ["web_fetch", "web_search", "decisions.parallel"] },
|
|
37
|
+
{ id: "monid", kind: "tool", label: "Monid", fields: ["MONID_API_KEY"], unlocks: ["monid.discover", "monid.inspect", "monid.run"] },
|
|
38
|
+
{ id: "browserbase", kind: "tool", label: "Browserbase", fields: ["BROWSERBASE_API_KEY", "BROWSERBASE_PROJECT_ID"], unlocks: ["browser"] },
|
|
39
|
+
// Jev's decision provider (decisions.ts' `jev`), on TypeSafe's key: a workflow's judges, as Parallel's key unlocks its.
|
|
40
|
+
{ id: "typesafe", kind: "tool", label: "TypeSafe (Jev)", fields: ["TYPESAFE_API_KEY"], unlocks: ["decisions.jev"] },
|
|
41
|
+
// A model provider's key (model.ts' MODEL_KEYS, which give each its default model): every run gets it, as the
|
|
42
|
+
// launcher's model keys reach every run. Its harnesses are pi and the harness that is the provider's own.
|
|
43
|
+
...MODEL_KEYS.map(({ id, label, field, harnesses }) => ({ id, kind: "model", label, fields: [field], unlocks: [], harnesses })),
|
|
44
|
+
];
|
|
45
|
+
const FIELDS = TOOL_KEYS.flatMap((row) => row.fields);
|
|
46
|
+
/** The fields of the `tool` rows: keys a tool or a decision provider reads, and no harness (the harnesses read their
|
|
47
|
+
* packages, their pins and their models' keys). A row of another kind (a model's) is outside them. */
|
|
48
|
+
export const TOOL_FIELDS = TOOL_KEYS.filter((row) => row.kind === "tool").flatMap((row) => row.fields);
|
|
49
|
+
/** What `candidates` unlock here, as capabilities show it: the tools of `tools` (capabilities' `tools`, available or
|
|
50
|
+
* not) and the providers of `providers` (its `workflows.decisions.providers`) named among them, and the harnesses
|
|
51
|
+
* that run those tools. A name neither holds is left out; a key that unlocks none of its names lists nothing. */
|
|
52
|
+
export function unlockedBy(candidates, tools, providers) {
|
|
53
|
+
const bound = new Set([...tools.map((tool) => tool.name), ...providers.map((provider) => `decisions.${provider.id}`)]);
|
|
54
|
+
const unlocks = candidates.filter((name) => bound.has(name));
|
|
55
|
+
const run = new Set(tools.filter((tool) => unlocks.includes(tool.name)).flatMap((tool) => tool.harnesses));
|
|
56
|
+
return { unlocks, harnesses: HARNESSES.filter((harness) => run.has(harness)) };
|
|
57
|
+
}
|
|
58
|
+
/** What a row unlocks here: a `tool` row's, its tools and providers as capabilities bind them (unlockedBy); any other
|
|
59
|
+
* kind's (a model's), no tool, on those that run on it (its `harnesses`, when it names them) that this server runs
|
|
60
|
+
* (`offers`, harness.ts' harnessOffers) or would once its key is set: one unavailable only for want of a model key
|
|
61
|
+
* among whose `keys` is the row's (its first field). So OpenRouter's row names all three before any key is saved; a
|
|
62
|
+
* harness not installed, off its pins or too big for this host is left out. */
|
|
63
|
+
export function rowUnlocks(row, tools, providers, offers) {
|
|
64
|
+
if (row.kind === "tool")
|
|
65
|
+
return unlockedBy(row.unlocks, tools, providers);
|
|
66
|
+
const key = row.fields?.[0];
|
|
67
|
+
const runs = (harness) => offers.some((offer) => offer.id === harness && (offer.available || (key !== undefined && offer.keys?.includes(key) === true)));
|
|
68
|
+
return { unlocks: [], harnesses: HARNESSES.filter((harness) => (row.harnesses ?? HARNESSES).includes(harness) && runs(harness)) };
|
|
69
|
+
}
|
|
70
|
+
/** The key that unlocks the tool `name` (capabilities' `tools[].key`, so a page links "needs the X key" to it), if any. */
|
|
71
|
+
export const keyOf = (name) => TOOL_KEYS.find((row) => row.unlocks.includes(name))?.id;
|
|
72
|
+
/** Why a stored value does not open, in the order a re-entry names one: no seal key now, another than it was sealed
|
|
73
|
+
* under, or the file (or its entry) damaged. */
|
|
74
|
+
export const UNREADABLE = ["seal_key_missing", "seal_key_changed", "file_unreadable"];
|
|
75
|
+
/** The check a key kept before this server checked keys reads as: none was made. */
|
|
76
|
+
const UNCHECKED = { state: "not_checked", reason: "Saved before this server checked keys; save it again to check it" };
|
|
77
|
+
/** A check as the file keeps it, else undefined. */
|
|
78
|
+
const keptCheck = (entry) => !isObject(entry) ? undefined
|
|
79
|
+
: entry.state === "accepted" && typeof entry.at === "string" ? { state: "accepted", at: entry.at }
|
|
80
|
+
: entry.state === "not_checked" && typeof entry.reason === "string" ? { state: "not_checked", reason: entry.reason, ...(typeof entry.at === "string" ? { at: entry.at } : {}) }
|
|
81
|
+
: undefined;
|
|
82
|
+
/** The seal key `text` gives: 32 bytes in base64 (or base64url), else none. */
|
|
83
|
+
export function sealKeyOf(text) {
|
|
84
|
+
const trimmed = text?.trim() ?? "";
|
|
85
|
+
return /^[A-Za-z0-9+/_-]{43}=?$/.test(trimmed) ? Buffer.from(trimmed, "base64") : undefined;
|
|
86
|
+
}
|
|
87
|
+
const aad = (name) => `${FORMAT}|${name}`;
|
|
88
|
+
export class ToolKeys {
|
|
89
|
+
env;
|
|
90
|
+
say;
|
|
91
|
+
file;
|
|
92
|
+
key;
|
|
93
|
+
sealCheck;
|
|
94
|
+
said = "";
|
|
95
|
+
/** `env` is what the server is started with (withSecrets' `"own"`, never a saved key, or each would read as the
|
|
96
|
+
* server's and could not be deleted): a field it sets is the server's, and wins. `say` takes a log line's fields. */
|
|
97
|
+
constructor(data, env, say) {
|
|
98
|
+
this.env = env;
|
|
99
|
+
this.say = say;
|
|
100
|
+
this.file = join(data, TOOL_KEYS_FILE);
|
|
101
|
+
this.key = sealKeyOf(env[SEAL_KEY_ENV]);
|
|
102
|
+
this.sealCheck = this.key && createHmac("sha256", this.key).update(`agentrun-serve ${FORMAT} key check`).digest("base64url");
|
|
103
|
+
if (env[SEAL_KEY_ENV] !== undefined && !this.key)
|
|
104
|
+
say({ condition: "seal_key_invalid", name: SEAL_KEY_ENV });
|
|
105
|
+
}
|
|
106
|
+
/** The file's entries, none with no file; "unreadable" when it does not read as this format. A file from before checks
|
|
107
|
+
* has none. */
|
|
108
|
+
kept() {
|
|
109
|
+
try {
|
|
110
|
+
const doc = JSON.parse(readFileSync(this.file, "utf8"));
|
|
111
|
+
if (!isObject(doc) || doc.v !== 1 || !isObject(doc.fields))
|
|
112
|
+
return "unreadable";
|
|
113
|
+
const checks = Object.entries(isObject(doc.checks) ? doc.checks : {}).flatMap(([id, entry]) => {
|
|
114
|
+
const check = keptCheck(entry);
|
|
115
|
+
return check ? [[id, check]] : [];
|
|
116
|
+
});
|
|
117
|
+
return { fields: { ...doc.fields }, checks: Object.fromEntries(checks) };
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
return error.code === "ENOENT" ? { fields: {}, checks: {} } : "unreadable";
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
open(name, entry) {
|
|
124
|
+
if (!this.key)
|
|
125
|
+
return { unreadable: "seal_key_missing" };
|
|
126
|
+
if (!isObject(entry) || typeof entry.sealed !== "string" || typeof entry.check !== "string")
|
|
127
|
+
return { unreadable: "file_unreadable" };
|
|
128
|
+
if (entry.check !== this.sealCheck)
|
|
129
|
+
return { unreadable: "seal_key_changed" };
|
|
130
|
+
try {
|
|
131
|
+
return { value: unseal(this.key, Buffer.from(entry.sealed, "base64"), aad(name)).toString("utf8") };
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
return { unreadable: "file_unreadable" };
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/** The stored value of the field `name`, opened now (secrets.ts reads a saved key by name through this); undefined
|
|
138
|
+
* with none, or one that does not open, which view() asks for again: never a clear fallback. */
|
|
139
|
+
value(name) {
|
|
140
|
+
if (!FIELDS.includes(name))
|
|
141
|
+
return undefined;
|
|
142
|
+
const kept = this.kept();
|
|
143
|
+
const opened = kept !== "unreadable" && kept.fields[name] !== undefined ? this.open(name, kept.fields[name]) : undefined;
|
|
144
|
+
return opened && "value" in opened ? opened.value : undefined;
|
|
145
|
+
}
|
|
146
|
+
/** Every stored value that opens, by field name. */
|
|
147
|
+
values() {
|
|
148
|
+
return Object.fromEntries(FIELDS.flatMap((name) => {
|
|
149
|
+
const value = this.value(name);
|
|
150
|
+
return value === undefined ? [] : [[name, value]];
|
|
151
|
+
}));
|
|
152
|
+
}
|
|
153
|
+
/** GET: each key's fields, whether set and where from (never a value), what it unlocks of what capabilities shows
|
|
154
|
+
* here (a model key: the harnesses `offers` says this server runs or would on the key), its check when its key (its first field) is
|
|
155
|
+
* stored here (null otherwise: the server's own is not checked here), and what to enter again, with why. */
|
|
156
|
+
view(offers = []) {
|
|
157
|
+
const kept = this.kept();
|
|
158
|
+
const again = [];
|
|
159
|
+
const tools = toolsView(this.env);
|
|
160
|
+
const providers = decisionsOf(this.env);
|
|
161
|
+
const keys = TOOL_KEYS.map((row) => {
|
|
162
|
+
const fields = row.fields.map((name) => {
|
|
163
|
+
if (this.env[name])
|
|
164
|
+
return { name, set: true, source: "server" };
|
|
165
|
+
const opened = kept !== "unreadable" && kept.fields[name] !== undefined ? this.open(name, kept.fields[name]) : undefined;
|
|
166
|
+
if (opened && "value" in opened)
|
|
167
|
+
return { name, set: true, source: "stored" };
|
|
168
|
+
if (opened)
|
|
169
|
+
again.push({ name, why: opened.unreadable });
|
|
170
|
+
return { name, set: false, source: null, ...(opened ? { stored_unreadable: true } : {}) };
|
|
171
|
+
});
|
|
172
|
+
const check = fields[0].source === "stored" && kept !== "unreadable" ? (kept.checks[row.id] ?? UNCHECKED) : null;
|
|
173
|
+
return { id: row.id, kind: row.kind, label: row.label, ...rowUnlocks(row, tools, providers, offers), fields, check };
|
|
174
|
+
});
|
|
175
|
+
// A file that does not read as a whole names no field: which it held is unknown.
|
|
176
|
+
const reason = kept === "unreadable" ? "file_unreadable" : UNREADABLE.find((why) => again.some((field) => field.why === why));
|
|
177
|
+
const reenter = reason ? { reason, fields: again.map((field) => field.name) } : null;
|
|
178
|
+
const said = JSON.stringify(reenter);
|
|
179
|
+
if (reenter && said !== this.said)
|
|
180
|
+
this.say({ condition: reenter.reason, file: this.file, fields: reenter.fields.join(",") || "unknown" });
|
|
181
|
+
this.said = said;
|
|
182
|
+
return { keys, reenter };
|
|
183
|
+
}
|
|
184
|
+
/** A PUT's check, before save(): the key it sends (its row's first field; Browserbase's project id is no key) checked
|
|
185
|
+
* against its provider (key-check.ts), the fetch `fetchFor` gives for the row (undefined: none, so not checked), its
|
|
186
|
+
* wait cut by `stop`. The body is held to what save() takes first, so a save that would be refused sends nothing. A
|
|
187
|
+
* key the provider refuses is 422 in its words, and nothing is kept; undefined when the body sends no key: the row's
|
|
188
|
+
* check stays as it was. */
|
|
189
|
+
async check(id, body, fetchFor, stop) {
|
|
190
|
+
const { row, values } = this.admit(id, body);
|
|
191
|
+
const name = row.fields[0];
|
|
192
|
+
if (values[name] === undefined)
|
|
193
|
+
return undefined;
|
|
194
|
+
const outcome = await checkKey(row, values[name], this.env, await fetchFor(row.id), undefined, stop);
|
|
195
|
+
if (outcome.state === "refused")
|
|
196
|
+
throw invalid([{ field: `values.${name}`, reason: "refused_by_provider", message: outcome.message }]);
|
|
197
|
+
return outcome;
|
|
198
|
+
}
|
|
199
|
+
/** PUT: each of `body.values` sealed under the seal key, and `check` (check()'s) kept for the key when given; the key's
|
|
200
|
+
* other fields stay as they are. A key saved with no check (a caller other than the route) drops the one it had. */
|
|
201
|
+
save(id, body, check) {
|
|
202
|
+
const { row, values } = this.admit(id, body);
|
|
203
|
+
const kept = this.kept();
|
|
204
|
+
// A file that does not read is replaced: what it held opens nowhere.
|
|
205
|
+
const { fields, checks } = kept === "unreadable" ? { fields: {}, checks: {} } : kept;
|
|
206
|
+
for (const [name, value] of Object.entries(values))
|
|
207
|
+
fields[name] = { sealed: seal(this.key, Buffer.from(value, "utf8"), aad(name)).toString("base64"), check: this.sealCheck };
|
|
208
|
+
if (values[row.fields[0]] !== undefined)
|
|
209
|
+
delete checks[row.id];
|
|
210
|
+
if (check)
|
|
211
|
+
checks[row.id] = check;
|
|
212
|
+
this.write(fields, checks);
|
|
213
|
+
}
|
|
214
|
+
/** What a PUT may save: the key's row and the body's values, or 422 (the body), 409 (a field the server's, or no seal
|
|
215
|
+
* key). No message holds a value, or any part of one. */
|
|
216
|
+
admit(id, body) {
|
|
217
|
+
const row = this.row(id);
|
|
218
|
+
const issues = unknownFields(body, ["values"]);
|
|
219
|
+
const values = isObject(body.values) ? body.values : {};
|
|
220
|
+
if (!Object.keys(values).length)
|
|
221
|
+
issues.push({ field: "values", reason: body.values === undefined ? "missing" : "wrong_type", message: `values holds one or more of ${row.fields.join(", ")}, by name` });
|
|
222
|
+
for (const [name, value] of Object.entries(values)) {
|
|
223
|
+
const field = `values.${name}`;
|
|
224
|
+
if (!row.fields.includes(name))
|
|
225
|
+
issues.push({ field, reason: "not_allowed", message: `The key ${row.id} has the fields ${row.fields.join(", ")}.` });
|
|
226
|
+
else if (typeof value !== "string" || value === "")
|
|
227
|
+
issues.push({ field, reason: "wrong_type", message: `${name} is text, not empty` });
|
|
228
|
+
else if (CONTROL.test(value))
|
|
229
|
+
issues.push({ field, reason: "invalid", message: `${name} holds a control character` });
|
|
230
|
+
else if (Buffer.byteLength(value) > MAX_VALUE_BYTES)
|
|
231
|
+
issues.push({ field, reason: "too_long", message: `${name} is at most ${MAX_VALUE_BYTES} bytes` });
|
|
232
|
+
}
|
|
233
|
+
if (issues.length)
|
|
234
|
+
throw invalid(issues);
|
|
235
|
+
this.notServers(Object.keys(values));
|
|
236
|
+
if (!this.key)
|
|
237
|
+
throw new ApiError("no_sealing_key", `This server was handed no seal key (${SEAL_KEY_ENV}), so it keeps no tool key: it never keeps one in the clear.`);
|
|
238
|
+
return { row, values };
|
|
239
|
+
}
|
|
240
|
+
/** DELETE: the key's stored fields gone, and its check. Refused only when the server sets every field of it: none is
|
|
241
|
+
* the page's. */
|
|
242
|
+
remove(id) {
|
|
243
|
+
const row = this.row(id);
|
|
244
|
+
if (row.fields.every((name) => this.env[name]))
|
|
245
|
+
this.notServers(row.fields);
|
|
246
|
+
const kept = this.kept();
|
|
247
|
+
if (kept !== "unreadable" && !row.fields.some((name) => name in kept.fields))
|
|
248
|
+
return;
|
|
249
|
+
const { fields, checks } = kept === "unreadable" ? { fields: {}, checks: {} } : kept;
|
|
250
|
+
for (const name of row.fields)
|
|
251
|
+
delete fields[name];
|
|
252
|
+
delete checks[row.id];
|
|
253
|
+
this.write(fields, checks);
|
|
254
|
+
}
|
|
255
|
+
row(id) {
|
|
256
|
+
const row = TOOL_KEYS.find((r) => r.id === id);
|
|
257
|
+
if (!row)
|
|
258
|
+
throw invalid([{ field: "key_id", reason: "not_an_option", message: `The tool keys are ${TOOL_KEYS.map((r) => r.id).join(", ")}.` }]);
|
|
259
|
+
return row;
|
|
260
|
+
}
|
|
261
|
+
/** 409 when this server's own environment (its launcher) sets one of `names`: that one wins, and is changed where the
|
|
262
|
+
* server is started. */
|
|
263
|
+
notServers(names) {
|
|
264
|
+
const held = names.filter((name) => this.env[name]);
|
|
265
|
+
if (held.length)
|
|
266
|
+
throw new ApiError("key_set_by_server", `This server is started with ${held.join(" and ")}: change it where the server is started.`, { details: { fields: held } });
|
|
267
|
+
}
|
|
268
|
+
write(fields, checks) {
|
|
269
|
+
// On disk, the file and then its directory, before the 204: a crash after it neither loses a saved key nor brings
|
|
270
|
+
// back a forgotten one.
|
|
271
|
+
writeDurableSync(this.file, `${JSON.stringify({ v: 1, fields, checks }, null, 2)}\n`);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import type { InputIssue } from "./errors.js";
|
|
2
|
+
import { type HarnessId } from "./harness.js";
|
|
3
|
+
/**
|
|
4
|
+
* The capabilities a pack or a revision may grant, by name: the tools the kernel gives a run, bound from serve's closed
|
|
5
|
+
* table (tools.ts) and named the same on every harness that runs them. `web_search` and `web_fetch` resolve to a
|
|
6
|
+
* provider (PROVIDERS); the rest are the kernel's own. Not capabilities: `fetch_page` (legacy: web_fetch's guarded fetch
|
|
7
|
+
* with no provider behind it), the workflow call nodes' `pdf_pages` and `llm` (a workflow's call node names them, a grant
|
|
8
|
+
* never does), and a catalog's tools (`monid.*`, `mcp:<server>/<tool>`: catalog tools, which their catalog grants).
|
|
9
|
+
*/
|
|
10
|
+
export declare const CAPABILITIES: readonly ["read", "write", "edit", "web_search", "web_fetch", "browser", "ask_person"];
|
|
11
|
+
export type Capability = (typeof CAPABILITIES)[number];
|
|
12
|
+
/** The providers a user may pick for each capability that has a choice, its default first: `auto`, the native search
|
|
13
|
+
* where there is one (never on claude-agent, where Claude's own search is picked as `native`), else Parallel where the
|
|
14
|
+
* server holds its key, else keyless Exa; `native`, the harness's own tool or its model provider's hosted one, and
|
|
15
|
+
* nothing else; `exa-keyless`, Exa's public MCP endpoint, no key; `kernel`, the guarded direct fetch; `parallel`,
|
|
16
|
+
* Parallel's Search and Extract APIs on PARALLEL_API_KEY; `off`, web_search turned off: nothing is searched, and an
|
|
17
|
+
* agent naming it is refused until it is turned on again. */
|
|
18
|
+
export declare const PROVIDERS: Readonly<{
|
|
19
|
+
readonly web_search: readonly ["auto", "native", "exa-keyless", "parallel", "off"];
|
|
20
|
+
readonly web_fetch: readonly ["kernel", "parallel"];
|
|
21
|
+
}>;
|
|
22
|
+
export type Pickable = keyof typeof PROVIDERS;
|
|
23
|
+
export declare const PICKABLE: Pickable[];
|
|
24
|
+
/** Older names a revision may still grant, and the capability each one is: `fetch_page` runs web_fetch, under its own
|
|
25
|
+
* name, and resolves as web_fetch does. */
|
|
26
|
+
export declare const LEGACY_NAMES: Readonly<Record<string, Pickable>>;
|
|
27
|
+
/** The capability a granted name runs: its legacy target, else itself. */
|
|
28
|
+
export declare const capabilityOf: (name: string) => string;
|
|
29
|
+
/** One capability's settings: its provider. `permission` is reserved for the tool gate, and refused until it lands. */
|
|
30
|
+
export type ToolSetting = {
|
|
31
|
+
provider?: string;
|
|
32
|
+
};
|
|
33
|
+
/** The settings of each capability that has a choice: the server's (`/v2/settings/tools`) and an agent's own
|
|
34
|
+
* (`definition.tool_settings`), one shape. */
|
|
35
|
+
export type ToolSettingsMap = Partial<Record<Pickable, ToolSetting>>;
|
|
36
|
+
/** What a capability resolves to on a run: the native tool, the kernel's own, keyless Exa, Parallel, or why not. */
|
|
37
|
+
export type Resolution = "native" | "kernel" | "exa-keyless" | "parallel" | `unavailable: ${string}`;
|
|
38
|
+
export declare const NO_PARALLEL_KEY: Resolution;
|
|
39
|
+
/** web_search with `off` picked: no search leaves the server. */
|
|
40
|
+
export declare const SEARCH_OFF: Resolution;
|
|
41
|
+
/** The model providers whose hosted web search pi's web_search asks (hosted-search.ts), by pi-ai's provider id. */
|
|
42
|
+
export declare const HOSTED_SEARCH_PROVIDERS: readonly string[];
|
|
43
|
+
/** A run's facts its capabilities resolve from. */
|
|
44
|
+
export type ResolveInput = {
|
|
45
|
+
harness: string;
|
|
46
|
+
/** The run's model as named, `provider/model-id`: the revision's, else the host's for its harness (hostModel: a tier
|
|
47
|
+
* variable or AGENT_MODEL it runs, else a model key's default). */
|
|
48
|
+
model?: string;
|
|
49
|
+
/** Its model requests go through a gateway (AGENT_MODEL_BASE_URL), not the provider's own API (pi's). */
|
|
50
|
+
gateway: boolean;
|
|
51
|
+
/** The agent's pick, then the server's; neither, the capability's default. */
|
|
52
|
+
override?: string;
|
|
53
|
+
pick?: string;
|
|
54
|
+
/** The server holds PARALLEL_API_KEY; `parallelKeyFrom`, where from: its own environment, or saved on Tool keys. */
|
|
55
|
+
parallelKey: boolean;
|
|
56
|
+
parallelKeyFrom?: "server" | "saved";
|
|
57
|
+
/** The run has a spend cap: Codex's own search sends a request with no input bound, which a cap cannot admit. */
|
|
58
|
+
capped?: boolean;
|
|
59
|
+
/** The harness's model requests go through OpenRouter (model.ts' viaOpenRouter), where its own search does not run. */
|
|
60
|
+
openRouter?: boolean;
|
|
61
|
+
};
|
|
62
|
+
/** What `capability` resolves to on a run of `input`, and why in a plain sentence (capabilities' `why`): one rule, so
|
|
63
|
+
* the two never disagree. */
|
|
64
|
+
export declare function explainCapability(capability: Pickable, input: ResolveInput): {
|
|
65
|
+
resolves: Resolution;
|
|
66
|
+
why: string;
|
|
67
|
+
};
|
|
68
|
+
/** What `capability` resolves to on a run of `input`. */
|
|
69
|
+
export declare const resolveCapability: (capability: Pickable, input: ResolveInput) => Resolution;
|
|
70
|
+
export declare const isUnavailable: (resolution: Resolution | undefined) => resolution is `unavailable: ${string}`;
|
|
71
|
+
/** Why a resolution is unavailable: its words after "unavailable: " (any other resolution as it is). */
|
|
72
|
+
export declare const whyUnavailable: (resolution: string) => string;
|
|
73
|
+
/** Each pickable capability on each harness under the server's `settings` and an agent's `overrides`, on `model`
|
|
74
|
+
* (default each harness's host model, the one a run that names none runs on: hostModel): what it resolves to and why, as
|
|
75
|
+
* capabilities and the tool catalog show them. */
|
|
76
|
+
export declare function explainsView(env: NodeJS.ProcessEnv, settings: ToolSettingsMap, overrides?: ToolSettingsMap, model?: string): Record<Pickable, {
|
|
77
|
+
resolves: Record<HarnessId, Resolution>;
|
|
78
|
+
why: Record<HarnessId, string>;
|
|
79
|
+
}>;
|
|
80
|
+
/** What a run is told: each pickable capability its revision names, resolved; with web_search native on pi, the model
|
|
81
|
+
* its search asks (the one the resolution read). */
|
|
82
|
+
export type Plane = Partial<Record<Pickable, Resolution>> & {
|
|
83
|
+
model?: string;
|
|
84
|
+
};
|
|
85
|
+
/** The facts of a pinned revision its run's tools resolve from. */
|
|
86
|
+
export type Tooling = {
|
|
87
|
+
harness?: string;
|
|
88
|
+
tools: readonly string[];
|
|
89
|
+
model?: string;
|
|
90
|
+
overrides?: ToolSettingsMap;
|
|
91
|
+
workflow?: true;
|
|
92
|
+
};
|
|
93
|
+
/** The run's process's description of its tools' providers: JSON of its Plane. */
|
|
94
|
+
export declare const TOOL_PLANE_ENV = "AGENTRUN_SERVE_TOOL_PLANE";
|
|
95
|
+
/** The Plane of a run of `tooling`, in the server's `env` (with its secrets) under its `settings`. */
|
|
96
|
+
export declare function planeFor(env: NodeJS.ProcessEnv, tooling: Tooling, settings: ToolSettingsMap, { capped }?: {
|
|
97
|
+
capped?: boolean;
|
|
98
|
+
}): Plane;
|
|
99
|
+
/** A run's kept Plane at a later launch: as it was, but Parallel where the server no longer holds its key, which is
|
|
100
|
+
* unavailable, never another provider. */
|
|
101
|
+
export declare function recheckPlane(plane: Plane, env: NodeJS.ProcessEnv): Plane;
|
|
102
|
+
/** The Plane the server handed this run's process; empty when it handed none. */
|
|
103
|
+
export declare function planeOf(env: NodeJS.ProcessEnv): Plane;
|
|
104
|
+
/** Whether a run is handed Parallel's key: one of its capabilities resolves to Parallel. */
|
|
105
|
+
export declare const handsParallel: (plane: Plane) => boolean;
|
|
106
|
+
/** What a save of `permission` answers until the tool gate lands, so no one keeps a deny that nothing enforces. */
|
|
107
|
+
export declare const NOT_YET = "permissions arrive with the tool gate";
|
|
108
|
+
/** The issues of `value` as a settings map, its fields under `at` (none: a body's own): each capability that has a
|
|
109
|
+
* choice to `{provider?}`, the provider one offered for it. */
|
|
110
|
+
export declare function settingsIssues(value: unknown, at?: string): InputIssue[];
|
|
111
|
+
/** `map` with each capability's provider, its default where none is picked. */
|
|
112
|
+
export declare const withDefaults: (map: ToolSettingsMap) => Record<Pickable, {
|
|
113
|
+
provider: string;
|
|
114
|
+
}>;
|
|
115
|
+
/** The server's tool settings, beside the agent store in its data directory: not a secret, and not in store.sqlite,
|
|
116
|
+
* which runs hold open. Read once at the start, written whole and durably (0600) at each PUT; a missing file is every
|
|
117
|
+
* default, and so is one it cannot read, which it says in one line. */
|
|
118
|
+
export declare class ToolSettings {
|
|
119
|
+
private readonly dir;
|
|
120
|
+
static readonly FILE = "tool-settings.json";
|
|
121
|
+
private current;
|
|
122
|
+
constructor(dir: string, warn?: (line: string) => void);
|
|
123
|
+
get(): ToolSettingsMap;
|
|
124
|
+
/** Replaces the settings: a capability `map` leaves out takes its default. Durable before it returns. */
|
|
125
|
+
put(map: ToolSettingsMap): ToolSettingsMap;
|
|
126
|
+
}
|
|
127
|
+
/** GET /v2/agents/{id}'s `tools`: each tool its current revision grants, in `order` (capabilities.tools'), and for one
|
|
128
|
+
* with a provider choice the provider in force and where it came from (the agent's own settings, the server's, or the
|
|
129
|
+
* default), the one that applies when the agent sets none (the server's), and what it resolves to on the agent's
|
|
130
|
+
* harness and model. A tool with no choice is its name alone. */
|
|
131
|
+
export declare function agentTools(env: NodeJS.ProcessEnv, settings: ToolSettingsMap, agent: Tooling, order: readonly string[]): ({
|
|
132
|
+
name: string;
|
|
133
|
+
provider?: undefined;
|
|
134
|
+
provider_from?: undefined;
|
|
135
|
+
default_provider?: undefined;
|
|
136
|
+
resolved?: undefined;
|
|
137
|
+
} | {
|
|
138
|
+
name: string;
|
|
139
|
+
provider: string;
|
|
140
|
+
provider_from: string;
|
|
141
|
+
default_provider: string;
|
|
142
|
+
resolved: Resolution;
|
|
143
|
+
})[];
|