@voltro/plugin-ai-flows 0.84.0 → 0.85.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,21 +1,21 @@
1
1
  import { FLOW_RUN_WORKFLOW as e, HUMAN_RESPONSE_SIGNAL_PREFIX as t, flowRunWorkflow as n, humanResponseSignalName as r } from "./workflow.js";
2
- import { A as i, B as a, C as o, D as s, E as c, F as l, H as u, I as d, L as f, M as p, N as m, O as h, P as g, R as _, S as v, T as ee, V as y, _ as te, a as ne, b, c as re, d as x, f as S, g as C, h as ie, i as w, j as ae, k as oe, l as se, m as ce, n as le, o as T, p as ue, r as de, s as fe, t as pe, u as me, v as he, w as ge, x as _e, y as ve, z as ye } from "./ir-CdDUTf98.js";
3
- import { FlowBriefIncomplete as be, FlowCapabilityMissing as E, FlowDependencyError as xe, FlowNotAwaitingResponse as Se, FlowNotFound as Ce, FlowReviewDeliveryError as we, FlowRunNotFound as D, FlowValidationError as Te } from "./errors.js";
4
- import { n as Ee, t as De } from "./cadence-_9Izk_fL.js";
5
- import { Cause as Oe, Effect as O, Exit as ke, Schema as k } from "effect";
6
- import { WorkflowControlResultSchema as Ae, WorkflowRunHandleSchema as je, definePlugin as Me, pluginInstanceName as Ne } from "@voltro/protocol";
7
- import { and as Pe, boolean as Fe, eq as A, id as Ie, inSet as Le, integer as j, json as M, notInSet as Re, queryFor as N, registerRetention as ze, table as Be, text as P, timestamp as Ve } from "@voltro/database";
8
- import { tenant as He } from "@voltro/plugin-multitenancy/mixin";
9
- import { audit as Ue } from "@voltro/plugin-audit/mixin";
10
- import { softDelete as We } from "@voltro/plugin-soft-delete/mixin";
11
- import { SuspensionUnavailable as Ge, awaitSignalSuspending as Ke, step as F } from "@voltro/workflow";
12
- import { defineTool as qe, estimateCostUsd as Je, gatewayCostUsd as Ye, generateImage as Xe, generateObject as Ze, generateObjectJson as Qe, generateObjectWithTools as $e, generateSpeech as et, generateText as tt, generateVideo as nt, isMeteredUsage as rt } from "@voltro/ai";
13
- import { createHash as it } from "node:crypto";
2
+ import { A as i, B as a, C as o, D as s, E as c, F as l, H as u, I as d, L as f, M as p, N as m, O as h, P as g, R as ee, S as _, T as te, V as v, _ as ne, a as re, b as y, c as ie, d as b, f as x, g as ae, h as oe, i as S, j as se, k as ce, l as le, m as ue, n as de, o as C, p as fe, r as pe, s as me, t as he, u as ge, v as _e, w as ve, x as ye, y as be, z as xe } from "./ir-Cjk1kQl9.js";
3
+ import { FlowBriefIncomplete as Se, FlowCapabilityMissing as w, FlowDependencyError as Ce, FlowNotAwaitingResponse as we, FlowNotFound as Te, FlowReviewDeliveryError as Ee, FlowRunNotFound as T, FlowValidationError as De } from "./errors.js";
4
+ import { n as Oe, t as ke } from "./cadence-_9Izk_fL.js";
5
+ import { Cause as E, Effect as D, Exit as Ae, Result as O, Schema as k } from "effect";
6
+ import { WorkflowControlResultSchema as je, WorkflowRunHandleSchema as Me, definePlugin as Ne, pluginInstanceName as Pe } from "@voltro/protocol";
7
+ import { and as Fe, boolean as Ie, eq as A, id as Le, inSet as Re, integer as j, json as M, notInSet as ze, queryFor as N, registerRetention as Be, table as Ve, text as P, timestamp as He } from "@voltro/database";
8
+ import { tenant as Ue } from "@voltro/plugin-multitenancy/mixin";
9
+ import { audit as We } from "@voltro/plugin-audit/mixin";
10
+ import { softDelete as Ge } from "@voltro/plugin-soft-delete/mixin";
11
+ import { SuspensionUnavailable as Ke, awaitSignalSuspending as qe, step as F } from "@voltro/workflow";
12
+ import { defineTool as Je, estimateCostUsd as Ye, gatewayCostUsd as Xe, generateImage as Ze, generateObject as Qe, generateObjectJson as $e, generateObjectWithTools as et, generateSpeech as tt, generateText as nt, generateVideo as rt, isMeteredUsage as it } from "@voltro/ai";
13
+ import { createHash as at } from "node:crypto";
14
14
  //#region src/registry.ts
