@parcha/agentrun-serve 0.1.0-beta.53 → 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.
Files changed (224) hide show
  1. package/CHANGELOG.md +138 -3
  2. package/README.md +346 -99
  3. package/dist/adapters.d.ts +10 -0
  4. package/dist/adapters.js +46 -0
  5. package/dist/agent-package.d.ts +3 -3
  6. package/dist/agent-package.js +7 -14
  7. package/dist/agent-rows.d.ts +1 -1
  8. package/dist/agents-store.js +7 -6
  9. package/dist/api-only.d.ts +17 -6
  10. package/dist/api-only.js +22 -9
  11. package/dist/cli.js +11 -4
  12. package/dist/composio-made.d.ts +26 -1
  13. package/dist/composio-made.js +39 -2
  14. package/dist/composio-preset.d.ts +6 -4
  15. package/dist/composio-preset.js +50 -17
  16. package/dist/computer-held-routes.js +2 -3
  17. package/dist/computer-needs.d.ts +1 -1
  18. package/dist/computer-needs.js +1 -1
  19. package/dist/computer-setting.d.ts +8 -4
  20. package/dist/computer-setting.js +0 -2
  21. package/dist/computers-running.d.ts +8 -0
  22. package/dist/computers-running.js +27 -0
  23. package/dist/computers.d.ts +0 -2
  24. package/dist/computers.js +1 -1
  25. package/dist/console/assets/backend-D5EmB4N3.js +166 -0
  26. package/dist/console/assets/index-DUYLaqiR.js +746 -0
  27. package/dist/console/assets/index-DYhU4adm.css +1 -0
  28. package/dist/console/index.html +2 -2
  29. package/dist/docker-host-addresses.d.ts +23 -3
  30. package/dist/docker-host-addresses.js +90 -18
  31. package/dist/errors.d.ts +4 -0
  32. package/dist/errors.js +7 -0
  33. package/dist/exa-keyless.d.ts +2 -3
  34. package/dist/exa-keyless.js +43 -127
  35. package/dist/firecrawl-keyless.d.ts +41 -0
  36. package/dist/firecrawl-keyless.js +152 -0
  37. package/dist/github-connection.d.ts +50 -1
  38. package/dist/github-connection.js +96 -3
  39. package/dist/github-faux.d.ts +11 -2
  40. package/dist/github-faux.js +138 -7
  41. package/dist/github-pull-request.d.ts +37 -0
  42. package/dist/github-pull-request.js +110 -0
  43. package/dist/handed-secret.d.ts +3 -1
  44. package/dist/handed-secret.js +4 -2
  45. package/dist/harness-keys.d.ts +98 -0
  46. package/dist/harness-keys.js +247 -0
  47. package/dist/harness-recipe-entry.d.ts +14 -9
  48. package/dist/harness-recipe-entry.js +25 -14
  49. package/dist/harness-table.d.ts +16 -1
  50. package/dist/harness-table.js +19 -7
  51. package/dist/harness.d.ts +4 -0
  52. package/dist/harness.js +12 -1
  53. package/dist/host-check.d.ts +2 -0
  54. package/dist/host-check.js +6 -0
  55. package/dist/import-summary.d.ts +1 -1
  56. package/dist/import-summary.js +1 -1
  57. package/dist/import.d.ts +5 -5
  58. package/dist/import.js +54 -67
  59. package/dist/keyless-mcp.d.ts +36 -0
  60. package/dist/keyless-mcp.js +127 -0
  61. package/dist/learn/audit.d.ts +3 -3
  62. package/dist/learn/audit.js +3 -3
  63. package/dist/learn/commit.d.ts +8 -7
  64. package/dist/learn/commit.js +60 -20
  65. package/dist/learn/compile.d.ts +4 -3
  66. package/dist/learn/compile.js +7 -5
  67. package/dist/learn/folder.d.ts +16 -3
  68. package/dist/learn/folder.js +46 -13
  69. package/dist/learn/promote.d.ts +37 -13
  70. package/dist/learn/promote.js +112 -40
  71. package/dist/learn/secrets.js +10 -2
  72. package/dist/learning-routes.d.ts +22 -17
  73. package/dist/learning-routes.js +40 -39
  74. package/dist/learning.js +2 -2
  75. package/dist/live-reach.d.ts +34 -7
  76. package/dist/live-reach.js +76 -11
  77. package/dist/manifest.d.ts +10 -0
  78. package/dist/manifest.js +30 -0
  79. package/dist/mcp-pin-first.d.ts +4 -2
  80. package/dist/mcp-pin-first.js +5 -2
  81. package/dist/mcp-probe.js +2 -2
  82. package/dist/mcp-secret-writes.d.ts +16 -7
  83. package/dist/mcp-secret-writes.js +35 -27
  84. package/dist/mcp-servers-store.d.ts +30 -6
  85. package/dist/mcp-servers-store.js +112 -28
  86. package/dist/mcp-sources.d.ts +10 -2
  87. package/dist/mcp-sources.js +9 -2
  88. package/dist/mcp-store.d.ts +13 -7
  89. package/dist/mcp-store.js +12 -9
  90. package/dist/model-form.d.ts +3 -2
  91. package/dist/model-form.js +11 -7
  92. package/dist/model.d.ts +20 -4
  93. package/dist/model.js +68 -9
  94. package/dist/native/history.d.ts +1 -1
  95. package/dist/native/history.js +2 -2
  96. package/dist/ollama-provider.d.ts +92 -0
  97. package/dist/ollama-provider.js +495 -0
  98. package/dist/openapi/agentrun-v2.openapi.json +2 -2
  99. package/dist/openapi.js +235 -41
  100. package/dist/page.d.ts +11 -3
  101. package/dist/page.js +22 -7
  102. package/dist/place-offers.d.ts +17 -1
  103. package/dist/place-offers.js +46 -5
  104. package/dist/print.js +1 -1
  105. package/dist/purged-workflow.d.ts +35 -7
  106. package/dist/purged-workflow.js +73 -26
  107. package/dist/run-computer.d.ts +2 -0
  108. package/dist/run-computer.js +2 -0
  109. package/dist/run-files.d.ts +4 -0
  110. package/dist/run-files.js +4 -0
  111. package/dist/run-keys.d.ts +2 -4
  112. package/dist/run-keys.js +6 -7
  113. package/dist/run-launch.d.ts +4 -0
  114. package/dist/run-launch.js +4 -0
  115. package/dist/run-reads-over-store.d.ts +3 -2
  116. package/dist/run-reads-over-store.js +66 -2
  117. package/dist/run-secrets.js +5 -2
  118. package/dist/runner/adapter-loop.d.ts +6 -3
  119. package/dist/runner/adapter-loop.js +34 -15
  120. package/dist/runner/adapter-run-spec.d.ts +3 -0
  121. package/dist/runner/adapter-run-spec.js +6 -4
  122. package/dist/runner/audit.js +8 -4
  123. package/dist/runner/beside.d.ts +2 -1
  124. package/dist/runner/beside.js +6 -2
  125. package/dist/runner/claim-secrets.d.ts +5 -8
  126. package/dist/runner/claim-secrets.js +6 -0
  127. package/dist/runner/cli-run-spec.d.ts +1 -1
  128. package/dist/runner/cli-run-spec.js +39 -7
  129. package/dist/runner/harness-loops.d.ts +22 -9
  130. package/dist/runner/harness-loops.js +21 -11
  131. package/dist/runner/held.d.ts +3 -0
  132. package/dist/runner/learning-end.d.ts +1 -1
  133. package/dist/runner/learning-end.js +8 -3
  134. package/dist/runner/loop-contract.d.ts +5 -4
  135. package/dist/runner/main.js +4 -2
  136. package/dist/runner/mcp-claim.d.ts +3 -0
  137. package/dist/runner/mcp-claim.js +26 -2
  138. package/dist/runner/mcp-run.d.ts +3 -0
  139. package/dist/runner/mcp-run.js +2 -1
  140. package/dist/runner/metrics.d.ts +10 -8
  141. package/dist/runner/metrics.js +20 -27
  142. package/dist/runner/model-route.d.ts +3 -0
  143. package/dist/runner/model-route.js +6 -2
  144. package/dist/runner/pr-checkout.d.ts +21 -4
  145. package/dist/runner/pr-checkout.js +103 -4
  146. package/dist/runner/promotion.d.ts +15 -9
  147. package/dist/runner/promotion.js +25 -15
  148. package/dist/runner/run-child-host.js +24 -11
  149. package/dist/runner/run-child.js +3 -1
  150. package/dist/runner/runner-check.d.ts +3 -0
  151. package/dist/runner/runner-check.js +23 -0
  152. package/dist/runner/sdk-loop.js +2 -0
  153. package/dist/runner/workflow-loop.d.ts +2 -2
  154. package/dist/runner/workflow-loop.js +1 -2
  155. package/dist/runner/workflow-spec.d.ts +1 -1
  156. package/dist/runner/workflow-spec.js +6 -6
  157. package/dist/sdk/check.d.ts +4 -1
  158. package/dist/sdk/check.js +2 -1
  159. package/dist/sdk/runs.d.ts +2 -2
  160. package/dist/sdk/runs.js +8 -6
  161. package/dist/secret-cut.js +2 -1
  162. package/dist/secret-writes.d.ts +3 -2
  163. package/dist/secret-writes.js +1 -1
  164. package/dist/server.d.ts +55 -8
  165. package/dist/server.js +363 -118
  166. package/dist/standard-webhooks.d.ts +11 -0
  167. package/dist/standard-webhooks.js +20 -2
  168. package/dist/store/agent-body.d.ts +2 -2
  169. package/dist/store/agent-body.js +2 -2
  170. package/dist/store/index.d.ts +1 -1
  171. package/dist/store/schema.js +5 -2
  172. package/dist/store/sqlite/store.js +90 -34
  173. package/dist/store/store.d.ts +54 -14
  174. package/dist/store-reads/journal.d.ts +7 -2
  175. package/dist/store-reads/journal.js +9 -6
  176. package/dist/store-reads/learning.d.ts +12 -9
  177. package/dist/store-reads/learning.js +18 -24
  178. package/dist/store-view.d.ts +0 -5
  179. package/dist/store-view.js +9 -8
  180. package/dist/suggestions.d.ts +282 -0
  181. package/dist/suggestions.js +919 -0
  182. package/dist/telemetry.d.ts +8 -1
  183. package/dist/telemetry.js +12 -4
  184. package/dist/template-eval.d.ts +49 -4
  185. package/dist/template-eval.js +168 -45
  186. package/dist/template-import.d.ts +17 -0
  187. package/dist/template-import.js +36 -2
  188. package/dist/templates.d.ts +83 -76
  189. package/dist/templates.js +29 -48
  190. package/dist/timeline/labels.d.ts +2 -2
  191. package/dist/timeline/labels.js +2 -2
  192. package/dist/timeline/timeline.d.ts +2 -2
  193. package/dist/timeline/timeline.js +1 -1
  194. package/dist/tool-plane.d.ts +17 -9
  195. package/dist/tool-plane.js +38 -17
  196. package/dist/tools.js +2 -2
  197. package/dist/trigger-launch-hook.d.ts +19 -9
  198. package/dist/trigger-launch-hook.js +35 -25
  199. package/dist/trigger-targets.d.ts +18 -8
  200. package/dist/trigger-targets.js +42 -19
  201. package/dist/triggers.d.ts +85 -23
  202. package/dist/triggers.js +303 -96
  203. package/dist/validate.d.ts +1 -1
  204. package/dist/validate.js +2 -2
  205. package/dist/web-fake.js +3 -3
  206. package/dist/web-fetch-direct.d.ts +4 -0
  207. package/dist/web-fetch-direct.js +8 -1
  208. package/dist/web-fetch.d.ts +12 -3
  209. package/dist/web-fetch.js +47 -14
  210. package/dist/web-search.d.ts +33 -4
  211. package/dist/web-search.js +100 -41
  212. package/dist/webhooks.js +4 -5
  213. package/dist/workspace/synced-folder.d.ts +1 -1
  214. package/dist/workspace/synced-folder.js +11 -14
  215. package/launcher/agentrun-serve +5 -1
  216. package/package.json +17 -13
  217. package/templates/README.md +5 -4
  218. package/templates/agent-scout/agent.md +46 -0
  219. package/templates/agent-scout/skills/scout/SKILL.md +88 -0
  220. package/templates/agent-scout/skills/scout/suggestions.schema.json +112 -0
  221. package/dist/console/assets/index-BFgyZzF_.js +0 -734
  222. package/dist/console/assets/index-DbilxljH.css +0 -1
  223. package/dist/import-sources.d.ts +0 -116
  224. package/dist/import-sources.js +0 -693
