fix: prettier write
This commit is contained in:
@@ -215,7 +215,11 @@ const DynamicJsonForm = ({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const updateArray = (array: JsonValue[], path: string[], value: JsonValue): JsonValue[] => {
|
const updateArray = (
|
||||||
|
array: JsonValue[],
|
||||||
|
path: string[],
|
||||||
|
value: JsonValue,
|
||||||
|
): JsonValue[] => {
|
||||||
const [index, ...restPath] = path;
|
const [index, ...restPath] = path;
|
||||||
const arrayIndex = Number(index);
|
const arrayIndex = Number(index);
|
||||||
|
|
||||||
@@ -232,7 +236,7 @@ const DynamicJsonForm = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const newArray = [...array];
|
const newArray = [...array];
|
||||||
|
|
||||||
if (restPath.length === 0) {
|
if (restPath.length === 0) {
|
||||||
newArray[arrayIndex] = value;
|
newArray[arrayIndex] = value;
|
||||||
} else {
|
} else {
|
||||||
@@ -242,22 +246,30 @@ const DynamicJsonForm = ({
|
|||||||
newArray.length = arrayIndex + 1;
|
newArray.length = arrayIndex + 1;
|
||||||
newArray.fill(null, array.length, arrayIndex);
|
newArray.fill(null, array.length, arrayIndex);
|
||||||
}
|
}
|
||||||
newArray[arrayIndex] = updateValue(newArray[arrayIndex], restPath, value);
|
newArray[arrayIndex] = updateValue(
|
||||||
|
newArray[arrayIndex],
|
||||||
|
restPath,
|
||||||
|
value,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return newArray;
|
return newArray;
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateObject = (obj: JsonObject, path: string[], value: JsonValue): JsonObject => {
|
const updateObject = (
|
||||||
|
obj: JsonObject,
|
||||||
|
path: string[],
|
||||||
|
value: JsonValue,
|
||||||
|
): JsonObject => {
|
||||||
const [key, ...restPath] = path;
|
const [key, ...restPath] = path;
|
||||||
|
|
||||||
// Validate object key
|
// Validate object key
|
||||||
if (typeof key !== 'string') {
|
if (typeof key !== "string") {
|
||||||
console.error(`Invalid object key: ${key}`);
|
console.error(`Invalid object key: ${key}`);
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
const newObj = { ...obj };
|
const newObj = { ...obj };
|
||||||
|
|
||||||
if (restPath.length === 0) {
|
if (restPath.length === 0) {
|
||||||
newObj[key] = value;
|
newObj[key] = value;
|
||||||
} else {
|
} else {
|
||||||
@@ -271,7 +283,11 @@ const DynamicJsonForm = ({
|
|||||||
return newObj;
|
return newObj;
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateValue = (current: JsonValue, path: string[], value: JsonValue): JsonValue => {
|
const updateValue = (
|
||||||
|
current: JsonValue,
|
||||||
|
path: string[],
|
||||||
|
value: JsonValue,
|
||||||
|
): JsonValue => {
|
||||||
if (path.length === 0) return value;
|
if (path.length === 0) return value;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -282,14 +298,17 @@ const DynamicJsonForm = ({
|
|||||||
// Type checking
|
// Type checking
|
||||||
if (Array.isArray(current)) {
|
if (Array.isArray(current)) {
|
||||||
return updateArray(current, path, value);
|
return updateArray(current, path, value);
|
||||||
} else if (typeof current === 'object' && current !== null) {
|
} else if (typeof current === "object" && current !== null) {
|
||||||
return updateObject(current, path, value);
|
return updateObject(current, path, value);
|
||||||
} else {
|
} else {
|
||||||
console.error(`Cannot update path ${path.join('.')} in non-object/array value:`, current);
|
console.error(
|
||||||
|
`Cannot update path ${path.join(".")} in non-object/array value:`,
|
||||||
|
current,
|
||||||
|
);
|
||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Error updating value at path ${path.join('.')}:`, error);
|
console.error(`Error updating value at path ${path.join(".")}:`, error);
|
||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -298,7 +317,7 @@ const DynamicJsonForm = ({
|
|||||||
const newValue = updateValue(value, path, fieldValue);
|
const newValue = updateValue(value, path, fieldValue);
|
||||||
onChange(newValue);
|
onChange(newValue);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to update form value:', error);
|
console.error("Failed to update form value:", error);
|
||||||
// Keep the original value unchanged
|
// Keep the original value unchanged
|
||||||
onChange(value);
|
onChange(value);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import ListPane from "./ListPane";
|
|||||||
|
|
||||||
import { CompatibilityCallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
import { CompatibilityCallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
||||||
|
|
||||||
|
|
||||||
const ToolsTab = ({
|
const ToolsTab = ({
|
||||||
tools,
|
tools,
|
||||||
listTools,
|
listTools,
|
||||||
@@ -206,17 +205,15 @@ const ToolsTab = ({
|
|||||||
}
|
}
|
||||||
className="mt-1"
|
className="mt-1"
|
||||||
/>
|
/>
|
||||||
) : prop.type === "object"|| prop.type === "array" ? (
|
) : prop.type === "object" || prop.type === "array" ? (
|
||||||
<div className="mt-1">
|
<div className="mt-1">
|
||||||
<DynamicJsonForm
|
<DynamicJsonForm
|
||||||
schema={
|
schema={{
|
||||||
{
|
type: prop.type,
|
||||||
type: prop.type,
|
properties: prop.properties,
|
||||||
properties: prop.properties,
|
description: prop.description,
|
||||||
description: prop.description,
|
items: prop.items,
|
||||||
items:prop.items
|
}}
|
||||||
}
|
|
||||||
}
|
|
||||||
value={(params[key] as JsonValue) ?? {}}
|
value={(params[key] as JsonValue) ?? {}}
|
||||||
onChange={(newValue: JsonValue) => {
|
onChange={(newValue: JsonValue) => {
|
||||||
setParams({
|
setParams({
|
||||||
|
|||||||
Reference in New Issue
Block a user