diff --git a/src/auto-reply/command-reply.ts b/src/auto-reply/command-reply.ts index 108fb039b..7b0043b8f 100644 --- a/src/auto-reply/command-reply.ts +++ b/src/auto-reply/command-reply.ts @@ -161,6 +161,7 @@ type CommandReplyParams = { verboseLevel?: "off" | "on"; onPartialReply?: (payload: ReplyPayload) => Promise | void; runId?: string; + onAgentEvent?: (evt: { stream: string; data: Record }) => void; }; export type CommandReplyMeta = { @@ -596,6 +597,14 @@ export async function runCommandReply( args: ev.args, }, }); + params.onAgentEvent?.({ + stream: "tool", + data: { + phase: "start", + name: ev.toolName, + toolCallId: ev.toolCallId, + }, + }); } if ( @@ -620,6 +629,15 @@ export async function runCommandReply( meta, }, }); + params.onAgentEvent?.({ + stream: "tool", + data: { + phase: "result", + name: toolName, + toolCallId, + meta, + }, + }); if ( pendingToolName && @@ -646,6 +664,13 @@ export async function runCommandReply( if (ev.type === "message_end") { streamAssistantFinal(ev.message); + const text = extractRpcAssistantText(line); + if (text) { + params.onAgentEvent?.({ + stream: "assistant", + data: { text }, + }); + } } // Preserve existing partial reply hook when provided.