@providerprotocol/ai 0.0.28 → 0.0.31

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 (35) hide show
  1. package/dist/anthropic/index.d.ts +11 -0
  2. package/dist/anthropic/index.js +7 -7
  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-SBCATNHA.js → chunk-KUPF5KHT.js} +2 -2
  10. package/dist/{embedding-DtyOFIsS.d.ts → embedding-k7g-BcSY.d.ts} +14 -1
  11. package/dist/google/index.d.ts +4 -0
  12. package/dist/google/index.js +14 -10
  13. package/dist/google/index.js.map +1 -1
  14. package/dist/http/index.d.ts +7 -2
  15. package/dist/http/index.js +9 -5
  16. package/dist/index.d.ts +3 -3
  17. package/dist/index.js +12 -3
  18. package/dist/index.js.map +1 -1
  19. package/dist/ollama/index.js +24 -18
  20. package/dist/ollama/index.js.map +1 -1
  21. package/dist/openai/index.js +8 -11
  22. package/dist/openai/index.js.map +1 -1
  23. package/dist/openrouter/index.d.ts +1 -1
  24. package/dist/openrouter/index.js +6 -4
  25. package/dist/openrouter/index.js.map +1 -1
  26. package/dist/proxy/index.d.ts +1 -1
  27. package/dist/proxy/index.js +2 -2
  28. package/dist/{retry-DXLQnTuU.d.ts → retry-CyAwm_KZ.d.ts} +15 -1
  29. package/dist/xai/index.d.ts +15 -35
  30. package/dist/xai/index.js +11 -14
  31. package/dist/xai/index.js.map +1 -1
  32. package/package.json +1 -1
  33. package/dist/chunk-QNJO7DSD.js.map +0 -1
  34. /package/dist/{chunk-Z6DKC37J.js.map → chunk-3C7O2RNO.js.map} +0 -0
  35. /package/dist/{chunk-SBCATNHA.js.map → chunk-KUPF5KHT.js.map} +0 -0
@@ -1,5 +1,5 @@
1
1
  import { X as Message, ad as MessageJSON, a6 as Turn, aX as TurnJSON, ae as StreamEvent, aP as ImageStreamResult, aU as ImageProviderStreamResult, aN as ImageResult, ag as StreamResult, f as Image, J as JSONSchema, N as ToolMetadata, aB as EmbeddingInput, G as Tool, P as Provider, M as ModelReference } from '../llm-DgDEy9il.js';
2
- import { d as EmbeddingResult } from '../embedding-DtyOFIsS.js';
2
+ import { d as EmbeddingResult } from '../embedding-k7g-BcSY.js';
3
3
 
4
4
  /**
5
5
  * @fileoverview Proxy provider types.
@@ -6,7 +6,7 @@ import {
6
6
  } from "../chunk-WAKD3OO5.js";
7
7
  import {
8
8
  parseJsonResponse
9
- } from "../chunk-Z6DKC37J.js";
9
+ } from "../chunk-3C7O2RNO.js";
10
10
  import {
11
11
  AssistantMessage,
12
12
  ToolResultMessage,
@@ -21,7 +21,7 @@ import {
21
21
  doStreamFetch,
22
22
  normalizeHttpError,
23
23
  toError
24
- } from "../chunk-QNJO7DSD.js";
24
+ } from "../chunk-4J6OFUKX.js";
25
25
 
26
26
  // src/providers/proxy/headers.ts
27
27
  function mergeHeaders(requestHeaders, defaultHeaders) {
@@ -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 };
@@ -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,7 +3,7 @@ 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
8
  StreamEventType
9
9
  } from "../chunk-73IIE3QT.js";
@@ -20,7 +20,7 @@ import {
20
20
  } from "../chunk-TOJCZMVU.js";
21
21
  import {
22
22
  resolveApiKey
23
- } from "../chunk-55X3W2MN.js";
23
+ } from "../chunk-3D6XGGVG.js";
24
24
  import {
25
25
  ErrorCode,
26
26
  ModalityType,
@@ -29,7 +29,7 @@ import {
29
29
  doStreamFetch,
30
30
  normalizeHttpError,
31
31
  toError
32
- } from "../chunk-QNJO7DSD.js";
32
+ } from "../chunk-4J6OFUKX.js";
33
33
 
34
34
  // src/providers/xai/transform.completions.ts
35
35
  function transformRequest(request, modelId) {
@@ -192,9 +192,7 @@ function transformContentBlock(block) {
192
192
  } else if (imageBlock.source.type === "url") {
193
193
  url = imageBlock.source.url;
194
194
  } else if (imageBlock.source.type === "bytes") {
195
- const base64 = btoa(
196
- Array.from(imageBlock.source.data).map((b) => String.fromCharCode(b)).join("")
197
- );
195
+ const base64 = Buffer.from(imageBlock.source.data).toString("base64");
198
196
  url = `data:${imageBlock.mimeType};base64,${base64}`;
199
197
  } else {
200
198
  throw new Error("Unknown image source type");
@@ -844,9 +842,7 @@ function transformContentPart(block) {
844
842
  };
845
843
  }
846
844
  if (imageBlock.source.type === "bytes") {
847
- const base64 = btoa(
848
- Array.from(imageBlock.source.data).map((b) => String.fromCharCode(b)).join("")
849
- );
845
+ const base64 = Buffer.from(imageBlock.source.data).toString("base64");
850
846
  return {
851
847
  type: "input_image",
852
848
  image_url: `data:${imageBlock.mimeType};base64,${base64}`
@@ -1465,7 +1461,9 @@ function transformRequest3(request, modelId) {
1465
1461
  }
1466
1462
  if (request.tools && request.tools.length > 0) {
1467
1463
  xaiRequest.tools = request.tools.map(transformTool3);
1468
- xaiRequest.tool_choice = { type: "auto" };
1464
+ if (!xaiRequest.tool_choice) {
1465
+ xaiRequest.tool_choice = { type: "auto" };
1466
+ }
1469
1467
  }
1470
1468
  if (request.structure) {
1471
1469
  const structuredTool = {
@@ -1565,9 +1563,7 @@ function transformContentBlock2(block) {
1565
1563
  };
1566
1564
  }
1567
1565
  if (imageBlock.source.type === "bytes") {
1568
- const base64 = btoa(
1569
- Array.from(imageBlock.source.data).map((b) => String.fromCharCode(b)).join("")
1570
- );
1566
+ const base64 = Buffer.from(imageBlock.source.data).toString("base64");
1571
1567
  return {
1572
1568
  type: "image",
1573
1569
  source: {
@@ -2070,7 +2066,8 @@ function transformResponse4(data) {
2070
2066
  }
2071
2067
  return {
2072
2068
  image,
2073
- metadata: item.revised_prompt ? { revised_prompt: item.revised_prompt } : void 0
2069
+ // Per-image metadata namespaced under provider (Spec 15.4)
2070
+ metadata: item.revised_prompt ? { xai: { revised_prompt: item.revised_prompt } } : void 0
2074
2071
  };
2075
2072
  });
2076
2073
  return {