From a972ed795c3efa05f454c2ed47960fb0c7b65c4e Mon Sep 17 00:00:00 2001 From: claude-code-best Date: Sat, 6 Jun 2026 10:15:24 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=20cacheWarningEnable?= =?UTF-8?q?d=20=E9=85=8D=E7=BD=AE=E9=A1=B9=EF=BC=8C=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E5=9C=A8=20/config=20=E9=9D=A2=E6=9D=BF=E5=85=B3=E9=97=AD?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E7=8E=87=E8=AD=A6=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Settings/Config.tsx | 18 ++++++++++++++++++ src/query.ts | 3 ++- src/utils/cacheWarning.ts | 8 ++++++++ src/utils/settings/types.ts | 6 ++++++ 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/components/Settings/Config.tsx b/src/components/Settings/Config.tsx index a2031bde2..371b9aed6 100644 --- a/src/components/Settings/Config.tsx +++ b/src/components/Settings/Config.tsx @@ -331,6 +331,24 @@ export function Config({ }); }, }, + { + id: 'cacheWarningEnabled', + label: 'Cache warnings', + value: settingsData?.cacheWarningEnabled ?? true, + type: 'boolean' as const, + onChange(cacheWarningEnabled: boolean) { + updateSettingsForSource('localSettings', { + cacheWarningEnabled, + }); + setSettingsData(prev => ({ + ...prev, + cacheWarningEnabled, + })); + logEvent('tengu_cache_warning_setting_changed', { + enabled: cacheWarningEnabled, + }); + }, + }, { id: 'prefersReducedMotion', label: 'Reduce motion', diff --git a/src/query.ts b/src/query.ts index b2de65d4e..3b2053158 100644 --- a/src/query.ts +++ b/src/query.ts @@ -133,6 +133,7 @@ import { getAPIProvider } from './utils/model/providers.js' import { createCacheWarningMessage, getCacheThreshold, + isCacheWarningEnabled, shouldShowCacheWarning, } from './utils/cacheWarning.js' @@ -1256,7 +1257,7 @@ async function* queryLoop( cache_read_input_tokens: number } | undefined - if (usage) { + if (usage && isCacheWarningEnabled()) { const warningInfo = shouldShowCacheWarning( usage, querySource, diff --git a/src/utils/cacheWarning.ts b/src/utils/cacheWarning.ts index 2e193f9a4..6558e5440 100644 --- a/src/utils/cacheWarning.ts +++ b/src/utils/cacheWarning.ts @@ -40,6 +40,14 @@ export function getCacheThreshold(): number { return settings.cacheThreshold ?? DEFAULT_CACHE_THRESHOLD } +/** + * 检查缓存警告是否启用。默认 true。 + */ +export function isCacheWarningEnabled(): boolean { + const settings = getInitialSettings() + return settings.cacheWarningEnabled ?? true +} + /** * 计算缓存命中率 * 返回值范围 0-100,null 表示无有效数据 diff --git a/src/utils/settings/types.ts b/src/utils/settings/types.ts index 678eb5c76..9cc515fff 100644 --- a/src/utils/settings/types.ts +++ b/src/utils/settings/types.ts @@ -1089,6 +1089,12 @@ export const SettingsSchema = lazySchema(() => .describe( 'Prompt cache hit rate threshold (0-100). Warnings shown when cache hit rate falls below this percentage. Default: 80.', ), + cacheWarningEnabled: z + .boolean() + .optional() + .describe( + 'Whether to show cache hit rate warnings in the message flow when the rate falls below cacheThreshold. Default: true.', + ), pluginTrustMessage: z .string() .optional()