@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
package/dist/tools.js CHANGED
@@ -19,7 +19,7 @@ import { registerTurnEnding } from "./timeline/index.js";
19
19
  import { BACKGROUND_LOG_BYTES, BACKGROUND_MAX, BACKGROUND_PAGE_BYTES } from "./background.js";
20
20
  import { isWorkspaceError, localWorkspace } from "./workspace/index.js";
21
21
  import { fetchOptions, HTML_READ_CHARS, TEXT_CAP } from "./web-fetch-direct.js";
22
- import { DEFAULT_HARNESS, HARNESSES } from "./harness.js";
22
+ import { harnessIds, onAdapter } from "./harness-table.js";
23
23
  import { META_TOOLS } from "./meta-tool-names.js";
24
24
  import { localFolderOf } from "./workspace/local.js";
25
25
  import { LLM_TOOL } from "./llm.js";
@@ -28,6 +28,7 @@ import { FAUX_ENV, workflowNodes } from "./model.js";
28
28
  import { bookedIn, booking } from "./paid-calls.js";
29
29
  import { hostToolDefs } from "@parcha/agentrun-kernel/kernel";
30
30
  import { browserPrice, browserSpend } from "./browser-cost.js";
31
+ import { sessionRecordings } from "./computer-record.js";
31
32
  import { forModel } from "./result.js";
32
33
  import { fetchFor, pagesOf, WEB_FETCH_TOOL, webFetchTool } from "./web-fetch.js";
33
34
  import { searchFor, WEB_SEARCH_TOOL, webSearchTool } from "./web-search.js";
@@ -46,6 +47,7 @@ import { HANDOVER_WAITING } from "./runner/journal-kinds.js";
46
47
  import { provenFor } from "./live-reach.js";
47
48
  import { clearWaitEnded, markWaitEnded } from "./browser-wait-ended.js";
48
49
  import { runSignIn, verifyRunSignIn } from "./sign-ins-store.js";
50
+ import { held } from "./runner/held.js";
49
51
  export const ASK_TOOL = "ask_person";
50
52
  /** Under `--faux` only: a module whose default export gives the browser's `{ computer, driver }` for the run's
51
53
  * environment, the vendor its plane names and the saved sign-in it was handed for that vendor (`{ provider, ref, save }`,
@@ -261,13 +263,18 @@ export const runSignInSaved = (store, sealKey, claim, kept) => async (row, chang
261
263
  if (!kept.save || !savedOnRelease(row, change))
262
264
  return false;
263
265
  const ended = row.session.endedAt ? Date.parse(row.session.endedAt) : Number.NaN;
264
- return verifyRunSignIn(store, sealKey, claim, kept, Number.isFinite(ended) ? ended : Date.now());
266
+ const at = Number.isFinite(ended) ? ended : Date.now();
267
+ // A run's own process holds no seal key: its runner marks it under the claim (held.ts verifySignIn).
268
+ if (!sealKey)
269
+ return (await held()?.verifySignIn(kept, at)) ?? false;
270
+ return verifyRunSignIn(store, sealKey, claim, kept, at);
265
271
  };
266
272
  /** A browser on pi-browser's durable adapter, its sessions a browser computer provider's of the computer registry
267
273
  * (browser-computer.ts), each driven over its CDP URL by pi-browser's raw-CDP driver: the agent's computer, where it is
268
274
  * a browser (the claim's, computer-for-claim.ts), else the one the run's plane names (tool-plane.ts: picked, else
269
275
  * Browserbase where the server holds its keys, else Kernel), kept for the run's life; a plane that names none (a run kept
270
- * from before the pick) is Browserbase. Its sessions' custody lives in the run's own store. No recording; the owner
276
+ * from before the pick) is Browserbase. Its sessions' custody lives in the run's own store. No vendor's recording:
277
+ * where the agent's computer says computer.record, each session's video is the live view's screencast. The owner
271
278
  * watches it live, takes it over and hands it back, and the agent may ask them to (browser-live.ts, browser-person.ts).
272
279
  * A session the run still holds is released when the run is let go. Where the plane says unavailable (its vendor's key
273
280
  * gone since), each call is refused, saying why. Its session time is the run's spend, held under its cap before it runs
@@ -307,7 +314,9 @@ const browserTool = {
307
314
  // launch makes it: never the process's environment, so one run's keys never make another's.
308
315
  const runLog = (line) => void process.stderr.write(`agentrun-serve: run ${host.where.ref.id}: ${line}\n`);
309
316
  const vendorFetch = async () => (host.env[FAUX_ENV] ? fauxFetch(host.env, FAUX_VENDOR_API_ENV) : fetch);
310
- const handed = computer ? undefined : host.claim ? (planeRefused || !host.store || !host.sealKey ? undefined : await runSignIn(host.store, host.sealKey, host.claim, vendor, { vendors: vendorsOver(() => host.env, vendorFetch), log: runLog })) : handedSignIn();
317
+ // A run's own process holds no seal key: its runner opens the run's sign-in under the claim (held.ts runSignIn).
318
+ const atRunner = held();
319
+ const handed = computer ? undefined : host.claim ? (planeRefused || !host.store ? undefined : host.sealKey ? await runSignIn(host.store, host.sealKey, host.claim, vendor, { vendors: vendorsOver(() => host.env, vendorFetch), log: runLog }) : await atRunner?.runSignIn(vendor)) : handedSignIn();
311
320
  const kept = !planeRefused && handed?.provider === vendor ? handed : undefined;
312
321
  // Tests only (--faux): the faux browser's computer provider and driver stand in for the plane vendor's and the raw-CDP
313
322
  // driver. The agent's browser computer is still the claim's, so a test hands the claim a faux provider of its own.
@@ -423,6 +432,9 @@ const browserTool = {
423
432
  // (host.liveViewers); never a file in the run's folder, which is the agent's workspace.
424
433
  const viewers = live.sessionHandovers(host.liveViewers, at?.host);
425
434
  const onSession = (row, change) => viewers.changed(row, change);
435
+ // Where the agent's computer records (its claim's `record`, computer.record): each session's video, by its computer,
436
+ // from its launch (or its reopening after a restart) to its release, through the live view's one screencast of it.
437
+ const recordSession = sessionRecordings(view, computer?.record);
426
438
  // Its session time is the run's spend, at its provider's price, and held under the run's cap (browser-cost.ts).
427
439
  const providerName = parts.provider?.name ?? vendor;
428
440
  const price = browserPrice(providerName, host.env);
@@ -440,7 +452,7 @@ const browserTool = {
440
452
  const files = { files: uploadsFrom(work, MAX_UPLOAD_BYTES, uploadMime), ...(folder !== undefined && keepsDownloads ? { workspace: () => folder } : {}) };
441
453
  // A session that saved to the sign-in, let go: its time, for the sign-in's verified_at when the run's lease ends.
442
454
  // On the runner, the store's verified_at under the run's claim (runSignInSaved), never a mark in the run's directory.
443
- const verify = kept?.save && host.claim && host.store && host.sealKey ? runSignInSaved(host.store, host.sealKey, host.claim, kept) : undefined;
455
+ const verify = kept?.save && host.claim && host.store && (host.sealKey || held()) ? runSignInSaved(host.store, host.sealKey, host.claim, kept) : undefined;
444
456
  // Awaited by the session's change, so the release that lets a run's sessions go (beforeRelease) returns only once its
445
457
  // last save is verified: the run's end commit, which ends the claim, never fences it.
446
458
  const saved = verify
@@ -451,6 +463,7 @@ const browserTool = {
451
463
  // A session let go ends a wait on the person's answer that kept it open (personWait, below): the run parks.
452
464
  if (change === "released")
453
465
  hands.sessionEnded(row.session.tag);
466
+ await recordSession(row.session.tag, change === "released" ? null : row.session.resourceId);
454
467
  // A session that opens, whatever let the last one go: the Screen tab's ended state goes (browser-wait-ended.ts).
455
468
  if (change === "launched" && host.store && host.claim)
456
469
  await clearWaitEnded(host.store.settings, host.claim.runId, host.claim.epoch).catch(() => undefined);
@@ -513,6 +526,8 @@ const browserTool = {
513
526
  try {
514
527
  const opened = await watched?.liveView?.({ id: row.resourceId, tag: row.tag });
515
528
  await viewers.reopened(row.tag, opened?.fullscreen);
529
+ if (opened)
530
+ await recordSession(row.tag, row.resourceId);
516
531
  }
517
532
  catch {
518
533
  // A browser that cannot be reached has no view to give: the owner reads none, as for any session without one.
@@ -641,7 +656,7 @@ export const allows = (allowed, name) => allowed.includes(name);
641
656
  * agent's `granted` tools a workflow's call node runs here (CALL_TOOLS, and each MCP tool granted by its own name,
642
657
  * tool-names.ts mcpNameOf), and with the run's `plane`, none it resolves unavailable (its agent's own tool of the name
643
658
  * does not run either). A
644
- * learned model node runs without tools (learn/skills.ts MODEL_NODE_TOOLS), and a harness's own tool (Bash,
659
+ * learned model node runs without tools (learn/workflow-draft.ts MODEL_NODE_TOOLS), and a harness's own tool (Bash,
645
660
  * exec_command, apply_patch) is never one, so the DSL refuses a draft that names it. */
