feat: preempt active runs in interrupt queue mode

This commit is contained in:
William Valentin
2026-02-18 10:06:35 -08:00
parent b786b1435a
commit 9cbd66cdcc
7 changed files with 145 additions and 5 deletions
+24
View File
@@ -132,6 +132,30 @@ export class SessionBridge {
return true;
}
/**
* Request cancellation for the active operation in a session.
* Returns true if at least one connection in the session is currently busy.
*/
cancelSession(sessionId: string): boolean {
const clients = Array.from(this.clients.values()).filter((client) => client.sessionId === sessionId);
if (clients.length === 0) {
return false;
}
const hasBusyClient = clients.some((client) => client.busy);
if (!hasBusyClient) {
return false;
}
const agent = this.agents.get(sessionId);
if (!agent) {
return false;
}
agent.cancel();
return true;
}
/** Set onToolUse callback for a connection's agent. */
setOnToolUse(connectionId: string, callback: ((event: ToolUseEvent) => void) | undefined): void {
const client = this.clients.get(connectionId);