@tiledesk/tiledesk-server 3.0.1 → 3.2.1

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 (140) hide show
  1. package/.circleci/config.yml +1 -1
  2. package/CHANGELOG.md +47 -0
  3. package/Dockerfile +3 -2
  4. package/Dockerfile-en +3 -2
  5. package/Dockerfile-jobs +3 -2
  6. package/Dockerfile-profiler +3 -2
  7. package/README.md +15 -0
  8. package/app.js +12 -1
  9. package/bin/quota-reset +68 -0
  10. package/bin/quota-restore +86 -0
  11. package/channels/chat21/chat21Handler.js +50 -34
  12. package/channels/chat21/chat21JoinTracker.js +43 -0
  13. package/config/database.js +5 -5
  14. package/config/native_mcp/native_mcp_servers.json +1 -0
  15. package/controllers/chatbot.controller.js +80 -27
  16. package/controllers/intents.controller.js +42 -0
  17. package/docs/superpowers/plans/2026-09-15-webhook-chatbot-hitl-chat21-ionic.md +468 -0
  18. package/docs/superpowers/plans/2026-09-15-webhook-chatbot-hitl-design-studio.md +1349 -0
  19. package/docs/superpowers/plans/2026-09-15-webhook-chatbot-hitl-server.md +1694 -0
  20. package/docs/superpowers/plans/2026-09-15-webhook-chatbot-hitl-tybot.md +789 -0
  21. package/docs/superpowers/plans/2026-09-29-hitl-known-limits-server.md +83 -0
  22. package/docs/superpowers/plans/2026-09-29-hitl-known-limits-tybot.md +76 -0
  23. package/docs/superpowers/plans/2026-09-29-hitl-participant-removal-chat21-ionic.md +97 -0
  24. package/docs/superpowers/plans/2026-09-29-hitl-participant-removal-design-studio.md +72 -0
  25. package/docs/superpowers/plans/2026-09-29-hitl-participant-removal-server.md +223 -0
  26. package/docs/superpowers/plans/2026-09-29-hitl-participant-removal-tybot.md +121 -0
  27. package/docs/superpowers/plans/2026-09-29-hitl-pre-branch-ports.md +65 -0
  28. package/docs/superpowers/plans/2026-09-30-flow-start-points-design-studio.md +88 -0
  29. package/docs/superpowers/plans/2026-09-30-flow-start-points-server.md +103 -0
  30. package/docs/superpowers/plans/2026-09-30-flow-start-points-tybot.md +43 -0
  31. package/docs/superpowers/plans/2026-10-01-scheduled-start-point-design-studio.md +80 -0
  32. package/docs/superpowers/plans/2026-10-01-scheduled-start-point-runtime.md +39 -0
  33. package/docs/superpowers/plans/2026-10-01-scheduled-start-point-server.md +106 -0
  34. package/docs/superpowers/specs/2026-09-15-webhook-chatbot-hitl-design.md +715 -0
  35. package/docs/superpowers/specs/2026-09-30-flow-start-points-design.md +156 -0
  36. package/docs/superpowers/specs/2026-10-01-scheduled-start-point-design.md +303 -0
  37. package/docs/superpowers/todo/2026-09-14-webhook-chatbot-shared-code-fixes.md +191 -0
  38. package/event/botEvent.js +12 -1
  39. package/event/emailEvent.js +3 -0
  40. package/event/messageEvent.js +44 -0
  41. package/jobs.js +10 -0
  42. package/jobsManager.js +19 -0
  43. package/middleware/errorHandler.js +6 -2
  44. package/models/analyticResult.js +1 -1
  45. package/models/channelConstants.js +3 -2
  46. package/models/dataTable.js +16 -0
  47. package/models/location.js +6 -12
  48. package/models/quotaUsage.js +71 -0
  49. package/models/request.js +71 -61
  50. package/models/requestSnapshot.js +12 -0
  51. package/models/routerLogger.js +1 -1
  52. package/models/webhook.js +44 -0
  53. package/package.json +9 -7
  54. package/pubmodules/emailNotification/requestNotification.js +14 -22
  55. package/pubmodules/events/test/eventRoute.js +7 -6
  56. package/pubmodules/rules/conciergeBot.js +9 -4
  57. package/routes/auth.js +1 -12
  58. package/routes/campaigns.js +0 -13
  59. package/routes/dataTable.js +23 -3
  60. package/routes/faq_kb.js +12 -1
  61. package/routes/messagesRoot.js +0 -1
  62. package/routes/quotes.js +38 -1
  63. package/routes/request.js +81 -5
  64. package/routes/users.js +0 -1
  65. package/routes/webhook.js +160 -8
  66. package/routes/webhooks.js +276 -6
  67. package/routes/widgetLoader.js +6 -3
  68. package/services/QuoteManager.js +77 -16
  69. package/services/aiService.js +1 -1
  70. package/services/chatbotService.js +55 -1
  71. package/services/dataTableService.js +436 -42
  72. package/services/departmentService.js +60 -43
  73. package/services/dolphinSchedulerClient.js +116 -0
  74. package/services/emailService.js +6 -1
  75. package/services/hitlParticipantListener.js +260 -0
  76. package/services/participantInviteService.js +302 -0
  77. package/services/participantRemoveService.js +79 -0
  78. package/services/quotaSnapshotService.js +1167 -0
  79. package/services/requestService.js +102 -144
  80. package/services/scheduledStart/dolphinBackend.js +246 -0
  81. package/services/scheduledStart/schedulerBackend.js +101 -0
  82. package/services/scheduledStart/schedulerServiceClient.js +41 -0
  83. package/services/scheduledStartPublishListener.js +186 -0
  84. package/services/scheduledStartRules.js +173 -0
  85. package/services/scheduledStartService.js +130 -0
  86. package/services/startPointCleanupListener.js +30 -0
  87. package/services/startPointService.js +158 -0
  88. package/services/testWsService.js +1 -4
  89. package/services/updateRequestSnapshotQueued.js +8 -9
  90. package/services/webhookConversationService.js +185 -0
  91. package/services/webhookSettingsValidator.js +61 -0
  92. package/template/email/checkpointReachedEmail.html +5 -0
  93. package/test/agentPromptsRoute.test.js +3 -2
  94. package/test/agentTokensQuota.js +237 -0
  95. package/test/botEventHitlFallback.js +19 -0
  96. package/test/chat21HandlerJoinWiring.js +59 -0
  97. package/test/dataTablesRoute.test.js +649 -2
  98. package/test/dateUtils.test.js +0 -3
  99. package/test/departmentService.js +8 -12
  100. package/test/{fileRoute.js → deprecated/_deprecated_fileRoute} +2 -2
  101. package/test/{kbsettingsRoute.js → deprecated/_deprecated_kbsettingsRoute} +3 -3
  102. package/test/faqRoute.js +6 -1
  103. package/test/faqkbRoute.js +14 -10
  104. package/test/faqkbV3Route.js +1 -1
  105. package/test/filepRoute.js +4 -50
  106. package/test/hitlParticipantListener.js +446 -0
  107. package/test/hitlQueueWiring.js +191 -0
  108. package/test/hitlWaitingReset.js +124 -0
  109. package/test/inviteParticipantsRoute.js +492 -0
  110. package/test/kbRoute.js +1 -1
  111. package/test/messageRoute.js +33 -21
  112. package/test/nativemcp.test.js +7 -1
  113. package/test/openaiRoute.js +2 -8
  114. package/test/publishFailLoud.test.js +414 -0
  115. package/test/quotaSnapshots.js +1044 -0
  116. package/test/removeParticipantsRoute.js +186 -0
  117. package/test/requestService.js +24 -16
  118. package/test/requestServiceRemoveParticipant.js +144 -0
  119. package/test/requestVisibility.test.js +186 -0
  120. package/test/scheduledStartFacade.js +184 -0
  121. package/test/scheduledStartHandover.js +95 -0
  122. package/test/scheduledStartPublish.js +320 -0
  123. package/test/scheduledStartRoute.js +163 -0
  124. package/test/scheduledStartRules.js +177 -0
  125. package/test/scheduledStartRun.js +299 -0
  126. package/test/scheduledStartSchedulerBackend.js +116 -0
  127. package/test/scheduledStartService.js +290 -0
  128. package/test/startPointsCleanup.js +69 -0
  129. package/test/startPointsRegression.js +169 -0
  130. package/test/startPointsRoute.js +158 -0
  131. package/test/webhookConversationRoute.js +347 -0
  132. package/test/webhookConversationService.js +261 -0
  133. package/test/webhookConversationTestUtils.js +55 -0
  134. package/utils/aiUtils.js +95 -1
  135. package/utils/dataTableUtils.js +99 -9
  136. package/utils/intentFieldNames.js +192 -0
  137. package/utils/quotaCliUtil.js +43 -0
  138. package/utils/requestVisibility.js +355 -0
  139. package/websocket/webSocketServer.js +36 -31
  140. /package/test/{imageRoute.js → deprecated/_deprecated_imageRoute} +0 -0
