@lostgradient/weft 0.23.1 → 0.24.1

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 (469) hide show
  1. package/README.md +72 -4
  2. package/dist/cli/codegen-emit-dedup.d.ts +81 -0
  3. package/dist/cli/codegen-emit-dedup.js +45 -0
  4. package/dist/cli/codegen-emit-registry.d.ts +90 -0
  5. package/dist/cli/codegen-emit-registry.js +50 -0
  6. package/dist/cli/codegen-emit.d.ts +26 -39
  7. package/dist/cli/codegen-emit.js +4 -27
  8. package/dist/cli/codegen-validate.d.ts +49 -0
  9. package/dist/cli/codegen-validate.js +186 -0
  10. package/dist/cli/codegen.js +6 -87
  11. package/dist/cli/conformance.js +5 -2
  12. package/dist/cli/generated/operation-catalog.snapshot.json +381 -3
  13. package/dist/cli/generated/operation-client.generated.d.ts +350 -10
  14. package/dist/cli/generated/operation-client.generated.js +14 -0
  15. package/dist/cli/output.js +1 -1
  16. package/dist/cli/parse-schedule-arguments.js +15 -3
  17. package/dist/cli/schedule.js +2 -1
  18. package/dist/cli/storage-factory.js +2 -0
  19. package/dist/cli/types.d.ts +2 -1
  20. package/dist/cli/workflow-commands.js +2 -0
  21. package/dist/cli-main.js +1 -1
  22. package/dist/client/http-client-requests.js +6 -9
  23. package/dist/client/start-body.js +1 -0
  24. package/dist/core/application-payload-digest.d.ts +42 -0
  25. package/dist/core/application-payload-digest.js +76 -0
  26. package/dist/core/application-primitive-abort.d.ts +50 -0
  27. package/dist/core/application-primitive-abort.js +40 -0
  28. package/dist/core/application-primitive-attempt-registry.d.ts +74 -0
  29. package/dist/core/application-primitive-attempt-registry.js +73 -0
  30. package/dist/core/application-primitive-codec.d.ts +36 -0
  31. package/dist/core/application-primitive-codec.js +56 -0
  32. package/dist/core/application-primitive-commit.d.ts +67 -0
  33. package/dist/core/application-primitive-commit.js +66 -0
  34. package/dist/core/application-primitive-guards.d.ts +62 -0
  35. package/dist/core/application-primitive-guards.js +89 -0
  36. package/dist/core/application-primitive-payload.d.ts +29 -0
  37. package/dist/core/application-primitive-payload.js +65 -0
  38. package/dist/core/application-primitive-timing.d.ts +18 -0
  39. package/dist/core/application-primitive-timing.js +22 -0
  40. package/dist/core/atomic-state.js +2 -0
  41. package/dist/core/catalog/codec.d.ts +40 -0
  42. package/dist/core/catalog/codec.js +45 -0
  43. package/dist/core/catalog/errors.d.ts +104 -0
  44. package/dist/core/catalog/errors.js +41 -0
  45. package/dist/core/catalog/index.d.ts +25 -0
  46. package/dist/core/catalog/index.js +22 -0
  47. package/dist/core/catalog/reference-counts.d.ts +120 -0
  48. package/dist/core/catalog/reference-counts.js +28 -0
  49. package/dist/core/catalog/removal.d.ts +105 -0
  50. package/dist/core/catalog/removal.js +30 -0
  51. package/dist/core/catalog/storage-io.d.ts +101 -0
  52. package/dist/core/catalog/storage-io.js +106 -0
  53. package/dist/core/catalog/types.d.ts +108 -0
  54. package/dist/core/catalog/types.js +0 -0
  55. package/dist/core/catalog/workflow-catalog.d.ts +165 -0
  56. package/dist/core/catalog/workflow-catalog.js +198 -0
  57. package/dist/core/compare-codepoint.d.ts +13 -0
  58. package/dist/core/compare-codepoint.js +7 -0
  59. package/dist/core/compression.js +2 -0
  60. package/dist/core/context/attributes.d.ts +1 -1
  61. package/dist/core/context/durable-operations.d.ts +2 -2
  62. package/dist/core/context/index.js +5 -3
  63. package/dist/core/context/state-namespace.d.ts +1 -1
  64. package/dist/core/contract/build.d.ts +64 -0
  65. package/dist/core/contract/build.js +99 -0
  66. package/dist/core/contract/compatibility.d.ts +187 -0
  67. package/dist/core/contract/compatibility.js +37 -0
  68. package/dist/core/contract/failure.d.ts +64 -0
  69. package/dist/core/contract/failure.js +4 -0
  70. package/dist/core/contract/hash.d.ts +92 -0
  71. package/dist/core/contract/hash.js +34 -0
  72. package/dist/core/contract/index.d.ts +21 -0
  73. package/dist/core/contract/index.js +22 -0
  74. package/dist/core/contract/limits.d.ts +74 -0
  75. package/dist/core/contract/limits.js +1 -0
  76. package/dist/core/contract/manifest-parse-schema.d.ts +37 -0
  77. package/dist/core/contract/manifest-parse-schema.js +106 -0
  78. package/dist/core/contract/manifest-parse.d.ts +76 -0
  79. package/dist/core/contract/manifest-parse.js +189 -0
  80. package/dist/core/contract/manifest.d.ts +56 -0
  81. package/dist/core/contract/manifest.js +31 -0
  82. package/dist/core/contract/normalize.d.ts +97 -0
  83. package/dist/core/contract/normalize.js +127 -0
  84. package/dist/core/contract/revision.d.ts +29 -0
  85. package/dist/core/contract/revision.js +5 -0
  86. package/dist/core/contract/types.d.ts +274 -0
  87. package/dist/core/contract/types.js +1 -0
  88. package/dist/core/engine/activity-resolution.js +17 -17
  89. package/dist/core/engine/bulk-operations-purge.js +14 -20
  90. package/dist/core/engine/bulk-operations-retry.d.ts +9 -0
  91. package/dist/core/engine/bulk-operations-retry.js +177 -0
  92. package/dist/core/engine/bulk-operations-shared.d.ts +18 -0
  93. package/dist/core/engine/bulk-operations-shared.js +14 -0
  94. package/dist/core/engine/bulk-operations.js +8 -167
  95. package/dist/core/engine/callback-creators-bundles.js +4 -2
  96. package/dist/core/engine/callback-creators-core.js +9 -1
  97. package/dist/core/engine/callback-creators-schedule.js +2 -2
  98. package/dist/core/engine/catalog-activation.d.ts +40 -0
  99. package/dist/core/engine/catalog-activation.js +17 -0
  100. package/dist/core/engine/catalog-events.d.ts +36 -0
  101. package/dist/core/engine/catalog-events.js +15 -0
  102. package/dist/core/engine/catalog-readiness.d.ts +49 -0
  103. package/dist/core/engine/catalog-readiness.js +61 -0
  104. package/dist/core/engine/catalog-removal.d.ts +236 -0
  105. package/dist/core/engine/catalog-removal.js +123 -0
  106. package/dist/core/engine/catalog-tombstone-recovery.d.ts +56 -0
  107. package/dist/core/engine/catalog-tombstone-recovery.js +39 -0
  108. package/dist/core/engine/constraints.js +5 -1
  109. package/dist/core/engine/construction.d.ts +2 -2
  110. package/dist/core/engine/construction.js +4 -2
  111. package/dist/core/engine/decode-revision.d.ts +32 -0
  112. package/dist/core/engine/decode-revision.js +9 -0
  113. package/dist/core/engine/disposal.d.ts +6 -2
  114. package/dist/core/engine/disposal.js +26 -3
  115. package/dist/core/engine/dynamic-source-errors.d.ts +81 -0
  116. package/dist/core/engine/dynamic-source-errors.js +25 -0
  117. package/dist/core/engine/dynamic-source-execution.d.ts +173 -0
  118. package/dist/core/engine/dynamic-source-execution.js +108 -0
  119. package/dist/core/engine/engine-internal-types.d.ts +16 -0
  120. package/dist/core/engine/engine-workflows-namespace.d.ts +140 -0
  121. package/dist/core/engine/engine-workflows-namespace.js +51 -0
  122. package/dist/core/engine/finalizer-metadata.d.ts +22 -0
  123. package/dist/core/engine/finalizer-metadata.js +12 -0
  124. package/dist/core/engine/handle-result.js +2 -0
  125. package/dist/core/engine/index.d.ts +91 -0
  126. package/dist/core/engine/index.js +78 -6
  127. package/dist/core/engine/inline-launch-queue.js +1 -1
  128. package/dist/core/engine/internals.d.ts +54 -15
  129. package/dist/core/engine/internals.js +6 -0
  130. package/dist/core/engine/lifecycle/checkpoint-launch.d.ts +29 -0
  131. package/dist/core/engine/lifecycle/checkpoint-launch.js +75 -0
  132. package/dist/core/engine/lifecycle/delayed-start-registration.d.ts +30 -0
  133. package/dist/core/engine/lifecycle/delayed-start-registration.js +11 -0
  134. package/dist/core/engine/lifecycle/fork-helpers.d.ts +33 -1
  135. package/dist/core/engine/lifecycle/fork-helpers.js +3 -1
  136. package/dist/core/engine/lifecycle/recovery-revision-groups.d.ts +75 -0
  137. package/dist/core/engine/lifecycle/recovery-revision-groups.js +64 -0
  138. package/dist/core/engine/lifecycle/resume-generation-guard.d.ts +58 -0
  139. package/dist/core/engine/lifecycle/resume-generation-guard.js +11 -0
  140. package/dist/core/engine/lifecycle/resume.js +18 -9
  141. package/dist/core/engine/lifecycle/shared.d.ts +43 -0
  142. package/dist/core/engine/lifecycle/standalone-claim-acquire.d.ts +12 -0
  143. package/dist/core/engine/lifecycle/standalone-claim-acquire.js +6 -0
  144. package/dist/core/engine/lifecycle/start-commit-errors.d.ts +12 -0
  145. package/dist/core/engine/lifecycle/start-commit-errors.js +6 -0
  146. package/dist/core/engine/lifecycle/start-commit.d.ts +22 -7
  147. package/dist/core/engine/lifecycle/start-commit.js +49 -15
  148. package/dist/core/engine/lifecycle/start-exec.d.ts +18 -2
  149. package/dist/core/engine/lifecycle/start-exec.js +7 -5
  150. package/dist/core/engine/lifecycle/start-or-signal-create.js +1 -3
  151. package/dist/core/engine/lifecycle/start-or-signal.js +1 -1
  152. package/dist/core/engine/lifecycle/start-precondition-attribution.d.ts +49 -0
  153. package/dist/core/engine/lifecycle/start-precondition-attribution.js +13 -0
  154. package/dist/core/engine/lifecycle/start-revision-resolution.d.ts +34 -0
  155. package/dist/core/engine/lifecycle/start-revision-resolution.js +11 -0
  156. package/dist/core/engine/lifecycle/start-state.d.ts +16 -0
  157. package/dist/core/engine/lifecycle/start-state.js +60 -0
  158. package/dist/core/engine/lifecycle/start-terminal-conflict-purge.d.ts +66 -3
  159. package/dist/core/engine/lifecycle/start-terminal-conflict-purge.js +13 -3
  160. package/dist/core/engine/lifecycle/start.d.ts +16 -6
  161. package/dist/core/engine/lifecycle/start.js +39 -66
  162. package/dist/core/engine/lifecycle/transition.d.ts +3 -4
  163. package/dist/core/engine/lifecycle/transition.js +30 -80
  164. package/dist/core/engine/lifecycle.d.ts +4 -2
  165. package/dist/core/engine/lifecycle.js +6 -6
  166. package/dist/core/engine/listing.js +15 -1
  167. package/dist/core/engine/memo-durable-activity.js +4 -1
  168. package/dist/core/engine/nonterminal-revision-count.d.ts +25 -0
  169. package/dist/core/engine/nonterminal-revision-count.js +16 -0
  170. package/dist/core/engine/operations-time.d.ts +5 -23
  171. package/dist/core/engine/operations-time.js +13 -11
  172. package/dist/core/engine/ownership-bootstrap.d.ts +1 -1
  173. package/dist/core/engine/pinned-schedule-revision-count.d.ts +26 -0
  174. package/dist/core/engine/pinned-schedule-revision-count.js +19 -0
  175. package/dist/core/engine/pinned-schedule-revision.d.ts +76 -0
  176. package/dist/core/engine/pinned-schedule-revision.js +53 -0
  177. package/dist/core/engine/registration.d.ts +106 -0
  178. package/dist/core/engine/registration.js +28 -7
  179. package/dist/core/engine/retention.js +9 -2
  180. package/dist/core/engine/revision-errors.d.ts +71 -0
  181. package/dist/core/engine/revision-errors.js +13 -0
  182. package/dist/core/engine/schedule-revision-fire.d.ts +17 -0
  183. package/dist/core/engine/schedule-revision-fire.js +3 -0
  184. package/dist/core/engine/schedule-run.js +2 -1
  185. package/dist/core/engine/schedules.d.ts +2 -1
  186. package/dist/core/engine/schedules.js +28 -9
  187. package/dist/core/engine/source-diagnostics.d.ts +76 -0
  188. package/dist/core/engine/source-diagnostics.js +105 -0
  189. package/dist/core/engine/source-registration.d.ts +42 -0
  190. package/dist/core/engine/source-registration.js +38 -0
  191. package/dist/core/engine/source-resolution.d.ts +101 -0
  192. package/dist/core/engine/source-resolution.js +154 -0
  193. package/dist/core/engine/source-runtime-state.d.ts +92 -0
  194. package/dist/core/engine/source-runtime-state.js +36 -0
  195. package/dist/core/engine/storage-io.d.ts +19 -2
  196. package/dist/core/engine/storage-io.js +21 -2
  197. package/dist/core/engine/termination/finalizer-registration.d.ts +18 -0
  198. package/dist/core/engine/termination/finalizer-registration.js +21 -0
  199. package/dist/core/engine/termination/finalizer.d.ts +16 -19
  200. package/dist/core/engine/termination/finalizer.js +3 -3
  201. package/dist/core/engine/time-operation-callbacks.d.ts +32 -0
  202. package/dist/core/engine/time-operation-callbacks.js +0 -0
  203. package/dist/core/engine/validation/schedule-cadence.d.ts +16 -0
  204. package/dist/core/engine/validation/schedule-cadence.js +20 -0
  205. package/dist/core/engine/validation/schedule-options.d.ts +4 -1
  206. package/dist/core/engine/validation/schedule-options.js +14 -0
  207. package/dist/core/engine/validation/schedule-revision.d.ts +24 -0
  208. package/dist/core/engine/validation/schedule-revision.js +21 -0
  209. package/dist/core/engine/validation/schedule-warnings.d.ts +11 -0
  210. package/dist/core/engine/validation/schedule-warnings.js +5 -0
  211. package/dist/core/engine/validation/schedule.d.ts +4 -3
  212. package/dist/core/engine/validation/schedule.js +15 -26
  213. package/dist/core/engine/validation.js +5 -2
  214. package/dist/core/engine/workflow-claim-reclaim-target.d.ts +1 -1
  215. package/dist/core/engine/workflow-claim-reclaim-target.js +16 -2
  216. package/dist/core/engine/workflow-retention-deadline.d.ts +16 -0
  217. package/dist/core/engine/workflow-retention-deadline.js +33 -0
  218. package/dist/core/events/catalog-events.d.ts +117 -0
  219. package/dist/core/events/catalog-events.js +62 -0
  220. package/dist/core/events/event-map.d.ts +11 -0
  221. package/dist/core/events/index.d.ts +2 -0
  222. package/dist/core/events/index.js +2 -0
  223. package/dist/core/events/workflow-source-events.d.ts +102 -0
  224. package/dist/core/events/workflow-source-events.js +57 -0
  225. package/dist/core/execution-strategy.d.ts +7 -0
  226. package/dist/core/inline-execution-strategy.context-options.d.ts +1 -1
  227. package/dist/core/inline-execution-strategy.js +1 -1
  228. package/dist/core/mailbox-admission.d.ts +26 -0
  229. package/dist/core/mailbox-admission.js +130 -0
  230. package/dist/core/mailbox-claims.d.ts +251 -0
  231. package/dist/core/mailbox-claims.js +0 -0
  232. package/dist/core/mailbox-codec.d.ts +32 -0
  233. package/dist/core/mailbox-codec.js +221 -0
  234. package/dist/core/mailbox-contract.d.ts +290 -0
  235. package/dist/core/mailbox-contract.js +0 -0
  236. package/dist/core/mailbox-delivery.d.ts +37 -0
  237. package/dist/core/mailbox-delivery.js +193 -0
  238. package/dist/core/mailbox-guards.d.ts +78 -0
  239. package/dist/core/mailbox-guards.js +58 -0
  240. package/dist/core/mailbox-index-codec.d.ts +41 -0
  241. package/dist/core/mailbox-index-codec.js +71 -0
  242. package/dist/core/mailbox-internals.d.ts +156 -0
  243. package/dist/core/mailbox-internals.js +154 -0
  244. package/dist/core/mailbox-maintenance.d.ts +29 -0
  245. package/dist/core/mailbox-maintenance.js +196 -0
  246. package/dist/core/mailbox-settlement.d.ts +69 -0
  247. package/dist/core/mailbox-settlement.js +206 -0
  248. package/dist/core/mailbox-storage.d.ts +117 -0
  249. package/dist/core/mailbox-storage.js +115 -0
  250. package/dist/core/mailbox-transition-helpers.d.ts +70 -0
  251. package/dist/core/mailbox-transition-helpers.js +43 -0
  252. package/dist/core/mailbox-transitions-recovery.d.ts +28 -0
  253. package/dist/core/mailbox-transitions-recovery.js +64 -0
  254. package/dist/core/mailbox-transitions.d.ts +138 -0
  255. package/dist/core/mailbox-transitions.js +180 -0
  256. package/dist/core/mailbox-types.d.ts +406 -0
  257. package/dist/core/mailbox-types.js +16 -0
  258. package/dist/core/mailbox-validation.d.ts +65 -0
  259. package/dist/core/mailbox-validation.js +73 -0
  260. package/dist/core/mailbox-waits.d.ts +50 -0
  261. package/dist/core/mailbox-waits.js +97 -0
  262. package/dist/core/mailbox.d.ts +163 -0
  263. package/dist/core/mailbox.js +211 -0
  264. package/dist/core/outbox-claims.d.ts +307 -0
  265. package/dist/core/outbox-claims.js +0 -0
  266. package/dist/core/outbox-codec.d.ts +24 -0
  267. package/dist/core/outbox-codec.js +257 -0
  268. package/dist/core/outbox-contract.d.ts +346 -0
  269. package/dist/core/outbox-contract.js +0 -0
  270. package/dist/core/outbox-delivery.d.ts +34 -0
  271. package/dist/core/outbox-delivery.js +149 -0
  272. package/dist/core/outbox-drain.d.ts +29 -0
  273. package/dist/core/outbox-drain.js +158 -0
  274. package/dist/core/outbox-enqueue.d.ts +24 -0
  275. package/dist/core/outbox-enqueue.js +115 -0
  276. package/dist/core/outbox-guards.d.ts +76 -0
  277. package/dist/core/outbox-guards.js +60 -0
  278. package/dist/core/outbox-index-codec.d.ts +33 -0
  279. package/dist/core/outbox-index-codec.js +71 -0
  280. package/dist/core/outbox-internals.d.ts +99 -0
  281. package/dist/core/outbox-internals.js +159 -0
  282. package/dist/core/outbox-listing.d.ts +12 -0
  283. package/dist/core/outbox-listing.js +38 -0
  284. package/dist/core/outbox-maintenance.d.ts +28 -0
  285. package/dist/core/outbox-maintenance.js +191 -0
  286. package/dist/core/outbox-operations.d.ts +18 -0
  287. package/dist/core/outbox-operations.js +46 -0
  288. package/dist/core/outbox-runner.d.ts +30 -0
  289. package/dist/core/outbox-runner.js +217 -0
  290. package/dist/core/outbox-settlement.d.ts +57 -0
  291. package/dist/core/outbox-settlement.js +183 -0
  292. package/dist/core/outbox-storage.d.ts +107 -0
  293. package/dist/core/outbox-storage.js +127 -0
  294. package/dist/core/outbox-transition-helpers.d.ts +83 -0
  295. package/dist/core/outbox-transition-helpers.js +63 -0
  296. package/dist/core/outbox-transitions-recovery.d.ts +30 -0
  297. package/dist/core/outbox-transitions-recovery.js +42 -0
  298. package/dist/core/outbox-transitions.d.ts +145 -0
  299. package/dist/core/outbox-transitions.js +236 -0
  300. package/dist/core/outbox-types.d.ts +400 -0
  301. package/dist/core/outbox-types.js +20 -0
  302. package/dist/core/outbox-validation.d.ts +101 -0
  303. package/dist/core/outbox-validation.js +127 -0
  304. package/dist/core/outbox-waits.d.ts +39 -0
  305. package/dist/core/outbox-waits.js +88 -0
  306. package/dist/core/outbox.d.ts +156 -0
  307. package/dist/core/outbox.js +234 -0
  308. package/dist/core/registry-limits.d.ts +49 -0
  309. package/dist/core/registry-limits.js +10 -0
  310. package/dist/core/registry-schema-conversion.d.ts +20 -0
  311. package/dist/core/registry-schema-conversion.js +22 -0
  312. package/dist/core/registry-snapshot.d.ts +91 -42
  313. package/dist/core/registry-snapshot.js +39 -77
  314. package/dist/core/registry-workflow-contract-draft.d.ts +32 -0
  315. package/dist/core/registry-workflow-contract-draft.js +28 -0
  316. package/dist/core/registry-workflow-manifest.d.ts +122 -0
  317. package/dist/core/registry-workflow-manifest.js +92 -0
  318. package/dist/core/source/errors.d.ts +55 -0
  319. package/dist/core/source/errors.js +13 -0
  320. package/dist/core/source/index.d.ts +19 -0
  321. package/dist/core/source/index.js +4 -0
  322. package/dist/core/source/resolvers.d.ts +45 -0
  323. package/dist/core/source/resolvers.js +9 -0
  324. package/dist/core/source/types.d.ts +211 -0
  325. package/dist/core/source/types.js +0 -0
  326. package/dist/core/source/validate.d.ts +91 -0
  327. package/dist/core/source/validate.js +62 -0
  328. package/dist/core/source/workflow-source.d.ts +43 -0
  329. package/dist/core/source/workflow-source.js +16 -0
  330. package/dist/core/types/checkpoint.d.ts +14 -0
  331. package/dist/core/types/schedules.d.ts +52 -1
  332. package/dist/core/types/state.d.ts +16 -0
  333. package/dist/core/types/workflow-registries.d.ts +7 -0
  334. package/dist/core/types/workflow-registry.d.ts +12 -0
  335. package/dist/core/versioning.js +2 -0
  336. package/dist/core/weft-error.d.ts +1 -1
  337. package/dist/core/weft-error.js +12 -1
  338. package/dist/core/worker-execution-strategy.d.ts +1 -0
  339. package/dist/core/worker-execution-strategy.js +13 -1
  340. package/dist/core/worker-fault-handling.d.ts +10 -0
  341. package/dist/core/worker-fault-handling.js +1 -0
  342. package/dist/core/worker-inbound-message.d.ts +1 -0
  343. package/dist/core/worker-inbound-message.js +1 -0
  344. package/dist/core/worker-protocol-guard.js +4 -0
  345. package/dist/core/worker-protocol.d.ts +7 -0
  346. package/dist/core/worker-protocol.js +2 -1
  347. package/dist/core/worker-turn-watchdog.d.ts +8 -1
  348. package/dist/core/worker-turn-watchdog.js +3 -2
  349. package/dist/diagnostics/format.js +5 -0
  350. package/dist/diagnostics/types.d.ts +24 -0
  351. package/dist/diagnostics/version-check.js +8 -2
  352. package/dist/http.js +2 -2
  353. package/dist/index.d.ts +25 -4
  354. package/dist/index.js +57 -0
  355. package/dist/indexeddb.js +1 -1
  356. package/dist/json-schema.js +3 -3
  357. package/dist/mcp/resources.js +2 -0
  358. package/dist/runtime/portable.d.ts +9 -1
  359. package/dist/server/fault-to-json-rpc.js +4 -1
  360. package/dist/server/handler/auth-context-principal.js +4 -0
  361. package/dist/server/index.d.ts +11 -0
  362. package/dist/server/json-rpc-http.js +2 -0
  363. package/dist/server/json-rpc-websocket.js +6 -4
  364. package/dist/server/operation-catalog/index.d.ts +1 -1
  365. package/dist/server/operation-catalog/pipeline-helpers.js +2 -0
  366. package/dist/server/operation-catalog/types.d.ts +17 -0
  367. package/dist/server/operation-fault.d.ts +5 -0
  368. package/dist/server/operation-fault.js +4 -1
  369. package/dist/server/operations/activate-workflow-revision.d.ts +30 -0
  370. package/dist/server/operations/activate-workflow-revision.js +69 -0
  371. package/dist/server/operations/create-schedule.d.ts +2 -0
  372. package/dist/server/operations/create-schedule.js +10 -6
  373. package/dist/server/operations/fleet-events-subscription.js +1 -1
  374. package/dist/server/operations/fork-workflow.js +1 -1
  375. package/dist/server/operations/get-active-workflow-revision.d.ts +32 -0
  376. package/dist/server/operations/get-active-workflow-revision.js +46 -0
  377. package/dist/server/operations/get-catalog-diagnostics.d.ts +113 -0
  378. package/dist/server/operations/get-catalog-diagnostics.js +65 -0
  379. package/dist/server/operations/get-registry.js +17 -4
  380. package/dist/server/operations/get-task-detail-schema.d.ts +8 -0
  381. package/dist/server/operations/get-task-detail-schema.js +1 -0
  382. package/dist/server/operations/get-task-detail.d.ts +8 -0
  383. package/dist/server/operations/get-task-detail.js +1 -0
  384. package/dist/server/operations/get-task-diagnostics.d.ts +4 -4
  385. package/dist/server/operations/get-workflow-revision.d.ts +25 -0
  386. package/dist/server/operations/get-workflow-revision.js +50 -0
  387. package/dist/server/operations/install-workflow-revision.d.ts +27 -0
  388. package/dist/server/operations/install-workflow-revision.js +46 -0
  389. package/dist/server/operations/list-workflow-revisions.d.ts +20 -0
  390. package/dist/server/operations/list-workflow-revisions.js +40 -0
  391. package/dist/server/operations/preload-workflow-revision.d.ts +28 -0
  392. package/dist/server/operations/preload-workflow-revision.js +60 -0
  393. package/dist/server/operations/schedule-faults.d.ts +1 -0
  394. package/dist/server/operations/schedule-faults.js +32 -4
  395. package/dist/server/operations/schedule-rest-body.d.ts +1 -0
  396. package/dist/server/operations/schedule-rest-body.js +2 -1
  397. package/dist/server/operations/start-or-signal-workflow.js +1 -1
  398. package/dist/server/operations/start-workflow.js +1 -1
  399. package/dist/server/operations/static-registrations.js +42 -0
  400. package/dist/server/operations/storage.js +2 -2
  401. package/dist/server/operations/submit-review-decision.js +1 -1
  402. package/dist/server/operations/update-schedule.d.ts +2 -0
  403. package/dist/server/operations/update-schedule.js +4 -2
  404. package/dist/server/operations/workflow-catalog-operation-helpers.d.ts +59 -0
  405. package/dist/server/operations/workflow-catalog-operation-helpers.js +162 -0
  406. package/dist/server/runtime/task-dispatch-envelope.d.ts +14 -0
  407. package/dist/server/runtime/task-dispatch-envelope.js +32 -0
  408. package/dist/server/runtime/task-dispatch-revision.d.ts +29 -0
  409. package/dist/server/runtime/task-dispatch-revision.js +13 -0
  410. package/dist/server/runtime/task-dispatch.js +12 -37
  411. package/dist/server/runtime/task-ledger-recovery.js +1 -1
  412. package/dist/server/runtime/task-ledger-runtime.d.ts +14 -2
  413. package/dist/server/runtime/task-ledger-runtime.js +5 -3
  414. package/dist/server/runtime/task-polling.js +9 -3
  415. package/dist/server/runtime/task-reconciliation.js +2 -1
  416. package/dist/server/runtime/websocket-upgrade.js +2 -0
  417. package/dist/server/runtime/websocket-worker.js +9 -0
  418. package/dist/server/task-ledger-codec.d.ts +9 -0
  419. package/dist/server/task-ledger-codec.js +4 -1
  420. package/dist/server/task-ledger-transition-helpers.js +1 -0
  421. package/dist/server/task-ledger-types.d.ts +9 -0
  422. package/dist/server/task-ledger.d.ts +1 -1
  423. package/dist/server/task-ledger.js +2 -1
  424. package/dist/server/task-queue-types.d.ts +2 -0
  425. package/dist/storage/bun-sql.js +51 -6
  426. package/dist/storage/catalog-keys.d.ts +64 -0
  427. package/dist/storage/catalog-keys.js +8 -0
  428. package/dist/storage/compressed-storage.js +1 -1
  429. package/dist/storage/derived-operations.js +1 -1
  430. package/dist/storage/index.d.ts +28 -1
  431. package/dist/storage/interface.d.ts +28 -1
  432. package/dist/storage/interface.js +1 -1
  433. package/dist/storage/key-encoding.d.ts +15 -0
  434. package/dist/storage/key-encoding.js +3 -0
  435. package/dist/storage/key-prefixes.d.ts +1 -1
  436. package/dist/storage/key-prefixes.js +16 -0
  437. package/dist/storage/lmdb.d.ts +54 -1
  438. package/dist/storage/lmdb.js +1 -1
  439. package/dist/storage/mailbox-keys.d.ts +80 -0
  440. package/dist/storage/mailbox-keys.js +14 -0
  441. package/dist/storage/memory.js +1 -1
  442. package/dist/storage/neon.js +2 -2
  443. package/dist/storage/node-sqlite-loader.d.ts +1 -1
  444. package/dist/storage/node-sqlite.js +51 -6
  445. package/dist/storage/outbox-keys.d.ts +77 -0
  446. package/dist/storage/outbox-keys.js +14 -0
  447. package/dist/storage/postgres.js +2 -2
  448. package/dist/storage/resolve.js +1 -1
  449. package/dist/storage/scoped-storage.js +1 -1
  450. package/dist/storage/storage-configuration.d.ts +6 -0
  451. package/dist/storage/testing.js +1 -1
  452. package/dist/storage/turso.js +2 -2
  453. package/dist/version.d.ts +1 -1
  454. package/dist/version.js +1 -1
  455. package/dist/web-extension.js +1 -1
  456. package/dist/worker/manifest/registry-contract-builder.d.ts +21 -3
  457. package/dist/worker/manifest/registry-contract-builder.js +40 -31
  458. package/dist/worker/protocol-messages.d.ts +17 -0
  459. package/dist/worker/protocol-schemas.d.ts +32 -0
  460. package/dist/worker/protocol-schemas.js +7 -3
  461. package/dist/worker/protocol-task-result.js +35 -3
  462. package/dist/worker/protocol.js +1 -1
  463. package/dist/worker/registry/types.d.ts +2 -0
  464. package/dist/worker/registry.d.ts +1 -1
  465. package/dist/worker/registry.js +3 -1
  466. package/dist/workers/workflow-runner.d.ts +9 -0
  467. package/dist/workers/workflow-runner.js +9 -2
  468. package/dist/workers/workflow-worker-entry.js +9 -4
  469. package/package.json +2 -2
