@ai-sdk/google 2.0.62 → 2.0.64
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 +17 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +108 -45
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +105 -42
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +1 -0
- package/dist/internal/index.d.ts +1 -0
- package/dist/internal/index.js +107 -44
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +104 -41
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -3
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.64" : "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) {
|
|
@@ -658,7 +704,15 @@ var googleGenerativeAIProviderOptions = lazySchema4(
|
|
|
658
704
|
latitude: z4.number(),
|
|
659
705
|
longitude: z4.number()
|
|
660
706
|
}).optional()
|
|
661
|
-
}).optional()
|
|
707
|
+
}).optional(),
|
|
708
|
+
/**
|
|
709
|
+
* Optional. The service tier to use for the request.
|
|
710
|
+
*/
|
|
711
|
+
serviceTier: z4.enum([
|
|
712
|
+
"SERVICE_TIER_STANDARD",
|
|
713
|
+
"SERVICE_TIER_FLEX",
|
|
714
|
+
"SERVICE_TIER_PRIORITY"
|
|
715
|
+
]).optional()
|
|
662
716
|
})
|
|
663
717
|
)
|
|
664
718
|
);
|
|
@@ -937,9 +991,10 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
937
991
|
});
|
|
938
992
|
}
|
|
939
993
|
const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
|
|
994
|
+
const supportsFunctionResponseParts = this.modelId.startsWith("gemini-3");
|
|
940
995
|
const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
|
|
941
996
|
prompt,
|
|
942
|
-
{ isGemmaModel }
|
|
997
|
+
{ isGemmaModel, supportsFunctionResponseParts }
|
|
943
998
|
);
|
|
944
999
|
const {
|
|
945
1000
|
tools: googleTools2,
|
|
@@ -990,13 +1045,14 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
990
1045
|
retrievalConfig: googleOptions.retrievalConfig
|
|
991
1046
|
} : googleToolConfig,
|
|
992
1047
|
cachedContent: googleOptions == null ? void 0 : googleOptions.cachedContent,
|
|
993
|
-
labels: googleOptions == null ? void 0 : googleOptions.labels
|
|
1048
|
+
labels: googleOptions == null ? void 0 : googleOptions.labels,
|
|
1049
|
+
serviceTier: googleOptions == null ? void 0 : googleOptions.serviceTier
|
|
994
1050
|
},
|
|
995
1051
|
warnings: [...warnings, ...toolWarnings]
|
|
996
1052
|
};
|
|
997
1053
|
}
|
|
998
1054
|
async doGenerate(options) {
|
|
999
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
1055
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
1000
1056
|
const { args, warnings } = await this.getArgs(options);
|
|
1001
1057
|
const body = JSON.stringify(args);
|
|
1002
1058
|
const mergedHeaders = combineHeaders2(
|
|
@@ -1106,7 +1162,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1106
1162
|
groundingMetadata: (_k = candidate.groundingMetadata) != null ? _k : null,
|
|
1107
1163
|
urlContextMetadata: (_l = candidate.urlContextMetadata) != null ? _l : null,
|
|
1108
1164
|
safetyRatings: (_m = candidate.safetyRatings) != null ? _m : null,
|
|
1109
|
-
|
|
1165
|
+
serviceTier: (_n = response.serviceTier) != null ? _n : null
|
|
1110
1166
|
}
|
|
1111
1167
|
},
|
|
1112
1168
|
request: { body },
|
|
@@ -1144,6 +1200,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1144
1200
|
let providerMetadata = void 0;
|
|
1145
1201
|
let lastGroundingMetadata = null;
|
|
1146
1202
|
let lastUrlContextMetadata = null;
|
|
1203
|
+
let serviceTier = null;
|
|
1147
1204
|
const generateId3 = this.config.generateId;
|
|
1148
1205
|
let hasToolCalls = false;
|
|
1149
1206
|
let currentTextBlockId = null;
|
|
@@ -1175,6 +1232,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1175
1232
|
usage.reasoningTokens = (_d = usageMetadata.thoughtsTokenCount) != null ? _d : void 0;
|
|
1176
1233
|
usage.cachedInputTokens = (_e = usageMetadata.cachedContentTokenCount) != null ? _e : void 0;
|
|
1177
1234
|
}
|
|
1235
|
+
if (value.serviceTier != null) {
|
|
1236
|
+
serviceTier = value.serviceTier;
|
|
1237
|
+
}
|
|
1178
1238
|
const candidate = (_f = value.candidates) == null ? void 0 : _f[0];
|
|
1179
1239
|
if (candidate == null) {
|
|
1180
1240
|
return;
|
|
@@ -1339,7 +1399,8 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1339
1399
|
promptFeedback: (_i = value.promptFeedback) != null ? _i : null,
|
|
1340
1400
|
groundingMetadata: lastGroundingMetadata,
|
|
1341
1401
|
urlContextMetadata: lastUrlContextMetadata,
|
|
1342
|
-
safetyRatings: (_j = candidate.safetyRatings) != null ? _j : null
|
|
1402
|
+
safetyRatings: (_j = candidate.safetyRatings) != null ? _j : null,
|
|
1403
|
+
serviceTier
|
|
1343
1404
|
}
|
|
1344
1405
|
};
|
|
1345
1406
|
if (usageMetadata != null) {
|
|
@@ -1606,7 +1667,8 @@ var responseSchema = lazySchema5(
|
|
|
1606
1667
|
promptFeedback: z5.object({
|
|
1607
1668
|
blockReason: z5.string().nullish(),
|
|
1608
1669
|
safetyRatings: z5.array(getSafetyRatingSchema()).nullish()
|
|
1609
|
-
}).nullish()
|
|
1670
|
+
}).nullish(),
|
|
1671
|
+
serviceTier: z5.string().nullish()
|
|
1610
1672
|
})
|
|
1611
1673
|
)
|
|
1612
1674
|
);
|
|
@@ -1626,7 +1688,8 @@ var chunkSchema = lazySchema5(
|
|
|
1626
1688
|
promptFeedback: z5.object({
|
|
1627
1689
|
blockReason: z5.string().nullish(),
|
|
1628
1690
|
safetyRatings: z5.array(getSafetyRatingSchema()).nullish()
|
|
1629
|
-
}).nullish()
|
|
1691
|
+
}).nullish(),
|
|
1692
|
+
serviceTier: z5.string().nullish()
|
|
1630
1693
|
})
|
|
1631
1694
|
)
|
|
1632
1695
|
);
|