@parcha/agentrun-serve 0.1.0-beta.56 → 0.1.0-beta.57

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 (275) hide show
  1. package/CHANGELOG.md +229 -0
  2. package/README.md +201 -52
  3. package/dist/acp-package.d.ts +2 -0
  4. package/dist/adapters.d.ts +15 -3
  5. package/dist/adapters.js +17 -6
  6. package/dist/agent-package.d.ts +3 -3
  7. package/dist/agent-package.js +17 -8
  8. package/dist/api-keys.d.ts +76 -0
  9. package/dist/api-keys.js +217 -0
  10. package/dist/api-only.d.ts +17 -5
  11. package/dist/api-only.js +34 -8
  12. package/dist/browser-hold.d.ts +23 -0
  13. package/dist/browser-hold.js +48 -0
  14. package/dist/browser-person.d.ts +3 -0
  15. package/dist/browser-person.js +4 -1
  16. package/dist/chatgpt-plan.d.ts +18 -8
  17. package/dist/chatgpt-plan.js +91 -34
  18. package/dist/claude-login.d.ts +74 -16
  19. package/dist/claude-login.js +215 -56
  20. package/dist/claude-sign-in.d.ts +17 -6
  21. package/dist/claude-sign-in.js +42 -39
  22. package/dist/cli.js +63 -6
  23. package/dist/composio-made.d.ts +4 -0
  24. package/dist/composio-made.js +4 -0
  25. package/dist/composio-preset.d.ts +43 -2
  26. package/dist/composio-preset.js +92 -4
  27. package/dist/computer-held-routes.d.ts +5 -4
  28. package/dist/computer-held-routes.js +29 -8
  29. package/dist/computer-held.d.ts +6 -1
  30. package/dist/computer-held.js +14 -0
  31. package/dist/computer-record.js +4 -2
  32. package/dist/computer-viewer.js +4 -1
  33. package/dist/console/assets/{backend-Boh7tC4i.js → backend-DVhHzJX2.js} +19 -19
  34. package/dist/console/assets/index-Bwn1oTem.css +1 -0
  35. package/dist/console/assets/index-okP-y8PK.js +747 -0
  36. package/dist/console/index.html +2 -2
  37. package/dist/decisions.d.ts +1 -1
  38. package/dist/decisions.js +1 -1
  39. package/dist/docker-host-addresses.d.ts +22 -11
  40. package/dist/docker-host-addresses.js +38 -26
  41. package/dist/env-switch.d.ts +10 -0
  42. package/dist/env-switch.js +33 -2
  43. package/dist/errors.d.ts +1 -0
  44. package/dist/errors.js +2 -0
  45. package/dist/fal-price.d.ts +58 -20
  46. package/dist/fal-price.js +341 -82
  47. package/dist/handed-values.d.ts +43 -1
  48. package/dist/handed-values.js +119 -2
  49. package/dist/harness-archive.d.ts +13 -10
  50. package/dist/harness-archive.js +60 -34
  51. package/dist/harness-check.d.ts +3 -1
  52. package/dist/harness-check.js +25 -46
  53. package/dist/harness-keys.d.ts +73 -27
  54. package/dist/harness-keys.js +194 -61
  55. package/dist/harness-recipe-entry.d.ts +8 -7
  56. package/dist/harness-recipe-entry.js +21 -32
  57. package/dist/harness-recipe.d.ts +38 -25
  58. package/dist/harness-recipe.js +49 -36
  59. package/dist/harness-sign-in.js +12 -23
  60. package/dist/harness-table.d.ts +10 -3
  61. package/dist/harness-table.js +26 -21
  62. package/dist/harness.d.ts +1 -0
  63. package/dist/harness.js +17 -5
  64. package/dist/hosted-search.d.ts +1 -1
  65. package/dist/hosted-search.js +1 -2
  66. package/dist/import-worker.d.ts +4 -2
  67. package/dist/import-worker.js +9 -2
  68. package/dist/in-flight.d.ts +26 -0
  69. package/dist/in-flight.js +52 -0
  70. package/dist/key-refusal.d.ts +9 -4
  71. package/dist/key-refusal.js +107 -25
  72. package/dist/learn/secrets.d.ts +13 -3
  73. package/dist/learn/secrets.js +118 -17
  74. package/dist/learning-cost.d.ts +6 -3
  75. package/dist/learning-cost.js +4 -2
  76. package/dist/link-check.js +1 -1
  77. package/dist/llms.txt +1 -1
  78. package/dist/marketplace.d.ts +77 -0
  79. package/dist/marketplace.js +224 -0
  80. package/dist/mcp-api-only-origins.d.ts +30 -0
  81. package/dist/mcp-api-only-origins.js +57 -0
  82. package/dist/mcp-gateway.d.ts +7 -5
  83. package/dist/mcp-gateway.js +9 -12
  84. package/dist/mcp-secret-writes.js +5 -3
  85. package/dist/mcp-servers-store.d.ts +28 -6
  86. package/dist/mcp-servers-store.js +53 -4
  87. package/dist/media-duration.d.ts +3 -0
  88. package/dist/media-duration.js +90 -9
  89. package/dist/model-form.d.ts +5 -4
  90. package/dist/model-form.js +11 -7
  91. package/dist/model.d.ts +5 -2
  92. package/dist/model.js +9 -5
  93. package/dist/ollama-provider.d.ts +7 -1
  94. package/dist/ollama-provider.js +14 -2
  95. package/dist/openapi.js +178 -27
  96. package/dist/otel/genai.d.ts +65 -0
  97. package/dist/otel/genai.js +116 -0
  98. package/dist/otel/tracer.d.ts +55 -0
  99. package/dist/otel/tracer.js +308 -0
  100. package/dist/page.d.ts +2 -0
  101. package/dist/page.js +3 -1
  102. package/dist/paid-calls.d.ts +1 -32
  103. package/dist/paid-calls.js +4 -39
  104. package/dist/provider.d.ts +9 -0
  105. package/dist/provider.js +50 -3
  106. package/dist/redact/match.d.ts +30 -3
  107. package/dist/redact/match.js +422 -41
  108. package/dist/refusal-words.d.ts +11 -0
  109. package/dist/refusal-words.js +11 -0
  110. package/dist/run-census.d.ts +67 -0
  111. package/dist/run-census.js +240 -0
  112. package/dist/run-computer.d.ts +6 -3
  113. package/dist/run-computer.js +4 -1
  114. package/dist/run-cut.d.ts +15 -6
  115. package/dist/run-cut.js +30 -9
  116. package/dist/run-files.d.ts +3 -0
  117. package/dist/run-files.js +3 -0
  118. package/dist/run-launch.d.ts +12 -1
  119. package/dist/run-launch.js +9 -10
  120. package/dist/run-learning-served.d.ts +2 -0
  121. package/dist/run-model-key.d.ts +8 -0
  122. package/dist/run-model-key.js +31 -1
  123. package/dist/run-reads-over-store.d.ts +24 -6
  124. package/dist/run-reads-over-store.js +67 -23
  125. package/dist/run-recordings.d.ts +5 -1
  126. package/dist/run-recordings.js +39 -14
  127. package/dist/run-timeline-served.d.ts +2 -0
  128. package/dist/run-timeline-served.js +2 -2
  129. package/dist/run-usage.d.ts +1 -0
  130. package/dist/runnable.d.ts +10 -1
  131. package/dist/runnable.js +20 -8
  132. package/dist/runner/adapter-loop.d.ts +11 -0
  133. package/dist/runner/adapter-loop.js +55 -10
  134. package/dist/runner/adapter-run-spec.d.ts +45 -8
  135. package/dist/runner/adapter-run-spec.js +150 -28
  136. package/dist/runner/adapters/pi.js +25 -3
  137. package/dist/runner/beside.js +4 -3
  138. package/dist/runner/big-writes.js +1 -10
  139. package/dist/runner/claim-secrets.d.ts +18 -3
  140. package/dist/runner/claim-secrets.js +35 -6
  141. package/dist/runner/cli-run-spec.d.ts +6 -0
  142. package/dist/runner/cli-run-spec.js +82 -35
  143. package/dist/runner/computer-journal.d.ts +9 -1
  144. package/dist/runner/computer-journal.js +26 -0
  145. package/dist/runner/conformance/harness.js +1 -1
  146. package/dist/runner/feedback-round.js +3 -0
  147. package/dist/runner/harness-loops.d.ts +6 -5
  148. package/dist/runner/harness-loops.js +7 -7
  149. package/dist/runner/held.d.ts +11 -5
  150. package/dist/runner/journal-kinds.d.ts +5 -0
  151. package/dist/runner/journal-kinds.js +5 -0
  152. package/dist/runner/main.js +7 -2
  153. package/dist/runner/mcp-claim.js +30 -3
  154. package/dist/runner/mcp-run.d.ts +12 -0
  155. package/dist/runner/mcp-run.js +12 -5
  156. package/dist/runner/model-route.d.ts +17 -0
  157. package/dist/runner/model-route.js +120 -2
  158. package/dist/runner/run-child-host.d.ts +3 -0
  159. package/dist/runner/run-child-host.js +69 -28
  160. package/dist/runner/run-child.js +5 -2
  161. package/dist/runner/runner.d.ts +14 -3
  162. package/dist/runner/runner.js +129 -33
  163. package/dist/runner/store-port.d.ts +1 -1
  164. package/dist/runner/store-secrets.d.ts +6 -0
  165. package/dist/runner/store-secrets.js +49 -7
  166. package/dist/runner/subagent.js +4 -40
  167. package/dist/runner/workflow-first.d.ts +11 -4
  168. package/dist/runner/workflow-first.js +14 -8
  169. package/dist/runner/workflow-spec.js +3 -2
  170. package/dist/runs-over-store.d.ts +15 -6
  171. package/dist/runs-over-store.js +33 -21
  172. package/dist/scrub-command.d.ts +73 -0
  173. package/dist/scrub-command.js +307 -0
  174. package/dist/secret-cut.d.ts +73 -0
  175. package/dist/secret-cut.js +291 -4
  176. package/dist/secret-rules.d.ts +143 -0
  177. package/dist/secret-rules.js +2564 -0
  178. package/dist/secrets.d.ts +7 -0
  179. package/dist/secrets.js +20 -0
  180. package/dist/server-keys.d.ts +20 -0
  181. package/dist/server-keys.js +25 -6
  182. package/dist/server.d.ts +52 -11
  183. package/dist/server.js +345 -118
  184. package/dist/skills/agentrun-serve/SKILL.md +4 -0
  185. package/dist/store/index.d.ts +1 -1
  186. package/dist/store/index.js +1 -1
  187. package/dist/store/journal/storage.js +1 -1
  188. package/dist/store/postgres/migrations/0027_run_launch_census.sql +31 -0
  189. package/dist/store/schema.d.ts +6 -0
  190. package/dist/store/schema.js +11 -1
  191. package/dist/store/seal.d.ts +6 -1
  192. package/dist/store/seal.js +5 -3
  193. package/dist/store/sqlite/run-launch.d.ts +9 -1
  194. package/dist/store/sqlite/run-launch.js +24 -13
  195. package/dist/store/sqlite/run-patch.d.ts +1 -1
  196. package/dist/store/sqlite/run-patch.js +13 -4
  197. package/dist/store/sqlite/store.js +34 -4
  198. package/dist/store/store.d.ts +43 -2
  199. package/dist/store/store.js +20 -0
  200. package/dist/store-reads/learning.d.ts +6 -3
  201. package/dist/store-reads/learning.js +22 -7
  202. package/dist/store-view.d.ts +3 -0
  203. package/dist/store-view.js +3 -3
  204. package/dist/suggestions.js +3 -2
  205. package/dist/template-eval.d.ts +20 -9
  206. package/dist/template-eval.js +115 -33
  207. package/dist/template-import.d.ts +10 -0
  208. package/dist/template-import.js +16 -7
  209. package/dist/templates.d.ts +10 -2
  210. package/dist/templates.js +28 -8
  211. package/dist/timeline/labels.d.ts +6 -4
  212. package/dist/timeline/labels.js +18 -6
  213. package/dist/timeline/timeline.d.ts +5 -0
  214. package/dist/timeline/timeline.js +14 -8
  215. package/dist/timeline/util.js +1 -1
  216. package/dist/timeline/web-calls.d.ts +26 -9
  217. package/dist/timeline/web-calls.js +124 -37
  218. package/dist/tool-gate.d.ts +42 -3
  219. package/dist/tool-gate.js +66 -5
  220. package/dist/tool-keys-store.d.ts +2 -4
  221. package/dist/tool-keys-store.js +5 -21
  222. package/dist/tool-keys.d.ts +2 -2
  223. package/dist/tool-keys.js +2 -2
  224. package/dist/tool-list.js +1 -1
  225. package/dist/tool-plane.d.ts +2 -2
  226. package/dist/tool-plane.js +35 -33
  227. package/dist/tools.js +13 -7
  228. package/dist/trigger-targets.d.ts +4 -0
  229. package/dist/trigger-targets.js +9 -2
  230. package/dist/triggers.d.ts +67 -4
  231. package/dist/triggers.js +171 -22
  232. package/dist/until.d.ts +3 -0
  233. package/dist/until.js +11 -0
  234. package/dist/web-fake.d.ts +1 -3
  235. package/dist/web-fake.js +7 -18
  236. package/dist/web-fetch.d.ts +6 -72
  237. package/dist/web-fetch.js +11 -265
  238. package/dist/web-run.d.ts +31 -0
  239. package/dist/web-run.js +90 -0
  240. package/dist/web-save.d.ts +6 -4
  241. package/dist/web-save.js +9 -12
  242. package/dist/web-search.d.ts +9 -127
  243. package/dist/web-search.js +23 -259
  244. package/dist/wires.d.ts +13 -0
  245. package/dist/wires.js +11 -0
  246. package/dist/workflow-run.d.ts +5 -4
  247. package/dist/workflow-run.js +5 -4
  248. package/dist/workspace/computer-deps.d.ts +2 -1
  249. package/dist/workspace/computer-deps.js +9 -2
  250. package/dist/workspace/computer-for-claim.d.ts +12 -1
  251. package/dist/workspace/computer-for-claim.js +77 -8
  252. package/dist/workspace/computer-kept.d.ts +3 -0
  253. package/dist/workspace/computer-kept.js +11 -2
  254. package/dist/workspace/index.d.ts +1 -1
  255. package/dist/workspace/index.js +1 -1
  256. package/dist/workspace/kind-skills.d.ts +4 -0
  257. package/dist/workspace/kind-skills.js +9 -0
  258. package/dist/workspace/synced-folder.js +3 -4
  259. package/dist/wrapped.d.ts +13 -5
  260. package/dist/wrapped.js +52 -26
  261. package/package.json +17 -11
  262. package/skills/agentrun-serve/SKILL.md +4 -0
  263. package/templates/README.md +30 -8
  264. package/dist/console/assets/index-CQ3cJRzI.js +0 -746
  265. package/dist/console/assets/index-DKkaS3a0.css +0 -1
  266. package/dist/exa-keyless.d.ts +0 -34
  267. package/dist/exa-keyless.js +0 -118
  268. package/dist/firecrawl-keyless.d.ts +0 -41
  269. package/dist/firecrawl-keyless.js +0 -152
  270. package/dist/keyless-mcp.d.ts +0 -36
  271. package/dist/keyless-mcp.js +0 -127
  272. package/dist/text-urls.d.ts +0 -38
  273. package/dist/text-urls.js +0 -170
  274. package/dist/web-fetch-direct.d.ts +0 -119
  275. package/dist/web-fetch-direct.js +0 -190
