46 lines
1.6 KiB
JavaScript
46 lines
1.6 KiB
JavaScript
import axios from "axios";
|
|
import { resolveCurrentAcaiUser } from "./sessionHelpers.js";
|
|
|
|
const PYTHON_BASE = `http://app:${process.env.ACAI_PORT || 9091}`;
|
|
|
|
/**
|
|
* Construye el set de headers comunes para llamadas al server Python interno.
|
|
* Inyecta automaticamente `X-Acai-User` cuando hay sesion MCP activa con
|
|
* `acai_user` conocido, lo que permite a los endpoints autenticados identificar
|
|
* al usuario sin Authorization Basic.
|
|
*/
|
|
function buildPythonHeaders(extra = {}) {
|
|
const authHeader = process.env.ACAI_AUTH_HEADER || "";
|
|
const mode = process.env.ACAI_MODE_OVERRIDE || process.env.ACAI_MODE || "";
|
|
const role = process.env.ACAI_ROLE_OVERRIDE || "";
|
|
const acaiUser = resolveCurrentAcaiUser();
|
|
|
|
return {
|
|
"Content-Type": "application/json",
|
|
...(authHeader ? { "Authorization": authHeader } : {}),
|
|
...(mode ? { "X-Acai-Mode": mode } : {}),
|
|
...(role ? { "X-Acai-Role": role } : {}),
|
|
...(acaiUser ? { "X-Acai-User": acaiUser } : {}),
|
|
...extra,
|
|
};
|
|
}
|
|
|
|
export async function pythonPost(path, data, timeout = 120000) {
|
|
const response = await axios.post(`${PYTHON_BASE}${path}`, data, {
|
|
headers: buildPythonHeaders(),
|
|
timeout,
|
|
maxBodyLength: Infinity,
|
|
maxContentLength: Infinity,
|
|
});
|
|
return response.data;
|
|
}
|
|
|
|
export async function pythonGet(path, params = null, timeout = 30000) {
|
|
const response = await axios.get(`${PYTHON_BASE}${path}`, {
|
|
params: params || undefined,
|
|
headers: buildPythonHeaders(),
|
|
timeout,
|
|
});
|
|
return response.data;
|
|
}
|