@ai-sdk/openai 4.0.70 → 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 +17 -0
- package/dist/index.js +65 -14
- package/dist/index.js.map +1 -1
- package/dist/internal/index.js +64 -13
- package/dist/internal/index.js.map +1 -1
- package/package.json +2 -2
- package/src/image/openai-image-model.ts +4 -3
- package/src/normalize-openai-json-schema.ts +79 -10
- package/src/speech/openai-speech-model-options.ts +1 -1
- package/src/speech/openai-speech-model.ts +4 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
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
|
+
|
|
10
|
+
## 4.0.71
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- e76a0a3: fix(openai): cancel image edit URL downloads when the request is aborted
|
|
15
|
+
- Updated dependencies [2973485]
|
|
16
|
+
- Updated dependencies [a4db5ea]
|
|
17
|
+
- Updated dependencies [2937ea2]
|
|
18
|
+
- @ai-sdk/provider-utils@5.0.45
|
|
19
|
+
|
|
3
20
|
## 4.0.70
|
|
4
21
|
|
|
5
22
|
### 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
|
|
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({
|
|
@@ -2680,10 +2727,10 @@ var OpenAIImageModel = class _OpenAIImageModel {
|
|
|
2680
2727
|
})
|
|
2681
2728
|
],
|
|
2682
2729
|
{ type: file.mediaType }
|
|
2683
|
-
) : downloadBlob(file.url)
|
|
2730
|
+
) : downloadBlob(file.url, { abortSignal })
|
|
2684
2731
|
)
|
|
2685
2732
|
),
|
|
2686
|
-
mask: mask != null ? await fileToBlob(mask) : void 0,
|
|
2733
|
+
mask: mask != null ? await fileToBlob(mask, abortSignal) : void 0,
|
|
2687
2734
|
n,
|
|
2688
2735
|
size,
|
|
2689
2736
|
quality: openaiOptions2.quality,
|
|
@@ -2820,10 +2867,10 @@ function distributeTokenDetails(details, index, total) {
|
|
|
2820
2867
|
}
|
|
2821
2868
|
return result;
|
|
2822
2869
|
}
|
|
2823
|
-
async function fileToBlob(file) {
|
|
2870
|
+
async function fileToBlob(file, abortSignal) {
|
|
2824
2871
|
if (!file) return void 0;
|
|
2825
2872
|
if (file.type === "url") {
|
|
2826
|
-
return downloadBlob(file.url);
|
|
2873
|
+
return downloadBlob(file.url, { abortSignal });
|
|
2827
2874
|
}
|
|
2828
2875
|
const data = file.data instanceof Uint8Array ? file.data : convertBase64ToUint8Array(file.data);
|
|
2829
2876
|
return new Blob([data], { type: file.mediaType });
|
|
@@ -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).
|
|
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.
|
|
12021
|
+
var VERSION = true ? "4.0.72" : "0.0.0-test";
|
|
11971
12022
|
|
|
11972
12023
|
// src/openai-provider.ts
|
|
11973
12024
|
function createOpenAI(options = {}) {
|