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