@ai-sdk/openai 2.0.0-canary.1 → 2.0.0-canary.10

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.
@@ -25,21 +25,24 @@ __export(internal_exports, {
25
25
  OpenAIEmbeddingModel: () => OpenAIEmbeddingModel,
26
26
  OpenAIImageModel: () => OpenAIImageModel,
27
27
  OpenAIResponsesLanguageModel: () => OpenAIResponsesLanguageModel,
28
- modelMaxImagesPerCall: () => modelMaxImagesPerCall
28
+ OpenAISpeechModel: () => OpenAISpeechModel,
29
+ OpenAITranscriptionModel: () => OpenAITranscriptionModel,
30
+ modelMaxImagesPerCall: () => modelMaxImagesPerCall,
31
+ openaiEmbeddingProviderOptions: () => openaiEmbeddingProviderOptions,
32
+ openaiProviderOptions: () => openaiProviderOptions
29
33
  });
30
34
  module.exports = __toCommonJS(internal_exports);
31
35
 
32
36
  // src/openai-chat-language-model.ts
33
37
  var import_provider3 = require("@ai-sdk/provider");
34
38
  var import_provider_utils3 = require("@ai-sdk/provider-utils");
35
- var import_zod2 = require("zod");
39
+ var import_zod3 = require("zod");
36
40
 
37
41
  // src/convert-to-openai-chat-messages.ts
38
42
  var import_provider = require("@ai-sdk/provider");
39
43
  var import_provider_utils = require("@ai-sdk/provider-utils");
