@voltro/ai 0.63.0 → 0.64.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/workflow.js CHANGED
@@ -1,17 +1,17 @@
1
- import { r as e } from "./provider-BOgeCRkg.js";
2
- import { B as t, D as n, G as r, K as i, O as a, b as o, m as s, o as c, p as l, s as u, t as d, w as f, y as p } from "./inferenceQueue-CS1VouiW.js";
3
- import { Effect as m, Schema as h } from "effect";
4
- import { eq as g } from "@voltro/database";
5
- import { CurrentWorkflowExecutionId as _, awaitSignalSuspending as v, step as y, suspendForBudget as b } from "@voltro/workflow";
1
+ import { r as e } from "./provider-RA0getTL.js";
2
+ import { B as t, D as n, E as r, G as i, K as a, O as o, b as s, m as c, o as l, p as u, s as d, t as f, w as p, y as m } from "./inferenceQueue-BS3PVSkk.js";
3
+ import { Effect as h, Schema as g } from "effect";
4
+ import { eq as _ } from "@voltro/database";
5
+ import { CurrentWorkflowExecutionId as v, awaitSignalSuspending as y, step as b, suspendForBudget as x } from "@voltro/workflow";
6
6
  //#region src/inferStep.ts
7
- var x = {
7
+ var S = {
8
8
  maxAttempts: 4,
9
9
  strategy: "exponential",
10
10
  baseDelay: "1 second",
11
11
  maxDelay: "30 seconds",
12
12
  jitter: !0,
13
13
  respectRetryAfter: !0
14
- }, S = 36e5, C = "ai-usd", w = (e, t, n, r) => {
14
+ }, C = 36e5, w = "ai-usd", T = (e, t, n, r) => {
15
15
  let i = r === void 0 ? {} : {
16
16
  promptId: r.promptId,
17
17
  promptVersion: r.digest,
@@ -24,14 +24,14 @@ var x = {
24
24
  ...t === void 0 ? {} : { system: t }
25
25
  } : {
26
26
  ...i,
27
- promptDigest: s(e),
27
+ promptDigest: c(e),
28
28
  promptChars: e.length,
29
29
  ...t === void 0 ? {} : {
30
- systemDigest: s(t),
30
+ systemDigest: c(t),
31
31
  systemChars: t.length
32
32
  }
33
33
  };
34
- }, T = (e) => l(e.prompt) ? {
34
+ }, E = (e) => u(e.prompt) ? {
35
35
  text: e.prompt.prompt,
36
36
  system: e.system ?? e.prompt.system,
37
37
  rendered: e.prompt
@@ -39,68 +39,68 @@ var x = {
39
39
  text: e.prompt,
40
40
  system: e.system,
41
41
  rendered: void 0
42
- }, E = (e) => ({
42
+ }, D = (e) => ({
43
43
  provider: String(e.provider ?? "unknown"),
44
44
  model: String(e.model ?? "unknown")
45
- }), D = (e, n, i, a, o) => {
45
+ }), O = (e, n, r, a, o) => {
46
46
  let s = e.store;
47
- if (s === void 0) return m.void;
48
- let { provider: c, model: l } = E(n), u = t(a.providerMetadata);
49
- return r(s, {
47
+ if (s === void 0) return h.void;
48
+ let { provider: c, model: l } = D(n), u = t(a.providerMetadata);
49
+ return i(s, {
50
50
  provider: c,
51
51
  model: l,
52
- operation: i,
52
+ operation: r,
53
53
  agent: e.name,
54
54
  usage: a.usage,
55
55
  ...e.tenantId === void 0 ? {} : { tenantId: e.tenantId },
56
56
  ...u === void 0 ? {} : { actualCostUsd: u },
57
57
  ...o === void 0 ? {} : { prompt: o }
58
- }).pipe(m.asVoid, m.catchAllCause(() => m.void));
59
- }, O = (e, t) => {
58
+ }).pipe(h.asVoid, h.catchAllCause(() => h.void));
59
+ }, k = (e, t) => {
60
60
  let n = e.store;
61
- return n === void 0 || t === void 0 ? m.void : p(n, {
61
+ return n === void 0 || t === void 0 ? h.void : m(n, {
62
62
  ...t.definition,
63
63
  digest: t.digest
64
- }).pipe(m.asVoid, m.catchAllCause(() => m.void));
65
- }, k = h.Struct({
66
- text: h.String,
67
- inputTokens: h.NullOr(h.Number),
68
- outputTokens: h.NullOr(h.Number),
69
- totalTokens: h.NullOr(h.Number)
70
- }), A = (e) => typeof e == "object" && !!e && e.__voltro_ai_error === !0, j = class extends Error {
64
+ }).pipe(h.asVoid, h.catchAllCause(() => h.void));
65
+ }, A = g.Struct({
66
+ text: g.String,
67
+ inputTokens: g.NullOr(g.Number),
68
+ outputTokens: g.NullOr(g.Number),
69
+ totalTokens: g.NullOr(g.Number)
70
+ }), j = (e) => typeof e == "object" && !!e && e.__voltro_ai_error === !0, M = class extends Error {
71
71
  attempts;
72
72
  constructor(e, t, n) {
73
73
  super(`aiStep('${e}'): the offloaded model call gave up after ${n} attempt(s): ${t}. The queued call is in _voltro_ai_inferences with status 'failed' — the Flow tab shows it with the provider's own message.`), this.name = "AiOffloadError", this.attempts = n;
74
74
  }
75
- }, M = class extends Error {
75
+ }, N = class extends Error {
76
76
  constructor(e) {
77
77
  super(`aiStep('${e}'): offload: true needs \`store\` — the queued call lives in a table and the dispatcher reads it from there. Pass ctx.store.`), this.name = "AiOffloadMisuseError";
78
78
  }
79
- }, N = (e, t, n, r, i, a) => m.gen(function* () {
79
+ }, P = (e, t, n, r, i, a) => h.gen(function* () {
80
80
  let o = e.store;
81
- if (o === void 0) return yield* m.die(new M(e.name));
82
- let s = yield* _;
83
- if (s === void 0) return yield* m.die(/* @__PURE__ */ Error(`aiStep('${e.name}'): offload: true is only valid inside a workflow body — there is no execution to suspend here.`));
84
- let { provider: l, model: f } = E(t), p = u(s, e.name), h = yield* m.promise(() => o.query({
81
+ if (o === void 0) return yield* h.die(new N(e.name));
82
+ let s = yield* v;
83
+ if (s === void 0) return yield* h.die(/* @__PURE__ */ Error(`aiStep('${e.name}'): offload: true is only valid inside a workflow body — there is no execution to suspend here.`));
84
+ let { provider: c, model: u } = D(t), p = d(s, e.name), m = yield* h.promise(() => o.query({
85
85
  table: "_voltro_workflow_runs",
86
- predicate: g("executionId", s),
86
+ predicate: _("executionId", s),
87
87
  order: [],
88
88
  take: 1,
89
89
  skip: void 0,
90
90
  projection: void 0
91
- })), v = String(h[0]?.tag ?? ""), y = h[0]?.id;
92
- return yield* m.promise(() => o.insertIgnore(d, {
91
+ })), g = String(m[0]?.tag ?? ""), y = m[0]?.id;
92
+ return yield* h.promise(() => o.insertIgnore(f, {
93
93
  id: p,
94
94
  tenantId: e.tenantId ?? null,
95
95
  executionId: s,
96
- workflowName: v,
96
+ workflowName: g,
97
97
  runId: typeof y == "string" ? y : null,
98
- signalName: c(p),
98
+ signalName: l(p),
99
99
  stepName: e.name,
100
100
  status: "pending",
101
101
  kind: n,
102
- provider: l,
103
- model: f,
102
+ provider: c,
103
+ model: u,
104
104
  prompt: i.text,
105
105
  system: i.system ?? null,
106
106
  promptId: i.rendered?.promptId ?? null,
@@ -113,97 +113,100 @@ var x = {
113
113
  attempts: 0,
114
114
  enqueuedAt: /* @__PURE__ */ new Date()
115
115
  }, { conflictColumns: ["id"] })), p;
116
- }), P = (e, t, n, r, i, a, o) => m.gen(function* () {
117
- let s = yield* y({
116
+ }), F = (e, t, n, r, i, a, o) => h.gen(function* () {
117
+ let s = yield* b({
118
118
  name: `${e.name}:enqueue`,
119
- success: h.String,
119
+ success: g.String,
120
120
  input: i,
121
- execute: N(e, t, n, r, a, o)
121
+ execute: P(e, t, n, r, a, o)
122
122
  });
123
- yield* O(e, a.rendered);
124
- let l = yield* v({ store: e.store }, {
125
- name: c(s),
126
- schema: h.Unknown,
123
+ yield* k(e, a.rendered);
124
+ let c = yield* y({ store: e.store }, {
125
+ name: l(s),
126
+ schema: g.Unknown,
127
127
  timeoutMs: e.offloadTimeoutMs ?? 36e5
128
128
  });
129
- return A(l) ? yield* m.die(new j(e.name, l.message, l.attempts)) : l;
130
- }), F = class extends Error {
129
+ return j(c) ? yield* h.die(new M(e.name, c.message, c.attempts)) : c;
130
+ }), I = class extends Error {
131
131
  constructor(e) {
132
132
  super(`aiStep('${e}'): budget needs \`store\` — the reservation counter and the hold both live in tables. Pass ctx.store.`), this.name = "AiBudgetMisuseError";
133
133
  }
134
- }, I = (e) => m.gen(function* () {
134
+ }, L = (e) => h.gen(function* () {
135
135
  let t = e.budget;
136
136
  if (t === void 0) return;
137
137
  let n = e.store;
138
- if (n === void 0) return yield* m.die(new F(e.name));
139
- let r = e.tenantId ?? null, a = t.name ?? "ai-usd", o = () => i(n, {
138
+ if (n === void 0) return yield* h.die(new I(e.name));
139
+ let r = e.tenantId ?? null, i = t.name ?? "ai-usd", o = () => a(n, {
140
140
  tenantId: r,
141
141
  limitUsd: t.limitUsd,
142
142
  addUsd: 0,
143
143
  ...t.since === void 0 ? {} : { since: t.since }
144
- }).pipe(m.as(null), m.catchTag("AiBudgetExceeded", (e) => m.succeed(e))), s = () => t.estimateUsd === void 0 ? m.void : i(n, {
144
+ }).pipe(h.as(null), h.catchTag("AiBudgetExceeded", (e) => h.succeed(e))), s = () => t.estimateUsd === void 0 ? h.void : a(n, {
145
145
  tenantId: r,
146
146
  limitUsd: t.limitUsd,
147
147
  addUsd: t.estimateUsd,
148
148
  ...t.since === void 0 ? {} : { since: t.since }
149
149
  }), c = yield* o();
150
150
  if (c === null) return yield* s();
151
- if ((t.onExceeded ?? "fail") !== "suspend") return yield* m.fail(c);
152
- let l = yield* _;
153
- return l === void 0 ? yield* m.fail(c) : (yield* b({
151
+ if ((t.onExceeded ?? "fail") !== "suspend") return yield* h.fail(c);
152
+ let l = yield* v;
153
+ return l === void 0 ? yield* h.fail(c) : (yield* x({
154
154
  store: n,
155
- budget: a,
155
+ budget: i,
156
156
  tenantId: r,
157
157
  executionId: l,
158
- workflowName: yield* L(n, l),
158
+ workflowName: yield* R(n, l),
159
159
  stepName: e.name,
160
160
  spentMicroUsd: Math.round(c.spentUsd * 1e6),
161
161
  limitMicroUsd: Math.round(t.limitUsd * 1e6),
162
- hasHeadroom: o().pipe(m.map((e) => e === null)),
162
+ hasHeadroom: o().pipe(h.map((e) => e === null)),
163
163
  ...t.holdTimeoutMs === void 0 ? {} : { timeoutMs: t.holdTimeoutMs },
164
164
  ...t.recheckEveryMs === void 0 ? {} : { recheckEveryMs: t.recheckEveryMs }
165
- }).pipe(m.catchAll((e) => m.die(e))), yield* s());
166
- }), L = (e, t) => m.promise(async () => {
165
+ }).pipe(h.catchAll((e) => h.die(e))), yield* s());
166
+ }), R = (e, t) => h.promise(async () => {
167
167
  let n = await e.query({
168
168
  table: "_voltro_workflow_runs",
169
- predicate: g("executionId", t),
169
+ predicate: _("executionId", t),
170
170
  order: [],
171
171
  take: 1,
172
172
  skip: void 0,
173
173
  projection: void 0
174
174
  });
175
175
  return String(n[0]?.tag ?? "");
176
- }), R = (t) => {
177
- let r = t.provider ?? e(), i = T(t), a = {
178
- ...E(r),
176
+ }), z = (t) => {
177
+ let r = t.provider ?? e(), i = E(t), a = {
178
+ ...D(r),
179
179
  operation: "generateText",
180
180
  offloaded: t.offload === !0,
181
- ...w(i.text, i.system, t.recordPrompt ?? "digest", i.rendered)
182
- }, o = (e) => t.budget === void 0 ? e : m.zipRight(I(t), e);
183
- return t.offload === !0 ? o(P(t, r, "text", null, a, i)) : o(y({
181
+ ...T(i.text, i.system, t.recordPrompt ?? "digest", i.rendered)
182
+ }, o = (e) => t.budget === void 0 ? e : h.zipRight(L(t), e);
183
+ return t.offload === !0 ? o(F(t, r, "text", null, a, i)) : o(b({
184
184
  name: t.name,
185
- success: k,
185
+ success: A,
186
186
  input: a,
187
- retry: t.retry ?? x,
187
+ retry: t.retry ?? S,
188
188
  execute: n({
189
189
  prompt: i.text,
190
190
  provider: r,
191
191
  ...i.system === void 0 ? {} : { system: i.system },
192
192
  ...t.fallbacks === void 0 ? {} : { fallbacks: t.fallbacks },
193
193
  ...t.maxTokens === void 0 ? {} : { maxTokens: t.maxTokens },
194
- ...t.providerOptions === void 0 ? {} : { providerOptions: t.providerOptions }
195
- }).pipe(m.tap((e) => D(t, r, "generateText", e, i.rendered)), m.tap(() => O(t, i.rendered)), m.map((e) => ({
194
+ ...t.providerOptions === void 0 ? {} : { providerOptions: t.providerOptions },
195
+ ...t.tools === void 0 ? {} : { tools: t.tools },
196
+ ...t.maxSteps === void 0 ? {} : { maxSteps: t.maxSteps },
197
+ ...t.toolContext === void 0 ? {} : { toolContext: t.toolContext }
198
+ }).pipe(h.tap((e) => O(t, r, "generateText", e, i.rendered)), h.tap(() => k(t, i.rendered)), h.map((e) => ({
196
199
  text: e.text,
197
200
  inputTokens: e.usage.inputTokens ?? null,
198
201
  outputTokens: e.usage.outputTokens ?? null,
199
202
  totalTokens: e.usage.totalTokens ?? null
200
203
  })))
201
204
  }));
202
- }, z = h.Struct({
203
- text: h.String,
204
- language: h.optional(h.String),
205
- durationSec: h.optional(h.Number)
206
- }), B = (t) => {
205
+ }, B = g.Struct({
206
+ text: g.String,
207
+ language: g.optional(g.String),
208
+ durationSec: g.optional(g.Number)
209
+ }), V = (t) => {
207
210
  let n = t.provider ?? e(), r = {
208
211
  source: t.source,
209
212
  ...t.language === void 0 ? {} : { language: t.language },
@@ -211,54 +214,65 @@ var x = {
211
214
  ...t.diarize === void 0 ? {} : { diarize: t.diarize },
212
215
  ...t.translateToEnglish === void 0 ? {} : { translateToEnglish: t.translateToEnglish }
213
216
  }, i = {
214
- ...E(n),
217
+ ...D(n),
215
218
  operation: "transcribe",
216
219
  offloaded: t.offload === !0
217
- }, a = (e) => t.budget === void 0 ? e : m.zipRight(I(t), e);
218
- return t.offload === !0 ? a(P(t, n, "transcription", null, i, {
220
+ }, a = (e) => t.budget === void 0 ? e : h.zipRight(L(t), e);
221
+ return t.offload === !0 ? a(F(t, n, "transcription", null, i, {
219
222
  text: "",
220
223
  system: void 0,
221
224
  rendered: void 0
222
- }, r)) : a(y({
225
+ }, r)) : a(b({
223
226
  name: t.name,
224
- success: z,
227
+ success: B,
225
228
  input: i,
226
- retry: t.retry ?? x,
227
- execute: o({
229
+ retry: t.retry ?? S,
230
+ execute: s({
228
231
  ...r,
229
232
  provider: n,
230
233
  ...t.resolveRef === void 0 ? {} : { resolveRef: t.resolveRef }
231
- }).pipe(m.map((e) => ({
234
+ }).pipe(h.map((e) => ({
232
235
  text: e.text,
233
236
  ...e.language === void 0 ? {} : { language: e.language },
234
237
  ...e.durationSec === void 0 ? {} : { durationSec: e.durationSec }
235
238
  })))
236
239
  }));
237
- }, V = (t) => {
238
- let n = t.provider ?? e(), r = T(t), i = {
239
- ...E(n),
240
+ }, H = (t) => {
241
+ let n = t.provider ?? e(), i = E(t), a = {
242
+ ...D(n),
240
243
  operation: "generateObject",
241
244
  offloaded: t.offload === !0,
242
- ...w(r.text, r.system, t.recordPrompt ?? "digest", r.rendered)
243
- }, o = (e) => t.budget === void 0 ? e : m.zipRight(I(t), e);
244
- return t.offload === !0 ? o(m.gen(function* () {
245
- let e = yield* a(t.schema, "aiObjectStep"), o = yield* P(t, n, "object", e, i, r);
246
- return yield* h.decodeUnknown(t.schema)(o);
247
- })) : o(y({
245
+ ...T(i.text, i.system, t.recordPrompt ?? "digest", i.rendered)
246
+ }, s = (e) => t.budget === void 0 ? e : h.zipRight(L(t), e);
247
+ return t.offload === !0 ? s(h.gen(function* () {
248
+ let e = yield* o(t.schema, "aiObjectStep"), r = yield* F(t, n, "object", e, a, i);
249
+ return yield* g.decodeUnknown(t.schema)(r);
250
+ })) : s(b({
248
251
  name: t.name,
249
252
  success: t.schema,
250
- input: i,
251
- retry: t.retry ?? x,
252
- execute: f({
253
- prompt: r.text,
253
+ input: a,
254
+ retry: t.retry ?? S,
255
+ execute: (t.tools === void 0 ? p({
256
+ prompt: i.text,
254
257
  schema: t.schema,
255
258
  provider: n,
256
- ...r.system === void 0 ? {} : { system: r.system },
259
+ ...i.system === void 0 ? {} : { system: i.system },
260
+ ...t.fallbacks === void 0 ? {} : { fallbacks: t.fallbacks },
261
+ ...t.maxTokens === void 0 ? {} : { maxTokens: t.maxTokens },
262
+ ...t.providerOptions === void 0 ? {} : { providerOptions: t.providerOptions }
263
+ }) : r({
264
+ prompt: i.text,
265
+ schema: t.schema,
266
+ provider: n,
267
+ tools: t.tools,
268
+ ...t.maxSteps === void 0 ? {} : { maxSteps: t.maxSteps },
269
+ ...t.toolContext === void 0 ? {} : { toolContext: t.toolContext },
270
+ ...i.system === void 0 ? {} : { system: i.system },
257
271
  ...t.fallbacks === void 0 ? {} : { fallbacks: t.fallbacks },
258
272
  ...t.maxTokens === void 0 ? {} : { maxTokens: t.maxTokens },
259
273
  ...t.providerOptions === void 0 ? {} : { providerOptions: t.providerOptions }
260
- }).pipe(m.tap((e) => D(t, n, "generateObject", e, r.rendered)), m.tap(() => O(t, r.rendered)), m.map((e) => e.object))
274
+ })).pipe(h.tap((e) => O(t, n, "generateObject", e, i.rendered)), h.tap(() => k(t, i.rendered)), h.map((e) => e.object))
261
275
  }));
262
276
  };
263
277
  //#endregion
264
- export { x as AI_STEP_RETRY, F as AiBudgetMisuseError, j as AiOffloadError, M as AiOffloadMisuseError, C as DEFAULT_AI_BUDGET_NAME, S as DEFAULT_OFFLOAD_TIMEOUT_MS, z as TranscriptionStepResult, V as aiObjectStep, R as aiStep, s as promptDigest, w as promptRecordFor, T as resolveStepPrompt, B as transcribeStep };
278
+ export { S as AI_STEP_RETRY, I as AiBudgetMisuseError, M as AiOffloadError, N as AiOffloadMisuseError, w as DEFAULT_AI_BUDGET_NAME, C as DEFAULT_OFFLOAD_TIMEOUT_MS, B as TranscriptionStepResult, H as aiObjectStep, z as aiStep, c as promptDigest, T as promptRecordFor, E as resolveStepPrompt, V as transcribeStep };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voltro/ai",
3
- "version": "0.63.0",
3
+ "version": "0.64.0",
4
4
  "description": "Effect-native AI primitives — generateText / generateObject / streamText, tools, agents, media generation, cost tracking + budgets, and provider fallback.",
5
5
  "keywords": [
6
6
  "voltro",
@@ -57,10 +57,10 @@
57
57
  "@ai-sdk/gateway": "^4.0.47",
58
58
  "@ai-sdk/openai": "^4.0.37",
59
59
  "@ai-sdk/provider": "^4.0.7",
60
- "@voltro/cache": "0.63.0",
61
- "@voltro/database": "0.63.0",
62
- "@voltro/protocol": "0.63.0",
63
- "@voltro/workflow": "0.63.0",
60
+ "@voltro/cache": "0.64.0",
61
+ "@voltro/database": "0.64.0",
62
+ "@voltro/protocol": "0.64.0",
63
+ "@voltro/workflow": "0.64.0",
64
64
  "ai": "^7.0.59"
65
65
  },
66
66
  "peerDependencies": {
@@ -1,46 +0,0 @@
1
- import { Schema as e } from "effect";
2
- import { defineAction as t, defineQuery as n } from "@voltro/protocol";
3
- //#region src/agentConstants.ts
4
- var r = "_voltro_agent_threads", i = "_voltro_agent_messages", a = e.Struct({ prompt: e.String }), o = "@voltro/ai/AgentDescriptor", s = (e) => ({
5
- _brand: o,
6
- name: e.name,
7
- ...e.input === void 0 ? {} : { input: e.input }
8
- }), c = (e) => typeof e == "object" && !!e && e._brand === o, l = (e) => e.input ?? a, u = e.Struct({ type: e.String }, {
9
- key: e.String,
10
- value: e.Unknown
11
- }), d = e.Struct({
12
- id: e.String,
13
- threadId: e.String,
14
- role: e.String,
15
- content: e.String,
16
- streaming: e.Boolean,
17
- order: e.Number,
18
- stepOrder: e.Number,
19
- parts: e.Array(u)
20
- }), f = (t) => {
21
- let n = l(t), r = e.Struct({
22
- threadId: e.String,
23
- order: e.Number
24
- });
25
- try {
26
- return e.extend(n, r);
27
- } catch {
28
- return r;
29
- }
30
- }, p = (r) => ({
31
- send: t({
32
- name: `${r.name}.send`,
33
- input: f(r),
34
- output: e.Struct({ text: e.String }),
35
- openAccess: "the synthesized agent chat surface serves any session this app authenticates; defineAgent declares no per-agent guard vocabulary today"
36
- }),
37
- messages: n({
38
- name: `${r.name}.messages`,
39
- input: e.Struct({ threadId: e.String }),
40
- output: e.Array(d),
41
- source: i,
42
- openAccess: "the synthesized agent chat surface serves any session this app authenticates; messages are keyed by the caller-supplied threadId"
43
- })
44
- });
45
- //#endregion
46
- export { c as a, s as i, d as n, i as o, p as r, r as s, l as t };