From 4bc44c4d19342f4f49d73cc67f43315d952d0b17 Mon Sep 17 00:00:00 2001 From: Maxwell Gerber Date: Tue, 8 Apr 2025 14:54:48 -0700 Subject: [PATCH] fix: When tool type cannot be determined, use DynamicJsonForm --- client/src/components/DynamicJsonForm.tsx | 12 ++++-- client/src/components/ToolsTab.tsx | 46 +++++++++++++++-------- 2 files changed, 38 insertions(+), 20 deletions(-) diff --git a/client/src/components/DynamicJsonForm.tsx b/client/src/components/DynamicJsonForm.tsx index f5b0d63..a3fd847 100644 --- a/client/src/components/DynamicJsonForm.tsx +++ b/client/src/components/DynamicJsonForm.tsx @@ -36,6 +36,7 @@ interface DynamicJsonFormProps { value: JsonValue; onChange: (value: JsonValue) => void; maxDepth?: number; + onlyJSON?: boolean; } const DynamicJsonForm = ({ @@ -43,8 +44,9 @@ const DynamicJsonForm = ({ value, onChange, maxDepth = 3, + onlyJSON = false, }: DynamicJsonFormProps) => { - const [isJsonMode, setIsJsonMode] = useState(false); + const [isJsonMode, setIsJsonMode] = useState(onlyJSON); const [jsonError, setJsonError] = useState(); // Store the raw JSON string to allow immediate feedback during typing // while deferring parsing until the user stops typing @@ -374,9 +376,11 @@ const DynamicJsonForm = ({ Format JSON )} - + {!onlyJSON && ( + + )} {isJsonMode ? ( diff --git a/client/src/components/ToolsTab.tsx b/client/src/components/ToolsTab.tsx index a9e9bf8..8eddad1 100644 --- a/client/src/components/ToolsTab.tsx +++ b/client/src/components/ToolsTab.tsx @@ -40,7 +40,13 @@ const ToolsTab = ({ }) => { const [params, setParams] = useState>({}); useEffect(() => { - setParams({}); + const params = Object.entries( + selectedTool?.inputSchema.properties ?? [], + ).map(([key, value]) => [ + key, + generateDefaultValue(value as JsonSchemaType), + ]); + setParams(Object.fromEntries(params)); }, [selectedTool]); const renderToolResult = () => { @@ -194,10 +200,7 @@ const ToolsTab = ({ description: prop.description, items: prop.items, }} - value={ - (params[key] as JsonValue) ?? - generateDefaultValue(prop) - } + value={params[key] as JsonValue} onChange={(newValue: JsonValue) => { setParams({ ...params, @@ -206,13 +209,9 @@ const ToolsTab = ({ }} /> - ) : ( + ) : prop.type === "number" || prop.type === "integer" ? ( setParams({ ...params, - [key]: - prop.type === "number" || - prop.type === "integer" - ? Number(e.target.value) - : e.target.value, + [key]: Number(e.target.value), }) } className="mt-1" /> + ) : ( +
+ { + setParams({ + ...params, + [key]: newValue, + }); + }} + /> +
)} );