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

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 (312) hide show
  1. package/CHANGELOG.md +281 -0
  2. package/README.md +246 -66
  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 +15 -5
  11. package/dist/api-only.js +32 -8
  12. package/dist/box-paths.d.ts +4 -3
  13. package/dist/box-paths.js +7 -4
  14. package/dist/browser-hold.d.ts +23 -0
  15. package/dist/browser-hold.js +48 -0
  16. package/dist/browser-person.d.ts +3 -0
  17. package/dist/browser-person.js +4 -1
  18. package/dist/chatgpt-plan.d.ts +18 -8
  19. package/dist/chatgpt-plan.js +91 -34
  20. package/dist/claude-login-token.d.ts +117 -0
  21. package/dist/claude-login-token.js +737 -0
  22. package/dist/claude-login.d.ts +120 -22
  23. package/dist/claude-login.js +347 -63
  24. package/dist/claude-sign-in.d.ts +17 -6
  25. package/dist/claude-sign-in.js +42 -39
  26. package/dist/cli.js +33 -10
  27. package/dist/composio-made.d.ts +4 -0
  28. package/dist/composio-made.js +4 -0
  29. package/dist/composio-preset.d.ts +43 -2
  30. package/dist/composio-preset.js +92 -4
  31. package/dist/computer-attach.d.ts +35 -17
  32. package/dist/computer-attach.js +301 -49
  33. package/dist/computer-held-routes.d.ts +5 -4
  34. package/dist/computer-held-routes.js +29 -8
  35. package/dist/computer-held.d.ts +6 -1
  36. package/dist/computer-held.js +14 -0
  37. package/dist/computer-record.js +4 -2
  38. package/dist/computer-viewer.js +4 -1
  39. package/dist/computers.d.ts +10 -10
  40. package/dist/computers.js +5 -5
  41. package/dist/console/assets/{backend-Boh7tC4i.js → backend-CSAWUqtZ.js} +19 -19
  42. package/dist/console/assets/index-Bwn1oTem.css +1 -0
  43. package/dist/console/assets/index-DPh29cyz.js +747 -0
  44. package/dist/console/index.html +2 -2
  45. package/dist/decisions.d.ts +1 -1
  46. package/dist/decisions.js +1 -1
  47. package/dist/dial-relay.d.ts +25 -4
  48. package/dist/dial-relay.js +129 -1
  49. package/dist/docker-host-addresses.d.ts +22 -11
  50. package/dist/docker-host-addresses.js +38 -26
  51. package/dist/env-switch.d.ts +8 -0
  52. package/dist/env-switch.js +31 -2
  53. package/dist/errors.d.ts +1 -0
  54. package/dist/errors.js +2 -0
  55. package/dist/fal-price.d.ts +56 -20
  56. package/dist/fal-price.js +400 -90
  57. package/dist/handed-values.d.ts +43 -1
  58. package/dist/handed-values.js +119 -2
  59. package/dist/harness-archive.d.ts +13 -10
  60. package/dist/harness-archive.js +60 -34
  61. package/dist/harness-check.d.ts +3 -1
  62. package/dist/harness-check.js +25 -46
  63. package/dist/harness-keys.d.ts +73 -27
  64. package/dist/harness-keys.js +194 -61
  65. package/dist/harness-recipe-entry.d.ts +8 -7
  66. package/dist/harness-recipe-entry.js +21 -32
  67. package/dist/harness-recipe.d.ts +38 -25
  68. package/dist/harness-recipe.js +49 -36
  69. package/dist/harness-sign-in.js +12 -23
  70. package/dist/harness-table.d.ts +10 -3
  71. package/dist/harness-table.js +26 -21
  72. package/dist/harness.d.ts +1 -0
  73. package/dist/harness.js +17 -5
  74. package/dist/hosted-search.d.ts +1 -1
  75. package/dist/hosted-search.js +1 -2
  76. package/dist/import-worker.d.ts +4 -2
  77. package/dist/import-worker.js +9 -2
  78. package/dist/in-flight.d.ts +26 -0
  79. package/dist/in-flight.js +52 -0
  80. package/dist/key-refusal.d.ts +9 -4
  81. package/dist/key-refusal.js +107 -25
  82. package/dist/learn/ledger.d.ts +170 -0
  83. package/dist/learn/ledger.js +218 -0
  84. package/dist/learn/promote.d.ts +3 -3
  85. package/dist/learn/promote.js +1 -1
  86. package/dist/learn/secrets.d.ts +13 -3
  87. package/dist/learn/secrets.js +118 -17
  88. package/dist/learning-cost.d.ts +28 -23
  89. package/dist/learning-cost.js +19 -23
  90. package/dist/link-check.js +1 -1
  91. package/dist/live-reach.d.ts +2 -0
  92. package/dist/live-reach.js +2 -0
  93. package/dist/llms.txt +1 -1
  94. package/dist/marketplace.d.ts +77 -0
  95. package/dist/marketplace.js +224 -0
  96. package/dist/mcp-api-only-origins.d.ts +35 -0
  97. package/dist/mcp-api-only-origins.js +57 -0
  98. package/dist/mcp-gateway.d.ts +7 -5
  99. package/dist/mcp-gateway.js +9 -12
  100. package/dist/mcp-secret-writes.js +5 -3
  101. package/dist/mcp-servers-store.d.ts +28 -6
  102. package/dist/mcp-servers-store.js +53 -4
  103. package/dist/media-duration.d.ts +3 -0
  104. package/dist/media-duration.js +90 -9
  105. package/dist/micro.d.ts +2 -0
  106. package/dist/micro.js +2 -0
  107. package/dist/model-form.d.ts +5 -4
  108. package/dist/model-form.js +11 -7
  109. package/dist/model.d.ts +10 -6
  110. package/dist/model.js +16 -11
  111. package/dist/monid.d.ts +14 -1
  112. package/dist/monid.js +103 -26
  113. package/dist/ollama-provider.d.ts +7 -1
  114. package/dist/ollama-provider.js +14 -2
  115. package/dist/openapi.js +210 -37
  116. package/dist/otel/genai.d.ts +65 -0
  117. package/dist/otel/genai.js +116 -0
  118. package/dist/otel/tracer.d.ts +55 -0
  119. package/dist/otel/tracer.js +308 -0
  120. package/dist/page.d.ts +2 -0
  121. package/dist/page.js +3 -1
  122. package/dist/paid-calls.d.ts +1 -32
  123. package/dist/paid-calls.js +4 -39
  124. package/dist/place-offers.d.ts +4 -0
  125. package/dist/place-offers.js +7 -4
  126. package/dist/provider.d.ts +11 -2
  127. package/dist/provider.js +59 -8
  128. package/dist/redact/match.d.ts +30 -3
  129. package/dist/redact/match.js +422 -41
  130. package/dist/refusal-words.d.ts +11 -0
  131. package/dist/refusal-words.js +11 -0
  132. package/dist/run-census.d.ts +67 -0
  133. package/dist/run-census.js +240 -0
  134. package/dist/run-computer.d.ts +6 -3
  135. package/dist/run-computer.js +4 -1
  136. package/dist/run-cut.d.ts +15 -6
  137. package/dist/run-cut.js +30 -9
  138. package/dist/run-files.d.ts +3 -0
  139. package/dist/run-files.js +3 -0
  140. package/dist/run-launch.d.ts +12 -1
  141. package/dist/run-launch.js +9 -10
  142. package/dist/run-learning-served.d.ts +4 -2
  143. package/dist/run-model-key.d.ts +8 -0
  144. package/dist/run-model-key.js +31 -1
  145. package/dist/run-reads-over-store.d.ts +24 -6
  146. package/dist/run-reads-over-store.js +67 -23
  147. package/dist/run-recordings.d.ts +5 -1
  148. package/dist/run-recordings.js +39 -14
  149. package/dist/run-timeline-served.d.ts +2 -0
  150. package/dist/run-timeline-served.js +2 -2
  151. package/dist/run-usage.d.ts +1 -0
  152. package/dist/run-view.d.ts +1 -2
  153. package/dist/run-view.js +2 -1
  154. package/dist/runnable.d.ts +10 -1
  155. package/dist/runnable.js +20 -8
  156. package/dist/runner/adapter-loop.d.ts +11 -0
  157. package/dist/runner/adapter-loop.js +58 -26
  158. package/dist/runner/adapter-run-spec.d.ts +55 -11
  159. package/dist/runner/adapter-run-spec.js +183 -52
  160. package/dist/runner/adapters/pi.js +25 -3
  161. package/dist/runner/beside.d.ts +9 -2
  162. package/dist/runner/beside.js +27 -9
  163. package/dist/runner/big-writes.js +1 -10
  164. package/dist/runner/claim-secrets.d.ts +27 -10
  165. package/dist/runner/claim-secrets.js +49 -22
  166. package/dist/runner/cli-run-spec.d.ts +6 -0
  167. package/dist/runner/cli-run-spec.js +97 -38
  168. package/dist/runner/computer-journal.d.ts +9 -1
  169. package/dist/runner/computer-journal.js +26 -0
  170. package/dist/runner/conformance/harness.js +1 -1
  171. package/dist/runner/feedback-round.js +3 -0
  172. package/dist/runner/harness-loops.d.ts +6 -5
  173. package/dist/runner/harness-loops.js +7 -7
  174. package/dist/runner/held.d.ts +24 -6
  175. package/dist/runner/journal-kinds.d.ts +5 -0
  176. package/dist/runner/journal-kinds.js +5 -0
  177. package/dist/runner/main.d.ts +11 -6
  178. package/dist/runner/main.js +19 -9
  179. package/dist/runner/mcp-claim.js +31 -3
  180. package/dist/runner/mcp-run.d.ts +9 -0
  181. package/dist/runner/mcp-run.js +11 -5
  182. package/dist/runner/model-route.d.ts +17 -0
  183. package/dist/runner/model-route.js +120 -2
  184. package/dist/runner/presence.d.ts +11 -1
  185. package/dist/runner/presence.js +7 -0
  186. package/dist/runner/reflect-hook.js +1 -1
  187. package/dist/runner/run-child-host.d.ts +22 -8
  188. package/dist/runner/run-child-host.js +128 -41
  189. package/dist/runner/run-child.js +5 -2
  190. package/dist/runner/runner.d.ts +17 -3
  191. package/dist/runner/runner.js +130 -34
  192. package/dist/runner/save-slots.js +2 -1
  193. package/dist/runner/store-port.d.ts +1 -1
  194. package/dist/runner/store-secrets.d.ts +6 -0
  195. package/dist/runner/store-secrets.js +49 -7
  196. package/dist/runner/subagent.d.ts +11 -0
  197. package/dist/runner/subagent.js +16 -38
  198. package/dist/runner/workflow-first.d.ts +35 -15
  199. package/dist/runner/workflow-first.js +38 -25
  200. package/dist/runner/workflow-spec.js +4 -3
  201. package/dist/runs-over-store.d.ts +15 -6
  202. package/dist/runs-over-store.js +33 -21
  203. package/dist/scrub-command.d.ts +73 -0
  204. package/dist/scrub-command.js +307 -0
  205. package/dist/secret-cut.d.ts +73 -0
  206. package/dist/secret-cut.js +291 -4
  207. package/dist/secret-rules.d.ts +143 -0
  208. package/dist/secret-rules.js +2564 -0
  209. package/dist/secrets.d.ts +7 -0
  210. package/dist/secrets.js +20 -0
  211. package/dist/server-keys.d.ts +20 -0
  212. package/dist/server-keys.js +25 -6
  213. package/dist/server.d.ts +65 -13
  214. package/dist/server.js +470 -157
  215. package/dist/skills/agentrun-serve/SKILL.md +4 -0
  216. package/dist/slots.d.ts +9 -0
  217. package/dist/slots.js +45 -0
  218. package/dist/store/index.d.ts +1 -1
  219. package/dist/store/index.js +1 -1
  220. package/dist/store/journal/storage.js +1 -1
  221. package/dist/store/postgres/migrations/0027_run_launch_census.sql +31 -0
  222. package/dist/store/postgres/migrations/0028_learning_ledger.sql +44 -0
  223. package/dist/store/schema.d.ts +23 -0
  224. package/dist/store/schema.js +58 -2
  225. package/dist/store/seal.d.ts +6 -1
  226. package/dist/store/seal.js +5 -3
  227. package/dist/store/sqlite/run-launch.d.ts +9 -1
  228. package/dist/store/sqlite/run-launch.js +24 -13
  229. package/dist/store/sqlite/run-patch.d.ts +12 -2
  230. package/dist/store/sqlite/run-patch.js +42 -5
  231. package/dist/store/sqlite/store.js +105 -12
  232. package/dist/store/store.d.ts +57 -2
  233. package/dist/store/store.js +20 -0
  234. package/dist/store-reads/learning.d.ts +84 -124
  235. package/dist/store-reads/learning.js +210 -274
  236. package/dist/store-view.d.ts +3 -0
  237. package/dist/store-view.js +3 -3
  238. package/dist/suggestions.js +3 -2
  239. package/dist/template-eval.d.ts +39 -9
  240. package/dist/template-eval.js +191 -60
  241. package/dist/template-import.js +6 -2
  242. package/dist/templates.d.ts +10 -2
  243. package/dist/templates.js +28 -8
  244. package/dist/timeline/labels.d.ts +6 -4
  245. package/dist/timeline/labels.js +18 -6
  246. package/dist/timeline/timeline.d.ts +5 -0
  247. package/dist/timeline/timeline.js +14 -8
  248. package/dist/timeline/util.js +1 -1
  249. package/dist/timeline/web-calls.d.ts +22 -7
  250. package/dist/timeline/web-calls.js +106 -35
  251. package/dist/tool-gate.d.ts +42 -3
  252. package/dist/tool-gate.js +66 -5
  253. package/dist/tool-keys-store.d.ts +2 -4
  254. package/dist/tool-keys-store.js +5 -21
  255. package/dist/tool-keys.d.ts +2 -2
  256. package/dist/tool-keys.js +2 -2
  257. package/dist/tool-list.js +1 -1
  258. package/dist/tool-plane.d.ts +2 -2
  259. package/dist/tool-plane.js +35 -33
  260. package/dist/tools.js +13 -7
  261. package/dist/trigger-targets.d.ts +4 -0
  262. package/dist/trigger-targets.js +9 -2
  263. package/dist/triggers.d.ts +67 -4
  264. package/dist/triggers.js +171 -22
  265. package/dist/until.d.ts +3 -0
  266. package/dist/until.js +11 -0
  267. package/dist/web-fake.d.ts +1 -3
  268. package/dist/web-fake.js +7 -18
  269. package/dist/web-fetch.d.ts +6 -72
  270. package/dist/web-fetch.js +11 -265
  271. package/dist/web-run.d.ts +31 -0
  272. package/dist/web-run.js +90 -0
  273. package/dist/web-save.d.ts +10 -13
  274. package/dist/web-save.js +13 -55
  275. package/dist/web-search.d.ts +9 -127
  276. package/dist/web-search.js +23 -259
  277. package/dist/wires.d.ts +13 -0
  278. package/dist/wires.js +11 -0
  279. package/dist/workflow-run.d.ts +5 -4
  280. package/dist/workflow-run.js +5 -4
  281. package/dist/workspace/attached-computers.d.ts +32 -9
  282. package/dist/workspace/attached-computers.js +77 -13
  283. package/dist/workspace/computer-deps.d.ts +8 -2
  284. package/dist/workspace/computer-deps.js +10 -3
  285. package/dist/workspace/computer-for-claim.d.ts +12 -1
  286. package/dist/workspace/computer-for-claim.js +83 -11
  287. package/dist/workspace/computer-kept.d.ts +3 -0
  288. package/dist/workspace/computer-kept.js +11 -2
  289. package/dist/workspace/index.d.ts +1 -1
  290. package/dist/workspace/index.js +1 -1
  291. package/dist/workspace/kind-skills.d.ts +4 -0
  292. package/dist/workspace/kind-skills.js +9 -0
  293. package/dist/workspace/paired-route.d.ts +91 -0
  294. package/dist/workspace/paired-route.js +153 -0
  295. package/dist/workspace/synced-folder.js +3 -4
  296. package/dist/wrapped.d.ts +20 -6
  297. package/dist/wrapped.js +66 -25
  298. package/package.json +17 -11
  299. package/skills/agentrun-serve/SKILL.md +4 -0
  300. package/templates/README.md +32 -10
  301. package/dist/console/assets/index-CQ3cJRzI.js +0 -746
  302. package/dist/console/assets/index-DKkaS3a0.css +0 -1
  303. package/dist/exa-keyless.d.ts +0 -34
  304. package/dist/exa-keyless.js +0 -118
  305. package/dist/firecrawl-keyless.d.ts +0 -41
  306. package/dist/firecrawl-keyless.js +0 -152
  307. package/dist/keyless-mcp.d.ts +0 -36
  308. package/dist/keyless-mcp.js +0 -127
  309. package/dist/text-urls.d.ts +0 -38
  310. package/dist/text-urls.js +0 -170
  311. package/dist/web-fetch-direct.d.ts +0 -119
  312. package/dist/web-fetch-direct.js +0 -190
@@ -6,8 +6,8 @@
6
6
  <meta name="color-scheme" content="light dark" />
7
7
  <title>AgentRun</title>
8
8
  <link rel="icon" type="image/svg+xml" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Crect width='32' height='32' fill='%23ff8000'/%3E%3Cpath d='M12 9l11 7-11 7z' fill='%23000'/%3E%3C/svg%3E" />
9
- <script type="module" crossorigin src="./assets/index-CQ3cJRzI.js"></script>
10
- <link rel="stylesheet" crossorigin href="./assets/index-DKkaS3a0.css">
9
+ <script type="module" crossorigin src="./assets/index-DPh29cyz.js"></script>
10
+ <link rel="stylesheet" crossorigin href="./assets/index-Bwn1oTem.css">
11
11
  </head>
12
12
  <body>
13
13
  <div id="root"></div>
@@ -50,7 +50,7 @@ export declare const jevRoute: (env: NodeJS.ProcessEnv) => "typesafe" | "openrou
50
50
  * OpenRouter's Decisions models, on either Jev route; and Parallel's. */
51
51
  export declare function decisionKeysOf(env: NodeJS.ProcessEnv): Record<string, string>;
52
52
  /** What a run's decision keys are for: the providers of its workflow's typed questions (providersNamed), and whether one
53
- * of its web tools resolves to Parallel (tool-plane.ts' handsParallel), whose client reads Parallel's key (web-fetch.ts). */
53
+ * of its web tools resolves to Parallel (tool-plane.ts' handsParallel), whose client reads Parallel's key (web-run.ts webOf). */
54
54
  export type DecisionNeeds = {
55
55
  providers: readonly string[];
56
56
  parallelWeb: boolean;
package/dist/decisions.js CHANGED
@@ -8,7 +8,7 @@
8
8
  // The server chooses the keys a run needs (decisionKeysFor) and hands them over once, by name, on an inherited pipe
9
9
  // (`DECISION_KEY_FD_ENV` names it), at each launch of the run: its workflow's decision providers' keys, and Parallel's
10
10
  // where one of its web tools resolves to Parallel (tool-plane.ts); a run that needs none gets no pipe. The run's process
11
- // reads them once (handedKeys) into its providers and the web tools' Parallel client (web-fetch.ts), and nowhere else;
11
+ // reads them once (handedKeys) into its providers and the web tools' Parallel client (web-run.ts webOf), and nowhere else;
12
12
  // no provider reads a key from the environment. The TypeSafe and Parallel keys never enter a run's environment, which
13
13
  // the run's tools and its model's provider read (`ToolHost.env`, a call node's effect): the server drops the variables
14
14
  // from the run's process. On the OpenRouter route the Jev key is also the model gateway's key, which the run's process
@@ -1,10 +1,13 @@
1
- import { type HostedDial } from "@parcha/agentrun-computer";
1
+ import { AttachHub, type HostedDial } from "@parcha/agentrun-computer";
2
2
  import { type AttachTiming } from "./computer-attach.js";
3
- import type { Presence } from "./runner/presence.js";
3
+ import { type Presence } from "./runner/presence.js";
4
4
  import type { Store } from "./store/index.js";
5
- /** A runner's relay: its HostedDial for its providers, where its listener answers, and its close. */
5
+ import { type PairedRelay } from "./workspace/attached-computers.js";
6
+ /** A runner's relay: its HostedDial for its providers, the paired computers' bring and let-go, where its listener
7
+ * answers, and its close. */
6
8
  export interface RunnerRelay {
7
9
  readonly dial: HostedDial;
10
+ readonly paired: PairedRelay;
8
11
  readonly incarnation: string;
9
12
  readonly host: string;
10
13
  readonly port: number;
@@ -12,7 +15,7 @@ export interface RunnerRelay {
12
15
  close(): Promise<void>;
13
16
  }
14
17
  export interface RunnerRelayOptions {
15
- readonly store: Pick<Store, "mintedTokens" | "pairedComputers">;
18
+ readonly store: Pick<Store, "mintedTokens" | "pairedComputers" | "settings" | "runners" | "runs">;
16
19
  readonly sealKey: Buffer;
17
20
  /** The runner's name, as its claims and its row carry it. */
18
21
  readonly runner: string;
@@ -29,5 +32,23 @@ export interface RunnerRelayOptions {
29
32
  }
30
33
  /** The server's public address as this runner's environment names it (cli.ts reads the same two), or undefined. */
31
34
  export declare function publicUrlOf(env: NodeJS.ProcessEnv): string | undefined;
35
+ /** What pairedRelayOn needs: the store's routes, runners and runs; the hub the box is brought to; the runner (and its
36
+ * incarnation) the routes name; where a route it could not drop is said; the clock. */
37
+ export interface PairedRelayOnOptions {
38
+ readonly store: Pick<Store, "settings" | "runners" | "runs">;
39
+ readonly hub: AttachHub;
40
+ readonly runner: string;
41
+ readonly incarnation: string;
42
+ readonly log?: (line: string) => void;
43
+ readonly now?: () => number;
44
+ }
45
+ /** The paired computers' bring and let-go over `hub` for runner `runner` of incarnation `incarnation`: a runner apart's
46
+ * own hub (startRunnerRelay), or the server's for the runner beside it in its process (runner/beside.ts). `left` is
47
+ * told when a box's socket leaves the hub; `stop` ends the sweep of the routes it brought. */
48
+ export declare function pairedRelayOn(options: PairedRelayOnOptions): {
49
+ readonly paired: PairedRelay;
50
+ left(id: string): Promise<void>;
51
+ stop(): void;
52
+ };
32
53
  /** The runner's relay, started: undefined where its environment names no public address of the server's. */
33
54
  export declare function startRunnerRelay(options: RunnerRelayOptions): Promise<RunnerRelay | undefined>;
@@ -16,17 +16,136 @@
16
16
  //
17
17
  // A runner with no public address keeps no relay: its dial providers still refuse (hosted/provider.ts), and the server's
18
18
  // Settings → Computers still says so (computers.ts runs_refused).
19
+ //
20
+ // A paired computer reaches a run on this runner the same way (`paired`): the run's claim routes the box here
21
+ // (workspace/paired-route.ts takeRoute, under the run's claim) and waits until the server has moved its socket onto this
22
+ // hub (bring), and the run's release lets it go (letGo) once its hold ended, every remove or KILL it sent answered. The
23
+ // listener takes a paired computer's token only while its route names this runner and incarnation. A route this runner
24
+ // brought whose hold ended (released, or at its deadline) with no bring in flight is dropped at the next sweep
25
+ // (PRESENCE_RENEW_MS); and when the box's socket leaves this hub for a route that names another runner (the run resumed
26
+ // there), this runner's hold of it ends.
27
+ //
28
+ // The runner beside a server, in its process, brings and lets go of a paired box the same way (pairedRelayOn over the
29
+ // server's own hub, runner/beside.ts): its run's claim takes the box's route under that runner's name and incarnation,
30
+ // so a runner apart's take for another run is refused while the hold lasts, and the server's tick, which knows that
31
+ // runner (Serve.beside), keeps the box in its own hub.
19
32
  import { createServer } from "node:http";
33
+ import { setTimeout as sleep } from "node:timers/promises";
20
34
  import { ATTACH_PATH, AttachHub } from "@parcha/agentrun-computer";
21
35
  import { bearerOf, createAttachRoutes, sha256Hex } from "./computer-attach.js";
22
36
  import { LOOPBACK, relayKeyOf, relayProofs, runnerLiveOf } from "./live-reach.js";
23
37
  import { logLine } from "./print.js";
38
+ import { PRESENCE_RENEW_MS } from "./runner/presence.js";
39
+ import { PAIRED_ID_PREFIX } from "./workspace/attached-computers.js";
40
+ import { dropRoute, lateWords, PAIRED_BRING_MS, PAIRED_BRING_POLL_MS, readRoute, takeRoute } from "./workspace/paired-route.js";
41
+ /** A claim's failure to have its paired computer here, in words: the claim fails computer_unavailable with them. */
42
+ const unavailable = (words) => Object.assign(new Error(words), { code: "computer_unavailable" });
43
+ /** A bring whose claim was cancelled (its create's signal aborted) before the box reached runner `runner`. */
44
+ const cancelledWords = (name, runner) => `${name} was not brought to runner ${runner}: this run's claim was cancelled while it waited for the box, and its route was let go`;
24
45
  /** The server's public address as this runner's environment names it (cli.ts reads the same two), or undefined. */
25
46
  export function publicUrlOf(env) {
26
47
  const given = env.AGENTRUN_PUBLIC_URL || env.RENDER_EXTERNAL_URL;
27
48
  const parsed = given && URL.canParse(given) ? new URL(given) : undefined;
28
49
  return parsed && /^https?:$/.test(parsed.protocol) ? parsed.href.replace(/\/+$/, "") : undefined;
29
50
  }
51
+ /** The paired computers' bring and let-go over `hub` for runner `runner` of incarnation `incarnation`: a runner apart's
52
+ * own hub (startRunnerRelay), or the server's for the runner beside it in its process (runner/beside.ts). `left` is
53
+ * told when a box's socket leaves the hub; `stop` ends the sweep of the routes it brought. */
54
+ export function pairedRelayOn(options) {
55
+ const { store, hub, runner, incarnation, now = Date.now } = options;
56
+ const log = options.log ?? (() => { });
57
+ const mine = { runner, incarnation };
58
+ /** The routes this process brought, by computer: the run, when it was taken, and whether a hold was seen on it. */
59
+ const held = new Map();
60
+ /** The bring in flight per computer, by its run. */
61
+ const bringing = new Map();
62
+ /** When the box's socket leaves this hub: a route that now names another runner (or another process of this one)
63
+ * ends this runner's hold of it (the run resumed there); a route still here keeps it, for the box's redial. */
64
+ const left = async (id) => {
65
+ const route = await readRoute(store.settings, id);
66
+ if (route.runner === runner && route.incarnation === incarnation)
67
+ return;
68
+ const hold = hub.hold(id);
69
+ if (hold !== undefined)
70
+ await hub.unclaim(id, hold);
71
+ held.delete(id);
72
+ };
73
+ const paired = {
74
+ hub,
75
+ async bring(row, { run, until, claim, signal }) {
76
+ // A claim cancelled before its bring takes nothing.
77
+ if (signal?.aborted)
78
+ throw unavailable(cancelledWords(row.name, runner));
79
+ bringing.set(row.id, run);
80
+ try {
81
+ const took = await takeRoute({ settings: store.settings, runners: store.runners, runs: store.runs }, row.id, { ...mine, run, until }, { ...(claim ? { claim } : {}), name: row.name });
82
+ if (!took.taken)
83
+ throw unavailable(took.why);
84
+ held.set(row.id, { run, since: now(), seenHold: false });
85
+ const end = now() + PAIRED_BRING_MS;
86
+ for (;;) {
87
+ // The claim was cancelled while it waited: its route goes (the row removed while it is still this run's), and
88
+ // the claim fails in words at once, never waiting out PAIRED_BRING_MS.
89
+ if (signal?.aborted) {
90
+ await dropRoute(store.settings, row.id, { ...mine, run }).catch(() => undefined);
91
+ held.delete(row.id);
92
+ throw unavailable(cancelledWords(row.name, runner));
93
+ }
94
+ if (hub.online(row.id))
95
+ return;
96
+ const route = await readRoute(store.settings, row.id);
97
+ const ours = route.runner === runner && route.incarnation === incarnation && route.run === run;
98
+ // The server noted why the box can't come (not attached now, its relay refused), or the time is up: the route
99
+ // goes, its words kept on the row, and the claim fails in them. Never a hang.
100
+ const why = !ours ? (route.refused ?? `${row.name}'s route went to another run while this run waited for it: its next claim tries again`) : (route.refused ?? (now() >= end ? lateWords(row.name, runner) : undefined));
101
+ if (why !== undefined) {
102
+ if (ours)
103
+ await dropRoute(store.settings, row.id, { ...mine, run }, why).catch(() => undefined);
104
+ held.delete(row.id);
105
+ throw unavailable(why);
106
+ }
107
+ // A cancel wakes the wait at once; the loop's top answers it.
108
+ await sleep(PAIRED_BRING_POLL_MS, undefined, signal ? { signal } : undefined).catch(() => undefined);
109
+ }
110
+ }
111
+ finally {
112
+ if (bringing.get(row.id) === run)
113
+ bringing.delete(row.id);
114
+ }
115
+ },
116
+ async letGo(computer, hold, run) {
117
+ // Its hold ends first: unclaim waits for every remove or KILL it sent. A route stays while a hold is left here, or
118
+ // while another run's bring is in flight here.
119
+ if (hold !== undefined)
120
+ await hub.unclaim(computer, hold);
121
+ if (hub.hold(computer) !== undefined)
122
+ return;
123
+ const bring = bringing.get(computer);
124
+ if (bring !== undefined && bring !== run)
125
+ return;
126
+ held.delete(computer);
127
+ await dropRoute(store.settings, computer, { ...mine, ...(run !== undefined ? { run } : {}) });
128
+ },
129
+ };
130
+ // The sweep of the routes this process brought: one whose hold ended (released, or at its deadline), or that no hold
131
+ // took within PAIRED_BRING_MS, with no bring in flight, goes.
132
+ const sweep = setInterval(() => {
133
+ for (const [id, at] of held) {
134
+ if (bringing.has(id))
135
+ continue;
136
+ if (hub.hold(id) !== undefined) {
137
+ at.seenHold = true;
138
+ continue;
139
+ }
140
+ if (!at.seenHold && now() - at.since < PAIRED_BRING_MS)
141
+ continue;
142
+ held.delete(id);
143
+ void dropRoute(store.settings, id, { ...mine, run: at.run }).catch((error) => log(logLine("computer_route_undropped", { computer: id, run: at.run, error: error instanceof Error ? error.message : String(error) })));
144
+ }
145
+ }, PRESENCE_RENEW_MS);
146
+ sweep.unref();
147
+ return { paired, left, stop: () => clearInterval(sweep) };
148
+ }
30
149
  /** The runner's relay, started: undefined where its environment names no public address of the server's. */
31
150
  export async function startRunnerRelay(options) {
32
151
  const url = publicUrlOf(options.env);
@@ -38,9 +157,16 @@ export async function startRunnerRelay(options) {
38
157
  const live = runnerLiveOf(options.env, options.sealKey);
39
158
  const host = live?.host ?? LOOPBACK;
40
159
  const hub = new AttachHub();
160
+ const mine = { runner, incarnation };
161
+ const relayed = pairedRelayOn({ store, hub, runner, incarnation, log, now });
162
+ const { paired } = relayed;
41
163
  const routes = createAttachRoutes({
42
- store, hub, machinesOnly: true, owner: { runner, incarnation }, now,
164
+ store, hub, owner: mine, now,
43
165
  log: (event, fields) => log(logLine(event, fields)),
166
+ onSocket: (computer, ws) => {
167
+ if (computer.startsWith(PAIRED_ID_PREFIX))
168
+ ws.once("close", () => void relayed.left(computer).catch(() => undefined));
169
+ },
44
170
  ...(options.timing ? { timing: options.timing } : {}),
45
171
  });
46
172
  const proven = relayProofs(relayKeyOf(options.sealKey), now);
@@ -65,6 +191,7 @@ export async function startRunnerRelay(options) {
65
191
  });
66
192
  const port = server.address().port;
67
193
  const shut = async () => {
194
+ relayed.stop();
68
195
  await routes.close();
69
196
  server.closeAllConnections();
70
197
  await new Promise((resolve) => server.close(() => resolve()));
@@ -80,6 +207,7 @@ export async function startRunnerRelay(options) {
80
207
  let closing;
81
208
  return {
82
209
  dial: { url, tokens: routes.machineTokens, hub },
210
+ paired,
83
211
  incarnation,
84
212
  host,
85
213
  port,
@@ -7,6 +7,10 @@ export declare const READ_LABEL = "agentrun.read=host-addresses";
7
7
  export declare const readArgsOf: (name: string) => readonly string[];
8
8
  /** A fresh name for one read's container. */
9
9
  export declare const helperName: () => string;
10
+ /** How long removing a read's container, and checking it is gone, may each take: together within a server's stop
11
+ * deadline (stop-signals.ts DEADLINE_MARGIN_MS, compose's 15 s grace), as a read cut by the close removes its container
12
+ * inside that stop. A name not confirmed gone in time is kept and removed again later. */
13
+ export declare const REMOVE_MS = 5000;
10
14
  /** The addresses in the read's answer: each an IP address, the zone of a scoped one cut, loopback and link-local left out,
11
15
  * each once. */
12
16
  export declare function addressesOf(answer: string): string[];
@@ -16,22 +20,26 @@ export type HostRead = {
16
20
  } | {
17
21
  readonly why: string;
18
22
  };
19
- /** `docker` with `args`, bound to `ms`: its exit code (or the spawn's error code) and output. */
20
- export type DockerRun = (args: readonly string[], ms: number) => Promise<{
23
+ /** `docker` with `args`, bound to `ms` and ended at once when `signal` aborts: its exit code ("timeout" at the bound,
24
+ * "aborted" at the signal, the signal's name when another signal ended it, the spawn's error code when it never ran)
25
+ * and output. */
26
+ export type DockerRun = (args: readonly string[], ms: number, signal?: AbortSignal) => Promise<{
21
27
  code: number | string;
22
28
  stdout: string;
23
29
  stderr: string;
24
30
  }>;
25
31
  /** The Docker host's addresses, read through `env`'s docker as above, after removing the containers earlier reads left
26
- * (removeLeft). Never throws: a read that fails, or whose answer can't be read, says why; one that runs out of time or
27
- * exits non-zero has its container removed by name. `docker`, `ms` and `name` are the tests'. */
28
- export declare function readHostAddresses(env: NodeJS.ProcessEnv, docker?: DockerRun, ms?: number, name?: string): Promise<HostRead>;
32
+ * (removeLeft). Never throws: a read that fails, or whose answer can't be read, says why; one that ends any way but
33
+ * answering or never running (a spawn error) has its container removed by name. `signal` (the server's close) cuts
34
+ * the read at once, its client killed, and its container is removed then, within two REMOVE_MS. `docker`, `ms` and
35
+ * `name` are the tests'. */
36
+ export declare function readHostAddresses(env: NodeJS.ProcessEnv, docker?: DockerRun, ms?: number, name?: string, signal?: AbortSignal): Promise<HostRead>;
29
37
  /** The union of the read's addresses and the operator's, each once; the read's why when it failed. */
30
38
  export declare function unionOf(read: HostRead, named: readonly string[] | undefined): {
31
39
  addresses: string[];
32
40
  why?: string;
33
41
  };
34
- export declare function hostAddressesOnce(env: NodeJS.ProcessEnv): Promise<HostRead>;
42
+ export declare function hostAddressesOnce(env: NodeJS.ProcessEnv, signal?: AbortSignal): Promise<HostRead>;
35
43
  /** The waits before each read again after a read failed at the start, the last one repeated: soon at first, as a busy
36
44
  * host's Docker (an image pull, a loaded daemon) often answers within minutes, then every 4 minutes, so a daemon that
37
45
  * stays down costs one short-lived container each time and no more. */
@@ -41,13 +49,16 @@ export type Wait = (ms: number, signal: AbortSignal) => Promise<void>;
41
49
  /** Reads again through `env`'s docker after a read failed (`read`: hostAddressesOnce, so the runner beside the server
42
50
  * shares what it finds), waiting RETRY_MS before each, until one answers (`found` gets it). An answer is kept from then
43
51
  * on, so no later read removes what the failed ones left: on the same waits, the retry goes on removing those
44
- * containers (removeLeft) until none is left. All of it ends when `signal` aborts (the server's close, or a start that
45
- * failed): a pending wait ends at once, nothing more is read or removed, and a read in flight is not taken. `wait` and
46
- * `docker` are the tests'. */
52
+ * containers (removeLeft) until none is left. With no `read` (the operator's addresses are known, so no answer would
53
+ * change what is offered), it only removes them. All of it ends when `signal` aborts (the server's close, or a start
54
+ * that failed): a pending wait ends at once and nothing more is read or removed; a read in flight ends as `read` lets
55
+ * it (the server's is cut by the same signal) and its answer is not taken, and a removal in flight runs to its bound,
56
+ * so a close that awaits this promise has removed its containers or kept their names. `wait` and `docker` are the
57
+ * tests'. */
47
58
  export declare function retryHostAddresses({ env, read, found, signal, wait: waitFor, docker }: {
48
59
  env: NodeJS.ProcessEnv;
49
- read: () => Promise<HostRead>;
50
- found: (read: HostRead) => void;
60
+ read?: () => Promise<HostRead>;
61
+ found?: (read: HostRead) => void;
51
62
  signal: AbortSignal;
52
63
  wait?: Wait;
53
64
  docker?: DockerRun;
@@ -39,8 +39,10 @@ export const readArgsOf = (name) => [
39
39
  ];
40
40
  /** A fresh name for one read's container. */
41
41
  export const helperName = () => `agentrun-host-read-${randomBytes(6).toString("hex")}`;
42
- /** How long removing a read's container that ran out of time, and checking it is gone, may each take. */
43
- const REMOVE_MS = 15_000;
42
+ /** How long removing a read's container, and checking it is gone, may each take: together within a server's stop
43
+ * deadline (stop-signals.ts DEADLINE_MARGIN_MS, compose's 15 s grace), as a read cut by the close removes its container
44
+ * inside that stop. A name not confirmed gone in time is kept and removed again later. */
45
+ export const REMOVE_MS = 5_000;
44
46
  /** Loopback and link-local: no address another machine reaches the host by. */
45
47
  const local = (address) => /^127\./.test(address) || address === "::1" || /^169\.254\./.test(address) || /^fe[89ab][0-9a-f]:/i.test(address);
46
48
  /** The addresses in the read's answer: each an IP address, the zone of a scoped one cut, loopback and link-local left out,
@@ -51,10 +53,12 @@ export function addressesOf(answer) {
51
53
  const addresses = listed.filter((one) => typeof one === "string").map((one) => one.split("%")[0]);
52
54
  return [...new Set(addresses.filter((one) => isIP(one) !== 0 && !local(one)))];
53
55
  }
54
- const dockerRun = (env) => (args, ms) => new Promise((resolve) => {
55
- const child = execFile("docker", args, { env: withoutSecrets(env), timeout: ms, killSignal: "SIGKILL", maxBuffer: 64 * 1024 }, (error, stdout, stderr) => {
56
+ /** The spawn's error codes: a docker that never ran, so it made no container. */
57
+ const NEVER_RAN = new Set(["ENOENT", "EACCES"]);
58
+ const dockerRun = (env) => (args, ms, signal) => new Promise((resolve) => {
59
+ const child = execFile("docker", args, { env: withoutSecrets(env), timeout: ms, killSignal: "SIGKILL", maxBuffer: 64 * 1024, ...(signal ? { signal } : {}) }, (error, stdout, stderr) => {
56
60
  const failed = error;
57
- resolve({ code: !failed ? 0 : failed.killed ? "timeout" : typeof failed.code === "number" ? failed.code : (failed.code ?? failed.name), stdout: String(stdout), stderr: String(stderr) });
61
+ resolve({ code: !failed ? 0 : failed.name === "AbortError" ? "aborted" : failed.killed ? "timeout" : typeof failed.code === "number" ? failed.code : (failed.code ?? failed.signal ?? failed.name), stdout: String(stdout), stderr: String(stderr) });
58
62
  });
59
63
  child.stdin?.end();
60
64
  });
@@ -99,20 +103,26 @@ async function removeLeft(env, docker, signal) {
99
103
  }
100
104
  }
101
105
  /** The Docker host's addresses, read through `env`'s docker as above, after removing the containers earlier reads left
102
- * (removeLeft). Never throws: a read that fails, or whose answer can't be read, says why; one that runs out of time or
103
- * exits non-zero has its container removed by name. `docker`, `ms` and `name` are the tests'. */
104
- export async function readHostAddresses(env, docker = dockerRun(env), ms = READ_MS, name = helperName()) {
106
+ * (removeLeft). Never throws: a read that fails, or whose answer can't be read, says why; one that ends any way but
107
+ * answering or never running (a spawn error) has its container removed by name. `signal` (the server's close) cuts
108
+ * the read at once, its client killed, and its container is removed then, within two REMOVE_MS. `docker`, `ms` and
109
+ * `name` are the tests'. */
110
+ export async function readHostAddresses(env, docker = dockerRun(env), ms = READ_MS, name = helperName(), signal) {
105
111
  const kept = keptOf(env);
106
- await removeLeft(env, docker);
107
- const ran = await docker(readArgsOf(name), ms);
108
- if (ran.code === "timeout") {
112
+ await removeLeft(env, docker, signal);
113
+ if (signal?.aborted)
114
+ return { why: "the read through Docker's socket was stopped with the server" };
115
+ const ran = await docker(readArgsOf(name), ms, signal);
116
+ if (ran.code === "timeout" || ran.code === "aborted") {
109
117
  const removal = await removeHelper(docker, name, kept);
110
- return { why: `the read through Docker's socket took over ${ms / 1000} s (${removal.left === "gone" ? "its container was removed" : removal.words})` };
118
+ const what = ran.code === "timeout" ? `took over ${ms / 1000} s` : "was stopped with the server";
119
+ return { why: `the read through Docker's socket ${what} (${removal.left === "gone" ? "its container was removed" : removal.words})` };
111
120
  }
112
121
  if (ran.code !== 0) {
113
122
  const failed = `the read through Docker's socket failed (exit ${ran.code}: ${ran.stderr.trim().slice(0, 200)})`;
114
- // A docker that never ran (its spawn failed: no exit code) made no container.
115
- if (typeof ran.code !== "number")
123
+ // A docker that never ran (its spawn failed) made no container. One ended any other way, a signal from outside
124
+ // included (the OOM killer's), may have made it, running or never started.
125
+ if (typeof ran.code === "string" && NEVER_RAN.has(ran.code))
116
126
  return { why: failed };
117
127
  const removal = await removeHelper(docker, name, kept);
118
128
  return { why: removal.left === "there" ? `${failed} (${removal.words})` : failed };
@@ -130,14 +140,15 @@ export function unionOf(read, named) {
130
140
  return "why" in read ? { addresses, why: read.why } : { addresses };
131
141
  }
132
142
  /** One read per process, for each environment's docker (the binary PATH finds and the daemon it reaches), kept once it
133
- * succeeds: a server and the runner beside it share it, and a failed read is tried again at the next ask. */
143
+ * succeeds: a server and the runner beside it share it, and a failed read is tried again at the next ask. A read this
144
+ * call starts ends at `signal` (readHostAddresses). */
134
145
  const reads = new Map();
135
- export function hostAddressesOnce(env) {
146
+ export function hostAddressesOnce(env, signal) {
136
147
  const key = envKey(env);
137
148
  const known = reads.get(key);
138
149
  if (known)
139
150
  return known;
140
- const read = readHostAddresses(env).then((result) => {
151
+ const read = readHostAddresses(env, undefined, undefined, undefined, signal).then((result) => {
141
152
  if ("why" in result)
142
153
  reads.delete(key);
143
154
  return result;
@@ -153,16 +164,19 @@ const wait = (ms, signal) => delay(ms, undefined, { signal }).catch(() => undefi
153
164
  /** Reads again through `env`'s docker after a read failed (`read`: hostAddressesOnce, so the runner beside the server
154
165
  * shares what it finds), waiting RETRY_MS before each, until one answers (`found` gets it). An answer is kept from then
155
166
  * on, so no later read removes what the failed ones left: on the same waits, the retry goes on removing those
156
- * containers (removeLeft) until none is left. All of it ends when `signal` aborts (the server's close, or a start that
157
- * failed): a pending wait ends at once, nothing more is read or removed, and a read in flight is not taken. `wait` and
158
- * `docker` are the tests'. */
167
+ * containers (removeLeft) until none is left. With no `read` (the operator's addresses are known, so no answer would
168
+ * change what is offered), it only removes them. All of it ends when `signal` aborts (the server's close, or a start
169
+ * that failed): a pending wait ends at once and nothing more is read or removed; a read in flight ends as `read` lets
170
+ * it (the server's is cut by the same signal) and its answer is not taken, and a removal in flight runs to its bound,
171
+ * so a close that awaits this promise has removed its containers or kept their names. `wait` and `docker` are the
172
+ * tests'. */
159
173
  export async function retryHostAddresses({ env, read, found, signal, wait: waitFor = wait, docker = dockerRun(env) }) {
160
- let answered = false;
161
- for (let tried = 0; !signal.aborted; tried++) {
174
+ let answered = read === undefined;
175
+ for (let tried = 0; !signal.aborted && !(answered && keptOf(env).size === 0); tried++) {
162
176
  await waitFor(RETRY_MS[Math.min(tried, RETRY_MS.length - 1)], signal);
163
177
  if (signal.aborted)
164
178
  return;
165
- if (answered)
179
+ if (answered || !read)
166
180
  await removeLeft(env, docker, signal);
167
181
  else {
168
182
  const result = await read();
@@ -171,10 +185,8 @@ export async function retryHostAddresses({ env, read, found, signal, wait: waitF
171
185
  if ("why" in result)
172
186
  continue;
173
187
  answered = true;
174
- found(result);
188
+ found?.(result);
175
189
  }
176
- if (keptOf(env).size === 0)
177
- return;
178
190
  }
179
191
  }
180
192
  /** Why a Docker computer can't keep this server's allow-list from a container: no address of the Docker host is known,
@@ -11,4 +11,12 @@ declare const MEANS: {
11
11
  * in words that say what each means (a TypeError), so a typo never leaves the console open on a server meant to be
12
12
  * API-only. */
13
13
  export declare function switchFrom(name: keyof typeof MEANS, env?: NodeJS.ProcessEnv): boolean;
14
+ /** The MCP origins an API-only server's token may save a per_run MCP server at: the serve README's API-only section. */
15
+ export declare const API_ONLY_MCP_ORIGINS_ENV = "AGENTRUN_API_ONLY_MCP_ORIGINS";
16
+ /** The origins `value` (API_ONLY_MCP_ORIGINS_ENV) names, each once, in its order: none when unset or blank. An entry
17
+ * that is not an http or https origin alone (a path, query, fragment, user or password, or no URL at all) is refused
18
+ * (a TypeError naming the entry by its place, never its text, which could hold a password), and so is a wildcard
19
+ * (`https://*.example.com`), which would otherwise be taken as a literal host and match nothing. Empty entries are
20
+ * skipped. */
21
+ export declare function apiOnlyMcpOriginsFrom(value: string | undefined): string[];
14
22
  export {};
@@ -1,5 +1,5 @@
1
- // The server's two on/off settings, which the CLI reads before the rest of the server loads (cli.ts): this module
2
- // imports nothing.
1
+ // The server's two on/off settings, and the API-only profile's MCP origins, which the CLI reads before the rest of the
2
+ // server loads (cli.ts): this module imports nothing.
3
3
  /** The API-only profile (api-only.ts). */
4
4
  export const API_ONLY_ENV = "AGENTRUN_API_ONLY";
5
5
  /** The run-keys setting (run-keys.ts). */
@@ -21,3 +21,32 @@ export function switchFrom(name, env = process.env) {
21
21
  const [on, off] = MEANS[name];
22
22
  throw new TypeError(`${name} is 1 (${on}) or 0${off === undefined ? "" : ` (${off})`}, not ${JSON.stringify(env[name])}`);
23
23
  }
24
+ /** The MCP origins an API-only server's token may save a per_run MCP server at: the serve README's API-only section. */
25
+ export const API_ONLY_MCP_ORIGINS_ENV = "AGENTRUN_API_ONLY_MCP_ORIGINS";
26
+ /** The origins `value` (API_ONLY_MCP_ORIGINS_ENV) names, each once, in its order: none when unset or blank. An entry
27
+ * that is not an http or https origin alone (a path, query, fragment, user or password, or no URL at all) is refused
28
+ * (a TypeError naming the entry by its place, never its text, which could hold a password), and so is a wildcard
29
+ * (`https://*.example.com`), which would otherwise be taken as a literal host and match nothing. Empty entries are
30
+ * skipped. */
31
+ export function apiOnlyMcpOriginsFrom(value) {
32
+ const origins = [];
33
+ (value ?? "").split(",").map((entry) => entry.trim()).forEach((entry, at) => {
34
+ if (entry === "")
35
+ return;
36
+ if (entry.includes("*"))
37
+ throw new TypeError(`${API_ONLY_MCP_ORIGINS_ENV} names each origin whole: entry ${at + 1} is a wildcard, and wildcards are not supported`);
38
+ let url;
39
+ try {
40
+ url = new URL(entry);
41
+ }
42
+ catch {
43
+ url = undefined;
44
+ }
45
+ if (!url || (url.protocol !== "http:" && url.protocol !== "https:") || url.href !== `${url.origin}/`) {
46
+ throw new TypeError(`${API_ONLY_MCP_ORIGINS_ENV} is a comma-separated list of MCP origins (http or https, scheme://host[:port], no path): entry ${at + 1} is not one`);
47
+ }
48
+ if (!origins.includes(url.origin))
49
+ origins.push(url.origin);
50
+ });
51
+ return origins;
52
+ }
package/dist/errors.d.ts CHANGED
@@ -67,6 +67,7 @@ export declare const ERROR_STATUS: {
67
67
  readonly purged: 410;
68
68
  readonly model_key_required: 422;
69
69
  readonly runner_refused: 503;
70
+ readonly api_keys_full: 409;
70
71
  };
71
72
  export type ErrorCode = keyof typeof ERROR_STATUS;
72
73
  /** A field that is missing or wrong. `example`: a value the field accepts, read from the request body's schema (explain.ts). */
package/dist/errors.js CHANGED
@@ -106,6 +106,8 @@ export const ERROR_STATUS = {
106
106
  // (run-child-host.ts runIsolationOf), in the runner's words and their fix. Not retryable: it stays so until the runner
107
107
  // is started again as the words say.
108
108
  runner_refused: 503,
109
+ // POST /settings/api-keys (api-keys.ts) while the server keeps as many API keys as it takes: one is revoked first.
110
+ api_keys_full: 409,
109
111
  };
110
112
  const RETRYABLE = new Set(["home_busy", "idempotency_in_progress", "rate_limited", "internal", "unavailable", "github_failed", "runs_in_flight", "learning_busy", "run_learning"]);
111
113
  export class ApiError extends Error {