@parcha/agentrun-serve 0.1.0-beta.33 → 0.1.0-beta.34

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 (381) hide show
  1. package/CHANGELOG.md +233 -0
  2. package/README.md +266 -201
  3. package/dist/adapters.d.ts +0 -4
  4. package/dist/adapters.js +11 -15
  5. package/dist/agent-rows.d.ts +98 -0
  6. package/dist/agent-rows.js +1 -0
  7. package/dist/agents-store.d.ts +6 -2
  8. package/dist/agents-store.js +60 -25
  9. package/dist/agents.d.ts +9 -125
  10. package/dist/agents.js +15 -305
  11. package/dist/answer-json.d.ts +23 -0
  12. package/dist/answer-json.js +58 -0
  13. package/dist/api-only.d.ts +1 -1
  14. package/dist/api-only.js +2 -2
  15. package/dist/bash-read-only.d.ts +22 -0
  16. package/dist/bash-read-only.js +701 -0
  17. package/dist/box-settings.d.ts +3 -23
  18. package/dist/box-settings.js +7 -51
  19. package/dist/boxes.d.ts +17 -0
  20. package/dist/boxes.js +27 -20
  21. package/dist/browser-commands.d.ts +5 -2
  22. package/dist/browser-commands.js +4 -4
  23. package/dist/browser-computer.d.ts +5 -0
  24. package/dist/browser-computer.js +21 -0
  25. package/dist/browser-cost.d.ts +9 -6
  26. package/dist/browser-cost.js +92 -50
  27. package/dist/browser-live.d.ts +7 -20
  28. package/dist/browser-live.js +15 -93
  29. package/dist/browser-person.d.ts +18 -51
  30. package/dist/browser-person.js +94 -277
  31. package/dist/cap.d.ts +8 -5
  32. package/dist/cap.js +12 -5
  33. package/dist/cli.js +39 -13
  34. package/dist/closed-pipes.d.ts +2 -0
  35. package/dist/closed-pipes.js +13 -0
  36. package/dist/computer-commands.d.ts +2 -0
  37. package/dist/computer-commands.js +2 -0
  38. package/dist/computer-keys.js +5 -2
  39. package/dist/computer-setting.d.ts +20 -4
  40. package/dist/computer-setting.js +25 -5
  41. package/dist/computers.d.ts +30 -2
  42. package/dist/computers.js +70 -11
  43. package/dist/confine.d.ts +120 -0
  44. package/dist/confine.js +436 -0
  45. package/dist/console/assets/index-RPHGlXmM.js +540 -0
  46. package/dist/console/assets/index-opTN5Naq.css +1 -0
  47. package/dist/console/index.html +2 -2
  48. package/dist/decision-rows.d.ts +1 -1
  49. package/dist/decision-rows.js +1 -1
  50. package/dist/docker-daemon.d.ts +31 -0
  51. package/dist/docker-daemon.js +56 -0
  52. package/dist/effort-guidance.js +4 -3
  53. package/dist/environment.d.ts +0 -3
  54. package/dist/environment.js +3 -5
  55. package/dist/errors.d.ts +0 -2
  56. package/dist/errors.js +6 -9
  57. package/dist/filed-answer.d.ts +32 -0
  58. package/dist/filed-answer.js +160 -0
  59. package/dist/files.d.ts +1 -3
  60. package/dist/files.js +2 -4
  61. package/dist/github-connection.d.ts +1 -1
  62. package/dist/graph-view.d.ts +3 -5
  63. package/dist/graph-view.js +4 -14
  64. package/dist/handed-values.d.ts +9 -0
  65. package/dist/handed-values.js +26 -0
  66. package/dist/harness-install.d.ts +1 -7
  67. package/dist/harness-install.js +1 -18
  68. package/dist/harness-opencode/adapter.d.ts +7 -0
  69. package/dist/harness-opencode/adapter.js +23 -6
  70. package/dist/harness-opencode/index.d.ts +1 -1
  71. package/dist/harness-opencode/index.js +1 -1
  72. package/dist/harness-opencode/verify.d.ts +17 -0
  73. package/dist/harness-opencode/verify.js +30 -10
  74. package/dist/harness-table.js +6 -1
  75. package/dist/heard.js +1 -1
  76. package/dist/held-fd.d.ts +5 -0
  77. package/dist/held-fd.js +14 -0
  78. package/dist/host-calls.d.ts +20 -0
  79. package/dist/host-calls.js +12 -0
  80. package/dist/host-tools.d.ts +4 -21
  81. package/dist/host-tools.js +4 -61
  82. package/dist/host.d.ts +2 -4
  83. package/dist/host.js +2 -7
  84. package/dist/import-summary.d.ts +1 -5
  85. package/dist/import-summary.js +0 -21
  86. package/dist/import.d.ts +6 -6
  87. package/dist/import.js +14 -15
  88. package/dist/key-refusal.d.ts +5 -1
  89. package/dist/key-refusal.js +19 -4
  90. package/dist/learn/check.d.ts +6 -2
  91. package/dist/learn/check.js +83 -29
  92. package/dist/learn/folder.d.ts +5 -1
  93. package/dist/learn/folder.js +10 -3
  94. package/dist/learn/grade.d.ts +14 -0
  95. package/dist/learn/grade.js +68 -12
  96. package/dist/learn/index.d.ts +4 -4
  97. package/dist/learn/index.js +4 -4
  98. package/dist/learn/reflect.d.ts +31 -2
  99. package/dist/learn/reflect.js +79 -4
  100. package/dist/learn/relevance.d.ts +24 -0
  101. package/dist/learn/relevance.js +91 -0
  102. package/dist/learn/secrets.d.ts +7 -1
  103. package/dist/learn/secrets.js +86 -19
  104. package/dist/learn/skills.d.ts +112 -14
  105. package/dist/learn/skills.js +556 -52
  106. package/dist/learned-workflow.d.ts +32 -1
  107. package/dist/learned-workflow.js +100 -9
  108. package/dist/learning-routes.d.ts +8 -4
  109. package/dist/learning-routes.js +23 -9
  110. package/dist/learning-run.d.ts +9 -26
  111. package/dist/learning-run.js +22 -32
  112. package/dist/learning-words.d.ts +12 -5
  113. package/dist/learning-words.js +18 -9
  114. package/dist/learning.d.ts +93 -77
  115. package/dist/learning.js +176 -304
  116. package/dist/live/stream.js +1 -1
  117. package/dist/live/translate.js +12 -2
  118. package/dist/local-models.d.ts +11 -5
  119. package/dist/local-models.js +13 -8
  120. package/dist/mcp-gateway.d.ts +11 -49
  121. package/dist/mcp-gateway.js +44 -135
  122. package/dist/mcp-oauth.d.ts +10 -14
  123. package/dist/mcp-oauth.js +14 -32
  124. package/dist/mcp-probe.d.ts +0 -7
  125. package/dist/mcp-probe.js +4 -10
  126. package/dist/mcp-servers-store.d.ts +6 -6
  127. package/dist/mcp-servers-store.js +12 -14
  128. package/dist/mcp-store.js +3 -4
  129. package/dist/mcp.js +4 -3
  130. package/dist/model.d.ts +6 -7
  131. package/dist/model.js +43 -27
  132. package/dist/monid.d.ts +0 -2
  133. package/dist/monid.js +3 -6
  134. package/dist/openapi.d.ts +8 -1
  135. package/dist/openapi.js +121 -47
  136. package/dist/page.d.ts +1 -3
  137. package/dist/page.js +6 -18
  138. package/dist/paid-calls.d.ts +21 -27
  139. package/dist/paid-calls.js +25 -60
  140. package/dist/propose.js +83 -39
  141. package/dist/push-handler.d.ts +1 -1
  142. package/dist/reflect-range.d.ts +25 -0
  143. package/dist/reflect-range.js +30 -0
  144. package/dist/refusal-words.d.ts +5 -1
  145. package/dist/refusal-words.js +5 -1
  146. package/dist/rows.d.ts +1 -1
  147. package/dist/run-cut.d.ts +0 -6
  148. package/dist/run-cut.js +0 -6
  149. package/dist/run-db.d.ts +2 -11
  150. package/dist/run-db.js +2 -37
  151. package/dist/run-launch.d.ts +19 -2
  152. package/dist/run-launch.js +13 -5
  153. package/dist/run-learning-served.d.ts +10 -4
  154. package/dist/run-learning-served.js +23 -13
  155. package/dist/run-reads-over-store.d.ts +1 -1
  156. package/dist/run-reads-over-store.js +15 -6
  157. package/dist/run-secrets.d.ts +1 -1
  158. package/dist/run-timeline-served.d.ts +5 -1
  159. package/dist/run-timeline-served.js +15 -4
  160. package/dist/run-view.d.ts +7 -8
  161. package/dist/run-view.js +26 -7
  162. package/dist/runnable.d.ts +18 -10
  163. package/dist/runnable.js +21 -10
  164. package/dist/runner/adapter-loop.d.ts +6 -1
  165. package/dist/runner/adapter-loop.js +423 -53
  166. package/dist/runner/adapter-run-spec.d.ts +21 -8
  167. package/dist/runner/adapter-run-spec.js +90 -32
  168. package/dist/runner/adapters/index.js +11 -1
  169. package/dist/runner/adapters/pi.d.ts +12 -2
  170. package/dist/runner/adapters/pi.js +16 -5
  171. package/dist/runner/beside.d.ts +30 -3
  172. package/dist/runner/beside.js +36 -5
  173. package/dist/runner/claim-secrets.d.ts +10 -1
  174. package/dist/runner/claim-secrets.js +48 -14
  175. package/dist/runner/cli-run-spec.d.ts +2 -0
  176. package/dist/runner/cli-run-spec.js +45 -16
  177. package/dist/runner/commands.js +1 -1
  178. package/dist/runner/computer-journal.d.ts +15 -2
  179. package/dist/runner/computer-journal.js +41 -5
  180. package/dist/runner/conformance/harness.js +118 -8
  181. package/dist/runner/conformance/subject.d.ts +4 -1
  182. package/dist/runner/dispatch.d.ts +8 -1
  183. package/dist/runner/dispatch.js +81 -7
  184. package/dist/runner/end-of-run.d.ts +8 -2
  185. package/dist/runner/end-of-run.js +10 -4
  186. package/dist/runner/github-app.js +1 -1
  187. package/dist/runner/harness-loops.d.ts +9 -1
  188. package/dist/runner/harness-loops.js +15 -2
  189. package/dist/runner/journal-kinds.d.ts +24 -6
  190. package/dist/runner/journal-kinds.js +20 -5
  191. package/dist/runner/journal-reader.d.ts +1 -1
  192. package/dist/runner/journal-reader.js +2 -2
  193. package/dist/runner/learning-ask.d.ts +4 -0
  194. package/dist/runner/learning-ask.js +15 -1
  195. package/dist/runner/learning-end.d.ts +18 -3
  196. package/dist/runner/learning-end.js +113 -11
  197. package/dist/runner/learning-loop.d.ts +5 -0
  198. package/dist/runner/learning-loop.js +26 -6
  199. package/dist/runner/main.d.ts +56 -9
  200. package/dist/runner/main.js +127 -18
  201. package/dist/runner/mcp-claim.js +1 -2
  202. package/dist/runner/mcp-run.d.ts +2 -0
  203. package/dist/runner/mcp-run.js +15 -5
  204. package/dist/runner/memory-claim.d.ts +9 -0
  205. package/dist/runner/memory-claim.js +25 -0
  206. package/dist/runner/metrics.d.ts +33 -1
  207. package/dist/runner/metrics.js +85 -1
  208. package/dist/runner/model-route.d.ts +13 -0
  209. package/dist/runner/model-route.js +133 -9
  210. package/dist/runner/reflect-hook.d.ts +12 -1
  211. package/dist/runner/reflect-hook.js +33 -3
  212. package/dist/runner/runner.d.ts +20 -0
  213. package/dist/runner/runner.js +56 -10
  214. package/dist/runner/store-port.d.ts +1 -1
  215. package/dist/runner/store-secrets.d.ts +3 -3
  216. package/dist/runner/store-secrets.js +8 -12
  217. package/dist/runner/text-tools.d.ts +44 -0
  218. package/dist/runner/text-tools.js +237 -0
  219. package/dist/runner/workflow-loop.d.ts +6 -0
  220. package/dist/runner/workflow-loop.js +6 -4
  221. package/dist/runner/workflow-spec.d.ts +18 -0
  222. package/dist/runner/workflow-spec.js +63 -17
  223. package/dist/runs-over-store.d.ts +7 -2
  224. package/dist/runs-over-store.js +60 -14
  225. package/dist/seal-key.js +5 -43
  226. package/dist/sealed-settings-store.d.ts +19 -4
  227. package/dist/sealed-settings-store.js +9 -9
  228. package/dist/sealing.d.ts +4 -0
  229. package/dist/sealing.js +20 -0
  230. package/dist/secret-cut.d.ts +1 -1
  231. package/dist/secret-cut.js +1 -1
  232. package/dist/secret-name.d.ts +9 -0
  233. package/dist/secret-name.js +15 -0
  234. package/dist/secret-writes.d.ts +0 -1
  235. package/dist/secret-writes.js +0 -1
  236. package/dist/server-fs.d.ts +4 -0
  237. package/dist/server-fs.js +8 -2
  238. package/dist/server-lock.d.ts +0 -24
  239. package/dist/server-lock.js +1 -80
  240. package/dist/server-secrets-store.d.ts +4 -4
  241. package/dist/server-secrets-store.js +9 -31
  242. package/dist/server-secrets.d.ts +4 -9
  243. package/dist/server-secrets.js +12 -36
  244. package/dist/server.d.ts +16 -38
  245. package/dist/server.js +145 -106
  246. package/dist/sign-ins-store.d.ts +34 -36
  247. package/dist/sign-ins-store.js +27 -38
  248. package/dist/sign-ins.d.ts +2 -119
  249. package/dist/sign-ins.js +5 -311
  250. package/dist/standard-webhooks.d.ts +1 -1
  251. package/dist/standard-webhooks.js +1 -1
  252. package/dist/stats.d.ts +3 -2
  253. package/dist/stats.js +1 -1
  254. package/dist/store/agent-body.d.ts +8 -2
  255. package/dist/store/agent-body.js +16 -4
  256. package/dist/store/index.d.ts +2 -2
  257. package/dist/store/index.js +2 -2
  258. package/dist/store/open.d.ts +6 -3
  259. package/dist/store/open.js +2 -2
  260. package/dist/store/postgres/connection.d.ts +18 -2
  261. package/dist/store/postgres/connection.js +156 -32
  262. package/dist/store/postgres/migrate.d.ts +4 -0
  263. package/dist/store/postgres/migrate.js +9 -2
  264. package/dist/store/postgres/migrations/0003_commands_one_answer.check.sql +19 -0
  265. package/dist/store/postgres/migrations/0003_commands_one_answer.sql +13 -0
  266. package/dist/store/postgres/store.d.ts +9 -2
  267. package/dist/store/postgres/store.js +9 -0
  268. package/dist/store/schema.js +1 -1
  269. package/dist/store/seal.js +2 -2
  270. package/dist/store/sqlite/connection.js +49 -5
  271. package/dist/store/sqlite/run-patch.d.ts +3 -0
  272. package/dist/store/sqlite/run-patch.js +3 -0
  273. package/dist/store/sqlite/store.js +41 -12
  274. package/dist/store/store.d.ts +35 -6
  275. package/dist/store/store.js +12 -2
  276. package/dist/store-reads/cap.d.ts +1 -1
  277. package/dist/store-reads/cap.js +22 -4
  278. package/dist/store-reads/journal.d.ts +9 -6
  279. package/dist/store-reads/journal.js +93 -17
  280. package/dist/store-reads/learning.d.ts +26 -8
  281. package/dist/store-reads/learning.js +12 -4
  282. package/dist/store-reads/workflow.d.ts +1 -1
  283. package/dist/store-reads/workflow.js +1 -1
  284. package/dist/store-view.d.ts +5 -1
  285. package/dist/store-view.js +53 -18
  286. package/dist/template-eval.d.ts +60 -4
  287. package/dist/template-eval.js +120 -54
  288. package/dist/templates.d.ts +24 -10
  289. package/dist/templates.js +69 -38
  290. package/dist/timeline/group.d.ts +33 -0
  291. package/dist/timeline/group.js +77 -0
  292. package/dist/timeline/index.d.ts +7 -0
  293. package/dist/timeline/index.js +7 -0
  294. package/dist/timeline/labels.d.ts +79 -0
  295. package/dist/timeline/labels.js +150 -0
  296. package/dist/timeline/origin.d.ts +56 -0
  297. package/dist/timeline/origin.js +92 -0
  298. package/dist/timeline/render-text.d.ts +11 -0
  299. package/dist/timeline/render-text.js +62 -0
  300. package/dist/timeline/timeline.d.ts +274 -0
  301. package/dist/timeline/timeline.js +1308 -0
  302. package/dist/timeline/util.d.ts +17 -0
  303. package/dist/timeline/util.js +49 -0
  304. package/dist/tool-gate.d.ts +41 -216
  305. package/dist/tool-gate.js +79 -540
  306. package/dist/tool-keys-store.d.ts +11 -12
  307. package/dist/tool-keys-store.js +24 -31
  308. package/dist/tool-keys.d.ts +5 -101
  309. package/dist/tool-keys.js +8 -267
  310. package/dist/tool-plane.d.ts +14 -42
  311. package/dist/tool-plane.js +23 -81
  312. package/dist/tool-settings-store.d.ts +1 -2
  313. package/dist/tool-settings-store.js +5 -8
  314. package/dist/tools.d.ts +30 -18
  315. package/dist/tools.js +97 -107
  316. package/dist/trigger-adapter.d.ts +2 -2
  317. package/dist/trigger-targets.d.ts +13 -1
  318. package/dist/trigger-targets.js +31 -1
  319. package/dist/triggers.d.ts +2 -2
  320. package/dist/triggers.js +3 -3
  321. package/dist/turn-end.d.ts +1 -1
  322. package/dist/turn-end.js +1 -1
  323. package/dist/turns.d.ts +0 -6
  324. package/dist/turns.js +0 -19
  325. package/dist/uploads.js +1 -1
  326. package/dist/usage.d.ts +0 -2
  327. package/dist/usage.js +0 -2
  328. package/dist/validate.d.ts +2 -0
  329. package/dist/validate.js +23 -14
  330. package/dist/webhooks.d.ts +102 -76
  331. package/dist/webhooks.js +266 -233
  332. package/dist/workflow-run.d.ts +114 -0
  333. package/dist/workflow-run.js +144 -0
  334. package/dist/workspace/beneath.d.ts +19 -0
  335. package/dist/workspace/beneath.js +106 -0
  336. package/dist/workspace/computer-deps.d.ts +24 -6
  337. package/dist/workspace/computer-deps.js +108 -20
  338. package/dist/workspace/computer-for-claim.d.ts +12 -11
  339. package/dist/workspace/computer-for-claim.js +76 -15
  340. package/dist/workspace/computer-hold.d.ts +6 -1
  341. package/dist/workspace/computer-hold.js +6 -1
  342. package/dist/workspace/computer-janitor.d.ts +47 -0
  343. package/dist/workspace/computer-janitor.js +182 -0
  344. package/dist/workspace/grep-worker.d.ts +5 -0
  345. package/dist/workspace/grep-worker.js +9 -6
  346. package/dist/workspace/index.d.ts +3 -2
  347. package/dist/workspace/index.js +3 -3
  348. package/dist/workspace/local.d.ts +11 -2
  349. package/dist/workspace/local.js +161 -43
  350. package/dist/workspace/resolve-computer.d.ts +50 -10
  351. package/dist/workspace/resolve-computer.js +46 -11
  352. package/dist/workspace/run-tools.d.ts +13 -31
  353. package/dist/workspace/run-tools.js +10 -27
  354. package/dist/workspace-paths.d.ts +0 -17
  355. package/dist/workspace-paths.js +1 -41
  356. package/dist/workspace.d.ts +0 -14
  357. package/dist/workspace.js +3 -96
  358. package/package.json +13 -13
  359. package/templates/README.md +9 -3
  360. package/templates/market-monitor/agent.md +2 -2
  361. package/templates/market-monitor/skills/monitor/SKILL.md +6 -4
  362. package/dist/bound-files.d.ts +0 -4
  363. package/dist/bound-files.js +0 -164
  364. package/dist/coding-tools.d.ts +0 -47
  365. package/dist/coding-tools.js +0 -189
  366. package/dist/computer-adb.d.ts +0 -12
  367. package/dist/computer-adb.js +0 -14
  368. package/dist/console/assets/index-Dn0ngwG9.js +0 -535
  369. package/dist/console/assets/index-DvW6Aled.css +0 -1
  370. package/dist/grade.d.ts +0 -63
  371. package/dist/grade.js +0 -150
  372. package/dist/mcp-servers.d.ts +0 -269
  373. package/dist/mcp-servers.js +0 -456
  374. package/dist/packs.d.ts +0 -71
  375. package/dist/packs.js +0 -180
  376. package/dist/sealed-settings.d.ts +0 -60
  377. package/dist/sealed-settings.js +0 -171
  378. package/dist/sessions.d.ts +0 -6
  379. package/dist/sessions.js +0 -109
  380. package/dist/workspace/computer-serves.d.ts +0 -12
  381. package/dist/workspace/computer-serves.js +0 -15
