@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/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # @ai-sdk/openai
2
2
 
3
+ ## 2.0.140
4
+
5
+ ### Patch Changes
6
+
7
+ - 0a069bd: fix(openai): preserve valid JSON string tool arguments and serialize BigInt and cycles in tool calls and results, retaining malformed argument replay fallbacks
8
+ - 0a069bd: Forward `languages` and `keywords` transcription hints as repeated multipart fields instead of silently dropping them.
9
+ - Updated dependencies [0a069bd]
10
+ - Updated dependencies [0a069bd]
11
+ - Updated dependencies [0a069bd]
12
+ - @ai-sdk/provider-utils@3.0.44
13
+
3
14
  ## 2.0.139
4
15
 
5
16
  ### Patch Changes
package/dist/index.js CHANGED
@@ -100,7 +100,18 @@ function getGptVersion(modelId) {
100
100
  var import_provider = require("@ai-sdk/provider");
101
101
  var import_provider_utils2 = require("@ai-sdk/provider-utils");
102
102
  function serializeToolCallArguments(input) {
103
- return JSON.stringify(
103
+ if (typeof input === "string") {
104
+ try {
105
+ const parsed = (0, import_provider_utils2.secureJsonParse)(input);
106
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
107
+ return "{}";
108
+ }
109
+ return input;
110
+ } catch (e) {
111
+ return "{}";
112
+ }
113
+ }
114
+ return (0, import_provider_utils2.stringifyWithBigIntAndCycles)(
104
115
  typeof input === "object" && input !== null && !Array.isArray(input) ? input : {}
105
116
  );
106
117
  }
@@ -323,7 +334,7 @@ function convertToOpenAIChatMessages({
323
334
  case "content":
324
335
  case "json":
325
336
  case "error-json":
326
- contentValue = JSON.stringify(output.value);
337
+ contentValue = (0, import_provider_utils2.stringifyWithBigIntAndCycles)(output.value);
327
338
  break;
328
339
  }
329
340
  messages.push({
@@ -2764,7 +2775,7 @@ async function convertToOpenAIResponsesInput({
2764
2775
  type: "function_call",
2765
2776
  call_id: part.toolCallId,
2766
2777
  name: part.toolName,
2767
- arguments: JSON.stringify(part.input),
2778
+ arguments: serializeToolCallArguments2(part.input),
2768
2779
  ...isAsync != null && { async: isAsync },
2769
2780
  id: canUseItemId ? id : void 0
2770
2781
  });
@@ -2826,7 +2837,7 @@ async function convertToOpenAIResponsesInput({
2826
2837
  } else if (reasoningMessage !== void 0) {
2827
2838
  warnings.push({
2828
2839
  type: "other",
2829
- message: `Cannot append empty reasoning part to existing reasoning sequence. Skipping reasoning part: ${JSON.stringify(part)}.`
2840
+ message: `Cannot append empty reasoning part to existing reasoning sequence. Skipping reasoning part: ${(0, import_provider_utils22.stringifyWithBigIntAndCycles)(part)}.`
2830
2841
  });
2831
2842
  }
2832
2843
  if (reasoningMessage === void 0) {
@@ -2847,7 +2858,7 @@ async function convertToOpenAIResponsesInput({
2847
2858
  } else {
2848
2859
  warnings.push({
2849
2860
  type: "other",
2850
- message: `Non-OpenAI reasoning parts are not supported. Skipping reasoning part: ${JSON.stringify(part)}.`
2861
+ message: `Non-OpenAI reasoning parts are not supported. Skipping reasoning part: ${(0, import_provider_utils22.stringifyWithBigIntAndCycles)(part)}.`
2851
2862
  });
2852
2863
  }
2853
2864
  break;
@@ -2888,10 +2899,10 @@ async function convertToOpenAIResponsesInput({
2888
2899
  break;
2889
2900
  case "json":
2890
2901
  case "error-json":
2891
- contentValue = promptCacheBreakpoint == null ? JSON.stringify(output.value) : [
2902
+ contentValue = promptCacheBreakpoint == null ? (0, import_provider_utils22.stringifyWithBigIntAndCycles)(output.value) : [
2892
2903
  {
2893
2904
  type: "input_text",
2894
- text: JSON.stringify(output.value),
2905
+ text: (0, import_provider_utils22.stringifyWithBigIntAndCycles)(output.value),
2895
2906
  prompt_cache_breakpoint: promptCacheBreakpoint
2896
2907
  }
2897
2908
  ];
@@ -2964,6 +2975,17 @@ var openaiResponsesReasoningProviderOptionsSchema = (0, import_provider_utils22.
2964
2975
  })
2965
2976
  )
2966
2977
  );
2978
+ function serializeToolCallArguments2(input) {
2979
+ if (typeof input === "string") {
2980
+ try {
2981
+ (0, import_provider_utils22.secureJsonParse)(input);
2982
+ return input;
2983
+ } catch (e) {
2984
+ return (0, import_provider_utils22.stringifyWithBigIntAndCycles)(input);
2985
+ }
2986
+ }
2987
+ return (0, import_provider_utils22.stringifyWithBigIntAndCycles)(input === void 0 ? {} : input);
2988
+ }
2967
2989
 
2968
2990
  // src/responses/map-openai-responses-finish-reason.ts
2969
2991
  function mapOpenAIResponseFinishReason({
@@ -5045,6 +5067,16 @@ var openAITranscriptionProviderOptions = (0, import_provider_utils29.lazyValidat
5045
5067
  * The language of the input audio in ISO-639-1 format.
5046
5068
  */
5047
5069
  language: import_v421.z.string().optional(),
5070
+ /**
5071
+ * Expected languages for REST transcription, e.g. with gpt-transcribe.
5072
+ * Use this instead of language. The API validates model support.
5073
+ */
5074
+ languages: import_v421.z.array(import_v421.z.string()).optional(),
5075
+ /**
5076
+ * Vocabulary hints for REST transcription, e.g. names or technical terms.
5077
+ * The API validates model support.
5078
+ */
5079
+ keywords: import_v421.z.array(import_v421.z.string()).optional(),
5048
5080
  /**
5049
5081
  * An optional text to guide the model's style or continue a previous audio segment.
5050
5082
  */
@@ -5156,6 +5188,8 @@ var OpenAITranscriptionModel = class {
5156
5188
  const transcriptionModelOptions = {
5157
5189
  include: openAIOptions.include,
5158
5190
  language: openAIOptions.language,
5191
+ languages: openAIOptions.languages,
5192
+ keywords: openAIOptions.keywords,
5159
5193
  prompt: openAIOptions.prompt,
5160
5194
  // https://platform.openai.com/docs/api-reference/audio/createTranscription#audio_createtranscription-response_format
5161
5195
  // prefer verbose_json to get segments for models that support it
@@ -5232,7 +5266,7 @@ var OpenAITranscriptionModel = class {
5232
5266
  };
5233
5267
 
5234
5268
  // src/version.ts
5235
- var VERSION = true ? "2.0.139" : "0.0.0-test";
5269
+ var VERSION = true ? "2.0.140" : "0.0.0-test";
5236
5270
 
5237
5271
  // src/openai-provider.ts
5238
5272
  function createOpenAI(options = {}) {