@voltro/ai 0.85.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 (60) hide show
  1. package/CHANGELOG.md +666 -0
  2. package/THIRD-PARTY-NOTICES.md +5 -33
  3. package/dist/agent.js +64 -2
  4. package/dist/agentConstants.js +4 -0
  5. package/dist/agentExecutor.js +51 -0
  6. package/dist/api.js +199 -0
  7. package/dist/appTools.js +80 -0
  8. package/dist/budget.js +201 -0
  9. package/dist/callEvidence.js +51 -0
  10. package/dist/copilot.js +126 -0
  11. package/dist/cost.js +242 -0
  12. package/dist/embed.js +41 -0
  13. package/dist/embeddingProvider.js +51 -0
  14. package/dist/eval.js +130 -0
  15. package/dist/events.d.ts +4 -0
  16. package/dist/events.js +81 -2
  17. package/dist/executableModalities.js +13 -0
  18. package/dist/gateway.js +58 -0
  19. package/dist/gatewayCatalog.js +47 -0
  20. package/dist/gatewayMedia.js +88 -0
  21. package/dist/index.d.ts +11 -0
  22. package/dist/index.js +42 -2750
  23. package/dist/inferenceDispatch.js +493 -0
  24. package/dist/inferenceQueue.js +96 -0
  25. package/dist/jsonOutputValidation.js +27 -0
  26. package/dist/mcpClient.js +332 -0
  27. package/dist/mcpTools.js +80 -0
  28. package/dist/media.js +182 -0
  29. package/dist/mediaBytes.js +19 -0
  30. package/dist/mediaCall.js +13 -0
  31. package/dist/mediaTaskProvider.js +16 -0
  32. package/dist/middleware.js +32 -0
  33. package/dist/observe.js +52 -0
  34. package/dist/prompts.js +103 -0
  35. package/dist/provider.js +303 -0
  36. package/dist/realtimeEvent.js +97 -0
  37. package/dist/realtimeSession.js +154 -0
  38. package/dist/rerank.js +61 -0
  39. package/dist/resumableStream.js +321 -0
  40. package/dist/retrieveReranked.js +16 -0
  41. package/dist/runAndPersist.js +148 -0
  42. package/dist/semanticCache.js +66 -0
  43. package/dist/speechProvider.js +16 -0
  44. package/dist/streamRegistry.js +14 -0
  45. package/dist/streamText.js +170 -0
  46. package/dist/streamTranscribe.js +74 -0
  47. package/dist/streamWakeups.js +44 -0
  48. package/dist/structuredEvidence.js +48 -0
  49. package/dist/test.js +1 -1
  50. package/dist/threads.js +92 -0
  51. package/dist/tools.js +68 -0
  52. package/dist/transcribe.js +64 -0
  53. package/dist/transcriptionEvent.js +46 -0
  54. package/dist/workflow.d.ts +2 -0
  55. package/dist/workflow.js +115 -110
  56. package/package.json +5 -5
  57. package/dist/agentDescriptor-DhoiXVqO.js +0 -63
  58. package/dist/agentEvent-Bl4egdM5.js +0 -211
  59. package/dist/inferenceQueue-DcEulZep.js +0 -1077
  60. package/dist/provider-BnemgE4D.js +0 -409
