@proofoftech/flowsafe 0.11.0 → 0.13.0

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 +54 -0
  2. package/README.md +91 -44
  3. package/deployment-identity-protocol.d.mts +52 -0
  4. package/deployment-identity-protocol.mjs +231 -0
  5. package/dist/agent-host/approval-resumer.d.ts +3 -3
  6. package/dist/agent-host/approval-resumer.d.ts.map +1 -1
  7. package/dist/agent-host/approval-resumer.js +6 -7
  8. package/dist/agent-host/approval-resumer.js.map +1 -1
  9. package/dist/agent-host/catalog.js +2 -2
  10. package/dist/agent-host/catalog.js.map +1 -1
  11. package/dist/agent-host/index.d.ts +2 -2
  12. package/dist/agent-host/index.d.ts.map +1 -1
  13. package/dist/agent-host/index.js.map +1 -1
  14. package/dist/agent-host/router.d.ts +2 -2
  15. package/dist/agent-host/router.d.ts.map +1 -1
  16. package/dist/agent-host/router.js +22 -54
  17. package/dist/agent-host/router.js.map +1 -1
  18. package/dist/agent-host/thread-host.d.ts +42 -8
  19. package/dist/agent-host/thread-host.d.ts.map +1 -1
  20. package/dist/agent-host/thread-host.js +533 -106
  21. package/dist/agent-host/thread-host.js.map +1 -1
  22. package/dist/agent-host/thread-topology.d.ts +28 -7
  23. package/dist/agent-host/thread-topology.d.ts.map +1 -1
  24. package/dist/agent-host/thread-topology.js +97 -39
  25. package/dist/agent-host/thread-topology.js.map +1 -1
  26. package/dist/agent-host/trusted-context.d.ts.map +1 -1
  27. package/dist/agent-host/trusted-context.js +3 -1
  28. package/dist/agent-host/trusted-context.js.map +1 -1
  29. package/dist/agent-host/types.d.ts +2 -0
  30. package/dist/agent-host/types.d.ts.map +1 -1
  31. package/dist/agent-runner/agent-run-state.d.ts +9 -8
  32. package/dist/agent-runner/agent-run-state.d.ts.map +1 -1
  33. package/dist/agent-runner/agent-run-state.js +78 -40
  34. package/dist/agent-runner/agent-run-state.js.map +1 -1
  35. package/dist/agent-runner/durable-agent-runner.d.ts +18 -16
  36. package/dist/agent-runner/durable-agent-runner.d.ts.map +1 -1
  37. package/dist/agent-runner/durable-agent-runner.js +120 -43
  38. package/dist/agent-runner/durable-agent-runner.js.map +1 -1
  39. package/dist/agent-runner/index.d.ts +1 -1
  40. package/dist/agent-runner/index.d.ts.map +1 -1
  41. package/dist/agent-runner/index.js +1 -1
  42. package/dist/agent-runner/index.js.map +1 -1
  43. package/dist/approval-api/actor-context.d.ts +67 -0
  44. package/dist/approval-api/actor-context.d.ts.map +1 -0
  45. package/dist/approval-api/actor-context.js +120 -0
  46. package/dist/approval-api/actor-context.js.map +1 -0
  47. package/dist/approval-api/contract.d.ts +12 -23
  48. package/dist/approval-api/contract.d.ts.map +1 -1
  49. package/dist/approval-api/d1-store.d.ts +7 -15
  50. package/dist/approval-api/d1-store.d.ts.map +1 -1
  51. package/dist/approval-api/d1-store.js +83 -159
  52. package/dist/approval-api/d1-store.js.map +1 -1
  53. package/dist/approval-api/grants.d.ts +3 -17
  54. package/dist/approval-api/grants.d.ts.map +1 -1
  55. package/dist/approval-api/grants.js +19 -39
  56. package/dist/approval-api/grants.js.map +1 -1
  57. package/dist/approval-api/index.d.ts +8 -8
  58. package/dist/approval-api/index.d.ts.map +1 -1
  59. package/dist/approval-api/index.js +5 -5
  60. package/dist/approval-api/index.js.map +1 -1
  61. package/dist/approval-api/principal.d.ts +29 -30
  62. package/dist/approval-api/principal.d.ts.map +1 -1
  63. package/dist/approval-api/principal.js +73 -54
  64. package/dist/approval-api/principal.js.map +1 -1
  65. package/dist/approval-api/resource-ownership.d.ts +64 -0
  66. package/dist/approval-api/resource-ownership.d.ts.map +1 -0
  67. package/dist/approval-api/resource-ownership.js +329 -0
  68. package/dist/approval-api/resource-ownership.js.map +1 -0
  69. package/dist/approval-api/retention.d.ts +6 -11
  70. package/dist/approval-api/retention.d.ts.map +1 -1
  71. package/dist/approval-api/retention.js +7 -12
  72. package/dist/approval-api/retention.js.map +1 -1
  73. package/dist/approval-api/router.d.ts +9 -8
  74. package/dist/approval-api/router.d.ts.map +1 -1
  75. package/dist/approval-api/router.js +50 -18
  76. package/dist/approval-api/router.js.map +1 -1
  77. package/dist/approval-api/service.d.ts +26 -36
  78. package/dist/approval-api/service.d.ts.map +1 -1
  79. package/dist/approval-api/service.js +104 -166
  80. package/dist/approval-api/service.js.map +1 -1
  81. package/dist/approval-api/store-factory.d.ts +19 -0
  82. package/dist/approval-api/store-factory.d.ts.map +1 -0
  83. package/dist/approval-api/store-factory.js +49 -0
  84. package/dist/approval-api/store-factory.js.map +1 -0
  85. package/dist/approval-api/store.d.ts +22 -36
  86. package/dist/approval-api/store.d.ts.map +1 -1
  87. package/dist/approval-api/store.js +48 -66
  88. package/dist/approval-api/store.js.map +1 -1
  89. package/dist/approval-api/types.d.ts +28 -22
  90. package/dist/approval-api/types.d.ts.map +1 -1
  91. package/dist/approval-api/types.js +51 -3
  92. package/dist/approval-api/types.js.map +1 -1
  93. package/dist/approval-ui/client.js +3 -3
  94. package/dist/approval-ui/client.js.map +1 -1
  95. package/dist/approval-ui/stream.d.ts +4 -4
  96. package/dist/approval-ui/stream.d.ts.map +1 -1
  97. package/dist/approval-ui/stream.js +2 -2
  98. package/dist/approval-ui/tips.d.ts +1 -1
  99. package/dist/approval-ui/tips.js +1 -1
  100. package/dist/approval-ui/tips.js.map +1 -1
  101. package/dist/approval-ui/use-approval-dashboard.d.ts +3 -3
  102. package/dist/approval-ui/use-approval-dashboard.js +1 -1
  103. package/dist/artifacts/index.d.ts +2 -3
  104. package/dist/artifacts/index.d.ts.map +1 -1
  105. package/dist/artifacts/index.js +9 -8
  106. package/dist/artifacts/index.js.map +1 -1
  107. package/dist/audit-export/audit-proxy.d.ts +71 -0
  108. package/dist/audit-export/audit-proxy.d.ts.map +1 -0
  109. package/dist/audit-export/audit-proxy.js +142 -0
  110. package/dist/audit-export/audit-proxy.js.map +1 -0
  111. package/dist/audit-export/index.d.ts +4 -7
  112. package/dist/audit-export/index.d.ts.map +1 -1
  113. package/dist/audit-export/index.js +1 -4
  114. package/dist/audit-export/index.js.map +1 -1
  115. package/dist/audit-export/queue-types.d.ts +5 -0
  116. package/dist/audit-export/queue-types.d.ts.map +1 -0
  117. package/dist/audit-export/queue-types.js +3 -0
  118. package/dist/audit-export/queue-types.js.map +1 -0
  119. package/dist/background-tasks/d1-storage.d.ts +9 -19
  120. package/dist/background-tasks/d1-storage.d.ts.map +1 -1
  121. package/dist/background-tasks/d1-storage.js +22 -52
  122. package/dist/background-tasks/d1-storage.js.map +1 -1
  123. package/dist/background-tasks/host.d.ts +4 -6
  124. package/dist/background-tasks/host.d.ts.map +1 -1
  125. package/dist/background-tasks/host.js +14 -17
  126. package/dist/background-tasks/host.js.map +1 -1
  127. package/dist/background-tasks/index.d.ts +1 -1
  128. package/dist/background-tasks/index.d.ts.map +1 -1
  129. package/dist/background-tasks/index.js +3 -3
  130. package/dist/background-tasks/index.js.map +1 -1
  131. package/dist/background-tasks/routes.d.ts +8 -4
  132. package/dist/background-tasks/routes.d.ts.map +1 -1
  133. package/dist/background-tasks/routes.js +33 -31
  134. package/dist/background-tasks/routes.js.map +1 -1
  135. package/dist/deployment-identity-protocol.d.ts +3 -0
  136. package/dist/deployment-identity-protocol.d.ts.map +1 -0
  137. package/dist/deployment-identity-protocol.js +3 -0
  138. package/dist/deployment-identity-protocol.js.map +1 -0
  139. package/dist/do-runner/breakwater-keys.d.ts +7 -5
  140. package/dist/do-runner/breakwater-keys.d.ts.map +1 -1
  141. package/dist/do-runner/breakwater-keys.js +7 -5
  142. package/dist/do-runner/breakwater-keys.js.map +1 -1
  143. package/dist/do-runner/cf-types.d.ts +18 -12
  144. package/dist/do-runner/cf-types.d.ts.map +1 -1
  145. package/dist/do-runner/cf-types.js.map +1 -1
  146. package/dist/do-runner/d1-storage.d.ts +51 -189
  147. package/dist/do-runner/d1-storage.d.ts.map +1 -1
  148. package/dist/do-runner/d1-storage.js +111 -362
  149. package/dist/do-runner/d1-storage.js.map +1 -1
  150. package/dist/do-runner/deployment-identity.d.ts +121 -0
  151. package/dist/do-runner/deployment-identity.d.ts.map +1 -0
  152. package/dist/do-runner/deployment-identity.js +272 -0
  153. package/dist/do-runner/deployment-identity.js.map +1 -0
  154. package/dist/do-runner/do-error-response.d.ts +1 -1
  155. package/dist/do-runner/do-error-response.d.ts.map +1 -1
  156. package/dist/do-runner/do-error-response.js +7 -1
  157. package/dist/do-runner/do-error-response.js.map +1 -1
  158. package/dist/do-runner/durable-object.d.ts +23 -16
  159. package/dist/do-runner/durable-object.d.ts.map +1 -1
  160. package/dist/do-runner/durable-object.js +303 -70
  161. package/dist/do-runner/durable-object.js.map +1 -1
  162. package/dist/do-runner/execution-context.d.ts +1 -0
  163. package/dist/do-runner/execution-context.d.ts.map +1 -1
  164. package/dist/do-runner/execution-context.js +4 -7
  165. package/dist/do-runner/execution-context.js.map +1 -1
  166. package/dist/do-runner/execution-principal-header.d.ts +16 -0
  167. package/dist/do-runner/execution-principal-header.d.ts.map +1 -0
  168. package/dist/do-runner/execution-principal-header.js +20 -0
  169. package/dist/do-runner/execution-principal-header.js.map +1 -0
  170. package/dist/do-runner/hub-do.d.ts +17 -25
  171. package/dist/do-runner/hub-do.d.ts.map +1 -1
  172. package/dist/do-runner/hub-do.js +63 -59
  173. package/dist/do-runner/hub-do.js.map +1 -1
  174. package/dist/do-runner/index.d.ts +12 -10
  175. package/dist/do-runner/index.d.ts.map +1 -1
  176. package/dist/do-runner/index.js +10 -9
  177. package/dist/do-runner/index.js.map +1 -1
  178. package/dist/do-runner/init.d.ts +0 -7
  179. package/dist/do-runner/init.d.ts.map +1 -1
  180. package/dist/do-runner/init.js +1 -2
  181. package/dist/do-runner/init.js.map +1 -1
  182. package/dist/do-runner/memory-id.d.ts +8 -25
  183. package/dist/do-runner/memory-id.d.ts.map +1 -1
  184. package/dist/do-runner/memory-id.js +25 -52
  185. package/dist/do-runner/memory-id.js.map +1 -1
  186. package/dist/do-runner/path-safe-id.d.ts +2 -48
  187. package/dist/do-runner/path-safe-id.d.ts.map +1 -1
  188. package/dist/do-runner/path-safe-id.js +3 -93
  189. package/dist/do-runner/path-safe-id.js.map +1 -1
  190. package/dist/do-runner/pubsub.d.ts +1 -1
  191. package/dist/do-runner/pubsub.js +1 -1
  192. package/dist/do-runner/runtime.d.ts +47 -34
  193. package/dist/do-runner/runtime.d.ts.map +1 -1
  194. package/dist/do-runner/runtime.js +281 -143
  195. package/dist/do-runner/runtime.js.map +1 -1
  196. package/dist/do-runner/schedule-source.d.ts +81 -0
  197. package/dist/do-runner/schedule-source.d.ts.map +1 -0
  198. package/dist/do-runner/schedule-source.js +64 -0
  199. package/dist/do-runner/schedule-source.js.map +1 -0
  200. package/dist/do-runner/table-prefix.d.ts +3 -0
  201. package/dist/do-runner/table-prefix.d.ts.map +1 -0
  202. package/dist/do-runner/table-prefix.js +17 -0
  203. package/dist/do-runner/table-prefix.js.map +1 -0
  204. package/dist/do-runner/thread-do.d.ts +18 -32
  205. package/dist/do-runner/thread-do.d.ts.map +1 -1
  206. package/dist/do-runner/thread-do.js +52 -74
  207. package/dist/do-runner/thread-do.js.map +1 -1
  208. package/dist/goals/objective-routes.d.ts +7 -4
  209. package/dist/goals/objective-routes.d.ts.map +1 -1
  210. package/dist/goals/objective-routes.js +58 -43
  211. package/dist/goals/objective-routes.js.map +1 -1
  212. package/dist/host-kit/approval-bridge.d.ts +18 -21
  213. package/dist/host-kit/approval-bridge.d.ts.map +1 -1
  214. package/dist/host-kit/approval-bridge.js +37 -37
  215. package/dist/host-kit/approval-bridge.js.map +1 -1
  216. package/dist/host-kit/bearer-auth.d.ts +3 -4
  217. package/dist/host-kit/bearer-auth.d.ts.map +1 -1
  218. package/dist/host-kit/bearer-auth.js +7 -11
  219. package/dist/host-kit/bearer-auth.js.map +1 -1
  220. package/dist/host-kit/do-run-topology.d.ts +14 -5
  221. package/dist/host-kit/do-run-topology.d.ts.map +1 -1
  222. package/dist/host-kit/do-run-topology.js +47 -15
  223. package/dist/host-kit/do-run-topology.js.map +1 -1
  224. package/dist/host-kit/env-vars.d.ts +1 -1
  225. package/dist/host-kit/env-vars.js +1 -1
  226. package/dist/host-kit/flowsafe-worker.d.ts +159 -80
  227. package/dist/host-kit/flowsafe-worker.d.ts.map +1 -1
  228. package/dist/host-kit/flowsafe-worker.js +629 -142
  229. package/dist/host-kit/flowsafe-worker.js.map +1 -1
  230. package/dist/host-kit/host-approval-service.d.ts +62 -54
  231. package/dist/host-kit/host-approval-service.d.ts.map +1 -1
  232. package/dist/host-kit/host-approval-service.js +90 -61
  233. package/dist/host-kit/host-approval-service.js.map +1 -1
  234. package/dist/host-kit/hub-topology.d.ts +6 -7
  235. package/dist/host-kit/hub-topology.d.ts.map +1 -1
  236. package/dist/host-kit/hub-topology.js +16 -12
  237. package/dist/host-kit/hub-topology.js.map +1 -1
  238. package/dist/host-kit/index.d.ts +13 -11
  239. package/dist/host-kit/index.d.ts.map +1 -1
  240. package/dist/host-kit/index.js +9 -12
  241. package/dist/host-kit/index.js.map +1 -1
  242. package/dist/host-kit/maintenance-capability.d.ts +58 -0
  243. package/dist/host-kit/maintenance-capability.d.ts.map +1 -0
  244. package/dist/host-kit/maintenance-capability.js +268 -0
  245. package/dist/host-kit/maintenance-capability.js.map +1 -0
  246. package/dist/host-kit/memory-boundary.d.ts +4 -19
  247. package/dist/host-kit/memory-boundary.d.ts.map +1 -1
  248. package/dist/host-kit/memory-boundary.js +12 -27
  249. package/dist/host-kit/memory-boundary.js.map +1 -1
  250. package/dist/host-kit/resource-access.d.ts +4 -0
  251. package/dist/host-kit/resource-access.d.ts.map +1 -0
  252. package/dist/host-kit/resource-access.js +12 -0
  253. package/dist/host-kit/resource-access.js.map +1 -0
  254. package/dist/host-kit/run-router.d.ts +25 -15
  255. package/dist/host-kit/run-router.d.ts.map +1 -1
  256. package/dist/host-kit/run-router.js +61 -46
  257. package/dist/host-kit/run-router.js.map +1 -1
  258. package/dist/host-kit/state-egress.d.ts +51 -0
  259. package/dist/host-kit/state-egress.d.ts.map +1 -0
  260. package/dist/host-kit/state-egress.js +120 -0
  261. package/dist/host-kit/state-egress.js.map +1 -0
  262. package/dist/host-kit/stream-router.d.ts +9 -4
  263. package/dist/host-kit/stream-router.d.ts.map +1 -1
  264. package/dist/host-kit/stream-router.js +45 -38
  265. package/dist/host-kit/stream-router.js.map +1 -1
  266. package/dist/host-kit/stream-ticket.d.ts +10 -10
  267. package/dist/host-kit/stream-ticket.d.ts.map +1 -1
  268. package/dist/host-kit/stream-ticket.js +60 -90
  269. package/dist/host-kit/stream-ticket.js.map +1 -1
  270. package/dist/host-kit/thread-topology.d.ts +17 -11
  271. package/dist/host-kit/thread-topology.d.ts.map +1 -1
  272. package/dist/host-kit/thread-topology.js +33 -59
  273. package/dist/host-kit/thread-topology.js.map +1 -1
  274. package/dist/host-kit/verifier.d.ts +6 -6
  275. package/dist/host-kit/verifier.d.ts.map +1 -1
  276. package/dist/host-kit/verifier.js +51 -119
  277. package/dist/host-kit/verifier.js.map +1 -1
  278. package/dist/http-body.d.ts +20 -0
  279. package/dist/http-body.d.ts.map +1 -0
  280. package/dist/http-body.js +67 -0
  281. package/dist/http-body.js.map +1 -0
  282. package/dist/schedules/index.d.ts +3 -2
  283. package/dist/schedules/index.d.ts.map +1 -1
  284. package/dist/schedules/index.js +5 -4
  285. package/dist/schedules/index.js.map +1 -1
  286. package/dist/schedules/router.d.ts +16 -10
  287. package/dist/schedules/router.d.ts.map +1 -1
  288. package/dist/schedules/router.js +153 -91
  289. package/dist/schedules/router.js.map +1 -1
  290. package/dist/schedules/schedules-d1.d.ts +88 -0
  291. package/dist/schedules/schedules-d1.d.ts.map +1 -1
  292. package/dist/schedules/schedules-d1.js +411 -50
  293. package/dist/schedules/schedules-d1.js.map +1 -1
  294. package/dist/schedules/target-policy.d.ts +29 -0
  295. package/dist/schedules/target-policy.d.ts.map +1 -0
  296. package/dist/schedules/target-policy.js +70 -0
  297. package/dist/schedules/target-policy.js.map +1 -0
  298. package/dist/schedules/tick.d.ts +125 -21
  299. package/dist/schedules/tick.d.ts.map +1 -1
  300. package/dist/schedules/tick.js +637 -160
  301. package/dist/schedules/tick.js.map +1 -1
  302. package/dist/signal-providers/delivery.d.ts +0 -19
  303. package/dist/signal-providers/delivery.d.ts.map +1 -1
  304. package/dist/signal-providers/delivery.js +5 -54
  305. package/dist/signal-providers/delivery.js.map +1 -1
  306. package/dist/signal-providers/github-provider.d.ts.map +1 -1
  307. package/dist/signal-providers/github-provider.js +9 -16
  308. package/dist/signal-providers/github-provider.js.map +1 -1
  309. package/dist/signal-providers/host-do.d.ts +3 -45
  310. package/dist/signal-providers/host-do.d.ts.map +1 -1
  311. package/dist/signal-providers/host-do.js +86 -106
  312. package/dist/signal-providers/host-do.js.map +1 -1
  313. package/dist/signal-providers/host-topology.d.ts +5 -14
  314. package/dist/signal-providers/host-topology.d.ts.map +1 -1
  315. package/dist/signal-providers/host-topology.js +11 -25
  316. package/dist/signal-providers/host-topology.js.map +1 -1
  317. package/dist/signal-providers/index.d.ts +3 -3
  318. package/dist/signal-providers/index.d.ts.map +1 -1
  319. package/dist/signal-providers/index.js +3 -3
  320. package/dist/signal-providers/index.js.map +1 -1
  321. package/dist/signal-providers/provider.d.ts +4 -5
  322. package/dist/signal-providers/provider.d.ts.map +1 -1
  323. package/dist/signal-providers/provider.js +5 -6
  324. package/dist/signal-providers/provider.js.map +1 -1
  325. package/dist/signal-providers/subscription-d1.d.ts +10 -57
  326. package/dist/signal-providers/subscription-d1.d.ts.map +1 -1
  327. package/dist/signal-providers/subscription-d1.js +208 -155
  328. package/dist/signal-providers/subscription-d1.js.map +1 -1
  329. package/dist/signal-providers/webhook-route.d.ts +28 -14
  330. package/dist/signal-providers/webhook-route.d.ts.map +1 -1
  331. package/dist/signal-providers/webhook-route.js +117 -88
  332. package/dist/signal-providers/webhook-route.js.map +1 -1
  333. package/dist/signals/client.js +8 -8
  334. package/dist/signals/client.js.map +1 -1
  335. package/dist/signals/d1-shared.js +1 -1
  336. package/dist/signals/d1-shared.js.map +1 -1
  337. package/dist/signals/index.d.ts +1 -1
  338. package/dist/signals/index.d.ts.map +1 -1
  339. package/dist/signals/index.js.map +1 -1
  340. package/dist/signals/notification-dispatch.d.ts +12 -6
  341. package/dist/signals/notification-dispatch.d.ts.map +1 -1
  342. package/dist/signals/notification-dispatch.js +37 -21
  343. package/dist/signals/notification-dispatch.js.map +1 -1
  344. package/dist/signals/notifications-d1.d.ts +5 -8
  345. package/dist/signals/notifications-d1.d.ts.map +1 -1
  346. package/dist/signals/notifications-d1.js +8 -13
  347. package/dist/signals/notifications-d1.js.map +1 -1
  348. package/dist/signals/router.d.ts +10 -10
  349. package/dist/signals/router.d.ts.map +1 -1
  350. package/dist/signals/router.js +49 -51
  351. package/dist/signals/router.js.map +1 -1
  352. package/dist/signals/thread-do-routes.d.ts +74 -15
  353. package/dist/signals/thread-do-routes.d.ts.map +1 -1
  354. package/dist/signals/thread-do-routes.js +484 -41
  355. package/dist/signals/thread-do-routes.js.map +1 -1
  356. package/dist/signals/thread-state-d1.d.ts.map +1 -1
  357. package/dist/signals/thread-state-d1.js +2 -3
  358. package/dist/signals/thread-state-d1.js.map +1 -1
  359. package/package.json +29 -6
  360. package/scripts/seed-deployment-identity.mjs +252 -0
  361. package/dist/approval-api/tenant-brand.d.ts +0 -35
  362. package/dist/approval-api/tenant-brand.d.ts.map +0 -1
  363. package/dist/approval-api/tenant-brand.js +0 -19
  364. package/dist/approval-api/tenant-brand.js.map +0 -1
  365. package/dist/approval-api/tenant-context.d.ts +0 -84
  366. package/dist/approval-api/tenant-context.d.ts.map +0 -1
  367. package/dist/approval-api/tenant-context.js +0 -112
  368. package/dist/approval-api/tenant-context.js.map +0 -1
  369. package/dist/approval-api/tenant-store.d.ts +0 -36
  370. package/dist/approval-api/tenant-store.d.ts.map +0 -1
  371. package/dist/approval-api/tenant-store.js +0 -129
  372. package/dist/approval-api/tenant-store.js.map +0 -1
  373. package/dist/do-runner/resume-ledger.d.ts +0 -48
  374. package/dist/do-runner/resume-ledger.d.ts.map +0 -1
  375. package/dist/do-runner/resume-ledger.js +0 -60
  376. package/dist/do-runner/resume-ledger.js.map +0 -1
  377. package/dist/do-runner/thread-header.d.ts +0 -31
  378. package/dist/do-runner/thread-header.d.ts.map +0 -1
  379. package/dist/do-runner/thread-header.js +0 -39
  380. package/dist/do-runner/thread-header.js.map +0 -1
  381. package/dist/host-kit/subdomain-check.d.ts +0 -23
  382. package/dist/host-kit/subdomain-check.d.ts.map +0 -1
  383. package/dist/host-kit/subdomain-check.js +0 -61
  384. package/dist/host-kit/subdomain-check.js.map +0 -1
  385. package/dist/host-kit/tenant-registry.d.ts +0 -51
  386. package/dist/host-kit/tenant-registry.d.ts.map +0 -1
  387. package/dist/host-kit/tenant-registry.js +0 -88
  388. package/dist/host-kit/tenant-registry.js.map +0 -1
