@tiledesk/tiledesk-tybot-connector 2.5.0 → 2.6.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 (50) hide show
  1. package/CHANGELOG.md +1 -52
  2. package/ExtUtil.js +1 -0
  3. package/TdCache copy.js +242 -0
  4. package/TiledeskExpression.js +1 -6
  5. package/TiledeskWhenExpression.js +1 -18
  6. package/engine/MongodbBotsDataSource.js +1 -3
  7. package/engine/MongodbIntentsMachine.js +2 -3
  8. package/engine/TiledeskChatbot.js +4 -76
  9. package/engine/TiledeskChatbotConst.js +1 -7
  10. package/engine/mock/MockBotsDataSource.js +6 -11
  11. package/index.js +36 -132
  12. package/models/faq_kb.js +0 -11
  13. package/package.json +1 -1
  14. package/services/AIController.js +1 -31
  15. package/services/AIService.js +33 -62
  16. package/services/IntegrationService.js +1 -4
  17. package/services/{LLMService.js → KbService.js} +3 -3
  18. package/services/RequestService.js +2 -23
  19. package/services/TilebotService.js +3 -19
  20. package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +17 -34
  21. package/tiledeskChatbotPlugs/directives/DirAiCondition.js +51 -18
  22. package/tiledeskChatbotPlugs/directives/DirAiPrompt.js +52 -103
  23. package/tiledeskChatbotPlugs/directives/DirAskGPTV2.js +5 -108
  24. package/tiledeskChatbotPlugs/directives/DirCallSubagent.js +8 -34
  25. package/tiledeskChatbotPlugs/directives/DirCaptureUserReply.js +11 -36
  26. package/tiledeskChatbotPlugs/directives/DirGptTask.js +4 -16
  27. package/tiledeskChatbotPlugs/directives/DirIntent.js +6 -12
  28. package/tiledeskChatbotPlugs/directives/DirIteration.js +10 -63
  29. package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +16 -69
  30. package/tiledeskChatbotPlugs/directives/DirRemoveCurrentBot.js +2 -40
  31. package/tiledeskChatbotPlugs/directives/DirReply.js +6 -81
  32. package/tiledeskChatbotPlugs/directives/DirReplyV2.js +4 -58
  33. package/tiledeskChatbotPlugs/directives/DirWebRequest.js +0 -8
  34. package/tiledeskChatbotPlugs/directives/DirWebRequestV2.js +1 -11
  35. package/tiledeskChatbotPlugs/directives/DirWebRequestV2_old.js +418 -0
  36. package/tiledeskChatbotPlugs/directives/DirWebResponse.js +2 -5
  37. package/tiledeskChatbotPlugs/directives/Directives.js +0 -6
  38. package/utils/HttpUtils.js +17 -99
  39. package/utils/TiledeskChatbotUtil.js +5 -73
  40. package/utils/winston.js +2 -80
  41. package/services/InternalSubAgentService.js +0 -330
  42. package/tiledeskChatbotPlugs/directives/DirInviteHuman.js +0 -259
  43. package/tiledeskChatbotPlugs/directives/DirInvokeSubAgent.js +0 -345
  44. package/tiledeskChatbotPlugs/directives/DirJSONConditionMulti.js +0 -171
  45. package/tiledeskChatbotPlugs/directives/DirRemoveHuman.js +0 -129
  46. package/tiledeskChatbotPlugs/directives/DirReturn.js +0 -98
  47. package/utils/ConnectorsV3.js +0 -292
  48. package/utils/LlmStream.js +0 -215
  49. package/utils/SentenceChunker.js +0 -94
  50. package/utils/StreamSender.js +0 -109
package/index.js CHANGED
@@ -39,13 +39,13 @@ const AiService = require('./services/AIService.js');
39
39
  const tilebotService = require('./services/TilebotService.js');
40
40
 
41
41
  let API_ENDPOINT = null;
42
- let API_URL = null;
43
42
  let TILEBOT_ENDPOINT = null;
