@kaia-team/n8n-nodes-kaia
Version:
n8n nodes for Kaia LLM integration
160 lines • 5.18 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.summaryConfigApiProperties = void 0;
exports.handleSummaryConfigApi = handleSummaryConfigApi;
const n8n_workflow_1 = require("n8n-workflow");
const utils_1 = require("../utils");
/**
* Summary Config API Properties
* Properties specific to the summaryConfig API resource
*
* TODO: Test the update operation properties - some properties (history_insight_prompt,
* user_insight_prompt, daily_analytics_prompt, content_summary_prompt) were added based
* on handler usage but haven't been integration tested yet.
*/
exports.summaryConfigApiProperties = [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
resource: ['summaryConfig'],
},
},
options: [
{
name: 'Read',
value: 'read',
action: 'Read summary config',
},
{
name: 'Update',
value: 'update',
action: 'Update summary config',
},
],
default: 'read',
},
{
displayName: 'Delay',
name: 'delay',
type: 'number',
default: 0,
displayOptions: {
show: {
resource: ['summaryConfig'],
operation: ['update'],
},
},
},
{
displayName: 'Model',
name: 'model',
type: 'string',
default: '',
displayOptions: {
show: {
resource: ['summaryConfig'],
operation: ['update'],
},
},
},
// TODO: These properties were added based on handler usage but haven't been integration tested
{
displayName: 'History Insight Prompt',
name: 'history_insight_prompt',
type: 'string',
default: '',
displayOptions: {
show: {
resource: ['summaryConfig'],
operation: ['update'],
},
},
description: 'Prompt for history insights',
},
{
displayName: 'User Insight Prompt',
name: 'user_insight_prompt',
type: 'string',
default: '',
displayOptions: {
show: {
resource: ['summaryConfig'],
operation: ['update'],
},
},
description: 'Prompt for user insights',
},
{
displayName: 'Daily Analytics Prompt',
name: 'daily_analytics_prompt',
type: 'string',
default: '',
displayOptions: {
show: {
resource: ['summaryConfig'],
operation: ['update'],
},
},
description: 'Prompt for daily analytics',
},
{
displayName: 'Content Summary Prompt',
name: 'content_summary_prompt',
type: 'string',
default: '',
displayOptions: {
show: {
resource: ['summaryConfig'],
operation: ['update'],
},
},
description: 'Prompt for content summaries',
},
];
/**
* Summary Config API Handler
* Handles requests to the summaryConfig API
*
* TODO: Test the update operation with all the new prompt properties
*/
async function handleSummaryConfigApi(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 === 'read') {
const response = await executeFunctions.helpers.httpRequest({
method: 'GET',
url: `${adminUrl}/summary_config.json`,
headers,
});
return response;
}
else if (operation === 'update') {
const payload = { summary_config: {} };
const addIfSet = (key, param, defaultVal = '') => {
const val = executeFunctions.getNodeParameter(param, itemIndex, defaultVal);
if (val !== defaultVal && (typeof val !== 'string' || val.trim() !== '')) {
payload.summary_config[key] = val;
}
};
addIfSet('delay', 'delay', 0);
addIfSet('model', 'model');
addIfSet('history_insight_prompt', 'history_insight_prompt');
addIfSet('user_insight_prompt', 'user_insight_prompt');
addIfSet('daily_analytics_prompt', 'daily_analytics_prompt');
addIfSet('content_summary_prompt', 'content_summary_prompt');
const response = await executeFunctions.helpers.httpRequest({
method: 'PATCH',
url: `${adminUrl}/summary_config.json`,
body: payload,
headers,
});
return response;
}
throw new n8n_workflow_1.NodeOperationError(executeFunctions.getNode(), `Unknown summary config operation: ${operation}`);
}
//# sourceMappingURL=summaryConfigApi.js.map