@@ -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 kernel's keyless fallback: web_fetch's guarded direct fetch, and web_search on Exa's public keyless MCP
7
- // endpoint (exa-keyless.ts). On claude-agent `auto` skips (2): Claude's own search is an explicit pick, `native`. Codex's
8
- // own search on codex, Parallel or keyless Exa behind a gateway, on OpenRouter or under a spend cap;
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 Exa. A grant names a capability, never a provider. A pick of parallel without
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
- /** The providers a user may pick for each capability that has a choice, its default first: `auto`, the native search
46
- * where there is one (never on claude-agent, where Claude's own search is picked as `native`), else Parallel where the
47
- * server holds its key, else keyless Exa; `native`, the harness's own tool or its model provider's hosted one, and
48
- * nothing else; `exa-keyless`, Exa's public MCP endpoint, no key; `kernel`, the guarded direct fetch; `parallel`,
49
- * Parallel's Search and Extract APIs on PARALLEL_API_KEY; `off`, web_search turned off: nothing is searched, and an
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: ["kernel", "parallel"], browser: Object.freeze(["auto", ...browserProviderIds(), "chrome"]) });
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 Exa.
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
- return { resolves: "kernel", why: "the guarded direct fetch" };
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 Exa.
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: "exa-keyless", why: `Exa's free keyless search, no key; ${facts.label}'s own search is an explicit pick` };
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: "exa-keyless", why: `${none.why}; Exa's free keyless search, no key` };
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 Exa, or Parallel where picked), never on a model a node may not use.
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 Exa's keyless search; 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.",
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,12 @@ 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. `timeoutMs`: a test's bound, else
12
- * LAUNCH_HOOK_TIMEOUT_MS. */
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;
16
+ readonly bound?: (ms: number) => AbortSignal;
17
17
  };