44
43
  let staticBots;
45
44
 
46
45
  router.post('/ext/:botid', async (req, res) => {
47
46
  const botId = req.params.botid;
48
47
  winston.verbose("(tybotRoute) POST /ext/:botid called: " + botId)
48
+
49
49
  if(!botId || botId === "null" || botId === "undefined"){
50
50
  return res.status(400).send({"success": false, error: "Required parameters botid not found. Value is 'null' or 'undefined'"})
51
51
  }
@@ -54,6 +54,7 @@ router.post('/ext/:botid', async (req, res) => {
54
54
  delete req.body.payload.request.snapshot;
55
55
  }
56
56
  winston.verbose("(tybotRoute) Request Body: ", req.body);
57
+
57
58
  const message = req.body.payload;
58
59
  const messageId = message._id;
59
60
  //const faq_kb = req.body.hook; now it is "bot"
@@ -67,7 +68,6 @@ router.post('/ext/:botid', async (req, res) => {
67
68
  message.request.id_project = projectId;
68
69
  }
69
70
 
70
-
71
71
  //skip internal note messages
72
72
  if(message && message.attributes && message.attributes.subtype === 'private') {
73
73
  winston.verbose("(tybotRoute) Skipping internal note message: " + message.text);
@@ -148,29 +148,7 @@ router.post('/ext/:botid', async (req, res) => {
148
148
  winston.error("Error on /ext updating request attributes or transcript: ", e)
149
149
  return;
150
150
  }
151
-
152
- // Streaming channels (voice): this caller message starts a new turn; a turn still running stops at its next step.
153
- // Only for calls the connector streams (request attribute voice_stream, or the previous marker voice_relay):
154
- // Gather calls on the same channel are untouched.
155
- let turnId;
156
- if (message._id && TiledeskChatbot.isVoiceStreamMessage(message) &&
157
- message.sender !== "_tdinternal" && !(message.attributes && message.attributes.subtype === "info")) {
158
- turnId = message._id;
159
- try {
160
- await TiledeskChatbot.setCurrentTurn(tdcache, requestId, turnId);
161
- winston.verbose("(tybotRoute) voice turn " + turnId + " on " + requestId);
162
- // timing for local/measure (the chatbot log has no timestamps)
163
- winston.info("[VoiceTiming] " + requestId + " " + turnId + " ext " + Date.now());
164
- } catch (e) {
165
- winston.error("(tybotRoute) Error setting the voice turn: ", e);
166
- turnId = undefined;
167
- }
168
- } else if (message.sender === "_tdinternal" && message.voice_turn_id) {
169
- // block jump (DirIntent) inside a voice turn that arrives here instead of /exec: the jumped block belongs to the
170
- // caller message's turn (supersession, and the reply that closes a streamed answer), it does not start a new one
171
- turnId = message.voice_turn_id;
172
- }
173
-
151
+
174
152
  let reply = null;
175
153
  try {
176
154
  reply = await chatbot.replyToMessage(message);
@@ -198,17 +176,15 @@ router.post('/ext/:botid', async (req, res) => {
198
176
  chatbot: chatbot,
199
177
  supportRequest: message.request,
200
178
  API_ENDPOINT: API_ENDPOINT,
201
- API_URL: API_URL,
202
179
  TILEBOT_ENDPOINT:TILEBOT_ENDPOINT,
203
180
  token: token,
204
181
  // HELP_CENTER_API_ENDPOINT: process.env.HELP_CENTER_API_ENDPOINT,
205
- cache: tdcache,
206
- turnId: turnId
182
+ cache: tdcache
207
183
  }
208
184
  );
209
-
210
- await directivesPlug.processDirectives();
211
- winston.verbose("(tybotRoute) Actions - Directives executed.");
185
+ directivesPlug.processDirectives( () => {
186
+ winston.verbose("(tybotRoute) Actions - Directives executed.");
187
+ });
212
188
  }
213
189
  catch (error) {
214
190
  directivesSuccess = false;
@@ -254,7 +230,7 @@ router.post('/ext/:botid', async (req, res) => {
254
230
  AnalyticsClient.track('agent.intent_completed', projectId, {
255
231
  agent_id: bot.root_id,
256
232
  intent_id: chatbot._lastIntentId || '',
257
- intent_name: reply.intent_display_name || 'unknown',
233
+ intent_name: reply.attributes?.intent_info?.intent_name || 'unknown',
258
234
  duration_ms: intentDuration,
259
235
  success: true,
260
236
  request_id: requestId || null
@@ -265,6 +241,11 @@ router.post('/ext/:botid', async (req, res) => {
265
241
  });
266
242
 
267
243
  router.post('/exec/:botid', async (req, res) => {
244
+ // NOTE (analytics): This route executes a named block directly via findBlock() and has no
245
+ // intent context. agent.intent_matched / agent.intent_completed are intentionally NOT emitted
246
+ // here. Only agent.block_executed (and related events) may be emitted by DirectivesChatbotPlug
247
+ // for individual directives inside the block.
248
+
268
249
  const botId = req.params.botid;
269
250
  winston.verbose("(tybotRoute) POST /exec/:botid called: " + botId);
270
251
  if(!botId || botId === "null" || botId === "undefined"){
@@ -295,12 +276,6 @@ router.post('/exec/:botid', async (req, res) => {
295
276
  return res.status(200).send({"success":true});
296
277
  }
297
278
 
298
- //skip hidden info messages (must not trigger intent matching or defaultFallback)
299
- if (TiledeskChatbotUtil.isHiddenMessage(message)) {
300
- winston.verbose("(tybotRoute) Skipping hidden info message: " + message.text);
301
- return res.status(200).send({"success":true});
302
- }
303
-
304
279
  // validate reuqestId
305
280
  let isValid = TiledeskChatbotUtil.validateRequestId(requestId, projectId);
306
281
  if (isValid) {
@@ -312,7 +287,12 @@ router.post('/exec/:botid', async (req, res) => {
312
287
  }
313
288
 
314
289
  const request_botId_key = "tilebot:botId_requests:" + requestId;
315
-
290
+ await tdcache.set(
291
+ request_botId_key,
292
+ botId,
293
+ {EX: 604800} // 7 days
294
+ );
295
+
316
296
  let botsDS;
317
297
  if (!staticBots) {
318
298
  botsDS = new MongodbBotsDataSource({projectId: projectId, botId: botId});
@@ -322,14 +302,11 @@ router.post('/exec/:botid', async (req, res) => {
322
302
  botsDS = new MockBotsDataSource(staticBots);
323
303
  }
324
304
 
325
- // Run Redis request↔bot mapping and bot metadata load in parallel (independent keys / work).
326
- let bot = await Promise.all([
327
- tdcache.set(request_botId_key, botId, {EX: 604800}), // 7 days
328
- botsDS.getBotByIdCache(botId, tdcache).catch((err)=> {
329
- Promise.reject(err);
330
- return;
331
- }),
332
- ]).then(([, b]) => b);
305
+ // get the bot metadata
306
+ let bot = await botsDS.getBotByIdCache(botId, tdcache).catch((err)=> {
307
+ Promise.reject(err);
308
+ return;
309
+ });
333
310
 
334
311
  let intentsMachine;
335
312
  let backupMachine;
@@ -351,17 +328,6 @@ router.post('/exec/:botid', async (req, res) => {
351
328
  });
352
329
  winston.verbose("(tybotRoute) Message text: " + message.text);
353
330
 
354
-
355
- try {
356
- await TiledeskChatbotUtil.updateRequestAttributes(chatbot, token, message, projectId, requestId);
357
- if (requestId.startsWith("support-group-")) {
358
- await TiledeskChatbotUtil.updateConversationTranscript(chatbot, message);
359
- }
360
- } catch (e) {
361
- winston.error("Error on /exec updating request attributes or transcript: ", e)
362
- return;
363
- }
364
-
365
331
  let reply = null;
366
332
  try {
367
333
  reply = await chatbot.findBlock(message);
@@ -375,24 +341,7 @@ router.post('/exec/:botid', async (req, res) => {
375
341
  return;
376
342
  }
377
343
 
378
- if (!reply.attributes) {
379
- reply.attributes = {};
380
- }
381
- if (!reply.attributes.intent_info) {
382
- let question_payload = Object.assign({}, message);
383
- delete question_payload.request;
384
- reply.attributes.intent_info = {
385
- intent_name: reply.intent_display_name,
386
- intent_id: reply.intent_id,
387
- is_fallback: false,
388
- question_payload: question_payload,
389
- botId: botId,
390
- bot: bot
391
- };
392
- }
393
-
394
344
  if (reply.actions && reply.actions.length > 0) { // structured actions (coming from chatbot designer)
395
- let directivesSuccess = true;
396
345
  try {
397
346
  winston.debug("(tybotRoute) Reply actions: ", reply.actions)
398
347
  let directives = TiledeskChatbotUtil.actionsToDirectives(reply.actions);
@@ -405,35 +354,19 @@ router.post('/exec/:botid', async (req, res) => {
405
354
  chatbot: chatbot,
406
355
  supportRequest: message.request,
407
356
  API_ENDPOINT: API_ENDPOINT,
408
- API_URL: API_URL,
409
357
  TILEBOT_ENDPOINT:TILEBOT_ENDPOINT,
410
358
  token: token,
411
359
  // HELP_CENTER_API_ENDPOINT: process.env.HELP_CENTER_API_ENDPOINT,
412
- cache: tdcache,
413
- // voice turn carried by DirIntent across block jumps
414
- turnId: message.voice_turn_id
360
+ cache: tdcache
415
361
  }
416
362
  );
417
- await directivesPlug.processDirectives();
418
- winston.verbose("(tybotRoute) Actions - Directives executed.");
419
-
363
+ directivesPlug.processDirectives( () => {
364
+ winston.verbose("(tybotRoute) Actions - Directives executed.");
365
+ });
420
366
  }
421
367
  catch (error) {
422
- directivesSuccess = false;
423
368
  winston.error("(tybotRoute) Error while processing actions:", error);
424
369
  }
425
-
426
- if (chatbot._intentStartTime) {
427
- const intentDuration = Date.now() - chatbot._intentStartTime;
428
- AnalyticsClient.track('agent.intent_completed', projectId, {
429
- agent_id: bot.root_id || botId,
430
- intent_id: reply?.intent_id || reply._id?.toString() || '',
431
- intent_name: reply?.intent_display_name || 'unknown',
432
- duration_ms: intentDuration,
433
- success: directivesSuccess,
434
- request_id: requestId || null
435
- });
436
- }
437
370
  }
438
371
  else { // text answer (parse text directives to get actions)
439
372
  winston.verbose("(tybotRoute) No actions. Reply text: ", reply.text)
@@ -445,25 +378,13 @@ router.post('/exec/:botid', async (req, res) => {
445
378
  reply.attributes.splits = true;
446
379
  reply.attributes.markbot = true;
447
380
  reply.attributes.fillParams = true;
448
-
381
+
449
382
  const apiext = new ExtApi({
450
383
  TILEBOT_ENDPOINT: TILEBOT_ENDPOINT
451
384
  });
452
385
  apiext.sendSupportMessageExt(reply, projectId, requestId, token, () => {
453
386
  winston.verbose("(tybotRoute) sendSupportMessageExt reply sent: ", reply)
454
387
  });
455
-
456
- if (chatbot._intentStartTime) {
457
- const intentDuration = Date.now() - chatbot._intentStartTime;
458
- AnalyticsClient.track('agent.intent_completed', projectId, {
459
- agent_id: bot.root_id,
460
- intent_id: chatbot._lastIntentId || '',
461
- intent_name: reply.intent_display_name || 'unknown',
462
- duration_ms: intentDuration,
463
- success: true,
464
- request_id: requestId || null
465
- });
466
- }
467
388
  }
468
389
 
469
390
  })
@@ -525,27 +446,21 @@ router.post('/ext/:projectId/requests/:requestId/messages', async (req, res) =>
525
446
  }
526
447
 
527
448
  bot_answer.attributes["_raw_message"] = original_answer_text;
528
- tdclient.sendSupportMessage(requestId, bot_answer, async (err, response) => {
449
+ tdclient.sendSupportMessage(requestId, bot_answer, (err, response) => {
529
450
  winston.verbose("(tybotRoute) Bot answer sent")
530
451
  if (err) {
531
452
  winston.error("(tybotRoute) Error sending message", err);
532
453
  }
533
- try {
534
- await directivesPlug.processDirectives();
454
+ directivesPlug.processDirectives(() => {
535
455
  winston.verbose("(tybotRoute) Directives executed")
536
- } catch (e) {
537
- winston.error("(tybotRoute) processDirectives error:", e);
538
- }
456
+ });
539
457
  });
540
458
  }
541
459
  else {
542
460
  winston.verbose("(tybotRoute) No bot_answer")
543
- try {
544
- await directivesPlug.processDirectives();
461
+ directivesPlug.processDirectives(() => {
545
462
  winston.verbose("(tybotRoute) Directives executed")
546
- } catch (e) {
547
- winston.error("(tybotRoute) processDirectives error:", e);
548
- }
463
+ });
549
464
  }
550
465
 
551
466
  });
@@ -712,10 +627,8 @@ router.post('/block/:project_id/:bot_id/:block_id', async (req, res) => {
712
627
  winston.verbose("Async webhook");
713
628
  tilebotService.sendMessageToBot(message, bot_id, (err, resbody) => {
714
629
  if (err) {
715
- // never log or return the raw error: it carries request headers/body (bot token)
716
- const extUrl = `${process.env.TILEBOT_ENDPOINT || `${process.env.API_ENDPOINT}/modules/tilebot`}/ext/${bot_id}`;
717
- winston.error("Async webhook err:", HttpUtils.errorSummary(err, extUrl));
718
- return res.status(500).send({ success: false, error: (err && err.message) || 'Error sending the message to the chatbot' });
630
+ winston.error("Async webhook err:\n", err);
631
+ return res.status(500).send({ success: false, error: err });
719
632
  }
720
633
  return res.status(200).send({ success: true });
721
634
  })
@@ -772,14 +685,6 @@ async function startApp(settings, completionCallback) {
772
685
  winston.info("(Tilebot) settings.API_ENDPOINT:" + API_ENDPOINT);
773
686
  }
774
687
 
775
- if (!settings.API_URL) {
776
- throw new Error("settings.API_URL is mandatory id no settings.bots.");
777
- }
778
- else {
779
- API_URL = settings.API_URL;
780
- winston.info("(Tilebot) settings.API_URL:" + API_URL);
781
- }
782
-
783
688
  if (!settings.TILEBOT_ENDPOINT) {
784
689
  TILEBOT_ENDPOINT = `${API_ENDPOINT}/modules/tilebot`
785
690
  }
@@ -787,7 +692,6 @@ async function startApp(settings, completionCallback) {
787
692
  TILEBOT_ENDPOINT = settings.TILEBOT_ENDPOINT
788
693
  }
789
694
  winston.info("(Tilebot) settings.TILEBOT_ENDPOINT:" + TILEBOT_ENDPOINT);
790
- tilebotService.setEndpoint(settings.TILEBOT_ENDPOINT, TILEBOT_ENDPOINT); // i salti fra blocchi usano lo stesso endpoint
791
695
 
792
696
  if (settings.REDIS_HOST && settings.REDIS_PORT) {
793
697
  tdcache = new TdCache({
package/models/faq_kb.js CHANGED
@@ -73,17 +73,6 @@ var Faq_kbSchema = new Schema({
73
73
  attributes: {
74
74
  type: Object,
75
75
  },
76
- /** 'v3' for an agent of the Design Studio V3 (a field of the bot since 15/10/2026, no longer `attributes.dsVersion`). */
77
- ds_version: {
78
- type: String,
79
- required: false
80
- },
81
- /** V3 agents: the connectors list the engine executes the flow from (ConnectorsV3). The server
82
- * stores it unselected by default, so the data source asks for it explicitly. */
83
- connectors: {
84
- type: Object,
85
- required: false
86
- },
87
76
  createdBy: {
88
77
  type: String,
89
78
  required: true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiledesk/tiledesk-tybot-connector",
3
- "version": "2.5.0",
3
+ "version": "2.6.0",
4
4
  "description": "Tiledesk Tybot connector",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,26 +1,6 @@
1
1
  const integrationService = require("./IntegrationService");
2
2
  const { buildOpenRouterModel } = require("../utils/openrouterUtils");
3
3
 
4
- function buildCustomHeaders(customHeaders) {
5
- if (!Array.isArray(customHeaders)) {
6
- return undefined;
7
- }
8
-
9
- const headers = {};
10
- for (const header of customHeaders) {
11
- if (!header || header.enabled === false) {
12
- continue;
13
- }
14
- const key = typeof header.key === 'string' ? header.key.trim() : '';
15
- if (!key) {
16
- continue;
17
- }
18
- headers[key] = header.value ?? "";
19
- }
20
-
21
- return Object.keys(headers).length > 0 ? headers : undefined;
22
- }
23
-
24
4
  class AIController {
25
5
 
26
6
  constructor() {}
@@ -98,22 +78,12 @@ class AIController {
98
78
  if (!server.url) {
99
79
  throw { code: 422, error: "Server url for vllm is empty or invalid" };
100
80
  }
101
- const config = {
81
+ return {
102
82
  provider,
103
83
  name: model,
104
84
  url: server.url,
105
85
  api_key: server.apikey || ""
106
86
  };
107
-
108
- const customHeaders = buildCustomHeaders(server.customHeaders);
109
- if (customHeaders) {
110
- config.custom_headers = customHeaders;
111
- // tiledesk-llm rejects an empty api_key, even when the server authenticates through headers
112
- if (config.api_key === "") {
113
- config.api_key = "sk-...";
114
- }
115
- }
116
- return config;
117
87
  }
118
88
 
119
89
  if (!value.url) {
@@ -1,73 +1,44 @@
1
1
  const httpUtils = require("../utils/HttpUtils");
2
- const API_ENDPOINT = process.env.API_ENDPOINT;
3
2
 
4
3
  class AiService {
5
4
 
6
- constructor(){}
7
-
8
- async speechToText(url, id_project, token){
9
- return new Promise((resolve, reject)=> {
10
- const HTTPREQUEST = {
11
- url: `${API_ENDPOINT}/${id_project}/llm/transcription`,
12
- headers: {
13
- 'Content-Type' : 'application/json',
14
- 'Authorization': httpUtils.fixToken(token)
15
- },
16
- json: {
17
- url: url
18
- },
19
- method: 'POST',
20
- httpsOptions: this.httpsOptions
21
- };
22
- httpUtils.request(
23
- HTTPREQUEST,
24
- function(err, resbody) {
25
- if (err) {
26
- reject(err)
27
- }
28
- else {
29
- resolve(resbody)
30
- }
31
- }
32
- );
33
- });
5
+ constructor(options){
6
+ this.APIURL = options.API_ENDPOINT
7
+ this.TOKEN = options.TOKEN
8
+ this.PROJECT_ID = options.PROJECT_ID
34
9
  }
35
10
 
36
- async textToSpeech(voiceSettings, id_project, token){
37
- return new Promise((resolve, reject)=> {
38
- const HTTPREQUEST = {
39
- url: `${API_ENDPOINT}/${id_project}/llm/speech`,
40
- headers: {
41
- 'Content-Type' : 'application/json',
42
- 'Authorization': httpUtils.fixToken(token)
43
- },
44
- json: {
45
- text: voiceSettings.text,
46
- provider: voiceSettings.provider,
47
- model: voiceSettings.model,
48
- voice: voiceSettings.voice,
49
- language: voiceSettings.language,
50
- },
51
- method: 'POST',
52
- httpsOptions: this.httpsOptions
53
- };
54
- httpUtils.request(
55
- HTTPREQUEST,
56
- function(err, resbody) {
57
- if (err) {
58
- reject(err)
59
- }
60
- else {
61
- resolve(resbody)
62
- }
63
- }
64
- );
65
- })
66
- }
11
+ async speechToText(url){
12
+ return new Promise((resolve, reject)=> {
13
+ const HTTPREQUEST = {
14
+ url: `${this.APIURL}/${this.PROJECT_ID}/llm/transcription`,
15
+ headers: {
16
+ 'Content-Type' : 'application/json',
17
+ 'Authorization': httpUtils.fixToken(this.TOKEN)
18
+ },
19
+ json: {
20
+ url: url
21
+ },
22
+ method: 'POST',
23
+ httpsOptions: this.httpsOptions
24
+ };
25
+ httpUtils.request(
26
+ HTTPREQUEST,
27
+ function(err, resbody) {
28
+ if (err) {
29
+ reject(err)
30
+ }
31
+ else {
32
+ resolve(resbody)
33
+ }
34
+ }
35
+ );
36
+ });
37
+ }
67
38
 
68
39
 
69
40
 
70
41
 
71
42
  }
72
- const aiService = new AiService();
73
- module.exports= aiService;
43
+
44
+ module.exports= AiService
@@ -103,10 +103,7 @@ class IntegrationService {
103
103
  }
104
104
 
105
105
  const masked = SECRET_KEYS.some((key) => this.looksMasked(value[key])) ||
106
- (Array.isArray(value.servers) && value.servers.some((server) => server && (
107
- this.looksMasked(server.apikey) ||
108
- (Array.isArray(server.customHeaders) && server.customHeaders.some((header) => header && this.looksMasked(header.value)))
109
- )));
106
+ (Array.isArray(value.servers) && value.servers.some((server) => server && this.looksMasked(server.apikey)));
110
107
 
111
108
  if (masked) {
112
109
  winston.error("IntegrationService: the API returned a masked credential for integration " +
@@ -2,7 +2,7 @@ const httpUtils = require('../utils/HttpUtils');
2
2
  const winston = require('../utils/winston');
3
3
  const API_ENDPOINT = process.env.API_ENDPOINT;
4
4
 
5
- class LLMService {
5
+ class KBService {
6
6
 
7
7
  constructor() { }
8
8
 
@@ -90,5 +90,5 @@ class LLMService {
90
90
  }
91
91
  }
92
92
 
93
- const llmService = new LLMService();
94
- module.exports = llmService;
93
+ const kbService = new KBService();
94
+ module.exports = kbService;
@@ -1,5 +1,4 @@
1
1
  const httpUtils = require("../utils/HttpUtils");
2
- const HttpUtils = httpUtils.constructor;
3
2
  const winston = require("../utils/winston");
4
3
  const API_ENDPOINT = process.env.API_ENDPOINT;
5
4
 
@@ -8,9 +7,8 @@ class RequestService {
8
7
  constructor() { }
9
8
 
10
9
  replaceBot(id_project, request_id, data, token) {
11
- const url = API_ENDPOINT + "/" + id_project + "/requests/" + request_id + "/replace";
12
10
  const httpRequest = {
13
- url: url,
11
+ url: API_ENDPOINT + "/" + id_project + "/requests/" + request_id + "/replace",
14
12
  headers: {
15
13
  'Content-Type': 'application/json',
16
14
  'Authorization': 'JWT ' + token
@@ -19,32 +17,13 @@ class RequestService {
19
17
  method: 'PUT'
20
18
  };
21
19
 
22
- winston.info("(RequestService) replaceBot request " + JSON.stringify({
23
- url: url,
24
- requestId: request_id,
25
- data: data,
26
- hasToken: !!token
27
- }));
28
- const started = Date.now();
29
-
30
20
  return new Promise((resolve, reject) => {
31
21
  httpUtils.request(httpRequest, (err, resbody) => {
32
- const duration_ms = Date.now() - started;
33
22
  if (err) {
34
- winston.error("(RequestService) replaceBot failed " + JSON.stringify({
35
- requestId: request_id,
36
- duration_ms: duration_ms,
37
- ...HttpUtils.errorSummary(err, url)
38
- }));
23
+ winston.error("(RequestService) error: ", err);
39
24
  reject(err);
40
25
  return;
41
26
  }
42
- winston.info("(RequestService) replaceBot response " + JSON.stringify({
43
- requestId: request_id,
44
- duration_ms: duration_ms,
45
- participants: resbody?.participants,
46
- replaced_bot_root_id: resbody?.replaced_bot_root_id
47
- }));
48
27
  resolve(resbody);
49
28
  });
50
29
  });
@@ -1,27 +1,11 @@
1
1
  const httpUtils = require("../utils/HttpUtils");
2
2
  const winston = require('../utils/winston');
3
- // L'endpoint dei salti fra blocchi (`/ext`, `/exec`). Vale, nell'ordine: il `TILEBOT_ENDPOINT`
4
- // passato a `startApp`, la variabile d'ambiente, l'endpoint che `startApp` ha ricavato da
5
- // `API_ENDPOINT`, infine l'ambiente `API_ENDPOINT`. Prima (14/10/2026) il modulo leggeva solo
6
- // l'ambiente e ignorava le impostazioni di `startApp`: un server che avvia il motore con un
7
- // endpoint diverso dall'ambiente mandava i salti al posto sbagliato.
8
- let configuredEndpoint = null;
9
- let computedEndpoint = null;
3
+ const TILEBOT_ENDPOINT = process.env.TILEBOT_ENDPOINT || `${process.env.API_ENDPOINT}/modules/tilebot`
10
4
 
11
5
  class TilebotService {
12
6
 
13
7
  constructor() { }
14
8
 
15
- /** Chiamato da `startApp`: `configured` e' `settings.TILEBOT_ENDPOINT`, `computed` il ripiego da `API_ENDPOINT`. */
16
- setEndpoint(configured, computed) {
17
- configuredEndpoint = configured || null;
18
- computedEndpoint = computed || null;
19
- }
20
-
21
- endpoint() {
22
- return configuredEndpoint || process.env.TILEBOT_ENDPOINT || computedEndpoint || `${process.env.API_ENDPOINT}/modules/tilebot`;
23
- }
24
-
25
9
  /**
26
10
  * A stub to send message to the "ext/botId" endpoint, hosted by tilebot on:
27
11
  * /${TILEBOT_ROUTE}/ext/${botId}
@@ -31,7 +15,7 @@ class TilebotService {
31
15
  * @param {string} token. User token
32
16
  */
33
17
  sendMessageToBot(message, botId, callback) {
34
- const url = `${this.endpoint()}/ext/${botId}`;
18
+ const url = `${TILEBOT_ENDPOINT}/ext/${botId}`;
35
19
  winston.verbose("sendMessageToBot URL" + url);
36
20
  const HTTPREQUEST = {
37
21
  url: url,
@@ -67,7 +51,7 @@ class TilebotService {
67
51
  * @param {string} token. User token
68
52
  */
69
53
  executeBlock(message, botId, callback) {
70
- const url = `${this.endpoint()}/exec/${botId}`;
54
+ const url = `${TILEBOT_ENDPOINT}/exec/${botId}`;
71
55
  winston.verbose("sendMessageToBot URL" + url);
72
56
  const HTTPREQUEST = {
73
57
  url: url,