@voltro/plugin-ai-flows 0.83.1 → 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 +642 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +632 -621
- 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 { SuspensionUnavailable 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 N = /* @__PURE__ */ new Map(), ct = (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 N = /* @__PURE__ */ new Map(), ct = (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 N = /* @__PURE__ */ new Map(), ct = (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 N = /* @__PURE__ */ new Map(), ct = (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 N = /* @__PURE__ */ new Map(), ct = (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
|
-
}),
|
|
209
|
-
maxTokens:
|
|
210
|
-
temperature:
|
|
211
|
-
providerOptions:
|
|
212
|
-
}),
|
|
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
|
+
}), Ft = [
|
|
213
213
|
"maxTokens",
|
|
214
214
|
"temperature",
|
|
215
215
|
"providerOptions"
|
|
216
|
-
],
|
|
216
|
+
], It = (e) => {
|
|
217
217
|
if (typeof e != "object" || !e || Array.isArray(e)) return "params must be an object";
|
|
218
|
-
let t = Object.keys(e), n = t.filter((e) => !
|
|
218
|
+
let t = Object.keys(e), n = t.filter((e) => !Ft.includes(e)).sort(), r = t.filter((t) => Ft.includes(t) && 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
|
-
},
|
|
221
|
-
try: () =>
|
|
222
|
-
catch: () => `invalid text params (${
|
|
223
|
-
}),
|
|
220
|
+
}, Lt = (e) => O.try({
|
|
221
|
+
try: () => k.decodeUnknownSync(Pt, { onExcessProperty: "error" })(e === void 0 ? {} : e),
|
|
222
|
+
catch: () => `invalid text params (${It(e)}): expected maxTokens (positive safe integer), temperature (finite nonnegative number), and/or providerOptions (provider-keyed JSON object); other fields are not supported`
|
|
223
|
+
}), 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
|
-
})),
|
|
231
|
-
key:
|
|
232
|
-
value:
|
|
233
|
-
}),
|
|
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
|
-
}),
|
|
240
|
-
url:
|
|
241
|
-
mediaType:
|
|
239
|
+
}), Bt = k.Struct({
|
|
240
|
+
url: V,
|
|
241
|
+
mediaType: k.NonEmptyString
|
|
242
242
|
});
|
|
243
|
-
|
|
244
|
-
key:
|
|
245
|
-
value:
|
|
243
|
+
k.Record({
|
|
244
|
+
key: k.String,
|
|
245
|
+
value: Bt
|
|
246
246
|
});
|
|
247
|
-
var
|
|
248
|
-
let n =
|
|
247
|
+
var Vt = (e, t = {}) => {
|
|
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 Ht = (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
|
-
},
|
|
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 Ht = (e, t = {}) => {
|
|
|
277
277
|
return n;
|
|
278
278
|
},
|
|
279
279
|
catch: () => `invalid or unsupported media input for ${e}; check the built-in adapter's slot contract`
|
|
280
|
-
}),
|
|
281
|
-
artifacts:
|
|
282
|
-
costMicroUsd:
|
|
283
|
-
costSource:
|
|
284
|
-
requestId:
|
|
285
|
-
usage:
|
|
286
|
-
}),
|
|
287
|
-
try: () =>
|
|
280
|
+
}), Ut = 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
|
-
}),
|
|
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 Ht = (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
|
-
}),
|
|
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
|
-
costMicroUsd:
|
|
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 Ht = (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 Ht = (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*
|
|
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*
|
|
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 =
|
|
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 Ht = (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
|
})));
|
|
@@ -483,15 +483,15 @@ var Ht = (e, t = {}) => {
|
|
|
483
483
|
...e === void 0 ? {} : e
|
|
484
484
|
};
|
|
485
485
|
}
|
|
486
|
-
return yield*
|
|
486
|
+
return yield* qt(d.m);
|
|
487
487
|
}
|
|
488
|
-
case "human": return { error: new
|
|
488
|
+
case "human": return { error: new 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}`,
|
|
@@ -499,26 +499,26 @@ var Ht = (e, t = {}) => {
|
|
|
499
499
|
status: "pending",
|
|
500
500
|
...e.description ? { description: e.description } : {}
|
|
501
501
|
})), d = 0;
|
|
502
|
-
yield*
|
|
502
|
+
yield* Qt(e, n, {
|
|
503
503
|
status: "running",
|
|
504
504
|
steps: u,
|
|
505
505
|
totalSteps: i.steps.length,
|
|
506
506
|
currentStep: 0,
|
|
507
|
-
startedAt:
|
|
507
|
+
startedAt: W()
|
|
508
508
|
}, "startedAt");
|
|
509
|
-
for (let o of
|
|
510
|
-
if (yield*
|
|
509
|
+
for (let o of Mt(i.steps)) {
|
|
510
|
+
if (yield* $t(e, n)) return yield* en(e, n), {
|
|
511
511
|
runId: n,
|
|
512
512
|
status: "cancelled"
|
|
513
513
|
};
|
|
514
514
|
if (o.steps.length > 1) {
|
|
515
515
|
let r = [];
|
|
516
516
|
for (let { index: e, step: t } of o.steps) {
|
|
517
|
-
if (t.when !== void 0 && !
|
|
517
|
+
if (t.when !== void 0 && !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,23 +529,23 @@ var Ht = (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
|
-
success:
|
|
542
|
+
success: Kt,
|
|
543
543
|
execute: nn(e, t, i, c, {
|
|
544
544
|
runId: n,
|
|
545
545
|
tenantId: s.tenantId,
|
|
546
546
|
ownerId: s.ownerId
|
|
547
547
|
}, l)
|
|
548
|
-
}).pipe(
|
|
548
|
+
}).pipe(O.map((e) => ({
|
|
549
549
|
index: r,
|
|
550
550
|
step: i,
|
|
551
551
|
result: e
|
|
@@ -555,49 +555,49 @@ var Ht = (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 Ht = (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
|
-
}), l = yield*
|
|
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 Ht = (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 Ht = (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 Ht = (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,15 +692,15 @@ var Ht = (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
|
-
success:
|
|
703
|
+
success: Kt,
|
|
704
704
|
execute: nn(e, t, p, c, {
|
|
705
705
|
runId: n,
|
|
706
706
|
tenantId: s.tenantId,
|
|
@@ -710,16 +710,16 @@ var Ht = (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 Ht = (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 Ht = (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 Ht = (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,8 +801,8 @@ var Ht = (e, t = {}) => {
|
|
|
801
801
|
requestId: m,
|
|
802
802
|
chainPath: c
|
|
803
803
|
});
|
|
804
|
-
}).pipe(
|
|
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 =
|
|
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
806
|
try {
|
|
807
807
|
let t = JSON.parse(e);
|
|
808
808
|
return typeof t == "object" && t && !Array.isArray(t) ? t : void 0;
|
|
@@ -810,9 +810,9 @@ var Ht = (e, t = {}) => {
|
|
|
810
810
|
return;
|
|
811
811
|
}
|
|
812
812
|
}, pn = (e) => {
|
|
813
|
-
if (
|
|
814
|
-
if (
|
|
815
|
-
let t =
|
|
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
816
|
return t instanceof Error ? t.message : String(t);
|
|
817
817
|
}, mn = (e) => {
|
|
818
818
|
let t = Object.entries(e);
|
|
@@ -820,257 +820,265 @@ var Ht = (e, t = {}) => {
|
|
|
820
820
|
}, hn = (e) => [
|
|
821
821
|
e.orchestrator?.instructions ?? "You are an orchestrator that uses the available tools to produce a bundled result.",
|
|
822
822
|
sn(e),
|
|
823
|
-
"When finished, emit a JSON object mapping each deliverable name (outputKey) to its value."
|
|
824
|
-
].filter(Boolean).join("\n\n"), gn =
|
|
825
|
-
object:
|
|
826
|
-
key:
|
|
827
|
-
value:
|
|
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
|
|
828
828
|
}),
|
|
829
|
-
planCostMicroUsd:
|
|
830
|
-
planCostSource:
|
|
831
|
-
toolCostMicroUsd:
|
|
832
|
-
steps:
|
|
833
|
-
error:
|
|
834
|
-
}), _n = (e, t, n, r, i, a, o, s) =>
|
|
835
|
-
yield*
|
|
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* () {
|
|
835
|
+
yield* Qt(e, n, {
|
|
836
836
|
status: "running",
|
|
837
|
-
startedAt:
|
|
837
|
+
startedAt: W(),
|
|
838
838
|
totalSteps: r.steps.length
|
|
839
839
|
}, "startedAt");
|
|
840
|
-
let c = yield*
|
|
840
|
+
let c = yield* F({
|
|
841
841
|
name: "flow-agentic",
|
|
842
842
|
input: { flowRef: r.name },
|
|
843
843
|
success: gn,
|
|
844
|
-
execute:
|
|
844
|
+
execute: O.gen(function* () {
|
|
845
845
|
let c = [], l = 0, u = (e) => {
|
|
846
846
|
let t = c.length;
|
|
847
847
|
return c.push({
|
|
848
848
|
id: t,
|
|
849
849
|
status: "running",
|
|
850
|
-
startedAt:
|
|
850
|
+
startedAt: W(),
|
|
851
851
|
...e
|
|
852
852
|
}), t;
|
|
853
853
|
}, d = (e, t) => {
|
|
854
854
|
c[e] = {
|
|
855
855
|
...c[e],
|
|
856
|
-
completedAt:
|
|
856
|
+
completedAt: W(),
|
|
857
857
|
...t
|
|
858
858
|
};
|
|
859
|
-
}, f = () =>
|
|
859
|
+
}, f = () => J(e, n, {
|
|
860
860
|
steps: c,
|
|
861
861
|
currentStep: c.length,
|
|
862
862
|
costMicroUsd: l
|
|
863
|
-
}), p = (e, t) =>
|
|
863
|
+
}), p = (e, t) => O.suspend(() => {
|
|
864
864
|
let n = u(e);
|
|
865
|
-
return
|
|
865
|
+
return O.zipRight(f(), t(n)).pipe(O.onExit((e) => c[n]?.status === "running" ? (d(n, {
|
|
866
866
|
status: "failed",
|
|
867
867
|
errorMessage: pn(e)
|
|
868
|
-
}),
|
|
869
|
-
}), m = (t.listAgents ?
|
|
868
|
+
}), O.ignore(f())) : O.void));
|
|
869
|
+
}), m = yield* (t.listAgents ? H(t.listAgents({
|
|
870
870
|
runId: n,
|
|
871
871
|
tenantId: o,
|
|
872
872
|
ownerId: a
|
|
873
|
-
}))
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
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, {
|
|
889
924
|
status: "failed",
|
|
890
|
-
errorMessage:
|
|
891
|
-
}), yield* f(),
|
|
892
|
-
|
|
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: {
|
|
893
966
|
runId: n,
|
|
894
967
|
tenantId: o,
|
|
895
968
|
ownerId: a
|
|
896
|
-
})).pipe(w.map((e) => ({
|
|
897
|
-
ok: !0,
|
|
898
|
-
a: e
|
|
899
|
-
})), w.catchAll((e) => w.succeed({
|
|
900
|
-
ok: !1,
|
|
901
|
-
e
|
|
902
|
-
})));
|
|
903
|
-
if (!s.ok) return d(i, {
|
|
904
|
-
status: "failed",
|
|
905
|
-
errorMessage: s.e.message
|
|
906
|
-
}), yield* f(), `ERROR: ${Kt(s.e)}`;
|
|
907
|
-
let c = yield* Zt(t, s.a, r, {}).pipe(w.map((e) => ({
|
|
908
|
-
ok: !0,
|
|
909
|
-
r: e
|
|
910
|
-
})), w.catchAll((e) => w.succeed({
|
|
911
|
-
ok: !1,
|
|
912
|
-
e
|
|
913
|
-
})));
|
|
914
|
-
if (!c.ok) {
|
|
915
|
-
let e = String(c.e.message ?? c.e);
|
|
916
|
-
return d(i, {
|
|
917
|
-
status: "failed",
|
|
918
|
-
errorMessage: e
|
|
919
|
-
}), yield* f(), `ERROR: ${e}`;
|
|
920
969
|
}
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
}))
|
|
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)
|
|
928
1001
|
}),
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
}, (i) => w.gen(function* () {
|
|
949
|
-
if (!t.generateMedia) return d(i, {
|
|
950
|
-
status: "failed",
|
|
951
|
-
errorMessage: `no media generator for ${e}`
|
|
952
|
-
}), yield* f(), `ERROR: no media generator configured for ${e}`;
|
|
953
|
-
let p = yield* V(t.generateMedia({
|
|
954
|
-
modality: e,
|
|
955
|
-
prompt: r,
|
|
956
|
-
...s ? { model: s } : {},
|
|
957
|
-
...c === void 0 ? {} : { inputs: c },
|
|
958
|
-
...u === void 0 ? {} : { params: u },
|
|
959
|
-
run: {
|
|
960
|
-
runId: n,
|
|
961
|
-
tenantId: o,
|
|
962
|
-
ownerId: a
|
|
963
|
-
}
|
|
964
|
-
})).pipe(w.map((e) => ({
|
|
965
|
-
ok: !0,
|
|
966
|
-
r: e
|
|
967
|
-
})), w.catchAll((e) => w.succeed({
|
|
968
|
-
ok: !1,
|
|
969
|
-
e
|
|
970
|
-
})));
|
|
971
|
-
if (!p.ok) return d(i, {
|
|
972
|
-
status: "failed",
|
|
973
|
-
errorMessage: p.e.message
|
|
974
|
-
}), yield* f(), `ERROR: ${p.e.message}`;
|
|
975
|
-
let m = yield* Jt(p.r);
|
|
976
|
-
return m.error ? (d(i, {
|
|
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, {
|
|
977
1021
|
status: "failed",
|
|
978
|
-
errorMessage:
|
|
979
|
-
}), yield* f(), { error:
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
}), yield* f(), { artifacts: m.artifacts });
|
|
987
|
-
}))
|
|
988
|
-
}),
|
|
989
|
-
pick_structured: M({
|
|
990
|
-
name: "pick_structured",
|
|
991
|
-
description: "Produce a JSON object for a task. Returns the object.",
|
|
992
|
-
input: T.Struct({
|
|
993
|
-
prompt: T.String,
|
|
994
|
-
purpose: ln,
|
|
995
|
-
model: T.optional(T.String)
|
|
996
|
-
}),
|
|
997
|
-
execute: ({ prompt: e, purpose: n, model: r }) => p({
|
|
998
|
-
title: "structured",
|
|
999
|
-
type: "structured",
|
|
1000
|
-
...un(n)
|
|
1001
|
-
}, (n) => w.gen(function* () {
|
|
1002
|
-
let i = yield* et({
|
|
1003
|
-
prompt: `${e}\n\nReturn the JSON object serialized as a string in the \`json\` field.`,
|
|
1004
|
-
schema: dn,
|
|
1005
|
-
...r ? { provider: W(t, r) } : {}
|
|
1006
|
-
}).pipe(w.map((e) => ({
|
|
1007
|
-
ok: !0,
|
|
1008
|
-
r: e
|
|
1009
|
-
})), w.catchAll((e) => w.succeed({
|
|
1010
|
-
ok: !1,
|
|
1011
|
-
e
|
|
1012
|
-
})));
|
|
1013
|
-
if (!i.ok) {
|
|
1014
|
-
let e = String(i.e.message ?? i.e);
|
|
1015
|
-
return d(n, {
|
|
1016
|
-
status: "failed",
|
|
1017
|
-
errorMessage: e
|
|
1018
|
-
}), yield* f(), { error: e };
|
|
1019
|
-
}
|
|
1020
|
-
let a = Qt(i.r.usage, i.r.providerMetadata, r);
|
|
1021
|
-
l += a;
|
|
1022
|
-
let o = fn(i.r.object.json);
|
|
1023
|
-
if (o === void 0) {
|
|
1024
|
-
let e = "the model's `json` field is not a JSON object";
|
|
1025
|
-
return d(n, {
|
|
1026
|
-
status: "failed",
|
|
1027
|
-
errorMessage: e,
|
|
1028
|
-
costMicroUsd: a
|
|
1029
|
-
}), yield* f(), { error: e };
|
|
1030
|
-
}
|
|
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";
|
|
1031
1030
|
return d(n, {
|
|
1032
|
-
status: "
|
|
1033
|
-
|
|
1031
|
+
status: "failed",
|
|
1032
|
+
errorMessage: e,
|
|
1034
1033
|
costMicroUsd: a
|
|
1035
|
-
}), yield* f(),
|
|
1036
|
-
}
|
|
1037
|
-
|
|
1038
|
-
|
|
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, {
|
|
1039
1047
|
runId: n,
|
|
1040
1048
|
tenantId: o,
|
|
1041
1049
|
ownerId: a
|
|
1042
|
-
}, { provider: () => r.orchestrator?.model ?
|
|
1043
|
-
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" })), {
|
|
1044
1052
|
object: {},
|
|
1045
1053
|
planCostMicroUsd: 0,
|
|
1046
1054
|
toolCostMicroUsd: 0,
|
|
1047
1055
|
steps: c,
|
|
1048
1056
|
error: "flow tool resolution failed"
|
|
1049
1057
|
};
|
|
1050
|
-
if (Object.keys(
|
|
1058
|
+
if (Object.keys(b.right).some((e) => Object.hasOwn(ne, e))) return {
|
|
1051
1059
|
object: {},
|
|
1052
1060
|
planCostMicroUsd: 0,
|
|
1053
1061
|
toolCostMicroUsd: 0,
|
|
1054
1062
|
steps: c,
|
|
1055
1063
|
error: "flow tools cannot replace reserved planner tools"
|
|
1056
1064
|
};
|
|
1057
|
-
let
|
|
1058
|
-
system:
|
|
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,
|
|
1059
1067
|
prompt: mn(i),
|
|
1060
|
-
schema:
|
|
1061
|
-
key: T.String,
|
|
1062
|
-
value: T.Unknown
|
|
1063
|
-
}),
|
|
1068
|
+
schema: dn,
|
|
1064
1069
|
tools: {
|
|
1065
|
-
...
|
|
1066
|
-
...
|
|
1070
|
+
...b.right,
|
|
1071
|
+
...h?.length === 0 ? {
|
|
1072
|
+
generate_media: y,
|
|
1073
|
+
pick_structured: te
|
|
1074
|
+
} : ne
|
|
1067
1075
|
},
|
|
1068
1076
|
maxSteps: r.maxSteps,
|
|
1069
|
-
...r.orchestrator?.model ? { provider:
|
|
1070
|
-
}).pipe(
|
|
1077
|
+
...r.orchestrator?.model ? { provider: G(t, r.orchestrator.model) } : {}
|
|
1078
|
+
}).pipe(O.provideService(Ge, cn), O.map((e) => ({
|
|
1071
1079
|
ok: !0,
|
|
1072
1080
|
r: e
|
|
1073
|
-
})),
|
|
1081
|
+
})), O.catchAll((e) => O.succeed({
|
|
1074
1082
|
ok: !1,
|
|
1075
1083
|
e
|
|
1076
1084
|
})));
|
|
@@ -1078,40 +1086,43 @@ var Ht = (e, t = {}) => {
|
|
|
1078
1086
|
status: "failed",
|
|
1079
1087
|
errorMessage: "not finished — the run ended first"
|
|
1080
1088
|
});
|
|
1081
|
-
|
|
1082
|
-
object: y.r.object,
|
|
1083
|
-
planCostMicroUsd: Qt(y.r.usage, y.r.providerMetadata, r.orchestrator?.model),
|
|
1084
|
-
planCostSource: G(y.r.usage, y.r.providerMetadata, r.orchestrator?.model).costSource,
|
|
1085
|
-
toolCostMicroUsd: l,
|
|
1086
|
-
steps: c
|
|
1087
|
-
} : {
|
|
1089
|
+
if (!S.ok) return {
|
|
1088
1090
|
object: {},
|
|
1089
1091
|
planCostMicroUsd: 0,
|
|
1090
1092
|
toolCostMicroUsd: l,
|
|
1091
1093
|
steps: c,
|
|
1092
|
-
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
|
|
1093
1104
|
};
|
|
1094
1105
|
})
|
|
1095
|
-
}), l = c.planCostMicroUsd + c.toolCostMicroUsd, u =
|
|
1106
|
+
}), l = c.planCostMicroUsd + c.toolCostMicroUsd, u = q([...c.steps, {
|
|
1096
1107
|
status: "succeeded",
|
|
1097
1108
|
costMicroUsd: c.planCostMicroUsd,
|
|
1098
1109
|
costSource: c.planCostSource ?? "unpriced"
|
|
1099
1110
|
}]);
|
|
1100
|
-
return c.error ? (yield*
|
|
1111
|
+
return c.error ? (yield* J(e, n, {
|
|
1101
1112
|
status: "failed",
|
|
1102
1113
|
steps: c.steps,
|
|
1103
1114
|
errorMessage: c.error,
|
|
1104
|
-
completedAt:
|
|
1115
|
+
completedAt: W(),
|
|
1105
1116
|
costMicroUsd: l,
|
|
1106
1117
|
costCompleteness: u
|
|
1107
1118
|
}), {
|
|
1108
1119
|
runId: n,
|
|
1109
1120
|
status: "failed"
|
|
1110
|
-
}) : (yield*
|
|
1121
|
+
}) : (yield* J(e, n, {
|
|
1111
1122
|
status: "succeeded",
|
|
1112
1123
|
steps: c.steps,
|
|
1113
1124
|
output: c.object,
|
|
1114
|
-
completedAt:
|
|
1125
|
+
completedAt: W(),
|
|
1115
1126
|
costMicroUsd: l,
|
|
1116
1127
|
costCompleteness: u
|
|
1117
1128
|
}), {
|
|
@@ -1119,36 +1130,36 @@ var Ht = (e, t = {}) => {
|
|
|
1119
1130
|
status: "succeeded",
|
|
1120
1131
|
output: c.object
|
|
1121
1132
|
});
|
|
1122
|
-
}), vn = (e, t = {}) => (n, r) =>
|
|
1123
|
-
let { runId: r, flowRef: i, input: a } = n, o = yield*
|
|
1124
|
-
id:
|
|
1125
|
-
tenantId:
|
|
1126
|
-
ownerId:
|
|
1127
|
-
})))),
|
|
1128
|
-
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, {
|
|
1129
1140
|
status: "failed",
|
|
1130
1141
|
errorMessage: "flow run context unavailable: expected one matching run row with an explicit tenantId (string or null)",
|
|
1131
|
-
completedAt:
|
|
1142
|
+
completedAt: W()
|
|
1132
1143
|
}), {
|
|
1133
1144
|
runId: r,
|
|
1134
1145
|
status: "failed"
|
|
1135
1146
|
};
|
|
1136
|
-
let { tenantId: s, ownerId: c = null } = o.right[0], l = yield*
|
|
1147
|
+
let { tenantId: s, ownerId: c = null } = o.right[0], l = yield* F({
|
|
1137
1148
|
name: "flow-0-resolve",
|
|
1138
1149
|
input: { flowRef: i },
|
|
1139
|
-
success:
|
|
1140
|
-
ir:
|
|
1141
|
-
error:
|
|
1150
|
+
success: k.Struct({
|
|
1151
|
+
ir: k.Unknown,
|
|
1152
|
+
error: k.optional(k.String)
|
|
1142
1153
|
}),
|
|
1143
|
-
execute:
|
|
1154
|
+
execute: tn(e, i).pipe(O.map((e) => ({ ir: e })), O.catchAll((e) => O.succeed({
|
|
1144
1155
|
ir: void 0,
|
|
1145
1156
|
error: e.message
|
|
1146
1157
|
})))
|
|
1147
1158
|
});
|
|
1148
|
-
if (l.error || !l.ir) return yield*
|
|
1159
|
+
if (l.error || !l.ir) return yield* J(e, r, {
|
|
1149
1160
|
status: "failed",
|
|
1150
1161
|
errorMessage: l.error ?? "flow not found",
|
|
1151
|
-
completedAt:
|
|
1162
|
+
completedAt: W()
|
|
1152
1163
|
}), {
|
|
1153
1164
|
runId: r,
|
|
1154
1165
|
status: "failed"
|
|
@@ -1158,13 +1169,13 @@ var Ht = (e, t = {}) => {
|
|
|
1158
1169
|
tenantId: s,
|
|
1159
1170
|
source: n.source
|
|
1160
1171
|
});
|
|
1161
|
-
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({
|
|
1162
1173
|
kind: d.status,
|
|
1163
1174
|
runId: r,
|
|
1164
1175
|
flowName: u.name,
|
|
1165
1176
|
ownerId: c,
|
|
1166
1177
|
source: n.source
|
|
1167
|
-
})).pipe(
|
|
1178
|
+
})).pipe(O.catchAllCause(() => O.void))), d;
|
|
1168
1179
|
}), yn = {
|
|
1169
1180
|
text: (e) => ({
|
|
1170
1181
|
type: "generate",
|
|
@@ -1196,19 +1207,19 @@ var Ht = (e, t = {}) => {
|
|
|
1196
1207
|
id: `step-${t}`,
|
|
1197
1208
|
...e
|
|
1198
1209
|
}), xn = (e) => {
|
|
1199
|
-
let t = [], n =
|
|
1200
|
-
for (let e of
|
|
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`);
|
|
1201
1212
|
let r = new Set(e.brief.map((e) => e.key));
|
|
1202
1213
|
for (let e of n) {
|
|
1203
1214
|
for (let { step: n } of e.steps) {
|
|
1204
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`);
|
|
1205
|
-
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`);
|
|
1206
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`);
|
|
1207
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`);
|
|
1208
1219
|
}
|
|
1209
1220
|
for (let { step: t } of e.steps) t.outputKey && r.add(f(t.outputKey));
|
|
1210
1221
|
}
|
|
1211
|
-
if (t.length > 0) throw new
|
|
1222
|
+
if (t.length > 0) throw new Te({
|
|
1212
1223
|
flowRef: e.name,
|
|
1213
1224
|
message: `flow "${e.name}" has ${t.length} problem(s)`,
|
|
1214
1225
|
issues: t
|
|
@@ -1226,21 +1237,21 @@ var Ht = (e, t = {}) => {
|
|
|
1226
1237
|
cadence: e.cadence,
|
|
1227
1238
|
humanTimeoutMs: e.humanTimeoutMs
|
|
1228
1239
|
});
|
|
1229
|
-
return xn(t),
|
|
1240
|
+
return xn(t), at(t), t;
|
|
1230
1241
|
}, Cn = async (e, t, n) => {
|
|
1231
|
-
let r =
|
|
1232
|
-
if (await e.store.update(
|
|
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");
|
|
1233
1244
|
return r;
|
|
1234
1245
|
}, wn = (e, t, n) => {
|
|
1235
1246
|
if (!Number.isFinite(t.getTime())) throw Error("cadence timestamp must be valid");
|
|
1236
|
-
return `cron-${
|
|
1247
|
+
return `cron-${it("sha256").update(JSON.stringify([
|
|
1237
1248
|
n,
|
|
1238
1249
|
e,
|
|
1239
1250
|
Math.floor(t.getTime() / 6e4)
|
|
1240
1251
|
])).digest("hex")}`;
|
|
1241
1252
|
}, Tn = async (e) => {
|
|
1242
1253
|
let t = [];
|
|
1243
|
-
for (let n of
|
|
1254
|
+
for (let n of st()) n.cadence && (n.cadence.repeats?.length ?? 0) > 0 && t.push({
|
|
1244
1255
|
tenantId: e.request.subject.tenantId,
|
|
1245
1256
|
flowRef: n.name,
|
|
1246
1257
|
cadence: n.cadence,
|
|
@@ -1255,7 +1266,7 @@ var Ht = (e, t = {}) => {
|
|
|
1255
1266
|
});
|
|
1256
1267
|
return t;
|
|
1257
1268
|
}, En = async (e, t = /* @__PURE__ */ new Date()) => {
|
|
1258
|
-
let r = [], i = 0, a = [], o = e.workflows ? await
|
|
1269
|
+
let r = [], i = 0, a = [], o = e.workflows ? await pt(e) : {
|
|
1259
1270
|
examined: 0,
|
|
1260
1271
|
accepted: 0,
|
|
1261
1272
|
notExecuted: 0,
|
|
@@ -1265,7 +1276,7 @@ var Ht = (e, t = {}) => {
|
|
|
1265
1276
|
a.push(...o.failures.map((e) => Error(`flow run ${e.runId}: start reconciliation failed`, { cause: e.cause })));
|
|
1266
1277
|
let s = await Tn(e);
|
|
1267
1278
|
for (let o of s) {
|
|
1268
|
-
if (!
|
|
1279
|
+
if (!De(o.cadence, t)) continue;
|
|
1269
1280
|
i += 1;
|
|
1270
1281
|
let s = wn(o.flowRef, t, o.tenantId), c = `run-${s}`;
|
|
1271
1282
|
try {
|
|
@@ -1284,7 +1295,7 @@ var Ht = (e, t = {}) => {
|
|
|
1284
1295
|
}, { conflictColumns: ["id"] });
|
|
1285
1296
|
let r = await e.store.select("_voltro_ai_flow_runs").where("id", c).first();
|
|
1286
1297
|
if (!r) throw Error("cadence run is not readable after persistence");
|
|
1287
|
-
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")))({
|
|
1288
1299
|
...r,
|
|
1289
1300
|
runId: r.id
|
|
1290
1301
|
});
|
|
@@ -1300,42 +1311,42 @@ var Ht = (e, t = {}) => {
|
|
|
1300
1311
|
started: r,
|
|
1301
1312
|
reconciled: o
|
|
1302
1313
|
};
|
|
1303
|
-
}, Y = (e) =>
|
|
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({
|
|
1304
1315
|
n: Y(Dn),
|
|
1305
1316
|
seed: Y(On),
|
|
1306
1317
|
size: Y(kn),
|
|
1307
1318
|
aspectRatio: Y(An),
|
|
1308
|
-
providerOptions: Y(
|
|
1309
|
-
}), Mn =
|
|
1310
|
-
voice: Y(
|
|
1311
|
-
outputFormat: Y(
|
|
1312
|
-
instructions: Y(
|
|
1313
|
-
speed: Y(
|
|
1314
|
-
language: Y(
|
|
1315
|
-
providerOptions: Y(
|
|
1316
|
-
}), Nn =
|
|
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({
|
|
1317
1328
|
aspectRatio: Y(An),
|
|
1318
|
-
durationSeconds: Y(
|
|
1329
|
+
durationSeconds: Y(k.Finite.pipe(k.positive())),
|
|
1319
1330
|
resolution: Y(kn),
|
|
1320
|
-
fps: Y(
|
|
1331
|
+
fps: Y(k.Finite.pipe(k.positive())),
|
|
1321
1332
|
seed: Y(On),
|
|
1322
|
-
generateAudio: Y(
|
|
1333
|
+
generateAudio: Y(k.Boolean),
|
|
1323
1334
|
maxInlineBytes: Y(Dn),
|
|
1324
|
-
providerOptions: Y(
|
|
1325
|
-
}), Pn = (e, t, n) =>
|
|
1326
|
-
try: () =>
|
|
1335
|
+
providerOptions: Y(B)
|
|
1336
|
+
}), Pn = (e, t, n) => O.try({
|
|
1337
|
+
try: () => k.decodeUnknownSync(e, { onExcessProperty: "error" })(t === void 0 ? {} : t),
|
|
1327
1338
|
catch: () => `invalid ${n} media params: check the built-in adapter's supported options and value ranges`
|
|
1328
1339
|
}), Fn = (e) => Pn(jn, e, "image"), In = (e) => Pn(Mn, e, "audio"), Ln = (e) => Pn(Nn, e, "video"), Rn = (e) => ({
|
|
1329
1340
|
name: "gateway",
|
|
1330
1341
|
model: e
|
|
1331
1342
|
}), zn = (e) => Math.round(e * 1e6), X = (e, t, n) => {
|
|
1332
|
-
let r =
|
|
1343
|
+
let r = Ye(t);
|
|
1333
1344
|
if (typeof r == "number") return {
|
|
1334
1345
|
costMicroUsd: zn(r),
|
|
1335
1346
|
costSource: "gateway"
|
|
1336
1347
|
};
|
|
1337
1348
|
if (e) {
|
|
1338
|
-
let t =
|
|
1349
|
+
let t = Je(e, { model: n ?? "unknown" });
|
|
1339
1350
|
return {
|
|
1340
1351
|
costMicroUsd: t.costMicroUsd ?? 0,
|
|
1341
1352
|
costSource: t.costSource ?? "unpriced"
|
|
@@ -1347,7 +1358,7 @@ var Ht = (e, t = {}) => {
|
|
|
1347
1358
|
};
|
|
1348
1359
|
}, Z = (e) => {
|
|
1349
1360
|
if (e === void 0) return { status: "unreported" };
|
|
1350
|
-
let [t, n, r] =
|
|
1361
|
+
let [t, n, r] = rt(e) ? [
|
|
1351
1362
|
e.unit,
|
|
1352
1363
|
e.input,
|
|
1353
1364
|
e.output
|
|
@@ -1367,16 +1378,16 @@ var Ht = (e, t = {}) => {
|
|
|
1367
1378
|
usage: Z(e)
|
|
1368
1379
|
}), Bn = (e, t) => (n) => {
|
|
1369
1380
|
let r = n.model, i = (e) => t?.resolveModel?.(e) ?? Rn(e);
|
|
1370
|
-
return
|
|
1371
|
-
let t = yield*
|
|
1381
|
+
return O.gen(function* () {
|
|
1382
|
+
let t = yield* Ht(n.modality, n.inputs).pipe(O.mapError((e) => new E({
|
|
1372
1383
|
capability: `media:${n.modality}`,
|
|
1373
1384
|
message: e
|
|
1374
1385
|
})));
|
|
1375
1386
|
if (n.modality === "image") {
|
|
1376
|
-
let a = yield* Fn(n.params).pipe(
|
|
1387
|
+
let a = yield* Fn(n.params).pipe(O.mapError((e) => new E({
|
|
1377
1388
|
capability: "media:image",
|
|
1378
1389
|
message: e
|
|
1379
|
-
}))), o = t.referenceImageUrl, s = t.maskImageUrl, c = yield*
|
|
1390
|
+
}))), o = t.referenceImageUrl, s = t.maskImageUrl, c = yield* Xe({
|
|
1380
1391
|
...a,
|
|
1381
1392
|
prompt: n.prompt,
|
|
1382
1393
|
...o === void 0 ? {} : { inputs: {
|
|
@@ -1385,7 +1396,7 @@ var Ht = (e, t = {}) => {
|
|
|
1385
1396
|
} },
|
|
1386
1397
|
...r ? { provider: i(r) } : {}
|
|
1387
1398
|
});
|
|
1388
|
-
if (c.images.length === 0) return yield*
|
|
1399
|
+
if (c.images.length === 0) return yield* O.fail(new E({
|
|
1389
1400
|
capability: "media:image",
|
|
1390
1401
|
message: "no image produced"
|
|
1391
1402
|
}));
|
|
@@ -1395,7 +1406,7 @@ var Ht = (e, t = {}) => {
|
|
|
1395
1406
|
data: i.data,
|
|
1396
1407
|
mediaType: i.mediaType,
|
|
1397
1408
|
run: n.run
|
|
1398
|
-
}).pipe(
|
|
1409
|
+
}).pipe(O.mapError(() => new E({
|
|
1399
1410
|
capability: "media:image",
|
|
1400
1411
|
message: "media persistence failed",
|
|
1401
1412
|
receipt: Q(c.usage, c.providerMetadata, r)
|
|
@@ -1415,10 +1426,10 @@ var Ht = (e, t = {}) => {
|
|
|
1415
1426
|
};
|
|
1416
1427
|
}
|
|
1417
1428
|
if (n.modality === "audio") {
|
|
1418
|
-
let t = yield* In(n.params).pipe(
|
|
1429
|
+
let t = yield* In(n.params).pipe(O.mapError((e) => new E({
|
|
1419
1430
|
capability: "media:audio",
|
|
1420
1431
|
message: e
|
|
1421
|
-
}))), a = yield*
|
|
1432
|
+
}))), a = yield* et({
|
|
1422
1433
|
...t,
|
|
1423
1434
|
text: n.prompt,
|
|
1424
1435
|
...r ? { provider: i(r) } : {}
|
|
@@ -1426,7 +1437,7 @@ var Ht = (e, t = {}) => {
|
|
|
1426
1437
|
data: a.audio.data,
|
|
1427
1438
|
mediaType: a.audio.mediaType,
|
|
1428
1439
|
run: n.run
|
|
1429
|
-
}).pipe(
|
|
1440
|
+
}).pipe(O.mapError(() => new E({
|
|
1430
1441
|
capability: "media:audio",
|
|
1431
1442
|
message: "media persistence failed",
|
|
1432
1443
|
receipt: Q(a.usage, a.providerMetadata, r)
|
|
@@ -1442,10 +1453,10 @@ var Ht = (e, t = {}) => {
|
|
|
1442
1453
|
usage: Z(a.usage)
|
|
1443
1454
|
};
|
|
1444
1455
|
}
|
|
1445
|
-
let { maxInlineBytes: a, providerOptions: o, ...s } = yield* Ln(n.params).pipe(
|
|
1456
|
+
let { maxInlineBytes: a, providerOptions: o, ...s } = yield* Ln(n.params).pipe(O.mapError((e) => new E({
|
|
1446
1457
|
capability: "media:video",
|
|
1447
1458
|
message: e
|
|
1448
|
-
}))), c = yield*
|
|
1459
|
+
}))), c = yield* nt({
|
|
1449
1460
|
prompt: n.prompt,
|
|
1450
1461
|
inputs: {
|
|
1451
1462
|
...t.referenceImageUrl === void 0 ? {} : { image: t.referenceImageUrl },
|
|
@@ -1463,7 +1474,7 @@ var Ht = (e, t = {}) => {
|
|
|
1463
1474
|
...o === void 0 ? {} : { providerOptions: o },
|
|
1464
1475
|
...a === void 0 ? {} : { maxInlineBytes: a }
|
|
1465
1476
|
}), l;
|
|
1466
|
-
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({
|
|
1467
1478
|
capability: "media:video",
|
|
1468
1479
|
message: "media persistence failed",
|
|
1469
1480
|
receipt: Q(c.usage, c.providerMetadata, r)
|
|
@@ -1472,12 +1483,12 @@ var Ht = (e, t = {}) => {
|
|
|
1472
1483
|
data: c.video.data,
|
|
1473
1484
|
mediaType: c.video.mediaType,
|
|
1474
1485
|
run: n.run
|
|
1475
|
-
}).pipe(
|
|
1486
|
+
}).pipe(O.mapError(() => new E({
|
|
1476
1487
|
capability: "media:video",
|
|
1477
1488
|
message: "media persistence failed",
|
|
1478
1489
|
receipt: Q(c.usage, c.providerMetadata, r)
|
|
1479
1490
|
})));
|
|
1480
|
-
else return yield*
|
|
1491
|
+
else return yield* O.fail(new E({
|
|
1481
1492
|
capability: "media:video",
|
|
1482
1493
|
message: "no video produced"
|
|
1483
1494
|
}));
|
|
@@ -1491,26 +1502,26 @@ var Ht = (e, t = {}) => {
|
|
|
1491
1502
|
...X(c.usage, c.providerMetadata, r),
|
|
1492
1503
|
usage: Z(c.usage)
|
|
1493
1504
|
};
|
|
1494
|
-
}).pipe(
|
|
1505
|
+
}).pipe(O.catchAll((e) => e instanceof E ? O.fail(e) : O.fail(new E({
|
|
1495
1506
|
capability: `media:${n.modality}`,
|
|
1496
1507
|
message: String(e.message ?? e)
|
|
1497
1508
|
}))));
|
|
1498
|
-
}, Vn = () => globalThis.crypto?.randomUUID?.() ?? `req-${Date.now().toString(36)}`, Hn = (e) => e.request?.subject?.id ?? null, $ = (e, t) =>
|
|
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(() => {
|
|
1499
1510
|
let t = e.workflows;
|
|
1500
1511
|
if (!t) throw Error("workflow runtime unavailable; no flow start was submitted");
|
|
1501
1512
|
return t;
|
|
1502
|
-
}), Wn = (t, n) =>
|
|
1513
|
+
}), Wn = (t, n) => O.gen(function* () {
|
|
1503
1514
|
yield* Un(t);
|
|
1504
|
-
let r = yield*
|
|
1505
|
-
if (a.length > 0) return yield*
|
|
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);
|
|
1516
|
+
if (a.length > 0) return yield* O.fail(new be({
|
|
1506
1517
|
missing: a,
|
|
1507
1518
|
message: `missing required brief field(s): ${a.join(", ")}`
|
|
1508
1519
|
}));
|
|
1509
1520
|
let o = Vn(), s = `run-${o}`, c = n.source ?? "manual";
|
|
1510
|
-
return yield*
|
|
1521
|
+
return yield* O.promise(() => t.transaction(async (t) => {
|
|
1511
1522
|
let a = t.workflows;
|
|
1512
1523
|
if (!a) throw Error("workflow runtime unavailable in transaction; no flow start was submitted");
|
|
1513
|
-
await t.store.insert(
|
|
1524
|
+
await t.store.insert(R.tableName, {
|
|
1514
1525
|
id: s,
|
|
1515
1526
|
flowRef: n.flowRef,
|
|
1516
1527
|
flowName: r.name,
|
|
@@ -1528,106 +1539,106 @@ var Ht = (e, t = {}) => {
|
|
|
1528
1539
|
source: c,
|
|
1529
1540
|
requestId: o
|
|
1530
1541
|
}));
|
|
1531
|
-
return
|
|
1542
|
+
return x.make({
|
|
1532
1543
|
runId: s,
|
|
1533
1544
|
requestId: o,
|
|
1534
1545
|
admission: l
|
|
1535
1546
|
});
|
|
1536
1547
|
}));
|
|
1537
|
-
}), Gn = (t, r) =>
|
|
1538
|
-
return yield* Un(t), yield*
|
|
1548
|
+
}), Gn = (t, r) => O.gen(function* () {
|
|
1549
|
+
return yield* Un(t), yield* O.tryPromise({
|
|
1539
1550
|
try: () => t.transaction(async (t) => {
|
|
1540
1551
|
let i = t.workflows;
|
|
1541
1552
|
if (!i) throw Error("workflow runtime unavailable in transaction; no flow start was submitted");
|
|
1542
|
-
let a = (await t.store.query(
|
|
1543
|
-
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({
|
|
1544
1555
|
runId: r.runId,
|
|
1545
1556
|
message: "run not found"
|
|
1546
1557
|
});
|
|
1547
1558
|
let o = a.requestId;
|
|
1548
1559
|
if (typeof o != "string" || o.length === 0) throw Error("stored flow run has no valid requestId; retry refused without changing the run");
|
|
1549
|
-
let s =
|
|
1560
|
+
let s = k.decodeUnknownEither(n.payloadSchema.pipe(k.filter((e) => e.runId === r.runId && e.flowRef.length > 0)))({
|
|
1550
1561
|
...a,
|
|
1551
1562
|
runId: a.id
|
|
1552
1563
|
});
|
|
1553
1564
|
if (s._tag === "Left") throw Error("stored workflow payload is incomplete or invalid; retry refused without changing the run");
|
|
1554
1565
|
let c = await Cn(t, r.runId, await i.start(e, s.right));
|
|
1555
|
-
return
|
|
1566
|
+
return x.make({
|
|
1556
1567
|
runId: r.runId,
|
|
1557
1568
|
requestId: o,
|
|
1558
1569
|
admission: c
|
|
1559
1570
|
});
|
|
1560
1571
|
}),
|
|
1561
1572
|
catch: (e) => e
|
|
1562
|
-
}).pipe(
|
|
1563
|
-
}), Kn = (t, r) =>
|
|
1573
|
+
}).pipe(O.catchAll((e) => e instanceof D ? O.fail(e) : O.die(e)));
|
|
1574
|
+
}), Kn = (t, r) => O.gen(function* () {
|
|
1564
1575
|
let i = yield* $(t, r.runId);
|
|
1565
|
-
if (!i) return yield*
|
|
1576
|
+
if (!i) return yield* O.fail(new D({
|
|
1566
1577
|
runId: r.runId,
|
|
1567
1578
|
message: "run not found"
|
|
1568
1579
|
}));
|
|
1569
|
-
if (qn(i.status)) return
|
|
1580
|
+
if (qn(i.status)) return T.make({
|
|
1570
1581
|
runId: r.runId,
|
|
1571
1582
|
status: i.status,
|
|
1572
1583
|
engine: "not-requested",
|
|
1573
1584
|
control: null
|
|
1574
1585
|
});
|
|
1575
1586
|
let a = (/* @__PURE__ */ new Date()).toISOString();
|
|
1576
|
-
yield*
|
|
1587
|
+
yield* O.promise(() => t.store.updateMany(R.tableName, {
|
|
1577
1588
|
status: "cancelling",
|
|
1578
1589
|
cancelledAt: a
|
|
1579
|
-
}, { where:
|
|
1590
|
+
}, { where: Pe(A("id", r.runId), Le("status", [
|
|
1580
1591
|
"pending",
|
|
1581
1592
|
"running",
|
|
1582
1593
|
"waiting"
|
|
1583
1594
|
])) }));
|
|
1584
1595
|
let o = yield* $(t, r.runId);
|
|
1585
|
-
if (!o) return yield*
|
|
1596
|
+
if (!o) return yield* O.fail(new D({
|
|
1586
1597
|
runId: r.runId,
|
|
1587
1598
|
message: "run not found"
|
|
1588
1599
|
}));
|
|
1589
|
-
if (qn(o.status)) return
|
|
1600
|
+
if (qn(o.status)) return T.make({
|
|
1590
1601
|
runId: r.runId,
|
|
1591
1602
|
status: o.status,
|
|
1592
1603
|
engine: "not-requested",
|
|
1593
1604
|
control: null
|
|
1594
1605
|
});
|
|
1595
|
-
let s = t.workflows, c =
|
|
1596
|
-
runId:
|
|
1597
|
-
flowRef:
|
|
1598
|
-
requestId:
|
|
1599
|
-
input:
|
|
1600
|
-
key:
|
|
1601
|
-
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
|
|
1602
1613
|
}),
|
|
1603
|
-
source:
|
|
1614
|
+
source: k.Literal("manual", "cron")
|
|
1604
1615
|
}))({
|
|
1605
1616
|
...i,
|
|
1606
1617
|
runId: i.id
|
|
1607
|
-
}), l = s === void 0 || c._tag === "None" ? null : yield*
|
|
1608
|
-
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));
|
|
1609
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");
|
|
1610
1621
|
return n;
|
|
1611
|
-
})).pipe(
|
|
1612
|
-
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, {
|
|
1613
1624
|
status: "cancelled",
|
|
1614
1625
|
completedAt: o.completedAt ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
1615
1626
|
}, { where: d }));
|
|
1616
1627
|
else if (l?.kind === "already-terminal") {
|
|
1617
|
-
let e =
|
|
1618
|
-
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, {
|
|
1619
1630
|
status: i,
|
|
1620
1631
|
completedAt: o.completedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
1621
1632
|
...i === "cancelled" ? {} : { cancelledAt: null }
|
|
1622
1633
|
}, { where: d })));
|
|
1623
1634
|
}
|
|
1624
1635
|
let f = yield* $(t, r.runId);
|
|
1625
|
-
return f ? yield*
|
|
1636
|
+
return f ? yield* k.decodeUnknown(T)({
|
|
1626
1637
|
runId: r.runId,
|
|
1627
1638
|
status: f.status,
|
|
1628
1639
|
engine: u,
|
|
1629
1640
|
control: l
|
|
1630
|
-
}).pipe(
|
|
1641
|
+
}).pipe(O.orDie) : yield* O.fail(new D({
|
|
1631
1642
|
runId: r.runId,
|
|
1632
1643
|
message: "run not found"
|
|
1633
1644
|
}));
|
|
@@ -1635,80 +1646,80 @@ var Ht = (e, t = {}) => {
|
|
|
1635
1646
|
let t = e.steps?.filter((e) => e.status === "waiting"), n = t?.[0];
|
|
1636
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");
|
|
1637
1648
|
return n.id;
|
|
1638
|
-
}, Yn = (t, i) =>
|
|
1639
|
-
let a = (e, t) => new
|
|
1649
|
+
}, Yn = (t, i) => O.gen(function* () {
|
|
1650
|
+
let a = (e, t) => new we({
|
|
1640
1651
|
runId: i.runId,
|
|
1641
1652
|
reason: e,
|
|
1642
1653
|
message: t
|
|
1643
|
-
}), o = yield*
|
|
1644
|
-
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"));
|
|
1645
1656
|
let s = t.workflows;
|
|
1646
|
-
if (!s) return yield*
|
|
1657
|
+
if (!s) return yield* O.fail(a("runtime-unavailable", "workflow runtime unavailable; review was not sent"));
|
|
1647
1658
|
let c = yield* $(t, i.runId);
|
|
1648
|
-
if (!c) return yield*
|
|
1659
|
+
if (!c) return yield* O.fail(new D({
|
|
1649
1660
|
runId: i.runId,
|
|
1650
1661
|
message: "run not found"
|
|
1651
1662
|
}));
|
|
1652
1663
|
let l = c.status;
|
|
1653
|
-
if (l !== "waiting") return yield*
|
|
1664
|
+
if (l !== "waiting") return yield* O.fail(new Se({
|
|
1654
1665
|
runId: i.runId,
|
|
1655
1666
|
status: l ?? "unknown",
|
|
1656
1667
|
message: `run is "${l}", not awaiting a response`
|
|
1657
1668
|
}));
|
|
1658
|
-
let u = yield*
|
|
1669
|
+
let u = yield* O.try({
|
|
1659
1670
|
try: () => Jn(c),
|
|
1660
1671
|
catch: () => a("invalid-run", "stored run has no unambiguous waiting review")
|
|
1661
1672
|
});
|
|
1662
|
-
if (u !== o.stepIndex) return yield*
|
|
1673
|
+
if (u !== o.stepIndex) return yield* O.fail(new Se({
|
|
1663
1674
|
runId: i.runId,
|
|
1664
1675
|
status: l,
|
|
1665
1676
|
message: "this review is no longer waiting; reload the run before answering"
|
|
1666
1677
|
}));
|
|
1667
|
-
let d = yield*
|
|
1668
|
-
runId:
|
|
1669
|
-
flowRef:
|
|
1670
|
-
requestId:
|
|
1671
|
-
input:
|
|
1672
|
-
key:
|
|
1673
|
-
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
|
|
1674
1685
|
}),
|
|
1675
|
-
source:
|
|
1686
|
+
source: k.Literal("manual", "cron")
|
|
1676
1687
|
}))({
|
|
1677
1688
|
...c,
|
|
1678
1689
|
runId: c.id
|
|
1679
|
-
}).pipe(
|
|
1690
|
+
}).pipe(O.mapError(() => a("invalid-run", "stored workflow payload is incomplete; review was not sent"))), f = yield* n.executionId(d), p = {
|
|
1680
1691
|
...o.response,
|
|
1681
1692
|
respondedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1682
|
-
}, m = yield*
|
|
1693
|
+
}, m = yield* O.tryPromise({
|
|
1683
1694
|
try: () => s.signal({
|
|
1684
1695
|
workflowName: e,
|
|
1685
1696
|
executionId: f
|
|
1686
1697
|
}, r(u), p),
|
|
1687
1698
|
catch: () => a("delivery-unknown", "review delivery was not confirmed; observe the run before retrying")
|
|
1688
|
-
}), h = yield*
|
|
1689
|
-
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)({
|
|
1690
1701
|
runId: i.runId,
|
|
1691
1702
|
stepIndex: u,
|
|
1692
1703
|
executionId: f,
|
|
1693
1704
|
eventId: h.eventId,
|
|
1694
1705
|
status: "accepted"
|
|
1695
|
-
}).pipe(
|
|
1696
|
-
}), Xn = (e, t) =>
|
|
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, {
|
|
1697
1708
|
id: t.id ?? `flow-${Vn()}`,
|
|
1698
1709
|
...t
|
|
1699
|
-
})), $n = (e, t) =>
|
|
1700
|
-
let t =
|
|
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({
|
|
1701
1712
|
base: tr,
|
|
1702
1713
|
alias: e.alias
|
|
1703
1714
|
});
|
|
1704
|
-
|
|
1715
|
+
xt(e.humanReviewTimeoutMs === void 0 ? {} : { humanReviewTimeoutMs: e.humanReviewTimeoutMs }), ze({
|
|
1705
1716
|
source: "plugin",
|
|
1706
|
-
table:
|
|
1717
|
+
table: R.tableName,
|
|
1707
1718
|
timeColumn: "createdAt",
|
|
1708
|
-
ttlMs: e.runsTtlMs ??
|
|
1709
|
-
envVar:
|
|
1719
|
+
ttlMs: e.runsTtlMs ?? wt(process.env.VOLTRO_AI_FLOW_RUNS_TTL_HOURS, 2160),
|
|
1720
|
+
envVar: _t,
|
|
1710
1721
|
label: "ai flow runs",
|
|
1711
|
-
where:
|
|
1722
|
+
where: Le("status", [
|
|
1712
1723
|
"succeeded",
|
|
1713
1724
|
"failed",
|
|
1714
1725
|
"cancelled"
|
|
@@ -1721,12 +1732,12 @@ var Ht = (e, t = {}) => {
|
|
|
1721
1732
|
kind: "json",
|
|
1722
1733
|
status: e,
|
|
1723
1734
|
data: { error: t }
|
|
1724
|
-
}), o = (e, t, n) =>
|
|
1735
|
+
}), o = (e, t, n) => O.promise(async () => {
|
|
1725
1736
|
let o = r.current;
|
|
1726
1737
|
if (!o) return a(503, "store not bound yet");
|
|
1727
1738
|
let s = await o.query({
|
|
1728
1739
|
table: e,
|
|
1729
|
-
predicate: n === void 0 ? void 0 :
|
|
1740
|
+
predicate: n === void 0 ? void 0 : A("id", n),
|
|
1730
1741
|
order: [{
|
|
1731
1742
|
column: "createdAt",
|
|
1732
1743
|
direction: "desc"
|
|
@@ -1756,7 +1767,7 @@ var Ht = (e, t = {}) => {
|
|
|
1756
1767
|
rows: s,
|
|
1757
1768
|
take: t
|
|
1758
1769
|
});
|
|
1759
|
-
}).pipe(
|
|
1770
|
+
}).pipe(O.catchAllCause(() => O.succeed(a(500, "query failed")))), s = (e, t) => {
|
|
1760
1771
|
let r = /[?&]take=(\d+)/.exec(e)?.[1], i = r === void 0 ? t : Number(r);
|
|
1761
1772
|
return Math.min(n, Math.max(1, Number.isFinite(i) ? i : t));
|
|
1762
1773
|
}, c = [{
|
|
@@ -1764,17 +1775,17 @@ var Ht = (e, t = {}) => {
|
|
|
1764
1775
|
path: "/flows",
|
|
1765
1776
|
scope: "process",
|
|
1766
1777
|
description: "List flow definitions (`?take=` up to the configured max).",
|
|
1767
|
-
handler: (e) =>
|
|
1778
|
+
handler: (e) => O.promise(async () => {
|
|
1768
1779
|
let t = r.current;
|
|
1769
1780
|
if (!t) return a(503, "store not bound yet");
|
|
1770
|
-
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) => ({
|
|
1771
1782
|
id: e.name,
|
|
1772
1783
|
name: e.name,
|
|
1773
1784
|
mode: e.mode,
|
|
1774
1785
|
definitionSource: "code"
|
|
1775
1786
|
})), u = l.length === o ? [] : await t.query({
|
|
1776
1787
|
table: "_voltro_ai_flows",
|
|
1777
|
-
predicate: c.length === 0 ? void 0 :
|
|
1788
|
+
predicate: c.length === 0 ? void 0 : Re("id", c.map((e) => e.name)),
|
|
1778
1789
|
order: [{
|
|
1779
1790
|
column: "createdAt",
|
|
1780
1791
|
direction: "desc"
|
|
@@ -1794,7 +1805,7 @@ var Ht = (e, t = {}) => {
|
|
|
1794
1805
|
rows: d,
|
|
1795
1806
|
take: o
|
|
1796
1807
|
});
|
|
1797
|
-
}).pipe(
|
|
1808
|
+
}).pipe(O.catchAllCause(() => O.succeed(a(500, "query failed"))))
|
|
1798
1809
|
}, {
|
|
1799
1810
|
method: "GET",
|
|
1800
1811
|
path: "/runs",
|
|
@@ -1802,7 +1813,7 @@ var Ht = (e, t = {}) => {
|
|
|
1802
1813
|
description: "List recent run summaries (`?take=` bounded); `?runId=` reads one run with payloads and steps.",
|
|
1803
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)
|
|
1804
1815
|
}];
|
|
1805
|
-
return
|
|
1816
|
+
return Me({
|
|
1806
1817
|
name: t,
|
|
1807
1818
|
baseName: tr,
|
|
1808
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.",
|
|
@@ -1811,12 +1822,12 @@ var Ht = (e, t = {}) => {
|
|
|
1811
1822
|
"inspect:read",
|
|
1812
1823
|
"store:changes:read"
|
|
1813
1824
|
],
|
|
1814
|
-
...e.tables === !1 ? {} : { extendSchema: { tables:
|
|
1825
|
+
...e.tables === !1 ? {} : { extendSchema: { tables: lt } },
|
|
1815
1826
|
inspectEndpoints: c,
|
|
1816
1827
|
bindDataStore: (e) => {
|
|
1817
1828
|
r.current = e;
|
|
1818
1829
|
},
|
|
1819
|
-
onChangeEvent: (e) =>
|
|
1830
|
+
onChangeEvent: (e) => O.gen(function* () {
|
|
1820
1831
|
if (e.table !== "_voltro_workflow_runs" || e.new === null || e.op !== "update" && e.op !== "insert") return;
|
|
1821
1832
|
let t = e.new;
|
|
1822
1833
|
if (t.tag !== "flow.run") return;
|
|
@@ -1824,20 +1835,20 @@ var Ht = (e, t = {}) => {
|
|
|
1824
1835
|
if (n === void 0) return;
|
|
1825
1836
|
let i = t.payload, a = (typeof i == "string" ? JSON.parse(i) : i)?.runId;
|
|
1826
1837
|
if (typeof a != "string") return;
|
|
1827
|
-
let o = (yield*
|
|
1838
|
+
let o = (yield* O.promise(() => n.query(N(R).where(A("id", a)).descriptor)))[0];
|
|
1828
1839
|
if (o === void 0) return;
|
|
1829
1840
|
let s = o.status, c = t.executionId, l = o.workflowStart;
|
|
1830
|
-
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) })));
|
|
1831
1842
|
let u = e.old?.status === "cancelled";
|
|
1832
1843
|
if (e.op !== "update" || t.status !== "cancelled" || u || s === "cancelled" || s === "succeeded" || s === "failed") return;
|
|
1833
1844
|
let d = (/* @__PURE__ */ new Date()).toISOString(), f = typeof o.cancelledAt == "string" ? o.cancelledAt : d;
|
|
1834
|
-
yield*
|
|
1845
|
+
yield* O.promise(() => n.update(R.tableName, a, {
|
|
1835
1846
|
status: "cancelled",
|
|
1836
1847
|
cancelledAt: f,
|
|
1837
1848
|
completedAt: d
|
|
1838
1849
|
}));
|
|
1839
|
-
}).pipe(
|
|
1850
|
+
}).pipe(O.catchAllCause(() => O.void))
|
|
1840
1851
|
});
|
|
1841
1852
|
};
|
|
1842
1853
|
//#endregion
|
|
1843
|
-
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 };
|