@@ -2,10 +2,9 @@ import type { ApprovalActor } from '../approval-api/index.js';
2
2
  import { type TokenVerifier } from './verifier.js';
3
3
  /**
4
4
  * Parse the `APPROVAL_ACTOR_TOKENS` secret:
5
- * `{"<token>": {"id","role","tenantId"}}`. Every entry passes the real
6
- * validator (toApprovalActor) — unknown roles, empty ids, and missing,
7
- * invalid, or reserved-identity ('system') tenantIds are dropped rather
8
- * than trusted; there is no `as`-cast at this JSON boundary.
5
+ * `{"<token>": {"id","role"}}`. Every entry passes the real validator
6
+ * (`toApprovalActor`) — unknown roles and empty ids are dropped rather than
7
+ * trusted; there is no `as` cast at this JSON boundary.
9
8
  */
10
9
  export declare function parseActorTokens(raw: string | undefined): Map<string, ApprovalActor>;
11
10
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"bearer-auth.d.ts","sourceRoot":"","sources":["../../src/host-kit/bearer-auth.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,KAAK,aAAa,EAAmB,MAAM,eAAe,CAAC;AAEpE;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,MAAM,GAAG,SAAS,GACtB,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAiC5B;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,aAAa,GACtB,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CAO1D"}
1
+ {"version":3,"file":"bearer-auth.d.ts","sourceRoot":"","sources":["../../src/host-kit/bearer-auth.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,KAAK,aAAa,EAAmB,MAAM,eAAe,CAAC;AAEpE;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,MAAM,GAAG,SAAS,GACtB,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAiC5B;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,aAAa,GACtB,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CAO1D"}
@@ -3,19 +3,15 @@
3
3
  // to a TokenVerifier (static map or HS256 JWT — verifier.ts), get back an
4
4
  // ApprovalActor or undefined.
5
5
  //
6
- // This is trusted-computing-base code: it ASSERTS identity (the service
7
- // enforces roles from it; the tenant predicates key on actor.tenantId), so a
8
- // malformed map must fail closed — an unparseable or absent secret yields an
9
- // empty map and every authenticated route 401s, and an entry without an
10
- // INV-3-valid tenantId is dropped (its token 401s) rather than admitted
11
- // tenant-less.
6
+ // This is trusted-computing-base code: it asserts the identity and role that
7
+ // authorization consumes. A malformed map fails closed — an unparseable or
8
+ // absent secret yields an empty map and every authenticated route 401s.
12
9
  import { toApprovalActor } from './verifier.js';
13
10
  /**
14
11
  * Parse the `APPROVAL_ACTOR_TOKENS` secret:
15
- * `{"<token>": {"id","role","tenantId"}}`. Every entry passes the real
16
- * validator (toApprovalActor) — unknown roles, empty ids, and missing,
17
- * invalid, or reserved-identity ('system') tenantIds are dropped rather
18
- * than trusted; there is no `as`-cast at this JSON boundary.
12
+ * `{"<token>": {"id","role"}}`. Every entry passes the real validator
13
+ * (`toApprovalActor`) — unknown roles and empty ids are dropped rather than
14
+ * trusted; there is no `as` cast at this JSON boundary.
19
15
  */
20
16
  export function parseActorTokens(raw) {
21
17
  const actors = new Map();
@@ -44,7 +40,7 @@ export function parseActorTokens(raw) {
44
40
  console.error(JSON.stringify({
45
41
  type: 'config-error',
46
42
  var: 'APPROVAL_ACTOR_TOKENS',
47
- reason: "entry dropped: needs non-empty id, a known role, and an INV-3 tenantId (^[a-z0-9]{3,32}$, not the reserved identity 'system') — its token will 401",
43
+ reason: 'entry dropped: needs a non-empty id and a known role — its token will 401',
48
44
  }));
49
45
  }
50
46
  }
@@ -1 +1 @@
1
- {"version":3,"file":"bearer-auth.js","sourceRoot":"","sources":["../../src/host-kit/bearer-auth.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,4EAA4E;AAC5E,0EAA0E;AAC1E,8BAA8B;AAC9B,EAAE;AACF,wEAAwE;AACxE,6EAA6E;AAC7E,6EAA6E;AAC7E,wEAAwE;AACxE,wEAAwE;AACxE,eAAe;AAGf,OAAO,EAAsB,eAAe,EAAE,MAAM,eAAe,CAAC;AAEpE;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAC9B,GAAuB;IAEvB,MAAM,MAAM,GAAG,IAAI,GAAG,EAAyB,CAAC;IAChD,IAAI,CAAC,GAAG;QAAE,OAAO,MAAM,CAAC;IACxB,IAAI,MAAe,CAAC;IACpB,IAAI,CAAC;QACH,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,CAAC,KAAK,CACX,IAAI,CAAC,SAAS,CAAC;YACb,IAAI,EAAE,cAAc;YACpB,GAAG,EAAE,uBAAuB;YAC5B,MAAM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GAAG,CAAC,eAAe,CAAC;YACrB,EAAE,KAAK,CAAC,kBAAkB,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QACnC,OAAO,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACpD,CAAC,CAAC;AACJ,CAAC"}
@@ -1,6 +1,7 @@
1
- import type { ApprovalDecision, ApprovalRecord } from '../approval-api/index.js';
2
- import type { RunSummary } from '../do-runner/index.js';
1
+ import type { ApprovalDecision, ApprovalRecord, ExecutionPrincipalKind } from '../approval-api/index.js';
2
+ import { type RunSummary } from '../do-runner/index.js';
3
3
  import { type DoResponseLike } from './do-response.js';
4
+ import type { RunStartInput } from './run-router.js';
4
5
  /** The subset of a DurableObjectStub the topology uses. */
5
6
  export interface RunnerStubLike {
6
7
  fetch(url: string, init?: {
@@ -16,11 +17,13 @@ export interface RunnerNamespaceLike<Id = unknown> {
16
17
  }
17
18
  export interface DoRunTopology {
18
19
  /** createRunRouter's `start` thunk. */
19
- start(workflowId: string, runId: string, inputData: unknown): Promise<RunSummary>;
20
+ start(input: DoRunStartInput): Promise<RunSummary>;
20
21
  /** createRunRouter's `status` thunk (a DO 404 reads as undefined). */
21
22
  status(workflowId: string, runId: string): Promise<RunSummary | undefined>;
23
+ /** Waits behind start/recovery before declaring a dispatch absent. */
24
+ dispatchStatus(workflowId: string, runId: string): Promise<RunSummary | undefined>;
22
25
  /** createRunRouter's `resume` thunk. */
23
- resume(workflowId: string, runId: string, body: unknown): Promise<RunSummary>;
26
+ resume(workflowId: string, runId: string, body: unknown, requestedBy: string, requestedByKind: ExecutionPrincipalKind): Promise<RunSummary>;
24
27
  /**
25
28
  * ApprovalServiceOptions.resumeRun base: resume a DECIDED approval's run
26
29
  * through its DO stub with the standard resumeData contract. Hand this to
@@ -28,5 +31,11 @@ export interface DoRunTopology {
28
31
  */
29
32
  resumeRecord(record: ApprovalRecord, decision: ApprovalDecision): Promise<RunSummary>;
30
33
  }
31
- export declare function createDoRunTopology<Id>(namespace: RunnerNamespaceLike<Id>): DoRunTopology;
34
+ export type DoRunStartInput = RunStartInput & {
35
+ /** Prepared trigger paired with scheduleId for a one-shot schedule fire. */
36
+ dispatchId?: string;
37
+ /** Ordinary trusted starts may seed core workflow state. */
38
+ initialState?: unknown;
39
+ };
40
+ export declare function createDoRunTopology<Id>(namespace: RunnerNamespaceLike<Id>, deploymentIdentitySecret: string): DoRunTopology;
32
41
  //# sourceMappingURL=do-run-topology.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"do-run-topology.d.ts","sourceRoot":"","sources":["../../src/host-kit/do-run-topology.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EACV,gBAAgB,EAChB,cAAc,EACf,MAAM,0BAA0B,CAAC;AAElC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,KAAK,cAAc,EAAa,MAAM,kBAAkB,CAAC;AAElE,2DAA2D;AAC3D,MAAM,WAAW,cAAc;IAC7B,KAAK,CACH,GAAG,EAAE,MAAM,EACX,IAAI,CAAC,EAAE;QACL,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACjC,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,GACA,OAAO,CAAC,cAAc,CAAC,CAAC;CAC5B;AAED,gEAAgE;AAChE,MAAM,WAAW,mBAAmB,CAAC,EAAE,GAAG,OAAO;IAC/C,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,EAAE,CAAC;IAC7B,GAAG,CAAC,EAAE,EAAE,EAAE,GAAG,cAAc,CAAC;CAC7B;AAED,MAAM,WAAW,aAAa;IAC5B,uCAAuC;IACvC,KAAK,CACH,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,OAAO,GACjB,OAAO,CAAC,UAAU,CAAC,CA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GAAG,CAAC,EAAE,EAAE,EAAE,GAAG,cAAc,CAAC;CAC7B;AAED,MAAM,WAAW,aAAa;IAC5B,uCAAuC;IACvC,KAAK,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IACnD,sEAAsE;IACtE,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAAC;IAC3E,sEAAsE;IACtE,cAAc,CACZ,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAAC;IACnC,wCAAwC;IACxC,MAAM,CACJ,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,OAAO,EACb,WAAW,EAAE,MAAM,EACnB,eAAe,EAAE,sBAAsB,GACtC,OAAO,CAAC,UAAU,CAAC,CAAC;IACvB;;;;OAIG;IACH,YAAY,CACV,MAAM,EAAE,cAAc,EACtB,QAAQ,EAAE,gBAAgB,GACzB,OAAO,CAAC,UAAU,CAAC,CAAC;CACxB;AAED,MAAM,MAAM,eAAe,GAAG,aAAa,GAAG;IAC5C,4EAA4E;IAC5E,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,4DAA4D;IAC5D,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF,wBAAgB,mBAAmB,CAAC,EAAE,EACpC,SAAS,EAAE,mBAAmB,CAAC,EAAE,CAAC,EAClC,wBAAwB,EAAE,MAAM,GAC/B,aAAa,CAiGf"}
@@ -5,36 +5,68 @@
5
5
  // via doSummary. Hosts pass their `env.RUNNER` binding directly — the
6
6
  // namespace/stub types are structural subsets so this module (like the rest
7
7
  // of host-kit) never imports @cloudflare/workers-types.
8
- import { defaultResumeData } from '../approval-api/index.js';
8
+ import { defaultResumeData, encodeExecutionPrincipal, } from '../approval-api/index.js';
9
+ import { deploymentIdentityHeaders, EXECUTION_PRINCIPAL_HEADER, } from '../do-runner/index.js';
9
10
  import { doSummary } from './do-response.js';
10
- export function createDoRunTopology(namespace) {
11
+ export function createDoRunTopology(namespace, deploymentIdentitySecret) {
11
12
  // One DO per (workflowId, runId): the name join is unambiguous because
12
13
  // PATH_SAFE_ID_PATTERN excludes ':' from both ids.
13
14
  const stub = (workflowId, runId) => namespace.get(namespace.idFromName(`${workflowId}:${runId}`));
14
- const resume = async (workflowId, runId, body) => doSummary(await stub(workflowId, runId).fetch(`http://do/runs/${workflowId}/${runId}/resume`, {
15
+ const resume = async (workflowId, runId, body, requestedBy, requestedByKind) => doSummary(await stub(workflowId, runId).fetch(`http://do/runs/${workflowId}/${runId}/resume`, {
15
16
  method: 'POST',
16
- headers: { 'content-type': 'application/json' },
17
- body: JSON.stringify(body),
17
+ headers: deploymentIdentityHeaders(deploymentIdentitySecret, {
18
+ 'content-type': 'application/json',
19
+ }),
20
+ body: JSON.stringify({
21
+ ...(body && typeof body === 'object' ? body : {}),
22
+ requestedBy,
23
+ requestedByKind,
24
+ }),
18
25
  }));
19
26
  return {
20
- start: async (workflowId, runId, inputData) => doSummary(await stub(workflowId, runId).fetch('http://do/runs', {
21
- method: 'POST',
22
- headers: { 'content-type': 'application/json' },
23
- body: JSON.stringify({ workflowId, runId, inputData }),
24
- })),
27
+ start: async ({ workflowId, runId, inputData, initialState, principal, scheduleId, dispatchId, }) => {
28
+ if ((scheduleId === undefined) !== (dispatchId === undefined)) {
29
+ throw new Error('scheduled run starts require both scheduleId and dispatchId');
30
+ }
31
+ return doSummary(await stub(workflowId, runId).fetch('http://do/runs', {
32
+ method: 'POST',
33
+ headers: deploymentIdentityHeaders(deploymentIdentitySecret, {
34
+ 'content-type': 'application/json',
35
+ [EXECUTION_PRINCIPAL_HEADER]: encodeExecutionPrincipal(principal),
36
+ }),
37
+ body: JSON.stringify({
38
+ workflowId,
39
+ runId,
40
+ ...(scheduleId === undefined
41
+ ? { inputData, initialState }
42
+ : { scheduleId, dispatchId }),
43
+ }),
44
+ }));
45
+ },
25
46
  // The DO answers 404 for a run it has never seen; the router turns the
26
47
  // undefined into its own 404 rather than leaking the DO's body.
27
48
  status: async (workflowId, runId) => {
28
- const response = await stub(workflowId, runId).fetch(`http://do/runs/${workflowId}/${runId}`);
49
+ const response = await stub(workflowId, runId).fetch(`http://do/runs/${workflowId}/${runId}`, { headers: deploymentIdentityHeaders(deploymentIdentitySecret) });
50
+ if (response.status === 404)
51
+ return undefined;
52
+ return doSummary(response);
53
+ },
54
+ dispatchStatus: async (workflowId, runId) => {
55
+ const response = await stub(workflowId, runId).fetch(`http://do/runs/${workflowId}/${runId}/dispatch-status`, { headers: deploymentIdentityHeaders(deploymentIdentitySecret) });
29
56
  if (response.status === 404)
30
57
  return undefined;
31
58
  return doSummary(response);
32
59
  },
33
60
  resume,
34
- resumeRecord: (record, decision) => resume(record.workflowId, record.runId, {
35
- step: record.stepPath,
36
- resumeData: defaultResumeData(record, decision),
37
- }),
61
+ resumeRecord: (record, decision) => {
62
+ if (!record.decidedBy) {
63
+ throw new Error(`approval '${record.id}' has no decision actor`);
64
+ }
65
+ return resume(record.workflowId, record.runId, {
66
+ step: record.stepPath,
67
+ resumeData: defaultResumeData(record, decision),
68
+ }, record.decidedBy, 'human');
69
+ },
38
70
  };
39
71
  }
40
72
  //# sourceMappingURL=do-run-topology.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"do-run-topology.js","sourceRoot":"","sources":["../../src/host-kit/do-run-topology.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,wEAAwE;AACxE,4EAA4E;AAC5E,6EAA6E;AAC7E,sEAAsE;AACtE,4EAA4E;AAC5E,wDAAwD;AAMxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE7D,OAAO,EAAuB,SAAS,EAAE,MAAM,kBAAkB,CAAC;AA0ClE,MAAM,UAAU,mBAAmB,CACjC,SAAkC;IAElC,uEAAuE;IACvE,mDAAmD;IACnD,M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AwB,CAAC,EAAE,CACjE,CAAC;YACF,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG;gBAAE,OAAO,SAAS,CAAC;YAC9C,OAAO,SAAS,CAAC,QAAQ,CAAC,CAAC;QAC7B,CAAC;QACD,cAAc,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE;YAC1C,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC,KAAK,CAClD,kBAAkB,UAAU,IAAI,KAAK,kBAAkB,EACvD,EAAE,OAAO,EAAE,yBAAyB,CAAC,wBAAwB,CAAC,EAAE,CACjE,CAAC;YACF,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG;gBAAE,OAAO,SAAS,CAAC;YAC9C,OAAO,SAAS,CAAC,QAAQ,CAAC,CAAC;QAC7B,CAAC;QACD,MAAM;QACN,YAAY,EAAE,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE;YACjC,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;gBACtB,MAAM,IAAI,KAAK,CAAC,aAAa,MAAM,CAAC,EAAE,yBAAyB,CAAC,CAAC;YACnE,CAAC;YACD,OAAO,MAAM,CACX,MAAM,CAAC,UAAU,EACjB,MAAM,CAAC,KAAK,EACZ;gBACE,IAAI,EAAE,MAAM,CAAC,QAAQ;gBACrB,UAAU,EAAE,iBAAiB,CAAC,MAAM,EAAE,QAAQ,CAAC;aAChD,EACD,MAAM,CAAC,SAAS,EAChB,OAAO,CACR,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -22,7 +22,7 @@ export declare function numberVar(raw: string | undefined, fallback: number, nam
22
22
  * IRREVERSIBLE delete happens at all, so a fallback would not preserve behavior,
23
23
  * it would INVENT it — and invent a threshold the caller has already decided it
24
24
  * cannot pick on the operator's behalf. Never expiring is recoverable; deleting
25
- * a tenant's conversations because a var was mistyped is not.
25
+ * a deployment's conversations because a var was mistyped is not.
26
26
  *
27
27
  * The empty-string case is not hypothetical: `''` is what an unset CI/CD
28
28
  * variable interpolates to and what a blank wrangler `vars` entry produces, and
@@ -30,7 +30,7 @@ export function numberVar(raw, fallback, name, options = {}) {
30
30
  * IRREVERSIBLE delete happens at all, so a fallback would not preserve behavior,
31
31
  * it would INVENT it — and invent a threshold the caller has already decided it
32
32
  * cannot pick on the operator's behalf. Never expiring is recoverable; deleting
33
- * a tenant's conversations because a var was mistyped is not.
33
+ * a deployment's conversations because a var was mistyped is not.
34
34
  *
35
35
  * The empty-string case is not hypothetical: `''` is what an unset CI/CD
36
36
  * variable interpolates to and what a blank wrangler `vars` entry produces, and
@@ -1,15 +1,60 @@
1
- import type { ApprovalAuditEvent, ApprovalDatabase, ApprovalNotificationSink, TenantResolver } from '../approval-api/index.js';
2
- import type { AuditMessageBatch, AuditQueue } from '../audit-export/index.js';
3
- import type { SnapshotDatabase, TenantArtifactPurger } from '../do-runner/index.js';
1
+ import type { ActorContext, ActorResolver, ApprovalAuditEvent, ApprovalDatabase, ApprovalNotificationSink } from '../approval-api/index.js';
2
+ import { type AuditProxyNamespaceLike, type AuditQueue, type InfrastructureAuditEnvelope } from '../audit-export/index.js';
3
+ import type { DeploymentIdentityDatabase, RunArtifactPurger, SnapshotDatabase } from '../do-runner/index.js';
4
4
  import type { ResumeRunFn } from './approval-bridge.js';
5
5
  import { type DoRunTopology, type RunnerNamespaceLike } from './do-run-topology.js';
6
+ import { type MaintenanceOutcome } from './host-approval-service.js';
6
7
  import { type HubNamespaceLike } from './hub-topology.js';
8
+ import { type StateEgressBinding } from './state-egress.js';
7
9
  import type { TokenVerifier } from './verifier.js';
8
10
  import type { WorkflowMeta } from './workflow-meta.js';
9
11
  /** The ExecutionContext subset the composer needs (structural, like the rest of host-kit). */
10
12
  export interface FlowsafeWorkerContext {
11
13
  waitUntil(promise: Promise<unknown>): void;
12
14
  }
15
+ /** Fixed instance name used by every deployment maintenance namespace. */
16
+ export declare const MAINTENANCE_INSTANCE_NAME = "deployment-maintenance";
17
+ export interface MaintenanceStubLike {
18
+ fetch(url: string, init?: {
19
+ method?: string;
20
+ headers?: Record<string, string>;
21
+ }): Promise<Response>;
22
+ }
23
+ export interface MaintenanceNamespaceLike<Id = unknown> {
24
+ idFromName(name: string): Id;
25
+ get(id: Id): MaintenanceStubLike;
26
+ }
27
+ export interface MaintenanceHealth {
28
+ nextSweepAt: number;
29
+ nextPurgeAt: number;
30
+ nextTickAt?: number;
31
+ lastSweepAt?: number;
32
+ lastPurgeAt?: number;
33
+ lastTickAt?: number;
34
+ lastSweepAttemptAt?: number;
35
+ lastPurgeAttemptAt?: number;
36
+ lastTickAttemptAt?: number;
37
+ lastSweepError?: string;
38
+ lastPurgeError?: string;
39
+ lastTickError?: string;
40
+ }
41
+ export interface MaintenanceStorage {
42
+ get<T = unknown>(key: string): Promise<T | undefined>;
43
+ getAlarm(): Promise<number | null>;
44
+ setAlarm(scheduledTime: number | Date): Promise<void>;
45
+ transaction<T>(closure: (transaction: MaintenanceStorageTransaction) => Promise<T>): Promise<T>;
46
+ }
47
+ export interface MaintenanceStorageTransaction {
48
+ get<T = unknown>(key: string): Promise<T | undefined>;
49
+ put<T>(key: string, value: T): Promise<void>;
50
+ setAlarm(scheduledTime: number | Date): Promise<void>;
51
+ }
52
+ export interface MaintenanceDurableObjectState {
53
+ readonly id: {
54
+ readonly name?: string;
55
+ };
56
+ readonly storage: MaintenanceStorage;
57
+ }
13
58
  /**
14
59
  * The env bindings the composed Worker reads. A host's own Env extends this
15
60
  * (its workers-typed D1Database/DurableObjectNamespace/Queue bindings satisfy
@@ -17,13 +62,37 @@ export interface FlowsafeWorkerContext {
17
62
  */
18
63
  export interface FlowsafeWorkerEnv {
19
64
  /** D1: the approval store AND the Mastra snapshot table live here. */
20
- DB: ApprovalDatabase & SnapshotDatabase;
65
+ DB: ApprovalDatabase & SnapshotDatabase & DeploymentIdentityDatabase;
66
+ /** Provisioning-stamped deployment tag; must match the D1 sentinel. */
67
+ DEPLOYMENT_TENANT: string;
68
+ /** Optional fleet release identity returned only by authenticated maintenance routes. */
69
+ FLEET_SPEC_DIGEST?: string;
70
+ /** Fleet-controlled marker: maintenance routes relay one-shot capabilities. */
71
+ FLEET_MAINTENANCE_CAPABILITIES?: 'required';
72
+ /** Fleet Ed25519 public JWK used before external maintenance execution. */
73
+ FLEET_MAINTENANCE_CAPABILITY_PUBLIC_KEY?: string;
74
+ /** Fleet-controlled marker: audit export must use the trusted state proxy. */
75
+ FLEET_AUDIT_PROXY?: 'required';
76
+ /** Fleet-controlled marker: this private Worker terminates audit proxy calls. */
77
+ FLEET_AUDIT_PROXY_INGRESS?: 'required';
78
+ /** Fleet-controlled environment attribution for trusted state. */
79
+ FLEET_ENVIRONMENT?: string;
80
+ /** Fleet-controlled logical release-family name for trusted audit attribution. */
81
+ FLEET_DEPLOYMENT_SCRIPT?: string;
82
+ /** Fleet resource group stamped onto trusted state. */
83
+ FLEET_RESOURCE_GROUP?: string;
84
+ /** Distinguishes the trusted state runtime from an external candidate. */
85
+ FLEET_RESOURCE_ROLE?: 'platform-state';
86
+ /** Per-deployment Worker-to-Durable-Object credential. */
87
+ DEPLOYMENT_IDENTITY_SECRET: string;
21
88
  /** The runner DO namespace createDoRunTopology drives. */
22
89
  RUNNER: RunnerNamespaceLike;
90
+ /** Fixed-name singleton that owns deployment maintenance alarms. */
91
+ MAINTENANCE: MaintenanceNamespaceLike;
23
92
  /**
24
- * Optional per-tenant hub Durable Object namespace for live streaming.
93
+ * Optional deployment hub Durable Object namespace for live streaming.
25
94
  * Present together with STREAM_TICKET_SECRET => the composer mounts the stream
26
- * stage and fans approval mutations out to the tenant hub; either absent =>
95
+ * stage and fans approval mutations out to the deployment hub; either absent =>
27
96
  * streaming stays unmounted and the client remains poll-only.
28
97
  */
29
98
  HUB?: HubNamespaceLike;
@@ -38,13 +107,13 @@ export interface FlowsafeWorkerEnv {
38
107
  * value falls back to OFF (fail closed).
39
108
  */
40
109
  APPROVAL_ALLOW_SELF_DECISION?: string;
41
- /** Cron purges terminal run snapshots older than this (var; default 30; 0 = immediately). */
110
+ /** Maintenance purges terminal run snapshots older than this (default 30 days). */
42
111
  RUN_RETENTION_DAYS?: string;
43
- /** Cron purges DECIDED approval records older than this (var; default 30; 0 = immediately). */
112
+ /** Maintenance purges DECIDED approval records older than this (default 30 days). */
44
113
  APPROVAL_RETENTION_DAYS?: string;
45
114
  /**
46
- * Agent-memory thread TTL in days (var; docs/agent-memory-tenancy.md item 7):
47
- * the purge cron deletes threads untouched for longer than this, with their
115
+ * Agent-memory thread TTL in days (docs/agent-memory-isolation.md#thread-retention):
116
+ * the purge duty deletes threads untouched for longer than this, with their
48
117
  * messages. UNSET, EMPTY, or INVALID => the duty does not run and no thread
49
118
  * ever expires — the opt-in default, because a thread is a conversation a host
50
119
  * means to keep, not a terminal run snapshot that is finished by definition.
@@ -56,7 +125,7 @@ export interface FlowsafeWorkerEnv {
56
125
  */
57
126
  THREAD_RETENTION_DAYS?: string;
58
127
  /**
59
- * Agent-inbox TTL in days. The purge cron reaps terminal
128
+ * Agent-inbox TTL in days. The purge duty reaps terminal
60
129
  * `mastra_notifications` rows past this age (pending rows are never reaped —
61
130
  * one may await a future deliverAt). UNSET/EMPTY/INVALID => the duty does not
62
131
  * run and no notification ever expires (opt-in, like THREAD_RETENTION_DAYS —
@@ -64,24 +133,37 @@ export interface FlowsafeWorkerEnv {
64
133
  */
65
134
  NOTIFICATION_RETENTION_DAYS?: string;
66
135
  /**
67
- * Thread-state TTL in days. The purge cron reaps
136
+ * Thread-state TTL in days. The purge duty reaps
68
137
  * `mastra_thread_state` rows (state-signal lanes + goals) untouched for longer
69
138
  * than this. UNSET/EMPTY/INVALID => the duty does not run (opt-in; an active
70
139
  * goal bumps updatedAt so it never ages out).
71
140
  */
72
141
  THREAD_STATE_RETENTION_DAYS?: string;
73
142
  /**
74
- * Schedule-trigger history TTL in days. The purge cron reaps
143
+ * Schedule-trigger history TTL in days. The purge duty reaps
75
144
  * `mastra_schedule_triggers` rows past this age by their `actualFireAt`.
76
145
  * UNSET/EMPTY/INVALID => the duty does not run (opt-in; a schedule's fire
77
- * history is inspectable until the host sets a window). The schedule rows
78
- * themselves are standing config — never TTL'd, reaped only at offboarding.
146
+ * history is inspectable until the host sets a window). Schedule rows are
147
+ * standing config with no TTL; an authorized DELETE removes them, and
148
+ * deployment decommissioning removes any that remain.
79
149
  */
80
150
  SCHEDULE_TRIGGER_RETENTION_DAYS?: string;
81
- /** Optional audit export: queue producer binding + SIEM collector config. */
82
- AUDIT_QUEUE?: AuditQueue<ApprovalAuditEvent>;
83
- SIEM_ENDPOINT?: string;
84
- SIEM_AUTH_HEADER?: string;
151
+ /** Optional audit queue producer; delivery belongs to the control plane. */
152
+ AUDIT_QUEUE?: AuditQueue<ApprovalAuditEvent | InfrastructureAuditEnvelope>;
153
+ /** Remote trusted-state Durable Object namespace used by external releases. */
154
+ AUDIT_PROXY?: AuditProxyNamespaceLike;
155
+ /** Named StateEgress service binding, present only on trusted state. */
156
+ OUTBOUND_PROXY?: StateEgressBinding;
157
+ /** Dedicated trusted-state credential for the shared outbound entrypoint. */
158
+ OUTBOUND_PROXY_CREDENTIAL?: string;
159
+ OUTBOUND_TENANT_ID?: string;
160
+ OUTBOUND_ENVIRONMENT?: string;
161
+ OUTBOUND_RESOURCE_GROUP_ID?: string;
162
+ OUTBOUND_STATE_SCRIPT_NAME?: string;
163
+ OUTBOUND_ROUTE_HOSTNAME?: string;
164
+ OUTBOUND_POLICY_ID?: string;
165
+ /** Dedicated control-plane credential for maintenance administration. */
166
+ MAINTENANCE_ADMIN_SECRET?: string;
85
167
  }
86
168
  /**
87
169
  * Background-task TTL cleanup config, surfaced through
@@ -100,51 +182,42 @@ export interface FlowsafeWorkerConfig<Env extends FlowsafeWorkerEnv> {
100
182
  /** The catalog createRunRouter serves and gates (hosts pass their metas). */
101
183
  workflows: ReadonlyArray<WorkflowMeta>;
102
184
  /**
103
- * Id for system-created records (the bridge's record creator and the cron
104
- * maintenance attribution). Must differ from human actor ids or the
105
- * separation-of-duties check can never fire.
185
+ * System-principal id for bridge bookkeeping and alarm maintenance
186
+ * attribution. Requester kind is persisted separately, so ids may overlap
187
+ * across principal kinds.
106
188
  */
107
- systemActorId: string;
189
+ systemPrincipalId: string;
108
190
  /**
109
- * The identity seam: env -> TokenVerifier. Called once per fetch (and per
110
- * scheduled notify), so hosts keep their own per-isolate memoization —
191
+ * The identity seam: env -> TokenVerifier. Called once per fetch, so hosts
192
+ * keep their own per-isolate memoization —
111
193
  * re-parsing a token map on every request is pure waste, but that is the
112
194
  * host's trade to make.
113
195
  */
114
196
  buildVerifier: (env: Env) => TokenVerifier;
115
197
  /**
116
- * The cron expressions scheduled() dispatches on. `sweep` + `purge` are
117
- * required and must never share an invocation. `tick` is optional for
118
- * schedules: when set and `scheduleTick` is provided, the schedule tick runs
119
- * on it as its OWN failure-isolated invocation (a runaway fire pass gets its
120
- * own CPU budget, the same rationale that keeps sweep and purge apart). Keep
121
- * these byte-equal to wrangler.jsonc's `triggers.crons`; an unrecognized
122
- * expression runs the sweep + purge duties sequentially and logs a
123
- * config-error (availability beats purity on a misconfig). Absent `tick` ⇒ no
124
- * schedule-tick invocation, byte-identical.
125
- */
126
- crons: {
127
- sweep: string;
128
- purge: string;
129
- tick?: string;
198
+ * Recurrence intervals for the singleton maintenance Durable Object. Every
199
+ * duty receives its own alarm invocation; `tickIntervalMs` is required when
200
+ * `scheduleTick` is configured and omitted otherwise.
201
+ */
202
+ maintenance: {
203
+ sweepIntervalMs: number;
204
+ purgeIntervalMs: number;
205
+ tickIntervalMs?: number;
130
206
  };
131
207
  /**
132
208
  * Deployment-specific routes tried AFTER /healthz and BEFORE the approval
133
- * and run routers (the showcase mounts its demo sign-in and sandbox reset
134
- * here). `kit` hands over the request's already-built resolver and DO
135
- * topology so a pre-route can share them (the reset route authenticates
136
- * through the same resolve). Return null to fall through.
209
+ * and run routers (the showcase mounts its demo sign-in here). `kit` hands
210
+ * over the request's already-built resolver and DO topology so a pre-route
211
+ * can share them. Return null to fall through.
137
212
  */
138
213
  preRoutes?: (request: Request, env: Env, ctx: FlowsafeWorkerContext, kit: {
139
- resolve: TenantResolver;
214
+ resolve: ActorResolver;
140
215
  topology: DoRunTopology;
141
216
  }) => Promise<Response | null>;
142
- /** Wrap the tenant resolver (e.g. withSubdomainCrossCheck behind an env var). */
143
- wrapResolve?: (resolve: TenantResolver, env: Env) => TenantResolver;
144
- /** Wrap the run-start thunk (e.g. charge a budget BEFORE the DO round-trip). */
145
- wrapStart?: (start: DoRunTopology['start'], env: Env) => DoRunTopology['start'];
146
- /** Wrap the raw-resume thunk (metered like starts on budgeted hosts). */
147
- wrapResume?: (resume: DoRunTopology['resume'], env: Env) => DoRunTopology['resume'];
217
+ /** Host policy immediately before a validated start reaches the run DO. */
218
+ beforeStart?: (context: ActorContext, env: Env, workflowId: string, inputData: unknown) => Promise<void>;
219
+ /** Host policy immediately before a validated raw resume reaches the run DO. */
220
+ beforeResume?: (context: ActorContext, env: Env, workflowId: string, runId: string, body: unknown) => Promise<void>;
148
221
  /**
149
222
  * Compose approval-driven resume handling. Agent hosts use this to handle
150
223
  * agent-thread targets and delegate generic workflow targets to fallback.
@@ -157,19 +230,22 @@ export interface FlowsafeWorkerConfig<Env extends FlowsafeWorkerEnv> {
157
230
  */
158
231
  notify?: (env: Env) => ApprovalNotificationSink | undefined;
159
232
  /**
160
- * When set, the retention purge (runPurgeMaintenance -> the built-in
161
- * purgeExpiredWorkflowRuns) deletes each expired run's R2 artifacts WITH its
162
- * snapshot row. The snapshot row is the only enumerable record of a run's
163
- * artifact keys (R2 keys lead with workflowId — there is no run-level listing
164
- * without it), so a retention purge without this pairing strands the run's
165
- * artifacts beyond even purgeTenant's reach. Pass the same TenantArtifactPurger
166
- * (an R2ArtifactStore) purgeTenant gets; undefined keeps the byte-identical
167
- * row-only purge. NOT via extraPurgeDuties — that hook runs AFTER the rows are
168
- * deleted, when the keys are already unenumerable.
233
+ * Builds the artifact purger from the current invocation's environment.
234
+ * When set, the retention purge deletes each expired run's R2 artifacts WITH
235
+ * its snapshot row. The snapshot row is the only enumerable record of a run's
236
+ * artifact keys, so a retention purge without this pairing strands artifacts
237
+ * until deployment teardown. Return the same R2-backed store used for runtime
238
+ * writes, or undefined for row-only purge. NOT via extraPurgeDuties: that hook
239
+ * runs after the rows are deleted, when the keys are already unenumerable.
240
+ */
241
+ artifactStore?: (env: Env) => RunArtifactPurger | undefined;
242
+ /**
243
+ * Prefix for every prefix-aware built-in retention table. Must match the
244
+ * max-39 `tablePrefix` contract used when the deployment creates D1 storage.
169
245
  */
170
- artifactStore?: TenantArtifactPurger;
246
+ storageTablePrefix?: string;
171
247
  /**
172
- * Opt-in background-task TTL cleanup. When present, the purge cron
248
+ * Opt-in background-task TTL cleanup. When present, the purge duty
173
249
  * reaps terminal `mastra_background_tasks` rows past the TTL as its OWN
174
250
  * failure-isolated duty — the storage-layer belt to a hosting DO's manager
175
251
  * cleanup (which needs the DO alive). Absent => no duty, byte-identical
@@ -181,68 +257,71 @@ export interface FlowsafeWorkerConfig<Env extends FlowsafeWorkerEnv> {
181
257
  * Opt-in authenticated agent catalog/run router. Structurally typed so this
182
258
  * module does not import the server-only agent-host subpath.
183
259
  */
184
- buildAgentRouter?: (resolve: TenantResolver, env: Env) => AgentRouter | undefined;
260
+ buildAgentRouter?: (resolve: ActorResolver, env: Env) => AgentRouter | undefined;
185
261
  /**
186
262
  * Opt-in signal-ingestion stage. The host builds its
187
263
  * `createSignalRouter` (which needs its per-thread DO namespace via
188
264
  * createThreadTopology, plus its audit/rate/allowlist config) and returns it
189
- * here, closed over the request's resolved TenantResolver; the composer mounts
265
+ * here, closed over the request's ActorResolver; the composer mounts
190
266
  * it after preRoutes, ahead of approvals/runs (its `/api/threads/*` routes
191
267
  * don't overlap). INJECTED rather than built here because createSignalRouter
192
268
  * lives in `signals/`, which imports host-kit — host-kit importing it back
193
269
  * would cycle. Absent (or returns undefined) => no signal stage, byte-identical.
194
270
  */
195
- buildSignalRouter?: (resolve: TenantResolver, env: Env) => ((request: Request) => Promise<Response | null>) | undefined;
271
+ buildSignalRouter?: (resolve: ActorResolver, env: Env) => ((request: Request) => Promise<Response | null>) | undefined;
196
272
  /**
197
273
  * Opt-in goal-objective stage. Mirrors
198
274
  * buildSignalRouter: the host builds its `createObjectiveRouter` (which needs
199
275
  * the thread-state store from its D1 domains, plus its audit/maxRuns config)
200
- * and returns it here, closed over the request's resolved TenantResolver; the
276
+ * and returns it here, closed over the request's ActorResolver; the
201
277
  * composer mounts it after the signal stage. Both live under `/api/threads/*`
202
278
  * but do not overlap — goals use the `/goal` segment, signals the channel
203
279
  * segments. INJECTED rather than built here because createObjectiveRouter lives
204
280
  * in `goals/`, which imports host-kit — host-kit importing it back would cycle.
205
281
  * Absent (or returns undefined) ⇒ no goal stage, byte-identical.
206
282
  */
207
- buildObjectiveRouter?: (resolve: TenantResolver, env: Env) => ((request: Request) => Promise<Response | null>) | undefined;
283
+ buildObjectiveRouter?: (resolve: ActorResolver, env: Env) => ((request: Request) => Promise<Response | null>) | undefined;
208
284
  /**
209
285
  * Opt-in schedule CRUD facade. Mirrors buildSignalRouter/
210
286
  * buildObjectiveRouter: the host builds its `createScheduleRouter` (which needs
211
287
  * the schedules store from its D1 domains + its audit/cap config) and returns it
212
- * here, closed over the request's resolved TenantResolver; the composer mounts it
288
+ * here, closed over the request's ActorResolver; the composer mounts it
213
289
  * after the goal stage. Its `/api/schedules/*` routes don't overlap the others.
214
290
  * INJECTED (not built here, typed structurally) because createScheduleRouter
215
291
  * lives in `schedules/`, which transitively imports host-kit — importing it back
216
292
  * would cycle. Absent (or returns undefined) ⇒ no schedule surface, byte-identical.
217
293
  */
218
- buildScheduleRouter?: (resolve: TenantResolver, env: Env) => ((request: Request) => Promise<Response | null>) | undefined;
294
+ buildScheduleRouter?: (resolve: ActorResolver, env: Env) => ((request: Request) => Promise<Response | null>) | undefined;
219
295
  /**
220
296
  * Opt-in schedule tick. The host builds its `createScheduleTick`
221
297
  * (which needs the schedules store, its run-start seam — topology.start — and
222
298
  * the run-cap + audit config) and returns the closure here. The composer runs
223
- * it on the `crons.tick` cron as its OWN failure-isolated duty (own try/catch,
299
+ * it as its OWN failure-isolated alarm duty (own try/catch,
224
300
  * own `schedule-tick` log line). INJECTED (not built here, structurally typed as
225
301
  * `() => Promise<unknown>`) because createScheduleTick lives in `schedules/`,
226
302
  * which transitively imports host-kit — host-kit importing it back would cycle.
227
- * Absent (or `crons.tick` unset) ⇒ no tick invocation, byte-identical.
303
+ * Absent (or `tickIntervalMs` unset) ⇒ no tick invocation.
228
304
  */
229
305
  scheduleTick?: (env: Env) => (() => Promise<unknown>) | undefined;
230
306
  /**
231
- * Extra purge-cron duties (e.g. the showcase's demo-tenant reaper). The
307
+ * Extra purge duties. The
232
308
  * returned fields fold into the ONE combined `{type:'maintenance'}` log
233
- * line. Isolated: a throw here logs a maintenance-error and never blocks
234
- * the combined log — though duties SHOULD own their try/catch so their
235
- * error surface stays specific.
309
+ * line. A throw reports the purge attempt as failed while the worker still
310
+ * contains it, logs a maintenance-error, and emits the combined log.
236
311
  */
237
- extraPurgeDuties?: (env: Env, cron: string) => Promise<Record<string, unknown>>;
312
+ extraPurgeDuties?: (env: Env) => Promise<Record<string, unknown>>;
238
313
  }
239
- /** The handler triple a host re-exports (behind its own workers-typed casts). */
314
+ export type MaintenanceDuty = 'sweep' | 'purge' | 'tick';
315
+ /** The Worker handler plus the maintenance duty seam consumed by its DO. */
240
316
  export interface FlowsafeWorker<Env extends FlowsafeWorkerEnv> {
241
317
  fetch(request: Request, env: Env, ctx: FlowsafeWorkerContext): Promise<Response>;
242
- scheduled(controller: {
243
- cron: string;
244
- }, env: Env, ctx: FlowsafeWorkerContext): Promise<void>;
245
- queue(batch: AuditMessageBatch<unknown>, env: Env): Promise<void>;
318
+ runMaintenanceDuty(duty: MaintenanceDuty, env: Env): Promise<MaintenanceOutcome>;
246
319
  }
247
320
  export declare function createFlowsafeWorker<Env extends FlowsafeWorkerEnv>(config: FlowsafeWorkerConfig<Env>): FlowsafeWorker<Env>;
321
+ export type MaintenanceDurableObjectConstructor<Env extends FlowsafeWorkerEnv> = new (state: MaintenanceDurableObjectState, env: Env) => {
322
+ fetch(request: Request): Promise<Response>;
323
+ alarm(): Promise<void>;
324
+ };
325
+ /** Build the fixed-name maintenance Durable Object class for one host. */
326
+ export declare function createFlowsafeMaintenanceDurableObject<Env extends FlowsafeWorkerEnv>(config: FlowsafeWorkerConfig<Env>): MaintenanceDurableObjectConstructor<Env>;
248
327
  //# sourceMappingURL=flowsafe-worker.d.ts.map