646
661
  export const learnedWorkflowTools = (granted, plane, options = {}) => [...new Set(granted.filter((name) => (options.mcp === true && mcpNameOf(name) !== undefined) || (allows(CALL_TOOLS, name) && !isUnavailable(plane?.[name]))))];
647
662
  /** The tools a learned draft may name (learnedWorkflowTools) that the gate allows: `permission` is what the gate holds a
@@ -706,7 +721,7 @@ export async function toolingOf(revision) {
706
721
  /** The variables `entry` needs that `env` does not set, by name. */
707
722
  export const missingEnv = (entry, env) => entry.needs.filter((name) => !env[name]);
708
723
  /** Every tool as capabilities show it, the server's one tool catalog: available here, or the variables it is missing
709
- * (names only), and the harnesses that run it (another harness than pi runs only the host tools, host-tools.ts). A tool
724
+ * (names only), and the harnesses that run it (one on an adapter runs only the host tools, host-tools.ts). A tool
710
725
  * a user picks a provider for (tool-plane.ts) gives the providers offered, the server's (`provider`, the default where it
711
726
  * sets none), the default, and what it resolves to on each harness under the server's `settings`: available where any
712
727
  * is not unavailable, and missing PARALLEL_API_KEY where Parallel is picked without it. An unavailable tool says why
@@ -719,6 +734,11 @@ export const missingEnv = (entry, env) => entry.needs.filter((name) => !env[name
719
734
  export const toolsView = (env, settings = {}, noBox, refused = {}, runnerShell = new Set()) => {
720
735
  const views = explainsView(env, settings);
721
736
  const picked = withDefaults(settings);
737
+ // The harnesses by the table `env` runs on (a module's among them): a host tool runs on each; any other tool on those
738
+ // that run on the general spec with pi's tools (no adapter facts: pi, and a module's harness without them), as the save
739
+ // check takes them (runnable.ts onAdapter).
740
+ const everyHarness = harnessIds(env);
741
+ const generalSpec = everyHarness.filter((id) => !onAdapter(env, id));
722
742
  const table = Object.entries(TOOLS).map(([name, entry]) => {
723
743
  const view = PICKABLE.includes(name) ? views[name] : undefined;
724
744
  const plane = view?.resolves;
@@ -732,11 +752,11 @@ export const toolsView = (env, settings = {}, noBox, refused = {}, runnerShell =
732
752
  // Unavailable says why: a sandbox-only tool no box here can run, why none can (`noBox`); on a tool a user picks a
733
753
  // provider for, the resolutions' own words (`web_search is turned off in settings`); else the variables it needs.
734
754
  const reason = available ? undefined : refusal ?? boxless ?? (plane ? [...new Set(Object.values(plane).filter(isUnavailable).map(whyUnavailable))].join("; ") : `Needs ${keyNeeded(missing)}`);
735
- return { name, summary: entry.summary, ...(blurbOf(name) ? { blurb: blurbOf(name) } : {}), nodes: entry.nodes, calls: entry.effect !== undefined, ...(entry.callOnly ? { call_only: true } : {}), ...(entry.sandboxOnly ? { sandbox_only: true } : {}), available, ...(reason ? { reason } : {}), ...(missing.length ? { missing } : {}), harnesses: isHostTool(name) ? [...HARNESSES] : [DEFAULT_HARNESS], ...serverGate(name, settings), ...(plane ? { providers: [...PROVIDERS[name]], provider: picked[name].provider, default_provider: PROVIDERS[name][0], resolves: plane, why: view.why } : {}) };
755
+ return { name, summary: entry.summary, ...(blurbOf(name) ? { blurb: blurbOf(name) } : {}), nodes: entry.nodes, calls: entry.effect !== undefined, ...(entry.callOnly ? { call_only: true } : {}), ...(entry.sandboxOnly ? { sandbox_only: true } : {}), available, ...(reason ? { reason } : {}), ...(missing.length ? { missing } : {}), harnesses: isHostTool(name) ? [...everyHarness] : [...generalSpec], ...serverGate(name, settings), ...(plane ? { providers: [...PROVIDERS[name]], provider: picked[name].provider, default_provider: PROVIDERS[name][0], resolves: plane, why: view.why } : {}) };
736
756
  });
737
757
  // The host tools over a run's own tools (META_TOOLS): not in the table, never granted or named by a node (`meta`), listed
738
758
  // so the owner sees them and their setting (allow or deny; a deny is not offered at all).
739
- const meta = [...META_TOOLS].map((name) => ({ name, summary: META_SUMMARY[name], blurb: blurbOf(name), nodes: false, calls: false, meta: true, available: true, harnesses: [...HARNESSES], ...serverGate(name, settings) }));
759
+ const meta = [...META_TOOLS].map((name) => ({ name, summary: META_SUMMARY[name], blurb: blurbOf(name), nodes: false, calls: false, meta: true, available: true, harnesses: [...everyHarness], ...serverGate(name, settings) }));
740
760
  return [...table, ...meta];
741
761
  };
742
762
  const META_SUMMARY = Object.freeze({
@@ -54,6 +54,9 @@ export type TriggerAdapter = {
54
54
  parse(value: Json, now: number, bad: (field: string, reason: string, message: string) => void, issues: InputIssue[]): Source | undefined;
55
55
  /** Whether a source the store keeps is whole, of its type. */
