@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.
@@ -919,16 +919,26 @@ import {
919
919
  } from "@ai-sdk/provider";
920
920
  function normalizeOpenAIJsonSchema(schema) {
921
921
  let removedPropertyNames = false;
922
+ let removedLookaroundPattern = false;
922
923
  const normalizedSchema = normalizeSchema(schema);
924
+ const warnings = [];
925
+ if (removedPropertyNames) {
926
+ warnings.push({
927
+ type: "compatibility",
928
+ feature: "JSON Schema propertyNames",
929
+ details: "OpenAI does not support JSON Schema propertyNames. It was removed before sending the schema, so OpenAI will not enforce property-name constraints."
930
+ });
931
+ }
932
+ if (removedLookaroundPattern) {
933
+ warnings.push({
934
+ type: "compatibility",
935
+ feature: "JSON Schema pattern with regex lookaround",
936
+ 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."
937
+ });
938
+ }
923
939
  return {
924
940
  schema: normalizedSchema,
925
- warnings: removedPropertyNames ? [
926
- {
927
- type: "compatibility",
928
- feature: "JSON Schema propertyNames",
929
- details: "OpenAI does not support JSON Schema propertyNames. It was removed before sending the schema, so OpenAI will not enforce property-name constraints."
930
- }
931
- ] : []
941
+ warnings
932
942
  };
933
943
  function normalizeSchema(schema2) {
934
944
  const propertyNames = schema2.propertyNames;
@@ -942,6 +952,10 @@ function normalizeOpenAIJsonSchema(schema) {
942
952
  }
943
953
  const normalizedSchema2 = { ...schema2 };
944
954
  delete normalizedSchema2.propertyNames;
955
+ if (normalizedSchema2.pattern != null && containsRegexLookaround(normalizedSchema2.pattern)) {
956
+ delete normalizedSchema2.pattern;
957
+ removedLookaroundPattern = true;
958
+ }
945
959
  if (normalizedSchema2.properties != null) {
946
960
  normalizedSchema2.properties = normalizeSchemaRecord(
947
961
  normalizedSchema2.properties
@@ -1020,6 +1034,39 @@ function normalizeOpenAIJsonSchema(schema) {
1020
1034
  return typeof definition === "boolean" ? definition : normalizeSchema(definition);
1021
1035
  }
1022
1036
  }
1037
+ function containsRegexLookaround(pattern) {
1038
+ let escaped = false;
1039
+ let inCharacterClass = false;
1040
+ for (let index = 0; index < pattern.length; index++) {
1041
+ const character = pattern[index];
1042
+ if (escaped) {
1043
+ escaped = false;
1044
+ continue;
1045
+ }
1046
+ if (character === "\\") {
1047
+ escaped = true;
1048
+ continue;
1049
+ }
1050
+ if (character === "[") {
1051
+ inCharacterClass = true;
1052
+ continue;
1053
+ }
1054
+ if (character === "]") {
1055
+ inCharacterClass = false;
1056
+ continue;
1057
+ }
1058
+ if (!inCharacterClass && character === "(" && pattern[index + 1] === "?") {
1059
+ const lookaroundPrefix = pattern[index + 2];
1060
+ if (lookaroundPrefix === "=" || lookaroundPrefix === "!") {
1061
+ return true;
1062
+ }
1063
+ if (lookaroundPrefix === "<" && (pattern[index + 3] === "=" || pattern[index + 3] === "!")) {
1064
+ return true;
1065
+ }
1066
+ }
1067
+ }
1068
+ return false;
1069
+ }
1023
1070
 
1024
1071
  // src/chat/openai-chat-prepare-tools.ts
1025
1072
  function prepareChatTools({
@@ -3160,7 +3207,7 @@ var openaiSpeechModelOptionsSchema = lazySchema11(
3160
3207
  () => zodSchema11(
3161
3208
  z12.object({
3162
3209
  instructions: z12.string().nullish(),
3163
- speed: z12.number().min(0.25).max(4).default(1).nullish()
3210
+ speed: z12.number().min(0.25).max(4).nullish()
3164
3211
  })
3165
3212
  )
3166
3213
  );
@@ -3193,6 +3240,7 @@ var OpenAISpeechModel = class _OpenAISpeechModel {
3193
3240
  language,
3194
3241
  providerOptions
3195
3242
  }) {
3243
+ var _a2, _b;
3196
3244
  const warnings = [];
3197
3245
  const openAIOptions = await parseProviderOptions6({
3198
3246
  provider: "openai",
@@ -3219,7 +3267,10 @@ var OpenAISpeechModel = class _OpenAISpeechModel {
3219
3267
  }
3220
3268
  }
3221
3269
  if (openAIOptions) {
3222
- const speechModelOptions = {};
3270
+ const speechModelOptions = {
3271
+ speed: (_a2 = openAIOptions.speed) != null ? _a2 : void 0,
3272
+ instructions: (_b = openAIOptions.instructions) != null ? _b : void 0
3273
+ };
3223
3274
  for (const key in speechModelOptions) {
3224
3275
  const value = speechModelOptions[key];
3225
3276
  if (value !== void 0) {