package/dist/sign-ins.js CHANGED
@@ -1,318 +1,12 @@
1
1
  // An agent's saved sign-ins: the browser it signed in with stays signed in for its later runs. The cookies stay at the
2
- // browser's vendor (a Browserbase context, a Kernel profile); this server keeps only a pointer to that object per agent,
3
- // in DATA/homes/<home key>/sign-ins/sign-ins.json (a host-owned folder: the home API neither reads nor writes it, and no
4
- // run's tools see it), each pointer sealed under the seal key tool keys are kept under (AGENTRUN_SEAL_KEY), bound to its
5
- // agent, key and vendor. One saved profile per agent per vendor, keyed `default`; the host picks it, never the model.
6
- // The server resolves the pointer before a run's launch and hands the run the pointer over its secrets' pipe, never its
7
- // environment: the run's process never gets the seal key. Local Chrome keeps none (its cookies would sit on this disk).
8
- //
9
- // Saving is leased across runs: each run is its own process, so pi-browser's one-saver rule (per process) cannot see
10
- // two runs of one agent. The first run of the agent to start with the browser holds the lease and its sessions save;
11
- // a run started while another holds it starts from the same sign-in and saves nothing. The lease ends when its run
12
- // ends, or lets go cleanly to wait for its person (runs.ts); a relaunch or a restart keeps it, since a session the run
13
- // opened before its process went may still write back. One whose run has ended since (a server down first) is stale.
14
- import { createHash, randomBytes } from "node:crypto";
15
- import { lstat, mkdir, readFile, rm } from "node:fs/promises";
16
- import { join } from "node:path";
17
- import { seal, unseal } from "@parcha/pi-durable-agent";
18
- import { ApiError } from "./errors.js";
19
- import { homeOf } from "./files.js";
20
- import { serialBy, writeDurable } from "./server-fs.js";
2
+ // browser's vendor (a Browserbase context, a Kernel profile); this server keeps only a sealed pointer to that object per
3
+ // agent and vendor, in the one store (sign-ins-store.ts), and a run on the runner reads it under its own claim. Here: the
4
+ // names a run and an agent's home use for it, and the vendors' own calls.
5
+ import { randomBytes } from "node:crypto";
6
+ /** The folder a sign-in was kept in under an agent's home: never served or written by the home API. */
21
7
  export const SIGN_INS_DIR = "sign-ins";
