@providerprotocol/ai 0.0.14 → 0.0.15

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.
@@ -117,6 +117,40 @@ interface XAIResponsesParams {
117
117
  * Use Agent Tools API instead for new implementations
118
118
  */
119
119
  search_parameters?: XAISearchParameters;
120
+ /**
121
+ * Built-in agentic tools for server-side execution.
122
+ *
123
+ * Use the tool helper constructors from the `tools` namespace:
124
+ * - `tools.webSearch()` - Web search capability
125
+ * - `tools.xSearch()` - X (Twitter) search capability
126
+ * - `tools.codeExecution()` - Python code execution
127
+ * - `tools.fileSearch()` - Document/collections search
128
+ * - `tools.mcp()` - Remote MCP server connection
129
+ *
130
+ * Note: Only available via the Responses API (`api: 'responses'`).
131
+ *
132
+ * @example
133
+ * ```typescript
134
+ * import { xai, tools } from 'provider-protocol/xai';
135
+ *
136
+ * const model = llm({
137
+ * model: xai('grok-4-1-fast', { api: 'responses' }),
138
+ * params: {
139
+ * builtInTools: [
140
+ * tools.webSearch(),
141
+ * tools.xSearch({ from_date: '2025-01-01' }),
142
+ * tools.codeExecution(),
143
+ * ],
144
+ * },
145
+ * });
146
+ * ```
147
+ */
148
+ builtInTools?: XAIBuiltInTool[];
149
+ /**
150
+ * Maximum agent reasoning turns.
151
+ * Limits the number of assistant turns, not individual tool calls.
152
+ */
153
+ max_turns?: number;
120
154
  }
