@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/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.52" : "0.0.0-test";
|
|
11
11
|
|
|
12
12
|
// src/google-generative-ai-embedding-model.ts
|
|
13
13
|
import {
|
|
@@ -406,13 +406,118 @@ import {
|
|
|
406
406
|
UnsupportedFunctionalityError
|
|
407
407
|
} from "@ai-sdk/provider";
|
|
408
408
|
import { convertToBase64 } from "@ai-sdk/provider-utils";
|
|
409
|
+
var dataUrlRegex = /^data:([^;,]+);base64,(.+)$/s;
|
|
410
|
+
function parseBase64DataUrl(value) {
|
|
411
|
+
const match = dataUrlRegex.exec(value);
|
|
412
|
+
if (match == null) {
|
|
413
|
+
return void 0;
|
|
414
|
+
}
|
|
415
|
+
return {
|
|
416
|
+
mediaType: match[1],
|
|
417
|
+
data: match[2]
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
function convertUrlToolResultPart(url) {
|
|
421
|
+
const parsedDataUrl = parseBase64DataUrl(url);
|
|
422
|
+
if (parsedDataUrl == null) {
|
|
423
|
+
return void 0;
|
|
424
|
+
}
|
|
425
|
+
return {
|
|
426
|
+
inlineData: {
|
|
427
|
+
mimeType: parsedDataUrl.mediaType,
|
|
428
|
+
data: parsedDataUrl.data
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
function appendToolResultParts(parts, toolName, outputValue) {
|
|
433
|
+
const functionResponseParts = [];
|
|
434
|
+
const responseTextParts = [];
|
|
435
|
+
for (const contentPart of outputValue) {
|
|
436
|
+
switch (contentPart.type) {
|
|
437
|
+
case "text": {
|
|
438
|
+
responseTextParts.push(contentPart.text);
|
|
439
|
+
break;
|
|
440
|
+
}
|
|
441
|
+
case "image-data":
|
|
442
|
+
case "file-data": {
|
|
443
|
+
functionResponseParts.push({
|
|
444
|
+
inlineData: {
|
|
445
|
+
mimeType: contentPart.mediaType,
|
|
446
|
+
data: contentPart.data
|
|
447
|
+
}
|
|
448
|
+
});
|
|
449
|
+
break;
|
|
450
|
+
}
|
|
451
|
+
case "image-url":
|
|
452
|
+
case "file-url": {
|
|
453
|
+
const functionResponsePart = convertUrlToolResultPart(
|
|
454
|
+
contentPart.url
|
|
455
|
+
);
|
|
456
|
+
if (functionResponsePart != null) {
|
|
457
|
+
functionResponseParts.push(functionResponsePart);
|
|
458
|
+
} else {
|
|
459
|
+
responseTextParts.push(JSON.stringify(contentPart));
|
|
460
|
+
}
|
|
461
|
+
break;
|
|
462
|
+
}
|
|
463
|
+
default: {
|
|
464
|
+
responseTextParts.push(JSON.stringify(contentPart));
|
|
465
|
+
break;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
parts.push({
|
|
470
|
+
functionResponse: {
|
|
471
|
+
name: toolName,
|
|
472
|
+
response: {
|
|
473
|
+
name: toolName,
|
|
474
|
+
content: responseTextParts.length > 0 ? responseTextParts.join("\n") : "Tool executed successfully."
|
|
475
|
+
},
|
|
476
|
+
...functionResponseParts.length > 0 ? { parts: functionResponseParts } : {}
|
|
477
|
+
}
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
function appendLegacyToolResultParts(parts, toolName, outputValue) {
|
|
481
|
+
for (const contentPart of outputValue) {
|
|
482
|
+
switch (contentPart.type) {
|
|
483
|
+
case "text":
|
|
484
|
+
parts.push({
|
|
485
|
+
functionResponse: {
|
|
486
|
+
name: toolName,
|
|
487
|
+
response: {
|
|
488
|
+
name: toolName,
|
|
489
|
+
content: contentPart.text
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
});
|
|
493
|
+
break;
|
|
494
|
+
case "image-data":
|
|
495
|
+
parts.push(
|
|
496
|
+
{
|
|
497
|
+
inlineData: {
|
|
498
|
+
mimeType: String(contentPart.mediaType),
|
|
499
|
+
data: String(contentPart.data)
|
|
500
|
+
}
|
|
501
|
+
},
|
|
502
|
+
{
|
|
503
|
+
text: "Tool executed successfully and returned this image as a response"
|
|
504
|
+
}
|
|
505
|
+
);
|
|
506
|
+
break;
|
|
507
|
+
default:
|
|
508
|
+
parts.push({ text: JSON.stringify(contentPart) });
|
|
509
|
+
break;
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
}
|
|
409
513
|
function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
410
|
-
var _a, _b, _c;
|
|
514
|
+
var _a, _b, _c, _d;
|
|
411
515
|
const systemInstructionParts = [];
|
|
412
516
|
const contents = [];
|
|
413
517
|
let systemMessagesAllowed = true;
|
|
414
518
|
const isGemmaModel = (_a = options == null ? void 0 : options.isGemmaModel) != null ? _a : false;
|
|
415
519
|
const providerOptionsName = (_b = options == null ? void 0 : options.providerOptionsName) != null ? _b : "google";
|
|
520
|
+
const supportsFunctionResponseParts = (_c = options == null ? void 0 : options.supportsFunctionResponseParts) != null ? _c : true;
|
|
416
521
|
for (const { role, content } of prompt) {
|
|
417
522
|
switch (role) {
|
|
418
523
|
case "system": {
|
|
@@ -460,8 +565,8 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
460
565
|
contents.push({
|
|
461
566
|
role: "model",
|
|
462
567
|
parts: content.map((part) => {
|
|
463
|
-
var _a2, _b2, _c2,
|
|
464
|
-
const providerOpts = (
|
|
568
|
+
var _a2, _b2, _c2, _d2;
|
|
569
|
+
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;
|
|
465
570
|
const thoughtSignature = (providerOpts == null ? void 0 : providerOpts.thoughtSignature) != null ? String(providerOpts.thoughtSignature) : void 0;
|
|
466
571
|
switch (part.type) {
|
|
467
572
|
case "text": {
|
|
@@ -515,36 +620,10 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
515
620
|
}
|
|
516
621
|
const output = part.output;
|
|
517
622
|
if (output.type === "content") {
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
functionResponse: {
|
|
523
|
-
name: part.toolName,
|
|
524
|
-
response: {
|
|
525
|
-
name: part.toolName,
|
|
526
|
-
content: contentPart.text
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
});
|
|
530
|
-
break;
|
|
531
|
-
case "image-data":
|
|
532
|
-
parts.push(
|
|
533
|
-
{
|
|
534
|
-
inlineData: {
|
|
535
|
-
mimeType: contentPart.mediaType,
|
|
536
|
-
data: contentPart.data
|
|
537
|
-
}
|
|
538
|
-
},
|
|
539
|
-
{
|
|
540
|
-
text: "Tool executed successfully and returned this image as a response"
|
|
541
|
-
}
|
|
542
|
-
);
|
|
543
|
-
break;
|
|
544
|
-
default:
|
|
545
|
-
parts.push({ text: JSON.stringify(contentPart) });
|
|
546
|
-
break;
|
|
547
|
-
}
|
|
623
|
+
if (supportsFunctionResponseParts) {
|
|
624
|
+
appendToolResultParts(parts, part.toolName, output.value);
|
|
625
|
+
} else {
|
|
626
|
+
appendLegacyToolResultParts(parts, part.toolName, output.value);
|
|
548
627
|
}
|
|
549
628
|
} else {
|
|
550
629
|
parts.push({
|
|
@@ -552,7 +631,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
552
631
|
name: part.toolName,
|
|
553
632
|
response: {
|
|
554
633
|
name: part.toolName,
|
|
555
|
-
content: output.type === "execution-denied" ? (
|
|
634
|
+
content: output.type === "execution-denied" ? (_d = output.reason) != null ? _d : "Tool execution denied." : output.value
|
|
556
635
|
}
|
|
557
636
|
}
|
|
558
637
|
});
|
|
@@ -996,9 +1075,14 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
996
1075
|
});
|
|
997
1076
|
}
|
|
998
1077
|
const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
|
|
1078
|
+
const supportsFunctionResponseParts = this.modelId.startsWith("gemini-3");
|
|
999
1079
|
const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
|
|
1000
1080
|
prompt,
|
|
1001
|
-
{
|
|
1081
|
+
{
|
|
1082
|
+
isGemmaModel,
|
|
1083
|
+
providerOptionsName,
|
|
1084
|
+
supportsFunctionResponseParts
|
|
1085
|
+
}
|
|
1002
1086
|
);
|
|
1003
1087
|
const {
|
|
1004
1088
|
tools: googleTools2,
|