@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
@@ -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-okP-y8PK.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
@@ -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,14 @@ 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 operator's list of MCP origins (comma-separated, each scheme://host[:port]) an API-only server's token may save a
15
+ * per_run MCP server at through the generic save. A plain setting, not a secret. Unset or blank, that save is refused
16
+ * as any route outside api-only.ts API_ONLY_ROUTES. AGENTRUN_MCP_ALLOW_LOOPBACK still decides whether a loopback origin is saved. */
17
+ export declare const API_ONLY_MCP_ORIGINS_ENV = "AGENTRUN_API_ONLY_MCP_ORIGINS";
18
+ /** The origins `value` (API_ONLY_MCP_ORIGINS_ENV) names, each once, in its order: none when unset or blank. An entry
19
+ * that is not an http or https origin alone (a path, query, fragment, user or password, or no URL at all) is refused
20
+ * (a TypeError naming the entry by its place, never its text, which could hold a password), and so is a wildcard
21
+ * (`https://*.example.com`), which would otherwise be taken as a literal host and match nothing. Empty entries are
22
+ * skipped. */
23
+ export declare function apiOnlyMcpOriginsFrom(value: string | undefined): string[];
14
24
  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,34 @@ 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 operator's list of MCP origins (comma-separated, each scheme://host[:port]) an API-only server's token may save a
