@providerprotocol/ai 0.0.11 → 0.0.13

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 (104) hide show
  1. package/dist/anthropic/index.d.ts +51 -15
  2. package/dist/anthropic/index.js +54 -19
  3. package/dist/anthropic/index.js.map +1 -1
  4. package/dist/{chunk-SUNYWHTH.js → chunk-MOU4U3PO.js} +55 -3
  5. package/dist/chunk-MOU4U3PO.js.map +1 -0
  6. package/dist/{chunk-Y6Q7JCNP.js → chunk-MSR5P65T.js} +1 -1
  7. package/dist/chunk-MSR5P65T.js.map +1 -0
  8. package/dist/{chunk-W4BB4BG2.js → chunk-SVYROCLD.js} +31 -11
  9. package/dist/chunk-SVYROCLD.js.map +1 -0
  10. package/dist/chunk-U4JJC2YX.js +234 -0
  11. package/dist/chunk-U4JJC2YX.js.map +1 -0
  12. package/dist/{chunk-X5G4EHL7.js → chunk-Z7RBRCRN.js} +1 -1
  13. package/dist/chunk-Z7RBRCRN.js.map +1 -0
  14. package/dist/google/index.d.ts +376 -7
  15. package/dist/google/index.js +127 -15
  16. package/dist/google/index.js.map +1 -1
  17. package/dist/http/index.d.ts +222 -25
  18. package/dist/http/index.js +3 -3
  19. package/dist/index.d.ts +1482 -198
  20. package/dist/index.js +233 -49
  21. package/dist/index.js.map +1 -1
  22. package/dist/ollama/index.d.ts +92 -20
  23. package/dist/ollama/index.js +17 -7
  24. package/dist/ollama/index.js.map +1 -1
  25. package/dist/openai/index.d.ts +340 -61
  26. package/dist/openai/index.js +57 -15
  27. package/dist/openai/index.js.map +1 -1
  28. package/dist/openrouter/index.d.ts +107 -51
  29. package/dist/openrouter/index.js +36 -8
  30. package/dist/openrouter/index.js.map +1 -1
  31. package/dist/provider-mKkz7Q9U.d.ts +488 -0
  32. package/dist/retry-Dh70lgr0.d.ts +508 -0
  33. package/dist/xai/index.d.ts +97 -22
  34. package/dist/xai/index.js +55 -19
  35. package/dist/xai/index.js.map +1 -1
  36. package/package.json +8 -12
  37. package/dist/chunk-CUCRF5W6.js +0 -136
  38. package/dist/chunk-CUCRF5W6.js.map +0 -1
  39. package/dist/chunk-SUNYWHTH.js.map +0 -1
  40. package/dist/chunk-W4BB4BG2.js.map +0 -1
  41. package/dist/chunk-X5G4EHL7.js.map +0 -1
  42. package/dist/chunk-Y6Q7JCNP.js.map +0 -1
  43. package/dist/provider-CUJWjgNl.d.ts +0 -192
  44. package/dist/retry-I2661_rv.d.ts +0 -118
  45. package/src/anthropic/index.ts +0 -3
  46. package/src/core/image.ts +0 -188
  47. package/src/core/llm.ts +0 -650
  48. package/src/core/provider.ts +0 -92
  49. package/src/google/index.ts +0 -3
  50. package/src/http/errors.ts +0 -112
  51. package/src/http/fetch.ts +0 -210
  52. package/src/http/index.ts +0 -31
  53. package/src/http/keys.ts +0 -136
  54. package/src/http/retry.ts +0 -205
  55. package/src/http/sse.ts +0 -136
  56. package/src/index.ts +0 -32
  57. package/src/ollama/index.ts +0 -3
  58. package/src/openai/index.ts +0 -39
  59. package/src/openrouter/index.ts +0 -11
  60. package/src/providers/anthropic/index.ts +0 -17
  61. package/src/providers/anthropic/llm.ts +0 -196
  62. package/src/providers/anthropic/transform.ts +0 -434
  63. package/src/providers/anthropic/types.ts +0 -213
  64. package/src/providers/google/index.ts +0 -17
  65. package/src/providers/google/llm.ts +0 -203
  66. package/src/providers/google/transform.ts +0 -447
  67. package/src/providers/google/types.ts +0 -214
  68. package/src/providers/ollama/index.ts +0 -43
  69. package/src/providers/ollama/llm.ts +0 -272
  70. package/src/providers/ollama/transform.ts +0 -434
  71. package/src/providers/ollama/types.ts +0 -260
  72. package/src/providers/openai/index.ts +0 -186
  73. package/src/providers/openai/llm.completions.ts +0 -201
  74. package/src/providers/openai/llm.responses.ts +0 -211
  75. package/src/providers/openai/transform.completions.ts +0 -561
  76. package/src/providers/openai/transform.responses.ts +0 -708
  77. package/src/providers/openai/types.ts +0 -1249
  78. package/src/providers/openrouter/index.ts +0 -177
  79. package/src/providers/openrouter/llm.completions.ts +0 -201
  80. package/src/providers/openrouter/llm.responses.ts +0 -211
  81. package/src/providers/openrouter/transform.completions.ts +0 -538
  82. package/src/providers/openrouter/transform.responses.ts +0 -742
  83. package/src/providers/openrouter/types.ts +0 -717
  84. package/src/providers/xai/index.ts +0 -223
  85. package/src/providers/xai/llm.completions.ts +0 -201
  86. package/src/providers/xai/llm.messages.ts +0 -195
  87. package/src/providers/xai/llm.responses.ts +0 -211
  88. package/src/providers/xai/transform.completions.ts +0 -565
  89. package/src/providers/xai/transform.messages.ts +0 -448
  90. package/src/providers/xai/transform.responses.ts +0 -678
  91. package/src/providers/xai/types.ts +0 -938
  92. package/src/types/content.ts +0 -133
  93. package/src/types/errors.ts +0 -85
  94. package/src/types/index.ts +0 -105
  95. package/src/types/llm.ts +0 -211
  96. package/src/types/messages.ts +0 -205
  97. package/src/types/provider.ts +0 -195
  98. package/src/types/schema.ts +0 -58
  99. package/src/types/stream.ts +0 -188
  100. package/src/types/thread.ts +0 -226
  101. package/src/types/tool.ts +0 -88
  102. package/src/types/turn.ts +0 -118
  103. package/src/utils/id.ts +0 -28
  104. package/src/xai/index.ts +0 -41
