fix: When tool type cannot be determined, use DynamicJsonForm
This commit is contained in:
@@ -36,6 +36,7 @@ interface DynamicJsonFormProps {
|
|||||||
value: JsonValue;
|
value: JsonValue;
|
||||||
onChange: (value: JsonValue) => void;
|
onChange: (value: JsonValue) => void;
|
||||||
maxDepth?: number;
|
maxDepth?: number;
|
||||||
|
onlyJSON?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const DynamicJsonForm = ({
|
const DynamicJsonForm = ({
|
||||||
@@ -43,8 +44,9 @@ const DynamicJsonForm = ({
|
|||||||
value,
|
value,
|
||||||
onChange,
|
onChange,
|
||||||
maxDepth = 3,
|
maxDepth = 3,
|
||||||
|
onlyJSON = false,
|
||||||
}: DynamicJsonFormProps) => {
|
}: DynamicJsonFormProps) => {
|
||||||
const [isJsonMode, setIsJsonMode] = useState(false);
|
const [isJsonMode, setIsJsonMode] = useState(onlyJSON);
|
||||||
const [jsonError, setJsonError] = useState<string>();
|
const [jsonError, setJsonError] = useState<string>();
|
||||||
// Store the raw JSON string to allow immediate feedback during typing
|
// Store the raw JSON string to allow immediate feedback during typing
|
||||||
// while deferring parsing until the user stops typing
|
// while deferring parsing until the user stops typing
|
||||||
@@ -374,9 +376,11 @@ const DynamicJsonForm = ({
|
|||||||
Format JSON
|
Format JSON
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
<Button variant="outline" size="sm" onClick={handleSwitchToFormMode}>
|
{!onlyJSON && (
|
||||||
{isJsonMode ? "Switch to Form" : "Switch to JSON"}
|
<Button variant="outline" size="sm" onClick={handleSwitchToFormMode}>
|
||||||
</Button>
|
{isJsonMode ? "Switch to Form" : "Switch to JSON"}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{isJsonMode ? (
|
{isJsonMode ? (
|
||||||
|
|||||||
@@ -40,7 +40,13 @@ const ToolsTab = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const [params, setParams] = useState<Record<string, unknown>>({});
|
const [params, setParams] = useState<Record<string, unknown>>({});
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setParams({});
|
const params = Object.entries(
|
||||||
|
selectedTool?.inputSchema.properties ?? [],
|
||||||
|
).map(([key, value]) => [
|
||||||
|
key,
|
||||||
|
generateDefaultValue(value as JsonSchemaType),
|
||||||
|
]);
|
||||||
|
setParams(Object.fromEntries(params));
|
||||||
}, [selectedTool]);
|
}, [selectedTool]);
|
||||||
|
|
||||||
const renderToolResult = () => {
|
const renderToolResult = () => {
|
||||||
@@ -194,10 +200,7 @@ const ToolsTab = ({
|
|||||||
description: prop.description,
|
description: prop.description,
|
||||||
items: prop.items,
|
items: prop.items,
|
||||||
}}
|
}}
|
||||||
value={
|
value={params[key] as JsonValue}
|
||||||
(params[key] as JsonValue) ??
|
|
||||||
generateDefaultValue(prop)
|
|
||||||
}
|
|
||||||
onChange={(newValue: JsonValue) => {
|
onChange={(newValue: JsonValue) => {
|
||||||
setParams({
|
setParams({
|
||||||
...params,
|
...params,
|
||||||
@@ -206,13 +209,9 @@ const ToolsTab = ({
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : prop.type === "number" || prop.type === "integer" ? (
|
||||||
<Input
|
<Input
|
||||||
type={
|
type="number"
|
||||||
prop.type === "number" || prop.type === "integer"
|
|
||||||
? "number"
|
|
||||||
: "text"
|
|
||||||
}
|
|
||||||
id={key}
|
id={key}
|
||||||
name={key}
|
name={key}
|
||||||
placeholder={prop.description}
|
placeholder={prop.description}
|
||||||
@@ -220,15 +219,30 @@ const ToolsTab = ({
|
|||||||
onChange={(e) =>
|
onChange={(e) =>
|
||||||
setParams({
|
setParams({
|
||||||
...params,
|
...params,
|
||||||
[key]:
|
[key]: Number(e.target.value),
|
||||||
prop.type === "number" ||
|
|
||||||
prop.type === "integer"
|
|
||||||
? Number(e.target.value)
|
|
||||||
: e.target.value,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
className="mt-1"
|
className="mt-1"
|
||||||
/>
|
/>
|
||||||
|
) : (
|
||||||
|
<div className="mt-1">
|
||||||
|
<DynamicJsonForm
|
||||||
|
onlyJSON
|
||||||
|
schema={{
|
||||||
|
type: prop.type,
|
||||||
|
properties: prop.properties,
|
||||||
|
description: prop.description,
|
||||||
|
items: prop.items,
|
||||||
|
}}
|
||||||
|
value={params[key] as JsonValue}
|
||||||
|
onChange={(newValue: JsonValue) => {
|
||||||
|
setParams({
|
||||||
|
...params,
|
||||||
|
[key]: newValue,
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user