-
Notifications
You must be signed in to change notification settings - Fork 28
feat: 添加 Agent 会话归档和搜索功能 #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -5,7 +5,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { ipcMain, nativeTheme, shell, dialog, BrowserWindow } from 'electron' | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { IPC_CHANNELS, CHANNEL_IPC_CHANNELS, CHAT_IPC_CHANNELS, AGENT_IPC_CHANNELS, ENVIRONMENT_IPC_CHANNELS, PROXY_IPC_CHANNELS, GITHUB_RELEASE_IPC_CHANNELS } from '@proma/shared' | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { IPC_CHANNELS, CHANNEL_IPC_CHANNELS, CHAT_IPC_CHANNELS, AGENT_IPC_CHANNELS, ENVIRONMENT_IPC_CHANNELS, PROXY_IPC_CHANNELS, GITHUB_RELEASE_IPC_CHANNELS, USAGE_IPC_CHANNELS } from '@proma/shared' | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { USER_PROFILE_IPC_CHANNELS, SETTINGS_IPC_CHANNELS } from '../types' | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import type { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| RuntimeStatus, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -44,6 +44,9 @@ import type { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| SystemProxyDetectResult, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| GitHubRelease, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| GitHubReleaseListOptions, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| UsageStats, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ConversationUsage, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| UsageSettings, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } from '@proma/shared' | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import type { UserProfile, AppSettings } from '../types' | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { getRuntimeStatus, getGitRepoStatus } from './lib/runtime-init' | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -109,6 +112,12 @@ import { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| listReleases as listGitHubReleases, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| getReleaseByTag, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } from './lib/github-release-service' | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| getUsageStats, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| getConversationUsage, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| getUsageSettings, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| updateUsageSettings, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } from './lib/usage-service' | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+115
to
121
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { | |
| getUsageStats, | |
| getConversationUsage, | |
| getUsageSettings, | |
| updateUsageSettings, | |
| } from './lib/usage-service' | |
| // Usage service stubs: underlying implementation not available in this build. | |
| // These implementations return null so usage-related IPC calls fail gracefully | |
| // instead of causing module resolution errors at runtime. | |
| const getUsageStats: any = async (..._args: any[]) => { | |
| return null | |
| } | |
| const getConversationUsage: any = async (..._args: any[]) => { | |
| return null | |
| } | |
| const getUsageSettings: any = async (..._args: any[]) => { | |
| return null | |
| } | |
| const updateUsageSettings: any = async (..._args: any[]) => { | |
| return null | |
| } |
Copilot
AI
Feb 19, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
切换归档状态时通过 listAgentSessions() 读取并排序全量会话再 find 当前项,属于不必要的 IO + 排序开销。既然 agent-session-manager 已提供 getAgentSessionMeta(id),建议改用它读取当前 meta(或直接在 updateAgentSessionMeta 内处理不存在),减少额外开销。
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,7 @@ | |
| */ | ||
|
|
||
| import { contextBridge, ipcRenderer } from 'electron' | ||
| import { IPC_CHANNELS, CHANNEL_IPC_CHANNELS, CHAT_IPC_CHANNELS, AGENT_IPC_CHANNELS, ENVIRONMENT_IPC_CHANNELS, PROXY_IPC_CHANNELS, GITHUB_RELEASE_IPC_CHANNELS } from '@proma/shared' | ||
| import { IPC_CHANNELS, CHANNEL_IPC_CHANNELS, CHAT_IPC_CHANNELS, AGENT_IPC_CHANNELS, ENVIRONMENT_IPC_CHANNELS, PROXY_IPC_CHANNELS, GITHUB_RELEASE_IPC_CHANNELS, USAGE_IPC_CHANNELS } from '@proma/shared' | ||
| import { USER_PROFILE_IPC_CHANNELS, SETTINGS_IPC_CHANNELS } from '../types' | ||
|
Comment on lines
+9
to
10
|
||
| import type { | ||
| RuntimeStatus, | ||
|
|
@@ -50,6 +50,9 @@ import type { | |
| SystemProxyDetectResult, | ||
| GitHubRelease, | ||
| GitHubReleaseListOptions, | ||
| UsageStats, | ||
| ConversationUsage, | ||
| UsageSettings, | ||
| } from '@proma/shared' | ||
| import type { UserProfile, AppSettings } from '../types' | ||
|
|
||
|
|
@@ -239,6 +242,9 @@ export interface ElectronAPI { | |
| /** 删除 Agent 会话 */ | ||
| deleteAgentSession: (id: string) => Promise<void> | ||
|
|
||
| /** 切换 Agent 会话归档状态 */ | ||
| toggleArchiveAgentSession: (id: string) => Promise<AgentSessionMeta> | ||
|
|
||
| /** 生成 Agent 会话标题 */ | ||
| generateAgentTitle: (input: AgentGenerateTitleInput) => Promise<string | null> | ||
|
|
||
|
|
@@ -361,6 +367,20 @@ export interface ElectronAPI { | |
| // 工作区文件变化通知 | ||
| onCapabilitiesChanged: (callback: () => void) => () => void | ||
| onWorkspaceFilesChanged: (callback: () => void) => () => void | ||
|
|
||
| // ===== 使用统计相关 ===== | ||
|
|
||
| /** 获取使用量统计总览 */ | ||
| getUsageStats: (days?: number) => Promise<UsageStats> | ||
|
|
||
| /** 获取指定对话的使用量详情 */ | ||
| getConversationUsage: (conversationId: string) => Promise<ConversationUsage | null> | ||
|
|
||
| /** 获取使用统计设置 */ | ||
| getUsageSettings: () => Promise<UsageSettings> | ||
|
|
||
| /** 更新使用统计设置 */ | ||
| updateUsageSettings: (settings: UsageSettings) => Promise<UsageSettings> | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -594,6 +614,10 @@ const electronAPI: ElectronAPI = { | |
| return ipcRenderer.invoke(AGENT_IPC_CHANNELS.DELETE_SESSION, id) | ||
| }, | ||
|
|
||
| toggleArchiveAgentSession: (id: string) => { | ||
| return ipcRenderer.invoke(AGENT_IPC_CHANNELS.TOGGLE_ARCHIVE, id) | ||
| }, | ||
|
|
||
| generateAgentTitle: (input: AgentGenerateTitleInput) => { | ||
| return ipcRenderer.invoke(AGENT_IPC_CHANNELS.GENERATE_TITLE, input) | ||
| }, | ||
|
|
@@ -754,6 +778,23 @@ const electronAPI: ElectronAPI = { | |
| getReleaseByTag: (tag) => { | ||
| return ipcRenderer.invoke(GITHUB_RELEASE_IPC_CHANNELS.GET_RELEASE_BY_TAG, tag) | ||
| }, | ||
|
|
||
| // 使用统计 | ||
| getUsageStats: (days?: number) => { | ||
| return ipcRenderer.invoke(USAGE_IPC_CHANNELS.GET_USAGE_STATS, days) | ||
| }, | ||
|
|
||
| getConversationUsage: (conversationId: string) => { | ||
| return ipcRenderer.invoke(USAGE_IPC_CHANNELS.GET_CONVERSATION_USAGE, conversationId) | ||
| }, | ||
|
|
||
| getUsageSettings: () => { | ||
| return ipcRenderer.invoke(USAGE_IPC_CHANNELS.GET_USAGE_SETTINGS) | ||
| }, | ||
|
|
||
| updateUsageSettings: (settings: UsageSettings) => { | ||
| return ipcRenderer.invoke(USAGE_IPC_CHANNELS.UPDATE_USAGE_SETTINGS, settings) | ||
| }, | ||
| } | ||
|
|
||
| // 将 API 暴露到渲染进程的 window 对象上 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -444,6 +444,55 @@ export const currentAgentSessionDraftAtom = atom( | |
| } | ||
| ) | ||
|
|
||
| // ===== 会话归档与搜索 ===== | ||
|
|
||
| /** 归档视图切换 */ | ||
| export const showArchivedSessionsAtom = atom<boolean>(false) | ||
|
|
||
| /** 会话搜索关键词 */ | ||
| export const sessionSearchKeywordAtom = atom<string>('') | ||
|
|
||
| /** 获取活跃会话(按工作区过滤 + 排除归档) */ | ||
| export const activeAgentSessionsAtom = atom((get) => { | ||
| const sessions = get(agentSessionsAtom) | ||
| const currentWorkspaceId = get(currentAgentWorkspaceIdAtom) | ||
| return sessions.filter( | ||
| (s) => s.workspaceId === currentWorkspaceId && !s.archived, | ||
| ) | ||
| }) | ||
|
|
||
| /** 获取归档会话 */ | ||
| export const archivedAgentSessionsAtom = atom((get) => { | ||
| const sessions = get(agentSessionsAtom) | ||
| const currentWorkspaceId = get(currentAgentWorkspaceIdAtom) | ||
| return sessions.filter( | ||
| (s) => s.workspaceId === currentWorkspaceId && s.archived, | ||
| ) | ||
| }) | ||
|
|
||
| /** 过滤后的会话列表(结合工作区、归档状态、搜索关键词) */ | ||
| export const filteredAgentSessionsAtom = atom((get) => { | ||
| const sessions = get(agentSessionsAtom) | ||
| const currentWorkspaceId = get(currentAgentWorkspaceIdAtom) | ||
| const showArchived = get(showArchivedSessionsAtom) | ||
| const keyword = get(sessionSearchKeywordAtom) | ||
|
|
||
| return sessions.filter((s) => { | ||
| // 工作区筛选 | ||
| if (s.workspaceId !== currentWorkspaceId) return false | ||
|
|
||
| // 归档状态筛选 | ||
| if (showArchived !== !!s.archived) return false | ||
|
|
||
| // 关键词搜索 | ||
| if (keyword.trim()) { | ||
| return s.title.toLowerCase().includes(keyword.toLowerCase()) | ||
| } | ||
|
Comment on lines
+487
to
+490
|
||
|
|
||
| return true | ||
| }) | ||
| }) | ||
|
|
||
| // ===== 后台任务管理 ===== | ||
|
|
||
| /** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@proma/shared中当前没有导出USAGE_IPC_CHANNELS,且本文件引用的UsageStats/ConversationUsage/UsageSettings类型在 shared 包中也未找到定义,会导致主进程编译失败。建议移除 usage 相关改动或先在 shared 包补齐导出。