@voltro/plugin-ai-flows 0.38.0 → 0.39.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/CHANGELOG.md +224 -0
- package/THIRD-PARTY-NOTICES.md +11 -11
- package/dist/{cadence-Bt6dPelT.js → cadence-_9Izk_fL.js} +2 -2
- package/dist/index.js +356 -356
- package/dist/web.js +1 -1
- package/package.json +11 -11
package/dist/index.js
CHANGED
|
@@ -1,91 +1,91 @@
|
|
|
1
|
-
import { A as e, C as t, D as n, E as r, M as i, O as a, S as o, T as s, _ as c, a as l, b as u, c as d, d as f, f as p, g as m, h, i as
|
|
2
|
-
import { FLOW_RUN_WORKFLOW as
|
|
3
|
-
import { FlowBriefIncomplete as
|
|
4
|
-
import { n as
|
|
5
|
-
import { Cause as
|
|
6
|
-
import { definePlugin as
|
|
7
|
-
import { boolean as
|
|
8
|
-
import { tenant as
|
|
9
|
-
import { audit as
|
|
10
|
-
import { softDelete as
|
|
11
|
-
import { awaitSignalSuspending as
|
|
12
|
-
import { defineTool as
|
|
1
|
+
import { A as e, C as t, D as n, E as r, M as i, O as a, S as o, T as s, _ as c, a as l, b as u, c as d, d as f, f as p, g as m, h, i as ee, j as g, k as te, l as ne, m as re, n as ie, o as ae, p as oe, r as se, s as ce, t as le, u as ue, v as de, w as fe, x as pe, y as me } from "./ir-BOv5uwYI.js";
|
|
2
|
+
import { FLOW_RUN_WORKFLOW as _, HUMAN_RESPONSE_SIGNAL_PREFIX as he, humanResponseSignalName as v } from "./workflow.js";
|
|
3
|
+
import { FlowBriefIncomplete as ge, FlowCapabilityMissing as y, FlowDependencyError as _e, FlowNotAwaitingResponse as ve, FlowNotFound as ye, FlowRunNotFound as b, FlowValidationError as be } from "./errors.js";
|
|
4
|
+
import { n as xe, t as Se } from "./cadence-_9Izk_fL.js";
|
|
5
|
+
import { Cause as Ce, Effect as x, Schema as S } from "effect";
|
|
6
|
+
import { definePlugin as we, pluginInstanceName as Te } from "@voltro/protocol";
|
|
7
|
+
import { boolean as Ee, eq as C, id as De, inSet as Oe, integer as w, json as T, queryFor as E, registerRetention as ke, table as Ae, text as D, timestamp as O } from "@voltro/database";
|
|
8
|
+
import { tenant as je } from "@voltro/plugin-multitenancy/mixin";
|
|
9
|
+
import { audit as Me } from "@voltro/plugin-audit/mixin";
|
|
10
|
+
import { softDelete as Ne } from "@voltro/plugin-soft-delete/mixin";
|
|
11
|
+
import { awaitSignalSuspending as Pe, step as k } from "@voltro/workflow";
|
|
12
|
+
import { defineTool as A, estimateCostUsd as Fe, gatewayCostUsd as Ie, generateImage as Le, generateObject as Re, generateObjectWithTools as ze, generateSpeech as Be, generateText as j, generateVideo as Ve } from "@voltro/ai";
|
|
13
13
|
//#region src/table.ts
|
|
14
|
-
var
|
|
15
|
-
id:
|
|
16
|
-
name:
|
|
17
|
-
description:
|
|
18
|
-
mode:
|
|
19
|
-
status:
|
|
20
|
-
visibility:
|
|
21
|
-
orchestratorModel:
|
|
22
|
-
orchestratorInstructions:
|
|
23
|
-
maxSteps:
|
|
24
|
-
steps:
|
|
25
|
-
inputSchema:
|
|
26
|
-
chainTo:
|
|
27
|
-
cadence:
|
|
28
|
-
humanTimeoutMs:
|
|
29
|
-
isEnabled:
|
|
30
|
-
metadata:
|
|
31
|
-
icon:
|
|
32
|
-
color:
|
|
33
|
-
avatarUrl:
|
|
34
|
-
usageCount:
|
|
35
|
-
ownerId:
|
|
36
|
-
}).renamedFrom("ai_flows").with(
|
|
37
|
-
id:
|
|
38
|
-
flowRef:
|
|
39
|
-
flowName:
|
|
40
|
-
mode:
|
|
41
|
-
status:
|
|
42
|
-
source:
|
|
43
|
-
requestId:
|
|
44
|
-
input:
|
|
45
|
-
output:
|
|
46
|
-
steps:
|
|
47
|
-
currentStep:
|
|
48
|
-
totalSteps:
|
|
49
|
-
humanResponse:
|
|
50
|
-
chainPending:
|
|
51
|
-
chainRefusal:
|
|
52
|
-
costMicroUsd:
|
|
53
|
-
durationMs:
|
|
54
|
-
error:
|
|
55
|
-
errorMessage:
|
|
56
|
-
startedAt:
|
|
57
|
-
completedAt:
|
|
58
|
-
cancelledAt:
|
|
59
|
-
sessionId:
|
|
60
|
-
sessionName:
|
|
61
|
-
ownerId:
|
|
62
|
-
metadata:
|
|
63
|
-
}).renamedFrom("ai_flow_runs").with(
|
|
64
|
-
|
|
65
|
-
},
|
|
66
|
-
|
|
67
|
-
},
|
|
14
|
+
var M = Ae("_voltro_ai_flows", {
|
|
15
|
+
id: De({ prefix: "aifl" }),
|
|
16
|
+
name: D(),
|
|
17
|
+
description: D().nullable(),
|
|
18
|
+
mode: D().default("deterministic"),
|
|
19
|
+
status: D().default("draft"),
|
|
20
|
+
visibility: D().default("private"),
|
|
21
|
+
orchestratorModel: D().nullable(),
|
|
22
|
+
orchestratorInstructions: D().nullable(),
|
|
23
|
+
maxSteps: w().default(30),
|
|
24
|
+
steps: T().nullable(),
|
|
25
|
+
inputSchema: T().nullable(),
|
|
26
|
+
chainTo: T().nullable(),
|
|
27
|
+
cadence: T().nullable(),
|
|
28
|
+
humanTimeoutMs: w().nullable(),
|
|
29
|
+
isEnabled: Ee().default(!0),
|
|
30
|
+
metadata: T().nullable(),
|
|
31
|
+
icon: D().nullable(),
|
|
32
|
+
color: D().nullable(),
|
|
33
|
+
avatarUrl: D().nullable(),
|
|
34
|
+
usageCount: w().default(0),
|
|
35
|
+
ownerId: D().nullable()
|
|
36
|
+
}).renamedFrom("ai_flows").with(je(), Me(), Ne()).index(["status"]).index(["visibility"]), N = Ae("_voltro_ai_flow_runs", {
|
|
37
|
+
id: De({ prefix: "aifr" }),
|
|
38
|
+
flowRef: D(),
|
|
39
|
+
flowName: D().nullable(),
|
|
40
|
+
mode: D().default("deterministic"),
|
|
41
|
+
status: D().default("pending"),
|
|
42
|
+
source: D().nullable(),
|
|
43
|
+
requestId: D(),
|
|
44
|
+
input: T().nullable(),
|
|
45
|
+
output: T().nullable(),
|
|
46
|
+
steps: T().nullable(),
|
|
47
|
+
currentStep: w().default(0),
|
|
48
|
+
totalSteps: w().default(0),
|
|
49
|
+
humanResponse: T().nullable(),
|
|
50
|
+
chainPending: T().nullable(),
|
|
51
|
+
chainRefusal: D().nullable(),
|
|
52
|
+
costMicroUsd: w().default(0),
|
|
53
|
+
durationMs: w().nullable(),
|
|
54
|
+
error: D().nullable(),
|
|
55
|
+
errorMessage: D().nullable(),
|
|
56
|
+
startedAt: O().nullable(),
|
|
57
|
+
completedAt: O().nullable(),
|
|
58
|
+
cancelledAt: O().nullable(),
|
|
59
|
+
sessionId: D().nullable(),
|
|
60
|
+
sessionName: D().nullable(),
|
|
61
|
+
ownerId: D().nullable(),
|
|
62
|
+
metadata: T().nullable()
|
|
63
|
+
}).renamedFrom("ai_flow_runs").with(je(), Me()).index(["flowRef"]).index(["status"]).index(["requestId"]), He = [M, N], Ue = 168, We = "VOLTRO_AI_FLOW_HUMAN_REVIEW_TIMEOUT_HOURS", Ge = 2160, Ke = "VOLTRO_AI_FLOW_RUNS_TTL_HOURS", qe = 5, Je = "VOLTRO_AI_FLOW_MAX_CHAIN_DEPTH", P = { current: {} }, Ye = (e) => {
|
|
64
|
+
P.current = e;
|
|
65
|
+
}, F = () => P.current, Xe = () => {
|
|
66
|
+
P.current = {};
|
|
67
|
+
}, Ze = (e, t) => {
|
|
68
68
|
if (e === void 0 || e.trim() === "") return t * 36e5;
|
|
69
69
|
let n = Number(e);
|
|
70
70
|
return !Number.isFinite(n) || n < 0 ? t * 36e5 : n * 36e5;
|
|
71
|
-
},
|
|
71
|
+
}, Qe = (e) => Number.isFinite(e) && e > 0 ? e : Infinity, $e = (e) => {
|
|
72
72
|
let t = e.env ?? process.env;
|
|
73
|
-
return
|
|
74
|
-
},
|
|
75
|
-
let t = e?.env ?? process.env, n = Number(t[
|
|
73
|
+
return Qe(e.step?.timeoutMs ?? e.flow?.humanTimeoutMs ?? e.deps?.humanReviewTimeoutMs ?? F().humanReviewTimeoutMs ?? Ze(t.VOLTRO_AI_FLOW_HUMAN_REVIEW_TIMEOUT_HOURS, 168));
|
|
74
|
+
}, et = (e) => {
|
|
75
|
+
let t = e?.env ?? process.env, n = Number(t[Je]), r = e?.maxChainDepth ?? F().maxChainDepth ?? (Number.isFinite(n) && n >= 1 ? n : 5);
|
|
76
76
|
return Number.isFinite(r) && r >= 1 ? r : 5;
|
|
77
|
-
},
|
|
77
|
+
}, tt = /\{\{\s*([\w.-]+)\s*\}\}/g, I = (e) => {
|
|
78
78
|
let t = [];
|
|
79
|
-
for (let n of e.matchAll(
|
|
79
|
+
for (let n of e.matchAll(tt)) t.push(n[1]);
|
|
80
80
|
return t;
|
|
81
|
-
},
|
|
81
|
+
}, L = (e, t) => e.replace(tt, (e, n) => {
|
|
82
82
|
let r = t[n];
|
|
83
83
|
return r == null ? "" : typeof r == "string" ? r : JSON.stringify(r);
|
|
84
|
-
}),
|
|
84
|
+
}), nt = (e, t) => {
|
|
85
85
|
let n = /* @__PURE__ */ new Set();
|
|
86
|
-
for (let r of
|
|
86
|
+
for (let r of I(e)) t[r] == null && !n.has(r) && n.add(r);
|
|
87
87
|
return [...n];
|
|
88
|
-
},
|
|
88
|
+
}, R = (e) => {
|
|
89
89
|
let t = [], n;
|
|
90
90
|
if (e.forEach((e, r) => {
|
|
91
91
|
let i = e.group;
|
|
@@ -114,66 +114,66 @@ var N = ke("_voltro_ai_flows", {
|
|
|
114
114
|
});
|
|
115
115
|
}
|
|
116
116
|
return t;
|
|
117
|
-
},
|
|
117
|
+
}, rt = (e) => {
|
|
118
118
|
let t = /* @__PURE__ */ new Map();
|
|
119
119
|
for (let n of e) n.group !== void 0 && t.set(n.group, (t.get(n.group) ?? 0) + 1);
|
|
120
120
|
return [...t.entries()].filter(([, e]) => e > 1).map(([e]) => e).sort();
|
|
121
|
-
},
|
|
122
|
-
|
|
123
|
-
},
|
|
121
|
+
}, z = /* @__PURE__ */ new Map(), it = (e) => {
|
|
122
|
+
z.set(e.name, e);
|
|
123
|
+
}, at = (e) => z.get(e), ot = () => [...z.values()], st = () => z.clear(), B = (e) => typeof e == "object" && e && !Array.isArray(e) ? e : void 0, V = (e) => Array.isArray(e) ? e : void 0, ct = (e) => {
|
|
124
124
|
switch (e) {
|
|
125
|
-
case "string": return
|
|
126
|
-
case "number": return
|
|
127
|
-
case "integer": return
|
|
128
|
-
case "boolean": return
|
|
129
|
-
case "null": return
|
|
130
|
-
default: return
|
|
125
|
+
case "string": return S.String;
|
|
126
|
+
case "number": return S.Number;
|
|
127
|
+
case "integer": return S.Int;
|
|
128
|
+
case "boolean": return S.Boolean;
|
|
129
|
+
case "null": return S.Null;
|
|
130
|
+
default: return S.Unknown;
|
|
131
131
|
}
|
|
132
|
-
},
|
|
132
|
+
}, H = (e, t) => {
|
|
133
133
|
let n = typeof t.description == "string" ? t.description : void 0, r = typeof t.title == "string" ? t.title : void 0;
|
|
134
134
|
return n === void 0 && r === void 0 ? e : e.annotations({
|
|
135
135
|
...n === void 0 ? {} : { description: n },
|
|
136
136
|
...r === void 0 ? {} : { title: r }
|
|
137
137
|
});
|
|
138
|
-
},
|
|
139
|
-
key:
|
|
140
|
-
value:
|
|
141
|
-
}),
|
|
142
|
-
let t =
|
|
143
|
-
if (t === void 0) return
|
|
144
|
-
if ("const" in t) return
|
|
145
|
-
let n =
|
|
146
|
-
if (n !== void 0 && n.length > 0) return
|
|
147
|
-
let r =
|
|
148
|
-
if (r !== void 0) return
|
|
149
|
-
let i = t.type, a = typeof i == "string" ? [i] :
|
|
150
|
-
return
|
|
151
|
-
},
|
|
152
|
-
let t =
|
|
153
|
-
if (t === void 0) return
|
|
154
|
-
let n = new Set((
|
|
138
|
+
}, lt = (e) => e.length === 0 ? S.Unknown : e.length === 1 ? e[0] : S.Union(...e), ut = () => S.Record({
|
|
139
|
+
key: S.String,
|
|
140
|
+
value: S.Unknown
|
|
141
|
+
}), U = (e) => {
|
|
142
|
+
let t = B(e);
|
|
143
|
+
if (t === void 0) return S.Unknown;
|
|
144
|
+
if ("const" in t) return H(S.Literal(t.const), t);
|
|
145
|
+
let n = V(t.enum);
|
|
146
|
+
if (n !== void 0 && n.length > 0) return H(S.Literal(...n), t);
|
|
147
|
+
let r = V(t.anyOf) ?? V(t.oneOf);
|
|
148
|
+
if (r !== void 0) return H(lt(r.map(U)), t);
|
|
149
|
+
let i = t.type, a = typeof i == "string" ? [i] : V(i)?.filter((e) => typeof e == "string") ?? [], o = t.nullable === !0 || a.includes("null"), s = a.find((e) => e !== "null"), c = s === "object" || s === void 0 && t.properties !== void 0 ? dt(t) : s === "array" || s === void 0 && t.items !== void 0 ? S.Array(U(t.items)) : s === void 0 ? S.Unknown : ct(s);
|
|
150
|
+
return H(o ? S.NullOr(c) : c, t);
|
|
151
|
+
}, dt = (e) => {
|
|
152
|
+
let t = B(e.properties);
|
|
153
|
+
if (t === void 0) return ut();
|
|
154
|
+
let n = new Set((V(e.required) ?? []).filter((e) => typeof e == "string")), r = {};
|
|
155
155
|
for (let [e, i] of Object.entries(t)) {
|
|
156
|
-
let t =
|
|
157
|
-
r[e] = n.has(e) ? t :
|
|
156
|
+
let t = U(i);
|
|
157
|
+
r[e] = n.has(e) ? t : S.optional(t);
|
|
158
158
|
}
|
|
159
|
-
return
|
|
160
|
-
},
|
|
161
|
-
let t =
|
|
162
|
-
return t === void 0 || Object.keys(t).length === 0 ?
|
|
163
|
-
},
|
|
164
|
-
value:
|
|
165
|
-
text:
|
|
166
|
-
url:
|
|
167
|
-
costMicroUsd:
|
|
168
|
-
requestId:
|
|
169
|
-
error:
|
|
170
|
-
}),
|
|
171
|
-
let r =
|
|
172
|
-
return typeof r == "number" ?
|
|
173
|
-
},
|
|
174
|
-
let n =
|
|
159
|
+
return S.Struct(r);
|
|
160
|
+
}, ft = (e) => {
|
|
161
|
+
let t = B(e);
|
|
162
|
+
return t === void 0 || Object.keys(t).length === 0 ? ut() : U(t);
|
|
163
|
+
}, W = (e) => e, pt = S.Struct({
|
|
164
|
+
value: S.optional(S.Unknown),
|
|
165
|
+
text: S.optional(S.String),
|
|
166
|
+
url: S.optional(S.String),
|
|
167
|
+
costMicroUsd: S.optional(S.Number),
|
|
168
|
+
requestId: S.optional(S.String),
|
|
169
|
+
error: S.optional(S.String)
|
|
170
|
+
}), G = () => (/* @__PURE__ */ new Date()).toISOString(), mt = (e) => Math.round(e * 1e6), K = (e, t) => e.resolveModel?.(t) ?? K(e, t), q = (e, t, n) => {
|
|
171
|
+
let r = Ie(t);
|
|
172
|
+
return typeof r == "number" ? mt(r) : Fe(e, { model: n ?? "unknown" }).costMicroUsd ?? 0;
|
|
173
|
+
}, J = (e, t, n) => x.promise(() => e.store.update(N.tableName, t, n).then(() => void 0)).pipe(x.catchAllCause(() => x.void)), ht = (e, t) => x.promise(async () => (await e.store.query(E(N).where(C("id", t)).descriptor))[0]?.status === "cancelled").pipe(x.catchAllCause(() => x.succeed(!1))), Y = (e, t) => x.gen(function* () {
|
|
174
|
+
let n = at(t);
|
|
175
175
|
if (n) return n;
|
|
176
|
-
let i = (yield*
|
|
176
|
+
let i = (yield* x.promise(() => e.store.query(E(M).where(C("id", t)).descriptor)))[0];
|
|
177
177
|
return i ? r({
|
|
178
178
|
name: i.name ?? t,
|
|
179
179
|
mode: i.mode,
|
|
@@ -185,13 +185,13 @@ var N = ke("_voltro_ai_flows", {
|
|
|
185
185
|
chain: i.chainTo ?? null,
|
|
186
186
|
cadence: i.cadence ?? null,
|
|
187
187
|
humanTimeoutMs: i.humanTimeoutMs ?? null
|
|
188
|
-
}) : yield*
|
|
188
|
+
}) : yield* x.fail(new ye({
|
|
189
189
|
flowRef: t,
|
|
190
190
|
message: `no flow registered or stored for "${t}"`
|
|
191
191
|
}));
|
|
192
|
-
}),
|
|
193
|
-
let e =
|
|
194
|
-
if (a.length > 0) return { error: new
|
|
192
|
+
}), gt = (e, t, n, r, i) => x.gen(function* () {
|
|
193
|
+
let e = L(n.prompt ?? "", r), a = nt(n.prompt ?? "", r);
|
|
194
|
+
if (a.length > 0) return { error: new _e({
|
|
195
195
|
stepId: n.id,
|
|
196
196
|
unresolvedRef: a[0],
|
|
197
197
|
message: `step "${n.id}" references unresolved {{${a[0]}}}`
|
|
@@ -204,86 +204,86 @@ var N = ke("_voltro_ai_flows", {
|
|
|
204
204
|
};
|
|
205
205
|
case "agent": {
|
|
206
206
|
if (!n.agentRef) return { error: "agent step missing agentRef" };
|
|
207
|
-
if (!t.resolveAgent) return { error: new
|
|
207
|
+
if (!t.resolveAgent) return { error: new y({
|
|
208
208
|
capability: "resolveAgent",
|
|
209
209
|
message: "no agent resolver configured"
|
|
210
210
|
}).message };
|
|
211
|
-
let r = yield*
|
|
211
|
+
let r = yield* W(t.resolveAgent(n.agentRef)).pipe(x.map((e) => ({
|
|
212
212
|
ok: !0,
|
|
213
213
|
a: e
|
|
214
|
-
})),
|
|
214
|
+
})), x.catchAll((e) => x.succeed({
|
|
215
215
|
ok: !1,
|
|
216
216
|
e
|
|
217
217
|
})));
|
|
218
218
|
if (!r.ok) return { error: r.e.message };
|
|
219
|
-
let i = yield*
|
|
219
|
+
let i = yield* j({
|
|
220
220
|
system: r.a.system,
|
|
221
221
|
prompt: e,
|
|
222
|
-
provider:
|
|
223
|
-
}).pipe(
|
|
222
|
+
provider: K(t, r.a.model)
|
|
223
|
+
}).pipe(x.map((e) => ({
|
|
224
224
|
ok: !0,
|
|
225
225
|
r: e
|
|
226
|
-
})),
|
|
226
|
+
})), x.catchAll((e) => x.succeed({
|
|
227
227
|
ok: !1,
|
|
228
228
|
e
|
|
229
229
|
})));
|
|
230
230
|
return i.ok ? {
|
|
231
231
|
value: i.r.text,
|
|
232
232
|
text: i.r.text,
|
|
233
|
-
costMicroUsd:
|
|
233
|
+
costMicroUsd: q(i.r.usage, i.r.providerMetadata, r.a.model)
|
|
234
234
|
} : { error: String(i.e.message ?? i.e) };
|
|
235
235
|
}
|
|
236
236
|
case "structured": {
|
|
237
|
-
let r = n.model ?? t.defaultModels?.text, i = yield*
|
|
237
|
+
let r = n.model ?? t.defaultModels?.text, i = yield* Re({
|
|
238
238
|
prompt: e,
|
|
239
|
-
schema:
|
|
240
|
-
...r ? { provider:
|
|
241
|
-
}).pipe(
|
|
239
|
+
schema: ft(n.schema),
|
|
240
|
+
...r ? { provider: K(t, r) } : {}
|
|
241
|
+
}).pipe(x.map((e) => ({
|
|
242
242
|
ok: !0,
|
|
243
243
|
r: e
|
|
244
|
-
})),
|
|
244
|
+
})), x.catchAll((e) => x.succeed({
|
|
245
245
|
ok: !1,
|
|
246
246
|
e
|
|
247
247
|
})));
|
|
248
248
|
return i.ok ? {
|
|
249
249
|
value: i.r.object,
|
|
250
250
|
text: JSON.stringify(i.r.object, null, 2),
|
|
251
|
-
costMicroUsd:
|
|
251
|
+
costMicroUsd: q(i.r.usage, i.r.providerMetadata, r)
|
|
252
252
|
} : { error: String(i.e.message ?? i.e) };
|
|
253
253
|
}
|
|
254
254
|
case "generate": {
|
|
255
255
|
let r = n.modality ?? "text";
|
|
256
256
|
if (r === "text") {
|
|
257
|
-
let r = n.model ?? t.defaultModels?.text, i = yield*
|
|
257
|
+
let r = n.model ?? t.defaultModels?.text, i = yield* j({
|
|
258
258
|
prompt: e,
|
|
259
|
-
...r ? { provider:
|
|
260
|
-
}).pipe(
|
|
259
|
+
...r ? { provider: K(t, r) } : {}
|
|
260
|
+
}).pipe(x.map((e) => ({
|
|
261
261
|
ok: !0,
|
|
262
262
|
r: e
|
|
263
|
-
})),
|
|
263
|
+
})), x.catchAll((e) => x.succeed({
|
|
264
264
|
ok: !1,
|
|
265
265
|
e
|
|
266
266
|
})));
|
|
267
267
|
return i.ok ? {
|
|
268
268
|
value: i.r.text,
|
|
269
269
|
text: i.r.text,
|
|
270
|
-
costMicroUsd:
|
|
270
|
+
costMicroUsd: q(i.r.usage, i.r.providerMetadata, r)
|
|
271
271
|
} : { error: String(i.e.message ?? i.e) };
|
|
272
272
|
}
|
|
273
|
-
if (!t.generateMedia) return { error: new
|
|
273
|
+
if (!t.generateMedia) return { error: new y({
|
|
274
274
|
capability: `media:${r}`,
|
|
275
275
|
message: `no media generator configured for ${r}`
|
|
276
276
|
}).message };
|
|
277
|
-
let a = n.model ?? t.defaultModels?.[r], o = yield*
|
|
277
|
+
let a = n.model ?? t.defaultModels?.[r], o = yield* W(t.generateMedia({
|
|
278
278
|
modality: r,
|
|
279
279
|
...a ? { model: a } : {},
|
|
280
280
|
prompt: e,
|
|
281
281
|
...n.params ? { params: n.params } : {},
|
|
282
282
|
run: i
|
|
283
|
-
})).pipe(
|
|
283
|
+
})).pipe(x.map((e) => ({
|
|
284
284
|
ok: !0,
|
|
285
285
|
m: e
|
|
286
|
-
})),
|
|
286
|
+
})), x.catchAll((e) => x.succeed({
|
|
287
287
|
ok: !1,
|
|
288
288
|
e
|
|
289
289
|
})));
|
|
@@ -294,13 +294,13 @@ var N = ke("_voltro_ai_flows", {
|
|
|
294
294
|
costMicroUsd: o.m.costMicroUsd ?? 0
|
|
295
295
|
} : { error: o.e.message };
|
|
296
296
|
}
|
|
297
|
-
case "human": return { error: new
|
|
297
|
+
case "human": return { error: new y({
|
|
298
298
|
capability: "human",
|
|
299
299
|
message: "human step reached the step interpreter — it should have been parked by the deterministic executor (routing bug)"
|
|
300
300
|
}).message };
|
|
301
301
|
default: return { error: `unknown step type: ${String(n.type)}` };
|
|
302
302
|
}
|
|
303
|
-
}),
|
|
303
|
+
}), _t = (t, n, r, i, a, o) => x.gen(function* () {
|
|
304
304
|
let s = { ...a }, c = i.steps.map((e, t) => ({
|
|
305
305
|
id: t,
|
|
306
306
|
title: e.title ?? `Step ${t + 1}`,
|
|
@@ -308,26 +308,26 @@ var N = ke("_voltro_ai_flows", {
|
|
|
308
308
|
status: "pending",
|
|
309
309
|
...e.description ? { description: e.description } : {}
|
|
310
310
|
})), l = 0;
|
|
311
|
-
yield*
|
|
311
|
+
yield* J(t, r, {
|
|
312
312
|
status: "running",
|
|
313
313
|
steps: c,
|
|
314
314
|
totalSteps: i.steps.length,
|
|
315
315
|
currentStep: 0,
|
|
316
|
-
startedAt:
|
|
316
|
+
startedAt: G()
|
|
317
317
|
});
|
|
318
|
-
for (let a of
|
|
319
|
-
if (yield*
|
|
318
|
+
for (let a of R(i.steps)) {
|
|
319
|
+
if (yield* ht(t, r)) return {
|
|
320
320
|
runId: r,
|
|
321
321
|
status: "cancelled"
|
|
322
322
|
};
|
|
323
323
|
if (a.steps.length > 1) {
|
|
324
324
|
let i = [];
|
|
325
325
|
for (let { index: t, step: n } of a.steps) {
|
|
326
|
-
if (n.when !== void 0 && !
|
|
326
|
+
if (n.when !== void 0 && !g(n.when, s)) {
|
|
327
327
|
c[t] = {
|
|
328
328
|
...c[t],
|
|
329
329
|
status: "skipped",
|
|
330
|
-
completedAt:
|
|
330
|
+
completedAt: G(),
|
|
331
331
|
skipReason: e(n.when)
|
|
332
332
|
};
|
|
333
333
|
continue;
|
|
@@ -338,22 +338,22 @@ var N = ke("_voltro_ai_flows", {
|
|
|
338
338
|
}), c[t] = {
|
|
339
339
|
...c[t],
|
|
340
340
|
status: "running",
|
|
341
|
-
startedAt:
|
|
341
|
+
startedAt: G()
|
|
342
342
|
};
|
|
343
343
|
}
|
|
344
|
-
yield*
|
|
344
|
+
yield* J(t, r, {
|
|
345
345
|
steps: c,
|
|
346
346
|
currentStep: a.steps[0].index
|
|
347
347
|
});
|
|
348
|
-
let u = yield*
|
|
348
|
+
let u = yield* x.all(i.map(({ index: e, step: i }) => k({
|
|
349
349
|
name: `flow-${e}-${i.id}`,
|
|
350
350
|
input: { index: e },
|
|
351
|
-
success:
|
|
352
|
-
execute:
|
|
351
|
+
success: pt,
|
|
352
|
+
execute: gt(t, n, i, s, {
|
|
353
353
|
runId: r,
|
|
354
354
|
tenantId: o.tenantId
|
|
355
355
|
})
|
|
356
|
-
}).pipe(
|
|
356
|
+
}).pipe(x.map((t) => ({
|
|
357
357
|
index: e,
|
|
358
358
|
step: i,
|
|
359
359
|
result: t
|
|
@@ -363,7 +363,7 @@ var N = ke("_voltro_ai_flows", {
|
|
|
363
363
|
c[e] = {
|
|
364
364
|
...c[e],
|
|
365
365
|
status: "failed",
|
|
366
|
-
completedAt:
|
|
366
|
+
completedAt: G(),
|
|
367
367
|
errorMessage: n.error
|
|
368
368
|
};
|
|
369
369
|
continue;
|
|
@@ -371,24 +371,24 @@ var N = ke("_voltro_ai_flows", {
|
|
|
371
371
|
t.outputKey && n.value !== void 0 && (s[t.outputKey] = n.value), l += n.costMicroUsd ?? 0, c[e] = {
|
|
372
372
|
...c[e],
|
|
373
373
|
status: "succeeded",
|
|
374
|
-
completedAt:
|
|
374
|
+
completedAt: G(),
|
|
375
375
|
...n.text ? { output: { text: n.text } } : {},
|
|
376
376
|
...n.url ? { url: n.url } : {},
|
|
377
377
|
...n.requestId ? { requestId: n.requestId } : {},
|
|
378
378
|
...n.costMicroUsd ? { costMicroUsd: n.costMicroUsd } : {}
|
|
379
379
|
};
|
|
380
380
|
}
|
|
381
|
-
if (d !== void 0) return yield*
|
|
381
|
+
if (d !== void 0) return yield* J(t, r, {
|
|
382
382
|
steps: c,
|
|
383
383
|
status: "failed",
|
|
384
384
|
errorMessage: d.result.error,
|
|
385
|
-
completedAt:
|
|
385
|
+
completedAt: G(),
|
|
386
386
|
costMicroUsd: l
|
|
387
387
|
}), {
|
|
388
388
|
runId: r,
|
|
389
389
|
status: "failed"
|
|
390
390
|
};
|
|
391
|
-
yield*
|
|
391
|
+
yield* J(t, r, {
|
|
392
392
|
steps: c,
|
|
393
393
|
currentStep: a.steps[a.steps.length - 1].index + 1,
|
|
394
394
|
costMicroUsd: l
|
|
@@ -396,13 +396,13 @@ var N = ke("_voltro_ai_flows", {
|
|
|
396
396
|
continue;
|
|
397
397
|
}
|
|
398
398
|
let { index: u, step: f } = a.steps[0];
|
|
399
|
-
if (f.when !== void 0 && !
|
|
399
|
+
if (f.when !== void 0 && !g(f.when, s)) {
|
|
400
400
|
c[u] = {
|
|
401
401
|
...c[u],
|
|
402
402
|
status: "skipped",
|
|
403
|
-
completedAt:
|
|
403
|
+
completedAt: G(),
|
|
404
404
|
skipReason: e(f.when)
|
|
405
|
-
}, yield*
|
|
405
|
+
}, yield* J(t, r, {
|
|
406
406
|
steps: c,
|
|
407
407
|
currentStep: u + 1
|
|
408
408
|
});
|
|
@@ -412,36 +412,36 @@ var N = ke("_voltro_ai_flows", {
|
|
|
412
412
|
let e = {
|
|
413
413
|
mode: f.reviewMode ?? "approve",
|
|
414
414
|
...f.options ? { options: f.options } : {},
|
|
415
|
-
prompt:
|
|
415
|
+
prompt: L(f.prompt ?? "", s)
|
|
416
416
|
};
|
|
417
417
|
c[u] = {
|
|
418
418
|
...c[u],
|
|
419
419
|
status: "waiting",
|
|
420
|
-
startedAt:
|
|
420
|
+
startedAt: G(),
|
|
421
421
|
review: e
|
|
422
|
-
}, yield*
|
|
422
|
+
}, yield* J(t, r, {
|
|
423
423
|
steps: c,
|
|
424
424
|
status: "waiting",
|
|
425
425
|
currentStep: u
|
|
426
|
-
}), n.onEvent && (yield*
|
|
426
|
+
}), n.onEvent && (yield* W(n.onEvent({
|
|
427
427
|
kind: "review-needed",
|
|
428
428
|
runId: r,
|
|
429
429
|
flowName: i.name,
|
|
430
430
|
ownerId: o.ownerId,
|
|
431
431
|
source: o.source
|
|
432
|
-
})).pipe(
|
|
433
|
-
let a =
|
|
432
|
+
})).pipe(x.catchAllCause(() => x.void)));
|
|
433
|
+
let a = $e({
|
|
434
434
|
step: f,
|
|
435
435
|
flow: i,
|
|
436
436
|
deps: n
|
|
437
|
-
}), p = yield*
|
|
438
|
-
name:
|
|
437
|
+
}), p = yield* Pe(t, {
|
|
438
|
+
name: v(u),
|
|
439
439
|
schema: d,
|
|
440
440
|
timeoutMs: a
|
|
441
|
-
}).pipe(
|
|
441
|
+
}).pipe(x.map((e) => ({
|
|
442
442
|
ok: !0,
|
|
443
443
|
a: e
|
|
444
|
-
})),
|
|
444
|
+
})), x.catchAllCause((e) => Ce.isInterruptedOnly(e) ? x.failCause(e) : x.succeed({
|
|
445
445
|
ok: !1,
|
|
446
446
|
cause: e
|
|
447
447
|
})));
|
|
@@ -450,13 +450,13 @@ var N = ke("_voltro_ai_flows", {
|
|
|
450
450
|
return c[u] = {
|
|
451
451
|
...c[u],
|
|
452
452
|
status: "failed",
|
|
453
|
-
completedAt:
|
|
453
|
+
completedAt: G(),
|
|
454
454
|
errorMessage: e
|
|
455
|
-
}, yield*
|
|
455
|
+
}, yield* J(t, r, {
|
|
456
456
|
steps: c,
|
|
457
457
|
status: "failed",
|
|
458
458
|
errorMessage: e,
|
|
459
|
-
completedAt:
|
|
459
|
+
completedAt: G(),
|
|
460
460
|
costMicroUsd: l
|
|
461
461
|
}), {
|
|
462
462
|
runId: r,
|
|
@@ -467,12 +467,12 @@ var N = ke("_voltro_ai_flows", {
|
|
|
467
467
|
if (m.decision === "reject") return c[u] = {
|
|
468
468
|
...c[u],
|
|
469
469
|
status: "failed",
|
|
470
|
-
completedAt:
|
|
470
|
+
completedAt: G(),
|
|
471
471
|
errorMessage: "rejected by reviewer"
|
|
472
|
-
}, yield*
|
|
472
|
+
}, yield* J(t, r, {
|
|
473
473
|
steps: c,
|
|
474
474
|
status: "cancelled",
|
|
475
|
-
completedAt:
|
|
475
|
+
completedAt: G(),
|
|
476
476
|
costMicroUsd: l
|
|
477
477
|
}), {
|
|
478
478
|
runId: r,
|
|
@@ -481,9 +481,9 @@ var N = ke("_voltro_ai_flows", {
|
|
|
481
481
|
f.outputKey && (s[f.outputKey] = m.value ?? m.text ?? m.decision ?? !0), c[u] = {
|
|
482
482
|
...c[u],
|
|
483
483
|
status: "succeeded",
|
|
484
|
-
completedAt:
|
|
484
|
+
completedAt: G(),
|
|
485
485
|
output: { text: String(m.text ?? m.value ?? m.decision ?? "approved") }
|
|
486
|
-
}, yield*
|
|
486
|
+
}, yield* J(t, r, {
|
|
487
487
|
steps: c,
|
|
488
488
|
status: "running",
|
|
489
489
|
currentStep: u + 1
|
|
@@ -493,16 +493,16 @@ var N = ke("_voltro_ai_flows", {
|
|
|
493
493
|
c[u] = {
|
|
494
494
|
...c[u],
|
|
495
495
|
status: "running",
|
|
496
|
-
startedAt:
|
|
497
|
-
}, yield*
|
|
496
|
+
startedAt: G()
|
|
497
|
+
}, yield* J(t, r, {
|
|
498
498
|
steps: c,
|
|
499
499
|
currentStep: u
|
|
500
500
|
});
|
|
501
|
-
let p = yield*
|
|
501
|
+
let p = yield* k({
|
|
502
502
|
name: `flow-${u}-${f.id}`,
|
|
503
503
|
input: { index: u },
|
|
504
|
-
success:
|
|
505
|
-
execute:
|
|
504
|
+
success: pt,
|
|
505
|
+
execute: gt(t, n, f, s, {
|
|
506
506
|
runId: r,
|
|
507
507
|
tenantId: o.tenantId
|
|
508
508
|
})
|
|
@@ -510,13 +510,13 @@ var N = ke("_voltro_ai_flows", {
|
|
|
510
510
|
if (p.error) return c[u] = {
|
|
511
511
|
...c[u],
|
|
512
512
|
status: "failed",
|
|
513
|
-
completedAt:
|
|
513
|
+
completedAt: G(),
|
|
514
514
|
errorMessage: p.error
|
|
515
|
-
}, yield*
|
|
515
|
+
}, yield* J(t, r, {
|
|
516
516
|
steps: c,
|
|
517
517
|
status: "failed",
|
|
518
518
|
errorMessage: p.error,
|
|
519
|
-
completedAt:
|
|
519
|
+
completedAt: G(),
|
|
520
520
|
costMicroUsd: l
|
|
521
521
|
}), {
|
|
522
522
|
runId: r,
|
|
@@ -525,12 +525,12 @@ var N = ke("_voltro_ai_flows", {
|
|
|
525
525
|
f.outputKey && p.value !== void 0 && (s[f.outputKey] = p.value), l += p.costMicroUsd ?? 0, c[u] = {
|
|
526
526
|
...c[u],
|
|
527
527
|
status: "succeeded",
|
|
528
|
-
completedAt:
|
|
528
|
+
completedAt: G(),
|
|
529
529
|
...p.text ? { output: { text: p.text } } : {},
|
|
530
530
|
...p.url ? { url: p.url } : {},
|
|
531
531
|
...p.requestId ? { requestId: p.requestId } : {},
|
|
532
532
|
...p.costMicroUsd ? { costMicroUsd: p.costMicroUsd } : {}
|
|
533
|
-
}, yield*
|
|
533
|
+
}, yield* J(t, r, {
|
|
534
534
|
steps: c,
|
|
535
535
|
currentStep: u + 1,
|
|
536
536
|
costMicroUsd: l
|
|
@@ -538,28 +538,28 @@ var N = ke("_voltro_ai_flows", {
|
|
|
538
538
|
}
|
|
539
539
|
let u = {};
|
|
540
540
|
for (let e of i.steps) e.outputKey && s[e.outputKey] !== void 0 && (u[e.outputKey] = s[e.outputKey]);
|
|
541
|
-
return yield*
|
|
541
|
+
return yield* J(t, r, {
|
|
542
542
|
status: "succeeded",
|
|
543
543
|
output: u,
|
|
544
|
-
completedAt:
|
|
544
|
+
completedAt: G(),
|
|
545
545
|
costMicroUsd: l
|
|
546
546
|
}), {
|
|
547
547
|
runId: r,
|
|
548
548
|
status: "succeeded",
|
|
549
549
|
output: u
|
|
550
550
|
};
|
|
551
|
-
}),
|
|
551
|
+
}), vt = (e, t, n, r, i, a, o) => x.gen(function* () {
|
|
552
552
|
let s = n.chain;
|
|
553
553
|
if (!s) return;
|
|
554
554
|
let c = [...a.chainPath ?? [], a.flowRef];
|
|
555
555
|
if (s.flowRef === n.name || s.flowRef === a.flowRef) return;
|
|
556
556
|
if (c.includes(s.flowRef)) {
|
|
557
|
-
yield*
|
|
557
|
+
yield* J(e, t, { chainRefusal: `chain to "${s.flowRef}" refused — it is already in this run's chain (${c.join(" → ")}), which would loop` });
|
|
558
558
|
return;
|
|
559
559
|
}
|
|
560
|
-
let l =
|
|
560
|
+
let l = et(o);
|
|
561
561
|
if (c.length >= l) {
|
|
562
|
-
yield*
|
|
562
|
+
yield* J(e, t, { chainRefusal: `chain to "${s.flowRef}" refused — depth ${c.length} reached the limit of ${l} (${c.join(" → ")})` });
|
|
563
563
|
return;
|
|
564
564
|
}
|
|
565
565
|
let u = {
|
|
@@ -568,7 +568,7 @@ var N = ke("_voltro_ai_flows", {
|
|
|
568
568
|
}, d = {};
|
|
569
569
|
for (let e of s.mappings) e.sourceKey in u && (d[e.targetKey] = u[e.sourceKey]);
|
|
570
570
|
if (s.requireConfirmation) {
|
|
571
|
-
yield*
|
|
571
|
+
yield* J(e, t, { chainPending: {
|
|
572
572
|
flowRef: s.flowRef,
|
|
573
573
|
input: d,
|
|
574
574
|
status: "pending"
|
|
@@ -578,9 +578,9 @@ var N = ke("_voltro_ai_flows", {
|
|
|
578
578
|
let f = e.workflows;
|
|
579
579
|
if (!f) return;
|
|
580
580
|
let p = `${t}--chain`, m = `${a.requestId}--chain`;
|
|
581
|
-
yield*
|
|
581
|
+
yield* x.promise(async () => {
|
|
582
582
|
try {
|
|
583
|
-
await e.store.insert(
|
|
583
|
+
await e.store.insert(N.tableName, {
|
|
584
584
|
id: p,
|
|
585
585
|
flowRef: s.flowRef,
|
|
586
586
|
flowName: s.flowRef,
|
|
@@ -598,60 +598,60 @@ var N = ke("_voltro_ai_flows", {
|
|
|
598
598
|
requestId: m,
|
|
599
599
|
chainPath: c
|
|
600
600
|
});
|
|
601
|
-
}).pipe(
|
|
602
|
-
}),
|
|
601
|
+
}).pipe(x.catchAllCause(() => x.void));
|
|
602
|
+
}), yt = (e) => e.steps.length === 0 ? "" : "Suggested plan (you MAY reorder, insert, or skip steps):\n" + e.steps.map((e, t) => `${t + 1}. [${e.type}${e.modality ? `/${e.modality}` : ""}] ${e.title ?? e.id}${e.prompt ? `: ${e.prompt}` : ""}`).join("\n"), bt = (e) => {
|
|
603
603
|
let t = Object.entries(e);
|
|
604
604
|
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");
|
|
605
|
-
},
|
|
605
|
+
}, xt = (e) => [
|
|
606
606
|
e.orchestrator?.instructions ?? "You are an orchestrator that uses the available tools to produce a bundled result.",
|
|
607
|
-
|
|
607
|
+
yt(e),
|
|
608
608
|
"When finished, emit a JSON object mapping each deliverable name (outputKey) to its value."
|
|
609
|
-
].filter(Boolean).join("\n\n"),
|
|
610
|
-
object:
|
|
611
|
-
key:
|
|
612
|
-
value:
|
|
609
|
+
].filter(Boolean).join("\n\n"), St = S.Struct({
|
|
610
|
+
object: S.Record({
|
|
611
|
+
key: S.String,
|
|
612
|
+
value: S.Unknown
|
|
613
613
|
}),
|
|
614
|
-
planCostMicroUsd:
|
|
615
|
-
toolCostMicroUsd:
|
|
616
|
-
steps:
|
|
617
|
-
error:
|
|
618
|
-
}),
|
|
619
|
-
yield*
|
|
614
|
+
planCostMicroUsd: S.Number,
|
|
615
|
+
toolCostMicroUsd: S.Number,
|
|
616
|
+
steps: S.Array(pe),
|
|
617
|
+
error: S.optional(S.String)
|
|
618
|
+
}), Ct = (e, t, n, r, i, a, o) => x.gen(function* () {
|
|
619
|
+
yield* J(e, n, {
|
|
620
620
|
status: "running",
|
|
621
|
-
startedAt:
|
|
621
|
+
startedAt: G(),
|
|
622
622
|
totalSteps: r.steps.length
|
|
623
623
|
});
|
|
624
|
-
let s = yield*
|
|
624
|
+
let s = yield* k({
|
|
625
625
|
name: "flow-agentic",
|
|
626
626
|
input: { flowRef: r.name },
|
|
627
|
-
success:
|
|
628
|
-
execute:
|
|
627
|
+
success: St,
|
|
628
|
+
execute: x.gen(function* () {
|
|
629
629
|
let s = [], c = 0, l = (e) => {
|
|
630
630
|
let t = s.length;
|
|
631
631
|
return s.push({
|
|
632
632
|
id: t,
|
|
633
633
|
status: "running",
|
|
634
|
-
startedAt:
|
|
634
|
+
startedAt: G(),
|
|
635
635
|
...e
|
|
636
636
|
}), t;
|
|
637
637
|
}, u = (e, t) => {
|
|
638
638
|
s[e] = {
|
|
639
639
|
...s[e],
|
|
640
|
-
completedAt:
|
|
640
|
+
completedAt: G(),
|
|
641
641
|
...t
|
|
642
642
|
};
|
|
643
|
-
}, d = () =>
|
|
643
|
+
}, d = () => J(e, n, {
|
|
644
644
|
steps: s,
|
|
645
645
|
currentStep: s.length,
|
|
646
646
|
costMicroUsd: c
|
|
647
|
-
}), f =
|
|
647
|
+
}), f = A({
|
|
648
648
|
name: "run_agent",
|
|
649
649
|
description: "Delegate a text task to an allowed sub-agent. Returns the agent's text.",
|
|
650
|
-
input:
|
|
651
|
-
agentRef:
|
|
652
|
-
prompt:
|
|
650
|
+
input: S.Struct({
|
|
651
|
+
agentRef: S.String,
|
|
652
|
+
prompt: S.String
|
|
653
653
|
}),
|
|
654
|
-
execute: ({ agentRef: e, prompt: n }) =>
|
|
654
|
+
execute: ({ agentRef: e, prompt: n }) => x.gen(function* () {
|
|
655
655
|
let r = l({
|
|
656
656
|
title: `agent:${e}`,
|
|
657
657
|
type: "agent"
|
|
@@ -660,10 +660,10 @@ var N = ke("_voltro_ai_flows", {
|
|
|
660
660
|
status: "failed",
|
|
661
661
|
errorMessage: "no agent resolver configured"
|
|
662
662
|
}), yield* d(), "ERROR: no agent resolver configured";
|
|
663
|
-
let i = yield*
|
|
663
|
+
let i = yield* W(t.resolveAgent(e)).pipe(x.map((e) => ({
|
|
664
664
|
ok: !0,
|
|
665
665
|
a: e
|
|
666
|
-
})),
|
|
666
|
+
})), x.catchAll((e) => x.succeed({
|
|
667
667
|
ok: !1,
|
|
668
668
|
e
|
|
669
669
|
})));
|
|
@@ -671,14 +671,14 @@ var N = ke("_voltro_ai_flows", {
|
|
|
671
671
|
status: "failed",
|
|
672
672
|
errorMessage: i.e.message
|
|
673
673
|
}), yield* d(), `ERROR: ${i.e.message}`;
|
|
674
|
-
let a = yield*
|
|
674
|
+
let a = yield* j({
|
|
675
675
|
system: i.a.system,
|
|
676
676
|
prompt: n,
|
|
677
|
-
provider:
|
|
678
|
-
}).pipe(
|
|
677
|
+
provider: K(t, i.a.model)
|
|
678
|
+
}).pipe(x.map((e) => ({
|
|
679
679
|
ok: !0,
|
|
680
680
|
r: e
|
|
681
|
-
})),
|
|
681
|
+
})), x.catchAll((e) => x.succeed({
|
|
682
682
|
ok: !1,
|
|
683
683
|
e
|
|
684
684
|
})));
|
|
@@ -689,22 +689,22 @@ var N = ke("_voltro_ai_flows", {
|
|
|
689
689
|
errorMessage: e
|
|
690
690
|
}), yield* d(), `ERROR: ${e}`;
|
|
691
691
|
}
|
|
692
|
-
let o =
|
|
692
|
+
let o = q(a.r.usage, a.r.providerMetadata, i.a.model);
|
|
693
693
|
return c += o, u(r, {
|
|
694
694
|
status: "succeeded",
|
|
695
695
|
output: { text: a.r.text },
|
|
696
696
|
costMicroUsd: o
|
|
697
697
|
}), yield* d(), a.r.text;
|
|
698
698
|
})
|
|
699
|
-
}), p =
|
|
699
|
+
}), p = A({
|
|
700
700
|
name: "generate_media",
|
|
701
701
|
description: "Generate an image, video, or audio artifact. Returns the hosted URL.",
|
|
702
|
-
input:
|
|
703
|
-
modality:
|
|
704
|
-
prompt:
|
|
705
|
-
model:
|
|
702
|
+
input: S.Struct({
|
|
703
|
+
modality: S.Literal("image", "video", "audio"),
|
|
704
|
+
prompt: S.String,
|
|
705
|
+
model: S.optional(S.String)
|
|
706
706
|
}),
|
|
707
|
-
execute: ({ modality: e, prompt: r, model: i }) =>
|
|
707
|
+
execute: ({ modality: e, prompt: r, model: i }) => x.gen(function* () {
|
|
708
708
|
let a = l({
|
|
709
709
|
title: `media:${e}`,
|
|
710
710
|
type: "generate"
|
|
@@ -713,7 +713,7 @@ var N = ke("_voltro_ai_flows", {
|
|
|
713
713
|
status: "failed",
|
|
714
714
|
errorMessage: `no media generator for ${e}`
|
|
715
715
|
}), yield* d(), `ERROR: no media generator configured for ${e}`;
|
|
716
|
-
let s = yield*
|
|
716
|
+
let s = yield* W(t.generateMedia({
|
|
717
717
|
modality: e,
|
|
718
718
|
prompt: r,
|
|
719
719
|
...i ? { model: i } : {},
|
|
@@ -721,10 +721,10 @@ var N = ke("_voltro_ai_flows", {
|
|
|
721
721
|
runId: n,
|
|
722
722
|
tenantId: o
|
|
723
723
|
}
|
|
724
|
-
})).pipe(
|
|
724
|
+
})).pipe(x.map((e) => ({
|
|
725
725
|
ok: !0,
|
|
726
726
|
r: e
|
|
727
|
-
})),
|
|
727
|
+
})), x.catchAll((e) => x.succeed({
|
|
728
728
|
ok: !1,
|
|
729
729
|
e
|
|
730
730
|
})));
|
|
@@ -738,30 +738,30 @@ var N = ke("_voltro_ai_flows", {
|
|
|
738
738
|
errorMessage: s.e.message
|
|
739
739
|
}), yield* d(), `ERROR: ${s.e.message}`);
|
|
740
740
|
})
|
|
741
|
-
}), m =
|
|
741
|
+
}), m = A({
|
|
742
742
|
name: "pick_structured",
|
|
743
743
|
description: "Produce a JSON object for a task. Returns the object.",
|
|
744
|
-
input:
|
|
745
|
-
prompt:
|
|
746
|
-
model:
|
|
744
|
+
input: S.Struct({
|
|
745
|
+
prompt: S.String,
|
|
746
|
+
model: S.optional(S.String)
|
|
747
747
|
}),
|
|
748
|
-
execute: ({ prompt: e, model: n }) =>
|
|
748
|
+
execute: ({ prompt: e, model: n }) => x.gen(function* () {
|
|
749
749
|
let r = l({
|
|
750
750
|
title: "structured",
|
|
751
751
|
type: "structured"
|
|
752
752
|
});
|
|
753
753
|
yield* d();
|
|
754
|
-
let i = yield*
|
|
754
|
+
let i = yield* Re({
|
|
755
755
|
prompt: e,
|
|
756
|
-
schema:
|
|
757
|
-
key:
|
|
758
|
-
value:
|
|
756
|
+
schema: S.Record({
|
|
757
|
+
key: S.String,
|
|
758
|
+
value: S.Unknown
|
|
759
759
|
}),
|
|
760
|
-
...n ? { provider:
|
|
761
|
-
}).pipe(
|
|
760
|
+
...n ? { provider: K(t, n) } : {}
|
|
761
|
+
}).pipe(x.map((e) => ({
|
|
762
762
|
ok: !0,
|
|
763
763
|
r: e
|
|
764
|
-
})),
|
|
764
|
+
})), x.catchAll((e) => x.succeed({
|
|
765
765
|
ok: !1,
|
|
766
766
|
e
|
|
767
767
|
})));
|
|
@@ -772,19 +772,19 @@ var N = ke("_voltro_ai_flows", {
|
|
|
772
772
|
errorMessage: e
|
|
773
773
|
}), yield* d(), { error: e };
|
|
774
774
|
}
|
|
775
|
-
let a =
|
|
775
|
+
let a = q(i.r.usage, i.r.providerMetadata, n);
|
|
776
776
|
return c += a, u(r, {
|
|
777
777
|
status: "succeeded",
|
|
778
778
|
output: { text: JSON.stringify(i.r.object) },
|
|
779
779
|
costMicroUsd: a
|
|
780
780
|
}), yield* d(), i.r.object;
|
|
781
781
|
})
|
|
782
|
-
}), h = t.memoryPrefix ? yield*
|
|
783
|
-
system:
|
|
784
|
-
prompt:
|
|
785
|
-
schema:
|
|
786
|
-
key:
|
|
787
|
-
value:
|
|
782
|
+
}), h = t.memoryPrefix ? yield* W(t.memoryPrefix(a)).pipe(x.catchAll(() => x.succeed(""))) : "", ee = h ? `${h}\n\n${xt(r)}` : xt(r), g = yield* ze({
|
|
783
|
+
system: ee,
|
|
784
|
+
prompt: bt(i),
|
|
785
|
+
schema: S.Record({
|
|
786
|
+
key: S.String,
|
|
787
|
+
value: S.Unknown
|
|
788
788
|
}),
|
|
789
789
|
tools: {
|
|
790
790
|
run_agent: f,
|
|
@@ -792,17 +792,17 @@ var N = ke("_voltro_ai_flows", {
|
|
|
792
792
|
pick_structured: m
|
|
793
793
|
},
|
|
794
794
|
maxSteps: r.maxSteps,
|
|
795
|
-
...r.orchestrator?.model ? { provider:
|
|
796
|
-
}).pipe(
|
|
795
|
+
...r.orchestrator?.model ? { provider: K(t, r.orchestrator.model) } : {}
|
|
796
|
+
}).pipe(x.map((e) => ({
|
|
797
797
|
ok: !0,
|
|
798
798
|
r: e
|
|
799
|
-
})),
|
|
799
|
+
})), x.catchAll((e) => x.succeed({
|
|
800
800
|
ok: !1,
|
|
801
801
|
e
|
|
802
802
|
})));
|
|
803
803
|
return g.ok ? {
|
|
804
804
|
object: g.r.object,
|
|
805
|
-
planCostMicroUsd:
|
|
805
|
+
planCostMicroUsd: q(g.r.usage, g.r.providerMetadata, r.orchestrator?.model),
|
|
806
806
|
toolCostMicroUsd: c,
|
|
807
807
|
steps: s
|
|
808
808
|
} : {
|
|
@@ -814,60 +814,60 @@ var N = ke("_voltro_ai_flows", {
|
|
|
814
814
|
};
|
|
815
815
|
})
|
|
816
816
|
}), c = s.planCostMicroUsd + s.toolCostMicroUsd;
|
|
817
|
-
return s.error ? (yield*
|
|
817
|
+
return s.error ? (yield* J(e, n, {
|
|
818
818
|
status: "failed",
|
|
819
819
|
steps: s.steps,
|
|
820
820
|
errorMessage: s.error,
|
|
821
|
-
completedAt:
|
|
821
|
+
completedAt: G(),
|
|
822
822
|
costMicroUsd: c
|
|
823
823
|
}), {
|
|
824
824
|
runId: n,
|
|
825
825
|
status: "failed"
|
|
826
|
-
}) : (yield*
|
|
826
|
+
}) : (yield* J(e, n, {
|
|
827
827
|
status: "succeeded",
|
|
828
828
|
steps: s.steps,
|
|
829
829
|
output: s.object,
|
|
830
|
-
completedAt:
|
|
830
|
+
completedAt: G(),
|
|
831
831
|
costMicroUsd: c
|
|
832
832
|
}), {
|
|
833
833
|
runId: n,
|
|
834
834
|
status: "succeeded",
|
|
835
835
|
output: s.object
|
|
836
836
|
});
|
|
837
|
-
}),
|
|
838
|
-
let { runId: r, flowRef: i, input: a } = n, o = yield*
|
|
837
|
+
}), wt = (e, t = {}) => (n, r) => x.gen(function* () {
|
|
838
|
+
let { runId: r, flowRef: i, input: a } = n, o = yield* k({
|
|
839
839
|
name: "flow-0-resolve",
|
|
840
840
|
input: { flowRef: i },
|
|
841
|
-
success:
|
|
842
|
-
ir:
|
|
843
|
-
error:
|
|
841
|
+
success: S.Struct({
|
|
842
|
+
ir: S.Unknown,
|
|
843
|
+
error: S.optional(S.String)
|
|
844
844
|
}),
|
|
845
|
-
execute:
|
|
845
|
+
execute: Y(e, i).pipe(x.map((e) => ({ ir: e })), x.catchAll((e) => x.succeed({
|
|
846
846
|
ir: void 0,
|
|
847
847
|
error: e.message
|
|
848
848
|
})))
|
|
849
849
|
});
|
|
850
|
-
if (o.error || !o.ir) return yield*
|
|
850
|
+
if (o.error || !o.ir) return yield* J(e, r, {
|
|
851
851
|
status: "failed",
|
|
852
852
|
errorMessage: o.error ?? "flow not found",
|
|
853
|
-
completedAt:
|
|
853
|
+
completedAt: G()
|
|
854
854
|
}), {
|
|
855
855
|
runId: r,
|
|
856
856
|
status: "failed"
|
|
857
857
|
};
|
|
858
|
-
let s = o.ir, c = (yield*
|
|
858
|
+
let s = o.ir, c = (yield* x.promise(() => e.store.query(E(N).where(C("id", r)).descriptor)).pipe(x.catchAllCause(() => x.succeed([]))))[0], l = c?.ownerId ?? null, u = c?.tenantId ?? null, d = s.mode === "agentic" ? yield* Ct(e, t, r, s, a, l, u) : yield* _t(e, t, r, s, a, {
|
|
859
859
|
ownerId: l,
|
|
860
860
|
tenantId: u,
|
|
861
861
|
source: n.source
|
|
862
862
|
});
|
|
863
|
-
return d.status === "succeeded" && s.chain && (yield*
|
|
863
|
+
return d.status === "succeeded" && s.chain && (yield* vt(e, r, s, a, d.output ?? {}, n, t)), t.onEvent && (d.status === "succeeded" || d.status === "failed") && (yield* W(t.onEvent({
|
|
864
864
|
kind: d.status,
|
|
865
865
|
runId: r,
|
|
866
866
|
flowName: s.name,
|
|
867
867
|
ownerId: l,
|
|
868
868
|
source: n.source
|
|
869
|
-
})).pipe(
|
|
870
|
-
}),
|
|
869
|
+
})).pipe(x.catchAllCause(() => x.void))), d;
|
|
870
|
+
}), Tt = {
|
|
871
871
|
text: (e) => ({
|
|
872
872
|
type: "generate",
|
|
873
873
|
modality: "text",
|
|
@@ -894,31 +894,31 @@ var N = ke("_voltro_ai_flows", {
|
|
|
894
894
|
type: "human",
|
|
895
895
|
...e
|
|
896
896
|
})
|
|
897
|
-
},
|
|
897
|
+
}, Et = (e) => e.map((e, t) => "id" in e && e.id ? e : {
|
|
898
898
|
id: `step-${t}`,
|
|
899
899
|
...e
|
|
900
|
-
}),
|
|
901
|
-
let t = [], r =
|
|
902
|
-
for (let e of
|
|
900
|
+
}), Dt = (e) => {
|
|
901
|
+
let t = [], r = R(e.steps);
|
|
902
|
+
for (let e of rt(r)) t.push(`group "${e}" is not contiguous — only CONSECUTIVE steps sharing a group run concurrently, so this would execute as two separate fan-outs`);
|
|
903
903
|
let i = new Set(e.brief.map((e) => e.key));
|
|
904
904
|
for (let e of r) {
|
|
905
905
|
for (let { step: n } of e.steps) {
|
|
906
906
|
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`);
|
|
907
|
-
for (let r of
|
|
907
|
+
for (let r of I(n.prompt ?? "")) i.has(r) || t.push(e.steps.length > 1 ? `step "${n.id}" references {{${r}}} 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 {{${r}}} which is not a brief field or a prior step outputKey`);
|
|
908
908
|
n.when !== void 0 && !i.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`);
|
|
909
909
|
}
|
|
910
910
|
for (let { step: t } of e.steps) t.outputKey && i.add(n(t.outputKey));
|
|
911
911
|
}
|
|
912
|
-
if (t.length > 0) throw new
|
|
912
|
+
if (t.length > 0) throw new be({
|
|
913
913
|
flowRef: e.name,
|
|
914
914
|
message: `flow "${e.name}" has ${t.length} problem(s)`,
|
|
915
915
|
issues: t
|
|
916
916
|
});
|
|
917
|
-
},
|
|
917
|
+
}, Ot = (e) => {
|
|
918
918
|
let t = r({
|
|
919
919
|
name: e.name,
|
|
920
920
|
mode: e.mode,
|
|
921
|
-
steps:
|
|
921
|
+
steps: Et(e.steps),
|
|
922
922
|
maxSteps: e.maxSteps,
|
|
923
923
|
brief: e.brief,
|
|
924
924
|
orchestratorModel: e.orchestrator?.model,
|
|
@@ -927,10 +927,10 @@ var N = ke("_voltro_ai_flows", {
|
|
|
927
927
|
cadence: e.cadence,
|
|
928
928
|
humanTimeoutMs: e.humanTimeoutMs
|
|
929
929
|
});
|
|
930
|
-
return
|
|
931
|
-
},
|
|
930
|
+
return Dt(t), it(t), t;
|
|
931
|
+
}, X = (e) => String(e).padStart(2, "0"), kt = (e, t) => `cron-${e}-${t.getFullYear()}${X(t.getMonth() + 1)}${X(t.getDate())}-${X(t.getHours())}${X(t.getMinutes())}`, At = async (e) => {
|
|
932
932
|
let t = [];
|
|
933
|
-
for (let e of
|
|
933
|
+
for (let e of ot()) e.cadence && (e.cadence.repeats?.length ?? 0) > 0 && t.push({
|
|
934
934
|
flowRef: e.name,
|
|
935
935
|
cadence: e.cadence,
|
|
936
936
|
defaultInput: e.cadence.defaultInput ?? {}
|
|
@@ -942,11 +942,11 @@ var N = ke("_voltro_ai_flows", {
|
|
|
942
942
|
defaultInput: e.cadence.defaultInput ?? {}
|
|
943
943
|
});
|
|
944
944
|
return t;
|
|
945
|
-
},
|
|
946
|
-
let n = e.workflows, r = [], i = 0, a = await
|
|
945
|
+
}, jt = async (e, t = /* @__PURE__ */ new Date()) => {
|
|
946
|
+
let n = e.workflows, r = [], i = 0, a = await At(e).catch(() => []);
|
|
947
947
|
for (let o of a) {
|
|
948
|
-
if (!
|
|
949
|
-
let a =
|
|
948
|
+
if (!Se(o.cadence, t) || (i += 1, !n)) continue;
|
|
949
|
+
let a = kt(o.flowRef, t), s = `run-${a}`;
|
|
950
950
|
try {
|
|
951
951
|
try {
|
|
952
952
|
await e.store.insert("_voltro_ai_flow_runs", {
|
|
@@ -972,25 +972,25 @@ var N = ke("_voltro_ai_flows", {
|
|
|
972
972
|
matched: i,
|
|
973
973
|
started: r
|
|
974
974
|
};
|
|
975
|
-
},
|
|
975
|
+
}, Mt = (e) => ({
|
|
976
976
|
name: "gateway",
|
|
977
977
|
model: e
|
|
978
|
-
}),
|
|
979
|
-
let r =
|
|
980
|
-
return typeof r == "number" ?
|
|
978
|
+
}), Nt = (e) => Math.round(e * 1e6), Z = (e, t, n) => {
|
|
979
|
+
let r = Ie(t);
|
|
980
|
+
return typeof r == "number" ? Nt(r) : e ? Fe(e, { model: n ?? "unknown" }).costMicroUsd ?? 0 : 0;
|
|
981
981
|
}, Pt = (e, t) => (n) => {
|
|
982
|
-
let r = n.model, i = (e) => t?.resolveModel?.(e) ??
|
|
983
|
-
return
|
|
982
|
+
let r = n.model, i = (e) => t?.resolveModel?.(e) ?? Mt(e);
|
|
983
|
+
return x.gen(function* () {
|
|
984
984
|
if (n.modality === "image") {
|
|
985
|
-
let t = yield*
|
|
985
|
+
let t = yield* Le({
|
|
986
986
|
prompt: n.prompt,
|
|
987
987
|
...r ? { provider: i(r) } : {}
|
|
988
988
|
}), a = t.images[0];
|
|
989
|
-
if (!a) return yield*
|
|
989
|
+
if (!a) return yield* x.fail(new y({
|
|
990
990
|
capability: "media:image",
|
|
991
991
|
message: "no image produced"
|
|
992
992
|
}));
|
|
993
|
-
let o = yield*
|
|
993
|
+
let o = yield* x.promise(() => e.put({
|
|
994
994
|
data: a.data,
|
|
995
995
|
mediaType: a.mediaType,
|
|
996
996
|
run: n.run
|
|
@@ -998,14 +998,14 @@ var N = ke("_voltro_ai_flows", {
|
|
|
998
998
|
return {
|
|
999
999
|
url: o.url,
|
|
1000
1000
|
...o.refId ? { requestId: o.refId } : {},
|
|
1001
|
-
costMicroUsd:
|
|
1001
|
+
costMicroUsd: Z(t.usage, t.providerMetadata, r)
|
|
1002
1002
|
};
|
|
1003
1003
|
}
|
|
1004
1004
|
if (n.modality === "audio") {
|
|
1005
|
-
let t = yield*
|
|
1005
|
+
let t = yield* Be({
|
|
1006
1006
|
text: n.prompt,
|
|
1007
1007
|
...r ? { provider: i(r) } : {}
|
|
1008
|
-
}), a = yield*
|
|
1008
|
+
}), a = yield* x.promise(() => e.put({
|
|
1009
1009
|
data: t.audio.data,
|
|
1010
1010
|
mediaType: t.audio.mediaType,
|
|
1011
1011
|
run: n.run
|
|
@@ -1013,41 +1013,41 @@ var N = ke("_voltro_ai_flows", {
|
|
|
1013
1013
|
return {
|
|
1014
1014
|
url: a.url,
|
|
1015
1015
|
...a.refId ? { requestId: a.refId } : {},
|
|
1016
|
-
costMicroUsd:
|
|
1016
|
+
costMicroUsd: Z(t.usage, t.providerMetadata, r)
|
|
1017
1017
|
};
|
|
1018
1018
|
}
|
|
1019
|
-
let t = yield*
|
|
1019
|
+
let t = yield* Ve({
|
|
1020
1020
|
prompt: n.prompt,
|
|
1021
1021
|
...r ? { provider: i(r) } : {},
|
|
1022
1022
|
...n.params ? { params: n.params } : {}
|
|
1023
1023
|
}), a;
|
|
1024
|
-
if (t.video.url) a = e.ingestUrl ? yield*
|
|
1025
|
-
else if (t.video.data) a = yield*
|
|
1024
|
+
if (t.video.url) a = e.ingestUrl ? yield* x.promise(() => e.ingestUrl(t.video.url, n.run)) : { url: t.video.url };
|
|
1025
|
+
else if (t.video.data) a = yield* x.promise(() => e.put({
|
|
1026
1026
|
data: t.video.data,
|
|
1027
1027
|
mediaType: t.video.mediaType,
|
|
1028
1028
|
run: n.run
|
|
1029
1029
|
}));
|
|
1030
|
-
else return yield*
|
|
1030
|
+
else return yield* x.fail(new y({
|
|
1031
1031
|
capability: "media:video",
|
|
1032
1032
|
message: "no video produced"
|
|
1033
1033
|
}));
|
|
1034
1034
|
return {
|
|
1035
1035
|
url: a.url,
|
|
1036
1036
|
...a.refId ? { requestId: a.refId } : {},
|
|
1037
|
-
costMicroUsd:
|
|
1037
|
+
costMicroUsd: Z(t.usage, t.providerMetadata, r)
|
|
1038
1038
|
};
|
|
1039
|
-
}).pipe(
|
|
1039
|
+
}).pipe(x.catchAll((e) => e instanceof y ? x.fail(e) : x.fail(new y({
|
|
1040
1040
|
capability: `media:${n.modality}`,
|
|
1041
1041
|
message: String(e.message ?? e)
|
|
1042
1042
|
}))));
|
|
1043
|
-
}, Q = () => globalThis.crypto?.randomUUID?.() ?? `req-${Date.now().toString(36)}`, Ft = (e) => e.request?.subject?.id ?? null, $ = (e, t) =>
|
|
1044
|
-
let n = yield*
|
|
1045
|
-
if (i.length > 0) return yield*
|
|
1043
|
+
}, Q = () => globalThis.crypto?.randomUUID?.() ?? `req-${Date.now().toString(36)}`, Ft = (e) => e.request?.subject?.id ?? null, $ = (e, t) => x.promise(() => e.store.query(E(N).where(C("id", t)).descriptor)).pipe(x.map((e) => e[0])), It = (e, t) => x.gen(function* () {
|
|
1044
|
+
let n = yield* Y(e, t.flowRef), r = t.input ?? {}, i = n.brief.filter((e) => e.required && e.type !== "boolean" && (r[e.key] === void 0 || r[e.key] === null || r[e.key] === "")).map((e) => e.key);
|
|
1045
|
+
if (i.length > 0) return yield* x.fail(new ge({
|
|
1046
1046
|
missing: i,
|
|
1047
1047
|
message: `missing required brief field(s): ${i.join(", ")}`
|
|
1048
1048
|
}));
|
|
1049
1049
|
let a = Q(), o = `run-${a}`, s = t.source ?? "manual";
|
|
1050
|
-
yield*
|
|
1050
|
+
yield* x.promise(() => e.store.insert(N.tableName, {
|
|
1051
1051
|
id: o,
|
|
1052
1052
|
flowRef: t.flowRef,
|
|
1053
1053
|
flowName: n.name,
|
|
@@ -1059,7 +1059,7 @@ var N = ke("_voltro_ai_flows", {
|
|
|
1059
1059
|
ownerId: Ft(e)
|
|
1060
1060
|
}));
|
|
1061
1061
|
let c = e.workflows;
|
|
1062
|
-
return c && (yield*
|
|
1062
|
+
return c && (yield* x.promise(() => c.start(_, {
|
|
1063
1063
|
runId: o,
|
|
1064
1064
|
flowRef: t.flowRef,
|
|
1065
1065
|
input: r,
|
|
@@ -1070,20 +1070,20 @@ var N = ke("_voltro_ai_flows", {
|
|
|
1070
1070
|
requestId: a,
|
|
1071
1071
|
status: "pending"
|
|
1072
1072
|
};
|
|
1073
|
-
}), Lt = (e, t) =>
|
|
1073
|
+
}), Lt = (e, t) => x.gen(function* () {
|
|
1074
1074
|
let n = yield* $(e, t.runId);
|
|
1075
|
-
if (!n) return yield*
|
|
1075
|
+
if (!n) return yield* x.fail(new b({
|
|
1076
1076
|
runId: t.runId,
|
|
1077
1077
|
message: "run not found"
|
|
1078
1078
|
}));
|
|
1079
1079
|
let r = n.requestId ?? Q(), i = n.flowRef, a = n.input ?? {}, o = n.source ?? "manual";
|
|
1080
|
-
yield*
|
|
1080
|
+
yield* x.promise(() => e.store.update(N.tableName, t.runId, {
|
|
1081
1081
|
status: "pending",
|
|
1082
1082
|
error: null,
|
|
1083
1083
|
errorMessage: null
|
|
1084
1084
|
}));
|
|
1085
1085
|
let s = e.workflows;
|
|
1086
|
-
return s && (yield*
|
|
1086
|
+
return s && (yield* x.promise(() => s.start(_, {
|
|
1087
1087
|
runId: t.runId,
|
|
1088
1088
|
flowRef: i,
|
|
1089
1089
|
input: a,
|
|
@@ -1094,14 +1094,14 @@ var N = ke("_voltro_ai_flows", {
|
|
|
1094
1094
|
requestId: r,
|
|
1095
1095
|
status: "pending"
|
|
1096
1096
|
};
|
|
1097
|
-
}), Rt = (e, t) =>
|
|
1098
|
-
return (yield* $(e, t.runId)) ? (yield*
|
|
1097
|
+
}), Rt = (e, t) => x.gen(function* () {
|
|
1098
|
+
return (yield* $(e, t.runId)) ? (yield* x.promise(() => e.store.update(N.tableName, t.runId, {
|
|
1099
1099
|
status: "cancelled",
|
|
1100
1100
|
cancelledAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1101
1101
|
})), {
|
|
1102
1102
|
runId: t.runId,
|
|
1103
1103
|
status: "cancelled"
|
|
1104
|
-
}) : yield*
|
|
1104
|
+
}) : yield* x.fail(new b({
|
|
1105
1105
|
runId: t.runId,
|
|
1106
1106
|
message: "run not found"
|
|
1107
1107
|
}));
|
|
@@ -1110,14 +1110,14 @@ var N = ke("_voltro_ai_flows", {
|
|
|
1110
1110
|
if (t !== void 0) return t.id;
|
|
1111
1111
|
let n = e.currentStep;
|
|
1112
1112
|
return typeof n == "number" ? n : 0;
|
|
1113
|
-
}, Bt = (e, t) =>
|
|
1113
|
+
}, Bt = (e, t) => x.gen(function* () {
|
|
1114
1114
|
let n = yield* $(e, t.runId);
|
|
1115
|
-
if (!n) return yield*
|
|
1115
|
+
if (!n) return yield* x.fail(new b({
|
|
1116
1116
|
runId: t.runId,
|
|
1117
1117
|
message: "run not found"
|
|
1118
1118
|
}));
|
|
1119
1119
|
let r = n.status;
|
|
1120
|
-
if (r !== "waiting") return yield*
|
|
1120
|
+
if (r !== "waiting") return yield* x.fail(new ve({
|
|
1121
1121
|
runId: t.runId,
|
|
1122
1122
|
status: r ?? "unknown",
|
|
1123
1123
|
message: `run is "${r}", not awaiting a response`
|
|
@@ -1126,31 +1126,31 @@ var N = ke("_voltro_ai_flows", {
|
|
|
1126
1126
|
...t.response,
|
|
1127
1127
|
respondedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1128
1128
|
};
|
|
1129
|
-
yield*
|
|
1129
|
+
yield* x.promise(() => e.store.update(N.tableName, t.runId, { humanResponse: i }));
|
|
1130
1130
|
let a = e.workflows, o = n.requestId, s = zt(n);
|
|
1131
|
-
return a && o && (yield*
|
|
1132
|
-
workflowName:
|
|
1131
|
+
return a && o && (yield* x.promise(() => a.signal({
|
|
1132
|
+
workflowName: _,
|
|
1133
1133
|
executionId: `flow-run:${o}`
|
|
1134
|
-
},
|
|
1134
|
+
}, v(s), i)).pipe(x.catchAllCause(() => x.void))), {
|
|
1135
1135
|
runId: t.runId,
|
|
1136
1136
|
stepIndex: s
|
|
1137
1137
|
};
|
|
1138
|
-
}), Vt = (e, t) =>
|
|
1138
|
+
}), Vt = (e, t) => x.promise(() => e.store.query(E(M).where(C("id", t.id)).descriptor)).pipe(x.map((e) => e[0])), Ht = (e) => x.promise(() => e.store.query(E(M).descriptor)), Ut = (e, t) => x.promise(() => e.store.insert(M.tableName, {
|
|
1139
1139
|
id: t.id ?? `flow-${Q()}`,
|
|
1140
1140
|
...t
|
|
1141
|
-
})), Wt = (e, t) =>
|
|
1142
|
-
let t =
|
|
1141
|
+
})), Wt = (e, t) => x.promise(() => e.store.update(M.tableName, t.id, t.patch)), Gt = (e, t) => x.promise(() => e.store.delete(M.tableName, t.id)), Kt = "aiFlows", qt = (e = {}) => {
|
|
1142
|
+
let t = Te({
|
|
1143
1143
|
base: Kt,
|
|
1144
1144
|
alias: e.alias
|
|
1145
1145
|
});
|
|
1146
|
-
|
|
1146
|
+
Ye(e.humanReviewTimeoutMs === void 0 ? {} : { humanReviewTimeoutMs: e.humanReviewTimeoutMs }), ke({
|
|
1147
1147
|
source: "plugin",
|
|
1148
|
-
table:
|
|
1148
|
+
table: N.tableName,
|
|
1149
1149
|
timeColumn: "createdAt",
|
|
1150
|
-
ttlMs: e.runsTtlMs ??
|
|
1151
|
-
envVar:
|
|
1150
|
+
ttlMs: e.runsTtlMs ?? Ze(process.env.VOLTRO_AI_FLOW_RUNS_TTL_HOURS, 2160),
|
|
1151
|
+
envVar: Ke,
|
|
1152
1152
|
label: "ai flow runs",
|
|
1153
|
-
where:
|
|
1153
|
+
where: Oe("status", [
|
|
1154
1154
|
"succeeded",
|
|
1155
1155
|
"failed",
|
|
1156
1156
|
"cancelled"
|
|
@@ -1163,7 +1163,7 @@ var N = ke("_voltro_ai_flows", {
|
|
|
1163
1163
|
kind: "json",
|
|
1164
1164
|
status: e,
|
|
1165
1165
|
data: { error: t }
|
|
1166
|
-
}), o = (e, t) =>
|
|
1166
|
+
}), o = (e, t) => x.promise(async () => {
|
|
1167
1167
|
let n = r.current;
|
|
1168
1168
|
if (!n) return a(503, "store not bound yet");
|
|
1169
1169
|
let o = await n.query({
|
|
@@ -1179,7 +1179,7 @@ var N = ke("_voltro_ai_flows", {
|
|
|
1179
1179
|
rows: o,
|
|
1180
1180
|
take: t
|
|
1181
1181
|
});
|
|
1182
|
-
}).pipe(
|
|
1182
|
+
}).pipe(x.catchAllCause(() => x.succeed(a(500, "query failed")))), s = (e, t) => {
|
|
1183
1183
|
let r = /[?&]take=(\d+)/.exec(e)?.[1], i = r === void 0 ? t : Number(r);
|
|
1184
1184
|
return Math.min(n, Math.max(1, Number.isFinite(i) ? i : t));
|
|
1185
1185
|
}, c = [{
|
|
@@ -1193,12 +1193,12 @@ var N = ke("_voltro_ai_flows", {
|
|
|
1193
1193
|
description: "List recent flow runs (`?take=` up to the configured max).",
|
|
1194
1194
|
handler: (e) => o("_voltro_ai_flow_runs", s(e.url, Math.min(100, n)))
|
|
1195
1195
|
}];
|
|
1196
|
-
return
|
|
1196
|
+
return we({
|
|
1197
1197
|
name: t,
|
|
1198
1198
|
baseName: Kt,
|
|
1199
1199
|
description: "AI Flows — durable multi-step AI pipelines (deterministic + agentic) with human-in-the-loop, chaining, and cadence. Code-first (defineFlow) or data-driven.",
|
|
1200
1200
|
permissions: ["store:write", "inspect:read"],
|
|
1201
|
-
...e.tables === !1 ? {} : { extendSchema: { tables:
|
|
1201
|
+
...e.tables === !1 ? {} : { extendSchema: { tables: He } },
|
|
1202
1202
|
inspectEndpoints: c,
|
|
1203
1203
|
bindDataStore: (e) => {
|
|
1204
1204
|
r.current = e;
|
|
@@ -1206,4 +1206,4 @@ var N = ke("_voltro_ai_flows", {
|
|
|
1206
1206
|
});
|
|
1207
1207
|
};
|
|
1208
1208
|
//#endregion
|
|
1209
|
-
export {
|
|
1209
|
+
export { le as BriefField, ie as ChainPending, a as ConditionOp, Ke as FLOW_RUNS_TTL_ENV, Ge as FLOW_RUNS_TTL_HOURS_DEFAULT, _ as FLOW_RUN_WORKFLOW, se as FlowCadence, ee as FlowChain, l as FlowMode, ae as FlowStatus, ce as FlowStep, he as HUMAN_RESPONSE_SIGNAL_PREFIX, We as HUMAN_REVIEW_TIMEOUT_ENV, Ue as HUMAN_REVIEW_TIMEOUT_HOURS_DEFAULT, d as HumanResponse, ne as Json, qe as MAX_CHAIN_DEPTH_DEFAULT, Je as MAX_CHAIN_DEPTH_ENV, ue as MAX_STEPS_DEFAULT, f as MAX_STEPS_MAX, p as MAX_STEPS_MIN, oe as MediaInputSlot, re as MediaInputs, h as Modality, m as ReviewMode, c as ReviewOption, de as RunReview, me as RunSource, u as RunStatus, pe as RunStep, o as RunStepStatus, te as StepCondition, t as StepType, fe as Visibility, N as aiFlowRunsTable, qt as aiFlowsPlugin, M as aiFlowsTable, He as aiFlowsTables, wt as buildFlowRunExecute, Se as cadenceMatches, Rt as cancelFlow, s as clampMaxSteps, st as clearRegistry, I as collectRefs, Ut as createFlow, kt as cronRequestId, Ot as defineFlow, Gt as deleteFlow, e as describeCondition, g as evaluateCondition, R as flowSegments, Tt as flowStep, F as getAiFlowsDefaults, Vt as getFlow, at as getRegisteredFlow, v as humanResponseSignalName, L as interpolate, i as isTruthy, ft as jsonSchemaToEffectSchema, It as launchFlow, Ht as listFlows, ot as listRegisteredFlows, Pt as makeMediaGenerator, xe as nextRuns, rt as nonContiguousGroups, r as normalizeFlow, it as registerFlow, Xe as resetAiFlowsDefaults, $e as resolveHumanReviewTimeoutMs, Y as resolveIr, et as resolveMaxChainDepth, Bt as respondToFlow, Lt as retryFlow, jt as runCadenceTick, n as sanitizeOutputKey, Ye as setAiFlowsDefaults, nt as unresolvedRefs, Wt as updateFlow, Dt as validateFlow, zt as waitingStepIndex };
|