Fix code style
This commit is contained in:
parent
cbb9331643
commit
236dee0dca
2 changed files with 396 additions and 379 deletions
|
|
@ -1,4 +1,11 @@
|
||||||
import { useState, useEffect, useCallback, useRef, forwardRef, useImperativeHandle } from "react";
|
import {
|
||||||
|
useState,
|
||||||
|
useEffect,
|
||||||
|
useCallback,
|
||||||
|
useRef,
|
||||||
|
forwardRef,
|
||||||
|
useImperativeHandle,
|
||||||
|
} from "react";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import JsonEditor from "./JsonEditor";
|
import JsonEditor from "./JsonEditor";
|
||||||
|
|
@ -55,12 +62,8 @@ const getArrayItemDefault = (schema: JsonSchemaType): JsonValue => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const DynamicJsonForm = forwardRef<DynamicJsonFormRef, DynamicJsonFormProps>(({
|
const DynamicJsonForm = forwardRef<DynamicJsonFormRef, DynamicJsonFormProps>(
|
||||||
schema,
|
({ schema, value, onChange, maxDepth = 3 }, ref) => {
|
||||||
value,
|
|
||||||
onChange,
|
|
||||||
maxDepth = 3,
|
|
||||||
}, ref) => {
|
|
||||||
const isOnlyJSON = !isSimpleObject(schema);
|
const isOnlyJSON = !isSimpleObject(schema);
|
||||||
const [isJsonMode, setIsJsonMode] = useState(isOnlyJSON);
|
const [isJsonMode, setIsJsonMode] = useState(isOnlyJSON);
|
||||||
const [jsonError, setJsonError] = useState<string>();
|
const [jsonError, setJsonError] = useState<string>();
|
||||||
|
|
@ -150,7 +153,8 @@ const DynamicJsonForm = forwardRef<DynamicJsonFormRef, DynamicJsonFormProps>(({
|
||||||
setJsonError(undefined);
|
setJsonError(undefined);
|
||||||
return { isValid: true, error: null };
|
return { isValid: true, error: null };
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const errorMessage = err instanceof Error ? err.message : "Invalid JSON";
|
const errorMessage =
|
||||||
|
err instanceof Error ? err.message : "Invalid JSON";
|
||||||
setJsonError(errorMessage);
|
setJsonError(errorMessage);
|
||||||
return { isValid: false, error: errorMessage };
|
return { isValid: false, error: errorMessage };
|
||||||
}
|
}
|
||||||
|
|
@ -187,7 +191,9 @@ const DynamicJsonForm = forwardRef<DynamicJsonFormRef, DynamicJsonFormProps>(({
|
||||||
handleFieldChange(path, parsed);
|
handleFieldChange(path, parsed);
|
||||||
setJsonError(undefined);
|
setJsonError(undefined);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setJsonError(err instanceof Error ? err.message : "Invalid JSON");
|
setJsonError(
|
||||||
|
err instanceof Error ? err.message : "Invalid JSON",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
error={jsonError}
|
error={jsonError}
|
||||||
|
|
@ -436,7 +442,11 @@ const DynamicJsonForm = forwardRef<DynamicJsonFormRef, DynamicJsonFormProps>(({
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
{!isOnlyJSON && (
|
{!isOnlyJSON && (
|
||||||
<Button variant="outline" size="sm" onClick={handleSwitchToFormMode}>
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={handleSwitchToFormMode}
|
||||||
|
>
|
||||||
{isJsonMode ? "Switch to Form" : "Switch to JSON"}
|
{isJsonMode ? "Switch to Form" : "Switch to JSON"}
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
|
|
@ -479,6 +489,7 @@ const DynamicJsonForm = forwardRef<DynamicJsonFormRef, DynamicJsonFormProps>(({
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
export default DynamicJsonForm;
|
export default DynamicJsonForm;
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,13 @@ import {
|
||||||
ListToolsResult,
|
ListToolsResult,
|
||||||
Tool,
|
Tool,
|
||||||
} from "@modelcontextprotocol/sdk/types.js";
|
} from "@modelcontextprotocol/sdk/types.js";
|
||||||
import { Loader2, Send, ChevronDown, ChevronUp, AlertCircle } from "lucide-react";
|
import {
|
||||||
|
Loader2,
|
||||||
|
Send,
|
||||||
|
ChevronDown,
|
||||||
|
ChevronUp,
|
||||||
|
AlertCircle,
|
||||||
|
} from "lucide-react";
|
||||||
import { useEffect, useState, useRef } from "react";
|
import { useEffect, useState, useRef } from "react";
|
||||||
import ListPane from "./ListPane";
|
import ListPane from "./ListPane";
|
||||||
import JsonView from "./JsonView";
|
import JsonView from "./JsonView";
|
||||||
|
|
@ -254,9 +260,9 @@ const ToolsTab = ({
|
||||||
<Button
|
<Button
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
// Validate JSON inputs before calling tool
|
// Validate JSON inputs before calling tool
|
||||||
const hasValidationErrors = Object.values(formRefs.current).some(
|
const hasValidationErrors = Object.values(
|
||||||
(ref) => ref && !ref.validateJson().isValid
|
formRefs.current,
|
||||||
);
|
).some((ref) => ref && !ref.validateJson().isValid);
|
||||||
if (hasValidationErrors) return;
|
if (hasValidationErrors) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue