@ai-sdk/google 4.0.0-beta.3 → 4.0.0-beta.30
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 +201 -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.mjs
CHANGED
|
@@ -4,7 +4,10 @@ import {
|
|
|
4
4
|
createEventSourceResponseHandler,
|
|
5
5
|
createJsonResponseHandler,
|
|
6
6
|
generateId,
|
|
7
|
+
isCustomReasoning,
|
|
7
8
|
lazySchema as lazySchema3,
|
|
9
|
+
mapReasoningToProviderBudget,
|
|
10
|
+
mapReasoningToProviderEffort,
|
|
8
11
|
parseProviderOptions,
|
|
9
12
|
postJsonToApi,
|
|
10
13
|
resolve,
|
|
@@ -171,14 +174,123 @@ function isEmptyObjectSchema(jsonSchema) {
|
|
|
171
174
|
import {
|
|
172
175
|
UnsupportedFunctionalityError
|
|
173
176
|
} from "@ai-sdk/provider";
|
|
174
|
-
import {
|
|
177
|
+
import {
|
|
178
|
+
convertToBase64,
|
|
179
|
+
isProviderReference,
|
|
180
|
+
resolveProviderReference
|
|
181
|
+
} from "@ai-sdk/provider-utils";
|
|
182
|
+
var dataUrlRegex = /^data:([^;,]+);base64,(.+)$/s;
|
|
183
|
+
function parseBase64DataUrl(value) {
|
|
184
|
+
const match = dataUrlRegex.exec(value);
|
|
185
|
+
if (match == null) {
|
|
186
|
+
return void 0;
|
|
187
|
+
}
|
|
188
|
+
return {
|
|
189
|
+
mediaType: match[1],
|
|
190
|
+
data: match[2]
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
function convertUrlToolResultPart(url) {
|
|
194
|
+
const parsedDataUrl = parseBase64DataUrl(url);
|
|
195
|
+
if (parsedDataUrl == null) {
|
|
196
|
+
return void 0;
|
|
197
|
+
}
|
|
198
|
+
return {
|
|
199
|
+
inlineData: {
|
|
200
|
+
mimeType: parsedDataUrl.mediaType,
|
|
201
|
+
data: parsedDataUrl.data
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
function appendToolResultParts(parts, toolName, outputValue) {
|
|
206
|
+
const functionResponseParts = [];
|
|
207
|
+
const responseTextParts = [];
|
|
208
|
+
for (const contentPart of outputValue) {
|
|
209
|
+
switch (contentPart.type) {
|
|
210
|
+
case "text": {
|
|
211
|
+
responseTextParts.push(contentPart.text);
|
|
212
|
+
break;
|
|
213
|
+
}
|
|
214
|
+
case "image-data":
|
|
215
|
+
case "file-data": {
|
|
216
|
+
functionResponseParts.push({
|
|
217
|
+
inlineData: {
|
|
218
|
+
mimeType: contentPart.mediaType,
|
|
219
|
+
data: contentPart.data
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
break;
|
|
223
|
+
}
|
|
224
|
+
case "image-url":
|
|
225
|
+
case "file-url": {
|
|
226
|
+
const functionResponsePart = convertUrlToolResultPart(
|
|
227
|
+
contentPart.url
|
|
228
|
+
);
|
|
229
|
+
if (functionResponsePart != null) {
|
|
230
|
+
functionResponseParts.push(functionResponsePart);
|
|
231
|
+
} else {
|
|
232
|
+
responseTextParts.push(JSON.stringify(contentPart));
|
|
233
|
+
}
|
|
234
|
+
break;
|
|
235
|
+
}
|
|
236
|
+
default: {
|
|
237
|
+
responseTextParts.push(JSON.stringify(contentPart));
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
parts.push({
|
|
243
|
+
functionResponse: {
|
|
244
|
+
name: toolName,
|
|
245
|
+
response: {
|
|
246
|
+
name: toolName,
|
|
247
|
+
content: responseTextParts.length > 0 ? responseTextParts.join("\n") : "Tool executed successfully."
|
|
248
|
+
},
|
|
249
|
+
...functionResponseParts.length > 0 ? { parts: functionResponseParts } : {}
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
function appendLegacyToolResultParts(parts, toolName, outputValue) {
|
|
254
|
+
for (const contentPart of outputValue) {
|
|
255
|
+
switch (contentPart.type) {
|
|
256
|
+
case "text":
|
|
257
|
+
parts.push({
|
|
258
|
+
functionResponse: {
|
|
259
|
+
name: toolName,
|
|
260
|
+
response: {
|
|
261
|
+
name: toolName,
|
|
262
|
+
content: contentPart.text
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
break;
|
|
267
|
+
case "image-data":
|
|
268
|
+
parts.push(
|
|
269
|
+
{
|
|
270
|
+
inlineData: {
|
|
271
|
+
mimeType: String(contentPart.mediaType),
|
|
272
|
+
data: String(contentPart.data)
|
|
273
|
+
}
|
|
274
|
+
},
|
|
275
|
+
{
|
|
276
|
+
text: "Tool executed successfully and returned this image as a response"
|
|
277
|
+
}
|
|
278
|
+
);
|
|
279
|
+
break;
|
|
280
|
+
default:
|
|
281
|
+
parts.push({ text: JSON.stringify(contentPart) });
|
|
282
|
+
break;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
175
286
|
function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
176
|
-
var _a, _b, _c;
|
|
287
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
177
288
|
const systemInstructionParts = [];
|
|
178
289
|
const contents = [];
|
|
179
290
|
let systemMessagesAllowed = true;
|
|
180
291
|
const isGemmaModel = (_a = options == null ? void 0 : options.isGemmaModel) != null ? _a : false;
|
|
181
292
|
const providerOptionsName = (_b = options == null ? void 0 : options.providerOptionsName) != null ? _b : "google";
|
|
293
|
+
const supportsFunctionResponseParts = (_c = options == null ? void 0 : options.supportsFunctionResponseParts) != null ? _c : true;
|
|
182
294
|
for (const { role, content } of prompt) {
|
|
183
295
|
switch (role) {
|
|
184
296
|
case "system": {
|
|
@@ -201,19 +313,36 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
201
313
|
}
|
|
202
314
|
case "file": {
|
|
203
315
|
const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
|
|
204
|
-
|
|
205
|
-
|
|
316
|
+
if (part.data instanceof URL) {
|
|
317
|
+
parts.push({
|
|
206
318
|
fileData: {
|
|
207
319
|
mimeType: mediaType,
|
|
208
320
|
fileUri: part.data.toString()
|
|
209
321
|
}
|
|
210
|
-
}
|
|
322
|
+
});
|
|
323
|
+
} else if (isProviderReference(part.data)) {
|
|
324
|
+
if (providerOptionsName === "vertex") {
|
|
325
|
+
throw new UnsupportedFunctionalityError({
|
|
326
|
+
functionality: "file parts with provider references"
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
parts.push({
|
|
330
|
+
fileData: {
|
|
331
|
+
mimeType: mediaType,
|
|
332
|
+
fileUri: resolveProviderReference({
|
|
333
|
+
reference: part.data,
|
|
334
|
+
provider: "google"
|
|
335
|
+
})
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
} else {
|
|
339
|
+
parts.push({
|
|
211
340
|
inlineData: {
|
|
212
341
|
mimeType: mediaType,
|
|
213
342
|
data: convertToBase64(part.data)
|
|
214
343
|
}
|
|
215
|
-
}
|
|
216
|
-
|
|
344
|
+
});
|
|
345
|
+
}
|
|
217
346
|
break;
|
|
218
347
|
}
|
|
219
348
|
}
|
|
@@ -226,8 +355,8 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
226
355
|
contents.push({
|
|
227
356
|
role: "model",
|
|
228
357
|
parts: content.map((part) => {
|
|
229
|
-
var _a2, _b2, _c2,
|
|
230
|
-
const providerOpts = (
|
|
358
|
+
var _a2, _b2, _c2, _d2;
|
|
359
|
+
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;
|
|
231
360
|
const thoughtSignature = (providerOpts == null ? void 0 : providerOpts.thoughtSignature) != null ? String(providerOpts.thoughtSignature) : void 0;
|
|
232
361
|
switch (part.type) {
|
|
233
362
|
case "text": {
|
|
@@ -243,21 +372,67 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
243
372
|
thoughtSignature
|
|
244
373
|
};
|
|
245
374
|
}
|
|
375
|
+
case "reasoning-file": {
|
|
376
|
+
if (part.data instanceof URL) {
|
|
377
|
+
throw new UnsupportedFunctionalityError({
|
|
378
|
+
functionality: "File data URLs in assistant messages are not supported"
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
return {
|
|
382
|
+
inlineData: {
|
|
383
|
+
mimeType: part.mediaType,
|
|
384
|
+
data: convertToBase64(part.data)
|
|
385
|
+
},
|
|
386
|
+
thought: true,
|
|
387
|
+
thoughtSignature
|
|
388
|
+
};
|
|
389
|
+
}
|
|
246
390
|
case "file": {
|
|
247
391
|
if (part.data instanceof URL) {
|
|
248
392
|
throw new UnsupportedFunctionalityError({
|
|
249
393
|
functionality: "File data URLs in assistant messages are not supported"
|
|
250
394
|
});
|
|
251
395
|
}
|
|
396
|
+
if (isProviderReference(part.data)) {
|
|
397
|
+
if (providerOptionsName === "vertex") {
|
|
398
|
+
throw new UnsupportedFunctionalityError({
|
|
399
|
+
functionality: "file parts with provider references"
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
return {
|
|
403
|
+
fileData: {
|
|
404
|
+
mimeType: part.mediaType,
|
|
405
|
+
fileUri: resolveProviderReference({
|
|
406
|
+
reference: part.data,
|
|
407
|
+
provider: "google"
|
|
408
|
+
})
|
|
409
|
+
},
|
|
410
|
+
...(providerOpts == null ? void 0 : providerOpts.thought) === true ? { thought: true } : {},
|
|
411
|
+
thoughtSignature
|
|
412
|
+
};
|
|
413
|
+
}
|
|
252
414
|
return {
|
|
253
415
|
inlineData: {
|
|
254
416
|
mimeType: part.mediaType,
|
|
255
417
|
data: convertToBase64(part.data)
|
|
256
418
|
},
|
|
419
|
+
...(providerOpts == null ? void 0 : providerOpts.thought) === true ? { thought: true } : {},
|
|
257
420
|
thoughtSignature
|
|
258
421
|
};
|
|
259
422
|
}
|
|
260
423
|
case "tool-call": {
|
|
424
|
+
const serverToolCallId = (providerOpts == null ? void 0 : providerOpts.serverToolCallId) != null ? String(providerOpts.serverToolCallId) : void 0;
|
|
425
|
+
const serverToolType = (providerOpts == null ? void 0 : providerOpts.serverToolType) != null ? String(providerOpts.serverToolType) : void 0;
|
|
426
|
+
if (serverToolCallId && serverToolType) {
|
|
427
|
+
return {
|
|
428
|
+
toolCall: {
|
|
429
|
+
toolType: serverToolType,
|
|
430
|
+
args: typeof part.input === "string" ? JSON.parse(part.input) : part.input,
|
|
431
|
+
id: serverToolCallId
|
|
432
|
+
},
|
|
433
|
+
thoughtSignature
|
|
434
|
+
};
|
|
435
|
+
}
|
|
261
436
|
return {
|
|
262
437
|
functionCall: {
|
|
263
438
|
name: part.toolName,
|
|
@@ -266,6 +441,21 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
266
441
|
thoughtSignature
|
|
267
442
|
};
|
|
268
443
|
}
|
|
444
|
+
case "tool-result": {
|
|
445
|
+
const serverToolCallId = (providerOpts == null ? void 0 : providerOpts.serverToolCallId) != null ? String(providerOpts.serverToolCallId) : void 0;
|
|
446
|
+
const serverToolType = (providerOpts == null ? void 0 : providerOpts.serverToolType) != null ? String(providerOpts.serverToolType) : void 0;
|
|
447
|
+
if (serverToolCallId && serverToolType) {
|
|
448
|
+
return {
|
|
449
|
+
toolResponse: {
|
|
450
|
+
toolType: serverToolType,
|
|
451
|
+
response: part.output.type === "json" ? part.output.value : {},
|
|
452
|
+
id: serverToolCallId
|
|
453
|
+
},
|
|
454
|
+
thoughtSignature
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
return void 0;
|
|
458
|
+
}
|
|
269
459
|
}
|
|
270
460
|
}).filter((part) => part !== void 0)
|
|
271
461
|
});
|
|
@@ -278,38 +468,32 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
278
468
|
if (part.type === "tool-approval-response") {
|
|
279
469
|
continue;
|
|
280
470
|
}
|
|
471
|
+
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;
|
|
472
|
+
const serverToolCallId = (partProviderOpts == null ? void 0 : partProviderOpts.serverToolCallId) != null ? String(partProviderOpts.serverToolCallId) : void 0;
|
|
473
|
+
const serverToolType = (partProviderOpts == null ? void 0 : partProviderOpts.serverToolType) != null ? String(partProviderOpts.serverToolType) : void 0;
|
|
474
|
+
if (serverToolCallId && serverToolType) {
|
|
475
|
+
const serverThoughtSignature = (partProviderOpts == null ? void 0 : partProviderOpts.thoughtSignature) != null ? String(partProviderOpts.thoughtSignature) : void 0;
|
|
476
|
+
if (contents.length > 0) {
|
|
477
|
+
const lastContent = contents[contents.length - 1];
|
|
478
|
+
if (lastContent.role === "model") {
|
|
479
|
+
lastContent.parts.push({
|
|
480
|
+
toolResponse: {
|
|
481
|
+
toolType: serverToolType,
|
|
482
|
+
response: part.output.type === "json" ? part.output.value : {},
|
|
483
|
+
id: serverToolCallId
|
|
484
|
+
},
|
|
485
|
+
thoughtSignature: serverThoughtSignature
|
|
486
|
+
});
|
|
487
|
+
continue;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
}
|
|
281
491
|
const output = part.output;
|
|
282
492
|
if (output.type === "content") {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
functionResponse: {
|
|
288
|
-
name: part.toolName,
|
|
289
|
-
response: {
|
|
290
|
-
name: part.toolName,
|
|
291
|
-
content: contentPart.text
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
});
|
|
295
|
-
break;
|
|
296
|
-
case "image-data":
|
|
297
|
-
parts.push(
|
|
298
|
-
{
|
|
299
|
-
inlineData: {
|
|
300
|
-
mimeType: contentPart.mediaType,
|
|
301
|
-
data: contentPart.data
|
|
302
|
-
}
|
|
303
|
-
},
|
|
304
|
-
{
|
|
305
|
-
text: "Tool executed successfully and returned this image as a response"
|
|
306
|
-
}
|
|
307
|
-
);
|
|
308
|
-
break;
|
|
309
|
-
default:
|
|
310
|
-
parts.push({ text: JSON.stringify(contentPart) });
|
|
311
|
-
break;
|
|
312
|
-
}
|
|
493
|
+
if (supportsFunctionResponseParts) {
|
|
494
|
+
appendToolResultParts(parts, part.toolName, output.value);
|
|
495
|
+
} else {
|
|
496
|
+
appendLegacyToolResultParts(parts, part.toolName, output.value);
|
|
313
497
|
}
|
|
314
498
|
} else {
|
|
315
499
|
parts.push({
|
|
@@ -317,7 +501,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
317
501
|
name: part.toolName,
|
|
318
502
|
response: {
|
|
319
503
|
name: part.toolName,
|
|
320
|
-
content: output.type === "execution-denied" ? (
|
|
504
|
+
content: output.type === "execution-denied" ? (_h = output.reason) != null ? _h : "Tool execution denied." : output.value
|
|
321
505
|
}
|
|
322
506
|
}
|
|
323
507
|
});
|
|
@@ -486,7 +670,11 @@ var googleLanguageModelOptions = lazySchema2(
|
|
|
486
670
|
latitude: z2.number(),
|
|
487
671
|
longitude: z2.number()
|
|
488
672
|
}).optional()
|
|
489
|
-
}).optional()
|
|
673
|
+
}).optional(),
|
|
674
|
+
/**
|
|
675
|
+
* Optional. The service tier to use for the request.
|
|
676
|
+
*/
|
|
677
|
+
serviceTier: z2.enum(["standard", "flex", "priority"]).optional()
|
|
490
678
|
})
|
|
491
679
|
)
|
|
492
680
|
);
|
|
@@ -500,7 +688,7 @@ function prepareTools({
|
|
|
500
688
|
toolChoice,
|
|
501
689
|
modelId
|
|
502
690
|
}) {
|
|
503
|
-
var _a;
|
|
691
|
+
var _a, _b;
|
|
504
692
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
505
693
|
const toolWarnings = [];
|
|
506
694
|
const isLatest = [
|
|
@@ -509,13 +697,14 @@ function prepareTools({
|
|
|
509
697
|
"gemini-pro-latest"
|
|
510
698
|
].some((id) => id === modelId);
|
|
511
699
|
const isGemini2orNewer = modelId.includes("gemini-2") || modelId.includes("gemini-3") || modelId.includes("nano-banana") || isLatest;
|
|
700
|
+
const isGemini3orNewer = modelId.includes("gemini-3");
|
|
512
701
|
const supportsFileSearch = modelId.includes("gemini-2.5") || modelId.includes("gemini-3");
|
|
513
702
|
if (tools == null) {
|
|
514
703
|
return { tools: void 0, toolConfig: void 0, toolWarnings };
|
|
515
704
|
}
|
|
516
705
|
const hasFunctionTools = tools.some((tool) => tool.type === "function");
|
|
517
706
|
const hasProviderTools = tools.some((tool) => tool.type === "provider");
|
|
518
|
-
if (hasFunctionTools && hasProviderTools) {
|
|
707
|
+
if (hasFunctionTools && hasProviderTools && !isGemini3orNewer) {
|
|
519
708
|
toolWarnings.push({
|
|
520
709
|
type: "unsupported",
|
|
521
710
|
feature: `combination of function and provider-defined tools`
|
|
@@ -566,7 +755,7 @@ function prepareTools({
|
|
|
566
755
|
toolWarnings.push({
|
|
567
756
|
type: "unsupported",
|
|
568
757
|
feature: `provider-defined tool ${tool.id}`,
|
|
569
|
-
details: "The code execution
|
|
758
|
+
details: "The code execution tool is not supported with other Gemini models than Gemini 2."
|
|
570
759
|
});
|
|
571
760
|
}
|
|
572
761
|
break;
|
|
@@ -620,6 +809,45 @@ function prepareTools({
|
|
|
620
809
|
break;
|
|
621
810
|
}
|
|
622
811
|
});
|
|
812
|
+
if (hasFunctionTools && isGemini3orNewer && googleTools2.length > 0) {
|
|
813
|
+
const functionDeclarations2 = [];
|
|
814
|
+
for (const tool of tools) {
|
|
815
|
+
if (tool.type === "function") {
|
|
816
|
+
functionDeclarations2.push({
|
|
817
|
+
name: tool.name,
|
|
818
|
+
description: (_a = tool.description) != null ? _a : "",
|
|
819
|
+
parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
|
|
820
|
+
});
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
const combinedToolConfig = {
|
|
824
|
+
functionCallingConfig: { mode: "VALIDATED" },
|
|
825
|
+
includeServerSideToolInvocations: true
|
|
826
|
+
};
|
|
827
|
+
if (toolChoice != null) {
|
|
828
|
+
switch (toolChoice.type) {
|
|
829
|
+
case "auto":
|
|
830
|
+
break;
|
|
831
|
+
case "none":
|
|
832
|
+
combinedToolConfig.functionCallingConfig = { mode: "NONE" };
|
|
833
|
+
break;
|
|
834
|
+
case "required":
|
|
835
|
+
combinedToolConfig.functionCallingConfig = { mode: "ANY" };
|
|
836
|
+
break;
|
|
837
|
+
case "tool":
|
|
838
|
+
combinedToolConfig.functionCallingConfig = {
|
|
839
|
+
mode: "ANY",
|
|
840
|
+
allowedFunctionNames: [toolChoice.toolName]
|
|
841
|
+
};
|
|
842
|
+
break;
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
return {
|
|
846
|
+
tools: [...googleTools2, { functionDeclarations: functionDeclarations2 }],
|
|
847
|
+
toolConfig: combinedToolConfig,
|
|
848
|
+
toolWarnings
|
|
849
|
+
};
|
|
850
|
+
}
|
|
623
851
|
return {
|
|
624
852
|
tools: googleTools2.length > 0 ? googleTools2 : void 0,
|
|
625
853
|
toolConfig: void 0,
|
|
@@ -633,7 +861,7 @@ function prepareTools({
|
|
|
633
861
|
case "function":
|
|
634
862
|
functionDeclarations.push({
|
|
635
863
|
name: tool.name,
|
|
636
|
-
description: (
|
|
864
|
+
description: (_b = tool.description) != null ? _b : "",
|
|
637
865
|
parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
|
|
638
866
|
});
|
|
639
867
|
if (tool.strict === true) {
|
|
@@ -732,7 +960,7 @@ function mapGoogleGenerativeAIFinishReason({
|
|
|
732
960
|
// src/google-generative-ai-language-model.ts
|
|
733
961
|
var GoogleGenerativeAILanguageModel = class {
|
|
734
962
|
constructor(modelId, config) {
|
|
735
|
-
this.specificationVersion = "
|
|
963
|
+
this.specificationVersion = "v4";
|
|
736
964
|
var _a;
|
|
737
965
|
this.modelId = modelId;
|
|
738
966
|
this.config = config;
|
|
@@ -758,6 +986,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
758
986
|
seed,
|
|
759
987
|
tools,
|
|
760
988
|
toolChoice,
|
|
989
|
+
reasoning,
|
|
761
990
|
providerOptions
|
|
762
991
|
}) {
|
|
763
992
|
var _a;
|
|
@@ -784,9 +1013,14 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
784
1013
|
});
|
|
785
1014
|
}
|
|
786
1015
|
const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
|
|
1016
|
+
const supportsFunctionResponseParts = this.modelId.startsWith("gemini-3");
|
|
787
1017
|
const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
|
|
788
1018
|
prompt,
|
|
789
|
-
{
|
|
1019
|
+
{
|
|
1020
|
+
isGemmaModel,
|
|
1021
|
+
providerOptionsName,
|
|
1022
|
+
supportsFunctionResponseParts
|
|
1023
|
+
}
|
|
790
1024
|
);
|
|
791
1025
|
const {
|
|
792
1026
|
tools: googleTools2,
|
|
@@ -797,6 +1031,12 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
797
1031
|
toolChoice,
|
|
798
1032
|
modelId: this.modelId
|
|
799
1033
|
});
|
|
1034
|
+
const resolvedThinking = resolveThinkingConfig({
|
|
1035
|
+
reasoning,
|
|
1036
|
+
modelId: this.modelId,
|
|
1037
|
+
warnings
|
|
1038
|
+
});
|
|
1039
|
+
const thinkingConfig = (googleOptions == null ? void 0 : googleOptions.thinkingConfig) || resolvedThinking ? { ...resolvedThinking, ...googleOptions == null ? void 0 : googleOptions.thinkingConfig } : void 0;
|
|
800
1040
|
return {
|
|
801
1041
|
args: {
|
|
802
1042
|
generationConfig: {
|
|
@@ -820,7 +1060,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
820
1060
|
},
|
|
821
1061
|
// provider options:
|
|
822
1062
|
responseModalities: googleOptions == null ? void 0 : googleOptions.responseModalities,
|
|
823
|
-
thinkingConfig
|
|
1063
|
+
thinkingConfig,
|
|
824
1064
|
...(googleOptions == null ? void 0 : googleOptions.mediaResolution) && {
|
|
825
1065
|
mediaResolution: googleOptions.mediaResolution
|
|
826
1066
|
},
|
|
@@ -837,14 +1077,15 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
837
1077
|
retrievalConfig: googleOptions.retrievalConfig
|
|
838
1078
|
} : googleToolConfig,
|
|
839
1079
|
cachedContent: googleOptions == null ? void 0 : googleOptions.cachedContent,
|
|
840
|
-
labels: googleOptions == null ? void 0 : googleOptions.labels
|
|
1080
|
+
labels: googleOptions == null ? void 0 : googleOptions.labels,
|
|
1081
|
+
serviceTier: googleOptions == null ? void 0 : googleOptions.serviceTier
|
|
841
1082
|
},
|
|
842
1083
|
warnings: [...warnings, ...toolWarnings],
|
|
843
1084
|
providerOptionsName
|
|
844
1085
|
};
|
|
845
1086
|
}
|
|
846
1087
|
async doGenerate(options) {
|
|
847
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
1088
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
848
1089
|
const { args, warnings, providerOptionsName } = await this.getArgs(options);
|
|
849
1090
|
const mergedHeaders = combineHeaders(
|
|
850
1091
|
await resolve(this.config.headers),
|
|
@@ -870,6 +1111,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
870
1111
|
const parts = (_b = (_a = candidate.content) == null ? void 0 : _a.parts) != null ? _b : [];
|
|
871
1112
|
const usageMetadata = response.usageMetadata;
|
|
872
1113
|
let lastCodeExecutionToolCallId;
|
|
1114
|
+
let lastServerToolCallId;
|
|
873
1115
|
for (const part of parts) {
|
|
874
1116
|
if ("executableCode" in part && ((_c = part.executableCode) == null ? void 0 : _c.code)) {
|
|
875
1117
|
const toolCallId = this.config.generateId();
|
|
@@ -924,22 +1166,68 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
924
1166
|
} : void 0
|
|
925
1167
|
});
|
|
926
1168
|
} else if ("inlineData" in part) {
|
|
1169
|
+
const hasThought = part.thought === true;
|
|
1170
|
+
const hasThoughtSignature = !!part.thoughtSignature;
|
|
927
1171
|
content.push({
|
|
928
|
-
type: "file",
|
|
1172
|
+
type: hasThought ? "reasoning-file" : "file",
|
|
929
1173
|
data: part.inlineData.data,
|
|
930
1174
|
mediaType: part.inlineData.mimeType,
|
|
931
|
-
providerMetadata:
|
|
1175
|
+
providerMetadata: hasThoughtSignature ? {
|
|
932
1176
|
[providerOptionsName]: {
|
|
933
1177
|
thoughtSignature: part.thoughtSignature
|
|
934
1178
|
}
|
|
935
1179
|
} : void 0
|
|
936
1180
|
});
|
|
1181
|
+
} else if ("toolCall" in part && part.toolCall) {
|
|
1182
|
+
const toolCallId = (_e = part.toolCall.id) != null ? _e : this.config.generateId();
|
|
1183
|
+
lastServerToolCallId = toolCallId;
|
|
1184
|
+
content.push({
|
|
1185
|
+
type: "tool-call",
|
|
1186
|
+
toolCallId,
|
|
1187
|
+
toolName: `server:${part.toolCall.toolType}`,
|
|
1188
|
+
input: JSON.stringify((_f = part.toolCall.args) != null ? _f : {}),
|
|
1189
|
+
providerExecuted: true,
|
|
1190
|
+
dynamic: true,
|
|
1191
|
+
providerMetadata: part.thoughtSignature ? {
|
|
1192
|
+
[providerOptionsName]: {
|
|
1193
|
+
thoughtSignature: part.thoughtSignature,
|
|
1194
|
+
serverToolCallId: toolCallId,
|
|
1195
|
+
serverToolType: part.toolCall.toolType
|
|
1196
|
+
}
|
|
1197
|
+
} : {
|
|
1198
|
+
[providerOptionsName]: {
|
|
1199
|
+
serverToolCallId: toolCallId,
|
|
1200
|
+
serverToolType: part.toolCall.toolType
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
});
|
|
1204
|
+
} else if ("toolResponse" in part && part.toolResponse) {
|
|
1205
|
+
const responseToolCallId = (_g = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _g : this.config.generateId();
|
|
1206
|
+
content.push({
|
|
1207
|
+
type: "tool-result",
|
|
1208
|
+
toolCallId: responseToolCallId,
|
|
1209
|
+
toolName: `server:${part.toolResponse.toolType}`,
|
|
1210
|
+
result: (_h = part.toolResponse.response) != null ? _h : {},
|
|
1211
|
+
providerMetadata: part.thoughtSignature ? {
|
|
1212
|
+
[providerOptionsName]: {
|
|
1213
|
+
thoughtSignature: part.thoughtSignature,
|
|
1214
|
+
serverToolCallId: responseToolCallId,
|
|
1215
|
+
serverToolType: part.toolResponse.toolType
|
|
1216
|
+
}
|
|
1217
|
+
} : {
|
|
1218
|
+
[providerOptionsName]: {
|
|
1219
|
+
serverToolCallId: responseToolCallId,
|
|
1220
|
+
serverToolType: part.toolResponse.toolType
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1223
|
+
});
|
|
1224
|
+
lastServerToolCallId = void 0;
|
|
937
1225
|
}
|
|
938
1226
|
}
|
|
939
|
-
const sources = (
|
|
1227
|
+
const sources = (_i = extractSources({
|
|
940
1228
|
groundingMetadata: candidate.groundingMetadata,
|
|
941
1229
|
generateId: this.config.generateId
|
|
942
|
-
})) != null ?
|
|
1230
|
+
})) != null ? _i : [];
|
|
943
1231
|
for (const source of sources) {
|
|
944
1232
|
content.push(source);
|
|
945
1233
|
}
|
|
@@ -953,17 +1241,19 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
953
1241
|
(part) => part.type === "tool-call" && !part.providerExecuted
|
|
954
1242
|
)
|
|
955
1243
|
}),
|
|
956
|
-
raw: (
|
|
1244
|
+
raw: (_j = candidate.finishReason) != null ? _j : void 0
|
|
957
1245
|
},
|
|
958
1246
|
usage: convertGoogleGenerativeAIUsage(usageMetadata),
|
|
959
1247
|
warnings,
|
|
960
1248
|
providerMetadata: {
|
|
961
1249
|
[providerOptionsName]: {
|
|
962
|
-
promptFeedback: (
|
|
963
|
-
groundingMetadata: (
|
|
964
|
-
urlContextMetadata: (
|
|
965
|
-
safetyRatings: (
|
|
966
|
-
usageMetadata: usageMetadata != null ? usageMetadata : null
|
|
1250
|
+
promptFeedback: (_k = response.promptFeedback) != null ? _k : null,
|
|
1251
|
+
groundingMetadata: (_l = candidate.groundingMetadata) != null ? _l : null,
|
|
1252
|
+
urlContextMetadata: (_m = candidate.urlContextMetadata) != null ? _m : null,
|
|
1253
|
+
safetyRatings: (_n = candidate.safetyRatings) != null ? _n : null,
|
|
1254
|
+
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
1255
|
+
finishMessage: (_o = candidate.finishMessage) != null ? _o : null,
|
|
1256
|
+
serviceTier: (_p = response.serviceTier) != null ? _p : null
|
|
967
1257
|
}
|
|
968
1258
|
},
|
|
969
1259
|
request: { body: args },
|
|
@@ -999,6 +1289,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
999
1289
|
let providerMetadata = void 0;
|
|
1000
1290
|
let lastGroundingMetadata = null;
|
|
1001
1291
|
let lastUrlContextMetadata = null;
|
|
1292
|
+
let serviceTier = null;
|
|
1002
1293
|
const generateId2 = this.config.generateId;
|
|
1003
1294
|
let hasToolCalls = false;
|
|
1004
1295
|
let currentTextBlockId = null;
|
|
@@ -1006,6 +1297,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1006
1297
|
let blockCounter = 0;
|
|
1007
1298
|
const emittedSourceUrls = /* @__PURE__ */ new Set();
|
|
1008
1299
|
let lastCodeExecutionToolCallId;
|
|
1300
|
+
let lastServerToolCallId;
|
|
1009
1301
|
return {
|
|
1010
1302
|
stream: response.pipeThrough(
|
|
1011
1303
|
new TransformStream({
|
|
@@ -1013,7 +1305,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1013
1305
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1014
1306
|
},
|
|
1015
1307
|
transform(chunk, controller) {
|
|
1016
|
-
var _a, _b, _c, _d, _e, _f;
|
|
1308
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
1017
1309
|
if (options.includeRawChunks) {
|
|
1018
1310
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1019
1311
|
}
|
|
@@ -1026,6 +1318,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1026
1318
|
if (usageMetadata != null) {
|
|
1027
1319
|
usage = usageMetadata;
|
|
1028
1320
|
}
|
|
1321
|
+
if (value.serviceTier != null) {
|
|
1322
|
+
serviceTier = value.serviceTier;
|
|
1323
|
+
}
|
|
1029
1324
|
const candidate = (_a = value.candidates) == null ? void 0 : _a[0];
|
|
1030
1325
|
if (candidate == null) {
|
|
1031
1326
|
return;
|
|
@@ -1151,17 +1446,55 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1151
1446
|
});
|
|
1152
1447
|
currentReasoningBlockId = null;
|
|
1153
1448
|
}
|
|
1154
|
-
const
|
|
1449
|
+
const hasThought = part.thought === true;
|
|
1450
|
+
const hasThoughtSignature = !!part.thoughtSignature;
|
|
1451
|
+
const fileMeta = hasThoughtSignature ? {
|
|
1155
1452
|
[providerOptionsName]: {
|
|
1156
1453
|
thoughtSignature: part.thoughtSignature
|
|
1157
1454
|
}
|
|
1158
1455
|
} : void 0;
|
|
1159
1456
|
controller.enqueue({
|
|
1160
|
-
type: "file",
|
|
1457
|
+
type: hasThought ? "reasoning-file" : "file",
|
|
1161
1458
|
mediaType: part.inlineData.mimeType,
|
|
1162
1459
|
data: part.inlineData.data,
|
|
1163
|
-
providerMetadata:
|
|
1460
|
+
providerMetadata: fileMeta
|
|
1164
1461
|
});
|
|
1462
|
+
} else if ("toolCall" in part && part.toolCall) {
|
|
1463
|
+
const toolCallId = (_e = part.toolCall.id) != null ? _e : generateId2();
|
|
1464
|
+
lastServerToolCallId = toolCallId;
|
|
1465
|
+
const serverMeta = {
|
|
1466
|
+
[providerOptionsName]: {
|
|
1467
|
+
...part.thoughtSignature ? { thoughtSignature: part.thoughtSignature } : {},
|
|
1468
|
+
serverToolCallId: toolCallId,
|
|
1469
|
+
serverToolType: part.toolCall.toolType
|
|
1470
|
+
}
|
|
1471
|
+
};
|
|
1472
|
+
controller.enqueue({
|
|
1473
|
+
type: "tool-call",
|
|
1474
|
+
toolCallId,
|
|
1475
|
+
toolName: `server:${part.toolCall.toolType}`,
|
|
1476
|
+
input: JSON.stringify((_f = part.toolCall.args) != null ? _f : {}),
|
|
1477
|
+
providerExecuted: true,
|
|
1478
|
+
dynamic: true,
|
|
1479
|
+
providerMetadata: serverMeta
|
|
1480
|
+
});
|
|
1481
|
+
} else if ("toolResponse" in part && part.toolResponse) {
|
|
1482
|
+
const responseToolCallId = (_g = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _g : generateId2();
|
|
1483
|
+
const serverMeta = {
|
|
1484
|
+
[providerOptionsName]: {
|
|
1485
|
+
...part.thoughtSignature ? { thoughtSignature: part.thoughtSignature } : {},
|
|
1486
|
+
serverToolCallId: responseToolCallId,
|
|
1487
|
+
serverToolType: part.toolResponse.toolType
|
|
1488
|
+
}
|
|
1489
|
+
};
|
|
1490
|
+
controller.enqueue({
|
|
1491
|
+
type: "tool-result",
|
|
1492
|
+
toolCallId: responseToolCallId,
|
|
1493
|
+
toolName: `server:${part.toolResponse.toolType}`,
|
|
1494
|
+
result: (_h = part.toolResponse.response) != null ? _h : {},
|
|
1495
|
+
providerMetadata: serverMeta
|
|
1496
|
+
});
|
|
1497
|
+
lastServerToolCallId = void 0;
|
|
1165
1498
|
}
|
|
1166
1499
|
}
|
|
1167
1500
|
const toolCallDeltas = getToolCallsFromParts({
|
|
@@ -1209,15 +1542,15 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1209
1542
|
};
|
|
1210
1543
|
providerMetadata = {
|
|
1211
1544
|
[providerOptionsName]: {
|
|
1212
|
-
promptFeedback: (
|
|
1545
|
+
promptFeedback: (_i = value.promptFeedback) != null ? _i : null,
|
|
1213
1546
|
groundingMetadata: lastGroundingMetadata,
|
|
1214
1547
|
urlContextMetadata: lastUrlContextMetadata,
|
|
1215
|
-
safetyRatings: (
|
|
1548
|
+
safetyRatings: (_j = candidate.safetyRatings) != null ? _j : null,
|
|
1549
|
+
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
1550
|
+
finishMessage: (_k = candidate.finishMessage) != null ? _k : null,
|
|
1551
|
+
serviceTier
|
|
1216
1552
|
}
|
|
1217
1553
|
};
|
|
1218
|
-
if (usageMetadata != null) {
|
|
1219
|
-
providerMetadata[providerOptionsName].usageMetadata = usageMetadata;
|
|
1220
|
-
}
|
|
1221
1554
|
}
|
|
1222
1555
|
},
|
|
1223
1556
|
flush(controller) {
|
|
@@ -1247,6 +1580,75 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1247
1580
|
};
|
|
1248
1581
|
}
|
|
1249
1582
|
};
|
|
1583
|
+
function isGemini3Model(modelId) {
|
|
1584
|
+
return /gemini-3[\.\-]/i.test(modelId) || /gemini-3$/i.test(modelId);
|
|
1585
|
+
}
|
|
1586
|
+
function getMaxOutputTokensForGemini25Model() {
|
|
1587
|
+
return 65536;
|
|
1588
|
+
}
|
|
1589
|
+
function getMaxThinkingTokensForGemini25Model(modelId) {
|
|
1590
|
+
const id = modelId.toLowerCase();
|
|
1591
|
+
if (id.includes("2.5-pro") || id.includes("gemini-3-pro-image")) {
|
|
1592
|
+
return 32768;
|
|
1593
|
+
}
|
|
1594
|
+
return 24576;
|
|
1595
|
+
}
|
|
1596
|
+
function resolveThinkingConfig({
|
|
1597
|
+
reasoning,
|
|
1598
|
+
modelId,
|
|
1599
|
+
warnings
|
|
1600
|
+
}) {
|
|
1601
|
+
if (!isCustomReasoning(reasoning)) {
|
|
1602
|
+
return void 0;
|
|
1603
|
+
}
|
|
1604
|
+
if (isGemini3Model(modelId) && !modelId.includes("gemini-3-pro-image")) {
|
|
1605
|
+
return resolveGemini3ThinkingConfig({ reasoning, warnings });
|
|
1606
|
+
}
|
|
1607
|
+
return resolveGemini25ThinkingConfig({ reasoning, modelId, warnings });
|
|
1608
|
+
}
|
|
1609
|
+
function resolveGemini3ThinkingConfig({
|
|
1610
|
+
reasoning,
|
|
1611
|
+
warnings
|
|
1612
|
+
}) {
|
|
1613
|
+
if (reasoning === "none") {
|
|
1614
|
+
return { thinkingLevel: "minimal" };
|
|
1615
|
+
}
|
|
1616
|
+
const thinkingLevel = mapReasoningToProviderEffort({
|
|
1617
|
+
reasoning,
|
|
1618
|
+
effortMap: {
|
|
1619
|
+
minimal: "minimal",
|
|
1620
|
+
low: "low",
|
|
1621
|
+
medium: "medium",
|
|
1622
|
+
high: "high",
|
|
1623
|
+
xhigh: "high"
|
|
1624
|
+
},
|
|
1625
|
+
warnings
|
|
1626
|
+
});
|
|
1627
|
+
if (thinkingLevel == null) {
|
|
1628
|
+
return void 0;
|
|
1629
|
+
}
|
|
1630
|
+
return { thinkingLevel };
|
|
1631
|
+
}
|
|
1632
|
+
function resolveGemini25ThinkingConfig({
|
|
1633
|
+
reasoning,
|
|
1634
|
+
modelId,
|
|
1635
|
+
warnings
|
|
1636
|
+
}) {
|
|
1637
|
+
if (reasoning === "none") {
|
|
1638
|
+
return { thinkingBudget: 0 };
|
|
1639
|
+
}
|
|
1640
|
+
const thinkingBudget = mapReasoningToProviderBudget({
|
|
1641
|
+
reasoning,
|
|
1642
|
+
maxOutputTokens: getMaxOutputTokensForGemini25Model(),
|
|
1643
|
+
maxReasoningBudget: getMaxThinkingTokensForGemini25Model(modelId),
|
|
1644
|
+
minReasoningBudget: 0,
|
|
1645
|
+
warnings
|
|
1646
|
+
});
|
|
1647
|
+
if (thinkingBudget == null) {
|
|
1648
|
+
return void 0;
|
|
1649
|
+
}
|
|
1650
|
+
return { thinkingBudget };
|
|
1651
|
+
}
|
|
1250
1652
|
function getToolCallsFromParts({
|
|
1251
1653
|
parts,
|
|
1252
1654
|
generateId: generateId2,
|
|
@@ -1426,6 +1828,23 @@ var getContentSchema = () => z3.object({
|
|
|
1426
1828
|
mimeType: z3.string(),
|
|
1427
1829
|
data: z3.string()
|
|
1428
1830
|
}),
|
|
1831
|
+
thought: z3.boolean().nullish(),
|
|
1832
|
+
thoughtSignature: z3.string().nullish()
|
|
1833
|
+
}),
|
|
1834
|
+
z3.object({
|
|
1835
|
+
toolCall: z3.object({
|
|
1836
|
+
toolType: z3.string(),
|
|
1837
|
+
args: z3.unknown().nullish(),
|
|
1838
|
+
id: z3.string()
|
|
1839
|
+
}),
|
|
1840
|
+
thoughtSignature: z3.string().nullish()
|
|
1841
|
+
}),
|
|
1842
|
+
z3.object({
|
|
1843
|
+
toolResponse: z3.object({
|
|
1844
|
+
toolType: z3.string(),
|
|
1845
|
+
response: z3.unknown().nullish(),
|
|
1846
|
+
id: z3.string()
|
|
1847
|
+
}),
|
|
1429
1848
|
thoughtSignature: z3.string().nullish()
|
|
1430
1849
|
}),
|
|
1431
1850
|
z3.object({
|
|
@@ -1452,6 +1871,12 @@ var getSafetyRatingSchema = () => z3.object({
|
|
|
1452
1871
|
severityScore: z3.number().nullish(),
|
|
1453
1872
|
blocked: z3.boolean().nullish()
|
|
1454
1873
|
});
|
|
1874
|
+
var tokenDetailsSchema = z3.array(
|
|
1875
|
+
z3.object({
|
|
1876
|
+
modality: z3.string(),
|
|
1877
|
+
tokenCount: z3.number()
|
|
1878
|
+
})
|
|
1879
|
+
).nullish();
|
|
1455
1880
|
var usageSchema = z3.object({
|
|
1456
1881
|
cachedContentTokenCount: z3.number().nullish(),
|
|
1457
1882
|
thoughtsTokenCount: z3.number().nullish(),
|
|
@@ -1459,7 +1884,10 @@ var usageSchema = z3.object({
|
|
|
1459
1884
|
candidatesTokenCount: z3.number().nullish(),
|
|
1460
1885
|
totalTokenCount: z3.number().nullish(),
|
|
1461
1886
|
// https://cloud.google.com/vertex-ai/generative-ai/docs/reference/rest/v1/GenerateContentResponse#TrafficType
|
|
1462
|
-
trafficType: z3.string().nullish()
|
|
1887
|
+
trafficType: z3.string().nullish(),
|
|
1888
|
+
// https://ai.google.dev/api/generate-content#Modality
|
|
1889
|
+
promptTokensDetails: tokenDetailsSchema,
|
|
1890
|
+
candidatesTokensDetails: tokenDetailsSchema
|
|
1463
1891
|
});
|
|
1464
1892
|
var getUrlContextMetadataSchema = () => z3.object({
|
|
1465
1893
|
urlMetadata: z3.array(
|
|
@@ -1476,6 +1904,7 @@ var responseSchema = lazySchema3(
|
|
|
1476
1904
|
z3.object({
|
|
1477
1905
|
content: getContentSchema().nullish().or(z3.object({}).strict()),
|
|
1478
1906
|
finishReason: z3.string().nullish(),
|
|
1907
|
+
finishMessage: z3.string().nullish(),
|
|
1479
1908
|
safetyRatings: z3.array(getSafetyRatingSchema()).nullish(),
|
|
1480
1909
|
groundingMetadata: getGroundingMetadataSchema().nullish(),
|
|
1481
1910
|
urlContextMetadata: getUrlContextMetadataSchema().nullish()
|
|
@@ -1485,7 +1914,8 @@ var responseSchema = lazySchema3(
|
|
|
1485
1914
|
promptFeedback: z3.object({
|
|
1486
1915
|
blockReason: z3.string().nullish(),
|
|
1487
1916
|
safetyRatings: z3.array(getSafetyRatingSchema()).nullish()
|
|
1488
|
-
}).nullish()
|
|
1917
|
+
}).nullish(),
|
|
1918
|
+
serviceTier: z3.string().nullish()
|
|
1489
1919
|
})
|
|
1490
1920
|
)
|
|
1491
1921
|
);
|
|
@@ -1496,6 +1926,7 @@ var chunkSchema = lazySchema3(
|
|
|
1496
1926
|
z3.object({
|
|
1497
1927
|
content: getContentSchema().nullish(),
|
|
1498
1928
|
finishReason: z3.string().nullish(),
|
|
1929
|
+
finishMessage: z3.string().nullish(),
|
|
1499
1930
|
safetyRatings: z3.array(getSafetyRatingSchema()).nullish(),
|
|
1500
1931
|
groundingMetadata: getGroundingMetadataSchema().nullish(),
|
|
1501
1932
|
urlContextMetadata: getUrlContextMetadataSchema().nullish()
|
|
@@ -1505,7 +1936,8 @@ var chunkSchema = lazySchema3(
|
|
|
1505
1936
|
promptFeedback: z3.object({
|
|
1506
1937
|
blockReason: z3.string().nullish(),
|
|
1507
1938
|
safetyRatings: z3.array(getSafetyRatingSchema()).nullish()
|
|
1508
|
-
}).nullish()
|
|
1939
|
+
}).nullish(),
|
|
1940
|
+
serviceTier: z3.string().nullish()
|
|
1509
1941
|
})
|
|
1510
1942
|
)
|
|
1511
1943
|
);
|