@ai-sdk/google 2.0.62 → 2.0.63
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 +11 -0
- package/dist/index.js +85 -38
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +82 -35
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +84 -37
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +81 -34
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +3 -5
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.63" : "0.0.0-test";
|
|
11
11
|
|
|
12
12
|
// src/google-generative-ai-embedding-model.ts
|
|
13
13
|
import {
|
|
@@ -366,11 +366,12 @@ import {
|
|
|
366
366
|
} from "@ai-sdk/provider";
|
|
367
367
|
import { convertToBase64 } from "@ai-sdk/provider-utils";
|
|
368
368
|
function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
369
|
-
var _a;
|
|
369
|
+
var _a, _b;
|
|
370
370
|
const systemInstructionParts = [];
|
|
371
371
|
const contents = [];
|
|
372
372
|
let systemMessagesAllowed = true;
|
|
373
373
|
const isGemmaModel = (_a = options == null ? void 0 : options.isGemmaModel) != null ? _a : false;
|
|
374
|
+
const supportsFunctionResponseParts = (_b = options == null ? void 0 : options.supportsFunctionResponseParts) != null ? _b : true;
|
|
374
375
|
for (const { role, content } of prompt) {
|
|
375
376
|
switch (role) {
|
|
376
377
|
case "system": {
|
|
@@ -418,8 +419,8 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
418
419
|
contents.push({
|
|
419
420
|
role: "model",
|
|
420
421
|
parts: content.map((part) => {
|
|
421
|
-
var _a2,
|
|
422
|
-
const thoughtSignature = ((
|
|
422
|
+
var _a2, _b2, _c;
|
|
423
|
+
const thoughtSignature = ((_b2 = (_a2 = part.providerOptions) == null ? void 0 : _a2.google) == null ? void 0 : _b2.thoughtSignature) != null ? String((_c = part.providerOptions.google) == null ? void 0 : _c.thoughtSignature) : void 0;
|
|
423
424
|
switch (part.type) {
|
|
424
425
|
case "text": {
|
|
425
426
|
return part.text.length === 0 ? void 0 : {
|
|
@@ -472,36 +473,10 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
472
473
|
for (const part of content) {
|
|
473
474
|
const output = part.output;
|
|
474
475
|
if (output.type === "content") {
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
functionResponse: {
|
|
480
|
-
name: part.toolName,
|
|
481
|
-
response: {
|
|
482
|
-
name: part.toolName,
|
|
483
|
-
content: contentPart.text
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
});
|
|
487
|
-
break;
|
|
488
|
-
case "media":
|
|
489
|
-
parts.push(
|
|
490
|
-
{
|
|
491
|
-
inlineData: {
|
|
492
|
-
mimeType: contentPart.mediaType,
|
|
493
|
-
data: 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
|
-
}
|
|
476
|
+
if (supportsFunctionResponseParts) {
|
|
477
|
+
appendToolResultParts({ parts, part, output });
|
|
478
|
+
} else {
|
|
479
|
+
appendLegacyToolResultParts({ parts, part, output });
|
|
505
480
|
}
|
|
506
481
|
} else {
|
|
507
482
|
parts.push({
|
|
@@ -532,6 +507,77 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
532
507
|
contents
|
|
533
508
|
};
|
|
534
509
|
}
|
|
510
|
+
function appendToolResultParts({
|
|
511
|
+
parts,
|
|
512
|
+
part,
|
|
513
|
+
output
|
|
514
|
+
}) {
|
|
515
|
+
const responseTextParts = [];
|
|
516
|
+
const functionResponseParts = [];
|
|
517
|
+
for (const contentPart of output.value) {
|
|
518
|
+
switch (contentPart.type) {
|
|
519
|
+
case "text":
|
|
520
|
+
responseTextParts.push(contentPart.text);
|
|
521
|
+
break;
|
|
522
|
+
case "media":
|
|
523
|
+
functionResponseParts.push({
|
|
524
|
+
inlineData: {
|
|
525
|
+
mimeType: contentPart.mediaType,
|
|
526
|
+
data: contentPart.data
|
|
527
|
+
}
|
|
528
|
+
});
|
|
529
|
+
break;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
const responseText = responseTextParts.length > 0 ? responseTextParts.join("\n") : "Tool executed successfully.";
|
|
533
|
+
parts.push({
|
|
534
|
+
functionResponse: {
|
|
535
|
+
name: part.toolName,
|
|
536
|
+
response: {
|
|
537
|
+
name: part.toolName,
|
|
538
|
+
content: responseText
|
|
539
|
+
},
|
|
540
|
+
...functionResponseParts.length > 0 ? { parts: functionResponseParts } : {}
|
|
541
|
+
}
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
function appendLegacyToolResultParts({
|
|
545
|
+
parts,
|
|
546
|
+
part,
|
|
547
|
+
output
|
|
548
|
+
}) {
|
|
549
|
+
for (const contentPart of output.value) {
|
|
550
|
+
switch (contentPart.type) {
|
|
551
|
+
case "text":
|
|
552
|
+
parts.push({
|
|
553
|
+
functionResponse: {
|
|
554
|
+
name: part.toolName,
|
|
555
|
+
response: {
|
|
556
|
+
name: part.toolName,
|
|
557
|
+
content: contentPart.text
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
});
|
|
561
|
+
break;
|
|
562
|
+
case "media":
|
|
563
|
+
parts.push(
|
|
564
|
+
{
|
|
565
|
+
inlineData: {
|
|
566
|
+
mimeType: contentPart.mediaType,
|
|
567
|
+
data: contentPart.data
|
|
568
|
+
}
|
|
569
|
+
},
|
|
570
|
+
{
|
|
571
|
+
text: "Tool executed successfully and returned this image as a response"
|
|
572
|
+
}
|
|
573
|
+
);
|
|
574
|
+
break;
|
|
575
|
+
default:
|
|
576
|
+
parts.push({ text: JSON.stringify(contentPart) });
|
|
577
|
+
break;
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
}
|
|
535
581
|
|
|
536
582
|
// src/get-model-path.ts
|
|
537
583
|
function getModelPath(modelId) {
|
|
@@ -937,9 +983,10 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
937
983
|
});
|
|
938
984
|
}
|
|
939
985
|
const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
|
|
986
|
+
const supportsFunctionResponseParts = this.modelId.startsWith("gemini-3");
|
|
940
987
|
const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
|
|
941
988
|
prompt,
|
|
942
|
-
{ isGemmaModel }
|
|
989
|
+
{ isGemmaModel, supportsFunctionResponseParts }
|
|
943
990
|
);
|
|
944
991
|
const {
|
|
945
992
|
tools: googleTools2,
|