package/dist/events.js CHANGED
@@ -1,2 +1,81 @@
1
- import { a as e, i as t, n, o as r, r as i, s as a, t as o } from "./agentEvent-Bl4egdM5.js";
2
- export { o as AgentErrorCode, n as AgentEvent, t as RealtimeClientEvent, e as RealtimeServerEvent, i as SeqEvent, r as TranscriptionStreamError, a as TranscriptionStreamEvent };
1
+ import { TranscriptionStreamError as e, TranscriptionStreamEvent as t } from "./transcriptionEvent.js";
2
+ import { RealtimeClientEvent as n, RealtimeServerEvent as r } from "./realtimeEvent.js";
3
+ import { Schema as i } from "effect";
4
+ //#region src/agentEvent.ts
5
+ var a = i.Literals([
6
+ "provider",
7
+ "tool",
8
+ "timeout",
9
+ "cancelled",
10
+ "decode",
11
+ "internal"
12
+ ]), o = i.Struct({
13
+ inputTokens: i.optional(i.Number),
14
+ outputTokens: i.optional(i.Number),
15
+ totalTokens: i.optional(i.Number)
16
+ }), s = i.Union([
17
+ i.Struct({
18
+ _tag: i.Literal("token"),
19
+ text: i.String
20
+ }),
21
+ i.Struct({
22
+ _tag: i.Literal("reasoning"),
23
+ text: i.String
24
+ }),
25
+ i.Struct({
26
+ _tag: i.Literal("toolCall"),
27
+ id: i.String,
28
+ name: i.String,
29
+ input: i.Unknown,
30
+ execution: i.optional(i.Literal("client"))
31
+ }),
32
+ i.Struct({
33
+ _tag: i.Literal("toolResult"),
34
+ id: i.String,
35
+ name: i.String,
36
+ output: i.optional(i.Unknown),
37
+ error: i.optional(i.String)
38
+ }),
39
+ i.Struct({
40
+ _tag: i.Literal("source"),
41
+ sourceType: i.Literals(["url", "document"]),
42
+ id: i.String,
43
+ url: i.optional(i.String),
44
+ title: i.optional(i.String),
45
+ mediaType: i.optional(i.String),
46
+ filename: i.optional(i.String),
47
+ providerMetadata: i.optional(i.Unknown)
48
+ }),
49
+ i.Struct({
50
+ _tag: i.Literal("file"),
51
+ mediaType: i.String,
52
+ data: i.String,
53
+ providerMetadata: i.optional(i.Unknown)
54
+ }),
55
+ i.Struct({
56
+ _tag: i.Literal("stepMetadata"),
57
+ step: i.Int.pipe(i.check(i.isGreaterThanOrEqualTo(0))),
58
+ providerMetadata: i.Unknown
59
+ }),
60
+ i.Struct({
61
+ _tag: i.Literal("message"),
62
+ role: i.String,
63
+ content: i.String
64
+ }),
65
+ i.Struct({
66
+ _tag: i.Literal("error"),
67
+ code: a,
68
+ message: i.String,
69
+ retryable: i.Boolean
70
+ }),
71
+ i.Struct({
72
+ _tag: i.Literal("done"),
73
+ finishReason: i.String,
74
+ usage: o
75
+ })
76
+ ]), c = i.Struct({
77
+ seq: i.Number,
78
+ event: s
79
+ });
80
+ //#endregion
81
+ export { a as AgentErrorCode, s as AgentEvent, n as RealtimeClientEvent, r as RealtimeServerEvent, c as SeqEvent, e as TranscriptionStreamError, t as TranscriptionStreamEvent };
@@ -0,0 +1,13 @@
1
+ //#region src/executableModalities.ts
2
+ var e = {
3
+ language: "generateText / generateObject / streamText",
4
+ embedding: "embed / embedMany",
5
+ image: "generateImage",
6
+ video: "generateVideo",
7
+ speech: "generateSpeech",
8
+ reranking: "rerank",
9
+ transcription: "transcribe",
10
+ realtime: "defineRealtimeSession / resolveRealtimeModel"
11
+ }, t = () => new Set(Object.keys(e)), n = (e) => t().has(e.modality);
12
+ //#endregion
13
+ export { e as MODALITY_PRIMITIVE, n as canExecute, t as executableModalities };
@@ -0,0 +1,58 @@
1
+ import { capabilitiesOf as e, contextWindowOf as t, dataPolicyOf as n, knowledgeCutoffOf as r, maxOutputTokensOf as i, modalitiesOf as a, modalityOf as o, releasedAtOf as s } from "./gatewayCatalog.js";
2
+ import { createGateway as c, gateway as l } from "@ai-sdk/gateway";
3
+ //#region src/gateway.ts
4
+ var u = (e) => {
5
+ if (e === void 0) return;
6
+ let t = Number(e);
7
+ return Number.isFinite(t) ? t * 1e6 : void 0;
8
+ }, d = (e) => {
9
+ let t = u(e.pricing?.input), n = u(e.pricing?.output), r = u(e.pricing?.cachedInputTokens ?? void 0);
10
+ return {
11
+ id: e.id,
12
+ name: e.name,
13
+ ...e.description == null ? {} : { description: e.description },
14
+ modality: o({ model_type: e.modelType }),
15
+ ...t !== void 0 && n !== void 0 ? { pricing: {
16
+ inputPer1M: t,
17
+ outputPer1M: n,
18
+ ...r === void 0 ? {} : { cachedInputPer1M: r }
19
+ } } : {}
20
+ };
21
+ }, f = async (e = {}) => {
22
+ let t = (await (e.gatewayProvider ?? (e.apiKey !== void 0 || e.baseURL !== void 0 ? c({
23
+ ...e.apiKey === void 0 ? {} : { apiKey: e.apiKey },
24
+ ...e.baseURL === void 0 ? {} : { baseURL: e.baseURL }
25
+ }) : l)).getAvailableModels()).models.map(d);
26
+ return e.modality === void 0 ? t : t.filter((t) => t.modality === e.modality);
27
+ }, p = "https://ai-gateway.vercel.sh/v1", m = async (e = {}) => {
28
+ let t = (e.baseURL ?? p).replace(/\/+$/, ""), n = e.apiKey ?? process.env.AI_GATEWAY_API_KEY, r = await (e.fetchImpl ?? fetch)(`${t}/models`, { headers: {
29
+ accept: "application/json",
30
+ ...n === void 0 ? {} : { authorization: `Bearer ${n}` }
31
+ } });
32
+ if (!r.ok) throw Error(`gateway catalog: GET ${t}/models answered ${r.status}. Set AI_GATEWAY_API_KEY, or pass \`apiKey\`.`);
33
+ let i = await r.json(), a = (Array.isArray(i.data) ? i.data : Array.isArray(i.models) ? i.models : []).map(h);
34
+ return e.modality === void 0 ? a : a.filter((t) => t.modality === e.modality);
35
+ }, h = (c) => {
36
+ let l = c.pricing ?? {}, d = u(l.input), f = u(l.output), p = u(l.cachedInputTokens), m = t(c), h = i(c), g = s(c), _ = r(c);
37
+ return {
38
+ id: String(c.id ?? ""),
39
+ name: String(c.name ?? c.id ?? ""),
40
+ ...typeof c.description == "string" && c.description !== "" ? { description: c.description } : {},
41
+ modality: o(c),
42
+ ...d !== void 0 && f !== void 0 ? { pricing: {
43
+ inputPer1M: d,
44
+ outputPer1M: f,
45
+ ...p === void 0 ? {} : { cachedInputPer1M: p }
46
+ } } : {},
47
+ capabilities: e(c),
48
+ modalities: a(c),
49
+ ...m === void 0 ? {} : { contextWindow: m },
50
+ ...h === void 0 ? {} : { maxOutputTokens: h },
51
+ ...g === void 0 ? {} : { releasedAt: g },
52
+ ..._ === void 0 ? {} : { knowledgeCutoff: _ },
53
+ dataPolicy: n(c),
54
+ raw: c
55
+ };
56
+ };
57
+ //#endregion
58
+ export { h as fromRaw, f as getAvailableModels, m as readGatewayCatalog, d as toModelInfo };
@@ -0,0 +1,47 @@
1
+ //#region src/gatewayCatalog.ts
2
+ var e = (e) => Array.isArray(e) ? e.filter((e) => typeof e == "string") : [], t = (e) => typeof e == "number" && Number.isFinite(e) ? e : void 0, n = (e) => e === "all" || e === "some" ? e : "none", r = (e) => {
3
+ let n = t(e);
4
+ if (n === void 0) return;
5
+ let r = /* @__PURE__ */ new Date(n * 1e3);
6
+ return Number.isNaN(r.getTime()) ? void 0 : r.toISOString();
7
+ }, i = (t) => {
8
+ let n = new Set(e(t.tags)), r = new Set(e(t.supported_parameters)), i = t.modalities ?? {}, a = new Set(e(i.input)), o = new Set(e(i.output));
9
+ return {
10
+ vision: n.has("vision") || a.has("image"),
11
+ reasoning: n.has("reasoning") || r.has("reasoning"),
12
+ toolUse: n.has("tool-use") || r.has("tools"),
13
+ structuredOutput: n.has("structured-output") || r.has("response_format"),
14
+ webSearch: n.has("web-search") || r.has("web_search_options"),
15
+ caching: n.has("caching") || r.has("prompt_cache_key"),
16
+ imageOut: o.has("image"),
17
+ audioOut: o.has("audio"),
18
+ videoOut: o.has("video"),
19
+ audioIn: a.has("audio"),
20
+ videoIn: a.has("video"),
21
+ fileInput: a.has("file") || a.has("pdf")
22
+ };
23
+ }, a = (t) => {
24
+ let n = t.modalities ?? {};
25
+ return {
26
+ input: e(n.input),
27
+ output: e(n.output)
28
+ };
29
+ }, o = (e) => ({
30
+ zeroRetention: n(e.zdr),
31
+ noTraining: n(e.no_training)
32
+ }), s = (e) => t(e.context_window), c = (e) => t(e.max_tokens), l = (e) => r(e.released), u = (e) => typeof e.knowledge == "string" && e.knowledge !== "" ? e.knowledge : void 0, d = (e) => {
33
+ let t = e.model_type;
34
+ return typeof t == "string" && [
35
+ "language",
36
+ "embedding",
37
+ "image",
38
+ "video",
39
+ "realtime",
40
+ "reranking",
41
+ "speech",
42
+ "transcription",
43
+ "evaluation"
44
+ ].includes(t) ? t : "unknown";
45
+ };
46
+ //#endregion
47
+ export { i as capabilitiesOf, s as contextWindowOf, o as dataPolicyOf, u as knowledgeCutoffOf, c as maxOutputTokensOf, a as modalitiesOf, d as modalityOf, l as releasedAtOf };
@@ -0,0 +1,88 @@
1
+ import { createGateway as e } from "@ai-sdk/gateway";
2
+ //#region src/gatewayMedia.ts
3
+ var t = (e, t) => {
4
+ let n = Object.fromEntries(Object.entries(t).filter(([, e]) => e !== void 0));
5
+ return {
6
+ ...e,
7
+ fetch: async (t, r) => {
8
+ let i = e.fetch ?? globalThis.fetch;
9
+ if (Object.keys(n).length === 0) return i(t, r);
10
+ if (r?.method !== "POST" || typeof r.body != "string") throw Error("Gateway media: expected a JSON POST to preserve the requested parameters");
11
+ let a;
12
+ try {
13
+ a = JSON.parse(r.body);
14
+ } catch {
15
+ throw Error("Gateway media: expected a JSON object to preserve the requested parameters");
16
+ }
17
+ if (typeof a != "object" || !a || Array.isArray(a)) throw Error("Gateway media: expected a JSON object to preserve the requested parameters");
18
+ return i(t, {
19
+ ...r,
20
+ body: JSON.stringify({
21
+ ...a,
22
+ ...n
23
+ })
24
+ });
25
+ }
26
+ };
27
+ }, n = (e, t) => {
28
+ let n = Reflect.get(e, t, e);
29
+ return typeof n == "function" && t !== "constructor" ? n.bind(e) : n;
30
+ }, r = (r, i) => {
31
+ let a = e(r).image(i), o = (n) => e(t(r, {
32
+ seed: n.seed,
33
+ size: n.size,
34
+ aspectRatio: n.aspectRatio
35
+ })).image(i).doGenerate(n);
36
+ return new Proxy(a, { get: (e, t) => t === "doGenerate" ? o : n(e, t) });
37
+ }, i = (r, i) => {
38
+ let a = e(r).video(i), o = a.doGenerate === void 0 ? void 0 : (n) => {
39
+ let a = e(t(r, {
40
+ seed: n.seed,
41
+ duration: n.duration,
42
+ fps: n.fps,
43
+ aspectRatio: n.aspectRatio,
44
+ resolution: n.resolution
45
+ })).video(i);
46
+ if (!a.doGenerate) throw Error("Gateway video does not implement doGenerate");
47
+ return a.doGenerate(n);
48
+ }, s = a.doStart === void 0 ? void 0 : (n) => {
49
+ let a = e(t(r, {
50
+ seed: n.seed,
51
+ duration: n.duration,
52
+ fps: n.fps,
53
+ aspectRatio: n.aspectRatio,
54
+ resolution: n.resolution
55
+ })).video(i);
56
+ if (!a.doStart) throw Error("Gateway video does not implement doStart");
57
+ return a.doStart(n);
58
+ };
59
+ return new Proxy(a, { get: (e, t) => t === "doGenerate" ? o : t === "doStart" ? s : n(e, t) });
60
+ }, a = 134217728, o = (e, t = process.env) => {
61
+ if (e !== void 0) return e;
62
+ let n = Number(t.VOLTRO_AI_MEDIA_MAX_RESPONSE_BYTES);
63
+ return Number.isFinite(n) && n > 0 ? Math.floor(n) : a;
64
+ }, 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: {
65
+ message: s(e),
66
+ type: "response_too_large"
67
+ } }, { status: 413 }), l = async (e, t) => {
68
+ let n = Number(e.headers.get("content-length"));
69
+ if (Number.isFinite(n) && n > t) return e.body?.cancel(), c(t);
70
+ if (e.body === null) return e;
71
+ let r = e.body.getReader(), i = [], a = 0;
72
+ for (;;) {
73
+ let { done: e, value: n } = await r.read();
74
+ if (e) break;
75
+ if (a += n.byteLength, a > t) return r.cancel(), c(t);
76
+ i.push(new Uint8Array(n));
77
+ }
78
+ return new Response(new Blob(i), {
79
+ status: e.status,
80
+ statusText: e.statusText,
81
+ headers: e.headers
82
+ });
83
+ }, u = (e, t) => ({
84
+ ...e,
85
+ fetch: async (n, r) => l(await (e.fetch ?? globalThis.fetch)(n, r), t)
86
+ });
87
+ //#endregion
88
+ export { a as DEFAULT_MEDIA_MAX_RESPONSE_BYTES, u as boundedGatewaySettings, r as gatewayImageModel, i as gatewayVideoModel, o as mediaResponseBudget, s as mediaResponseTooLargeMessage };
package/dist/index.d.ts CHANGED
@@ -108,6 +108,8 @@ export declare const AgentEvent: Schema.Union<readonly [Schema.Struct<{
108
108
  readonly id: Schema.String;
109
109
  readonly name: Schema.String;
110
110
  readonly input: Schema.Unknown;
111
+ /** Present when the caller must execute this pending call. */
112
+ readonly execution: Schema.optional<Schema.Literal<"client">>;
111
113
  }>, Schema.Struct<{
112
114
  readonly _tag: Schema.Literal<"toolResult">;
113
115
  readonly id: Schema.String;
@@ -621,6 +623,8 @@ export declare interface AnyTool {
621
623
  readonly output?: Schema.Top;
622
624
  readonly execute?: (input: never) => Effect.Effect<unknown, never, unknown>;
623
625
  readonly handler?: ToolHandler<never, unknown>;
626
+ /** Client tools return a pending call to the caller; never run on the server. */
627
+ readonly execution?: 'server' | 'client';
624
628
  readonly timeoutMs?: number;
625
629
  }
626
630
 
@@ -1174,6 +1178,8 @@ export declare const defineTool: <A, I, O>(def: {
1174
1178
  readonly output?: Schema.Top;
1175
1179
  readonly execute?: (input: A) => Effect.Effect<O, never, unknown>;
1176
1180
  readonly handler?: ToolHandler<A, O>;
1181
+ /** Client tools return a pending call to the caller; never run on the server. */
1182
+ readonly execution?: "server" | "client";
1177
1183
  readonly timeoutMs?: number;
1178
1184
  }) => AnyTool;
1179
1185
 
@@ -2504,6 +2510,7 @@ export declare type MessagePart = {
2504
2510
  readonly type: 'tool';
2505
2511
  readonly toolCallId: string;
2506
2512
  readonly toolName: string;
2513
+ readonly execution?: 'client';
2507
2514
  /** 'input-available' once the model emitted args; 'output-available' once the tool ran. */
2508
2515
  readonly state: 'input-available' | 'output-available' | 'output-error';
2509
2516
  readonly input?: unknown;
@@ -3813,6 +3820,8 @@ export declare const SeqEvent: Schema.Struct<{
3813
3820
  readonly id: Schema.String;
3814
3821
  readonly name: Schema.String;
3815
3822
  readonly input: Schema.Unknown;
3823
+ /** Present when the caller must execute this pending call. */
3824
+ readonly execution: Schema.optional<Schema.Literal<"client">>;
3816
3825
  }>, Schema.Struct<{
3817
3826
  readonly _tag: Schema.Literal<"toolResult">;
3818
3827
  readonly id: Schema.String;
@@ -4180,6 +4189,8 @@ export declare interface ToolDef<A, I, O> {
4180
4189
  readonly execute?: (input: A) => Effect.Effect<O, never, unknown>;
4181
4190
  /** File-convention body: receives `ctx`, returns Effect or Promise. */
4182
4191
  readonly handler?: ToolHandler<A, O>;
4192
+ /** Client tools return a pending call to the caller; never run on the server. */
4193
+ readonly execution?: 'server' | 'client';
4183
4194
  /** Per-call deadline; the tool fails with a timeout error past it. */
4184
4195
  readonly timeoutMs?: number;
4185
4196
  }