feat(chat): add /stop cancellation command across gateway and telegram
This commit is contained in:
@@ -36,6 +36,7 @@ describe('createAgentHandlers command fast-path', () => {
|
||||
setBusy: vi.fn(),
|
||||
setOnToolUse: vi.fn(),
|
||||
isBusy: vi.fn(() => false),
|
||||
cancel: vi.fn(() => true),
|
||||
};
|
||||
|
||||
const sessionManager = {
|
||||
@@ -219,6 +220,26 @@ describe('createAgentHandlers command fast-path', () => {
|
||||
expect(((sent[0] as GatewayEvent).data as { content: string }).content).toContain('Reset default to: anthropic/claude-sonnet-4');
|
||||
});
|
||||
|
||||
it('handles /stop command via fast-path and requests cancellation', async () => {
|
||||
const sent: OutboundMessage[] = [];
|
||||
const send = vi.fn((msg: OutboundMessage) => sent.push(msg));
|
||||
const req: GatewayRequest = {
|
||||
id: 12,
|
||||
method: 'agent.send',
|
||||
params: {
|
||||
message: '/stop',
|
||||
connectionId: 'conn-1',
|
||||
metadata: { isCommand: true, command: 'stop' },
|
||||
},
|
||||
};
|
||||
|
||||
await handlers['agent.send'](req, send);
|
||||
|
||||
expect(sessionBridge.cancel).toHaveBeenCalledWith('conn-1');
|
||||
expect(mockAgent.process).not.toHaveBeenCalled();
|
||||
expect(((sent[0] as GatewayEvent).data as { content: string }).content).toContain('Cancellation requested');
|
||||
});
|
||||
|
||||
it('falls through to agent.process for unknown commands', async () => {
|
||||
const sent: OutboundMessage[] = [];
|
||||
const send = vi.fn((msg: OutboundMessage) => sent.push(msg));
|
||||
|
||||
@@ -294,6 +294,12 @@ export function createAgentHandlers(deps: AgentHandlerDeps) {
|
||||
}
|
||||
return 'Session reset.';
|
||||
},
|
||||
cancelRun: () => {
|
||||
const cancelled = deps.sessionBridge.cancel(connectionId);
|
||||
return cancelled
|
||||
? 'Cancellation requested. The active operation will stop at the next safe point.'
|
||||
: 'No active operation to cancel.';
|
||||
},
|
||||
getApprovals: () => {
|
||||
if (!deps.hookEngine) {
|
||||
return 'Approval gates are not enabled in this runtime.';
|
||||
|
||||
Reference in New Issue
Block a user