22
- const FILE = "sign-ins.json";
23
- const FORMAT = "sign-ins/1";
24
8
  /** The one saved profile an agent keeps per vendor. */
25
9
  export const SIGN_IN_KEY = "default";
26
- /** The file a run's process writes in its run directory when a session that saved to its sign-in let go: when the
27
- * lease ends, its time is the sign-in's `verified_at`. A time, never a pointer. */
28
- export const SIGN_IN_SAVED = "sign-in-saved";
29
- /** Browserbase writes a saved context back after its session ends (pi-browser waits profileSettleMs, 5 s, for it), so
30
- * its saver's lease outlasts the run's end by twice that: a run started meanwhile neither saves over it. A bound this
31
- * server chose; Browserbase publishes none. */
32
- export const BROWSERBASE_SETTLE_MS = 10_000;
33
- /** How long a lease outlives its holder's process: pi-browser's default session timeout (DEFAULT_BROWSER_POLICY's
34
- * sessionTimeoutS, 1800 s), which every session a run opens is created under, so none it opened before its process
35
- * went can still write back after it. A holder that comes back (its relaunch) holds the lease again from then on. */
36
- export const GONE_LEASE_MS = 1_800_000;
37
- /** How many forgotten pointers an agent keeps, the oldest dropped first. A run handed one dropped since is withheld, as
38
- * one whose sign-in does not open is (runs.ts): its pointer could no longer be cut. */
39
- export const MAX_FORGOTTEN = 32;
40
- /** What a run's serve.json keeps of the sign-in pointer it was handed (runs.ts `sign_in_handed`), and what forget asks
41
- * after: its SHA-256, never the pointer. */
42
- export const pointerHash = (ref) => createHash("sha256").update(ref, "utf8").digest("hex");
43
- /** The vendor a run's browser resolves to (its plane's `browser`) keeps a sign-in for: Browserbase's and Kernel's; local
44
- * Chrome is refused by name; an unavailable browser has none. */
45
- export function vendorOf(resolution) {
46
- if (resolution === "browserbase" || resolution === "kernel")
47
- return resolution;
48
- if (resolution === "chrome" || resolution === "cdp")
49
- throw new Error("a local Chrome keeps no saved sign-in: its cookies would sit on this server's disk");
50
- return undefined;
51
- }
52
- const aad = (agentId, entry) => `${FORMAT}|${agentId}|${entry.key}|${entry.provider}`;
53
- export class SignIns {
54
- data;
55
- key;
56
- vendors;
57
- holds;
58
- /** One read-modify-write at a time per agent; an agent's queue goes once it is empty. In this process alone: it, and
59
- * forget's ordering against a launch handing a pointer (forRun's keep), assume one server per data directory, which
60
- * the data directory's lock holds (server-lock.ts). */
61
- chains = new Map();
62
- now;
63
- writeFile;
64
- sleep;
65
- handedTo;
66
- /** `holds(run)`: whether that run has not ended, so a lease it names still holds; `handedTo`, which run still going
67
- * was handed a pointer (runs.ts), so forget waits for it; `now` and `sleep`, the clock, and `write`, the durable
68
- * write (writeDurable), the tests'. */
69
- constructor(data, key, vendors, holds, options = {}) {
70
- this.data = data;
71
- this.key = key;
72
- this.vendors = vendors;
73
- this.holds = holds;
74
- this.handedTo = options.handedTo;
75
- this.now = options.now ?? Date.now;
76
- this.sleep = options.sleep ?? ((ms) => new Promise((done) => setTimeout(done, ms)));
77
- this.writeFile = options.write ?? writeDurable;
78
- }
79
- /** Whether sign-ins are kept here: never without a seal key, never in the clear. */
80
- get available() {
81
- return this.key !== undefined;
82
- }
83
- file(agentId) {
84
- return join(homeOf(this.data, agentId), SIGN_INS_DIR, FILE);
85
- }
86
- async stored(agentId) {
87
- const text = await readFile(this.file(agentId), "utf8").catch((error) => (error.code === "ENOENT" ? null : Promise.reject(error)));
88
- if (text === null)
89
- return { sign_ins: [], forgotten: [] };
90
- const stored = JSON.parse(text);
91
- if (stored?.format !== FORMAT || !Array.isArray(stored.sign_ins) || (stored.forgotten !== undefined && !Array.isArray(stored.forgotten)))
92
- throw new Error(`${FILE} is not a ${FORMAT} file, so it was left as it is`);
93
- return { sign_ins: stored.sign_ins, forgotten: stored.forgotten ?? [] };
94
- }
95
- async read(agentId) {
96
- return (await this.stored(agentId)).sign_ins;
97
- }
98
- /** `forgotten`: the agent's forgotten pointers as they are to be kept; absent, those the file keeps now (every write is
99
- * under the agent's lock, so none comes between). */
100
- async write(agentId, entries, forgotten) {
101
- const dir = join(homeOf(this.data, agentId), SIGN_INS_DIR);
102
- const kept = forgotten ?? (await this.stored(agentId)).forgotten;
103
- if (!entries.length && !kept.length)
104
- return void (await rm(this.file(agentId), { force: true }));
105
- await mkdir(dir, { recursive: true, mode: 0o700 });
106
- if ((await lstat(dir)).isSymbolicLink())
107
- throw new Error(`${SIGN_INS_DIR}/ is a link, which this server never follows`);
108
- // Synced before it answers: a pointer to a vendor object just made survives a crash of the machine.
109
- await this.writeFile(this.file(agentId), `${JSON.stringify({ format: FORMAT, sign_ins: entries, ...(kept.length ? { forgotten: kept } : {}) })}\n`);
110
- }
111
- locked(agentId, work) {
112
- return serialBy(this.chains, agentId, work);
113
- }
114
- /** Whether `entry`'s lease still holds: it names a run that has not ended; or, once its process was found gone, that
115
- * went less than GONE_LEASE_MS ago, ended or not (a run waiting on its person with no process, or one that crashed and
116
- * ended, is never let go otherwise, or let go too soon). */
117
- async held(entry) {
118
- if (entry.held_by === null)
119
- return false;
120
- if (entry.held_until)
121
- return this.now() < Date.parse(entry.held_until);
122
- // A Browserbase session that lived out the timeout still writes its context back after it ends; Kernel's browser
123
- // ends at its idle timeout and saves as it ends, so it needs no margin.
124
- // Once its process is found gone, that alone decides, whether its run has ended since or not: a session it left
125
- // live may still write back until then.
126
- if (entry.gone_at)
127
- return this.now() - Date.parse(entry.gone_at) < GONE_LEASE_MS + (entry.provider === "browserbase" ? BROWSERBASE_SETTLE_MS : 0);
128
- return this.holds(entry.held_by).catch(() => true);
129
- }
130
- /** `entry`'s pointer, opened under this server's seal key; undefined when it does not open (none now, or another). A
131
- * forgotten one opens under the same binding, read only by `forgotten`, never as a sign-in. */
132
- open(agentId, entry) {
133
- if (!this.key)
134
- return undefined;
135
- try {
136
- return unseal(this.key, Buffer.from(entry.ref, "base64"), aad(agentId, entry)).toString("utf8");
137
- }
138
- catch {
139
- return undefined;
140
- }
141
- }
142
- /** The agent's sign-ins, as the contract shows them: never a ref. */
143
- async view(agentId) {
144
- const entries = await this.read(agentId).catch(() => []);
145
- return Promise.all(entries.map(async (entry) => {
146
- const held = await this.held(entry);
147
- // Unreadable or not, a run that holds its lease is named: forget is refused until it ends.
148
- if (this.open(agentId, entry) === undefined)
149
- return { key: entry.key, provider: entry.provider, state: "unreadable", held_by: held ? entry.held_by : null, verified_at: entry.verified_at };
150
- return { key: entry.key, provider: entry.provider, state: held ? "held" : "ready", held_by: held ? entry.held_by : null, verified_at: entry.verified_at };
151
- }));
152
- }
153
- /** The pointer of `agentId`'s sign-in for `resolution`, read only: no lease taken, nothing made or written. For a run
154
- * this server loads (after a restart), whose rows, errors and answers must never show it: `{ ref }`; `unreadable`
155
- * when the agent keeps one that does not open under this server's seal key (none now, or another), or its sign-ins
156
- * file cannot be read or parsed, told apart from none at all (undefined: no file, or no entry for the vendor). */
157
- async peek(agentId, resolution) {
158
- const vendor = (() => { try {
159
- return vendorOf(resolution);
160
- }
161
- catch {
162
- return undefined;
163
- } })();
164
- if (!vendor)
165
- return undefined;
166
- // Only a file that is not there means none: one this server may not read, or that does not parse, is unreadable.
167
- const entries = await this.read(agentId).catch(() => null);
168
- if (entries === null)
169
- return "unreadable";
170
- const entry = entries.find((e) => e.key === SIGN_IN_KEY && e.provider === vendor);
171
- if (!entry)
172
- return undefined;
173
- const ref = this.open(agentId, entry);
174
- return ref === undefined ? "unreadable" : { ref };
175
- }
176
- /** The pointers of `agentId`'s forgotten sign-ins for `resolution`'s vendor, read only, for a run this server loads that
177
- * may have been handed one (runs.ts peekSignIn): never a sign-in. `refs`, each that opens under this server's seal
178
- * key; `unreadable`, whether one does not (none now, or another). `unreadable` alone when the sign-ins file can't be
179
- * read or parsed. */
180
- async forgotten(agentId, resolution) {
181
- const vendor = (() => { try {
182
- return vendorOf(resolution);
183
- }
184
- catch {
185
- return undefined;
186
- } })();
187
- if (!vendor)
188
- return { refs: [], unreadable: false };
189
- const stored = await this.stored(agentId).catch(() => null);
190
- if (stored === null)
191
- return "unreadable";
192
- const opened = stored.forgotten.filter((gone) => gone.provider === vendor).map((gone) => this.open(agentId, gone));
193
- return { refs: opened.filter((ref) => ref !== undefined), unreadable: opened.some((ref) => ref === undefined) };
194
- }
195
- /** The sign-in run `runId` of `agentId` starts from on `resolution` (its plane's browser): made at the vendor when the
196
- * agent has none, then leased to this run to save, unless another run of the agent holds the lease. None for a
197
- * browser that keeps none, or with no seal key. `keep`: the run keeps that it was handed it (its serve.json), before
198
- * any forget of the agent's can look (forget's handedTo, under the same lock); one it could not keep is handed none. */
199
- async forRun(agentId, runId, resolution, keep) {
200
- const vendor = vendorOf(resolution);
201
- if (!vendor || !this.key)
202
- return undefined;
203
- const key = this.key;
204
- // The Browserbase saver itself, resumed while its last save is still being written back (held_until): it waits that
205
- // out, at most BROWSERBASE_SETTLE_MS, before it is handed save again, so no session of it opens on a context in flux.
206
- const mine = (await this.read(agentId).catch(() => [])).find((e) => e.key === SIGN_IN_KEY && e.provider === vendor && e.held_by === runId && e.held_until);
207
- const rest = mine ? Date.parse(mine.held_until) - this.now() : 0;
208
- if (rest > 0)
209
- await this.sleep(Math.min(rest, BROWSERBASE_SETTLE_MS));
210
- return this.locked(agentId, async () => {
211
- const entries = await this.read(agentId);
212
- let entry = entries.find((e) => e.key === SIGN_IN_KEY && e.provider === vendor);
213
- let ref;
214
- let made = false;
215
- if (entry) {
216
- // Never replaced by itself: the vendor's object it points to would be left behind, holding the agent's cookies.
217
- ref = this.open(agentId, entry);
218
- if (ref === undefined)
219
- throw new Error(`its saved sign-in does not open under this server's seal key: forget it (DELETE /v2/agents/${agentId}/sign-ins/${SIGN_IN_KEY}) and its next run signs in afresh`);
220
- }
221
- else {
222
- ref = await this.vendors.create(vendor);
223
- made = true;
224
- entry = { key: SIGN_IN_KEY, provider: vendor, ref: "", verified_at: null, held_by: null };
225
- entry.ref = seal(key, Buffer.from(ref, "utf8"), aad(agentId, entry)).toString("base64");
226
- entries.push(entry);
227
- }
228
- const save = entry.held_by === runId || !(await this.held(entry));
229
- if (save)
230
- Object.assign(entry, { held_by: runId, gone_at: null, held_until: null });
231
- try {
232
- await this.write(agentId, entries);
233
- }
234
- catch (error) {
235
- // Never kept, so never forgotten: the object just made goes at the vendor now, as far as it answers. Unless the
236
- // write landed and only what follows it failed (the folder's sync): then the pointer is kept, and so is its object.
237
- const sealed = entry.ref;
238
- const kept = await this.read(agentId).then((now) => now.some((e) => e.ref === sealed), () => false);
239
- if (made && !kept)
240
- await this.vendors.remove(vendor, ref).catch(() => undefined);
241
- throw error;
242
- }
243
- const handed = { provider: vendor, ref, save };
244
- return !keep || (await keep(handed)) ? handed : undefined;
245
- });
246
- }
247
- /** Run `runId`'s process was found gone: a lease it holds counts from now, while it does not come back (held). */
248
- markGone(agentId, runId) {
249
- return this.locked(agentId, async () => {
250
- const entries = await this.read(agentId);
251
- const mine = entries.filter((entry) => entry.held_by === runId && !entry.gone_at && !entry.held_until);
252
- if (!mine.length)
253
- return;
254
- for (const entry of mine)
255
- entry.gone_at = new Date(this.now()).toISOString();
256
- await this.write(agentId, entries);
257
- });
258
- }
259
- /** Ends the lease run `runId` holds, if it holds one: it ended, or let go to wait for its person; one whose process did
260
- * not let its sessions go (`clean` false) keeps it until the gone rule ends it. A session of it that saved (its
261
- * run directory's SIGN_IN_SAVED) makes that the sign-in's `verified_at`. */
262
- release(agentId, runId, runDir, clean = true) {
263
- return this.locked(agentId, async () => {
264
- const marker = join(runDir, SIGN_IN_SAVED);
265
- const saved = await readFile(marker, "utf8").then((text) => text.trim(), () => undefined);
266
- const entries = await this.read(agentId);
267
- const mine = entries.filter((entry) => entry.held_by === runId && !entry.held_until);
268
- if (mine.length) {
269
- const when = saved && !Number.isNaN(Date.parse(saved)) ? new Date(saved).toISOString() : undefined;
270
- const now = new Date(this.now()).toISOString();
271
- // `clean`: its process let its sessions go. One that crashed may have left a session live at the vendor, which
272
- // writes back when it ends: the lease stays named for it, and the gone rule (held) ends it.
273
- // A Browserbase session that saved is still being written back: the lease waits that out, named for this run.
274
- for (const entry of mine)
275
- Object.assign(entry, !clean ? { gone_at: entry.gone_at ?? now } : { gone_at: null, ...(when && entry.provider === "browserbase" ? { held_until: new Date(this.now() + BROWSERBASE_SETTLE_MS).toISOString() } : { held_by: null, held_until: null }) }, when ? { verified_at: when } : {});
276
- await this.write(agentId, entries);
277
- }
278
- await rm(marker, { force: true });
279
- });
280
- }
281
- /** DELETE /agents/{id}/sign-ins/{key}: each vendor's object deleted (best effort: what failed is said), then the
282
- * pointer. 404 for a key the agent has none of; 409 while a run holds its lease, or while a run it was handed is still
283
- * going (handedTo), its lease let go or not: what that run says could repeat the pointer, and a server started after
284
- * the pointer is gone could no longer read it back to cut it (runs.ts peekSignIn). */
285
- forget(agentId, signInKey) {
286
- return this.locked(agentId, async () => {
287
- const entries = await this.read(agentId);
288
- const named = entries.filter((entry) => entry.key === signInKey);
289
- if (!named.length)
290
- throw new ApiError("not_found", `The agent ${agentId} has no sign-in ${signInKey}.`);
291
- for (const entry of named)
292
- if (await this.held(entry))
293
- throw new ApiError("sign_in_held", `The sign-in ${signInKey} is held by the run ${entry.held_by}, which may still save to it: forget it once that run ends.`, { details: { held_by: entry.held_by } });
294
- // Asked under the lock a launch hands a pointer under (forRun's keep): a run handed it now is one this sees.
295
- for (const entry of named) {
296
- const ref = this.open(agentId, entry);
297
- const runId = await this.handedTo?.(agentId, ref === undefined ? undefined : pointerHash(ref));
298
- if (runId)
299
- throw new ApiError("sign_in_held", `The sign-in ${signInKey} was handed to the run ${runId}, which is still going: what it says could repeat it, and once it is forgotten a restarted server could no longer cut it from what that run shows. Forget it once that run ends.`, { details: { handed_to: runId } });
300
- }
301
- const removed = [];
302
- for (const entry of named) {
303
- const ref = this.open(agentId, entry);
304
- const gone = ref === undefined ? new Error("its pointer does not open under this server's seal key") : await this.vendors.remove(entry.provider, ref).then(() => undefined, (error) => error);
305
- removed.push({ provider: entry.provider, at_vendor: gone ? "not_deleted" : "deleted", ...(gone ? { message: `Not deleted at ${entry.provider}: ${gone.message}. This server no longer points to it.` } : {}) });
306
- }
307
- // Each forgotten pointer is kept sealed as it was, for cutting alone (Forgotten), the newest MAX_FORGOTTEN of them.
308
- const { forgotten } = await this.stored(agentId);
309
- const at = new Date(this.now()).toISOString();
310
- const kept = [...forgotten, ...named.map((entry) => ({ key: entry.key, provider: entry.provider, ref: entry.ref, forgotten_at: at }))].slice(-MAX_FORGOTTEN);
311
- await this.write(agentId, entries.filter((entry) => entry.key !== signInKey), kept);
312
- return { key: signInKey, removed };
313
- });
314
- }
315
- }
316
10
  const base = (set, fallback) => (set?.trim() || fallback).replace(/\/+$/, "");
