@ai-sdk/openai 2.0.0-canary.5 → 2.0.0-canary.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -6,8 +6,7 @@ import {
6
6
 
7
7
  // src/openai-chat-language-model.ts
8
8
  import {
9
- InvalidResponseDataError,
10
- UnsupportedFunctionalityError as UnsupportedFunctionalityError3
9
+ InvalidResponseDataError
11
10
  } from "@ai-sdk/provider";
12
11
  import {
13
12
  combineHeaders,
@@ -15,17 +14,18 @@ import {
15
14
  createJsonResponseHandler,
16
15
  generateId,
17
16
  isParsableJson,
18
- postJsonToApi
17
+ postJsonToApi,
18
+ parseProviderOptions
19
19
  } from "@ai-sdk/provider-utils";
20
- import { z as z2 } from "zod";
20
+ import { z as z3 } from "zod";
21
21
 
22
22
  // src/convert-to-openai-chat-messages.ts
23
23
  import {
24
24
  UnsupportedFunctionalityError
25
25
  } from "@ai-sdk/provider";
26
+ import { convertToBase64 } from "@ai-sdk/provider-utils";
26
27
  function convertToOpenAIChatMessages({
27
28
  prompt,
28
- useLegacyFunctionCalling = false,
29
29
  systemMessageMode = "system"
30
30
  }) {
31
31
  const messages = [];
@@ -77,7 +77,7 @@ function convertToOpenAIChatMessages({
77
77
  return {
78
78
  type: "image_url",
79
79
  image_url: {
80
- url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${part.data}`,
80
+ url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${convertToBase64(part.data)}`,
81
81
  // OpenAI specific extension: image detail
82
82
  detail: (_b = (_a = part.providerOptions) == null ? void 0 : _a.openai) == null ? void 0 : _b.imageDetail
83
83
  }
@@ -92,14 +92,20 @@ function convertToOpenAIChatMessages({
92
92
  case "audio/wav": {
93
93
  return {
94
94
  type: "input_audio",
95
- input_audio: { data: part.data, format: "wav" }
95
+ input_audio: {
96
+ data: convertToBase64(part.data),
97
+ format: "wav"
98
+ }
96
99
  };
97
100
  }
98
101
  case "audio/mp3":
99
102
  case "audio/mpeg": {
100
103
  return {
101
104
  type: "input_audio",
102
- input_audio: { data: part.data, format: "mp3" }
105
+ input_audio: {
106
+ data: convertToBase64(part.data),
107
+ format: "mp3"
108
+ }
103
109
  };
104
110
  }
105
111
  default: {
@@ -154,41 +160,20 @@ function convertToOpenAIChatMessages({
154
160
  }
155
161
  }
156
162
  }
157
- if (useLegacyFunctionCalling) {
158
- if (toolCalls.length > 1) {
159
- throw new UnsupportedFunctionalityError({
160
- functionality: "useLegacyFunctionCalling with multiple tool calls in one message"
161
- });
162
- }
163
- messages.push({
164
- role: "assistant",
165
- content: text,
166
- function_call: toolCalls.length > 0 ? toolCalls[0].function : void 0
167
- });
168
- } else {
169
- messages.push({
170
- role: "assistant",
171
- content: text,
172
- tool_calls: toolCalls.length > 0 ? toolCalls : void 0
173
- });
174
- }
163
+ messages.push({
164
+ role: "assistant",
165
+ content: text,
166
+ tool_calls: toolCalls.length > 0 ? toolCalls : void 0
167
+ });
175
168
  break;
176
169
  }
177
170
  case "tool": {
178
171
  for (const toolResponse of content) {
179
- if (useLegacyFunctionCalling) {
180
- messages.push({
181
- role: "function",
182
- name: toolResponse.toolName,
183
- content: JSON.stringify(toolResponse.result)
184
- });
185
- } else {
186
- messages.push({
187
- role: "tool",
188
- tool_call_id: toolResponse.toolCallId,
189
- content: JSON.stringify(toolResponse.result)
190
- });
191
- }
172
+ messages.push({
173
+ role: "tool",
174
+ tool_call_id: toolResponse.toolCallId,
175
+ content: JSON.stringify(toolResponse.result)
176
+ });
192
177
  }
193
178
  break;
194
179
  }
@@ -231,18 +216,69 @@ function mapOpenAIFinishReason(finishReason) {
231
216
  }
232
217
  }
233
218
 
234
- // src/openai-error.ts
219
+ // src/openai-chat-options.ts
235
220
  import { z } from "zod";
221
+ var openaiProviderOptions = z.object({
222
+ /**
223
+ * Modify the likelihood of specified tokens appearing in the completion.
224
+ *
225
+ * Accepts a JSON object that maps tokens (specified by their token ID in
226
+ * the GPT tokenizer) to an associated bias value from -100 to 100.
227
+ */
228
+ logitBias: z.record(z.coerce.number(), z.number()).optional(),
229
+ /**
230
+ * Return the log probabilities of the tokens.
231
+ *
232
+ * Setting to true will return the log probabilities of the tokens that
233
+ * were generated.
234
+ *
235
+ * Setting to a number will return the log probabilities of the top n
236
+ * tokens that were generated.
237
+ */
238
+ logprobs: z.union([z.boolean(), z.number()]).optional(),
239
+ /**
240
+ * Whether to enable parallel function calling during tool use. Default to true.
241
+ */
242
+ parallelToolCalls: z.boolean().optional(),
243
+ /**
244
+ * A unique identifier representing your end-user, which can help OpenAI to
245
+ * monitor and detect abuse.
246
+ */
247
+ user: z.string().optional(),
248
+ /**
249
+ * Reasoning effort for reasoning models. Defaults to `medium`.
250
+ */
251
+ reasoningEffort: z.enum(["low", "medium", "high"]).optional(),
252
+ /**
253
+ * Maximum number of completion tokens to generate. Useful for reasoning models.
254
+ */
255
+ maxCompletionTokens: z.number().optional(),
256
+ /**
257
+ * Whether to enable persistence in responses API.
258
+ */
259
+ store: z.boolean().optional(),
260
+ /**
261
+ * Metadata to associate with the request.
262
+ */
263
+ metadata: z.record(z.string()).optional(),
264
+ /**
265
+ * Parameters for prediction mode.
266
+ */
267
+ prediction: z.record(z.any()).optional()
268
+ });
269
+
270
+ // src/openai-error.ts
271
+ import { z as z2 } from "zod";
236
272
  import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
237
- var openaiErrorDataSchema = z.object({
238
- error: z.object({
239
- message: z.string(),
273
+ var openaiErrorDataSchema = z2.object({
274
+ error: z2.object({
275
+ message: z2.string(),
240
276
  // The additional information below is handled loosely to support
241
277
  // OpenAI-compatible providers that have slightly different error
242
278
  // responses:
243
- type: z.string().nullish(),
244
- param: z.any().nullish(),
245
- code: z.union([z.string(), z.number()]).nullish()
279
+ type: z2.string().nullish(),
280
+ param: z2.any().nullish(),
281
+ code: z2.union([z2.string(), z2.number()]).nullish()
246
282
  })
247
283
  });
248
284
  var openaiFailedResponseHandler = createJsonErrorResponseHandler({
@@ -270,7 +306,6 @@ import {
270
306
  function prepareTools({
271
307
  tools,
272
308
  toolChoice,
273
- useLegacyFunctionCalling = false,
274
309
  structuredOutputs
275
310
  }) {
276
311
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
@@ -278,48 +313,6 @@ function prepareTools({
278
313
  if (tools == null) {
279
314
  return { tools: void 0, toolChoice: void 0, toolWarnings };
280
315
  }
281
- if (useLegacyFunctionCalling) {
282
- const openaiFunctions = [];
283
- for (const tool of tools) {
284
- if (tool.type === "provider-defined") {
285
- toolWarnings.push({ type: "unsupported-tool", tool });
286
- } else {
287
- openaiFunctions.push({
288
- name: tool.name,
289
- description: tool.description,
290
- parameters: tool.parameters
291
- });
292
- }
293
- }
294
- if (toolChoice == null) {
295
- return {
296
- functions: openaiFunctions,
297
- function_call: void 0,
298
- toolWarnings
299
- };
300
- }
301
- const type2 = toolChoice.type;
302
- switch (type2) {
303
- case "auto":
304
- case "none":
305
- case void 0:
306
- return {
307
- functions: openaiFunctions,
308
- function_call: void 0,
309
- toolWarnings
310
- };
311
- case "required":
312
- throw new UnsupportedFunctionalityError2({
313
- functionality: "useLegacyFunctionCalling and toolChoice: required"
314
- });
315
- default:
316
- return {
317
- functions: openaiFunctions,
318
- function_call: { name: toolChoice.toolName },
319
- toolWarnings
320
- };
321
- }
322
- }
323
316
  const openaiTools2 = [];
324
317
  for (const tool of tools) {
325
318
  if (tool.type === "provider-defined") {
@@ -391,7 +384,7 @@ var OpenAIChatLanguageModel = class {
391
384
  }
392
385
  getArgs({
393
386
  prompt,
394
- maxTokens,
387
+ maxOutputTokens,
395
388
  temperature,
396
389
  topP,
397
390
  topK,
@@ -404,8 +397,13 @@ var OpenAIChatLanguageModel = class {
404
397
  toolChoice,
405
398
  providerOptions
406
399
  }) {
407
- var _a, _b, _c, _d, _e, _f, _g;
400
+ var _a, _b;
408
401
  const warnings = [];
402
+ const openaiOptions = (_a = parseProviderOptions({
403
+ provider: "openai",
404
+ providerOptions,
405
+ schema: openaiProviderOptions
406
+ })) != null ? _a : {};
409
407
  if (topK != null) {
410
408
  warnings.push({
411
409
  type: "unsupported-setting",
@@ -419,21 +417,9 @@ var OpenAIChatLanguageModel = class {
419
417
  details: "JSON response format schema is only supported with structuredOutputs"
420
418
  });
421
419
  }
422
- const useLegacyFunctionCalling = this.settings.useLegacyFunctionCalling;
423
- if (useLegacyFunctionCalling && this.settings.parallelToolCalls === true) {
424
- throw new UnsupportedFunctionalityError3({
425
- functionality: "useLegacyFunctionCalling with parallelToolCalls"
426
- });
427
- }
428
- if (useLegacyFunctionCalling && this.supportsStructuredOutputs) {
429
- throw new UnsupportedFunctionalityError3({
430
- functionality: "structuredOutputs with useLegacyFunctionCalling"
431
- });
432
- }
433
420
  const { messages, warnings: messageWarnings } = convertToOpenAIChatMessages(
434
421
  {
435
422
  prompt,
436
- useLegacyFunctionCalling,
437
423
  systemMessageMode: getSystemMessageMode(this.modelId)
438
424
  }
439
425
  );
@@ -442,13 +428,13 @@ var OpenAIChatLanguageModel = class {
442
428
  // model id:
443
429
  model: this.modelId,
444
430
  // model specific settings:
445
- logit_bias: this.settings.logitBias,
446
- logprobs: this.settings.logprobs === true || typeof this.settings.logprobs === "number" ? true : void 0,
447
- top_logprobs: typeof this.settings.logprobs === "number" ? this.settings.logprobs : typeof this.settings.logprobs === "boolean" ? this.settings.logprobs ? 0 : void 0 : void 0,
448
- user: this.settings.user,
449
- parallel_tool_calls: this.settings.parallelToolCalls,
431
+ logit_bias: openaiOptions.logitBias,
432
+ logprobs: openaiOptions.logprobs === true || typeof openaiOptions.logprobs === "number" ? true : void 0,
433
+ top_logprobs: typeof openaiOptions.logprobs === "number" ? openaiOptions.logprobs : typeof openaiOptions.logprobs === "boolean" ? openaiOptions.logprobs ? 0 : void 0 : void 0,
434
+ user: openaiOptions.user,
435
+ parallel_tool_calls: openaiOptions.parallelToolCalls,
450
436
  // standardized settings:
451
- max_tokens: maxTokens,
437
+ max_tokens: maxOutputTokens,
452
438
  temperature,
453
439
  top_p: topP,
454
440
  frequency_penalty: frequencyPenalty,
@@ -459,19 +445,19 @@ var OpenAIChatLanguageModel = class {
459
445
  json_schema: {
460
446
  schema: responseFormat.schema,
461
447
  strict: true,
462
- name: (_a = responseFormat.name) != null ? _a : "response",
448
+ name: (_b = responseFormat.name) != null ? _b : "response",
463
449
  description: responseFormat.description
464
450
  }
465
451
  } : { type: "json_object" } : void 0,
466
452
  stop: stopSequences,
467
453
  seed,
468
454
  // openai specific settings:
469
- // TODO remove in next major version; we auto-map maxTokens now
470
- max_completion_tokens: (_b = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _b.maxCompletionTokens,
471
- store: (_c = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _c.store,
472
- metadata: (_d = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _d.metadata,
473
- prediction: (_e = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _e.prediction,
474
- reasoning_effort: (_g = (_f = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _f.reasoningEffort) != null ? _g : this.settings.reasoningEffort,
455
+ // TODO remove in next major version; we auto-map maxOutputTokens now
456
+ max_completion_tokens: openaiOptions.maxCompletionTokens,
457
+ store: openaiOptions.store,
458
+ metadata: openaiOptions.metadata,
459
+ prediction: openaiOptions.prediction,
460
+ reasoning_effort: openaiOptions.reasoningEffort,
475
461
  // messages:
476
462
  messages
477
463
  };
@@ -535,32 +521,36 @@ var OpenAIChatLanguageModel = class {
535
521
  }
536
522
  baseArgs.max_tokens = void 0;
537
523
  }
524
+ } else if (this.modelId.startsWith("gpt-4o-search-preview")) {
525
+ if (baseArgs.temperature != null) {
526
+ baseArgs.temperature = void 0;
527
+ warnings.push({
528
+ type: "unsupported-setting",
529
+ setting: "temperature",
530
+ details: "temperature is not supported for the gpt-4o-search-preview model and has been removed."
531
+ });
532
+ }
538
533
  }
539
534
  const {
540
535
  tools: openaiTools2,
541
536
  toolChoice: openaiToolChoice,
542
- functions,
543
- function_call,
544
537
  toolWarnings
545
538
  } = prepareTools({
546
539
  tools,
547
540
  toolChoice,
548
- useLegacyFunctionCalling,
549
541
  structuredOutputs: this.supportsStructuredOutputs
550
542
  });
551
543
  return {
552
544
  args: {
553
545
  ...baseArgs,
554
546
  tools: openaiTools2,
555
- tool_choice: openaiToolChoice,
556
- functions,
557
- function_call
547
+ tool_choice: openaiToolChoice
558
548
  },
559
549
  warnings: [...warnings, ...toolWarnings]
560
550
  };
561
551
  }
562
552
  async doGenerate(options) {
563
- var _a, _b, _c, _d, _e, _f, _g, _h;
553
+ var _a, _b, _c, _d, _e, _f, _g;
564
554
  const { args: body, warnings } = this.getArgs(options);
565
555
  const {
566
556
  responseHeaders,
@@ -598,17 +588,11 @@ var OpenAIChatLanguageModel = class {
598
588
  providerMetadata.openai.cachedPromptTokens = promptTokenDetails == null ? void 0 : promptTokenDetails.cached_tokens;
599
589
  }
600
590
  return {
601
- text: (_c = choice.message.content) != null ? _c : void 0,
602
- toolCalls: this.settings.useLegacyFunctionCalling && choice.message.function_call ? [
603
- {
604
- toolCallType: "function",
605
- toolCallId: generateId(),
606
- toolName: choice.message.function_call.name,
607
- args: choice.message.function_call.arguments
608
- }
609
- ] : (_d = choice.message.tool_calls) == null ? void 0 : _d.map((toolCall) => {
591
+ text: choice.message.content != null ? { type: "text", text: choice.message.content } : void 0,
592
+ toolCalls: (_c = choice.message.tool_calls) == null ? void 0 : _c.map((toolCall) => {
610
593
  var _a2;
611
594
  return {
595
+ type: "tool-call",
612
596
  toolCallType: "function",
613
597
  toolCallId: (_a2 = toolCall.id) != null ? _a2 : generateId(),
614
598
  toolName: toolCall.function.name,
@@ -617,8 +601,8 @@ var OpenAIChatLanguageModel = class {
617
601
  }),
618
602
  finishReason: mapOpenAIFinishReason(choice.finish_reason),
619
603
  usage: {
620
- promptTokens: (_f = (_e = response.usage) == null ? void 0 : _e.prompt_tokens) != null ? _f : NaN,
621
- completionTokens: (_h = (_g = response.usage) == null ? void 0 : _g.completion_tokens) != null ? _h : NaN
604
+ inputTokens: (_e = (_d = response.usage) == null ? void 0 : _d.prompt_tokens) != null ? _e : void 0,
605
+ outputTokens: (_g = (_f = response.usage) == null ? void 0 : _f.completion_tokens) != null ? _g : void 0
622
606
  },
623
607
  request: { body },
624
608
  response: {
@@ -632,48 +616,6 @@ var OpenAIChatLanguageModel = class {
632
616
  };
633
617
  }
634
618
  async doStream(options) {
635
- if (this.settings.simulateStreaming) {
636
- const result = await this.doGenerate(options);
637
- const simulatedStream = new ReadableStream({
638
- start(controller) {
639
- controller.enqueue({ type: "response-metadata", ...result.response });
640
- if (result.text) {
641
- controller.enqueue({
642
- type: "text-delta",
643
- textDelta: result.text
644
- });
645
- }
646
- if (result.toolCalls) {
647
- for (const toolCall of result.toolCalls) {
648
- controller.enqueue({
649
- type: "tool-call-delta",
650
- toolCallType: "function",
651
- toolCallId: toolCall.toolCallId,
652
- toolName: toolCall.toolName,
653
- argsTextDelta: toolCall.args
654
- });
655
- controller.enqueue({
656
- type: "tool-call",
657
- ...toolCall
658
- });
659
- }
660
- }
661
- controller.enqueue({
662
- type: "finish",
663
- finishReason: result.finishReason,
664
- usage: result.usage,
665
- logprobs: result.logprobs,
666
- providerMetadata: result.providerMetadata
667
- });
668
- controller.close();
669
- }
670
- });
671
- return {
672
- stream: simulatedStream,
673
- response: result.response,
674
- warnings: result.warnings
675
- };
676
- }
677
619
  const { args, warnings } = this.getArgs(options);
678
620
  const body = {
679
621
  ...args,
@@ -698,13 +640,12 @@ var OpenAIChatLanguageModel = class {
698
640
  const { messages: rawPrompt, ...rawSettings } = args;
699
641
  const toolCalls = [];
700
642
  let finishReason = "unknown";
701
- let usage = {
702
- promptTokens: void 0,
703
- completionTokens: void 0
643
+ const usage = {
644
+ inputTokens: void 0,
645
+ outputTokens: void 0
704
646
  };
705
647
  let logprobs;
706
648
  let isFirstChunk = true;
707
- const { useLegacyFunctionCalling } = this.settings;
708
649
  const providerMetadata = { openai: {} };
709
650
  return {
710
651
  stream: response.pipeThrough(
@@ -736,10 +677,8 @@ var OpenAIChatLanguageModel = class {
736
677
  prompt_tokens_details,
737
678
  completion_tokens_details
738
679
  } = value.usage;
739
- usage = {
740
- promptTokens: prompt_tokens != null ? prompt_tokens : void 0,
741
- completionTokens: completion_tokens != null ? completion_tokens : void 0
742
- };
680
+ usage.inputTokens = prompt_tokens != null ? prompt_tokens : void 0;
681
+ usage.outputTokens = completion_tokens != null ? completion_tokens : void 0;
743
682
  if ((completion_tokens_details == null ? void 0 : completion_tokens_details.reasoning_tokens) != null) {
744
683
  providerMetadata.openai.reasoningTokens = completion_tokens_details == null ? void 0 : completion_tokens_details.reasoning_tokens;
745
684
  }
@@ -763,8 +702,8 @@ var OpenAIChatLanguageModel = class {
763
702
  const delta = choice.delta;
764
703
  if (delta.content != null) {
765
704
  controller.enqueue({
766
- type: "text-delta",
767
- textDelta: delta.content
705
+ type: "text",
706
+ text: delta.content
768
707
  });
769
708
  }
770
709
  const mappedLogprobs = mapOpenAIChatLogProbsOutput(
@@ -774,16 +713,8 @@ var OpenAIChatLanguageModel = class {
774
713
  if (logprobs === void 0) logprobs = [];
775
714
  logprobs.push(...mappedLogprobs);
776
715
  }
777
- const mappedToolCalls = useLegacyFunctionCalling && delta.function_call != null ? [
778
- {
779
- type: "function",
780
- id: generateId(),
781
- function: delta.function_call,
782
- index: 0
783
- }
784
- ] : delta.tool_calls;
785
- if (mappedToolCalls != null) {
786
- for (const toolCallDelta of mappedToolCalls) {
716
+ if (delta.tool_calls != null) {
717
+ for (const toolCallDelta of delta.tool_calls) {
787
718
  const index = toolCallDelta.index;
788
719
  if (toolCalls[index] == null) {
789
720
  if (toolCallDelta.type !== "function") {
@@ -865,15 +796,11 @@ var OpenAIChatLanguageModel = class {
865
796
  }
866
797
  },
867
798
  flush(controller) {
868
- var _a, _b;
869
799
  controller.enqueue({
870
800
  type: "finish",
871
801
  finishReason,
872
802
  logprobs,
873
- usage: {
874
- promptTokens: (_a = usage.promptTokens) != null ? _a : NaN,
875
- completionTokens: (_b = usage.completionTokens) != null ? _b : NaN
876
- },
803
+ usage,
877
804
  ...providerMetadata != null ? { providerMetadata } : {}
878
805
  });
879
806
  }
@@ -885,104 +812,96 @@ var OpenAIChatLanguageModel = class {
885
812
  };
886
813
  }
887
814
  };
888
- var openaiTokenUsageSchema = z2.object({
889
- prompt_tokens: z2.number().nullish(),
890
- completion_tokens: z2.number().nullish(),
891
- prompt_tokens_details: z2.object({
892
- cached_tokens: z2.number().nullish()
815
+ var openaiTokenUsageSchema = z3.object({
816
+ prompt_tokens: z3.number().nullish(),
817
+ completion_tokens: z3.number().nullish(),
818
+ prompt_tokens_details: z3.object({
819
+ cached_tokens: z3.number().nullish()
893
820
  }).nullish(),
894
- completion_tokens_details: z2.object({
895
- reasoning_tokens: z2.number().nullish(),
896
- accepted_prediction_tokens: z2.number().nullish(),
897
- rejected_prediction_tokens: z2.number().nullish()
821
+ completion_tokens_details: z3.object({
822
+ reasoning_tokens: z3.number().nullish(),
823
+ accepted_prediction_tokens: z3.number().nullish(),
824
+ rejected_prediction_tokens: z3.number().nullish()
898
825
  }).nullish()
899
826
  }).nullish();
900
- var openaiChatResponseSchema = z2.object({
901
- id: z2.string().nullish(),
902
- created: z2.number().nullish(),
903
- model: z2.string().nullish(),
904
- choices: z2.array(
905
- z2.object({
906
- message: z2.object({
907
- role: z2.literal("assistant").nullish(),
908
- content: z2.string().nullish(),
909
- function_call: z2.object({
910
- arguments: z2.string(),
911
- name: z2.string()
912
- }).nullish(),
913
- tool_calls: z2.array(
914
- z2.object({
915
- id: z2.string().nullish(),
916
- type: z2.literal("function"),
917
- function: z2.object({
918
- name: z2.string(),
919
- arguments: z2.string()
827
+ var openaiChatResponseSchema = z3.object({
828
+ id: z3.string().nullish(),
829
+ created: z3.number().nullish(),
830
+ model: z3.string().nullish(),
831
+ choices: z3.array(
832
+ z3.object({
833
+ message: z3.object({
834
+ role: z3.literal("assistant").nullish(),
835
+ content: z3.string().nullish(),
836
+ tool_calls: z3.array(
837
+ z3.object({
838
+ id: z3.string().nullish(),
839
+ type: z3.literal("function"),
840
+ function: z3.object({
841
+ name: z3.string(),
842
+ arguments: z3.string()
920
843
  })
921
844
  })
922
845
  ).nullish()
923
846
  }),
924
- index: z2.number(),
925
- logprobs: z2.object({
926
- content: z2.array(
927
- z2.object({
928
- token: z2.string(),
929
- logprob: z2.number(),
930
- top_logprobs: z2.array(
931
- z2.object({
932
- token: z2.string(),
933
- logprob: z2.number()
847
+ index: z3.number(),
848
+ logprobs: z3.object({
849
+ content: z3.array(
850
+ z3.object({
851
+ token: z3.string(),
852
+ logprob: z3.number(),
853
+ top_logprobs: z3.array(
854
+ z3.object({
855
+ token: z3.string(),
856
+ logprob: z3.number()
934
857
  })
935
858
  )
936
859
  })
937
860
  ).nullable()
938
861
  }).nullish(),
939
- finish_reason: z2.string().nullish()
862
+ finish_reason: z3.string().nullish()
940
863
  })
941
864
  ),
942
865
  usage: openaiTokenUsageSchema
943
866
  });
944
- var openaiChatChunkSchema = z2.union([
945
- z2.object({
946
- id: z2.string().nullish(),
947
- created: z2.number().nullish(),
948
- model: z2.string().nullish(),
949
- choices: z2.array(
950
- z2.object({
951
- delta: z2.object({
952
- role: z2.enum(["assistant"]).nullish(),
953
- content: z2.string().nullish(),
954
- function_call: z2.object({
955
- name: z2.string().optional(),
956
- arguments: z2.string().optional()
957
- }).nullish(),
958
- tool_calls: z2.array(
959
- z2.object({
960
- index: z2.number(),
961
- id: z2.string().nullish(),
962
- type: z2.literal("function").optional(),
963
- function: z2.object({
964
- name: z2.string().nullish(),
965
- arguments: z2.string().nullish()
867
+ var openaiChatChunkSchema = z3.union([
868
+ z3.object({
869
+ id: z3.string().nullish(),
870
+ created: z3.number().nullish(),
871
+ model: z3.string().nullish(),
872
+ choices: z3.array(
873
+ z3.object({
874
+ delta: z3.object({
875
+ role: z3.enum(["assistant"]).nullish(),
876
+ content: z3.string().nullish(),
877
+ tool_calls: z3.array(
878
+ z3.object({
879
+ index: z3.number(),
880
+ id: z3.string().nullish(),
881
+ type: z3.literal("function").optional(),
882
+ function: z3.object({
883
+ name: z3.string().nullish(),
884
+ arguments: z3.string().nullish()
966
885
  })
967
886
  })
968
887
  ).nullish()
969
888
  }).nullish(),
970
- logprobs: z2.object({
971
- content: z2.array(
972
- z2.object({
973
- token: z2.string(),
974
- logprob: z2.number(),
975
- top_logprobs: z2.array(
976
- z2.object({
977
- token: z2.string(),
978
- logprob: z2.number()
889
+ logprobs: z3.object({
890
+ content: z3.array(
891
+ z3.object({
892
+ token: z3.string(),
893
+ logprob: z3.number(),
894
+ top_logprobs: z3.array(
895
+ z3.object({
896
+ token: z3.string(),
897
+ logprob: z3.number()
979
898
  })
980
899
  )
981
900
  })
982
901
  ).nullable()
983
902
  }).nullish(),
984
- finish_reason: z2.string().nullable().optional(),
985
- index: z2.number()
903
+ finish_reason: z3.string().nullable().optional(),
904
+ index: z3.number()
986
905
  })
987
906
  ),
988
907
  usage: openaiTokenUsageSchema
@@ -1030,12 +949,12 @@ import {
1030
949
  createJsonResponseHandler as createJsonResponseHandler2,
1031
950
  postJsonToApi as postJsonToApi2
1032
951
  } from "@ai-sdk/provider-utils";
1033
- import { z as z3 } from "zod";
952
+ import { z as z4 } from "zod";
1034
953
 
1035
954
  // src/convert-to-openai-completion-prompt.ts
1036
955
  import {
1037
956
  InvalidPromptError,
1038
- UnsupportedFunctionalityError as UnsupportedFunctionalityError4
957
+ UnsupportedFunctionalityError as UnsupportedFunctionalityError3
1039
958
  } from "@ai-sdk/provider";
1040
959
  function convertToOpenAICompletionPrompt({
1041
960
  prompt,
@@ -1082,7 +1001,7 @@ ${userMessage}
1082
1001
  return part.text;
1083
1002
  }
1084
1003
  case "tool-call": {
1085
- throw new UnsupportedFunctionalityError4({
1004
+ throw new UnsupportedFunctionalityError3({
1086
1005
  functionality: "tool-call messages"
1087
1006
  });
1088
1007
  }
@@ -1095,7 +1014,7 @@ ${assistantMessage}
1095
1014
  break;
1096
1015
  }
1097
1016
  case "tool": {
1098
- throw new UnsupportedFunctionalityError4({
1017
+ throw new UnsupportedFunctionalityError3({
1099
1018
  functionality: "tool messages"
1100
1019
  });
1101
1020
  }
@@ -1143,7 +1062,7 @@ var OpenAICompletionLanguageModel = class {
1143
1062
  getArgs({
1144
1063
  inputFormat,
1145
1064
  prompt,
1146
- maxTokens,
1065
+ maxOutputTokens,
1147
1066
  temperature,
1148
1067
  topP,
1149
1068
  topK,
@@ -1185,7 +1104,7 @@ var OpenAICompletionLanguageModel = class {
1185
1104
  suffix: this.settings.suffix,
1186
1105
  user: this.settings.user,
1187
1106
  // standardized settings:
1188
- max_tokens: maxTokens,
1107
+ max_tokens: maxOutputTokens,
1189
1108
  temperature,
1190
1109
  top_p: topP,
1191
1110
  frequency_penalty: frequencyPenalty,
@@ -1221,10 +1140,10 @@ var OpenAICompletionLanguageModel = class {
1221
1140
  });
1222
1141
  const choice = response.choices[0];
1223
1142
  return {
1224
- text: choice.text,
1143
+ text: { type: "text", text: choice.text },
1225
1144
  usage: {
1226
- promptTokens: response.usage.prompt_tokens,
1227
- completionTokens: response.usage.completion_tokens
1145
+ inputTokens: response.usage.prompt_tokens,
1146
+ outputTokens: response.usage.completion_tokens
1228
1147
  },
1229
1148
  finishReason: mapOpenAIFinishReason(choice.finish_reason),
1230
1149
  logprobs: mapOpenAICompletionLogProbs(choice.logprobs),
@@ -1260,9 +1179,9 @@ var OpenAICompletionLanguageModel = class {
1260
1179
  fetch: this.config.fetch
1261
1180
  });
1262
1181
  let finishReason = "unknown";
1263
- let usage = {
1264
- promptTokens: Number.NaN,
1265
- completionTokens: Number.NaN
1182
+ const usage = {
1183
+ inputTokens: void 0,
1184
+ outputTokens: void 0
1266
1185
  };
1267
1186
  let logprobs;
1268
1187
  let isFirstChunk = true;
@@ -1289,10 +1208,8 @@ var OpenAICompletionLanguageModel = class {
1289
1208
  });
1290
1209
  }
1291
1210
  if (value.usage != null) {
1292
- usage = {
1293
- promptTokens: value.usage.prompt_tokens,
1294
- completionTokens: value.usage.completion_tokens
1295
- };
1211
+ usage.inputTokens = value.usage.prompt_tokens;
1212
+ usage.outputTokens = value.usage.completion_tokens;
1296
1213
  }
1297
1214
  const choice = value.choices[0];
1298
1215
  if ((choice == null ? void 0 : choice.finish_reason) != null) {
@@ -1300,8 +1217,8 @@ var OpenAICompletionLanguageModel = class {
1300
1217
  }
1301
1218
  if ((choice == null ? void 0 : choice.text) != null) {
1302
1219
  controller.enqueue({
1303
- type: "text-delta",
1304
- textDelta: choice.text
1220
+ type: "text",
1221
+ text: choice.text
1305
1222
  });
1306
1223
  }
1307
1224
  const mappedLogprobs = mapOpenAICompletionLogProbs(
@@ -1328,46 +1245,46 @@ var OpenAICompletionLanguageModel = class {
1328
1245
  };
1329
1246
  }
1330
1247
  };
1331
- var openaiCompletionResponseSchema = z3.object({
1332
- id: z3.string().nullish(),
1333
- created: z3.number().nullish(),
1334
- model: z3.string().nullish(),
1335
- choices: z3.array(
1336
- z3.object({
1337
- text: z3.string(),
1338
- finish_reason: z3.string(),
1339
- logprobs: z3.object({
1340
- tokens: z3.array(z3.string()),
1341
- token_logprobs: z3.array(z3.number()),
1342
- top_logprobs: z3.array(z3.record(z3.string(), z3.number())).nullable()
1248
+ var openaiCompletionResponseSchema = z4.object({
1249
+ id: z4.string().nullish(),
1250
+ created: z4.number().nullish(),
1251
+ model: z4.string().nullish(),
1252
+ choices: z4.array(
1253
+ z4.object({
1254
+ text: z4.string(),
1255
+ finish_reason: z4.string(),
1256
+ logprobs: z4.object({
1257
+ tokens: z4.array(z4.string()),
1258
+ token_logprobs: z4.array(z4.number()),
1259
+ top_logprobs: z4.array(z4.record(z4.string(), z4.number())).nullable()
1343
1260
  }).nullish()
1344
1261
  })
1345
1262
  ),
1346
- usage: z3.object({
1347
- prompt_tokens: z3.number(),
1348
- completion_tokens: z3.number()
1263
+ usage: z4.object({
1264
+ prompt_tokens: z4.number(),
1265
+ completion_tokens: z4.number()
1349
1266
  })
1350
1267
  });
1351
- var openaiCompletionChunkSchema = z3.union([
1352
- z3.object({
1353
- id: z3.string().nullish(),
1354
- created: z3.number().nullish(),
1355
- model: z3.string().nullish(),
1356
- choices: z3.array(
1357
- z3.object({
1358
- text: z3.string(),
1359
- finish_reason: z3.string().nullish(),
1360
- index: z3.number(),
1361
- logprobs: z3.object({
1362
- tokens: z3.array(z3.string()),
1363
- token_logprobs: z3.array(z3.number()),
1364
- top_logprobs: z3.array(z3.record(z3.string(), z3.number())).nullable()
1268
+ var openaiCompletionChunkSchema = z4.union([
1269
+ z4.object({
1270
+ id: z4.string().nullish(),
1271
+ created: z4.number().nullish(),
1272
+ model: z4.string().nullish(),
1273
+ choices: z4.array(
1274
+ z4.object({
1275
+ text: z4.string(),
1276
+ finish_reason: z4.string().nullish(),
1277
+ index: z4.number(),
1278
+ logprobs: z4.object({
1279
+ tokens: z4.array(z4.string()),
1280
+ token_logprobs: z4.array(z4.number()),
1281
+ top_logprobs: z4.array(z4.record(z4.string(), z4.number())).nullable()
1365
1282
  }).nullish()
1366
1283
  })
1367
1284
  ),
1368
- usage: z3.object({
1369
- prompt_tokens: z3.number(),
1370
- completion_tokens: z3.number()
1285
+ usage: z4.object({
1286
+ prompt_tokens: z4.number(),
1287
+ completion_tokens: z4.number()
1371
1288
  }).nullish()
1372
1289
  }),
1373
1290
  openaiErrorDataSchema
@@ -1382,10 +1299,10 @@ import {
1382
1299
  createJsonResponseHandler as createJsonResponseHandler3,
1383
1300
  postJsonToApi as postJsonToApi3
1384
1301
  } from "@ai-sdk/provider-utils";
1385
- import { z as z4 } from "zod";
1302
+ import { z as z5 } from "zod";
1386
1303
  var OpenAIEmbeddingModel = class {
1387
1304
  constructor(modelId, settings, config) {
1388
- this.specificationVersion = "v1";
1305
+ this.specificationVersion = "v2";
1389
1306
  this.modelId = modelId;
1390
1307
  this.settings = settings;
1391
1308
  this.config = config;
@@ -1414,7 +1331,11 @@ var OpenAIEmbeddingModel = class {
1414
1331
  values
1415
1332
  });
1416
1333
  }
1417
- const { responseHeaders, value: response } = await postJsonToApi3({
1334
+ const {
1335
+ responseHeaders,
1336
+ value: response,
1337
+ rawValue
1338
+ } = await postJsonToApi3({
1418
1339
  url: this.config.url({
1419
1340
  path: "/embeddings",
1420
1341
  modelId: this.modelId
@@ -1437,13 +1358,13 @@ var OpenAIEmbeddingModel = class {
1437
1358
  return {
1438
1359
  embeddings: response.data.map((item) => item.embedding),
1439
1360
  usage: response.usage ? { tokens: response.usage.prompt_tokens } : void 0,
1440
- rawResponse: { headers: responseHeaders }
1361
+ response: { headers: responseHeaders, body: rawValue }
1441
1362
  };
1442
1363
  }
1443
1364
  };
1444
- var openaiTextEmbeddingResponseSchema = z4.object({
1445
- data: z4.array(z4.object({ embedding: z4.array(z4.number()) })),
1446
- usage: z4.object({ prompt_tokens: z4.number() }).nullish()
1365
+ var openaiTextEmbeddingResponseSchema = z5.object({
1366
+ data: z5.array(z5.object({ embedding: z5.array(z5.number()) })),
1367
+ usage: z5.object({ prompt_tokens: z5.number() }).nullish()
1447
1368
  });
1448
1369
 
1449
1370
  // src/openai-image-model.ts
@@ -1452,7 +1373,7 @@ import {
1452
1373
  createJsonResponseHandler as createJsonResponseHandler4,
1453
1374
  postJsonToApi as postJsonToApi4
1454
1375
  } from "@ai-sdk/provider-utils";
1455
- import { z as z5 } from "zod";
1376
+ import { z as z6 } from "zod";
1456
1377
 
1457
1378
  // src/openai-image-settings.ts
1458
1379
  var modelMaxImagesPerCall = {
@@ -1530,13 +1451,13 @@ var OpenAIImageModel = class {
1530
1451
  };
1531
1452
  }
1532
1453
  };
1533
- var openaiImageResponseSchema = z5.object({
1534
- data: z5.array(z5.object({ b64_json: z5.string() }))
1454
+ var openaiImageResponseSchema = z6.object({
1455
+ data: z6.array(z6.object({ b64_json: z6.string() }))
1535
1456
  });
1536
1457
 
1537
1458
  // src/openai-tools.ts
1538
- import { z as z6 } from "zod";
1539
- var WebSearchPreviewParameters = z6.object({});
1459
+ import { z as z7 } from "zod";
1460
+ var WebSearchPreviewParameters = z7.object({});
1540
1461
  function webSearchPreviewTool({
1541
1462
  searchContextSize,
1542
1463
  userLocation
@@ -1560,22 +1481,16 @@ import {
1560
1481
  combineHeaders as combineHeaders5,
1561
1482
  convertBase64ToUint8Array,
1562
1483
  createJsonResponseHandler as createJsonResponseHandler5,
1563
- parseProviderOptions,
1484
+ parseProviderOptions as parseProviderOptions2,
1564
1485
  postFormDataToApi
1565
1486
  } from "@ai-sdk/provider-utils";
1566
- import { z as z7 } from "zod";
1567
- var OpenAIProviderOptionsSchema = z7.object({
1568
- include: z7.array(z7.string()).optional().describe(
1569
- "Additional information to include in the transcription response."
1570
- ),
1571
- language: z7.string().optional().describe("The language of the input audio in ISO-639-1 format."),
1572
- prompt: z7.string().optional().describe(
1573
- "An optional text to guide the model's style or continue a previous audio segment."
1574
- ),
1575
- temperature: z7.number().min(0).max(1).optional().default(0).describe("The sampling temperature, between 0 and 1."),
1576
- timestampGranularities: z7.array(z7.enum(["word", "segment"])).optional().default(["segment"]).describe(
1577
- "The timestamp granularities to populate for this transcription."
1578
- )
1487
+ import { z as z8 } from "zod";
1488
+ var openAIProviderOptionsSchema = z8.object({
1489
+ include: z8.array(z8.string()).nullish(),
1490
+ language: z8.string().nullish(),
1491
+ prompt: z8.string().nullish(),
1492
+ temperature: z8.number().min(0).max(1).nullish().default(0),
1493
+ timestampGranularities: z8.array(z8.enum(["word", "segment"])).nullish().default(["segment"])
1579
1494
  });
1580
1495
  var languageMap = {
1581
1496
  afrikaans: "af",
@@ -1650,11 +1565,12 @@ var OpenAITranscriptionModel = class {
1650
1565
  mediaType,
1651
1566
  providerOptions
1652
1567
  }) {
1568
+ var _a, _b, _c, _d, _e;
1653
1569
  const warnings = [];
1654
- const openAIOptions = parseProviderOptions({
1570
+ const openAIOptions = parseProviderOptions2({
1655
1571
  provider: "openai",
1656
1572
  providerOptions,
1657
- schema: OpenAIProviderOptionsSchema
1573
+ schema: openAIProviderOptionsSchema
1658
1574
  });
1659
1575
  const formData = new FormData();
1660
1576
  const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([convertBase64ToUint8Array(audio)]);
@@ -1662,16 +1578,16 @@ var OpenAITranscriptionModel = class {
1662
1578
  formData.append("file", new File([blob], "audio", { type: mediaType }));
1663
1579
  if (openAIOptions) {
1664
1580
  const transcriptionModelOptions = {
1665
- include: openAIOptions.include,
1666
- language: openAIOptions.language,
1667
- prompt: openAIOptions.prompt,
1668
- temperature: openAIOptions.temperature,
1669
- timestamp_granularities: openAIOptions.timestampGranularities
1581
+ include: (_a = openAIOptions.include) != null ? _a : void 0,
1582
+ language: (_b = openAIOptions.language) != null ? _b : void 0,
1583
+ prompt: (_c = openAIOptions.prompt) != null ? _c : void 0,
1584
+ temperature: (_d = openAIOptions.temperature) != null ? _d : void 0,
1585
+ timestamp_granularities: (_e = openAIOptions.timestampGranularities) != null ? _e : void 0
1670
1586
  };
1671
1587
  for (const key in transcriptionModelOptions) {
1672
1588
  const value = transcriptionModelOptions[key];
1673
1589
  if (value !== void 0) {
1674
- formData.append(key, value);
1590
+ formData.append(key, String(value));
1675
1591
  }
1676
1592
  }
1677
1593
  }
@@ -1722,15 +1638,15 @@ var OpenAITranscriptionModel = class {
1722
1638
  };
1723
1639
  }
1724
1640
  };
1725
- var openaiTranscriptionResponseSchema = z7.object({
1726
- text: z7.string(),
1727
- language: z7.string().nullish(),
1728
- duration: z7.number().nullish(),
1729
- words: z7.array(
1730
- z7.object({
1731
- word: z7.string(),
1732
- start: z7.number(),
1733
- end: z7.number()
1641
+ var openaiTranscriptionResponseSchema = z8.object({
1642
+ text: z8.string(),
1643
+ language: z8.string().nullish(),
1644
+ duration: z8.number().nullish(),
1645
+ words: z8.array(
1646
+ z8.object({
1647
+ word: z8.string(),
1648
+ start: z8.number(),
1649
+ end: z8.number()
1734
1650
  })
1735
1651
  ).nullish()
1736
1652
  });
@@ -1741,14 +1657,14 @@ import {
1741
1657
  createEventSourceResponseHandler as createEventSourceResponseHandler3,
1742
1658
  createJsonResponseHandler as createJsonResponseHandler6,
1743
1659
  generateId as generateId2,
1744
- parseProviderOptions as parseProviderOptions2,
1660
+ parseProviderOptions as parseProviderOptions3,
1745
1661
  postJsonToApi as postJsonToApi5
1746
1662
  } from "@ai-sdk/provider-utils";
1747
- import { z as z8 } from "zod";
1663
+ import { z as z9 } from "zod";
1748
1664
 
1749
1665
  // src/responses/convert-to-openai-responses-messages.ts
1750
1666
  import {
1751
- UnsupportedFunctionalityError as UnsupportedFunctionalityError5
1667
+ UnsupportedFunctionalityError as UnsupportedFunctionalityError4
1752
1668
  } from "@ai-sdk/provider";
1753
1669
  function convertToOpenAIResponsesMessages({
1754
1670
  prompt,
@@ -1804,7 +1720,7 @@ function convertToOpenAIResponsesMessages({
1804
1720
  };
1805
1721
  } else if (part.mediaType === "application/pdf") {
1806
1722
  if (part.data instanceof URL) {
1807
- throw new UnsupportedFunctionalityError5({
1723
+ throw new UnsupportedFunctionalityError4({
1808
1724
  functionality: "PDF file parts with URLs"
1809
1725
  });
1810
1726
  }
@@ -1814,7 +1730,7 @@ function convertToOpenAIResponsesMessages({
1814
1730
  file_data: `data:application/pdf;base64,${part.data}`
1815
1731
  };
1816
1732
  } else {
1817
- throw new UnsupportedFunctionalityError5({
1733
+ throw new UnsupportedFunctionalityError4({
1818
1734
  functionality: `file part media type ${part.mediaType}`
1819
1735
  });
1820
1736
  }
@@ -1886,7 +1802,7 @@ function mapOpenAIResponseFinishReason({
1886
1802
 
1887
1803
  // src/responses/openai-responses-prepare-tools.ts
1888
1804
  import {
1889
- UnsupportedFunctionalityError as UnsupportedFunctionalityError6
1805
+ UnsupportedFunctionalityError as UnsupportedFunctionalityError5
1890
1806
  } from "@ai-sdk/provider";
1891
1807
  function prepareResponsesTools({
1892
1808
  tools,
@@ -1946,7 +1862,7 @@ function prepareResponsesTools({
1946
1862
  };
1947
1863
  default: {
1948
1864
  const _exhaustiveCheck = type;
1949
- throw new UnsupportedFunctionalityError6({
1865
+ throw new UnsupportedFunctionalityError5({
1950
1866
  functionality: `tool choice type: ${_exhaustiveCheck}`
1951
1867
  });
1952
1868
  }
@@ -1965,7 +1881,7 @@ var OpenAIResponsesLanguageModel = class {
1965
1881
  return this.config.provider;
1966
1882
  }
1967
1883
  getArgs({
1968
- maxTokens,
1884
+ maxOutputTokens,
1969
1885
  temperature,
1970
1886
  stopSequences,
1971
1887
  topP,
@@ -2008,7 +1924,7 @@ var OpenAIResponsesLanguageModel = class {
2008
1924
  systemMessageMode: modelConfig.systemMessageMode
2009
1925
  });
2010
1926
  warnings.push(...messageWarnings);
2011
- const openaiOptions = parseProviderOptions2({
1927
+ const openaiOptions = parseProviderOptions3({
2012
1928
  provider: "openai",
2013
1929
  providerOptions,
2014
1930
  schema: openaiResponsesProviderOptionsSchema
@@ -2019,7 +1935,7 @@ var OpenAIResponsesLanguageModel = class {
2019
1935
  input: messages,
2020
1936
  temperature,
2021
1937
  top_p: topP,
2022
- max_output_tokens: maxTokens,
1938
+ max_output_tokens: maxOutputTokens,
2023
1939
  ...(responseFormat == null ? void 0 : responseFormat.type) === "json" && {
2024
1940
  text: {
2025
1941
  format: responseFormat.schema != null ? {
@@ -2098,49 +2014,49 @@ var OpenAIResponsesLanguageModel = class {
2098
2014
  body,
2099
2015
  failedResponseHandler: openaiFailedResponseHandler,
2100
2016
  successfulResponseHandler: createJsonResponseHandler6(
2101
- z8.object({
2102
- id: z8.string(),
2103
- created_at: z8.number(),
2104
- model: z8.string(),
2105
- output: z8.array(
2106
- z8.discriminatedUnion("type", [
2107
- z8.object({
2108
- type: z8.literal("message"),
2109
- role: z8.literal("assistant"),
2110
- content: z8.array(
2111
- z8.object({
2112
- type: z8.literal("output_text"),
2113
- text: z8.string(),
2114
- annotations: z8.array(
2115
- z8.object({
2116
- type: z8.literal("url_citation"),
2117
- start_index: z8.number(),
2118
- end_index: z8.number(),
2119
- url: z8.string(),
2120
- title: z8.string()
2017
+ z9.object({
2018
+ id: z9.string(),
2019
+ created_at: z9.number(),
2020
+ model: z9.string(),
2021
+ output: z9.array(
2022
+ z9.discriminatedUnion("type", [
2023
+ z9.object({
2024
+ type: z9.literal("message"),
2025
+ role: z9.literal("assistant"),
2026
+ content: z9.array(
2027
+ z9.object({
2028
+ type: z9.literal("output_text"),
2029
+ text: z9.string(),
2030
+ annotations: z9.array(
2031
+ z9.object({
2032
+ type: z9.literal("url_citation"),
2033
+ start_index: z9.number(),
2034
+ end_index: z9.number(),
2035
+ url: z9.string(),
2036
+ title: z9.string()
2121
2037
  })
2122
2038
  )
2123
2039
  })
2124
2040
  )
2125
2041
  }),
2126
- z8.object({
2127
- type: z8.literal("function_call"),
2128
- call_id: z8.string(),
2129
- name: z8.string(),
2130
- arguments: z8.string()
2042
+ z9.object({
2043
+ type: z9.literal("function_call"),
2044
+ call_id: z9.string(),
2045
+ name: z9.string(),
2046
+ arguments: z9.string()
2131
2047
  }),
2132
- z8.object({
2133
- type: z8.literal("web_search_call")
2048
+ z9.object({
2049
+ type: z9.literal("web_search_call")
2134
2050
  }),
2135
- z8.object({
2136
- type: z8.literal("computer_call")
2051
+ z9.object({
2052
+ type: z9.literal("computer_call")
2137
2053
  }),
2138
- z8.object({
2139
- type: z8.literal("reasoning")
2054
+ z9.object({
2055
+ type: z9.literal("reasoning")
2140
2056
  })
2141
2057
  ])
2142
2058
  ),
2143
- incomplete_details: z8.object({ reason: z8.string() }).nullable(),
2059
+ incomplete_details: z9.object({ reason: z9.string() }).nullable(),
2144
2060
  usage: usageSchema
2145
2061
  })
2146
2062
  ),
@@ -2149,17 +2065,22 @@ var OpenAIResponsesLanguageModel = class {
2149
2065
  });
2150
2066
  const outputTextElements = response.output.filter((output) => output.type === "message").flatMap((output) => output.content).filter((content) => content.type === "output_text");
2151
2067
  const toolCalls = response.output.filter((output) => output.type === "function_call").map((output) => ({
2068
+ type: "tool-call",
2152
2069
  toolCallType: "function",
2153
2070
  toolCallId: output.call_id,
2154
2071
  toolName: output.name,
2155
2072
  args: output.arguments
2156
2073
  }));
2157
2074
  return {
2158
- text: outputTextElements.map((content) => content.text).join("\n"),
2075
+ text: {
2076
+ type: "text",
2077
+ text: outputTextElements.map((content) => content.text).join("\n")
2078
+ },
2159
2079
  sources: outputTextElements.flatMap(
2160
2080
  (content) => content.annotations.map((annotation) => {
2161
2081
  var _a2, _b2, _c2;
2162
2082
  return {
2083
+ type: "source",
2163
2084
  sourceType: "url",
2164
2085
  id: (_c2 = (_b2 = (_a2 = this.config).generateId) == null ? void 0 : _b2.call(_a2)) != null ? _c2 : generateId2(),
2165
2086
  url: annotation.url,
@@ -2173,8 +2094,8 @@ var OpenAIResponsesLanguageModel = class {
2173
2094
  }),
2174
2095
  toolCalls: toolCalls.length > 0 ? toolCalls : void 0,
2175
2096
  usage: {
2176
- promptTokens: response.usage.input_tokens,
2177
- completionTokens: response.usage.output_tokens
2097
+ inputTokens: response.usage.input_tokens,
2098
+ outputTokens: response.usage.output_tokens
2178
2099
  },
2179
2100
  request: { body },
2180
2101
  response: {
@@ -2215,8 +2136,10 @@ var OpenAIResponsesLanguageModel = class {
2215
2136
  });
2216
2137
  const self = this;
2217
2138
  let finishReason = "unknown";
2218
- let promptTokens = NaN;
2219
- let completionTokens = NaN;
2139
+ const usage = {
2140
+ inputTokens: void 0,
2141
+ outputTokens: void 0
2142
+ };
2220
2143
  let cachedPromptTokens = null;
2221
2144
  let reasoningTokens = null;
2222
2145
  let responseId = null;
@@ -2268,8 +2191,8 @@ var OpenAIResponsesLanguageModel = class {
2268
2191
  });
2269
2192
  } else if (isTextDeltaChunk(value)) {
2270
2193
  controller.enqueue({
2271
- type: "text-delta",
2272
- textDelta: value.delta
2194
+ type: "text",
2195
+ text: value.delta
2273
2196
  });
2274
2197
  } else if (isResponseOutputItemDoneChunk(value) && value.item.type === "function_call") {
2275
2198
  ongoingToolCalls[value.output_index] = void 0;
@@ -2286,19 +2209,17 @@ var OpenAIResponsesLanguageModel = class {
2286
2209
  finishReason: (_a = value.response.incomplete_details) == null ? void 0 : _a.reason,
2287
2210
  hasToolCalls
2288
2211
  });
2289
- promptTokens = value.response.usage.input_tokens;
2290
- completionTokens = value.response.usage.output_tokens;
2212
+ usage.inputTokens = value.response.usage.input_tokens;
2213
+ usage.outputTokens = value.response.usage.output_tokens;
2291
2214
  cachedPromptTokens = (_c = (_b = value.response.usage.input_tokens_details) == null ? void 0 : _b.cached_tokens) != null ? _c : cachedPromptTokens;
2292
2215
  reasoningTokens = (_e = (_d = value.response.usage.output_tokens_details) == null ? void 0 : _d.reasoning_tokens) != null ? _e : reasoningTokens;
2293
2216
  } else if (isResponseAnnotationAddedChunk(value)) {
2294
2217
  controller.enqueue({
2295
2218
  type: "source",
2296
- source: {
2297
- sourceType: "url",
2298
- id: (_h = (_g = (_f = self.config).generateId) == null ? void 0 : _g.call(_f)) != null ? _h : generateId2(),
2299
- url: value.annotation.url,
2300
- title: value.annotation.title
2301
- }
2219
+ sourceType: "url",
2220
+ id: (_h = (_g = (_f = self.config).generateId) == null ? void 0 : _g.call(_f)) != null ? _h : generateId2(),
2221
+ url: value.annotation.url,
2222
+ title: value.annotation.title
2302
2223
  });
2303
2224
  }
2304
2225
  },
@@ -2306,7 +2227,7 @@ var OpenAIResponsesLanguageModel = class {
2306
2227
  controller.enqueue({
2307
2228
  type: "finish",
2308
2229
  finishReason,
2309
- usage: { promptTokens, completionTokens },
2230
+ usage,
2310
2231
  ...(cachedPromptTokens != null || reasoningTokens != null) && {
2311
2232
  providerMetadata: {
2312
2233
  openai: {
@@ -2326,79 +2247,79 @@ var OpenAIResponsesLanguageModel = class {
2326
2247
  };
2327
2248
  }
2328
2249
  };
2329
- var usageSchema = z8.object({
2330
- input_tokens: z8.number(),
2331
- input_tokens_details: z8.object({ cached_tokens: z8.number().nullish() }).nullish(),
2332
- output_tokens: z8.number(),
2333
- output_tokens_details: z8.object({ reasoning_tokens: z8.number().nullish() }).nullish()
2250
+ var usageSchema = z9.object({
2251
+ input_tokens: z9.number(),
2252
+ input_tokens_details: z9.object({ cached_tokens: z9.number().nullish() }).nullish(),
2253
+ output_tokens: z9.number(),
2254
+ output_tokens_details: z9.object({ reasoning_tokens: z9.number().nullish() }).nullish()
2334
2255
  });
2335
- var textDeltaChunkSchema = z8.object({
2336
- type: z8.literal("response.output_text.delta"),
2337
- delta: z8.string()
2256
+ var textDeltaChunkSchema = z9.object({
2257
+ type: z9.literal("response.output_text.delta"),
2258
+ delta: z9.string()
2338
2259
  });
2339
- var responseFinishedChunkSchema = z8.object({
2340
- type: z8.enum(["response.completed", "response.incomplete"]),
2341
- response: z8.object({
2342
- incomplete_details: z8.object({ reason: z8.string() }).nullish(),
2260
+ var responseFinishedChunkSchema = z9.object({
2261
+ type: z9.enum(["response.completed", "response.incomplete"]),
2262
+ response: z9.object({
2263
+ incomplete_details: z9.object({ reason: z9.string() }).nullish(),
2343
2264
  usage: usageSchema
2344
2265
  })
2345
2266
  });
2346
- var responseCreatedChunkSchema = z8.object({
2347
- type: z8.literal("response.created"),
2348
- response: z8.object({
2349
- id: z8.string(),
2350
- created_at: z8.number(),
2351
- model: z8.string()
2267
+ var responseCreatedChunkSchema = z9.object({
2268
+ type: z9.literal("response.created"),
2269
+ response: z9.object({
2270
+ id: z9.string(),
2271
+ created_at: z9.number(),
2272
+ model: z9.string()
2352
2273
  })
2353
2274
  });
2354
- var responseOutputItemDoneSchema = z8.object({
2355
- type: z8.literal("response.output_item.done"),
2356
- output_index: z8.number(),
2357
- item: z8.discriminatedUnion("type", [
2358
- z8.object({
2359
- type: z8.literal("message")
2275
+ var responseOutputItemDoneSchema = z9.object({
2276
+ type: z9.literal("response.output_item.done"),
2277
+ output_index: z9.number(),
2278
+ item: z9.discriminatedUnion("type", [
2279
+ z9.object({
2280
+ type: z9.literal("message")
2360
2281
  }),
2361
- z8.object({
2362
- type: z8.literal("function_call"),
2363
- id: z8.string(),
2364
- call_id: z8.string(),
2365
- name: z8.string(),
2366
- arguments: z8.string(),
2367
- status: z8.literal("completed")
2282
+ z9.object({
2283
+ type: z9.literal("function_call"),
2284
+ id: z9.string(),
2285
+ call_id: z9.string(),
2286
+ name: z9.string(),
2287
+ arguments: z9.string(),
2288
+ status: z9.literal("completed")
2368
2289
  })
2369
2290
  ])
2370
2291
  });
2371
- var responseFunctionCallArgumentsDeltaSchema = z8.object({
2372
- type: z8.literal("response.function_call_arguments.delta"),
2373
- item_id: z8.string(),
2374
- output_index: z8.number(),
2375
- delta: z8.string()
2292
+ var responseFunctionCallArgumentsDeltaSchema = z9.object({
2293
+ type: z9.literal("response.function_call_arguments.delta"),
2294
+ item_id: z9.string(),
2295
+ output_index: z9.number(),
2296
+ delta: z9.string()
2376
2297
  });
2377
- var responseOutputItemAddedSchema = z8.object({
2378
- type: z8.literal("response.output_item.added"),
2379
- output_index: z8.number(),
2380
- item: z8.discriminatedUnion("type", [
2381
- z8.object({
2382
- type: z8.literal("message")
2298
+ var responseOutputItemAddedSchema = z9.object({
2299
+ type: z9.literal("response.output_item.added"),
2300
+ output_index: z9.number(),
2301
+ item: z9.discriminatedUnion("type", [
2302
+ z9.object({
2303
+ type: z9.literal("message")
2383
2304
  }),
2384
- z8.object({
2385
- type: z8.literal("function_call"),
2386
- id: z8.string(),
2387
- call_id: z8.string(),
2388
- name: z8.string(),
2389
- arguments: z8.string()
2305
+ z9.object({
2306
+ type: z9.literal("function_call"),
2307
+ id: z9.string(),
2308
+ call_id: z9.string(),
2309
+ name: z9.string(),
2310
+ arguments: z9.string()
2390
2311
  })
2391
2312
  ])
2392
2313
  });
2393
- var responseAnnotationAddedSchema = z8.object({
2394
- type: z8.literal("response.output_text.annotation.added"),
2395
- annotation: z8.object({
2396
- type: z8.literal("url_citation"),
2397
- url: z8.string(),
2398
- title: z8.string()
2314
+ var responseAnnotationAddedSchema = z9.object({
2315
+ type: z9.literal("response.output_text.annotation.added"),
2316
+ annotation: z9.object({
2317
+ type: z9.literal("url_citation"),
2318
+ url: z9.string(),
2319
+ title: z9.string()
2399
2320
  })
2400
2321
  });
2401
- var openaiResponsesChunkSchema = z8.union([
2322
+ var openaiResponsesChunkSchema = z9.union([
2402
2323
  textDeltaChunkSchema,
2403
2324
  responseFinishedChunkSchema,
2404
2325
  responseCreatedChunkSchema,
@@ -2406,7 +2327,7 @@ var openaiResponsesChunkSchema = z8.union([
2406
2327
  responseFunctionCallArgumentsDeltaSchema,
2407
2328
  responseOutputItemAddedSchema,
2408
2329
  responseAnnotationAddedSchema,
2409
- z8.object({ type: z8.string() }).passthrough()
2330
+ z9.object({ type: z9.string() }).passthrough()
2410
2331
  // fallback for unknown chunks
2411
2332
  ]);
2412
2333
  function isTextDeltaChunk(chunk) {
@@ -2451,15 +2372,15 @@ function getResponsesModelConfig(modelId) {
2451
2372
  requiredAutoTruncation: false
2452
2373
  };
2453
2374
  }
2454
- var openaiResponsesProviderOptionsSchema = z8.object({
2455
- metadata: z8.any().nullish(),
2456
- parallelToolCalls: z8.boolean().nullish(),
2457
- previousResponseId: z8.string().nullish(),
2458
- store: z8.boolean().nullish(),
2459
- user: z8.string().nullish(),
2460
- reasoningEffort: z8.string().nullish(),
2461
- strictSchemas: z8.boolean().nullish(),
2462
- instructions: z8.string().nullish()
2375
+ var openaiResponsesProviderOptionsSchema = z9.object({
2376
+ metadata: z9.any().nullish(),
2377
+ parallelToolCalls: z9.boolean().nullish(),
2378
+ previousResponseId: z9.string().nullish(),
2379
+ store: z9.boolean().nullish(),
2380
+ user: z9.string().nullish(),
2381
+ reasoningEffort: z9.string().nullish(),
2382
+ strictSchemas: z9.boolean().nullish(),
2383
+ instructions: z9.string().nullish()
2463
2384
  });
2464
2385
 
2465
2386
  // src/openai-provider.ts