From e9165a323681d42fcb55b69529688c95c578bc72 Mon Sep 17 00:00:00 2001 From: Ishaan Gupta Date: Tue, 9 Jun 2026 18:07:27 +0530 Subject: [PATCH] Harden Nova connector tool rendering --- .../components/chat/message/agent-message.tsx | 46 +++++++++++++------ 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/apps/web/components/chat/message/agent-message.tsx b/apps/web/components/chat/message/agent-message.tsx index cf047c68..c7d76485 100644 --- a/apps/web/components/chat/message/agent-message.tsx +++ b/apps/web/components/chat/message/agent-message.tsx @@ -142,16 +142,33 @@ const STATUS_COPY: Record< }, } +function connectorToolName(part: ToolCallDisplayPart): string { + return part.type.startsWith("tool-") + ? part.type.slice("tool-".length) + : part.type +} + +function parseConnectorOutput(value: string): NovaConnectorToolOutput | null { + try { + return JSON.parse(value) as NovaConnectorToolOutput + } catch { + return null + } +} + function unwrapToolOutput(output: unknown): NovaConnectorToolOutput | null { if (typeof output === "string") { - try { - return JSON.parse(output) as NovaConnectorToolOutput - } catch { - return null - } + return parseConnectorOutput(output) } if (!output || typeof output !== "object") return null const record = output as Record + for (const key of ["value", "result", "data", "output"]) { + const nested = record[key] + if (nested && nested !== output) { + const parsed = unwrapToolOutput(nested) + if (parsed) return parsed + } + } if ( record.type === "json" && record.value && @@ -160,17 +177,17 @@ function unwrapToolOutput(output: unknown): NovaConnectorToolOutput | null { return record.value as NovaConnectorToolOutput } if (record.type === "text" && typeof record.value === "string") { - try { - return JSON.parse(record.value) as NovaConnectorToolOutput - } catch { - return null - } + return parseConnectorOutput(record.value) + } + if (typeof record.text === "string") { + return parseConnectorOutput(record.text) } return record as NovaConnectorToolOutput } function StatusPill({ status }: { status?: NovaConnectorStatus }) { - const copy = STATUS_COPY[status ?? "not_connected"] + const copy = + STATUS_COPY[status ?? "not_connected"] ?? STATUS_COPY.not_connected return ( ) } - if (isError || !output) { + if (isError) { return (
Couldn't load connector setup.
) } + if (!output) return null if (output.success === false) { return (
@@ -748,7 +766,7 @@ function BashToolDisplay({ part }: { part: ToolCallDisplayPart }) { function ToolCallDisplay({ part }: { part: ToolCallDisplayPart }) { const [expanded, setExpanded] = useState(false) - const toolName = part.type.replace("tool-", "") + const toolName = connectorToolName(part) if (NOVA_CONNECTOR_TOOLS.has(toolName)) { return }