@voltro/plugin-ai-flows 0.83.1 → 0.85.0

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