feat: expose bot task progress

This commit is contained in:
zenord
2026-08-17 14:37:51 +08:00
parent 91bf4e7a0c
commit 2795567f8c
13 changed files with 321 additions and 54 deletions
+21 -13
View File
@@ -7,6 +7,7 @@ import type { PermissionPolicy } from "../config.js";
export interface AcpClientOptions {
initializeTimeoutMs: number;
policy: PermissionPolicy;
onSessionActivity?: () => void;
}
export class AcpClient {
@@ -47,19 +48,24 @@ export class AcpClient {
async resumeSession(sessionId: string, cwd: string): Promise<void> {
this.collecting = false;
this.chunks = [];
if (this.capabilities.sessionCapabilities?.resume) {
try {
await this.connection.agent.request(acp.methods.agent.session.resume, { sessionId, cwd, mcpServers: [] });
} catch (error) {
if (!this.capabilities.loadSession) throw error;
await this.connection.agent.request(acp.methods.agent.session.load, { sessionId, cwd, mcpServers: [] });
}
} else if (this.capabilities.loadSession) {
await this.connection.agent.request(acp.methods.agent.session.load, { sessionId, cwd, mcpServers: [] });
} else {
throw new Error("ACP backend cannot resume or load sessions");
}
this.activeSessionId = sessionId;
try {
if (this.capabilities.sessionCapabilities?.resume) {
try {
await this.connection.agent.request(acp.methods.agent.session.resume, { sessionId, cwd, mcpServers: [] });
} catch (error) {
if (!this.capabilities.loadSession) throw error;
await this.connection.agent.request(acp.methods.agent.session.load, { sessionId, cwd, mcpServers: [] });
}
} else if (this.capabilities.loadSession) {
await this.connection.agent.request(acp.methods.agent.session.load, { sessionId, cwd, mcpServers: [] });
} else {
throw new Error("ACP backend cannot resume or load sessions");
}
} catch (error) {
this.activeSessionId = undefined;
throw error;
}
this.chunks = [];
}
@@ -91,7 +97,9 @@ export class AcpClient {
close(error?: unknown): void { this.connection.close(error); }
private handleUpdate(notification: SessionNotification): void {
if (!this.collecting || notification.sessionId !== this.activeSessionId) return;
if (notification.sessionId !== this.activeSessionId) return;
this.options.onSessionActivity?.();
if (!this.collecting) return;
const update = notification.update;
if (update.sessionUpdate === "agent_message_chunk" && update.content.type === "text") this.chunks.push(update.content.text);
}