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