@proofoftech/flowsafe 0.19.0 → 0.21.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 (297) hide show
  1. package/CHANGELOG.md +106 -0
  2. package/README.md +68 -6
  3. package/deployment-identity-protocol.d.mts +70 -1
  4. package/deployment-identity-protocol.mjs +423 -5
  5. package/dist/agent-host/index.d.ts +1 -1
  6. package/dist/agent-host/index.d.ts.map +1 -1
  7. package/dist/agent-host/index.js.map +1 -1
  8. package/dist/agent-host/router.d.ts.map +1 -1
  9. package/dist/agent-host/router.js +17 -4
  10. package/dist/agent-host/router.js.map +1 -1
  11. package/dist/agent-host/thread-host.d.ts +14 -1
  12. package/dist/agent-host/thread-host.d.ts.map +1 -1
  13. package/dist/agent-host/thread-host.js +865 -308
  14. package/dist/agent-host/thread-host.js.map +1 -1
  15. package/dist/agent-host/thread-topology.d.ts +43 -1
  16. package/dist/agent-host/thread-topology.d.ts.map +1 -1
  17. package/dist/agent-host/thread-topology.js +301 -28
  18. package/dist/agent-host/thread-topology.js.map +1 -1
  19. package/dist/agent-runner/durable-agent-runner.d.ts +107 -8
  20. package/dist/agent-runner/durable-agent-runner.d.ts.map +1 -1
  21. package/dist/agent-runner/durable-agent-runner.js +427 -55
  22. package/dist/agent-runner/durable-agent-runner.js.map +1 -1
  23. package/dist/agent-runner/index.d.ts +1 -1
  24. package/dist/agent-runner/index.d.ts.map +1 -1
  25. package/dist/agent-runner/index.js.map +1 -1
  26. package/dist/approval-api/actor-context.d.ts +4 -0
  27. package/dist/approval-api/actor-context.d.ts.map +1 -1
  28. package/dist/approval-api/actor-context.js +53 -5
  29. package/dist/approval-api/actor-context.js.map +1 -1
  30. package/dist/approval-api/d1-store.d.ts.map +1 -1
  31. package/dist/approval-api/d1-store.js +6 -3
  32. package/dist/approval-api/d1-store.js.map +1 -1
  33. package/dist/approval-api/principal-identity.d.ts +32 -0
  34. package/dist/approval-api/principal-identity.d.ts.map +1 -0
  35. package/dist/approval-api/principal-identity.js +69 -0
  36. package/dist/approval-api/principal-identity.js.map +1 -0
  37. package/dist/approval-api/principal.d.ts +10 -13
  38. package/dist/approval-api/principal.d.ts.map +1 -1
  39. package/dist/approval-api/principal.js +10 -46
  40. package/dist/approval-api/principal.js.map +1 -1
  41. package/dist/approval-api/retention.d.ts +1 -2
  42. package/dist/approval-api/retention.d.ts.map +1 -1
  43. package/dist/approval-api/retention.js.map +1 -1
  44. package/dist/approval-api/router.d.ts.map +1 -1
  45. package/dist/approval-api/router.js +9 -1
  46. package/dist/approval-api/router.js.map +1 -1
  47. package/dist/approval-api/service.d.ts +29 -14
  48. package/dist/approval-api/service.d.ts.map +1 -1
  49. package/dist/approval-api/service.js +83 -25
  50. package/dist/approval-api/service.js.map +1 -1
  51. package/dist/approval-api/types.d.ts +12 -0
  52. package/dist/approval-api/types.d.ts.map +1 -1
  53. package/dist/approval-api/types.js +12 -0
  54. package/dist/approval-api/types.js.map +1 -1
  55. package/dist/audit-export/index.d.ts +2 -2
  56. package/dist/audit-export/index.js +2 -2
  57. package/dist/background-tasks/d1-storage.d.ts +4 -3
  58. package/dist/background-tasks/d1-storage.d.ts.map +1 -1
  59. package/dist/background-tasks/d1-storage.js +7 -13
  60. package/dist/background-tasks/d1-storage.js.map +1 -1
  61. package/dist/background-tasks/host.d.ts +127 -14
  62. package/dist/background-tasks/host.d.ts.map +1 -1
  63. package/dist/background-tasks/host.js +579 -50
  64. package/dist/background-tasks/host.js.map +1 -1
  65. package/dist/background-tasks/index.d.ts +2 -2
  66. package/dist/background-tasks/index.d.ts.map +1 -1
  67. package/dist/background-tasks/index.js +11 -6
  68. package/dist/background-tasks/index.js.map +1 -1
  69. package/dist/background-tasks/routes.d.ts +19 -2
  70. package/dist/background-tasks/routes.d.ts.map +1 -1
  71. package/dist/background-tasks/routes.js +4 -4
  72. package/dist/background-tasks/routes.js.map +1 -1
  73. package/dist/deployment-identity-protocol.d.ts +2 -2
  74. package/dist/deployment-identity-protocol.d.ts.map +1 -1
  75. package/dist/deployment-identity-protocol.js +1 -1
  76. package/dist/deployment-identity-protocol.js.map +1 -1
  77. package/dist/do-runner/cause-chain.d.ts +53 -0
  78. package/dist/do-runner/cause-chain.d.ts.map +1 -0
  79. package/dist/do-runner/cause-chain.js +96 -0
  80. package/dist/do-runner/cause-chain.js.map +1 -0
  81. package/dist/do-runner/constants.d.ts +3 -0
  82. package/dist/do-runner/constants.d.ts.map +1 -0
  83. package/dist/do-runner/constants.js +3 -0
  84. package/dist/do-runner/constants.js.map +1 -0
  85. package/dist/do-runner/d1-storage.d.ts +47 -69
  86. package/dist/do-runner/d1-storage.d.ts.map +1 -1
  87. package/dist/do-runner/d1-storage.js +972 -196
  88. package/dist/do-runner/d1-storage.js.map +1 -1
  89. package/dist/do-runner/deployment-identity.d.ts +29 -5
  90. package/dist/do-runner/deployment-identity.d.ts.map +1 -1
  91. package/dist/do-runner/deployment-identity.js +23 -6
  92. package/dist/do-runner/deployment-identity.js.map +1 -1
  93. package/dist/do-runner/do-error-response.d.ts +4 -23
  94. package/dist/do-runner/do-error-response.d.ts.map +1 -1
  95. package/dist/do-runner/do-error-response.js +19 -24
  96. package/dist/do-runner/do-error-response.js.map +1 -1
  97. package/dist/do-runner/do-status-error.d.ts +37 -0
  98. package/dist/do-runner/do-status-error.d.ts.map +1 -0
  99. package/dist/do-runner/do-status-error.js +42 -0
  100. package/dist/do-runner/do-status-error.js.map +1 -0
  101. package/dist/do-runner/durable-object.d.ts +2 -1
  102. package/dist/do-runner/durable-object.d.ts.map +1 -1
  103. package/dist/do-runner/durable-object.js +617 -144
  104. package/dist/do-runner/durable-object.js.map +1 -1
  105. package/dist/do-runner/execution-admission.d.ts +114 -0
  106. package/dist/do-runner/execution-admission.d.ts.map +1 -0
  107. package/dist/do-runner/execution-admission.js +206 -0
  108. package/dist/do-runner/execution-admission.js.map +1 -0
  109. package/dist/do-runner/execution-context.d.ts.map +1 -1
  110. package/dist/do-runner/execution-context.js +1 -0
  111. package/dist/do-runner/execution-context.js.map +1 -1
  112. package/dist/do-runner/execution-fence.d.ts +379 -0
  113. package/dist/do-runner/execution-fence.d.ts.map +1 -0
  114. package/dist/do-runner/execution-fence.js +1098 -0
  115. package/dist/do-runner/execution-fence.js.map +1 -0
  116. package/dist/do-runner/fenced-workflow-capability.d.ts +64 -0
  117. package/dist/do-runner/fenced-workflow-capability.d.ts.map +1 -0
  118. package/dist/do-runner/fenced-workflow-capability.js +3 -0
  119. package/dist/do-runner/fenced-workflow-capability.js.map +1 -0
  120. package/dist/do-runner/fenced-workflows-d1.d.ts +15 -0
  121. package/dist/do-runner/fenced-workflows-d1.d.ts.map +1 -0
  122. package/dist/do-runner/fenced-workflows-d1.js +894 -0
  123. package/dist/do-runner/fenced-workflows-d1.js.map +1 -0
  124. package/dist/do-runner/index.d.ts +20 -8
  125. package/dist/do-runner/index.d.ts.map +1 -1
  126. package/dist/do-runner/index.js +21 -4
  127. package/dist/do-runner/index.js.map +1 -1
  128. package/dist/do-runner/init.d.ts +82 -1
  129. package/dist/do-runner/init.d.ts.map +1 -1
  130. package/dist/do-runner/init.js +58 -3
  131. package/dist/do-runner/init.js.map +1 -1
  132. package/dist/do-runner/initial-admission-refusal.d.ts +7 -0
  133. package/dist/do-runner/initial-admission-refusal.d.ts.map +1 -0
  134. package/dist/do-runner/initial-admission-refusal.js +41 -0
  135. package/dist/do-runner/initial-admission-refusal.js.map +1 -0
  136. package/dist/do-runner/inventory.d.ts +295 -0
  137. package/dist/do-runner/inventory.d.ts.map +1 -0
  138. package/dist/do-runner/inventory.js +800 -0
  139. package/dist/do-runner/inventory.js.map +1 -0
  140. package/dist/do-runner/notification-predicate.d.ts +8 -0
  141. package/dist/do-runner/notification-predicate.d.ts.map +1 -0
  142. package/dist/do-runner/notification-predicate.js +136 -0
  143. package/dist/do-runner/notification-predicate.js.map +1 -0
  144. package/dist/do-runner/run-lifecycle.d.ts +20 -1
  145. package/dist/do-runner/run-lifecycle.d.ts.map +1 -1
  146. package/dist/do-runner/run-lifecycle.js +67 -13
  147. package/dist/do-runner/run-lifecycle.js.map +1 -1
  148. package/dist/do-runner/run-provenance.d.ts +38 -0
  149. package/dist/do-runner/run-provenance.d.ts.map +1 -0
  150. package/dist/do-runner/run-provenance.js +152 -0
  151. package/dist/do-runner/run-provenance.js.map +1 -0
  152. package/dist/do-runner/run-storage-tables.d.ts +2 -0
  153. package/dist/do-runner/run-storage-tables.d.ts.map +1 -0
  154. package/dist/do-runner/run-storage-tables.js +4 -0
  155. package/dist/do-runner/run-storage-tables.js.map +1 -0
  156. package/dist/do-runner/run-terminal-state.d.ts +29 -0
  157. package/dist/do-runner/run-terminal-state.d.ts.map +1 -0
  158. package/dist/do-runner/run-terminal-state.js +105 -0
  159. package/dist/do-runner/run-terminal-state.js.map +1 -0
  160. package/dist/do-runner/runtime.d.ts +191 -46
  161. package/dist/do-runner/runtime.d.ts.map +1 -1
  162. package/dist/do-runner/runtime.js +994 -378
  163. package/dist/do-runner/runtime.js.map +1 -1
  164. package/dist/do-runner/start-idempotency.d.ts +285 -0
  165. package/dist/do-runner/start-idempotency.d.ts.map +1 -0
  166. package/dist/do-runner/start-idempotency.js +994 -0
  167. package/dist/do-runner/start-idempotency.js.map +1 -0
  168. package/dist/do-runner/start-reservation-contract.d.ts +103 -0
  169. package/dist/do-runner/start-reservation-contract.d.ts.map +1 -0
  170. package/dist/do-runner/start-reservation-contract.js +338 -0
  171. package/dist/do-runner/start-reservation-contract.js.map +1 -0
  172. package/dist/do-runner/suspension-deadline.d.ts +4 -11
  173. package/dist/do-runner/suspension-deadline.d.ts.map +1 -1
  174. package/dist/do-runner/suspension-deadline.js +8 -12
  175. package/dist/do-runner/suspension-deadline.js.map +1 -1
  176. package/dist/do-runner/table-prefix.d.ts.map +1 -1
  177. package/dist/do-runner/table-prefix.js +2 -1
  178. package/dist/do-runner/table-prefix.js.map +1 -1
  179. package/dist/do-runner/testing.d.ts +3 -0
  180. package/dist/do-runner/testing.d.ts.map +1 -0
  181. package/dist/do-runner/testing.js +3 -0
  182. package/dist/do-runner/testing.js.map +1 -0
  183. package/dist/do-runner/thread-do.d.ts +2 -1
  184. package/dist/do-runner/thread-do.d.ts.map +1 -1
  185. package/dist/do-runner/thread-do.js +14 -10
  186. package/dist/do-runner/thread-do.js.map +1 -1
  187. package/dist/do-runner/workflow-snapshot-row.d.ts +49 -0
  188. package/dist/do-runner/workflow-snapshot-row.d.ts.map +1 -0
  189. package/dist/do-runner/workflow-snapshot-row.js +97 -0
  190. package/dist/do-runner/workflow-snapshot-row.js.map +1 -0
  191. package/dist/goals/objective-routes.d.ts +15 -5
  192. package/dist/goals/objective-routes.d.ts.map +1 -1
  193. package/dist/goals/objective-routes.js +64 -64
  194. package/dist/goals/objective-routes.js.map +1 -1
  195. package/dist/host-kit/approval-bridge.d.ts.map +1 -1
  196. package/dist/host-kit/approval-bridge.js +10 -7
  197. package/dist/host-kit/approval-bridge.js.map +1 -1
  198. package/dist/host-kit/do-response.d.ts +16 -0
  199. package/dist/host-kit/do-response.d.ts.map +1 -1
  200. package/dist/host-kit/do-response.js +181 -0
  201. package/dist/host-kit/do-response.js.map +1 -1
  202. package/dist/host-kit/do-run-topology.d.ts +3 -0
  203. package/dist/host-kit/do-run-topology.d.ts.map +1 -1
  204. package/dist/host-kit/do-run-topology.js +36 -8
  205. package/dist/host-kit/do-run-topology.js.map +1 -1
  206. package/dist/host-kit/env-vars.d.ts.map +1 -1
  207. package/dist/host-kit/env-vars.js +5 -6
  208. package/dist/host-kit/env-vars.js.map +1 -1
  209. package/dist/host-kit/flowsafe-worker.d.ts +49 -6
  210. package/dist/host-kit/flowsafe-worker.d.ts.map +1 -1
  211. package/dist/host-kit/flowsafe-worker.js +409 -111
  212. package/dist/host-kit/flowsafe-worker.js.map +1 -1
  213. package/dist/host-kit/host-approval-service.d.ts +24 -14
  214. package/dist/host-kit/host-approval-service.d.ts.map +1 -1
  215. package/dist/host-kit/host-approval-service.js +29 -40
  216. package/dist/host-kit/host-approval-service.js.map +1 -1
  217. package/dist/host-kit/index.d.ts +9 -3
  218. package/dist/host-kit/index.d.ts.map +1 -1
  219. package/dist/host-kit/index.js +5 -1
  220. package/dist/host-kit/index.js.map +1 -1
  221. package/dist/host-kit/run-route-error.d.ts +8 -4
  222. package/dist/host-kit/run-route-error.d.ts.map +1 -1
  223. package/dist/host-kit/run-route-error.js +14 -11
  224. package/dist/host-kit/run-route-error.js.map +1 -1
  225. package/dist/host-kit/run-router.d.ts +63 -2
  226. package/dist/host-kit/run-router.d.ts.map +1 -1
  227. package/dist/host-kit/run-router.js +167 -45
  228. package/dist/host-kit/run-router.js.map +1 -1
  229. package/dist/host-kit/stream-router.d.ts.map +1 -1
  230. package/dist/host-kit/stream-router.js +18 -9
  231. package/dist/host-kit/stream-router.js.map +1 -1
  232. package/dist/host-kit/thread-topology.d.ts +1 -1
  233. package/dist/host-kit/thread-topology.d.ts.map +1 -1
  234. package/dist/host-kit/thread-topology.js +7 -3
  235. package/dist/host-kit/thread-topology.js.map +1 -1
  236. package/dist/internal-error-response.d.ts.map +1 -1
  237. package/dist/internal-error-response.js +16 -6
  238. package/dist/internal-error-response.js.map +1 -1
  239. package/dist/schedules/index.d.ts +1 -0
  240. package/dist/schedules/index.d.ts.map +1 -1
  241. package/dist/schedules/index.js +1 -7
  242. package/dist/schedules/index.js.map +1 -1
  243. package/dist/schedules/mutation-contract.d.ts +38 -0
  244. package/dist/schedules/mutation-contract.d.ts.map +1 -0
  245. package/dist/schedules/mutation-contract.js +21 -0
  246. package/dist/schedules/mutation-contract.js.map +1 -0
  247. package/dist/schedules/router.d.ts +15 -8
  248. package/dist/schedules/router.d.ts.map +1 -1
  249. package/dist/schedules/router.js +170 -59
  250. package/dist/schedules/router.js.map +1 -1
  251. package/dist/schedules/schedules-d1.d.ts +11 -5
  252. package/dist/schedules/schedules-d1.d.ts.map +1 -1
  253. package/dist/schedules/schedules-d1.js +570 -143
  254. package/dist/schedules/schedules-d1.js.map +1 -1
  255. package/dist/schedules/storage.d.ts +0 -7
  256. package/dist/schedules/storage.d.ts.map +1 -1
  257. package/dist/schedules/storage.js +0 -27
  258. package/dist/schedules/storage.js.map +1 -1
  259. package/dist/schedules/tick.d.ts +13 -0
  260. package/dist/schedules/tick.d.ts.map +1 -1
  261. package/dist/schedules/tick.js +66 -40
  262. package/dist/schedules/tick.js.map +1 -1
  263. package/dist/signal-providers/host-do.d.ts +12 -1
  264. package/dist/signal-providers/host-do.d.ts.map +1 -1
  265. package/dist/signal-providers/host-do.js +28 -3
  266. package/dist/signal-providers/host-do.js.map +1 -1
  267. package/dist/signal-providers/webhook-route.d.ts +15 -1
  268. package/dist/signal-providers/webhook-route.d.ts.map +1 -1
  269. package/dist/signal-providers/webhook-route.js +126 -113
  270. package/dist/signal-providers/webhook-route.js.map +1 -1
  271. package/dist/signals/d1-shared.d.ts +11 -8
  272. package/dist/signals/d1-shared.d.ts.map +1 -1
  273. package/dist/signals/d1-shared.js +1 -6
  274. package/dist/signals/d1-shared.js.map +1 -1
  275. package/dist/signals/index.d.ts +1 -1
  276. package/dist/signals/index.d.ts.map +1 -1
  277. package/dist/signals/index.js +1 -1
  278. package/dist/signals/index.js.map +1 -1
  279. package/dist/signals/notification-dispatch.d.ts +109 -5
  280. package/dist/signals/notification-dispatch.d.ts.map +1 -1
  281. package/dist/signals/notification-dispatch.js +430 -46
  282. package/dist/signals/notification-dispatch.js.map +1 -1
  283. package/dist/signals/notifications-d1.d.ts +14 -1
  284. package/dist/signals/notifications-d1.d.ts.map +1 -1
  285. package/dist/signals/notifications-d1.js +229 -18
  286. package/dist/signals/notifications-d1.js.map +1 -1
  287. package/dist/signals/router.d.ts +6 -4
  288. package/dist/signals/router.d.ts.map +1 -1
  289. package/dist/signals/router.js +49 -84
  290. package/dist/signals/router.js.map +1 -1
  291. package/dist/signals/thread-do-routes.d.ts +2 -0
  292. package/dist/signals/thread-do-routes.d.ts.map +1 -1
  293. package/dist/signals/thread-do-routes.js +330 -83
  294. package/dist/signals/thread-do-routes.js.map +1 -1
  295. package/package.json +6 -3
  296. package/patches/@mastra__core@1.53.0.patch +54 -0
  297. package/scripts/seed-deployment-identity.mjs +34 -9
