@lostgradient/weft 0.24.1 → 0.24.2

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 (97) hide show
  1. package/README.md +1 -1
  2. package/dist/core/engine/bulk-operations-purge.d.ts +1 -1
  3. package/dist/core/engine/bulk-operations-purge.js +3 -2
  4. package/dist/core/engine/bulk-operations-retry.d.ts +16 -1
  5. package/dist/core/engine/bulk-operations-retry.js +19 -6
  6. package/dist/core/engine/bulk-operations.d.ts +3 -2
  7. package/dist/core/engine/bulk-operations.js +2 -2
  8. package/dist/core/engine/callback-creators-bundles.js +1 -1
  9. package/dist/core/engine/callback-creators-schedule.js +2 -2
  10. package/dist/core/engine/child-workflow.d.ts +13 -1
  11. package/dist/core/engine/child-workflow.js +22 -4
  12. package/dist/core/engine/generation-codec.d.ts +22 -0
  13. package/dist/core/engine/generation-codec.js +2 -0
  14. package/dist/core/engine/index.js +1 -1
  15. package/dist/core/engine/lifecycle/recovery-isolation.d.ts +20 -0
  16. package/dist/core/engine/lifecycle/recovery-isolation.js +26 -0
  17. package/dist/core/engine/lifecycle/resume-body.d.ts +44 -0
  18. package/dist/core/engine/lifecycle/resume-body.js +211 -0
  19. package/dist/core/engine/lifecycle/resume.d.ts +46 -3
  20. package/dist/core/engine/lifecycle/resume.js +21 -210
  21. package/dist/core/engine/lifecycle/standalone-claim-acquire.d.ts +68 -2
  22. package/dist/core/engine/lifecycle/standalone-claim-acquire.js +14 -4
  23. package/dist/core/engine/lifecycle/start-commit.d.ts +2 -0
  24. package/dist/core/engine/lifecycle/start-commit.js +16 -8
  25. package/dist/core/engine/lifecycle/start-or-signal-resolution.d.ts +8 -2
  26. package/dist/core/engine/lifecycle/start-or-signal-resolution.js +11 -3
  27. package/dist/core/engine/lifecycle/start-precondition-attribution.d.ts +10 -4
  28. package/dist/core/engine/lifecycle/start-schedule-timing.d.ts +11 -0
  29. package/dist/core/engine/lifecycle/start-schedule-timing.js +21 -0
  30. package/dist/core/engine/lifecycle/start-terminal-conflict-purge.d.ts +90 -11
  31. package/dist/core/engine/lifecycle/start-terminal-conflict-purge.js +24 -5
  32. package/dist/core/engine/lifecycle/start.d.ts +40 -3
  33. package/dist/core/engine/lifecycle/start.js +19 -26
  34. package/dist/core/engine/lifecycle/transition.d.ts +9 -0
  35. package/dist/core/engine/lifecycle/transition.js +20 -25
  36. package/dist/core/engine/lifecycle.d.ts +2 -1
  37. package/dist/core/engine/lifecycle.js +2 -1
  38. package/dist/core/engine/schedule-overlap.js +2 -1
  39. package/dist/core/engine/schedule-run.d.ts +10 -0
  40. package/dist/core/engine/schedule-run.js +1 -1
  41. package/dist/core/engine/schedules.d.ts +11 -2
  42. package/dist/core/engine/termination/complete.js +1 -1
  43. package/dist/core/engine/termination/suspend.js +3 -0
  44. package/dist/core/engine/validation/schedule.d.ts +25 -1
  45. package/dist/core/engine/validation/schedule.js +4 -10
  46. package/dist/core/engine/validation.js +10 -17
  47. package/dist/core/engine/workflow-claim-reclaim-target.js +6 -6
  48. package/dist/core/engine/workflow-claim-registry.d.ts +79 -75
  49. package/dist/core/engine/workflow-claim-registry.js +15 -2
  50. package/dist/core/engine/workflow-generation-fence.d.ts +74 -0
  51. package/dist/core/engine/workflow-generation-fence.js +19 -0
  52. package/dist/core/start-workflow-validation.d.ts +15 -0
  53. package/dist/core/start-workflow-validation.js +11 -1
  54. package/dist/core/workflow-identifiers.d.ts +37 -0
  55. package/dist/core/workflow-identifiers.js +19 -1
  56. package/dist/http.js +2 -2
  57. package/dist/indexeddb.js +1 -1
  58. package/dist/server/fleet-event-feed.js +6 -6
  59. package/dist/server/rest-binding.d.ts +11 -0
  60. package/dist/server/runtime/task-dispatch-envelope.d.ts +32 -5
  61. package/dist/server/runtime/task-dispatch-envelope.js +23 -1
  62. package/dist/server/runtime/task-dispatch.d.ts +3 -1
  63. package/dist/server/runtime/task-dispatch.js +9 -8
  64. package/dist/server/task-ledger-codec.d.ts +19 -0
  65. package/dist/server/task-ledger-codec.js +3 -0
  66. package/dist/server/task-ledger.d.ts +1 -1
  67. package/dist/server/task-ledger.js +1 -0
  68. package/dist/storage/bun-sql.js +132 -99
  69. package/dist/storage/compressed-storage.js +1 -1
  70. package/dist/storage/generation-keys.d.ts +52 -0
  71. package/dist/storage/generation-keys.js +4 -0
  72. package/dist/storage/index.d.ts +76 -65
  73. package/dist/storage/interface.d.ts +24 -232
  74. package/dist/storage/interface.js +1 -1
  75. package/dist/storage/key-prefixes.d.ts +1 -1
  76. package/dist/storage/key-prefixes.js +1 -0
  77. package/dist/storage/lease-keys.d.ts +48 -0
  78. package/dist/storage/lease-keys.js +8 -0
  79. package/dist/storage/lmdb.js +1 -1
  80. package/dist/storage/memory.js +1 -1
  81. package/dist/storage/neon.js +3 -3
  82. package/dist/storage/node-sqlite.js +132 -99
  83. package/dist/storage/postgres.js +3 -3
  84. package/dist/storage/resolve.js +1 -1
  85. package/dist/storage/scoped-storage.js +1 -1
  86. package/dist/storage/signal-keys.d.ts +23 -0
  87. package/dist/storage/signal-keys.js +9 -0
  88. package/dist/storage/testing.js +1 -1
  89. package/dist/storage/turso.js +2 -2
  90. package/dist/storage/workflow-lifecycle-keys.d.ts +128 -0
  91. package/dist/storage/workflow-lifecycle-keys.js +46 -0
  92. package/dist/storage/workflow-record-keys.d.ts +98 -0
  93. package/dist/storage/workflow-record-keys.js +47 -0
  94. package/dist/version.d.ts +1 -1
  95. package/dist/version.js +1 -1
  96. package/dist/web-extension.js +1 -1
  97. package/package.json +1 -1
@@ -26,9 +26,6 @@ var WORKFLOW_CATALOG_KEYS = {
26
26
  catalogTombstonePrefix: () => `catalog-tombstone:`
27
27
  };
28
28
 
29
- // src/storage/default-scope.ts
30
- var DEFAULT_SCOPE = "default";
31
-
32
29
  // src/storage/derived-operations.ts
