@providerprotocol/ai 0.0.29 → 0.0.32

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 (42) hide show
  1. package/dist/anthropic/index.d.ts +12 -1
  2. package/dist/anthropic/index.js +15 -10
  3. package/dist/anthropic/index.js.map +1 -1
  4. package/dist/{chunk-Z6DKC37J.js → chunk-3C7O2RNO.js} +2 -2
  5. package/dist/{chunk-55X3W2MN.js → chunk-3D6XGGVG.js} +9 -2
  6. package/dist/{chunk-55X3W2MN.js.map → chunk-3D6XGGVG.js.map} +1 -1
  7. package/dist/{chunk-QNJO7DSD.js → chunk-4J6OFUKX.js} +10 -1
  8. package/dist/chunk-4J6OFUKX.js.map +1 -0
  9. package/dist/{chunk-73IIE3QT.js → chunk-6S222DHN.js} +11 -1
  10. package/dist/chunk-6S222DHN.js.map +1 -0
  11. package/dist/{chunk-SBCATNHA.js → chunk-KUPF5KHT.js} +2 -2
  12. package/dist/{embedding-DtyOFIsS.d.ts → embedding-D2BYIehX.d.ts} +22 -2
  13. package/dist/google/index.d.ts +5 -1
  14. package/dist/google/index.js +22 -13
  15. package/dist/google/index.js.map +1 -1
  16. package/dist/http/index.d.ts +8 -3
  17. package/dist/http/index.js +9 -5
  18. package/dist/index.d.ts +118 -6
  19. package/dist/index.js +641 -86
  20. package/dist/index.js.map +1 -1
  21. package/dist/{llm-DgDEy9il.d.ts → llm-BQJZj3cD.d.ts} +277 -10
  22. package/dist/ollama/index.d.ts +1 -1
  23. package/dist/ollama/index.js +32 -21
  24. package/dist/ollama/index.js.map +1 -1
  25. package/dist/openai/index.d.ts +1 -1
  26. package/dist/openai/index.js +21 -15
  27. package/dist/openai/index.js.map +1 -1
  28. package/dist/openrouter/index.d.ts +2 -2
  29. package/dist/openrouter/index.js +19 -8
  30. package/dist/openrouter/index.js.map +1 -1
  31. package/dist/proxy/index.d.ts +2 -2
  32. package/dist/proxy/index.js +9 -6
  33. package/dist/proxy/index.js.map +1 -1
  34. package/dist/{retry-DXLQnTuU.d.ts → retry-8Ch-WWgX.d.ts} +16 -2
  35. package/dist/xai/index.d.ts +16 -36
  36. package/dist/xai/index.js +29 -19
  37. package/dist/xai/index.js.map +1 -1
  38. package/package.json +1 -1
  39. package/dist/chunk-73IIE3QT.js.map +0 -1
  40. package/dist/chunk-QNJO7DSD.js.map +0 -1
  41. /package/dist/{chunk-Z6DKC37J.js.map → chunk-3C7O2RNO.js.map} +0 -0
  42. /package/dist/{chunk-SBCATNHA.js.map → chunk-KUPF5KHT.js.map} +0 -0
@@ -1,4 +1,4 @@
1
- import { ar as KeyStrategy, aq as ProviderConfig, i as Modality, as as RetryStrategy, U as UPPError } from './llm-DgDEy9il.js';
1
+ import { av as KeyStrategy, au as ProviderConfig, k as Modality, aw as RetryStrategy, U as UPPError } from './llm-BQJZj3cD.js';
2
2
 
3
3
  /**
4
4
  * API key management strategies for load balancing and dynamic key selection.
@@ -147,6 +147,20 @@ declare class DynamicKey implements KeyStrategy {
147
147
  */
148
148
  getKey(): Promise<string>;
149
149
  }