@@ -0,0 +1,295 @@
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`, the enumerated pending rows not yet due, including rows with
64
+ * neither delivery timestamp).
65
+ */
66
+ readonly totals?: Readonly<Record<string, number>>;
67
+ }
68
+ /**
69
+ * State that holds work but cannot be counted, declared rather than omitted.
70
+ *
71
+ * An inventory that silently skipped these would be reporting a smaller number
72
+ * than the truth under the same name as a complete one, which is the single
73
+ * most dangerous thing this surface could do. Each entry states what it holds
74
+ * and the BOUND on how long it can stay invisible, so the drain procedure can
75
+ * be built to outlast it.
76
+ */
77
+ export interface UnenumerableState {
78
+ /** Stable identifier for the invisible state. */
79
+ readonly name: string;
80
+ /** What it can hold. */
81
+ readonly holds: string;
82
+ /** Why no pure query can see it. */
83
+ readonly because: string;
84
+ /** How long it can stay invisible, and what makes it visible again. */
85
+ readonly bound: string;
86
+ }
87
+ /** The rule an operator reads an empty inventory under. */
88
+ export interface DrainProofContract {
89
+ /**
90
+ * How to interpret point-in-time readings while draining still admits work.
91
+ * Rows can enter or leave, but an empty result cannot over-count work.
92
+ */
93
+ readonly reading: string;
94
+ /** What a proof actually is. */
95
+ readonly proof: string;
96
+ /** The fence states an empty `work` set is reachable from. */
97
+ readonly reachableFrom: readonly ExecutionFenceState[];
98
+ /** How to interpret a post-lock re-sweep and a read taken under the lock. */
99
+ readonly note: string;
100
+ }
101
+ /** The no-category response: what can be asked for, and how to read the answer. */
102
+ export interface InventoryIndex {
103
+ readonly categories: readonly InventoryCategoryDescriptor[];
104
+ readonly unenumerable: readonly UnenumerableState[];
105
+ readonly drainProof: DrainProofContract;
106
+ }
107
+ /**
108
+ * The database surface an inventory read needs — and NOTHING ELSE.
109
+ *
110
+ * There is no `run()` on this seam, deliberately. Every other store in this
111
+ * package takes a shape that can write, because it writes; this one cannot
112
+ * express a write at all, so "the inventory performs no writes" is a fact about
113
+ * the type rather than a promise about the code. `env.DB` satisfies it
114
+ * structurally, as does a node:sqlite test double.
115
+ */
116
+ export interface InventoryDatabase {
117
+ prepare(query: string): InventoryStatement;
118
+ }
119
+ /** One prepared read. */
120
+ export interface InventoryStatement {
121
+ bind(...values: unknown[]): InventoryStatement;
122
+ all<T = unknown>(): Promise<{
123
+ results: T[];
124
+ }>;
125
+ }
126
+ /** How one flowsafe-owned table is accounted for by the inventory. */
127
+ export type InventoryTableAccounting = {
128
+ /** Rows of this table are reported under this category. */
129
+ readonly category: InventoryCategory;
130
+ } | {
131
+ /**
132
+ * This table holds no drainable work, and here is why. The census
133
+ * requires more than twenty characters: "not work" and "nobody looked"
134
+ * are indistinguishable at that length, and only one of them is a
135
+ * decision.
136
+ */
137
+ readonly excluded: string;
138
+ };
139
+ /** One flowsafe-owned table and its accounting. */
140
+ export interface FlowsafeTableEntry {
141
+ /** The un-prefixed table name. */
142
+ readonly table: string;
143
+ /** What the table is for. */
144
+ readonly purpose: string;
145
+ /** Its inventory category, or the reason it has none. */
146
+ readonly accounting: InventoryTableAccounting;
147
+ }
148
+ /**
149
+ * THE FLOWSAFE TABLE CENSUS. Every `flowsafe_`-prefixed table this package
150
+ * creates, mapped to an inventory category or to a justified exclusion.
151
+ *
152
+ * It exists because the schema guard's `mastra_%` sweep cannot see these: they
153
+ * are not created by `createD1Storage`, and two of them (the deployment
154
+ * sentinel and the fence) are created by the provisioning protocol before any
155
+ * runtime code runs. Without an explicit list, a flowsafe table holding
156
+ * suspended work could be added, purged, documented, and shipped without ever
157
+ * meeting the question this module exists to answer.
158
+ *
159
+ * ADDING A TABLE: add it here in the same change. The census test fails until
160
+ * you do, and it fails again if you claim an exclusion in fewer than twenty
161
+ * characters.
162
+ */
163
+ export declare const FLOWSAFE_TABLES: readonly FlowsafeTableEntry[];
164
+ /** The largest page an inventory read will return, whatever `limit` asks for. */
165
+ export declare const INVENTORY_MAX_LIMIT = 200;
166
+ /** The page size used when `limit` is absent. */
167
+ export declare const INVENTORY_DEFAULT_LIMIT = 100;
168
+ /**
169
+ * Bound parameters D1 accepts in ONE statement. The retention purge caps its
170
+ * own batch against the same limit (d1-storage.ts).
171
+ */
172
+ export declare const D1_MAX_BOUND_PARAMETERS = 100;
173
+ /**
174
+ * Bound parameters the run-owner lookup spends on anything OTHER than run ids.
175
+ *
176
+ * Zero today: `resource_kind = 'run'` is a SQL literal, not a bind. It is named
177
+ * rather than assumed because the slice size below is `cap - this`, and a
178
+ * future predicate that binds a value would otherwise push the statement one
179
+ * parameter over the limit with nothing to catch it.
180
+ */
181
+ export declare const RUN_OWNER_FIXED_BINDINGS = 0;
182
+ /**
183
+ * Run ids per owner-lookup statement: the full parameter budget, less whatever
184
+ * the statement spends on its own predicate. 100 - 0 = 100, so a maximum page
185
+ * (INVENTORY_MAX_LIMIT = 200) costs exactly two statements.
186
+ */
187
+ export declare const RUN_OWNER_LOOKUP_CHUNK: number;
188
+ /**
189
+ * A malformed inventory request: an unknown category, an unparseable cursor, or
190
+ * a cursor whose shape does not match the category it was sent to.
191
+ *
192
+ * 400 rather than a silent restart from the beginning. A cursor that quietly
193
+ * resets would make a sweep re-read rows it had already counted and never
194
+ * reach the end, and an operator watching for two consecutive empty sweeps
195
+ * would wait forever without being told why.
196
+ */
197
+ export declare class InvalidInventoryRequestError extends DoStatusError {
198
+ readonly status = 400;
199
+ readonly reason: {
200
+ readonly code: 'INVALID_INVENTORY_REQUEST';
201
+ };
202
+ constructor(message: string);
203
+ }
204
+ /** Is this a category the inventory serves? */
205
+ export declare function isInventoryCategory(value: unknown): value is InventoryCategory;
206
+ /**
207
+ * The state a pure D1 query cannot see, declared rather than omitted.
208
+ *
209
+ * THE SWEEP BEHIND THIS LIST. Every key a Durable Object in this package writes
210
+ * was checked against the categories above, and all but one is backed by a row
211
+ * a query here already returns:
212
+ *
213
+ * `flowsafe:run-owner-recovery:v1` — DECLARED below. It is written BEFORE the
214
+ * D1 owner row, so a crash between the two leaves a run with no D1 record at
215
+ * all.
216
+ *
217
+ * `flowsafe:agent-thread-binding:v1` / `flowsafe:agent-run:v1:*` — a thread's
218
+ * binding to its agent run and that run's own state. Both name a run whose
219
+ * ownership is RESERVED in D1 BEFORE execution begins
220
+ * (agent-host/thread-host.ts, durable-object.ts) and settled only AFTER a
221
+ * summary has persisted. The engine also writes a `running` snapshot as the
222
+ * run starts, so an executing run is normally reported under `runs` on its own
223
+ * — but that snapshot lands INSIDE `runtime.start`, after the reservation, and
224
+ * the unsettled reservation is what covers the gap between the two as well as
225
+ * any later moment the snapshot is behind the run. `resource-owners` is a WORK
226
+ * category for exactly that reason: an unsettled reservation means a start
227
+ * that has not durably settled, whatever the snapshot currently says.
228
+ * (Pinned behaviourally by inventory.test.ts's ownership-ordering test, which
229
+ * fails if settlement ever moves ahead of the persisted summary.)
230
+ *
231
+ * `flowsafe:suspension-deadline:v1` — an armed wake for a run that is
232
+ * suspended, and therefore nonterminal, and therefore under `runs`.
233
+ *
234
+ * `flowsafe:maintenance-health:v1`, `flowsafe:maintenance-nonces:v1`,
235
+ * `flowsafe:maintenance-deadline-cursor:v1` — the maintenance object's own
236
+ * health, replay protection, and scan position. None is a unit of work: they
237
+ * describe the sweeper, not what it sweeps.
238
+ */
239
+ export declare const INVENTORY_UNENUMERABLE: readonly UnenumerableState[];
240
+ /**
241
+ * The rule that turns inventory readings into a decision.
242
+ *
243
+ * Stated in the index response, and repeated in the route doc, because every
244
+ * dangerous use of this surface is a use that skips it: one empty sweep is not
245
+ * a proof, and an empty sweep taken under `migration-locked` is not even a
246
+ * measurement of a drain.
247
+ */
248
+ export declare const INVENTORY_DRAIN_PROOF: DrainProofContract;
249
+ /** Every category's descriptor, in index order. */
250
+ export declare const INVENTORY_CATEGORY_DESCRIPTORS: readonly InventoryCategoryDescriptor[];
251
+ /** The whole no-category answer, assembled once. */
252
+ export declare const INVENTORY_INDEX: InventoryIndex;
253
+ /** Construction-time options for a deployment inventory. */
254
+ export interface DeploymentInventoryOptions {
255
+ /**
256
+ * The same storage table prefix `createD1Storage` and the retention purges
257
+ * take. It applies to the Mastra-owned tables only, exactly as it does
258
+ * there — the flowsafe-owned registries are never prefixed.
259
+ */
260
+ tablePrefix?: string;
261
+ /** Injectable clock, for the due-notification predicate. */
262
+ now?: () => number;
263
+ }
264
+ /** Per-read options: where to resume, and how many rows to take. */
265
+ export interface InventoryReadOptions {
266
+ /** The `key` of the last entry of the previous page, as JSON text. */
267
+ cursor?: string;
268
+ /** Rows to return, clamped to INVENTORY_MAX_LIMIT. */
269
+ limit?: number;
270
+ }
271
+ /**
272
+ * The deployment's read-only work inventory over one D1 database — the same
273
+ * database its runs, approvals, and fence live in, so what it reports and what
274
+ * the fence governs cannot be two different deployments.
275
+ */
276
+ export declare class DeploymentInventory {
277
+ #private;
278
+ constructor(db: InventoryDatabase, options?: DeploymentInventoryOptions);
279
+ /**
280
+ * What this deployment can be asked about, what it cannot answer, and the
281
+ * rule for reading an empty answer.
282
+ *
283
+ * A constant, and deliberately not a query: the index is the CONTRACT, and a
284
+ * contract that changed with the data would let an operator conclude that a
285
+ * category they cannot see does not apply to them.
286
+ */
287
+ index(): InventoryIndex;
288
+ /** One page of one category. */
289
+ read(category: InventoryCategory, options?: InventoryReadOptions): Promise<InventoryPage>;
290
+ /** Every category's first page, for a caller sweeping the whole deployment. */
291
+ sweep(options?: {
292
+ limit?: number;
293
+ }): Promise<readonly InventoryPage[]>;
294
+ }
295
+ //# sourceMappingURL=inventory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inventory.d.ts","sourceRoot":"","sources":["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