@proofoftech/flowsafe 0.18.0 → 0.20.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 (196) hide show
  1. package/CHANGELOG.md +114 -0
  2. package/README.md +79 -5
  3. package/deployment-identity-protocol.d.mts +62 -1
  4. package/deployment-identity-protocol.mjs +201 -5
  5. package/dist/agent-host/catalog.js +1 -1
  6. package/dist/agent-host/catalog.js.map +1 -1
  7. package/dist/agent-host/index.d.ts +1 -1
  8. package/dist/agent-host/index.d.ts.map +1 -1
  9. package/dist/agent-host/index.js.map +1 -1
  10. package/dist/agent-host/router.d.ts.map +1 -1
  11. package/dist/agent-host/router.js +6 -2
  12. package/dist/agent-host/router.js.map +1 -1
  13. package/dist/agent-host/thread-host.d.ts +11 -0
  14. package/dist/agent-host/thread-host.d.ts.map +1 -1
  15. package/dist/agent-host/thread-host.js +53 -1
  16. package/dist/agent-host/thread-host.js.map +1 -1
  17. package/dist/agent-host/thread-topology.d.ts +35 -1
  18. package/dist/agent-host/thread-topology.d.ts.map +1 -1
  19. package/dist/agent-host/thread-topology.js +103 -7
  20. package/dist/agent-host/thread-topology.js.map +1 -1
  21. package/dist/agent-runner/durable-agent-runner.d.ts +267 -21
  22. package/dist/agent-runner/durable-agent-runner.d.ts.map +1 -1
  23. package/dist/agent-runner/durable-agent-runner.js +706 -76
  24. package/dist/agent-runner/durable-agent-runner.js.map +1 -1
  25. package/dist/approval-api/d1-store.d.ts.map +1 -1
  26. package/dist/approval-api/d1-store.js +6 -3
  27. package/dist/approval-api/d1-store.js.map +1 -1
  28. package/dist/approval-api/principal-identity.d.ts +32 -0
  29. package/dist/approval-api/principal-identity.d.ts.map +1 -0
  30. package/dist/approval-api/principal-identity.js +69 -0
  31. package/dist/approval-api/principal-identity.js.map +1 -0
  32. package/dist/approval-api/principal.d.ts +9 -12
  33. package/dist/approval-api/principal.d.ts.map +1 -1
  34. package/dist/approval-api/principal.js +9 -45
  35. package/dist/approval-api/principal.js.map +1 -1
  36. package/dist/approval-api/router.d.ts.map +1 -1
  37. package/dist/approval-api/router.js +9 -1
  38. package/dist/approval-api/router.js.map +1 -1
  39. package/dist/approval-api/service.d.ts +19 -0
  40. package/dist/approval-api/service.d.ts.map +1 -1
  41. package/dist/approval-api/service.js +41 -10
  42. package/dist/approval-api/service.js.map +1 -1
  43. package/dist/approval-api/types.d.ts +12 -0
  44. package/dist/approval-api/types.d.ts.map +1 -1
  45. package/dist/approval-api/types.js +12 -0
  46. package/dist/approval-api/types.js.map +1 -1
  47. package/dist/background-tasks/host.d.ts +127 -14
  48. package/dist/background-tasks/host.d.ts.map +1 -1
  49. package/dist/background-tasks/host.js +579 -50
  50. package/dist/background-tasks/host.js.map +1 -1
  51. package/dist/background-tasks/index.d.ts +2 -2
  52. package/dist/background-tasks/index.d.ts.map +1 -1
  53. package/dist/background-tasks/index.js +11 -6
  54. package/dist/background-tasks/index.js.map +1 -1
  55. package/dist/background-tasks/routes.d.ts +19 -2
  56. package/dist/background-tasks/routes.d.ts.map +1 -1
  57. package/dist/background-tasks/routes.js +4 -4
  58. package/dist/background-tasks/routes.js.map +1 -1
  59. package/dist/deployment-identity-protocol.d.ts +2 -2
  60. package/dist/deployment-identity-protocol.d.ts.map +1 -1
  61. package/dist/deployment-identity-protocol.js +1 -1
  62. package/dist/deployment-identity-protocol.js.map +1 -1
  63. package/dist/do-runner/cause-chain.d.ts +53 -0
  64. package/dist/do-runner/cause-chain.d.ts.map +1 -0
  65. package/dist/do-runner/cause-chain.js +96 -0
  66. package/dist/do-runner/cause-chain.js.map +1 -0
  67. package/dist/do-runner/d1-storage.d.ts +109 -5
  68. package/dist/do-runner/d1-storage.d.ts.map +1 -1
  69. package/dist/do-runner/d1-storage.js +289 -44
  70. package/dist/do-runner/d1-storage.js.map +1 -1
  71. package/dist/do-runner/deployment-identity.d.ts +28 -13
  72. package/dist/do-runner/deployment-identity.d.ts.map +1 -1
  73. package/dist/do-runner/deployment-identity.js +25 -35
  74. package/dist/do-runner/deployment-identity.js.map +1 -1
  75. package/dist/do-runner/do-error-response.d.ts +4 -23
  76. package/dist/do-runner/do-error-response.d.ts.map +1 -1
  77. package/dist/do-runner/do-error-response.js +19 -24
  78. package/dist/do-runner/do-error-response.js.map +1 -1
  79. package/dist/do-runner/do-status-error.d.ts +37 -0
  80. package/dist/do-runner/do-status-error.d.ts.map +1 -0
  81. package/dist/do-runner/do-status-error.js +42 -0
  82. package/dist/do-runner/do-status-error.js.map +1 -0
  83. package/dist/do-runner/durable-object.d.ts +2 -1
  84. package/dist/do-runner/durable-object.d.ts.map +1 -1
  85. package/dist/do-runner/durable-object.js +205 -19
  86. package/dist/do-runner/durable-object.js.map +1 -1
  87. package/dist/do-runner/execution-fence.d.ts +335 -0
  88. package/dist/do-runner/execution-fence.d.ts.map +1 -0
  89. package/dist/do-runner/execution-fence.js +534 -0
  90. package/dist/do-runner/execution-fence.js.map +1 -0
  91. package/dist/do-runner/index.d.ts +10 -3
  92. package/dist/do-runner/index.d.ts.map +1 -1
  93. package/dist/do-runner/index.js +16 -3
  94. package/dist/do-runner/index.js.map +1 -1
  95. package/dist/do-runner/init.d.ts +82 -1
  96. package/dist/do-runner/init.d.ts.map +1 -1
  97. package/dist/do-runner/init.js +58 -3
  98. package/dist/do-runner/init.js.map +1 -1
  99. package/dist/do-runner/inventory.d.ts +294 -0
  100. package/dist/do-runner/inventory.d.ts.map +1 -0
  101. package/dist/do-runner/inventory.js +811 -0
  102. package/dist/do-runner/inventory.js.map +1 -0
  103. package/dist/do-runner/notification-predicate.d.ts +8 -0
  104. package/dist/do-runner/notification-predicate.d.ts.map +1 -0
  105. package/dist/do-runner/notification-predicate.js +9 -0
  106. package/dist/do-runner/notification-predicate.js.map +1 -0
  107. package/dist/do-runner/runtime.d.ts +83 -0
  108. package/dist/do-runner/runtime.d.ts.map +1 -1
  109. package/dist/do-runner/runtime.js +131 -4
  110. package/dist/do-runner/runtime.js.map +1 -1
  111. package/dist/do-runner/start-idempotency.d.ts +508 -0
  112. package/dist/do-runner/start-idempotency.d.ts.map +1 -0
  113. package/dist/do-runner/start-idempotency.js +886 -0
  114. package/dist/do-runner/start-idempotency.js.map +1 -0
  115. package/dist/do-runner/suspension-deadline.d.ts +3 -2
  116. package/dist/do-runner/suspension-deadline.d.ts.map +1 -1
  117. package/dist/do-runner/suspension-deadline.js +3 -2
  118. package/dist/do-runner/suspension-deadline.js.map +1 -1
  119. package/dist/goals/objective-routes.d.ts +14 -0
  120. package/dist/goals/objective-routes.d.ts.map +1 -1
  121. package/dist/goals/objective-routes.js +45 -24
  122. package/dist/goals/objective-routes.js.map +1 -1
  123. package/dist/host-kit/do-run-topology.d.ts +15 -0
  124. package/dist/host-kit/do-run-topology.d.ts.map +1 -1
  125. package/dist/host-kit/do-run-topology.js +22 -1
  126. package/dist/host-kit/do-run-topology.js.map +1 -1
  127. package/dist/host-kit/flowsafe-worker.d.ts +11 -0
  128. package/dist/host-kit/flowsafe-worker.d.ts.map +1 -1
  129. package/dist/host-kit/flowsafe-worker.js +343 -62
  130. package/dist/host-kit/flowsafe-worker.js.map +1 -1
  131. package/dist/host-kit/host-approval-service.d.ts +20 -0
  132. package/dist/host-kit/host-approval-service.d.ts.map +1 -1
  133. package/dist/host-kit/host-approval-service.js +6 -0
  134. package/dist/host-kit/host-approval-service.js.map +1 -1
  135. package/dist/host-kit/index.d.ts +2 -2
  136. package/dist/host-kit/index.d.ts.map +1 -1
  137. package/dist/host-kit/index.js +1 -1
  138. package/dist/host-kit/index.js.map +1 -1
  139. package/dist/host-kit/run-route-error.d.ts +18 -0
  140. package/dist/host-kit/run-route-error.d.ts.map +1 -1
  141. package/dist/host-kit/run-route-error.js +23 -0
  142. package/dist/host-kit/run-route-error.js.map +1 -1
  143. package/dist/host-kit/run-router.d.ts +58 -1
  144. package/dist/host-kit/run-router.d.ts.map +1 -1
  145. package/dist/host-kit/run-router.js +120 -11
  146. package/dist/host-kit/run-router.js.map +1 -1
  147. package/dist/host-kit/stream-router.d.ts.map +1 -1
  148. package/dist/host-kit/stream-router.js +18 -9
  149. package/dist/host-kit/stream-router.js.map +1 -1
  150. package/dist/schedules/router.d.ts +15 -0
  151. package/dist/schedules/router.d.ts.map +1 -1
  152. package/dist/schedules/router.js +47 -17
  153. package/dist/schedules/router.js.map +1 -1
  154. package/dist/schedules/tick.d.ts +13 -0
  155. package/dist/schedules/tick.d.ts.map +1 -1
  156. package/dist/schedules/tick.js +59 -39
  157. package/dist/schedules/tick.js.map +1 -1
  158. package/dist/signal-providers/delivery.d.ts +32 -0
  159. package/dist/signal-providers/delivery.d.ts.map +1 -1
  160. package/dist/signal-providers/delivery.js +45 -0
  161. package/dist/signal-providers/delivery.js.map +1 -1
  162. package/dist/signal-providers/host-do.d.ts +23 -1
  163. package/dist/signal-providers/host-do.d.ts.map +1 -1
  164. package/dist/signal-providers/host-do.js +76 -17
  165. package/dist/signal-providers/host-do.js.map +1 -1
  166. package/dist/signal-providers/provider.d.ts +8 -0
  167. package/dist/signal-providers/provider.d.ts.map +1 -1
  168. package/dist/signal-providers/provider.js.map +1 -1
  169. package/dist/signal-providers/webhook-route.d.ts +20 -0
  170. package/dist/signal-providers/webhook-route.d.ts.map +1 -1
  171. package/dist/signal-providers/webhook-route.js +137 -26
  172. package/dist/signal-providers/webhook-route.js.map +1 -1
  173. package/dist/signals/client.d.ts +19 -5
  174. package/dist/signals/client.d.ts.map +1 -1
  175. package/dist/signals/client.js +25 -17
  176. package/dist/signals/client.js.map +1 -1
  177. package/dist/signals/index.d.ts +1 -1
  178. package/dist/signals/index.d.ts.map +1 -1
  179. package/dist/signals/index.js.map +1 -1
  180. package/dist/signals/notification-dispatch.d.ts +15 -0
  181. package/dist/signals/notification-dispatch.d.ts.map +1 -1
  182. package/dist/signals/notification-dispatch.js +23 -1
  183. package/dist/signals/notification-dispatch.js.map +1 -1
  184. package/dist/signals/notifications-d1.d.ts +8 -0
  185. package/dist/signals/notifications-d1.d.ts.map +1 -1
  186. package/dist/signals/notifications-d1.js +15 -9
  187. package/dist/signals/notifications-d1.js.map +1 -1
  188. package/dist/signals/router.d.ts.map +1 -1
  189. package/dist/signals/router.js +3 -2
  190. package/dist/signals/router.js.map +1 -1
  191. package/dist/signals/thread-do-routes.d.ts +48 -10
  192. package/dist/signals/thread-do-routes.d.ts.map +1 -1
  193. package/dist/signals/thread-do-routes.js +710 -136
  194. package/dist/signals/thread-do-routes.js.map +1 -1
  195. package/package.json +8 -6
  196. package/scripts/seed-deployment-identity.mjs +22 -4
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/do-runner/index.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,qEAAqE;AACrE,6EAA6E;AAC7E,qEAAqE;AACrE,yEAAyE;AA0BzE,OAAO,EACL,gCAAgC,EAChC,eAAe,EACf,SAAS,EACT,6BAA6B,EAC7B,2BAA2B,EAC3B,yBAAyB,EACzB,4BAA4B,EAC5B,uBAAuB,EACvB,mBAAmB,EACnB,wBAAwB,EACxB,oBAAoB,EACpB,iCAAiC,EACjC,wBAAwB,EACxB,6BAA6B,EAC7B,uBAAuB,GACxB,MAAM,iBAAiB,CAAC;AAQzB,OAAO,EACL,wBAAwB,EACxB,8BAA8B,EAC9B,0BAA0B,EAC1B,sBAAsB,EACtB,uBAAuB,EACvB,yBAAyB,EACzB,wBAAwB,EACxB,gCAAgC,EAChC,sBAAsB,EACtB,sBAAsB,EACtB,8BAA8B,EAC9B,qCAAqC,EACrC,oCAAoC,GACrC,MAAM,0BAA0B,CAAC;AAClC,gFAAgF;AAChF,gEAAgE;AAChE,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACxE,OAAO,EAEL,mBAAmB,GAGpB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,gCAAgC,EAChC,+BAA+B,EAC/B,6BAA6B,EAC7B,+BAA+B,EAC/B,6BAA6B,EAC7B,6BAA6B,GAC9B,MAAM,wBAAwB,C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Y,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAEvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAoB/C,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,wBAAwB,EACxB,oBAAoB,EACpB,aAAa,EACb,uBAAuB,EACvB,wBAAwB,EACxB,eAAe,EACf,oBAAoB,GACrB,MAAM,cAAc,CAAC;AAWtB,OAAO,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AA6BjE,OAAO,EACL,oBAAoB,EACpB,kCAAkC,EAClC,2BAA2B,EAC3B,gCAAgC,EAChC,mCAAmC,EACnC,yBAAyB,EACzB,uBAAuB,EACvB,mBAAmB,EACnB,qBAAqB,EACrB,+BAA+B,EAC/B,iCAAiC,EACjC,uBAAuB,EACvB,wBAAwB,EACxB,kBAAkB,EAClB,qBAAqB,EACrB,gCAAgC,EAChC,kCAAkC,EAClC,mCAAmC,EACnC,+BAA+B;AAC/B,wEAAwE;AACxE,8EAA8E;AAC9E,0BAA0B;AAC1B,mBAAmB,GACpB,MAAM,wBAAwB,CAAC;AAehC,OAAO,EACL,6BAA6B,EAC7B,0BAA0B,EAC1B,gCAAgC,EAChC,0BAA0B,EAC1B,+BAA+B,EAC/B,gCAAgC,EAChC,6BAA6B,GAC9B,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC"}
@@ -1,9 +1,12 @@
1
1
  import type { MastraCompositeStore } from '@mastra/core/storage';
