@parcha/agentrun-serve 0.1.0-beta.43 → 0.1.0-beta.45

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 (388) hide show
  1. package/CHANGELOG.md +231 -0
  2. package/README.md +580 -320
  3. package/dist/acp-package.d.ts +28 -0
  4. package/dist/acp-package.js +23 -0
  5. package/dist/adapter-facts.d.ts +8 -1
  6. package/dist/adapter-facts.js +9 -1
  7. package/dist/adapters.d.ts +5 -0
  8. package/dist/adapters.js +36 -3
  9. package/dist/agent-delete.d.ts +50 -0
  10. package/dist/agent-delete.js +125 -0
  11. package/dist/agents-store.d.ts +9 -3
  12. package/dist/agents-store.js +22 -8
  13. package/dist/agents.d.ts +5 -1
  14. package/dist/agents.js +8 -4
  15. package/dist/api-only.d.ts +8 -3
  16. package/dist/api-only.js +10 -4
  17. package/dist/archil-routes.d.ts +5 -1
  18. package/dist/archil-routes.js +57 -2
  19. package/dist/browser-wait-ended.d.ts +2 -0
  20. package/dist/browser-wait-ended.js +2 -0
  21. package/dist/calendar/ics-faux.d.ts +3 -1
  22. package/dist/calendar/ics-faux.js +12 -2
  23. package/dist/calendar/tools.js +5 -2
  24. package/dist/chatgpt-plan.js +3 -1
  25. package/dist/claude-login.d.ts +135 -0
  26. package/dist/claude-login.js +244 -0
  27. package/dist/cli.js +92 -22
  28. package/dist/composio-preset.d.ts +4 -3
  29. package/dist/composio-preset.js +81 -11
  30. package/dist/composio-triggers.d.ts +34 -2
  31. package/dist/composio-triggers.js +261 -31
  32. package/dist/computer-attach.d.ts +40 -5
  33. package/dist/computer-attach.js +130 -15
  34. package/dist/computer-keys.d.ts +3 -0
  35. package/dist/computer-keys.js +7 -1
  36. package/dist/computer-live.js +3 -2
  37. package/dist/computer-lost.d.ts +11 -0
  38. package/dist/computer-lost.js +19 -0
  39. package/dist/computer-record.d.ts +10 -2
  40. package/dist/computer-record.js +50 -18
  41. package/dist/computer-setting.d.ts +1 -0
  42. package/dist/computer-setting.js +2 -2
  43. package/dist/computers.d.ts +21 -10
  44. package/dist/computers.js +39 -28
  45. package/dist/console/assets/index-3O2Yl6hZ.js +701 -0
  46. package/dist/console/assets/index-DaFsZuzQ.css +1 -0
  47. package/dist/console/index.html +2 -2
  48. package/dist/decisions.d.ts +1 -1
  49. package/dist/dial-relay.d.ts +29 -0
  50. package/dist/dial-relay.js +94 -0
  51. package/dist/email/tools.js +10 -5
  52. package/dist/env-proxy.d.ts +2 -0
  53. package/dist/env-proxy.js +35 -0
  54. package/dist/errors.d.ts +4 -1
  55. package/dist/errors.js +10 -4
  56. package/dist/faux-computers.d.ts +8 -2
  57. package/dist/faux-computers.js +83 -6
  58. package/dist/harness-archive.d.ts +67 -0
  59. package/dist/harness-archive.js +177 -0
  60. package/dist/harness-goose.d.ts +34 -0
  61. package/dist/harness-goose.js +87 -0
  62. package/dist/harness-install.d.ts +21 -0
  63. package/dist/harness-install.js +24 -11
  64. package/dist/harness-opencode/adapter.js +1 -1
  65. package/dist/harness-table.d.ts +59 -3
  66. package/dist/harness-table.js +119 -14
  67. package/dist/harness.d.ts +17 -1
  68. package/dist/harness.js +22 -11
  69. package/dist/host.d.ts +12 -10
  70. package/dist/host.js +19 -16
  71. package/dist/import-worker.d.ts +3 -0
  72. package/dist/import-worker.js +7 -5
  73. package/dist/import.d.ts +22 -1
  74. package/dist/import.js +141 -28
  75. package/dist/key-check.js +3 -0
  76. package/dist/learn/audit.d.ts +6 -6
  77. package/dist/learn/audit.js +3 -7
  78. package/dist/learn/check.d.ts +26 -89
  79. package/dist/learn/check.js +58 -336
  80. package/dist/learn/commit.d.ts +63 -90
  81. package/dist/learn/commit.js +124 -316
  82. package/dist/learn/compile.d.ts +53 -50
  83. package/dist/learn/compile.js +88 -103
  84. package/dist/learn/corrections.d.ts +13 -0
  85. package/dist/learn/corrections.js +23 -0
  86. package/dist/learn/delete.d.ts +17 -0
  87. package/dist/learn/delete.js +42 -0
  88. package/dist/learn/folder.d.ts +35 -47
  89. package/dist/learn/folder.js +118 -134
  90. package/dist/learn/index.d.ts +3 -5
  91. package/dist/learn/index.js +6 -9
  92. package/dist/learn/learning.sh +45 -15
  93. package/dist/learn/promote.d.ts +20 -2
  94. package/dist/learn/promote.js +17 -4
  95. package/dist/learn/{skills.d.ts → workflow-draft.d.ts} +34 -38
  96. package/dist/learn/{skills.js → workflow-draft.js} +65 -59
  97. package/dist/learn/workflow-nodes.d.ts +22 -1
  98. package/dist/learn/workflow-nodes.js +29 -10
  99. package/dist/learned-workflow.js +2 -2
  100. package/dist/learning-cost.d.ts +127 -13
  101. package/dist/learning-cost.js +142 -10
  102. package/dist/learning-routes.d.ts +99 -170
  103. package/dist/learning-routes.js +199 -420
  104. package/dist/learning-run.d.ts +19 -40
  105. package/dist/learning-run.js +23 -93
  106. package/dist/learning-setting.d.ts +4 -4
  107. package/dist/learning-setting.js +6 -6
  108. package/dist/learning-words.d.ts +28 -74
  109. package/dist/learning-words.js +64 -162
  110. package/dist/learning.d.ts +62 -393
  111. package/dist/learning.js +101 -651
  112. package/dist/listen-first.d.ts +30 -0
  113. package/dist/listen-first.js +115 -0
  114. package/dist/live-reach.d.ts +25 -2
  115. package/dist/live-reach.js +46 -4
  116. package/dist/llms.txt +2 -1
  117. package/dist/local-models.d.ts +3 -11
  118. package/dist/local-models.js +5 -6
  119. package/dist/mcp-servers-store.d.ts +16 -16
  120. package/dist/model-form.js +6 -5
  121. package/dist/model.d.ts +12 -4
  122. package/dist/model.js +41 -16
  123. package/dist/native/binding.js +1 -1
  124. package/dist/native/connection.js +1 -1
  125. package/dist/native/discovery.js +1 -1
  126. package/dist/native/instructions.d.ts +3 -0
  127. package/dist/native/instructions.js +5 -3
  128. package/dist/native/remote-worker-bridge.js +9 -43
  129. package/dist/native/remote.d.ts +8 -15
  130. package/dist/native/remote.js +3 -3
  131. package/dist/native/schema.js +1 -1
  132. package/dist/native/types.d.ts +2 -2
  133. package/dist/openapi.js +375 -347
  134. package/dist/owner.d.ts +8 -0
  135. package/dist/owner.js +11 -0
  136. package/dist/paid-calls.d.ts +14 -0
  137. package/dist/paid-calls.js +31 -1
  138. package/dist/particle-provider.d.ts +11 -0
  139. package/dist/particle-provider.js +135 -0
  140. package/dist/place.d.ts +8 -3
  141. package/dist/place.js +13 -9
  142. package/dist/port-models.d.ts +12 -4
  143. package/dist/port-models.js +28 -11
  144. package/dist/print.d.ts +27 -0
  145. package/dist/print.js +21 -0
  146. package/dist/provider.d.ts +7 -0
  147. package/dist/provider.js +30 -2
  148. package/dist/reflect-range.js +2 -3
  149. package/dist/run-launch.d.ts +14 -28
  150. package/dist/run-launch.js +9 -12
  151. package/dist/run-learning-served.d.ts +16 -90
  152. package/dist/run-listing.d.ts +34 -0
  153. package/dist/run-listing.js +128 -0
  154. package/dist/run-model-key.d.ts +64 -0
  155. package/dist/run-model-key.js +147 -0
  156. package/dist/run-timeline-served.js +5 -3
  157. package/dist/run-trace.d.ts +97 -0
  158. package/dist/run-trace.js +253 -0
  159. package/dist/run-view.d.ts +15 -0
  160. package/dist/run-view.js +9 -0
  161. package/dist/runnable.js +2 -1
  162. package/dist/runner/adapter-loop.d.ts +14 -6
  163. package/dist/runner/adapter-loop.js +25 -14
  164. package/dist/runner/adapter-run-spec.d.ts +22 -7
  165. package/dist/runner/adapter-run-spec.js +130 -77
  166. package/dist/runner/adapters/index.d.ts +4 -2
  167. package/dist/runner/adapters/index.js +35 -4
  168. package/dist/runner/adapters/pi.d.ts +4 -12
  169. package/dist/runner/adapters/pi.js +2 -2
  170. package/dist/runner/audit.d.ts +5 -1
  171. package/dist/runner/audit.js +31 -12
  172. package/dist/runner/beside.d.ts +7 -2
  173. package/dist/runner/beside.js +41 -9
  174. package/dist/runner/claim-secrets.d.ts +66 -1
  175. package/dist/runner/claim-secrets.js +136 -3
  176. package/dist/runner/cli-run-spec.d.ts +2 -1
  177. package/dist/runner/cli-run-spec.js +82 -59
  178. package/dist/runner/commands.d.ts +3 -6
  179. package/dist/runner/conformance/harness.d.ts +6 -0
  180. package/dist/runner/conformance/harness.js +16 -5
  181. package/dist/runner/dispatch.d.ts +2 -2
  182. package/dist/runner/end-of-run.d.ts +6 -14
  183. package/dist/runner/end-of-run.js +8 -33
  184. package/dist/runner/feedback-round.d.ts +5 -4
  185. package/dist/runner/feedback-round.js +14 -10
  186. package/dist/runner/github-app.js +3 -1
  187. package/dist/runner/harness-loops.d.ts +0 -8
  188. package/dist/runner/harness-loops.js +30 -56
  189. package/dist/runner/held.d.ts +170 -0
  190. package/dist/runner/held.js +57 -0
  191. package/dist/runner/journal-kinds.d.ts +7 -3
  192. package/dist/runner/journal-kinds.js +2 -3
  193. package/dist/runner/learned-first.d.ts +40 -0
  194. package/dist/runner/learned-first.js +32 -0
  195. package/dist/runner/learning-end.d.ts +77 -66
  196. package/dist/runner/learning-end.js +250 -299
  197. package/dist/runner/learning-seed.d.ts +15 -33
  198. package/dist/runner/learning-seed.js +24 -45
  199. package/dist/runner/loop-contract.d.ts +8 -3
  200. package/dist/runner/loop-contract.js +4 -0
  201. package/dist/runner/loop.js +6 -2
  202. package/dist/runner/main.d.ts +18 -9
  203. package/dist/runner/main.js +82 -22
  204. package/dist/runner/mcp-run.d.ts +11 -0
  205. package/dist/runner/mcp-run.js +67 -0
  206. package/dist/runner/memory-claim.d.ts +14 -6
  207. package/dist/runner/memory-claim.js +18 -9
  208. package/dist/runner/model-route.d.ts +7 -4
  209. package/dist/runner/model-route.js +22 -10
  210. package/dist/runner/native-loop.d.ts +0 -7
  211. package/dist/runner/native-loop.js +9 -101
  212. package/dist/runner/promotion.d.ts +13 -6
  213. package/dist/runner/promotion.js +63 -17
  214. package/dist/runner/reflect-hook.d.ts +64 -91
  215. package/dist/runner/reflect-hook.js +112 -206
  216. package/dist/runner/run-channel.d.ts +43 -0
  217. package/dist/runner/run-channel.js +467 -0
  218. package/dist/runner/run-child-host.d.ts +169 -0
  219. package/dist/runner/run-child-host.js +1222 -0
  220. package/dist/runner/run-child.d.ts +1 -0
  221. package/dist/runner/run-child.js +254 -0
  222. package/dist/runner/run-errors.d.ts +2 -0
  223. package/dist/runner/run-errors.js +20 -0
  224. package/dist/runner/runner.js +58 -9
  225. package/dist/runner/sdk-ask.d.ts +78 -0
  226. package/dist/runner/sdk-ask.js +158 -0
  227. package/dist/runner/sdk-loop.d.ts +2 -4
  228. package/dist/runner/sdk-loop.js +29 -49
  229. package/dist/runner/store-secrets.d.ts +5 -3
  230. package/dist/runner/store-secrets.js +14 -6
  231. package/dist/runner/workflow-first.d.ts +5 -0
  232. package/dist/runner/workflow-first.js +4 -0
  233. package/dist/runner/workflow-spec.js +17 -4
  234. package/dist/runs-over-store.d.ts +21 -32
  235. package/dist/runs-over-store.js +44 -41
  236. package/dist/sdk/runs.d.ts +6 -11
  237. package/dist/sdk/runs.js +20 -41
  238. package/dist/sdk/schema.js +3 -4
  239. package/dist/sdk/workflows.d.ts +1 -1
  240. package/dist/seal-key.d.ts +5 -0
  241. package/dist/seal-key.js +7 -0
  242. package/dist/secrets.d.ts +3 -0
  243. package/dist/secrets.js +16 -3
  244. package/dist/server.d.ts +119 -83
  245. package/dist/server.js +1121 -419
  246. package/dist/sign-ins-store.d.ts +8 -0
  247. package/dist/sign-ins-store.js +36 -1
  248. package/dist/skills.js +1 -1
  249. package/dist/store/index.d.ts +3 -3
  250. package/dist/store/index.js +2 -2
  251. package/dist/store/journal/storage.js +3 -0
  252. package/dist/store/postgres/migrations/0017_run_listing.sql +83 -0
  253. package/dist/store/postgres/migrations/0018_trigger_template.sql +6 -0
  254. package/dist/store/postgres/migrations/0019_runner_relays.sql +28 -0
  255. package/dist/store/schema.d.ts +53 -4
  256. package/dist/store/schema.js +137 -6
  257. package/dist/store/seal.d.ts +20 -2
  258. package/dist/store/seal.js +24 -8
  259. package/dist/store/sqlite/connection.d.ts +2 -0
  260. package/dist/store/sqlite/connection.js +3 -1
  261. package/dist/store/sqlite/run-launch.d.ts +4 -1
  262. package/dist/store/sqlite/run-launch.js +12 -0
  263. package/dist/store/sqlite/run-patch.d.ts +0 -17
  264. package/dist/store/sqlite/run-patch.js +4 -33
  265. package/dist/store/sqlite/store.d.ts +3 -2
  266. package/dist/store/sqlite/store.js +360 -75
  267. package/dist/store/sqlite/worker.js +25 -0
  268. package/dist/store/store.d.ts +231 -39
  269. package/dist/store/store.js +25 -3
  270. package/dist/store-reads/analytics.js +11 -1
  271. package/dist/store-reads/learning.d.ts +131 -194
  272. package/dist/store-reads/learning.js +292 -301
  273. package/dist/store-reads/loop.d.ts +0 -1
  274. package/dist/store-reads/loop.js +1 -1
  275. package/dist/store-reads/stats.js +13 -3
  276. package/dist/store-view.d.ts +34 -2
  277. package/dist/store-view.js +108 -41
  278. package/dist/telemetry.d.ts +59 -0
  279. package/dist/telemetry.js +153 -0
  280. package/dist/template-eval.d.ts +3 -6
  281. package/dist/template-eval.js +22 -36
  282. package/dist/templates.d.ts +2 -1
  283. package/dist/templates.js +6 -3
  284. package/dist/timeline/index.d.ts +1 -1
  285. package/dist/timeline/index.js +1 -1
  286. package/dist/timeline/timeline.d.ts +5 -1
  287. package/dist/timeline/timeline.js +16 -0
  288. package/dist/tool-gate.d.ts +0 -7
  289. package/dist/tool-gate.js +1 -15
  290. package/dist/tool-keys-store.d.ts +1 -1
  291. package/dist/tool-keys.d.ts +6 -4
  292. package/dist/tool-keys.js +12 -6
  293. package/dist/tool-plane.d.ts +12 -12
  294. package/dist/tools.d.ts +13 -13
  295. package/dist/tools.js +29 -9
  296. package/dist/trigger-adapter.d.ts +3 -0
  297. package/dist/trigger-adapters.d.ts +4 -0
  298. package/dist/trigger-adapters.js +13 -0
  299. package/dist/trigger-composio.d.ts +58 -1
  300. package/dist/trigger-composio.js +160 -6
  301. package/dist/triggers.d.ts +64 -5
  302. package/dist/triggers.js +141 -17
  303. package/dist/validate.d.ts +11 -7
  304. package/dist/validate.js +9 -8
  305. package/dist/webhooks.d.ts +4 -1
  306. package/dist/webhooks.js +11 -4
  307. package/dist/workspace/agent-computer.d.ts +2 -0
  308. package/dist/workspace/agent-computer.js +2 -0
  309. package/dist/workspace/archil-claim.d.ts +7 -0
  310. package/dist/workspace/archil-claim.js +29 -0
  311. package/dist/workspace/archil.d.ts +9 -1
  312. package/dist/workspace/archil.js +165 -3
  313. package/dist/workspace/attach.d.ts +3 -1
  314. package/dist/workspace/attach.js +2 -0
  315. package/dist/workspace/attached-computers.d.ts +16 -5
  316. package/dist/workspace/attached-computers.js +25 -9
  317. package/dist/workspace/computer-deps.js +1 -1
  318. package/dist/workspace/computer-for-claim.d.ts +22 -8
  319. package/dist/workspace/computer-for-claim.js +339 -46
  320. package/dist/workspace/computer-hold.js +2 -1
  321. package/dist/workspace/computer-kept.d.ts +11 -1
  322. package/dist/workspace/computer-kept.js +24 -3
  323. package/dist/workspace/resolve-computer.d.ts +41 -21
  324. package/dist/workspace/resolve-computer.js +172 -64
  325. package/dist/workspace/revision-skills.d.ts +1 -2
  326. package/dist/workspace/revision-skills.js +3 -4
  327. package/dist/workspace/run-workspace.d.ts +1 -1
  328. package/dist/workspace/run-workspace.js +5 -0
  329. package/dist/workspace/synced-folder.d.ts +85 -0
  330. package/dist/workspace/synced-folder.js +230 -0
  331. package/dist/workspace/workspace.d.ts +4 -0
  332. package/launcher/agentrun-serve +1 -1
  333. package/package.json +10 -9
  334. package/templates/README.md +7 -7
  335. package/templates/inbound-lead/agent.md +3 -3
  336. package/templates/inbound-lead/evals/learned-correction/case.yaml +3 -3
  337. package/templates/inbound-lead/evals/learned-correction/fixtures/corrections.md +1 -0
  338. package/templates/inbound-lead/evals/learned-correction/graders/applies-correction.md +22 -0
  339. package/templates/inbound-lead/evals/learned-correction/graders/learned-origin.md +1 -1
  340. package/templates/inbound-lead/evals/learned-correction/prompt.md +1 -1
  341. package/templates/inbound-lead/lead.schema.json +6 -5
  342. package/templates/inbound-lead/rules/RUBRIC.md +4 -4
  343. package/templates/inbound-lead/skills/lead/SKILL.md +4 -4
  344. package/templates/market-monitor/evals/learned-preference/case.yaml +4 -4
  345. package/templates/market-monitor/evals/learned-preference/fixtures/corrections.md +1 -0
  346. package/templates/market-monitor/evals/learned-preference/graders/omits-junior-post.md +3 -3
  347. package/templates/market-monitor/evals/learned-preference/prompt.md +1 -1
  348. package/templates/release-notes/evals/learned-style/case.yaml +4 -4
  349. package/templates/release-notes/evals/learned-style/fixtures/corrections.md +1 -0
  350. package/templates/release-notes/evals/learned-style/graders/same-changes.md +2 -2
  351. package/templates/release-notes/evals/learned-style/prompt.md +1 -1
  352. package/dist/console/assets/index-BrcDSBD8.css +0 -1
  353. package/dist/console/assets/index-Bz6IWncl.js +0 -711
  354. package/dist/learn/grade.d.ts +0 -138
  355. package/dist/learn/grade.js +0 -682
  356. package/dist/learn/notes.d.ts +0 -81
  357. package/dist/learn/notes.js +0 -178
  358. package/dist/learn/reflect.d.ts +0 -77
  359. package/dist/learn/reflect.js +0 -228
  360. package/dist/learn/relevance.d.ts +0 -24
  361. package/dist/learn/relevance.js +0 -91
  362. package/dist/learn/seed-check.d.ts +0 -74
  363. package/dist/learn/seed-check.js +0 -103
  364. package/dist/learning-batch.d.ts +0 -291
  365. package/dist/learning-batch.js +0 -600
  366. package/dist/learning-evals.d.ts +0 -33
  367. package/dist/learning-evals.js +0 -98
  368. package/dist/native/context.d.ts +0 -6
  369. package/dist/native/context.js +0 -22
  370. package/dist/propose.d.ts +0 -52
  371. package/dist/propose.js +0 -224
  372. package/dist/runner/learning-ask.d.ts +0 -47
  373. package/dist/runner/learning-ask.js +0 -128
  374. package/dist/runner/learning-dispatch.d.ts +0 -45
  375. package/dist/runner/learning-dispatch.js +0 -99
  376. package/dist/runner/learning-factory.d.ts +0 -16
  377. package/dist/runner/learning-factory.js +0 -50
  378. package/dist/runner/learning-loop.d.ts +0 -273
  379. package/dist/runner/learning-loop.js +0 -521
  380. package/dist/usage.d.ts +0 -11
  381. package/dist/usage.js +0 -11
  382. package/templates/inbound-lead/evals/learned-correction/fixtures/learning/MEMORY.md +0 -1
  383. package/templates/inbound-lead/evals/learned-correction/fixtures/learning/no-agencies.md +0 -14
  384. package/templates/inbound-lead/evals/learned-correction/graders/applies-note.md +0 -21
  385. package/templates/market-monitor/evals/learned-preference/fixtures/learning/MEMORY.md +0 -1
  386. package/templates/market-monitor/evals/learned-preference/fixtures/learning/skip-junior-job-posts.md +0 -8
  387. package/templates/release-notes/evals/learned-style/fixtures/learning/MEMORY.md +0 -1
  388. package/templates/release-notes/evals/learned-style/fixtures/learning/say-agent-not-bot.md +0 -13
