@parcha/agentrun-serve 0.1.0-beta.54 → 0.1.0-beta.55
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 +110 -2
- package/README.md +266 -88
- package/dist/adapters.d.ts +10 -0
- package/dist/adapters.js +46 -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/api-only.d.ts +16 -4
- package/dist/api-only.js +21 -7
- 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-D5EmB4N3.js +166 -0
- package/dist/console/assets/index-DUYLaqiR.js +746 -0
- package/dist/console/assets/index-DYhU4adm.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 +2 -0
- package/dist/host-check.js +6 -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/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.js +10 -2
- package/dist/learning-routes.d.ts +22 -17
- package/dist/learning-routes.js +40 -39
- package/dist/learning.js +2 -2
- 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.js +127 -37
- package/dist/page.d.ts +11 -3
- package/dist/page.js +22 -7
- package/dist/place-offers.d.ts +17 -1
- package/dist/place-offers.js +46 -5
- package/dist/print.js +1 -1
- package/dist/purged-workflow.d.ts +35 -7
- package/dist/purged-workflow.js +73 -26
- 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/runner/adapter-loop.d.ts +6 -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 +5 -3
- package/dist/runner/audit.js +8 -4
- package/dist/runner/beside.d.ts +2 -1
- package/dist/runner/beside.js +6 -2
- 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 +38 -6
- 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 +5 -4
- package/dist/runner/main.js +4 -2
- 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/promotion.d.ts +15 -9
- package/dist/runner/promotion.js +25 -15
- package/dist/runner/run-child-host.js +17 -7
- package/dist/runner/run-child.js +3 -1
- 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 +44 -8
- package/dist/server.js +283 -108
- package/dist/standard-webhooks.d.ts +11 -0
- package/dist/standard-webhooks.js +20 -2
- package/dist/store/index.d.ts +1 -1
- package/dist/store/schema.js +5 -2
- package/dist/store/sqlite/store.js +90 -34
- package/dist/store/store.d.ts +54 -14
- 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 +9 -8
- package/dist/template-eval.d.ts +49 -4
- package/dist/template-eval.js +168 -45
- package/dist/template-import.js +4 -2
- package/dist/templates.d.ts +5 -3
- package/dist/templates.js +19 -40
- package/dist/timeline/labels.d.ts +2 -2
- package/dist/timeline/labels.js +2 -2
- package/dist/timeline/timeline.d.ts +2 -2
- package/dist/timeline/timeline.js +1 -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/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/launcher/agentrun-serve +5 -1
- package/package.json +17 -13
- package/templates/README.md +2 -2
- 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
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, {
|
package/dist/trigger-targets.js
CHANGED
|
@@ -9,12 +9,14 @@ import { message, startRun, WAITS_ON_A_PERSON } from "./runs-over-store.js";
|
|
|
9
9
|
import { runOfOrigin } from "./store-reads/runs.js";
|
|
10
10
|
import { NATIVE_CAP_UNSUPPORTED, NATIVE_RUN_OVERRIDES_UNSUPPORTED, nativeOf, nativeRunOverrides } from "./native/binding.js";
|
|
11
11
|
import { firingsOwe, keysOwedRefusal } from "./run-keys.js";
|
|
12
|
+
import { isObject } from "./validate.js";
|
|
12
13
|
/** Why a trigger may not message a run with no cap (server.ts NO_CAP). */
|
|
13
14
|
const NO_CAP = "The run has no spend cap: a trigger only messages a run with one, as every turn it drives is capped.";
|
|
14
|
-
/** Why a trigger may not message a run on a harness recipe billed to its vendor's plan
|
|
15
|
-
* does, on its owner's own sign-in, which runs
|
|
16
|
-
*
|
|
17
|
-
|
|
15
|
+
/** 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
|
|
16
|
+
* saved for that harness (harness-keys.ts): the turn would run as that run does, on its owner's own sign-in, which runs
|
|
17
|
+
* only what a person starts (HARNESS.md#run-it); a trigger's turn runs on the saved keys alone (the claim's
|
|
18
|
+
* RECIPE_SIGN_IN_PERSON_ONLY, for a new run). */
|
|
19
|
+
export 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 → Harness keys, message the run yourself, or target a run on a harness billed through this server's model proxy.";
|
|
18
20
|
/** The most of a trigger's firings, newest first, read for its last completed run. */
|
|
19
21
|
const PREVIOUS_FIRINGS_READ = 20;
|
|
20
22
|
/** The most bytes of a previous run's result a triggered run is handed, as JSON: past it, it is handed none, said so. */
|
|
@@ -112,18 +114,30 @@ function carriedEntryBytes(entry) {
|
|
|
112
114
|
lines += 1;
|
|
113
115
|
return 4 + Buffer.byteLength(json) + 4 * lines;
|
|
114
116
|
}
|
|
117
|
+
/** A handed run's cap: its bound (the target's cap, else the agent's default on the revision the run starts on), which a
|
|
118
|
+
* host's own may lower and never raise; with no bound, the host's. A host's value that is no number is passed on, for
|
|
119
|
+
* the run's checks to refuse. */
|
|
120
|
+
function handedCap(bound, host) {
|
|
121
|
+
if (bound === undefined || host === undefined)
|
|
122
|
+
return bound ?? host;
|
|
123
|
+
return typeof host === "number" ? Math.min(bound, host) : host;
|
|
124
|
+
}
|
|
115
125
|
/** The trigger target policy over `store`, with its reads and the run-start leaves injected. */
|
|
116
126
|
export function triggerTargets(store, deps) {
|
|
127
|
+
/** Under the run-keys setting, the 409 for a trigger whose firings could never bring the keys its runs owe (firingsOwe):
|
|
128
|
+
* at its create or move, and again at each message_run firing, since one made before the setting was on, or while this
|
|
129
|
+
* server held the key, would open a turn with none. */
|
|
130
|
+
async function targetRefusal(target) {
|
|
131
|
+
if (!deps.keysOwed)
|
|
132
|
+
return undefined;
|
|
133
|
+
// The revision a firing would open a turn of: the run's own for a message_run, the agent's current for a start_run.
|
|
134
|
+
const row = target.kind === "message_run" ? await store.runs.get(target.run_id) : undefined;
|
|
135
|
+
const revision = target.kind === "message_run" ? (row ? await store.agents.revision(row.revisionId) : undefined) : (await deps.getAgent(target.agent_id))?.revision;
|
|
136
|
+
const owed = revision ? deps.keysOwed(revision) : [];
|
|
137
|
+
return firingsOwe(owed, target.kind, deps.hooked === true) ? keysOwedRefusal(owed) : undefined;
|
|
138
|
+
}
|
|
117
139
|
return {
|
|
118
|
-
|
|
119
|
-
if (!deps.keysOwed)
|
|
120
|
-
return undefined;
|
|
121
|
-
// The revision a firing would open a turn of: the run's own for a message_run, the agent's current for a start_run.
|
|
122
|
-
const row = target.kind === "message_run" ? await store.runs.get(target.run_id) : undefined;
|
|
123
|
-
const revision = target.kind === "message_run" ? (row ? await store.agents.revision(row.revisionId) : undefined) : (await deps.getAgent(target.agent_id))?.revision;
|
|
124
|
-
const owed = revision ? deps.keysOwed(revision) : [];
|
|
125
|
-
return firingsOwe(owed, target.kind, deps.hooked === true) ? keysOwedRefusal(owed) : undefined;
|
|
126
|
-
},
|
|
140
|
+
targetRefusal,
|
|
127
141
|
async targetIssues(target) {
|
|
128
142
|
if (target.kind === "message_run") {
|
|
129
143
|
const run = await deps.momentOf(target.run_id);
|
|
@@ -158,20 +172,26 @@ export function triggerTargets(store, deps) {
|
|
|
158
172
|
const wrong = revision ? await deps.start.explainRun(await deps.start.inputIssuesOf(revision, target.input), { input: target.input }, revision) : [];
|
|
159
173
|
return [...start, ...wrong.map((issue) => ({ ...issue, field: `target.${issue.field}` }))];
|
|
160
174
|
},
|
|
161
|
-
async start(target, given, trigger, from, title, previous) {
|
|
175
|
+
async start(target, given, trigger, from, title, previous, host) {
|
|
162
176
|
const entry = await deps.needAgent(target.agent_id);
|
|
163
177
|
// An agentic run is handed its trigger's previous result after its message (previousResultOf), so a repeat run
|
|
164
178
|
// (a weekly digest) leaves out what the last one reported. A workflow's input is its own schema's: nothing is added.
|
|
165
179
|
// `previous` is its adapter's previousResult (carriesPrevious).
|
|
166
|
-
const content = given.content;
|
|
180
|
+
const content = isObject(given) ? given.content : undefined;
|
|
167
181
|
const handed = previous && entry.revision?.kind === "agentic" && typeof content === "string" ? await previousResultOf(store, deps, trigger) : "";
|
|
168
182
|
const input = handed ? { ...given, content: `${content}${handed}` } : given;
|
|
169
|
-
// The target's cap, else the agent's default as it stands now
|
|
170
|
-
//
|
|
183
|
+
// The target's cap, else the agent's default as it stands now on the revision the run starts on, either of which a
|
|
184
|
+
// host's may lower and never raise: a run a trigger starts is never uncapped (capped), but a connected agent's,
|
|
185
|
+
// which its own CLI's limits keep and AgentRun can't cap (NATIVE_CAP_UNSUPPORTED). The effort is the target's when
|
|
186
|
+
// it sets one, else the host's, else the agent's.
|
|
171
187
|
const native = Boolean(nativeOf(entry.revision?.body));
|
|
172
|
-
const
|
|
188
|
+
const { max_cost_usd: hostCap, ...overlay } = host?.body ?? {};
|
|
189
|
+
const body = { ...overlay, ...(input !== undefined ? { input } : {}) };
|
|
190
|
+
const agentCap = target.max_cost_usd === undefined && typeof hostCap === "number" ? (await deps.start.pinnedOf(entry, body))?.revision.body?.maxCostUsd : undefined;
|
|
191
|
+
const cap = handedCap(target.max_cost_usd ?? agentCap, hostCap);
|
|
192
|
+
const run = await startRun(store, deps.start, entry, { ...body, ...(cap !== undefined ? { max_cost_usd: cap } : {}), ...(target.effort ? { effort: target.effort } : {}) },
|
|
173
193
|
// Titled from the trigger (the engine's titleOf: "<Source> <name>"), never from its input, a sender's markup.
|
|
174
|
-
{ trigger, origin: { key: trigger.firing_key }, capped: !native, from, ...(title ? { title } : {}) });
|
|
194
|
+
{ trigger, origin: { key: trigger.firing_key }, capped: !native, from, ...(title ? { title } : {}), ...(host?.sealed ? { sealed: host.sealed } : {}), ...(host?.keys ? { keys: host.keys } : {}) });
|
|
175
195
|
return { run_id: run.id };
|
|
176
196
|
},
|
|
177
197
|
async message(target, input, key, from, bound) {
|
|
@@ -190,6 +210,9 @@ export function triggerTargets(store, deps) {
|
|
|
190
210
|
throw new ApiError("not_continuable", NO_CAP);
|
|
191
211
|
if (run.waitsOnPerson)
|
|
192
212
|
return { skipped: WAITS_ON_A_PERSON };
|
|
213
|
+
const owes = await targetRefusal(target);
|
|
214
|
+
if (owes)
|
|
215
|
+
throw owes;
|
|
193
216
|
try {
|
|
194
217
|
// The firing's key is the message's id; the message answers no person (answers false), its origin the trigger's.
|
|
195
218
|
// Its command row is written with its firing marked sent, in one transaction, within the trigger's bound per run
|