feat: forward tool/assistant events to agent bus

This commit is contained in:
Peter Steinberger
2025-12-09 00:44:30 +01:00
parent 2d1f1640f3
commit b7b1714f32

View File

@@ -161,6 +161,7 @@ type CommandReplyParams = {
verboseLevel?: "off" | "on";
onPartialReply?: (payload: ReplyPayload) => Promise<void> | void;
runId?: string;
onAgentEvent?: (evt: { stream: string; data: Record<string, unknown> }) => 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.