@voltro/ai 0.84.0 → 0.86.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.
Files changed (61) hide show
  1. package/CHANGELOG.md +1215 -0
  2. package/THIRD-PARTY-NOTICES.md +5 -151
  3. package/dist/agent.d.ts +34 -41
  4. package/dist/agent.js +64 -2
  5. package/dist/agentConstants.js +4 -0
  6. package/dist/agentExecutor.js +51 -0
  7. package/dist/api.js +199 -0
  8. package/dist/appTools.js +80 -0
  9. package/dist/budget.js +201 -0
  10. package/dist/callEvidence.js +51 -0
  11. package/dist/copilot.js +126 -0
  12. package/dist/cost.js +242 -0
  13. package/dist/embed.js +41 -0
  14. package/dist/embeddingProvider.js +51 -0
  15. package/dist/eval.js +130 -0
  16. package/dist/events.d.ts +171 -168
  17. package/dist/events.js +81 -2
  18. package/dist/executableModalities.js +13 -0
  19. package/dist/gateway.js +58 -0
  20. package/dist/gatewayCatalog.js +47 -0
  21. package/dist/gatewayMedia.js +88 -0
  22. package/dist/index.d.ts +328 -326
  23. package/dist/index.js +42 -2581
  24. package/dist/inferenceDispatch.js +493 -0
  25. package/dist/inferenceQueue.js +96 -0
  26. package/dist/jsonOutputValidation.js +27 -0
  27. package/dist/mcpClient.js +332 -0
  28. package/dist/mcpTools.js +80 -0
  29. package/dist/media.js +182 -0
  30. package/dist/mediaBytes.js +19 -0
  31. package/dist/mediaCall.js +13 -0
  32. package/dist/mediaTaskProvider.js +16 -0
  33. package/dist/middleware.js +32 -0
  34. package/dist/observe.js +52 -0
  35. package/dist/prompts.js +103 -0
  36. package/dist/provider.js +303 -0
  37. package/dist/realtimeEvent.js +97 -0
  38. package/dist/realtimeSession.js +154 -0
  39. package/dist/rerank.js +61 -0
  40. package/dist/resumableStream.js +321 -0
  41. package/dist/retrieveReranked.js +16 -0
  42. package/dist/runAndPersist.js +148 -0
  43. package/dist/semanticCache.js +66 -0
  44. package/dist/speechProvider.js +16 -0
  45. package/dist/streamRegistry.js +14 -0
  46. package/dist/streamText.js +170 -0
  47. package/dist/streamTranscribe.js +74 -0
  48. package/dist/streamWakeups.js +44 -0
  49. package/dist/structuredEvidence.js +48 -0
  50. package/dist/test.js +1 -1
  51. package/dist/threads.js +92 -0
  52. package/dist/tools.js +68 -0
  53. package/dist/transcribe.js +64 -0
  54. package/dist/transcriptionEvent.js +46 -0
  55. package/dist/workflow.d.ts +12 -10
  56. package/dist/workflow.js +117 -112
  57. package/package.json +6 -6
  58. package/dist/agentDescriptor-DuxvWGDi.js +0 -63
  59. package/dist/agentEvent-BuXA7sRt.js +0 -152
  60. package/dist/inferenceQueue-BmtEm3YI.js +0 -1061
  61. package/dist/provider-BnemgE4D.js +0 -409
