@ai-sdk/google 3.0.68 → 3.0.71
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 +26 -0
- package/dist/index.js +56 -20
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +56 -20
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +46 -19
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +46 -19
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/google-generative-ai-language-model.ts +36 -6
- package/src/google-prepare-tools.ts +6 -2
- package/src/interactions/convert-to-google-interactions-input.ts +9 -0
package/dist/internal/index.mjs
CHANGED
|
@@ -648,7 +648,8 @@ import {
|
|
|
648
648
|
function prepareTools({
|
|
649
649
|
tools,
|
|
650
650
|
toolChoice,
|
|
651
|
-
modelId
|
|
651
|
+
modelId,
|
|
652
|
+
isVertexProvider = false
|
|
652
653
|
}) {
|
|
653
654
|
var _a, _b;
|
|
654
655
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
@@ -784,7 +785,9 @@ function prepareTools({
|
|
|
784
785
|
}
|
|
785
786
|
const combinedToolConfig = {
|
|
786
787
|
functionCallingConfig: { mode: "VALIDATED" },
|
|
787
|
-
|
|
788
|
+
...!isVertexProvider && {
|
|
789
|
+
includeServerSideToolInvocations: true
|
|
790
|
+
}
|
|
788
791
|
};
|
|
789
792
|
if (toolChoice != null) {
|
|
790
793
|
switch (toolChoice.type) {
|
|
@@ -1224,7 +1227,8 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1224
1227
|
} = prepareTools({
|
|
1225
1228
|
tools,
|
|
1226
1229
|
toolChoice,
|
|
1227
|
-
modelId: this.modelId
|
|
1230
|
+
modelId: this.modelId,
|
|
1231
|
+
isVertexProvider
|
|
1228
1232
|
});
|
|
1229
1233
|
const streamFunctionCallArguments = isStreaming && isVertexProvider ? (_a = googleOptions == null ? void 0 : googleOptions.streamFunctionCallArguments) != null ? _a : false : void 0;
|
|
1230
1234
|
const toolConfig = googleToolConfig || streamFunctionCallArguments || (googleOptions == null ? void 0 : googleOptions.retrievalConfig) ? {
|
|
@@ -1284,7 +1288,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1284
1288
|
};
|
|
1285
1289
|
}
|
|
1286
1290
|
async doGenerate(options) {
|
|
1287
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
1291
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
1288
1292
|
const { args, warnings, providerOptionsName } = await this.getArgs(options);
|
|
1289
1293
|
const mergedHeaders = combineHeaders(
|
|
1290
1294
|
await resolve(this.config.headers),
|
|
@@ -1352,12 +1356,12 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1352
1356
|
providerMetadata: thoughtSignatureMetadata
|
|
1353
1357
|
});
|
|
1354
1358
|
}
|
|
1355
|
-
} else if ("functionCall" in part && part.functionCall.name != null
|
|
1359
|
+
} else if ("functionCall" in part && part.functionCall.name != null) {
|
|
1356
1360
|
content.push({
|
|
1357
1361
|
type: "tool-call",
|
|
1358
1362
|
toolCallId: this.config.generateId(),
|
|
1359
1363
|
toolName: part.functionCall.name,
|
|
1360
|
-
input: JSON.stringify(part.functionCall.args),
|
|
1364
|
+
input: JSON.stringify((_e = part.functionCall.args) != null ? _e : {}),
|
|
1361
1365
|
providerMetadata: part.thoughtSignature ? {
|
|
1362
1366
|
[providerOptionsName]: {
|
|
1363
1367
|
thoughtSignature: part.thoughtSignature
|
|
@@ -1379,13 +1383,13 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1379
1383
|
} : void 0
|
|
1380
1384
|
});
|
|
1381
1385
|
} else if ("toolCall" in part && part.toolCall) {
|
|
1382
|
-
const toolCallId = (
|
|
1386
|
+
const toolCallId = (_f = part.toolCall.id) != null ? _f : this.config.generateId();
|
|
1383
1387
|
lastServerToolCallId = toolCallId;
|
|
1384
1388
|
content.push({
|
|
1385
1389
|
type: "tool-call",
|
|
1386
1390
|
toolCallId,
|
|
1387
1391
|
toolName: `server:${part.toolCall.toolType}`,
|
|
1388
|
-
input: JSON.stringify((
|
|
1392
|
+
input: JSON.stringify((_g = part.toolCall.args) != null ? _g : {}),
|
|
1389
1393
|
providerExecuted: true,
|
|
1390
1394
|
dynamic: true,
|
|
1391
1395
|
providerMetadata: part.thoughtSignature ? {
|
|
@@ -1402,12 +1406,12 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1402
1406
|
}
|
|
1403
1407
|
});
|
|
1404
1408
|
} else if ("toolResponse" in part && part.toolResponse) {
|
|
1405
|
-
const responseToolCallId = (
|
|
1409
|
+
const responseToolCallId = (_h = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _h : this.config.generateId();
|
|
1406
1410
|
content.push({
|
|
1407
1411
|
type: "tool-result",
|
|
1408
1412
|
toolCallId: responseToolCallId,
|
|
1409
1413
|
toolName: `server:${part.toolResponse.toolType}`,
|
|
1410
|
-
result: (
|
|
1414
|
+
result: (_i = part.toolResponse.response) != null ? _i : {},
|
|
1411
1415
|
providerMetadata: part.thoughtSignature ? {
|
|
1412
1416
|
[providerOptionsName]: {
|
|
1413
1417
|
thoughtSignature: part.thoughtSignature,
|
|
@@ -1424,10 +1428,10 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1424
1428
|
lastServerToolCallId = void 0;
|
|
1425
1429
|
}
|
|
1426
1430
|
}
|
|
1427
|
-
const sources = (
|
|
1431
|
+
const sources = (_j = extractSources({
|
|
1428
1432
|
groundingMetadata: candidate.groundingMetadata,
|
|
1429
1433
|
generateId: this.config.generateId
|
|
1430
|
-
})) != null ?
|
|
1434
|
+
})) != null ? _j : [];
|
|
1431
1435
|
for (const source of sources) {
|
|
1432
1436
|
content.push(source);
|
|
1433
1437
|
}
|
|
@@ -1441,19 +1445,19 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1441
1445
|
(part) => part.type === "tool-call" && !part.providerExecuted
|
|
1442
1446
|
)
|
|
1443
1447
|
}),
|
|
1444
|
-
raw: (
|
|
1448
|
+
raw: (_k = candidate.finishReason) != null ? _k : void 0
|
|
1445
1449
|
},
|
|
1446
1450
|
usage: convertGoogleGenerativeAIUsage(usageMetadata),
|
|
1447
1451
|
warnings,
|
|
1448
1452
|
providerMetadata: {
|
|
1449
1453
|
[providerOptionsName]: {
|
|
1450
|
-
promptFeedback: (
|
|
1451
|
-
groundingMetadata: (
|
|
1452
|
-
urlContextMetadata: (
|
|
1453
|
-
safetyRatings: (
|
|
1454
|
+
promptFeedback: (_l = response.promptFeedback) != null ? _l : null,
|
|
1455
|
+
groundingMetadata: (_m = candidate.groundingMetadata) != null ? _m : null,
|
|
1456
|
+
urlContextMetadata: (_n = candidate.urlContextMetadata) != null ? _n : null,
|
|
1457
|
+
safetyRatings: (_o = candidate.safetyRatings) != null ? _o : null,
|
|
1454
1458
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
1455
|
-
finishMessage: (
|
|
1456
|
-
serviceTier: (
|
|
1459
|
+
finishMessage: (_p = candidate.finishMessage) != null ? _p : null,
|
|
1460
|
+
serviceTier: (_q = response.serviceTier) != null ? _q : null
|
|
1457
1461
|
}
|
|
1458
1462
|
},
|
|
1459
1463
|
request: { body: args },
|
|
@@ -1712,6 +1716,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1712
1716
|
const isStreamingChunk = part.functionCall.partialArgs != null || part.functionCall.name != null && part.functionCall.willContinue === true;
|
|
1713
1717
|
const isTerminalChunk = part.functionCall.name == null && part.functionCall.args == null && part.functionCall.partialArgs == null && part.functionCall.willContinue == null;
|
|
1714
1718
|
const isCompleteCall = part.functionCall.name != null && part.functionCall.args != null && part.functionCall.partialArgs == null;
|
|
1719
|
+
const isNoArgsCompleteCall = part.functionCall.name != null && part.functionCall.args == null && part.functionCall.partialArgs == null && part.functionCall.willContinue !== true;
|
|
1715
1720
|
if (isStreamingChunk) {
|
|
1716
1721
|
if (part.functionCall.name != null && part.functionCall.willContinue === true) {
|
|
1717
1722
|
const toolCallId = generateId2();
|
|
@@ -1808,6 +1813,28 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1808
1813
|
providerMetadata: providerMeta
|
|
1809
1814
|
});
|
|
1810
1815
|
hasToolCalls = true;
|
|
1816
|
+
} else if (isNoArgsCompleteCall) {
|
|
1817
|
+
const toolCallId = generateId2();
|
|
1818
|
+
const toolName = part.functionCall.name;
|
|
1819
|
+
controller.enqueue({
|
|
1820
|
+
type: "tool-input-start",
|
|
1821
|
+
id: toolCallId,
|
|
1822
|
+
toolName,
|
|
1823
|
+
providerMetadata: providerMeta
|
|
1824
|
+
});
|
|
1825
|
+
controller.enqueue({
|
|
1826
|
+
type: "tool-input-end",
|
|
1827
|
+
id: toolCallId,
|
|
1828
|
+
providerMetadata: providerMeta
|
|
1829
|
+
});
|
|
1830
|
+
controller.enqueue({
|
|
1831
|
+
type: "tool-call",
|
|
1832
|
+
toolCallId,
|
|
1833
|
+
toolName,
|
|
1834
|
+
input: "{}",
|
|
1835
|
+
providerMetadata: providerMeta
|
|
1836
|
+
});
|
|
1837
|
+
hasToolCalls = true;
|
|
1811
1838
|
}
|
|
1812
1839
|
}
|
|
1813
1840
|
}
|