@@ -7,7 +7,6 @@ var Request = require("../models/request");
7
7
  var Message = require("../models/message");
8
8
  var Faq_kb = require("../models/faq_kb");
9
9
  const WebSocket = require('ws');
10
- var url = require('url');
11
10
  var validtoken = require('../middleware/valid-token');
12
11
  var messageEvent = require("../event/messageEvent");
13
12
  var eventEvent = require("../pubmodules/events/eventEvent");
@@ -25,6 +24,7 @@ var mongoose = require('mongoose');
25
24
  const requestConstants = require("../models/requestConstants");
26
25
  var RoleConstants = require('../models/roleConstants');
27
26
  var projectUserService = require("../services/projectUserService");
27
+ var requestVisibility = require("../utils/requestVisibility");
28
28
 
29
29
  let configSecretOrPubicKay = process.env.GLOBAL_SECRET || config.secret;
30
30
 
@@ -102,9 +102,12 @@ class WebSocketServer {
102
102
  verifyClient: function (info, cb) {
103
103
  //console.log('info.req', info.req);
104
104
  // var token = info.req.headers.Authorization
105
- let urlParsed = url.parse(info.req.url, true);
106
- // console.log('urlParsed', urlParsed);
107
- var queryParameter = urlParsed.query;
105
+ let queryParameter;
106
+ try {
107
+ queryParameter = Object.fromEntries(new URL(info.req.url, 'http://localhost').searchParams);
108
+ } catch (err) {
109
+ return cb(false, 401, 'Unauthorized');
110
+ }
108
111
  winston.debug('queryParameter', queryParameter);
109
112
 
110
113
  var token = queryParameter.token;
@@ -276,7 +279,7 @@ class WebSocketServer {
276
279
  winston.debug('queryRequest admin: ' + JSON.stringify(queryRequest));
277
280
  }
278
281
  else if (projectuser.hasPermissionOrRole('request_read_group', ["agent"])) {
279
- queryRequest["$or"] = [{ "snapshot.agents.id_user": req.user.id }, { "participants": req.user.id }]
282
+ queryRequest["$or"] = requestVisibility.visibilityOr(req.user.id, projectuser.createdAt)
280
283
  } else {
281
284
  winston.debug('queryRequest agent: ' + JSON.stringify(queryRequest));
282
285
  queryRequest["participants"] = req.user.id;
@@ -358,7 +361,7 @@ class WebSocketServer {
358
361
  if (projectuser.hasPermissionOrRole('request_read_all', ["owner", "admin"])) {
359
362
  winston.debug('ws requests query admin: ' + JSON.stringify(query));
360
363
  } else if (projectuser.hasPermissionOrRole('request_read_group', ["agent"])) {
361
- query["$or"] = [{ "snapshot.agents.id_user": req.user.id }, { "participants": req.user.id }];
364
+ query["$or"] = requestVisibility.visibilityOr(req.user.id, projectuser.createdAt);
362
365
  winston.debug('ws requests query agent: ' + JSON.stringify(query));
363
366
  } else {
364
367
  query["participants"] = req.user.id;
@@ -416,12 +419,11 @@ class WebSocketServer {
416
419
  }
417
420
 
418
421
  // attento qui
419
- if (request.snapshot.agents && request.snapshot.agents.length > 0) {
420
- var agentsnew = [];
421
- request.snapshot.agents.forEach(a => {
422
- agentsnew.push({ id_user: a.id_user }) //remove unnecessary request.agents[].project_user fields. keep only id_user
423
- });
424
- request.snapshot.agents = agentsnew;
422
+ if (request.snapshot) {
423
+ var agentsForClient = requestVisibility.agentsForClient(request.snapshot);
424
+ if (agentsForClient) {
425
+ request.snapshot.agents = agentsForClient;
426
+ }
425
427
  }
426
428
 
427
429
 
@@ -660,7 +662,7 @@ class WebSocketServer {
660
662
  winston.debug('query admin: ' + JSON.stringify(query));
661
663
  } else if (projectuser.hasPermissionOrRole('request_read_group', ["agent"])) {
662
664
 
663
- query["$or"] = [{ "snapshot.agents.id_user": req.user.id }, { "participants": req.user.id }]
665
+ query["$or"] = requestVisibility.visibilityOr(req.user.id, projectuser.createdAt)
664
666
 
665
667
  }
666
668
  // else if (projectuser.hasPermissionOrRole('request_read_mine', ["????"])) {
@@ -773,13 +775,16 @@ class WebSocketServer {
773
775
  winston.debug('snapshotAgents', snapshotAgents);
774
776
  // requestJSON.snapshot.agents = snapshotAgents;
775
777
 
776
- if (snapshotAgents.snapshot.agents && snapshotAgents.snapshot.agents.length > 0) {
777
- var agentsnew = [];
778
- snapshotAgents.snapshot.agents.forEach(a => {
779
- agentsnew.push({ id_user: a.id_user })
780
- });
781
- //TODO ATTENTION change value by reference requestJSON.snapshot.agents. but it's fixed with line 640
782
- requestJSON.snapshot.agents = agentsnew;
778
+ if (snapshotAgents && snapshotAgents.snapshot) {
779
+ var agentsForClient = requestVisibility.agentsForClient(snapshotAgents.snapshot);
780
+ if (agentsForClient) {
781
+ requestJSON.snapshot.agents = agentsForClient;
782
+ }
783
+ if (snapshotAgents.snapshot.visibility) {
784
+ requestJSON.snapshot.visibility = snapshotAgents.snapshot.visibility;
785
+ requestJSON.snapshot.visibilitySince = snapshotAgents.snapshot.visibilitySince;
786
+ requestJSON.snapshot.agentIds = snapshotAgents.snapshot.agentIds;
787
+ }
783
788
  }
784
789
  winston.debug('requestJSON', requestJSON);
785
790
  } catch (e) {
@@ -827,13 +832,16 @@ class WebSocketServer {
827
832
  winston.debug('snapshotAgents', snapshotAgents);
828
833
  // requestJSON.snapshot.agents = snapshotAgents;
829
834
 
830
- if (snapshotAgents.snapshot.agents && snapshotAgents.snapshot.agents.length > 0) {
831
- var agentsnew = [];
832
- snapshotAgents.snapshot.agents.forEach(a => {
833
- agentsnew.push({ id_user: a.id_user })
834
- });
835
- //TODO ATTENTION change value by reference requestJSON.snapshot.agents . fixed with line 693
836
- requestJSON.snapshot.agents = agentsnew;
835
+ if (snapshotAgents && snapshotAgents.snapshot) {
836
+ var agentsForClient = requestVisibility.agentsForClient(snapshotAgents.snapshot);
837
+ if (agentsForClient) {
838
+ requestJSON.snapshot.agents = agentsForClient;
839
+ }
840
+ if (snapshotAgents.snapshot.visibility) {
841
+ requestJSON.snapshot.visibility = snapshotAgents.snapshot.visibility;
842
+ requestJSON.snapshot.visibilitySince = snapshotAgents.snapshot.visibilitySince;
843
+ requestJSON.snapshot.agentIds = snapshotAgents.snapshot.agentIds;
844
+ }
837
845
  }
838
846
  winston.debug('requestJSON', requestJSON);
839
847
 
@@ -950,10 +958,7 @@ class WebSocketServer {
950
958
  // winston.debug('ws connection. req.url)', req.url);
951
959
  // //console.log('ws connection. req', req);
952
960
 
953
- // let urlParsed = url.parse(req.url, true);
954
- // winston.debug('urlParsed', urlParsed);
955
-
956
- // var queryParameter = urlParsed.query;
961
+ // let queryParameter = Object.fromEntries(new URL(req.url, 'http://localhost').searchParams);
957
962
  // winston.debug('queryParameter', queryParameter);
958
963
 
959
964
  // var id_project = queryParameter.id_project;