@ai-sdk/google 3.0.110 → 3.0.111
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 +115 -25
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +110 -18
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +107 -17
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +109 -17
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/convert-json-schema-to-openapi-schema.ts +175 -15
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 ? "3.0.
|
|
10
|
+
var VERSION = true ? "3.0.111" : "0.0.0-test";
|
|
11
11
|
|
|
12
12
|
// src/google-generative-ai-embedding-model.ts
|
|
13
13
|
import {
|
|
@@ -293,22 +293,41 @@ function convertGoogleGenerativeAIUsage(usage) {
|
|
|
293
293
|
}
|
|
294
294
|
|
|
295
295
|
// src/convert-json-schema-to-openapi-schema.ts
|
|
296
|
+
import {
|
|
297
|
+
UnsupportedFunctionalityError
|
|
298
|
+
} from "@ai-sdk/provider";
|
|
296
299
|
function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
|
|
300
|
+
const rootSchema = typeof jsonSchema === "object" ? jsonSchema : void 0;
|
|
301
|
+
return convertJSONSchemaDefinition(jsonSchema, isRoot, {
|
|
302
|
+
definitions: rootSchema == null ? void 0 : rootSchema.definitions,
|
|
303
|
+
dollarDefinitions: rootSchema == null ? void 0 : rootSchema.$defs,
|
|
304
|
+
resolvingReferences: /* @__PURE__ */ new Set()
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
function convertJSONSchemaDefinition(jsonSchema, isRoot, referenceContext) {
|
|
297
308
|
if (jsonSchema == null) {
|
|
298
309
|
return void 0;
|
|
299
310
|
}
|
|
311
|
+
if (typeof jsonSchema === "boolean") {
|
|
312
|
+
return { type: "boolean", properties: {} };
|
|
313
|
+
}
|
|
314
|
+
if (jsonSchema.$ref != null) {
|
|
315
|
+
return convertJSONSchemaReference({
|
|
316
|
+
jsonSchema,
|
|
317
|
+
reference: jsonSchema.$ref,
|
|
318
|
+
isRoot,
|
|
319
|
+
referenceContext
|
|
320
|
+
});
|
|
321
|
+
}
|
|
300
322
|
if (isEmptyObjectSchema(jsonSchema)) {
|
|
301
323
|
if (isRoot) {
|
|
302
324
|
return void 0;
|
|
303
325
|
}
|
|
304
|
-
if (
|
|
326
|
+
if (jsonSchema.description) {
|
|
305
327
|
return { type: "object", description: jsonSchema.description };
|
|
306
328
|
}
|
|
307
329
|
return { type: "object" };
|
|
308
330
|
}
|
|
309
|
-
if (typeof jsonSchema === "boolean") {
|
|
310
|
-
return { type: "boolean", properties: {} };
|
|
311
|
-
}
|
|
312
331
|
const {
|
|
313
332
|
type,
|
|
314
333
|
description,
|
|
@@ -352,18 +371,20 @@ function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
|
|
|
352
371
|
if (properties != null) {
|
|
353
372
|
result.properties = Object.entries(properties).reduce(
|
|
354
373
|
(acc, [key, value]) => {
|
|
355
|
-
acc[key] =
|
|
374
|
+
acc[key] = convertJSONSchemaDefinition(value, false, referenceContext);
|
|
356
375
|
return acc;
|
|
357
376
|
},
|
|
358
377
|
{}
|
|
359
378
|
);
|
|
360
379
|
}
|
|
361
380
|
if (items) {
|
|
362
|
-
result.items = Array.isArray(items) ? items.map(
|
|
381
|
+
result.items = Array.isArray(items) ? items.map(
|
|
382
|
+
(item) => convertJSONSchemaDefinition(item, false, referenceContext)
|
|
383
|
+
) : convertJSONSchemaDefinition(items, false, referenceContext);
|
|
363
384
|
}
|
|
364
385
|
if (allOf) {
|
|
365
386
|
result.allOf = allOf.map(
|
|
366
|
-
(item) =>
|
|
387
|
+
(item) => convertJSONSchemaDefinition(item, false, referenceContext)
|
|
367
388
|
);
|
|
368
389
|
}
|
|
369
390
|
if (anyOf) {
|
|
@@ -374,9 +395,10 @@ function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
|
|
|
374
395
|
(schema) => !(typeof schema === "object" && (schema == null ? void 0 : schema.type) === "null")
|
|
375
396
|
);
|
|
376
397
|
if (nonNullSchemas.length === 1) {
|
|
377
|
-
const converted =
|
|
398
|
+
const converted = convertJSONSchemaDefinition(
|
|
378
399
|
nonNullSchemas[0],
|
|
379
|
-
false
|
|
400
|
+
false,
|
|
401
|
+
referenceContext
|
|
380
402
|
);
|
|
381
403
|
if (typeof converted === "object") {
|
|
382
404
|
result.nullable = true;
|
|
@@ -384,19 +406,19 @@ function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
|
|
|
384
406
|
}
|
|
385
407
|
} else {
|
|
386
408
|
result.anyOf = nonNullSchemas.map(
|
|
387
|
-
(item) =>
|
|
409
|
+
(item) => convertJSONSchemaDefinition(item, false, referenceContext)
|
|
388
410
|
);
|
|
389
411
|
result.nullable = true;
|
|
390
412
|
}
|
|
391
413
|
} else {
|
|
392
414
|
result.anyOf = anyOf.map(
|
|
393
|
-
(item) =>
|
|
415
|
+
(item) => convertJSONSchemaDefinition(item, false, referenceContext)
|
|
394
416
|
);
|
|
395
417
|
}
|
|
396
418
|
}
|
|
397
419
|
if (oneOf) {
|
|
398
420
|
result.oneOf = oneOf.map(
|
|
399
|
-
(item) =>
|
|
421
|
+
(item) => convertJSONSchemaDefinition(item, false, referenceContext)
|
|
400
422
|
);
|
|
401
423
|
}
|
|
402
424
|
if (minLength !== void 0) {
|
|
@@ -404,13 +426,83 @@ function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
|
|
|
404
426
|
}
|
|
405
427
|
return result;
|
|
406
428
|
}
|
|
429
|
+
function convertJSONSchemaReference({
|
|
430
|
+
jsonSchema,
|
|
431
|
+
reference,
|
|
432
|
+
isRoot,
|
|
433
|
+
referenceContext
|
|
434
|
+
}) {
|
|
435
|
+
const { definition, referenceKey } = getReferencedDefinition(
|
|
436
|
+
reference,
|
|
437
|
+
referenceContext
|
|
438
|
+
);
|
|
439
|
+
if (referenceContext.resolvingReferences.has(referenceKey)) {
|
|
440
|
+
throw new UnsupportedFunctionalityError({
|
|
441
|
+
functionality: `recursive JSON Schema reference: ${reference}`,
|
|
442
|
+
message: "Google schema conversion does not support recursive JSON Schema references."
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
const resolvingReferences = new Set(referenceContext.resolvingReferences);
|
|
446
|
+
resolvingReferences.add(referenceKey);
|
|
447
|
+
const { $ref: _reference, ...siblingSchema } = jsonSchema;
|
|
448
|
+
const resolvedSchema = typeof definition === "boolean" ? definition ? siblingSchema : false : { ...definition, ...siblingSchema };
|
|
449
|
+
return convertJSONSchemaDefinition(resolvedSchema, isRoot, {
|
|
450
|
+
...referenceContext,
|
|
451
|
+
resolvingReferences
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
function getReferencedDefinition(reference, referenceContext) {
|
|
455
|
+
const definitionSources = [
|
|
456
|
+
{
|
|
457
|
+
prefix: "#/$defs/",
|
|
458
|
+
definitions: referenceContext.dollarDefinitions
|
|
459
|
+
},
|
|
460
|
+
{
|
|
461
|
+
prefix: "#/definitions/",
|
|
462
|
+
definitions: referenceContext.definitions
|
|
463
|
+
}
|
|
464
|
+
];
|
|
465
|
+
const source = definitionSources.find(
|
|
466
|
+
({ prefix }) => reference.startsWith(prefix)
|
|
467
|
+
);
|
|
468
|
+
const encodedDefinitionName = source ? reference.slice(source.prefix.length) : void 0;
|
|
469
|
+
if (source == null || encodedDefinitionName == null || encodedDefinitionName.length === 0 || encodedDefinitionName.includes("/")) {
|
|
470
|
+
throwUnsupportedReference(reference);
|
|
471
|
+
}
|
|
472
|
+
let decodedDefinitionName;
|
|
473
|
+
try {
|
|
474
|
+
decodedDefinitionName = decodeURIComponent(encodedDefinitionName);
|
|
475
|
+
} catch (e) {
|
|
476
|
+
throwUnsupportedReference(reference);
|
|
477
|
+
}
|
|
478
|
+
if (decodedDefinitionName.includes("/") || /~(?![01])/u.test(decodedDefinitionName) || source.definitions == null) {
|
|
479
|
+
throwUnsupportedReference(reference);
|
|
480
|
+
}
|
|
481
|
+
const definitionName = decodedDefinitionName.replace(
|
|
482
|
+
/~[01]/g,
|
|
483
|
+
(match) => match === "~1" ? "/" : "~"
|
|
484
|
+
);
|
|
485
|
+
if (!Object.prototype.hasOwnProperty.call(source.definitions, definitionName)) {
|
|
486
|
+
throwUnsupportedReference(reference);
|
|
487
|
+
}
|
|
488
|
+
return {
|
|
489
|
+
definition: source.definitions[definitionName],
|
|
490
|
+
referenceKey: `${source.prefix}${definitionName}`
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
function throwUnsupportedReference(reference) {
|
|
494
|
+
throw new UnsupportedFunctionalityError({
|
|
495
|
+
functionality: `JSON Schema reference: ${reference}`,
|
|
496
|
+
message: "Google schema conversion only supports references to direct children of root-level $defs or definitions."
|
|
497
|
+
});
|
|
498
|
+
}
|
|
407
499
|
function isEmptyObjectSchema(jsonSchema) {
|
|
408
500
|
return jsonSchema != null && typeof jsonSchema === "object" && jsonSchema.type === "object" && (jsonSchema.properties == null || Object.keys(jsonSchema.properties).length === 0) && !jsonSchema.additionalProperties;
|
|
409
501
|
}
|
|
410
502
|
|
|
411
503
|
// src/convert-to-google-generative-ai-messages.ts
|
|
412
504
|
import {
|
|
413
|
-
UnsupportedFunctionalityError
|
|
505
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
414
506
|
} from "@ai-sdk/provider";
|
|
415
507
|
import { convertToBase64, secureJsonParse } from "@ai-sdk/provider-utils";
|
|
416
508
|
var SKIP_THOUGHT_SIGNATURE_VALIDATOR = "skip_thought_signature_validator";
|
|
@@ -561,7 +653,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
561
653
|
switch (role) {
|
|
562
654
|
case "system": {
|
|
563
655
|
if (!systemMessagesAllowed) {
|
|
564
|
-
throw new
|
|
656
|
+
throw new UnsupportedFunctionalityError2({
|
|
565
657
|
functionality: "system messages are only supported at the beginning of the conversation"
|
|
566
658
|
});
|
|
567
659
|
}
|
|
@@ -626,7 +718,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
626
718
|
}
|
|
627
719
|
case "file": {
|
|
628
720
|
if (part.data instanceof URL) {
|
|
629
|
-
throw new
|
|
721
|
+
throw new UnsupportedFunctionalityError2({
|
|
630
722
|
functionality: "File data URLs in assistant messages are not supported"
|
|
631
723
|
});
|
|
632
724
|
}
|
|
@@ -999,7 +1091,7 @@ function getGoogleModelCapabilities(modelId) {
|
|
|
999
1091
|
|
|
1000
1092
|
// src/google-prepare-tools.ts
|
|
1001
1093
|
import {
|
|
1002
|
-
UnsupportedFunctionalityError as
|
|
1094
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError3
|
|
1003
1095
|
} from "@ai-sdk/provider";
|
|
1004
1096
|
function prepareTools({
|
|
1005
1097
|
tools,
|
|
@@ -1238,7 +1330,7 @@ function prepareTools({
|
|
|
1238
1330
|
};
|
|
1239
1331
|
default: {
|
|
1240
1332
|
const _exhaustiveCheck = type;
|
|
1241
|
-
throw new
|
|
1333
|
+
throw new UnsupportedFunctionalityError3({
|
|
1242
1334
|
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
1243
1335
|
});
|
|
1244
1336
|
}
|