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:
@@ -71,7 +71,7 @@ export class HookRunner {
|
||||
private getModel: () => Model<any> | undefined = () => undefined;
|
||||
private isIdleFn: () => boolean = () => true;
|
||||
private waitForIdleFn: () => Promise<void> = async () => {};
|
||||
private abortFn: () => Promise<void> = async () => {};
|
||||
private abortFn: () => void = () => {};
|
||||
private hasQueuedMessagesFn: () => boolean = () => false;
|
||||
private newSessionHandler: NewSessionHandler = async () => ({ cancelled: false });
|
||||
private branchHandler: BranchHandler = async () => ({ cancelled: false });
|
||||
@@ -107,8 +107,8 @@ export class HookRunner {
|
||||
isIdle?: () => boolean;
|
||||
/** Function to wait for agent to be idle */
|
||||
waitForIdle?: () => Promise<void>;
|
||||
/** Function to abort current operation */
|
||||
abort?: () => Promise<void>;
|
||||
/** Function to abort current operation (fire-and-forget) */
|
||||
abort?: () => void;
|
||||
/** Function to check if there are queued messages */
|
||||
hasQueuedMessages?: () => boolean;
|
||||
/** UI context for interactive prompts */
|
||||
@@ -119,7 +119,7 @@ export class HookRunner {
|
||||
this.getModel = options.getModel;
|
||||
this.isIdleFn = options.isIdle ?? (() => true);
|
||||
this.waitForIdleFn = options.waitForIdle ?? (async () => {});
|
||||
this.abortFn = options.abort ?? (async () => {});
|
||||
this.abortFn = options.abort ?? (() => {});
|
||||
this.hasQueuedMessagesFn = options.hasQueuedMessages ?? (() => false);
|
||||
// Store session handlers for HookCommandContext
|
||||
if (options.newSessionHandler) {
|
||||
|
||||
@@ -150,7 +150,7 @@ export interface HookContext {
|
||||
/** Whether the agent is idle (not streaming) */
|
||||
isIdle(): boolean;
|
||||
/** Abort the current agent operation (fire-and-forget, does not wait) */
|
||||
abort(): Promise<void>;
|
||||
abort(): void;
|
||||
/** Whether there are queued messages waiting to be processed */
|
||||
hasQueuedMessages(): boolean;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user