@kaia-team/n8n-nodes-kaia
Version:
n8n nodes for Kaia LLM integration
300 lines • 13.7 kB
JavaScript
;
/**
* Kaia Node - Modular Version
*
* This is the modular version of the Kaia node that uses separate API modules.
*
* IMPORTANT: This file demonstrates the modular structure. To complete the migration:
* 1. Extract all API properties and handlers to separate modules in the apis/ directory
* 2. Import them here and concatenate the properties arrays
* 3. Replace the original Kaia.node.ts with this modular version
*
* DO NOT add new APIs directly to this file - always create separate modules!
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.Kaia = void 0;
// Import API modules
const apis_1 = require("./apis");
class Kaia {
constructor() {
this.description = {
displayName: 'Kaia',
name: 'kaia',
icon: 'file:kaia.svg',
group: ['transform'],
version: 1,
description: 'Interact with Kaia LLM platform APIs',
defaults: {
name: 'Kaia',
},
inputs: ["main" /* NodeConnectionType.Main */],
outputs: ["main" /* NodeConnectionType.Main */],
credentials: [
{
name: 'kaiaApi',
required: true,
},
],
codex: {
categories: ['AI & ML'],
subcategories: {
'AI & ML': ['LLM', 'Chatbot'],
},
resources: {
primaryDocumentation: [
{
url: 'https://docs.kaia.team',
},
],
},
},
properties: [
// Base resource selector
{
displayName: 'Resource',
name: 'resource',
type: 'options',
noDataExpression: true,
options: [
{
name: 'Admin API',
value: 'admin',
description: 'Interact with the admin instance API',
},
{
name: 'Admin Token',
value: 'adminTokens',
description: 'Manage admin tokens',
},
{
name: 'Answer Rating',
value: 'answerRatings',
description: 'Manage answer ratings',
},
{
name: 'Answer Reporting',
value: 'answerReportings',
description: 'Manage answer reportings',
},
{
name: 'API Config',
value: 'apiConfigs',
description: 'Manage incoming webhooks (API configs)',
},
{
name: 'Assistant',
value: 'assistants',
description: 'Manage assistants',
},
{
name: 'Chat History',
value: 'chatHistories',
description: 'Manage chat histories',
},
{
name: 'Content',
value: 'contents',
description: 'Manage contents (news tiles)',
},
{
name: 'Crawl',
value: 'crawls',
description: 'Manage websites (crawls)',
},
{
name: 'CSV',
value: 'documentImports',
description: 'Manage CSV document imports',
},
{
name: 'Document',
value: 'documents',
description: 'Manage documents',
},
{
name: 'Document Shard',
value: 'documentShards',
description: 'Manage document shards',
},
{
name: 'Feed',
value: 'feeds',
},
{
name: 'Function Call',
value: 'functionCalls',
description: 'Manage function calls',
},
{
name: 'Headless Widget API',
value: 'widget',
description: 'Interact with the headless widget API',
},
{
name: 'Link Package',
value: 'linkPackages',
description: 'Manage link packages',
},
{
name: 'Shop',
value: 'shop',
description: 'Manage redeem codes',
},
{
name: 'Statistic',
value: 'statistics',
description: 'Get statistics',
},
{
name: 'Summary Config',
value: 'summaryConfig',
description: 'Manage summary configuration',
},
{
name: 'System Webhook',
value: 'systemWebhook',
description: 'Manage system webhooks',
},
{
name: 'User Account',
value: 'userAccounts',
description: 'Manage user accounts',
},
{
name: 'User File',
value: 'userFiles',
description: 'Manage user files',
},
{
name: 'Vec DB',
value: 'vecDbs',
description: 'Manage vector databases',
},
{
name: 'Widget',
value: 'widgets',
description: 'Manage widgets',
},
],
default: 'admin',
},
// Concatenate all API properties
...apis_1.adminApiProperties,
// TODO: Add other API properties as they are extracted
// ...widgetApiProperties,
// ...systemWebhookProperties,
// ...widgetsApiProperties,
// ...assistantsApiProperties,
// ...statisticsApiProperties,
// ...chatHistoriesApiProperties,
// ...userAccountsApiProperties,
// ...functionCallsApiProperties,
// ...answerRatingsApiProperties,
// ...answerReportingsApiProperties,
// ...summaryConfigApiProperties,
// ...userFilesApiProperties,
// ...apiConfigsApiProperties,
// ...documentsApiProperties,
// ...documentImportsApiProperties,
// ...adminTokensApiProperties,
// ...vecDbsApiProperties,
// ...documentShardsApiProperties,
// ...crawlsApiProperties,
// ...feedsApiProperties,
// ...contentsApiProperties,
// ...linkPackagesApiProperties,
// ...shopApiProperties,
// Shared properties
apis_1.additionalFieldsProperty,
apis_1.bodyProperty,
],
};
}
async execute() {
const items = this.getInputData();
const returnData = [];
const credentials = await this.getCredentials('kaiaApi');
const adminUrl = credentials.adminUrl;
const adminToken = credentials.adminToken;
const clientId = credentials.clientId;
for (let i = 0; i < items.length; i++) {
try {
const resource = this.getNodeParameter('resource', i);
let response;
// Route to appropriate API handler
if (resource === 'admin') {
response = await (0, apis_1.handleAdminApi)(this, i, adminUrl, adminToken);
}
// TODO: Add other API handlers as they are extracted
// else if (resource === 'widget') {
// response = await handleWidgetApi(this, i, adminUrl, adminToken, clientId);
// } else if (resource === 'systemWebhook') {
// response = await handleSystemWebhook(this, i, adminUrl, adminToken);
// } else if (resource === 'widgets') {
// response = await handleWidgetsApi(this, i, adminUrl, adminToken);
// } else if (resource === 'assistants') {
// response = await handleAssistantsApi(this, i, adminUrl, adminToken);
// } else if (resource === 'statistics') {
// response = await handleStatisticsApi(this, i, adminUrl, adminToken);
// } else if (resource === 'chatHistories') {
// response = await handleChatHistoriesApi(this, i, adminUrl, adminToken);
// } else if (resource === 'userAccounts') {
// response = await handleUserAccountsApi(this, i, adminUrl, adminToken);
// } else if (resource === 'functionCalls') {
// response = await handleFunctionCallsApi(this, i, adminUrl, adminToken);
// } else if (resource === 'answerRatings') {
// response = await handleAnswerRatingsApi(this, i, adminUrl, adminToken);
// } else if (resource === 'answerReportings') {
// response = await handleAnswerReportingsApi(this, i, adminUrl, adminToken);
// } else if (resource === 'summaryConfig') {
// response = await handleSummaryConfigApi(this, i, adminUrl, adminToken);
// } else if (resource === 'userFiles') {
// response = await handleUserFilesApi(this, i, adminUrl, adminToken);
// } else if (resource === 'apiConfigs') {
// response = await handleApiConfigsApi(this, i, adminUrl, adminToken);
// } else if (resource === 'documents') {
// response = await handleDocumentsApi(this, i, adminUrl, adminToken);
// } else if (resource === 'documentImports') {
// response = await handleDocumentImportsApi(this, i, adminUrl, adminToken);
// } else if (resource === 'adminTokens') {
// response = await handleAdminTokensApi(this, i, adminUrl, adminToken);
// } else if (resource === 'vecDbs') {
// response = await handleVecDbsApi(this, i, adminUrl, adminToken);
// } else if (resource === 'documentShards') {
// response = await handleDocumentShardsApi(this, i, adminUrl, adminToken);
// } else if (resource === 'crawls') {
// response = await handleCrawlsApi(this, i, adminUrl, adminToken);
// } else if (resource === 'feeds') {
// response = await handleFeedsApi(this, i, adminUrl, adminToken);
// } else if (resource === 'contents') {
// response = await handleContentsApi(this, i, adminUrl, adminToken);
// } else if (resource === 'linkPackages') {
// response = await handleLinkPackagesApi(this, i, adminUrl, adminToken);
// } else if (resource === 'shop') {
// response = await handleShopApi(this, i, adminUrl, adminToken);
// }
if (response) {
// Handle both single objects and arrays of execution data
if (Array.isArray(response)) {
// If response is already an array of INodeExecutionData, spread it
returnData.push(...response);
}
else {
// If response is a single object, wrap it in INodeExecutionData
returnData.push({ json: response });
}
}
}
catch (error) {
if (this.continueOnFail()) {
returnData.push({ json: { error: error.message } });
continue;
}
throw error;
}
}
return [returnData];
}
}
exports.Kaia = Kaia;
//# sourceMappingURL=Kaia.node.modular.js.map