@@ -12,15 +12,21 @@
12
12
  // resuming and deleting follow on Composio once the change holds here, and so does the server turning a trigger off
13
13
  // itself (triggers.ts); what Composio could not do is said, with what to do by hand.
14
14
  // - One project's steps run one at a time (serial): a create's setup, its save here and its undo, a pause, a delete, a
15
- // rotate, the subscription's delete and the saved server's delete. Each reads the triggers holding what it would undo,
15
+ // rotate, the subscription's delete and the saved server's delete; a template update's removal (removedThere) deletes
16
+ // its trigger here in the same step, once Composio is done. Each reads the triggers holding what it would undo,
16
17
  // turn off or delete as they are then, so it never removes what another holds, a pause or resume sets the instance as
17
18
  // its triggers now stand, and a create re-reads its saved server before it saves, so no trigger outlives its server.
19
+ // - A config field named like a credential (trigger-composio.ts sealedConfigFields) is sealed at the create, each under
20
+ // its own scope of the same sealed settings (configScope), and the trigger keeps SEALED_MASK in its place, the field
21
+ // named in `sealed_config`: Composio's upsert alone gets the value. A PATCH that leaves it out or sends the mask keeps
22
+ // it; any other value is a change to the config, refused. The delete removes it. A trigger kept before this rule with
23
+ // its key in the clear is answered masked all the same (shownSource), and sealed at the next start (sealKept).
18
24
  // No public address (AGENTRUN_PUBLIC_URL): Composio can't reach this server, so making one is refused before Composio is
