@voltro/ai 0.85.0 → 0.87.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 +5987 -0
  2. package/THIRD-PARTY-NOTICES.md +4723 -519
  3. package/dist/agent.js +64 -2
  4. package/dist/agentConstants.js +4 -0
  5. package/dist/agentExecutor.js +55 -0
  6. package/dist/aiSettings.js +11 -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 +69 -0
  15. package/dist/eval.js +130 -0
  16. package/dist/events.d.ts +4 -0
  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 +60 -2
  23. package/dist/index.js +42 -2750
  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 +319 -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 +147 -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 +2 -0
  56. package/dist/workflow.js +115 -110
  57. package/package.json +6 -5
  58. package/dist/agentDescriptor-DhoiXVqO.js +0 -63
  59. package/dist/agentEvent-Bl4egdM5.js +0 -211
  60. package/dist/inferenceQueue-DcEulZep.js +0 -1077
  61. package/dist/provider-BnemgE4D.js +0 -409
@@ -0,0 +1,52 @@
1
+ import { estimateCostUsd as e } from "./cost.js";
2
+ import { Effect as t, Metric as n, Stream as r } from "effect";
3
+ //#region src/observe.ts
4
+ var i = Array.from({ length: 16 }, (e, t) => .001 * 2 ** t), a = n.counter("voltro_ai_calls_total", { description: "Total AI provider calls (generate + stream)." }), o = n.counter("voltro_ai_call_errors_total", { description: "AI provider calls that errored." }), s = n.histogram("voltro_ai_call_duration_seconds", {
5
+ boundaries: i,
6
+ description: "AI provider call duration in seconds."
7
+ }), c = n.counter("voltro_ai_input_tokens_total", {
8
+ description: "Total prompt (input) tokens across AI calls.",
9
+ incremental: !0
10
+ }), l = n.counter("voltro_ai_output_tokens_total", {
11
+ description: "Total completion (output) tokens across AI calls.",
12
+ incremental: !0
13
+ }), u = n.counter("voltro_ai_cost_microusd_total", {
14
+ description: "Total estimated AI spend in micro-USD (USD × 1e6).",
15
+ incremental: !0
16
+ }), d = (e, t) => ({
17
+ provider: e.name,
18
+ model: e.model ?? e.name,
19
+ operation: t
20
+ }), f = (e, r, i) => t.updateService(e, n.CurrentMetricAttributes, (e) => ({
21
+ ...e,
22
+ provider: r.provider,
23
+ model: r.model,
24
+ operation: r.operation,
25
+ status: i
26
+ })), p = (r, i) => {
27
+ let a = i.inputTokens ?? 0, o = i.outputTokens ?? 0, s = e({
28
+ inputTokens: a,
29
+ outputTokens: o
30
+ }, { model: r.model }), d = Math.round(s.totalCostUsd * 1e6);
31
+ return t.all([
32
+ f(n.update(c, a), r, "ok"),
33
+ f(n.update(l, o), r, "ok"),
34
+ f(n.update(u, d), r, "ok")
35
+ ], { discard: !0 });
36
+ }, m = (e, r, i) => t.gen(function* () {
37
+ let c = yield* t.clockWith((e) => e.currentTimeMillis);
38
+ return yield* i.pipe(t.tap((t) => p(e, r(t))), t.tap(() => f(n.update(a, 1), e, "ok").pipe(t.andThen(t.clockWith((e) => e.currentTimeMillis).pipe(t.flatMap((t) => f(n.update(s, (t - c) / 1e3), e, "ok")))))), t.tapError(() => f(n.update(a, 1), e, "error").pipe(t.andThen(f(n.update(o, 1), e, "error")), t.andThen(t.clockWith((e) => e.currentTimeMillis).pipe(t.flatMap((t) => f(n.update(s, (t - c) / 1e3), e, "error")))))), t.withSpan("voltro.ai.call", { attributes: {
39
+ "ai.provider": e.provider,
40
+ "ai.model": e.model,
41
+ "ai.operation": e.operation
42
+ } }));
43
+ }), h = (e, i) => {
44
+ let c = Date.now();
45
+ return i.pipe(r.tap((r) => r._tag === "done" ? f(n.update(a, 1), e, "ok").pipe(t.andThen(f(n.update(s, (Date.now() - c) / 1e3), e, "ok")), t.andThen(p(e, r.usage ?? {}))) : r._tag === "error" ? f(n.update(a, 1), e, "error").pipe(t.andThen(f(n.update(o, 1), e, "error")), t.andThen(f(n.update(s, (Date.now() - c) / 1e3), e, "error"))) : t.void), r.withSpan("voltro.ai.call", { attributes: {
46
+ "ai.provider": e.provider,
47
+ "ai.model": e.model,
48
+ "ai.operation": e.operation
49
+ } }));
50
+ };
51
+ //#endregion
52
+ export { d as aiCallAttributes, h as observeStream, m as withAiCallSpan };
@@ -0,0 +1,103 @@
1
+ import { Effect as e, Schema as t } from "effect";
2
+ import { and as n, eq as r, generateId as i, id as a, integer as o, queryFor as s, registerRetention as c, retentionTtlMsFromEnv as l, table as u, text as d, timestamp as f } from "@voltro/database";
3
+ import { createHash as p } from "node:crypto";
4
+ //#region src/prompts.ts
5
+ var m = (e) => `sha256:${p("sha256").update(e).digest("hex").slice(0, 16)}`, h = class extends t.TaggedError()("PromptRenderError", {
6
+ promptId: t.String,
7
+ missing: t.Array(t.String),
8
+ message: t.String
9
+ }) {}, g = /\{\{\s*([A-Za-z0-9_.]+)\s*\}\}/g, _ = (e) => {
10
+ let t = /* @__PURE__ */ new Set();
11
+ for (let n of e.matchAll(g)) {
12
+ let e = n[1];
13
+ e !== void 0 && t.add(e);
14
+ }
15
+ return [...t];
16
+ }, v = (e, t) => m(`${e.length}:${e}${(t ?? "").length}:${t ?? ""}`), y = (t) => {
17
+ let n = v(t.template, t.system), r = _(t.template);
18
+ return {
19
+ ...t,
20
+ digest: n,
21
+ variables: r,
22
+ render: (i = {}) => e.suspend(() => {
23
+ let a = r.filter((e) => i[e] === void 0);
24
+ if (a.length > 0) return e.fail(new h({
25
+ promptId: t.id,
26
+ missing: a,
27
+ message: `prompt '${t.id}' needs ${a.map((e) => `{{${e}}}`).join(", ")}, which ${a.length === 1 ? "was" : "were"} not supplied.`
28
+ }));
29
+ let o = t.template.replace(g, (e, t) => String(i[t]));
30
+ return e.succeed({
31
+ promptId: t.id,
32
+ digest: n,
33
+ ...t.label === void 0 ? {} : { label: t.label },
34
+ prompt: o,
35
+ ...t.system === void 0 ? {} : { system: t.system },
36
+ definition: t
37
+ });
38
+ })
39
+ };
40
+ }, b = (e) => typeof e == "object" && !!e && typeof e.prompt == "string" && typeof e.digest == "string" && typeof e.promptId == "string", x = "_voltro_prompts", S = u(x, {
41
+ id: a({ prefix: "prm" }),
42
+ promptId: d().maxLength(191),
43
+ digest: d().maxLength(191),
44
+ revision: o().default(1),
45
+ label: d().nullable(),
46
+ template: d().nullable(),
47
+ system: d().nullable(),
48
+ templateChars: o().default(0),
49
+ firstSeenAt: f().default("now"),
50
+ lastUsedAt: f().default("now")
51
+ }).unique("byPromptsVersion", ["promptId", "digest"]).index(["promptId"]), C = 8760, w = () => {
52
+ c({
53
+ source: "framework",
54
+ table: x,
55
+ timeColumn: "lastUsedAt",
56
+ ttlMs: l(process.env.VOLTRO_AI_PROMPTS_TTL_HOURS, C),
57
+ envVar: "VOLTRO_AI_PROMPTS_TTL_HOURS",
58
+ label: "ai prompt versions"
59
+ });
60
+ }, T = (e) => ({
61
+ promptId: String(e.promptId),
62
+ digest: String(e.digest),
63
+ revision: Number(e.revision) || 1,
64
+ label: e.label ?? null,
65
+ template: e.template ?? null,
66
+ system: e.system ?? null,
67
+ firstSeenAt: e.firstSeenAt ?? null,
68
+ lastUsedAt: e.lastUsedAt ?? null
69
+ }), E = (t, a) => e.gen(function* () {
70
+ w();
71
+ let o = a.digest ?? y(a).digest;
72
+ return yield* e.promise(async () => {
73
+ let e = (await t.query(s(S).where(n(r("promptId", a.id), r("digest", o))).descriptor))[0];
74
+ if (e !== void 0) {
75
+ let n = /* @__PURE__ */ new Date();
76
+ return await t.updateMany(x, { lastUsedAt: n }, { where: r("id", String(e.id)) }), T({
77
+ ...e,
78
+ lastUsedAt: n
79
+ });
80
+ }
81
+ let c = (await t.query(s(S).where(r("promptId", a.id)).descriptor)).reduce((e, t) => Math.max(e, Number(t.revision) || 0), 0) + 1, l = /* @__PURE__ */ new Date(), u = {
82
+ id: i({
83
+ kind: "typeid",
84
+ prefix: "prm"
85
+ }, x),
86
+ promptId: a.id,
87
+ digest: o,
88
+ revision: c,
89
+ label: a.label ?? null,
90
+ template: a.template,
91
+ system: a.system ?? null,
92
+ templateChars: a.template.length,
93
+ firstSeenAt: l,
94
+ lastUsedAt: l
95
+ };
96
+ return T(await t.insertIgnore(x, u, { conflictColumns: ["promptId", "digest"] }) ?? u);
97
+ });
98
+ }), D = (t, n) => e.promise(async () => {
99
+ let e = (await t.query(s(S).where(r("digest", n)).descriptor))[0];
100
+ return e === void 0 ? null : T(e);
101
+ }), O = (t, n) => e.promise(async () => [...await t.query(s(S).where(r("promptId", n)).orderBy("revision", "desc").descriptor)].sort((e, t) => (Number(t.revision) || 0) - (Number(e.revision) || 0)).map(T));
102
+ //#endregion
103
+ export { C as DEFAULT_PROMPT_RETENTION_HOURS, x as PROMPTS_TABLE, h as PromptRenderError, y as definePrompt, b as isRenderedPrompt, m as promptDigest, D as promptVersionByDigest, v as promptVersionDigest, O as promptVersionsFor, S as promptsTable, E as recordPromptVersion };
@@ -0,0 +1,319 @@
1
+ import { aiSetting as e, isProductionEnv as t } from "./aiSettings.js";
2
+ import { applyMiddleware as n } from "./middleware.js";
3
+ import { boundedGatewaySettings as r, gatewayImageModel as i, gatewayVideoModel as a, mediaResponseBudget as o } from "./gatewayMedia.js";
4
+ import { anthropic as s, createAnthropic as c } from "@ai-sdk/anthropic";
5
+ import { createOpenAI as l, openai as u } from "@ai-sdk/openai";
6
+ import { createGateway as d, gateway as f } from "@ai-sdk/gateway";
7
+ //#region src/provider.ts
8
+ var p = {
9
+ inputTokens: {
10
+ total: 0,
11
+ noCache: 0,
12
+ cacheRead: 0,
13
+ cacheWrite: 0
14
+ },
15
+ outputTokens: {
16
+ total: 0,
17
+ text: 0,
18
+ reasoning: 0
19
+ }
20
+ }, m = (e) => ({
21
+ unified: e,
22
+ raw: void 0
23
+ }), h = class {
24
+ turns;
25
+ cursor = 0;
26
+ calls = [];
27
+ constructor(e) {
28
+ this.turns = e.length > 0 ? e : [{ text: "" }];
29
+ }
30
+ record(e, t) {
31
+ this.calls.push({
32
+ prompt: e,
33
+ tools: t
34
+ });
35
+ }
36
+ next() {
37
+ let e = this.turns[Math.min(this.cursor, this.turns.length - 1)];
38
+ return this.cursor += 1, e;
39
+ }
40
+ reset() {
41
+ this.cursor = 0, this.calls.length = 0;
42
+ }
43
+ }, g = (e) => (e.toolCalls ?? []).map((e, t) => ({
44
+ type: "tool-call",
45
+ toolCallId: `mock_tool_${t}`,
46
+ toolName: e.name,
47
+ input: JSON.stringify(e.input ?? {})
48
+ })), _ = (e) => (e.sources ?? []).map((e, t) => e.sourceType === "document" ? {
49
+ type: "source",
50
+ sourceType: "document",
51
+ id: e.id ?? `mock_src_${t}`,
52
+ mediaType: e.mediaType ?? "application/pdf",
53
+ title: e.title ?? "document",
54
+ ...e.filename === void 0 ? {} : { filename: e.filename }
55
+ } : {
56
+ type: "source",
57
+ sourceType: "url",
58
+ id: e.id ?? `mock_src_${t}`,
59
+ url: e.url ?? "https://example.com",
60
+ ...e.title === void 0 ? {} : { title: e.title }
61
+ }), v = (e) => (e.files ?? []).map((e) => ({
62
+ type: "file",
63
+ mediaType: e.mediaType,
64
+ data: {
65
+ type: "data",
66
+ data: e.data
67
+ }
68
+ })), y = (e) => [
69
+ {
70
+ type: "text-start",
71
+ id: "0"
72
+ },
73
+ ...e.split(/(\s+)/).filter((e) => e.length > 0).map((e) => ({
74
+ type: "text-delta",
75
+ id: "0",
76
+ delta: e
77
+ })),
78
+ {
79
+ type: "text-end",
80
+ id: "0"
81
+ }
82
+ ], b = (e) => e.length === 0 ? [] : [
83
+ {
84
+ type: "reasoning-start",
85
+ id: "r0"
86
+ },
87
+ {
88
+ type: "reasoning-delta",
89
+ id: "r0",
90
+ delta: e
91
+ },
92
+ {
93
+ type: "reasoning-end",
94
+ id: "r0"
95
+ }
96
+ ], x = (e, t, n, r) => ({
97
+ specificationVersion: "v4",
98
+ provider: "mock",
99
+ modelId: e,
100
+ supportedUrls: {},
101
+ doGenerate: async ({ prompt: i, tools: a }) => {
102
+ n?.record(i, (a ?? []).map((e) => e.name ?? ""));
103
+ let o = n?.next();
104
+ if (o?.error) throw Error(o.error.message);
105
+ let s = JSON.stringify(i).slice(0, 80), c = o?.toolCalls ?? [];
106
+ return c.length > 0 ? {
107
+ content: c.map((e, t) => ({
108
+ type: "tool-call",
109
+ toolCallId: `mock_tool_${t}`,
110
+ toolName: e.name,
111
+ input: JSON.stringify(e.input ?? {})
112
+ })),
113
+ finishReason: m("tool-calls"),
114
+ usage: p,
115
+ warnings: []
116
+ } : {
117
+ content: [{
118
+ type: "text",
119
+ text: o?.text ?? t ?? `[mock(${e})] ${s}`
120
+ }],
121
+ finishReason: m("stop"),
122
+ usage: p,
123
+ warnings: [],
124
+ ...r === void 0 ? {} : { providerMetadata: r }
125
+ };
126
+ },
127
+ doStream: async ({ prompt: e, tools: r }) => {
128
+ n?.record(e, (r ?? []).map((e) => e.name ?? ""));
129
+ let i = n?.next(), a = (i?.toolCalls?.length ?? 0) > 0, o = i?.text ?? (n ? "" : t ?? "[mock] streamed response"), s = [{
130
+ type: "stream-start",
131
+ warnings: []
132
+ }];
133
+ return i?.error ? (s.push({
134
+ type: "error",
135
+ error: Error(i.error.message)
136
+ }), s.push({
137
+ type: "finish",
138
+ finishReason: m("error"),
139
+ usage: p
140
+ })) : (s.push(...b(i?.reasoning ?? "")), o.length > 0 && s.push(...y(o)), s.push(..._(i ?? {})), s.push(...v(i ?? {})), s.push(...g(i ?? {})), s.push({
141
+ type: "finish",
142
+ finishReason: m(a ? "tool-calls" : "stop"),
143
+ usage: p
144
+ })), { stream: new ReadableStream({ start(e) {
145
+ for (let t of s) e.enqueue(t);
146
+ e.close();
147
+ } }) };
148
+ }
149
+ }), S = "iVBORw0KGgo=", C = "SUQzBAAAAAAAAA==", w = "video/mp4", T = "mock transcript", E = (e, t) => ({
150
+ specificationVersion: "v4",
151
+ provider: "mock",
152
+ modelId: e,
153
+ maxImagesPerCall: 8,
154
+ doGenerate: async ({ n }) => ({
155
+ images: Array.from({ length: Math.max(1, n) }, () => t),
156
+ warnings: [],
157
+ response: {
158
+ timestamp: /* @__PURE__ */ new Date(),
159
+ modelId: e,
160
+ headers: void 0
161
+ },
162
+ usage: {
163
+ inputTokens: 0,
164
+ outputTokens: 0,
165
+ totalTokens: 0
166
+ }
167
+ })
168
+ }), D = (e, t, n) => ({
169
+ specificationVersion: "v4",
170
+ provider: "mock",
171
+ modelId: e,
172
+ doGenerate: async () => ({
173
+ audio: t,
174
+ warnings: [],
175
+ response: {
176
+ timestamp: /* @__PURE__ */ new Date(),
177
+ modelId: e
178
+ },
179
+ ...n === void 0 ? {} : { providerMetadata: n }
180
+ })
181
+ }), O = (e, t, n) => ({
182
+ specificationVersion: "v4",
183
+ provider: "mock",
184
+ modelId: e,
185
+ doGenerate: async () => ({
186
+ text: t,
187
+ segments: [],
188
+ language: "en",
189
+ durationInSeconds: 1,
190
+ warnings: [],
191
+ response: {
192
+ timestamp: /* @__PURE__ */ new Date(),
193
+ modelId: e,
194
+ headers: {},
195
+ body: void 0
196
+ },
197
+ ...n === void 0 ? {} : { providerMetadata: n }
198
+ })
199
+ }), k = (e, t, n) => ({
200
+ specificationVersion: "v4",
201
+ provider: "mock",
202
+ modelId: e,
203
+ maxVideosPerCall: 1,
204
+ doGenerate: async () => ({
205
+ videos: [t],
206
+ warnings: [],
207
+ response: {
208
+ timestamp: /* @__PURE__ */ new Date(),
209
+ modelId: e,
210
+ headers: void 0
211
+ },
212
+ ...n === void 0 ? {} : { providerMetadata: n }
213
+ })
214
+ }), A = (e) => e.apiKey !== void 0 || e.baseURL !== void 0, j = (e) => ({
215
+ ...e.apiKey === void 0 ? {} : { apiKey: e.apiKey },
216
+ ...e.baseURL === void 0 ? {} : { baseURL: e.baseURL }
217
+ }), M = (e, t) => {
218
+ let r = (() => {
219
+ switch (e.name) {
220
+ case "mock": return x(e.model ?? "mock", e.mockText, e.script, e.providerMetadata);
221
+ case "anthropic": return A(e) ? c(j(e))(e.model) : s(e.model);
222
+ case "openai": return A(e) ? l(j(e))(e.model) : u(e.model);
223
+ case "gateway": return A(e) ? d(j(e))(e.model) : f(e.model);
224
+ }
225
+ })();
226
+ return n(r, t);
227
+ }, N = (e) => {
228
+ switch (e.name) {
229
+ case "mock": return E(e.model ?? "mock", e.mockMedia?.imageBase64 ?? S);
230
+ case "openai": return A(e) ? l(j(e)).image(e.model) : u.image(e.model);
231
+ case "gateway": return i(r(j(e), o(e.maxResponseBytes)), e.model);
232
+ case "anthropic": throw Error("Provider 'anthropic' does not support image generation. Use 'openai' or 'gateway'.");
233
+ }
234
+ }, P = (e) => {
235
+ switch (e.name) {
236
+ case "mock": return D(e.model ?? "mock", e.mockMedia?.audioBase64 ?? C, e.providerMetadata);
237
+ case "openai": return A(e) ? l(j(e)).speech(e.model) : u.speech(e.model);
238
+ case "gateway": return d(r(j(e), o(e.maxResponseBytes))).speech(e.model);
239
+ case "anthropic": throw Error("Provider 'anthropic' does not support speech generation. Use 'openai' or 'gateway'.");
240
+ }
241
+ }, F = (e) => {
242
+ switch (e.name) {
243
+ case "mock": return O(e.model ?? "mock", e.mockMedia?.transcript ?? T, e.providerMetadata);
244
+ case "openai": return A(e) ? l(j(e)).transcription(e.model) : u.transcription(e.model);
245
+ case "gateway": return d(r(j(e), o(e.maxResponseBytes))).transcription(e.model);
246
+ case "anthropic": throw Error("Provider 'anthropic' does not support transcription. Use 'openai' or 'gateway'.");
247
+ }
248
+ }, I = (e) => {
249
+ switch (e.name) {
250
+ case "mock": {
251
+ let t = e.mockMedia, n = t?.videoBase64 === void 0 ? {
252
+ type: "url",
253
+ url: t?.videoUrl ?? `https://mock.local/${e.model ?? "mock"}.mp4`,
254
+ mediaType: w
255
+ } : {
256
+ type: "base64",
257
+ data: t.videoBase64,
258
+ mediaType: w
259
+ };
260
+ return k(e.model ?? "mock", n, e.providerMetadata);
261
+ }
262
+ case "gateway": return a(r(j(e), o(e.maxResponseBytes)), e.model);
263
+ case "openai": throw Error("Provider 'openai' does not support video generation. Use 'gateway'.");
264
+ case "anthropic": throw Error("Provider 'anthropic' does not support video generation. Use 'gateway'.");
265
+ }
266
+ }, L = null, R = (e) => {
267
+ let t = L;
268
+ return L = e, t;
269
+ }, z = () => L, B = (e) => {
270
+ switch (e.toLowerCase()) {
271
+ case "anthropic": return "ANTHROPIC_API_KEY";
272
+ case "openai": return "OPENAI_API_KEY";
273
+ case "gateway": return "AI_GATEWAY_API_KEY";
274
+ default: return;
275
+ }
276
+ }, V = (t = process.env) => {
277
+ if (L) return {
278
+ name: L.name,
279
+ chosen: !0
280
+ };
281
+ let n = e("AI_PROVIDER", t);
282
+ return n === void 0 ? {
283
+ name: "mock",
284
+ chosen: !1
285
+ } : {
286
+ name: n.toLowerCase(),
287
+ chosen: !0
288
+ };
289
+ }, H = (n = process.env) => {
290
+ if (L) return L;
291
+ let r = V(n);
292
+ if (!r.chosen && t(n)) throw Error("No AI provider is chosen in this production process: AI_PROVIDER is unset and this call passes no `provider` (or its agent declares no `model`), so it would answer from the mock provider. Set AI_PROVIDER (anthropic | openai | gateway) for every process that makes model calls, or declare it in `defineEnv` with a `default`, or pass `provider` to the call. Set AI_PROVIDER=mock to serve mock answers deliberately.");
293
+ let i = r.name, a = e("AI_MODEL", n);
294
+ switch (i) {
295
+ case "mock": return {
296
+ name: "mock",
297
+ model: a ?? "mock"
298
+ };
299
+ case "anthropic": return {
300
+ name: "anthropic",
301
+ model: a ?? "claude-opus-4-8"
302
+ };
303
+ case "openai": return {
304
+ name: "openai",
305
+ model: a ?? "gpt-5.5"
306
+ };
307
+ case "gateway": {
308
+ let e = a === void 0 ? -1 : a.indexOf("/");
309
+ if (a === void 0 || e <= 0 || e === a.length - 1) throw Error("AI_PROVIDER=gateway requires AI_MODEL set to a 'creator/model' id, e.g. 'openai/gpt-5.5'");
310
+ return {
311
+ name: "gateway",
312
+ model: a
313
+ };
314
+ }
315
+ default: throw Error(`Unknown AI_PROVIDER '${i}'. Expected one of: mock, anthropic, openai, gateway.`);
316
+ }
317
+ };
318
+ //#endregion
319
+ export { h as MockScript, z as getProviderOverride, V as providerChoice, H as providerFromEnv, B as providerKeyEnvVar, N as resolveImageModel, M as resolveModel, P as resolveSpeechModel, F as resolveTranscriptionModel, I as resolveVideoModel, R as setProviderOverride };
@@ -0,0 +1,97 @@
1
+ import { Schema as e } from "effect";
2
+ //#region src/realtimeEvent.ts
3
+ var t = e.String.pipe(e.check(e.isPattern(/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/))), n = e.Number.pipe(e.check(e.isFinite()), e.check(e.isGreaterThanOrEqualTo(0))), r = e.Union([
4
+ e.Struct({
5
+ type: e.Literal("input-audio-append"),
6
+ audio: t
7
+ }),
8
+ e.Struct({ type: e.Literals([
9
+ "input-audio-commit",
10
+ "input-audio-clear",
11
+ "response-create",
12
+ "response-cancel"
13
+ ]) }),
14
+ e.Struct({
15
+ type: e.Literal("conversation-item-create"),
16
+ item: e.Struct({
17
+ type: e.Literal("text-message"),
18
+ role: e.Literal("user"),
19
+ text: e.String
20
+ })
21
+ }),
22
+ e.Struct({
23
+ type: e.Literal("conversation-item-truncate"),
24
+ itemId: e.String,
25
+ contentIndex: n.pipe(e.check(e.isInt())),
26
+ audioEndMs: n
27
+ })
28
+ ]), i = { itemId: e.String }, a = {
29
+ responseId: e.String,
30
+ ...i
31
+ }, o = e.Union([
32
+ e.Struct({ type: e.Literal("ready") }),
33
+ e.Struct({
34
+ type: e.Literal("session-created"),
35
+ sessionId: e.optional(e.String)
36
+ }),
37
+ e.Struct({ type: e.Literal("session-updated") }),
38
+ e.Struct({
39
+ type: e.Literals(["speech-started", "speech-stopped"]),
40
+ itemId: e.optional(e.String)
41
+ }),
42
+ e.Struct({
43
+ type: e.Literal("audio-committed"),
44
+ itemId: e.optional(e.String),
45
+ previousItemId: e.optional(e.String)
46
+ }),
47
+ e.Struct({
48
+ type: e.Literal("conversation-item-added"),
49
+ ...i
50
+ }),
51
+ e.Struct({
52
+ type: e.Literal("input-transcription-completed"),
53
+ ...i,
54
+ transcript: e.String
55
+ }),
56
+ e.Struct({
57
+ type: e.Literal("response-created"),
58
+ responseId: e.String
59
+ }),
60
+ e.Struct({
61
+ type: e.Literal("response-done"),
62
+ responseId: e.String,
63
+ status: e.String
64
+ }),
65
+ e.Struct({
66
+ type: e.Literals([
67
+ "output-item-added",
68
+ "output-item-done",
69
+ "content-part-added",
70
+ "content-part-done",
71
+ "audio-done"
72
+ ]),
73
+ ...a
74
+ }),
75
+ e.Struct({
76
+ type: e.Literal("audio-delta"),
77
+ ...a,
78
+ delta: t
79
+ }),
80
+ e.Struct({
81
+ type: e.Literals(["text-delta", "audio-transcript-delta"]),
82
+ ...a,
83
+ delta: e.String
84
+ }),
85
+ e.Struct({
86
+ type: e.Literal("text-done"),
87
+ ...a,
88
+ text: e.optional(e.String)
89
+ }),
90
+ e.Struct({
91
+ type: e.Literal("audio-transcript-done"),
92
+ ...a,
93
+ transcript: e.optional(e.String)
94
+ })
95
+ ]);
96
+ //#endregion
97
+ export { r as RealtimeClientEvent, o as RealtimeServerEvent };