@voltro/ai 0.86.0 → 0.88.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 (55) hide show
  1. package/CHANGELOG.md +5484 -0
  2. package/THIRD-PARTY-NOTICES.md +5352 -524
  3. package/dist/agent.js +1 -2
  4. package/dist/agentConstants.js +1 -2
  5. package/dist/agentExecutor.js +43 -40
  6. package/dist/aiSettings.js +10 -0
  7. package/dist/api.js +1 -2
  8. package/dist/appTools.js +1 -2
  9. package/dist/budget.js +1 -2
  10. package/dist/callEvidence.js +1 -2
  11. package/dist/copilot.js +1 -2
  12. package/dist/cost.js +1 -2
  13. package/dist/embed.js +1 -2
  14. package/dist/embeddingProvider.js +40 -23
  15. package/dist/eval.js +1 -2
  16. package/dist/events.js +1 -2
  17. package/dist/executableModalities.js +1 -2
  18. package/dist/gateway.js +1 -2
  19. package/dist/gatewayCatalog.js +1 -2
  20. package/dist/gatewayMedia.js +1 -2
  21. package/dist/index.d.ts +49 -2
  22. package/dist/index.js +41 -41
  23. package/dist/inferenceDispatch.js +1 -2
  24. package/dist/inferenceQueue.js +1 -2
  25. package/dist/jsonOutputValidation.js +1 -2
  26. package/dist/mcpClient.js +1 -2
  27. package/dist/mcpTools.js +1 -2
  28. package/dist/media.js +1 -2
  29. package/dist/mediaBytes.js +1 -2
  30. package/dist/mediaCall.js +1 -2
  31. package/dist/mediaTaskProvider.js +1 -2
  32. package/dist/middleware.js +1 -2
  33. package/dist/observe.js +1 -2
  34. package/dist/prompts.js +1 -2
  35. package/dist/provider.js +85 -70
  36. package/dist/realtimeEvent.js +1 -2
  37. package/dist/realtimeSession.js +1 -2
  38. package/dist/rerank.js +1 -2
  39. package/dist/resumableStream.js +2 -3
  40. package/dist/retrieveReranked.js +1 -2
  41. package/dist/runAndPersist.js +47 -49
  42. package/dist/semanticCache.js +1 -2
  43. package/dist/speechProvider.js +1 -2
  44. package/dist/streamRegistry.js +1 -2
  45. package/dist/streamText.js +1 -2
  46. package/dist/streamTranscribe.js +1 -2
  47. package/dist/streamWakeups.js +1 -2
  48. package/dist/structuredEvidence.js +1 -2
  49. package/dist/test.js +1 -2
  50. package/dist/threads.js +1 -2
  51. package/dist/tools.js +1 -2
  52. package/dist/transcribe.js +1 -2
  53. package/dist/transcriptionEvent.js +1 -2
  54. package/dist/workflow.js +1 -2
  55. package/package.json +13 -12
package/dist/agent.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { AGENT_MESSAGES_TABLE as e } from "./agentConstants.js";
2
2
  import { Schema as t } from "effect";
3
3
  import { defineAction as n, defineQuery as r } from "@voltro/protocol";
4
- //#region src/agentDescriptor.ts
4
+ // src/agentDescriptor.ts
5
5
  var i = t.Struct({ prompt: t.String }), a = "@voltro/ai/AgentDescriptor", o = class extends t.TaggedError()("AgentThreadAccessDenied", { threadId: t.String }) {
6
6
  get message() {
7
7
  return `agent thread '${this.threadId}' belongs to another subject`;
@@ -60,5 +60,4 @@ var i = t.Struct({ prompt: t.String }), a = "@voltro/ai/AgentDescriptor", o = cl
60
60
  })
61
61
  };
62
62
  };
63
- //#endregion
64
63
  export { o as AgentThreadAccessDenied, l as agentInputSchema, d as agentMessageSchema, p as agentRouteDescriptors, s as defineAgent, c as isAgentDescriptor };
@@ -1,4 +1,3 @@
1
- //#region src/agentConstants.ts
1
+ // src/agentConstants.ts
2
2
  var e = "_voltro_agent_threads", t = "_voltro_agent_messages";
3
- //#endregion
4
3
  export { t as AGENT_MESSAGES_TABLE, e as AGENT_THREADS_TABLE };
