feat: expose bot task progress
This commit is contained in:
+21
-13
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user