33
30
  async function storageHasCore(storage, key) {
34
31
  return await storage.get(key) !== null;
@@ -68,6 +65,20 @@ async function storageDeleteRangeCore(storage, prefix, options) {
68
65
  return operations.length;
69
66
  }
70
67
 
68
+ // src/storage/generation-keys.ts
69
+ var GENERATION_KEYS = {
70
+ workflowGeneration: (workflowId) => `wf-gen:${encodeStorageKeyComponent(workflowId)}`
71
+ };
72
+
73
+ // src/storage/lease-keys.ts
74
+ var LEASE_KEYS = {
75
+ livenessPrefix: () => "liveness:",
76
+ liveness: (instanceId) => `liveness:${encodeStorageKeyComponent(instanceId)}`,
77
+ leasePrefix: () => "lease:",
78
+ leaseEpoch: () => "lease:epoch",
79
+ leaseHolder: () => "lease:holder"
80
+ };
81
+
71
82
  // src/storage/mailbox-keys.ts
72
83
  var MAILBOX_KEYS = {
73
84
  applicationMailbox: (namespace, resourceId) => `appmbx:v1:${encodeStorageKeyComponent(namespace)}:${encodeStorageKeyComponent(resourceId)}`,
@@ -105,6 +116,117 @@ var OWNERSHIP_CLAIM_KEYS = {
105
116
  ownershipModeMarker: () => "ownership-mode-marker"
106
117
  };
107
118
 
119
+ // src/storage/signal-keys.ts
120
+ var SIGNAL_SORT_CLASS_START = "0";
121
+ var SIGNAL_SORT_CLASS_NORMAL = "1";
122
+ var signalStorageKey = (workflowId, name, id, sortClass) => `sig:${encodeStorageKeyComponent(workflowId)}:${encodeStorageKeyComponent(name)}:${sortClass}:${encodeStorageKeyComponent(id)}`;
123
+ var SIGNAL_KEYS = {
124
+ signal: (workflowId, name, id) => signalStorageKey(workflowId, name, id, SIGNAL_SORT_CLASS_NORMAL),
125
+ startSignal: (workflowId, name, id) => signalStorageKey(workflowId, name, id, SIGNAL_SORT_CLASS_START),
126
+ signalSequence: (workflowId) => `sigseq:v1:${encodeStorageKeyComponent(workflowId)}`,
127
+ signalAcceptedResponsePrefix: (workflowId) => `sigres:v1:${encodeStorageKeyComponent(workflowId)}:`,
128
+ signalAcceptedResponse: (workflowId, name, signalId) => `sigres:v1:${encodeStorageKeyComponent(workflowId)}:${encodeStorageKeyComponent(name)}:${encodeStorageKeyComponent(signalId)}`
129
+ };
130
+
131
+ // src/storage/default-scope.ts
132
+ var DEFAULT_SCOPE = "default";
133
+
134
+ // src/storage/workflow-lifecycle-keys.ts
135
+ var formatSortableTimestamp = formatSortableStorageTimestamp;
136
+ var WORKFLOW_LIFECYCLE_KEYS_CORE = {
137
+ deadline: (deadline, workflowId) => `wf-deadline:${formatSortableTimestamp(deadline)}:${encodeStorageKeyComponent(workflowId)}`,
138
+ terminalCleanup: (fireAt, timerId) => `wf-cleanup:${formatSortableTimestamp(fireAt)}:${encodeStorageKeyComponent(timerId)}`,
139
+ teardownTimer: (fireAt, timerId) => `wf-teardown:${formatSortableTimestamp(fireAt)}:${encodeStorageKeyComponent(timerId)}`,
140
+ delayedStart: (startAt, workflowId) => `wf-delayed:${formatSortableTimestamp(startAt)}:${encodeStorageKeyComponent(workflowId)}`,
141
+ terminalWorkflowPrefix: () => "wf-terminal:",
142
+ terminalWorkflow: (updatedAt, workflowId) => `wf-terminal:${formatSortableTimestamp(updatedAt)}:${encodeStorageKeyComponent(workflowId)}`
143
+ };
144
+ var WORKFLOW_LIFECYCLE_KEYS_EXTENDED = {
145
+ budget: (namespace, period, date) => `budget:${namespace}:${period}:${date}`,
146
+ review: (workflowId, reviewId) => `review:${encodeStorageKeyComponent(workflowId)}:${reviewId}`,
147
+ workflowHeaders: (workflowId) => `wf-headers:${encodeStorageKeyComponent(workflowId)}`,
148
+ childCancellationPrefix: (workflowId) => `child-cancel:${encodeStorageKeyComponent(workflowId)}:`,
149
+ childCancellation: (workflowId, childWorkflowId) => `child-cancel:${encodeStorageKeyComponent(workflowId)}:${encodeStorageKeyComponent(childWorkflowId)}`,
150
+ childWorkflowByParentPrefix: (parentWorkflowId, parentWorkflowExecutionToken) => `child-by-parent:${encodeStorageKeyComponent(parentWorkflowId)}:${parentWorkflowExecutionToken === undefined ? "" : `${encodeStorageKeyComponent(parentWorkflowExecutionToken)}:`}`,
151
+ childWorkflowByParent: (parentWorkflowId, parentWorkflowExecutionToken, childWorkflowId) => `child-by-parent:${encodeStorageKeyComponent(parentWorkflowId)}:${parentWorkflowExecutionToken === undefined ? "" : `${encodeStorageKeyComponent(parentWorkflowExecutionToken)}:`}${encodeStorageKeyComponent(childWorkflowId)}`,
152
+ terminalCleanupNeeded: (workflowId) => `wf-cleanup-needed:${encodeStorageKeyComponent(workflowId)}`,
153
+ workflowConcurrency: (workflowType, partitionKey) => `wf-concurrency:${encodeStorageKeyComponent(workflowType)}:${encodeStorageKeyComponent(partitionKey)}`,
154
+ workflowConcurrencyHolder: (workflowId) => `wf-concurrency-holder:${encodeStorageKeyComponent(workflowId)}`,
155
+ workflowHasServices: (workflowId) => `wf-has-services:${encodeStorageKeyComponent(workflowId)}`,
156
+ finalizerState: (workflowId) => `wf-finalizer-state:${encodeStorageKeyComponent(workflowId)}`,
157
+ teardownOwed: (workflowId) => `wf-teardown-needed:${encodeStorageKeyComponent(workflowId)}`,
158
+ teardownSucceeded: (workflowId) => `wf-teardown-succeeded:${encodeStorageKeyComponent(workflowId)}`,
159
+ teardownDeadLetter: (workflowId) => `wf-teardown-deadletter:${encodeStorageKeyComponent(workflowId)}`,
160
+ offload: (workflowId, key) => `offload:${encodeStorageKeyComponent(workflowId)}:${key}`,
161
+ archive: (workflowId, key) => `archive:${encodeStorageKeyComponent(workflowId)}:${key}`,
162
+ stateExecution: (ownerWorkflowId, key) => `state:execution:${encodeStorageKeyComponent(ownerWorkflowId)}:${encodeStorageKeyComponent(key)}`,
163
+ stateWorkflow: (workflowType, key) => `state:workflow-scope:${DEFAULT_SCOPE}:${encodeStorageKeyComponent(workflowType)}:${encodeStorageKeyComponent(key)}`,
164
+ streamChunkPrefix: (workflowId, key) => `blob:${encodeStorageKeyComponent(workflowId)}:${key}:chunk:`,
165
+ streamChunk: (workflowId, key, chunkIndex) => `blob:${encodeStorageKeyComponent(workflowId)}:${key}:chunk:${String(chunkIndex).padStart(10, "0")}`,
166
+ streamTail: (workflowId, key) => `blob:${encodeStorageKeyComponent(workflowId)}:${key}:tail`,
167
+ streamMetadata: (workflowId, key) => `blob:${encodeStorageKeyComponent(workflowId)}:${key}:meta`,
168
+ budgetCharged: (operationId) => `budget-charged:${operationId}`,
169
+ toolEffect: (workflowId, agentId, semanticHash) => `tool-effect:${encodeStorageKeyComponent(workflowId)}:${agentId}:${semanticHash}`,
170
+ workflowVisibilityStatus: (status, workflowId) => `wf-idx-status:${encodeStorageKeyComponent(status)}:${encodeStorageKeyComponent(workflowId)}`,
171
+ workflowVisibilityType: (type, workflowId) => `wf-idx-type:${encodeStorageKeyComponent(type)}:${encodeStorageKeyComponent(workflowId)}`,
172
+ workflowVisibilityCreated: (createdAt, workflowId) => `wf-idx-created:${formatSortableTimestamp(createdAt)}:${encodeStorageKeyComponent(workflowId)}`,
173
+ workflowVisibilityUpdated: (updatedAt, workflowId) => `wf-idx-updated:${formatSortableTimestamp(updatedAt)}:${encodeStorageKeyComponent(workflowId)}`,
174
+ workflowVisibilityDeadline: (deadline, workflowId) => `wf-idx-deadline:${formatSortableTimestamp(deadline)}:${encodeStorageKeyComponent(workflowId)}`,
175
+ workflowVisibilityManifest: (workflowId) => `wf-idx-manifest:${encodeStorageKeyComponent(workflowId)}`,
176
+ workflowVisibilityMetaVersion: () => "wf-idx-meta:version",
177
+ workflowVisibilityMetaBuiltAt: () => "wf-idx-meta:built-at",
178
+ workflowVisibilityMetaCursor: () => "wf-idx-meta:cursor"
179
+ };
180
+
181
+ // src/storage/workflow-record-keys.ts
182
+ var formatSortableTimestamp2 = formatSortableStorageTimestamp;
183
+ var WORKFLOW_RECORD_KEYS_CORE = {
184
+ workflow: (id) => `wf:${encodeStorageKeyComponent(id)}`,
185
+ checkpoint: (id) => `wf:${encodeStorageKeyComponent(id)}:ckpt`,
186
+ checkpointHistory: (id, step) => `wf:${encodeStorageKeyComponent(id)}:ckpt:${String(step).padStart(10, "0")}`,
187
+ timelinePrefix: (id) => `wf:${encodeStorageKeyComponent(id)}:timeline:`,
188
+ timeline: (id, step) => `wf:${encodeStorageKeyComponent(id)}:timeline:${String(step).padStart(10, "0")}`,
189
+ schedule: (id) => `schedule:${encodeStorageKeyComponent(id)}`,
190
+ scheduleTick: (fireAt, id) => `schedule-due:${String(fireAt).padStart(16, "0")}:${encodeStorageKeyComponent(id)}`,
191
+ scheduleRun: (workflowId) => `schedule-run:${encodeStorageKeyComponent(workflowId)}`,
192
+ scheduleRunLink: (workflowId) => `schedule-run-link:${encodeStorageKeyComponent(workflowId)}`,
193
+ scheduleRunBySchedulePrefix: (scheduleId) => `schedule-run-by-schedule:${encodeStorageKeyComponent(scheduleId)}:`,
194
+ scheduleRunBySchedule: (scheduleId, workflowId) => `schedule-run-by-schedule:${encodeStorageKeyComponent(scheduleId)}:${encodeStorageKeyComponent(workflowId)}`,
195
+ operation: (queue, scheduledAt, id) => `op:${queue}:${formatSortableTimestamp2(scheduledAt)}:${id}`,
196
+ operationInflight: (id) => `op:inflight:${id}`,
197
+ operationQueued: (id) => `op:queued:${id}`,
198
+ operationResolved: (id) => `op:resolved:${id}`,
199
+ bulkOperationAuditPrefix: () => "audit:bulk:",
200
+ bulkOperationAudit: (timestamp, requestId, confirmationToken) => `audit:bulk:${formatSortableTimestamp2(timestamp)}:${encodeStorageKeyComponent(requestId)}:${encodeStorageKeyComponent(confirmationToken)}`,
201
+ operationResolvedByTimePrefix: () => "op:resolved-by-time:",
202
+ operationResolvedByTime: (resolvedAt, id) => `op:resolved-by-time:${formatSortableTimestamp2(resolvedAt)}:${encodeStorageKeyComponent(id)}`,
203
+ asyncActivity: (workflowId, token) => `async-act:v1:${encodeStorageKeyComponent(workflowId)}:${encodeStorageKeyComponent(token)}`,
204
+ asyncActivityResolution: (workflowId, token) => `async-act:v1:${encodeStorageKeyComponent(workflowId)}:${encodeStorageKeyComponent(token)}:resolution`,
205
+ activityReconciliationPrefix: (workflowId) => `actrec:v1:${encodeStorageKeyComponent(workflowId)}:`,
206
+ activityReconciliation: (workflowId, activityName, idempotencyKeyDigest) => `actrec:v1:${encodeStorageKeyComponent(workflowId)}:${encodeStorageKeyComponent(activityName)}:${idempotencyKeyDigest}`,
207
+ eventPrefix: (workflowId) => `ev:${encodeStorageKeyComponent(workflowId)}:`,
208
+ event: (workflowId, sequence) => `ev:${encodeStorageKeyComponent(workflowId)}:${String(sequence).padStart(10, "0")}`,
209
+ eventHead: (workflowId) => `ev:${encodeStorageKeyComponent(workflowId)}:head`,
210
+ eventWatermark: (workflowId) => `ev:${encodeStorageKeyComponent(workflowId)}:watermark`,
211
+ fleetEventPrefix: () => "fleet-event:",
212
+ fleetEvent: (sequence) => `fleet-event:${String(sequence).padStart(10, "0")}`,
213
+ fleetEventTail: () => "fleet-event-tail",
214
+ fleetEventWatermark: () => "fleet-event-watermark",
215
+ fleetEventByWorkflowPrefix: (workflowId) => `fleet-event-by-workflow:${encodeStorageKeyComponent(workflowId)}:`,
216
+ fleetEventByWorkflow: (workflowId, sequence) => `fleet-event-by-workflow:${encodeStorageKeyComponent(workflowId)}:${String(sequence).padStart(10, "0")}`
217
+ };
218
+ var WORKFLOW_RECORD_KEYS_EXTENDED = {
219
+ attribute: (workflowId) => `attr:${encodeStorageKeyComponent(workflowId)}`,
220
+ attributeIndex: (attributeName, encodedValue, workflowId) => `idx:${attributeName}:${encodedValue}:${encodeStorageKeyComponent(workflowId)}`,
221
+ tagIndex: (tag, workflowId) => `tag:${encodeStorageKeyComponent(tag)}:${encodeStorageKeyComponent(workflowId)}`,
222
+ updatePrefix: (workflowId) => `upd:${encodeStorageKeyComponent(workflowId)}:`,
223
+ update: (workflowId, updateId) => `upd:${encodeStorageKeyComponent(workflowId)}:${updateId}`,
224
+ updateResponse: (updateId) => `upr:${updateId}`,
225
+ updateIdempotency: (workflowId, key) => `upk:${encodeStorageKeyComponent(workflowId)}:${key}`,
226
+ startIdempotency: (key) => `start-idem:${encodeStorageKeyComponent(key)}`,
227
+ startIdempotencySignalId: (key) => `start-idem:${key}`
228
+ };
229
+
108
230
  // src/storage/interface.ts
109
231
  var MAX_BATCH_OPERATIONS = 1e4;
110
232
  class StorageBatchOperationLimitExceededError extends Error {
@@ -174,107 +296,18 @@ async function storageConditionalBatch(storage, conditions, operations) {
174
296
  }
175
297
  return storage.conditionalBatch(conditions, operations);
176
298
  }
177
- var formatSortableTimestamp = formatSortableStorageTimestamp;
178
- var SIGNAL_SORT_CLASS_START = "0";
179
- var SIGNAL_SORT_CLASS_NORMAL = "1";
180
- var signalStorageKey = (workflowId, name, id, sortClass) => `sig:${encodeStorageKeyComponent(workflowId)}:${encodeStorageKeyComponent(name)}:${sortClass}:${encodeStorageKeyComponent(id)}`;
181
299
  var KEYS = {
182
- workflow: (id) => `wf:${encodeStorageKeyComponent(id)}`,
183
- checkpoint: (id) => `wf:${encodeStorageKeyComponent(id)}:ckpt`,
184
- checkpointHistory: (id, step) => `wf:${encodeStorageKeyComponent(id)}:ckpt:${String(step).padStart(10, "0")}`,
185
- timelinePrefix: (id) => `wf:${encodeStorageKeyComponent(id)}:timeline:`,
186
- timeline: (id, step) => `wf:${encodeStorageKeyComponent(id)}:timeline:${String(step).padStart(10, "0")}`,
187
- schedule: (id) => `schedule:${encodeStorageKeyComponent(id)}`,
188
- scheduleTick: (fireAt, id) => `schedule-due:${String(fireAt).padStart(16, "0")}:${encodeStorageKeyComponent(id)}`,
189
- scheduleRun: (workflowId) => `schedule-run:${encodeStorageKeyComponent(workflowId)}`,
190
- scheduleRunLink: (workflowId) => `schedule-run-link:${encodeStorageKeyComponent(workflowId)}`,
191
- scheduleRunBySchedulePrefix: (scheduleId) => `schedule-run-by-schedule:${encodeStorageKeyComponent(scheduleId)}:`,
192
- scheduleRunBySchedule: (scheduleId, workflowId) => `schedule-run-by-schedule:${encodeStorageKeyComponent(scheduleId)}:${encodeStorageKeyComponent(workflowId)}`,
193
- operation: (queue, scheduledAt, id) => `op:${queue}:${formatSortableTimestamp(scheduledAt)}:${id}`,
194
- operationInflight: (id) => `op:inflight:${id}`,
195
- operationQueued: (id) => `op:queued:${id}`,
196
- operationResolved: (id) => `op:resolved:${id}`,
197
- bulkOperationAuditPrefix: () => "audit:bulk:",
198
- bulkOperationAudit: (timestamp, requestId, confirmationToken) => `audit:bulk:${formatSortableTimestamp(timestamp)}:${encodeStorageKeyComponent(requestId)}:${encodeStorageKeyComponent(confirmationToken)}`,
199
- operationResolvedByTimePrefix: () => "op:resolved-by-time:",
200
- operationResolvedByTime: (resolvedAt, id) => `op:resolved-by-time:${formatSortableTimestamp(resolvedAt)}:${encodeStorageKeyComponent(id)}`,
201
- asyncActivity: (workflowId, token) => `async-act:v1:${encodeStorageKeyComponent(workflowId)}:${encodeStorageKeyComponent(token)}`,
202
- asyncActivityResolution: (workflowId, token) => `async-act:v1:${encodeStorageKeyComponent(workflowId)}:${encodeStorageKeyComponent(token)}:resolution`,
203
- activityReconciliationPrefix: (workflowId) => `actrec:v1:${encodeStorageKeyComponent(workflowId)}:`,
204
- activityReconciliation: (workflowId, activityName, idempotencyKeyDigest) => `actrec:v1:${encodeStorageKeyComponent(workflowId)}:${encodeStorageKeyComponent(activityName)}:${idempotencyKeyDigest}`,
205
- eventPrefix: (workflowId) => `ev:${encodeStorageKeyComponent(workflowId)}:`,
206
- event: (workflowId, sequence) => `ev:${encodeStorageKeyComponent(workflowId)}:${String(sequence).padStart(10, "0")}`,
207
- eventHead: (workflowId) => `ev:${encodeStorageKeyComponent(workflowId)}:head`,
208
- eventWatermark: (workflowId) => `ev:${encodeStorageKeyComponent(workflowId)}:watermark`,
209
- fleetEventPrefix: () => "fleet-event:",
210
- fleetEvent: (sequence) => `fleet-event:${String(sequence).padStart(10, "0")}`,
211
- fleetEventTail: () => "fleet-event-tail",
212
- fleetEventWatermark: () => "fleet-event-watermark",
213
- fleetEventByWorkflowPrefix: (workflowId) => `fleet-event-by-workflow:${encodeStorageKeyComponent(workflowId)}:`,
214
- fleetEventByWorkflow: (workflowId, sequence) => `fleet-event-by-workflow:${encodeStorageKeyComponent(workflowId)}:${String(sequence).padStart(10, "0")}`,
215
- signal: (workflowId, name, id) => signalStorageKey(workflowId, name, id, SIGNAL_SORT_CLASS_NORMAL),
216
- startSignal: (workflowId, name, id) => signalStorageKey(workflowId, name, id, SIGNAL_SORT_CLASS_START),
217
- signalSequence: (workflowId) => `sigseq:v1:${encodeStorageKeyComponent(workflowId)}`,
218
- signalAcceptedResponsePrefix: (workflowId) => `sigres:v1:${encodeStorageKeyComponent(workflowId)}:`,
219
- signalAcceptedResponse: (workflowId, name, signalId) => `sigres:v1:${encodeStorageKeyComponent(workflowId)}:${encodeStorageKeyComponent(name)}:${encodeStorageKeyComponent(signalId)}`,
220
- deadline: (deadline, workflowId) => `wf-deadline:${formatSortableTimestamp(deadline)}:${encodeStorageKeyComponent(workflowId)}`,
221
- terminalCleanup: (fireAt, timerId) => `wf-cleanup:${formatSortableTimestamp(fireAt)}:${encodeStorageKeyComponent(timerId)}`,
222
- teardownTimer: (fireAt, timerId) => `wf-teardown:${formatSortableTimestamp(fireAt)}:${encodeStorageKeyComponent(timerId)}`,
223
- delayedStart: (startAt, workflowId) => `wf-delayed:${formatSortableTimestamp(startAt)}:${encodeStorageKeyComponent(workflowId)}`,
224
- terminalWorkflowPrefix: () => "wf-terminal:",
225
- terminalWorkflow: (updatedAt, workflowId) => `wf-terminal:${formatSortableTimestamp(updatedAt)}:${encodeStorageKeyComponent(workflowId)}`,
226
- attribute: (workflowId) => `attr:${encodeStorageKeyComponent(workflowId)}`,
227
- attributeIndex: (attributeName, encodedValue, workflowId) => `idx:${attributeName}:${encodedValue}:${encodeStorageKeyComponent(workflowId)}`,
228
- tagIndex: (tag, workflowId) => `tag:${encodeStorageKeyComponent(tag)}:${encodeStorageKeyComponent(workflowId)}`,
229
- updatePrefix: (workflowId) => `upd:${encodeStorageKeyComponent(workflowId)}:`,
230
- update: (workflowId, updateId) => `upd:${encodeStorageKeyComponent(workflowId)}:${updateId}`,
231
- updateResponse: (updateId) => `upr:${updateId}`,
232
- updateIdempotency: (workflowId, key) => `upk:${encodeStorageKeyComponent(workflowId)}:${key}`,
233
- startIdempotency: (key) => `start-idem:${encodeStorageKeyComponent(key)}`,
234
- startIdempotencySignalId: (key) => `start-idem:${key}`,
235
- livenessPrefix: () => "liveness:",
236
- liveness: (instanceId) => `liveness:${encodeStorageKeyComponent(instanceId)}`,
237
- leasePrefix: () => "lease:",
238
- leaseEpoch: () => "lease:epoch",
239
- leaseHolder: () => "lease:holder",
300
+ ...WORKFLOW_RECORD_KEYS_CORE,
301
+ ...SIGNAL_KEYS,
302
+ ...WORKFLOW_LIFECYCLE_KEYS_CORE,
303
+ ...WORKFLOW_RECORD_KEYS_EXTENDED,
304
+ ...LEASE_KEYS,
240
305
  ...MAILBOX_KEYS,
241
306
  ...OUTBOX_KEYS,
242
307
  ...OWNERSHIP_CLAIM_KEYS,
243
308
  ...WORKFLOW_CATALOG_KEYS,
244
- budget: (namespace, period, date) => `budget:${namespace}:${period}:${date}`,
245
- review: (workflowId, reviewId) => `review:${encodeStorageKeyComponent(workflowId)}:${reviewId}`,
246
- workflowHeaders: (workflowId) => `wf-headers:${encodeStorageKeyComponent(workflowId)}`,
247
- childCancellationPrefix: (workflowId) => `child-cancel:${encodeStorageKeyComponent(workflowId)}:`,
248
- childCancellation: (workflowId, childWorkflowId) => `child-cancel:${encodeStorageKeyComponent(workflowId)}:${encodeStorageKeyComponent(childWorkflowId)}`,
249
- childWorkflowByParentPrefix: (parentWorkflowId, parentWorkflowExecutionToken) => `child-by-parent:${encodeStorageKeyComponent(parentWorkflowId)}:${parentWorkflowExecutionToken === undefined ? "" : `${encodeStorageKeyComponent(parentWorkflowExecutionToken)}:`}`,
250
- childWorkflowByParent: (parentWorkflowId, parentWorkflowExecutionToken, childWorkflowId) => `child-by-parent:${encodeStorageKeyComponent(parentWorkflowId)}:${parentWorkflowExecutionToken === undefined ? "" : `${encodeStorageKeyComponent(parentWorkflowExecutionToken)}:`}${encodeStorageKeyComponent(childWorkflowId)}`,
251
- terminalCleanupNeeded: (workflowId) => `wf-cleanup-needed:${encodeStorageKeyComponent(workflowId)}`,
252
- workflowConcurrency: (workflowType, partitionKey) => `wf-concurrency:${encodeStorageKeyComponent(workflowType)}:${encodeStorageKeyComponent(partitionKey)}`,
253
- workflowConcurrencyHolder: (workflowId) => `wf-concurrency-holder:${encodeStorageKeyComponent(workflowId)}`,
254
- workflowHasServices: (workflowId) => `wf-has-services:${encodeStorageKeyComponent(workflowId)}`,
255
- finalizerState: (workflowId) => `wf-finalizer-state:${encodeStorageKeyComponent(workflowId)}`,
256
- teardownOwed: (workflowId) => `wf-teardown-needed:${encodeStorageKeyComponent(workflowId)}`,
257
- teardownSucceeded: (workflowId) => `wf-teardown-succeeded:${encodeStorageKeyComponent(workflowId)}`,
258
- teardownDeadLetter: (workflowId) => `wf-teardown-deadletter:${encodeStorageKeyComponent(workflowId)}`,
259
- offload: (workflowId, key) => `offload:${encodeStorageKeyComponent(workflowId)}:${key}`,
260
- archive: (workflowId, key) => `archive:${encodeStorageKeyComponent(workflowId)}:${key}`,
261
- stateExecution: (ownerWorkflowId, key) => `state:execution:${encodeStorageKeyComponent(ownerWorkflowId)}:${encodeStorageKeyComponent(key)}`,
262
- stateWorkflow: (workflowType, key) => `state:workflow-scope:${DEFAULT_SCOPE}:${encodeStorageKeyComponent(workflowType)}:${encodeStorageKeyComponent(key)}`,
263
- streamChunkPrefix: (workflowId, key) => `blob:${encodeStorageKeyComponent(workflowId)}:${key}:chunk:`,
264
- streamChunk: (workflowId, key, chunkIndex) => `blob:${encodeStorageKeyComponent(workflowId)}:${key}:chunk:${String(chunkIndex).padStart(10, "0")}`,
265
- streamTail: (workflowId, key) => `blob:${encodeStorageKeyComponent(workflowId)}:${key}:tail`,
266
- streamMetadata: (workflowId, key) => `blob:${encodeStorageKeyComponent(workflowId)}:${key}:meta`,
267
- budgetCharged: (operationId) => `budget-charged:${operationId}`,
268
- toolEffect: (workflowId, agentId, semanticHash) => `tool-effect:${encodeStorageKeyComponent(workflowId)}:${agentId}:${semanticHash}`,
269
- workflowVisibilityStatus: (status, workflowId) => `wf-idx-status:${encodeStorageKeyComponent(status)}:${encodeStorageKeyComponent(workflowId)}`,
270
- workflowVisibilityType: (type, workflowId) => `wf-idx-type:${encodeStorageKeyComponent(type)}:${encodeStorageKeyComponent(workflowId)}`,
271
- workflowVisibilityCreated: (createdAt, workflowId) => `wf-idx-created:${formatSortableTimestamp(createdAt)}:${encodeStorageKeyComponent(workflowId)}`,
272
- workflowVisibilityUpdated: (updatedAt, workflowId) => `wf-idx-updated:${formatSortableTimestamp(updatedAt)}:${encodeStorageKeyComponent(workflowId)}`,
273
- workflowVisibilityDeadline: (deadline, workflowId) => `wf-idx-deadline:${formatSortableTimestamp(deadline)}:${encodeStorageKeyComponent(workflowId)}`,
274
- workflowVisibilityManifest: (workflowId) => `wf-idx-manifest:${encodeStorageKeyComponent(workflowId)}`,
275
- workflowVisibilityMetaVersion: () => "wf-idx-meta:version",
276
- workflowVisibilityMetaBuiltAt: () => "wf-idx-meta:built-at",
277
- workflowVisibilityMetaCursor: () => "wf-idx-meta:cursor"
309
+ ...GENERATION_KEYS,
310
+ ...WORKFLOW_LIFECYCLE_KEYS_EXTENDED
278
311
  };
279
312
 
280
313
  // src/storage/conditional-batch-body.ts
@@ -1,2 +1,2 @@
1
1
  // @bun
2
- var re=import.meta.require;function m(e,t,n){if(!e.capabilities()[t])throw Error(`Feature "${n}" requires storage capability "${t}", but this storage backend does not provide it.`)}function q(e){let t=e.capabilities(),n=[];if(t.persistence!=="local"&&t.persistence!=="remote")n.push(`persistence must be "local" or "remote" (got "${t.persistence}")`);if(t.readAfterWrite!=="linearizable")n.push(`readAfterWrite must be "linearizable" (got "${t.readAfterWrite}")`);if(t.scanConsistency!=="snapshot")n.push(`scanConsistency must be "snapshot" (got "${t.scanConsistency}")`);if(!t.atomicBatch)n.push("atomicBatch must be true");if(!t.conditionalBatch)n.push("conditionalBatch must be true");if(n.length>0)throw Error(`Storage is not durable enough for recovery: ${n.join("; ")}.`)}function r(e){return encodeURIComponent(e)}function H(e){return decodeURIComponent(e)}function W(e){try{return decodeURIComponent(e)}catch{return null}}function o(e){return String(e).padStart(16,"0")}var x={catalogEntry:(e,t)=>`catalog-entry:${r(e)}:${r(t)}`,catalogEntryPrefix:(e)=>`catalog-entry:${r(e)}:`,catalogActive:(e)=>`catalog-active:${r(e)}`,catalogTombstone:(e,t)=>`catalog-tombstone:${r(e)}:${r(t)}`,catalogTombstonePrefix:()=>"catalog-tombstone:"};var y="default";async function v(e,t){return await e.get(t)!==null}async function*p(e,t,n){for await(let[i]of e.scan(t,n))yield i}async function C(e,t){let n=0;for await(let i of p(e,t))n++;return n}async function A(e,t){let n=[];for await(let i of p(e,t))n.push({type:"delete",key:i});if(n.length===0)return 0;return await e.batch(n),n.length}async function le(e,t,n){let i=[];for await(let f of p(e,t,n))i.push({type:"delete",key:f});if(i.length===0)return 0;return await e.batch(i),i.length}var B={applicationMailbox:(e,t)=>`appmbx:v1:${r(e)}:${r(t)}`,applicationMailboxSinkProbe:(e,t,n)=>`appprobe:v1:${r(e)}:${r(t)}:${r(n)}`,applicationCommandPrefix:(e,t)=>`appcmd:v1:${r(e)}:${r(t)}:`,applicationCommand:(e,t,n)=>`appcmd:v1:${r(e)}:${r(t)}:${r(n)}`,applicationCommandReadyPrefix:(e,t)=>`appready:v1:${r(e)}:${r(t)}:`,applicationCommandReady:(e,t,n)=>`appready:v1:${r(e)}:${r(t)}:${o(n)}`,applicationCommandIdempotency:(e,t,n)=>`appidem:v1:${r(e)}:${r(t)}:${r(n)}`,applicationCommandBySequencePrefix:(e,t)=>`appseq:v1:${r(e)}:${r(t)}:`,applicationCommandBySequence:(e,t,n)=>`appseq:v1:${r(e)}:${r(t)}:${o(n)}`,applicationCommandTerminalPrefix:(e,t)=>`appterm:v1:${r(e)}:${r(t)}:`,applicationCommandTerminal:(e,t,n,i)=>`appterm:v1:${r(e)}:${r(t)}:${o(n)}:${r(i)}`};var P={applicationOutbox:(e,t)=>`appobx:v1:${r(e)}:${r(t)}`,applicationOutboxSinkProbe:(e,t,n)=>`appprobe:v1:outbox:${r(e)}:${r(t)}:${r(n)}`,applicationDeliveryPrefix:(e,t)=>`appdlv:v1:${r(e)}:${r(t)}:`,applicationDelivery:(e,t,n)=>`appdlv:v1:${r(e)}:${r(t)}:${r(n)}`,applicationDeliveryDuePrefix:(e,t)=>`appdue:v1:${r(e)}:${r(t)}:`,applicationDeliveryDue:(e,t,n,i)=>`appdue:v1:${r(e)}:${r(t)}:${o(n)}:${r(i)}`,applicationDeliveryIdempotency:(e,t,n)=>`appdidem:v1:${r(e)}:${r(t)}:${r(n)}`,applicationDeliveryBySequencePrefix:(e,t)=>`appdseq:v1:${r(e)}:${r(t)}:`,applicationDeliveryBySequence:(e,t,n)=>`appdseq:v1:${r(e)}:${r(t)}:${o(n)}`,applicationDeliveryTerminalPrefix:(e,t)=>`appdterm:v1:${r(e)}:${r(t)}:`,applicationDeliveryTerminal:(e,t,n,i)=>`appdterm:v1:${r(e)}:${r(t)}:${o(n)}:${r(i)}`};var O={workflowOwnerEpoch:(e)=>`wf-owner-epoch:${r(e)}`,workflowOwnerHolder:(e)=>`wf-owner-holder:${r(e)}`,ownershipModeMarker:()=>"ownership-mode-marker"};var V=["actrec:","appcmd:","appdidem:","appdlv:","appdseq:","appdterm:","appdue:","appidem:","appmbx:","appobx:","appprobe:","appready:","appseq:","appterm:","archive:","async-act:","attr:","audit:bulk:","blob:","budget:","budget-charged:","catalog-active:","catalog-entry:","catalog-tombstone:","child-by-parent:","ev:","fleet-event-by-workflow:","fleet-event:","fleet-event-tail","fleet-event-watermark","idx:","lease:","liveness:","offload:","ownership-mode-marker","op:","review:","schedule:","schedule-due:","schedule-run-by-schedule:","schedule-run-link:","schedule-run:","sig:","sigres:","sigseq:","start-idem:","state:","tag:","tool-effect:","upd:","upk:","upr:","wf:","wf-cleanup:","wf-cleanup-needed:","wf-concurrency:","wf-concurrency-holder:","wf-deadline:","wf-delayed:","wf-finalizer-state:","wf-has-services:","wf-headers:","wf-idx-","wf-owner-epoch:","wf-owner-holder:","wf-teardown:","wf-teardown-deadletter:","wf-teardown-needed:","wf-teardown-succeeded:","wf-terminal:"];var b=1e4,Be=1e4;class k extends Error{code="StorageBatchOperationLimitExceededError";cap=b;count;target;constructor(e,t){super(`${e} count ${t} exceeds MAX_BATCH_OPERATIONS (${b}).`);this.name="StorageBatchOperationLimitExceededError",this.target=e,this.count=t}}function g(e,t){if(t>b)throw new k(e,t)}function Pe(e){return e.length>0?e.slice(0,-1)+String.fromCharCode(e.charCodeAt(e.length-1)+1):"\xFF"}function Oe(e,t={}){if(t.gt!==void 0&&e<=t.gt)return!1;if(t.gte!==void 0&&e<t.gte)return!1;if(t.lt!==void 0&&e>=t.lt)return!1;if(t.lte!==void 0&&e>t.lte)return!1;return!0}function Ee(e,t){if(e===null||t===null)return e===t;if(e.byteLength!==t.byteLength)return!1;for(let n=0;n<e.byteLength;n++)if(e[n]!==t[n])return!1;return!0}async function ke(e,t){if(e.has)return e.has(t);return v(e,t)}function Te(e,t,n){if(e.keys)return e.keys(t,n);return p(e,t,n)}async function Re(e,t){if(e.count)return e.count(t);return C(e,t)}async function Ue(e,t){if(e.deletePrefix)return e.deletePrefix(t);return A(e,t)}async function _e(e,t){g("batch operations",t.length),await e.batch(t)}async function De(e,t,n){if(g("conditionalBatch conditions",t.length),g("conditionalBatch operations",n.length),m(e,"conditionalBatch","storageConditionalBatch"),!e.conditionalBatch)throw Error("This storage backend reports conditionalBatch capability but does not implement the conditionalBatch() method.");return e.conditionalBatch(t,n)}var s=o,F="0",G="1",E=(e,t,n,i)=>`sig:${r(e)}:${r(t)}:${i}:${r(n)}`,Ie={workflow:(e)=>`wf:${r(e)}`,checkpoint:(e)=>`wf:${r(e)}:ckpt`,checkpointHistory:(e,t)=>`wf:${r(e)}:ckpt:${String(t).padStart(10,"0")}`,timelinePrefix:(e)=>`wf:${r(e)}:timeline:`,timeline:(e,t)=>`wf:${r(e)}:timeline:${String(t).padStart(10,"0")}`,schedule:(e)=>`schedule:${r(e)}`,scheduleTick:(e,t)=>`schedule-due:${String(e).padStart(16,"0")}:${r(t)}`,scheduleRun:(e)=>`schedule-run:${r(e)}`,scheduleRunLink:(e)=>`schedule-run-link:${r(e)}`,scheduleRunBySchedulePrefix:(e)=>`schedule-run-by-schedule:${r(e)}:`,scheduleRunBySchedule:(e,t)=>`schedule-run-by-schedule:${r(e)}:${r(t)}`,operation:(e,t,n)=>`op:${e}:${s(t)}:${n}`,operationInflight:(e)=>`op:inflight:${e}`,operationQueued:(e)=>`op:queued:${e}`,operationResolved:(e)=>`op:resolved:${e}`,bulkOperationAuditPrefix:()=>"audit:bulk:",bulkOperationAudit:(e,t,n)=>`audit:bulk:${s(e)}:${r(t)}:${r(n)}`,operationResolvedByTimePrefix:()=>"op:resolved-by-time:",operationResolvedByTime:(e,t)=>`op:resolved-by-time:${s(e)}:${r(t)}`,asyncActivity:(e,t)=>`async-act:v1:${r(e)}:${r(t)}`,asyncActivityResolution:(e,t)=>`async-act:v1:${r(e)}:${r(t)}:resolution`,activityReconciliationPrefix:(e)=>`actrec:v1:${r(e)}:`,activityReconciliation:(e,t,n)=>`actrec:v1:${r(e)}:${r(t)}:${n}`,eventPrefix:(e)=>`ev:${r(e)}:`,event:(e,t)=>`ev:${r(e)}:${String(t).padStart(10,"0")}`,eventHead:(e)=>`ev:${r(e)}:head`,eventWatermark:(e)=>`ev:${r(e)}:watermark`,fleetEventPrefix:()=>"fleet-event:",fleetEvent:(e)=>`fleet-event:${String(e).padStart(10,"0")}`,fleetEventTail:()=>"fleet-event-tail",fleetEventWatermark:()=>"fleet-event-watermark",fleetEventByWorkflowPrefix:(e)=>`fleet-event-by-workflow:${r(e)}:`,fleetEventByWorkflow:(e,t)=>`fleet-event-by-workflow:${r(e)}:${String(t).padStart(10,"0")}`,signal:(e,t,n)=>E(e,t,n,G),startSignal:(e,t,n)=>E(e,t,n,F),signalSequence:(e)=>`sigseq:v1:${r(e)}`,signalAcceptedResponsePrefix:(e)=>`sigres:v1:${r(e)}:`,signalAcceptedResponse:(e,t,n)=>`sigres:v1:${r(e)}:${r(t)}:${r(n)}`,deadline:(e,t)=>`wf-deadline:${s(e)}:${r(t)}`,terminalCleanup:(e,t)=>`wf-cleanup:${s(e)}:${r(t)}`,teardownTimer:(e,t)=>`wf-teardown:${s(e)}:${r(t)}`,delayedStart:(e,t)=>`wf-delayed:${s(e)}:${r(t)}`,terminalWorkflowPrefix:()=>"wf-terminal:",terminalWorkflow:(e,t)=>`wf-terminal:${s(e)}:${r(t)}`,attribute:(e)=>`attr:${r(e)}`,attributeIndex:(e,t,n)=>`idx:${e}:${t}:${r(n)}`,tagIndex:(e,t)=>`tag:${r(e)}:${r(t)}`,updatePrefix:(e)=>`upd:${r(e)}:`,update:(e,t)=>`upd:${r(e)}:${t}`,updateResponse:(e)=>`upr:${e}`,updateIdempotency:(e,t)=>`upk:${r(e)}:${t}`,startIdempotency:(e)=>`start-idem:${r(e)}`,startIdempotencySignalId:(e)=>`start-idem:${e}`,livenessPrefix:()=>"liveness:",liveness:(e)=>`liveness:${r(e)}`,leasePrefix:()=>"lease:",leaseEpoch:()=>"lease:epoch",leaseHolder:()=>"lease:holder",...B,...P,...O,...x,budget:(e,t,n)=>`budget:${e}:${t}:${n}`,review:(e,t)=>`review:${r(e)}:${t}`,workflowHeaders:(e)=>`wf-headers:${r(e)}`,childCancellationPrefix:(e)=>`child-cancel:${r(e)}:`,childCancellation:(e,t)=>`child-cancel:${r(e)}:${r(t)}`,childWorkflowByParentPrefix:(e,t)=>`child-by-parent:${r(e)}:${t===void 0?"":`${r(t)}:`}`,childWorkflowByParent:(e,t,n)=>`child-by-parent:${r(e)}:${t===void 0?"":`${r(t)}:`}${r(n)}`,terminalCleanupNeeded:(e)=>`wf-cleanup-needed:${r(e)}`,workflowConcurrency:(e,t)=>`wf-concurrency:${r(e)}:${r(t)}`,workflowConcurrencyHolder:(e)=>`wf-concurrency-holder:${r(e)}`,workflowHasServices:(e)=>`wf-has-services:${r(e)}`,finalizerState:(e)=>`wf-finalizer-state:${r(e)}`,teardownOwed:(e)=>`wf-teardown-needed:${r(e)}`,teardownSucceeded:(e)=>`wf-teardown-succeeded:${r(e)}`,teardownDeadLetter:(e)=>`wf-teardown-deadletter:${r(e)}`,offload:(e,t)=>`offload:${r(e)}:${t}`,archive:(e,t)=>`archive:${r(e)}:${t}`,stateExecution:(e,t)=>`state:execution:${r(e)}:${r(t)}`,stateWorkflow:(e,t)=>`state:workflow-scope:${y}:${r(e)}:${r(t)}`,streamChunkPrefix:(e,t)=>`blob:${r(e)}:${t}:chunk:`,streamChunk:(e,t,n)=>`blob:${r(e)}:${t}:chunk:${String(n).padStart(10,"0")}`,streamTail:(e,t)=>`blob:${r(e)}:${t}:tail`,streamMetadata:(e,t)=>`blob:${r(e)}:${t}:meta`,budgetCharged:(e)=>`budget-charged:${e}`,toolEffect:(e,t,n)=>`tool-effect:${r(e)}:${t}:${n}`,workflowVisibilityStatus:(e,t)=>`wf-idx-status:${r(e)}:${r(t)}`,workflowVisibilityType:(e,t)=>`wf-idx-type:${r(e)}:${r(t)}`,workflowVisibilityCreated:(e,t)=>`wf-idx-created:${s(e)}:${r(t)}`,workflowVisibilityUpdated:(e,t)=>`wf-idx-updated:${s(e)}:${r(t)}`,workflowVisibilityDeadline:(e,t)=>`wf-idx-deadline:${s(e)}:${r(t)}`,workflowVisibilityManifest:(e)=>`wf-idx-manifest:${r(e)}`,workflowVisibilityMetaVersion:()=>"wf-idx-meta:version",workflowVisibilityMetaBuiltAt:()=>"wf-idx-meta:built-at",workflowVisibilityMetaCursor:()=>"wf-idx-meta:cursor"};var l;function Y(){if(l&&"bun"in l)return l.bun;return globalThis.Bun}function T(){return typeof Y()<"u"}function X(){if(l&&"process"in l)return l.process;return globalThis.process}function R(e){let t=X();if(typeof t?.getBuiltinModule!=="function")return;return t.getBuiltinModule(e)}function U(){let e=R("node:zlib");if(!e)throw Error("gzip/gunzip require Bun or Node 22.5+ (process.getBuiltinModule). "+"Not available in browser or edge runtimes \u2014 use CompressionStream directly.");return e}function _(e){if(T())return new Uint8Array(Bun.gzipSync(new Uint8Array(e)));return new Uint8Array(U().gzipSync(e))}function D(e){if(T())return new Uint8Array(Bun.gunzipSync(new Uint8Array(e)));return new Uint8Array(U().gunzipSync(e))}function I(){return R("node:zlib")}function L(){let e=I();if(!e)throw Error("Brotli compression requires Bun or Node 22.5+ with process.getBuiltinModule support. Use gzip compression for browser/edge runtimes.");return e}function Z(e){return new Uint8Array(L().brotliCompressSync(e))}function j(e){return new Uint8Array(L().brotliDecompressSync(e))}var d=193,h=0,z=1,K=2,a=2;function M(e){return Q(e)}function Q(e){switch(e){case"gzip":return{algorithm:"gzip",compress(t){return _(t)}};case"brotli":return{algorithm:"brotli",compress(t){return Z(t)}};case"none":return{algorithm:"none",compress(t){return t}};default:throw Error(`Unknown compression algorithm: ${JSON.stringify(e)}`)}}async function w(e,t,n){if(e.length<n||t.algorithm==="none"){let c=new Uint8Array(e.length+a);return c[0]=d,c[1]=h,c.set(e,a),c}let i=await t.compress(e);if(i.length+a>=e.length+a){let c=new Uint8Array(e.length+a);return c[0]=d,c[1]=h,c.set(e,a),c}let f=t.algorithm==="gzip"?z:K,u=new Uint8Array(i.length+a);return u[0]=d,u[1]=f,u.set(i,a),u}async function S(e){if(e.length<a)throw Error("Compression payload missing 2-byte header.");if(e[0]!==d)throw Error("Compression payload missing magic byte 0xC1.");let t=e[1],n=e.slice(a);switch(t){case h:return n;case z:return D(n);case K:return j(n);default:throw Error(`Compression payload uses unsupported algorithm byte 0x${t.toString(16).padStart(2,"0")}.`)}}var J=4096,ee="gzip";function N(e){return{threshold:e?.threshold??J,algorithm:e?.algorithm??ee}}class te{#e;#t;#r;constructor(e,t){this.#e=e;let n=N(t);if(this.#t=M(n.algorithm),this.#r=n.threshold,e.query){let i=e.query.bind(e);Object.defineProperty(this,"query",{value:i,enumerable:!0,configurable:!0})}}capabilities(){let e=this.#e.capabilities();return{persistence:e.persistence,readAfterWrite:e.readAfterWrite,scanConsistency:e.scanConsistency,atomicBatch:e.atomicBatch,conditionalBatch:!1,boundedRangeDelete:!1}}async get(e){let t=await this.#e.get(e);if(!t)return null;return S(t)}async put(e,t){let n=await w(t,this.#t,this.#r);return this.#e.put(e,n)}async delete(e){return this.#e.delete(e)}async*scan(e,t){for await(let[n,i]of this.#e.scan(e,t))yield[n,await S(i)]}async batch(e){g("batch operations",e.length);let t=await Promise.all(e.map(async(n)=>{if(n.type==="put")return{type:"put",key:n.key,value:await w(n.value,this.#t,this.#r)};return n}));return this.#e.batch(t)}[Symbol.dispose](){this.#e[Symbol.dispose]()}}export{te as CompressedStorage};
2
+ var le=import.meta.require;function m(e,t,n){if(!e.capabilities()[t])throw Error(`Feature "${n}" requires storage capability "${t}", but this storage backend does not provide it.`)}function Z(e){let t=e.capabilities(),n=[];if(t.persistence!=="local"&&t.persistence!=="remote")n.push(`persistence must be "local" or "remote" (got "${t.persistence}")`);if(t.readAfterWrite!=="linearizable")n.push(`readAfterWrite must be "linearizable" (got "${t.readAfterWrite}")`);if(t.scanConsistency!=="snapshot")n.push(`scanConsistency must be "snapshot" (got "${t.scanConsistency}")`);if(!t.atomicBatch)n.push("atomicBatch must be true");if(!t.conditionalBatch)n.push("conditionalBatch must be true");if(n.length>0)throw Error(`Storage is not durable enough for recovery: ${n.join("; ")}.`)}function r(e){return encodeURIComponent(e)}function j(e){return decodeURIComponent(e)}function Q(e){try{return decodeURIComponent(e)}catch{return null}}function o(e){return String(e).padStart(16,"0")}var x={catalogEntry:(e,t)=>`catalog-entry:${r(e)}:${r(t)}`,catalogEntryPrefix:(e)=>`catalog-entry:${r(e)}:`,catalogActive:(e)=>`catalog-active:${r(e)}`,catalogTombstone:(e,t)=>`catalog-tombstone:${r(e)}:${r(t)}`,catalogTombstonePrefix:()=>"catalog-tombstone:"};async function C(e,t){return await e.get(t)!==null}async function*l(e,t,n){for await(let[i]of e.scan(t,n))yield i}async function v(e,t){let n=0;for await(let i of l(e,t))n++;return n}async function O(e,t){let n=[];for await(let i of l(e,t))n.push({type:"delete",key:i});if(n.length===0)return 0;return await e.batch(n),n.length}async function ye(e,t,n){let i=[];for await(let f of l(e,t,n))i.push({type:"delete",key:f});if(i.length===0)return 0;return await e.batch(i),i.length}var A={workflowGeneration:(e)=>`wf-gen:${r(e)}`};var R={livenessPrefix:()=>"liveness:",liveness:(e)=>`liveness:${r(e)}`,leasePrefix:()=>"lease:",leaseEpoch:()=>"lease:epoch",leaseHolder:()=>"lease:holder"};var _={applicationMailbox:(e,t)=>`appmbx:v1:${r(e)}:${r(t)}`,applicationMailboxSinkProbe:(e,t,n)=>`appprobe:v1:${r(e)}:${r(t)}:${r(n)}`,applicationCommandPrefix:(e,t)=>`appcmd:v1:${r(e)}:${r(t)}:`,applicationCommand:(e,t,n)=>`appcmd:v1:${r(e)}:${r(t)}:${r(n)}`,applicationCommandReadyPrefix:(e,t)=>`appready:v1:${r(e)}:${r(t)}:`,applicationCommandReady:(e,t,n)=>`appready:v1:${r(e)}:${r(t)}:${o(n)}`,applicationCommandIdempotency:(e,t,n)=>`appidem:v1:${r(e)}:${r(t)}:${r(n)}`,applicationCommandBySequencePrefix:(e,t)=>`appseq:v1:${r(e)}:${r(t)}:`,applicationCommandBySequence:(e,t,n)=>`appseq:v1:${r(e)}:${r(t)}:${o(n)}`,applicationCommandTerminalPrefix:(e,t)=>`appterm:v1:${r(e)}:${r(t)}:`,applicationCommandTerminal:(e,t,n,i)=>`appterm:v1:${r(e)}:${r(t)}:${o(n)}:${r(i)}`};var B={applicationOutbox:(e,t)=>`appobx:v1:${r(e)}:${r(t)}`,applicationOutboxSinkProbe:(e,t,n)=>`appprobe:v1:outbox:${r(e)}:${r(t)}:${r(n)}`,applicationDeliveryPrefix:(e,t)=>`appdlv:v1:${r(e)}:${r(t)}:`,applicationDelivery:(e,t,n)=>`appdlv:v1:${r(e)}:${r(t)}:${r(n)}`,applicationDeliveryDuePrefix:(e,t)=>`appdue:v1:${r(e)}:${r(t)}:`,applicationDeliveryDue:(e,t,n,i)=>`appdue:v1:${r(e)}:${r(t)}:${o(n)}:${r(i)}`,applicationDeliveryIdempotency:(e,t,n)=>`appdidem:v1:${r(e)}:${r(t)}:${r(n)}`,applicationDeliveryBySequencePrefix:(e,t)=>`appdseq:v1:${r(e)}:${r(t)}:`,applicationDeliveryBySequence:(e,t,n)=>`appdseq:v1:${r(e)}:${r(t)}:${o(n)}`,applicationDeliveryTerminalPrefix:(e,t)=>`appdterm:v1:${r(e)}:${r(t)}:`,applicationDeliveryTerminal:(e,t,n,i)=>`appdterm:v1:${r(e)}:${r(t)}:${o(n)}:${r(i)}`};var P={workflowOwnerEpoch:(e)=>`wf-owner-epoch:${r(e)}`,workflowOwnerHolder:(e)=>`wf-owner-holder:${r(e)}`,ownershipModeMarker:()=>"ownership-mode-marker"};var J="0",ee="1",T=(e,t,n,i)=>`sig:${r(e)}:${r(t)}:${i}:${r(n)}`,k={signal:(e,t,n)=>T(e,t,n,ee),startSignal:(e,t,n)=>T(e,t,n,J),signalSequence:(e)=>`sigseq:v1:${r(e)}`,signalAcceptedResponsePrefix:(e)=>`sigres:v1:${r(e)}:`,signalAcceptedResponse:(e,t,n)=>`sigres:v1:${r(e)}:${r(t)}:${r(n)}`};var y="default";var c=o,K={deadline:(e,t)=>`wf-deadline:${c(e)}:${r(t)}`,terminalCleanup:(e,t)=>`wf-cleanup:${c(e)}:${r(t)}`,teardownTimer:(e,t)=>`wf-teardown:${c(e)}:${r(t)}`,delayedStart:(e,t)=>`wf-delayed:${c(e)}:${r(t)}`,terminalWorkflowPrefix:()=>"wf-terminal:",terminalWorkflow:(e,t)=>`wf-terminal:${c(e)}:${r(t)}`},L={budget:(e,t,n)=>`budget:${e}:${t}:${n}`,review:(e,t)=>`review:${r(e)}:${t}`,workflowHeaders:(e)=>`wf-headers:${r(e)}`,childCancellationPrefix:(e)=>`child-cancel:${r(e)}:`,childCancellation:(e,t)=>`child-cancel:${r(e)}:${r(t)}`,childWorkflowByParentPrefix:(e,t)=>`child-by-parent:${r(e)}:${t===void 0?"":`${r(t)}:`}`,childWorkflowByParent:(e,t,n)=>`child-by-parent:${r(e)}:${t===void 0?"":`${r(t)}:`}${r(n)}`,terminalCleanupNeeded:(e)=>`wf-cleanup-needed:${r(e)}`,workflowConcurrency:(e,t)=>`wf-concurrency:${r(e)}:${r(t)}`,workflowConcurrencyHolder:(e)=>`wf-concurrency-holder:${r(e)}`,workflowHasServices:(e)=>`wf-has-services:${r(e)}`,finalizerState:(e)=>`wf-finalizer-state:${r(e)}`,teardownOwed:(e)=>`wf-teardown-needed:${r(e)}`,teardownSucceeded:(e)=>`wf-teardown-succeeded:${r(e)}`,teardownDeadLetter:(e)=>`wf-teardown-deadletter:${r(e)}`,offload:(e,t)=>`offload:${r(e)}:${t}`,archive:(e,t)=>`archive:${r(e)}:${t}`,stateExecution:(e,t)=>`state:execution:${r(e)}:${r(t)}`,stateWorkflow:(e,t)=>`state:workflow-scope:${y}:${r(e)}:${r(t)}`,streamChunkPrefix:(e,t)=>`blob:${r(e)}:${t}:chunk:`,streamChunk:(e,t,n)=>`blob:${r(e)}:${t}:chunk:${String(n).padStart(10,"0")}`,streamTail:(e,t)=>`blob:${r(e)}:${t}:tail`,streamMetadata:(e,t)=>`blob:${r(e)}:${t}:meta`,budgetCharged:(e)=>`budget-charged:${e}`,toolEffect:(e,t,n)=>`tool-effect:${r(e)}:${t}:${n}`,workflowVisibilityStatus:(e,t)=>`wf-idx-status:${r(e)}:${r(t)}`,workflowVisibilityType:(e,t)=>`wf-idx-type:${r(e)}:${r(t)}`,workflowVisibilityCreated:(e,t)=>`wf-idx-created:${c(e)}:${r(t)}`,workflowVisibilityUpdated:(e,t)=>`wf-idx-updated:${c(e)}:${r(t)}`,workflowVisibilityDeadline:(e,t)=>`wf-idx-deadline:${c(e)}:${r(t)}`,workflowVisibilityManifest:(e)=>`wf-idx-manifest:${r(e)}`,workflowVisibilityMetaVersion:()=>"wf-idx-meta:version",workflowVisibilityMetaBuiltAt:()=>"wf-idx-meta:built-at",workflowVisibilityMetaCursor:()=>"wf-idx-meta:cursor"};var b=o,D={workflow:(e)=>`wf:${r(e)}`,checkpoint:(e)=>`wf:${r(e)}:ckpt`,checkpointHistory:(e,t)=>`wf:${r(e)}:ckpt:${String(t).padStart(10,"0")}`,timelinePrefix:(e)=>`wf:${r(e)}:timeline:`,timeline:(e,t)=>`wf:${r(e)}:timeline:${String(t).padStart(10,"0")}`,schedule:(e)=>`schedule:${r(e)}`,scheduleTick:(e,t)=>`schedule-due:${String(e).padStart(16,"0")}:${r(t)}`,scheduleRun:(e)=>`schedule-run:${r(e)}`,scheduleRunLink:(e)=>`schedule-run-link:${r(e)}`,scheduleRunBySchedulePrefix:(e)=>`schedule-run-by-schedule:${r(e)}:`,scheduleRunBySchedule:(e,t)=>`schedule-run-by-schedule:${r(e)}:${r(t)}`,operation:(e,t,n)=>`op:${e}:${b(t)}:${n}`,operationInflight:(e)=>`op:inflight:${e}`,operationQueued:(e)=>`op:queued:${e}`,operationResolved:(e)=>`op:resolved:${e}`,bulkOperationAuditPrefix:()=>"audit:bulk:",bulkOperationAudit:(e,t,n)=>`audit:bulk:${b(e)}:${r(t)}:${r(n)}`,operationResolvedByTimePrefix:()=>"op:resolved-by-time:",operationResolvedByTime:(e,t)=>`op:resolved-by-time:${b(e)}:${r(t)}`,asyncActivity:(e,t)=>`async-act:v1:${r(e)}:${r(t)}`,asyncActivityResolution:(e,t)=>`async-act:v1:${r(e)}:${r(t)}:resolution`,activityReconciliationPrefix:(e)=>`actrec:v1:${r(e)}:`,activityReconciliation:(e,t,n)=>`actrec:v1:${r(e)}:${r(t)}:${n}`,eventPrefix:(e)=>`ev:${r(e)}:`,event:(e,t)=>`ev:${r(e)}:${String(t).padStart(10,"0")}`,eventHead:(e)=>`ev:${r(e)}:head`,eventWatermark:(e)=>`ev:${r(e)}:watermark`,fleetEventPrefix:()=>"fleet-event:",fleetEvent:(e)=>`fleet-event:${String(e).padStart(10,"0")}`,fleetEventTail:()=>"fleet-event-tail",fleetEventWatermark:()=>"fleet-event-watermark",fleetEventByWorkflowPrefix:(e)=>`fleet-event-by-workflow:${r(e)}:`,fleetEventByWorkflow:(e,t)=>`fleet-event-by-workflow:${r(e)}:${String(t).padStart(10,"0")}`},U={attribute:(e)=>`attr:${r(e)}`,attributeIndex:(e,t,n)=>`idx:${e}:${t}:${r(n)}`,tagIndex:(e,t)=>`tag:${r(e)}:${r(t)}`,updatePrefix:(e)=>`upd:${r(e)}:`,update:(e,t)=>`upd:${r(e)}:${t}`,updateResponse:(e)=>`upr:${e}`,updateIdempotency:(e,t)=>`upk:${r(e)}:${t}`,startIdempotency:(e)=>`start-idem:${r(e)}`,startIdempotencySignalId:(e)=>`start-idem:${e}`};var te=["actrec:","appcmd:","appdidem:","appdlv:","appdseq:","appdterm:","appdue:","appidem:","appmbx:","appobx:","appprobe:","appready:","appseq:","appterm:","archive:","async-act:","attr:","audit:bulk:","blob:","budget:","budget-charged:","catalog-active:","catalog-entry:","catalog-tombstone:","child-by-parent:","ev:","fleet-event-by-workflow:","fleet-event:","fleet-event-tail","fleet-event-watermark","idx:","lease:","liveness:","offload:","ownership-mode-marker","op:","review:","schedule:","schedule-due:","schedule-run-by-schedule:","schedule-run-link:","schedule-run:","sig:","sigres:","sigseq:","start-idem:","state:","tag:","tool-effect:","upd:","upk:","upr:","wf:","wf-cleanup:","wf-cleanup-needed:","wf-concurrency:","wf-concurrency-holder:","wf-deadline:","wf-delayed:","wf-finalizer-state:","wf-gen:","wf-has-services:","wf-headers:","wf-idx-","wf-owner-epoch:","wf-owner-holder:","wf-teardown:","wf-teardown-deadletter:","wf-teardown-needed:","wf-teardown-succeeded:","wf-terminal:"];var h=1e4,Ve=1e4;class I extends Error{code="StorageBatchOperationLimitExceededError";cap=h;count;target;constructor(e,t){super(`${e} count ${t} exceeds MAX_BATCH_OPERATIONS (${h}).`);this.name="StorageBatchOperationLimitExceededError",this.target=e,this.count=t}}function g(e,t){if(t>h)throw new I(e,t)}function Xe(e){return e.length>0?e.slice(0,-1)+String.fromCharCode(e.charCodeAt(e.length-1)+1):"\xFF"}function Ze(e,t={}){if(t.gt!==void 0&&e<=t.gt)return!1;if(t.gte!==void 0&&e<t.gte)return!1;if(t.lt!==void 0&&e>=t.lt)return!1;if(t.lte!==void 0&&e>t.lte)return!1;return!0}function je(e,t){if(e===null||t===null)return e===t;if(e.byteLength!==t.byteLength)return!1;for(let n=0;n<e.byteLength;n++)if(e[n]!==t[n])return!1;return!0}async function Qe(e,t){if(e.has)return e.has(t);return C(e,t)}function Je(e,t,n){if(e.keys)return e.keys(t,n);return l(e,t,n)}async function et(e,t){if(e.count)return e.count(t);return v(e,t)}async function tt(e,t){if(e.deletePrefix)return e.deletePrefix(t);return O(e,t)}async function rt(e,t){g("batch operations",t.length),await e.batch(t)}async function nt(e,t,n){if(g("conditionalBatch conditions",t.length),g("conditionalBatch operations",n.length),m(e,"conditionalBatch","storageConditionalBatch"),!e.conditionalBatch)throw Error("This storage backend reports conditionalBatch capability but does not implement the conditionalBatch() method.");return e.conditionalBatch(t,n)}var it={...D,...k,...K,...U,...R,..._,...B,...P,...x,...A,...L};var p;function re(){if(p&&"bun"in p)return p.bun;return globalThis.Bun}function N(){return typeof re()<"u"}function ne(){if(p&&"process"in p)return p.process;return globalThis.process}function W(e){let t=ne();if(typeof t?.getBuiltinModule!=="function")return;return t.getBuiltinModule(e)}function Y(){let e=W("node:zlib");if(!e)throw Error("gzip/gunzip require Bun or Node 22.5+ (process.getBuiltinModule). "+"Not available in browser or edge runtimes \u2014 use CompressionStream directly.");return e}function F(e){if(N())return new Uint8Array(Bun.gzipSync(new Uint8Array(e)));return new Uint8Array(Y().gzipSync(e))}function z(e){if(N())return new Uint8Array(Bun.gunzipSync(new Uint8Array(e)));return new Uint8Array(Y().gunzipSync(e))}function M(){return W("node:zlib")}function q(){let e=M();if(!e)throw Error("Brotli compression requires Bun or Node 22.5+ with process.getBuiltinModule support. Use gzip compression for browser/edge runtimes.");return e}function ie(e){return new Uint8Array(q().brotliCompressSync(e))}function oe(e){return new Uint8Array(q().brotliDecompressSync(e))}var u=193,S=0,G=1,H=2,s=2;function V(e){return se(e)}function se(e){switch(e){case"gzip":return{algorithm:"gzip",compress(t){return F(t)}};case"brotli":return{algorithm:"brotli",compress(t){return ie(t)}};case"none":return{algorithm:"none",compress(t){return t}};default:throw Error(`Unknown compression algorithm: ${JSON.stringify(e)}`)}}async function w(e,t,n){if(e.length<n||t.algorithm==="none"){let a=new Uint8Array(e.length+s);return a[0]=u,a[1]=S,a.set(e,s),a}let i=await t.compress(e);if(i.length+s>=e.length+s){let a=new Uint8Array(e.length+s);return a[0]=u,a[1]=S,a.set(e,s),a}let f=t.algorithm==="gzip"?G:H,d=new Uint8Array(i.length+s);return d[0]=u,d[1]=f,d.set(i,s),d}async function E(e){if(e.length<s)throw Error("Compression payload missing 2-byte header.");if(e[0]!==u)throw Error("Compression payload missing magic byte 0xC1.");let t=e[1],n=e.slice(s);switch(t){case S:return n;case G:return z(n);case H:return oe(n);default:throw Error(`Compression payload uses unsupported algorithm byte 0x${t.toString(16).padStart(2,"0")}.`)}}var ae=4096,ce="gzip";function X(e){return{threshold:e?.threshold??ae,algorithm:e?.algorithm??ce}}class pe{#e;#t;#r;constructor(e,t){this.#e=e;let n=X(t);if(this.#t=V(n.algorithm),this.#r=n.threshold,e.query){let i=e.query.bind(e);Object.defineProperty(this,"query",{value:i,enumerable:!0,configurable:!0})}}capabilities(){let e=this.#e.capabilities();return{persistence:e.persistence,readAfterWrite:e.readAfterWrite,scanConsistency:e.scanConsistency,atomicBatch:e.atomicBatch,conditionalBatch:!1,boundedRangeDelete:!1}}async get(e){let t=await this.#e.get(e);if(!t)return null;return E(t)}async put(e,t){let n=await w(t,this.#t,this.#r);return this.#e.put(e,n)}async delete(e){return this.#e.delete(e)}async*scan(e,t){for await(let[n,i]of this.#e.scan(e,t))yield[n,await E(i)]}async batch(e){g("batch operations",e.length);let t=await Promise.all(e.map(async(n)=>{if(n.type==="put")return{type:"put",key:n.key,value:await w(n.value,this.#t,this.#r)};return n}));return this.#e.batch(t)}[Symbol.dispose](){this.#e[Symbol.dispose]()}}export{pe as CompressedStorage};
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Storage key builder for the durable per-workflow-id generation counter
3
+ * (WFT-153).
4
+ *
5
+ * This is spread into `KEYS` in `interface.ts` rather than declared there, so
6
+ * it can carry its full rationale without pushing that file's documented line
7
+ * ceiling. Callers still reach it through `KEYS`, which keeps one import
8
+ * contract for storage keys.
9
+ *
10
+ * @module storage/generation-keys
11
+ */
12
+ /**
13
+ * A monotonic per-workflow-id generation counter, spread into `KEYS`; not
14
+ * intended to be imported directly by engine code.
15
+ *
16
+ * `wf-gen:<id>` closes the explicit-id start fence's pre-CAS ABA (WFT-153,
17
+ * following WFT-152): `start-terminal-conflict-purge.ts`'s duplicate-id
18
+ * `conditionalBatch` precondition compares the observed `wf:<id>` VALUE, so
19
+ * it cannot tell "this id was never used" from "a run existed here and was
20
+ * purged" — if a racing winner completes and is purged before a slower
21
+ * loser's batch commits, `wf:<id>` looks absent again and both starts
22
+ * execute. This counter is bumped in the SAME atomic batch that deletes
23
+ * `wf:<id>` on purge (`engine.purge()` and the retention sweep, plus a
24
+ * `onTerminalConflict: 'start-new'` restart's own displacing purge), so a
25
+ * duplicate-id start's `conditionalBatch` can carry an ADDITIONAL condition
26
+ * on the exact generation bytes it observed — a purge in the read-to-commit
27
+ * gap changes this key even though `wf:<id>` reads the same, so the stale
28
+ * loser's condition fails where a value-only comparison could not detect it.
29
+ *
30
+ * Like `wf-owner-epoch:<id>` (`ownership-keys.ts`), which is the precedent
31
+ * this key's mechanism and permanence both follow, this key is
32
+ * **permanently retained**: never deleted by release, purge, retention, or a
33
+ * mode downgrade. Retention is what makes the fence ABA-safe across
34
+ * unbounded id reuse — the counter is never reset, so a stale reader's
35
+ * captured value can never coincide with a later generation's.
36
+ *
37
+ * Unlike `wf-owner-epoch`, which is written only under
38
+ * `ownership: 'workflow-lease'`, this key is written under EVERY ownership
39
+ * mode (`'none'`, `'lease'`, `'workflow-lease'`): the ABA hole this closes
40
+ * exists whenever an explicit-id start can race a purge, which has nothing
41
+ * to do with per-workflow claim fencing — `'none'` and `'lease'` have no
42
+ * epoch condition on the workflow record at all today.
43
+ *
44
+ * Encoded exactly like `wf-owner-epoch` — an 8-byte big-endian uint64 via
45
+ * `encodeGeneration`/`decodeGeneration` (`core/engine/generation-codec.ts`,
46
+ * which re-exports `lease-codec.ts`'s `encodeEpoch`/`decodeEpoch` under
47
+ * generation-specific names) — so both permanently-retained monotonic
48
+ * counters share one representation and one validity range.
49
+ */
50
+ export declare const GENERATION_KEYS: {
51
+ readonly workflowGeneration: (workflowId: string) => string;
52
+ };
@@ -0,0 +1,4 @@
1
+ import { encodeStorageKeyComponent } from "./key-encoding.js";
2
+ export const GENERATION_KEYS = {
3
+ workflowGeneration: (workflowId) => `wf-gen:${encodeStorageKeyComponent(workflowId)}`
4
+ };
@@ -82,70 +82,6 @@ declare const exportedCopyTextKeyValueRowsToStorage: typeof copyTextKeyValueRows
82
82
  * ```
83
83
  */
84
84
  declare const exportedKeys: {
85
- readonly budget: (namespace: string, period: string, date: string) => string;
86
- readonly review: (workflowId: string, reviewId: string) => string;
87
- readonly workflowHeaders: (workflowId: string) => string;
88
- readonly childCancellationPrefix: (workflowId: string) => string;
89
- readonly childCancellation: (workflowId: string, childWorkflowId: string) => string;
90
- readonly childWorkflowByParentPrefix: (parentWorkflowId: string, parentWorkflowExecutionToken?: string) => string;
91
- readonly childWorkflowByParent: (parentWorkflowId: string, parentWorkflowExecutionToken: string | undefined, childWorkflowId: string) => string;
92
- readonly terminalCleanupNeeded: (workflowId: string) => string;
93
- readonly workflowConcurrency: (workflowType: string, partitionKey: string) => string;
94
- readonly workflowConcurrencyHolder: (workflowId: string) => string;
95
- readonly workflowHasServices: (workflowId: string) => string;
96
- readonly finalizerState: (workflowId: string) => string;
97
- readonly teardownOwed: (workflowId: string) => string;
98
- readonly teardownSucceeded: (workflowId: string) => string;
99
- readonly teardownDeadLetter: (workflowId: string) => string;
100
- readonly offload: (workflowId: string, key: string) => string;
101
- readonly archive: (workflowId: string, key: string) => string;
102
- readonly stateExecution: (ownerWorkflowId: string, key: string) => string;
103
- readonly stateWorkflow: (workflowType: string, key: string) => string;
104
- readonly streamChunkPrefix: (workflowId: string, key: string) => string;
105
- readonly streamChunk: (workflowId: string, key: string, chunkIndex: number) => string;
106
- readonly streamTail: (workflowId: string, key: string) => string;
107
- readonly streamMetadata: (workflowId: string, key: string) => string;
108
- readonly budgetCharged: (operationId: string) => string;
109
- readonly toolEffect: (workflowId: string, agentId: string, semanticHash: string) => string;
110
- readonly workflowVisibilityStatus: (status: string, workflowId: string) => string;
111
- readonly workflowVisibilityType: (type: string, workflowId: string) => string;
112
- readonly workflowVisibilityCreated: (createdAt: number, workflowId: string) => string;
113
- readonly workflowVisibilityUpdated: (updatedAt: number, workflowId: string) => string;
114
- readonly workflowVisibilityDeadline: (deadline: number, workflowId: string) => string;
115
- readonly workflowVisibilityManifest: (workflowId: string) => string;
116
- readonly workflowVisibilityMetaVersion: () => string;
117
- readonly workflowVisibilityMetaBuiltAt: () => string;
118
- readonly workflowVisibilityMetaCursor: () => string;
119
- readonly catalogEntry: (name: string, revision: string) => string;
120
- readonly catalogEntryPrefix: (name: string) => string;
121
- readonly catalogActive: (name: string) => string;
122
- readonly catalogTombstone: (name: string, revision: string) => string;
123
- readonly catalogTombstonePrefix: () => string;
124
- readonly workflowOwnerEpoch: (workflowId: string) => string;
125
- readonly workflowOwnerHolder: (workflowId: string) => string;
126
- readonly ownershipModeMarker: () => string;
127
- readonly applicationOutbox: (namespace: string, ownerId: string) => string;
128
- readonly applicationOutboxSinkProbe: (namespace: string, ownerId: string, nonce: string) => string;
129
- readonly applicationDeliveryPrefix: (namespace: string, ownerId: string) => string;
130
- readonly applicationDelivery: (namespace: string, ownerId: string, deliveryId: string) => string;
131
- readonly applicationDeliveryDuePrefix: (namespace: string, ownerId: string) => string;
132
- readonly applicationDeliveryDue: (namespace: string, ownerId: string, availableAt: number, deliveryId: string) => string;
133
- readonly applicationDeliveryIdempotency: (namespace: string, ownerId: string, key: string) => string;
134
- readonly applicationDeliveryBySequencePrefix: (namespace: string, ownerId: string) => string;
135
- readonly applicationDeliveryBySequence: (namespace: string, ownerId: string, sequence: number) => string;
136
- readonly applicationDeliveryTerminalPrefix: (namespace: string, ownerId: string) => string;
137
- readonly applicationDeliveryTerminal: (namespace: string, ownerId: string, terminalAt: number, deliveryId: string) => string;
138
- readonly applicationMailbox: (namespace: string, resourceId: string) => string;
139
- readonly applicationMailboxSinkProbe: (namespace: string, resourceId: string, nonce: string) => string;
140
- readonly applicationCommandPrefix: (namespace: string, resourceId: string) => string;
141
- readonly applicationCommand: (namespace: string, resourceId: string, commandId: string) => string;
142
- readonly applicationCommandReadyPrefix: (namespace: string, resourceId: string) => string;
143
- readonly applicationCommandReady: (namespace: string, resourceId: string, sequence: number) => string;
144
- readonly applicationCommandIdempotency: (namespace: string, resourceId: string, key: string) => string;
145
- readonly applicationCommandBySequencePrefix: (namespace: string, resourceId: string) => string;
146
- readonly applicationCommandBySequence: (namespace: string, resourceId: string, sequence: number) => string;
147
- readonly applicationCommandTerminalPrefix: (namespace: string, resourceId: string) => string;
148
- readonly applicationCommandTerminal: (namespace: string, resourceId: string, terminalAt: number, commandId: string) => string;
149
85
  readonly workflow: (id: string) => string;
150
86
  readonly checkpoint: (id: string) => string;
151
87
  readonly checkpointHistory: (id: string, step: number) => string;
@@ -179,17 +115,20 @@ declare const exportedKeys: {
179
115
  readonly fleetEventWatermark: () => string;
180
116
  readonly fleetEventByWorkflowPrefix: (workflowId: string) => string;
181
117
  readonly fleetEventByWorkflow: (workflowId: string, sequence: number) => string;
118
+ } & {
182
119
  readonly signal: (workflowId: string, name: string, id: string) => string;
183
120
  readonly startSignal: (workflowId: string, name: string, id: string) => string;
184
121
  readonly signalSequence: (workflowId: string) => string;
185
122
  readonly signalAcceptedResponsePrefix: (workflowId: string) => string;
186
123
  readonly signalAcceptedResponse: (workflowId: string, name: string, signalId: string) => string;
124
+ } & {
187
125
  readonly deadline: (deadline: number, workflowId: string) => string;
188
126
  readonly terminalCleanup: (fireAt: number, timerId: string) => string;
189
127
  readonly teardownTimer: (fireAt: number, timerId: string) => string;
190
128
  readonly delayedStart: (startAt: number, workflowId: string) => string;
191
129
  readonly terminalWorkflowPrefix: () => string;
192
130
  readonly terminalWorkflow: (updatedAt: number, workflowId: string) => string;
131
+ } & {
193
132
  readonly attribute: (workflowId: string) => string;
194
133
  readonly attributeIndex: (attributeName: string, encodedValue: string, workflowId: string) => string;
195
134
  readonly tagIndex: (tag: string, workflowId: string) => string;
@@ -199,11 +138,83 @@ declare const exportedKeys: {
199
138
  readonly updateIdempotency: (workflowId: string, key: string) => string;
200
139
  readonly startIdempotency: (key: string) => string;
201
140
  readonly startIdempotencySignalId: (key: string) => string;
141
+ } & {
202
142
  readonly livenessPrefix: () => string;
203
143
  readonly liveness: (instanceId: string) => string;
204
144
  readonly leasePrefix: () => string;
205
145
  readonly leaseEpoch: () => string;
206
146
  readonly leaseHolder: () => string;
147
+ } & {
148
+ readonly applicationMailbox: (namespace: string, resourceId: string) => string;
149
+ readonly applicationMailboxSinkProbe: (namespace: string, resourceId: string, nonce: string) => string;
150
+ readonly applicationCommandPrefix: (namespace: string, resourceId: string) => string;
151
+ readonly applicationCommand: (namespace: string, resourceId: string, commandId: string) => string;
152
+ readonly applicationCommandReadyPrefix: (namespace: string, resourceId: string) => string;
153
+ readonly applicationCommandReady: (namespace: string, resourceId: string, sequence: number) => string;
154
+ readonly applicationCommandIdempotency: (namespace: string, resourceId: string, key: string) => string;
155
+ readonly applicationCommandBySequencePrefix: (namespace: string, resourceId: string) => string;
156
+ readonly applicationCommandBySequence: (namespace: string, resourceId: string, sequence: number) => string;
157
+ readonly applicationCommandTerminalPrefix: (namespace: string, resourceId: string) => string;
158
+ readonly applicationCommandTerminal: (namespace: string, resourceId: string, terminalAt: number, commandId: string) => string;
159
+ } & {
160
+ readonly applicationOutbox: (namespace: string, ownerId: string) => string;
161
+ readonly applicationOutboxSinkProbe: (namespace: string, ownerId: string, nonce: string) => string;
162
+ readonly applicationDeliveryPrefix: (namespace: string, ownerId: string) => string;
163
+ readonly applicationDelivery: (namespace: string, ownerId: string, deliveryId: string) => string;
164
+ readonly applicationDeliveryDuePrefix: (namespace: string, ownerId: string) => string;
165
+ readonly applicationDeliveryDue: (namespace: string, ownerId: string, availableAt: number, deliveryId: string) => string;
166
+ readonly applicationDeliveryIdempotency: (namespace: string, ownerId: string, key: string) => string;
167
+ readonly applicationDeliveryBySequencePrefix: (namespace: string, ownerId: string) => string;
168
+ readonly applicationDeliveryBySequence: (namespace: string, ownerId: string, sequence: number) => string;
169
+ readonly applicationDeliveryTerminalPrefix: (namespace: string, ownerId: string) => string;
170
+ readonly applicationDeliveryTerminal: (namespace: string, ownerId: string, terminalAt: number, deliveryId: string) => string;
171
+ } & {
172
+ readonly workflowOwnerEpoch: (workflowId: string) => string;
173
+ readonly workflowOwnerHolder: (workflowId: string) => string;
174
+ readonly ownershipModeMarker: () => string;
175
+ } & {
176
+ readonly catalogEntry: (name: string, revision: string) => string;
177
+ readonly catalogEntryPrefix: (name: string) => string;
178
+ readonly catalogActive: (name: string) => string;
179
+ readonly catalogTombstone: (name: string, revision: string) => string;
180
+ readonly catalogTombstonePrefix: () => string;
181
+ } & {
182
+ readonly workflowGeneration: (workflowId: string) => string;
183
+ } & {
184
+ readonly budget: (namespace: string, period: string, date: string) => string;
185
+ readonly review: (workflowId: string, reviewId: string) => string;
186
+ readonly workflowHeaders: (workflowId: string) => string;
187
+ readonly childCancellationPrefix: (workflowId: string) => string;
188
+ readonly childCancellation: (workflowId: string, childWorkflowId: string) => string;
189
+ readonly childWorkflowByParentPrefix: (parentWorkflowId: string, parentWorkflowExecutionToken?: string) => string;
190
+ readonly childWorkflowByParent: (parentWorkflowId: string, parentWorkflowExecutionToken: string | undefined, childWorkflowId: string) => string;
191
+ readonly terminalCleanupNeeded: (workflowId: string) => string;
192
+ readonly workflowConcurrency: (workflowType: string, partitionKey: string) => string;
193
+ readonly workflowConcurrencyHolder: (workflowId: string) => string;
194
+ readonly workflowHasServices: (workflowId: string) => string;
195
+ readonly finalizerState: (workflowId: string) => string;
196
+ readonly teardownOwed: (workflowId: string) => string;
197
+ readonly teardownSucceeded: (workflowId: string) => string;
198
+ readonly teardownDeadLetter: (workflowId: string) => string;
199
+ readonly offload: (workflowId: string, key: string) => string;
200
+ readonly archive: (workflowId: string, key: string) => string;
201
+ readonly stateExecution: (ownerWorkflowId: string, key: string) => string;
202
+ readonly stateWorkflow: (workflowType: string, key: string) => string;
203
+ readonly streamChunkPrefix: (workflowId: string, key: string) => string;
204
+ readonly streamChunk: (workflowId: string, key: string, chunkIndex: number) => string;
205
+ readonly streamTail: (workflowId: string, key: string) => string;
206
+ readonly streamMetadata: (workflowId: string, key: string) => string;
207
+ readonly budgetCharged: (operationId: string) => string;
208
+ readonly toolEffect: (workflowId: string, agentId: string, semanticHash: string) => string;
209
+ readonly workflowVisibilityStatus: (status: string, workflowId: string) => string;
210
+ readonly workflowVisibilityType: (type: string, workflowId: string) => string;
211
+ readonly workflowVisibilityCreated: (createdAt: number, workflowId: string) => string;
212
+ readonly workflowVisibilityUpdated: (updatedAt: number, workflowId: string) => string;
213
+ readonly workflowVisibilityDeadline: (deadline: number, workflowId: string) => string;
214
+ readonly workflowVisibilityManifest: (workflowId: string) => string;
215
+ readonly workflowVisibilityMetaVersion: () => string;
216
+ readonly workflowVisibilityMetaBuiltAt: () => string;
217
+ readonly workflowVisibilityMetaCursor: () => string;
207
218
  };
208
219
  /**
209
220
  * Re-exported {@link MAX_BATCH_OPERATIONS}. See the original declaration for full docs.
@@ -384,7 +395,7 @@ declare const exportedTextValueStore: typeof textValueStore;
384
395
  * void isWeftKey;
385
396
  * ```
386
397
  */
387
- declare const exportedWeftReservedKeyPrefixes: readonly ["actrec:", "appcmd:", "appdidem:", "appdlv:", "appdseq:", "appdterm:", "appdue:", "appidem:", "appmbx:", "appobx:", "appprobe:", "appready:", "appseq:", "appterm:", "archive:", "async-act:", "attr:", "audit:bulk:", "blob:", "budget:", "budget-charged:", "catalog-active:", "catalog-entry:", "catalog-tombstone:", "child-by-parent:", "ev:", "fleet-event-by-workflow:", "fleet-event:", "fleet-event-tail", "fleet-event-watermark", "idx:", "lease:", "liveness:", "offload:", "ownership-mode-marker", "op:", "review:", "schedule:", "schedule-due:", "schedule-run-by-schedule:", "schedule-run-link:", "schedule-run:", "sig:", "sigres:", "sigseq:", "start-idem:", "state:", "tag:", "tool-effect:", "upd:", "upk:", "upr:", "wf:", "wf-cleanup:", "wf-cleanup-needed:", "wf-concurrency:", "wf-concurrency-holder:", "wf-deadline:", "wf-delayed:", "wf-finalizer-state:", "wf-has-services:", "wf-headers:", "wf-idx-", "wf-owner-epoch:", "wf-owner-holder:", "wf-teardown:", "wf-teardown-deadletter:", "wf-teardown-needed:", "wf-teardown-succeeded:", "wf-terminal:"];
398
+ declare const exportedWeftReservedKeyPrefixes: readonly ["actrec:", "appcmd:", "appdidem:", "appdlv:", "appdseq:", "appdterm:", "appdue:", "appidem:", "appmbx:", "appobx:", "appprobe:", "appready:", "appseq:", "appterm:", "archive:", "async-act:", "attr:", "audit:bulk:", "blob:", "budget:", "budget-charged:", "catalog-active:", "catalog-entry:", "catalog-tombstone:", "child-by-parent:", "ev:", "fleet-event-by-workflow:", "fleet-event:", "fleet-event-tail", "fleet-event-watermark", "idx:", "lease:", "liveness:", "offload:", "ownership-mode-marker", "op:", "review:", "schedule:", "schedule-due:", "schedule-run-by-schedule:", "schedule-run-link:", "schedule-run:", "sig:", "sigres:", "sigseq:", "start-idem:", "state:", "tag:", "tool-effect:", "upd:", "upk:", "upr:", "wf:", "wf-cleanup:", "wf-cleanup-needed:", "wf-concurrency:", "wf-concurrency-holder:", "wf-deadline:", "wf-delayed:", "wf-finalizer-state:", "wf-gen:", "wf-has-services:", "wf-headers:", "wf-idx-", "wf-owner-epoch:", "wf-owner-holder:", "wf-teardown:", "wf-teardown-deadletter:", "wf-teardown-needed:", "wf-teardown-succeeded:", "wf-terminal:"];
388
399
  /**
389
400
  * Re-exported {@link withCodec}. See the original declaration for full docs.
390
401
  *