@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
@@ -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,303 @@
1
+ import { applyMiddleware as e } from "./middleware.js";
2
+ import { boundedGatewaySettings as t, gatewayImageModel as n, gatewayVideoModel as r, mediaResponseBudget as i } from "./gatewayMedia.js";
3
+ import { anthropic as a, createAnthropic as o } from "@ai-sdk/anthropic";
4
+ import { createOpenAI as s, openai as c } from "@ai-sdk/openai";
5
+ import { createGateway as l, gateway as u } from "@ai-sdk/gateway";
6
+ //#region src/provider.ts
7
+ var d = {
8
+ inputTokens: {
9
+ total: 0,
10
+ noCache: 0,
11
+ cacheRead: 0,
12
+ cacheWrite: 0
13
+ },
14
+ outputTokens: {
15
+ total: 0,
16
+ text: 0,
17
+ reasoning: 0
18
+ }
19
+ }, f = (e) => ({
20
+ unified: e,
21
+ raw: void 0
22
+ }), p = class {
23
+ turns;
24
+ cursor = 0;
25
+ calls = [];
26
+ constructor(e) {
27
+ this.turns = e.length > 0 ? e : [{ text: "" }];
28
+ }
29
+ record(e, t) {
30
+ this.calls.push({
31
+ prompt: e,
32
+ tools: t
33
+ });
34
+ }
35
+ next() {
36
+ let e = this.turns[Math.min(this.cursor, this.turns.length - 1)];
37
+ return this.cursor += 1, e;
38
+ }
39
+ reset() {
40
+ this.cursor = 0, this.calls.length = 0;
41
+ }
42
+ }, m = (e) => (e.toolCalls ?? []).map((e, t) => ({
43
+ type: "tool-call",
44
+ toolCallId: `mock_tool_${t}`,
45
+ toolName: e.name,
46
+ input: JSON.stringify(e.input ?? {})
47
+ })), h = (e) => (e.sources ?? []).map((e, t) => e.sourceType === "document" ? {
48
+ type: "source",
49
+ sourceType: "document",
50
+ id: e.id ?? `mock_src_${t}`,
51
+ mediaType: e.mediaType ?? "application/pdf",
52
+ title: e.title ?? "document",
53
+ ...e.filename === void 0 ? {} : { filename: e.filename }
54
+ } : {
55
+ type: "source",
56
+ sourceType: "url",
57
+ id: e.id ?? `mock_src_${t}`,
58
+ url: e.url ?? "https://example.com",
59
+ ...e.title === void 0 ? {} : { title: e.title }
60
+ }), g = (e) => (e.files ?? []).map((e) => ({
61
+ type: "file",
62
+ mediaType: e.mediaType,
63
+ data: {
64
+ type: "data",
65
+ data: e.data
66
+ }
67
+ })), _ = (e) => [
68
+ {
69
+ type: "text-start",
70
+ id: "0"
71
+ },
72
+ ...e.split(/(\s+)/).filter((e) => e.length > 0).map((e) => ({
73
+ type: "text-delta",
74
+ id: "0",
75
+ delta: e
76
+ })),
77
+ {
78
+ type: "text-end",
79
+ id: "0"
80
+ }
81
+ ], v = (e) => e.length === 0 ? [] : [
82
+ {
83
+ type: "reasoning-start",
84
+ id: "r0"
85
+ },
86
+ {
87
+ type: "reasoning-delta",
88
+ id: "r0",
89
+ delta: e
90
+ },
91
+ {
92
+ type: "reasoning-end",
93
+ id: "r0"
94
+ }
95
+ ], y = (e, t, n, r) => ({
96
+ specificationVersion: "v4",
97
+ provider: "mock",
98
+ modelId: e,
99
+ supportedUrls: {},
100
+ doGenerate: async ({ prompt: i, tools: a }) => {
101
+ n?.record(i, (a ?? []).map((e) => e.name ?? ""));
102
+ let o = n?.next();
103
+ if (o?.error) throw Error(o.error.message);
104
+ let s = JSON.stringify(i).slice(0, 80), c = o?.toolCalls ?? [];
105
+ return c.length > 0 ? {
106
+ content: c.map((e, t) => ({
107
+ type: "tool-call",
108
+ toolCallId: `mock_tool_${t}`,
109
+ toolName: e.name,
110
+ input: JSON.stringify(e.input ?? {})
111
+ })),
112
+ finishReason: f("tool-calls"),
113
+ usage: d,
114
+ warnings: []
115
+ } : {
116
+ content: [{
117
+ type: "text",
118
+ text: o?.text ?? t ?? `[mock(${e})] ${s}`
119
+ }],
120
+ finishReason: f("stop"),
121
+ usage: d,
122
+ warnings: [],
123
+ ...r === void 0 ? {} : { providerMetadata: r }
124
+ };
125
+ },
126
+ doStream: async ({ prompt: e, tools: r }) => {
127
+ n?.record(e, (r ?? []).map((e) => e.name ?? ""));
128
+ let i = n?.next(), a = (i?.toolCalls?.length ?? 0) > 0, o = i?.text ?? (n ? "" : t ?? "[mock] streamed response"), s = [{
129
+ type: "stream-start",
130
+ warnings: []
131
+ }];
132
+ return i?.error ? (s.push({
133
+ type: "error",
134
+ error: Error(i.error.message)
135
+ }), s.push({
136
+ type: "finish",
137
+ finishReason: f("error"),
138
+ usage: d
139
+ })) : (s.push(...v(i?.reasoning ?? "")), o.length > 0 && s.push(..._(o)), s.push(...h(i ?? {})), s.push(...g(i ?? {})), s.push(...m(i ?? {})), s.push({
140
+ type: "finish",
141
+ finishReason: f(a ? "tool-calls" : "stop"),
142
+ usage: d
143
+ })), { stream: new ReadableStream({ start(e) {
144
+ for (let t of s) e.enqueue(t);
145
+ e.close();
146
+ } }) };
147
+ }
148
+ }), b = "iVBORw0KGgo=", x = "SUQzBAAAAAAAAA==", S = "video/mp4", C = "mock transcript", w = (e, t) => ({
149
+ specificationVersion: "v4",
150
+ provider: "mock",
151
+ modelId: e,
152
+ maxImagesPerCall: 8,
153
+ doGenerate: async ({ n }) => ({
154
+ images: Array.from({ length: Math.max(1, n) }, () => t),
155
+ warnings: [],
156
+ response: {
157
+ timestamp: /* @__PURE__ */ new Date(),
158
+ modelId: e,
159
+ headers: void 0
160
+ },
161
+ usage: {
162
+ inputTokens: 0,
163
+ outputTokens: 0,
164
+ totalTokens: 0
165
+ }
166
+ })
167
+ }), T = (e, t, n) => ({
168
+ specificationVersion: "v4",
169
+ provider: "mock",
170
+ modelId: e,
171
+ doGenerate: async () => ({
172
+ audio: t,
173
+ warnings: [],
174
+ response: {
175
+ timestamp: /* @__PURE__ */ new Date(),
176
+ modelId: e
177
+ },
178
+ ...n === void 0 ? {} : { providerMetadata: n }
179
+ })
180
+ }), E = (e, t, n) => ({
181
+ specificationVersion: "v4",
182
+ provider: "mock",
183
+ modelId: e,
184
+ doGenerate: async () => ({
185
+ text: t,
186
+ segments: [],
187
+ language: "en",
188
+ durationInSeconds: 1,
189
+ warnings: [],
190
+ response: {
191
+ timestamp: /* @__PURE__ */ new Date(),
192
+ modelId: e,
193
+ headers: {},
194
+ body: void 0
195
+ },
196
+ ...n === void 0 ? {} : { providerMetadata: n }
197
+ })
198
+ }), D = (e, t, n) => ({
199
+ specificationVersion: "v4",
200
+ provider: "mock",
201
+ modelId: e,
202
+ maxVideosPerCall: 1,
203
+ doGenerate: async () => ({
204
+ videos: [t],
205
+ warnings: [],
206
+ response: {
207
+ timestamp: /* @__PURE__ */ new Date(),
208
+ modelId: e,
209
+ headers: void 0
210
+ },
211
+ ...n === void 0 ? {} : { providerMetadata: n }
212
+ })
213
+ }), O = (e) => e.apiKey !== void 0 || e.baseURL !== void 0, k = (e) => ({
214
+ ...e.apiKey === void 0 ? {} : { apiKey: e.apiKey },
215
+ ...e.baseURL === void 0 ? {} : { baseURL: e.baseURL }
216
+ }), A = (t, n) => {
217
+ let r = (() => {
218
+ switch (t.name) {
219
+ case "mock": return y(t.model ?? "mock", t.mockText, t.script, t.providerMetadata);
220
+ case "anthropic": return O(t) ? o(k(t))(t.model) : a(t.model);
221
+ case "openai": return O(t) ? s(k(t))(t.model) : c(t.model);
222
+ case "gateway": return O(t) ? l(k(t))(t.model) : u(t.model);
223
+ }
224
+ })();
225
+ return e(r, n);
226
+ }, j = (e) => {
227
+ switch (e.name) {
228
+ case "mock": return w(e.model ?? "mock", e.mockMedia?.imageBase64 ?? b);
229
+ case "openai": return O(e) ? s(k(e)).image(e.model) : c.image(e.model);
230
+ case "gateway": return n(t(k(e), i(e.maxResponseBytes)), e.model);
231
+ case "anthropic": throw Error("Provider 'anthropic' does not support image generation. Use 'openai' or 'gateway'.");
232
+ }
233
+ }, M = (e) => {
234
+ switch (e.name) {
235
+ case "mock": return T(e.model ?? "mock", e.mockMedia?.audioBase64 ?? x, e.providerMetadata);
236
+ case "openai": return O(e) ? s(k(e)).speech(e.model) : c.speech(e.model);
237
+ case "gateway": return l(t(k(e), i(e.maxResponseBytes))).speech(e.model);
238
+ case "anthropic": throw Error("Provider 'anthropic' does not support speech generation. Use 'openai' or 'gateway'.");
239
+ }
240
+ }, N = (e) => {
241
+ switch (e.name) {
242
+ case "mock": return E(e.model ?? "mock", e.mockMedia?.transcript ?? C, e.providerMetadata);
243
+ case "openai": return O(e) ? s(k(e)).transcription(e.model) : c.transcription(e.model);
244
+ case "gateway": return l(t(k(e), i(e.maxResponseBytes))).transcription(e.model);
245
+ case "anthropic": throw Error("Provider 'anthropic' does not support transcription. Use 'openai' or 'gateway'.");
246
+ }
247
+ }, P = (e) => {
248
+ switch (e.name) {
249
+ case "mock": {
250
+ let t = e.mockMedia, n = t?.videoBase64 === void 0 ? {
251
+ type: "url",
252
+ url: t?.videoUrl ?? `https://mock.local/${e.model ?? "mock"}.mp4`,
253
+ mediaType: S
254
+ } : {
255
+ type: "base64",
256
+ data: t.videoBase64,
257
+ mediaType: S
258
+ };
259
+ return D(e.model ?? "mock", n, e.providerMetadata);
260
+ }
261
+ case "gateway": return r(t(k(e), i(e.maxResponseBytes)), e.model);
262
+ case "openai": throw Error("Provider 'openai' does not support video generation. Use 'gateway'.");
263
+ case "anthropic": throw Error("Provider 'anthropic' does not support video generation. Use 'gateway'.");
264
+ }
265
+ }, F = null, I = (e) => {
266
+ let t = F;
267
+ return F = e, t;
268
+ }, L = () => F, R = (e) => {
269
+ switch (e.toLowerCase()) {
270
+ case "anthropic": return "ANTHROPIC_API_KEY";
271
+ case "openai": return "OPENAI_API_KEY";
272
+ case "gateway": return "AI_GATEWAY_API_KEY";
273
+ default: return;
274
+ }
275
+ }, z = (e = process.env) => {
276
+ if (F) return F;
277
+ let t = (e.AI_PROVIDER ?? "mock").toLowerCase(), n = e.AI_MODEL;
278
+ switch (t) {
279
+ case "mock": return {
280
+ name: "mock",
281
+ model: n ?? "mock"
282
+ };
283
+ case "anthropic": return {
284
+ name: "anthropic",
285
+ model: n ?? "claude-opus-4-8"
286
+ };
287
+ case "openai": return {
288
+ name: "openai",
289
+ model: n ?? "gpt-5.5"
290
+ };
291
+ case "gateway": {
292
+ let e = n === void 0 ? -1 : n.indexOf("/");
293
+ 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'");
294
+ return {
295
+ name: "gateway",
296
+ model: n
297
+ };
298
+ }
299
+ default: throw Error(`Unknown AI_PROVIDER '${t}'. Expected one of: mock, anthropic, openai, gateway.`);
300
+ }
301
+ };
302
+ //#endregion
303
+ export { p as MockScript, L as getProviderOverride, z as providerFromEnv, R as providerKeyEnvVar, j as resolveImageModel, A as resolveModel, M as resolveSpeechModel, N as resolveTranscriptionModel, P as resolveVideoModel, I 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 };