@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.mjs
CHANGED
|
@@ -195,7 +195,7 @@ function convertUrlToolResultPart(url) {
|
|
|
195
195
|
}
|
|
196
196
|
};
|
|
197
197
|
}
|
|
198
|
-
function appendToolResultParts(parts, toolName, outputValue) {
|
|
198
|
+
function appendToolResultParts(parts, toolName, outputValue, toolCallId) {
|
|
199
199
|
const functionResponseParts = [];
|
|
200
200
|
const responseTextParts = [];
|
|
201
201
|
for (const contentPart of outputValue) {
|
|
@@ -234,6 +234,7 @@ function appendToolResultParts(parts, toolName, outputValue) {
|
|
|
234
234
|
}
|
|
235
235
|
parts.push({
|
|
236
236
|
functionResponse: {
|
|
237
|
+
...toolCallId != null ? { id: toolCallId } : {},
|
|
237
238
|
name: toolName,
|
|
238
239
|
response: {
|
|
239
240
|
name: toolName,
|
|
@@ -243,12 +244,13 @@ function appendToolResultParts(parts, toolName, outputValue) {
|
|
|
243
244
|
}
|
|
244
245
|
});
|
|
245
246
|
}
|
|
246
|
-
function appendLegacyToolResultParts(parts, toolName, outputValue) {
|
|
247
|
+
function appendLegacyToolResultParts(parts, toolName, outputValue, toolCallId) {
|
|
247
248
|
for (const contentPart of outputValue) {
|
|
248
249
|
switch (contentPart.type) {
|
|
249
250
|
case "text":
|
|
250
251
|
parts.push({
|
|
251
252
|
functionResponse: {
|
|
253
|
+
...toolCallId != null ? { id: toolCallId } : {},
|
|
252
254
|
name: toolName,
|
|
253
255
|
response: {
|
|
254
256
|
name: toolName,
|
|
@@ -378,6 +380,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
378
380
|
}
|
|
379
381
|
return {
|
|
380
382
|
functionCall: {
|
|
383
|
+
...part.toolCallId != null ? { id: part.toolCallId } : {},
|
|
381
384
|
name: part.toolName,
|
|
382
385
|
args: part.input
|
|
383
386
|
},
|
|
@@ -434,13 +437,24 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
434
437
|
const output = part.output;
|
|
435
438
|
if (output.type === "content") {
|
|
436
439
|
if (supportsFunctionResponseParts) {
|
|
437
|
-
appendToolResultParts(
|
|
440
|
+
appendToolResultParts(
|
|
441
|
+
parts,
|
|
442
|
+
part.toolName,
|
|
443
|
+
output.value,
|
|
444
|
+
part.toolCallId
|
|
445
|
+
);
|
|
438
446
|
} else {
|
|
439
|
-
appendLegacyToolResultParts(
|
|
447
|
+
appendLegacyToolResultParts(
|
|
448
|
+
parts,
|
|
449
|
+
part.toolName,
|
|
450
|
+
output.value,
|
|
451
|
+
part.toolCallId
|
|
452
|
+
);
|
|
440
453
|
}
|
|
441
454
|
} else {
|
|
442
455
|
parts.push({
|
|
443
456
|
functionResponse: {
|
|
457
|
+
...part.toolCallId != null ? { id: part.toolCallId } : {},
|
|
444
458
|
name: part.toolName,
|
|
445
459
|
response: {
|
|
446
460
|
name: part.toolName,
|
|
@@ -1288,7 +1302,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1288
1302
|
};
|
|
1289
1303
|
}
|
|
1290
1304
|
async doGenerate(options) {
|
|
1291
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
1305
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
|
|
1292
1306
|
const { args, warnings, providerOptionsName } = await this.getArgs(options);
|
|
1293
1307
|
const mergedHeaders = combineHeaders(
|
|
1294
1308
|
await resolve(this.config.headers),
|
|
@@ -1359,9 +1373,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1359
1373
|
} else if ("functionCall" in part && part.functionCall.name != null) {
|
|
1360
1374
|
content.push({
|
|
1361
1375
|
type: "tool-call",
|
|
1362
|
-
toolCallId: this.config.generateId(),
|
|
1376
|
+
toolCallId: (_e = part.functionCall.id) != null ? _e : this.config.generateId(),
|
|
1363
1377
|
toolName: part.functionCall.name,
|
|
1364
|
-
input: JSON.stringify((
|
|
1378
|
+
input: JSON.stringify((_f = part.functionCall.args) != null ? _f : {}),
|
|
1365
1379
|
providerMetadata: part.thoughtSignature ? {
|
|
1366
1380
|
[providerOptionsName]: {
|
|
1367
1381
|
thoughtSignature: part.thoughtSignature
|
|
@@ -1383,13 +1397,13 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1383
1397
|
} : void 0
|
|
1384
1398
|
});
|
|
1385
1399
|
} else if ("toolCall" in part && part.toolCall) {
|
|
1386
|
-
const toolCallId = (
|
|
1400
|
+
const toolCallId = (_g = part.toolCall.id) != null ? _g : this.config.generateId();
|
|
1387
1401
|
lastServerToolCallId = toolCallId;
|
|
1388
1402
|
content.push({
|
|
1389
1403
|
type: "tool-call",
|
|
1390
1404
|
toolCallId,
|
|
1391
1405
|
toolName: `server:${part.toolCall.toolType}`,
|
|
1392
|
-
input: JSON.stringify((
|
|
1406
|
+
input: JSON.stringify((_h = part.toolCall.args) != null ? _h : {}),
|
|
1393
1407
|
providerExecuted: true,
|
|
1394
1408
|
dynamic: true,
|
|
1395
1409
|
providerMetadata: part.thoughtSignature ? {
|
|
@@ -1406,12 +1420,12 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1406
1420
|
}
|
|
1407
1421
|
});
|
|
1408
1422
|
} else if ("toolResponse" in part && part.toolResponse) {
|
|
1409
|
-
const responseToolCallId = (
|
|
1423
|
+
const responseToolCallId = (_i = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _i : this.config.generateId();
|
|
1410
1424
|
content.push({
|
|
1411
1425
|
type: "tool-result",
|
|
1412
1426
|
toolCallId: responseToolCallId,
|
|
1413
1427
|
toolName: `server:${part.toolResponse.toolType}`,
|
|
1414
|
-
result: (
|
|
1428
|
+
result: (_j = part.toolResponse.response) != null ? _j : {},
|
|
1415
1429
|
providerMetadata: part.thoughtSignature ? {
|
|
1416
1430
|
[providerOptionsName]: {
|
|
1417
1431
|
thoughtSignature: part.thoughtSignature,
|
|
@@ -1428,10 +1442,10 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1428
1442
|
lastServerToolCallId = void 0;
|
|
1429
1443
|
}
|
|
1430
1444
|
}
|
|
1431
|
-
const sources = (
|
|
1445
|
+
const sources = (_k = extractSources({
|
|
1432
1446
|
groundingMetadata: candidate.groundingMetadata,
|
|
1433
1447
|
generateId: this.config.generateId
|
|
1434
|
-
})) != null ?
|
|
1448
|
+
})) != null ? _k : [];
|
|
1435
1449
|
for (const source of sources) {
|
|
1436
1450
|
content.push(source);
|
|
1437
1451
|
}
|
|
@@ -1445,19 +1459,19 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1445
1459
|
(part) => part.type === "tool-call" && !part.providerExecuted
|
|
1446
1460
|
)
|
|
1447
1461
|
}),
|
|
1448
|
-
raw: (
|
|
1462
|
+
raw: (_l = candidate.finishReason) != null ? _l : void 0
|
|
1449
1463
|
},
|
|
1450
1464
|
usage: convertGoogleGenerativeAIUsage(usageMetadata),
|
|
1451
1465
|
warnings,
|
|
1452
1466
|
providerMetadata: {
|
|
1453
1467
|
[providerOptionsName]: {
|
|
1454
|
-
promptFeedback: (
|
|
1455
|
-
groundingMetadata: (
|
|
1456
|
-
urlContextMetadata: (
|
|
1457
|
-
safetyRatings: (
|
|
1468
|
+
promptFeedback: (_m = response.promptFeedback) != null ? _m : null,
|
|
1469
|
+
groundingMetadata: (_n = candidate.groundingMetadata) != null ? _n : null,
|
|
1470
|
+
urlContextMetadata: (_o = candidate.urlContextMetadata) != null ? _o : null,
|
|
1471
|
+
safetyRatings: (_p = candidate.safetyRatings) != null ? _p : null,
|
|
1458
1472
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
1459
|
-
finishMessage: (
|
|
1460
|
-
serviceTier: (
|
|
1473
|
+
finishMessage: (_q = candidate.finishMessage) != null ? _q : null,
|
|
1474
|
+
serviceTier: (_r = response.serviceTier) != null ? _r : null
|
|
1461
1475
|
}
|
|
1462
1476
|
},
|
|
1463
1477
|
request: { body: args },
|
|
@@ -1513,7 +1527,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1513
1527
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1514
1528
|
},
|
|
1515
1529
|
transform(chunk, controller) {
|
|
1516
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
1530
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
1517
1531
|
if (options.includeRawChunks) {
|
|
1518
1532
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1519
1533
|
}
|
|
@@ -1719,7 +1733,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1719
1733
|
const isNoArgsCompleteCall = part.functionCall.name != null && part.functionCall.args == null && part.functionCall.partialArgs == null && part.functionCall.willContinue !== true;
|
|
1720
1734
|
if (isStreamingChunk) {
|
|
1721
1735
|
if (part.functionCall.name != null && part.functionCall.willContinue === true) {
|
|
1722
|
-
const toolCallId = generateId2();
|
|
1736
|
+
const toolCallId = (_i = part.functionCall.id) != null ? _i : generateId2();
|
|
1723
1737
|
const accumulator = new GoogleJSONAccumulator();
|
|
1724
1738
|
activeStreamingToolCalls.push({
|
|
1725
1739
|
toolCallId,
|
|
@@ -1785,9 +1799,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1785
1799
|
});
|
|
1786
1800
|
hasToolCalls = true;
|
|
1787
1801
|
} else if (isCompleteCall) {
|
|
1788
|
-
const toolCallId = generateId2();
|
|
1802
|
+
const toolCallId = (_j = part.functionCall.id) != null ? _j : generateId2();
|
|
1789
1803
|
const toolName = part.functionCall.name;
|
|
1790
|
-
const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((
|
|
1804
|
+
const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((_k = part.functionCall.args) != null ? _k : {});
|
|
1791
1805
|
controller.enqueue({
|
|
1792
1806
|
type: "tool-input-start",
|
|
1793
1807
|
id: toolCallId,
|
|
@@ -1814,7 +1828,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1814
1828
|
});
|
|
1815
1829
|
hasToolCalls = true;
|
|
1816
1830
|
} else if (isNoArgsCompleteCall) {
|
|
1817
|
-
const toolCallId = generateId2();
|
|
1831
|
+
const toolCallId = (_l = part.functionCall.id) != null ? _l : generateId2();
|
|
1818
1832
|
const toolName = part.functionCall.name;
|
|
1819
1833
|
controller.enqueue({
|
|
1820
1834
|
type: "tool-input-start",
|
|
@@ -1848,12 +1862,12 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1848
1862
|
};
|
|
1849
1863
|
providerMetadata = {
|
|
1850
1864
|
[providerOptionsName]: {
|
|
1851
|
-
promptFeedback: (
|
|
1865
|
+
promptFeedback: (_m = value.promptFeedback) != null ? _m : null,
|
|
1852
1866
|
groundingMetadata: lastGroundingMetadata,
|
|
1853
1867
|
urlContextMetadata: lastUrlContextMetadata,
|
|
1854
|
-
safetyRatings: (
|
|
1868
|
+
safetyRatings: (_n = candidate.safetyRatings) != null ? _n : null,
|
|
1855
1869
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
1856
|
-
finishMessage: (
|
|
1870
|
+
finishMessage: (_o = candidate.finishMessage) != null ? _o : null,
|
|
1857
1871
|
serviceTier
|
|
1858
1872
|
}
|
|
1859
1873
|
};
|
|
@@ -2043,6 +2057,7 @@ var getContentSchema = () => z3.object({
|
|
|
2043
2057
|
// note: order matters since text can be fully empty
|
|
2044
2058
|
z3.object({
|
|
2045
2059
|
functionCall: z3.object({
|
|
2060
|
+
id: z3.string().nullish(),
|
|
2046
2061
|
name: z3.string().nullish(),
|
|
2047
2062
|
args: z3.unknown().nullish(),
|
|
2048
2063
|
partialArgs: z3.array(partialArgSchema).nullish(),
|