150
+ /**
151
+ * Masks an API key for safe logging.
152
+ * Shows first 4 and last 4 characters with ellipsis, or '***' for short keys.
153
+ *
154
+ * @param key - The API key to mask
155
+ * @returns Masked key like "sk-ab...yz12" or "***" for short keys
156
+ *
157
+ * @example
158
+ * ```typescript
159
+ * maskApiKey('sk-abc123def456xyz789'); // 'sk-a...z789'
160
+ * maskApiKey('short'); // '***'
161
+ * ```
162
+ */
163
+ declare function maskApiKey(key: string): string;
150
164
  /**
151
165
  * Resolves an API key from provider configuration with multiple fallback options.
152
166
  *
@@ -514,4 +528,4 @@ declare class RetryAfterStrategy implements RetryStrategy {
514
528
  onRetry(error: UPPError, attempt: number): number | null;
515
529
  }
516
530
 
517
- export { DynamicKey as D, ExponentialBackoff as E, LinearBackoff as L, NoRetry as N, RoundRobinKeys as R, TokenBucket as T, WeightedKeys as W, RetryAfterStrategy as a, resolveApiKey as r };
531
+ export { DynamicKey as D, ExponentialBackoff as E, LinearBackoff as L, NoRetry as N, RoundRobinKeys as R, TokenBucket as T, WeightedKeys as W, RetryAfterStrategy as a, maskApiKey as m, resolveApiKey as r };
@@ -1,4 +1,4 @@
1
- import { P as Provider } from '../llm-DgDEy9il.js';
1
+ import { P as Provider } from '../llm-BQJZj3cD.js';
2
2
 
3
3
  /**
4
4
  * xAI Chat Completions API parameters (OpenAI-compatible).
@@ -59,11 +59,6 @@ interface XAICompletionsParams {
59
59
  metadata?: Record<string, string>;
60
60
  /** Response format for structured output */
61
61
  response_format?: XAIResponseFormat;
62
- /**
63
- * Live Search parameters (deprecated, will be removed Dec 15, 2025)
64
- * Use Agent Tools API instead for new implementations
65
- */
66
- search_parameters?: XAISearchParameters;
67
62
  }
68
63
  /**
69
64
  * xAI Responses API parameters (OpenAI Responses-compatible).
@@ -112,11 +107,6 @@ interface XAIResponsesParams {
112
107
  store_messages?: boolean;
113
108
  /** Metadata key-value pairs */
114
109
  metadata?: Record<string, string>;
115
- /**
116
- * Live Search parameters (deprecated, will be removed Dec 15, 2025)
117
- * Use Agent Tools API instead for new implementations
118
- */
119
- search_parameters?: XAISearchParameters;
120
110
  /**
121
111
  * Built-in agentic tools for server-side execution.
122
112
  *
@@ -191,6 +181,17 @@ interface XAIMessagesParams {
191
181
  type: 'enabled';
192
182
  budget_tokens: number;
193
183
  };
184
+ /**
185
+ * Tool selection strategy.
186
+ *
187
+ * - `auto`: Model decides when to use tools
188
+ * - `any`: Model must use at least one tool
189
+ * - `tool`: Model must use the specific tool named in `name`
190
+ */
191
+ tool_choice?: {
192
+ type: 'auto' | 'any' | 'tool';
193
+ name?: string;
194
+ };
194
195
  }
195
196
  /**
196
197
  * API mode selector for the xAI provider.
@@ -224,24 +225,6 @@ interface XAIConfig {
224
225
  /** The API mode to use (defaults to 'completions') */
225
226
  api?: XAIAPIMode;
226
227
  }
