import { withAuth, getSessionCredentials } from "../../auth/index.js"; import { handleToolError, handleApiResponse } from "../helpers/errorHandler.js"; import { AcaiHttpClient } from "../helpers/acaiHttpClient.js"; import { withAuthParams } from "../helpers/authSchema.js"; export function registerListWebLanguagesTool(server) { server.tool( "list_web_languages", `List the active languages configured for the current website (from settings.dat.php [idiomas]). Returns an array of languages, each with: - name: internal code (e.g. 'espanol') - label: human label - prefix: the translation prefix stored in cms_traducciones. The prefix "www" is the BASE language (its URLs have NO path prefix). Any other prefix (e.g. "en") is a secondary language served under //... - urlPrefix: the URL path segment for that language ('' for the base language, e.g. 'en' otherwise) - isDefault: true for the base language Also returns defaultLanguage. Use the prefix values here when calling get_record_translations / set_record_translations.`, withAuthParams({}), { readOnlyHint: true, destructiveHint: false }, withAuth(async (_args, extra) => { try { const credentials = await getSessionCredentials(extra.sessionId); const response = await AcaiHttpClient.postViewerAction( credentials, "getLanguages", {}, credentials.token, credentials.tokenHash, {}, 15000 ); const apiError = handleApiResponse(response.data, "list_web_languages"); if (apiError) return apiError; return { content: [{ type: "text", text: JSON.stringify({ success: true, action: "list_web_languages", languages: response.data?.languages || [], defaultLanguage: response.data?.defaultLanguage, }, null, 2) }], }; } catch (error) { return handleToolError(error, "list_web_languages"); } }) ); }