package/dist/adapters.js CHANGED
@@ -14,7 +14,7 @@ import { facts as openCodeFacts } from "./harness-opencode/facts.js";
14
14
  import { CLAUDE_SDK, codexBinaryIn, HarnessNotInstalled, installDirOf, installLine, loadSdk } from "./harness-install.js";
15
15
  import { DATA_ENV, defaultData } from "./files.js";
16
16
  import { harnessOf, onAdapter } from "./harness-table.js";
17
- import { HarnessUnavailable, providerFor } from "./provider.js";
17
+ import { HarnessUnavailable, heldRefusedProvider, providerFor } from "./provider.js";
18
18
  import { keyShaped } from "./secret-cut.js";
19
19
  import { servedSkills } from "./learn/workflow-draft.js";
20
20
  import { runKeyOf } from "./key-refusal.js";
@@ -211,6 +211,10 @@ function unavailable(facts, error, npx, env) {
211
211
  const hinted = installHint(said, facts.install.npmLine, facts.install.spec, npx, env);
212
212
  return new HarnessUnavailable(hinted, hinted === said ? fixOf(facts, error) : undefined);
213
213
  }
214
+ /** Where a run's adapter sends its model's requests (providerFor), or, for a held run its model kept from running at its
215
+ * create, the stand-in (heldRefusedProvider): no key is read, and its proxy refuses every request in the create's words,
216
+ * sending none. */
217
+ export const providerOf = (wire, env, needs, who) => needs.heldRefusal !== undefined ? heldRefusedProvider(needs.model, needs.heldRefusal) : providerFor(wire, env, needs.model, who);
214
218
  /** The ConfineChild that starts a child under `prefix` (the argv pi's commands start under, ending in "--"); none when
215
219
  * the run confines nothing (macOS), since an adapter refuses a confinement that adds nothing. */
