@parcha/agentrun-serve 0.1.0-beta.55 → 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 (296) hide show
  1. package/CHANGELOG.md +261 -0
  2. package/README.md +228 -45
  3. package/dist/acp-package.d.ts +2 -0
  4. package/dist/adapters.d.ts +18 -5
  5. package/dist/adapters.js +23 -9
  6. package/dist/agent-package.d.ts +3 -3
  7. package/dist/agent-package.js +17 -8
  8. package/dist/answer-json.d.ts +6 -2
  9. package/dist/answer-json.js +22 -4
  10. package/dist/api-keys.d.ts +76 -0
  11. package/dist/api-keys.js +217 -0
  12. package/dist/api-only.d.ts +17 -5
  13. package/dist/api-only.js +36 -8
  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/calendar/tools.js +3 -2
  19. package/dist/chatgpt-plan.d.ts +28 -3
  20. package/dist/chatgpt-plan.js +182 -21
  21. package/dist/claude-login.d.ts +101 -14
  22. package/dist/claude-login.js +232 -49
  23. package/dist/claude-sign-in.d.ts +46 -0
  24. package/dist/claude-sign-in.js +93 -0
  25. package/dist/cli.js +63 -6
  26. package/dist/composio-made.d.ts +4 -0
  27. package/dist/composio-made.js +4 -0
  28. package/dist/composio-preset.d.ts +43 -2
  29. package/dist/composio-preset.js +92 -4
  30. package/dist/computer-held-routes.d.ts +5 -4
  31. package/dist/computer-held-routes.js +29 -8
  32. package/dist/computer-held.d.ts +6 -1
  33. package/dist/computer-held.js +14 -0
  34. package/dist/computer-record.js +4 -2
  35. package/dist/computer-viewer.js +4 -1
  36. package/dist/console/assets/{backend-D5EmB4N3.js → backend-DVhHzJX2.js} +19 -19
  37. package/dist/console/assets/index-Bwn1oTem.css +1 -0
  38. package/dist/console/assets/index-okP-y8PK.js +747 -0
  39. package/dist/console/index.html +2 -2
  40. package/dist/decisions.d.ts +1 -1
  41. package/dist/decisions.js +1 -1
  42. package/dist/docker-host-addresses.d.ts +22 -11
  43. package/dist/docker-host-addresses.js +38 -26
  44. package/dist/env-switch.d.ts +10 -0
  45. package/dist/env-switch.js +33 -2
  46. package/dist/errors.d.ts +1 -0
  47. package/dist/errors.js +2 -0
  48. package/dist/fal-price.d.ts +58 -20
  49. package/dist/fal-price.js +341 -82
  50. package/dist/handed-values.d.ts +43 -1
  51. package/dist/handed-values.js +119 -2
  52. package/dist/harness-archive.d.ts +13 -10
  53. package/dist/harness-archive.js +60 -34
  54. package/dist/harness-check.d.ts +3 -1
  55. package/dist/harness-check.js +25 -46
  56. package/dist/harness-keys.d.ts +73 -27
  57. package/dist/harness-keys.js +194 -61
  58. package/dist/harness-recipe-entry.d.ts +8 -7
  59. package/dist/harness-recipe-entry.js +21 -32
  60. package/dist/harness-recipe.d.ts +38 -25
  61. package/dist/harness-recipe.js +49 -36
  62. package/dist/harness-sign-in.js +12 -23
  63. package/dist/harness-table.d.ts +10 -3
  64. package/dist/harness-table.js +26 -21
  65. package/dist/harness.d.ts +1 -0
  66. package/dist/harness.js +17 -5
  67. package/dist/host-check.d.ts +4 -0
  68. package/dist/host-check.js +4 -0
  69. package/dist/hosted-search.d.ts +1 -1
  70. package/dist/hosted-search.js +1 -2
  71. package/dist/import-worker.d.ts +4 -2
  72. package/dist/import-worker.js +9 -2
  73. package/dist/in-flight.d.ts +26 -0
  74. package/dist/in-flight.js +52 -0
  75. package/dist/key-refusal.d.ts +26 -5
  76. package/dist/key-refusal.js +313 -37
  77. package/dist/learn/secrets.d.ts +31 -11
  78. package/dist/learn/secrets.js +152 -191
  79. package/dist/learning-cost.d.ts +6 -3
  80. package/dist/learning-cost.js +4 -2
  81. package/dist/link-check.js +1 -1
  82. package/dist/llms.txt +2 -2
  83. package/dist/marketplace.d.ts +77 -0
  84. package/dist/marketplace.js +224 -0
  85. package/dist/mcp-api-only-origins.d.ts +30 -0
  86. package/dist/mcp-api-only-origins.js +57 -0
  87. package/dist/mcp-gateway.d.ts +7 -5
  88. package/dist/mcp-gateway.js +9 -12
  89. package/dist/mcp-secret-writes.js +5 -3
  90. package/dist/mcp-servers-store.d.ts +28 -6
  91. package/dist/mcp-servers-store.js +53 -4
  92. package/dist/media-duration.d.ts +3 -0
  93. package/dist/media-duration.js +90 -9
  94. package/dist/model-form.d.ts +5 -4
  95. package/dist/model-form.js +11 -7
  96. package/dist/model.d.ts +5 -2
  97. package/dist/model.js +9 -5
  98. package/dist/ollama-provider.d.ts +7 -1
  99. package/dist/ollama-provider.js +14 -2
  100. package/dist/openapi.d.ts +3 -3
  101. package/dist/openapi.js +245 -42
  102. package/dist/otel/genai.d.ts +65 -0
  103. package/dist/otel/genai.js +116 -0
  104. package/dist/otel/tracer.d.ts +55 -0
  105. package/dist/otel/tracer.js +308 -0
  106. package/dist/page.d.ts +2 -0
  107. package/dist/page.js +3 -1
  108. package/dist/paid-calls.d.ts +1 -32
  109. package/dist/paid-calls.js +4 -39
  110. package/dist/place-offers.d.ts +14 -6
  111. package/dist/place-offers.js +26 -13
  112. package/dist/provider.d.ts +9 -0
  113. package/dist/provider.js +50 -3
  114. package/dist/redact/match.d.ts +101 -0
  115. package/dist/redact/match.js +1152 -0
  116. package/dist/refusal-words.d.ts +11 -0
  117. package/dist/refusal-words.js +11 -0
  118. package/dist/run-census.d.ts +67 -0
  119. package/dist/run-census.js +240 -0
  120. package/dist/run-computer.d.ts +6 -3
  121. package/dist/run-computer.js +4 -1
  122. package/dist/run-cut.d.ts +15 -6
  123. package/dist/run-cut.js +30 -9
  124. package/dist/run-files.d.ts +3 -0
  125. package/dist/run-files.js +3 -0
  126. package/dist/run-launch.d.ts +12 -1
  127. package/dist/run-launch.js +9 -10
  128. package/dist/run-learning-served.d.ts +2 -0
  129. package/dist/run-model-key.d.ts +8 -0
  130. package/dist/run-model-key.js +31 -1
  131. package/dist/run-reads-over-store.d.ts +24 -6
  132. package/dist/run-reads-over-store.js +67 -23
  133. package/dist/run-recordings.d.ts +5 -1
  134. package/dist/run-recordings.js +39 -14
  135. package/dist/run-timeline-served.d.ts +3 -1
  136. package/dist/run-timeline-served.js +4 -4
  137. package/dist/run-usage.d.ts +1 -0
  138. package/dist/runnable.d.ts +10 -1
  139. package/dist/runnable.js +20 -8
  140. package/dist/runner/adapter-loop.d.ts +14 -0
  141. package/dist/runner/adapter-loop.js +56 -11
  142. package/dist/runner/adapter-run-spec.d.ts +45 -8
  143. package/dist/runner/adapter-run-spec.js +154 -29
  144. package/dist/runner/adapters/pi.js +25 -3
  145. package/dist/runner/beside.js +11 -6
  146. package/dist/runner/big-writes.js +1 -10
  147. package/dist/runner/claim-secrets.d.ts +18 -3
  148. package/dist/runner/claim-secrets.js +35 -6
  149. package/dist/runner/cli-run-spec.d.ts +6 -0
  150. package/dist/runner/cli-run-spec.js +85 -36
  151. package/dist/runner/computer-journal.d.ts +9 -1
  152. package/dist/runner/computer-journal.js +26 -0
  153. package/dist/runner/conformance/harness.js +1 -1
  154. package/dist/runner/feedback-round.js +3 -0
  155. package/dist/runner/harness-loops.d.ts +6 -5
  156. package/dist/runner/harness-loops.js +7 -7
  157. package/dist/runner/held.d.ts +11 -5
  158. package/dist/runner/journal-kinds.d.ts +5 -0
  159. package/dist/runner/journal-kinds.js +5 -0
  160. package/dist/runner/loop-contract.d.ts +4 -0
  161. package/dist/runner/main.js +15 -6
  162. package/dist/runner/mcp-claim.js +30 -3
  163. package/dist/runner/mcp-run.d.ts +12 -0
  164. package/dist/runner/mcp-run.js +12 -5
  165. package/dist/runner/model-route.d.ts +17 -0
  166. package/dist/runner/model-route.js +120 -2
  167. package/dist/runner/presence.d.ts +4 -3
  168. package/dist/runner/presence.js +4 -2
  169. package/dist/runner/run-child-host.d.ts +5 -0
  170. package/dist/runner/run-child-host.js +71 -30
  171. package/dist/runner/run-child.js +5 -2
  172. package/dist/runner/runner.d.ts +18 -3
  173. package/dist/runner/runner.js +162 -36
  174. package/dist/runner/store-port.d.ts +1 -1
  175. package/dist/runner/store-secrets.d.ts +6 -0
  176. package/dist/runner/store-secrets.js +49 -7
  177. package/dist/runner/subagent.js +4 -40
  178. package/dist/runner/workflow-first.d.ts +11 -4
  179. package/dist/runner/workflow-first.js +14 -8
  180. package/dist/runner/workflow-spec.js +3 -2
  181. package/dist/runs-over-store.d.ts +15 -6
  182. package/dist/runs-over-store.js +33 -21
  183. package/dist/scrub-command.d.ts +73 -0
  184. package/dist/scrub-command.js +307 -0
  185. package/dist/secret-cut.d.ts +73 -0
  186. package/dist/secret-cut.js +291 -4
  187. package/dist/secret-rules.d.ts +143 -0
  188. package/dist/secret-rules.js +2564 -0
  189. package/dist/secrets.d.ts +7 -0
  190. package/dist/secrets.js +20 -0
  191. package/dist/server-keys.d.ts +20 -0
  192. package/dist/server-keys.js +25 -6
  193. package/dist/server.d.ts +57 -13
  194. package/dist/server.js +371 -113
  195. package/dist/skills/agentrun-serve/SKILL.md +4 -0
  196. package/dist/store/dialect.d.ts +3 -0
  197. package/dist/store/dialect.js +1 -0
  198. package/dist/store/index.d.ts +1 -1
  199. package/dist/store/index.js +1 -1
  200. package/dist/store/journal/storage.js +1 -1
  201. package/dist/store/postgres/dialect.js +3 -0
  202. package/dist/store/postgres/migrations/0027_run_launch_census.sql +31 -0
  203. package/dist/store/schema.d.ts +6 -0
  204. package/dist/store/schema.js +11 -1
  205. package/dist/store/seal.d.ts +6 -1
  206. package/dist/store/seal.js +5 -3
  207. package/dist/store/sqlite/run-launch.d.ts +9 -1
  208. package/dist/store/sqlite/run-launch.js +24 -13
  209. package/dist/store/sqlite/run-patch.d.ts +1 -1
  210. package/dist/store/sqlite/run-patch.js +13 -4
  211. package/dist/store/sqlite/store.js +76 -16
  212. package/dist/store/store.d.ts +53 -3
  213. package/dist/store/store.js +27 -0
  214. package/dist/store-reads/learning.d.ts +6 -3
  215. package/dist/store-reads/learning.js +22 -7
  216. package/dist/store-view.d.ts +3 -0
  217. package/dist/store-view.js +4 -4
  218. package/dist/suggestions.js +3 -2
  219. package/dist/template-eval.d.ts +22 -11
  220. package/dist/template-eval.js +124 -41
  221. package/dist/template-import.d.ts +10 -0
  222. package/dist/template-import.js +16 -7
  223. package/dist/templates.d.ts +10 -2
  224. package/dist/templates.js +28 -8
  225. package/dist/timeline/index.d.ts +1 -1
  226. package/dist/timeline/index.js +1 -1
  227. package/dist/timeline/labels.d.ts +6 -4
  228. package/dist/timeline/labels.js +18 -6
  229. package/dist/timeline/timeline.d.ts +17 -7
  230. package/dist/timeline/timeline.js +28 -14
  231. package/dist/timeline/util.js +1 -1
  232. package/dist/timeline/web-calls.d.ts +26 -9
  233. package/dist/timeline/web-calls.js +124 -37
  234. package/dist/tool-gate.d.ts +42 -3
  235. package/dist/tool-gate.js +69 -6
  236. package/dist/tool-keys-store.d.ts +2 -4
  237. package/dist/tool-keys-store.js +5 -21
  238. package/dist/tool-keys.d.ts +2 -2
  239. package/dist/tool-keys.js +2 -2
  240. package/dist/tool-list.js +1 -1
  241. package/dist/tool-plane.d.ts +2 -2
  242. package/dist/tool-plane.js +35 -33
  243. package/dist/tools.js +13 -7
  244. package/dist/trigger-targets.d.ts +4 -0
  245. package/dist/trigger-targets.js +9 -2
  246. package/dist/triggers.d.ts +67 -4
  247. package/dist/triggers.js +171 -22
  248. package/dist/until.d.ts +3 -0
  249. package/dist/until.js +11 -0
  250. package/dist/validate.js +1 -1
  251. package/dist/web-fake.d.ts +1 -3
  252. package/dist/web-fake.js +7 -18
  253. package/dist/web-fetch.d.ts +6 -72
  254. package/dist/web-fetch.js +11 -265
  255. package/dist/web-run.d.ts +31 -0
  256. package/dist/web-run.js +90 -0
  257. package/dist/web-save.d.ts +6 -4
  258. package/dist/web-save.js +9 -12
  259. package/dist/web-search.d.ts +9 -127
  260. package/dist/web-search.js +23 -259
  261. package/dist/wires.d.ts +13 -0
  262. package/dist/wires.js +11 -0
  263. package/dist/workflow-run.d.ts +5 -4
  264. package/dist/workflow-run.js +5 -4
  265. package/dist/workspace/computer-deps.d.ts +3 -1
  266. package/dist/workspace/computer-deps.js +12 -4
  267. package/dist/workspace/computer-for-claim.d.ts +19 -2
  268. package/dist/workspace/computer-for-claim.js +101 -13
  269. package/dist/workspace/computer-janitor.d.ts +15 -7
  270. package/dist/workspace/computer-janitor.js +33 -8
  271. package/dist/workspace/computer-kept.d.ts +55 -4
  272. package/dist/workspace/computer-kept.js +129 -8
  273. package/dist/workspace/index.d.ts +1 -1
  274. package/dist/workspace/index.js +1 -1
  275. package/dist/workspace/kind-skills.d.ts +4 -0
  276. package/dist/workspace/kind-skills.js +9 -0
  277. package/dist/workspace/run-end-computers.d.ts +5 -1
  278. package/dist/workspace/run-end-computers.js +27 -1
  279. package/dist/workspace/synced-folder.js +3 -4
  280. package/dist/wrapped.d.ts +65 -0
  281. package/dist/wrapped.js +77 -0
  282. package/package.json +17 -11
  283. package/skills/agentrun-serve/SKILL.md +4 -0
  284. package/templates/README.md +38 -15
  285. package/dist/console/assets/index-DUYLaqiR.js +0 -746
  286. package/dist/console/assets/index-DYhU4adm.css +0 -1
  287. package/dist/exa-keyless.d.ts +0 -34
  288. package/dist/exa-keyless.js +0 -118
  289. package/dist/firecrawl-keyless.d.ts +0 -41
  290. package/dist/firecrawl-keyless.js +0 -152
  291. package/dist/keyless-mcp.d.ts +0 -36
  292. package/dist/keyless-mcp.js +0 -127
  293. package/dist/text-urls.d.ts +0 -38
  294. package/dist/text-urls.js +0 -170
  295. package/dist/web-fetch-direct.d.ts +0 -119
  296. package/dist/web-fetch-direct.js +0 -190