15
- var I = /* @__PURE__ */ new Map(), at = (e) => {
15
+ var I = /* @__PURE__ */ new Map(), ot = (e) => {
16
16
  I.set(e.name, e);
17
- }, ot = (e) => I.get(e), st = () => [...I.values()], ct = () => I.clear(), L = Be("_voltro_ai_flows", {
18
- id: Ie({ prefix: "aifl" }),
17
+ }, st = (e) => I.get(e), ct = () => [...I.values()], lt = () => I.clear(), L = Ve("_voltro_ai_flows", {
18
+ id: Le({ prefix: "aifl" }),
19
19
  name: P(),
20
20
  description: P().nullable(),
21
21
  mode: P().default("deterministic"),
@@ -29,15 +29,15 @@ var I = /* @__PURE__ */ new Map(), at = (e) => {
29
29
  chainTo: M().nullable(),
30
30
  cadence: M().nullable(),
31
31
  humanTimeoutMs: j().nullable(),
32
- isEnabled: Fe().default(!0),
32
+ isEnabled: Ie().default(!0),
33
33
  metadata: M().nullable(),
34
34
  icon: P().nullable(),
35
35
  color: P().nullable(),
36
36
  avatarUrl: P().nullable(),
37
37
  usageCount: j().default(0),
38
38
  ownerId: P().nullable()
39
- }).renamedFrom("ai_flows").with(He(), Ue(), We()).index(["status"]).index(["visibility"]), R = Be("_voltro_ai_flow_runs", {
40
- id: Ie({ prefix: "aifr" }),
39
+ }).renamedFrom("ai_flows").with(Ue(), We(), Ge()).index(["status"]).index(["visibility"]), R = Ve("_voltro_ai_flow_runs", {
40
+ id: Le({ prefix: "aifr" }),
41
41
  flowRef: P(),
42
42
  flowName: P().nullable(),
43
43
  mode: P().default("deterministic"),
@@ -58,26 +58,26 @@ var I = /* @__PURE__ */ new Map(), at = (e) => {
58
58
  durationMs: j().nullable(),
59
59
  error: P().nullable(),
60
60
  errorMessage: P().nullable(),
61
- startedAt: Ve().nullable(),
62
- completedAt: Ve().nullable(),
63
- cancelledAt: Ve().nullable(),
61
+ startedAt: He().nullable(),
62
+ completedAt: He().nullable(),
63
+ cancelledAt: He().nullable(),
64
64
  sessionId: P().nullable(),
65
65
  sessionName: P().nullable(),
66
66
  ownerId: P().nullable(),
67
67
  metadata: M().nullable()
68
- }).renamedFrom("ai_flow_runs").with(He(), Ue()).index(["flowRef"]).index(["status"]).index(["requestId"]), lt = [L, R], ut = k.Struct({
68
+ }).renamedFrom("ai_flow_runs").with(Ue(), We()).index(["flowRef"]).index(["status"]).index(["requestId"]), ut = [L, R], dt = k.Struct({
69
69
  id: k.NonEmptyString,
70
70
  workflowName: k.Literal(e),
71
71
  status: k.Literal("queued")
72
- }), dt = (t) => ({
72
+ }), ft = (t) => ({
73
73
  id: t,
74
74
  workflowName: e,
75
75
  executionId: t,
76
76
  status: "running"
77
- }), ft = (e) => {
77
+ }), pt = (e) => {
78
78
  let t = `flow start was not executed: ${e.reason}`;
79
79
  return e.incumbentExecutionId === null ? e.failureId === null ? t : `${t} (failure report ${e.failureId})` : `${t} (incumbent execution ${e.incumbentExecutionId})`;
80
- }, pt = async (e, t = {}) => {
80
+ }, mt = async (e, t = {}) => {
81
81
  let n = e.workflows;
82
82
  if (!n) throw Error("workflow runtime unavailable; flow starts cannot be reconciled");
83
83
  if (n.startsDeferredUntilCommit === !0) return {
@@ -104,7 +104,7 @@ var I = /* @__PURE__ */ new Map(), at = (e) => {
104
104
  for (let t of i) {
105
105
  let r = t.id;
106
106
  if (typeof r != "string") continue;
107
- let i = k.decodeUnknownOption(ut)(t.workflowStart);
107
+ let i = k.decodeUnknownOption(dt)(t.workflowStart);
108
108
  if (i._tag !== "None") {
109
109
  a.examined++;
110
110
  try {
@@ -118,14 +118,14 @@ var I = /* @__PURE__ */ new Map(), at = (e) => {
118
118
  }
119
119
  let o = (/* @__PURE__ */ new Date()).toISOString();
120
120
  if (t.kind === "accepted") {
121
- if (await e.store.update(R.tableName, r, { workflowStart: dt(t.executionId) }) === null) throw Error("flow run disappeared while recording its accepted start");
121
+ if (await e.store.update(R.tableName, r, { workflowStart: ft(t.executionId) }) === null) throw Error("flow run disappeared while recording its accepted start");
122
122
  a.accepted++;
123
123
  continue;
124
124
  }
125
125
  if (await e.store.update(R.tableName, r, {
126
126
  status: "failed",
127
127
  error: "FlowStartNotExecuted",
128
- errorMessage: ft(t),
128
+ errorMessage: pt(t),
129
129
  completedAt: o
130
130
  }) === null) throw Error("flow run disappeared while recording that its start will not execute");
131
131
  a.notExecuted++;
@@ -138,32 +138,32 @@ var I = /* @__PURE__ */ new Map(), at = (e) => {
138
138
  }
139
139
  }
140
140
  return a;
141
- }, mt = 168, ht = "VOLTRO_AI_FLOW_HUMAN_REVIEW_TIMEOUT_HOURS", gt = 2160, _t = "VOLTRO_AI_FLOW_RUNS_TTL_HOURS", vt = 5, yt = "VOLTRO_AI_FLOW_MAX_CHAIN_DEPTH", bt = { current: {} }, xt = (e) => {
142
- bt.current = e;
143
- }, St = () => bt.current, Ct = () => {
144
- bt.current = {};
145
- }, wt = (e, t) => {
141
+ }, ht = 168, gt = "VOLTRO_AI_FLOW_HUMAN_REVIEW_TIMEOUT_HOURS", _t = 2160, vt = "VOLTRO_AI_FLOW_RUNS_TTL_HOURS", yt = 5, bt = "VOLTRO_AI_FLOW_MAX_CHAIN_DEPTH", xt = { current: {} }, St = (e) => {
142
+ xt.current = e;
143
+ }, Ct = () => xt.current, wt = () => {
144
+ xt.current = {};
145
+ }, Tt = (e, t) => {
146
146
  if (e === void 0 || e.trim() === "") return t * 36e5;
147
147
  let n = Number(e);
148
148
  return !Number.isFinite(n) || n < 0 ? t * 36e5 : n * 36e5;
149
- }, Tt = (e) => Number.isFinite(e) && e > 0 ? e : Infinity, Et = (e) => {
149
+ }, Et = (e) => Number.isFinite(e) && e > 0 ? e : Infinity, Dt = (e) => {
150
150
  let t = e.env ?? process.env;
151
- return Tt(e.step?.timeoutMs ?? e.flow?.humanTimeoutMs ?? e.deps?.humanReviewTimeoutMs ?? St().humanReviewTimeoutMs ?? wt(t.VOLTRO_AI_FLOW_HUMAN_REVIEW_TIMEOUT_HOURS, 168));
152
- }, Dt = (e) => {
153
- let t = e?.env ?? process.env, n = Number(t[yt]), r = e?.maxChainDepth ?? St().maxChainDepth ?? (Number.isFinite(n) && n >= 1 ? n : 5);
151
+ return Et(e.step?.timeoutMs ?? e.flow?.humanTimeoutMs ?? e.deps?.humanReviewTimeoutMs ?? Ct().humanReviewTimeoutMs ?? Tt(t.VOLTRO_AI_FLOW_HUMAN_REVIEW_TIMEOUT_HOURS, 168));
152
+ }, Ot = (e) => {
153
+ let t = e?.env ?? process.env, n = Number(t[bt]), r = e?.maxChainDepth ?? Ct().maxChainDepth ?? (Number.isFinite(n) && n >= 1 ? n : 5);
154
154
  return Number.isFinite(r) && r >= 1 ? r : 5;
155
- }, Ot = /\{\{\s*([\w.-]+)\s*\}\}/g, kt = (e) => {
155
+ }, kt = /\{\{\s*([\w.-]+)\s*\}\}/g, At = (e) => {
156
156
  let t = [];
157
- for (let n of e.matchAll(Ot)) t.push(n[1]);
157
+ for (let n of e.matchAll(kt)) t.push(n[1]);
158
158
  return t;
159
- }, At = (e, t) => e.replace(Ot, (e, n) => {
159
+ }, jt = (e, t) => e.replace(kt, (e, n) => {
160
160
  let r = t[n];
161
161
  return r == null ? "" : typeof r == "string" ? r : JSON.stringify(r);
162
- }), jt = (e, t) => {
162
+ }), Mt = (e, t) => {
163
163
  let n = /* @__PURE__ */ new Set();
164
- for (let r of kt(e)) t[r] == null && !n.has(r) && n.add(r);
164
+ for (let r of At(e)) t[r] == null && !n.has(r) && n.add(r);
165
165
  return [...n];
166
- }, Mt = (e) => {
166
+ }, Nt = (e) => {
167
167
  let t = [], n;
168
168
  if (e.forEach((e, r) => {
169
169
  let i = e.group;
@@ -192,65 +192,57 @@ var I = /* @__PURE__ */ new Map(), at = (e) => {
192
192
  });
193
193
  }
194
194
  return t;
195
- }, Nt = (e) => {
195
+ }, Pt = (e) => {
196
196
  let t = /* @__PURE__ */ new Map();
197
197
  for (let n of e) n.group !== void 0 && t.set(n.group, (t.get(n.group) ?? 0) + 1);
198
198
  return [...t.entries()].filter(([, e]) => e > 1).map(([e]) => e).sort();
199
- }, z = k.suspend(() => k.Union(k.Null, k.Boolean, k.Finite, k.String, k.Array(z).pipe(k.mutable), k.Record({
200
- key: k.String,
201
- value: z
202
- }))), B = k.Record({
203
- key: k.String,
204
- value: k.Record({
205
- key: k.String,
206
- value: z
207
- })
208
- }), Pt = k.Struct({
209
- maxTokens: k.optionalWith(k.Int.pipe(k.positive(), k.lessThanOrEqualTo(2 ** 53 - 1)), { exact: !0 }),
210
- temperature: k.optionalWith(k.Finite.pipe(k.nonNegative()), { exact: !0 }),
211
- providerOptions: k.optionalWith(B, { exact: !0 })
212
- }), Ft = [
199
+ }, Ft = k.suspend(() => k.Union([
200
+ k.Null,
201
+ k.Boolean,
202
+ k.Finite,
203
+ k.String,
204
+ k.Array(Ft).pipe(k.mutable),
205
+ k.Record(k.String, Ft)
206
+ ])), z = k.Record(k.String, k.Record(k.String, Ft)), It = k.Struct({
207
+ maxTokens: k.optionalKey(k.Int.pipe(k.check(k.isGreaterThan(0)), k.check(k.isLessThanOrEqualTo(2 ** 53 - 1)))),
208
+ temperature: k.optionalKey(k.Finite.pipe(k.check(k.isGreaterThanOrEqualTo(0)))),
209
+ providerOptions: k.optionalKey(z)
210
+ }), Lt = [
213
211
  "maxTokens",
214
212
  "temperature",
215
213
  "providerOptions"
216
- ], It = (e) => {
214
+ ], Rt = (e) => {
217
215
  if (typeof e != "object" || !e || Array.isArray(e)) return "params must be an object";
218
- let t = Object.keys(e), n = t.filter((e) => !Ft.includes(e)).sort(), r = t.filter((t) => Ft.includes(t) && k.decodeUnknownOption(Pt)({ [t]: e[t] })._tag === "None").sort();
216
+ let t = Object.keys(e), n = t.filter((e) => !Lt.includes(e)).sort(), r = t.filter((t) => Lt.includes(t) && k.decodeUnknownOption(It)({ [t]: e[t] })._tag === "None").sort();
219
217
  return [...n.length > 0 ? [`unsupported field${n.length === 1 ? "" : "s"}: ${n.join(", ")}`] : [], ...r.length > 0 ? [`invalid value for: ${r.join(", ")}`] : []].join("; ");
220
- }, Lt = (e) => O.try({
221
- try: () => k.decodeUnknownSync(Pt, { onExcessProperty: "error" })(e === void 0 ? {} : e),
222
- catch: () => `invalid text params (${It(e)}): expected maxTokens (positive safe integer), temperature (finite nonnegative number), and/or providerOptions (provider-keyed JSON object); other fields are not supported`
223
- }), V = k.String.pipe(k.filter((e) => {
218
+ }, zt = (e) => D.try({
219
+ try: () => k.decodeUnknownSync(It, { onExcessProperty: "error" })(e === void 0 ? {} : e),
220
+ catch: () => `invalid text params (${Rt(e)}): expected maxTokens (positive safe integer), temperature (finite nonnegative number), and/or providerOptions (provider-keyed JSON object); other fields are not supported`
221
+ }), B = k.String.pipe(k.check(k.makeFilter((e) => {
224
222
  try {
225
223
  let t = new URL(e);
226
224
  return (t.protocol === "https:" || t.protocol === "http:") && t.username === "" && t.password === "";
227
225
  } catch {
228
226
  return !1;
229
227
  }
230
- })), Rt = k.Record({
231
- key: k.String,
232
- value: V
233
- }), zt = (e, t, n = {}) => O.try({
228
+ }))), Bt = k.Record(k.String, B), Vt = (e, t, n = {}) => D.try({
234
229
  try: () => {
235
- let r = k.decodeUnknownSync(v, { onExcessProperty: "error" })(e === void 0 ? {} : e), i = Object.fromEntries(Object.entries(r).map(([e, r]) => [e, r.from === "upload" ? r.url : r.artifact === void 0 ? Object.hasOwn(t, r.ref) ? t[r.ref] : void 0 : Object.hasOwn(n, r.ref) ? n[r.ref]?.[r.artifact]?.url : void 0]));
236
- return k.decodeUnknownSync(Rt)(i);
230
+ let r = k.decodeUnknownSync(_, { onExcessProperty: "error" })(e === void 0 ? {} : e), i = Object.fromEntries(Object.entries(r).map(([e, r]) => [e, r.from === "upload" ? r.url : r.artifact === void 0 ? Object.hasOwn(t, r.ref) ? t[r.ref] : void 0 : Object.hasOwn(n, r.ref) ? n[r.ref]?.[r.artifact]?.url : void 0]));
231
+ return k.decodeUnknownSync(Bt)(i);
237
232
  },
238
233
  catch: () => "invalid or unresolved media input: each slot must resolve to an absolute HTTP(S) URL without embedded credentials"
239
- }), Bt = k.Struct({
240
- url: V,
234
+ }), Ht = k.Struct({
235
+ url: B,
241
236
  mediaType: k.NonEmptyString
242
237
  });
243
- k.Record({
244
- key: k.String,
245
- value: Bt
246
- });
247
- var Vt = (e, t = {}) => {
248
- let n = k.decodeUnknownOption(v)(e === void 0 ? {} : e);
238
+ k.Record(k.String, Ht);
239
+ var Ut = (e, t = {}) => {
240
+ let n = k.decodeUnknownOption(_)(e === void 0 ? {} : e);
249
241
  if (n._tag === "None") return {};
250
242
  let r = {};
251
243
  for (let [e, i] of Object.entries(n.value)) {
252
244
  if (i.from === "upload") {
253
- i.mediaType !== void 0 && k.is(V)(i.url) && (r[e] = {
245
+ i.mediaType !== void 0 && k.is(B)(i.url) && (r[e] = {
254
246
  url: i.url,
255
247
  mediaType: i.mediaType
256
248
  });
@@ -258,15 +250,15 @@ var Vt = (e, t = {}) => {
258
250
  }
259
251
  if (i.artifact === void 0 || !Object.hasOwn(t, i.ref)) continue;
260
252
  let n = t[i.ref]?.[i.artifact];
261
- n !== void 0 && k.is(V)(n.url) && (r[e] = {
253
+ n !== void 0 && k.is(B)(n.url) && (r[e] = {
262
254
  url: n.url,
263
255
  mediaType: n.mediaType
264
256
  });
265
257
  }
266
258
  return r;
267
- }, Ht = (e, t) => O.try({
259
+ }, Wt = (e, t) => D.try({
268
260
  try: () => {
269
- let n = k.decodeUnknownSync(Rt)(t === void 0 ? {} : t), r = e === "image" ? ["referenceImageUrl", "maskImageUrl"] : e === "video" ? [
261
+ let n = k.decodeUnknownSync(Bt)(t === void 0 ? {} : t), r = e === "image" ? ["referenceImageUrl", "maskImageUrl"] : e === "video" ? [
270
262
  "referenceImageUrl",
271
263
  "firstFrameImageUrl",
272
264
  "lastFrameImageUrl",
@@ -277,26 +269,26 @@ var Vt = (e, t = {}) => {
277
269
  return n;
278
270
  },
279
271
  catch: () => `invalid or unsupported media input for ${e}; check the built-in adapter's slot contract`
280
- }), Ut = k.Struct({
281
- artifacts: b,
282
- costMicroUsd: k.optional(k.Finite.pipe(k.nonNegative())),
283
- costSource: k.optional(w),
272
+ }), Gt = k.Struct({
273
+ artifacts: y,
274
+ costMicroUsd: k.optional(k.Finite.pipe(k.check(k.isGreaterThanOrEqualTo(0)))),
275
+ costSource: k.optional(S),
284
276
  requestId: k.optional(k.NonEmptyString),
285
277
  usage: k.optional(m)
286
- }), Wt = (e) => O.try({
287
- try: () => k.decodeUnknownSync(Ut, { onExcessProperty: "error" })(e),
278
+ }), Kt = (e) => D.try({
279
+ try: () => k.decodeUnknownSync(Gt, { onExcessProperty: "error" })(e),
288
280
  catch: () => "invalid media result: expected artifacts with URL, mediaType and role, exactly one primary artifact, and optional storage references"
289
- }), H = (e) => e, Gt = (e) => e._tag === "FlowAgentUnavailable" ? e.publicMessage ?? "agent unavailable" : "agent not found", Kt = k.Struct({
281
+ }), V = (e) => e, qt = (e) => e._tag === "FlowAgentUnavailable" ? e.publicMessage ?? "agent unavailable" : "agent not found", Jt = k.Struct({
290
282
  value: k.optional(k.Unknown),
291
283
  text: k.optional(k.String),
292
284
  url: k.optional(k.String),
293
- artifacts: k.optional(b),
285
+ artifacts: k.optional(y),
294
286
  costMicroUsd: k.optional(k.Number),
295
- costSource: k.optional(w),
287
+ costSource: k.optional(S),
296
288
  requestId: k.optional(k.String),
297
289
  usage: k.optional(m),
298
290
  error: k.optional(k.String)
299
- }), qt = (e) => Wt(e).pipe(O.map((e) => {
291
+ }), Yt = (e) => Kt(e).pipe(D.map((e) => {
300
292
  let t = e.artifacts.find((e) => e.role === "primary");
301
293
  return {
302
294
  value: t.url,
@@ -307,55 +299,55 @@ var Vt = (e, t = {}) => {
307
299
  ...e.costSource === void 0 ? {} : { costSource: e.costSource },
308
300
  ...e.usage === void 0 ? {} : { usage: e.usage }
309
301
  };
310
- }), O.catchAll((e) => O.succeed({ error: e }))), U = (e) => ({
302
+ }), D.catch((e) => D.succeed({ error: e }))), H = (e) => ({
311
303
  ...e.requestId ? { requestId: e.requestId } : {},
312
304
  ...e.costMicroUsd ? { costMicroUsd: e.costMicroUsd } : {},
313
305
  ...e.costSource === void 0 ? {} : { costSource: e.costSource },
314
306
  ...e.usage === void 0 ? {} : { usage: e.usage }
315
- }), W = () => (/* @__PURE__ */ new Date()).toISOString(), Jt = (e) => Math.round(e * 1e6), Yt = (e) => ({
307
+ }), U = () => (/* @__PURE__ */ new Date()).toISOString(), Xt = (e) => Math.round(e * 1e6), Zt = (e) => ({
316
308
  name: "gateway",
317
309
  model: e
318
- }), G = (e, t) => e.resolveModel?.(t) ?? Yt(t), Xt = (e, t, n, r) => O.gen(function* () {
319
- return t.maxSteps !== void 0 && (!Number.isSafeInteger(t.maxSteps) || t.maxSteps < 1) ? yield* O.fail(new E({
310
+ }), W = (e, t) => e.resolveModel?.(t) ?? Zt(t), Qt = (e, t, n, r) => D.gen(function* () {
311
+ return t.maxSteps !== void 0 && (!Number.isSafeInteger(t.maxSteps) || t.maxSteps < 1) ? yield* D.fail(new w({
320
312
  capability: "resolveAgent",
321
313
  message: "agent maxSteps must be a positive safe integer"
322
- })) : yield* tt({
314
+ })) : yield* nt({
323
315
  ...r,
324
316
  system: t.system,
325
317
  prompt: n,
326
- provider: G(e, t.model),
318
+ provider: W(e, t.model),
327
319
  ...t.tools === void 0 ? {} : { tools: t.tools },
328
320
  ...t.maxSteps === void 0 ? {} : { maxSteps: t.maxSteps }
329
321
  });
330
- }), Zt = (e, t, n) => K(e, t, n).costMicroUsd, K = (e, t, n) => {
331
- let r = Ye(t);
322
+ }), $t = (e, t, n) => G(e, t, n).costMicroUsd, G = (e, t, n) => {
323
+ let r = Xe(t);
332
324
  if (typeof r == "number") return {
333
- costMicroUsd: Jt(r),
325
+ costMicroUsd: Xt(r),
334
326
  costSource: "gateway"
335
327
  };
336
- let i = Je(e, { model: n ?? "unknown" });
328
+ let i = Ye(e, { model: n ?? "unknown" });
337
329
  return {
338
330
  costMicroUsd: i.costMicroUsd ?? 0,
339
331
  costSource: i.costSource ?? "unpriced"
340
332
  };
341
- }, q = (e) => {
333
+ }, K = (e) => {
342
334
  let t = e.filter((e) => (e.status === "succeeded" || e.status === "failed") && (e.costSource !== void 0 || e.costMicroUsd !== void 0));
343
335
  if (t.length === 0) return "unknown";
344
336
  let n = t.map((e) => e.costSource ?? "unpriced");
345
337
  return n.every((e) => e === "gateway") ? "actual" : n.some((e) => e === "unpriced") ? "incomplete" : "estimated";
346
- }, J = (e, t, n) => O.promise(() => e.store.update(R.tableName, t, n).then(() => void 0)).pipe(O.catchAllCause(() => O.void)), Qt = (e, t, n, r) => O.promise(async () => {
338
+ }, q = (e, t, n) => D.promise(() => e.store.update(R.tableName, t, n).then(() => void 0)).pipe(D.catchCause(() => D.void)), en = (e, t, n, r) => D.promise(async () => {
347
339
  let i = await e.store.query(N(R).where(A("id", t)).descriptor), a = i[0]?.[r];
348
340
  i[0] !== void 0 && a == null && await e.store.update(R.tableName, t, n);
349
- }).pipe(O.catchAllCause(() => O.void)), $t = (e, t) => O.promise(async () => {
341
+ }).pipe(D.catchCause(() => D.void)), tn = (e, t) => D.promise(async () => {
350
342
  let n = (await e.store.query(N(R).where(A("id", t)).descriptor))[0]?.status;
351
343
  return n === "cancelling" || n === "cancelled";
352
- }).pipe(O.catchAllCause(() => O.succeed(!1))), en = (e, t) => O.promise(() => e.store.updateMany(R.tableName, {
344
+ }).pipe(D.catchCause(() => D.succeed(!1))), nn = (e, t) => D.promise(() => e.store.updateMany(R.tableName, {
353
345
  status: "cancelled",
354
- completedAt: W()
355
- }, { where: Pe(A("id", t), A("status", "cancelling")) }).then(() => void 0)).pipe(O.catchAllCause(() => O.void)), tn = (e, t) => O.gen(function* () {
356
- let n = ot(t);
346
+ completedAt: U()
347
+ }, { where: Fe(A("id", t), A("status", "cancelling")) }).then(() => void 0)).pipe(D.catchCause(() => D.void)), rn = (e, t) => D.gen(function* () {
348
+ let n = st(t);
357
349
  if (n) return n;
358
- let r = (yield* O.promise(() => e.store.query(N(L).where(A("id", t)).descriptor)))[0];
350
+ let r = (yield* D.promise(() => e.store.query(N(L).where(A("id", t)).descriptor)))[0];
359
351
  return r ? d({
360
352
  name: r.name ?? t,
361
353
  mode: r.mode,
@@ -367,16 +359,16 @@ var Vt = (e, t = {}) => {
367
359
  chain: r.chainTo ?? null,
368
360
  cadence: r.cadence ?? null,
369
361
  humanTimeoutMs: r.humanTimeoutMs ?? null
370
- }) : yield* O.fail(new Ce({
362
+ }) : yield* D.fail(new Te({
371
363
  flowRef: t,
372
364
  message: `no flow registered or stored for "${t}"`
373
365
  }));
374
- }), nn = (e, t, n, r, i, a) => O.gen(function* () {
375
- let e = At(n.prompt ?? "", r), o = yield* Lt(n.type === "agent" || n.type === "structured" || n.type === "generate" && (n.modality ?? "text") === "text" ? n.params : void 0).pipe(O.either);
376
- if (o._tag === "Left") return { error: `step "${n.id}": ${o.left}` };
366
+ }), an = (e, t, n, r, i, a) => D.gen(function* () {
367
+ let e = jt(n.prompt ?? "", r), o = yield* zt(n.type === "agent" || n.type === "structured" || n.type === "generate" && (n.modality ?? "text") === "text" ? n.params : void 0).pipe(D.result);
368
+ if (O.isFailure(o)) return { error: `step "${n.id}": ${o.failure}` };
377
369
  if (n.mediaInputs !== void 0 && (n.type !== "generate" || (n.modality ?? "text") === "text")) return { error: `step "${n.id}": media inputs require an image, video or audio generation step` };
378
- let s = jt(n.prompt ?? "", r);
379
- if (s.length > 0) return { error: new xe({
370
+ let s = Mt(n.prompt ?? "", r);
371
+ if (s.length > 0) return { error: new Ce({
380
372
  stepId: n.id,
381
373
  unresolvedRef: s[0],
382
374
  message: `step "${n.id}" references unresolved {{${s[0]}}}`
@@ -390,89 +382,89 @@ var Vt = (e, t = {}) => {
390
382
  };
391
383
  case "agent": {
392
384
  if (!n.agentRef) return { error: "agent step missing agentRef" };
393
- if (!t.resolveAgent) return { error: new E({
385
+ if (!t.resolveAgent) return { error: new w({
394
386
  capability: "resolveAgent",
395
387
  message: "no agent resolver configured"
396
388
  }).message };
397
- let r = yield* H(t.resolveAgent(n.agentRef, i)).pipe(O.map((e) => ({
389
+ let r = yield* V(t.resolveAgent(n.agentRef, i)).pipe(D.map((e) => ({
398
390
  ok: !0,
399
391
  a: e
400
- })), O.catchAll((e) => O.succeed({
392
+ })), D.catch((e) => D.succeed({
401
393
  ok: !1,
402
394
  e
403
395
  })));
404
396
  if (!r.ok) return { error: r.e.message };
405
- let a = yield* Xt(t, r.a, e, o.right).pipe(O.map((e) => ({
397
+ let a = yield* Qt(t, r.a, e, o.success).pipe(D.map((e) => ({
406
398
  ok: !0,
407
399
  r: e
408
- })), O.catchAll((e) => O.succeed({
400
+ })), D.catch((e) => D.succeed({
409
401
  ok: !1,
410
402
  e
411
403
  })));
412
404
  return a.ok ? {
413
405
  value: a.r.text,
414
406
  text: a.r.text,
415
- ...K(a.r.usage, a.r.providerMetadata, r.a.model)
407
+ ...G(a.r.usage, a.r.providerMetadata, r.a.model)
416
408
  } : { error: String(a.e.message ?? a.e) };
417
409
  }
418
410
  case "structured": {
419
411
  if (n.schema === void 0) return { error: `step "${n.id}": structured step requires a JSON Schema` };
420
- let r = n.model ?? t.defaultModels?.text, i = yield* Qe({
421
- ...o.right,
412
+ let r = n.model ?? t.defaultModels?.text, i = yield* $e({
413
+ ...o.success,
422
414
  prompt: e,
423
415
  jsonSchema: n.schema,
424
- ...r ? { provider: G(t, r) } : {}
425
- }).pipe(O.map((e) => ({
416
+ ...r ? { provider: W(t, r) } : {}
417
+ }).pipe(D.map((e) => ({
426
418
  ok: !0,
427
419
  r: e
428
- })), O.catchAll((e) => O.succeed({
420
+ })), D.catch((e) => D.succeed({
429
421
  ok: !1,
430
422
  e
431
423
  })));
432
424
  return i.ok ? {
433
425
  value: i.r.object,
434
426
  text: JSON.stringify(i.r.object, null, 2),
435
- ...K(i.r.usage, i.r.providerMetadata, r)
427
+ ...G(i.r.usage, i.r.providerMetadata, r)
436
428
  } : { error: String(i.e.message ?? i.e) };
437
429
  }
438
430
  case "generate": {
439
431
  let s = n.modality ?? "text";
440
432
  if (s === "text") {
441
- let r = n.model ?? t.defaultModels?.text, i = yield* tt({
442
- ...o.right,
433
+ let r = n.model ?? t.defaultModels?.text, i = yield* nt({
434
+ ...o.success,
443
435
  prompt: e,
444
- ...r ? { provider: G(t, r) } : {}
445
- }).pipe(O.map((e) => ({
436
+ ...r ? { provider: W(t, r) } : {}
437
+ }).pipe(D.map((e) => ({
446
438
  ok: !0,
447
439
  r: e
448
- })), O.catchAll((e) => O.succeed({
440
+ })), D.catch((e) => D.succeed({
449
441
  ok: !1,
450
442
  e
451
443
  })));
452
444
  return i.ok ? {
453
445
  value: i.r.text,
454
446
  text: i.r.text,
455
- ...K(i.r.usage, i.r.providerMetadata, r)
447
+ ...G(i.r.usage, i.r.providerMetadata, r)
456
448
  } : { error: String(i.e.message ?? i.e) };
457
449
  }
458
- if (!t.generateMedia) return { error: new E({
450
+ if (!t.generateMedia) return { error: new w({
459
451
  capability: `media:${s}`,
460
452
  message: `no media generator configured for ${s}`
461
453
  }).message };
462
- let c = yield* zt(n.mediaInputs, r, a).pipe(O.either);
463
- if (c._tag === "Left") return { error: `step "${n.id}": ${c.left}` };
464
- let l = Vt(n.mediaInputs, a), u = n.model ?? t.defaultModels?.[s], d = yield* H(t.generateMedia({
454
+ let c = yield* Vt(n.mediaInputs, r, a).pipe(D.result);
455
+ if (O.isFailure(c)) return { error: `step "${n.id}": ${c.failure}` };
456
+ let l = Ut(n.mediaInputs, a), u = n.model ?? t.defaultModels?.[s], d = yield* V(t.generateMedia({
465
457
  modality: s,
466
458
  ...u ? { model: u } : {},
467
459
  prompt: e,
468
460
  ...n.params ? { params: n.params } : {},
469
- ...n.mediaInputs === void 0 ? {} : { inputs: c.right },
461
+ ...n.mediaInputs === void 0 ? {} : { inputs: c.success },
470
462
  ...Object.keys(l).length > 0 ? { inputRefs: l } : {},
471
463
  run: i
472
- })).pipe(O.map((e) => ({
464
+ })).pipe(D.map((e) => ({
473
465
  ok: !0,
474
466
  m: e
475
- })), O.catchAll((e) => O.succeed({
467
+ })), D.catch((e) => D.succeed({
476
468
  ok: !1,
477
469
  e
478
470
  })));
@@ -483,15 +475,15 @@ var Vt = (e, t = {}) => {
483
475
  ...e === void 0 ? {} : e
484
476
  };
485
477
  }
486
- return yield* qt(d.m);
478
+ return yield* Yt(d.m);
487
479
  }
488
- case "human": return { error: new E({
480
+ case "human": return { error: new w({
489
481
  capability: "human",
490
482
  message: "human step reached the step interpreter — it should have been parked by the deterministic executor (routing bug)"
491
483
  }).message };
492
484
  default: return { error: `unknown step type: ${String(n.type)}` };
493
485
  }
494
- }), rn = (e, t, n, i, o, s) => O.gen(function* () {
486
+ }), on = (e, t, n, i, o, s) => D.gen(function* () {
495
487
  let c = Object.assign(Object.create(null), o), l = Object.create(null), u = i.steps.map((e, t) => ({
496
488
  id: t,
497
489
  title: e.title ?? `Step ${t + 1}`,
@@ -499,26 +491,26 @@ var Vt = (e, t = {}) => {
499
491
  status: "pending",
500
492
  ...e.description ? { description: e.description } : {}
501
493
  })), d = 0;
502
- yield* Qt(e, n, {
494
+ yield* en(e, n, {
503
495
  status: "running",
504
496
  steps: u,
505
497
  totalSteps: i.steps.length,
506
498
  currentStep: 0,
507
- startedAt: W()
499
+ startedAt: U()
508
500
  }, "startedAt");
509
- for (let o of Mt(i.steps)) {
510
- if (yield* $t(e, n)) return yield* en(e, n), {
501
+ for (let o of Nt(i.steps)) {
502
+ if (yield* tn(e, n)) return yield* nn(e, n), {
511
503
  runId: n,
512
504
  status: "cancelled"
513
505
  };
514
506
  if (o.steps.length > 1) {
515
507
  let r = [];
516
508
  for (let { index: e, step: t } of o.steps) {
517
- if (t.when !== void 0 && !y(t.when, c)) {
509
+ if (t.when !== void 0 && !v(t.when, c)) {
518
510
  u[e] = {
519
511
  ...u[e],
520
512
  status: "skipped",
521
- completedAt: W(),
513
+ completedAt: U(),
522
514
  skipReason: a(t.when)
523
515
  };
524
516
  continue;
@@ -529,23 +521,23 @@ var Vt = (e, t = {}) => {
529
521
  }), u[e] = {
530
522
  ...u[e],
531
523
  status: "running",
532
- startedAt: W()
524
+ startedAt: U()
533
525
  };
534
526
  }
535
- yield* J(e, n, {
527
+ yield* q(e, n, {
536
528
  steps: u,
537
529
  currentStep: o.steps[0].index
538
530
  });
539
- let i = yield* O.all(r.map(({ index: r, step: i }) => F({
531
+ let i = yield* D.all(r.map(({ index: r, step: i }) => F({
540
532
  name: `flow-${r}-${i.id}`,
541
533
  input: { index: r },
542
- success: Kt,
543
- execute: nn(e, t, i, c, {
534
+ success: Jt,
535
+ execute: an(e, t, i, c, {
544
536
  runId: n,
545
537
  tenantId: s.tenantId,
546
538
  ownerId: s.ownerId
547
539
  }, l)
548
- }).pipe(O.map((e) => ({
540
+ }).pipe(D.map((e) => ({
549
541
  index: r,
550
542
  step: i,
551
543
  result: e
@@ -555,49 +547,49 @@ var Vt = (e, t = {}) => {
555
547
  d += n.costMicroUsd ?? 0, u[e] = {
556
548
  ...u[e],
557
549
  status: "failed",
558
- completedAt: W(),
550
+ completedAt: U(),
559
551
  errorMessage: n.error,
560
- ...U(n)
552
+ ...H(n)
561
553
  };
562
554
  continue;
563
555
  }
564
556
  t.outputKey && n.value !== void 0 && (c[t.outputKey] = n.value), t.outputKey && n.artifacts !== void 0 && (l[t.outputKey] = n.artifacts), d += n.costMicroUsd ?? 0, u[e] = {
565
557
  ...u[e],
566
558
  status: "succeeded",
567
- completedAt: W(),
559
+ completedAt: U(),
568
560
  ...n.text ? { output: { text: n.text } } : {},
569
561
  ...n.url ? { url: n.url } : {},
570
562
  ...n.artifacts === void 0 ? {} : { artifacts: n.artifacts },
571
- ...U(n)
563
+ ...H(n)
572
564
  };
573
565
  }
574
- if (f !== void 0) return yield* J(e, n, {
566
+ if (f !== void 0) return yield* q(e, n, {
575
567
  steps: u,
576
568
  status: "failed",
577
569
  errorMessage: f.result.error,
578
- completedAt: W(),
570
+ completedAt: U(),
579
571
  costMicroUsd: d,
580
- costCompleteness: q(u)
572
+ costCompleteness: K(u)
581
573
  }), {
582
574
  runId: n,
583
575
  status: "failed"
584
576
  };
585
- yield* J(e, n, {
577
+ yield* q(e, n, {
586
578
  steps: u,
587
579
  currentStep: o.steps[o.steps.length - 1].index + 1,
588
580
  costMicroUsd: d,
589
- costCompleteness: q(u)
581
+ costCompleteness: K(u)
590
582
  });
591
583
  continue;
592
584
  }
593
585
  let { index: f, step: p } = o.steps[0];
594
- if (p.when !== void 0 && !y(p.when, c)) {
586
+ if (p.when !== void 0 && !v(p.when, c)) {
595
587
  u[f] = {
596
588
  ...u[f],
597
589
  status: "skipped",
598
- completedAt: W(),
590
+ completedAt: U(),
599
591
  skipReason: a(p.when)
600
- }, yield* J(e, n, {
592
+ }, yield* q(e, n, {
601
593
  steps: u,
602
594
  currentStep: f + 1
603
595
  });
@@ -607,36 +599,36 @@ var Vt = (e, t = {}) => {
607
599
  let a = {
608
600
  mode: p.reviewMode ?? "approve",
609
601
  ...p.options ? { options: p.options } : {},
610
- prompt: At(p.prompt ?? "", c)
602
+ prompt: jt(p.prompt ?? "", c)
611
603
  };
612
604
  u[f] = {
613
605
  ...u[f],
614
606
  status: "waiting",
615
- startedAt: W(),
607
+ startedAt: U(),
616
608
  review: a
617
- }, yield* J(e, n, {
609
+ }, yield* q(e, n, {
618
610
  steps: u,
619
611
  status: "waiting",
620
612
  currentStep: f
621
- }), t.onEvent && (yield* H(t.onEvent({
613
+ }), t.onEvent && (yield* V(t.onEvent({
622
614
  kind: "review-needed",
623
615
  runId: n,
624
616
  flowName: i.name,
625
617
  ownerId: s.ownerId,
626
618
  source: s.source
627
- })).pipe(O.catchAllCause(() => O.void)));
628
- let o = Et({
619
+ })).pipe(D.catchCause(() => D.void)));
620
+ let o = Dt({
629
621
  step: p,
630
622
  flow: i,
631
623
  deps: t
632
- }), l = yield* Ke(e, {
624
+ }), l = yield* qe(e, {
633
625
  name: r(f),
634
- schema: ce,
626
+ schema: ue,
635
627
  timeoutMs: o
636
- }).pipe(O.map((e) => ({
628
+ }).pipe(D.map((e) => ({
637
629
  ok: !0,
638
630
  a: e
639
- })), O.catchAllCause((e) => Oe.isInterruptedOnly(e) ? O.failCause(e) : O.succeed({
631
+ })), D.catchCause((e) => E.hasInterruptsOnly(e) ? D.failCause(e) : D.succeed({
640
632
  ok: !1,
641
633
  cause: e
642
634
  })));
@@ -645,15 +637,15 @@ var Vt = (e, t = {}) => {
645
637
  return u[f] = {
646
638
  ...u[f],
647
639
  status: "failed",
648
- completedAt: W(),
640
+ completedAt: U(),
649
641
  errorMessage: t
650
- }, yield* J(e, n, {
642
+ }, yield* q(e, n, {
651
643
  steps: u,
652
644
  status: "failed",
653
645
  errorMessage: t,
654
- completedAt: W(),
646
+ completedAt: U(),
655
647
  costMicroUsd: d,
656
- costCompleteness: q(u)
648
+ costCompleteness: K(u)
657
649
  }), {
658
650
  runId: n,
659
651
  status: "failed"
@@ -663,15 +655,15 @@ var Vt = (e, t = {}) => {
663
655
  if (m.decision === "reject") return u[f] = {
664
656
  ...u[f],
665
657
  status: "failed",
666
- completedAt: W(),
658
+ completedAt: U(),
667
659
  errorMessage: "rejected by reviewer"
668
- }, yield* J(e, n, {
660
+ }, yield* q(e, n, {
669
661
  steps: u,
670
662
  status: "cancelled",
671
663
  humanResponse: m,
672
- completedAt: W(),
664
+ completedAt: U(),
673
665
  costMicroUsd: d,
674
- costCompleteness: q(u)
666
+ costCompleteness: K(u)
675
667
  }), {
676
668
  runId: n,
677
669
  status: "cancelled"
@@ -679,9 +671,9 @@ var Vt = (e, t = {}) => {
679
671
  p.outputKey && (c[p.outputKey] = m.value ?? m.text ?? m.decision ?? !0), u[f] = {
680
672
  ...u[f],
681
673
  status: "succeeded",
682
- completedAt: W(),
674
+ completedAt: U(),
683
675
  output: { text: String(m.text ?? m.value ?? m.decision ?? "approved") }
684
- }, yield* J(e, n, {
676
+ }, yield* q(e, n, {
685
677
  steps: u,
686
678
  status: "running",
687
679
  humanResponse: m,
@@ -692,16 +684,16 @@ var Vt = (e, t = {}) => {
692
684
  u[f] = {
693
685
  ...u[f],
694
686
  status: "running",
695
- startedAt: W()
696
- }, yield* J(e, n, {
687
+ startedAt: U()
688
+ }, yield* q(e, n, {
697
689
  steps: u,
698
690
  currentStep: f
699
691
  });
700
692
  let m = yield* F({
701
693
  name: `flow-${f}-${p.id}`,
702
694
  input: { index: f },
703
- success: Kt,
704
- execute: nn(e, t, p, c, {
695
+ success: Jt,
696
+ execute: an(e, t, p, c, {
705
697
  runId: n,
706
698
  tenantId: s.tenantId,
707
699
  ownerId: s.ownerId
@@ -710,16 +702,16 @@ var Vt = (e, t = {}) => {
710
702
  if (m.error) return d += m.costMicroUsd ?? 0, u[f] = {
711
703
  ...u[f],
712
704
  status: "failed",
713
- completedAt: W(),
705
+ completedAt: U(),
714
706
  errorMessage: m.error,
715
- ...U(m)
716
- }, yield* J(e, n, {
707
+ ...H(m)
708
+ }, yield* q(e, n, {
717
709
  steps: u,
718
710
  status: "failed",
719
711
  errorMessage: m.error,
720
- completedAt: W(),
712
+ completedAt: U(),
721
713
  costMicroUsd: d,
722
- costCompleteness: q(u)
714
+ costCompleteness: K(u)
723
715
  }), {
724
716
  runId: n,
725
717
  status: "failed"
@@ -727,42 +719,42 @@ var Vt = (e, t = {}) => {
727
719
  p.outputKey && m.value !== void 0 && (c[p.outputKey] = m.value), p.outputKey && m.artifacts !== void 0 && (l[p.outputKey] = m.artifacts), d += m.costMicroUsd ?? 0, u[f] = {
728
720
  ...u[f],
729
721
  status: "succeeded",
730
- completedAt: W(),
722
+ completedAt: U(),
731
723
  ...m.text ? { output: { text: m.text } } : {},
732
724
  ...m.url ? { url: m.url } : {},
733
725
  ...m.artifacts === void 0 ? {} : { artifacts: m.artifacts },
734
- ...U(m)
735
- }, yield* J(e, n, {
726
+ ...H(m)
727
+ }, yield* q(e, n, {
736
728
  steps: u,
737
729
  currentStep: f + 1,
738
730
  costMicroUsd: d,
739
- costCompleteness: q(u)
731
+ costCompleteness: K(u)
740
732
  });
741
733
  }
742
734
  let f = Object.create(null);
743
735
  for (let e of i.steps) e.outputKey && c[e.outputKey] !== void 0 && (f[e.outputKey] = c[e.outputKey]);
744
- return yield* J(e, n, {
736
+ return yield* q(e, n, {
745
737
  status: "succeeded",
746
738
  output: f,
747
- completedAt: W(),
739
+ completedAt: U(),
748
740
  costMicroUsd: d
749
741
  }), {
750
742
  runId: n,
751
743
  status: "succeeded",
752
744
  output: f
753
745
  };
754
- }), an = (e, t, n, r, i, a, o) => O.gen(function* () {
746
+ }), sn = (e, t, n, r, i, a, o) => D.gen(function* () {
755
747
  let s = n.chain;
756
748
  if (!s) return;
757
749
  let c = [...a.chainPath ?? [], a.flowRef];
758
750
  if (s.flowRef === n.name || s.flowRef === a.flowRef) return;
759
751
  if (c.includes(s.flowRef)) {
760
- yield* J(e, t, { chainRefusal: `chain to "${s.flowRef}" refused — it is already in this run's chain (${c.join(" → ")}), which would loop` });
752
+ yield* q(e, t, { chainRefusal: `chain to "${s.flowRef}" refused — it is already in this run's chain (${c.join(" → ")}), which would loop` });
761
753
  return;
762
754
  }
763
- let l = Dt(o);
755
+ let l = Ot(o);
764
756
  if (c.length >= l) {
765
- yield* J(e, t, { chainRefusal: `chain to "${s.flowRef}" refused — depth ${c.length} reached the limit of ${l} (${c.join(" → ")})` });
757
+ yield* q(e, t, { chainRefusal: `chain to "${s.flowRef}" refused — depth ${c.length} reached the limit of ${l} (${c.join(" → ")})` });
766
758
  return;
767
759
  }
768
760
  let u = {
@@ -771,7 +763,7 @@ var Vt = (e, t = {}) => {
771
763
  }, d = {};
772
764
  for (let e of s.mappings) e.sourceKey in u && (d[e.targetKey] = u[e.sourceKey]);
773
765
  if (s.requireConfirmation) {
774
- yield* J(e, t, { chainPending: {
766
+ yield* q(e, t, { chainPending: {
775
767
  flowRef: s.flowRef,
776
768
  input: d,
777
769
  status: "pending"
@@ -781,7 +773,7 @@ var Vt = (e, t = {}) => {
781
773
  let f = e.workflows;
782
774
  if (!f) return;
783
775
  let p = `${t}--chain`, m = `${a.requestId}--chain`;
784
- yield* O.promise(async () => {
776
+ yield* D.promise(async () => {
785
777
  try {
786
778
  await e.store.insert(R.tableName, {
787
779
  id: p,
@@ -801,120 +793,117 @@ var Vt = (e, t = {}) => {
801
793
  requestId: m,
802
794
  chainPath: c
803
795
  });
804
- }).pipe(O.catchAllCause(() => O.void));
805
- }), on = (e) => e.type === "agent" ? e.agentRef ? `agent step, agent "${e.agentRef}"` : "agent step" : e.type === "generate" ? `${e.modality ?? "media"} generation step` : `${e.type} step`, sn = (e) => e.steps.length === 0 ? "" : "Suggested plan (you MAY reorder, insert, or skip steps):\n" + e.steps.map((e, t) => `${t + 1}. ${e.title ?? e.id}${e.prompt ? `: ${e.prompt}` : ""} (${on(e)})`).join("\n"), cn = "an agentic flow runs its planner and every tool inside one durable step, which cannot park. Call the provider directly from the tool (generateImage, generateVideo, …), or give the work its own deterministic flow step", ln = k.optional(k.String.annotations({ description: "One short sentence: what this call is for. Shown to the user in the run timeline." })), un = (e) => e === void 0 || e.trim() === "" ? {} : { description: e.trim().slice(0, 200) }, dn = k.Struct({ json: k.String.annotations({ description: "The requested JSON object, serialized as a JSON string." }) }), fn = (e) => {
796
+ }).pipe(D.catchCause(() => D.void));
797
+ }), cn = (e) => e.type === "agent" ? e.agentRef ? `agent step, agent "${e.agentRef}"` : "agent step" : e.type === "generate" ? `${e.modality ?? "media"} generation step` : `${e.type} step`, ln = (e) => e.steps.length === 0 ? "" : "Suggested plan (you MAY reorder, insert, or skip steps):\n" + e.steps.map((e, t) => `${t + 1}. ${e.title ?? e.id}${e.prompt ? `: ${e.prompt}` : ""} (${cn(e)})`).join("\n"), un = "an agentic flow runs its planner and every tool inside one durable step, which cannot park. Call the provider directly from the tool (generateImage, generateVideo, …), or give the work its own deterministic flow step", dn = k.optional(k.String.annotate({ description: "One short sentence: what this call is for. Shown to the user in the run timeline." })), fn = (e) => e === void 0 || e.trim() === "" ? {} : { description: e.trim().slice(0, 200) }, pn = k.Struct({ json: k.String.annotate({ description: "The requested JSON object, serialized as a JSON string." }) }), mn = (e) => {
806
798
  try {
807
799
  let t = JSON.parse(e);
808
800
  return typeof t == "object" && t && !Array.isArray(t) ? t : void 0;
809
801
  } catch {
810
802
  return;
811
803
  }
812
- }, pn = (e) => {
813
- if (ke.isSuccess(e)) return "the tool returned without recording a result";
814
- if (Oe.isInterruptedOnly(e.cause)) return "interrupted before it finished — nothing waited for its result";
815
- let t = Oe.squash(e.cause);
804
+ }, hn = (e) => {
805
+ if (Ae.isSuccess(e)) return "the tool returned without recording a result";
806
+ if (E.hasInterruptsOnly(e.cause)) return "interrupted before it finished — nothing waited for its result";
807
+ let t = E.squash(e.cause);
816
808
  return t instanceof Error ? t.message : String(t);
817
- }, mn = (e) => {
809
+ }, gn = (e) => {
818
810
  let t = Object.entries(e);
819
811
  return t.length === 0 ? "Execute the flow." : "Brief for this run:\n" + t.map(([e, t]) => `- ${e}: ${typeof t == "string" ? t : JSON.stringify(t)}`).join("\n");
820
- }, hn = (e) => [
812
+ }, _n = (e) => [
821
813
  e.orchestrator?.instructions ?? "You are an orchestrator that uses the available tools to produce a bundled result.",
822
- sn(e),
814
+ ln(e),
823
815
  "When finished, emit a JSON object mapping each deliverable name (outputKey) to its value, serialized as a string in the json field."
824
- ].filter(Boolean).join("\n\n"), gn = k.Struct({
825
- object: k.Record({
826
- key: k.String,
827
- value: k.Unknown
828
- }),
816
+ ].filter(Boolean).join("\n\n"), vn = k.Struct({
817
+ object: k.Record(k.String, k.Unknown),
829
818
  planCostMicroUsd: k.Number,
830
- planCostSource: k.optional(w),
819
+ planCostSource: k.optional(S),
831
820
  toolCostMicroUsd: k.Number,
832
821
  steps: k.Array(i),
833
822
  error: k.optional(k.String)
834
- }), _n = (e, t, n, r, i, a, o, s) => O.gen(function* () {
835
- yield* Qt(e, n, {
823
+ }), yn = (e, t, n, r, i, a, o, s) => D.gen(function* () {
824
+ yield* en(e, n, {
836
825
  status: "running",
837
- startedAt: W(),
826
+ startedAt: U(),
838
827
  totalSteps: r.steps.length
839
828
  }, "startedAt");
840
829
  let c = yield* F({
841
830
  name: "flow-agentic",
842
831
  input: { flowRef: r.name },
843
- success: gn,
844
- execute: O.gen(function* () {
832
+ success: vn,
833
+ execute: D.gen(function* () {
845
834
  let c = [], l = 0, u = (e) => {
846
835
  let t = c.length;
847
836
  return c.push({
848
837
  id: t,
849
838
  status: "running",
850
- startedAt: W(),
839
+ startedAt: U(),
851
840
  ...e
852
841
  }), t;
853
842
  }, d = (e, t) => {
854
843
  c[e] = {
855
844
  ...c[e],
856
- completedAt: W(),
845
+ completedAt: U(),
857
846
  ...t
858
847
  };
859
- }, f = () => J(e, n, {
848
+ }, f = () => q(e, n, {
860
849
  steps: c,
861
850
  currentStep: c.length,
862
851
  costMicroUsd: l
863
- }), p = (e, t) => O.suspend(() => {
852
+ }), p = (e, t) => D.suspend(() => {
864
853
  let n = u(e);
865
- return O.zipRight(f(), t(n)).pipe(O.onExit((e) => c[n]?.status === "running" ? (d(n, {
854
+ return D.andThen(f(), t(n)).pipe(D.onExit((e) => c[n]?.status === "running" ? (d(n, {
866
855
  status: "failed",
867
- errorMessage: pn(e)
868
- }), O.ignore(f())) : O.void));
869
- }), m = yield* (t.listAgents ? H(t.listAgents({
856
+ errorMessage: hn(e)
857
+ }), D.ignore(f())) : D.void));
858
+ }), m = yield* (t.listAgents ? V(t.listAgents({
870
859
  runId: n,
871
860
  tenantId: o,
872
861
  ownerId: a
873
- })) : O.succeed(void 0)).pipe(O.either);
874
- if (m._tag === "Left") return yield* O.logWarning(`flow agent listing failed for run ${n}: ${m.left.message}`).pipe(O.annotateLogs({ scope: "voltro:ai-flows" })), {
862
+ })) : D.succeed(void 0)).pipe(D.result);
863
+ if (O.isFailure(m)) return yield* D.logWarning(`flow agent listing failed for run ${n}: ${m.failure.message}`).pipe(D.annotateLogs({ scope: "voltro:ai-flows" })), {
875
864
  object: {},
876
865
  planCostMicroUsd: 0,
877
866
  toolCostMicroUsd: 0,
878
867
  steps: c,
879
868
  error: "flow agent listing failed"
880
869
  };
881
- let h = m.right, g = h ?? [...new Set(r.steps.flatMap((e) => e.type === "agent" && e.agentRef ? [e.agentRef] : []))].map((e) => ({ ref: e })), _ = g.map((e) => e.ref), v = _.length > 0 ? k.Literal(..._) : k.String, ee = qe({
870
+ let h = m.success, g = h ?? [...new Set(r.steps.flatMap((e) => e.type === "agent" && e.agentRef ? [e.agentRef] : []))].map((e) => ({ ref: e })), ee = g.map((e) => e.ref), _ = ee.length > 0 ? k.Literals(ee) : k.String, te = Je({
882
871
  name: "run_agent",
883
872
  description: "Delegate a text task to an allowed sub-agent. Returns the agent's text." + (g.length > 0 ? ` Agents you may call: ${g.map((e) => e.description ? `${e.ref} (${e.description})` : e.ref).join("; ")}.` : ""),
884
873
  input: k.Struct({
885
- agentRef: v,
874
+ agentRef: _,
886
875
  prompt: k.String,
887
- purpose: ln
876
+ purpose: dn
888
877
  }),
889
878
  execute: ({ agentRef: e, prompt: r, purpose: i }) => p({
890
879
  title: `agent:${e}`,
891
880
  type: "agent",
892
881
  agentRef: e,
893
- ...un(i)
894
- }, (i) => O.gen(function* () {
882
+ ...fn(i)
883
+ }, (i) => D.gen(function* () {
895
884
  if (!t.resolveAgent) return d(i, {
896
885
  status: "failed",
897
886
  errorMessage: "no agent resolver configured"
898
887
  }), yield* f(), "ERROR: no agent resolver configured";
899
- let s = yield* H(t.resolveAgent(e, {
888
+ let s = yield* V(t.resolveAgent(e, {
900
889
  runId: n,
901
890
  tenantId: o,
902
891
  ownerId: a
903
- })).pipe(O.map((e) => ({
892
+ })).pipe(D.map((e) => ({
904
893
  ok: !0,
905
894
  a: e
906
- })), O.catchAll((e) => O.succeed({
895
+ })), D.catch((e) => D.succeed({
907
896
  ok: !1,
908
897
  e
909
898
  })));
910
899
  if (!s.ok) return d(i, {
911
900
  status: "failed",
912
901
  errorMessage: s.e.message
913
- }), yield* f(), `ERROR: ${Gt(s.e)}`;
914
- let c = yield* Xt(t, s.a, r, {}).pipe(O.map((e) => ({
902
+ }), yield* f(), `ERROR: ${qt(s.e)}`;
903
+ let c = yield* Qt(t, s.a, r, {}).pipe(D.map((e) => ({
915
904
  ok: !0,
916
905
  r: e
917
- })), O.catchAll((e) => O.succeed({
906
+ })), D.catch((e) => D.succeed({
918
907
  ok: !1,
919
908
  e
920
909
  })));
@@ -925,38 +914,39 @@ var Vt = (e, t = {}) => {
925
914
  errorMessage: e
926
915
  }), yield* f(), `ERROR: ${e}`;
927
916
  }
928
- let u = Zt(c.r.usage, c.r.providerMetadata, s.a.model);
917
+ let u = $t(c.r.usage, c.r.providerMetadata, s.a.model);
929
918
  return l += u, d(i, {
930
919
  status: "succeeded",
931
920
  output: { text: c.r.text },
932
921
  costMicroUsd: u
933
922
  }), yield* f(), c.r.text;
934
923
  }))
935
- }), y = qe({
924
+ }), v = Je({
936
925
  name: "generate_media",
937
926
  description: "Generate image, video, or audio artifacts. Returns every artifact with its URL, role, media type and optional storage reference.",
938
927
  input: k.Struct({
939
- modality: k.Literal("image", "video", "audio"),
928
+ modality: k.Literals([
929
+ "image",
930
+ "video",
931
+ "audio"
932
+ ]),
940
933
  prompt: k.String,
941
- purpose: ln,
934
+ purpose: dn,
942
935
  model: k.optional(k.String),
943
- inputs: k.optional(Rt),
944
- params: k.optional(k.Record({
945
- key: k.String,
946
- value: k.Unknown
947
- }))
936
+ inputs: k.optional(Bt),
937
+ params: k.optional(k.Record(k.String, k.Unknown))
948
938
  }),
949
939
  execute: ({ modality: e, prompt: r, purpose: i, model: s, inputs: c, params: u }) => p({
950
940
  title: `media:${e}`,
951
941
  type: "generate",
952
942
  modality: e,
953
- ...un(i)
954
- }, (i) => O.gen(function* () {
943
+ ...fn(i)
944
+ }, (i) => D.gen(function* () {
955
945
  if (!t.generateMedia) return d(i, {
956
946
  status: "failed",
957
947
  errorMessage: `no media generator for ${e}`
958
948
  }), yield* f(), `ERROR: no media generator configured for ${e}`;
959
- let p = yield* H(t.generateMedia({
949
+ let p = yield* V(t.generateMedia({
960
950
  modality: e,
961
951
  prompt: r,
962
952
  ...s ? { model: s } : {},
@@ -967,10 +957,10 @@ var Vt = (e, t = {}) => {
967
957
  tenantId: o,
968
958
  ownerId: a
969
959
  }
970
- })).pipe(O.map((e) => ({
960
+ })).pipe(D.map((e) => ({
971
961
  ok: !0,
972
962
  r: e
973
- })), O.catchAll((e) => O.succeed({
963
+ })), D.catch((e) => D.succeed({
974
964
  ok: !1,
975
965
  e
976
966
  })));
@@ -978,7 +968,7 @@ var Vt = (e, t = {}) => {
978
968
  status: "failed",
979
969
  errorMessage: p.e.message
980
970
  }), yield* f(), `ERROR: ${p.e.message}`;
981
- let m = yield* qt(p.r);
971
+ let m = yield* Yt(p.r);
982
972
  return m.error ? (d(i, {
983
973
  status: "failed",
984
974
  errorMessage: m.error
@@ -991,27 +981,27 @@ var Vt = (e, t = {}) => {
991
981
  costSource: m.costSource ?? "unpriced"
992
982
  }), yield* f(), { artifacts: m.artifacts });
993
983
  }))
994
- }), te = qe({
984
+ }), ne = Je({
995
985
  name: "pick_structured",
996
986
  description: "Produce a JSON object for a task. Returns the object.",
997
987
  input: k.Struct({
998
988
  prompt: k.String,
999
- purpose: ln,
989
+ purpose: dn,
1000
990
  model: k.optional(k.String)
1001
991
  }),
1002
992
  execute: ({ prompt: e, purpose: n, model: r }) => p({
1003
993
  title: "structured",
1004
994
  type: "structured",
1005
- ...un(n)
1006
- }, (n) => O.gen(function* () {
1007
- let i = yield* Ze({
995
+ ...fn(n)
996
+ }, (n) => D.gen(function* () {
997
+ let i = yield* Qe({
1008
998
  prompt: `${e}\n\nReturn the JSON object serialized as a string in the \`json\` field.`,
1009
- schema: dn,
1010
- ...r ? { provider: G(t, r) } : {}
1011
- }).pipe(O.map((e) => ({
999
+ schema: pn,
1000
+ ...r ? { provider: W(t, r) } : {}
1001
+ }).pipe(D.map((e) => ({
1012
1002
  ok: !0,
1013
1003
  r: e
1014
- })), O.catchAll((e) => O.succeed({
1004
+ })), D.catch((e) => D.succeed({
1015
1005
  ok: !1,
1016
1006
  e
1017
1007
  })));
@@ -1022,9 +1012,9 @@ var Vt = (e, t = {}) => {
1022
1012
  errorMessage: e
1023
1013
  }), yield* f(), { error: e };
1024
1014
  }
1025
- let a = Zt(i.r.usage, i.r.providerMetadata, r);
1015
+ let a = $t(i.r.usage, i.r.providerMetadata, r);
1026
1016
  l += a;
1027
- let o = fn(i.r.object.json);
1017
+ let o = mn(i.r.object.json);
1028
1018
  if (o === void 0) {
1029
1019
  let e = "the model's `json` field is not a JSON object";
1030
1020
  return d(n, {
@@ -1039,46 +1029,46 @@ var Vt = (e, t = {}) => {
1039
1029
  costMicroUsd: a
1040
1030
  }), yield* f(), o;
1041
1031
  }))
1042
- }), ne = {
1043
- run_agent: ee,
1044
- generate_media: y,
1045
- pick_structured: te
1046
- }, b = yield* (t.resolveTools ? H(t.resolveTools(s, {
1032
+ }), re = {
1033
+ run_agent: te,
1034
+ generate_media: v,
1035
+ pick_structured: ne
1036
+ }, y = yield* (t.resolveTools ? V(t.resolveTools(s, {
1047
1037
  runId: n,
1048
1038
  tenantId: o,
1049
1039
  ownerId: a
1050
- }, { provider: () => r.orchestrator?.model ? G(t, r.orchestrator.model) : void 0 })) : O.succeed({})).pipe(O.either);
1051
- if (b._tag === "Left") return yield* O.logWarning(`flow tool resolution failed for run ${n}: ${b.left.message}`).pipe(O.annotateLogs({ scope: "voltro:ai-flows" })), {
1040
+ }, { provider: () => r.orchestrator?.model ? W(t, r.orchestrator.model) : void 0 })) : D.succeed({})).pipe(D.result);
1041
+ if (O.isFailure(y)) return yield* D.logWarning(`flow tool resolution failed for run ${n}: ${y.failure.message}`).pipe(D.annotateLogs({ scope: "voltro:ai-flows" })), {
1052
1042
  object: {},
1053
1043
  planCostMicroUsd: 0,
1054
1044
  toolCostMicroUsd: 0,
1055
1045
  steps: c,
1056
1046
  error: "flow tool resolution failed"
1057
1047
  };
1058
- if (Object.keys(b.right).some((e) => Object.hasOwn(ne, e))) return {
1048
+ if (Object.keys(y.success).some((e) => Object.hasOwn(re, e))) return {
1059
1049
  object: {},
1060
1050
  planCostMicroUsd: 0,
1061
1051
  toolCostMicroUsd: 0,
1062
1052
  steps: c,
1063
1053
  error: "flow tools cannot replace reserved planner tools"
1064
1054
  };
1065
- let re = t.memoryPrefix ? yield* H(t.memoryPrefix(a)).pipe(O.catchAll(() => O.succeed(""))) : "", x = re ? `${re}\n\n${hn(r)}` : hn(r), S = yield* $e({
1066
- system: x,
1067
- prompt: mn(i),
1068
- schema: dn,
1055
+ let ie = t.memoryPrefix ? yield* V(t.memoryPrefix(a)).pipe(D.catch(() => D.succeed(""))) : "", b = ie ? `${ie}\n\n${_n(r)}` : _n(r), x = yield* et({
1056
+ system: b,
1057
+ prompt: gn(i),
1058
+ schema: pn,
1069
1059
  tools: {
1070
- ...b.right,
1060
+ ...y.success,
1071
1061
  ...h?.length === 0 ? {
1072
- generate_media: y,
1073
- pick_structured: te
1074
- } : ne
1062
+ generate_media: v,
1063
+ pick_structured: ne
1064
+ } : re
1075
1065
  },
1076
1066
  maxSteps: r.maxSteps,
1077
- ...r.orchestrator?.model ? { provider: G(t, r.orchestrator.model) } : {}
1078
- }).pipe(O.provideService(Ge, cn), O.map((e) => ({
1067
+ ...r.orchestrator?.model ? { provider: W(t, r.orchestrator.model) } : {}
1068
+ }).pipe(D.provideService(Ke, un), D.map((e) => ({
1079
1069
  ok: !0,
1080
1070
  r: e
1081
- })), O.catchAll((e) => O.succeed({
1071
+ })), D.catch((e) => D.succeed({
1082
1072
  ok: !1,
1083
1073
  e
1084
1074
  })));
@@ -1086,43 +1076,43 @@ var Vt = (e, t = {}) => {
1086
1076
  status: "failed",
1087
1077
  errorMessage: "not finished — the run ended first"
1088
1078
  });
1089
- if (!S.ok) return {
1079
+ if (!x.ok) return {
1090
1080
  object: {},
1091
1081
  planCostMicroUsd: 0,
1092
1082
  toolCostMicroUsd: l,
1093
1083
  steps: c,
1094
- error: String(S.e.message ?? S.e)
1084
+ error: String(x.e.message ?? x.e)
1095
1085
  };
1096
- let C = fn(S.r.object.json);
1086
+ let ae = mn(x.r.object.json);
1097
1087
  return {
1098
- object: C ?? {},
1099
- ...C === void 0 ? { error: "the planner's `json` field is not a JSON object" } : {},
1100
- planCostMicroUsd: Zt(S.r.usage, S.r.providerMetadata, r.orchestrator?.model),
1101
- planCostSource: K(S.r.usage, S.r.providerMetadata, r.orchestrator?.model).costSource,
1088
+ object: ae ?? {},
1089
+ ...ae === void 0 ? { error: "the planner's `json` field is not a JSON object" } : {},
1090
+ planCostMicroUsd: $t(x.r.usage, x.r.providerMetadata, r.orchestrator?.model),
1091
+ planCostSource: G(x.r.usage, x.r.providerMetadata, r.orchestrator?.model).costSource,
1102
1092
  toolCostMicroUsd: l,
1103
1093
  steps: c
1104
1094
  };
1105
1095
  })
1106
- }), l = c.planCostMicroUsd + c.toolCostMicroUsd, u = q([...c.steps, {
1096
+ }), l = c.planCostMicroUsd + c.toolCostMicroUsd, u = K([...c.steps, {
1107
1097
  status: "succeeded",
1108
1098
  costMicroUsd: c.planCostMicroUsd,
1109
1099
  costSource: c.planCostSource ?? "unpriced"
1110
1100
  }]);
1111
- return c.error ? (yield* J(e, n, {
1101
+ return c.error ? (yield* q(e, n, {
1112
1102
  status: "failed",
1113
1103
  steps: c.steps,
1114
1104
  errorMessage: c.error,
1115
- completedAt: W(),
1105
+ completedAt: U(),
1116
1106
  costMicroUsd: l,
1117
1107
  costCompleteness: u
1118
1108
  }), {
1119
1109
  runId: n,
1120
1110
  status: "failed"
1121
- }) : (yield* J(e, n, {
1111
+ }) : (yield* q(e, n, {
1122
1112
  status: "succeeded",
1123
1113
  steps: c.steps,
1124
1114
  output: c.object,
1125
- completedAt: W(),
1115
+ completedAt: U(),
1126
1116
  costMicroUsd: l,
1127
1117
  costCompleteness: u
1128
1118
  }), {
@@ -1130,53 +1120,63 @@ var Vt = (e, t = {}) => {
1130
1120
  status: "succeeded",
1131
1121
  output: c.object
1132
1122
  });
1133
- }), vn = (e, t = {}) => (n, r) => O.gen(function* () {
1134
- let { runId: r, flowRef: i, input: a } = n, o = yield* O.tryPromise(() => e.store.query(N(R).where(A("id", r)).descriptor)).pipe(O.flatMap(k.decodeUnknown(k.Tuple(k.Struct({
1123
+ }), bn = (e, t = {}) => (n, r) => D.gen(function* () {
1124
+ let { runId: r, flowRef: i, input: a } = n, o = yield* D.tryPromise(() => e.store.query(N(R).where(A("id", r)).descriptor)).pipe(D.flatMap(k.decodeUnknownEffect(k.Tuple([k.Struct({
1135
1125
  id: k.Literal(r),
1136
1126
  tenantId: k.NullOr(k.NonEmptyString),
1137
1127
  ownerId: k.optional(k.NullOr(k.String))
1138
- })))), O.either);
1139
- if (o._tag === "Left") return yield* J(e, r, {
1128
+ })]))), D.result);
1129
+ if (O.isFailure(o)) return yield* q(e, r, {
1140
1130
  status: "failed",
1141
1131
  errorMessage: "flow run context unavailable: expected one matching run row with an explicit tenantId (string or null)",
1142
- completedAt: W()
1132
+ completedAt: U()
1143
1133
  }), {
1144
1134
  runId: r,
1145
1135
  status: "failed"
1146
1136
  };
1147
- let { tenantId: s, ownerId: c = null } = o.right[0], l = yield* F({
1137
+ let { tenantId: s, ownerId: c = null } = o.success[0], l = yield* F({
1148
1138
  name: "flow-0-resolve",
1149
1139
  input: { flowRef: i },
1150
1140
  success: k.Struct({
1151
1141
  ir: k.Unknown,
1152
1142
  error: k.optional(k.String)
1153
1143
  }),
1154
- execute: tn(e, i).pipe(O.map((e) => ({ ir: e })), O.catchAll((e) => O.succeed({
1155
- ir: void 0,
1144
+ execute: rn(e, i).pipe(D.flatMap((e) => {
1145
+ for (let t of e.steps) {
1146
+ if (!(t.type === "agent" || t.type === "structured" || t.type === "generate" && (t.modality ?? "text") === "text") || t.params === void 0) continue;
1147
+ let e = D.runSyncExit(zt(t.params));
1148
+ if (Ae.isFailure(e)) return D.succeed({
1149
+ ir: null,
1150
+ error: `step "${t.id}": ${E.squash(e.cause)}`
1151
+ });
1152
+ }
1153
+ return D.succeed({ ir: JSON.parse(JSON.stringify(e)) });
1154
+ }), D.catch((e) => D.succeed({
1155
+ ir: null,
1156
1156
  error: e.message
1157
1157
  })))
1158
1158
  });
1159
- if (l.error || !l.ir) return yield* J(e, r, {
1159
+ if (l.error || !l.ir) return yield* q(e, r, {
1160
1160
  status: "failed",
1161
1161
  errorMessage: l.error ?? "flow not found",
1162
- completedAt: W()
1162
+ completedAt: U()
1163
1163
  }), {
1164
1164
  runId: r,
1165
1165
  status: "failed"
1166
1166
  };
1167
- let u = l.ir, d = u.mode === "agentic" ? yield* _n(e, t, r, u, a, c, s, i) : yield* rn(e, t, r, u, a, {
1167
+ let u = l.ir, d = u.mode === "agentic" ? yield* yn(e, t, r, u, a, c, s, i) : yield* on(e, t, r, u, a, {
1168
1168
  ownerId: c,
1169
1169
  tenantId: s,
1170
1170
  source: n.source
1171
1171
  });
1172
- return d.status === "succeeded" && u.chain && (yield* an(e, r, u, a, d.output ?? {}, n, t)), t.onEvent && (d.status === "succeeded" || d.status === "failed") && (yield* H(t.onEvent({
1172
+ return d.status === "succeeded" && u.chain && (yield* sn(e, r, u, a, d.output ?? {}, n, t)), t.onEvent && (d.status === "succeeded" || d.status === "failed") && (yield* V(t.onEvent({
1173
1173
  kind: d.status,
1174
1174
  runId: r,
1175
1175
  flowName: u.name,
1176
1176
  ownerId: c,
1177
1177
  source: n.source
1178
- })).pipe(O.catchAllCause(() => O.void))), d;
1179
- }), yn = {
1178
+ })).pipe(D.catchCause(() => D.void))), d;
1179
+ }), xn = {
1180
1180
  text: (e) => ({
1181
1181
  type: "generate",
1182
1182
  modality: "text",
@@ -1203,32 +1203,32 @@ var Vt = (e, t = {}) => {
1203
1203
  type: "human",
1204
1204
  ...e
1205
1205
  })
1206
- }, bn = (e) => e.map((e, t) => "id" in e && e.id ? e : {
1206
+ }, Sn = (e) => e.map((e, t) => "id" in e && e.id ? e : {
1207
1207
  id: `step-${t}`,
1208
1208
  ...e
1209
- }), xn = (e) => {
1210
- let t = [], n = Mt(e.steps);
1211
- for (let e of Nt(n)) t.push(`group "${e}" is not contiguous — only CONSECUTIVE steps sharing a group run concurrently, so this would execute as two separate fan-outs`);
1209
+ }), Cn = (e) => {
1210
+ let t = [], n = Nt(e.steps);
1211
+ for (let e of Pt(n)) t.push(`group "${e}" is not contiguous — only CONSECUTIVE steps sharing a group run concurrently, so this would execute as two separate fan-outs`);
1212
1212
  let r = new Set(e.brief.map((e) => e.key));
1213
1213
  for (let e of n) {
1214
1214
  for (let { step: n } of e.steps) {
1215
1215
  n.type === "human" && n.group !== void 0 && t.push(`step "${n.id}" is a human review inside group "${n.group}" — a review SUSPENDS the whole run, which one branch of a fan-out cannot do`);
1216
- for (let i of kt(n.prompt ?? "")) r.has(i) || t.push(e.steps.length > 1 ? `step "${n.id}" references {{${i}}} which is produced inside its OWN group "${n.group}" or does not exist — grouped steps run concurrently, so they cannot read each other` : `step "${n.id}" references {{${i}}} which is not a brief field or a prior step outputKey`);
1216
+ for (let i of At(n.prompt ?? "")) r.has(i) || t.push(e.steps.length > 1 ? `step "${n.id}" references {{${i}}} which is produced inside its OWN group "${n.group}" or does not exist — grouped steps run concurrently, so they cannot read each other` : `step "${n.id}" references {{${i}}} which is not a brief field or a prior step outputKey`);
1217
1217
  for (let [e, i] of Object.entries(n.mediaInputs ?? {})) i.from === "step" && !r.has(i.ref) && t.push(`step "${n.id}" media input "${e}" references "${i.ref}" which is not a brief field or an earlier segment's outputKey`);
1218
1218
  n.when !== void 0 && !r.has(n.when.ref) && t.push(`step "${n.id}" has a when-condition on {{${n.when.ref}}} which is not a brief field or a prior step outputKey — it would never run`);
1219
1219
  }
1220
1220
  for (let { step: t } of e.steps) t.outputKey && r.add(f(t.outputKey));
1221
1221
  }
1222
- if (t.length > 0) throw new Te({
1222
+ if (t.length > 0) throw new De({
1223
1223
  flowRef: e.name,
1224
1224
  message: `flow "${e.name}" has ${t.length} problem(s)`,
1225
1225
  issues: t
1226
1226
  });
1227
- }, Sn = (e) => {
1227
+ }, wn = (e) => {
1228
1228
  let t = d({
1229
1229
  name: e.name,
1230
1230
  mode: e.mode,
1231
- steps: bn(e.steps),
1231
+ steps: Sn(e.steps),
1232
1232
  maxSteps: e.maxSteps,
1233
1233
  brief: e.brief,
1234
1234
  orchestratorModel: e.orchestrator?.model,
@@ -1237,21 +1237,21 @@ var Vt = (e, t = {}) => {
1237
1237
  cadence: e.cadence,
1238
1238
  humanTimeoutMs: e.humanTimeoutMs
1239
1239
  });
1240
- return xn(t), at(t), t;
1241
- }, Cn = async (e, t, n) => {
1242
- let r = k.decodeUnknownSync(je.pipe(k.filter((e) => e.workflowName === "flow.run" && e.id.length > 0)))(n);
1240
+ return Cn(t), ot(t), t;
1241
+ }, Tn = async (e, t, n) => {
1242
+ let r = k.decodeUnknownSync(Me.pipe(k.check(k.makeFilter((e) => e.workflowName === "flow.run" && e.id.length > 0))))(n);
1243
1243
  if (await e.store.update(R.tableName, t, { workflowStart: r }) === null) throw Error("flow start receipt could not be recorded; workflow submission may have succeeded");
1244
1244
  return r;
1245
- }, wn = (e, t, n) => {
1245
+ }, En = (e, t, n) => {
1246
1246
  if (!Number.isFinite(t.getTime())) throw Error("cadence timestamp must be valid");
1247
- return `cron-${it("sha256").update(JSON.stringify([
1247
+ return `cron-${at("sha256").update(JSON.stringify([
1248
1248
  n,
1249
1249
  e,
1250
1250
  Math.floor(t.getTime() / 6e4)
1251
1251
  ])).digest("hex")}`;
1252
- }, Tn = async (e) => {
1252
+ }, Dn = async (e) => {
1253
1253
  let t = [];
1254
- for (let n of st()) n.cadence && (n.cadence.repeats?.length ?? 0) > 0 && t.push({
1254
+ for (let n of ct()) n.cadence && (n.cadence.repeats?.length ?? 0) > 0 && t.push({
1255
1255
  tenantId: e.request.subject.tenantId,
1256
1256
  flowRef: n.name,
1257
1257
  cadence: n.cadence,
@@ -1265,8 +1265,8 @@ var Vt = (e, t = {}) => {
1265
1265
  defaultInput: r.cadence.defaultInput ?? {}
1266
1266
  });
1267
1267
  return t;
1268
- }, En = async (e, t = /* @__PURE__ */ new Date()) => {
1269
- let r = [], i = 0, a = [], o = e.workflows ? await pt(e) : {
1268
+ }, On = async (e, t = /* @__PURE__ */ new Date()) => {
1269
+ let r = [], i = 0, a = [], o = e.workflows ? await mt(e) : {
1270
1270
  examined: 0,
1271
1271
  accepted: 0,
1272
1272
  notExecuted: 0,
@@ -1274,11 +1274,11 @@ var Vt = (e, t = {}) => {
1274
1274
  failures: []
1275
1275
  };
1276
1276
  a.push(...o.failures.map((e) => Error(`flow run ${e.runId}: start reconciliation failed`, { cause: e.cause })));
1277
- let s = await Tn(e);
1277
+ let s = await Dn(e);
1278
1278
  for (let o of s) {
1279
- if (!De(o.cadence, t)) continue;
1279
+ if (!ke(o.cadence, t)) continue;
1280
1280
  i += 1;
1281
- let s = wn(o.flowRef, t, o.tenantId), c = `run-${s}`;
1281
+ let s = En(o.flowRef, t, o.tenantId), c = `run-${s}`;
1282
1282
  try {
1283
1283
  if (!e.workflows) throw Error("workflow runtime unavailable; no cadence start was submitted");
1284
1284
  (await e.transaction(async (e) => {
@@ -1295,11 +1295,11 @@ var Vt = (e, t = {}) => {
1295
1295
  }, { conflictColumns: ["id"] });
1296
1296
  let r = await e.store.select("_voltro_ai_flow_runs").where("id", c).first();
1297
1297
  if (!r) throw Error("cadence run is not readable after persistence");
1298
- let i = k.decodeUnknownSync(n.payloadSchema.pipe(k.filter((e) => e.runId === c && e.flowRef === o.flowRef && e.requestId === s && e.source === "cron")))({
1298
+ let i = k.decodeUnknownSync(n.payloadSchema.pipe(k.check(k.makeFilter((e) => e.runId === c && e.flowRef === o.flowRef && e.requestId === s && e.source === "cron"))))({
1299
1299
  ...r,
1300
1300
  runId: r.id
1301
1301
  });
1302
- return Cn(e, c, await t.start("flow.run", i));
1302
+ return Tn(e, c, await t.start("flow.run", i));
1303
1303
  }, o.tenantId === null ? void 0 : { tenantId: o.tenantId })).status === "running" && r.push(s);
1304
1304
  } catch (e) {
1305
1305
  a.push(e);
@@ -1311,42 +1311,53 @@ var Vt = (e, t = {}) => {
1311
1311
  started: r,
1312
1312
  reconciled: o
1313
1313
  };
1314
- }, Y = (e) => k.optionalWith(e, { exact: !0 }), Dn = k.Int.pipe(k.positive(), k.lessThanOrEqualTo(2 ** 53 - 1)), On = k.Int.pipe(k.between(-(2 ** 53 - 1), 2 ** 53 - 1)), kn = k.TemplateLiteral(k.Number, "x", k.Number).pipe(k.pattern(/^[1-9]\d*x[1-9]\d*$/)), An = k.TemplateLiteral(k.Number, ":", k.Number).pipe(k.pattern(/^[1-9]\d*:[1-9]\d*$/)), jn = k.Struct({
1315
- n: Y(Dn),
1316
- seed: Y(On),
1317
- size: Y(kn),
1318
- aspectRatio: Y(An),
1319
- providerOptions: Y(B)
1320
- }), Mn = k.Struct({
1321
- voice: Y(k.NonEmptyString),
1322
- outputFormat: Y(k.NonEmptyString),
1323
- instructions: Y(k.String),
1324
- speed: Y(k.Finite.pipe(k.positive())),
1325
- language: Y(k.NonEmptyString),
1326
- providerOptions: Y(B)
1327
- }), Nn = k.Struct({
1328
- aspectRatio: Y(An),
1329
- durationSeconds: Y(k.Finite.pipe(k.positive())),
1330
- resolution: Y(kn),
1331
- fps: Y(k.Finite.pipe(k.positive())),
1332
- seed: Y(On),
1333
- generateAudio: Y(k.Boolean),
1334
- maxInlineBytes: Y(Dn),
1335
- providerOptions: Y(B)
1336
- }), Pn = (e, t, n) => O.try({
1314
+ }, J = (e) => k.optionalKey(e), kn = k.Int.pipe(k.check(k.isGreaterThan(0)), k.check(k.isLessThanOrEqualTo(2 ** 53 - 1))), An = k.Int.pipe(k.check(k.isBetween({
1315
+ minimum: -(2 ** 53 - 1),
1316
+ maximum: 2 ** 53 - 1
1317
+ }))), jn = k.TemplateLiteral([
1318
+ k.Number,
1319
+ "x",
1320
+ k.Number
1321
+ ]).pipe(k.check(k.isPattern(/^[1-9]\d*x[1-9]\d*$/))), Mn = k.TemplateLiteral([
1322
+ k.Number,
1323
+ ":",
1324
+ k.Number
1325
+ ]).pipe(k.check(k.isPattern(/^[1-9]\d*:[1-9]\d*$/))), Nn = k.Struct({
1326
+ n: J(kn),
1327
+ seed: J(An),
1328
+ size: J(jn),
1329
+ aspectRatio: J(Mn),
1330
+ providerOptions: J(z)
1331
+ }), Pn = k.Struct({
1332
+ voice: J(k.NonEmptyString),
1333
+ outputFormat: J(k.NonEmptyString),
1334
+ instructions: J(k.String),
1335
+ speed: J(k.Finite.pipe(k.check(k.isGreaterThan(0)))),
1336
+ language: J(k.NonEmptyString),
1337
+ providerOptions: J(z)
1338
+ }), Fn = k.Struct({
1339
+ aspectRatio: J(Mn),
1340
+ durationSeconds: J(k.Finite.pipe(k.check(k.isGreaterThan(0)))),
1341
+ resolution: J(jn),
1342
+ fps: J(k.Finite.pipe(k.check(k.isGreaterThan(0)))),
1343
+ seed: J(An),
1344
+ generateAudio: J(k.Boolean),
1345
+ maxInlineBytes: J(kn),
1346
+ providerOptions: J(z)
1347
+ }), Y = (e, t, n) => D.try({
1337
1348
  try: () => k.decodeUnknownSync(e, { onExcessProperty: "error" })(t === void 0 ? {} : t),
1338
1349
  catch: () => `invalid ${n} media params: check the built-in adapter's supported options and value ranges`
1339
- }), Fn = (e) => Pn(jn, e, "image"), In = (e) => Pn(Mn, e, "audio"), Ln = (e) => Pn(Nn, e, "video"), Rn = (e) => ({
1350
+ }), In = (e) => Y(Nn, e, "image"), Ln = (e) => Y(Pn, e, "audio"), Rn = (e) => Y(Fn, e, "video"), zn = (e) => ({
1340
1351
  name: "gateway",
1341
1352
  model: e
1342
- }), zn = (e) => Math.round(e * 1e6), X = (e, t, n) => {
1343
- let r = Ye(t);
1353
+ }), Bn = (e) => Math.round(e * 1e6), X = (e, t, n) => {
1354
+ let r = Xe(t);
1344
1355
  if (typeof r == "number") return {
1345
- costMicroUsd: zn(r),
1356
+ costMicroUsd: Bn(r),
1346
1357
  costSource: "gateway"
1347
1358
  };
1348
1359
  if (e) {
1349
- let t = Je(e, { model: n ?? "unknown" });
1360
+ let t = Ye(e, { model: n ?? "unknown" });
1350
1361
  return {
1351
1362
  costMicroUsd: t.costMicroUsd ?? 0,
1352
1363
  costSource: t.costSource ?? "unpriced"
@@ -1358,7 +1369,7 @@ var Vt = (e, t = {}) => {
1358
1369
  };
1359
1370
  }, Z = (e) => {
1360
1371
  if (e === void 0) return { status: "unreported" };
1361
- let [t, n, r] = rt(e) ? [
1372
+ let [t, n, r] = it(e) ? [
1362
1373
  e.unit,
1363
1374
  e.input,
1364
1375
  e.output
@@ -1376,18 +1387,18 @@ var Vt = (e, t = {}) => {
1376
1387
  }, Q = (e, t, n) => ({
1377
1388
  ...X(e, t, n),
1378
1389
  usage: Z(e)
1379
- }), Bn = (e, t) => (n) => {
1380
- let r = n.model, i = (e) => t?.resolveModel?.(e) ?? Rn(e);
1381
- return O.gen(function* () {
1382
- let t = yield* Ht(n.modality, n.inputs).pipe(O.mapError((e) => new E({
1390
+ }), Vn = (e, t) => (n) => {
1391
+ let r = n.model, i = (e) => t?.resolveModel?.(e) ?? zn(e);
1392
+ return D.gen(function* () {
1393
+ let t = yield* Wt(n.modality, n.inputs).pipe(D.mapError((e) => new w({
1383
1394
  capability: `media:${n.modality}`,
1384
1395
  message: e
1385
1396
  })));
1386
1397
  if (n.modality === "image") {
1387
- let a = yield* Fn(n.params).pipe(O.mapError((e) => new E({
1398
+ let a = yield* In(n.params).pipe(D.mapError((e) => new w({
1388
1399
  capability: "media:image",
1389
1400
  message: e
1390
- }))), o = t.referenceImageUrl, s = t.maskImageUrl, c = yield* Xe({
1401
+ }))), o = t.referenceImageUrl, s = t.maskImageUrl, c = yield* Ze({
1391
1402
  ...a,
1392
1403
  prompt: n.prompt,
1393
1404
  ...o === void 0 ? {} : { inputs: {
@@ -1396,7 +1407,7 @@ var Vt = (e, t = {}) => {
1396
1407
  } },
1397
1408
  ...r ? { provider: i(r) } : {}
1398
1409
  });
1399
- if (c.images.length === 0) return yield* O.fail(new E({
1410
+ if (c.images.length === 0) return yield* D.fail(new w({
1400
1411
  capability: "media:image",
1401
1412
  message: "no image produced"
1402
1413
  }));
@@ -1406,7 +1417,7 @@ var Vt = (e, t = {}) => {
1406
1417
  data: i.data,
1407
1418
  mediaType: i.mediaType,
1408
1419
  run: n.run
1409
- }).pipe(O.mapError(() => new E({
1420
+ }).pipe(D.mapError(() => new w({
1410
1421
  capability: "media:image",
1411
1422
  message: "media persistence failed",
1412
1423
  receipt: Q(c.usage, c.providerMetadata, r)
@@ -1426,10 +1437,10 @@ var Vt = (e, t = {}) => {
1426
1437
  };
1427
1438
  }
1428
1439
  if (n.modality === "audio") {
1429
- let t = yield* In(n.params).pipe(O.mapError((e) => new E({
1440
+ let t = yield* Ln(n.params).pipe(D.mapError((e) => new w({
1430
1441
  capability: "media:audio",
1431
1442
  message: e
1432
- }))), a = yield* et({
1443
+ }))), a = yield* tt({
1433
1444
  ...t,
1434
1445
  text: n.prompt,
1435
1446
  ...r ? { provider: i(r) } : {}
@@ -1437,7 +1448,7 @@ var Vt = (e, t = {}) => {
1437
1448
  data: a.audio.data,
1438
1449
  mediaType: a.audio.mediaType,
1439
1450
  run: n.run
1440
- }).pipe(O.mapError(() => new E({
1451
+ }).pipe(D.mapError(() => new w({
1441
1452
  capability: "media:audio",
1442
1453
  message: "media persistence failed",
1443
1454
  receipt: Q(a.usage, a.providerMetadata, r)
@@ -1453,10 +1464,10 @@ var Vt = (e, t = {}) => {
1453
1464
  usage: Z(a.usage)
1454
1465
  };
1455
1466
  }
1456
- let { maxInlineBytes: a, providerOptions: o, ...s } = yield* Ln(n.params).pipe(O.mapError((e) => new E({
1467
+ let { maxInlineBytes: a, providerOptions: o, ...s } = yield* Rn(n.params).pipe(D.mapError((e) => new w({
1457
1468
  capability: "media:video",
1458
1469
  message: e
1459
- }))), c = yield* nt({
1470
+ }))), c = yield* rt({
1460
1471
  prompt: n.prompt,
1461
1472
  inputs: {
1462
1473
  ...t.referenceImageUrl === void 0 ? {} : { image: t.referenceImageUrl },
@@ -1474,7 +1485,7 @@ var Vt = (e, t = {}) => {
1474
1485
  ...o === void 0 ? {} : { providerOptions: o },
1475
1486
  ...a === void 0 ? {} : { maxInlineBytes: a }
1476
1487
  }), l;
1477
- if (c.video.url) l = e.ingestUrl ? yield* e.ingestUrl(c.video.url, n.run).pipe(O.mapError(() => new E({
1488
+ if (c.video.url) l = e.ingestUrl ? yield* e.ingestUrl(c.video.url, n.run).pipe(D.mapError(() => new w({
1478
1489
  capability: "media:video",
1479
1490
  message: "media persistence failed",
1480
1491
  receipt: Q(c.usage, c.providerMetadata, r)
@@ -1483,12 +1494,12 @@ var Vt = (e, t = {}) => {
1483
1494
  data: c.video.data,
1484
1495
  mediaType: c.video.mediaType,
1485
1496
  run: n.run
1486
- }).pipe(O.mapError(() => new E({
1497
+ }).pipe(D.mapError(() => new w({
1487
1498
  capability: "media:video",
1488
1499
  message: "media persistence failed",
1489
1500
  receipt: Q(c.usage, c.providerMetadata, r)
1490
1501
  })));
1491
- else return yield* O.fail(new E({
1502
+ else return yield* D.fail(new w({
1492
1503
  capability: "media:video",
1493
1504
  message: "no video produced"
1494
1505
  }));
@@ -1502,23 +1513,23 @@ var Vt = (e, t = {}) => {
1502
1513
  ...X(c.usage, c.providerMetadata, r),
1503
1514
  usage: Z(c.usage)
1504
1515
  };
1505
- }).pipe(O.catchAll((e) => e instanceof E ? O.fail(e) : O.fail(new E({
1516
+ }).pipe(D.catch((e) => e instanceof w ? D.fail(e) : D.fail(new w({
1506
1517
  capability: `media:${n.modality}`,
1507
1518
  message: String(e.message ?? e)
1508
1519
  }))));
1509
- }, Vn = () => globalThis.crypto?.randomUUID?.() ?? `req-${Date.now().toString(36)}`, Hn = (e) => e.request?.subject?.id ?? null, $ = (e, t) => O.promise(() => e.store.query(N(R).where(A("id", t)).descriptor)).pipe(O.map((e) => e[0])), Un = (e) => O.sync(() => {
1520
+ }, Hn = () => globalThis.crypto?.randomUUID?.() ?? `req-${Date.now().toString(36)}`, Un = (e) => e.request?.subject?.id ?? null, $ = (e, t) => D.promise(() => e.store.query(N(R).where(A("id", t)).descriptor)).pipe(D.map((e) => e[0])), Wn = (e) => D.sync(() => {
1510
1521
  let t = e.workflows;
1511
1522
  if (!t) throw Error("workflow runtime unavailable; no flow start was submitted");
1512
1523
  return t;
1513
- }), Wn = (t, n) => O.gen(function* () {
1514
- yield* Un(t);
1515
- let r = yield* tn(t, n.flowRef), i = n.input ?? {}, a = r.brief.filter((e) => e.required && e.type !== "boolean" && (i[e.key] === void 0 || i[e.key] === null || i[e.key] === "")).map((e) => e.key);
1516
- if (a.length > 0) return yield* O.fail(new be({
1524
+ }), Gn = (t, n) => D.gen(function* () {
1525
+ yield* Wn(t);
1526
+ let r = yield* rn(t, n.flowRef), i = n.input ?? {}, a = r.brief.filter((e) => e.required && e.type !== "boolean" && (i[e.key] === void 0 || i[e.key] === null || i[e.key] === "")).map((e) => e.key);
1527
+ if (a.length > 0) return yield* D.fail(new Se({
1517
1528
  missing: a,
1518
1529
  message: `missing required brief field(s): ${a.join(", ")}`
1519
1530
  }));
1520
- let o = Vn(), s = `run-${o}`, c = n.source ?? "manual";
1521
- return yield* O.promise(() => t.transaction(async (t) => {
1531
+ let o = Hn(), s = `run-${o}`, c = n.source ?? "manual";
1532
+ return yield* D.promise(() => t.transaction(async (t) => {
1522
1533
  let a = t.workflows;
1523
1534
  if (!a) throw Error("workflow runtime unavailable in transaction; no flow start was submitted");
1524
1535
  await t.store.insert(R.tableName, {
@@ -1530,74 +1541,74 @@ var Vt = (e, t = {}) => {
1530
1541
  source: c,
1531
1542
  requestId: o,
1532
1543
  input: i,
1533
- ownerId: Hn(t)
1544
+ ownerId: Un(t)
1534
1545
  });
1535
- let l = await Cn(t, s, await a.start(e, {
1546
+ let l = await Tn(t, s, await a.start(e, {
1536
1547
  runId: s,
1537
1548
  flowRef: n.flowRef,
1538
1549
  input: i,
1539
1550
  source: c,
1540
1551
  requestId: o
1541
1552
  }));
1542
- return x.make({
1553
+ return b.make({
1543
1554
  runId: s,
1544
1555
  requestId: o,
1545
1556
  admission: l
1546
1557
  });
1547
1558
  }));
1548
- }), Gn = (t, r) => O.gen(function* () {
1549
- return yield* Un(t), yield* O.tryPromise({
1559
+ }), Kn = (t, r) => D.gen(function* () {
1560
+ return yield* Wn(t), yield* D.tryPromise({
1550
1561
  try: () => t.transaction(async (t) => {
1551
1562
  let i = t.workflows;
1552
1563
  if (!i) throw Error("workflow runtime unavailable in transaction; no flow start was submitted");
1553
1564
  let a = (await t.store.query(N(R).where(A("id", r.runId)).descriptor))[0];
1554
- if (!a) throw new D({
1565
+ if (!a) throw new T({
1555
1566
  runId: r.runId,
1556
1567
  message: "run not found"
1557
1568
  });
1558
1569
  let o = a.requestId;
1559
1570
  if (typeof o != "string" || o.length === 0) throw Error("stored flow run has no valid requestId; retry refused without changing the run");
1560
- let s = k.decodeUnknownEither(n.payloadSchema.pipe(k.filter((e) => e.runId === r.runId && e.flowRef.length > 0)))({
1571
+ let s = k.decodeUnknownResult(n.payloadSchema.pipe(k.check(k.makeFilter((e) => e.runId === r.runId && e.flowRef.length > 0))))({
1561
1572
  ...a,
1562
1573
  runId: a.id
1563
1574
  });
1564
- if (s._tag === "Left") throw Error("stored workflow payload is incomplete or invalid; retry refused without changing the run");
1565
- let c = await Cn(t, r.runId, await i.start(e, s.right));
1566
- return x.make({
1575
+ if (O.isFailure(s)) throw Error("stored workflow payload is incomplete or invalid; retry refused without changing the run");
1576
+ let c = await Tn(t, r.runId, await i.start(e, s.success));
1577
+ return b.make({
1567
1578
  runId: r.runId,
1568
1579
  requestId: o,
1569
1580
  admission: c
1570
1581
  });
1571
1582
  }),
1572
1583
  catch: (e) => e
1573
- }).pipe(O.catchAll((e) => e instanceof D ? O.fail(e) : O.die(e)));
1574
- }), Kn = (t, r) => O.gen(function* () {
1584
+ }).pipe(D.catch((e) => e instanceof T ? D.fail(e) : D.die(e)));
1585
+ }), qn = (t, r) => D.gen(function* () {
1575
1586
  let i = yield* $(t, r.runId);
1576
- if (!i) return yield* O.fail(new D({
1587
+ if (!i) return yield* D.fail(new T({
1577
1588
  runId: r.runId,
1578
1589
  message: "run not found"
1579
1590
  }));
1580
- if (qn(i.status)) return T.make({
1591
+ if (Jn(i.status)) return C.make({
1581
1592
  runId: r.runId,
1582
1593
  status: i.status,
1583
1594
  engine: "not-requested",
1584
1595
  control: null
1585
1596
  });
1586
1597
  let a = (/* @__PURE__ */ new Date()).toISOString();
1587
- yield* O.promise(() => t.store.updateMany(R.tableName, {
1598
+ yield* D.promise(() => t.store.updateMany(R.tableName, {
1588
1599
  status: "cancelling",
1589
1600
  cancelledAt: a
1590
- }, { where: Pe(A("id", r.runId), Le("status", [
1601
+ }, { where: Fe(A("id", r.runId), Re("status", [
1591
1602
  "pending",
1592
1603
  "running",
1593
1604
  "waiting"
1594
1605
  ])) }));
1595
1606
  let o = yield* $(t, r.runId);
1596
- if (!o) return yield* O.fail(new D({
1607
+ if (!o) return yield* D.fail(new T({
1597
1608
  runId: r.runId,
1598
1609
  message: "run not found"
1599
1610
  }));
1600
- if (qn(o.status)) return T.make({
1611
+ if (Jn(o.status)) return C.make({
1601
1612
  runId: r.runId,
1602
1613
  status: o.status,
1603
1614
  engine: "not-requested",
@@ -1607,119 +1618,113 @@ var Vt = (e, t = {}) => {
1607
1618
  runId: k.Literal(r.runId),
1608
1619
  flowRef: k.NonEmptyString,
1609
1620
  requestId: k.NonEmptyString,
1610
- input: k.Record({
1611
- key: k.String,
1612
- value: k.Unknown
1613
- }),
1614
- source: k.Literal("manual", "cron")
1621
+ input: k.Record(k.String, k.Unknown),
1622
+ source: k.Literals(["manual", "cron"])
1615
1623
  }))({
1616
1624
  ...i,
1617
1625
  runId: i.id
1618
- }), l = s === void 0 || c._tag === "None" ? null : yield* O.flatMap(n.executionId(c.value), (t) => O.tryPromise(async () => {
1619
- let n = k.decodeUnknownSync(Ae)(await s.cancel(e, t));
1626
+ }), l = s === void 0 || c._tag === "None" ? null : yield* D.flatMap(n.executionId(c.value), (t) => D.tryPromise(async () => {
1627
+ let n = k.decodeUnknownSync(je)(await s.cancel(e, t));
1620
1628
  if (n.operation !== "cancel" || n.snapshot.workflowName !== "flow.run" || n.snapshot.executionId !== t) throw Error("workflow cancellation receipt does not match the flow execution");
1621
1629
  return n;
1622
- })).pipe(O.catchAll(() => O.succeed(null))), u = l === null ? s === void 0 || c._tag === "None" ? "unreachable" : "unknown" : l.snapshot.status === "cancelled" && (l.kind === "confirmed" || l.kind === "already-terminal") ? "cancelled" : l.kind === "accepted" ? "accepted" : l.kind === "already-terminal" ? "already-terminal" : "unknown", d = Pe(A("id", r.runId), A("status", "cancelling"), A("cancelledAt", o.cancelledAt));
1623
- if (u === "cancelled") yield* O.promise(() => t.store.updateMany(R.tableName, {
1630
+ })).pipe(D.catch(() => D.succeed(null))), u = l === null ? s === void 0 || c._tag === "None" ? "unreachable" : "unknown" : l.snapshot.status === "cancelled" && (l.kind === "confirmed" || l.kind === "already-terminal") ? "cancelled" : l.kind === "accepted" ? "accepted" : l.kind === "already-terminal" ? "already-terminal" : "unknown", d = Fe(A("id", r.runId), A("status", "cancelling"), A("cancelledAt", o.cancelledAt));
1631
+ if (u === "cancelled") yield* D.promise(() => t.store.updateMany(R.tableName, {
1624
1632
  status: "cancelled",
1625
1633
  completedAt: o.completedAt ?? (/* @__PURE__ */ new Date()).toISOString()
1626
1634
  }, { where: d }));
1627
1635
  else if (l?.kind === "already-terminal") {
1628
1636
  let e = k.decodeUnknownOption(n.successSchema)(l.snapshot.output), i = l.snapshot.status === "failed" ? "failed" : e._tag === "Some" && e.value.runId === r.runId && e.value.status !== "waiting" ? e.value.status : void 0;
1629
- i !== void 0 && (yield* O.promise(() => t.store.updateMany(R.tableName, {
1637
+ i !== void 0 && (yield* D.promise(() => t.store.updateMany(R.tableName, {
1630
1638
  status: i,
1631
1639
  completedAt: o.completedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
1632
1640
  ...i === "cancelled" ? {} : { cancelledAt: null }
1633
1641
  }, { where: d })));
1634
1642
  }
1635
1643
  let f = yield* $(t, r.runId);
1636
- return f ? yield* k.decodeUnknown(T)({
1644
+ return f ? yield* k.decodeUnknownEffect(C)({
1637
1645
  runId: r.runId,
1638
1646
  status: f.status,
1639
1647
  engine: u,
1640
1648
  control: l
1641
- }).pipe(O.orDie) : yield* O.fail(new D({
1649
+ }).pipe(D.orDie) : yield* D.fail(new T({
1642
1650
  runId: r.runId,
1643
1651
  message: "run not found"
1644
1652
  }));
1645
- }), qn = (e) => e === "succeeded" || e === "failed" || e === "cancelled", Jn = (e) => {
1653
+ }), Jn = (e) => e === "succeeded" || e === "failed" || e === "cancelled", Yn = (e) => {
1646
1654
  let t = e.steps?.filter((e) => e.status === "waiting"), n = t?.[0];
1647
1655
  if (t?.length !== 1 || n?.type !== "human" || !Number.isSafeInteger(n.id) || n.id < 0) throw Error("expected exactly one waiting human step with a nonnegative integer index");
1648
1656
  return n.id;
1649
- }, Yn = (t, i) => O.gen(function* () {
1650
- let a = (e, t) => new we({
1657
+ }, Xn = (t, i) => D.gen(function* () {
1658
+ let a = (e, t) => new Ee({
1651
1659
  runId: i.runId,
1652
1660
  reason: e,
1653
1661
  message: t
1654
- }), o = yield* k.decodeUnknown(se, { onExcessProperty: "error" })(i).pipe(O.mapError(() => a("invalid-response", "review response requires runId, displayed stepIndex and a valid response")));
1655
- if (o.response.decision === void 0 && o.response.text === void 0 && o.response.value === void 0) return yield* O.fail(a("invalid-response", "review response must contain a decision, text or value"));
1662
+ }), o = yield* k.decodeUnknownEffect(le, { onExcessProperty: "error" })(i).pipe(D.mapError(() => a("invalid-response", "review response requires runId, displayed stepIndex and a valid response")));
1663
+ if (o.response.decision === void 0 && o.response.text === void 0 && o.response.value === void 0) return yield* D.fail(a("invalid-response", "review response must contain a decision, text or value"));
1656
1664
  let s = t.workflows;
1657
- if (!s) return yield* O.fail(a("runtime-unavailable", "workflow runtime unavailable; review was not sent"));
1665
+ if (!s) return yield* D.fail(a("runtime-unavailable", "workflow runtime unavailable; review was not sent"));
1658
1666
  let c = yield* $(t, i.runId);
1659
- if (!c) return yield* O.fail(new D({
1667
+ if (!c) return yield* D.fail(new T({
1660
1668
  runId: i.runId,
1661
1669
  message: "run not found"
1662
1670
  }));
1663
1671
  let l = c.status;
1664
- if (l !== "waiting") return yield* O.fail(new Se({
1672
+ if (l !== "waiting") return yield* D.fail(new we({
1665
1673
  runId: i.runId,
1666
1674
  status: l ?? "unknown",
1667
1675
  message: `run is "${l}", not awaiting a response`
1668
1676
  }));
1669
- let u = yield* O.try({
1670
- try: () => Jn(c),
1677
+ let u = yield* D.try({
1678
+ try: () => Yn(c),
1671
1679
  catch: () => a("invalid-run", "stored run has no unambiguous waiting review")
1672
1680
  });
1673
- if (u !== o.stepIndex) return yield* O.fail(new Se({
1681
+ if (u !== o.stepIndex) return yield* D.fail(new we({
1674
1682
  runId: i.runId,
1675
1683
  status: l,
1676
1684
  message: "this review is no longer waiting; reload the run before answering"
1677
1685
  }));
1678
- let d = yield* k.decodeUnknown(k.Struct({
1686
+ let d = yield* k.decodeUnknownEffect(k.Struct({
1679
1687
  runId: k.Literal(i.runId),
1680
1688
  flowRef: k.NonEmptyString,
1681
1689
  requestId: k.NonEmptyString,
1682
- input: k.Record({
1683
- key: k.String,
1684
- value: k.Unknown
1685
- }),
1686
- source: k.Literal("manual", "cron")
1690
+ input: k.Record(k.String, k.Unknown),
1691
+ source: k.Literals(["manual", "cron"])
1687
1692
  }))({
1688
1693
  ...c,
1689
1694
  runId: c.id
1690
- }).pipe(O.mapError(() => a("invalid-run", "stored workflow payload is incomplete; review was not sent"))), f = yield* n.executionId(d), p = {
1695
+ }).pipe(D.mapError(() => a("invalid-run", "stored workflow payload is incomplete; review was not sent"))), f = yield* n.executionId(d), p = {
1691
1696
  ...o.response,
1692
1697
  respondedAt: (/* @__PURE__ */ new Date()).toISOString()
1693
- }, m = yield* O.tryPromise({
1698
+ }, m = yield* D.tryPromise({
1694
1699
  try: () => s.signal({
1695
1700
  workflowName: e,
1696
1701
  executionId: f
1697
1702
  }, r(u), p),
1698
1703
  catch: () => a("delivery-unknown", "review delivery was not confirmed; observe the run before retrying")
1699
- }), h = yield* k.decodeUnknown(k.Struct({ eventId: k.NonEmptyString }))(m).pipe(O.mapError(() => a("delivery-unknown", "workflow runtime returned no valid review delivery receipt")));
1700
- return yield* k.decodeUnknown(me)({
1704
+ }), h = yield* k.decodeUnknownEffect(k.Struct({ eventId: k.NonEmptyString }))(m).pipe(D.mapError(() => a("delivery-unknown", "workflow runtime returned no valid review delivery receipt")));
1705
+ return yield* k.decodeUnknownEffect(ge)({
1701
1706
  runId: i.runId,
1702
1707
  stepIndex: u,
1703
1708
  executionId: f,
1704
1709
  eventId: h.eventId,
1705
1710
  status: "accepted"
1706
- }).pipe(O.mapError(() => a("delivery-unknown", "workflow runtime returned no valid review delivery receipt")));
1707
- }), Xn = (e, t) => O.promise(() => e.store.query(N(L).where(A("id", t.id)).descriptor)).pipe(O.map((e) => e[0])), Zn = (e) => O.promise(() => e.store.query(N(L).descriptor)), Qn = (e, t) => O.promise(() => e.store.insert(L.tableName, {
1708
- id: t.id ?? `flow-${Vn()}`,
1711
+ }).pipe(D.mapError(() => a("delivery-unknown", "workflow runtime returned no valid review delivery receipt")));
1712
+ }), Zn = (e, t) => D.promise(() => e.store.query(N(L).where(A("id", t.id)).descriptor)).pipe(D.map((e) => e[0])), Qn = (e) => D.promise(() => e.store.query(N(L).descriptor)), $n = (e, t) => D.promise(() => e.store.insert(L.tableName, {
1713
+ id: t.id ?? `flow-${Hn()}`,
1709
1714
  ...t
1710
- })), $n = (e, t) => O.promise(() => e.store.update(L.tableName, t.id, t.patch)), er = (e, t) => O.promise(() => e.store.delete(L.tableName, t.id)), tr = "aiFlows", nr = (e = {}) => {
1711
- let t = Ne({
1712
- base: tr,
1715
+ })), er = (e, t) => D.promise(() => e.store.update(L.tableName, t.id, t.patch)), tr = (e, t) => D.promise(() => e.store.delete(L.tableName, t.id)), nr = "aiFlows", rr = (e = {}) => {
1716
+ let t = Pe({
1717
+ base: nr,
1713
1718
  alias: e.alias
1714
1719
  });
1715
- xt(e.humanReviewTimeoutMs === void 0 ? {} : { humanReviewTimeoutMs: e.humanReviewTimeoutMs }), ze({
1720
+ St(e.humanReviewTimeoutMs === void 0 ? {} : { humanReviewTimeoutMs: e.humanReviewTimeoutMs }), Be({
1716
1721
  source: "plugin",
1717
1722
  table: R.tableName,
1718
1723
  timeColumn: "createdAt",
1719
- ttlMs: e.runsTtlMs ?? wt(process.env.VOLTRO_AI_FLOW_RUNS_TTL_HOURS, 2160),
1720
- envVar: _t,
1724
+ ttlMs: e.runsTtlMs ?? Tt(process.env.VOLTRO_AI_FLOW_RUNS_TTL_HOURS, 2160),
1725
+ envVar: vt,
1721
1726
  label: "ai flow runs",
1722
- where: Le("status", [
1727
+ where: Re("status", [
1723
1728
  "succeeded",
1724
1729
  "failed",
1725
1730
  "cancelled"
@@ -1732,7 +1737,7 @@ var Vt = (e, t = {}) => {
1732
1737
  kind: "json",
1733
1738
  status: e,
1734
1739
  data: { error: t }
1735
- }), o = (e, t, n) => O.promise(async () => {
1740
+ }), o = (e, t, n) => D.promise(async () => {
1736
1741
  let o = r.current;
1737
1742
  if (!o) return a(503, "store not bound yet");
1738
1743
  let s = await o.query({
@@ -1767,7 +1772,7 @@ var Vt = (e, t = {}) => {
1767
1772
  rows: s,
1768
1773
  take: t
1769
1774
  });
1770
- }).pipe(O.catchAllCause(() => O.succeed(a(500, "query failed")))), s = (e, t) => {
1775
+ }).pipe(D.catchCause(() => D.succeed(a(500, "query failed")))), s = (e, t) => {
1771
1776
  let r = /[?&]take=(\d+)/.exec(e)?.[1], i = r === void 0 ? t : Number(r);
1772
1777
  return Math.min(n, Math.max(1, Number.isFinite(i) ? i : t));
1773
1778
  }, c = [{
@@ -1775,17 +1780,17 @@ var Vt = (e, t = {}) => {
1775
1780
  path: "/flows",
1776
1781
  scope: "process",
1777
1782
  description: "List flow definitions (`?take=` up to the configured max).",
1778
- handler: (e) => O.promise(async () => {
1783
+ handler: (e) => D.promise(async () => {
1779
1784
  let t = r.current;
1780
1785
  if (!t) return a(503, "store not bound yet");
1781
- let o = s(e.url, Math.min(200, n)), c = [...st()].sort((e, t) => e.name < t.name ? -1 : +(e.name > t.name)), l = c.slice(0, o).map((e) => ({
1786
+ let o = s(e.url, Math.min(200, n)), c = [...ct()].sort((e, t) => e.name < t.name ? -1 : +(e.name > t.name)), l = c.slice(0, o).map((e) => ({
1782
1787
  id: e.name,
1783
1788
  name: e.name,
1784
1789
  mode: e.mode,
1785
1790
  definitionSource: "code"
1786
1791
  })), u = l.length === o ? [] : await t.query({
1787
1792
  table: "_voltro_ai_flows",
1788
- predicate: c.length === 0 ? void 0 : Re("id", c.map((e) => e.name)),
1793
+ predicate: c.length === 0 ? void 0 : ze("id", c.map((e) => e.name)),
1789
1794
  order: [{
1790
1795
  column: "createdAt",
1791
1796
  direction: "desc"
@@ -1805,7 +1810,7 @@ var Vt = (e, t = {}) => {
1805
1810
  rows: d,
1806
1811
  take: o
1807
1812
  });
1808
- }).pipe(O.catchAllCause(() => O.succeed(a(500, "query failed"))))
1813
+ }).pipe(D.catchCause(() => D.succeed(a(500, "query failed"))))
1809
1814
  }, {
1810
1815
  method: "GET",
1811
1816
  path: "/runs",
@@ -1813,21 +1818,21 @@ var Vt = (e, t = {}) => {
1813
1818
  description: "List recent run summaries (`?take=` bounded); `?runId=` reads one run with payloads and steps.",
1814
1819
  handler: (e) => o("_voltro_ai_flow_runs", s(e.url, Math.min(100, n)), new URL(e.url, "http://inspect.local").searchParams.get("runId") ?? void 0)
1815
1820
  }];
1816
- return Me({
1821
+ return Ne({
1817
1822
  name: t,
1818
- baseName: tr,
1823
+ baseName: nr,
1819
1824
  description: "AI Flows — durable multi-step AI pipelines (deterministic + agentic) with human-in-the-loop, chaining, and cadence. Code-first (defineFlow) or data-driven.",
1820
1825
  permissions: [
1821
1826
  "store:write",
1822
1827
  "inspect:read",
1823
1828
  "store:changes:read"
1824
1829
  ],
1825
- ...e.tables === !1 ? {} : { extendSchema: { tables: lt } },
1830
+ ...e.tables === !1 ? {} : { extendSchema: { tables: ut } },
1826
1831
  inspectEndpoints: c,
1827
1832
  bindDataStore: (e) => {
1828
1833
  r.current = e;
1829
1834
  },
1830
- onChangeEvent: (e) => O.gen(function* () {
1835
+ onChangeEvent: (e) => D.gen(function* () {
1831
1836
  if (e.table !== "_voltro_workflow_runs" || e.new === null || e.op !== "update" && e.op !== "insert") return;
1832
1837
  let t = e.new;
1833
1838
  if (t.tag !== "flow.run") return;
@@ -1835,20 +1840,20 @@ var Vt = (e, t = {}) => {
1835
1840
  if (n === void 0) return;
1836
1841
  let i = t.payload, a = (typeof i == "string" ? JSON.parse(i) : i)?.runId;
1837
1842
  if (typeof a != "string") return;
1838
- let o = (yield* O.promise(() => n.query(N(R).where(A("id", a)).descriptor)))[0];
1843
+ let o = (yield* D.promise(() => n.query(N(R).where(A("id", a)).descriptor)))[0];
1839
1844
  if (o === void 0) return;
1840
1845
  let s = o.status, c = t.executionId, l = o.workflowStart;
1841
- s === "pending" && l?.status === "queued" && typeof c == "string" && c.length > 0 && (yield* O.promise(() => n.update(R.tableName, a, { workflowStart: dt(c) })));
1846
+ s === "pending" && l?.status === "queued" && typeof c == "string" && c.length > 0 && (yield* D.promise(() => n.update(R.tableName, a, { workflowStart: ft(c) })));
1842
1847
  let u = e.old?.status === "cancelled";
1843
1848
  if (e.op !== "update" || t.status !== "cancelled" || u || s === "cancelled" || s === "succeeded" || s === "failed") return;
1844
1849
  let d = (/* @__PURE__ */ new Date()).toISOString(), f = typeof o.cancelledAt == "string" ? o.cancelledAt : d;
1845
- yield* O.promise(() => n.update(R.tableName, a, {
1850
+ yield* D.promise(() => n.update(R.tableName, a, {
1846
1851
  status: "cancelled",
1847
1852
  cancelledAt: f,
1848
1853
  completedAt: d
1849
1854
  }));
1850
- }).pipe(O.catchAllCause(() => O.void))
1855
+ }).pipe(D.catchCause(() => D.void))
1851
1856
  });
1852
1857
  };
1853
1858
  //#endregion
1854
- export { pe as BriefField, le as ChainPending, _ as ConditionOp, de as CostCompleteness, w as CostSource, _t as FLOW_RUNS_TTL_ENV, gt as FLOW_RUNS_TTL_HOURS_DEFAULT, e as FLOW_RUN_WORKFLOW, ne as FlowCadence, T as FlowCancelReceipt, fe as FlowChain, re as FlowMode, se as FlowReviewInput, me as FlowReviewReceipt, x as FlowStartReceipt, S as FlowStatus, ue as FlowStep, t as HUMAN_RESPONSE_SIGNAL_PREFIX, ht as HUMAN_REVIEW_TIMEOUT_ENV, mt as HUMAN_REVIEW_TIMEOUT_HOURS_DEFAULT, ce as HumanResponse, ie as Json, vt as MAX_CHAIN_DEPTH_DEFAULT, yt as MAX_CHAIN_DEPTH_ENV, C as MAX_STEPS_DEFAULT, te as MAX_STEPS_MAX, he as MAX_STEPS_MIN, ve as MediaArtifact, b as MediaArtifacts, _e as MediaInputSlot, v as MediaInputs, o as MediaReceipt, ge as Modality, ee as ReviewMode, c as ReviewOption, s as RunReview, h as RunSource, oe as RunStatus, i as RunStep, ae as RunStepStatus, ye as StepCondition, p as StepType, m as StepUsage, g as Visibility, dt as admittedStartHandle, R as aiFlowRunsTable, nr as aiFlowsPlugin, L as aiFlowsTable, lt as aiFlowsTables, vn as buildFlowRunExecute, De as cadenceMatches, Kn as cancelFlow, l as clampMaxSteps, ct as clearRegistry, kt as collectRefs, Qn as createFlow, wn as cronRequestId, Sn as defineFlow, er as deleteFlow, a as describeCondition, y as evaluateCondition, Mt as flowSegments, yn as flowStep, St as getAiFlowsDefaults, Xn as getFlow, ot as getRegisteredFlow, r as humanResponseSignalName, At as interpolate, u as isTruthy, Wn as launchFlow, Zn as listFlows, st as listRegisteredFlows, Bn as makeMediaGenerator, Ee as nextRuns, Nt as nonContiguousGroups, d as normalizeFlow, pt as reconcileFlowStarts, at as registerFlow, Ct as resetAiFlowsDefaults, Et as resolveHumanReviewTimeoutMs, tn as resolveIr, Dt as resolveMaxChainDepth, Yn as respondToFlow, Gn as retryFlow, En as runCadenceTick, f as sanitizeOutputKey, xt as setAiFlowsDefaults, jt as unresolvedRefs, $n as updateFlow, xn as validateFlow, Jn as waitingStepIndex };
1859
+ export { he as BriefField, de as ChainPending, ee as ConditionOp, pe as CostCompleteness, S as CostSource, vt as FLOW_RUNS_TTL_ENV, _t as FLOW_RUNS_TTL_HOURS_DEFAULT, e as FLOW_RUN_WORKFLOW, re as FlowCadence, C as FlowCancelReceipt, me as FlowChain, ie as FlowMode, le as FlowReviewInput, ge as FlowReviewReceipt, b as FlowStartReceipt, x as FlowStatus, fe as FlowStep, t as HUMAN_RESPONSE_SIGNAL_PREFIX, gt as HUMAN_REVIEW_TIMEOUT_ENV, ht as HUMAN_REVIEW_TIMEOUT_HOURS_DEFAULT, ue as HumanResponse, oe as Json, yt as MAX_CHAIN_DEPTH_DEFAULT, bt as MAX_CHAIN_DEPTH_ENV, ae as MAX_STEPS_DEFAULT, ne as MAX_STEPS_MAX, _e as MAX_STEPS_MIN, be as MediaArtifact, y as MediaArtifacts, ye as MediaInputSlot, _ as MediaInputs, o as MediaReceipt, ve as Modality, te as ReviewMode, c as ReviewOption, s as RunReview, h as RunSource, ce as RunStatus, i as RunStep, se as RunStepStatus, xe as StepCondition, p as StepType, m as StepUsage, g as Visibility, ft as admittedStartHandle, R as aiFlowRunsTable, rr as aiFlowsPlugin, L as aiFlowsTable, ut as aiFlowsTables, bn as buildFlowRunExecute, ke as cadenceMatches, qn as cancelFlow, l as clampMaxSteps, lt as clearRegistry, At as collectRefs, $n as createFlow, En as cronRequestId, wn as defineFlow, tr as deleteFlow, a as describeCondition, v as evaluateCondition, Nt as flowSegments, xn as flowStep, Ct as getAiFlowsDefaults, Zn as getFlow, st as getRegisteredFlow, r as humanResponseSignalName, jt as interpolate, u as isTruthy, Gn as launchFlow, Qn as listFlows, ct as listRegisteredFlows, Vn as makeMediaGenerator, Oe as nextRuns, Pt as nonContiguousGroups, d as normalizeFlow, mt as reconcileFlowStarts, ot as registerFlow, wt as resetAiFlowsDefaults, Dt as resolveHumanReviewTimeoutMs, rn as resolveIr, Ot as resolveMaxChainDepth, Xn as respondToFlow, Kn as retryFlow, On as runCadenceTick, f as sanitizeOutputKey, St as setAiFlowsDefaults, Mt as unresolvedRefs, er as updateFlow, Cn as validateFlow, Yn as waitingStepIndex };