@ai-sdk/google 3.0.114 → 3.0.116
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.d.mts +57 -3
- package/dist/index.d.ts +57 -3
- package/dist/index.js +926 -672
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +863 -601
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +65 -5
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +65 -5
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/convert-json-schema-to-openapi-schema.ts +123 -7
- package/src/google-provider.ts +24 -0
- package/src/index.ts +5 -0
- package/src/transcription/google-transcription-model-options.ts +51 -0
- package/src/transcription/google-transcription-model.ts +243 -0
package/dist/internal/index.js
CHANGED
|
@@ -127,9 +127,6 @@ function convertJSONSchemaDefinition(jsonSchema, isRoot, referenceContext) {
|
|
|
127
127
|
if (description) result.description = description;
|
|
128
128
|
if (required) result.required = required;
|
|
129
129
|
if (format) result.format = format;
|
|
130
|
-
if (constValue !== void 0) {
|
|
131
|
-
result.enum = [constValue];
|
|
132
|
-
}
|
|
133
130
|
if (type) {
|
|
134
131
|
if (Array.isArray(type)) {
|
|
135
132
|
const hasNull = type.includes("null");
|
|
@@ -146,8 +143,9 @@ function convertJSONSchemaDefinition(jsonSchema, isRoot, referenceContext) {
|
|
|
146
143
|
result.type = type;
|
|
147
144
|
}
|
|
148
145
|
}
|
|
149
|
-
|
|
150
|
-
|
|
146
|
+
const values = enumValues != null ? enumValues : constValue !== void 0 ? [constValue] : void 0;
|
|
147
|
+
if (values !== void 0) {
|
|
148
|
+
addEnumToSchema({ values, type, result });
|
|
151
149
|
}
|
|
152
150
|
if (properties != null) {
|
|
153
151
|
result.properties = Object.entries(properties).reduce(
|
|
@@ -207,6 +205,68 @@ function convertJSONSchemaDefinition(jsonSchema, isRoot, referenceContext) {
|
|
|
207
205
|
}
|
|
208
206
|
return result;
|
|
209
207
|
}
|
|
208
|
+
function addEnumToSchema({
|
|
209
|
+
values,
|
|
210
|
+
type,
|
|
211
|
+
result
|
|
212
|
+
}) {
|
|
213
|
+
const nullable = Array.isArray(type) && type.includes("null") || type === void 0 && values.includes(null);
|
|
214
|
+
const enumValues = nullable ? values.filter((value) => value !== null) : values;
|
|
215
|
+
if (values.length > 0 && values.every((value) => value === null)) {
|
|
216
|
+
const typeAllowsNull = type === void 0 || type === "null" || Array.isArray(type) && type.includes("null");
|
|
217
|
+
if (typeAllowsNull) {
|
|
218
|
+
result.type = "null";
|
|
219
|
+
if (Array.isArray(type)) {
|
|
220
|
+
delete result.anyOf;
|
|
221
|
+
}
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
const enumType = getEnumType({ values: enumValues, type });
|
|
226
|
+
if (enumType === void 0) {
|
|
227
|
+
throw new import_provider.UnsupportedFunctionalityError({
|
|
228
|
+
functionality: "JSON Schema enum with mixed or unsupported values",
|
|
229
|
+
message: "Google does not support this JSON Schema enum. Enum values must share one supported primitive type and match the schema type."
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
result.type = enumType;
|
|
233
|
+
if (Array.isArray(type)) {
|
|
234
|
+
delete result.anyOf;
|
|
235
|
+
}
|
|
236
|
+
if (nullable) {
|
|
237
|
+
result.nullable = true;
|
|
238
|
+
}
|
|
239
|
+
if (enumType === "string") {
|
|
240
|
+
result.enum = enumValues;
|
|
241
|
+
} else {
|
|
242
|
+
result.format = "enum";
|
|
243
|
+
result.enum = enumValues.map(String);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
function getEnumType({
|
|
247
|
+
values,
|
|
248
|
+
type
|
|
249
|
+
}) {
|
|
250
|
+
if (values.length === 0) {
|
|
251
|
+
return void 0;
|
|
252
|
+
}
|
|
253
|
+
const typeAllows = (enumType) => type === void 0 || type === enumType || Array.isArray(type) && type.includes(enumType);
|
|
254
|
+
if (typeAllows("string") && values.every((value) => typeof value === "string")) {
|
|
255
|
+
return "string";
|
|
256
|
+
}
|
|
257
|
+
if ((typeAllows("number") || typeAllows("integer")) && values.every((value) => typeof value === "number" && Number.isFinite(value))) {
|
|
258
|
+
if (typeAllows("number")) {
|
|
259
|
+
return "number";
|
|
260
|
+
}
|
|
261
|
+
if (values.every((value) => Number.isInteger(value))) {
|
|
262
|
+
return "integer";
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
if (typeAllows("boolean") && values.every((value) => typeof value === "boolean")) {
|
|
266
|
+
return "boolean";
|
|
267
|
+
}
|
|
268
|
+
return void 0;
|
|
269
|
+
}
|
|
210
270
|
function convertJSONSchemaReference({
|
|
211
271
|
jsonSchema,
|
|
212
272
|
reference,
|