@@ -43,10 +43,12 @@ export interface HeldMcpAsk {
43
43
  /** The run's journal commit, for a call's record on the run's root (mcp-gateway.ts commit): an entry appended. */
44
44
  readonly appendRoot: (entry: unknown) => Promise<void>;
45
45
  }
46
- /** What the run's process gives the runner's computerForClaim (workspace/computer-for-claim.ts): its callbacks only. The
47
- * run, its epoch, its folder, its mode and its revision are the runner's own reads of the claim. */
46
+ /** What the run's process gives the runner's computerForClaim (workspace/computer-for-claim.ts): its callbacks, and the
47
+ * kind its journal says an earlier claim's deny turned off (ComputerForClaimDeps.turnedOff), read there as hadComputer
48
+ * is. The run, its epoch, its folder, its mode and its revision are the runner's own reads of the claim. */
48
49
  export interface HeldComputerAsk {
49
50
  readonly hadComputer: () => Promise<boolean>;
51
+ readonly turnedOff?: string;
50
52
  readonly signal?: AbortSignal;
51
53
  readonly say?: (words: string) => void;
52
54
  readonly onImageWait?: (making: boolean, image: string) => void;
@@ -72,7 +74,9 @@ export interface Held {
72
74
  * out and its launch's payload names the pull request. Its mint makes a token of that repository alone, contents
73
75
  * read, whatever the process names; its MCP mints on the runner (mcp). */
74
76
  githubAppAccess(): Promise<GithubAppAccessAt | undefined>;
75
- /** Every saved model key, for a run whose routes have no revision to scope them by (a subagent's tiers, a grade). */
77
+ /** Every saved model key, for a run whose routes have no revision to scope them by (a subagent's tiers, a learning run's
78
+ * grade, an SDK run's); a replay's or an audit's grader gets its fast model's provider's key alone, none when its revision
79
+ * names agree_on or has no fast model. */
76
80
  savedModelKeys(): Promise<Record<string, string>>;
77
81
  /** The model keys the host's models of `tiers` need (claim-secrets.ts tierModelKeys), the plan's reader with them: of
78
82
  * the tiers the claim's learned workflows name, as the runner chose them (learnedFirst), alone. */
@@ -90,8 +94,10 @@ export interface Held {
90
94
  * claim's own launch, else the server's. A zone's name, never the trigger's row. */
91
95
  runZone(): Promise<string>;
92
96
  /** The keys saved for the claim's own harness alone (harness-keys.ts openHarnessKeys), by name, opened by the runner:
93
- * none unless that harness is a plan-billed recipe. The process lays them on its adapter's environment alone. */
94
- harnessKeys(): Promise<Record<string, string>>;
97
+ * none unless that harness is a plan-billed recipe, and none unless they are bound to `digest`, the sha256 of the
98
+ * recipe file the process loaded itself (a file swapped since the runner read its table never takes the first's).
99
+ * The process lays them on its adapter's environment alone. */
100
+ harnessKeys(digest: string): Promise<Record<string, string>>;
95
101
  /** The host's keys of the decision providers `providers` (claim-secrets.ts hostDecisionKeys): of the providers the
96
102
  * claim's learned workflows' questions name, as the runner chose them (learnedFirst), alone. */
97
103
  decisionKeys(providers: readonly string[]): Promise<Record<string, string>>;
@@ -89,6 +89,11 @@ export declare const KINDS: {
89
89
  * entry is how that claim knows the run had one when nothing of the earlier claim's is left to let go (a server's
90
90
  * stop, a park): computer-journal.ts hadComputer. Neither a call nor a message, and never on the Timeline. */
91
91
  readonly computerMade: "agentrun.computer.made";
92
+ /** The run's computer is off for the rest of the run (`computer`: its kind): written on the root by the claim's gate at
93
+ * the first deny of a call of that computer's own tools (tool-gate.ts RunGate.computerOff), whose refusal said so. A
94
+ * later claim of the run starts no computer and refuses each call of its tools short: computer-journal.ts
95
+ * computerTurnedOff. Neither a call nor a message, and never on the Timeline. */
96
+ readonly computerOff: "agentrun.computer.off";
92
97
  /** A grade's feedback round (runner/feedback-round.ts): the run opened again on a grade's words, asked no turn of the
93
98
  * job's; its next end's end-of-run turn reads them (`text`, the `round`, whether the grade said right, the workflow a
94
99
  * revision is asked of). Written on the root by the commit that takes the round's steer row. Neither a call nor a
@@ -89,6 +89,11 @@ export const KINDS = {
89
89
  * entry is how that claim knows the run had one when nothing of the earlier claim's is left to let go (a server's
90
90
  * stop, a park): computer-journal.ts hadComputer. Neither a call nor a message, and never on the Timeline. */
91
91
  computerMade: "agentrun.computer.made",
92
+ /** The run's computer is off for the rest of the run (`computer`: its kind): written on the root by the claim's gate at
93
+ * the first deny of a call of that computer's own tools (tool-gate.ts RunGate.computerOff), whose refusal said so. A
94
+ * later claim of the run starts no computer and refuses each call of its tools short: computer-journal.ts
95
+ * computerTurnedOff. Neither a call nor a message, and never on the Timeline. */
96
+ computerOff: "agentrun.computer.off",
92
97
  /** A grade's feedback round (runner/feedback-round.ts): the run opened again on a grade's words, asked no turn of the
93
98
  * job's; its next end's end-of-run turn reads them (`text`, the `round`, whether the grade said right, the workflow a
94
99
  * revision is asked of). Written on the root by the commit that takes the round's steer row. Neither a call nor a
@@ -191,6 +191,10 @@ export interface LoopDeps {
191
191
  * end goes through it, so no secret the runner holds is stored, its values cut the run's live view (live-ticker.ts),
192
192
  * and a claim carries the run's own tool keys into it (claim-secrets.ts). */
193
193
  redact: HeldRedact;
194
+ /** The incarnation of the runner's word in the store (runner/presence.ts), the claim's runner being the claim's own
195
+ * `runner`: a park that keeps a computer only this runner can reach again pins it to both (workspace/computer-kept.ts
196
+ * pinnedOf), so the claim rule gives the run back to this runner while it is there. Absent: nothing is pinned. */
197
+ incarnation?: string;
194
198
  }
195
199
  /** A run's held state: what pi shows before it stores it. The live view (live/stream.ts) streams it beside the stored
196
200
  * commits' events, in the door's vocabulary (a running tool's tool_execution_start, a partial's message_update). */
@@ -56,6 +56,7 @@ import { routeOf } from "./model-route.js";
56
56
  import { RUN_PROCESS_MIB, runnerMemory } from "./memory-claim.js";
57
57
  import { childLoops, isolationLoops, RunIsolationRefused, runIsolationOf } from "./run-child-host.js";
58
58
  import { sweepEndedScratch } from "./scratch-sweep.js";
59
+ import { runCensus } from "../run-census.js";
59
60
  import { RUNNER_LOOPS, RUNNER_RENEW_EVERY_MS, runnerName, startRunner } from "./runner.js";
60
61
  import { keepPresence } from "./presence.js";
61
62
  import { diskFreeGate } from "./disk-free.js";
@@ -96,8 +97,10 @@ export async function openRunnerStore(dataDir, env, warn, url) {
96
97
  /** The runner's own secrets, which a run never gets, not even in the runner's in-process environment: the server's
97
98
  * tokens (the token and the token list) and API key, the seal key (the runner holds it as its sealKey), the store's connection (its URL holds a
98
99
  * database password), the launch hook's signing secret (the server's alone), and the Composio account key, which the
99
- * runner's claim alone reads (composio-made.ts composioEnvKey) and sends only as a granted Composio server's MCP header. */
100
- const RUNNER_ONLY = (name) => name === "AGENTRUN_TOKEN" || name === "AGENTRUN_TOKENS" || name === "AGENTRUN_API_KEY" || name === SEAL_KEY_ENV || name === LAUNCH_HOOK_SECRET_ENV || name === COMPOSIO_KEY_ENV || name.startsWith("AGENTRUN_STORE_");
100
+ * runner's claim alone reads (composio-made.ts composioEnvKey) and sends only as a granted Composio server's MCP header.
101
+ * And every OpenTelemetry setting (OTEL_*: OTEL_EXPORTER_OTLP_HEADERS holds a backend's key): a run's process is handed
102
+ * them on its pipe (secrets.ts OTEL_PAIR), never in an environment, so no harness, tool or computer of a run has them. */
103
+ const RUNNER_ONLY = (name) => name === "AGENTRUN_TOKEN" || name === "AGENTRUN_TOKENS" || name === "AGENTRUN_API_KEY" || name === SEAL_KEY_ENV || name === LAUNCH_HOOK_SECRET_ENV || name === COMPOSIO_KEY_ENV || name.startsWith("AGENTRUN_STORE_") || name.startsWith("OTEL_");
101
104
  /** A run's environment as the runner hands its loops (AdapterSpecDeps.env): this process's, less the runner's own
102
105
  * secrets, with every other secret the launcher's pipe handed it (a model key, a tool key, a box key) readable by name
103
106
  * but not enumerable, as secrets.ts withSecrets makes them: code that reads one by name (the model route) finds it, and
@@ -257,7 +260,8 @@ export async function startRunnerProcess(options) {
257
260
  // tokens and proofs name the same one, so the server's "restarted since" and the runner's row speak of one process.
258
261
  // The presence first, then the relay says where it answers on the presence's row.
259
262
  // Its row says this build's version and the most runs it holds (its loops), for the server's capacity read.
260
- presence = keepPresence(store.runners, name, null, { warn, incarnation: randomUUID(), slots: options.loops ?? RUNNER_LOOPS });
263
+ const incarnation = randomUUID();
264
+ presence = keepPresence(store.runners, name, null, { warn, incarnation, slots: options.loops ?? RUNNER_LOOPS });
261
265
  // Its relay (dial-relay.ts), where its environment names the server's public address: a machine that dials the
262
266
  // server lands in this runner's hub, through the server. Its log lines are the runner's warnings.
263
267
  relay = await startRunnerRelay({ store, sealKey: seal.key, runner: name, presence, env, log: warn });
@@ -267,17 +271,22 @@ export async function startRunnerProcess(options) {
267
271
  const createLoop = typeof parts === "function" ? parts : parts.createLoop;
268
272
  // The janitor sweeps with the computers the loop composed, never a second composition. Its lines are the runner's
269
273
  // warnings, said where the runner says its others (warn: stderr unless a test gives its own).
274
+ // It sweeps as this runner (its name and its presence's incarnation): a computer kept at a park pinned to another
275
+ // runner still there is that runner's to end (computer-kept.ts sweepKept).
270
276
  if (options.janitor && typeof parts !== "function")
271
- janitor = startJanitor({ store, computers: parts.computers, env: parts.env, log: warn });
277
+ janitor = startJanitor({ store, computers: parts.computers, env: parts.env, log: warn, self: { runner: name, incarnation } });
272
278
  // Before it claims: the scratch folders of runs that ended after their runner died (scratch-sweep.ts), said as warnings.
273
279
  await sweepEndedScratch(store, options.dataDir, { log: warn });
274
- // A run's end lets go of what its earlier claims' computers left, with the same computers (run-end-computers.ts).
275
- const runEnded = projectRunEnded(store, typeof parts !== "function" ? runEndComputers({ store, computers: parts.computers, log: warn }) : undefined);
280
+ // A run's end lets go of what its earlier claims' computers left, with the same computers (run-end-computers.ts), as
281
+ // this runner, as the janitor sweeps: a computer kept pinned to another runner still keeping it is that runner's.
282
+ const runEnded = projectRunEnded(store, typeof parts !== "function" ? runEndComputers({ store, computers: parts.computers, log: warn, self: () => ({ runner: name, incarnation }) }) : undefined);
276
283
  runner = startRunner({
277
284
  store,
278
285
  createLoop,
279
286
  name,
280
287
  presence,
288
+ // Each end counts where in the run's files what its caller handed it sits, as the server reads them.
289
+ census: runCensus(store, { data: options.dataDir, sealKey: seal.key, env }),
281
290
  ...(options.loops ? { loops: options.loops } : {}),
282
291
  ...(options.drainMs ? { drainMs: options.drainMs } : {}),
283
292
  memory,
@@ -31,6 +31,8 @@
31
31
  // as the runner was handed it at its start (secrets.ts secret, never its environment), for an address on Composio's origin
32
32
  // alone (composioEnvKey), and only for a server the run is granted: the run's process never holds it. Unset, or a row at
33
33
  // another address, the claim is refused before the loop starts (pinOf), in words naming it, and nothing is sent.
34
+ // A per_run server the API token saved at an origin off the API-only list (mcp-api-only-origins.ts) is refused at the
35
+ // claim (pinOf) and at each call after it (check): its entry holds only those words, so nothing goes to that origin.
34
36
  //
35
37
  // fresh(). After the pin check and before the loop, and again on a command-row resume: an OAuth access token past its
36
38
  // expiry is refreshed, bounded (the call within MCP_REFRESH_CALL_MS; a request not yet dialled within 4 s, and tried again
@@ -53,6 +55,7 @@
53
55
  // the next call sends the new one (or is refused for the move); and an OAuth access token within REFRESH_MARGIN_MS of its
54
56
  // end is refreshed through open's lease path: behind the call while the token is still valid (the call goes at once on
55
57
  // it), waited on only when it has run out. Concurrent calls to one server share one such open.
58
+ import { heldApiOnlyMcpOrigins, offApiOnlyMcpOrigins } from "../mcp-api-only-origins.js";
56
59
  import { randomUUID } from "node:crypto";
57
60
  import { EndpointRefused, REFRESH_REQUEST_MS, refreshed, refused, RequestUnsent, systemNetwork } from "../mcp-oauth.js";
58
61
  import { pinFirst } from "../mcp-pin-first.js";
@@ -103,6 +106,9 @@ export async function mcpClaim(options) {
103
106
  const stamps = new Map();
104
107
  /** The servers check() found removed: nothing (a github_app token's refresh among it) puts their entry back. */
105
108
  const gone = new Set();
109
+ /** The per_run servers the API-only origin list refused when last opened (offApiOnlyMcpOrigins): check() opens one
110
+ * again when the list says otherwise now. */
111
+ const offList = new Set();
106
112
  /** The opens check() started, by server: concurrent calls share one. */
107
113
  const reopening = new Map();
108
114
  // Servers whose refresh behind a still-valid token is going: one at a time per server from this claim.
@@ -218,8 +224,15 @@ export async function mcpClaim(options) {
218
224
  return await github.open(name, entry), { awaited: true };
219
225
  // A per_run server keeps none either: its credential is the one the run's caller handed it (mcp_auth), sealed in the
220
226
  // run's launch, read again at every fresh() so a message's new one reaches the run's next request.
221
- if (row.auth === "per_run")
222
- return entry(await perRun(name, row.url)), { awaited: false };
227
+ // One the API token saved at an origin no longer on the API-only list gets no entry but those words.
228
+ if (row.auth === "per_run") {
229
+ const off = await offApiOnlyMcpOrigins(store, name, row);
230
+ if (off)
231
+ offList.add(name);
232
+ else
233
+ offList.delete(name);
234
+ return entry(off ? { unopened: off } : await perRun(name, row.url)), { awaited: false };
235
+ }
223
236
  // A per-run Composio server: the run's account, or its calls refused unsent; its key is opened below as any server's.
224
237
  const account = row.auth === "headers" ? await composioAccount(name, row) : undefined;
225
238
  if (account && "unopened" in account)
@@ -425,8 +438,18 @@ export async function mcpClaim(options) {
425
438
  delete credentials[name];
426
439
  return;
427
440
  }
441
+ // A per_run server: the API-only origin list read at every call, not only at the claim, since a runner of its own
442
+ // holds its runs past a server's restart with the list changed. Refused or let in since its last open: opened again.
443
+ // The list is read first: with none held (a full server's store) the row is not read, and nothing is refused.
444
+ let listMoved = false;
445
+ if (stamp.auth === "per_run") {
446
+ const row = (await heldApiOnlyMcpOrigins(store)) ? await getMcpServer(store, name) : undefined;
447
+ listMoved = (row !== undefined && (await offApiOnlyMcpOrigins(store, name, row)) !== undefined) !== offList.has(name);
448
+ if (released)
449
+ return;
450
+ }
428
451
  const was = stamps.get(name);
429
- const changed = !was || gone.has(name) || was.url !== stamp.url || was.auth !== stamp.auth || was.changedAt !== stamp.credentialChangedAt;
452
+ const changed = !was || gone.has(name) || listMoved || was.url !== stamp.url || was.auth !== stamp.auth || was.changedAt !== stamp.credentialChangedAt;
430
453
  // The token's end by the store's clock (tokenLeftMs), else as this claim opened it.
431
454
  const left = stamp.tokenLeftMs ?? (was?.end !== undefined ? was.end - now() : null);
432
455
  // And whether the row still holds the token this claim opened: another claim's refresh moves the row's token end (not
@@ -526,6 +549,10 @@ async function pinOf({ store, claim, grants, githubMcpOrigin = GITHUB_MCP_ORIGIN
526
549
  const got = row && keyEnv ? composioEnvKey(server, row.url, keyEnv, composioMcpOrigin) : undefined;
527
550
  if (got && "refused" in got)
528
551
  throw new McpClaimRefused(`${got.refused} Nothing was sent.`);
552
+ // A per_run server the API token saved at an origin no longer on the API-only list: the run never starts, nothing sent.
553
+ const off = row ? await offApiOnlyMcpOrigins(store, server, row) : undefined;
554
+ if (off)
555
+ throw new McpClaimRefused(off);
529
556
  }
530
557
  // As plain JSON, as the stored pin reads (the harnesses and the run's directory take it as such).
531
558
  return JSON.parse(JSON.stringify(pinned));
@@ -74,6 +74,18 @@ export interface McpForClaimOptions {
74
74
  /** Each credential value the claim opens, refreshes or mints, for the run's redactors (mcp-claim.ts `hold`). */
75
75
  readonly hold?: (values: string[]) => void;
76
76
  }
77
+ /** What a spec builder gives a claim's MCP for its metered jobs (`capped` and `media`), the same for every builder:
78
+ * whether its launch has a cap, and where a job's input media are read from: the agent's eval web fake, else the
79
+ * builder's `env`, in web_save's slots. */
80
+ export declare function claimMetering(deps: {
81
+ readonly env: NodeJS.ProcessEnv;
82
+ readonly evalFakes?: (agentId: string) => {
83
+ readonly web?: WebFake;
84
+ } | undefined;
85
+ readonly saveSlots?: SaveSlots;
86
+ }, agentId: string, launch: {
87
+ readonly maxCostUsd?: number | undefined;
88
+ }): Pick<McpForClaimOptions, "capped" | "media">;
77
89
  /** A claim's MCP (AdapterRunSpec.mcp): what the loop reaches the gateway by, and the claim step's own hooks. */
78
90
  export interface ClaimMcp {
79
91
  /** One host tool per pinned tool, under its wire name, on every harness. Each reaches the gateway only as the loop
@@ -1,9 +1,9 @@
1
1
  import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
2
2
  import { wireName } from "../catalog.js";
3
3
  import { mcpGateway } from "../mcp-gateway.js";
4
- import { meterFor, publicMedia } from "../fal-price.js";
4
+ import { falBills, meterNamed, publicMedia } from "../fal-price.js";
5
5
  import { FAUX_ENV } from "../model.js";
6
- import { fetchOptions } from "../web-fetch-direct.js";
6
+ import { fetchOptions } from "../web-run.js";
7
7
  import { fakeSaveOptions } from "../web-fake.js";
8
8
  import { dialAt, mcpServerAt, systemNetwork } from "../mcp-oauth.js";
9
9
  import { privateOAuthHosts } from "../mcp-private-hosts.js";
@@ -13,6 +13,13 @@ import { mcpClaim } from "./mcp-claim.js";
13
13
  import { registryListing } from "../mcp-pin-first.js";
14
14
  import { heldOrThrow } from "./held.js";
15
15
  import { ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
16
+ /** What a spec builder gives a claim's MCP for its metered jobs (`capped` and `media`), the same for every builder:
17
+ * whether its launch has a cap, and where a job's input media are read from: the agent's eval web fake, else the
18
+ * builder's `env`, in web_save's slots. */
19
+ export function claimMetering(deps, agentId, launch) {
20
+ const web = deps.evalFakes?.(agentId)?.web;
21
+ return { capped: launch.maxCostUsd !== undefined, media: { env: deps.env, ...(web ? { web } : {}), ...(deps.saveSlots ? { slots: deps.saveSlots } : {}) } };
22
+ }
16
23
  /** The wire names a subagent's `grant` gives of the run's MCP and monid tools, by the gate's keys; else the grant's own. */
17
24
  export function catalogSessionNames(catalog, grant) {
18
25
  const given = (catalog?.tools ?? []).flatMap((tool) => (permissionKeys(catalog.catalogOf(tool.name) ?? "").includes(grant) ? [tool.name] : []));
@@ -80,7 +87,7 @@ export async function mcpForClaim(options) {
80
87
  commit: () => (change) => options.harness.commit(change, BACKGROUND_CONTEXT),
81
88
  ...(options.fetch ? { fetch: options.fetch } : {}),
82
89
  ...(options.callBounds ? { bounds: options.callBounds } : {}),
83
- capped: () => options.capped !== false,
90
+ capped: options.capped !== false,
84
91
  ...(media ? { media: publicMedia(async () => (media.web ? fakeSaveOptions(media.web) : fetchOptions(media.env, FAUX_ENV)), media.slots) } : {}),
85
92
  });
86
93
  const catalog = new Map();
@@ -118,8 +125,8 @@ export async function mcpForClaim(options) {
118
125
  return undefined;
119
126
  if (pinned.prices && Object.hasOwn(pinned.prices, parsed.tool))
120
127
  return pinned.prices[parsed.tool];
121
- // A metered server's job is priced from its input, when the call runs: no price to show before it.
122
- return meterFor(pinned)?.bills(parsed.tool) ? undefined : "not metered";
128
+ // fal's job is priced from its input when the call runs, after the person's allow.
129
+ return meterNamed(pinned.url, pinned.meter) && falBills(parsed.tool) ? "priced by usage" : "not metered";
123
130
  },
124
131
  effectOf: (name) => pinnedEffect(pin, name),
125
132
  fresh: () => step.fresh(),
@@ -66,6 +66,11 @@ export interface ModelRoute {
66
66
  readonly price?: (model: string, usage: RouteUsage) => number | null;
67
67
  /** The upstream fetch: the route's own, for a model that does not speak Messages. Absent: the network. */
68
68
  readonly fetch?: typeof fetch;
69
+ /** Where the route's own translation (`fetch`) sends the model's requests: the origin pi-ai's catalog entry gives it
70
+ * (OpenRouter's, Particle's, this machine's Ollama). A run's GenAI trace names its host, never `provider.origin`
71
+ * (ROUTE_ORIGIN, a name no request leaves for). Absent on a route with no translation, and under the faux model,
72
+ * whose requests go nowhere. */
73
+ readonly upstreamOrigin?: string;
69
74
  /** The catalog's cost of the model, tiers included: what the cap prices a request at before it leaves. */
70
75
  readonly cost?: RouteCost;
71
76
  /** True when serve has no price for the model (runModels' `unpriced`): `cost` is then a placeholder of zeros, which the
@@ -140,6 +145,18 @@ export declare function routeOf(model: string | PinnedModel | undefined, env?: N
140
145
  * sends to OpenRouter carries AgentRun's app attribution unless `env` turns it off (kernel openrouter-attribution.ts),
141
146
  * as one the model proxy sends there does; a request to any other provider carries none. */
142
147
  export declare function messagesFetch(models: PiModels, target: PiModel, redact?: Redact, upstream?: typeof fetch, env?: NodeJS.ProcessEnv): typeof fetch;
148
+ /** `route` (a translated route's fetch, which streams every answer, as pi-ai asks) for any Messages client on the wire it
149
+ * translates onto, which asks two things pi-ai never does. Its token count (POST /v1/messages/count_tokens, free, asked
150
+ * beside its turns) is answered here and never run on the model, which has no count of its own: the body's bytes over
151
+ * four (COUNT_BYTES_PER_TOKEN), a bound for its context, not a price. A request with no `stream: true` (a side request)
152
+ * gets its answer whole, one JSON message as Messages writes it, joined from the stream (wholeOf). A tool_choice that
153
+ * forces a call is refused with a 400 before the model is asked (forcedChoice). */
154
+ export declare function forMessagesClients(route: typeof fetch): typeof fetch;
155
+ /** The route's translation onto each wire it translates a model onto (wires.ts TRANSLATED), by wire: what a harness's
156
+ * proxy on that wire forwards with for `model` (`provider/model-id`), made on `env`. Anthropic's Messages: the route's
157
+ * own Messages fetch (messagesFetch), as a Messages client asks it (forMessagesClients). provider.ts routedProvider reads
158
+ * it; a wire with no entry has no translation, whatever TRANSLATED says. */
159
+ export declare const TRANSLATORS: Readonly<Partial<Record<Wire, (model: string, env: NodeJS.ProcessEnv) => Promise<typeof fetch>>>>;
143
160
  /** A text-tools re-ask's output limit: the most tokens it may answer with when what is left of the request's hold is
144
161
  * `leftUsd` (its first try's input as it was billed and its output limit `outputHeld`, less every try so far) and its
145
162
  * input, the prompt `last` was asked with, is priced uncached at the dearer of the input and cache-write prices, as the
@@ -16,7 +16,7 @@
16
16
  import { randomUUID } from "node:crypto";
17
17
  import { calculateCost } from "@earendil-works/pi-ai";
18
18
  import { onOpenRouter, openRouterAttribution, ROUTE_ORIGIN, streamErrorOf } from "@parcha/agentrun-kernel/host";
19
- import { chooseModel, MODEL_PROVIDER, runModels } from "../model.js";
19
+ import { chooseModel, FAUX_PROVIDER, MODEL_PROVIDER, runModels } from "../model.js";
20
20
  import { OLLAMA_PROVIDER } from "../ollama-provider.js";
21
21
  import { gatewayHeadersAt, providerFor } from "../provider.js";
22
22
  import { keepText, runnerSecrets, secretRedactor } from "./redact.js";
@@ -85,7 +85,9 @@ export async function routeOf(model, env = process.env, tier = "default", wires
85
85
  // before Ollama would cut the prompt.
86
86
  const local = target.provider === OLLAMA_PROVIDER;
87
87
  const like = target.provider === "particle" ? { ...settings, ...LEVELS_BY_NAME, translatedChatCompletions: true } : local ? { ...settings, ...(target.reasoning ? LEVELS_BY_NAME : {}) } : target.reasoning ? { ...sees, ...LEVELS_BY_NAME } : undefined;
88
- return { ...route, ...(like ? { like } : {}), ...(local ? { local: true } : {}), provider: { api: "anthropic-messages", origin: ROUTE_ORIGIN, credential: () => "model-route" }, fetch: messagesFetch(models, target, redact ?? secretRedactor(runnerSecrets(env)), upstream, env) };
88
+ // Where pi-ai sends the translated requests (its model's baseUrl), for the run's trace: none under the faux model.
89
+ const upstreamOrigin = target.provider !== FAUX_PROVIDER && target.baseUrl ? { upstreamOrigin: target.baseUrl } : {};
90
+ return { ...route, ...(like ? { like } : {}), ...(local ? { local: true } : {}), ...upstreamOrigin, provider: { api: "anthropic-messages", origin: ROUTE_ORIGIN, credential: () => "model-route" }, fetch: messagesFetch(models, target, redact ?? secretRedactor(runnerSecrets(env)), upstream, env) };
89
91
  }
90
92
  /** Whether pi-ai sends `target`'s requests to OpenRouter (pi-ai's own test, utils/openrouter-cost.js isOpenRouterModel). */
91
93
  const piOnOpenRouter = (target) => target.provider === "openrouter" || onOpenRouter(target.baseUrl ?? "");
@@ -393,6 +395,122 @@ export function messagesFetch(models, target, redact = keepText, upstream, env =
393
395
  return new Response(stream, { status: 200, headers: { "content-type": "text/event-stream" } });
394
396
  });
395
397
  }
398
+ /** The bytes of a request a token count answers per token (forMessagesClients' count_tokens). */
399
+ const COUNT_BYTES_PER_TOKEN = 4;
400
+ /** Whether a request asks Messages' token count (its path's last segment, any query after it). */
401
+ const countsTokens = (url) => /\/count_tokens(?:\?|$)/.test(String(url));
402
+ /** Why a Messages `tool_choice` that forces a call is refused (its 400's words), else undefined: the model behind the
403
+ * route (Ollama's chat) takes no tool choice, so a call forced by "any" or by a tool's name cannot be kept. "auto",
404
+ * "none" and none at all are taken; any other type is refused too. */
405
+ function forcedChoice(choice) {
406
+ if (choice === undefined || choice === null)
407
+ return undefined;
408
+ const plain = typeof choice === "object" && !Array.isArray(choice) ? choice : undefined;
409
+ const type = plain ? plain.type : choice;
410
+ if (type === "auto" || type === "none")
411
+ return undefined;
412
+ const unkept = 'is not taken on this model\'s route: the model here cannot be made to call a tool, so send "auto"';
413
+ if (type === "any")
414
+ return `tool_choice "any" ${unkept}`;
415
+ if (type === "tool")
416
+ return `tool_choice naming the tool ${String(plain?.name ?? "(none)")} ${unkept}`;
417
+ return `tool_choice ${JSON.stringify(type ?? "(no type)")} is not taken on this model's route: "auto" and "none" only`;
418
+ }
419
+ /** `route` (a translated route's fetch, which streams every answer, as pi-ai asks) for any Messages client on the wire it
420
+ * translates onto, which asks two things pi-ai never does. Its token count (POST /v1/messages/count_tokens, free, asked
421
+ * beside its turns) is answered here and never run on the model, which has no count of its own: the body's bytes over
422
+ * four (COUNT_BYTES_PER_TOKEN), a bound for its context, not a price. A request with no `stream: true` (a side request)
423
+ * gets its answer whole, one JSON message as Messages writes it, joined from the stream (wholeOf). A tool_choice that
424
+ * forces a call is refused with a 400 before the model is asked (forcedChoice). */
425
+ export function forMessagesClients(route) {
426
+ return (async (url, init = {}) => {
427
+ const body = String(init.body ?? "");
428
+ if (countsTokens(url))
429
+ return Response.json({ input_tokens: Math.ceil(new TextEncoder().encode(body).length / COUNT_BYTES_PER_TOKEN) });
430
+ const read = (() => {
431
+ try {
432
+ return JSON.parse(body || "{}");
433
+ }
434
+ catch {
435
+ return undefined;
436
+ }
437
+ })();
438
+ const refused = forcedChoice(read?.tool_choice);
439
+ if (refused)
440
+ return messagesError(refused, 400, "invalid_request_error");
441
+ const streamed = read === undefined || read.stream === true;
442
+ const answer = await route(url, init);
443
+ return streamed || answer.status !== 200 ? answer : wholeOf(await answer.text());
444
+ });
445
+ }
446
+ /** The route's translation onto each wire it translates a model onto (wires.ts TRANSLATED), by wire: what a harness's
447
+ * proxy on that wire forwards with for `model` (`provider/model-id`), made on `env`. Anthropic's Messages: the route's
448
+ * own Messages fetch (messagesFetch), as a Messages client asks it (forMessagesClients). provider.ts routedProvider reads
449
+ * it; a wire with no entry has no translation, whatever TRANSLATED says. */
450
+ export const TRANSLATORS = Object.freeze({
451
+ "anthropic-messages": async (model, env) => forMessagesClients((await routeOf(model, env)).fetch),
452
+ });
453
+ /** One Messages answer whole, from the events of its stream (`sse`): the message_start's message, each block joined from
454
+ * its deltas (a tool call's input parsed from its pieces), the last message_delta's stop and usage over the start's. An
455
+ * error event answers as Messages writes an error, at 500, with its words; so does a stream a part of which is not JSON. */
456
+ function wholeOf(sse) {
457
+ try {
458
+ return wholeRead(sse);
459
+ }
460
+ catch {
461
+ // A part that does not read (a data line not JSON, a tool call's input cut short) is said as an error event is.
462
+ return messagesError("The model's answer could not be read whole: a part of it is not JSON.");
463
+ }
464
+ }
465
+ /** A Messages error answer: `words` its message, 500 api_error unless said otherwise. */
466
+ const messagesError = (words, status = 500, type = "api_error") => Response.json({ type: "error", error: { type, message: words } }, { status });
467
+ /** wholeOf's reading, which throws on a part that is not JSON. */
468
+ function wholeRead(sse) {
469
+ let message = {};
470
+ const blocks = [];
471
+ const pieces = new Map();
472
+ for (const frame of sse.split(/\n\n/)) {
473
+ const lines = frame.split("\n");
474
+ const kind = lines.find((line) => line.startsWith("event: "))?.slice("event: ".length);
475
+ const data = lines.filter((line) => line.startsWith("data: ")).map((line) => line.slice("data: ".length)).join("\n");
476
+ if (!kind || !data)
477
+ continue;
478
+ if (kind === "error") {
479
+ let words = data;
480
+ try {
481
+ const said = JSON.parse(data);
482
+ words = String(said.error?.message ?? said.message ?? data);
483
+ }
484
+ catch {
485
+ // Its words alone (sendWords), not JSON.
486
+ }
487
+ return messagesError(words);
488
+ }
489
+ const event = JSON.parse(data);
490
+ const at = event.index ?? -1;
491
+ if (kind === "message_start")
492
+ message = { ...event.message };
493
+ else if (kind === "content_block_start" && event.content_block)
494
+ blocks[at] = { ...event.content_block };
495
+ else if (kind === "content_block_delta" && blocks[at] && event.delta) {
496
+ const { type, text, thinking, signature, partial_json: piece } = event.delta;
497
+ if (type === "text_delta")
498
+ blocks[at].text = (blocks[at].text ?? "") + (text ?? "");
499
+ else if (type === "thinking_delta")
500
+ blocks[at].thinking = (blocks[at].thinking ?? "") + (thinking ?? "");
501
+ else if (type === "signature_delta")
502
+ blocks[at].signature = signature ?? "";
503
+ else if (type === "input_json_delta")
504
+ pieces.set(at, (pieces.get(at) ?? "") + (piece ?? ""));
505
+ }
506
+ else if (kind === "message_delta")
507
+ message = { ...message, ...(event.delta ?? {}), usage: { ...(message.usage ?? {}), ...(event.usage ?? {}) } };
508
+ }
509
+ for (const [at, piece] of pieces)
510
+ if (blocks[at] && piece)
511
+ blocks[at].input = JSON.parse(piece);
512
+ return Response.json({ ...message, content: blocks.filter(Boolean) });
513
+ }
396
514
  /** pi-ai's stop reason as Messages says it. */
397
515
  const stopReasonOf = (reason) => (reason === "toolUse" ? "tool_use" : reason === "length" ? "max_tokens" : "end_turn");
398
516
  /** pi-ai's thinking levels past off, each asked by its own name. */
@@ -1,8 +1,9 @@
1
- import type { Runners } from "../store/store.js";
1
+ import { type Runners } from "../store/store.js";
2
2
  /** How often a runner says again that it is there. */
3
3
  export declare const PRESENCE_RENEW_MS = 10000;
4
- /** How old a runner's word can be and still count: three renewals missed. */
5
- export declare const PRESENCE_STALE_MS: number;
4
+ /** How old a runner's word can be and still count: three renewals missed. The store's (RUNNER_STALE_MS), which its claim
5
+ * rule reads for a kept computer's pin. */
6
+ export declare const PRESENCE_STALE_MS = 30000;
6
7
  /** This build's version (the serve package's), which every runner says on its row (runners.version) for the server's
7
8
  * capacity read (GET /v2/capacity). */
8
9
  export declare const RUNNER_VERSION: string;
@@ -12,10 +12,12 @@
12
12
  import { randomUUID } from "node:crypto";
13
13
  import { readFileSync } from "node:fs";
14
14
  import { ApiError } from "../errors.js";
15
+ import { RUNNER_STALE_MS } from "../store/store.js";
15
16
  /** How often a runner says again that it is there. */
16
17
  export const PRESENCE_RENEW_MS = 10_000;
17
- /** How old a runner's word can be and still count: three renewals missed. */
18
- export const PRESENCE_STALE_MS = 3 * PRESENCE_RENEW_MS;
18
+ /** How old a runner's word can be and still count: three renewals missed. The store's (RUNNER_STALE_MS), which its claim
19
+ * rule reads for a kept computer's pin. */
20
+ export const PRESENCE_STALE_MS = RUNNER_STALE_MS;
19
21
  /** This build's version (the serve package's), which every runner says on its row (runners.version) for the server's
20
22
  * capacity read (GET /v2/capacity). */
21
23
  export const RUNNER_VERSION = JSON.parse(readFileSync(new URL("../../package.json", import.meta.url), "utf8")).version;
@@ -117,6 +117,8 @@ interface ClaimReads {
117
117
  };
118
118
  readonly claimed: NodeJS.ProcessEnv;
119
119
  readonly signal?: AbortSignal;
120
+ /** The runner's presence incarnation (LoopDeps.incarnation): with the claim's runner, who keeps a computer a park pins. */
121
+ readonly incarnation?: string;
120
122
  }
121
123
  /** Held (held.ts) for one claim, on the runner: each answer the claim's own, read with the runner's seal key from the
122
124
  * runner's own reads of the claim; every argument from the run's process is checked or ignored. `bigs`: the run's pieced
@@ -173,6 +175,9 @@ export declare function staysInRunner(deps: Pick<AdapterSpecDeps, "store" | "dat
173
175
  /** The runner's loop factory where each run is a process of its own: a ChildLoop per claim, but for a run that stays in
174
176
  * the runner (staysInRunner). */
175
177
  export declare function childLoops(options: ChildLoopsOptions): LoopFactory;
178
+ /** The pair a run's process is handed this runner's OpenTelemetry settings in (secrets.ts OTEL_PAIR): none when it has
179
+ * none. */
180
+ export declare const otelPair: (env?: NodeJS.ProcessEnv) => (readonly [string, string])[];
176
181
  /** The runner's side of a run's channel over `socket`. Each call of the run's process runs inside the ledger of the tool
177
182
  * call it was made in (paid-calls.ts). web_save's slots are `gate`, this runner's one (save-slots.ts); the channel's end
178
183
  * (the run's end, or its process gone) gives back every slot the run held or waited for, and lets go of every pieced write