@exado/n8n-nodes-exado 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +132 -0
  3. package/dist/credentials/ExadoApi.credentials.d.ts +9 -0
  4. package/dist/credentials/ExadoApi.credentials.js +48 -0
  5. package/dist/credentials/ExadoApi.credentials.js.map +1 -0
  6. package/dist/index.d.ts +1 -0
  7. package/dist/index.js +3 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/nodes/Exado/Exado.node.d.ts +17 -0
  10. package/dist/nodes/Exado/Exado.node.js +709 -0
  11. package/dist/nodes/Exado/Exado.node.js.map +1 -0
  12. package/dist/nodes/Exado/ExadoTrigger.node.d.ts +5 -0
  13. package/dist/nodes/Exado/ExadoTrigger.node.js +123 -0
  14. package/dist/nodes/Exado/ExadoTrigger.node.js.map +1 -0
  15. package/dist/nodes/Exado/descriptions/ChatCompletionDescription.d.ts +3 -0
  16. package/dist/nodes/Exado/descriptions/ChatCompletionDescription.js +181 -0
  17. package/dist/nodes/Exado/descriptions/ChatCompletionDescription.js.map +1 -0
  18. package/dist/nodes/Exado/descriptions/ChatDescription.d.ts +3 -0
  19. package/dist/nodes/Exado/descriptions/ChatDescription.js +78 -0
  20. package/dist/nodes/Exado/descriptions/ChatDescription.js.map +1 -0
  21. package/dist/nodes/Exado/descriptions/ConversationConfigDescription.d.ts +3 -0
  22. package/dist/nodes/Exado/descriptions/ConversationConfigDescription.js +115 -0
  23. package/dist/nodes/Exado/descriptions/ConversationConfigDescription.js.map +1 -0
  24. package/dist/nodes/Exado/descriptions/ConversationDescription.d.ts +3 -0
  25. package/dist/nodes/Exado/descriptions/ConversationDescription.js +102 -0
  26. package/dist/nodes/Exado/descriptions/ConversationDescription.js.map +1 -0
  27. package/dist/nodes/Exado/descriptions/ConversationTemplateDescription.d.ts +3 -0
  28. package/dist/nodes/Exado/descriptions/ConversationTemplateDescription.js +97 -0
  29. package/dist/nodes/Exado/descriptions/ConversationTemplateDescription.js.map +1 -0
  30. package/dist/nodes/Exado/descriptions/DocumentDescription.d.ts +3 -0
  31. package/dist/nodes/Exado/descriptions/DocumentDescription.js +221 -0
  32. package/dist/nodes/Exado/descriptions/DocumentDescription.js.map +1 -0
  33. package/dist/nodes/Exado/descriptions/EmbeddingDescription.d.ts +3 -0
  34. package/dist/nodes/Exado/descriptions/EmbeddingDescription.js +56 -0
  35. package/dist/nodes/Exado/descriptions/EmbeddingDescription.js.map +1 -0
  36. package/dist/nodes/Exado/descriptions/FaqTopicDescription.d.ts +3 -0
  37. package/dist/nodes/Exado/descriptions/FaqTopicDescription.js +89 -0
  38. package/dist/nodes/Exado/descriptions/FaqTopicDescription.js.map +1 -0
  39. package/dist/nodes/Exado/descriptions/FolderDescription.d.ts +3 -0
  40. package/dist/nodes/Exado/descriptions/FolderDescription.js +81 -0
  41. package/dist/nodes/Exado/descriptions/FolderDescription.js.map +1 -0
  42. package/dist/nodes/Exado/descriptions/GroupDescription.d.ts +3 -0
  43. package/dist/nodes/Exado/descriptions/GroupDescription.js +29 -0
  44. package/dist/nodes/Exado/descriptions/GroupDescription.js.map +1 -0
  45. package/dist/nodes/Exado/descriptions/MetadataDescription.d.ts +3 -0
  46. package/dist/nodes/Exado/descriptions/MetadataDescription.js +116 -0
  47. package/dist/nodes/Exado/descriptions/MetadataDescription.js.map +1 -0
  48. package/dist/nodes/Exado/descriptions/ModelDescription.d.ts +3 -0
  49. package/dist/nodes/Exado/descriptions/ModelDescription.js +30 -0
  50. package/dist/nodes/Exado/descriptions/ModelDescription.js.map +1 -0
  51. package/dist/nodes/Exado/descriptions/QuickDescription.d.ts +3 -0
  52. package/dist/nodes/Exado/descriptions/QuickDescription.js +35 -0
  53. package/dist/nodes/Exado/descriptions/QuickDescription.js.map +1 -0
  54. package/dist/nodes/Exado/exado.svg +4 -0
  55. package/dist/nodes/Exado/helpers/pagination.d.ts +4 -0
  56. package/dist/nodes/Exado/helpers/pagination.js +33 -0
  57. package/dist/nodes/Exado/helpers/pagination.js.map +1 -0
  58. package/dist/nodes/Exado/helpers/request.d.ts +15 -0
  59. package/dist/nodes/Exado/helpers/request.js +101 -0
  60. package/dist/nodes/Exado/helpers/request.js.map +1 -0
  61. package/dist/nodes/Exado/helpers/sse.d.ts +12 -0
  62. package/dist/nodes/Exado/helpers/sse.js +87 -0
  63. package/dist/nodes/Exado/helpers/sse.js.map +1 -0
  64. package/dist/nodes/Exado/helpers/upload.d.ts +2 -0
  65. package/dist/nodes/Exado/helpers/upload.js +24 -0
  66. package/dist/nodes/Exado/helpers/upload.js.map +1 -0
  67. package/dist/nodes/Exado/methods/loadOptions.d.ts +8 -0
  68. package/dist/nodes/Exado/methods/loadOptions.js +95 -0
  69. package/dist/nodes/Exado/methods/loadOptions.js.map +1 -0
  70. package/dist/tsconfig.tsbuildinfo +1 -0
  71. package/package.json +66 -0
