Skip to content

Commit 4bc44c4

Browse files
committed
fix: When tool type cannot be determined, use DynamicJsonForm
1 parent 4053aa1 commit 4bc44c4

File tree

2 files changed

+38
-20
lines changed

2 files changed

+38
-20
lines changed

client/src/components/DynamicJsonForm.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,17 @@ interface DynamicJsonFormProps {
3636
value: JsonValue;
3737
onChange: (value: JsonValue) => void;
3838
maxDepth?: number;
39+
onlyJSON?: boolean;
3940
}
4041

4142
const DynamicJsonForm = ({
4243
schema,
4344
value,
4445
onChange,
4546
maxDepth = 3,
47+
onlyJSON = false,
4648
}: DynamicJsonFormProps) => {
47-
const [isJsonMode, setIsJsonMode] = useState(false);
49+
const [isJsonMode, setIsJsonMode] = useState(onlyJSON);
4850
const [jsonError, setJsonError] = useState<string>();
4951
// Store the raw JSON string to allow immediate feedback during typing
5052
// while deferring parsing until the user stops typing
@@ -374,9 +376,11 @@ const DynamicJsonForm = ({
374376
Format JSON
375377
</Button>
376378
)}
377-
<Button variant="outline" size="sm" onClick={handleSwitchToFormMode}>
378-
{isJsonMode ? "Switch to Form" : "Switch to JSON"}
379-
</Button>
379+
{!onlyJSON && (
380+
<Button variant="outline" size="sm" onClick={handleSwitchToFormMode}>
381+
{isJsonMode ? "Switch to Form" : "Switch to JSON"}
382+
</Button>
383+
)}
380384
</div>
381385

382386
{isJsonMode ? (

client/src/components/ToolsTab.tsx

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,13 @@ const ToolsTab = ({
4040
}) => {
4141
const [params, setParams] = useState<Record<string, unknown>>({});
4242
useEffect(() => {
43-
setParams({});
43+
const params = Object.entries(
44+
selectedTool?.inputSchema.properties ?? [],
45+
).map(([key, value]) => [
46+
key,
47+
generateDefaultValue(value as JsonSchemaType),
48+
]);
49+
setParams(Object.fromEntries(params));
4450
}, [selectedTool]);
4551

4652
const renderToolResult = () => {
@@ -194,10 +200,7 @@ const ToolsTab = ({
194200
description: prop.description,
195201
items: prop.items,
196202
}}
197-
value={
198-
(params[key] as JsonValue) ??
199-
generateDefaultValue(prop)
200-
}
203+
value={params[key] as JsonValue}
201204
onChange={(newValue: JsonValue) => {
202205
setParams({
203206
...params,
@@ -206,29 +209,40 @@ const ToolsTab = ({
206209
}}
207210
/>
208211
</div>
209-
) : (
212+
) : prop.type === "number" || prop.type === "integer" ? (
210213
<Input
211-
type={
212-
prop.type === "number" || prop.type === "integer"
213-
? "number"
214-
: "text"
215-
}
214+
type="number"
216215
id={key}
217216
name={key}
218217
placeholder={prop.description}
219218
value={(params[key] as string) ?? ""}
220219
onChange={(e) =>
221220
setParams({
222221
...params,
223-
[key]:
224-
prop.type === "number" ||
225-
prop.type === "integer"
226-
? Number(e.target.value)
227-
: e.target.value,
222+
[key]: Number(e.target.value),
228223
})
229224
}
230225
className="mt-1"
231226
/>
227+
) : (
228+
<div className="mt-1">
229+
<DynamicJsonForm
230+
onlyJSON
231+
schema={{
232+
type: prop.type,
233+
properties: prop.properties,
234+
description: prop.description,
235+
items: prop.items,
236+
}}
237+
value={params[key] as JsonValue}
238+
onChange={(newValue: JsonValue) => {
239+
setParams({
240+
...params,
241+
[key]: newValue,
242+
});
243+
}}
244+
/>
245+
</div>
232246
)}
233247
</div>
234248
);

0 commit comments

Comments
 (0)