19
25
  // asked anything.
20
- import { createHash, randomBytes } from "node:crypto";
26
+ import { createHash, randomBytes, timingSafeEqual } from "node:crypto";
21
27
  import { ApiError, invalid } from "./errors.js";
22
28
  import { asking } from "./composio-preset.js";
23
- import { COMPOSIO_HOOK, COMPOSIO_SECRET, MOVE_FIELD } from "./trigger-composio.js";
29
+ import { COMPOSIO_HOOK, COMPOSIO_SECRET, CONFIG_SECRET, CONFIG_UNLISTED, configScope, configSecrets, MOVE_FIELD, SEALED_FIELD, SEALED_MASK, sealableValue, sealedConfigFields, sealedKept, sealedSchemaFields, shownSource } from "./trigger-composio.js";
24
30
  import { isObject } from "./validate.js";
25
31
  /** Where the owner does by hand what this server could not do on Composio. */
26
32
  const DASHBOARD = "https://platform.composio.dev";
@@ -34,6 +40,27 @@ const text = (value) => (typeof value === "string" ? value : "");
34
40
  const enc = encodeURIComponent;
35
41
  const newHook = () => `cph_${randomBytes(12).toString("hex")}`;
36
42
  const instanceOf = (source) => String(source.instance_id);
43
+ /** The config fields `source` keeps sealed (its sealed_config). */
44
+ const sealedOf = (source) => (Array.isArray(source[SEALED_FIELD]) ? source[SEALED_FIELD].filter((name) => typeof name === "string") : []);
45
+ /** The settings field a sealed config value is kept under: one the list of the server's secrets can hold (8 bytes or
46
+ * more, no whitespace), else the unlisted one. */
47
+ const configFieldFor = (value) => (!/\s/.test(value) && Buffer.byteLength(value, "utf8") >= 8 ? CONFIG_SECRET : CONFIG_UNLISTED);
48
+ /** The keys of a sealed_config name's place in the config: a top-level name as it is, a JSON Pointer's unescaped. */
49
+ const placeOf = (name) => (name.startsWith("/") ? name.slice(1).split("/").map((key) => key.replace(/~1/g, "/").replace(/~0/g, "~")) : [name]);
50
+ /** The value at `path` in `config` where it is still kept in the clear (a trigger an earlier server saved), as text. */
51
+ const clearAt = (config, path) => {
52
+ let node = config;
53
+ for (const key of path)
54
+ node = isObject(node) ? node[key] : Array.isArray(node) ? node[Number(key)] : undefined;
55
+ return (typeof node === "string" || typeof node === "number") && node !== SEALED_MASK ? String(node) : undefined;
56
+ };
57
+ /** Whether two secrets are equal, in time that does not depend on where they differ: each digested first, so two of
58
+ * different lengths compare as two equal-length buffers. */
59
+ const sameSecret = (a, b) => timingSafeEqual(createHash("sha256").update(a, "utf8").digest(), createHash("sha256").update(b, "utf8").digest());
60
+ /** `said` with each of `values` (sealed config values) put as the mask. */
61
+ /** An error's words for a log line: none with sealed config values (`values`) in play, as a quote of one may be in a form
62
+ * no match finds (JSON-escaped, encoded); its code alone then. */
63
+ const told = (error, values) => values.some(Boolean) ? `${error instanceof ApiError ? error.code : "error"} (its words are withheld: the config holds a sealed value)` : String(error?.message ?? error);
37
64
  /** Whether two JSON values are equal, an object's fields in any order. */
