mirror of
https://github.com/hellodigua/ChatLab.git
synced 2026-05-06 21:16:10 +08:00
refactor: 重构部分架构
This commit is contained in:
Vendored
+29
@@ -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,
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user