n8n-nodes-aimlapi
Version:
Custom n8n node for integrating with the AI/ML API platform (AIMLAPI) to interact with LLMs and multimodal AI models such as chat completion endpoints.
56 lines • 1.93 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createRequestOptions = createRequestOptions;
exports.resolveEndpoint = resolveEndpoint;
const AIMLAPI_NODE_TITLE = 'n8n AIMLAPI Node';
const TRAILING_SLASH_REGEX = /\/+$/;
const VERSION_PREFIX_REGEX = /^\/(v\d+)(?=\/|$)/;
const VERSION_SUFFIX_REGEX = /\/v\d+$/;
function normalizePath(path) {
return path.startsWith('/') ? path : `/${path}`;
}
function resolveEndpoint(baseURL, path) {
const normalizedPath = normalizePath(path);
const trimmedBase = baseURL.replace(TRAILING_SLASH_REGEX, '');
const versionMatch = VERSION_PREFIX_REGEX.exec(normalizedPath);
if (!versionMatch) {
return {
baseURL: trimmedBase,
url: normalizedPath,
};
}
const baseWithoutVersion = trimmedBase.replace(VERSION_SUFFIX_REGEX, '');
const version = versionMatch[1];
const resolvedPath = normalizedPath.slice(versionMatch[0].length) || '/';
return {
baseURL: `${baseWithoutVersion}/${version}`,
url: resolvedPath.startsWith('/') ? resolvedPath : `/${resolvedPath}`,
};
}
function hasContentTypeHeader(headers) {
if (!headers) {
return false;
}
return Object.keys(headers).some((key) => key.toLowerCase() === 'content-type');
}
function createRequestOptions(baseURL, path, method = 'POST', overrides = {}) {
const endpoint = resolveEndpoint(baseURL, path);
const { headers: overrideHeaders, ...restOverrides } = overrides;
const headers = {
'X-Title': AIMLAPI_NODE_TITLE,
...(overrideHeaders ?? {}),
};
if (!hasContentTypeHeader(headers)) {
headers['Content-Type'] = 'application/json';
}
return {
method,
baseURL: endpoint.baseURL,
url: endpoint.url,
headers,
json: true,
body: {},
...restOverrides,
};
}
//# sourceMappingURL=request.js.map