@ai-sdk/google 4.0.0-beta.9 → 4.0.0-canary.51
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 +354 -4
- package/README.md +6 -4
- package/dist/index.d.ts +97 -54
- package/dist/index.js +1643 -575
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +62 -22
- package/dist/internal/index.js +1261 -449
- package/dist/internal/index.js.map +1 -1
- package/docs/{15-google-generative-ai.mdx → 15-google.mdx} +46 -40
- package/package.json +13 -14
- package/src/{convert-google-generative-ai-usage.ts → convert-google-usage.ts} +11 -4
- package/src/convert-json-schema-to-openapi-schema.ts +1 -1
- package/src/convert-to-google-messages.ts +585 -0
- package/src/{google-generative-ai-embedding-options.ts → google-embedding-model-options.ts} +2 -2
- package/src/{google-generative-ai-embedding-model.ts → google-embedding-model.ts} +28 -15
- package/src/google-error.ts +1 -1
- package/src/google-files.ts +225 -0
- package/src/google-image-model-options.ts +23 -0
- package/src/{google-generative-ai-image-model.ts → google-image-model.ts} +61 -49
- package/src/{google-generative-ai-image-settings.ts → google-image-settings.ts} +2 -2
- package/src/google-json-accumulator.ts +336 -0
- package/src/{google-generative-ai-options.ts → google-language-model-options.ts} +32 -5
- package/src/{google-generative-ai-language-model.ts → google-language-model.ts} +586 -191
- package/src/google-prepare-tools.ts +68 -8
- package/src/google-prompt.ts +82 -0
- package/src/google-provider.ts +56 -47
- package/src/google-video-model-options.ts +43 -0
- package/src/{google-generative-ai-video-model.ts → google-video-model.ts} +11 -50
- package/src/{google-generative-ai-video-settings.ts → google-video-settings.ts} +2 -1
- package/src/index.ts +28 -9
- package/src/internal/index.ts +2 -2
- package/src/{map-google-generative-ai-finish-reason.ts → map-google-finish-reason.ts} +2 -2
- package/src/tool/code-execution.ts +2 -2
- package/src/tool/enterprise-web-search.ts +9 -3
- package/src/tool/file-search.ts +5 -7
- package/src/tool/google-maps.ts +3 -2
- package/src/tool/google-search.ts +10 -11
- package/src/tool/url-context.ts +4 -2
- package/src/tool/vertex-rag-store.ts +9 -6
- package/dist/index.d.mts +0 -384
- package/dist/index.mjs +0 -2519
- package/dist/index.mjs.map +0 -1
- package/dist/internal/index.d.mts +0 -287
- package/dist/internal/index.mjs +0 -1708
- package/dist/internal/index.mjs.map +0 -1
- package/src/convert-to-google-generative-ai-messages.ts +0 -239
- package/src/google-generative-ai-prompt.ts +0 -47
package/dist/internal/index.js
CHANGED
|
@@ -1,38 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
// src/internal/index.ts
|
|
21
|
-
var internal_exports = {};
|
|
22
|
-
__export(internal_exports, {
|
|
23
|
-
GoogleGenerativeAILanguageModel: () => GoogleGenerativeAILanguageModel,
|
|
24
|
-
getGroundingMetadataSchema: () => getGroundingMetadataSchema,
|
|
25
|
-
getUrlContextMetadataSchema: () => getUrlContextMetadataSchema,
|
|
26
|
-
googleTools: () => googleTools
|
|
27
|
-
});
|
|
28
|
-
module.exports = __toCommonJS(internal_exports);
|
|
1
|
+
// src/google-language-model.ts
|
|
2
|
+
import {
|
|
3
|
+
combineHeaders,
|
|
4
|
+
createEventSourceResponseHandler,
|
|
5
|
+
createJsonResponseHandler,
|
|
6
|
+
generateId,
|
|
7
|
+
isCustomReasoning,
|
|
8
|
+
lazySchema as lazySchema3,
|
|
9
|
+
mapReasoningToProviderBudget,
|
|
10
|
+
mapReasoningToProviderEffort,
|
|
11
|
+
parseProviderOptions,
|
|
12
|
+
postJsonToApi,
|
|
13
|
+
resolve,
|
|
14
|
+
serializeModelOptions,
|
|
15
|
+
WORKFLOW_SERIALIZE,
|
|
16
|
+
WORKFLOW_DESERIALIZE,
|
|
17
|
+
zodSchema as zodSchema3
|
|
18
|
+
} from "@ai-sdk/provider-utils";
|
|
19
|
+
import { z as z3 } from "zod/v4";
|
|
29
20
|
|
|
30
|
-
// src/google-
|
|
31
|
-
|
|
32
|
-
var import_v43 = require("zod/v4");
|
|
33
|
-
|
|
34
|
-
// src/convert-google-generative-ai-usage.ts
|
|
35
|
-
function convertGoogleGenerativeAIUsage(usage) {
|
|
21
|
+
// src/convert-google-usage.ts
|
|
22
|
+
function convertGoogleUsage(usage) {
|
|
36
23
|
var _a, _b, _c, _d;
|
|
37
24
|
if (usage == null) {
|
|
38
25
|
return {
|
|
@@ -186,21 +173,151 @@ function isEmptyObjectSchema(jsonSchema) {
|
|
|
186
173
|
return jsonSchema != null && typeof jsonSchema === "object" && jsonSchema.type === "object" && (jsonSchema.properties == null || Object.keys(jsonSchema.properties).length === 0) && !jsonSchema.additionalProperties;
|
|
187
174
|
}
|
|
188
175
|
|
|
189
|
-
// src/convert-to-google-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
176
|
+
// src/convert-to-google-messages.ts
|
|
177
|
+
import {
|
|
178
|
+
UnsupportedFunctionalityError
|
|
179
|
+
} from "@ai-sdk/provider";
|
|
180
|
+
import {
|
|
181
|
+
convertToBase64,
|
|
182
|
+
getTopLevelMediaType,
|
|
183
|
+
isFullMediaType,
|
|
184
|
+
resolveFullMediaType,
|
|
185
|
+
resolveProviderReference
|
|
186
|
+
} from "@ai-sdk/provider-utils";
|
|
187
|
+
var dataUrlRegex = /^data:([^;,]+);base64,(.+)$/s;
|
|
188
|
+
function parseBase64DataUrl(value) {
|
|
189
|
+
const match = dataUrlRegex.exec(value);
|
|
190
|
+
if (match == null) {
|
|
191
|
+
return void 0;
|
|
192
|
+
}
|
|
193
|
+
return {
|
|
194
|
+
mediaType: match[1],
|
|
195
|
+
data: match[2]
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
function convertUrlToolResultPart(url) {
|
|
199
|
+
const parsedDataUrl = parseBase64DataUrl(url);
|
|
200
|
+
if (parsedDataUrl == null) {
|
|
201
|
+
return void 0;
|
|
202
|
+
}
|
|
203
|
+
return {
|
|
204
|
+
inlineData: {
|
|
205
|
+
mimeType: parsedDataUrl.mediaType,
|
|
206
|
+
data: parsedDataUrl.data
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
function appendToolResultParts(parts, toolName, outputValue) {
|
|
211
|
+
const functionResponseParts = [];
|
|
212
|
+
const responseTextParts = [];
|
|
213
|
+
for (const contentPart of outputValue) {
|
|
214
|
+
switch (contentPart.type) {
|
|
215
|
+
case "text": {
|
|
216
|
+
responseTextParts.push(contentPart.text);
|
|
217
|
+
break;
|
|
218
|
+
}
|
|
219
|
+
case "file": {
|
|
220
|
+
if (contentPart.data.type === "data") {
|
|
221
|
+
functionResponseParts.push({
|
|
222
|
+
inlineData: {
|
|
223
|
+
mimeType: resolveFullMediaType({ part: contentPart }),
|
|
224
|
+
data: convertToBase64(contentPart.data.data)
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
} else if (contentPart.data.type === "url") {
|
|
228
|
+
const functionResponsePart = convertUrlToolResultPart(
|
|
229
|
+
contentPart.data.url.toString()
|
|
230
|
+
);
|
|
231
|
+
if (functionResponsePart != null) {
|
|
232
|
+
functionResponseParts.push(functionResponsePart);
|
|
233
|
+
} else {
|
|
234
|
+
responseTextParts.push(JSON.stringify(contentPart));
|
|
235
|
+
}
|
|
236
|
+
} else {
|
|
237
|
+
responseTextParts.push(JSON.stringify(contentPart));
|
|
238
|
+
}
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
default: {
|
|
242
|
+
responseTextParts.push(JSON.stringify(contentPart));
|
|
243
|
+
break;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
parts.push({
|
|
248
|
+
functionResponse: {
|
|
249
|
+
name: toolName,
|
|
250
|
+
response: {
|
|
251
|
+
name: toolName,
|
|
252
|
+
content: responseTextParts.length > 0 ? responseTextParts.join("\n") : "Tool executed successfully."
|
|
253
|
+
},
|
|
254
|
+
...functionResponseParts.length > 0 ? { parts: functionResponseParts } : {}
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
function appendLegacyToolResultParts(parts, toolName, outputValue) {
|
|
259
|
+
for (const contentPart of outputValue) {
|
|
260
|
+
switch (contentPart.type) {
|
|
261
|
+
case "text":
|
|
262
|
+
parts.push({
|
|
263
|
+
functionResponse: {
|
|
264
|
+
name: toolName,
|
|
265
|
+
response: {
|
|
266
|
+
name: toolName,
|
|
267
|
+
content: contentPart.text
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
break;
|
|
272
|
+
case "file": {
|
|
273
|
+
if (contentPart.data.type === "data" && getTopLevelMediaType(contentPart.mediaType) === "image") {
|
|
274
|
+
parts.push(
|
|
275
|
+
{
|
|
276
|
+
inlineData: {
|
|
277
|
+
mimeType: resolveFullMediaType({ part: contentPart }),
|
|
278
|
+
data: convertToBase64(contentPart.data.data)
|
|
279
|
+
}
|
|
280
|
+
},
|
|
281
|
+
{
|
|
282
|
+
text: "Tool executed successfully and returned this image as a response"
|
|
283
|
+
}
|
|
284
|
+
);
|
|
285
|
+
} else {
|
|
286
|
+
parts.push({ text: JSON.stringify(contentPart) });
|
|
287
|
+
}
|
|
288
|
+
break;
|
|
289
|
+
}
|
|
290
|
+
default:
|
|
291
|
+
parts.push({ text: JSON.stringify(contentPart) });
|
|
292
|
+
break;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
function convertToGoogleMessages(prompt, options) {
|
|
297
|
+
var _a, _b, _c, _d;
|
|
194
298
|
const systemInstructionParts = [];
|
|
195
299
|
const contents = [];
|
|
196
300
|
let systemMessagesAllowed = true;
|
|
197
301
|
const isGemmaModel = (_a = options == null ? void 0 : options.isGemmaModel) != null ? _a : false;
|
|
198
|
-
const
|
|
302
|
+
const providerOptionsNames = (_b = options == null ? void 0 : options.providerOptionsNames) != null ? _b : ["google"];
|
|
303
|
+
const isVertexLike = !providerOptionsNames.includes("google");
|
|
304
|
+
const supportsFunctionResponseParts = (_c = options == null ? void 0 : options.supportsFunctionResponseParts) != null ? _c : true;
|
|
305
|
+
const readProviderOpts = (part) => {
|
|
306
|
+
var _a2, _b2, _c2, _d2, _e;
|
|
307
|
+
for (const name of providerOptionsNames) {
|
|
308
|
+
const v = (_a2 = part.providerOptions) == null ? void 0 : _a2[name];
|
|
309
|
+
if (v != null) return v;
|
|
310
|
+
}
|
|
311
|
+
if (isVertexLike) {
|
|
312
|
+
return (_b2 = part.providerOptions) == null ? void 0 : _b2.google;
|
|
313
|
+
}
|
|
314
|
+
return (_e = (_c2 = part.providerOptions) == null ? void 0 : _c2.googleVertex) != null ? _e : (_d2 = part.providerOptions) == null ? void 0 : _d2.vertex;
|
|
315
|
+
};
|
|
199
316
|
for (const { role, content } of prompt) {
|
|
200
317
|
switch (role) {
|
|
201
318
|
case "system": {
|
|
202
319
|
if (!systemMessagesAllowed) {
|
|
203
|
-
throw new
|
|
320
|
+
throw new UnsupportedFunctionalityError({
|
|
204
321
|
functionality: "system messages are only supported at the beginning of the conversation"
|
|
205
322
|
});
|
|
206
323
|
}
|
|
@@ -217,20 +334,54 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
217
334
|
break;
|
|
218
335
|
}
|
|
219
336
|
case "file": {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
337
|
+
switch (part.data.type) {
|
|
338
|
+
case "url": {
|
|
339
|
+
parts.push({
|
|
340
|
+
fileData: {
|
|
341
|
+
mimeType: resolveFullMediaType({ part }),
|
|
342
|
+
fileUri: part.data.url.toString()
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
break;
|
|
346
|
+
}
|
|
347
|
+
case "reference": {
|
|
348
|
+
if (isVertexLike) {
|
|
349
|
+
throw new UnsupportedFunctionalityError({
|
|
350
|
+
functionality: "file parts with provider references"
|
|
351
|
+
});
|
|
231
352
|
}
|
|
353
|
+
parts.push({
|
|
354
|
+
fileData: {
|
|
355
|
+
mimeType: resolveFullMediaType({ part }),
|
|
356
|
+
fileUri: resolveProviderReference({
|
|
357
|
+
reference: part.data.reference,
|
|
358
|
+
provider: "google"
|
|
359
|
+
})
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
break;
|
|
363
|
+
}
|
|
364
|
+
case "text": {
|
|
365
|
+
parts.push({
|
|
366
|
+
inlineData: {
|
|
367
|
+
mimeType: isFullMediaType(part.mediaType) ? part.mediaType : "text/plain",
|
|
368
|
+
data: convertToBase64(
|
|
369
|
+
new TextEncoder().encode(part.data.text)
|
|
370
|
+
)
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
break;
|
|
232
374
|
}
|
|
233
|
-
|
|
375
|
+
case "data": {
|
|
376
|
+
parts.push({
|
|
377
|
+
inlineData: {
|
|
378
|
+
mimeType: resolveFullMediaType({ part }),
|
|
379
|
+
data: convertToBase64(part.data.data)
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
break;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
234
385
|
break;
|
|
235
386
|
}
|
|
236
387
|
}
|
|
@@ -243,8 +394,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
243
394
|
contents.push({
|
|
244
395
|
role: "model",
|
|
245
396
|
parts: content.map((part) => {
|
|
246
|
-
|
|
247
|
-
const providerOpts = (_d = (_a2 = part.providerOptions) == null ? void 0 : _a2[providerOptionsName]) != null ? _d : providerOptionsName !== "google" ? (_b2 = part.providerOptions) == null ? void 0 : _b2.google : (_c2 = part.providerOptions) == null ? void 0 : _c2.vertex;
|
|
397
|
+
const providerOpts = readProviderOpts(part);
|
|
248
398
|
const thoughtSignature = (providerOpts == null ? void 0 : providerOpts.thoughtSignature) != null ? String(providerOpts.thoughtSignature) : void 0;
|
|
249
399
|
switch (part.type) {
|
|
250
400
|
case "text": {
|
|
@@ -260,22 +410,89 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
260
410
|
thoughtSignature
|
|
261
411
|
};
|
|
262
412
|
}
|
|
413
|
+
case "reasoning-file": {
|
|
414
|
+
switch (part.data.type) {
|
|
415
|
+
case "url": {
|
|
416
|
+
throw new UnsupportedFunctionalityError({
|
|
417
|
+
functionality: "File data URLs in assistant messages are not supported"
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
case "data": {
|
|
421
|
+
return {
|
|
422
|
+
inlineData: {
|
|
423
|
+
mimeType: part.mediaType,
|
|
424
|
+
data: convertToBase64(part.data.data)
|
|
425
|
+
},
|
|
426
|
+
thought: true,
|
|
427
|
+
thoughtSignature
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
break;
|
|
432
|
+
}
|
|
263
433
|
case "file": {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
434
|
+
switch (part.data.type) {
|
|
435
|
+
case "url": {
|
|
436
|
+
throw new UnsupportedFunctionalityError({
|
|
437
|
+
functionality: "File data URLs in assistant messages are not supported"
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
case "reference": {
|
|
441
|
+
if (isVertexLike) {
|
|
442
|
+
throw new UnsupportedFunctionalityError({
|
|
443
|
+
functionality: "file parts with provider references"
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
return {
|
|
447
|
+
fileData: {
|
|
448
|
+
mimeType: part.mediaType,
|
|
449
|
+
fileUri: resolveProviderReference({
|
|
450
|
+
reference: part.data.reference,
|
|
451
|
+
provider: "google"
|
|
452
|
+
})
|
|
453
|
+
},
|
|
454
|
+
...(providerOpts == null ? void 0 : providerOpts.thought) === true ? { thought: true } : {},
|
|
455
|
+
thoughtSignature
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
case "text": {
|
|
459
|
+
return {
|
|
460
|
+
inlineData: {
|
|
461
|
+
mimeType: isFullMediaType(part.mediaType) ? part.mediaType : "text/plain",
|
|
462
|
+
data: convertToBase64(
|
|
463
|
+
new TextEncoder().encode(part.data.text)
|
|
464
|
+
)
|
|
465
|
+
},
|
|
466
|
+
...(providerOpts == null ? void 0 : providerOpts.thought) === true ? { thought: true } : {},
|
|
467
|
+
thoughtSignature
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
case "data": {
|
|
471
|
+
return {
|
|
472
|
+
inlineData: {
|
|
473
|
+
mimeType: part.mediaType,
|
|
474
|
+
data: convertToBase64(part.data.data)
|
|
475
|
+
},
|
|
476
|
+
...(providerOpts == null ? void 0 : providerOpts.thought) === true ? { thought: true } : {},
|
|
477
|
+
thoughtSignature
|
|
478
|
+
};
|
|
479
|
+
}
|
|
268
480
|
}
|
|
269
|
-
|
|
270
|
-
inlineData: {
|
|
271
|
-
mimeType: part.mediaType,
|
|
272
|
-
data: (0, import_provider_utils.convertToBase64)(part.data)
|
|
273
|
-
},
|
|
274
|
-
...(providerOpts == null ? void 0 : providerOpts.thought) === true ? { thought: true } : {},
|
|
275
|
-
thoughtSignature
|
|
276
|
-
};
|
|
481
|
+
break;
|
|
277
482
|
}
|
|
278
483
|
case "tool-call": {
|
|
484
|
+
const serverToolCallId = (providerOpts == null ? void 0 : providerOpts.serverToolCallId) != null ? String(providerOpts.serverToolCallId) : void 0;
|
|
485
|
+
const serverToolType = (providerOpts == null ? void 0 : providerOpts.serverToolType) != null ? String(providerOpts.serverToolType) : void 0;
|
|
486
|
+
if (serverToolCallId && serverToolType) {
|
|
487
|
+
return {
|
|
488
|
+
toolCall: {
|
|
489
|
+
toolType: serverToolType,
|
|
490
|
+
args: typeof part.input === "string" ? JSON.parse(part.input) : part.input,
|
|
491
|
+
id: serverToolCallId
|
|
492
|
+
},
|
|
493
|
+
thoughtSignature
|
|
494
|
+
};
|
|
495
|
+
}
|
|
279
496
|
return {
|
|
280
497
|
functionCall: {
|
|
281
498
|
name: part.toolName,
|
|
@@ -284,6 +501,21 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
284
501
|
thoughtSignature
|
|
285
502
|
};
|
|
286
503
|
}
|
|
504
|
+
case "tool-result": {
|
|
505
|
+
const serverToolCallId = (providerOpts == null ? void 0 : providerOpts.serverToolCallId) != null ? String(providerOpts.serverToolCallId) : void 0;
|
|
506
|
+
const serverToolType = (providerOpts == null ? void 0 : providerOpts.serverToolType) != null ? String(providerOpts.serverToolType) : void 0;
|
|
507
|
+
if (serverToolCallId && serverToolType) {
|
|
508
|
+
return {
|
|
509
|
+
toolResponse: {
|
|
510
|
+
toolType: serverToolType,
|
|
511
|
+
response: part.output.type === "json" ? part.output.value : {},
|
|
512
|
+
id: serverToolCallId
|
|
513
|
+
},
|
|
514
|
+
thoughtSignature
|
|
515
|
+
};
|
|
516
|
+
}
|
|
517
|
+
return void 0;
|
|
518
|
+
}
|
|
287
519
|
}
|
|
288
520
|
}).filter((part) => part !== void 0)
|
|
289
521
|
});
|
|
@@ -296,38 +528,32 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
296
528
|
if (part.type === "tool-approval-response") {
|
|
297
529
|
continue;
|
|
298
530
|
}
|
|
531
|
+
const partProviderOpts = readProviderOpts(part);
|
|
532
|
+
const serverToolCallId = (partProviderOpts == null ? void 0 : partProviderOpts.serverToolCallId) != null ? String(partProviderOpts.serverToolCallId) : void 0;
|
|
533
|
+
const serverToolType = (partProviderOpts == null ? void 0 : partProviderOpts.serverToolType) != null ? String(partProviderOpts.serverToolType) : void 0;
|
|
534
|
+
if (serverToolCallId && serverToolType) {
|
|
535
|
+
const serverThoughtSignature = (partProviderOpts == null ? void 0 : partProviderOpts.thoughtSignature) != null ? String(partProviderOpts.thoughtSignature) : void 0;
|
|
536
|
+
if (contents.length > 0) {
|
|
537
|
+
const lastContent = contents[contents.length - 1];
|
|
538
|
+
if (lastContent.role === "model") {
|
|
539
|
+
lastContent.parts.push({
|
|
540
|
+
toolResponse: {
|
|
541
|
+
toolType: serverToolType,
|
|
542
|
+
response: part.output.type === "json" ? part.output.value : {},
|
|
543
|
+
id: serverToolCallId
|
|
544
|
+
},
|
|
545
|
+
thoughtSignature: serverThoughtSignature
|
|
546
|
+
});
|
|
547
|
+
continue;
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
}
|
|
299
551
|
const output = part.output;
|
|
300
552
|
if (output.type === "content") {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
functionResponse: {
|
|
306
|
-
name: part.toolName,
|
|
307
|
-
response: {
|
|
308
|
-
name: part.toolName,
|
|
309
|
-
content: contentPart.text
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
});
|
|
313
|
-
break;
|
|
314
|
-
case "image-data":
|
|
315
|
-
parts.push(
|
|
316
|
-
{
|
|
317
|
-
inlineData: {
|
|
318
|
-
mimeType: contentPart.mediaType,
|
|
319
|
-
data: contentPart.data
|
|
320
|
-
}
|
|
321
|
-
},
|
|
322
|
-
{
|
|
323
|
-
text: "Tool executed successfully and returned this image as a response"
|
|
324
|
-
}
|
|
325
|
-
);
|
|
326
|
-
break;
|
|
327
|
-
default:
|
|
328
|
-
parts.push({ text: JSON.stringify(contentPart) });
|
|
329
|
-
break;
|
|
330
|
-
}
|
|
553
|
+
if (supportsFunctionResponseParts) {
|
|
554
|
+
appendToolResultParts(parts, part.toolName, output.value);
|
|
555
|
+
} else {
|
|
556
|
+
appendLegacyToolResultParts(parts, part.toolName, output.value);
|
|
331
557
|
}
|
|
332
558
|
} else {
|
|
333
559
|
parts.push({
|
|
@@ -335,7 +561,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
335
561
|
name: part.toolName,
|
|
336
562
|
response: {
|
|
337
563
|
name: part.toolName,
|
|
338
|
-
content: output.type === "execution-denied" ? (
|
|
564
|
+
content: output.type === "execution-denied" ? (_d = output.reason) != null ? _d : "Tool call execution denied." : output.value
|
|
339
565
|
}
|
|
340
566
|
}
|
|
341
567
|
});
|
|
@@ -365,58 +591,65 @@ function getModelPath(modelId) {
|
|
|
365
591
|
}
|
|
366
592
|
|
|
367
593
|
// src/google-error.ts
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
594
|
+
import {
|
|
595
|
+
createJsonErrorResponseHandler,
|
|
596
|
+
lazySchema,
|
|
597
|
+
zodSchema
|
|
598
|
+
} from "@ai-sdk/provider-utils";
|
|
599
|
+
import { z } from "zod/v4";
|
|
600
|
+
var googleErrorDataSchema = lazySchema(
|
|
601
|
+
() => zodSchema(
|
|
602
|
+
z.object({
|
|
603
|
+
error: z.object({
|
|
604
|
+
code: z.number().nullable(),
|
|
605
|
+
message: z.string(),
|
|
606
|
+
status: z.string()
|
|
377
607
|
})
|
|
378
608
|
})
|
|
379
609
|
)
|
|
380
610
|
);
|
|
381
|
-
var googleFailedResponseHandler =
|
|
611
|
+
var googleFailedResponseHandler = createJsonErrorResponseHandler({
|
|
382
612
|
errorSchema: googleErrorDataSchema,
|
|
383
613
|
errorToMessage: (data) => data.error.message
|
|
384
614
|
});
|
|
385
615
|
|
|
386
|
-
// src/google-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
616
|
+
// src/google-language-model-options.ts
|
|
617
|
+
import {
|
|
618
|
+
lazySchema as lazySchema2,
|
|
619
|
+
zodSchema as zodSchema2
|
|
620
|
+
} from "@ai-sdk/provider-utils";
|
|
621
|
+
import { z as z2 } from "zod/v4";
|
|
622
|
+
var googleLanguageModelOptions = lazySchema2(
|
|
623
|
+
() => zodSchema2(
|
|
624
|
+
z2.object({
|
|
625
|
+
responseModalities: z2.array(z2.enum(["TEXT", "IMAGE"])).optional(),
|
|
626
|
+
thinkingConfig: z2.object({
|
|
627
|
+
thinkingBudget: z2.number().optional(),
|
|
628
|
+
includeThoughts: z2.boolean().optional(),
|
|
396
629
|
// https://ai.google.dev/gemini-api/docs/gemini-3?thinking=high#thinking_level
|
|
397
|
-
thinkingLevel:
|
|
630
|
+
thinkingLevel: z2.enum(["minimal", "low", "medium", "high"]).optional()
|
|
398
631
|
}).optional(),
|
|
399
632
|
/**
|
|
400
633
|
* Optional.
|
|
401
634
|
* The name of the cached content used as context to serve the prediction.
|
|
402
635
|
* Format: cachedContents/{cachedContent}
|
|
403
636
|
*/
|
|
404
|
-
cachedContent:
|
|
637
|
+
cachedContent: z2.string().optional(),
|
|
405
638
|
/**
|
|
406
639
|
* Optional. Enable structured output. Default is true.
|
|
407
640
|
*
|
|
408
641
|
* This is useful when the JSON Schema contains elements that are
|
|
409
642
|
* not supported by the OpenAPI schema version that
|
|
410
|
-
* Google
|
|
643
|
+
* Google uses. You can use this to disable
|
|
411
644
|
* structured outputs if you need to.
|
|
412
645
|
*/
|
|
413
|
-
structuredOutputs:
|
|
646
|
+
structuredOutputs: z2.boolean().optional(),
|
|
414
647
|
/**
|
|
415
648
|
* Optional. A list of unique safety settings for blocking unsafe content.
|
|
416
649
|
*/
|
|
417
|
-
safetySettings:
|
|
418
|
-
|
|
419
|
-
category:
|
|
650
|
+
safetySettings: z2.array(
|
|
651
|
+
z2.object({
|
|
652
|
+
category: z2.enum([
|
|
420
653
|
"HARM_CATEGORY_UNSPECIFIED",
|
|
421
654
|
"HARM_CATEGORY_HATE_SPEECH",
|
|
422
655
|
"HARM_CATEGORY_DANGEROUS_CONTENT",
|
|
@@ -424,7 +657,7 @@ var googleLanguageModelOptions = (0, import_provider_utils3.lazySchema)(
|
|
|
424
657
|
"HARM_CATEGORY_SEXUALLY_EXPLICIT",
|
|
425
658
|
"HARM_CATEGORY_CIVIC_INTEGRITY"
|
|
426
659
|
]),
|
|
427
|
-
threshold:
|
|
660
|
+
threshold: z2.enum([
|
|
428
661
|
"HARM_BLOCK_THRESHOLD_UNSPECIFIED",
|
|
429
662
|
"BLOCK_LOW_AND_ABOVE",
|
|
430
663
|
"BLOCK_MEDIUM_AND_ABOVE",
|
|
@@ -434,7 +667,7 @@ var googleLanguageModelOptions = (0, import_provider_utils3.lazySchema)(
|
|
|
434
667
|
])
|
|
435
668
|
})
|
|
436
669
|
).optional(),
|
|
437
|
-
threshold:
|
|
670
|
+
threshold: z2.enum([
|
|
438
671
|
"HARM_BLOCK_THRESHOLD_UNSPECIFIED",
|
|
439
672
|
"BLOCK_LOW_AND_ABOVE",
|
|
440
673
|
"BLOCK_MEDIUM_AND_ABOVE",
|
|
@@ -447,19 +680,19 @@ var googleLanguageModelOptions = (0, import_provider_utils3.lazySchema)(
|
|
|
447
680
|
*
|
|
448
681
|
* https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/audio-understanding
|
|
449
682
|
*/
|
|
450
|
-
audioTimestamp:
|
|
683
|
+
audioTimestamp: z2.boolean().optional(),
|
|
451
684
|
/**
|
|
452
685
|
* Optional. Defines labels used in billing reports. Available on Vertex AI only.
|
|
453
686
|
*
|
|
454
687
|
* https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/add-labels-to-api-calls
|
|
455
688
|
*/
|
|
456
|
-
labels:
|
|
689
|
+
labels: z2.record(z2.string(), z2.string()).optional(),
|
|
457
690
|
/**
|
|
458
691
|
* Optional. If specified, the media resolution specified will be used.
|
|
459
692
|
*
|
|
460
693
|
* https://ai.google.dev/api/generate-content#MediaResolution
|
|
461
694
|
*/
|
|
462
|
-
mediaResolution:
|
|
695
|
+
mediaResolution: z2.enum([
|
|
463
696
|
"MEDIA_RESOLUTION_UNSPECIFIED",
|
|
464
697
|
"MEDIA_RESOLUTION_LOW",
|
|
465
698
|
"MEDIA_RESOLUTION_MEDIUM",
|
|
@@ -470,8 +703,8 @@ var googleLanguageModelOptions = (0, import_provider_utils3.lazySchema)(
|
|
|
470
703
|
*
|
|
471
704
|
* https://ai.google.dev/gemini-api/docs/image-generation#aspect_ratios
|
|
472
705
|
*/
|
|
473
|
-
imageConfig:
|
|
474
|
-
aspectRatio:
|
|
706
|
+
imageConfig: z2.object({
|
|
707
|
+
aspectRatio: z2.enum([
|
|
475
708
|
"1:1",
|
|
476
709
|
"2:3",
|
|
477
710
|
"3:2",
|
|
@@ -487,7 +720,7 @@ var googleLanguageModelOptions = (0, import_provider_utils3.lazySchema)(
|
|
|
487
720
|
"1:4",
|
|
488
721
|
"4:1"
|
|
489
722
|
]).optional(),
|
|
490
|
-
imageSize:
|
|
723
|
+
imageSize: z2.enum(["1K", "2K", "4K", "512"]).optional()
|
|
491
724
|
}).optional(),
|
|
492
725
|
/**
|
|
493
726
|
* Optional. Configuration for grounding retrieval.
|
|
@@ -495,24 +728,47 @@ var googleLanguageModelOptions = (0, import_provider_utils3.lazySchema)(
|
|
|
495
728
|
*
|
|
496
729
|
* https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/grounding-with-google-maps
|
|
497
730
|
*/
|
|
498
|
-
retrievalConfig:
|
|
499
|
-
latLng:
|
|
500
|
-
latitude:
|
|
501
|
-
longitude:
|
|
731
|
+
retrievalConfig: z2.object({
|
|
732
|
+
latLng: z2.object({
|
|
733
|
+
latitude: z2.number(),
|
|
734
|
+
longitude: z2.number()
|
|
502
735
|
}).optional()
|
|
503
|
-
}).optional()
|
|
736
|
+
}).optional(),
|
|
737
|
+
/**
|
|
738
|
+
* Optional. When set to true, function call arguments will be streamed
|
|
739
|
+
* incrementally via partialArgs in streaming responses. Only supported
|
|
740
|
+
* on the Vertex AI API (not the Gemini API) and only for Gemini 3+
|
|
741
|
+
* models.
|
|
742
|
+
*
|
|
743
|
+
* @default false
|
|
744
|
+
*
|
|
745
|
+
* https://docs.cloud.google.com/vertex-ai/generative-ai/docs/multimodal/function-calling#streaming-fc
|
|
746
|
+
*/
|
|
747
|
+
streamFunctionCallArguments: z2.boolean().optional(),
|
|
748
|
+
/**
|
|
749
|
+
* Optional. The service tier to use for the request.
|
|
750
|
+
*/
|
|
751
|
+
serviceTier: z2.enum(["standard", "flex", "priority"]).optional()
|
|
504
752
|
})
|
|
505
753
|
)
|
|
506
754
|
);
|
|
755
|
+
var VertexServiceTierMap = {
|
|
756
|
+
standard: "SERVICE_TIER_STANDARD",
|
|
757
|
+
flex: "SERVICE_TIER_FLEX",
|
|
758
|
+
priority: "SERVICE_TIER_PRIORITY"
|
|
759
|
+
};
|
|
507
760
|
|
|
508
761
|
// src/google-prepare-tools.ts
|
|
509
|
-
|
|
762
|
+
import {
|
|
763
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
764
|
+
} from "@ai-sdk/provider";
|
|
510
765
|
function prepareTools({
|
|
511
766
|
tools,
|
|
512
767
|
toolChoice,
|
|
513
|
-
modelId
|
|
768
|
+
modelId,
|
|
769
|
+
isVertexProvider = false
|
|
514
770
|
}) {
|
|
515
|
-
var _a;
|
|
771
|
+
var _a, _b;
|
|
516
772
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
517
773
|
const toolWarnings = [];
|
|
518
774
|
const isLatest = [
|
|
@@ -521,13 +777,14 @@ function prepareTools({
|
|
|
521
777
|
"gemini-pro-latest"
|
|
522
778
|
].some((id) => id === modelId);
|
|
523
779
|
const isGemini2orNewer = modelId.includes("gemini-2") || modelId.includes("gemini-3") || modelId.includes("nano-banana") || isLatest;
|
|
780
|
+
const isGemini3orNewer = modelId.includes("gemini-3");
|
|
524
781
|
const supportsFileSearch = modelId.includes("gemini-2.5") || modelId.includes("gemini-3");
|
|
525
782
|
if (tools == null) {
|
|
526
783
|
return { tools: void 0, toolConfig: void 0, toolWarnings };
|
|
527
784
|
}
|
|
528
785
|
const hasFunctionTools = tools.some((tool) => tool.type === "function");
|
|
529
786
|
const hasProviderTools = tools.some((tool) => tool.type === "provider");
|
|
530
|
-
if (hasFunctionTools && hasProviderTools) {
|
|
787
|
+
if (hasFunctionTools && hasProviderTools && !isGemini3orNewer) {
|
|
531
788
|
toolWarnings.push({
|
|
532
789
|
type: "unsupported",
|
|
533
790
|
feature: `combination of function and provider-defined tools`
|
|
@@ -578,7 +835,7 @@ function prepareTools({
|
|
|
578
835
|
toolWarnings.push({
|
|
579
836
|
type: "unsupported",
|
|
580
837
|
feature: `provider-defined tool ${tool.id}`,
|
|
581
|
-
details: "The code execution
|
|
838
|
+
details: "The code execution tool is not supported with other Gemini models than Gemini 2."
|
|
582
839
|
});
|
|
583
840
|
}
|
|
584
841
|
break;
|
|
@@ -632,6 +889,47 @@ function prepareTools({
|
|
|
632
889
|
break;
|
|
633
890
|
}
|
|
634
891
|
});
|
|
892
|
+
if (hasFunctionTools && isGemini3orNewer && googleTools2.length > 0) {
|
|
893
|
+
const functionDeclarations2 = [];
|
|
894
|
+
for (const tool of tools) {
|
|
895
|
+
if (tool.type === "function") {
|
|
896
|
+
functionDeclarations2.push({
|
|
897
|
+
name: tool.name,
|
|
898
|
+
description: (_a = tool.description) != null ? _a : "",
|
|
899
|
+
parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
|
|
900
|
+
});
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
const combinedToolConfig = {
|
|
904
|
+
functionCallingConfig: { mode: "VALIDATED" },
|
|
905
|
+
...!isVertexProvider && {
|
|
906
|
+
includeServerSideToolInvocations: true
|
|
907
|
+
}
|
|
908
|
+
};
|
|
909
|
+
if (toolChoice != null) {
|
|
910
|
+
switch (toolChoice.type) {
|
|
911
|
+
case "auto":
|
|
912
|
+
break;
|
|
913
|
+
case "none":
|
|
914
|
+
combinedToolConfig.functionCallingConfig = { mode: "NONE" };
|
|
915
|
+
break;
|
|
916
|
+
case "required":
|
|
917
|
+
combinedToolConfig.functionCallingConfig = { mode: "ANY" };
|
|
918
|
+
break;
|
|
919
|
+
case "tool":
|
|
920
|
+
combinedToolConfig.functionCallingConfig = {
|
|
921
|
+
mode: "ANY",
|
|
922
|
+
allowedFunctionNames: [toolChoice.toolName]
|
|
923
|
+
};
|
|
924
|
+
break;
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
return {
|
|
928
|
+
tools: [...googleTools2, { functionDeclarations: functionDeclarations2 }],
|
|
929
|
+
toolConfig: combinedToolConfig,
|
|
930
|
+
toolWarnings
|
|
931
|
+
};
|
|
932
|
+
}
|
|
635
933
|
return {
|
|
636
934
|
tools: googleTools2.length > 0 ? googleTools2 : void 0,
|
|
637
935
|
toolConfig: void 0,
|
|
@@ -645,7 +943,7 @@ function prepareTools({
|
|
|
645
943
|
case "function":
|
|
646
944
|
functionDeclarations.push({
|
|
647
945
|
name: tool.name,
|
|
648
|
-
description: (
|
|
946
|
+
description: (_b = tool.description) != null ? _b : "",
|
|
649
947
|
parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
|
|
650
948
|
});
|
|
651
949
|
if (tool.strict === true) {
|
|
@@ -708,15 +1006,238 @@ function prepareTools({
|
|
|
708
1006
|
};
|
|
709
1007
|
default: {
|
|
710
1008
|
const _exhaustiveCheck = type;
|
|
711
|
-
throw new
|
|
1009
|
+
throw new UnsupportedFunctionalityError2({
|
|
712
1010
|
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
713
1011
|
});
|
|
714
1012
|
}
|
|
715
1013
|
}
|
|
716
1014
|
}
|
|
717
1015
|
|
|
718
|
-
// src/
|
|
719
|
-
|
|
1016
|
+
// src/google-json-accumulator.ts
|
|
1017
|
+
var GoogleJSONAccumulator = class {
|
|
1018
|
+
constructor() {
|
|
1019
|
+
this.accumulatedArgs = {};
|
|
1020
|
+
this.jsonText = "";
|
|
1021
|
+
/**
|
|
1022
|
+
* Stack representing the currently "open" containers in the JSON output.
|
|
1023
|
+
* Entry 0 is always the root `{` object once the first value is written.
|
|
1024
|
+
*/
|
|
1025
|
+
this.pathStack = [];
|
|
1026
|
+
/**
|
|
1027
|
+
* Whether a string value is currently "open" (willContinue was true),
|
|
1028
|
+
* meaning the closing quote has not yet been emitted.
|
|
1029
|
+
*/
|
|
1030
|
+
this.stringOpen = false;
|
|
1031
|
+
}
|
|
1032
|
+
/**
|
|
1033
|
+
* Input: [{jsonPath:"$.brightness",numberValue:50}]
|
|
1034
|
+
* Output: { currentJSON:{brightness:50}, textDelta:'{"brightness":50' }
|
|
1035
|
+
*/
|
|
1036
|
+
processPartialArgs(partialArgs) {
|
|
1037
|
+
let delta = "";
|
|
1038
|
+
for (const arg of partialArgs) {
|
|
1039
|
+
const rawPath = arg.jsonPath.replace(/^\$\./, "");
|
|
1040
|
+
if (!rawPath) continue;
|
|
1041
|
+
const segments = parsePath(rawPath);
|
|
1042
|
+
const existingValue = getNestedValue(this.accumulatedArgs, segments);
|
|
1043
|
+
const isStringContinuation = arg.stringValue != null && existingValue !== void 0;
|
|
1044
|
+
if (isStringContinuation) {
|
|
1045
|
+
const escaped = JSON.stringify(arg.stringValue).slice(1, -1);
|
|
1046
|
+
setNestedValue(
|
|
1047
|
+
this.accumulatedArgs,
|
|
1048
|
+
segments,
|
|
1049
|
+
existingValue + arg.stringValue
|
|
1050
|
+
);
|
|
1051
|
+
delta += escaped;
|
|
1052
|
+
continue;
|
|
1053
|
+
}
|
|
1054
|
+
const resolved = resolvePartialArgValue(arg);
|
|
1055
|
+
if (resolved == null) continue;
|
|
1056
|
+
setNestedValue(this.accumulatedArgs, segments, resolved.value);
|
|
1057
|
+
delta += this.emitNavigationTo(segments, arg, resolved.json);
|
|
1058
|
+
}
|
|
1059
|
+
this.jsonText += delta;
|
|
1060
|
+
return {
|
|
1061
|
+
currentJSON: this.accumulatedArgs,
|
|
1062
|
+
textDelta: delta
|
|
1063
|
+
};
|
|
1064
|
+
}
|
|
1065
|
+
/**
|
|
1066
|
+
* Input: jsonText='{"brightness":50', accumulatedArgs={brightness:50}
|
|
1067
|
+
* Output: { finalJSON:'{"brightness":50}', closingDelta:'}' }
|
|
1068
|
+
*/
|
|
1069
|
+
finalize() {
|
|
1070
|
+
const finalArgs = JSON.stringify(this.accumulatedArgs);
|
|
1071
|
+
const closingDelta = finalArgs.slice(this.jsonText.length);
|
|
1072
|
+
return { finalJSON: finalArgs, closingDelta };
|
|
1073
|
+
}
|
|
1074
|
+
/**
|
|
1075
|
+
* Input: pathStack=[] (first call) or pathStack=[root,...] (subsequent calls)
|
|
1076
|
+
* Output: '{' (first call) or '' (subsequent calls)
|
|
1077
|
+
*/
|
|
1078
|
+
ensureRoot() {
|
|
1079
|
+
if (this.pathStack.length === 0) {
|
|
1080
|
+
this.pathStack.push({ segment: "", isArray: false, childCount: 0 });
|
|
1081
|
+
return "{";
|
|
1082
|
+
}
|
|
1083
|
+
return "";
|
|
1084
|
+
}
|
|
1085
|
+
/**
|
|
1086
|
+
* Emits the JSON text fragment needed to navigate from the current open
|
|
1087
|
+
* path to the new leaf at `targetSegments`, then writes the value.
|
|
1088
|
+
*
|
|
1089
|
+
* Input: targetSegments=["recipe","name"], arg={jsonPath:"$.recipe.name",stringValue:"Lasagna"}, valueJson='"Lasagna"'
|
|
1090
|
+
* Output: '{"recipe":{"name":"Lasagna"'
|
|
1091
|
+
*/
|
|
1092
|
+
emitNavigationTo(targetSegments, arg, valueJson) {
|
|
1093
|
+
let fragment = "";
|
|
1094
|
+
if (this.stringOpen) {
|
|
1095
|
+
fragment += '"';
|
|
1096
|
+
this.stringOpen = false;
|
|
1097
|
+
}
|
|
1098
|
+
fragment += this.ensureRoot();
|
|
1099
|
+
const targetContainerSegments = targetSegments.slice(0, -1);
|
|
1100
|
+
const leafSegment = targetSegments[targetSegments.length - 1];
|
|
1101
|
+
const commonDepth = this.findCommonStackDepth(targetContainerSegments);
|
|
1102
|
+
fragment += this.closeDownTo(commonDepth);
|
|
1103
|
+
fragment += this.openDownTo(targetContainerSegments, leafSegment);
|
|
1104
|
+
fragment += this.emitLeaf(leafSegment, arg, valueJson);
|
|
1105
|
+
return fragment;
|
|
1106
|
+
}
|
|
1107
|
+
/**
|
|
1108
|
+
* Returns the stack depth to preserve when navigating to a new target
|
|
1109
|
+
* container path. Always >= 1 (the root is never popped).
|
|
1110
|
+
*
|
|
1111
|
+
* Input: stack=[root,"recipe","ingredients",0], target=["recipe","ingredients",1]
|
|
1112
|
+
* Output: 3 (keep root+"recipe"+"ingredients")
|
|
1113
|
+
*/
|
|
1114
|
+
findCommonStackDepth(targetContainer) {
|
|
1115
|
+
const maxDepth = Math.min(
|
|
1116
|
+
this.pathStack.length - 1,
|
|
1117
|
+
targetContainer.length
|
|
1118
|
+
);
|
|
1119
|
+
let common = 0;
|
|
1120
|
+
for (let i = 0; i < maxDepth; i++) {
|
|
1121
|
+
if (this.pathStack[i + 1].segment === targetContainer[i]) {
|
|
1122
|
+
common++;
|
|
1123
|
+
} else {
|
|
1124
|
+
break;
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
return common + 1;
|
|
1128
|
+
}
|
|
1129
|
+
/**
|
|
1130
|
+
* Closes containers from the current stack depth back down to `targetDepth`.
|
|
1131
|
+
*
|
|
1132
|
+
* Input: this.pathStack=[root,"recipe","ingredients",0], targetDepth=3
|
|
1133
|
+
* Output: '}'
|
|
1134
|
+
*/
|
|
1135
|
+
closeDownTo(targetDepth) {
|
|
1136
|
+
let fragment = "";
|
|
1137
|
+
while (this.pathStack.length > targetDepth) {
|
|
1138
|
+
const entry = this.pathStack.pop();
|
|
1139
|
+
fragment += entry.isArray ? "]" : "}";
|
|
1140
|
+
}
|
|
1141
|
+
return fragment;
|
|
1142
|
+
}
|
|
1143
|
+
/**
|
|
1144
|
+
* Opens containers from the current stack depth down to the full target
|
|
1145
|
+
* container path, emitting opening `{`, `[`, keys, and commas as needed.
|
|
1146
|
+
* `leafSegment` is used to determine if the innermost container is an array.
|
|
1147
|
+
*
|
|
1148
|
+
* Input: this.pathStack=[root], targetContainer=["recipe","ingredients"], leafSegment=0
|
|
1149
|
+
* Output: '"recipe":{"ingredients":['
|
|
1150
|
+
*/
|
|
1151
|
+
openDownTo(targetContainer, leafSegment) {
|
|
1152
|
+
let fragment = "";
|
|
1153
|
+
const startIdx = this.pathStack.length - 1;
|
|
1154
|
+
for (let i = startIdx; i < targetContainer.length; i++) {
|
|
1155
|
+
const seg = targetContainer[i];
|
|
1156
|
+
const parentEntry = this.pathStack[this.pathStack.length - 1];
|
|
1157
|
+
if (parentEntry.childCount > 0) {
|
|
1158
|
+
fragment += ",";
|
|
1159
|
+
}
|
|
1160
|
+
parentEntry.childCount++;
|
|
1161
|
+
if (typeof seg === "string") {
|
|
1162
|
+
fragment += `${JSON.stringify(seg)}:`;
|
|
1163
|
+
}
|
|
1164
|
+
const childSeg = i + 1 < targetContainer.length ? targetContainer[i + 1] : leafSegment;
|
|
1165
|
+
const isArray = typeof childSeg === "number";
|
|
1166
|
+
fragment += isArray ? "[" : "{";
|
|
1167
|
+
this.pathStack.push({ segment: seg, isArray, childCount: 0 });
|
|
1168
|
+
}
|
|
1169
|
+
return fragment;
|
|
1170
|
+
}
|
|
1171
|
+
/**
|
|
1172
|
+
* Emits the comma, key, and value for a leaf entry in the current container.
|
|
1173
|
+
*
|
|
1174
|
+
* Input: leafSegment="name", arg={stringValue:"Lasagna"}, valueJson='"Lasagna"'
|
|
1175
|
+
* Output: '"name":"Lasagna"' (or ',"name":"Lasagna"' if container.childCount > 0)
|
|
1176
|
+
*/
|
|
1177
|
+
emitLeaf(leafSegment, arg, valueJson) {
|
|
1178
|
+
let fragment = "";
|
|
1179
|
+
const container = this.pathStack[this.pathStack.length - 1];
|
|
1180
|
+
if (container.childCount > 0) {
|
|
1181
|
+
fragment += ",";
|
|
1182
|
+
}
|
|
1183
|
+
container.childCount++;
|
|
1184
|
+
if (typeof leafSegment === "string") {
|
|
1185
|
+
fragment += `${JSON.stringify(leafSegment)}:`;
|
|
1186
|
+
}
|
|
1187
|
+
if (arg.stringValue != null && arg.willContinue) {
|
|
1188
|
+
fragment += valueJson.slice(0, -1);
|
|
1189
|
+
this.stringOpen = true;
|
|
1190
|
+
} else {
|
|
1191
|
+
fragment += valueJson;
|
|
1192
|
+
}
|
|
1193
|
+
return fragment;
|
|
1194
|
+
}
|
|
1195
|
+
};
|
|
1196
|
+
function parsePath(rawPath) {
|
|
1197
|
+
const segments = [];
|
|
1198
|
+
for (const part of rawPath.split(".")) {
|
|
1199
|
+
const bracketIdx = part.indexOf("[");
|
|
1200
|
+
if (bracketIdx === -1) {
|
|
1201
|
+
segments.push(part);
|
|
1202
|
+
} else {
|
|
1203
|
+
if (bracketIdx > 0) segments.push(part.slice(0, bracketIdx));
|
|
1204
|
+
for (const m of part.matchAll(/\[(\d+)\]/g)) {
|
|
1205
|
+
segments.push(parseInt(m[1], 10));
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
return segments;
|
|
1210
|
+
}
|
|
1211
|
+
function getNestedValue(obj, segments) {
|
|
1212
|
+
let current = obj;
|
|
1213
|
+
for (const seg of segments) {
|
|
1214
|
+
if (current == null || typeof current !== "object") return void 0;
|
|
1215
|
+
current = current[seg];
|
|
1216
|
+
}
|
|
1217
|
+
return current;
|
|
1218
|
+
}
|
|
1219
|
+
function setNestedValue(obj, segments, value) {
|
|
1220
|
+
let current = obj;
|
|
1221
|
+
for (let i = 0; i < segments.length - 1; i++) {
|
|
1222
|
+
const seg = segments[i];
|
|
1223
|
+
const nextSeg = segments[i + 1];
|
|
1224
|
+
if (current[seg] == null) {
|
|
1225
|
+
current[seg] = typeof nextSeg === "number" ? [] : {};
|
|
1226
|
+
}
|
|
1227
|
+
current = current[seg];
|
|
1228
|
+
}
|
|
1229
|
+
current[segments[segments.length - 1]] = value;
|
|
1230
|
+
}
|
|
1231
|
+
function resolvePartialArgValue(arg) {
|
|
1232
|
+
var _a, _b;
|
|
1233
|
+
const value = (_b = (_a = arg.stringValue) != null ? _a : arg.numberValue) != null ? _b : arg.boolValue;
|
|
1234
|
+
if (value != null) return { value, json: JSON.stringify(value) };
|
|
1235
|
+
if ("nullValue" in arg) return { value: null, json: "null" };
|
|
1236
|
+
return void 0;
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1239
|
+
// src/map-google-finish-reason.ts
|
|
1240
|
+
function mapGoogleFinishReason({
|
|
720
1241
|
finishReason,
|
|
721
1242
|
hasToolCalls
|
|
722
1243
|
}) {
|
|
@@ -741,14 +1262,23 @@ function mapGoogleGenerativeAIFinishReason({
|
|
|
741
1262
|
}
|
|
742
1263
|
}
|
|
743
1264
|
|
|
744
|
-
// src/google-
|
|
745
|
-
var
|
|
1265
|
+
// src/google-language-model.ts
|
|
1266
|
+
var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
746
1267
|
constructor(modelId, config) {
|
|
747
1268
|
this.specificationVersion = "v4";
|
|
748
1269
|
var _a;
|
|
749
1270
|
this.modelId = modelId;
|
|
750
1271
|
this.config = config;
|
|
751
|
-
this.generateId = (_a = config.generateId) != null ? _a :
|
|
1272
|
+
this.generateId = (_a = config.generateId) != null ? _a : generateId;
|
|
1273
|
+
}
|
|
1274
|
+
static [WORKFLOW_SERIALIZE](model) {
|
|
1275
|
+
return serializeModelOptions({
|
|
1276
|
+
modelId: model.modelId,
|
|
1277
|
+
config: model.config
|
|
1278
|
+
});
|
|
1279
|
+
}
|
|
1280
|
+
static [WORKFLOW_DESERIALIZE](options) {
|
|
1281
|
+
return new _GoogleLanguageModel(options.modelId, options.config);
|
|
752
1282
|
}
|
|
753
1283
|
get provider() {
|
|
754
1284
|
return this.config.provider;
|
|
@@ -770,36 +1300,54 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
770
1300
|
seed,
|
|
771
1301
|
tools,
|
|
772
1302
|
toolChoice,
|
|
1303
|
+
reasoning,
|
|
773
1304
|
providerOptions
|
|
774
|
-
}) {
|
|
775
|
-
var _a;
|
|
1305
|
+
}, { isStreaming = false } = {}) {
|
|
1306
|
+
var _a, _b;
|
|
776
1307
|
const warnings = [];
|
|
777
|
-
const
|
|
778
|
-
let googleOptions
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
1308
|
+
const providerOptionsNames = this.config.provider.includes("vertex") ? ["googleVertex", "vertex"] : ["google"];
|
|
1309
|
+
let googleOptions;
|
|
1310
|
+
for (const name of providerOptionsNames) {
|
|
1311
|
+
googleOptions = await parseProviderOptions({
|
|
1312
|
+
provider: name,
|
|
1313
|
+
providerOptions,
|
|
1314
|
+
schema: googleLanguageModelOptions
|
|
1315
|
+
});
|
|
1316
|
+
if (googleOptions != null) break;
|
|
1317
|
+
}
|
|
1318
|
+
if (googleOptions == null && !providerOptionsNames.includes("google")) {
|
|
1319
|
+
googleOptions = await parseProviderOptions({
|
|
785
1320
|
provider: "google",
|
|
786
1321
|
providerOptions,
|
|
787
1322
|
schema: googleLanguageModelOptions
|
|
788
1323
|
});
|
|
789
1324
|
}
|
|
1325
|
+
const isVertexProvider = this.config.provider.startsWith("google.vertex.");
|
|
790
1326
|
if ((tools == null ? void 0 : tools.some(
|
|
791
1327
|
(tool) => tool.type === "provider" && tool.id === "google.vertex_rag_store"
|
|
792
|
-
)) && !
|
|
1328
|
+
)) && !isVertexProvider) {
|
|
793
1329
|
warnings.push({
|
|
794
1330
|
type: "other",
|
|
795
1331
|
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}).`
|
|
796
1332
|
});
|
|
797
1333
|
}
|
|
1334
|
+
if ((googleOptions == null ? void 0 : googleOptions.streamFunctionCallArguments) && !isVertexProvider) {
|
|
1335
|
+
warnings.push({
|
|
1336
|
+
type: "other",
|
|
1337
|
+
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`
|
|
1338
|
+
});
|
|
1339
|
+
}
|
|
1340
|
+
let sanitizedServiceTier = googleOptions == null ? void 0 : googleOptions.serviceTier;
|
|
1341
|
+
if ((googleOptions == null ? void 0 : googleOptions.serviceTier) && isVertexProvider) {
|
|
1342
|
+
sanitizedServiceTier = VertexServiceTierMap[googleOptions.serviceTier];
|
|
1343
|
+
}
|
|
798
1344
|
const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
|
|
799
|
-
const
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
1345
|
+
const supportsFunctionResponseParts = this.modelId.startsWith("gemini-3");
|
|
1346
|
+
const { contents, systemInstruction } = convertToGoogleMessages(prompt, {
|
|
1347
|
+
isGemmaModel,
|
|
1348
|
+
providerOptionsNames,
|
|
1349
|
+
supportsFunctionResponseParts
|
|
1350
|
+
});
|
|
803
1351
|
const {
|
|
804
1352
|
tools: googleTools2,
|
|
805
1353
|
toolConfig: googleToolConfig,
|
|
@@ -807,8 +1355,28 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
807
1355
|
} = prepareTools({
|
|
808
1356
|
tools,
|
|
809
1357
|
toolChoice,
|
|
810
|
-
modelId: this.modelId
|
|
1358
|
+
modelId: this.modelId,
|
|
1359
|
+
isVertexProvider
|
|
1360
|
+
});
|
|
1361
|
+
const resolvedThinking = resolveThinkingConfig({
|
|
1362
|
+
reasoning,
|
|
1363
|
+
modelId: this.modelId,
|
|
1364
|
+
warnings
|
|
811
1365
|
});
|
|
1366
|
+
const thinkingConfig = (googleOptions == null ? void 0 : googleOptions.thinkingConfig) || resolvedThinking ? { ...resolvedThinking, ...googleOptions == null ? void 0 : googleOptions.thinkingConfig } : void 0;
|
|
1367
|
+
const streamFunctionCallArguments = isStreaming && isVertexProvider ? (_a = googleOptions == null ? void 0 : googleOptions.streamFunctionCallArguments) != null ? _a : false : void 0;
|
|
1368
|
+
const toolConfig = googleToolConfig || streamFunctionCallArguments || (googleOptions == null ? void 0 : googleOptions.retrievalConfig) ? {
|
|
1369
|
+
...googleToolConfig,
|
|
1370
|
+
...streamFunctionCallArguments && {
|
|
1371
|
+
functionCallingConfig: {
|
|
1372
|
+
...googleToolConfig == null ? void 0 : googleToolConfig.functionCallingConfig,
|
|
1373
|
+
streamFunctionCallArguments: true
|
|
1374
|
+
}
|
|
1375
|
+
},
|
|
1376
|
+
...(googleOptions == null ? void 0 : googleOptions.retrievalConfig) && {
|
|
1377
|
+
retrievalConfig: googleOptions.retrievalConfig
|
|
1378
|
+
}
|
|
1379
|
+
} : void 0;
|
|
812
1380
|
return {
|
|
813
1381
|
args: {
|
|
814
1382
|
generationConfig: {
|
|
@@ -826,13 +1394,13 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
826
1394
|
responseSchema: (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && // Google GenAI does not support all OpenAPI Schema features,
|
|
827
1395
|
// so this is needed as an escape hatch:
|
|
828
1396
|
// TODO convert into provider option
|
|
829
|
-
((
|
|
1397
|
+
((_b = googleOptions == null ? void 0 : googleOptions.structuredOutputs) != null ? _b : true) ? convertJSONSchemaToOpenAPISchema(responseFormat.schema) : void 0,
|
|
830
1398
|
...(googleOptions == null ? void 0 : googleOptions.audioTimestamp) && {
|
|
831
1399
|
audioTimestamp: googleOptions.audioTimestamp
|
|
832
1400
|
},
|
|
833
1401
|
// provider options:
|
|
834
1402
|
responseModalities: googleOptions == null ? void 0 : googleOptions.responseModalities,
|
|
835
|
-
thinkingConfig
|
|
1403
|
+
thinkingConfig,
|
|
836
1404
|
...(googleOptions == null ? void 0 : googleOptions.mediaResolution) && {
|
|
837
1405
|
mediaResolution: googleOptions.mediaResolution
|
|
838
1406
|
},
|
|
@@ -844,36 +1412,37 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
844
1412
|
systemInstruction: isGemmaModel ? void 0 : systemInstruction,
|
|
845
1413
|
safetySettings: googleOptions == null ? void 0 : googleOptions.safetySettings,
|
|
846
1414
|
tools: googleTools2,
|
|
847
|
-
toolConfig
|
|
848
|
-
...googleToolConfig,
|
|
849
|
-
retrievalConfig: googleOptions.retrievalConfig
|
|
850
|
-
} : googleToolConfig,
|
|
1415
|
+
toolConfig,
|
|
851
1416
|
cachedContent: googleOptions == null ? void 0 : googleOptions.cachedContent,
|
|
852
|
-
labels: googleOptions == null ? void 0 : googleOptions.labels
|
|
1417
|
+
labels: googleOptions == null ? void 0 : googleOptions.labels,
|
|
1418
|
+
serviceTier: sanitizedServiceTier
|
|
853
1419
|
},
|
|
854
1420
|
warnings: [...warnings, ...toolWarnings],
|
|
855
|
-
|
|
1421
|
+
providerOptionsNames
|
|
856
1422
|
};
|
|
857
1423
|
}
|
|
858
1424
|
async doGenerate(options) {
|
|
859
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
860
|
-
const { args, warnings,
|
|
861
|
-
const
|
|
862
|
-
|
|
1425
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
1426
|
+
const { args, warnings, providerOptionsNames } = await this.getArgs(options);
|
|
1427
|
+
const wrapProviderMetadata = (payload) => Object.fromEntries(
|
|
1428
|
+
providerOptionsNames.map((name) => [name, payload])
|
|
1429
|
+
);
|
|
1430
|
+
const mergedHeaders = combineHeaders(
|
|
1431
|
+
this.config.headers ? await resolve(this.config.headers) : void 0,
|
|
863
1432
|
options.headers
|
|
864
1433
|
);
|
|
865
1434
|
const {
|
|
866
1435
|
responseHeaders,
|
|
867
1436
|
value: response,
|
|
868
1437
|
rawValue: rawResponse
|
|
869
|
-
} = await
|
|
1438
|
+
} = await postJsonToApi({
|
|
870
1439
|
url: `${this.config.baseURL}/${getModelPath(
|
|
871
1440
|
this.modelId
|
|
872
1441
|
)}:generateContent`,
|
|
873
1442
|
headers: mergedHeaders,
|
|
874
1443
|
body: args,
|
|
875
1444
|
failedResponseHandler: googleFailedResponseHandler,
|
|
876
|
-
successfulResponseHandler:
|
|
1445
|
+
successfulResponseHandler: createJsonResponseHandler(responseSchema),
|
|
877
1446
|
abortSignal: options.abortSignal,
|
|
878
1447
|
fetch: this.config.fetch
|
|
879
1448
|
});
|
|
@@ -882,6 +1451,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
882
1451
|
const parts = (_b = (_a = candidate.content) == null ? void 0 : _a.parts) != null ? _b : [];
|
|
883
1452
|
const usageMetadata = response.usageMetadata;
|
|
884
1453
|
let lastCodeExecutionToolCallId;
|
|
1454
|
+
let lastServerToolCallId;
|
|
885
1455
|
for (const part of parts) {
|
|
886
1456
|
if ("executableCode" in part && ((_c = part.executableCode) == null ? void 0 : _c.code)) {
|
|
887
1457
|
const toolCallId = this.config.generateId();
|
|
@@ -906,11 +1476,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
906
1476
|
});
|
|
907
1477
|
lastCodeExecutionToolCallId = void 0;
|
|
908
1478
|
} else if ("text" in part && part.text != null) {
|
|
909
|
-
const thoughtSignatureMetadata = part.thoughtSignature ? {
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
}
|
|
913
|
-
} : void 0;
|
|
1479
|
+
const thoughtSignatureMetadata = part.thoughtSignature ? wrapProviderMetadata({
|
|
1480
|
+
thoughtSignature: part.thoughtSignature
|
|
1481
|
+
}) : void 0;
|
|
914
1482
|
if (part.text.length === 0) {
|
|
915
1483
|
if (thoughtSignatureMetadata != null && content.length > 0) {
|
|
916
1484
|
const lastContent = content[content.length - 1];
|
|
@@ -923,65 +1491,95 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
923
1491
|
providerMetadata: thoughtSignatureMetadata
|
|
924
1492
|
});
|
|
925
1493
|
}
|
|
926
|
-
} else if ("functionCall" in part) {
|
|
1494
|
+
} else if ("functionCall" in part && part.functionCall.name != null && part.functionCall.args != null) {
|
|
927
1495
|
content.push({
|
|
928
1496
|
type: "tool-call",
|
|
929
1497
|
toolCallId: this.config.generateId(),
|
|
930
1498
|
toolName: part.functionCall.name,
|
|
931
1499
|
input: JSON.stringify(part.functionCall.args),
|
|
932
|
-
providerMetadata: part.thoughtSignature ? {
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
}
|
|
936
|
-
} : void 0
|
|
1500
|
+
providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
|
|
1501
|
+
thoughtSignature: part.thoughtSignature
|
|
1502
|
+
}) : void 0
|
|
937
1503
|
});
|
|
938
1504
|
} else if ("inlineData" in part) {
|
|
939
1505
|
const hasThought = part.thought === true;
|
|
940
1506
|
const hasThoughtSignature = !!part.thoughtSignature;
|
|
941
1507
|
content.push({
|
|
942
|
-
type: "file",
|
|
943
|
-
data: part.inlineData.data,
|
|
1508
|
+
type: hasThought ? "reasoning-file" : "file",
|
|
1509
|
+
data: { type: "data", data: part.inlineData.data },
|
|
944
1510
|
mediaType: part.inlineData.mimeType,
|
|
945
|
-
providerMetadata:
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
...hasThoughtSignature ? { thoughtSignature: part.thoughtSignature } : {}
|
|
949
|
-
}
|
|
950
|
-
} : void 0
|
|
1511
|
+
providerMetadata: hasThoughtSignature ? wrapProviderMetadata({
|
|
1512
|
+
thoughtSignature: part.thoughtSignature
|
|
1513
|
+
}) : void 0
|
|
951
1514
|
});
|
|
1515
|
+
} else if ("toolCall" in part && part.toolCall) {
|
|
1516
|
+
const toolCallId = (_e = part.toolCall.id) != null ? _e : this.config.generateId();
|
|
1517
|
+
lastServerToolCallId = toolCallId;
|
|
1518
|
+
content.push({
|
|
1519
|
+
type: "tool-call",
|
|
1520
|
+
toolCallId,
|
|
1521
|
+
toolName: `server:${part.toolCall.toolType}`,
|
|
1522
|
+
input: JSON.stringify((_f = part.toolCall.args) != null ? _f : {}),
|
|
1523
|
+
providerExecuted: true,
|
|
1524
|
+
dynamic: true,
|
|
1525
|
+
providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
|
|
1526
|
+
thoughtSignature: part.thoughtSignature,
|
|
1527
|
+
serverToolCallId: toolCallId,
|
|
1528
|
+
serverToolType: part.toolCall.toolType
|
|
1529
|
+
}) : wrapProviderMetadata({
|
|
1530
|
+
serverToolCallId: toolCallId,
|
|
1531
|
+
serverToolType: part.toolCall.toolType
|
|
1532
|
+
})
|
|
1533
|
+
});
|
|
1534
|
+
} else if ("toolResponse" in part && part.toolResponse) {
|
|
1535
|
+
const responseToolCallId = (_g = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _g : this.config.generateId();
|
|
1536
|
+
content.push({
|
|
1537
|
+
type: "tool-result",
|
|
1538
|
+
toolCallId: responseToolCallId,
|
|
1539
|
+
toolName: `server:${part.toolResponse.toolType}`,
|
|
1540
|
+
result: (_h = part.toolResponse.response) != null ? _h : {},
|
|
1541
|
+
providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
|
|
1542
|
+
thoughtSignature: part.thoughtSignature,
|
|
1543
|
+
serverToolCallId: responseToolCallId,
|
|
1544
|
+
serverToolType: part.toolResponse.toolType
|
|
1545
|
+
}) : wrapProviderMetadata({
|
|
1546
|
+
serverToolCallId: responseToolCallId,
|
|
1547
|
+
serverToolType: part.toolResponse.toolType
|
|
1548
|
+
})
|
|
1549
|
+
});
|
|
1550
|
+
lastServerToolCallId = void 0;
|
|
952
1551
|
}
|
|
953
1552
|
}
|
|
954
|
-
const sources = (
|
|
1553
|
+
const sources = (_i = extractSources({
|
|
955
1554
|
groundingMetadata: candidate.groundingMetadata,
|
|
956
1555
|
generateId: this.config.generateId
|
|
957
|
-
})) != null ?
|
|
1556
|
+
})) != null ? _i : [];
|
|
958
1557
|
for (const source of sources) {
|
|
959
1558
|
content.push(source);
|
|
960
1559
|
}
|
|
961
1560
|
return {
|
|
962
1561
|
content,
|
|
963
1562
|
finishReason: {
|
|
964
|
-
unified:
|
|
1563
|
+
unified: mapGoogleFinishReason({
|
|
965
1564
|
finishReason: candidate.finishReason,
|
|
966
1565
|
// Only count client-executed tool calls for finish reason determination.
|
|
967
1566
|
hasToolCalls: content.some(
|
|
968
1567
|
(part) => part.type === "tool-call" && !part.providerExecuted
|
|
969
1568
|
)
|
|
970
1569
|
}),
|
|
971
|
-
raw: (
|
|
1570
|
+
raw: (_j = candidate.finishReason) != null ? _j : void 0
|
|
972
1571
|
},
|
|
973
|
-
usage:
|
|
1572
|
+
usage: convertGoogleUsage(usageMetadata),
|
|
974
1573
|
warnings,
|
|
975
|
-
providerMetadata: {
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
},
|
|
1574
|
+
providerMetadata: wrapProviderMetadata({
|
|
1575
|
+
promptFeedback: (_k = response.promptFeedback) != null ? _k : null,
|
|
1576
|
+
groundingMetadata: (_l = candidate.groundingMetadata) != null ? _l : null,
|
|
1577
|
+
urlContextMetadata: (_m = candidate.urlContextMetadata) != null ? _m : null,
|
|
1578
|
+
safetyRatings: (_n = candidate.safetyRatings) != null ? _n : null,
|
|
1579
|
+
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
1580
|
+
finishMessage: (_o = candidate.finishMessage) != null ? _o : null,
|
|
1581
|
+
serviceTier: (_p = response.serviceTier) != null ? _p : null
|
|
1582
|
+
}),
|
|
985
1583
|
request: { body: args },
|
|
986
1584
|
response: {
|
|
987
1585
|
// TODO timestamp, model id, id
|
|
@@ -991,19 +1589,25 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
991
1589
|
};
|
|
992
1590
|
}
|
|
993
1591
|
async doStream(options) {
|
|
994
|
-
const { args, warnings,
|
|
995
|
-
|
|
996
|
-
|
|
1592
|
+
const { args, warnings, providerOptionsNames } = await this.getArgs(
|
|
1593
|
+
options,
|
|
1594
|
+
{ isStreaming: true }
|
|
1595
|
+
);
|
|
1596
|
+
const wrapProviderMetadata = (payload) => Object.fromEntries(
|
|
1597
|
+
providerOptionsNames.map((name) => [name, payload])
|
|
1598
|
+
);
|
|
1599
|
+
const headers = combineHeaders(
|
|
1600
|
+
this.config.headers ? await resolve(this.config.headers) : void 0,
|
|
997
1601
|
options.headers
|
|
998
1602
|
);
|
|
999
|
-
const { responseHeaders, value: response } = await
|
|
1603
|
+
const { responseHeaders, value: response } = await postJsonToApi({
|
|
1000
1604
|
url: `${this.config.baseURL}/${getModelPath(
|
|
1001
1605
|
this.modelId
|
|
1002
1606
|
)}:streamGenerateContent?alt=sse`,
|
|
1003
1607
|
headers,
|
|
1004
1608
|
body: args,
|
|
1005
1609
|
failedResponseHandler: googleFailedResponseHandler,
|
|
1006
|
-
successfulResponseHandler:
|
|
1610
|
+
successfulResponseHandler: createEventSourceResponseHandler(chunkSchema),
|
|
1007
1611
|
abortSignal: options.abortSignal,
|
|
1008
1612
|
fetch: this.config.fetch
|
|
1009
1613
|
});
|
|
@@ -1015,6 +1619,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1015
1619
|
let providerMetadata = void 0;
|
|
1016
1620
|
let lastGroundingMetadata = null;
|
|
1017
1621
|
let lastUrlContextMetadata = null;
|
|
1622
|
+
let serviceTier = null;
|
|
1018
1623
|
const generateId2 = this.config.generateId;
|
|
1019
1624
|
let hasToolCalls = false;
|
|
1020
1625
|
let currentTextBlockId = null;
|
|
@@ -1022,6 +1627,8 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1022
1627
|
let blockCounter = 0;
|
|
1023
1628
|
const emittedSourceUrls = /* @__PURE__ */ new Set();
|
|
1024
1629
|
let lastCodeExecutionToolCallId;
|
|
1630
|
+
let lastServerToolCallId;
|
|
1631
|
+
const activeStreamingToolCalls = [];
|
|
1025
1632
|
return {
|
|
1026
1633
|
stream: response.pipeThrough(
|
|
1027
1634
|
new TransformStream({
|
|
@@ -1029,7 +1636,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1029
1636
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1030
1637
|
},
|
|
1031
1638
|
transform(chunk, controller) {
|
|
1032
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
1639
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
1033
1640
|
if (options.includeRawChunks) {
|
|
1034
1641
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1035
1642
|
}
|
|
@@ -1042,6 +1649,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1042
1649
|
if (usageMetadata != null) {
|
|
1043
1650
|
usage = usageMetadata;
|
|
1044
1651
|
}
|
|
1652
|
+
if (value.serviceTier != null) {
|
|
1653
|
+
serviceTier = value.serviceTier;
|
|
1654
|
+
}
|
|
1045
1655
|
const candidate = (_a = value.candidates) == null ? void 0 : _a[0];
|
|
1046
1656
|
if (candidate == null) {
|
|
1047
1657
|
return;
|
|
@@ -1093,11 +1703,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1093
1703
|
lastCodeExecutionToolCallId = void 0;
|
|
1094
1704
|
}
|
|
1095
1705
|
} else if ("text" in part && part.text != null) {
|
|
1096
|
-
const thoughtSignatureMetadata = part.thoughtSignature ? {
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
}
|
|
1100
|
-
} : void 0;
|
|
1706
|
+
const thoughtSignatureMetadata = part.thoughtSignature ? wrapProviderMetadata({
|
|
1707
|
+
thoughtSignature: part.thoughtSignature
|
|
1708
|
+
}) : void 0;
|
|
1101
1709
|
if (part.text.length === 0) {
|
|
1102
1710
|
if (thoughtSignatureMetadata != null && currentTextBlockId !== null) {
|
|
1103
1711
|
controller.enqueue({
|
|
@@ -1169,50 +1777,151 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1169
1777
|
}
|
|
1170
1778
|
const hasThought = part.thought === true;
|
|
1171
1779
|
const hasThoughtSignature = !!part.thoughtSignature;
|
|
1172
|
-
const fileMeta =
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
...hasThoughtSignature ? { thoughtSignature: part.thoughtSignature } : {}
|
|
1176
|
-
}
|
|
1177
|
-
} : void 0;
|
|
1780
|
+
const fileMeta = hasThoughtSignature ? wrapProviderMetadata({
|
|
1781
|
+
thoughtSignature: part.thoughtSignature
|
|
1782
|
+
}) : void 0;
|
|
1178
1783
|
controller.enqueue({
|
|
1179
|
-
type: "file",
|
|
1784
|
+
type: hasThought ? "reasoning-file" : "file",
|
|
1180
1785
|
mediaType: part.inlineData.mimeType,
|
|
1181
|
-
data: part.inlineData.data,
|
|
1786
|
+
data: { type: "data", data: part.inlineData.data },
|
|
1182
1787
|
providerMetadata: fileMeta
|
|
1183
1788
|
});
|
|
1789
|
+
} else if ("toolCall" in part && part.toolCall) {
|
|
1790
|
+
const toolCallId = (_e = part.toolCall.id) != null ? _e : generateId2();
|
|
1791
|
+
lastServerToolCallId = toolCallId;
|
|
1792
|
+
const serverMeta = wrapProviderMetadata({
|
|
1793
|
+
...part.thoughtSignature ? { thoughtSignature: part.thoughtSignature } : {},
|
|
1794
|
+
serverToolCallId: toolCallId,
|
|
1795
|
+
serverToolType: part.toolCall.toolType
|
|
1796
|
+
});
|
|
1797
|
+
controller.enqueue({
|
|
1798
|
+
type: "tool-call",
|
|
1799
|
+
toolCallId,
|
|
1800
|
+
toolName: `server:${part.toolCall.toolType}`,
|
|
1801
|
+
input: JSON.stringify((_f = part.toolCall.args) != null ? _f : {}),
|
|
1802
|
+
providerExecuted: true,
|
|
1803
|
+
dynamic: true,
|
|
1804
|
+
providerMetadata: serverMeta
|
|
1805
|
+
});
|
|
1806
|
+
} else if ("toolResponse" in part && part.toolResponse) {
|
|
1807
|
+
const responseToolCallId = (_g = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _g : generateId2();
|
|
1808
|
+
const serverMeta = wrapProviderMetadata({
|
|
1809
|
+
...part.thoughtSignature ? { thoughtSignature: part.thoughtSignature } : {},
|
|
1810
|
+
serverToolCallId: responseToolCallId,
|
|
1811
|
+
serverToolType: part.toolResponse.toolType
|
|
1812
|
+
});
|
|
1813
|
+
controller.enqueue({
|
|
1814
|
+
type: "tool-result",
|
|
1815
|
+
toolCallId: responseToolCallId,
|
|
1816
|
+
toolName: `server:${part.toolResponse.toolType}`,
|
|
1817
|
+
result: (_h = part.toolResponse.response) != null ? _h : {},
|
|
1818
|
+
providerMetadata: serverMeta
|
|
1819
|
+
});
|
|
1820
|
+
lastServerToolCallId = void 0;
|
|
1184
1821
|
}
|
|
1185
1822
|
}
|
|
1186
|
-
const
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1823
|
+
for (const part of parts) {
|
|
1824
|
+
if (!("functionCall" in part)) continue;
|
|
1825
|
+
const providerMeta = part.thoughtSignature ? wrapProviderMetadata({
|
|
1826
|
+
thoughtSignature: part.thoughtSignature
|
|
1827
|
+
}) : void 0;
|
|
1828
|
+
const isStreamingChunk = part.functionCall.partialArgs != null || part.functionCall.name != null && part.functionCall.willContinue === true;
|
|
1829
|
+
const isTerminalChunk = part.functionCall.name == null && part.functionCall.args == null && part.functionCall.partialArgs == null && part.functionCall.willContinue == null;
|
|
1830
|
+
const isCompleteCall = part.functionCall.name != null && part.functionCall.args != null && part.functionCall.partialArgs == null;
|
|
1831
|
+
if (isStreamingChunk) {
|
|
1832
|
+
if (part.functionCall.name != null && part.functionCall.willContinue === true) {
|
|
1833
|
+
const toolCallId = generateId2();
|
|
1834
|
+
const accumulator = new GoogleJSONAccumulator();
|
|
1835
|
+
activeStreamingToolCalls.push({
|
|
1836
|
+
toolCallId,
|
|
1837
|
+
toolName: part.functionCall.name,
|
|
1838
|
+
accumulator,
|
|
1839
|
+
providerMetadata: providerMeta
|
|
1840
|
+
});
|
|
1841
|
+
controller.enqueue({
|
|
1842
|
+
type: "tool-input-start",
|
|
1843
|
+
id: toolCallId,
|
|
1844
|
+
toolName: part.functionCall.name,
|
|
1845
|
+
providerMetadata: providerMeta
|
|
1846
|
+
});
|
|
1847
|
+
if (part.functionCall.partialArgs != null) {
|
|
1848
|
+
const { textDelta } = accumulator.processPartialArgs(
|
|
1849
|
+
part.functionCall.partialArgs
|
|
1850
|
+
);
|
|
1851
|
+
if (textDelta.length > 0) {
|
|
1852
|
+
controller.enqueue({
|
|
1853
|
+
type: "tool-input-delta",
|
|
1854
|
+
id: toolCallId,
|
|
1855
|
+
delta: textDelta,
|
|
1856
|
+
providerMetadata: providerMeta
|
|
1857
|
+
});
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1860
|
+
} else if (part.functionCall.partialArgs != null && activeStreamingToolCalls.length > 0) {
|
|
1861
|
+
const active = activeStreamingToolCalls[activeStreamingToolCalls.length - 1];
|
|
1862
|
+
const { textDelta } = active.accumulator.processPartialArgs(
|
|
1863
|
+
part.functionCall.partialArgs
|
|
1864
|
+
);
|
|
1865
|
+
if (textDelta.length > 0) {
|
|
1866
|
+
controller.enqueue({
|
|
1867
|
+
type: "tool-input-delta",
|
|
1868
|
+
id: active.toolCallId,
|
|
1869
|
+
delta: textDelta,
|
|
1870
|
+
providerMetadata: providerMeta
|
|
1871
|
+
});
|
|
1872
|
+
}
|
|
1873
|
+
}
|
|
1874
|
+
} else if (isTerminalChunk && activeStreamingToolCalls.length > 0) {
|
|
1875
|
+
const active = activeStreamingToolCalls.pop();
|
|
1876
|
+
const { finalJSON, closingDelta } = active.accumulator.finalize();
|
|
1877
|
+
if (closingDelta.length > 0) {
|
|
1878
|
+
controller.enqueue({
|
|
1879
|
+
type: "tool-input-delta",
|
|
1880
|
+
id: active.toolCallId,
|
|
1881
|
+
delta: closingDelta,
|
|
1882
|
+
providerMetadata: active.providerMetadata
|
|
1883
|
+
});
|
|
1884
|
+
}
|
|
1885
|
+
controller.enqueue({
|
|
1886
|
+
type: "tool-input-end",
|
|
1887
|
+
id: active.toolCallId,
|
|
1888
|
+
providerMetadata: active.providerMetadata
|
|
1889
|
+
});
|
|
1890
|
+
controller.enqueue({
|
|
1891
|
+
type: "tool-call",
|
|
1892
|
+
toolCallId: active.toolCallId,
|
|
1893
|
+
toolName: active.toolName,
|
|
1894
|
+
input: finalJSON,
|
|
1895
|
+
providerMetadata: active.providerMetadata
|
|
1896
|
+
});
|
|
1897
|
+
hasToolCalls = true;
|
|
1898
|
+
} else if (isCompleteCall) {
|
|
1899
|
+
const toolCallId = generateId2();
|
|
1900
|
+
const toolName = part.functionCall.name;
|
|
1901
|
+
const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((_i = part.functionCall.args) != null ? _i : {});
|
|
1193
1902
|
controller.enqueue({
|
|
1194
1903
|
type: "tool-input-start",
|
|
1195
|
-
id:
|
|
1196
|
-
toolName
|
|
1197
|
-
providerMetadata:
|
|
1904
|
+
id: toolCallId,
|
|
1905
|
+
toolName,
|
|
1906
|
+
providerMetadata: providerMeta
|
|
1198
1907
|
});
|
|
1199
1908
|
controller.enqueue({
|
|
1200
1909
|
type: "tool-input-delta",
|
|
1201
|
-
id:
|
|
1202
|
-
delta:
|
|
1203
|
-
providerMetadata:
|
|
1910
|
+
id: toolCallId,
|
|
1911
|
+
delta: args2,
|
|
1912
|
+
providerMetadata: providerMeta
|
|
1204
1913
|
});
|
|
1205
1914
|
controller.enqueue({
|
|
1206
1915
|
type: "tool-input-end",
|
|
1207
|
-
id:
|
|
1208
|
-
providerMetadata:
|
|
1916
|
+
id: toolCallId,
|
|
1917
|
+
providerMetadata: providerMeta
|
|
1209
1918
|
});
|
|
1210
1919
|
controller.enqueue({
|
|
1211
1920
|
type: "tool-call",
|
|
1212
|
-
toolCallId
|
|
1213
|
-
toolName
|
|
1214
|
-
input:
|
|
1215
|
-
providerMetadata:
|
|
1921
|
+
toolCallId,
|
|
1922
|
+
toolName,
|
|
1923
|
+
input: args2,
|
|
1924
|
+
providerMetadata: providerMeta
|
|
1216
1925
|
});
|
|
1217
1926
|
hasToolCalls = true;
|
|
1218
1927
|
}
|
|
@@ -1220,22 +1929,21 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1220
1929
|
}
|
|
1221
1930
|
if (candidate.finishReason != null) {
|
|
1222
1931
|
finishReason = {
|
|
1223
|
-
unified:
|
|
1932
|
+
unified: mapGoogleFinishReason({
|
|
1224
1933
|
finishReason: candidate.finishReason,
|
|
1225
1934
|
hasToolCalls
|
|
1226
1935
|
}),
|
|
1227
1936
|
raw: candidate.finishReason
|
|
1228
1937
|
};
|
|
1229
|
-
providerMetadata = {
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
};
|
|
1938
|
+
providerMetadata = wrapProviderMetadata({
|
|
1939
|
+
promptFeedback: (_j = value.promptFeedback) != null ? _j : null,
|
|
1940
|
+
groundingMetadata: lastGroundingMetadata,
|
|
1941
|
+
urlContextMetadata: lastUrlContextMetadata,
|
|
1942
|
+
safetyRatings: (_k = candidate.safetyRatings) != null ? _k : null,
|
|
1943
|
+
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
1944
|
+
finishMessage: (_l = candidate.finishMessage) != null ? _l : null,
|
|
1945
|
+
serviceTier
|
|
1946
|
+
});
|
|
1239
1947
|
}
|
|
1240
1948
|
},
|
|
1241
1949
|
flush(controller) {
|
|
@@ -1254,7 +1962,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1254
1962
|
controller.enqueue({
|
|
1255
1963
|
type: "finish",
|
|
1256
1964
|
finishReason,
|
|
1257
|
-
usage:
|
|
1965
|
+
usage: convertGoogleUsage(usage),
|
|
1258
1966
|
providerMetadata
|
|
1259
1967
|
});
|
|
1260
1968
|
}
|
|
@@ -1265,25 +1973,74 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1265
1973
|
};
|
|
1266
1974
|
}
|
|
1267
1975
|
};
|
|
1268
|
-
function
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1976
|
+
function isGemini3Model(modelId) {
|
|
1977
|
+
return /gemini-3[\.\-]/i.test(modelId) || /gemini-3$/i.test(modelId);
|
|
1978
|
+
}
|
|
1979
|
+
function getMaxOutputTokensForGemini25Model() {
|
|
1980
|
+
return 65536;
|
|
1981
|
+
}
|
|
1982
|
+
function getMaxThinkingTokensForGemini25Model(modelId) {
|
|
1983
|
+
const id = modelId.toLowerCase();
|
|
1984
|
+
if (id.includes("2.5-pro") || id.includes("gemini-3-pro-image")) {
|
|
1985
|
+
return 32768;
|
|
1986
|
+
}
|
|
1987
|
+
return 24576;
|
|
1988
|
+
}
|
|
1989
|
+
function resolveThinkingConfig({
|
|
1990
|
+
reasoning,
|
|
1991
|
+
modelId,
|
|
1992
|
+
warnings
|
|
1272
1993
|
}) {
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1994
|
+
if (!isCustomReasoning(reasoning)) {
|
|
1995
|
+
return void 0;
|
|
1996
|
+
}
|
|
1997
|
+
if (isGemini3Model(modelId) && !modelId.includes("gemini-3-pro-image")) {
|
|
1998
|
+
return resolveGemini3ThinkingConfig({ reasoning, warnings });
|
|
1999
|
+
}
|
|
2000
|
+
return resolveGemini25ThinkingConfig({ reasoning, modelId, warnings });
|
|
2001
|
+
}
|
|
2002
|
+
function resolveGemini3ThinkingConfig({
|
|
2003
|
+
reasoning,
|
|
2004
|
+
warnings
|
|
2005
|
+
}) {
|
|
2006
|
+
if (reasoning === "none") {
|
|
2007
|
+
return { thinkingLevel: "minimal" };
|
|
2008
|
+
}
|
|
2009
|
+
const thinkingLevel = mapReasoningToProviderEffort({
|
|
2010
|
+
reasoning,
|
|
2011
|
+
effortMap: {
|
|
2012
|
+
minimal: "minimal",
|
|
2013
|
+
low: "low",
|
|
2014
|
+
medium: "medium",
|
|
2015
|
+
high: "high",
|
|
2016
|
+
xhigh: "high"
|
|
2017
|
+
},
|
|
2018
|
+
warnings
|
|
2019
|
+
});
|
|
2020
|
+
if (thinkingLevel == null) {
|
|
2021
|
+
return void 0;
|
|
2022
|
+
}
|
|
2023
|
+
return { thinkingLevel };
|
|
2024
|
+
}
|
|
2025
|
+
function resolveGemini25ThinkingConfig({
|
|
2026
|
+
reasoning,
|
|
2027
|
+
modelId,
|
|
2028
|
+
warnings
|
|
2029
|
+
}) {
|
|
2030
|
+
if (reasoning === "none") {
|
|
2031
|
+
return { thinkingBudget: 0 };
|
|
2032
|
+
}
|
|
2033
|
+
const thinkingBudget = mapReasoningToProviderBudget({
|
|
2034
|
+
reasoning,
|
|
2035
|
+
maxOutputTokens: getMaxOutputTokensForGemini25Model(),
|
|
2036
|
+
maxReasoningBudget: getMaxThinkingTokensForGemini25Model(modelId),
|
|
2037
|
+
minReasoningBudget: 0,
|
|
2038
|
+
warnings
|
|
2039
|
+
});
|
|
2040
|
+
if (thinkingBudget == null) {
|
|
2041
|
+
return void 0;
|
|
2042
|
+
}
|
|
2043
|
+
return { thinkingBudget };
|
|
1287
2044
|
}
|
|
1288
2045
|
function extractSources({
|
|
1289
2046
|
groundingMetadata,
|
|
@@ -1379,256 +2136,312 @@ function extractSources({
|
|
|
1379
2136
|
}
|
|
1380
2137
|
return sources.length > 0 ? sources : void 0;
|
|
1381
2138
|
}
|
|
1382
|
-
var getGroundingMetadataSchema = () =>
|
|
1383
|
-
webSearchQueries:
|
|
1384
|
-
imageSearchQueries:
|
|
1385
|
-
retrievalQueries:
|
|
1386
|
-
searchEntryPoint:
|
|
1387
|
-
groundingChunks:
|
|
1388
|
-
|
|
1389
|
-
web:
|
|
1390
|
-
image:
|
|
1391
|
-
sourceUri:
|
|
1392
|
-
imageUri:
|
|
1393
|
-
title:
|
|
1394
|
-
domain:
|
|
2139
|
+
var getGroundingMetadataSchema = () => z3.object({
|
|
2140
|
+
webSearchQueries: z3.array(z3.string()).nullish(),
|
|
2141
|
+
imageSearchQueries: z3.array(z3.string()).nullish(),
|
|
2142
|
+
retrievalQueries: z3.array(z3.string()).nullish(),
|
|
2143
|
+
searchEntryPoint: z3.object({ renderedContent: z3.string() }).nullish(),
|
|
2144
|
+
groundingChunks: z3.array(
|
|
2145
|
+
z3.object({
|
|
2146
|
+
web: z3.object({ uri: z3.string(), title: z3.string().nullish() }).nullish(),
|
|
2147
|
+
image: z3.object({
|
|
2148
|
+
sourceUri: z3.string(),
|
|
2149
|
+
imageUri: z3.string(),
|
|
2150
|
+
title: z3.string().nullish(),
|
|
2151
|
+
domain: z3.string().nullish()
|
|
1395
2152
|
}).nullish(),
|
|
1396
|
-
retrievedContext:
|
|
1397
|
-
uri:
|
|
1398
|
-
title:
|
|
1399
|
-
text:
|
|
1400
|
-
fileSearchStore:
|
|
2153
|
+
retrievedContext: z3.object({
|
|
2154
|
+
uri: z3.string().nullish(),
|
|
2155
|
+
title: z3.string().nullish(),
|
|
2156
|
+
text: z3.string().nullish(),
|
|
2157
|
+
fileSearchStore: z3.string().nullish()
|
|
1401
2158
|
}).nullish(),
|
|
1402
|
-
maps:
|
|
1403
|
-
uri:
|
|
1404
|
-
title:
|
|
1405
|
-
text:
|
|
1406
|
-
placeId:
|
|
2159
|
+
maps: z3.object({
|
|
2160
|
+
uri: z3.string().nullish(),
|
|
2161
|
+
title: z3.string().nullish(),
|
|
2162
|
+
text: z3.string().nullish(),
|
|
2163
|
+
placeId: z3.string().nullish()
|
|
1407
2164
|
}).nullish()
|
|
1408
2165
|
})
|
|
1409
2166
|
).nullish(),
|
|
1410
|
-
groundingSupports:
|
|
1411
|
-
|
|
1412
|
-
segment:
|
|
1413
|
-
startIndex:
|
|
1414
|
-
endIndex:
|
|
1415
|
-
text:
|
|
2167
|
+
groundingSupports: z3.array(
|
|
2168
|
+
z3.object({
|
|
2169
|
+
segment: z3.object({
|
|
2170
|
+
startIndex: z3.number().nullish(),
|
|
2171
|
+
endIndex: z3.number().nullish(),
|
|
2172
|
+
text: z3.string().nullish()
|
|
1416
2173
|
}).nullish(),
|
|
1417
|
-
segment_text:
|
|
1418
|
-
groundingChunkIndices:
|
|
1419
|
-
supportChunkIndices:
|
|
1420
|
-
confidenceScores:
|
|
1421
|
-
confidenceScore:
|
|
2174
|
+
segment_text: z3.string().nullish(),
|
|
2175
|
+
groundingChunkIndices: z3.array(z3.number()).nullish(),
|
|
2176
|
+
supportChunkIndices: z3.array(z3.number()).nullish(),
|
|
2177
|
+
confidenceScores: z3.array(z3.number()).nullish(),
|
|
2178
|
+
confidenceScore: z3.array(z3.number()).nullish()
|
|
1422
2179
|
})
|
|
1423
2180
|
).nullish(),
|
|
1424
|
-
retrievalMetadata:
|
|
1425
|
-
|
|
1426
|
-
webDynamicRetrievalScore:
|
|
2181
|
+
retrievalMetadata: z3.union([
|
|
2182
|
+
z3.object({
|
|
2183
|
+
webDynamicRetrievalScore: z3.number()
|
|
1427
2184
|
}),
|
|
1428
|
-
|
|
2185
|
+
z3.object({})
|
|
1429
2186
|
]).nullish()
|
|
1430
2187
|
});
|
|
1431
|
-
var
|
|
1432
|
-
|
|
1433
|
-
|
|
2188
|
+
var partialArgSchema = z3.object({
|
|
2189
|
+
jsonPath: z3.string(),
|
|
2190
|
+
stringValue: z3.string().nullish(),
|
|
2191
|
+
numberValue: z3.number().nullish(),
|
|
2192
|
+
boolValue: z3.boolean().nullish(),
|
|
2193
|
+
nullValue: z3.unknown().nullish(),
|
|
2194
|
+
willContinue: z3.boolean().nullish()
|
|
2195
|
+
});
|
|
2196
|
+
var getContentSchema = () => z3.object({
|
|
2197
|
+
parts: z3.array(
|
|
2198
|
+
z3.union([
|
|
1434
2199
|
// note: order matters since text can be fully empty
|
|
1435
|
-
|
|
1436
|
-
functionCall:
|
|
1437
|
-
name:
|
|
1438
|
-
args:
|
|
2200
|
+
z3.object({
|
|
2201
|
+
functionCall: z3.object({
|
|
2202
|
+
name: z3.string().nullish(),
|
|
2203
|
+
args: z3.unknown().nullish(),
|
|
2204
|
+
partialArgs: z3.array(partialArgSchema).nullish(),
|
|
2205
|
+
willContinue: z3.boolean().nullish()
|
|
2206
|
+
}),
|
|
2207
|
+
thoughtSignature: z3.string().nullish()
|
|
2208
|
+
}),
|
|
2209
|
+
z3.object({
|
|
2210
|
+
inlineData: z3.object({
|
|
2211
|
+
mimeType: z3.string(),
|
|
2212
|
+
data: z3.string()
|
|
2213
|
+
}),
|
|
2214
|
+
thought: z3.boolean().nullish(),
|
|
2215
|
+
thoughtSignature: z3.string().nullish()
|
|
2216
|
+
}),
|
|
2217
|
+
z3.object({
|
|
2218
|
+
toolCall: z3.object({
|
|
2219
|
+
toolType: z3.string(),
|
|
2220
|
+
args: z3.unknown().nullish(),
|
|
2221
|
+
id: z3.string()
|
|
1439
2222
|
}),
|
|
1440
|
-
thoughtSignature:
|
|
2223
|
+
thoughtSignature: z3.string().nullish()
|
|
1441
2224
|
}),
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
2225
|
+
z3.object({
|
|
2226
|
+
toolResponse: z3.object({
|
|
2227
|
+
toolType: z3.string(),
|
|
2228
|
+
response: z3.unknown().nullish(),
|
|
2229
|
+
id: z3.string()
|
|
1446
2230
|
}),
|
|
1447
|
-
|
|
1448
|
-
thoughtSignature: import_v43.z.string().nullish()
|
|
2231
|
+
thoughtSignature: z3.string().nullish()
|
|
1449
2232
|
}),
|
|
1450
|
-
|
|
1451
|
-
executableCode:
|
|
1452
|
-
language:
|
|
1453
|
-
code:
|
|
2233
|
+
z3.object({
|
|
2234
|
+
executableCode: z3.object({
|
|
2235
|
+
language: z3.string(),
|
|
2236
|
+
code: z3.string()
|
|
1454
2237
|
}).nullish(),
|
|
1455
|
-
codeExecutionResult:
|
|
1456
|
-
outcome:
|
|
1457
|
-
output:
|
|
2238
|
+
codeExecutionResult: z3.object({
|
|
2239
|
+
outcome: z3.string(),
|
|
2240
|
+
output: z3.string().nullish()
|
|
1458
2241
|
}).nullish(),
|
|
1459
|
-
text:
|
|
1460
|
-
thought:
|
|
1461
|
-
thoughtSignature:
|
|
2242
|
+
text: z3.string().nullish(),
|
|
2243
|
+
thought: z3.boolean().nullish(),
|
|
2244
|
+
thoughtSignature: z3.string().nullish()
|
|
1462
2245
|
})
|
|
1463
2246
|
])
|
|
1464
2247
|
).nullish()
|
|
1465
2248
|
});
|
|
1466
|
-
var getSafetyRatingSchema = () =>
|
|
1467
|
-
category:
|
|
1468
|
-
probability:
|
|
1469
|
-
probabilityScore:
|
|
1470
|
-
severity:
|
|
1471
|
-
severityScore:
|
|
1472
|
-
blocked:
|
|
2249
|
+
var getSafetyRatingSchema = () => z3.object({
|
|
2250
|
+
category: z3.string().nullish(),
|
|
2251
|
+
probability: z3.string().nullish(),
|
|
2252
|
+
probabilityScore: z3.number().nullish(),
|
|
2253
|
+
severity: z3.string().nullish(),
|
|
2254
|
+
severityScore: z3.number().nullish(),
|
|
2255
|
+
blocked: z3.boolean().nullish()
|
|
1473
2256
|
});
|
|
1474
|
-
var
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
2257
|
+
var tokenDetailsSchema = z3.array(
|
|
2258
|
+
z3.object({
|
|
2259
|
+
modality: z3.string(),
|
|
2260
|
+
tokenCount: z3.number()
|
|
2261
|
+
})
|
|
2262
|
+
).nullish();
|
|
2263
|
+
var usageSchema = z3.object({
|
|
2264
|
+
cachedContentTokenCount: z3.number().nullish(),
|
|
2265
|
+
thoughtsTokenCount: z3.number().nullish(),
|
|
2266
|
+
promptTokenCount: z3.number().nullish(),
|
|
2267
|
+
candidatesTokenCount: z3.number().nullish(),
|
|
2268
|
+
totalTokenCount: z3.number().nullish(),
|
|
1480
2269
|
// https://cloud.google.com/vertex-ai/generative-ai/docs/reference/rest/v1/GenerateContentResponse#TrafficType
|
|
1481
|
-
trafficType:
|
|
2270
|
+
trafficType: z3.string().nullish(),
|
|
2271
|
+
// https://ai.google.dev/api/generate-content#Modality
|
|
2272
|
+
promptTokensDetails: tokenDetailsSchema,
|
|
2273
|
+
candidatesTokensDetails: tokenDetailsSchema
|
|
1482
2274
|
});
|
|
1483
|
-
var getUrlContextMetadataSchema = () =>
|
|
1484
|
-
urlMetadata:
|
|
1485
|
-
|
|
1486
|
-
retrievedUrl:
|
|
1487
|
-
urlRetrievalStatus:
|
|
2275
|
+
var getUrlContextMetadataSchema = () => z3.object({
|
|
2276
|
+
urlMetadata: z3.array(
|
|
2277
|
+
z3.object({
|
|
2278
|
+
retrievedUrl: z3.string(),
|
|
2279
|
+
urlRetrievalStatus: z3.string()
|
|
1488
2280
|
})
|
|
1489
2281
|
).nullish()
|
|
1490
2282
|
});
|
|
1491
|
-
var responseSchema = (
|
|
1492
|
-
() => (
|
|
1493
|
-
|
|
1494
|
-
candidates:
|
|
1495
|
-
|
|
1496
|
-
content: getContentSchema().nullish().or(
|
|
1497
|
-
finishReason:
|
|
1498
|
-
finishMessage:
|
|
1499
|
-
safetyRatings:
|
|
2283
|
+
var responseSchema = lazySchema3(
|
|
2284
|
+
() => zodSchema3(
|
|
2285
|
+
z3.object({
|
|
2286
|
+
candidates: z3.array(
|
|
2287
|
+
z3.object({
|
|
2288
|
+
content: getContentSchema().nullish().or(z3.object({}).strict()),
|
|
2289
|
+
finishReason: z3.string().nullish(),
|
|
2290
|
+
finishMessage: z3.string().nullish(),
|
|
2291
|
+
safetyRatings: z3.array(getSafetyRatingSchema()).nullish(),
|
|
1500
2292
|
groundingMetadata: getGroundingMetadataSchema().nullish(),
|
|
1501
2293
|
urlContextMetadata: getUrlContextMetadataSchema().nullish()
|
|
1502
2294
|
})
|
|
1503
2295
|
),
|
|
1504
2296
|
usageMetadata: usageSchema.nullish(),
|
|
1505
|
-
promptFeedback:
|
|
1506
|
-
blockReason:
|
|
1507
|
-
safetyRatings:
|
|
1508
|
-
}).nullish()
|
|
2297
|
+
promptFeedback: z3.object({
|
|
2298
|
+
blockReason: z3.string().nullish(),
|
|
2299
|
+
safetyRatings: z3.array(getSafetyRatingSchema()).nullish()
|
|
2300
|
+
}).nullish(),
|
|
2301
|
+
serviceTier: z3.string().nullish()
|
|
1509
2302
|
})
|
|
1510
2303
|
)
|
|
1511
2304
|
);
|
|
1512
|
-
var chunkSchema = (
|
|
1513
|
-
() => (
|
|
1514
|
-
|
|
1515
|
-
candidates:
|
|
1516
|
-
|
|
2305
|
+
var chunkSchema = lazySchema3(
|
|
2306
|
+
() => zodSchema3(
|
|
2307
|
+
z3.object({
|
|
2308
|
+
candidates: z3.array(
|
|
2309
|
+
z3.object({
|
|
1517
2310
|
content: getContentSchema().nullish(),
|
|
1518
|
-
finishReason:
|
|
1519
|
-
finishMessage:
|
|
1520
|
-
safetyRatings:
|
|
2311
|
+
finishReason: z3.string().nullish(),
|
|
2312
|
+
finishMessage: z3.string().nullish(),
|
|
2313
|
+
safetyRatings: z3.array(getSafetyRatingSchema()).nullish(),
|
|
1521
2314
|
groundingMetadata: getGroundingMetadataSchema().nullish(),
|
|
1522
2315
|
urlContextMetadata: getUrlContextMetadataSchema().nullish()
|
|
1523
2316
|
})
|
|
1524
2317
|
).nullish(),
|
|
1525
2318
|
usageMetadata: usageSchema.nullish(),
|
|
1526
|
-
promptFeedback:
|
|
1527
|
-
blockReason:
|
|
1528
|
-
safetyRatings:
|
|
1529
|
-
}).nullish()
|
|
2319
|
+
promptFeedback: z3.object({
|
|
2320
|
+
blockReason: z3.string().nullish(),
|
|
2321
|
+
safetyRatings: z3.array(getSafetyRatingSchema()).nullish()
|
|
2322
|
+
}).nullish(),
|
|
2323
|
+
serviceTier: z3.string().nullish()
|
|
1530
2324
|
})
|
|
1531
2325
|
)
|
|
1532
2326
|
);
|
|
1533
2327
|
|
|
1534
2328
|
// src/tool/code-execution.ts
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
var codeExecution = (
|
|
2329
|
+
import { createProviderExecutedToolFactory } from "@ai-sdk/provider-utils";
|
|
2330
|
+
import { z as z4 } from "zod/v4";
|
|
2331
|
+
var codeExecution = createProviderExecutedToolFactory({
|
|
1538
2332
|
id: "google.code_execution",
|
|
1539
|
-
inputSchema:
|
|
1540
|
-
language:
|
|
1541
|
-
code:
|
|
2333
|
+
inputSchema: z4.object({
|
|
2334
|
+
language: z4.string().describe("The programming language of the code."),
|
|
2335
|
+
code: z4.string().describe("The code to be executed.")
|
|
1542
2336
|
}),
|
|
1543
|
-
outputSchema:
|
|
1544
|
-
outcome:
|
|
1545
|
-
output:
|
|
2337
|
+
outputSchema: z4.object({
|
|
2338
|
+
outcome: z4.string().describe('The outcome of the execution (e.g., "OUTCOME_OK").'),
|
|
2339
|
+
output: z4.string().describe("The output from the code execution.")
|
|
1546
2340
|
})
|
|
1547
2341
|
});
|
|
1548
2342
|
|
|
1549
2343
|
// src/tool/enterprise-web-search.ts
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
2344
|
+
import {
|
|
2345
|
+
createProviderExecutedToolFactory as createProviderExecutedToolFactory2,
|
|
2346
|
+
lazySchema as lazySchema4,
|
|
2347
|
+
zodSchema as zodSchema4
|
|
2348
|
+
} from "@ai-sdk/provider-utils";
|
|
2349
|
+
import { z as z5 } from "zod/v4";
|
|
2350
|
+
var enterpriseWebSearch = createProviderExecutedToolFactory2({
|
|
1553
2351
|
id: "google.enterprise_web_search",
|
|
1554
|
-
inputSchema: (
|
|
2352
|
+
inputSchema: lazySchema4(() => zodSchema4(z5.object({}))),
|
|
2353
|
+
outputSchema: lazySchema4(() => zodSchema4(z5.object({})))
|
|
1555
2354
|
});
|
|
1556
2355
|
|
|
1557
2356
|
// src/tool/file-search.ts
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
2357
|
+
import {
|
|
2358
|
+
createProviderExecutedToolFactory as createProviderExecutedToolFactory3,
|
|
2359
|
+
lazySchema as lazySchema5,
|
|
2360
|
+
zodSchema as zodSchema5
|
|
2361
|
+
} from "@ai-sdk/provider-utils";
|
|
2362
|
+
import { z as z6 } from "zod/v4";
|
|
2363
|
+
var fileSearchArgsBaseSchema = z6.object({
|
|
1561
2364
|
/** The names of the file_search_stores to retrieve from.
|
|
1562
2365
|
* Example: `fileSearchStores/my-file-search-store-123`
|
|
1563
2366
|
*/
|
|
1564
|
-
fileSearchStoreNames:
|
|
2367
|
+
fileSearchStoreNames: z6.array(z6.string()).describe(
|
|
1565
2368
|
"The names of the file_search_stores to retrieve from. Example: `fileSearchStores/my-file-search-store-123`"
|
|
1566
2369
|
),
|
|
1567
2370
|
/** The number of file search retrieval chunks to retrieve. */
|
|
1568
|
-
topK:
|
|
2371
|
+
topK: z6.number().int().positive().describe("The number of file search retrieval chunks to retrieve.").optional(),
|
|
1569
2372
|
/** Metadata filter to apply to the file search retrieval documents.
|
|
1570
2373
|
* See https://google.aip.dev/160 for the syntax of the filter expression.
|
|
1571
2374
|
*/
|
|
1572
|
-
metadataFilter:
|
|
2375
|
+
metadataFilter: z6.string().describe(
|
|
1573
2376
|
"Metadata filter to apply to the file search retrieval documents. See https://google.aip.dev/160 for the syntax of the filter expression."
|
|
1574
2377
|
).optional()
|
|
1575
2378
|
}).passthrough();
|
|
1576
|
-
var
|
|
1577
|
-
() => (0, import_provider_utils7.zodSchema)(fileSearchArgsBaseSchema)
|
|
1578
|
-
);
|
|
1579
|
-
var fileSearch = (0, import_provider_utils7.createProviderToolFactory)({
|
|
2379
|
+
var fileSearch = createProviderExecutedToolFactory3({
|
|
1580
2380
|
id: "google.file_search",
|
|
1581
|
-
inputSchema:
|
|
2381
|
+
inputSchema: lazySchema5(() => zodSchema5(z6.object({}))),
|
|
2382
|
+
outputSchema: lazySchema5(() => zodSchema5(z6.object({})))
|
|
1582
2383
|
});
|
|
1583
2384
|
|
|
1584
2385
|
// src/tool/google-maps.ts
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
2386
|
+
import {
|
|
2387
|
+
createProviderExecutedToolFactory as createProviderExecutedToolFactory4,
|
|
2388
|
+
lazySchema as lazySchema6,
|
|
2389
|
+
zodSchema as zodSchema6
|
|
2390
|
+
} from "@ai-sdk/provider-utils";
|
|
2391
|
+
import { z as z7 } from "zod/v4";
|
|
2392
|
+
var googleMaps = createProviderExecutedToolFactory4({
|
|
1588
2393
|
id: "google.google_maps",
|
|
1589
|
-
inputSchema: (
|
|
2394
|
+
inputSchema: lazySchema6(() => zodSchema6(z7.object({}))),
|
|
2395
|
+
outputSchema: lazySchema6(() => zodSchema6(z7.object({})))
|
|
1590
2396
|
});
|
|
1591
2397
|
|
|
1592
2398
|
// src/tool/google-search.ts
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
2399
|
+
import {
|
|
2400
|
+
createProviderExecutedToolFactory as createProviderExecutedToolFactory5,
|
|
2401
|
+
lazySchema as lazySchema7,
|
|
2402
|
+
zodSchema as zodSchema7
|
|
2403
|
+
} from "@ai-sdk/provider-utils";
|
|
2404
|
+
import { z as z8 } from "zod/v4";
|
|
2405
|
+
var googleSearchToolArgsBaseSchema = z8.object({
|
|
2406
|
+
searchTypes: z8.object({
|
|
2407
|
+
webSearch: z8.object({}).optional(),
|
|
2408
|
+
imageSearch: z8.object({}).optional()
|
|
1599
2409
|
}).optional(),
|
|
1600
|
-
timeRangeFilter:
|
|
1601
|
-
startTime:
|
|
1602
|
-
endTime:
|
|
2410
|
+
timeRangeFilter: z8.object({
|
|
2411
|
+
startTime: z8.string(),
|
|
2412
|
+
endTime: z8.string()
|
|
1603
2413
|
}).optional()
|
|
1604
2414
|
}).passthrough();
|
|
1605
|
-
var
|
|
1606
|
-
|
|
1607
|
-
)
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
id: "google.google_search",
|
|
1611
|
-
inputSchema: googleSearchToolArgsSchema
|
|
1612
|
-
}
|
|
1613
|
-
);
|
|
2415
|
+
var googleSearch = createProviderExecutedToolFactory5({
|
|
2416
|
+
id: "google.google_search",
|
|
2417
|
+
inputSchema: lazySchema7(() => zodSchema7(z8.object({}))),
|
|
2418
|
+
outputSchema: lazySchema7(() => zodSchema7(z8.object({})))
|
|
2419
|
+
});
|
|
1614
2420
|
|
|
1615
2421
|
// src/tool/url-context.ts
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
2422
|
+
import {
|
|
2423
|
+
createProviderExecutedToolFactory as createProviderExecutedToolFactory6,
|
|
2424
|
+
lazySchema as lazySchema8,
|
|
2425
|
+
zodSchema as zodSchema8
|
|
2426
|
+
} from "@ai-sdk/provider-utils";
|
|
2427
|
+
import { z as z9 } from "zod/v4";
|
|
2428
|
+
var urlContext = createProviderExecutedToolFactory6({
|
|
1619
2429
|
id: "google.url_context",
|
|
1620
|
-
inputSchema: (
|
|
2430
|
+
inputSchema: lazySchema8(() => zodSchema8(z9.object({}))),
|
|
2431
|
+
outputSchema: lazySchema8(() => zodSchema8(z9.object({})))
|
|
1621
2432
|
});
|
|
1622
2433
|
|
|
1623
2434
|
// src/tool/vertex-rag-store.ts
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
2435
|
+
import {
|
|
2436
|
+
createProviderExecutedToolFactory as createProviderExecutedToolFactory7,
|
|
2437
|
+
lazySchema as lazySchema9,
|
|
2438
|
+
zodSchema as zodSchema9
|
|
2439
|
+
} from "@ai-sdk/provider-utils";
|
|
2440
|
+
import { z as z10 } from "zod/v4";
|
|
2441
|
+
var vertexRagStore = createProviderExecutedToolFactory7({
|
|
1627
2442
|
id: "google.vertex_rag_store",
|
|
1628
|
-
inputSchema:
|
|
1629
|
-
|
|
1630
|
-
topK: import_v410.z.number().optional()
|
|
1631
|
-
})
|
|
2443
|
+
inputSchema: lazySchema9(() => zodSchema9(z10.object({}))),
|
|
2444
|
+
outputSchema: lazySchema9(() => zodSchema9(z10.object({})))
|
|
1632
2445
|
});
|
|
1633
2446
|
|
|
1634
2447
|
// src/google-tools.ts
|
|
@@ -1690,11 +2503,10 @@ var googleTools = {
|
|
|
1690
2503
|
*/
|
|
1691
2504
|
vertexRagStore
|
|
1692
2505
|
};
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
GoogleGenerativeAILanguageModel,
|
|
2506
|
+
export {
|
|
2507
|
+
GoogleLanguageModel,
|
|
1696
2508
|
getGroundingMetadataSchema,
|
|
1697
2509
|
getUrlContextMetadataSchema,
|
|
1698
2510
|
googleTools
|
|
1699
|
-
}
|
|
2511
|
+
};
|
|
1700
2512
|
//# sourceMappingURL=index.js.map
|