@parcha/agentrun-serve 0.0.0-stage → 0.1.0-beta.30
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 +748 -0
- package/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +2190 -2
- package/dist/adapters.d.ts +234 -0
- package/dist/adapters.js +585 -0
- package/dist/agents.d.ts +130 -0
- package/dist/agents.js +308 -0
- package/dist/app.d.ts +7 -0
- package/dist/app.js +384 -0
- package/dist/background.d.ts +28 -0
- package/dist/background.js +376 -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-egress.d.ts +98 -0
- package/dist/box-egress.js +259 -0
- package/dist/box-image.d.ts +98 -0
- package/dist/box-image.js +285 -0
- package/dist/box-relay-vm.d.ts +80 -0
- package/dist/box-relay-vm.js +389 -0
- package/dist/box-relay.d.ts +45 -0
- package/dist/box-relay.js +227 -0
- package/dist/boxes.d.ts +72 -0
- package/dist/boxes.js +189 -0
- package/dist/browser-cost.d.ts +41 -0
- package/dist/browser-cost.js +158 -0
- package/dist/cap.d.ts +332 -0
- package/dist/cap.js +992 -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 +35 -0
- package/dist/coding-tools.js +87 -0
- package/dist/console/THIRD-PARTY-NOTICES.txt +1721 -0
- package/dist/console/assets/index-34jfpIbQ.js +481 -0
- package/dist/console/assets/index-DUHbWcIP.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/content-filter.d.ts +7 -0
- package/dist/content-filter.js +23 -0
- package/dist/daytona-api.d.ts +21 -0
- package/dist/daytona-api.js +101 -0
- package/dist/decision-rows.d.ts +19 -0
- package/dist/decision-rows.js +123 -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 +74 -0
- package/dist/errors.js +69 -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 +65 -0
- package/dist/files.js +158 -0
- package/dist/grade.d.ts +93 -0
- package/dist/grade.js +328 -0
- package/dist/graph-served.d.ts +23 -0
- package/dist/graph-served.js +75 -0
- package/dist/graph-view.d.ts +102 -0
- package/dist/graph-view.js +219 -0
- package/dist/harness-app.d.ts +40 -0
- package/dist/harness-app.js +708 -0
- package/dist/harness-opencode/adapter.d.ts +45 -0
- package/dist/harness-opencode/adapter.js +272 -0
- package/dist/harness-opencode/binary.d.ts +18 -0
- package/dist/harness-opencode/binary.js +87 -0
- package/dist/harness-opencode/config.d.ts +24 -0
- package/dist/harness-opencode/config.js +61 -0
- package/dist/harness-opencode/harness.d.ts +77 -0
- package/dist/harness-opencode/harness.js +620 -0
- package/dist/harness-opencode/host/mcp.d.ts +40 -0
- package/dist/harness-opencode/host/mcp.js +208 -0
- package/dist/harness-opencode/host/policy.d.ts +71 -0
- package/dist/harness-opencode/host/policy.js +419 -0
- package/dist/harness-opencode/host/server.d.ts +55 -0
- package/dist/harness-opencode/host/server.js +165 -0
- package/dist/harness-opencode/index.d.ts +9 -0
- package/dist/harness-opencode/index.js +6 -0
- package/dist/harness-opencode/verify.d.ts +32 -0
- package/dist/harness-opencode/verify.js +75 -0
- package/dist/harness-opencode/versions.d.ts +33 -0
- package/dist/harness-opencode/versions.js +64 -0
- package/dist/harness.d.ts +56 -0
- package/dist/harness.js +77 -0
- package/dist/home-path.d.ts +27 -0
- package/dist/home-path.js +78 -0
- package/dist/host-tools.d.ts +30 -0
- package/dist/host-tools.js +154 -0
- package/dist/host.d.ts +39 -0
- package/dist/host.js +85 -0
- package/dist/hosted-search.d.ts +27 -0
- package/dist/hosted-search.js +133 -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 +1222 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +6 -0
- package/dist/key-check.d.ts +37 -0
- package/dist/key-check.js +112 -0
- package/dist/key-refusal.d.ts +51 -0
- package/dist/key-refusal.js +191 -0
- package/dist/learn/check.d.ts +108 -0
- package/dist/learn/check.js +277 -0
- package/dist/learn/grade.d.ts +80 -0
- package/dist/learn/grade.js +445 -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 +147 -0
- package/dist/learn/reflect.d.ts +49 -0
- package/dist/learn/reflect.js +213 -0
- package/dist/learn/secrets.d.ts +18 -0
- package/dist/learn/secrets.js +131 -0
- package/dist/learn/skills.d.ts +97 -0
- package/dist/learn/skills.js +271 -0
- package/dist/learned-workflow.d.ts +59 -0
- package/dist/learned-workflow.js +191 -0
- package/dist/learning-routes.d.ts +196 -0
- package/dist/learning-routes.js +609 -0
- package/dist/learning-run.d.ts +306 -0
- package/dist/learning-run.js +819 -0
- package/dist/learning-words.d.ts +76 -0
- package/dist/learning-words.js +174 -0
- package/dist/learning.d.ts +418 -0
- package/dist/learning.js +946 -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 +118 -0
- package/dist/mcp-servers.js +450 -0
- package/dist/mcp.d.ts +51 -0
- package/dist/mcp.js +392 -0
- package/dist/model.d.ts +186 -0
- package/dist/model.js +485 -0
- package/dist/monid.d.ts +74 -0
- package/dist/monid.js +277 -0
- package/dist/openapi/agentrun-v2.openapi.json +4806 -0
- package/dist/openapi.d.ts +10 -0
- package/dist/openapi.js +1727 -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 +50 -0
- package/dist/paid-calls.js +110 -0
- package/dist/pause.d.ts +70 -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 +69 -0
- package/dist/place.js +137 -0
- package/dist/print.d.ts +20 -0
- package/dist/print.js +29 -0
- package/dist/propose.d.ts +40 -0
- package/dist/propose.js +112 -0
- package/dist/quiet-sqlite-warning.d.ts +1 -0
- package/dist/quiet-sqlite-warning.js +14 -0
- package/dist/request-start.d.ts +22 -0
- package/dist/request-start.js +350 -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 +186 -0
- package/dist/run-box.js +590 -0
- package/dist/run-manifest.d.ts +27 -0
- package/dist/run-manifest.js +60 -0
- package/dist/runnable.d.ts +83 -0
- package/dist/runnable.js +170 -0
- package/dist/runs.d.ts +1062 -0
- package/dist/runs.js +3020 -0
- package/dist/secret-cut.d.ts +27 -0
- package/dist/secret-cut.js +109 -0
- package/dist/secrets.d.ts +62 -0
- package/dist/secrets.js +158 -0
- package/dist/server-lock.d.ts +44 -0
- package/dist/server-lock.js +140 -0
- package/dist/server.d.ts +722 -0
- package/dist/server.js +2118 -0
- package/dist/sessions.d.ts +4 -0
- package/dist/sessions.js +105 -0
- package/dist/sign-ins.d.ts +99 -0
- package/dist/sign-ins.js +288 -0
- package/dist/skills.d.ts +43 -0
- package/dist/skills.js +96 -0
- package/dist/stats.d.ts +106 -0
- package/dist/stats.js +103 -0
- package/dist/tool-gate.d.ts +266 -0
- package/dist/tool-gate.js +554 -0
- package/dist/tool-keys.d.ts +187 -0
- package/dist/tool-keys.js +315 -0
- package/dist/tool-plane.d.ts +228 -0
- package/dist/tool-plane.js +400 -0
- package/dist/tools.d.ts +202 -0
- package/dist/tools.js +372 -0
- package/dist/trigger-secrets.d.ts +32 -0
- package/dist/trigger-secrets.js +143 -0
- package/dist/triggers.d.ts +439 -0
- package/dist/triggers.js +863 -0
- package/dist/turn-end.d.ts +24 -0
- package/dist/turn-end.js +15 -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-lines.d.ts +26 -0
- package/dist/usage-lines.js +28 -0
- package/dist/usage.d.ts +29 -0
- package/dist/usage.js +58 -0
- package/dist/validate.d.ts +57 -0
- package/dist/validate.js +184 -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 +189 -0
- package/dist/webhooks.js +503 -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 +100 -4
- package/skills/agentrun-serve/SKILL.md +128 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { DecisionProvider } from "@parcha/agentrun-dsl";
|
|
2
|
+
export declare const JEV_KEY_ENV = "TYPESAFE_API_KEY";
|
|
3
|
+
export declare const JEV_OPENROUTER_KEY_ENV = "OPENROUTER_API_KEY";
|
|
4
|
+
export declare const PARALLEL_KEY_ENV = "PARALLEL_API_KEY";
|
|
5
|
+
/** The provider a decision node that names none is answered by. */
|
|
6
|
+
export declare const DEFAULT_DECISION_PROVIDER = "jev";
|
|
7
|
+
/** The adapter a workflow's typed questions run through. */
|
|
8
|
+
export declare const DECISION_ADAPTER = "runJudge";
|
|
9
|
+
/** Set on a run's process the server hands decision keys: the descriptor's number, never a key. The keys come as one
|
|
10
|
+
* JSON object of variable name to value, on the first descriptor after the process's stdio and its secrets pipe:
|
|
11
|
+
* macOS aborts the parent of a spawn with a pipe at 16 or above. */
|
|
12
|
+
export declare const DECISION_KEY_FD_ENV = "AGENTRUN_SERVE_DECISION_KEY_FD";
|
|
13
|
+
/** Under --faux only: a module whose default export is the fetch Jev's runner sends through, in place of TypeSafe's
|
|
14
|
+
* API (the tests' fake). */
|
|
15
|
+
export declare const FAUX_JEV_ENV = "AGENTRUN_SERVE_FAUX_JEV";
|
|
16
|
+
/** Under --faux only: a module whose default export is the fetch the Parallel provider sends through, in place of
|
|
17
|
+
* Parallel's API (the tests' fake). */
|
|
18
|
+
export declare const FAUX_PARALLEL_ENV = "AGENTRUN_SERVE_FAUX_PARALLEL";
|
|
19
|
+
/** Under `faux` only (startServe's `fauxOpenrouter`): a module whose default export is the fetch the OpenRouter decisions
|
|
20
|
+
* provider sends through, in place of OpenRouter's System One API (`@parcha/agentrun-decisions/testing/faux-system-one`
|
|
21
|
+
* is one). */
|
|
22
|
+
export declare const FAUX_OPENROUTER_ENV = "AGENTRUN_SERVE_FAUX_OPENROUTER";
|
|
23
|
+
/** One decision provider as capabilities lists it: whether this server runs it, when not why, and what to know when
|
|
24
|
+
* it runs in a way the operator should hear of. */
|
|
25
|
+
export type DecisionOffer = {
|
|
26
|
+
id: "jev" | "parallel" | "openrouter";
|
|
27
|
+
available: boolean;
|
|
28
|
+
reason?: string;
|
|
29
|
+
note?: string;
|
|
30
|
+
};
|
|
31
|
+
/** The model gateway's key (model.ts), Jev's on the OpenRouter route when that gateway is OpenRouter. */
|
|
32
|
+
export declare const JEV_GATEWAY_KEY_ENV = "AGENT_MODEL_API_KEY";
|
|
33
|
+
/** The key Jev runs on here and its route: TypeSafe's API when its key is set, else OpenRouter's System One when an
|
|
34
|
+
* OpenRouter key is (openRouterKeyEnv). */
|
|
35
|
+
export declare function jevKey(env: NodeJS.ProcessEnv): {
|
|
36
|
+
route: "typesafe" | "openrouter";
|
|
37
|
+
key: string;
|
|
38
|
+
} | undefined;
|
|
39
|
+
/** How this server reaches Jev, when it does. */
|
|
40
|
+
export declare const jevRoute: (env: NodeJS.ProcessEnv) => "typesafe" | "openrouter" | undefined;
|
|
41
|
+
/** The keys the server hands a workflow run's process, by name: Jev's, as TYPESAFE_API_KEY or, on the OpenRouter route,
|
|
42
|
+
* as OPENROUTER_API_KEY whichever variable holds it; an OpenRouter key (openRouterKeyEnv) as OPENROUTER_API_KEY for
|
|
43
|
+
* OpenRouter's Decisions models, on either Jev route; and Parallel's. */
|
|
44
|
+
export declare function decisionKeysOf(env: NodeJS.ProcessEnv): Record<string, string>;
|
|
45
|
+
/** What a run's decision keys are for: the providers of its workflow's typed questions (providersNamed), and whether one
|
|
46
|
+
* of its web tools resolves to Parallel (tool-plane.ts' handsParallel), whose client reads Parallel's key (web-fetch.ts). */
|
|
47
|
+
export type DecisionNeeds = {
|
|
48
|
+
providers: readonly string[];
|
|
49
|
+
parallelWeb: boolean;
|
|
50
|
+
};
|
|
51
|
+
/** The decision keys the server hands a run's process for `needs`, of those it holds (decisionKeysOf): Jev's by its route
|
|
52
|
+
* (TypeSafe's, or OpenRouter's), OpenRouter's for an OpenRouter decision node, Parallel's for a Parallel one or for a
|
|
53
|
+
* web tool that resolves to Parallel. None else: a run with no decision node and no web tool on Parallel gets no
|
|
54
|
+
* descriptor at all. */
|
|
55
|
+
export declare function decisionKeysFor(env: NodeJS.ProcessEnv, needs: DecisionNeeds): Record<string, string>;
|
|
56
|
+
/** Why Jev does not run here, naming the variable to set. */
|
|
57
|
+
export declare const jevMissing = "This server's environment does not set TYPESAFE_API_KEY (or, for Jev through OpenRouter, OPENROUTER_API_KEY, or AGENT_MODEL_API_KEY with AGENT_MODEL_BASE_URL on openrouter.ai), which a workflow's judge, pick, sift, route and ask nodes need.";
|
|
58
|
+
/** Why Parallel does not run here, naming the variable to set. */
|
|
59
|
+
export declare const parallelMissing = "This server's environment does not set PARALLEL_API_KEY, which a decision node naming the provider \"parallel\" needs.";
|
|
60
|
+
/** Why the OpenRouter route is worth a note, naming the variable Jev runs on: its key is also the model gateway's, which
|
|
61
|
+
* a run's process holds. */
|
|
62
|
+
export declare const jevGatewayNote: (env: NodeJS.ProcessEnv) => string;
|
|
63
|
+
/** Why OpenRouter's decision models do not run here, naming the variable to set. */
|
|
64
|
+
export declare const openrouterMissing = "This server's environment does not set OPENROUTER_API_KEY (or AGENT_MODEL_API_KEY with AGENT_MODEL_BASE_URL on openrouter.ai), which a decision node naming the provider \"openrouter\" needs.";
|
|
65
|
+
/** What to know of OpenRouter's decision models here: the key they run on, which a run's process holds as the model
|
|
66
|
+
* gateway's, and that images go only to a model the catalog lists with image input, untested live. */
|
|
67
|
+
export declare const openrouterNote: (env: NodeJS.ProcessEnv) => string;
|
|
68
|
+
/** What this server offers of each decision provider. */
|
|
69
|
+
export declare function decisionsOf(env: NodeJS.ProcessEnv): DecisionOffer[];
|
|
70
|
+
/** Why provider `id` does not run here and the variables that would make it run; undefined when it runs, and no `needs`
|
|
71
|
+
* for a provider this server does not have at all. */
|
|
72
|
+
export declare function providerMissing(env: NodeJS.ProcessEnv, id: string): {
|
|
73
|
+
message: string;
|
|
74
|
+
needs?: string[];
|
|
75
|
+
} | undefined;
|
|
76
|
+
/** The providers a workflow's typed questions are answered by (`nodes` from workflowNodes): each decision node's and
|
|
77
|
+
* `ask` predicate's own, else the default, as is a generative node's `verify`. */
|
|
78
|
+
export declare function providersNamed(nodes: readonly Record<string, unknown>[]): string[];
|
|
79
|
+
/** The keys the server handed the run's process, by name: read at the first call and the descriptor closed, and the
|
|
80
|
+
* same object at every later one (the decision providers' and the web tools'), so the descriptor is read and closed once
|
|
81
|
+
* whoever asks first. Empty when none were handed, or when the first read failed. */
|
|
82
|
+
export declare function handedKeys(env: NodeJS.ProcessEnv): Record<string, string>;
|
|
83
|
+
/** Under --faux only: the fetch the module `env[name]` names, in place of a provider's API (the tests' fake). */
|
|
84
|
+
export declare const fauxFetch: (env: NodeJS.ProcessEnv, name: string) => Promise<typeof fetch | undefined>;
|
|
85
|
+
/** In a run's process: the decision providers its workflow's typed questions are answered by, on the keys the server
|
|
86
|
+
* handed it (Jev's, Parallel's), and the one a node that names none gets; undefined when it handed none. Called once per
|
|
87
|
+
* process, on the keys handedKeys read once for it and the web tools alike. The run's judge (`judgeFromProviders`) and its
|
|
88
|
+
* checks before any node runs take this one registry, so a node's provider and timeoutMs hold, and a node naming a
|
|
89
|
+
* provider it lacks is refused before the run instead of being asked of another. Each provider sends a request once: one that fails after it
|
|
90
|
+
* was sent may have been answered and billed, so the decision escalates as interrupted instead of being asked again. */
|
|
91
|
+
export declare function decisionProvidersOf(env: NodeJS.ProcessEnv): Promise<{
|
|
92
|
+
providers: Record<string, DecisionProvider>;
|
|
93
|
+
default: string;
|
|
94
|
+
} | undefined>;
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
// Decision providers: the models a workflow's judge, pick, sift, route and ask nodes ask, through the DSL's `runJudge`.
|
|
2
|
+
// This server runs three, each when its environment names the provider's key: Jev (TypeSafe's System One), on
|
|
3
|
+
// TYPESAFE_API_KEY (the route to use), or for Jev through OpenRouter OPENROUTER_API_KEY, else an OpenRouter model
|
|
4
|
+
// gateway's AGENT_MODEL_API_KEY; Parallel Decisions, on PARALLEL_API_KEY; and OpenRouter's Decisions models, on the
|
|
5
|
+
// same OpenRouter key Jev's OpenRouter route reads. A node names its provider (`provider: "parallel"`); one that names
|
|
6
|
+
// none is answered by Jev.
|
|
7
|
+
//
|
|
8
|
+
// The server chooses the keys a run needs (decisionKeysFor) and hands them over once, by name, on an inherited pipe
|
|
9
|
+
// (`DECISION_KEY_FD_ENV` names it), at each launch of the run: its workflow's decision providers' keys, and Parallel's
|
|
10
|
+
// where one of its web tools resolves to Parallel (tool-plane.ts); a run that needs none gets no pipe. The run's process
|
|
11
|
+
// reads them once (handedKeys) into its providers and the web tools' Parallel client (web-fetch.ts), and nowhere else;
|
|
12
|
+
// no provider reads a key from the environment. The TypeSafe and Parallel keys never enter a run's environment, which
|
|
13
|
+
// the run's tools and its model's provider read (`ToolHost.env`, a call node's effect): the server drops the variables
|
|
14
|
+
// from the run's process. On the OpenRouter route the Jev key is also the model gateway's key, which the run's process
|
|
15
|
+
// holds for its model nodes.
|
|
16
|
+
import { closeSync, readFileSync } from "node:fs";
|
|
17
|
+
import { pathToFileURL } from "node:url";
|
|
18
|
+
import { FAUX_ENV } from "./model.js";
|
|
19
|
+
export const JEV_KEY_ENV = "TYPESAFE_API_KEY";
|
|
20
|
+
export const JEV_OPENROUTER_KEY_ENV = "OPENROUTER_API_KEY";
|
|
21
|
+
export const PARALLEL_KEY_ENV = "PARALLEL_API_KEY";
|
|
22
|
+
/** The provider a decision node that names none is answered by. */
|
|
23
|
+
export const DEFAULT_DECISION_PROVIDER = "jev";
|
|
24
|
+
/** The adapter a workflow's typed questions run through. */
|
|
25
|
+
export const DECISION_ADAPTER = "runJudge";
|
|
26
|
+
/** Set on a run's process the server hands decision keys: the descriptor's number, never a key. The keys come as one
|
|
27
|
+
* JSON object of variable name to value, on the first descriptor after the process's stdio and its secrets pipe:
|
|
28
|
+
* macOS aborts the parent of a spawn with a pipe at 16 or above. */
|
|
29
|
+
export const DECISION_KEY_FD_ENV = "AGENTRUN_SERVE_DECISION_KEY_FD";
|
|
30
|
+
/** Under --faux only: a module whose default export is the fetch Jev's runner sends through, in place of TypeSafe's
|
|
31
|
+
* API (the tests' fake). */
|
|
32
|
+
export const FAUX_JEV_ENV = "AGENTRUN_SERVE_FAUX_JEV";
|
|
33
|
+
/** Under --faux only: a module whose default export is the fetch the Parallel provider sends through, in place of
|
|
34
|
+
* Parallel's API (the tests' fake). */
|
|
35
|
+
export const FAUX_PARALLEL_ENV = "AGENTRUN_SERVE_FAUX_PARALLEL";
|
|
36
|
+
/** Under `faux` only (startServe's `fauxOpenrouter`): a module whose default export is the fetch the OpenRouter decisions
|
|
37
|
+
* provider sends through, in place of OpenRouter's System One API (`@parcha/agentrun-decisions/testing/faux-system-one`
|
|
38
|
+
* is one). */
|
|
39
|
+
export const FAUX_OPENROUTER_ENV = "AGENTRUN_SERVE_FAUX_OPENROUTER";
|
|
40
|
+
const isSet = (value) => typeof value === "string" && value.trim() !== "";
|
|
41
|
+
/** The model gateway's key (model.ts), Jev's on the OpenRouter route when that gateway is OpenRouter. */
|
|
42
|
+
export const JEV_GATEWAY_KEY_ENV = "AGENT_MODEL_API_KEY";
|
|
43
|
+
/** The variable Jev's OpenRouter key is in: OPENROUTER_API_KEY, else the model gateway's key when AGENT_MODEL_BASE_URL's
|
|
44
|
+
* host is exactly openrouter.ai. Jev sends it to openrouter.ai, so another host's key never goes there. */
|
|
45
|
+
function openRouterKeyEnv(env) {
|
|
46
|
+
if (isSet(env[JEV_OPENROUTER_KEY_ENV]))
|
|
47
|
+
return JEV_OPENROUTER_KEY_ENV;
|
|
48
|
+
const onOpenRouter = URL.parse(env.AGENT_MODEL_BASE_URL ?? "")?.hostname === "openrouter.ai";
|
|
49
|
+
return onOpenRouter && isSet(env[JEV_GATEWAY_KEY_ENV]) ? JEV_GATEWAY_KEY_ENV : undefined;
|
|
50
|
+
}
|
|
51
|
+
/** The key Jev runs on here and its route: TypeSafe's API when its key is set, else OpenRouter's System One when an
|
|
52
|
+
* OpenRouter key is (openRouterKeyEnv). */
|
|
53
|
+
export function jevKey(env) {
|
|
54
|
+
if (isSet(env[JEV_KEY_ENV]))
|
|
55
|
+
return { route: "typesafe", key: env[JEV_KEY_ENV] };
|
|
56
|
+
const name = openRouterKeyEnv(env);
|
|
57
|
+
return name ? { route: "openrouter", key: env[name] } : undefined;
|
|
58
|
+
}
|
|
59
|
+
/** How this server reaches Jev, when it does. */
|
|
60
|
+
export const jevRoute = (env) => jevKey(env)?.route;
|
|
61
|
+
/** The keys the server hands a workflow run's process, by name: Jev's, as TYPESAFE_API_KEY or, on the OpenRouter route,
|
|
62
|
+
* as OPENROUTER_API_KEY whichever variable holds it; an OpenRouter key (openRouterKeyEnv) as OPENROUTER_API_KEY for
|
|
63
|
+
* OpenRouter's Decisions models, on either Jev route; and Parallel's. */
|
|
64
|
+
export function decisionKeysOf(env) {
|
|
65
|
+
const jev = jevKey(env);
|
|
66
|
+
const openrouter = openRouterKeyEnv(env);
|
|
67
|
+
return {
|
|
68
|
+
...(jev ? { [jev.route === "typesafe" ? JEV_KEY_ENV : JEV_OPENROUTER_KEY_ENV]: jev.key } : {}),
|
|
69
|
+
...(openrouter ? { [JEV_OPENROUTER_KEY_ENV]: env[openrouter] } : {}),
|
|
70
|
+
...(isSet(env[PARALLEL_KEY_ENV]) ? { [PARALLEL_KEY_ENV]: env[PARALLEL_KEY_ENV] } : {}),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/** The decision keys the server hands a run's process for `needs`, of those it holds (decisionKeysOf): Jev's by its route
|
|
74
|
+
* (TypeSafe's, or OpenRouter's), OpenRouter's for an OpenRouter decision node, Parallel's for a Parallel one or for a
|
|
75
|
+
* web tool that resolves to Parallel. None else: a run with no decision node and no web tool on Parallel gets no
|
|
76
|
+
* descriptor at all. */
|
|
77
|
+
export function decisionKeysFor(env, needs) {
|
|
78
|
+
const names = new Set();
|
|
79
|
+
for (const id of needs.providers) {
|
|
80
|
+
const route = id === DEFAULT_DECISION_PROVIDER ? jevRoute(env) : undefined;
|
|
81
|
+
if (route)
|
|
82
|
+
names.add(route === "typesafe" ? JEV_KEY_ENV : JEV_OPENROUTER_KEY_ENV);
|
|
83
|
+
if (id === "openrouter")
|
|
84
|
+
names.add(JEV_OPENROUTER_KEY_ENV);
|
|
85
|
+
if (id === "parallel")
|
|
86
|
+
names.add(PARALLEL_KEY_ENV);
|
|
87
|
+
}
|
|
88
|
+
if (needs.parallelWeb)
|
|
89
|
+
names.add(PARALLEL_KEY_ENV);
|
|
90
|
+
return Object.fromEntries(Object.entries(decisionKeysOf(env)).filter(([name]) => names.has(name)));
|
|
91
|
+
}
|
|
92
|
+
/** Why Jev does not run here, naming the variable to set. */
|
|
93
|
+
export const jevMissing = `This server's environment does not set ${JEV_KEY_ENV} (or, for Jev through OpenRouter, ${JEV_OPENROUTER_KEY_ENV}, or ${JEV_GATEWAY_KEY_ENV} with AGENT_MODEL_BASE_URL on openrouter.ai), which a workflow's judge, pick, sift, route and ask nodes need.`;
|
|
94
|
+
/** Why Parallel does not run here, naming the variable to set. */
|
|
95
|
+
export const parallelMissing = `This server's environment does not set ${PARALLEL_KEY_ENV}, which a decision node naming the provider "parallel" needs.`;
|
|
96
|
+
/** Why the OpenRouter route is worth a note, naming the variable Jev runs on: its key is also the model gateway's, which
|
|
97
|
+
* a run's process holds. */
|
|
98
|
+
export const jevGatewayNote = (env) => `Jev runs on ${openRouterKeyEnv(env)}, the model gateway key on this server, which a run's processes hold in their environment for its model nodes. Set ${JEV_KEY_ENV} to keep the decision key out of them.`;
|
|
99
|
+
/** Why OpenRouter's decision models do not run here, naming the variable to set. */
|
|
100
|
+
export const openrouterMissing = `This server's environment does not set ${JEV_OPENROUTER_KEY_ENV} (or ${JEV_GATEWAY_KEY_ENV} with AGENT_MODEL_BASE_URL on openrouter.ai), which a decision node naming the provider "openrouter" needs.`;
|
|
101
|
+
/** What to know of OpenRouter's decision models here: the key they run on, which a run's process holds as the model
|
|
102
|
+
* gateway's, and that images go only to a model the catalog lists with image input, untested live. */
|
|
103
|
+
export const openrouterNote = (env) => `Any OpenRouter Decisions model, named by the node's model (required), on ${openRouterKeyEnv(env)}, the model gateway key on this server, which a run's processes hold in their environment. Images are experimental: sent only to a model OpenRouter's catalog lists with image input.`;
|
|
104
|
+
/** What this server offers of each decision provider. */
|
|
105
|
+
export function decisionsOf(env) {
|
|
106
|
+
const route = jevRoute(env);
|
|
107
|
+
const jev = route === "typesafe" ? { id: "jev", available: true } : route === "openrouter" ? { id: "jev", available: true, note: jevGatewayNote(env) } : { id: "jev", available: false, reason: jevMissing };
|
|
108
|
+
const parallel = isSet(env[PARALLEL_KEY_ENV]) ? { id: "parallel", available: true } : { id: "parallel", available: false, reason: parallelMissing };
|
|
109
|
+
const openrouter = openRouterKeyEnv(env) ? { id: "openrouter", available: true, note: openrouterNote(env) } : { id: "openrouter", available: false, reason: openrouterMissing };
|
|
110
|
+
return [jev, parallel, openrouter];
|
|
111
|
+
}
|
|
112
|
+
/** Why provider `id` does not run here and the variables that would make it run; undefined when it runs, and no `needs`
|
|
113
|
+
* for a provider this server does not have at all. */
|
|
114
|
+
export function providerMissing(env, id) {
|
|
115
|
+
if (id === DEFAULT_DECISION_PROVIDER)
|
|
116
|
+
return jevRoute(env) ? undefined : { message: jevMissing, needs: [JEV_KEY_ENV] };
|
|
117
|
+
if (id === "parallel")
|
|
118
|
+
return isSet(env[PARALLEL_KEY_ENV]) ? undefined : { message: parallelMissing, needs: [PARALLEL_KEY_ENV] };
|
|
119
|
+
if (id === "openrouter")
|
|
120
|
+
return openRouterKeyEnv(env) ? undefined : { message: openrouterMissing, needs: [JEV_OPENROUTER_KEY_ENV] };
|
|
121
|
+
return { message: `This server's decision providers are jev, parallel and openrouter; this workflow also names the provider ${id}.` };
|
|
122
|
+
}
|
|
123
|
+
/** The providers a workflow's typed questions are answered by (`nodes` from workflowNodes): each decision node's and
|
|
124
|
+
* `ask` predicate's own, else the default, as is a generative node's `verify`. */
|
|
125
|
+
export function providersNamed(nodes) {
|
|
126
|
+
const ids = new Set();
|
|
127
|
+
const add = (at) => ids.add(typeof at.provider === "string" ? (at.provider) : DEFAULT_DECISION_PROVIDER);
|
|
128
|
+
for (const node of nodes) {
|
|
129
|
+
if (["judge", "pick", "sift"].includes(node.node) || (node.node === "route" && node.valuePath === undefined))
|
|
130
|
+
add(node);
|
|
131
|
+
for (const predicate of [node.node === "loop" ? node.until : undefined, node.node === "escalate" ? node.when : undefined]) {
|
|
132
|
+
if (predicate?.predicate === "ask")
|
|
133
|
+
add(predicate);
|
|
134
|
+
}
|
|
135
|
+
if (node.verify)
|
|
136
|
+
ids.add(DEFAULT_DECISION_PROVIDER);
|
|
137
|
+
}
|
|
138
|
+
return [...ids];
|
|
139
|
+
}
|
|
140
|
+
let keysHanded;
|
|
141
|
+
/** The keys the server handed the run's process, by name: read at the first call and the descriptor closed, and the
|
|
142
|
+
* same object at every later one (the decision providers' and the web tools'), so the descriptor is read and closed once
|
|
143
|
+
* whoever asks first. Empty when none were handed, or when the first read failed. */
|
|
144
|
+
export function handedKeys(env) {
|
|
145
|
+
if (keysHanded)
|
|
146
|
+
return keysHanded;
|
|
147
|
+
keysHanded = {};
|
|
148
|
+
const fd = Number(env[DECISION_KEY_FD_ENV]);
|
|
149
|
+
if (!Number.isSafeInteger(fd) || fd < 3)
|
|
150
|
+
return keysHanded;
|
|
151
|
+
try {
|
|
152
|
+
const keys = JSON.parse(readFileSync(fd, "utf8"));
|
|
153
|
+
return (keysHanded = Object.fromEntries([JEV_KEY_ENV, JEV_OPENROUTER_KEY_ENV, PARALLEL_KEY_ENV].flatMap((name) => (typeof keys?.[name] === "string" ? [[name, keys[name]]] : []))));
|
|
154
|
+
}
|
|
155
|
+
finally {
|
|
156
|
+
closeSync(fd);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/** Under --faux only: the fetch the module `env[name]` names, in place of a provider's API (the tests' fake). */
|
|
160
|
+
export const fauxFetch = async (env, name) => env[FAUX_ENV] && env[name] ? (await import(pathToFileURL(env[name]).href)).default : undefined;
|
|
161
|
+
/** In a run's process: the decision providers its workflow's typed questions are answered by, on the keys the server
|
|
162
|
+
* handed it (Jev's, Parallel's), and the one a node that names none gets; undefined when it handed none. Called once per
|
|
163
|
+
* process, on the keys handedKeys read once for it and the web tools alike. The run's judge (`judgeFromProviders`) and its
|
|
164
|
+
* checks before any node runs take this one registry, so a node's provider and timeoutMs hold, and a node naming a
|
|
165
|
+
* provider it lacks is refused before the run instead of being asked of another. Each provider sends a request once: one that fails after it
|
|
166
|
+
* was sent may have been answered and billed, so the decision escalates as interrupted instead of being asked again. */
|
|
167
|
+
export async function decisionProvidersOf(env) {
|
|
168
|
+
const handed = handedKeys(env);
|
|
169
|
+
const providers = {};
|
|
170
|
+
const jev = handed[JEV_KEY_ENV] !== undefined ? { apiKey: handed[JEV_KEY_ENV] } : handed[JEV_OPENROUTER_KEY_ENV] !== undefined ? { provider: "openrouter", apiKey: handed[JEV_OPENROUTER_KEY_ENV] } : undefined;
|
|
171
|
+
if (jev) {
|
|
172
|
+
const [{ jevProvider }, faux] = await Promise.all([import("@parcha/agentrun-jev"), fauxFetch(env, FAUX_JEV_ENV)]);
|
|
173
|
+
providers.jev = jevProvider({ ...jev, ...(faux ? { fetch: faux } : {}) });
|
|
174
|
+
}
|
|
175
|
+
if (handed[PARALLEL_KEY_ENV] !== undefined) {
|
|
176
|
+
const [{ parallelProvider }, faux] = await Promise.all([import("@parcha/agentrun-decisions"), fauxFetch(env, FAUX_PARALLEL_ENV)]);
|
|
177
|
+
providers.parallel = parallelProvider({ apiKey: handed[PARALLEL_KEY_ENV], ...(faux ? { fetch: faux } : {}) });
|
|
178
|
+
}
|
|
179
|
+
if (handed[JEV_OPENROUTER_KEY_ENV] !== undefined) {
|
|
180
|
+
const [{ openrouterProvider }, faux] = await Promise.all([import("@parcha/agentrun-decisions"), fauxFetch(env, FAUX_OPENROUTER_ENV)]);
|
|
181
|
+
providers.openrouter = openrouterProvider({ apiKey: handed[JEV_OPENROUTER_KEY_ENV], ...(faux ? { fetch: faux } : {}), app: { title: "AgentRun Server" } });
|
|
182
|
+
}
|
|
183
|
+
return Object.keys(providers).length ? { providers, default: DEFAULT_DECISION_PROVIDER } : undefined;
|
|
184
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type Effort } from "./model.js";
|
|
2
|
+
/** The note each effort adds after the agent's instructions. */
|
|
3
|
+
export declare const EFFORT_GUIDANCE: Readonly<Record<Effort, string>>;
|
|
4
|
+
/** `effort`'s note, or undefined for none (or a value that is not an effort). */
|
|
5
|
+
export declare function effortGuidance(effort: string | undefined): string | undefined;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// A run's effort is its model's thinking level (model.ts thinkingOf) and a short note on how to work, added right after
|
|
2
|
+
// the agent's instructions on every harness (app.ts): one table, one note for each effort. A run with no effort gets no
|
|
3
|
+
// note, and thinks at its agent revision's own thinking level, else the host's default.
|
|
4
|
+
import { EFFORTS } from "./model.js";
|
|
5
|
+
/** The note each effort adds after the agent's instructions. */
|
|
6
|
+
export const EFFORT_GUIDANCE = {
|
|
7
|
+
low: "Answer directly and keep it short. If you need a fact you don't have, or one that may have changed since your training, search once and use what you find. Cite the sources you use. Don't make a plan, don't write extra files, and don't explore past the question. Stop as soon as the question is answered.",
|
|
8
|
+
medium: "Start with a short plan of two to four steps. When you need facts, run your searches in parallel, prefer recent primary sources, and check each key claim against a second, independent source. Cite what you use. Do the work the plan calls for and no more. Write the answer, then check it once against the question: does it answer every part, and is each claim supported? Fix what's missing, then finish.",
|
|
9
|
+
high: "Be thorough. Before you start, break the task into its parts and plan how to cover each one. Work through the parts in order. Where a part needs facts, search widely: run searches in parallel, read the primary sources, and check every important claim against at least two independent sources. When the parts are done, look for gaps, contradictions and claims you haven't checked, and fill them. Then write the full result, with citations. Before you finish, review it once against the original request, point by point, and fix anything missing or wrong.",
|
|
10
|
+
};
|
|
11
|
+
/** `effort`'s note, or undefined for none (or a value that is not an effort). */
|
|
12
|
+
export function effortGuidance(effort) {
|
|
13
|
+
return EFFORTS.includes(effort) ? EFFORT_GUIDANCE[effort] : undefined;
|
|
14
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type Extension } from "@earendil-works/pi-durable";
|
|
2
|
+
/** The environment line on `now`'s day, in UTC. */
|
|
3
|
+
export declare function environmentLine(now?: Date): string;
|
|
4
|
+
/** pi's section of the line, untagged: installed before any other extension, it is the system prompt's first text. */
|
|
5
|
+
export declare const EnvironmentLine: Extension;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// The line every harness's system prompt starts with: today's date, in UTC, and where the run works. A model knows only
|
|
2
|
+
// the date its training ended, so a question about "the latest" release is answered from then unless the run says what
|
|
3
|
+
// day it is. One line for every harness, made as each turn starts, so a run resumed on a later day reads that day: pi's
|
|
4
|
+
// section is rendered again before each model request, and another harness's session is opened with it in each process.
|
|
5
|
+
import { defineExtension, section } from "@earendil-works/pi-durable";
|
|
6
|
+
/** The environment line on `now`'s day, in UTC. */
|
|
7
|
+
export function environmentLine(now = new Date()) {
|
|
8
|
+
return `Today is ${now.toISOString().slice(0, 10)} (UTC). You are running on AgentRun; your workspace is your working directory, and file paths are relative to it.`;
|
|
9
|
+
}
|
|
10
|
+
/** pi's section of the line, untagged: installed before any other extension, it is the system prompt's first text. */
|
|
11
|
+
export const EnvironmentLine = defineExtension({ name: "agentrun-environment", sections: [section("environment", () => environmentLine(), { tag: false })] });
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/** Each code of the closed list, with its one HTTP status. */
|
|
2
|
+
export declare const ERROR_STATUS: {
|
|
3
|
+
readonly bad_request: 400;
|
|
4
|
+
readonly invalid_file_path: 400;
|
|
5
|
+
readonly unauthenticated: 401;
|
|
6
|
+
readonly insufficient_credits: 402;
|
|
7
|
+
readonly spend_cap_reached: 402;
|
|
8
|
+
readonly forbidden: 403;
|
|
9
|
+
readonly system_file_forbidden: 403;
|
|
10
|
+
readonly not_found: 404;
|
|
11
|
+
readonly method_not_allowed: 405;
|
|
12
|
+
readonly agent_exists: 409;
|
|
13
|
+
readonly agent_not_runnable: 409;
|
|
14
|
+
readonly home_busy: 409;
|
|
15
|
+
readonly idempotency_mismatch: 409;
|
|
16
|
+
readonly idempotency_in_progress: 409;
|
|
17
|
+
readonly not_continuable: 409;
|
|
18
|
+
readonly quote_invalid: 409;
|
|
19
|
+
readonly precondition_failed: 412;
|
|
20
|
+
readonly payload_too_large: 413;
|
|
21
|
+
readonly unsupported_media_type: 415;
|
|
22
|
+
readonly range_not_satisfiable: 416;
|
|
23
|
+
readonly input_invalid: 422;
|
|
24
|
+
readonly home_check_failed: 422;
|
|
25
|
+
readonly rate_limited: 429;
|
|
26
|
+
readonly internal: 500;
|
|
27
|
+
readonly unsupported_here: 501;
|
|
28
|
+
readonly unavailable: 503;
|
|
29
|
+
readonly key_set_by_server: 409;
|
|
30
|
+
readonly budget_reached: 409;
|
|
31
|
+
readonly no_sealing_key: 409;
|
|
32
|
+
readonly webhook_off: 409;
|
|
33
|
+
readonly precondition_required: 428;
|
|
34
|
+
readonly auth_required: 422;
|
|
35
|
+
readonly not_mcp: 422;
|
|
36
|
+
readonly upstream_failed: 424;
|
|
37
|
+
readonly store_unreadable: 409;
|
|
38
|
+
readonly sign_in_held: 409;
|
|
39
|
+
};
|
|
40
|
+
export type ErrorCode = keyof typeof ERROR_STATUS;
|
|
41
|
+
export type InputIssue = {
|
|
42
|
+
field: string;
|
|
43
|
+
reason: string;
|
|
44
|
+
message: string;
|
|
45
|
+
expected?: string;
|
|
46
|
+
fix?: string;
|
|
47
|
+
code?: string;
|
|
48
|
+
};
|
|
49
|
+
/** What a refusal carries beside its code and message. */
|
|
50
|
+
export type ErrorExtra = {
|
|
51
|
+
capability?: string;
|
|
52
|
+
fields?: InputIssue[];
|
|
53
|
+
next_action?: Record<string, unknown>;
|
|
54
|
+
details?: Record<string, unknown>;
|
|
55
|
+
retry_after_ms?: number;
|
|
56
|
+
/** A learning note the structural checks refuse: each problem, printable. */
|
|
57
|
+
problems?: readonly unknown[];
|
|
58
|
+
};
|
|
59
|
+
export declare class ApiError extends Error {
|
|
60
|
+
readonly code: ErrorCode;
|
|
61
|
+
readonly status: number;
|
|
62
|
+
readonly extra: ErrorExtra;
|
|
63
|
+
readonly headers: Record<string, string>;
|
|
64
|
+
constructor(code: ErrorCode, message: string, extra?: ErrorExtra, headers?: Record<string, string>);
|
|
65
|
+
body(requestId: string): {
|
|
66
|
+
error: Record<string, unknown>;
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/** A feature this server does not offer: 501 naming its dotted path under `features`. */
|
|
70
|
+
export declare const unsupported: (capability: string, message: string) => ApiError;
|
|
71
|
+
/** `text` as one sentence: it ends in one full stop, whatever it ended in (a box's reason ends in none). */
|
|
72
|
+
export declare const sentence: (text: string) => string;
|
|
73
|
+
/** `422 input_invalid` with each field that is missing or wrong. */
|
|
74
|
+
export declare const invalid: (fields: InputIssue[], message?: string) => ApiError;
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// The /v2 error envelope: `{error: {code, message, retryable, ...}}`, with a code from the contract's closed list and
|
|
2
|
+
// that code's one HTTP status.
|
|
3
|
+
/** Each code of the closed list, with its one HTTP status. */
|
|
4
|
+
export const ERROR_STATUS = {
|
|
5
|
+
bad_request: 400,
|
|
6
|
+
invalid_file_path: 400,
|
|
7
|
+
unauthenticated: 401,
|
|
8
|
+
insufficient_credits: 402,
|
|
9
|
+
spend_cap_reached: 402,
|
|
10
|
+
forbidden: 403,
|
|
11
|
+
system_file_forbidden: 403,
|
|
12
|
+
not_found: 404,
|
|
13
|
+
method_not_allowed: 405,
|
|
14
|
+
agent_exists: 409,
|
|
15
|
+
agent_not_runnable: 409,
|
|
16
|
+
home_busy: 409,
|
|
17
|
+
idempotency_mismatch: 409,
|
|
18
|
+
idempotency_in_progress: 409,
|
|
19
|
+
not_continuable: 409,
|
|
20
|
+
quote_invalid: 409,
|
|
21
|
+
precondition_failed: 412,
|
|
22
|
+
payload_too_large: 413,
|
|
23
|
+
unsupported_media_type: 415,
|
|
24
|
+
range_not_satisfiable: 416,
|
|
25
|
+
input_invalid: 422,
|
|
26
|
+
home_check_failed: 422,
|
|
27
|
+
rate_limited: 429,
|
|
28
|
+
internal: 500,
|
|
29
|
+
unsupported_here: 501,
|
|
30
|
+
unavailable: 503,
|
|
31
|
+
// This server's own, beside the contract's list (openapi.ts marks them): a tool key its launcher sets, a key saved with
|
|
32
|
+
// no seal key to keep it under, a send to a webhook a 410 turned off, a write to a learning note that names no
|
|
33
|
+
// version it read, a remote MCP server that asks for a credential, does not speak MCP, or fails, a saved-servers file
|
|
34
|
+
// that does not read, which is never written over (mcp-servers.ts), a message to a run paused at its cap, which
|
|
35
|
+
// takes one once its cap is raised, and a saved sign-in forgotten while a run holds its save lease (sign-ins.ts).
|
|
36
|
+
key_set_by_server: 409,
|
|
37
|
+
budget_reached: 409,
|
|
38
|
+
no_sealing_key: 409,
|
|
39
|
+
webhook_off: 409,
|
|
40
|
+
precondition_required: 428,
|
|
41
|
+
auth_required: 422,
|
|
42
|
+
not_mcp: 422,
|
|
43
|
+
upstream_failed: 424,
|
|
44
|
+
store_unreadable: 409,
|
|
45
|
+
sign_in_held: 409,
|
|
46
|
+
};
|
|
47
|
+
const RETRYABLE = new Set(["home_busy", "idempotency_in_progress", "rate_limited", "internal", "unavailable"]);
|
|
48
|
+
export class ApiError extends Error {
|
|
49
|
+
code;
|
|
50
|
+
status;
|
|
51
|
+
extra;
|
|
52
|
+
headers;
|
|
53
|
+
constructor(code, message, extra = {}, headers = {}) {
|
|
54
|
+
super(message);
|
|
55
|
+
this.code = code;
|
|
56
|
+
this.status = ERROR_STATUS[code];
|
|
57
|
+
this.extra = extra;
|
|
58
|
+
this.headers = headers;
|
|
59
|
+
}
|
|
60
|
+
body(requestId) {
|
|
61
|
+
return { error: { code: this.code, message: this.message, retryable: RETRYABLE.has(this.code), request_id: requestId, ...this.extra } };
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/** A feature this server does not offer: 501 naming its dotted path under `features`. */
|
|
65
|
+
export const unsupported = (capability, message) => new ApiError("unsupported_here", message, { capability });
|
|
66
|
+
/** `text` as one sentence: it ends in one full stop, whatever it ended in (a box's reason ends in none). */
|
|
67
|
+
export const sentence = (text) => `${text.trimEnd().replace(/[.?!;:,]+$/, "")}.`;
|
|
68
|
+
/** `422 input_invalid` with each field that is missing or wrong. */
|
|
69
|
+
export const invalid = (fields, message = fields[0]?.message ?? "the request is not valid") => new ApiError("input_invalid", message, { fields });
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { LookupFunction } from "node:net";
|
|
2
|
+
import { type Search } from "./web-search.js";
|
|
3
|
+
export declare const EXA_MCP_URL = "https://mcp.exa.ai/mcp";
|
|
4
|
+
export declare const EXA_SEARCH_TOOL = "web_search_exa";
|
|
5
|
+
/** Under `--faux` only: a module whose default export is the fetch Exa's MCP exchange goes through (the tests' fake
|
|
6
|
+
* MCP server), in place of Exa's endpoint. */
|
|
7
|
+
export declare const FAUX_EXA_ENV = "AGENTRUN_SERVE_FAUX_EXA";
|
|
8
|
+
/** What a search answers when Exa's free limit holds after the one retry. Exa's own words name a fix (an API key in
|
|
9
|
+
* its MCP URL) that means nothing to a person here, so they are never passed on. */
|
|
10
|
+
export declare const RATE_LIMITED = "Free web search is rate-limited right now. Try again in a minute, or add a Parallel key in Settings \u2192 Tool keys to search with a key.";
|
|
11
|
+
/** A search Exa refused for its free limit (`retryAfterS`, the wait it named, when it named one) or for the connection
|
|
12
|
+
* (403): a reason another provider may get past, which the caller reads before the model reads `error` alone. */
|
|
13
|
+
export type ExaLimited = {
|
|
14
|
+
error: string;
|
|
15
|
+
limit: "rate_limited";
|
|
16
|
+
retryAfterS?: number;
|
|
17
|
+
} | {
|
|
18
|
+
error: string;
|
|
19
|
+
limit: "connection_refused";
|
|
20
|
+
};
|
|
21
|
+
/** A fetch that reaches hosts over IPv4 alone: each name looked up for family 4 (through `lookup`, default the system
|
|
22
|
+
* resolver) and the connection dialled at the address found, never an IPv6 one. undici loads at the first request, so
|
|
23
|
+
* a run that never searches never loads it; `close` ends the connections. */
|
|
24
|
+
export declare function ipv4Fetch(lookup?: LookupFunction): {
|
|
25
|
+
send: typeof fetch;
|
|
26
|
+
close(): Promise<void>;
|
|
27
|
+
};
|
|
28
|
+
/** `query` searched on Exa's keyless MCP endpoint through `send` (a test's fake; default a fetch over IPv4 alone,
|
|
29
|
+
* ipv4Fetch, closed when the search ends), at most `n` results: once, and once more past Exa's free limit after
|
|
30
|
+
* `pause` (default a wait the search's signal ends; a test's records it). */
|
|
31
|
+
export declare function exaSearch(query: string, n: number, { send, signal, pause }?: {
|
|
32
|
+
send?: typeof fetch;
|
|
33
|
+
signal?: AbortSignal;
|
|
34
|
+
pause?: (ms: number, signal: AbortSignal) => Promise<void>;
|
|
35
|
+
}): Promise<Search | ExaLimited>;
|