@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/internal/index.mjs
CHANGED
|
@@ -134,11 +134,12 @@ import {
|
|
|
134
134
|
} from "@ai-sdk/provider";
|
|
135
135
|
import { convertToBase64 } from "@ai-sdk/provider-utils";
|
|
136
136
|
function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
137
|
-
var _a;
|
|
137
|
+
var _a, _b;
|
|
138
138
|
const systemInstructionParts = [];
|
|
139
139
|
const contents = [];
|
|
140
140
|
let systemMessagesAllowed = true;
|
|
141
141
|
const isGemmaModel = (_a = options == null ? void 0 : options.isGemmaModel) != null ? _a : false;
|
|
142
|
+
const supportsFunctionResponseParts = (_b = options == null ? void 0 : options.supportsFunctionResponseParts) != null ? _b : true;
|
|
142
143
|
for (const { role, content } of prompt) {
|
|
143
144
|
switch (role) {
|
|
144
145
|
case "system": {
|
|
@@ -186,8 +187,8 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
186
187
|
contents.push({
|
|
187
188
|
role: "model",
|
|
188
189
|
parts: content.map((part) => {
|
|
189
|
-
var _a2,
|
|
190
|
-
const thoughtSignature = ((
|
|
190
|
+
var _a2, _b2, _c;
|
|
191
|
+
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;
|
|
191
192
|
switch (part.type) {
|
|
192
193
|
case "text": {
|
|
193
194
|
return part.text.length === 0 ? void 0 : {
|
|
@@ -240,36 +241,10 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
240
241
|
for (const part of content) {
|
|
241
242
|
const output = part.output;
|
|
242
243
|
if (output.type === "content") {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
functionResponse: {
|
|
248
|
-
name: part.toolName,
|
|
249
|
-
response: {
|
|
250
|
-
name: part.toolName,
|
|
251
|
-
content: contentPart.text
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
});
|
|
255
|
-
break;
|
|
256
|
-
case "media":
|
|
257
|
-
parts.push(
|
|
258
|
-
{
|
|
259
|
-
inlineData: {
|
|
260
|
-
mimeType: contentPart.mediaType,
|
|
261
|
-
data: contentPart.data
|
|
262
|
-
}
|
|
263
|
-
},
|
|
264
|
-
{
|
|
265
|
-
text: "Tool executed successfully and returned this image as a response"
|
|
266
|
-
}
|
|
267
|
-
);
|
|
268
|
-
break;
|
|
269
|
-
default:
|
|
270
|
-
parts.push({ text: JSON.stringify(contentPart) });
|
|
271
|
-
break;
|
|
272
|
-
}
|
|
244
|
+
if (supportsFunctionResponseParts) {
|
|
245
|
+
appendToolResultParts({ parts, part, output });
|
|
246
|
+
} else {
|
|
247
|
+
appendLegacyToolResultParts({ parts, part, output });
|
|
273
248
|
}
|
|
274
249
|
} else {
|
|
275
250
|
parts.push({
|
|
@@ -300,6 +275,77 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
300
275
|
contents
|
|
301
276
|
};
|
|
302
277
|
}
|
|
278
|
+
function appendToolResultParts({
|
|
279
|
+
parts,
|
|
280
|
+
part,
|
|
281
|
+
output
|
|
282
|
+
}) {
|
|
283
|
+
const responseTextParts = [];
|
|
284
|
+
const functionResponseParts = [];
|
|
285
|
+
for (const contentPart of output.value) {
|
|
286
|
+
switch (contentPart.type) {
|
|
287
|
+
case "text":
|
|
288
|
+
responseTextParts.push(contentPart.text);
|
|
289
|
+
break;
|
|
290
|
+
case "media":
|
|
291
|
+
functionResponseParts.push({
|
|
292
|
+
inlineData: {
|
|
293
|
+
mimeType: contentPart.mediaType,
|
|
294
|
+
data: contentPart.data
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
break;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
const responseText = responseTextParts.length > 0 ? responseTextParts.join("\n") : "Tool executed successfully.";
|
|
301
|
+
parts.push({
|
|
302
|
+
functionResponse: {
|
|
303
|
+
name: part.toolName,
|
|
304
|
+
response: {
|
|
305
|
+
name: part.toolName,
|
|
306
|
+
content: responseText
|
|
307
|
+
},
|
|
308
|
+
...functionResponseParts.length > 0 ? { parts: functionResponseParts } : {}
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
function appendLegacyToolResultParts({
|
|
313
|
+
parts,
|
|
314
|
+
part,
|
|
315
|
+
output
|
|
316
|
+
}) {
|
|
317
|
+
for (const contentPart of output.value) {
|
|
318
|
+
switch (contentPart.type) {
|
|
319
|
+
case "text":
|
|
320
|
+
parts.push({
|
|
321
|
+
functionResponse: {
|
|
322
|
+
name: part.toolName,
|
|
323
|
+
response: {
|
|
324
|
+
name: part.toolName,
|
|
325
|
+
content: contentPart.text
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
break;
|
|
330
|
+
case "media":
|
|
331
|
+
parts.push(
|
|
332
|
+
{
|
|
333
|
+
inlineData: {
|
|
334
|
+
mimeType: contentPart.mediaType,
|
|
335
|
+
data: contentPart.data
|
|
336
|
+
}
|
|
337
|
+
},
|
|
338
|
+
{
|
|
339
|
+
text: "Tool executed successfully and returned this image as a response"
|
|
340
|
+
}
|
|
341
|
+
);
|
|
342
|
+
break;
|
|
343
|
+
default:
|
|
344
|
+
parts.push({ text: JSON.stringify(contentPart) });
|
|
345
|
+
break;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
303
349
|
|
|
304
350
|
// src/get-model-path.ts
|
|
305
351
|
function getModelPath(modelId) {
|
|
@@ -728,9 +774,10 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
728
774
|
});
|
|
729
775
|
}
|
|
730
776
|
const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
|
|
777
|
+
const supportsFunctionResponseParts = this.modelId.startsWith("gemini-3");
|
|
731
778
|
const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
|
|
732
779
|
prompt,
|
|
733
|
-
{ isGemmaModel }
|
|
780
|
+
{ isGemmaModel, supportsFunctionResponseParts }
|
|
734
781
|
);
|
|
735
782
|
const {
|
|
736
783
|
tools: googleTools2,
|