From edfc264b657eb9fbf9b2a9586841938bd271d3bf Mon Sep 17 00:00:00 2001 From: Danny Avila Date: Wed, 9 Jul 2025 18:44:42 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20fix:=20Handle=20optional=20argum?= =?UTF-8?q?ents=20in=20`useParseArgs`=20and=20improve=20tool=20call=20cond?= =?UTF-8?q?ition?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/Chat/Messages/Content/Part.tsx | 2 +- .../Messages/Content/Parts/ExecuteCode.tsx | 20 +++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/client/src/components/Chat/Messages/Content/Part.tsx b/client/src/components/Chat/Messages/Content/Part.tsx index c63dfe31e7..75e6d6ea17 100644 --- a/client/src/components/Chat/Messages/Content/Part.tsx +++ b/client/src/components/Chat/Messages/Content/Part.tsx @@ -85,7 +85,7 @@ const Part = memo( const isToolCall = 'args' in toolCall && (!toolCall.type || toolCall.type === ToolCallTypes.TOOL_CALL); - if (isToolCall && toolCall.name === Tools.execute_code) { + if (isToolCall && toolCall.name === Tools.execute_code && toolCall.args) { return ( { - let parsedArgs: ParsedArgs | string = args; + let parsedArgs: ParsedArgs | string | undefined | null = args; try { - parsedArgs = JSON.parse(args); + parsedArgs = JSON.parse(args || ''); } catch { // console.error('Failed to parse args:', e); } if (typeof parsedArgs === 'object') { return parsedArgs; } - const langMatch = args.match(/"lang"\s*:\s*"(\w+)"/); - const codeMatch = args.match(/"code"\s*:\s*"(.+?)(?="\s*,\s*"(session_id|args)"|"\s*})/s); + const langMatch = args?.match(/"lang"\s*:\s*"(\w+)"/); + const codeMatch = args?.match(/"code"\s*:\s*"(.+?)(?="\s*,\s*"(session_id|args)"|"\s*})/s); let code = ''; if (codeMatch) { @@ -51,7 +51,7 @@ export default function ExecuteCode({ attachments, }: { initialProgress: number; - args: string; + args?: string; output?: string; attachments?: TAttachment[]; }) { @@ -65,7 +65,7 @@ export default function ExecuteCode({ const outputRef = useRef(output); const prevShowCodeRef = useRef(showCode); - const { lang, code } = useParseArgs(args); + const { lang, code } = useParseArgs(args) ?? ({} as ParsedArgs); const progress = useProgress(initialProgress); useEffect(() => { @@ -144,7 +144,7 @@ export default function ExecuteCode({ onClick={() => setShowCode((prev) => !prev)} inProgressText={localize('com_ui_analyzing')} finishedText={localize('com_ui_analyzing_finished')} - hasInput={!!code.length} + hasInput={!!code?.length} isExpanded={showCode} />