56
56
  wellFormed(source: Json): boolean;
57
+ /** A kept source as every answer sends it, when that is not as kept: a field that holds a credential masked (a composio
58
+ * config's key), by the one rule, whether the source sealed it yet or not. Default: as kept. */
59
+ shown?(source: Source): Source;
57
60
  /** The zone its times are read in, for its runs' provenance line. Default UTC. */
58
61
  zone?(source: Source): string;
59
62
  /** A clock source's times. */
@@ -1,2 +1,6 @@
1
1
  import type { TriggerAdapter } from "./trigger-adapter.js";
2
2
  export declare const TRIGGER_ADAPTERS: readonly TriggerAdapter[];
3
+ /** A trigger's answer (an object whose top-level `source` is a trigger source) with that source as a read sends it now
4
+ * (its adapter's `shown`): for an answer kept before that rule, an Idempotency-Key's record of a trigger create. Only
5
+ * that one field of that one shape: any other value is as it is. */
6
+ export declare function shownTrigger(body: unknown, adapters?: readonly TriggerAdapter[]): unknown;
@@ -5,3 +5,16 @@ import { webhook } from "./trigger-webhook.js";
5
5
  import { email } from "./trigger-email.js";
6
6
  import { feed } from "./trigger-feed.js";
7
7
  export const TRIGGER_ADAPTERS = [schedule, webhook, github, composio, email, feed];
8
+ /** A trigger's answer (an object whose top-level `source` is a trigger source) with that source as a read sends it now
9
+ * (its adapter's `shown`): for an answer kept before that rule, an Idempotency-Key's record of a trigger create. Only
10
+ * that one field of that one shape: any other value is as it is. */
11
+ export function shownTrigger(body, adapters = TRIGGER_ADAPTERS) {
12
+ if (body === null || typeof body !== "object" || Array.isArray(body))
13
+ return body;
14
+ const source = body.source;
15
+ if (source === null || typeof source !== "object" || Array.isArray(source))
16
+ return body;
17
+ const kind = source.kind;
18
+ const adapter = typeof kind === "string" ? adapters.find((a) => a.id === kind) : undefined;
19
+ return adapter?.shown ? { ...body, source: adapter.shown(source) } : body;
20
+ }
@@ -1,4 +1,5 @@
1
- import { type TriggerAdapter } from "./trigger-adapter.js";
1
+ import { type Source, type TriggerAdapter } from "./trigger-adapter.js";
2
+ import { type Json } from "./validate.js";
2
3
  /** A Composio trigger slug: upper case, digits and `_` (GITHUB_ISSUE_ADDED_EVENT). */
3
4
  export declare const COMPOSIO_EVENT: RegExp;
4
5
  /** The id of a project's route here, made once when its subscription is made or moved here. */
@@ -7,4 +8,60 @@ export declare const COMPOSIO_HOOK: RegExp;
7
8
  export declare const MOVE_FIELD = "move_subscription";
8
9
  /** The settings field the project's subscription secret is sealed under, one scope per hook. */
9
10
  export declare const COMPOSIO_SECRET = "secret";
