@ai-sdk/google 3.0.60 → 3.0.61
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 -29
- 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
|
@@ -614,6 +614,16 @@ var googleLanguageModelOptions = lazySchema2(
|
|
|
614
614
|
longitude: z2.number()
|
|
615
615
|
}).optional()
|
|
616
616
|
}).optional(),
|
|
617
|
+
/**
|
|
618
|
+
* Optional. When set to true, function call arguments will be streamed
|
|
619
|
+
* incrementally via partialArgs in streaming responses. Only supported
|
|
620
|
+
* on the Vertex AI API (not the Gemini API).
|
|
621
|
+
*
|
|
622
|
+
* @default true
|
|
623
|
+
*
|
|
624
|
+
* https://docs.cloud.google.com/vertex-ai/generative-ai/docs/multimodal/function-calling#streaming-fc
|
|
625
|
+
*/
|
|
626
|
+
streamFunctionCallArguments: z2.boolean().optional(),
|
|
617
627
|
/**
|
|
618
628
|
* Optional. The service tier to use for the request.
|
|
619
629
|
*/
|
|
@@ -874,6 +884,229 @@ function prepareTools({
|
|
|
874
884
|
}
|
|
875
885
|
}
|
|
876
886
|
|
|
887
|
+
// src/google-json-accumulator.ts
|
|
888
|
+
var GoogleJSONAccumulator = class {
|
|
889
|
+
constructor() {
|
|
890
|
+
this.accumulatedArgs = {};
|
|
891
|
+
this.jsonText = "";
|
|
892
|
+
/**
|
|
893
|
+
* Stack representing the currently "open" containers in the JSON output.
|
|
894
|
+
* Entry 0 is always the root `{` object once the first value is written.
|
|
895
|
+
*/
|
|
896
|
+
this.pathStack = [];
|
|
897
|
+
/**
|
|
898
|
+
* Whether a string value is currently "open" (willContinue was true),
|
|
899
|
+
* meaning the closing quote has not yet been emitted.
|
|
900
|
+
*/
|
|
901
|
+
this.stringOpen = false;
|
|
902
|
+
}
|
|
903
|
+
/**
|
|
904
|
+
* Input: [{jsonPath:"$.brightness",numberValue:50}]
|
|
905
|
+
* Output: { currentJSON:{brightness:50}, textDelta:'{"brightness":50' }
|
|
906
|
+
*/
|
|
907
|
+
processPartialArgs(partialArgs) {
|
|
908
|
+
let delta = "";
|
|
909
|
+
for (const arg of partialArgs) {
|
|
910
|
+
const rawPath = arg.jsonPath.replace(/^\$\./, "");
|
|
911
|
+
if (!rawPath) continue;
|
|
912
|
+
const segments = parsePath(rawPath);
|
|
913
|
+
const existingValue = getNestedValue(this.accumulatedArgs, segments);
|
|
914
|
+
const isStringContinuation = arg.stringValue != null && existingValue !== void 0;
|
|
915
|
+
if (isStringContinuation) {
|
|
916
|
+
const escaped = JSON.stringify(arg.stringValue).slice(1, -1);
|
|
917
|
+
setNestedValue(
|
|
918
|
+
this.accumulatedArgs,
|
|
919
|
+
segments,
|
|
920
|
+
existingValue + arg.stringValue
|
|
921
|
+
);
|
|
922
|
+
delta += escaped;
|
|
923
|
+
continue;
|
|
924
|
+
}
|
|
925
|
+
const resolved = resolvePartialArgValue(arg);
|
|
926
|
+
if (resolved == null) continue;
|
|
927
|
+
setNestedValue(this.accumulatedArgs, segments, resolved.value);
|
|
928
|
+
delta += this.emitNavigationTo(segments, arg, resolved.json);
|
|
929
|
+
}
|
|
930
|
+
this.jsonText += delta;
|
|
931
|
+
return {
|
|
932
|
+
currentJSON: this.accumulatedArgs,
|
|
933
|
+
textDelta: delta
|
|
934
|
+
};
|
|
935
|
+
}
|
|
936
|
+
/**
|
|
937
|
+
* Input: jsonText='{"brightness":50', accumulatedArgs={brightness:50}
|
|
938
|
+
* Output: { finalJSON:'{"brightness":50}', closingDelta:'}' }
|
|
939
|
+
*/
|
|
940
|
+
finalize() {
|
|
941
|
+
const finalArgs = JSON.stringify(this.accumulatedArgs);
|
|
942
|
+
const closingDelta = finalArgs.slice(this.jsonText.length);
|
|
943
|
+
return { finalJSON: finalArgs, closingDelta };
|
|
944
|
+
}
|
|
945
|
+
/**
|
|
946
|
+
* Input: pathStack=[] (first call) or pathStack=[root,...] (subsequent calls)
|
|
947
|
+
* Output: '{' (first call) or '' (subsequent calls)
|
|
948
|
+
*/
|
|
949
|
+
ensureRoot() {
|
|
950
|
+
if (this.pathStack.length === 0) {
|
|
951
|
+
this.pathStack.push({ segment: "", isArray: false, childCount: 0 });
|
|
952
|
+
return "{";
|
|
953
|
+
}
|
|
954
|
+
return "";
|
|
955
|
+
}
|
|
956
|
+
/**
|
|
957
|
+
* Emits the JSON text fragment needed to navigate from the current open
|
|
958
|
+
* path to the new leaf at `targetSegments`, then writes the value.
|
|
959
|
+
*
|
|
960
|
+
* Input: targetSegments=["recipe","name"], arg={jsonPath:"$.recipe.name",stringValue:"Lasagna"}, valueJson='"Lasagna"'
|
|
961
|
+
* Output: '{"recipe":{"name":"Lasagna"'
|
|
962
|
+
*/
|
|
963
|
+
emitNavigationTo(targetSegments, arg, valueJson) {
|
|
964
|
+
let fragment = "";
|
|
965
|
+
if (this.stringOpen) {
|
|
966
|
+
fragment += '"';
|
|
967
|
+
this.stringOpen = false;
|
|
968
|
+
}
|
|
969
|
+
fragment += this.ensureRoot();
|
|
970
|
+
const targetContainerSegments = targetSegments.slice(0, -1);
|
|
971
|
+
const leafSegment = targetSegments[targetSegments.length - 1];
|
|
972
|
+
const commonDepth = this.findCommonStackDepth(targetContainerSegments);
|
|
973
|
+
fragment += this.closeDownTo(commonDepth);
|
|
974
|
+
fragment += this.openDownTo(targetContainerSegments, leafSegment);
|
|
975
|
+
fragment += this.emitLeaf(leafSegment, arg, valueJson);
|
|
976
|
+
return fragment;
|
|
977
|
+
}
|
|
978
|
+
/**
|
|
979
|
+
* Returns the stack depth to preserve when navigating to a new target
|
|
980
|
+
* container path. Always >= 1 (the root is never popped).
|
|
981
|
+
*
|
|
982
|
+
* Input: stack=[root,"recipe","ingredients",0], target=["recipe","ingredients",1]
|
|
983
|
+
* Output: 3 (keep root+"recipe"+"ingredients")
|
|
984
|
+
*/
|
|
985
|
+
findCommonStackDepth(targetContainer) {
|
|
986
|
+
const maxDepth = Math.min(
|
|
987
|
+
this.pathStack.length - 1,
|
|
988
|
+
targetContainer.length
|
|
989
|
+
);
|
|
990
|
+
let common = 0;
|
|
991
|
+
for (let i = 0; i < maxDepth; i++) {
|
|
992
|
+
if (this.pathStack[i + 1].segment === targetContainer[i]) {
|
|
993
|
+
common++;
|
|
994
|
+
} else {
|
|
995
|
+
break;
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
return common + 1;
|
|
999
|
+
}
|
|
1000
|
+
/**
|
|
1001
|
+
* Closes containers from the current stack depth back down to `targetDepth`.
|
|
1002
|
+
*
|
|
1003
|
+
* Input: this.pathStack=[root,"recipe","ingredients",0], targetDepth=3
|
|
1004
|
+
* Output: '}'
|
|
1005
|
+
*/
|
|
1006
|
+
closeDownTo(targetDepth) {
|
|
1007
|
+
let fragment = "";
|
|
1008
|
+
while (this.pathStack.length > targetDepth) {
|
|
1009
|
+
const entry = this.pathStack.pop();
|
|
1010
|
+
fragment += entry.isArray ? "]" : "}";
|
|
1011
|
+
}
|
|
1012
|
+
return fragment;
|
|
1013
|
+
}
|
|
1014
|
+
/**
|
|
1015
|
+
* Opens containers from the current stack depth down to the full target
|
|
1016
|
+
* container path, emitting opening `{`, `[`, keys, and commas as needed.
|
|
1017
|
+
* `leafSegment` is used to determine if the innermost container is an array.
|
|
1018
|
+
*
|
|
1019
|
+
* Input: this.pathStack=[root], targetContainer=["recipe","ingredients"], leafSegment=0
|
|
1020
|
+
* Output: '"recipe":{"ingredients":['
|
|
1021
|
+
*/
|
|
1022
|
+
openDownTo(targetContainer, leafSegment) {
|
|
1023
|
+
let fragment = "";
|
|
1024
|
+
const startIdx = this.pathStack.length - 1;
|
|
1025
|
+
for (let i = startIdx; i < targetContainer.length; i++) {
|
|
1026
|
+
const seg = targetContainer[i];
|
|
1027
|
+
const parentEntry = this.pathStack[this.pathStack.length - 1];
|
|
1028
|
+
if (parentEntry.childCount > 0) {
|
|
1029
|
+
fragment += ",";
|
|
1030
|
+
}
|
|
1031
|
+
parentEntry.childCount++;
|
|
1032
|
+
if (typeof seg === "string") {
|
|
1033
|
+
fragment += `${JSON.stringify(seg)}:`;
|
|
1034
|
+
}
|
|
1035
|
+
const childSeg = i + 1 < targetContainer.length ? targetContainer[i + 1] : leafSegment;
|
|
1036
|
+
const isArray = typeof childSeg === "number";
|
|
1037
|
+
fragment += isArray ? "[" : "{";
|
|
1038
|
+
this.pathStack.push({ segment: seg, isArray, childCount: 0 });
|
|
1039
|
+
}
|
|
1040
|
+
return fragment;
|
|
1041
|
+
}
|
|
1042
|
+
/**
|
|
1043
|
+
* Emits the comma, key, and value for a leaf entry in the current container.
|
|
1044
|
+
*
|
|
1045
|
+
* Input: leafSegment="name", arg={stringValue:"Lasagna"}, valueJson='"Lasagna"'
|
|
1046
|
+
* Output: '"name":"Lasagna"' (or ',"name":"Lasagna"' if container.childCount > 0)
|
|
1047
|
+
*/
|
|
1048
|
+
emitLeaf(leafSegment, arg, valueJson) {
|
|
1049
|
+
let fragment = "";
|
|
1050
|
+
const container = this.pathStack[this.pathStack.length - 1];
|
|
1051
|
+
if (container.childCount > 0) {
|
|
1052
|
+
fragment += ",";
|
|
1053
|
+
}
|
|
1054
|
+
container.childCount++;
|
|
1055
|
+
if (typeof leafSegment === "string") {
|
|
1056
|
+
fragment += `${JSON.stringify(leafSegment)}:`;
|
|
1057
|
+
}
|
|
1058
|
+
if (arg.stringValue != null && arg.willContinue) {
|
|
1059
|
+
fragment += valueJson.slice(0, -1);
|
|
1060
|
+
this.stringOpen = true;
|
|
1061
|
+
} else {
|
|
1062
|
+
fragment += valueJson;
|
|
1063
|
+
}
|
|
1064
|
+
return fragment;
|
|
1065
|
+
}
|
|
1066
|
+
};
|
|
1067
|
+
function parsePath(rawPath) {
|
|
1068
|
+
const segments = [];
|
|
1069
|
+
for (const part of rawPath.split(".")) {
|
|
1070
|
+
const bracketIdx = part.indexOf("[");
|
|
1071
|
+
if (bracketIdx === -1) {
|
|
1072
|
+
segments.push(part);
|
|
1073
|
+
} else {
|
|
1074
|
+
if (bracketIdx > 0) segments.push(part.slice(0, bracketIdx));
|
|
1075
|
+
for (const m of part.matchAll(/\[(\d+)\]/g)) {
|
|
1076
|
+
segments.push(parseInt(m[1], 10));
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
return segments;
|
|
1081
|
+
}
|
|
1082
|
+
function getNestedValue(obj, segments) {
|
|
1083
|
+
let current = obj;
|
|
1084
|
+
for (const seg of segments) {
|
|
1085
|
+
if (current == null || typeof current !== "object") return void 0;
|
|
1086
|
+
current = current[seg];
|
|
1087
|
+
}
|
|
1088
|
+
return current;
|
|
1089
|
+
}
|
|
1090
|
+
function setNestedValue(obj, segments, value) {
|
|
1091
|
+
let current = obj;
|
|
1092
|
+
for (let i = 0; i < segments.length - 1; i++) {
|
|
1093
|
+
const seg = segments[i];
|
|
1094
|
+
const nextSeg = segments[i + 1];
|
|
1095
|
+
if (current[seg] == null) {
|
|
1096
|
+
current[seg] = typeof nextSeg === "number" ? [] : {};
|
|
1097
|
+
}
|
|
1098
|
+
current = current[seg];
|
|
1099
|
+
}
|
|
1100
|
+
current[segments[segments.length - 1]] = value;
|
|
1101
|
+
}
|
|
1102
|
+
function resolvePartialArgValue(arg) {
|
|
1103
|
+
var _a, _b;
|
|
1104
|
+
const value = (_b = (_a = arg.stringValue) != null ? _a : arg.numberValue) != null ? _b : arg.boolValue;
|
|
1105
|
+
if (value != null) return { value, json: JSON.stringify(value) };
|
|
1106
|
+
if ("nullValue" in arg) return { value: null, json: "null" };
|
|
1107
|
+
return void 0;
|
|
1108
|
+
}
|
|
1109
|
+
|
|
877
1110
|
// src/map-google-generative-ai-finish-reason.ts
|
|
878
1111
|
function mapGoogleGenerativeAIFinishReason({
|
|
879
1112
|
finishReason,
|
|
@@ -931,7 +1164,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
931
1164
|
toolChoice,
|
|
932
1165
|
providerOptions
|
|
933
1166
|
}) {
|
|
934
|
-
var _a;
|
|
1167
|
+
var _a, _b;
|
|
935
1168
|
const warnings = [];
|
|
936
1169
|
const providerOptionsName = this.config.provider.includes("vertex") ? "vertex" : "google";
|
|
937
1170
|
let googleOptions = await parseProviderOptions({
|
|
@@ -946,14 +1179,21 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
946
1179
|
schema: googleLanguageModelOptions
|
|
947
1180
|
});
|
|
948
1181
|
}
|
|
1182
|
+
const isVertexProvider = this.config.provider.startsWith("google.vertex.");
|
|
949
1183
|
if ((tools == null ? void 0 : tools.some(
|
|
950
1184
|
(tool) => tool.type === "provider" && tool.id === "google.vertex_rag_store"
|
|
951
|
-
)) && !
|
|
1185
|
+
)) && !isVertexProvider) {
|
|
952
1186
|
warnings.push({
|
|
953
1187
|
type: "other",
|
|
954
1188
|
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}).`
|
|
955
1189
|
});
|
|
956
1190
|
}
|
|
1191
|
+
if ((googleOptions == null ? void 0 : googleOptions.streamFunctionCallArguments) && !isVertexProvider) {
|
|
1192
|
+
warnings.push({
|
|
1193
|
+
type: "other",
|
|
1194
|
+
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`
|
|
1195
|
+
});
|
|
1196
|
+
}
|
|
957
1197
|
const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
|
|
958
1198
|
const supportsFunctionResponseParts = this.modelId.startsWith("gemini-3");
|
|
959
1199
|
const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
|
|
@@ -973,6 +1213,19 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
973
1213
|
toolChoice,
|
|
974
1214
|
modelId: this.modelId
|
|
975
1215
|
});
|
|
1216
|
+
const streamFunctionCallArguments = isVertexProvider ? (_a = googleOptions == null ? void 0 : googleOptions.streamFunctionCallArguments) != null ? _a : true : void 0;
|
|
1217
|
+
const toolConfig = googleToolConfig || streamFunctionCallArguments || (googleOptions == null ? void 0 : googleOptions.retrievalConfig) ? {
|
|
1218
|
+
...googleToolConfig,
|
|
1219
|
+
...streamFunctionCallArguments && {
|
|
1220
|
+
functionCallingConfig: {
|
|
1221
|
+
...googleToolConfig == null ? void 0 : googleToolConfig.functionCallingConfig,
|
|
1222
|
+
streamFunctionCallArguments: true
|
|
1223
|
+
}
|
|
1224
|
+
},
|
|
1225
|
+
...(googleOptions == null ? void 0 : googleOptions.retrievalConfig) && {
|
|
1226
|
+
retrievalConfig: googleOptions.retrievalConfig
|
|
1227
|
+
}
|
|
1228
|
+
} : void 0;
|
|
976
1229
|
return {
|
|
977
1230
|
args: {
|
|
978
1231
|
generationConfig: {
|
|
@@ -990,7 +1243,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
990
1243
|
responseSchema: (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && // Google GenAI does not support all OpenAPI Schema features,
|
|
991
1244
|
// so this is needed as an escape hatch:
|
|
992
1245
|
// TODO convert into provider option
|
|
993
|
-
((
|
|
1246
|
+
((_b = googleOptions == null ? void 0 : googleOptions.structuredOutputs) != null ? _b : true) ? convertJSONSchemaToOpenAPISchema(responseFormat.schema) : void 0,
|
|
994
1247
|
...(googleOptions == null ? void 0 : googleOptions.audioTimestamp) && {
|
|
995
1248
|
audioTimestamp: googleOptions.audioTimestamp
|
|
996
1249
|
},
|
|
@@ -1008,10 +1261,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1008
1261
|
systemInstruction: isGemmaModel ? void 0 : systemInstruction,
|
|
1009
1262
|
safetySettings: googleOptions == null ? void 0 : googleOptions.safetySettings,
|
|
1010
1263
|
tools: googleTools2,
|
|
1011
|
-
toolConfig
|
|
1012
|
-
...googleToolConfig,
|
|
1013
|
-
retrievalConfig: googleOptions.retrievalConfig
|
|
1014
|
-
} : googleToolConfig,
|
|
1264
|
+
toolConfig,
|
|
1015
1265
|
cachedContent: googleOptions == null ? void 0 : googleOptions.cachedContent,
|
|
1016
1266
|
labels: googleOptions == null ? void 0 : googleOptions.labels,
|
|
1017
1267
|
serviceTier: googleOptions == null ? void 0 : googleOptions.serviceTier
|
|
@@ -1089,7 +1339,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1089
1339
|
providerMetadata: thoughtSignatureMetadata
|
|
1090
1340
|
});
|
|
1091
1341
|
}
|
|
1092
|
-
} else if ("functionCall" in part) {
|
|
1342
|
+
} else if ("functionCall" in part && part.functionCall.name != null && part.functionCall.args != null) {
|
|
1093
1343
|
content.push({
|
|
1094
1344
|
type: "tool-call",
|
|
1095
1345
|
toolCallId: this.config.generateId(),
|
|
@@ -1235,6 +1485,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1235
1485
|
const emittedSourceUrls = /* @__PURE__ */ new Set();
|
|
1236
1486
|
let lastCodeExecutionToolCallId;
|
|
1237
1487
|
let lastServerToolCallId;
|
|
1488
|
+
const activeStreamingToolCalls = [];
|
|
1238
1489
|
return {
|
|
1239
1490
|
stream: response.pipeThrough(
|
|
1240
1491
|
new TransformStream({
|
|
@@ -1242,7 +1493,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1242
1493
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1243
1494
|
},
|
|
1244
1495
|
transform(chunk, controller) {
|
|
1245
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
1496
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
1246
1497
|
if (options.includeRawChunks) {
|
|
1247
1498
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1248
1499
|
}
|
|
@@ -1435,36 +1686,110 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1435
1686
|
lastServerToolCallId = void 0;
|
|
1436
1687
|
}
|
|
1437
1688
|
}
|
|
1438
|
-
const
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1689
|
+
for (const part of parts) {
|
|
1690
|
+
if (!("functionCall" in part)) continue;
|
|
1691
|
+
const providerMeta = part.thoughtSignature ? {
|
|
1692
|
+
[providerOptionsName]: {
|
|
1693
|
+
thoughtSignature: part.thoughtSignature
|
|
1694
|
+
}
|
|
1695
|
+
} : void 0;
|
|
1696
|
+
const isStreamingChunk = part.functionCall.partialArgs != null || part.functionCall.name != null && part.functionCall.willContinue === true;
|
|
1697
|
+
const isTerminalChunk = part.functionCall.name == null && part.functionCall.args == null && part.functionCall.partialArgs == null && part.functionCall.willContinue == null;
|
|
1698
|
+
const isCompleteCall = part.functionCall.name != null && part.functionCall.args != null && part.functionCall.partialArgs == null;
|
|
1699
|
+
if (isStreamingChunk) {
|
|
1700
|
+
if (part.functionCall.name != null && part.functionCall.willContinue === true) {
|
|
1701
|
+
const toolCallId = generateId2();
|
|
1702
|
+
const accumulator = new GoogleJSONAccumulator();
|
|
1703
|
+
activeStreamingToolCalls.push({
|
|
1704
|
+
toolCallId,
|
|
1705
|
+
toolName: part.functionCall.name,
|
|
1706
|
+
accumulator,
|
|
1707
|
+
providerMetadata: providerMeta
|
|
1708
|
+
});
|
|
1709
|
+
controller.enqueue({
|
|
1710
|
+
type: "tool-input-start",
|
|
1711
|
+
id: toolCallId,
|
|
1712
|
+
toolName: part.functionCall.name,
|
|
1713
|
+
providerMetadata: providerMeta
|
|
1714
|
+
});
|
|
1715
|
+
if (part.functionCall.partialArgs != null) {
|
|
1716
|
+
const { textDelta } = accumulator.processPartialArgs(
|
|
1717
|
+
part.functionCall.partialArgs
|
|
1718
|
+
);
|
|
1719
|
+
if (textDelta.length > 0) {
|
|
1720
|
+
controller.enqueue({
|
|
1721
|
+
type: "tool-input-delta",
|
|
1722
|
+
id: toolCallId,
|
|
1723
|
+
delta: textDelta,
|
|
1724
|
+
providerMetadata: providerMeta
|
|
1725
|
+
});
|
|
1726
|
+
}
|
|
1727
|
+
}
|
|
1728
|
+
} else if (part.functionCall.partialArgs != null && activeStreamingToolCalls.length > 0) {
|
|
1729
|
+
const active = activeStreamingToolCalls[activeStreamingToolCalls.length - 1];
|
|
1730
|
+
const { textDelta } = active.accumulator.processPartialArgs(
|
|
1731
|
+
part.functionCall.partialArgs
|
|
1732
|
+
);
|
|
1733
|
+
if (textDelta.length > 0) {
|
|
1734
|
+
controller.enqueue({
|
|
1735
|
+
type: "tool-input-delta",
|
|
1736
|
+
id: active.toolCallId,
|
|
1737
|
+
delta: textDelta,
|
|
1738
|
+
providerMetadata: providerMeta
|
|
1739
|
+
});
|
|
1740
|
+
}
|
|
1741
|
+
}
|
|
1742
|
+
} else if (isTerminalChunk && activeStreamingToolCalls.length > 0) {
|
|
1743
|
+
const active = activeStreamingToolCalls.pop();
|
|
1744
|
+
const { finalJSON, closingDelta } = active.accumulator.finalize();
|
|
1745
|
+
if (closingDelta.length > 0) {
|
|
1746
|
+
controller.enqueue({
|
|
1747
|
+
type: "tool-input-delta",
|
|
1748
|
+
id: active.toolCallId,
|
|
1749
|
+
delta: closingDelta,
|
|
1750
|
+
providerMetadata: active.providerMetadata
|
|
1751
|
+
});
|
|
1752
|
+
}
|
|
1753
|
+
controller.enqueue({
|
|
1754
|
+
type: "tool-input-end",
|
|
1755
|
+
id: active.toolCallId,
|
|
1756
|
+
providerMetadata: active.providerMetadata
|
|
1757
|
+
});
|
|
1758
|
+
controller.enqueue({
|
|
1759
|
+
type: "tool-call",
|
|
1760
|
+
toolCallId: active.toolCallId,
|
|
1761
|
+
toolName: active.toolName,
|
|
1762
|
+
input: finalJSON,
|
|
1763
|
+
providerMetadata: active.providerMetadata
|
|
1764
|
+
});
|
|
1765
|
+
hasToolCalls = true;
|
|
1766
|
+
} else if (isCompleteCall) {
|
|
1767
|
+
const toolCallId = generateId2();
|
|
1768
|
+
const toolName = part.functionCall.name;
|
|
1769
|
+
const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((_i = part.functionCall.args) != null ? _i : {});
|
|
1445
1770
|
controller.enqueue({
|
|
1446
1771
|
type: "tool-input-start",
|
|
1447
|
-
id:
|
|
1448
|
-
toolName
|
|
1449
|
-
providerMetadata:
|
|
1772
|
+
id: toolCallId,
|
|
1773
|
+
toolName,
|
|
1774
|
+
providerMetadata: providerMeta
|
|
1450
1775
|
});
|
|
1451
1776
|
controller.enqueue({
|
|
1452
1777
|
type: "tool-input-delta",
|
|
1453
|
-
id:
|
|
1454
|
-
delta:
|
|
1455
|
-
providerMetadata:
|
|
1778
|
+
id: toolCallId,
|
|
1779
|
+
delta: args2,
|
|
1780
|
+
providerMetadata: providerMeta
|
|
1456
1781
|
});
|
|
1457
1782
|
controller.enqueue({
|
|
1458
1783
|
type: "tool-input-end",
|
|
1459
|
-
id:
|
|
1460
|
-
providerMetadata:
|
|
1784
|
+
id: toolCallId,
|
|
1785
|
+
providerMetadata: providerMeta
|
|
1461
1786
|
});
|
|
1462
1787
|
controller.enqueue({
|
|
1463
1788
|
type: "tool-call",
|
|
1464
|
-
toolCallId
|
|
1465
|
-
toolName
|
|
1466
|
-
input:
|
|
1467
|
-
providerMetadata:
|
|
1789
|
+
toolCallId,
|
|
1790
|
+
toolName,
|
|
1791
|
+
input: args2,
|
|
1792
|
+
providerMetadata: providerMeta
|
|
1468
1793
|
});
|
|
1469
1794
|
hasToolCalls = true;
|
|
1470
1795
|
}
|
|
@@ -1480,12 +1805,12 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1480
1805
|
};
|
|
1481
1806
|
providerMetadata = {
|
|
1482
1807
|
[providerOptionsName]: {
|
|
1483
|
-
promptFeedback: (
|
|
1808
|
+
promptFeedback: (_j = value.promptFeedback) != null ? _j : null,
|
|
1484
1809
|
groundingMetadata: lastGroundingMetadata,
|
|
1485
1810
|
urlContextMetadata: lastUrlContextMetadata,
|
|
1486
|
-
safetyRatings: (
|
|
1811
|
+
safetyRatings: (_k = candidate.safetyRatings) != null ? _k : null,
|
|
1487
1812
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
1488
|
-
finishMessage: (
|
|
1813
|
+
finishMessage: (_l = candidate.finishMessage) != null ? _l : null,
|
|
1489
1814
|
serviceTier
|
|
1490
1815
|
}
|
|
1491
1816
|
};
|
|
@@ -1518,26 +1843,6 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1518
1843
|
};
|
|
1519
1844
|
}
|
|
1520
1845
|
};
|
|
1521
|
-
function getToolCallsFromParts({
|
|
1522
|
-
parts,
|
|
1523
|
-
generateId: generateId2,
|
|
1524
|
-
providerOptionsName
|
|
1525
|
-
}) {
|
|
1526
|
-
const functionCallParts = parts == null ? void 0 : parts.filter(
|
|
1527
|
-
(part) => "functionCall" in part
|
|
1528
|
-
);
|
|
1529
|
-
return functionCallParts == null || functionCallParts.length === 0 ? void 0 : functionCallParts.map((part) => ({
|
|
1530
|
-
type: "tool-call",
|
|
1531
|
-
toolCallId: generateId2(),
|
|
1532
|
-
toolName: part.functionCall.name,
|
|
1533
|
-
args: JSON.stringify(part.functionCall.args),
|
|
1534
|
-
providerMetadata: part.thoughtSignature ? {
|
|
1535
|
-
[providerOptionsName]: {
|
|
1536
|
-
thoughtSignature: part.thoughtSignature
|
|
1537
|
-
}
|
|
1538
|
-
} : void 0
|
|
1539
|
-
}));
|
|
1540
|
-
}
|
|
1541
1846
|
function extractSources({
|
|
1542
1847
|
groundingMetadata,
|
|
1543
1848
|
generateId: generateId2
|
|
@@ -1681,14 +1986,24 @@ var getGroundingMetadataSchema = () => z3.object({
|
|
|
1681
1986
|
z3.object({})
|
|
1682
1987
|
]).nullish()
|
|
1683
1988
|
});
|
|
1989
|
+
var partialArgSchema = z3.object({
|
|
1990
|
+
jsonPath: z3.string(),
|
|
1991
|
+
stringValue: z3.string().nullish(),
|
|
1992
|
+
numberValue: z3.number().nullish(),
|
|
1993
|
+
boolValue: z3.boolean().nullish(),
|
|
1994
|
+
nullValue: z3.unknown().nullish(),
|
|
1995
|
+
willContinue: z3.boolean().nullish()
|
|
1996
|
+
});
|
|
1684
1997
|
var getContentSchema = () => z3.object({
|
|
1685
1998
|
parts: z3.array(
|
|
1686
1999
|
z3.union([
|
|
1687
2000
|
// note: order matters since text can be fully empty
|
|
1688
2001
|
z3.object({
|
|
1689
2002
|
functionCall: z3.object({
|
|
1690
|
-
name: z3.string(),
|
|
1691
|
-
args: z3.unknown()
|
|
2003
|
+
name: z3.string().nullish(),
|
|
2004
|
+
args: z3.unknown().nullish(),
|
|
2005
|
+
partialArgs: z3.array(partialArgSchema).nullish(),
|
|
2006
|
+
willContinue: z3.boolean().nullish()
|
|
1692
2007
|
}),
|
|
1693
2008
|
thoughtSignature: z3.string().nullish()
|
|
1694
2009
|
}),
|