2
2
  import { createWorkflow as coreCreateWorkflow, createStep } from '@mastra/core/workflows';
3
3
  import type { D1DatabaseBinding } from './cf-types.js';
4
+ import type { ExecutionFenceWiring } from './execution-fence.js';
5
+ import { ExecutionFenceStore } from './execution-fence.js';
4
6
  import type { HostPubSub } from './pubsub.js';
5
7
  import type { RequestContextProvider } from './runtime.js';
6
8
  import { RunnerRuntime } from './runtime.js';
9
+ import type { StartIdempotencyStore, StartIdempotencyWiring } from './start-idempotency.js';
7
10
  /** Workers env shape init() understands directly. */
8
11
  export interface DORunnerEnv {
9
12
  DB: D1DatabaseBinding;
@@ -35,7 +38,59 @@ export interface InitOptions {
35
38
  * stays the fallback).
36
39
  */
37
40
  pubsub?: HostPubSub;
41
+ /**
42
+ * The deployment execution fence (do-runner/execution-fence.ts).
43
+ *
44
+ * OPTIONAL only for a `{ DB }` source, where init builds one from that same
45
+ * binding — the fence must live in the database it fences, and init is the
46
+ * one place that holds both. Passing a store here overrides the auto-build
47
+ * (a host sharing one instance across its Durable Objects). There is
48
+ * deliberately NO `'none'` on this branch: a host that hands init a database
49
+ * cannot end up with a fence-less runtime, whatever it forgets or opts out
50
+ * of, which is the fail-closed-by-construction half of the contract.
51
+ *
52
+ * REQUIRED, and widened to include the opt-out, for a `{ storage }` source —
53
+ * see ExecutionFenceWiring, which spells out why every fence option that CAN
54
+ * be required is.
55
+ */
56
+ executionFence?: ExecutionFenceStore;
57
+ /**
58
+ * The deployment's start reservations, for a `{ storage }` source only.
59
+ *
60
+ * A `{ DB }` source ignores this and always gets the store built from its own
61
+ * binding — the reservation table must live in the database the runs live in,
62
+ * and init is the one place that holds both.
63
+ *
64
+ * OPTIONAL on THIS branch only, where it is ignored. `StorageInitOptions`
65
+ * requires it, and widens it to include the opt-out — see there for why a
66
+ * `{ storage }` host must write the answer down.
67
+ */
68
+ startIdempotency?: StartIdempotencyWiring;
38
69
  }
