@voltro/plugin-ai-flows 0.90.0 → 0.91.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/dist/engine.js CHANGED
@@ -1,11 +1,11 @@
1
- import { getRegisteredFlow as e } from "./registry.js";
2
- import { aiFlowRunsTable as t, aiFlowsTable as n } from "./table.js";
3
- import { humanResponseSignalName as r } from "./workflow.js";
4
- import { resolveHumanReviewTimeoutMs as i, resolveMaxChainDepth as a } from "./defaults.js";
5
- import { describeCondition as o, evaluateCondition as s } from "./condition.js";
6
- import { CostSource as c, HumanResponse as l, MediaArtifacts as u, RunStep as d, StepUsage as f, normalizeFlow as p } from "./ir.js";
7
- import { interpolate as m, unresolvedRefs as h } from "./interpolate.js";
8
- import { flowSegments as g } from "./segments.js";
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(u),
23
+ artifacts: k.optional(i),
24
24
  costMicroUsd: k.optional(k.Number),
25
- costSource: k.optional(c),
25
+ costSource: k.optional(n),
26
26
  requestId: k.optional(k.String),
27
- usage: k.optional(f),
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 = (e, n, r) => E.promise(() => e.store.update(t.tableName, n, r).then(() => void 0)).pipe(E.catchCause(() => E.void)), q = (e, n, r, i) => E.promise(async () => {
77
- let a = await e.store.query(M(t).where(j("id", n)).descriptor), o = a[0]?.[i];
78
- a[0] !== void 0 && o == null && await e.store.update(t.tableName, n, r);
79
- }).pipe(E.catchCause(() => E.void)), de = (e, n) => E.promise(async () => {
80
- let r = (await e.store.query(M(t).where(j("id", n)).descriptor))[0]?.status;
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 = (e, n) => E.promise(() => e.store.updateMany(t.tableName, {
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 = (t, r) => E.gen(function* () {
89
- let i = e(r);
90
- if (i) return i;
91
- let a = (yield* E.promise(() => t.store.query(M(n).where(j("id", r)).descriptor)))[0];
92
- return a ? p({
93
- name: a.name ?? r,
94
- mode: a.mode,
95
- steps: a.steps ?? [],
96
- maxSteps: a.maxSteps ?? null,
97
- brief: a.inputSchema ?? [],
98
- orchestratorModel: a.orchestratorModel ?? null,
99
- orchestratorInstructions: a.orchestratorInstructions ?? null,
100
- chain: a.chainTo ?? null,
101
- cadence: a.cadence ?? null,
102
- humanTimeoutMs: a.humanTimeoutMs ?? null
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: r,
105
- message: `no flow registered or stored for "${r}"`
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 = m(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);
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 c = h(n.prompt ?? "", r);
112
- if (c.length > 0) return { error: new C({
111
+ let u = l(n.prompt ?? "", r);
112
+ if (u.length > 0) return { error: new C({
113
113
  stepId: n.id,
114
- unresolvedRef: c[0],
115
- message: `step "${n.id}" references unresolved {{${c[0]}}}`
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, a, c, u) => E.gen(function* () {
228
- let d = Object.assign(Object.create(null), c), f = Object.create(null), p = a.steps.map((e, t) => ({
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
- })), h = 0;
234
+ })), g = 0;
235
235
  yield* q(e, n, {
236
236
  status: "running",
237
237
  steps: p,
238
- totalSteps: a.steps.length,
238
+ totalSteps: i.steps.length,
239
239
  currentStep: 0,
240
240
  startedAt: B()
241
241
  }, "startedAt");
242
- for (let c of g(a.steps)) {
242
+ for (let a of f(i.steps)) {
243
243
  if (yield* de(e, n)) return yield* pe(e, n), yield* fe;
244
- if (c.steps.length > 1) {
244
+ if (a.steps.length > 1) {
245
245
  let r = [];
246
- for (let { index: e, step: t } of c.steps) t.when !== void 0 && !s(t.when, d) ? p[e] = {
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: o(t.when)
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: c.steps[0].index
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, d, {
267
+ execute: Y(e, t, i, s, {
268
268
  runId: n,
269
- tenantId: u.tenantId,
270
- ownerId: u.ownerId
271
- }, f)
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" }), a = i.find((e) => e.result.error);
277
- for (let { index: e, step: t, result: n } of i) n.error ? (h += n.costMicroUsd ?? 0, p[e] = {
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 && (d[t.outputKey] = n.value), t.outputKey && n.artifacts !== void 0 && (f[t.outputKey] = n.artifacts), h += n.costMicroUsd ?? 0, p[e] = {
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 (a !== void 0) return yield* K(e, n, {
292
+ if (c !== void 0) return yield* K(e, n, {
293
293
  steps: p,
294
294
  status: "failed",
295
- errorMessage: a.result.error,
295
+ errorMessage: c.result.error,
296
296
  completedAt: B(),
297
- costMicroUsd: h,
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: c.steps[c.steps.length - 1].index + 1,
306
- costMicroUsd: h,
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: g, step: _ } = c.steps[0];
312
- if (_.when !== void 0 && !s(_.when, d)) {
313
- p[g] = {
314
- ...p[g],
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: o(_.when)
317
+ skipReason: u(_.when)
318
318
  }, yield* K(e, n, {
319
319
  steps: p,
320
- currentStep: g + 1
320
+ currentStep: f + 1
321
321
  });
322
322
  continue;
323
323
  }
324
324
  if (_.type === "human") {
325
- let o = {
325
+ let a = {
326
326
  mode: _.reviewMode ?? "approve",
327
327
  ..._.options ? { options: _.options } : {},
328
- prompt: m(_.prompt ?? "", d)
328
+ prompt: c(_.prompt ?? "", s)
329
329
  };
330
- p[g] = {
331
- ...p[g],
330
+ p[f] = {
331
+ ...p[f],
332
332
  status: "waiting",
333
333
  startedAt: B(),
334
- review: o
334
+ review: a
335
335
  }, yield* K(e, n, {
336
336
  steps: p,
337
337
  status: "waiting",
338
- currentStep: g
338
+ currentStep: f
339
339
  }), t.onEvent && (yield* I(t.onEvent({
340
340
  kind: "review-needed",
341
341
  runId: n,
342
- flowName: a.name,
343
- ownerId: u.ownerId,
344
- source: u.source
342
+ flowName: i.name,
343
+ ownerId: o.ownerId,
344
+ source: o.source
345
345
  })).pipe(E.catchCause(() => E.void)));
346
- let s = i({
346
+ let l = h({
347
347
  step: _,
348
- flow: a,
348
+ flow: i,
349
349
  deps: t
350
- }), c = yield* ne(e, {
351
- name: r(g),
352
- schema: l,
353
- timeoutMs: s
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 (!c.ok) {
362
- let t = Number.isFinite(s) ? `human review timed out after ${s}ms` : "human review failed";
363
- return p[g] = {
364
- ...p[g],
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: h,
373
+ costMicroUsd: g,
374
374
  costCompleteness: G(p)
375
375
  }), {
376
376
  runId: n,
377
377
  status: "failed"
378
378
  };
379
379
  }
380
- let f = c.a;
381
- if (f.decision === "reject") return p[g] = {
382
- ...p[g],
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: f,
389
+ humanResponse: d,
390
390
  completedAt: B(),
391
- costMicroUsd: h,
391
+ costMicroUsd: g,
392
392
  costCompleteness: G(p)
393
393
  }), {
394
394
  runId: n,
395
395
  status: "cancelled"
396
396
  };
397
- _.outputKey && (d[_.outputKey] = f.value ?? f.text ?? f.decision ?? !0), p[g] = {
398
- ...p[g],
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(f.text ?? f.value ?? f.decision ?? "approved") }
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: f,
406
- currentStep: g + 1
405
+ humanResponse: d,
406
+ currentStep: f + 1
407
407
  });
408
408
  continue;
409
409
  }
410
- p[g] = {
411
- ...p[g],
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: g
416
+ currentStep: f
417
417
  });
418
418
  let v = yield* N({
419
- name: `flow-${g}-${_.id}`,
420
- input: { index: g },
419
+ name: `flow-${f}-${_.id}`,
420
+ input: { index: f },
421
421
  success: L,
422
- execute: Y(e, t, _, d, {
422
+ execute: Y(e, t, _, s, {
423
423
  runId: n,
424
- tenantId: u.tenantId,
425
- ownerId: u.ownerId
426
- }, f)
424
+ tenantId: o.tenantId,
425
+ ownerId: o.ownerId
426
+ }, l)
427
427
  });
428
- if (v.error) return h += v.costMicroUsd ?? 0, p[g] = {
429
- ...p[g],
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: h,
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 && (d[_.outputKey] = v.value), _.outputKey && v.artifacts !== void 0 && (f[_.outputKey] = v.artifacts), h += v.costMicroUsd ?? 0, p[g] = {
446
- ...p[g],
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: g + 1,
456
- costMicroUsd: h,
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 a.steps) e.outputKey && d[e.outputKey] !== void 0 && (_[e.outputKey] = d[e.outputKey]);
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: h
466
+ costMicroUsd: g
467
467
  }), {
468
468
  runId: n,
469
469
  status: "succeeded",
470
470
  output: _
471
471
  };
472
- }), he = (e, n, r, i, o, s, c) => E.gen(function* () {
473
- let l = r.chain;
474
- if (!l) return;
475
- let u = [...s.chainPath ?? [], s.flowRef];
476
- if (l.flowRef === r.name || l.flowRef === s.flowRef) return;
477
- if (u.includes(l.flowRef)) {
478
- yield* K(e, n, { chainRefusal: `chain to "${l.flowRef}" refused — it is already in this run's chain (${u.join(" → ")}), which would loop` });
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 d = a(c);
482
- if (u.length >= d) {
483
- yield* K(e, n, { chainRefusal: `chain to "${l.flowRef}" refused — depth ${u.length} reached the limit of ${d} (${u.join(" → ")})` });
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 f = {
486
+ let d = {
487
487
  ...i,
488
- ...o
489
- }, p = {};
490
- for (let e of l.mappings) e.sourceKey in f && (p[e.targetKey] = f[e.sourceKey]);
491
- if (l.requireConfirmation) {
492
- yield* K(e, n, { chainPending: {
493
- flowRef: l.flowRef,
494
- input: p,
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 m = e.workflows;
500
- if (!m) return;
501
- let h = `${n}--chain`, g = `${s.requestId}--chain`;
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 e.store.insert(t.tableName, {
505
- id: h,
506
- flowRef: l.flowRef,
507
- flowName: l.flowRef,
504
+ await t.store.insert(e.tableName, {
505
+ id: m,
506
+ flowRef: c.flowRef,
507
+ flowName: c.flowRef,
508
508
  status: "pending",
509
- source: s.source,
510
- requestId: g,
511
- input: p
509
+ source: o.source,
510
+ requestId: h,
511
+ input: f
512
512
  });
513
513
  } catch {}
514
- await m.child("flow.run", {
515
- runId: h,
516
- flowRef: l.flowRef,
517
- input: p,
518
- source: s.source,
519
- requestId: g,
520
- chainPath: u
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(c),
545
+ planCostSource: k.optional(n),
546
546
  toolCostMicroUsd: k.Number,
547
- steps: k.Array(d),
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 = (e, n = {}) => (r, i) => E.gen(function* () {
850
- let { runId: i, flowRef: a, input: o } = r, s = yield* E.tryPromise(() => e.store.query(M(t).where(j("id", i)).descriptor)).pipe(E.flatMap(k.decodeUnknownEffect(k.Tuple([k.Struct({
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(e, i, {
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(e, a).pipe(E.flatMap((e) => {
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(e, i, {
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(e, n, i, d, o, l, c, a) : yield* me(e, n, i, d, o, {
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(e, i, d, o, f.output ?? {}, r, n)), n.onEvent && (f.status === "succeeded" || f.status === "failed") && (yield* I(n.onEvent({
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 { collectRefs as ge, interpolate as _e, unresolvedRefs as ve } from "./interpolate.js";
9
- import { flowSegments as ye, nonContiguousGroups as be } from "./segments.js";
10
- import { buildFlowRunExecute as xe, resolveIr as Se } from "./engine.js";
11
- import { defineFlow as Ce, flowStep as we, validateFlow as Te } from "./define.js";
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, xe as buildFlowRunExecute, Ee as cadenceMatches, je as cancelFlow, pe as clampMaxSteps, e as clearRegistry, ge as collectRefs, Me as createFlow, Oe as cronRequestId, Ce as defineFlow, Ne as deleteFlow, x as describeCondition, S as evaluateCondition, ye as flowSegments, we as flowStep, ne as getAiFlowsDefaults, Pe as getFlow, t as getRegisteredFlow, l as humanResponseSignalName, _e as interpolate, C as isTruthy, Fe as launchFlow, Ie as listFlows, n as listRegisteredFlows, Ae as makeMediaGenerator, De as nextRuns, be as nonContiguousGroups, me as normalizeFlow, d as reconcileFlowStarts, r as registerFlow, ie as resetAiFlowsDefaults, g as resolveHumanReviewTimeoutMs, Se as resolveIr, _ as resolveMaxChainDepth, Le as respondToFlow, X as retryFlow, ke as runCadenceTick, he as sanitizeOutputKey, v as setAiFlowsDefaults, ve as unresolvedRefs, Re as updateFlow, Te as validateFlow, ze as waitingStepIndex };
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 };