refactor(ai): migrate remaining AI IPC to shared HTTP routes

This commit is contained in:
digua committed 2026-06-02 15:41:21 +08:00
1 parent 7dcc37e714
commit bf14c68899
15 files changed
+293 -678

No files matched your search

+4 -166
View File
@@ -12,16 +12,6 @@ export type { TokenUsage, AgentRuntimeStatus, SerializedErrorInfo } from '../../
// ==================== 类型定义 ====================
export interface ChatMessage {
role: 'system' | 'user' | 'assistant'
content: string
}
export interface ChatOptions {
temperature?: number
maxTokens?: number
}
export interface DesensitizeRule {
id: string
label: string
@@ -32,22 +22,6 @@ export interface DesensitizeRule {
locales: string[]
}
export interface ToolCatalogEntry {
name: string
category: 'core' | 'analysis'
description: string
parameters: Record<string, unknown>
}
export interface ToolExecuteResult {
success: boolean
elapsed?: number
content?: Array<{ type: string; text: string }>
details?: Record<string, unknown>
error?: string
truncated?: boolean
}
export interface PreprocessConfig {
dataCleaning: boolean
mergeConsecutive: boolean
@@ -62,101 +36,7 @@ export interface PreprocessConfig {
// ==================== AI API (IPC-only subset) ====================
export const aiApi = {
// ===== 消息筛选/导出(worker-dependent) =====
filterMessagesWithContext: (
sessionId: string,
keywords?: string[],
timeFilter?: { startTs: number; endTs: number },
senderIds?: number[],
contextSize?: number,
page?: number,
pageSize?: number
): Promise<{
blocks: Array<{
startTs: number
endTs: number
messages: Array<{
id: number
senderName: string
senderPlatformId: string
senderAliases: string[]
senderAvatar: string | null
content: string
timestamp: number
type: number
replyToMessageId: string | null
replyToContent: string | null
replyToSenderName: string | null
isHit: boolean
}>
hitCount: number
}>
stats: {
totalMessages: number
hitMessages: number
totalChars: number
}
pagination: {
page: number
pageSize: number
totalBlocks: number
totalHits: number
hasMore: boolean
}
}> => {
return ipcRenderer.invoke(
'ai:filterMessagesWithContext',
sessionId,
keywords,
timeFilter,
senderIds,
contextSize,
page,
pageSize
)
},
getMultipleSessionsMessages: (
sessionId: string,
chatSessionIds: number[],
page?: number,
pageSize?: number
): Promise<{
blocks: Array<{
startTs: number
endTs: number
messages: Array<{
id: number
senderName: string
senderPlatformId: string
senderAliases: string[]
senderAvatar: string | null
content: string
timestamp: number
type: number
replyToMessageId: string | null
replyToContent: string | null
replyToSenderName: string | null
isHit: boolean
}>
hitCount: number
}>
stats: {
totalMessages: number
hitMessages: number
totalChars: number
}
pagination: {
page: number
pageSize: number
totalBlocks: number
totalHits: number
hasMore: boolean
}
}> => {
return ipcRenderer.invoke('ai:getMultipleSessionsMessages', sessionId, chatSessionIds, page, pageSize)
},
// filterMessagesWithContext / getMultipleSessionsMessages migrated to shared HTTP routes.
exportFilterResultToFile: (params: {
sessionId: string
@@ -188,50 +68,8 @@ export const aiApi = {
return ipcRenderer.invoke('ai:showLogFile')
},
// ===== 脱敏规则(node-runtime) =====
getDefaultDesensitizeRules: (locale: string): Promise<DesensitizeRule[]> => {
return ipcRenderer.invoke('ai:getDefaultDesensitizeRules', locale)
},
mergeDesensitizeRules: (existingRules: DesensitizeRule[], locale: string): Promise<DesensitizeRule[]> => {
return ipcRenderer.invoke('ai:mergeDesensitizeRules', existingRules, locale)
},
// ===== 工具测试(tool registry on main process) =====
getToolCatalog: (): Promise<ToolCatalogEntry[]> => {
return ipcRenderer.invoke('ai:getToolCatalog')
},
executeTool: (
testId: string,
toolName: string,
params: Record<string, unknown>,
sessionId: string
): Promise<ToolExecuteResult> => {
return ipcRenderer.invoke('ai:executeTool', testId, toolName, params, sessionId)
},
cancelToolTest: (testId: string): Promise<{ success: boolean }> => {
return ipcRenderer.invoke('ai:cancelToolTest', testId)
},
// ===== 上下文估算(needs conversationManager) =====
estimateContextTokens: (
conversationId: string
): Promise<{ success: boolean; tokens: number; messageCount?: number; error?: string }> => {
return ipcRenderer.invoke('ai:estimateContextTokens', conversationId)
},
// Desensitize rules, tool testing, estimateContextTokens have been migrated to shared HTTP routes.
}
// LLM chat (non-streaming) still uses IPC for Electron-specific config resolution
export const llmApi = {
chat: (
messages: ChatMessage[],
options?: ChatOptions
): Promise<{ success: boolean; content?: string; error?: string }> => {
return ipcRenderer.invoke('llm:chat', messages, options)
},
}
// LLM chat (non-streaming) IPC has been removed — no frontend consumers remain.
// All LLM calls now go through shared HTTP/SSE routes.
+1 -8
View File
@@ -21,14 +21,7 @@ export const api = {
}
},
receive: (channel: string, func: (...args: unknown[]) => void) => {
const validChannels = [
'show-message',
'chat:importProgress',
'merge:parseProgress',
'llm:streamChunk',
'agent:streamChunk',
'agent:complete',
]
const validChannels = ['show-message', 'chat:importProgress', 'merge:parseProgress']
if (validChannels.includes(channel)) {
// Deliberately strip event as it includes `sender`
ipcRenderer.on(channel, (_event, ...args) => func(...args))