@broberg/ai-sdk 0.75.1 → 0.76.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.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { U as Usage, C as CostSink, T as Tier, a as ChatResult, b as ChatStreamEvent, c as TranslateResult, I as ImageResult, A as AnimateResult, d as TrainStyleResult, E as EmbeddingResult, e as TranscribeResult, O as OcrResult, M as ModerationResult, J as JudgeResult, V as VectorizeResult, P as PodcastResult, B as BatchRequestItem, f as TierSpec, g as BatchJob, h as BatchResultItem, i as ProviderAdapter, j as ToolCall, k as Tool, l as Transport, m as Capability, R as Region, n as BudgetConfig, o as BudgetStore } from './registry-CsDDEHEr.js';
2
- export { p as AlignedWordTimings, q as AvailabilitySource, r as AvailabilityStatus, s as AzureWordBoundary, t as CallOptions, u as ChatRequest, v as ContentPart, D as DialogueRequest, w as DialogueTurn, x as EmbeddingRequest, y as ImageRequest, z as JudgeAnswer, F as JudgeChoiceAnswer, G as JudgeNoulAnswer, H as JudgeQuestion, K as JudgeScoreAnswer, L as LoraWeight, N as Message, Q as ModelStatus, S as ModelUnavailableError, W as ModerationItem, X as ModerationRequest, Y as OcrPage, Z as OcrRequest, _ as ResolveOptions, $ as ResolveResult, a0 as Role, a1 as TierDescription, a2 as TrainStyleRequest, a3 as TranscribeRequest, a4 as TtsRequest, a5 as WordTiming, a6 as alignWordTimings, a7 as classifyRegionName, a8 as describeTier, a9 as listModels, aa as regionOfHost, ab as regionOfProvider, ac as resolveModel } from './registry-CsDDEHEr.js';
1
+ import { U as Usage, C as CostSink, T as Tier, a as ChatResult, b as ChatStreamEvent, c as TranslateResult, I as ImageResult, A as AnimateResult, d as TrainStyleResult, E as EmbeddingResult, e as TranscribeResult, O as OcrResult, M as ModerationResult, J as JudgeResult, V as VectorizeResult, P as PodcastResult, B as BatchRequestItem, f as TierSpec, g as BatchJob, h as BatchResultItem, i as ProviderAdapter, j as ToolCall, k as Tool, l as Transport, m as Capability, R as Region, n as BudgetConfig, o as BudgetStore } from './registry-Bkh7DUFZ.js';
2
+ export { p as AlignedWordTimings, q as AvailabilitySource, r as AvailabilityStatus, s as AzureWordBoundary, t as CallOptions, u as ChatRequest, v as ContentPart, D as DialogueRequest, w as DialogueTurn, x as EmbeddingRequest, y as ImageRequest, z as JudgeAnswer, F as JudgeChoiceAnswer, G as JudgeNoulAnswer, H as JudgeQuestion, K as JudgeScoreAnswer, L as LoraWeight, N as Message, Q as ModelStatus, S as ModelUnavailableError, W as ModerationItem, X as ModerationRequest, Y as OcrPage, Z as OcrRequest, _ as ResolveOptions, $ as ResolveResult, a0 as Role, a1 as TierDescription, a2 as TrainStyleRequest, a3 as TranscribeRequest, a4 as TtsRequest, a5 as WordTiming, a6 as alignWordTimings, a7 as classifyRegionName, a8 as describeTier, a9 as listModels, aa as regionOfHost, ab as regionOfProvider, ac as resolveModel } from './registry-Bkh7DUFZ.js';
3
3
  import { z } from 'zod';
4
4
  export { CheapestQuery, CheapestResult, CheapestRow, DEFAULT_CLIP_SEC, MEDIA_PRICING_CHECKED_AT, MediaPrice, MediaUnit, PRICING_STALE_AFTER_DAYS, PriceKind, PricingFreshness, UnitFreshness, UpstreamStatus, cheapestModels, classifyKind, getMediaPrice, listMediaPrices, pricingFreshness, pricingGeneratedAt } from './pricing.js';
5
5
 
@@ -1294,6 +1294,15 @@ interface OpenRouterAdapterConfig {
1294
1294
  }
