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