18
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
19
19
  * run would start on now, the run's input as the trigger gives it, and the firing's time. */
@@ -25,15 +25,24 @@ export type HookFiring = {
25
25
  input: Json;
26
26
  fired_at: string;
27
27
  };
28
- /** The host's answer: taken (2xx); or why the firing is skipped; or `stopped`, the server's stop cut it short and the
29
- * firing is left as it was. */
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. */
30
30
  export type Handed = {
31
31
  taken: true;
32
- } | {
33
- skipped: string;
34
32
  } | {
35
33
  stopped: true;
36
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
+ }
37
46
  /** The launch hook `given` sets (the URL from the environment, the secret as the server holds its own), or undefined when
38
47
  * neither is set. Throws, in words that never hold the secret, when one is set without the other, the URL is not https
39
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. */
@@ -43,5 +52,6 @@ export declare function launchHookFrom(given: {
43
52
  }): LaunchHook | undefined;
44
53
  /** Where `hook` sends, for the start's banner: its origin alone, never a path or query that may hold a token. */
45
54
  export declare const hookOrigin: (hook: LaunchHook) => string;
46
- /** `firing` handed to `hook`: one signed POST of it, within the hook's bound and cut by `stop`. A redirect is not followed. */
47
- export declare function handToHost(hook: LaunchHook, firing: HookFiring, stop: AbortSignal): Promise<Handed>;
55
+ /** `firing` handed to `hook`: one signed POST of it, stamped at `now` (the triggers' clock), within the hook's bound and
56
+ * cut by `stop`. A redirect is not followed. Throws HookFailed when the host does not take it. */
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, before or after that start
5
- // (after: within LAUNCH_HOOK_LATE_START_MS of that 2xx, the firing's start_by); any other answer, or none within
6
- // LAUNCH_HOOK_TIMEOUT_MS, and the firing is skipped with why, unless the host started its run. Unset, nothing changes.
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, signatureOf } from "./standard-webhooks.js";
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. */
@@ -57,34 +73,28 @@ export function launchHookFrom(given) {
57
73
  }
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
- /** `firing` handed to `hook`: one signed POST of it, within the hook's bound and cut by `stop`. A redirect is not followed. */
61
- export async function handToHost(hook, firing, stop) {
62
- const timeoutMs = hook.timeoutMs ?? LAUNCH_HOOK_TIMEOUT_MS;
76
+ /** `firing` handed to `hook`: one signed POST of it, stamped at `now` (the triggers' clock), within the hook's bound and
77
+ * cut by `stop`. A redirect is not followed. Throws HookFailed when the host does not take it. */
78
+ export async function handToHost(hook, firing, stop, now = Date.now) {
63
79
  const body = JSON.stringify(firing);
64
- const timestamp = String(Math.floor(Date.now() / 1000));
65
- const headers = {
66
- "content-type": "application/json",
67
- "user-agent": "agentrun-serve-launch-hook/1",
68
- "webhook-id": firing.firing_id,
69
- "webhook-timestamp": timestamp,
70
- "webhook-signature": signatureOf(hook.secret, firing.firing_id, timestamp, body),
71
- };
72
- const signal = AbortSignal.any([AbortSignal.timeout(timeoutMs), stop]);
80
+ const timestamp = String(Math.floor(now() / 1000));
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;
73
84
  try {
74
- const res = await undiciFetch(hook.url, { method: "POST", redirect: "manual", signal, headers, body });
75
- // The answer's body is not read: the run the host started is found by the firing's key, never by what it says.
76
- await res.body?.cancel().catch(() => undefined);
77
- if (res.status >= 200 && res.status <= 299)
78
- return { taken: true };
79
- const said = res.status >= 300 && res.status < 400 ? `answered ${res.status}: a redirect is not followed` : `answered ${res.status}`;
80
- 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 });
81
86
  }