38
65
  function same(a, b) {
39
66
  if (a === b)
@@ -64,21 +91,43 @@ export class ComposioTriggers {
64
91
  async make(source, id, enabled, keep) {
65
92
  if (!this.deps.publicUrl)
66
93
  throw new ApiError("composio_no_public_url", "Composio can't reach this server: set its public URL first (AGENTRUN_PUBLIC_URL, the https address Composio sends events to), then make the trigger.");
67
- for (const field of ["instance_id", "hook"])
94
+ for (const field of ["instance_id", "hook", SEALED_FIELD])
68
95
  if (source[field] !== undefined)
69
96
  throw invalid([{ field: `source.${field}`, reason: "not_allowed", message: `${field} is set by this server when it makes the trigger on Composio: leave it out.` }]);
97
+ const config = source.config;
98
+ // A credential below the config's top level is refused: a create seals one as a top-level field alone (and Composio's
99
+ // trigger configs are flat), so none is kept here in the clear.
100
+ const deeper = configSecrets(config).filter((secret) => secret.path.length > 1);
101
+ if (deeper.length)
102
+ throw invalid(deeper.map((secret) => ({ field: `source.config.${secret.path.join(".")}`, reason: "not_allowed", message: `${secret.name} is a credential below the config's top level: this server seals a credential only as a top-level field of the config, so it can't keep this one. Give it as a top-level field, or leave it out.` })));
103
+ const named = sealedConfigFields(config);
104
+ const refuseMasked = (sealing) => {
105
+ const masked = sealing.filter((name) => config[name] === SEALED_MASK);
106
+ if (masked.length)
107
+ throw invalid(masked.map((name) => ({ field: `source.config.${name}`, reason: "invalid", message: `${name} is a credential: give its value. "${SEALED_MASK}" is what an answer shows in its place.` })));
108
+ };
109
+ refuseMasked(named);
70
110
  const server = String(source.server);
71
111
  const credential = await this.deps.credential(server, "field");
112
+ const event = String(source.event);
113
+ const missing = `Composio has no event ${event} for ${credential.toolkit}: pick one from the server's events.`;
72
114
  // Made, saved here, and undone when not saved, alone among the project's steps.
73
115
  return this.serial(credential.key, async () => {
74
- const ask = this.ask(credential, "nothing was saved");
116
+ // The event's schema first, a read: a field it marks as a credential (format: password, writeOnly) is sealed too,
117
+ // whatever its name (sealedSchemaFields).
118
+ const type = await this.ask(credential, "nothing was saved", named.map((name) => String(config[name])))(`reading ${event}'s config on Composio`, "GET", `/api/v3/triggers_types/${enc(event)}`, undefined, missing).catch((error) => {
119
+ throw onField(error, "source.event");
120
+ });
121
+ const sealing = [...new Set([...named, ...sealedSchemaFields(type.config).filter((name) => sealableValue(config[name]))])];
122
+ refuseMasked(sealing);
123
+ const values = sealing.map((name) => String(config[name]));
124
+ const ask = this.ask(credential, "nothing was saved", values);
75
125
  const undo = [];
76
126
  try {
77
127
  // The account first: a read, so a server not connected yet leaves nothing made on Composio.
78
128
  const account = await this.accountOf(ask, credential, server);
79
129
  const hook = await this.subscribe(ask, source[MOVE_FIELD] === true, undo);
80
- const event = String(source.event);
81
- const made = await ask(`turning on ${event} on Composio`, "POST", `/api/v3/trigger_instances/${enc(event)}/upsert`, { connected_account_id: account, user_id: credential.user, trigger_config: source.config }, `Composio has no event ${event} for ${credential.toolkit}: pick one from the server's events.`).catch((error) => {
130
+ const made = await ask(`turning on ${event} on Composio`, "POST", `/api/v3/trigger_instances/${enc(event)}/upsert`, { connected_account_id: account, user_id: credential.user, trigger_config: source.config }, missing).catch((error) => {
82
131
  throw onField(onField(error, "source.config"), "source.event");
83
132
  });
84
133
  const instance = text(made.trigger_id);
@@ -94,26 +143,73 @@ export class ComposioTriggers {
94
143
  const now = await this.deps.credential(server, "field");
95
144
  if (now.key !== credential.key)
96
145
  throw invalid([{ field: "source.server", reason: "invalid", message: `${server} was saved again with another Composio key while this trigger was being made: nothing was saved, make it again.` }]);
146
+ // Each credential of its config sealed, the trigger keeping the mask in its place: Composio's upsert above was the
147
+ // one place it went.
148
+ undo.push(async () => {
149
+ for (const name of sealing)
150
+ await this.deps.sealed.remove(configScope(id, name));
151
+ });
152
+ // A number is sealed as its decimal text; Composio got it, as a number, in the upsert above.
153
+ for (const name of sealing)
154
+ await this.deps.sealed.set(configScope(id, name), configFieldFor(String(config[name])), String(config[name]));
97
155
  const { [MOVE_FIELD]: _moved, ...kept } = source;
98
- return await keep({ ...kept, instance_id: instance, hook });
156
+ const shown = sealing.length ? { config: { ...config, ...Object.fromEntries(sealing.map((name) => [name, SEALED_MASK])) }, [SEALED_FIELD]: sealing } : {};
157
+ return await keep({ ...kept, ...shown, instance_id: instance, hook });
99
158
  }
100
159
  catch (error) {
101
160
  for (const step of undo.splice(0).reverse())
102
- await step().catch((undone) => this.deps.say({ condition: "composio_undo_failed", trigger: id, error: String(undone?.message ?? undone) }));
161
+ await step().catch((undone) => this.deps.say({ condition: "composio_undo_failed", trigger: id, error: told(undone, values) }));
103
162
  throw error;
104
163
  }
105
164
  });
106
165
  }
166
+ /** A source sent whole again for trigger `id` (`was`), as an apply with agent_id sends its package's, its credentials in
167
+ * the clear: each sealed field whose value it sends is the value sealed (compared in constant time) is left out, so the
168
+ * PATCH keeps it (patched); then patched's own check, so another value, or any other change to the config, is refused
169
+ * here, before the caller writes anything, in patched's words (none holds a value). The answer is the source to PATCH
170
+ * the trigger with: no sealed value is in it. */
171
+ resent(was, id, given) {
172
+ const config = isObject(given.config) ? structuredClone(given.config) : given.config;
173
+ if (isObject(config)) {
174
+ for (const name of sealedOf(shownSource(was))) {
175
+ const path = placeOf(name);
176
+ let node = config;
177
+ for (const key of path.slice(0, -1))
178
+ node = isObject(node) ? node[key] : undefined;
179
+ const last = path.at(-1);
180
+ if (!isObject(node))
181
+ continue;
182
+ const sent = node[last];
183
+ if (!(typeof sent === "string" || typeof sent === "number") || sent === SEALED_MASK)
184
+ continue;
185
+ const kept = this.deps.sealed.get(configScope(id, name), CONFIG_SECRET) ?? this.deps.sealed.get(configScope(id, name), CONFIG_UNLISTED) ?? clearAt(was.config, path);
186
+ if (kept !== undefined && sameSecret(String(sent), kept))
187
+ delete node[last];
188
+ }
189
+ }
190
+ const source = { ...given, config };
191
+ this.patched(was, source);
192
+ return source;
193
+ }
107
194
  patched(was, given) {
108
- const fixed = "A Composio trigger's server, event and config made its instance on Composio, so they stay: make a new trigger for another.";
195
+ const fixed = "A Composio trigger's server, event and config made its instance on Composio, so they stay: to change one (a sealed key too), delete the trigger and make a new one.";
109
196
  for (const field of ["server", "event", "instance_id", "hook"])
110
197
  if (given[field] !== undefined && given[field] !== was[field])
111
198
  throw invalid([{ field: `source.${field}`, reason: "not_allowed", message: fixed }]);
112
- if (!same(given.config, was.config))
199
+ // A sealed field left out, or sent as the mask an answer shows, keeps its value; any other value is a change. Read
200
+ // against the source as answered (shownSource), so one still kept in the clear compares as the answer showed it.
201
+ const shown = shownSource(was);
202
+ const sealed = sealedOf(shown);
203
+ const sent = given.config;
204
+ // At its own place: a top-level name, or a nested one's JSON Pointer (a trigger an earlier server kept).
205
+ const config = isObject(sent) && sealed.length ? sealedKept(sent, shown.config, sealed) : sent;
206
+ if (!same(config, shown.config))
113
207
  throw invalid([{ field: "source.config", reason: "not_allowed", message: fixed }]);
114
208
  if (given[MOVE_FIELD] !== undefined)
115
209
  throw invalid([{ field: `source.${MOVE_FIELD}`, reason: "not_allowed", message: `${MOVE_FIELD} is a create's alone.` }]);
116
- return { ...given, instance_id: was.instance_id, hook: was.hook };
210
+ const { [SEALED_FIELD]: _given, ...rest } = given;
211
+ const kept = sealedOf(was);
212
+ return { ...rest, config: was.config, ...(kept.length ? { [SEALED_FIELD]: kept } : {}), instance_id: was.instance_id, hook: was.hook };
117
213
  }
118
214
  async turned(source, id, on) {
119
215
  const instance = instanceOf(source);
@@ -127,7 +223,7 @@ export class ComposioTriggers {
127
223
  if (!holding.length)
128
224
  return;
129
225
  on = holding.some((h) => h.enabled);
130
- await this.ask(credential)(`turning the trigger instance ${on ? "on" : "off"}`, "PATCH", `/api/v3/trigger_instances/manage/${enc(instance)}`, { status: on ? "enable" : "disable" });
226
+ await this.ask(credential, "nothing was changed", this.sealedValues(holding))(`turning the trigger instance ${on ? "on" : "off"}`, "PATCH", `/api/v3/trigger_instances/manage/${enc(instance)}`, { status: on ? "enable" : "disable" });
131
227
  });
132
228
  return undefined;
133
229
  }
@@ -137,23 +233,51 @@ export class ComposioTriggers {
137
233
  }
138
234
  }
139
235
  async removed(source, id) {
236
+ // Its sealed config goes with it, whatever Composio says below; read first, so Composio's words about its instance are
237
+ // withheld (asking).
238
+ const values = this.sealedValues([{ id, source }]);
239
+ await this.forgotten(source, id);
240
+ return this.leftThere(source, id, values);
241
+ }
242
+ async removedThere(source, id, here) {
243
+ return this.leftThere(source, id, this.sealedValues([{ id, source }]), here);
244
+ }
245
+ async forgotten(source, id) {
246
+ for (const name of sealedOf(source))
247
+ await this.deps.sealed.remove(configScope(id, name)).catch((error) => this.deps.say({ condition: "composio_sealed_config_not_removed", trigger: id, field: name, error: String(error?.message ?? error) }));
248
+ }
249
+ /** The trigger `id`'s instance on Composio deleted, or turned off while other triggers hold it (none of them on), or
250
+ * kept (one of them on): undefined when that is done, else what is left there, said. `values`: its sealed config's,
251
+ * withheld from Composio's words. `here`, once that is done, in the same step of the project's: the trigger's delete
252
+ * here, so the next removal of a trigger sharing the instance reads the holders without it (two removals at once
253
+ * never each keep the instance for the other); its refusal is thrown, never said as Composio's. */
254
+ async leftThere(source, id, values, here) {
140
255
  const instance = instanceOf(source);
141
256
  let left = "delete";
142
- try {
143
- // Kept while another trigger holds it, and off once none of those is on, as a pause leaves it.
144
- const credential = await this.deps.credential(String(source.server), "field");
145
- await this.serial(credential.key, async () => this.leave(this.ask(credential), instance, (left = await this.leftWith(instance, id))));
146
- return undefined;
257
+ let failed = undefined;
258
+ // Kept while another trigger holds it, and off once none of those is on, as a pause leaves it.
259
+ const credential = await this.deps.credential(String(source.server), "field").catch((error) => void (failed = { error }));
260
+ if (credential) {
261
+ await this.serial(credential.key, async () => {
262
+ try {
263
+ await this.leave(this.ask(credential, "nothing was changed", values), instance, (left = await this.leftWith(instance, id)));
264
+ }
265
+ catch (error) {
266
+ failed = { error };
267
+ return;
268
+ }
269
+ await here?.();
270
+ });
147
271
  }
148
- catch (error) {
149
- const said = String(error?.message ?? error);
150
- if (left === "off") {
151
- this.deps.say({ condition: "composio_instance_not_turned", trigger: id, instance, on: "false", error: said });
152
- return { composio: { done: false, note: `Composio didn't turn the trigger instance ${instance} off, and no trigger left that holds it is on: turn it off there yourself: ${DASHBOARD}` } };
153
- }
154
- this.deps.say({ condition: "composio_instance_not_removed", trigger: id, instance, error: said });
155
- return { composio: { done: false, note: `Composio didn't delete the trigger instance ${instance}: remove it there yourself: ${DASHBOARD}` } };
272
+ if (failed === undefined)
273
+ return undefined;
274
+ const said = String(failed.error?.message ?? failed.error);
275
+ if (left === "off") {
276
+ this.deps.say({ condition: "composio_instance_not_turned", trigger: id, instance, on: "false", error: said });
277
+ return { composio: { done: false, note: `Composio didn't turn the trigger instance ${instance} off, and no trigger left that holds it is on: turn it off there yourself: ${DASHBOARD}` } };
156
278
  }
279
+ this.deps.say({ condition: "composio_instance_not_removed", trigger: id, instance, error: said });
280
+ return { composio: { done: false, note: `Composio didn't delete the trigger instance ${instance}: remove it there yourself: ${DASHBOARD}` } };
157
281
  }
158
282
  // ---- the routes of a saved Composio server ---------------------------------------------------------------------------
159
283
  /** GET /settings/mcp-servers/{name}/composio/events: its toolkit's events, every page. */
@@ -165,7 +289,7 @@ export class ComposioTriggers {
165
289
  if (!isObject(item) || !text(item.slug))
166
290
  continue;
167
291
  const config = isObject(item.config) ? item.config : { type: "object", properties: {} };
168
- events.push({ slug: text(item.slug), name: text(item.name) || text(item.slug), description: text(item.description), ...(text(item.instructions) ? { instructions: text(item.instructions) } : {}), config, polled: item.type === "poll" });
292
+ events.push({ slug: text(item.slug), name: text(item.name) || text(item.slug), description: text(item.description), ...(text(item.instructions) ? { instructions: text(item.instructions) } : {}), config, polled: item.type === "poll", sealed: sealedSchemaFields(config) });
169
293
  }
170
294
  return { server: name, toolkit: credential.toolkit, events };
171
295
  }
@@ -174,7 +298,7 @@ export class ComposioTriggers {
174
298
  async triggersOf(name) {
175
299
  const credential = await this.deps.credential(name, "route");
176
300
  const mine = (await this.deps.holders()).filter((h) => h.source.server === name);
177
- const ask = this.ask(credential);
301
+ const ask = this.ask(credential, "nothing was changed", this.sealedValues(mine));
178
302
  // What Composio answered, and whether it answered for every instance: one it didn't answer for is unknown, not missing.
179
303
  const states = new Map();
180
304
  let read = false;
@@ -256,6 +380,107 @@ export class ComposioTriggers {
256
380
  if (using.length)
257
381
  throw new ApiError("composio_in_use", `${name} has Composio triggers: ${using.map((h) => h.name).join(", ")}. Delete ${using.length > 1 ? "them" : "it"} first, ${then}.`, { details: { triggers: using.map((h) => ({ id: h.id, name: h.name })) } });
258
382
  }
383
+ /** At the server's start: each composio trigger kept with a credential of its config in the clear (made before the
384
+ * config was sealed) sealed now, its source rewritten (`rewrite`) as an answer shows it (shownSource: the mask in its
385
+ * place), and said with the trigger's id and the fields' names alone. Composio's instance is left as it is: it already
386
+ * holds the value. One that can't be sealed is said, still answered masked, and left for the next start. A trigger
387
+ * with nothing in the clear is passed over, so a second start does nothing. */
388
+ async sealKept(rewrite) {
389
+ let done = 0;
390
+ for (const holder of await this.deps.holders()) {
391
+ // At any depth: an earlier server took a config with one below its top level, each sealed by its JSON Pointer.
392
+ const clear = configSecrets(holder.source.config);
393
+ if (!clear.length)
394
+ continue;
395
+ const names = clear.map((secret) => secret.name).join(",");
396
+ try {
397
+ for (const secret of clear)
398
+ await this.deps.sealed.set(configScope(holder.id, secret.name), configFieldFor(String(secret.value)), String(secret.value));
399
+ await rewrite(holder.id, shownSource(holder.source));
400
+ this.deps.say({ condition: "composio_config_sealed", trigger: holder.id, fields: names });
401
+ done++;
402
+ }
403
+ catch (error) {
404
+ this.deps.say({ condition: "composio_config_not_sealed", trigger: holder.id, fields: names, error: told(error, clear.map((secret) => String(secret.value))) });
405
+ }
406
+ }
407
+ return done;
408
+ }
409
+ /** After the server's start, never holding it up: each composio trigger an earlier server kept with a value in the clear
410
+ * in a field only its event's schema marks (format: password, writeOnly: sealedSchemaFields; the name rule is
411
+ * sealKept's) sealed, as sealKept seals one. Each event's schema is read once from Composio with its server's key, its
412
+ * words withheld when the server's triggers hold sealed values. When a read fails (Composio down), that is said once,
413
+ * by a code, and those triggers are left for the next start. The rewrites run inside `around` (the store's
414
+ * secureRewrite), once, and only when there is one to make. */
415
+ async sealMarked(rewrite, around) {
416
+ const eventOf = (holder) => `${String(holder.source.server)}\n${String(holder.source.event)}`;
417
+ // A top-level value in the clear its sealed_config doesn't name: one the schema may mark.
418
+ const plain = (source) => {
419
+ const sealed = new Set(sealedOf(source));
420
+ return isObject(source.config) ? Object.entries(source.config).filter(([name, value]) => !sealed.has(name) && value !== SEALED_MASK && sealableValue(value)).map(([name]) => name) : [];
421
+ };
422
+ const holders = (await this.deps.holders()).filter((holder) => plain(holder.source).length);
423
+ const marked = new Map();
424
+ let unread = 0;
425
+ let failed;
426
+ for (const event of new Set(holders.map(eventOf))) {
427
+ if (this.deps.signal?.aborted)
428
+ return;
429
+ const [server, slug] = event.split("\n");
430
+ try {
431
+ const credential = await this.deps.credential(server, "field");
432
+ const type = await this.ask(credential, "nothing was changed", this.sealedValues(holders.filter((holder) => eventOf(holder) === event)))(`reading ${slug}'s config on Composio`, "GET", `/api/v3/triggers_types/${enc(slug)}`);
433
+ marked.set(event, sealedSchemaFields(type.config));
434
+ }
435
+ catch (error) {
436
+ unread++;
437
+ failed ??= error;
438
+ }
439
+ }
440
+ if (unread && !this.deps.signal?.aborted)
441
+ this.deps.say({ condition: "composio_config_schemas_unread", events: String(unread), error: failed instanceof ApiError ? failed.code : "error" });
442
+ const due = (holder) => plain(holder.source).filter((name) => marked.get(eventOf(holder))?.includes(name));
443
+ if (this.deps.signal?.aborted || !holders.some((holder) => due(holder).length))
444
+ return;
445
+ await around(async () => {
446
+ let done = 0;
447
+ // Read again: a request since may have changed or deleted one.
448
+ for (const holder of await this.deps.holders()) {
449
+ const fields = due(holder);
450
+ if (!fields.length)
451
+ continue;
452
+ const config = holder.source.config;
453
+ const values = fields.map((name) => String(config[name]));
454
+ const unseal = async () => {
455
+ for (const name of fields)
456
+ await this.deps.sealed.remove(configScope(holder.id, name)).catch(() => undefined);
457
+ };
458
+ let written;
459
+ try {
460
+ for (const [i, name] of fields.entries())
461
+ await this.deps.sealed.set(configScope(holder.id, name), configFieldFor(values[i]), values[i]);
462
+ // These fields alone masked: any other value is as the row keeps it (sealKept's). Written only while the row is
463
+ // the one read here (its updatedAt and its source: one millisecond's writes share an updatedAt): a PATCH since (an
464
+ // accept) is not undone, a delete since leaves no sealed row.
465
+ written = await rewrite(holder.id, { ...holder.source, config: { ...config, ...Object.fromEntries(fields.map((name) => [name, SEALED_MASK])) }, [SEALED_FIELD]: [...new Set([...sealedOf(holder.source), ...fields])] }, holder.updatedAt, holder.source);
466
+ }
467
+ catch (error) {
468
+ await unseal();
469
+ this.deps.say({ condition: "composio_config_not_sealed", trigger: holder.id, fields: fields.join(","), error: told(error, values) });
470
+ continue;
471
+ }
472
+ if (!written) {
473
+ await unseal();
474
+ this.deps.say({ condition: "composio_config_not_sealed", trigger: holder.id, fields: fields.join(","), error: "changed_meanwhile" });
475
+ continue;
476
+ }
477
+ // Written: the row is masked, so its sealed values are now the one copy and nothing after this undoes them.
478
+ this.deps.say({ condition: "composio_config_sealed", trigger: holder.id, fields: fields.join(",") });
479
+ done++;
480
+ }
481
+ return done;
482
+ });
483
+ }
259
484
  // ---- its steps ---------------------------------------------------------------------------------------------------------
260
485
  /** `step` run once the steps queued before it for the project of key `key` are done (failed or not), and before any
261
486
  * queued after it. The key is digested, never kept as it is. */
@@ -301,9 +526,14 @@ export class ComposioTriggers {
301
526
  throw error;
302
527
  });
303
528
  }
304
- /** Composio asked with the server's key; a failure's words end with what it left (`outcome`). */
305
- ask(credential, outcome = "nothing was changed") {
306
- return asking(this.deps.control, credential.key, this.deps.signal, outcome);
529
+ /** The sealed config values `holders` keep here: what Composio may quote back about their instance. */
530
+ sealedValues(holders) {
531
+ return holders.flatMap((h) => sealedOf(h.source).map((name) => this.deps.sealed.get(configScope(h.id, name), CONFIG_SECRET) ?? this.deps.sealed.get(configScope(h.id, name), CONFIG_UNLISTED) ?? "")).filter(Boolean);
532
+ }
533
+ /** Composio asked with the server's key; a failure's words end with what it left (`outcome`), and pass on none of
534
+ * Composio's own with a value of `sealed` (a trigger's sealed config) in play. */
535
+ ask(credential, outcome = "nothing was changed", sealed = []) {
536
+ return asking(this.deps.control, credential.key, this.deps.signal, outcome, sealed);
307
537
  }
308
538
  addressOf(hook) {
309
539
  return `${this.deps.publicUrl}/v2/hooks/composio/${hook}`;
@@ -1,8 +1,9 @@
1
1
  import type { IncomingMessage } from "node:http";
2
2
  import type { Duplex } from "node:stream";
3
3
  import { type AttachHub, type AttachSocket, type HelloResult, type MachineTokens } from "@parcha/agentrun-computer";
4
- import { type WebSocket } from "ws";
5
- import type { MintedTokens, PairedComputerRow, PairedComputers } from "./store/index.js";
4
+ import { WebSocket } from "ws";
5
+ import { type LiveReach } from "./live-reach.js";
6
+ import type { MintedTokens, PairedComputerRow, PairedComputers, RunnerRelays } from "./store/index.js";
6
7
  /** The characters of a pairing code: no 0, O, 1 or I, so a person reads it off a screen without a doubt. */
7
8
  export declare const PAIRING_ALPHABET = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
8
9
  /** A computer's token starts with this, so a secret scanner knows one. */
@@ -67,6 +68,9 @@ export type PairedView = {
67
68
  serves: string[];
68
69
  /** When it serves no kind, why, naming what its driver lacks (servesNoKind); null when it serves one. */
69
70
  unserved: string | null;
71
+ /** On a server whose runner runs in a process of its own, why no run here can use it and how to start the server
72
+ * instead (RUNNER_APART_WORDS); null where its runs can. */
73
+ runs_refused: string | null;
70
74
  os: string;
71
75
  os_version: string | null;
72
76
  device: {
@@ -93,7 +97,7 @@ export type PairedView = {
93
97
  /** Its last hello: the live socket's while it is attached (never null while online), else the last one kept. */
94
98
  seen_at: string | null;
95
99
  };
96
- export declare function pairedView(row: PairedComputerRow, hub: Pick<AttachHub, "online" | "since" | "hello" | "claimed" | "deadline">, serves: readonly string[]): PairedView;
100
+ export declare function pairedView(row: PairedComputerRow, hub: Pick<AttachHub, "online" | "since" | "hello" | "claimed" | "deadline">, serves: readonly string[], runnerApart?: boolean): PairedView;
97
101
  /** How the socket's liveness is timed: ATTACH_HEARTBEAT_MS and ATTACH_IDLE_MS, unless a test gives its own. */
98
102
  export type AttachTiming = {
99
103
  readonly heartbeatMs: number;
@@ -101,8 +105,10 @@ export type AttachTiming = {
101
105
  };
102
106
  /** One WebSocket as the hub takes it (attach.ts AttachSocket): text frames in and out; a ping each heartbeat; closed
103
107
  * with ATTACH_CLOSE.idle once nothing (no frame, ping or pong) is heard for idleMs, and with ATTACH_CLOSE.binary on a
104
- * binary frame. A frame over MAX_LINE_BYTES is the server's maxPayload, which closes it with 1009 itself. */
105
- export declare function attachSocketOf(ws: WebSocket, timing?: AttachTiming): AttachSocket;
108
+ * binary frame. A frame over MAX_LINE_BYTES is the server's maxPayload, which closes it with 1009 itself. `closing` is
109
+ * told each close this side starts, when it starts: a peer that does not answer it (an idle one) ends the socket only
110
+ * once ws gives up on it. */
111
+ export declare function attachSocketOf(ws: WebSocket, timing?: AttachTiming, closing?: (code: number, reason: string) => void): AttachSocket;
106
112
  export interface AttachRoutesOptions {
107
113
  readonly store: {
108
114
  readonly pairedComputers: PairedComputers;
@@ -115,13 +121,40 @@ export interface AttachRoutesOptions {
115
121
  /** An API-only server's (api-only.ts): the socket takes a hosted machine's minted token alone, and a paired computer's
116
122
  * (the console's) is 401 as one it does not know. */
117
123
  readonly machinesOnly?: boolean;
124
+ /** No runner in this server's process (ServeOptions.runnerApart): a pairing code and the pair answer say no run here
125
+ * can use a paired computer, and how to start the server so one can (RUNNER_APART_WORDS). */
126
+ readonly runnerApart?: boolean;
118
127
  /** The socket's liveness timing: the protocol's unless a test gives its own. */
119
128
  readonly timing?: AttachTiming;
120
129
  readonly now?: () => number;
121
130
  /** Told each socket taken, with its computer, before its hello: the binding's conformance run (attach-conformance.ts)
122
131
  * watches the raw socket to see how a driver answers a close, a drop and a frame it must refuse. */
123
132
  readonly onSocket?: (computer: string, ws: WebSocket) => void;
133
+ /** A runner in a process of its own (dial-relay.ts): the tokens it mints name it and this incarnation, and the socket
134
+ * takes a machine's token only where its row names both. */
135
+ readonly owner?: {
136
+ readonly runner: string;
137
+ readonly incarnation: string;
138
+ };
139
+ /** The server's relay of a dial whose token another runner minted: where each runner's attach listener answers, and
140
+ * the hosts it may dial with the proxy's proof (live-reach.ts). Without it such a dial is refused 503. */
141
+ readonly relay?: {
142
+ readonly relays: Pick<RunnerRelays, "get">;
143
+ readonly reach: LiveReach;
144
+ };
124
145
  }
146
+ /** A request's Bearer token, or undefined. */
147
+ export declare const bearerOf: (authorization: string | undefined) => string | undefined;
148
+ /** How often a runner's attach listener says it is there (its runner_relays row's seen_at), and how long after its last
149
+ * word the server takes it as gone. */
150
+ export declare const RELAY_RENEW_MS = 10000;
151
+ export declare const RELAY_STALE_MS: number;
152
+ /** How long the server waits for a runner's attach listener to take a relayed dial. */
153
+ export declare const RELAY_CONNECT_MS = 10000;
154
+ /** Two WebSockets joined frame by frame, each an attach socket with `timing` (attachSocketOf: its idle close, its binary
155
+ * refusal, the server's maxPayload), each closing the other with its code and reason: once it ended, or as soon as it
156
+ * starts a close of its own, so an idle peer's close reaches the other side at once. */
157
+ export declare function joinSockets(one: WebSocket, other: WebSocket, timing?: AttachTiming): void;
125
158
  /** The pairing routes, the attach socket and the daemon route over one store and one hub, and the tokens a dial
126
159
  * provider mints. */
127
160
  export declare function createAttachRoutes(options: AttachRoutesOptions): {
@@ -129,10 +162,12 @@ export declare function createAttachRoutes(options: AttachRoutesOptions): {
129
162
  id: string;
130
163
  code: string;
131
164
  expires_at: string;
165
+ runs_refused: string | null;
132
166
  }>;
133
167
  pair: (body: unknown, address: string) => Promise<{
134
168
  computer: string;
135
169
  token: string;
170
+ runs_refused: string | null;
136
171
  }>;
137
172
  remove: (id: string) => Promise<void>;
138
173
  upgrade: (req: IncomingMessage, socket: Duplex, head: Buffer, deny: (status: string, words?: string, headers?: Record<string, string>) => void) => void;