@ai-sdk/google 2.0.61 → 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 +17 -0
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +104 -47
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +101 -44
- 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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @ai-sdk/google
|
|
2
2
|
|
|
3
|
+
## 2.0.63
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 7655bcf: feat(provider/google): Add multimodal tool-result support for Google function responses.
|
|
8
|
+
|
|
9
|
+
Tool results with `output.type = 'content'` now map media parts into
|
|
10
|
+
`functionResponse.parts` for Google models, including `image-data`,
|
|
11
|
+
`file-data`, and base64 `data:` URLs in URL-style content parts.
|
|
12
|
+
Remote HTTP(S) URLs in URL-style tool-result parts are not supported.
|
|
13
|
+
|
|
14
|
+
## 2.0.62
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- a608d48: feat(provider/google): add `gemini-embedding-2-preview` and fix multimodal embedding support with `embedMany`
|
|
19
|
+
|
|
3
20
|
## 2.0.61
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -180,18 +180,18 @@ declare const googleImageProviderOptionsSchema: _ai_sdk_provider_utils.LazySchem
|
|
|
180
180
|
}>;
|
|
181
181
|
type GoogleGenerativeAIImageProviderOptions = InferValidator<typeof googleImageProviderOptionsSchema>;
|
|
182
182
|
|
|
183
|
-
type GoogleGenerativeAIEmbeddingModelId = 'gemini-embedding-001' | '
|
|
183
|
+
type GoogleGenerativeAIEmbeddingModelId = 'gemini-embedding-001' | 'gemini-embedding-2-preview' | (string & {});
|
|
184
184
|
declare const googleGenerativeAIEmbeddingProviderOptions: _ai_sdk_provider_utils.LazySchema<{
|
|
185
185
|
outputDimensionality?: number | undefined;
|
|
186
186
|
taskType?: "SEMANTIC_SIMILARITY" | "CLASSIFICATION" | "CLUSTERING" | "RETRIEVAL_DOCUMENT" | "RETRIEVAL_QUERY" | "QUESTION_ANSWERING" | "FACT_VERIFICATION" | "CODE_RETRIEVAL_QUERY" | undefined;
|
|
187
|
-
content?: ({
|
|
187
|
+
content?: (({
|
|
188
188
|
text: string;
|
|
189
189
|
} | {
|
|
190
190
|
inlineData: {
|
|
191
191
|
mimeType: string;
|
|
192
192
|
data: string;
|
|
193
193
|
};
|
|
194
|
-
})[] | undefined;
|
|
194
|
+
})[] | null)[] | undefined;
|
|
195
195
|
}>;
|
|
196
196
|
type GoogleGenerativeAIEmbeddingProviderOptions = InferValidator<typeof googleGenerativeAIEmbeddingProviderOptions>;
|
|
197
197
|
|
package/dist/index.d.ts
CHANGED
|
@@ -180,18 +180,18 @@ declare const googleImageProviderOptionsSchema: _ai_sdk_provider_utils.LazySchem
|
|
|
180
180
|
}>;
|
|
181
181
|
type GoogleGenerativeAIImageProviderOptions = InferValidator<typeof googleImageProviderOptionsSchema>;
|
|
182
182
|
|
|
183
|
-
type GoogleGenerativeAIEmbeddingModelId = 'gemini-embedding-001' | '
|
|
183
|
+
type GoogleGenerativeAIEmbeddingModelId = 'gemini-embedding-001' | 'gemini-embedding-2-preview' | (string & {});
|
|
184
184
|
declare const googleGenerativeAIEmbeddingProviderOptions: _ai_sdk_provider_utils.LazySchema<{
|
|
185
185
|
outputDimensionality?: number | undefined;
|
|
186
186
|
taskType?: "SEMANTIC_SIMILARITY" | "CLASSIFICATION" | "CLUSTERING" | "RETRIEVAL_DOCUMENT" | "RETRIEVAL_QUERY" | "QUESTION_ANSWERING" | "FACT_VERIFICATION" | "CODE_RETRIEVAL_QUERY" | undefined;
|
|
187
|
-
content?: ({
|
|
187
|
+
content?: (({
|
|
188
188
|
text: string;
|
|
189
189
|
} | {
|
|
190
190
|
inlineData: {
|
|
191
191
|
mimeType: string;
|
|
192
192
|
data: string;
|
|
193
193
|
};
|
|
194
|
-
})[] | undefined;
|
|
194
|
+
})[] | null)[] | undefined;
|
|
195
195
|
}>;
|
|
196
196
|
type GoogleGenerativeAIEmbeddingProviderOptions = InferValidator<typeof googleGenerativeAIEmbeddingProviderOptions>;
|
|
197
197
|
|
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_utils15 = require("@ai-sdk/provider-utils");
|
|
31
31
|
|
|
32
32
|
// src/version.ts
|
|
33
|
-
var VERSION = true ? "2.0.
|
|
33
|
+
var VERSION = true ? "2.0.63" : "0.0.0-test";
|
|
34
34
|
|
|
35
35
|
// src/google-generative-ai-embedding-model.ts
|
|
36
36
|
var import_provider = require("@ai-sdk/provider");
|
|
@@ -99,11 +99,15 @@ var googleGenerativeAIEmbeddingProviderOptions = (0, import_provider_utils2.lazy
|
|
|
99
99
|
"CODE_RETRIEVAL_QUERY"
|
|
100
100
|
]).optional(),
|
|
101
101
|
/**
|
|
102
|
-
* Optional.
|
|
103
|
-
* (images, video, PDF, audio).
|
|
104
|
-
*
|
|
102
|
+
* Optional. Per-value multimodal content parts for embedding non-text
|
|
103
|
+
* content (images, video, PDF, audio). Each entry corresponds to the
|
|
104
|
+
* embedding value at the same index and its parts are merged with the
|
|
105
|
+
* text value in the request. Use `null` for entries that are text-only.
|
|
106
|
+
*
|
|
107
|
+
* The array length must match the number of values being embedded. In
|
|
108
|
+
* the case of a single embedding, the array length must be 1.
|
|
105
109
|
*/
|
|
106
|
-
content: import_v42.z.array(googleEmbeddingContentPartSchema).min(1).optional()
|
|
110
|
+
content: import_v42.z.array(import_v42.z.array(googleEmbeddingContentPartSchema).min(1).nullable()).optional()
|
|
107
111
|
})
|
|
108
112
|
)
|
|
109
113
|
);
|
|
@@ -126,7 +130,6 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
|
126
130
|
abortSignal,
|
|
127
131
|
providerOptions
|
|
128
132
|
}) {
|
|
129
|
-
var _a;
|
|
130
133
|
const googleOptions = await (0, import_provider_utils3.parseProviderOptions)({
|
|
131
134
|
provider: "google",
|
|
132
135
|
providerOptions,
|
|
@@ -144,10 +147,16 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
|
144
147
|
await (0, import_provider_utils3.resolve)(this.config.headers),
|
|
145
148
|
headers
|
|
146
149
|
);
|
|
147
|
-
const multimodalContent =
|
|
150
|
+
const multimodalContent = googleOptions == null ? void 0 : googleOptions.content;
|
|
151
|
+
if (multimodalContent != null && multimodalContent.length !== values.length) {
|
|
152
|
+
throw new Error(
|
|
153
|
+
`The number of multimodal content entries (${multimodalContent.length}) must match the number of values (${values.length}).`
|
|
154
|
+
);
|
|
155
|
+
}
|
|
148
156
|
if (values.length === 1) {
|
|
157
|
+
const valueParts = multimodalContent == null ? void 0 : multimodalContent[0];
|
|
149
158
|
const textPart = values[0] ? [{ text: values[0] }] : [];
|
|
150
|
-
const parts =
|
|
159
|
+
const parts = valueParts != null ? [...textPart, ...valueParts] : [{ text: values[0] }];
|
|
151
160
|
const {
|
|
152
161
|
responseHeaders: responseHeaders2,
|
|
153
162
|
value: response2,
|
|
@@ -184,13 +193,14 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
|
184
193
|
url: `${this.config.baseURL}/models/${this.modelId}:batchEmbedContents`,
|
|
185
194
|
headers: mergedHeaders,
|
|
186
195
|
body: {
|
|
187
|
-
requests: values.map((value) => {
|
|
196
|
+
requests: values.map((value, index) => {
|
|
197
|
+
const valueParts = multimodalContent == null ? void 0 : multimodalContent[index];
|
|
188
198
|
const textPart = value ? [{ text: value }] : [];
|
|
189
199
|
return {
|
|
190
200
|
model: `models/${this.modelId}`,
|
|
191
201
|
content: {
|
|
192
202
|
role: "user",
|
|
193
|
-
parts:
|
|
203
|
+
parts: valueParts != null ? [...textPart, ...valueParts] : [{ text: value }]
|
|
194
204
|
},
|
|
195
205
|
outputDimensionality: googleOptions == null ? void 0 : googleOptions.outputDimensionality,
|
|
196
206
|
taskType: googleOptions == null ? void 0 : googleOptions.taskType
|
|
@@ -350,11 +360,12 @@ function isEmptyObjectSchema(jsonSchema) {
|
|
|
350
360
|
var import_provider2 = require("@ai-sdk/provider");
|
|
351
361
|
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
|
352
362
|
function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
353
|
-
var _a;
|
|
363
|
+
var _a, _b;
|
|
354
364
|
const systemInstructionParts = [];
|
|
355
365
|
const contents = [];
|
|
356
366
|
let systemMessagesAllowed = true;
|
|
357
367
|
const isGemmaModel = (_a = options == null ? void 0 : options.isGemmaModel) != null ? _a : false;
|
|
368
|
+
const supportsFunctionResponseParts = (_b = options == null ? void 0 : options.supportsFunctionResponseParts) != null ? _b : true;
|
|
358
369
|
for (const { role, content } of prompt) {
|
|
359
370
|
switch (role) {
|
|
360
371
|
case "system": {
|
|
@@ -402,8 +413,8 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
402
413
|
contents.push({
|
|
403
414
|
role: "model",
|
|
404
415
|
parts: content.map((part) => {
|
|
405
|
-
var _a2,
|
|
406
|
-
const thoughtSignature = ((
|
|
416
|
+
var _a2, _b2, _c;
|
|
417
|
+
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;
|
|
407
418
|
switch (part.type) {
|
|
408
419
|
case "text": {
|
|
409
420
|
return part.text.length === 0 ? void 0 : {
|
|
@@ -456,36 +467,10 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
456
467
|
for (const part of content) {
|
|
457
468
|
const output = part.output;
|
|
458
469
|
if (output.type === "content") {
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
functionResponse: {
|
|
464
|
-
name: part.toolName,
|
|
465
|
-
response: {
|
|
466
|
-
name: part.toolName,
|
|
467
|
-
content: contentPart.text
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
});
|
|
471
|
-
break;
|
|
472
|
-
case "media":
|
|
473
|
-
parts.push(
|
|
474
|
-
{
|
|
475
|
-
inlineData: {
|
|
476
|
-
mimeType: contentPart.mediaType,
|
|
477
|
-
data: contentPart.data
|
|
478
|
-
}
|
|
479
|
-
},
|
|
480
|
-
{
|
|
481
|
-
text: "Tool executed successfully and returned this image as a response"
|
|
482
|
-
}
|
|
483
|
-
);
|
|
484
|
-
break;
|
|
485
|
-
default:
|
|
486
|
-
parts.push({ text: JSON.stringify(contentPart) });
|
|
487
|
-
break;
|
|
488
|
-
}
|
|
470
|
+
if (supportsFunctionResponseParts) {
|
|
471
|
+
appendToolResultParts({ parts, part, output });
|
|
472
|
+
} else {
|
|
473
|
+
appendLegacyToolResultParts({ parts, part, output });
|
|
489
474
|
}
|
|
490
475
|
} else {
|
|
491
476
|
parts.push({
|
|
@@ -516,6 +501,77 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
516
501
|
contents
|
|
517
502
|
};
|
|
518
503
|
}
|
|
504
|
+
function appendToolResultParts({
|
|
505
|
+
parts,
|
|
506
|
+
part,
|
|
507
|
+
output
|
|
508
|
+
}) {
|
|
509
|
+
const responseTextParts = [];
|
|
510
|
+
const functionResponseParts = [];
|
|
511
|
+
for (const contentPart of output.value) {
|
|
512
|
+
switch (contentPart.type) {
|
|
513
|
+
case "text":
|
|
514
|
+
responseTextParts.push(contentPart.text);
|
|
515
|
+
break;
|
|
516
|
+
case "media":
|
|
517
|
+
functionResponseParts.push({
|
|
518
|
+
inlineData: {
|
|
519
|
+
mimeType: contentPart.mediaType,
|
|
520
|
+
data: contentPart.data
|
|
521
|
+
}
|
|
522
|
+
});
|
|
523
|
+
break;
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
const responseText = responseTextParts.length > 0 ? responseTextParts.join("\n") : "Tool executed successfully.";
|
|
527
|
+
parts.push({
|
|
528
|
+
functionResponse: {
|
|
529
|
+
name: part.toolName,
|
|
530
|
+
response: {
|
|
531
|
+
name: part.toolName,
|
|
532
|
+
content: responseText
|
|
533
|
+
},
|
|
534
|
+
...functionResponseParts.length > 0 ? { parts: functionResponseParts } : {}
|
|
535
|
+
}
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
function appendLegacyToolResultParts({
|
|
539
|
+
parts,
|
|
540
|
+
part,
|
|
541
|
+
output
|
|
542
|
+
}) {
|
|
543
|
+
for (const contentPart of output.value) {
|
|
544
|
+
switch (contentPart.type) {
|
|
545
|
+
case "text":
|
|
546
|
+
parts.push({
|
|
547
|
+
functionResponse: {
|
|
548
|
+
name: part.toolName,
|
|
549
|
+
response: {
|
|
550
|
+
name: part.toolName,
|
|
551
|
+
content: contentPart.text
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
});
|
|
555
|
+
break;
|
|
556
|
+
case "media":
|
|
557
|
+
parts.push(
|
|
558
|
+
{
|
|
559
|
+
inlineData: {
|
|
560
|
+
mimeType: contentPart.mediaType,
|
|
561
|
+
data: contentPart.data
|
|
562
|
+
}
|
|
563
|
+
},
|
|
564
|
+
{
|
|
565
|
+
text: "Tool executed successfully and returned this image as a response"
|
|
566
|
+
}
|
|
567
|
+
);
|
|
568
|
+
break;
|
|
569
|
+
default:
|
|
570
|
+
parts.push({ text: JSON.stringify(contentPart) });
|
|
571
|
+
break;
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
}
|
|
519
575
|
|
|
520
576
|
// src/get-model-path.ts
|
|
521
577
|
function getModelPath(modelId) {
|
|
@@ -916,9 +972,10 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
916
972
|
});
|
|
917
973
|
}
|
|
918
974
|
const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
|
|
975
|
+
const supportsFunctionResponseParts = this.modelId.startsWith("gemini-3");
|
|
919
976
|
const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
|
|
920
977
|
prompt,
|
|
921
|
-
{ isGemmaModel }
|
|
978
|
+
{ isGemmaModel, supportsFunctionResponseParts }
|
|
922
979
|
);
|
|
923
980
|
const {
|
|
924
981
|
tools: googleTools2,
|