@@ -0,0 +1,709 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Exado = void 0;
4
+ const n8n_workflow_1 = require("n8n-workflow");
5
+ const ChatCompletionDescription_1 = require("./descriptions/ChatCompletionDescription");
6
+ const ChatDescription_1 = require("./descriptions/ChatDescription");
7
+ const ConversationConfigDescription_1 = require("./descriptions/ConversationConfigDescription");
8
+ const ConversationDescription_1 = require("./descriptions/ConversationDescription");
9
+ const ConversationTemplateDescription_1 = require("./descriptions/ConversationTemplateDescription");
10
+ const DocumentDescription_1 = require("./descriptions/DocumentDescription");
11
+ const EmbeddingDescription_1 = require("./descriptions/EmbeddingDescription");
12
+ const FaqTopicDescription_1 = require("./descriptions/FaqTopicDescription");
13
+ const FolderDescription_1 = require("./descriptions/FolderDescription");
14
+ const GroupDescription_1 = require("./descriptions/GroupDescription");
15
+ const MetadataDescription_1 = require("./descriptions/MetadataDescription");
16
+ const ModelDescription_1 = require("./descriptions/ModelDescription");
17
+ const QuickDescription_1 = require("./descriptions/QuickDescription");
18
+ const request_1 = require("./helpers/request");
19
+ const pagination_1 = require("./helpers/pagination");
20
+ const sse_1 = require("./helpers/sse");
21
+ const upload_1 = require("./helpers/upload");
22
+ const loadOptions_1 = require("./methods/loadOptions");
23
+ class Exado {
24
+ constructor() {
25
+ this.description = {
26
+ displayName: 'Exado',
27
+ name: 'exado',
28
+ icon: 'file:exado.svg',
29
+ group: ['transform'],
30
+ version: 1,
31
+ subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
32
+ description: 'Interact with the Exado AI API: RAG chat, OpenAI-compatible completions/embeddings, documents, conversations, FAQ.',
33
+ defaults: { name: 'Exado' },
34
+ inputs: ['main'],
35
+ outputs: ['main'],
36
+ credentials: [{ name: 'exadoApi', required: true }],
37
+ properties: [
38
+ {
39
+ displayName: 'Resource',
40
+ name: 'resource',
41
+ type: 'options',
42
+ noDataExpression: true,
43
+ options: [
44
+ { name: 'Chat', value: 'chat' },
45
+ { name: 'Chat Completion', value: 'chatCompletion' },
46
+ { name: 'Conversation', value: 'conversation' },
47
+ { name: 'Conversation Config', value: 'conversationConfig' },
48
+ { name: 'Conversation Template', value: 'conversationTemplate' },
49
+ { name: 'Document', value: 'document' },
50
+ { name: 'Embedding', value: 'embedding' },
51
+ { name: 'FAQ Topic', value: 'faqTopic' },
52
+ { name: 'Folder', value: 'folder' },
53
+ { name: 'Group', value: 'group' },
54
+ { name: 'Metadata', value: 'metadata' },
55
+ { name: 'Model', value: 'model' },
56
+ { name: 'Quick', value: 'quick' },
57
+ ],
58
+ default: 'chat',
59
+ },
60
+ ...ChatDescription_1.chatOperations,
61
+ ...ChatDescription_1.chatFields,
62
+ ...ChatCompletionDescription_1.chatCompletionOperations,
63
+ ...ChatCompletionDescription_1.chatCompletionFields,
64
+ ...EmbeddingDescription_1.embeddingOperations,
65
+ ...EmbeddingDescription_1.embeddingFields,
66
+ ...ModelDescription_1.modelOperations,
67
+ ...ModelDescription_1.modelFields,
68
+ ...DocumentDescription_1.documentOperations,
69
+ ...DocumentDescription_1.documentFields,
70
+ ...ConversationDescription_1.conversationOperations,
71
+ ...ConversationDescription_1.conversationFields,
72
+ ...ConversationConfigDescription_1.conversationConfigOperations,
73
+ ...ConversationConfigDescription_1.conversationConfigFields,
74
+ ...ConversationTemplateDescription_1.conversationTemplateOperations,
75
+ ...ConversationTemplateDescription_1.conversationTemplateFields,
76
+ ...MetadataDescription_1.metadataOperations,
77
+ ...MetadataDescription_1.metadataFields,
78
+ ...FolderDescription_1.folderOperations,
79
+ ...FolderDescription_1.folderFields,
80
+ ...GroupDescription_1.groupOperations,
81
+ ...GroupDescription_1.groupFields,
82
+ ...FaqTopicDescription_1.faqTopicOperations,
83
+ ...FaqTopicDescription_1.faqTopicFields,
84
+ ...QuickDescription_1.quickOperations,
85
+ ...QuickDescription_1.quickFields,
86
+ ],
87
+ };
88
+ this.methods = {
89
+ loadOptions: {
90
+ getModels: loadOptions_1.getModels,
91
+ getOpenAiModels: loadOptions_1.getOpenAiModels,
92
+ getGroups: loadOptions_1.getGroups,
93
+ getConversationConfigs: loadOptions_1.getConversationConfigs,
94
+ getMetadatas: loadOptions_1.getMetadatas,
95
+ getDocuments: loadOptions_1.getDocuments,
96
+ getFolders: loadOptions_1.getFolders,
97
+ },
98
+ };
99
+ }
100
+ async execute() {
101
+ const items = this.getInputData();
102
+ const returnData = [];
103
+ for (let i = 0; i < items.length; i++) {
104
+ const resource = this.getNodeParameter('resource', i);
105
+ const operation = this.getNodeParameter('operation', i);
106
+ try {
107
+ const handlerOutput = await dispatch.call(this, resource, operation, i);
108
+ returnData.push(...handlerOutput);
109
+ }
110
+ catch (error) {
111
+ if (this.continueOnFail()) {
112
+ returnData.push({
113
+ json: { error: error.message },
114
+ pairedItem: { item: i },
115
+ });
116
+ continue;
117
+ }
118
+ if (error instanceof n8n_workflow_1.NodeApiError || error instanceof n8n_workflow_1.NodeOperationError)
119
+ throw error;
120
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), error, { itemIndex: i });
121
+ }
122
+ }
123
+ return [returnData];
124
+ }
125
+ }
126
+ exports.Exado = Exado;
127
+ async function dispatch(resource, operation, itemIndex) {
128
+ switch (resource) {
129
+ case 'chat':
130
+ return chatHandler.call(this, operation, itemIndex);
131
+ case 'chatCompletion':
132
+ return chatCompletionHandler.call(this, operation, itemIndex);
133
+ case 'embedding':
134
+ return embeddingHandler.call(this, operation, itemIndex);
135
+ case 'model':
136
+ return modelHandler.call(this, operation, itemIndex);
137
+ case 'document':
138
+ return documentHandler.call(this, operation, itemIndex);
139
+ case 'conversation':
140
+ return conversationHandler.call(this, operation, itemIndex);
141
+ case 'conversationConfig':
142
+ return conversationConfigHandler.call(this, operation, itemIndex);
143
+ case 'conversationTemplate':
144
+ return conversationTemplateHandler.call(this, operation, itemIndex);
145
+ case 'metadata':
146
+ return metadataHandler.call(this, operation, itemIndex);
147
+ case 'folder':
148
+ return folderHandler.call(this, operation, itemIndex);
149
+ case 'group':
150
+ return groupHandler.call(this, operation, itemIndex);
151
+ case 'faqTopic':
152
+ return faqTopicHandler.call(this, operation, itemIndex);
153
+ case 'quick':
154
+ return quickHandler.call(this, operation, itemIndex);
155
+ default:
156
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Unknown resource "${resource}"`, { itemIndex });
157
+ }
158
+ }
159
+ function wrap(itemIndex, json) {
160
+ return { json, pairedItem: { item: itemIndex } };
161
+ }
162
+ async function chatHandler(operation, i) {
163
+ if (operation !== 'sendMessage') {
164
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Unknown chat operation: ${operation}`, {
165
+ itemIndex: i,
166
+ });
167
+ }
168
+ const prompt = this.getNodeParameter('prompt', i);
169
+ const model = this.getNodeParameter('model', i, '');
170
+ const systemPrompt = this.getNodeParameter('systemPrompt', i, '');
171
+ const context = this.getNodeParameter('context', i, '');
172
+ const stream = this.getNodeParameter('stream', i, false);
173
+ const body = { prompt };
174
+ if (model)
175
+ body.model = model;
176
+ if (systemPrompt)
177
+ body.system_prompt = systemPrompt;
178
+ if (context)
179
+ body.context = context;
180
+ body.stream = stream;
181
+ if (!stream) {
182
+ const response = (await request_1.exadoApiRequest.call(this, 'POST', '/public/chat', {
183
+ body,
184
+ }));
185
+ return [wrap(i, response)];
186
+ }
187
+ const emitEachChunk = this.getNodeParameter('emitEachChunk', i, false);
188
+ return await runStreaming.call(this, 'POST', '/public/chat', body, i, {
189
+ parseJson: false,
190
+ emitEachChunk,
191
+ });
192
+ }
193
+ async function chatCompletionHandler(operation, i) {
194
+ const model = this.getNodeParameter('model', i);
195
+ const stream = this.getNodeParameter('stream', i, false);
196
+ const additional = this.getNodeParameter('additionalOptions', i, {});
197
+ const body = { model, stream };
198
+ if (additional.temperature !== undefined)
199
+ body.temperature = additional.temperature;
200
+ if (additional.top_p !== undefined)
201
+ body.top_p = additional.top_p;
202
+ if (additional.max_tokens !== undefined)
203
+ body.max_tokens = additional.max_tokens;
204
+ if (additional.seed !== undefined)
205
+ body.seed = additional.seed;
206
+ if (additional.presence_penalty !== undefined)
207
+ body.presence_penalty = additional.presence_penalty;
208
+ if (additional.frequency_penalty !== undefined)
209
+ body.frequency_penalty = additional.frequency_penalty;
210
+ if (typeof additional.stop === 'string' && additional.stop) {
211
+ body.stop = additional.stop.split(',').map((s) => s.trim()).filter(Boolean);
212
+ }
213
+ if (stream && additional.include_usage) {
214
+ body.stream_options = { include_usage: true };
215
+ }
216
+ let endpoint;
217
+ if (operation === 'createChatCompletion') {
218
+ endpoint = '/public/openai/v1/chat/completions';
219
+ const messagesParam = this.getNodeParameter('messages.values', i, []);
220
+ body.messages = messagesParam.map((m) => ({ role: m.role, content: m.content }));
221
+ }
222
+ else if (operation === 'createCompletion') {
223
+ endpoint = '/public/openai/v1/completions';
224
+ body.prompt = this.getNodeParameter('prompt', i);
225
+ }
226
+ else {
227
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Unknown chatCompletion operation: ${operation}`, { itemIndex: i });
228
+ }
229
+ if (!stream) {
230
+ const response = (await request_1.exadoApiRequest.call(this, 'POST', endpoint, {
231
+ body,
232
+ }));
233
+ return [wrap(i, response)];
234
+ }
235
+ const emitEachChunk = this.getNodeParameter('emitEachChunk', i, false);
236
+ return await runStreaming.call(this, 'POST', endpoint, body, i, {
237
+ parseJson: true,
238
+ emitEachChunk,
239
+ });
240
+ }
241
+ async function embeddingHandler(operation, i) {
242
+ if (operation !== 'create') {
243
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Unknown embedding operation: ${operation}`, {
244
+ itemIndex: i,
245
+ });
246
+ }
247
+ const inputRaw = this.getNodeParameter('input', i);
248
+ const model = this.getNodeParameter('model', i);
249
+ const encodingFormat = this.getNodeParameter('encoding_format', i, 'float');
250
+ const lines = inputRaw.split('\n').map((l) => l.trim()).filter(Boolean);
251
+ const input = lines.length > 1 ? lines : inputRaw;
252
+ const response = (await request_1.exadoApiRequest.call(this, 'POST', '/public/openai/v1/embeddings', {
253
+ body: { input, model, encoding_format: encodingFormat },
254
+ }));
255
+ return [wrap(i, response)];
256
+ }
257
+ async function modelHandler(operation, i) {
258
+ if (operation === 'listAvailable') {
259
+ const response = (await request_1.exadoApiRequest.call(this, 'GET', '/system/available-models'));
260
+ return [wrap(i, response)];
261
+ }
262
+ if (operation === 'listOpenAiCompatible') {
263
+ const response = (await request_1.exadoApiRequest.call(this, 'GET', '/public/openai/v1/models'));
264
+ return [wrap(i, response)];
265
+ }
266
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Unknown model operation: ${operation}`, {
267
+ itemIndex: i,
268
+ });
269
+ }
270
+ async function documentHandler(operation, i) {
271
+ switch (operation) {
272
+ case 'uploadAsync':
273
+ case 'uploadSync': {
274
+ const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i, 'data');
275
+ const options = this.getNodeParameter('options', i, {});
276
+ const extra = {};
277
+ if (options.path)
278
+ extra.path = options.path;
279
+ if (options.mode)
280
+ extra.mode = options.mode;
281
+ if (options.metadata !== undefined)
282
+ extra.metadata = options.metadata;
283
+ const formData = await upload_1.buildUploadFormData.call(this, i, binaryPropertyName, extra);
284
+ const endpoint = operation === 'uploadAsync' ? '/documents/a-upload' : '/documents/upload';
285
+ const response = (await request_1.exadoApiRequest.call(this, 'POST', endpoint, {
286
+ formData,
287
+ }));
288
+ return [wrap(i, response)];
289
+ }
290
+ case 'get': {
291
+ const documentId = this.getNodeParameter('documentId', i);
292
+ const response = (await request_1.exadoApiRequest.call(this, 'GET', `/documents/${documentId}`));
293
+ return [wrap(i, response)];
294
+ }
295
+ case 'getContent': {
296
+ const documentId = this.getNodeParameter('documentId', i);
297
+ const response = (await request_1.exadoApiRequest.call(this, 'GET', `/documents/${documentId}/content`));
298
+ return [wrap(i, response)];
299
+ }
300
+ case 'getStatus': {
301
+ const documentId = this.getNodeParameter('documentId', i);
302
+ const response = (await request_1.exadoApiRequest.call(this, 'GET', `/documents/${documentId}/status`));
303
+ return [wrap(i, response)];
304
+ }
305
+ case 'getAll': {
306
+ const returnAll = this.getNodeParameter('returnAll', i, false);
307
+ const filters = this.getNodeParameter('filters', i, {});
308
+ const qs = {};
309
+ if (filters.search)
310
+ qs.search = filters.search;
311
+ if (filters.path)
312
+ qs.path = filters.path;
313
+ const limit = returnAll ? undefined : this.getNodeParameter('limit', i, 50);
314
+ const docs = await pagination_1.exadoApiRequestAllItems.call(this, 'GET', '/documents', 'documents', qs, limit);
315
+ return docs.map((d) => wrap(i, d));
316
+ }
317
+ case 'update': {
318
+ const documentId = this.getNodeParameter('documentId', i);
319
+ const updateFields = this.getNodeParameter('updateFields', i, {});
320
+ const response = (await request_1.exadoApiRequest.call(this, 'PUT', `/documents/${documentId}`, {
321
+ body: updateFields,
322
+ }));
323
+ return [wrap(i, response)];
324
+ }
325
+ case 'delete': {
326
+ const documentId = this.getNodeParameter('documentId', i);
327
+ const recursive = this.getNodeParameter('recursive', i, false);
328
+ const response = (await request_1.exadoApiRequest.call(this, 'DELETE', `/documents/${documentId}`, {
329
+ qs: recursive ? { recursive: true } : {},
330
+ }));
331
+ return [wrap(i, response)];
332
+ }
333
+ case 'bulkDelete': {
334
+ const idsRaw = this.getNodeParameter('documentIds', i);
335
+ const recursive = this.getNodeParameter('recursive', i, false);
336
+ const ids = idsRaw.split(',').map((s) => s.trim()).filter(Boolean);
337
+ const response = (await request_1.exadoApiRequest.call(this, 'DELETE', '/documents/bulk', {
338
+ body: { document_ids: ids, recursive },
339
+ }));
340
+ return [wrap(i, response)];
341
+ }
342
+ case 'translate': {
343
+ const documentId = this.getNodeParameter('documentId', i);
344
+ const targetLanguage = this.getNodeParameter('targetLanguage', i);
345
+ const response = (await request_1.exadoApiRequest.call(this, 'POST', `/documents/${documentId}/translate`, { body: { target_language: targetLanguage } }));
346
+ return [wrap(i, response)];
347
+ }
348
+ case 'getTranslationStatus': {
349
+ const documentId = this.getNodeParameter('documentId', i);
350
+ const response = (await request_1.exadoApiRequest.call(this, 'GET', `/documents/${documentId}/translation/status`));
351
+ return [wrap(i, response)];
352
+ }
353
+ case 'getTranslationResult': {
354
+ const documentId = this.getNodeParameter('documentId', i);
355
+ const response = (await request_1.exadoApiRequest.call(this, 'GET', `/documents/${documentId}/translation/result`));
356
+ return [wrap(i, response)];
357
+ }
358
+ default:
359
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Unknown document operation: ${operation}`, { itemIndex: i });
360
+ }
361
+ }
362
+ async function conversationHandler(operation, i) {
363
+ switch (operation) {
364
+ case 'getAll': {
365
+ const returnAll = this.getNodeParameter('returnAll', i, false);
366
+ const filters = this.getNodeParameter('filters', i, {});
367
+ const qs = {};
368
+ if (filters.search)
369
+ qs.search = filters.search;
370
+ if (filters.status)
371
+ qs.status = filters.status;
372
+ const limit = returnAll ? undefined : this.getNodeParameter('limit', i, 50);
373
+ const items = await pagination_1.exadoApiRequestAllItems.call(this, 'GET', '/conversations', 'conversations', qs, limit);
374
+ return items.map((d) => wrap(i, d));
375
+ }
376
+ case 'get': {
377
+ const id = this.getNodeParameter('conversationId', i);
378
+ const response = (await request_1.exadoApiRequest.call(this, 'GET', `/conversations/${id}`));
379
+ return [wrap(i, response)];
380
+ }
381
+ case 'ask': {
382
+ const id = this.getNodeParameter('conversationId', i);
383
+ const query = this.getNodeParameter('query', i);
384
+ const stream = this.getNodeParameter('stream', i, false);
385
+ const body = { query, stream };
386
+ if (!stream) {
387
+ const response = (await request_1.exadoApiRequest.call(this, 'POST', `/conversations/${id}/ask`, { body }));
388
+ return [wrap(i, response)];
389
+ }
390
+ const emitEachChunk = this.getNodeParameter('emitEachChunk', i, false);
391
+ return await runStreaming.call(this, 'POST', `/conversations/${id}/ask`, body, i, {
392
+ parseJson: false,
393
+ emitEachChunk,
394
+ });
395
+ }
396
+ case 'getStatus': {
397
+ const id = this.getNodeParameter('conversationId', i);
398
+ const response = (await request_1.exadoApiRequest.call(this, 'GET', `/conversations/${id}/status`));
399
+ return [wrap(i, response)];
400
+ }
401
+ case 'cancel': {
402
+ const id = this.getNodeParameter('conversationId', i);
403
+ const response = (await request_1.exadoApiRequest.call(this, 'POST', `/conversations/${id}/cancel`));
404
+ return [wrap(i, response)];
405
+ }
406
+ default:
407
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Unknown conversation operation: ${operation}`, { itemIndex: i });
408
+ }
409
+ }
410
+ async function conversationConfigHandler(operation, i) {
411
+ switch (operation) {
412
+ case 'create': {
413
+ const fileIdsRaw = this.getNodeParameter('fileIds', i, '');
414
+ const additional = this.getNodeParameter('additionalOptions', i, {});
415
+ const body = {
416
+ configuration_name: this.getNodeParameter('configurationName', i),
417
+ language: this.getNodeParameter('language', i, 'fr'),
418
+ instructions: this.getNodeParameter('instructions', i, ''),
419
+ llm_model: this.getNodeParameter('llmModel', i, ''),
420
+ file_ids: fileIdsRaw.split(',').map((s) => s.trim()).filter(Boolean),
421
+ group_ids: this.getNodeParameter('groupIds', i, []),
422
+ };
423
+ if (additional.numberOfSources !== undefined)
424
+ body.number_of_sources = additional.numberOfSources;
425
+ if (additional.isPublic !== undefined)
426
+ body.is_public = additional.isPublic;
427
+ if (additional.modelOptions) {
428
+ try {
429
+ body.model_options = JSON.parse(additional.modelOptions);
430
+ }
431
+ catch {
432
+ body.model_options = additional.modelOptions;
433
+ }
434
+ }
435
+ const response = (await request_1.exadoApiRequest.call(this, 'POST', '/conversation-configs', {
436
+ body,
437
+ }));
438
+ return [wrap(i, response)];
439
+ }
440
+ case 'getAll': {
441
+ const returnAll = this.getNodeParameter('returnAll', i, false);
442
+ const limit = returnAll ? undefined : this.getNodeParameter('limit', i, 50);
443
+ const items = await pagination_1.exadoApiRequestAllItems.call(this, 'GET', '/conversation-configs', 'configs', {}, limit);
444
+ return items.map((d) => wrap(i, d));
445
+ }
446
+ default:
447
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Unknown conversationConfig operation: ${operation}`, { itemIndex: i });
448
+ }
449
+ }
450
+ async function conversationTemplateHandler(operation, i) {
451
+ switch (operation) {
452
+ case 'create': {
453
+ const filesRaw = this.getNodeParameter('files', i, '');
454
+ const body = {
455
+ label: this.getNodeParameter('label', i),
456
+ emoji: this.getNodeParameter('emoji', i, ''),
457
+ language: this.getNodeParameter('language', i, 'fr'),
458
+ instructions: this.getNodeParameter('instructions', i, ''),
459
+ llm_model: this.getNodeParameter('llmModel', i, ''),
460
+ files: filesRaw.split(',').map((s) => s.trim()).filter(Boolean),
461
+ groups: this.getNodeParameter('groups', i, []),
462
+ number_of_sources: this.getNodeParameter('numberOfSources', i, 5),
463
+ };
464
+ const response = (await request_1.exadoApiRequest.call(this, 'POST', '/conversation-templates', {
465
+ body,
466
+ }));
467
+ return [wrap(i, response)];
468
+ }
469
+ case 'createConversation': {
470
+ const id = this.getNodeParameter('conversationTemplateId', i);
471
+ const response = (await request_1.exadoApiRequest.call(this, 'POST', `/conversation-templates/${id}/conversation`));
472
+ return [wrap(i, response)];
473
+ }
474
+ default:
475
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Unknown conversationTemplate operation: ${operation}`, { itemIndex: i });
476
+ }
477
+ }
478
+ async function metadataHandler(operation, i) {
479
+ switch (operation) {
480
+ case 'create': {
481
+ const body = {
482
+ title: this.getNodeParameter('title', i),
483
+ query: this.getNodeParameter('query', i),
484
+ group_ids: this.getNodeParameter('groupIds', i, []),
485
+ };
486
+ const response = (await request_1.exadoApiRequest.call(this, 'POST', '/metadatas', {
487
+ body,
488
+ }));
489
+ return [wrap(i, response)];
490
+ }
491
+ case 'get': {
492
+ const id = this.getNodeParameter('metadataId', i);
493
+ const response = (await request_1.exadoApiRequest.call(this, 'GET', `/metadatas/${id}`));
494
+ return [wrap(i, response)];
495
+ }
496
+ case 'getAll': {
497
+ const returnAll = this.getNodeParameter('returnAll', i, false);
498
+ const limit = returnAll ? undefined : this.getNodeParameter('limit', i, 50);
499
+ const items = await pagination_1.exadoApiRequestAllItems.call(this, 'GET', '/metadatas', 'metadatas', {}, limit);
500
+ return items.map((d) => wrap(i, d));
501
+ }
502
+ case 'update': {
503
+ const id = this.getNodeParameter('metadataId', i);
504
+ const updateFields = this.getNodeParameter('updateFields', i, {});
505
+ const response = (await request_1.exadoApiRequest.call(this, 'PUT', `/metadatas/${id}`, {
506
+ body: updateFields,
507
+ }));
508
+ return [wrap(i, response)];
509
+ }
510
+ case 'delete': {
511
+ const id = this.getNodeParameter('metadataId', i);
512
+ const response = (await request_1.exadoApiRequest.call(this, 'DELETE', `/metadatas/${id}`));
513
+ return [wrap(i, response)];
514
+ }
515
+ case 'pendingStatus': {
516
+ const response = (await request_1.exadoApiRequest.call(this, 'GET', '/metadatas/status'));
517
+ return [wrap(i, response)];
518
+ }
519
+ case 'generate': {
520
+ const documentId = this.getNodeParameter('documentId', i);
521
+ const response = (await request_1.exadoApiRequest.call(this, 'PUT', '/metadatas/generate', {
522
+ body: { document_id: documentId },
523
+ }));
524
+ return [wrap(i, response)];
525
+ }
526
+ default:
527
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Unknown metadata operation: ${operation}`, { itemIndex: i });
528
+ }
529
+ }
530
+ async function folderHandler(operation, i) {
531
+ switch (operation) {
532
+ case 'create': {
533
+ const body = {
534
+ name: this.getNodeParameter('name', i),
535
+ parent_path: this.getNodeParameter('parentPath', i, '/'),
536
+ groups: this.getNodeParameter('groups', i, []),
537
+ };
538
+ const response = (await request_1.exadoApiRequest.call(this, 'POST', '/folders', {
539
+ body,
540
+ }));
541
+ return [wrap(i, response)];
542
+ }
543
+ case 'listChildren': {
544
+ const body = {
545
+ path: this.getNodeParameter('path', i, '/'),
546
+ state: this.getNodeParameter('state', i, 'all'),
547
+ };
548
+ const response = (await request_1.exadoApiRequest.call(this, 'POST', '/folders/children', {
549
+ body,
550
+ }));
551
+ return [wrap(i, response)];
552
+ }
553
+ case 'rename': {
554
+ const body = {
555
+ old_name: this.getNodeParameter('oldName', i),
556
+ new_name: this.getNodeParameter('newName', i),
557
+ parent_path: this.getNodeParameter('parentPath', i, '/'),
558
+ };
559
+ const response = (await request_1.exadoApiRequest.call(this, 'PUT', '/folders/rename', {
560
+ body,
561
+ }));
562
+ return [wrap(i, response)];
563
+ }
564
+ default:
565
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Unknown folder operation: ${operation}`, { itemIndex: i });
566
+ }
567
+ }
568
+ async function groupHandler(operation, i) {
569
+ if (operation === 'getAll') {
570
+ const response = (await request_1.exadoApiRequest.call(this, 'GET', '/service/groups'));
571
+ return [wrap(i, response)];
572
+ }
573
+ if (operation === 'get') {
574
+ const id = this.getNodeParameter('groupId', i);
575
+ const response = (await request_1.exadoApiRequest.call(this, 'GET', `/service/groups/${id}`));
576
+ return [wrap(i, response)];
577
+ }
578
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Unknown group operation: ${operation}`, {
579
+ itemIndex: i,
580
+ });
581
+ }
582
+ async function faqTopicHandler(operation, i) {
583
+ switch (operation) {
584
+ case 'create': {
585
+ const keywordsRaw = this.getNodeParameter('keywords', i, '');
586
+ const body = {
587
+ title: this.getNodeParameter('title', i),
588
+ description: this.getNodeParameter('description', i, ''),
589
+ keywords: keywordsRaw.split(',').map((s) => s.trim()).filter(Boolean),
590
+ };
591
+ const response = (await request_1.exadoApiRequest.call(this, 'POST', '/faq/topics', {
592
+ body,
593
+ }));
594
+ return [wrap(i, response)];
595
+ }
596
+ case 'get': {
597
+ const id = this.getNodeParameter('topicId', i);
598
+ const response = (await request_1.exadoApiRequest.call(this, 'GET', `/faq/topics/${id}`));
599
+ return [wrap(i, response)];
600
+ }
601
+ case 'getAll': {
602
+ const search = this.getNodeParameter('search', i, '');
603
+ const qs = {};
604
+ if (search)
605
+ qs.search = search;
606
+ const response = (await request_1.exadoApiRequest.call(this, 'GET', '/faq/topics', {
607
+ qs,
608
+ }));
609
+ return [wrap(i, response)];
610
+ }
611
+ case 'update': {
612
+ const id = this.getNodeParameter('topicId', i);
613
+ const updateFields = this.getNodeParameter('updateFields', i, {});
614
+ if (typeof updateFields.keywords === 'string') {
615
+ updateFields.keywords = updateFields.keywords
616
+ .split(',')
617
+ .map((s) => s.trim())
618
+ .filter(Boolean);
619
+ }
620
+ const response = (await request_1.exadoApiRequest.call(this, 'PUT', `/faq/topics/${id}`, {
621
+ body: updateFields,
622
+ }));
623
+ return [wrap(i, response)];
624
+ }
625
+ case 'delete': {
626
+ const id = this.getNodeParameter('topicId', i);
627
+ const response = (await request_1.exadoApiRequest.call(this, 'DELETE', `/faq/topics/${id}`));
628
+ return [wrap(i, response)];
629
+ }
630
+ default:
631
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Unknown faqTopic operation: ${operation}`, { itemIndex: i });
632
+ }
633
+ }
634
+ async function quickHandler(operation, i) {
635
+ if (operation !== 'quickAsk') {
636
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Unknown quick operation: ${operation}`, {
637
+ itemIndex: i,
638
+ });
639
+ }
640
+ const query = this.getNodeParameter('query', i);
641
+ const response = (await request_1.exadoApiRequest.call(this, 'POST', '/tools/quick-ask', {
642
+ body: { query },
643
+ }));
644
+ return [wrap(i, response)];
645
+ }
646
+ async function runStreaming(method, endpoint, body, itemIndex, opts) {
647
+ var _a, _b, _c;
648
+ const fullResponse = (await request_1.exadoApiRequest.call(this, method, endpoint, {
649
+ body,
650
+ encoding: 'stream',
651
+ returnFullResponse: true,
652
+ json: false,
653
+ }, itemIndex));
654
+ const stream = fullResponse.body;
655
+ const items = [];
656
+ const buffer = { content: '', chunks: 0 };
657
+ try {
658
+ for await (const frame of (0, sse_1.parseSseStream)(stream, { parseJson: opts.parseJson })) {
659
+ if (frame.isError) {
660
+ throw new n8n_workflow_1.NodeApiError(this.getNode(), { message: (_a = frame.errorMessage) !== null && _a !== void 0 ? _a : 'Stream errored' }, {
661
+ message: `Exado stream errored after ${buffer.chunks} chunk(s)`,
662
+ description: `Endpoint: ${endpoint}. Partial content: ${buffer.content.slice(0, 500)}`,
663
+ itemIndex,
664
+ });
665
+ }
666
+ buffer.chunks += 1;
667
+ let textDelta = '';
668
+ if (frame.json) {
669
+ textDelta = (0, sse_1.extractDeltaText)(frame.json);
670
+ const model = frame.json.model;
671
+ if (typeof model === 'string')
672
+ buffer.model = model;
673
+ const usage = frame.json.usage;
674
+ if (usage)
675
+ buffer.usage = usage;
676
+ const choices = frame.json.choices;
677
+ const finishReason = (_b = choices === null || choices === void 0 ? void 0 : choices[0]) === null || _b === void 0 ? void 0 : _b.finish_reason;
678
+ if (typeof finishReason === 'string')
679
+ buffer.finishReason = finishReason;
680
+ }
681
+ else {
682
+ textDelta = frame.raw;
683
+ }
684
+ buffer.content += textDelta;
685
+ if (opts.emitEachChunk) {
686
+ items.push(wrap(itemIndex, {
687
+ chunk: textDelta,
688
+ raw: frame.raw,
689
+ ...(frame.json ? { json: frame.json } : {}),
690
+ }));
691
+ }
692
+ }
693
+ }
694
+ finally {
695
+ (_c = stream.destroy) === null || _c === void 0 ? void 0 : _c.call(stream);
696
+ }
697
+ if (opts.emitEachChunk)
698
+ return items;
699
+ return [
700
+ wrap(itemIndex, {
701
+ content: buffer.content,
702
+ chunks: buffer.chunks,
703
+ ...(buffer.model ? { model: buffer.model } : {}),
704
+ ...(buffer.finishReason ? { finishReason: buffer.finishReason } : {}),
705
+ ...(buffer.usage ? { usage: buffer.usage } : {}),
706
+ }),
707
+ ];
708
+ }
709
+ //# sourceMappingURL=Exado.node.js.map