Fix formatting

This commit is contained in:
olaservo 2025-06-01 15:41:30 -07:00
commit 990bc0f7fd
3 changed files with 29 additions and 11 deletions

View file

@ -124,7 +124,8 @@ const DynamicJsonForm = ({
return ( return (
<JsonEditor <JsonEditor
value={JSON.stringify( value={JSON.stringify(
currentValue ?? generateDefaultValue(propSchema, propertyName, parentSchema), currentValue ??
generateDefaultValue(propSchema, propertyName, parentSchema),
null, null,
2, 2,
)} )}
@ -143,7 +144,8 @@ const DynamicJsonForm = ({
} }
// Check if this property is required in the parent schema // Check if this property is required in the parent schema
const isRequired = parentSchema?.required?.includes(propertyName || "") ?? false; const isRequired =
parentSchema?.required?.includes(propertyName || "") ?? false;
switch (propSchema.type) { switch (propSchema.type) {
case "string": case "string":
@ -223,14 +225,16 @@ const DynamicJsonForm = ({
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}
/> />
); );
} }
return ( return (
<div className="space-y-2 border rounded p-3"> <div className="space-y-2 border rounded p-3">
{Object.entries(propSchema.properties).map(([key, subSchema]) => ( {Object.entries(propSchema.properties).map(([key, subSchema]) => (
@ -263,7 +267,9 @@ const DynamicJsonForm = ({
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}

View file

@ -48,7 +48,11 @@ const ToolsTab = ({
selectedTool?.inputSchema.properties ?? [], selectedTool?.inputSchema.properties ?? [],
).map(([key, value]) => [ ).map(([key, value]) => [
key, key,
generateDefaultValue(value as JsonSchemaType, key, selectedTool?.inputSchema as JsonSchemaType), generateDefaultValue(
value as JsonSchemaType,
key,
selectedTool?.inputSchema as JsonSchemaType,
),
]); ]);
setParams(Object.fromEntries(params)); setParams(Object.fromEntries(params));
}, [selectedTool]); }, [selectedTool]);
@ -92,7 +96,8 @@ const ToolsTab = ({
{Object.entries(selectedTool.inputSchema.properties ?? []).map( {Object.entries(selectedTool.inputSchema.properties ?? []).map(
([key, value]) => { ([key, value]) => {
const prop = value as JsonSchemaType; const prop = value as JsonSchemaType;
const inputSchema = selectedTool.inputSchema as JsonSchemaType; const inputSchema =
selectedTool.inputSchema as JsonSchemaType;
const required = isPropertyRequired(key, inputSchema); const required = isPropertyRequired(key, inputSchema);
return ( return (
<div key={key}> <div key={key}>
@ -100,7 +105,10 @@ const ToolsTab = ({
htmlFor={key} htmlFor={key}
className="block text-sm font-medium text-gray-700 dark:text-gray-300" className="block text-sm font-medium text-gray-700 dark:text-gray-300"
> >
{key}{required && <span className="text-red-500 ml-1">*</span>} {key}
{required && (
<span className="text-red-500 ml-1">*</span>
)}
</Label> </Label>
{prop.type === "boolean" ? ( {prop.type === "boolean" ? (
<div className="flex items-center space-x-2 mt-2"> <div className="flex items-center space-x-2 mt-2">

View file

@ -88,14 +88,15 @@ export function hasOutputSchema(toolName: string): boolean {
export function generateDefaultValue( export function generateDefaultValue(
schema: JsonSchemaType, schema: JsonSchemaType,
propertyName?: string, propertyName?: string,
parentSchema?: JsonSchemaType parentSchema?: JsonSchemaType,
): JsonValue { ): JsonValue {
if ("default" in schema && schema.default !== undefined) { if ("default" in schema && schema.default !== undefined) {
return schema.default; return schema.default;
} }
// Check if this property is required in the parent schema // Check if this property is required in the parent schema
const isRequired = parentSchema?.required?.includes(propertyName || "") ?? false; const isRequired =
parentSchema?.required?.includes(propertyName || "") ?? false;
switch (schema.type) { switch (schema.type) {
case "string": case "string":
@ -136,7 +137,10 @@ export function generateDefaultValue(
* @param schema The parent schema containing the required array * @param schema The parent schema containing the required array
* @returns true if the property is required, false otherwise * @returns true if the property is required, false otherwise
*/ */
export function isPropertyRequired(propertyName: string, schema: JsonSchemaType): boolean { export function isPropertyRequired(
propertyName: string,
schema: JsonSchemaType,
): boolean {
return schema.required?.includes(propertyName) ?? false; return schema.required?.includes(propertyName) ?? false;
} }