40
44
  function convertToOpenAIChatMessages({
41
45
  prompt,
42
- useLegacyFunctionCalling = false,
43
46
  systemMessageMode = "system"
44
47
  }) {
45
48
  const messages = [];
@@ -80,55 +83,71 @@ function convertToOpenAIChatMessages({
80
83
  messages.push({
81
84
  role: "user",
82
85
  content: content.map((part, index) => {
83
- var _a, _b, _c, _d;
86
+ var _a, _b, _c;
84
87
  switch (part.type) {
85
88
  case "text": {
86
89
  return { type: "text", text: part.text };
87
90
  }
88
- case "image": {
89
- return {
90
- type: "image_url",
91
- image_url: {
92
- url: part.image instanceof URL ? part.image.toString() : `data:${(_a = part.mimeType) != null ? _a : "image/jpeg"};base64,${(0, import_provider_utils.convertUint8ArrayToBase64)(part.image)}`,
93
- // OpenAI specific extension: image detail
94
- detail: (_c = (_b = part.providerMetadata) == null ? void 0 : _b.openai) == null ? void 0 : _c.imageDetail
95
- }
96
- };
97
- }
98
91
  case "file": {
99
- if (part.data instanceof URL) {
100
- throw new import_provider.UnsupportedFunctionalityError({
101
- functionality: "'File content parts with URL data' functionality not supported."
102
- });
103
- }
104
- switch (part.mimeType) {
105
- case "audio/wav": {
106
- return {
107
- type: "input_audio",
108
- input_audio: { data: part.data, format: "wav" }
109
- };
110
- }
111
- case "audio/mp3":
112
- case "audio/mpeg": {
113
- return {
114
- type: "input_audio",
115
- input_audio: { data: part.data, format: "mp3" }
116
- };
92
+ if (part.mediaType.startsWith("image/")) {
93
+ const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
94
+ return {
95
+ type: "image_url",
96
+ image_url: {
97
+ url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${(0, import_provider_utils.convertToBase64)(part.data)}`,
98
+ // OpenAI specific extension: image detail
99
+ detail: (_b = (_a = part.providerOptions) == null ? void 0 : _a.openai) == null ? void 0 : _b.imageDetail
100
+ }
101
+ };
102
+ } else if (part.mediaType.startsWith("audio/")) {
103
+ if (part.data instanceof URL) {
104
+ throw new import_provider.UnsupportedFunctionalityError({
105
+ functionality: "audio file parts with URLs"
106
+ });
117
107
  }
118
- case "application/pdf": {
119
- return {
120
- type: "file",
121
- file: {
122
- filename: (_d = part.filename) != null ? _d : `part-${index}.pdf`,
123
- file_data: `data:application/pdf;base64,${part.data}`
124
- }
125
- };
108
+ switch (part.mediaType) {
109
+ case "audio/wav": {
110
+ return {
111
+ type: "input_audio",
112
+ input_audio: {
113
+ data: (0, import_provider_utils.convertToBase64)(part.data),
114
+ format: "wav"
115
+ }
116
+ };
117
+ }
118
+ case "audio/mp3":
119
+ case "audio/mpeg": {
120
+ return {
121
+ type: "input_audio",
122
+ input_audio: {
123
+ data: (0, import_provider_utils.convertToBase64)(part.data),
124
+ format: "mp3"
125
+ }
126
+ };
127
+ }
128
+ default: {
129
+ throw new import_provider.UnsupportedFunctionalityError({
130
+ functionality: `audio content parts with media type ${part.mediaType}`
131
+ });
132
+ }
126
133
  }
127
- default: {
134
+ } else if (part.mediaType === "application/pdf") {
135
+ if (part.data instanceof URL) {
128
136
  throw new import_provider.UnsupportedFunctionalityError({
129
- functionality: `File content part type ${part.mimeType} in user messages`
137
+ functionality: "PDF file parts with URLs"
130
138
  });
131
139
  }
140
+ return {
141
+ type: "file",
142
+ file: {
143
+ filename: (_c = part.filename) != null ? _c : `part-${index}.pdf`,
144
+ file_data: `data:application/pdf;base64,${part.data}`
145
+ }
146
+ };
147
+ } else {
148
+ throw new import_provider.UnsupportedFunctionalityError({
149
+ functionality: `file part media type ${part.mediaType}`
150
+ });
132
151
  }
133
152
  }
134
153
  }
@@ -158,41 +177,20 @@ function convertToOpenAIChatMessages({
158
177
  }
159
178
  }
160
179
  }
161
- if (useLegacyFunctionCalling) {
162
- if (toolCalls.length > 1) {
163
- throw new import_provider.UnsupportedFunctionalityError({
164
- functionality: "useLegacyFunctionCalling with multiple tool calls in one message"
165
- });
166
- }
167
- messages.push({
168
- role: "assistant",
169
- content: text,
170
- function_call: toolCalls.length > 0 ? toolCalls[0].function : void 0
171
- });
172
- } else {
173
- messages.push({
174
- role: "assistant",
175
- content: text,
176
- tool_calls: toolCalls.length > 0 ? toolCalls : void 0
177
- });
178
- }
180
+ messages.push({
181
+ role: "assistant",
182
+ content: text,
183
+ tool_calls: toolCalls.length > 0 ? toolCalls : void 0
184
+ });
179
185
  break;
180
186
  }
181
187
  case "tool": {
182
188
  for (const toolResponse of content) {
183
- if (useLegacyFunctionCalling) {
184
- messages.push({
185
- role: "function",
186
- name: toolResponse.toolName,
187
- content: JSON.stringify(toolResponse.result)
188
- });
189
- } else {
190
- messages.push({
191
- role: "tool",
192
- tool_call_id: toolResponse.toolCallId,
193
- content: JSON.stringify(toolResponse.result)
194
- });
195
- }
189
+ messages.push({
190
+ role: "tool",
191
+ tool_call_id: toolResponse.toolCallId,
192
+ content: JSON.stringify(toolResponse.result)
193
+ });
196
194
  }
197
195
  break;
198
196
  }
@@ -205,6 +203,19 @@ function convertToOpenAIChatMessages({
205
203
  return { messages, warnings };
206
204
  }
207
205
 
206
+ // src/get-response-metadata.ts
207
+ function getResponseMetadata({
208
+ id,
209
+ model,
210
+ created
211
+ }) {
212
+ return {
213
+ id: id != null ? id : void 0,
214
+ modelId: model != null ? model : void 0,
215
+ timestamp: created != null ? new Date(created * 1e3) : void 0
216
+ };
217
+ }
218
+
208
219
  // src/map-openai-chat-logprobs.ts
209
220
  function mapOpenAIChatLogProbsOutput(logprobs) {
210
221
  var _a, _b;
@@ -235,18 +246,69 @@ function mapOpenAIFinishReason(finishReason) {
235
246
  }
236
247
  }
237
248
 
238
- // src/openai-error.ts
249
+ // src/openai-chat-options.ts
239
250
  var import_zod = require("zod");
251
+ var openaiProviderOptions = import_zod.z.object({
252
+ /**
253
+ * Modify the likelihood of specified tokens appearing in the completion.
254
+ *
255
+ * Accepts a JSON object that maps tokens (specified by their token ID in
256
+ * the GPT tokenizer) to an associated bias value from -100 to 100.
257
+ */
258
+ logitBias: import_zod.z.record(import_zod.z.coerce.number(), import_zod.z.number()).optional(),
259
+ /**
260
+ * Return the log probabilities of the tokens.
261
+ *
262
+ * Setting to true will return the log probabilities of the tokens that
263
+ * were generated.
264
+ *
265
+ * Setting to a number will return the log probabilities of the top n
266
+ * tokens that were generated.
267
+ */
268
+ logprobs: import_zod.z.union([import_zod.z.boolean(), import_zod.z.number()]).optional(),
269
+ /**
270
+ * Whether to enable parallel function calling during tool use. Default to true.
271
+ */
272
+ parallelToolCalls: import_zod.z.boolean().optional(),
273
+ /**
274
+ * A unique identifier representing your end-user, which can help OpenAI to
275
+ * monitor and detect abuse.
276
+ */
277
+ user: import_zod.z.string().optional(),
278
+ /**
279
+ * Reasoning effort for reasoning models. Defaults to `medium`.
280
+ */
281
+ reasoningEffort: import_zod.z.enum(["low", "medium", "high"]).optional(),
282
+ /**
283
+ * Maximum number of completion tokens to generate. Useful for reasoning models.
284
+ */
285
+ maxCompletionTokens: import_zod.z.number().optional(),
286
+ /**
287
+ * Whether to enable persistence in responses API.
288
+ */
289
+ store: import_zod.z.boolean().optional(),
290
+ /**
291
+ * Metadata to associate with the request.
292
+ */
293
+ metadata: import_zod.z.record(import_zod.z.string()).optional(),
294
+ /**
295
+ * Parameters for prediction mode.
296
+ */
297
+ prediction: import_zod.z.record(import_zod.z.any()).optional()
298
+ });
299
+
300
+ // src/openai-error.ts
301
+ var import_zod2 = require("zod");
240
302
  var import_provider_utils2 = require("@ai-sdk/provider-utils");
241
- var openaiErrorDataSchema = import_zod.z.object({
242
- error: import_zod.z.object({
243
- message: import_zod.z.string(),
303
+ var openaiErrorDataSchema = import_zod2.z.object({
304
+ error: import_zod2.z.object({
305
+ message: import_zod2.z.string(),
244
306
  // The additional information below is handled loosely to support
245
307
  // OpenAI-compatible providers that have slightly different error
246
308
  // responses:
247
- type: import_zod.z.string().nullish(),
248
- param: import_zod.z.any().nullish(),
249
- code: import_zod.z.union([import_zod.z.string(), import_zod.z.number()]).nullish()
309
+ type: import_zod2.z.string().nullish(),
310
+ param: import_zod2.z.any().nullish(),
311
+ code: import_zod2.z.union([import_zod2.z.string(), import_zod2.z.number()]).nullish()
250
312
  })
251
313
  });
252
314
  var openaiFailedResponseHandler = (0, import_provider_utils2.createJsonErrorResponseHandler)({
@@ -254,74 +316,17 @@ var openaiFailedResponseHandler = (0, import_provider_utils2.createJsonErrorResp
254
316
  errorToMessage: (data) => data.error.message
255
317
  });
256
318
 
257
- // src/get-response-metadata.ts
258
- function getResponseMetadata({
259
- id,
260
- model,
261
- created
262
- }) {
263
- return {
264
- id: id != null ? id : void 0,
265
- modelId: model != null ? model : void 0,
266
- timestamp: created != null ? new Date(created * 1e3) : void 0
267
- };
268
- }
269
-
270
319
  // src/openai-prepare-tools.ts
271
320
  var import_provider2 = require("@ai-sdk/provider");
272
321
  function prepareTools({
273
- mode,
274
- useLegacyFunctionCalling = false,
322
+ tools,
323
+ toolChoice,
275
324
  structuredOutputs
276
325
  }) {
277
- var _a;
278
- const tools = ((_a = mode.tools) == null ? void 0 : _a.length) ? mode.tools : void 0;
326
+ tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
279
327
  const toolWarnings = [];
280
328
  if (tools == null) {
281
- return { tools: void 0, tool_choice: void 0, toolWarnings };
282
- }
283
- const toolChoice = mode.toolChoice;
284
- if (useLegacyFunctionCalling) {
285
- const openaiFunctions = [];
286
- for (const tool of tools) {
287
- if (tool.type === "provider-defined") {
288
- toolWarnings.push({ type: "unsupported-tool", tool });
289
- } else {
290
- openaiFunctions.push({
291
- name: tool.name,
292
- description: tool.description,
293
- parameters: tool.parameters
294
- });
295
- }
296
- }
297
- if (toolChoice == null) {
298
- return {
299
- functions: openaiFunctions,
300
- function_call: void 0,
301
- toolWarnings
302
- };
303
- }
304
- const type2 = toolChoice.type;
305
- switch (type2) {
306
- case "auto":
307
- case "none":
308
- case void 0:
309
- return {
310
- functions: openaiFunctions,
311
- function_call: void 0,
312
- toolWarnings
313
- };
314
- case "required":
315
- throw new import_provider2.UnsupportedFunctionalityError({
316
- functionality: "useLegacyFunctionCalling and toolChoice: required"
317
- });
318
- default:
319
- return {
320
- functions: openaiFunctions,
321
- function_call: { name: toolChoice.toolName },
322
- toolWarnings
323
- };
324
- }
329
+ return { tools: void 0, toolChoice: void 0, toolWarnings };
325
330
  }
326
331
  const openaiTools = [];
327
332
  for (const tool of tools) {
@@ -340,18 +345,18 @@ function prepareTools({
340
345
  }
341
346
  }
342
347
  if (toolChoice == null) {
343
- return { tools: openaiTools, tool_choice: void 0, toolWarnings };
348
+ return { tools: openaiTools, toolChoice: void 0, toolWarnings };
344
349
  }
345
350
  const type = toolChoice.type;
346
351
  switch (type) {
347
352
  case "auto":
348
353
  case "none":
349
354
  case "required":
350
- return { tools: openaiTools, tool_choice: type, toolWarnings };
355
+ return { tools: openaiTools, toolChoice: type, toolWarnings };
351
356
  case "tool":
352
357
  return {
353
358
  tools: openaiTools,
354
- tool_choice: {
359
+ toolChoice: {
355
360
  type: "function",
356
361
  function: {
357
362
  name: toolChoice.toolName
@@ -362,7 +367,7 @@ function prepareTools({
362
367
  default: {
363
368
  const _exhaustiveCheck = type;
364
369
  throw new import_provider2.UnsupportedFunctionalityError({
365
- functionality: `Unsupported tool choice type: ${_exhaustiveCheck}`
370
+ functionality: `tool choice type: ${_exhaustiveCheck}`
366
371
  });
367
372
  }
368
373
  }
@@ -376,26 +381,17 @@ var OpenAIChatLanguageModel = class {
376
381
  this.settings = settings;
377
382
  this.config = config;
378
383
  }
379
- get supportsStructuredOutputs() {
380
- var _a;
381
- return (_a = this.settings.structuredOutputs) != null ? _a : isReasoningModel(this.modelId);
382
- }
383
- get defaultObjectGenerationMode() {
384
- if (isAudioModel(this.modelId)) {
385
- return "tool";
386
- }
387
- return this.supportsStructuredOutputs ? "json" : "tool";
388
- }
389
384
  get provider() {
390
385
  return this.config.provider;
391
386
  }
392
- get supportsImageUrls() {
393
- return !this.settings.downloadImages;
387
+ async getSupportedUrls() {
388
+ return {
389
+ "image/*": [/^https?:\/\/.*$/]
390
+ };
394
391
  }
395
392
  getArgs({
396
- mode,
397
393
  prompt,
398
- maxTokens,
394
+ maxOutputTokens,
399
395
  temperature,
400
396
  topP,
401
397
  topK,
@@ -404,39 +400,33 @@ var OpenAIChatLanguageModel = class {
404
400
  stopSequences,
405
401
  responseFormat,
406
402
  seed,
407
- providerMetadata
403
+ tools,
404
+ toolChoice,
405
+ providerOptions
408
406
  }) {
409
- var _a, _b, _c, _d, _e, _f, _g, _h;
410
- const type = mode.type;
407
+ var _a, _b, _c;
411
408
  const warnings = [];
409
+ const openaiOptions = (_a = (0, import_provider_utils3.parseProviderOptions)({
410
+ provider: "openai",
411
+ providerOptions,
412
+ schema: openaiProviderOptions
413
+ })) != null ? _a : {};
412
414
  if (topK != null) {
413
415
  warnings.push({
414
416
  type: "unsupported-setting",
415
417
  setting: "topK"
416
418
  });
417
419
  }
418
- if ((responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !this.supportsStructuredOutputs) {
420
+ if ((responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !this.settings.structuredOutputs) {
419
421
  warnings.push({
420
422
  type: "unsupported-setting",
421
423
  setting: "responseFormat",
422
424
  details: "JSON response format schema is only supported with structuredOutputs"
423
425
  });
424
426
  }
425
- const useLegacyFunctionCalling = this.settings.useLegacyFunctionCalling;
426
- if (useLegacyFunctionCalling && this.settings.parallelToolCalls === true) {
427
- throw new import_provider3.UnsupportedFunctionalityError({
428
- functionality: "useLegacyFunctionCalling with parallelToolCalls"
429
- });
430
- }
431
- if (useLegacyFunctionCalling && this.supportsStructuredOutputs) {
432
- throw new import_provider3.UnsupportedFunctionalityError({
433
- functionality: "structuredOutputs with useLegacyFunctionCalling"
434
- });
435
- }
436
427
  const { messages, warnings: messageWarnings } = convertToOpenAIChatMessages(
437
428
  {
438
429
  prompt,
439
- useLegacyFunctionCalling,
440
430
  systemMessageMode: getSystemMessageMode(this.modelId)
441
431
  }
442
432
  );
@@ -445,35 +435,38 @@ var OpenAIChatLanguageModel = class {
445
435
  // model id:
446
436
  model: this.modelId,
447
437
  // model specific settings:
448
- logit_bias: this.settings.logitBias,
449
- logprobs: this.settings.logprobs === true || typeof this.settings.logprobs === "number" ? true : void 0,
450
- top_logprobs: typeof this.settings.logprobs === "number" ? this.settings.logprobs : typeof this.settings.logprobs === "boolean" ? this.settings.logprobs ? 0 : void 0 : void 0,
451
- user: this.settings.user,
452
- parallel_tool_calls: this.settings.parallelToolCalls,
438
+ logit_bias: openaiOptions.logitBias,
439
+ logprobs: openaiOptions.logprobs === true || typeof openaiOptions.logprobs === "number" ? true : void 0,
440
+ top_logprobs: typeof openaiOptions.logprobs === "number" ? openaiOptions.logprobs : typeof openaiOptions.logprobs === "boolean" ? openaiOptions.logprobs ? 0 : void 0 : void 0,
441
+ user: openaiOptions.user,
442
+ parallel_tool_calls: openaiOptions.parallelToolCalls,
453
443
  // standardized settings:
454
- max_tokens: maxTokens,
444
+ max_tokens: maxOutputTokens,
455
445
  temperature,
456
446
  top_p: topP,
457
447
  frequency_penalty: frequencyPenalty,
458
448
  presence_penalty: presencePenalty,
459
- response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? this.supportsStructuredOutputs && responseFormat.schema != null ? {
460
- type: "json_schema",
461
- json_schema: {
462
- schema: responseFormat.schema,
463
- strict: true,
464
- name: (_a = responseFormat.name) != null ? _a : "response",
465
- description: responseFormat.description
466
- }
467
- } : { type: "json_object" } : void 0,
449
+ response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? (
450
+ // TODO convert into provider option
451
+ this.settings.structuredOutputs && responseFormat.schema != null ? {
452
+ type: "json_schema",
453
+ json_schema: {
454
+ schema: responseFormat.schema,
455
+ strict: true,
456
+ name: (_b = responseFormat.name) != null ? _b : "response",
457
+ description: responseFormat.description
458
+ }
459
+ } : { type: "json_object" }
460
+ ) : void 0,
468
461
  stop: stopSequences,
469
462
  seed,
470
463
  // openai specific settings:
471
- // TODO remove in next major version; we auto-map maxTokens now
472
- max_completion_tokens: (_b = providerMetadata == null ? void 0 : providerMetadata.openai) == null ? void 0 : _b.maxCompletionTokens,
473
- store: (_c = providerMetadata == null ? void 0 : providerMetadata.openai) == null ? void 0 : _c.store,
474
- metadata: (_d = providerMetadata == null ? void 0 : providerMetadata.openai) == null ? void 0 : _d.metadata,
475
- prediction: (_e = providerMetadata == null ? void 0 : providerMetadata.openai) == null ? void 0 : _e.prediction,
476
- reasoning_effort: (_g = (_f = providerMetadata == null ? void 0 : providerMetadata.openai) == null ? void 0 : _f.reasoningEffort) != null ? _g : this.settings.reasoningEffort,
464
+ // TODO remove in next major version; we auto-map maxOutputTokens now
465
+ max_completion_tokens: openaiOptions.maxCompletionTokens,
466
+ store: openaiOptions.store,
467
+ metadata: openaiOptions.metadata,
468
+ prediction: openaiOptions.prediction,
469
+ reasoning_effort: openaiOptions.reasoningEffort,
477
470
  // messages:
478
471
  messages
479
472
  };
@@ -537,82 +530,33 @@ var OpenAIChatLanguageModel = class {
537
530
  }
538
531
  baseArgs.max_tokens = void 0;
539
532
  }
540
- }
541
- switch (type) {
542
- case "regular": {
543
- const { tools, tool_choice, functions, function_call, toolWarnings } = prepareTools({
544
- mode,
545
- useLegacyFunctionCalling,
546
- structuredOutputs: this.supportsStructuredOutputs
533
+ } else if (this.modelId.startsWith("gpt-4o-search-preview") || this.modelId.startsWith("gpt-4o-mini-search-preview")) {
534
+ if (baseArgs.temperature != null) {
535
+ baseArgs.temperature = void 0;
536
+ warnings.push({
537
+ type: "unsupported-setting",
538
+ setting: "temperature",
539
+ details: "temperature is not supported for the search preview models and has been removed."
547
540
  });
548
- return {
549
- args: {
550
- ...baseArgs,
551
- tools,
552
- tool_choice,
553
- functions,
554
- function_call
555
- },
556
- warnings: [...warnings, ...toolWarnings]
557
- };
558
- }
559
- case "object-json": {
560
- return {
561
- args: {
562
- ...baseArgs,
563
- response_format: this.supportsStructuredOutputs && mode.schema != null ? {
564
- type: "json_schema",
565
- json_schema: {
566
- schema: mode.schema,
567
- strict: true,
568
- name: (_h = mode.name) != null ? _h : "response",
569
- description: mode.description
570
- }
571
- } : { type: "json_object" }
572
- },
573
- warnings
574
- };
575
- }
576
- case "object-tool": {
577
- return {
578
- args: useLegacyFunctionCalling ? {
579
- ...baseArgs,
580
- function_call: {
581
- name: mode.tool.name
582
- },
583
- functions: [
584
- {
585
- name: mode.tool.name,
586
- description: mode.tool.description,
587
- parameters: mode.tool.parameters
588
- }
589
- ]
590
- } : {
591
- ...baseArgs,
592
- tool_choice: {
593
- type: "function",
594
- function: { name: mode.tool.name }
595
- },
596
- tools: [
597
- {
598
- type: "function",
599
- function: {
600
- name: mode.tool.name,
601
- description: mode.tool.description,
602
- parameters: mode.tool.parameters,
603
- strict: this.supportsStructuredOutputs ? true : void 0
604
- }
605
- }
606
- ]
607
- },
608
- warnings
609
- };
610
- }
611
- default: {
612
- const _exhaustiveCheck = type;
613
- throw new Error(`Unsupported type: ${_exhaustiveCheck}`);
614
541
  }
615
542
  }
543
+ const {
544
+ tools: openaiTools,
545
+ toolChoice: openaiToolChoice,
546
+ toolWarnings
547
+ } = prepareTools({
548
+ tools,
549
+ toolChoice,
550
+ structuredOutputs: (_c = this.settings.structuredOutputs) != null ? _c : false
551
+ });
552
+ return {
553
+ args: {
554
+ ...baseArgs,
555
+ tools: openaiTools,
556
+ tool_choice: openaiToolChoice
557
+ },
558
+ warnings: [...warnings, ...toolWarnings]
559
+ };
616
560
  }
617
561
  async doGenerate(options) {
618
562
  var _a, _b, _c, _d, _e, _f, _g, _h;
@@ -635,10 +579,23 @@ var OpenAIChatLanguageModel = class {
635
579
  abortSignal: options.abortSignal,
636
580
  fetch: this.config.fetch
637
581
  });
638
- const { messages: rawPrompt, ...rawSettings } = body;
639
582
  const choice = response.choices[0];
640
- const completionTokenDetails = (_a = response.usage) == null ? void 0 : _a.completion_tokens_details;
641
- const promptTokenDetails = (_b = response.usage) == null ? void 0 : _b.prompt_tokens_details;
583
+ const content = [];
584
+ const text = choice.message.content;
585
+ if (text != null && text.length > 0) {
586
+ content.push({ type: "text", text });
587
+ }
588
+ for (const toolCall of (_a = choice.message.tool_calls) != null ? _a : []) {
589
+ content.push({
590
+ type: "tool-call",
591
+ toolCallType: "function",
592
+ toolCallId: (_b = toolCall.id) != null ? _b : (0, import_provider_utils3.generateId)(),
593
+ toolName: toolCall.function.name,
594
+ args: toolCall.function.arguments
595
+ });
596
+ }
597
+ const completionTokenDetails = (_c = response.usage) == null ? void 0 : _c.completion_tokens_details;
598
+ const promptTokenDetails = (_d = response.usage) == null ? void 0 : _d.prompt_tokens_details;
642
599
  const providerMetadata = { openai: {} };
643
600
  if ((completionTokenDetails == null ? void 0 : completionTokenDetails.reasoning_tokens) != null) {
644
601
  providerMetadata.openai.reasoningTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.reasoning_tokens;
@@ -653,81 +610,24 @@ var OpenAIChatLanguageModel = class {
653
610
  providerMetadata.openai.cachedPromptTokens = promptTokenDetails == null ? void 0 : promptTokenDetails.cached_tokens;
654
611
  }
655
612
  return {
656
- text: (_c = choice.message.content) != null ? _c : void 0,
657
- toolCalls: this.settings.useLegacyFunctionCalling && choice.message.function_call ? [
658
- {
659
- toolCallType: "function",
660
- toolCallId: (0, import_provider_utils3.generateId)(),
661
- toolName: choice.message.function_call.name,
662
- args: choice.message.function_call.arguments
663
- }
664
- ] : (_d = choice.message.tool_calls) == null ? void 0 : _d.map((toolCall) => {
665
- var _a2;
666
- return {
667
- toolCallType: "function",
668
- toolCallId: (_a2 = toolCall.id) != null ? _a2 : (0, import_provider_utils3.generateId)(),
669
- toolName: toolCall.function.name,
670
- args: toolCall.function.arguments
671
- };
672
- }),
613
+ content,
673
614
  finishReason: mapOpenAIFinishReason(choice.finish_reason),
674
615
  usage: {
675
- promptTokens: (_f = (_e = response.usage) == null ? void 0 : _e.prompt_tokens) != null ? _f : NaN,
676
- completionTokens: (_h = (_g = response.usage) == null ? void 0 : _g.completion_tokens) != null ? _h : NaN
616
+ inputTokens: (_f = (_e = response.usage) == null ? void 0 : _e.prompt_tokens) != null ? _f : void 0,
617
+ outputTokens: (_h = (_g = response.usage) == null ? void 0 : _g.completion_tokens) != null ? _h : void 0
618
+ },
619
+ request: { body },
620
+ response: {
621
+ ...getResponseMetadata(response),
622
+ headers: responseHeaders,
623
+ body: rawResponse
677
624
  },
678
- rawCall: { rawPrompt, rawSettings },
679
- rawResponse: { headers: responseHeaders, body: rawResponse },
680
- request: { body: JSON.stringify(body) },
681
- response: getResponseMetadata(response),
682
625
  warnings,
683
626
  logprobs: mapOpenAIChatLogProbsOutput(choice.logprobs),
684
627
  providerMetadata
685
628
  };
686
629
  }
687
630
  async doStream(options) {
688
- if (this.settings.simulateStreaming) {
689
- const result = await this.doGenerate(options);
690
- const simulatedStream = new ReadableStream({
691
- start(controller) {
692
- controller.enqueue({ type: "response-metadata", ...result.response });
693
- if (result.text) {
694
- controller.enqueue({
695
- type: "text-delta",
696
- textDelta: result.text
697
- });
698
- }
699
- if (result.toolCalls) {
700
- for (const toolCall of result.toolCalls) {
701
- controller.enqueue({
702
- type: "tool-call-delta",
703
- toolCallType: "function",
704
- toolCallId: toolCall.toolCallId,
705
- toolName: toolCall.toolName,
706
- argsTextDelta: toolCall.args
707
- });
708
- controller.enqueue({
709
- type: "tool-call",
710
- ...toolCall
711
- });
712
- }
713
- }
714
- controller.enqueue({
715
- type: "finish",
716
- finishReason: result.finishReason,
717
- usage: result.usage,
718
- logprobs: result.logprobs,
719
- providerMetadata: result.providerMetadata
720
- });
721
- controller.close();
722
- }
723
- });
724
- return {
725
- stream: simulatedStream,
726
- rawCall: result.rawCall,
727
- rawResponse: result.rawResponse,
728
- warnings: result.warnings
729
- };
730
- }
731
631
  const { args, warnings } = this.getArgs(options);
732
632
  const body = {
733
633
  ...args,
@@ -752,17 +652,19 @@ var OpenAIChatLanguageModel = class {
752
652
  const { messages: rawPrompt, ...rawSettings } = args;
753
653
  const toolCalls = [];
754
654
  let finishReason = "unknown";
755
- let usage = {
756
- promptTokens: void 0,
757
- completionTokens: void 0
655
+ const usage = {
656
+ inputTokens: void 0,
657
+ outputTokens: void 0
758
658
  };
759
659
  let logprobs;
760
660
  let isFirstChunk = true;
761
- const { useLegacyFunctionCalling } = this.settings;
762
661
  const providerMetadata = { openai: {} };
763
662
  return {
764
663
  stream: response.pipeThrough(
765
664
  new TransformStream({
665
+ start(controller) {
666
+ controller.enqueue({ type: "stream-start", warnings });
667
+ },
766
668
  transform(chunk, controller) {
767
669
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
768
670
  if (!chunk.success) {
@@ -790,10 +692,8 @@ var OpenAIChatLanguageModel = class {
790
692
  prompt_tokens_details,
791
693
  completion_tokens_details
792
694
  } = value.usage;
793
- usage = {
794
- promptTokens: prompt_tokens != null ? prompt_tokens : void 0,
795
- completionTokens: completion_tokens != null ? completion_tokens : void 0
796
- };
695
+ usage.inputTokens = prompt_tokens != null ? prompt_tokens : void 0;
696
+ usage.outputTokens = completion_tokens != null ? completion_tokens : void 0;
797
697
  if ((completion_tokens_details == null ? void 0 : completion_tokens_details.reasoning_tokens) != null) {
798
698
  providerMetadata.openai.reasoningTokens = completion_tokens_details == null ? void 0 : completion_tokens_details.reasoning_tokens;
799
699
  }
@@ -817,8 +717,8 @@ var OpenAIChatLanguageModel = class {
817
717
  const delta = choice.delta;
818
718
  if (delta.content != null) {
819
719
  controller.enqueue({
820
- type: "text-delta",
821
- textDelta: delta.content
720
+ type: "text",
721
+ text: delta.content
822
722
  });
823
723
  }
824
724
  const mappedLogprobs = mapOpenAIChatLogProbsOutput(
@@ -828,16 +728,8 @@ var OpenAIChatLanguageModel = class {
828
728
  if (logprobs === void 0) logprobs = [];
829
729
  logprobs.push(...mappedLogprobs);
830
730
  }
831
- const mappedToolCalls = useLegacyFunctionCalling && delta.function_call != null ? [
832
- {
833
- type: "function",
834
- id: (0, import_provider_utils3.generateId)(),
835
- function: delta.function_call,
836
- index: 0
837
- }
838
- ] : delta.tool_calls;
839
- if (mappedToolCalls != null) {
840
- for (const toolCallDelta of mappedToolCalls) {
731
+ if (delta.tool_calls != null) {
732
+ for (const toolCallDelta of delta.tool_calls) {
841
733
  const index = toolCallDelta.index;
842
734
  if (toolCalls[index] == null) {
843
735
  if (toolCallDelta.type !== "function") {
@@ -919,125 +811,111 @@ var OpenAIChatLanguageModel = class {
919
811
  }
920
812
  },
921
813
  flush(controller) {
922
- var _a, _b;
923
814
  controller.enqueue({
924
815
  type: "finish",
925
816
  finishReason,
926
817
  logprobs,
927
- usage: {
928
- promptTokens: (_a = usage.promptTokens) != null ? _a : NaN,
929
- completionTokens: (_b = usage.completionTokens) != null ? _b : NaN
930
- },
818
+ usage,
931
819
  ...providerMetadata != null ? { providerMetadata } : {}
932
820
  });
933
821
  }
934
822
  })
935
823
  ),
936
- rawCall: { rawPrompt, rawSettings },
937
- rawResponse: { headers: responseHeaders },
938
- request: { body: JSON.stringify(body) },
939
- warnings
824
+ request: { body },
825
+ response: { headers: responseHeaders }
940
826
  };
941
827
  }
942
828
  };
943
- var openaiTokenUsageSchema = import_zod2.z.object({
944
- prompt_tokens: import_zod2.z.number().nullish(),
945
- completion_tokens: import_zod2.z.number().nullish(),
946
- prompt_tokens_details: import_zod2.z.object({
947
- cached_tokens: import_zod2.z.number().nullish()
829
+ var openaiTokenUsageSchema = import_zod3.z.object({
830
+ prompt_tokens: import_zod3.z.number().nullish(),
831
+ completion_tokens: import_zod3.z.number().nullish(),
832
+ prompt_tokens_details: import_zod3.z.object({
833
+ cached_tokens: import_zod3.z.number().nullish()
948
834
  }).nullish(),
949
- completion_tokens_details: import_zod2.z.object({
950
- reasoning_tokens: import_zod2.z.number().nullish(),
951
- accepted_prediction_tokens: import_zod2.z.number().nullish(),
952
- rejected_prediction_tokens: import_zod2.z.number().nullish()
835
+ completion_tokens_details: import_zod3.z.object({
836
+ reasoning_tokens: import_zod3.z.number().nullish(),
837
+ accepted_prediction_tokens: import_zod3.z.number().nullish(),
838
+ rejected_prediction_tokens: import_zod3.z.number().nullish()
953
839
  }).nullish()
954
840
  }).nullish();
955
- var openaiChatResponseSchema = import_zod2.z.object({
956
- id: import_zod2.z.string().nullish(),
957
- created: import_zod2.z.number().nullish(),
958
- model: import_zod2.z.string().nullish(),
959
- choices: import_zod2.z.array(
960
- import_zod2.z.object({
961
- message: import_zod2.z.object({
962
- role: import_zod2.z.literal("assistant").nullish(),
963
- content: import_zod2.z.string().nullish(),
964
- function_call: import_zod2.z.object({
965
- arguments: import_zod2.z.string(),
966
- name: import_zod2.z.string()
967
- }).nullish(),
968
- tool_calls: import_zod2.z.array(
969
- import_zod2.z.object({
970
- id: import_zod2.z.string().nullish(),
971
- type: import_zod2.z.literal("function"),
972
- function: import_zod2.z.object({
973
- name: import_zod2.z.string(),
974
- arguments: import_zod2.z.string()
841
+ var openaiChatResponseSchema = import_zod3.z.object({
842
+ id: import_zod3.z.string().nullish(),
843
+ created: import_zod3.z.number().nullish(),
844
+ model: import_zod3.z.string().nullish(),
845
+ choices: import_zod3.z.array(
846
+ import_zod3.z.object({
847
+ message: import_zod3.z.object({
848
+ role: import_zod3.z.literal("assistant").nullish(),
849
+ content: import_zod3.z.string().nullish(),
850
+ tool_calls: import_zod3.z.array(
851
+ import_zod3.z.object({
852
+ id: import_zod3.z.string().nullish(),
853
+ type: import_zod3.z.literal("function"),
854
+ function: import_zod3.z.object({
855
+ name: import_zod3.z.string(),
856
+ arguments: import_zod3.z.string()
975
857
  })
976
858
  })
977
859
  ).nullish()
978
860
  }),
979
- index: import_zod2.z.number(),
980
- logprobs: import_zod2.z.object({
981
- content: import_zod2.z.array(
982
- import_zod2.z.object({
983
- token: import_zod2.z.string(),
984
- logprob: import_zod2.z.number(),
985
- top_logprobs: import_zod2.z.array(
986
- import_zod2.z.object({
987
- token: import_zod2.z.string(),
988
- logprob: import_zod2.z.number()
861
+ index: import_zod3.z.number(),
862
+ logprobs: import_zod3.z.object({
863
+ content: import_zod3.z.array(
864
+ import_zod3.z.object({
865
+ token: import_zod3.z.string(),
866
+ logprob: import_zod3.z.number(),
867
+ top_logprobs: import_zod3.z.array(
868
+ import_zod3.z.object({
869
+ token: import_zod3.z.string(),
870
+ logprob: import_zod3.z.number()
989
871
  })
990
872
  )
991
873
  })
992
874
  ).nullable()
993
875
  }).nullish(),
994
- finish_reason: import_zod2.z.string().nullish()
876
+ finish_reason: import_zod3.z.string().nullish()
995
877
  })
996
878
  ),
997
879
  usage: openaiTokenUsageSchema
998
880
  });
999
- var openaiChatChunkSchema = import_zod2.z.union([
1000
- import_zod2.z.object({
1001
- id: import_zod2.z.string().nullish(),
1002
- created: import_zod2.z.number().nullish(),
1003
- model: import_zod2.z.string().nullish(),
1004
- choices: import_zod2.z.array(
1005
- import_zod2.z.object({
1006
- delta: import_zod2.z.object({
1007
- role: import_zod2.z.enum(["assistant"]).nullish(),
1008
- content: import_zod2.z.string().nullish(),
1009
- function_call: import_zod2.z.object({
1010
- name: import_zod2.z.string().optional(),
1011
- arguments: import_zod2.z.string().optional()
1012
- }).nullish(),
1013
- tool_calls: import_zod2.z.array(
1014
- import_zod2.z.object({
1015
- index: import_zod2.z.number(),
1016
- id: import_zod2.z.string().nullish(),
1017
- type: import_zod2.z.literal("function").optional(),
1018
- function: import_zod2.z.object({
1019
- name: import_zod2.z.string().nullish(),
1020
- arguments: import_zod2.z.string().nullish()
881
+ var openaiChatChunkSchema = import_zod3.z.union([
882
+ import_zod3.z.object({
883
+ id: import_zod3.z.string().nullish(),
884
+ created: import_zod3.z.number().nullish(),
885
+ model: import_zod3.z.string().nullish(),
886
+ choices: import_zod3.z.array(
887
+ import_zod3.z.object({
888
+ delta: import_zod3.z.object({
889
+ role: import_zod3.z.enum(["assistant"]).nullish(),
890
+ content: import_zod3.z.string().nullish(),
891
+ tool_calls: import_zod3.z.array(
892
+ import_zod3.z.object({
893
+ index: import_zod3.z.number(),
894
+ id: import_zod3.z.string().nullish(),
895
+ type: import_zod3.z.literal("function").optional(),
896
+ function: import_zod3.z.object({
897
+ name: import_zod3.z.string().nullish(),
898
+ arguments: import_zod3.z.string().nullish()
1021
899
  })
1022
900
  })
1023
901
  ).nullish()
1024
902
  }).nullish(),
1025
- logprobs: import_zod2.z.object({
1026
- content: import_zod2.z.array(
1027
- import_zod2.z.object({
1028
- token: import_zod2.z.string(),
1029
- logprob: import_zod2.z.number(),
1030
- top_logprobs: import_zod2.z.array(
1031
- import_zod2.z.object({
1032
- token: import_zod2.z.string(),
1033
- logprob: import_zod2.z.number()
903
+ logprobs: import_zod3.z.object({
904
+ content: import_zod3.z.array(
905
+ import_zod3.z.object({
906
+ token: import_zod3.z.string(),
907
+ logprob: import_zod3.z.number(),
908
+ top_logprobs: import_zod3.z.array(
909
+ import_zod3.z.object({
910
+ token: import_zod3.z.string(),
911
+ logprob: import_zod3.z.number()
1034
912
  })
1035
913
  )
1036
914
  })
1037
915
  ).nullable()
1038
916
  }).nullish(),
1039
- finish_reason: import_zod2.z.string().nullable().optional(),
1040
- index: import_zod2.z.number()
917
+ finish_reason: import_zod3.z.string().nullable().optional(),
918
+ index: import_zod3.z.number()
1041
919
  })
1042
920
  ),
1043
921
  usage: openaiTokenUsageSchema
@@ -1045,10 +923,7 @@ var openaiChatChunkSchema = import_zod2.z.union([
1045
923
  openaiErrorDataSchema
1046
924
  ]);
1047
925
  function isReasoningModel(modelId) {
1048
- return modelId === "o1" || modelId.startsWith("o1-") || modelId === "o3" || modelId.startsWith("o3-");
1049
- }
1050
- function isAudioModel(modelId) {
1051
- return modelId.startsWith("gpt-4o-audio-preview");
926
+ return modelId.startsWith("o");
1052
927
  }
1053
928
  function getSystemMessageMode(modelId) {
1054
929
  var _a, _b;
@@ -1079,9 +954,8 @@ var reasoningModels = {
1079
954
  };
1080
955
 
1081
956
  // src/openai-completion-language-model.ts
1082
- var import_provider5 = require("@ai-sdk/provider");
1083
957
  var import_provider_utils4 = require("@ai-sdk/provider-utils");
1084
- var import_zod3 = require("zod");
958
+ var import_zod4 = require("zod");
1085
959
 
1086
960
  // src/convert-to-openai-completion-prompt.ts
1087
961
  var import_provider4 = require("@ai-sdk/provider");
@@ -1115,13 +989,8 @@ function convertToOpenAICompletionPrompt({
1115
989
  case "text": {
1116
990
  return part.text;
1117
991
  }
1118
- case "image": {
1119
- throw new import_provider4.UnsupportedFunctionalityError({
1120
- functionality: "images"
1121
- });
1122
- }
1123
992
  }
1124
- }).join("");
993
+ }).filter(Boolean).join("");
1125
994
  text += `${user}:
1126
995
  ${userMessage}
1127
996
 
@@ -1185,7 +1054,6 @@ function mapOpenAICompletionLogProbs(logprobs) {
1185
1054
  var OpenAICompletionLanguageModel = class {
1186
1055
  constructor(modelId, settings, config) {
1187
1056
  this.specificationVersion = "v2";
1188
- this.defaultObjectGenerationMode = void 0;
1189
1057
  this.modelId = modelId;
1190
1058
  this.settings = settings;
1191
1059
  this.config = config;
@@ -1193,11 +1061,15 @@ var OpenAICompletionLanguageModel = class {
1193
1061
  get provider() {
1194
1062
  return this.config.provider;
1195
1063
  }
1064
+ async getSupportedUrls() {
1065
+ return {
1066
+ // no supported urls for completion models
1067
+ };
1068
+ }
1196
1069
  getArgs({
1197
- mode,
1198
1070
  inputFormat,
1199
1071
  prompt,
1200
- maxTokens,
1072
+ maxOutputTokens,
1201
1073
  temperature,
1202
1074
  topP,
1203
1075
  topK,
@@ -1205,16 +1077,19 @@ var OpenAICompletionLanguageModel = class {
1205
1077
  presencePenalty,
1206
1078
  stopSequences: userStopSequences,
1207
1079
  responseFormat,
1080
+ tools,
1081
+ toolChoice,
1208
1082
  seed
1209
1083
  }) {
1210
- var _a;
1211
- const type = mode.type;
1212
1084
  const warnings = [];
1213
1085
  if (topK != null) {
1214
- warnings.push({
1215
- type: "unsupported-setting",
1216
- setting: "topK"
1217
- });
1086
+ warnings.push({ type: "unsupported-setting", setting: "topK" });
1087
+ }
1088
+ if (tools == null ? void 0 : tools.length) {
1089
+ warnings.push({ type: "unsupported-setting", setting: "tools" });
1090
+ }
1091
+ if (toolChoice != null) {
1092
+ warnings.push({ type: "unsupported-setting", setting: "toolChoice" });
1218
1093
  }
1219
1094
  if (responseFormat != null && responseFormat.type !== "text") {
1220
1095
  warnings.push({
@@ -1225,56 +1100,30 @@ var OpenAICompletionLanguageModel = class {
1225
1100
  }
1226
1101
  const { prompt: completionPrompt, stopSequences } = convertToOpenAICompletionPrompt({ prompt, inputFormat });
1227
1102
  const stop = [...stopSequences != null ? stopSequences : [], ...userStopSequences != null ? userStopSequences : []];
1228
- const baseArgs = {
1229
- // model id:
1230
- model: this.modelId,
1231
- // model specific settings:
1232
- echo: this.settings.echo,
1233
- logit_bias: this.settings.logitBias,
1234
- logprobs: typeof this.settings.logprobs === "number" ? this.settings.logprobs : typeof this.settings.logprobs === "boolean" ? this.settings.logprobs ? 0 : void 0 : void 0,
1235
- suffix: this.settings.suffix,
1236
- user: this.settings.user,
1237
- // standardized settings:
1238
- max_tokens: maxTokens,
1239
- temperature,
1240
- top_p: topP,
1241
- frequency_penalty: frequencyPenalty,
1242
- presence_penalty: presencePenalty,
1243
- seed,
1244
- // prompt:
1245
- prompt: completionPrompt,
1246
- // stop sequences:
1247
- stop: stop.length > 0 ? stop : void 0
1103
+ return {
1104
+ args: {
1105
+ // model id:
1106
+ model: this.modelId,
1107
+ // model specific settings:
1108
+ echo: this.settings.echo,
1109
+ logit_bias: this.settings.logitBias,
1110
+ logprobs: typeof this.settings.logprobs === "number" ? this.settings.logprobs : typeof this.settings.logprobs === "boolean" ? this.settings.logprobs ? 0 : void 0 : void 0,
1111
+ suffix: this.settings.suffix,
1112
+ user: this.settings.user,
1113
+ // standardized settings:
1114
+ max_tokens: maxOutputTokens,
1115
+ temperature,
1116
+ top_p: topP,
1117
+ frequency_penalty: frequencyPenalty,
1118
+ presence_penalty: presencePenalty,
1119
+ seed,
1120
+ // prompt:
1121
+ prompt: completionPrompt,
1122
+ // stop sequences:
1123
+ stop: stop.length > 0 ? stop : void 0
1124
+ },
1125
+ warnings
1248
1126
  };
1249
- switch (type) {
1250
- case "regular": {
1251
- if ((_a = mode.tools) == null ? void 0 : _a.length) {
1252
- throw new import_provider5.UnsupportedFunctionalityError({
1253
- functionality: "tools"
1254
- });
1255
- }
1256
- if (mode.toolChoice) {
1257
- throw new import_provider5.UnsupportedFunctionalityError({
1258
- functionality: "toolChoice"
1259
- });
1260
- }
1261
- return { args: baseArgs, warnings };
1262
- }
1263
- case "object-json": {
1264
- throw new import_provider5.UnsupportedFunctionalityError({
1265
- functionality: "object-json mode"
1266
- });
1267
- }
1268
- case "object-tool": {
1269
- throw new import_provider5.UnsupportedFunctionalityError({
1270
- functionality: "object-tool mode"
1271
- });
1272
- }
1273
- default: {
1274
- const _exhaustiveCheck = type;
1275
- throw new Error(`Unsupported type: ${_exhaustiveCheck}`);
1276
- }
1277
- }
1278
1127
  }
1279
1128
  async doGenerate(options) {
1280
1129
  const { args, warnings } = this.getArgs(options);
@@ -1296,21 +1145,22 @@ var OpenAICompletionLanguageModel = class {
1296
1145
  abortSignal: options.abortSignal,
1297
1146
  fetch: this.config.fetch
1298
1147
  });
1299
- const { prompt: rawPrompt, ...rawSettings } = args;
1300
1148
  const choice = response.choices[0];
1301
1149
  return {
1302
- text: choice.text,
1150
+ content: [{ type: "text", text: choice.text }],
1303
1151
  usage: {
1304
- promptTokens: response.usage.prompt_tokens,
1305
- completionTokens: response.usage.completion_tokens
1152
+ inputTokens: response.usage.prompt_tokens,
1153
+ outputTokens: response.usage.completion_tokens
1306
1154
  },
1307
1155
  finishReason: mapOpenAIFinishReason(choice.finish_reason),
1308
1156
  logprobs: mapOpenAICompletionLogProbs(choice.logprobs),
1309
- rawCall: { rawPrompt, rawSettings },
1310
- rawResponse: { headers: responseHeaders, body: rawResponse },
1311
- response: getResponseMetadata(response),
1312
- warnings,
1313
- request: { body: JSON.stringify(args) }
1157
+ request: { body: args },
1158
+ response: {
1159
+ ...getResponseMetadata(response),
1160
+ headers: responseHeaders,
1161
+ body: rawResponse
1162
+ },
1163
+ warnings
1314
1164
  };
1315
1165
  }
1316
1166
  async doStream(options) {
@@ -1335,17 +1185,19 @@ var OpenAICompletionLanguageModel = class {
1335
1185
  abortSignal: options.abortSignal,
1336
1186
  fetch: this.config.fetch
1337
1187
  });
1338
- const { prompt: rawPrompt, ...rawSettings } = args;
1339
1188
  let finishReason = "unknown";
1340
- let usage = {
1341
- promptTokens: Number.NaN,
1342
- completionTokens: Number.NaN
1189
+ const usage = {
1190
+ inputTokens: void 0,
1191
+ outputTokens: void 0
1343
1192
  };
1344
1193
  let logprobs;
1345
1194
  let isFirstChunk = true;
1346
1195
  return {
1347
1196
  stream: response.pipeThrough(
1348
1197
  new TransformStream({
1198
+ start(controller) {
1199
+ controller.enqueue({ type: "stream-start", warnings });
1200
+ },
1349
1201
  transform(chunk, controller) {
1350
1202
  if (!chunk.success) {
1351
1203
  finishReason = "error";
@@ -1366,10 +1218,8 @@ var OpenAICompletionLanguageModel = class {
1366
1218
  });
1367
1219
  }
1368
1220
  if (value.usage != null) {
1369
- usage = {
1370
- promptTokens: value.usage.prompt_tokens,
1371
- completionTokens: value.usage.completion_tokens
1372
- };
1221
+ usage.inputTokens = value.usage.prompt_tokens;
1222
+ usage.outputTokens = value.usage.completion_tokens;
1373
1223
  }
1374
1224
  const choice = value.choices[0];
1375
1225
  if ((choice == null ? void 0 : choice.finish_reason) != null) {
@@ -1377,8 +1227,8 @@ var OpenAICompletionLanguageModel = class {
1377
1227
  }
1378
1228
  if ((choice == null ? void 0 : choice.text) != null) {
1379
1229
  controller.enqueue({
1380
- type: "text-delta",
1381
- textDelta: choice.text
1230
+ type: "text",
1231
+ text: choice.text
1382
1232
  });
1383
1233
  }
1384
1234
  const mappedLogprobs = mapOpenAICompletionLogProbs(
@@ -1399,65 +1249,80 @@ var OpenAICompletionLanguageModel = class {
1399
1249
  }
1400
1250
  })
1401
1251
  ),
1402
- rawCall: { rawPrompt, rawSettings },
1403
- rawResponse: { headers: responseHeaders },
1404
- warnings,
1405
- request: { body: JSON.stringify(body) }
1252
+ request: { body },
1253
+ response: { headers: responseHeaders }
1406
1254
  };
1407
1255
  }
1408
1256
  };
1409
- var openaiCompletionResponseSchema = import_zod3.z.object({
1410
- id: import_zod3.z.string().nullish(),
1411
- created: import_zod3.z.number().nullish(),
1412
- model: import_zod3.z.string().nullish(),
1413
- choices: import_zod3.z.array(
1414
- import_zod3.z.object({
1415
- text: import_zod3.z.string(),
1416
- finish_reason: import_zod3.z.string(),
1417
- logprobs: import_zod3.z.object({
1418
- tokens: import_zod3.z.array(import_zod3.z.string()),
1419
- token_logprobs: import_zod3.z.array(import_zod3.z.number()),
1420
- top_logprobs: import_zod3.z.array(import_zod3.z.record(import_zod3.z.string(), import_zod3.z.number())).nullable()
1257
+ var openaiCompletionResponseSchema = import_zod4.z.object({
1258
+ id: import_zod4.z.string().nullish(),
1259
+ created: import_zod4.z.number().nullish(),
1260
+ model: import_zod4.z.string().nullish(),
1261
+ choices: import_zod4.z.array(
1262
+ import_zod4.z.object({
1263
+ text: import_zod4.z.string(),
1264
+ finish_reason: import_zod4.z.string(),
1265
+ logprobs: import_zod4.z.object({
1266
+ tokens: import_zod4.z.array(import_zod4.z.string()),
1267
+ token_logprobs: import_zod4.z.array(import_zod4.z.number()),
1268
+ top_logprobs: import_zod4.z.array(import_zod4.z.record(import_zod4.z.string(), import_zod4.z.number())).nullable()
1421
1269
  }).nullish()
1422
1270
  })
1423
1271
  ),
1424
- usage: import_zod3.z.object({
1425
- prompt_tokens: import_zod3.z.number(),
1426
- completion_tokens: import_zod3.z.number()
1272
+ usage: import_zod4.z.object({
1273
+ prompt_tokens: import_zod4.z.number(),
1274
+ completion_tokens: import_zod4.z.number()
1427
1275
  })
1428
1276
  });
1429
- var openaiCompletionChunkSchema = import_zod3.z.union([
1430
- import_zod3.z.object({
1431
- id: import_zod3.z.string().nullish(),
1432
- created: import_zod3.z.number().nullish(),
1433
- model: import_zod3.z.string().nullish(),
1434
- choices: import_zod3.z.array(
1435
- import_zod3.z.object({
1436
- text: import_zod3.z.string(),
1437
- finish_reason: import_zod3.z.string().nullish(),
1438
- index: import_zod3.z.number(),
1439
- logprobs: import_zod3.z.object({
1440
- tokens: import_zod3.z.array(import_zod3.z.string()),
1441
- token_logprobs: import_zod3.z.array(import_zod3.z.number()),
1442
- top_logprobs: import_zod3.z.array(import_zod3.z.record(import_zod3.z.string(), import_zod3.z.number())).nullable()
1277
+ var openaiCompletionChunkSchema = import_zod4.z.union([
1278
+ import_zod4.z.object({
1279
+ id: import_zod4.z.string().nullish(),
1280
+ created: import_zod4.z.number().nullish(),
1281
+ model: import_zod4.z.string().nullish(),
1282
+ choices: import_zod4.z.array(
1283
+ import_zod4.z.object({
1284
+ text: import_zod4.z.string(),
1285
+ finish_reason: import_zod4.z.string().nullish(),
1286
+ index: import_zod4.z.number(),
1287
+ logprobs: import_zod4.z.object({
1288
+ tokens: import_zod4.z.array(import_zod4.z.string()),
1289
+ token_logprobs: import_zod4.z.array(import_zod4.z.number()),
1290
+ top_logprobs: import_zod4.z.array(import_zod4.z.record(import_zod4.z.string(), import_zod4.z.number())).nullable()
1443
1291
  }).nullish()
1444
1292
  })
1445
1293
  ),
1446
- usage: import_zod3.z.object({
1447
- prompt_tokens: import_zod3.z.number(),
1448
- completion_tokens: import_zod3.z.number()
1294
+ usage: import_zod4.z.object({
1295
+ prompt_tokens: import_zod4.z.number(),
1296
+ completion_tokens: import_zod4.z.number()
1449
1297
  }).nullish()
1450
1298
  }),
1451
1299
  openaiErrorDataSchema
1452
1300
  ]);
1453
1301
 
1454
1302
  // src/openai-embedding-model.ts
1455
- var import_provider6 = require("@ai-sdk/provider");
1303
+ var import_provider5 = require("@ai-sdk/provider");
1456
1304
  var import_provider_utils5 = require("@ai-sdk/provider-utils");
1457
- var import_zod4 = require("zod");
1305
+ var import_zod6 = require("zod");
1306
+
1307
+ // src/openai-embedding-options.ts
1308
+ var import_zod5 = require("zod");
1309
+ var openaiEmbeddingProviderOptions = import_zod5.z.object({
1310
+ /**
1311
+ The number of dimensions the resulting output embeddings should have.
1312
+ Only supported in text-embedding-3 and later models.
1313
+ */
1314
+ dimensions: import_zod5.z.number().optional(),
1315
+ /**
1316
+ A unique identifier representing your end-user, which can help OpenAI to
1317
+ monitor and detect abuse. Learn more.
1318
+ */
1319
+ user: import_zod5.z.string().optional()
1320
+ });
1321
+
1322
+ // src/openai-embedding-model.ts
1458
1323
  var OpenAIEmbeddingModel = class {
1459
1324
  constructor(modelId, settings, config) {
1460
- this.specificationVersion = "v1";
1325
+ this.specificationVersion = "v2";
1461
1326
  this.modelId = modelId;
1462
1327
  this.settings = settings;
1463
1328
  this.config = config;
@@ -1476,17 +1341,28 @@ var OpenAIEmbeddingModel = class {
1476
1341
  async doEmbed({
1477
1342
  values,
1478
1343
  headers,
1479
- abortSignal
1344
+ abortSignal,
1345
+ providerOptions
1480
1346
  }) {
1347
+ var _a;
1481
1348
  if (values.length > this.maxEmbeddingsPerCall) {
1482
- throw new import_provider6.TooManyEmbeddingValuesForCallError({
1349
+ throw new import_provider5.TooManyEmbeddingValuesForCallError({
1483
1350
  provider: this.provider,
1484
1351
  modelId: this.modelId,
1485
1352
  maxEmbeddingsPerCall: this.maxEmbeddingsPerCall,
1486
1353
  values
1487
1354
  });
1488
1355
  }
1489
- const { responseHeaders, value: response } = await (0, import_provider_utils5.postJsonToApi)({
1356
+ const openaiOptions = (_a = (0, import_provider_utils5.parseProviderOptions)({
1357
+ provider: "openai",
1358
+ providerOptions,
1359
+ schema: openaiEmbeddingProviderOptions
1360
+ })) != null ? _a : {};
1361
+ const {
1362
+ responseHeaders,
1363
+ value: response,
1364
+ rawValue
1365
+ } = await (0, import_provider_utils5.postJsonToApi)({
1490
1366
  url: this.config.url({
1491
1367
  path: "/embeddings",
1492
1368
  modelId: this.modelId
@@ -1496,8 +1372,8 @@ var OpenAIEmbeddingModel = class {
1496
1372
  model: this.modelId,
1497
1373
  input: values,
1498
1374
  encoding_format: "float",
1499
- dimensions: this.settings.dimensions,
1500
- user: this.settings.user
1375
+ dimensions: openaiOptions.dimensions,
1376
+ user: openaiOptions.user
1501
1377
  },
1502
1378
  failedResponseHandler: openaiFailedResponseHandler,
1503
1379
  successfulResponseHandler: (0, import_provider_utils5.createJsonResponseHandler)(
@@ -1509,18 +1385,18 @@ var OpenAIEmbeddingModel = class {
1509
1385
  return {
1510
1386
  embeddings: response.data.map((item) => item.embedding),
1511
1387
  usage: response.usage ? { tokens: response.usage.prompt_tokens } : void 0,
1512
- rawResponse: { headers: responseHeaders }
1388
+ response: { headers: responseHeaders, body: rawValue }
1513
1389
  };
1514
1390
  }
1515
1391
  };
1516
- var openaiTextEmbeddingResponseSchema = import_zod4.z.object({
1517
- data: import_zod4.z.array(import_zod4.z.object({ embedding: import_zod4.z.array(import_zod4.z.number()) })),
1518
- usage: import_zod4.z.object({ prompt_tokens: import_zod4.z.number() }).nullish()
1392
+ var openaiTextEmbeddingResponseSchema = import_zod6.z.object({
1393
+ data: import_zod6.z.array(import_zod6.z.object({ embedding: import_zod6.z.array(import_zod6.z.number()) })),
1394
+ usage: import_zod6.z.object({ prompt_tokens: import_zod6.z.number() }).nullish()
1519
1395
  });
1520
1396
 
1521
1397
  // src/openai-image-model.ts
1522
1398
  var import_provider_utils6 = require("@ai-sdk/provider-utils");
1523
- var import_zod5 = require("zod");
1399
+ var import_zod7 = require("zod");
1524
1400
 
1525
1401
  // src/openai-image-settings.ts
1526
1402
  var modelMaxImagesPerCall = {
@@ -1598,17 +1474,284 @@ var OpenAIImageModel = class {
1598
1474
  };
1599
1475
  }
1600
1476
  };
1601
- var openaiImageResponseSchema = import_zod5.z.object({
1602
- data: import_zod5.z.array(import_zod5.z.object({ b64_json: import_zod5.z.string() }))
1477
+ var openaiImageResponseSchema = import_zod7.z.object({
1478
+ data: import_zod7.z.array(import_zod7.z.object({ b64_json: import_zod7.z.string() }))
1603
1479
  });
1604
1480
 
1605
- // src/responses/openai-responses-language-model.ts
1481
+ // src/openai-transcription-model.ts
1482
+ var import_provider_utils7 = require("@ai-sdk/provider-utils");
1483
+ var import_zod8 = require("zod");
1484
+ var openAIProviderOptionsSchema = import_zod8.z.object({
1485
+ include: import_zod8.z.array(import_zod8.z.string()).nullish(),
1486
+ language: import_zod8.z.string().nullish(),
1487
+ prompt: import_zod8.z.string().nullish(),
1488
+ temperature: import_zod8.z.number().min(0).max(1).nullish().default(0),
1489
+ timestampGranularities: import_zod8.z.array(import_zod8.z.enum(["word", "segment"])).nullish().default(["segment"])
1490
+ });
1491
+ var languageMap = {
1492
+ afrikaans: "af",
1493
+ arabic: "ar",
1494
+ armenian: "hy",
1495
+ azerbaijani: "az",
1496
+ belarusian: "be",
1497
+ bosnian: "bs",
1498
+ bulgarian: "bg",
1499
+ catalan: "ca",
1500
+ chinese: "zh",
1501
+ croatian: "hr",
1502
+ czech: "cs",
1503
+ danish: "da",
1504
+ dutch: "nl",
1505
+ english: "en",
1506
+ estonian: "et",
1507
+ finnish: "fi",
1508
+ french: "fr",
1509
+ galician: "gl",
1510
+ german: "de",
1511
+ greek: "el",
1512
+ hebrew: "he",
1513
+ hindi: "hi",
1514
+ hungarian: "hu",
1515
+ icelandic: "is",
1516
+ indonesian: "id",
1517
+ italian: "it",
1518
+ japanese: "ja",
1519
+ kannada: "kn",
1520
+ kazakh: "kk",
1521
+ korean: "ko",
1522
+ latvian: "lv",
1523
+ lithuanian: "lt",
1524
+ macedonian: "mk",
1525
+ malay: "ms",
1526
+ marathi: "mr",
1527
+ maori: "mi",
1528
+ nepali: "ne",
1529
+ norwegian: "no",
1530
+ persian: "fa",
1531
+ polish: "pl",
1532
+ portuguese: "pt",
1533
+ romanian: "ro",
1534
+ russian: "ru",
1535
+ serbian: "sr",
1536
+ slovak: "sk",
1537
+ slovenian: "sl",
1538
+ spanish: "es",
1539
+ swahili: "sw",
1540
+ swedish: "sv",
1541
+ tagalog: "tl",
1542
+ tamil: "ta",
1543
+ thai: "th",
1544
+ turkish: "tr",
1545
+ ukrainian: "uk",
1546
+ urdu: "ur",
1547
+ vietnamese: "vi",
1548
+ welsh: "cy"
1549
+ };
1550
+ var OpenAITranscriptionModel = class {
1551
+ constructor(modelId, config) {
1552
+ this.modelId = modelId;
1553
+ this.config = config;
1554
+ this.specificationVersion = "v1";
1555
+ }
1556
+ get provider() {
1557
+ return this.config.provider;
1558
+ }
1559
+ getArgs({
1560
+ audio,
1561
+ mediaType,
1562
+ providerOptions
1563
+ }) {
1564
+ var _a, _b, _c, _d, _e;
1565
+ const warnings = [];
1566
+ const openAIOptions = (0, import_provider_utils7.parseProviderOptions)({
1567
+ provider: "openai",
1568
+ providerOptions,
1569
+ schema: openAIProviderOptionsSchema
1570
+ });
1571
+ const formData = new FormData();
1572
+ const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([(0, import_provider_utils7.convertBase64ToUint8Array)(audio)]);
1573
+ formData.append("model", this.modelId);
1574
+ formData.append("file", new File([blob], "audio", { type: mediaType }));
1575
+ if (openAIOptions) {
1576
+ const transcriptionModelOptions = {
1577
+ include: (_a = openAIOptions.include) != null ? _a : void 0,
1578
+ language: (_b = openAIOptions.language) != null ? _b : void 0,
1579
+ prompt: (_c = openAIOptions.prompt) != null ? _c : void 0,
1580
+ temperature: (_d = openAIOptions.temperature) != null ? _d : void 0,
1581
+ timestamp_granularities: (_e = openAIOptions.timestampGranularities) != null ? _e : void 0
1582
+ };
1583
+ for (const key in transcriptionModelOptions) {
1584
+ const value = transcriptionModelOptions[key];
1585
+ if (value !== void 0) {
1586
+ formData.append(key, String(value));
1587
+ }
1588
+ }
1589
+ }
1590
+ return {
1591
+ formData,
1592
+ warnings
1593
+ };
1594
+ }
1595
+ async doGenerate(options) {
1596
+ var _a, _b, _c, _d, _e, _f;
1597
+ const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
1598
+ const { formData, warnings } = this.getArgs(options);
1599
+ const {
1600
+ value: response,
1601
+ responseHeaders,
1602
+ rawValue: rawResponse
1603
+ } = await (0, import_provider_utils7.postFormDataToApi)({
1604
+ url: this.config.url({
1605
+ path: "/audio/transcriptions",
1606
+ modelId: this.modelId
1607
+ }),
1608
+ headers: (0, import_provider_utils7.combineHeaders)(this.config.headers(), options.headers),
1609
+ formData,
1610
+ failedResponseHandler: openaiFailedResponseHandler,
1611
+ successfulResponseHandler: (0, import_provider_utils7.createJsonResponseHandler)(
1612
+ openaiTranscriptionResponseSchema
1613
+ ),
1614
+ abortSignal: options.abortSignal,
1615
+ fetch: this.config.fetch
1616
+ });
1617
+ const language = response.language != null && response.language in languageMap ? languageMap[response.language] : void 0;
1618
+ return {
1619
+ text: response.text,
1620
+ segments: (_e = (_d = response.words) == null ? void 0 : _d.map((word) => ({
1621
+ text: word.word,
1622
+ startSecond: word.start,
1623
+ endSecond: word.end
1624
+ }))) != null ? _e : [],
1625
+ language,
1626
+ durationInSeconds: (_f = response.duration) != null ? _f : void 0,
1627
+ warnings,
1628
+ response: {
1629
+ timestamp: currentDate,
1630
+ modelId: this.modelId,
1631
+ headers: responseHeaders,
1632
+ body: rawResponse
1633
+ }
1634
+ };
1635
+ }
1636
+ };
1637
+ var openaiTranscriptionResponseSchema = import_zod8.z.object({
1638
+ text: import_zod8.z.string(),
1639
+ language: import_zod8.z.string().nullish(),
1640
+ duration: import_zod8.z.number().nullish(),
1641
+ words: import_zod8.z.array(
1642
+ import_zod8.z.object({
1643
+ word: import_zod8.z.string(),
1644
+ start: import_zod8.z.number(),
1645
+ end: import_zod8.z.number()
1646
+ })
1647
+ ).nullish()
1648
+ });
1649
+
1650
+ // src/openai-speech-model.ts
1606
1651
  var import_provider_utils8 = require("@ai-sdk/provider-utils");
1607
- var import_zod6 = require("zod");
1652
+ var import_zod9 = require("zod");
1653
+ var OpenAIProviderOptionsSchema = import_zod9.z.object({
1654
+ instructions: import_zod9.z.string().nullish(),
1655
+ speed: import_zod9.z.number().min(0.25).max(4).default(1).nullish()
1656
+ });
1657
+ var OpenAISpeechModel = class {
1658
+ constructor(modelId, config) {
1659
+ this.modelId = modelId;
1660
+ this.config = config;
1661
+ this.specificationVersion = "v1";
1662
+ }
1663
+ get provider() {
1664
+ return this.config.provider;
1665
+ }
1666
+ getArgs({
1667
+ text,
1668
+ voice = "alloy",
1669
+ outputFormat = "mp3",
1670
+ speed,
1671
+ instructions,
1672
+ providerOptions
1673
+ }) {
1674
+ const warnings = [];
1675
+ const openAIOptions = (0, import_provider_utils8.parseProviderOptions)({
1676
+ provider: "openai",
1677
+ providerOptions,
1678
+ schema: OpenAIProviderOptionsSchema
1679
+ });
1680
+ const requestBody = {
1681
+ model: this.modelId,
1682
+ input: text,
1683
+ voice,
1684
+ response_format: "mp3",
1685
+ speed,
1686
+ instructions
1687
+ };
1688
+ if (outputFormat) {
1689
+ if (["mp3", "opus", "aac", "flac", "wav", "pcm"].includes(outputFormat)) {
1690
+ requestBody.response_format = outputFormat;
1691
+ } else {
1692
+ warnings.push({
1693
+ type: "unsupported-setting",
1694
+ setting: "outputFormat",
1695
+ details: `Unsupported output format: ${outputFormat}. Using mp3 instead.`
1696
+ });
1697
+ }
1698
+ }
1699
+ if (openAIOptions) {
1700
+ const speechModelOptions = {};
1701
+ for (const key in speechModelOptions) {
1702
+ const value = speechModelOptions[key];
1703
+ if (value !== void 0) {
1704
+ requestBody[key] = value;
1705
+ }
1706
+ }
1707
+ }
1708
+ return {
1709
+ requestBody,
1710
+ warnings
1711
+ };
1712
+ }
1713
+ async doGenerate(options) {
1714
+ var _a, _b, _c;
1715
+ const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
1716
+ const { requestBody, warnings } = this.getArgs(options);
1717
+ const {
1718
+ value: audio,
1719
+ responseHeaders,
1720
+ rawValue: rawResponse
1721
+ } = await (0, import_provider_utils8.postJsonToApi)({
1722
+ url: this.config.url({
1723
+ path: "/audio/speech",
1724
+ modelId: this.modelId
1725
+ }),
1726
+ headers: (0, import_provider_utils8.combineHeaders)(this.config.headers(), options.headers),
1727
+ body: requestBody,
1728
+ failedResponseHandler: openaiFailedResponseHandler,
1729
+ successfulResponseHandler: (0, import_provider_utils8.createBinaryResponseHandler)(),
1730
+ abortSignal: options.abortSignal,
1731
+ fetch: this.config.fetch
1732
+ });
1733
+ return {
1734
+ audio,
1735
+ warnings,
1736
+ request: {
1737
+ body: JSON.stringify(requestBody)
1738
+ },
1739
+ response: {
1740
+ timestamp: currentDate,
1741
+ modelId: this.modelId,
1742
+ headers: responseHeaders,
1743
+ body: rawResponse
1744
+ }
1745
+ };
1746
+ }
1747
+ };
1748
+
1749
+ // src/responses/openai-responses-language-model.ts
1750
+ var import_provider_utils9 = require("@ai-sdk/provider-utils");
1751
+ var import_zod10 = require("zod");
1608
1752
 
1609
1753
  // src/responses/convert-to-openai-responses-messages.ts
1610
- var import_provider7 = require("@ai-sdk/provider");
1611
- var import_provider_utils7 = require("@ai-sdk/provider-utils");
1754
+ var import_provider6 = require("@ai-sdk/provider");
1612
1755
  function convertToOpenAIResponsesMessages({
1613
1756
  prompt,
1614
1757
  systemMessageMode
@@ -1647,38 +1790,35 @@ function convertToOpenAIResponsesMessages({
1647
1790
  messages.push({
1648
1791
  role: "user",
1649
1792
  content: content.map((part, index) => {
1650
- var _a, _b, _c, _d;
1793
+ var _a, _b, _c;
1651
1794
  switch (part.type) {
1652
1795
  case "text": {
1653
1796
  return { type: "input_text", text: part.text };
1654
1797
  }
1655
- case "image": {
1656
- return {
1657
- type: "input_image",
1658
- image_url: part.image instanceof URL ? part.image.toString() : `data:${(_a = part.mimeType) != null ? _a : "image/jpeg"};base64,${(0, import_provider_utils7.convertUint8ArrayToBase64)(part.image)}`,
1659
- // OpenAI specific extension: image detail
1660
- detail: (_c = (_b = part.providerMetadata) == null ? void 0 : _b.openai) == null ? void 0 : _c.imageDetail
1661
- };
1662
- }
1663
1798
  case "file": {
1664
- if (part.data instanceof URL) {
1665
- throw new import_provider7.UnsupportedFunctionalityError({
1666
- functionality: "File URLs in user messages"
1667
- });
1668
- }
1669
- switch (part.mimeType) {
1670
- case "application/pdf": {
1671
- return {
1672
- type: "input_file",
1673
- filename: (_d = part.filename) != null ? _d : `part-${index}.pdf`,
1674
- file_data: `data:application/pdf;base64,${part.data}`
1675
- };
1676
- }
1677
- default: {
1678
- throw new import_provider7.UnsupportedFunctionalityError({
1679
- functionality: "Only PDF files are supported in user messages"
1799
+ if (part.mediaType.startsWith("image/")) {
1800
+ const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
1801
+ return {
1802
+ type: "input_image",
1803
+ image_url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${part.data}`,
1804
+ // OpenAI specific extension: image detail
1805
+ detail: (_b = (_a = part.providerOptions) == null ? void 0 : _a.openai) == null ? void 0 : _b.imageDetail
1806
+ };
1807
+ } else if (part.mediaType === "application/pdf") {
1808
+ if (part.data instanceof URL) {
1809
+ throw new import_provider6.UnsupportedFunctionalityError({
1810
+ functionality: "PDF file parts with URLs"
1680
1811
  });
1681
1812
  }
1813
+ return {
1814
+ type: "input_file",
1815
+ filename: (_c = part.filename) != null ? _c : `part-${index}.pdf`,
1816
+ file_data: `data:application/pdf;base64,${part.data}`
1817
+ };
1818
+ } else {
1819
+ throw new import_provider6.UnsupportedFunctionalityError({
1820
+ functionality: `file part media type ${part.mediaType}`
1821
+ });
1682
1822
  }
1683
1823
  }
1684
1824
  }
@@ -1747,18 +1887,17 @@ function mapOpenAIResponseFinishReason({
1747
1887
  }
1748
1888
 
1749
1889
  // src/responses/openai-responses-prepare-tools.ts
1750
- var import_provider8 = require("@ai-sdk/provider");
1890
+ var import_provider7 = require("@ai-sdk/provider");
1751
1891
  function prepareResponsesTools({
1752
- mode,
1892
+ tools,
1893
+ toolChoice,
1753
1894
  strict
1754
1895
  }) {
1755
- var _a;
1756
- const tools = ((_a = mode.tools) == null ? void 0 : _a.length) ? mode.tools : void 0;
1896
+ tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
1757
1897
  const toolWarnings = [];
1758
1898
  if (tools == null) {
1759
- return { tools: void 0, tool_choice: void 0, toolWarnings };
1899
+ return { tools: void 0, toolChoice: void 0, toolWarnings };
1760
1900
  }
1761
- const toolChoice = mode.toolChoice;
1762
1901
  const openaiTools = [];
1763
1902
  for (const tool of tools) {
1764
1903
  switch (tool.type) {
@@ -1791,37 +1930,24 @@ function prepareResponsesTools({
1791
1930
  }
1792
1931
  }
1793
1932
  if (toolChoice == null) {
1794
- return { tools: openaiTools, tool_choice: void 0, toolWarnings };
1933
+ return { tools: openaiTools, toolChoice: void 0, toolWarnings };
1795
1934
  }
1796
1935
  const type = toolChoice.type;
1797
1936
  switch (type) {
1798
1937
  case "auto":
1799
1938
  case "none":
1800
1939
  case "required":
1801
- return { tools: openaiTools, tool_choice: type, toolWarnings };
1802
- case "tool": {
1803
- if (toolChoice.toolName === "web_search_preview") {
1804
- return {
1805
- tools: openaiTools,
1806
- tool_choice: {
1807
- type: "web_search_preview"
1808
- },
1809
- toolWarnings
1810
- };
1811
- }
1940
+ return { tools: openaiTools, toolChoice: type, toolWarnings };
1941
+ case "tool":
1812
1942
  return {
1813
1943
  tools: openaiTools,
1814
- tool_choice: {
1815
- type: "function",
1816
- name: toolChoice.toolName
1817
- },
1944
+ toolChoice: toolChoice.toolName === "web_search_preview" ? { type: "web_search_preview" } : { type: "function", name: toolChoice.toolName },
1818
1945
  toolWarnings
1819
1946
  };
1820
- }
1821
1947
  default: {
1822
1948
  const _exhaustiveCheck = type;
1823
- throw new import_provider8.UnsupportedFunctionalityError({
1824
- functionality: `Unsupported tool choice type: ${_exhaustiveCheck}`
1949
+ throw new import_provider7.UnsupportedFunctionalityError({
1950
+ functionality: `tool choice type: ${_exhaustiveCheck}`
1825
1951
  });
1826
1952
  }
1827
1953
  }
@@ -1831,16 +1957,19 @@ function prepareResponsesTools({
1831
1957
  var OpenAIResponsesLanguageModel = class {
1832
1958
  constructor(modelId, config) {
1833
1959
  this.specificationVersion = "v2";
1834
- this.defaultObjectGenerationMode = "json";
1835
1960
  this.modelId = modelId;
1836
1961
  this.config = config;
1837
1962
  }
1963
+ async getSupportedUrls() {
1964
+ return {
1965
+ "image/*": [/^https?:\/\/.*$/]
1966
+ };
1967
+ }
1838
1968
  get provider() {
1839
1969
  return this.config.provider;
1840
1970
  }
1841
1971
  getArgs({
1842
- mode,
1843
- maxTokens,
1972
+ maxOutputTokens,
1844
1973
  temperature,
1845
1974
  stopSequences,
1846
1975
  topP,
@@ -1849,24 +1978,19 @@ var OpenAIResponsesLanguageModel = class {
1849
1978
  frequencyPenalty,
1850
1979
  seed,
1851
1980
  prompt,
1852
- providerMetadata,
1981
+ providerOptions,
1982
+ tools,
1983
+ toolChoice,
1853
1984
  responseFormat
1854
1985
  }) {
1855
- var _a, _b, _c;
1986
+ var _a, _b;
1856
1987
  const warnings = [];
1857
1988
  const modelConfig = getResponsesModelConfig(this.modelId);
1858
- const type = mode.type;
1859
1989
  if (topK != null) {
1860
- warnings.push({
1861
- type: "unsupported-setting",
1862
- setting: "topK"
1863
- });
1990
+ warnings.push({ type: "unsupported-setting", setting: "topK" });
1864
1991
  }
1865
1992
  if (seed != null) {
1866
- warnings.push({
1867
- type: "unsupported-setting",
1868
- setting: "seed"
1869
- });
1993
+ warnings.push({ type: "unsupported-setting", setting: "seed" });
1870
1994
  }
1871
1995
  if (presencePenalty != null) {
1872
1996
  warnings.push({
@@ -1881,19 +2005,16 @@ var OpenAIResponsesLanguageModel = class {
1881
2005
  });
1882
2006
  }
1883
2007
  if (stopSequences != null) {
1884
- warnings.push({
1885
- type: "unsupported-setting",
1886
- setting: "stopSequences"
1887
- });
2008
+ warnings.push({ type: "unsupported-setting", setting: "stopSequences" });
1888
2009
  }
1889
2010
  const { messages, warnings: messageWarnings } = convertToOpenAIResponsesMessages({
1890
2011
  prompt,
1891
2012
  systemMessageMode: modelConfig.systemMessageMode
1892
2013
  });
1893
2014
  warnings.push(...messageWarnings);
1894
- const openaiOptions = (0, import_provider_utils8.parseProviderOptions)({
2015
+ const openaiOptions = (0, import_provider_utils9.parseProviderOptions)({
1895
2016
  provider: "openai",
1896
- providerOptions: providerMetadata,
2017
+ providerOptions,
1897
2018
  schema: openaiResponsesProviderOptionsSchema
1898
2019
  });
1899
2020
  const isStrict = (_a = openaiOptions == null ? void 0 : openaiOptions.strictSchemas) != null ? _a : true;
@@ -1902,7 +2023,7 @@ var OpenAIResponsesLanguageModel = class {
1902
2023
  input: messages,
1903
2024
  temperature,
1904
2025
  top_p: topP,
1905
- max_output_tokens: maxTokens,
2026
+ max_output_tokens: maxOutputTokens,
1906
2027
  ...(responseFormat == null ? void 0 : responseFormat.type) === "json" && {
1907
2028
  text: {
1908
2029
  format: responseFormat.schema != null ? {
@@ -1947,178 +2068,145 @@ var OpenAIResponsesLanguageModel = class {
1947
2068
  });
1948
2069
  }
1949
2070
  }
1950
- switch (type) {
1951
- case "regular": {
1952
- const { tools, tool_choice, toolWarnings } = prepareResponsesTools({
1953
- mode,
1954
- strict: isStrict
1955
- // TODO support provider options on tools
1956
- });
1957
- return {
1958
- args: {
1959
- ...baseArgs,
1960
- tools,
1961
- tool_choice
1962
- },
1963
- warnings: [...warnings, ...toolWarnings]
1964
- };
1965
- }
1966
- case "object-json": {
1967
- return {
1968
- args: {
1969
- ...baseArgs,
1970
- text: {
1971
- format: mode.schema != null ? {
1972
- type: "json_schema",
1973
- strict: isStrict,
1974
- name: (_c = mode.name) != null ? _c : "response",
1975
- description: mode.description,
1976
- schema: mode.schema
1977
- } : { type: "json_object" }
1978
- }
1979
- },
1980
- warnings
1981
- };
1982
- }
1983
- case "object-tool": {
1984
- return {
1985
- args: {
1986
- ...baseArgs,
1987
- tool_choice: { type: "function", name: mode.tool.name },
1988
- tools: [
1989
- {
1990
- type: "function",
1991
- name: mode.tool.name,
1992
- description: mode.tool.description,
1993
- parameters: mode.tool.parameters,
1994
- strict: isStrict
1995
- }
1996
- ]
1997
- },
1998
- warnings
1999
- };
2000
- }
2001
- default: {
2002
- const _exhaustiveCheck = type;
2003
- throw new Error(`Unsupported type: ${_exhaustiveCheck}`);
2004
- }
2005
- }
2071
+ const {
2072
+ tools: openaiTools,
2073
+ toolChoice: openaiToolChoice,
2074
+ toolWarnings
2075
+ } = prepareResponsesTools({
2076
+ tools,
2077
+ toolChoice,
2078
+ strict: isStrict
2079
+ });
2080
+ return {
2081
+ args: {
2082
+ ...baseArgs,
2083
+ tools: openaiTools,
2084
+ tool_choice: openaiToolChoice
2085
+ },
2086
+ warnings: [...warnings, ...toolWarnings]
2087
+ };
2006
2088
  }
2007
2089
  async doGenerate(options) {
2008
- var _a, _b, _c, _d, _e;
2090
+ var _a, _b, _c, _d, _e, _f, _g, _h;
2009
2091
  const { args: body, warnings } = this.getArgs(options);
2010
2092
  const {
2011
2093
  responseHeaders,
2012
2094
  value: response,
2013
2095
  rawValue: rawResponse
2014
- } = await (0, import_provider_utils8.postJsonToApi)({
2096
+ } = await (0, import_provider_utils9.postJsonToApi)({
2015
2097
  url: this.config.url({
2016
2098
  path: "/responses",
2017
2099
  modelId: this.modelId
2018
2100
  }),
2019
- headers: (0, import_provider_utils8.combineHeaders)(this.config.headers(), options.headers),
2101
+ headers: (0, import_provider_utils9.combineHeaders)(this.config.headers(), options.headers),
2020
2102
  body,
2021
2103
  failedResponseHandler: openaiFailedResponseHandler,
2022
- successfulResponseHandler: (0, import_provider_utils8.createJsonResponseHandler)(
2023
- import_zod6.z.object({
2024
- id: import_zod6.z.string(),
2025
- created_at: import_zod6.z.number(),
2026
- model: import_zod6.z.string(),
2027
- output: import_zod6.z.array(
2028
- import_zod6.z.discriminatedUnion("type", [
2029
- import_zod6.z.object({
2030
- type: import_zod6.z.literal("message"),
2031
- role: import_zod6.z.literal("assistant"),
2032
- content: import_zod6.z.array(
2033
- import_zod6.z.object({
2034
- type: import_zod6.z.literal("output_text"),
2035
- text: import_zod6.z.string(),
2036
- annotations: import_zod6.z.array(
2037
- import_zod6.z.object({
2038
- type: import_zod6.z.literal("url_citation"),
2039
- start_index: import_zod6.z.number(),
2040
- end_index: import_zod6.z.number(),
2041
- url: import_zod6.z.string(),
2042
- title: import_zod6.z.string()
2104
+ successfulResponseHandler: (0, import_provider_utils9.createJsonResponseHandler)(
2105
+ import_zod10.z.object({
2106
+ id: import_zod10.z.string(),
2107
+ created_at: import_zod10.z.number(),
2108
+ model: import_zod10.z.string(),
2109
+ output: import_zod10.z.array(
2110
+ import_zod10.z.discriminatedUnion("type", [
2111
+ import_zod10.z.object({
2112
+ type: import_zod10.z.literal("message"),
2113
+ role: import_zod10.z.literal("assistant"),
2114
+ content: import_zod10.z.array(
2115
+ import_zod10.z.object({
2116
+ type: import_zod10.z.literal("output_text"),
2117
+ text: import_zod10.z.string(),
2118
+ annotations: import_zod10.z.array(
2119
+ import_zod10.z.object({
2120
+ type: import_zod10.z.literal("url_citation"),
2121
+ start_index: import_zod10.z.number(),
2122
+ end_index: import_zod10.z.number(),
2123
+ url: import_zod10.z.string(),
2124
+ title: import_zod10.z.string()
2043
2125
  })
2044
2126
  )
2045
2127
  })
2046
2128
  )
2047
2129
  }),
2048
- import_zod6.z.object({
2049
- type: import_zod6.z.literal("function_call"),
2050
- call_id: import_zod6.z.string(),
2051
- name: import_zod6.z.string(),
2052
- arguments: import_zod6.z.string()
2130
+ import_zod10.z.object({
2131
+ type: import_zod10.z.literal("function_call"),
2132
+ call_id: import_zod10.z.string(),
2133
+ name: import_zod10.z.string(),
2134
+ arguments: import_zod10.z.string()
2053
2135
  }),
2054
- import_zod6.z.object({
2055
- type: import_zod6.z.literal("web_search_call")
2136
+ import_zod10.z.object({
2137
+ type: import_zod10.z.literal("web_search_call")
2056
2138
  }),
2057
- import_zod6.z.object({
2058
- type: import_zod6.z.literal("computer_call")
2139
+ import_zod10.z.object({
2140
+ type: import_zod10.z.literal("computer_call")
2059
2141
  }),
2060
- import_zod6.z.object({
2061
- type: import_zod6.z.literal("reasoning")
2142
+ import_zod10.z.object({
2143
+ type: import_zod10.z.literal("reasoning")
2062
2144
  })
2063
2145
  ])
2064
2146
  ),
2065
- incomplete_details: import_zod6.z.object({ reason: import_zod6.z.string() }).nullable(),
2147
+ incomplete_details: import_zod10.z.object({ reason: import_zod10.z.string() }).nullable(),
2066
2148
  usage: usageSchema
2067
2149
  })
2068
2150
  ),
2069
2151
  abortSignal: options.abortSignal,
2070
2152
  fetch: this.config.fetch
2071
2153
  });
2072
- const outputTextElements = response.output.filter((output) => output.type === "message").flatMap((output) => output.content).filter((content) => content.type === "output_text");
2073
- const toolCalls = response.output.filter((output) => output.type === "function_call").map((output) => ({
2074
- toolCallType: "function",
2075
- toolCallId: output.call_id,
2076
- toolName: output.name,
2077
- args: output.arguments
2078
- }));
2154
+ const content = [];
2155
+ for (const part of response.output) {
2156
+ switch (part.type) {
2157
+ case "message": {
2158
+ for (const contentPart of part.content) {
2159
+ content.push({
2160
+ type: "text",
2161
+ text: contentPart.text
2162
+ });
2163
+ for (const annotation of contentPart.annotations) {
2164
+ content.push({
2165
+ type: "source",
2166
+ sourceType: "url",
2167
+ id: (_c = (_b = (_a = this.config).generateId) == null ? void 0 : _b.call(_a)) != null ? _c : (0, import_provider_utils9.generateId)(),
2168
+ url: annotation.url,
2169
+ title: annotation.title
2170
+ });
2171
+ }
2172
+ }
2173
+ break;
2174
+ }
2175
+ case "function_call": {
2176
+ content.push({
2177
+ type: "tool-call",
2178
+ toolCallType: "function",
2179
+ toolCallId: part.call_id,
2180
+ toolName: part.name,
2181
+ args: part.arguments
2182
+ });
2183
+ break;
2184
+ }
2185
+ }
2186
+ }
2079
2187
  return {
2080
- text: outputTextElements.map((content) => content.text).join("\n"),
2081
- sources: outputTextElements.flatMap(
2082
- (content) => content.annotations.map((annotation) => {
2083
- var _a2, _b2, _c2;
2084
- return {
2085
- sourceType: "url",
2086
- id: (_c2 = (_b2 = (_a2 = this.config).generateId) == null ? void 0 : _b2.call(_a2)) != null ? _c2 : (0, import_provider_utils8.generateId)(),
2087
- url: annotation.url,
2088
- title: annotation.title
2089
- };
2090
- })
2091
- ),
2188
+ content,
2092
2189
  finishReason: mapOpenAIResponseFinishReason({
2093
- finishReason: (_a = response.incomplete_details) == null ? void 0 : _a.reason,
2094
- hasToolCalls: toolCalls.length > 0
2190
+ finishReason: (_d = response.incomplete_details) == null ? void 0 : _d.reason,
2191
+ hasToolCalls: content.some((part) => part.type === "tool-call")
2095
2192
  }),
2096
- toolCalls: toolCalls.length > 0 ? toolCalls : void 0,
2097
2193
  usage: {
2098
- promptTokens: response.usage.input_tokens,
2099
- completionTokens: response.usage.output_tokens
2100
- },
2101
- rawCall: {
2102
- rawPrompt: void 0,
2103
- rawSettings: {}
2104
- },
2105
- rawResponse: {
2106
- headers: responseHeaders,
2107
- body: rawResponse
2108
- },
2109
- request: {
2110
- body: JSON.stringify(body)
2194
+ inputTokens: response.usage.input_tokens,
2195
+ outputTokens: response.usage.output_tokens
2111
2196
  },
2197
+ request: { body },
2112
2198
  response: {
2113
2199
  id: response.id,
2114
2200
  timestamp: new Date(response.created_at * 1e3),
2115
- modelId: response.model
2201
+ modelId: response.model,
2202
+ headers: responseHeaders,
2203
+ body: rawResponse
2116
2204
  },
2117
2205
  providerMetadata: {
2118
2206
  openai: {
2119
2207
  responseId: response.id,
2120
- cachedPromptTokens: (_c = (_b = response.usage.input_tokens_details) == null ? void 0 : _b.cached_tokens) != null ? _c : null,
2121
- reasoningTokens: (_e = (_d = response.usage.output_tokens_details) == null ? void 0 : _d.reasoning_tokens) != null ? _e : null
2208
+ cachedPromptTokens: (_f = (_e = response.usage.input_tokens_details) == null ? void 0 : _e.cached_tokens) != null ? _f : null,
2209
+ reasoningTokens: (_h = (_g = response.usage.output_tokens_details) == null ? void 0 : _g.reasoning_tokens) != null ? _h : null
2122
2210
  }
2123
2211
  },
2124
2212
  warnings
@@ -2126,18 +2214,18 @@ var OpenAIResponsesLanguageModel = class {
2126
2214
  }
2127
2215
  async doStream(options) {
2128
2216
  const { args: body, warnings } = this.getArgs(options);
2129
- const { responseHeaders, value: response } = await (0, import_provider_utils8.postJsonToApi)({
2217
+ const { responseHeaders, value: response } = await (0, import_provider_utils9.postJsonToApi)({
2130
2218
  url: this.config.url({
2131
2219
  path: "/responses",
2132
2220
  modelId: this.modelId
2133
2221
  }),
2134
- headers: (0, import_provider_utils8.combineHeaders)(this.config.headers(), options.headers),
2222
+ headers: (0, import_provider_utils9.combineHeaders)(this.config.headers(), options.headers),
2135
2223
  body: {
2136
2224
  ...body,
2137
2225
  stream: true
2138
2226
  },
2139
2227
  failedResponseHandler: openaiFailedResponseHandler,
2140
- successfulResponseHandler: (0, import_provider_utils8.createEventSourceResponseHandler)(
2228
+ successfulResponseHandler: (0, import_provider_utils9.createEventSourceResponseHandler)(
2141
2229
  openaiResponsesChunkSchema
2142
2230
  ),
2143
2231
  abortSignal: options.abortSignal,
@@ -2145,8 +2233,10 @@ var OpenAIResponsesLanguageModel = class {
2145
2233
  });
2146
2234
  const self = this;
2147
2235
  let finishReason = "unknown";
2148
- let promptTokens = NaN;
2149
- let completionTokens = NaN;
2236
+ const usage = {
2237
+ inputTokens: void 0,
2238
+ outputTokens: void 0
2239
+ };
2150
2240
  let cachedPromptTokens = null;
2151
2241
  let reasoningTokens = null;
2152
2242
  let responseId = null;
@@ -2155,6 +2245,9 @@ var OpenAIResponsesLanguageModel = class {
2155
2245
  return {
2156
2246
  stream: response.pipeThrough(
2157
2247
  new TransformStream({
2248
+ start(controller) {
2249
+ controller.enqueue({ type: "stream-start", warnings });
2250
+ },
2158
2251
  transform(chunk, controller) {
2159
2252
  var _a, _b, _c, _d, _e, _f, _g, _h;
2160
2253
  if (!chunk.success) {
@@ -2198,8 +2291,8 @@ var OpenAIResponsesLanguageModel = class {
2198
2291
  });
2199
2292
  } else if (isTextDeltaChunk(value)) {
2200
2293
  controller.enqueue({
2201
- type: "text-delta",
2202
- textDelta: value.delta
2294
+ type: "text",
2295
+ text: value.delta
2203
2296
  });
2204
2297
  } else if (isResponseOutputItemDoneChunk(value) && value.item.type === "function_call") {
2205
2298
  ongoingToolCalls[value.output_index] = void 0;
@@ -2216,19 +2309,17 @@ var OpenAIResponsesLanguageModel = class {
2216
2309
  finishReason: (_a = value.response.incomplete_details) == null ? void 0 : _a.reason,
2217
2310
  hasToolCalls
2218
2311
  });
2219
- promptTokens = value.response.usage.input_tokens;
2220
- completionTokens = value.response.usage.output_tokens;
2312
+ usage.inputTokens = value.response.usage.input_tokens;
2313
+ usage.outputTokens = value.response.usage.output_tokens;
2221
2314
  cachedPromptTokens = (_c = (_b = value.response.usage.input_tokens_details) == null ? void 0 : _b.cached_tokens) != null ? _c : cachedPromptTokens;
2222
2315
  reasoningTokens = (_e = (_d = value.response.usage.output_tokens_details) == null ? void 0 : _d.reasoning_tokens) != null ? _e : reasoningTokens;
2223
2316
  } else if (isResponseAnnotationAddedChunk(value)) {
2224
2317
  controller.enqueue({
2225
2318
  type: "source",
2226
- source: {
2227
- sourceType: "url",
2228
- id: (_h = (_g = (_f = self.config).generateId) == null ? void 0 : _g.call(_f)) != null ? _h : (0, import_provider_utils8.generateId)(),
2229
- url: value.annotation.url,
2230
- title: value.annotation.title
2231
- }
2319
+ sourceType: "url",
2320
+ id: (_h = (_g = (_f = self.config).generateId) == null ? void 0 : _g.call(_f)) != null ? _h : (0, import_provider_utils9.generateId)(),
2321
+ url: value.annotation.url,
2322
+ title: value.annotation.title
2232
2323
  });
2233
2324
  }
2234
2325
  },
@@ -2236,7 +2327,7 @@ var OpenAIResponsesLanguageModel = class {
2236
2327
  controller.enqueue({
2237
2328
  type: "finish",
2238
2329
  finishReason,
2239
- usage: { promptTokens, completionTokens },
2330
+ usage,
2240
2331
  ...(cachedPromptTokens != null || reasoningTokens != null) && {
2241
2332
  providerMetadata: {
2242
2333
  openai: {
@@ -2250,89 +2341,84 @@ var OpenAIResponsesLanguageModel = class {
2250
2341
  }
2251
2342
  })
2252
2343
  ),
2253
- rawCall: {
2254
- rawPrompt: void 0,
2255
- rawSettings: {}
2256
- },
2257
- rawResponse: { headers: responseHeaders },
2258
- request: { body: JSON.stringify(body) },
2259
- warnings
2344
+ request: { body },
2345
+ response: { headers: responseHeaders }
2260
2346
  };
2261
2347
  }
2262
2348
  };
2263
- var usageSchema = import_zod6.z.object({
2264
- input_tokens: import_zod6.z.number(),
2265
- input_tokens_details: import_zod6.z.object({ cached_tokens: import_zod6.z.number().nullish() }).nullish(),
2266
- output_tokens: import_zod6.z.number(),
2267
- output_tokens_details: import_zod6.z.object({ reasoning_tokens: import_zod6.z.number().nullish() }).nullish()
2349
+ var usageSchema = import_zod10.z.object({
2350
+ input_tokens: import_zod10.z.number(),
2351
+ input_tokens_details: import_zod10.z.object({ cached_tokens: import_zod10.z.number().nullish() }).nullish(),
2352
+ output_tokens: import_zod10.z.number(),
2353
+ output_tokens_details: import_zod10.z.object({ reasoning_tokens: import_zod10.z.number().nullish() }).nullish()
2268
2354
  });
2269
- var textDeltaChunkSchema = import_zod6.z.object({
2270
- type: import_zod6.z.literal("response.output_text.delta"),
2271
- delta: import_zod6.z.string()
2355
+ var textDeltaChunkSchema = import_zod10.z.object({
2356
+ type: import_zod10.z.literal("response.output_text.delta"),
2357
+ delta: import_zod10.z.string()
2272
2358
  });
2273
- var responseFinishedChunkSchema = import_zod6.z.object({
2274
- type: import_zod6.z.enum(["response.completed", "response.incomplete"]),
2275
- response: import_zod6.z.object({
2276
- incomplete_details: import_zod6.z.object({ reason: import_zod6.z.string() }).nullish(),
2359
+ var responseFinishedChunkSchema = import_zod10.z.object({
2360
+ type: import_zod10.z.enum(["response.completed", "response.incomplete"]),
2361
+ response: import_zod10.z.object({
2362
+ incomplete_details: import_zod10.z.object({ reason: import_zod10.z.string() }).nullish(),
2277
2363
  usage: usageSchema
2278
2364
  })
2279
2365
  });
2280
- var responseCreatedChunkSchema = import_zod6.z.object({
2281
- type: import_zod6.z.literal("response.created"),
2282
- response: import_zod6.z.object({
2283
- id: import_zod6.z.string(),
2284
- created_at: import_zod6.z.number(),
2285
- model: import_zod6.z.string()
2366
+ var responseCreatedChunkSchema = import_zod10.z.object({
2367
+ type: import_zod10.z.literal("response.created"),
2368
+ response: import_zod10.z.object({
2369
+ id: import_zod10.z.string(),
2370
+ created_at: import_zod10.z.number(),
2371
+ model: import_zod10.z.string()
2286
2372
  })
2287
2373
  });
2288
- var responseOutputItemDoneSchema = import_zod6.z.object({
2289
- type: import_zod6.z.literal("response.output_item.done"),
2290
- output_index: import_zod6.z.number(),
2291
- item: import_zod6.z.discriminatedUnion("type", [
2292
- import_zod6.z.object({
2293
- type: import_zod6.z.literal("message")
2374
+ var responseOutputItemDoneSchema = import_zod10.z.object({
2375
+ type: import_zod10.z.literal("response.output_item.done"),
2376
+ output_index: import_zod10.z.number(),
2377
+ item: import_zod10.z.discriminatedUnion("type", [
2378
+ import_zod10.z.object({
2379
+ type: import_zod10.z.literal("message")
2294
2380
  }),
2295
- import_zod6.z.object({
2296
- type: import_zod6.z.literal("function_call"),
2297
- id: import_zod6.z.string(),
2298
- call_id: import_zod6.z.string(),
2299
- name: import_zod6.z.string(),
2300
- arguments: import_zod6.z.string(),
2301
- status: import_zod6.z.literal("completed")
2381
+ import_zod10.z.object({
2382
+ type: import_zod10.z.literal("function_call"),
2383
+ id: import_zod10.z.string(),
2384
+ call_id: import_zod10.z.string(),
2385
+ name: import_zod10.z.string(),
2386
+ arguments: import_zod10.z.string(),
2387
+ status: import_zod10.z.literal("completed")
2302
2388
  })
2303
2389
  ])
2304
2390
  });
2305
- var responseFunctionCallArgumentsDeltaSchema = import_zod6.z.object({
2306
- type: import_zod6.z.literal("response.function_call_arguments.delta"),
2307
- item_id: import_zod6.z.string(),
2308
- output_index: import_zod6.z.number(),
2309
- delta: import_zod6.z.string()
2391
+ var responseFunctionCallArgumentsDeltaSchema = import_zod10.z.object({
2392
+ type: import_zod10.z.literal("response.function_call_arguments.delta"),
2393
+ item_id: import_zod10.z.string(),
2394
+ output_index: import_zod10.z.number(),
2395
+ delta: import_zod10.z.string()
2310
2396
  });
2311
- var responseOutputItemAddedSchema = import_zod6.z.object({
2312
- type: import_zod6.z.literal("response.output_item.added"),
2313
- output_index: import_zod6.z.number(),
2314
- item: import_zod6.z.discriminatedUnion("type", [
2315
- import_zod6.z.object({
2316
- type: import_zod6.z.literal("message")
2397
+ var responseOutputItemAddedSchema = import_zod10.z.object({
2398
+ type: import_zod10.z.literal("response.output_item.added"),
2399
+ output_index: import_zod10.z.number(),
2400
+ item: import_zod10.z.discriminatedUnion("type", [
2401
+ import_zod10.z.object({
2402
+ type: import_zod10.z.literal("message")
2317
2403
  }),
2318
- import_zod6.z.object({
2319
- type: import_zod6.z.literal("function_call"),
2320
- id: import_zod6.z.string(),
2321
- call_id: import_zod6.z.string(),
2322
- name: import_zod6.z.string(),
2323
- arguments: import_zod6.z.string()
2404
+ import_zod10.z.object({
2405
+ type: import_zod10.z.literal("function_call"),
2406
+ id: import_zod10.z.string(),
2407
+ call_id: import_zod10.z.string(),
2408
+ name: import_zod10.z.string(),
2409
+ arguments: import_zod10.z.string()
2324
2410
  })
2325
2411
  ])
2326
2412
  });
2327
- var responseAnnotationAddedSchema = import_zod6.z.object({
2328
- type: import_zod6.z.literal("response.output_text.annotation.added"),
2329
- annotation: import_zod6.z.object({
2330
- type: import_zod6.z.literal("url_citation"),
2331
- url: import_zod6.z.string(),
2332
- title: import_zod6.z.string()
2413
+ var responseAnnotationAddedSchema = import_zod10.z.object({
2414
+ type: import_zod10.z.literal("response.output_text.annotation.added"),
2415
+ annotation: import_zod10.z.object({
2416
+ type: import_zod10.z.literal("url_citation"),
2417
+ url: import_zod10.z.string(),
2418
+ title: import_zod10.z.string()
2333
2419
  })
2334
2420
  });
2335
- var openaiResponsesChunkSchema = import_zod6.z.union([
2421
+ var openaiResponsesChunkSchema = import_zod10.z.union([
2336
2422
  textDeltaChunkSchema,
2337
2423
  responseFinishedChunkSchema,
2338
2424
  responseCreatedChunkSchema,
@@ -2340,7 +2426,7 @@ var openaiResponsesChunkSchema = import_zod6.z.union([
2340
2426
  responseFunctionCallArgumentsDeltaSchema,
2341
2427
  responseOutputItemAddedSchema,
2342
2428
  responseAnnotationAddedSchema,
2343
- import_zod6.z.object({ type: import_zod6.z.string() }).passthrough()
2429
+ import_zod10.z.object({ type: import_zod10.z.string() }).passthrough()
2344
2430
  // fallback for unknown chunks
2345
2431
  ]);
2346
2432
  function isTextDeltaChunk(chunk) {
@@ -2385,15 +2471,15 @@ function getResponsesModelConfig(modelId) {
2385
2471
  requiredAutoTruncation: false
2386
2472
  };
2387
2473
  }
2388
- var openaiResponsesProviderOptionsSchema = import_zod6.z.object({
2389
- metadata: import_zod6.z.any().nullish(),
2390
- parallelToolCalls: import_zod6.z.boolean().nullish(),
2391
- previousResponseId: import_zod6.z.string().nullish(),
2392
- store: import_zod6.z.boolean().nullish(),
2393
- user: import_zod6.z.string().nullish(),
2394
- reasoningEffort: import_zod6.z.string().nullish(),
2395
- strictSchemas: import_zod6.z.boolean().nullish(),
2396
- instructions: import_zod6.z.string().nullish()
2474
+ var openaiResponsesProviderOptionsSchema = import_zod10.z.object({
2475
+ metadata: import_zod10.z.any().nullish(),
2476
+ parallelToolCalls: import_zod10.z.boolean().nullish(),
2477
+ previousResponseId: import_zod10.z.string().nullish(),
2478
+ store: import_zod10.z.boolean().nullish(),
2479
+ user: import_zod10.z.string().nullish(),
2480
+ reasoningEffort: import_zod10.z.string().nullish(),
2481
+ strictSchemas: import_zod10.z.boolean().nullish(),
2482
+ instructions: import_zod10.z.string().nullish()
2397
2483
  });
2398
2484
  // Annotate the CommonJS export names for ESM import in node:
2399
2485
  0 && (module.exports = {
@@ -2402,6 +2488,10 @@ var openaiResponsesProviderOptionsSchema = import_zod6.z.object({
2402
2488
  OpenAIEmbeddingModel,
2403
2489
  OpenAIImageModel,
2404
2490
  OpenAIResponsesLanguageModel,
2405
- modelMaxImagesPerCall
2491
+ OpenAISpeechModel,
2492
+ OpenAITranscriptionModel,
2493
+ modelMaxImagesPerCall,
2494
+ openaiEmbeddingProviderOptions,
2495
+ openaiProviderOptions
2406
2496
  });
2407
2497
  //# sourceMappingURL=index.js.map