@depup/ai-sdk__google 4.0.69-depup.0 → 4.0.70-depup.0
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 +19 -0
- package/README.md +2 -2
- package/changes.json +1 -1
- package/dist/index.js +66 -314
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +2 -3
- package/dist/internal/index.js +52 -307
- package/dist/internal/index.js.map +1 -1
- package/package.json +3 -3
- package/src/google-language-model.ts +5 -5
- package/src/google-prepare-tools.ts +3 -23
- package/src/realtime/google-realtime-event-mapper.ts +24 -3
- package/src/sanitize-response-json-schema.ts +65 -0
- package/src/convert-json-schema-to-openapi-schema.ts +0 -456
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @ai-sdk/google
|
|
2
2
|
|
|
3
|
+
## 4.0.70
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 2a32459: fix(google): preserve JSON Schema instead of converting to OpenAPI schema
|
|
8
|
+
- d93e295: fix(google): keep a realtime `functionResponse.response` an object
|
|
9
|
+
|
|
10
|
+
Gemini types that field as a `google.protobuf.Struct`, which accepts an object and
|
|
11
|
+
nothing else. `onToolCall` returns `unknown` and `addToolOutput` takes `unknown`, so a
|
|
12
|
+
string, number, array or `null` tool result reached the wire unwrapped, Gemini closed
|
|
13
|
+
the socket with `1007`, and the close code was dropped on the way back so the
|
|
14
|
+
application saw a plain disconnect. A non-object result is now wrapped under the
|
|
15
|
+
`output` key the field's own docstring prescribes; an object is passed through
|
|
16
|
+
unchanged, as before.
|
|
17
|
+
|
|
18
|
+
An `output` that is not valid JSON no longer becomes `{}`. That branch told the model
|
|
19
|
+
the tool had returned an empty object, with nothing thrown and the socket still up, so
|
|
20
|
+
the answer was wrong with nothing to notice. The text is kept instead.
|
|
21
|
+
|
|
3
22
|
## 4.0.69
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -13,8 +13,8 @@ npm install @depup/ai-sdk__google
|
|
|
13
13
|
|
|
14
14
|
| Field | Value |
|
|
15
15
|
|-------|-------|
|
|
16
|
-
| Original | [@ai-sdk/google](https://www.npmjs.com/package/@ai-sdk/google) @ 4.0.
|
|
17
|
-
| Processed | 2026-09-
|
|
16
|
+
| Original | [@ai-sdk/google](https://www.npmjs.com/package/@ai-sdk/google) @ 4.0.70 |
|
|
17
|
+
| Processed | 2026-09-15 |
|
|
18
18
|
| Smoke test | failed |
|
|
19
19
|
| Deps updated | 0 |
|
|
20
20
|
|
package/changes.json
CHANGED
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from "@ai-sdk/provider-utils";
|
|
8
8
|
|
|
9
9
|
// src/version.ts
|
|
10
|
-
var VERSION = true ? "4.0.
|
|
10
|
+
var VERSION = true ? "4.0.70" : "0.0.0-test";
|
|
11
11
|
|
|
12
12
|
// src/google-embedding-model.ts
|
|
13
13
|
import {
|
|
@@ -255,7 +255,7 @@ var googleGenerativeAISingleEmbeddingResponseSchema = lazySchema3(
|
|
|
255
255
|
import {
|
|
256
256
|
InvalidArgumentError,
|
|
257
257
|
InvalidResponseDataError,
|
|
258
|
-
UnsupportedFunctionalityError as
|
|
258
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError3
|
|
259
259
|
} from "@ai-sdk/provider";
|
|
260
260
|
import {
|
|
261
261
|
combineHeaders as combineHeaders3,
|
|
@@ -329,289 +329,9 @@ function convertGoogleUsage(usage) {
|
|
|
329
329
|
};
|
|
330
330
|
}
|
|
331
331
|
|
|
332
|
-
// src/convert-json-schema-to-openapi-schema.ts
|
|
333
|
-
import {
|
|
334
|
-
UnsupportedFunctionalityError
|
|
335
|
-
} from "@ai-sdk/provider";
|
|
336
|
-
var recursiveReferenceFunctionalityPrefix = "recursive JSON Schema reference:";
|
|
337
|
-
function isRecursiveJSONSchemaReferenceError(error) {
|
|
338
|
-
return UnsupportedFunctionalityError.isInstance(error) && error.functionality.startsWith(recursiveReferenceFunctionalityPrefix);
|
|
339
|
-
}
|
|
340
|
-
function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
|
|
341
|
-
const rootSchema = typeof jsonSchema === "object" ? jsonSchema : void 0;
|
|
342
|
-
return convertJSONSchemaDefinition(jsonSchema, isRoot, {
|
|
343
|
-
definitions: rootSchema == null ? void 0 : rootSchema.definitions,
|
|
344
|
-
dollarDefinitions: rootSchema == null ? void 0 : rootSchema.$defs,
|
|
345
|
-
resolvingReferences: /* @__PURE__ */ new Set()
|
|
346
|
-
});
|
|
347
|
-
}
|
|
348
|
-
function convertJSONSchemaDefinition(jsonSchema, isRoot, referenceContext) {
|
|
349
|
-
if (jsonSchema == null) {
|
|
350
|
-
return void 0;
|
|
351
|
-
}
|
|
352
|
-
if (typeof jsonSchema === "boolean") {
|
|
353
|
-
return { type: "boolean", properties: {} };
|
|
354
|
-
}
|
|
355
|
-
if (jsonSchema.$ref != null) {
|
|
356
|
-
return convertJSONSchemaReference({
|
|
357
|
-
jsonSchema,
|
|
358
|
-
reference: jsonSchema.$ref,
|
|
359
|
-
isRoot,
|
|
360
|
-
referenceContext
|
|
361
|
-
});
|
|
362
|
-
}
|
|
363
|
-
if (isEmptyObjectSchema(jsonSchema)) {
|
|
364
|
-
if (isRoot) {
|
|
365
|
-
return void 0;
|
|
366
|
-
}
|
|
367
|
-
if (jsonSchema.description) {
|
|
368
|
-
return { type: "object", description: jsonSchema.description };
|
|
369
|
-
}
|
|
370
|
-
return { type: "object" };
|
|
371
|
-
}
|
|
372
|
-
const {
|
|
373
|
-
type,
|
|
374
|
-
description,
|
|
375
|
-
required,
|
|
376
|
-
properties,
|
|
377
|
-
items,
|
|
378
|
-
allOf,
|
|
379
|
-
anyOf,
|
|
380
|
-
oneOf,
|
|
381
|
-
format,
|
|
382
|
-
const: constValue,
|
|
383
|
-
minLength,
|
|
384
|
-
minItems,
|
|
385
|
-
maxItems,
|
|
386
|
-
enum: enumValues
|
|
387
|
-
} = jsonSchema;
|
|
388
|
-
const result = {};
|
|
389
|
-
if (description) result.description = description;
|
|
390
|
-
if (required) result.required = required;
|
|
391
|
-
if (format) result.format = format;
|
|
392
|
-
if (type) {
|
|
393
|
-
if (Array.isArray(type)) {
|
|
394
|
-
const hasNull = type.includes("null");
|
|
395
|
-
const nonNullTypes = type.filter((t) => t !== "null");
|
|
396
|
-
if (nonNullTypes.length === 0) {
|
|
397
|
-
result.type = "null";
|
|
398
|
-
} else {
|
|
399
|
-
result.anyOf = nonNullTypes.map((t) => ({ type: t }));
|
|
400
|
-
if (hasNull) {
|
|
401
|
-
result.nullable = true;
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
} else {
|
|
405
|
-
result.type = type;
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
const values = enumValues != null ? enumValues : constValue !== void 0 ? [constValue] : void 0;
|
|
409
|
-
if (values !== void 0) {
|
|
410
|
-
addEnumToSchema({ values, type, result });
|
|
411
|
-
}
|
|
412
|
-
if (properties != null) {
|
|
413
|
-
result.properties = Object.entries(properties).reduce(
|
|
414
|
-
(acc, [key, value]) => {
|
|
415
|
-
acc[key] = convertJSONSchemaDefinition(value, false, referenceContext);
|
|
416
|
-
return acc;
|
|
417
|
-
},
|
|
418
|
-
{}
|
|
419
|
-
);
|
|
420
|
-
}
|
|
421
|
-
if (items) {
|
|
422
|
-
result.items = Array.isArray(items) ? items.map(
|
|
423
|
-
(item) => convertJSONSchemaDefinition(item, false, referenceContext)
|
|
424
|
-
) : convertJSONSchemaDefinition(items, false, referenceContext);
|
|
425
|
-
}
|
|
426
|
-
if (allOf) {
|
|
427
|
-
result.allOf = allOf.map(
|
|
428
|
-
(item) => convertJSONSchemaDefinition(item, false, referenceContext)
|
|
429
|
-
);
|
|
430
|
-
}
|
|
431
|
-
if (anyOf) {
|
|
432
|
-
if (anyOf.some(
|
|
433
|
-
(schema) => typeof schema === "object" && (schema == null ? void 0 : schema.type) === "null"
|
|
434
|
-
)) {
|
|
435
|
-
const nonNullSchemas = anyOf.filter(
|
|
436
|
-
(schema) => !(typeof schema === "object" && (schema == null ? void 0 : schema.type) === "null")
|
|
437
|
-
);
|
|
438
|
-
if (nonNullSchemas.length === 1) {
|
|
439
|
-
const converted = convertJSONSchemaDefinition(
|
|
440
|
-
nonNullSchemas[0],
|
|
441
|
-
false,
|
|
442
|
-
referenceContext
|
|
443
|
-
);
|
|
444
|
-
if (typeof converted === "object") {
|
|
445
|
-
result.nullable = true;
|
|
446
|
-
Object.assign(result, converted);
|
|
447
|
-
}
|
|
448
|
-
} else {
|
|
449
|
-
result.anyOf = nonNullSchemas.map(
|
|
450
|
-
(item) => convertJSONSchemaDefinition(item, false, referenceContext)
|
|
451
|
-
);
|
|
452
|
-
result.nullable = true;
|
|
453
|
-
}
|
|
454
|
-
} else {
|
|
455
|
-
result.anyOf = anyOf.map(
|
|
456
|
-
(item) => convertJSONSchemaDefinition(item, false, referenceContext)
|
|
457
|
-
);
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
if (oneOf) {
|
|
461
|
-
result.oneOf = oneOf.map(
|
|
462
|
-
(item) => convertJSONSchemaDefinition(item, false, referenceContext)
|
|
463
|
-
);
|
|
464
|
-
}
|
|
465
|
-
if (minLength !== void 0) {
|
|
466
|
-
result.minLength = minLength;
|
|
467
|
-
}
|
|
468
|
-
if (minItems !== void 0) {
|
|
469
|
-
result.minItems = minItems;
|
|
470
|
-
}
|
|
471
|
-
if (maxItems !== void 0) {
|
|
472
|
-
result.maxItems = maxItems;
|
|
473
|
-
}
|
|
474
|
-
return result;
|
|
475
|
-
}
|
|
476
|
-
function convertJSONSchemaReference({
|
|
477
|
-
jsonSchema,
|
|
478
|
-
reference,
|
|
479
|
-
isRoot,
|
|
480
|
-
referenceContext
|
|
481
|
-
}) {
|
|
482
|
-
const { definition, referenceKey } = getReferencedDefinition(
|
|
483
|
-
reference,
|
|
484
|
-
referenceContext
|
|
485
|
-
);
|
|
486
|
-
if (referenceContext.resolvingReferences.has(referenceKey)) {
|
|
487
|
-
throw new UnsupportedFunctionalityError({
|
|
488
|
-
functionality: `${recursiveReferenceFunctionalityPrefix} ${reference}`,
|
|
489
|
-
message: "Google schema conversion does not support recursive JSON Schema references."
|
|
490
|
-
});
|
|
491
|
-
}
|
|
492
|
-
const resolvingReferences = new Set(referenceContext.resolvingReferences);
|
|
493
|
-
resolvingReferences.add(referenceKey);
|
|
494
|
-
const { $ref: _reference, ...siblingSchema } = jsonSchema;
|
|
495
|
-
const resolvedSchema = typeof definition === "boolean" ? definition ? siblingSchema : false : { ...definition, ...siblingSchema };
|
|
496
|
-
return convertJSONSchemaDefinition(resolvedSchema, isRoot, {
|
|
497
|
-
...referenceContext,
|
|
498
|
-
resolvingReferences
|
|
499
|
-
});
|
|
500
|
-
}
|
|
501
|
-
function getReferencedDefinition(reference, referenceContext) {
|
|
502
|
-
const definitionSources = [
|
|
503
|
-
{
|
|
504
|
-
prefix: "#/$defs/",
|
|
505
|
-
definitions: referenceContext.dollarDefinitions
|
|
506
|
-
},
|
|
507
|
-
{
|
|
508
|
-
prefix: "#/definitions/",
|
|
509
|
-
definitions: referenceContext.definitions
|
|
510
|
-
}
|
|
511
|
-
];
|
|
512
|
-
const source = definitionSources.find(
|
|
513
|
-
({ prefix }) => reference.startsWith(prefix)
|
|
514
|
-
);
|
|
515
|
-
const encodedDefinitionName = source ? reference.slice(source.prefix.length) : void 0;
|
|
516
|
-
if (source == null || encodedDefinitionName == null || encodedDefinitionName.length === 0 || encodedDefinitionName.includes("/")) {
|
|
517
|
-
throwUnsupportedReference(reference);
|
|
518
|
-
}
|
|
519
|
-
let decodedDefinitionName;
|
|
520
|
-
try {
|
|
521
|
-
decodedDefinitionName = decodeURIComponent(encodedDefinitionName);
|
|
522
|
-
} catch (e) {
|
|
523
|
-
throwUnsupportedReference(reference);
|
|
524
|
-
}
|
|
525
|
-
if (decodedDefinitionName.includes("/") || /~(?![01])/u.test(decodedDefinitionName) || source.definitions == null) {
|
|
526
|
-
throwUnsupportedReference(reference);
|
|
527
|
-
}
|
|
528
|
-
const definitionName = decodedDefinitionName.replace(
|
|
529
|
-
/~[01]/g,
|
|
530
|
-
(match) => match === "~1" ? "/" : "~"
|
|
531
|
-
);
|
|
532
|
-
if (!Object.prototype.hasOwnProperty.call(source.definitions, definitionName)) {
|
|
533
|
-
throwUnsupportedReference(reference);
|
|
534
|
-
}
|
|
535
|
-
return {
|
|
536
|
-
definition: source.definitions[definitionName],
|
|
537
|
-
referenceKey: `${source.prefix}${definitionName}`
|
|
538
|
-
};
|
|
539
|
-
}
|
|
540
|
-
function throwUnsupportedReference(reference) {
|
|
541
|
-
throw new UnsupportedFunctionalityError({
|
|
542
|
-
functionality: `JSON Schema reference: ${reference}`,
|
|
543
|
-
message: "Google schema conversion only supports references to direct children of root-level $defs or definitions."
|
|
544
|
-
});
|
|
545
|
-
}
|
|
546
|
-
function addEnumToSchema({
|
|
547
|
-
values,
|
|
548
|
-
type,
|
|
549
|
-
result
|
|
550
|
-
}) {
|
|
551
|
-
const nullable = Array.isArray(type) && type.includes("null") || type === void 0 && values.includes(null);
|
|
552
|
-
const enumValues = nullable ? values.filter((value) => value !== null) : values;
|
|
553
|
-
if (values.length > 0 && values.every((value) => value === null)) {
|
|
554
|
-
const typeAllowsNull = type === void 0 || type === "null" || Array.isArray(type) && type.includes("null");
|
|
555
|
-
if (typeAllowsNull) {
|
|
556
|
-
result.type = "null";
|
|
557
|
-
if (Array.isArray(type)) {
|
|
558
|
-
delete result.anyOf;
|
|
559
|
-
}
|
|
560
|
-
return;
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
const enumType = getEnumType({ values: enumValues, type });
|
|
564
|
-
if (enumType === void 0) {
|
|
565
|
-
throw new UnsupportedFunctionalityError({
|
|
566
|
-
functionality: "JSON Schema enum with mixed or unsupported values",
|
|
567
|
-
message: "Google does not support this JSON Schema enum. Enum values must share one supported primitive type and match the schema type."
|
|
568
|
-
});
|
|
569
|
-
}
|
|
570
|
-
result.type = enumType;
|
|
571
|
-
if (Array.isArray(type)) {
|
|
572
|
-
delete result.anyOf;
|
|
573
|
-
}
|
|
574
|
-
if (nullable) {
|
|
575
|
-
result.nullable = true;
|
|
576
|
-
}
|
|
577
|
-
if (enumType === "string") {
|
|
578
|
-
result.enum = enumValues;
|
|
579
|
-
} else {
|
|
580
|
-
result.format = "enum";
|
|
581
|
-
result.enum = enumValues.map(String);
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
function getEnumType({
|
|
585
|
-
values,
|
|
586
|
-
type
|
|
587
|
-
}) {
|
|
588
|
-
if (values.length === 0) {
|
|
589
|
-
return void 0;
|
|
590
|
-
}
|
|
591
|
-
const typeAllows = (enumType) => type === void 0 || type === enumType || Array.isArray(type) && type.includes(enumType);
|
|
592
|
-
if (typeAllows("string") && values.every((value) => typeof value === "string")) {
|
|
593
|
-
return "string";
|
|
594
|
-
}
|
|
595
|
-
if ((typeAllows("number") || typeAllows("integer")) && values.every((value) => typeof value === "number" && Number.isFinite(value))) {
|
|
596
|
-
if (typeAllows("number")) {
|
|
597
|
-
return "number";
|
|
598
|
-
}
|
|
599
|
-
if (values.every((value) => Number.isInteger(value))) {
|
|
600
|
-
return "integer";
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
if (typeAllows("boolean") && values.every((value) => typeof value === "boolean")) {
|
|
604
|
-
return "boolean";
|
|
605
|
-
}
|
|
606
|
-
return void 0;
|
|
607
|
-
}
|
|
608
|
-
function isEmptyObjectSchema(jsonSchema) {
|
|
609
|
-
return jsonSchema != null && typeof jsonSchema === "object" && jsonSchema.type === "object" && (jsonSchema.properties == null || Object.keys(jsonSchema.properties).length === 0) && !jsonSchema.additionalProperties;
|
|
610
|
-
}
|
|
611
|
-
|
|
612
332
|
// src/convert-to-google-messages.ts
|
|
613
333
|
import {
|
|
614
|
-
UnsupportedFunctionalityError
|
|
334
|
+
UnsupportedFunctionalityError
|
|
615
335
|
} from "@ai-sdk/provider";
|
|
616
336
|
import {
|
|
617
337
|
convertToBase64,
|
|
@@ -768,7 +488,7 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
768
488
|
switch (role) {
|
|
769
489
|
case "system": {
|
|
770
490
|
if (!systemMessagesAllowed) {
|
|
771
|
-
throw new
|
|
491
|
+
throw new UnsupportedFunctionalityError({
|
|
772
492
|
functionality: "system messages are only supported at the beginning of the conversation"
|
|
773
493
|
});
|
|
774
494
|
}
|
|
@@ -797,7 +517,7 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
797
517
|
}
|
|
798
518
|
case "reference": {
|
|
799
519
|
if (isVertexLike) {
|
|
800
|
-
throw new
|
|
520
|
+
throw new UnsupportedFunctionalityError({
|
|
801
521
|
functionality: "file parts with provider references"
|
|
802
522
|
});
|
|
803
523
|
}
|
|
@@ -865,7 +585,7 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
865
585
|
case "reasoning-file": {
|
|
866
586
|
switch (part.data.type) {
|
|
867
587
|
case "url": {
|
|
868
|
-
throw new
|
|
588
|
+
throw new UnsupportedFunctionalityError({
|
|
869
589
|
functionality: "File data URLs in assistant messages are not supported"
|
|
870
590
|
});
|
|
871
591
|
}
|
|
@@ -885,13 +605,13 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
885
605
|
case "file": {
|
|
886
606
|
switch (part.data.type) {
|
|
887
607
|
case "url": {
|
|
888
|
-
throw new
|
|
608
|
+
throw new UnsupportedFunctionalityError({
|
|
889
609
|
functionality: "File data URLs in assistant messages are not supported"
|
|
890
610
|
});
|
|
891
611
|
}
|
|
892
612
|
case "reference": {
|
|
893
613
|
if (isVertexLike) {
|
|
894
|
-
throw new
|
|
614
|
+
throw new UnsupportedFunctionalityError({
|
|
895
615
|
functionality: "file parts with provider references"
|
|
896
616
|
});
|
|
897
617
|
}
|
|
@@ -1154,6 +874,44 @@ async function downloadToolResultOutput(output, {
|
|
|
1154
874
|
};
|
|
1155
875
|
}
|
|
1156
876
|
|
|
877
|
+
// src/sanitize-response-json-schema.ts
|
|
878
|
+
function sanitizeResponseJsonSchema(schema) {
|
|
879
|
+
const {
|
|
880
|
+
const: constValue,
|
|
881
|
+
properties,
|
|
882
|
+
items,
|
|
883
|
+
additionalProperties,
|
|
884
|
+
anyOf,
|
|
885
|
+
oneOf,
|
|
886
|
+
...result
|
|
887
|
+
} = schema;
|
|
888
|
+
return {
|
|
889
|
+
...result,
|
|
890
|
+
...constValue !== void 0 ? { enum: [constValue] } : {},
|
|
891
|
+
...properties != null ? { properties: sanitizeDefinitions(properties) } : {},
|
|
892
|
+
...items != null ? {
|
|
893
|
+
items: Array.isArray(items) ? items.map(sanitizeDefinition) : sanitizeDefinition(items)
|
|
894
|
+
} : {},
|
|
895
|
+
...additionalProperties != null ? {
|
|
896
|
+
additionalProperties: typeof additionalProperties === "boolean" ? additionalProperties : sanitizeDefinition(additionalProperties)
|
|
897
|
+
} : {},
|
|
898
|
+
...anyOf != null ? { anyOf: anyOf.map(sanitizeDefinition) } : {},
|
|
899
|
+
...oneOf != null ? { oneOf: oneOf.map(sanitizeDefinition) } : {},
|
|
900
|
+
...result.$defs != null ? { $defs: sanitizeDefinitions(result.$defs) } : {}
|
|
901
|
+
};
|
|
902
|
+
}
|
|
903
|
+
function sanitizeDefinitions(definitions) {
|
|
904
|
+
return Object.fromEntries(
|
|
905
|
+
Object.entries(definitions).map(([name, definition]) => [
|
|
906
|
+
name,
|
|
907
|
+
sanitizeDefinition(definition)
|
|
908
|
+
])
|
|
909
|
+
);
|
|
910
|
+
}
|
|
911
|
+
function sanitizeDefinition(definition) {
|
|
912
|
+
return typeof definition === "boolean" ? definition : sanitizeResponseJsonSchema(definition);
|
|
913
|
+
}
|
|
914
|
+
|
|
1157
915
|
// src/google-language-model-options.ts
|
|
1158
916
|
import {
|
|
1159
917
|
lazySchema as lazySchema4,
|
|
@@ -1368,7 +1126,7 @@ function getGoogleModelCapabilities(modelId) {
|
|
|
1368
1126
|
|
|
1369
1127
|
// src/google-prepare-tools.ts
|
|
1370
1128
|
import {
|
|
1371
|
-
UnsupportedFunctionalityError as
|
|
1129
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
1372
1130
|
} from "@ai-sdk/provider";
|
|
1373
1131
|
function prepareTools({
|
|
1374
1132
|
tools,
|
|
@@ -1598,7 +1356,7 @@ function prepareTools({
|
|
|
1598
1356
|
};
|
|
1599
1357
|
default: {
|
|
1600
1358
|
const _exhaustiveCheck = type;
|
|
1601
|
-
throw new
|
|
1359
|
+
throw new UnsupportedFunctionalityError2({
|
|
1602
1360
|
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
1603
1361
|
});
|
|
1604
1362
|
}
|
|
@@ -1606,24 +1364,11 @@ function prepareTools({
|
|
|
1606
1364
|
}
|
|
1607
1365
|
function prepareFunctionDeclaration(tool) {
|
|
1608
1366
|
var _a;
|
|
1609
|
-
|
|
1367
|
+
return {
|
|
1610
1368
|
name: tool.name,
|
|
1611
|
-
description: (_a = tool.description) != null ? _a : ""
|
|
1369
|
+
description: (_a = tool.description) != null ? _a : "",
|
|
1370
|
+
parametersJsonSchema: tool.inputSchema
|
|
1612
1371
|
};
|
|
1613
|
-
try {
|
|
1614
|
-
return {
|
|
1615
|
-
...declaration,
|
|
1616
|
-
parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
|
|
1617
|
-
};
|
|
1618
|
-
} catch (error) {
|
|
1619
|
-
if (!isRecursiveJSONSchemaReferenceError(error)) {
|
|
1620
|
-
throw error;
|
|
1621
|
-
}
|
|
1622
|
-
return {
|
|
1623
|
-
...declaration,
|
|
1624
|
-
parametersJsonSchema: tool.inputSchema
|
|
1625
|
-
};
|
|
1626
|
-
}
|
|
1627
1372
|
}
|
|
1628
1373
|
|
|
1629
1374
|
// src/google-json-accumulator.ts
|
|
@@ -2109,10 +1854,10 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2109
1854
|
seed,
|
|
2110
1855
|
// response format:
|
|
2111
1856
|
responseMimeType: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? "application/json" : void 0,
|
|
2112
|
-
|
|
2113
|
-
// so this is needed as an escape hatch:
|
|
1857
|
+
responseJsonSchema: (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && // Google does not support all JSON Schema features in
|
|
1858
|
+
// responseJsonSchema, so this is needed as an escape hatch:
|
|
2114
1859
|
// TODO convert into provider option
|
|
2115
|
-
((_c = googleOptions == null ? void 0 : googleOptions.structuredOutputs) != null ? _c : true) ?
|
|
1860
|
+
((_c = googleOptions == null ? void 0 : googleOptions.structuredOutputs) != null ? _c : true) ? sanitizeResponseJsonSchema(responseFormat.schema) : void 0,
|
|
2116
1861
|
...(googleOptions == null ? void 0 : googleOptions.audioTimestamp) && {
|
|
2117
1862
|
audioTimestamp: googleOptions.audioTimestamp
|
|
2118
1863
|
},
|
|
@@ -3214,7 +2959,7 @@ function assertSupportedBatchRequests(requests) {
|
|
|
3214
2959
|
for (const request of requests) {
|
|
3215
2960
|
const requestType = request.type;
|
|
3216
2961
|
if (requestType !== "text" && requestType !== "image") {
|
|
3217
|
-
throw new
|
|
2962
|
+
throw new UnsupportedFunctionalityError3({
|
|
3218
2963
|
functionality: `batch request type: ${requestType}`,
|
|
3219
2964
|
message: `The Google Batch API does not support batch requests with type "${requestType}".`
|
|
3220
2965
|
});
|
|
@@ -3703,12 +3448,12 @@ var GoogleBatch = class {
|
|
|
3703
3448
|
const { prompt, n, size, aspectRatio, seed, files, mask, providerOptions } = request.options;
|
|
3704
3449
|
const warnings = [];
|
|
3705
3450
|
if (mask != null) {
|
|
3706
|
-
throw new
|
|
3451
|
+
throw new UnsupportedFunctionalityError3({
|
|
3707
3452
|
functionality: "mask-based image editing in Google batches"
|
|
3708
3453
|
});
|
|
3709
3454
|
}
|
|
3710
3455
|
if (n > 1) {
|
|
3711
|
-
throw new
|
|
3456
|
+
throw new UnsupportedFunctionalityError3({
|
|
3712
3457
|
functionality: "multiple images per Google batch request"
|
|
3713
3458
|
});
|
|
3714
3459
|
}
|
|
@@ -8400,9 +8145,16 @@ var GoogleRealtimeEventMapper = class {
|
|
|
8400
8145
|
return null;
|
|
8401
8146
|
}
|
|
8402
8147
|
};
|
|
8148
|
+
function toFunctionResponseStruct(value) {
|
|
8149
|
+
const isStruct = typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8150
|
+
return isStruct ? value : { output: value };
|
|
8151
|
+
}
|
|
8403
8152
|
async function serializeFunctionCallOutput(item) {
|
|
8404
8153
|
const parseResult = await safeParseJSON({ text: item.output });
|
|
8405
|
-
const response = parseResult.success ? parseResult.value :
|
|
8154
|
+
const response = parseResult.success ? toFunctionResponseStruct(parseResult.value) : (
|
|
8155
|
+
// Preserve non-JSON output in the required object wrapper.
|
|
8156
|
+
{ output: item.output }
|
|
8157
|
+
);
|
|
8406
8158
|
return {
|
|
8407
8159
|
toolResponse: {
|
|
8408
8160
|
functionResponses: [
|
|
@@ -8448,7 +8200,7 @@ function buildGoogleSessionConfig(config, modelId) {
|
|
|
8448
8200
|
functionDeclarations: config.tools.map((tool) => ({
|
|
8449
8201
|
name: tool.name,
|
|
8450
8202
|
description: tool.description,
|
|
8451
|
-
|
|
8203
|
+
parametersJsonSchema: tool.parameters
|
|
8452
8204
|
}))
|
|
8453
8205
|
}
|
|
8454
8206
|
];
|