fix(hooks): handle agent_error events in useGatewayChat

Desktop path already forwards agent_error to chat.setError() via
use-local-chat.ts, but the Web/Gateway path was missing this handling.
Add agent_error interception in the StreamAction branch so Web clients
render LLM errors the same way Desktop does.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Naiyuan Qing 2026-02-09 07:30:35 +08:00
parent be71614cf5
commit 56ebe613db

View file

@ -50,6 +50,12 @@ export function useGatewayChat({ client, hubId, agentId }: UseGatewayChatOptions
client.onMessage((msg) => {
if (msg.action === StreamAction) {
const payload = msg.payload as StreamPayload;
if (payload.event.type === "agent_error") {
const errorMsg = (payload.event as { error?: string }).error ?? "Unknown error";
chat.setError({ code: "AGENT_ERROR", message: errorMsg });
setIsLoading(false);
return;
}
chat.handleStream(payload);
if (payload.event.type === "message_start") setIsLoading(true);
if (payload.event.type === "message_end") setIsLoading(false);