@voltro/plugin-ai-flows 0.86.0 → 0.88.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/cadence.js CHANGED
@@ -1,4 +1,4 @@
1
- //#region src/cadence.ts
1
+ // src/cadence.ts
2
2
  var e = (e) => (e.getDay() + 6) % 7, t = (e) => Math.ceil(e.getDate() / 7), n = (e) => {
3
3
  let t = new Date(e.getFullYear(), e.getMonth() + 1, 0).getDate();
4
4
  return e.getDate() + 7 > t;
@@ -36,5 +36,4 @@ var e = (e) => (e.getDay() + 6) % 7, t = (e) => Math.ceil(e.getDate() / 7), n =
36
36
  for (; r.length < n && i.getTime() <= s;) a(e, i) && r.push(new Date(i)), i.setMinutes(i.getMinutes() + 15);
37
37
  return r;
38
38
  };
39
- //#endregion
40
39
  export { a as cadenceMatches, o as nextRuns };
@@ -5,7 +5,7 @@ import { cadenceMatches as r } from "./cadence.js";
5
5
  import { recordFlowStartReceipt as i } from "./startReceipt.js";
6
6
  import { Schema as a } from "effect";
7
7
  import { createHash as o } from "node:crypto";
8
- //#region src/cadenceTick.ts
8
+ // src/cadenceTick.ts
9
9
  var s = (e, t, n) => {
10
10
  if (!Number.isFinite(t.getTime())) throw Error("cadence timestamp must be valid");
11
11
  return `cron-${o("sha256").update(JSON.stringify([
@@ -76,5 +76,4 @@ var s = (e, t, n) => {
76
76
  reconciled: f
77
77
  };
78
78
  };
79
- //#endregion
80
79
  export { s as cronRequestId, l as runCadenceTick };
package/dist/condition.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Schema as e } from "effect";
2
- //#region src/condition.ts
2
+ // src/condition.ts
3
3
  var t = e.Literals([
4
4
  "truthy",
5
5
  "falsy",
@@ -42,5 +42,4 @@ var t = e.Literals([
42
42
  case "contains": return `{{${e.ref}}} contains ${JSON.stringify(e.value)}`;
43
43
  }
44
44
  };
45
- //#endregion
46
45
  export { t as ConditionOp, n as StepCondition, o as describeCondition, a as evaluateCondition, r as isTruthy };
package/dist/defaults.js CHANGED
@@ -1,4 +1,4 @@
1
- //#region src/defaults.ts
1
+ // src/defaults.ts
2
2
  var e = 168, t = "VOLTRO_AI_FLOW_HUMAN_REVIEW_TIMEOUT_HOURS", n = 2160, r = "VOLTRO_AI_FLOW_RUNS_TTL_HOURS", i = 5, a = "VOLTRO_AI_FLOW_MAX_CHAIN_DEPTH", o = { current: {} }, s = (e) => {
3
3
  o.current = e;
4
4
  }, c = () => o.current, l = () => {
@@ -14,5 +14,4 @@ var e = 168, t = "VOLTRO_AI_FLOW_HUMAN_REVIEW_TIMEOUT_HOURS", n = 2160, r = "VOL
14
14
  let t = e?.env ?? process.env, n = Number(t[a]), r = e?.maxChainDepth ?? c().maxChainDepth ?? (Number.isFinite(n) && n >= 1 ? n : 5);
15
15
  return Number.isFinite(r) && r >= 1 ? r : 5;
16
16
  };
17
- //#endregion
18
17
  export { r as FLOW_RUNS_TTL_ENV, n as FLOW_RUNS_TTL_HOURS_DEFAULT, t as HUMAN_REVIEW_TIMEOUT_ENV, e as HUMAN_REVIEW_TIMEOUT_HOURS_DEFAULT, i as MAX_CHAIN_DEPTH_DEFAULT, a as MAX_CHAIN_DEPTH_ENV, c as getAiFlowsDefaults, u as msFromHoursEnv, l as resetAiFlowsDefaults, f as resolveHumanReviewTimeoutMs, p as resolveMaxChainDepth, s as setAiFlowsDefaults, d as toTimeoutMs };
package/dist/define.js CHANGED
@@ -3,7 +3,7 @@ import { normalizeFlow as t, sanitizeOutputKey as n } from "./ir.js";
3
3
  import { collectRefs as r } from "./interpolate.js";
4
4
  import { flowSegments as i, nonContiguousGroups as a } from "./segments.js";
5
5
  import { FlowValidationError as o } from "./errors.js";
6
- //#region src/define.ts
6
+ // src/define.ts
7
7
  var s = {
8
8
  text: (e) => ({
9
9
  type: "generate",
@@ -67,5 +67,4 @@ var s = {
67
67
  });
68
68
  return l(r), e(r), r;
69
69
  };
70
- //#endregion
71
70
  export { u as defineFlow, s as flowStep, l as validateFlow };
package/dist/engine.js CHANGED
@@ -12,10 +12,11 @@ import { decodeMediaResult as x } from "./mediaResult.js";
12
12
  import { FlowCapabilityMissing as S, FlowDependencyError as C, FlowNotFound as w } from "./errors.js";
13
13
  import { Cause as T, Effect as E, Exit as D, Result as O, Schema as k } from "effect";
14
14
  import { and as A, eq as j, queryFor as M } from "@voltro/database";
15
- import { SuspensionUnavailable as ee, awaitSignalSuspending as te, step as N } from "@voltro/workflow";
16
- import { defineTool as P, estimateCostUsd as ne, gatewayCostUsd as re, generateObject as ie, generateObjectJson as ae, generateObjectWithTools as oe, generateText as F } from "@voltro/ai";
17
- //#region src/engine.ts
18
- var I = (e) => e, se = (e) => e._tag === "FlowAgentUnavailable" ? e.publicMessage ?? "agent unavailable" : "agent not found", L = k.Struct({
15
+ import { WorkflowEngine as ee } from "effect/workflow";
16
+ import { SuspensionUnavailable as te, awaitSignalSuspending as ne, step as N } from "@voltro/workflow";
17
+ import { defineTool as P, estimateCostUsd as re, gatewayCostUsd as ie, generateObject as ae, generateObjectJson as oe, generateObjectWithTools as se, generateText as F } from "@voltro/ai";
18
+ // src/engine.ts
19
+ var I = (e) => e, ce = (e) => e._tag === "FlowAgentUnavailable" ? e.publicMessage ?? "agent unavailable" : "agent not found", L = k.Struct({
19
20
  value: k.optional(k.Unknown),
20
21
  text: k.optional(k.String),
21
22
  url: k.optional(k.String),
@@ -41,10 +42,10 @@ var I = (e) => e, se = (e) => e._tag === "FlowAgentUnavailable" ? e.publicMessag
41
42
  ...e.costMicroUsd ? { costMicroUsd: e.costMicroUsd } : {},
42
43
  ...e.costSource === void 0 ? {} : { costSource: e.costSource },
43
44
  ...e.usage === void 0 ? {} : { usage: e.usage }
44
- }), B = () => (/* @__PURE__ */ new Date()).toISOString(), ce = (e) => Math.round(e * 1e6), le = (e) => ({
45
+ }), B = () => (/* @__PURE__ */ new Date()).toISOString(), le = (e) => Math.round(e * 1e6), ue = (e) => ({
45
46
  name: "gateway",
46
47
  model: e
47
- }), V = (e, t) => e.resolveModel?.(t) ?? le(t), H = (e, t, n, r) => E.gen(function* () {
48
+ }), V = (e, t) => e.resolveModel?.(t) ?? ue(t), H = (e, t, n, r) => E.gen(function* () {
48
49
  return t.maxSteps !== void 0 && (!Number.isSafeInteger(t.maxSteps) || t.maxSteps < 1) ? yield* E.fail(new S({
49
50
  capability: "resolveAgent",
50
51
  message: "agent maxSteps must be a positive safe integer"
@@ -57,12 +58,12 @@ var I = (e) => e, se = (e) => e._tag === "FlowAgentUnavailable" ? e.publicMessag
57
58
  ...t.maxSteps === void 0 ? {} : { maxSteps: t.maxSteps }
58
59
  });
59
60
  }), U = (e, t, n) => W(e, t, n).costMicroUsd, W = (e, t, n) => {
60
- let r = re(t);
61
+ let r = ie(t);
61
62
  if (typeof r == "number") return {
62
- costMicroUsd: ce(r),
63
+ costMicroUsd: le(r),
63
64
  costSource: "gateway"
64
65
  };
65
- let i = ne(e, { model: n ?? "unknown" });
66
+ let i = re(e, { model: n ?? "unknown" });
66
67
  return {
67
68
  costMicroUsd: i.costMicroUsd ?? 0,
68
69
  costSource: i.costSource ?? "unpriced"
@@ -75,10 +76,13 @@ var I = (e) => e, se = (e) => e._tag === "FlowAgentUnavailable" ? e.publicMessag
75
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 () => {
76
77
  let a = await e.store.query(M(t).where(j("id", n)).descriptor), o = a[0]?.[i];
77
78
  a[0] !== void 0 && o == null && await e.store.update(t.tableName, n, r);
78
- }).pipe(E.catchCause(() => E.void)), ue = (e, n) => E.promise(async () => {
79
+ }).pipe(E.catchCause(() => E.void)), de = (e, n) => E.promise(async () => {
79
80
  let r = (await e.store.query(M(t).where(j("id", n)).descriptor))[0]?.status;
80
81
  return r === "cancelling" || r === "cancelled";
81
- }).pipe(E.catchCause(() => E.succeed(!1))), de = (e, n) => E.promise(() => e.store.updateMany(t.tableName, {
82
+ }).pipe(E.catchCause(() => E.succeed(!1))), fe = E.gen(function* () {
83
+ let e = yield* ee.WorkflowInstance;
84
+ return e.interrupted = !0, yield* E.interrupt;
85
+ }), pe = (e, n) => E.promise(() => e.store.updateMany(t.tableName, {
82
86
  status: "cancelled",
83
87
  completedAt: B()
84
88
  }, { where: A(j("id", n), j("status", "cancelling")) }).then(() => void 0)).pipe(E.catchCause(() => E.void)), J = (t, r) => E.gen(function* () {
@@ -146,7 +150,7 @@ var I = (e) => e, se = (e) => e._tag === "FlowAgentUnavailable" ? e.publicMessag
146
150
  }
147
151
  case "structured": {
148
152
  if (n.schema === void 0) return { error: `step "${n.id}": structured step requires a JSON Schema` };
149
- let r = n.model ?? t.defaultModels?.text, i = yield* ae({
153
+ let r = n.model ?? t.defaultModels?.text, i = yield* oe({
150
154
  ...s.success,
151
155
  prompt: e,
152
156
  jsonSchema: n.schema,
@@ -220,7 +224,7 @@ var I = (e) => e, se = (e) => e._tag === "FlowAgentUnavailable" ? e.publicMessag
220
224
  }).message };
221
225
  default: return { error: `unknown step type: ${String(n.type)}` };
222
226
  }
223
- }), fe = (e, t, n, a, c, u) => E.gen(function* () {
227
+ }), me = (e, t, n, a, c, u) => E.gen(function* () {
224
228
  let d = Object.assign(Object.create(null), c), f = Object.create(null), p = a.steps.map((e, t) => ({
225
229
  id: t,
226
230
  title: e.title ?? `Step ${t + 1}`,
@@ -236,10 +240,7 @@ var I = (e) => e, se = (e) => e._tag === "FlowAgentUnavailable" ? e.publicMessag
236
240
  startedAt: B()
237
241
  }, "startedAt");
238
242
  for (let c of g(a.steps)) {
239
- if (yield* ue(e, n)) return yield* de(e, n), {
240
- runId: n,
241
- status: "cancelled"
242
- };
243
+ if (yield* de(e, n)) return yield* pe(e, n), yield* fe;
243
244
  if (c.steps.length > 1) {
244
245
  let r = [];
245
246
  for (let { index: e, step: t } of c.steps) t.when !== void 0 && !s(t.when, d) ? p[e] = {
@@ -346,7 +347,7 @@ var I = (e) => e, se = (e) => e._tag === "FlowAgentUnavailable" ? e.publicMessag
346
347
  step: _,
347
348
  flow: a,
348
349
  deps: t
349
- }), c = yield* te(e, {
350
+ }), c = yield* ne(e, {
350
351
  name: r(g),
351
352
  schema: l,
352
353
  timeoutMs: s
@@ -468,7 +469,7 @@ var I = (e) => e, se = (e) => e._tag === "FlowAgentUnavailable" ? e.publicMessag
468
469
  status: "succeeded",
469
470
  output: _
470
471
  };
471
- }), pe = (e, n, r, i, o, s, c) => E.gen(function* () {
472
+ }), he = (e, n, r, i, o, s, c) => E.gen(function* () {
472
473
  let l = r.chain;
473
474
  if (!l) return;
474
475
  let u = [...s.chainPath ?? [], s.flowRef];
@@ -519,33 +520,33 @@ var I = (e) => e, se = (e) => e._tag === "FlowAgentUnavailable" ? e.publicMessag
519
520
  chainPath: u
520
521
  });
521
522
  }).pipe(E.catchCause(() => E.void));
522
- }), me = (e) => e.type === "agent" ? e.agentRef ? `agent step, agent "${e.agentRef}"` : "agent step" : e.type === "generate" ? `${e.modality ?? "media"} generation step` : `${e.type} step`, he = (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}` : ""} (${me(e)})`).join("\n"), ge = "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." }) }), _e = (e) => {
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) => {
523
524
  try {
524
525
  let t = JSON.parse(e);
525
526
  return typeof t == "object" && t && !Array.isArray(t) ? t : void 0;
526
527
  } catch {
527
528
  return;
528
529
  }
529
- }, ve = (e) => {
530
+ }, be = (e) => {
530
531
  if (D.isSuccess(e)) return "the tool returned without recording a result";
531
532
  if (T.hasInterruptsOnly(e.cause)) return "interrupted before it finished — nothing waited for its result";
532
533
  let t = T.squash(e.cause);
533
534
  return t instanceof Error ? t.message : String(t);
534
- }, ye = (e) => {
535
+ }, xe = (e) => {
535
536
  let t = Object.entries(e);
536
537
  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");
537
538
  }, $ = (e) => [
538
539
  e.orchestrator?.instructions ?? "You are an orchestrator that uses the available tools to produce a bundled result.",
539
- he(e),
540
+ _e(e),
540
541
  "When finished, emit a JSON object mapping each deliverable name (outputKey) to its value, serialized as a string in the json field."
541
- ].filter(Boolean).join("\n\n"), be = k.Struct({
542
+ ].filter(Boolean).join("\n\n"), Se = k.Struct({
542
543
  object: k.Record(k.String, k.Unknown),
543
544
  planCostMicroUsd: k.Number,
544
545
  planCostSource: k.optional(c),
545
546
  toolCostMicroUsd: k.Number,
546
547
  steps: k.Array(d),
547
548
  error: k.optional(k.String)
548
- }), xe = (e, t, n, r, i, a, o, s) => E.gen(function* () {
549
+ }), Ce = (e, t, n, r, i, a, o, s) => E.gen(function* () {
549
550
  yield* q(e, n, {
550
551
  status: "running",
551
552
  startedAt: B(),
@@ -554,7 +555,7 @@ var I = (e) => e, se = (e) => e._tag === "FlowAgentUnavailable" ? e.publicMessag
554
555
  let c = yield* N({
555
556
  name: "flow-agentic",
556
557
  input: { flowRef: r.name },
557
- success: be,
558
+ success: Se,
558
559
  execute: E.gen(function* () {
559
560
  let c = [], l = 0, u = (e) => {
560
561
  let t = c.length;
@@ -578,7 +579,7 @@ var I = (e) => e, se = (e) => e._tag === "FlowAgentUnavailable" ? e.publicMessag
578
579
  let n = u(e);
579
580
  return E.andThen(f(), t(n)).pipe(E.onExit((e) => c[n]?.status === "running" ? (d(n, {
580
581
  status: "failed",
581
- errorMessage: ve(e)
582
+ errorMessage: be(e)
582
583
  }), E.ignore(f())) : E.void));
583
584
  }), m = yield* (t.listAgents ? I(t.listAgents({
584
585
  runId: n,
@@ -624,7 +625,7 @@ var I = (e) => e, se = (e) => e._tag === "FlowAgentUnavailable" ? e.publicMessag
624
625
  if (!s.ok) return d(i, {
625
626
  status: "failed",
626
627
  errorMessage: s.e.message
627
- }), yield* f(), `ERROR: ${se(s.e)}`;
628
+ }), yield* f(), `ERROR: ${ce(s.e)}`;
628
629
  let c = yield* H(t, s.a, r, {}).pipe(E.map((e) => ({
629
630
  ok: !0,
630
631
  r: e
@@ -719,7 +720,7 @@ var I = (e) => e, se = (e) => e._tag === "FlowAgentUnavailable" ? e.publicMessag
719
720
  type: "structured",
720
721
  ...Z(n)
721
722
  }, (n) => E.gen(function* () {
722
- let i = yield* ie({
723
+ let i = yield* ae({
723
724
  prompt: `${e}\n\nReturn the JSON object serialized as a string in the \`json\` field.`,