121
155
  /**
122
156
  * xAI Messages API parameters (Anthropic-compatible).
@@ -209,16 +243,329 @@ interface XAISearchParameters {
209
243
  max_search_results?: number;
210
244
  }
211
245
  /**
212
- * Server-side agentic tool configuration.
246
+ * Web search tool for real-time web information retrieval.
247
+ *
248
+ * Enables Grok to search the web for up-to-date information.
249
+ * Pricing: $5 per 1,000 successful tool invocations.
250
+ *
251
+ * @example
252
+ * ```typescript
253
+ * const tool: XAIWebSearchTool = {
254
+ * type: 'web_search',
255
+ * allowed_domains: ['wikipedia.org', 'github.com'],
256
+ * };
257
+ * ```
258
+ */
259
+ interface XAIWebSearchTool {
260
+ /** Tool type identifier */
261
+ type: 'web_search';
262
+ /** Restrict to specific domains (max 5, mutually exclusive with excluded_domains) */
263
+ allowed_domains?: string[];
264
+ /** Exclude specific domains (max 5, mutually exclusive with allowed_domains) */
265
+ excluded_domains?: string[];
266
+ /** Enable image analysis from search results */
267
+ enable_image_understanding?: boolean;
268
+ }
269
+ /**
270
+ * X (Twitter) search tool for social media content.
271
+ *
272
+ * Enables Grok to search X posts and profiles in real-time.
273
+ * Pricing: $5 per 1,000 successful tool invocations.
274
+ *
275
+ * @example
276
+ * ```typescript
277
+ * const tool: XAIXSearchTool = {
278
+ * type: 'x_search',
279
+ * allowed_x_handles: ['elonmusk', 'xai'],
280
+ * from_date: '2025-01-01',
281
+ * };
282
+ * ```
283
+ */
284
+ interface XAIXSearchTool {
285
+ /** Tool type identifier */
286
+ type: 'x_search';
287
+ /** Limit to specific X handles (max 10, mutually exclusive with excluded_x_handles) */
288
+ allowed_x_handles?: string[];
289
+ /** Exclude specific X handles (max 10, "grok" excluded by default) */
290
+ excluded_x_handles?: string[];
291
+ /** Start date filter (YYYY-MM-DD) */
292
+ from_date?: string;
293
+ /** End date filter (YYYY-MM-DD) */
294
+ to_date?: string;
295
+ /** Enable image analysis in posts */
296
+ enable_image_understanding?: boolean;
297
+ /** Enable video analysis in posts */
298
+ enable_video_understanding?: boolean;
299
+ }
300
+ /**
301
+ * Code execution tool for Python in a sandbox.
302
+ *
303
+ * Enables Grok to write and execute Python code in a secure environment.
304
+ * Pricing: $5 per 1,000 successful tool invocations.
305
+ *
306
+ * @example
307
+ * ```typescript
308
+ * const tool: XAICodeExecutionTool = {
309
+ * type: 'code_interpreter',
310
+ * container: {
311
+ * pip_packages: ['numpy', 'pandas'],
312
+ * },
313
+ * };
314
+ * ```
315
+ */
316
+ interface XAICodeExecutionTool {
317
+ /** Tool type identifier */
318
+ type: 'code_interpreter';
319
+ /** Container configuration */
320
+ container?: {
321
+ /** Additional pip packages to install */
322
+ pip_packages?: string[];
323
+ };
324
+ }
325
+ /**
326
+ * File/collections search tool for document retrieval.
327
+ *
328
+ * Enables Grok to search through uploaded document collections.
329
+ * Pricing: $2.50 per 1,000 successful tool invocations.
330
+ *
331
+ * @example
332
+ * ```typescript
333
+ * const tool: XAIFileSearchTool = {
334
+ * type: 'file_search',
335
+ * vector_store_ids: ['vs_abc123'],
336
+ * max_num_results: 10,
337
+ * };
338
+ * ```
339
+ */
340
+ interface XAIFileSearchTool {
341
+ /** Tool type identifier */
342
+ type: 'file_search';
343
+ /** Collection/vector store IDs to search */
344
+ vector_store_ids: string[];
345
+ /** Maximum results to return */
346
+ max_num_results?: number;
347
+ /** Retrieval mode configuration */
348
+ retrieval_mode?: {
349
+ type: 'keyword' | 'semantic' | 'hybrid';
350
+ };
351
+ }
352
+ /**
353
+ * Remote MCP server tool configuration.
354
+ *
355
+ * Enables Grok to connect to external Model Context Protocol servers.
356
+ * Pricing: Token-based only (no per-invocation charge).
357
+ *
358
+ * @example
359
+ * ```typescript
360
+ * const tool: XAIMcpTool = {
361
+ * type: 'mcp',
362
+ * server_url: 'https://my-mcp-server.com/sse',
363
+ * server_label: 'my_tools',
364
+ * };
365
+ * ```
366
+ */
367
+ interface XAIMcpTool {
368
+ /** Tool type identifier */
369
+ type: 'mcp';
370
+ /** MCP server URL (HTTP Streaming/SSE only) */
371
+ server_url: string;
372
+ /** Server label for tool call prefixing */
373
+ server_label?: string;
374
+ /** Description of server capabilities */
375
+ server_description?: string;
376
+ /** Specific tools to enable (empty = all available) */
377
+ allowed_tool_names?: string[];
378
+ /** Authentication token */
379
+ authorization?: string;
380
+ /** Custom request headers */
381
+ extra_headers?: Record<string, string>;
382
+ }
383
+ /**
384
+ * Union type for all xAI built-in tools.
385
+ *
386
+ * These tools are only available via the Responses API (`api: 'responses'`).
387
+ * They run server-side and provide agentic capabilities.
388
+ */
389
+ type XAIBuiltInTool = XAIWebSearchTool | XAIXSearchTool | XAICodeExecutionTool | XAIFileSearchTool | XAIMcpTool;
390
+ /**
391
+ * Server-side tool usage tracking returned in responses.
392
+ */
393
+ interface XAIServerSideToolUsage {
394
+ /** Number of successful web searches */
395
+ web_search?: number;
396
+ /** Number of successful X searches */
397
+ x_search?: number;
398
+ /** Number of successful code executions */
399
+ code_execution?: number;
400
+ /** Number of successful file searches */
401
+ file_search?: number;
402
+ }
403
+ /**
404
+ * Creates a web search tool configuration.
405
+ *
406
+ * Enables Grok to search the web for up-to-date information.
407
+ * Pricing: $5 per 1,000 successful tool invocations.
408
+ *
409
+ * @param options - Optional configuration for search behavior
410
+ * @returns A web search tool configuration object
411
+ *
412
+ * @example
413
+ * ```typescript
414
+ * // Basic web search
415
+ * const search = webSearchTool();
416
+ *
417
+ * // With domain restrictions
418
+ * const searchWithDomains = webSearchTool({
419
+ * allowed_domains: ['wikipedia.org', 'github.com'],
420
+ * });
421
+ * ```
422
+ */
423
+ declare function webSearchTool(options?: {
424
+ allowed_domains?: string[];
425
+ excluded_domains?: string[];
426
+ enable_image_understanding?: boolean;
427
+ }): XAIWebSearchTool;
428
+ /**
429
+ * Creates an X (Twitter) search tool configuration.
430
+ *
431
+ * Enables Grok to search X posts and profiles in real-time.
432
+ * Pricing: $5 per 1,000 successful tool invocations.
433
+ *
434
+ * @param options - Optional configuration for search behavior
435
+ * @returns An X search tool configuration object
436
+ *
437
+ * @example
438
+ * ```typescript
439
+ * // Basic X search
440
+ * const xSearch = xSearchTool();
441
+ *
442
+ * // With handle and date filters
443
+ * const filteredSearch = xSearchTool({
444
+ * allowed_x_handles: ['elonmusk', 'xai'],
445
+ * from_date: '2025-01-01',
446
+ * to_date: '2025-12-31',
447
+ * });
448
+ * ```
449
+ */
450
+ declare function xSearchTool(options?: {
451
+ allowed_x_handles?: string[];
452
+ excluded_x_handles?: string[];
453
+ from_date?: string;
454
+ to_date?: string;
455
+ enable_image_understanding?: boolean;
456
+ enable_video_understanding?: boolean;
457
+ }): XAIXSearchTool;
458
+ /**
459
+ * Creates a code execution tool configuration.
460
+ *
461
+ * Enables Grok to write and execute Python code in a sandbox.
462
+ * Pricing: $5 per 1,000 successful tool invocations.
463
+ *
464
+ * @param options - Optional configuration for the execution environment
465
+ * @returns A code execution tool configuration object
466
+ *
467
+ * @example
468
+ * ```typescript
469
+ * // Basic code execution
470
+ * const codeExec = codeExecutionTool();
471
+ *
472
+ * // With additional packages
473
+ * const codeExecWithPackages = codeExecutionTool({
474
+ * pip_packages: ['numpy', 'pandas', 'scipy'],
475
+ * });
476
+ * ```
477
+ */
478
+ declare function codeExecutionTool(options?: {
479
+ pip_packages?: string[];
480
+ }): XAICodeExecutionTool;
481
+ /**
482
+ * Creates a file/collections search tool configuration.
483
+ *
484
+ * Enables Grok to search through uploaded document collections.
485
+ * Pricing: $2.50 per 1,000 successful tool invocations.
486
+ *
487
+ * @param options - File search configuration
488
+ * @returns A file search tool configuration object
489
+ *
490
+ * @example
491
+ * ```typescript
492
+ * const fileSearch = fileSearchTool({
493
+ * vector_store_ids: ['vs_abc123'],
494
+ * max_num_results: 10,
495
+ * retrieval_mode: 'hybrid',
496
+ * });
497
+ * ```
498
+ */
499
+ declare function fileSearchTool(options: {
500
+ vector_store_ids: string[];
501
+ max_num_results?: number;
502
+ retrieval_mode?: 'keyword' | 'semantic' | 'hybrid';
503
+ }): XAIFileSearchTool;
504
+ /**
505
+ * Creates a remote MCP server tool configuration.
506
+ *
507
+ * Enables Grok to connect to external Model Context Protocol servers.
508
+ * Pricing: Token-based only (no per-invocation charge).
509
+ *
510
+ * @param options - MCP server configuration
511
+ * @returns An MCP tool configuration object
512
+ *
513
+ * @example
514
+ * ```typescript
515
+ * const mcp = mcpTool({
516
+ * server_url: 'https://my-mcp-server.com/sse',
517
+ * server_label: 'my_tools',
518
+ * allowed_tool_names: ['get_weather', 'search_db'],
519
+ * });
520
+ * ```
521
+ */
522
+ declare function mcpTool(options: {
523
+ server_url: string;
524
+ server_label?: string;
525
+ server_description?: string;
526
+ allowed_tool_names?: string[];
527
+ authorization?: string;
528
+ extra_headers?: Record<string, string>;
529
+ }): XAIMcpTool;
530
+ /**
531
+ * Namespace object containing all xAI tool helper constructors.
213
532
  *
214
- * These tools run on xAI's servers and provide capabilities like
215
- * web search, X (Twitter) search, and code execution.
533
+ * Provides a convenient way to create built-in tool configurations.
534
+ * Note: These tools are only available via the Responses API (`api: 'responses'`).
216
535
  *
217
536
  * @example
218
537
  * ```typescript
219
- * const tool: XAIAgentTool = { type: 'web_search' };
538
+ * import { xai, tools } from 'provider-protocol/xai';
539
+ *
540
+ * const model = llm({
541
+ * model: xai('grok-4-1-fast', { api: 'responses' }),
542
+ * params: {
543
+ * builtInTools: [
544
+ * tools.webSearch(),
545
+ * tools.xSearch({ from_date: '2025-01-01' }),
546
+ * tools.codeExecution(),
547
+ * ],
548
+ * include: ['inline_citations', 'code_execution_call_output'],
549
+ * },
550
+ * });
220
551
  * ```
221
552
  */
