@ai-sdk/openai 4.0.79 → 4.0.81
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 +14 -0
- package/dist/index.js +43 -5
- package/dist/index.js.map +1 -1
- package/dist/internal/index.js +41 -3
- package/dist/internal/index.js.map +1 -1
- package/package.json +2 -2
- package/src/normalize-openai-json-schema.ts +76 -3
- package/src/openai-provider.ts +1 -1
package/dist/internal/index.js
CHANGED
|
@@ -916,7 +916,7 @@ import {
|
|
|
916
916
|
function normalizeOpenAIJsonSchema(schema) {
|
|
917
917
|
let removedPropertyNames = false;
|
|
918
918
|
let removedLookaroundPattern = false;
|
|
919
|
-
const normalizedSchema = normalizeSchema(schema);
|
|
919
|
+
const normalizedSchema = normalizeSchema(schema, true);
|
|
920
920
|
const warnings = [];
|
|
921
921
|
if (removedPropertyNames) {
|
|
922
922
|
warnings.push({
|
|
@@ -936,7 +936,7 @@ function normalizeOpenAIJsonSchema(schema) {
|
|
|
936
936
|
schema: normalizedSchema,
|
|
937
937
|
warnings
|
|
938
938
|
};
|
|
939
|
-
function normalizeSchema(schema2) {
|
|
939
|
+
function normalizeSchema(schema2, isRoot = false) {
|
|
940
940
|
const propertyNames = schema2.propertyNames;
|
|
941
941
|
if (propertyNames != null) {
|
|
942
942
|
if (typeof propertyNames === "boolean" || propertyNames.type !== "string") {
|
|
@@ -1016,7 +1016,45 @@ function normalizeOpenAIJsonSchema(schema) {
|
|
|
1016
1016
|
normalizedSchema2[keyword] = normalizeDefinition(conditionalSchema);
|
|
1017
1017
|
}
|
|
1018
1018
|
}
|
|
1019
|
-
|
|
1019
|
+
const reference = getSingletonReference(normalizedSchema2);
|
|
1020
|
+
if (reference == null) {
|
|
1021
|
+
return normalizedSchema2;
|
|
1022
|
+
}
|
|
1023
|
+
const { allOf: _allOf, ...schemaWithoutAllOf } = normalizedSchema2;
|
|
1024
|
+
if (!isRoot) {
|
|
1025
|
+
return {
|
|
1026
|
+
...schemaWithoutAllOf,
|
|
1027
|
+
$ref: reference
|
|
1028
|
+
};
|
|
1029
|
+
}
|
|
1030
|
+
const referencedSchema = getLocalReferenceSchema(
|
|
1031
|
+
reference,
|
|
1032
|
+
normalizedSchema2
|
|
1033
|
+
);
|
|
1034
|
+
if (referencedSchema == null) {
|
|
1035
|
+
return normalizedSchema2;
|
|
1036
|
+
}
|
|
1037
|
+
return {
|
|
1038
|
+
...referencedSchema,
|
|
1039
|
+
...schemaWithoutAllOf
|
|
1040
|
+
};
|
|
1041
|
+
}
|
|
1042
|
+
function getSingletonReference(schema2) {
|
|
1043
|
+
if (schema2.allOf?.length !== 1) {
|
|
1044
|
+
return void 0;
|
|
1045
|
+
}
|
|
1046
|
+
const [allOfSchema] = schema2.allOf;
|
|
1047
|
+
return typeof allOfSchema === "object" && allOfSchema != null && Object.keys(allOfSchema).length === 1 && typeof allOfSchema.$ref === "string" ? allOfSchema.$ref : void 0;
|
|
1048
|
+
}
|
|
1049
|
+
function getLocalReferenceSchema(reference, schema2) {
|
|
1050
|
+
const match = /^#\/(definitions|\$defs)\/(.+)$/.exec(reference);
|
|
1051
|
+
if (match == null) {
|
|
1052
|
+
return void 0;
|
|
1053
|
+
}
|
|
1054
|
+
const [, keyword, encodedName] = match;
|
|
1055
|
+
const name = encodedName.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
1056
|
+
const definition = keyword === "definitions" ? schema2.definitions?.[name] : schema2.$defs?.[name];
|
|
1057
|
+
return typeof definition === "object" && definition != null ? definition : void 0;
|
|
1020
1058
|
}
|
|
1021
1059
|
function normalizeSchemaRecord(schemas) {
|
|
1022
1060
|
return Object.fromEntries(
|