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