@ai-sdk/google 3.0.72 → 3.0.74
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 +12 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +50 -29
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +50 -29
- 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 +43 -28
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +43 -28
- package/dist/internal/index.mjs.map +1 -1
- package/docs/15-google-generative-ai.mdx +1 -1
- package/package.json +3 -3
- package/src/convert-to-google-generative-ai-messages.ts +20 -2
- package/src/google-generative-ai-embedding-options.ts +6 -0
- package/src/google-generative-ai-language-model.ts +5 -4
- package/src/google-generative-ai-prompt.ts +5 -1
package/dist/internal/index.d.ts
CHANGED
package/dist/internal/index.js
CHANGED
|
@@ -212,7 +212,7 @@ function convertUrlToolResultPart(url) {
|
|
|
212
212
|
}
|
|
213
213
|
};
|
|
214
214
|
}
|
|
215
|
-
function appendToolResultParts(parts, toolName, outputValue) {
|
|
215
|
+
function appendToolResultParts(parts, toolName, outputValue, toolCallId) {
|
|
216
216
|
const functionResponseParts = [];
|
|
217
217
|
const responseTextParts = [];
|
|
218
218
|
for (const contentPart of outputValue) {
|
|
@@ -251,6 +251,7 @@ function appendToolResultParts(parts, toolName, outputValue) {
|
|
|
251
251
|
}
|
|
252
252
|
parts.push({
|
|
253
253
|
functionResponse: {
|
|
254
|
+
...toolCallId != null ? { id: toolCallId } : {},
|
|
254
255
|
name: toolName,
|
|
255
256
|
response: {
|
|
256
257
|
name: toolName,
|
|
@@ -260,12 +261,13 @@ function appendToolResultParts(parts, toolName, outputValue) {
|
|
|
260
261
|
}
|
|
261
262
|
});
|
|
262
263
|
}
|
|
263
|
-
function appendLegacyToolResultParts(parts, toolName, outputValue) {
|
|
264
|
+
function appendLegacyToolResultParts(parts, toolName, outputValue, toolCallId) {
|
|
264
265
|
for (const contentPart of outputValue) {
|
|
265
266
|
switch (contentPart.type) {
|
|
266
267
|
case "text":
|
|
267
268
|
parts.push({
|
|
268
269
|
functionResponse: {
|
|
270
|
+
...toolCallId != null ? { id: toolCallId } : {},
|
|
269
271
|
name: toolName,
|
|
270
272
|
response: {
|
|
271
273
|
name: toolName,
|
|
@@ -395,6 +397,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
395
397
|
}
|
|
396
398
|
return {
|
|
397
399
|
functionCall: {
|
|
400
|
+
...part.toolCallId != null ? { id: part.toolCallId } : {},
|
|
398
401
|
name: part.toolName,
|
|
399
402
|
args: part.input
|
|
400
403
|
},
|
|
@@ -451,13 +454,24 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
451
454
|
const output = part.output;
|
|
452
455
|
if (output.type === "content") {
|
|
453
456
|
if (supportsFunctionResponseParts) {
|
|
454
|
-
appendToolResultParts(
|
|
457
|
+
appendToolResultParts(
|
|
458
|
+
parts,
|
|
459
|
+
part.toolName,
|
|
460
|
+
output.value,
|
|
461
|
+
part.toolCallId
|
|
462
|
+
);
|
|
455
463
|
} else {
|
|
456
|
-
appendLegacyToolResultParts(
|
|
464
|
+
appendLegacyToolResultParts(
|
|
465
|
+
parts,
|
|
466
|
+
part.toolName,
|
|
467
|
+
output.value,
|
|
468
|
+
part.toolCallId
|
|
469
|
+
);
|
|
457
470
|
}
|
|
458
471
|
} else {
|
|
459
472
|
parts.push({
|
|
460
473
|
functionResponse: {
|
|
474
|
+
...part.toolCallId != null ? { id: part.toolCallId } : {},
|
|
461
475
|
name: part.toolName,
|
|
462
476
|
response: {
|
|
463
477
|
name: part.toolName,
|
|
@@ -1296,7 +1310,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1296
1310
|
};
|
|
1297
1311
|
}
|
|
1298
1312
|
async doGenerate(options) {
|
|
1299
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
1313
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
|
|
1300
1314
|
const { args, warnings, providerOptionsName } = await this.getArgs(options);
|
|
1301
1315
|
const mergedHeaders = (0, import_provider_utils4.combineHeaders)(
|
|
1302
1316
|
await (0, import_provider_utils4.resolve)(this.config.headers),
|
|
@@ -1367,9 +1381,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1367
1381
|
} else if ("functionCall" in part && part.functionCall.name != null) {
|
|
1368
1382
|
content.push({
|
|
1369
1383
|
type: "tool-call",
|
|
1370
|
-
toolCallId: this.config.generateId(),
|
|
1384
|
+
toolCallId: (_e = part.functionCall.id) != null ? _e : this.config.generateId(),
|
|
1371
1385
|
toolName: part.functionCall.name,
|
|
1372
|
-
input: JSON.stringify((
|
|
1386
|
+
input: JSON.stringify((_f = part.functionCall.args) != null ? _f : {}),
|
|
1373
1387
|
providerMetadata: part.thoughtSignature ? {
|
|
1374
1388
|
[providerOptionsName]: {
|
|
1375
1389
|
thoughtSignature: part.thoughtSignature
|
|
@@ -1391,13 +1405,13 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1391
1405
|
} : void 0
|
|
1392
1406
|
});
|
|
1393
1407
|
} else if ("toolCall" in part && part.toolCall) {
|
|
1394
|
-
const toolCallId = (
|
|
1408
|
+
const toolCallId = (_g = part.toolCall.id) != null ? _g : this.config.generateId();
|
|
1395
1409
|
lastServerToolCallId = toolCallId;
|
|
1396
1410
|
content.push({
|
|
1397
1411
|
type: "tool-call",
|
|
1398
1412
|
toolCallId,
|
|
1399
1413
|
toolName: `server:${part.toolCall.toolType}`,
|
|
1400
|
-
input: JSON.stringify((
|
|
1414
|
+
input: JSON.stringify((_h = part.toolCall.args) != null ? _h : {}),
|
|
1401
1415
|
providerExecuted: true,
|
|
1402
1416
|
dynamic: true,
|
|
1403
1417
|
providerMetadata: part.thoughtSignature ? {
|
|
@@ -1414,12 +1428,12 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1414
1428
|
}
|
|
1415
1429
|
});
|
|
1416
1430
|
} else if ("toolResponse" in part && part.toolResponse) {
|
|
1417
|
-
const responseToolCallId = (
|
|
1431
|
+
const responseToolCallId = (_i = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _i : this.config.generateId();
|
|
1418
1432
|
content.push({
|
|
1419
1433
|
type: "tool-result",
|
|
1420
1434
|
toolCallId: responseToolCallId,
|
|
1421
1435
|
toolName: `server:${part.toolResponse.toolType}`,
|
|
1422
|
-
result: (
|
|
1436
|
+
result: (_j = part.toolResponse.response) != null ? _j : {},
|
|
1423
1437
|
providerMetadata: part.thoughtSignature ? {
|
|
1424
1438
|
[providerOptionsName]: {
|
|
1425
1439
|
thoughtSignature: part.thoughtSignature,
|
|
@@ -1436,10 +1450,10 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1436
1450
|
lastServerToolCallId = void 0;
|
|
1437
1451
|
}
|
|
1438
1452
|
}
|
|
1439
|
-
const sources = (
|
|
1453
|
+
const sources = (_k = extractSources({
|
|
1440
1454
|
groundingMetadata: candidate.groundingMetadata,
|
|
1441
1455
|
generateId: this.config.generateId
|
|
1442
|
-
})) != null ?
|
|
1456
|
+
})) != null ? _k : [];
|
|
1443
1457
|
for (const source of sources) {
|
|
1444
1458
|
content.push(source);
|
|
1445
1459
|
}
|
|
@@ -1453,19 +1467,19 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1453
1467
|
(part) => part.type === "tool-call" && !part.providerExecuted
|
|
1454
1468
|
)
|
|
1455
1469
|
}),
|
|
1456
|
-
raw: (
|
|
1470
|
+
raw: (_l = candidate.finishReason) != null ? _l : void 0
|
|
1457
1471
|
},
|
|
1458
1472
|
usage: convertGoogleGenerativeAIUsage(usageMetadata),
|
|
1459
1473
|
warnings,
|
|
1460
1474
|
providerMetadata: {
|
|
1461
1475
|
[providerOptionsName]: {
|
|
1462
|
-
promptFeedback: (
|
|
1463
|
-
groundingMetadata: (
|
|
1464
|
-
urlContextMetadata: (
|
|
1465
|
-
safetyRatings: (
|
|
1476
|
+
promptFeedback: (_m = response.promptFeedback) != null ? _m : null,
|
|
1477
|
+
groundingMetadata: (_n = candidate.groundingMetadata) != null ? _n : null,
|
|
1478
|
+
urlContextMetadata: (_o = candidate.urlContextMetadata) != null ? _o : null,
|
|
1479
|
+
safetyRatings: (_p = candidate.safetyRatings) != null ? _p : null,
|
|
1466
1480
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
1467
|
-
finishMessage: (
|
|
1468
|
-
serviceTier: (
|
|
1481
|
+
finishMessage: (_q = candidate.finishMessage) != null ? _q : null,
|
|
1482
|
+
serviceTier: (_r = response.serviceTier) != null ? _r : null
|
|
1469
1483
|
}
|
|
1470
1484
|
},
|
|
1471
1485
|
request: { body: args },
|
|
@@ -1521,7 +1535,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1521
1535
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1522
1536
|
},
|
|
1523
1537
|
transform(chunk, controller) {
|
|
1524
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
1538
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
1525
1539
|
if (options.includeRawChunks) {
|
|
1526
1540
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1527
1541
|
}
|
|
@@ -1727,7 +1741,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1727
1741
|
const isNoArgsCompleteCall = part.functionCall.name != null && part.functionCall.args == null && part.functionCall.partialArgs == null && part.functionCall.willContinue !== true;
|
|
1728
1742
|
if (isStreamingChunk) {
|
|
1729
1743
|
if (part.functionCall.name != null && part.functionCall.willContinue === true) {
|
|
1730
|
-
const toolCallId = generateId2();
|
|
1744
|
+
const toolCallId = (_i = part.functionCall.id) != null ? _i : generateId2();
|
|
1731
1745
|
const accumulator = new GoogleJSONAccumulator();
|
|
1732
1746
|
activeStreamingToolCalls.push({
|
|
1733
1747
|
toolCallId,
|
|
@@ -1793,9 +1807,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1793
1807
|
});
|
|
1794
1808
|
hasToolCalls = true;
|
|
1795
1809
|
} else if (isCompleteCall) {
|
|
1796
|
-
const toolCallId = generateId2();
|
|
1810
|
+
const toolCallId = (_j = part.functionCall.id) != null ? _j : generateId2();
|
|
1797
1811
|
const toolName = part.functionCall.name;
|
|
1798
|
-
const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((
|
|
1812
|
+
const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((_k = part.functionCall.args) != null ? _k : {});
|
|
1799
1813
|
controller.enqueue({
|
|
1800
1814
|
type: "tool-input-start",
|
|
1801
1815
|
id: toolCallId,
|
|
@@ -1822,7 +1836,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1822
1836
|
});
|
|
1823
1837
|
hasToolCalls = true;
|
|
1824
1838
|
} else if (isNoArgsCompleteCall) {
|
|
1825
|
-
const toolCallId = generateId2();
|
|
1839
|
+
const toolCallId = (_l = part.functionCall.id) != null ? _l : generateId2();
|
|
1826
1840
|
const toolName = part.functionCall.name;
|
|
1827
1841
|
controller.enqueue({
|
|
1828
1842
|
type: "tool-input-start",
|
|
@@ -1856,12 +1870,12 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1856
1870
|
};
|
|
1857
1871
|
providerMetadata = {
|
|
1858
1872
|
[providerOptionsName]: {
|
|
1859
|
-
promptFeedback: (
|
|
1873
|
+
promptFeedback: (_m = value.promptFeedback) != null ? _m : null,
|
|
1860
1874
|
groundingMetadata: lastGroundingMetadata,
|
|
1861
1875
|
urlContextMetadata: lastUrlContextMetadata,
|
|
1862
|
-
safetyRatings: (
|
|
1876
|
+
safetyRatings: (_n = candidate.safetyRatings) != null ? _n : null,
|
|
1863
1877
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
1864
|
-
finishMessage: (
|
|
1878
|
+
finishMessage: (_o = candidate.finishMessage) != null ? _o : null,
|
|
1865
1879
|
serviceTier
|
|
1866
1880
|
}
|
|
1867
1881
|
};
|
|
@@ -2051,6 +2065,7 @@ var getContentSchema = () => import_v43.z.object({
|
|
|
2051
2065
|
// note: order matters since text can be fully empty
|
|
2052
2066
|
import_v43.z.object({
|
|
2053
2067
|
functionCall: import_v43.z.object({
|
|
2068
|
+
id: import_v43.z.string().nullish(),
|
|
2054
2069
|
name: import_v43.z.string().nullish(),
|
|
2055
2070
|
args: import_v43.z.unknown().nullish(),
|
|
2056
2071
|
partialArgs: import_v43.z.array(partialArgSchema).nullish(),
|