553
+ declare const tools: {
554
+ /** Creates a web search tool configuration */
555
+ webSearch: typeof webSearchTool;
556
+ /** Creates an X (Twitter) search tool configuration */
557
+ xSearch: typeof xSearchTool;
558
+ /** Creates a code execution tool configuration */
559
+ codeExecution: typeof codeExecutionTool;
560
+ /** Creates a file/collections search tool configuration */
561
+ fileSearch: typeof fileSearchTool;
562
+ /** Creates a remote MCP server tool configuration */
563
+ mcp: typeof mcpTool;
564
+ };
565
+ /**
566
+ * @deprecated Use the specific tool interfaces and the `tools` namespace instead.
567
+ * This basic type is maintained for backwards compatibility.
568
+ */
222
569
  interface XAIAgentTool {
223
570
  /** The type of server-side tool to enable */
224
571
  type: 'web_search' | 'x_search' | 'code_execution';
@@ -243,6 +590,21 @@ type XAIResponseFormat = {
243
590
  strict?: boolean;
244
591
  };
245
592
  };
593
+ /**
594
+ * xAI-specific HTTP headers for API requests.
595
+ *
596
+ * @example
597
+ * ```typescript
598
+ * const headers: XAIHeaders = {
599
+ * 'X-Client-Request-Id': 'trace-123',
600
+ * };
601
+ * ```
602
+ */
603
+ interface XAIHeaders {
604
+ /** Client-generated request ID for tracing. */
605
+ 'X-Client-Request-Id'?: string;
606
+ [key: string]: string | undefined;
607
+ }
246
608
 