227
- /**
228
- * Live Search parameters for real-time web search integration.
229
- *
230
- * @deprecated Live Search API will be removed on December 15, 2025.
231
- * Use the Agent Tools API with `web_search` tool instead.
232
- */
233
- interface XAISearchParameters {
234
- /** Search mode */
235
- mode?: 'auto' | 'on' | 'off';
236
- /** Limit search to specific date range */
237
- from_date?: string;
238
- /** End date for search range */
239
- to_date?: string;
240
- /** Sources to search */
241
- sources?: Array<'web' | 'x' | 'news' | 'rss'>;
242
- /** Maximum number of search results */
243
- max_search_results?: number;
244
- }
245
228
  /**
246
229
  * Web search tool for real-time web information retrieval.
247
230
  *
@@ -677,15 +660,12 @@ type XAIProvider = Provider<XAIProviderOptions>;
677
660
  * }
678
661
  * });
679
662
  *
680
- * // Using Live Search (deprecated Dec 2025)
663
+ * // Using Agent Tools (web search, code execution, etc.)
681
664
  * const searchModel = llm({
682
- * model: xai('grok-4'),
665
+ * model: xai('grok-4', { api: 'responses' }),
683
666
  * params: {
684
667
  * max_tokens: 1000,
685
- * search_parameters: {
686
- * mode: 'auto',
687
- * sources: ['web', 'x', 'news'],
688
- * }
668
+ * tools: [tools.webSearch()],
689
669
  * }
690
670
  * });
691
671
  *
@@ -696,4 +676,4 @@ type XAIProvider = Provider<XAIProviderOptions>;
696
676
  */
697
677
  declare const xai: Provider<XAIProviderOptions>;
698
678
 
699
- export { type XAIAPIMode, type XAIAgentTool, type XAIBuiltInTool, type XAICodeExecutionTool, type XAICompletionsParams, type XAIConfig, type XAIFileSearchTool, type XAIHeaders, type XAIMcpTool, type XAIMessagesParams, type XAIModelOptions, type XAIModelReference, type XAIProvider, type XAIProviderOptions, type XAIResponsesParams, type XAISearchParameters, type XAIServerSideToolUsage, type XAIWebSearchTool, type XAIXSearchTool, tools, xai };
679
+ export { type XAIAPIMode, type XAIAgentTool, type XAIBuiltInTool, type XAICodeExecutionTool, type XAICompletionsParams, type XAIConfig, type XAIFileSearchTool, type XAIHeaders, type XAIMcpTool, type XAIMessagesParams, type XAIModelOptions, type XAIModelReference, type XAIProvider, type XAIProviderOptions, type XAIResponsesParams, type XAIServerSideToolUsage, type XAIWebSearchTool, type XAIXSearchTool, tools, xai };
package/dist/xai/index.js CHANGED
@@ -3,10 +3,11 @@ import {
3
3
  } from "../chunk-WAKD3OO5.js";
4
4
  import {
5
5
  parseJsonResponse
6
- } from "../chunk-Z6DKC37J.js";
6
+ } from "../chunk-3C7O2RNO.js";
7
7
  import {
8
- StreamEventType
9
- } from "../chunk-73IIE3QT.js";
8
+ StreamEventType,
9
+ objectDelta
10
+ } from "../chunk-6S222DHN.js";
10
11
  import {
11
12
  AssistantMessage,
12
13
  createProvider,
@@ -20,7 +21,7 @@ import {
20
21
  } from "../chunk-TOJCZMVU.js";
21
22
  import {
22
23
  resolveApiKey
23
- } from "../chunk-55X3W2MN.js";
24
+ } from "../chunk-3D6XGGVG.js";
24
25
  import {
25
26
  ErrorCode,
26
27
  ModalityType,
@@ -29,7 +30,7 @@ import {
29
30
  doStreamFetch,
30
31
  normalizeHttpError,
31
32
  toError
32
- } from "../chunk-QNJO7DSD.js";
33
+ } from "../chunk-4J6OFUKX.js";
33
34
 
34
35
  // src/providers/xai/transform.completions.ts