25
+ * per_run MCP server at through the generic save. A plain setting, not a secret. Unset or blank, that save is refused
26
+ * as any route outside api-only.ts API_ONLY_ROUTES. AGENTRUN_MCP_ALLOW_LOOPBACK still decides whether a loopback origin is saved. */
27
+ export const API_ONLY_MCP_ORIGINS_ENV = "AGENTRUN_API_ONLY_MCP_ORIGINS";
28
+ /** The origins `value` (API_ONLY_MCP_ORIGINS_ENV) names, each once, in its order: none when unset or blank. An entry
29
+ * that is not an http or https origin alone (a path, query, fragment, user or password, or no URL at all) is refused
30
+ * (a TypeError naming the entry by its place, never its text, which could hold a password), and so is a wildcard
31
+ * (`https://*.example.com`), which would otherwise be taken as a literal host and match nothing. Empty entries are
32
+ * skipped. */
33
+ export function apiOnlyMcpOriginsFrom(value) {
34
+ const origins = [];
35
+ (value ?? "").split(",").map((entry) => entry.trim()).forEach((entry, at) => {
36
+ if (entry === "")
37
+ return;
38
+ if (entry.includes("*"))
39
+ throw new TypeError(`${API_ONLY_MCP_ORIGINS_ENV} names each origin whole: entry ${at + 1} is a wildcard, and wildcards are not supported`);
40
+ let url;
41
+ try {
42
+ url = new URL(entry);
43
+ }
44
+ catch {
45
+ url = undefined;
46
+ }
47
+ if (!url || (url.protocol !== "http:" && url.protocol !== "https:") || url.href !== `${url.origin}/`) {
48
+ 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`);
49
+ }
50
+ if (!origins.includes(url.origin))
51
+ origins.push(url.origin);
52
+ });
53
+ return origins;
54
+ }
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 {
@@ -5,14 +5,24 @@ import { type SaveSlots } from "./web-save.js";
5
5
  export declare const FAL_MCP_HOST = "mcp.fal.ai";
6
6
  /** A pin's `meter` for a fal server. */
7
7
  export declare const FAL_METER = "fal";
8
+ export type FalMeterName = typeof FAL_METER;
8
9
  /** How long a unit price read from get_pricing is used. */
9
10
  export declare const PRICE_TTL_MS: number;
10
11
  /** One deadline for reading an input media file's length. */
11
12
  export declare const MEDIA_TIMEOUT_MS = 120000;
12
- /** Whether a saved server is fal's: its owner's toolkit for it is `fal`, or its URL is on fal's MCP host. */
13
- export declare function falServer(url: string, toolkit?: string | null): boolean;
14
- /** The `meter` a save pins for a server at `url` with `toolkit` (mcp-gateway.ts mcpPinOf). */
15
- export declare const meterNamed: (url: string, toolkit?: string | null) => string | undefined;
13
+ /** The most of a talking head's voice read to price it: a minute of 48 kHz stereo 32-bit WAV (23 MB) fits, and fal's
14
+ * talking heads take a minute of voice at most (OmniHuman v1.5's OpenAPI). A larger voice is unpriceable. */
15
+ export declare const VOICE_MAX_BYTES: number;
16
+ /** How a talking head's voice is read: https only, under VOICE_MAX_BYTES, and following no redirect, so a fal.media URL
17
+ * can't send the read to a host whose bytes may change (voiceOf). fal.media serves its files with no redirect. */
18
+ export declare const VOICE_READ: {
19
+ readonly maxBytes: number;
20
+ readonly httpsOnly: true;
21
+ readonly maxRedirects: 0;
22
+ };
23
+ /** The one test of a server being fal's: `fal` when `named` (its owner's toolkit for it, or the meter a pin carries) is
24
+ * `fal` or its URL is on fal's MCP host; the `meter` a save pins (mcp-gateway.ts mcpPinOf). */
25
+ export declare const meterNamed: (url: string, named?: string | null) => FalMeterName | undefined;
16
26
  /** One job a call submits: its endpoint and input as the call gives them, and its index in a submit_jobs call. */
17
27
  export type FalJob = {
18
28
  endpoint: string | undefined;
@@ -22,13 +32,36 @@ export type FalJob = {
22
32
  /** The jobs a call of fal's `tool` submits: one for run_model and submit_job, one per request for submit_jobs. Undefined
23
33
  * for a tool that submits none (get_pricing, wait_for_jobs, ...), which fal does not bill. */
24
34
  export declare function falJobsOf(tool: string, args: unknown): FalJob[] | undefined;
35
+ /** Whether fal bills a call of `tool`: one that submits jobs. */
36
+ export declare const falBills: (tool: string) => boolean;
25
37
  /** A job's billed units before it runs: `units` and where the number came from (`from`); `media`, the audio and video
26
- * URLs whose length it is billed by (the longest); or `unknown`, why they can't be known, in words. */
38
+ * URLs whose length it is billed by (the longest); `voice`, a talking head's voice URL, whose length in whole seconds
39
+ * it is billed by (TALKING_HEADS); or `unknown`, why they can't be known, in words. */
27
40
  export type Units = {
28
41
  units: number;
29
42
  from: string;
30
43
  } | {
31
44
  media: string[];
45
+ } | {
46
+ voice: string;
47
+ } | {
48
+ unknown: string;
49
+ };
50
+ /** What is decided here, for the test that pins it against fal's catalog: the families billed by their settings, the
51
+ * endpoints priced by their settings (RATE_TIERS), and those with one rate (ONE_RATE). */
52
+ export declare function decidedRates(): {
53
+ families: string[];
54
+ tiered: string[];
55
+ oneRate: string[];
56
+ };
57
+ /** The rate a job of `endpoint` is billed at, against get_pricing's (in `unit`): `ratio`, its tier's rate over the rate
58
+ * get_pricing states (RATE_TIERS), `perUnitUsd` a charge added to each unit's price, and `words` the settings they came from (none at
59
+ * get_pricing's own rate); or `unknown`, why it can't be known. 1 and nothing for an endpoint with one rate; unknown for
60
+ * an endpoint in a family fal bills by its settings whose rate is not decided here (TIERED_FAMILIES). */
61
+ export declare function rateOf(endpoint: string, unit: string, input: unknown): {
62
+ ratio: number;
63
+ perUnitUsd: number;
64
+ words: string[];
32
65
  } | {
33
66
  unknown: string;
34
67
  };
@@ -42,35 +75,40 @@ export declare function priceIn(answer: unknown, endpoint: string): {
42
75
  unitPrice: number;
43
76
  unit: string;
44
77
  } | undefined;
78
+ /** How a MediaReader reads: under `maxBytes` (lower than its own cap; never higher), with `httpsOnly` refusing http
79
+ * on the first hop and at every redirect, and following at most `maxRedirects` (0 to 5; default 5). */
80
+ export type MediaRead = {
81
+ maxBytes?: number;
82
+ httpsOnly?: boolean;
83
+ maxRedirects?: number;
84
+ };
45
85
  /** The bytes of a job's input media at `url`, read before the job is sent; it throws when they can't be read. */
46
- export type MediaReader = (url: string, signal: AbortSignal) => Promise<Uint8Array>;
86
+ export type MediaReader = (url: string, signal: AbortSignal, read?: MediaRead) => Promise<Uint8Array>;
47
87
  /** A MediaReader over the public-host guard web_fetch and web_save download through (`guard`: their fetch options),
48
88
  * within web_save's size cap and download slots. */
49
- export declare const publicMedia: (guard: () => Promise<Omit<PublicFetchOptions, "maxBytes" | "signal">>, slots?: SaveSlots) => MediaReader;
50
- /** fal's longest submission_key: its tools declare `^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$`. */
51
- export declare const KEY_MAX = 128;
89
+ export declare const publicMedia: (guard: () => Promise<Omit<PublicFetchOptions, "maxBytes" | "signal" | "httpsOnly" | "maxRedirects">>, slots?: SaveSlots) => MediaReader;
90
+ /** The longest submission_key an agent can send fal in a run: fal's KEY_MAX less the run's KEY_TAIL. */
91
+ export declare const KEY_ROOM: number;
52
92
  /** The submission keys of one run on fal's hosted server (McpMeter.keys). fal's journal is per account, so the same key
53
93
  * from two runs (a model makes the same key for the same task) would bind the second run's request to the first's and be
54
94
  * refused. Each key leaves as the agent's key and `.<16 hex of the run>`: the same run's key leaves the same each time,
55
- * so a retry is deduped, and another run's never matches it. A key too long for KEY_MAX with that suffix keeps its start
56
- * and a hash of the whole key in its place, never cut into another key, and ends `:<16 hex of the run>` instead: its
57
- * shortened start is itself a valid key, and the different mark keeps an agent key that spells it from leaving as the
58
- * same key. `back` reads each scoped key in a reply as the agent's: by the keys this gateway sent, else by taking the
95
+ * on every claim of it, so a retry is deduped, and another run's never matches it. A key with no room for that suffix
96
+ * (over KEY_ROOM) is refused unsent, in words. `back` reads each scoped key in a reply as the agent's by taking the
59
97
  * suffix off. */
60
98
  export declare function falKeys(run: string): McpKeys;
61
99
  /** A fal server's meter: fal's unit prices read through the gateway's `ask`, kept per endpoint for PRICE_TTL_MS.
62
- * `media` reads an input media file (none: such a job is unpriceable); `now`, the clock; `run`, the run whose
63
- * submission keys it scopes (falKeys; none: they leave as the agent sent them). */
64
- export declare function falMeter({ media, now, run }?: {
100
+ * `media` reads an input media file (none: such a job is unpriceable); `now`, the clock. */
101
+ export declare function falMeter({ media, now }?: {
65
102
  media?: MediaReader;
66
103
  now?: () => number;
67
- run?: string;
68
104
  }): McpMeter;
69
105
  /** The meter of a pinned server (mcp-gateway.ts McpPin entry): fal's for one marked `fal` at its save, or, for a pin made
70
106
  * before servers were marked, one whose URL is on fal's MCP host. Only a server at fal's host scopes its submission keys
71
- * to `deps.run`: the journal they collide in is that server's, and a server marked `fal` elsewhere (a template eval's
72
- * fake, whose answers and log graders read by the agent's own key) receives them as the agent sent them. */
107
+ * to `run` (falKeys): the journal they collide in is that server's, and a server marked `fal` elsewhere (a template
108
+ * eval's fake, whose answers and log graders read by the agent's own key) receives them as the agent sent them. */
73
109
  export declare const meterFor: (pinned: {
74
110
  url: string;
75
111
  meter?: string;
76
- }, deps?: Parameters<typeof falMeter>[0]) => McpMeter | undefined;
112
+ }, { run, ...deps }?: Parameters<typeof falMeter>[0] & {
113
+ run?: string;
114
+ }) => McpMeter | undefined;