724
725
  schema: Q,
725
726
  ...r ? { provider: V(t, r) } : {}
@@ -739,7 +740,7 @@ var I = (e) => e, se = (e) => e._tag === "FlowAgentUnavailable" ? e.publicMessag
739
740
  }
740
741
  let a = U(i.r.usage, i.r.providerMetadata, r);
741
742
  l += a;
742
- let o = _e(i.r.object.json);
743
+ let o = ye(i.r.object.json);
743
744
  if (o === void 0) {
744
745
  let e = "the model's `json` field is not a JSON object";
745
746
  return d(n, {
@@ -777,9 +778,9 @@ var I = (e) => e, se = (e) => e._tag === "FlowAgentUnavailable" ? e.publicMessag
777
778
  steps: c,
778
779
  error: "flow tools cannot replace reserved planner tools"
779
780
  };
780
- let T = t.memoryPrefix ? yield* I(t.memoryPrefix(a)).pipe(E.catch(() => E.succeed(""))) : "", D = T ? `${T}\n\n${$(r)}` : $(r), A = yield* oe({
781
+ let T = t.memoryPrefix ? yield* I(t.memoryPrefix(a)).pipe(E.catch(() => E.succeed(""))) : "", D = T ? `${T}\n\n${$(r)}` : $(r), A = yield* se({
781
782
  system: D,
782
- prompt: ye(i),
783
+ prompt: xe(i),
783
784
  schema: Q,
784
785
  tools: {
785
786
  ...w.success,
@@ -790,7 +791,7 @@ var I = (e) => e, se = (e) => e._tag === "FlowAgentUnavailable" ? e.publicMessag
790
791
  },
791
792
  maxSteps: r.maxSteps,
792
793
  ...r.orchestrator?.model ? { provider: V(t, r.orchestrator.model) } : {}
793
- }).pipe(E.provideService(ee, ge), E.map((e) => ({
794
+ }).pipe(E.provideService(te, ve), E.map((e) => ({
794
795
  ok: !0,
795
796
  r: e
796
797
  })), E.catch((e) => E.succeed({
@@ -808,7 +809,7 @@ var I = (e) => e, se = (e) => e._tag === "FlowAgentUnavailable" ? e.publicMessag
808
809
  steps: c,
809
810
  error: String(A.e.message ?? A.e)
810
811
  };
811
- let j = _e(A.r.object.json);
812
+ let j = ye(A.r.object.json);
812
813
  return {
813
814
  object: j ?? {},
814
815
  ...j === void 0 ? { error: "the planner's `json` field is not a JSON object" } : {},
@@ -845,7 +846,7 @@ var I = (e) => e, se = (e) => e._tag === "FlowAgentUnavailable" ? e.publicMessag
845
846
  status: "succeeded",
846
847
  output: c.object
847
848
  });
848
- }), Se = (e, n = {}) => (r, i) => E.gen(function* () {
849
+ }), we = (e, n = {}) => (r, i) => E.gen(function* () {
849
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({
850
851
  id: k.Literal(i),
851
852
  tenantId: k.NullOr(k.NonEmptyString),
@@ -889,12 +890,12 @@ var I = (e) => e, se = (e) => e._tag === "FlowAgentUnavailable" ? e.publicMessag
889
890
  runId: i,
890
891
  status: "failed"
891
892
  };
892
- let d = u.ir, f = d.mode === "agentic" ? yield* xe(e, n, i, d, o, l, c, a) : yield* fe(e, n, i, d, o, {
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
894
  ownerId: l,
894
895
  tenantId: c,
895
896
  source: r.source
896
897
  });
897
- return f.status === "succeeded" && d.chain && (yield* pe(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(e, i, d, o, f.output ?? {}, r, n)), n.onEvent && (f.status === "succeeded" || f.status === "failed") && (yield* I(n.onEvent({
898
899
  kind: f.status,
899
900
  runId: i,
900
901
  flowName: d.name,
@@ -902,5 +903,4 @@ var I = (e) => e, se = (e) => e._tag === "FlowAgentUnavailable" ? e.publicMessag
902
903
  source: r.source
903
904
  })).pipe(E.catchCause(() => E.void))), f;
904
905
  });
905
- //#endregion
906
- export { Se as buildFlowRunExecute, J as resolveIr };
906
+ export { we as buildFlowRunExecute, J as resolveIr };
package/dist/errors.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { MediaReceipt as e } from "./ir.js";
2
2
  import { Schema as t } from "effect";
3
- //#region src/errors.ts
3
+ // src/errors.ts
4
4
  var n = class extends t.TaggedError()("FlowNotFound", {
5
5
  flowRef: t.String,
6
6
  message: t.String
@@ -45,5 +45,4 @@ var n = class extends t.TaggedError()("FlowNotFound", {
45
45
  message: t.String,
46
46
  publicMessage: t.optional(t.String)
47
47
  }) {};
48
- //#endregion
49
48
  export { u as FlowAgentUnavailable, o as FlowBriefIncomplete, l as FlowCapabilityMissing, a as FlowDependencyError, s as FlowNotAwaitingResponse, n as FlowNotFound, c as FlowReviewDeliveryError, r as FlowRunNotFound, i as FlowValidationError };
package/dist/index.d.ts CHANGED
@@ -10,8 +10,7 @@ import { Schema } from 'effect';
10
10
  import { Table } from '@voltro/database';
11
11
  import { TableLike } from '@voltro/database';
12
12
  import { VoltroPlugin } from '@voltro/protocol';
13
- import { WorkflowEngine } from 'effect/workflow/WorkflowEngine';
14
- import { WorkflowInstance } from 'effect/workflow/WorkflowEngine';
13
+ import { WorkflowEngine } from 'effect/workflow';
15
14
  import { WorkflowRunHandle } from '@voltro/protocol';
16
15
  import { YieldableError } from 'effect/Cause';
17
16
 
@@ -49,7 +48,7 @@ export declare const aiFlowRunsTable: Table<"_voltro_ai_flow_runs", FieldDefinit
49
48
  /** Last observed admission answer, not current execution state. Null means
50
49
  * no answer was recorded, not that submission did not reach the engine. */
51
50
  readonly workflowStart: ColumnBuilder<{
52
- readonly status: "dropped" | "skipped" | "running" | "succeeded" | "queued" | "replayed";
51
+ readonly status: "succeeded" | "dropped" | "skipped" | "running" | "queued" | "replayed";
53
52
  readonly id: string;
54
53
  readonly executionId: string | null;
55
54
  readonly workflowName: string;
@@ -275,17 +274,17 @@ export declare interface BriefField {
275
274
  */
276
275
  export declare const buildFlowRunExecute: (ctx: AppContext, deps?: EngineDeps) => (payload: FlowRunPayload, _executionId: string) => Effect.Effect<{
277
276
  runId: string;
278
- status: "cancelled";
277
+ status: "failed";
279
278
  output?: never;
280
279
  } | {
281
280
  runId: string;
282
- status: "failed";
281
+ status: "cancelled";
283
282
  output?: never;
284
283
  } | {
285
284
  runId: string;
286
285
  status: "succeeded";
287
286
  output: Record<string, unknown>;
288
- }, never, WorkflowEngine | WorkflowInstance>;
287
+ }, never, WorkflowEngine.WorkflowEngine | WorkflowEngine.WorkflowInstance>;
289
288
 
290
289
  /**
291
290
  * Does `cadence` fire at wall-clock `now`? True only on a 15-min slot matching
@@ -314,14 +313,14 @@ export declare const cancelFlow: (ctx: AppContext, args: {
314
313
  runId: string;
315
314
  }) => Effect.Effect<{
316
315
  readonly runId: string;
317
- readonly status: "failed" | "pending" | "waiting" | "cancelled" | "running" | "succeeded" | "cancelling";
316
+ readonly status: "failed" | "succeeded" | "pending" | "waiting" | "cancelled" | "running" | "cancelling";
318
317
  readonly engine: "unknown" | "unreachable" | "cancelled" | "accepted" | "already-terminal" | "not-requested";
319
318
  readonly control: {
320
319
  readonly operation: "resume" | "cancel";
321
320
  readonly kind: "unknown" | "accepted" | "confirmed" | "already-terminal";
322
321
  readonly requestId: string | null;
323
322
  readonly snapshot: {
324
- readonly status: "unknown" | "failed" | "cancelled" | "running" | "succeeded" | "suspended";
323
+ readonly status: "unknown" | "failed" | "succeeded" | "cancelled" | "running" | "suspended";
325
324
  readonly id: string;
326
325
  readonly executionId: string;
327
326
  readonly workflowName: string;
@@ -1112,7 +1111,7 @@ export declare const launchFlow: (ctx: AppContext, args: {
1112
1111
  readonly runId: string;
1113
1112
  readonly requestId: string;
1114
1113
  readonly admission: {
1115
- readonly status: "dropped" | "skipped" | "running" | "succeeded" | "queued" | "replayed";
1114
+ readonly status: "succeeded" | "dropped" | "skipped" | "running" | "queued" | "replayed";
1116
1115
  readonly id: string;
1117
1116
  readonly executionId: string | null;
1118
1117
  readonly workflowName: string;
@@ -1400,7 +1399,7 @@ export declare const retryFlow: (ctx: AppContext, args: {
1400
1399
  readonly runId: string;
1401
1400
  readonly requestId: string;
1402
1401
  readonly admission: {
1403
- readonly status: "dropped" | "skipped" | "running" | "succeeded" | "queued" | "replayed";
1402
+ readonly status: "succeeded" | "dropped" | "skipped" | "running" | "queued" | "replayed";
1404
1403
  readonly id: string;
1405
1404
  readonly executionId: string | null;
1406
1405
  readonly workflowName: string;
package/dist/index.js CHANGED
@@ -16,7 +16,7 @@ import { cancelFlow as je, createFlow as Me, deleteFlow as Ne, getFlow as Pe, la
16
16
  import { Effect as Z } from "effect";
17
17
  import { definePlugin as Be, pluginInstanceName as Ve } from "@voltro/protocol";
18
18
  import { eq as Q, inSet as He, notInSet as Ue, queryFor as We, registerRetention as Ge } from "@voltro/database";
19
- //#region src/index.ts
19
+ // src/index.ts
20
20
  var $ = "aiFlows", Ke = (e = {}) => {
21
21
  let t = Ve({
22
22
  base: $,
@@ -160,5 +160,4 @@ var $ = "aiFlows", Ke = (e = {}) => {
160
160
  }).pipe(Z.catchCause(() => Z.void))
161
161
  });
162
162
  };
163
- //#endregion
164
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 };
@@ -1,4 +1,4 @@
1
- //#region src/interpolate.ts
1
+ // src/interpolate.ts
2
2
  var e = /\{\{\s*([\w.-]+)\s*\}\}/g, t = (t) => {
3
3
  let n = [];
4
4
  for (let r of t.matchAll(e)) n.push(r[1]);
@@ -11,5 +11,4 @@ var e = /\{\{\s*([\w.-]+)\s*\}\}/g, t = (t) => {
11
11
  for (let i of t(e)) n[i] == null && !r.has(i) && r.add(i);
12
12
  return [...r];
13
13
  };
14
- //#endregion
15
14
  export { t as collectRefs, n as interpolate, r as unresolvedRefs };
package/dist/ir.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ConditionOp as e, StepCondition as t, describeCondition as n, evaluateCondition as r, isTruthy as i } from "./condition.js";
2
2
  import { Schema as a } from "effect";
3
3
  import { WorkflowControlResultSchema as o, WorkflowRunHandleSchema as s } from "@voltro/protocol";
4
- //#region src/ir.ts
4
+ // src/ir.ts
5
5
  var c = a.Struct({
6
6
  runId: a.NonEmptyString,
7
7
  requestId: a.NonEmptyString,
@@ -229,5 +229,4 @@ var c = a.Struct({
229
229
  ...e.humanTimeoutMs != null && Number.isFinite(e.humanTimeoutMs) ? { humanTimeoutMs: e.humanTimeoutMs } : {}
230
230
  };
231
231
  };
232
- //#endregion
233
232
  export { T as BriefField, R as ChainPending, e as ConditionOp, j as CostCompleteness, A as CostSource, D as FlowCadence, p as FlowCancelReceipt, E as FlowChain, l as FlowMode, I as FlowReviewInput, L as FlowReviewReceipt, c as FlowStartReceipt, u as FlowStatus, w as FlowStep, F as HumanResponse, x as Json, z as MAX_STEPS_DEFAULT, V as MAX_STEPS_MAX, B as MAX_STEPS_MIN, S as MediaArtifact, C as MediaArtifacts, y as MediaInputSlot, b as MediaInputs, N as MediaReceipt, g as Modality, _ as ReviewMode, v as ReviewOption, k as RunReview, m as RunSource, f as RunStatus, P as RunStep, O as RunStepStatus, t as StepCondition, h as StepType, M as StepUsage, d as Visibility, H as clampMaxSteps, n as describeCondition, r as evaluateCondition, i as isTruthy, W as normalizeFlow, U as sanitizeOutputKey };
@@ -1,5 +1,5 @@
1
1
  import { Schema as e } from "effect";
2
- //#region src/jsonParams.ts
2
+ // src/jsonParams.ts
3
3
  var t = e.suspend(() => e.Union([
4
4
  e.Null,
5
5
  e.Boolean,
@@ -8,5 +8,4 @@ var t = e.suspend(() => e.Union([
8
8
  e.Array(t).pipe(e.mutable),
9
9
  e.Record(e.String, t)
10
10
  ])), n = e.Record(e.String, e.Record(e.String, t));
11
- //#endregion
12
11
  export { n as ProviderOptions };
@@ -3,7 +3,7 @@ import { FlowCapabilityMissing as t } from "./errors.js";
3
3
  import { audioParams as n, imageParams as r, videoParams as i } from "./mediaParams.js";
4
4
  import { Effect as a } from "effect";
5
5
  import { estimateCostUsd as o, gatewayCostUsd as s, generateImage as c, generateSpeech as l, generateVideo as u, isMeteredUsage as d } from "@voltro/ai";
6
- //#region src/mediaAdapter.ts
6
+ // src/mediaAdapter.ts
7
7
  var f = (e) => ({
8
8
  name: "gateway",
9
9
  model: e
@@ -175,5 +175,4 @@ var f = (e) => ({
175
175
  message: String(e.message ?? e)
176
176
  }))));
177
177
  };
178
- //#endregion
179
178
  export { _ as makeMediaGenerator };
@@ -1,6 +1,6 @@
1
1
  import { MediaInputs as e } from "./ir.js";
2
2
  import { Effect as t, Schema as n } from "effect";
3
- //#region src/mediaInputs.ts
3
+ // src/mediaInputs.ts
4
4
  var r = n.String.pipe(n.check(n.makeFilter((e) => {
5
5
  try {
6
6
  let t = new URL(e);
@@ -53,5 +53,4 @@ var s = (t, i = {}) => {
53
53
  },
54
54
  catch: () => `invalid or unsupported media input for ${e}; check the built-in adapter's slot contract`
55
55
  });
56
- //#endregion
57
56
  export { r as MediaInputUrl, o as ResolvedMediaInputRef, i as ResolvedMediaInputs, c as nativeMediaInputs, s as resolveMediaInputRefs, a as resolveMediaInputs };
@@ -1,6 +1,6 @@
1
1
  import { ProviderOptions as e } from "./jsonParams.js";
2
2
  import { Effect as t, Schema as n } from "effect";
3
- //#region src/mediaParams.ts
3
+ // src/mediaParams.ts
4
4
  var r = (e) => n.optionalKey(e), i = n.Int.pipe(n.check(n.isGreaterThan(0)), n.check(n.isLessThanOrEqualTo(2 ** 53 - 1))), a = n.Int.pipe(n.check(n.isBetween({
5
5
  minimum: -(2 ** 53 - 1),
6
6
  maximum: 2 ** 53 - 1
@@ -38,5 +38,4 @@ var r = (e) => n.optionalKey(e), i = n.Int.pipe(n.check(n.isGreaterThan(0)), n.c
38
38
  try: () => n.decodeUnknownSync(e, { onExcessProperty: "error" })(r === void 0 ? {} : r),
39
39
  catch: () => `invalid ${i} media params: check the built-in adapter's supported options and value ranges`
40
40
  }), f = (e) => d(c, e, "image"), p = (e) => d(l, e, "audio"), m = (e) => d(u, e, "video");
41
- //#endregion
42
41
  export { p as audioParams, f as imageParams, m as videoParams };
@@ -1,6 +1,6 @@
1
1
  import { CostSource as e, MediaArtifacts as t, StepUsage as n } from "./ir.js";
2
2
  import { Effect as r, Schema as i } from "effect";
3
- //#region src/mediaResult.ts
3
+ // src/mediaResult.ts
4
4
  var a = i.Struct({
5
5
  artifacts: t,
6
6
  costMicroUsd: i.optional(i.Finite.pipe(i.check(i.isGreaterThanOrEqualTo(0)))),
@@ -11,5 +11,4 @@ var a = i.Struct({
11
11
  try: () => i.decodeUnknownSync(a, { onExcessProperty: "error" })(e),
12
12
  catch: () => "invalid media result: expected artifacts with URL, mediaType and role, exactly one primary artifact, and optional storage references"
13
13
  });
14
- //#endregion
15
14
  export { a as MediaResult, o as decodeMediaResult };
@@ -7,7 +7,7 @@ import { recordFlowStartReceipt as m } from "./startReceipt.js";
7
7
  import { Effect as h, Result as g, Schema as _ } from "effect";
8
8
  import { WorkflowControlResultSchema as v } from "@voltro/protocol";
9
9
  import { and as y, eq as b, inSet as x, queryFor as S } from "@voltro/database";
10
- //#region src/procedures.ts
10
+ // src/procedures.ts
11
11
  var C = () => globalThis.crypto?.randomUUID?.() ?? `req-${Date.now().toString(36)}`, w = (e) => e.request?.subject?.id ?? null, T = (t, n) => h.promise(() => t.store.query(S(e).where(b("id", n)).descriptor)).pipe(h.map((e) => e[0])), E = (e) => h.sync(() => {
12
12
  let t = e.workflows;
13
13
  if (!t) throw Error("workflow runtime unavailable; no flow start was submitted");
@@ -204,5 +204,4 @@ var C = () => globalThis.crypto?.randomUUID?.() ?? `req-${Date.now().toString(36
204
204
  id: n.id ?? `flow-${C()}`,
205
205
  ...n
206
206
  })), I = (e, n) => h.promise(() => e.store.update(t.tableName, n.id, n.patch)), L = (e, n) => h.promise(() => e.store.delete(t.tableName, n.id));
207
- //#endregion
208
207
  export { k as cancelFlow, F as createFlow, L as deleteFlow, N as getFlow, i as humanResponseSignalName, D as launchFlow, P as listFlows, M as respondToFlow, O as retryFlow, I as updateFlow, j as waitingStepIndex };
package/dist/registry.js CHANGED
@@ -1,6 +1,5 @@
1
- //#region src/registry.ts
1
+ // src/registry.ts
2
2
  var e = /* @__PURE__ */ new Map(), t = (t) => {
3
3
  e.set(t.name, t);
4
4
  }, n = (t) => e.get(t), r = () => [...e.values()], i = () => e.clear();
5
- //#endregion
6
5
  export { i as clearRegistry, n as getRegisteredFlow, r as listRegisteredFlows, t as registerFlow };
package/dist/rpc.js CHANGED
@@ -1,4 +1,3 @@
1
- //#region src/rpc.ts
1
+ // src/rpc.ts
2
2
  var e = [];
3
- //#endregion
4
3
  export { e as aiFlowsRpcClientImports };
package/dist/segments.js CHANGED
@@ -1,4 +1,4 @@
1
- //#region src/segments.ts
1
+ // src/segments.ts
2
2
  var e = (e) => {
3
3
  let t = [], n;
4
4
  if (e.forEach((e, r) => {
@@ -29,5 +29,4 @@ var e = (e) => {
29
29
  for (let n of e) n.group !== void 0 && t.set(n.group, (t.get(n.group) ?? 0) + 1);
30
30
  return [...t.entries()].filter(([, e]) => e > 1).map(([e]) => e).sort();
31
31
  };
32
- //#endregion
33
32
  export { e as flowSegments, t as nonContiguousGroups };
@@ -2,11 +2,10 @@ import { aiFlowRunsTable as e } from "./table.js";
2
2
  import "./workflow.js";
3
3
  import { Schema as t } from "effect";
4
4
  import { WorkflowRunHandleSchema as n } from "@voltro/protocol";
5
- //#region src/startReceipt.ts
5
+ // src/startReceipt.ts
6
6
  var r = async (r, i, a) => {
7
7
  let o = t.decodeUnknownSync(n.pipe(t.check(t.makeFilter((e) => e.workflowName === "flow.run" && e.id.length > 0))))(a);
8
8
  if (await r.store.update(e.tableName, i, { workflowStart: o }) === null) throw Error("flow start receipt could not be recorded; workflow submission may have succeeded");
9
9
  return o;
10
10
  };
11
- //#endregion
12
11
  export { r as recordFlowStartReceipt };
@@ -2,7 +2,7 @@ import { aiFlowRunsTable as e } from "./table.js";
2
2
  import { FLOW_RUN_WORKFLOW as t } from "./workflow.js";
3
3
  import { Schema as n } from "effect";
4
4
  import { eq as r } from "@voltro/database";
5
- //#region src/startReconcile.ts
5
+ // src/startReconcile.ts
6
6
  var i = n.Struct({
7
7
  id: n.NonEmptyString,
8
8
  workflowName: n.Literal(t),
@@ -77,5 +77,4 @@ var i = n.Struct({
77
77
  }
78
78
  return d;
79
79
  };
80
- //#endregion
81
80
  export { a as admittedStartHandle, s as reconcileFlowStarts };
package/dist/table.js CHANGED
@@ -2,7 +2,7 @@ import { boolean as e, id as t, integer as n, json as r, table as i, text as a,
2
2
  import { tenant as s } from "@voltro/plugin-multitenancy/mixin";
3
3
  import { audit as c } from "@voltro/plugin-audit/mixin";
4
4
  import { softDelete as l } from "@voltro/plugin-soft-delete/mixin";
5
- //#region src/table.ts
5
+ // src/table.ts
6
6
  var u = i("_voltro_ai_flows", {
7
7
  id: t({ prefix: "aifl" }),
8
8
  name: a(),
@@ -55,5 +55,4 @@ var u = i("_voltro_ai_flows", {
55
55
  ownerId: a().nullable(),
56
56
  metadata: r().nullable()
57
57
  }).renamedFrom("ai_flow_runs").with(s(), c()).index(["flowRef"]).index(["status"]).index(["requestId"]), f = [u, d];
58
- //#endregion
59
58
  export { d as aiFlowRunsTable, u as aiFlowsTable, f as aiFlowsTables };
@@ -1,6 +1,6 @@
1
1
  import { ProviderOptions as e } from "./jsonParams.js";
2
2
  import { Effect as t, Schema as n } from "effect";
3
- //#region src/textParams.ts
3
+ // src/textParams.ts
4
4
  var r = n.Struct({
5
5
  maxTokens: n.optionalKey(n.Int.pipe(n.check(n.isGreaterThan(0)), n.check(n.isLessThanOrEqualTo(2 ** 53 - 1)))),
6
6
  temperature: n.optionalKey(n.Finite.pipe(n.check(n.isGreaterThanOrEqualTo(0)))),
@@ -17,5 +17,4 @@ var r = n.Struct({
17
17
  try: () => n.decodeUnknownSync(r, { onExcessProperty: "error" })(e === void 0 ? {} : e),
18
18
  catch: () => `invalid text params (${a(e)}): expected maxTokens (positive safe integer), temperature (finite nonnegative number), and/or providerOptions (provider-keyed JSON object); other fields are not supported`
19
19
  });
20
- //#endregion
21
20
  export { o as decodeTextParams };