@ai-sdk/google 4.0.0-beta.3 → 4.0.0-beta.31
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 +209 -4
- package/README.md +2 -0
- package/dist/index.d.mts +73 -23
- package/dist/index.d.ts +73 -23
- package/dist/index.js +756 -136
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +767 -130
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +42 -15
- package/dist/internal/index.d.ts +42 -15
- package/dist/internal/index.js +499 -74
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +504 -72
- package/dist/internal/index.mjs.map +1 -1
- package/docs/15-google-generative-ai.mdx +36 -3
- package/package.json +3 -5
- package/src/convert-google-generative-ai-usage.ts +9 -2
- package/src/convert-to-google-generative-ai-messages.ts +330 -50
- package/src/google-generative-ai-embedding-model.ts +42 -13
- package/src/google-generative-ai-embedding-options.ts +24 -0
- package/src/google-generative-ai-files.ts +230 -0
- package/src/google-generative-ai-image-model.ts +14 -14
- package/src/google-generative-ai-language-model.ts +317 -44
- package/src/google-generative-ai-options.ts +5 -1
- package/src/google-generative-ai-prompt.ts +48 -4
- package/src/google-generative-ai-video-model.ts +7 -7
- package/src/google-prepare-tools.ts +64 -9
- package/src/google-provider.ts +31 -18
- package/src/index.ts +1 -0
- package/src/map-google-generative-ai-finish-reason.ts +2 -2
package/dist/internal/index.js
CHANGED
|
@@ -18,14 +18,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
|
|
20
20
|
// src/internal/index.ts
|
|
21
|
-
var
|
|
22
|
-
__export(
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
23
|
GoogleGenerativeAILanguageModel: () => GoogleGenerativeAILanguageModel,
|
|
24
24
|
getGroundingMetadataSchema: () => getGroundingMetadataSchema,
|
|
25
25
|
getUrlContextMetadataSchema: () => getUrlContextMetadataSchema,
|
|
26
26
|
googleTools: () => googleTools
|
|
27
27
|
});
|
|
28
|
-
module.exports = __toCommonJS(
|
|
28
|
+
module.exports = __toCommonJS(index_exports);
|
|
29
29
|
|
|
30
30
|
// src/google-generative-ai-language-model.ts
|
|
31
31
|
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
|
@@ -189,13 +189,118 @@ function isEmptyObjectSchema(jsonSchema) {
|
|
|
189
189
|
// src/convert-to-google-generative-ai-messages.ts
|
|
190
190
|
var import_provider = require("@ai-sdk/provider");
|
|
191
191
|
var import_provider_utils = require("@ai-sdk/provider-utils");
|
|
192
|
+
var dataUrlRegex = /^data:([^;,]+);base64,(.+)$/s;
|
|
193
|
+
function parseBase64DataUrl(value) {
|
|
194
|
+
const match = dataUrlRegex.exec(value);
|
|
195
|
+
if (match == null) {
|
|
196
|
+
return void 0;
|
|
197
|
+
}
|
|
198
|
+
return {
|
|
199
|
+
mediaType: match[1],
|
|
200
|
+
data: match[2]
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
function convertUrlToolResultPart(url) {
|
|
204
|
+
const parsedDataUrl = parseBase64DataUrl(url);
|
|
205
|
+
if (parsedDataUrl == null) {
|
|
206
|
+
return void 0;
|
|
207
|
+
}
|
|
208
|
+
return {
|
|
209
|
+
inlineData: {
|
|
210
|
+
mimeType: parsedDataUrl.mediaType,
|
|
211
|
+
data: parsedDataUrl.data
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
function appendToolResultParts(parts, toolName, outputValue) {
|
|
216
|
+
const functionResponseParts = [];
|
|
217
|
+
const responseTextParts = [];
|
|
218
|
+
for (const contentPart of outputValue) {
|
|
219
|
+
switch (contentPart.type) {
|
|
220
|
+
case "text": {
|
|
221
|
+
responseTextParts.push(contentPart.text);
|
|
222
|
+
break;
|
|
223
|
+
}
|
|
224
|
+
case "image-data":
|
|
225
|
+
case "file-data": {
|
|
226
|
+
functionResponseParts.push({
|
|
227
|
+
inlineData: {
|
|
228
|
+
mimeType: contentPart.mediaType,
|
|
229
|
+
data: contentPart.data
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
case "image-url":
|
|
235
|
+
case "file-url": {
|
|
236
|
+
const functionResponsePart = convertUrlToolResultPart(
|
|
237
|
+
contentPart.url
|
|
238
|
+
);
|
|
239
|
+
if (functionResponsePart != null) {
|
|
240
|
+
functionResponseParts.push(functionResponsePart);
|
|
241
|
+
} else {
|
|
242
|
+
responseTextParts.push(JSON.stringify(contentPart));
|
|
243
|
+
}
|
|
244
|
+
break;
|
|
245
|
+
}
|
|
246
|
+
default: {
|
|
247
|
+
responseTextParts.push(JSON.stringify(contentPart));
|
|
248
|
+
break;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
parts.push({
|
|
253
|
+
functionResponse: {
|
|
254
|
+
name: toolName,
|
|
255
|
+
response: {
|
|
256
|
+
name: toolName,
|
|
257
|
+
content: responseTextParts.length > 0 ? responseTextParts.join("\n") : "Tool executed successfully."
|
|
258
|
+
},
|
|
259
|
+
...functionResponseParts.length > 0 ? { parts: functionResponseParts } : {}
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
function appendLegacyToolResultParts(parts, toolName, outputValue) {
|
|
264
|
+
for (const contentPart of outputValue) {
|
|
265
|
+
switch (contentPart.type) {
|
|
266
|
+
case "text":
|
|
267
|
+
parts.push({
|
|
268
|
+
functionResponse: {
|
|
269
|
+
name: toolName,
|
|
270
|
+
response: {
|
|
271
|
+
name: toolName,
|
|
272
|
+
content: contentPart.text
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
break;
|
|
277
|
+
case "image-data":
|
|
278
|
+
parts.push(
|
|
279
|
+
{
|
|
280
|
+
inlineData: {
|
|
281
|
+
mimeType: String(contentPart.mediaType),
|
|
282
|
+
data: String(contentPart.data)
|
|
283
|
+
}
|
|
284
|
+
},
|
|
285
|
+
{
|
|
286
|
+
text: "Tool executed successfully and returned this image as a response"
|
|
287
|
+
}
|
|
288
|
+
);
|
|
289
|
+
break;
|
|
290
|
+
default:
|
|
291
|
+
parts.push({ text: JSON.stringify(contentPart) });
|
|
292
|
+
break;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
192
296
|
function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
193
|
-
var _a, _b, _c;
|
|
297
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
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
302
|
const providerOptionsName = (_b = options == null ? void 0 : options.providerOptionsName) != null ? _b : "google";
|
|
303
|
+
const supportsFunctionResponseParts = (_c = options == null ? void 0 : options.supportsFunctionResponseParts) != null ? _c : true;
|
|
199
304
|
for (const { role, content } of prompt) {
|
|
200
305
|
switch (role) {
|
|
201
306
|
case "system": {
|
|
@@ -218,19 +323,36 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
218
323
|
}
|
|
219
324
|
case "file": {
|
|
220
325
|
const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
|
|
221
|
-
|
|
222
|
-
|
|
326
|
+
if (part.data instanceof URL) {
|
|
327
|
+
parts.push({
|
|
223
328
|
fileData: {
|
|
224
329
|
mimeType: mediaType,
|
|
225
330
|
fileUri: part.data.toString()
|
|
226
331
|
}
|
|
227
|
-
}
|
|
332
|
+
});
|
|
333
|
+
} else if ((0, import_provider_utils.isProviderReference)(part.data)) {
|
|
334
|
+
if (providerOptionsName === "vertex") {
|
|
335
|
+
throw new import_provider.UnsupportedFunctionalityError({
|
|
336
|
+
functionality: "file parts with provider references"
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
parts.push({
|
|
340
|
+
fileData: {
|
|
341
|
+
mimeType: mediaType,
|
|
342
|
+
fileUri: (0, import_provider_utils.resolveProviderReference)({
|
|
343
|
+
reference: part.data,
|
|
344
|
+
provider: "google"
|
|
345
|
+
})
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
} else {
|
|
349
|
+
parts.push({
|
|
228
350
|
inlineData: {
|
|
229
351
|
mimeType: mediaType,
|
|
230
352
|
data: (0, import_provider_utils.convertToBase64)(part.data)
|
|
231
353
|
}
|
|
232
|
-
}
|
|
233
|
-
|
|
354
|
+
});
|
|
355
|
+
}
|
|
234
356
|
break;
|
|
235
357
|
}
|
|
236
358
|
}
|
|
@@ -243,8 +365,8 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
243
365
|
contents.push({
|
|
244
366
|
role: "model",
|
|
245
367
|
parts: content.map((part) => {
|
|
246
|
-
var _a2, _b2, _c2,
|
|
247
|
-
const providerOpts = (
|
|
368
|
+
var _a2, _b2, _c2, _d2;
|
|
369
|
+
const providerOpts = (_d2 = (_a2 = part.providerOptions) == null ? void 0 : _a2[providerOptionsName]) != null ? _d2 : providerOptionsName !== "google" ? (_b2 = part.providerOptions) == null ? void 0 : _b2.google : (_c2 = part.providerOptions) == null ? void 0 : _c2.vertex;
|
|
248
370
|
const thoughtSignature = (providerOpts == null ? void 0 : providerOpts.thoughtSignature) != null ? String(providerOpts.thoughtSignature) : void 0;
|
|
249
371
|
switch (part.type) {
|
|
250
372
|
case "text": {
|
|
@@ -260,21 +382,67 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
260
382
|
thoughtSignature
|
|
261
383
|
};
|
|
262
384
|
}
|
|
385
|
+
case "reasoning-file": {
|
|
386
|
+
if (part.data instanceof URL) {
|
|
387
|
+
throw new import_provider.UnsupportedFunctionalityError({
|
|
388
|
+
functionality: "File data URLs in assistant messages are not supported"
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
return {
|
|
392
|
+
inlineData: {
|
|
393
|
+
mimeType: part.mediaType,
|
|
394
|
+
data: (0, import_provider_utils.convertToBase64)(part.data)
|
|
395
|
+
},
|
|
396
|
+
thought: true,
|
|
397
|
+
thoughtSignature
|
|
398
|
+
};
|
|
399
|
+
}
|
|
263
400
|
case "file": {
|
|
264
401
|
if (part.data instanceof URL) {
|
|
265
402
|
throw new import_provider.UnsupportedFunctionalityError({
|
|
266
403
|
functionality: "File data URLs in assistant messages are not supported"
|
|
267
404
|
});
|
|
268
405
|
}
|
|
406
|
+
if ((0, import_provider_utils.isProviderReference)(part.data)) {
|
|
407
|
+
if (providerOptionsName === "vertex") {
|
|
408
|
+
throw new import_provider.UnsupportedFunctionalityError({
|
|
409
|
+
functionality: "file parts with provider references"
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
return {
|
|
413
|
+
fileData: {
|
|
414
|
+
mimeType: part.mediaType,
|
|
415
|
+
fileUri: (0, import_provider_utils.resolveProviderReference)({
|
|
416
|
+
reference: part.data,
|
|
417
|
+
provider: "google"
|
|
418
|
+
})
|
|
419
|
+
},
|
|
420
|
+
...(providerOpts == null ? void 0 : providerOpts.thought) === true ? { thought: true } : {},
|
|
421
|
+
thoughtSignature
|
|
422
|
+
};
|
|
423
|
+
}
|
|
269
424
|
return {
|
|
270
425
|
inlineData: {
|
|
271
426
|
mimeType: part.mediaType,
|
|
272
427
|
data: (0, import_provider_utils.convertToBase64)(part.data)
|
|
273
428
|
},
|
|
429
|
+
...(providerOpts == null ? void 0 : providerOpts.thought) === true ? { thought: true } : {},
|
|
274
430
|
thoughtSignature
|
|
275
431
|
};
|
|
276
432
|
}
|
|
277
433
|
case "tool-call": {
|
|
434
|
+
const serverToolCallId = (providerOpts == null ? void 0 : providerOpts.serverToolCallId) != null ? String(providerOpts.serverToolCallId) : void 0;
|
|
435
|
+
const serverToolType = (providerOpts == null ? void 0 : providerOpts.serverToolType) != null ? String(providerOpts.serverToolType) : void 0;
|
|
436
|
+
if (serverToolCallId && serverToolType) {
|
|
437
|
+
return {
|
|
438
|
+
toolCall: {
|
|
439
|
+
toolType: serverToolType,
|
|
440
|
+
args: typeof part.input === "string" ? JSON.parse(part.input) : part.input,
|
|
441
|
+
id: serverToolCallId
|
|
442
|
+
},
|
|
443
|
+
thoughtSignature
|
|
444
|
+
};
|
|
445
|
+
}
|
|
278
446
|
return {
|
|
279
447
|
functionCall: {
|
|
280
448
|
name: part.toolName,
|
|
@@ -283,6 +451,21 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
283
451
|
thoughtSignature
|
|
284
452
|
};
|
|
285
453
|
}
|
|
454
|
+
case "tool-result": {
|
|
455
|
+
const serverToolCallId = (providerOpts == null ? void 0 : providerOpts.serverToolCallId) != null ? String(providerOpts.serverToolCallId) : void 0;
|
|
456
|
+
const serverToolType = (providerOpts == null ? void 0 : providerOpts.serverToolType) != null ? String(providerOpts.serverToolType) : void 0;
|
|
457
|
+
if (serverToolCallId && serverToolType) {
|
|
458
|
+
return {
|
|
459
|
+
toolResponse: {
|
|
460
|
+
toolType: serverToolType,
|
|
461
|
+
response: part.output.type === "json" ? part.output.value : {},
|
|
462
|
+
id: serverToolCallId
|
|
463
|
+
},
|
|
464
|
+
thoughtSignature
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
return void 0;
|
|
468
|
+
}
|
|
286
469
|
}
|
|
287
470
|
}).filter((part) => part !== void 0)
|
|
288
471
|
});
|
|
@@ -295,38 +478,32 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
295
478
|
if (part.type === "tool-approval-response") {
|
|
296
479
|
continue;
|
|
297
480
|
}
|
|
481
|
+
const partProviderOpts = (_g = (_d = part.providerOptions) == null ? void 0 : _d[providerOptionsName]) != null ? _g : providerOptionsName !== "google" ? (_e = part.providerOptions) == null ? void 0 : _e.google : (_f = part.providerOptions) == null ? void 0 : _f.vertex;
|
|
482
|
+
const serverToolCallId = (partProviderOpts == null ? void 0 : partProviderOpts.serverToolCallId) != null ? String(partProviderOpts.serverToolCallId) : void 0;
|
|
483
|
+
const serverToolType = (partProviderOpts == null ? void 0 : partProviderOpts.serverToolType) != null ? String(partProviderOpts.serverToolType) : void 0;
|
|
484
|
+
if (serverToolCallId && serverToolType) {
|
|
485
|
+
const serverThoughtSignature = (partProviderOpts == null ? void 0 : partProviderOpts.thoughtSignature) != null ? String(partProviderOpts.thoughtSignature) : void 0;
|
|
486
|
+
if (contents.length > 0) {
|
|
487
|
+
const lastContent = contents[contents.length - 1];
|
|
488
|
+
if (lastContent.role === "model") {
|
|
489
|
+
lastContent.parts.push({
|
|
490
|
+
toolResponse: {
|
|
491
|
+
toolType: serverToolType,
|
|
492
|
+
response: part.output.type === "json" ? part.output.value : {},
|
|
493
|
+
id: serverToolCallId
|
|
494
|
+
},
|
|
495
|
+
thoughtSignature: serverThoughtSignature
|
|
496
|
+
});
|
|
497
|
+
continue;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
}
|
|
298
501
|
const output = part.output;
|
|
299
502
|
if (output.type === "content") {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
functionResponse: {
|
|
305
|
-
name: part.toolName,
|
|
306
|
-
response: {
|
|
307
|
-
name: part.toolName,
|
|
308
|
-
content: contentPart.text
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
});
|
|
312
|
-
break;
|
|
313
|
-
case "image-data":
|
|
314
|
-
parts.push(
|
|
315
|
-
{
|
|
316
|
-
inlineData: {
|
|
317
|
-
mimeType: contentPart.mediaType,
|
|
318
|
-
data: contentPart.data
|
|
319
|
-
}
|
|
320
|
-
},
|
|
321
|
-
{
|
|
322
|
-
text: "Tool executed successfully and returned this image as a response"
|
|
323
|
-
}
|
|
324
|
-
);
|
|
325
|
-
break;
|
|
326
|
-
default:
|
|
327
|
-
parts.push({ text: JSON.stringify(contentPart) });
|
|
328
|
-
break;
|
|
329
|
-
}
|
|
503
|
+
if (supportsFunctionResponseParts) {
|
|
504
|
+
appendToolResultParts(parts, part.toolName, output.value);
|
|
505
|
+
} else {
|
|
506
|
+
appendLegacyToolResultParts(parts, part.toolName, output.value);
|
|
330
507
|
}
|
|
331
508
|
} else {
|
|
332
509
|
parts.push({
|
|
@@ -334,7 +511,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
334
511
|
name: part.toolName,
|
|
335
512
|
response: {
|
|
336
513
|
name: part.toolName,
|
|
337
|
-
content: output.type === "execution-denied" ? (
|
|
514
|
+
content: output.type === "execution-denied" ? (_h = output.reason) != null ? _h : "Tool execution denied." : output.value
|
|
338
515
|
}
|
|
339
516
|
}
|
|
340
517
|
});
|
|
@@ -499,7 +676,11 @@ var googleLanguageModelOptions = (0, import_provider_utils3.lazySchema)(
|
|
|
499
676
|
latitude: import_v42.z.number(),
|
|
500
677
|
longitude: import_v42.z.number()
|
|
501
678
|
}).optional()
|
|
502
|
-
}).optional()
|
|
679
|
+
}).optional(),
|
|
680
|
+
/**
|
|
681
|
+
* Optional. The service tier to use for the request.
|
|
682
|
+
*/
|
|
683
|
+
serviceTier: import_v42.z.enum(["standard", "flex", "priority"]).optional()
|
|
503
684
|
})
|
|
504
685
|
)
|
|
505
686
|
);
|
|
@@ -511,7 +692,7 @@ function prepareTools({
|
|
|
511
692
|
toolChoice,
|
|
512
693
|
modelId
|
|
513
694
|
}) {
|
|
514
|
-
var _a;
|
|
695
|
+
var _a, _b;
|
|
515
696
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
516
697
|
const toolWarnings = [];
|
|
517
698
|
const isLatest = [
|
|
@@ -520,13 +701,14 @@ function prepareTools({
|
|
|
520
701
|
"gemini-pro-latest"
|
|
521
702
|
].some((id) => id === modelId);
|
|
522
703
|
const isGemini2orNewer = modelId.includes("gemini-2") || modelId.includes("gemini-3") || modelId.includes("nano-banana") || isLatest;
|
|
704
|
+
const isGemini3orNewer = modelId.includes("gemini-3");
|
|
523
705
|
const supportsFileSearch = modelId.includes("gemini-2.5") || modelId.includes("gemini-3");
|
|
524
706
|
if (tools == null) {
|
|
525
707
|
return { tools: void 0, toolConfig: void 0, toolWarnings };
|
|
526
708
|
}
|
|
527
709
|
const hasFunctionTools = tools.some((tool) => tool.type === "function");
|
|
528
710
|
const hasProviderTools = tools.some((tool) => tool.type === "provider");
|
|
529
|
-
if (hasFunctionTools && hasProviderTools) {
|
|
711
|
+
if (hasFunctionTools && hasProviderTools && !isGemini3orNewer) {
|
|
530
712
|
toolWarnings.push({
|
|
531
713
|
type: "unsupported",
|
|
532
714
|
feature: `combination of function and provider-defined tools`
|
|
@@ -577,7 +759,7 @@ function prepareTools({
|
|
|
577
759
|
toolWarnings.push({
|
|
578
760
|
type: "unsupported",
|
|
579
761
|
feature: `provider-defined tool ${tool.id}`,
|
|
580
|
-
details: "The code execution
|
|
762
|
+
details: "The code execution tool is not supported with other Gemini models than Gemini 2."
|
|
581
763
|
});
|
|
582
764
|
}
|
|
583
765
|
break;
|
|
@@ -631,6 +813,45 @@ function prepareTools({
|
|
|
631
813
|
break;
|
|
632
814
|
}
|
|
633
815
|
});
|
|
816
|
+
if (hasFunctionTools && isGemini3orNewer && googleTools2.length > 0) {
|
|
817
|
+
const functionDeclarations2 = [];
|
|
818
|
+
for (const tool of tools) {
|
|
819
|
+
if (tool.type === "function") {
|
|
820
|
+
functionDeclarations2.push({
|
|
821
|
+
name: tool.name,
|
|
822
|
+
description: (_a = tool.description) != null ? _a : "",
|
|
823
|
+
parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
|
|
824
|
+
});
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
const combinedToolConfig = {
|
|
828
|
+
functionCallingConfig: { mode: "VALIDATED" },
|
|
829
|
+
includeServerSideToolInvocations: true
|
|
830
|
+
};
|
|
831
|
+
if (toolChoice != null) {
|
|
832
|
+
switch (toolChoice.type) {
|
|
833
|
+
case "auto":
|
|
834
|
+
break;
|
|
835
|
+
case "none":
|
|
836
|
+
combinedToolConfig.functionCallingConfig = { mode: "NONE" };
|
|
837
|
+
break;
|
|
838
|
+
case "required":
|
|
839
|
+
combinedToolConfig.functionCallingConfig = { mode: "ANY" };
|
|
840
|
+
break;
|
|
841
|
+
case "tool":
|
|
842
|
+
combinedToolConfig.functionCallingConfig = {
|
|
843
|
+
mode: "ANY",
|
|
844
|
+
allowedFunctionNames: [toolChoice.toolName]
|
|
845
|
+
};
|
|
846
|
+
break;
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
return {
|
|
850
|
+
tools: [...googleTools2, { functionDeclarations: functionDeclarations2 }],
|
|
851
|
+
toolConfig: combinedToolConfig,
|
|
852
|
+
toolWarnings
|
|
853
|
+
};
|
|
854
|
+
}
|
|
634
855
|
return {
|
|
635
856
|
tools: googleTools2.length > 0 ? googleTools2 : void 0,
|
|
636
857
|
toolConfig: void 0,
|
|
@@ -644,7 +865,7 @@ function prepareTools({
|
|
|
644
865
|
case "function":
|
|
645
866
|
functionDeclarations.push({
|
|
646
867
|
name: tool.name,
|
|
647
|
-
description: (
|
|
868
|
+
description: (_b = tool.description) != null ? _b : "",
|
|
648
869
|
parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
|
|
649
870
|
});
|
|
650
871
|
if (tool.strict === true) {
|
|
@@ -743,7 +964,7 @@ function mapGoogleGenerativeAIFinishReason({
|
|
|
743
964
|
// src/google-generative-ai-language-model.ts
|
|
744
965
|
var GoogleGenerativeAILanguageModel = class {
|
|
745
966
|
constructor(modelId, config) {
|
|
746
|
-
this.specificationVersion = "
|
|
967
|
+
this.specificationVersion = "v4";
|
|
747
968
|
var _a;
|
|
748
969
|
this.modelId = modelId;
|
|
749
970
|
this.config = config;
|
|
@@ -769,6 +990,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
769
990
|
seed,
|
|
770
991
|
tools,
|
|
771
992
|
toolChoice,
|
|
993
|
+
reasoning,
|
|
772
994
|
providerOptions
|
|
773
995
|
}) {
|
|
774
996
|
var _a;
|
|
@@ -795,9 +1017,14 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
795
1017
|
});
|
|
796
1018
|
}
|
|
797
1019
|
const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
|
|
1020
|
+
const supportsFunctionResponseParts = this.modelId.startsWith("gemini-3");
|
|
798
1021
|
const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
|
|
799
1022
|
prompt,
|
|
800
|
-
{
|
|
1023
|
+
{
|
|
1024
|
+
isGemmaModel,
|
|
1025
|
+
providerOptionsName,
|
|
1026
|
+
supportsFunctionResponseParts
|
|
1027
|
+
}
|
|
801
1028
|
);
|
|
802
1029
|
const {
|
|
803
1030
|
tools: googleTools2,
|
|
@@ -808,6 +1035,12 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
808
1035
|
toolChoice,
|
|
809
1036
|
modelId: this.modelId
|
|
810
1037
|
});
|
|
1038
|
+
const resolvedThinking = resolveThinkingConfig({
|
|
1039
|
+
reasoning,
|
|
1040
|
+
modelId: this.modelId,
|
|
1041
|
+
warnings
|
|
1042
|
+
});
|
|
1043
|
+
const thinkingConfig = (googleOptions == null ? void 0 : googleOptions.thinkingConfig) || resolvedThinking ? { ...resolvedThinking, ...googleOptions == null ? void 0 : googleOptions.thinkingConfig } : void 0;
|
|
811
1044
|
return {
|
|
812
1045
|
args: {
|
|
813
1046
|
generationConfig: {
|
|
@@ -831,7 +1064,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
831
1064
|
},
|
|
832
1065
|
// provider options:
|
|
833
1066
|
responseModalities: googleOptions == null ? void 0 : googleOptions.responseModalities,
|
|
834
|
-
thinkingConfig
|
|
1067
|
+
thinkingConfig,
|
|
835
1068
|
...(googleOptions == null ? void 0 : googleOptions.mediaResolution) && {
|
|
836
1069
|
mediaResolution: googleOptions.mediaResolution
|
|
837
1070
|
},
|
|
@@ -848,14 +1081,15 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
848
1081
|
retrievalConfig: googleOptions.retrievalConfig
|
|
849
1082
|
} : googleToolConfig,
|
|
850
1083
|
cachedContent: googleOptions == null ? void 0 : googleOptions.cachedContent,
|
|
851
|
-
labels: googleOptions == null ? void 0 : googleOptions.labels
|
|
1084
|
+
labels: googleOptions == null ? void 0 : googleOptions.labels,
|
|
1085
|
+
serviceTier: googleOptions == null ? void 0 : googleOptions.serviceTier
|
|
852
1086
|
},
|
|
853
1087
|
warnings: [...warnings, ...toolWarnings],
|
|
854
1088
|
providerOptionsName
|
|
855
1089
|
};
|
|
856
1090
|
}
|
|
857
1091
|
async doGenerate(options) {
|
|
858
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
1092
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
859
1093
|
const { args, warnings, providerOptionsName } = await this.getArgs(options);
|
|
860
1094
|
const mergedHeaders = (0, import_provider_utils4.combineHeaders)(
|
|
861
1095
|
await (0, import_provider_utils4.resolve)(this.config.headers),
|
|
@@ -881,6 +1115,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
881
1115
|
const parts = (_b = (_a = candidate.content) == null ? void 0 : _a.parts) != null ? _b : [];
|
|
882
1116
|
const usageMetadata = response.usageMetadata;
|
|
883
1117
|
let lastCodeExecutionToolCallId;
|
|
1118
|
+
let lastServerToolCallId;
|
|
884
1119
|
for (const part of parts) {
|
|
885
1120
|
if ("executableCode" in part && ((_c = part.executableCode) == null ? void 0 : _c.code)) {
|
|
886
1121
|
const toolCallId = this.config.generateId();
|
|
@@ -935,22 +1170,68 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
935
1170
|
} : void 0
|
|
936
1171
|
});
|
|
937
1172
|
} else if ("inlineData" in part) {
|
|
1173
|
+
const hasThought = part.thought === true;
|
|
1174
|
+
const hasThoughtSignature = !!part.thoughtSignature;
|
|
938
1175
|
content.push({
|
|
939
|
-
type: "file",
|
|
1176
|
+
type: hasThought ? "reasoning-file" : "file",
|
|
940
1177
|
data: part.inlineData.data,
|
|
941
1178
|
mediaType: part.inlineData.mimeType,
|
|
942
|
-
providerMetadata:
|
|
1179
|
+
providerMetadata: hasThoughtSignature ? {
|
|
943
1180
|
[providerOptionsName]: {
|
|
944
1181
|
thoughtSignature: part.thoughtSignature
|
|
945
1182
|
}
|
|
946
1183
|
} : void 0
|
|
947
1184
|
});
|
|
1185
|
+
} else if ("toolCall" in part && part.toolCall) {
|
|
1186
|
+
const toolCallId = (_e = part.toolCall.id) != null ? _e : this.config.generateId();
|
|
1187
|
+
lastServerToolCallId = toolCallId;
|
|
1188
|
+
content.push({
|
|
1189
|
+
type: "tool-call",
|
|
1190
|
+
toolCallId,
|
|
1191
|
+
toolName: `server:${part.toolCall.toolType}`,
|
|
1192
|
+
input: JSON.stringify((_f = part.toolCall.args) != null ? _f : {}),
|
|
1193
|
+
providerExecuted: true,
|
|
1194
|
+
dynamic: true,
|
|
1195
|
+
providerMetadata: part.thoughtSignature ? {
|
|
1196
|
+
[providerOptionsName]: {
|
|
1197
|
+
thoughtSignature: part.thoughtSignature,
|
|
1198
|
+
serverToolCallId: toolCallId,
|
|
1199
|
+
serverToolType: part.toolCall.toolType
|
|
1200
|
+
}
|
|
1201
|
+
} : {
|
|
1202
|
+
[providerOptionsName]: {
|
|
1203
|
+
serverToolCallId: toolCallId,
|
|
1204
|
+
serverToolType: part.toolCall.toolType
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
});
|
|
1208
|
+
} else if ("toolResponse" in part && part.toolResponse) {
|
|
1209
|
+
const responseToolCallId = (_g = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _g : this.config.generateId();
|
|
1210
|
+
content.push({
|
|
1211
|
+
type: "tool-result",
|
|
1212
|
+
toolCallId: responseToolCallId,
|
|
1213
|
+
toolName: `server:${part.toolResponse.toolType}`,
|
|
1214
|
+
result: (_h = part.toolResponse.response) != null ? _h : {},
|
|
1215
|
+
providerMetadata: part.thoughtSignature ? {
|
|
1216
|
+
[providerOptionsName]: {
|
|
1217
|
+
thoughtSignature: part.thoughtSignature,
|
|
1218
|
+
serverToolCallId: responseToolCallId,
|
|
1219
|
+
serverToolType: part.toolResponse.toolType
|
|
1220
|
+
}
|
|
1221
|
+
} : {
|
|
1222
|
+
[providerOptionsName]: {
|
|
1223
|
+
serverToolCallId: responseToolCallId,
|
|
1224
|
+
serverToolType: part.toolResponse.toolType
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
});
|
|
1228
|
+
lastServerToolCallId = void 0;
|
|
948
1229
|
}
|
|
949
1230
|
}
|
|
950
|
-
const sources = (
|
|
1231
|
+
const sources = (_i = extractSources({
|
|
951
1232
|
groundingMetadata: candidate.groundingMetadata,
|
|
952
1233
|
generateId: this.config.generateId
|
|
953
|
-
})) != null ?
|
|
1234
|
+
})) != null ? _i : [];
|
|
954
1235
|
for (const source of sources) {
|
|
955
1236
|
content.push(source);
|
|
956
1237
|
}
|
|
@@ -964,17 +1245,19 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
964
1245
|
(part) => part.type === "tool-call" && !part.providerExecuted
|
|
965
1246
|
)
|
|
966
1247
|
}),
|
|
967
|
-
raw: (
|
|
1248
|
+
raw: (_j = candidate.finishReason) != null ? _j : void 0
|
|
968
1249
|
},
|
|
969
1250
|
usage: convertGoogleGenerativeAIUsage(usageMetadata),
|
|
970
1251
|
warnings,
|
|
971
1252
|
providerMetadata: {
|
|
972
1253
|
[providerOptionsName]: {
|
|
973
|
-
promptFeedback: (
|
|
974
|
-
groundingMetadata: (
|
|
975
|
-
urlContextMetadata: (
|
|
976
|
-
safetyRatings: (
|
|
977
|
-
usageMetadata: usageMetadata != null ? usageMetadata : null
|
|
1254
|
+
promptFeedback: (_k = response.promptFeedback) != null ? _k : null,
|
|
1255
|
+
groundingMetadata: (_l = candidate.groundingMetadata) != null ? _l : null,
|
|
1256
|
+
urlContextMetadata: (_m = candidate.urlContextMetadata) != null ? _m : null,
|
|
1257
|
+
safetyRatings: (_n = candidate.safetyRatings) != null ? _n : null,
|
|
1258
|
+
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
1259
|
+
finishMessage: (_o = candidate.finishMessage) != null ? _o : null,
|
|
1260
|
+
serviceTier: (_p = response.serviceTier) != null ? _p : null
|
|
978
1261
|
}
|
|
979
1262
|
},
|
|
980
1263
|
request: { body: args },
|
|
@@ -1010,6 +1293,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1010
1293
|
let providerMetadata = void 0;
|
|
1011
1294
|
let lastGroundingMetadata = null;
|
|
1012
1295
|
let lastUrlContextMetadata = null;
|
|
1296
|
+
let serviceTier = null;
|
|
1013
1297
|
const generateId2 = this.config.generateId;
|
|
1014
1298
|
let hasToolCalls = false;
|
|
1015
1299
|
let currentTextBlockId = null;
|
|
@@ -1017,6 +1301,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1017
1301
|
let blockCounter = 0;
|
|
1018
1302
|
const emittedSourceUrls = /* @__PURE__ */ new Set();
|
|
1019
1303
|
let lastCodeExecutionToolCallId;
|
|
1304
|
+
let lastServerToolCallId;
|
|
1020
1305
|
return {
|
|
1021
1306
|
stream: response.pipeThrough(
|
|
1022
1307
|
new TransformStream({
|
|
@@ -1024,7 +1309,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1024
1309
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1025
1310
|
},
|
|
1026
1311
|
transform(chunk, controller) {
|
|
1027
|
-
var _a, _b, _c, _d, _e, _f;
|
|
1312
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
1028
1313
|
if (options.includeRawChunks) {
|
|
1029
1314
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1030
1315
|
}
|
|
@@ -1037,6 +1322,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1037
1322
|
if (usageMetadata != null) {
|
|
1038
1323
|
usage = usageMetadata;
|
|
1039
1324
|
}
|
|
1325
|
+
if (value.serviceTier != null) {
|
|
1326
|
+
serviceTier = value.serviceTier;
|
|
1327
|
+
}
|
|
1040
1328
|
const candidate = (_a = value.candidates) == null ? void 0 : _a[0];
|
|
1041
1329
|
if (candidate == null) {
|
|
1042
1330
|
return;
|
|
@@ -1162,17 +1450,55 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1162
1450
|
});
|
|
1163
1451
|
currentReasoningBlockId = null;
|
|
1164
1452
|
}
|
|
1165
|
-
const
|
|
1453
|
+
const hasThought = part.thought === true;
|
|
1454
|
+
const hasThoughtSignature = !!part.thoughtSignature;
|
|
1455
|
+
const fileMeta = hasThoughtSignature ? {
|
|
1166
1456
|
[providerOptionsName]: {
|
|
1167
1457
|
thoughtSignature: part.thoughtSignature
|
|
1168
1458
|
}
|
|
1169
1459
|
} : void 0;
|
|
1170
1460
|
controller.enqueue({
|
|
1171
|
-
type: "file",
|
|
1461
|
+
type: hasThought ? "reasoning-file" : "file",
|
|
1172
1462
|
mediaType: part.inlineData.mimeType,
|
|
1173
1463
|
data: part.inlineData.data,
|
|
1174
|
-
providerMetadata:
|
|
1464
|
+
providerMetadata: fileMeta
|
|
1465
|
+
});
|
|
1466
|
+
} else if ("toolCall" in part && part.toolCall) {
|
|
1467
|
+
const toolCallId = (_e = part.toolCall.id) != null ? _e : generateId2();
|
|
1468
|
+
lastServerToolCallId = toolCallId;
|
|
1469
|
+
const serverMeta = {
|
|
1470
|
+
[providerOptionsName]: {
|
|
1471
|
+
...part.thoughtSignature ? { thoughtSignature: part.thoughtSignature } : {},
|
|
1472
|
+
serverToolCallId: toolCallId,
|
|
1473
|
+
serverToolType: part.toolCall.toolType
|
|
1474
|
+
}
|
|
1475
|
+
};
|
|
1476
|
+
controller.enqueue({
|
|
1477
|
+
type: "tool-call",
|
|
1478
|
+
toolCallId,
|
|
1479
|
+
toolName: `server:${part.toolCall.toolType}`,
|
|
1480
|
+
input: JSON.stringify((_f = part.toolCall.args) != null ? _f : {}),
|
|
1481
|
+
providerExecuted: true,
|
|
1482
|
+
dynamic: true,
|
|
1483
|
+
providerMetadata: serverMeta
|
|
1175
1484
|
});
|
|
1485
|
+
} else if ("toolResponse" in part && part.toolResponse) {
|
|
1486
|
+
const responseToolCallId = (_g = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _g : generateId2();
|
|
1487
|
+
const serverMeta = {
|
|
1488
|
+
[providerOptionsName]: {
|
|
1489
|
+
...part.thoughtSignature ? { thoughtSignature: part.thoughtSignature } : {},
|
|
1490
|
+
serverToolCallId: responseToolCallId,
|
|
1491
|
+
serverToolType: part.toolResponse.toolType
|
|
1492
|
+
}
|
|
1493
|
+
};
|
|
1494
|
+
controller.enqueue({
|
|
1495
|
+
type: "tool-result",
|
|
1496
|
+
toolCallId: responseToolCallId,
|
|
1497
|
+
toolName: `server:${part.toolResponse.toolType}`,
|
|
1498
|
+
result: (_h = part.toolResponse.response) != null ? _h : {},
|
|
1499
|
+
providerMetadata: serverMeta
|
|
1500
|
+
});
|
|
1501
|
+
lastServerToolCallId = void 0;
|
|
1176
1502
|
}
|
|
1177
1503
|
}
|
|
1178
1504
|
const toolCallDeltas = getToolCallsFromParts({
|
|
@@ -1220,15 +1546,15 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1220
1546
|
};
|
|
1221
1547
|
providerMetadata = {
|
|
1222
1548
|
[providerOptionsName]: {
|
|
1223
|
-
promptFeedback: (
|
|
1549
|
+
promptFeedback: (_i = value.promptFeedback) != null ? _i : null,
|
|
1224
1550
|
groundingMetadata: lastGroundingMetadata,
|
|
1225
1551
|
urlContextMetadata: lastUrlContextMetadata,
|
|
1226
|
-
safetyRatings: (
|
|
1552
|
+
safetyRatings: (_j = candidate.safetyRatings) != null ? _j : null,
|
|
1553
|
+
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
1554
|
+
finishMessage: (_k = candidate.finishMessage) != null ? _k : null,
|
|
1555
|
+
serviceTier
|
|
1227
1556
|
}
|
|
1228
1557
|
};
|
|
1229
|
-
if (usageMetadata != null) {
|
|
1230
|
-
providerMetadata[providerOptionsName].usageMetadata = usageMetadata;
|
|
1231
|
-
}
|
|
1232
1558
|
}
|
|
1233
1559
|
},
|
|
1234
1560
|
flush(controller) {
|
|
@@ -1258,6 +1584,75 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1258
1584
|
};
|
|
1259
1585
|
}
|
|
1260
1586
|
};
|
|
1587
|
+
function isGemini3Model(modelId) {
|
|
1588
|
+
return /gemini-3[\.\-]/i.test(modelId) || /gemini-3$/i.test(modelId);
|
|
1589
|
+
}
|
|
1590
|
+
function getMaxOutputTokensForGemini25Model() {
|
|
1591
|
+
return 65536;
|
|
1592
|
+
}
|
|
1593
|
+
function getMaxThinkingTokensForGemini25Model(modelId) {
|
|
1594
|
+
const id = modelId.toLowerCase();
|
|
1595
|
+
if (id.includes("2.5-pro") || id.includes("gemini-3-pro-image")) {
|
|
1596
|
+
return 32768;
|
|
1597
|
+
}
|
|
1598
|
+
return 24576;
|
|
1599
|
+
}
|
|
1600
|
+
function resolveThinkingConfig({
|
|
1601
|
+
reasoning,
|
|
1602
|
+
modelId,
|
|
1603
|
+
warnings
|
|
1604
|
+
}) {
|
|
1605
|
+
if (!(0, import_provider_utils4.isCustomReasoning)(reasoning)) {
|
|
1606
|
+
return void 0;
|
|
1607
|
+
}
|
|
1608
|
+
if (isGemini3Model(modelId) && !modelId.includes("gemini-3-pro-image")) {
|
|
1609
|
+
return resolveGemini3ThinkingConfig({ reasoning, warnings });
|
|
1610
|
+
}
|
|
1611
|
+
return resolveGemini25ThinkingConfig({ reasoning, modelId, warnings });
|
|
1612
|
+
}
|
|
1613
|
+
function resolveGemini3ThinkingConfig({
|
|
1614
|
+
reasoning,
|
|
1615
|
+
warnings
|
|
1616
|
+
}) {
|
|
1617
|
+
if (reasoning === "none") {
|
|
1618
|
+
return { thinkingLevel: "minimal" };
|
|
1619
|
+
}
|
|
1620
|
+
const thinkingLevel = (0, import_provider_utils4.mapReasoningToProviderEffort)({
|
|
1621
|
+
reasoning,
|
|
1622
|
+
effortMap: {
|
|
1623
|
+
minimal: "minimal",
|
|
1624
|
+
low: "low",
|
|
1625
|
+
medium: "medium",
|
|
1626
|
+
high: "high",
|
|
1627
|
+
xhigh: "high"
|
|
1628
|
+
},
|
|
1629
|
+
warnings
|
|
1630
|
+
});
|
|
1631
|
+
if (thinkingLevel == null) {
|
|
1632
|
+
return void 0;
|
|
1633
|
+
}
|
|
1634
|
+
return { thinkingLevel };
|
|
1635
|
+
}
|
|
1636
|
+
function resolveGemini25ThinkingConfig({
|
|
1637
|
+
reasoning,
|
|
1638
|
+
modelId,
|
|
1639
|
+
warnings
|
|
1640
|
+
}) {
|
|
1641
|
+
if (reasoning === "none") {
|
|
1642
|
+
return { thinkingBudget: 0 };
|
|
1643
|
+
}
|
|
1644
|
+
const thinkingBudget = (0, import_provider_utils4.mapReasoningToProviderBudget)({
|
|
1645
|
+
reasoning,
|
|
1646
|
+
maxOutputTokens: getMaxOutputTokensForGemini25Model(),
|
|
1647
|
+
maxReasoningBudget: getMaxThinkingTokensForGemini25Model(modelId),
|
|
1648
|
+
minReasoningBudget: 0,
|
|
1649
|
+
warnings
|
|
1650
|
+
});
|
|
1651
|
+
if (thinkingBudget == null) {
|
|
1652
|
+
return void 0;
|
|
1653
|
+
}
|
|
1654
|
+
return { thinkingBudget };
|
|
1655
|
+
}
|
|
1261
1656
|
function getToolCallsFromParts({
|
|
1262
1657
|
parts,
|
|
1263
1658
|
generateId: generateId2,
|
|
@@ -1437,6 +1832,23 @@ var getContentSchema = () => import_v43.z.object({
|
|
|
1437
1832
|
mimeType: import_v43.z.string(),
|
|
1438
1833
|
data: import_v43.z.string()
|
|
1439
1834
|
}),
|
|
1835
|
+
thought: import_v43.z.boolean().nullish(),
|
|
1836
|
+
thoughtSignature: import_v43.z.string().nullish()
|
|
1837
|
+
}),
|
|
1838
|
+
import_v43.z.object({
|
|
1839
|
+
toolCall: import_v43.z.object({
|
|
1840
|
+
toolType: import_v43.z.string(),
|
|
1841
|
+
args: import_v43.z.unknown().nullish(),
|
|
1842
|
+
id: import_v43.z.string()
|
|
1843
|
+
}),
|
|
1844
|
+
thoughtSignature: import_v43.z.string().nullish()
|
|
1845
|
+
}),
|
|
1846
|
+
import_v43.z.object({
|
|
1847
|
+
toolResponse: import_v43.z.object({
|
|
1848
|
+
toolType: import_v43.z.string(),
|
|
1849
|
+
response: import_v43.z.unknown().nullish(),
|
|
1850
|
+
id: import_v43.z.string()
|
|
1851
|
+
}),
|
|
1440
1852
|
thoughtSignature: import_v43.z.string().nullish()
|
|
1441
1853
|
}),
|
|
1442
1854
|
import_v43.z.object({
|
|
@@ -1463,6 +1875,12 @@ var getSafetyRatingSchema = () => import_v43.z.object({
|
|
|
1463
1875
|
severityScore: import_v43.z.number().nullish(),
|
|
1464
1876
|
blocked: import_v43.z.boolean().nullish()
|
|
1465
1877
|
});
|
|
1878
|
+
var tokenDetailsSchema = import_v43.z.array(
|
|
1879
|
+
import_v43.z.object({
|
|
1880
|
+
modality: import_v43.z.string(),
|
|
1881
|
+
tokenCount: import_v43.z.number()
|
|
1882
|
+
})
|
|
1883
|
+
).nullish();
|
|
1466
1884
|
var usageSchema = import_v43.z.object({
|
|
1467
1885
|
cachedContentTokenCount: import_v43.z.number().nullish(),
|
|
1468
1886
|
thoughtsTokenCount: import_v43.z.number().nullish(),
|
|
@@ -1470,7 +1888,10 @@ var usageSchema = import_v43.z.object({
|
|
|
1470
1888
|
candidatesTokenCount: import_v43.z.number().nullish(),
|
|
1471
1889
|
totalTokenCount: import_v43.z.number().nullish(),
|
|
1472
1890
|
// https://cloud.google.com/vertex-ai/generative-ai/docs/reference/rest/v1/GenerateContentResponse#TrafficType
|
|
1473
|
-
trafficType: import_v43.z.string().nullish()
|
|
1891
|
+
trafficType: import_v43.z.string().nullish(),
|
|
1892
|
+
// https://ai.google.dev/api/generate-content#Modality
|
|
1893
|
+
promptTokensDetails: tokenDetailsSchema,
|
|
1894
|
+
candidatesTokensDetails: tokenDetailsSchema
|
|
1474
1895
|
});
|
|
1475
1896
|
var getUrlContextMetadataSchema = () => import_v43.z.object({
|
|
1476
1897
|
urlMetadata: import_v43.z.array(
|
|
@@ -1487,6 +1908,7 @@ var responseSchema = (0, import_provider_utils4.lazySchema)(
|
|
|
1487
1908
|
import_v43.z.object({
|
|
1488
1909
|
content: getContentSchema().nullish().or(import_v43.z.object({}).strict()),
|
|
1489
1910
|
finishReason: import_v43.z.string().nullish(),
|
|
1911
|
+
finishMessage: import_v43.z.string().nullish(),
|
|
1490
1912
|
safetyRatings: import_v43.z.array(getSafetyRatingSchema()).nullish(),
|
|
1491
1913
|
groundingMetadata: getGroundingMetadataSchema().nullish(),
|
|
1492
1914
|
urlContextMetadata: getUrlContextMetadataSchema().nullish()
|
|
@@ -1496,7 +1918,8 @@ var responseSchema = (0, import_provider_utils4.lazySchema)(
|
|
|
1496
1918
|
promptFeedback: import_v43.z.object({
|
|
1497
1919
|
blockReason: import_v43.z.string().nullish(),
|
|
1498
1920
|
safetyRatings: import_v43.z.array(getSafetyRatingSchema()).nullish()
|
|
1499
|
-
}).nullish()
|
|
1921
|
+
}).nullish(),
|
|
1922
|
+
serviceTier: import_v43.z.string().nullish()
|
|
1500
1923
|
})
|
|
1501
1924
|
)
|
|
1502
1925
|
);
|
|
@@ -1507,6 +1930,7 @@ var chunkSchema = (0, import_provider_utils4.lazySchema)(
|
|
|
1507
1930
|
import_v43.z.object({
|
|
1508
1931
|
content: getContentSchema().nullish(),
|
|
1509
1932
|
finishReason: import_v43.z.string().nullish(),
|
|
1933
|
+
finishMessage: import_v43.z.string().nullish(),
|
|
1510
1934
|
safetyRatings: import_v43.z.array(getSafetyRatingSchema()).nullish(),
|
|
1511
1935
|
groundingMetadata: getGroundingMetadataSchema().nullish(),
|
|
1512
1936
|
urlContextMetadata: getUrlContextMetadataSchema().nullish()
|
|
@@ -1516,7 +1940,8 @@ var chunkSchema = (0, import_provider_utils4.lazySchema)(
|
|
|
1516
1940
|
promptFeedback: import_v43.z.object({
|
|
1517
1941
|
blockReason: import_v43.z.string().nullish(),
|
|
1518
1942
|
safetyRatings: import_v43.z.array(getSafetyRatingSchema()).nullish()
|
|
1519
|
-
}).nullish()
|
|
1943
|
+
}).nullish(),
|
|
1944
|
+
serviceTier: import_v43.z.string().nullish()
|
|
1520
1945
|
})
|
|
1521
1946
|
)
|
|
1522
1947
|
);
|