-
+
{jsonString}
diff --git a/registry/commandly/lib/types/commandly-nested.ts b/registry/commandly/lib/types/commandly-nested.ts
index 878c88f..0fe9c0d 100644
--- a/registry/commandly/lib/types/commandly-nested.ts
+++ b/registry/commandly/lib/types/commandly-nested.ts
@@ -1,13 +1,13 @@
import {
- ParameterValidation,
- ParameterDependencyType,
- ParameterType,
+ ExclusionType,
ParameterDataType,
+ ParameterDependencyType,
ParameterMetadata,
- ExclusionType,
+ ParameterType,
+ ParameterValidation,
SupportedToolInputType,
- SupportedToolOutputType
-} from "../../types";
+ SupportedToolOutputType,
+} from "./commandly";
export interface NestedCommand {
name: string;
@@ -26,10 +26,7 @@ export interface NestedParameterEnumValue {
sortOrder: number;
}
-export type NestedParameterValidation = Omit<
- ParameterValidation,
- "id" | "parameterId"
->;
+export type NestedParameterValidation = Omit;
export interface NestedParameterDependency {
dependsOnParameter: string;
diff --git a/registry/commandly/lib/types/commandly.ts b/registry/commandly/lib/types/commandly.ts
index 79a90ca..0f07b6c 100644
--- a/registry/commandly/lib/types/commandly.ts
+++ b/registry/commandly/lib/types/commandly.ts
@@ -6,7 +6,7 @@ export const CommandSchema = z.object({
name: z.string(),
description: z.string(),
isDefault: z.boolean(),
- sortOrder: z.number()
+ sortOrder: z.number(),
});
export type Command = z.infer;
@@ -17,7 +17,7 @@ export const ParameterEnumValueSchema = z.object({
displayName: z.string(),
description: z.string(),
isDefault: z.boolean(),
- sortOrder: z.number()
+ sortOrder: z.number(),
});
export type ParameterEnumValue = z.infer;
@@ -26,33 +26,26 @@ export const ParameterValidationTypeSchema = z.enum([
"max_length",
"min_value",
"max_value",
- "regex"
+ "regex",
]);
-export type ParameterValidationType = z.infer<
- typeof ParameterValidationTypeSchema
->;
+export type ParameterValidationType = z.infer;
export const ParameterValidationSchema = z.object({
id: z.string(),
parameterId: z.string(),
validationType: ParameterValidationTypeSchema,
validationValue: z.string(),
- errorMessage: z.string()
+ errorMessage: z.string(),
});
export type ParameterValidation = z.infer;
-export const ParameterDependencyTypeSchema = z.enum([
- "requires",
- "conflicts_with"
-]);
-export type ParameterDependencyType = z.infer<
- typeof ParameterDependencyTypeSchema
->;
+export const ParameterDependencyTypeSchema = z.enum(["requires", "conflicts_with"]);
+export type ParameterDependencyType = z.infer;
export const ParameterDependencySchema = z.object({
id: z.string(),
parameterId: z.string(),
dependsOnParameterId: z.string(),
dependencyType: ParameterDependencyTypeSchema,
- conditionValue: z.string().optional()
+ conditionValue: z.string().optional(),
});
export type ParameterValue = string | number | boolean;
@@ -60,18 +53,13 @@ export type ParameterValue = string | number | boolean;
export type ParameterDependency = z.infer;
export const ParameterMetadataSchema = z.object({
- tags: z.array(z.string()).optional()
+ tags: z.array(z.string()).optional(),
});
export type ParameterMetadata = z.infer;
export const ParameterTypeSchema = z.enum(["Flag", "Option", "Argument"]);
export type ParameterType = z.infer;
-export const ParameterDataTypeSchema = z.enum([
- "String",
- "Number",
- "Boolean",
- "Enum"
-]);
+export const ParameterDataTypeSchema = z.enum(["String", "Number", "Boolean", "Enum"]);
export type ParameterDataType = z.infer;
export const ParameterSchema = z.object({
@@ -94,14 +82,11 @@ export const ParameterSchema = z.object({
keyValueSeparator: z.string().optional(),
enumValues: z.array(ParameterEnumValueSchema),
validations: z.array(ParameterValidationSchema).optional(),
- dependencies: z.array(ParameterDependencySchema).optional()
+ dependencies: z.array(ParameterDependencySchema).optional(),
});
export type Parameter = z.infer;
-export const ExclusionTypeSchema = z.enum([
- "mutual_exclusive",
- "required_one_of"
-]);
+export const ExclusionTypeSchema = z.enum(["mutual_exclusive", "required_one_of"]);
export type ExclusionType = z.infer;
export const ExclusionGroupSchema = z.object({
@@ -109,32 +94,21 @@ export const ExclusionGroupSchema = z.object({
commandId: z.string().optional(),
name: z.string(),
exclusionType: ExclusionTypeSchema,
- parameterIds: z.array(z.string())
+ parameterIds: z.array(z.string()),
});
export type ExclusionGroup = z.infer;
export const SavedCommandSchema = z.object({
id: z.string(),
- command: z.string()
+ command: z.string(),
});
export type SavedCommand = z.infer;
-export const SupportedToolInputTypeSchema = z.enum([
- "StandardInput",
- "Parameter"
-]);
-export type SupportedToolInputType = z.infer<
- typeof SupportedToolInputTypeSchema
->;
-
-export const SupportedToolOutputTypeSchema = z.enum([
- "StandardOutput",
- "File",
- "Directory"
-]);
-export type SupportedToolOutputType = z.infer<
- typeof SupportedToolOutputTypeSchema
->;
+export const SupportedToolInputTypeSchema = z.enum(["StandardInput", "Parameter"]);
+export type SupportedToolInputType = z.infer;
+
+export const SupportedToolOutputTypeSchema = z.enum(["StandardOutput", "File", "Directory"]);
+export type SupportedToolOutputType = z.infer;
export const ToolSchema = z.object({
id: z.string().optional(),
@@ -149,20 +123,20 @@ export const ToolSchema = z.object({
parameters: z.array(ParameterSchema),
exclusionGroups: z.array(ExclusionGroupSchema),
supportedInput: z.array(SupportedToolInputTypeSchema),
- supportedOutput: z.array(SupportedToolOutputTypeSchema)
+ supportedOutput: z.array(SupportedToolOutputTypeSchema),
});
export type Tool = z.infer;
export const AIParseRequestSchema = z.object({
helpText: z.string(),
- toolName: z.string().optional()
+ toolName: z.string().optional(),
});
export type AIParseRequest = z.infer;
export const AIParseResponseSchema = z.object({
success: z.boolean(),
data: ToolSchema.optional(),
- error: z.string().optional()
+ error: z.string().optional(),
});
export type AIParseResponse = z.infer;
@@ -171,6 +145,6 @@ export const newToolSchema = z.object({
name: z.string(),
version: z.string().optional(),
description: z.string().optional(),
- url: z.url().optional()
+ url: z.url().optional(),
});
export type ManualNewTool = z.infer;
diff --git a/registry/commandly/lib/utils/commandly-nested.ts b/registry/commandly/lib/utils/commandly-nested.ts
index e171e69..7a6af40 100644
--- a/registry/commandly/lib/utils/commandly-nested.ts
+++ b/registry/commandly/lib/utils/commandly-nested.ts
@@ -1,14 +1,10 @@
-import type {
- Tool,
- Command,
- Parameter
-} from "@/registry/commandly/lib/types/commandly";
import {
NestedCommand,
NestedExclusionGroup,
NestedParameter,
- NestedTool
+ NestedTool,
} from "../types/commandly-nested";
+import type { Tool, Command, Parameter } from "@/registry/commandly/lib/types/commandly";
export const convertToNestedStructure = (tool: Tool): NestedTool => {
const globalParameters = tool.parameters.filter((p) => p.isGlobal);
@@ -22,34 +18,29 @@ export const convertToNestedStructure = (tool: Tool): NestedTool => {
return {
validationType: v.validationType,
validationValue: v.validationValue,
- errorMessage: v.errorMessage
+ errorMessage: v.errorMessage,
};
}) || [],
metadata: param.metadata,
dataType: param.dataType,
dependencies:
param.dependencies?.map((dep) => {
- const dependsOnParam = tool.parameters.find(
- (p) => p.id === dep.dependsOnParameterId
- );
+ const dependsOnParam = tool.parameters.find((p) => p.id === dep.dependsOnParameterId);
return {
dependsOnParameter: dependsOnParam?.longFlag || "",
dependencyType: dep.dependencyType,
- conditionValue: dep.conditionValue
+ conditionValue: dep.conditionValue,
};
- }) || []
+ }) || [],
};
};
- const buildNestedCommands = (
- commands: Command[],
- parentId?: string
- ): NestedCommand[] => {
+ const buildNestedCommands = (commands: Command[], parentId?: string): NestedCommand[] => {
return commands
.filter((cmd) => cmd.parentCommandId === parentId)
.map((cmd) => {
const commandParameters = tool.parameters.filter(
- (p) => p.commandId === cmd.id && !p.isGlobal
+ (p) => p.commandId === cmd.id && !p.isGlobal,
);
return {
name: cmd.name,
@@ -57,22 +48,21 @@ export const convertToNestedStructure = (tool: Tool): NestedTool => {
isDefault: cmd.isDefault,
sortOrder: cmd.sortOrder,
parameters: commandParameters.map(convertParameter),
- subcommands: buildNestedCommands(commands, cmd.id)
+ subcommands: buildNestedCommands(commands, cmd.id),
};
});
};
- const nestedExclusionGroups: NestedExclusionGroup[] =
- tool.exclusionGroups.map((group) => {
- return {
- name: group.name,
- exclusionType: group.exclusionType,
- parameters: group.parameterIds.map((pid) => {
- const param = tool.parameters.find((p) => p.id === pid);
- return param?.longFlag || "";
- })
- };
- });
+ const nestedExclusionGroups: NestedExclusionGroup[] = tool.exclusionGroups.map((group) => {
+ return {
+ name: group.name,
+ exclusionType: group.exclusionType,
+ parameters: group.parameterIds.map((pid) => {
+ const param = tool.parameters.find((p) => p.id === pid);
+ return param?.longFlag || "";
+ }),
+ };
+ });
return {
name: tool.name,
@@ -84,6 +74,6 @@ export const convertToNestedStructure = (tool: Tool): NestedTool => {
supportedOutput: tool.supportedOutput,
globalParameters: globalParameters.map(convertParameter),
commands: buildNestedCommands(tool.commands),
- exclusionGroups: nestedExclusionGroups
+ exclusionGroups: nestedExclusionGroups,
};
};
diff --git a/registry/commandly/lib/utils/commandly.ts b/registry/commandly/lib/utils/commandly.ts
index ab05da9..c20560c 100644
--- a/registry/commandly/lib/utils/commandly.ts
+++ b/registry/commandly/lib/utils/commandly.ts
@@ -1,8 +1,11 @@
import type {
Command,
+ ExclusionGroup,
Parameter,
SavedCommand,
- Tool
+ SupportedToolInputType,
+ SupportedToolOutputType,
+ Tool,
} from "@/registry/commandly/lib/types/commandly";
import { v7 as uuidv7 } from "uuid";
@@ -14,21 +17,16 @@ export const getCommandPath = (command: Command, tool: Tool): string => {
const findCommandPath = (
targetId: string,
commands: Command[],
- path: string[] = []
+ path: string[] = [],
): string[] | null => {
for (const cmd of commands) {
if (cmd.name === targetId) {
return [...path, cmd.name];
}
- const childCommands = commands.filter(
- (c) => c.parentCommandId === cmd.id
- );
+ const childCommands = commands.filter((c) => c.parentCommandId === cmd.id);
if (childCommands.length > 0) {
- const subPath = findCommandPath(targetId, childCommands, [
- ...path,
- cmd.name
- ]);
+ const subPath = findCommandPath(targetId, childCommands, [...path, cmd.name]);
if (subPath) {
return subPath;
}
@@ -54,10 +52,7 @@ export const getCommandPath = (command: Command, tool: Tool): string => {
return path.join(" ");
};
-export const getAllSubcommands = (
- commandId: string,
- commands: Command[]
-): Command[] => {
+export const getAllSubcommands = (commandId: string, commands: Command[]): Command[] => {
const result: Command[] = [];
const findSubcommands = (parentId: string) => {
@@ -88,11 +83,11 @@ export const exportToStructuredJSON = (tool: Tool) => {
parameters: tool.parameters,
exclusionGroups: tool.exclusionGroups,
supportedInput: tool.supportedInput,
- supportedOutput: tool.supportedOutput
+ supportedOutput: tool.supportedOutput,
};
};
-export const flattenImportedData = (importedData: any): Tool => {
+export const flattenImportedData = (importedData: Record): Tool => {
const {
name,
displayName,
@@ -100,41 +95,57 @@ export const flattenImportedData = (importedData: any): Tool => {
commands = [],
exclusionGroups = [],
supportedInput = [],
- supportedOutput = []
- } = importedData;
+ supportedOutput = [],
+ } = importedData as {
+ name: string;
+ displayName?: string;
+ parameters?: Parameter[];
+ commands?: Record[];
+ exclusionGroups?: ExclusionGroup[];
+ supportedInput?: SupportedToolInputType[];
+ supportedOutput?: SupportedToolOutputType[];
+ };
const allParameters: Parameter[] = [...parameters];
const flattenCommandParameters = (
- command: any,
- parentId?: string
+ command: Record,
+ parentId?: string,
): Command[] => {
- const { parameters = [], subcommands = [], ...commandData } = command;
+ const {
+ parameters = [],
+ subcommands = [],
+ ...commandData
+ } = command as {
+ parameters?: Parameter[];
+ subcommands?: Record[];
+ [key: string]: unknown;
+ };
- parameters.forEach((param: any) => {
+ (parameters as Parameter[]).forEach((param: Parameter) => {
allParameters.push({
...param,
- commandId: command.id,
- isGlobal: !command.name
+ commandId: command.id as string,
+ isGlobal: !command.name,
});
});
const flatCommand: Command = {
...commandData,
- parentCommandId: parentId
- };
+ parentCommandId: parentId,
+ } as Command;
const flatCommands = [flatCommand];
- subcommands.forEach((subcmd: any) => {
- flatCommands.push(...flattenCommandParameters(subcmd, command.name));
+ (subcommands as Record[]).forEach((subcmd) => {
+ flatCommands.push(...flattenCommandParameters(subcmd, command.name as string));
});
return flatCommands;
};
const flatCommands: Command[] = [];
- commands.forEach((cmd: any) => {
+ (commands as Record[]).forEach((cmd) => {
flatCommands.push(...flattenCommandParameters(cmd));
});
@@ -145,7 +156,7 @@ export const flattenImportedData = (importedData: any): Tool => {
parameters: allParameters,
exclusionGroups,
supportedInput: supportedInput,
- supportedOutput: supportedOutput
+ supportedOutput: supportedOutput,
};
};
@@ -161,8 +172,8 @@ export const defaultTool = (toolName?: string, displayName?: string): Tool => {
name: toolName || "my-tool",
description: "Main command",
isDefault: true,
- sortOrder: 0
- }
+ sortOrder: 0,
+ },
],
parameters: [
{
@@ -178,17 +189,17 @@ export const defaultTool = (toolName?: string, displayName?: string): Tool => {
isRepeatable: false,
enumValues: [],
validations: [],
- dependencies: []
- }
+ dependencies: [],
+ },
],
exclusionGroups: [],
supportedInput: ["StandardInput"],
- supportedOutput: ["StandardOutput"]
+ supportedOutput: ["StandardOutput"],
};
};
export const validateDefaultValue = (
- parameter: Parameter
+ parameter: Parameter,
): { isValid: boolean; error?: string } => {
const { defaultValue, validations, dataType } = parameter;
@@ -204,7 +215,7 @@ export const validateDefaultValue = (
if (!["true", "false", "1", "0"].includes(defaultValue.toLowerCase())) {
return {
isValid: false,
- error: "Default value must be true/false or 1/0"
+ error: "Default value must be true/false or 1/0",
};
}
break;
@@ -215,57 +226,42 @@ export const validateDefaultValue = (
switch (validation.validationType) {
case "min_length":
- if (
- typeof value === "string" &&
- value.length < Number(validation.validationValue)
- ) {
+ if (typeof value === "string" && value.length < Number(validation.validationValue)) {
return {
isValid: false,
- error: validation.errorMessage || "Value too short"
+ error: validation.errorMessage || "Value too short",
};
}
break;
case "max_length":
- if (
- typeof value === "string" &&
- value.length > Number(validation.validationValue)
- ) {
+ if (typeof value === "string" && value.length > Number(validation.validationValue)) {
return {
isValid: false,
- error: validation.errorMessage || "Value too long"
+ error: validation.errorMessage || "Value too long",
};
}
break;
case "min_value":
- if (
- typeof value === "number" &&
- value < Number(validation.validationValue)
- ) {
+ if (typeof value === "number" && value < Number(validation.validationValue)) {
return {
isValid: false,
- error: validation.errorMessage || "Value too small"
+ error: validation.errorMessage || "Value too small",
};
}
break;
case "max_value":
- if (
- typeof value === "number" &&
- value > Number(validation.validationValue)
- ) {
+ if (typeof value === "number" && value > Number(validation.validationValue)) {
return {
isValid: false,
- error: validation.errorMessage || "Value too large"
+ error: validation.errorMessage || "Value too large",
};
}
break;
case "regex":
- if (
- typeof value === "string" &&
- !new RegExp(validation.validationValue).test(value)
- ) {
+ if (typeof value === "string" && !new RegExp(validation.validationValue).test(value)) {
return {
isValid: false,
- error: validation.errorMessage || "Value doesn't match pattern"
+ error: validation.errorMessage || "Value doesn't match pattern",
};
}
break;
@@ -282,14 +278,11 @@ export const createNewCommand = (parentId?: string): Command => {
name: randomCommandName(),
description: "",
isDefault: false,
- sortOrder: 1
+ sortOrder: 1,
};
};
-export const createNewParameter = (
- isGlobal: boolean,
- commandId?: string
-): Parameter => {
+export const createNewParameter = (isGlobal: boolean, commandId?: string): Parameter => {
return {
id: uuidv7(),
name: "",
@@ -308,7 +301,7 @@ export const createNewParameter = (
keyValueSeparator: " ",
enumValues: [],
validations: [],
- dependencies: []
+ dependencies: [],
};
};
@@ -321,10 +314,7 @@ export const getSavedCommandsFromStorage = (toolId: string): SavedCommand[] => {
}
};
-export const saveSavedCommandsToStorage = (
- toolId: string,
- commands: SavedCommand[]
-): void => {
+export const saveSavedCommandsToStorage = (toolId: string, commands: SavedCommand[]): void => {
try {
localStorage.setItem(toolId, JSON.stringify(commands));
} catch (error) {
@@ -332,23 +322,15 @@ export const saveSavedCommandsToStorage = (
}
};
-export const addSavedCommandToStorage = (
- toolId: string,
- command: SavedCommand
-): void => {
+export const addSavedCommandToStorage = (toolId: string, command: SavedCommand): void => {
const existingCommands = getSavedCommandsFromStorage(toolId);
const updatedCommands = [...existingCommands, command];
saveSavedCommandsToStorage(toolId, updatedCommands);
};
-export const removeSavedCommandFromStorage = (
- toolId: string,
- commandId: string
-): void => {
+export const removeSavedCommandFromStorage = (toolId: string, commandId: string): void => {
const existingCommands = getSavedCommandsFromStorage(toolId);
- const updatedCommands = existingCommands.filter(
- (cmd) => cmd.id !== commandId
- );
+ const updatedCommands = existingCommands.filter((cmd) => cmd.id !== commandId);
saveSavedCommandsToStorage(toolId, updatedCommands);
};
@@ -368,8 +350,7 @@ export const randomCommandName = () => {
export function generateHashCode(s: string): string {
let h = 0;
- for (let i = 0; i < s.length; i++)
- h = (Math.imul(31, h) + s.charCodeAt(i)) | 0;
+ for (let i = 0; i < s.length; i++) h = (Math.imul(31, h) + s.charCodeAt(i)) | 0;
return h.toString();
}
diff --git a/registry/commandly/runtime-preview.tsx b/registry/commandly/runtime-preview.tsx
index 6523a5e..fded8e0 100644
--- a/registry/commandly/runtime-preview.tsx
+++ b/registry/commandly/runtime-preview.tsx
@@ -1,26 +1,18 @@
+import { Badge } from "@/components/ui/badge";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
-
-import { Badge } from "@/components/ui/badge";
-import { Switch } from "@/components/ui/switch";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
- SelectValue
+ SelectValue,
} from "@/components/ui/select";
-import { InfoIcon } from "lucide-react";
-import {
- Parameter,
- ParameterValue
-} from "@/registry/commandly/lib/types/commandly";
+import { Switch } from "@/components/ui/switch";
+import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
+import { Parameter, ParameterValue } from "@/registry/commandly/lib/types/commandly";
import { Command, Tool } from "@/registry/commandly/lib/types/commandly";
-import {
- Tooltip,
- TooltipContent,
- TooltipTrigger
-} from "@/components/ui/tooltip";
+import { InfoIcon } from "lucide-react";
import React from "react";
const findDefaultCommand = (tool: Tool): Command | null => {
@@ -28,13 +20,192 @@ const findDefaultCommand = (tool: Tool): Command | null => {
if (defaultCommand) return defaultCommand;
const nameMatchCommand = tool.commands.find(
- (command) => command.name.toLowerCase() === tool.name.toLowerCase()
+ (command) => command.name.toLowerCase() === tool.name.toLowerCase(),
);
if (nameMatchCommand) return nameMatchCommand;
return tool.commands.length > 0 ? tool.commands[0] : null;
};
+interface ParameterLabelProps {
+ name: string;
+ longFlag?: string;
+ shortFlag?: string;
+ isRequired?: boolean;
+ isGlobal?: boolean;
+ description: string;
+ className?: string;
+ children?: React.ReactNode;
+}
+
+function ParameterLabel({
+ name,
+ longFlag,
+ shortFlag,
+ isRequired,
+ isGlobal,
+ description,
+ className,
+ children,
+}: ParameterLabelProps) {
+ return (
+
+ );
+}
+
+type ParameterInputProps = {
+ parameter: Parameter;
+ value: ParameterValue;
+ onUpdate: (value: ParameterValue) => void;
+};
+
+function FlagInput({ parameter, value, onUpdate }: ParameterInputProps) {
+ return (
+
+ );
+}
+
+function OptionEnumInput({ parameter, value, onUpdate }: ParameterInputProps) {
+ return (
+
+
+
+
+ );
+}
+
+function OptionBooleanInput({ parameter, value, onUpdate }: ParameterInputProps) {
+ return (
+
+
onUpdate(checked.toString())}
+ />
+
+
+ );
+}
+
+function OptionTextInput({ parameter, value, onUpdate }: ParameterInputProps) {
+ return (
+
+
+
onUpdate(e.target.value)}
+ placeholder="Enter value"
+ />
+
+ );
+}
+
+function ArgumentInput({ parameter, value, onUpdate }: ParameterInputProps) {
+ return (
+
+
+
+ {parameter.parameterType}
+ {parameter.position !== undefined && ` (${parameter.position})`}
+
+
+
onUpdate(e.target.value)}
+ placeholder="Enter value"
+ />
+
+ );
+}
+
interface RuntimePreviewProps {
selectedCommand?: Command | null;
tool: Tool;
@@ -46,253 +217,77 @@ export function RuntimePreview({
selectedCommand: providedCommand,
tool,
parameterValues,
- updateParameterValue
+ updateParameterValue,
}: RuntimePreviewProps) {
const selectedCommand = providedCommand ?? findDefaultCommand(tool);
- const renderParameterInput = (parameter: Parameter) => {
- const value = parameterValues[parameter.id] || parameter.defaultValue || "";
-
- switch (parameter.parameterType) {
- case "Flag":
- return (
-
-
- updateParameterValue(parameter.id, checked)
- }
- />
-
- {parameter.isGlobal && (
-
- global
-
- )}
-
- );
-
- case "Option":
- if (parameter.dataType === "Enum") {
- return (
-
-
-
-
- );
- } else if (parameter.dataType === "Boolean") {
- return (
-
-
- updateParameterValue(parameter.id, checked.toString())
- }
- />
-
- {parameter.isGlobal && (
-
- global
-
- )}
-
- );
- } else {
- return (
-
-
-
- {parameter.isGlobal && (
-
- global
-
- )}
-
-
- updateParameterValue(parameter.id, e.target.value)
- }
- placeholder="Enter value"
- />
-
- );
- }
-
- case "Argument":
- return (
-
-
-
- updateParameterValue(parameter.id, e.target.value)
- }
- placeholder="Enter value"
- />
-
- );
-
- default:
- return null;
- }
- };
-
return (
{selectedCommand && tool.commands.length === 0 ? (
-
- No commands available for this tool.
-
+ No commands available for this tool.
) : (
{tool.parameters.length > 0 ? (
tool.parameters
- .filter(
- (param) =>
- param.commandId === selectedCommand?.id || param.isGlobal
- )
- .map(renderParameterInput)
+ .filter((param) => param.commandId === selectedCommand?.id || param.isGlobal)
+ .map((parameter) => {
+ const value = parameterValues[parameter.id] || parameter.defaultValue || "";
+ const onUpdate = (val: ParameterValue) => updateParameterValue(parameter.id, val);
+
+ if (parameter.parameterType === "Flag") {
+ return (
+
+ );
+ }
+ if (parameter.parameterType === "Argument") {
+ return (
+
+ );
+ }
+ if (parameter.parameterType === "Option") {
+ if (parameter.dataType === "Enum") {
+ return (
+
+ );
+ }
+ if (parameter.dataType === "Boolean") {
+ return (
+
+ );
+ }
+ return (
+
+ );
+ }
+ return null;
+ })
) : (
-
+
No parameters available for this command.
)}
diff --git a/registry/commandly/tool-editor/command-tree.tsx b/registry/commandly/tool-editor/command-tree.tsx
index 929c245..3d1fb9f 100644
--- a/registry/commandly/tool-editor/command-tree.tsx
+++ b/registry/commandly/tool-editor/command-tree.tsx
@@ -1,32 +1,150 @@
-import { useState, useEffect, ReactNode } from "react";
-import { Button } from "@/components/ui/button";
+import { CommandDialog } from "../tool-editor/dialogs/command-dialog";
+import { toolBuilderStore, toolBuilderActions } from "./tool-editor.store";
import { Badge } from "@/components/ui/badge";
+import { Button } from "@/components/ui/button";
import { ScrollArea } from "@/components/ui/scroll-area";
import { Command } from "@/registry/commandly/lib/types/commandly";
-import {
- ChevronDownIcon,
- ChevronRightIcon,
- Edit2Icon,
- PlusIcon,
- Trash2Icon
-} from "lucide-react";
-import { CommandDialog } from "../tool-editor/dialogs/command-dialog";
import { useStore } from "@tanstack/react-store";
-import { toolBuilderStore, toolBuilderActions } from "./tool-editor.store";
+import { ChevronDownIcon, ChevronRightIcon, Edit2Icon, PlusIcon, Trash2Icon } from "lucide-react";
+import { useState, useEffect } from "react";
+
+interface CommandNodeProps {
+ command: Command;
+ level?: number;
+ allCommands: Command[];
+ toolName: string;
+ selectedCommandId?: string;
+ expandedCommands: Set
;
+ onToggle: (commandId: string) => void;
+ onEdit: (command: Command) => void;
+ onAddSubcommand: (parentId?: string) => void;
+ onDelete: (commandId: string) => void;
+}
+
+function CommandNode({
+ command,
+ level = 0,
+ allCommands,
+ toolName,
+ selectedCommandId,
+ expandedCommands,
+ onToggle,
+ onEdit,
+ onAddSubcommand,
+ onDelete,
+}: CommandNodeProps) {
+ const isExpanded = expandedCommands.has(command.id);
+ const subcommands = allCommands.filter((cmd) => cmd.parentCommandId === command.id);
+ const hasSubcommands = subcommands.length > 0;
+ const isSelected = selectedCommandId === command.id;
+ const isRoot = command.name === toolName;
+
+ return (
+
+
toolBuilderActions.setSelectedCommand(command)}
+ >
+ {hasSubcommands ? (
+
+ ) : (
+
+ )}
+
+
{command.name}
+ {command.isDefault && (
+
+ default
+
+ )}
+
+
+ {!isRoot && (
+
+ )}
+
+
+ {isExpanded && hasSubcommands && (
+
+ {subcommands.map((subcmd) => (
+
+ ))}
+
+ )}
+
+ );
+}
export function CommandTree() {
const tool = useStore(toolBuilderStore, (state) => state.tool);
- const selectedCommand = useStore(
- toolBuilderStore,
- (state) => state.selectedCommand
- );
- const editingCommand = useStore(
- toolBuilderStore,
- (state) => state.editingCommand
- );
+ const selectedCommand = useStore(toolBuilderStore, (state) => state.selectedCommand);
+ const editingCommand = useStore(toolBuilderStore, (state) => state.editingCommand);
const [expandedCommands, setExpandedCommands] = useState>(
- new Set([tool.commands[0]?.id])
+ new Set([tool.commands[0]?.id]),
);
const [isDialogOpen, setIsDialogOpen] = useState(false);
const [lastAddedCommand, setLastAddedCommand] = useState<{
@@ -34,10 +152,6 @@ export function CommandTree() {
parentId?: string;
} | null>(null);
- const handleEditCommand = (command: Command | null) => {
- toolBuilderActions.setEditingCommand(command);
- };
-
const toggleExpanded = (commandId: string) => {
setExpandedCommands((prev) => {
const newSet = new Set(prev);
@@ -54,9 +168,7 @@ export function CommandTree() {
const handleAddSubcommand = (parentId?: string) => {
const prevIds = new Set(tool.commands.map((cmd) => cmd.id));
toolBuilderActions.addSubcommand(parentId);
- const newCmd = toolBuilderStore.state.tool.commands.find(
- (cmd) => !prevIds.has(cmd.id)
- );
+ const newCmd = toolBuilderStore.state.tool.commands.find((cmd) => !prevIds.has(cmd.id));
if (newCmd) {
setLastAddedCommand({ id: newCmd.id, parentId });
}
@@ -79,100 +191,9 @@ export function CommandTree() {
}
}, [tool.commands, lastAddedCommand]);
- const renderCommandNode = (command: Command, level = 0): ReactNode => {
- const isExpanded = expandedCommands.has(command.id);
- const subcommands = tool.commands.filter(
- (cmd) => cmd.parentCommandId === command.id
- );
- const hasSubcommands = subcommands.length > 0;
- const isSelected = selectedCommand?.id === command.id;
- const isRoot = command.name == tool.name;
-
- return (
-
-
toolBuilderActions.setSelectedCommand(command)}
- >
- {hasSubcommands ? (
-
- ) : (
-
- )}
-
-
{command.name}
- {command.isDefault && (
-
- default
-
- )}
-
-
- {!isRoot && (
-
- )}
-
-
- {isExpanded && hasSubcommands && (
- <>
-
- {subcommands.map((subcmd) =>
- renderCommandNode(subcmd, level + 1)
- )}
-
- >
- )}
-
- );
+ const handleEdit = (command: Command) => {
+ toolBuilderActions.setEditingCommand(command);
+ setIsDialogOpen(true);
};
const rootCommands = tool.commands.filter((cmd) => !cmd.parentCommandId);
@@ -181,11 +202,27 @@ export function CommandTree() {
<>
- {rootCommands.map((command) => renderCommandNode(command))}
+ {rootCommands.map((command) => (
+
+ ))}
-
@@ -195,7 +232,7 @@ export function CommandTree() {
isOpen={isDialogOpen}
onOpenChange={(open) => {
setIsDialogOpen(open);
- handleEditCommand(null);
+ toolBuilderActions.setEditingCommand(null);
}}
/>
)}
diff --git a/registry/commandly/tool-editor/dialogs/command-dialog.tsx b/registry/commandly/tool-editor/dialogs/command-dialog.tsx
index e0ce262..542ceed 100644
--- a/registry/commandly/tool-editor/dialogs/command-dialog.tsx
+++ b/registry/commandly/tool-editor/dialogs/command-dialog.tsx
@@ -1,21 +1,21 @@
+import { toolBuilderActions, toolBuilderStore } from "../tool-editor.store";
import { Button } from "@/components/ui/button";
-import { Input } from "@/components/ui/input";
-import { Label } from "@/components/ui/label";
-import { Textarea } from "@/components/ui/textarea";
-import { Switch } from "@/components/ui/switch";
import {
Dialog,
DialogContent,
DialogHeader,
DialogTitle,
DialogFooter,
- DialogDescription
+ DialogDescription,
} from "@/components/ui/dialog";
+import { Input } from "@/components/ui/input";
+import { Label } from "@/components/ui/label";
+import { Switch } from "@/components/ui/switch";
+import { Textarea } from "@/components/ui/textarea";
import { Command } from "@/registry/commandly/lib/types/commandly";
+import { useStore } from "@tanstack/react-store";
import { TerminalIcon } from "lucide-react";
import { useState } from "react";
-import { useStore } from "@tanstack/react-store";
-import { toolBuilderActions, toolBuilderStore } from "../tool-editor.store";
interface CommandDialogProps {
isOpen: boolean;
@@ -28,16 +28,17 @@ export function CommandDialog({ isOpen, onOpenChange }: CommandDialogProps) {
const [editCommand, setCommand] = useState(command!);
return (
-