@providerprotocol/ai 0.0.1
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/LICENSE +21 -0
- package/README.md +84 -0
- package/dist/anthropic/index.d.ts +41 -0
- package/dist/anthropic/index.js +500 -0
- package/dist/anthropic/index.js.map +1 -0
- package/dist/chunk-CUCRF5W6.js +136 -0
- package/dist/chunk-CUCRF5W6.js.map +1 -0
- package/dist/chunk-FTFX2VET.js +424 -0
- package/dist/chunk-FTFX2VET.js.map +1 -0
- package/dist/chunk-QUUX4G7U.js +117 -0
- package/dist/chunk-QUUX4G7U.js.map +1 -0
- package/dist/chunk-Y6Q7JCNP.js +39 -0
- package/dist/chunk-Y6Q7JCNP.js.map +1 -0
- package/dist/google/index.d.ts +69 -0
- package/dist/google/index.js +517 -0
- package/dist/google/index.js.map +1 -0
- package/dist/http/index.d.ts +61 -0
- package/dist/http/index.js +43 -0
- package/dist/http/index.js.map +1 -0
- package/dist/index.d.ts +792 -0
- package/dist/index.js +898 -0
- package/dist/index.js.map +1 -0
- package/dist/openai/index.d.ts +204 -0
- package/dist/openai/index.js +1340 -0
- package/dist/openai/index.js.map +1 -0
- package/dist/provider-CUJWjgNl.d.ts +192 -0
- package/dist/retry-I2661_rv.d.ts +118 -0
- package/package.json +88 -0
- package/src/anthropic/index.ts +3 -0
- package/src/core/image.ts +188 -0
- package/src/core/llm.ts +619 -0
- package/src/core/provider.ts +92 -0
- package/src/google/index.ts +3 -0
- package/src/http/errors.ts +112 -0
- package/src/http/fetch.ts +210 -0
- package/src/http/index.ts +31 -0
- package/src/http/keys.ts +136 -0
- package/src/http/retry.ts +205 -0
- package/src/http/sse.ts +136 -0
- package/src/index.ts +32 -0
- package/src/openai/index.ts +9 -0
- package/src/providers/anthropic/index.ts +17 -0
- package/src/providers/anthropic/llm.ts +196 -0
- package/src/providers/anthropic/transform.ts +452 -0
- package/src/providers/anthropic/types.ts +213 -0
- package/src/providers/google/index.ts +17 -0
- package/src/providers/google/llm.ts +203 -0
- package/src/providers/google/transform.ts +487 -0
- package/src/providers/google/types.ts +214 -0
- package/src/providers/openai/index.ts +151 -0
- package/src/providers/openai/llm.completions.ts +201 -0
- package/src/providers/openai/llm.responses.ts +211 -0
- package/src/providers/openai/transform.completions.ts +628 -0
- package/src/providers/openai/transform.responses.ts +718 -0
- package/src/providers/openai/types.ts +711 -0
- package/src/types/content.ts +133 -0
- package/src/types/errors.ts +85 -0
- package/src/types/index.ts +105 -0
- package/src/types/llm.ts +211 -0
- package/src/types/messages.ts +182 -0
- package/src/types/provider.ts +195 -0
- package/src/types/schema.ts +58 -0
- package/src/types/stream.ts +146 -0
- package/src/types/thread.ts +226 -0
- package/src/types/tool.ts +88 -0
- package/src/types/turn.ts +118 -0
- package/src/utils/id.ts +28 -0
|
@@ -0,0 +1,711 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAI-specific LLM parameters
|
|
3
|
+
* These are passed through to the relevant OpenAI APIs
|
|
4
|
+
*/
|
|
5
|
+
export interface OpenAILLMParams {
|
|
6
|
+
/** Maximum number of tokens to generate */
|
|
7
|
+
max_tokens?: number;
|
|
8
|
+
|
|
9
|
+
/** Maximum completion tokens (preferred over max_tokens for newer models) */
|
|
10
|
+
max_completion_tokens?: number;
|
|
11
|
+
|
|
12
|
+
/** Maximum output tokens (Responses API) */
|
|
13
|
+
max_output_tokens?: number;
|
|
14
|
+
|
|
15
|
+
/** Temperature for randomness (0.0 - 2.0) */
|
|
16
|
+
temperature?: number;
|
|
17
|
+
|
|
18
|
+
/** Top-p (nucleus) sampling (0.0 - 1.0) */
|
|
19
|
+
top_p?: number;
|
|
20
|
+
|
|
21
|
+
/** Frequency penalty (-2.0 - 2.0) */
|
|
22
|
+
frequency_penalty?: number;
|
|
23
|
+
|
|
24
|
+
/** Presence penalty (-2.0 - 2.0) */
|
|
25
|
+
presence_penalty?: number;
|
|
26
|
+
|
|
27
|
+
/** Custom stop sequences */
|
|
28
|
+
stop?: string | string[];
|
|
29
|
+
|
|
30
|
+
/** Number of completions to generate */
|
|
31
|
+
n?: number;
|
|
32
|
+
|
|
33
|
+
/** Enable logprobs */
|
|
34
|
+
logprobs?: boolean;
|
|
35
|
+
|
|
36
|
+
/** Number of top logprobs to return (0-20) */
|
|
37
|
+
top_logprobs?: number;
|
|
38
|
+
|
|
39
|
+
/** Seed for deterministic sampling (beta) */
|
|
40
|
+
seed?: number;
|
|
41
|
+
|
|
42
|
+
/** User identifier for abuse detection */
|
|
43
|
+
user?: string;
|
|
44
|
+
|
|
45
|
+
/** Logit bias map (Chat Completions API) */
|
|
46
|
+
logit_bias?: Record<string, number>;
|
|
47
|
+
|
|
48
|
+
/** Verbosity control (Chat Completions API) */
|
|
49
|
+
verbosity?: 'low' | 'medium' | 'high';
|
|
50
|
+
|
|
51
|
+
/** Whether to enable parallel tool calls */
|
|
52
|
+
parallel_tool_calls?: boolean;
|
|
53
|
+
|
|
54
|
+
/** Reasoning effort for reasoning models */
|
|
55
|
+
reasoning_effort?: 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh';
|
|
56
|
+
|
|
57
|
+
/** Reasoning configuration (Responses API) */
|
|
58
|
+
reasoning?: {
|
|
59
|
+
effort?: 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh';
|
|
60
|
+
summary?: string;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/** Service tier */
|
|
64
|
+
service_tier?: 'auto' | 'default' | 'flex' | 'priority';
|
|
65
|
+
|
|
66
|
+
/** Truncation strategy (Responses API) */
|
|
67
|
+
truncation?: 'auto' | 'disabled';
|
|
68
|
+
|
|
69
|
+
/** Fields to include in Responses API output */
|
|
70
|
+
include?: string[];
|
|
71
|
+
|
|
72
|
+
/** Background processing (Responses API) */
|
|
73
|
+
background?: boolean;
|
|
74
|
+
|
|
75
|
+
/** Continue from a previous response (Responses API) */
|
|
76
|
+
previous_response_id?: string;
|
|
77
|
+
|
|
78
|
+
/** Store completion for distillation */
|
|
79
|
+
store?: boolean;
|
|
80
|
+
|
|
81
|
+
/** Metadata key-value pairs */
|
|
82
|
+
metadata?: Record<string, string>;
|
|
83
|
+
|
|
84
|
+
/** Response format for structured output (Chat Completions API only) */
|
|
85
|
+
response_format?: OpenAIResponseFormat;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Predicted Output configuration for faster regeneration
|
|
89
|
+
* Improves response times when large parts of the response are known ahead of time
|
|
90
|
+
* Most useful when regenerating a file with only minor changes
|
|
91
|
+
*/
|
|
92
|
+
prediction?: {
|
|
93
|
+
type: 'content';
|
|
94
|
+
content: string | Array<{ type: 'text'; text: string }>;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Stable identifier for caching similar requests (replaces user field)
|
|
99
|
+
* Used to optimize cache hit rates
|
|
100
|
+
*/
|
|
101
|
+
prompt_cache_key?: string;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Retention policy for prompt cache
|
|
105
|
+
* Set to "24h" to enable extended prompt caching up to 24 hours
|
|
106
|
+
*/
|
|
107
|
+
prompt_cache_retention?: '24h';
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Stable identifier for abuse detection
|
|
111
|
+
* Recommend hashing username or email address
|
|
112
|
+
*/
|
|
113
|
+
safety_identifier?: string;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* API mode for OpenAI provider
|
|
118
|
+
*/
|
|
119
|
+
export type OpenAIAPIMode = 'responses' | 'completions';
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Model options when creating a model reference
|
|
123
|
+
*/
|
|
124
|
+
export interface OpenAIModelOptions {
|
|
125
|
+
/** Which API to use */
|
|
126
|
+
api?: OpenAIAPIMode;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Model reference with OpenAI-specific options
|
|
131
|
+
*/
|
|
132
|
+
export interface OpenAIModelReference {
|
|
133
|
+
modelId: string;
|
|
134
|
+
options?: OpenAIModelOptions;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* OpenAI provider configuration
|
|
139
|
+
*/
|
|
140
|
+
export interface OpenAIConfig {
|
|
141
|
+
/** Which API to use: 'responses' (modern) or 'completions' (legacy) */
|
|
142
|
+
api?: 'responses' | 'completions';
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// ============================================
|
|
146
|
+
// Chat Completions API Types
|
|
147
|
+
// ============================================
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Chat Completions API request body
|
|
151
|
+
*/
|
|
152
|
+
export interface OpenAICompletionsRequest {
|
|
153
|
+
model: string;
|
|
154
|
+
messages: OpenAICompletionsMessage[];
|
|
155
|
+
temperature?: number;
|
|
156
|
+
top_p?: number;
|
|
157
|
+
n?: number;
|
|
158
|
+
stream?: boolean;
|
|
159
|
+
stream_options?: { include_usage?: boolean };
|
|
160
|
+
stop?: string | string[];
|
|
161
|
+
max_tokens?: number;
|
|
162
|
+
max_completion_tokens?: number;
|
|
163
|
+
presence_penalty?: number;
|
|
164
|
+
frequency_penalty?: number;
|
|
165
|
+
logit_bias?: Record<string, number>;
|
|
166
|
+
logprobs?: boolean;
|
|
167
|
+
top_logprobs?: number;
|
|
168
|
+
user?: string;
|
|
169
|
+
seed?: number;
|
|
170
|
+
tools?: OpenAICompletionsTool[];
|
|
171
|
+
tool_choice?: OpenAIToolChoice;
|
|
172
|
+
parallel_tool_calls?: boolean;
|
|
173
|
+
response_format?: OpenAIResponseFormat;
|
|
174
|
+
reasoning_effort?: string;
|
|
175
|
+
verbosity?: 'low' | 'medium' | 'high';
|
|
176
|
+
service_tier?: string;
|
|
177
|
+
store?: boolean;
|
|
178
|
+
metadata?: Record<string, string>;
|
|
179
|
+
/** Predicted output for faster regeneration */
|
|
180
|
+
prediction?: {
|
|
181
|
+
type: 'content';
|
|
182
|
+
content: string | Array<{ type: 'text'; text: string }>;
|
|
183
|
+
};
|
|
184
|
+
/** Stable identifier for caching (replaces user) */
|
|
185
|
+
prompt_cache_key?: string;
|
|
186
|
+
/** Retention policy for prompt cache */
|
|
187
|
+
prompt_cache_retention?: string;
|
|
188
|
+
/** Stable identifier for abuse detection */
|
|
189
|
+
safety_identifier?: string;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Chat Completions message format
|
|
194
|
+
*/
|
|
195
|
+
export type OpenAICompletionsMessage =
|
|
196
|
+
| OpenAISystemMessage
|
|
197
|
+
| OpenAIUserMessage
|
|
198
|
+
| OpenAIAssistantMessage
|
|
199
|
+
| OpenAIToolMessage;
|
|
200
|
+
|
|
201
|
+
export interface OpenAISystemMessage {
|
|
202
|
+
role: 'system' | 'developer';
|
|
203
|
+
content: string;
|
|
204
|
+
name?: string;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export interface OpenAIUserMessage {
|
|
208
|
+
role: 'user';
|
|
209
|
+
content: string | OpenAIUserContent[];
|
|
210
|
+
name?: string;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export interface OpenAIAssistantMessage {
|
|
214
|
+
role: 'assistant';
|
|
215
|
+
content?: string | null;
|
|
216
|
+
name?: string;
|
|
217
|
+
tool_calls?: OpenAIToolCall[];
|
|
218
|
+
refusal?: string | null;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export interface OpenAIToolMessage {
|
|
222
|
+
role: 'tool';
|
|
223
|
+
content: string;
|
|
224
|
+
tool_call_id: string;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* User content types
|
|
229
|
+
*/
|
|
230
|
+
export type OpenAIUserContent = OpenAITextContent | OpenAIImageContent;
|
|
231
|
+
|
|
232
|
+
export interface OpenAITextContent {
|
|
233
|
+
type: 'text';
|
|
234
|
+
text: string;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export interface OpenAIImageContent {
|
|
238
|
+
type: 'image_url';
|
|
239
|
+
image_url: {
|
|
240
|
+
url: string;
|
|
241
|
+
detail?: 'auto' | 'low' | 'high';
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Tool call format
|
|
247
|
+
*/
|
|
248
|
+
export interface OpenAIToolCall {
|
|
249
|
+
id: string;
|
|
250
|
+
type: 'function';
|
|
251
|
+
function: {
|
|
252
|
+
name: string;
|
|
253
|
+
arguments: string;
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Tool definition for Chat Completions
|
|
259
|
+
*/
|
|
260
|
+
export interface OpenAICompletionsTool {
|
|
261
|
+
type: 'function';
|
|
262
|
+
function: {
|
|
263
|
+
name: string;
|
|
264
|
+
description: string;
|
|
265
|
+
parameters: {
|
|
266
|
+
type: 'object';
|
|
267
|
+
properties: Record<string, unknown>;
|
|
268
|
+
required?: string[];
|
|
269
|
+
additionalProperties?: boolean;
|
|
270
|
+
};
|
|
271
|
+
strict?: boolean;
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Tool choice options
|
|
277
|
+
*/
|
|
278
|
+
export type OpenAIToolChoice =
|
|
279
|
+
| 'none'
|
|
280
|
+
| 'auto'
|
|
281
|
+
| 'required'
|
|
282
|
+
| { type: 'function'; function: { name: string } };
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Response format
|
|
286
|
+
*/
|
|
287
|
+
export type OpenAIResponseFormat =
|
|
288
|
+
| { type: 'text' }
|
|
289
|
+
| { type: 'json_object' }
|
|
290
|
+
| {
|
|
291
|
+
type: 'json_schema';
|
|
292
|
+
json_schema: {
|
|
293
|
+
name: string;
|
|
294
|
+
description?: string;
|
|
295
|
+
schema: Record<string, unknown>;
|
|
296
|
+
strict?: boolean;
|
|
297
|
+
};
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Chat Completions response format
|
|
302
|
+
*/
|
|
303
|
+
export interface OpenAICompletionsResponse {
|
|
304
|
+
id: string;
|
|
305
|
+
object: 'chat.completion';
|
|
306
|
+
created: number;
|
|
307
|
+
model: string;
|
|
308
|
+
choices: OpenAICompletionsChoice[];
|
|
309
|
+
usage: OpenAIUsage;
|
|
310
|
+
system_fingerprint?: string;
|
|
311
|
+
service_tier?: string;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
export interface OpenAICompletionsChoice {
|
|
315
|
+
index: number;
|
|
316
|
+
message: OpenAIAssistantMessage;
|
|
317
|
+
finish_reason: 'stop' | 'length' | 'tool_calls' | 'content_filter' | null;
|
|
318
|
+
logprobs?: OpenAILogprobs | null;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
export interface OpenAILogprobs {
|
|
322
|
+
content?: Array<{
|
|
323
|
+
token: string;
|
|
324
|
+
logprob: number;
|
|
325
|
+
bytes?: number[];
|
|
326
|
+
top_logprobs?: Array<{
|
|
327
|
+
token: string;
|
|
328
|
+
logprob: number;
|
|
329
|
+
bytes?: number[];
|
|
330
|
+
}>;
|
|
331
|
+
}>;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
export interface OpenAIUsage {
|
|
335
|
+
prompt_tokens: number;
|
|
336
|
+
completion_tokens: number;
|
|
337
|
+
total_tokens: number;
|
|
338
|
+
prompt_tokens_details?: {
|
|
339
|
+
cached_tokens?: number;
|
|
340
|
+
audio_tokens?: number;
|
|
341
|
+
};
|
|
342
|
+
completion_tokens_details?: {
|
|
343
|
+
reasoning_tokens?: number;
|
|
344
|
+
audio_tokens?: number;
|
|
345
|
+
accepted_prediction_tokens?: number;
|
|
346
|
+
rejected_prediction_tokens?: number;
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Chat Completions streaming event types
|
|
352
|
+
*/
|
|
353
|
+
export interface OpenAICompletionsStreamChunk {
|
|
354
|
+
id: string;
|
|
355
|
+
object: 'chat.completion.chunk';
|
|
356
|
+
created: number;
|
|
357
|
+
model: string;
|
|
358
|
+
choices: OpenAICompletionsStreamChoice[];
|
|
359
|
+
usage?: OpenAIUsage | null;
|
|
360
|
+
system_fingerprint?: string;
|
|
361
|
+
service_tier?: string;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
export interface OpenAICompletionsStreamChoice {
|
|
365
|
+
index: number;
|
|
366
|
+
delta: OpenAICompletionsStreamDelta;
|
|
367
|
+
finish_reason: 'stop' | 'length' | 'tool_calls' | 'content_filter' | null;
|
|
368
|
+
logprobs?: OpenAILogprobs | null;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
export interface OpenAICompletionsStreamDelta {
|
|
372
|
+
role?: 'assistant';
|
|
373
|
+
content?: string | null;
|
|
374
|
+
tool_calls?: OpenAIStreamToolCall[];
|
|
375
|
+
refusal?: string | null;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
export interface OpenAIStreamToolCall {
|
|
379
|
+
index: number;
|
|
380
|
+
id?: string;
|
|
381
|
+
type?: 'function';
|
|
382
|
+
function?: {
|
|
383
|
+
name?: string;
|
|
384
|
+
arguments?: string;
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// ============================================
|
|
389
|
+
// Responses API Types
|
|
390
|
+
// ============================================
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Responses API request body
|
|
394
|
+
*/
|
|
395
|
+
export interface OpenAIResponsesRequest {
|
|
396
|
+
model: string;
|
|
397
|
+
input: string | OpenAIResponsesInputItem[];
|
|
398
|
+
instructions?: string;
|
|
399
|
+
max_output_tokens?: number;
|
|
400
|
+
temperature?: number;
|
|
401
|
+
top_p?: number;
|
|
402
|
+
stream?: boolean;
|
|
403
|
+
tools?: OpenAIResponsesTool[];
|
|
404
|
+
tool_choice?: OpenAIResponsesToolChoice;
|
|
405
|
+
parallel_tool_calls?: boolean;
|
|
406
|
+
text?: OpenAIResponsesTextConfig;
|
|
407
|
+
truncation?: 'auto' | 'disabled';
|
|
408
|
+
store?: boolean;
|
|
409
|
+
metadata?: Record<string, string>;
|
|
410
|
+
reasoning?: {
|
|
411
|
+
effort?: 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh';
|
|
412
|
+
summary?: string;
|
|
413
|
+
};
|
|
414
|
+
service_tier?: string;
|
|
415
|
+
include?: string[];
|
|
416
|
+
background?: boolean;
|
|
417
|
+
previous_response_id?: string;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Responses API input item
|
|
422
|
+
*/
|
|
423
|
+
export type OpenAIResponsesInputItem =
|
|
424
|
+
| OpenAIResponsesSystemItem
|
|
425
|
+
| OpenAIResponsesUserItem
|
|
426
|
+
| OpenAIResponsesAssistantItem
|
|
427
|
+
| OpenAIResponsesFunctionCallInputItem
|
|
428
|
+
| OpenAIResponsesToolResultItem;
|
|
429
|
+
|
|
430
|
+
export interface OpenAIResponsesSystemItem {
|
|
431
|
+
type: 'message';
|
|
432
|
+
role: 'system' | 'developer';
|
|
433
|
+
content: string | OpenAIResponsesContentPart[];
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
export interface OpenAIResponsesUserItem {
|
|
437
|
+
type: 'message';
|
|
438
|
+
role: 'user';
|
|
439
|
+
content: string | OpenAIResponsesContentPart[];
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
export interface OpenAIResponsesAssistantItem {
|
|
443
|
+
type: 'message';
|
|
444
|
+
role: 'assistant';
|
|
445
|
+
content: string | OpenAIResponsesContentPart[];
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
export interface OpenAIResponsesFunctionCallInputItem {
|
|
449
|
+
type: 'function_call';
|
|
450
|
+
id: string;
|
|
451
|
+
call_id: string;
|
|
452
|
+
name: string;
|
|
453
|
+
arguments: string;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
export interface OpenAIResponsesToolResultItem {
|
|
457
|
+
type: 'function_call_output';
|
|
458
|
+
call_id: string;
|
|
459
|
+
output: string;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* Content parts for Responses API
|
|
464
|
+
*/
|
|
465
|
+
export type OpenAIResponsesContentPart =
|
|
466
|
+
| OpenAIResponsesTextPart
|
|
467
|
+
| OpenAIResponsesImagePart
|
|
468
|
+
| OpenAIResponsesFunctionCallPart;
|
|
469
|
+
|
|
470
|
+
export interface OpenAIResponsesTextPart {
|
|
471
|
+
type: 'input_text' | 'output_text';
|
|
472
|
+
text: string;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
export interface OpenAIResponsesImagePart {
|
|
476
|
+
type: 'input_image';
|
|
477
|
+
image_url?: string;
|
|
478
|
+
image?: string; // base64
|
|
479
|
+
detail?: 'auto' | 'low' | 'high';
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
export interface OpenAIResponsesFunctionCallPart {
|
|
483
|
+
type: 'function_call';
|
|
484
|
+
id: string;
|
|
485
|
+
call_id: string;
|
|
486
|
+
name: string;
|
|
487
|
+
arguments: string;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* Tool definition for Responses API
|
|
492
|
+
*/
|
|
493
|
+
export interface OpenAIResponsesTool {
|
|
494
|
+
type: 'function';
|
|
495
|
+
name: string;
|
|
496
|
+
description: string;
|
|
497
|
+
parameters: {
|
|
498
|
+
type: 'object';
|
|
499
|
+
properties: Record<string, unknown>;
|
|
500
|
+
required?: string[];
|
|
501
|
+
additionalProperties?: boolean;
|
|
502
|
+
};
|
|
503
|
+
strict?: boolean;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
/**
|
|
507
|
+
* Tool choice for Responses API
|
|
508
|
+
*/
|
|
509
|
+
export type OpenAIResponsesToolChoice =
|
|
510
|
+
| 'none'
|
|
511
|
+
| 'auto'
|
|
512
|
+
| 'required'
|
|
513
|
+
| { type: 'function'; name: string };
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* Text configuration for structured output
|
|
517
|
+
*/
|
|
518
|
+
export interface OpenAIResponsesTextConfig {
|
|
519
|
+
format?:
|
|
520
|
+
| { type: 'text' }
|
|
521
|
+
| { type: 'json_object' }
|
|
522
|
+
| {
|
|
523
|
+
type: 'json_schema';
|
|
524
|
+
name: string;
|
|
525
|
+
description?: string;
|
|
526
|
+
schema: Record<string, unknown>;
|
|
527
|
+
strict?: boolean;
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
/**
|
|
532
|
+
* Responses API response format
|
|
533
|
+
*/
|
|
534
|
+
export interface OpenAIResponsesResponse {
|
|
535
|
+
id: string;
|
|
536
|
+
object: 'response';
|
|
537
|
+
created_at: number;
|
|
538
|
+
model: string;
|
|
539
|
+
output: OpenAIResponsesOutputItem[];
|
|
540
|
+
usage: OpenAIResponsesUsage;
|
|
541
|
+
status: 'completed' | 'failed' | 'incomplete' | 'in_progress';
|
|
542
|
+
error?: {
|
|
543
|
+
code: string;
|
|
544
|
+
message: string;
|
|
545
|
+
};
|
|
546
|
+
incomplete_details?: {
|
|
547
|
+
reason: string;
|
|
548
|
+
};
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
export type OpenAIResponsesOutputItem =
|
|
552
|
+
| OpenAIResponsesMessageOutput
|
|
553
|
+
| OpenAIResponsesFunctionCallOutput;
|
|
554
|
+
|
|
555
|
+
export interface OpenAIResponsesMessageOutput {
|
|
556
|
+
type: 'message';
|
|
557
|
+
id: string;
|
|
558
|
+
role: 'assistant';
|
|
559
|
+
content: OpenAIResponsesOutputContent[];
|
|
560
|
+
status: 'completed' | 'in_progress';
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
export interface OpenAIResponsesFunctionCallOutput {
|
|
564
|
+
type: 'function_call';
|
|
565
|
+
id: string;
|
|
566
|
+
call_id: string;
|
|
567
|
+
name: string;
|
|
568
|
+
arguments: string;
|
|
569
|
+
status: 'completed' | 'in_progress';
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
export type OpenAIResponsesOutputContent =
|
|
573
|
+
| { type: 'output_text'; text: string; annotations?: unknown[] }
|
|
574
|
+
| { type: 'refusal'; refusal: string };
|
|
575
|
+
|
|
576
|
+
export interface OpenAIResponsesUsage {
|
|
577
|
+
input_tokens: number;
|
|
578
|
+
output_tokens: number;
|
|
579
|
+
total_tokens: number;
|
|
580
|
+
input_tokens_details?: {
|
|
581
|
+
cached_tokens?: number;
|
|
582
|
+
text_tokens?: number;
|
|
583
|
+
image_tokens?: number;
|
|
584
|
+
audio_tokens?: number;
|
|
585
|
+
};
|
|
586
|
+
output_tokens_details?: {
|
|
587
|
+
text_tokens?: number;
|
|
588
|
+
reasoning_tokens?: number;
|
|
589
|
+
audio_tokens?: number;
|
|
590
|
+
};
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
/**
|
|
594
|
+
* Responses API streaming event types
|
|
595
|
+
*/
|
|
596
|
+
export type OpenAIResponsesStreamEvent =
|
|
597
|
+
| OpenAIResponseCreatedEvent
|
|
598
|
+
| OpenAIResponseInProgressEvent
|
|
599
|
+
| OpenAIResponseCompletedEvent
|
|
600
|
+
| OpenAIResponseFailedEvent
|
|
601
|
+
| OpenAIResponseOutputItemAddedEvent
|
|
602
|
+
| OpenAIResponseOutputItemDoneEvent
|
|
603
|
+
| OpenAIResponseContentPartAddedEvent
|
|
604
|
+
| OpenAIResponseContentPartDoneEvent
|
|
605
|
+
| OpenAIResponseTextDeltaEvent
|
|
606
|
+
| OpenAIResponseTextDoneEvent
|
|
607
|
+
| OpenAIResponseRefusalDeltaEvent
|
|
608
|
+
| OpenAIResponseRefusalDoneEvent
|
|
609
|
+
| OpenAIResponseFunctionCallArgumentsDeltaEvent
|
|
610
|
+
| OpenAIResponseFunctionCallArgumentsDoneEvent
|
|
611
|
+
| OpenAIResponseErrorEvent;
|
|
612
|
+
|
|
613
|
+
export interface OpenAIResponseCreatedEvent {
|
|
614
|
+
type: 'response.created';
|
|
615
|
+
response: OpenAIResponsesResponse;
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
export interface OpenAIResponseInProgressEvent {
|
|
619
|
+
type: 'response.in_progress';
|
|
620
|
+
response: OpenAIResponsesResponse;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
export interface OpenAIResponseCompletedEvent {
|
|
624
|
+
type: 'response.completed';
|
|
625
|
+
response: OpenAIResponsesResponse;
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
export interface OpenAIResponseFailedEvent {
|
|
629
|
+
type: 'response.failed';
|
|
630
|
+
response: OpenAIResponsesResponse;
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
export interface OpenAIResponseOutputItemAddedEvent {
|
|
634
|
+
type: 'response.output_item.added';
|
|
635
|
+
output_index: number;
|
|
636
|
+
item: OpenAIResponsesOutputItem;
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
export interface OpenAIResponseOutputItemDoneEvent {
|
|
640
|
+
type: 'response.output_item.done';
|
|
641
|
+
output_index: number;
|
|
642
|
+
item: OpenAIResponsesOutputItem;
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
export interface OpenAIResponseContentPartAddedEvent {
|
|
646
|
+
type: 'response.content_part.added';
|
|
647
|
+
output_index: number;
|
|
648
|
+
content_index: number;
|
|
649
|
+
part: OpenAIResponsesOutputContent;
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
export interface OpenAIResponseContentPartDoneEvent {
|
|
653
|
+
type: 'response.content_part.done';
|
|
654
|
+
output_index: number;
|
|
655
|
+
content_index: number;
|
|
656
|
+
part: OpenAIResponsesOutputContent;
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
export interface OpenAIResponseTextDeltaEvent {
|
|
660
|
+
type: 'response.output_text.delta';
|
|
661
|
+
output_index: number;
|
|
662
|
+
content_index: number;
|
|
663
|
+
delta: string;
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
export interface OpenAIResponseTextDoneEvent {
|
|
667
|
+
type: 'response.output_text.done';
|
|
668
|
+
output_index: number;
|
|
669
|
+
content_index: number;
|
|
670
|
+
text: string;
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
export interface OpenAIResponseRefusalDeltaEvent {
|
|
674
|
+
type: 'response.refusal.delta';
|
|
675
|
+
output_index: number;
|
|
676
|
+
content_index: number;
|
|
677
|
+
delta: string;
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
export interface OpenAIResponseRefusalDoneEvent {
|
|
681
|
+
type: 'response.refusal.done';
|
|
682
|
+
output_index: number;
|
|
683
|
+
content_index: number;
|
|
684
|
+
refusal: string;
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
export interface OpenAIResponseFunctionCallArgumentsDeltaEvent {
|
|
688
|
+
type: 'response.function_call_arguments.delta';
|
|
689
|
+
output_index: number;
|
|
690
|
+
item_id: string;
|
|
691
|
+
delta: string;
|
|
692
|
+
call_id?: string;
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
export interface OpenAIResponseFunctionCallArgumentsDoneEvent {
|
|
696
|
+
type: 'response.function_call_arguments.done';
|
|
697
|
+
output_index: number;
|
|
698
|
+
item_id: string;
|
|
699
|
+
name: string;
|
|
700
|
+
arguments: string;
|
|
701
|
+
call_id?: string;
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
export interface OpenAIResponseErrorEvent {
|
|
705
|
+
type: 'error';
|
|
706
|
+
error: {
|
|
707
|
+
type: string;
|
|
708
|
+
code?: string;
|
|
709
|
+
message: string;
|
|
710
|
+
};
|
|
711
|
+
}
|