317
11
  /** The vendors over their REST APIs, with the server's keys (`env`, read at each call) through `fetchFor` (the tests'
318
12
  * fakes under faux). Browserbase: a context made for the agent (POST /v1/contexts, which opens no session; Browserbase
@@ -2,7 +2,7 @@
2
2
  export declare const HOOK_TOLERANCE_S = 300;
3
3
  /** The fewest bytes a verification key may have (the spec's secrets are 24 to 64; this server makes 32): a shorter one,
4
4
  * an empty one above all, signs nothing. It is the floor for keys a request is verified with alone: a sealed setting
5
- * that is such a key declares `minBytes: MIN_KEY_BYTES` (sealed-settings.ts); a token that is no HMAC key (a bot's)
5
+ * that is such a key declares `minBytes: MIN_KEY_BYTES` (sealed-settings-store.ts); a token that is no HMAC key (a bot's)
6
6
  * sets its own floor, or none. */
7
7
  export declare const MIN_KEY_BYTES = 24;
8
8
  /** A webhook-id: printable ASCII with no space, as the spec's `msg_...` ids are; it goes into a firing's key and history. */
@@ -7,7 +7,7 @@ import { createHmac, randomBytes, timingSafeEqual } from "node:crypto";
7
7
  export const HOOK_TOLERANCE_S = 300;
