@proofoftech/flowsafe 0.11.0 → 0.12.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 (384) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/README.md +65 -43
  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 +44 -182
  147. package/dist/do-runner/d1-storage.d.ts.map +1 -1
  148. package/dist/do-runner/d1-storage.js +102 -353
  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/thread-do.d.ts +18 -32
  201. package/dist/do-runner/thread-do.d.ts.map +1 -1
  202. package/dist/do-runner/thread-do.js +52 -74
  203. package/dist/do-runner/thread-do.js.map +1 -1
  204. package/dist/goals/objective-routes.d.ts +7 -4
  205. package/dist/goals/objective-routes.d.ts.map +1 -1
  206. package/dist/goals/objective-routes.js +58 -43
  207. package/dist/goals/objective-routes.js.map +1 -1
  208. package/dist/host-kit/approval-bridge.d.ts +18 -21
  209. package/dist/host-kit/approval-bridge.d.ts.map +1 -1
  210. package/dist/host-kit/approval-bridge.js +37 -37
  211. package/dist/host-kit/approval-bridge.js.map +1 -1
  212. package/dist/host-kit/bearer-auth.d.ts +3 -4
  213. package/dist/host-kit/bearer-auth.d.ts.map +1 -1
  214. package/dist/host-kit/bearer-auth.js +7 -11
  215. package/dist/host-kit/bearer-auth.js.map +1 -1
  216. package/dist/host-kit/do-run-topology.d.ts +14 -5
  217. package/dist/host-kit/do-run-topology.d.ts.map +1 -1
  218. package/dist/host-kit/do-run-topology.js +47 -15
  219. package/dist/host-kit/do-run-topology.js.map +1 -1
  220. package/dist/host-kit/env-vars.d.ts +1 -1
  221. package/dist/host-kit/env-vars.js +1 -1
  222. package/dist/host-kit/flowsafe-worker.d.ts +149 -73
  223. package/dist/host-kit/flowsafe-worker.d.ts.map +1 -1
  224. package/dist/host-kit/flowsafe-worker.js +619 -141
  225. package/dist/host-kit/flowsafe-worker.js.map +1 -1
  226. package/dist/host-kit/host-approval-service.d.ts +62 -54
  227. package/dist/host-kit/host-approval-service.d.ts.map +1 -1
  228. package/dist/host-kit/host-approval-service.js +90 -61
  229. package/dist/host-kit/host-approval-service.js.map +1 -1
  230. package/dist/host-kit/hub-topology.d.ts +6 -7
  231. package/dist/host-kit/hub-topology.d.ts.map +1 -1
  232. package/dist/host-kit/hub-topology.js +16 -12
  233. package/dist/host-kit/hub-topology.js.map +1 -1
  234. package/dist/host-kit/index.d.ts +13 -11
  235. package/dist/host-kit/index.d.ts.map +1 -1
  236. package/dist/host-kit/index.js +9 -12
  237. package/dist/host-kit/index.js.map +1 -1
  238. package/dist/host-kit/maintenance-capability.d.ts +58 -0
  239. package/dist/host-kit/maintenance-capability.d.ts.map +1 -0
  240. package/dist/host-kit/maintenance-capability.js +268 -0
  241. package/dist/host-kit/maintenance-capability.js.map +1 -0
  242. package/dist/host-kit/memory-boundary.d.ts +4 -19
  243. package/dist/host-kit/memory-boundary.d.ts.map +1 -1
  244. package/dist/host-kit/memory-boundary.js +12 -27
  245. package/dist/host-kit/memory-boundary.js.map +1 -1
  246. package/dist/host-kit/resource-access.d.ts +4 -0
  247. package/dist/host-kit/resource-access.d.ts.map +1 -0
  248. package/dist/host-kit/resource-access.js +12 -0
  249. package/dist/host-kit/resource-access.js.map +1 -0
  250. package/dist/host-kit/run-router.d.ts +25 -15
  251. package/dist/host-kit/run-router.d.ts.map +1 -1
  252. package/dist/host-kit/run-router.js +61 -46
  253. package/dist/host-kit/run-router.js.map +1 -1
  254. package/dist/host-kit/state-egress.d.ts +51 -0
  255. package/dist/host-kit/state-egress.d.ts.map +1 -0
  256. package/dist/host-kit/state-egress.js +120 -0
  257. package/dist/host-kit/state-egress.js.map +1 -0
  258. package/dist/host-kit/stream-router.d.ts +9 -4
  259. package/dist/host-kit/stream-router.d.ts.map +1 -1
  260. package/dist/host-kit/stream-router.js +45 -38
  261. package/dist/host-kit/stream-router.js.map +1 -1
  262. package/dist/host-kit/stream-ticket.d.ts +10 -10
  263. package/dist/host-kit/stream-ticket.d.ts.map +1 -1
  264. package/dist/host-kit/stream-ticket.js +60 -90
  265. package/dist/host-kit/stream-ticket.js.map +1 -1
  266. package/dist/host-kit/thread-topology.d.ts +17 -11
  267. package/dist/host-kit/thread-topology.d.ts.map +1 -1
  268. package/dist/host-kit/thread-topology.js +33 -59
  269. package/dist/host-kit/thread-topology.js.map +1 -1
  270. package/dist/host-kit/verifier.d.ts +6 -6
  271. package/dist/host-kit/verifier.d.ts.map +1 -1
  272. package/dist/host-kit/verifier.js +51 -119
  273. package/dist/host-kit/verifier.js.map +1 -1
  274. package/dist/http-body.d.ts +20 -0
  275. package/dist/http-body.d.ts.map +1 -0
  276. package/dist/http-body.js +67 -0
  277. package/dist/http-body.js.map +1 -0
  278. package/dist/schedules/index.d.ts +3 -2
  279. package/dist/schedules/index.d.ts.map +1 -1
  280. package/dist/schedules/index.js +5 -4
  281. package/dist/schedules/index.js.map +1 -1
  282. package/dist/schedules/router.d.ts +16 -10
  283. package/dist/schedules/router.d.ts.map +1 -1
  284. package/dist/schedules/router.js +153 -91
  285. package/dist/schedules/router.js.map +1 -1
  286. package/dist/schedules/schedules-d1.d.ts +88 -0
  287. package/dist/schedules/schedules-d1.d.ts.map +1 -1
  288. package/dist/schedules/schedules-d1.js +411 -50
  289. package/dist/schedules/schedules-d1.js.map +1 -1
  290. package/dist/schedules/target-policy.d.ts +29 -0
  291. package/dist/schedules/target-policy.d.ts.map +1 -0
  292. package/dist/schedules/target-policy.js +70 -0
  293. package/dist/schedules/target-policy.js.map +1 -0
  294. package/dist/schedules/tick.d.ts +125 -21
  295. package/dist/schedules/tick.d.ts.map +1 -1
  296. package/dist/schedules/tick.js +637 -160
  297. package/dist/schedules/tick.js.map +1 -1
  298. package/dist/signal-providers/delivery.d.ts +0 -19
  299. package/dist/signal-providers/delivery.d.ts.map +1 -1
  300. package/dist/signal-providers/delivery.js +5 -54
  301. package/dist/signal-providers/delivery.js.map +1 -1
  302. package/dist/signal-providers/github-provider.d.ts.map +1 -1
  303. package/dist/signal-providers/github-provider.js +9 -16
  304. package/dist/signal-providers/github-provider.js.map +1 -1
  305. package/dist/signal-providers/host-do.d.ts +3 -45
  306. package/dist/signal-providers/host-do.d.ts.map +1 -1
  307. package/dist/signal-providers/host-do.js +86 -106
  308. package/dist/signal-providers/host-do.js.map +1 -1
  309. package/dist/signal-providers/host-topology.d.ts +5 -14
  310. package/dist/signal-providers/host-topology.d.ts.map +1 -1
  311. package/dist/signal-providers/host-topology.js +11 -25
  312. package/dist/signal-providers/host-topology.js.map +1 -1
  313. package/dist/signal-providers/index.d.ts +3 -3
  314. package/dist/signal-providers/index.d.ts.map +1 -1
  315. package/dist/signal-providers/index.js +3 -3
  316. package/dist/signal-providers/index.js.map +1 -1
  317. package/dist/signal-providers/provider.d.ts +4 -5
  318. package/dist/signal-providers/provider.d.ts.map +1 -1
  319. package/dist/signal-providers/provider.js +5 -6
  320. package/dist/signal-providers/provider.js.map +1 -1
  321. package/dist/signal-providers/subscription-d1.d.ts +10 -57
  322. package/dist/signal-providers/subscription-d1.d.ts.map +1 -1
  323. package/dist/signal-providers/subscription-d1.js +208 -155
  324. package/dist/signal-providers/subscription-d1.js.map +1 -1
  325. package/dist/signal-providers/webhook-route.d.ts +28 -14
  326. package/dist/signal-providers/webhook-route.d.ts.map +1 -1
  327. package/dist/signal-providers/webhook-route.js +117 -88
  328. package/dist/signal-providers/webhook-route.js.map +1 -1
  329. package/dist/signals/client.js +8 -8
  330. package/dist/signals/client.js.map +1 -1
  331. package/dist/signals/d1-shared.js +1 -1
  332. package/dist/signals/d1-shared.js.map +1 -1
  333. package/dist/signals/index.d.ts +1 -1
  334. package/dist/signals/index.d.ts.map +1 -1
  335. package/dist/signals/index.js.map +1 -1
  336. package/dist/signals/notification-dispatch.d.ts +12 -6
  337. package/dist/signals/notification-dispatch.d.ts.map +1 -1
  338. package/dist/signals/notification-dispatch.js +37 -21
  339. package/dist/signals/notification-dispatch.js.map +1 -1
  340. package/dist/signals/notifications-d1.d.ts +5 -8
  341. package/dist/signals/notifications-d1.d.ts.map +1 -1
  342. package/dist/signals/notifications-d1.js +8 -13
  343. package/dist/signals/notifications-d1.js.map +1 -1
  344. package/dist/signals/router.d.ts +10 -10
  345. package/dist/signals/router.d.ts.map +1 -1
  346. package/dist/signals/router.js +49 -51
  347. package/dist/signals/router.js.map +1 -1
  348. package/dist/signals/thread-do-routes.d.ts +74 -15
  349. package/dist/signals/thread-do-routes.d.ts.map +1 -1
  350. package/dist/signals/thread-do-routes.js +484 -41
  351. package/dist/signals/thread-do-routes.js.map +1 -1
  352. package/dist/signals/thread-state-d1.d.ts.map +1 -1
  353. package/dist/signals/thread-state-d1.js +2 -3
  354. package/dist/signals/thread-state-d1.js.map +1 -1
  355. package/package.json +29 -6
  356. package/scripts/seed-deployment-identity.mjs +252 -0
  357. package/dist/approval-api/tenant-brand.d.ts +0 -35
  358. package/dist/approval-api/tenant-brand.d.ts.map +0 -1
  359. package/dist/approval-api/tenant-brand.js +0 -19
  360. package/dist/approval-api/tenant-brand.js.map +0 -1
  361. package/dist/approval-api/tenant-context.d.ts +0 -84
  362. package/dist/approval-api/tenant-context.d.ts.map +0 -1
  363. package/dist/approval-api/tenant-context.js +0 -112
  364. package/dist/approval-api/tenant-context.js.map +0 -1
  365. package/dist/approval-api/tenant-store.d.ts +0 -36
  366. package/dist/approval-api/tenant-store.d.ts.map +0 -1
  367. package/dist/approval-api/tenant-store.js +0 -129
  368. package/dist/approval-api/tenant-store.js.map +0 -1
  369. package/dist/do-runner/resume-ledger.d.ts +0 -48
  370. package/dist/do-runner/resume-ledger.d.ts.map +0 -1
  371. package/dist/do-runner/resume-ledger.js +0 -60
  372. package/dist/do-runner/resume-ledger.js.map +0 -1
  373. package/dist/do-runner/thread-header.d.ts +0 -31
  374. package/dist/do-runner/thread-header.d.ts.map +0 -1
  375. package/dist/do-runner/thread-header.js +0 -39
  376. package/dist/do-runner/thread-header.js.map +0 -1
  377. package/dist/host-kit/subdomain-check.d.ts +0 -23
  378. package/dist/host-kit/subdomain-check.d.ts.map +0 -1
  379. package/dist/host-kit/subdomain-check.js +0 -61
  380. package/dist/host-kit/subdomain-check.js.map +0 -1
  381. package/dist/host-kit/tenant-registry.d.ts +0 -51
  382. package/dist/host-kit/tenant-registry.d.ts.map +0 -1
  383. package/dist/host-kit/tenant-registry.js +0 -88
  384. package/dist/host-kit/tenant-registry.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,41 @@
