@voltro/plugin-ai-flows 0.11.2 → 0.11.4
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 +228 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.js +234 -234
- package/package.json +10 -10
package/dist/index.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { BriefField as e, ChainPending as t, FlowCadence as n, FlowChain as r, FlowMode as i, FlowStatus as a, FlowStep as o, HumanResponse as s, Json as c, MAX_STEPS_DEFAULT as l, MAX_STEPS_MAX as u, MAX_STEPS_MIN as d, MediaInputSlot as f, MediaInputs as p, Modality as ee, ReviewMode as m, ReviewOption as h, RunReview as te, RunSource as ne, RunStatus as re, RunStep as ie, RunStepStatus as ae, StepType as oe, Visibility as se, clampMaxSteps as ce, normalizeFlow as g, sanitizeOutputKey as
|
|
2
|
-
import { FLOW_RUN_WORKFLOW as
|
|
3
|
-
import { FlowBriefIncomplete as
|
|
4
|
-
import { n as
|
|
5
|
-
import { Effect as
|
|
6
|
-
import { definePlugin as
|
|
7
|
-
import { boolean as
|
|
1
|
+
import { BriefField as e, ChainPending as t, FlowCadence as n, FlowChain as r, FlowMode as i, FlowStatus as a, FlowStep as o, HumanResponse as s, Json as c, MAX_STEPS_DEFAULT as l, MAX_STEPS_MAX as u, MAX_STEPS_MIN as d, MediaInputSlot as f, MediaInputs as p, Modality as ee, ReviewMode as m, ReviewOption as h, RunReview as te, RunSource as ne, RunStatus as re, RunStep as ie, RunStepStatus as ae, StepType as oe, Visibility as se, clampMaxSteps as ce, normalizeFlow as g, sanitizeOutputKey as _ } from "./ir.js";
|
|
2
|
+
import { FLOW_RUN_WORKFLOW as v, HUMAN_RESPONSE_SIGNAL as y } from "./workflow.js";
|
|
3
|
+
import { FlowBriefIncomplete as le, FlowCapabilityMissing as b, FlowDependencyError as ue, FlowNotAwaitingResponse as de, FlowNotFound as fe, FlowRunNotFound as x, FlowValidationError as pe } from "./errors.js";
|
|
4
|
+
import { n as me, t as he } from "./cadence-Bt6dPelT.js";
|
|
5
|
+
import { Effect as S, Schema as C } from "effect";
|
|
6
|
+
import { definePlugin as ge } from "@voltro/protocol";
|
|
7
|
+
import { boolean as _e, eq as w, id as ve, integer as T, json as E, queryFor as D, table as ye, text as O, timestamp as k } from "@voltro/database";
|
|
8
8
|
import { tenant as A } from "@voltro/plugin-multitenancy/mixin";
|
|
9
9
|
import { audit as j } from "@voltro/plugin-audit/mixin";
|
|
10
10
|
import { softDelete as be } from "@voltro/plugin-soft-delete/mixin";
|
|
11
11
|
import { awaitSignalSuspending as xe, step as M } from "@voltro/workflow";
|
|
12
|
-
import { defineTool as N, estimateCostUsd as P, gatewayCostUsd as
|
|
12
|
+
import { defineTool as N, estimateCostUsd as P, gatewayCostUsd as Se, generateImage as Ce, generateObject as we, generateObjectWithTools as Te, generateSpeech as Ee, generateText as F, generateVideo as De } from "@voltro/ai";
|
|
13
13
|
//#region src/table.ts
|
|
14
|
-
var
|
|
15
|
-
id:
|
|
14
|
+
var I = ye("ai_flows", {
|
|
15
|
+
id: ve({ prefix: "aifl" }),
|
|
16
16
|
name: O(),
|
|
17
17
|
description: O().nullable(),
|
|
18
18
|
mode: O().default("deterministic"),
|
|
@@ -20,35 +20,35 @@ var R = D("ai_flows", {
|
|
|
20
20
|
visibility: O().default("private"),
|
|
21
21
|
orchestratorModel: O().nullable(),
|
|
22
22
|
orchestratorInstructions: O().nullable(),
|
|
23
|
-
maxSteps:
|
|
24
|
-
steps:
|
|
25
|
-
inputSchema:
|
|
26
|
-
chainTo:
|
|
27
|
-
cadence:
|
|
28
|
-
isEnabled:
|
|
29
|
-
metadata:
|
|
23
|
+
maxSteps: T().default(30),
|
|
24
|
+
steps: E().nullable(),
|
|
25
|
+
inputSchema: E().nullable(),
|
|
26
|
+
chainTo: E().nullable(),
|
|
27
|
+
cadence: E().nullable(),
|
|
28
|
+
isEnabled: _e().default(!0),
|
|
29
|
+
metadata: E().nullable(),
|
|
30
30
|
icon: O().nullable(),
|
|
31
31
|
color: O().nullable(),
|
|
32
32
|
avatarUrl: O().nullable(),
|
|
33
|
-
usageCount:
|
|
33
|
+
usageCount: T().default(0),
|
|
34
34
|
ownerId: O().nullable()
|
|
35
|
-
}).with(A(), j(), be()).index(["status"]).index(["visibility"]).reactive(),
|
|
36
|
-
id:
|
|
35
|
+
}).with(A(), j(), be()).index(["status"]).index(["visibility"]).reactive(), L = ye("ai_flow_runs", {
|
|
36
|
+
id: ve({ prefix: "aifr" }),
|
|
37
37
|
flowRef: O(),
|
|
38
38
|
flowName: O().nullable(),
|
|
39
39
|
mode: O().default("deterministic"),
|
|
40
40
|
status: O().default("pending"),
|
|
41
41
|
source: O().nullable(),
|
|
42
42
|
requestId: O(),
|
|
43
|
-
input:
|
|
44
|
-
output:
|
|
45
|
-
steps:
|
|
46
|
-
currentStep:
|
|
47
|
-
totalSteps:
|
|
48
|
-
humanResponse:
|
|
49
|
-
chainPending:
|
|
50
|
-
costMicroUsd:
|
|
51
|
-
durationMs:
|
|
43
|
+
input: E().nullable(),
|
|
44
|
+
output: E().nullable(),
|
|
45
|
+
steps: E().nullable(),
|
|
46
|
+
currentStep: T().default(0),
|
|
47
|
+
totalSteps: T().default(0),
|
|
48
|
+
humanResponse: E().nullable(),
|
|
49
|
+
chainPending: E().nullable(),
|
|
50
|
+
costMicroUsd: T().default(0),
|
|
51
|
+
durationMs: T().nullable(),
|
|
52
52
|
error: O().nullable(),
|
|
53
53
|
errorMessage: O().nullable(),
|
|
54
54
|
startedAt: k().nullable(),
|
|
@@ -57,34 +57,34 @@ var R = D("ai_flows", {
|
|
|
57
57
|
sessionId: O().nullable(),
|
|
58
58
|
sessionName: O().nullable(),
|
|
59
59
|
ownerId: O().nullable(),
|
|
60
|
-
metadata:
|
|
61
|
-
}).with(A(), j()).index(["flowRef"]).index(["status"]).index(["requestId"]).reactive(),
|
|
60
|
+
metadata: E().nullable()
|
|
61
|
+
}).with(A(), j()).index(["flowRef"]).index(["status"]).index(["requestId"]).reactive(), Oe = [I, L], ke = /\{\{\s*([\w.-]+)\s*\}\}/g, R = (e) => {
|
|
62
62
|
let t = [];
|
|
63
|
-
for (let n of e.matchAll(
|
|
63
|
+
for (let n of e.matchAll(ke)) t.push(n[1]);
|
|
64
64
|
return t;
|
|
65
|
-
},
|
|
65
|
+
}, z = (e, t) => e.replace(ke, (e, n) => {
|
|
66
66
|
let r = t[n];
|
|
67
67
|
return r == null ? "" : typeof r == "string" ? r : JSON.stringify(r);
|
|
68
|
-
}),
|
|
68
|
+
}), Ae = (e, t) => {
|
|
69
69
|
let n = /* @__PURE__ */ new Set();
|
|
70
|
-
for (let r of
|
|
70
|
+
for (let r of R(e)) t[r] == null && !n.has(r) && n.add(r);
|
|
71
71
|
return [...n];
|
|
72
|
-
},
|
|
73
|
-
|
|
74
|
-
},
|
|
75
|
-
value:
|
|
76
|
-
text:
|
|
77
|
-
url:
|
|
78
|
-
costMicroUsd:
|
|
79
|
-
requestId:
|
|
80
|
-
error:
|
|
81
|
-
}),
|
|
82
|
-
let r =
|
|
72
|
+
}, B = /* @__PURE__ */ new Map(), V = (e) => {
|
|
73
|
+
B.set(e.name, e);
|
|
74
|
+
}, H = (e) => B.get(e), U = () => [...B.values()], je = () => B.clear(), W = (e) => e, Me = C.Struct({
|
|
75
|
+
value: C.optional(C.Unknown),
|
|
76
|
+
text: C.optional(C.String),
|
|
77
|
+
url: C.optional(C.String),
|
|
78
|
+
costMicroUsd: C.optional(C.Number),
|
|
79
|
+
requestId: C.optional(C.String),
|
|
80
|
+
error: C.optional(C.String)
|
|
81
|
+
}), G = () => (/* @__PURE__ */ new Date()).toISOString(), Ne = (e) => Math.round(e * 1e6), K = (e, t) => e.resolveModel?.(t) ?? K(e, t), q = (e, t, n) => {
|
|
82
|
+
let r = Se(t);
|
|
83
83
|
return typeof r == "number" ? Ne(r) : P(e, { model: n ?? "unknown" }).costMicroUsd ?? 0;
|
|
84
|
-
},
|
|
85
|
-
let n =
|
|
84
|
+
}, J = (e, t, n) => S.promise(() => e.store.update(L.tableName, t, n).then(() => void 0)).pipe(S.catchAllCause(() => S.void)), Pe = (e, t) => S.promise(async () => (await e.store.query(D(L).where(w("id", t)).descriptor))[0]?.status === "cancelled").pipe(S.catchAllCause(() => S.succeed(!1))), Y = (e, t) => S.gen(function* () {
|
|
85
|
+
let n = H(t);
|
|
86
86
|
if (n) return n;
|
|
87
|
-
let r = (yield*
|
|
87
|
+
let r = (yield* S.promise(() => e.store.query(D(I).where(w("id", t)).descriptor)))[0];
|
|
88
88
|
return r ? g({
|
|
89
89
|
name: r.name ?? t,
|
|
90
90
|
mode: r.mode,
|
|
@@ -95,13 +95,13 @@ var R = D("ai_flows", {
|
|
|
95
95
|
orchestratorInstructions: r.orchestratorInstructions ?? null,
|
|
96
96
|
chain: r.chainTo ?? null,
|
|
97
97
|
cadence: r.cadence ?? null
|
|
98
|
-
}) : yield*
|
|
98
|
+
}) : yield* S.fail(new fe({
|
|
99
99
|
flowRef: t,
|
|
100
100
|
message: `no flow registered or stored for "${t}"`
|
|
101
101
|
}));
|
|
102
|
-
}), Fe = (e, t, n, r, i) =>
|
|
103
|
-
let e =
|
|
104
|
-
if (a.length > 0) return { error: new
|
|
102
|
+
}), Fe = (e, t, n, r, i) => S.gen(function* () {
|
|
103
|
+
let e = z(n.prompt ?? "", r), a = Ae(n.prompt ?? "", r);
|
|
104
|
+
if (a.length > 0) return { error: new ue({
|
|
105
105
|
stepId: n.id,
|
|
106
106
|
unresolvedRef: a[0],
|
|
107
107
|
message: `step "${n.id}" references unresolved {{${a[0]}}}`
|
|
@@ -114,89 +114,89 @@ var R = D("ai_flows", {
|
|
|
114
114
|
};
|
|
115
115
|
case "agent": {
|
|
116
116
|
if (!n.agentRef) return { error: "agent step missing agentRef" };
|
|
117
|
-
if (!t.resolveAgent) return { error: new
|
|
117
|
+
if (!t.resolveAgent) return { error: new b({
|
|
118
118
|
capability: "resolveAgent",
|
|
119
119
|
message: "no agent resolver configured"
|
|
120
120
|
}).message };
|
|
121
|
-
let r = yield* t.resolveAgent(n.agentRef).pipe(
|
|
121
|
+
let r = yield* W(t.resolveAgent(n.agentRef)).pipe(S.map((e) => ({
|
|
122
122
|
ok: !0,
|
|
123
123
|
a: e
|
|
124
|
-
})),
|
|
124
|
+
})), S.catchAll((e) => S.succeed({
|
|
125
125
|
ok: !1,
|
|
126
126
|
e
|
|
127
127
|
})));
|
|
128
128
|
if (!r.ok) return { error: r.e.message };
|
|
129
|
-
let i = yield*
|
|
129
|
+
let i = yield* F({
|
|
130
130
|
system: r.a.system,
|
|
131
131
|
prompt: e,
|
|
132
|
-
provider:
|
|
133
|
-
}).pipe(
|
|
132
|
+
provider: K(t, r.a.model)
|
|
133
|
+
}).pipe(S.map((e) => ({
|
|
134
134
|
ok: !0,
|
|
135
135
|
r: e
|
|
136
|
-
})),
|
|
136
|
+
})), S.catchAll((e) => S.succeed({
|
|
137
137
|
ok: !1,
|
|
138
138
|
e
|
|
139
139
|
})));
|
|
140
140
|
return i.ok ? {
|
|
141
141
|
value: i.r.text,
|
|
142
142
|
text: i.r.text,
|
|
143
|
-
costMicroUsd:
|
|
143
|
+
costMicroUsd: q(i.r.usage, i.r.providerMetadata, r.a.model)
|
|
144
144
|
} : { error: String(i.e.message ?? i.e) };
|
|
145
145
|
}
|
|
146
146
|
case "structured": {
|
|
147
|
-
let r = n.model ?? t.defaultModels?.text, i = yield*
|
|
147
|
+
let r = n.model ?? t.defaultModels?.text, i = yield* we({
|
|
148
148
|
prompt: e,
|
|
149
|
-
schema:
|
|
150
|
-
key:
|
|
151
|
-
value:
|
|
149
|
+
schema: C.Record({
|
|
150
|
+
key: C.String,
|
|
151
|
+
value: C.Unknown
|
|
152
152
|
}),
|
|
153
|
-
...r ? { provider:
|
|
154
|
-
}).pipe(
|
|
153
|
+
...r ? { provider: K(t, r) } : {}
|
|
154
|
+
}).pipe(S.map((e) => ({
|
|
155
155
|
ok: !0,
|
|
156
156
|
r: e
|
|
157
|
-
})),
|
|
157
|
+
})), S.catchAll((e) => S.succeed({
|
|
158
158
|
ok: !1,
|
|
159
159
|
e
|
|
160
160
|
})));
|
|
161
161
|
return i.ok ? {
|
|
162
162
|
value: i.r.object,
|
|
163
163
|
text: JSON.stringify(i.r.object, null, 2),
|
|
164
|
-
costMicroUsd:
|
|
164
|
+
costMicroUsd: q(i.r.usage, i.r.providerMetadata, r)
|
|
165
165
|
} : { error: String(i.e.message ?? i.e) };
|
|
166
166
|
}
|
|
167
167
|
case "generate": {
|
|
168
168
|
let r = n.modality ?? "text";
|
|
169
169
|
if (r === "text") {
|
|
170
|
-
let r = n.model ?? t.defaultModels?.text, i = yield*
|
|
170
|
+
let r = n.model ?? t.defaultModels?.text, i = yield* F({
|
|
171
171
|
prompt: e,
|
|
172
|
-
...r ? { provider:
|
|
173
|
-
}).pipe(
|
|
172
|
+
...r ? { provider: K(t, r) } : {}
|
|
173
|
+
}).pipe(S.map((e) => ({
|
|
174
174
|
ok: !0,
|
|
175
175
|
r: e
|
|
176
|
-
})),
|
|
176
|
+
})), S.catchAll((e) => S.succeed({
|
|
177
177
|
ok: !1,
|
|
178
178
|
e
|
|
179
179
|
})));
|
|
180
180
|
return i.ok ? {
|
|
181
181
|
value: i.r.text,
|
|
182
182
|
text: i.r.text,
|
|
183
|
-
costMicroUsd:
|
|
183
|
+
costMicroUsd: q(i.r.usage, i.r.providerMetadata, r)
|
|
184
184
|
} : { error: String(i.e.message ?? i.e) };
|
|
185
185
|
}
|
|
186
|
-
if (!t.generateMedia) return { error: new
|
|
186
|
+
if (!t.generateMedia) return { error: new b({
|
|
187
187
|
capability: `media:${r}`,
|
|
188
188
|
message: `no media generator configured for ${r}`
|
|
189
189
|
}).message };
|
|
190
|
-
let a = n.model ?? t.defaultModels?.[r], o = yield* t.generateMedia({
|
|
190
|
+
let a = n.model ?? t.defaultModels?.[r], o = yield* W(t.generateMedia({
|
|
191
191
|
modality: r,
|
|
192
192
|
...a ? { model: a } : {},
|
|
193
193
|
prompt: e,
|
|
194
194
|
...n.params ? { params: n.params } : {},
|
|
195
195
|
run: i
|
|
196
|
-
}).pipe(
|
|
196
|
+
})).pipe(S.map((e) => ({
|
|
197
197
|
ok: !0,
|
|
198
198
|
m: e
|
|
199
|
-
})),
|
|
199
|
+
})), S.catchAll((e) => S.succeed({
|
|
200
200
|
ok: !1,
|
|
201
201
|
e
|
|
202
202
|
})));
|
|
@@ -207,13 +207,13 @@ var R = D("ai_flows", {
|
|
|
207
207
|
costMicroUsd: o.m.costMicroUsd ?? 0
|
|
208
208
|
} : { error: o.e.message };
|
|
209
209
|
}
|
|
210
|
-
case "human": return { error: new
|
|
210
|
+
case "human": return { error: new b({
|
|
211
211
|
capability: "human",
|
|
212
212
|
message: "human-in-the-loop steps are not yet wired (task #35)"
|
|
213
213
|
}).message };
|
|
214
214
|
default: return { error: `unknown step type: ${String(n.type)}` };
|
|
215
215
|
}
|
|
216
|
-
}), Ie = (e, t, n, r, i, a) =>
|
|
216
|
+
}), Ie = (e, t, n, r, i, a) => S.gen(function* () {
|
|
217
217
|
let o = { ...i }, c = r.steps.map((e, t) => ({
|
|
218
218
|
id: t,
|
|
219
219
|
title: e.title ?? `Step ${t + 1}`,
|
|
@@ -221,12 +221,12 @@ var R = D("ai_flows", {
|
|
|
221
221
|
status: "pending",
|
|
222
222
|
...e.description ? { description: e.description } : {}
|
|
223
223
|
})), l = 0;
|
|
224
|
-
yield*
|
|
224
|
+
yield* J(e, n, {
|
|
225
225
|
status: "running",
|
|
226
226
|
steps: c,
|
|
227
227
|
totalSteps: r.steps.length,
|
|
228
228
|
currentStep: 0,
|
|
229
|
-
startedAt:
|
|
229
|
+
startedAt: G()
|
|
230
230
|
});
|
|
231
231
|
for (let [i, u] of r.steps.entries()) {
|
|
232
232
|
if (yield* Pe(e, n)) return {
|
|
@@ -237,44 +237,44 @@ var R = D("ai_flows", {
|
|
|
237
237
|
let d = {
|
|
238
238
|
mode: u.reviewMode ?? "approve",
|
|
239
239
|
...u.options ? { options: u.options } : {},
|
|
240
|
-
prompt:
|
|
240
|
+
prompt: z(u.prompt ?? "", o)
|
|
241
241
|
};
|
|
242
242
|
c[i] = {
|
|
243
243
|
...c[i],
|
|
244
244
|
status: "waiting",
|
|
245
|
-
startedAt:
|
|
245
|
+
startedAt: G(),
|
|
246
246
|
review: d
|
|
247
|
-
}, yield*
|
|
247
|
+
}, yield* J(e, n, {
|
|
248
248
|
steps: c,
|
|
249
249
|
status: "waiting",
|
|
250
250
|
currentStep: i
|
|
251
|
-
}), t.onEvent && (yield* t.onEvent({
|
|
251
|
+
}), t.onEvent && (yield* W(t.onEvent({
|
|
252
252
|
kind: "review-needed",
|
|
253
253
|
runId: n,
|
|
254
254
|
flowName: r.name,
|
|
255
255
|
ownerId: a.ownerId,
|
|
256
256
|
source: a.source
|
|
257
|
-
}).pipe(
|
|
257
|
+
})).pipe(S.catchAllCause(() => S.void)));
|
|
258
258
|
let f = yield* xe(e, {
|
|
259
|
-
name:
|
|
259
|
+
name: y,
|
|
260
260
|
schema: s
|
|
261
|
-
}).pipe(
|
|
261
|
+
}).pipe(S.map((e) => ({
|
|
262
262
|
ok: !0,
|
|
263
263
|
a: e
|
|
264
|
-
})),
|
|
264
|
+
})), S.catchAll((e) => S.succeed({
|
|
265
265
|
ok: !1,
|
|
266
266
|
e
|
|
267
267
|
})));
|
|
268
268
|
if (!f.ok) return c[i] = {
|
|
269
269
|
...c[i],
|
|
270
270
|
status: "failed",
|
|
271
|
-
completedAt:
|
|
271
|
+
completedAt: G(),
|
|
272
272
|
errorMessage: "human review timed out or failed to decode"
|
|
273
|
-
}, yield*
|
|
273
|
+
}, yield* J(e, n, {
|
|
274
274
|
steps: c,
|
|
275
275
|
status: "failed",
|
|
276
276
|
errorMessage: "human review timed out",
|
|
277
|
-
completedAt:
|
|
277
|
+
completedAt: G(),
|
|
278
278
|
costMicroUsd: l
|
|
279
279
|
}), {
|
|
280
280
|
runId: n,
|
|
@@ -284,12 +284,12 @@ var R = D("ai_flows", {
|
|
|
284
284
|
if (p.decision === "reject") return c[i] = {
|
|
285
285
|
...c[i],
|
|
286
286
|
status: "failed",
|
|
287
|
-
completedAt:
|
|
287
|
+
completedAt: G(),
|
|
288
288
|
errorMessage: "rejected by reviewer"
|
|
289
|
-
}, yield*
|
|
289
|
+
}, yield* J(e, n, {
|
|
290
290
|
steps: c,
|
|
291
291
|
status: "cancelled",
|
|
292
|
-
completedAt:
|
|
292
|
+
completedAt: G(),
|
|
293
293
|
costMicroUsd: l
|
|
294
294
|
}), {
|
|
295
295
|
runId: n,
|
|
@@ -298,9 +298,9 @@ var R = D("ai_flows", {
|
|
|
298
298
|
u.outputKey && (o[u.outputKey] = p.value ?? p.text ?? p.decision ?? !0), c[i] = {
|
|
299
299
|
...c[i],
|
|
300
300
|
status: "succeeded",
|
|
301
|
-
completedAt:
|
|
301
|
+
completedAt: G(),
|
|
302
302
|
output: { text: String(p.text ?? p.value ?? p.decision ?? "approved") }
|
|
303
|
-
}, yield*
|
|
303
|
+
}, yield* J(e, n, {
|
|
304
304
|
steps: c,
|
|
305
305
|
status: "running",
|
|
306
306
|
currentStep: i + 1
|
|
@@ -310,8 +310,8 @@ var R = D("ai_flows", {
|
|
|
310
310
|
c[i] = {
|
|
311
311
|
...c[i],
|
|
312
312
|
status: "running",
|
|
313
|
-
startedAt:
|
|
314
|
-
}, yield*
|
|
313
|
+
startedAt: G()
|
|
314
|
+
}, yield* J(e, n, {
|
|
315
315
|
steps: c,
|
|
316
316
|
currentStep: i
|
|
317
317
|
});
|
|
@@ -327,13 +327,13 @@ var R = D("ai_flows", {
|
|
|
327
327
|
if (d.error) return c[i] = {
|
|
328
328
|
...c[i],
|
|
329
329
|
status: "failed",
|
|
330
|
-
completedAt:
|
|
330
|
+
completedAt: G(),
|
|
331
331
|
errorMessage: d.error
|
|
332
|
-
}, yield*
|
|
332
|
+
}, yield* J(e, n, {
|
|
333
333
|
steps: c,
|
|
334
334
|
status: "failed",
|
|
335
335
|
errorMessage: d.error,
|
|
336
|
-
completedAt:
|
|
336
|
+
completedAt: G(),
|
|
337
337
|
costMicroUsd: l
|
|
338
338
|
}), {
|
|
339
339
|
runId: n,
|
|
@@ -342,12 +342,12 @@ var R = D("ai_flows", {
|
|
|
342
342
|
u.outputKey && d.value !== void 0 && (o[u.outputKey] = d.value), l += d.costMicroUsd ?? 0, c[i] = {
|
|
343
343
|
...c[i],
|
|
344
344
|
status: "succeeded",
|
|
345
|
-
completedAt:
|
|
345
|
+
completedAt: G(),
|
|
346
346
|
...d.text ? { output: { text: d.text } } : {},
|
|
347
347
|
...d.url ? { url: d.url } : {},
|
|
348
348
|
...d.requestId ? { requestId: d.requestId } : {},
|
|
349
349
|
...d.costMicroUsd ? { costMicroUsd: d.costMicroUsd } : {}
|
|
350
|
-
}, yield*
|
|
350
|
+
}, yield* J(e, n, {
|
|
351
351
|
steps: c,
|
|
352
352
|
currentStep: i + 1,
|
|
353
353
|
costMicroUsd: l
|
|
@@ -355,17 +355,17 @@ var R = D("ai_flows", {
|
|
|
355
355
|
}
|
|
356
356
|
let u = {};
|
|
357
357
|
for (let e of r.steps) e.outputKey && o[e.outputKey] !== void 0 && (u[e.outputKey] = o[e.outputKey]);
|
|
358
|
-
return yield*
|
|
358
|
+
return yield* J(e, n, {
|
|
359
359
|
status: "succeeded",
|
|
360
360
|
output: u,
|
|
361
|
-
completedAt:
|
|
361
|
+
completedAt: G(),
|
|
362
362
|
costMicroUsd: l
|
|
363
363
|
}), {
|
|
364
364
|
runId: n,
|
|
365
365
|
status: "succeeded",
|
|
366
366
|
output: u
|
|
367
367
|
};
|
|
368
|
-
}), Le = (e, t, n, r, i, a) =>
|
|
368
|
+
}), Le = (e, t, n, r, i, a) => S.gen(function* () {
|
|
369
369
|
let o = n.chain;
|
|
370
370
|
if (!o || o.flowRef === n.name || o.flowRef === a.flowRef) return;
|
|
371
371
|
let s = {
|
|
@@ -374,7 +374,7 @@ var R = D("ai_flows", {
|
|
|
374
374
|
}, c = {};
|
|
375
375
|
for (let e of o.mappings) e.sourceKey in s && (c[e.targetKey] = s[e.sourceKey]);
|
|
376
376
|
if (o.requireConfirmation) {
|
|
377
|
-
yield*
|
|
377
|
+
yield* J(e, t, { chainPending: {
|
|
378
378
|
flowRef: o.flowRef,
|
|
379
379
|
input: c,
|
|
380
380
|
status: "pending"
|
|
@@ -384,9 +384,9 @@ var R = D("ai_flows", {
|
|
|
384
384
|
let l = e.workflows;
|
|
385
385
|
if (!l) return;
|
|
386
386
|
let u = `${t}--chain`, d = `${a.requestId}--chain`;
|
|
387
|
-
yield*
|
|
387
|
+
yield* S.promise(async () => {
|
|
388
388
|
try {
|
|
389
|
-
await e.store.insert(
|
|
389
|
+
await e.store.insert(L.tableName, {
|
|
390
390
|
id: u,
|
|
391
391
|
flowRef: o.flowRef,
|
|
392
392
|
flowName: o.flowRef,
|
|
@@ -403,7 +403,7 @@ var R = D("ai_flows", {
|
|
|
403
403
|
source: a.source,
|
|
404
404
|
requestId: d
|
|
405
405
|
});
|
|
406
|
-
}).pipe(
|
|
406
|
+
}).pipe(S.catchAllCause(() => S.void));
|
|
407
407
|
}), Re = (e) => e.steps.length === 0 ? "" : "Suggested plan (you MAY reorder, insert, or skip steps):\n" + e.steps.map((e, t) => `${t + 1}. [${e.type}${e.modality ? `/${e.modality}` : ""}] ${e.title ?? e.id}${e.prompt ? `: ${e.prompt}` : ""}`).join("\n"), ze = (e) => {
|
|
408
408
|
let t = Object.entries(e);
|
|
409
409
|
return t.length === 0 ? "Execute the flow." : "Brief for this run:\n" + t.map(([e, t]) => `- ${e}: ${typeof t == "string" ? t : JSON.stringify(t)}`).join("\n");
|
|
@@ -411,52 +411,52 @@ var R = D("ai_flows", {
|
|
|
411
411
|
e.orchestrator?.instructions ?? "You are an orchestrator that uses the available tools to produce a bundled result.",
|
|
412
412
|
Re(e),
|
|
413
413
|
"When finished, emit a JSON object mapping each deliverable name (outputKey) to its value."
|
|
414
|
-
].filter(Boolean).join("\n\n"), Ve =
|
|
415
|
-
object:
|
|
416
|
-
key:
|
|
417
|
-
value:
|
|
414
|
+
].filter(Boolean).join("\n\n"), Ve = C.Struct({
|
|
415
|
+
object: C.Record({
|
|
416
|
+
key: C.String,
|
|
417
|
+
value: C.Unknown
|
|
418
418
|
}),
|
|
419
|
-
planCostMicroUsd:
|
|
420
|
-
toolCostMicroUsd:
|
|
421
|
-
steps:
|
|
422
|
-
error:
|
|
423
|
-
}), He = (e, t, n, r, i, a, o) =>
|
|
424
|
-
yield*
|
|
419
|
+
planCostMicroUsd: C.Number,
|
|
420
|
+
toolCostMicroUsd: C.Number,
|
|
421
|
+
steps: C.Array(ie),
|
|
422
|
+
error: C.optional(C.String)
|
|
423
|
+
}), He = (e, t, n, r, i, a, o) => S.gen(function* () {
|
|
424
|
+
yield* J(e, n, {
|
|
425
425
|
status: "running",
|
|
426
|
-
startedAt:
|
|
426
|
+
startedAt: G(),
|
|
427
427
|
totalSteps: r.steps.length
|
|
428
428
|
});
|
|
429
429
|
let s = yield* M({
|
|
430
430
|
name: "flow-agentic",
|
|
431
431
|
input: { flowRef: r.name },
|
|
432
432
|
success: Ve,
|
|
433
|
-
execute:
|
|
433
|
+
execute: S.gen(function* () {
|
|
434
434
|
let s = [], c = 0, l = (e) => {
|
|
435
435
|
let t = s.length;
|
|
436
436
|
return s.push({
|
|
437
437
|
id: t,
|
|
438
438
|
status: "running",
|
|
439
|
-
startedAt:
|
|
439
|
+
startedAt: G(),
|
|
440
440
|
...e
|
|
441
441
|
}), t;
|
|
442
442
|
}, u = (e, t) => {
|
|
443
443
|
s[e] = {
|
|
444
444
|
...s[e],
|
|
445
|
-
completedAt:
|
|
445
|
+
completedAt: G(),
|
|
446
446
|
...t
|
|
447
447
|
};
|
|
448
|
-
}, d = () =>
|
|
448
|
+
}, d = () => J(e, n, {
|
|
449
449
|
steps: s,
|
|
450
450
|
currentStep: s.length,
|
|
451
451
|
costMicroUsd: c
|
|
452
452
|
}), f = N({
|
|
453
453
|
name: "run_agent",
|
|
454
454
|
description: "Delegate a text task to an allowed sub-agent. Returns the agent's text.",
|
|
455
|
-
input:
|
|
456
|
-
agentRef:
|
|
457
|
-
prompt:
|
|
455
|
+
input: C.Struct({
|
|
456
|
+
agentRef: C.String,
|
|
457
|
+
prompt: C.String
|
|
458
458
|
}),
|
|
459
|
-
execute: ({ agentRef: e, prompt: n }) =>
|
|
459
|
+
execute: ({ agentRef: e, prompt: n }) => S.gen(function* () {
|
|
460
460
|
let r = l({
|
|
461
461
|
title: `agent:${e}`,
|
|
462
462
|
type: "agent"
|
|
@@ -465,10 +465,10 @@ var R = D("ai_flows", {
|
|
|
465
465
|
status: "failed",
|
|
466
466
|
errorMessage: "no agent resolver configured"
|
|
467
467
|
}), yield* d(), "ERROR: no agent resolver configured";
|
|
468
|
-
let i = yield* t.resolveAgent(e).pipe(
|
|
468
|
+
let i = yield* W(t.resolveAgent(e)).pipe(S.map((e) => ({
|
|
469
469
|
ok: !0,
|
|
470
470
|
a: e
|
|
471
|
-
})),
|
|
471
|
+
})), S.catchAll((e) => S.succeed({
|
|
472
472
|
ok: !1,
|
|
473
473
|
e
|
|
474
474
|
})));
|
|
@@ -476,14 +476,14 @@ var R = D("ai_flows", {
|
|
|
476
476
|
status: "failed",
|
|
477
477
|
errorMessage: i.e.message
|
|
478
478
|
}), yield* d(), `ERROR: ${i.e.message}`;
|
|
479
|
-
let a = yield*
|
|
479
|
+
let a = yield* F({
|
|
480
480
|
system: i.a.system,
|
|
481
481
|
prompt: n,
|
|
482
|
-
provider:
|
|
483
|
-
}).pipe(
|
|
482
|
+
provider: K(t, i.a.model)
|
|
483
|
+
}).pipe(S.map((e) => ({
|
|
484
484
|
ok: !0,
|
|
485
485
|
r: e
|
|
486
|
-
})),
|
|
486
|
+
})), S.catchAll((e) => S.succeed({
|
|
487
487
|
ok: !1,
|
|
488
488
|
e
|
|
489
489
|
})));
|
|
@@ -494,7 +494,7 @@ var R = D("ai_flows", {
|
|
|
494
494
|
errorMessage: e
|
|
495
495
|
}), yield* d(), `ERROR: ${e}`;
|
|
496
496
|
}
|
|
497
|
-
let o =
|
|
497
|
+
let o = q(a.r.usage, a.r.providerMetadata, i.a.model);
|
|
498
498
|
return c += o, u(r, {
|
|
499
499
|
status: "succeeded",
|
|
500
500
|
output: { text: a.r.text },
|
|
@@ -504,12 +504,12 @@ var R = D("ai_flows", {
|
|
|
504
504
|
}), p = N({
|
|
505
505
|
name: "generate_media",
|
|
506
506
|
description: "Generate an image, video, or audio artifact. Returns the hosted URL.",
|
|
507
|
-
input:
|
|
508
|
-
modality:
|
|
509
|
-
prompt:
|
|
510
|
-
model:
|
|
507
|
+
input: C.Struct({
|
|
508
|
+
modality: C.Literal("image", "video", "audio"),
|
|
509
|
+
prompt: C.String,
|
|
510
|
+
model: C.optional(C.String)
|
|
511
511
|
}),
|
|
512
|
-
execute: ({ modality: e, prompt: r, model: i }) =>
|
|
512
|
+
execute: ({ modality: e, prompt: r, model: i }) => S.gen(function* () {
|
|
513
513
|
let a = l({
|
|
514
514
|
title: `media:${e}`,
|
|
515
515
|
type: "generate"
|
|
@@ -518,7 +518,7 @@ var R = D("ai_flows", {
|
|
|
518
518
|
status: "failed",
|
|
519
519
|
errorMessage: `no media generator for ${e}`
|
|
520
520
|
}), yield* d(), `ERROR: no media generator configured for ${e}`;
|
|
521
|
-
let s = yield* t.generateMedia({
|
|
521
|
+
let s = yield* W(t.generateMedia({
|
|
522
522
|
modality: e,
|
|
523
523
|
prompt: r,
|
|
524
524
|
...i ? { model: i } : {},
|
|
@@ -526,10 +526,10 @@ var R = D("ai_flows", {
|
|
|
526
526
|
runId: n,
|
|
527
527
|
tenantId: o
|
|
528
528
|
}
|
|
529
|
-
}).pipe(
|
|
529
|
+
})).pipe(S.map((e) => ({
|
|
530
530
|
ok: !0,
|
|
531
531
|
r: e
|
|
532
|
-
})),
|
|
532
|
+
})), S.catchAll((e) => S.succeed({
|
|
533
533
|
ok: !1,
|
|
534
534
|
e
|
|
535
535
|
})));
|
|
@@ -546,27 +546,27 @@ var R = D("ai_flows", {
|
|
|
546
546
|
}), ee = N({
|
|
547
547
|
name: "pick_structured",
|
|
548
548
|
description: "Produce a JSON object for a task. Returns the object.",
|
|
549
|
-
input:
|
|
550
|
-
prompt:
|
|
551
|
-
model:
|
|
549
|
+
input: C.Struct({
|
|
550
|
+
prompt: C.String,
|
|
551
|
+
model: C.optional(C.String)
|
|
552
552
|
}),
|
|
553
|
-
execute: ({ prompt: e, model: n }) =>
|
|
553
|
+
execute: ({ prompt: e, model: n }) => S.gen(function* () {
|
|
554
554
|
let r = l({
|
|
555
555
|
title: "structured",
|
|
556
556
|
type: "structured"
|
|
557
557
|
});
|
|
558
558
|
yield* d();
|
|
559
|
-
let i = yield*
|
|
559
|
+
let i = yield* we({
|
|
560
560
|
prompt: e,
|
|
561
|
-
schema:
|
|
562
|
-
key:
|
|
563
|
-
value:
|
|
561
|
+
schema: C.Record({
|
|
562
|
+
key: C.String,
|
|
563
|
+
value: C.Unknown
|
|
564
564
|
}),
|
|
565
|
-
...n ? { provider:
|
|
566
|
-
}).pipe(
|
|
565
|
+
...n ? { provider: K(t, n) } : {}
|
|
566
|
+
}).pipe(S.map((e) => ({
|
|
567
567
|
ok: !0,
|
|
568
568
|
r: e
|
|
569
|
-
})),
|
|
569
|
+
})), S.catchAll((e) => S.succeed({
|
|
570
570
|
ok: !1,
|
|
571
571
|
e
|
|
572
572
|
})));
|
|
@@ -577,19 +577,19 @@ var R = D("ai_flows", {
|
|
|
577
577
|
errorMessage: e
|
|
578
578
|
}), yield* d(), { error: e };
|
|
579
579
|
}
|
|
580
|
-
let a =
|
|
580
|
+
let a = q(i.r.usage, i.r.providerMetadata, n);
|
|
581
581
|
return c += a, u(r, {
|
|
582
582
|
status: "succeeded",
|
|
583
583
|
output: { text: JSON.stringify(i.r.object) },
|
|
584
584
|
costMicroUsd: a
|
|
585
585
|
}), yield* d(), i.r.object;
|
|
586
586
|
})
|
|
587
|
-
}), m = t.memoryPrefix ? yield* t.memoryPrefix(a).pipe(
|
|
587
|
+
}), m = t.memoryPrefix ? yield* W(t.memoryPrefix(a)).pipe(S.catchAll(() => S.succeed(""))) : "", h = yield* Te({
|
|
588
588
|
system: m ? `${m}\n\n${Be(r)}` : Be(r),
|
|
589
589
|
prompt: ze(i),
|
|
590
|
-
schema:
|
|
591
|
-
key:
|
|
592
|
-
value:
|
|
590
|
+
schema: C.Record({
|
|
591
|
+
key: C.String,
|
|
592
|
+
value: C.Unknown
|
|
593
593
|
}),
|
|
594
594
|
tools: {
|
|
595
595
|
run_agent: f,
|
|
@@ -597,17 +597,17 @@ var R = D("ai_flows", {
|
|
|
597
597
|
pick_structured: ee
|
|
598
598
|
},
|
|
599
599
|
maxSteps: r.maxSteps,
|
|
600
|
-
...r.orchestrator?.model ? { provider:
|
|
601
|
-
}).pipe(
|
|
600
|
+
...r.orchestrator?.model ? { provider: K(t, r.orchestrator.model) } : {}
|
|
601
|
+
}).pipe(S.map((e) => ({
|
|
602
602
|
ok: !0,
|
|
603
603
|
r: e
|
|
604
|
-
})),
|
|
604
|
+
})), S.catchAll((e) => S.succeed({
|
|
605
605
|
ok: !1,
|
|
606
606
|
e
|
|
607
607
|
})));
|
|
608
608
|
return h.ok ? {
|
|
609
609
|
object: h.r.object,
|
|
610
|
-
planCostMicroUsd:
|
|
610
|
+
planCostMicroUsd: q(h.r.usage, h.r.providerMetadata, r.orchestrator?.model),
|
|
611
611
|
toolCostMicroUsd: c,
|
|
612
612
|
steps: s
|
|
613
613
|
} : {
|
|
@@ -619,59 +619,59 @@ var R = D("ai_flows", {
|
|
|
619
619
|
};
|
|
620
620
|
})
|
|
621
621
|
}), c = s.planCostMicroUsd + s.toolCostMicroUsd;
|
|
622
|
-
return s.error ? (yield*
|
|
622
|
+
return s.error ? (yield* J(e, n, {
|
|
623
623
|
status: "failed",
|
|
624
624
|
steps: s.steps,
|
|
625
625
|
errorMessage: s.error,
|
|
626
|
-
completedAt:
|
|
626
|
+
completedAt: G(),
|
|
627
627
|
costMicroUsd: c
|
|
628
628
|
}), {
|
|
629
629
|
runId: n,
|
|
630
630
|
status: "failed"
|
|
631
|
-
}) : (yield*
|
|
631
|
+
}) : (yield* J(e, n, {
|
|
632
632
|
status: "succeeded",
|
|
633
633
|
steps: s.steps,
|
|
634
634
|
output: s.object,
|
|
635
|
-
completedAt:
|
|
635
|
+
completedAt: G(),
|
|
636
636
|
costMicroUsd: c
|
|
637
637
|
}), {
|
|
638
638
|
runId: n,
|
|
639
639
|
status: "succeeded",
|
|
640
640
|
output: s.object
|
|
641
641
|
});
|
|
642
|
-
}), Ue = (e, t = {}) => (n, r) =>
|
|
642
|
+
}), Ue = (e, t = {}) => (n, r) => S.gen(function* () {
|
|
643
643
|
let { runId: r, flowRef: i, input: a } = n, o = yield* M({
|
|
644
644
|
name: "flow-0-resolve",
|
|
645
645
|
input: { flowRef: i },
|
|
646
|
-
success:
|
|
647
|
-
ir:
|
|
648
|
-
error:
|
|
646
|
+
success: C.Struct({
|
|
647
|
+
ir: C.Unknown,
|
|
648
|
+
error: C.optional(C.String)
|
|
649
649
|
}),
|
|
650
|
-
execute:
|
|
650
|
+
execute: Y(e, i).pipe(S.map((e) => ({ ir: e })), S.catchAll((e) => S.succeed({
|
|
651
651
|
ir: void 0,
|
|
652
652
|
error: e.message
|
|
653
653
|
})))
|
|
654
654
|
});
|
|
655
|
-
if (o.error || !o.ir) return yield*
|
|
655
|
+
if (o.error || !o.ir) return yield* J(e, r, {
|
|
656
656
|
status: "failed",
|
|
657
657
|
errorMessage: o.error ?? "flow not found",
|
|
658
|
-
completedAt:
|
|
658
|
+
completedAt: G()
|
|
659
659
|
}), {
|
|
660
660
|
runId: r,
|
|
661
661
|
status: "failed"
|
|
662
662
|
};
|
|
663
|
-
let s = o.ir, c = (yield*
|
|
663
|
+
let s = o.ir, c = (yield* S.promise(() => e.store.query(D(L).where(w("id", r)).descriptor)).pipe(S.catchAllCause(() => S.succeed([]))))[0], l = c?.ownerId ?? null, u = c?.tenantId ?? null, d = s.mode === "agentic" ? yield* He(e, t, r, s, a, l, u) : yield* Ie(e, t, r, s, a, {
|
|
664
664
|
ownerId: l,
|
|
665
665
|
tenantId: u,
|
|
666
666
|
source: n.source
|
|
667
667
|
});
|
|
668
|
-
return d.status === "succeeded" && s.chain && (yield* Le(e, r, s, a, d.output ?? {}, n)), t.onEvent && (d.status === "succeeded" || d.status === "failed") && (yield* t.onEvent({
|
|
668
|
+
return d.status === "succeeded" && s.chain && (yield* Le(e, r, s, a, d.output ?? {}, n)), t.onEvent && (d.status === "succeeded" || d.status === "failed") && (yield* W(t.onEvent({
|
|
669
669
|
kind: d.status,
|
|
670
670
|
runId: r,
|
|
671
671
|
flowName: s.name,
|
|
672
672
|
ownerId: l,
|
|
673
673
|
source: n.source
|
|
674
|
-
}).pipe(
|
|
674
|
+
})).pipe(S.catchAllCause(() => S.void))), d;
|
|
675
675
|
}), We = {
|
|
676
676
|
text: (e) => ({
|
|
677
677
|
type: "generate",
|
|
@@ -705,10 +705,10 @@ var R = D("ai_flows", {
|
|
|
705
705
|
}), Ke = (e) => {
|
|
706
706
|
let t = new Set(e.brief.map((e) => e.key)), n = [];
|
|
707
707
|
for (let r of e.steps) {
|
|
708
|
-
for (let e of
|
|
709
|
-
r.outputKey && t.add(
|
|
708
|
+
for (let e of R(r.prompt ?? "")) t.has(e) || n.push(`step "${r.id}" references {{${e}}} which is not a brief field or a prior step outputKey`);
|
|
709
|
+
r.outputKey && t.add(_(r.outputKey));
|
|
710
710
|
}
|
|
711
|
-
if (n.length > 0) throw new
|
|
711
|
+
if (n.length > 0) throw new pe({
|
|
712
712
|
flowRef: e.name,
|
|
713
713
|
message: `flow "${e.name}" has ${n.length} unresolved reference(s)`,
|
|
714
714
|
issues: n
|
|
@@ -725,10 +725,10 @@ var R = D("ai_flows", {
|
|
|
725
725
|
chain: e.chain,
|
|
726
726
|
cadence: e.cadence
|
|
727
727
|
});
|
|
728
|
-
return Ke(t),
|
|
729
|
-
},
|
|
728
|
+
return Ke(t), V(t), t;
|
|
729
|
+
}, X = (e) => String(e).padStart(2, "0"), Je = (e, t) => `cron-${e}-${t.getFullYear()}${X(t.getMonth() + 1)}${X(t.getDate())}-${X(t.getHours())}${X(t.getMinutes())}`, Ye = async (e) => {
|
|
730
730
|
let t = [];
|
|
731
|
-
for (let e of
|
|
731
|
+
for (let e of U()) e.cadence && (e.cadence.repeats?.length ?? 0) > 0 && t.push({
|
|
732
732
|
flowRef: e.name,
|
|
733
733
|
cadence: e.cadence,
|
|
734
734
|
defaultInput: e.cadence.defaultInput ?? {}
|
|
@@ -740,11 +740,11 @@ var R = D("ai_flows", {
|
|
|
740
740
|
defaultInput: e.cadence.defaultInput ?? {}
|
|
741
741
|
});
|
|
742
742
|
return t;
|
|
743
|
-
},
|
|
744
|
-
let n = e.workflows, r = [], i = 0, a = await
|
|
743
|
+
}, Xe = async (e, t = /* @__PURE__ */ new Date()) => {
|
|
744
|
+
let n = e.workflows, r = [], i = 0, a = await Ye(e).catch(() => []);
|
|
745
745
|
for (let o of a) {
|
|
746
|
-
if (!
|
|
747
|
-
let a =
|
|
746
|
+
if (!he(o.cadence, t) || (i += 1, !n)) continue;
|
|
747
|
+
let a = Je(o.flowRef, t), s = `run-${a}`;
|
|
748
748
|
try {
|
|
749
749
|
try {
|
|
750
750
|
await e.store.insert("ai_flow_runs", {
|
|
@@ -770,25 +770,25 @@ var R = D("ai_flows", {
|
|
|
770
770
|
matched: i,
|
|
771
771
|
started: r
|
|
772
772
|
};
|
|
773
|
-
},
|
|
773
|
+
}, Ze = (e) => ({
|
|
774
774
|
name: "gateway",
|
|
775
775
|
model: e
|
|
776
|
-
}),
|
|
777
|
-
let r =
|
|
778
|
-
return typeof r == "number" ?
|
|
779
|
-
},
|
|
780
|
-
let r = n.model, i = (e) => t?.resolveModel?.(e) ??
|
|
781
|
-
return
|
|
776
|
+
}), Qe = (e) => Math.round(e * 1e6), Z = (e, t, n) => {
|
|
777
|
+
let r = Se(t);
|
|
778
|
+
return typeof r == "number" ? Qe(r) : e ? P(e, { model: n ?? "unknown" }).costMicroUsd ?? 0 : 0;
|
|
779
|
+
}, $e = (e, t) => (n) => {
|
|
780
|
+
let r = n.model, i = (e) => t?.resolveModel?.(e) ?? Ze(e);
|
|
781
|
+
return S.gen(function* () {
|
|
782
782
|
if (n.modality === "image") {
|
|
783
|
-
let t = yield*
|
|
783
|
+
let t = yield* Ce({
|
|
784
784
|
prompt: n.prompt,
|
|
785
785
|
...r ? { provider: i(r) } : {}
|
|
786
786
|
}), a = t.images[0];
|
|
787
|
-
if (!a) return yield*
|
|
787
|
+
if (!a) return yield* S.fail(new b({
|
|
788
788
|
capability: "media:image",
|
|
789
789
|
message: "no image produced"
|
|
790
790
|
}));
|
|
791
|
-
let o = yield*
|
|
791
|
+
let o = yield* S.promise(() => e.put({
|
|
792
792
|
data: a.data,
|
|
793
793
|
mediaType: a.mediaType,
|
|
794
794
|
run: n.run
|
|
@@ -800,10 +800,10 @@ var R = D("ai_flows", {
|
|
|
800
800
|
};
|
|
801
801
|
}
|
|
802
802
|
if (n.modality === "audio") {
|
|
803
|
-
let t = yield*
|
|
803
|
+
let t = yield* Ee({
|
|
804
804
|
text: n.prompt,
|
|
805
805
|
...r ? { provider: i(r) } : {}
|
|
806
|
-
}), a = yield*
|
|
806
|
+
}), a = yield* S.promise(() => e.put({
|
|
807
807
|
data: t.audio.data,
|
|
808
808
|
mediaType: t.audio.mediaType,
|
|
809
809
|
run: n.run
|
|
@@ -814,18 +814,18 @@ var R = D("ai_flows", {
|
|
|
814
814
|
costMicroUsd: Z(t.usage, t.providerMetadata, r)
|
|
815
815
|
};
|
|
816
816
|
}
|
|
817
|
-
let t = yield*
|
|
817
|
+
let t = yield* De({
|
|
818
818
|
prompt: n.prompt,
|
|
819
819
|
...r ? { provider: i(r) } : {},
|
|
820
820
|
...n.params ? { params: n.params } : {}
|
|
821
821
|
}), a;
|
|
822
|
-
if (t.video.url) a = e.ingestUrl ? yield*
|
|
823
|
-
else if (t.video.data) a = yield*
|
|
822
|
+
if (t.video.url) a = e.ingestUrl ? yield* S.promise(() => e.ingestUrl(t.video.url, n.run)) : { url: t.video.url };
|
|
823
|
+
else if (t.video.data) a = yield* S.promise(() => e.put({
|
|
824
824
|
data: t.video.data,
|
|
825
825
|
mediaType: t.video.mediaType,
|
|
826
826
|
run: n.run
|
|
827
827
|
}));
|
|
828
|
-
else return yield*
|
|
828
|
+
else return yield* S.fail(new b({
|
|
829
829
|
capability: "media:video",
|
|
830
830
|
message: "no video produced"
|
|
831
831
|
}));
|
|
@@ -834,18 +834,18 @@ var R = D("ai_flows", {
|
|
|
834
834
|
...a.refId ? { requestId: a.refId } : {},
|
|
835
835
|
costMicroUsd: Z(t.usage, t.providerMetadata, r)
|
|
836
836
|
};
|
|
837
|
-
}).pipe(
|
|
837
|
+
}).pipe(S.catchAll((e) => e instanceof b ? S.fail(e) : S.fail(new b({
|
|
838
838
|
capability: `media:${n.modality}`,
|
|
839
839
|
message: String(e.message ?? e)
|
|
840
840
|
}))));
|
|
841
|
-
}, Q = () => globalThis.crypto?.randomUUID?.() ?? `req-${Date.now().toString(36)}`,
|
|
842
|
-
let n = yield*
|
|
843
|
-
if (i.length > 0) return yield*
|
|
841
|
+
}, Q = () => globalThis.crypto?.randomUUID?.() ?? `req-${Date.now().toString(36)}`, et = (e) => e.request?.subject?.id ?? null, $ = (e, t) => S.promise(() => e.store.query(D(L).where(w("id", t)).descriptor)).pipe(S.map((e) => e[0])), tt = (e, t) => S.gen(function* () {
|
|
842
|
+
let n = yield* Y(e, t.flowRef), r = t.input ?? {}, i = n.brief.filter((e) => e.required && e.type !== "boolean" && (r[e.key] === void 0 || r[e.key] === null || r[e.key] === "")).map((e) => e.key);
|
|
843
|
+
if (i.length > 0) return yield* S.fail(new le({
|
|
844
844
|
missing: i,
|
|
845
845
|
message: `missing required brief field(s): ${i.join(", ")}`
|
|
846
846
|
}));
|
|
847
847
|
let a = Q(), o = `run-${a}`, s = t.source ?? "manual";
|
|
848
|
-
yield*
|
|
848
|
+
yield* S.promise(() => e.store.insert(L.tableName, {
|
|
849
849
|
id: o,
|
|
850
850
|
flowRef: t.flowRef,
|
|
851
851
|
flowName: n.name,
|
|
@@ -854,10 +854,10 @@ var R = D("ai_flows", {
|
|
|
854
854
|
source: s,
|
|
855
855
|
requestId: a,
|
|
856
856
|
input: r,
|
|
857
|
-
ownerId:
|
|
857
|
+
ownerId: et(e)
|
|
858
858
|
}));
|
|
859
859
|
let c = e.workflows;
|
|
860
|
-
return c && (yield*
|
|
860
|
+
return c && (yield* S.promise(() => c.start(v, {
|
|
861
861
|
runId: o,
|
|
862
862
|
flowRef: t.flowRef,
|
|
863
863
|
input: r,
|
|
@@ -868,20 +868,20 @@ var R = D("ai_flows", {
|
|
|
868
868
|
requestId: a,
|
|
869
869
|
status: "pending"
|
|
870
870
|
};
|
|
871
|
-
}),
|
|
871
|
+
}), nt = (e, t) => S.gen(function* () {
|
|
872
872
|
let n = yield* $(e, t.runId);
|
|
873
|
-
if (!n) return yield*
|
|
873
|
+
if (!n) return yield* S.fail(new x({
|
|
874
874
|
runId: t.runId,
|
|
875
875
|
message: "run not found"
|
|
876
876
|
}));
|
|
877
877
|
let r = n.requestId ?? Q(), i = n.flowRef, a = n.input ?? {}, o = n.source ?? "manual";
|
|
878
|
-
yield*
|
|
878
|
+
yield* S.promise(() => e.store.update(L.tableName, t.runId, {
|
|
879
879
|
status: "pending",
|
|
880
880
|
error: null,
|
|
881
881
|
errorMessage: null
|
|
882
882
|
}));
|
|
883
883
|
let s = e.workflows;
|
|
884
|
-
return s && (yield*
|
|
884
|
+
return s && (yield* S.promise(() => s.start(v, {
|
|
885
885
|
runId: t.runId,
|
|
886
886
|
flowRef: i,
|
|
887
887
|
input: a,
|
|
@@ -892,25 +892,25 @@ var R = D("ai_flows", {
|
|
|
892
892
|
requestId: r,
|
|
893
893
|
status: "pending"
|
|
894
894
|
};
|
|
895
|
-
}),
|
|
896
|
-
return (yield* $(e, t.runId)) ? (yield*
|
|
895
|
+
}), rt = (e, t) => S.gen(function* () {
|
|
896
|
+
return (yield* $(e, t.runId)) ? (yield* S.promise(() => e.store.update(L.tableName, t.runId, {
|
|
897
897
|
status: "cancelled",
|
|
898
898
|
cancelledAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
899
899
|
})), {
|
|
900
900
|
runId: t.runId,
|
|
901
901
|
status: "cancelled"
|
|
902
|
-
}) : yield*
|
|
902
|
+
}) : yield* S.fail(new x({
|
|
903
903
|
runId: t.runId,
|
|
904
904
|
message: "run not found"
|
|
905
905
|
}));
|
|
906
|
-
}),
|
|
906
|
+
}), it = (e, t) => S.gen(function* () {
|
|
907
907
|
let n = yield* $(e, t.runId);
|
|
908
|
-
if (!n) return yield*
|
|
908
|
+
if (!n) return yield* S.fail(new x({
|
|
909
909
|
runId: t.runId,
|
|
910
910
|
message: "run not found"
|
|
911
911
|
}));
|
|
912
912
|
let r = n.status;
|
|
913
|
-
if (r !== "waiting") return yield*
|
|
913
|
+
if (r !== "waiting") return yield* S.fail(new de({
|
|
914
914
|
runId: t.runId,
|
|
915
915
|
status: r ?? "unknown",
|
|
916
916
|
message: `run is "${r}", not awaiting a response`
|
|
@@ -919,16 +919,16 @@ var R = D("ai_flows", {
|
|
|
919
919
|
...t.response,
|
|
920
920
|
respondedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
921
921
|
};
|
|
922
|
-
yield*
|
|
922
|
+
yield* S.promise(() => e.store.update(L.tableName, t.runId, { humanResponse: i }));
|
|
923
923
|
let a = e.workflows, o = n.requestId;
|
|
924
|
-
return a && o && (yield*
|
|
925
|
-
workflowName:
|
|
924
|
+
return a && o && (yield* S.promise(() => a.signal({
|
|
925
|
+
workflowName: v,
|
|
926
926
|
executionId: `flow-run:${o}`
|
|
927
|
-
},
|
|
928
|
-
}),
|
|
927
|
+
}, y, i)).pipe(S.catchAllCause(() => S.void))), { runId: t.runId };
|
|
928
|
+
}), at = (e, t) => S.promise(() => e.store.query(D(I).where(w("id", t.id)).descriptor)).pipe(S.map((e) => e[0])), ot = (e) => S.promise(() => e.store.query(D(I).descriptor)), st = (e, t) => S.promise(() => e.store.insert(I.tableName, {
|
|
929
929
|
id: t.id ?? `flow-${Q()}`,
|
|
930
930
|
...t
|
|
931
|
-
})),
|
|
931
|
+
})), ct = (e, t) => S.promise(() => e.store.update(I.tableName, t.id, t.patch)), lt = (e, t) => S.promise(() => e.store.delete(I.tableName, t.id)), ut = (e = {}) => {
|
|
932
932
|
let t = e.alias ?? "aiFlows", n = { current: void 0 }, r = (e) => ({
|
|
933
933
|
kind: "json",
|
|
934
934
|
data: e
|
|
@@ -936,7 +936,7 @@ var R = D("ai_flows", {
|
|
|
936
936
|
kind: "json",
|
|
937
937
|
status: e,
|
|
938
938
|
data: { error: t }
|
|
939
|
-
}), a = (e, t) =>
|
|
939
|
+
}), a = (e, t) => S.promise(async () => {
|
|
940
940
|
let a = n.current;
|
|
941
941
|
if (!a) return i(503, "store not bound yet");
|
|
942
942
|
let o = await a.query({
|
|
@@ -951,12 +951,12 @@ var R = D("ai_flows", {
|
|
|
951
951
|
count: o.length,
|
|
952
952
|
rows: o
|
|
953
953
|
});
|
|
954
|
-
}).pipe(
|
|
955
|
-
return
|
|
954
|
+
}).pipe(S.catchAllCause(() => S.succeed(i(500, "query failed"))));
|
|
955
|
+
return ge({
|
|
956
956
|
name: t,
|
|
957
957
|
description: "AI Flows — durable multi-step AI pipelines (deterministic + agentic) with human-in-the-loop, chaining, and cadence. Code-first (defineFlow) or data-driven.",
|
|
958
958
|
permissions: ["store:write", "inspect:read"],
|
|
959
|
-
extendSchema: { tables:
|
|
959
|
+
extendSchema: { tables: Oe },
|
|
960
960
|
inspectEndpoints: [{
|
|
961
961
|
method: "GET",
|
|
962
962
|
path: "/flows",
|
|
@@ -974,4 +974,4 @@ var R = D("ai_flows", {
|
|
|
974
974
|
});
|
|
975
975
|
};
|
|
976
976
|
//#endregion
|
|
977
|
-
export { e as BriefField, t as ChainPending,
|
|
977
|
+
export { e as BriefField, t as ChainPending, v as FLOW_RUN_WORKFLOW, n as FlowCadence, r as FlowChain, i as FlowMode, a as FlowStatus, o as FlowStep, y as HUMAN_RESPONSE_SIGNAL, s as HumanResponse, c as Json, l as MAX_STEPS_DEFAULT, u as MAX_STEPS_MAX, d as MAX_STEPS_MIN, f as MediaInputSlot, p as MediaInputs, ee as Modality, m as ReviewMode, h as ReviewOption, te as RunReview, ne as RunSource, re as RunStatus, ie as RunStep, ae as RunStepStatus, oe as StepType, se as Visibility, L as aiFlowRunsTable, ut as aiFlowsPlugin, I as aiFlowsTable, Oe as aiFlowsTables, Ue as buildFlowRunExecute, he as cadenceMatches, rt as cancelFlow, ce as clampMaxSteps, je as clearRegistry, R as collectRefs, st as createFlow, Je as cronRequestId, qe as defineFlow, lt as deleteFlow, We as flowStep, at as getFlow, H as getRegisteredFlow, z as interpolate, tt as launchFlow, ot as listFlows, U as listRegisteredFlows, $e as makeMediaGenerator, me as nextRuns, g as normalizeFlow, V as registerFlow, Y as resolveIr, it as respondToFlow, nt as retryFlow, Xe as runCadenceTick, _ as sanitizeOutputKey, Ae as unresolvedRefs, ct as updateFlow, Ke as validateFlow };
|