feat:toolsbar add array support
This commit is contained in:
@@ -215,23 +215,48 @@ const DynamicJsonForm = ({
|
||||
return;
|
||||
}
|
||||
|
||||
const newValue = {
|
||||
...(typeof value === "object" && value !== null && !Array.isArray(value)
|
||||
? value
|
||||
: {}),
|
||||
} as JsonObject;
|
||||
let current: JsonObject = newValue;
|
||||
|
||||
for (let i = 0; i < path.length - 1; i++) {
|
||||
const key = path[i];
|
||||
if (!(key in current)) {
|
||||
current[key] = {};
|
||||
const updateArray = (array: JsonValue[], path: string[], value: JsonValue): JsonValue[] => {
|
||||
const [index, ...restPath] = path;
|
||||
const arrayIndex = Number(index);
|
||||
const newArray = [...array];
|
||||
|
||||
if (restPath.length === 0) {
|
||||
newArray[arrayIndex] = value;
|
||||
} else {
|
||||
newArray[arrayIndex] = updateValue(newArray[arrayIndex], restPath, value);
|
||||
}
|
||||
current = current[key] as JsonObject;
|
||||
}
|
||||
return newArray;
|
||||
};
|
||||
|
||||
current[path[path.length - 1]] = fieldValue;
|
||||
onChange(newValue);
|
||||
const updateObject = (obj: JsonObject, path: string[], value: JsonValue): JsonObject => {
|
||||
const [key, ...restPath] = path;
|
||||
const newObj = { ...obj };
|
||||
|
||||
if (restPath.length === 0) {
|
||||
newObj[key] = value;
|
||||
} else {
|
||||
newObj[key] = updateValue(newObj[key], restPath, value);
|
||||
}
|
||||
return newObj;
|
||||
};
|
||||
|
||||
const updateValue = (current: JsonValue, path: string[], value: JsonValue): JsonValue => {
|
||||
if (path.length === 0) return value;
|
||||
|
||||
if (!current) {
|
||||
current = !isNaN(Number(path[0])) ? [] : {};
|
||||
}
|
||||
|
||||
if (Array.isArray(current)) {
|
||||
return updateArray(current, path, value);
|
||||
} else if (typeof current === 'object' && current !== null) {
|
||||
return updateObject(current, path, value);
|
||||
}
|
||||
|
||||
return current;
|
||||
};
|
||||
|
||||
onChange(updateValue(value, path, fieldValue));
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
@@ -17,11 +17,6 @@ import ListPane from "./ListPane";
|
||||
|
||||
import { CompatibilityCallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
||||
|
||||
type SchemaProperty = {
|
||||
type: string;
|
||||
description?: string;
|
||||
properties?: Record<string, SchemaProperty>;
|
||||
};
|
||||
|
||||
const ToolsTab = ({
|
||||
tools,
|
||||
@@ -168,7 +163,7 @@ const ToolsTab = ({
|
||||
</p>
|
||||
{Object.entries(selectedTool.inputSchema.properties ?? []).map(
|
||||
([key, value]) => {
|
||||
const prop = value as SchemaProperty;
|
||||
const prop = value as JsonSchemaType;
|
||||
return (
|
||||
<div key={key}>
|
||||
<Label
|
||||
@@ -211,15 +206,16 @@ const ToolsTab = ({
|
||||
}
|
||||
className="mt-1"
|
||||
/>
|
||||
) : prop.type === "object" ? (
|
||||
) : prop.type === "object"|| prop.type === "array" ? (
|
||||
<div className="mt-1">
|
||||
<DynamicJsonForm
|
||||
schema={
|
||||
{
|
||||
type: "object",
|
||||
type: prop.type,
|
||||
properties: prop.properties,
|
||||
description: prop.description,
|
||||
} as JsonSchemaType
|
||||
items:prop.items
|
||||
}
|
||||
}
|
||||
value={(params[key] as JsonValue) ?? {}}
|
||||
onChange={(newValue: JsonValue) => {
|
||||
|
||||
Reference in New Issue
Block a user