@@ -1,1249 +0,0 @@
1
- // ============================================
2
- // Audio Configuration Types
3
- // ============================================
4
-
5
- /**
6
- * Audio output configuration for Chat Completions
7
- */
8
- export interface OpenAIAudioConfig {
9
- /** Audio format */
10
- format: 'wav' | 'aac' | 'mp3' | 'flac' | 'opus' | 'pcm16';
11
- /** Voice to use for audio generation */
12
- voice:
13
- | 'alloy'
14
- | 'ash'
15
- | 'ballad'
16
- | 'coral'
17
- | 'echo'
18
- | 'sage'
19
- | 'shimmer'
20
- | 'verse'
21
- | 'marin'
22
- | 'cedar';
23
- }
24
-
25
- // ============================================
26
- // Web Search Configuration Types
27
- // ============================================
28
-
29
- /**
30
- * User location for web search context (Responses API format)
31
- * Fields are at the same level as type
32
- */
33
- export interface OpenAIWebSearchUserLocation {
34
- /** Location type - must be 'approximate' */
35
- type: 'approximate';
36
- /** City name */
37
- city?: string;
38
- /** ISO 3166-1 country code (e.g., "US") */
39
- country?: string;
40
- /** Region/state name */
41
- region?: string;
42
- /** IANA timezone (e.g., "America/New_York") */
43
- timezone?: string;
44
- }
45
-
46
- /**
47
- * User location for web search context (Chat Completions API format)
48
- * Fields are nested under 'approximate' object
49
- */
50
- export interface OpenAICompletionsWebSearchUserLocation {
51
- /** Location type - must be 'approximate' */
52
- type: 'approximate';
53
- /** Approximate location details */
54
- approximate: {
55
- /** City name */
56
- city?: string;
57
- /** ISO 3166-1 country code (e.g., "US") */
58
- country?: string;
59
- /** Region/state name */
60
- region?: string;
61
- /** IANA timezone (e.g., "America/New_York") */
62
- timezone?: string;
63
- };
64
- }
65
-
66
- /**
67
- * Web search options for Chat Completions API
68
- * Use with gpt-5-search-api-* models
69
- */
70
- export interface OpenAIWebSearchOptions {
71
- /**
72
- * Context size for search results
73
- * Controls how much context from web results to include
74
- */
75
- search_context_size?: 'low' | 'medium' | 'high';
76
- /** User location for localizing search results */
77
- user_location?: OpenAICompletionsWebSearchUserLocation | null;
78
- }
79
-
80
- /**
81
- * OpenAI Chat Completions API parameters
82
- * These are passed through to the /v1/chat/completions endpoint
83
- */
84
- export interface OpenAICompletionsParams {
85
- /** Maximum number of tokens to generate (legacy, prefer max_completion_tokens) */
86
- max_tokens?: number;
87
-
88
- /** Maximum completion tokens (preferred for newer models) */
89
- max_completion_tokens?: number;
90
-
91
- /** Temperature for randomness (0.0 - 2.0) */
92
- temperature?: number;
93
-
94
- /** Top-p (nucleus) sampling (0.0 - 1.0) */
95
- top_p?: number;
96
-
97
- /** Frequency penalty (-2.0 - 2.0) */
98
- frequency_penalty?: number;
99
-
100
- /** Presence penalty (-2.0 - 2.0) */
101
- presence_penalty?: number;
102
-
103
- /** Custom stop sequences */
104
- stop?: string | string[];
105
-
106
- /** Number of completions to generate */
107
- n?: number;
108
-
109
- /** Enable logprobs */
110
- logprobs?: boolean;
111
-
112
- /** Number of top logprobs to return (0-20) */
113
- top_logprobs?: number;
114
-
115
- /** Seed for deterministic sampling (beta, deprecated) */
116
- seed?: number;
117
-
118
- /** User identifier (deprecated, use safety_identifier or prompt_cache_key) */
119
- user?: string;
120
-
121
- /** Logit bias map */
122
- logit_bias?: Record<string, number>;
123
-
124
- /** Verbosity control */
125
- verbosity?: 'low' | 'medium' | 'high';
126
-
127
- /** Whether to enable parallel tool calls */
128
- parallel_tool_calls?: boolean;
129
-
130
- /** Reasoning effort for reasoning models */
131
- reasoning_effort?: 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh';
132
-
133
- /** Service tier */
134
- service_tier?: 'auto' | 'default' | 'flex' | 'scale' | 'priority';
135
-
136
- /** Store completion for distillation */
137
- store?: boolean;
138
-
139
- /** Metadata key-value pairs (max 16, keys max 64 chars, values max 512 chars) */
140
- metadata?: Record<string, string>;
141
-
142
- /** Response format for structured output */
143
- response_format?: OpenAIResponseFormat;
144
-
145
- /**
146
- * Predicted Output configuration for faster regeneration
147
- * Improves response times when large parts of the response are known ahead of time
148
- */
149
- prediction?: {
150
- type: 'content';
151
- content: string | Array<{ type: 'text'; text: string }>;
152
- };
153
-
154
- /**
155
- * Stable identifier for caching similar requests
156
- * Used to optimize cache hit rates (replaces user field)
157
- */
158
- prompt_cache_key?: string;
159
-
160
- /**
161
- * Retention policy for prompt cache
162
- * Set to "24h" to enable extended prompt caching up to 24 hours
163
- */
164
- prompt_cache_retention?: 'in-memory' | '24h';
165
-
166
- /**
167
- * Stable identifier for abuse detection
168
- * Recommend hashing username or email address
169
- */
170
- safety_identifier?: string;
171
-
172
- /**
173
- * Output modalities to generate
174
- * Default: ["text"]. Use ["text", "audio"] for audio-capable models
175
- */
176
- modalities?: Array<'text' | 'audio'>;
177
-
178
- /**
179
- * Audio output configuration
180
- * Required when modalities includes "audio"
181
- */
182
- audio?: OpenAIAudioConfig | null;
183
-
184
- /**
185
- * Web search configuration
186
- * Enables the model to search the web for up-to-date information
187
- */
188
- web_search_options?: OpenAIWebSearchOptions;
189
- }
190
-
191
- /**
192
- * Prompt template reference for Responses API
193
- */
194
- export interface OpenAIPromptTemplate {
195
- /** Prompt template ID */
196
- id: string;
197
- /** Variables to fill into the template */
198
- variables?: Record<string, string>;
199
- }
200
-
201
- /**
202
- * Conversation reference for Responses API
203
- * Items from this conversation are prepended to input_items
204
- */
205
- export interface OpenAIConversation {
206
- /** Conversation ID */
207
- id: string;
208
- }
209
-
210
- /**
211
- * OpenAI Responses API parameters
212
- * These are passed through to the /v1/responses endpoint
213
- */
214
- export interface OpenAIResponsesParams {
215
- /** Maximum output tokens */
216
- max_output_tokens?: number;
217
-
218
- /** Temperature for randomness (0.0 - 2.0) */
219
- temperature?: number;
220
-
221
- /** Top-p (nucleus) sampling (0.0 - 1.0) */
222
- top_p?: number;
223
-
224
- /** Number of top logprobs to return (0-20) */
225
- top_logprobs?: number;
226
-
227
- /** Whether to enable parallel tool calls */
228
- parallel_tool_calls?: boolean;
229
-
230
- /** Reasoning configuration (for gpt-5 and o-series models) */
231
- reasoning?: {
232
- effort?: 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh';
233
- /** Include summary of reasoning */
234
- summary?: 'auto' | 'concise' | 'detailed';
235
- };
236
-
237
- /** Service tier */
238
- service_tier?: 'auto' | 'default' | 'flex' | 'scale' | 'priority';
239
-
240
- /** Truncation strategy */
241
- truncation?: 'auto' | 'disabled';
242
-
243
- /**
244
- * Fields to include in output
245
- * Supported values:
246
- * - 'web_search_call.action.sources': Include web search sources
247
- * - 'code_interpreter_call.outputs': Include code execution outputs
248
- * - 'computer_call_output.output.image_url': Include computer call images
249
- * - 'file_search_call.results': Include file search results
250
- * - 'message.input_image.image_url': Include input image URLs
251
- * - 'message.output_text.logprobs': Include logprobs with messages
252
- * - 'reasoning.encrypted_content': Include encrypted reasoning tokens
253
- */
254
- include?: string[];
255
-
256
- /** Background processing - run response asynchronously */
257
- background?: boolean;
258
-
259
- /** Continue from a previous response (cannot use with conversation) */
260
- previous_response_id?: string;
261
-
262
- /**
263
- * Conversation context - items prepended to input_items
264
- * Cannot be used with previous_response_id
265
- */
266
- conversation?: string | OpenAIConversation;
267
-
268
- /** Store response for continuation */
269
- store?: boolean;
270
-
271
- /** Metadata key-value pairs (max 16, keys max 64 chars, values max 512 chars) */
272
- metadata?: Record<string, string>;
273
-
274
- /**
275
- * Maximum total calls to built-in tools in a response
276
- * Applies across all built-in tool calls, not per tool
277
- */
278
- max_tool_calls?: number;
279
-
280
- /**
281
- * Reference to a prompt template and its variables
282
- */
283
- prompt?: OpenAIPromptTemplate;
284
-
285
- /**
286
- * Stable identifier for caching similar requests
287
- * Used to optimize cache hit rates (replaces user field)
288
- */
289
- prompt_cache_key?: string;
290
-
291
- /**
292
- * Retention policy for prompt cache
293
- * Set to "24h" to enable extended prompt caching up to 24 hours
294
- */
295
- prompt_cache_retention?: 'in-memory' | '24h';
296
-
297
- /**
298
- * Stable identifier for abuse detection
299
- * Recommend hashing username or email address
300
- */
301
- safety_identifier?: string;
302
-
303
- /** User identifier (deprecated, use safety_identifier or prompt_cache_key) */
304
- user?: string;
305
-
306
- /**
307
- * Built-in tools for the Responses API
308
- * Use the tool helper constructors: tools.webSearch(), tools.imageGeneration(), etc.
309
- *
310
- * @example
311
- * ```ts
312
- * import { tools } from 'provider-protocol/openai';
313
- *
314
- * const model = llm({
315
- * model: openai('gpt-4o'),
316
- * params: {
317
- * tools: [
318
- * tools.webSearch(),
319
- * tools.imageGeneration({ quality: 'high' }),
320
- * ],
321
- * },
322
- * });
323
- * ```
324
- */
325
- tools?: OpenAIBuiltInTool[];
326
- }
327
-
328
- /**
329
- * API mode for OpenAI provider
330
- */
331
- export type OpenAIAPIMode = 'responses' | 'completions';
332
-
333
- /**
334
- * Model options when creating a model reference
335
- */
336
- export interface OpenAIModelOptions {
337
- /** Which API to use */
338
- api?: OpenAIAPIMode;
339
- }
340
-
341
- /**
342
- * Model reference with OpenAI-specific options
343
- */
344
- export interface OpenAIModelReference {
345
- modelId: string;
346
- options?: OpenAIModelOptions;
347
- }
348
-
349
- /**
350
- * OpenAI provider configuration
351
- */
352
- export interface OpenAIConfig {
353
- /** Which API to use: 'responses' (modern) or 'completions' (legacy) */
354
- api?: 'responses' | 'completions';
355
- }
356
-
357
- // ============================================
358
- // Chat Completions API Types
359
- // ============================================
360
-
361
- /**
362
- * Chat Completions API request body
363
- */
364
- export interface OpenAICompletionsRequest {
365
- model: string;
366
- messages: OpenAICompletionsMessage[];
367
- temperature?: number;
368
- top_p?: number;
369
- n?: number;
370
- stream?: boolean;
371
- stream_options?: { include_usage?: boolean };
372
- stop?: string | string[];
373
- max_tokens?: number;
374
- max_completion_tokens?: number;
375
- presence_penalty?: number;
376
- frequency_penalty?: number;
377
- logit_bias?: Record<string, number>;
378
- logprobs?: boolean;
379
- top_logprobs?: number;
380
- user?: string;
381
- seed?: number;
382
- tools?: OpenAICompletionsTool[];
383
- tool_choice?: OpenAIToolChoice;
384
- parallel_tool_calls?: boolean;
385
- response_format?: OpenAIResponseFormat;
386
- reasoning_effort?: string;
387
- verbosity?: 'low' | 'medium' | 'high';
388
- service_tier?: string;
389
- store?: boolean;
390
- metadata?: Record<string, string>;
391
- /** Predicted output for faster regeneration */
392
- prediction?: {
393
- type: 'content';
394
- content: string | Array<{ type: 'text'; text: string }>;
395
- };
396
- /** Stable identifier for caching (replaces user) */
397
- prompt_cache_key?: string;
398
- /** Retention policy for prompt cache */
399
- prompt_cache_retention?: string;
400
- /** Stable identifier for abuse detection */
401
- safety_identifier?: string;
402
- /** Output modalities (text, audio) */
403
- modalities?: Array<'text' | 'audio'>;
404
- /** Audio output configuration */
405
- audio?: OpenAIAudioConfig | null;
406
- /** Web search configuration */
407
- web_search_options?: OpenAIWebSearchOptions;
408
- }
409
-
410
- /**
411
- * Chat Completions message format
412
- */
413
- export type OpenAICompletionsMessage =
414
- | OpenAISystemMessage
415
- | OpenAIUserMessage
416
- | OpenAIAssistantMessage
417
- | OpenAIToolMessage;
418
-
419
- export interface OpenAISystemMessage {
420
- role: 'system' | 'developer';
421
- content: string;
422
- name?: string;
423
- }
424
-
425
- export interface OpenAIUserMessage {
426
- role: 'user';
427
- content: string | OpenAIUserContent[];
428
- name?: string;
429
- }
430
-
431
- export interface OpenAIAssistantMessage {
432
- role: 'assistant';
433
- content?: string | null;
434
- name?: string;
435
- tool_calls?: OpenAIToolCall[];
436
- refusal?: string | null;
437
- }
438
-
439
- export interface OpenAIToolMessage {
440
- role: 'tool';
441
- content: string;
442
- tool_call_id: string;
443
- }
444
-
445
- /**
446
- * User content types
447
- */
448
- export type OpenAIUserContent = OpenAITextContent | OpenAIImageContent;
449
-
450
- export interface OpenAITextContent {
451
- type: 'text';
452
- text: string;
453
- }
454
-
455
- export interface OpenAIImageContent {
456
- type: 'image_url';
457
- image_url: {
458
- url: string;
459
- detail?: 'auto' | 'low' | 'high';
460
- };
461
- }
462
-
463
- /**
464
- * Tool call format
465
- */
466
- export interface OpenAIToolCall {
467
- id: string;
468
- type: 'function';
469
- function: {
470
- name: string;
471
- arguments: string;
472
- };
473
- }
474
-
475
- /**
476
- * Tool definition for Chat Completions
477
- */
478
- export interface OpenAICompletionsTool {
479
- type: 'function';
480
- function: {
481
- name: string;
482
- description: string;
483
- parameters: {
484
- type: 'object';
485
- properties: Record<string, unknown>;
486
- required?: string[];
487
- additionalProperties?: boolean;
488
- };
489
- strict?: boolean;
490
- };
491
- }
492
-
493
- /**
494
- * Tool choice options
495
- */
496
- export type OpenAIToolChoice =
497
- | 'none'
498
- | 'auto'
499
- | 'required'
500
- | { type: 'function'; function: { name: string } };
501
-
502
- /**
503
- * Response format
504
- */
505
- export type OpenAIResponseFormat =
506
- | { type: 'text' }
507
- | { type: 'json_object' }
508
- | {
509
- type: 'json_schema';
510
- json_schema: {
511
- name: string;
512
- description?: string;
513
- schema: Record<string, unknown>;
514
- strict?: boolean;
515
- };
516
- };
517
-
518
- /**
519
- * Chat Completions response format
520
- */
521
- export interface OpenAICompletionsResponse {
522
- id: string;
523
- object: 'chat.completion';
524
- created: number;
525
- model: string;
526
- choices: OpenAICompletionsChoice[];
527
- usage: OpenAIUsage;
528
- system_fingerprint?: string;
529
- service_tier?: string;
530
- }
531
-
532
- export interface OpenAICompletionsChoice {
533
- index: number;
534
- message: OpenAIAssistantMessage;
535
- finish_reason: 'stop' | 'length' | 'tool_calls' | 'content_filter' | null;
536
- logprobs?: OpenAILogprobs | null;
537
- }
538
-
539
- export interface OpenAILogprobs {
540
- content?: Array<{
541
- token: string;
542
- logprob: number;
543
- bytes?: number[];
544
- top_logprobs?: Array<{
545
- token: string;
546
- logprob: number;
547
- bytes?: number[];
548
- }>;
549
- }>;
550
- }
551
-
552
- export interface OpenAIUsage {
553
- prompt_tokens: number;
554
- completion_tokens: number;
555
- total_tokens: number;
556
- prompt_tokens_details?: {
557
- cached_tokens?: number;
558
- audio_tokens?: number;
559
- };
560
- completion_tokens_details?: {
561
- reasoning_tokens?: number;
562
- audio_tokens?: number;
563
- accepted_prediction_tokens?: number;
564
- rejected_prediction_tokens?: number;
565
- };
566
- }
567
-
568
- /**
569
- * Chat Completions streaming event types
570
- */
571
- export interface OpenAICompletionsStreamChunk {
572
- id: string;
573
- object: 'chat.completion.chunk';
574
- created: number;
575
- model: string;
576
- choices: OpenAICompletionsStreamChoice[];
577
- usage?: OpenAIUsage | null;
578
- system_fingerprint?: string;
579
- service_tier?: string;
580
- }
581
-
582
- export interface OpenAICompletionsStreamChoice {
583
- index: number;
584
- delta: OpenAICompletionsStreamDelta;
585
- finish_reason: 'stop' | 'length' | 'tool_calls' | 'content_filter' | null;
586
- logprobs?: OpenAILogprobs | null;
587
- }
588
-
589
- export interface OpenAICompletionsStreamDelta {
590
- role?: 'assistant';
591
- content?: string | null;
592
- tool_calls?: OpenAIStreamToolCall[];
593
- refusal?: string | null;
594
- }
595
-
596
- export interface OpenAIStreamToolCall {
597
- index: number;
598
- id?: string;
599
- type?: 'function';
600
- function?: {
601
- name?: string;
602
- arguments?: string;
603
- };
604
- }
605
-
606
- // ============================================
607
- // Responses API Types
608
- // ============================================
609
-
610
- /**
611
- * Responses API request body
612
- */
613
- export interface OpenAIResponsesRequest {
614
- model: string;
615
- input: string | OpenAIResponsesInputItem[];
616
- instructions?: string;
617
- max_output_tokens?: number;
618
- temperature?: number;
619
- top_p?: number;
620
- top_logprobs?: number;
621
- stream?: boolean;
622
- tools?: OpenAIResponsesToolUnion[];
623
- tool_choice?: OpenAIResponsesToolChoice;
624
- parallel_tool_calls?: boolean;
625
- text?: OpenAIResponsesTextConfig;
626
- truncation?: 'auto' | 'disabled';
627
- store?: boolean;
628
- metadata?: Record<string, string>;
629
- reasoning?: {
630
- effort?: 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh';
631
- summary?: 'auto' | 'concise' | 'detailed';
632
- };
633
- service_tier?: string;
634
- include?: string[];
635
- background?: boolean;
636
- previous_response_id?: string;
637
- /** Conversation context (cannot use with previous_response_id) */
638
- conversation?: string | OpenAIConversation;
639
- /** Maximum total calls to built-in tools */
640
- max_tool_calls?: number;
641
- /** Prompt template reference */
642
- prompt?: OpenAIPromptTemplate;
643
- /** Stable identifier for caching (replaces user) */
644
- prompt_cache_key?: string;
645
- /** Retention policy for prompt cache */
646
- prompt_cache_retention?: 'in-memory' | '24h';
647
- /** Stable identifier for abuse detection */
648
- safety_identifier?: string;
649
- /** User identifier (deprecated) */
650
- user?: string;
651
- }
652
-
653
- /**
654
- * Responses API input item
655
- */
656
- export type OpenAIResponsesInputItem =
657
- | OpenAIResponsesSystemItem
658
- | OpenAIResponsesUserItem
659
- | OpenAIResponsesAssistantItem
660
- | OpenAIResponsesFunctionCallInputItem
661
- | OpenAIResponsesToolResultItem;
662
-
663
- export interface OpenAIResponsesSystemItem {
664
- type: 'message';
665
- role: 'system' | 'developer';
666
- content: string | OpenAIResponsesContentPart[];
667
- }
668
-
669
- export interface OpenAIResponsesUserItem {
670
- type: 'message';
671
- role: 'user';
672
- content: string | OpenAIResponsesContentPart[];
673
- }
674
-
675
- export interface OpenAIResponsesAssistantItem {
676
- type: 'message';
677
- role: 'assistant';
678
- content: string | OpenAIResponsesContentPart[];
679
- }
680
-
681
- export interface OpenAIResponsesFunctionCallInputItem {
682
- type: 'function_call';
683
- id: string;
684
- call_id: string;
685
- name: string;
686
- arguments: string;
687
- }
688
-
689
- export interface OpenAIResponsesToolResultItem {
690
- type: 'function_call_output';
691
- call_id: string;
692
- output: string;
693
- }
694
-
695
- /**
696
- * Content parts for Responses API
697
- */
698
- export type OpenAIResponsesContentPart =
699
- | OpenAIResponsesTextPart
700
- | OpenAIResponsesImagePart
701
- | OpenAIResponsesFunctionCallPart;
702
-
703
- export interface OpenAIResponsesTextPart {
704
- type: 'input_text' | 'output_text';
705
- text: string;
706
- }
707
-
708
- export interface OpenAIResponsesImagePart {
709
- type: 'input_image';
710
- image_url?: string;
711
- image?: string; // base64
712
- detail?: 'auto' | 'low' | 'high';
713
- }
714
-
715
- export interface OpenAIResponsesFunctionCallPart {
716
- type: 'function_call';
717
- id: string;
718
- call_id: string;
719
- name: string;
720
- arguments: string;
721
- }
722
-
723
- /**
724
- * Tool definition for Responses API
725
- */
726
- export interface OpenAIResponsesTool {
727
- type: 'function';
728
- name: string;
729
- description: string;
730
- parameters: {
731
- type: 'object';
732
- properties: Record<string, unknown>;
733
- required?: string[];
734
- additionalProperties?: boolean;
735
- };
736
- strict?: boolean;
737
- }
738
-
739
- /**
740
- * Tool choice for Responses API
741
- */
742
- export type OpenAIResponsesToolChoice =
743
- | 'none'
744
- | 'auto'
745
- | 'required'
746
- | { type: 'function'; name: string };
747
-
748
- /**
749
- * Text configuration for structured output
750
- */
751
- export interface OpenAIResponsesTextConfig {
752
- format?:
753
- | { type: 'text' }
754
- | { type: 'json_object' }
755
- | {
756
- type: 'json_schema';
757
- name: string;
758
- description?: string;
759
- schema: Record<string, unknown>;
760
- strict?: boolean;
761
- };
762
- }
763
-
764
- /**
765
- * Responses API response format
766
- */
767
- export interface OpenAIResponsesResponse {
768
- id: string;
769
- object: 'response';
770
- created_at: number;
771
- model: string;
772
- output: OpenAIResponsesOutputItem[];
773
- usage: OpenAIResponsesUsage;
774
- status: 'completed' | 'failed' | 'incomplete' | 'in_progress';
775
- error?: {
776
- code: string;
777
- message: string;
778
- };
779
- incomplete_details?: {
780
- reason: string;
781
- };
782
- }
783
-
784
- export type OpenAIResponsesOutputItem =
785
- | OpenAIResponsesMessageOutput
786
- | OpenAIResponsesFunctionCallOutput
787
- | OpenAIResponsesImageGenerationOutput
788
- | OpenAIResponsesWebSearchOutput;
789
-
790
- export interface OpenAIResponsesMessageOutput {
791
- type: 'message';
792
- id: string;
793
- role: 'assistant';
794
- content: OpenAIResponsesOutputContent[];
795
- status: 'completed' | 'in_progress';
796
- }
797
-
798
- export interface OpenAIResponsesFunctionCallOutput {
799
- type: 'function_call';
800
- id: string;
801
- call_id: string;
802
- name: string;
803
- arguments: string;
804
- status: 'completed' | 'in_progress';
805
- }
806
-
807
- export interface OpenAIResponsesImageGenerationOutput {
808
- type: 'image_generation_call';
809
- id: string;
810
- result?: string;
811
- status: 'completed' | 'in_progress';
812
- }
813
-
814
- export interface OpenAIResponsesWebSearchOutput {
815
- type: 'web_search_call';
816
- id: string;
817
- status: 'completed' | 'in_progress';
818
- }
819
-
820
- export type OpenAIResponsesOutputContent =
821
- | { type: 'output_text'; text: string; annotations?: unknown[] }
822
- | { type: 'refusal'; refusal: string };
823
-
824
- export interface OpenAIResponsesUsage {
825
- input_tokens: number;
826
- output_tokens: number;
827
- total_tokens: number;
828
- input_tokens_details?: {
829
- cached_tokens?: number;
830
- text_tokens?: number;
831
- image_tokens?: number;
832
- audio_tokens?: number;
833
- };
834
- output_tokens_details?: {
835
- text_tokens?: number;
836
- reasoning_tokens?: number;
837
- audio_tokens?: number;
838
- };
839
- }
840
-
841
- /**
842
- * Responses API streaming event types
843
- */
844
- export type OpenAIResponsesStreamEvent =
845
- | OpenAIResponseCreatedEvent
846
- | OpenAIResponseInProgressEvent
847
- | OpenAIResponseCompletedEvent
848
- | OpenAIResponseFailedEvent
849
- | OpenAIResponseOutputItemAddedEvent
850
- | OpenAIResponseOutputItemDoneEvent
851
- | OpenAIResponseContentPartAddedEvent
852
- | OpenAIResponseContentPartDoneEvent
853
- | OpenAIResponseTextDeltaEvent
854
- | OpenAIResponseTextDoneEvent
855
- | OpenAIResponseRefusalDeltaEvent
856
- | OpenAIResponseRefusalDoneEvent
857
- | OpenAIResponseFunctionCallArgumentsDeltaEvent
858
- | OpenAIResponseFunctionCallArgumentsDoneEvent
859
- | OpenAIResponseErrorEvent;
860
-
861
- export interface OpenAIResponseCreatedEvent {
862
- type: 'response.created';
863
- response: OpenAIResponsesResponse;
864
- }
865
-
866
- export interface OpenAIResponseInProgressEvent {
867
- type: 'response.in_progress';
868
- response: OpenAIResponsesResponse;
869
- }
870
-
871
- export interface OpenAIResponseCompletedEvent {
872
- type: 'response.completed';
873
- response: OpenAIResponsesResponse;
874
- }
875
-
876
- export interface OpenAIResponseFailedEvent {
877
- type: 'response.failed';
878
- response: OpenAIResponsesResponse;
879
- }
880
-
881
- export interface OpenAIResponseOutputItemAddedEvent {
882
- type: 'response.output_item.added';
883
- output_index: number;
884
- item: OpenAIResponsesOutputItem;
885
- }
886
-
887
- export interface OpenAIResponseOutputItemDoneEvent {
888
- type: 'response.output_item.done';
889
- output_index: number;
890
- item: OpenAIResponsesOutputItem;
891
- }
892
-
893
- export interface OpenAIResponseContentPartAddedEvent {
894
- type: 'response.content_part.added';
895
- output_index: number;
896
- content_index: number;
897
- part: OpenAIResponsesOutputContent;
898
- }
899
-
900
- export interface OpenAIResponseContentPartDoneEvent {
901
- type: 'response.content_part.done';
902
- output_index: number;
903
- content_index: number;
904
- part: OpenAIResponsesOutputContent;
905
- }
906
-
907
- export interface OpenAIResponseTextDeltaEvent {
908
- type: 'response.output_text.delta';
909
- output_index: number;
910
- content_index: number;
911
- delta: string;
912
- }
913
-
914
- export interface OpenAIResponseTextDoneEvent {
915
- type: 'response.output_text.done';
916
- output_index: number;
917
- content_index: number;
918
- text: string;
919
- }
920
-
921
- export interface OpenAIResponseRefusalDeltaEvent {
922
- type: 'response.refusal.delta';
923
- output_index: number;
924
- content_index: number;
925
- delta: string;
926
- }
927
-
928
- export interface OpenAIResponseRefusalDoneEvent {
929
- type: 'response.refusal.done';
930
- output_index: number;
931
- content_index: number;
932
- refusal: string;
933
- }
934
-
935
- export interface OpenAIResponseFunctionCallArgumentsDeltaEvent {
936
- type: 'response.function_call_arguments.delta';
937
- output_index: number;
938
- item_id: string;
939
- delta: string;
940
- call_id?: string;
941
- }
942
-
943
- export interface OpenAIResponseFunctionCallArgumentsDoneEvent {
944
- type: 'response.function_call_arguments.done';
945
- output_index: number;
946
- item_id: string;
947
- name: string;
948
- arguments: string;
949
- call_id?: string;
950
- }
951
-
952
- export interface OpenAIResponseErrorEvent {
953
- type: 'error';
954
- error: {
955
- type: string;
956
- code?: string;
957
- message: string;
958
- };
959
- }
960
-
961
- // ============================================
962
- // Built-in Tools for Responses API
963
- // ============================================
964
-
965
- /**
966
- * Web search tool for Responses API
967
- * Enables the model to search the web for up-to-date information
968
- */
969
- export interface OpenAIWebSearchTool {
970
- type: 'web_search';
971
- /**
972
- * Context size for search results
973
- * Controls how much context from web results to include
974
- */
975
- search_context_size?: 'low' | 'medium' | 'high';
976
- /** User location for localizing search results */
977
- user_location?: OpenAIWebSearchUserLocation | null;
978
- }
979
-
980
- /**
981
- * File search tool for Responses API
982
- * Enables the model to search through uploaded files
983
- */
984
- export interface OpenAIFileSearchTool {
985
- type: 'file_search';
986
- /** File search configuration */
987
- file_search?: {
988
- /** Vector store IDs to search */
989
- vector_store_ids: string[];
990
- /** Maximum number of results to return */
991
- max_num_results?: number;
992
- /** Ranking options for search results */
993
- ranking_options?: {
994
- /** Ranker to use */
995
- ranker?: 'auto' | 'default_2024_08_21';
996
- /** Score threshold (0-1) */
997
- score_threshold?: number;
998
- };
999
- /** Filters to apply */
1000
- filters?: Record<string, unknown>;
1001
- };
1002
- }
1003
-
1004
- /**
1005
- * Code interpreter container configuration
1006
- */
1007
- export interface OpenAICodeInterpreterContainer {
1008
- /** Container type - 'auto' creates a new container */
1009
- type: 'auto';
1010
- /** Memory limit for the container (e.g., '1g', '4g') */
1011
- memory_limit?: string;
1012
- /** File IDs to make available in the container */
1013
- file_ids?: string[];
1014
- }
1015
-
1016
- /**
1017
- * Code interpreter tool for Responses API
1018
- * Allows the model to write and run Python code
1019
- */
1020
- export interface OpenAICodeInterpreterTool {
1021
- type: 'code_interpreter';
1022
- /** Code interpreter configuration */
1023
- code_interpreter?: {
1024
- /** Container configuration */
1025
- container: string | OpenAICodeInterpreterContainer;
1026
- };
1027
- }
1028
-
1029
- /**
1030
- * Computer tool environment configuration
1031
- */
1032
- export interface OpenAIComputerEnvironment {
1033
- /** Environment type */
1034
- type: 'browser' | 'mac' | 'windows' | 'linux' | 'ubuntu';
1035
- }
1036
-
1037
- /**
1038
- * Computer tool for Responses API
1039
- * Enables the model to interact with computer interfaces
1040
- */
1041
- export interface OpenAIComputerTool {
1042
- type: 'computer';
1043
- /** Computer tool configuration */
1044
- computer?: {
1045
- /** Display width in pixels */
1046
- display_width: number;
1047
- /** Display height in pixels */
1048
- display_height: number;
1049
- /** Environment configuration */
1050
- environment?: OpenAIComputerEnvironment;
1051
- };
1052
- }
1053
-
1054
- /**
1055
- * Image generation tool for Responses API
1056
- */
1057
- export interface OpenAIImageGenerationTool {
1058
- type: 'image_generation';
1059
- /** Background transparency */
1060
- background?: 'transparent' | 'opaque' | 'auto';
1061
- /** Input image formats supported */
1062
- input_image_mask?: boolean;
1063
- /** Model to use for generation */
1064
- model?: string;
1065
- /** Moderation level */
1066
- moderation?: 'auto' | 'low';
1067
- /** Output compression */
1068
- output_compression?: number;
1069
- /** Output format */
1070
- output_format?: 'png' | 'jpeg' | 'webp';
1071
- /** Partial images during streaming */
1072
- partial_images?: number;
1073
- /** Image quality */
1074
- quality?: 'auto' | 'high' | 'medium' | 'low';
1075
- /** Image size */
1076
- size?: 'auto' | '1024x1024' | '1024x1536' | '1536x1024';
1077
- }
1078
-
1079
- /**
1080
- * MCP (Model Context Protocol) server configuration
1081
- */
1082
- export interface OpenAIMcpServerConfig {
1083
- /** Server URL */
1084
- url: string;
1085
- /** Server name for identification */
1086
- name?: string;
1087
- /** Tool configuration for the server */
1088
- tool_configuration?: {
1089
- /** Allowed tools from this server */
1090
- allowed_tools?: string[] | { type: 'all' };
1091
- };
1092
- /** Headers to send with requests */
1093
- headers?: Record<string, string>;
1094
- /** Allowed resources */
1095
- allowed_resources?: string[];
1096
- /** Require approval for tool calls */
1097
- require_approval?: 'always' | 'never' | { type: 'except'; tools: string[] };
1098
- }
1099
-
1100
- /**
1101
- * MCP tool for Responses API
1102
- * Enables connections to MCP servers
1103
- */
1104
- export interface OpenAIMcpTool {
1105
- type: 'mcp';
1106
- /** MCP server configurations */
1107
- mcp?: {
1108
- /** Server configuration */
1109
- server: OpenAIMcpServerConfig;
1110
- };
1111
- }
1112
-
1113
- /**
1114
- * Union type for all Responses API built-in tools
1115
- */
1116
- export type OpenAIBuiltInTool =
1117
- | OpenAIWebSearchTool
1118
- | OpenAIFileSearchTool
1119
- | OpenAICodeInterpreterTool
1120
- | OpenAIComputerTool
1121
- | OpenAIImageGenerationTool
1122
- | OpenAIMcpTool;
1123
-
1124
- /**
1125
- * Combined tool type for Responses API (built-in or function)
1126
- */
1127
- export type OpenAIResponsesToolUnion = OpenAIResponsesTool | OpenAIBuiltInTool;
1128
-
1129
- // ============================================
1130
- // Tool Helper Constructors
1131
- // ============================================
1132
-
1133
- /**
1134
- * Helper to create a web search tool
1135
- * Note: Configuration options are passed at the top level, not nested
1136
- */
1137
- export function webSearchTool(options?: {
1138
- search_context_size?: 'low' | 'medium' | 'high';
1139
- user_location?: OpenAIWebSearchUserLocation | null;
1140
- }): OpenAIWebSearchTool {
1141
- if (options) {
1142
- return {
1143
- type: 'web_search',
1144
- ...options,
1145
- } as OpenAIWebSearchTool;
1146
- }
1147
- return { type: 'web_search' };
1148
- }
1149
-
1150
- /**
1151
- * Helper to create a file search tool
1152
- */
1153
- export function fileSearchTool(options: {
1154
- vector_store_ids: string[];
1155
- max_num_results?: number;
1156
- ranking_options?: {
1157
- ranker?: 'auto' | 'default_2024_08_21';
1158
- score_threshold?: number;
1159
- };
1160
- filters?: Record<string, unknown>;
1161
- }): OpenAIFileSearchTool {
1162
- return {
1163
- type: 'file_search',
1164
- file_search: options,
1165
- };
1166
- }
1167
-
1168
- /**
1169
- * Helper to create a code interpreter tool
1170
- */
1171
- export function codeInterpreterTool(options?: {
1172
- container?: string | OpenAICodeInterpreterContainer;
1173
- }): OpenAICodeInterpreterTool {
1174
- return {
1175
- type: 'code_interpreter',
1176
- ...(options?.container && { code_interpreter: { container: options.container } }),
1177
- };
1178
- }
1179
-
1180
- /**
1181
- * Helper to create a computer tool
1182
- */
1183
- export function computerTool(options: {
1184
- display_width: number;
1185
- display_height: number;
1186
- environment?: OpenAIComputerEnvironment;
1187
- }): OpenAIComputerTool {
1188
- return {
1189
- type: 'computer',
1190
- computer: options,
1191
- };
1192
- }
1193
-
1194
- /**
1195
- * Helper to create an image generation tool
1196
- * Note: Configuration options are passed at the top level, not nested
1197
- */
1198
- export function imageGenerationTool(options?: {
1199
- background?: 'transparent' | 'opaque' | 'auto';
1200
- model?: string;
1201
- quality?: 'auto' | 'high' | 'medium' | 'low';
1202
- size?: 'auto' | '1024x1024' | '1024x1536' | '1536x1024';
1203
- output_format?: 'png' | 'jpeg' | 'webp';
1204
- }): OpenAIImageGenerationTool {
1205
- if (options) {
1206
- return {
1207
- type: 'image_generation',
1208
- ...options,
1209
- };
1210
- }
1211
- return { type: 'image_generation' };
1212
- }
1213
-
1214
- /**
1215
- * Helper to create an MCP tool
1216
- */
1217
- export function mcpTool(options: {
1218
- url: string;
1219
- name?: string;
1220
- allowed_tools?: string[] | { type: 'all' };
1221
- headers?: Record<string, string>;
1222
- require_approval?: 'always' | 'never' | { type: 'except'; tools: string[] };
1223
- }): OpenAIMcpTool {
1224
- const { url, name, allowed_tools, headers, require_approval } = options;
1225
- return {
1226
- type: 'mcp',
1227
- mcp: {
1228
- server: {
1229
- url,
1230
- name,
1231
- ...(allowed_tools && { tool_configuration: { allowed_tools } }),
1232
- headers,
1233
- require_approval,
1234
- },
1235
- },
1236
- };
1237
- }
1238
-
1239
- /**
1240
- * Namespace for tool helper constructors
1241
- */
1242
- export const tools = {
1243
- webSearch: webSearchTool,
1244
- fileSearch: fileSearchTool,
1245
- codeInterpreter: codeInterpreterTool,
1246
- computer: computerTool,
1247
- imageGeneration: imageGenerationTool,
1248
- mcp: mcpTool,
1249
- };