@ai-sdk/google 2.0.88 → 2.0.89
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 +6 -0
- package/dist/index.js +109 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +111 -19
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +108 -18
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +110 -18
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from "@ai-sdk/provider-utils";
|
|
8
8
|
|
|
9
9
|
// src/version.ts
|
|
10
|
-
var VERSION = true ? "2.0.
|
|
10
|
+
var VERSION = true ? "2.0.89" : "0.0.0-test";
|
|
11
11
|
|
|
12
12
|
// src/google-generative-ai-embedding-model.ts
|
|
13
13
|
import {
|
|
@@ -246,22 +246,41 @@ import {
|
|
|
246
246
|
import { z as z5 } from "zod/v4";
|
|
247
247
|
|
|
248
248
|
// src/convert-json-schema-to-openapi-schema.ts
|
|
249
|
+
import {
|
|
250
|
+
UnsupportedFunctionalityError
|
|
251
|
+
} from "@ai-sdk/provider";
|
|
249
252
|
function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
|
|
253
|
+
const rootSchema = typeof jsonSchema === "object" ? jsonSchema : void 0;
|
|
254
|
+
return convertJSONSchemaDefinition(jsonSchema, isRoot, {
|
|
255
|
+
definitions: rootSchema == null ? void 0 : rootSchema.definitions,
|
|
256
|
+
dollarDefinitions: rootSchema == null ? void 0 : rootSchema.$defs,
|
|
257
|
+
resolvingReferences: /* @__PURE__ */ new Set()
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
function convertJSONSchemaDefinition(jsonSchema, isRoot, referenceContext) {
|
|
250
261
|
if (jsonSchema == null) {
|
|
251
262
|
return void 0;
|
|
252
263
|
}
|
|
264
|
+
if (typeof jsonSchema === "boolean") {
|
|
265
|
+
return { type: "boolean", properties: {} };
|
|
266
|
+
}
|
|
267
|
+
if (jsonSchema.$ref != null) {
|
|
268
|
+
return convertJSONSchemaReference({
|
|
269
|
+
jsonSchema,
|
|
270
|
+
reference: jsonSchema.$ref,
|
|
271
|
+
isRoot,
|
|
272
|
+
referenceContext
|
|
273
|
+
});
|
|
274
|
+
}
|
|
253
275
|
if (isEmptyObjectSchema(jsonSchema)) {
|
|
254
276
|
if (isRoot) {
|
|
255
277
|
return void 0;
|
|
256
278
|
}
|
|
257
|
-
if (
|
|
279
|
+
if (jsonSchema.description) {
|
|
258
280
|
return { type: "object", description: jsonSchema.description };
|
|
259
281
|
}
|
|
260
282
|
return { type: "object" };
|
|
261
283
|
}
|
|
262
|
-
if (typeof jsonSchema === "boolean") {
|
|
263
|
-
return { type: "boolean", properties: {} };
|
|
264
|
-
}
|
|
265
284
|
const {
|
|
266
285
|
type,
|
|
267
286
|
description,
|
|
@@ -305,18 +324,20 @@ function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
|
|
|
305
324
|
if (properties != null) {
|
|
306
325
|
result.properties = Object.entries(properties).reduce(
|
|
307
326
|
(acc, [key, value]) => {
|
|
308
|
-
acc[key] =
|
|
327
|
+
acc[key] = convertJSONSchemaDefinition(value, false, referenceContext);
|
|
309
328
|
return acc;
|
|
310
329
|
},
|
|
311
330
|
{}
|
|
312
331
|
);
|
|
313
332
|
}
|
|
314
333
|
if (items) {
|
|
315
|
-
result.items = Array.isArray(items) ? items.map(
|
|
334
|
+
result.items = Array.isArray(items) ? items.map(
|
|
335
|
+
(item) => convertJSONSchemaDefinition(item, false, referenceContext)
|
|
336
|
+
) : convertJSONSchemaDefinition(items, false, referenceContext);
|
|
316
337
|
}
|
|
317
338
|
if (allOf) {
|
|
318
339
|
result.allOf = allOf.map(
|
|
319
|
-
(item) =>
|
|
340
|
+
(item) => convertJSONSchemaDefinition(item, false, referenceContext)
|
|
320
341
|
);
|
|
321
342
|
}
|
|
322
343
|
if (anyOf) {
|
|
@@ -327,9 +348,10 @@ function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
|
|
|
327
348
|
(schema) => !(typeof schema === "object" && (schema == null ? void 0 : schema.type) === "null")
|
|
328
349
|
);
|
|
329
350
|
if (nonNullSchemas.length === 1) {
|
|
330
|
-
const converted =
|
|
351
|
+
const converted = convertJSONSchemaDefinition(
|
|
331
352
|
nonNullSchemas[0],
|
|
332
|
-
false
|
|
353
|
+
false,
|
|
354
|
+
referenceContext
|
|
333
355
|
);
|
|
334
356
|
if (typeof converted === "object") {
|
|
335
357
|
result.nullable = true;
|
|
@@ -337,19 +359,19 @@ function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
|
|
|
337
359
|
}
|
|
338
360
|
} else {
|
|
339
361
|
result.anyOf = nonNullSchemas.map(
|
|
340
|
-
(item) =>
|
|
362
|
+
(item) => convertJSONSchemaDefinition(item, false, referenceContext)
|
|
341
363
|
);
|
|
342
364
|
result.nullable = true;
|
|
343
365
|
}
|
|
344
366
|
} else {
|
|
345
367
|
result.anyOf = anyOf.map(
|
|
346
|
-
(item) =>
|
|
368
|
+
(item) => convertJSONSchemaDefinition(item, false, referenceContext)
|
|
347
369
|
);
|
|
348
370
|
}
|
|
349
371
|
}
|
|
350
372
|
if (oneOf) {
|
|
351
373
|
result.oneOf = oneOf.map(
|
|
352
|
-
(item) =>
|
|
374
|
+
(item) => convertJSONSchemaDefinition(item, false, referenceContext)
|
|
353
375
|
);
|
|
354
376
|
}
|
|
355
377
|
if (minLength !== void 0) {
|
|
@@ -357,13 +379,83 @@ function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
|
|
|
357
379
|
}
|
|
358
380
|
return result;
|
|
359
381
|
}
|
|
382
|
+
function convertJSONSchemaReference({
|
|
383
|
+
jsonSchema,
|
|
384
|
+
reference,
|
|
385
|
+
isRoot,
|
|
386
|
+
referenceContext
|
|
387
|
+
}) {
|
|
388
|
+
const { definition, referenceKey } = getReferencedDefinition(
|
|
389
|
+
reference,
|
|
390
|
+
referenceContext
|
|
391
|
+
);
|
|
392
|
+
if (referenceContext.resolvingReferences.has(referenceKey)) {
|
|
393
|
+
throw new UnsupportedFunctionalityError({
|
|
394
|
+
functionality: `recursive JSON Schema reference: ${reference}`,
|
|
395
|
+
message: "Google schema conversion does not support recursive JSON Schema references."
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
const resolvingReferences = new Set(referenceContext.resolvingReferences);
|
|
399
|
+
resolvingReferences.add(referenceKey);
|
|
400
|
+
const { $ref: _reference, ...siblingSchema } = jsonSchema;
|
|
401
|
+
const resolvedSchema = typeof definition === "boolean" ? definition ? siblingSchema : false : { ...definition, ...siblingSchema };
|
|
402
|
+
return convertJSONSchemaDefinition(resolvedSchema, isRoot, {
|
|
403
|
+
...referenceContext,
|
|
404
|
+
resolvingReferences
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
function getReferencedDefinition(reference, referenceContext) {
|
|
408
|
+
const definitionSources = [
|
|
409
|
+
{
|
|
410
|
+
prefix: "#/$defs/",
|
|
411
|
+
definitions: referenceContext.dollarDefinitions
|
|
412
|
+
},
|
|
413
|
+
{
|
|
414
|
+
prefix: "#/definitions/",
|
|
415
|
+
definitions: referenceContext.definitions
|
|
416
|
+
}
|
|
417
|
+
];
|
|
418
|
+
const source = definitionSources.find(
|
|
419
|
+
({ prefix }) => reference.startsWith(prefix)
|
|
420
|
+
);
|
|
421
|
+
const encodedDefinitionName = source ? reference.slice(source.prefix.length) : void 0;
|
|
422
|
+
if (source == null || encodedDefinitionName == null || encodedDefinitionName.length === 0 || encodedDefinitionName.includes("/")) {
|
|
423
|
+
throwUnsupportedReference(reference);
|
|
424
|
+
}
|
|
425
|
+
let decodedDefinitionName;
|
|
426
|
+
try {
|
|
427
|
+
decodedDefinitionName = decodeURIComponent(encodedDefinitionName);
|
|
428
|
+
} catch (e) {
|
|
429
|
+
throwUnsupportedReference(reference);
|
|
430
|
+
}
|
|
431
|
+
if (decodedDefinitionName.includes("/") || /~(?![01])/u.test(decodedDefinitionName) || source.definitions == null) {
|
|
432
|
+
throwUnsupportedReference(reference);
|
|
433
|
+
}
|
|
434
|
+
const definitionName = decodedDefinitionName.replace(
|
|
435
|
+
/~[01]/g,
|
|
436
|
+
(match) => match === "~1" ? "/" : "~"
|
|
437
|
+
);
|
|
438
|
+
if (!Object.prototype.hasOwnProperty.call(source.definitions, definitionName)) {
|
|
439
|
+
throwUnsupportedReference(reference);
|
|
440
|
+
}
|
|
441
|
+
return {
|
|
442
|
+
definition: source.definitions[definitionName],
|
|
443
|
+
referenceKey: `${source.prefix}${definitionName}`
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
function throwUnsupportedReference(reference) {
|
|
447
|
+
throw new UnsupportedFunctionalityError({
|
|
448
|
+
functionality: `JSON Schema reference: ${reference}`,
|
|
449
|
+
message: "Google schema conversion only supports references to direct children of root-level $defs or definitions."
|
|
450
|
+
});
|
|
451
|
+
}
|
|
360
452
|
function isEmptyObjectSchema(jsonSchema) {
|
|
361
453
|
return jsonSchema != null && typeof jsonSchema === "object" && jsonSchema.type === "object" && (jsonSchema.properties == null || Object.keys(jsonSchema.properties).length === 0) && !jsonSchema.additionalProperties;
|
|
362
454
|
}
|
|
363
455
|
|
|
364
456
|
// src/convert-to-google-generative-ai-messages.ts
|
|
365
457
|
import {
|
|
366
|
-
UnsupportedFunctionalityError
|
|
458
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
367
459
|
} from "@ai-sdk/provider";
|
|
368
460
|
import { convertToBase64 } from "@ai-sdk/provider-utils";
|
|
369
461
|
var SKIP_THOUGHT_SIGNATURE_VALIDATOR = "skip_thought_signature_validator";
|
|
@@ -379,7 +471,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
379
471
|
switch (role) {
|
|
380
472
|
case "system": {
|
|
381
473
|
if (!systemMessagesAllowed) {
|
|
382
|
-
throw new
|
|
474
|
+
throw new UnsupportedFunctionalityError2({
|
|
383
475
|
functionality: "system messages are only supported at the beginning of the conversation"
|
|
384
476
|
});
|
|
385
477
|
}
|
|
@@ -441,12 +533,12 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
441
533
|
}
|
|
442
534
|
case "file": {
|
|
443
535
|
if (part.mediaType !== "image/png") {
|
|
444
|
-
throw new
|
|
536
|
+
throw new UnsupportedFunctionalityError2({
|
|
445
537
|
functionality: "Only PNG images are supported in assistant messages"
|
|
446
538
|
});
|
|
447
539
|
}
|
|
448
540
|
if (part.data instanceof URL) {
|
|
449
|
-
throw new
|
|
541
|
+
throw new UnsupportedFunctionalityError2({
|
|
450
542
|
functionality: "File data URLs in assistant messages are not supported"
|
|
451
543
|
});
|
|
452
544
|
}
|
|
@@ -784,7 +876,7 @@ function getGoogleModelCapabilities(modelId) {
|
|
|
784
876
|
|
|
785
877
|
// src/google-prepare-tools.ts
|
|
786
878
|
import {
|
|
787
|
-
UnsupportedFunctionalityError as
|
|
879
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError3
|
|
788
880
|
} from "@ai-sdk/provider";
|
|
789
881
|
function prepareTools({
|
|
790
882
|
tools,
|
|
@@ -1023,7 +1115,7 @@ function prepareTools({
|
|
|
1023
1115
|
};
|
|
1024
1116
|
default: {
|
|
1025
1117
|
const _exhaustiveCheck = type;
|
|
1026
|
-
throw new
|
|
1118
|
+
throw new UnsupportedFunctionalityError3({
|
|
1027
1119
|
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
1028
1120
|
});
|
|
1029
1121
|
}
|