@@ -0,0 +1,406 @@
1
+ /**
2
+ * Record and public contract types for the durable application command mailbox
3
+ * (WFT-84).
4
+ *
5
+ * A mailbox is scoped by an opaque `(namespace, resourceId)` pair. Weft never
6
+ * interprets either component: they are application identity, not workflow
7
+ * identity, and nothing here is a remote-worker protocol record. The remote task
8
+ * ledger's transition vocabulary (`server/task-ledger-types.ts`) is deliberately
9
+ * mirrored where it fits — `generation`, attempt fencing, whole-record CAS — but
10
+ * the two record families stay independent so a worker protocol change cannot
11
+ * reshape an application receipt.
12
+ *
13
+ * This module defines shapes only. It reads no storage and performs no
14
+ * transitions; `mailbox-transitions.ts` owns the legality rules and
15
+ * `mailbox.ts` owns the commits.
16
+ *
17
+ * @module core/mailbox-types
18
+ */
19
+ import type { JSONValue } from './json.ts';
20
+ /** Current persisted record version for every mailbox record. */
21
+ export declare const MAILBOX_RECORD_VERSION = 1;
22
+ /**
23
+ * A command payload carried inline in the durable record.
24
+ *
25
+ * `value` is encoded with Weft's structured-clone codec, so `Uint8Array`,
26
+ * `Map`, `Set`, and `Date` round-trip verbatim. Opaque multimodal and
27
+ * managed-asset references survive as whatever value the application put in —
28
+ * nothing is coerced to text.
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * import type { ApplicationCommandInlinePayload } from '@lostgradient/weft';
33
+ *
34
+ * const payload: ApplicationCommandInlinePayload = {
35
+ * form: 'inline',
36
+ * value: { prompt: 'summarize', attachment: new Uint8Array([1, 2, 3]) },
37
+ * };
38
+ * console.log(payload.form); // 'inline'
39
+ * ```
40
+ */
41
+ export type ApplicationCommandInlinePayload = Readonly<{
42
+ form: 'inline';
43
+ value: unknown;
44
+ }>;
45
+ /**
46
+ * A command payload held outside the mailbox behind a content-addressed
47
+ * reference the application resolves itself.
48
+ *
49
+ * Weft stores the locator and the caller-supplied `digest` verbatim and never
50
+ * dereferences either, so it cannot verify that remote content still matches.
51
+ * `digest` is required precisely because the mailbox has no other way to bind
52
+ * idempotency to payload identity for this form.
53
+ *
54
+ * @example
55
+ * ```ts
56
+ * import type { ApplicationCommandReferencePayload } from '@lostgradient/weft';
57
+ *
58
+ * const payload: ApplicationCommandReferencePayload = {
59
+ * form: 'reference',
60
+ * reference: 's3://assets/9f2c',
61
+ * digest: 'a'.repeat(64),
62
+ * };
63
+ * console.log(payload.reference); // 's3://assets/9f2c'
64
+ * ```
65
+ */
66
+ export type ApplicationCommandReferencePayload = Readonly<{
67
+ form: 'reference';
68
+ reference: string;
69
+ digest: string;
70
+ byteLength?: number | undefined;
71
+ }>;
72
+ /**
73
+ * Either payload form a command may carry.
74
+ *
75
+ * @example
76
+ * ```ts
77
+ * import type { ApplicationCommandPayload } from '@lostgradient/weft';
78
+ *
79
+ * const payload: ApplicationCommandPayload = { form: 'inline', value: { ok: true } };
80
+ * console.log(payload.form === 'inline'); // true
81
+ * ```
82
+ */
83
+ export type ApplicationCommandPayload = ApplicationCommandInlinePayload | ApplicationCommandReferencePayload;
84
+ /**
85
+ * Bounded causal metadata linking a command to whatever produced it.
86
+ *
87
+ * @example
88
+ * ```ts
89
+ * import type { ApplicationCommandCausation } from '@lostgradient/weft';
90
+ *
91
+ * const causation: ApplicationCommandCausation = { correlationId: 'conv-7' };
92
+ * console.log(causation.correlationId); // 'conv-7'
93
+ * ```
94
+ */
95
+ export type ApplicationCommandCausation = Readonly<{
96
+ correlationId?: string | undefined;
97
+ causationId?: string | undefined;
98
+ traceparent?: string | undefined;
99
+ }>;
100
+ /**
101
+ * Every disposition a command record can occupy.
102
+ *
103
+ * `accepted` means admitted and durable but not yet released for delivery —
104
+ * either an initial delay or a retry backoff. `available` means released and
105
+ * claimable. The four terminal states never transition again.
106
+ *
107
+ * @example
108
+ * ```ts
109
+ * import type { ApplicationCommandState } from '@lostgradient/weft';
110
+ *
111
+ * const state: ApplicationCommandState = 'available';
112
+ * console.log(state); // 'available'
113
+ * ```
114
+ */
115
+ export type ApplicationCommandState = 'accepted' | 'available' | 'claimed' | 'cancellation-requested' | 'applied' | 'rejected' | 'cancelled' | 'dead-lettered';
116
+ /** The four dispositions from which no further transition is legal. */
117
+ export declare const APPLICATION_COMMAND_TERMINAL_STATES: readonly ["applied", "rejected", "cancelled", "dead-lettered"];
118
+ /**
119
+ * A terminal command disposition.
120
+ *
121
+ * @example
122
+ * ```ts
123
+ * import type { ApplicationCommandTerminalState } from '@lostgradient/weft';
124
+ *
125
+ * const state: ApplicationCommandTerminalState = 'applied';
126
+ * console.log(state); // 'applied'
127
+ * ```
128
+ */
129
+ export type ApplicationCommandTerminalState = (typeof APPLICATION_COMMAND_TERMINAL_STATES)[number];
130
+ /**
131
+ * Why a command reached a non-success terminal state. Stable, low-cardinality,
132
+ * and safe to branch on.
133
+ *
134
+ * @example
135
+ * ```ts
136
+ * import type { ApplicationCommandFailureReason } from '@lostgradient/weft';
137
+ *
138
+ * const reason: ApplicationCommandFailureReason = 'deadline-exceeded';
139
+ * console.log(reason); // 'deadline-exceeded'
140
+ * ```
141
+ */
142
+ export type ApplicationCommandFailureReason = 'application' | 'attempts-exhausted' | 'deadline-exceeded' | 'cancelled';
143
+ /**
144
+ * Bounded terminal evidence retained on a failed, cancelled, or dead-lettered
145
+ * receipt.
146
+ *
147
+ * @example
148
+ * ```ts
149
+ * import type { ApplicationCommandFailure } from '@lostgradient/weft';
150
+ *
151
+ * const failure: ApplicationCommandFailure = { reason: 'application', message: 'unsupported kind' };
152
+ * console.log(failure.reason); // 'application'
153
+ * ```
154
+ */
155
+ export type ApplicationCommandFailure = Readonly<{
156
+ reason: ApplicationCommandFailureReason;
157
+ message?: string | undefined;
158
+ details?: JSONValue | undefined;
159
+ }>;
160
+ /**
161
+ * Fields every command record carries in every state — the identity and policy
162
+ * fixed at admission that no transition may rewrite.
163
+ *
164
+ * `sequence` is the mailbox-scoped FIFO position assigned at admission. It is
165
+ * never reassigned, so a redelivered command re-enters the delivery index at
166
+ * the position it was first admitted to.
167
+ *
168
+ * `absoluteDeadlineAt` is the wall-clock ceiling for the whole command across
169
+ * every attempt. Claim renewal clamps to it and can never move it.
170
+ */
171
+ export type ApplicationCommandBase = Readonly<{
172
+ recordVersion: typeof MAILBOX_RECORD_VERSION;
173
+ namespace: string;
174
+ resourceId: string;
175
+ commandId: string;
176
+ sequence: number;
177
+ idempotencyKey?: string | undefined;
178
+ caller: string;
179
+ target: string;
180
+ kind: string;
181
+ payload: ApplicationCommandPayload;
182
+ payloadDigest: string;
183
+ payloadMediaType?: string | undefined;
184
+ payloadSchema?: string | undefined;
185
+ causation?: ApplicationCommandCausation | undefined;
186
+ acceptedAt: number;
187
+ absoluteDeadlineAt: number;
188
+ maxAttempts: number;
189
+ visibilityTimeoutMs: number;
190
+ /** Monotonic transition counter. Diagnostic provenance; whole-record byte equality is the real fence. */
191
+ generation: number;
192
+ }>;
193
+ /** Attempt provenance preserved across claim, expiry, retry, and recovery. */
194
+ export type ApplicationCommandAttemptFields = Readonly<{
195
+ /** Number of claims issued so far. `0` until the first claim. */
196
+ attempt: number;
197
+ /** Number of redeliveries caused by rejection-with-retry or visibility expiry. */
198
+ retryCount: number;
199
+ /** First time any attempt claimed this command. Absent until the first claim. */
200
+ firstClaimedAt?: number | undefined;
201
+ }>;
202
+ /** A command admitted but not yet released for delivery (initial delay or retry backoff).
203
+ *
204
+ * @example
205
+ * ```ts
206
+ * import type { ApplicationCommandAccepted } from '@lostgradient/weft';
207
+ *
208
+ * declare const record: ApplicationCommandAccepted;
209
+ * console.log(record.state, record.availableAt); // 'accepted', when it is released
210
+ * ```
211
+ */
212
+ export type ApplicationCommandAccepted = ApplicationCommandBase & ApplicationCommandAttemptFields & Readonly<{
213
+ state: 'accepted';
214
+ availableAt: number;
215
+ }>;
216
+ /** A command released for delivery and waiting at its FIFO position.
217
+ *
218
+ * @example
219
+ * ```ts
220
+ * import type { ApplicationCommandAvailable } from '@lostgradient/weft';
221
+ *
222
+ * declare const record: ApplicationCommandAvailable;
223
+ * console.log(record.state); // 'available'
224
+ * ```
225
+ */
226
+ export type ApplicationCommandAvailable = ApplicationCommandBase & ApplicationCommandAttemptFields & Readonly<{
227
+ state: 'available';
228
+ availableAt: number;
229
+ }>;
230
+ /** Lease fields held while one attempt owns a command. */
231
+ export type ApplicationCommandLeaseFields = Readonly<{
232
+ /** Opaque per-attempt fencing token. Every mutation from a claimant must present it. */
233
+ attemptToken: string;
234
+ claimedAt: number;
235
+ /** When an unrenewed claim becomes reclaimable. Never later than `absoluteDeadlineAt`. */
236
+ visibilityExpiresAt: number;
237
+ /** Latest liveness evidence from the claimant. Distinct from semantic progress. */
238
+ lastActivityAt: number;
239
+ /** Optional bounded, caller-supplied progress marker. Never used for fencing. */
240
+ progress?: JSONValue | undefined;
241
+ }>;
242
+ /** A command leased by a live attempt.
243
+ *
244
+ * @example
245
+ * ```ts
246
+ * import type { ApplicationCommandClaimed } from '@lostgradient/weft';
247
+ *
248
+ * declare const record: ApplicationCommandClaimed;
249
+ * console.log(record.attemptToken, record.visibilityExpiresAt);
250
+ * ```
251
+ */
252
+ export type ApplicationCommandClaimed = ApplicationCommandBase & ApplicationCommandAttemptFields & ApplicationCommandLeaseFields & Readonly<{
253
+ state: 'claimed';
254
+ availableAt: number;
255
+ }>;
256
+ /**
257
+ * A claimed command whose cancellation is durably requested and whose claimant
258
+ * has not yet settled. The lease stays intact so the current attempt — and only
259
+ * the current attempt — can finish cleanup.
260
+ *
261
+ * @example
262
+ * ```ts
263
+ * import type { ApplicationCommandCancelling } from '@lostgradient/weft';
264
+ *
265
+ * declare const record: ApplicationCommandCancelling;
266
+ * console.log(record.cancellationRequestedAt);
267
+ * ```
268
+ */
269
+ export type ApplicationCommandCancelling = ApplicationCommandBase & ApplicationCommandAttemptFields & ApplicationCommandLeaseFields & Readonly<{
270
+ state: 'cancellation-requested';
271
+ availableAt: number;
272
+ cancellationRequestedAt: number;
273
+ cancellationReason?: string | undefined;
274
+ }>;
275
+ /**
276
+ * A command in a terminal disposition.
277
+ *
278
+ * `cleanupPending` is `true` when the command reached this disposition while an
279
+ * attempt still held it and that attempt never settled: a cancellation whose
280
+ * claimant never finished cleanup (`cancelled`), a final attempt whose lease
281
+ * expired (`dead-lettered`, `attempts-exhausted`), or a claimed command that
282
+ * crossed its absolute deadline (`dead-lettered`, `deadline-exceeded`).
283
+ * `abandonedAttemptToken` names that attempt. The mailbox records that it
284
+ * stopped waiting, never that the handler stopped.
285
+ *
286
+ * @example
287
+ * ```ts
288
+ * import type { ApplicationCommandTerminalRecord } from '@lostgradient/weft';
289
+ *
290
+ * declare const record: ApplicationCommandTerminalRecord;
291
+ * console.log(record.state, record.terminalAt);
292
+ * ```
293
+ */
294
+ export type ApplicationCommandTerminalRecord = ApplicationCommandBase & ApplicationCommandAttemptFields & Readonly<{
295
+ state: ApplicationCommandTerminalState;
296
+ availableAt: number;
297
+ terminalAt: number;
298
+ outcome?: JSONValue | undefined;
299
+ failure?: ApplicationCommandFailure | undefined;
300
+ cancellationRequestedAt?: number | undefined;
301
+ cancellationReason?: string | undefined;
302
+ cleanupPending?: boolean | undefined;
303
+ /** Attempt token of the lease that was still open when the command terminalized. */
304
+ abandonedAttemptToken?: string | undefined;
305
+ }>;
306
+ /**
307
+ * The canonical durable record for one command, in whichever state it currently
308
+ * occupies.
309
+ *
310
+ * @example
311
+ * ```ts
312
+ * import type { ApplicationCommandRecord } from '@lostgradient/weft';
313
+ *
314
+ * declare const record: ApplicationCommandRecord;
315
+ * console.log(record.commandId, record.state);
316
+ * ```
317
+ */
318
+ export type ApplicationCommandRecord = ApplicationCommandAccepted | ApplicationCommandAvailable | ApplicationCommandClaimed | ApplicationCommandCancelling | ApplicationCommandTerminalRecord;
319
+ /** Any record still holding a lease.
320
+ *
321
+ * @example
322
+ * ```ts
323
+ * import type { ApplicationCommandLeasedRecord } from '@lostgradient/weft';
324
+ *
325
+ * declare const record: ApplicationCommandLeasedRecord;
326
+ * console.log(record.attemptToken);
327
+ * ```
328
+ */
329
+ export type ApplicationCommandLeasedRecord = ApplicationCommandClaimed | ApplicationCommandCancelling;
330
+ /** Any record waiting in the delivery index.
331
+ *
332
+ * @example
333
+ * ```ts
334
+ * import type { ApplicationCommandWaitingRecord } from '@lostgradient/weft';
335
+ *
336
+ * declare const record: ApplicationCommandWaitingRecord;
337
+ * console.log(record.availableAt);
338
+ * ```
339
+ */
340
+ export type ApplicationCommandWaitingRecord = ApplicationCommandAccepted | ApplicationCommandAvailable;
341
+ /**
342
+ * The per-mailbox header holding the FIFO sequence allocator and the
343
+ * open-backlog counter admission backpressure reads.
344
+ *
345
+ * @example
346
+ * ```ts
347
+ * import type { MailboxRecord } from '@lostgradient/weft';
348
+ *
349
+ * declare const header: MailboxRecord;
350
+ * console.log(header.nextSequence, header.openCount);
351
+ * ```
352
+ */
353
+ export type MailboxRecord = Readonly<{
354
+ recordVersion: typeof MAILBOX_RECORD_VERSION;
355
+ namespace: string;
356
+ resourceId: string;
357
+ /** Sequence assigned to the next admitted command. */
358
+ nextSequence: number;
359
+ /** Commands admitted and not yet terminal. */
360
+ openCount: number;
361
+ /** Lifetime admissions. Never decremented; diagnostic provenance only. */
362
+ admittedCount: number;
363
+ }>;
364
+ /** The idempotency index record binding a retry identity to one admitted command. */
365
+ export type ApplicationCommandIdempotencyRecord = Readonly<{
366
+ recordVersion: typeof MAILBOX_RECORD_VERSION;
367
+ commandId: string;
368
+ /** The digest of `(caller, target, kind, payloadDigest)` this key is bound to. */
369
+ identityDigest: string;
370
+ }>;
371
+ /**
372
+ * Whether a command state is terminal.
373
+ *
374
+ * @example
375
+ * ```ts
376
+ * import { isApplicationCommandTerminalState } from '@lostgradient/weft';
377
+ *
378
+ * console.log(isApplicationCommandTerminalState('applied')); // true
379
+ * console.log(isApplicationCommandTerminalState('claimed')); // false
380
+ * ```
381
+ */
382
+ export declare function isApplicationCommandTerminalState(state: string): state is ApplicationCommandTerminalState;
383
+ /**
384
+ * Whether a record still holds an attempt lease.
385
+ *
386
+ * @example
387
+ * ```ts
388
+ * import { isApplicationCommandLeased, type ApplicationCommandRecord } from '@lostgradient/weft';
389
+ *
390
+ * declare const record: ApplicationCommandRecord;
391
+ * if (isApplicationCommandLeased(record)) console.log(record.attemptToken);
392
+ * ```
393
+ */
394
+ export declare function isApplicationCommandLeased(record: ApplicationCommandRecord): record is ApplicationCommandLeasedRecord;
395
+ /**
396
+ * Whether a record is waiting in the delivery index.
397
+ *
398
+ * @example
399
+ * ```ts
400
+ * import { isApplicationCommandWaiting, type ApplicationCommandRecord } from '@lostgradient/weft';
401
+ *
402
+ * declare const record: ApplicationCommandRecord;
403
+ * if (isApplicationCommandWaiting(record)) console.log(record.availableAt);
404
+ * ```
405
+ */
406
+ export declare function isApplicationCommandWaiting(record: ApplicationCommandRecord): record is ApplicationCommandWaitingRecord;
@@ -0,0 +1,16 @@
1
+ export const MAILBOX_RECORD_VERSION = 1, APPLICATION_COMMAND_TERMINAL_STATES = [
2
+ "applied",
3
+ "rejected",
4
+ "cancelled",
5
+ "dead-lettered"
6
+ ];
7
+ const TERMINAL_STATE_SET = new Set(APPLICATION_COMMAND_TERMINAL_STATES);
8
+ export function isApplicationCommandTerminalState(state) {
9
+ return TERMINAL_STATE_SET.has(state);
10
+ }
11
+ export function isApplicationCommandLeased(record) {
12
+ return record.state === "claimed" || record.state === "cancellation-requested";
13
+ }
14
+ export function isApplicationCommandWaiting(record) {
15
+ return record.state === "accepted" || record.state === "available";
16
+ }
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Bounds and input validation for the durable application command mailbox
3
+ * (WFT-84).
4
+ *
5
+ * Every bound here exists so a hostile or buggy caller cannot grow durable
6
+ * storage without limit or push an unbounded string into a storage key. The
7
+ * mailbox validates at admission — before any write — so a rejected command
8
+ * leaves no trace.
9
+ *
10
+ * @module core/mailbox-validation
11
+ */
12
+ import type { ApplicationCommandInput, MailboxOptions } from './mailbox-contract.ts';
13
+ import type { ApplicationCommandPayload } from './mailbox-types.ts';
14
+ /** Mailbox defaults resolved once at construction. */
15
+ export type ResolvedMailboxPolicy = Readonly<{
16
+ namespace: string;
17
+ resourceId: string;
18
+ maxBacklog: number;
19
+ visibilityTimeoutMs: number;
20
+ commandTimeoutMs: number;
21
+ maxAttempts: number;
22
+ retryBackoffMs: number;
23
+ maxRetryBackoffMs: number;
24
+ terminalRetentionMs: number;
25
+ maxInlinePayloadBytes: number;
26
+ maintenanceBatchSize: number;
27
+ }>;
28
+ /**
29
+ * Resolve and range-check the mailbox construction options.
30
+ *
31
+ * @throws {ApplicationCommandValidationError} When any option is out of range.
32
+ */
33
+ export declare function resolveMailboxPolicy(options: MailboxOptions): ResolvedMailboxPolicy;
34
+ /** A validated command input with its digest and effective per-command policy resolved. */
35
+ export type ValidatedCommandInput = Readonly<{
36
+ caller: string;
37
+ target: string;
38
+ kind: string;
39
+ payload: ApplicationCommandPayload;
40
+ payloadDigest: string;
41
+ payloadMediaType?: string | undefined;
42
+ payloadSchema?: string | undefined;
43
+ idempotencyKey?: string | undefined;
44
+ causation?: ApplicationCommandInput['causation'] | undefined;
45
+ availableAfterMs: number;
46
+ maxAttempts: number;
47
+ visibilityTimeoutMs: number;
48
+ commandTimeoutMs: number;
49
+ }>;
50
+ /**
51
+ * Validate one command offered for admission and resolve its effective policy.
52
+ *
53
+ * @throws {ApplicationCommandValidationError} When any field is missing,
54
+ * oversized, or out of range.
55
+ */
56
+ export declare function validateCommandInput(input: ApplicationCommandInput, policy: ResolvedMailboxPolicy): Promise<ValidatedCommandInput>;
57
+ export { ApplicationCommandValidationError, clampListLimit, DEFAULT_WAIT_POLL_INTERVAL_MS, MAX_APPLICATION_COMMAND_ATTEMPTS, MAX_APPLICATION_IDEMPOTENCY_KEY_BYTES, MAX_APPLICATION_IDENTITY_BYTES, MAX_APPLICATION_PAYLOAD_REFERENCE_BYTES, MAX_CANCELLATION_REASON_BYTES, MAX_FAILURE_MESSAGE_BYTES, MAX_MAILBOX_BACKLOG, MAX_MAILBOX_LIST_LIMIT, requireClockInstant, requireDerivedInstant, requireGeneratedIdentifier, requireMaintenanceInstant, requireWaitBudget, validateCancellationReason, validateDurableJSONValue, validateFailure, } from './mailbox-guards.ts';
58
+ /**
59
+ * Validate a caller-supplied command id before it reaches key construction.
60
+ *
61
+ * Every command-scoped operation builds a storage key from this value, and
62
+ * `encodeURIComponent` throws a raw `URIError` on an unpaired surrogate; the
63
+ * contract says caller mistakes surface as `ApplicationCommandValidationError`.
64
+ */
65
+ export declare function validateCommandIdentifier(commandId: unknown): string;
@@ -0,0 +1,73 @@
1
+ import { createPayloadValidators } from "./application-primitive-payload.js";
2
+ import {
3
+ ApplicationCommandValidationError,
4
+ MAX_APPLICATION_COMMAND_ATTEMPTS,
5
+ MAX_APPLICATION_IDEMPOTENCY_KEY_BYTES,
6
+ MAX_APPLICATION_IDENTITY_BYTES,
7
+ MAX_MAILBOX_BACKLOG,
8
+ optionalIdentityOf,
9
+ requireIdentity,
10
+ requireNonNegativeInteger,
11
+ requirePositiveInteger
12
+ } from "./mailbox-guards.js";
13
+ const ONE_HOUR_MS = 3600000, ONE_DAY_MS = 86400000, MAX_DURATION_MS = 31536000000;
14
+ export function resolveMailboxPolicy(options) {
15
+ return {
16
+ namespace: requireIdentity(options.namespace, "namespace", MAX_APPLICATION_IDENTITY_BYTES),
17
+ resourceId: requireIdentity(options.resourceId, "resourceId", MAX_APPLICATION_IDENTITY_BYTES),
18
+ maxBacklog: requirePositiveInteger(options.maxBacklog ?? 1000, "maxBacklog", MAX_MAILBOX_BACKLOG),
19
+ visibilityTimeoutMs: requirePositiveInteger(options.visibilityTimeoutMs ?? 30000, "visibilityTimeoutMs", MAX_DURATION_MS),
20
+ commandTimeoutMs: requirePositiveInteger(options.commandTimeoutMs ?? ONE_HOUR_MS, "commandTimeoutMs", MAX_DURATION_MS),
21
+ maxAttempts: requirePositiveInteger(options.maxAttempts ?? 3, "maxAttempts", MAX_APPLICATION_COMMAND_ATTEMPTS),
22
+ retryBackoffMs: requirePositiveInteger(options.retryBackoffMs ?? 1000, "retryBackoffMs", MAX_DURATION_MS),
23
+ maxRetryBackoffMs: requirePositiveInteger(options.maxRetryBackoffMs ?? 60000, "maxRetryBackoffMs", MAX_DURATION_MS),
24
+ terminalRetentionMs: requirePositiveInteger(options.terminalRetentionMs ?? ONE_DAY_MS, "terminalRetentionMs", MAX_DURATION_MS),
25
+ maxInlinePayloadBytes: requirePositiveInteger(options.maxInlinePayloadBytes ?? 262144, "maxInlinePayloadBytes", 67108864),
26
+ maintenanceBatchSize: requirePositiveInteger(options.maintenanceBatchSize ?? 500, "maintenanceBatchSize", 1e4)
27
+ };
28
+ }
29
+ const { validatePayload, validateCausation } = createPayloadValidators(ApplicationCommandValidationError);
30
+ export async function validateCommandInput(input, policy) {
31
+ if (typeof input !== "object" || input === null)
32
+ throw new ApplicationCommandValidationError("command must be an object.");
33
+ const { payload, digest } = await validatePayload(input.payload, policy.maxInlinePayloadBytes);
34
+ return {
35
+ caller: requireIdentity(input.caller, "caller", MAX_APPLICATION_IDENTITY_BYTES),
36
+ target: requireIdentity(input.target, "target", MAX_APPLICATION_IDENTITY_BYTES),
37
+ kind: requireIdentity(input.kind, "kind", MAX_APPLICATION_IDENTITY_BYTES),
38
+ payload,
39
+ payloadDigest: digest,
40
+ payloadMediaType: optionalIdentityOf(input.payloadMediaType, "payloadMediaType", MAX_APPLICATION_IDENTITY_BYTES),
41
+ payloadSchema: optionalIdentityOf(input.payloadSchema, "payloadSchema", MAX_APPLICATION_IDENTITY_BYTES),
42
+ idempotencyKey: optionalIdentityOf(input.idempotencyKey, "idempotencyKey", MAX_APPLICATION_IDEMPOTENCY_KEY_BYTES),
43
+ causation: validateCausation(input.causation),
44
+ availableAfterMs: requireNonNegativeInteger(input.availableAfterMs ?? 0, "availableAfterMs", MAX_DURATION_MS),
45
+ maxAttempts: requirePositiveInteger(input.maxAttempts ?? policy.maxAttempts, "maxAttempts", MAX_APPLICATION_COMMAND_ATTEMPTS),
46
+ visibilityTimeoutMs: requirePositiveInteger(input.visibilityTimeoutMs ?? policy.visibilityTimeoutMs, "visibilityTimeoutMs", MAX_DURATION_MS),
47
+ commandTimeoutMs: requirePositiveInteger(input.commandTimeoutMs ?? policy.commandTimeoutMs, "commandTimeoutMs", MAX_DURATION_MS)
48
+ };
49
+ }
50
+ export {
51
+ ApplicationCommandValidationError,
52
+ clampListLimit,
53
+ DEFAULT_WAIT_POLL_INTERVAL_MS,
54
+ MAX_APPLICATION_COMMAND_ATTEMPTS,
55
+ MAX_APPLICATION_IDEMPOTENCY_KEY_BYTES,
56
+ MAX_APPLICATION_IDENTITY_BYTES,
57
+ MAX_APPLICATION_PAYLOAD_REFERENCE_BYTES,
58
+ MAX_CANCELLATION_REASON_BYTES,
59
+ MAX_FAILURE_MESSAGE_BYTES,
60
+ MAX_MAILBOX_BACKLOG,
61
+ MAX_MAILBOX_LIST_LIMIT,
62
+ requireClockInstant,
63
+ requireDerivedInstant,
64
+ requireGeneratedIdentifier,
65
+ requireMaintenanceInstant,
66
+ requireWaitBudget,
67
+ validateCancellationReason,
68
+ validateDurableJSONValue,
69
+ validateFailure
70
+ } from "./mailbox-guards.js";
71
+ export function validateCommandIdentifier(commandId) {
72
+ return requireIdentity(commandId, "commandId", MAX_APPLICATION_IDENTITY_BYTES);
73
+ }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * The abortable, bounded waits the application command mailbox exposes
3
+ * (WFT-84): waiting for work to become due, and waiting for a cancelled
4
+ * command's claimant to settle.
5
+ *
6
+ * Both are polling waits. Cross-process wakeup has no push channel — another
7
+ * process's admission is only visible in durable storage — so a poll is the
8
+ * honest mechanism rather than a subscription that would silently miss remote
9
+ * work. Every wait is bounded by a caller-supplied deadline, respects a
10
+ * caller-supplied `AbortSignal`, and unwinds cleanly when the mailbox is
11
+ * disposed mid-wait: the timer is cleared and both abort listeners are removed
12
+ * on every settlement path, so no wait can outlive its mailbox.
13
+ *
14
+ * Waiting never claims, starts, or advances durable work.
15
+ *
16
+ * @module core/mailbox-waits
17
+ */
18
+ import { delayUnlessAborted } from './application-primitive-timing.ts';
19
+ import type { ApplicationCommandCleanupResult, MailboxWaitOptions } from './mailbox-contract.ts';
20
+ import type { MailboxRuntime } from './mailbox-internals.ts';
21
+ export { DEFAULT_WAIT_POLL_INTERVAL_MS as DEFAULT_MAILBOX_POLL_INTERVAL_MS } from './mailbox-validation.ts';
22
+ export { delayUnlessAborted };
23
+ /**
24
+ * Whether the FIFO head exists and is claimable right now.
25
+ *
26
+ * The absolute deadline counts as well as availability. A head that is due but
27
+ * already expired is not deliverable — `claim()` would terminalize it and report
28
+ * `empty` — so reporting it as available would advertise work that does not
29
+ * exist.
30
+ */
31
+ export declare function hasDueWork(runtime: MailboxRuntime): Promise<boolean>;
32
+ /**
33
+ * Wait, bounded and abortably, until this mailbox has work due for delivery.
34
+ *
35
+ * Returns `true` when the FIFO head is claimable and `false` when the wait was
36
+ * aborted, the mailbox was disposed, or the timeout elapsed first.
37
+ */
38
+ export declare function waitForAvailableWork(runtime: MailboxRuntime, disposal: AbortSignal, options?: MailboxWaitOptions): Promise<boolean>;
39
+ /**
40
+ * Wait, bounded, for a cancelled command's claimant to settle.
41
+ *
42
+ * A `pending` result means this mailbox stopped waiting — never that the
43
+ * handler stopped.
44
+ */
45
+ export declare function waitForCleanup(runtime: MailboxRuntime, disposal: AbortSignal, options: {
46
+ readonly commandId: string;
47
+ readonly timeoutMs: number;
48
+ readonly signal?: AbortSignal | undefined;
49
+ readonly pollIntervalMs?: number | undefined;
50
+ }): Promise<ApplicationCommandCleanupResult>;