35
36
  function transformRequest(request, modelId) {
@@ -192,9 +193,7 @@ function transformContentBlock(block) {
192
193
  } else if (imageBlock.source.type === "url") {
193
194
  url = imageBlock.source.url;
194
195
  } else if (imageBlock.source.type === "bytes") {
195
- const base64 = btoa(
196
- Array.from(imageBlock.source.data).map((b) => String.fromCharCode(b)).join("")
197
- );
196
+ const base64 = Buffer.from(imageBlock.source.data).toString("base64");
198
197
  url = `data:${imageBlock.mimeType};base64,${base64}`;
199
198
  } else {
200
199
  throw new Error("Unknown image source type");
@@ -619,7 +618,11 @@ function createCompletionsLLMHandler() {
619
618
  }
620
619
  const uppEvents = transformStreamEvent(chunk, state);
621
620
  for (const event of uppEvents) {
622
- yield event;
621
+ if (request.structure && event.type === StreamEventType.TextDelta) {
622
+ yield objectDelta(event.delta.text ?? "", event.index);
623
+ } else {
624
+ yield event;
625
+ }
623
626
  }
624
627
  }
625
628
  }
@@ -844,9 +847,7 @@ function transformContentPart(block) {
844
847
  };
845
848
  }
846
849
  if (imageBlock.source.type === "bytes") {
847
- const base64 = btoa(
848
- Array.from(imageBlock.source.data).map((b) => String.fromCharCode(b)).join("")
849
- );
850
+ const base64 = Buffer.from(imageBlock.source.data).toString("base64");
850
851
  return {
851
852
  type: "input_image",
852
853
  image_url: `data:${imageBlock.mimeType};base64,${base64}`
@@ -1391,7 +1392,11 @@ function createResponsesLLMHandler() {
1391
1392
  }
1392
1393
  const uppEvents = transformStreamEvent2(event, state);
1393
1394
  for (const uppEvent of uppEvents) {
1394
- yield uppEvent;
1395
+ if (request.structure && uppEvent.type === StreamEventType.TextDelta) {
1396
+ yield objectDelta(uppEvent.delta.text ?? "", uppEvent.index);
1397
+ } else {
1398
+ yield uppEvent;
1399
+ }
1395
1400
  }
1396
1401
  }
1397
1402
  }
@@ -1465,7 +1470,9 @@ function transformRequest3(request, modelId) {
1465
1470
  }
1466
1471
  if (request.tools && request.tools.length > 0) {
1467
1472
  xaiRequest.tools = request.tools.map(transformTool3);
1468
- xaiRequest.tool_choice = { type: "auto" };
1473
+ if (!xaiRequest.tool_choice) {
1474
+ xaiRequest.tool_choice = { type: "auto" };
1475
+ }
1469
1476
  }
1470
1477
  if (request.structure) {
1471
1478
  const structuredTool = {
@@ -1565,9 +1572,7 @@ function transformContentBlock2(block) {
1565
1572
  };
1566
1573
  }
1567
1574
  if (imageBlock.source.type === "bytes") {
1568
- const base64 = btoa(
1569
- Array.from(imageBlock.source.data).map((b) => String.fromCharCode(b)).join("")
1570
- );
1575
+ const base64 = Buffer.from(imageBlock.source.data).toString("base64");
1571
1576
  return {
1572
1577
  type: "image",
1573
1578
  source: {
@@ -1951,7 +1956,11 @@ function createMessagesLLMHandler() {
1951
1956
  }
1952
1957
  const uppEvent = transformStreamEvent3(event, state);
1953
1958
  if (uppEvent) {
1954
- yield uppEvent;
1959
+ if (request.structure && uppEvent.type === StreamEventType.TextDelta) {
1960
+ yield objectDelta(uppEvent.delta.text ?? "", uppEvent.index);
1961
+ } else {
1962
+ yield uppEvent;
1963
+ }
1955
1964
  }
1956
1965
  }
1957
1966
  }
@@ -2070,7 +2079,8 @@ function transformResponse4(data) {
2070
2079
  }
2071
2080
  return {
2072
2081
  image,
2073
- metadata: item.revised_prompt ? { revised_prompt: item.revised_prompt } : void 0
2082
+ // Per-image metadata namespaced under provider (Spec 15.4)
2083
+ metadata: item.revised_prompt ? { xai: { revised_prompt: item.revised_prompt } } : void 0
2074
2084
  };
2075
2085
  });
2076
2086
  return {