1
1
  # @proofoftech/flowsafe
2
2
 
3
+ ## 0.12.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 3276c2a: Use `jose` for actor JWT verification and stream-ticket signing. Stream tickets are now standard three-segment JWTs with a dedicated audience and `typ`, so actor tokens and stream tickets cannot cross-verify even if a deployment reuses a secret. Existing verifier injection, actor validation, issuer, audience, expiry, and key-selection behavior remains fail closed.
8
+
9
+ GitHub webhook signatures now require the exact `sha256=<64 hex>` shape before raw-byte WebCrypto verification. Malformed signatures and invalid UTF-8 JSON return stable client errors without throwing, while empty and non-ASCII payloads remain byte-exact.
10
+
11
+ Deployment identity provisioning now recognizes Cloudflare D1's exact `_cf_KV` and `_cf_METADATA` internal tables on a fresh database while continuing to reject arbitrary or lookalike pre-existing application tables.
12
+
13
+ - b3b4b55: Replace pooled request-level tenancy with one physically isolated organization per deployment.
14
+
15
+ This breaking release requires `DEPLOYMENT_TENANT`, a matching D1 sentinel seeded before application migrations, and a per-deployment `DEPLOYMENT_IDENTITY_SECRET`. The Worker validates the strict singleton sentinel, and production Durable Objects also authenticate every Worker caller before reading storage.
16
+
17
+ `ActorContext`, `ActorResolver`, and `createActorResolver()` replace their tenant-named equivalents. Approval and subscription factories now expose `.store()`, run, thread, schedule, and subscription ids are opaque and server-minted, and live hubs, provider hosts, and background-task hosts are deployment singletons.
18
+
19
+ Tenant-branded stores, tenant-prefixed id helpers, the tenant registry, subdomain cross-check, and in-database tenant purge APIs have been removed. First-time sentinel provisioning refuses any database with pre-existing application tables; provision a fresh database for each organization.
20
+
21
+ `createFlowsafeWorker()` no longer exposes the unused `wrapResolve` hook. Authenticate and validate actors in `buildVerifier`, mount deployment-specific routes through `preRoutes`, and enforce final mutation policy through `beforeStart` or `beforeResume`.
22
+
23
+ `createFlowsafeWorker()` now delegates sweep, purge, and optional schedule-tick duties to `createFlowsafeMaintenanceDurableObject()`. Tenant Workers no longer export `scheduled()` or `queue()` handlers and contain no cron triggers or queue consumers. Provisioning must set a distinct `MAINTENANCE_ADMIN_SECRET`, call `POST /admin/ensure-maintenance`, and monitor `GET /admin/maintenance-status`.
24
+
25
+ The maintenance singleton persists and re-arms its next alarm before running one due duty. A failed or terminated duty cannot break the alarm chain, starve another due duty, or update the last-success timestamp.
26
+
27
+ Externally authored fleet releases no longer receive the reusable maintenance administrator secret or a shared audit Queue producer. They relay operation-bound, short-lived maintenance capabilities to trusted state and require signed results, and send untrusted audit events through an authenticated trusted-state proxy that supplies canonical infrastructure attribution.
28
+
29
+ Server-minted runs, threads, and schedules plus validated host-owned resource keys retain per-principal authorization through the deployment-local resource-owner registry. Inaccessible resources return `404` before role checks.
30
+
31
+ The package now ships `flowsafe-provision` for strict D1 sentinel provisioning. The CLI resolves a consumer-installed Wrangler `>=4 <5` optional peer, rejects other Wrangler majors, and maps preview provisioning to Wrangler's remote preview target.
32
+
33
+ The deployment-identity protocol is exported as `@proofoftech/flowsafe/deployment-identity-protocol` for trusted fleet provisioners that must apply the same sentinel rules through another Cloudflare API client.
34
+
35
+ Opt-in HTTP approval creation now requires write access to the named run. Those client-filed records remain decision-only; only trusted suspension-bound, run-scoped, or server-targeted approvals can resume execution.
36
+
37
+ Subscription stores now snapshot caller input before persistence and use the same JSON metadata semantics in D1 and memory. External provider resource ids reject ASCII controls and values larger than 1,024 UTF-8 bytes.
38
+
3
39
  ## 0.11.0