70
+ /**
71
+ * InitOptions for a `{ storage }` source: the fence wiring AND the reservation
72
+ * wiring are mandatory, and both are widened to admit the opt-out. Written as
73
+ * an intersection rather than an `extends`, because a subtype may not WIDEN an
74
+ * inherited property's type — and the widening is the point: `'none'` exists
75
+ * only on this branch.
76
+ *
77
+ * `startIdempotency` is required HERE and optional on `InitOptions` because the
78
+ * two branches fail differently. A `{ DB }` host cannot get this wrong: init
79
+ * builds the store from the binding, and `DurableObjectRunner.build` refuses to
80
+ * serve a runtime that lacks one while a DB binding is present. A `{ storage }`
81
+ * host has no binding to derive one from, and its failure is SILENT and split:
82
+ * such a host can still wire a real store into its run router (the router takes
83
+ * its own), so keys reserve and claim normally — and then nothing ever settles
84
+ * them, because the runtime that sees every terminal transition was never given
85
+ * the store. The reservation stays `started` forever, and the next retry of
86
+ * that key is told UNRESOLVABLE instead of replaying a run that completed
87
+ * perfectly well. Making the host WRITE `'none'` turns that into a decision
88
+ * someone made; nothing about an omission could have said it.
89
+ */
90
+ export type StorageInitOptions = Omit<InitOptions, 'executionFence' | 'startIdempotency'> & {
91
+ executionFence: ExecutionFenceWiring;
92
+ startIdempotency: StartIdempotencyWiring;
93
+ };
39
94
  export interface InitResult {
40
95
  createWorkflow: typeof coreCreateWorkflow;
41
96
  createStep: typeof createStep;
@@ -46,6 +101,32 @@ export interface InitResult {
46
101
  * which is what keeps it single per DO.
47
102
  */
48
103
  pubsub?: HostPubSub;
104
+ /**
105
+ * The deployment execution fence, or undefined for an explicitly unfenced
106
+ * host. THE accessor for it, for the same reason as `pubsub`: a route that
107
+ * built its own store could be gating a different database than the runtime
108
+ * it sits in front of. Thread-DO signal routes read it off `scope.init`.
109
+ */
110
+ executionFence?: ExecutionFenceStore;
111
+ /**
112
+ * The deployment's start reservations, or undefined for a `{ storage }` host
113
+ * with no database to reserve against. THE accessor for it, for the same
114
+ * reason as `executionFence`: a surface that built its own store could be
115
+ * reserving into a different database than the runtime that settles.
116
+ */
117
+ startIdempotency?: StartIdempotencyStore;
49
118
  }
50
- export declare function init(source: InitSource, options?: InitOptions): InitResult;
119
+ export declare function init(source: DORunnerEnv, options?: InitOptions): InitResult;
120
+ export declare function init(source: {
121
+ storage: MastraCompositeStore;
122
+ }, options: StorageInitOptions): InitResult;
123
+ /**
124
+ * A source whose shape is only known at runtime (a host that accepts either).
125
+ * The wiring is REQUIRED here for the same reason it is on the `{ storage }`
126
+ * branch: the compiler cannot tell which branch this call will take, so it
127
+ * cannot know whether init would have built a fence. `'none'` still applies
128
+ * only to a `{ storage }` source — a `{ DB }` one is fenced regardless, so
129
+ * choosing the opt-out cannot leave a database-backed runtime unfenced.
130
+ */
131
+ export declare function init(source: InitSource, options: StorageInitOptions): InitResult;
51
132
  //# sourceMappingURL=init.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/do-runner/init.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAEjE,OAAO,EACL,cAAc,IAAI,kBAAkB,EACpC,UAAU,EACX,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEvD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,qDAAqD;AACrD,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,iBAAiB,CAAC;CACvB;AAED,iFAAiF;AACjF,MAAM,MAAM,UAAU,GAAG;IAAE,OAAO,EAAE,oBAAoB,CAAA;CAAE,GAAG,WAAW,CAAC;AAEzE,MAAM,WAAW,WAAW;IAC1B,8EAA8E;IAC9E,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,uDAAuD;IACvD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,oBAAoB,CAAC,EAAE,sBAAsB,CAAC;IAC9C;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,EAAE,UAAU,CAAC;CACrB;AAED,MAAM,WAAW,UAAU;IACzB,cAAc,EAAE,OAAO,kBAAkB,CAAC;IAC1C,UAAU,EAAE,OAAO,UAAU,CAAC;IAC9B,OAAO,EAAE,aAAa,CAAC;IACvB;;;;OAIG;IACH,MAAM,CAAC,EAAE,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UG;IACH,gBAAgB,CAAC,EAAE,sBAAsB,CAAC;CAC3C;AA8BD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,MAAM,kBAAkB,GAAG,IAAI,CACnC,WAAW,EACX,gBAAgB,GAAG,kBAAkB,CACtC,GAAG;IACF,cAAc,EAAE,oBAAoB,CAAC;IACrC,gBAAgB,EAAE,sBAAsB,CAAC;CAC1C,CAAC;AAEF,MAAM,WAAW,UAAU;IACzB,cAAc,EAAE,OAAO,kBAAkB,CAAC;IAC1C,UAAU,EAAE,OAAO,UAAU,CAAC;IAC9B,OAAO,EAAE,aAAa,CAAC;IACvB;;;;OAIG;IACH,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB;;;;;OAKG;IACH,cAAc,CAAC,EAAE,mBAAmB,CAAC;IACrC;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,qBAAqB,CAAC;CAC1C;AAED,wBAAgB,IAAI,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,UAAU,CAAC;AAC7E,wBAAgB,IAAI,CAClB,MAAM,EAAE;IAAE,OAAO,EAAE,oBAAoB,CAAA;CAAE,EACzC,OAAO,EAAE,kBAAkB,GAC1B,UAAU,CAAC;AACd;;;;;;;GAOG;AACH,wBAAgB,IAAI,CAClB,MAAM,EAAE,UAAU,EAClB,OAAO,EAAE,kBAAkB,GAC1B,UAAU,CAAC"}
@@ -11,9 +11,36 @@
11
11
  // handlers/DO constructors, never at module scope.
12
12
  import { createWorkflow as coreCreateWorkflow, createStep, } from '@mastra/core/workflows';
13
13
  import { createD1Storage } from './d1-storage.js';
14
+ import { ExecutionFenceStore } from './execution-fence.js';
14
15
  import { RunnerRuntime } from './runtime.js';
16
+ import { startIdempotencyFor } from './start-idempotency.js';
17
+ /**
18
+ * The reservation store this runtime settles against.
19
+ *
20
+ * A `{ DB }` source gets one built from its own binding, with no option and no
21
+ * opt-out — the reservation table must live in the database the runs live in,
22
+ * and init is the one place that holds both, so there is no third answer for a
23
+ * host to get wrong. A `{ storage }` source has no binding to derive one from,
24
+ * so it gets whatever it was handed and `undefined` otherwise.
25
+ *
26
+ * `startIdempotencyFor` is the per-binding memo, so the store the runtime
27
+ * settles against and the store the run router reserved into are the same
28
+ * object whenever both were built from the same `env.DB`.
29
+ */
30
+ function startIdempotencyForSource(source, configured) {
31
+ if ('storage' in source) {
32
+ return configured === undefined || configured === 'none'
33
+ ? undefined
34
+ : configured;
35
+ }
36
+ // The same boundary widening createD1Storage makes on this identical value:
37
+ // D1DatabaseBinding types `prepare` as returning `unknown` so the shared env
38
+ // shape needs no statement type.
39
+ return startIdempotencyFor(source.DB);
40
+ }
15
41
  export function init(source, options = {}) {
16
42
  let storage;
43
+ let executionFence;
17
44
  if ('storage' in source) {
18
45
  if (options.id !== undefined || options.tablePrefix !== undefined) {
19
46
  // Silently ignoring these would mask a misconfiguration: they only
@@ -21,6 +48,8 @@ export function init(source, options = {}) {
21
48
  throw new Error("init: 'id'/'tablePrefix' apply only when init builds the D1 store from env.DB — configure the passed storage instance directly");
22
49
  }
23
50
  storage = source.storage;
51
+ executionFence =
52
+ options.executionFence === 'none' ? undefined : options.executionFence;
24
53
  }
25
54
  else {
26
55
  storage = createD1Storage({
@@ -28,16 +57,40 @@ export function init(source, options = {}) {
28
57
  id: options.id,
29
58
  tablePrefix: options.tablePrefix,
30
59
  });
60
+ // Fail-closed by construction: a host that hands init a database gets a
61
+ // fenced runtime whether or not it remembered to ask for one, and the
62
+ // option's type on this branch admits no opt-out. The cast is the same
63
+ // boundary widening createD1Storage makes on the identical value
64
+ // (d1-storage.ts) — D1DatabaseBinding deliberately types `prepare` as
65
+ // returning `unknown` so the shared env shape needs no statement type.
66
+ // The overload for this source types `executionFence` as a store, so the
67
+ // opt-out cannot be written here; the narrowing is what makes that visible
68
+ // to the implementation signature, which sees both branches' options.
69
+ const configured = options.executionFence;
70
+ executionFence =
71
+ configured === undefined || configured === 'none'
72
+ ? new ExecutionFenceStore(source.DB)
73
+ : configured;
31
74
  }
75
+ const startIdempotency = startIdempotencyForSource(source, options.startIdempotency);
32
76
  const runtime = new RunnerRuntime({
33
77
  storage,
34
78
  requestContextForRun: options.requestContextForRun,
35
79
  // Threaded directly because every DO subclass
36
80
  // returns THIS runtime from build(), so a host that configures a pubsub
37
- // reaches the runtime's createRun sites with no host change (Track A wires
38
- // those). Handing it only to InitResult would strand it — build() returns a
39
- // RunnerRuntime, not an InitResult, so the run-DO path would drop it.
81
+ // reaches the runtime's createRun sites with no host change (the durable
82
+ // agent wires those). Handing it only to InitResult would strand it:
83
+ // build() returns a RunnerRuntime, not an InitResult, so the run-DO path
84
+ // would drop it.
40
85
  pubsub: options.pubsub,
86
+ // Same reasoning, and the reason the fence is a construction-time argument
87
+ // rather than a per-call one: the runtime IS the closure guarantee, so it
88
+ // must not be possible to reach start()/resume() with the fence left off.
89
+ executionFence,
90
+ // Same construction-time reasoning: the runtime is the one layer that sees
91
+ // every terminal transition, so it must not be possible to build one that
92
+ // executes runs but cannot mark their reservations spent.
93
+ startIdempotency,
41
94
  });
42
95
  // Cast preserves core's generic call-site inference (6 type params); the
43
96
  // wrapper body is inference-erased but only registers and returns.
@@ -51,6 +104,8 @@ export function init(source, options = {}) {
51
104
  createStep,
52
105
  runtime,
53
106
  pubsub: options.pubsub,
107
+ executionFence,
108
+ startIdempotency,
54
109
  };
55
110
  }
56
111
  //# sourceMappingURL=init.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/do-runner/init.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,6EAA6E;AAC7E,8EAA8E;AAC9E,4EAA4E;AAC5E,+EAA+E;AAC/E,+DAA+D;AAC/D,EAAE;AACF,2EAA2E;AAC3E,2EAA2E;AAC3E,8EAA8E;AAC9E,mDAAmD;AAInD,OAAO,EACL,cAAc,IAAI,kBAAkB,EACpC,UAAU,GACX,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EAAE,eAAe,EA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CAAC,QAAuB,CAAC,CAAC;QAC1C,OAAO,QAAQ,CAAC;IAClB,CAAC,CAA8B,CAAC;IAEhC,OAAO;QACL,cAAc,EAAE,mBAAmB;QACnC,UAAU;QACV,OAAO;QACP,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,cAAc;QACd,gBAAgB;KACjB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,294 @@
1
+ import { DoStatusError } from './do-status-error.js';
2
+ import { type ExecutionFenceState } from './execution-fence.js';
3
+ /**
4
+ * Whether a category must reach empty before a deployment may be locked.
5
+ *
6
+ * `work` is outstanding obligation: something is expected to happen and has not
7
+ * happened yet. `standing` is configuration that survives the migration and is
8
+ * reported so an operator can reconcile it on the far side, never so they can
9
+ * wait for it to disappear.
10
+ */
11
+ export type InventoryCategoryClass = 'work' | 'standing';
12
+ /**
13
+ * Every category name, in the order the index reports them: work first, then
14
+ * standing.
15
+ */
16
+ export declare const INVENTORY_CATEGORIES: readonly ["runs", "approvals-waiting", "schedule-deferred-dispatches", "pending-notifications", "background-tasks", "resource-owners", "start-reservations", "schedules", "signal-subscriptions"];
17
+ /** One inventory category's name. */
18
+ export type InventoryCategory = (typeof INVENTORY_CATEGORIES)[number];
19
+ /** What the index says about one category, before anything is counted. */
20
+ export interface InventoryCategoryDescriptor {
21
+ /** The category to pass as `?category=`. */
22
+ readonly category: InventoryCategory;
23
+ /** Whether a drain must see this category empty. */
24
+ readonly class: InventoryCategoryClass;
25
+ /** The table its rows live in, un-prefixed. */
26
+ readonly table: string;
27
+ /** What a row in this category means, in one sentence. */
28
+ readonly holds: string;
29
+ }
30
+ /** One row, projected to what an operator needs to act on it. */
31
+ export interface InventoryEntry {
32
+ /**
33
+ * The row's primary-key components, in the order the keyset scan visits
34
+ * them. Passing the LAST entry's key back as `cursor` resumes after it.
35
+ */
36
+ readonly key: readonly string[];
37
+ /** Category-specific columns; absent values are omitted rather than nulled. */
38
+ readonly detail: Readonly<Record<string, string | number | boolean>>;
39
+ }
40
+ /** One page of one category. */
41
+ export interface InventoryPage {
42
+ readonly category: InventoryCategory;
43
+ readonly class: InventoryCategoryClass;
44
+ /** The table read, with the deployment's storage prefix applied. */
45
+ readonly table: string;
46
+ readonly entries: readonly InventoryEntry[];
47
+ /**
48
+ * Pass back as `?cursor=` to continue. Absent means this page reached the
49
+ * end of the category as of this read — which, for a `work` category, is the
50
+ * observation a drain proof is built from.
51
+ */
52
+ readonly cursor?: string;
53
+ /**
54
+ * Total rows matching this category, counted on the FIRST page of a sweep
55
+ * only (a caller that is paging has already committed to walking them).
56
+ * Absent on continuation pages, and absent when the table does not exist.
57
+ */
58
+ readonly count?: number;
59
+ /**
60
+ * Category-specific totals taken with `count`, in the same read: the numbers
61
+ * that answer an operator's next question without a second sweep. See
62
+ * `background-tasks` (`fenceSuspended`) and `pending-notifications`
63
+ * (`notDue`).
64
+ */
65
+ readonly totals?: Readonly<Record<string, number>>;
66
+ }
67
+ /**
68
+ * State that holds work but cannot be counted, declared rather than omitted.
69
+ *
70
+ * An inventory that silently skipped these would be reporting a smaller number
71
+ * than the truth under the same name as a complete one, which is the single
72
+ * most dangerous thing this surface could do. Each entry states what it holds
73
+ * and the BOUND on how long it can stay invisible, so the drain procedure can
74
+ * be built to outlast it.
75
+ */
76
+ export interface UnenumerableState {
77
+ /** Stable identifier for the invisible state. */
78
+ readonly name: string;
79
+ /** What it can hold. */
80
+ readonly holds: string;
81
+ /** Why no pure query can see it. */
82
+ readonly because: string;
83
+ /** How long it can stay invisible, and what makes it visible again. */
84
+ readonly bound: string;
85
+ }
86
+ /** The rule an operator reads an empty inventory under. */
87
+ export interface DrainProofContract {
88
+ /**
89
+ * How to interpret point-in-time readings while draining still admits work.
90
+ * Rows can enter or leave, but an empty result cannot over-count work.
91
+ */
92
+ readonly reading: string;
93
+ /** What a proof actually is. */
94
+ readonly proof: string;
95
+ /** The fence states an empty `work` set is reachable from. */
96
+ readonly reachableFrom: readonly ExecutionFenceState[];
97
+ /** How to interpret a post-lock re-sweep and a read taken under the lock. */
98
+ readonly note: string;
99
+ }
100
+ /** The no-category response: what can be asked for, and how to read the answer. */
101
+ export interface InventoryIndex {
102
+ readonly categories: readonly InventoryCategoryDescriptor[];
103
+ readonly unenumerable: readonly UnenumerableState[];
104
+ readonly drainProof: DrainProofContract;
105
+ }
106
+ /**
107
+ * The database surface an inventory read needs — and NOTHING ELSE.
108
+ *
109
+ * There is no `run()` on this seam, deliberately. Every other store in this
110
+ * package takes a shape that can write, because it writes; this one cannot
111
+ * express a write at all, so "the inventory performs no writes" is a fact about
112
+ * the type rather than a promise about the code. `env.DB` satisfies it
113
+ * structurally, as does a node:sqlite test double.
114
+ */
115
+ export interface InventoryDatabase {
116
+ prepare(query: string): InventoryStatement;
117
+ }
118
+ /** One prepared read. */
119
+ export interface InventoryStatement {
120
+ bind(...values: unknown[]): InventoryStatement;
121
+ all<T = unknown>(): Promise<{
122
+ results: T[];
123
+ }>;
124
+ }
125
+ /** How one flowsafe-owned table is accounted for by the inventory. */
126
+ export type InventoryTableAccounting = {
127
+ /** Rows of this table are reported under this category. */
128
+ readonly category: InventoryCategory;
129
+ } | {
130
+ /**
131
+ * This table holds no drainable work, and here is why. The census
132
+ * requires more than twenty characters: "not work" and "nobody looked"
133
+ * are indistinguishable at that length, and only one of them is a
134
+ * decision.
135
+ */
136
+ readonly excluded: string;
137
+ };
138
+ /** One flowsafe-owned table and its accounting. */
139
+ export interface FlowsafeTableEntry {
140
+ /** The un-prefixed table name. */
141
+ readonly table: string;
142
+ /** What the table is for. */
143
+ readonly purpose: string;
144
+ /** Its inventory category, or the reason it has none. */
145
+ readonly accounting: InventoryTableAccounting;
146
+ }
147
+ /**
148
+ * THE FLOWSAFE TABLE CENSUS. Every `flowsafe_`-prefixed table this package
149
+ * creates, mapped to an inventory category or to a justified exclusion.
150
+ *
151
+ * It exists because the schema guard's `mastra_%` sweep cannot see these: they
152
+ * are not created by `createD1Storage`, and two of them (the deployment
153
+ * sentinel and the fence) are created by the provisioning protocol before any
154
+ * runtime code runs. Without an explicit list, a flowsafe table holding
155
+ * suspended work could be added, purged, documented, and shipped without ever
156
+ * meeting the question this module exists to answer.
157
+ *
158
+ * ADDING A TABLE: add it here in the same change. The census test fails until
159
+ * you do, and it fails again if you claim an exclusion in fewer than twenty
160
+ * characters.
161
+ */
162
+ export declare const FLOWSAFE_TABLES: readonly FlowsafeTableEntry[];
163
+ /** The largest page an inventory read will return, whatever `limit` asks for. */
164
+ export declare const INVENTORY_MAX_LIMIT = 200;
165
+ /** The page size used when `limit` is absent. */
166
+ export declare const INVENTORY_DEFAULT_LIMIT = 100;
167
+ /**
168
+ * Bound parameters D1 accepts in ONE statement. The retention purge caps its
169
+ * own batch against the same limit (d1-storage.ts).
170
+ */
171
+ export declare const D1_MAX_BOUND_PARAMETERS = 100;
172
+ /**
173
+ * Bound parameters the run-owner lookup spends on anything OTHER than run ids.
174
+ *
175
+ * Zero today: `resource_kind = 'run'` is a SQL literal, not a bind. It is named
176
+ * rather than assumed because the slice size below is `cap - this`, and a
177
+ * future predicate that binds a value would otherwise push the statement one
178
+ * parameter over the limit with nothing to catch it.
179
+ */
180
+ export declare const RUN_OWNER_FIXED_BINDINGS = 0;
181
+ /**
182
+ * Run ids per owner-lookup statement: the full parameter budget, less whatever
183
+ * the statement spends on its own predicate. 100 - 0 = 100, so a maximum page
184
+ * (INVENTORY_MAX_LIMIT = 200) costs exactly two statements.
185
+ */
186
+ export declare const RUN_OWNER_LOOKUP_CHUNK: number;
187
+ /**
188
+ * A malformed inventory request: an unknown category, an unparseable cursor, or
189
+ * a cursor whose shape does not match the category it was sent to.
190
+ *
191
+ * 400 rather than a silent restart from the beginning. A cursor that quietly
192
+ * resets would make a sweep re-read rows it had already counted and never
193
+ * reach the end, and an operator watching for two consecutive empty sweeps
194
+ * would wait forever without being told why.
195
+ */
196
+ export declare class InvalidInventoryRequestError extends DoStatusError {
197
+ readonly status = 400;
198
+ readonly reason: {
199
+ readonly code: 'INVALID_INVENTORY_REQUEST';
200
+ };
201
+ constructor(message: string);
202
+ }
203
+ /** Is this a category the inventory serves? */
204
+ export declare function isInventoryCategory(value: unknown): value is InventoryCategory;
205
+ /**
206
+ * The state a pure D1 query cannot see, declared rather than omitted.
207
+ *
208
+ * THE SWEEP BEHIND THIS LIST. Every key a Durable Object in this package writes
209
+ * was checked against the categories above, and all but one is backed by a row
210
+ * a query here already returns:
211
+ *
212
+ * `flowsafe:run-owner-recovery:v1` — DECLARED below. It is written BEFORE the
213
+ * D1 owner row, so a crash between the two leaves a run with no D1 record at
214
+ * all.
215
+ *
216
+ * `flowsafe:agent-thread-binding:v1` / `flowsafe:agent-run:v1:*` — a thread's
217
+ * binding to its agent run and that run's own state. Both name a run whose
218
+ * ownership is RESERVED in D1 BEFORE execution begins
219
+ * (agent-host/thread-host.ts, durable-object.ts) and settled only AFTER a
220
+ * summary has persisted. The engine also writes a `running` snapshot as the
221
+ * run starts, so an executing run is normally reported under `runs` on its own
222
+ * — but that snapshot lands INSIDE `runtime.start`, after the reservation, and
223
+ * the unsettled reservation is what covers the gap between the two as well as
224
+ * any later moment the snapshot is behind the run. `resource-owners` is a WORK
225
+ * category for exactly that reason: an unsettled reservation means a start
226
+ * that has not durably settled, whatever the snapshot currently says.
227
+ * (Pinned behaviourally by inventory.test.ts's ownership-ordering test, which
228
+ * fails if settlement ever moves ahead of the persisted summary.)
229
+ *
230
+ * `flowsafe:suspension-deadline:v1` — an armed wake for a run that is
231
+ * suspended, and therefore nonterminal, and therefore under `runs`.
232
+ *
233
+ * `flowsafe:maintenance-health:v1`, `flowsafe:maintenance-nonces:v1`,
234
+ * `flowsafe:maintenance-deadline-cursor:v1` — the maintenance object's own
235
+ * health, replay protection, and scan position. None is a unit of work: they
236
+ * describe the sweeper, not what it sweeps.
237
+ */
238
+ export declare const INVENTORY_UNENUMERABLE: readonly UnenumerableState[];
239
+ /**
240
+ * The rule that turns inventory readings into a decision.
241
+ *
242
+ * Stated in the index response, and repeated in the route doc, because every
243
+ * dangerous use of this surface is a use that skips it: one empty sweep is not
244
+ * a proof, and an empty sweep taken under `migration-locked` is not even a
245
+ * measurement of a drain.
246
+ */
247
+ export declare const INVENTORY_DRAIN_PROOF: DrainProofContract;
248
+ /** Every category's descriptor, in index order. */
249
+ export declare const INVENTORY_CATEGORY_DESCRIPTORS: readonly InventoryCategoryDescriptor[];
250
+ /** The whole no-category answer, assembled once. */
251
+ export declare const INVENTORY_INDEX: InventoryIndex;
252
+ /** Construction-time options for a deployment inventory. */
253
+ export interface DeploymentInventoryOptions {
254
+ /**
255
+ * The same storage table prefix `createD1Storage` and the retention purges
256
+ * take. It applies to the Mastra-owned tables only, exactly as it does
257
+ * there — the flowsafe-owned registries are never prefixed.
258
+ */
259
+ tablePrefix?: string;
260
+ /** Injectable clock, for the due-notification predicate. */
261
+ now?: () => number;
262
+ }
263
+ /** Per-read options: where to resume, and how many rows to take. */
264
+ export interface InventoryReadOptions {
265
+ /** The `key` of the last entry of the previous page, as JSON text. */
266
+ cursor?: string;
267
+ /** Rows to return, clamped to INVENTORY_MAX_LIMIT. */
268
+ limit?: number;
269
+ }
270
+ /**
271
+ * The deployment's read-only work inventory over one D1 database — the same
272
+ * database its runs, approvals, and fence live in, so what it reports and what
273
+ * the fence governs cannot be two different deployments.
274
+ */
275
+ export declare class DeploymentInventory {
276
+ #private;
277
+ constructor(db: InventoryDatabase, options?: DeploymentInventoryOptions);
278
+ /**
279
+ * What this deployment can be asked about, what it cannot answer, and the
280
+ * rule for reading an empty answer.
281
+ *
282
+ * A constant, and deliberately not a query: the index is the CONTRACT, and a
283
+ * contract that changed with the data would let an operator conclude that a
284
+ * category they cannot see does not apply to them.
285
+ */
286
+ index(): InventoryIndex;
287
+ /** One page of one category. */
288
+ read(category: InventoryCategory, options?: InventoryReadOptions): Promise<InventoryPage>;
289
+ /** Every category's first page, for a caller sweeping the whole deployment. */
290
+ sweep(options?: {
291
+ limit?: number;
292
+ }): Promise<readonly InventoryPage[]>;
293
+ }
294
+ //# sourceMappingURL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