Add agent state methods to CustomToolContext and fix abort signature

CustomToolContext now has:
- isIdle() - check if agent is streaming
- hasQueuedMessages() - check if user has queued messages
- abort() - abort current operation (fire-and-forget)

Changed abort() signature from Promise<void> to void in both
HookContext and CustomToolContext. The abort is fire-and-forget:
it calls session.abort() without awaiting, so the abort signal
is set immediately while waitForIdle() runs in the background.

Fixes #388
This commit is contained in:
Mario Zechner 2026-01-02 00:31:23 +01:00
parent 0d9fddec1e
commit 03159d2f4b
10 changed files with 68 additions and 9 deletions

View file

@ -1878,6 +1878,11 @@ export class AgentSession {
sessionManager: this.sessionManager,
modelRegistry: this._modelRegistry,
model: this.agent.state.model,
isIdle: () => !this.isStreaming,
hasQueuedMessages: () => this.queuedMessageCount > 0,
abort: () => {
this.abort();
},
};
for (const { tool } of this._customTools) {