Skip to content

Commit a972ed7

Browse files
feat: 添加 cacheWarningEnabled 配置项,支持在 /config 面板关闭缓存率警告
1 parent 9947ae7 commit a972ed7

4 files changed

Lines changed: 34 additions & 1 deletion

File tree

src/components/Settings/Config.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,24 @@ export function Config({
331331
});
332332
},
333333
},
334+
{
335+
id: 'cacheWarningEnabled',
336+
label: 'Cache warnings',
337+
value: settingsData?.cacheWarningEnabled ?? true,
338+
type: 'boolean' as const,
339+
onChange(cacheWarningEnabled: boolean) {
340+
updateSettingsForSource('localSettings', {
341+
cacheWarningEnabled,
342+
});
343+
setSettingsData(prev => ({
344+
...prev,
345+
cacheWarningEnabled,
346+
}));
347+
logEvent('tengu_cache_warning_setting_changed', {
348+
enabled: cacheWarningEnabled,
349+
});
350+
},
351+
},
334352
{
335353
id: 'prefersReducedMotion',
336354
label: 'Reduce motion',

src/query.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ import { getAPIProvider } from './utils/model/providers.js'
133133
import {
134134
createCacheWarningMessage,
135135
getCacheThreshold,
136+
isCacheWarningEnabled,
136137
shouldShowCacheWarning,
137138
} from './utils/cacheWarning.js'
138139

@@ -1256,7 +1257,7 @@ async function* queryLoop(
12561257
cache_read_input_tokens: number
12571258
}
12581259
| undefined
1259-
if (usage) {
1260+
if (usage && isCacheWarningEnabled()) {
12601261
const warningInfo = shouldShowCacheWarning(
12611262
usage,
12621263
querySource,

src/utils/cacheWarning.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ export function getCacheThreshold(): number {
4040
return settings.cacheThreshold ?? DEFAULT_CACHE_THRESHOLD
4141
}
4242

43+
/**
44+
* 检查缓存警告是否启用。默认 true。
45+
*/
46+
export function isCacheWarningEnabled(): boolean {
47+
const settings = getInitialSettings()
48+
return settings.cacheWarningEnabled ?? true
49+
}
50+
4351
/**
4452
* 计算缓存命中率
4553
* 返回值范围 0-100,null 表示无有效数据

src/utils/settings/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,12 @@ export const SettingsSchema = lazySchema(() =>
10891089
.describe(
10901090
'Prompt cache hit rate threshold (0-100). Warnings shown when cache hit rate falls below this percentage. Default: 80.',
10911091
),
1092+
cacheWarningEnabled: z
1093+
.boolean()
1094+
.optional()
1095+
.describe(
1096+
'Whether to show cache hit rate warnings in the message flow when the rate falls below cacheThreshold. Default: true.',
1097+
),
10921098
pluginTrustMessage: z
10931099
.string()
10941100
.optional()

0 commit comments

Comments
 (0)