@ai-sdk/openai 2.0.139 → 2.0.140

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
@@ -91,9 +91,24 @@ function getGptVersion(modelId) {
91
91
  import {
92
92
  UnsupportedFunctionalityError
93
93
  } from "@ai-sdk/provider";
94
- import { convertToBase64 } from "@ai-sdk/provider-utils";
94
+ import {
95
+ stringifyWithBigIntAndCycles,
96
+ secureJsonParse,
97
+ convertToBase64
98
+ } from "@ai-sdk/provider-utils";
95
99
  function serializeToolCallArguments(input) {
96
- return JSON.stringify(
100
+ if (typeof input === "string") {
101
+ try {
102
+ const parsed = secureJsonParse(input);
103
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
104
+ return "{}";
105
+ }
106
+ return input;
107
+ } catch (e) {
108
+ return "{}";
109
+ }
110
+ }
111
+ return stringifyWithBigIntAndCycles(
97
112
  typeof input === "object" && input !== null && !Array.isArray(input) ? input : {}
98
113
  );
99
114
  }
@@ -316,7 +331,7 @@ function convertToOpenAIChatMessages({
316
331
  case "content":
317
332
  case "json":
318
333
  case "error-json":
319
- contentValue = JSON.stringify(output.value);
334
+ contentValue = stringifyWithBigIntAndCycles(output.value);
320
335
  break;
321
336
  }
322
337
  messages.push({
@@ -2355,6 +2370,8 @@ import {
2355
2370
  UnsupportedFunctionalityError as UnsupportedFunctionalityError4
2356
2371
  } from "@ai-sdk/provider";
2357
2372
  import {
2373
+ stringifyWithBigIntAndCycles as stringifyWithBigIntAndCycles2,
2374
+ secureJsonParse as secureJsonParse2,
2358
2375
  lazySchema as lazySchema8,
2359
2376
  zodSchema as zodSchema17,
2360
2377
  convertToBase64 as convertToBase642,
@@ -2845,7 +2862,7 @@ async function convertToOpenAIResponsesInput({
2845
2862
  type: "function_call",
2846
2863
  call_id: part.toolCallId,
2847
2864
  name: part.toolName,
2848
- arguments: JSON.stringify(part.input),
2865
+ arguments: serializeToolCallArguments2(part.input),
2849
2866
  ...isAsync != null && { async: isAsync },
2850
2867
  id: canUseItemId ? id : void 0
2851
2868
  });
@@ -2907,7 +2924,7 @@ async function convertToOpenAIResponsesInput({
2907
2924
  } else if (reasoningMessage !== void 0) {
2908
2925
  warnings.push({
2909
2926
  type: "other",
2910
- message: `Cannot append empty reasoning part to existing reasoning sequence. Skipping reasoning part: ${JSON.stringify(part)}.`
2927
+ message: `Cannot append empty reasoning part to existing reasoning sequence. Skipping reasoning part: ${stringifyWithBigIntAndCycles2(part)}.`
2911
2928
  });
2912
2929
  }
2913
2930
  if (reasoningMessage === void 0) {
@@ -2928,7 +2945,7 @@ async function convertToOpenAIResponsesInput({
2928
2945
  } else {
2929
2946
  warnings.push({
2930
2947
  type: "other",
2931
- message: `Non-OpenAI reasoning parts are not supported. Skipping reasoning part: ${JSON.stringify(part)}.`
2948
+ message: `Non-OpenAI reasoning parts are not supported. Skipping reasoning part: ${stringifyWithBigIntAndCycles2(part)}.`
2932
2949
  });
2933
2950
  }
2934
2951
  break;
@@ -2969,10 +2986,10 @@ async function convertToOpenAIResponsesInput({
2969
2986
  break;
2970
2987
  case "json":
2971
2988
  case "error-json":
2972
- contentValue = promptCacheBreakpoint == null ? JSON.stringify(output.value) : [
2989
+ contentValue = promptCacheBreakpoint == null ? stringifyWithBigIntAndCycles2(output.value) : [
2973
2990
  {
2974
2991
  type: "input_text",
2975
- text: JSON.stringify(output.value),
2992
+ text: stringifyWithBigIntAndCycles2(output.value),
2976
2993
  prompt_cache_breakpoint: promptCacheBreakpoint
2977
2994
  }
2978
2995
  ];
@@ -3045,6 +3062,17 @@ var openaiResponsesReasoningProviderOptionsSchema = lazySchema8(
3045
3062
  })
3046
3063
  )
3047
3064
  );
3065
+ function serializeToolCallArguments2(input) {
3066
+ if (typeof input === "string") {
3067
+ try {
3068
+ secureJsonParse2(input);
3069
+ return input;
3070
+ } catch (e) {
3071
+ return stringifyWithBigIntAndCycles2(input);
3072
+ }
3073
+ }
3074
+ return stringifyWithBigIntAndCycles2(input === void 0 ? {} : input);
3075
+ }
3048
3076
 
3049
3077
  // src/responses/map-openai-responses-finish-reason.ts
3050
3078
  function mapOpenAIResponseFinishReason({
@@ -5149,6 +5177,16 @@ var openAITranscriptionProviderOptions = lazyValidator13(
5149
5177
  * The language of the input audio in ISO-639-1 format.
5150
5178
  */
5151
5179
  language: z21.string().optional(),
5180
+ /**
5181
+ * Expected languages for REST transcription, e.g. with gpt-transcribe.
5182
+ * Use this instead of language. The API validates model support.
5183
+ */
5184
+ languages: z21.array(z21.string()).optional(),
5185
+ /**
5186
+ * Vocabulary hints for REST transcription, e.g. names or technical terms.
5187
+ * The API validates model support.
5188
+ */
5189
+ keywords: z21.array(z21.string()).optional(),
5152
5190
  /**
5153
5191
  * An optional text to guide the model's style or continue a previous audio segment.
5154
5192
  */
@@ -5260,6 +5298,8 @@ var OpenAITranscriptionModel = class {
5260
5298
  const transcriptionModelOptions = {
5261
5299
  include: openAIOptions.include,
5262
5300
  language: openAIOptions.language,
5301
+ languages: openAIOptions.languages,
5302
+ keywords: openAIOptions.keywords,
5263
5303
  prompt: openAIOptions.prompt,
5264
5304
  // https://platform.openai.com/docs/api-reference/audio/createTranscription#audio_createtranscription-response_format
5265
5305
  // prefer verbose_json to get segments for models that support it
@@ -5336,7 +5376,7 @@ var OpenAITranscriptionModel = class {
5336
5376
  };
5337
5377
 
5338
5378
  // src/version.ts
5339
- var VERSION = true ? "2.0.139" : "0.0.0-test";
5379
+ var VERSION = true ? "2.0.140" : "0.0.0-test";
5340
5380
 
5341
5381
  // src/openai-provider.ts
5342
5382
  function createOpenAI(options = {}) {