82
87
  catch (error) {
83
88
  if (stop.aborted)
84
89
  return { stopped: true };
85
90
  if (error.name === "TimeoutError" || signal.aborted)
86
- return { skipped: `The launch hook did not answer in ${timeoutMs / 1000} s, so the host did not take this firing.` };
91
+ throw new HookFailed("timeout", `did not answer in ${LAUNCH_HOOK_TIMEOUT_MS / 1000} s`);
87
92
  const code = error.cause?.code;
88
- return { skipped: `The launch hook was not reached${typeof code === "string" ? ` (${code})` : ""}, so the host did not take this firing.` };
93
+ throw new HookFailed("unreachable", `was not reached${typeof code === "string" ? ` (${code})` : ""}`);
89
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);
90
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 { Json } from "./validate.js";
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: the turn would run as that run
9
- * does, on its owner's own sign-in, which runs only what a person starts (HARNESS.md#run-it), and a scheduled turn runs
10
- * on keys saved for the harness, which no server saves yet (the claim's RECIPE_SIGN_IN_PERSON_ONLY, for a new run). */
11
- 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 this server saves no harness's keys yet. Message the run yourself, or target a run on a harness billed through this server's model proxy.";
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: Json, origin: RunTrigger, from: MessageOrigin, title: string | undefined, previous: boolean): Promise<{
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, {
@@ -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: the turn would run as that run
15
- * does, on its owner's own sign-in, which runs only what a person starts (HARNESS.md#run-it), and a scheduled turn runs
16
- * on keys saved for the harness, which no server saves yet (the claim's RECIPE_SIGN_IN_PERSON_ONLY, for a new run). */
17
- 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 this server saves no harness's keys yet. Message the run yourself, or target a run on a harness billed through this server's model proxy.";
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
- async targetRefusal(target) {
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: a run a trigger starts is never uncapped (capped),
170
- // but a connected agent's, which its own CLI's limits keep and AgentRun can't cap (NATIVE_CAP_UNSUPPORTED).
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 run = await startRun(store, deps.start, entry, { input, ...(target.max_cost_usd !== undefined ? { max_cost_usd: target.max_cost_usd } : {}), ...(target.effort ? { effort: target.effort } : {}) },
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