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