@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/openai",
3
- "version": "4.0.71",
3
+ "version": "4.0.72",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": false,
@@ -12,27 +12,42 @@ import {
12
12
  * names in JSON objects are always strings, so string-based constraints can be
13
13
  * left to client-side validation after removing the keyword. This
14
14
  * compatibility layer does not rewrite non-string property name schemas.
15
+ *
16
+ * OpenAI also does not support regex lookaround in JSON Schema `pattern`
17
+ * values. Those patterns are removed and left to client-side validation.
15
18
  */
16
19
  export function normalizeOpenAIJsonSchema(schema: JSONSchema7): {
17
20
  schema: JSONSchema7;
18
21
  warnings: SharedV4Warning[];
19
22
  } {
20
23
  let removedPropertyNames = false;
24
+ let removedLookaroundPattern = false;
21
25
 
22
26
  const normalizedSchema = normalizeSchema(schema);
23
27
 
28
+ const warnings: SharedV4Warning[] = [];
29
+
30
+ if (removedPropertyNames) {
31
+ warnings.push({
32
+ type: 'compatibility',
33
+ feature: 'JSON Schema propertyNames',
34
+ details:
35
+ 'OpenAI does not support JSON Schema propertyNames. It was removed before sending the schema, so OpenAI will not enforce property-name constraints.',
36
+ });
37
+ }
38
+
39
+ if (removedLookaroundPattern) {
40
+ warnings.push({
41
+ type: 'compatibility',
42
+ feature: 'JSON Schema pattern with regex lookaround',
43
+ details:
44
+ '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.',
45
+ });
46
+ }
47
+
24
48
  return {
25
49
  schema: normalizedSchema,
26
- warnings: removedPropertyNames
27
- ? [
28
- {
29
- type: 'compatibility',
30
- feature: 'JSON Schema propertyNames',
31
- details:
32
- 'OpenAI does not support JSON Schema propertyNames. It was removed before sending the schema, so OpenAI will not enforce property-name constraints.',
33
- },
34
- ]
35
- : [],
50
+ warnings,
36
51
  };
37
52
 
38
53
  function normalizeSchema(schema: JSONSchema7): JSONSchema7 {
@@ -55,6 +70,14 @@ export function normalizeOpenAIJsonSchema(schema: JSONSchema7): {
55
70
  const normalizedSchema = { ...schema };
56
71
  delete normalizedSchema.propertyNames;
57
72
 
73
+ if (
74
+ normalizedSchema.pattern != null &&
75
+ containsRegexLookaround(normalizedSchema.pattern)
76
+ ) {
77
+ delete normalizedSchema.pattern;
78
+ removedLookaroundPattern = true;
79
+ }
80
+
58
81
  if (normalizedSchema.properties != null) {
59
82
  normalizedSchema.properties = normalizeSchemaRecord(
60
83
  normalizedSchema.properties,
@@ -159,3 +182,49 @@ export function normalizeOpenAIJsonSchema(schema: JSONSchema7): {
159
182
  : normalizeSchema(definition);
160
183
  }
161
184
  }
185
+
186
+ function containsRegexLookaround(pattern: string): boolean {
187
+ let escaped = false;
188
+ let inCharacterClass = false;
189
+
190
+ for (let index = 0; index < pattern.length; index++) {
191
+ const character = pattern[index];
192
+
193
+ if (escaped) {
194
+ escaped = false;
195
+ continue;
196
+ }
197
+
198
+ if (character === '\\') {
199
+ escaped = true;
200
+ continue;
201
+ }
202
+
203
+ if (character === '[') {
204
+ inCharacterClass = true;
205
+ continue;
206
+ }
207
+
208
+ if (character === ']') {
209
+ inCharacterClass = false;
210
+ continue;
211
+ }
212
+
213
+ if (!inCharacterClass && character === '(' && pattern[index + 1] === '?') {
214
+ const lookaroundPrefix = pattern[index + 2];
215
+
216
+ if (lookaroundPrefix === '=' || lookaroundPrefix === '!') {
217
+ return true;
218
+ }
219
+
220
+ if (
221
+ lookaroundPrefix === '<' &&
222
+ (pattern[index + 3] === '=' || pattern[index + 3] === '!')
223
+ ) {
224
+ return true;
225
+ }
226
+ }
227
+ }
228
+
229
+ return false;
230
+ }
@@ -20,7 +20,7 @@ export const openaiSpeechModelOptionsSchema = lazySchema(() =>
20
20
  zodSchema(
21
21
  z.object({
22
22
  instructions: z.string().nullish(),
23
- speed: z.number().min(0.25).max(4.0).default(1.0).nullish(),
23
+ speed: z.number().min(0.25).max(4.0).nullish(),
24
24
  }),
25
25
  ),
26
26
  );
@@ -89,7 +89,10 @@ export class OpenAISpeechModel implements SpeechModelV4 {
89
89
 
90
90
  // Add provider-specific options
91
91
  if (openAIOptions) {
92
- const speechModelOptions: OpenAISpeechAPITypes = {};
92
+ const speechModelOptions: OpenAISpeechAPITypes = {
93
+ speed: openAIOptions.speed ?? undefined,
94
+ instructions: openAIOptions.instructions ?? undefined,
95
+ };
93
96
 
94
97
  for (const key in speechModelOptions) {
95
98
  const value = speechModelOptions[key as keyof OpenAISpeechAPITypes];