@parcha/agentrun-serve 0.1.0-beta.54 → 0.1.0-beta.56
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 +142 -2
- package/README.md +310 -98
- package/dist/adapters.d.ts +11 -0
- package/dist/adapters.js +49 -0
- package/dist/agent-package.d.ts +3 -3
- package/dist/agent-package.js +6 -13
- package/dist/agents-store.js +6 -5
- package/dist/answer-json.d.ts +6 -2
- package/dist/answer-json.js +22 -4
- package/dist/api-only.d.ts +16 -4
- package/dist/api-only.js +23 -7
- package/dist/calendar/tools.js +3 -2
- package/dist/chatgpt-plan.d.ts +16 -1
- package/dist/chatgpt-plan.js +116 -12
- package/dist/claude-login.d.ts +34 -5
- package/dist/claude-login.js +31 -7
- package/dist/claude-sign-in.d.ts +35 -0
- package/dist/claude-sign-in.js +90 -0
- package/dist/cli.js +5 -3
- package/dist/composio-made.d.ts +26 -1
- package/dist/composio-made.js +39 -2
- package/dist/composio-preset.d.ts +3 -2
- package/dist/composio-preset.js +46 -14
- package/dist/computer-held-routes.js +2 -3
- package/dist/computer-setting.d.ts +4 -2
- package/dist/computer-setting.js +0 -2
- package/dist/computers-running.d.ts +8 -0
- package/dist/computers-running.js +27 -0
- package/dist/console/assets/backend-Boh7tC4i.js +166 -0
- package/dist/console/assets/index-CQ3cJRzI.js +746 -0
- package/dist/console/assets/index-DKkaS3a0.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/docker-host-addresses.d.ts +23 -3
- package/dist/docker-host-addresses.js +90 -18
- package/dist/exa-keyless.d.ts +2 -3
- package/dist/exa-keyless.js +43 -127
- package/dist/firecrawl-keyless.d.ts +41 -0
- package/dist/firecrawl-keyless.js +152 -0
- package/dist/handed-secret.d.ts +3 -1
- package/dist/handed-secret.js +4 -2
- package/dist/harness-keys.d.ts +98 -0
- package/dist/harness-keys.js +247 -0
- package/dist/harness-recipe-entry.d.ts +14 -9
- package/dist/harness-recipe-entry.js +25 -14
- package/dist/harness-table.d.ts +16 -1
- package/dist/harness-table.js +19 -7
- package/dist/harness.d.ts +4 -0
- package/dist/harness.js +12 -1
- package/dist/host-check.d.ts +6 -0
- package/dist/host-check.js +10 -0
- package/dist/import-summary.d.ts +1 -1
- package/dist/import-summary.js +1 -1
- package/dist/import.d.ts +5 -5
- package/dist/import.js +54 -67
- package/dist/key-refusal.d.ts +21 -5
- package/dist/key-refusal.js +231 -37
- package/dist/keyless-mcp.d.ts +36 -0
- package/dist/keyless-mcp.js +127 -0
- package/dist/learn/audit.d.ts +3 -3
- package/dist/learn/audit.js +3 -3
- package/dist/learn/commit.d.ts +8 -7
- package/dist/learn/commit.js +60 -20
- package/dist/learn/compile.d.ts +4 -3
- package/dist/learn/compile.js +7 -5
- package/dist/learn/folder.d.ts +16 -3
- package/dist/learn/folder.js +46 -13
- package/dist/learn/promote.d.ts +37 -13
- package/dist/learn/promote.js +112 -40
- package/dist/learn/secrets.d.ts +20 -10
- package/dist/learn/secrets.js +44 -176
- package/dist/learning-routes.d.ts +22 -17
- package/dist/learning-routes.js +40 -39
- package/dist/learning.js +2 -2
- package/dist/llms.txt +1 -1
- package/dist/manifest.d.ts +10 -0
- package/dist/manifest.js +30 -0
- package/dist/mcp-pin-first.d.ts +4 -2
- package/dist/mcp-pin-first.js +5 -2
- package/dist/mcp-secret-writes.d.ts +16 -7
- package/dist/mcp-secret-writes.js +35 -27
- package/dist/mcp-servers-store.d.ts +30 -6
- package/dist/mcp-servers-store.js +112 -28
- package/dist/mcp-sources.d.ts +10 -2
- package/dist/mcp-sources.js +9 -2
- package/dist/mcp-store.d.ts +13 -7
- package/dist/mcp-store.js +12 -9
- package/dist/model-form.d.ts +3 -2
- package/dist/model-form.js +11 -7
- package/dist/model.d.ts +20 -4
- package/dist/model.js +68 -9
- package/dist/native/history.d.ts +1 -1
- package/dist/native/history.js +2 -2
- package/dist/ollama-provider.d.ts +92 -0
- package/dist/ollama-provider.js +495 -0
- package/dist/openapi/agentrun-v2.openapi.json +2 -2
- package/dist/openapi.d.ts +3 -3
- package/dist/openapi.js +197 -55
- package/dist/page.d.ts +11 -3
- package/dist/page.js +22 -7
- package/dist/place-offers.d.ts +25 -1
- package/dist/place-offers.js +62 -8
- package/dist/print.js +1 -1
- package/dist/purged-workflow.d.ts +35 -7
- package/dist/purged-workflow.js +73 -26
- package/dist/redact/match.d.ts +74 -0
- package/dist/redact/match.js +771 -0
- package/dist/run-computer.d.ts +2 -0
- package/dist/run-computer.js +2 -0
- package/dist/run-files.d.ts +4 -0
- package/dist/run-files.js +4 -0
- package/dist/run-keys.d.ts +2 -4
- package/dist/run-keys.js +6 -7
- package/dist/run-launch.d.ts +4 -0
- package/dist/run-launch.js +4 -0
- package/dist/run-reads-over-store.d.ts +3 -2
- package/dist/run-reads-over-store.js +66 -2
- package/dist/run-secrets.js +5 -2
- package/dist/run-timeline-served.d.ts +1 -1
- package/dist/run-timeline-served.js +4 -4
- package/dist/runner/adapter-loop.d.ts +9 -3
- package/dist/runner/adapter-loop.js +34 -15
- package/dist/runner/adapter-run-spec.d.ts +3 -0
- package/dist/runner/adapter-run-spec.js +9 -4
- package/dist/runner/audit.js +8 -4
- package/dist/runner/beside.d.ts +2 -1
- package/dist/runner/beside.js +13 -5
- package/dist/runner/claim-secrets.d.ts +5 -8
- package/dist/runner/claim-secrets.js +6 -0
- package/dist/runner/cli-run-spec.d.ts +1 -1
- package/dist/runner/cli-run-spec.js +41 -7
- package/dist/runner/harness-loops.d.ts +22 -9
- package/dist/runner/harness-loops.js +21 -11
- package/dist/runner/held.d.ts +3 -0
- package/dist/runner/learning-end.d.ts +1 -1
- package/dist/runner/learning-end.js +8 -3
- package/dist/runner/loop-contract.d.ts +9 -4
- package/dist/runner/main.js +12 -6
- package/dist/runner/mcp-claim.d.ts +3 -0
- package/dist/runner/mcp-claim.js +26 -2
- package/dist/runner/mcp-run.d.ts +3 -0
- package/dist/runner/mcp-run.js +2 -1
- package/dist/runner/metrics.d.ts +10 -10
- package/dist/runner/metrics.js +19 -38
- package/dist/runner/model-route.d.ts +3 -0
- package/dist/runner/model-route.js +6 -2
- package/dist/runner/presence.d.ts +4 -3
- package/dist/runner/presence.js +4 -2
- package/dist/runner/promotion.d.ts +15 -9
- package/dist/runner/promotion.js +25 -15
- package/dist/runner/run-child-host.d.ts +2 -0
- package/dist/runner/run-child-host.js +19 -9
- package/dist/runner/run-child.js +3 -1
- package/dist/runner/runner.d.ts +4 -0
- package/dist/runner/runner.js +33 -3
- package/dist/runner/sdk-loop.js +2 -0
- package/dist/runner/workflow-loop.d.ts +2 -2
- package/dist/runner/workflow-loop.js +1 -2
- package/dist/runner/workflow-spec.d.ts +1 -1
- package/dist/runner/workflow-spec.js +6 -6
- package/dist/sdk/check.d.ts +4 -1
- package/dist/sdk/check.js +2 -1
- package/dist/sdk/runs.d.ts +2 -2
- package/dist/sdk/runs.js +8 -6
- package/dist/secret-cut.js +2 -1
- package/dist/secret-writes.d.ts +3 -2
- package/dist/secret-writes.js +1 -1
- package/dist/server.d.ts +49 -10
- package/dist/server.js +324 -118
- package/dist/standard-webhooks.d.ts +11 -0
- package/dist/standard-webhooks.js +20 -2
- package/dist/store/dialect.d.ts +3 -0
- package/dist/store/dialect.js +1 -0
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +1 -1
- package/dist/store/postgres/dialect.js +3 -0
- package/dist/store/schema.js +5 -2
- package/dist/store/sqlite/store.js +133 -47
- package/dist/store/store.d.ts +64 -15
- package/dist/store/store.js +7 -0
- package/dist/store-reads/journal.d.ts +7 -2
- package/dist/store-reads/journal.js +9 -6
- package/dist/store-reads/learning.d.ts +12 -9
- package/dist/store-reads/learning.js +18 -24
- package/dist/store-view.d.ts +0 -5
- package/dist/store-view.js +10 -9
- package/dist/template-eval.d.ts +51 -6
- package/dist/template-eval.js +177 -53
- package/dist/template-import.js +4 -2
- package/dist/templates.d.ts +5 -3
- package/dist/templates.js +19 -40
- package/dist/timeline/index.d.ts +1 -1
- package/dist/timeline/index.js +1 -1
- package/dist/timeline/labels.d.ts +2 -2
- package/dist/timeline/labels.js +2 -2
- package/dist/timeline/timeline.d.ts +14 -9
- package/dist/timeline/timeline.js +15 -7
- package/dist/tool-gate.js +3 -1
- package/dist/tool-plane.d.ts +17 -9
- package/dist/tool-plane.js +38 -17
- package/dist/tools.js +2 -2
- package/dist/trigger-launch-hook.d.ts +16 -8
- package/dist/trigger-launch-hook.js +32 -23
- package/dist/trigger-targets.d.ts +18 -8
- package/dist/trigger-targets.js +42 -19
- package/dist/triggers.d.ts +85 -23
- package/dist/triggers.js +303 -96
- package/dist/validate.js +1 -1
- package/dist/web-fake.js +3 -3
- package/dist/web-fetch-direct.d.ts +4 -0
- package/dist/web-fetch-direct.js +8 -1
- package/dist/web-fetch.d.ts +12 -3
- package/dist/web-fetch.js +47 -14
- package/dist/web-search.d.ts +33 -4
- package/dist/web-search.js +100 -41
- package/dist/webhooks.js +4 -5
- package/dist/workspace/computer-deps.d.ts +2 -1
- package/dist/workspace/computer-deps.js +5 -4
- package/dist/workspace/computer-for-claim.d.ts +8 -2
- package/dist/workspace/computer-for-claim.js +28 -9
- package/dist/workspace/computer-janitor.d.ts +15 -7
- package/dist/workspace/computer-janitor.js +33 -8
- package/dist/workspace/computer-kept.d.ts +52 -4
- package/dist/workspace/computer-kept.js +118 -6
- package/dist/workspace/run-end-computers.d.ts +5 -1
- package/dist/workspace/run-end-computers.js +27 -1
- package/dist/wrapped.d.ts +57 -0
- package/dist/wrapped.js +51 -0
- package/launcher/agentrun-serve +5 -1
- package/package.json +17 -13
- package/templates/README.md +10 -9
- package/dist/console/assets/index-B_85An2t.js +0 -745
- package/dist/console/assets/index-n1YsbnYh.css +0 -1
- package/dist/import-sources.d.ts +0 -116
- package/dist/import-sources.js +0 -693
|
@@ -59,7 +59,7 @@ export declare const callFailed: (tool: string, result: {
|
|
|
59
59
|
export declare function registerTurnEnding(tool: string): void;
|
|
60
60
|
/** Whether `tool` ends its turn (registerTurnEnding). */
|
|
61
61
|
export declare const endsTurn: (tool: string) => boolean;
|
|
62
|
-
/** The label of a call; `result` is given once the call has finished. Unknown tools get
|
|
62
|
+
/** The label of a call; `result` is given once the call has finished. Unknown tools get the default fallback. */
|
|
63
63
|
export declare function labelOf(tool: string, args: Obj, result?: ToolResultView, extra?: Record<string, LabelFn>): string;
|
|
64
64
|
/** One line for several calls of one tool: `Read 4 pages: a.example, b.example, +2 more`. */
|
|
65
65
|
export declare function foldLabel(tool: string, calls: readonly {
|
|
@@ -68,7 +68,7 @@ export declare function foldLabel(tool: string, calls: readonly {
|
|
|
68
68
|
}[], options?: {
|
|
69
69
|
path?: (path: string) => string;
|
|
70
70
|
}): string;
|
|
71
|
-
/** The input worth showing:
|
|
71
|
+
/** The input worth showing: the base keys first, then the browser and file ones, and last the app a computer's look or act
|
|
72
72
|
* names (never what an act types: its steps; nor a codemode script, which can hold it). */
|
|
73
73
|
export declare function inputPreview(args: Obj, max: number): string | null;
|
|
74
74
|
/** Files a finished call put in the workspace. */
|
package/dist/timeline/labels.js
CHANGED
|
@@ -51,7 +51,7 @@ export function registerTurnEnding(tool) {
|
|
|
51
51
|
}
|
|
52
52
|
/** Whether `tool` ends its turn (registerTurnEnding). */
|
|
53
53
|
export const endsTurn = (tool) => turnEnding.has(tool);
|
|
54
|
-
/** The label of a call; `result` is given once the call has finished. Unknown tools get
|
|
54
|
+
/** The label of a call; `result` is given once the call has finished. Unknown tools get the default fallback. */
|
|
55
55
|
export function labelOf(tool, args, result, extra) {
|
|
56
56
|
const own = extra && Object.hasOwn(extra, tool) ? extra[tool] : undefined;
|
|
57
57
|
return (own ?? labels.get(tool))?.(args, result) ?? mcpLabel(tool) ?? `Using tool: ${tool}`;
|
|
@@ -65,7 +65,7 @@ export function foldLabel(tool, calls, options = {}) {
|
|
|
65
65
|
const subjects = calls.flatMap((call) => spec?.subject?.(named(call.input), call.output) ?? []);
|
|
66
66
|
return subjects.length ? `${head}: ${list(subjects)}` : head;
|
|
67
67
|
}
|
|
68
|
-
/** The input worth showing:
|
|
68
|
+
/** The input worth showing: the base keys first, then the browser and file ones, and last the app a computer's look or act
|
|
69
69
|
* names (never what an act types: its steps; nor a codemode script, which can hold it). */
|
|
70
70
|
export function inputPreview(args, max) {
|
|
71
71
|
for (const key of ["description", "command", "query", "file_path", "url", "path", "code", "app"]) {
|
|
@@ -9,7 +9,7 @@ export type TimelineKind = "thinking" | "text_block" | "tool_use" | "tool_result
|
|
|
9
9
|
| "learning"
|
|
10
10
|
/** A tool call that waited for a person's approval, after its result's row (serve's tool gate). */
|
|
11
11
|
| "tool_approval_requested";
|
|
12
|
-
/**
|
|
12
|
+
/** The public `TimelineEvent` (its 13 base fields) plus the open additions, all optional. */
|
|
13
13
|
export type TimelineEvent = {
|
|
14
14
|
id: string;
|
|
15
15
|
timestamp: string;
|
|
@@ -95,9 +95,9 @@ export type TimelineEvent = {
|
|
|
95
95
|
/** On a `tool_use` row of a timeline read with `calls` (TimelineOptions): the call's arguments, each string as `redact`
|
|
96
96
|
* makes it where the call is first seen, cut at CAPS.text. */
|
|
97
97
|
tool_input?: Obj;
|
|
98
|
-
/** On a `tool_result` row of a timeline read with `calls`: the
|
|
99
|
-
* as `calls.redact` makes it, its URLs' query values elided as the preview's are; a web call's every
|
|
100
|
-
* texts cut to fit (CALL_RESULT_CHARS). */
|
|
98
|
+
/** On a `tool_result` row of a timeline read with `calls`: the call's output whole to `calls.result` characters (its
|
|
99
|
+
* head past that), as `calls.redact` makes it, its URLs' query values elided as the preview's are; a web call's every
|
|
100
|
+
* url, its long texts cut to fit (CALL_RESULT_CHARS). */
|
|
101
101
|
tool_result_text?: string | null;
|
|
102
102
|
};
|
|
103
103
|
/** A pi conversation entry as stored: `pi.assistant`, `pi.tool-result`, a host's own kind. */
|
|
@@ -118,18 +118,23 @@ export type AgentEventLike = {
|
|
|
118
118
|
type: string;
|
|
119
119
|
[key: string]: unknown;
|
|
120
120
|
};
|
|
121
|
-
/**
|
|
121
|
+
/** The base caps, so a row is the same on both sides. `thinking` cuts the first sentence of a thinking summary. */
|
|
122
122
|
export declare const CAPS: {
|
|
123
123
|
summary: number;
|
|
124
124
|
preview: number;
|
|
125
125
|
text: number;
|
|
126
126
|
thinking: number;
|
|
127
127
|
};
|
|
128
|
-
/** The most of a call's output a read for a grader shows (`calls`, tool_result_text): a
|
|
129
|
-
*
|
|
128
|
+
/** The most of a call's output a read for a grader shows (`calls`, tool_result_text): as much as a grader's whole prompt
|
|
129
|
+
* takes (template-eval.ts GRADER_PROMPT_MAX), so a grader judges what the run read, not a head of it; the grader's own
|
|
130
|
+
* fit (fitCalls) shares that room among the calls. The run's redaction reads it in pieces of an answer's size
|
|
131
|
+
* (key-refusal.ts redactedCall), so a long head costs no more a pass than a short one. Past it, a tool's output's head; a
|
|
132
|
+
* web call's is not its head: a
|
|
130
133
|
* web_search's every result keeps its url, title and published date, and a web_fetch its url and title, their snippets
|
|
131
|
-
* and page text cut to fit (web-calls.ts), past this only when its urls alone pass it
|
|
132
|
-
export declare const CALL_RESULT_CHARS =
|
|
134
|
+
* and page text cut to fit (web-calls.ts), past this only when its urls alone pass it. */
|
|
135
|
+
export declare const CALL_RESULT_CHARS = 120000;
|
|
136
|
+
/** The most rows a `calls=whole` timeline page holds, and its default: each row's result may be CALL_RESULT_CHARS long. */
|
|
137
|
+
export declare const CALLS_PAGE_ROWS = 100;
|
|
133
138
|
/** A host's marks of a model request: as it leaves (written before it does), and as its stream ends aborted. A request
|
|
134
139
|
* that answered or failed has a `pi.assistant` entry; one aborted before its first content has none; a start with no
|
|
135
140
|
* end and no entry is in flight when it is the latest, unless the run is settled, and was cut by a crash when a later
|
|
@@ -8,13 +8,18 @@ export const nestingCallOf = (callId) => {
|
|
|
8
8
|
const at = callId.lastIndexOf("/");
|
|
9
9
|
return at > 0 ? callId.slice(0, at) : undefined;
|
|
10
10
|
};
|
|
11
|
-
/**
|
|
11
|
+
/** The base caps, so a row is the same on both sides. `thinking` cuts the first sentence of a thinking summary. */
|
|
12
12
|
export const CAPS = { summary: 500, preview: 500, text: 2000, thinking: 100 };
|
|
13
|
-
/** The most of a call's output a read for a grader shows (`calls`, tool_result_text): a
|
|
14
|
-
*
|
|
13
|
+
/** The most of a call's output a read for a grader shows (`calls`, tool_result_text): as much as a grader's whole prompt
|
|
14
|
+
* takes (template-eval.ts GRADER_PROMPT_MAX), so a grader judges what the run read, not a head of it; the grader's own
|
|
15
|
+
* fit (fitCalls) shares that room among the calls. The run's redaction reads it in pieces of an answer's size
|
|
16
|
+
* (key-refusal.ts redactedCall), so a long head costs no more a pass than a short one. Past it, a tool's output's head; a
|
|
17
|
+
* web call's is not its head: a
|
|
15
18
|
* web_search's every result keeps its url, title and published date, and a web_fetch its url and title, their snippets
|
|
16
|
-
* and page text cut to fit (web-calls.ts), past this only when its urls alone pass it
|
|
17
|
-
export const CALL_RESULT_CHARS =
|
|
19
|
+
* and page text cut to fit (web-calls.ts), past this only when its urls alone pass it. */
|
|
20
|
+
export const CALL_RESULT_CHARS = 120_000;
|
|
21
|
+
/** The most rows a `calls=whole` timeline page holds, and its default: each row's result may be CALL_RESULT_CHARS long. */
|
|
22
|
+
export const CALLS_PAGE_ROWS = 100;
|
|
18
23
|
/** A host's marks of a model request: as it leaves (written before it does), and as its stream ends aborted. A request
|
|
19
24
|
* that answered or failed has a `pi.assistant` entry; one aborted before its first content has none; a start with no
|
|
20
25
|
* end and no entry is in flight when it is the latest, unless the run is settled, and was cut by a crash when a later
|
|
@@ -696,8 +701,11 @@ function createProjector(options) {
|
|
|
696
701
|
const shown = options.calls ? obj(inputShown(args, caps.text, options.redact, options.calls.held)) : undefined;
|
|
697
702
|
return shown ? { tool_input: shown } : {};
|
|
698
703
|
};
|
|
699
|
-
/** A call's output as a `calls` read shows it (tool_result_text): redacted by its redactor, else the rows' own, its
|
|
700
|
-
* URLs' query values elided, cut at `calls.result`; a web call's every url whole, only its long texts cut
|
|
704
|
+
/** A call's output as a `calls` read shows it (tool_result_text): redacted by its redactor, else the rows' own, then its
|
|
705
|
+
* URLs' query values elided, cut at `calls.result`; a web call's every url whole, only its long texts cut
|
|
706
|
+
* (web-calls.ts). Every secret check reads the text as it came, never as shown: elided, a URL's query and userinfo are
|
|
707
|
+
* cut apart, and a held value in one no longer reads as itself. The served redactor (redactedCall) elides each piece it
|
|
708
|
+
* read after redacting it, so what it returns is already as shown and the elision here changes nothing in it. */
|
|
701
709
|
const wholeRedact = options.calls?.redact ?? options.redact;
|
|
702
710
|
const callShown = (text) => scrubUrls(wholeRedact ? wholeRedact(text) : text);
|
|
703
711
|
const resultText = (tool, text) => {
|
package/dist/tool-gate.js
CHANGED
|
@@ -18,7 +18,9 @@
|
|
|
18
18
|
//
|
|
19
19
|
// An ask has one way to wait, every tool's alike (the owner's ruling of 11-04): it PARKS. The runner's loop holds the
|
|
20
20
|
// call and the run goes needs_input with the pending approval. On an answer the loop runs the approved call once, through
|
|
21
|
-
// the journal, and the session goes on with its result.
|
|
21
|
+
// the journal, and the session goes on with its result. A read the runner lost mid-call (its claim lapsed before the
|
|
22
|
+
// call's end was recorded) may run again on its next claim; a call with a side effect never does: that claim answers it
|
|
23
|
+
// interrupted (test/adapter-approved-call-lapse.test.mjs). One call waits at a time: another asked meanwhile is refused.
|
|
22
24
|
//
|
|
23
25
|
// The answer: POST /v2/runs/{id}/approvals/{approval_id} { decision: "allow" | "deny", note? } -> 204. The first answer
|
|
24
26
|
// wins; the same answer again is 204, a conflicting one 409. Only the owner's password session answers (server.ts), never
|
package/dist/tool-plane.d.ts
CHANGED
|
@@ -16,18 +16,24 @@ type EmailScope = (typeof EMAIL_SCOPES)[number];
|
|
|
16
16
|
* catalog grants).
|
|
17
17
|
*/
|
|
18
18
|
export declare const CAPABILITIES: readonly ["read", "write", "edit", "web_search", "web_fetch", "browser", "ask_person"];
|
|
19
|
-
/**
|
|
20
|
-
*
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
*
|
|
19
|
+
/** web_fetch's guarded direct fetch, by its id: "kernel", the kernel's own fetch, never the Kernel browser provider.
|
|
20
|
+
* Named once here, so the scan of vendor ids (scripts/check-vendor-ids.mjs) counts it once. */
|
|
21
|
+
declare const DIRECT_FETCH: "kernel";
|
|
22
|
+
/** The providers a user may pick for each capability that has a choice, its default first: `auto`, for web_search the
|
|
23
|
+
* native search where there is one (never on claude-agent, where Claude's own search is picked as `native`), else
|
|
24
|
+
* Parallel where the server holds its key, else keyless Firecrawl; for web_fetch the guarded direct fetch where the
|
|
25
|
+
* server holds a Parallel key, else keyless Firecrawl; `native`, the harness's own tool or its model provider's hosted
|
|
26
|
+
* one, and nothing else; `firecrawl-keyless`, Firecrawl's public MCP endpoint, no key, with keyless Exa behind it for
|
|
27
|
+
* web_search and the guarded direct fetch behind it for web_fetch; `exa-keyless`, Exa's public MCP endpoint alone, no
|
|
28
|
+
* key; `kernel`, the guarded direct fetch; `parallel`, Parallel's Search and Extract APIs on PARALLEL_API_KEY; `off`,
|
|
29
|
+
* web_search turned off: nothing is searched, and an
|
|
24
30
|
* agent naming it is refused until it is turned on again. The browser's: `auto`, the computer registry's first browser
|
|
25
31
|
* provider whose keys the server holds (Browserbase, else Kernel); a browser provider's id (`browserbase`, `kernel`:
|
|
26
32
|
* BROWSER_VENDOR_IDS), that one alone; `chrome`, a Chrome on the server's own host, which no server sets up yet
|
|
27
33
|
* (browserBy). */
|
|
28
34
|
export declare const PROVIDERS: Readonly<{
|
|
29
|
-
web_search: readonly ["auto", "native", "exa-keyless", "parallel", "off"];
|
|
30
|
-
web_fetch: readonly ["kernel", "parallel"];
|
|
35
|
+
web_search: readonly ["auto", "native", "firecrawl-keyless", "exa-keyless", "parallel", "off"];
|
|
36
|
+
web_fetch: readonly ["auto", "firecrawl-keyless", "kernel", "parallel"];
|
|
31
37
|
browser: readonly string[];
|
|
32
38
|
}>;
|
|
33
39
|
export type Pickable = keyof typeof PROVIDERS;
|
|
@@ -89,8 +95,9 @@ export declare const sortedPin: (pin: Pin) => Pin;
|
|
|
89
95
|
/** The tools' settings, the server's (`/v2/settings/tools`) and an agent's own (`definition.tool_settings`), one shape:
|
|
90
96
|
* by settings key. */
|
|
91
97
|
export type ToolSettingsMap = Partial<Record<string, ToolSetting>>;
|
|
92
|
-
/** What a capability resolves to on a run: the native tool, the kernel's own, keyless
|
|
93
|
-
|
|
98
|
+
/** What a capability resolves to on a run: the native tool, the kernel's own, keyless Firecrawl (keyless Exa behind it),
|
|
99
|
+
* keyless Exa, Parallel, or why not. */
|
|
100
|
+
export type Resolution = "native" | typeof DIRECT_FETCH | "firecrawl-keyless" | "exa-keyless" | "parallel" | "browserbase" | `unavailable: ${string}`;
|
|
94
101
|
export declare const NO_PARALLEL_KEY: Resolution;
|
|
95
102
|
/** web_search with `off` picked: no search leaves the server. */
|
|
96
103
|
export declare const SEARCH_OFF: Resolution;
|
|
@@ -129,6 +136,7 @@ export type ResolveInput = {
|
|
|
129
136
|
/** Whether a run on `harness` sends through OpenRouter, where a harness's own search does not run: false for one with
|
|
130
137
|
* none (and for pi, whose hosted search is asked of the model's provider). */
|
|
131
138
|
export declare const ownSearchViaOpenRouter: (env: NodeJS.ProcessEnv, harness: string, model?: string) => boolean;
|
|
139
|
+
export declare const FIRECRAWL_FETCH = "Firecrawl's free keyless fetch, no key, the guarded direct fetch behind it. web_fetch sends each URL to Firecrawl's keyless service (never a private or local one); set PARALLEL_API_KEY or choose kernel to fetch directly";
|
|
132
140
|
/** What `capability` resolves to on a run of `input`, and why in a plain sentence (capabilities' `why`): one rule, so
|
|
133
141
|
* the two never disagree. */
|
|
134
142
|
export declare function explainCapability(capability: Pickable, input: ResolveInput): {
|
package/dist/tool-plane.js
CHANGED
|
@@ -3,11 +3,15 @@
|
|
|
3
3
|
// agent's own (`definition.tool_settings`) over the server's (`PUT /v2/settings/tools`), optional; (2) the native tool:
|
|
4
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
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
|
|
7
|
-
//
|
|
8
|
-
//
|
|
6
|
+
// it); (4) the keyless fallback: Firecrawl's public keyless MCP endpoint (firecrawl-keyless.ts), with Exa's
|
|
7
|
+
// (exa-keyless.ts) behind it. web_fetch has no (2): its `auto` is the guarded direct fetch where the server holds a
|
|
8
|
+
// Parallel key (as before keyless Firecrawl), else keyless Firecrawl with the guarded direct fetch behind it, and
|
|
9
|
+
// Parallel's extract is a pick. Through Firecrawl web_fetch sends each URL to a third party, and its `why` says so; a URL
|
|
10
|
+
// the public-host guard refuses never goes (web-fetch.ts). On claude-agent `auto` skips (2):
|
|
11
|
+
// Claude's own search is an explicit pick, `native`. Codex's own search on codex, Parallel or keyless Firecrawl behind
|
|
12
|
+
// a gateway, on OpenRouter or under a spend cap;
|
|
9
13
|
// `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
|
|
14
|
+
// unavailable where there is none, never a keyless search. A grant names a capability, never a provider. A pick of parallel without
|
|
11
15
|
// PARALLEL_API_KEY resolves unavailable, never to something else. The server resolves a run's tools at its first
|
|
12
16
|
// launch, from its pinned revision and the settings then, keeps them for the run's life (runs.ts), and hands the run's
|
|
13
17
|
// process the outcome as a non-secret description (TOOL_PLANE_ENV): the run reads its tools' providers there, never from
|
|
@@ -42,16 +46,22 @@ import { isCatalogName, isMcpName, mcpNameOf, parseToolName } from "./tool-names
|
|
|
42
46
|
* catalog grants).
|
|
43
47
|
*/
|
|
44
48
|
export const CAPABILITIES = ["read", "write", "edit", "web_search", "web_fetch", "browser", "ask_person"];
|
|
45
|
-
/**
|
|
46
|
-
*
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
*
|
|
49
|
+
/** web_fetch's guarded direct fetch, by its id: "kernel", the kernel's own fetch, never the Kernel browser provider.
|
|
50
|
+
* Named once here, so the scan of vendor ids (scripts/check-vendor-ids.mjs) counts it once. */
|
|
51
|
+
const DIRECT_FETCH = "kernel";
|
|
52
|
+
/** The providers a user may pick for each capability that has a choice, its default first: `auto`, for web_search the
|
|
53
|
+
* native search where there is one (never on claude-agent, where Claude's own search is picked as `native`), else
|
|
54
|
+
* Parallel where the server holds its key, else keyless Firecrawl; for web_fetch the guarded direct fetch where the
|
|
55
|
+
* server holds a Parallel key, else keyless Firecrawl; `native`, the harness's own tool or its model provider's hosted
|
|
56
|
+
* one, and nothing else; `firecrawl-keyless`, Firecrawl's public MCP endpoint, no key, with keyless Exa behind it for
|
|
57
|
+
* web_search and the guarded direct fetch behind it for web_fetch; `exa-keyless`, Exa's public MCP endpoint alone, no
|
|
58
|
+
* key; `kernel`, the guarded direct fetch; `parallel`, Parallel's Search and Extract APIs on PARALLEL_API_KEY; `off`,
|
|
59
|
+
* web_search turned off: nothing is searched, and an
|
|
50
60
|
* agent naming it is refused until it is turned on again. The browser's: `auto`, the computer registry's first browser
|
|
51
61
|
* provider whose keys the server holds (Browserbase, else Kernel); a browser provider's id (`browserbase`, `kernel`:
|
|
52
62
|
* BROWSER_VENDOR_IDS), that one alone; `chrome`, a Chrome on the server's own host, which no server sets up yet
|
|
53
63
|
* (browserBy). */
|
|
54
|
-
export const PROVIDERS = Object.freeze({ web_search: ["auto", "native", "exa-keyless", "parallel", "off"], web_fetch: ["
|
|
64
|
+
export const PROVIDERS = Object.freeze({ web_search: ["auto", "native", "firecrawl-keyless", "exa-keyless", "parallel", "off"], web_fetch: ["auto", "firecrawl-keyless", DIRECT_FETCH, "parallel"], browser: Object.freeze(["auto", ...browserProviderIds(), "chrome"]) });
|
|
55
65
|
export const PICKABLE = Object.keys(PROVIDERS);
|
|
56
66
|
/** The permissions `name` may be set to: ask is offered for the tools whose approved call the kernel runs itself, outside
|
|
57
67
|
* the model's turn (tool-list.ts `askable`) and for catalog tools. Any other (browser, ask_person, the call-only ones) is
|
|
@@ -162,7 +172,7 @@ function noNative(input) {
|
|
|
162
172
|
// (cappedOwn: per-use fees the cap cannot reserve yet, its request's bound holding the pages' input tokens, not the
|
|
163
173
|
// fees; or a request with no input bound). A harness with none (OpenCode, whose proxy policy refuses a
|
|
164
174
|
// provider-hosted tool) has none at all. Where there is none, `native` is unavailable, and `auto` goes to Parallel on
|
|
165
|
-
// the server's key (its fee booked and held by a cap, paid-calls.ts), else to keyless
|
|
175
|
+
// the server's key (its fee booked and held by a cap, paid-calls.ts), else to keyless Firecrawl.
|
|
166
176
|
const vendor = input.model?.slice(0, Math.max(0, input.model.indexOf("/")));
|
|
167
177
|
const { facts } = input;
|
|
168
178
|
if (facts) {
|
|
@@ -185,6 +195,10 @@ const nativeWhy = (input) => {
|
|
|
185
195
|
const { facts } = input;
|
|
186
196
|
return facts?.webSearch ? `${facts.label}'s own search` : `${input.model?.startsWith("openai/") ? "OpenAI" : "Anthropic"}'s hosted search, for ${input.model}`;
|
|
187
197
|
};
|
|
198
|
+
/** Keyless Firecrawl in a sentence, as web_search and web_fetch use it. web_fetch's says plainly that each URL leaves
|
|
199
|
+
* the server, and how to keep it here. */
|
|
200
|
+
const FIRECRAWL_SEARCH = "Firecrawl's free keyless search, no key, keyless Exa behind it";
|
|
201
|
+
export const FIRECRAWL_FETCH = "Firecrawl's free keyless fetch, no key, the guarded direct fetch behind it. web_fetch sends each URL to Firecrawl's keyless service (never a private or local one); set PARALLEL_API_KEY or choose kernel to fetch directly";
|
|
188
202
|
/** What `capability` resolves to on a run of `input`, and why in a plain sentence (capabilities' `why`): one rule, so
|
|
189
203
|
* the two never disagree. */
|
|
190
204
|
export function explainCapability(capability, input) {
|
|
@@ -197,12 +211,19 @@ export function explainCapability(capability, input) {
|
|
|
197
211
|
return { resolves: SEARCH_OFF, why: "turned off in settings" };
|
|
198
212
|
if (chosen === "parallel")
|
|
199
213
|
return input.parallelKey ? { resolves: "parallel", why: `Parallel, ${picked}: ${key}` } : { resolves: NO_PARALLEL_KEY, why: `Parallel is picked, and it needs ${keyNeeded([PARALLEL_KEY_ENV])}` };
|
|
200
|
-
if (capability === "web_fetch")
|
|
201
|
-
|
|
214
|
+
if (capability === "web_fetch") {
|
|
215
|
+
if (chosen === DIRECT_FETCH)
|
|
216
|
+
return { resolves: DIRECT_FETCH, why: `the guarded direct fetch, ${picked}` };
|
|
217
|
+
if (chosen === "firecrawl-keyless")
|
|
218
|
+
return { resolves: "firecrawl-keyless", why: `keyless Firecrawl, ${picked}: ${FIRECRAWL_FETCH}` };
|
|
219
|
+
return input.parallelKey ? { resolves: DIRECT_FETCH, why: `the guarded direct fetch: the server holds ${key}, so no URL goes to a keyless service` } : { resolves: "firecrawl-keyless", why: FIRECRAWL_FETCH };
|
|
220
|
+
}
|
|
202
221
|
if (capability === "browser")
|
|
203
222
|
return browserBy(chosen, picked, input.browserKeys);
|
|
204
223
|
if (chosen === "exa-keyless")
|
|
205
224
|
return { resolves: "exa-keyless", why: `keyless Exa, ${picked}: Exa's free search, no key` };
|
|
225
|
+
if (chosen === "firecrawl-keyless")
|
|
226
|
+
return { resolves: "firecrawl-keyless", why: `keyless Firecrawl, ${picked}: ${FIRECRAWL_SEARCH}` };
|
|
206
227
|
// Under ask, a harness's own search runs inside its CLI, where no call can wait for a person: none on claude-agent or
|
|
207
228
|
// codex then, and the kernel's search, which the gate holds, in its place. pi's is a tool of the run's, which it holds.
|
|
208
229
|
const asks = input.permission === "ask" && input.facts !== undefined;
|
|
@@ -213,13 +234,13 @@ export function explainCapability(capability, input) {
|
|
|
213
234
|
if (chosen === "native")
|
|
214
235
|
return none === undefined ? { resolves: "native", why: nativeWhy(input) } : { resolves: `unavailable: no native search for ${none.id}`, why: `no native search for ${none.id}` };
|
|
215
236
|
// `auto` skips a harness's own search that has per-use fees (its facts' `native`: the provider's search tool), an
|
|
216
|
-
// explicit pick (`native`): Parallel on the server's key, else keyless
|
|
237
|
+
// explicit pick (`native`): Parallel on the server's key, else keyless Firecrawl.
|
|
217
238
|
const { facts } = input;
|
|
218
239
|
if (facts?.webSearch === "native")
|
|
219
|
-
return input.parallelKey ? { resolves: "parallel", why: key } : { resolves: "
|
|
240
|
+
return input.parallelKey ? { resolves: "parallel", why: key } : { resolves: "firecrawl-keyless", why: `${FIRECRAWL_SEARCH}; ${facts.label}'s own search is an explicit pick` };
|
|
220
241
|
if (none === undefined)
|
|
221
242
|
return { resolves: "native", why: nativeWhy(input) };
|
|
222
|
-
return input.parallelKey ? { resolves: "parallel", why: `${none.why}; ${key}` } : { resolves: "
|
|
243
|
+
return input.parallelKey ? { resolves: "parallel", why: `${none.why}; ${key}` } : { resolves: "firecrawl-keyless", why: `${none.why}; ${FIRECRAWL_SEARCH}` };
|
|
223
244
|
}
|
|
224
245
|
/** What `capability` resolves to on a run of `input`. */
|
|
225
246
|
export const resolveCapability = (capability, input) => explainCapability(capability, input).resolves;
|
|
@@ -312,7 +333,7 @@ export const TOOL_PLANE_ENV = "AGENTRUN_SERVE_TOOL_PLANE";
|
|
|
312
333
|
export function planeFor(env, tooling, settings, { capped = false, run = false } = {}) {
|
|
313
334
|
const harness = tooling.harness ?? DEFAULT_HARNESS;
|
|
314
335
|
// A workflow's model nodes may each run on another tier's model, and a native search asks one model's provider: a
|
|
315
|
-
// workflow's search resolves with no model (keyless
|
|
336
|
+
// workflow's search resolves with no model (keyless Firecrawl, or Parallel where picked), never on a model a node may not use.
|
|
316
337
|
// A run that names no model runs on the host's for its harness (hostModel: a model key's default when no AGENT_MODEL
|
|
317
338
|
// it runs is set), so its search resolves on that one.
|
|
318
339
|
const model = tooling.workflow ? undefined : (tooling.model ?? hostModel(env, "default", harness));
|
package/dist/tools.js
CHANGED
|
@@ -103,7 +103,7 @@ const emailTool = (name) => ({
|
|
|
103
103
|
});
|
|
104
104
|
/** web_fetch, bound under `name`. */
|
|
105
105
|
const webFetchEntry = (name) => ({
|
|
106
|
-
summary: `Read one public web page from a public host through the guarded direct fetch, or through Parallel's extract where Parallel is picked (falling back to the direct fetch, saying why, when Parallel answers no page), a part at a time (offset, max_chars; the page fetched once a run): { ok, url, status, title, text, chars, truncated?, original_chars?, beyond_read?, offset?, next_offset?, html_chars?, converted?, links, links_omitted?, via, parallel?, refused?, error? }; html_chars, the page's whole length, when its HTML was cut at ${HTML_READ_CHARS.toLocaleString("en-US")} characters before it was read, so its text is only the start of the page; converted: "text" when the text is plain text, its conversion to markdown having run out of time; a private or local address, a port other than 80 or 443, or a scheme other than http(s) is refused, never sent to Parallel.`,
|
|
106
|
+
summary: `Read one public web page from a public host through Firecrawl's keyless fetch where the server holds no Parallel key (each URL sent to Firecrawl, never a private or local one; the guarded direct fetch when Firecrawl answers no page or its free limit is spent), else through the guarded direct fetch, or through Parallel's extract where Parallel is picked (falling back to the direct fetch, saying why, when Parallel answers no page), a part at a time (offset, max_chars; the page fetched once a run): { ok, url, status, title, text, chars, truncated?, original_chars?, beyond_read?, offset?, next_offset?, html_chars?, converted?, links, links_omitted?, via, parallel?, refused?, error? }; html_chars, the page's whole length, when its HTML was cut at ${HTML_READ_CHARS.toLocaleString("en-US")} characters before it was read, so its text is only the start of the page; converted: "text" when the text is plain text, its conversion to markdown having run out of time; a private or local address, a port other than 80 or 443, or a scheme other than http(s) is refused, never sent to Parallel.`,
|
|
107
107
|
needs: [],
|
|
108
108
|
nodes: true,
|
|
109
109
|
bind: async (host) => {
|
|
@@ -617,7 +617,7 @@ export const TOOLS = Object.freeze({
|
|
|
617
617
|
},
|
|
618
618
|
[WEB_FETCH_TOOL]: webFetchEntry(WEB_FETCH_TOOL),
|
|
619
619
|
[WEB_SEARCH_TOOL]: {
|
|
620
|
-
summary: "Search the web: codex's own search (claude-agent's where it is picked), on pi the model provider's hosted search (Anthropic, OpenAI), with none of those Parallel's Search API where the server holds its key, else
|
|
620
|
+
summary: "Search the web: codex's own search (claude-agent's where it is picked), on pi the model provider's hosted search (Anthropic, OpenAI), with none of those Parallel's Search API where the server holds its key, else Firecrawl's keyless search with Exa's behind it; or the provider picked: { query, n? } -> { provider, query, results: [{ url, title, snippet, published? }], text? }, provider naming the one that served it, 1 to 25 results, each snippet at most 3,000 characters; { error } when the search gives no answer.",
|
|
621
621
|
needs: [],
|
|
622
622
|
nodes: true,
|
|
623
623
|
// On the runner its hosted search goes through the run's own route (host.search, run.search), labelled web_search.
|
|
@@ -8,12 +8,11 @@ export declare const LAUNCH_HOOK_TIMEOUT_MS = 10000;
|
|
|
8
8
|
* trigger's max_active_runs, or one a stop cut short and the next start handed again reaches the host late, and its
|
|
9
9
|
* host gets the same 10 minutes as any. */
|
|
10
10
|
export declare const LAUNCH_HOOK_LATE_START_MS: number;
|
|
11
|
-
/** The hook a server hands its firings to: where, and the secret it signs with. `
|
|
12
|
-
*
|
|
11
|
+
/** The hook a server hands its firings to: where, and the secret it signs with. `bound`: a test's seam, the signal for a
|
|
12
|
+
* POST's bound (LAUNCH_HOOK_TIMEOUT_MS) in place of AbortSignal.timeout. */
|
|
13
13
|
export type LaunchHook = {
|
|
14
14
|
readonly url: string;
|
|
15
15
|
readonly secret: string;
|
|
16
|
-
readonly timeoutMs?: number;
|
|
17
16
|
readonly bound?: (ms: number) => AbortSignal;
|
|
18
17
|
};
|
|
19
18
|
/** What the host is sent for a firing: its id (the message's webhook-id too), its trigger, the agent and the revision a
|
|
@@ -26,15 +25,24 @@ export type HookFiring = {
|
|
|
26
25
|
input: Json;
|
|
27
26
|
fired_at: string;
|
|
28
27
|
};
|
|
29
|
-
/** The host's answer: taken (2xx); or
|
|
30
|
-
*
|
|
28
|
+
/** The host's answer: taken (2xx); or `stopped`, the server's stop cut it short and the firing is left as it was. Any
|
|
29
|
+
* other answer, or none, is a HookFailed. */
|
|
31
30
|
export type Handed = {
|
|
32
31
|
taken: true;
|
|
33
|
-
} | {
|
|
34
|
-
skipped: string;
|
|
35
32
|
} | {
|
|
36
33
|
stopped: true;
|
|
37
34
|
};
|
|
35
|
+
/** Why the hook did not take a firing, a failed try of it (triggers.ts answered): `failure` is the status the host
|
|
36
|
+
* answered, `timeout` or `unreachable`. No answer, no connection, a 5xx or a 429 is `retryable`, tried again under the
|
|
37
|
+
* trigger's retry policy; any other answer fails the firing. Its code is hook_failed, and its words begin with it and
|
|
38
|
+
* the failure, so a firing's error and reason say which. */
|
|
39
|
+
export declare class HookFailed extends Error {
|
|
40
|
+
readonly failure: number | "timeout" | "unreachable";
|
|
41
|
+
name: string;
|
|
42
|
+
readonly code = "hook_failed";
|
|
43
|
+
readonly retryable: boolean;
|
|
44
|
+
constructor(failure: number | "timeout" | "unreachable", why: string);
|
|
45
|
+
}
|
|
38
46
|
/** The launch hook `given` sets (the URL from the environment, the secret as the server holds its own), or undefined when
|
|
39
47
|
* neither is set. Throws, in words that never hold the secret, when one is set without the other, the URL is not https
|
|
40
48
|
* (http only to loopback) or holds a user or password, or the secret is not a `whsec_` secret of MIN_KEY_BYTES or more. */
|
|
@@ -45,5 +53,5 @@ export declare function launchHookFrom(given: {
|
|
|
45
53
|
/** Where `hook` sends, for the start's banner: its origin alone, never a path or query that may hold a token. */
|
|
46
54
|
export declare const hookOrigin: (hook: LaunchHook) => string;
|
|
47
55
|
/** `firing` handed to `hook`: one signed POST of it, stamped at `now` (the triggers' clock), within the hook's bound and
|
|
48
|
-
* cut by `stop`. A redirect is not followed. */
|
|
56
|
+
* cut by `stop`. A redirect is not followed. Throws HookFailed when the host does not take it. */
|
|
49
57
|
export declare function handToHost(hook: LaunchHook, firing: HookFiring, stop: AbortSignal, now?: () => number): Promise<Handed>;
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
// The launch hook: a server started with AGENTRUN_LAUNCH_HOOK_URL and AGENTRUN_LAUNCH_HOOK_SECRET hands each trigger firing
|
|
2
2
|
// that would start a run to the host behind it instead (triggers.ts drive), and starts no run of its own for it. The host
|
|
3
3
|
// starts the run through the API (POST /v2/agents/{agent_id}/runs with `trigger_firing` and its own model_key, keys and
|
|
4
|
-
// max_cost_usd: the firing's run, under its key, triggers.ts handedStart) and answers 2xx,
|
|
5
|
-
// (after: within LAUNCH_HOOK_LATE_START_MS of that 2xx, the firing's start_by)
|
|
6
|
-
//
|
|
4
|
+
// max_cost_usd: the firing's run, under its key, on its trigger's target, triggers.ts handedStart) and answers 2xx,
|
|
5
|
+
// before or after that start (after: within LAUNCH_HOOK_LATE_START_MS of that 2xx, the firing's start_by). Any other
|
|
6
|
+
// answer, or none within LAUNCH_HOOK_TIMEOUT_MS, is a failed try of the firing under its trigger's retry policy
|
|
7
|
+
// (HookFailed), unless the host started its run. Unset, nothing changes.
|
|
7
8
|
// Off this machine the hook is https: a firing's input can carry a person's data, and the signature proves who sent it,
|
|
8
9
|
// not that no one else read it.
|
|
9
10
|
// The POST is signed as the outbound webhook's messages are (standard-webhooks.ts): `webhook-id` (the firing's id, the
|
|
10
11
|
// same each time it is handed), `webhook-timestamp` (Unix seconds) and `webhook-signature: v1,<base64 HMAC-SHA256 of
|
|
11
12
|
// "{id}.{timestamp}.{body}">` under the secret's key, so a host checks it with any Standard Webhooks library.
|
|
12
13
|
import { fetch as undiciFetch } from "undici";
|
|
13
|
-
import { keyBytes, MIN_KEY_BYTES, SECRET_PREFIX,
|
|
14
|
+
import { answerOf, keyBytes, MIN_KEY_BYTES, SECRET_PREFIX, signedRequest } from "./standard-webhooks.js";
|
|
14
15
|
export const LAUNCH_HOOK_URL_ENV = "AGENTRUN_LAUNCH_HOOK_URL";
|
|
15
16
|
export const LAUNCH_HOOK_SECRET_ENV = "AGENTRUN_LAUNCH_HOOK_SECRET";
|
|
16
17
|
/** How long the host has to answer a firing, its connection included. */
|
|
@@ -23,6 +24,21 @@ export const LAUNCH_HOOK_LATE_START_MS = 10 * 60_000;
|
|
|
23
24
|
/** A host this machine alone answers: localhost, 127.0.0.0/8 or ::1, as URL writes them (lower case, IPv4 in four parts,
|
|
24
25
|
* IPv6 in brackets and shortest form). */
|
|
25
26
|
const loopback = (hostname) => hostname === "localhost" || hostname === "[::1]" || /^127(\.\d{1,3}){3}$/.test(hostname);
|
|
27
|
+
/** Why the hook did not take a firing, a failed try of it (triggers.ts answered): `failure` is the status the host
|
|
28
|
+
* answered, `timeout` or `unreachable`. No answer, no connection, a 5xx or a 429 is `retryable`, tried again under the
|
|
29
|
+
* trigger's retry policy; any other answer fails the firing. Its code is hook_failed, and its words begin with it and
|
|
30
|
+
* the failure, so a firing's error and reason say which. */
|
|
31
|
+
export class HookFailed extends Error {
|
|
32
|
+
failure;
|
|
33
|
+
name = "HookFailed";
|
|
34
|
+
code = "hook_failed";
|
|
35
|
+
retryable;
|
|
36
|
+
constructor(failure, why) {
|
|
37
|
+
super(`hook_failed (${failure}): the launch hook ${why}, so its host did not take this firing.`);
|
|
38
|
+
this.failure = failure;
|
|
39
|
+
this.retryable = typeof failure !== "number" || failure >= 500 || failure === 429;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
26
42
|
/** The launch hook `given` sets (the URL from the environment, the secret as the server holds its own), or undefined when
|
|
27
43
|
* neither is set. Throws, in words that never hold the secret, when one is set without the other, the URL is not https
|
|
28
44
|
* (http only to loopback) or holds a user or password, or the secret is not a `whsec_` secret of MIN_KEY_BYTES or more. */
|
|
@@ -58,34 +74,27 @@ export function launchHookFrom(given) {
|
|
|
58
74
|
/** Where `hook` sends, for the start's banner: its origin alone, never a path or query that may hold a token. */
|
|
59
75
|
export const hookOrigin = (hook) => new URL(hook.url).origin;
|
|
60
76
|
/** `firing` handed to `hook`: one signed POST of it, stamped at `now` (the triggers' clock), within the hook's bound and
|
|
61
|
-
* cut by `stop`. A redirect is not followed. */
|
|
77
|
+
* cut by `stop`. A redirect is not followed. Throws HookFailed when the host does not take it. */
|
|
62
78
|
export async function handToHost(hook, firing, stop, now = Date.now) {
|
|
63
|
-
const timeoutMs = hook.timeoutMs ?? LAUNCH_HOOK_TIMEOUT_MS;
|
|
64
79
|
const body = JSON.stringify(firing);
|
|
65
80
|
const timestamp = String(Math.floor(now() / 1000));
|
|
66
|
-
const headers =
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
"webhook-id": firing.firing_id,
|
|
70
|
-
"webhook-timestamp": timestamp,
|
|
71
|
-
"webhook-signature": signatureOf(hook.secret, firing.firing_id, timestamp, body),
|
|
72
|
-
};
|
|
73
|
-
const signal = AbortSignal.any([hook.bound ? hook.bound(timeoutMs) : AbortSignal.timeout(timeoutMs), stop]);
|
|
81
|
+
const headers = signedRequest(hook.secret, firing.firing_id, timestamp, body, "agentrun-serve-launch-hook/1");
|
|
82
|
+
const signal = AbortSignal.any([hook.bound ? hook.bound(LAUNCH_HOOK_TIMEOUT_MS) : AbortSignal.timeout(LAUNCH_HOOK_TIMEOUT_MS), stop]);
|
|
83
|
+
let res;
|
|
74
84
|
try {
|
|
75
|
-
|
|
76
|
-
// The answer's body is not read: the run the host started is found by the firing's key, never by what it says.
|
|
77
|
-
await res.body?.cancel().catch(() => undefined);
|
|
78
|
-
if (res.status >= 200 && res.status <= 299)
|
|
79
|
-
return { taken: true };
|
|
80
|
-
const said = res.status >= 300 && res.status < 400 ? `answered ${res.status}: a redirect is not followed` : `answered ${res.status}`;
|
|
81
|
-
return { skipped: `The launch hook ${said}, so the host did not take this firing.` };
|
|
85
|
+
res = await undiciFetch(hook.url, { method: "POST", redirect: "manual", signal, headers, body });
|
|
82
86
|
}
|
|
83
87
|
catch (error) {
|
|
84
88
|
if (stop.aborted)
|
|
85
89
|
return { stopped: true };
|
|
86
90
|
if (error.name === "TimeoutError" || signal.aborted)
|
|
87
|
-
|
|
91
|
+
throw new HookFailed("timeout", `did not answer in ${LAUNCH_HOOK_TIMEOUT_MS / 1000} s`);
|
|
88
92
|
const code = error.cause?.code;
|
|
89
|
-
|
|
93
|
+
throw new HookFailed("unreachable", `was not reached${typeof code === "string" ? ` (${code})` : ""}`);
|
|
90
94
|
}
|
|
95
|
+
// The answer's body is not read: the run the host started is found by the firing's key, never by what it says.
|
|
96
|
+
const failure = await answerOf(res);
|
|
97
|
+
if (failure === undefined)
|
|
98
|
+
return { taken: true };
|
|
99
|
+
throw new HookFailed(res.status, failure);
|
|
91
100
|
}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { ApiError, type InputIssue } from "./errors.js";
|
|
2
|
-
import { type RunMoment, type RunsStore, type StartDeps } from "./runs-over-store.js";
|
|
2
|
+
import { type RunMoment, type RunsStore, type StartDeps, type StartOptions } from "./runs-over-store.js";
|
|
3
3
|
import type { Store } from "./store/index.js";
|
|
4
4
|
import type { AgentEntry } from "./agents-store.js";
|
|
5
5
|
import type { MessageOrigin } from "./timeline/index.js";
|
|
6
|
-
import type
|
|
6
|
+
import { type Json } from "./validate.js";
|
|
7
7
|
import type { RunTrigger, Target } from "./triggers.js";
|
|
8
|
-
/** Why a trigger may not message a run on a harness recipe billed to its vendor's plan
|
|
9
|
-
* does, on its owner's own sign-in, which runs
|
|
10
|
-
*
|
|
11
|
-
|
|
8
|
+
/** Why a trigger may not message a run on a harness recipe billed to its vendor's plan while not every key it runs on is
|
|
9
|
+
* saved for that harness (harness-keys.ts): the turn would run as that run does, on its owner's own sign-in, which runs
|
|
10
|
+
* only what a person starts (HARNESS.md#run-it); a trigger's turn runs on the saved keys alone (the claim's
|
|
11
|
+
* RECIPE_SIGN_IN_PERSON_ONLY, for a new run). */
|
|
12
|
+
export declare const RECIPE_MESSAGE_PERSON_ONLY = "The run is on a harness recipe billed to its vendor's plan, which runs on its owner's own sign-in only for what a person starts: a trigger's turn runs on keys saved for that harness, and not every one is saved. Save them in Settings \u2192 Harness keys, message the run yourself, or target a run on a harness billed through this server's model proxy.";
|
|
12
13
|
/** What the trigger target policy needs that lives elsewhere: the run-start leaves (StartDeps, shared with the create
|
|
13
14
|
* route), the agent reads, and the run view that gives a run's live moment and its v2 status. */
|
|
14
15
|
export interface TriggerTargetDeps {
|
|
@@ -24,7 +25,7 @@ export interface TriggerTargetDeps {
|
|
|
24
25
|
* for an unknown run. */
|
|
25
26
|
momentOf(runId: string): Promise<RunMoment | undefined>;
|
|
26
27
|
/** Whether `harness` is a harness recipe billed to its vendor's plan in this server's table (harness-table.ts
|
|
27
|
-
* recipeHarness): a trigger never messages a run on one. Absent: none is. */
|
|
28
|
+
* recipeHarness) whose keys are not all saved (harness-keys.ts): a trigger never messages a run on one. Absent: none is. */
|
|
28
29
|
planRecipe?(harness: string): boolean;
|
|
29
30
|
/** `work`, a write that may open run `runId` of agent `agentId` again, done in the agent's delete turn (server.ts
|
|
30
31
|
* runWrite): never under a purge of the run, and 410 purged after one. */
|
|
@@ -74,6 +75,15 @@ export type PreviousHandover = {
|
|
|
74
75
|
dropped?: Record<string, number>;
|
|
75
76
|
};
|
|
76
77
|
export declare function previousHandover(runId: string, done: CompletedOutput): PreviousHandover;
|
|
78
|
+
/** What a launch hook's host lays over the run it starts for a firing it was handed (RunCreate `trigger_firing`): its
|
|
79
|
+
* create body (its input, which the trigger's previous result follows, the run's other fields, and its own
|
|
80
|
+
* max_cost_usd: handedCap), and the launch secrets it carries (`sealed`: its model_key, keys and mcp_auth, sealed for
|
|
81
|
+
* the run; `keys`: the keys' names). Its effort is taken only when the target sets none. */
|
|
82
|
+
export type HostStart = {
|
|
83
|
+
readonly body: Json;
|
|
84
|
+
readonly sealed?: StartOptions["sealed"];
|
|
85
|
+
readonly keys?: StartOptions["keys"];
|
|
86
|
+
};
|
|
77
87
|
/** The trigger-facing run policy: the subset of the trigger engine's deps this module owns. The engine's other deps (an
|
|
78
88
|
* adapter's sealed settings, the failed-firing webhook) stay server-wired. */
|
|
79
89
|
export type TriggerTargets = {
|
|
@@ -81,7 +91,7 @@ export type TriggerTargets = {
|
|
|
81
91
|
targetRefusal(target: Target): Promise<ApiError | undefined>;
|
|
82
92
|
start(target: Extract<Target, {
|
|
83
93
|
kind: "start_run";
|
|
84
|
-
}>, input:
|
|
94
|
+
}>, input: unknown, origin: RunTrigger, from: MessageOrigin, title: string | undefined, previous: boolean, host?: HostStart): Promise<{
|
|
85
95
|
run_id: string;
|
|
86
96
|
}>;
|
|
87
97
|
message(target: Extract<Target, {
|