@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
|
@@ -86,8 +86,17 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
86
86
|
content?: Record<string, never> | {
|
|
87
87
|
parts?: ({
|
|
88
88
|
functionCall: {
|
|
89
|
-
name
|
|
90
|
-
args
|
|
89
|
+
name?: string | null | undefined;
|
|
90
|
+
args?: unknown;
|
|
91
|
+
partialArgs?: {
|
|
92
|
+
jsonPath: string;
|
|
93
|
+
stringValue?: string | null | undefined;
|
|
94
|
+
numberValue?: number | null | undefined;
|
|
95
|
+
boolValue?: boolean | null | undefined;
|
|
96
|
+
nullValue?: unknown;
|
|
97
|
+
willContinue?: boolean | null | undefined;
|
|
98
|
+
}[] | null | undefined;
|
|
99
|
+
willContinue?: boolean | null | undefined;
|
|
91
100
|
};
|
|
92
101
|
thoughtSignature?: string | null | undefined;
|
|
93
102
|
} | {
|
package/dist/internal/index.d.ts
CHANGED
|
@@ -86,8 +86,17 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
86
86
|
content?: Record<string, never> | {
|
|
87
87
|
parts?: ({
|
|
88
88
|
functionCall: {
|
|
89
|
-
name
|
|
90
|
-
args
|
|
89
|
+
name?: string | null | undefined;
|
|
90
|
+
args?: unknown;
|
|
91
|
+
partialArgs?: {
|
|
92
|
+
jsonPath: string;
|
|
93
|
+
stringValue?: string | null | undefined;
|
|
94
|
+
numberValue?: number | null | undefined;
|
|
95
|
+
boolValue?: boolean | null | undefined;
|
|
96
|
+
nullValue?: unknown;
|
|
97
|
+
willContinue?: boolean | null | undefined;
|
|
98
|
+
}[] | null | undefined;
|
|
99
|
+
willContinue?: boolean | null | undefined;
|
|
91
100
|
};
|
|
92
101
|
thoughtSignature?: string | null | undefined;
|
|
93
102
|
} | {
|
package/dist/internal/index.js
CHANGED
|
@@ -627,6 +627,16 @@ var googleLanguageModelOptions = (0, import_provider_utils3.lazySchema)(
|
|
|
627
627
|
longitude: import_v42.z.number()
|
|
628
628
|
}).optional()
|
|
629
629
|
}).optional(),
|
|
630
|
+
/**
|
|
631
|
+
* Optional. When set to true, function call arguments will be streamed
|
|
632
|
+
* incrementally via partialArgs in streaming responses. Only supported
|
|
633
|
+
* on the Vertex AI API (not the Gemini API).
|
|
634
|
+
*
|
|
635
|
+
* @default true
|
|
636
|
+
*
|
|
637
|
+
* https://docs.cloud.google.com/vertex-ai/generative-ai/docs/multimodal/function-calling#streaming-fc
|
|
638
|
+
*/
|
|
639
|
+
streamFunctionCallArguments: import_v42.z.boolean().optional(),
|
|
630
640
|
/**
|
|
631
641
|
* Optional. The service tier to use for the request.
|
|
632
642
|
*/
|
|
@@ -885,6 +895,229 @@ function prepareTools({
|
|
|
885
895
|
}
|
|
886
896
|
}
|
|
887
897
|
|
|
898
|
+
// src/google-json-accumulator.ts
|
|
899
|
+
var GoogleJSONAccumulator = class {
|
|
900
|
+
constructor() {
|
|
901
|
+
this.accumulatedArgs = {};
|
|
902
|
+
this.jsonText = "";
|
|
903
|
+
/**
|
|
904
|
+
* Stack representing the currently "open" containers in the JSON output.
|
|
905
|
+
* Entry 0 is always the root `{` object once the first value is written.
|
|
906
|
+
*/
|
|
907
|
+
this.pathStack = [];
|
|
908
|
+
/**
|
|
909
|
+
* Whether a string value is currently "open" (willContinue was true),
|
|
910
|
+
* meaning the closing quote has not yet been emitted.
|
|
911
|
+
*/
|
|
912
|
+
this.stringOpen = false;
|
|
913
|
+
}
|
|
914
|
+
/**
|
|
915
|
+
* Input: [{jsonPath:"$.brightness",numberValue:50}]
|
|
916
|
+
* Output: { currentJSON:{brightness:50}, textDelta:'{"brightness":50' }
|
|
917
|
+
*/
|
|
918
|
+
processPartialArgs(partialArgs) {
|
|
919
|
+
let delta = "";
|
|
920
|
+
for (const arg of partialArgs) {
|
|
921
|
+
const rawPath = arg.jsonPath.replace(/^\$\./, "");
|
|
922
|
+
if (!rawPath) continue;
|
|
923
|
+
const segments = parsePath(rawPath);
|
|
924
|
+
const existingValue = getNestedValue(this.accumulatedArgs, segments);
|
|
925
|
+
const isStringContinuation = arg.stringValue != null && existingValue !== void 0;
|
|
926
|
+
if (isStringContinuation) {
|
|
927
|
+
const escaped = JSON.stringify(arg.stringValue).slice(1, -1);
|
|
928
|
+
setNestedValue(
|
|
929
|
+
this.accumulatedArgs,
|
|
930
|
+
segments,
|
|
931
|
+
existingValue + arg.stringValue
|
|
932
|
+
);
|
|
933
|
+
delta += escaped;
|
|
934
|
+
continue;
|
|
935
|
+
}
|
|
936
|
+
const resolved = resolvePartialArgValue(arg);
|
|
937
|
+
if (resolved == null) continue;
|
|
938
|
+
setNestedValue(this.accumulatedArgs, segments, resolved.value);
|
|
939
|
+
delta += this.emitNavigationTo(segments, arg, resolved.json);
|
|
940
|
+
}
|
|
941
|
+
this.jsonText += delta;
|
|
942
|
+
return {
|
|
943
|
+
currentJSON: this.accumulatedArgs,
|
|
944
|
+
textDelta: delta
|
|
945
|
+
};
|
|
946
|
+
}
|
|
947
|
+
/**
|
|
948
|
+
* Input: jsonText='{"brightness":50', accumulatedArgs={brightness:50}
|
|
949
|
+
* Output: { finalJSON:'{"brightness":50}', closingDelta:'}' }
|
|
950
|
+
*/
|
|
951
|
+
finalize() {
|
|
952
|
+
const finalArgs = JSON.stringify(this.accumulatedArgs);
|
|
953
|
+
const closingDelta = finalArgs.slice(this.jsonText.length);
|
|
954
|
+
return { finalJSON: finalArgs, closingDelta };
|
|
955
|
+
}
|
|
956
|
+
/**
|
|
957
|
+
* Input: pathStack=[] (first call) or pathStack=[root,...] (subsequent calls)
|
|
958
|
+
* Output: '{' (first call) or '' (subsequent calls)
|
|
959
|
+
*/
|
|
960
|
+
ensureRoot() {
|
|
961
|
+
if (this.pathStack.length === 0) {
|
|
962
|
+
this.pathStack.push({ segment: "", isArray: false, childCount: 0 });
|
|
963
|
+
return "{";
|
|
964
|
+
}
|
|
965
|
+
return "";
|
|
966
|
+
}
|
|
967
|
+
/**
|
|
968
|
+
* Emits the JSON text fragment needed to navigate from the current open
|
|
969
|
+
* path to the new leaf at `targetSegments`, then writes the value.
|
|
970
|
+
*
|
|
971
|
+
* Input: targetSegments=["recipe","name"], arg={jsonPath:"$.recipe.name",stringValue:"Lasagna"}, valueJson='"Lasagna"'
|
|
972
|
+
* Output: '{"recipe":{"name":"Lasagna"'
|
|
973
|
+
*/
|
|
974
|
+
emitNavigationTo(targetSegments, arg, valueJson) {
|
|
975
|
+
let fragment = "";
|
|
976
|
+
if (this.stringOpen) {
|
|
977
|
+
fragment += '"';
|
|
978
|
+
this.stringOpen = false;
|
|
979
|
+
}
|
|
980
|
+
fragment += this.ensureRoot();
|
|
981
|
+
const targetContainerSegments = targetSegments.slice(0, -1);
|
|
982
|
+
const leafSegment = targetSegments[targetSegments.length - 1];
|
|
983
|
+
const commonDepth = this.findCommonStackDepth(targetContainerSegments);
|
|
984
|
+
fragment += this.closeDownTo(commonDepth);
|
|
985
|
+
fragment += this.openDownTo(targetContainerSegments, leafSegment);
|
|
986
|
+
fragment += this.emitLeaf(leafSegment, arg, valueJson);
|
|
987
|
+
return fragment;
|
|
988
|
+
}
|
|
989
|
+
/**
|
|
990
|
+
* Returns the stack depth to preserve when navigating to a new target
|
|
991
|
+
* container path. Always >= 1 (the root is never popped).
|
|
992
|
+
*
|
|
993
|
+
* Input: stack=[root,"recipe","ingredients",0], target=["recipe","ingredients",1]
|
|
994
|
+
* Output: 3 (keep root+"recipe"+"ingredients")
|
|
995
|
+
*/
|
|
996
|
+
findCommonStackDepth(targetContainer) {
|
|
997
|
+
const maxDepth = Math.min(
|
|
998
|
+
this.pathStack.length - 1,
|
|
999
|
+
targetContainer.length
|
|
1000
|
+
);
|
|
1001
|
+
let common = 0;
|
|
1002
|
+
for (let i = 0; i < maxDepth; i++) {
|
|
1003
|
+
if (this.pathStack[i + 1].segment === targetContainer[i]) {
|
|
1004
|
+
common++;
|
|
1005
|
+
} else {
|
|
1006
|
+
break;
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
return common + 1;
|
|
1010
|
+
}
|
|
1011
|
+
/**
|
|
1012
|
+
* Closes containers from the current stack depth back down to `targetDepth`.
|
|
1013
|
+
*
|
|
1014
|
+
* Input: this.pathStack=[root,"recipe","ingredients",0], targetDepth=3
|
|
1015
|
+
* Output: '}'
|
|
1016
|
+
*/
|
|
1017
|
+
closeDownTo(targetDepth) {
|
|
1018
|
+
let fragment = "";
|
|
1019
|
+
while (this.pathStack.length > targetDepth) {
|
|
1020
|
+
const entry = this.pathStack.pop();
|
|
1021
|
+
fragment += entry.isArray ? "]" : "}";
|
|
1022
|
+
}
|
|
1023
|
+
return fragment;
|
|
1024
|
+
}
|
|
1025
|
+
/**
|
|
1026
|
+
* Opens containers from the current stack depth down to the full target
|
|
1027
|
+
* container path, emitting opening `{`, `[`, keys, and commas as needed.
|
|
1028
|
+
* `leafSegment` is used to determine if the innermost container is an array.
|
|
1029
|
+
*
|
|
1030
|
+
* Input: this.pathStack=[root], targetContainer=["recipe","ingredients"], leafSegment=0
|
|
1031
|
+
* Output: '"recipe":{"ingredients":['
|
|
1032
|
+
*/
|
|
1033
|
+
openDownTo(targetContainer, leafSegment) {
|
|
1034
|
+
let fragment = "";
|
|
1035
|
+
const startIdx = this.pathStack.length - 1;
|
|
1036
|
+
for (let i = startIdx; i < targetContainer.length; i++) {
|
|
1037
|
+
const seg = targetContainer[i];
|
|
1038
|
+
const parentEntry = this.pathStack[this.pathStack.length - 1];
|
|
1039
|
+
if (parentEntry.childCount > 0) {
|
|
1040
|
+
fragment += ",";
|
|
1041
|
+
}
|
|
1042
|
+
parentEntry.childCount++;
|
|
1043
|
+
if (typeof seg === "string") {
|
|
1044
|
+
fragment += `${JSON.stringify(seg)}:`;
|
|
1045
|
+
}
|
|
1046
|
+
const childSeg = i + 1 < targetContainer.length ? targetContainer[i + 1] : leafSegment;
|
|
1047
|
+
const isArray = typeof childSeg === "number";
|
|
1048
|
+
fragment += isArray ? "[" : "{";
|
|
1049
|
+
this.pathStack.push({ segment: seg, isArray, childCount: 0 });
|
|
1050
|
+
}
|
|
1051
|
+
return fragment;
|
|
1052
|
+
}
|
|
1053
|
+
/**
|
|
1054
|
+
* Emits the comma, key, and value for a leaf entry in the current container.
|
|
1055
|
+
*
|
|
1056
|
+
* Input: leafSegment="name", arg={stringValue:"Lasagna"}, valueJson='"Lasagna"'
|
|
1057
|
+
* Output: '"name":"Lasagna"' (or ',"name":"Lasagna"' if container.childCount > 0)
|
|
1058
|
+
*/
|
|
1059
|
+
emitLeaf(leafSegment, arg, valueJson) {
|
|
1060
|
+
let fragment = "";
|
|
1061
|
+
const container = this.pathStack[this.pathStack.length - 1];
|
|
1062
|
+
if (container.childCount > 0) {
|
|
1063
|
+
fragment += ",";
|
|
1064
|
+
}
|
|
1065
|
+
container.childCount++;
|
|
1066
|
+
if (typeof leafSegment === "string") {
|
|
1067
|
+
fragment += `${JSON.stringify(leafSegment)}:`;
|
|
1068
|
+
}
|
|
1069
|
+
if (arg.stringValue != null && arg.willContinue) {
|
|
1070
|
+
fragment += valueJson.slice(0, -1);
|
|
1071
|
+
this.stringOpen = true;
|
|
1072
|
+
} else {
|
|
1073
|
+
fragment += valueJson;
|
|
1074
|
+
}
|
|
1075
|
+
return fragment;
|
|
1076
|
+
}
|
|
1077
|
+
};
|
|
1078
|
+
function parsePath(rawPath) {
|
|
1079
|
+
const segments = [];
|
|
1080
|
+
for (const part of rawPath.split(".")) {
|
|
1081
|
+
const bracketIdx = part.indexOf("[");
|
|
1082
|
+
if (bracketIdx === -1) {
|
|
1083
|
+
segments.push(part);
|
|
1084
|
+
} else {
|
|
1085
|
+
if (bracketIdx > 0) segments.push(part.slice(0, bracketIdx));
|
|
1086
|
+
for (const m of part.matchAll(/\[(\d+)\]/g)) {
|
|
1087
|
+
segments.push(parseInt(m[1], 10));
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
return segments;
|
|
1092
|
+
}
|
|
1093
|
+
function getNestedValue(obj, segments) {
|
|
1094
|
+
let current = obj;
|
|
1095
|
+
for (const seg of segments) {
|
|
1096
|
+
if (current == null || typeof current !== "object") return void 0;
|
|
1097
|
+
current = current[seg];
|
|
1098
|
+
}
|
|
1099
|
+
return current;
|
|
1100
|
+
}
|
|
1101
|
+
function setNestedValue(obj, segments, value) {
|
|
1102
|
+
let current = obj;
|
|
1103
|
+
for (let i = 0; i < segments.length - 1; i++) {
|
|
1104
|
+
const seg = segments[i];
|
|
1105
|
+
const nextSeg = segments[i + 1];
|
|
1106
|
+
if (current[seg] == null) {
|
|
1107
|
+
current[seg] = typeof nextSeg === "number" ? [] : {};
|
|
1108
|
+
}
|
|
1109
|
+
current = current[seg];
|
|
1110
|
+
}
|
|
1111
|
+
current[segments[segments.length - 1]] = value;
|
|
1112
|
+
}
|
|
1113
|
+
function resolvePartialArgValue(arg) {
|
|
1114
|
+
var _a, _b;
|
|
1115
|
+
const value = (_b = (_a = arg.stringValue) != null ? _a : arg.numberValue) != null ? _b : arg.boolValue;
|
|
1116
|
+
if (value != null) return { value, json: JSON.stringify(value) };
|
|
1117
|
+
if ("nullValue" in arg) return { value: null, json: "null" };
|
|
1118
|
+
return void 0;
|
|
1119
|
+
}
|
|
1120
|
+
|
|
888
1121
|
// src/map-google-generative-ai-finish-reason.ts
|
|
889
1122
|
function mapGoogleGenerativeAIFinishReason({
|
|
890
1123
|
finishReason,
|
|
@@ -942,7 +1175,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
942
1175
|
toolChoice,
|
|
943
1176
|
providerOptions
|
|
944
1177
|
}) {
|
|
945
|
-
var _a;
|
|
1178
|
+
var _a, _b;
|
|
946
1179
|
const warnings = [];
|
|
947
1180
|
const providerOptionsName = this.config.provider.includes("vertex") ? "vertex" : "google";
|
|
948
1181
|
let googleOptions = await (0, import_provider_utils4.parseProviderOptions)({
|
|
@@ -957,14 +1190,21 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
957
1190
|
schema: googleLanguageModelOptions
|
|
958
1191
|
});
|
|
959
1192
|
}
|
|
1193
|
+
const isVertexProvider = this.config.provider.startsWith("google.vertex.");
|
|
960
1194
|
if ((tools == null ? void 0 : tools.some(
|
|
961
1195
|
(tool) => tool.type === "provider" && tool.id === "google.vertex_rag_store"
|
|
962
|
-
)) && !
|
|
1196
|
+
)) && !isVertexProvider) {
|
|
963
1197
|
warnings.push({
|
|
964
1198
|
type: "other",
|
|
965
1199
|
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}).`
|
|
966
1200
|
});
|
|
967
1201
|
}
|
|
1202
|
+
if ((googleOptions == null ? void 0 : googleOptions.streamFunctionCallArguments) && !isVertexProvider) {
|
|
1203
|
+
warnings.push({
|
|
1204
|
+
type: "other",
|
|
1205
|
+
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`
|
|
1206
|
+
});
|
|
1207
|
+
}
|
|
968
1208
|
const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
|
|
969
1209
|
const supportsFunctionResponseParts = this.modelId.startsWith("gemini-3");
|
|
970
1210
|
const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
|
|
@@ -984,6 +1224,19 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
984
1224
|
toolChoice,
|
|
985
1225
|
modelId: this.modelId
|
|
986
1226
|
});
|
|
1227
|
+
const streamFunctionCallArguments = isVertexProvider ? (_a = googleOptions == null ? void 0 : googleOptions.streamFunctionCallArguments) != null ? _a : true : void 0;
|
|
1228
|
+
const toolConfig = googleToolConfig || streamFunctionCallArguments || (googleOptions == null ? void 0 : googleOptions.retrievalConfig) ? {
|
|
1229
|
+
...googleToolConfig,
|
|
1230
|
+
...streamFunctionCallArguments && {
|
|
1231
|
+
functionCallingConfig: {
|
|
1232
|
+
...googleToolConfig == null ? void 0 : googleToolConfig.functionCallingConfig,
|
|
1233
|
+
streamFunctionCallArguments: true
|
|
1234
|
+
}
|
|
1235
|
+
},
|
|
1236
|
+
...(googleOptions == null ? void 0 : googleOptions.retrievalConfig) && {
|
|
1237
|
+
retrievalConfig: googleOptions.retrievalConfig
|
|
1238
|
+
}
|
|
1239
|
+
} : void 0;
|
|
987
1240
|
return {
|
|
988
1241
|
args: {
|
|
989
1242
|
generationConfig: {
|
|
@@ -1001,7 +1254,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1001
1254
|
responseSchema: (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && // Google GenAI does not support all OpenAPI Schema features,
|
|
1002
1255
|
// so this is needed as an escape hatch:
|
|
1003
1256
|
// TODO convert into provider option
|
|
1004
|
-
((
|
|
1257
|
+
((_b = googleOptions == null ? void 0 : googleOptions.structuredOutputs) != null ? _b : true) ? convertJSONSchemaToOpenAPISchema(responseFormat.schema) : void 0,
|
|
1005
1258
|
...(googleOptions == null ? void 0 : googleOptions.audioTimestamp) && {
|
|
1006
1259
|
audioTimestamp: googleOptions.audioTimestamp
|
|
1007
1260
|
},
|
|
@@ -1019,10 +1272,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1019
1272
|
systemInstruction: isGemmaModel ? void 0 : systemInstruction,
|
|
1020
1273
|
safetySettings: googleOptions == null ? void 0 : googleOptions.safetySettings,
|
|
1021
1274
|
tools: googleTools2,
|
|
1022
|
-
toolConfig
|
|
1023
|
-
...googleToolConfig,
|
|
1024
|
-
retrievalConfig: googleOptions.retrievalConfig
|
|
1025
|
-
} : googleToolConfig,
|
|
1275
|
+
toolConfig,
|
|
1026
1276
|
cachedContent: googleOptions == null ? void 0 : googleOptions.cachedContent,
|
|
1027
1277
|
labels: googleOptions == null ? void 0 : googleOptions.labels,
|
|
1028
1278
|
serviceTier: googleOptions == null ? void 0 : googleOptions.serviceTier
|
|
@@ -1100,7 +1350,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1100
1350
|
providerMetadata: thoughtSignatureMetadata
|
|
1101
1351
|
});
|
|
1102
1352
|
}
|
|
1103
|
-
} else if ("functionCall" in part) {
|
|
1353
|
+
} else if ("functionCall" in part && part.functionCall.name != null && part.functionCall.args != null) {
|
|
1104
1354
|
content.push({
|
|
1105
1355
|
type: "tool-call",
|
|
1106
1356
|
toolCallId: this.config.generateId(),
|
|
@@ -1246,6 +1496,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1246
1496
|
const emittedSourceUrls = /* @__PURE__ */ new Set();
|
|
1247
1497
|
let lastCodeExecutionToolCallId;
|
|
1248
1498
|
let lastServerToolCallId;
|
|
1499
|
+
const activeStreamingToolCalls = [];
|
|
1249
1500
|
return {
|
|
1250
1501
|
stream: response.pipeThrough(
|
|
1251
1502
|
new TransformStream({
|
|
@@ -1253,7 +1504,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1253
1504
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1254
1505
|
},
|
|
1255
1506
|
transform(chunk, controller) {
|
|
1256
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
1507
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
1257
1508
|
if (options.includeRawChunks) {
|
|
1258
1509
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1259
1510
|
}
|
|
@@ -1446,36 +1697,110 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1446
1697
|
lastServerToolCallId = void 0;
|
|
1447
1698
|
}
|
|
1448
1699
|
}
|
|
1449
|
-
const
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1700
|
+
for (const part of parts) {
|
|
1701
|
+
if (!("functionCall" in part)) continue;
|
|
1702
|
+
const providerMeta = part.thoughtSignature ? {
|
|
1703
|
+
[providerOptionsName]: {
|
|
1704
|
+
thoughtSignature: part.thoughtSignature
|
|
1705
|
+
}
|
|
1706
|
+
} : void 0;
|
|
1707
|
+
const isStreamingChunk = part.functionCall.partialArgs != null || part.functionCall.name != null && part.functionCall.willContinue === true;
|
|
1708
|
+
const isTerminalChunk = part.functionCall.name == null && part.functionCall.args == null && part.functionCall.partialArgs == null && part.functionCall.willContinue == null;
|
|
1709
|
+
const isCompleteCall = part.functionCall.name != null && part.functionCall.args != null && part.functionCall.partialArgs == null;
|
|
1710
|
+
if (isStreamingChunk) {
|
|
1711
|
+
if (part.functionCall.name != null && part.functionCall.willContinue === true) {
|
|
1712
|
+
const toolCallId = generateId2();
|
|
1713
|
+
const accumulator = new GoogleJSONAccumulator();
|
|
1714
|
+
activeStreamingToolCalls.push({
|
|
1715
|
+
toolCallId,
|
|
1716
|
+
toolName: part.functionCall.name,
|
|
1717
|
+
accumulator,
|
|
1718
|
+
providerMetadata: providerMeta
|
|
1719
|
+
});
|
|
1720
|
+
controller.enqueue({
|
|
1721
|
+
type: "tool-input-start",
|
|
1722
|
+
id: toolCallId,
|
|
1723
|
+
toolName: part.functionCall.name,
|
|
1724
|
+
providerMetadata: providerMeta
|
|
1725
|
+
});
|
|
1726
|
+
if (part.functionCall.partialArgs != null) {
|
|
1727
|
+
const { textDelta } = accumulator.processPartialArgs(
|
|
1728
|
+
part.functionCall.partialArgs
|
|
1729
|
+
);
|
|
1730
|
+
if (textDelta.length > 0) {
|
|
1731
|
+
controller.enqueue({
|
|
1732
|
+
type: "tool-input-delta",
|
|
1733
|
+
id: toolCallId,
|
|
1734
|
+
delta: textDelta,
|
|
1735
|
+
providerMetadata: providerMeta
|
|
1736
|
+
});
|
|
1737
|
+
}
|
|
1738
|
+
}
|
|
1739
|
+
} else if (part.functionCall.partialArgs != null && activeStreamingToolCalls.length > 0) {
|
|
1740
|
+
const active = activeStreamingToolCalls[activeStreamingToolCalls.length - 1];
|
|
1741
|
+
const { textDelta } = active.accumulator.processPartialArgs(
|
|
1742
|
+
part.functionCall.partialArgs
|
|
1743
|
+
);
|
|
1744
|
+
if (textDelta.length > 0) {
|
|
1745
|
+
controller.enqueue({
|
|
1746
|
+
type: "tool-input-delta",
|
|
1747
|
+
id: active.toolCallId,
|
|
1748
|
+
delta: textDelta,
|
|
1749
|
+
providerMetadata: providerMeta
|
|
1750
|
+
});
|
|
1751
|
+
}
|
|
1752
|
+
}
|
|
1753
|
+
} else if (isTerminalChunk && activeStreamingToolCalls.length > 0) {
|
|
1754
|
+
const active = activeStreamingToolCalls.pop();
|
|
1755
|
+
const { finalJSON, closingDelta } = active.accumulator.finalize();
|
|
1756
|
+
if (closingDelta.length > 0) {
|
|
1757
|
+
controller.enqueue({
|
|
1758
|
+
type: "tool-input-delta",
|
|
1759
|
+
id: active.toolCallId,
|
|
1760
|
+
delta: closingDelta,
|
|
1761
|
+
providerMetadata: active.providerMetadata
|
|
1762
|
+
});
|
|
1763
|
+
}
|
|
1764
|
+
controller.enqueue({
|
|
1765
|
+
type: "tool-input-end",
|
|
1766
|
+
id: active.toolCallId,
|
|
1767
|
+
providerMetadata: active.providerMetadata
|
|
1768
|
+
});
|
|
1769
|
+
controller.enqueue({
|
|
1770
|
+
type: "tool-call",
|
|
1771
|
+
toolCallId: active.toolCallId,
|
|
1772
|
+
toolName: active.toolName,
|
|
1773
|
+
input: finalJSON,
|
|
1774
|
+
providerMetadata: active.providerMetadata
|
|
1775
|
+
});
|
|
1776
|
+
hasToolCalls = true;
|
|
1777
|
+
} else if (isCompleteCall) {
|
|
1778
|
+
const toolCallId = generateId2();
|
|
1779
|
+
const toolName = part.functionCall.name;
|
|
1780
|
+
const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((_i = part.functionCall.args) != null ? _i : {});
|
|
1456
1781
|
controller.enqueue({
|
|
1457
1782
|
type: "tool-input-start",
|
|
1458
|
-
id:
|
|
1459
|
-
toolName
|
|
1460
|
-
providerMetadata:
|
|
1783
|
+
id: toolCallId,
|
|
1784
|
+
toolName,
|
|
1785
|
+
providerMetadata: providerMeta
|
|
1461
1786
|
});
|
|
1462
1787
|
controller.enqueue({
|
|
1463
1788
|
type: "tool-input-delta",
|
|
1464
|
-
id:
|
|
1465
|
-
delta:
|
|
1466
|
-
providerMetadata:
|
|
1789
|
+
id: toolCallId,
|
|
1790
|
+
delta: args2,
|
|
1791
|
+
providerMetadata: providerMeta
|
|
1467
1792
|
});
|
|
1468
1793
|
controller.enqueue({
|
|
1469
1794
|
type: "tool-input-end",
|
|
1470
|
-
id:
|
|
1471
|
-
providerMetadata:
|
|
1795
|
+
id: toolCallId,
|
|
1796
|
+
providerMetadata: providerMeta
|
|
1472
1797
|
});
|
|
1473
1798
|
controller.enqueue({
|
|
1474
1799
|
type: "tool-call",
|
|
1475
|
-
toolCallId
|
|
1476
|
-
toolName
|
|
1477
|
-
input:
|
|
1478
|
-
providerMetadata:
|
|
1800
|
+
toolCallId,
|
|
1801
|
+
toolName,
|
|
1802
|
+
input: args2,
|
|
1803
|
+
providerMetadata: providerMeta
|
|
1479
1804
|
});
|
|
1480
1805
|
hasToolCalls = true;
|
|
1481
1806
|
}
|
|
@@ -1491,12 +1816,12 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1491
1816
|
};
|
|
1492
1817
|
providerMetadata = {
|
|
1493
1818
|
[providerOptionsName]: {
|
|
1494
|
-
promptFeedback: (
|
|
1819
|
+
promptFeedback: (_j = value.promptFeedback) != null ? _j : null,
|
|
1495
1820
|
groundingMetadata: lastGroundingMetadata,
|
|
1496
1821
|
urlContextMetadata: lastUrlContextMetadata,
|
|
1497
|
-
safetyRatings: (
|
|
1822
|
+
safetyRatings: (_k = candidate.safetyRatings) != null ? _k : null,
|
|
1498
1823
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
1499
|
-
finishMessage: (
|
|
1824
|
+
finishMessage: (_l = candidate.finishMessage) != null ? _l : null,
|
|
1500
1825
|
serviceTier
|
|
1501
1826
|
}
|
|
1502
1827
|
};
|
|
@@ -1529,26 +1854,6 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1529
1854
|
};
|
|
1530
1855
|
}
|
|
1531
1856
|
};
|
|
1532
|
-
function getToolCallsFromParts({
|
|
1533
|
-
parts,
|
|
1534
|
-
generateId: generateId2,
|
|
1535
|
-
providerOptionsName
|
|
1536
|
-
}) {
|
|
1537
|
-
const functionCallParts = parts == null ? void 0 : parts.filter(
|
|
1538
|
-
(part) => "functionCall" in part
|
|
1539
|
-
);
|
|
1540
|
-
return functionCallParts == null || functionCallParts.length === 0 ? void 0 : functionCallParts.map((part) => ({
|
|
1541
|
-
type: "tool-call",
|
|
1542
|
-
toolCallId: generateId2(),
|
|
1543
|
-
toolName: part.functionCall.name,
|
|
1544
|
-
args: JSON.stringify(part.functionCall.args),
|
|
1545
|
-
providerMetadata: part.thoughtSignature ? {
|
|
1546
|
-
[providerOptionsName]: {
|
|
1547
|
-
thoughtSignature: part.thoughtSignature
|
|
1548
|
-
}
|
|
1549
|
-
} : void 0
|
|
1550
|
-
}));
|
|
1551
|
-
}
|
|
1552
1857
|
function extractSources({
|
|
1553
1858
|
groundingMetadata,
|
|
1554
1859
|
generateId: generateId2
|
|
@@ -1692,14 +1997,24 @@ var getGroundingMetadataSchema = () => import_v43.z.object({
|
|
|
1692
1997
|
import_v43.z.object({})
|
|
1693
1998
|
]).nullish()
|
|
1694
1999
|
});
|
|
2000
|
+
var partialArgSchema = import_v43.z.object({
|
|
2001
|
+
jsonPath: import_v43.z.string(),
|
|
2002
|
+
stringValue: import_v43.z.string().nullish(),
|
|
2003
|
+
numberValue: import_v43.z.number().nullish(),
|
|
2004
|
+
boolValue: import_v43.z.boolean().nullish(),
|
|
2005
|
+
nullValue: import_v43.z.unknown().nullish(),
|
|
2006
|
+
willContinue: import_v43.z.boolean().nullish()
|
|
2007
|
+
});
|
|
1695
2008
|
var getContentSchema = () => import_v43.z.object({
|
|
1696
2009
|
parts: import_v43.z.array(
|
|
1697
2010
|
import_v43.z.union([
|
|
1698
2011
|
// note: order matters since text can be fully empty
|
|
1699
2012
|
import_v43.z.object({
|
|
1700
2013
|
functionCall: import_v43.z.object({
|
|
1701
|
-
name: import_v43.z.string(),
|
|
1702
|
-
args: import_v43.z.unknown()
|
|
2014
|
+
name: import_v43.z.string().nullish(),
|
|
2015
|
+
args: import_v43.z.unknown().nullish(),
|
|
2016
|
+
partialArgs: import_v43.z.array(partialArgSchema).nullish(),
|
|
2017
|
+
willContinue: import_v43.z.boolean().nullish()
|
|
1703
2018
|
}),
|
|
1704
2019
|
thoughtSignature: import_v43.z.string().nullish()
|
|
1705
2020
|
}),
|