@voltro/plugin-ai-flows 0.90.0 → 0.91.1
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 +131 -0
- package/THIRD-PARTY-NOTICES.md +91 -1268
- package/dist/cadenceTick.js +34 -34
- package/dist/define.js +28 -28
- package/dist/engine.js +158 -158
- package/dist/index.js +5 -5
- package/dist/mediaAdapter.js +22 -22
- package/dist/procedures.js +107 -107
- package/package.json +12 -12
package/dist/engine.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
1
|
+
import { aiFlowRunsTable as e, aiFlowsTable as t } from "./table.js";
|
|
2
|
+
import { CostSource as n, HumanResponse as r, MediaArtifacts as i, RunStep as a, StepUsage as o, normalizeFlow as s } from "./ir.js";
|
|
3
|
+
import { interpolate as c, unresolvedRefs as l } from "./interpolate.js";
|
|
4
|
+
import { describeCondition as u, evaluateCondition as d } from "./condition.js";
|
|
5
|
+
import { flowSegments as f } from "./segments.js";
|
|
6
|
+
import { getRegisteredFlow as p } from "./registry.js";
|
|
7
|
+
import { humanResponseSignalName as m } from "./workflow.js";
|
|
8
|
+
import { resolveHumanReviewTimeoutMs as h, resolveMaxChainDepth as g } from "./defaults.js";
|
|
9
9
|
import { decodeTextParams as _ } from "./textParams.js";
|
|
10
10
|
import { ResolvedMediaInputs as v, resolveMediaInputRefs as y, resolveMediaInputs as b } from "./mediaInputs.js";
|
|
11
11
|
import { decodeMediaResult as x } from "./mediaResult.js";
|
|
@@ -20,11 +20,11 @@ var I = (e) => e, ce = (e) => e._tag === "FlowAgentUnavailable" ? e.publicMessag
|
|
|
20
20
|
value: k.optional(k.Unknown),
|
|
21
21
|
text: k.optional(k.String),
|
|
22
22
|
url: k.optional(k.String),
|
|
23
|
-
artifacts: k.optional(
|
|
23
|
+
artifacts: k.optional(i),
|
|
24
24
|
costMicroUsd: k.optional(k.Number),
|
|
25
|
-
costSource: k.optional(
|
|
25
|
+
costSource: k.optional(n),
|
|
26
26
|
requestId: k.optional(k.String),
|
|
27
|
-
usage: k.optional(
|
|
27
|
+
usage: k.optional(o),
|
|
28
28
|
error: k.optional(k.String)
|
|
29
29
|
}), R = (e) => x(e).pipe(E.map((e) => {
|
|
30
30
|
let t = e.artifacts.find((e) => e.role === "primary");
|
|
@@ -73,46 +73,46 @@ var I = (e) => e, ce = (e) => e._tag === "FlowAgentUnavailable" ? e.publicMessag
|
|
|
73
73
|
if (t.length === 0) return "unknown";
|
|
74
74
|
let n = t.map((e) => e.costSource ?? "unpriced");
|
|
75
75
|
return n.every((e) => e === "gateway") ? "actual" : n.some((e) => e === "unpriced") ? "incomplete" : "estimated";
|
|
76
|
-
}, K = (
|
|
77
|
-
let a = await
|
|
78
|
-
a[0] !== void 0 && o == null && await
|
|
79
|
-
}).pipe(E.catchCause(() => E.void)), de = (
|
|
80
|
-
let r = (await
|
|
76
|
+
}, K = (t, n, r) => E.promise(() => t.store.update(e.tableName, n, r).then(() => void 0)).pipe(E.catchCause(() => E.void)), q = (t, n, r, i) => E.promise(async () => {
|
|
77
|
+
let a = await t.store.query(M(e).where(j("id", n)).descriptor), o = a[0]?.[i];
|
|
78
|
+
a[0] !== void 0 && o == null && await t.store.update(e.tableName, n, r);
|
|
79
|
+
}).pipe(E.catchCause(() => E.void)), de = (t, n) => E.promise(async () => {
|
|
80
|
+
let r = (await t.store.query(M(e).where(j("id", n)).descriptor))[0]?.status;
|
|
81
81
|
return r === "cancelling" || r === "cancelled";
|
|
82
82
|
}).pipe(E.catchCause(() => E.succeed(!1))), fe = E.gen(function* () {
|
|
83
83
|
let e = yield* ee.WorkflowInstance;
|
|
84
84
|
return e.interrupted = !0, yield* E.interrupt;
|
|
85
|
-
}), pe = (
|
|
85
|
+
}), pe = (t, n) => E.promise(() => t.store.updateMany(e.tableName, {
|
|
86
86
|
status: "cancelled",
|
|
87
87
|
completedAt: B()
|
|
88
|
-
}, { where: A(j("id", n), j("status", "cancelling")) }).then(() => void 0)).pipe(E.catchCause(() => E.void)), J = (
|
|
89
|
-
let
|
|
90
|
-
if (
|
|
91
|
-
let
|
|
92
|
-
return
|
|
93
|
-
name:
|
|
94
|
-
mode:
|
|
95
|
-
steps:
|
|
96
|
-
maxSteps:
|
|
97
|
-
brief:
|
|
98
|
-
orchestratorModel:
|
|
99
|
-
orchestratorInstructions:
|
|
100
|
-
chain:
|
|
101
|
-
cadence:
|
|
102
|
-
humanTimeoutMs:
|
|
88
|
+
}, { where: A(j("id", n), j("status", "cancelling")) }).then(() => void 0)).pipe(E.catchCause(() => E.void)), J = (e, n) => E.gen(function* () {
|
|
89
|
+
let r = p(n);
|
|
90
|
+
if (r) return r;
|
|
91
|
+
let i = (yield* E.promise(() => e.store.query(M(t).where(j("id", n)).descriptor)))[0];
|
|
92
|
+
return i ? s({
|
|
93
|
+
name: i.name ?? n,
|
|
94
|
+
mode: i.mode,
|
|
95
|
+
steps: i.steps ?? [],
|
|
96
|
+
maxSteps: i.maxSteps ?? null,
|
|
97
|
+
brief: i.inputSchema ?? [],
|
|
98
|
+
orchestratorModel: i.orchestratorModel ?? null,
|
|
99
|
+
orchestratorInstructions: i.orchestratorInstructions ?? null,
|
|
100
|
+
chain: i.chainTo ?? null,
|
|
101
|
+
cadence: i.cadence ?? null,
|
|
102
|
+
humanTimeoutMs: i.humanTimeoutMs ?? null
|
|
103
103
|
}) : yield* E.fail(new w({
|
|
104
|
-
flowRef:
|
|
105
|
-
message: `no flow registered or stored for "${
|
|
104
|
+
flowRef: n,
|
|
105
|
+
message: `no flow registered or stored for "${n}"`
|
|
106
106
|
}));
|
|
107
107
|
}), Y = (e, t, n, r, i, a) => E.gen(function* () {
|
|
108
|
-
let e =
|
|
108
|
+
let e = c(n.prompt ?? "", r), o = n.type === "agent" || n.type === "structured" || n.type === "generate" && (n.modality ?? "text") === "text", s = yield* _(o ? n.params : void 0).pipe(E.result);
|
|
109
109
|
if (O.isFailure(s)) return { error: `step "${n.id}": ${s.failure}` };
|
|
110
110
|
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` };
|
|
111
|
-
let
|
|
112
|
-
if (
|
|
111
|
+
let u = l(n.prompt ?? "", r);
|
|
112
|
+
if (u.length > 0) return { error: new C({
|
|
113
113
|
stepId: n.id,
|
|
114
|
-
unresolvedRef:
|
|
115
|
-
message: `step "${n.id}" references unresolved {{${
|
|
114
|
+
unresolvedRef: u[0],
|
|
115
|
+
message: `step "${n.id}" references unresolved {{${u[0]}}}`
|
|
116
116
|
}).message };
|
|
117
117
|
switch (n.type) {
|
|
118
118
|
case "note": return {
|
|
@@ -224,30 +224,30 @@ var I = (e) => e, ce = (e) => e._tag === "FlowAgentUnavailable" ? e.publicMessag
|
|
|
224
224
|
}).message };
|
|
225
225
|
default: return { error: `unknown step type: ${String(n.type)}` };
|
|
226
226
|
}
|
|
227
|
-
}), me = (e, t, n,
|
|
228
|
-
let
|
|
227
|
+
}), me = (e, t, n, i, a, o) => E.gen(function* () {
|
|
228
|
+
let s = Object.assign(Object.create(null), a), l = Object.create(null), p = i.steps.map((e, t) => ({
|
|
229
229
|
id: t,
|
|
230
230
|
title: e.title ?? `Step ${t + 1}`,
|
|
231
231
|
type: e.type,
|
|
232
232
|
status: "pending",
|
|
233
233
|
...e.description ? { description: e.description } : {}
|
|
234
|
-
})),
|
|
234
|
+
})), g = 0;
|
|
235
235
|
yield* q(e, n, {
|
|
236
236
|
status: "running",
|
|
237
237
|
steps: p,
|
|
238
|
-
totalSteps:
|
|
238
|
+
totalSteps: i.steps.length,
|
|
239
239
|
currentStep: 0,
|
|
240
240
|
startedAt: B()
|
|
241
241
|
}, "startedAt");
|
|
242
|
-
for (let
|
|
242
|
+
for (let a of f(i.steps)) {
|
|
243
243
|
if (yield* de(e, n)) return yield* pe(e, n), yield* fe;
|
|
244
|
-
if (
|
|
244
|
+
if (a.steps.length > 1) {
|
|
245
245
|
let r = [];
|
|
246
|
-
for (let { index: e, step: t } of
|
|
246
|
+
for (let { index: e, step: t } of a.steps) t.when !== void 0 && !d(t.when, s) ? p[e] = {
|
|
247
247
|
...p[e],
|
|
248
248
|
status: "skipped",
|
|
249
249
|
completedAt: B(),
|
|
250
|
-
skipReason:
|
|
250
|
+
skipReason: u(t.when)
|
|
251
251
|
} : (r.push({
|
|
252
252
|
index: e,
|
|
253
253
|
step: t
|
|
@@ -258,29 +258,29 @@ var I = (e) => e, ce = (e) => e._tag === "FlowAgentUnavailable" ? e.publicMessag
|
|
|
258
258
|
});
|
|
259
259
|
yield* K(e, n, {
|
|
260
260
|
steps: p,
|
|
261
|
-
currentStep:
|
|
261
|
+
currentStep: a.steps[0].index
|
|
262
262
|
});
|
|
263
263
|
let i = yield* E.all(r.map(({ index: r, step: i }) => N({
|
|
264
264
|
name: `flow-${r}-${i.id}`,
|
|
265
265
|
input: { index: r },
|
|
266
266
|
success: L,
|
|
267
|
-
execute: Y(e, t, i,
|
|
267
|
+
execute: Y(e, t, i, s, {
|
|
268
268
|
runId: n,
|
|
269
|
-
tenantId:
|
|
270
|
-
ownerId:
|
|
271
|
-
},
|
|
269
|
+
tenantId: o.tenantId,
|
|
270
|
+
ownerId: o.ownerId
|
|
271
|
+
}, l)
|
|
272
272
|
}).pipe(E.map((e) => ({
|
|
273
273
|
index: r,
|
|
274
274
|
step: i,
|
|
275
275
|
result: e
|
|
276
|
-
})))), { concurrency: "unbounded" }),
|
|
277
|
-
for (let { index: e, step: t, result: n } of i) n.error ? (
|
|
276
|
+
})))), { concurrency: "unbounded" }), c = i.find((e) => e.result.error);
|
|
277
|
+
for (let { index: e, step: t, result: n } of i) n.error ? (g += n.costMicroUsd ?? 0, p[e] = {
|
|
278
278
|
...p[e],
|
|
279
279
|
status: "failed",
|
|
280
280
|
completedAt: B(),
|
|
281
281
|
errorMessage: n.error,
|
|
282
282
|
...z(n)
|
|
283
|
-
}) : (t.outputKey && n.value !== void 0 && (
|
|
283
|
+
}) : (t.outputKey && n.value !== void 0 && (s[t.outputKey] = n.value), t.outputKey && n.artifacts !== void 0 && (l[t.outputKey] = n.artifacts), g += n.costMicroUsd ?? 0, p[e] = {
|
|
284
284
|
...p[e],
|
|
285
285
|
status: "succeeded",
|
|
286
286
|
completedAt: B(),
|
|
@@ -289,12 +289,12 @@ var I = (e) => e, ce = (e) => e._tag === "FlowAgentUnavailable" ? e.publicMessag
|
|
|
289
289
|
...n.artifacts === void 0 ? {} : { artifacts: n.artifacts },
|
|
290
290
|
...z(n)
|
|
291
291
|
});
|
|
292
|
-
if (
|
|
292
|
+
if (c !== void 0) return yield* K(e, n, {
|
|
293
293
|
steps: p,
|
|
294
294
|
status: "failed",
|
|
295
|
-
errorMessage:
|
|
295
|
+
errorMessage: c.result.error,
|
|
296
296
|
completedAt: B(),
|
|
297
|
-
costMicroUsd:
|
|
297
|
+
costMicroUsd: g,
|
|
298
298
|
costCompleteness: G(p)
|
|
299
299
|
}), {
|
|
300
300
|
runId: n,
|
|
@@ -302,55 +302,55 @@ var I = (e) => e, ce = (e) => e._tag === "FlowAgentUnavailable" ? e.publicMessag
|
|
|
302
302
|
};
|
|
303
303
|
yield* K(e, n, {
|
|
304
304
|
steps: p,
|
|
305
|
-
currentStep:
|
|
306
|
-
costMicroUsd:
|
|
305
|
+
currentStep: a.steps[a.steps.length - 1].index + 1,
|
|
306
|
+
costMicroUsd: g,
|
|
307
307
|
costCompleteness: G(p)
|
|
308
308
|
});
|
|
309
309
|
continue;
|
|
310
310
|
}
|
|
311
|
-
let { index:
|
|
312
|
-
if (_.when !== void 0 && !
|
|
313
|
-
p[
|
|
314
|
-
...p[
|
|
311
|
+
let { index: f, step: _ } = a.steps[0];
|
|
312
|
+
if (_.when !== void 0 && !d(_.when, s)) {
|
|
313
|
+
p[f] = {
|
|
314
|
+
...p[f],
|
|
315
315
|
status: "skipped",
|
|
316
316
|
completedAt: B(),
|
|
317
|
-
skipReason:
|
|
317
|
+
skipReason: u(_.when)
|
|
318
318
|
}, yield* K(e, n, {
|
|
319
319
|
steps: p,
|
|
320
|
-
currentStep:
|
|
320
|
+
currentStep: f + 1
|
|
321
321
|
});
|
|
322
322
|
continue;
|
|
323
323
|
}
|
|
324
324
|
if (_.type === "human") {
|
|
325
|
-
let
|
|
325
|
+
let a = {
|
|
326
326
|
mode: _.reviewMode ?? "approve",
|
|
327
327
|
..._.options ? { options: _.options } : {},
|
|
328
|
-
prompt:
|
|
328
|
+
prompt: c(_.prompt ?? "", s)
|
|
329
329
|
};
|
|
330
|
-
p[
|
|
331
|
-
...p[
|
|
330
|
+
p[f] = {
|
|
331
|
+
...p[f],
|
|
332
332
|
status: "waiting",
|
|
333
333
|
startedAt: B(),
|
|
334
|
-
review:
|
|
334
|
+
review: a
|
|
335
335
|
}, yield* K(e, n, {
|
|
336
336
|
steps: p,
|
|
337
337
|
status: "waiting",
|
|
338
|
-
currentStep:
|
|
338
|
+
currentStep: f
|
|
339
339
|
}), t.onEvent && (yield* I(t.onEvent({
|
|
340
340
|
kind: "review-needed",
|
|
341
341
|
runId: n,
|
|
342
|
-
flowName:
|
|
343
|
-
ownerId:
|
|
344
|
-
source:
|
|
342
|
+
flowName: i.name,
|
|
343
|
+
ownerId: o.ownerId,
|
|
344
|
+
source: o.source
|
|
345
345
|
})).pipe(E.catchCause(() => E.void)));
|
|
346
|
-
let
|
|
346
|
+
let l = h({
|
|
347
347
|
step: _,
|
|
348
|
-
flow:
|
|
348
|
+
flow: i,
|
|
349
349
|
deps: t
|
|
350
|
-
}),
|
|
351
|
-
name:
|
|
352
|
-
schema:
|
|
353
|
-
timeoutMs:
|
|
350
|
+
}), u = yield* ne(e, {
|
|
351
|
+
name: m(f),
|
|
352
|
+
schema: r,
|
|
353
|
+
timeoutMs: l
|
|
354
354
|
}).pipe(E.map((e) => ({
|
|
355
355
|
ok: !0,
|
|
356
356
|
a: e
|
|
@@ -358,10 +358,10 @@ var I = (e) => e, ce = (e) => e._tag === "FlowAgentUnavailable" ? e.publicMessag
|
|
|
358
358
|
ok: !1,
|
|
359
359
|
cause: e
|
|
360
360
|
})));
|
|
361
|
-
if (!
|
|
362
|
-
let t = Number.isFinite(
|
|
363
|
-
return p[
|
|
364
|
-
...p[
|
|
361
|
+
if (!u.ok) {
|
|
362
|
+
let t = Number.isFinite(l) ? `human review timed out after ${l}ms` : "human review failed";
|
|
363
|
+
return p[f] = {
|
|
364
|
+
...p[f],
|
|
365
365
|
status: "failed",
|
|
366
366
|
completedAt: B(),
|
|
367
367
|
errorMessage: t
|
|
@@ -370,63 +370,63 @@ var I = (e) => e, ce = (e) => e._tag === "FlowAgentUnavailable" ? e.publicMessag
|
|
|
370
370
|
status: "failed",
|
|
371
371
|
errorMessage: t,
|
|
372
372
|
completedAt: B(),
|
|
373
|
-
costMicroUsd:
|
|
373
|
+
costMicroUsd: g,
|
|
374
374
|
costCompleteness: G(p)
|
|
375
375
|
}), {
|
|
376
376
|
runId: n,
|
|
377
377
|
status: "failed"
|
|
378
378
|
};
|
|
379
379
|
}
|
|
380
|
-
let
|
|
381
|
-
if (
|
|
382
|
-
...p[
|
|
380
|
+
let d = u.a;
|
|
381
|
+
if (d.decision === "reject") return p[f] = {
|
|
382
|
+
...p[f],
|
|
383
383
|
status: "failed",
|
|
384
384
|
completedAt: B(),
|
|
385
385
|
errorMessage: "rejected by reviewer"
|
|
386
386
|
}, yield* K(e, n, {
|
|
387
387
|
steps: p,
|
|
388
388
|
status: "cancelled",
|
|
389
|
-
humanResponse:
|
|
389
|
+
humanResponse: d,
|
|
390
390
|
completedAt: B(),
|
|
391
|
-
costMicroUsd:
|
|
391
|
+
costMicroUsd: g,
|
|
392
392
|
costCompleteness: G(p)
|
|
393
393
|
}), {
|
|
394
394
|
runId: n,
|
|
395
395
|
status: "cancelled"
|
|
396
396
|
};
|
|
397
|
-
_.outputKey && (
|
|
398
|
-
...p[
|
|
397
|
+
_.outputKey && (s[_.outputKey] = d.value ?? d.text ?? d.decision ?? !0), p[f] = {
|
|
398
|
+
...p[f],
|
|
399
399
|
status: "succeeded",
|
|
400
400
|
completedAt: B(),
|
|
401
|
-
output: { text: String(
|
|
401
|
+
output: { text: String(d.text ?? d.value ?? d.decision ?? "approved") }
|
|
402
402
|
}, yield* K(e, n, {
|
|
403
403
|
steps: p,
|
|
404
404
|
status: "running",
|
|
405
|
-
humanResponse:
|
|
406
|
-
currentStep:
|
|
405
|
+
humanResponse: d,
|
|
406
|
+
currentStep: f + 1
|
|
407
407
|
});
|
|
408
408
|
continue;
|
|
409
409
|
}
|
|
410
|
-
p[
|
|
411
|
-
...p[
|
|
410
|
+
p[f] = {
|
|
411
|
+
...p[f],
|
|
412
412
|
status: "running",
|
|
413
413
|
startedAt: B()
|
|
414
414
|
}, yield* K(e, n, {
|
|
415
415
|
steps: p,
|
|
416
|
-
currentStep:
|
|
416
|
+
currentStep: f
|
|
417
417
|
});
|
|
418
418
|
let v = yield* N({
|
|
419
|
-
name: `flow-${
|
|
420
|
-
input: { index:
|
|
419
|
+
name: `flow-${f}-${_.id}`,
|
|
420
|
+
input: { index: f },
|
|
421
421
|
success: L,
|
|
422
|
-
execute: Y(e, t, _,
|
|
422
|
+
execute: Y(e, t, _, s, {
|
|
423
423
|
runId: n,
|
|
424
|
-
tenantId:
|
|
425
|
-
ownerId:
|
|
426
|
-
},
|
|
424
|
+
tenantId: o.tenantId,
|
|
425
|
+
ownerId: o.ownerId
|
|
426
|
+
}, l)
|
|
427
427
|
});
|
|
428
|
-
if (v.error) return
|
|
429
|
-
...p[
|
|
428
|
+
if (v.error) return g += v.costMicroUsd ?? 0, p[f] = {
|
|
429
|
+
...p[f],
|
|
430
430
|
status: "failed",
|
|
431
431
|
completedAt: B(),
|
|
432
432
|
errorMessage: v.error,
|
|
@@ -436,14 +436,14 @@ var I = (e) => e, ce = (e) => e._tag === "FlowAgentUnavailable" ? e.publicMessag
|
|
|
436
436
|
status: "failed",
|
|
437
437
|
errorMessage: v.error,
|
|
438
438
|
completedAt: B(),
|
|
439
|
-
costMicroUsd:
|
|
439
|
+
costMicroUsd: g,
|
|
440
440
|
costCompleteness: G(p)
|
|
441
441
|
}), {
|
|
442
442
|
runId: n,
|
|
443
443
|
status: "failed"
|
|
444
444
|
};
|
|
445
|
-
_.outputKey && v.value !== void 0 && (
|
|
446
|
-
...p[
|
|
445
|
+
_.outputKey && v.value !== void 0 && (s[_.outputKey] = v.value), _.outputKey && v.artifacts !== void 0 && (l[_.outputKey] = v.artifacts), g += v.costMicroUsd ?? 0, p[f] = {
|
|
446
|
+
...p[f],
|
|
447
447
|
status: "succeeded",
|
|
448
448
|
completedAt: B(),
|
|
449
449
|
...v.text ? { output: { text: v.text } } : {},
|
|
@@ -452,72 +452,72 @@ var I = (e) => e, ce = (e) => e._tag === "FlowAgentUnavailable" ? e.publicMessag
|
|
|
452
452
|
...z(v)
|
|
453
453
|
}, yield* K(e, n, {
|
|
454
454
|
steps: p,
|
|
455
|
-
currentStep:
|
|
456
|
-
costMicroUsd:
|
|
455
|
+
currentStep: f + 1,
|
|
456
|
+
costMicroUsd: g,
|
|
457
457
|
costCompleteness: G(p)
|
|
458
458
|
});
|
|
459
459
|
}
|
|
460
460
|
let _ = Object.create(null);
|
|
461
|
-
for (let e of
|
|
461
|
+
for (let e of i.steps) e.outputKey && s[e.outputKey] !== void 0 && (_[e.outputKey] = s[e.outputKey]);
|
|
462
462
|
return yield* K(e, n, {
|
|
463
463
|
status: "succeeded",
|
|
464
464
|
output: _,
|
|
465
465
|
completedAt: B(),
|
|
466
|
-
costMicroUsd:
|
|
466
|
+
costMicroUsd: g
|
|
467
467
|
}), {
|
|
468
468
|
runId: n,
|
|
469
469
|
status: "succeeded",
|
|
470
470
|
output: _
|
|
471
471
|
};
|
|
472
|
-
}), he = (
|
|
473
|
-
let
|
|
474
|
-
if (!
|
|
475
|
-
let
|
|
476
|
-
if (
|
|
477
|
-
if (
|
|
478
|
-
yield* K(
|
|
472
|
+
}), he = (t, n, r, i, a, o, s) => E.gen(function* () {
|
|
473
|
+
let c = r.chain;
|
|
474
|
+
if (!c) return;
|
|
475
|
+
let l = [...o.chainPath ?? [], o.flowRef];
|
|
476
|
+
if (c.flowRef === r.name || c.flowRef === o.flowRef) return;
|
|
477
|
+
if (l.includes(c.flowRef)) {
|
|
478
|
+
yield* K(t, n, { chainRefusal: `chain to "${c.flowRef}" refused — it is already in this run's chain (${l.join(" → ")}), which would loop` });
|
|
479
479
|
return;
|
|
480
480
|
}
|
|
481
|
-
let
|
|
482
|
-
if (
|
|
483
|
-
yield* K(
|
|
481
|
+
let u = g(s);
|
|
482
|
+
if (l.length >= u) {
|
|
483
|
+
yield* K(t, n, { chainRefusal: `chain to "${c.flowRef}" refused — depth ${l.length} reached the limit of ${u} (${l.join(" → ")})` });
|
|
484
484
|
return;
|
|
485
485
|
}
|
|
486
|
-
let
|
|
486
|
+
let d = {
|
|
487
487
|
...i,
|
|
488
|
-
...
|
|
489
|
-
},
|
|
490
|
-
for (let e of
|
|
491
|
-
if (
|
|
492
|
-
yield* K(
|
|
493
|
-
flowRef:
|
|
494
|
-
input:
|
|
488
|
+
...a
|
|
489
|
+
}, f = {};
|
|
490
|
+
for (let e of c.mappings) e.sourceKey in d && (f[e.targetKey] = d[e.sourceKey]);
|
|
491
|
+
if (c.requireConfirmation) {
|
|
492
|
+
yield* K(t, n, { chainPending: {
|
|
493
|
+
flowRef: c.flowRef,
|
|
494
|
+
input: f,
|
|
495
495
|
status: "pending"
|
|
496
496
|
} });
|
|
497
497
|
return;
|
|
498
498
|
}
|
|
499
|
-
let
|
|
500
|
-
if (!
|
|
501
|
-
let
|
|
499
|
+
let p = t.workflows;
|
|
500
|
+
if (!p) return;
|
|
501
|
+
let m = `${n}--chain`, h = `${o.requestId}--chain`;
|
|
502
502
|
yield* E.promise(async () => {
|
|
503
503
|
try {
|
|
504
|
-
await
|
|
505
|
-
id:
|
|
506
|
-
flowRef:
|
|
507
|
-
flowName:
|
|
504
|
+
await t.store.insert(e.tableName, {
|
|
505
|
+
id: m,
|
|
506
|
+
flowRef: c.flowRef,
|
|
507
|
+
flowName: c.flowRef,
|
|
508
508
|
status: "pending",
|
|
509
|
-
source:
|
|
510
|
-
requestId:
|
|
511
|
-
input:
|
|
509
|
+
source: o.source,
|
|
510
|
+
requestId: h,
|
|
511
|
+
input: f
|
|
512
512
|
});
|
|
513
513
|
} catch {}
|
|
514
|
-
await
|
|
515
|
-
runId:
|
|
516
|
-
flowRef:
|
|
517
|
-
input:
|
|
518
|
-
source:
|
|
519
|
-
requestId:
|
|
520
|
-
chainPath:
|
|
514
|
+
await p.child("flow.run", {
|
|
515
|
+
runId: m,
|
|
516
|
+
flowRef: c.flowRef,
|
|
517
|
+
input: f,
|
|
518
|
+
source: o.source,
|
|
519
|
+
requestId: h,
|
|
520
|
+
chainPath: l
|
|
521
521
|
});
|
|
522
522
|
}).pipe(E.catchCause(() => E.void));
|
|
523
523
|
}), ge = (e) => e.type === "agent" ? e.agentRef ? `agent step, agent "${e.agentRef}"` : "agent step" : e.type === "generate" ? `${e.modality ?? "media"} generation step` : `${e.type} step`, _e = (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}` : ""} (${ge(e)})`).join("\n"), ve = "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", X = k.optional(k.String.annotate({ description: "One short sentence: what this call is for. Shown to the user in the run timeline." })), Z = (e) => e === void 0 || e.trim() === "" ? {} : { description: e.trim().slice(0, 200) }, Q = k.Struct({ json: k.String.annotate({ description: "The requested JSON object, serialized as a JSON string." }) }), ye = (e) => {
|
|
@@ -542,9 +542,9 @@ var I = (e) => e, ce = (e) => e._tag === "FlowAgentUnavailable" ? e.publicMessag
|
|
|
542
542
|
].filter(Boolean).join("\n\n"), Se = k.Struct({
|
|
543
543
|
object: k.Record(k.String, k.Unknown),
|
|
544
544
|
planCostMicroUsd: k.Number,
|
|
545
|
-
planCostSource: k.optional(
|
|
545
|
+
planCostSource: k.optional(n),
|
|
546
546
|
toolCostMicroUsd: k.Number,
|
|
547
|
-
steps: k.Array(
|
|
547
|
+
steps: k.Array(a),
|
|
548
548
|
error: k.optional(k.String)
|
|
549
549
|
}), Ce = (e, t, n, r, i, a, o, s) => E.gen(function* () {
|
|
550
550
|
yield* q(e, n, {
|
|
@@ -846,13 +846,13 @@ var I = (e) => e, ce = (e) => e._tag === "FlowAgentUnavailable" ? e.publicMessag
|
|
|
846
846
|
status: "succeeded",
|
|
847
847
|
output: c.object
|
|
848
848
|
});
|
|
849
|
-
}), we = (
|
|
850
|
-
let { runId: i, flowRef: a, input: o } = r, s = yield* E.tryPromise(() =>
|
|
849
|
+
}), we = (t, n = {}) => (r, i) => E.gen(function* () {
|
|
850
|
+
let { runId: i, flowRef: a, input: o } = r, s = yield* E.tryPromise(() => t.store.query(M(e).where(j("id", i)).descriptor)).pipe(E.flatMap(k.decodeUnknownEffect(k.Tuple([k.Struct({
|
|
851
851
|
id: k.Literal(i),
|
|
852
852
|
tenantId: k.NullOr(k.NonEmptyString),
|
|
853
853
|
ownerId: k.optional(k.NullOr(k.String))
|
|
854
854
|
})]))), E.result);
|
|
855
|
-
if (O.isFailure(s)) return yield* K(
|
|
855
|
+
if (O.isFailure(s)) return yield* K(t, i, {
|
|
856
856
|
status: "failed",
|
|
857
857
|
errorMessage: "flow run context unavailable: expected one matching run row with an explicit tenantId (string or null)",
|
|
858
858
|
completedAt: B()
|
|
@@ -867,7 +867,7 @@ var I = (e) => e, ce = (e) => e._tag === "FlowAgentUnavailable" ? e.publicMessag
|
|
|
867
867
|
ir: k.Unknown,
|
|
868
868
|
error: k.optional(k.String)
|
|
869
869
|
}),
|
|
870
|
-
execute: J(
|
|
870
|
+
execute: J(t, a).pipe(E.flatMap((e) => {
|
|
871
871
|
for (let t of e.steps) {
|
|
872
872
|
if (!(t.type === "agent" || t.type === "structured" || t.type === "generate" && (t.modality ?? "text") === "text") || t.params === void 0) continue;
|
|
873
873
|
let e = E.runSyncExit(_(t.params));
|
|
@@ -882,7 +882,7 @@ var I = (e) => e, ce = (e) => e._tag === "FlowAgentUnavailable" ? e.publicMessag
|
|
|
882
882
|
error: e.message
|
|
883
883
|
})))
|
|
884
884
|
});
|
|
885
|
-
if (u.error || !u.ir) return yield* K(
|
|
885
|
+
if (u.error || !u.ir) return yield* K(t, i, {
|
|
886
886
|
status: "failed",
|
|
887
887
|
errorMessage: u.error ?? "flow not found",
|
|
888
888
|
completedAt: B()
|
|
@@ -890,12 +890,12 @@ var I = (e) => e, ce = (e) => e._tag === "FlowAgentUnavailable" ? e.publicMessag
|
|
|
890
890
|
runId: i,
|
|
891
891
|
status: "failed"
|
|
892
892
|
};
|
|
893
|
-
let d = u.ir, f = d.mode === "agentic" ? yield* Ce(
|
|
893
|
+
let d = u.ir, f = d.mode === "agentic" ? yield* Ce(t, n, i, d, o, l, c, a) : yield* me(t, n, i, d, o, {
|
|
894
894
|
ownerId: l,
|
|
895
895
|
tenantId: c,
|
|
896
896
|
source: r.source
|
|
897
897
|
});
|
|
898
|
-
return f.status === "succeeded" && d.chain && (yield* he(
|
|
898
|
+
return f.status === "succeeded" && d.chain && (yield* he(t, i, d, o, f.output ?? {}, r, n)), n.onEvent && (f.status === "succeeded" || f.status === "failed") && (yield* I(n.onEvent({
|
|
899
899
|
kind: f.status,
|
|
900
900
|
runId: i,
|
|
901
901
|
flowName: d.name,
|
package/dist/index.js
CHANGED
|
@@ -5,10 +5,10 @@ import { admittedStartHandle as u, reconcileFlowStarts as d } from "./startRecon
|
|
|
5
5
|
import { FLOW_RUNS_TTL_ENV as f, FLOW_RUNS_TTL_HOURS_DEFAULT as p, HUMAN_REVIEW_TIMEOUT_ENV as m, HUMAN_REVIEW_TIMEOUT_HOURS_DEFAULT as h, MAX_CHAIN_DEPTH_DEFAULT as ee, MAX_CHAIN_DEPTH_ENV as te, getAiFlowsDefaults as ne, msFromHoursEnv as re, resetAiFlowsDefaults as ie, resolveHumanReviewTimeoutMs as g, resolveMaxChainDepth as _, setAiFlowsDefaults as v } from "./defaults.js";
|
|
6
6
|
import { ConditionOp as y, StepCondition as b, describeCondition as x, evaluateCondition as S, isTruthy as C } from "./condition.js";
|
|
7
7
|
import { BriefField as w, ChainPending as T, CostCompleteness as E, CostSource as D, FlowCadence as O, FlowCancelReceipt as k, FlowChain as A, FlowMode as j, FlowReviewInput as M, FlowReviewReceipt as N, FlowStartReceipt as P, FlowStatus as F, FlowStep as I, HumanResponse as L, Json as R, MAX_STEPS_DEFAULT as z, MAX_STEPS_MAX as B, MAX_STEPS_MIN as V, MediaArtifact as H, MediaArtifacts as U, MediaInputSlot as W, MediaInputs as G, MediaReceipt as K, Modality as q, ReviewMode as J, ReviewOption as Y, RunReview as ae, RunSource as oe, RunStatus as se, RunStep as ce, RunStepStatus as le, StepType as ue, StepUsage as de, Visibility as fe, clampMaxSteps as pe, normalizeFlow as me, sanitizeOutputKey as he } from "./ir.js";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
8
|
+
import { buildFlowRunExecute as ge, resolveIr as _e } from "./engine.js";
|
|
9
|
+
import { collectRefs as ve, interpolate as ye, unresolvedRefs as be } from "./interpolate.js";
|
|
10
|
+
import { defineFlow as xe, flowStep as Se, validateFlow as Ce } from "./define.js";
|
|
11
|
+
import { flowSegments as we, nonContiguousGroups as Te } from "./segments.js";
|
|
12
12
|
import { cadenceMatches as Ee, nextRuns as De } from "./cadence.js";
|
|
13
13
|
import { cronRequestId as Oe, runCadenceTick as ke } from "./cadenceTick.js";
|
|
14
14
|
import { makeMediaGenerator as Ae } from "./mediaAdapter.js";
|
|
@@ -160,4 +160,4 @@ var $ = "aiFlows", Ke = (e = {}) => {
|
|
|
160
160
|
}).pipe(Z.catchCause(() => Z.void))
|
|
161
161
|
});
|
|
162
162
|
};
|
|
163
|
-
export { w as BriefField, T as ChainPending, y as ConditionOp, E as CostCompleteness, D as CostSource, f as FLOW_RUNS_TTL_ENV, p as FLOW_RUNS_TTL_HOURS_DEFAULT, s as FLOW_RUN_WORKFLOW, O as FlowCadence, k as FlowCancelReceipt, A as FlowChain, j as FlowMode, M as FlowReviewInput, N as FlowReviewReceipt, P as FlowStartReceipt, F as FlowStatus, I as FlowStep, c as HUMAN_RESPONSE_SIGNAL_PREFIX, m as HUMAN_REVIEW_TIMEOUT_ENV, h as HUMAN_REVIEW_TIMEOUT_HOURS_DEFAULT, L as HumanResponse, R as Json, ee as MAX_CHAIN_DEPTH_DEFAULT, te as MAX_CHAIN_DEPTH_ENV, z as MAX_STEPS_DEFAULT, B as MAX_STEPS_MAX, V as MAX_STEPS_MIN, H as MediaArtifact, U as MediaArtifacts, W as MediaInputSlot, G as MediaInputs, K as MediaReceipt, q as Modality, J as ReviewMode, Y as ReviewOption, ae as RunReview, oe as RunSource, se as RunStatus, ce as RunStep, le as RunStepStatus, b as StepCondition, ue as StepType, de as StepUsage, fe as Visibility, u as admittedStartHandle, i as aiFlowRunsTable, Ke as aiFlowsPlugin, a as aiFlowsTable, o as aiFlowsTables,
|
|
163
|
+
export { w as BriefField, T as ChainPending, y as ConditionOp, E as CostCompleteness, D as CostSource, f as FLOW_RUNS_TTL_ENV, p as FLOW_RUNS_TTL_HOURS_DEFAULT, s as FLOW_RUN_WORKFLOW, O as FlowCadence, k as FlowCancelReceipt, A as FlowChain, j as FlowMode, M as FlowReviewInput, N as FlowReviewReceipt, P as FlowStartReceipt, F as FlowStatus, I as FlowStep, c as HUMAN_RESPONSE_SIGNAL_PREFIX, m as HUMAN_REVIEW_TIMEOUT_ENV, h as HUMAN_REVIEW_TIMEOUT_HOURS_DEFAULT, L as HumanResponse, R as Json, ee as MAX_CHAIN_DEPTH_DEFAULT, te as MAX_CHAIN_DEPTH_ENV, z as MAX_STEPS_DEFAULT, B as MAX_STEPS_MAX, V as MAX_STEPS_MIN, H as MediaArtifact, U as MediaArtifacts, W as MediaInputSlot, G as MediaInputs, K as MediaReceipt, q as Modality, J as ReviewMode, Y as ReviewOption, ae as RunReview, oe as RunSource, se as RunStatus, ce as RunStep, le as RunStepStatus, b as StepCondition, ue as StepType, de as StepUsage, fe as Visibility, u as admittedStartHandle, i as aiFlowRunsTable, Ke as aiFlowsPlugin, a as aiFlowsTable, o as aiFlowsTables, ge as buildFlowRunExecute, Ee as cadenceMatches, je as cancelFlow, pe as clampMaxSteps, e as clearRegistry, ve as collectRefs, Me as createFlow, Oe as cronRequestId, xe as defineFlow, Ne as deleteFlow, x as describeCondition, S as evaluateCondition, we as flowSegments, Se as flowStep, ne as getAiFlowsDefaults, Pe as getFlow, t as getRegisteredFlow, l as humanResponseSignalName, ye as interpolate, C as isTruthy, Fe as launchFlow, Ie as listFlows, n as listRegisteredFlows, Ae as makeMediaGenerator, De as nextRuns, Te as nonContiguousGroups, me as normalizeFlow, d as reconcileFlowStarts, r as registerFlow, ie as resetAiFlowsDefaults, g as resolveHumanReviewTimeoutMs, _e as resolveIr, _ as resolveMaxChainDepth, Le as respondToFlow, X as retryFlow, ke as runCadenceTick, he as sanitizeOutputKey, v as setAiFlowsDefaults, be as unresolvedRefs, Re as updateFlow, Ce as validateFlow, ze as waitingStepIndex };
|