247
609
  /**
248
610
  * Union type for LLM parameters across all xAI API modes.
@@ -378,4 +740,4 @@ interface XAIProvider extends Provider<XAIProviderOptions> {
378
740
  */
379
741
  declare const xai: XAIProvider;
380
742
 
381
- export { type XAIAPIMode, type XAIAgentTool, type XAICompletionsParams, type XAIConfig, type XAIMessagesParams, type XAIModelOptions, type XAIModelReference, type XAIProvider, type XAIProviderOptions, type XAIResponsesParams, type XAISearchParameters, xai };
743
+ 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 };
package/dist/xai/index.js CHANGED
@@ -1726,6 +1726,52 @@ function createMessagesLLMHandler() {
1726
1726
  };
1727
1727
  }
1728
1728
 
1729
+ // src/providers/xai/types.ts
1730
+ function webSearchTool(options) {
1731
+ return {
1732
+ type: "web_search",
1733
+ ...options
1734
+ };
1735
+ }
1736
+ function xSearchTool(options) {
1737
+ return {
1738
+ type: "x_search",
1739
+ ...options
1740
+ };
1741
+ }
1742
+ function codeExecutionTool(options) {
1743
+ return {
1744
+ type: "code_interpreter",
1745
+ ...options?.pip_packages && { container: { pip_packages: options.pip_packages } }
1746
+ };
1747
+ }
1748
+ function fileSearchTool(options) {
1749
+ return {
1750
+ type: "file_search",
1751
+ vector_store_ids: options.vector_store_ids,
1752
+ ...options.max_num_results !== void 0 && { max_num_results: options.max_num_results },
1753
+ ...options.retrieval_mode && { retrieval_mode: { type: options.retrieval_mode } }
1754
+ };
1755
+ }
1756
+ function mcpTool(options) {
1757
+ return {
1758
+ type: "mcp",
1759
+ ...options
1760
+ };
1761
+ }
1762
+ var tools = {
1763
+ /** Creates a web search tool configuration */
1764
+ webSearch: webSearchTool,
1765
+ /** Creates an X (Twitter) search tool configuration */
1766
+ xSearch: xSearchTool,
1767
+ /** Creates a code execution tool configuration */
1768
+ codeExecution: codeExecutionTool,
1769
+ /** Creates a file/collections search tool configuration */
1770
+ fileSearch: fileSearchTool,
1771
+ /** Creates a remote MCP server tool configuration */
1772
+ mcp: mcpTool
1773
+ };
1774
+
1729
1775
  // src/providers/xai/index.ts
1730
1776
  function createXAIProvider() {
1731
1777
  let currentApiMode = "completions";
@@ -1775,6 +1821,7 @@ function createXAIProvider() {
1775
1821
  }
1776
1822
  var xai = createXAIProvider();
1777
1823
  export {
1824
+ tools,
1778
1825
  xai
1779
1826
  };
1780
1827
  //# sourceMappingURL=index.js.map