@@ -1,409 +0,0 @@
1
- import { anthropic as e, createAnthropic as t } from "@ai-sdk/anthropic";
2
- import { createOpenAI as n, openai as r } from "@ai-sdk/openai";
3
- import { createGateway as i, gateway as a } from "@ai-sdk/gateway";
4
- import { defaultSettingsMiddleware as o, extractReasoningMiddleware as s, simulateStreamingMiddleware as c, wrapLanguageModel as l } from "ai";
5
- //#region src/middleware.ts
6
- var u = [], d = (...e) => {
7
- let t = u;
8
- return u = e, t;
9
- }, f = () => u, p = () => {
10
- u = [];
11
- }, m = (e, t) => {
12
- let n = t === void 0 ? [] : Array.isArray(t) ? t : [t], r = [...u, ...n];
13
- return r.length === 0 ? e : l({
14
- model: e,
15
- middleware: r
16
- });
17
- }, h = (e) => {
18
- let t = e?.log ?? ((e) => console.log(`[ai] ${e.phase} model=${e.model}`, e.usage ?? ""));
19
- return {
20
- wrapGenerate: async ({ doGenerate: e, model: n }) => {
21
- let r = await e();
22
- return t({
23
- phase: "generate",
24
- model: n.modelId,
25
- usage: r.usage
26
- }), r;
27
- },
28
- wrapStream: async ({ doStream: e, model: n }) => (t({
29
- phase: "stream",
30
- model: n.modelId
31
- }), e())
32
- };
33
- }, g = (e, t) => {
34
- let n = Object.fromEntries(Object.entries(t).filter(([, e]) => e !== void 0));
35
- return {
36
- ...e,
37
- fetch: async (t, r) => {
38
- let i = e.fetch ?? globalThis.fetch;
39
- if (Object.keys(n).length === 0) return i(t, r);
40
- if (r?.method !== "POST" || typeof r.body != "string") throw Error("Gateway media: expected a JSON POST to preserve the requested parameters");
41
- let a;
42
- try {
43
- a = JSON.parse(r.body);
44
- } catch {
45
- throw Error("Gateway media: expected a JSON object to preserve the requested parameters");
46
- }
47
- if (typeof a != "object" || !a || Array.isArray(a)) throw Error("Gateway media: expected a JSON object to preserve the requested parameters");
48
- return i(t, {
49
- ...r,
50
- body: JSON.stringify({
51
- ...a,
52
- ...n
53
- })
54
- });
55
- }
56
- };
57
- }, _ = (e, t) => {
58
- let n = Reflect.get(e, t, e);
59
- return typeof n == "function" && t !== "constructor" ? n.bind(e) : n;
60
- }, v = (e, t) => {
61
- let n = i(e).image(t), r = (n) => i(g(e, {
62
- seed: n.seed,
63
- size: n.size,
64
- aspectRatio: n.aspectRatio
65
- })).image(t).doGenerate(n);
66
- return new Proxy(n, { get: (e, t) => t === "doGenerate" ? r : _(e, t) });
67
- }, y = (e, t) => {
68
- let n = i(e).video(t), r = n.doGenerate === void 0 ? void 0 : (n) => {
69
- let r = i(g(e, {
70
- seed: n.seed,
71
- duration: n.duration,
72
- fps: n.fps,
73
- aspectRatio: n.aspectRatio,
74
- resolution: n.resolution
75
- })).video(t);
76
- if (!r.doGenerate) throw Error("Gateway video does not implement doGenerate");
77
- return r.doGenerate(n);
78
- }, a = n.doStart === void 0 ? void 0 : (n) => {
79
- let r = i(g(e, {
80
- seed: n.seed,
81
- duration: n.duration,
82
- fps: n.fps,
83
- aspectRatio: n.aspectRatio,
84
- resolution: n.resolution
85
- })).video(t);
86
- if (!r.doStart) throw Error("Gateway video does not implement doStart");
87
- return r.doStart(n);
88
- };
89
- return new Proxy(n, { get: (e, t) => t === "doGenerate" ? r : t === "doStart" ? a : _(e, t) });
90
- }, b = 134217728, x = (e, t = process.env) => {
91
- if (e !== void 0) return e;
92
- let n = Number(t.VOLTRO_AI_MEDIA_MAX_RESPONSE_BYTES);
93
- return Number.isFinite(n) && n > 0 ? Math.floor(n) : b;
94
- }, S = (e) => `gateway media response exceeded maxResponseBytes (${e}); it was not read further. Raise \`maxResponseBytes\` on the gateway provider config, or VOLTRO_AI_MEDIA_MAX_RESPONSE_BYTES.`, C = (e) => Response.json({ error: {
95
- message: S(e),
96
- type: "response_too_large"
97
- } }, { status: 413 }), w = async (e, t) => {
98
- let n = Number(e.headers.get("content-length"));
99
- if (Number.isFinite(n) && n > t) return e.body?.cancel(), C(t);
100
- if (e.body === null) return e;
101
- let r = e.body.getReader(), i = [], a = 0;
102
- for (;;) {
103
- let { done: e, value: n } = await r.read();
104
- if (e) break;
105
- if (a += n.byteLength, a > t) return r.cancel(), C(t);
106
- i.push(new Uint8Array(n));
107
- }
108
- return new Response(new Blob(i), {
109
- status: e.status,
110
- statusText: e.statusText,
111
- headers: e.headers
112
- });
113
- }, T = (e, t) => ({
114
- ...e,
115
- fetch: async (n, r) => w(await (e.fetch ?? globalThis.fetch)(n, r), t)
116
- }), E = {
117
- inputTokens: {
118
- total: 0,
119
- noCache: 0,
120
- cacheRead: 0,
121
- cacheWrite: 0
122
- },
123
- outputTokens: {
124
- total: 0,
125
- text: 0,
126
- reasoning: 0
127
- }
128
- }, D = (e) => ({
129
- unified: e,
130
- raw: void 0
131
- }), O = class {
132
- turns;
133
- cursor = 0;
134
- calls = [];
135
- constructor(e) {
136
- this.turns = e.length > 0 ? e : [{ text: "" }];
137
- }
138
- record(e, t) {
139
- this.calls.push({
140
- prompt: e,
141
- tools: t
142
- });
143
- }
144
- next() {
145
- let e = this.turns[Math.min(this.cursor, this.turns.length - 1)];
146
- return this.cursor += 1, e;
147
- }
148
- reset() {
149
- this.cursor = 0, this.calls.length = 0;
150
- }
151
- }, k = (e) => (e.toolCalls ?? []).map((e, t) => ({
152
- type: "tool-call",
153
- toolCallId: `mock_tool_${t}`,
154
- toolName: e.name,
155
- input: JSON.stringify(e.input ?? {})
156
- })), A = (e) => (e.sources ?? []).map((e, t) => e.sourceType === "document" ? {
157
- type: "source",
158
- sourceType: "document",
159
- id: e.id ?? `mock_src_${t}`,
160
- mediaType: e.mediaType ?? "application/pdf",
161
- title: e.title ?? "document",
162
- ...e.filename === void 0 ? {} : { filename: e.filename }
163
- } : {
164
- type: "source",
165
- sourceType: "url",
166
- id: e.id ?? `mock_src_${t}`,
167
- url: e.url ?? "https://example.com",
168
- ...e.title === void 0 ? {} : { title: e.title }
169
- }), j = (e) => (e.files ?? []).map((e) => ({
170
- type: "file",
171
- mediaType: e.mediaType,
172
- data: {
173
- type: "data",
174
- data: e.data
175
- }
176
- })), M = (e) => [
177
- {
178
- type: "text-start",
179
- id: "0"
180
- },
181
- ...e.split(/(\s+)/).filter((e) => e.length > 0).map((e) => ({
182
- type: "text-delta",
183
- id: "0",
184
- delta: e
185
- })),
186
- {
187
- type: "text-end",
188
- id: "0"
189
- }
190
- ], N = (e) => e.length === 0 ? [] : [
191
- {
192
- type: "reasoning-start",
193
- id: "r0"
194
- },
195
- {
196
- type: "reasoning-delta",
197
- id: "r0",
198
- delta: e
199
- },
200
- {
201
- type: "reasoning-end",
202
- id: "r0"
203
- }
204
- ], P = (e, t, n, r) => ({
205
- specificationVersion: "v4",
206
- provider: "mock",
207
- modelId: e,
208
- supportedUrls: {},
209
- doGenerate: async ({ prompt: i, tools: a }) => {
210
- n?.record(i, (a ?? []).map((e) => e.name ?? ""));
211
- let o = n?.next();
212
- if (o?.error) throw Error(o.error.message);
213
- let s = JSON.stringify(i).slice(0, 80), c = o?.toolCalls ?? [];
214
- return c.length > 0 ? {
215
- content: c.map((e, t) => ({
216
- type: "tool-call",
217
- toolCallId: `mock_tool_${t}`,
218
- toolName: e.name,
219
- input: JSON.stringify(e.input ?? {})
220
- })),
221
- finishReason: D("tool-calls"),
222
- usage: E,
223
- warnings: []
224
- } : {
225
- content: [{
226
- type: "text",
227
- text: o?.text ?? t ?? `[mock(${e})] ${s}`
228
- }],
229
- finishReason: D("stop"),
230
- usage: E,
231
- warnings: [],
232
- ...r === void 0 ? {} : { providerMetadata: r }
233
- };
234
- },
235
- doStream: async ({ prompt: e, tools: r }) => {
236
- n?.record(e, (r ?? []).map((e) => e.name ?? ""));
237
- let i = n?.next(), a = (i?.toolCalls?.length ?? 0) > 0, o = i?.text ?? (n ? "" : t ?? "[mock] streamed response"), s = [{
238
- type: "stream-start",
239
- warnings: []
240
- }];
241
- return i?.error ? (s.push({
242
- type: "error",
243
- error: Error(i.error.message)
244
- }), s.push({
245
- type: "finish",
246
- finishReason: D("error"),
247
- usage: E
248
- })) : (s.push(...N(i?.reasoning ?? "")), o.length > 0 && s.push(...M(o)), s.push(...A(i ?? {})), s.push(...j(i ?? {})), s.push(...k(i ?? {})), s.push({
249
- type: "finish",
250
- finishReason: D(a ? "tool-calls" : "stop"),
251
- usage: E
252
- })), { stream: new ReadableStream({ start(e) {
253
- for (let t of s) e.enqueue(t);
254
- e.close();
255
- } }) };
256
- }
257
- }), F = "iVBORw0KGgo=", I = "SUQzBAAAAAAAAA==", L = "video/mp4", R = "mock transcript", z = (e, t) => ({
258
- specificationVersion: "v4",
259
- provider: "mock",
260
- modelId: e,
261
- maxImagesPerCall: 8,
262
- doGenerate: async ({ n }) => ({
263
- images: Array.from({ length: Math.max(1, n) }, () => t),
264
- warnings: [],
265
- response: {
266
- timestamp: /* @__PURE__ */ new Date(),
267
- modelId: e,
268
- headers: void 0
269
- },
270
- usage: {
271
- inputTokens: 0,
272
- outputTokens: 0,
273
- totalTokens: 0
274
- }
275
- })
276
- }), B = (e, t, n) => ({
277
- specificationVersion: "v4",
278
- provider: "mock",
279
- modelId: e,
280
- doGenerate: async () => ({
281
- audio: t,
282
- warnings: [],
283
- response: {
284
- timestamp: /* @__PURE__ */ new Date(),
285
- modelId: e
286
- },
287
- ...n === void 0 ? {} : { providerMetadata: n }
288
- })
289
- }), V = (e, t, n) => ({
290
- specificationVersion: "v4",
291
- provider: "mock",
292
- modelId: e,
293
- doGenerate: async () => ({
294
- text: t,
295
- segments: [],
296
- language: "en",
297
- durationInSeconds: 1,
298
- warnings: [],
299
- response: {
300
- timestamp: /* @__PURE__ */ new Date(),
301
- modelId: e,
302
- headers: {},
303
- body: void 0
304
- },
305
- ...n === void 0 ? {} : { providerMetadata: n }
306
- })
307
- }), H = (e, t, n) => ({
308
- specificationVersion: "v4",
309
- provider: "mock",
310
- modelId: e,
311
- maxVideosPerCall: 1,
312
- doGenerate: async () => ({
313
- videos: [t],
314
- warnings: [],
315
- response: {
316
- timestamp: /* @__PURE__ */ new Date(),
317
- modelId: e,
318
- headers: void 0
319
- },
320
- ...n === void 0 ? {} : { providerMetadata: n }
321
- })
322
- }), U = (e) => e.apiKey !== void 0 || e.baseURL !== void 0, W = (e) => ({
323
- ...e.apiKey === void 0 ? {} : { apiKey: e.apiKey },
324
- ...e.baseURL === void 0 ? {} : { baseURL: e.baseURL }
325
- }), G = (o, s) => m((() => {
326
- switch (o.name) {
327
- case "mock": return P(o.model ?? "mock", o.mockText, o.script, o.providerMetadata);
328
- case "anthropic": return U(o) ? t(W(o))(o.model) : e(o.model);
329
- case "openai": return U(o) ? n(W(o))(o.model) : r(o.model);
330
- case "gateway": return U(o) ? i(W(o))(o.model) : a(o.model);
331
- }
332
- })(), s), K = (e) => {
333
- switch (e.name) {
334
- case "mock": return z(e.model ?? "mock", e.mockMedia?.imageBase64 ?? F);
335
- case "openai": return U(e) ? n(W(e)).image(e.model) : r.image(e.model);
336
- case "gateway": return v(T(W(e), x(e.maxResponseBytes)), e.model);
337
- case "anthropic": throw Error("Provider 'anthropic' does not support image generation. Use 'openai' or 'gateway'.");
338
- }
339
- }, q = (e) => {
340
- switch (e.name) {
341
- case "mock": return B(e.model ?? "mock", e.mockMedia?.audioBase64 ?? I, e.providerMetadata);
342
- case "openai": return U(e) ? n(W(e)).speech(e.model) : r.speech(e.model);
343
- case "gateway": return i(T(W(e), x(e.maxResponseBytes))).speech(e.model);
344
- case "anthropic": throw Error("Provider 'anthropic' does not support speech generation. Use 'openai' or 'gateway'.");
345
- }
346
- }, J = (e) => {
347
- switch (e.name) {
348
- case "mock": return V(e.model ?? "mock", e.mockMedia?.transcript ?? R, e.providerMetadata);
349
- case "openai": return U(e) ? n(W(e)).transcription(e.model) : r.transcription(e.model);
350
- case "gateway": return i(T(W(e), x(e.maxResponseBytes))).transcription(e.model);
351
- case "anthropic": throw Error("Provider 'anthropic' does not support transcription. Use 'openai' or 'gateway'.");
352
- }
353
- }, Y = (e) => {
354
- switch (e.name) {
355
- case "mock": {
356
- let t = e.mockMedia, n = t?.videoBase64 === void 0 ? {
357
- type: "url",
358
- url: t?.videoUrl ?? `https://mock.local/${e.model ?? "mock"}.mp4`,
359
- mediaType: L
360
- } : {
361
- type: "base64",
362
- data: t.videoBase64,
363
- mediaType: L
364
- };
365
- return H(e.model ?? "mock", n, e.providerMetadata);
366
- }
367
- case "gateway": return y(T(W(e), x(e.maxResponseBytes)), e.model);
368
- case "openai": throw Error("Provider 'openai' does not support video generation. Use 'gateway'.");
369
- case "anthropic": throw Error("Provider 'anthropic' does not support video generation. Use 'gateway'.");
370
- }
371
- }, X = null, Z = (e) => {
372
- let t = X;
373
- return X = e, t;
374
- }, Q = () => X, $ = (e) => {
375
- switch (e.toLowerCase()) {
376
- case "anthropic": return "ANTHROPIC_API_KEY";
377
- case "openai": return "OPENAI_API_KEY";
378
- case "gateway": return "AI_GATEWAY_API_KEY";
379
- default: return;
380
- }
381
- }, ee = (e = process.env) => {
382
- if (X) return X;
383
- let t = (e.AI_PROVIDER ?? "mock").toLowerCase(), n = e.AI_MODEL;
384
- switch (t) {
385
- case "mock": return {
386
- name: "mock",
387
- model: n ?? "mock"
388
- };
389
- case "anthropic": return {
390
- name: "anthropic",
391
- model: n ?? "claude-opus-4-8"
392
- };
393
- case "openai": return {
394
- name: "openai",
395
- model: n ?? "gpt-5.5"
396
- };
397
- case "gateway": {
398
- let e = n === void 0 ? -1 : n.indexOf("/");
399
- if (n === void 0 || e <= 0 || e === n.length - 1) throw Error("AI_PROVIDER=gateway requires AI_MODEL set to a 'creator/model' id, e.g. 'openai/gpt-5.5'");
400
- return {
401
- name: "gateway",
402
- model: n
403
- };
404
- }
405
- default: throw Error(`Unknown AI_PROVIDER '${t}'. Expected one of: mock, anthropic, openai, gateway.`);
406
- }
407
- };
408
- //#endregion
409
- export { d as _, K as a, J as c, m as d, p as f, h as g, f as h, $ as i, Y as l, s as m, Q as n, G as o, o as p, ee as r, q as s, O as t, Z as u, c as v };