feat: tools get_hook_entryparams / set_hook_entryparams

Completan la feature del endpoint /api/creator/hook-entryparams, que ya
estaba desplegado en el server (commit fe81765 del repo de Forge) pero sin
tools que lo usaran desde el agente.

Los entryParams son los parametros de entrada declarados de un hook global
({variable, value?, valueType?}), que se le pasan al invocarlo.
This commit is contained in:
Jordan Diaz
2026-08-12 11:32:17 +00:00
parent bdee7665ec
commit f7e950694e

View File

@@ -129,16 +129,130 @@ Examples:
); );
} }
function registerGetHookEntryParamsTool(server) {
server.tool(
"get_hook_entryparams",
`Read the declared entry parameters (entryParams) of a global hook. entryParams are the input parameters a hook expects — each has a required 'variable' name plus optional 'value' and 'valueType'. They are passed to the hook when it is invoked.
Use this when the user asks about a hook's inputs, or to inspect the current params before editing them.
hookEndPoint format: starts and ends with '/', with '/' as separator. E.g. "/hooks/appListado/".
Returns:
- entryParams: array of { variable, value?, valueType? }.
Example: [{ "variable": "action" }, { "variable": "data", "value": "", "valueType": "Integer" }].`,
withAuthParams({
hookEndPoint: z.string().describe('Hook endpoint path, e.g. "/hooks/appListado/"'),
}),
{ readOnlyHint: true, destructiveHint: false },
withAuth(async ({ hookEndPoint }, extra) => {
try {
const { projectSlug } = getCurrentProjectInfo();
const result = await pythonGet("/api/creator/hook-entryparams", {
project: projectSlug,
endPoint: hookEndPoint,
});
if (!result?.success) {
return {
content: [{
type: "text",
text: JSON.stringify({
success: false,
error: result?.error || "No se pudieron leer los entryParams",
}),
}],
isError: true,
};
}
return {
content: [{
type: "text",
text: JSON.stringify({
success: true,
exists: !!result.exists,
entryParams: result.entryParams || [],
hookEndPoint,
}, null, 2),
}],
};
} catch (error) {
return handleToolError(error, "get_hook_entryparams", { hookEndPoint });
}
})
);
}
function registerSetHookEntryParamsTool(server) {
server.tool(
"set_hook_entryparams",
`Set the declared entry parameters (entryParams) of a global hook. entryParams describe the inputs a hook expects — each has a required 'variable' name plus optional 'value' and 'valueType'.
IMPORTANT: this OVERWRITES the entire entryParams list of the hook (it does NOT merge). You must pass the COMPLETE set of params every time, because the whole array is replaced.
Use this AFTER creating or editing the hook file (via acai-write) to declare which inputs it accepts.
entryParams format: array of { variable, value?, valueType? }.
Example: [{ "variable": "action" }, { "variable": "data", "value": "", "valueType": "Integer" }].`,
withAuthParams({
hookEndPoint: z.string().describe('Hook endpoint path, e.g. "/hooks/appListado/"'),
entryParams: z.array(z.object({
variable: z.string(),
value: z.string().optional(),
valueType: z.string().optional(),
})).describe('Complete list of entry params. Each item: { variable (required), value? (string), valueType? (string) }. Replaces the whole array. E.g. [{"variable":"action"},{"variable":"data","value":"","valueType":"Integer"}]'),
}),
{ readOnlyHint: false, destructiveHint: false },
withAuth(async ({ hookEndPoint, entryParams }, extra) => {
try {
const { projectSlug } = getCurrentProjectInfo();
const result = await pythonPost("/api/creator/hook-entryparams", {
project: projectSlug,
endPoint: hookEndPoint,
entryParams,
});
if (!result?.success) {
return {
content: [{
type: "text",
text: JSON.stringify({
success: false,
error: result?.error || "No se pudo guardar",
}),
}],
isError: true,
};
}
return {
content: [{
type: "text",
text: JSON.stringify({
success: true,
message: result.message || "entryParams actualizados",
entryParams: result.entryParams || [],
hookEndPoint,
}, null, 2),
}],
};
} catch (error) {
return handleToolError(error, "set_hook_entryparams", { hookEndPoint, entryParams });
}
})
);
}
/** /**
* Registra las tools de configuracion de hooks globales. * Registra las tools de configuracion de hooks globales.
* *
* `get_hook_middleware` es de solo lectura y se registra siempre. El set * Las tools de solo lectura (`get_hook_middleware`, `get_hook_entryparams`) se
* modifica el layout y solo se expone si el rol puede editar codigo — sigue * registran siempre. Las de escritura modifican el layout y solo se exponen si
* el mismo criterio que otras tools de escritura (ver project/index.js). * el rol puede editar codigo — sigue el mismo criterio que otras tools de
* escritura (ver project/index.js).
*/ */
export function registerHookTools(server) { export function registerHookTools(server) {
registerGetHookMiddlewareTool(server); registerGetHookMiddlewareTool(server);
registerGetHookEntryParamsTool(server);
if (canEditCode()) { if (canEditCode()) {
registerSetHookMiddlewareTool(server); registerSetHookMiddlewareTool(server);
registerSetHookEntryParamsTool(server);
} }
} }