From 08d450971467605886294ba2cf228d5269c39774 Mon Sep 17 00:00:00 2001 From: fullex <0xfullex@gmail.com> Date: Mon, 1 Dec 2025 09:12:05 +0800 Subject: [PATCH] refactor: replace CacheService with cacheService for consistent caching in Inputbar components Updated the Inputbar and AgentSessionInputbar components to use the new cacheService for managing draft persistence and mentioned models, ensuring consistency across the application. --- .../src/pages/home/Inputbar/AgentSessionInputbar.tsx | 6 +++--- src/renderer/src/pages/home/Inputbar/Inputbar.tsx | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/renderer/src/pages/home/Inputbar/AgentSessionInputbar.tsx b/src/renderer/src/pages/home/Inputbar/AgentSessionInputbar.tsx index 2dbcd04067..2111822641 100644 --- a/src/renderer/src/pages/home/Inputbar/AgentSessionInputbar.tsx +++ b/src/renderer/src/pages/home/Inputbar/AgentSessionInputbar.tsx @@ -1,3 +1,4 @@ +import { cacheService } from '@data/CacheService' import { loggerService } from '@logger' import type { QuickPanelTriggerInfo } from '@renderer/components/QuickPanel' import { QuickPanelReservedSymbol, useQuickPanel } from '@renderer/components/QuickPanel' @@ -9,7 +10,6 @@ import { getModel } from '@renderer/hooks/useModel' import { useSettings } from '@renderer/hooks/useSettings' import { useTextareaResize } from '@renderer/hooks/useTextareaResize' import { useTimer } from '@renderer/hooks/useTimer' -import { CacheService } from '@renderer/services/CacheService' import { pauseTrace } from '@renderer/services/SpanManagerService' import { estimateUserPromptUsage } from '@renderer/services/TokenService' import { useAppDispatch, useAppSelector } from '@renderer/store' @@ -169,8 +169,8 @@ const AgentSessionInputbarInner: FC = ({ assistant, agentId, session setText, isEmpty: inputEmpty } = useInputText({ - initialValue: CacheService.get(draftCacheKey) ?? '', - onChange: (value) => CacheService.set(draftCacheKey, value, DRAFT_CACHE_TTL) + initialValue: cacheService.get(draftCacheKey) ?? '', + onChange: (value) => cacheService.set(draftCacheKey, value, DRAFT_CACHE_TTL) }) const { textareaRef, diff --git a/src/renderer/src/pages/home/Inputbar/Inputbar.tsx b/src/renderer/src/pages/home/Inputbar/Inputbar.tsx index e029599d05..9cd4077caa 100644 --- a/src/renderer/src/pages/home/Inputbar/Inputbar.tsx +++ b/src/renderer/src/pages/home/Inputbar/Inputbar.tsx @@ -1,3 +1,4 @@ +import { cacheService } from '@data/CacheService' import { usePreference } from '@data/hooks/usePreference' import { loggerService } from '@logger' import { @@ -23,7 +24,6 @@ import { useInputbarToolsState } from '@renderer/pages/home/Inputbar/context/InputbarToolsProvider' import { getDefaultTopic } from '@renderer/services/AssistantService' -import { CacheService } from '@renderer/services/CacheService' import { EVENT_NAMES, EventEmitter } from '@renderer/services/EventService' import FileManager from '@renderer/services/FileManager' import { checkRateLimit, getUserMessage } from '@renderer/services/MessagesService' @@ -57,7 +57,7 @@ const DRAFT_CACHE_TTL = 24 * 60 * 60 * 1000 // 24 hours const getMentionedModelsCacheKey = (assistantId: string) => `inputbar-mentioned-models-${assistantId}` const getValidatedCachedModels = (assistantId: string): Model[] => { - const cached = CacheService.get(getMentionedModelsCacheKey(assistantId)) + const cached = cacheService.get(getMentionedModelsCacheKey(assistantId)) if (!Array.isArray(cached)) return [] return cached.filter((model) => model?.id && model?.name) } @@ -135,8 +135,8 @@ const InputbarInner: FC = ({ assistant: initialAssistant, se const { setCouldAddImageFile } = useInputbarToolsInternalDispatch() const { text, setText } = useInputText({ - initialValue: CacheService.get(INPUTBAR_DRAFT_CACHE_KEY) ?? '', - onChange: (value) => CacheService.set(INPUTBAR_DRAFT_CACHE_KEY, value, DRAFT_CACHE_TTL) + initialValue: cacheService.get(INPUTBAR_DRAFT_CACHE_KEY) ?? '', + onChange: (value) => cacheService.set(INPUTBAR_DRAFT_CACHE_KEY, value, DRAFT_CACHE_TTL) }) const { textareaRef, @@ -208,7 +208,7 @@ const InputbarInner: FC = ({ assistant: initialAssistant, se }, [canAddImageFile, setCouldAddImageFile]) const onUnmount = useEffectEvent((id: string) => { - CacheService.set(getMentionedModelsCacheKey(id), mentionedModels, DRAFT_CACHE_TTL) + cacheService.set(getMentionedModelsCacheKey(id), mentionedModels, DRAFT_CACHE_TTL) }) useEffect(() => {