refactor: 重构部分架构

This commit is contained in:
digua
2025-12-05 01:11:37 +08:00
parent 04dc2a79c1
commit 4fb9255605
18 changed files with 1903 additions and 1503 deletions
+29
View File
@@ -278,6 +278,31 @@ interface AgentApi {
abort: (requestId: string) => Promise<{ success: boolean; error?: string }>
}
// Cache API 类型
interface CacheDirectoryInfo {
id: string
name: string
description: string
path: string
icon: string
canClear: boolean
size: number
fileCount: number
exists: boolean
}
interface CacheInfo {
baseDir: string
directories: CacheDirectoryInfo[]
totalSize: number
}
interface CacheApi {
getInfo: () => Promise<CacheInfo>
clear: (cacheId: string) => Promise<{ success: boolean; error?: string; message?: string }>
openDir: (cacheId: string) => Promise<{ success: boolean; error?: string }>
}
declare global {
interface Window {
electron: ElectronAPI
@@ -287,6 +312,7 @@ declare global {
aiApi: AiApi
llmApi: LlmApi
agentApi: AgentApi
cacheApi: CacheApi
}
}
@@ -297,6 +323,7 @@ export {
AiApi,
LlmApi,
AgentApi,
CacheApi,
SearchMessageResult,
AIConversation,
AIMessage,
@@ -309,4 +336,6 @@ export {
AgentStreamChunk,
AgentResult,
ToolContext,
CacheDirectoryInfo,
CacheInfo,
}
+45
View File
@@ -797,6 +797,48 @@ const agentApi = {
},
}
// Cache API - 缓存管理
interface CacheDirectoryInfo {
id: string
name: string
description: string
path: string
icon: string
canClear: boolean
size: number
fileCount: number
exists: boolean
}
interface CacheInfo {
baseDir: string
directories: CacheDirectoryInfo[]
totalSize: number
}
const cacheApi = {
/**
* 获取所有缓存目录信息
*/
getInfo: (): Promise<CacheInfo> => {
return ipcRenderer.invoke('cache:getInfo')
},
/**
* 清理指定缓存目录
*/
clear: (cacheId: string): Promise<{ success: boolean; error?: string; message?: string }> => {
return ipcRenderer.invoke('cache:clear', cacheId)
},
/**
* 在文件管理器中打开缓存目录
*/
openDir: (cacheId: string): Promise<{ success: boolean; error?: string }> => {
return ipcRenderer.invoke('cache:openDir', cacheId)
},
}
// 扩展 api,添加 dialog 功能
const extendedApi = {
...api,
@@ -819,6 +861,7 @@ if (process.contextIsolated) {
contextBridge.exposeInMainWorld('aiApi', aiApi)
contextBridge.exposeInMainWorld('llmApi', llmApi)
contextBridge.exposeInMainWorld('agentApi', agentApi)
contextBridge.exposeInMainWorld('cacheApi', cacheApi)
} catch (error) {
console.error(error)
}
@@ -837,4 +880,6 @@ if (process.contextIsolated) {
window.llmApi = llmApi
// @ts-ignore (define in dts)
window.agentApi = agentApi
// @ts-ignore (define in dts)
window.cacheApi = cacheApi
}