@voltro/workflow 0.83.0 → 0.83.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.
@@ -1,180 +1,180 @@
1
1
  import { E as e, F as t, L as n, M as r, N as i, P as a, R as o, T as s, w as c } from "./primitives-Btjhjm8P.js";
2
2
  import { S as l, T as u, _ as d, a as f, b as p, g as m, h, i as g, l as _, n as v, u as y, v as ee, x as b } from "./journalEncryption--n5VDdYO.js";
3
- import { $ as x, A as te, At as ne, C as re, Ct as ie, D as ae, Dt as S, E as C, Et as w, F as oe, Ft as se, H as ce, Ht as T, I as E, It as le, J as ue, Kt as D, L as de, Mt as O, N as k, Nt as A, O as fe, Pt as pe, Q as j, Rt as M, S as me, T as he, Tt as N, U as ge, Ut as _e, V as ve, Z as ye, _t as be, bt as xe, ct as Se, ft as P, gt as Ce, h as we, i as Te, it as Ee, jt as De, k as Oe, kt as ke, ot as Ae, pt as je, q as Me, qt as Ne, rt as F, st as Pe, tt as Fe, v as Ie, vt as Le, w as Re, wt as ze, xt as Be, y as Ve, yt as He } from "./clusterDiagnostics-CGUtnJkX.js";
4
- import { DurableClock as Ue, DurableDeferred as We, Workflow as Ge, WorkflowEngine as Ke } from "@effect/workflow";
5
- import { Cause as I, Effect as L, Either as R, Exit as qe, Fiber as Je, FiberRef as Ye, Layer as Xe, Schema as z } from "effect";
6
- import { WorkflowQueuedCancellationResultSchema as Ze, publishServerError as Qe } from "@voltro/protocol";
7
- import { and as B, boolean as $e, derivedRowId as et, eq as V, generateId as tt, gt as H, gte as nt, id as U, inSet as rt, integer as W, isNotNull as it, isNull as G, json as K, lt as at, or as ot, queryFor as st, real as ct, reference as lt, registerRetention as ut, retentionTtlMsFromEnv as dt, table as q, text as J, timestamp as Y } from "@voltro/database";
8
- import { createHash as ft, randomUUID as pt } from "node:crypto";
9
- import { WorkflowInstance as mt } from "@effect/workflow/WorkflowEngine";
3
+ import { $ as x, A as te, At as ne, C as re, Ct as ie, D as ae, Dt as S, E as C, Et as w, F as oe, Ft as se, H as ce, Ht as T, I as E, It as le, J as ue, Kt as D, L as de, Mt as fe, N as O, Nt as k, O as pe, Pt as me, Q as A, Rt as j, S as he, T as ge, Tt as M, U as _e, Ut as ve, V as ye, Z as be, _t as xe, bt as Se, ct as Ce, ft as N, gt as we, h as Te, i as Ee, it as De, jt as Oe, k as ke, kt as Ae, ot as je, pt as Me, q as Ne, qt as Pe, rt as P, st as Fe, tt as Ie, v as Le, vt as Re, w as ze, wt as Be, xt as Ve, y as He, yt as Ue } from "./clusterDiagnostics-CGUtnJkX.js";
4
+ import { DurableClock as We, DurableDeferred as Ge, Workflow as Ke, WorkflowEngine as qe } from "@effect/workflow";
5
+ import { Cause as F, Context as Je, Effect as I, Either as L, Exit as Ye, Fiber as Xe, FiberRef as Ze, Layer as Qe, Schema as R } from "effect";
6
+ import { WorkflowQueuedCancellationResultSchema as $e, publishServerError as et } from "@voltro/protocol";
7
+ import { and as z, boolean as tt, derivedRowId as nt, eq as B, generateId as rt, gt as V, gte as it, id as H, inSet as at, integer as U, isNotNull as ot, isNull as W, json as G, lt as st, or as ct, queryFor as lt, real as ut, reference as dt, registerRetention as ft, retentionTtlMsFromEnv as pt, table as K, text as q, timestamp as J } from "@voltro/database";
8
+ import { createHash as mt, randomUUID as ht } from "node:crypto";
9
+ import { WorkflowInstance as Y } from "@effect/workflow/WorkflowEngine";
10
10
  //#region src/inMemoryLayer.ts