4
40
 
5
41
  ### Minor Changes
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @proofoftech/flowsafe
2
2
 
3
- Durable approvals and tenant-safe long-running execution for Mastra on Cloudflare.
3
+ Durable approvals and physically isolated long-running execution for Mastra on Cloudflare.
4
4
 
5
5
  Flowsafe runs Mastra workflows and agents through Cloudflare Durable Objects, stores their snapshots in D1, turns suspensions into human approval requests, and derives connector grants from stored decisions when a run resumes.
6
6
 
@@ -28,6 +28,7 @@ Compatibility:
28
28
  - `@mastra/core` in the declared `^1.50.0` peer range
29
29
  - `react` and `react-dom` `>=18 <20` (React 18 or 19) for the optional approval UI
30
30
  - `@proofoftech/breakwater` `>=0.9.0 <1.0.0` when used
31
+ - `wrangler` `>=4 <5` for the optional `flowsafe-provision` CLI
31
32
 
32
33
  ## Choose an export
33
34
 
@@ -35,10 +36,10 @@ Compatibility:
35
36
  | --- | --- |
36
37
  | `@proofoftech/flowsafe` | Compatibility barrel for approval API, runner, artifacts, and audit export |
37
38
  | `@proofoftech/flowsafe/agent-host` | Server-only guarded-agent catalogs, authenticated run routes, thread hosting, NDJSON observation, and approval-only resume |
38
- | `@proofoftech/flowsafe/approval-api` | Approval records, service, tenant-bound stores, REST router, grants, SLA, retention, notifications, and stream events |
39
- | `@proofoftech/flowsafe/do-runner` | Durable Object runner, D1 storage, run summaries, identities, pub/sub, resume ledger, retention, and offboarding |
39
+ | `@proofoftech/flowsafe/approval-api` | Approval records, actor resolver, service, deployment store, REST router, grants, SLA, retention, notifications, and stream events |
40
+ | `@proofoftech/flowsafe/do-runner` | Durable Object runner, D1 storage, deployment sentinel, run summaries, snapshot provenance, identities, pub/sub, and retention |
40
41
  | `@proofoftech/flowsafe/approval-ui` | Styling-library-agnostic React dashboard, DOM-free API client, headless hook, and live transport |
41
- | `@proofoftech/flowsafe/host-kit` | Auth seams, tenant resolver, topologies, run/stream routers, approval bridges, and composed Worker |
42
+ | `@proofoftech/flowsafe/host-kit` | Authenticator and verifier seams, topologies, run/stream routers, approval bridges, and composed Worker |
42
43
  | `@proofoftech/flowsafe/host-kit/module` | Import-safe workflow module contract |
43
44
  | `@proofoftech/flowsafe/artifacts` | R2 artifact store and in-memory test bucket |
44
45
  | `@proofoftech/flowsafe/audit-export` | Cloudflare Queue producer sink and NDJSON SIEM consumer |
@@ -46,8 +47,8 @@ Compatibility:
46
47
  | `@proofoftech/flowsafe/signals` | Thread signal routes, ingestion router, D1 notification/state domains, dispatch, and client |
47
48
  | `@proofoftech/flowsafe/signals/client` | DOM-free signal client without Worker code |
48
49
  | `@proofoftech/flowsafe/goals` | Durable objective router |
49
- | `@proofoftech/flowsafe/schedules` | D1 schedules, tenant facade, reserved-context controls, and CAS tick |
50
- | `@proofoftech/flowsafe/background-tasks` | Tenant task host, D1 task domains, routes, and cleanup |
50
+ | `@proofoftech/flowsafe/schedules` | D1 schedules, deployment router, reserved-context controls, and CAS tick |
51
+ | `@proofoftech/flowsafe/background-tasks` | Deployment task host, D1 task domains, routes, and cleanup |
51
52
  | `@proofoftech/flowsafe/signal-providers` | Alarm-driven provider host, topology, subscriptions, verified webhooks, and GitHub reference provider |
52
53
 
53
54
  New host-side and React features are subpath-only. This keeps the root import free of Breakwater, durable-agent-host, and UI dependency graphs.
