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