- Nueva categoria tools/languages: list_web_languages, get_record_translations y set_record_translations (registros, config, textos_generales y vars de modulo via builder_custom). - Param lang opcional en list_table_records y get_record (options.translates de CocoDB). - Docs actualizados (03/04/06/09/11b + ACAI_ENDPOINTS) con el modelo de cms_traducciones y los workflows de traduccion.
55 lines
2.3 KiB
JavaScript
55 lines
2.3 KiB
JavaScript
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>/...
|
|
- 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");
|
|
}
|
|
})
|
|
);
|
|
}
|