@kaia-team/n8n-nodes-kaia
Version:
n8n nodes for Kaia LLM integration
189 lines • 6.58 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.functionCallsApiProperties = void 0;
exports.handleFunctionCallsApi = handleFunctionCallsApi;
const n8n_workflow_1 = require("n8n-workflow");
const utils_1 = require("../utils");
/**
* Function Calls API Properties
* Properties specific to the functionCalls API resource
*/
exports.functionCallsApiProperties = [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
resource: ['functionCalls'],
},
},
options: [
{
name: 'Create',
value: 'create',
action: 'Create a function call',
},
{
name: 'Delete',
value: 'delete',
action: 'Delete a function call',
},
{
name: 'List',
value: 'list',
action: 'List function calls',
},
{
name: 'Read',
value: 'read',
action: 'Read a function call',
},
{
name: 'Update',
value: 'update',
action: 'Update a function call',
},
],
default: 'list',
},
{
displayName: 'Function Call ID',
name: 'functionCallId',
type: 'string',
default: '',
displayOptions: {
show: {
resource: ['functionCalls'],
operation: ['read', 'update', 'delete'],
},
},
description: 'The ID of the function call',
required: true,
},
{
displayName: 'Data',
name: 'data',
type: 'string',
typeOptions: { rows: 4 },
default: '',
displayOptions: {
show: {
resource: ['functionCalls'],
operation: ['create', 'update'],
},
},
description: 'JSON encoded function data',
},
// Additional Fields for custom headers
{
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
placeholder: 'Add Field',
default: {},
displayOptions: {
show: {
resource: ['functionCalls'],
},
},
options: [
{
displayName: 'Headers',
name: 'headers',
type: 'fixedCollection',
typeOptions: {
multipleValues: true,
},
placeholder: 'Add Header',
default: {},
options: [
{
name: 'headerParameters',
displayName: 'Headers',
values: [
{
displayName: 'Name',
name: 'name',
type: 'string',
default: '',
description: 'Name of the header',
},
{
displayName: 'Value',
name: 'value',
type: 'string',
default: '',
description: 'Value of the header',
},
],
},
],
},
],
},
];
/**
* Function Calls API Handler
* Handles requests to the functionCalls API
*/
async function handleFunctionCallsApi(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}/function_calls.json`,
headers,
});
return executeFunctions.helpers.returnJsonArray(response);
}
else if (operation === 'read') {
let functionCallId = executeFunctions.getNodeParameter('functionCallId', itemIndex);
functionCallId = (0, utils_1.extractIdFromUrlOrId)(functionCallId, 'function_calls');
const response = await executeFunctions.helpers.httpRequest({
method: 'GET',
url: `${adminUrl}/function_calls/${functionCallId}.json`,
headers,
});
return response;
}
else if (operation === 'create') {
const data = executeFunctions.getNodeParameter('data', itemIndex);
const payload = { function_call: { data } };
const response = await executeFunctions.helpers.httpRequest({
method: 'POST',
url: `${adminUrl}/function_calls.json`,
body: payload,
headers,
});
return response;
}
else if (operation === 'update') {
let functionCallId = executeFunctions.getNodeParameter('functionCallId', itemIndex);
functionCallId = (0, utils_1.extractIdFromUrlOrId)(functionCallId, 'function_calls');
const data = executeFunctions.getNodeParameter('data', itemIndex);
const payload = { function_call: { data } };
const response = await executeFunctions.helpers.httpRequest({
method: 'PATCH',
url: `${adminUrl}/function_calls/${functionCallId}.json`,
body: payload,
headers,
});
return response;
}
else if (operation === 'delete') {
let functionCallId = executeFunctions.getNodeParameter('functionCallId', itemIndex);
functionCallId = (0, utils_1.extractIdFromUrlOrId)(functionCallId, 'function_calls');
const response = await executeFunctions.helpers.httpRequest({
method: 'DELETE',
url: `${adminUrl}/function_calls/${functionCallId}.json`,
headers,
});
return { success: true, deletedId: functionCallId };
}
throw new n8n_workflow_1.NodeOperationError(executeFunctions.getNode(), `Unknown function calls operation: ${operation}`);
}
//# sourceMappingURL=functionCallsApi.js.map