8
8
  /** The fewest bytes a verification key may have (the spec's secrets are 24 to 64; this server makes 32): a shorter one,
9
9
  * an empty one above all, signs nothing. It is the floor for keys a request is verified with alone: a sealed setting
10
- * that is such a key declares `minBytes: MIN_KEY_BYTES` (sealed-settings.ts); a token that is no HMAC key (a bot's)
10
+ * that is such a key declares `minBytes: MIN_KEY_BYTES` (sealed-settings-store.ts); a token that is no HMAC key (a bot's)
11
11
  * sets its own floor, or none. */
12
12
  export const MIN_KEY_BYTES = 24;
13
13
  /** A webhook-id: printable ASCII with no space, as the spec's `msg_...` ids are; it goes into a firing's key and history. */
package/dist/stats.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import type { AnalyticsFilter, PendingEnd, StoreAnalytics, StoreStats } from "@parcha/pi-durable-agent";
1
+ import type { StoreStats } from "./store-reads/stats.js";
2
+ import type { AnalyticsFilter, PendingEnd, StoreAnalytics } from "./store-reads/analytics.js";
2
3
  import { type Status } from "./run-view.js";
3
4
  /** GET /stats's counts, from the store's aggregates (StoreStats) and each running row's status read over the store
4
5
  * (`statusOf`, viewOverStore): the runner writes a run's end to the store before it lets it go, so this server holds no
@@ -91,7 +92,7 @@ export declare function analyticsView(a: StoreAnalytics, filter: AnalyticsFilter
91
92
  tokens: number;
92
93
  cost_usd: number | null;
93
94
  unknown_cost_runs: number;
94
- source: "live" | import("@parcha/pi-durable-agent").ImportSource;
95
+ source: "live" | import("./store-reads/analytics.js").ImportSource;
95
96
  }[];
96
97
  tools: {
97
98
  tool: string;
package/dist/stats.js CHANGED
@@ -1,4 +1,4 @@
1
- import { nameOf } from "@parcha/pi-durable-agent/timeline";
1
+ import { nameOf } from "./timeline/index.js";
2
2
  import { ApiError } from "./errors.js";
3
3
  import { ID } from "./validate.js";
4
4
  /** Where a running row is counted, by its status (a paused workflow run is active). Over the store a run's status is its
@@ -26,11 +26,15 @@ export type RevisionPlace = {
26
26
  mode: string;
27
27
  box?: string;
28
28
  };
29
- /** A revision's computer (computer-setting.ts): its kind and the provider that serves it, ids its host knows; `place` is
30
- * its v2 view. */
29
+ /** A revision's computer (computer-setting.ts): its kind and the provider that serves it, ids its host knows, and a
30
+ * sandbox's GPUs, a type its provider names and how many; `place` is its v2 view. */
31
31
  export type RevisionComputer = {
32
32
  kind: string;
33
33
  provider?: string;
34
+ gpu?: {
35
+ type: string;
36
+ count: number;
37
+ };
34
38
  };