11
+ /** The settings fields a trigger's sealed config value is kept under, one scope per trigger and field (configScope):
12
+ * CONFIG_SECRET for a value the server's list of its secrets can hold (8 bytes or more, no whitespace), so a run that
13
+ * echoes it is cut; CONFIG_UNLISTED, sealed and masked all the same, for one too short or spaced for that list. */
14
+ export declare const CONFIG_SECRET = "config";
15
+ export declare const CONFIG_UNLISTED = "config_unlisted";
16
+ /** What a trigger keeps, and answers, in place of a sealed config value. */
17
+ export declare const SEALED_MASK = "[sealed]";
18
+ /** The source's field that names its sealed config fields, set by this server. */
19
+ export declare const SEALED_FIELD = "sealed_config";
20
+ /** The settings scope of trigger `id`'s sealed config field `field`. */
21
+ export declare const configScope: (id: string, field: string) => string;
22
+ /** Whether config field `name` is named like a credential. Each word is read as its singular (a trailing s dropped), and
23
+ * the name is a credential's when a word is secret, password, passwd, passphrase, passcode, pwd, pat, token, credential,
24
+ * apikey, hapikey, jwt, dsn, sig, authorization, bearer or cookie; when it has connection then string; or when its last
25
+ * word is key (api_key, api_keys, developer_api_key, private_key; key_id and keyword are not). A credential's word with a
26
+ * count's word (COUNT_WORDS) just before or after it names a count, not a credential (max_tokens, token_count; a
27
+ * budget_api_key is still a key). Conservative otherwise: a field so named that holds no secret is sealed all the same. */
28
+ export declare const secretConfigName: (name: string) => boolean;
29
+ /** Whether `value` is an address, in any scheme (https, postgres, redis, amqp, mongodb+srv...), that carries a
30
+ * credential: a user part (user:pass@, :pass@, or a token alone as in https://TOKEN@host: any '@' after scheme://
31
+ * before whitespace), or a query or fragment parameter with a value whose name is a credential's (secretConfigName:
32
+ * ?token=, ?api_key=, #access_token=). Such a value is sealed whole, whatever its field's name. Conservative: a user
33
+ * name with no secret (ssh://git@host), or an '@' in a path or query (?email=a@b), is sealed too. */
34
+ export declare const credentialUrl: (value: string) => boolean;
35
+ /** Whether `value` is one a credential's field seals: a string, not empty, or a number (its decimal text is what is
36
+ * sealed; the config keeps its type wherever the value goes). A switch, null, an object or an array is not. */
37
+ export declare const sealableValue: (value: unknown) => value is string | number;
38
+ /** The fields of `config` sealed at a save without its schema: each named like a credential (secretConfigName) whose value
39
+ * is sealable (sealableValue), and each whose value is an address carrying a credential (credentialUrl). A create adds
40
+ * those its event's schema marks (sealedSchemaFields). */
41
+ export declare const sealedConfigFields: (config: unknown) => string[];
42
+ /** The fields of an event's config schema a save seals: each property the schema marks as a credential (format: password,
43
+ * or writeOnly), whatever its name; and each named like a credential that may hold a string or a number (its type is one
44
+ * of those, or says none). What the console's form takes as a password. */
45
+ export declare const sealedSchemaFields: (schema: unknown) => string[];
46
+ /** A credential in a config, where it is: `name`, its top-level field's name or, below the top level, its JSON Pointer
47
+ * (/auth/api_key), as sealed_config names it and its sealed scope is keyed (configScope); `path`, its keys from the
48
+ * config down; `value`. */
49
+ export type ConfigSecret = {
50
+ name: string;
51
+ path: string[];
52
+ value: string | number;
53
+ };
54
+ /** Every credential `config` holds in the clear, at any depth: a sealable value (sealableValue: a string, not empty, or a
55
+ * number), not SEALED_MASK, whose field is named like a credential (secretConfigName), or that is anywhere inside an
56
+ * object or array so named; and every string that is an address carrying a credential (credentialUrl), wherever it is. A create takes one
57
+ * at the top level alone (composio-triggers.ts make); a trigger an earlier server kept may hold one deeper. */
58
+ export declare const configSecrets: (config: unknown) => ConfigSecret[];
59
+ /** `sent`, a PATCH's config, with SEALED_MASK put back at each place `shown` (the config as answered) holds a field named
60
+ * in `sealed` (sealed_config: a top-level name, or a JSON Pointer read as configSecrets writes it, pointerOf) and `sent`
61
+ * leaves it out under an object it sends: a sealed value left out is kept. A copy: `sent` is not changed. */
62
+ export declare const sealedKept: (sent: Json, shown: unknown, sealed: readonly string[]) => Json;
63
+ /** `source` as every answer sends it: each credential in its config (configSecrets, at any depth) as SEALED_MASK, and
64
+ * named in sealed_config, whether it is sealed yet or still kept in the clear (a trigger saved before this rule, until
65
+ * the next start seals it: composio-triggers.ts sealKept). */
66
+ export declare const shownSource: (source: Source) => Source;
10
67
  export declare const composio: TriggerAdapter;
@@ -6,6 +6,10 @@
6
6
  // that scope. Every event of the project comes to that one route, checked once with the secret (trigger-signatures.ts's
7
7
  // composio scheme); each trigger whose instance is the delivery's metadata.trigger_id and whose `accept` takes it fires,
8
8
  // each its own run. This is the one way Composio's events start runs: a webhook trigger takes no composio signature.
9
+ // A config can hold a credential (HubSpot's deal-stage event takes {app_id, developer_api_key}). Composio's trigger
10
+ // schemas mark no field secret (their `config` is a plain JSON schema: type, title, description, required), so a field is
11
+ // sealed by its name (sealedConfigFields), or as an address carrying a credential (credentialUrl): kept in this source's sealed settings, the trigger keeping SEALED_MASK in its
12
+ // place and the field named in `sealed_config`, so no answer, row or log holds it (composio-triggers.ts).
9
13
  import { ACCEPT_SCHEMA, acceptOf, acceptRefusal } from "./trigger-accept.js";
10
14
  import { closedSchema, unknownSourceFields } from "./trigger-adapter.js";
11
15
  import { SIGNATURE_SCHEMES } from "./trigger-signatures.js";
@@ -26,6 +30,151 @@ const CONFIG_BYTES = 8 * 1024;
26
30
  export const MOVE_FIELD = "move_subscription";
27
31
  /** The settings field the project's subscription secret is sealed under, one scope per hook. */
28
32
  export const COMPOSIO_SECRET = "secret";
