feat(session): 实现会话保存和加载功能

- 在 AcpConnection 和 AcpSessionManager 中添加会话保存方法
- 在 QwenAgentManager 中实现通过 ACP 和直接保存会话的功能
- 在前端添加保存会话对话框和相关交互逻辑
- 新增 QwenSessionManager 用于直接操作文件系统保存和加载会话
This commit is contained in:
yiliang114
2025-11-21 23:51:48 +08:00
parent e2beecb9c4
commit ce07fb2b3f
13 changed files with 1379 additions and 59 deletions

View File

@@ -41,6 +41,7 @@ import { AcpSessionManager } from './acpSessionManager.js';
* ✅ session/prompt - Send user message to agent
* ✅ session/cancel - Cancel current generation
* ✅ session/load - Load previous session
* ✅ session/save - Save current session
*
* Custom Methods (Not in standard ACP):
* ⚠️ session/list - List available sessions (custom extension)
@@ -348,6 +349,21 @@ export class AcpConnection {
await this.sessionManager.cancelSession(this.child);
}
/**
* 保存当前会话
*
* @param tag - 保存标签
* @returns 保存响应
*/
async saveSession(tag: string): Promise<AcpResponse> {
return this.sessionManager.saveSession(
tag,
this.child,
this.pendingRequests,
this.nextRequestId,
);
}
/**
* 断开连接
*/

View File

@@ -349,6 +349,40 @@ export class AcpSessionManager {
console.log('[ACP] Cancel notification sent');
}
/**
* 保存当前会话
*
* @param tag - 保存标签
* @param child - 子进程实例
* @param pendingRequests - 待处理请求映射表
* @param nextRequestId - 请求ID计数器
* @returns 保存响应
*/
async saveSession(
tag: string,
child: ChildProcess | null,
pendingRequests: Map<number, PendingRequest<unknown>>,
nextRequestId: { value: number },
): Promise<AcpResponse> {
if (!this.sessionId) {
throw new Error('No active ACP session');
}
console.log('[ACP] Saving session with tag:', tag);
const response = await this.sendRequest<AcpResponse>(
AGENT_METHODS.session_save,
{
sessionId: this.sessionId,
tag,
},
child,
pendingRequests,
nextRequestId,
);
console.log('[ACP] Session save response:', response);
return response;
}
/**
* 重置会话管理器状态
*/

View File

@@ -18,9 +18,10 @@
* ✅ initialize - Protocol initialization
* ✅ authenticate - User authentication
* ✅ session/new - Create new session
* session/load - Load existing session (not implemented in CLI)
* session/load - Load existing session
* ✅ session/prompt - Send user message to agent
* ✅ session/cancel - Cancel current generation
* ✅ session/save - Save current session
*/
export const AGENT_METHODS = {
authenticate: 'authenticate',
@@ -29,6 +30,7 @@ export const AGENT_METHODS = {
session_load: 'session/load',
session_new: 'session/new',
session_prompt: 'session/prompt',
session_save: 'session/save',
} as const;
/**