@ai-sdk/google 3.0.60 → 3.0.62
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/index.d.mts +12 -2
- package/dist/index.d.ts +12 -2
- package/dist/index.js +375 -56
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +375 -56
- 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 +374 -55
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +374 -55
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/google-generative-ai-language-model.ts +216 -45
- package/src/google-generative-ai-options.ts +12 -0
- package/src/google-json-accumulator.ts +336 -0
- package/src/google-prepare-tools.ts +1 -0
package/dist/index.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from "@ai-sdk/provider-utils";
|
|
8
8
|
|
|
9
9
|
// src/version.ts
|
|
10
|
-
var VERSION = true ? "3.0.
|
|
10
|
+
var VERSION = true ? "3.0.62" : "0.0.0-test";
|
|
11
11
|
|
|
12
12
|
// src/google-generative-ai-embedding-model.ts
|
|
13
13
|
import {
|
|
@@ -825,6 +825,17 @@ var googleLanguageModelOptions = lazySchema4(
|
|
|
825
825
|
longitude: z4.number()
|
|
826
826
|
}).optional()
|
|
827
827
|
}).optional(),
|
|
828
|
+
/**
|
|
829
|
+
* Optional. When set to true, function call arguments will be streamed
|
|
830
|
+
* incrementally via partialArgs in streaming responses. Only supported
|
|
831
|
+
* on the Vertex AI API (not the Gemini API) and only for Gemini 3+
|
|
832
|
+
* models.
|
|
833
|
+
*
|
|
834
|
+
* @default false
|
|
835
|
+
*
|
|
836
|
+
* https://docs.cloud.google.com/vertex-ai/generative-ai/docs/multimodal/function-calling#streaming-fc
|
|
837
|
+
*/
|
|
838
|
+
streamFunctionCallArguments: z4.boolean().optional(),
|
|
828
839
|
/**
|
|
829
840
|
* Optional. The service tier to use for the request.
|
|
830
841
|
*/
|
|
@@ -1085,6 +1096,229 @@ function prepareTools({
|
|
|
1085
1096
|
}
|
|
1086
1097
|
}
|
|
1087
1098
|
|
|
1099
|
+
// src/google-json-accumulator.ts
|
|
1100
|
+
var GoogleJSONAccumulator = class {
|
|
1101
|
+
constructor() {
|
|
1102
|
+
this.accumulatedArgs = {};
|
|
1103
|
+
this.jsonText = "";
|
|
1104
|
+
/**
|
|
1105
|
+
* Stack representing the currently "open" containers in the JSON output.
|
|
1106
|
+
* Entry 0 is always the root `{` object once the first value is written.
|
|
1107
|
+
*/
|
|
1108
|
+
this.pathStack = [];
|
|
1109
|
+
/**
|
|
1110
|
+
* Whether a string value is currently "open" (willContinue was true),
|
|
1111
|
+
* meaning the closing quote has not yet been emitted.
|
|
1112
|
+
*/
|
|
1113
|
+
this.stringOpen = false;
|
|
1114
|
+
}
|
|
1115
|
+
/**
|
|
1116
|
+
* Input: [{jsonPath:"$.brightness",numberValue:50}]
|
|
1117
|
+
* Output: { currentJSON:{brightness:50}, textDelta:'{"brightness":50' }
|
|
1118
|
+
*/
|
|
1119
|
+
processPartialArgs(partialArgs) {
|
|
1120
|
+
let delta = "";
|
|
1121
|
+
for (const arg of partialArgs) {
|
|
1122
|
+
const rawPath = arg.jsonPath.replace(/^\$\./, "");
|
|
1123
|
+
if (!rawPath) continue;
|
|
1124
|
+
const segments = parsePath(rawPath);
|
|
1125
|
+
const existingValue = getNestedValue(this.accumulatedArgs, segments);
|
|
1126
|
+
const isStringContinuation = arg.stringValue != null && existingValue !== void 0;
|
|
1127
|
+
if (isStringContinuation) {
|
|
1128
|
+
const escaped = JSON.stringify(arg.stringValue).slice(1, -1);
|
|
1129
|
+
setNestedValue(
|
|
1130
|
+
this.accumulatedArgs,
|
|
1131
|
+
segments,
|
|
1132
|
+
existingValue + arg.stringValue
|
|
1133
|
+
);
|
|
1134
|
+
delta += escaped;
|
|
1135
|
+
continue;
|
|
1136
|
+
}
|
|
1137
|
+
const resolved = resolvePartialArgValue(arg);
|
|
1138
|
+
if (resolved == null) continue;
|
|
1139
|
+
setNestedValue(this.accumulatedArgs, segments, resolved.value);
|
|
1140
|
+
delta += this.emitNavigationTo(segments, arg, resolved.json);
|
|
1141
|
+
}
|
|
1142
|
+
this.jsonText += delta;
|
|
1143
|
+
return {
|
|
1144
|
+
currentJSON: this.accumulatedArgs,
|
|
1145
|
+
textDelta: delta
|
|
1146
|
+
};
|
|
1147
|
+
}
|
|
1148
|
+
/**
|
|
1149
|
+
* Input: jsonText='{"brightness":50', accumulatedArgs={brightness:50}
|
|
1150
|
+
* Output: { finalJSON:'{"brightness":50}', closingDelta:'}' }
|
|
1151
|
+
*/
|
|
1152
|
+
finalize() {
|
|
1153
|
+
const finalArgs = JSON.stringify(this.accumulatedArgs);
|
|
1154
|
+
const closingDelta = finalArgs.slice(this.jsonText.length);
|
|
1155
|
+
return { finalJSON: finalArgs, closingDelta };
|
|
1156
|
+
}
|
|
1157
|
+
/**
|
|
1158
|
+
* Input: pathStack=[] (first call) or pathStack=[root,...] (subsequent calls)
|
|
1159
|
+
* Output: '{' (first call) or '' (subsequent calls)
|
|
1160
|
+
*/
|
|
1161
|
+
ensureRoot() {
|
|
1162
|
+
if (this.pathStack.length === 0) {
|
|
1163
|
+
this.pathStack.push({ segment: "", isArray: false, childCount: 0 });
|
|
1164
|
+
return "{";
|
|
1165
|
+
}
|
|
1166
|
+
return "";
|
|
1167
|
+
}
|
|
1168
|
+
/**
|
|
1169
|
+
* Emits the JSON text fragment needed to navigate from the current open
|
|
1170
|
+
* path to the new leaf at `targetSegments`, then writes the value.
|
|
1171
|
+
*
|
|
1172
|
+
* Input: targetSegments=["recipe","name"], arg={jsonPath:"$.recipe.name",stringValue:"Lasagna"}, valueJson='"Lasagna"'
|
|
1173
|
+
* Output: '{"recipe":{"name":"Lasagna"'
|
|
1174
|
+
*/
|
|
1175
|
+
emitNavigationTo(targetSegments, arg, valueJson) {
|
|
1176
|
+
let fragment = "";
|
|
1177
|
+
if (this.stringOpen) {
|
|
1178
|
+
fragment += '"';
|
|
1179
|
+
this.stringOpen = false;
|
|
1180
|
+
}
|
|
1181
|
+
fragment += this.ensureRoot();
|
|
1182
|
+
const targetContainerSegments = targetSegments.slice(0, -1);
|
|
1183
|
+
const leafSegment = targetSegments[targetSegments.length - 1];
|
|
1184
|
+
const commonDepth = this.findCommonStackDepth(targetContainerSegments);
|
|
1185
|
+
fragment += this.closeDownTo(commonDepth);
|
|
1186
|
+
fragment += this.openDownTo(targetContainerSegments, leafSegment);
|
|
1187
|
+
fragment += this.emitLeaf(leafSegment, arg, valueJson);
|
|
1188
|
+
return fragment;
|
|
1189
|
+
}
|
|
1190
|
+
/**
|
|
1191
|
+
* Returns the stack depth to preserve when navigating to a new target
|
|
1192
|
+
* container path. Always >= 1 (the root is never popped).
|
|
1193
|
+
*
|
|
1194
|
+
* Input: stack=[root,"recipe","ingredients",0], target=["recipe","ingredients",1]
|
|
1195
|
+
* Output: 3 (keep root+"recipe"+"ingredients")
|
|
1196
|
+
*/
|
|
1197
|
+
findCommonStackDepth(targetContainer) {
|
|
1198
|
+
const maxDepth = Math.min(
|
|
1199
|
+
this.pathStack.length - 1,
|
|
1200
|
+
targetContainer.length
|
|
1201
|
+
);
|
|
1202
|
+
let common = 0;
|
|
1203
|
+
for (let i = 0; i < maxDepth; i++) {
|
|
1204
|
+
if (this.pathStack[i + 1].segment === targetContainer[i]) {
|
|
1205
|
+
common++;
|
|
1206
|
+
} else {
|
|
1207
|
+
break;
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
return common + 1;
|
|
1211
|
+
}
|
|
1212
|
+
/**
|
|
1213
|
+
* Closes containers from the current stack depth back down to `targetDepth`.
|
|
1214
|
+
*
|
|
1215
|
+
* Input: this.pathStack=[root,"recipe","ingredients",0], targetDepth=3
|
|
1216
|
+
* Output: '}'
|
|
1217
|
+
*/
|
|
1218
|
+
closeDownTo(targetDepth) {
|
|
1219
|
+
let fragment = "";
|
|
1220
|
+
while (this.pathStack.length > targetDepth) {
|
|
1221
|
+
const entry = this.pathStack.pop();
|
|
1222
|
+
fragment += entry.isArray ? "]" : "}";
|
|
1223
|
+
}
|
|
1224
|
+
return fragment;
|
|
1225
|
+
}
|
|
1226
|
+
/**
|
|
1227
|
+
* Opens containers from the current stack depth down to the full target
|
|
1228
|
+
* container path, emitting opening `{`, `[`, keys, and commas as needed.
|
|
1229
|
+
* `leafSegment` is used to determine if the innermost container is an array.
|
|
1230
|
+
*
|
|
1231
|
+
* Input: this.pathStack=[root], targetContainer=["recipe","ingredients"], leafSegment=0
|
|
1232
|
+
* Output: '"recipe":{"ingredients":['
|
|
1233
|
+
*/
|
|
1234
|
+
openDownTo(targetContainer, leafSegment) {
|
|
1235
|
+
let fragment = "";
|
|
1236
|
+
const startIdx = this.pathStack.length - 1;
|
|
1237
|
+
for (let i = startIdx; i < targetContainer.length; i++) {
|
|
1238
|
+
const seg = targetContainer[i];
|
|
1239
|
+
const parentEntry = this.pathStack[this.pathStack.length - 1];
|
|
1240
|
+
if (parentEntry.childCount > 0) {
|
|
1241
|
+
fragment += ",";
|
|
1242
|
+
}
|
|
1243
|
+
parentEntry.childCount++;
|
|
1244
|
+
if (typeof seg === "string") {
|
|
1245
|
+
fragment += `${JSON.stringify(seg)}:`;
|
|
1246
|
+
}
|
|
1247
|
+
const childSeg = i + 1 < targetContainer.length ? targetContainer[i + 1] : leafSegment;
|
|
1248
|
+
const isArray = typeof childSeg === "number";
|
|
1249
|
+
fragment += isArray ? "[" : "{";
|
|
1250
|
+
this.pathStack.push({ segment: seg, isArray, childCount: 0 });
|
|
1251
|
+
}
|
|
1252
|
+
return fragment;
|
|
1253
|
+
}
|
|
1254
|
+
/**
|
|
1255
|
+
* Emits the comma, key, and value for a leaf entry in the current container.
|
|
1256
|
+
*
|
|
1257
|
+
* Input: leafSegment="name", arg={stringValue:"Lasagna"}, valueJson='"Lasagna"'
|
|
1258
|
+
* Output: '"name":"Lasagna"' (or ',"name":"Lasagna"' if container.childCount > 0)
|
|
1259
|
+
*/
|
|
1260
|
+
emitLeaf(leafSegment, arg, valueJson) {
|
|
1261
|
+
let fragment = "";
|
|
1262
|
+
const container = this.pathStack[this.pathStack.length - 1];
|
|
1263
|
+
if (container.childCount > 0) {
|
|
1264
|
+
fragment += ",";
|
|
1265
|
+
}
|
|
1266
|
+
container.childCount++;
|
|
1267
|
+
if (typeof leafSegment === "string") {
|
|
1268
|
+
fragment += `${JSON.stringify(leafSegment)}:`;
|
|
1269
|
+
}
|
|
1270
|
+
if (arg.stringValue != null && arg.willContinue) {
|
|
1271
|
+
fragment += valueJson.slice(0, -1);
|
|
1272
|
+
this.stringOpen = true;
|
|
1273
|
+
} else {
|
|
1274
|
+
fragment += valueJson;
|
|
1275
|
+
}
|
|
1276
|
+
return fragment;
|
|
1277
|
+
}
|
|
1278
|
+
};
|
|
1279
|
+
function parsePath(rawPath) {
|
|
1280
|
+
const segments = [];
|
|
1281
|
+
for (const part of rawPath.split(".")) {
|
|
1282
|
+
const bracketIdx = part.indexOf("[");
|
|
1283
|
+
if (bracketIdx === -1) {
|
|
1284
|
+
segments.push(part);
|
|
1285
|
+
} else {
|
|
1286
|
+
if (bracketIdx > 0) segments.push(part.slice(0, bracketIdx));
|
|
1287
|
+
for (const m of part.matchAll(/\[(\d+)\]/g)) {
|
|
1288
|
+
segments.push(parseInt(m[1], 10));
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
return segments;
|
|
1293
|
+
}
|
|
1294
|
+
function getNestedValue(obj, segments) {
|
|
1295
|
+
let current = obj;
|
|
1296
|
+
for (const seg of segments) {
|
|
1297
|
+
if (current == null || typeof current !== "object") return void 0;
|
|
1298
|
+
current = current[seg];
|
|
1299
|
+
}
|
|
1300
|
+
return current;
|
|
1301
|
+
}
|
|
1302
|
+
function setNestedValue(obj, segments, value) {
|
|
1303
|
+
let current = obj;
|
|
1304
|
+
for (let i = 0; i < segments.length - 1; i++) {
|
|
1305
|
+
const seg = segments[i];
|
|
1306
|
+
const nextSeg = segments[i + 1];
|
|
1307
|
+
if (current[seg] == null) {
|
|
1308
|
+
current[seg] = typeof nextSeg === "number" ? [] : {};
|
|
1309
|
+
}
|
|
1310
|
+
current = current[seg];
|
|
1311
|
+
}
|
|
1312
|
+
current[segments[segments.length - 1]] = value;
|
|
1313
|
+
}
|
|
1314
|
+
function resolvePartialArgValue(arg) {
|
|
1315
|
+
var _a, _b;
|
|
1316
|
+
const value = (_b = (_a = arg.stringValue) != null ? _a : arg.numberValue) != null ? _b : arg.boolValue;
|
|
1317
|
+
if (value != null) return { value, json: JSON.stringify(value) };
|
|
1318
|
+
if ("nullValue" in arg) return { value: null, json: "null" };
|
|
1319
|
+
return void 0;
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1088
1322
|
// src/map-google-generative-ai-finish-reason.ts
|
|
1089
1323
|
function mapGoogleGenerativeAIFinishReason({
|
|
1090
1324
|
finishReason,
|
|
@@ -1141,8 +1375,8 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1141
1375
|
tools,
|
|
1142
1376
|
toolChoice,
|
|
1143
1377
|
providerOptions
|
|
1144
|
-
}) {
|
|
1145
|
-
var _a;
|
|
1378
|
+
}, { isStreaming = false } = {}) {
|
|
1379
|
+
var _a, _b;
|
|
1146
1380
|
const warnings = [];
|
|
1147
1381
|
const providerOptionsName = this.config.provider.includes("vertex") ? "vertex" : "google";
|
|
1148
1382
|
let googleOptions = await parseProviderOptions2({
|
|
@@ -1157,14 +1391,21 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1157
1391
|
schema: googleLanguageModelOptions
|
|
1158
1392
|
});
|
|
1159
1393
|
}
|
|
1394
|
+
const isVertexProvider = this.config.provider.startsWith("google.vertex.");
|
|
1160
1395
|
if ((tools == null ? void 0 : tools.some(
|
|
1161
1396
|
(tool) => tool.type === "provider" && tool.id === "google.vertex_rag_store"
|
|
1162
|
-
)) && !
|
|
1397
|
+
)) && !isVertexProvider) {
|
|
1163
1398
|
warnings.push({
|
|
1164
1399
|
type: "other",
|
|
1165
1400
|
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}).`
|
|
1166
1401
|
});
|
|
1167
1402
|
}
|
|
1403
|
+
if ((googleOptions == null ? void 0 : googleOptions.streamFunctionCallArguments) && !isVertexProvider) {
|
|
1404
|
+
warnings.push({
|
|
1405
|
+
type: "other",
|
|
1406
|
+
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`
|
|
1407
|
+
});
|
|
1408
|
+
}
|
|
1168
1409
|
const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
|
|
1169
1410
|
const supportsFunctionResponseParts = this.modelId.startsWith("gemini-3");
|
|
1170
1411
|
const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
|
|
@@ -1184,6 +1425,19 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1184
1425
|
toolChoice,
|
|
1185
1426
|
modelId: this.modelId
|
|
1186
1427
|
});
|
|
1428
|
+
const streamFunctionCallArguments = isStreaming && isVertexProvider ? (_a = googleOptions == null ? void 0 : googleOptions.streamFunctionCallArguments) != null ? _a : false : void 0;
|
|
1429
|
+
const toolConfig = googleToolConfig || streamFunctionCallArguments || (googleOptions == null ? void 0 : googleOptions.retrievalConfig) ? {
|
|
1430
|
+
...googleToolConfig,
|
|
1431
|
+
...streamFunctionCallArguments && {
|
|
1432
|
+
functionCallingConfig: {
|
|
1433
|
+
...googleToolConfig == null ? void 0 : googleToolConfig.functionCallingConfig,
|
|
1434
|
+
streamFunctionCallArguments: true
|
|
1435
|
+
}
|
|
1436
|
+
},
|
|
1437
|
+
...(googleOptions == null ? void 0 : googleOptions.retrievalConfig) && {
|
|
1438
|
+
retrievalConfig: googleOptions.retrievalConfig
|
|
1439
|
+
}
|
|
1440
|
+
} : void 0;
|
|
1187
1441
|
return {
|
|
1188
1442
|
args: {
|
|
1189
1443
|
generationConfig: {
|
|
@@ -1201,7 +1455,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1201
1455
|
responseSchema: (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && // Google GenAI does not support all OpenAPI Schema features,
|
|
1202
1456
|
// so this is needed as an escape hatch:
|
|
1203
1457
|
// TODO convert into provider option
|
|
1204
|
-
((
|
|
1458
|
+
((_b = googleOptions == null ? void 0 : googleOptions.structuredOutputs) != null ? _b : true) ? convertJSONSchemaToOpenAPISchema(responseFormat.schema) : void 0,
|
|
1205
1459
|
...(googleOptions == null ? void 0 : googleOptions.audioTimestamp) && {
|
|
1206
1460
|
audioTimestamp: googleOptions.audioTimestamp
|
|
1207
1461
|
},
|
|
@@ -1219,10 +1473,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1219
1473
|
systemInstruction: isGemmaModel ? void 0 : systemInstruction,
|
|
1220
1474
|
safetySettings: googleOptions == null ? void 0 : googleOptions.safetySettings,
|
|
1221
1475
|
tools: googleTools2,
|
|
1222
|
-
toolConfig
|
|
1223
|
-
...googleToolConfig,
|
|
1224
|
-
retrievalConfig: googleOptions.retrievalConfig
|
|
1225
|
-
} : googleToolConfig,
|
|
1476
|
+
toolConfig,
|
|
1226
1477
|
cachedContent: googleOptions == null ? void 0 : googleOptions.cachedContent,
|
|
1227
1478
|
labels: googleOptions == null ? void 0 : googleOptions.labels,
|
|
1228
1479
|
serviceTier: googleOptions == null ? void 0 : googleOptions.serviceTier
|
|
@@ -1300,7 +1551,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1300
1551
|
providerMetadata: thoughtSignatureMetadata
|
|
1301
1552
|
});
|
|
1302
1553
|
}
|
|
1303
|
-
} else if ("functionCall" in part) {
|
|
1554
|
+
} else if ("functionCall" in part && part.functionCall.name != null && part.functionCall.args != null) {
|
|
1304
1555
|
content.push({
|
|
1305
1556
|
type: "tool-call",
|
|
1306
1557
|
toolCallId: this.config.generateId(),
|
|
@@ -1413,7 +1664,10 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1413
1664
|
};
|
|
1414
1665
|
}
|
|
1415
1666
|
async doStream(options) {
|
|
1416
|
-
const { args, warnings, providerOptionsName } = await this.getArgs(
|
|
1667
|
+
const { args, warnings, providerOptionsName } = await this.getArgs(
|
|
1668
|
+
options,
|
|
1669
|
+
{ isStreaming: true }
|
|
1670
|
+
);
|
|
1417
1671
|
const headers = combineHeaders2(
|
|
1418
1672
|
await resolve2(this.config.headers),
|
|
1419
1673
|
options.headers
|
|
@@ -1446,6 +1700,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1446
1700
|
const emittedSourceUrls = /* @__PURE__ */ new Set();
|
|
1447
1701
|
let lastCodeExecutionToolCallId;
|
|
1448
1702
|
let lastServerToolCallId;
|
|
1703
|
+
const activeStreamingToolCalls = [];
|
|
1449
1704
|
return {
|
|
1450
1705
|
stream: response.pipeThrough(
|
|
1451
1706
|
new TransformStream({
|
|
@@ -1453,7 +1708,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1453
1708
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1454
1709
|
},
|
|
1455
1710
|
transform(chunk, controller) {
|
|
1456
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
1711
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
1457
1712
|
if (options.includeRawChunks) {
|
|
1458
1713
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1459
1714
|
}
|
|
@@ -1646,36 +1901,110 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1646
1901
|
lastServerToolCallId = void 0;
|
|
1647
1902
|
}
|
|
1648
1903
|
}
|
|
1649
|
-
const
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1904
|
+
for (const part of parts) {
|
|
1905
|
+
if (!("functionCall" in part)) continue;
|
|
1906
|
+
const providerMeta = part.thoughtSignature ? {
|
|
1907
|
+
[providerOptionsName]: {
|
|
1908
|
+
thoughtSignature: part.thoughtSignature
|
|
1909
|
+
}
|
|
1910
|
+
} : void 0;
|
|
1911
|
+
const isStreamingChunk = part.functionCall.partialArgs != null || part.functionCall.name != null && part.functionCall.willContinue === true;
|
|
1912
|
+
const isTerminalChunk = part.functionCall.name == null && part.functionCall.args == null && part.functionCall.partialArgs == null && part.functionCall.willContinue == null;
|
|
1913
|
+
const isCompleteCall = part.functionCall.name != null && part.functionCall.args != null && part.functionCall.partialArgs == null;
|
|
1914
|
+
if (isStreamingChunk) {
|
|
1915
|
+
if (part.functionCall.name != null && part.functionCall.willContinue === true) {
|
|
1916
|
+
const toolCallId = generateId3();
|
|
1917
|
+
const accumulator = new GoogleJSONAccumulator();
|
|
1918
|
+
activeStreamingToolCalls.push({
|
|
1919
|
+
toolCallId,
|
|
1920
|
+
toolName: part.functionCall.name,
|
|
1921
|
+
accumulator,
|
|
1922
|
+
providerMetadata: providerMeta
|
|
1923
|
+
});
|
|
1924
|
+
controller.enqueue({
|
|
1925
|
+
type: "tool-input-start",
|
|
1926
|
+
id: toolCallId,
|
|
1927
|
+
toolName: part.functionCall.name,
|
|
1928
|
+
providerMetadata: providerMeta
|
|
1929
|
+
});
|
|
1930
|
+
if (part.functionCall.partialArgs != null) {
|
|
1931
|
+
const { textDelta } = accumulator.processPartialArgs(
|
|
1932
|
+
part.functionCall.partialArgs
|
|
1933
|
+
);
|
|
1934
|
+
if (textDelta.length > 0) {
|
|
1935
|
+
controller.enqueue({
|
|
1936
|
+
type: "tool-input-delta",
|
|
1937
|
+
id: toolCallId,
|
|
1938
|
+
delta: textDelta,
|
|
1939
|
+
providerMetadata: providerMeta
|
|
1940
|
+
});
|
|
1941
|
+
}
|
|
1942
|
+
}
|
|
1943
|
+
} else if (part.functionCall.partialArgs != null && activeStreamingToolCalls.length > 0) {
|
|
1944
|
+
const active = activeStreamingToolCalls[activeStreamingToolCalls.length - 1];
|
|
1945
|
+
const { textDelta } = active.accumulator.processPartialArgs(
|
|
1946
|
+
part.functionCall.partialArgs
|
|
1947
|
+
);
|
|
1948
|
+
if (textDelta.length > 0) {
|
|
1949
|
+
controller.enqueue({
|
|
1950
|
+
type: "tool-input-delta",
|
|
1951
|
+
id: active.toolCallId,
|
|
1952
|
+
delta: textDelta,
|
|
1953
|
+
providerMetadata: providerMeta
|
|
1954
|
+
});
|
|
1955
|
+
}
|
|
1956
|
+
}
|
|
1957
|
+
} else if (isTerminalChunk && activeStreamingToolCalls.length > 0) {
|
|
1958
|
+
const active = activeStreamingToolCalls.pop();
|
|
1959
|
+
const { finalJSON, closingDelta } = active.accumulator.finalize();
|
|
1960
|
+
if (closingDelta.length > 0) {
|
|
1961
|
+
controller.enqueue({
|
|
1962
|
+
type: "tool-input-delta",
|
|
1963
|
+
id: active.toolCallId,
|
|
1964
|
+
delta: closingDelta,
|
|
1965
|
+
providerMetadata: active.providerMetadata
|
|
1966
|
+
});
|
|
1967
|
+
}
|
|
1968
|
+
controller.enqueue({
|
|
1969
|
+
type: "tool-input-end",
|
|
1970
|
+
id: active.toolCallId,
|
|
1971
|
+
providerMetadata: active.providerMetadata
|
|
1972
|
+
});
|
|
1973
|
+
controller.enqueue({
|
|
1974
|
+
type: "tool-call",
|
|
1975
|
+
toolCallId: active.toolCallId,
|
|
1976
|
+
toolName: active.toolName,
|
|
1977
|
+
input: finalJSON,
|
|
1978
|
+
providerMetadata: active.providerMetadata
|
|
1979
|
+
});
|
|
1980
|
+
hasToolCalls = true;
|
|
1981
|
+
} else if (isCompleteCall) {
|
|
1982
|
+
const toolCallId = generateId3();
|
|
1983
|
+
const toolName = part.functionCall.name;
|
|
1984
|
+
const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((_i = part.functionCall.args) != null ? _i : {});
|
|
1656
1985
|
controller.enqueue({
|
|
1657
1986
|
type: "tool-input-start",
|
|
1658
|
-
id:
|
|
1659
|
-
toolName
|
|
1660
|
-
providerMetadata:
|
|
1987
|
+
id: toolCallId,
|
|
1988
|
+
toolName,
|
|
1989
|
+
providerMetadata: providerMeta
|
|
1661
1990
|
});
|
|
1662
1991
|
controller.enqueue({
|
|
1663
1992
|
type: "tool-input-delta",
|
|
1664
|
-
id:
|
|
1665
|
-
delta:
|
|
1666
|
-
providerMetadata:
|
|
1993
|
+
id: toolCallId,
|
|
1994
|
+
delta: args2,
|
|
1995
|
+
providerMetadata: providerMeta
|
|
1667
1996
|
});
|
|
1668
1997
|
controller.enqueue({
|
|
1669
1998
|
type: "tool-input-end",
|
|
1670
|
-
id:
|
|
1671
|
-
providerMetadata:
|
|
1999
|
+
id: toolCallId,
|
|
2000
|
+
providerMetadata: providerMeta
|
|
1672
2001
|
});
|
|
1673
2002
|
controller.enqueue({
|
|
1674
2003
|
type: "tool-call",
|
|
1675
|
-
toolCallId
|
|
1676
|
-
toolName
|
|
1677
|
-
input:
|
|
1678
|
-
providerMetadata:
|
|
2004
|
+
toolCallId,
|
|
2005
|
+
toolName,
|
|
2006
|
+
input: args2,
|
|
2007
|
+
providerMetadata: providerMeta
|
|
1679
2008
|
});
|
|
1680
2009
|
hasToolCalls = true;
|
|
1681
2010
|
}
|
|
@@ -1691,12 +2020,12 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1691
2020
|
};
|
|
1692
2021
|
providerMetadata = {
|
|
1693
2022
|
[providerOptionsName]: {
|
|
1694
|
-
promptFeedback: (
|
|
2023
|
+
promptFeedback: (_j = value.promptFeedback) != null ? _j : null,
|
|
1695
2024
|
groundingMetadata: lastGroundingMetadata,
|
|
1696
2025
|
urlContextMetadata: lastUrlContextMetadata,
|
|
1697
|
-
safetyRatings: (
|
|
2026
|
+
safetyRatings: (_k = candidate.safetyRatings) != null ? _k : null,
|
|
1698
2027
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
1699
|
-
finishMessage: (
|
|
2028
|
+
finishMessage: (_l = candidate.finishMessage) != null ? _l : null,
|
|
1700
2029
|
serviceTier
|
|
1701
2030
|
}
|
|
1702
2031
|
};
|
|
@@ -1729,26 +2058,6 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1729
2058
|
};
|
|
1730
2059
|
}
|
|
1731
2060
|
};
|
|
1732
|
-
function getToolCallsFromParts({
|
|
1733
|
-
parts,
|
|
1734
|
-
generateId: generateId3,
|
|
1735
|
-
providerOptionsName
|
|
1736
|
-
}) {
|
|
1737
|
-
const functionCallParts = parts == null ? void 0 : parts.filter(
|
|
1738
|
-
(part) => "functionCall" in part
|
|
1739
|
-
);
|
|
1740
|
-
return functionCallParts == null || functionCallParts.length === 0 ? void 0 : functionCallParts.map((part) => ({
|
|
1741
|
-
type: "tool-call",
|
|
1742
|
-
toolCallId: generateId3(),
|
|
1743
|
-
toolName: part.functionCall.name,
|
|
1744
|
-
args: JSON.stringify(part.functionCall.args),
|
|
1745
|
-
providerMetadata: part.thoughtSignature ? {
|
|
1746
|
-
[providerOptionsName]: {
|
|
1747
|
-
thoughtSignature: part.thoughtSignature
|
|
1748
|
-
}
|
|
1749
|
-
} : void 0
|
|
1750
|
-
}));
|
|
1751
|
-
}
|
|
1752
2061
|
function extractSources({
|
|
1753
2062
|
groundingMetadata,
|
|
1754
2063
|
generateId: generateId3
|
|
@@ -1892,14 +2201,24 @@ var getGroundingMetadataSchema = () => z5.object({
|
|
|
1892
2201
|
z5.object({})
|
|
1893
2202
|
]).nullish()
|
|
1894
2203
|
});
|
|
2204
|
+
var partialArgSchema = z5.object({
|
|
2205
|
+
jsonPath: z5.string(),
|
|
2206
|
+
stringValue: z5.string().nullish(),
|
|
2207
|
+
numberValue: z5.number().nullish(),
|
|
2208
|
+
boolValue: z5.boolean().nullish(),
|
|
2209
|
+
nullValue: z5.unknown().nullish(),
|
|
2210
|
+
willContinue: z5.boolean().nullish()
|
|
2211
|
+
});
|
|
1895
2212
|
var getContentSchema = () => z5.object({
|
|
1896
2213
|
parts: z5.array(
|
|
1897
2214
|
z5.union([
|
|
1898
2215
|
// note: order matters since text can be fully empty
|
|
1899
2216
|
z5.object({
|
|
1900
2217
|
functionCall: z5.object({
|
|
1901
|
-
name: z5.string(),
|
|
1902
|
-
args: z5.unknown()
|
|
2218
|
+
name: z5.string().nullish(),
|
|
2219
|
+
args: z5.unknown().nullish(),
|
|
2220
|
+
partialArgs: z5.array(partialArgSchema).nullish(),
|
|
2221
|
+
willContinue: z5.boolean().nullish()
|
|
1903
2222
|
}),
|
|
1904
2223
|
thoughtSignature: z5.string().nullish()
|
|
1905
2224
|
}),
|