216
220
  export function confineOf(prefix) {
@@ -296,12 +300,16 @@ export async function packageSkillCheck(load) {
296
300
  const pkg = (await load());
297
301
  return typeof pkg?.skillProblems === "function" ? pkg.skillProblems : undefined;
298
302
  }
303
+ /** Whether a run's web_search is its harness's own search: the run's plane resolves it native and the harness has a search
304
+ * of its own (its facts' webSearch: claude-agent's, codex's). Its adapter then searches (nativeOptions), and the run is
305
+ * not also handed the host's web_search (cli-run-spec.ts), which would sit beside it. */
306
+ export const ownSearchRuns = (facts, plane) => plane?.web_search === "native" && Boolean(facts?.webSearch);
299
307
  /** What a harness's adapter takes from the run's plane (tool-plane.ts) where web_search resolves native, by its own search
300
308
  * (its facts' webSearch): `native`, the provider's search through its proxy, with the input a search request may read in
301
309
  * beyond its body (cap.ts), which its proxy adds to that request's bound; `live`, its own live search (its adapter books
302
310
  * each search); nothing for a harness with none. */
303
311
  export function nativeOptions(facts, env) {
304
- if (planeOf(env).web_search !== "native" || !facts.webSearch)
312
+ if (!ownSearchRuns(facts, planeOf(env)))
305
313
  return {};
306
314
  return facts.webSearch === "native" ? { webSearch: true, webSearchAllowance: NATIVE_SEARCH_ALLOWANCE_TOKENS } : { webSearch: "live" };
307
315
  }
@@ -322,7 +330,7 @@ export async function claudeOf(env, needs, load = loadClaude, sdkOf = (version,
322
330
  let provider;
323
331
  let refused;
324
332
  try {
325
- provider = providerFor(claudeFacts.wire, env, needs.model, claudeFacts.id);
333
+ provider = providerOf(claudeFacts.wire, env, needs, claudeFacts.id);
326
334
  }
327
335
  catch (error) {
328
336
  refused = error;
@@ -334,6 +342,9 @@ export async function claudeOf(env, needs, load = loadClaude, sdkOf = (version,
334
342
  // (providerFor's modelId); the key goes as the endpoint takes it, and the run is priced by the catalog entry of
335
343
  // whoever bills it (its priceModel).
336
344
  const endpoint = provider ? { origin: provider.origin, credential: provider.credential, auth: provider.auth, ...(provider.headers ? { headers: provider.headers } : {}) } : { origin: "", credential: () => "" };
345
+ // A model the route translates onto the wire (an Ollama model): its proxy forwards with the route's own fetch, and the
346
+ // provider's own web search (nativeOptions), which the translation cannot run, is not offered.
347
+ const forward = provider?.fetch ? { fetch: provider.fetch } : {};
337
348
  const priced = provider ? { ...needs, model: provider.priceModel } : native;
338
349
  // Its CLI checked off the event loop first (hashed and run as a child), so the server goes on answering: a pass is
339
350
  // kept, and the adapter's own check answers from it. A CLI that fails its pins is the adapter's to report, in its
@@ -343,7 +354,7 @@ export async function claudeOf(env, needs, load = loadClaude, sdkOf = (version,
343
354
  // On Claude Code's login on this machine: the login's directories in place of a provider, billed to the plan, never
344
355
  // priced here.
345
356
  const source = provider?.login ? { login: provider.login, price: () => null } : { provider: endpoint, price: priceOf(priced) };
346
- adapter = claude.claudeAgentAdapter({ model: { default: provider?.modelId ?? native.model.modelId }, ...source, log: harnessLog(claudeFacts.id, env), sdk: sdk.sdk, sdkVersion: sdk.sdkVersion, cliPath: sdk.cliPath, mcp: sdk.mcp, ...(needs.confine ? { confine: needs.confine } : {}), ...(needs.skills?.length ? { skills: needs.skills } : {}), ...(needs.now ? { now: needs.now } : {}), ...(needs.zone ? { zone: needs.zone } : {}), ...nativeOptions(claudeFacts, env) });
357
+ adapter = claude.claudeAgentAdapter({ model: { default: provider?.modelId ?? native.model.modelId }, ...source, log: harnessLog(claudeFacts.id, env), sdk: sdk.sdk, sdkVersion: sdk.sdkVersion, cliPath: sdk.cliPath, mcp: sdk.mcp, ...(needs.confine ? { confine: needs.confine } : {}), ...(needs.skills?.length ? { skills: needs.skills } : {}), ...(needs.now ? { now: needs.now } : {}), ...(needs.zone ? { zone: needs.zone } : {}), ...(provider?.fetch ? forward : nativeOptions(claudeFacts, env)) });
347
358
  }
348
359
  catch (error) {
349
360
  // The adapter's own install line is a project's; here Claude Code is installed into the data's harnesses directory.
@@ -387,7 +398,7 @@ export async function codexOf(env, needs, load = () => import("@parcha/agentrun-
387
398
  // whole (AGENT_MODEL_GATEWAY_IDS says whether it is provider-qualified), OpenAI's model id, which chooseModel has
388
399
  // already taken out of "openai/<id>", or OpenRouter's whole slug.
389
400
  // On a ChatGPT plan: the plan's rules on its route (no output limit, no input count), billed to it, never priced here.
390
- const provider = providerFor(codexFacts.wire, env, needs.model, codexFacts.id);
401
+ const provider = providerOf(codexFacts.wire, env, needs, codexFacts.id);
391
402
  const plan = provider.billing === "plan";
392
403
  return codex.codexAdapter({ model: provider.modelId, provider: { origin: provider.origin, credential: provider.credential, ...(plan ? { plan } : {}), ...(provider.refused ? { refused: provider.refused } : {}) }, price: plan ? () => null : priceOf({ ...needs, model: provider.priceModel }), log: harnessLog(codexFacts.id, env), ...(nativeOptions(codexFacts, env).webSearch === "live" ? { webSearch: "live" } : {}), ...(needs.confine ? { confine: needs.confine } : {}), ...(needs.skills?.length ? { skills: needs.skills } : {}), ...(standIn ? { standIn } : binary ? { binary } : {}) });
393
404
  }
@@ -411,7 +422,7 @@ export async function opencodeOf(env, needs, load = () => import("./harness-open
411
422
  // The shared date line (environment.ts) reaches OpenCode in the session's system prompt (app.ts), as it reaches every
412
423
  // harness.
413
424
  // The id as the provider's endpoint names it (providerFor, as codexOf takes it): OpenRouter's is the whole slug.
414
- const provider = providerFor(openCodeFacts.wire, env, needs.model, openCodeFacts.id);
425
+ const provider = providerOf(openCodeFacts.wire, env, needs, openCodeFacts.id);
415
426
  // Its instructions list each skill by the description its SKILL.md's front matter gives on one LF line, which is all the
416
427
  // adapter reads: each SKILL.md goes as servedSkill writes it (its name and description, as a prompt reads them, on one
417
428
  // line each), so a CRLF file or a folded description is listed by its own words.
@@ -8,7 +8,7 @@ export type PackageFile = {
8
8
  };
9
9
  /** What an export's note can be about: the document's enum of them (openapi.ts), so a note of a kind not here fails the
10
10
  * build, and an answer the document does not list fails its schema check. */
11
- export declare const EXPORT_NOTE_KINDS: readonly ["mcp_server", "trigger", "pin", "tool_setting", "tool_policy", "computer", "paired_computer", "sign_in", "learning", "input_schema", "budget", "package"];
11
+ export declare const EXPORT_NOTE_KINDS: readonly ["mcp_server", "trigger", "pin", "tool_setting", "tool_policy", "computer", "paired_computer", "sign_in", "learning", "secrets", "input_schema", "budget", "package"];
12
12
  /** One thing an export could not carry as it is here: what it is, which one, and why, in words. */
13
13
  export type ExportNote = {
14
14
  kind: (typeof EXPORT_NOTE_KINDS)[number];
@@ -46,8 +46,8 @@ export type ExportInput = {
46
46
  definition: Json;
47
47
  /** The revision's skill files, by path under the agent's skills folder. */
48
48
  skills: Readonly<Record<string, string>>;
49
- /** The package the agent was applied from (agentView's `template`) with the key names its apply kept, and that package
50
- * as this server holds it now. */
49
+ /** The package the agent was applied from (agentView's `template`) with the key names its apply kept (absent on a
50
+ * revision applied before an apply kept them), and that package as this server holds it now. */
51
51
  template: {
52
52
  id: string;
53
53
  version: string;
@@ -8,7 +8,7 @@
8
8
  import { createHash } from "node:crypto";
9
9
  import { stringify } from "yaml";
10
10
  import { LOOPBACK } from "./mcp-oauth.js";
11
- import { INPUT_KEYS, ITEM_KEYS, MANIFEST, memoryFiles, onServerNames, PackageError, readPackage } from "./templates.js";
11
+ import { INPUT_KEYS, ITEM_KEYS, MANIFEST, memoryFiles, onServerNames, PackageError, readPackage, uncappedTriggers } from "./templates.js";
12
12
  import { isMcpName, isMonidName, mcpToolName, parseToolName } from "./tool-names.js";
13
13
  import { isPinKeys, permissionKeys, SHELL_FAMILY } from "./tool-gate.js";
14
14
  import { toolOf } from "./tools.js";
@@ -18,7 +18,7 @@ import { isObject, MODEL_TIER_NAMES, stable } from "./validate.js";
18
18
  import { PAIRED_ID_PREFIX } from "./workspace/attached-computers.js";
19
19
  /** What an export's note can be about: the document's enum of them (openapi.ts), so a note of a kind not here fails the
20
20
  * build, and an answer the document does not list fails its schema check. */
21
- export const EXPORT_NOTE_KINDS = ["mcp_server", "trigger", "pin", "tool_setting", "tool_policy", "computer", "paired_computer", "sign_in", "learning", "input_schema", "budget", "package"];
21
+ export const EXPORT_NOTE_KINDS = ["mcp_server", "trigger", "pin", "tool_setting", "tool_policy", "computer", "paired_computer", "sign_in", "learning", "secrets", "input_schema", "budget", "package"];
22
22
  /** The package's digest: sha256, in hex, over its files sorted by path, each written as `path NUL bytes NUL`. */
23
23
  export function packageSha256(files) {
24
24
  const hash = createHash("sha256");
@@ -285,8 +285,11 @@ export function agentPackage(input) {
285
285
  const inputs = inputSchema && inputsOf(inputSchema);
286
286
  if (inputSchema && !inputs)
287
287
  blocked.push({ kind: "input_schema", name: "inputs", reason: "Its input schema is not a closed object of fields, which is what a package's inputs are." });
288
- // The keys its package declared, as its apply kept them.
288
+ // The keys its package declared, as its apply kept them. A revision applied before an apply kept them names none here,
289
+ // so the package says none, and the note says the target sets them up.
289
290
  const secrets = [...new Set([...(template?.secrets ?? []), ...((plain ?? []).some(isMonidName) ? ["MONID_API_KEY"] : [])])].sort();
291
+ if (template && !template.secrets)
292
+ remade.push({ kind: "secrets", name: template.id, reason: `The key names version ${template.version} of ${template.id} declares were not kept when it was applied here, so the package names none: save the keys the agent uses on the target, and name them under secrets in ${MANIFEST}.` });
290
293
  const bash = settings.bash?.policy;
291
294
  // Bash's policy holds every shell tool, and a package writes it only beside bash: a shell tool kept without bash would
292
295
  // run there what the policy refuses here.
@@ -294,15 +297,21 @@ export function agentPackage(input) {
294
297
  if (typeof bash === "string" && shellKept.length && !shellKept.includes("bash"))
295
298
  blocked.push({ kind: "tool_policy", name: "bash", reason: `Its bash policy (${bash}) holds ${shellKept.join(", ")}, and a package writes that policy only beside bash: grant bash too, or take ${shellKept.length === 1 ? "it" : "them"} out of the agent.` });
296
299
  const description = (agent.description?.trim() || agent.name).slice(0, 1024);
297
- // A package's budget is a spend cap per run first, and one with triggers has one: what fires runs nobody watches.
300
+ // A package's budget is a spend cap per run first. Every run a package's trigger starts is capped, what fires runs
301
+ // nobody watches: by the budget (the agent's max_cost_usd), else by the trigger's own cap, as readPackage holds it
302
+ // (uncappedTriggers). A trigger with neither is blocked, and left out, so the read-back does not name it again.
298
303
  const cost = typeof definition.max_cost_usd === "number" ? definition.max_cost_usd : undefined;
299
304
  const requests = typeof definition.max_requests === "number" ? definition.max_requests : undefined;
300
305
  if (cost === undefined && requests !== undefined)
301
306
  blocked.push({ kind: "budget", name: "max_requests", reason: "It caps each run's requests and not its spend, and a package's budget is a spend cap per run: set the agent's max_cost_usd." });
302
- if (cost === undefined && triggers.length) {
303
- blocked.push({ kind: "budget", name: "max_cost_usd", reason: "It has triggers and no spend cap per run, and a package with triggers caps what each run they fire may spend: set the agent's max_cost_usd." });
304
- triggers.length = 0;
305
- remade.splice(0, remade.length, ...remade.filter((note) => note.kind !== "trigger"));
307
+ const uncapped = cost === undefined ? uncappedTriggers(triggers) : [];
308
+ if (uncapped.length) {
309
+ const names = new Set(uncapped.map((one) => one.name));
310
+ for (const name of names)
311
+ blocked.push({ kind: "trigger", name, reason: "It has no spend cap of its own and the agent has no max_cost_usd, and every run a package's trigger starts is capped: give the trigger's target a max_cost_usd, or set the agent's max_cost_usd." });
312
+ const left = triggers.filter((_, index) => !uncapped.some((one) => one.index === index));
313
+ triggers.splice(0, triggers.length, ...left);
314
+ remade.splice(0, remade.length, ...remade.filter((note) => !(note.kind === "trigger" && names.has(note.name))));
306
315
  }
307
316
  // The manifest, in the order templates.ts reads its fields.
308
317
  const manifest = {
@@ -0,0 +1,76 @@
1
+ import { type SecretMeta } from "./secret-writes.js";
2
+ import type { Settings } from "./store/index.js";
3
+ /** Where the owner makes and revokes a key in the console. */
4
+ export declare const API_KEYS_PAGE = "/#/settings/api-keys";
5
+ /** What every key made here starts with: a person who meets one can tell what it is, and the redaction finds one by it
6
+ * (redact/match.ts holds the same prefix, and secrets-api-key.test.mjs holds the two together). */
7
+ export declare const API_KEY_PREFIX = "ar_key_";
8
+ /** The store settings a key's row is kept under: this prefix, then its id. */
9
+ export declare const API_KEY_SETTING = "api_key:";
10
+ /** The most keys a server keeps at once. */
11
+ export declare const API_KEYS_LIMIT = 50;
12
+ /** The longest name a key takes. */
13
+ export declare const API_KEY_NAME_MAX = 64;
14
+ /** A key's last use is written to the store at most this often: a busy key costs one write a minute, not one a request. */
15
+ export declare const USED_EVERY_MS = 60000;
16
+ /** A key as every read answers it: never its value, a prefix, a length or a hash. */
17
+ export type ApiKeyView = {
18
+ id: string;
19
+ name: string;
20
+ created_at: string;
21
+ last_used_at: string | null;
22
+ secret: SecretMeta;
23
+ };
24
+ /** A key's secret's metadata, named api-key:<id>: made by this server at the owner's request (source console). */
25
+ export declare const apiKeySecretMeta: (id: string, createdAt: string) => SecretMeta;
26
+ export type ApiKeysOptions = {
27
+ /** The clock (a test's). */
28
+ now?: () => number;
29
+ /** Where a row that could not be read, or a last use that could not be written, is said: fields with no secret. */
30
+ say?: (fields: Record<string, string | number>) => void;
31
+ /** The keys open nothing on this server (it is one person's, or has no owner): each is still read, listed, counted
32
+ * and revocable, so none waits unseen for a start that takes keys again. */
33
+ dormant?: boolean;
34
+ };
35
+ export declare class ApiKeys {
36
+ #private;
37
+ constructor(store: {
38
+ settings: Settings;
39
+ }, sealKey: Buffer, options?: ApiKeysOptions);
40
+ /** Reads the store's keys. A row that is no key's (another version's, or damaged) opens nothing and is said, with
41
+ * how it is removed. It is no key in the list: the list names it by id in `unreadable`, and it counts toward the
42
+ * store's limit while it stays. */
43
+ load(): Promise<void>;
44
+ /** How many keys open this server now: what the one-owner rule counts (server.ts loginRefused). Read it in a turn
45
+ * (inTurn) to decide by it: outside one, a revocation under way has taken its key out and may yet put it back. */
46
+ get count(): number;
47
+ /** One at a time: every change to which keys open the server (create, revoke) takes a turn, and so does whatever
48
+ * must decide by the keys as they stand once those changes have landed or been undone (the server turns Claude
49
+ * Code's login on in one). A turn starts when the one before it has settled, whether it kept its write or not. */
50
+ inTurn<T>(work: () => Promise<T>): Promise<T>;
51
+ /** GET /settings/api-keys: every key, oldest first, and the most a server keeps. `refused`: why this server makes
52
+ * none now (server.ts apiKeysRefused), said with the list so a page can say it before anyone tries. `unreadable`:
53
+ * the ids of the rows that are no key's, when there are any, so their owner sees what else counts toward the limit
54
+ * and removes it (revoke takes such an id). */
55
+ list(refused?: string): {
56
+ keys: ApiKeyView[];
57
+ limit: number;
58
+ refused?: string;
59
+ unreadable?: string[];
60
+ };
61
+ /** POST /settings/api-keys: a new key named `name`, its value as `api_key`, this once. `refused`: why this server
62
+ * makes no key now, asked in the create's own turn, so nothing that would refuse it starts between the answer and
63
+ * the write; its words are the 403's. */
64
+ create(body: unknown, refused?: () => Promise<string | undefined>): Promise<ApiKeyView & {
65
+ api_key: string;
66
+ }>;
67
+ /** DELETE /settings/api-keys/{id}: the key opens nothing from now on. In a turn of its own (inTurn): while its
68
+ * removal is under way the key is out of this process, and a removal that fails puts it back, so nothing decides by
69
+ * the count in between. */
70
+ revoke(id: string): Promise<void>;
71
+ /** The id of the key whose `Bearer` line `header` is, else undefined. Every key is compared on every call, with no
72
+ * early return, so the time taken says neither whether one matched nor which. A match is the key's last use. */
73
+ used(header: string | undefined): string | undefined;
74
+ /** Waits for the last-use writes under way, before the store closes. */
75
+ close(): Promise<void>;
76
+ }
@@ -0,0 +1,217 @@
1
+ // The API keys a person makes in the console (Settings → AgentRun API keys, /v2/settings/api-keys): each a Bearer token
2
+ // an app sends on /v2 and /mcp, as it would the server's own token (api-token.ts). A key is made here at random, shown
3
+ // once in the answer that made it, and kept nowhere. The store keeps an HMAC of its `Bearer` line under a key derived
4
+ // from the server's seal key, so a copy of the store names no key and a row written without the seal key opens nothing.
5
+ //
6
+ // Making and revoking a key are secret writes (secret-writes.ts): the owner's signed-in session alone, never a token,
7
+ // so a key that leaks cannot make another or outlive its revocation. A key is not the setup code: only a token the
8
+ // server was started with sets the first password (server.ts ownerRoute).
9
+ //
10
+ // Every presented header is compared with every key, in constant time, on two 32-byte digests, as bearerCheck compares
11
+ // the server's tokens. One server holds a store (its owner lock), so the keys in this process are the store's.
12
+ //
13
+ // On a server that is one person's, or has no owner, the keys are dormant: read, listed, counted and revocable, and
14
+ // opening nothing. A key never waits unseen for a later start to take it again.
15
+ //
16
+ // The server keeps no copy of a key, so it holds no value to cut a text by, as it cuts its own token. A key is found by
17
+ // its shape instead (redact/match.ts: the prefix and 43 or more of its characters), wherever a run's views, a shared
18
+ // transcript or a learned note would show one.
19
+ import { createHmac, randomBytes, timingSafeEqual } from "node:crypto";
20
+ import { ApiError, invalid } from "./errors.js";
21
+ import { uuidv7 } from "./ids.js";
22
+ import { registerSecretPage, registerSecretWrite, secretMeta, secretName } from "./secret-writes.js";
23
+ import { isObject, unknownFields } from "./validate.js";
24
+ registerSecretWrite("createApiKey", () => true);
25
+ registerSecretWrite("revokeApiKey", () => true);
26
+ /** Where the owner makes and revokes a key in the console. */
27
+ export const API_KEYS_PAGE = "/#/settings/api-keys";
28
+ registerSecretPage(["createApiKey", "revokeApiKey"], API_KEYS_PAGE);
29
+ /** What every key made here starts with: a person who meets one can tell what it is, and the redaction finds one by it
30
+ * (redact/match.ts holds the same prefix, and secrets-api-key.test.mjs holds the two together). */
31
+ export const API_KEY_PREFIX = "ar_key_";
32
+ /** The store settings a key's row is kept under: this prefix, then its id. */
33
+ export const API_KEY_SETTING = "api_key:";
34
+ /** The most keys a server keeps at once. */
35
+ export const API_KEYS_LIMIT = 50;
36
+ /** The longest name a key takes. */
37
+ export const API_KEY_NAME_MAX = 64;
38
+ /** A key's last use is written to the store at most this often: a busy key costs one write a minute, not one a request. */
39
+ export const USED_EVERY_MS = 60_000;
40
+ const ID = /^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
41
+ const isDate = (value) => typeof value === "string" && !Number.isNaN(Date.parse(value));
42
+ const isKept = (value) => isObject(value) && value.v === 1 && typeof value.id === "string" && ID.test(value.id) && typeof value.name === "string" && typeof value.mac === "string" && /^[0-9a-f]{64}$/.test(value.mac)
43
+ && isDate(value.created_at) && (value.last_used_at === null || isDate(value.last_used_at));
44
+ /** A key's secret's metadata, named api-key:<id>: made by this server at the owner's request (source console). */
45
+ export const apiKeySecretMeta = (id, createdAt) => secretMeta(secretName("api-key", id), { set: true, source: "console", changedAt: createdAt });
46
+ export class ApiKeys {
47
+ #settings;
48
+ #macKey;
49
+ #now;
50
+ #say;
51
+ #dormant;
52
+ #keys = new Map();
53
+ /** The rows under the keys' prefix that are no key's, by what follows the prefix in their store key: they open
54
+ * nothing, and a revocation by that id removes one (it counts toward the store's limit until then). */
55
+ #unreadable = new Set();
56
+ #writes = new Set();
57
+ /** The turn now taken (inTurn): settled before the next one starts, whatever it did. */
58
+ #turn = Promise.resolve();
59
+ constructor(store, sealKey, options = {}) {
60
+ this.#settings = store.settings;
61
+ this.#macKey = createHmac("sha256", sealKey).update("agentrun-serve api keys").digest();
62
+ this.#now = options.now ?? Date.now;
63
+ this.#say = options.say ?? (() => undefined);
64
+ this.#dormant = options.dormant === true;
65
+ }
66
+ #mac(header) {
67
+ return createHmac("sha256", this.#macKey).update(header).digest();
68
+ }
69
+ /** Reads the store's keys. A row that is no key's (another version's, or damaged) opens nothing and is said, with
70
+ * how it is removed. It is no key in the list: the list names it by id in `unreadable`, and it counts toward the
71
+ * store's limit while it stays. */
72
+ async load() {
73
+ this.#keys.clear();
74
+ this.#unreadable.clear();
75
+ for (const row of await this.#settings.all({ prefix: API_KEY_SETTING })) {
76
+ const kept = row.value;
77
+ if (!isKept(kept) || row.key !== API_KEY_SETTING + kept.id) {
78
+ const id = row.key.slice(API_KEY_SETTING.length);
79
+ this.#unreadable.add(id);
80
+ this.#say({ condition: "api_key_unreadable", key: row.key, effect: `ignored: it opens nothing, and counts toward the limit until DELETE /v2/settings/api-keys/${encodeURIComponent(id)} removes it` });
81
+ continue;
82
+ }
83
+ const used = kept.last_used_at === null ? null : Date.parse(kept.last_used_at);
84
+ this.#keys.set(kept.id, { row: kept, mac: Buffer.from(kept.mac, "hex"), usedAt: used, triedAt: used, saving: false });
85
+ }
86
+ }
87
+ #view(held) {
88
+ const { id, name, created_at } = held.row;
89
+ return { id, name, created_at, last_used_at: held.usedAt === null ? null : new Date(held.usedAt).toISOString(), secret: apiKeySecretMeta(id, created_at) };
90
+ }
91
+ /** How many keys open this server now: what the one-owner rule counts (server.ts loginRefused). Read it in a turn
92
+ * (inTurn) to decide by it: outside one, a revocation under way has taken its key out and may yet put it back. */
93
+ get count() {
94
+ return this.#keys.size;
95
+ }
96
+ /** One at a time: every change to which keys open the server (create, revoke) takes a turn, and so does whatever
97
+ * must decide by the keys as they stand once those changes have landed or been undone (the server turns Claude
98
+ * Code's login on in one). A turn starts when the one before it has settled, whether it kept its write or not. */
99
+ inTurn(work) {
100
+ const mine = this.#turn.then(work, work);
101
+ this.#turn = mine.catch(() => undefined);
102
+ return mine;
103
+ }
104
+ /** GET /settings/api-keys: every key, oldest first, and the most a server keeps. `refused`: why this server makes
105
+ * none now (server.ts apiKeysRefused), said with the list so a page can say it before anyone tries. `unreadable`:
106
+ * the ids of the rows that are no key's, when there are any, so their owner sees what else counts toward the limit
107
+ * and removes it (revoke takes such an id). */
108
+ list(refused) {
109
+ return {
110
+ keys: [...this.#keys.values()].sort((a, b) => (a.row.id < b.row.id ? -1 : 1)).map((held) => this.#view(held)),
111
+ limit: API_KEYS_LIMIT,
112
+ ...(refused ? { refused } : {}),
113
+ ...(this.#unreadable.size ? { unreadable: [...this.#unreadable].sort() } : {}),
114
+ };
115
+ }
116
+ /** POST /settings/api-keys: a new key named `name`, its value as `api_key`, this once. `refused`: why this server
117
+ * makes no key now, asked in the create's own turn, so nothing that would refuse it starts between the answer and
118
+ * the write; its words are the 403's. */
119
+ async create(body, refused) {
120
+ if (!isObject(body))
121
+ throw invalid([{ field: "body", reason: "wrong_type", message: "The body is an object: {\"name\": \"...\"}." }]);
122
+ const unknown = unknownFields(body, ["name"]);
123
+ if (unknown.length)
124
+ throw invalid(unknown);
125
+ const name = typeof body.name === "string" ? body.name.trim() : undefined;
126
+ if (name === undefined)
127
+ throw invalid([{ field: "name", reason: body.name === undefined ? "required" : "wrong_type", message: "name is what this key is for, in a few words: the app or the person that will hold it." }]);
128
+ // No control character: a name is shown in a list, on one line.
129
+ if (name === "" || name.length > API_KEY_NAME_MAX || /[\u0000-\u001f\u007f]/.test(name)) {
130
+ throw invalid([{ field: "name", reason: "out_of_range", message: `name is 1 to ${API_KEY_NAME_MAX} characters, on one line.` }]);
131
+ }
132
+ return this.inTurn(async () => {
133
+ const why = await refused?.();
134
+ if (why)
135
+ throw new ApiError("forbidden", why);
136
+ const id = uuidv7(this.#now());
137
+ const value = `${API_KEY_PREFIX}${randomBytes(32).toString("base64url")}`;
138
+ const mac = this.#mac(`Bearer ${value}`);
139
+ const kept = { v: 1, id, name, mac: mac.toString("hex"), created_at: new Date(this.#now()).toISOString(), last_used_at: null };
140
+ const saved = await this.#settings.putIfAbsent(API_KEY_SETTING + id, kept, { prefix: API_KEY_SETTING, limit: API_KEYS_LIMIT });
141
+ if (saved === undefined)
142
+ throw new ApiError("api_keys_full", `This server keeps at most ${API_KEYS_LIMIT} API keys. Revoke one you no longer use, then create this one.`);
143
+ const held = { row: kept, mac, usedAt: null, triedAt: null, saving: false };
144
+ this.#keys.set(id, held);
145
+ return { ...this.#view(held), api_key: value };
146
+ });
147
+ }
148
+ /** DELETE /settings/api-keys/{id}: the key opens nothing from now on. In a turn of its own (inTurn): while its
149
+ * removal is under way the key is out of this process, and a removal that fails puts it back, so nothing decides by
150
+ * the count in between. */
151
+ async revoke(id) {
152
+ return this.inTurn(async () => {
153
+ const held = this.#keys.get(id);
154
+ if (!held && this.#unreadable.has(id)) {
155
+ // A row the start could not read as a key: it opens nothing already, and its removal frees its place.
156
+ await this.#settings.remove(API_KEY_SETTING + id);
157
+ this.#unreadable.delete(id);
158
+ return;
159
+ }
160
+ if (!held)
161
+ throw new ApiError("not_found", "No API key has that id: it was revoked, or never created.");
162
+ // Out of this process first, so a request that races the store's write is refused already.
163
+ this.#keys.delete(id);
164
+ try {
165
+ await this.#settings.remove(API_KEY_SETTING + id);
166
+ }
167
+ catch (error) {
168
+ // Not removed from the store: it would open again at the next start, so it stays listed, to be revoked again.
169
+ this.#keys.set(id, held);
170
+ throw error;
171
+ }
172
+ });
173
+ }
174
+ /** The id of the key whose `Bearer` line `header` is, else undefined. Every key is compared on every call, with no
175
+ * early return, so the time taken says neither whether one matched nor which. A match is the key's last use. */
176
+ used(header) {
177
+ if (this.#dormant)
178
+ return undefined;
179
+ const given = this.#mac(String(header ?? ""));
180
+ let found;
181
+ for (const held of this.#keys.values()) {
182
+ const hit = timingSafeEqual(given, held.mac);
183
+ found = hit ? held : found;
184
+ }
185
+ if (found)
186
+ this.#touch(found);
187
+ return found?.row.id;
188
+ }
189
+ /** Marks `held` used now, and writes it to the store when the last try is USED_EVERY_MS old. Paced by the try, kept
190
+ * or not: while the store refuses writes, a busy key costs one try and one line a minute, not one a request. The row
191
+ * is replaced only while it reads as this process last wrote it, so a write that loses to a revocation writes
192
+ * nothing. */
193
+ #touch(held) {
194
+ const now = this.#now();
195
+ held.usedAt = now;
196
+ if (held.saving || (held.triedAt !== null && now - held.triedAt < USED_EVERY_MS))
197
+ return;
198
+ held.saving = true;
199
+ held.triedAt = now;
200
+ const next = { ...held.row, last_used_at: new Date(now).toISOString() };
201
+ const write = this.#settings.replaceIf(API_KEY_SETTING + held.row.id, held.row, next)
202
+ .then((replaced) => {
203
+ if (replaced)
204
+ held.row = next;
205
+ })
206
+ .catch((error) => this.#say({ condition: "api_key_use_not_saved", id: held.row.id, error: error instanceof Error ? error.message : String(error) }))
207
+ .finally(() => {
208
+ held.saving = false;
209
+ this.#writes.delete(write);
210
+ });
211
+ this.#writes.add(write);
212
+ }
213
+ /** Waits for the last-use writes under way, before the store closes. */
214
+ async close() {
215
+ await Promise.all([...this.#writes]);
216
+ }
217
+ }
@@ -26,9 +26,14 @@ import type { Route } from "./server.js";
26
26
  * (mcp-secret-writes.ts tokenWriteOverRefused), and never writes a secret (secret-writes.ts). A Composio server names
27
27
  * its key by api_key_env (COMPOSIO_API_KEY, on the launcher's list of secrets, read at each use through secrets.ts
28
28
  * secret, sent to Composio's origin alone: composio-made.ts composioEnvKey), and its body names no address or headers.
29
- * There is no list or read of the servers here (listMcpServerNames above is the listing), and no generic save (saveMcpServer), so the
30
- * token saves no server at an address or with headers of its own. Previews, refreshes, sign-ins and Composio's
31
- * triggers stay refused. */
29
+ * There is no list or read of the servers here (listMcpServerNames above is the listing). The generic save
30
+ * (saveMcpServer) is served only when the operator names MCP origins (API_ONLY_MCP_ORIGINS_ENV), and then saves a
31
+ * per_run server (which keeps no credential) at one of those origins alone (apiOnlyMcpSave); unset, it is refused as
32
+ * any other route, so the token saves no server at an address or with headers of its own. Previews, refreshes,
33
+ * sign-ins and Composio's triggers stay refused;
34
+ * - the launch hook's host (the backend in front of this server) releases a firing it took and will start no run for
35
+ * (releaseTriggerFiring, triggers.ts release), so its trigger's room frees at once; with no launch hook the route is
36
+ * the route's own 422. */
32
37
  export declare const API_ONLY_ROUTES: ReadonlySet<string>;
33
38
  /** The trigger sources an apply on an API-only server makes once the server has the launch hook: the ones that fire on
34
39
  * its own clock and need nothing a refused route sets up. Each firing goes to the backend in front of it
@@ -46,8 +51,15 @@ export declare function apiOnlyTriggerSkipped(packageName: string, trigger: {
46
51
  reason: typeof NOT_SET_UP | "not_an_option";
47
52
  message: string;
48
53
  } | undefined;
54
+ /** Whether an API-only server saves `body` through the generic save (saveMcpServer) over the name its path gives: a
55
+ * per_run server (no credential kept) whose url's origin is one of `origins`, under a name that is not a Composio
56
+ * preset's (`preset`; Composio's own route saves those). Checked before anything reaches the address. A body that
57
+ * carries a credential never gets here: the secret-write gate refuses it first (403), as it refuses the token's save
58
+ * over a server it did not save or one that seals a credential (mcp-secret-writes.ts tokenWriteOverRefused). */
59
+ export declare function apiOnlyMcpSave(body: unknown, preset: boolean, origins: readonly string[]): boolean;
49
60
  /** Whether an API-only server serves `method` on `raw` (the path as sent, its query cut): a /v2 path one of
50
- * API_ONLY_ROUTES matches for that method (HEAD as GET), or a GET of a run's computer live view. */
51
- export declare function servedApiOnly(routes: readonly Route[], method: string | undefined, raw: string): boolean;
61
+ * API_ONLY_ROUTES matches for that method (HEAD as GET), the generic MCP save when the operator names MCP origins
62
+ * (`mcpSave`, its body checked at the route: apiOnlyMcpSave), or a GET of a run's computer live view. */
63
+ export declare function servedApiOnly(routes: readonly Route[], method: string | undefined, raw: string, mcpSave?: boolean): boolean;
52
64
  /** The refusal's words for `raw` on an API-only server. */
53
65
  export declare const apiOnlyRefusal: (raw: string) => string;
package/dist/api-only.js CHANGED
@@ -2,7 +2,8 @@
2
2
  // deploy's routes alone, and refuses every other address before anything else reads the request: the console at "/" and
3
3
  // its assets, sign-in and setup, settings but the MCP servers' names, a Composio server's save and the delete of a server
4
4
  // (the secret-write gate lets the token save over or delete only a server it saved, mcp-secret-writes.ts), the MCP
5
- // endpoint, triggers and their webhook hooks, the rest of agents and templates. Off by default.
5
+ // endpoint, triggers and their webhook hooks (all but a firing's release, which the launch hook's host sends), the rest
6
+ // of agents and templates. Off by default.
6
7
  import { API_ONLY_ENV } from "./env-switch.js";
7
8
  import { NOT_SET_UP } from "./runnable.js";
8
9
  import { LAUNCH_HOOK_SECRET_ENV, LAUNCH_HOOK_URL_ENV } from "./trigger-launch-hook.js";
@@ -32,9 +33,14 @@ import { LAUNCH_HOOK_SECRET_ENV, LAUNCH_HOOK_URL_ENV } from "./trigger-launch-ho
32
33
  * (mcp-secret-writes.ts tokenWriteOverRefused), and never writes a secret (secret-writes.ts). A Composio server names
33
34
  * its key by api_key_env (COMPOSIO_API_KEY, on the launcher's list of secrets, read at each use through secrets.ts
34
35
  * secret, sent to Composio's origin alone: composio-made.ts composioEnvKey), and its body names no address or headers.
35
- * There is no list or read of the servers here (listMcpServerNames above is the listing), and no generic save (saveMcpServer), so the
36
- * token saves no server at an address or with headers of its own. Previews, refreshes, sign-ins and Composio's
37
- * triggers stay refused. */
36
+ * There is no list or read of the servers here (listMcpServerNames above is the listing). The generic save
37
+ * (saveMcpServer) is served only when the operator names MCP origins (API_ONLY_MCP_ORIGINS_ENV), and then saves a
38
+ * per_run server (which keeps no credential) at one of those origins alone (apiOnlyMcpSave); unset, it is refused as
39
+ * any other route, so the token saves no server at an address or with headers of its own. Previews, refreshes,
40
+ * sign-ins and Composio's triggers stay refused;
41
+ * - the launch hook's host (the backend in front of this server) releases a firing it took and will start no run for
42
+ * (releaseTriggerFiring, triggers.ts release), so its trigger's room frees at once; with no launch hook the route is
43
+ * the route's own 422. */
38
44
  export const API_ONLY_ROUTES = new Set([
39
45
  "createRun", "createInlineRun", "getComputerDaemon",
40
46
  "getRunComputer", "takeOverRunComputer", "handBackRunComputer", "createRunComputerViewer",
@@ -47,7 +53,7 @@ export const API_ONLY_ROUTES = new Set([
47
53
  "createFile", "listFiles", "getFile", "uploadFile", "deleteFile",
48
54
  "getCapabilities", "getHealth", "getUsage", "getCapacity", "listMcpServerNames",
49
55
  "importTemplate", "applyTemplate", "getAgent", "listRevisions", "setCurrent", "archiveAgent", "unarchiveAgent",
50
- "saveComposioServer", "deleteMcpServer",
56
+ "saveComposioServer", "deleteMcpServer", "releaseTriggerFiring",
51
57
  // Refused in its own words (403): it reads the machine's session files, which a server behind a backend does not have to give.
52
58
  "getWrapped",
53
59
  ]);
@@ -69,18 +75,38 @@ export function apiOnlyTriggerSkipped(packageName, trigger, hooked) {
69
75
  return undefined;
70
76
  return { reason: NOT_SET_UP, message: `${named} and has no launch hook, so its firings have nowhere to go. Start its runs through the API, or set the launch hook (${LAUNCH_HOOK_URL_ENV} and ${LAUNCH_HOOK_SECRET_ENV}) and apply again: each firing then goes to your backend, which starts its run.` };
71
77
  }
78
+ /** Whether an API-only server saves `body` through the generic save (saveMcpServer) over the name its path gives: a
79
+ * per_run server (no credential kept) whose url's origin is one of `origins`, under a name that is not a Composio
80
+ * preset's (`preset`; Composio's own route saves those). Checked before anything reaches the address. A body that
81
+ * carries a credential never gets here: the secret-write gate refuses it first (403), as it refuses the token's save
82
+ * over a server it did not save or one that seals a credential (mcp-secret-writes.ts tokenWriteOverRefused). */
83
+ export function apiOnlyMcpSave(body, preset, origins) {
84
+ if (preset || origins.length === 0 || body === null || typeof body !== "object")
85
+ return false;
86
+ const { url, auth } = body;
87
+ if (auth === null || typeof auth !== "object" || auth.type !== "per_run" || typeof url !== "string")
88
+ return false;
89
+ try {
90
+ return origins.includes(new URL(url).origin);
91
+ }
92
+ catch {
93
+ return false;
94
+ }
95
+ }
72
96
  /** A run's computer live view: its page, files and socket, which take the viewer credential alone here (server.ts). */
73
97
  const COMPUTER_LIVE = /^\/v2\/runs\/[^/]+\/computer\/live\//;
74
98
  /** Whether an API-only server serves `method` on `raw` (the path as sent, its query cut): a /v2 path one of
75
- * API_ONLY_ROUTES matches for that method (HEAD as GET), or a GET of a run's computer live view. */
76
- export function servedApiOnly(routes, method, raw) {
99
+ * API_ONLY_ROUTES matches for that method (HEAD as GET), the generic MCP save when the operator names MCP origins
100
+ * (`mcpSave`, its body checked at the route: apiOnlyMcpSave), or a GET of a run's computer live view. */
101
+ export function servedApiOnly(routes, method, raw, mcpSave = false) {
77
102
  if (!raw.startsWith("/v2/"))
78
103
  return false;
79
104
  const path = raw.slice(3);
80
105
  const asked = method === "HEAD" ? "GET" : method;
81
106
  if (asked === "GET" && COMPUTER_LIVE.test(raw))
82
107
  return true;
83
- return routes.some((route) => API_ONLY_ROUTES.has(route.name) && route.method === asked && route.pattern.test(path));
108
+ const served = (name) => API_ONLY_ROUTES.has(name) || (name === "saveMcpServer" && mcpSave);
109
+ return routes.some((route) => served(route.name) && route.method === asked && route.pattern.test(path));
84
110
  }
85
111
  /** The refusal's words for `raw` on an API-only server. */
86
112
  export const apiOnlyRefusal = (raw) => `this server serves the run API only (${API_ONLY_ENV}=1): ${raw} is not served here`;
@@ -0,0 +1,23 @@
1
+ import type { WaitEndedSettings } from "./browser-wait-ended.js";
2
+ /** A take of the run's browser in force: the session's tag and when it went live (ISO). */
3
+ export type BrowserHeld = {
4
+ session: string;
5
+ at: string;
6
+ };
7
+ /** The settings key a run's browser take is kept under (the run's delete removes it: server.ts). */
8
+ export declare const browserHoldKey: (runId: string) => string;
9
+ /** The run's process, as a take of its browser goes live. */
10
+ export declare function markBrowserHeld(settings: WaitEndedSettings, runId: string, held: BrowserHeld, epoch?: number): Promise<void>;
11
+ /** The run's process, as a take ends (given back, idle, away, the cap, the session gone, an answered ask), as a browser
12
+ * session opens, or at the run's end. Given the claim's `epoch`, a take a later claim wrote stays. Given `session`, only
13
+ * that session's take goes (another session's take, live meanwhile, stays). */
14
+ export declare function clearBrowserHeld(settings: WaitEndedSettings, runId: string, epoch?: number, session?: string): Promise<void>;
15
+ /** Whether the owner holds the run's browser now: one settings read; a value of another shape is no take. */
16
+ export declare function browserHeld(settings: Pick<WaitEndedSettings, "get">, runId: string): Promise<boolean>;
17
+ /** The run's process's writes of its browser's take, each after the one before it, so a quick take and hand-back can never
18
+ * land backward (the hand-back's removal reading before the take's write is in). The first removes any take an earlier
19
+ * process of the run left: this process's viewers start with nobody holding the browser. A write that fails leaves the
20
+ * ones after it to run. */
21
+ export declare function browserHoldWriter(settings: WaitEndedSettings, runId: string, epoch?: number): {
22
+ held(tag: string, on: boolean, at: number): Promise<void>;
23
+ };