mirror of
https://github.com/multica-ai/multica.git
synced 2026-07-27 21:33:41 +02:00
feat(agent): add AgentErrorEvent for error propagation via subscribe
Add agent_error event type to MulticaEvent union so errors from agent runs reach subscribe() consumers (Desktop IPC + Channel). Make emitMulticaEvent public on Runner so AsyncAgent can emit errors. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -48,12 +48,16 @@ export class AsyncAgent {
|
||||
await this.agent.flushSession();
|
||||
// Normal text is delivered via message_end event; only handle errors here
|
||||
if (result.error) {
|
||||
console.error(`[AsyncAgent] Agent run error: ${result.error}`);
|
||||
this.channel.send({ id: uuidv7(), content: `[error] ${result.error}` });
|
||||
this.agent.emitMulticaEvent({ type: "agent_error", error: result.error });
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
const message = err instanceof Error ? err.message : String(err);
|
||||
console.error(`[AsyncAgent] Agent run exception: ${message}`);
|
||||
this.channel.send({ id: uuidv7(), content: `[error] ${message}` });
|
||||
this.agent.emitMulticaEvent({ type: "agent_error", error: message });
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -26,5 +26,11 @@ export type CompactionEndEvent = {
|
||||
reason: "count" | "tokens" | "summary" | "pruning";
|
||||
};
|
||||
|
||||
/** Emitted when the agent encounters an error (LLM failure, quota exceeded, etc.) */
|
||||
export type AgentErrorEvent = {
|
||||
type: "agent_error";
|
||||
error: string;
|
||||
};
|
||||
|
||||
/** Union of all Multica-specific events */
|
||||
export type MulticaEvent = CompactionStartEvent | CompactionEndEvent;
|
||||
export type MulticaEvent = CompactionStartEvent | CompactionEndEvent | AgentErrorEvent;
|
||||
|
||||
@@ -342,7 +342,7 @@ export class Agent {
|
||||
};
|
||||
}
|
||||
|
||||
private emitMulticaEvent(event: MulticaEvent): void {
|
||||
emitMulticaEvent(event: MulticaEvent): void {
|
||||
for (const fn of this.multicaListeners) {
|
||||
try {
|
||||
fn(event);
|
||||
|
||||
Reference in New Issue
Block a user