@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/dist/internal/index.js
CHANGED
|
@@ -18,14 +18,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
|
|
20
20
|
// src/internal/index.ts
|
|
21
|
-
var
|
|
22
|
-
__export(
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
23
|
GoogleGenerativeAILanguageModel: () => GoogleGenerativeAILanguageModel,
|
|
24
24
|
getGroundingMetadataSchema: () => getGroundingMetadataSchema,
|
|
25
25
|
getUrlContextMetadataSchema: () => getUrlContextMetadataSchema,
|
|
26
26
|
googleTools: () => googleTools
|
|
27
27
|
});
|
|
28
|
-
module.exports = __toCommonJS(
|
|
28
|
+
module.exports = __toCommonJS(index_exports);
|
|
29
29
|
|
|
30
30
|
// src/google-generative-ai-language-model.ts
|
|
31
31
|
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
|
@@ -151,11 +151,12 @@ function isEmptyObjectSchema(jsonSchema) {
|
|
|
151
151
|
var import_provider = require("@ai-sdk/provider");
|
|
152
152
|
var import_provider_utils = require("@ai-sdk/provider-utils");
|
|
153
153
|
function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
154
|
-
var _a;
|
|
154
|
+
var _a, _b;
|
|
155
155
|
const systemInstructionParts = [];
|
|
156
156
|
const contents = [];
|
|
157
157
|
let systemMessagesAllowed = true;
|
|
158
158
|
const isGemmaModel = (_a = options == null ? void 0 : options.isGemmaModel) != null ? _a : false;
|
|
159
|
+
const supportsFunctionResponseParts = (_b = options == null ? void 0 : options.supportsFunctionResponseParts) != null ? _b : true;
|
|
159
160
|
for (const { role, content } of prompt) {
|
|
160
161
|
switch (role) {
|
|
161
162
|
case "system": {
|
|
@@ -203,8 +204,8 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
203
204
|
contents.push({
|
|
204
205
|
role: "model",
|
|
205
206
|
parts: content.map((part) => {
|
|
206
|
-
var _a2,
|
|
207
|
-
const thoughtSignature = ((
|
|
207
|
+
var _a2, _b2, _c;
|
|
208
|
+
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;
|
|
208
209
|
switch (part.type) {
|
|
209
210
|
case "text": {
|
|
210
211
|
return part.text.length === 0 ? void 0 : {
|
|
@@ -257,36 +258,10 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
257
258
|
for (const part of content) {
|
|
258
259
|
const output = part.output;
|
|
259
260
|
if (output.type === "content") {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
functionResponse: {
|
|
265
|
-
name: part.toolName,
|
|
266
|
-
response: {
|
|
267
|
-
name: part.toolName,
|
|
268
|
-
content: contentPart.text
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
});
|
|
272
|
-
break;
|
|
273
|
-
case "media":
|
|
274
|
-
parts.push(
|
|
275
|
-
{
|
|
276
|
-
inlineData: {
|
|
277
|
-
mimeType: contentPart.mediaType,
|
|
278
|
-
data: contentPart.data
|
|
279
|
-
}
|
|
280
|
-
},
|
|
281
|
-
{
|
|
282
|
-
text: "Tool executed successfully and returned this image as a response"
|
|
283
|
-
}
|
|
284
|
-
);
|
|
285
|
-
break;
|
|
286
|
-
default:
|
|
287
|
-
parts.push({ text: JSON.stringify(contentPart) });
|
|
288
|
-
break;
|
|
289
|
-
}
|
|
261
|
+
if (supportsFunctionResponseParts) {
|
|
262
|
+
appendToolResultParts({ parts, part, output });
|
|
263
|
+
} else {
|
|
264
|
+
appendLegacyToolResultParts({ parts, part, output });
|
|
290
265
|
}
|
|
291
266
|
} else {
|
|
292
267
|
parts.push({
|
|
@@ -317,6 +292,77 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
317
292
|
contents
|
|
318
293
|
};
|
|
319
294
|
}
|
|
295
|
+
function appendToolResultParts({
|
|
296
|
+
parts,
|
|
297
|
+
part,
|
|
298
|
+
output
|
|
299
|
+
}) {
|
|
300
|
+
const responseTextParts = [];
|
|
301
|
+
const functionResponseParts = [];
|
|
302
|
+
for (const contentPart of output.value) {
|
|
303
|
+
switch (contentPart.type) {
|
|
304
|
+
case "text":
|
|
305
|
+
responseTextParts.push(contentPart.text);
|
|
306
|
+
break;
|
|
307
|
+
case "media":
|
|
308
|
+
functionResponseParts.push({
|
|
309
|
+
inlineData: {
|
|
310
|
+
mimeType: contentPart.mediaType,
|
|
311
|
+
data: contentPart.data
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
break;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
const responseText = responseTextParts.length > 0 ? responseTextParts.join("\n") : "Tool executed successfully.";
|
|
318
|
+
parts.push({
|
|
319
|
+
functionResponse: {
|
|
320
|
+
name: part.toolName,
|
|
321
|
+
response: {
|
|
322
|
+
name: part.toolName,
|
|
323
|
+
content: responseText
|
|
324
|
+
},
|
|
325
|
+
...functionResponseParts.length > 0 ? { parts: functionResponseParts } : {}
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
function appendLegacyToolResultParts({
|
|
330
|
+
parts,
|
|
331
|
+
part,
|
|
332
|
+
output
|
|
333
|
+
}) {
|
|
334
|
+
for (const contentPart of output.value) {
|
|
335
|
+
switch (contentPart.type) {
|
|
336
|
+
case "text":
|
|
337
|
+
parts.push({
|
|
338
|
+
functionResponse: {
|
|
339
|
+
name: part.toolName,
|
|
340
|
+
response: {
|
|
341
|
+
name: part.toolName,
|
|
342
|
+
content: contentPart.text
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
break;
|
|
347
|
+
case "media":
|
|
348
|
+
parts.push(
|
|
349
|
+
{
|
|
350
|
+
inlineData: {
|
|
351
|
+
mimeType: contentPart.mediaType,
|
|
352
|
+
data: contentPart.data
|
|
353
|
+
}
|
|
354
|
+
},
|
|
355
|
+
{
|
|
356
|
+
text: "Tool executed successfully and returned this image as a response"
|
|
357
|
+
}
|
|
358
|
+
);
|
|
359
|
+
break;
|
|
360
|
+
default:
|
|
361
|
+
parts.push({ text: JSON.stringify(contentPart) });
|
|
362
|
+
break;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
320
366
|
|
|
321
367
|
// src/get-model-path.ts
|
|
322
368
|
function getModelPath(modelId) {
|
|
@@ -736,9 +782,10 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
736
782
|
});
|
|
737
783
|
}
|
|
738
784
|
const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
|
|
785
|
+
const supportsFunctionResponseParts = this.modelId.startsWith("gemini-3");
|
|
739
786
|
const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
|
|
740
787
|
prompt,
|
|
741
|
-
{ isGemmaModel }
|
|
788
|
+
{ isGemmaModel, supportsFunctionResponseParts }
|
|
742
789
|
);
|
|
743
790
|
const {
|
|
744
791
|
tools: googleTools2,
|