35
39
  /** A revision's tool settings as its body keeps them: a map of a tool's key to its settings ({provider?, permission?,
36
40
  * pin?}), checked and made canonical by the caller (agents-store.ts, through tool-plane's settingsIssues +
@@ -51,6 +55,7 @@ export type AgenticBody = {
51
55
  maxCostUsd?: number;
52
56
  capMode?: string;
53
57
  approvals?: "ask" | "never";
58
+ outputSchema?: Record<string, unknown>;
54
59
  };
55
60
  export type WorkflowBody = {
56
61
  workflow: Record<string, unknown>;
@@ -82,6 +87,7 @@ export type RevisionBodyInput = {
82
87
  maxCostUsd?: number;
83
88
  capMode?: string;
84
89
  approvals?: "ask" | "never";
90
+ outputSchema?: Record<string, unknown>;
85
91
  } | {
86
92
  kind: "workflow";
87
93
  workflow: unknown;
@@ -42,12 +42,20 @@ function placeOf(place) {
42
42
  const ok = place;
43
43
  return { mode: ok.mode, ...(ok.box !== undefined ? { box: ok.box } : {}) };
44
44
  }
45
- /** A computer as a body keeps it: `{kind, provider?}`, each an id, nothing else. */
45
+ /** A GPU type as a body keeps it: the vendor's own name ("T4", "A100-80GB", "RTX-PRO-6000"). */
46
+ const GPU_TYPE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
47
+ /** A computer as a body keeps it: `{kind, provider?, gpu?}`, nothing else: kind and provider ids, and gpu `{type, count}`,
48
+ * a GPU type name and a whole count from 1. */
46
49
  function computerOf(computer) {
47
- if (!isObject(computer) || !hostId(computer.kind) || (computer.provider !== undefined && !hostId(computer.provider)) || Object.keys(computer).some((key) => key !== "kind" && key !== "provider"))
48
- invalid("the computer is not {kind, provider?}, each an id (lowercase letters, digits and dashes)");
50
+ if (!isObject(computer) || !hostId(computer.kind) || (computer.provider !== undefined && !hostId(computer.provider)) || Object.keys(computer).some((key) => key !== "kind" && key !== "provider" && key !== "gpu"))
51
+ invalid("the computer is not {kind, provider?, gpu?}, kind and provider each an id (lowercase letters, digits and dashes)");
49
52
  const ok = computer;
50
- return { kind: ok.kind, ...(ok.provider !== undefined ? { provider: ok.provider } : {}) };
53
+ const gpu = ok.gpu;
54
+ if (gpu !== undefined && (!isObject(gpu) || Object.keys(gpu).some((key) => key !== "type" && key !== "count") || typeof gpu.type !== "string" || !GPU_TYPE.test(gpu.type) || !Number.isSafeInteger(gpu.count) || gpu.count < 1)) {
55
+ invalid("the computer's gpu is not {type, count}: a GPU type name (letters, digits, dots, underscores and dashes) and a whole count from 1");
56
+ }
57
+ const kept = gpu;
58
+ return { kind: ok.kind, ...(ok.provider !== undefined ? { provider: ok.provider } : {}), ...(kept !== undefined ? { gpu: { type: kept.type, count: kept.count } } : {}) };
51
59
  }
