From a220f4b6eab93740834ba747323f5f7094ff57e8 Mon Sep 17 00:00:00 2001 From: Henry Li Date: Wed, 14 May 2025 18:47:28 +0800 Subject: [PATCH] feat: add python result and error handling (#141) --- .../components/research-activities-block.tsx | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/web/src/app/chat/components/research-activities-block.tsx b/web/src/app/chat/components/research-activities-block.tsx index 408e802..239bea4 100644 --- a/web/src/app/chat/components/research-activities-block.tsx +++ b/web/src/app/chat/components/research-activities-block.tsx @@ -304,10 +304,58 @@ function PythonToolCall({ toolCall }: { toolCall: ToolCallRuntime }) { + {toolCall.result && } ); } +function PythonToolCallResult({ result }: { result: string }) { + const { resolvedTheme } = useTheme(); + const hasError = useMemo( + () => result.includes("Error executing code:\n"), + [result], + ); + const error = useMemo(() => { + if (hasError) { + const parts = result.split("```\nError: "); + if (parts.length > 1) { + return parts[1]!.trim(); + } + } + return null; + }, [result, hasError]); + const stdout = useMemo(() => { + if (!hasError) { + const parts = result.split("```\nStdout: "); + if (parts.length > 1) { + return parts[1]!.trim(); + } + } + return null; + }, [result, hasError]); + return ( + <> +
+ {hasError ? "Error when executing the above code" : "Execution output"} +
+
+ + {error ?? stdout ?? "(empty)"} + +
+ + ); +} + function MCPToolCall({ toolCall }: { toolCall: ToolCallRuntime }) { const tool = useMemo(() => findMCPTool(toolCall.name), [toolCall.name]); const { resolvedTheme } = useTheme();