@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/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -30,7 +30,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
30
30
|
var import_provider_utils15 = require("@ai-sdk/provider-utils");
|
|
31
31
|
|
|
32
32
|
// src/version.ts
|
|
33
|
-
var VERSION = true ? "2.0.
|
|
33
|
+
var VERSION = true ? "2.0.89" : "0.0.0-test";
|
|
34
34
|
|
|
35
35
|
// src/google-generative-ai-embedding-model.ts
|
|
36
36
|
var import_provider = require("@ai-sdk/provider");
|
|
@@ -242,22 +242,39 @@ var import_provider_utils6 = require("@ai-sdk/provider-utils");
|
|
|
242
242
|
var import_v45 = require("zod/v4");
|
|
243
243
|
|
|
244
244
|
// src/convert-json-schema-to-openapi-schema.ts
|
|
245
|
+
var import_provider2 = require("@ai-sdk/provider");
|
|
245
246
|
function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
|
|
247
|
+
const rootSchema = typeof jsonSchema === "object" ? jsonSchema : void 0;
|
|
248
|
+
return convertJSONSchemaDefinition(jsonSchema, isRoot, {
|
|
249
|
+
definitions: rootSchema == null ? void 0 : rootSchema.definitions,
|
|
250
|
+
dollarDefinitions: rootSchema == null ? void 0 : rootSchema.$defs,
|
|
251
|
+
resolvingReferences: /* @__PURE__ */ new Set()
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
function convertJSONSchemaDefinition(jsonSchema, isRoot, referenceContext) {
|
|
246
255
|
if (jsonSchema == null) {
|
|
247
256
|
return void 0;
|
|
248
257
|
}
|
|
258
|
+
if (typeof jsonSchema === "boolean") {
|
|
259
|
+
return { type: "boolean", properties: {} };
|
|
260
|
+
}
|
|
261
|
+
if (jsonSchema.$ref != null) {
|
|
262
|
+
return convertJSONSchemaReference({
|
|
263
|
+
jsonSchema,
|
|
264
|
+
reference: jsonSchema.$ref,
|
|
265
|
+
isRoot,
|
|
266
|
+
referenceContext
|
|
267
|
+
});
|
|
268
|
+
}
|
|
249
269
|
if (isEmptyObjectSchema(jsonSchema)) {
|
|
250
270
|
if (isRoot) {
|
|
251
271
|
return void 0;
|
|
252
272
|
}
|
|
253
|
-
if (
|
|
273
|
+
if (jsonSchema.description) {
|
|
254
274
|
return { type: "object", description: jsonSchema.description };
|
|
255
275
|
}
|
|
256
276
|
return { type: "object" };
|
|
257
277
|
}
|
|
258
|
-
if (typeof jsonSchema === "boolean") {
|
|
259
|
-
return { type: "boolean", properties: {} };
|
|
260
|
-
}
|
|
261
278
|
const {
|
|
262
279
|
type,
|
|
263
280
|
description,
|
|
@@ -301,18 +318,20 @@ function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
|
|
|
301
318
|
if (properties != null) {
|
|
302
319
|
result.properties = Object.entries(properties).reduce(
|
|
303
320
|
(acc, [key, value]) => {
|
|
304
|
-
acc[key] =
|
|
321
|
+
acc[key] = convertJSONSchemaDefinition(value, false, referenceContext);
|
|
305
322
|
return acc;
|
|
306
323
|
},
|
|
307
324
|
{}
|
|
308
325
|
);
|
|
309
326
|
}
|
|
310
327
|
if (items) {
|
|
311
|
-
result.items = Array.isArray(items) ? items.map(
|
|
328
|
+
result.items = Array.isArray(items) ? items.map(
|
|
329
|
+
(item) => convertJSONSchemaDefinition(item, false, referenceContext)
|
|
330
|
+
) : convertJSONSchemaDefinition(items, false, referenceContext);
|
|
312
331
|
}
|
|
313
332
|
if (allOf) {
|
|
314
333
|
result.allOf = allOf.map(
|
|
315
|
-
(item) =>
|
|
334
|
+
(item) => convertJSONSchemaDefinition(item, false, referenceContext)
|
|
316
335
|
);
|
|
317
336
|
}
|
|
318
337
|
if (anyOf) {
|
|
@@ -323,9 +342,10 @@ function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
|
|
|
323
342
|
(schema) => !(typeof schema === "object" && (schema == null ? void 0 : schema.type) === "null")
|
|
324
343
|
);
|
|
325
344
|
if (nonNullSchemas.length === 1) {
|
|
326
|
-
const converted =
|
|
345
|
+
const converted = convertJSONSchemaDefinition(
|
|
327
346
|
nonNullSchemas[0],
|
|
328
|
-
false
|
|
347
|
+
false,
|
|
348
|
+
referenceContext
|
|
329
349
|
);
|
|
330
350
|
if (typeof converted === "object") {
|
|
331
351
|
result.nullable = true;
|
|
@@ -333,19 +353,19 @@ function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
|
|
|
333
353
|
}
|
|
334
354
|
} else {
|
|
335
355
|
result.anyOf = nonNullSchemas.map(
|
|
336
|
-
(item) =>
|
|
356
|
+
(item) => convertJSONSchemaDefinition(item, false, referenceContext)
|
|
337
357
|
);
|
|
338
358
|
result.nullable = true;
|
|
339
359
|
}
|
|
340
360
|
} else {
|
|
341
361
|
result.anyOf = anyOf.map(
|
|
342
|
-
(item) =>
|
|
362
|
+
(item) => convertJSONSchemaDefinition(item, false, referenceContext)
|
|
343
363
|
);
|
|
344
364
|
}
|
|
345
365
|
}
|
|
346
366
|
if (oneOf) {
|
|
347
367
|
result.oneOf = oneOf.map(
|
|
348
|
-
(item) =>
|
|
368
|
+
(item) => convertJSONSchemaDefinition(item, false, referenceContext)
|
|
349
369
|
);
|
|
350
370
|
}
|
|
351
371
|
if (minLength !== void 0) {
|
|
@@ -353,12 +373,82 @@ function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
|
|
|
353
373
|
}
|
|
354
374
|
return result;
|
|
355
375
|
}
|
|
376
|
+
function convertJSONSchemaReference({
|
|
377
|
+
jsonSchema,
|
|
378
|
+
reference,
|
|
379
|
+
isRoot,
|
|
380
|
+
referenceContext
|
|
381
|
+
}) {
|
|
382
|
+
const { definition, referenceKey } = getReferencedDefinition(
|
|
383
|
+
reference,
|
|
384
|
+
referenceContext
|
|
385
|
+
);
|
|
386
|
+
if (referenceContext.resolvingReferences.has(referenceKey)) {
|
|
387
|
+
throw new import_provider2.UnsupportedFunctionalityError({
|
|
388
|
+
functionality: `recursive JSON Schema reference: ${reference}`,
|
|
389
|
+
message: "Google schema conversion does not support recursive JSON Schema references."
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
const resolvingReferences = new Set(referenceContext.resolvingReferences);
|
|
393
|
+
resolvingReferences.add(referenceKey);
|
|
394
|
+
const { $ref: _reference, ...siblingSchema } = jsonSchema;
|
|
395
|
+
const resolvedSchema = typeof definition === "boolean" ? definition ? siblingSchema : false : { ...definition, ...siblingSchema };
|
|
396
|
+
return convertJSONSchemaDefinition(resolvedSchema, isRoot, {
|
|
397
|
+
...referenceContext,
|
|
398
|
+
resolvingReferences
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
function getReferencedDefinition(reference, referenceContext) {
|
|
402
|
+
const definitionSources = [
|
|
403
|
+
{
|
|
404
|
+
prefix: "#/$defs/",
|
|
405
|
+
definitions: referenceContext.dollarDefinitions
|
|
406
|
+
},
|
|
407
|
+
{
|
|
408
|
+
prefix: "#/definitions/",
|
|
409
|
+
definitions: referenceContext.definitions
|
|
410
|
+
}
|
|
411
|
+
];
|
|
412
|
+
const source = definitionSources.find(
|
|
413
|
+
({ prefix }) => reference.startsWith(prefix)
|
|
414
|
+
);
|
|
415
|
+
const encodedDefinitionName = source ? reference.slice(source.prefix.length) : void 0;
|
|
416
|
+
if (source == null || encodedDefinitionName == null || encodedDefinitionName.length === 0 || encodedDefinitionName.includes("/")) {
|
|
417
|
+
throwUnsupportedReference(reference);
|
|
418
|
+
}
|
|
419
|
+
let decodedDefinitionName;
|
|
420
|
+
try {
|
|
421
|
+
decodedDefinitionName = decodeURIComponent(encodedDefinitionName);
|
|
422
|
+
} catch (e) {
|
|
423
|
+
throwUnsupportedReference(reference);
|
|
424
|
+
}
|
|
425
|
+
if (decodedDefinitionName.includes("/") || /~(?![01])/u.test(decodedDefinitionName) || source.definitions == null) {
|
|
426
|
+
throwUnsupportedReference(reference);
|
|
427
|
+
}
|
|
428
|
+
const definitionName = decodedDefinitionName.replace(
|
|
429
|
+
/~[01]/g,
|
|
430
|
+
(match) => match === "~1" ? "/" : "~"
|
|
431
|
+
);
|
|
432
|
+
if (!Object.prototype.hasOwnProperty.call(source.definitions, definitionName)) {
|
|
433
|
+
throwUnsupportedReference(reference);
|
|
434
|
+
}
|
|
435
|
+
return {
|
|
436
|
+
definition: source.definitions[definitionName],
|
|
437
|
+
referenceKey: `${source.prefix}${definitionName}`
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
function throwUnsupportedReference(reference) {
|
|
441
|
+
throw new import_provider2.UnsupportedFunctionalityError({
|
|
442
|
+
functionality: `JSON Schema reference: ${reference}`,
|
|
443
|
+
message: "Google schema conversion only supports references to direct children of root-level $defs or definitions."
|
|
444
|
+
});
|
|
445
|
+
}
|
|
356
446
|
function isEmptyObjectSchema(jsonSchema) {
|
|
357
447
|
return jsonSchema != null && typeof jsonSchema === "object" && jsonSchema.type === "object" && (jsonSchema.properties == null || Object.keys(jsonSchema.properties).length === 0) && !jsonSchema.additionalProperties;
|
|
358
448
|
}
|
|
359
449
|
|
|
360
450
|
// src/convert-to-google-generative-ai-messages.ts
|
|
361
|
-
var
|
|
451
|
+
var import_provider3 = require("@ai-sdk/provider");
|
|
362
452
|
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
|
363
453
|
var SKIP_THOUGHT_SIGNATURE_VALIDATOR = "skip_thought_signature_validator";
|
|
364
454
|
function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
@@ -373,7 +463,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
373
463
|
switch (role) {
|
|
374
464
|
case "system": {
|
|
375
465
|
if (!systemMessagesAllowed) {
|
|
376
|
-
throw new
|
|
466
|
+
throw new import_provider3.UnsupportedFunctionalityError({
|
|
377
467
|
functionality: "system messages are only supported at the beginning of the conversation"
|
|
378
468
|
});
|
|
379
469
|
}
|
|
@@ -435,12 +525,12 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
435
525
|
}
|
|
436
526
|
case "file": {
|
|
437
527
|
if (part.mediaType !== "image/png") {
|
|
438
|
-
throw new
|
|
528
|
+
throw new import_provider3.UnsupportedFunctionalityError({
|
|
439
529
|
functionality: "Only PNG images are supported in assistant messages"
|
|
440
530
|
});
|
|
441
531
|
}
|
|
442
532
|
if (part.data instanceof URL) {
|
|
443
|
-
throw new
|
|
533
|
+
throw new import_provider3.UnsupportedFunctionalityError({
|
|
444
534
|
functionality: "File data URLs in assistant messages are not supported"
|
|
445
535
|
});
|
|
446
536
|
}
|
|
@@ -774,7 +864,7 @@ function getGoogleModelCapabilities(modelId) {
|
|
|
774
864
|
}
|
|
775
865
|
|
|
776
866
|
// src/google-prepare-tools.ts
|
|
777
|
-
var
|
|
867
|
+
var import_provider4 = require("@ai-sdk/provider");
|
|
778
868
|
function prepareTools({
|
|
779
869
|
tools,
|
|
780
870
|
toolChoice,
|
|
@@ -1012,7 +1102,7 @@ function prepareTools({
|
|
|
1012
1102
|
};
|
|
1013
1103
|
default: {
|
|
1014
1104
|
const _exhaustiveCheck = type;
|
|
1015
|
-
throw new
|
|
1105
|
+
throw new import_provider4.UnsupportedFunctionalityError({
|
|
1016
1106
|
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
1017
1107
|
});
|
|
1018
1108
|
}
|