52
60
  /** The body of a new revision and the text of each skill it names (path to text), everything checked here, before any
53
61
  * write. The body keeps each skill path to its text's SHA-256; `skills` is the texts, for the revision's row. */
@@ -101,6 +109,8 @@ export function bodyOf(input) {
101
109
  invalid(`the ${field} is not a non-empty string`);
102
110
  if (input.learning !== undefined && typeof input.learning !== "boolean")
103
111
  invalid("learning is not true or false");
112
+ if (input.outputSchema !== undefined && !isObject(input.outputSchema))
113
+ invalid("the outputSchema is not a JSON object");
104
114
  const body = {
105
115
  instructions: input.instructions,
106
116
  skills: skillShas,
@@ -110,6 +120,8 @@ export function bodyOf(input) {
110
120
  ...(input.prompts !== undefined ? { prompts: structuredClone(input.prompts) } : {}),
111
121
  ...host,
112
122
  ...(input.learning !== undefined ? { learning: input.learning } : {}),
123
+ // The JSON Schema its final answer's structured part meets (definition.output_schema): a completed run's result.output.
124
+ ...(input.outputSchema !== undefined ? { outputSchema: structuredClone(input.outputSchema) } : {}),
113
125
  // The agent's unattended policy (PR #2003): the runner's gate reads it from the revision body at claim (`unattended`
114
126
  // below: "never" alone is kept).
115
127
  ...capped,
@@ -1,4 +1,4 @@
1
- export { AgentArchived, CommandTaken, endedReason, ExternalBodyConflict, FINAL_STATES, Fenced, MCP_REFRESH_CALL_MS, MCP_REFRESH_LEASE_MS, RunFinal, SchemaVersionUnknown, SIGN_IN_TOMBSTONES_KEPT, SignInHandedTo, SignInMissing, StoreBusy, StoreClosed, StoreConstraint, StoreDeadline, StoreFromEarlierVersion, StoreLaunchMissing, StoreOwned, StoreWorkerLost, STORE_WRITE_DEADLINE_MS, TriggerFull } from "./store.js";
1
+ export { AgentArchived, CommandTaken, endedReason, ExternalBodyConflict, FINAL_STATES, Fenced, MCP_REFRESH_CALL_MS, MCP_REFRESH_LEASE_MS, RevisionMoved, RunFinal, SchemaVersionUnknown, SignInHandedTo, SignInMissing, StoreBusy, StoreClosed, StoreConstraint, StoreDeadline, StoreFromEarlierVersion, StoreLaunchMissing, StoreOwned, StoreWorkerLost, STORE_WRITE_DEADLINE_MS, TriggerFull } from "./store.js";
2
2
  export type { ConstraintRule, AgentRow, Agents, AlsoRow, ChannelPost, Claim, Command, ComputerLedger, ComputerLedgerRow, Firing, FiringChange, FiringRow, FiringStatus, FiringStreak, Journal, Live, LiveRow, Mcp, McpCredentialMark, McpOauth, McpOauthPendingRow, McpPinRow, McpServerRow, McpServerWrite, NewFiring, NewRevision, NewTrigger, ReleasedState, RevisionRow, RunPatch, RunRow, Runs, RunState, SealedKeyRow, SealedKeys, SealedPlane, SealedSecretRow, SealedSecrets, SettingRow, Settings, Staged, StagedTake, Store, StoreRole, TemplatePackage, Templates, TriggerDef, TriggerPatch, TriggerRow, Triggers, TriggerScope, TriggerSettingRow, TriggerSettings, ImportedFrom, ImportSource, ImportRunInput, JournalReads, RunOrigin, RunOutcome, RunLaunchInput, RunLaunchRow, Learning, LearningProposal, LiveViewerRow, LiveViewers, SignIns, SignInRow, SignInTombstoneRow, UpdatedRun, ViewerKind, } from "./store.js";
3
3
  export { aadOf, type McpCredential, type OpenedMcpCredential, openMcpCredential, sealColumn, type SealedAt, sealedAt, sealMcpCredential, unsealColumn } from "./seal.js";
4
4
  export { AgentBodyInvalid, type AgenticBody, bodyOf, canonical, isObject, isSkillPath, type PromptVariant, type RevisionBodyInput, type RevisionComputer, type RevisionPlace, sha256, type ToolSettings, type WorkflowBody, } from "./agent-body.js";
@@ -11,7 +11,7 @@ export { Connection, DEFAULT_TRANSACTION_DEADLINE_MS, type SqliteDatabase, type
11
11
  export { cleanText, type Dialect, SQLITE } from "./dialect.js";
12
12
  export { DEFAULT_STORE_POOL_SIZE, MAX_STORE_POOL_SIZE, openStore, type OpenStoreOptions, storePlace, storePoolSize, storeTarget, type StoreTarget } from "./open.js";
13
13
  export { CLOCK_WARN_MS, DEFAULT_SCHEMA, openPostgresStore, type PostgresStoreOptions, postgresWhere } from "./postgres/store.js";
14
- export { LEASE_DEADLINE_MS, PgConnection, SCHEMA_NAME, STORE_CONNECT_TIMEOUT_MS, Unanswered } from "./postgres/connection.js";
14
+ export { LEASE_DEADLINE_MS, OWNER_WAIT_MS, PgConnection, SCHEMA_NAME, STORE_CONNECT_TIMEOUT_MS, Unanswered } from "./postgres/connection.js";
15
15
  export { dropPostgresSchema, migrate, migrationsIn, versionOf as postgresVersionOf } from "./postgres/migrate.js";
16
16
  export { applyRunPatch, RUN_COLUMNS, runOf, type RunRecord } from "./sqlite/run-patch.js";
17
17
  export { readLaunch, writeLaunch } from "./sqlite/run-launch.js";
@@ -1,5 +1,5 @@
1
1
  // The one store (design 2.1), for the cutover: nothing on main imports it until then.
2
- export { AgentArchived, CommandTaken, endedReason, ExternalBodyConflict, FINAL_STATES, Fenced, MCP_REFRESH_CALL_MS, MCP_REFRESH_LEASE_MS, RunFinal, SchemaVersionUnknown, SIGN_IN_TOMBSTONES_KEPT, SignInHandedTo, SignInMissing, StoreBusy, StoreClosed, StoreConstraint, StoreDeadline, StoreFromEarlierVersion, StoreLaunchMissing, StoreOwned, StoreWorkerLost, STORE_WRITE_DEADLINE_MS, TriggerFull } from "./store.js";
2
+ export { AgentArchived, CommandTaken, endedReason, ExternalBodyConflict, FINAL_STATES, Fenced, MCP_REFRESH_CALL_MS, MCP_REFRESH_LEASE_MS, RevisionMoved, RunFinal, SchemaVersionUnknown, SignInHandedTo, SignInMissing, StoreBusy, StoreClosed, StoreConstraint, StoreDeadline, StoreFromEarlierVersion, StoreLaunchMissing, StoreOwned, StoreWorkerLost, STORE_WRITE_DEADLINE_MS, TriggerFull } from "./store.js";
3
3
  export { aadOf, openMcpCredential, sealColumn, sealedAt, sealMcpCredential, unsealColumn } from "./seal.js";
4
4
  export { AgentBodyInvalid, bodyOf, canonical, isObject, isSkillPath, sha256, } from "./agent-body.js";
5
5
  export { checkPrompts, OTHER_OPTION, PromptsInvalid } from "./prompts.js";
@@ -11,7 +11,7 @@ export { Connection, DEFAULT_TRANSACTION_DEADLINE_MS } from "./sqlite/connection
11
11
  export { cleanText, SQLITE } from "./dialect.js";
12
12
  export { DEFAULT_STORE_POOL_SIZE, MAX_STORE_POOL_SIZE, openStore, storePlace, storePoolSize, storeTarget } from "./open.js";
13
13
  export { CLOCK_WARN_MS, DEFAULT_SCHEMA, openPostgresStore, postgresWhere } from "./postgres/store.js";
14
- export { LEASE_DEADLINE_MS, PgConnection, SCHEMA_NAME, STORE_CONNECT_TIMEOUT_MS, Unanswered } from "./postgres/connection.js";
14
+ export { LEASE_DEADLINE_MS, OWNER_WAIT_MS, PgConnection, SCHEMA_NAME, STORE_CONNECT_TIMEOUT_MS, Unanswered } from "./postgres/connection.js";
15
15
  export { dropPostgresSchema, migrate, migrationsIn, versionOf as postgresVersionOf } from "./postgres/migrate.js";
16
16
  export { applyRunPatch, RUN_COLUMNS, runOf } from "./sqlite/run-patch.js";
17
17
  export { readLaunch, writeLaunch } from "./sqlite/run-launch.js";
@@ -1,4 +1,4 @@
1
- import type { Store, StoreRole } from "./store.js";
1
+ import type { Store, StoreOwned, StoreRole } from "./store.js";
2
2
  /** Where a store is: SQLite's file in a data directory, or a schema on a Postgres. */
3
3
  export type StoreTarget = {
4
4
  readonly kind: "sqlite";
@@ -36,9 +36,12 @@ export interface OpenStoreOptions {
36
36
  readonly url?: string;
37
37
  /** The environment AGENTRUN_STORE_SCHEMA and AGENTRUN_STORE_POOL_SIZE are read from (process.env). Neither is a secret. */
38
38
  readonly env?: NodeJS.ProcessEnv;
39
- /** Told what a person should know at the open (a runner's clock far from Postgres's). */
39
+ /** Told what a person should know at the open (a runner's clock far from Postgres's; a server waiting for another to
40
+ * let the Postgres schema go). */
40
41
  readonly warn?: (message: string) => void;
42
+ /** A server's, on Postgres: told when its owner lock is lost for good (PostgresStoreOptions.onOwnerLost). */
43
+ readonly onOwnerLost?: (error: StoreOwned) => void;
41
44
  }
42
45
  /** Opens the store `options` names (storeTarget): the server's and the runner's one way in. On Postgres its pool holds at
43
46
  * most storePoolSize(env) connections; a pool size that is no size is refused on either store. */
44
- export declare function openStore({ dataDir, role, now, url, env, warn }: OpenStoreOptions): Promise<Store>;
47
+ export declare function openStore({ dataDir, role, now, url, env, warn, onOwnerLost }: OpenStoreOptions): Promise<Store>;
@@ -41,10 +41,10 @@ export function storePlace(target) {
41
41
  }
42
42
  /** Opens the store `options` names (storeTarget): the server's and the runner's one way in. On Postgres its pool holds at
43
43
  * most storePoolSize(env) connections; a pool size that is no size is refused on either store. */
44
- export async function openStore({ dataDir, role = "server", now, url, env = process.env, warn }) {
44
+ export async function openStore({ dataDir, role = "server", now, url, env = process.env, warn, onOwnerLost }) {
45
45
  const target = storeTarget(dataDir, env, url ?? storeUrl());
46
46
  const poolSize = storePoolSize(env);
47
47
  if (target.kind === "sqlite")
48
48
  return openSqliteStore({ dataDir, role, ...(now ? { now } : {}) });
49
- return openPostgresStore({ url: target.url, schema: target.schema, role, poolSize, ...(now ? { now } : {}), ...(warn ? { warn } : {}) });
49
+ return openPostgresStore({ url: target.url, schema: target.schema, role, poolSize, ...(now ? { now } : {}), ...(warn ? { warn } : {}), ...(onOwnerLost ? { onOwnerLost } : {}) });
50
50
  }
@@ -1,4 +1,5 @@
1
1
  import pg from "pg";
2
+ import { StoreOwned } from "../store.js";
2
3
  import { type SqliteValue, type Statement, type StatementResult, type StoreConnection, type TransactionOptions, type Tx } from "../sqlite/connection.js";
3
4
  import type { Dialect } from "../dialect.js";
4
5
  /** Which store this is, as two opens of the same data agree on it (StoreConnection.where): "postgres:" and the URL's host
@@ -10,8 +11,19 @@ export interface PgConnectionOptions {
10
11
  /** postgres:// or postgresql:// URL. Never printed: it may carry a password. */
11
12
  readonly url: string;
12
13
  readonly schema: string;
13
- /** Take the owner lock (a server): StoreOwned when another server holds the schema. */
14
+ /** Take the owner lock (a server): waited for while another server holds the schema (ownerWaitMs), StoreOwned past it. */
14
15
  readonly owner?: boolean;
16
+ /** How long a server waits for the owner lock another server holds, at its open and to take its own back once its
17
+ * lock's connection is lost (OWNER_WAIT_MS by default; 0 refuses at once). */
18
+ readonly ownerWaitMs?: number;
19
+ /** Told once, in words, when the open waits for another server to let the schema go (a deploy's old server stopping). */
20
+ readonly onOwnerWait?: (message: string) => void;
21
+ /** Told when this server's owner lock is lost for good (another server took the schema, or it could not be taken back
22
+ * within ownerWaitMs): every call is refused from then, and the process should exit so its platform restarts it. */
23
+ readonly onOwnerLost?: (error: StoreOwned) => void;
24
+ /** Asked on the owner connection each time the lock is taken back: why the schema is not one this build serves (a newer
25
+ * server migrated it while the lock was not held), or undefined. A reason gives the lock up for good (onOwnerLost). */
26
+ readonly ownerCheck?: (client: pg.Client) => Promise<string | undefined>;
15
27
  /** How long a statement waits for another writer's lock before StoreBusy. */
16
28
  readonly busyTimeoutMs?: number;
17
29
  /** Most clients open at once. */
@@ -41,6 +53,10 @@ export declare const LEASE_DEADLINE_MS = 8000;
41
53
  export declare class Unanswered extends Error {
42
54
  constructor(what: string, ms: number);
43
55
  }
56
+ /** How long a server waits for the owner lock another server holds before it gives up (StoreOwned), in ms, at its open
57
+ * and to take its own back after its lock's connection is lost: a deploy's new server waits out the old one's drain
58
+ * (a runner's 35 s graceful stop, the server's own) instead of exiting, and a lost lock is never a 503 forever. */
59
+ export declare const OWNER_WAIT_MS = 120000;
44
60
  export declare function numberParams(sql: string): string;
45
61
  export declare class PgConnection implements StoreConnection {
46
62
  #private;
@@ -50,7 +66,7 @@ export declare class PgConnection implements StoreConnection {
50
66
  readonly where: string;
51
67
  private constructor();
52
68
  /** The pool on `url` in `schema`, and (owner) the owner lock: StoreOwned when another server holds the schema. */
53
- static open({ url, schema, owner, busyTimeoutMs, poolSize, testClock, connectTimeoutMs }: PgConnectionOptions): Promise<PgConnection>;
69
+ static open({ url, schema, owner, busyTimeoutMs, poolSize, testClock, connectTimeoutMs, ownerWaitMs, onOwnerWait, onOwnerLost, ownerCheck }: PgConnectionOptions): Promise<PgConnection>;
54
70
  get<T extends object>(sql: string, ...params: SqliteValue[]): Promise<T | undefined>;
55
71
  all<T extends object>(sql: string, ...params: SqliteValue[]): Promise<T[]>;
56
72
  /** One statement on its own (autocommit), its changes counted: the shared code's run outside a transaction. */