@ai-sdk/google 3.0.51 → 3.0.52
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 +15 -0
- package/dist/index.js +123 -39
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +120 -36
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +122 -38
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +119 -35
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/convert-to-google-generative-ai-messages.ts +163 -32
- package/src/google-generative-ai-language-model.ts +6 -1
- package/src/google-generative-ai-prompt.ts +12 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @ai-sdk/google
|
|
2
2
|
|
|
3
|
+
## 3.0.52
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 055cd68: fix: publish v6 to latest npm dist tag
|
|
8
|
+
- 47114a3: feat(provider/google): Add multimodal tool-result support for Google function responses.
|
|
9
|
+
|
|
10
|
+
Tool results with `output.type = 'content'` now map media parts into
|
|
11
|
+
`functionResponse.parts` for Google models, including `image-data`,
|
|
12
|
+
`file-data`, and base64 `data:` URLs in URL-style content parts.
|
|
13
|
+
Remote HTTP(S) URLs in URL-style tool-result parts are not supported.
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [055cd68]
|
|
16
|
+
- @ai-sdk/provider-utils@4.0.21
|
|
17
|
+
|
|
3
18
|
## 3.0.51
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -18,19 +18,19 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
|
|
20
20
|
// src/index.ts
|
|
21
|
-
var
|
|
22
|
-
__export(
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
23
|
VERSION: () => VERSION,
|
|
24
24
|
createGoogleGenerativeAI: () => createGoogleGenerativeAI,
|
|
25
25
|
google: () => google
|
|
26
26
|
});
|
|
27
|
-
module.exports = __toCommonJS(
|
|
27
|
+
module.exports = __toCommonJS(index_exports);
|
|
28
28
|
|
|
29
29
|
// src/google-provider.ts
|
|
30
30
|
var import_provider_utils16 = require("@ai-sdk/provider-utils");
|
|
31
31
|
|
|
32
32
|
// src/version.ts
|
|
33
|
-
var VERSION = true ? "3.0.
|
|
33
|
+
var VERSION = true ? "3.0.52" : "0.0.0-test";
|
|
34
34
|
|
|
35
35
|
// src/google-generative-ai-embedding-model.ts
|
|
36
36
|
var import_provider = require("@ai-sdk/provider");
|
|
@@ -400,13 +400,118 @@ function isEmptyObjectSchema(jsonSchema) {
|
|
|
400
400
|
// src/convert-to-google-generative-ai-messages.ts
|
|
401
401
|
var import_provider2 = require("@ai-sdk/provider");
|
|
402
402
|
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
|
403
|
+
var dataUrlRegex = /^data:([^;,]+);base64,(.+)$/s;
|
|
404
|
+
function parseBase64DataUrl(value) {
|
|
405
|
+
const match = dataUrlRegex.exec(value);
|
|
406
|
+
if (match == null) {
|
|
407
|
+
return void 0;
|
|
408
|
+
}
|
|
409
|
+
return {
|
|
410
|
+
mediaType: match[1],
|
|
411
|
+
data: match[2]
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
function convertUrlToolResultPart(url) {
|
|
415
|
+
const parsedDataUrl = parseBase64DataUrl(url);
|
|
416
|
+
if (parsedDataUrl == null) {
|
|
417
|
+
return void 0;
|
|
418
|
+
}
|
|
419
|
+
return {
|
|
420
|
+
inlineData: {
|
|
421
|
+
mimeType: parsedDataUrl.mediaType,
|
|
422
|
+
data: parsedDataUrl.data
|
|
423
|
+
}
|
|
424
|
+
};
|
|
425
|
+
}
|
|
426
|
+
function appendToolResultParts(parts, toolName, outputValue) {
|
|
427
|
+
const functionResponseParts = [];
|
|
428
|
+
const responseTextParts = [];
|
|
429
|
+
for (const contentPart of outputValue) {
|
|
430
|
+
switch (contentPart.type) {
|
|
431
|
+
case "text": {
|
|
432
|
+
responseTextParts.push(contentPart.text);
|
|
433
|
+
break;
|
|
434
|
+
}
|
|
435
|
+
case "image-data":
|
|
436
|
+
case "file-data": {
|
|
437
|
+
functionResponseParts.push({
|
|
438
|
+
inlineData: {
|
|
439
|
+
mimeType: contentPart.mediaType,
|
|
440
|
+
data: contentPart.data
|
|
441
|
+
}
|
|
442
|
+
});
|
|
443
|
+
break;
|
|
444
|
+
}
|
|
445
|
+
case "image-url":
|
|
446
|
+
case "file-url": {
|
|
447
|
+
const functionResponsePart = convertUrlToolResultPart(
|
|
448
|
+
contentPart.url
|
|
449
|
+
);
|
|
450
|
+
if (functionResponsePart != null) {
|
|
451
|
+
functionResponseParts.push(functionResponsePart);
|
|
452
|
+
} else {
|
|
453
|
+
responseTextParts.push(JSON.stringify(contentPart));
|
|
454
|
+
}
|
|
455
|
+
break;
|
|
456
|
+
}
|
|
457
|
+
default: {
|
|
458
|
+
responseTextParts.push(JSON.stringify(contentPart));
|
|
459
|
+
break;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
parts.push({
|
|
464
|
+
functionResponse: {
|
|
465
|
+
name: toolName,
|
|
466
|
+
response: {
|
|
467
|
+
name: toolName,
|
|
468
|
+
content: responseTextParts.length > 0 ? responseTextParts.join("\n") : "Tool executed successfully."
|
|
469
|
+
},
|
|
470
|
+
...functionResponseParts.length > 0 ? { parts: functionResponseParts } : {}
|
|
471
|
+
}
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
function appendLegacyToolResultParts(parts, toolName, outputValue) {
|
|
475
|
+
for (const contentPart of outputValue) {
|
|
476
|
+
switch (contentPart.type) {
|
|
477
|
+
case "text":
|
|
478
|
+
parts.push({
|
|
479
|
+
functionResponse: {
|
|
480
|
+
name: toolName,
|
|
481
|
+
response: {
|
|
482
|
+
name: toolName,
|
|
483
|
+
content: contentPart.text
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
});
|
|
487
|
+
break;
|
|
488
|
+
case "image-data":
|
|
489
|
+
parts.push(
|
|
490
|
+
{
|
|
491
|
+
inlineData: {
|
|
492
|
+
mimeType: String(contentPart.mediaType),
|
|
493
|
+
data: String(contentPart.data)
|
|
494
|
+
}
|
|
495
|
+
},
|
|
496
|
+
{
|
|
497
|
+
text: "Tool executed successfully and returned this image as a response"
|
|
498
|
+
}
|
|
499
|
+
);
|
|
500
|
+
break;
|
|
501
|
+
default:
|
|
502
|
+
parts.push({ text: JSON.stringify(contentPart) });
|
|
503
|
+
break;
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
}
|
|
403
507
|
function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
404
|
-
var _a, _b, _c;
|
|
508
|
+
var _a, _b, _c, _d;
|
|
405
509
|
const systemInstructionParts = [];
|
|
406
510
|
const contents = [];
|
|
407
511
|
let systemMessagesAllowed = true;
|
|
408
512
|
const isGemmaModel = (_a = options == null ? void 0 : options.isGemmaModel) != null ? _a : false;
|
|
409
513
|
const providerOptionsName = (_b = options == null ? void 0 : options.providerOptionsName) != null ? _b : "google";
|
|
514
|
+
const supportsFunctionResponseParts = (_c = options == null ? void 0 : options.supportsFunctionResponseParts) != null ? _c : true;
|
|
410
515
|
for (const { role, content } of prompt) {
|
|
411
516
|
switch (role) {
|
|
412
517
|
case "system": {
|
|
@@ -454,8 +559,8 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
454
559
|
contents.push({
|
|
455
560
|
role: "model",
|
|
456
561
|
parts: content.map((part) => {
|
|
457
|
-
var _a2, _b2, _c2,
|
|
458
|
-
const providerOpts = (
|
|
562
|
+
var _a2, _b2, _c2, _d2;
|
|
563
|
+
const providerOpts = (_d2 = (_a2 = part.providerOptions) == null ? void 0 : _a2[providerOptionsName]) != null ? _d2 : providerOptionsName !== "google" ? (_b2 = part.providerOptions) == null ? void 0 : _b2.google : (_c2 = part.providerOptions) == null ? void 0 : _c2.vertex;
|
|
459
564
|
const thoughtSignature = (providerOpts == null ? void 0 : providerOpts.thoughtSignature) != null ? String(providerOpts.thoughtSignature) : void 0;
|
|
460
565
|
switch (part.type) {
|
|
461
566
|
case "text": {
|
|
@@ -509,36 +614,10 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
509
614
|
}
|
|
510
615
|
const output = part.output;
|
|
511
616
|
if (output.type === "content") {
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
functionResponse: {
|
|
517
|
-
name: part.toolName,
|
|
518
|
-
response: {
|
|
519
|
-
name: part.toolName,
|
|
520
|
-
content: contentPart.text
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
});
|
|
524
|
-
break;
|
|
525
|
-
case "image-data":
|
|
526
|
-
parts.push(
|
|
527
|
-
{
|
|
528
|
-
inlineData: {
|
|
529
|
-
mimeType: contentPart.mediaType,
|
|
530
|
-
data: contentPart.data
|
|
531
|
-
}
|
|
532
|
-
},
|
|
533
|
-
{
|
|
534
|
-
text: "Tool executed successfully and returned this image as a response"
|
|
535
|
-
}
|
|
536
|
-
);
|
|
537
|
-
break;
|
|
538
|
-
default:
|
|
539
|
-
parts.push({ text: JSON.stringify(contentPart) });
|
|
540
|
-
break;
|
|
541
|
-
}
|
|
617
|
+
if (supportsFunctionResponseParts) {
|
|
618
|
+
appendToolResultParts(parts, part.toolName, output.value);
|
|
619
|
+
} else {
|
|
620
|
+
appendLegacyToolResultParts(parts, part.toolName, output.value);
|
|
542
621
|
}
|
|
543
622
|
} else {
|
|
544
623
|
parts.push({
|
|
@@ -546,7 +625,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
546
625
|
name: part.toolName,
|
|
547
626
|
response: {
|
|
548
627
|
name: part.toolName,
|
|
549
|
-
content: output.type === "execution-denied" ? (
|
|
628
|
+
content: output.type === "execution-denied" ? (_d = output.reason) != null ? _d : "Tool execution denied." : output.value
|
|
550
629
|
}
|
|
551
630
|
}
|
|
552
631
|
});
|
|
@@ -988,9 +1067,14 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
988
1067
|
});
|
|
989
1068
|
}
|
|
990
1069
|
const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
|
|
1070
|
+
const supportsFunctionResponseParts = this.modelId.startsWith("gemini-3");
|
|
991
1071
|
const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
|
|
992
1072
|
prompt,
|
|
993
|
-
{
|
|
1073
|
+
{
|
|
1074
|
+
isGemmaModel,
|
|
1075
|
+
providerOptionsName,
|
|
1076
|
+
supportsFunctionResponseParts
|
|
1077
|
+
}
|
|
994
1078
|
);
|
|
995
1079
|
const {
|
|
996
1080
|
tools: googleTools2,
|