From 43448f0cc05c899816d058ee6bcb5ba39d53e64c Mon Sep 17 00:00:00 2001 From: Simon Shi Date: Mon, 20 Jul 2026 20:55:09 +0800 Subject: [PATCH] feat: default to maximum context size --- src/models.ts | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/models.ts b/src/models.ts index 08b06f5..ebb956d 100644 --- a/src/models.ts +++ b/src/models.ts @@ -19,7 +19,7 @@ export interface QoderModelEntry { display_name?: string; max_input_tokens?: number; max_output_tokens?: number; - context_config?: Record; + context_config?: Record; is_vl?: boolean; is_reasoning?: boolean; thinking_config?: { enabled?: { efforts?: unknown } }; @@ -358,7 +358,7 @@ export function getCachedModelConfig(modelKey: string, mode?: string): QoderMode try { const data = JSON.parse(readFileSync(cachePath, "utf8")); if (data?.configs?.[modelKey]) { - return data.configs[modelKey] as QoderModelEntry; + return withMaxContextAsDefault(data.configs[modelKey] as QoderModelEntry); } } catch {} } @@ -394,6 +394,27 @@ export function getCachedModelConfig(modelKey: string, mode?: string): QoderMode return null; } +/** Prefer the largest context option when Qoder exposes selectable contexts. */ +function withMaxContextAsDefault(entry: QoderModelEntry): QoderModelEntry { + const contextConfig = entry.context_config; + if (!contextConfig || typeof contextConfig !== "object") return entry; + + const maxTokenCount = Math.max( + ...Object.values(contextConfig).map((config) => (typeof config?.token_count === "number" ? config.token_count : 0)), + ); + if (maxTokenCount <= 0) return entry; + + return { + ...entry, + context_config: Object.fromEntries( + Object.entries(contextConfig).map(([name, config]) => [ + name, + { ...config, is_default: config.token_count === maxTokenCount }, + ]), + ), + }; +} + export function isCacheStale(mode?: string): boolean { const cachePath = getQoderCachePath(mode); if (!existsSync(cachePath)) return true;