Una sesion real del agente guardo title3/title6/title2 (columnas de builder_custom segun varsMeta.fieldName, como decian las docs) y el front no pintaba nada: el runtime traduce vars con t($record, $var) por nombre de var. Corregidas descripciones de set/get_record_translations, docs 03/09/11b y ACAI_ENDPOINTS; ademas el puente PHP ahora rechaza titleN/ textN sobre builder_custom con error explicativo (guardrail).
75 lines
3.9 KiB
JavaScript
75 lines
3.9 KiB
JavaScript
import { z } from "zod";
|
|
import { withAuth, getSessionCredentials } from "../../auth/index.js";
|
|
import { handleToolError, validateRequired, handleApiResponse } from "../helpers/errorHandler.js";
|
|
import { AcaiHttpClient } from "../helpers/acaiHttpClient.js";
|
|
import { withAuthParams } from "../helpers/authSchema.js";
|
|
|
|
export function registerGetRecordTranslationsTool(server) {
|
|
server.tool(
|
|
"get_record_translations",
|
|
`Read the stored translations for one or more records of a table, from the central cms_traducciones table.
|
|
|
|
Translations are keyed by (prefix = language code, tableName without 'cms_', fieldName, recordNum). Values are stored Base64 in the DB but this tool returns them already decoded (plain text). An absent field/prefix means there is no translation and the base-language value is used at runtime.
|
|
|
|
Params:
|
|
- tableName: table name WITHOUT the 'cms_' prefix (e.g. 'apartados', 'productos', 'builder_custom', 'textos_generales').
|
|
- recordNums: array of record 'num' primary keys to read.
|
|
- fields (optional): only return these field names. Omit to return every translated field found.
|
|
- prefix (optional): only return translations for this language prefix (e.g. 'en'). Omit to return all languages.
|
|
|
|
Returns translations shaped as { "<recordNum>": { "<prefix>": { "<fieldName>": "<value>" } } }.
|
|
|
|
To read module var translations, call get_module_config_vars for the recordNum (varsMeta) and read tableName='builder_custom' — rows are keyed by VAR NAME ('titulo', 'subtitulo'...), not by physical column (title3). For template literals, read tableName='textos_generales' field 'texto'.`,
|
|
withAuthParams({
|
|
tableName: z.string().describe("Table name without 'cms_' prefix (e.g. 'apartados', 'builder_custom', 'textos_generales')"),
|
|
recordNums: z.array(z.number()).describe("Array of record 'num' primary keys to read translations for"),
|
|
fields: z.array(z.string()).optional().describe("Only return these field names. Omit to return all translated fields."),
|
|
prefix: z.string().optional().describe("Only return translations for this language prefix (e.g. 'en'). Omit for all languages."),
|
|
}),
|
|
{ readOnlyHint: true, destructiveHint: false },
|
|
withAuth(async ({ tableName, recordNums, fields, prefix }, extra) => {
|
|
try {
|
|
const validationError = validateRequired(
|
|
{ tableName, recordNums },
|
|
["tableName", "recordNums"],
|
|
"get_record_translations"
|
|
);
|
|
if (validationError) return validationError;
|
|
|
|
const credentials = await getSessionCredentials(extra.sessionId);
|
|
|
|
const payload = { tableName, recordNums };
|
|
if (fields && fields.length > 0) payload.fields = fields;
|
|
if (prefix) payload.prefix = prefix;
|
|
|
|
const response = await AcaiHttpClient.postViewerAction(
|
|
credentials,
|
|
"getTranslations",
|
|
payload,
|
|
credentials.token,
|
|
credentials.tokenHash,
|
|
{},
|
|
15000
|
|
);
|
|
|
|
const apiError = handleApiResponse(response.data, "get_record_translations");
|
|
if (apiError) return apiError;
|
|
|
|
return {
|
|
content: [{
|
|
type: "text",
|
|
text: JSON.stringify({
|
|
success: true,
|
|
action: "get_record_translations",
|
|
tableName: response.data?.tableName || tableName,
|
|
translations: response.data?.translations || {},
|
|
}, null, 2)
|
|
}],
|
|
};
|
|
} catch (error) {
|
|
return handleToolError(error, "get_record_translations", { tableName, recordNums });
|
|
}
|
|
})
|
|
);
|
|
}
|