@@ -58,13 +59,14 @@ Copy the [reference deployment](https://github.com/ProofOfTechOrg/anchorage/tree
58
59
 
59
60
  - one Durable Object per run;
60
61
  - D1-backed Mastra snapshots and approvals;
61
- - bearer-authentication seam and tenant resolver;
62
+ - bearer-authentication seam and actor resolver;
63
+ - strict D1 deployment sentinel plus authenticated Worker-to-Durable-Object calls;
62
64
  - workflow catalog, start, status, and resume routes;
63
65
  - suspension-to-approval bridge;
64
66
  - exact suspension-bound breakwater grant derivation;
65
67
  - role checks and separation of duties;
66
68
  - optional live approval/run WebSockets;
67
- - cron-owned SLA sweep and retention purge;
69
+ - alarm-owned SLA sweep and retention purge;
68
70
  - structured audit and optional Queue-to-SIEM export;
69
71
  - a sample gated workflow.
70
72
 
@@ -82,8 +84,12 @@ import {
82
84
  import { approvalStoreFactoryFor } from '@proofoftech/flowsafe/host-kit';
83
85
 
84
86
  export class AppRunner extends DurableObjectRunner<Env> {
87
+ protected runOwnership(env: Env) {
88
+ return approvalStoreFactoryFor(env.DB).resources();
89
+ }
90
+
85
91
  protected build(env: Env): RunnerRuntime {
86
- const approvals = approvalStoreFactoryFor(env.DB).forTenant(this.tenantId);
92
+ const approvals = approvalStoreFactoryFor(env.DB).store();
87
93
  const { createWorkflow, createStep, runtime } = init(env, {
88
94
  requestContextForRun: approvalGrantProvider(approvals),
89
95
  });
@@ -102,7 +108,7 @@ export class AppRunner extends DurableObjectRunner<Env> {
102
108
  When a workflow or durable agent suspends:
103
109
 
104
110
  1. The authoritative run summary captures `stepPath`, `suspendedAt`, and `resumeCount`.
105
- 2. The trusted host bridge creates one open approval in a tenant-bound store.
111
+ 2. The trusted host bridge creates one open approval in the deployment store.
106
112
  3. The record's connector IDs and optional Mastra `toolCallId` come from a server-authored suspend payload.
107
113
  4. A reviewer claims, delegates, approves, or rejects through the service or REST router.
108
114
  5. A compare-and-swap commits the mutation.
@@ -138,9 +144,9 @@ Self-decision is denied by default. A non-exempt actor also cannot approve a lat
138
144
 
139
145
  ### SLA, notifications, and retention
140
146
 
141
- `sweepSLA()` accepts the system-only cross-tenant store and escalates overdue open records. It is intended for a scheduled invocation and is not an HTTP service method.
147
+ `sweepSLA()` accepts the deployment store and escalates overdue open records. It is intended for a scheduled invocation and is not an HTTP service method.
142
148
 
143
- `ApprovalNotificationSink` receives creation and escalation events. Failures are contained and audited. `ApprovalStreamSink` publishes mutations to the optional tenant hub.
149
+ `ApprovalNotificationSink` receives creation and escalation events. Failures are contained and audited. `ApprovalStreamSink` publishes mutations to the optional deployment hub.
144
150
 
145
151
  `purgeExpiredApprovals()` deletes only approved and rejected records past the configured age. Pending, claimed, and escalated records remain live at any age.
146
152
 
@@ -180,39 +186,51 @@ The package includes:
180
186
 
181
187
  Flowsafe has no Astryx or CSS dependency. The repository showcase injects Astryx in the application only.
182
188
 
183
- ## Multi-tenancy
189
+ ## Physical deployment isolation
190
+
191
+ Flowsafe serves one organization per Worker, D1 database, and set of Durable Object namespaces. It does not provide a pooled multi-tenant mode.
184
192
 
185
- Flowsafe applies three base invariants.
193
+ ### Deployment identity fails closed
186
194
 
187
- ### The run id carries the tenant
195
+ Provisioning writes the same stable tag to the `DEPLOYMENT_TENANT` binding and the singleton `flowsafe_deployment` D1 row. The Worker checks the pair before protected routes and maintenance work. Every Worker topology stamps `DEPLOYMENT_IDENTITY_SECRET` on Durable Object requests; the target compares the credential and validates its own tag and sentinel before reading storage.
188
196
 
189
- The host mints `${tenantId}_${uuid}` from authenticated context. `RunnerRuntime.start()` requires a run id and has no generation fallback. Status and resume return 404 for a foreign run.
197
+ Seed the sentinel before application migrations or traffic. First-time provisioning refuses any database that already contains application tables. A missing binding, malformed sentinel schema, non-singleton row set, malformed tag, credential mismatch, or tag mismatch returns `503` at the Worker or prevents Durable Object initialization.
190
198
 
191
- The run id scopes the snapshot, Durable Object, connector isolation context, approval lookup, and artifact path.
199
+ The package ships the `flowsafe-provision` CLI. It resolves Wrangler 4 from the application instead of downloading a CLI at runtime:
192
200
 
193
- ### Stores bind at construction
201
+ ```bash
202
+ npm install --save-dev wrangler@^4
203
+ npx flowsafe-provision \
204
+ --database <database> \
205
+ --tag <tag> \
206
+ --remote \
207
+ --config wrangler.jsonc
208
+ ```
194
209
 
195
- `D1ApprovalStoreFactory.forTenant()` returns a branded tenant-bound store. Request handlers cannot pass an unbound or system store where a tenant store is required.
210
+ Fleet control planes can import the same fail-closed sentinel implementation from `@proofoftech/flowsafe/deployment-identity-protocol` instead of duplicating its schema or race handling.
196
211
 
197
- Construct the store after authentication through `createTenantResolver()`. The system store exists only for scheduled cross-tenant maintenance.
212
+ ### Runtime ids are opaque
198
213
 
199
- ### The tenant charset makes prefix ownership exact
214
+ The host mints opaque, path-safe run and thread ids. `RunnerRuntime.start()` requires a host-owned run id and has no generation fallback. The id scopes the snapshot, Durable Object, approval lookup, stream address, and artifact path, but it carries no customer identity.
200
215
 
201
- Tenant ids match `^[a-z0-9]{3,32}$`. This excludes the `_` run and memory delimiter, making prefix ownership and D1 range deletion exact.
216
+ ### Stores are deployment-wide
202
217
 
203
- Provision each named tenant before issuing credentials. Do not infer customer identity from a slug without the registry.
218
+ `D1ApprovalStoreFactory.store()` and `D1SubscriptionStoreFactory.store()` return the store for the bound database. Tables and indexes contain no tenant column. Legacy pooled schemas require a fresh database.
204
219
 
205
- ## Memory, retention, and offboarding
220
+ `D1ApprovalStoreFactory.resources()` records ownership of server-minted runs, threads, and schedules plus validated host-owned resource keys. Operators and builders can access only their principal's resources; reviewers and viewers can read existing resources; admins can administer them. Inaccessible resources return `404` before role errors.
206
221
 
207
- Mastra memory ids are caller-chosen by default. In a multi-tenant host:
222
+ `deploymentTag` is audit attribution only. It comes from verified infrastructure and never authorizes a request or scopes a query.
208
223
 
209
- - mint threads with `TenantContext.newThreadId()`;
210
- - mint resources with `TenantContext.newResourceId(key)`;
224
+ ## Memory and retention
225
+
226
+ Mastra memory ids are caller-chosen by default. A Flowsafe host must:
227
+
228
+ - mint threads with `ActorContext.newThreadId()`;
229
+ - validate host-owned resource keys with `ActorContext.resourceIdFromKey(key)`;
211
230
  - reject client bodies that name memory ids;
212
- - return 404 for foreign stored ids;
213
231
  - reach a thread Durable Object only through `createThreadTopology()`.
214
232
 
215
- Retention helpers cover:
233
+ TTL retention helpers cover:
216
234
 
217
235
  - terminal workflow snapshots;
218
236
  - decided approvals;
@@ -222,9 +240,7 @@ Retention helpers cover:
222
240
  - schedule trigger history;
223
241
  - terminal background tasks.
224
242
 
225
- Schedules, resources/working memory, and provider subscriptions are standing state and delete at offboarding, not by default TTL.
226
-
227
- `purgeTenant()` deletes every adopted tenant domain. Pass the artifact store so R2 objects delete with their owning run rows.
243
+ Schedules, resources, working memory, and provider subscriptions are standing state. The schedule and subscription routes support authorized deletion. Flowsafe does not ship a public resource or permanent thread-deletion route: a host that adds one must remove every authoritative binding and wake source before it calls `ActorContext.releaseResource()` for the thread or resource claim. Run retention and schedule deletion release their ownership claims; idle-thread retention deliberately does not. Deployment decommissioning removes any remainder. TTL retention, explicit teardown, and decommissioning are separate lifecycle mechanisms.
228
244
 
229
245
  ## Artifacts
230
246
 
@@ -234,7 +250,7 @@ Schedules, resources/working memory, and provider subscriptions are standing sta
234
250
  [prefix/]workflowId/runId/name
235
251
  ```
236
252
 
237
- Workflow and run ids use the runner's path-safe pattern. Artifact names are validated segment by segment. `deleteRun()` pairs with terminal-run retention; tenant purge removes the remaining tenant artifacts.
253
+ Workflow and run ids use the runner's path-safe pattern. Artifact names are validated segment by segment. `deleteRun()` pairs with terminal-run retention. Deployment decommissioning removes the remaining bucket data.
238
254
 
239
255
  `InMemoryArtifactBucket` is available for tests and offline demos.
240
256
 
@@ -242,13 +258,15 @@ Workflow and run ids use the runner's path-safe pattern. Artifact names are vali
242
258
 
243
259
  `queueAuditSink(queue)` turns the shared audit contract into Cloudflare Queue messages. `createAuditQueueConsumer()` batches records as NDJSON, posts them to the configured collector, acknowledges the batch on 2xx, and retries otherwise.
244
260
 
261
+ For an externally authored fleet release, do not expose that shared Queue binding to the candidate. Bind the candidate to the trusted state Worker as `AUDIT_PROXY` and enable the matching candidate and trusted-ingress fleet markers. The adapter authenticates with the deployment identity; trusted state supplies canonical tenant, environment, and script attribution before enqueueing. The envelope marks the candidate event itself as untrusted, so its action, decision, resource, and detail remain claims rather than infrastructure attestations.
262
+
245
263
  The types are structural and do not require `@cloudflare/workers-types`. A transform seam can map internal events to your SIEM schema.
246
264
 
247
265
  ## Live streaming
248
266
 
249
267
  Live updates are opt-in behind a `HUB` Durable Object binding and `STREAM_TICKET_SECRET`.
250
268
 
251
- An authenticated REST request mints a short-lived HMAC ticket. The browser presents it when opening a queue or run WebSocket. The Worker is the only verifier, and each Durable Object rebinds the addressed tenant or run through its own identity.
269
+ An authenticated REST request mints a short-lived HMAC ticket. The browser presents it when opening a queue or run WebSocket. The Worker is the only verifier. The singleton hub and each run Durable Object rebind the addressed channel through their own identities.
252
270
 
253
271
  Tickets carry addressing information only. They contain no connector grant or approval decision. Polling remains available as fallback and reconciliation.
254
272
 
@@ -288,17 +306,17 @@ Agent event replay lasts only as long as the configured Mastra cache. The defaul
288
306
 
289
307
  ### Schedules
290
308
 
291
- `D1SchedulesStorage` implements the schedule domain. `createScheduleRouter()` provides tenant-filtered CRUD and read-only trigger history. `createScheduleTick()` claims due fires with CAS, protects reserved context keys, checks unattended-run caps, mints a tenant run id, and starts a workflow or agent through the correct topology.
309
+ `D1SchedulesStorage` implements the schedule domain. `createScheduleRouter()` provides deployment-wide role-gated CRUD and read-only trigger history. `createScheduleTick()` claims due fires with compare-and-swap (CAS), protects reserved context keys, consults the configured unattended-run cap, mints an opaque run id, and starts a workflow or agent through the correct topology. Without the optional cap seam, unattended starts are uncapped.
292
310
 
293
311
  ### Background tasks
294
312
 
295
- `createBackgroundTaskD1Domains()` supplies serialized workflow and tenant task storage. `BackgroundTaskHost` owns one manager per tenant Durable Object, while `createBackgroundTaskRoutes()` exposes its host surface. Terminal task cleanup is opt-in through the composed Worker.
313
+ `createBackgroundTaskD1Domains()` supplies serialized workflow and deployment task storage. `BackgroundTaskHost` owns one singleton manager Durable Object, while `createBackgroundTaskRoutes()` exposes its host surface. Terminal task cleanup is opt-in through the composed Worker.
296
314
 
297
315
  ### Signal providers
298
316
 
299
317
  Flowsafe providers route polling and webhook deliveries through the thread topology instead of Mastra's in-process registry.
300
318
 
301
- `SignalProviderHost` runs one alarm-driven host per tenant. `D1SubscriptionStoreFactory` persists subscriptions. Human-only subscription routes reconcile provider alarms after each committed mutation. Webhook routes verify raw bytes before parsing, derive the tenant from the stored subscription, apply a provider-and-tenant rate cap, and bound forgery audit.
319
+ `SignalProviderHost` runs one alarm-driven host per deployment. `D1SubscriptionStoreFactory` persists subscriptions. External resource ids are opaque, but must be non-empty, contain no ASCII control characters, and fit within 1,024 UTF-8 bytes. Human-only subscription routes reconcile provider alarms after each committed mutation. Webhook routes verify raw bytes before parsing, look up the stored subscription, apply a provider rate cap, and bound forgery audit.
302
320
 
303
321
  `githubSignalProvider()` is the reference provider.
304
322
 
@@ -306,9 +324,9 @@ Complete wiring is in the [durable-agents guide](https://github.com/ProofOfTechO
306
324
 
307
325
  ## Deployment and operations
308
326
 
309
- The composed `createFlowsafeWorker()` owns the shared route, scheduled, and Queue pipeline. Hosts inject workflows, identity verification, topology-backed optional routers, budget wrappers, notification transport, artifact pairing, schedule tick, and extra purge duties.
327
+ The composed `createFlowsafeWorker()` owns the shared route and maintenance-duty pipeline. Hosts inject workflows, identity verification, topology-backed optional routers, budget wrappers, notification transport, artifact pairing, schedule tick, and extra purge duties.
310
328
 
311
- Use separate cron expressions for approval SLA sweep, retention purge, and schedule fire. Provider polling uses per-tenant Durable Object alarms.
329
+ `createFlowsafeMaintenanceDurableObject()` runs approval service-level agreement (SLA) sweep, retention purge, and optional schedule fire as separate alarm invocations. Provider polling and background recovery use their own Durable Object alarms.
312
330
 
313
331
  Read:
314
332
 
@@ -322,19 +340,23 @@ Flowsafe does not authenticate users, execute an identity-provider protocol, pro
322
340
 
323
341
  Critical host obligations:
324
342
 
325
- - derive tenants and actors from verified credentials;
326
- - mint run, thread, resource, schedule, and subscription identities server-side;
343
+ - deploy one Worker, D1 database, and set of Durable Object namespaces per organization;
344
+ - seed `flowsafe_deployment` before application migrations, configure `DEPLOYMENT_TENANT`, and keep the values identical;
345
+ - set a distinct `DEPLOYMENT_IDENTITY_SECRET` for internal Durable Object calls;
346
+ - set a separate `MAINTENANCE_ADMIN_SECRET`, bootstrap the fixed maintenance singleton after deploy, and monitor its alarm status; for externally authored releases, keep that secret only in trusted state and relay short-lived signed capabilities through the candidate;
347
+ - derive actors and roles from verified credentials;
348
+ - mint run, thread, schedule, and subscription identities server-side, validate host-owned resource keys, and preserve their principal ownership records;
327
349
  - keep connector lists and agent resume targets server-authored;
328
350
  - persist the original authorized agent requester and resume execution as that principal;
329
351
  - expose decisions only through the approval path;
330
352
  - configure shared stores for cross-isolate connector budgets;
331
353
  - keep raw Durable Object namespaces behind the exported topologies;
332
- - schedule every enabled domain's retention and offboarding path;
354
+ - schedule every enabled domain's retention path and define deployment decommissioning;
333
355
  - protect model, provider, stream-ticket, webhook, and SIEM secrets separately.
334
356
 
335
357
  ## Verification
336
358
 
337
- The repository's deterministic workerd spike proves suspend, process restart, resume, forged-resume denial, repeated gates, tenant isolation, live streaming, durable-agent recovery, signals, goals, schedules, providers, notifications, and background-task restart.
359
+ The repository's deterministic workerd spike proves suspend, process restart, resume, forged-resume denial, repeated gates, deployment-sentinel mismatch refusal, live streaming, durable-agent recovery, signals, goals, schedules, providers, notifications, and background-task restart. Durable Object conformance suites separately cover wrong and missing internal caller credentials.
338
360
 
339
361
  ```bash
340
362
  pnpm --filter @proofoftech/flowsafe spike:verify
@@ -0,0 +1,52 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+
3
+ export interface DeploymentIdentityProtocolStatement {
4
+ readonly mode: 'read' | 'write';
5
+ readonly sql: string;
6
+ readonly bindings: readonly unknown[];
7
+ }
8
+
9
+ export type DeploymentIdentityProtocolRow = Readonly<Record<string, unknown>>;
10
+
11
+ export type DeploymentIdentityProtocolExecutor = (
12
+ statement: DeploymentIdentityProtocolStatement,
13
+ ) => Promise<readonly DeploymentIdentityProtocolRow[]>;
14
+
15
+ export const DEPLOYMENT_TAG_PATTERN: RegExp;
16
+ export const DEPLOYMENT_ENVIRONMENT_PATTERN: RegExp;
17
+ export const DEPLOYMENT_SENTINEL_TABLE: 'flowsafe_deployment';
18
+ export const DEPLOYMENT_SENTINEL_DDL: string;
19
+ export const DEPLOYMENT_SENTINEL_COLUMNS: readonly Readonly<{
20
+ name: string;
21
+ type: string;
22
+ notnull: number;
23
+ pk: number;
24
+ }>[];
25
+
26
+ export class DeploymentIdentityError extends Error {}
27
+
28
+ export function isDeploymentEnvironment(value: unknown): value is string;
29
+
30
+ export function assertValidDeploymentTag(
31
+ tag: unknown,
32
+ caller: string,
33
+ ): asserts tag is string;
34
+
35
+ export function normalizeDeploymentSentinelSql(sql: string): string;
36
+
37
+ export function deploymentIdentityApplicationTables(
38
+ rows: readonly DeploymentIdentityProtocolRow[],
39
+ ): string[];
40
+
41
+ export function readDeploymentIdentityProtocol(
42
+ execute: DeploymentIdentityProtocolExecutor,
43
+ ): Promise<string | undefined>;
44
+
45
+ export function provisionDeploymentIdentityProtocol(
46
+ execute: DeploymentIdentityProtocolExecutor,
47
+ tag: string,
48
+ options?: {
49
+ caller?: string;
50
+ provisionedAt?: string;
51
+ },
52
+ ): Promise<void>;
@@ -0,0 +1,231 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+
3
+ export const DEPLOYMENT_TAG_PATTERN = /^[a-z0-9]{3,32}$/;
4
+ export const DEPLOYMENT_ENVIRONMENT_PATTERN =
5
+ /^[a-z0-9](?:[a-z0-9-]{0,30}[a-z0-9])?$/;
6
+ export const DEPLOYMENT_SENTINEL_TABLE = 'flowsafe_deployment';
7
+ export const DEPLOYMENT_SENTINEL_DDL = `CREATE TABLE IF NOT EXISTS ${DEPLOYMENT_SENTINEL_TABLE} (
8
+ id INTEGER PRIMARY KEY CHECK (id = 1),
9
+ tenant_tag TEXT NOT NULL,
10
+ provisioned_at TEXT NOT NULL
11
+ )`;
12
+ export const DEPLOYMENT_SENTINEL_COLUMNS = Object.freeze([
13
+ Object.freeze({ name: 'id', type: 'INTEGER', notnull: 0, pk: 1 }),
14
+ Object.freeze({ name: 'tenant_tag', type: 'TEXT', notnull: 1, pk: 0 }),
15
+ Object.freeze({
16
+ name: 'provisioned_at',
17
+ type: 'TEXT',
18
+ notnull: 1,
19
+ pk: 0,
20
+ }),
21
+ ]);
22
+
23
+ const SENTINEL_SQL_PATTERN =
24
+ /^create table (?:if not exists )?flowsafe_deployment\s*\(\s*id integer primary key check\s*\(\s*id\s*=\s*1\s*\)\s*,\s*tenant_tag text not null\s*,\s*provisioned_at text not null\s*\)$/i;
25
+ const D1_OWNED_INTERNAL_TABLES = Object.freeze(['_cf_KV', '_cf_METADATA']);
26
+ const D1_OWNED_TABLE_EXCLUSIONS = D1_OWNED_INTERNAL_TABLES.map(
27
+ (name) => ` AND name <> '${name}'`,
28
+ ).join('\n');
29
+
30
+ const SCAN_TABLES = Object.freeze({
31
+ mode: 'read',
32
+ sql: `SELECT name, sql FROM sqlite_schema WHERE type = 'table' ORDER BY name`,
33
+ bindings: Object.freeze([]),
34
+ });
35
+ const READ_SENTINEL_SCHEMA = Object.freeze({
36
+ mode: 'read',
37
+ sql: `SELECT sql FROM sqlite_schema WHERE type = 'table' AND name = ?`,
38
+ bindings: Object.freeze([DEPLOYMENT_SENTINEL_TABLE]),
39
+ });
40
+ const READ_SENTINEL_COLUMNS = Object.freeze({
41
+ mode: 'read',
42
+ sql: `PRAGMA table_info(${DEPLOYMENT_SENTINEL_TABLE})`,
43
+ bindings: Object.freeze([]),
44
+ });
45
+ const READ_SENTINEL_OWNER = Object.freeze({
46
+ mode: 'read',
47
+ sql: `SELECT id, tenant_tag FROM ${DEPLOYMENT_SENTINEL_TABLE} ORDER BY id`,
48
+ bindings: Object.freeze([]),
49
+ });
50
+ const CREATE_SENTINEL = Object.freeze({
51
+ mode: 'write',
52
+ sql: DEPLOYMENT_SENTINEL_DDL,
53
+ bindings: Object.freeze([]),
54
+ });
55
+
56
+ export class DeploymentIdentityError extends Error {
57
+ constructor(message) {
58
+ super(message);
59
+ this.name = 'DeploymentIdentityError';
60
+ }
61
+ }
62
+
63
+ export function isDeploymentEnvironment(value) {
64
+ return (
65
+ typeof value === 'string' && DEPLOYMENT_ENVIRONMENT_PATTERN.test(value)
66
+ );
67
+ }
68
+
69
+ export function assertValidDeploymentTag(tag, caller) {
70
+ if (typeof tag !== 'string' || !DEPLOYMENT_TAG_PATTERN.test(tag)) {
71
+ throw new DeploymentIdentityError(
72
+ `${caller}: deployment tag '${String(tag)}' must match ${DEPLOYMENT_TAG_PATTERN} — fix the DEPLOYMENT_TENANT binding or the provisioning input`,
73
+ );
74
+ }
75
+ }
76
+
77
+ export function normalizeDeploymentSentinelSql(sql) {
78
+ return sql.replace(/\s+/g, ' ').trim();
79
+ }
80
+
81
+ export function deploymentIdentityApplicationTables(rows) {
82
+ return rows
83
+ .map((row) => rowField(row, 'name'))
84
+ .filter(
85
+ (name) =>
86
+ typeof name === 'string' &&
87
+ name !== DEPLOYMENT_SENTINEL_TABLE &&
88
+ !name.startsWith('sqlite_') &&
89
+ !D1_OWNED_INTERNAL_TABLES.includes(name),
90
+ )
91
+ .sort();
92
+ }
93
+
94
+ function rowField(row, name) {
95
+ return row !== null && typeof row === 'object' ? row[name] : undefined;
96
+ }
97
+
98
+ function malformedSentinel(reason) {
99
+ return new DeploymentIdentityError(
100
+ `${DEPLOYMENT_SENTINEL_TABLE} has an invalid ownership schema (${reason}) — recreate the database before serving`,
101
+ );
102
+ }
103
+
104
+ function assertSentinelSchemaDefinition(rows) {
105
+ const sql = rowField(rows[0], 'sql');
106
+ if (rows.length !== 1 || typeof sql !== 'string') {
107
+ throw malformedSentinel('table definition is missing or ambiguous');
108
+ }
109
+ if (!SENTINEL_SQL_PATTERN.test(normalizeDeploymentSentinelSql(sql))) {
110
+ throw malformedSentinel('table definition differs from the owned schema');
111
+ }
112
+ }
113
+
114
+ function assertSentinelColumns(rows) {
115
+ if (rows.length !== DEPLOYMENT_SENTINEL_COLUMNS.length) {
116
+ throw malformedSentinel('unexpected columns');
117
+ }
118
+ for (let index = 0; index < DEPLOYMENT_SENTINEL_COLUMNS.length; index += 1) {
119
+ const actual = rows[index];
120
+ const expected = DEPLOYMENT_SENTINEL_COLUMNS[index];
121
+ if (
122
+ rowField(actual, 'name') !== expected.name ||
123
+ String(rowField(actual, 'type')).toUpperCase() !== expected.type ||
124
+ Number(rowField(actual, 'notnull')) !== expected.notnull ||
125
+ Number(rowField(actual, 'pk')) !== expected.pk
126
+ ) {
127
+ throw malformedSentinel(`column ${expected.name} differs`);
128
+ }
129
+ }
130
+ }
131
+
132
+ function conditionalOwnershipInsert(tag, provisionedAt) {
133
+ return {
134
+ mode: 'write',
135
+ sql: `INSERT OR IGNORE INTO ${DEPLOYMENT_SENTINEL_TABLE} (id, tenant_tag, provisioned_at)
136
+ SELECT 1, ?, ?
137
+ WHERE NOT EXISTS (
138
+ SELECT 1 FROM sqlite_schema
139
+ WHERE type = 'table'
140
+ AND name <> '${DEPLOYMENT_SENTINEL_TABLE}'
141
+ ${D1_OWNED_TABLE_EXCLUSIONS}
142
+ AND name NOT GLOB 'sqlite_*'
143
+ )`,
144
+ bindings: [tag, provisionedAt],
145
+ };
146
+ }
147
+
148
+ async function scanTables(execute) {
149
+ return execute(SCAN_TABLES);
150
+ }
151
+
152
+ export async function readDeploymentIdentityProtocol(execute) {
153
+ const schema = await execute(READ_SENTINEL_SCHEMA);
154
+ if (schema.length === 0) return undefined;
155
+ assertSentinelSchemaDefinition(schema);
156
+ assertSentinelColumns(await execute(READ_SENTINEL_COLUMNS));
157
+
158
+ const owners = await execute(READ_SENTINEL_OWNER);
159
+ if (owners.length === 0) return undefined;
160
+ if (owners.length !== 1 || Number(rowField(owners[0], 'id')) !== 1) {
161
+ throw malformedSentinel('the ownership row is not an exact singleton');
162
+ }
163
+ const tag = rowField(owners[0], 'tenant_tag');
164
+ if (typeof tag !== 'string' || !DEPLOYMENT_TAG_PATTERN.test(tag)) {
165
+ throw malformedSentinel('tenant_tag is malformed');
166
+ }
167
+ return tag;
168
+ }
169
+
170
+ function unownedDatabaseError(caller, applicationTables) {
171
+ return new DeploymentIdentityError(
172
+ `${caller}: unowned database already contains application tables (${applicationTables.join(', ')}) — provision a fresh database instead of adopting pooled or unknown state`,
173
+ );
174
+ }
175
+
176
+ function differentOwnerError(caller, stored, tag) {
177
+ return new DeploymentIdentityError(
178
+ `${caller}: database already belongs to deployment '${stored}' — refusing to re-stamp it as '${tag}' (decommission and recreate instead)`,
179
+ );
180
+ }
181
+
182
+ export async function provisionDeploymentIdentityProtocol(
183
+ execute,
184
+ tag,
185
+ { caller = 'seedDeploymentIdentity', provisionedAt } = {},
186
+ ) {
187
+ assertValidDeploymentTag(tag, caller);
188
+ const tables = await scanTables(execute);
189
+ const applicationTables = deploymentIdentityApplicationTables(tables);
190
+ const sentinelExists = tables.some(
191
+ (row) => rowField(row, 'name') === DEPLOYMENT_SENTINEL_TABLE,
192
+ );
193
+ const storedBeforeCreate = await readDeploymentIdentityProtocol(execute);
194
+ if (storedBeforeCreate !== undefined) {
195
+ if (storedBeforeCreate !== tag) {
196
+ throw differentOwnerError(caller, storedBeforeCreate, tag);
197
+ }
198
+ return;
199
+ }
200
+ if (applicationTables.length > 0) {
201
+ throw unownedDatabaseError(caller, applicationTables);
202
+ }
203
+
204
+ if (!sentinelExists) await execute(CREATE_SENTINEL);
205
+ const storedAfterCreate = await readDeploymentIdentityProtocol(execute);
206
+ if (storedAfterCreate !== undefined) {
207
+ if (storedAfterCreate !== tag) {
208
+ throw differentOwnerError(caller, storedAfterCreate, tag);
209
+ }
210
+ return;
211
+ }
212
+
213
+ await execute(
214
+ conditionalOwnershipInsert(tag, provisionedAt ?? new Date().toISOString()),
215
+ );
216
+ const seeded = await readDeploymentIdentityProtocol(execute);
217
+ if (seeded === undefined) {
218
+ const racedApplicationTables = deploymentIdentityApplicationTables(
219
+ await scanTables(execute),
220
+ );
221
+ if (racedApplicationTables.length > 0) {
222
+ throw unownedDatabaseError(caller, racedApplicationTables);
223
+ }
224
+ throw new DeploymentIdentityError(
225
+ `${caller}: database sentinel is missing or malformed after seeding — recreate the database before serving`,
226
+ );
227
+ }
228
+ if (seeded !== tag) {
229
+ throw differentOwnerError(caller, seeded, tag);
230
+ }
231
+ }
@@ -1,4 +1,4 @@
1
- import { type ApprovalRecord, type ExecutionPrincipal, type TenantContext } from '../approval-api/index.js';
1
+ import { type ActorContext, type ApprovalRecord, type ExecutionPrincipal } from '../approval-api/index.js';
2
2
  import type { ResumeRunFn } from '../host-kit/index.js';
3
3
  import type { AgentThreadTopology } from './thread-topology.js';
4
4
  import type { AgentMeta } from './types.js';
@@ -7,11 +7,11 @@ export interface AgentApprovalResumerOptions {
7
7
  agents: readonly AgentMeta[];
8
8
  topology: AgentThreadTopology;
9
9
  /**
10
- * Builds the tenant context the resume runs under, from the STORED principal.
10
+ * Builds the actor context the resume runs under, from the stored principal.
11
11
  * It must return that principal unchanged; createAgentApprovalResumer
12
12
  * enforces that with an exact comparison after calling this.
13
13
  */
14
- tenantForPrincipal: (principal: ExecutionPrincipal, record: ApprovalRecord) => TenantContext | Promise<TenantContext>;
14
+ contextForPrincipal: (principal: ExecutionPrincipal, record: ApprovalRecord) => ActorContext | Promise<ActorContext>;
15
15
  }
16
16
  export type AgentApprovalResumer = ResumeRunFn;
17
17
  export declare function createAgentApprovalResumer(options: AgentApprovalResumerOptions): AgentApprovalResumer;
@@ -1 +1 @@
1
- {"version":3,"file":"approval-resumer.d.ts","sourceRoot":"","sources":["../../src/agent-host/approval-resumer.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,kBAAkB,EAEvB,KAAK,aAAa,EACnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAExD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C,MAAM,WAAW,2BAA2B;IAC1C,QAAQ,EAAE,WAAW,CAAC;IACtB,MAAM,EAAE,SAAS,SAAS,EAAE,CAAC;IAC7B,QAAQ,EAAE,mBAAmB,CAAC;IAC9B;;;;OAIG;IACH,kBAAkB,EAAE,CAClB,SAAS,EAAE,kBAAkB,EAC7B,MAAM,EAAE,cAAc,KACnB,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;CAC7C;AAED,MAAM,MAAM,oBAAoB,GAAG,WAAW,CAAC;AAE/C,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,2BAA2B,GACnC,oBAAoB,CAsEtB"}
1
+ {"version":3,"file":"approval-resumer.d.ts","sourceRoot":"","sources":["../../src/agent-host/approval-resumer.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,kBAAkB,EAExB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAExD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C,MAAM,WAAW,2BAA2B;IAC1C,QAAQ,EAAE,WAAW,CAAC;IACtB,MAAM,EAAE,SAAS,SAAS,EAAE,CAAC;IAC7B,QAAQ,EAAE,mBAAmB,CAAC;IAC9B;;;;OAIG;IACH,mBAAmB,EAAE,CACnB,SAAS,EAAE,kBAAkB,EAC7B,MAAM,EAAE,cAAc,KACnB,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;CAC3C;AAED,MAAM,MAAM,oBAAoB,GAAG,WAAW,CAAC;AAE/C,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,2BAA2B,GACnC,oBAAoB,CAiEtB"}
@@ -32,15 +32,14 @@ export function createAgentApprovalResumer(options) {
32
32
  if (!authorized) {
33
33
  throw new Error(`principal kind '${principal.kind}' may no longer resume agent '${target.agentId}'`);
34
34
  }
35
- if (principal.tenantId !== record.tenantId || principal.id.trim() === '') {
36
- throw new Error('agent approval principal does not match the record tenant');
35
+ if (principal.id.trim() === '') {
36
+ throw new Error('agent approval principal is invalid');
37
37
  }
38
- const tenant = await options.tenantForPrincipal(principal, record);
39
- if (tenant.tenantId !== record.tenantId ||
40
- !samePrincipal(tenant.principal, principal)) {
41
- throw new Error('tenantForPrincipal must preserve the stored agent execution principal exactly');
38
+ const context = await options.contextForPrincipal(principal, record);
39
+ if (!samePrincipal(context.principal, principal)) {
40
+ throw new Error('contextForPrincipal must preserve the stored agent execution principal exactly');
42
41
  }
43
- const envelope = await options.topology.resume(tenant, record, decision);
42
+ const envelope = await options.topology.resume(context, record, decision);
44
43
  if (envelope.agentId !== target.agentId ||
45
44
  envelope.threadId !== target.threadId ||
46
45
  envelope.resourceId !== target.resourceId ||