From a71f17f1d6e1e5a1d17c76db12a19b7aee1a4752 Mon Sep 17 00:00:00 2001 From: Brace Sproul Date: Thu, 19 Jun 2025 12:57:27 -0700 Subject: [PATCH] fix: command.join() is not a function (#270) * fix: command.join() is not a function * fix: better typing --- .../web/src/components/gen-ui/action-step.tsx | 46 ++++++++++++------- .../web/src/components/thread/messages/ai.tsx | 18 +++----- 2 files changed, 35 insertions(+), 29 deletions(-) diff --git a/apps/web/src/components/gen-ui/action-step.tsx b/apps/web/src/components/gen-ui/action-step.tsx index 6597ee6d..cfc05988 100644 --- a/apps/web/src/components/gen-ui/action-step.tsx +++ b/apps/web/src/components/gen-ui/action-step.tsx @@ -12,6 +12,18 @@ import { MessageSquare, FileText, } from "lucide-react"; +import { + createApplyPatchToolFields, + createShellToolFields, +} from "@open-swe/shared/open-swe/tools"; +import { z } from "zod"; + +// Used only for Zod type inference. +const dummyRepo = { owner: "dummy", repo: "dummy" }; +const shellTool = createShellToolFields(dummyRepo); +type ShellToolArgs = z.infer; +const applyPatchTool = createApplyPatchToolFields(dummyRepo); +type ApplyPatchToolArgs = z.infer; // Common props for all action types type BaseActionProps = { @@ -21,23 +33,23 @@ type BaseActionProps = { summaryText?: string; }; -// Shell command specific props -type ShellActionProps = BaseActionProps & { - actionType: "shell"; - command: string[]; - workdir?: string; - output?: string; - errorCode?: number; -}; +// Shell command specific props. We need to wrap the args in Partial<...> +// because even though they're required, they may be undefined at a point in time +// due to streaming. +type ShellActionProps = BaseActionProps & + Partial & { + actionType: "shell"; + output?: string; + errorCode?: number; + }; // Apply patch specific props -type PatchActionProps = BaseActionProps & { - actionType: "apply-patch"; - file: string; - diff?: string; - errorMessage?: string; - fixedDiff?: string; -}; +type PatchActionProps = BaseActionProps & + Partial & { + actionType: "apply-patch"; + errorMessage?: string; + fixedDiff?: string; + }; // Union type for all possible action props export type ActionStepProps = @@ -137,14 +149,14 @@ export function ActionStep(props: ActionStepProps) { )} - {props.command.join(" ")} + {props.command?.join(" ")} ); } else { return ( - {props.file} + {props.file_path} ); } diff --git a/apps/web/src/components/thread/messages/ai.tsx b/apps/web/src/components/thread/messages/ai.tsx index 7df32113..8c107c04 100644 --- a/apps/web/src/components/thread/messages/ai.tsx +++ b/apps/web/src/components/thread/messages/ai.tsx @@ -128,7 +128,7 @@ export function mapToolMessageToActionStepProps( actionType: "apply-patch", status, success, - file: args.file_path || "", + file_path: args.file_path || "", diff: args.diff, reasoningText, errorMessage: !success ? getContentString(message.content) : undefined, @@ -222,24 +222,18 @@ export function AssistantMessage({ actionType={aiToolCallName === shellTool.name ? "shell" : "apply-patch"} status="generating" command={ - aiToolCallName === shellTool.name - ? aiToolCallArgs?.command || [] - : undefined + aiToolCallName === shellTool.name ? aiToolCallArgs?.command || [] : [] } workdir={ - aiToolCallName === shellTool.name - ? aiToolCallArgs?.workdir - : undefined + aiToolCallName === shellTool.name ? aiToolCallArgs?.workdir : "" } - file={ + file_path={ aiToolCallName === applyPatchTool.name ? aiToolCallArgs?.file_path || "" - : undefined + : "" } diff={ - aiToolCallName === applyPatchTool.name - ? aiToolCallArgs?.diff - : undefined + aiToolCallName === applyPatchTool.name ? aiToolCallArgs?.diff : "" } reasoningText={contentString} />