import z from 'zod';
const parameters = z.object({
    directoryPath: z
        .string()
        .nullable()
        .optional()
        .describe('Directory to inspect. Defaults to the user\'s home directory when null.'),
    recursive: z
        .boolean()
        .nullable()
        .optional()
        .describe('Whether to list files recursively in subdirectories. Defaults to false when null.'),
    showHidden: z
        .boolean()
        .nullable()
        .optional()
        .describe('Whether to include dot-prefixed files/directories. Defaults to false when null.'),
    exclude: z
        .array(z.string())
        .nullable()
        .optional()
        .describe('File or directory names/paths to exclude from the listing.'),
});
export const listDirectoryTool = {
    name: 'sys:list_directory',
    description: `
  List the files and directories in a specified directory path on the local filesystem.
  You can specify options such as recursive listing, hidden files, and exclusions.
  If no directory path is provided, the tool defaults to the user's HOME directory.
  `,
    parameters,
    async execute(input) {
        if (!window.filesystem?.listDirectory) {
            throw new Error('filesystem bridge is not available');
        }
        const args = parameters.parse(input ?? {});
        try {
            const files = await window.filesystem.listDirectory({
                directoryPath: args.directoryPath ?? undefined,
                recursive: args.recursive ?? false,
                showHidden: args.showHidden ?? false,
                exclude: args.exclude ?? [],
            });
            return JSON.stringify(files, null, 2);
        }
        catch (error) {
            return `Error listing directory: ${error.message}`;
        }
    },
};
