@izzai/n8n-nodes-izzone
Version:
n8n custom node for izz.ONE
195 lines (194 loc) • 7.44 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.IzzOne = void 0;
const constants_1 = require("../constants");
const utils_1 = require("../utils");
class IzzOne {
description = {
displayName: 'izz.ONE',
name: 'izzOne',
icon: 'file:izz-one.png',
group: ['input'],
version: 1,
description: 'Fetch data from izz.ONE',
defaults: {
name: 'izz.ONE',
color: '#FF08FF', // TODO: Change color to match izz.ONE branding
},
inputs: ["main" /* NodeConnectionType.Main */],
outputs: ["main" /* NodeConnectionType.Main */],
credentials: [
{
name: 'IzzOneApi',
required: true,
},
],
properties: [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
options: [
{
name: 'Send a message',
value: 'sendMessage',
description: 'Send a message to a izz.ONE as chat',
},
{
name: 'Continue a chat',
value: 'continueChat',
description: 'Continue an existing chat with a message',
},
],
default: 'sendMessage',
description: 'The operation to perform',
},
{
displayName: 'Chat ID',
name: 'id',
type: 'string',
required: true,
default: '',
displayOptions: {
show: {
operation: ['continueChat'],
},
},
placeholder: 'Enter the chat ID (optional)',
description: 'The unique identifier for the chat. If not provided, a new chat will be created.',
},
{
displayName: 'Message',
name: 'msg',
type: 'string',
required: true,
default: '',
placeholder: 'Enter your message',
},
{
displayName: 'Datasources',
name: 'datasources',
type: 'multiOptions',
options: [],
required: false,
typeOptions: {
loadOptionsMethod: 'getDatasources',
},
default: ['auto'],
description: 'Select a datasource to use for the chat. If not selected, automatic datasource selection will be made. Mixing automatic with other datasources will defaults to automatic.',
},
{
displayName: 'Agent',
name: 'agent',
type: 'options',
options: [],
required: false,
typeOptions: {
loadOptionsMethod: 'getAgents',
},
default: '',
description: 'Select an agent to use for the chat. If not selected, no agent will be used.',
},
{
displayName: 'LLM Model',
name: 'llm',
type: 'options',
options: [],
required: false,
typeOptions: {
loadOptionsMethod: 'getLlms',
},
default: '',
description: 'Select a specific LLM model to use for the chat. If not selected, automatic model selection will be made.',
},
{
displayName: 'System Message',
name: 'systemMessage',
type: 'string',
required: false,
default: '',
placeholder: 'Enter a custom system message (optional)',
},
{
displayName: 'LLM Behavior',
name: 'behavior',
type: 'multiOptions',
default: [
constants_1.LlmBehaviorEnum.CONVERSATIONAL,
constants_1.LlmBehaviorEnum.FRIENDLY,
constants_1.LlmBehaviorEnum.INFORMAL,
constants_1.LlmBehaviorEnum.CREATIVE,
],
options: constants_1.LlmBehavior,
},
{
displayName: 'Tags',
name: 'tags',
type: 'string',
required: false,
default: '',
placeholder: 'Enter tags (comma-separated)',
description: 'Optional tags to categorize the message. Enter tags as a comma-separated list.',
},
{
// ! Might not work in local n8n
displayName: 'Streaming',
name: 'streaming',
type: 'boolean',
default: false,
description: 'If enabled, the response will be streamed back in real-time. Otherwise, the full response will be returned at once.',
},
],
};
methods = {
loadOptions: {
getAgents: utils_1.getAgents,
getDatasources: utils_1.getDatasources,
getLlms: utils_1.getLlms,
},
};
async execute() {
let responseData;
const operation = this.getNodeParameter('operation', 0);
const credentials = await this.getCredentials('IzzOneApi');
if (['sendMessage', 'continueChat'].includes(operation)) {
const msg = this.getNodeParameter('msg', 0);
const id = operation === 'continueChat'
? this.getNodeParameter('id', 0)
: undefined;
const datasources = this.getNodeParameter('datasources', 0);
const agent = this.getNodeParameter('agent', 0);
const llm = this.getNodeParameter('llm', 0);
const systemMessage = this.getNodeParameter('systemMessage', 0);
const behavior = this.getNodeParameter('behavior', 0);
const tags = this.getNodeParameter('tags', 0)
.split(',')
.map((v) => v.trim())
.filter(Boolean);
const streaming = this.getNodeParameter('streaming', 0);
const requestBody = {
msg,
...(id && { id: id.trim() }),
...(datasources && { datasources }),
...(agent && { agent }),
...(llm && { llm }),
...(systemMessage && { systemMessage: systemMessage.trim() }),
behavior,
tags,
};
const requestOptions = {
headers: (0, utils_1.getHeaders)(credentials),
method: 'POST',
body: requestBody,
url: new URL(
// /v1/chat or /v1/chat/stream
['/v1/chat', streaming && 'stream'].filter(Boolean).join('/'), (credentials.baseUrl || constants_1.BASE_URL)).href,
json: true,
};
responseData = await this.helpers.httpRequest(requestOptions);
}
// Map data to n8n data
return [this.helpers.returnJsonArray(responseData)];
}
}
exports.IzzOne = IzzOne;