@kaia-team/n8n-nodes-kaia
Version:
n8n nodes for Kaia LLM integration
310 lines • 9.95 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.apiConfigsApiProperties = void 0;
exports.handleApiConfigsApi = handleApiConfigsApi;
const n8n_workflow_1 = require("n8n-workflow");
const utils_1 = require("../utils");
/**
* API Configs API Properties
* Properties specific to the apiConfigs API resource
*/
exports.apiConfigsApiProperties = [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
resource: ['apiConfigs'],
},
},
options: [
{
name: 'Create',
value: 'create',
action: 'Create an API config',
},
{
name: 'Delete',
value: 'delete',
action: 'Delete an API config',
},
{
name: 'List',
value: 'list',
action: 'List API configs',
},
{
name: 'Read',
value: 'read',
action: 'Read an API config',
},
{
name: 'Update',
value: 'update',
action: 'Update an API config',
},
],
default: 'list',
},
{
displayName: 'API Config ID',
name: 'apiConfigId',
type: 'string',
default: '',
displayOptions: {
show: {
resource: ['apiConfigs'],
operation: ['read', 'update', 'delete'],
},
},
required: true,
},
{
displayName: 'Name',
name: 'name',
type: 'string',
default: '',
displayOptions: {
show: {
resource: ['apiConfigs'],
operation: ['create', 'update'],
},
},
},
{
displayName: 'Hidden',
name: 'hidden',
type: 'boolean',
default: true,
displayOptions: {
show: {
resource: ['apiConfigs'],
operation: ['create', 'update'],
},
},
},
{
displayName: 'Title',
name: 'title',
type: 'string',
default: '',
displayOptions: {
show: {
resource: ['apiConfigs'],
operation: ['create', 'update'],
},
},
description: 'Assistant name',
},
{
displayName: 'Asst UUID',
name: 'asst_uuid',
type: 'string',
default: '',
displayOptions: {
show: {
resource: ['apiConfigs'],
operation: ['create', 'update'],
},
},
},
{
displayName: 'Body',
name: 'body',
type: 'string',
typeOptions: { rows: 4 },
default: '',
displayOptions: {
show: {
resource: ['apiConfigs'],
operation: ['create', 'update'],
},
},
description: 'Instructions',
},
{
displayName: 'Model',
name: 'model',
type: 'string',
default: '',
displayOptions: {
show: {
resource: ['apiConfigs'],
operation: ['create', 'update'],
},
},
},
{
displayName: 'Temp',
name: 'temp',
type: 'number',
typeOptions: { minValue: 0, maxValue: 2, numberStepSize: 0.01 },
default: 1,
displayOptions: {
show: {
resource: ['apiConfigs'],
operation: ['create', 'update'],
},
},
},
{
displayName: 'Seed',
name: 'seed',
type: 'number',
default: 0,
displayOptions: {
show: {
resource: ['apiConfigs'],
operation: ['create', 'update'],
},
},
},
{
displayName: 'Vec ID IDs',
name: 'vec_id_ids',
type: 'fixedCollection',
typeOptions: { multipleValues: true },
default: {},
placeholder: 'Add Vec ID',
displayOptions: {
show: {
resource: ['apiConfigs'],
operation: ['create', 'update'],
},
},
options: [
{
name: 'vecIdItems',
displayName: 'Vec ID Items',
values: [
{
displayName: 'ID',
name: 'id',
type: 'string',
default: '',
},
{
displayName: 'Weight',
name: 'weight',
type: 'number',
default: 1,
},
],
},
],
},
{
displayName: 'Function Calls',
name: 'function_calls',
type: 'string',
default: '',
displayOptions: {
show: {
resource: ['apiConfigs'],
operation: ['create', 'update'],
},
},
description: 'Comma-separated list of function call IDs',
},
];
/**
* API Configs API Handler
* Handles requests to the apiConfigs API
*/
async function handleApiConfigsApi(executeFunctions, itemIndex, adminUrl, adminToken) {
const operation = executeFunctions.getNodeParameter('operation', itemIndex);
const additionalFields = executeFunctions.getNodeParameter('additionalFields', itemIndex, {});
const headers = (0, utils_1.createHeaders)(adminToken, additionalFields);
if (operation === 'list') {
const response = await executeFunctions.helpers.httpRequest({
method: 'GET',
url: `${adminUrl}/api_configs.json`,
headers,
});
return executeFunctions.helpers.returnJsonArray(response);
}
else if (operation === 'read') {
let apiConfigId = executeFunctions.getNodeParameter('apiConfigId', itemIndex);
apiConfigId = (0, utils_1.extractIdFromUrlOrId)(apiConfigId, 'api_configs');
const response = await executeFunctions.helpers.httpRequest({
method: 'GET',
url: `${adminUrl}/api_configs/${apiConfigId}.json`,
headers,
});
return response;
}
else if (operation === 'create' || operation === 'update') {
const payload = { api_config: { assistant_attributes: {} } };
// Add name at the top level
const addIfSet = (key, param, defaultVal = '') => {
const val = executeFunctions.getNodeParameter(param, itemIndex, defaultVal);
if (val !== defaultVal && (typeof val !== 'string' || val.trim() !== '')) {
payload.api_config[key] = val;
}
};
// Add assistant attributes
const addAssistantAttr = (key, param, defaultVal = '') => {
const val = executeFunctions.getNodeParameter(param, itemIndex, defaultVal);
if (val !== defaultVal && (typeof val !== 'string' || val.trim() !== '')) {
payload.api_config.assistant_attributes[key] = val;
}
};
addIfSet('name', 'name');
addAssistantAttr('hidden', 'hidden', true);
addAssistantAttr('title', 'title');
addAssistantAttr('asst_uuid', 'asst_uuid');
addAssistantAttr('body', 'body');
addAssistantAttr('model', 'model');
addAssistantAttr('temp', 'temp', 1);
addAssistantAttr('seed', 'seed', 0);
const vecIdItems = executeFunctions.getNodeParameter('vec_id_ids.vecIdItems', itemIndex, []);
if (vecIdItems.length > 0) {
// Convert to the format expected by Rails: {"0": {"id": "...", "weight": "..."}, "1": {...}}
const vecDbIds = {};
vecIdItems.forEach((item, index) => {
vecDbIds[index.toString()] = {
id: item.id,
weight: item.weight,
};
});
payload.api_config.assistant_attributes.vec_db_ids = vecDbIds;
}
const functionCallsStr = executeFunctions.getNodeParameter('function_calls', itemIndex, '');
if (functionCallsStr.trim() !== '') {
payload.api_config.assistant_attributes.function_calls = functionCallsStr
.split(',')
.map(s => s.trim());
}
const method = operation === 'create' ? 'post' : 'patch';
let url;
if (operation === 'create') {
url = `${adminUrl}/api_configs.json`;
}
else {
let apiConfigId = executeFunctions.getNodeParameter('apiConfigId', itemIndex);
apiConfigId = (0, utils_1.extractIdFromUrlOrId)(apiConfigId, 'api_configs');
url = `${adminUrl}/api_configs/${apiConfigId}.json`;
}
const response = await executeFunctions.helpers.httpRequest({
method: method.toUpperCase(),
url,
body: payload,
headers,
});
return response;
}
else if (operation === 'delete') {
let apiConfigId = executeFunctions.getNodeParameter('apiConfigId', itemIndex);
apiConfigId = (0, utils_1.extractIdFromUrlOrId)(apiConfigId, 'api_configs');
const response = await executeFunctions.helpers.httpRequest({
method: 'DELETE',
url: `${adminUrl}/api_configs/${apiConfigId}.json`,
headers,
});
return { success: true, deletedId: apiConfigId };
}
throw new n8n_workflow_1.NodeOperationError(executeFunctions.getNode(), `Unknown API configs operation: ${operation}`);
}
//# sourceMappingURL=apiConfigsApi.js.map