Initial commit

This commit is contained in:
Jordan
2026-04-01 23:16:45 +01:00
commit 91cfdaee72
200 changed files with 25589 additions and 0 deletions

View File

@@ -0,0 +1,82 @@
import { z } from "zod";
import axios from "axios";
import path from "path";
import { withAuth, getSessionCredentials } from "../../auth/index.js";
import { handleToolError, validateRequired } from "../helpers/errorHandler.js";
import { withAuthParams } from "../helpers/authSchema.js";
import { LOCAL_SERVER_URL } from "../../config/index.js";
export function registerCompileModuleTool(server) {
server.tool(
"compile_module",
`Manually recompile a module or general section when generated files may be out of sync and you need to force compilation without editing index-base.tpl.
Do not use this as part of the normal editing flow: most index-base.tpl edits made through the Acai file tools compile automatically.
This is a recovery / resync tool, not a required step after routine changes.
It parses the HTML into Twig, generates builder vars, and syncs with the Docker CMS.
Pass the full path to the index-base.tpl file and the project directory.`,
withAuthParams({
filePath: z.string().describe("Full absolute path to the index-base.tpl file that was edited"),
projectDir: z.string().describe("Full absolute path to the project root directory"),
}),
{ readOnlyHint: false, destructiveHint: false },
withAuth(async ({ filePath, projectDir }, extra) => {
try {
const validationError = validateRequired(
{ filePath, projectDir },
['filePath', 'projectDir'],
'compile_module'
);
if (validationError) return validationError;
const normalizedProjectDir = path.resolve(projectDir);
const normalizedFilePath = path.resolve(filePath);
const projectSlug = path.basename(normalizedProjectDir);
const relativePath = path.relative(normalizedProjectDir, normalizedFilePath);
const canUseSlugMode =
!!projectSlug &&
!!relativePath &&
relativePath !== "" &&
!relativePath.startsWith("..") &&
!path.isAbsolute(relativePath);
const payload = canUseSlugMode
? { project: projectSlug, relativePath, project_dir: projectDir }
: { file: filePath, project_dir: projectDir };
// Call the Python server compile endpoint
const response = await axios.post(
`${LOCAL_SERVER_URL}/api/compile-module`,
payload,
{ headers: { "Content-Type": "application/json" }, timeout: 30000 }
);
if (response.data?.ok) {
return {
content: [{
type: "text",
text: JSON.stringify({
success: true,
message: "Module compiled successfully",
output: response.data.output || "",
}, null, 2)
}],
};
} else {
return {
content: [{
type: "text",
text: JSON.stringify({
success: false,
error: response.data?.error || "Compilation failed",
}, null, 2)
}],
isError: true,
};
}
} catch (error) {
return handleToolError(error, 'compile_module', { filePath, projectDir });
}
})
);
}