@ai-sdk/google 3.0.50 → 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 +21 -0
- package/dist/index.d.mts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +132 -46
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +129 -43
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +4 -1
- package/dist/internal/index.d.ts +4 -1
- package/dist/internal/index.js +131 -45
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +128 -42
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/convert-to-google-generative-ai-messages.ts +163 -32
- package/src/google-generative-ai-language-model.ts +25 -12
- package/src/google-generative-ai-prompt.ts +21 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
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
|
+
|
|
18
|
+
## 3.0.51
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- 8901054: feat(google): add new finishMessage field in providerMetadata
|
|
23
|
+
|
|
3
24
|
## 3.0.50
|
|
4
25
|
|
|
5
26
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -73,6 +73,7 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
73
73
|
})[] | null | undefined;
|
|
74
74
|
} | null | undefined;
|
|
75
75
|
finishReason?: string | null | undefined;
|
|
76
|
+
finishMessage?: string | null | undefined;
|
|
76
77
|
safetyRatings?: {
|
|
77
78
|
category?: string | null | undefined;
|
|
78
79
|
probability?: string | null | undefined;
|
|
@@ -158,14 +159,21 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
158
159
|
type GroundingMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['groundingMetadata']>;
|
|
159
160
|
type UrlContextMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['urlContextMetadata']>;
|
|
160
161
|
type SafetyRatingSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['safetyRatings']>[number];
|
|
162
|
+
type PromptFeedbackSchema = NonNullable<InferSchema<typeof responseSchema>['promptFeedback']>;
|
|
163
|
+
type UsageMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['usageMetadata']>;
|
|
161
164
|
|
|
162
165
|
type GoogleGenerativeAIGroundingMetadata = GroundingMetadataSchema;
|
|
163
166
|
type GoogleGenerativeAIUrlContextMetadata = UrlContextMetadataSchema;
|
|
164
167
|
type GoogleGenerativeAISafetyRating = SafetyRatingSchema;
|
|
168
|
+
type GoogleGenerativeAIPromptFeedback = PromptFeedbackSchema;
|
|
169
|
+
type GoogleGenerativeAIUsageMetadata = UsageMetadataSchema;
|
|
165
170
|
interface GoogleGenerativeAIProviderMetadata {
|
|
171
|
+
promptFeedback: GoogleGenerativeAIPromptFeedback | null;
|
|
166
172
|
groundingMetadata: GoogleGenerativeAIGroundingMetadata | null;
|
|
167
173
|
urlContextMetadata: GoogleGenerativeAIUrlContextMetadata | null;
|
|
168
174
|
safetyRatings: GoogleGenerativeAISafetyRating[] | null;
|
|
175
|
+
usageMetadata: GoogleGenerativeAIUsageMetadata | null;
|
|
176
|
+
finishMessage: string | null;
|
|
169
177
|
}
|
|
170
178
|
|
|
171
179
|
type GoogleGenerativeAIImageModelId = 'imagen-4.0-generate-001' | 'imagen-4.0-ultra-generate-001' | 'imagen-4.0-fast-generate-001' | 'gemini-2.5-flash-image' | 'gemini-3-pro-image-preview' | 'gemini-3.1-flash-image-preview' | (string & {});
|
package/dist/index.d.ts
CHANGED
|
@@ -73,6 +73,7 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
73
73
|
})[] | null | undefined;
|
|
74
74
|
} | null | undefined;
|
|
75
75
|
finishReason?: string | null | undefined;
|
|
76
|
+
finishMessage?: string | null | undefined;
|
|
76
77
|
safetyRatings?: {
|
|
77
78
|
category?: string | null | undefined;
|
|
78
79
|
probability?: string | null | undefined;
|
|
@@ -158,14 +159,21 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
158
159
|
type GroundingMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['groundingMetadata']>;
|
|
159
160
|
type UrlContextMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['urlContextMetadata']>;
|
|
160
161
|
type SafetyRatingSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['safetyRatings']>[number];
|
|
162
|
+
type PromptFeedbackSchema = NonNullable<InferSchema<typeof responseSchema>['promptFeedback']>;
|
|
163
|
+
type UsageMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['usageMetadata']>;
|
|
161
164
|
|
|
162
165
|
type GoogleGenerativeAIGroundingMetadata = GroundingMetadataSchema;
|
|
163
166
|
type GoogleGenerativeAIUrlContextMetadata = UrlContextMetadataSchema;
|
|
164
167
|
type GoogleGenerativeAISafetyRating = SafetyRatingSchema;
|
|
168
|
+
type GoogleGenerativeAIPromptFeedback = PromptFeedbackSchema;
|
|
169
|
+
type GoogleGenerativeAIUsageMetadata = UsageMetadataSchema;
|
|
165
170
|
interface GoogleGenerativeAIProviderMetadata {
|
|
171
|
+
promptFeedback: GoogleGenerativeAIPromptFeedback | null;
|
|
166
172
|
groundingMetadata: GoogleGenerativeAIGroundingMetadata | null;
|
|
167
173
|
urlContextMetadata: GoogleGenerativeAIUrlContextMetadata | null;
|
|
168
174
|
safetyRatings: GoogleGenerativeAISafetyRating[] | null;
|
|
175
|
+
usageMetadata: GoogleGenerativeAIUsageMetadata | null;
|
|
176
|
+
finishMessage: string | null;
|
|
169
177
|
}
|
|
170
178
|
|
|
171
179
|
type GoogleGenerativeAIImageModelId = 'imagen-4.0-generate-001' | 'imagen-4.0-ultra-generate-001' | 'imagen-4.0-fast-generate-001' | 'gemini-2.5-flash-image' | 'gemini-3-pro-image-preview' | 'gemini-3.1-flash-image-preview' | (string & {});
|
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,
|
|
@@ -1048,7 +1132,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1048
1132
|
};
|
|
1049
1133
|
}
|
|
1050
1134
|
async doGenerate(options) {
|
|
1051
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
1135
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
1052
1136
|
const { args, warnings, providerOptionsName } = await this.getArgs(options);
|
|
1053
1137
|
const mergedHeaders = (0, import_provider_utils6.combineHeaders)(
|
|
1054
1138
|
await (0, import_provider_utils6.resolve)(this.config.headers),
|
|
@@ -1170,7 +1254,8 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1170
1254
|
groundingMetadata: (_h = candidate.groundingMetadata) != null ? _h : null,
|
|
1171
1255
|
urlContextMetadata: (_i = candidate.urlContextMetadata) != null ? _i : null,
|
|
1172
1256
|
safetyRatings: (_j = candidate.safetyRatings) != null ? _j : null,
|
|
1173
|
-
usageMetadata: usageMetadata != null ? usageMetadata : null
|
|
1257
|
+
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
1258
|
+
finishMessage: (_k = candidate.finishMessage) != null ? _k : null
|
|
1174
1259
|
}
|
|
1175
1260
|
},
|
|
1176
1261
|
request: { body: args },
|
|
@@ -1220,7 +1305,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1220
1305
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1221
1306
|
},
|
|
1222
1307
|
transform(chunk, controller) {
|
|
1223
|
-
var _a, _b, _c, _d, _e, _f;
|
|
1308
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1224
1309
|
if (options.includeRawChunks) {
|
|
1225
1310
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1226
1311
|
}
|
|
@@ -1422,12 +1507,11 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1422
1507
|
promptFeedback: (_e = value.promptFeedback) != null ? _e : null,
|
|
1423
1508
|
groundingMetadata: lastGroundingMetadata,
|
|
1424
1509
|
urlContextMetadata: lastUrlContextMetadata,
|
|
1425
|
-
safetyRatings: (_f = candidate.safetyRatings) != null ? _f : null
|
|
1510
|
+
safetyRatings: (_f = candidate.safetyRatings) != null ? _f : null,
|
|
1511
|
+
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
1512
|
+
finishMessage: (_g = candidate.finishMessage) != null ? _g : null
|
|
1426
1513
|
}
|
|
1427
1514
|
};
|
|
1428
|
-
if (usageMetadata != null) {
|
|
1429
|
-
providerMetadata[providerOptionsName].usageMetadata = usageMetadata;
|
|
1430
|
-
}
|
|
1431
1515
|
}
|
|
1432
1516
|
},
|
|
1433
1517
|
flush(controller) {
|
|
@@ -1687,6 +1771,7 @@ var responseSchema = (0, import_provider_utils6.lazySchema)(
|
|
|
1687
1771
|
import_v45.z.object({
|
|
1688
1772
|
content: getContentSchema().nullish().or(import_v45.z.object({}).strict()),
|
|
1689
1773
|
finishReason: import_v45.z.string().nullish(),
|
|
1774
|
+
finishMessage: import_v45.z.string().nullish(),
|
|
1690
1775
|
safetyRatings: import_v45.z.array(getSafetyRatingSchema()).nullish(),
|
|
1691
1776
|
groundingMetadata: getGroundingMetadataSchema().nullish(),
|
|
1692
1777
|
urlContextMetadata: getUrlContextMetadataSchema().nullish()
|
|
@@ -1707,6 +1792,7 @@ var chunkSchema = (0, import_provider_utils6.lazySchema)(
|
|
|
1707
1792
|
import_v45.z.object({
|
|
1708
1793
|
content: getContentSchema().nullish(),
|
|
1709
1794
|
finishReason: import_v45.z.string().nullish(),
|
|
1795
|
+
finishMessage: import_v45.z.string().nullish(),
|
|
1710
1796
|
safetyRatings: import_v45.z.array(getSafetyRatingSchema()).nullish(),
|
|
1711
1797
|
groundingMetadata: getGroundingMetadataSchema().nullish(),
|
|
1712
1798
|
urlContextMetadata: getUrlContextMetadataSchema().nullish()
|