mirror of
https://git.mirrors.martin98.com/https://github.com/bytedance/deer-flow
synced 2025-08-19 19:59:08 +08:00
feat: add python result and error handling (#141)
This commit is contained in:
parent
f73a7a229c
commit
a220f4b6ea
@ -304,10 +304,58 @@ function PythonToolCall({ toolCall }: { toolCall: ToolCallRuntime }) {
|
|||||||
</SyntaxHighlighter>
|
</SyntaxHighlighter>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{toolCall.result && <PythonToolCallResult result={toolCall.result} />}
|
||||||
</section>
|
</section>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 (
|
||||||
|
<>
|
||||||
|
<div className="mt-4 font-medium italic">
|
||||||
|
{hasError ? "Error when executing the above code" : "Execution output"}
|
||||||
|
</div>
|
||||||
|
<div className="bg-accent mt-2 max-h-[400px] max-w-[calc(100%-120px)] overflow-y-auto rounded-md p-2 text-sm">
|
||||||
|
<SyntaxHighlighter
|
||||||
|
language="plaintext"
|
||||||
|
style={resolvedTheme === "dark" ? dark : docco}
|
||||||
|
customStyle={{
|
||||||
|
color: hasError ? "red" : "inherit",
|
||||||
|
background: "transparent",
|
||||||
|
border: "none",
|
||||||
|
boxShadow: "none",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{error ?? stdout ?? "(empty)"}
|
||||||
|
</SyntaxHighlighter>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function MCPToolCall({ toolCall }: { toolCall: ToolCallRuntime }) {
|
function MCPToolCall({ toolCall }: { toolCall: ToolCallRuntime }) {
|
||||||
const tool = useMemo(() => findMCPTool(toolCall.name), [toolCall.name]);
|
const tool = useMemo(() => findMCPTool(toolCall.name), [toolCall.name]);
|
||||||
const { resolvedTheme } = useTheme();
|
const { resolvedTheme } = useTheme();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user