@ai-sdk/openai 4.0.71 → 4.0.72

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,12 @@
1
1
  # @ai-sdk/openai
2
2
 
3
+ ## 4.0.72
4
+
5
+ ### Patch Changes
6
+
7
+ - 411b3f2: fix(openai): strip unsupported regex patterns from JSON schemas
8
+ - e13c32f: fix(openai): include speech provider options in requests
9
+
3
10
  ## 4.0.71
4
11
 
5
12
  ### Patch Changes
package/dist/index.js CHANGED
@@ -929,16 +929,26 @@ import {
929
929
  } from "@ai-sdk/provider";
930
930
  function normalizeOpenAIJsonSchema(schema) {
931
931
  let removedPropertyNames = false;
932
+ let removedLookaroundPattern = false;
932
933
  const normalizedSchema = normalizeSchema(schema);
934
+ const warnings = [];
935
+ if (removedPropertyNames) {
936
+ warnings.push({
937
+ type: "compatibility",
938
+ feature: "JSON Schema propertyNames",
939
+ details: "OpenAI does not support JSON Schema propertyNames. It was removed before sending the schema, so OpenAI will not enforce property-name constraints."
940
+ });
941
+ }
942
+ if (removedLookaroundPattern) {
943
+ warnings.push({
944
+ type: "compatibility",
945
+ feature: "JSON Schema pattern with regex lookaround",
946
+ details: "OpenAI does not support regex lookaround in JSON Schema patterns. The pattern was removed before sending the schema, so OpenAI will not enforce that constraint."
947
+ });
948
+ }
933
949
  return {
934
950
  schema: normalizedSchema,
935
- warnings: removedPropertyNames ? [
936
- {
937
- type: "compatibility",
938
- feature: "JSON Schema propertyNames",
939
- details: "OpenAI does not support JSON Schema propertyNames. It was removed before sending the schema, so OpenAI will not enforce property-name constraints."
940
- }
941
- ] : []
951
+ warnings
942
952
  };
943
953
  function normalizeSchema(schema2) {
944
954
  const propertyNames = schema2.propertyNames;
@@ -952,6 +962,10 @@ function normalizeOpenAIJsonSchema(schema) {
952
962
  }
953
963
  const normalizedSchema2 = { ...schema2 };
954
964
  delete normalizedSchema2.propertyNames;
965
+ if (normalizedSchema2.pattern != null && containsRegexLookaround(normalizedSchema2.pattern)) {
966
+ delete normalizedSchema2.pattern;
967
+ removedLookaroundPattern = true;
968
+ }
955
969
  if (normalizedSchema2.properties != null) {
956
970
  normalizedSchema2.properties = normalizeSchemaRecord(
957
971
  normalizedSchema2.properties
@@ -1030,6 +1044,39 @@ function normalizeOpenAIJsonSchema(schema) {
1030
1044
  return typeof definition === "boolean" ? definition : normalizeSchema(definition);
1031
1045
  }
1032
1046
  }
1047
+ function containsRegexLookaround(pattern) {
1048
+ let escaped = false;
1049
+ let inCharacterClass = false;
1050
+ for (let index = 0; index < pattern.length; index++) {
1051
+ const character = pattern[index];
1052
+ if (escaped) {
1053
+ escaped = false;
1054
+ continue;
1055
+ }
1056
+ if (character === "\\") {
1057
+ escaped = true;
1058
+ continue;
1059
+ }
1060
+ if (character === "[") {
1061
+ inCharacterClass = true;
1062
+ continue;
1063
+ }
1064
+ if (character === "]") {
1065
+ inCharacterClass = false;
1066
+ continue;
1067
+ }
1068
+ if (!inCharacterClass && character === "(" && pattern[index + 1] === "?") {
1069
+ const lookaroundPrefix = pattern[index + 2];
1070
+ if (lookaroundPrefix === "=" || lookaroundPrefix === "!") {
1071
+ return true;
1072
+ }
1073
+ if (lookaroundPrefix === "<" && (pattern[index + 3] === "=" || pattern[index + 3] === "!")) {
1074
+ return true;
1075
+ }
1076
+ }
1077
+ }
1078
+ return false;
1079
+ }
1033
1080
 
1034
1081
  // src/chat/openai-chat-prepare-tools.ts
1035
1082
  function prepareChatTools({
@@ -10852,7 +10899,7 @@ var openaiSpeechModelOptionsSchema = lazySchema27(
10852
10899
  () => zodSchema27(
10853
10900
  z33.object({
10854
10901
  instructions: z33.string().nullish(),
10855
- speed: z33.number().min(0.25).max(4).default(1).nullish()
10902
+ speed: z33.number().min(0.25).max(4).nullish()
10856
10903
  })
10857
10904
  )
10858
10905
  );
@@ -10885,6 +10932,7 @@ var OpenAISpeechModel = class _OpenAISpeechModel {
10885
10932
  language,
10886
10933
  providerOptions
10887
10934
  }) {
10935
+ var _a2, _b;
10888
10936
  const warnings = [];
10889
10937
  const openAIOptions = await parseProviderOptions9({
10890
10938
  provider: "openai",
@@ -10911,7 +10959,10 @@ var OpenAISpeechModel = class _OpenAISpeechModel {
10911
10959
  }
10912
10960
  }
10913
10961
  if (openAIOptions) {
10914
- const speechModelOptions = {};
10962
+ const speechModelOptions = {
10963
+ speed: (_a2 = openAIOptions.speed) != null ? _a2 : void 0,
10964
+ instructions: (_b = openAIOptions.instructions) != null ? _b : void 0
10965
+ };
10915
10966
  for (const key in speechModelOptions) {
10916
10967
  const value = speechModelOptions[key];
10917
10968
  if (value !== void 0) {
@@ -11967,7 +12018,7 @@ var OpenAISkills = class {
11967
12018
  };
11968
12019
 
11969
12020
  // src/version.ts
11970
- var VERSION = true ? "4.0.71" : "0.0.0-test";
12021
+ var VERSION = true ? "4.0.72" : "0.0.0-test";
11971
12022
 
11972
12023
  // src/openai-provider.ts
11973
12024
  function createOpenAI(options = {}) {