@ai-sdk/google 2.0.72 → 2.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 +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +30 -22
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +30 -22
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +2 -1
- package/dist/internal/index.d.ts +2 -1
- package/dist/internal/index.js +29 -21
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +29 -21
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/internal/index.mjs
CHANGED
|
@@ -224,6 +224,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
224
224
|
case "tool-call": {
|
|
225
225
|
return {
|
|
226
226
|
functionCall: {
|
|
227
|
+
...part.toolCallId != null ? { id: part.toolCallId } : {},
|
|
227
228
|
name: part.toolName,
|
|
228
229
|
args: part.input
|
|
229
230
|
},
|
|
@@ -249,6 +250,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
249
250
|
} else {
|
|
250
251
|
parts.push({
|
|
251
252
|
functionResponse: {
|
|
253
|
+
...part.toolCallId != null ? { id: part.toolCallId } : {},
|
|
252
254
|
name: part.toolName,
|
|
253
255
|
response: {
|
|
254
256
|
name: part.toolName,
|
|
@@ -300,6 +302,7 @@ function appendToolResultParts({
|
|
|
300
302
|
const responseText = responseTextParts.length > 0 ? responseTextParts.join("\n") : "Tool executed successfully.";
|
|
301
303
|
parts.push({
|
|
302
304
|
functionResponse: {
|
|
305
|
+
...part.toolCallId != null ? { id: part.toolCallId } : {},
|
|
303
306
|
name: part.toolName,
|
|
304
307
|
response: {
|
|
305
308
|
name: part.toolName,
|
|
@@ -319,6 +322,7 @@ function appendLegacyToolResultParts({
|
|
|
319
322
|
case "text":
|
|
320
323
|
parts.push({
|
|
321
324
|
functionResponse: {
|
|
325
|
+
...part.toolCallId != null ? { id: part.toolCallId } : {},
|
|
322
326
|
name: part.toolName,
|
|
323
327
|
response: {
|
|
324
328
|
name: part.toolName,
|
|
@@ -861,7 +865,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
861
865
|
};
|
|
862
866
|
}
|
|
863
867
|
async doGenerate(options) {
|
|
864
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
868
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
865
869
|
const { args, warnings } = await this.getArgs(options);
|
|
866
870
|
const body = JSON.stringify(args);
|
|
867
871
|
const mergedHeaders = combineHeaders(
|
|
@@ -931,7 +935,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
931
935
|
} else if ("functionCall" in part) {
|
|
932
936
|
content.push({
|
|
933
937
|
type: "tool-call",
|
|
934
|
-
toolCallId: this.config.generateId(),
|
|
938
|
+
toolCallId: (_d = part.functionCall.id) != null ? _d : this.config.generateId(),
|
|
935
939
|
toolName: part.functionCall.name,
|
|
936
940
|
input: JSON.stringify(part.functionCall.args),
|
|
937
941
|
providerMetadata: part.thoughtSignature ? { google: { thoughtSignature: part.thoughtSignature } } : void 0
|
|
@@ -944,10 +948,10 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
944
948
|
});
|
|
945
949
|
}
|
|
946
950
|
}
|
|
947
|
-
const sources = (
|
|
951
|
+
const sources = (_e = extractSources({
|
|
948
952
|
groundingMetadata: candidate.groundingMetadata,
|
|
949
953
|
generateId: this.config.generateId
|
|
950
|
-
})) != null ?
|
|
954
|
+
})) != null ? _e : [];
|
|
951
955
|
for (const source of sources) {
|
|
952
956
|
content.push(source);
|
|
953
957
|
}
|
|
@@ -958,20 +962,20 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
958
962
|
hasToolCalls: content.some((part) => part.type === "tool-call")
|
|
959
963
|
}),
|
|
960
964
|
usage: {
|
|
961
|
-
inputTokens: (
|
|
962
|
-
outputTokens: (
|
|
963
|
-
totalTokens: (
|
|
964
|
-
reasoningTokens: (
|
|
965
|
-
cachedInputTokens: (
|
|
965
|
+
inputTokens: (_f = usageMetadata == null ? void 0 : usageMetadata.promptTokenCount) != null ? _f : void 0,
|
|
966
|
+
outputTokens: (_g = usageMetadata == null ? void 0 : usageMetadata.candidatesTokenCount) != null ? _g : void 0,
|
|
967
|
+
totalTokens: (_h = usageMetadata == null ? void 0 : usageMetadata.totalTokenCount) != null ? _h : void 0,
|
|
968
|
+
reasoningTokens: (_i = usageMetadata == null ? void 0 : usageMetadata.thoughtsTokenCount) != null ? _i : void 0,
|
|
969
|
+
cachedInputTokens: (_j = usageMetadata == null ? void 0 : usageMetadata.cachedContentTokenCount) != null ? _j : void 0
|
|
966
970
|
},
|
|
967
971
|
warnings,
|
|
968
972
|
providerMetadata: {
|
|
969
973
|
google: {
|
|
970
|
-
promptFeedback: (
|
|
971
|
-
groundingMetadata: (
|
|
972
|
-
urlContextMetadata: (
|
|
973
|
-
safetyRatings: (
|
|
974
|
-
serviceTier: (
|
|
974
|
+
promptFeedback: (_k = response.promptFeedback) != null ? _k : null,
|
|
975
|
+
groundingMetadata: (_l = candidate.groundingMetadata) != null ? _l : null,
|
|
976
|
+
urlContextMetadata: (_m = candidate.urlContextMetadata) != null ? _m : null,
|
|
977
|
+
safetyRatings: (_n = candidate.safetyRatings) != null ? _n : null,
|
|
978
|
+
serviceTier: (_o = response.serviceTier) != null ? _o : null
|
|
975
979
|
}
|
|
976
980
|
},
|
|
977
981
|
request: { body },
|
|
@@ -1251,13 +1255,16 @@ function getToolCallsFromParts({
|
|
|
1251
1255
|
const functionCallParts = parts == null ? void 0 : parts.filter(
|
|
1252
1256
|
(part) => "functionCall" in part
|
|
1253
1257
|
);
|
|
1254
|
-
return functionCallParts == null || functionCallParts.length === 0 ? void 0 : functionCallParts.map((part) =>
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1258
|
+
return functionCallParts == null || functionCallParts.length === 0 ? void 0 : functionCallParts.map((part) => {
|
|
1259
|
+
var _a;
|
|
1260
|
+
return {
|
|
1261
|
+
type: "tool-call",
|
|
1262
|
+
toolCallId: (_a = part.functionCall.id) != null ? _a : generateId2(),
|
|
1263
|
+
toolName: part.functionCall.name,
|
|
1264
|
+
args: JSON.stringify(part.functionCall.args),
|
|
1265
|
+
providerMetadata: part.thoughtSignature ? { google: { thoughtSignature: part.thoughtSignature } } : void 0
|
|
1266
|
+
};
|
|
1267
|
+
});
|
|
1261
1268
|
}
|
|
1262
1269
|
function extractSources({
|
|
1263
1270
|
groundingMetadata,
|
|
@@ -1408,6 +1415,7 @@ var getContentSchema = () => z3.object({
|
|
|
1408
1415
|
// note: order matters since text can be fully empty
|
|
1409
1416
|
z3.object({
|
|
1410
1417
|
functionCall: z3.object({
|
|
1418
|
+
id: z3.string().nullish(),
|
|
1411
1419
|
name: z3.string(),
|
|
1412
1420
|
args: z3.unknown()
|
|
1413
1421
|
}),
|