1295
1295
  declare function openrouterAdapter(config?: OpenRouterAdapterConfig): ProviderAdapter;
1296
1296
 
1297
+ /** Ollama's OpenAI-compatible endpoint on the same machine. */
1298
+ declare const LOCAL_EMBEDDING_DEFAULT_URL = "http://127.0.0.1:11434/v1";
1299
+ interface LocalAdapterConfig {
1300
+ /** Server base URL incl. /v1. Else env LOCAL_EMBEDDING_URL, else Ollama on 127.0.0.1. */
1301
+ baseUrl?: string;
1302
+ fetch?: typeof fetch;
1303
+ }
1304
+ declare function localAdapter(config?: LocalAdapterConfig): ProviderAdapter;
1305
+
1297
1306
  declare function requestyAdapter(config?: {
1298
1307
  apiKey?: string;
1299
1308
  baseUrl?: string;
@@ -1587,8 +1596,8 @@ declare const falStubAdapter: ProviderAdapter;
1587
1596
  * wires the live adapters. */
1588
1597
  declare const stubProviders: Record<string, ProviderAdapter>;
1589
1598
 
1590
- declare const VERSION: "0.75.1";
1591
- declare const SDK_TAG: "@broberg/ai-sdk@0.75.1";
1599
+ declare const VERSION: "0.76.0";
1600
+ declare const SDK_TAG: "@broberg/ai-sdk@0.76.0";
1592
1601
 
1593
1602
  /** Built-in defaults. Every entry is overridable via AiConfig.defaults or a
1594
1603
  * per-call override.
@@ -2157,4 +2166,4 @@ declare function memorySearchCache(max?: number): SearchCache;
2157
2166
 
2158
2167
  declare function search(req: SearchRequest, opts?: SearchOptions): Promise<SearchResult>;
2159
2168
 
2160
- export { AZURE_DANISH_VOICES, AZURE_DANISH_VOICE_LIST, AiAbortError, type AiClient, type AiConfig, AiTimeoutError, type AzureVoiceInfo, BatchJob, BatchRequestItem, BatchResultItem, type BflAdapterConfig, type BflCredits, BudgetConfig, BudgetExceededError, BudgetGuard, BudgetStore, CONFIG_DERIVED_HOSTS, Capability, type ChatInput, ChatResult, ChatStreamEvent, type CheckVoiceOptions, type ClassifyInput, type ClassifyResult, type Contracts, type CostQuery, CostSink, type CostSummary, type CostSummaryQuery, type CostTimeseriesQuery, DEFAULT_BASE_URLS, DEFAULT_SEARCH_ROUTES, DEFAULT_TIER_MAP, type DesignInput, type DesignResult, type DiscordSinkConfig, ELEVENLABS_DANISH_VOICES, type EmbeddingInput, EmbeddingResult, type ExtractInput, type ExtractResult, type FalAdapterConfig, type FixedHostProvider, type HttpResponse, INPUT_LIMITS, type ImageInput, ImageResult, type JudgeInput, JudgeResult, LOCALLY_PINNED_HOSTS, MICROSOFT_DECISION_DEFAULT_DEPLOYMENT, type MockupInput, type MockupResult, type ModerationInput, ModerationResult, type OcrInput, OcrResult, type OpenAICompatibleConfig, type Opinion, type PanelMember, type PodcastInput, PodcastResult, type PriceDriftResult, type PriceDriftRow, type PricingEntry, ProviderAdapter, type RefreshOptions, type RefreshResult, Region, type RerankInput, type RerankResult, type RouteForecast, SDK_TAG, SEARCH_CACHE_TTL_MS, SEARCH_PRICE_USD, SECOND_OPINION_DEFAULT_TIMEOUT_MS, SECOND_OPINION_INSTRUCTION, SECOND_OPINION_PANEL, SECOND_OPINION_SYNTH, SECOND_OPINION_SYNTH_INSTRUCTION, SearchBudgetExceededError, type SearchCache, type SearchCapStore, type SearchCredentials, type SearchItem, SearchKeyMissingError, type SearchOptions, type SearchProviderId, type SearchPurpose, type SearchRequest, type SearchResult, type SearchRoute, type SecondOpinionInput, type SecondOpinionResult, type SqliteBudgetStoreConfig, type SqliteSinkConfig, StreamHttpError, type SubprocessResponse, Tier, TierSpec, Tool, ToolCall, type TrainStyleInput, TrainStyleResult, type TranscribeInput, TranscribeResult, type TranslateInput, TranslateResult, Transport, type TransportRequest, type TransportResponse, type TtsInput, type UpmetricsCostClientConfig, UpmetricsCostError, type UpmetricsCostRow, type UpmetricsCostSummary, type UpmetricsCostTimeseries, type UpmetricsSink, type UpmetricsSinkConfig, type UpmetricsSinkStats, Usage, VERSION, type VideoInput, type VisionInput, type VoiceInfo, type VoiceProvider, type VoiceResolveResult, type VoiceStatus, VoiceUnavailableError, type WebSearchContext, type WebSearchToolResult, ZDR_PROVIDERS, aiConfigSchema, anthropicAdapter, anthropicApiAdapter, anthropicSubprocessAdapter, azureAdapter, bflAdapter, bflCredits, byokAdapter, chatInputSchema, checkPriceDrift, checkVoice, computeCost, createAI, deepinfraAdapter, deeplAdapter, deepseekAdapter, defaultBaseUrl, defaultProviders, discordSink, elevenlabsAdapter, embeddingInputSchema, falAdapter, falStubAdapter, freshUsage, fromProviderToolCall, geminiAdapter, getCostSummary, getPrice, httpTransport, imageInputSchema, isByokKeyed, listAzureDanishVoices, listVoices, makeContracts, makeOpenAICompatibleAdapter, matchLabel, memorySearchCache, messageSchema, microsoftDecisionAdapter, mistralAdapter, mistralStubAdapter, multiSink, noopSink, openaiAdapter, openaiStubAdapter, openrouterAdapter, parseClaudeCliJson, parseJsonLoose, recraftAdapter, refreshAvailability, requestyAdapter, resetRefreshState, resetRegistry, resolveAzureVoice, resolveTier, resolveVoice, routeSearch, runWebSearch, search, sqliteBudgetStore, sqliteSink, streamTransport, stubProviders, subprocessTransport, tierSpecSchema, toProviderTools, toolSchema, translateInputSchema, typesafeAdapter, upmetricsCostClient, upmetricsSink, usdFromMicro, vertexAdapter, visionInputSchema, webSearchTool, wouldProviderRouteTo, wouldRouteTo };
2169
+ export { AZURE_DANISH_VOICES, AZURE_DANISH_VOICE_LIST, AiAbortError, type AiClient, type AiConfig, AiTimeoutError, type AzureVoiceInfo, BatchJob, BatchRequestItem, BatchResultItem, type BflAdapterConfig, type BflCredits, BudgetConfig, BudgetExceededError, BudgetGuard, BudgetStore, CONFIG_DERIVED_HOSTS, Capability, type ChatInput, ChatResult, ChatStreamEvent, type CheckVoiceOptions, type ClassifyInput, type ClassifyResult, type Contracts, type CostQuery, CostSink, type CostSummary, type CostSummaryQuery, type CostTimeseriesQuery, DEFAULT_BASE_URLS, DEFAULT_SEARCH_ROUTES, DEFAULT_TIER_MAP, type DesignInput, type DesignResult, type DiscordSinkConfig, ELEVENLABS_DANISH_VOICES, type EmbeddingInput, EmbeddingResult, type ExtractInput, type ExtractResult, type FalAdapterConfig, type FixedHostProvider, type HttpResponse, INPUT_LIMITS, type ImageInput, ImageResult, type JudgeInput, JudgeResult, LOCALLY_PINNED_HOSTS, LOCAL_EMBEDDING_DEFAULT_URL, type LocalAdapterConfig, MICROSOFT_DECISION_DEFAULT_DEPLOYMENT, type MockupInput, type MockupResult, type ModerationInput, ModerationResult, type OcrInput, OcrResult, type OpenAICompatibleConfig, type Opinion, type PanelMember, type PodcastInput, PodcastResult, type PriceDriftResult, type PriceDriftRow, type PricingEntry, ProviderAdapter, type RefreshOptions, type RefreshResult, Region, type RerankInput, type RerankResult, type RouteForecast, SDK_TAG, SEARCH_CACHE_TTL_MS, SEARCH_PRICE_USD, SECOND_OPINION_DEFAULT_TIMEOUT_MS, SECOND_OPINION_INSTRUCTION, SECOND_OPINION_PANEL, SECOND_OPINION_SYNTH, SECOND_OPINION_SYNTH_INSTRUCTION, SearchBudgetExceededError, type SearchCache, type SearchCapStore, type SearchCredentials, type SearchItem, SearchKeyMissingError, type SearchOptions, type SearchProviderId, type SearchPurpose, type SearchRequest, type SearchResult, type SearchRoute, type SecondOpinionInput, type SecondOpinionResult, type SqliteBudgetStoreConfig, type SqliteSinkConfig, StreamHttpError, type SubprocessResponse, Tier, TierSpec, Tool, ToolCall, type TrainStyleInput, TrainStyleResult, type TranscribeInput, TranscribeResult, type TranslateInput, TranslateResult, Transport, type TransportRequest, type TransportResponse, type TtsInput, type UpmetricsCostClientConfig, UpmetricsCostError, type UpmetricsCostRow, type UpmetricsCostSummary, type UpmetricsCostTimeseries, type UpmetricsSink, type UpmetricsSinkConfig, type UpmetricsSinkStats, Usage, VERSION, type VideoInput, type VisionInput, type VoiceInfo, type VoiceProvider, type VoiceResolveResult, type VoiceStatus, VoiceUnavailableError, type WebSearchContext, type WebSearchToolResult, ZDR_PROVIDERS, aiConfigSchema, anthropicAdapter, anthropicApiAdapter, anthropicSubprocessAdapter, azureAdapter, bflAdapter, bflCredits, byokAdapter, chatInputSchema, checkPriceDrift, checkVoice, computeCost, createAI, deepinfraAdapter, deeplAdapter, deepseekAdapter, defaultBaseUrl, defaultProviders, discordSink, elevenlabsAdapter, embeddingInputSchema, falAdapter, falStubAdapter, freshUsage, fromProviderToolCall, geminiAdapter, getCostSummary, getPrice, httpTransport, imageInputSchema, isByokKeyed, listAzureDanishVoices, listVoices, localAdapter, makeContracts, makeOpenAICompatibleAdapter, matchLabel, memorySearchCache, messageSchema, microsoftDecisionAdapter, mistralAdapter, mistralStubAdapter, multiSink, noopSink, openaiAdapter, openaiStubAdapter, openrouterAdapter, parseClaudeCliJson, parseJsonLoose, recraftAdapter, refreshAvailability, requestyAdapter, resetRefreshState, resetRegistry, resolveAzureVoice, resolveTier, resolveVoice, routeSearch, runWebSearch, search, sqliteBudgetStore, sqliteSink, streamTransport, stubProviders, subprocessTransport, tierSpecSchema, toProviderTools, toolSchema, translateInputSchema, typesafeAdapter, upmetricsCostClient, upmetricsSink, usdFromMicro, vertexAdapter, visionInputSchema, webSearchTool, wouldProviderRouteTo, wouldRouteTo };
package/dist/index.js CHANGED
@@ -3539,6 +3539,52 @@ function recraftAdapter(config = {}) {
3539
3539
  return { name: "recraft", vectorize };
3540
3540
  }
3541
3541
 
3542
+ // src/providers/local.ts
3543
+ var LOCAL_EMBEDDING_DEFAULT_URL = "http://127.0.0.1:11434/v1";
3544
+ function localAdapter(config = {}) {
3545
+ const baseUrl = () => (config.baseUrl ?? env().LOCAL_EMBEDDING_URL ?? LOCAL_EMBEDDING_DEFAULT_URL).replace(/\/$/, "");
3546
+ async function embedding(req) {
3547
+ const url = baseUrl();
3548
+ const model = req.spec.model;
3549
+ let res;
3550
+ try {
3551
+ res = await httpTransport({
3552
+ spec: req.spec,
3553
+ fetch: config.fetch,
3554
+ // No key: a local server needs none, and none is ever sent.
3555
+ http: { url: `${url}/embeddings`, headers: { "content-type": "application/json" }, body: { model, input: req.input } }
3556
+ });
3557
+ } catch (e) {
3558
+ throw new Error(
3559
+ `local embedding server not reachable at ${url} (${e.message}). Start it (e.g. \`ollama serve\`) or set LOCAL_EMBEDDING_URL. Nothing was sent to any other provider.`,
3560
+ { cause: e }
3561
+ );
3562
+ }
3563
+ if (res.status === 404) {
3564
+ throw new Error(`local embedding model "${model}" is not available at ${url} \u2014 pull it first: \`ollama pull ${model}\`. (${errorBody(res.json, res.text)})`);
3565
+ }
3566
+ if (!res.ok) throw new Error(`local embedding ${res.status} at ${url}: ${errorBody(res.json, res.text)}`);
3567
+ const data = res.json;
3568
+ const vectors = (data.data ?? []).map((d) => d.embedding);
3569
+ if (vectors.length !== req.input.length) {
3570
+ throw new Error(`local embedding at ${url} returned ${vectors.length} vectors for ${req.input.length} inputs`);
3571
+ }
3572
+ const usage = freshUsage({
3573
+ provider: "local",
3574
+ model,
3575
+ transport: "http",
3576
+ capability: "embedding",
3577
+ region: regionOfHost(url),
3578
+ inputTokens: data.usage?.prompt_tokens ?? 0,
3579
+ outputTokens: 0
3580
+ });
3581
+ usage.costUsd = 0;
3582
+ usage.costBasis = "computed";
3583
+ return { vectors, usage };
3584
+ }
3585
+ return { name: "local", embedding };
3586
+ }
3587
+
3542
3588
  // src/providers/registry.ts
3543
3589
  var defaultProviders = {
3544
3590
  anthropic: anthropicAdapter(),
@@ -3557,7 +3603,9 @@ var defaultProviders = {
3557
3603
  "microsoft-decision": microsoftDecisionAdapter(),
3558
3604
  fal: falAdapter(),
3559
3605
  bfl: bflAdapter(),
3560
- recraft: recraftAdapter()
3606
+ recraft: recraftAdapter(),
3607
+ // F095 — embeddings on our own machines (Ollama), $0. Only via override; never a default.
3608
+ local: localAdapter()
3561
3609
  };
3562
3610
 
3563
3611
  // src/cost/budget.ts
@@ -4526,8 +4574,8 @@ var aiConfigSchema = z.object({
4526
4574
  import { randomUUID } from "crypto";
4527
4575
 
4528
4576
  // src/version.ts
4529
- var VERSION = "0.75.1";
4530
- var SDK_TAG = "@broberg/ai-sdk@0.75.1";
4577
+ var VERSION = "0.76.0";
4578
+ var SDK_TAG = "@broberg/ai-sdk@0.76.0";
4531
4579
 
4532
4580
  // src/cost/sinks/upmetrics.ts
4533
4581
  function isRetryableStatus(status) {
@@ -5495,7 +5543,8 @@ function createAI(config = {}) {
5495
5543
  invoke: async (spec) => {
5496
5544
  const adapter = pickProvider(spec.provider);
5497
5545
  if (!adapter.embedding) throw new Error(`createAI: provider "${spec.provider}" does not support embedding`);
5498
- return adapter.embedding({ input: text, spec });
5546
+ const r = await adapter.embedding({ input: text, spec });
5547
+ return { ...r, model: r.usage.model, dimensions: r.vectors[0]?.length ?? 0 };
5499
5548
  }
5500
5549
  });
5501
5550
  },
@@ -6148,6 +6197,7 @@ export {
6148
6197
  ELEVENLABS_DANISH_VOICES,
6149
6198
  INPUT_LIMITS,
6150
6199
  LOCALLY_PINNED_HOSTS,
6200
+ LOCAL_EMBEDDING_DEFAULT_URL,
6151
6201
  MEDIA_PRICING_CHECKED_AT,
6152
6202
  MICROSOFT_DECISION_DEFAULT_DEPLOYMENT,
6153
6203
  ModelUnavailableError,
@@ -6208,6 +6258,7 @@ export {
6208
6258
  listMediaPrices,
6209
6259
  listModels,
6210
6260
  listVoices,
6261
+ localAdapter,
6211
6262
  makeContracts,
6212
6263
  makeOpenAICompatibleAdapter,
6213
6264
  matchLabel,