11
- var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
12
- id: U({ prefix: "wfrun" }),
13
- tag: J(),
14
- executionId: J().unique(),
15
- status: J().oneOf([
11
+ var gt = qe.layerMemory, _t = K("_voltro_workflow_runs", {
12
+ id: H({ prefix: "wfrun" }),
13
+ tag: q(),
14
+ executionId: q().unique(),
15
+ status: q().oneOf([
16
16
  "running",
17
17
  "succeeded",
18
18
  "failed",
19
19
  "cancelled",
20
20
  "suspended"
21
21
  ]).default("running"),
22
- payload: K(),
23
- workflowVersion: J().nullable(),
24
- workflowPatches: K().nullable(),
25
- runnerEnteredAt: Y().nullable(),
26
- runnerGeneration: J().nullable(),
27
- engineDelivery: K().nullable(),
28
- reclaimCount: W().default(0),
29
- output: K().nullable(),
30
- subject: K().nullable(),
31
- source: J().nullable(),
32
- errorTag: J().nullable(),
33
- errorMessage: J().nullable(),
34
- cancelled: $e().default(!1),
35
- discardedAt: Y().nullable(),
36
- discardedBy: J().nullable(),
37
- startedAt: Y().default("now"),
38
- completedAt: Y().nullable(),
39
- durationMs: W().nullable(),
40
- traceId: J().nullable(),
41
- parentExecutionId: J().nullable(),
42
- parentGeneration: J().nullable(),
43
- parentClosePolicy: J().oneOf([
22
+ payload: G(),
23
+ workflowVersion: q().nullable(),
24
+ workflowPatches: G().nullable(),
25
+ runnerEnteredAt: J().nullable(),
26
+ runnerGeneration: q().nullable(),
27
+ engineDelivery: G().nullable(),
28
+ reclaimCount: U().default(0),
29
+ output: G().nullable(),
30
+ subject: G().nullable(),
31
+ source: q().nullable(),
32
+ errorTag: q().nullable(),
33
+ errorMessage: q().nullable(),
34
+ cancelled: tt().default(!1),
35
+ discardedAt: J().nullable(),
36
+ discardedBy: q().nullable(),
37
+ startedAt: J().default("now"),
38
+ completedAt: J().nullable(),
39
+ durationMs: U().nullable(),
40
+ traceId: q().nullable(),
41
+ parentExecutionId: q().nullable(),
42
+ parentGeneration: q().nullable(),
43
+ parentClosePolicy: q().oneOf([
44
44
  "cancel",
45
45
  "terminate",
46
46
  "abandon"
47
47
  ]).nullable()
48
- }).index(["tag"]).index(["status"]).index(["source"]).index(["startedAt"]).index(["parentExecutionId"]).index(["parentClosePolicy"]), _t = q("_voltro_workflow_run_steps", {
49
- id: U({ prefix: "wfstep" }),
50
- runId: lt(() => gt, {
48
+ }).index(["tag"]).index(["status"]).index(["source"]).index(["startedAt"]).index(["parentExecutionId"]).index(["parentClosePolicy"]), vt = K("_voltro_workflow_run_steps", {
49
+ id: H({ prefix: "wfstep" }),
50
+ runId: dt(() => _t, {
51
51
  index: !1,
52
52
  onDelete: "cascade"
53
53
  }),
54
- stepName: J(),
55
- attempt: W().default(1),
56
- status: J().oneOf([
54
+ stepName: q(),
55
+ attempt: U().default(1),
56
+ status: q().oneOf([
57
57
  "running",
58
58
  "succeeded",
59
59
  "failed"
60
60
  ]).default("running"),
61
- input: K().nullable(),
62
- retryPolicy: K().nullable(),
63
- output: K().nullable(),
64
- errorTag: J().nullable(),
65
- errorMessage: J().nullable(),
66
- errorCause: K().nullable(),
67
- startedAt: Y().default("now"),
68
- completedAt: Y().nullable(),
69
- durationMs: W().nullable()
70
- }).index(["runId", "stepName"]).index(["startedAt"]), vt = q("_voltro_workflow_run_events", {
71
- id: U({ prefix: "wfev" }),
72
- runId: lt(() => gt, {
61
+ input: G().nullable(),
62
+ retryPolicy: G().nullable(),
63
+ output: G().nullable(),
64
+ errorTag: q().nullable(),
65
+ errorMessage: q().nullable(),
66
+ errorCause: G().nullable(),
67
+ startedAt: J().default("now"),
68
+ completedAt: J().nullable(),
69
+ durationMs: U().nullable()
70
+ }).index(["runId", "stepName"]).index(["startedAt"]), yt = K("_voltro_workflow_run_events", {
71
+ id: H({ prefix: "wfev" }),
72
+ runId: dt(() => _t, {
73
73
  index: !1,
74
74
  onDelete: "cascade"
75
75
  }),
76
- eventType: J(),
77
- payload: K().nullable(),
78
- occurredAt: Y().default("now"),
79
- stepName: J().nullable(),
80
- attempt: W().nullable()
81
- }).index(["runId", "occurredAt"]).index(["eventType"]), yt = q("_voltro_workflow_start_contexts", {
82
- id: U({ prefix: "wfctx" }),
83
- workflowName: J(),
84
- executionId: J().unique(),
85
- subject: K().nullable(),
86
- traceId: J().nullable(),
87
- source: J().nullable(),
88
- parentExecutionId: J().nullable(),
89
- parentGeneration: J().nullable(),
90
- parentClosePolicy: J().oneOf([
76
+ eventType: q(),
77
+ payload: G().nullable(),
78
+ occurredAt: J().default("now"),
79
+ stepName: q().nullable(),
80
+ attempt: U().nullable()
81
+ }).index(["runId", "occurredAt"]).index(["eventType"]), bt = K("_voltro_workflow_start_contexts", {
82
+ id: H({ prefix: "wfctx" }),
83
+ workflowName: q(),
84
+ executionId: q().unique(),
85
+ subject: G().nullable(),
86
+ traceId: q().nullable(),
87
+ source: q().nullable(),
88
+ parentExecutionId: q().nullable(),
89
+ parentGeneration: q().nullable(),
90
+ parentClosePolicy: q().oneOf([
91
91
  "cancel",
92
92
  "terminate",
93
93
  "abandon"
94
94
  ]).nullable(),
95
- createdAt: Y().default("now")
96
- }).index(["workflowName"]).index(["executionId"]).index(["parentExecutionId"]), bt = q("_voltro_workflow_admission_locks", {
97
- id: U({ prefix: "wfalk" }),
98
- nonce: J()
99
- }).nonReactive(), xt = q("_voltro_workflow_parent_closures", {
100
- id: U({ prefix: "wfpc" }),
101
- runId: J(),
102
- workflowName: J(),
103
- executionId: J(),
104
- generation: J(),
105
- parentStatus: J().oneOf([
95
+ createdAt: J().default("now")
96
+ }).index(["workflowName"]).index(["executionId"]).index(["parentExecutionId"]), xt = K("_voltro_workflow_admission_locks", {
97
+ id: H({ prefix: "wfalk" }),
98
+ nonce: q()
99
+ }).nonReactive(), St = K("_voltro_workflow_parent_closures", {
100
+ id: H({ prefix: "wfpc" }),
101
+ runId: q(),
102
+ workflowName: q(),
103
+ executionId: q(),
104
+ generation: q(),
105
+ parentStatus: q().oneOf([
106
106
  "succeeded",
107
107
  "failed",
108
108
  "cancelled"
109
109
  ]),
110
- closedAt: Y(),
111
- afterChildId: J().nullable(),
112
- scanHasOpenChildren: $e().default(!1),
113
- completedAt: Y().nullable()
114
- }).index(["executionId"]).index(["completedAt", "id"]).nonReactive(), St = q("_voltro_workflow_control_requests", {
115
- id: U({ prefix: "wfctl" }),
116
- runId: J(),
117
- workflowName: J(),
118
- executionId: J(),
119
- generation: J(),
120
- operation: J().oneOf([
110
+ closedAt: J(),
111
+ afterChildId: q().nullable(),
112
+ scanHasOpenChildren: tt().default(!1),
113
+ completedAt: J().nullable()
114
+ }).index(["executionId"]).index(["completedAt", "id"]).nonReactive(), Ct = K("_voltro_workflow_control_requests", {
115
+ id: H({ prefix: "wfctl" }),
116
+ runId: q(),
117
+ workflowName: q(),
118
+ executionId: q(),
119
+ generation: q(),
120
+ operation: q().oneOf([
121
121
  "cancel",
122
122
  "terminate",
123
123
  "resume"
124
124
  ]),
125
- requestedAt: Y(),
126
- owner: K().nullable(),
127
- cause: K().nullable(),
128
- parentClosureId: J().nullable(),
129
- resumeJournal: K().nullable(),
130
- dispatchAttempts: W().default(0),
131
- result: K().nullable()
132
- }).index(["runId"]).index(["parentClosureId", "id"]).nonReactive(), Ct = q("_voltro_workflow_failure_reports", {
133
- id: U({ prefix: "wffr" }),
134
- workflowName: J(),
135
- tenantId: J().nullable(),
136
- sourceId: J(),
137
- sourceKind: J().oneOf([
125
+ requestedAt: J(),
126
+ owner: G().nullable(),
127
+ cause: G().nullable(),
128
+ parentClosureId: q().nullable(),
129
+ resumeJournal: G().nullable(),
130
+ dispatchAttempts: U().default(0),
131
+ result: G().nullable()
132
+ }).index(["runId"]).index(["parentClosureId", "id"]).nonReactive(), wt = K("_voltro_workflow_failure_reports", {
133
+ id: H({ prefix: "wffr" }),
134
+ workflowName: q(),
135
+ tenantId: q().nullable(),
136
+ sourceId: q(),
137
+ sourceKind: q().oneOf([
138
138
  "submission",
139
139
  "intent",
140
140
  "run"
141
141
  ]),
142
- handler: J().nullable(),
143
- callerContext: K().nullable(),
144
- report: K(),
145
- handoffReceiptId: J().nullable(),
146
- handoffAttempt: W().default(0),
147
- acceptedExecutionId: J().nullable()
148
- }).index(["sourceKind", "sourceId"]).nonReactive(), wt = q("_voltro_workflow_submissions", {
149
- id: U({ prefix: "wfsub" }),
150
- workflowName: J(),
151
- tenantId: J().nullable(),
152
- ledgerId: J(),
153
- executionId: J().nullable(),
154
- runId: J().nullable(),
155
- receiptsBound: $e().default(!1),
156
- preparedExecutionId: J().nullable(),
157
- dispatchAttempts: W().default(0),
158
- failureId: J().nullable(),
159
- retry: K(),
160
- payload: K(),
161
- callerContext: K().nullable(),
162
- intentIds: K(),
163
- eviction: K().nullable()
164
- }).nonReactive(), Tt = q("_voltro_workflow_start_receipts", {
165
- id: U({ prefix: "wfrc" }),
166
- workflowName: J(),
167
- tenantId: J().nullable(),
168
- pendingId: J().maxLength(64),
169
- submissionId: J().maxLength(64).nullable(),
170
- terminal: K().nullable(),
171
- requestFingerprint: J().maxLength(64).nullable()
172
- }).index(["pendingId"]).nonReactive(), Et = q("_voltro_workflow_pending", {
173
- id: U({ prefix: "wfp" }),
174
- tenantId: J().nullable(),
175
- workflowName: J(),
176
- controlKey: J(),
177
- mode: J().oneOf([
142
+ handler: q().nullable(),
143
+ callerContext: G().nullable(),
144
+ report: G(),
145
+ handoffReceiptId: q().nullable(),
146
+ handoffAttempt: U().default(0),
147
+ acceptedExecutionId: q().nullable()
148
+ }).index(["sourceKind", "sourceId"]).nonReactive(), Tt = K("_voltro_workflow_submissions", {
149
+ id: H({ prefix: "wfsub" }),
150
+ workflowName: q(),
151
+ tenantId: q().nullable(),
152
+ ledgerId: q(),
153
+ executionId: q().nullable(),
154
+ runId: q().nullable(),
155
+ receiptsBound: tt().default(!1),
156
+ preparedExecutionId: q().nullable(),
157
+ dispatchAttempts: U().default(0),
158
+ failureId: q().nullable(),
159
+ retry: G(),
160
+ payload: G(),
161
+ callerContext: G().nullable(),
162
+ intentIds: G(),
163
+ eviction: G().nullable()
164
+ }).nonReactive(), Et = K("_voltro_workflow_start_receipts", {
165
+ id: H({ prefix: "wfrc" }),
166
+ workflowName: q(),
167
+ tenantId: q().nullable(),
168
+ pendingId: q().maxLength(64),
169
+ submissionId: q().maxLength(64).nullable(),
170
+ terminal: G().nullable(),
171
+ requestFingerprint: q().maxLength(64).nullable()
172
+ }).index(["pendingId"]).nonReactive(), Dt = K("_voltro_workflow_pending", {
173
+ id: H({ prefix: "wfp" }),
174
+ tenantId: q().nullable(),
175
+ workflowName: q(),
176
+ controlKey: q(),
177
+ mode: q().oneOf([
178
178
  "debounce",
179
179
  "batch",
180
180
  "throttle",
@@ -182,24 +182,24 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
182
182
  "paused",
183
183
  "delayed"
184
184
  ]),
185
- payload: K(),
186
- callerContext: K().nullable(),
187
- queuedAppVersion: J().nullable(),
188
- queuedSchemaFingerprint: J().nullable(),
189
- priority: W().default(0),
190
- dueAt: Y(),
191
- deadlineAt: Y().nullable(),
192
- collapsed: W().default(1),
193
- firstSeenAt: Y().default("now"),
194
- updatedAt: Y().default("now"),
195
- attempts: W().default(0),
196
- lastError: J().nullable(),
197
- deadLetteredAt: Y().nullable()
198
- }).index(["workflowName", "controlKey"]).index(["dueAt"]).index(["workflowName", "mode"]).index(["tenantId"]), Dt = q("_voltro_workflow_admissions", {
199
- id: U({ prefix: "wfadm" }),
200
- tenantId: J().nullable(),
201
- workflowName: J(),
202
- outcome: J().oneOf([
185
+ payload: G(),
186
+ callerContext: G().nullable(),
187
+ queuedAppVersion: q().nullable(),
188
+ queuedSchemaFingerprint: q().nullable(),
189
+ priority: U().default(0),
190
+ dueAt: J(),
191
+ deadlineAt: J().nullable(),
192
+ collapsed: U().default(1),
193
+ firstSeenAt: J().default("now"),
194
+ updatedAt: J().default("now"),
195
+ attempts: U().default(0),
196
+ lastError: q().nullable(),
197
+ deadLetteredAt: J().nullable()
198
+ }).index(["workflowName", "controlKey"]).index(["dueAt"]).index(["workflowName", "mode"]).index(["tenantId"]), Ot = K("_voltro_workflow_admissions", {
199
+ id: H({ prefix: "wfadm" }),
200
+ tenantId: q().nullable(),
201
+ workflowName: q(),
202
+ outcome: q().oneOf([
203
203
  "admitted",
204
204
  "dropped",
205
205
  "skipped",
@@ -207,34 +207,34 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
207
207
  "expired",
208
208
  "discarded"
209
209
  ]),
210
- mode: J().nullable(),
211
- reason: J().nullable(),
212
- collapsed: W().default(1),
213
- waitedMs: ct().nullable().narrowedFrom("integer"),
214
- executionId: J().nullable(),
215
- runId: J().nullable(),
216
- singletonKey: J().nullable(),
217
- concurrencyKey: J().nullable(),
218
- concurrencyReservation: K().nullable(),
219
- rateKey: J().nullable(),
220
- admittedAt: Y().default("now"),
221
- expiresAt: Y().nullable(),
222
- releasedAt: Y().nullable()
223
- }).index(["workflowName", "admittedAt"]).index(["concurrencyKey", "releasedAt"]).index(["singletonKey", "releasedAt"]).index(["rateKey", "admittedAt"]).index(["executionId"]).index(["tenantId"]), Ot = q("_voltro_workflow_pauses", {
224
- id: U({ prefix: "wfpause" }),
225
- pausedAt: Y().default("now"),
226
- pausedBy: J().nullable(),
227
- reason: J().nullable()
228
- }), kt = async (e, t) => {
210
+ mode: q().nullable(),
211
+ reason: q().nullable(),
212
+ collapsed: U().default(1),
213
+ waitedMs: ut().nullable().narrowedFrom("integer"),
214
+ executionId: q().nullable(),
215
+ runId: q().nullable(),
216
+ singletonKey: q().nullable(),
217
+ concurrencyKey: q().nullable(),
218
+ concurrencyReservation: G().nullable(),
219
+ rateKey: q().nullable(),
220
+ admittedAt: J().default("now"),
221
+ expiresAt: J().nullable(),
222
+ releasedAt: J().nullable()
223
+ }).index(["workflowName", "admittedAt"]).index(["concurrencyKey", "releasedAt"]).index(["singletonKey", "releasedAt"]).index(["rateKey", "admittedAt"]).index(["executionId"]).index(["tenantId"]), kt = K("_voltro_workflow_pauses", {
224
+ id: H({ prefix: "wfpause" }),
225
+ pausedAt: J().default("now"),
226
+ pausedBy: q().nullable(),
227
+ reason: q().nullable()
228
+ }), At = async (e, t) => {
229
229
  if (!Number.isFinite(t.now) || !Number.isFinite(new Date(t.now).getTime())) throw Error("Queued cancellation requires a valid timestamp");
230
- let n = await Se(e, t.receiptId);
230
+ let n = await Ce(e, t.receiptId);
231
231
  if (n === void 0 || n.workflowName !== t.workflowName || n.tenantId !== t.tenantId) throw Error("Queued cancellation receipt is missing or belongs to another workflow or tenant");
232
232
  if (n.terminal !== null) return {
233
233
  kind: "terminal",
234
234
  outcome: n.terminal
235
235
  };
236
236
  if (n.submissionId !== null) {
237
- let t = await N(e, n.submissionId);
237
+ let t = await M(e, n.submissionId);
238
238
  if (t === void 0 || !t.receiptsBound || t.workflowName !== n.workflowName || t.tenantId !== n.tenantId || !t.intentIds.includes(n.pendingId)) throw Error("Queued cancellation receipt has no matching submission");
239
239
  return {
240
240
  kind: "submitted",
@@ -242,8 +242,8 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
242
242
  };
243
243
  }
244
244
  let [r] = await e.query({
245
- table: k,
246
- predicate: V("id", n.pendingId),
245
+ table: O,
246
+ predicate: B("id", n.pendingId),
247
247
  lock: "update",
248
248
  order: [],
249
249
  take: 1,
@@ -251,13 +251,13 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
251
251
  projection: void 0
252
252
  });
253
253
  if (r === void 0) throw Error("Queued cancellation has no pending input or submission");
254
- let i = F(r);
254
+ let i = P(r);
255
255
  if (i.workflowName !== n.workflowName || i.tenantId !== n.tenantId || i.deadLetteredAt !== void 0) throw Error("Queued cancellation input has contradictory ownership or is dead-lettered");
256
256
  let a = {
257
257
  kind: "cancelled",
258
258
  at: t.now
259
259
  };
260
- if (await P(e, {
260
+ if (await N(e, {
261
261
  pendingId: n.pendingId,
262
262
  workflowName: n.workflowName,
263
263
  tenantId: n.tenantId,
@@ -267,31 +267,31 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
267
267
  kind: "terminal",
268
268
  outcome: a
269
269
  };
270
- }, At = "_voltro_workflow_parent_closures", X = z.NonEmptyString, jt = z.Struct({
270
+ }, jt = "_voltro_workflow_parent_closures", X = R.NonEmptyString, Mt = R.Struct({
271
271
  id: X,
272
272
  runId: X,
273
273
  workflowName: X,
274
274
  executionId: X,
275
275
  generation: X,
276
- parentStatus: z.Literal("succeeded", "failed", "cancelled"),
277
- closedAt: z.DateFromSelf,
278
- afterChildId: z.NullOr(X),
279
- scanHasOpenChildren: z.Boolean,
280
- completedAt: z.NullOr(z.DateFromSelf)
281
- }), Mt = z.Struct({
276
+ parentStatus: R.Literal("succeeded", "failed", "cancelled"),
277
+ closedAt: R.DateFromSelf,
278
+ afterChildId: R.NullOr(X),
279
+ scanHasOpenChildren: R.Boolean,
280
+ completedAt: R.NullOr(R.DateFromSelf)
281
+ }), Nt = R.Struct({
282
282
  id: X,
283
283
  tag: X,
284
284
  executionId: X,
285
- status: z.Literal("running", "suspended", "succeeded", "failed", "cancelled"),
286
- runnerGeneration: z.optional(z.NullOr(X)),
287
- parentGeneration: z.optional(z.NullOr(X)),
288
- parentClosePolicy: z.NullOr(z.Literal("cancel", "terminate", "abandon"))
289
- }), Nt = async (e, t, n) => {
285
+ status: R.Literal("running", "suspended", "succeeded", "failed", "cancelled"),
286
+ runnerGeneration: R.optional(R.NullOr(X)),
287
+ parentGeneration: R.optional(R.NullOr(X)),
288
+ parentClosePolicy: R.NullOr(R.Literal("cancel", "terminate", "abandon"))
289
+ }), Pt = async (e, t, n) => {
290
290
  if (t.parentClosePolicy !== "cancel" && t.parentClosePolicy !== "terminate") return !1;
291
291
  if (typeof t.parentExecutionId != "string" || t.parentExecutionId.length === 0 || typeof t.parentGeneration != "string" || t.parentGeneration.length === 0) throw Error("Child entry requires its original parent execution and generation");
292
292
  let r = n ?? (await e.query({
293
- table: At,
294
- predicate: B(V("executionId", t.parentExecutionId), V("generation", t.parentGeneration)),
293
+ table: jt,
294
+ predicate: z(B("executionId", t.parentExecutionId), B("generation", t.parentGeneration)),
295
295
  lock: "update",
296
296
  order: [],
297
297
  take: 1,
@@ -299,9 +299,9 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
299
299
  projection: void 0
300
300
  }))[0];
301
301
  if (r === void 0) return !1;
302
- let i = z.decodeUnknownSync(jt)(r);
302
+ let i = R.decodeUnknownSync(Mt)(r);
303
303
  if (i.executionId !== t.parentExecutionId || i.generation !== t.parentGeneration) return !1;
304
- let a = z.decodeUnknownSync(Mt)(t), o = et("wfctl", JSON.stringify([
304
+ let a = R.decodeUnknownSync(Nt)(t), o = nt("wfctl", JSON.stringify([
305
305
  "parent-close",
306
306
  i.id,
307
307
  a.id
@@ -311,7 +311,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
311
311
  } else {
312
312
  if (a.status !== "running" && a.status !== "suspended") return !1;
313
313
  if (a.runnerGeneration === void 0 || a.runnerGeneration === null) throw Error("Child entry requires its own generation");
314
- await Ve(e, {
314
+ await He(e, {
315
315
  id: o,
316
316
  runId: a.id,
317
317
  workflowName: a.tag,
@@ -333,10 +333,10 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
333
333
  });
334
334
  }
335
335
  return !0;
336
- }, Pt = async (e, t, n = Date.now()) => {
336
+ }, Ft = async (e, t, n = Date.now()) => {
337
337
  let [r] = await e.query({
338
- table: At,
339
- predicate: V("id", t),
338
+ table: jt,
339
+ predicate: B("id", t),
340
340
  lock: "update",
341
341
  order: [],
342
342
  take: 1,
@@ -344,7 +344,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
344
344
  projection: void 0
345
345
  });
346
346
  if (r === void 0) throw Error("Parent closure is missing");
347
- let i = z.decodeUnknownSync(jt)(r);
347
+ let i = R.decodeUnknownSync(Mt)(r);
348
348
  if (i.completedAt !== null) return {
349
349
  scanned: 0,
350
350
  controls: 0,
@@ -353,7 +353,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
353
353
  if (!Number.isFinite(n)) throw Error("Parent closure requires a finite completion timestamp");
354
354
  let a = await e.query({
355
355
  table: "_voltro_workflow_runs",
356
- predicate: B(V("parentExecutionId", i.executionId), ...i.afterChildId === null ? [] : [H("id", i.afterChildId)]),
356
+ predicate: z(B("parentExecutionId", i.executionId), ...i.afterChildId === null ? [] : [V("id", i.afterChildId)]),
357
357
  lock: "update",
358
358
  order: [{
359
359
  column: "id",
@@ -364,10 +364,10 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
364
364
  projection: void 0
365
365
  }), o = 0, s = i.scanHasOpenChildren, c = null;
366
366
  for (let t of a) {
367
- let r = z.decodeUnknownSync(Mt)(t);
367
+ let r = R.decodeUnknownSync(Nt)(t);
368
368
  if (c = r.id, r.parentClosePolicy !== null && r.parentClosePolicy !== "abandon") {
369
369
  if (r.parentGeneration === void 0 || r.parentGeneration === null) throw Error("Parent closure cannot attribute a child without its parent generation");
370
- r.parentGeneration === i.generation && ((r.status === "running" || r.status === "suspended") && (s = !0), await Nt(e, t, i) && (o++, r.status === "suspended" && typeof r.runnerGeneration == "string" && await Vt(e, {
370
+ r.parentGeneration === i.generation && ((r.status === "running" || r.status === "suspended") && (s = !0), await Pt(e, t, i) && (o++, r.status === "suspended" && typeof r.runnerGeneration == "string" && await Ht(e, {
371
371
  runId: r.id,
372
372
  workflowName: r.tag,
373
373
  executionId: r.executionId,
@@ -375,8 +375,8 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
375
375
  }, n)));
376
376
  }
377
377
  }
378
- let l = a.length < 100, u = l && !s && !await Re(e, i.id);
379
- if (await e.update(At, i.id, {
378
+ let l = a.length < 100, u = l && !s && !await ze(e, i.id);
379
+ if (await e.update(jt, i.id, {
380
380
  afterChildId: l ? null : c,
381
381
  scanHasOpenChildren: !l && s,
382
382
  completedAt: u ? new Date(n) : null
@@ -386,19 +386,19 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
386
386
  controls: o,
387
387
  wrapped: l
388
388
  };
389
- }, Ft = "_voltro_workflow_runs", It = z.NullOr(z.Struct({
390
- requestId: z.NonEmptyString,
391
- restartToken: z.NullOr(z.NonEmptyString)
392
- })), Lt = async (e, t, n, r) => {
389
+ }, It = "_voltro_workflow_runs", Lt = R.NullOr(R.Struct({
390
+ requestId: R.NonEmptyString,
391
+ restartToken: R.NullOr(R.NonEmptyString)
392
+ })), Rt = async (e, t, n, r) => {
393
393
  if (typeof t.id != "string") throw Error("Child entry has no allocated run identity");
394
394
  let i = {
395
395
  runId: t.id,
396
396
  workflowName: n.workflowName,
397
397
  executionId: n.executionId,
398
398
  generation: n.generation
399
- }, a = await nn(e, i), o = await Nt(e, t);
399
+ }, a = await rn(e, i), o = await Pt(e, t);
400
400
  if (!a && !o) return;
401
- let s = await Ut(e, {
401
+ let s = await Wt(e, {
402
402
  owner: i,
403
403
  now: n.now,
404
404
  durationMs: 0,
@@ -411,43 +411,43 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
411
411
  previous: r,
412
412
  terminalEvent: s.terminalEvent
413
413
  };
414
- }, Rt = async (e, t) => {
415
- let n = await Te(e, t);
414
+ }, zt = async (e, t) => {
415
+ let n = await Ee(e, t);
416
416
  return {
417
- ...await Lt(e, n.row, t, n.previous) ?? {
417
+ ...await Rt(e, n.row, t, n.previous) ?? {
418
418
  kind: "entered",
419
419
  row: n.row,
420
420
  previous: n.previous
421
421
  },
422
422
  restartEvent: n.event
423
423
  };
424
- }, zt = async (e, t) => {
424
+ }, Bt = async (e, t) => {
425
425
  if ([
426
426
  t.workflowName,
427
427
  t.executionId,
428
428
  t.generation
429
429
  ].some((e) => e.length === 0) || typeof t.initialRow.id != "string" || t.initialRow.id.length === 0 || !Number.isFinite(t.now)) throw Error("Workflow entry requires allocated identities and a finite timestamp");
430
430
  let n = (await e.query({
431
- table: Ft,
432
- predicate: V("executionId", t.executionId),
431
+ table: It,
432
+ predicate: B("executionId", t.executionId),
433
433
  lock: "update",
434
434
  order: [],
435
435
  take: 1,
436
436
  skip: void 0,
437
437
  projection: void 0
438
- }))[0], r = z.decodeUnknownSync(It)(t.delivery ?? null), i = (r) => Lt(e, r, t, n);
438
+ }))[0], r = R.decodeUnknownSync(Lt)(t.delivery ?? null), i = (r) => Rt(e, r, t, n);
439
439
  if (n === void 0) {
440
440
  if (r !== null && r.restartToken !== null) throw Error("Workflow restart delivery has no resident authorization");
441
441
  if ((await e.query({
442
442
  table: "_voltro_workflow_parent_closures",
443
- predicate: V("executionId", t.executionId),
443
+ predicate: B("executionId", t.executionId),
444
444
  lock: "update",
445
445
  order: [],
446
446
  take: 1,
447
447
  skip: void 0,
448
448
  projection: ["id"]
449
449
  })).length !== 0) throw Error("Workflow execution is already terminal; restore its engine journal instead of re-entering the body");
450
- let n = await e.insert(Ft, {
450
+ let n = await e.insert(It, {
451
451
  ...t.initialRow,
452
452
  tag: t.workflowName,
453
453
  executionId: t.executionId,
@@ -464,9 +464,9 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
464
464
  };
465
465
  }
466
466
  if (n.tag !== t.workflowName || typeof n.id != "string") throw Error("Workflow entry execution belongs to a different resident run");
467
- let a = z.decodeUnknownSync(It)(n.engineDelivery ?? null);
467
+ let a = R.decodeUnknownSync(Lt)(n.engineDelivery ?? null);
468
468
  if (a?.requestId !== r?.requestId || a?.restartToken !== r?.restartToken) {
469
- if (n.status === "failed" && r !== null && r.restartToken !== null && a?.requestId === r.requestId) return Rt(e, {
469
+ if (n.status === "failed" && r !== null && r.restartToken !== null && a?.requestId === r.requestId) return zt(e, {
470
470
  runId: n.id,
471
471
  workflowName: t.workflowName,
472
472
  executionId: t.executionId,
@@ -490,7 +490,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
490
490
  generation: n.runnerGeneration
491
491
  };
492
492
  if (await re(e, r)) {
493
- let i = await Ut(e, {
493
+ let i = await Wt(e, {
494
494
  owner: r,
495
495
  now: t.now,
496
496
  durationMs: 0,
@@ -514,7 +514,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
514
514
  if (typeof s != "number" || !Number.isSafeInteger(s) || s < 0) throw Error("Workflow entry has an invalid resident reclaim counter");
515
515
  let c = o ? s + 1 : 0;
516
516
  if (!Number.isSafeInteger(c)) throw Error("Workflow reclaim counter exhausted");
517
- let l = await e.update(Ft, n.id, {
517
+ let l = await e.update(It, n.id, {
518
518
  runnerGeneration: t.generation,
519
519
  runnerEnteredAt: new Date(t.now),
520
520
  reclaimCount: c,
@@ -526,7 +526,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
526
526
  });
527
527
  if (l === null) throw Error("Workflow run disappeared while entering its new generation");
528
528
  let u = await i(l);
529
- return u === void 0 ? (n.status === "suspended" && n.runnerEnteredAt === null && typeof n.runnerGeneration == "string" && await Oe(e, {
529
+ return u === void 0 ? (n.status === "suspended" && n.runnerEnteredAt === null && typeof n.runnerGeneration == "string" && await ke(e, {
530
530
  runId: n.id,
531
531
  workflowName: t.workflowName,
532
532
  executionId: t.executionId,
@@ -536,7 +536,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
536
536
  row: l,
537
537
  previous: n
538
538
  }) : u;
539
- }, Bt = async (e, t) => {
539
+ }, Vt = async (e, t) => {
540
540
  if ([
541
541
  t.runId,
542
542
  t.workflowName,
@@ -544,8 +544,8 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
544
544
  t.generation
545
545
  ].some((e) => e.length === 0)) throw Error("Workflow runner ownership requires non-empty identities");
546
546
  let n = (await e.query({
547
- table: Ft,
548
- predicate: V("id", t.runId),
547
+ table: It,
548
+ predicate: B("id", t.runId),
549
549
  lock: "update",
550
550
  order: [],
551
551
  take: 1,
@@ -554,21 +554,21 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
554
554
  }))[0];
555
555
  if (n === void 0 || n.tag !== t.workflowName || n.executionId !== t.executionId) throw Error("Workflow runner ownership does not match its resident run");
556
556
  return n;
557
- }, Vt = async (e, t, n) => {
558
- let r = await Bt(e, t);
557
+ }, Ht = async (e, t, n) => {
558
+ let r = await Vt(e, t);
559
559
  if (r.runnerGeneration !== t.generation || r.status !== "suspended" || r.runnerEnteredAt !== null || !await re(e, t)) return !1;
560
- if ((await Ut(e, {
560
+ if ((await Wt(e, {
561
561
  owner: t,
562
562
  now: n,
563
563
  durationMs: 0,
564
564
  outcome: { status: "cancelled" }
565
565
  }, "suspended")).kind !== "committed") throw Error("Suspended cancellation lost its resident owner");
566
566
  return !0;
567
- }, Ht = async (e, t, n) => {
568
- let r = await Bt(e, t);
567
+ }, Ut = async (e, t, n) => {
568
+ let r = await Vt(e, t);
569
569
  if (r.runnerGeneration !== t.generation) return { kind: "superseded" };
570
570
  if (r.status !== "running") return { kind: "not-running" };
571
- let i = await e.update(Ft, t.runId, {
571
+ let i = await e.update(It, t.runId, {
572
572
  status: "suspended",
573
573
  runnerEnteredAt: null,
574
574
  errorTag: n.errorTag,
@@ -579,24 +579,24 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
579
579
  kind: "committed",
580
580
  row: i
581
581
  };
582
- }, Ut = async (e, t, n) => {
583
- let r = await Bt(e, t.owner);
582
+ }, Wt = async (e, t, n) => {
583
+ let r = await Vt(e, t.owner);
584
584
  if (r.runnerGeneration !== t.owner.generation) return { kind: "superseded" };
585
585
  if (r.status !== n) return { kind: "not-running" };
586
586
  if (!Number.isFinite(t.now) || !Number.isFinite(t.durationMs) || t.durationMs < 0) throw Error("Workflow completion requires finite time and non-negative duration");
587
587
  let i = t.outcome, a = null;
588
- if (i.status === "failed" && (a = `wffr_${ft("sha256").update(JSON.stringify([
588
+ if (i.status === "failed" && (a = `wffr_${mt("sha256").update(JSON.stringify([
589
589
  "run",
590
590
  t.owner.workflowName,
591
591
  t.owner.runId,
592
592
  t.owner.generation
593
- ])).digest("hex").slice(0, 40)}`, await M(e, {
593
+ ])).digest("hex").slice(0, 40)}`, await j(e, {
594
594
  id: a,
595
595
  sourceKind: "run",
596
596
  sourceId: t.owner.runId,
597
597
  workflowName: t.owner.workflowName,
598
598
  tenantId: i.tenantId,
599
- handler: await A(e, t.owner.executionId, t.owner.workflowName, i.tenantId) ? null : i.handler,
599
+ handler: await k(e, t.owner.executionId, t.owner.workflowName, i.tenantId) ? null : i.handler,
600
600
  callerContext: i.callerContext,
601
601
  report: {
602
602
  workflow: t.owner.workflowName,
@@ -608,28 +608,28 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
608
608
  reason: "the run failed",
609
609
  failedAt: t.now
610
610
  }
611
- }), await O(e, a, t.now)), i.status === "cancelled") {
611
+ }), await fe(e, a, t.now)), i.status === "cancelled") {
612
612
  let n = (await C((t) => e.query({
613
613
  ...t,
614
614
  lock: "update"
615
615
  }), t.owner)).map((e) => ({
616
616
  request: e,
617
- cause: me(e)
617
+ cause: he(e)
618
618
  })).find((e) => e.cause !== void 0);
619
619
  if (n !== void 0 && n.cause !== void 0) {
620
- let i = z.decodeUnknownOption(z.Struct({ tenantId: z.NullOr(z.String) }))(r.subject), o = n.request.owner?.tenantId ?? (i._tag === "Some" ? i.value.tenantId : null);
621
- a = `wffr_${ft("sha256").update(JSON.stringify([
620
+ let i = R.decodeUnknownOption(R.Struct({ tenantId: R.NullOr(R.String) }))(r.subject), o = n.request.owner?.tenantId ?? (i._tag === "Some" ? i.value.tenantId : null);
621
+ a = `wffr_${mt("sha256").update(JSON.stringify([
622
622
  "finish-timeout",
623
623
  t.owner.workflowName,
624
624
  t.owner.runId,
625
625
  t.owner.generation
626
- ])).digest("hex").slice(0, 40)}`, await M(e, {
626
+ ])).digest("hex").slice(0, 40)}`, await j(e, {
627
627
  id: a,
628
628
  sourceKind: "run",
629
629
  sourceId: t.owner.runId,
630
630
  workflowName: t.owner.workflowName,
631
631
  tenantId: o,
632
- handler: await A(e, t.owner.executionId, t.owner.workflowName, o) ? null : n.cause.detail.onFailure,
632
+ handler: await k(e, t.owner.executionId, t.owner.workflowName, o) ? null : n.cause.detail.onFailure,
633
633
  callerContext: {
634
634
  subject: r.subject ?? null,
635
635
  traceId: r.traceId ?? null,
@@ -648,10 +648,10 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
648
648
  reason: n.cause.reason,
649
649
  failedAt: t.now
650
650
  }
651
- }), await O(e, a, t.now);
651
+ }), await fe(e, a, t.now);
652
652
  }
653
653
  }
654
- let o = await e.update(Ft, t.owner.runId, {
654
+ let o = await e.update(It, t.owner.runId, {
655
655
  status: i.status,
656
656
  completedAt: new Date(t.now),
657
657
  durationMs: t.durationMs,
@@ -663,7 +663,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
663
663
  });
664
664
  if (o === null) throw Error("Workflow run disappeared during terminal recording");
665
665
  await e.insert("_voltro_workflow_parent_closures", {
666
- id: et("wfpc", JSON.stringify([t.owner.runId, t.owner.generation])),
666
+ id: nt("wfpc", JSON.stringify([t.owner.runId, t.owner.generation])),
667
667
  runId: t.owner.runId,
668
668
  workflowName: t.owner.workflowName,
669
669
  executionId: t.owner.executionId,
@@ -675,7 +675,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
675
675
  completedAt: null
676
676
  });
677
677
  let s = await e.insert("_voltro_workflow_run_events", {
678
- id: et("wfev", JSON.stringify([
678
+ id: nt("wfev", JSON.stringify([
679
679
  "terminal",
680
680
  t.owner.runId,
681
681
  t.owner.generation
@@ -695,11 +695,11 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
695
695
  } : {}
696
696
  }
697
697
  });
698
- await fe(e, t), await x(e, t.owner.executionId, t.now);
699
- for await (let n of He(e, t.owner.executionId, t.owner.workflowName)) {
698
+ await pe(e, t), await x(e, t.owner.executionId, t.now);
699
+ for await (let n of Ue(e, t.owner.executionId, t.owner.workflowName)) {
700
700
  let [r] = await e.query({
701
701
  table: te,
702
- predicate: V("id", n.ledgerId),
702
+ predicate: B("id", n.ledgerId),
703
703
  lock: "update",
704
704
  order: [],
705
705
  take: 1,
@@ -715,49 +715,49 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
715
715
  failureId: a,
716
716
  terminalEvent: s
717
717
  };
718
- }, Wt = (e, t) => Ut(e, t, "running"), Gt = q("_voltro_workflow_queued_cancellations", {
719
- id: U({ prefix: "wfqc" }),
720
- receiptId: J(),
721
- workflowName: J(),
722
- tenantId: J().nullable(),
723
- requestedAt: Y(),
724
- cause: K().nullable(),
725
- target: K(),
726
- controlBinding: K().nullable()
727
- }).index(["receiptId"]).index(["workflowName", "id"]).nonReactive(), Kt = z.NullOr(z.Struct({
728
- reason: z.NonEmptyString,
729
- detail: z.optional(z.Record({
730
- key: z.String,
731
- value: z.Unknown
718
+ }, Gt = (e, t) => Wt(e, t, "running"), Kt = K("_voltro_workflow_queued_cancellations", {
719
+ id: H({ prefix: "wfqc" }),
720
+ receiptId: q(),
721
+ workflowName: q(),
722
+ tenantId: q().nullable(),
723
+ requestedAt: J(),
724
+ cause: G().nullable(),
725
+ target: G(),
726
+ controlBinding: G().nullable()
727
+ }).index(["receiptId"]).index(["workflowName", "id"]).nonReactive(), qt = R.NullOr(R.Struct({
728
+ reason: R.NonEmptyString,
729
+ detail: R.optional(R.Record({
730
+ key: R.String,
731
+ value: R.Unknown
732
732
  }))
733
- })), qt = z.Struct({
734
- id: z.NonEmptyString,
735
- receiptId: z.NonEmptyString,
736
- workflowName: z.NonEmptyString,
737
- tenantId: z.NullOr(z.String),
738
- requestedAt: z.DateFromSelf,
739
- cause: Kt,
740
- controlBinding: z.NullOr(z.Struct({
741
- controlId: z.NonEmptyString,
742
- runId: z.NonEmptyString,
743
- executionId: z.NonEmptyString,
744
- generation: z.NonEmptyString
733
+ })), Jt = R.Struct({
734
+ id: R.NonEmptyString,
735
+ receiptId: R.NonEmptyString,
736
+ workflowName: R.NonEmptyString,
737
+ tenantId: R.NullOr(R.String),
738
+ requestedAt: R.DateFromSelf,
739
+ cause: qt,
740
+ controlBinding: R.NullOr(R.Struct({
741
+ controlId: R.NonEmptyString,
742
+ runId: R.NonEmptyString,
743
+ executionId: R.NonEmptyString,
744
+ generation: R.NonEmptyString
745
745
  })),
746
- target: z.Union(z.Struct({
747
- kind: z.Literal("submission"),
748
- submissionId: z.NonEmptyString
749
- }), z.Struct({
750
- kind: z.Literal("terminal"),
751
- receipt: z.Unknown
746
+ target: R.Union(R.Struct({
747
+ kind: R.Literal("submission"),
748
+ submissionId: R.NonEmptyString
749
+ }), R.Struct({
750
+ kind: R.Literal("terminal"),
751
+ receipt: R.Unknown
752
752
  }))
753
- }), Jt = (e) => {
754
- let t = z.decodeUnknownSync(qt)(e);
753
+ }), Yt = (e) => {
754
+ let t = R.decodeUnknownSync(Jt)(e);
755
755
  if (!Number.isFinite(t.requestedAt.getTime())) throw Error("Queued cancellation request has an invalid timestamp");
756
756
  if (t.target.kind === "submission") return {
757
757
  ...t,
758
758
  target: t.target
759
759
  };
760
- let n = Pe(t.target.receipt);
760
+ let n = Fe(t.target.receipt);
761
761
  if (t.controlBinding !== null) throw Error("A non-executed start cannot have a run control binding");
762
762
  if (n.id !== t.receiptId || n.workflowName !== t.workflowName || n.tenantId !== t.tenantId || n.terminal === null) throw Error("Queued cancellation terminal evidence belongs to another start or is not terminal");
763
763
  return {
@@ -767,44 +767,44 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
767
767
  receipt: n
768
768
  }
769
769
  };
770
- }, Yt = async (e, t) => {
770
+ }, Xt = async (e, t) => {
771
771
  let [n] = await e.query({
772
- table: Gt.tableName,
773
- predicate: V("id", t),
772
+ table: Kt.tableName,
773
+ predicate: B("id", t),
774
774
  lock: "update",
775
775
  order: [],
776
776
  take: 1,
777
777
  skip: void 0,
778
778
  projection: void 0
779
779
  });
780
- return n === void 0 ? void 0 : Jt(n);
781
- }, Xt = async (e, t) => {
780
+ return n === void 0 ? void 0 : Yt(n);
781
+ }, Zt = async (e, t) => {
782
782
  let n = t.controlBinding;
783
783
  if (n === null) throw Error("Queued cancellation has no control binding");
784
784
  let r = await ae(e, n.controlId);
785
785
  if (r === void 0 || r.operation !== "cancel" || r.workflowName !== t.workflowName || r.runId !== n.runId || r.executionId !== n.executionId || r.generation !== n.generation || r.owner?.tenantId !== t.tenantId || r.result?.status === "running") throw Error("Queued cancellation lost its original resident control owner");
786
786
  return r;
787
- }, Zt = async (e, t, n) => {
787
+ }, Qt = async (e, t, n) => {
788
788
  if (t.controlBinding === null) return;
789
- let r = await Xt(e, t);
789
+ let r = await Zt(e, t);
790
790
  if (r.result !== null) return;
791
791
  let [i] = await e.query({
792
792
  table: "_voltro_workflow_runs",
793
- predicate: V("id", r.runId),
793
+ predicate: B("id", r.runId),
794
794
  lock: "update",
795
795
  order: [],
796
796
  take: 1,
797
797
  skip: void 0,
798
798
  projection: void 0
799
799
  });
800
- i !== void 0 && await Vt(e, {
800
+ i !== void 0 && await Ht(e, {
801
801
  runId: r.runId,
802
802
  workflowName: r.workflowName,
803
803
  executionId: r.executionId,
804
804
  generation: r.generation
805
805
  }, n);
806
- }, Qt = async (e, t) => {
807
- let n = await Yt(e, t.requestId);
806
+ }, $t = async (e, t) => {
807
+ let n = await Xt(e, t.requestId);
808
808
  if (n === void 0) return {
809
809
  kind: "unknown",
810
810
  reason: "missing-request"
@@ -820,7 +820,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
820
820
  };
821
821
  }
822
822
  if (n.controlBinding !== null) {
823
- let t = await Xt(e, n);
823
+ let t = await Zt(e, n);
824
824
  if (t.result !== null) return {
825
825
  kind: t.result.kind,
826
826
  request: n,
@@ -828,7 +828,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
828
828
  };
829
829
  let [r] = await e.query({
830
830
  table: "_voltro_workflow_runs",
831
- predicate: V("id", t.runId),
831
+ predicate: B("id", t.runId),
832
832
  lock: "update",
833
833
  order: [],
834
834
  take: 1,
@@ -854,7 +854,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
854
854
  run: r
855
855
  };
856
856
  }
857
- let r = await N(e, n.target.submissionId);
857
+ let r = await M(e, n.target.submissionId);
858
858
  if (r === void 0 || !r.receiptsBound || r.workflowName !== n.workflowName || r.tenantId !== n.tenantId) throw Error("Queued cancellation has no matching submission evidence");
859
859
  return r.failureId === null ? r.retry.stoppedAt !== null || r.runId !== null ? {
860
860
  kind: "unknown",
@@ -868,10 +868,10 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
868
868
  request: n,
869
869
  outcome: {
870
870
  kind: "rejected",
871
- failureId: await je(e, r)
871
+ failureId: await Me(e, r)
872
872
  }
873
873
  };
874
- }, $t = (e, t) => {
874
+ }, en = (e, t) => {
875
875
  let n = "request" in t ? t.request : void 0;
876
876
  if (n !== void 0 && (n.id !== e.requestId || n.receiptId !== e.receiptId || n.workflowName !== e.workflowName)) throw Error("Queued control result belongs to another request or receipt");
877
877
  let r = {
@@ -880,7 +880,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
880
880
  receiptId: e.receiptId,
881
881
  requestId: n?.id ?? null,
882
882
  kind: t.kind
883
- }, i = z.decodeUnknownSync(Ze);
883
+ }, i = R.decodeUnknownSync($e);
884
884
  if (t.kind === "unknown") return i({
885
885
  ...r,
886
886
  observation: {
@@ -919,14 +919,14 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
919
919
  ...r,
920
920
  observation: { kind: "pending" }
921
921
  });
922
- }, en = async (e, t) => {
923
- let n = z.decodeUnknownSync(z.Struct({
924
- id: z.NonEmptyString,
925
- receiptId: z.NonEmptyString,
926
- workflowName: z.NonEmptyString,
927
- tenantId: z.NullOr(z.String),
928
- requestedAt: z.DateFromSelf,
929
- cause: Kt
922
+ }, tn = async (e, t) => {
923
+ let n = R.decodeUnknownSync(R.Struct({
924
+ id: R.NonEmptyString,
925
+ receiptId: R.NonEmptyString,
926
+ workflowName: R.NonEmptyString,
927
+ tenantId: R.NullOr(R.String),
928
+ requestedAt: R.DateFromSelf,
929
+ cause: qt
930
930
  }))({
931
931
  id: t.requestId,
932
932
  receiptId: t.receiptId,
@@ -936,36 +936,36 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
936
936
  cause: t.cause ?? null
937
937
  });
938
938
  if (!Number.isFinite(n.requestedAt.getTime())) throw Error("Queued cancellation request requires a valid timestamp");
939
- let r = await Yt(e, n.id);
939
+ let r = await Xt(e, n.id);
940
940
  if (r !== void 0) {
941
941
  if (r.receiptId !== n.receiptId || r.workflowName !== n.workflowName || r.tenantId !== n.tenantId) throw Error("Queued cancellation identity belongs to a different start or owner");
942
- return await Zt(e, r, t.now), r;
942
+ return await Qt(e, r, t.now), r;
943
943
  }
944
- let i = await kt(e, t), a;
944
+ let i = await At(e, t), a;
945
945
  if (i.kind === "submitted") a = {
946
946
  kind: "submission",
947
947
  submissionId: i.submissionId
948
948
  };
949
949
  else {
950
- let n = await Se(e, t.receiptId);
950
+ let n = await Ce(e, t.receiptId);
951
951
  if (n === void 0) throw Error("Cancelled start receipt disappeared during request acceptance");
952
952
  a = {
953
953
  kind: "terminal",
954
954
  receipt: n
955
955
  };
956
956
  }
957
- let o = Jt({
957
+ let o = Yt({
958
958
  ...n,
959
959
  target: a,
960
960
  controlBinding: null
961
961
  });
962
- if (await e.insert(Gt.tableName, o), a.kind === "submission") {
963
- let n = await N(e, a.submissionId);
962
+ if (await e.insert(Kt.tableName, o), a.kind === "submission") {
963
+ let n = await M(e, a.submissionId);
964
964
  if (n === void 0) throw Error("Queued cancellation submission disappeared during acceptance");
965
965
  if (n.preparedExecutionId !== null && n.dispatchAttempts > 0) {
966
966
  let [r] = await e.query({
967
967
  table: "_voltro_workflow_runs",
968
- predicate: V("executionId", n.preparedExecutionId),
968
+ predicate: B("executionId", n.preparedExecutionId),
969
969
  lock: "update",
970
970
  order: [],
971
971
  take: 1,
@@ -973,24 +973,24 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
973
973
  projection: void 0
974
974
  });
975
975
  if (r !== void 0) {
976
- let n = z.decodeUnknownSync(z.Struct({
977
- id: z.NonEmptyString,
978
- tag: z.NonEmptyString,
979
- executionId: z.NonEmptyString,
980
- runnerGeneration: z.NonEmptyString
976
+ let n = R.decodeUnknownSync(R.Struct({
977
+ id: R.NonEmptyString,
978
+ tag: R.NonEmptyString,
979
+ executionId: R.NonEmptyString,
980
+ runnerGeneration: R.NonEmptyString
981
981
  }))(r), i = {
982
982
  runId: n.id,
983
983
  workflowName: n.tag,
984
984
  executionId: n.executionId,
985
985
  generation: n.runnerGeneration
986
- }, a = await tn(e, o.id, i);
987
- return await Zt(e, a.request, t.now), a.request;
986
+ }, a = await nn(e, o.id, i);
987
+ return await Qt(e, a.request, t.now), a.request;
988
988
  }
989
989
  }
990
990
  }
991
991
  return o;
992
- }, tn = async (e, t, n) => {
993
- let r = await Yt(e, t);
992
+ }, nn = async (e, t, n) => {
993
+ let r = await Xt(e, t);
994
994
  if (r === void 0) throw Error("Queued cancellation request is missing");
995
995
  if (r.target.kind === "terminal") return {
996
996
  kind: "terminal",
@@ -999,19 +999,19 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
999
999
  if (r.controlBinding !== null) return {
1000
1000
  kind: "bound",
1001
1001
  request: r,
1002
- control: await Xt(e, r)
1002
+ control: await Zt(e, r)
1003
1003
  };
1004
- let i = await N(e, r.target.submissionId);
1004
+ let i = await M(e, r.target.submissionId);
1005
1005
  if (i === void 0 || i.workflowName !== r.workflowName || i.tenantId !== r.tenantId || !i.receiptsBound || i.failureId !== null || i.dispatchAttempts === 0 || i.preparedExecutionId !== n.executionId || i.executionId !== null && i.executionId !== n.executionId || i.runId !== null && i.runId !== n.runId || n.workflowName !== r.workflowName) throw Error("Queued cancellation has no dispatched submission for this resident execution");
1006
1006
  let [a] = await e.query({
1007
1007
  table: "_voltro_workflow_runs",
1008
- predicate: V("id", n.runId),
1008
+ predicate: B("id", n.runId),
1009
1009
  lock: "update",
1010
1010
  order: [],
1011
1011
  take: 1,
1012
1012
  skip: void 0,
1013
1013
  projection: void 0
1014
- }), o = z.decodeUnknownOption(z.Struct({ tenantId: z.NullOr(z.String) }))(a?.subject);
1014
+ }), o = R.decodeUnknownOption(R.Struct({ tenantId: R.NullOr(R.String) }))(a?.subject);
1015
1015
  if (a === void 0 || a.tag !== n.workflowName || a.executionId !== n.executionId || a.runnerGeneration !== n.generation || o._tag === "None" || o.value.tenantId !== r.tenantId || ![
1016
1016
  "running",
1017
1017
  "suspended",
@@ -1020,18 +1020,18 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
1020
1020
  "cancelled"
1021
1021
  ].includes(String(a.status))) throw Error("Queued cancellation generation or tenant does not match the resident run");
1022
1022
  let s = {
1023
- controlId: et("wfctl", JSON.stringify(["queued-cancel", r.id])),
1023
+ controlId: nt("wfctl", JSON.stringify(["queued-cancel", r.id])),
1024
1024
  runId: n.runId,
1025
1025
  executionId: n.executionId,
1026
1026
  generation: n.generation
1027
- }, c = await Ve(e, {
1027
+ }, c = await He(e, {
1028
1028
  id: s.controlId,
1029
1029
  ...n,
1030
1030
  operation: "cancel",
1031
1031
  requestedAt: r.requestedAt.getTime(),
1032
1032
  cause: r.cause
1033
1033
  });
1034
- if (await e.update(Gt.tableName, r.id, { controlBinding: s }) === null) throw Error("Queued cancellation request disappeared during run binding");
1034
+ if (await e.update(Kt.tableName, r.id, { controlBinding: s }) === null) throw Error("Queued cancellation request disappeared during run binding");
1035
1035
  return {
1036
1036
  kind: "bound",
1037
1037
  request: {
@@ -1040,15 +1040,15 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
1040
1040
  },
1041
1041
  control: c
1042
1042
  };
1043
- }, nn = async (e, t) => {
1043
+ }, rn = async (e, t) => {
1044
1044
  let n = /* @__PURE__ */ new Set();
1045
- for await (let r of He(e, t.executionId, t.workflowName)) n.add(r.id);
1045
+ for await (let r of Ue(e, t.executionId, t.workflowName)) n.add(r.id);
1046
1046
  if (n.size === 0) return !1;
1047
1047
  let r, i = !1;
1048
1048
  for (;;) {
1049
1049
  let a = await e.query({
1050
- table: Gt.tableName,
1051
- predicate: B(V("workflowName", t.workflowName), ...r === void 0 ? [] : [H("id", r)]),
1050
+ table: Kt.tableName,
1051
+ predicate: z(B("workflowName", t.workflowName), ...r === void 0 ? [] : [V("id", r)]),
1052
1052
  lock: "update",
1053
1053
  order: [{
1054
1054
  column: "id",
@@ -1059,9 +1059,9 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
1059
1059
  projection: void 0
1060
1060
  });
1061
1061
  for (let o of a) {
1062
- let a = Jt(o);
1062
+ let a = Yt(o);
1063
1063
  if (r = a.id, a.target.kind !== "submission" || !n.has(a.target.submissionId)) continue;
1064
- let s = await tn(e, a.id, t);
1064
+ let s = await nn(e, a.id, t);
1065
1065
  if (s.kind === "bound") {
1066
1066
  if (s.control.runId !== t.runId || s.control.executionId !== t.executionId || s.control.workflowName !== t.workflowName) throw Error("Queued cancellation entry does not match its original resident execution");
1067
1067
  s.control.result === null && (i = !0);
@@ -1069,32 +1069,32 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
1069
1069
  }
1070
1070
  if (a.length < 100) return i;
1071
1071
  }
1072
- }, rn = z.Struct({
1073
- requestId: z.NonEmptyString,
1074
- receiptId: z.NonEmptyString,
1075
- workflowName: z.NonEmptyString,
1076
- tenantId: z.NullOr(z.String)
1077
- }), an = async (e, t) => {
1078
- let n = z.decodeUnknownSync(rn)(t);
1079
- return await en(e, {
1072
+ }, an = R.Struct({
1073
+ requestId: R.NonEmptyString,
1074
+ receiptId: R.NonEmptyString,
1075
+ workflowName: R.NonEmptyString,
1076
+ tenantId: R.NullOr(R.String)
1077
+ }), on = async (e, t) => {
1078
+ let n = R.decodeUnknownSync(an)(t);
1079
+ return await tn(e, {
1080
1080
  ...n,
1081
1081
  now: t.now,
1082
1082
  ...t.cause === void 0 ? {} : { cause: t.cause }
1083
- }), on(e, n);
1084
- }, on = async (e, t) => {
1085
- let n = z.decodeUnknownSync(rn)(t);
1086
- return $t(n, await Qt(e, n));
1083
+ }), sn(e, n);
1087
1084
  }, sn = async (e, t) => {
1085
+ let n = R.decodeUnknownSync(an)(t);
1086
+ return en(n, await $t(e, n));
1087
+ }, cn = async (e, t) => {
1088
1088
  if (new Set(t.intentIds).size !== t.intentIds.length) throw Error("Admitted transfer requires distinct pending identities");
1089
- let n = await N(e, t.id);
1089
+ let n = await M(e, t.id);
1090
1090
  if (n !== void 0) {
1091
1091
  if (n.workflowName !== t.workflowName || n.tenantId !== t.tenantId || n.ledgerId !== t.ledgerId || !n.receiptsBound) throw Error("Admitted transfer contradicts its existing submission");
1092
1092
  return n;
1093
1093
  }
1094
1094
  for (let n of t.intentIds) {
1095
1095
  let r = await e.query({
1096
- table: k,
1097
- predicate: V("id", n),
1096
+ table: O,
1097
+ predicate: B("id", n),
1098
1098
  order: [],
1099
1099
  take: 1,
1100
1100
  skip: void 0,
@@ -1102,19 +1102,19 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
1102
1102
  lock: "update"
1103
1103
  });
1104
1104
  if (r[0] === void 0) throw Error("Admitted transfer lost a selected input");
1105
- let i = F(r[0]);
1105
+ let i = P(r[0]);
1106
1106
  if (i.workflowName !== t.workflowName || i.tenantId !== t.tenantId || i.deadLetteredAt !== void 0) throw Error("Admitted transfer selected a foreign or dead-lettered input");
1107
1107
  }
1108
1108
  let r = await ie(e, t);
1109
- await Ae(e, r.id);
1109
+ await je(e, r.id);
1110
1110
  for (let t of r.intentIds) if (!await e.delete("_voltro_workflow_pending", t)) throw Error("Admitted input disappeared during submission transfer");
1111
1111
  return {
1112
1112
  ...r,
1113
1113
  receiptsBound: !0
1114
1114
  };
1115
- }, cn = async (e, t) => Ne(e, (e) => ln(e, t)), ln = async (e, t) => {
1115
+ }, ln = async (e, t) => Pe(e, (e) => un(e, t)), un = async (e, t) => {
1116
1116
  if (t.id.length === 0 || t.intentIds.length === 0 || new Set(t.intentIds).size !== t.intentIds.length) throw Error("Queue transfer requires a submission identity and distinct pending identities");
1117
- let n = await N(e, t.id);
1117
+ let n = await M(e, t.id);
1118
1118
  if (n !== void 0) {
1119
1119
  if (n.workflowName !== t.workflowName || n.tenantId !== t.tenantId) throw Error("Admission submission identity belongs to a different workflow or tenant");
1120
1120
  if (!n.receiptsBound) throw Error("Submission exists without completed queue transfer");
@@ -1127,8 +1127,8 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
1127
1127
  let r = [];
1128
1128
  for (let n of t.intentIds) {
1129
1129
  let i = await e.query({
1130
- table: k,
1131
- predicate: V("id", n),
1130
+ table: O,
1131
+ predicate: B("id", n),
1132
1132
  order: [],
1133
1133
  take: 1,
1134
1134
  skip: void 0,
@@ -1136,14 +1136,14 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
1136
1136
  lock: "update"
1137
1137
  });
1138
1138
  if (i[0] === void 0) return { kind: "selection-unavailable" };
1139
- let a = F(i[0]);
1139
+ let a = P(i[0]);
1140
1140
  if (a.workflowName !== t.workflowName || a.tenantId !== t.tenantId) throw Error("Selected pending start belongs to a different workflow or tenant");
1141
1141
  if (a.deadLetteredAt !== void 0 || a.dueAt > t.now) return { kind: "selection-unavailable" };
1142
1142
  r.push(a);
1143
1143
  }
1144
1144
  let i = t.prepare(r);
1145
1145
  if (i.control.workflowName !== t.workflowName) throw Error("Prepared submission belongs to a different workflow");
1146
- let a = await ke(e, {
1146
+ let a = await Ae(e, {
1147
1147
  ...i,
1148
1148
  id: t.id,
1149
1149
  tenantId: t.tenantId,
@@ -1151,7 +1151,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
1151
1151
  now: t.now
1152
1152
  });
1153
1153
  if (a.kind !== "reserved") return a;
1154
- await Ae(e, t.id);
1154
+ await je(e, t.id);
1155
1155
  for (let t of r) if (!await e.delete("_voltro_workflow_pending", t.id)) throw Error("Pending start disappeared during queue transfer");
1156
1156
  return {
1157
1157
  ...a,
@@ -1160,7 +1160,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
1160
1160
  receiptsBound: !0
1161
1161
  }
1162
1162
  };
1163
- }, un = async (e) => {
1163
+ }, dn = async (e) => {
1164
1164
  let { store: t, control: n, now: r } = e, i = D(n, e.payload), a = await ce({
1165
1165
  store: t,
1166
1166
  control: n,
@@ -1169,7 +1169,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
1169
1169
  now: r,
1170
1170
  reconsidering: !1
1171
1171
  });
1172
- if (a.kind === "drop") return await j({
1172
+ if (a.kind === "drop") return await A({
1173
1173
  store: t,
1174
1174
  control: n,
1175
1175
  keys: i,
@@ -1186,7 +1186,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
1186
1186
  kind: "dropped",
1187
1187
  retryAfterMs: a.retryAfterMs
1188
1188
  };
1189
- if (a.kind === "skip") return await j({
1189
+ if (a.kind === "skip") return await A({
1190
1190
  store: t,
1191
1191
  control: n,
1192
1192
  keys: i,
@@ -1222,12 +1222,12 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
1222
1222
  };
1223
1223
  let o = e.payload, s = [], c = 1;
1224
1224
  if (n.batch !== void 0 && i.batchKey !== void 0) {
1225
- let r = await dn(t, n.workflowName, i.batchKey, n.batch.maxSize);
1225
+ let r = await fn(t, n.workflowName, i.batchKey, n.batch.maxSize);
1226
1226
  o = { items: [...r.map((e) => e.payload), e.payload] }, s = r.map((e) => e.id), c = r.length + 1;
1227
1227
  }
1228
1228
  return {
1229
1229
  kind: "start",
1230
- ledgerId: await j({
1230
+ ledgerId: await A({
1231
1231
  store: t,
1232
1232
  control: n,
1233
1233
  keys: i,
@@ -1250,9 +1250,9 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
1250
1250
  runId: a.evict.runId
1251
1251
  } }
1252
1252
  };
1253
- }, dn = async (e, t, n, r) => (await e.query({
1253
+ }, fn = async (e, t, n, r) => (await e.query({
1254
1254
  table: "_voltro_workflow_pending",
1255
- predicate: B(V("workflowName", t), V("controlKey", n), V("mode", "batch")),
1255
+ predicate: z(B("workflowName", t), B("controlKey", n), B("mode", "batch")),
1256
1256
  order: [{
1257
1257
  column: "firstSeenAt",
1258
1258
  direction: "asc"
@@ -1263,22 +1263,22 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
1263
1263
  })).map((n) => ({
1264
1264
  id: String(n.id),
1265
1265
  payload: E(e, t, n.payload)
1266
- })), fn = async (e, t, n, r) => {
1266
+ })), pn = async (e, t, n, r) => {
1267
1267
  await e.update("_voltro_workflow_admissions", t, {
1268
1268
  executionId: n,
1269
1269
  runId: r
1270
1270
  });
1271
- }, pn = q("_voltro_workflow_watermarks", {
1272
- id: U({ prefix: "wfwm" }),
1273
- positionAt: Y(),
1274
- updatedAt: Y().default("now")
1275
- }), mn = (e) => {
1271
+ }, mn = K("_voltro_workflow_watermarks", {
1272
+ id: H({ prefix: "wfwm" }),
1273
+ positionAt: J(),
1274
+ updatedAt: J().default("now")
1275
+ }), hn = (e) => {
1276
1276
  let t = e instanceof Error ? e.message : String(e);
1277
1277
  return t.length > 400 ? `${t.slice(0, 400)}…` : t;
1278
- }, hn = (e) => {
1279
- let t = [], n = [], r = [], i = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set(), o = e.payloadSchema === void 0 ? (e) => R.right(e) : (t) => {
1280
- let n = z.decodeUnknownEither(e.payloadSchema)(t);
1281
- return R.isRight(n) ? R.right(n.right) : R.left(mn(n.left));
1278
+ }, gn = (e) => {
1279
+ let t = [], n = [], r = [], i = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set(), o = e.payloadSchema === void 0 ? (e) => L.right(e) : (t) => {
1280
+ let n = R.decodeUnknownEither(e.payloadSchema)(t);
1281
+ return L.isRight(n) ? L.right(n.right) : L.left(hn(n.left));
1282
1282
  }, s = e.runs.map((e) => ({
1283
1283
  run: e,
1284
1284
  decoded: o(e.payload)
@@ -1288,19 +1288,19 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
1288
1288
  }));
1289
1289
  for (let o of e.entries) for (let l of e.events) {
1290
1290
  if (l.name !== o.event) continue;
1291
- let u = z.decodeUnknownEither(o.schema)(l.payload);
1292
- if (R.isLeft(u)) {
1291
+ let u = R.decodeUnknownEither(o.schema)(l.payload);
1292
+ if (L.isLeft(u)) {
1293
1293
  r.push({
1294
1294
  kind: "event-decode",
1295
1295
  workflowName: e.workflowName,
1296
1296
  event: o.event,
1297
1297
  subject: l.id,
1298
- detail: mn(u.left)
1298
+ detail: hn(u.left)
1299
1299
  });
1300
1300
  continue;
1301
1301
  }
1302
1302
  let d = u.right, f = (e) => e.getTime() > l.occurredAt.getTime() ? !1 : o.withinMs === void 0 || l.occurredAt.getTime() - e.getTime() <= o.withinMs, p = (t, n) => {
1303
- if (R.isLeft(t)) return r.push({
1303
+ if (L.isLeft(t)) return r.push({
1304
1304
  kind: "payload-decode",
1305
1305
  workflowName: e.workflowName,
1306
1306
  event: o.event,
@@ -1315,7 +1315,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
1315
1315
  workflowName: e.workflowName,
1316
1316
  event: o.event,
1317
1317
  subject: n,
1318
- detail: mn(t)
1318
+ detail: hn(t)
1319
1319
  }), !1;
1320
1320
  }
1321
1321
  };
@@ -1338,33 +1338,33 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
1338
1338
  discards: n,
1339
1339
  problems: r
1340
1340
  };
1341
- }, gn = (e) => {
1341
+ }, _n = (e) => {
1342
1342
  let t;
1343
1343
  for (let n of e) (t === void 0 || n.occurredAt.getTime() > t.getTime()) && (t = n.occurredAt);
1344
1344
  return t;
1345
- }, _n = "_voltro_workflow_watermarks", vn = "_voltro_workflow_events", yn = "cancelOn", bn = 36e5, xn = 500, Sn = (e) => {
1345
+ }, vn = "_voltro_workflow_watermarks", yn = "_voltro_workflow_events", bn = "cancelOn", xn = 36e5, Sn = 500, Cn = (e) => {
1346
1346
  if (e instanceof Date) return e;
1347
1347
  if (typeof e == "number") return new Date(e);
1348
1348
  if (typeof e == "string") {
1349
1349
  let t = new Date(e);
1350
1350
  if (!Number.isNaN(t.getTime())) return t;
1351
1351
  }
1352
- }, Cn = (e) => e instanceof Error ? e.message : String(e), wn = async (e, t) => Sn((await e.query({
1353
- table: _n,
1354
- predicate: V("id", t),
1352
+ }, wn = (e) => e instanceof Error ? e.message : String(e), Tn = async (e, t) => Cn((await e.query({
1353
+ table: vn,
1354
+ predicate: B("id", t),
1355
1355
  order: [],
1356
1356
  take: 1,
1357
1357
  skip: void 0,
1358
1358
  projection: void 0
1359
- }))[0]?.positionAt), Tn = async (e, t, n) => {
1360
- await e.upsert(_n, {
1359
+ }))[0]?.positionAt), En = async (e, t, n) => {
1360
+ await e.upsert(vn, {
1361
1361
  id: t,
1362
1362
  positionAt: n,
1363
1363
  updatedAt: /* @__PURE__ */ new Date()
1364
1364
  }, {
1365
1365
  conflictColumns: ["id"],
1366
1366
  update: (e) => {
1367
- let t = Sn(e.positionAt);
1367
+ let t = Cn(e.positionAt);
1368
1368
  return t !== void 0 && t.getTime() >= n.getTime() ? {
1369
1369
  positionAt: t,
1370
1370
  updatedAt: /* @__PURE__ */ new Date()
@@ -1374,10 +1374,10 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
1374
1374
  };
1375
1375
  }
1376
1376
  });
1377
- }, En = async (e, t, n) => {
1377
+ }, Dn = async (e, t, n) => {
1378
1378
  let r = async (r) => e.query({
1379
1379
  table: "_voltro_workflow_runs",
1380
- predicate: B(V("tag", t), V("status", r)),
1380
+ predicate: z(B("tag", t), B("status", r)),
1381
1381
  order: [{
1382
1382
  column: "startedAt",
1383
1383
  direction: "asc"
@@ -1387,7 +1387,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
1387
1387
  projection: void 0
1388
1388
  });
1389
1389
  return [...await r("running"), ...await r("suspended")].flatMap((e) => {
1390
- let t = e, n = Sn(t.startedAt);
1390
+ let t = e, n = Cn(t.startedAt);
1391
1391
  return typeof t.id != "string" || typeof t.executionId != "string" || n === void 0 ? [] : [{
1392
1392
  runId: t.id,
1393
1393
  executionId: t.executionId,
@@ -1395,9 +1395,9 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
1395
1395
  startedAt: n
1396
1396
  }];
1397
1397
  });
1398
- }, Dn = async (e, t, n) => (await e.query({
1398
+ }, On = async (e, t, n) => (await e.query({
1399
1399
  table: "_voltro_workflow_pending",
1400
- predicate: V("workflowName", t),
1400
+ predicate: B("workflowName", t),
1401
1401
  order: [{
1402
1402
  column: "firstSeenAt",
1403
1403
  direction: "asc"
@@ -1406,13 +1406,13 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
1406
1406
  skip: void 0,
1407
1407
  projection: void 0
1408
1408
  })).flatMap((e) => {
1409
- let t = e, n = Sn(t.firstSeenAt);
1409
+ let t = e, n = Cn(t.firstSeenAt);
1410
1410
  return typeof t.id != "string" || n === void 0 ? [] : [{
1411
1411
  intentId: t.id,
1412
1412
  payload: t.payload,
1413
1413
  firstSeenAt: n
1414
1414
  }];
1415
- }), On = async (e, t) => {
1415
+ }), kn = async (e, t) => {
1416
1416
  let n = t.workflows.filter((e) => e.entries.length > 0);
1417
1417
  if (n.length === 0) return {
1418
1418
  examined: !1,
@@ -1427,11 +1427,11 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
1427
1427
  };
1428
1428
  let r = e.now?.() ?? Date.now(), i = t.batch ?? 500, a = t.coldLookbackMs ?? 36e5, o = /* @__PURE__ */ new Set();
1429
1429
  for (let e of n) for (let t of e.entries) o.add(t.event);
1430
- let s = await wn(e.store, yn), c = s ?? new Date(r - a);
1431
- s === void 0 && (await Tn(e.store, yn, c), s = c);
1430
+ let s = await Tn(e.store, bn), c = s ?? new Date(r - a);
1431
+ s === void 0 && (await En(e.store, bn, c), s = c);
1432
1432
  let l = await e.store.query({
1433
- table: vn,
1434
- predicate: nt("occurredAt", c),
1433
+ table: yn,
1434
+ predicate: it("occurredAt", c),
1435
1435
  order: [{
1436
1436
  column: "occurredAt",
1437
1437
  direction: "asc"
@@ -1441,7 +1441,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
1441
1441
  projection: void 0
1442
1442
  }), u = [];
1443
1443
  for (let e of l) {
1444
- let t = e, n = Sn(t.occurredAt);
1444
+ let t = e, n = Cn(t.occurredAt);
1445
1445
  typeof t.id == "string" && typeof t.name == "string" && n !== void 0 && o.has(t.name) && u.push({
1446
1446
  id: t.id,
1447
1447
  name: t.name,
@@ -1455,15 +1455,15 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
1455
1455
  if (n.length === 0) continue;
1456
1456
  let r = [], i = [];
1457
1457
  try {
1458
- r = await En(e.store, t.workflowName, _), i = await Dn(e.store, t.workflowName, _), (r.length >= _ || i.length >= _) && (h = !0);
1458
+ r = await Dn(e.store, t.workflowName, _), i = await On(e.store, t.workflowName, _), (r.length >= _ || i.length >= _) && (h = !0);
1459
1459
  } catch (e) {
1460
1460
  f.push({
1461
1461
  subject: t.workflowName,
1462
- detail: Cn(e)
1462
+ detail: wn(e)
1463
1463
  }), g = !0;
1464
1464
  continue;
1465
1465
  }
1466
- let a = hn({
1466
+ let a = gn({
1467
1467
  workflowName: t.workflowName,
1468
1468
  entries: t.entries,
1469
1469
  payloadSchema: t.payloadSchema,
@@ -1485,7 +1485,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
1485
1485
  } catch (e) {
1486
1486
  f.push({
1487
1487
  subject: n.runId,
1488
- detail: Cn(e)
1488
+ detail: wn(e)
1489
1489
  }), g = !0;
1490
1490
  }
1491
1491
  for (let n of a.discards) try {
@@ -1496,18 +1496,18 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
1496
1496
  } catch (e) {
1497
1497
  f.push({
1498
1498
  subject: n.intentId,
1499
- detail: Cn(e)
1499
+ detail: wn(e)
1500
1500
  }), g = !0;
1501
1501
  }
1502
1502
  }
1503
- let v = gn(u), y = s;
1503
+ let v = _n(u), y = s;
1504
1504
  if (g) e.log?.warn("workflow.cancelOn: holding the watermark — evaluation or delivery remains incomplete", { failures: f.length });
1505
1505
  else if (v !== void 0) try {
1506
- await Tn(e.store, yn, v), y = v;
1506
+ await En(e.store, bn, v), y = v;
1507
1507
  } catch (e) {
1508
1508
  f.push({
1509
- subject: yn,
1510
- detail: Cn(e)
1509
+ subject: bn,
1510
+ detail: wn(e)
1511
1511
  });
1512
1512
  }
1513
1513
  return d.length > 0 && e.log?.warn("workflow.cancelOn: some events could not be evaluated", {
@@ -1524,16 +1524,16 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
1524
1524
  failures: f,
1525
1525
  watermark: y
1526
1526
  };
1527
- }, kn = 18e5, An = 200, jn = 20, Mn = (e) => {
1527
+ }, An = 18e5, jn = 200, Mn = 20, Nn = (e) => {
1528
1528
  if (e instanceof Date) return e;
1529
1529
  if (typeof e == "number") return new Date(e);
1530
1530
  if (typeof e == "string") {
1531
1531
  let t = new Date(e);
1532
1532
  if (!Number.isNaN(t.getTime())) return t;
1533
1533
  }
1534
- }, Nn = (e) => e instanceof Error ? e.message : String(e), Pn = async (e, t, n) => (await e.query({
1534
+ }, Pn = (e) => e instanceof Error ? e.message : String(e), Fn = async (e, t, n) => (await e.query({
1535
1535
  table: "_voltro_workflow_run_events",
1536
- predicate: V("runId", t),
1536
+ predicate: B("runId", t),
1537
1537
  order: [{
1538
1538
  column: "occurredAt",
1539
1539
  direction: "desc"
@@ -1542,16 +1542,16 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
1542
1542
  skip: void 0,
1543
1543
  projection: void 0
1544
1544
  })).flatMap((e) => {
1545
- let t = e, n = Mn(t.occurredAt);
1545
+ let t = e, n = Nn(t.occurredAt);
1546
1546
  return typeof t.eventType != "string" || n === void 0 ? [] : [{
1547
1547
  eventType: t.eventType,
1548
1548
  occurredAt: n,
1549
1549
  payload: t.payload
1550
1550
  }];
1551
- }), Fn = async (e, t) => {
1551
+ }), In = async (e, t) => {
1552
1552
  let n = (await e.query({
1553
1553
  table: "_voltro_workflow_run_steps",
1554
- predicate: V("runId", t),
1554
+ predicate: B("runId", t),
1555
1555
  order: [{
1556
1556
  column: "startedAt",
1557
1557
  direction: "desc"
@@ -1561,24 +1561,24 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
1561
1561
  projection: void 0
1562
1562
  }))[0];
1563
1563
  if (n === void 0) return;
1564
- let r = Mn(n.startedAt), i = Mn(n.completedAt);
1564
+ let r = Nn(n.startedAt), i = Nn(n.completedAt);
1565
1565
  return r === void 0 ? i : i === void 0 ? r : i.getTime() > r.getTime() ? i : r;
1566
- }, In = (e, t) => {
1566
+ }, Ln = (e, t) => {
1567
1567
  for (let n of e) {
1568
1568
  if (n.eventType === "timer-fired") return !1;
1569
1569
  if (n.eventType !== "timer-set") continue;
1570
- let e = Mn(n.payload?.scheduledWakeAt);
1570
+ let e = Nn(n.payload?.scheduledWakeAt);
1571
1571
  return e !== void 0 && e.getTime() > t;
1572
1572
  }
1573
1573
  return !1;
1574
- }, Ln = (e, t) => {
1574
+ }, Rn = (e, t) => {
1575
1575
  if (e !== "suspended") return "no-progress";
1576
1576
  for (let e of t) {
1577
1577
  if (e.eventType === "signal-received" || e.eventType === "signal-sent") return "suspended";
1578
1578
  if (e.eventType === "signal-awaited") return "awaiting-signal";
1579
1579
  }
1580
1580
  return "suspended";
1581
- }, Rn = async (e, t = {}) => {
1581
+ }, zn = async (e, t = {}) => {
1582
1582
  let n = e.now?.() ?? Date.now(), r = t.stallAfterMs ?? 18e5, i = t.runPage ?? 200, a = t.eventLookback ?? 20, o = new Date(n - r), s = [], c = [], l = 0, u = 0, d, f;
1583
1583
  try {
1584
1584
  if (!Number.isSafeInteger(i) || i < 1) throw Error("Staleness run page must be a positive integer");
@@ -1586,7 +1586,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
1586
1586
  if (n !== void 0 && (!(n.startedAt instanceof Date) || !Number.isFinite(n.startedAt.getTime()) || typeof n.runId != "string" || n.runId.length === 0)) throw Error("Invalid staleness run cursor");
1587
1587
  d = await e.store.query({
1588
1588
  table: "_voltro_workflow_runs",
1589
- predicate: B(rt("status", ["running", "suspended"]), at("startedAt", o), ...n === void 0 ? [] : [ot(H("startedAt", n.startedAt), B(V("startedAt", n.startedAt), H("id", n.runId)))]),
1589
+ predicate: z(at("status", ["running", "suspended"]), st("startedAt", o), ...n === void 0 ? [] : [ct(V("startedAt", n.startedAt), z(B("startedAt", n.startedAt), V("id", n.runId)))]),
1590
1590
  order: [{
1591
1591
  column: "startedAt",
1592
1592
  direction: "asc"
@@ -1600,7 +1600,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
1600
1600
  });
1601
1601
  let r = n;
1602
1602
  for (let e of d) {
1603
- let t = Mn(e.startedAt);
1603
+ let t = Nn(e.startedAt);
1604
1604
  if (t === void 0 || !Number.isFinite(t.getTime()) || typeof e.id != "string" || e.id.length === 0) throw Error("Staleness candidate has no valid pagination identity");
1605
1605
  if (r !== void 0 && (t.getTime() < r.startedAt.getTime() || t.getTime() === r.startedAt.getTime() && e.id <= r.runId)) throw Error("Staleness candidate page did not advance");
1606
1606
  r = {
@@ -1618,24 +1618,24 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
1618
1618
  sawFullRunPage: !1,
1619
1619
  failures: [{
1620
1620
  subject: "_voltro_workflow_runs",
1621
- detail: Nn(e)
1621
+ detail: Pn(e)
1622
1622
  }]
1623
1623
  };
1624
1624
  }
1625
1625
  for (let t of d) {
1626
- let i = t, o = Mn(i.startedAt);
1626
+ let i = t, o = Nn(i.startedAt);
1627
1627
  if (typeof i.id != "string" || typeof i.tag != "string" || typeof i.executionId != "string" || typeof i.status != "string" || o === void 0) continue;
1628
1628
  let d, f;
1629
1629
  try {
1630
- d = await Pn(e.store, i.id, a), f = await Fn(e.store, i.id);
1630
+ d = await Fn(e.store, i.id, a), f = await In(e.store, i.id);
1631
1631
  } catch (e) {
1632
1632
  s.push({
1633
1633
  subject: i.id,
1634
- detail: Nn(e)
1634
+ detail: Pn(e)
1635
1635
  });
1636
1636
  continue;
1637
1637
  }
1638
- if (In(d, n)) {
1638
+ if (Ln(d, n)) {
1639
1639
  u += 1;
1640
1640
  continue;
1641
1641
  }
@@ -1654,7 +1654,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
1654
1654
  status: i.status,
1655
1655
  lastProgressAt: m,
1656
1656
  idleMs: h,
1657
- reason: Ln(i.status, d)
1657
+ reason: Rn(i.status, d)
1658
1658
  };
1659
1659
  c.push(g);
1660
1660
  let _ = {};
@@ -1663,7 +1663,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
1663
1663
  } catch (e) {
1664
1664
  s.push({
1665
1665
  subject: `${g.runId}:describeRun`,
1666
- detail: Nn(e)
1666
+ detail: Pn(e)
1667
1667
  });
1668
1668
  }
1669
1669
  if (e.log?.warn("workflow.staleness: run has made no progress", {
@@ -1689,7 +1689,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
1689
1689
  } catch (e) {
1690
1690
  s.push({
1691
1691
  subject: g.runId,
1692
- detail: Nn(e)
1692
+ detail: Pn(e)
1693
1693
  });
1694
1694
  }
1695
1695
  if (e.onStalled !== void 0) try {
@@ -1697,7 +1697,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
1697
1697
  } catch (e) {
1698
1698
  s.push({
1699
1699
  subject: `${g.runId}:onStalled`,
1700
- detail: Nn(e)
1700
+ detail: Pn(e)
1701
1701
  });
1702
1702
  }
1703
1703
  }
@@ -1710,8 +1710,8 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
1710
1710
  failures: s,
1711
1711
  ...f === void 0 ? {} : { nextRun: f }
1712
1712
  };
1713
- }, zn = async (e, t, n) => {
1714
- let r = await e.transaction((e) => N(e, t.id));
1713
+ }, Bn = async (e, t, n) => {
1714
+ let r = await e.transaction((e) => M(e, t.id));
1715
1715
  if (r === void 0 || r.workflowName !== t.workflowName || r.tenantId !== t.tenantId || r.ledgerId !== t.ledgerId) throw Error("Submission dispatch lost its resident owner");
1716
1716
  if (!r.receiptsBound || r.failureId !== null) throw Error("Cannot dispatch an incomplete or rejected submission");
1717
1717
  if (r.preparedExecutionId !== null) {
@@ -1719,19 +1719,19 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
1719
1719
  return r.preparedExecutionId;
1720
1720
  }
1721
1721
  if (r.dispatchAttempts !== 0 || r.executionId !== null) throw Error("Submission has an unbound prior dispatch; reconciliation required");
1722
- let i = await e.resolveExecutionId(t.workflowName, n), a = await e.transaction((e) => ze(e, t.id, i));
1722
+ let i = await e.resolveExecutionId(t.workflowName, n), a = await e.transaction((e) => Be(e, t.id, i));
1723
1723
  if (a.preparedExecutionId === null) throw Error("Submission preparation returned no execution identity");
1724
1724
  return a.preparedExecutionId;
1725
- }, Bn = /* @__PURE__ */ new WeakMap(), Vn = async (e, t, n, r) => {
1726
- let i = Bn.get(e), a = await w(e.store, n, i?.afterId), o = 0, s = 0, c = 0, l = 0, u = i?.nextDueAt, d = (e) => {
1725
+ }, Vn = /* @__PURE__ */ new WeakMap(), Hn = async (e, t, n, r) => {
1726
+ let i = Vn.get(e), a = await w(e.store, n, i?.afterId), o = 0, s = 0, c = 0, l = 0, u = i?.nextDueAt, d = (e) => {
1727
1727
  u = Math.min(u ?? e, e);
1728
1728
  };
1729
1729
  for (let n of a) {
1730
1730
  let i;
1731
1731
  try {
1732
- i = Le(n);
1732
+ i = Re(n);
1733
1733
  } catch {
1734
- o++, c++, d(t + Fe(1)), e.log?.warn?.("workflow submission metadata is invalid", { submissionId: typeof n.id == "string" ? n.id : null });
1734
+ o++, c++, d(t + Ie(1)), e.log?.warn?.("workflow submission metadata is invalid", { submissionId: typeof n.id == "string" ? n.id : null });
1735
1735
  continue;
1736
1736
  }
1737
1737
  o++;
@@ -1757,7 +1757,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
1757
1757
  continue;
1758
1758
  }
1759
1759
  let c = r ?? await (async () => {
1760
- let n = e.controls.get(i.workflowName)?.batch === void 0 ? E(e.store, i.workflowName, i.payload) : { items: z.decodeUnknownSync(z.Struct({ items: z.Array(z.Unknown) }))(i.payload).items.map((t) => E(e.store, i.workflowName, t)) }, r = await zn(e, i, n), o = await e.transaction((e) => be(e, i.id, t));
1760
+ let n = e.controls.get(i.workflowName)?.batch === void 0 ? E(e.store, i.workflowName, i.payload) : { items: R.decodeUnknownSync(R.Struct({ items: R.Array(R.Unknown) }))(i.payload).items.map((t) => E(e.store, i.workflowName, t)) }, r = await Bn(e, i, n), o = await e.transaction((e) => xe(e, i.id, t));
1761
1761
  if (o === null) return;
1762
1762
  a = o.dispatchAttempts === 1 ? 1 : void 0;
1763
1763
  let s = await e.startAdmitted(i.workflowName, n, i.callerContext, r);
@@ -1773,7 +1773,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
1773
1773
  source: "flow-control",
1774
1774
  mode: "singleton"
1775
1775
  }
1776
- }), await x(e.store, i.eviction.executionId, t)), await e.transaction((e) => Ce(e, i.id, {
1776
+ }), await x(e.store, i.eviction.executionId, t)), await e.transaction((e) => we(e, i.id, {
1777
1777
  executionId: c.executionId,
1778
1778
  runId: c.runId ?? null
1779
1779
  })), s++;
@@ -1796,7 +1796,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
1796
1796
  continue;
1797
1797
  }
1798
1798
  }
1799
- o = await e.transaction((e) => Be(e, i.id, String(n), t, r));
1799
+ o = await e.transaction((e) => Ve(e, i.id, String(n), t, r));
1800
1800
  } catch (r) {
1801
1801
  d(t), e.log?.warn?.("workflow submission retry state could not be recorded", {
1802
1802
  workflow: i.workflowName,
@@ -1816,7 +1816,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
1816
1816
  }
1817
1817
  }
1818
1818
  let f = a.at(-1);
1819
- return a.length === n && f !== void 0 && typeof f.id == "string" ? (Bn.set(e, {
1819
+ return a.length === n && f !== void 0 && typeof f.id == "string" ? (Vn.set(e, {
1820
1820
  afterId: f.id,
1821
1821
  nextDueAt: u
1822
1822
  }), {
@@ -1826,7 +1826,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
1826
1826
  rejected: l,
1827
1827
  nextDueAt: t,
1828
1828
  examined: !0
1829
- }) : (Bn.delete(e), {
1829
+ }) : (Vn.delete(e), {
1830
1830
  scanned: o,
1831
1831
  admitted: s,
1832
1832
  failed: c,
@@ -1834,10 +1834,10 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
1834
1834
  nextDueAt: u,
1835
1835
  examined: a.length > 0
1836
1836
  });
1837
- }, Hn = /* @__PURE__ */ new WeakMap(), Un = async (e, t, n) => {
1838
- let r = Hn.get(e), i = await e.store.query({
1837
+ }, Un = /* @__PURE__ */ new WeakMap(), Wn = async (e, t, n) => {
1838
+ let r = Un.get(e), i = await e.store.query({
1839
1839
  table: le,
1840
- predicate: B(it("handler"), G("acceptedExecutionId"), ...r === void 0 ? [] : [H("id", r.afterId)]),
1840
+ predicate: z(ot("handler"), W("acceptedExecutionId"), ...r === void 0 ? [] : [V("id", r.afterId)]),
1841
1841
  order: [{
1842
1842
  column: "id",
1843
1843
  direction: "asc"
@@ -1846,7 +1846,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
1846
1846
  skip: void 0,
1847
1847
  projection: void 0
1848
1848
  }), a = 0, o = !1, s = r?.nextDueAt, c = () => {
1849
- let e = t + Fe(1, () => 1);
1849
+ let e = t + Ie(1, () => 1);
1850
1850
  s = Math.min(s ?? e, e);
1851
1851
  };
1852
1852
  for (let n of i) try {
@@ -1856,11 +1856,11 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
1856
1856
  } catch (t) {
1857
1857
  a++, c(), e.log?.warn?.("workflow failure delivery could not be reconciled", {
1858
1858
  failureId: typeof n.id == "string" ? n.id : null,
1859
- ...t instanceof De ? { reason: t.reason } : {}
1859
+ ...t instanceof Oe ? { reason: t.reason } : {}
1860
1860
  });
1861
1861
  }
1862
1862
  let l = i.at(-1);
1863
- return i.length === n && l !== void 0 && typeof l.id == "string" ? (Hn.set(e, {
1863
+ return i.length === n && l !== void 0 && typeof l.id == "string" ? (Un.set(e, {
1864
1864
  afterId: l.id,
1865
1865
  nextDueAt: s
1866
1866
  }), {
@@ -1869,17 +1869,17 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
1869
1869
  hasPending: o,
1870
1870
  nextDueAt: t,
1871
1871
  examined: !0
1872
- }) : (Hn.delete(e), {
1872
+ }) : (Un.delete(e), {
1873
1873
  scanned: i.length,
1874
1874
  failed: a,
1875
1875
  hasPending: o,
1876
1876
  nextDueAt: s,
1877
1877
  examined: i.length > 0
1878
1878
  });
1879
- }, Wn = "_voltro_workflow_parent_closures", Gn = /* @__PURE__ */ new WeakMap(), Kn = async (e, t, n) => {
1880
- let r = Gn.get(e), i = await e.store.query({
1881
- table: Wn,
1882
- predicate: B(G("completedAt"), ...r === void 0 ? [] : [H("id", r.afterId)]),
1879
+ }, Gn = "_voltro_workflow_parent_closures", Kn = /* @__PURE__ */ new WeakMap(), qn = async (e, t, n) => {
1880
+ let r = Kn.get(e), i = await e.store.query({
1881
+ table: Gn,
1882
+ predicate: z(W("completedAt"), ...r === void 0 ? [] : [V("id", r.afterId)]),
1883
1883
  order: [{
1884
1884
  column: "id",
1885
1885
  direction: "asc"
@@ -1894,10 +1894,10 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
1894
1894
  if (typeof n.id != "string" || n.id.length === 0) throw Error("Parent closure has no identity");
1895
1895
  let r = n.id;
1896
1896
  await e.transaction(async (e) => {
1897
- await Pt(e, r, t);
1897
+ await Ft(e, r, t);
1898
1898
  let [n] = await e.query({
1899
- table: Wn,
1900
- predicate: V("id", r),
1899
+ table: Gn,
1900
+ predicate: B("id", r),
1901
1901
  order: [],
1902
1902
  take: 1,
1903
1903
  skip: void 0,
@@ -1910,7 +1910,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
1910
1910
  a++, s(), e.log?.warn?.("workflow parent closure could not be reconciled", { closureId: typeof n.id == "string" ? n.id : null });
1911
1911
  }
1912
1912
  let c = i.at(-1);
1913
- return i.length === n && typeof c?.id == "string" ? (Gn.set(e, {
1913
+ return i.length === n && typeof c?.id == "string" ? (Kn.set(e, {
1914
1914
  afterId: c.id,
1915
1915
  nextDueAt: o
1916
1916
  }), {
@@ -1918,30 +1918,30 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
1918
1918
  failed: a,
1919
1919
  nextDueAt: t,
1920
1920
  examined: !0
1921
- }) : (Gn.delete(e), {
1921
+ }) : (Kn.delete(e), {
1922
1922
  scanned: i.length,
1923
1923
  failed: a,
1924
1924
  nextDueAt: o,
1925
1925
  examined: i.length > 0
1926
1926
  });
1927
- }, qn = async (e, t) => {
1927
+ }, Jn = async (e, t) => {
1928
1928
  if (t.from === t.to) throw Error("Queue transfer requires distinct source and target");
1929
1929
  let n = await e.query({
1930
- table: k,
1931
- predicate: V("id", t.to),
1930
+ table: O,
1931
+ predicate: B("id", t.to),
1932
1932
  order: [],
1933
1933
  take: 1,
1934
1934
  skip: void 0,
1935
1935
  projection: void 0
1936
- }), r = z.decodeUnknownSync(z.Struct({
1937
- workflowName: z.String,
1938
- tenantId: z.NullOr(z.String)
1936
+ }), r = R.decodeUnknownSync(R.Struct({
1937
+ workflowName: R.String,
1938
+ tenantId: R.NullOr(R.String)
1939
1939
  }))(n[0]);
1940
1940
  if (r.workflowName !== t.workflowName || r.tenantId !== t.tenantId) throw Error("Receipt target belongs to a different workflow or tenant");
1941
1941
  for (;;) {
1942
1942
  let n = await e.query({
1943
- table: Ee,
1944
- predicate: B(V("pendingId", t.from), G("submissionId"), G("terminal")),
1943
+ table: De,
1944
+ predicate: z(B("pendingId", t.from), W("submissionId"), W("terminal")),
1945
1945
  order: [{
1946
1946
  column: "id",
1947
1947
  direction: "asc"
@@ -1952,12 +1952,12 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
1952
1952
  });
1953
1953
  if (n.length === 0) return;
1954
1954
  for (let r of n) {
1955
- let n = Pe(r);
1955
+ let n = Fe(r);
1956
1956
  if (n.workflowName !== t.workflowName || n.tenantId !== t.tenantId) throw Error("Forwarded receipt belongs to a different workflow or tenant");
1957
1957
  if (await e.update("_voltro_workflow_start_receipts", n.id, { pendingId: t.to }) === null) throw Error("Start receipt disappeared during queue transfer");
1958
1958
  }
1959
1959
  }
1960
- }, Jn = {
1960
+ }, Yn = {
1961
1961
  scanned: 0,
1962
1962
  admitted: 0,
1963
1963
  deferred: 0,
@@ -1969,24 +1969,24 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
1969
1969
  deadLettered: 0,
1970
1970
  timedOut: 0,
1971
1971
  examined: !1
1972
- }, Yn = 200, Xn = class extends Error {
1972
+ }, Xn = 200, Zn = class extends Error {
1973
1973
  submissionId;
1974
1974
  rejected;
1975
1975
  constructor(e, t, n = !1) {
1976
1976
  super(n ? `Submission ${e} rejected; failure report retained` : `Submission ${e} remains unacknowledged`, { cause: t }), this.submissionId = e, this.rejected = n;
1977
1977
  }
1978
- }, Zn = (e) => e instanceof Xn && !e.rejected, Qn = async (e, t = {}) => {
1978
+ }, Qn = (e) => e instanceof Zn && !e.rejected, $n = async (e, t = {}) => {
1979
1979
  let n = e.now ?? (() => Date.now()), r = e.log, i = t.batchSize ?? 200, a, o, s, c, l, u;
1980
1980
  try {
1981
- c = await Vn(e, n(), i, e.deadLetterAfterAttempts ?? 50), l = await Un(e, n(), i), u = await Kn(e, n(), i), a = await (e.readPauses?.() ?? ye(e.store));
1981
+ c = await Hn(e, n(), i, e.deadLetterAfterAttempts ?? 50), l = await Wn(e, n(), i), u = await qn(e, n(), i), a = await (e.readPauses?.() ?? be(e.store));
1982
1982
  let r = t.skipPending === !0 && !l.hasPending ? {
1983
1983
  due: [],
1984
1984
  nextDueAt: void 0
1985
- } : await Me(e.store, n(), i);
1985
+ } : await Ne(e.store, n(), i);
1986
1986
  o = r.due, s = c.nextDueAt === void 0 ? r.nextDueAt : Math.min(r.nextDueAt ?? c.nextDueAt, c.nextDueAt), l.nextDueAt !== void 0 && (s = Math.min(s ?? l.nextDueAt, l.nextDueAt)), u.nextDueAt !== void 0 && (s = Math.min(s ?? u.nextDueAt, u.nextDueAt));
1987
1987
  } catch (e) {
1988
1988
  return r?.warn?.("workflow flow control: could not read the admission queue", { cause: String(e) }), {
1989
- ...Jn,
1989
+ ...Yn,
1990
1990
  scanned: (c?.scanned ?? 0) + (l?.scanned ?? 0) + (u?.scanned ?? 0),
1991
1991
  admitted: c?.admitted ?? 0,
1992
1992
  deadLettered: c?.rejected ?? 0,
@@ -2019,9 +2019,9 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2019
2019
  if (h !== !1 && t.attempts + 1 >= h) return `pending ${r} was dead-lettered after ${t.attempts + 1} failed attempts: ${String(n)}`;
2020
2020
  };
2021
2021
  for (let t of m) try {
2022
- await nr(e, t, a, d, n());
2022
+ await rr(e, t, a, d, n());
2023
2023
  } catch (i) {
2024
- if (d.failed++, i instanceof Xn) {
2024
+ if (d.failed++, i instanceof Zn) {
2025
2025
  i.rejected && d.deadLettered++, r?.warn?.(i.message, {
2026
2026
  submissionId: i.submissionId,
2027
2027
  cause: y(t.workflowName, i.cause)
@@ -2031,7 +2031,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2031
2031
  let a = g(t, i, "intent");
2032
2032
  if (a !== void 0) {
2033
2033
  let o = n(), s = String(i);
2034
- if (await er(e, [t], a, s, o, !1).catch((e) => (r?.warn?.("workflow flow control: intent could not be dead-lettered with its report", {
2034
+ if (await tr(e, [t], a, s, o, !1).catch((e) => (r?.warn?.("workflow flow control: intent could not be dead-lettered with its report", {
2035
2035
  workflow: t.workflowName,
2036
2036
  intent: t.id,
2037
2037
  cause: String(e)
@@ -2048,12 +2048,12 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2048
2048
  workflow: t.workflowName,
2049
2049
  intent: t.id,
2050
2050
  cause: y(t.workflowName, i)
2051
- }), await ge(e.store, t, String(i), n()).catch(() => {});
2051
+ }), await _e(e.store, t, String(i), n()).catch(() => {});
2052
2052
  }
2053
2053
  for (let t of f.values()) try {
2054
- await ir(e, t, a, d, n());
2054
+ await ar(e, t, a, d, n());
2055
2055
  } catch (i) {
2056
- if (d.failed++, i instanceof Xn) {
2056
+ if (d.failed++, i instanceof Zn) {
2057
2057
  i.rejected && d.deadLettered++, r?.warn?.(i.message, {
2058
2058
  submissionId: i.submissionId,
2059
2059
  cause: y(t[0]?.workflowName, i.cause)
@@ -2063,7 +2063,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2063
2063
  let a = t[0], o = a === void 0 ? void 0 : g(a, i, "batch");
2064
2064
  if (a !== void 0 && o !== void 0) {
2065
2065
  let s = n(), c = String(i);
2066
- if (await er(e, t, o, c, s, !0).catch((e) => (r?.warn?.("workflow flow control: batch could not be dead-lettered with its report", {
2066
+ if (await tr(e, t, o, c, s, !0).catch((e) => (r?.warn?.("workflow flow control: batch could not be dead-lettered with its report", {
2067
2067
  workflow: a.workflowName,
2068
2068
  intents: t.map((e) => e.id),
2069
2069
  size: t.length,
@@ -2088,8 +2088,8 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2088
2088
  let n = [];
2089
2089
  for (let r of t) {
2090
2090
  let t = await e.query({
2091
- table: k,
2092
- predicate: V("id", r.id),
2091
+ table: O,
2092
+ predicate: B("id", r.id),
2093
2093
  order: [],
2094
2094
  take: 1,
2095
2095
  skip: void 0,
@@ -2097,11 +2097,11 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2097
2097
  lock: "update"
2098
2098
  });
2099
2099
  if (t[0] === void 0) return;
2100
- let i = F(t[0]);
2100
+ let i = P(t[0]);
2101
2101
  if (i.workflowName !== r.workflowName || i.tenantId !== r.tenantId || i.mode !== r.mode || i.firstSeenAt !== r.firstSeenAt || i.dueAt !== r.dueAt || i.deadLetteredAt !== void 0) return;
2102
2102
  n.push(i);
2103
2103
  }
2104
- let r = new Date(s + Fe(Math.max(...n.map((e) => e.attempts + 1)), () => c));
2104
+ let r = new Date(s + Ie(Math.max(...n.map((e) => e.attempts + 1)), () => c));
2105
2105
  for (let t of n) if (await e.update("_voltro_workflow_pending", t.id, {
2106
2106
  attempts: t.attempts + 1,
2107
2107
  lastError: p(t.workflowName, String(i).slice(0, 500)),
@@ -2114,23 +2114,23 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2114
2114
  cause: String(e)
2115
2115
  }));
2116
2116
  }
2117
- let _ = await cr(e, n()).catch(() => ({ cancelled: 0 }));
2117
+ let _ = await lr(e, n()).catch(() => ({ cancelled: 0 }));
2118
2118
  return d.timedOut = _.cancelled, _.nextDeadlineAt !== void 0 && (s === void 0 || _.nextDeadlineAt < s) && (s = _.nextDeadlineAt), {
2119
2119
  ...d,
2120
2120
  examined: t.skipPending !== !0 || c.examined || l.examined || u.examined,
2121
2121
  ...s === void 0 ? {} : { nextDueAt: s }
2122
2122
  };
2123
- }, $n = async (e, t, n) => {
2123
+ }, er = async (e, t, n) => {
2124
2124
  let r = t.map((e) => ({
2125
2125
  intent: e,
2126
- failureId: `wff_${pt()}`
2126
+ failureId: `wff_${ht()}`
2127
2127
  }));
2128
2128
  return e.transaction(async (e) => {
2129
2129
  let t = 0;
2130
2130
  for (let { intent: i, failureId: a } of r) {
2131
2131
  let r = (await e.query({
2132
- table: k,
2133
- predicate: V("id", i.id),
2132
+ table: O,
2133
+ predicate: B("id", i.id),
2134
2134
  order: [],
2135
2135
  take: 1,
2136
2136
  skip: void 0,
@@ -2138,11 +2138,11 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2138
2138
  lock: "update"
2139
2139
  }))[0];
2140
2140
  if (r === void 0) continue;
2141
- let o = F(r);
2141
+ let o = P(r);
2142
2142
  if (o.workflowName !== i.workflowName || o.tenantId !== i.tenantId) throw Error("Abandoned queue selection belongs to another workflow or tenant");
2143
2143
  if (o.dueAt > n || o.deadLetteredAt !== void 0) continue;
2144
2144
  let s = `workflow '${o.workflowName}' no longer has its queued declaration`;
2145
- if (await M(e, {
2145
+ if (await j(e, {
2146
2146
  id: a,
2147
2147
  sourceKind: "intent",
2148
2148
  sourceId: o.id,
@@ -2160,7 +2160,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2160
2160
  runId: null,
2161
2161
  executionId: null
2162
2162
  }
2163
- }), await P(e, {
2163
+ }), await N(e, {
2164
2164
  pendingId: o.id,
2165
2165
  workflowName: o.workflowName,
2166
2166
  tenantId: o.tenantId,
@@ -2174,14 +2174,14 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2174
2174
  }
2175
2175
  return t;
2176
2176
  });
2177
- }, er = async (e, t, n, r, i, a) => {
2178
- let o = `wff_${pt()}`;
2177
+ }, tr = async (e, t, n, r, i, a) => {
2178
+ let o = `wff_${ht()}`;
2179
2179
  return e.transaction(async (s) => {
2180
2180
  let c = [];
2181
2181
  for (let e of t) {
2182
2182
  let t = await s.query({
2183
- table: k,
2184
- predicate: V("id", e.id),
2183
+ table: O,
2184
+ predicate: B("id", e.id),
2185
2185
  order: [],
2186
2186
  take: 1,
2187
2187
  skip: void 0,
@@ -2189,17 +2189,17 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2189
2189
  lock: "update"
2190
2190
  });
2191
2191
  if (t[0] === void 0) return 0;
2192
- let n = F(t[0]);
2192
+ let n = P(t[0]);
2193
2193
  if (n.workflowName !== e.workflowName || n.tenantId !== e.tenantId) throw Error("Dead-letter selection belongs to another workflow or tenant");
2194
2194
  if (n.deadLetteredAt !== void 0) return 0;
2195
2195
  c.push(n);
2196
2196
  }
2197
2197
  let l = c[0];
2198
2198
  if (l === void 0) return 0;
2199
- let u = await Promise.all(c.map((e) => pe(s, e.id)));
2199
+ let u = await Promise.all(c.map((e) => me(s, e.id)));
2200
2200
  if (u.some(Boolean) && !u.every(Boolean)) throw Error("Dead-lettered batch mixes failure delivery and ordinary callers; reconciliation required");
2201
2201
  let d = e.controls.get(l.workflowName);
2202
- await M(s, {
2202
+ await j(s, {
2203
2203
  id: o,
2204
2204
  sourceKind: "intent",
2205
2205
  sourceId: l.id,
@@ -2218,7 +2218,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2218
2218
  executionId: null
2219
2219
  }
2220
2220
  });
2221
- for (let e of c) if (await P(s, {
2221
+ for (let e of c) if (await N(s, {
2222
2222
  pendingId: e.id,
2223
2223
  workflowName: e.workflowName,
2224
2224
  tenantId: e.tenantId,
@@ -2228,16 +2228,16 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2228
2228
  failureId: o
2229
2229
  }
2230
2230
  }), !await oe(s, e, r, i)) throw Error("Dead-lettered queue row disappeared before marking");
2231
- return await O(s, o, i), c.length;
2231
+ return await fe(s, o, i), c.length;
2232
2232
  });
2233
- }, tr = async (e, t, n, r, i) => {
2234
- let a = `wff_${pt()}`;
2233
+ }, nr = async (e, t, n, r, i) => {
2234
+ let a = `wff_${ht()}`;
2235
2235
  return e.transaction(async (e) => {
2236
2236
  let o = [];
2237
2237
  for (let i of t) {
2238
2238
  let t = await e.query({
2239
- table: k,
2240
- predicate: V("id", i.id),
2239
+ table: O,
2240
+ predicate: B("id", i.id),
2241
2241
  order: [],
2242
2242
  take: 1,
2243
2243
  skip: void 0,
@@ -2245,18 +2245,18 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2245
2245
  lock: "update"
2246
2246
  });
2247
2247
  if (t[0] === void 0) return 0;
2248
- let a = F(t[0]);
2248
+ let a = P(t[0]);
2249
2249
  if (a.workflowName !== n.workflowName || a.tenantId !== i.tenantId) throw Error("Expired queue selection belongs to another workflow or tenant");
2250
2250
  if (a.mode !== i.mode || a.dueAt > r || a.deadLetteredAt !== void 0) return 0;
2251
2251
  o.push(a);
2252
2252
  }
2253
2253
  o.sort((e, t) => e.firstSeenAt - t.firstSeenAt || e.id.localeCompare(t.id));
2254
2254
  let s = o[0];
2255
- if (s === void 0 || !_e(n, s, r)) return 0;
2256
- let c = await Promise.all(o.map((t) => pe(e, t.id)));
2255
+ if (s === void 0 || !ve(n, s, r)) return 0;
2256
+ let c = await Promise.all(o.map((t) => me(e, t.id)));
2257
2257
  if (c.some(Boolean) && !c.every(Boolean)) throw Error("Expired batch mixes failure delivery and ordinary callers; reconciliation required");
2258
2258
  let l = `timeouts.start (${n.timeouts?.startMs}ms) elapsed while ${o.length} queued input(s) waited`;
2259
- await M(e, {
2259
+ await j(e, {
2260
2260
  id: a,
2261
2261
  sourceKind: "intent",
2262
2262
  sourceId: s.id,
@@ -2274,7 +2274,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2274
2274
  runId: null,
2275
2275
  executionId: null
2276
2276
  }
2277
- }), await j({
2277
+ }), await A({
2278
2278
  store: e,
2279
2279
  control: n,
2280
2280
  keys: D(n, E(e, s.workflowName, s.payload)),
@@ -2288,7 +2288,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2288
2288
  tenantId: s.tenantId,
2289
2289
  now: r
2290
2290
  });
2291
- for (let t of o) if (await P(e, {
2291
+ for (let t of o) if (await N(e, {
2292
2292
  pendingId: t.id,
2293
2293
  workflowName: t.workflowName,
2294
2294
  tenantId: t.tenantId,
@@ -2298,20 +2298,20 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2298
2298
  failureId: a
2299
2299
  }
2300
2300
  }), !await e.delete("_voltro_workflow_pending", t.id)) throw Error("Expired queue row disappeared before deletion");
2301
- return await O(e, a, r), o.length;
2301
+ return await fe(e, a, r), o.length;
2302
2302
  });
2303
- }, nr = async (e, t, n, r, i) => {
2303
+ }, rr = async (e, t, n, r, i) => {
2304
2304
  if (t = {
2305
2305
  ...t,
2306
2306
  payload: E(e.store, t.workflowName, t.payload)
2307
- }, t.mode === "delayed") return rr(e, t, n, r, i);
2307
+ }, t.mode === "delayed") return ir(e, t, n, r, i);
2308
2308
  let a = e.controls.get(t.workflowName);
2309
2309
  if (a === void 0) {
2310
- r.expired += await $n(e, [t], i);
2310
+ r.expired += await er(e, [t], i);
2311
2311
  return;
2312
2312
  }
2313
- if (_e(a, t, i)) {
2314
- r.expired += await tr(e, [t], a, i, !1);
2313
+ if (ve(a, t, i)) {
2314
+ r.expired += await nr(e, [t], a, i, !1);
2315
2315
  return;
2316
2316
  }
2317
2317
  let o = D(a, t.payload), s = await ce({
@@ -2322,7 +2322,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2322
2322
  now: i,
2323
2323
  reconsidering: !0
2324
2324
  });
2325
- await ar(e, {
2325
+ await or(e, {
2326
2326
  control: a,
2327
2327
  intent: t,
2328
2328
  decision: s,
@@ -2332,15 +2332,15 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2332
2332
  paused: n,
2333
2333
  items: void 0
2334
2334
  });
2335
- }, rr = async (e, t, n, r, i) => {
2335
+ }, ir = async (e, t, n, r, i) => {
2336
2336
  if (e.registeredWorkflows !== void 0 && !e.registeredWorkflows.has(t.workflowName)) {
2337
- r.expired += await $n(e, [t], i);
2337
+ r.expired += await er(e, [t], i);
2338
2338
  return;
2339
2339
  }
2340
- let a = e.controls.get(t.workflowName) ?? { workflowName: t.workflowName }, o = xe(), s = await e.transaction(async (e) => {
2340
+ let a = e.controls.get(t.workflowName) ?? { workflowName: t.workflowName }, o = Se(), s = await e.transaction(async (e) => {
2341
2341
  let r = await e.query({
2342
- table: k,
2343
- predicate: V("id", t.id),
2342
+ table: O,
2343
+ predicate: B("id", t.id),
2344
2344
  lock: "update",
2345
2345
  order: [],
2346
2346
  take: 1,
@@ -2348,10 +2348,10 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2348
2348
  projection: void 0
2349
2349
  });
2350
2350
  if (r[0] === void 0) return;
2351
- let s = F(r[0]);
2351
+ let s = P(r[0]);
2352
2352
  if (s.workflowName !== t.workflowName || s.tenantId !== t.tenantId) throw Error("Delayed arrival belongs to a different workflow or tenant");
2353
2353
  if (s.mode !== "delayed" || s.deadLetteredAt !== void 0 || s.dueAt > i) return;
2354
- let c = await un({
2354
+ let c = await dn({
2355
2355
  store: e,
2356
2356
  control: a,
2357
2357
  payload: E(e, s.workflowName, s.payload),
@@ -2361,7 +2361,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2361
2361
  now: i,
2362
2362
  waiting: !1
2363
2363
  });
2364
- if (c.kind === "queued" && (await qn(e, {
2364
+ if (c.kind === "queued" && (await Jn(e, {
2365
2365
  from: s.id,
2366
2366
  to: c.intentId,
2367
2367
  workflowName: s.workflowName,
@@ -2369,10 +2369,10 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2369
2369
  }), !await de(e, s.id))) throw Error("Delayed arrival disappeared during queue transfer");
2370
2370
  if (c.kind === "start") {
2371
2371
  if (c.ledgerId === void 0) throw Error("Delayed arrival has no admission reservation");
2372
- let t = a.batch === void 0 ? ve(e, s.workflowName, c.payload) : { items: z.decodeUnknownSync(z.Struct({ items: z.Array(z.Unknown) }))(c.payload).items.map((t) => ve(e, s.workflowName, t)) };
2372
+ let t = a.batch === void 0 ? ye(e, s.workflowName, c.payload) : { items: R.decodeUnknownSync(R.Struct({ items: R.Array(R.Unknown) }))(c.payload).items.map((t) => ye(e, s.workflowName, t)) };
2373
2373
  return {
2374
2374
  kind: "submission",
2375
- submission: await sn(e, {
2375
+ submission: await cn(e, {
2376
2376
  id: o,
2377
2377
  workflowName: s.workflowName,
2378
2378
  tenantId: s.tenantId,
@@ -2385,7 +2385,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2385
2385
  keys: c.keys
2386
2386
  };
2387
2387
  }
2388
- if ((c.kind === "dropped" || c.kind === "skipped") && (await P(e, {
2388
+ if ((c.kind === "dropped" || c.kind === "skipped") && (await N(e, {
2389
2389
  pendingId: s.id,
2390
2390
  workflowName: s.workflowName,
2391
2391
  tenantId: s.tenantId,
@@ -2409,9 +2409,9 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2409
2409
  r.skipped++;
2410
2410
  return;
2411
2411
  }
2412
- await sr(e, s.submission, a, r, i, a.batch !== void 0, s.keys);
2412
+ await cr(e, s.submission, a, r, i, a.batch !== void 0, s.keys);
2413
2413
  }
2414
- }, ir = async (e, t, n, r, i) => {
2414
+ }, ar = async (e, t, n, r, i) => {
2415
2415
  t = t.map((t) => ({
2416
2416
  ...t,
2417
2417
  payload: E(e.store, t.workflowName, t.payload)
@@ -2420,16 +2420,16 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2420
2420
  if (a === void 0) return;
2421
2421
  let o = e.controls.get(a.workflowName);
2422
2422
  if (o === void 0 || o.batch === void 0) {
2423
- r.expired += await $n(e, t, i);
2423
+ r.expired += await er(e, t, i);
2424
2424
  return;
2425
2425
  }
2426
2426
  let s = [...t].sort((e, t) => e.firstSeenAt - t.firstSeenAt), c = s[0];
2427
- if (_e(o, c, i)) {
2428
- r.expired += await tr(e, s, o, i, !0);
2427
+ if (ve(o, c, i)) {
2428
+ r.expired += await nr(e, s, o, i, !0);
2429
2429
  return;
2430
2430
  }
2431
2431
  let l = D(o, c.payload);
2432
- await ar(e, {
2432
+ await or(e, {
2433
2433
  control: o,
2434
2434
  intent: c,
2435
2435
  decision: await ce({
@@ -2446,7 +2446,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2446
2446
  paused: n,
2447
2447
  items: s
2448
2448
  });
2449
- }, ar = async (e, t) => {
2449
+ }, or = async (e, t) => {
2450
2450
  let { control: n, intent: r, decision: i, keys: a, counters: o, now: s, items: c, paused: l } = t;
2451
2451
  if (i.kind === "defer") {
2452
2452
  await ue({
@@ -2466,8 +2466,8 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2466
2466
  let t = [];
2467
2467
  for (let i of c ?? [r]) {
2468
2468
  let a = await e.query({
2469
- table: k,
2470
- predicate: V("id", i.id),
2469
+ table: O,
2470
+ predicate: B("id", i.id),
2471
2471
  lock: "update",
2472
2472
  order: [],
2473
2473
  take: 1,
@@ -2475,7 +2475,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2475
2475
  projection: void 0
2476
2476
  });
2477
2477
  if (a[0] === void 0) return;
2478
- let o = F(a[0]);
2478
+ let o = P(a[0]);
2479
2479
  if (o.workflowName !== n.workflowName || o.tenantId !== r.tenantId) throw Error("Terminal queue selection belongs to a different workflow or tenant");
2480
2480
  if (o.dueAt > s || o.deadLetteredAt !== void 0 || o.mode !== i.mode) return;
2481
2481
  t.push(o);
@@ -2485,7 +2485,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2485
2485
  store: e,
2486
2486
  control: n,
2487
2487
  keys: a,
2488
- paused: l.has(n.workflowName) || (await ye(e)).has(n.workflowName),
2488
+ paused: l.has(n.workflowName) || (await be(e)).has(n.workflowName),
2489
2489
  now: s,
2490
2490
  reconsidering: !0
2491
2491
  });
@@ -2500,7 +2500,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2500
2500
  executionId: o.incumbent.executionId,
2501
2501
  runId: o.incumbent.runId
2502
2502
  };
2503
- await j({
2503
+ await A({
2504
2504
  store: e,
2505
2505
  control: n,
2506
2506
  keys: a,
@@ -2514,7 +2514,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2514
2514
  tenantId: r.tenantId,
2515
2515
  now: s
2516
2516
  });
2517
- for (let n of t) if (await P(e, {
2517
+ for (let n of t) if (await N(e, {
2518
2518
  pendingId: n.id,
2519
2519
  workflowName: n.workflowName,
2520
2520
  tenantId: n.tenantId,
@@ -2525,7 +2525,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2525
2525
  t !== void 0 && o[t]++;
2526
2526
  return;
2527
2527
  }
2528
- let u = xe(), d = await e.transaction((t) => ln(t, {
2528
+ let u = Se(), d = await e.transaction((t) => un(t, {
2529
2529
  id: u,
2530
2530
  workflowName: n.workflowName,
2531
2531
  tenantId: r.tenantId,
@@ -2550,16 +2550,16 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2550
2550
  o.deferred++;
2551
2551
  return;
2552
2552
  }
2553
- await sr(e, d.submission, n, o, s, c !== void 0, a);
2553
+ await cr(e, d.submission, n, o, s, c !== void 0, a);
2554
2554
  }
2555
- }, or = async (e, t, n, r, i) => {
2556
- let a = await e.transaction((e) => N(e, t.id));
2555
+ }, sr = async (e, t, n, r, i) => {
2556
+ let a = await e.transaction((e) => M(e, t.id));
2557
2557
  if (a === void 0 || !a.receiptsBound || a.workflowName !== n.workflowName || a.workflowName !== t.workflowName || a.tenantId !== t.tenantId || a.ledgerId !== t.ledgerId) throw Error("Admission acceptance callback no longer has its resident submission owner");
2558
2558
  if (a.executionId !== null) {
2559
2559
  if (a.failureId !== null || a.executionId.length === 0 || a.executionId !== a.preparedExecutionId) throw Error("Admission acceptance has contradictory resident execution evidence");
2560
2560
  return a.executionId;
2561
2561
  }
2562
- await sr(e, a, n, {
2562
+ await cr(e, a, n, {
2563
2563
  admitted: 0,
2564
2564
  deferred: 0,
2565
2565
  dropped: 0,
@@ -2567,17 +2567,17 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2567
2567
  expired: 0,
2568
2568
  evicted: 0
2569
2569
  }, i, n.batch !== void 0, r);
2570
- let o = await e.transaction((e) => N(e, t.id));
2570
+ let o = await e.transaction((e) => M(e, t.id));
2571
2571
  if (o?.executionId == null || o.executionId !== o.preparedExecutionId) throw Error("Admission submission has no confirmed engine acceptance");
2572
2572
  return o.executionId;
2573
- }, sr = async (e, t, n, r, i, a, o) => {
2573
+ }, cr = async (e, t, n, r, i, a, o) => {
2574
2574
  let s = t.dispatchAttempts === 0 ? 0 : void 0;
2575
2575
  try {
2576
2576
  if (e.acquireSubmissionCapacity !== void 0 && !await e.acquireSubmissionCapacity(t)) {
2577
2577
  r.deferred++;
2578
2578
  return;
2579
2579
  }
2580
- let c = a ? { items: z.decodeUnknownSync(z.Struct({ items: z.Array(z.Unknown) }))(t.payload).items.map((t) => E(e.store, n.workflowName, t)) } : E(e.store, n.workflowName, t.payload), l = await zn(e, t, c), u = await e.transaction((e) => be(e, t.id, i));
2580
+ let c = a ? { items: R.decodeUnknownSync(R.Struct({ items: R.Array(R.Unknown) }))(t.payload).items.map((t) => E(e.store, n.workflowName, t)) } : E(e.store, n.workflowName, t.payload), l = await Bn(e, t, c), u = await e.transaction((e) => xe(e, t.id, i));
2581
2581
  if (u === null) return;
2582
2582
  s = u.dispatchAttempts === 1 ? 1 : void 0;
2583
2583
  let d = await e.startAdmitted(n.workflowName, c, t.callerContext, l);
@@ -2591,7 +2591,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2591
2591
  source: "flow-control",
2592
2592
  mode: "singleton"
2593
2593
  }
2594
- }), await x(e.store, t.eviction.executionId, i), await j({
2594
+ }), await x(e.store, t.eviction.executionId, i), await A({
2595
2595
  store: e.store,
2596
2596
  control: n,
2597
2597
  keys: o,
@@ -2604,7 +2604,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2604
2604
  runId: t.eviction.runId || null,
2605
2605
  tenantId: t.tenantId,
2606
2606
  now: i
2607
- }), r.evicted++), await e.transaction((e) => Ce(e, t.id, {
2607
+ }), r.evicted++), await e.transaction((e) => we(e, t.id, {
2608
2608
  executionId: d.executionId,
2609
2609
  runId: d.runId ?? null
2610
2610
  })), r.admitted++;
@@ -2620,7 +2620,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2620
2620
  })) !== void 0;
2621
2621
  }
2622
2622
  if (!a) {
2623
- let n = await e.transaction((n) => Be(n, t.id, String(r), i, e.deadLetterAfterAttempts ?? 50));
2623
+ let n = await e.transaction((n) => Ve(n, t.id, String(r), i, e.deadLetterAfterAttempts ?? 50));
2624
2624
  n.retry.stoppedAt !== null && e.log?.warn?.("workflow submission automatic retry stopped; engine acceptance unknown", {
2625
2625
  submissionId: t.id,
2626
2626
  workflow: t.workflowName,
@@ -2628,11 +2628,11 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2628
2628
  });
2629
2629
  }
2630
2630
  } catch (e) {
2631
- throw new Xn(t.id, AggregateError([r, e], "Submission and retry recording failed"));
2631
+ throw new Zn(t.id, AggregateError([r, e], "Submission and retry recording failed"));
2632
2632
  }
2633
- throw new Xn(t.id, r, a);
2633
+ throw new Zn(t.id, r, a);
2634
2634
  }
2635
- }, cr = async (e, t) => {
2635
+ }, lr = async (e, t) => {
2636
2636
  if (e.listRunningRuns === void 0) return { cancelled: 0 };
2637
2637
  let n = 0, r;
2638
2638
  for (let i of e.controls.values()) {
@@ -2654,7 +2654,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2654
2654
  executionId: o.executionId,
2655
2655
  reason: a,
2656
2656
  detail: {
2657
- ...Ie,
2657
+ ...Le,
2658
2658
  onFailure: i.onFailure ?? null
2659
2659
  }
2660
2660
  }) && (await x(e.store, o.executionId, t), n++);
@@ -2664,44 +2664,44 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2664
2664
  cancelled: n,
2665
2665
  ...r === void 0 ? {} : { nextDeadlineAt: r }
2666
2666
  };
2667
- }, lr = 3e5, ur, dr = (e) => {
2668
- ur = e !== void 0 && Number.isFinite(e) && e > 0 ? e : void 0;
2669
- }, fr = () => {
2667
+ }, ur = 3e5, dr, fr = (e) => {
2668
+ dr = e !== void 0 && Number.isFinite(e) && e > 0 ? e : void 0;
2669
+ }, pr = () => {
2670
2670
  let e = process.env.VOLTRO_WORKFLOW_SUSPEND_HINT_MS;
2671
2671
  if (e !== void 0) {
2672
2672
  let t = Number(e);
2673
2673
  if (Number.isFinite(t) && t > 0) return t;
2674
2674
  }
2675
- return ur ?? 3e5;
2676
- }, pr = /* @__PURE__ */ new Set(), mr = () => {
2677
- pr.clear();
2678
- }, hr = (e) => {
2679
- let t = fr();
2675
+ return dr ?? 3e5;
2676
+ }, mr = /* @__PURE__ */ new Set(), hr = () => {
2677
+ mr.clear();
2678
+ }, gr = (e) => {
2679
+ let t = pr();
2680
2680
  if (!(e.timeoutMs > t)) return !1;
2681
2681
  let n = `${e.workflowName ?? ""}\u0000${e.signalName}`;
2682
- if (pr.has(n)) return !1;
2683
- pr.add(n);
2682
+ if (mr.has(n)) return !1;
2683
+ mr.add(n);
2684
2684
  let r = e.workflowName === void 0 ? "" : ` in workflow '${e.workflowName}'`;
2685
2685
  return (e.warn ?? ((e) => console.warn(e)))(`awaitSignal('${e.signalName}')${r} declares a ${Math.round(e.timeoutMs / 1e3)}s timeout — a wait that long holds a worker fiber for its whole duration. For human-approval-length waits, awaitSignalSuspending (same call shape, from @voltro/workflow) SUSPENDS the run and frees the slot until the signal arrives. This is a hint, not a behaviour change; it is logged once per workflow. Threshold: workflows.suspendSignalHintMs in app.config.ts, or VOLTRO_WORKFLOW_SUSPEND_HINT_MS.`), !0;
2686
- }, gr = async (e, t) => {
2686
+ }, _r = async (e, t) => {
2687
2687
  if (e) try {
2688
2688
  await e.recordEvent(t);
2689
2689
  } catch {}
2690
- }, _r = (e, n) => {
2691
- let r = L.gen(function* () {
2692
- let r = n.pollIntervalMs ?? 200, i = n.maxPollIntervalMs ?? 5e3, a = n.timeoutMs ?? 864e5, s = yield* L.serviceOption(mt), c;
2693
- hr({
2690
+ }, vr = (e, n) => {
2691
+ let r = I.gen(function* () {
2692
+ let r = n.pollIntervalMs ?? 200, i = n.maxPollIntervalMs ?? 5e3, a = n.timeoutMs ?? 864e5, s = yield* I.serviceOption(Y), c;
2693
+ gr({
2694
2694
  workflowName: s._tag === "Some" ? s.value.workflow.name : void 0,
2695
2695
  signalName: n.name,
2696
2696
  timeoutMs: a,
2697
2697
  warn: (e) => {
2698
2698
  c = e;
2699
2699
  }
2700
- }), c !== void 0 && (yield* L.logWarning(c));
2701
- let l = yield* t, u = yield* L.serviceOption(o), d = u._tag === "Some" ? u.value : void 0;
2702
- if (l === void 0) return yield* L.die(/* @__PURE__ */ Error("awaitSignal: no active workflow run id in scope"));
2700
+ }), c !== void 0 && (yield* I.logWarning(c));
2701
+ let l = yield* t, u = yield* I.serviceOption(o), d = u._tag === "Some" ? u.value : void 0;
2702
+ if (l === void 0) return yield* I.die(/* @__PURE__ */ Error("awaitSignal: no active workflow run id in scope"));
2703
2703
  let f = l;
2704
- yield* L.promise(() => gr(d, {
2704
+ yield* I.promise(() => _r(d, {
2705
2705
  runId: f,
2706
2706
  eventType: "signal-awaited",
2707
2707
  payload: { signalName: n.name }
@@ -2709,24 +2709,24 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2709
2709
  let p = Date.now(), m = r;
2710
2710
  for (;;) {
2711
2711
  let t = Date.now() - p;
2712
- if (t > a) return yield* L.die(/* @__PURE__ */ Error(`awaitSignal('${n.name}') timed out after ${t}ms`));
2712
+ if (t > a) return yield* I.die(/* @__PURE__ */ Error(`awaitSignal('${n.name}') timed out after ${t}ms`));
2713
2713
  let r = {
2714
2714
  table: "_voltro_workflow_run_events",
2715
2715
  order: [{
2716
2716
  column: "occurredAt",
2717
2717
  direction: "asc"
2718
2718
  }],
2719
- predicate: B(V("runId", f), V("eventType", "signal-sent")),
2719
+ predicate: z(B("runId", f), B("eventType", "signal-sent")),
2720
2720
  projection: void 0,
2721
2721
  skip: void 0,
2722
2722
  take: 1e3
2723
- }, o = (yield* L.tryPromise({
2723
+ }, o = (yield* I.tryPromise({
2724
2724
  try: () => e.store.query(r),
2725
2725
  catch: (e) => e
2726
2726
  })).find((e) => e.payload?.signalName === n.name);
2727
2727
  if (o !== void 0) {
2728
- let e = h(o.payload)?.value, t = yield* z.decodeUnknown(n.schema)(e);
2729
- return yield* L.promise(() => gr(d, {
2728
+ let e = h(o.payload)?.value, t = yield* R.decodeUnknown(n.schema)(e);
2729
+ return yield* I.promise(() => _r(d, {
2730
2730
  runId: f,
2731
2731
  eventType: "signal-received",
2732
2732
  payload: {
@@ -2735,7 +2735,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2735
2735
  }
2736
2736
  })), t;
2737
2737
  }
2738
- yield* L.sleep(`${m} millis`), m = Math.min(m * 2, i);
2738
+ yield* I.sleep(`${m} millis`), m = Math.min(m * 2, i);
2739
2739
  }
2740
2740
  });
2741
2741
  return f({
@@ -2743,16 +2743,16 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2743
2743
  success: n.schema,
2744
2744
  execute: r
2745
2745
  });
2746
- }, vr = async (e, t) => {
2746
+ }, yr = async (e, t) => {
2747
2747
  if (e !== void 0) try {
2748
2748
  await e.recordEvent(t);
2749
2749
  } catch {}
2750
- }, yr = (e, n) => {
2751
- let r = L.gen(function* () {
2752
- let r = n.pollIntervalMs ?? 200, i = n.maxPollIntervalMs ?? 5e3, a = n.timeoutMs ?? 864e5, s = n.take ?? 500, c = yield* t, l = yield* L.serviceOption(o), u = l._tag === "Some" ? l.value : void 0;
2753
- if (c === void 0) return yield* L.die(/* @__PURE__ */ Error("awaitEvent: no active workflow run id in scope"));
2754
- let d = c, f = yield* n.since === "run-start" ? br(e, d) : L.succeed(/* @__PURE__ */ new Date());
2755
- yield* L.promise(() => vr(u, {
2750
+ }, br = (e, n) => {
2751
+ let r = I.gen(function* () {
2752
+ let r = n.pollIntervalMs ?? 200, i = n.maxPollIntervalMs ?? 5e3, a = n.timeoutMs ?? 864e5, s = n.take ?? 500, c = yield* t, l = yield* I.serviceOption(o), u = l._tag === "Some" ? l.value : void 0;
2753
+ if (c === void 0) return yield* I.die(/* @__PURE__ */ Error("awaitEvent: no active workflow run id in scope"));
2754
+ let d = c, f = yield* n.since === "run-start" ? xr(e, d) : I.succeed(/* @__PURE__ */ new Date());
2755
+ yield* I.promise(() => yr(u, {
2756
2756
  runId: d,
2757
2757
  eventType: "event-awaited",
2758
2758
  payload: {
@@ -2764,10 +2764,10 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2764
2764
  let p = Date.now(), m = r, h = 0;
2765
2765
  for (;;) {
2766
2766
  let t = Date.now() - p;
2767
- if (t > a) return yield* L.die(/* @__PURE__ */ Error(`awaitEvent('${n.event}') timed out after ${t}ms having examined ${h} candidate event(s). ${h === 0 ? "NONE were published under that name in the window — check the spelling against ctx.events.publish, and consider since: 'run-start' if the event may have arrived before this step began." : "The predicate rejected all of them — log one payload and compare it with what `match` expects."}`));
2767
+ if (t > a) return yield* I.die(/* @__PURE__ */ Error(`awaitEvent('${n.event}') timed out after ${t}ms having examined ${h} candidate event(s). ${h === 0 ? "NONE were published under that name in the window — check the spelling against ctx.events.publish, and consider since: 'run-start' if the event may have arrived before this step began." : "The predicate rejected all of them — log one payload and compare it with what `match` expects."}`));
2768
2768
  let r = {
2769
2769
  table: "_voltro_workflow_events",
2770
- predicate: B(V("name", n.event), nt("occurredAt", f)),
2770
+ predicate: z(B("name", n.event), it("occurredAt", f)),
2771
2771
  order: [{
2772
2772
  column: "occurredAt",
2773
2773
  direction: "asc"
@@ -2775,14 +2775,14 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2775
2775
  take: s,
2776
2776
  skip: void 0,
2777
2777
  projection: void 0
2778
- }, o = yield* L.tryPromise({
2778
+ }, o = yield* I.tryPromise({
2779
2779
  try: () => e.store.query(r),
2780
2780
  catch: (e) => e
2781
2781
  });
2782
2782
  h = o.length;
2783
2783
  for (let e of o) {
2784
- let t = yield* z.decodeUnknown(n.schema)(e.payload);
2785
- if (n.match(t)) return yield* L.promise(() => vr(u, {
2784
+ let t = yield* R.decodeUnknown(n.schema)(e.payload);
2785
+ if (n.match(t)) return yield* I.promise(() => yr(u, {
2786
2786
  runId: d,
2787
2787
  eventType: "event-received",
2788
2788
  payload: {
@@ -2791,7 +2791,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2791
2791
  }
2792
2792
  })), t;
2793
2793
  }
2794
- yield* L.sleep(`${m} millis`), m = Math.min(m * 2, i);
2794
+ yield* I.sleep(`${m} millis`), m = Math.min(m * 2, i);
2795
2795
  }
2796
2796
  });
2797
2797
  return f({
@@ -2799,11 +2799,11 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2799
2799
  success: n.schema,
2800
2800
  execute: r
2801
2801
  });
2802
- }, br = (e, t) => L.gen(function* () {
2803
- let n = (yield* L.tryPromise({
2802
+ }, xr = (e, t) => I.gen(function* () {
2803
+ let n = (yield* I.tryPromise({
2804
2804
  try: () => e.store.query({
2805
2805
  table: "_voltro_workflow_runs",
2806
- predicate: V("id", t),
2806
+ predicate: B("id", t),
2807
2807
  order: [],
2808
2808
  take: 1,
2809
2809
  skip: void 0,
@@ -2817,16 +2817,20 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2817
2817
  if (!Number.isNaN(e.getTime())) return e;
2818
2818
  }
2819
2819
  return /* @__PURE__ */ new Date(0);
2820
- }), xr = (e) => new Promise((t) => setTimeout(t, e)), Sr = () => {
2820
+ }), Sr = class extends Je.Reference()("@voltro/workflow/SuspensionUnavailable", { defaultValue: () => void 0 }) {}, Cr = class extends Error {
2821
+ constructor(e, t) {
2822
+ super(`${e} cannot wait for a durable result here: ${t}`), this.name = "WorkflowCannotPark";
2823
+ }
2824
+ }, wr = (e) => new Promise((t) => setTimeout(t, e)), Tr = () => {
2821
2825
  let e = globalThis.crypto;
2822
2826
  return typeof e?.randomUUID == "function" ? e.randomUUID() : `${Date.now().toString(36)}${Math.random().toString(36).slice(2)}`;
2823
- }, Cr = () => `wfu_${Sr()}`, wr = async (e, t) => {
2827
+ }, Er = () => `wfu_${Tr()}`, Dr = async (e, t) => {
2824
2828
  let n = t.id ?? t.executionId;
2825
2829
  if (!n) throw Error("workflow message target requires target.id or target.executionId");
2826
2830
  let r = await e.query({
2827
2831
  table: "_voltro_workflow_runs",
2828
2832
  order: [],
2829
- predicate: V("id", n),
2833
+ predicate: B("id", n),
2830
2834
  projection: void 0,
2831
2835
  skip: void 0,
2832
2836
  take: 1
@@ -2835,14 +2839,14 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2835
2839
  let i = (await e.query({
2836
2840
  table: "_voltro_workflow_runs",
2837
2841
  order: [],
2838
- predicate: V("executionId", n),
2842
+ predicate: B("executionId", n),
2839
2843
  projection: void 0,
2840
2844
  skip: void 0,
2841
2845
  take: 1
2842
2846
  }))[0];
2843
2847
  if (!i) throw Error(`workflow message target not found: ${n}`);
2844
2848
  return i;
2845
- }, Tr = class extends Error {
2849
+ }, Or = class extends Error {
2846
2850
  runId;
2847
2851
  eventType;
2848
2852
  eventId;
@@ -2850,8 +2854,8 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2850
2854
  constructor(e, t, n) {
2851
2855
  super(`workflow ${t} for run ${e} was NOT recorded (event ${n}): the run will not see it — the store refused the row, see the recorder's warning`), this.runId = e, this.eventType = t, this.eventId = n, this.name = "WorkflowMessageNotRecorded";
2852
2856
  }
2853
- }, Er = async (e) => {
2854
- let t = await wr(e.store, e.target), n = await e.recorder.recordEvent({
2857
+ }, kr = async (e) => {
2858
+ let t = await Dr(e.store, e.target), n = await e.recorder.recordEvent({
2855
2859
  runId: t.id,
2856
2860
  eventType: "signal-sent",
2857
2861
  payload: {
@@ -2859,10 +2863,10 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2859
2863
  value: e.payload
2860
2864
  }
2861
2865
  });
2862
- if (n.recorded === !1) throw new Tr(t.id, "signal-sent", n.id);
2866
+ if (n.recorded === !1) throw new Or(t.id, "signal-sent", n.id);
2863
2867
  return { eventId: n.id };
2864
- }, Dr = async (e) => {
2865
- let t = await wr(e.store, e.target), n = Cr(), r = await e.recorder.recordEvent({
2868
+ }, Ar = async (e) => {
2869
+ let t = await Dr(e.store, e.target), n = Er(), r = await e.recorder.recordEvent({
2866
2870
  runId: t.id,
2867
2871
  eventType: "update-requested",
2868
2872
  payload: {
@@ -2871,7 +2875,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2871
2875
  value: e.payload
2872
2876
  }
2873
2877
  });
2874
- if (r.recorded === !1) throw new Tr(t.id, "update-requested", r.id);
2878
+ if (r.recorded === !1) throw new Or(t.id, "update-requested", r.id);
2875
2879
  let i = Date.now(), a = e.options?.timeoutMs ?? 3e4, o = e.options?.pollIntervalMs ?? 100;
2876
2880
  for (;;) {
2877
2881
  let s = {
@@ -2880,7 +2884,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2880
2884
  column: "occurredAt",
2881
2885
  direction: "asc"
2882
2886
  }],
2883
- predicate: V("runId", t.id),
2887
+ predicate: B("runId", t.id),
2884
2888
  projection: void 0,
2885
2889
  skip: void 0,
2886
2890
  take: 1e3
@@ -2901,100 +2905,102 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
2901
2905
  }), t;
2902
2906
  }
2903
2907
  if (Date.now() - i >= a) throw Error(`Timed out waiting for workflow update '${e.updateName}' (${n})`);
2904
- await xr(o);
2908
+ await wr(o);
2905
2909
  }
2906
- }, Or = 864e5, kr = "voltro/suspending-signal", Ar = (e, t) => `${kr}/${e}/${t}`, jr = (e, t) => We.make(e, { success: _(t) ? u(z.Unknown, `signal '${e}' value`) : z.Unknown }), Mr = async (e, t) => {
2910
+ }, jr = 864e5, Mr = "voltro/suspending-signal", Nr = (e, t) => `${Mr}/${e}/${t}`, Pr = (e, t) => Ge.make(e, { success: _(t) ? u(R.Unknown, `signal '${e}' value`) : R.Unknown }), Fr = async (e, t) => {
2907
2911
  if (e) try {
2908
2912
  await e.recordEvent(t);
2909
2913
  } catch {}
2910
- }, Nr = (e, n) => L.gen(function* () {
2911
- let e = n.timeoutMs ?? Or, r = yield* Ke.WorkflowInstance, i = jr(Ar(r.workflow.name, n.name), r.workflow.name), a = yield* t, s = yield* L.serviceOption(o), c = s._tag === "Some" ? s.value : void 0;
2912
- a !== void 0 && (yield* L.promise(() => Mr(c, {
2913
- runId: a,
2914
+ }, Ir = (e, n) => I.gen(function* () {
2915
+ let e = yield* Sr;
2916
+ if (e !== void 0) return yield* I.die(new Cr(`awaitSignalSuspending('${n.name}')`, e));
2917
+ let r = n.timeoutMs ?? jr, i = yield* qe.WorkflowInstance, a = Pr(Nr(i.workflow.name, n.name), i.workflow.name), s = yield* t, c = yield* I.serviceOption(o), l = c._tag === "Some" ? c.value : void 0;
2918
+ s !== void 0 && (yield* I.promise(() => Fr(l, {
2919
+ runId: s,
2914
2920
  eventType: "signal-awaited",
2915
2921
  payload: { signalName: n.name }
2916
2922
  })));
2917
- let l = We.await(i), u = Number.isFinite(e) ? yield* L.race(l, Ue.sleep({
2923
+ let u = Ge.await(a), d = Number.isFinite(r) ? yield* I.race(u, We.sleep({
2918
2924
  name: `await-signal-timeout/${n.name}`,
2919
2925
  inMemoryThreshold: "0 millis",
2920
- duration: `${e} millis`
2921
- }).pipe(L.andThen(L.die(/* @__PURE__ */ Error(`awaitSignalSuspending('${n.name}') timed out after ${e}ms`))))).pipe(L.catchAllCause((e) => r.suspended ? I.isInterruptedOnly(e) ? Ge.suspend(r) : L.failCause(I.filter(e, (e) => !I.isInterruptType(e))) : L.failCause(e))) : yield* l, d = yield* z.decodeUnknown(n.schema)(u);
2922
- return a !== void 0 && (yield* L.promise(() => Mr(c, {
2923
- runId: a,
2926
+ duration: `${r} millis`
2927
+ }).pipe(I.andThen(I.die(/* @__PURE__ */ Error(`awaitSignalSuspending('${n.name}') timed out after ${r}ms`))))).pipe(I.catchAllCause((e) => i.suspended ? F.isInterruptedOnly(e) ? Ke.suspend(i) : I.failCause(F.filter(e, (e) => !F.isInterruptType(e))) : I.failCause(e))) : yield* u, f = yield* R.decodeUnknown(n.schema)(d);
2928
+ return s !== void 0 && (yield* I.promise(() => Fr(l, {
2929
+ runId: s,
2924
2930
  eventType: "signal-received",
2925
2931
  payload: {
2926
2932
  signalName: n.name,
2927
- value: d
2933
+ value: f
2928
2934
  }
2929
- }))), d;
2930
- }), Pr = (e) => L.gen(function* () {
2935
+ }))), f;
2936
+ }), Lr = (e) => I.gen(function* () {
2931
2937
  let t = e.target.executionId, n = e.target.workflowName;
2932
2938
  if (t === void 0 || n === void 0) {
2933
2939
  let r = e.store;
2934
- if (r === void 0) return yield* L.die(/* @__PURE__ */ Error("completeSuspendingSignal: provide a store, or target.executionId AND target.workflowName"));
2935
- let i = yield* L.tryPromise({
2936
- try: () => wr(r, e.target),
2940
+ if (r === void 0) return yield* I.die(/* @__PURE__ */ Error("completeSuspendingSignal: provide a store, or target.executionId AND target.workflowName"));
2941
+ let i = yield* I.tryPromise({
2942
+ try: () => Dr(r, e.target),
2937
2943
  catch: (e) => e
2938
2944
  });
2939
2945
  t ??= i.executionId, n ??= i.tag;
2940
2946
  }
2941
2947
  if (t === void 0 || n === void 0) return { completed: !1 };
2942
- let r = Ar(n, e.signalName), i = jr(r, n), a = new We.TokenParsed({
2948
+ let r = Nr(n, e.signalName), i = Pr(r, n), a = new Ge.TokenParsed({
2943
2949
  workflowName: n,
2944
2950
  executionId: t,
2945
2951
  deferredName: r
2946
2952
  }).asToken;
2947
- return yield* We.done(i, {
2953
+ return yield* Ge.done(i, {
2948
2954
  token: a,
2949
- exit: qe.succeed(e.payload)
2955
+ exit: Ye.succeed(e.payload)
2950
2956
  }), { completed: !0 };
2951
- }), Z = "_voltro_budget_holds", Fr = "budget-hold", Ir = (e) => `${Fr}:${e}`, Lr = (e) => `${e.executionId}/${e.stepName}/${e.budget}#${e.generation}`, Rr = async (e, t) => (await e.query({
2957
+ }), Z = "_voltro_budget_holds", Rr = "budget-hold", zr = (e) => `${Rr}:${e}`, Br = (e) => `${e.executionId}/${e.stepName}/${e.budget}#${e.generation}`, Vr = async (e, t) => (await e.query({
2952
2958
  table: Z,
2953
- predicate: B(V("executionId", t.executionId), V("stepName", t.stepName), V("budget", t.budget)),
2959
+ predicate: z(B("executionId", t.executionId), B("stepName", t.stepName), B("budget", t.budget)),
2954
2960
  order: []
2955
- })).length, zr = q(Z, {
2956
- id: U({ prefix: "bhd" }),
2957
- holdKey: J().maxLength(191).unique(),
2958
- budget: J(),
2959
- tenantId: J().nullable(),
2960
- executionId: J(),
2961
- workflowName: J(),
2962
- signalName: J(),
2963
- stepName: J(),
2964
- spentMicroUsd: J().nullable(),
2965
- limitMicroUsd: J().nullable(),
2966
- heldAt: Y().default("now"),
2967
- releasedAt: Y().nullable(),
2968
- outcome: J().nullable()
2969
- }).index(["budget", "releasedAt"]), Br = () => {
2970
- ut({
2961
+ })).length, Hr = K(Z, {
2962
+ id: H({ prefix: "bhd" }),
2963
+ holdKey: q().maxLength(191).unique(),
2964
+ budget: q(),
2965
+ tenantId: q().nullable(),
2966
+ executionId: q(),
2967
+ workflowName: q(),
2968
+ signalName: q(),
2969
+ stepName: q(),
2970
+ spentMicroUsd: q().nullable(),
2971
+ limitMicroUsd: q().nullable(),
2972
+ heldAt: J().default("now"),
2973
+ releasedAt: J().nullable(),
2974
+ outcome: q().nullable()
2975
+ }).index(["budget", "releasedAt"]), Ur = () => {
2976
+ ft({
2971
2977
  source: "framework",
2972
2978
  table: Z,
2973
2979
  timeColumn: "releasedAt",
2974
- ttlMs: dt(process.env.VOLTRO_BUDGET_HOLDS_TTL_HOURS, 720)
2980
+ ttlMs: pt(process.env.VOLTRO_BUDGET_HOLDS_TTL_HOURS, 720)
2975
2981
  });
2976
- }, Vr = class extends Error {
2982
+ }, Wr = class extends Error {
2977
2983
  budget;
2978
2984
  holdKey;
2979
2985
  constructor(e, t, n) {
2980
2986
  super(`budget '${e}': the run was suspended waiting for headroom and gave up after ${n}ms (hold ${t}). Nothing was spent. Raise the budget, reset its window, or lift the hold, then re-drive the run.`), this.name = "BudgetHoldExpired", this.budget = e, this.holdKey = t;
2981
2987
  }
2982
- }, Hr = 6048e5, Ur = (e) => L.gen(function* () {
2983
- Br();
2988
+ }, Gr = 6048e5, Kr = (e) => I.gen(function* () {
2989
+ Ur();
2984
2990
  let t = e.timeoutMs ?? 6048e5, n = e.recheckEveryMs ?? 9e5, r = {
2985
2991
  executionId: e.executionId,
2986
2992
  stepName: e.stepName,
2987
2993
  budget: e.budget
2988
2994
  };
2989
2995
  for (let i = 0;; i++) {
2990
- let a = yield* L.promise(() => Gr(e.store, r)), o = a.length === 0 ? Date.now() : Wr(a[0]?.heldAt), s = Number.isFinite(t) ? t - (Date.now() - o) : Infinity, c = Lr({
2996
+ let a = yield* I.promise(() => Jr(e.store, r)), o = a.length === 0 ? Date.now() : qr(a[0]?.heldAt), s = Number.isFinite(t) ? t - (Date.now() - o) : Infinity, c = Br({
2991
2997
  ...r,
2992
2998
  generation: i
2993
2999
  });
2994
- if (s <= 0) return yield* L.promise(() => Kr(e.store, r, "expired")), yield* L.fail(new Vr(e.budget, c, t));
2995
- let l = Ir(c);
2996
- yield* L.promise(() => e.store.insertIgnore(Z, {
2997
- id: tt({
3000
+ if (s <= 0) return yield* I.promise(() => Yr(e.store, r, "expired")), yield* I.fail(new Wr(e.budget, c, t));
3001
+ let l = zr(c);
3002
+ yield* I.promise(() => e.store.insertIgnore(Z, {
3003
+ id: rt({
2998
3004
  kind: "typeid",
2999
3005
  prefix: "bhd"
3000
3006
  }, Z),
@@ -3012,34 +3018,34 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
3012
3018
  outcome: null
3013
3019
  }, { conflictColumns: ["holdKey"] }));
3014
3020
  let u = Math.min(n, s);
3015
- if (yield* Nr({ store: e.store }, {
3021
+ if (yield* Ir({ store: e.store }, {
3016
3022
  name: l,
3017
- schema: z.Unknown,
3023
+ schema: R.Unknown,
3018
3024
  timeoutMs: u
3019
- }).pipe(L.catchAllCause((e) => I.isInterruptedOnly(e) ? L.failCause(e) : L.void)), yield* L.promise(() => e.store.updateMany(Z, {
3025
+ }).pipe(I.catchAllCause((e) => F.isInterruptedOnly(e) ? I.failCause(e) : I.void)), yield* I.promise(() => e.store.updateMany(Z, {
3020
3026
  releasedAt: /* @__PURE__ */ new Date(),
3021
3027
  outcome: "recheck"
3022
- }, { where: B(V("holdKey", c), G("releasedAt")) })), yield* e.hasHeadroom) return;
3028
+ }, { where: z(B("holdKey", c), W("releasedAt")) })), yield* e.hasHeadroom) return;
3023
3029
  }
3024
- }), Wr = (e) => e instanceof Date ? e.getTime() : typeof e == "string" ? Date.parse(e) : Date.now(), Gr = async (e, t) => [...await e.query({
3030
+ }), qr = (e) => e instanceof Date ? e.getTime() : typeof e == "string" ? Date.parse(e) : Date.now(), Jr = async (e, t) => [...await e.query({
3025
3031
  table: Z,
3026
- predicate: B(V("executionId", t.executionId), V("stepName", t.stepName), V("budget", t.budget)),
3032
+ predicate: z(B("executionId", t.executionId), B("stepName", t.stepName), B("budget", t.budget)),
3027
3033
  order: []
3028
- })].sort((e, t) => String(e.id).localeCompare(String(t.id))), Kr = async (e, t, n) => {
3034
+ })].sort((e, t) => String(e.id).localeCompare(String(t.id))), Yr = async (e, t, n) => {
3029
3035
  await e.updateMany(Z, {
3030
3036
  releasedAt: /* @__PURE__ */ new Date(),
3031
3037
  outcome: n
3032
- }, { where: B(V("executionId", t.executionId), V("stepName", t.stepName), V("budget", t.budget), G("releasedAt")) });
3033
- }, qr = (e) => L.gen(function* () {
3034
- let t = e.tenantId === void 0 ? B(V("budget", e.budget), G("releasedAt")) : B(V("budget", e.budget), V("tenantId", e.tenantId), G("releasedAt")), n = yield* L.promise(() => e.store.query({
3038
+ }, { where: z(B("executionId", t.executionId), B("stepName", t.stepName), B("budget", t.budget), W("releasedAt")) });
3039
+ }, Xr = (e) => I.gen(function* () {
3040
+ let t = e.tenantId === void 0 ? z(B("budget", e.budget), W("releasedAt")) : z(B("budget", e.budget), B("tenantId", e.tenantId), W("releasedAt")), n = yield* I.promise(() => e.store.query({
3035
3041
  table: Z,
3036
3042
  predicate: t,
3037
3043
  order: []
3038
3044
  })), r = 0;
3039
- for (let t of n) (yield* L.promise(() => e.store.updateMany("_voltro_budget_holds", {
3045
+ for (let t of n) (yield* I.promise(() => e.store.updateMany("_voltro_budget_holds", {
3040
3046
  releasedAt: /* @__PURE__ */ new Date(),
3041
3047
  outcome: e.outcome ?? "released"
3042
- }, { where: B(V("id", String(t.id)), G("releasedAt")) }))) === 1 && (yield* Pr({
3048
+ }, { where: z(B("id", String(t.id)), W("releasedAt")) }))) === 1 && (yield* Lr({
3043
3049
  target: {
3044
3050
  executionId: String(t.executionId),
3045
3051
  workflowName: String(t.workflowName)
@@ -3049,10 +3055,10 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
3049
3055
  released: !0,
3050
3056
  budget: e.budget
3051
3057
  }
3052
- }).pipe(L.catchAll(() => L.succeed({ completed: !1 }))), r += 1);
3058
+ }).pipe(I.catchAll(() => I.succeed({ completed: !1 }))), r += 1);
3053
3059
  return { released: r };
3054
- }), Jr = async (e, t) => {
3055
- let n = t?.budget === void 0 ? G("releasedAt") : B(V("budget", t.budget), G("releasedAt"));
3060
+ }), Zr = async (e, t) => {
3061
+ let n = t?.budget === void 0 ? W("releasedAt") : z(B("budget", t.budget), W("releasedAt"));
3056
3062
  return (await e.query({
3057
3063
  table: Z,
3058
3064
  predicate: n,
@@ -3067,8 +3073,8 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
3067
3073
  stepName: String(e.stepName),
3068
3074
  heldAt: e.heldAt instanceof Date ? e.heldAt.toISOString() : String(e.heldAt ?? "")
3069
3075
  }));
3070
- }, Yr = async (e) => {
3071
- let t = await Jr(e), n = /* @__PURE__ */ new Map();
3076
+ }, Qr = async (e) => {
3077
+ let t = await Zr(e), n = /* @__PURE__ */ new Map();
3072
3078
  for (let e of t) {
3073
3079
  let t = `${e.budget}\u0000${e.tenantId ?? ""}`;
3074
3080
  n.has(t) || n.set(t, {
@@ -3077,41 +3083,41 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
3077
3083
  });
3078
3084
  }
3079
3085
  return [...n.values()];
3080
- }, Xr = async (e, t) => {
3086
+ }, $r = async (e, t) => {
3081
3087
  if (e) try {
3082
3088
  await e.recordEvent(t);
3083
3089
  } catch {}
3084
- }, Zr = (e) => {
3085
- let t = I.failureOption(e), n = Array.from(I.defects(e)), r = t._tag === "Some" ? t.value : n[0] ?? I.squash(e);
3090
+ }, ei = (e) => {
3091
+ let t = F.failureOption(e), n = Array.from(F.defects(e)), r = t._tag === "Some" ? t.value : n[0] ?? F.squash(e);
3086
3092
  return {
3087
3093
  errorTag: r && typeof r == "object" && "_tag" in r ? String(r._tag) : null,
3088
3094
  errorMessage: r?.message ?? String(r)
3089
3095
  };
3090
- }, Qr = (e, n) => {
3091
- let r = L.gen(function* () {
3092
- let r = n.pollIntervalMs ?? 200, i = n.maxPollIntervalMs ?? 5e3, a = n.timeoutMs ?? 3e4, s = yield* t, c = yield* L.serviceOption(o), l = c._tag === "Some" ? c.value : void 0;
3093
- if (s === void 0) return yield* L.die(/* @__PURE__ */ Error("awaitUpdate: no active workflow run id in scope"));
3096
+ }, ti = (e, n) => {
3097
+ let r = I.gen(function* () {
3098
+ let r = n.pollIntervalMs ?? 200, i = n.maxPollIntervalMs ?? 5e3, a = n.timeoutMs ?? 3e4, s = yield* t, c = yield* I.serviceOption(o), l = c._tag === "Some" ? c.value : void 0;
3099
+ if (s === void 0) return yield* I.die(/* @__PURE__ */ Error("awaitUpdate: no active workflow run id in scope"));
3094
3100
  let u = s, d = Date.now(), f = r;
3095
3101
  for (;;) {
3096
3102
  let t = Date.now() - d;
3097
- if (t > a) return yield* L.die(/* @__PURE__ */ Error(`awaitUpdate('${n.name}') timed out after ${t}ms`));
3103
+ if (t > a) return yield* I.die(/* @__PURE__ */ Error(`awaitUpdate('${n.name}') timed out after ${t}ms`));
3098
3104
  let r = {
3099
3105
  table: "_voltro_workflow_run_events",
3100
3106
  order: [{
3101
3107
  column: "occurredAt",
3102
3108
  direction: "asc"
3103
3109
  }],
3104
- predicate: V("runId", u),
3110
+ predicate: B("runId", u),
3105
3111
  projection: void 0,
3106
3112
  skip: void 0,
3107
3113
  take: 1e3
3108
- }, o = yield* L.tryPromise({
3114
+ }, o = yield* I.tryPromise({
3109
3115
  try: () => e.store.query(r),
3110
3116
  catch: (e) => e
3111
3117
  }), s = new Set(o.filter((e) => e.eventType === "update-completed" || e.eventType === "update-failed").map((e) => e.payload?.updateId).filter((e) => typeof e == "string" && e.length > 0)), c = o.find((e) => e.eventType === "update-requested" && e.payload?.updateName === n.name && typeof e.payload.updateId == "string" && !s.has(e.payload.updateId));
3112
3118
  if (c !== void 0) {
3113
3119
  let e = c.payload.updateId;
3114
- yield* L.promise(() => Xr(l, {
3120
+ yield* I.promise(() => $r(l, {
3115
3121
  runId: u,
3116
3122
  eventType: "update-received",
3117
3123
  payload: {
@@ -3119,24 +3125,24 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
3119
3125
  updateName: n.name
3120
3126
  }
3121
3127
  }));
3122
- let t = yield* z.decodeUnknown(n.schema)(h(c.payload)?.value).pipe(L.tapErrorCause((t) => L.promise(() => Xr(l, {
3128
+ let t = yield* R.decodeUnknown(n.schema)(h(c.payload)?.value).pipe(I.tapErrorCause((t) => I.promise(() => $r(l, {
3123
3129
  runId: u,
3124
3130
  eventType: "update-failed",
3125
3131
  payload: {
3126
3132
  updateId: e,
3127
3133
  updateName: n.name,
3128
- ...Zr(t)
3134
+ ...ei(t)
3129
3135
  }
3130
- })))), r = yield* (n.handle ? n.handle(t) : L.succeed(t)).pipe(L.flatMap((e) => n.success ? z.decodeUnknown(n.success)(e) : L.succeed(e))).pipe(L.tapErrorCause((t) => L.promise(() => Xr(l, {
3136
+ })))), r = yield* (n.handle ? n.handle(t) : I.succeed(t)).pipe(I.flatMap((e) => n.success ? R.decodeUnknown(n.success)(e) : I.succeed(e))).pipe(I.tapErrorCause((t) => I.promise(() => $r(l, {
3131
3137
  runId: u,
3132
3138
  eventType: "update-failed",
3133
3139
  payload: {
3134
3140
  updateId: e,
3135
3141
  updateName: n.name,
3136
- ...Zr(t)
3142
+ ...ei(t)
3137
3143
  }
3138
3144
  }))));
3139
- return yield* L.promise(() => Xr(l, {
3145
+ return yield* I.promise(() => $r(l, {
3140
3146
  runId: u,
3141
3147
  eventType: "update-completed",
3142
3148
  payload: {
@@ -3146,7 +3152,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
3146
3152
  }
3147
3153
  })), r;
3148
3154
  }
3149
- yield* L.sleep(`${f} millis`), f = Math.min(f * 2, i);
3155
+ yield* I.sleep(`${f} millis`), f = Math.min(f * 2, i);
3150
3156
  }
3151
3157
  });
3152
3158
  return f({
@@ -3154,7 +3160,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
3154
3160
  success: n.success ?? n.schema,
3155
3161
  execute: r
3156
3162
  });
3157
- }, $r = (e) => {
3163
+ }, ni = (e) => {
3158
3164
  if (e == null) return null;
3159
3165
  if (e instanceof Date) return e;
3160
3166
  if (typeof e == "string" || typeof e == "number") {
@@ -3162,7 +3168,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
3162
3168
  return Number.isNaN(t.getTime()) ? null : t;
3163
3169
  }
3164
3170
  return null;
3165
- }, ei = (e) => typeof e == "number" ? e : e == null ? null : Number(e), Q = (e) => e == null ? null : String(e), ti = (e) => {
3171
+ }, ri = (e) => typeof e == "number" ? e : e == null ? null : Number(e), Q = (e) => e == null ? null : String(e), ii = (e) => {
3166
3172
  let t = /* @__PURE__ */ new Map();
3167
3173
  for (let n of e) {
3168
3174
  let e = String(n.stepName), r = t.get(e);
@@ -3170,27 +3176,27 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
3170
3176
  }
3171
3177
  let n = [];
3172
3178
  for (let [e, r] of t) {
3173
- r.sort((e, t) => (ei(e.attempt) ?? 0) - (ei(t.attempt) ?? 0));
3179
+ r.sort((e, t) => (ri(e.attempt) ?? 0) - (ri(t.attempt) ?? 0));
3174
3180
  let t = r[r.length - 1], i = Q(t.errorTag), a = Q(t.errorMessage), o = i !== null || a !== null ? {
3175
3181
  tag: i,
3176
3182
  message: a ?? ""
3177
3183
  } : null;
3178
3184
  n.push({
3179
3185
  name: e,
3180
- attempt: ei(t.attempt) ?? r.length,
3186
+ attempt: ri(t.attempt) ?? r.length,
3181
3187
  attempts: r.length,
3182
3188
  status: t.status ?? "running",
3183
3189
  input: t.input ?? null,
3184
3190
  output: t.output ?? null,
3185
3191
  error: o,
3186
- durationMs: ei(t.durationMs)
3192
+ durationMs: ri(t.durationMs)
3187
3193
  });
3188
3194
  }
3189
3195
  return n.sort((t, n) => {
3190
3196
  let r = e.find((e) => String(e.stepName) === t.name), i = e.find((e) => String(e.stepName) === n.name);
3191
- return ($r(r?.startedAt)?.getTime() ?? 0) - ($r(i?.startedAt)?.getTime() ?? 0);
3197
+ return (ni(r?.startedAt)?.getTime() ?? 0) - (ni(i?.startedAt)?.getTime() ?? 0);
3192
3198
  }), n;
3193
- }, ni = (e) => {
3199
+ }, ai = (e) => {
3194
3200
  if (e == null) return null;
3195
3201
  if (typeof e == "string") try {
3196
3202
  return JSON.parse(e);
@@ -3198,10 +3204,10 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
3198
3204
  return null;
3199
3205
  }
3200
3206
  return typeof e == "object" ? e : null;
3201
- }, ri = async (e, t) => {
3202
- let n = st(gt), r = (await t.query(n.where(ot(V("id", e), V("executionId", e))).limit(1).descriptor))[0];
3207
+ }, oi = async (e, t) => {
3208
+ let n = lt(_t), r = (await t.query(n.where(ct(B("id", e), B("executionId", e))).limit(1).descriptor))[0];
3203
3209
  if (r === void 0) return null;
3204
- let i = String(r.id), a = st(_t), o = await t.query(a.where(V("runId", i)).descriptor);
3210
+ let i = String(r.id), a = lt(vt), o = await t.query(a.where(B("runId", i)).descriptor);
3205
3211
  return {
3206
3212
  id: i,
3207
3213
  executionId: Q(r.executionId) ?? "",
@@ -3209,19 +3215,19 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
3209
3215
  status: r.status ?? "running",
3210
3216
  input: d(r.payload ?? null, "workflow run payload"),
3211
3217
  output: m(r.output ?? null, "workflow run result"),
3212
- subject: ni(r.subject),
3218
+ subject: ai(r.subject),
3213
3219
  source: Q(r.source),
3214
- steps: ti(o),
3215
- startedAt: $r(r.startedAt) ?? /* @__PURE__ */ new Date(0),
3216
- finishedAt: $r(r.completedAt),
3220
+ steps: ii(o),
3221
+ startedAt: ni(r.startedAt) ?? /* @__PURE__ */ new Date(0),
3222
+ finishedAt: ni(r.completedAt),
3217
3223
  traceId: Q(r.traceId),
3218
3224
  parentExecutionId: Q(r.parentExecutionId),
3219
3225
  parentClosePolicy: Q(r.parentClosePolicy)
3220
3226
  };
3221
- }, ii = () => {
3227
+ }, si = () => {
3222
3228
  let e = [], t = [], n = 0, r = 0;
3223
3229
  return {
3224
- layer: Xe.succeed(o, {
3230
+ layer: Qe.succeed(o, {
3225
3231
  startStep: async ({ runId: t, stepName: r, attempt: i, stepInput: a, retryPolicy: o }) => {
3226
3232
  let s = `wfstep_mem_${++n}`;
3227
3233
  return e.push({
@@ -3268,13 +3274,13 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
3268
3274
  readSteps: () => e,
3269
3275
  readEvents: () => t
3270
3276
  };
3271
- }, ai = (e, t, n) => L.gen(function* () {
3272
- let r = yield* mt;
3277
+ }, ci = (e, t, n) => I.gen(function* () {
3278
+ let r = yield* Y;
3273
3279
  for (;;) {
3274
- if (yield* L.tryPromise(() => he(t, e)).pipe(L.catchAll(() => L.sync(() => (n(), !1))))) return r.interrupted = !0, yield* L.interrupt;
3275
- yield* L.sleep(1e3);
3280
+ if (yield* I.tryPromise(() => ge(t, e)).pipe(I.catchAll(() => I.sync(() => (n(), !1))))) return r.interrupted = !0, yield* I.interrupt;
3281
+ yield* I.sleep(1e3);
3276
3282
  }
3277
- }), oi = 8192, si = 3, ci = 2e3, li = () => {
3283
+ }), li = 8192, ui = 3, di = 2e3, fi = () => {
3278
3284
  let e = (e) => {
3279
3285
  if (e === void 0) return;
3280
3286
  let t = Number(e);
@@ -3284,7 +3290,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
3284
3290
  ...t === void 0 ? {} : { maxRunReclaims: t },
3285
3291
  ...n === void 0 ? {} : { replayShapeLimit: n }
3286
3292
  };
3287
- }, ui = (e) => {
3293
+ }, pi = (e) => {
3288
3294
  let t = typeof e == "string" ? (() => {
3289
3295
  try {
3290
3296
  return JSON.parse(e);
@@ -3293,10 +3299,10 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
3293
3299
  }
3294
3300
  })() : e;
3295
3301
  if (Array.isArray(t)) return t.filter((e) => typeof e == "string");
3296
- }, di = () => {
3302
+ }, mi = () => {
3297
3303
  let e = globalThis.crypto;
3298
3304
  return typeof e?.randomUUID == "function" ? e.randomUUID() : `${Date.now().toString(36)}${Math.random().toString(36).slice(2)}`;
3299
- }, fi = (e) => `${e}_${di()}`, pi = (e, t = oi) => {
3305
+ }, hi = (e) => `${e}_${mi()}`, gi = (e, t = li) => {
3300
3306
  if (e == null) return e;
3301
3307
  try {
3302
3308
  let n = JSON.stringify(e);
@@ -3308,11 +3314,11 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
3308
3314
  } catch {
3309
3315
  return { __unserialisable: String(e) };
3310
3316
  }
3311
- }, mi = async (e, t, n) => {
3317
+ }, _i = async (e, t, n) => {
3312
3318
  if (n === null || !g() || !("value" in n || "result" in n || "errorMessage" in n) || e.query === void 0) return n;
3313
3319
  let [r] = await e.query({
3314
3320
  table: "_voltro_workflow_runs",
3315
- predicate: V("id", t),
3321
+ predicate: B("id", t),
3316
3322
  order: [],
3317
3323
  take: 1,
3318
3324
  skip: void 0,
@@ -3323,8 +3329,8 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
3323
3329
  let t = {};
3324
3330
  for (let [n, r] of Object.entries(e)) t[n] = r instanceof Date ? r.toISOString() : r;
3325
3331
  return ee(t);
3326
- }, hi = (e) => {
3327
- let t = e.truncateBytes ?? oi, n = e.makeId ?? fi, r = (t, n) => e.log?.warn(t, n), i = (e, t) => t === !0 ? l(e, "workflow step value", v) : e, a = e.emit, o = e.recording === "coarse";
3332
+ }, vi = (e) => {
3333
+ let t = e.truncateBytes ?? li, n = e.makeId ?? hi, r = (t, n) => e.log?.warn(t, n), i = (e, t) => t === !0 ? l(e, "workflow step value", v) : e, a = e.emit, o = e.recording === "coarse";
3328
3334
  return {
3329
3335
  startStep: async ({ runId: s, stepName: c, attempt: l, stepInput: u, retryPolicy: d, sealed: f }) => {
3330
3336
  if (!o) try {
@@ -3334,7 +3340,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
3334
3340
  stepName: c,
3335
3341
  attempt: l,
3336
3342
  status: "running",
3337
- input: u === void 0 ? null : i(pi(u, t), f),
3343
+ input: u === void 0 ? null : i(gi(u, t), f),
3338
3344
  retryPolicy: d ?? null,
3339
3345
  output: null,
3340
3346
  errorTag: null,
@@ -3361,7 +3367,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
3361
3367
  if (!o) try {
3362
3368
  let r = await e.store.update("_voltro_workflow_run_steps", n, {
3363
3369
  status: "succeeded",
3364
- output: i(pi(s, t), l),
3370
+ output: i(gi(s, t), l),
3365
3371
  completedAt: /* @__PURE__ */ new Date(),
3366
3372
  durationMs: c
3367
3373
  });
@@ -3382,7 +3388,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
3382
3388
  status: "failed",
3383
3389
  errorTag: s,
3384
3390
  errorMessage: c == null ? c : i(c, d),
3385
- errorCause: l === void 0 ? null : i(pi(l, t), d),
3391
+ errorCause: l === void 0 ? null : i(gi(l, t), d),
3386
3392
  completedAt: /* @__PURE__ */ new Date(),
3387
3393
  durationMs: u
3388
3394
  });
@@ -3404,7 +3410,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
3404
3410
  id: l,
3405
3411
  runId: t,
3406
3412
  eventType: i,
3407
- payload: await mi(e.store, t, o ?? null),
3413
+ payload: await _i(e.store, t, o ?? null),
3408
3414
  occurredAt: /* @__PURE__ */ new Date(),
3409
3415
  stepName: s ?? null,
3410
3416
  attempt: c ?? null
@@ -3430,16 +3436,16 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
3430
3436
  };
3431
3437
  }
3432
3438
  };
3433
- }, gi = (e, t, n) => L.gen(function* () {
3439
+ }, yi = (e, t, n) => I.gen(function* () {
3434
3440
  let r = e.store.query;
3435
3441
  if (r === void 0) return;
3436
- let i = e.replayShapeLimit ?? 2e3, a = yield* L.promise(() => r.call(e.store, {
3442
+ let i = e.replayShapeLimit ?? 2e3, a = yield* I.promise(() => r.call(e.store, {
3437
3443
  table: "_voltro_workflow_run_steps",
3438
3444
  order: [{
3439
3445
  column: "startedAt",
3440
3446
  direction: "asc"
3441
3447
  }],
3442
- predicate: V("runId", t),
3448
+ predicate: B("runId", t),
3443
3449
  projection: ["stepName"],
3444
3450
  skip: void 0,
3445
3451
  take: i + 1
@@ -3460,20 +3466,20 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
3460
3466
  return typeof t == "string" ? [{ stepName: t }] : [];
3461
3467
  });
3462
3468
  return o.length === 0 ? void 0 : s(o);
3463
- }), _i = (s, l) => {
3464
- let u = s.truncateBytes ?? oi, d = s.makeId ?? fi, f = s.recorder ?? hi(s), p = (e, t) => s.log?.warn(e, t), m = s.emit, h = (e) => L.gen(function* () {
3465
- yield* L.sync(() => m?.("workflowEvents", {
3469
+ }), bi = (s, l) => {
3470
+ let u = s.truncateBytes ?? li, d = s.makeId ?? hi, f = s.recorder ?? vi(s), p = (e, t) => s.log?.warn(e, t), m = s.emit, h = (e) => I.gen(function* () {
3471
+ yield* I.sync(() => m?.("workflowEvents", {
3466
3472
  op: "insert",
3467
3473
  row: $(e)
3468
3474
  }));
3469
3475
  let t = s.wakeups, n = e.runId;
3470
3476
  if (t !== void 0 && typeof n == "string") {
3471
3477
  let e = s.subject?.tenantId;
3472
- yield* L.promise(() => t.cancel(n, typeof e == "string" ? e : void 0).catch(() => {
3478
+ yield* I.promise(() => t.cancel(n, typeof e == "string" ? e : void 0).catch(() => {
3473
3479
  p("failed to clear terminal workflow wakeup", { runId: n });
3474
3480
  }));
3475
3481
  }
3476
- }), g = (e, t, n) => L.promise(async () => {
3482
+ }), g = (e, t, n) => I.promise(async () => {
3477
3483
  if (s.onParentClose) try {
3478
3484
  await s.onParentClose({
3479
3485
  workflowName: s.name,
@@ -3489,7 +3495,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
3489
3495
  reason: n?.message ?? String(n)
3490
3496
  });
3491
3497
  }
3492
- }), v = (e, t, n, r) => L.promise(async () => {
3498
+ }), v = (e, t, n, r) => I.promise(async () => {
3493
3499
  if (s.onTerminal) try {
3494
3500
  await s.onTerminal({
3495
3501
  workflowName: s.name,
@@ -3507,15 +3513,15 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
3507
3513
  });
3508
3514
  }
3509
3515
  });
3510
- return (ee, b) => L.gen(function* () {
3511
- let x = Date.now(), te = yield* Ye.get(r), ne = yield* Ye.get(i), re = s.parentExecutionId ?? te ?? null, ie = s.parentGeneration ?? (s.parentExecutionId == null ? ne : void 0) ?? null, ae = s.parentClosePolicy ?? null, S, C = (e, t) => t.pipe(L.catchAllCause((t) => I.isInterrupted(t) ? L.failCause(t) : L.sync(() => {
3512
- let n = I.squash(t);
3516
+ return (ee, b) => I.gen(function* () {
3517
+ let x = Date.now(), te = yield* Ze.get(r), ne = yield* Ze.get(i), re = s.parentExecutionId ?? te ?? null, ie = s.parentGeneration ?? (s.parentExecutionId == null ? ne : void 0) ?? null, ae = s.parentClosePolicy ?? null, S, C = (e, t) => t.pipe(I.catchAllCause((t) => F.isInterrupted(t) ? I.failCause(t) : I.sync(() => {
3518
+ let n = F.squash(t);
3513
3519
  p(e, {
3514
3520
  tag: s.name,
3515
3521
  executionId: b,
3516
3522
  reason: n?.message ?? String(n)
3517
3523
  });
3518
- }))), w = `wfrg_${di()}`, oe = yield* L.serviceOption(we), se = d("wr"), ce = yield* L.sync(() => s.encodePayload === void 0 ? ee : s.encodePayload(ee)), T = yield* L.promise(() => s.transaction((e) => zt(e, {
3524
+ }))), w = `wfrg_${mi()}`, oe = yield* I.serviceOption(Te), se = d("wr"), ce = yield* I.sync(() => s.encodePayload === void 0 ? ee : s.encodePayload(ee)), T = yield* I.promise(() => s.transaction((e) => Bt(e, {
3519
3525
  workflowName: s.name,
3520
3526
  executionId: b,
3521
3527
  generation: w,
@@ -3541,10 +3547,10 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
3541
3547
  parentClosePolicy: ae
3542
3548
  }
3543
3549
  })));
3544
- if (typeof T.row.id != "string") return yield* L.die(/* @__PURE__ */ Error("Recorded workflow entry has no run identity"));
3550
+ if (typeof T.row.id != "string") return yield* I.die(/* @__PURE__ */ Error("Recorded workflow entry has no run identity"));
3545
3551
  if (S = T.row.id, T.restartEvent !== void 0) {
3546
3552
  let e = T.restartEvent;
3547
- yield* C("failed to observe recorded workflow restart", L.sync(() => {
3553
+ yield* C("failed to observe recorded workflow restart", I.sync(() => {
3548
3554
  m?.("workflowEvents", {
3549
3555
  op: "insert",
3550
3556
  row: $(e)
@@ -3552,18 +3558,18 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
3552
3558
  }));
3553
3559
  }
3554
3560
  if (T.kind === "cancelled" || T.kind === "already-cancelled") {
3555
- let e = yield* mt;
3556
- return e.interrupted = !0, T.kind === "cancelled" && (yield* C("failed to observe suspended workflow cancellation", L.gen(function* () {
3561
+ let e = yield* Y;
3562
+ return e.interrupted = !0, T.kind === "cancelled" && (yield* C("failed to observe suspended workflow cancellation", I.gen(function* () {
3557
3563
  if (m?.("workflowRuns", {
3558
3564
  op: "update",
3559
3565
  row: $(T.row)
3560
- }), T.terminalEvent === void 0) return yield* L.die(/* @__PURE__ */ Error("Cancelled entry has no terminal event"));
3566
+ }), T.terminalEvent === void 0) return yield* I.die(/* @__PURE__ */ Error("Cancelled entry has no terminal event"));
3561
3567
  yield* h(T.terminalEvent), yield* g(b, "cancelled", S);
3562
- })), yield* v(b, "cancelled", S), yield* L.sync(() => s.recordRun?.({
3568
+ })), yield* v(b, "cancelled", S), yield* I.sync(() => s.recordRun?.({
3563
3569
  name: s.name,
3564
3570
  status: "cancelled",
3565
3571
  durationMs: 0
3566
- }))), yield* L.interrupt;
3572
+ }))), yield* I.interrupt;
3567
3573
  }
3568
3574
  let E = T.previous, le = E?.workflowVersion ?? null;
3569
3575
  if (E?.id !== void 0 && le !== null && s.workflowCompatibleVersions !== void 0 && s.workflowCompatibleVersions !== null && !s.workflowCompatibleVersions.includes(le)) {
@@ -3571,7 +3577,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
3571
3577
  handler: null,
3572
3578
  callerContext: null,
3573
3579
  tenantId: null
3574
- }, n = yield* L.promise(() => s.transaction((n) => Wt(n, {
3580
+ }, n = yield* I.promise(() => s.transaction((n) => Gt(n, {
3575
3581
  owner: {
3576
3582
  runId: S,
3577
3583
  workflowName: s.name,
@@ -3587,7 +3593,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
3587
3593
  ...t
3588
3594
  }
3589
3595
  })));
3590
- return n.kind === "committed" && (yield* C("failed to observe workflow version rejection", L.gen(function* () {
3596
+ return n.kind === "committed" && (yield* C("failed to observe workflow version rejection", I.gen(function* () {
3591
3597
  m?.("workflowRuns", {
3592
3598
  op: "update",
3593
3599
  row: $(n.row)
@@ -3596,7 +3602,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
3596
3602
  payload: T.row.payload,
3597
3603
  errorTag: "WorkflowVersionIncompatible",
3598
3604
  errorMessage: e
3599
- }), yield* L.sync(() => s.recordRun?.({
3605
+ }), yield* I.sync(() => s.recordRun?.({
3600
3606
  name: s.name,
3601
3607
  status: "failed",
3602
3608
  durationMs: 0
@@ -3606,16 +3612,16 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
3606
3612
  runId: S,
3607
3613
  errorTag: "WorkflowVersionIncompatible",
3608
3614
  cause: e
3609
- })), yield* L.fail(Error(e));
3615
+ })), yield* I.fail(Error(e));
3610
3616
  }
3611
3617
  let ue = s.workflowPatches ?? [], D;
3612
3618
  if (E?.id !== void 0) {
3613
- S = E.id, ue = ui(E.workflowPatches) ?? ue;
3619
+ S = E.id, ue = pi(E.workflowPatches) ?? ue;
3614
3620
  let e = T.row.reclaimCount;
3615
- if (typeof e != "number" || !Number.isSafeInteger(e) || e < 0) return yield* L.die(/* @__PURE__ */ Error("Recorded workflow entry has an invalid reclaim counter"));
3621
+ if (typeof e != "number" || !Number.isSafeInteger(e) || e < 0) return yield* I.die(/* @__PURE__ */ Error("Recorded workflow entry has an invalid reclaim counter"));
3616
3622
  let t = e > 0, n = s.maxRunReclaims ?? 3;
3617
3623
  if (t && e >= n) {
3618
- let t = `Workflow '${s.name}' run '${b}' killed its runner ${e} times in a row; parked instead of reclaimed again (maxRunReclaims=${n}).`, r = yield* L.promise(() => s.transaction((e) => Ht(e, {
3624
+ let t = `Workflow '${s.name}' run '${b}' killed its runner ${e} times in a row; parked instead of reclaimed again (maxRunReclaims=${n}).`, r = yield* I.promise(() => s.transaction((e) => Ut(e, {
3619
3625
  runId: S,
3620
3626
  workflowName: s.name,
3621
3627
  executionId: b,
@@ -3624,11 +3630,11 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
3624
3630
  errorTag: "WorkflowCrashLooped",
3625
3631
  errorMessage: t
3626
3632
  })));
3627
- r.kind === "committed" && (yield* C("failed to observe workflow crash-loop park", L.gen(function* () {
3633
+ r.kind === "committed" && (yield* C("failed to observe workflow crash-loop park", I.gen(function* () {
3628
3634
  m?.("workflowRuns", {
3629
3635
  op: "update",
3630
3636
  row: $(r.row)
3631
- }), yield* L.promise(() => f.recordEvent({
3637
+ }), yield* I.promise(() => f.recordEvent({
3632
3638
  runId: S,
3633
3639
  eventType: "run-crashlooped",
3634
3640
  payload: {
@@ -3645,14 +3651,14 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
3645
3651
  reclaimCount: e,
3646
3652
  maxRunReclaims: n
3647
3653
  }));
3648
- let i = yield* mt;
3649
- return yield* Ge.suspend(i);
3654
+ let i = yield* Y;
3655
+ return yield* Ke.suspend(i);
3650
3656
  }
3651
- D = yield* gi(s, S, p), yield* C("failed to record workflow re-entry", L.gen(function* () {
3657
+ D = yield* yi(s, S, p), yield* C("failed to record workflow re-entry", I.gen(function* () {
3652
3658
  m?.("workflowRuns", {
3653
3659
  op: "update",
3654
3660
  row: $(T.row)
3655
- }), t && (yield* L.promise(() => f.recordEvent({
3661
+ }), t && (yield* I.promise(() => f.recordEvent({
3656
3662
  runId: S,
3657
3663
  eventType: "run-resumed",
3658
3664
  payload: {
@@ -3662,13 +3668,13 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
3662
3668
  }
3663
3669
  })));
3664
3670
  }));
3665
- } else yield* C("failed to emit recorded workflow start", L.gen(function* () {
3671
+ } else yield* C("failed to emit recorded workflow start", I.gen(function* () {
3666
3672
  if (m?.("workflowRuns", {
3667
3673
  op: "insert",
3668
3674
  row: $(T.row)
3669
3675
  }), S) {
3670
3676
  let e = S;
3671
- yield* L.promise(() => f.recordEvent({
3677
+ yield* I.promise(() => f.recordEvent({
3672
3678
  runId: e,
3673
3679
  eventType: "run-started",
3674
3680
  payload: {
@@ -3683,7 +3689,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
3683
3689
  }));
3684
3690
  }
3685
3691
  }));
3686
- let de = s.subject?.tenantId, O = L.suspend(() => l(ee, b, w)).pipe(L.locally(t, S), L.locally(r, b), L.locally(i, w), L.locally(n, typeof de == "string" ? de : void 0), L.locally(a, ue), L.locally(c, D), L.provideService(o, f)), k = s.pluginWorkflowStepLayer ? O.pipe(L.provide(s.pluginWorkflowStepLayer)) : O, A = yield* Ge.intoResult(L.raceWith(k, ai({
3692
+ let de = s.subject?.tenantId, fe = I.suspend(() => l(ee, b, w)).pipe(I.locally(t, S), I.locally(r, b), I.locally(i, w), I.locally(n, typeof de == "string" ? de : void 0), I.locally(a, ue), I.locally(c, D), I.provideService(o, f)), O = s.pluginWorkflowStepLayer ? fe.pipe(I.provide(s.pluginWorkflowStepLayer)) : fe, k = yield* Ke.intoResult(I.raceWith(O, ci({
3687
3693
  runId: S,
3688
3694
  workflowName: s.name,
3689
3695
  executionId: b,
@@ -3691,12 +3697,12 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
3691
3697
  }, async (e) => s.store.query(e), () => p("workflow control read failed; retrying without claiming cancellation", {
3692
3698
  executionId: b,
3693
3699
  runId: S
3694
- })).pipe(L.interruptible), {
3695
- onSelfDone: (e, t) => Je.interrupt(t).pipe(L.zipRight(e)),
3696
- onOtherDone: (e, t) => Je.interrupt(t).pipe(L.zipRight(e))
3700
+ })).pipe(I.interruptible), {
3701
+ onSelfDone: (e, t) => Xe.interrupt(t).pipe(I.zipRight(e)),
3702
+ onOtherDone: (e, t) => Xe.interrupt(t).pipe(I.zipRight(e))
3697
3703
  }));
3698
- if (Ge.isResult(A) && A._tag === "Suspended") {
3699
- let e = A.cause, t = e !== void 0 && !I.isEmpty(e), n = t ? I.squash(e) : void 0, r = n && typeof n == "object" && "_tag" in n ? String(n._tag) : null, i = t ? n?.message ?? String(n) : null, a = yield* L.promise(() => s.transaction((e) => Ht(e, {
3704
+ if (Ke.isResult(k) && k._tag === "Suspended") {
3705
+ let e = k.cause, t = e !== void 0 && !F.isEmpty(e), n = t ? F.squash(e) : void 0, r = n && typeof n == "object" && "_tag" in n ? String(n._tag) : null, i = t ? n?.message ?? String(n) : null, a = yield* I.promise(() => s.transaction((e) => Ut(e, {
3700
3706
  runId: S,
3701
3707
  workflowName: s.name,
3702
3708
  executionId: b,
@@ -3705,7 +3711,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
3705
3711
  errorTag: r,
3706
3712
  errorMessage: i
3707
3713
  })));
3708
- a.kind === "committed" && t && (yield* L.sync(() => Qe({
3714
+ a.kind === "committed" && t && (yield* I.sync(() => et({
3709
3715
  error: n,
3710
3716
  source: "workflow",
3711
3717
  name: s.name,
@@ -3717,11 +3723,11 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
3717
3723
  ...r ? { errorTag: r } : {},
3718
3724
  ...S ? { runId: S } : {}
3719
3725
  }
3720
- }))), a.kind === "committed" && (yield* C("failed to observe workflow suspend", L.gen(function* () {
3726
+ }))), a.kind === "committed" && (yield* C("failed to observe workflow suspend", I.gen(function* () {
3721
3727
  m?.("workflowRuns", {
3722
3728
  op: "update",
3723
3729
  row: $(a.row)
3724
- }), yield* L.promise(() => f.recordEvent({
3730
+ }), yield* I.promise(() => f.recordEvent({
3725
3731
  runId: S,
3726
3732
  eventType: "run-suspended",
3727
3733
  payload: t ? {
@@ -3731,10 +3737,10 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
3731
3737
  } : { reason: "workflow-suspend" }
3732
3738
  }));
3733
3739
  })));
3734
- let o = yield* mt;
3735
- return yield* Ge.suspend(o);
3740
+ let o = yield* Y;
3741
+ return yield* Ke.suspend(o);
3736
3742
  }
3737
- let fe = A;
3743
+ let pe = k;
3738
3744
  if (D !== void 0 && S !== void 0) {
3739
3745
  let t = D.settle();
3740
3746
  if (t.length > 0) {
@@ -3744,7 +3750,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
3744
3750
  executionId: b,
3745
3751
  runId: n,
3746
3752
  findings: t.map((e) => `${e.kind}:${e.stepName}`)
3747
- }), yield* C("failed to record nondeterminism findings", L.promise(async () => {
3753
+ }), yield* C("failed to record nondeterminism findings", I.promise(async () => {
3748
3754
  for (let r of t) await f.recordEvent({
3749
3755
  runId: n,
3750
3756
  eventType: "nondeterminism-suspected",
@@ -3753,10 +3759,10 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
3753
3759
  }));
3754
3760
  }
3755
3761
  }
3756
- if (qe.isFailure(fe.exit)) {
3757
- let e = fe.exit.cause;
3758
- if ((yield* mt).interrupted && I.isInterruptedOnly(e)) {
3759
- let t = Date.now(), n = yield* L.promise(() => s.transaction((e) => Wt(e, {
3762
+ if (Ye.isFailure(pe.exit)) {
3763
+ let e = pe.exit.cause;
3764
+ if ((yield* Y).interrupted && F.isInterruptedOnly(e)) {
3765
+ let t = Date.now(), n = yield* I.promise(() => s.transaction((e) => Gt(e, {
3760
3766
  owner: {
3761
3767
  runId: S,
3762
3768
  workflowName: s.name,
@@ -3767,22 +3773,22 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
3767
3773
  durationMs: t - x,
3768
3774
  outcome: { status: "cancelled" }
3769
3775
  })));
3770
- return n.kind === "committed" && (yield* C("failed to observe workflow cancellation", L.gen(function* () {
3776
+ return n.kind === "committed" && (yield* C("failed to observe workflow cancellation", I.gen(function* () {
3771
3777
  m?.("workflowRuns", {
3772
3778
  op: "update",
3773
3779
  row: $(n.row)
3774
3780
  }), yield* h(n.terminalEvent), yield* g(b, "cancelled", S);
3775
- })), yield* v(b, "cancelled", S), yield* L.sync(() => s.recordRun?.({
3781
+ })), yield* v(b, "cancelled", S), yield* I.sync(() => s.recordRun?.({
3776
3782
  name: s.name,
3777
3783
  status: "cancelled",
3778
3784
  durationMs: t - x
3779
- }))), yield* L.failCause(e);
3785
+ }))), yield* I.failCause(e);
3780
3786
  }
3781
- let t = I.failureOption(e), n = t._tag === "Some" ? t.value : I.squash(e), r = n && typeof n == "object" && "_tag" in n ? String(n._tag) : null, i = n?.message ?? String(n), a = Date.now(), o = s.failureContext ?? {
3787
+ let t = F.failureOption(e), n = t._tag === "Some" ? t.value : F.squash(e), r = n && typeof n == "object" && "_tag" in n ? String(n._tag) : null, i = n?.message ?? String(n), a = Date.now(), o = s.failureContext ?? {
3782
3788
  handler: null,
3783
3789
  callerContext: null,
3784
3790
  tenantId: null
3785
- }, c = yield* L.promise(() => s.transaction((e) => Wt(e, {
3791
+ }, c = yield* I.promise(() => s.transaction((e) => Gt(e, {
3786
3792
  owner: {
3787
3793
  runId: S,
3788
3794
  workflowName: s.name,
@@ -3804,7 +3810,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
3804
3810
  runId: S,
3805
3811
  ...r ? { errorTag: r } : {},
3806
3812
  cause: y(s.name, n)
3807
- }), yield* L.sync(() => Qe({
3813
+ }), yield* I.sync(() => et({
3808
3814
  error: n,
3809
3815
  source: "workflow",
3810
3816
  name: s.name,
@@ -3815,7 +3821,7 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
3815
3821
  ...r ? { errorTag: r } : {},
3816
3822
  ...S ? { runId: S } : {}
3817
3823
  }
3818
- })), S && (yield* C("failed to record workflow failure", L.gen(function* () {
3824
+ })), S && (yield* C("failed to record workflow failure", I.gen(function* () {
3819
3825
  m?.("workflowRuns", {
3820
3826
  op: "update",
3821
3827
  row: $(c.row)
@@ -3824,38 +3830,38 @@ var ht = Ke.layerMemory, gt = q("_voltro_workflow_runs", {
3824
3830
  payload: ee,
3825
3831
  errorTag: r,
3826
3832
  errorMessage: i
3827
- }), yield* L.sync(() => s.recordRun?.({
3833
+ }), yield* I.sync(() => s.recordRun?.({
3828
3834
  name: s.name,
3829
3835
  status: "failed",
3830
3836
  durationMs: Date.now() - x
3831
- })), yield* L.failCause(e)) : yield* L.failCause(e);
3837
+ })), yield* I.failCause(e)) : yield* I.failCause(e);
3832
3838
  }
3833
- let pe = fe.exit.value, j = Date.now(), M = yield* L.promise(() => s.transaction((e) => Wt(e, {
3839
+ let me = pe.exit.value, A = Date.now(), j = yield* I.promise(() => s.transaction((e) => Gt(e, {
3834
3840
  owner: {
3835
3841
  runId: S,
3836
3842
  workflowName: s.name,
3837
3843
  executionId: b,
3838
3844
  generation: w
3839
3845
  },
3840
- now: j,
3841
- durationMs: j - x,
3846
+ now: A,
3847
+ durationMs: A - x,
3842
3848
  outcome: {
3843
3849
  status: "succeeded",
3844
- output: pi(pe, u)
3850
+ output: gi(me, u)
3845
3851
  }
3846
3852
  })));
3847
- return M.kind === "committed" ? (S && (yield* C("failed to record workflow success", L.gen(function* () {
3853
+ return j.kind === "committed" ? (S && (yield* C("failed to record workflow success", I.gen(function* () {
3848
3854
  m?.("workflowRuns", {
3849
3855
  op: "update",
3850
- row: $(M.row)
3851
- }), yield* h(M.terminalEvent), yield* g(b, "succeeded", S);
3852
- }))), yield* v(b, "succeeded", S), yield* L.sync(() => s.recordRun?.({
3856
+ row: $(j.row)
3857
+ }), yield* h(j.terminalEvent), yield* g(b, "succeeded", S);
3858
+ }))), yield* v(b, "succeeded", S), yield* I.sync(() => s.recordRun?.({
3853
3859
  name: s.name,
3854
3860
  status: "succeeded",
3855
3861
  durationMs: Date.now() - x,
3856
3862
  completedAtSec: Date.now() / 1e3
3857
- })), pe) : pe;
3863
+ })), me) : me;
3858
3864
  });
3859
3865
  };
3860
3866
  //#endregion
3861
- export { gn as $, yr as A, Zn as B, Nr as C, vt as Ct, wr as D, Cr as E, ht as Et, fr as F, yn as G, jn as H, dr as I, vn as J, bn as K, Yn as L, lr as M, hr as N, Er as O, mr as P, Tn as Q, or as R, Ur as S, yt as St, Ar as T, gt as Tt, An as U, kn as V, Rn as W, wn as X, _n as Y, On as Z, Lr as _, xt as _t, li as a, cn as at, Jr as b, Tt as bt, _i as c, Gt as ct, Qr as d, zt as dt, hn as et, Z as f, Pt as ft, Rr as g, Ct as gt, zr as h, St as ht, ui as i, sn as it, _r as j, Dr as k, ii as l, Vt as lt, Hr as m, Dt as mt, ci as n, un as nt, $ as o, an as ot, Vr as p, bt as pt, xn as q, hi as r, fn as rt, pi as s, on as st, si as t, pn as tt, ri as u, Wt as ut, Ir as v, Ot as vt, Pr as w, _t as wt, qr as x, wt as xt, Yr as y, Et as yt, Qn as z };
3867
+ export { kn as $, Sr as A, sr as B, Ir as C, Tt as Ct, Dr as D, _t as Dt, Er as E, vt as Et, gr as F, jn as G, Qn as H, hr as I, xn as J, zn as K, pr as L, br as M, vr as N, kr as O, gt as Ot, ur as P, Tn as Q, fr as R, Kr as S, Et as St, Nr as T, yt as Tt, An as U, $n as V, Mn as W, yn as X, Sn as Y, vn as Z, Br as _, Ct as _t, fi as a, pn as at, Zr as b, kt as bt, bi as c, on as ct, ti as d, Ht as dt, En as et, Z as f, Gt as ft, Vr as g, Ot as gt, Hr as h, xt as ht, pi as i, dn as it, Cr as j, Ar as k, si as l, sn as lt, Gr as m, Ft as mt, di as n, gn as nt, $ as o, cn as ot, Wr as p, Bt as pt, bn as q, vi as r, mn as rt, gi as s, ln as st, ui as t, _n as tt, oi as u, Kt as ut, zr as v, wt as vt, Lr as w, bt as wt, Xr as x, Dt as xt, Qr as y, St as yt, Xn as z };