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