@ai-sdk/google 4.0.87 → 4.0.89
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 +35 -0
- package/dist/index.d.ts +23 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +78 -29
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +20 -3
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +68 -23
- package/dist/internal/index.js.map +1 -1
- package/docs/15-google.mdx +30 -16
- package/package.json +5 -5
- package/src/google-batch.ts +4 -0
- package/src/google-image-model.ts +1 -0
- package/src/google-image-settings.ts +1 -0
- package/src/google-language-model-options.ts +1 -0
- package/src/google-language-model.ts +92 -4
- package/src/google-provider.ts +20 -7
- package/src/interactions/google-interactions-language-model-options.ts +1 -0
package/dist/internal/index.d.ts
CHANGED
|
@@ -81,7 +81,7 @@ type GoogleFunctionResponsePart = {
|
|
|
81
81
|
};
|
|
82
82
|
//#endregion
|
|
83
83
|
//#region src/google-language-model-options.d.ts
|
|
84
|
-
type GoogleModelId = 'gemini-2.0-flash' | 'gemini-2.0-flash-001' | 'gemini-2.0-flash-lite' | 'gemini-2.0-flash-lite-001' | 'gemini-2.5-pro' | 'gemini-2.5-flash' | 'gemini-2.5-flash-image' | 'gemini-2.5-flash-lite' | 'gemini-2.5-flash-preview-tts' | 'gemini-2.5-pro-preview-tts' | 'gemini-2.5-flash-native-audio-latest' | 'gemini-2.5-flash-native-audio-preview-09-2025' | 'gemini-2.5-flash-native-audio-preview-12-2025' | 'gemini-2.5-computer-use-preview-10-2025' | 'gemini-3-pro-preview' | 'gemini-3-pro-image-preview' | 'gemini-3-flash-preview' | 'gemini-3.1-pro-preview' | 'gemini-3.1-pro-preview-customtools' | 'gemini-3.1-flash-image-preview' | 'gemini-3.1-flash-lite-preview' | 'gemini-3.1-flash-tts-preview' | 'gemini-3.5-flash' | 'gemini-3.5-flash-lite' | 'gemini-3.6-flash' | 'gemini-3.7-flash' | 'gemini-3.8-flash' | 'gemini-pro-latest' | 'gemini-flash-latest' | 'gemini-flash-lite-latest' | 'deep-research-pro-preview-12-2025' | 'deep-research-max-preview-04-2026' | 'deep-research-preview-04-2026' | 'nano-banana-pro-preview' | 'aqa' | 'gemini-robotics-er-1.5-preview' | 'gemma-3-1b-it' | 'gemma-3-4b-it' | 'gemma-3n-e4b-it' | 'gemma-3n-e2b-it' | 'gemma-3-12b-it' | 'gemma-3-27b-it' | (string & {});
|
|
84
|
+
type GoogleModelId = 'gemini-2.0-flash' | 'gemini-2.0-flash-001' | 'gemini-2.0-flash-lite' | 'gemini-2.0-flash-lite-001' | 'gemini-2.5-pro' | 'gemini-2.5-flash' | 'gemini-2.5-flash-image' | 'gemini-2.5-flash-lite' | 'gemini-2.5-flash-preview-tts' | 'gemini-2.5-pro-preview-tts' | 'gemini-2.5-flash-native-audio-latest' | 'gemini-2.5-flash-native-audio-preview-09-2025' | 'gemini-2.5-flash-native-audio-preview-12-2025' | 'gemini-2.5-computer-use-preview-10-2025' | 'gemini-3-pro-preview' | 'gemini-3-pro-image-preview' | 'gemini-3-flash-preview' | 'gemini-3.1-pro-preview' | 'gemini-3.1-pro-preview-customtools' | 'gemini-3.1-flash-image-preview' | 'gemini-3.1-flash-lite-preview' | 'gemini-3.1-flash-tts-preview' | 'gemini-3.5-flash' | 'gemini-3.5-flash-lite' | 'gemini-3.6-flash' | 'gemini-3.7-flash' | 'gemini-3.8-flash' | 'gemini-nano-banana-2.1' | 'gemini-pro-latest' | 'gemini-flash-latest' | 'gemini-flash-lite-latest' | 'deep-research-pro-preview-12-2025' | 'deep-research-max-preview-04-2026' | 'deep-research-preview-04-2026' | 'nano-banana-pro-preview' | 'aqa' | 'gemini-robotics-er-1.5-preview' | 'gemma-3-1b-it' | 'gemma-3-4b-it' | 'gemma-3n-e4b-it' | 'gemma-3n-e2b-it' | 'gemma-3-12b-it' | 'gemma-3-27b-it' | (string & {});
|
|
85
85
|
//#endregion
|
|
86
86
|
//#region src/google-language-model.d.ts
|
|
87
87
|
export type GoogleLanguageModelConfig = {
|
|
@@ -196,12 +196,13 @@ export declare class GoogleLanguageModel implements LanguageModelV4 {
|
|
|
196
196
|
toolNameMapping: import("@ai-sdk/provider-utils").ToolNameMapping;
|
|
197
197
|
}>;
|
|
198
198
|
private getArgs;
|
|
199
|
-
static convertGenerateContentResponse({ config, response, warnings, providerOptionsNames, toolNameMapping }: {
|
|
199
|
+
static convertGenerateContentResponse({ config, response, warnings, providerOptionsNames, toolNameMapping, jsonResponseToolName }: {
|
|
200
200
|
config: GoogleLanguageModelConfig;
|
|
201
201
|
response: InferSchema<typeof responseSchema>;
|
|
202
202
|
warnings: SharedV4Warning[];
|
|
203
203
|
providerOptionsNames: readonly string[];
|
|
204
204
|
toolNameMapping?: ReturnType<typeof createToolNameMapping>;
|
|
205
|
+
jsonResponseToolName?: string;
|
|
205
206
|
}): LanguageModelV4GenerateResult;
|
|
206
207
|
doGenerate(options: LanguageModelV4CallOptions): Promise<LanguageModelV4GenerateResult>;
|
|
207
208
|
doStream(options: LanguageModelV4CallOptions): Promise<LanguageModelV4StreamResult>;
|
|
@@ -229,6 +230,14 @@ export declare const getGroundingMetadataSchema: () => z.ZodObject<{
|
|
|
229
230
|
title: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
230
231
|
text: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
231
232
|
fileSearchStore: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
233
|
+
customMetadata: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
|
|
234
|
+
key: z.ZodString;
|
|
235
|
+
stringValue: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
236
|
+
numericValue: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
237
|
+
stringListValue: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
238
|
+
values: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
|
|
239
|
+
}, z.core.$strip>>>;
|
|
240
|
+
}, z.core.$strip>>>>;
|
|
232
241
|
}, z.core.$strip>>>;
|
|
233
242
|
maps: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
234
243
|
uri: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
@@ -347,6 +356,14 @@ export declare const responseSchema: import("@ai-sdk/provider-utils").LazySchema
|
|
|
347
356
|
title?: string | null | undefined;
|
|
348
357
|
text?: string | null | undefined;
|
|
349
358
|
fileSearchStore?: string | null | undefined;
|
|
359
|
+
customMetadata?: {
|
|
360
|
+
key: string;
|
|
361
|
+
stringValue?: string | null | undefined;
|
|
362
|
+
numericValue?: number | null | undefined;
|
|
363
|
+
stringListValue?: {
|
|
364
|
+
values?: string[] | null | undefined;
|
|
365
|
+
} | null | undefined;
|
|
366
|
+
}[] | null | undefined;
|
|
350
367
|
} | null | undefined;
|
|
351
368
|
maps?: {
|
|
352
369
|
uri?: string | null | undefined;
|
|
@@ -568,7 +585,7 @@ export declare const googleTools: {
|
|
|
568
585
|
* the two surfaces (`:generateContent` vs `/interactions`) are independent and
|
|
569
586
|
* may diverge over time.
|
|
570
587
|
*/
|
|
571
|
-
type GoogleInteractionsModelId = 'gemini-2.5-computer-use-preview-10-2025' | 'gemini-2.5-flash' | 'gemini-2.5-flash-image' | 'gemini-2.5-flash-lite' | 'gemini-2.5-flash-lite-preview-09-2025' | 'gemini-2.5-flash-native-audio-preview-12-2025' | 'gemini-2.5-flash-preview-09-2025' | 'gemini-2.5-flash-preview-tts' | 'gemini-2.5-pro' | 'gemini-2.5-pro-preview-tts' | 'gemini-3-flash-preview' | 'gemini-3-pro-image-preview' | 'gemini-3-pro-preview' | 'gemini-3.1-pro-preview' | 'gemini-3.1-flash-image-preview' | 'gemini-3.1-flash-lite-preview' | 'gemini-3.1-flash-tts-preview' | 'gemini-3.5-flash' | 'gemini-3.5-flash-lite' | 'gemini-3.6-flash' | 'gemini-3.7-flash' | 'gemini-3.8-flash' | 'lyria-3-clip-preview' | 'lyria-3-pro-preview' | (string & {});
|
|
588
|
+
type GoogleInteractionsModelId = 'gemini-2.5-computer-use-preview-10-2025' | 'gemini-2.5-flash' | 'gemini-2.5-flash-image' | 'gemini-2.5-flash-lite' | 'gemini-2.5-flash-lite-preview-09-2025' | 'gemini-2.5-flash-native-audio-preview-12-2025' | 'gemini-2.5-flash-preview-09-2025' | 'gemini-2.5-flash-preview-tts' | 'gemini-2.5-pro' | 'gemini-2.5-pro-preview-tts' | 'gemini-3-flash-preview' | 'gemini-3-pro-image-preview' | 'gemini-3-pro-preview' | 'gemini-3.1-pro-preview' | 'gemini-3.1-flash-image-preview' | 'gemini-3.1-flash-lite-preview' | 'gemini-3.1-flash-tts-preview' | 'gemini-3.5-flash' | 'gemini-3.5-flash-lite' | 'gemini-3.6-flash' | 'gemini-3.7-flash' | 'gemini-3.8-flash' | 'gemini-nano-banana-2.1' | 'lyria-3-clip-preview' | 'lyria-3-pro-preview' | (string & {});
|
|
572
589
|
//#endregion
|
|
573
590
|
//#region src/interactions/google-interactions-language-model.d.ts
|
|
574
591
|
type GoogleInteractionsConfig = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["_$__google_prompt0.GoogleContent","_$__google_prompt0.GoogleSystemInstruction"],"sources":["../../src/google-prompt.ts","../../src/google-language-model-options.ts","../../src/google-language-model.ts","../../src/google-speech-model-options.ts","../../src/google-speech-model.ts","../../src/google-speech-input.ts","../../src/google-tools.ts","../../src/interactions/google-interactions-language-model-options.ts","../../src/interactions/google-interactions-language-model.ts","../../src/interactions/google-interactions-agent.ts"],"mappings":";;;;KAaY;EACV,OAAO;IAAQ;;;KAGL;EACV;EACA,OAAO,MAAM;;KAGH;EACN;EAAc;EAAmB;;EAEjC;IAAc;IAAkB;;EAChC;EACA;;EAGA;IAAgB;IAAa;IAAc;;EAC3C;;EAGA;IACE;IACA;IACA;IACA,QAAQ,MAAM;;;EAIhB;IAAY;IAAkB;;EAC9B;EACA;;EAGA;IACE;IACA;IACA;;EAEF;;EAGA;IACE;IACA;IACA;;EAEF;;EAGA;IACE;IACA;;;EAIF;IACE;IACA;;;KAII;EAEN;IAAc;IAAkB;;;EAGhC;IAAY;IAAkB;;;;;KCzExB;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["_$__google_prompt0.GoogleContent","_$__google_prompt0.GoogleSystemInstruction"],"sources":["../../src/google-prompt.ts","../../src/google-language-model-options.ts","../../src/google-language-model.ts","../../src/google-speech-model-options.ts","../../src/google-speech-model.ts","../../src/google-speech-input.ts","../../src/google-tools.ts","../../src/interactions/google-interactions-language-model-options.ts","../../src/interactions/google-interactions-language-model.ts","../../src/interactions/google-interactions-agent.ts"],"mappings":"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"}
|
package/dist/internal/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE, combineHeaders, convertBase64ToUint8Array, convertToBase64, createEventSourceResponseHandler, createJsonErrorResponseHandler, createJsonResponseHandler, createNullLanguageModelUsage, createProviderExecutedToolFactory, createProviderStreamError, createToolNameMapping, delay, detectMediaType, downloadBlob, generateId, getFromApi, getRuntimeEnvironmentUserAgent, getTopLevelMediaType, isAbortError, isCustomReasoning, isFullMediaType, isUrlSupported, lazySchema, mapReasoningToProviderBudget, mapReasoningToProviderEffort, parseProviderOptions, postJsonToApi, resolve, resolveFullMediaType, resolveProviderReference, secureJsonParse, serializeModelOptions, withUserAgentSuffix, zodSchema } from "@ai-sdk/provider-utils";
|
|
1
|
+
import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE, combineHeaders, convertBase64ToUint8Array, convertJsonResponseToolStream, convertToBase64, createEventSourceResponseHandler, createJsonErrorResponseHandler, createJsonResponseHandler, createNullLanguageModelUsage, createProviderExecutedToolFactory, createProviderStreamError, createToolNameMapping, delay, detectMediaType, downloadBlob, generateId, getFromApi, getRuntimeEnvironmentUserAgent, getTopLevelMediaType, isAbortError, isCustomReasoning, isFullMediaType, isUrlSupported, lazySchema, mapReasoningToProviderBudget, mapReasoningToProviderEffort, parseProviderOptions, postJsonToApi, resolve, resolveFullMediaType, resolveProviderReference, secureJsonParse, serializeModelOptions, withUserAgentSuffix, zodSchema } from "@ai-sdk/provider-utils";
|
|
2
2
|
import { z } from "zod/v4";
|
|
3
3
|
import { InvalidArgumentError, UnsupportedFunctionalityError } from "@ai-sdk/provider";
|
|
4
4
|
//#region src/convert-google-usage.ts
|
|
@@ -1370,15 +1370,38 @@ var GoogleLanguageModel = class GoogleLanguageModel {
|
|
|
1370
1370
|
toolNameMapping
|
|
1371
1371
|
};
|
|
1372
1372
|
}
|
|
1373
|
-
getArgs(options, { isStreaming = false } = {}) {
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1373
|
+
async getArgs(options, { isStreaming = false } = {}) {
|
|
1374
|
+
const { responseFormat, tools, toolChoice } = options;
|
|
1375
|
+
let jsonResponseTool;
|
|
1376
|
+
if (responseFormat?.type === "json" && responseFormat.schema != null && tools?.some((tool) => tool.type === "function") && /(^|\/)gemini-/i.test(this.modelId) && (!getGoogleModelCapabilities(this.modelId).usesGemini3Features || toolChoice?.type === "required" || toolChoice?.type === "tool")) {
|
|
1377
|
+
let name = "json";
|
|
1378
|
+
for (let suffix = 1; tools.some((tool) => tool.name === name); suffix++) name = `json_${suffix}`;
|
|
1379
|
+
jsonResponseTool = {
|
|
1380
|
+
type: "function",
|
|
1381
|
+
name,
|
|
1382
|
+
description: responseFormat.description ?? "Respond with a JSON object.",
|
|
1383
|
+
inputSchema: responseFormat.schema
|
|
1384
|
+
};
|
|
1385
|
+
}
|
|
1386
|
+
return {
|
|
1387
|
+
...await GoogleLanguageModel.prepareRequest({
|
|
1388
|
+
modelId: this.modelId,
|
|
1389
|
+
config: this.config,
|
|
1390
|
+
options: jsonResponseTool == null ? options : {
|
|
1391
|
+
...options,
|
|
1392
|
+
responseFormat: void 0,
|
|
1393
|
+
tools: [...tools ?? [], jsonResponseTool],
|
|
1394
|
+
toolChoice: toolChoice?.type === "tool" ? toolChoice : toolChoice?.type === "none" ? {
|
|
1395
|
+
type: "tool",
|
|
1396
|
+
toolName: jsonResponseTool.name
|
|
1397
|
+
} : { type: "required" }
|
|
1398
|
+
},
|
|
1399
|
+
isStreaming
|
|
1400
|
+
}),
|
|
1401
|
+
jsonResponseToolName: jsonResponseTool?.name
|
|
1402
|
+
};
|
|
1380
1403
|
}
|
|
1381
|
-
static convertGenerateContentResponse({ config, response, warnings, providerOptionsNames, toolNameMapping }) {
|
|
1404
|
+
static convertGenerateContentResponse({ config, response, warnings, providerOptionsNames, toolNameMapping, jsonResponseToolName }) {
|
|
1382
1405
|
const wrapProviderMetadata = (payload) => Object.fromEntries(providerOptionsNames.map((name) => [name, payload]));
|
|
1383
1406
|
const candidate = response.candidates?.[0];
|
|
1384
1407
|
const promptBlockReason = response.promptFeedback?.blockReason;
|
|
@@ -1410,6 +1433,7 @@ var GoogleLanguageModel = class GoogleLanguageModel {
|
|
|
1410
1433
|
}
|
|
1411
1434
|
});
|
|
1412
1435
|
else if ("text" in part && part.text != null) {
|
|
1436
|
+
if (jsonResponseToolName != null && part.thought !== true) continue;
|
|
1413
1437
|
const thoughtSignatureMetadata = part.thoughtSignature ? wrapProviderMetadata({ thoughtSignature: part.thoughtSignature }) : void 0;
|
|
1414
1438
|
if (part.text.length === 0) {
|
|
1415
1439
|
if (thoughtSignatureMetadata != null && content.length > 0) {
|
|
@@ -1421,14 +1445,23 @@ var GoogleLanguageModel = class GoogleLanguageModel {
|
|
|
1421
1445
|
text: part.text,
|
|
1422
1446
|
providerMetadata: thoughtSignatureMetadata
|
|
1423
1447
|
});
|
|
1424
|
-
} else if ("functionCall" in part && part.functionCall.name != null)
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1448
|
+
} else if ("functionCall" in part && part.functionCall.name != null) {
|
|
1449
|
+
if (part.functionCall.name === jsonResponseToolName) {
|
|
1450
|
+
content.push({
|
|
1451
|
+
type: "text",
|
|
1452
|
+
text: typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify(part.functionCall.args ?? {}),
|
|
1453
|
+
...part.thoughtSignature ? { providerMetadata: wrapProviderMetadata({ thoughtSignature: part.thoughtSignature }) } : {}
|
|
1454
|
+
});
|
|
1455
|
+
continue;
|
|
1456
|
+
}
|
|
1457
|
+
content.push({
|
|
1458
|
+
type: "tool-call",
|
|
1459
|
+
toolCallId: part.functionCall.id || config.generateId(),
|
|
1460
|
+
toolName: part.functionCall.name,
|
|
1461
|
+
input: JSON.stringify(part.functionCall.args ?? {}),
|
|
1462
|
+
providerMetadata: part.thoughtSignature ? wrapProviderMetadata({ thoughtSignature: part.thoughtSignature }) : void 0
|
|
1463
|
+
});
|
|
1464
|
+
} else if ("inlineData" in part) {
|
|
1432
1465
|
const hasThought = part.thought === true;
|
|
1433
1466
|
const hasThoughtSignature = !!part.thoughtSignature;
|
|
1434
1467
|
content.push({
|
|
@@ -1506,7 +1539,7 @@ var GoogleLanguageModel = class GoogleLanguageModel {
|
|
|
1506
1539
|
};
|
|
1507
1540
|
}
|
|
1508
1541
|
async doGenerate(options) {
|
|
1509
|
-
const { args, warnings, providerOptionsNames, extraHeaders, toolNameMapping } = await this.getArgs(options);
|
|
1542
|
+
const { args, warnings, providerOptionsNames, extraHeaders, toolNameMapping, jsonResponseToolName } = await this.getArgs(options);
|
|
1510
1543
|
const mergedHeaders = combineHeaders(this.config.headers ? await resolve(this.config.headers) : void 0, options.headers, extraHeaders);
|
|
1511
1544
|
const { responseHeaders, value: response, rawValue: rawResponse } = await postJsonToApi({
|
|
1512
1545
|
url: `${this.config.baseURL}/${getModelPath(this.modelId)}:generateContent`,
|
|
@@ -1522,7 +1555,8 @@ var GoogleLanguageModel = class GoogleLanguageModel {
|
|
|
1522
1555
|
response,
|
|
1523
1556
|
warnings,
|
|
1524
1557
|
providerOptionsNames,
|
|
1525
|
-
toolNameMapping
|
|
1558
|
+
toolNameMapping,
|
|
1559
|
+
jsonResponseToolName
|
|
1526
1560
|
});
|
|
1527
1561
|
return {
|
|
1528
1562
|
...result,
|
|
@@ -1535,7 +1569,7 @@ var GoogleLanguageModel = class GoogleLanguageModel {
|
|
|
1535
1569
|
};
|
|
1536
1570
|
}
|
|
1537
1571
|
async doStream(options) {
|
|
1538
|
-
const { args, warnings, providerOptionsNames, extraHeaders, toolNameMapping } = await this.getArgs(options, { isStreaming: true });
|
|
1572
|
+
const { args, warnings, providerOptionsNames, extraHeaders, toolNameMapping, jsonResponseToolName } = await this.getArgs(options, { isStreaming: true });
|
|
1539
1573
|
const wrapProviderMetadata = (payload) => Object.fromEntries(providerOptionsNames.map((name) => [name, payload]));
|
|
1540
1574
|
const headers = combineHeaders(this.config.headers ? await resolve(this.config.headers) : void 0, options.headers, extraHeaders);
|
|
1541
1575
|
const { responseHeaders, value: response } = await postJsonToApi({
|
|
@@ -1592,7 +1626,7 @@ var GoogleLanguageModel = class GoogleLanguageModel {
|
|
|
1592
1626
|
});
|
|
1593
1627
|
hasToolCalls = true;
|
|
1594
1628
|
};
|
|
1595
|
-
|
|
1629
|
+
const result = {
|
|
1596
1630
|
stream: response.pipeThrough(new TransformStream({
|
|
1597
1631
|
start(controller) {
|
|
1598
1632
|
controller.enqueue({
|
|
@@ -1924,6 +1958,10 @@ var GoogleLanguageModel = class GoogleLanguageModel {
|
|
|
1924
1958
|
response: { headers: responseHeaders },
|
|
1925
1959
|
request: { body: args }
|
|
1926
1960
|
};
|
|
1961
|
+
return {
|
|
1962
|
+
...result,
|
|
1963
|
+
stream: jsonResponseToolName == null ? result.stream : result.stream.pipeThrough(convertJsonResponseToolStream(jsonResponseToolName))
|
|
1964
|
+
};
|
|
1927
1965
|
}
|
|
1928
1966
|
};
|
|
1929
1967
|
function getMaxOutputTokensForGemini25Model() {
|
|
@@ -1957,7 +1995,8 @@ function resolveGemini3ThinkingConfig({ reasoning, modelId, warnings }) {
|
|
|
1957
1995
|
low: "low",
|
|
1958
1996
|
medium: "medium",
|
|
1959
1997
|
high: "high",
|
|
1960
|
-
xhigh: "high"
|
|
1998
|
+
xhigh: "high",
|
|
1999
|
+
max: "high"
|
|
1961
2000
|
},
|
|
1962
2001
|
warnings
|
|
1963
2002
|
});
|
|
@@ -2082,7 +2121,13 @@ const getGroundingMetadataSchema = () => z.object({
|
|
|
2082
2121
|
uri: z.string().nullish(),
|
|
2083
2122
|
title: z.string().nullish(),
|
|
2084
2123
|
text: z.string().nullish(),
|
|
2085
|
-
fileSearchStore: z.string().nullish()
|
|
2124
|
+
fileSearchStore: z.string().nullish(),
|
|
2125
|
+
customMetadata: z.array(z.object({
|
|
2126
|
+
key: z.string(),
|
|
2127
|
+
stringValue: z.string().nullish(),
|
|
2128
|
+
numericValue: z.number().nullish(),
|
|
2129
|
+
stringListValue: z.object({ values: z.array(z.string()).nullish() }).nullish()
|
|
2130
|
+
})).nullish()
|
|
2086
2131
|
}).nullish(),
|
|
2087
2132
|
maps: z.object({
|
|
2088
2133
|
uri: z.string().nullish(),
|