@tiledesk/tiledesk-server 3.0.0 → 3.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.
- package/.circleci/config.yml +1 -1
- package/CHANGELOG.md +37 -0
- package/Dockerfile +3 -2
- package/Dockerfile-en +3 -2
- package/Dockerfile-jobs +3 -2
- package/Dockerfile-profiler +3 -2
- package/README.md +15 -0
- package/app.js +14 -1
- package/bin/quota-reset +68 -0
- package/bin/quota-restore +86 -0
- package/channels/chat21/chat21Handler.js +50 -34
- package/channels/chat21/chat21JoinTracker.js +43 -0
- package/config/database.js +5 -5
- package/config/native_mcp/native_mcp_servers.json +1 -0
- package/controllers/chatbot.controller.js +80 -27
- package/controllers/intents.controller.js +42 -0
- package/docs/superpowers/plans/2026-09-15-webhook-chatbot-hitl-chat21-ionic.md +468 -0
- package/docs/superpowers/plans/2026-09-15-webhook-chatbot-hitl-design-studio.md +1349 -0
- package/docs/superpowers/plans/2026-09-15-webhook-chatbot-hitl-server.md +1694 -0
- package/docs/superpowers/plans/2026-09-15-webhook-chatbot-hitl-tybot.md +789 -0
- package/docs/superpowers/plans/2026-09-29-hitl-known-limits-server.md +83 -0
- package/docs/superpowers/plans/2026-09-29-hitl-known-limits-tybot.md +76 -0
- package/docs/superpowers/plans/2026-09-29-hitl-participant-removal-chat21-ionic.md +97 -0
- package/docs/superpowers/plans/2026-09-29-hitl-participant-removal-design-studio.md +72 -0
- package/docs/superpowers/plans/2026-09-29-hitl-participant-removal-server.md +223 -0
- package/docs/superpowers/plans/2026-09-29-hitl-participant-removal-tybot.md +121 -0
- package/docs/superpowers/plans/2026-09-29-hitl-pre-branch-ports.md +65 -0
- package/docs/superpowers/plans/2026-09-30-flow-start-points-design-studio.md +88 -0
- package/docs/superpowers/plans/2026-09-30-flow-start-points-server.md +103 -0
- package/docs/superpowers/plans/2026-09-30-flow-start-points-tybot.md +43 -0
- package/docs/superpowers/plans/2026-10-01-scheduled-start-point-design-studio.md +80 -0
- package/docs/superpowers/plans/2026-10-01-scheduled-start-point-runtime.md +39 -0
- package/docs/superpowers/plans/2026-10-01-scheduled-start-point-server.md +106 -0
- package/docs/superpowers/specs/2026-09-15-webhook-chatbot-hitl-design.md +715 -0
- package/docs/superpowers/specs/2026-09-30-flow-start-points-design.md +156 -0
- package/docs/superpowers/specs/2026-10-01-scheduled-start-point-design.md +303 -0
- package/docs/superpowers/todo/2026-09-14-webhook-chatbot-shared-code-fixes.md +191 -0
- package/event/botEvent.js +12 -1
- package/event/emailEvent.js +3 -0
- package/event/messageEvent.js +44 -0
- package/jobs.js +10 -0
- package/jobsManager.js +19 -0
- package/middleware/errorHandler.js +6 -2
- package/models/agentPrompt.js +104 -0
- package/models/analyticResult.js +1 -1
- package/models/channelConstants.js +3 -2
- package/models/quotaUsage.js +71 -0
- package/models/request.js +6 -0
- package/models/requestSnapshot.js +12 -0
- package/models/routerLogger.js +1 -1
- package/models/webhook.js +44 -0
- package/package.json +7 -5
- package/pubmodules/emailNotification/requestNotification.js +14 -22
- package/pubmodules/events/test/eventRoute.js +7 -6
- package/pubmodules/rules/conciergeBot.js +9 -4
- package/routes/agentPrompts.js +132 -0
- package/routes/auth.js +1 -12
- package/routes/campaigns.js +0 -13
- package/routes/dataTable.js +0 -3
- package/routes/faq_kb.js +12 -1
- package/routes/messagesRoot.js +0 -1
- package/routes/quotes.js +38 -1
- package/routes/request.js +81 -5
- package/routes/users.js +0 -1
- package/routes/webhook.js +160 -8
- package/routes/webhooks.js +276 -6
- package/routes/widgetLoader.js +6 -3
- package/services/QuoteManager.js +77 -16
- package/services/aiService.js +1 -1
- package/services/chatbotService.js +55 -1
- package/services/departmentService.js +60 -43
- package/services/dolphinSchedulerClient.js +116 -0
- package/services/emailService.js +6 -1
- package/services/hitlParticipantListener.js +260 -0
- package/services/participantInviteService.js +302 -0
- package/services/participantRemoveService.js +79 -0
- package/services/quotaSnapshotService.js +1167 -0
- package/services/requestService.js +102 -144
- package/services/scheduledStart/dolphinBackend.js +246 -0
- package/services/scheduledStart/schedulerBackend.js +101 -0
- package/services/scheduledStart/schedulerServiceClient.js +41 -0
- package/services/scheduledStartPublishListener.js +186 -0
- package/services/scheduledStartRules.js +173 -0
- package/services/scheduledStartService.js +130 -0
- package/services/startPointCleanupListener.js +30 -0
- package/services/startPointService.js +158 -0
- package/services/testWsService.js +1 -4
- package/services/updateRequestSnapshotQueued.js +8 -9
- package/services/webhookConversationService.js +185 -0
- package/services/webhookSettingsValidator.js +61 -0
- package/template/email/checkpointReachedEmail.html +5 -0
- package/test/agentPromptsRoute.test.js +154 -0
- package/test/agentTokensQuota.js +237 -0
- package/test/botEventHitlFallback.js +19 -0
- package/test/chat21HandlerJoinWiring.js +59 -0
- package/test/dataTablesRoute.test.js +10 -2
- package/test/dateUtils.test.js +0 -3
- package/test/departmentService.js +8 -12
- package/test/{fileRoute.js → deprecated/_deprecated_fileRoute} +2 -2
- package/test/{kbsettingsRoute.js → deprecated/_deprecated_kbsettingsRoute} +3 -3
- package/test/faqRoute.js +6 -1
- package/test/faqkbRoute.js +14 -10
- package/test/faqkbV3Route.js +1 -1
- package/test/filepRoute.js +4 -50
- package/test/hitlParticipantListener.js +446 -0
- package/test/hitlQueueWiring.js +191 -0
- package/test/hitlWaitingReset.js +124 -0
- package/test/inviteParticipantsRoute.js +492 -0
- package/test/kbRoute.js +1 -1
- package/test/messageRoute.js +33 -21
- package/test/nativemcp.test.js +7 -1
- package/test/openaiRoute.js +2 -8
- package/test/publishFailLoud.test.js +414 -0
- package/test/quotaSnapshots.js +1044 -0
- package/test/removeParticipantsRoute.js +186 -0
- package/test/requestService.js +24 -16
- package/test/requestServiceRemoveParticipant.js +144 -0
- package/test/requestVisibility.test.js +186 -0
- package/test/scheduledStartFacade.js +184 -0
- package/test/scheduledStartHandover.js +95 -0
- package/test/scheduledStartPublish.js +320 -0
- package/test/scheduledStartRoute.js +163 -0
- package/test/scheduledStartRules.js +177 -0
- package/test/scheduledStartRun.js +299 -0
- package/test/scheduledStartSchedulerBackend.js +116 -0
- package/test/scheduledStartService.js +290 -0
- package/test/startPointsCleanup.js +69 -0
- package/test/startPointsRegression.js +169 -0
- package/test/startPointsRoute.js +158 -0
- package/test/webhookConversationRoute.js +347 -0
- package/test/webhookConversationService.js +261 -0
- package/test/webhookConversationTestUtils.js +55 -0
- package/utils/aiUtils.js +95 -1
- package/utils/intentFieldNames.js +192 -0
- package/utils/quotaCliUtil.js +43 -0
- package/utils/requestVisibility.js +355 -0
- package/websocket/webSocketServer.js +36 -31
- /package/test/{imageRoute.js → deprecated/_deprecated_imageRoute} +0 -0
|
@@ -6,6 +6,7 @@ const intentsController = require("./intents.controller");
|
|
|
6
6
|
const botEvent = require("../event/botEvent");
|
|
7
7
|
const winston = require("../config/winston");
|
|
8
8
|
const v3FlowService = require("../services/v3FlowService");
|
|
9
|
+
const intentFieldNames = require("../utils/intentFieldNames");
|
|
9
10
|
|
|
10
11
|
const IMPORT_OVERRIDE_FIELDS = [
|
|
11
12
|
"webhook_enabled",
|
|
@@ -511,11 +512,46 @@ class ChatbotController {
|
|
|
511
512
|
}
|
|
512
513
|
}
|
|
513
514
|
|
|
515
|
+
/**
|
|
516
|
+
* Field names MongoDB cannot insert ('.' inside, '$' in front) in the agent's attributes or in any
|
|
517
|
+
* block of the JSON (and of its subagents): refused with a readable 422 before any write.
|
|
518
|
+
*/
|
|
519
|
+
_assertImportableBlocks(json, skipSubagents) {
|
|
520
|
+
const errors = [
|
|
521
|
+
...intentFieldNames.collectAgentErrors(json.name, json.attributes),
|
|
522
|
+
...intentFieldNames.collectIntentErrors(json.intents)
|
|
523
|
+
];
|
|
524
|
+
if (!skipSubagents && Array.isArray(json.subagents)) {
|
|
525
|
+
json.subagents.forEach((subagent) => {
|
|
526
|
+
if (subagent) {
|
|
527
|
+
errors.push(...intentFieldNames.collectAgentErrors(subagent.name, subagent.attributes));
|
|
528
|
+
errors.push(...intentFieldNames.collectIntentErrors(subagent.intents));
|
|
529
|
+
}
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
if (errors.length > 0) {
|
|
533
|
+
throw intentFieldNames.invalidFlowError(errors);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
/** Removes a bot created by a failed import (create mode): its blocks, its subagents and their blocks. */
|
|
538
|
+
async _rollbackCreated(chatbot, id_project) {
|
|
539
|
+
try {
|
|
540
|
+
await this.deleteSubagents(chatbot._id, id_project);
|
|
541
|
+
await intentsController.deleteByChatbotId(chatbot._id);
|
|
542
|
+
await Chatbot.deleteOne({ _id: chatbot._id }).exec();
|
|
543
|
+
winston.warn("(ChatbotController) import failed: created chatbot " + chatbot._id + " removed");
|
|
544
|
+
} catch (err) {
|
|
545
|
+
winston.error("(ChatbotController) import rollback error for " + chatbot._id + ": ", err);
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
|
|
514
549
|
async import(json, id_project, chatbot_id, create, replace, overwrite, user_id, skipSubagents) {
|
|
515
550
|
let chatbot;
|
|
516
551
|
const sourceParentId = this._sourceId(json);
|
|
517
552
|
this._stripImportedIdentity(json);
|
|
518
553
|
this._prepareImportedV3(json);
|
|
554
|
+
this._assertImportableBlocks(json, skipSubagents);
|
|
519
555
|
|
|
520
556
|
if (create) {
|
|
521
557
|
json.template = "empty";
|
|
@@ -526,42 +562,59 @@ class ChatbotController {
|
|
|
526
562
|
throw new AppError(400, "Error creating new chatbot");
|
|
527
563
|
}
|
|
528
564
|
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
565
|
+
// From here on a failure leaves no half-created copy behind (a fork for publish included).
|
|
566
|
+
try {
|
|
567
|
+
if (json.attributes) {
|
|
568
|
+
this._rewriteRulesParticipants(json.attributes, chatbot._id);
|
|
569
|
+
chatbot = await this.updatedChatbot(chatbot._id, id_project, { attributes: json.attributes });
|
|
570
|
+
}
|
|
571
|
+
return await this._importContent(chatbot, json, id_project, sourceParentId, replace, overwrite, user_id, skipSubagents);
|
|
572
|
+
} catch (err) {
|
|
573
|
+
await this._rollbackCreated(chatbot, id_project);
|
|
574
|
+
throw err;
|
|
536
575
|
}
|
|
576
|
+
}
|
|
577
|
+
chatbot = await this._importInto(json, id_project, chatbot_id);
|
|
578
|
+
return this._importContent(chatbot, json, id_project, sourceParentId, replace, overwrite, user_id, skipSubagents);
|
|
579
|
+
}
|
|
537
580
|
|
|
538
|
-
|
|
581
|
+
/** Replace/overwrite mode: the existing bot takes the JSON's fields. */
|
|
582
|
+
async _importInto(json, id_project, chatbot_id) {
|
|
583
|
+
let chatbot;
|
|
584
|
+
if (!chatbot_id) {
|
|
585
|
+
throw new AppError(400, "With replace or overwrite option a id_faq_kb must be provided");
|
|
586
|
+
}
|
|
539
587
|
|
|
540
|
-
|
|
541
|
-
if (json[field]) {
|
|
542
|
-
chatbot[field] = json[field];
|
|
543
|
-
}
|
|
544
|
-
}
|
|
588
|
+
chatbot = await this.getChatbot(chatbot_id, id_project);
|
|
545
589
|
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
chatbot
|
|
590
|
+
for (const field of IMPORT_OVERRIDE_FIELDS) {
|
|
591
|
+
if (json[field]) {
|
|
592
|
+
chatbot[field] = json[field];
|
|
549
593
|
}
|
|
550
|
-
|
|
594
|
+
}
|
|
551
595
|
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
}
|
|
558
|
-
if (!chatbot) {
|
|
559
|
-
throw new AppError(404, `Chatbot not found with id ${chatbot_id}`);
|
|
560
|
-
}
|
|
596
|
+
if (json.attributes) {
|
|
597
|
+
this._rewriteRulesParticipants(json.attributes, chatbot._id);
|
|
598
|
+
chatbot.attributes = json.attributes;
|
|
599
|
+
}
|
|
600
|
+
this._applyV3Fields(chatbot, json);
|
|
561
601
|
|
|
562
|
-
|
|
602
|
+
try {
|
|
603
|
+
chatbot = await Chatbot.findByIdAndUpdate(chatbot._id, chatbot, { new: true });
|
|
604
|
+
} catch (err) {
|
|
605
|
+
winston.error("(ChatbotController) import update error: ", err);
|
|
606
|
+
throw new AppError(400, "Error updating chatbot");
|
|
607
|
+
}
|
|
608
|
+
if (!chatbot) {
|
|
609
|
+
throw new AppError(404, `Chatbot not found with id ${chatbot_id}`);
|
|
563
610
|
}
|
|
564
611
|
|
|
612
|
+
botEvent.emit("faqbot.update", chatbot);
|
|
613
|
+
return chatbot;
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
/** Blocks and subagents of the JSON into `chatbot`. */
|
|
617
|
+
async _importContent(chatbot, json, id_project, sourceParentId, replace, overwrite, user_id, skipSubagents) {
|
|
565
618
|
if (replace) {
|
|
566
619
|
await intentsController.deleteByChatbotId(chatbot._id);
|
|
567
620
|
}
|
|
@@ -2,6 +2,7 @@ const Intent = require("../models/faq");
|
|
|
2
2
|
const AppError = require("../utils/AppError");
|
|
3
3
|
const faqBotEvent = require("../event/faqBotEvent");
|
|
4
4
|
const winston = require("../config/winston");
|
|
5
|
+
const intentFieldNames = require("../utils/intentFieldNames");
|
|
5
6
|
|
|
6
7
|
const INTENT_FIELDS = [
|
|
7
8
|
"intent_display_name",
|
|
@@ -50,6 +51,9 @@ class IntentsController {
|
|
|
50
51
|
}
|
|
51
52
|
throw new AppError(409, "Duplicate intent_display_name");
|
|
52
53
|
}
|
|
54
|
+
if (err instanceof AppError) {
|
|
55
|
+
throw err;
|
|
56
|
+
}
|
|
53
57
|
winston.error("(IntentsController) create error: ", err);
|
|
54
58
|
throw new AppError(500, "Error creating intent");
|
|
55
59
|
}
|
|
@@ -59,16 +63,49 @@ class IntentsController {
|
|
|
59
63
|
if (!intents?.length) {
|
|
60
64
|
return [];
|
|
61
65
|
}
|
|
66
|
+
this._assertValidFieldNames(intents);
|
|
62
67
|
const results = await Promise.allSettled(
|
|
63
68
|
intents.map((intent) =>
|
|
64
69
|
this.create(chatbot_id, id_project, user_id, intent, options)
|
|
65
70
|
)
|
|
66
71
|
);
|
|
72
|
+
this._assertAllSaved(intents, results);
|
|
67
73
|
return results
|
|
68
74
|
.filter((r) => r.status === "fulfilled" && r.value)
|
|
69
75
|
.map((r) => r.value);
|
|
70
76
|
}
|
|
71
77
|
|
|
78
|
+
/** Refuses the whole list, before any write, when a block holds a field name MongoDB cannot insert. */
|
|
79
|
+
_assertValidFieldNames(intents) {
|
|
80
|
+
const errors = intentFieldNames.collectIntentErrors(intents);
|
|
81
|
+
if (errors.length > 0) {
|
|
82
|
+
throw intentFieldNames.invalidFlowError(errors);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* A block that could not be saved is an error, not a block to drop: the caller (import, fork,
|
|
88
|
+
* publish) must not report success with fewer blocks. Skipped duplicates resolve to null and are fine.
|
|
89
|
+
*/
|
|
90
|
+
_assertAllSaved(intents, results) {
|
|
91
|
+
const errors = [];
|
|
92
|
+
results.forEach((r, i) => {
|
|
93
|
+
if (r.status === "rejected") {
|
|
94
|
+
errors.push({
|
|
95
|
+
intent_id: intents[i].intent_id,
|
|
96
|
+
intent_display_name: intents[i].intent_display_name,
|
|
97
|
+
reason: (r.reason && r.reason.message) || "could not be saved"
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
if (errors.length > 0) {
|
|
102
|
+
winston.error("(IntentsController) " + errors.length + " of " + intents.length + " blocks not saved: " + JSON.stringify(errors));
|
|
103
|
+
const err = new AppError(500, intentFieldNames.summarizeErrors(errors));
|
|
104
|
+
err.errors = errors;
|
|
105
|
+
throw err;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
72
109
|
async upsert(chatbot_id, id_project, user_id, intent) {
|
|
73
110
|
try {
|
|
74
111
|
const savingResult = await Intent.findOneAndUpdate(
|
|
@@ -91,6 +128,9 @@ class IntentsController {
|
|
|
91
128
|
|
|
92
129
|
return savingResult.value;
|
|
93
130
|
} catch (err) {
|
|
131
|
+
if (err instanceof AppError) {
|
|
132
|
+
throw err;
|
|
133
|
+
}
|
|
94
134
|
winston.error("(IntentsController) upsert error: ", err);
|
|
95
135
|
throw new AppError(500, "Error upserting intent");
|
|
96
136
|
}
|
|
@@ -100,11 +140,13 @@ class IntentsController {
|
|
|
100
140
|
if (!intents?.length) {
|
|
101
141
|
return [];
|
|
102
142
|
}
|
|
143
|
+
this._assertValidFieldNames(intents);
|
|
103
144
|
const results = await Promise.allSettled(
|
|
104
145
|
intents.map((intent) =>
|
|
105
146
|
this.upsert(chatbot_id, id_project, user_id, intent)
|
|
106
147
|
)
|
|
107
148
|
);
|
|
149
|
+
this._assertAllSaved(intents, results);
|
|
108
150
|
return results
|
|
109
151
|
.filter((r) => r.status === "fulfilled" && r.value)
|
|
110
152
|
.map((r) => r.value);
|