@ai-sdk/google 4.0.0-beta.31 → 4.0.0-beta.32
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 +6 -0
- package/dist/index.d.mts +12 -2
- package/dist/index.d.ts +12 -2
- package/dist/index.js +369 -54
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +369 -54
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +11 -2
- package/dist/internal/index.d.ts +11 -2
- package/dist/internal/index.js +368 -53
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +368 -53
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/google-generative-ai-language-model.ts +193 -64
- package/src/google-generative-ai-options.ts +11 -0
- package/src/google-json-accumulator.ts +336 -0
- package/src/google-prepare-tools.ts +1 -0
package/dist/internal/index.mjs
CHANGED
|
@@ -671,6 +671,16 @@ var googleLanguageModelOptions = lazySchema2(
|
|
|
671
671
|
longitude: z2.number()
|
|
672
672
|
}).optional()
|
|
673
673
|
}).optional(),
|
|
674
|
+
/**
|
|
675
|
+
* Optional. When set to true, function call arguments will be streamed
|
|
676
|
+
* incrementally via partialArgs in streaming responses. Only supported
|
|
677
|
+
* on the Vertex AI API (not the Gemini API).
|
|
678
|
+
*
|
|
679
|
+
* @default true
|
|
680
|
+
*
|
|
681
|
+
* https://docs.cloud.google.com/vertex-ai/generative-ai/docs/multimodal/function-calling#streaming-fc
|
|
682
|
+
*/
|
|
683
|
+
streamFunctionCallArguments: z2.boolean().optional(),
|
|
674
684
|
/**
|
|
675
685
|
* Optional. The service tier to use for the request.
|
|
676
686
|
*/
|
|
@@ -931,6 +941,229 @@ function prepareTools({
|
|
|
931
941
|
}
|
|
932
942
|
}
|
|
933
943
|
|
|
944
|
+
// src/google-json-accumulator.ts
|
|
945
|
+
var GoogleJSONAccumulator = class {
|
|
946
|
+
constructor() {
|
|
947
|
+
this.accumulatedArgs = {};
|
|
948
|
+
this.jsonText = "";
|
|
949
|
+
/**
|
|
950
|
+
* Stack representing the currently "open" containers in the JSON output.
|
|
951
|
+
* Entry 0 is always the root `{` object once the first value is written.
|
|
952
|
+
*/
|
|
953
|
+
this.pathStack = [];
|
|
954
|
+
/**
|
|
955
|
+
* Whether a string value is currently "open" (willContinue was true),
|
|
956
|
+
* meaning the closing quote has not yet been emitted.
|
|
957
|
+
*/
|
|
958
|
+
this.stringOpen = false;
|
|
959
|
+
}
|
|
960
|
+
/**
|
|
961
|
+
* Input: [{jsonPath:"$.brightness",numberValue:50}]
|
|
962
|
+
* Output: { currentJSON:{brightness:50}, textDelta:'{"brightness":50' }
|
|
963
|
+
*/
|
|
964
|
+
processPartialArgs(partialArgs) {
|
|
965
|
+
let delta = "";
|
|
966
|
+
for (const arg of partialArgs) {
|
|
967
|
+
const rawPath = arg.jsonPath.replace(/^\$\./, "");
|
|
968
|
+
if (!rawPath) continue;
|
|
969
|
+
const segments = parsePath(rawPath);
|
|
970
|
+
const existingValue = getNestedValue(this.accumulatedArgs, segments);
|
|
971
|
+
const isStringContinuation = arg.stringValue != null && existingValue !== void 0;
|
|
972
|
+
if (isStringContinuation) {
|
|
973
|
+
const escaped = JSON.stringify(arg.stringValue).slice(1, -1);
|
|
974
|
+
setNestedValue(
|
|
975
|
+
this.accumulatedArgs,
|
|
976
|
+
segments,
|
|
977
|
+
existingValue + arg.stringValue
|
|
978
|
+
);
|
|
979
|
+
delta += escaped;
|
|
980
|
+
continue;
|
|
981
|
+
}
|
|
982
|
+
const resolved = resolvePartialArgValue(arg);
|
|
983
|
+
if (resolved == null) continue;
|
|
984
|
+
setNestedValue(this.accumulatedArgs, segments, resolved.value);
|
|
985
|
+
delta += this.emitNavigationTo(segments, arg, resolved.json);
|
|
986
|
+
}
|
|
987
|
+
this.jsonText += delta;
|
|
988
|
+
return {
|
|
989
|
+
currentJSON: this.accumulatedArgs,
|
|
990
|
+
textDelta: delta
|
|
991
|
+
};
|
|
992
|
+
}
|
|
993
|
+
/**
|
|
994
|
+
* Input: jsonText='{"brightness":50', accumulatedArgs={brightness:50}
|
|
995
|
+
* Output: { finalJSON:'{"brightness":50}', closingDelta:'}' }
|
|
996
|
+
*/
|
|
997
|
+
finalize() {
|
|
998
|
+
const finalArgs = JSON.stringify(this.accumulatedArgs);
|
|
999
|
+
const closingDelta = finalArgs.slice(this.jsonText.length);
|
|
1000
|
+
return { finalJSON: finalArgs, closingDelta };
|
|
1001
|
+
}
|
|
1002
|
+
/**
|
|
1003
|
+
* Input: pathStack=[] (first call) or pathStack=[root,...] (subsequent calls)
|
|
1004
|
+
* Output: '{' (first call) or '' (subsequent calls)
|
|
1005
|
+
*/
|
|
1006
|
+
ensureRoot() {
|
|
1007
|
+
if (this.pathStack.length === 0) {
|
|
1008
|
+
this.pathStack.push({ segment: "", isArray: false, childCount: 0 });
|
|
1009
|
+
return "{";
|
|
1010
|
+
}
|
|
1011
|
+
return "";
|
|
1012
|
+
}
|
|
1013
|
+
/**
|
|
1014
|
+
* Emits the JSON text fragment needed to navigate from the current open
|
|
1015
|
+
* path to the new leaf at `targetSegments`, then writes the value.
|
|
1016
|
+
*
|
|
1017
|
+
* Input: targetSegments=["recipe","name"], arg={jsonPath:"$.recipe.name",stringValue:"Lasagna"}, valueJson='"Lasagna"'
|
|
1018
|
+
* Output: '{"recipe":{"name":"Lasagna"'
|
|
1019
|
+
*/
|
|
1020
|
+
emitNavigationTo(targetSegments, arg, valueJson) {
|
|
1021
|
+
let fragment = "";
|
|
1022
|
+
if (this.stringOpen) {
|
|
1023
|
+
fragment += '"';
|
|
1024
|
+
this.stringOpen = false;
|
|
1025
|
+
}
|
|
1026
|
+
fragment += this.ensureRoot();
|
|
1027
|
+
const targetContainerSegments = targetSegments.slice(0, -1);
|
|
1028
|
+
const leafSegment = targetSegments[targetSegments.length - 1];
|
|
1029
|
+
const commonDepth = this.findCommonStackDepth(targetContainerSegments);
|
|
1030
|
+
fragment += this.closeDownTo(commonDepth);
|
|
1031
|
+
fragment += this.openDownTo(targetContainerSegments, leafSegment);
|
|
1032
|
+
fragment += this.emitLeaf(leafSegment, arg, valueJson);
|
|
1033
|
+
return fragment;
|
|
1034
|
+
}
|
|
1035
|
+
/**
|
|
1036
|
+
* Returns the stack depth to preserve when navigating to a new target
|
|
1037
|
+
* container path. Always >= 1 (the root is never popped).
|
|
1038
|
+
*
|
|
1039
|
+
* Input: stack=[root,"recipe","ingredients",0], target=["recipe","ingredients",1]
|
|
1040
|
+
* Output: 3 (keep root+"recipe"+"ingredients")
|
|
1041
|
+
*/
|
|
1042
|
+
findCommonStackDepth(targetContainer) {
|
|
1043
|
+
const maxDepth = Math.min(
|
|
1044
|
+
this.pathStack.length - 1,
|
|
1045
|
+
targetContainer.length
|
|
1046
|
+
);
|
|
1047
|
+
let common = 0;
|
|
1048
|
+
for (let i = 0; i < maxDepth; i++) {
|
|
1049
|
+
if (this.pathStack[i + 1].segment === targetContainer[i]) {
|
|
1050
|
+
common++;
|
|
1051
|
+
} else {
|
|
1052
|
+
break;
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
return common + 1;
|
|
1056
|
+
}
|
|
1057
|
+
/**
|
|
1058
|
+
* Closes containers from the current stack depth back down to `targetDepth`.
|
|
1059
|
+
*
|
|
1060
|
+
* Input: this.pathStack=[root,"recipe","ingredients",0], targetDepth=3
|
|
1061
|
+
* Output: '}'
|
|
1062
|
+
*/
|
|
1063
|
+
closeDownTo(targetDepth) {
|
|
1064
|
+
let fragment = "";
|
|
1065
|
+
while (this.pathStack.length > targetDepth) {
|
|
1066
|
+
const entry = this.pathStack.pop();
|
|
1067
|
+
fragment += entry.isArray ? "]" : "}";
|
|
1068
|
+
}
|
|
1069
|
+
return fragment;
|
|
1070
|
+
}
|
|
1071
|
+
/**
|
|
1072
|
+
* Opens containers from the current stack depth down to the full target
|
|
1073
|
+
* container path, emitting opening `{`, `[`, keys, and commas as needed.
|
|
1074
|
+
* `leafSegment` is used to determine if the innermost container is an array.
|
|
1075
|
+
*
|
|
1076
|
+
* Input: this.pathStack=[root], targetContainer=["recipe","ingredients"], leafSegment=0
|
|
1077
|
+
* Output: '"recipe":{"ingredients":['
|
|
1078
|
+
*/
|
|
1079
|
+
openDownTo(targetContainer, leafSegment) {
|
|
1080
|
+
let fragment = "";
|
|
1081
|
+
const startIdx = this.pathStack.length - 1;
|
|
1082
|
+
for (let i = startIdx; i < targetContainer.length; i++) {
|
|
1083
|
+
const seg = targetContainer[i];
|
|
1084
|
+
const parentEntry = this.pathStack[this.pathStack.length - 1];
|
|
1085
|
+
if (parentEntry.childCount > 0) {
|
|
1086
|
+
fragment += ",";
|
|
1087
|
+
}
|
|
1088
|
+
parentEntry.childCount++;
|
|
1089
|
+
if (typeof seg === "string") {
|
|
1090
|
+
fragment += `${JSON.stringify(seg)}:`;
|
|
1091
|
+
}
|
|
1092
|
+
const childSeg = i + 1 < targetContainer.length ? targetContainer[i + 1] : leafSegment;
|
|
1093
|
+
const isArray = typeof childSeg === "number";
|
|
1094
|
+
fragment += isArray ? "[" : "{";
|
|
1095
|
+
this.pathStack.push({ segment: seg, isArray, childCount: 0 });
|
|
1096
|
+
}
|
|
1097
|
+
return fragment;
|
|
1098
|
+
}
|
|
1099
|
+
/**
|
|
1100
|
+
* Emits the comma, key, and value for a leaf entry in the current container.
|
|
1101
|
+
*
|
|
1102
|
+
* Input: leafSegment="name", arg={stringValue:"Lasagna"}, valueJson='"Lasagna"'
|
|
1103
|
+
* Output: '"name":"Lasagna"' (or ',"name":"Lasagna"' if container.childCount > 0)
|
|
1104
|
+
*/
|
|
1105
|
+
emitLeaf(leafSegment, arg, valueJson) {
|
|
1106
|
+
let fragment = "";
|
|
1107
|
+
const container = this.pathStack[this.pathStack.length - 1];
|
|
1108
|
+
if (container.childCount > 0) {
|
|
1109
|
+
fragment += ",";
|
|
1110
|
+
}
|
|
1111
|
+
container.childCount++;
|
|
1112
|
+
if (typeof leafSegment === "string") {
|
|
1113
|
+
fragment += `${JSON.stringify(leafSegment)}:`;
|
|
1114
|
+
}
|
|
1115
|
+
if (arg.stringValue != null && arg.willContinue) {
|
|
1116
|
+
fragment += valueJson.slice(0, -1);
|
|
1117
|
+
this.stringOpen = true;
|
|
1118
|
+
} else {
|
|
1119
|
+
fragment += valueJson;
|
|
1120
|
+
}
|
|
1121
|
+
return fragment;
|
|
1122
|
+
}
|
|
1123
|
+
};
|
|
1124
|
+
function parsePath(rawPath) {
|
|
1125
|
+
const segments = [];
|
|
1126
|
+
for (const part of rawPath.split(".")) {
|
|
1127
|
+
const bracketIdx = part.indexOf("[");
|
|
1128
|
+
if (bracketIdx === -1) {
|
|
1129
|
+
segments.push(part);
|
|
1130
|
+
} else {
|
|
1131
|
+
if (bracketIdx > 0) segments.push(part.slice(0, bracketIdx));
|
|
1132
|
+
for (const m of part.matchAll(/\[(\d+)\]/g)) {
|
|
1133
|
+
segments.push(parseInt(m[1], 10));
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
return segments;
|
|
1138
|
+
}
|
|
1139
|
+
function getNestedValue(obj, segments) {
|
|
1140
|
+
let current = obj;
|
|
1141
|
+
for (const seg of segments) {
|
|
1142
|
+
if (current == null || typeof current !== "object") return void 0;
|
|
1143
|
+
current = current[seg];
|
|
1144
|
+
}
|
|
1145
|
+
return current;
|
|
1146
|
+
}
|
|
1147
|
+
function setNestedValue(obj, segments, value) {
|
|
1148
|
+
let current = obj;
|
|
1149
|
+
for (let i = 0; i < segments.length - 1; i++) {
|
|
1150
|
+
const seg = segments[i];
|
|
1151
|
+
const nextSeg = segments[i + 1];
|
|
1152
|
+
if (current[seg] == null) {
|
|
1153
|
+
current[seg] = typeof nextSeg === "number" ? [] : {};
|
|
1154
|
+
}
|
|
1155
|
+
current = current[seg];
|
|
1156
|
+
}
|
|
1157
|
+
current[segments[segments.length - 1]] = value;
|
|
1158
|
+
}
|
|
1159
|
+
function resolvePartialArgValue(arg) {
|
|
1160
|
+
var _a, _b;
|
|
1161
|
+
const value = (_b = (_a = arg.stringValue) != null ? _a : arg.numberValue) != null ? _b : arg.boolValue;
|
|
1162
|
+
if (value != null) return { value, json: JSON.stringify(value) };
|
|
1163
|
+
if ("nullValue" in arg) return { value: null, json: "null" };
|
|
1164
|
+
return void 0;
|
|
1165
|
+
}
|
|
1166
|
+
|
|
934
1167
|
// src/map-google-generative-ai-finish-reason.ts
|
|
935
1168
|
function mapGoogleGenerativeAIFinishReason({
|
|
936
1169
|
finishReason,
|
|
@@ -989,7 +1222,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
989
1222
|
reasoning,
|
|
990
1223
|
providerOptions
|
|
991
1224
|
}) {
|
|
992
|
-
var _a;
|
|
1225
|
+
var _a, _b;
|
|
993
1226
|
const warnings = [];
|
|
994
1227
|
const providerOptionsName = this.config.provider.includes("vertex") ? "vertex" : "google";
|
|
995
1228
|
let googleOptions = await parseProviderOptions({
|
|
@@ -1004,14 +1237,21 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1004
1237
|
schema: googleLanguageModelOptions
|
|
1005
1238
|
});
|
|
1006
1239
|
}
|
|
1240
|
+
const isVertexProvider = this.config.provider.startsWith("google.vertex.");
|
|
1007
1241
|
if ((tools == null ? void 0 : tools.some(
|
|
1008
1242
|
(tool) => tool.type === "provider" && tool.id === "google.vertex_rag_store"
|
|
1009
|
-
)) && !
|
|
1243
|
+
)) && !isVertexProvider) {
|
|
1010
1244
|
warnings.push({
|
|
1011
1245
|
type: "other",
|
|
1012
1246
|
message: `The 'vertex_rag_store' tool is only supported with the Google Vertex provider and might not be supported or could behave unexpectedly with the current Google provider (${this.config.provider}).`
|
|
1013
1247
|
});
|
|
1014
1248
|
}
|
|
1249
|
+
if ((googleOptions == null ? void 0 : googleOptions.streamFunctionCallArguments) && !isVertexProvider) {
|
|
1250
|
+
warnings.push({
|
|
1251
|
+
type: "other",
|
|
1252
|
+
message: `'streamFunctionCallArguments' is only supported on the Vertex AI API and will be ignored with the current Google provider (${this.config.provider}). See https://docs.cloud.google.com/vertex-ai/generative-ai/docs/multimodal/function-calling#streaming-fc`
|
|
1253
|
+
});
|
|
1254
|
+
}
|
|
1015
1255
|
const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
|
|
1016
1256
|
const supportsFunctionResponseParts = this.modelId.startsWith("gemini-3");
|
|
1017
1257
|
const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
|
|
@@ -1037,6 +1277,19 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1037
1277
|
warnings
|
|
1038
1278
|
});
|
|
1039
1279
|
const thinkingConfig = (googleOptions == null ? void 0 : googleOptions.thinkingConfig) || resolvedThinking ? { ...resolvedThinking, ...googleOptions == null ? void 0 : googleOptions.thinkingConfig } : void 0;
|
|
1280
|
+
const streamFunctionCallArguments = isVertexProvider ? (_a = googleOptions == null ? void 0 : googleOptions.streamFunctionCallArguments) != null ? _a : true : void 0;
|
|
1281
|
+
const toolConfig = googleToolConfig || streamFunctionCallArguments || (googleOptions == null ? void 0 : googleOptions.retrievalConfig) ? {
|
|
1282
|
+
...googleToolConfig,
|
|
1283
|
+
...streamFunctionCallArguments && {
|
|
1284
|
+
functionCallingConfig: {
|
|
1285
|
+
...googleToolConfig == null ? void 0 : googleToolConfig.functionCallingConfig,
|
|
1286
|
+
streamFunctionCallArguments: true
|
|
1287
|
+
}
|
|
1288
|
+
},
|
|
1289
|
+
...(googleOptions == null ? void 0 : googleOptions.retrievalConfig) && {
|
|
1290
|
+
retrievalConfig: googleOptions.retrievalConfig
|
|
1291
|
+
}
|
|
1292
|
+
} : void 0;
|
|
1040
1293
|
return {
|
|
1041
1294
|
args: {
|
|
1042
1295
|
generationConfig: {
|
|
@@ -1054,7 +1307,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1054
1307
|
responseSchema: (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && // Google GenAI does not support all OpenAPI Schema features,
|
|
1055
1308
|
// so this is needed as an escape hatch:
|
|
1056
1309
|
// TODO convert into provider option
|
|
1057
|
-
((
|
|
1310
|
+
((_b = googleOptions == null ? void 0 : googleOptions.structuredOutputs) != null ? _b : true) ? convertJSONSchemaToOpenAPISchema(responseFormat.schema) : void 0,
|
|
1058
1311
|
...(googleOptions == null ? void 0 : googleOptions.audioTimestamp) && {
|
|
1059
1312
|
audioTimestamp: googleOptions.audioTimestamp
|
|
1060
1313
|
},
|
|
@@ -1072,10 +1325,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1072
1325
|
systemInstruction: isGemmaModel ? void 0 : systemInstruction,
|
|
1073
1326
|
safetySettings: googleOptions == null ? void 0 : googleOptions.safetySettings,
|
|
1074
1327
|
tools: googleTools2,
|
|
1075
|
-
toolConfig
|
|
1076
|
-
...googleToolConfig,
|
|
1077
|
-
retrievalConfig: googleOptions.retrievalConfig
|
|
1078
|
-
} : googleToolConfig,
|
|
1328
|
+
toolConfig,
|
|
1079
1329
|
cachedContent: googleOptions == null ? void 0 : googleOptions.cachedContent,
|
|
1080
1330
|
labels: googleOptions == null ? void 0 : googleOptions.labels,
|
|
1081
1331
|
serviceTier: googleOptions == null ? void 0 : googleOptions.serviceTier
|
|
@@ -1153,7 +1403,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1153
1403
|
providerMetadata: thoughtSignatureMetadata
|
|
1154
1404
|
});
|
|
1155
1405
|
}
|
|
1156
|
-
} else if ("functionCall" in part) {
|
|
1406
|
+
} else if ("functionCall" in part && part.functionCall.name != null && part.functionCall.args != null) {
|
|
1157
1407
|
content.push({
|
|
1158
1408
|
type: "tool-call",
|
|
1159
1409
|
toolCallId: this.config.generateId(),
|
|
@@ -1298,6 +1548,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1298
1548
|
const emittedSourceUrls = /* @__PURE__ */ new Set();
|
|
1299
1549
|
let lastCodeExecutionToolCallId;
|
|
1300
1550
|
let lastServerToolCallId;
|
|
1551
|
+
const activeStreamingToolCalls = [];
|
|
1301
1552
|
return {
|
|
1302
1553
|
stream: response.pipeThrough(
|
|
1303
1554
|
new TransformStream({
|
|
@@ -1305,7 +1556,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1305
1556
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1306
1557
|
},
|
|
1307
1558
|
transform(chunk, controller) {
|
|
1308
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
1559
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
1309
1560
|
if (options.includeRawChunks) {
|
|
1310
1561
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1311
1562
|
}
|
|
@@ -1497,36 +1748,110 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1497
1748
|
lastServerToolCallId = void 0;
|
|
1498
1749
|
}
|
|
1499
1750
|
}
|
|
1500
|
-
const
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1751
|
+
for (const part of parts) {
|
|
1752
|
+
if (!("functionCall" in part)) continue;
|
|
1753
|
+
const providerMeta = part.thoughtSignature ? {
|
|
1754
|
+
[providerOptionsName]: {
|
|
1755
|
+
thoughtSignature: part.thoughtSignature
|
|
1756
|
+
}
|
|
1757
|
+
} : void 0;
|
|
1758
|
+
const isStreamingChunk = part.functionCall.partialArgs != null || part.functionCall.name != null && part.functionCall.willContinue === true;
|
|
1759
|
+
const isTerminalChunk = part.functionCall.name == null && part.functionCall.args == null && part.functionCall.partialArgs == null && part.functionCall.willContinue == null;
|
|
1760
|
+
const isCompleteCall = part.functionCall.name != null && part.functionCall.args != null && part.functionCall.partialArgs == null;
|
|
1761
|
+
if (isStreamingChunk) {
|
|
1762
|
+
if (part.functionCall.name != null && part.functionCall.willContinue === true) {
|
|
1763
|
+
const toolCallId = generateId2();
|
|
1764
|
+
const accumulator = new GoogleJSONAccumulator();
|
|
1765
|
+
activeStreamingToolCalls.push({
|
|
1766
|
+
toolCallId,
|
|
1767
|
+
toolName: part.functionCall.name,
|
|
1768
|
+
accumulator,
|
|
1769
|
+
providerMetadata: providerMeta
|
|
1770
|
+
});
|
|
1771
|
+
controller.enqueue({
|
|
1772
|
+
type: "tool-input-start",
|
|
1773
|
+
id: toolCallId,
|
|
1774
|
+
toolName: part.functionCall.name,
|
|
1775
|
+
providerMetadata: providerMeta
|
|
1776
|
+
});
|
|
1777
|
+
if (part.functionCall.partialArgs != null) {
|
|
1778
|
+
const { textDelta } = accumulator.processPartialArgs(
|
|
1779
|
+
part.functionCall.partialArgs
|
|
1780
|
+
);
|
|
1781
|
+
if (textDelta.length > 0) {
|
|
1782
|
+
controller.enqueue({
|
|
1783
|
+
type: "tool-input-delta",
|
|
1784
|
+
id: toolCallId,
|
|
1785
|
+
delta: textDelta,
|
|
1786
|
+
providerMetadata: providerMeta
|
|
1787
|
+
});
|
|
1788
|
+
}
|
|
1789
|
+
}
|
|
1790
|
+
} else if (part.functionCall.partialArgs != null && activeStreamingToolCalls.length > 0) {
|
|
1791
|
+
const active = activeStreamingToolCalls[activeStreamingToolCalls.length - 1];
|
|
1792
|
+
const { textDelta } = active.accumulator.processPartialArgs(
|
|
1793
|
+
part.functionCall.partialArgs
|
|
1794
|
+
);
|
|
1795
|
+
if (textDelta.length > 0) {
|
|
1796
|
+
controller.enqueue({
|
|
1797
|
+
type: "tool-input-delta",
|
|
1798
|
+
id: active.toolCallId,
|
|
1799
|
+
delta: textDelta,
|
|
1800
|
+
providerMetadata: providerMeta
|
|
1801
|
+
});
|
|
1802
|
+
}
|
|
1803
|
+
}
|
|
1804
|
+
} else if (isTerminalChunk && activeStreamingToolCalls.length > 0) {
|
|
1805
|
+
const active = activeStreamingToolCalls.pop();
|
|
1806
|
+
const { finalJSON, closingDelta } = active.accumulator.finalize();
|
|
1807
|
+
if (closingDelta.length > 0) {
|
|
1808
|
+
controller.enqueue({
|
|
1809
|
+
type: "tool-input-delta",
|
|
1810
|
+
id: active.toolCallId,
|
|
1811
|
+
delta: closingDelta,
|
|
1812
|
+
providerMetadata: active.providerMetadata
|
|
1813
|
+
});
|
|
1814
|
+
}
|
|
1815
|
+
controller.enqueue({
|
|
1816
|
+
type: "tool-input-end",
|
|
1817
|
+
id: active.toolCallId,
|
|
1818
|
+
providerMetadata: active.providerMetadata
|
|
1819
|
+
});
|
|
1820
|
+
controller.enqueue({
|
|
1821
|
+
type: "tool-call",
|
|
1822
|
+
toolCallId: active.toolCallId,
|
|
1823
|
+
toolName: active.toolName,
|
|
1824
|
+
input: finalJSON,
|
|
1825
|
+
providerMetadata: active.providerMetadata
|
|
1826
|
+
});
|
|
1827
|
+
hasToolCalls = true;
|
|
1828
|
+
} else if (isCompleteCall) {
|
|
1829
|
+
const toolCallId = generateId2();
|
|
1830
|
+
const toolName = part.functionCall.name;
|
|
1831
|
+
const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((_i = part.functionCall.args) != null ? _i : {});
|
|
1507
1832
|
controller.enqueue({
|
|
1508
1833
|
type: "tool-input-start",
|
|
1509
|
-
id:
|
|
1510
|
-
toolName
|
|
1511
|
-
providerMetadata:
|
|
1834
|
+
id: toolCallId,
|
|
1835
|
+
toolName,
|
|
1836
|
+
providerMetadata: providerMeta
|
|
1512
1837
|
});
|
|
1513
1838
|
controller.enqueue({
|
|
1514
1839
|
type: "tool-input-delta",
|
|
1515
|
-
id:
|
|
1516
|
-
delta:
|
|
1517
|
-
providerMetadata:
|
|
1840
|
+
id: toolCallId,
|
|
1841
|
+
delta: args2,
|
|
1842
|
+
providerMetadata: providerMeta
|
|
1518
1843
|
});
|
|
1519
1844
|
controller.enqueue({
|
|
1520
1845
|
type: "tool-input-end",
|
|
1521
|
-
id:
|
|
1522
|
-
providerMetadata:
|
|
1846
|
+
id: toolCallId,
|
|
1847
|
+
providerMetadata: providerMeta
|
|
1523
1848
|
});
|
|
1524
1849
|
controller.enqueue({
|
|
1525
1850
|
type: "tool-call",
|
|
1526
|
-
toolCallId
|
|
1527
|
-
toolName
|
|
1528
|
-
input:
|
|
1529
|
-
providerMetadata:
|
|
1851
|
+
toolCallId,
|
|
1852
|
+
toolName,
|
|
1853
|
+
input: args2,
|
|
1854
|
+
providerMetadata: providerMeta
|
|
1530
1855
|
});
|
|
1531
1856
|
hasToolCalls = true;
|
|
1532
1857
|
}
|
|
@@ -1542,12 +1867,12 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1542
1867
|
};
|
|
1543
1868
|
providerMetadata = {
|
|
1544
1869
|
[providerOptionsName]: {
|
|
1545
|
-
promptFeedback: (
|
|
1870
|
+
promptFeedback: (_j = value.promptFeedback) != null ? _j : null,
|
|
1546
1871
|
groundingMetadata: lastGroundingMetadata,
|
|
1547
1872
|
urlContextMetadata: lastUrlContextMetadata,
|
|
1548
|
-
safetyRatings: (
|
|
1873
|
+
safetyRatings: (_k = candidate.safetyRatings) != null ? _k : null,
|
|
1549
1874
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
1550
|
-
finishMessage: (
|
|
1875
|
+
finishMessage: (_l = candidate.finishMessage) != null ? _l : null,
|
|
1551
1876
|
serviceTier
|
|
1552
1877
|
}
|
|
1553
1878
|
};
|
|
@@ -1649,26 +1974,6 @@ function resolveGemini25ThinkingConfig({
|
|
|
1649
1974
|
}
|
|
1650
1975
|
return { thinkingBudget };
|
|
1651
1976
|
}
|
|
1652
|
-
function getToolCallsFromParts({
|
|
1653
|
-
parts,
|
|
1654
|
-
generateId: generateId2,
|
|
1655
|
-
providerOptionsName
|
|
1656
|
-
}) {
|
|
1657
|
-
const functionCallParts = parts == null ? void 0 : parts.filter(
|
|
1658
|
-
(part) => "functionCall" in part
|
|
1659
|
-
);
|
|
1660
|
-
return functionCallParts == null || functionCallParts.length === 0 ? void 0 : functionCallParts.map((part) => ({
|
|
1661
|
-
type: "tool-call",
|
|
1662
|
-
toolCallId: generateId2(),
|
|
1663
|
-
toolName: part.functionCall.name,
|
|
1664
|
-
args: JSON.stringify(part.functionCall.args),
|
|
1665
|
-
providerMetadata: part.thoughtSignature ? {
|
|
1666
|
-
[providerOptionsName]: {
|
|
1667
|
-
thoughtSignature: part.thoughtSignature
|
|
1668
|
-
}
|
|
1669
|
-
} : void 0
|
|
1670
|
-
}));
|
|
1671
|
-
}
|
|
1672
1977
|
function extractSources({
|
|
1673
1978
|
groundingMetadata,
|
|
1674
1979
|
generateId: generateId2
|
|
@@ -1812,14 +2117,24 @@ var getGroundingMetadataSchema = () => z3.object({
|
|
|
1812
2117
|
z3.object({})
|
|
1813
2118
|
]).nullish()
|
|
1814
2119
|
});
|
|
2120
|
+
var partialArgSchema = z3.object({
|
|
2121
|
+
jsonPath: z3.string(),
|
|
2122
|
+
stringValue: z3.string().nullish(),
|
|
2123
|
+
numberValue: z3.number().nullish(),
|
|
2124
|
+
boolValue: z3.boolean().nullish(),
|
|
2125
|
+
nullValue: z3.unknown().nullish(),
|
|
2126
|
+
willContinue: z3.boolean().nullish()
|
|
2127
|
+
});
|
|
1815
2128
|
var getContentSchema = () => z3.object({
|
|
1816
2129
|
parts: z3.array(
|
|
1817
2130
|
z3.union([
|
|
1818
2131
|
// note: order matters since text can be fully empty
|
|
1819
2132
|
z3.object({
|
|
1820
2133
|
functionCall: z3.object({
|
|
1821
|
-
name: z3.string(),
|
|
1822
|
-
args: z3.unknown()
|
|
2134
|
+
name: z3.string().nullish(),
|
|
2135
|
+
args: z3.unknown().nullish(),
|
|
2136
|
+
partialArgs: z3.array(partialArgSchema).nullish(),
|
|
2137
|
+
willContinue: z3.boolean().nullish()
|
|
1823
2138
|
}),
|
|
1824
2139
|
thoughtSignature: z3.string().nullish()
|
|
1825
2140
|
}),
|