@providerprotocol/ai 0.0.13 → 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.
- package/dist/anthropic/index.d.ts +427 -2
- package/dist/anthropic/index.js +142 -13
- package/dist/anthropic/index.js.map +1 -1
- package/dist/google/index.d.ts +480 -7
- package/dist/google/index.js +104 -26
- package/dist/google/index.js.map +1 -1
- package/dist/http/index.d.ts +2 -2
- package/dist/index.d.ts +7 -5
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/ollama/index.d.ts +1 -1
- package/dist/ollama/index.js +14 -0
- package/dist/ollama/index.js.map +1 -1
- package/dist/openai/index.d.ts +1 -1
- package/dist/openai/index.js +48 -16
- package/dist/openai/index.js.map +1 -1
- package/dist/openrouter/index.d.ts +1 -1
- package/dist/openrouter/index.js +48 -16
- package/dist/openrouter/index.js.map +1 -1
- package/dist/{provider-mKkz7Q9U.d.ts → provider-Bi0nyNhA.d.ts} +17 -0
- package/dist/{retry-Dh70lgr0.d.ts → retry-BatS2hjD.d.ts} +1 -1
- package/dist/xai/index.d.ts +368 -6
- package/dist/xai/index.js +121 -26
- package/dist/xai/index.js.map +1 -1
- package/package.json +4 -3
package/dist/xai/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { b as Provider, M as ModelReference, a as LLMHandler } from '../provider-
|
|
1
|
+
import { b as Provider, M as ModelReference, a as LLMHandler } from '../provider-Bi0nyNhA.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* xAI Chat Completions API parameters (OpenAI-compatible).
|
|
@@ -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
|
-
*
|
|
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
|
-
*
|
|
215
|
-
*
|
|
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
|
-
*
|
|
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
|
@@ -450,14 +450,22 @@ function createCompletionsLLMHandler() {
|
|
|
450
450
|
);
|
|
451
451
|
const baseUrl = request.config.baseUrl ?? XAI_COMPLETIONS_API_URL;
|
|
452
452
|
const body = transformRequest(request, modelId);
|
|
453
|
+
const headers = {
|
|
454
|
+
"Content-Type": "application/json",
|
|
455
|
+
Authorization: `Bearer ${apiKey}`
|
|
456
|
+
};
|
|
457
|
+
if (request.config.headers) {
|
|
458
|
+
for (const [key, value] of Object.entries(request.config.headers)) {
|
|
459
|
+
if (value !== void 0) {
|
|
460
|
+
headers[key] = value;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
}
|
|
453
464
|
const response = await doFetch(
|
|
454
465
|
baseUrl,
|
|
455
466
|
{
|
|
456
467
|
method: "POST",
|
|
457
|
-
headers
|
|
458
|
-
"Content-Type": "application/json",
|
|
459
|
-
Authorization: `Bearer ${apiKey}`
|
|
460
|
-
},
|
|
468
|
+
headers,
|
|
461
469
|
body: JSON.stringify(body),
|
|
462
470
|
signal: request.signal
|
|
463
471
|
},
|
|
@@ -488,14 +496,22 @@ function createCompletionsLLMHandler() {
|
|
|
488
496
|
const body = transformRequest(request, modelId);
|
|
489
497
|
body.stream = true;
|
|
490
498
|
body.stream_options = { include_usage: true };
|
|
499
|
+
const headers = {
|
|
500
|
+
"Content-Type": "application/json",
|
|
501
|
+
Authorization: `Bearer ${apiKey}`
|
|
502
|
+
};
|
|
503
|
+
if (request.config.headers) {
|
|
504
|
+
for (const [key, value] of Object.entries(request.config.headers)) {
|
|
505
|
+
if (value !== void 0) {
|
|
506
|
+
headers[key] = value;
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
}
|
|
491
510
|
const response = await doStreamFetch(
|
|
492
511
|
baseUrl,
|
|
493
512
|
{
|
|
494
513
|
method: "POST",
|
|
495
|
-
headers
|
|
496
|
-
"Content-Type": "application/json",
|
|
497
|
-
Authorization: `Bearer ${apiKey}`
|
|
498
|
-
},
|
|
514
|
+
headers,
|
|
499
515
|
body: JSON.stringify(body),
|
|
500
516
|
signal: request.signal
|
|
501
517
|
},
|
|
@@ -1091,14 +1107,22 @@ function createResponsesLLMHandler() {
|
|
|
1091
1107
|
);
|
|
1092
1108
|
const baseUrl = request.config.baseUrl ?? XAI_RESPONSES_API_URL;
|
|
1093
1109
|
const body = transformRequest2(request, modelId);
|
|
1110
|
+
const headers = {
|
|
1111
|
+
"Content-Type": "application/json",
|
|
1112
|
+
Authorization: `Bearer ${apiKey}`
|
|
1113
|
+
};
|
|
1114
|
+
if (request.config.headers) {
|
|
1115
|
+
for (const [key, value] of Object.entries(request.config.headers)) {
|
|
1116
|
+
if (value !== void 0) {
|
|
1117
|
+
headers[key] = value;
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1094
1121
|
const response = await doFetch(
|
|
1095
1122
|
baseUrl,
|
|
1096
1123
|
{
|
|
1097
1124
|
method: "POST",
|
|
1098
|
-
headers
|
|
1099
|
-
"Content-Type": "application/json",
|
|
1100
|
-
Authorization: `Bearer ${apiKey}`
|
|
1101
|
-
},
|
|
1125
|
+
headers,
|
|
1102
1126
|
body: JSON.stringify(body),
|
|
1103
1127
|
signal: request.signal
|
|
1104
1128
|
},
|
|
@@ -1136,14 +1160,22 @@ function createResponsesLLMHandler() {
|
|
|
1136
1160
|
const baseUrl = request.config.baseUrl ?? XAI_RESPONSES_API_URL;
|
|
1137
1161
|
const body = transformRequest2(request, modelId);
|
|
1138
1162
|
body.stream = true;
|
|
1163
|
+
const headers = {
|
|
1164
|
+
"Content-Type": "application/json",
|
|
1165
|
+
Authorization: `Bearer ${apiKey}`
|
|
1166
|
+
};
|
|
1167
|
+
if (request.config.headers) {
|
|
1168
|
+
for (const [key, value] of Object.entries(request.config.headers)) {
|
|
1169
|
+
if (value !== void 0) {
|
|
1170
|
+
headers[key] = value;
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1139
1174
|
const response = await doStreamFetch(
|
|
1140
1175
|
baseUrl,
|
|
1141
1176
|
{
|
|
1142
1177
|
method: "POST",
|
|
1143
|
-
headers
|
|
1144
|
-
"Content-Type": "application/json",
|
|
1145
|
-
Authorization: `Bearer ${apiKey}`
|
|
1146
|
-
},
|
|
1178
|
+
headers,
|
|
1147
1179
|
body: JSON.stringify(body),
|
|
1148
1180
|
signal: request.signal
|
|
1149
1181
|
},
|
|
@@ -1571,15 +1603,23 @@ function createMessagesLLMHandler() {
|
|
|
1571
1603
|
);
|
|
1572
1604
|
const baseUrl = request.config.baseUrl ?? XAI_MESSAGES_API_URL;
|
|
1573
1605
|
const body = transformRequest3(request, modelId);
|
|
1606
|
+
const headers = {
|
|
1607
|
+
"Content-Type": "application/json",
|
|
1608
|
+
"x-api-key": apiKey,
|
|
1609
|
+
"anthropic-version": "2023-06-01"
|
|
1610
|
+
};
|
|
1611
|
+
if (request.config.headers) {
|
|
1612
|
+
for (const [key, value] of Object.entries(request.config.headers)) {
|
|
1613
|
+
if (value !== void 0) {
|
|
1614
|
+
headers[key] = value;
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1574
1618
|
const response = await doFetch(
|
|
1575
1619
|
baseUrl,
|
|
1576
1620
|
{
|
|
1577
1621
|
method: "POST",
|
|
1578
|
-
headers
|
|
1579
|
-
"Content-Type": "application/json",
|
|
1580
|
-
"x-api-key": apiKey,
|
|
1581
|
-
"anthropic-version": "2023-06-01"
|
|
1582
|
-
},
|
|
1622
|
+
headers,
|
|
1583
1623
|
body: JSON.stringify(body),
|
|
1584
1624
|
signal: request.signal
|
|
1585
1625
|
},
|
|
@@ -1609,15 +1649,23 @@ function createMessagesLLMHandler() {
|
|
|
1609
1649
|
const baseUrl = request.config.baseUrl ?? XAI_MESSAGES_API_URL;
|
|
1610
1650
|
const body = transformRequest3(request, modelId);
|
|
1611
1651
|
body.stream = true;
|
|
1652
|
+
const headers = {
|
|
1653
|
+
"Content-Type": "application/json",
|
|
1654
|
+
"x-api-key": apiKey,
|
|
1655
|
+
"anthropic-version": "2023-06-01"
|
|
1656
|
+
};
|
|
1657
|
+
if (request.config.headers) {
|
|
1658
|
+
for (const [key, value] of Object.entries(request.config.headers)) {
|
|
1659
|
+
if (value !== void 0) {
|
|
1660
|
+
headers[key] = value;
|
|
1661
|
+
}
|
|
1662
|
+
}
|
|
1663
|
+
}
|
|
1612
1664
|
const response = await doStreamFetch(
|
|
1613
1665
|
baseUrl,
|
|
1614
1666
|
{
|
|
1615
1667
|
method: "POST",
|
|
1616
|
-
headers
|
|
1617
|
-
"Content-Type": "application/json",
|
|
1618
|
-
"x-api-key": apiKey,
|
|
1619
|
-
"anthropic-version": "2023-06-01"
|
|
1620
|
-
},
|
|
1668
|
+
headers,
|
|
1621
1669
|
body: JSON.stringify(body),
|
|
1622
1670
|
signal: request.signal
|
|
1623
1671
|
},
|
|
@@ -1678,6 +1726,52 @@ function createMessagesLLMHandler() {
|
|
|
1678
1726
|
};
|
|
1679
1727
|
}
|
|
1680
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
|
+
|
|
1681
1775
|
// src/providers/xai/index.ts
|
|
1682
1776
|
function createXAIProvider() {
|
|
1683
1777
|
let currentApiMode = "completions";
|
|
@@ -1727,6 +1821,7 @@ function createXAIProvider() {
|
|
|
1727
1821
|
}
|
|
1728
1822
|
var xai = createXAIProvider();
|
|
1729
1823
|
export {
|
|
1824
|
+
tools,
|
|
1730
1825
|
xai
|
|
1731
1826
|
};
|
|
1732
1827
|
//# sourceMappingURL=index.js.map
|