import { z } from "zod"; import { handleToolError, validateRequired } from "../helpers/errorHandler.js"; import { getCurrentProjectInfo, callLocalFileEndpoint, buildLocalFileErrorResponse } from "./helpers.js"; import { isProtectedLayoutPath, buildProtectedLayoutPathError } from "./protectedPaths.js"; export function registerAcaiDeleteTool(server) { server.tool( "acai-delete", "Delete a file inside the project. Destructive operation.", { file_path: z.string().describe("Path relative to the project root"), expected_sha256: z.string().optional().describe("Optional safety check before deletion"), }, { readOnlyHint: false, destructiveHint: true }, async ({ file_path, expected_sha256 }) => { try { const validationError = validateRequired({ file_path }, ["file_path"], "acai-delete"); if (validationError) return validationError; if (isProtectedLayoutPath(file_path)) { return buildProtectedLayoutPathError(file_path); } const { projectSlug, projectDir } = getCurrentProjectInfo(); const result = await callLocalFileEndpoint("POST", "/api/files/delete", { project: projectSlug, projectDir: projectDir, relativePath: file_path, expectedSha256: expected_sha256 || "", }); if (!result.data?.success) { return buildLocalFileErrorResponse("acai-delete", result, { file_path }); } const data = result.data; return { content: [{ type: "text", text: JSON.stringify({ success: true, file_path: data.filePath, deleted: data.deleted, }, null, 2), }], }; } catch (error) { return handleToolError(error, "acai-delete", { file_path }); } } ); }