@broberg/ai-sdk 0.54.0 → 0.54.1

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
@@ -2850,7 +2850,7 @@ interface OpenAICompatibleConfig {
2850
2850
  apiKey?: string;
2851
2851
  /** Extra headers (e.g. OpenRouter's HTTP-Referer / X-Title). */
2852
2852
  extraHeaders?: Record<string, string>;
2853
- /** Injectable fetch for the streaming path (tests). */
2853
+ /** Injectable fetch — used by BOTH the streaming and the non-streaming path (F073). */
2854
2854
  fetch?: typeof fetch;
2855
2855
  /** F049 — the provider understands `prefix: true` on a trailing assistant message.
2856
2856
  * Mistral only. A prefix sent anywhere else is REFUSED rather than dropped: a
@@ -2939,8 +2939,8 @@ declare const falStubAdapter: ProviderAdapter;
2939
2939
  * wires the live adapters. */
2940
2940
  declare const stubProviders: Record<string, ProviderAdapter>;
2941
2941
 
2942
- declare const VERSION: "0.54.0";
2943
- declare const SDK_TAG: "@broberg/ai-sdk@0.54.0";
2942
+ declare const VERSION: "0.54.1";
2943
+ declare const SDK_TAG: "@broberg/ai-sdk@0.54.1";
2944
2944
 
2945
2945
  /** Built-in defaults. Every entry is overridable via AiConfig.defaults or a
2946
2946
  * per-call override.
@@ -3391,6 +3391,10 @@ interface TransportRequest {
3391
3391
  spec: TierSpec;
3392
3392
  /** HTTP details — required when spec.transport === "http". The adapter has
3393
3393
  * already built the provider-specific URL/headers/body. */
3394
+ /** F073 — the fetch to use. Absent → the global fetch. An adapter given `fetch` in its
3395
+ * config MUST pass it here, or a test's fake fetch is silently bypassed and the call
3396
+ * reaches the real provider with whatever key is in the environment. */
3397
+ fetch?: typeof fetch;
3394
3398
  http?: {
3395
3399
  url: string;
3396
3400
  method?: string;
package/dist/index.js CHANGED
@@ -56,7 +56,7 @@ async function httpTransport(req) {
56
56
  throw new Error("httpTransport: req.http is required for http transport");
57
57
  }
58
58
  const { url, method = "POST", headers, body } = req.http;
59
- const res = await fetch(url, {
59
+ const res = await (req.fetch ?? fetch)(url, {
60
60
  method,
61
61
  headers,
62
62
  body: body === void 0 ? void 0 : typeof body === "string" ? body : JSON.stringify(body)
@@ -495,6 +495,7 @@ function anthropicAdapter(config = {}) {
495
495
  const body = buildBody(req);
496
496
  const res = await httpTransport({
497
497
  spec: req.spec,
498
+ fetch: config.fetch,
498
499
  http: {
499
500
  url: `${baseUrl}/v1/messages`,
500
501
  headers: {
@@ -774,6 +775,7 @@ function makeOpenAICompatibleAdapter(config) {
774
775
  const body = buildChatBody(req, config);
775
776
  const res = await httpTransport({
776
777
  spec: req.spec,
778
+ fetch: config.fetch,
777
779
  http: {
778
780
  url: `${config.baseUrl}/chat/completions`,
779
781
  headers: {
@@ -931,12 +933,13 @@ function mapFinishReason(reason) {
931
933
  // src/providers/openai.ts
932
934
  function openaiAdapter(config = {}) {
933
935
  const baseUrl = config.baseUrl ?? DEFAULT_BASE_URLS.openai;
934
- const base = makeOpenAICompatibleAdapter({ name: "openai", baseUrl, apiKey: config.apiKey });
936
+ const base = makeOpenAICompatibleAdapter({ name: "openai", baseUrl, apiKey: config.apiKey, fetch: config.fetch });
935
937
  async function embedding(req) {
936
938
  const apiKey = config.apiKey ?? process.env.OPENAI_API_KEY;
937
939
  if (!apiKey) throw new Error("openai adapter: API key not set (env OPENAI_API_KEY)");
938
940
  const res = await httpTransport({
939
941
  spec: req.spec,
942
+ fetch: config.fetch,
940
943
  http: {
941
944
  url: `${baseUrl}/embeddings`,
942
945
  headers: { "content-type": "application/json", Authorization: `Bearer ${apiKey}` },
@@ -1081,6 +1084,7 @@ function geminiAdapter(config = {}) {
1081
1084
  const body = buildBody(req);
1082
1085
  const res = await httpTransport({
1083
1086
  spec: req.spec,
1087
+ fetch: config.fetch,
1084
1088
  http: {
1085
1089
  url: `${baseUrl}/models/${req.spec.model}:generateContent?key=${encodeURIComponent(apiKey)}`,
1086
1090
  headers: { "content-type": "application/json" },
@@ -1376,7 +1380,7 @@ function deepseekAdapter(config = {}) {
1376
1380
  // src/providers/mistral.ts
1377
1381
  function mistralAdapter(config = {}) {
1378
1382
  const baseUrl = config.baseUrl ?? DEFAULT_BASE_URLS.mistral;
1379
- const base = makeOpenAICompatibleAdapter({ name: "mistral", baseUrl, apiKey: config.apiKey, supportsPromptCacheKey: true, supportsPrefix: true });
1383
+ const base = makeOpenAICompatibleAdapter({ name: "mistral", baseUrl, apiKey: config.apiKey, fetch: config.fetch, supportsPromptCacheKey: true, supportsPrefix: true });
1380
1384
  function key() {
1381
1385
  const k = config.apiKey ?? process.env.MISTRAL_API_KEY;
1382
1386
  if (!k) throw new Error("mistral adapter: API key not set (env MISTRAL_API_KEY)");
@@ -3526,8 +3530,8 @@ var aiConfigSchema = z.object({
3526
3530
  import { randomUUID } from "crypto";
3527
3531
 
3528
3532
  // src/version.ts
3529
- var VERSION = "0.54.0";
3530
- var SDK_TAG = "@broberg/ai-sdk@0.54.0";
3533
+ var VERSION = "0.54.1";
3534
+ var SDK_TAG = "@broberg/ai-sdk@0.54.1";
3531
3535
 
3532
3536
  // src/cost/sinks/upmetrics.ts
3533
3537
  function isRetryableStatus(status) {