33
+ /** The settings fields a trigger's sealed config value is kept under, one scope per trigger and field (configScope):
34
+ * CONFIG_SECRET for a value the server's list of its secrets can hold (8 bytes or more, no whitespace), so a run that
35
+ * echoes it is cut; CONFIG_UNLISTED, sealed and masked all the same, for one too short or spaced for that list. */
36
+ export const CONFIG_SECRET = "config";
37
+ export const CONFIG_UNLISTED = "config_unlisted";
38
+ /** What a trigger keeps, and answers, in place of a sealed config value. */
39
+ export const SEALED_MASK = "[sealed]";
40
+ /** The source's field that names its sealed config fields, set by this server. */
41
+ export const SEALED_FIELD = "sealed_config";
42
+ /** The settings scope of trigger `id`'s sealed config field `field`. */
43
+ export const configScope = (id, field) => `config:${id}:${encodeURIComponent(field)}`;
44
+ /** The words of a config field's name, lower case: snake, kebab, dotted and camel case split (developerApiKey and
45
+ * developer_api_key both read developer, api, key). */
46
+ const wordsOf = (name) => name.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2").toLowerCase().split(/[^a-z0-9]+/).filter(Boolean);
47
+ /** A word of a name read as its singular: a trailing s dropped (tokens, secrets, keys), from a word of two letters or more. */
48
+ const singular = (word) => (word.length > 1 && word.endsWith("s") ? word.slice(0, -1) : word);
49
+ /** A word that names a credential wherever it stands in a name, read as its singular (credentials, tokens). */
50
+ const SECRET_WORDS = new Set(["secret", "password", "passwd", "passphrase", "passcode", "pwd", "pat", "token", "credential", "apikey", "hapikey", "jwt", "dsn", "sig", "authorization", "bearer", "cookie"]);
51
+ /** A word that, beside a credential's word, makes the name a count or size of it (max_tokens, token_count, tokens_used,
52
+ * tokens_per_minute, password_min_length): no credential. */
53
+ const COUNT_WORDS = new Set(["max", "min", "num", "number", "count", "limit", "total", "used", "usage", "budget", "remaining", "per", "length", "size", "quota"]);
54
+ /** Two words that name a credential together, the one after the other (connection_string); neither does alone. */
55
+ const SECRET_PAIRS = [["connection", "string"]];
56
+ /** Whether config field `name` is named like a credential. Each word is read as its singular (a trailing s dropped), and
57
+ * the name is a credential's when a word is secret, password, passwd, passphrase, passcode, pwd, pat, token, credential,
58
+ * apikey, hapikey, jwt, dsn, sig, authorization, bearer or cookie; when it has connection then string; or when its last
59
+ * word is key (api_key, api_keys, developer_api_key, private_key; key_id and keyword are not). A credential's word with a
60
+ * count's word (COUNT_WORDS) just before or after it names a count, not a credential (max_tokens, token_count; a
61
+ * budget_api_key is still a key). Conservative otherwise: a field so named that holds no secret is sealed all the same. */
62
+ export const secretConfigName = (name) => {
63
+ const words = wordsOf(name).map(singular);
64
+ const counted = (i) => COUNT_WORDS.has(words[i - 1] ?? "") || COUNT_WORDS.has(words[i + 1] ?? "");
65
+ return words.some((word, i) => SECRET_WORDS.has(word) && !counted(i)) || (words.at(-1) === "key" && !counted(words.length - 1)) || SECRET_PAIRS.some(([first, then]) => words.some((word, i) => word === first && words[i + 1] === then));
66
+ };
67
+ /** An address in any scheme with an authority (scheme://...): its authority, path, query and fragment, split by hand so a
68
+ * form a URL parser refuses (mongodb://h1:1,h2:2/db) is read too. */
69
+ const ADDRESS = /^[a-z][a-z0-9+.-]*:\/\/([^/?#]*)[^?#]*(\?[^#]*)?(#.*)?$/is;
70
+ /** Whether query or fragment `part` (with its leading ? or #) has a parameter with a value named like a credential. */
71
+ const credentialParam = (part) => part !== undefined && [...new URLSearchParams(part.slice(1))].some(([name, given]) => given !== "" && secretConfigName(name));
72
+ /** An address in any scheme with an '@' after its scheme:// and before any whitespace: a user part, read so whatever a
73
+ * password holds (a raw '/', '?' or '#' that would end the authority early, as in mongodb://u:pa/ss@h) is still one. */
74
+ const USER_PART = /^[a-z][a-z0-9+.-]*:\/\/\S*@/i;
75
+ /** Whether `value` is an address, in any scheme (https, postgres, redis, amqp, mongodb+srv...), that carries a
76
+ * credential: a user part (user:pass@, :pass@, or a token alone as in https://TOKEN@host: any '@' after scheme://
77
+ * before whitespace), or a query or fragment parameter with a value whose name is a credential's (secretConfigName:
78
+ * ?token=, ?api_key=, #access_token=). Such a value is sealed whole, whatever its field's name. Conservative: a user
79
+ * name with no secret (ssh://git@host), or an '@' in a path or query (?email=a@b), is sealed too. */
80
+ export const credentialUrl = (value) => {
81
+ if (USER_PART.test(value))
82
+ return true;
83
+ const parts = ADDRESS.exec(value);
84
+ return parts !== null && (credentialParam(parts[2]) || credentialParam(parts[3]));
85
+ };
86
+ /** Whether `value` is one a credential's field seals: a string, not empty, or a number (its decimal text is what is
87
+ * sealed; the config keeps its type wherever the value goes). A switch, null, an object or an array is not. */
88
+ export const sealableValue = (value) => (typeof value === "string" && value !== "") || (typeof value === "number" && Number.isFinite(value));
89
+ /** The fields of `config` sealed at a save without its schema: each named like a credential (secretConfigName) whose value
90
+ * is sealable (sealableValue), and each whose value is an address carrying a credential (credentialUrl). A create adds
91
+ * those its event's schema marks (sealedSchemaFields). */
92
+ export const sealedConfigFields = (config) => isObject(config) ? Object.entries(config).filter(([name, value]) => (sealableValue(value) && secretConfigName(name)) || (typeof value === "string" && credentialUrl(value))).map(([name]) => name) : [];
93
+ /** The JSON Schema types a credential's value may have. */
94
+ const SEALABLE_TYPES = ["string", "number", "integer"];
95
+ /** The fields of an event's config schema a save seals: each property the schema marks as a credential (format: password,
96
+ * or writeOnly), whatever its name; and each named like a credential that may hold a string or a number (its type is one
97
+ * of those, or says none). What the console's form takes as a password. */
98
+ export const sealedSchemaFields = (schema) => {
99
+ const properties = isObject(schema) && isObject(schema.properties) ? schema.properties : {};
100
+ return Object.entries(properties).filter(([name, property]) => {
101
+ if (isObject(property) && (property.format === "password" || property.writeOnly === true))
102
+ return true;
103
+ const type = isObject(property) ? property.type : undefined;
104
+ return secretConfigName(name) && (type === undefined || SEALABLE_TYPES.includes(String(type)) || (Array.isArray(type) && type.some((one) => SEALABLE_TYPES.includes(String(one)))));
105
+ }).map(([name]) => name);
106
+ };
107
+ const pointerOf = (path) => `/${path.map((key) => key.replace(/~/g, "~0").replace(/\//g, "~1")).join("/")}`;
108
+ /** Every credential `config` holds in the clear, at any depth: a sealable value (sealableValue: a string, not empty, or a
109
+ * number), not SEALED_MASK, whose field is named like a credential (secretConfigName), or that is anywhere inside an
110
+ * object or array so named; and every string that is an address carrying a credential (credentialUrl), wherever it is. A create takes one
111
+ * at the top level alone (composio-triggers.ts make); a trigger an earlier server kept may hold one deeper. */
112
+ export const configSecrets = (config) => {
113
+ const found = [];
114
+ const walk = (node, path, named) => {
115
+ if (typeof node === "string" || typeof node === "number") {
116
+ if ((named || (typeof node === "string" && credentialUrl(node))) && sealableValue(node) && node !== SEALED_MASK)
117
+ found.push({ name: path.length === 1 ? path[0] : pointerOf(path), path, value: node });
118
+ }
119
+ else if (Array.isArray(node))
120
+ node.forEach((item, i) => walk(item, [...path, String(i)], named));
121
+ else if (isObject(node))
122
+ for (const [key, item] of Object.entries(node))
123
+ walk(item, [...path, key], named || secretConfigName(key));
124
+ };
125
+ if (isObject(config))
126
+ for (const [key, item] of Object.entries(config))
127
+ walk(item, [key], secretConfigName(key));
128
+ return found;
129
+ };
130
+ /** `config` with each of `secrets` as SEALED_MASK, at its place. */
131
+ const maskedConfig = (config, secrets) => {
132
+ const copy = structuredClone(config);
133
+ for (const { path } of secrets) {
134
+ let node = copy;
135
+ for (const key of path.slice(0, -1))
136
+ node = node[key];
137
+ node[path.at(-1)] = SEALED_MASK;
138
+ }
139
+ return copy;
140
+ };
141
+ /** `sent`, a PATCH's config, with SEALED_MASK put back at each place `shown` (the config as answered) holds a field named
142
+ * in `sealed` (sealed_config: a top-level name, or a JSON Pointer read as configSecrets writes it, pointerOf) and `sent`
143
+ * leaves it out under an object it sends: a sealed value left out is kept. A copy: `sent` is not changed. */
144
+ export const sealedKept = (sent, shown, sealed) => {
145
+ const names = new Set(sealed);
146
+ const places = [];
147
+ const walk = (node, path) => {
148
+ if (path.length && names.has(path.length === 1 ? path[0] : pointerOf(path)))
149
+ places.push(path);
150
+ else if (Array.isArray(node))
151
+ node.forEach((item, i) => walk(item, [...path, String(i)]));
152
+ else if (isObject(node))
153
+ for (const [key, item] of Object.entries(node))
154
+ walk(item, [...path, key]);
155
+ };
156
+ walk(shown, []);
157
+ const copy = structuredClone(sent);
158
+ for (const path of places) {
159
+ let node = copy;
160
+ for (const key of path.slice(0, -1))
161
+ node = isObject(node) ? node[key] : undefined;
162
+ if (isObject(node) && node[path.at(-1)] === undefined)
163
+ node[path.at(-1)] = SEALED_MASK;
164
+ }
165
+ return copy;
166
+ };
167
+ /** `source` as every answer sends it: each credential in its config (configSecrets, at any depth) as SEALED_MASK, and
168
+ * named in sealed_config, whether it is sealed yet or still kept in the clear (a trigger saved before this rule, until
169
+ * the next start seals it: composio-triggers.ts sealKept). */
170
+ export const shownSource = (source) => {
171
+ const config = source.config;
172
+ const clear = configSecrets(config);
173
+ if (!clear.length || !isObject(config))
174
+ return source;
175
+ const sealed = Array.isArray(source[SEALED_FIELD]) ? source[SEALED_FIELD] : [];
176
+ return { ...source, config: maskedConfig(config, clear), [SEALED_FIELD]: [...new Set([...sealed, ...clear.map((secret) => secret.name)])] };
177
+ };
29
178
  const jsonOf = (text) => {
30
179
  try {
31
180
  return JSON.parse(text);
@@ -39,7 +188,7 @@ const jsonOf = (text) => {
39
188
  function fieldsOf(value, bad) {
40
189
  let failed = false;
41
190
  const fail = (...args) => ((failed = true), bad(...args));
42
- const { server, event, config, instance_id: instance, hook } = value;
191
+ const { server, event, config, instance_id: instance, hook, [SEALED_FIELD]: sealed } = value;
43
192
  if (typeof server !== "string" || !MCP_SERVER_NAME.test(server))
44
193
  fail("server", server === undefined ? "missing" : "invalid", "server is the name of a saved Composio MCP server (Settings → MCP servers), whose key and account the trigger uses");
45
194
  if (typeof event !== "string" || !COMPOSIO_EVENT.test(event))
@@ -50,6 +199,8 @@ function fieldsOf(value, bad) {
50
199
  fail("instance_id", "invalid", "instance_id is Composio's id for the trigger's instance, set by this server");
51
200
  if (hook !== undefined && !(typeof hook === "string" && COMPOSIO_HOOK.test(hook)))
52
201
  fail("hook", "invalid", "hook is the id of the project's route here, set by this server");
202
+ if (sealed !== undefined && !(Array.isArray(sealed) && sealed.length <= 100 && sealed.every((name) => typeof name === "string" && name.length <= 200)))
203
+ fail(SEALED_FIELD, "invalid", `${SEALED_FIELD} names the config's sealed fields, set by this server`);
53
204
  if (value[MOVE_FIELD] !== undefined && value[MOVE_FIELD] !== true)
54
205
  fail(MOVE_FIELD, "invalid", `${MOVE_FIELD} is true, or left out`);
55
206
  const accept = value.accept === undefined ? undefined : acceptOf(value.accept, fail);
@@ -59,7 +210,7 @@ function fieldsOf(value, bad) {
59
210
  return undefined;
60
211
  return {
61
212
  kind: "composio", server: server, event: event, config: config,
62
- ...(accept ? { accept } : {}), ...(typeof instance === "string" ? { instance_id: instance } : {}), ...(typeof hook === "string" ? { hook } : {}), ...(value[MOVE_FIELD] === true ? { [MOVE_FIELD]: true } : {}),
213
+ ...(accept ? { accept } : {}), ...(typeof instance === "string" ? { instance_id: instance } : {}), ...(typeof hook === "string" ? { hook } : {}), ...(Array.isArray(sealed) ? { [SEALED_FIELD]: sealed } : {}), ...(value[MOVE_FIELD] === true ? { [MOVE_FIELD]: true } : {}),
63
214
  };
64
215
  }
65
216
  export const composio = {
@@ -67,8 +218,9 @@ export const composio = {
67
218
  label: "Composio trigger",
68
219
  delivery: "push",
69
220
  owner: false,
70
- // Each project's subscription secret, Composio's own, sealed under its hook's scope (composio-triggers.ts keeps it).
71
- settings: { scope: "server", fields: { [COMPOSIO_SECRET]: {} } },
221
+ // Each project's subscription secret, Composio's own, sealed under its hook's scope, and each trigger's sealed config
222
+ // value under its own (configScope): composio-triggers.ts keeps them.
223
+ settings: { scope: "server", fields: { [COMPOSIO_SECRET]: {}, [CONFIG_SECRET]: {}, [CONFIG_UNLISTED]: { public: true } } },
72
224
  describe: '{kind: "composio", server, event, config, accept?: [{event, where?}], move_subscription?: true}',
73
225
  fires: "an event of a saved Composio server's toolkit that Composio delivers to /hooks/composio/{hook} for the trigger's instance, that its `accept` takes (`composio`)",
74
226
  firedBy: "`composio`: an event Composio delivered for the trigger's instance (the delivery's metadata.trigger_id) that its accept took, its key from the trigger and the delivery's `webhook-id`.",
@@ -77,18 +229,20 @@ export const composio = {
77
229
  kind: { const: "composio" },
78
230
  server: { type: "string", pattern: MCP_SERVER_NAME.source, description: "A saved Composio MCP server (Settings → MCP servers): its key makes the instance, for the account it is connected as." },
79
231
  event: { type: "string", pattern: COMPOSIO_EVENT.source, description: "One of the server's toolkit's events, Composio's trigger slug (GET /settings/mcp-servers/{name}/composio/events)." },
80
- config: { type: "object", description: "The event's config, as its schema in the events list says (GitHub's new-issue event: {owner, repo})." },
232
+ config: { type: "object", description: `The event's config, as its schema in the events list says (GitHub's new-issue event: {owner, repo}). A field named like a credential (a word of its name, read as its singular, is secret, password, passwd, passphrase, passcode, pwd, pat, token, credential, apikey, hapikey, jwt, dsn, sig, authorization, bearer or cookie, unless a count word (max, min, num, number, count, limit, total, used, usage, budget, remaining, per, length, size, quota) is right beside it: max_tokens and token_count are counts; it has connection then string; or its last word is key: developer_api_key, api_keys), or one the event's schema marks with format: password or writeOnly, holding a string or a number, is sealed at the save, as is any http(s) address with a password in its user part or a query parameter so named with a value: Composio gets it, and every answer has "${SEALED_MASK}" in its place, the field named in ${SEALED_FIELD}. One below the config's top level is refused 422. A PATCH that leaves it out or sends "${SEALED_MASK}" keeps it; another value is a change to the config, refused as any is.` },
81
233
  }, {
82
234
  accept: { ...ACCEPT_SCHEMA, description: "Optional: which of the event's deliveries fire it. A rule's `event` is the trigger's own, `where` pointers read the delivery, its event's data under `/data` (`/data/title`). None: every delivery for its instance fires." },
83
235
  instance_id: { type: "string", readOnly: true, description: "Composio's id for the trigger's instance, set by this server when it makes it: the delivery's metadata.trigger_id. Triggers with the same server, event and config share one." },
236
+ [SEALED_FIELD]: { type: "array", items: { type: "string" }, readOnly: true, description: `The config's sealed fields, set by this server at the save: each answered as "${SEALED_MASK}", its value kept sealed here. Each is a top-level field's name, or, for one an earlier server kept below the top level, its JSON Pointer (/auth/api_key).` },
84
237
  hook: { type: "string", pattern: COMPOSIO_HOOK.source, readOnly: true, description: "The id of the project's route here, /hooks/composio/{hook}, set by this server: the address of the project's webhook subscription on Composio." },
85
238
  [MOVE_FIELD]: { type: "boolean", enum: [true], writeOnly: true, description: "At a create alone, never kept: the project's webhook subscription is at another address, and the owner moves it here. Without it, such a create is refused 409 composio_subscription_elsewhere, naming the address." },
86
239
  }),
87
240
  ],
88
241
  parse(value, _now, bad, issues) {
89
- issues.push(...unknownSourceFields(value, ["kind", "server", "event", "config", "accept", "instance_id", "hook", MOVE_FIELD]));
242
+ issues.push(...unknownSourceFields(value, ["kind", "server", "event", "config", "accept", "instance_id", "hook", SEALED_FIELD, MOVE_FIELD]));
90
243
  return fieldsOf(value, bad);
91
244
  },
245
+ shown: shownSource,
92
246
  wellFormed: (source) => {
93
247
  const read = fieldsOf(source, () => { });
94
248
  return read !== undefined && typeof read.instance_id === "string" && typeof read.hook === "string";
@@ -50,8 +50,15 @@ export type TriggerUpstream = {
50
50
  patched(was: Source, given: Source): Source;
51
51
  /** The trigger `id` of `source`, turned on or off here: the same there. */
52
52
  turned(source: Source, id: string, on: boolean): Promise<Json | undefined>;
53
- /** The trigger `id` of `source`, deleted here: removed there. */
53
+ /** The trigger `id` of `source`, deleted here: removed there, with what it keeps here for it (a sealed config). */
54
54
  removed(source: Source, id: string): Promise<Json | undefined>;
55
+ /** The trigger `id` of `source`, still here: removed there, then `here` (its delete here) in the same step, so no other
56
+ * trigger's removal there reads it as still holding what they share; what it keeps here for it is left (`forgotten`
57
+ * drops that once the trigger is gone). Undefined when it is gone there and `here` is done; what could not be done
58
+ * there, said, with `here` not run. A refusal of `here`'s is thrown. */
59
+ removedThere(source: Source, id: string, here: () => Promise<void>): Promise<Json | undefined>;
60
+ /** What it keeps here for the trigger `id` of `source` (a sealed config), dropped once the trigger is gone here. */
61
+ forgotten(source: Source, id: string): Promise<void>;
55
62
  };
56
63
  /** `max_cost_usd`: each run's cap; absent, the agent's default as it stands when the firing starts (one of the two is
57
64
  * required: server.ts targetIssues and start). */
@@ -176,6 +183,11 @@ export declare class Triggers {
176
183
  /** Each trigger's firings, driven one after another in the order asked: a firing's overlap check reads what the one
177
184
  * before it settled to. */
178
185
  private readonly turns;
186
+ /** Each trigger's removals and the edits that name a target (the one way it moves to another agent), one after another
187
+ * on this server: a move never lands between a template update's delete of its Composio instance and its conditional
188
+ * delete of the row (remove), so a moved trigger never stands on an instance that delete took. Across servers the
189
+ * store's conditional write holds the row. Removed from the map once idle. */
190
+ private readonly edits;
179
191
  /** Whether a firing waits for its trigger's room (max_active_runs): the timer then reads the store every WAIT_POLL_MS. */
180
192
  private waiting;
181
193
  /** The triggers whose day-kept keys are at their cap, said once until they are under it again. */
@@ -295,7 +307,7 @@ export declare class Triggers {
295
307
  } | null;
296
308
  }[];
297
309
  }>;
298
- create(body: Json): Promise<{
310
+ create(body: Json, own?: TriggerOwn): Promise<{
299
311
  secret?: string;
300
312
  id: string;
301
313
  name: string;
@@ -358,6 +370,7 @@ export declare class Triggers {
358
370
  name: string;
359
371
  enabled: boolean;
360
372
  source: Source;
373
+ updatedAt: number;
361
374
  }[]>;
362
375
  /** Every trigger of source `kind` that is on, turned off because the connection it needs is gone (`disabled: {reason:
363
376
  * "connection_lost", detail}`), and said; how many. They are kept: on again once it is back. */
@@ -377,6 +390,9 @@ export declare class Triggers {
377
390
  }[]>;
378
391
  /** Refused (409 agent_archived) when agent `agentId` is archived: a trigger made on, turned on or aimed at it. */
379
392
  private needAgentOn;
393
+ /** Refused (409 agent_not_runnable, agents.ts agentDeleting) when agent `agentId` is being deleted: another system's
394
+ * agent with an archive time, which only its delete writes (agent-delete.ts). */
395
+ private needNotDeleting;
380
396
  /** The store's refusal of a trigger left on for an archived agent (an archive that committed past needAgentOn) as the
381
397
  * same 409; undefined for any other error. */
382
398
  private archivedRefusal;
@@ -401,7 +417,7 @@ export declare class Triggers {
401
417
  /** PATCH: any of name, enabled, source, target, catchup_window_s and max_active_runs. Enabled again, or its source changed, a trigger goes on from now: a
402
418
  * paused range is skipped, never caught up. Only the fields named change, applied to the trigger as it stands once
403
419
  * the target's check is done: an edit made meanwhile keeps its own. */
404
- update(id: string, body: Json): Promise<{
420
+ update(id: string, body: Json, own?: TriggerOwn): Promise<{
405
421
  id: string;
406
422
  name: string;
407
423
  enabled: boolean;
@@ -439,8 +455,37 @@ export declare class Triggers {
439
455
  } | null | undefined;
440
456
  hook_url?: string | undefined;
441
457
  }>;
442
- /** The trigger deleted, and what its sender keeps of it removed after (said, when it could not be: the delete holds). */
443
- remove(id: string): Promise<Json | undefined>;
458
+ private updating;
459
+ /** One try of `update`: undefined when its source write was refused because the trigger changed since it was read and
460
+ * `retry` (try again); refused on the last try, precondition_failed. */
461
+ private updateOnce;
462
+ /** The trigger deleted, and what its sender keeps of it removed after (said, when it could not be: the delete holds).
463
+ * On its agent's condition (`onAgent`: a template update's removal), what its sender keeps goes first: one its sender
464
+ * did not remove is said, and the trigger is kept here as it was (its row, its package mark, its sealed config and
465
+ * whether it is on), for the next update to remove; once it is gone there, the trigger goes here while it is still that
466
+ * agent's, then what its sender kept here for it. */
467
+ remove(id: string, own?: Pick<TriggerOwn, "onAgent">): Promise<Json | undefined>;
468
+ private removing;
469
+ /** `value` as a create keeps a source (its adapter's defaults filled in: a feed's every_s), or undefined when a create
470
+ * would refuse it. */
471
+ sourceAsKept(value: unknown): Source | undefined;
472
+ /** A deleted agent's trigger (agent-delete.ts), its first half: what its sender keeps of it removed there, the trigger
473
+ * kept here, so a failure, or a stop before the second half (removeHere), leaves the row that names what is left to
474
+ * remove for the next delete to find. Throws `unavailable` with what could not be done there. */
475
+ removeThere(id: string): Promise<void>;
476
+ /** The second half's first part, once removeThere is done: the trigger's adapter settings removed, its row kept. */
477
+ removeSettings(id: string): Promise<void>;
478
+ /** The second half, once removeThere is done: the trigger deleted here, its adapter settings and then its row. */
479
+ removeHere(id: string): Promise<void>;
480
+ /** A trigger's adapter settings (a webhook's secret, a poll's cursor) removed; nothing else of it. */
481
+ private dropSettings;
482
+ /** The trigger's settings and row removed. Without `onAgent`, its settings first, then its row: the settings have no
483
+ * link to the row, so a failure or a stop between the two leaves the row, which the next remove finds, never settings
484
+ * with no trigger left to name them. With `onAgent` (a template update's removal), the row first, on its agent's
485
+ * condition compared in the delete, then its settings: a trigger moved to another agent meanwhile keeps both. A stop
486
+ * between the two there leaves settings no row names (keyed by an id never used again), never a moved trigger
487
+ * without its own. */
488
+ private dropHere;
444
489
  /** Run now: one firing per Idempotency-Key, driven before the answer. `created` false: the key's firing, as it stands. */
445
490
  fire(id: string, idempotencyKey: string): Promise<{
446
491
  created: boolean;
@@ -450,6 +495,12 @@ export declare class Triggers {
450
495
  * then each failure's trigger.failed queued that is not yet, each due firing whose time has come driven, each waiting
451
496
  * firing whose trigger has room again driven (one read for all of them), and the timer armed again. */
452
497
  private tick;
498
+ /** `work` on trigger `id` once every edit or removal of it asked before has settled (edits). Neither update nor remove
499
+ * calls the other, so a turn never waits on itself. Only a target edit takes a turn: any other edit runs beside one, as
500
+ * concurrent edits each keep their change (trigger-engine.test.mjs, two edits at once, one a target whose check is
501
+ * slow: the source edit lands while the target's check waits). One racing a removal writes its row while the row is
502
+ * there, or finds it gone (not_found): the store's update changes no row a delete took. */
503
+ private one;
453
504
  /** `key`'s firing driven after every firing of its trigger asked before it. */
454
505
  private inTurn;
455
506
  /** Each of `triggers` turned off, with why its source no longer reads, and said. */
@@ -567,6 +618,14 @@ export declare class Triggers {
567
618
  * source says of it), then a line saying what fired it and when, in the trigger's zone. */
568
619
  private inputOf;
569
620
  }
621
+ /** What a template apply alone gives a trigger write, never an API body: `templateId`, the package mark it makes the
622
+ * trigger with or sets on one it keeps in place (TriggerRow.templateId); `onAgent`, the agent it read the trigger on, so
623
+ * the write (an update, a removal) is made only while the trigger is still that agent's, compared in the store's
624
+ * statement: one moved to another agent meanwhile is not_found, and nothing is written. */
625
+ export interface TriggerOwn {
626
+ readonly templateId?: string;
627
+ readonly onAgent?: string;
628
+ }
570
629
  declare function firingView(firing: FiringRow): {
571
630
  attempts?: number | undefined;
572
631
  retry_at?: string | undefined;