@@ -1,51 +1,54 @@
1
- import { AgentThreadAccessDenied as e } from "./agent.js";
2
- import { appendMessage as t, ensureThreadOwned as n, getMessages as r, getThread as i } from "./threads.js";
3
- import { historyToModelMessages as a, runAssistant as o } from "./runAndPersist.js";
4
- import { Effect as s } from "effect";
5
- //#region src/agentExecutor.ts
6
- var c = "@voltro/ai/AgentExecutor", l = (e, t) => ({
7
- _brand: c,
1
+ import { providerFromEnv as e } from "./provider.js";
2
+ import { AgentThreadAccessDenied as t } from "./agent.js";
3
+ import { appendMessage as n, ensureThreadOwned as r, getMessages as i, getThread as a } from "./threads.js";
4
+ import { historyToModelMessages as o, runAssistant as s } from "./runAndPersist.js";
5
+ import { Effect as c } from "effect";
6
+ // src/agentExecutor.ts
7
+ var l = "@voltro/ai/AgentExecutor", u = (e, t) => ({
8
+ _brand: l,
8
9
  descriptor: e,
9
10
  config: t
10
- }), u = (e) => typeof e == "object" && !!e && e._brand === c, d = (e, t) => {
11
+ }), d = (e) => typeof e == "object" && !!e && e._brand === l, f = (e, t) => {
11
12
  let n = e.config.system;
12
13
  if (n !== void 0) return typeof n == "function" ? n(t) : n;
13
- }, f = (e, t) => {
14
+ }, p = (e, t) => {
14
15
  let n = e.config.model;
15
16
  return typeof n == "function" ? n(t) : n;
16
- }, p = (e, i, c) => s.gen(function* () {
17
- yield* n(i, {
18
- threadId: c.threadId,
19
- subjectId: c.subjectId ?? null,
20
- tenantId: c.tenantId ?? null
17
+ }, m = (t, a, l) => c.gen(function* () {
18
+ yield* r(a, {
19
+ threadId: l.threadId,
20
+ subjectId: l.subjectId ?? null,
21
+ tenantId: l.tenantId ?? null
21
22
  });
22
- let s = c.promptOf ? c.promptOf(c.input) : String(c.input?.prompt ?? ""), l = d(e, c.input), u = f(e, c.input);
23
- yield* t(i, {
24
- threadId: c.threadId,
23
+ let u = l.promptOf ? l.promptOf(l.input) : String(l.input?.prompt ?? ""), d = f(t, l.input), m = p(t, l.input) ?? (yield* c.try({
24
+ try: () => e(),
25
+ catch: (e) => e instanceof Error ? e : Error(String(e))
26
+ }));
27
+ yield* n(a, {
28
+ threadId: l.threadId,
25
29
  role: "user",
26
- content: s,
27
- tenantId: c.tenantId ?? null,
28
- order: c.order
30
+ content: u,
31
+ tenantId: l.tenantId ?? null,
32
+ order: l.order
29
33
  });
30
- let p = yield* r(i, c.threadId), m = a(p);
31
- return yield* o(i, {
32
- threadId: c.threadId,
33
- tenantId: c.tenantId ?? null,
34
- prompt: s,
35
- ...m.length > 0 ? { messages: m } : {},
36
- ...l === void 0 ? {} : { system: l },
37
- ...e.config.tools === void 0 ? {} : { tools: e.config.tools },
38
- ...u === void 0 ? {} : { provider: u },
39
- ...e.config.maxSteps === void 0 ? {} : { maxSteps: e.config.maxSteps },
40
- ...e.config.providerOptions === void 0 ? {} : { providerOptions: e.config.providerOptions },
41
- ...c.toolContext === void 0 ? {} : { toolContext: c.toolContext },
42
- order: c.order + 1,
43
- ...c.throttleMs === void 0 ? {} : { throttleMs: c.throttleMs },
44
- agent: e.descriptor.name
34
+ let h = yield* i(a, l.threadId), g = o(h);
35
+ return yield* s(a, {
36
+ threadId: l.threadId,
37
+ tenantId: l.tenantId ?? null,
38
+ prompt: u,
39
+ ...g.length > 0 ? { messages: g } : {},
40
+ ...d === void 0 ? {} : { system: d },
41
+ ...t.config.tools === void 0 ? {} : { tools: t.config.tools },
42
+ provider: m,
43
+ ...t.config.maxSteps === void 0 ? {} : { maxSteps: t.config.maxSteps },
44
+ ...t.config.providerOptions === void 0 ? {} : { providerOptions: t.config.providerOptions },
45
+ ...l.toolContext === void 0 ? {} : { toolContext: l.toolContext },
46
+ order: l.order + 1,
47
+ ...l.throttleMs === void 0 ? {} : { throttleMs: l.throttleMs },
48
+ agent: t.descriptor.name
45
49
  });
46
- }), m = (t, n, a = null) => s.gen(function* () {
47
- let o = yield* i(t, n);
48
- return o !== null && o.subjectId !== null && o.subjectId !== a ? yield* s.fail(new e({ threadId: n })) : yield* r(t, n);
50
+ }), h = (e, n, r = null) => c.gen(function* () {
51
+ let o = yield* a(e, n);
52
+ return o !== null && o.subjectId !== null && o.subjectId !== r ? yield* c.fail(new t({ threadId: n })) : yield* i(e, n);
49
53
  });
50
- //#endregion
51
- export { l as defineAgentExecutor, u as isAgentExecutor, m as loadAgentMessages, f as resolveAgentModel, d as resolveSystem, p as runAgentTurn };
54
+ export { u as defineAgentExecutor, d as isAgentExecutor, h as loadAgentMessages, p as resolveAgentModel, f as resolveSystem, m as runAgentTurn };
@@ -0,0 +1,10 @@
1
+ import { readEnvValue as e } from "@voltro/env";
2
+ // src/aiSettings.ts
3
+ var t = (t, n) => {
4
+ let r = e(t);
5
+ if (typeof r == "string" && r !== "") return r;
6
+ if (typeof r == "number" || typeof r == "boolean") return String(r);
7
+ let i = n[t];
8
+ return i === void 0 || i === "" ? void 0 : i;
9
+ }, n = (e) => e.NODE_ENV === "production";
10
+ export { t as aiSetting, n as isProductionEnv };
package/dist/api.js CHANGED
@@ -7,7 +7,7 @@ import { captureStructuredEvidence as c } from "./structuredEvidence.js";
7
7
  import { NoObjectGeneratedError as l, Output as u, generateObject as d, generateText as f, jsonSchema as p, stepCountIs as m } from "ai";
8
8
  import { Context as h, Effect as g, Schema as _ } from "effect";
9
9
  import { jsonSchemaOf as v } from "@voltro/protocol";
10
- //#region src/api.ts
10
+ // src/api.ts
11
11
  var y = class extends _.TaggedError()("AiError", {
12
12
  reason: _.Literals(["generation", "decode"]),
13
13
  message: _.String,
@@ -195,5 +195,4 @@ var y = class extends _.TaggedError()("AiError", {
195
195
  generateText: (e) => C(e),
196
196
  generateObject: (e) => D(e)
197
197
  };
198
- //#endregion
199
198
  export { y as AiError, k as AiService, b as aiGenerationError, A as defaultAiService, D as generateObject, E as generateObjectJson, O as generateObjectWithTools, C as generateText, T as outputJsonSchema };
package/dist/appTools.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { defineTool as e } from "./tools.js";
2
- //#region src/appTools.ts
2
+ // src/appTools.ts
3
3
  var t = /* @__PURE__ */ new Map(), n = (e) => {
4
4
  let n = t.get(e);
5
5
  if (n !== void 0) return n;
@@ -76,5 +76,4 @@ var t = /* @__PURE__ */ new Map(), n = (e) => {
76
76
  ...t.descriptor.output === void 0 ? {} : { output: t.descriptor.output },
77
77
  handler: (e) => Promise.resolve(t.invoke(e))
78
78
  }));
79
- //#endregion
80
79
  export { s as agentActor, l as appToolDecision, d as appTools, a as passesPolicy, u as synthesizeToolSpecs };
package/dist/budget.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Effect as e, Schema as t } from "effect";
2
2
  import { and as n, bigint as r, eq as i, generateId as a, id as o, isNull as s, queryFor as c, registerRetention as l, retentionTtlMsFromEnv as u, table as d, text as f, timestamp as p } from "@voltro/database";
3
- //#region src/budget.ts
3
+ // src/budget.ts
4
4
  var m = class extends t.TaggedError()("AiBudgetExceeded", {
5
5
  tenantId: t.NullOr(t.String),
6
6
  limitUsd: t.Number,
@@ -197,5 +197,4 @@ var m = class extends t.TaggedError()("AiBudgetExceeded", {
197
197
  return "released";
198
198
  }));
199
199
  });
200
- //#endregion
201
200
  export { v as AI_BUDGET_RESERVATIONS_TABLE, _ as AI_BUDGET_TABLE, m as AiBudgetExceeded, h as AiBudgetInvalidInput, g as AiBudgetReservationConflict, b as aiBudgetReservationsTable, y as aiBudgetTable, A as releaseAiBudget, k as requireAiBudget };
@@ -1,6 +1,6 @@
1
1
  import { gatewayCostUsd as e } from "./cost.js";
2
2
  import { Schema as t } from "effect";
3
- //#region src/callEvidence.ts
3
+ // src/callEvidence.ts
4
4
  var n = t.Number.pipe(t.check(t.isInt()), t.check(t.isGreaterThanOrEqualTo(0)), t.check(t.isLessThanOrEqualTo(2 ** 53 - 1))), r = t.Struct({
5
5
  provider: t.String,
6
6
  model: t.String,
@@ -47,5 +47,4 @@ var n = t.Number.pipe(t.check(t.isInt()), t.check(t.isGreaterThanOrEqualTo(0)),
47
47
  }
48
48
  };
49
49
  };
50
- //#endregion
51
50
  export { r as AiCallEvidenceSchema, a as normalizeAiCallEvidence };
package/dist/copilot.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Schema as e } from "effect";
2
2
  import { and as t, contains as n, eq as r, gt as i, gte as a, inSet as o, lt as s, lte as c, neq as l } from "@voltro/database";
3
- //#region src/copilot.ts
3
+ // src/copilot.ts
4
4
  var u = class extends e.TaggedError()("CopilotRejected", {
5
5
  reason: e.Literals([
6
6
  "unknown-table",
@@ -122,5 +122,4 @@ var u = class extends e.TaggedError()("CopilotRejected", {
122
122
  prompt: e
123
123
  }), t);
124
124
  };
125
- //#endregion
126
125
  export { d as COPILOT_MAX_LIMIT, _ as CopilotProposalSchema, u as CopilotRejected, v as buildCopilotSystemPrompt, y as runDataCopilot, g as validateCopilotProposal };
package/dist/cost.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { AI_BUDGET_RESERVATIONS_TABLE as e, AI_BUDGET_TABLE as t, AiBudgetExceeded as n, AiBudgetInvalidInput as r, AiBudgetReservationConflict as i, aiBudgetReservationsTable as a, aiBudgetTable as o, releaseAiBudget as s, requireAiBudget as c } from "./budget.js";
2
2
  import { Data as l, Effect as u } from "effect";
3
3
  import { and as d, eq as f, generateId as p, gte as m, id as h, integer as g, queryFor as _, registerRetention as v, retentionTtlMsFromEnv as y, table as b, text as x, timestamp as S } from "@voltro/database";
4
- //#region src/cost.ts
4
+ // src/cost.ts
5
5
  var C = {
6
6
  "claude-opus-4-8": {
7
7
  inputPer1M: 15,
@@ -238,5 +238,4 @@ var C = {
238
238
  ], r = _(M), i = n.length === 0 ? r : r.where(n.length === 1 ? n[0] : d(...n));
239
239
  return (await e.query(i.descriptor)).reduce((e, t) => e + (Number(t.costMicroUsd) || 0), 0) / 1e6;
240
240
  });
241
- //#endregion
242
241
  export { e as AI_BUDGET_RESERVATIONS_TABLE, t as AI_BUDGET_TABLE, j as AI_USAGE_TABLE, n as AiBudgetExceeded, r as AiBudgetInvalidInput, i as AiBudgetReservationConflict, I as AiUsageLedgerError, F as AiUsageReceiptConflict, C as MODEL_PRICING_DEFAULTS, a as aiBudgetReservationsTable, o as aiBudgetTable, V as aiSpendUsd, M as aiUsageTable, A as estimateCostUsd, P as gatewayCostUsd, O as isMeteredUsage, E as modelPricing, k as normaliseUsage, D as priceForModel, R as recordAiUsage, B as recordAiUsageBestEffort, s as releaseAiBudget, c as requireAiBudget, T as setModelPricing };
package/dist/embed.js CHANGED
@@ -2,7 +2,7 @@ import { aiGenerationError as e } from "./api.js";
2
2
  import { embeddingProviderFromEnv as t, resolveEmbeddingModel as n } from "./embeddingProvider.js";
3
3
  import { cosineSimilarity as r, embed as i, embedMany as a } from "ai";
4
4
  import { Effect as o } from "effect";
5
- //#region src/embed.ts
5
+ // src/embed.ts
6
6
  var s = (r, a) => o.tryPromise({
7
7
  try: async (e) => {
8
8
  let o = a ?? t();
@@ -37,5 +37,4 @@ var s = (r, a) => o.tryPromise({
37
37
  if (t !== void 0 && e.length !== t) throw Error(`embedding ${n}: expected ${t} dimensions, received ${e.length}`);
38
38
  if (e.length === 0 || e.some((e) => !Number.isFinite(e))) throw Error(`embedding ${n}: expected a non-empty vector of finite numbers`);
39
39
  }, d = (e, t) => r([...e], [...t]);
40
- //#endregion
41
40
  export { d as cosineSimilarity, s as embed, c as embedMany };
@@ -1,17 +1,18 @@
1
- import { createGateway as e, gateway as t } from "@ai-sdk/gateway";
2
- //#region src/embeddingProvider.ts
3
- var n = (e, t) => ({
1
+ import { aiSetting as e, isProductionEnv as t } from "./aiSettings.js";
2
+ import { createGateway as n, gateway as r } from "@ai-sdk/gateway";
3
+ // src/embeddingProvider.ts
4
+ var i = (e, t) => ({
4
5
  specificationVersion: "v4",
5
6
  provider: "mock",
6
7
  modelId: e,
7
8
  maxEmbeddingsPerCall: 2048,
8
9
  supportsParallelCalls: !0,
9
10
  doEmbed: async ({ values: e }) => ({
10
- embeddings: e.map((e) => r(e, t)),
11
+ embeddings: e.map((e) => a(e, t)),
11
12
  usage: { tokens: e.reduce((e, t) => e + t.length, 0) },
12
13
  warnings: []
13
14
  })
14
- }), r = (e, t) => {
15
+ }), a = (e, t) => {
15
16
  let n = Array(t);
16
17
  for (let r = 0; r < t; r++) {
17
18
  let t = 2166136261 ^ r * 16777619;
@@ -19,18 +20,18 @@ var n = (e, t) => ({
19
20
  n[r] = (t >>> 0) / 4294967295 * 2 - 1;
20
21
  }
21
22
  return n;
22
- }, i = async (r) => {
23
- switch (r.name) {
24
- case "mock": return n(r.model, r.mockDim ?? 8);
25
- case "openai": return (await a("@ai-sdk/openai", "openai")).openai.textEmbeddingModel(r.model);
26
- case "voyage": return (await a("voyage-ai-provider", "voyage")).voyage.textEmbeddingModel(r.model);
27
- case "cohere": return (await a("@ai-sdk/cohere", "cohere")).cohere.textEmbeddingModel(r.model);
28
- case "gateway": return (r.apiKey !== void 0 || r.baseURL !== void 0 ? e({
29
- ...r.apiKey === void 0 ? {} : { apiKey: r.apiKey },
30
- ...r.baseURL === void 0 ? {} : { baseURL: r.baseURL }
31
- }) : t).embeddingModel(r.model);
23
+ }, o = async (e) => {
24
+ switch (e.name) {
25
+ case "mock": return i(e.model, e.mockDim ?? 8);
26
+ case "openai": return (await s("@ai-sdk/openai", "openai")).openai.textEmbeddingModel(e.model);
27
+ case "voyage": return (await s("voyage-ai-provider", "voyage")).voyage.textEmbeddingModel(e.model);
28
+ case "cohere": return (await s("@ai-sdk/cohere", "cohere")).cohere.textEmbeddingModel(e.model);
29
+ case "gateway": return (e.apiKey !== void 0 || e.baseURL !== void 0 ? n({
30
+ ...e.apiKey === void 0 ? {} : { apiKey: e.apiKey },
31
+ ...e.baseURL === void 0 ? {} : { baseURL: e.baseURL }
32
+ }) : r).embeddingModel(e.model);
32
33
  }
33
- }, a = async (e, t) => {
34
+ }, s = async (e, t) => {
34
35
  try {
35
36
  return await import(
36
37
  /* @vite-ignore */
@@ -39,13 +40,29 @@ var n = (e, t) => ({
39
40
  } catch {
40
41
  throw Error(`embedding provider '${t}' needs the '${e}' package — install it (pnpm add ${e}) or use AI_EMBED_PROVIDER=mock for tests/demos.`);
41
42
  }
42
- }, o = (e = process.env) => {
43
- let t = (e.AI_EMBED_PROVIDER ?? "mock").toLowerCase(), n = t === "openai" ? "text-embedding-3-small" : t === "voyage" ? "voyage-3" : t === "cohere" ? "embed-english-v3.0" : t === "gateway" ? "openai/text-embedding-3-small" : "mock", r = e.AI_EMBED_MODEL ?? n, i = e.AI_EMBED_MOCK_DIM === void 0 ? void 0 : Number(e.AI_EMBED_MOCK_DIM);
43
+ }, c = (e) => {
44
+ switch (e.toLowerCase()) {
45
+ case "openai": return "OPENAI_API_KEY";
46
+ case "gateway": return "AI_GATEWAY_API_KEY";
47
+ default: return;
48
+ }
49
+ }, l = (t = process.env) => {
50
+ let n = e("AI_EMBED_PROVIDER", t);
51
+ return n === void 0 ? {
52
+ name: "mock",
53
+ chosen: !1
54
+ } : {
55
+ name: n.toLowerCase(),
56
+ chosen: !0
57
+ };
58
+ }, u = (n = process.env) => {
59
+ let r = l(n);
60
+ if (!r.chosen && t(n)) throw Error("No embedding provider is chosen in this production process: AI_EMBED_PROVIDER is unset and this call passes no config, so it would embed with the mock provider, whose vectors carry no meaning. Set AI_EMBED_PROVIDER (openai | voyage | cohere | gateway) for every process that embeds, or declare it in `defineEnv` with a `default`, or pass a config to the call. Set AI_EMBED_PROVIDER=mock to embed with the mock deliberately.");
61
+ let i = r.name, a = i === "openai" ? "text-embedding-3-small" : i === "voyage" ? "voyage-3" : i === "cohere" ? "embed-english-v3.0" : i === "gateway" ? "openai/text-embedding-3-small" : "mock", o = e("AI_EMBED_MODEL", n) ?? a, s = e("AI_EMBED_MOCK_DIM", n), c = s === void 0 ? void 0 : Number(s);
44
62
  return {
45
- name: t,
46
- model: r,
47
- ...i !== void 0 && Number.isFinite(i) ? { mockDim: i } : {}
63
+ name: i,
64
+ model: o,
65
+ ...c !== void 0 && Number.isFinite(c) ? { mockDim: c } : {}
48
66
  };
49
67
  };
50
- //#endregion
51
- export { o as embeddingProviderFromEnv, r as hashToVector, i as resolveEmbeddingModel };
68
+ export { l as embeddingProviderChoice, u as embeddingProviderFromEnv, c as embeddingProviderKeyEnvVar, a as hashToVector, o as resolveEmbeddingModel };
package/dist/eval.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { providerFromEnv as e } from "./provider.js";
2
2
  import { generateObject as t } from "./api.js";
3
3
  import { Effect as n, Schema as r } from "effect";
4
- //#region src/eval.ts
4
+ // src/eval.ts
5
5
  var i = (e) => {
6
6
  if (e.name.trim() === "") throw Error("defineEval: name must be non-empty");
7
7
  if (e.cases.length === 0) throw Error(`defineEval "${e.name}": at least one case is required`);
@@ -126,5 +126,4 @@ var i = (e) => {
126
126
  score: 0,
127
127
  reason: `judge failed: ${e.message}`
128
128
  }))));
129
- //#endregion
130
129
  export { s as DEFAULT_JUDGE_THRESHOLD, i as defineEval, o as evaluateAssertions, a as isEvalDefinition, f as llmJudge, l as runEval, c as scoreCase };
package/dist/events.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { TranscriptionStreamError as e, TranscriptionStreamEvent as t } from "./transcriptionEvent.js";
2
2
  import { RealtimeClientEvent as n, RealtimeServerEvent as r } from "./realtimeEvent.js";
3
3
  import { Schema as i } from "effect";
4
- //#region src/agentEvent.ts
4
+ // src/agentEvent.ts
5
5
  var a = i.Literals([
6
6
  "provider",
7
7
  "tool",
@@ -77,5 +77,4 @@ var a = i.Literals([
77
77
  seq: i.Number,
78
78
  event: s
79
79
  });
80
- //#endregion
81
80
  export { a as AgentErrorCode, s as AgentEvent, n as RealtimeClientEvent, r as RealtimeServerEvent, c as SeqEvent, e as TranscriptionStreamError, t as TranscriptionStreamEvent };
@@ -1,4 +1,4 @@
1
- //#region src/executableModalities.ts
1
+ // src/executableModalities.ts
2
2
  var e = {
3
3
  language: "generateText / generateObject / streamText",
4
4
  embedding: "embed / embedMany",
@@ -9,5 +9,4 @@ var e = {
9
9
  transcription: "transcribe",
10
10
  realtime: "defineRealtimeSession / resolveRealtimeModel"
11
11
  }, t = () => new Set(Object.keys(e)), n = (e) => t().has(e.modality);
12
- //#endregion
13
12
  export { e as MODALITY_PRIMITIVE, n as canExecute, t as executableModalities };
package/dist/gateway.js CHANGED
@@ -1,6 +1,6 @@
1
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
2
  import { createGateway as c, gateway as l } from "@ai-sdk/gateway";
3
- //#region src/gateway.ts
3
+ // src/gateway.ts
4
4
  var u = (e) => {
5
5
  if (e === void 0) return;
6
6
  let t = Number(e);
@@ -54,5 +54,4 @@ var u = (e) => {
54
54
  raw: c
55
55
  };
56
56
  };
57
- //#endregion
58
57
  export { h as fromRaw, f as getAvailableModels, m as readGatewayCatalog, d as toModelInfo };
@@ -1,4 +1,4 @@
1
- //#region src/gatewayCatalog.ts
1
+ // src/gatewayCatalog.ts
2
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
3
  let n = t(e);
4
4
  if (n === void 0) return;
@@ -43,5 +43,4 @@ var e = (e) => Array.isArray(e) ? e.filter((e) => typeof e == "string") : [], t
43
43
  "evaluation"
44
44
  ].includes(t) ? t : "unknown";
45
45
  };
46
- //#endregion
47
46
  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 };
@@ -1,5 +1,5 @@
1
1
  import { createGateway as e } from "@ai-sdk/gateway";
2
- //#region src/gatewayMedia.ts
2
+ // src/gatewayMedia.ts
3
3
  var t = (e, t) => {
4
4
  let n = Object.fromEntries(Object.entries(t).filter(([, e]) => e !== void 0));
5
5
  return {
@@ -84,5 +84,4 @@ var t = (e, t) => {
84
84
  ...e,
85
85
  fetch: async (n, r) => l(await (e.fetch ?? globalThis.fetch)(n, r), t)
86
86
  });
87
- //#endregion
88
87
  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
@@ -1214,6 +1214,13 @@ export declare const dispatchInferences: (deps: InferenceDispatchDeps, options?:
1214
1214
  */
1215
1215
  export declare const embed: (text: string, config?: EmbeddingProviderConfig) => Effect.Effect<ReadonlyArray<number>, AiError>;
1216
1216
 
1217
+ /**
1218
+ * The embedding provider a call without a config resolves to, and whether
1219
+ * anybody chose it (`AI_EMBED_PROVIDER`, declared in `defineEnv` or set).
1220
+ * `chosen: false` is the mock fallback.
1221
+ */
1222
+ export declare const embeddingProviderChoice: (env?: Readonly<Record<string, string | undefined>>) => ProviderChoice;
1223
+
1217
1224
  export declare interface EmbeddingProviderConfig {
1218
1225
  readonly name: EmbeddingProviderName;
1219
1226
  /** Model id. For 'openai': e.g. 'text-embedding-3-small'; for 'gateway' a
@@ -1237,13 +1244,24 @@ export declare interface EmbeddingProviderConfig {
1237
1244
  }
1238
1245
 
1239
1246
  /**
1240
- * Read the embedding-provider config from env:
1241
- * AI_EMBED_PROVIDER=mock|openai|voyage|cohere|gateway (default: mock)
1247
+ * Read the embedding-provider config from env — a value declared in
1248
+ * `defineEnv` (its `default` included) before the raw variable:
1249
+ * AI_EMBED_PROVIDER=mock|openai|voyage|cohere|gateway (default: mock —
1250
+ * refused in production)
1242
1251
  * AI_EMBED_MODEL=<model-id> (default per provider)
1243
1252
  * AI_EMBED_MOCK_DIM=<n> (mock-only, default 8)
1244
1253
  */
1245
1254
  export declare const embeddingProviderFromEnv: (env?: Record<string, string | undefined>) => EmbeddingProviderConfig;
1246
1255
 
1256
+ /**
1257
+ * The env var an embedding provider's SDK reads its key from, for the
1258
+ * providers whose SDK this package resolves by default — `openai` through
1259
+ * `@ai-sdk/openai`, `gateway` through `@ai-sdk/gateway`. `undefined` for the
1260
+ * mock, and for the optional `voyage` / `cohere` packages, whose variable the
1261
+ * boot gate cannot vouch for.
1262
+ */
1263
+ export declare const embeddingProviderKeyEnvVar: (name: string) => string | undefined;
1264
+
1247
1265
  export declare type EmbeddingProviderName = 'mock' | 'openai' | 'voyage' | 'cohere' | 'gateway';
1248
1266
 
1249
1267
  /**
@@ -2858,6 +2876,22 @@ export declare interface PromptVersionRow {
2858
2876
  /** Every registered version of one prompt, newest revision first. */
2859
2877
  export declare const promptVersionsFor: (store: DataStore, promptId: string) => Effect.Effect<ReadonlyArray<PromptVersionRow>>;
2860
2878
 
2879
+ /** The provider a call without `provider` resolves to, and whether anybody
2880
+ * chose it — `useMockAi`, `AI_PROVIDER`, or the app's `defineEnv` declaration.
2881
+ * `chosen: false` is the mock fallback. */
2882
+ export declare interface ProviderChoice {
2883
+ readonly name: string;
2884
+ readonly chosen: boolean;
2885
+ }
2886
+
2887
+ /**
2888
+ * Which provider is in effect. ONE resolution, exported, so the boot gate that
2889
+ * checks the provider's key checks the provider the calls actually use — the
2890
+ * gate read raw `AI_PROVIDER` while an app's declared default was the value it
2891
+ * meant.
2892
+ */
2893
+ export declare const providerChoice: (env?: Readonly<Record<string, string | undefined>>) => ProviderChoice;
2894
+
2861
2895
  /**
2862
2896
  * A resolved provider choice — a DISCRIMINATED UNION on `name`. Each provider
2863
2897
  * only carries the fields that apply to it: the mock-only `mockText` / `script`
@@ -2939,6 +2973,19 @@ export declare type ProviderConfig = {
2939
2973
  */
2940
2974
  export declare type ProviderFallbacks = ReadonlyArray<ProviderConfig>;
2941
2975
 
2976
+ /**
2977
+ * Read the provider config. The process-global override (set by `useMockAi`)
2978
+ * wins over env. Otherwise honours, a value declared in `defineEnv` (its
2979
+ * `default` included) before the raw variable:
2980
+ * AI_PROVIDER=mock|anthropic|openai|gateway (default: mock — refused in
2981
+ * a production process, where nobody chose it)
2982
+ * AI_MODEL=<model-id> (default per provider: 'claude-opus-4-8' for
2983
+ * anthropic, 'gpt-5.5' for openai, 'mock' for mock;
2984
+ * REQUIRED for gateway — a `creator/model` id)
2985
+ *
2986
+ * Provider keys are read by the underlying AI SDK packages from their standard
2987
+ * env vars: ANTHROPIC_API_KEY, OPENAI_API_KEY, AI_GATEWAY_API_KEY.
2988
+ */
2942
2989
  export declare const providerFromEnv: (env?: Record<string, string | undefined>) => ProviderConfig;
2943
2990
 
2944
2991
  /**