Define own GoogleThinkingLevel type instead of importing from @google/genai

- Add GoogleThinkingLevel type mirroring Google's ThinkingLevel enum
- Update GoogleGeminiCliOptions and GoogleOptions to use our type
- Cast to any when assigning to Google SDK's ThinkingConfig
This commit is contained in:
Mario Zechner 2025-12-30 01:02:29 +01:00
parent 8ed6f6dd85
commit ecd240f636
3 changed files with 36 additions and 22 deletions

View file

@ -3,7 +3,6 @@ import {
type GenerateContentParameters,
GoogleGenAI,
type ThinkingConfig,
type ThinkingLevel,
} from "@google/genai";
import { calculateCost } from "../models.js";
import { getEnvApiKey } from "../stream.js";
@ -20,6 +19,7 @@ import type {
} from "../types.js";
import { AssistantMessageEventStream } from "../utils/event-stream.js";
import { sanitizeSurrogates } from "../utils/sanitize-unicode.js";
import type { GoogleThinkingLevel } from "./google-gemini-cli.js";
import { convertMessages, convertTools, mapStopReason, mapToolChoice } from "./google-shared.js";
export interface GoogleOptions extends StreamOptions {
@ -27,7 +27,7 @@ export interface GoogleOptions extends StreamOptions {
thinking?: {
enabled: boolean;
budgetTokens?: number; // -1 for dynamic, 0 to disable
level?: ThinkingLevel;
level?: GoogleThinkingLevel;
};
}
@ -299,7 +299,8 @@ function buildParams(
if (options.thinking?.enabled && model.reasoning) {
const thinkingConfig: ThinkingConfig = { includeThoughts: true };
if (options.thinking.level !== undefined) {
thinkingConfig.thinkingLevel = options.thinking.level;
// Cast to any since our GoogleThinkingLevel mirrors Google's ThinkingLevel enum values
thinkingConfig.thinkingLevel = options.thinking.level as any;
} else if (options.thinking.budgetTokens !== undefined) {
thinkingConfig.thinkingBudget = options.thinking.budgetTokens;
}