@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.
- package/.circleci/config.yml +1 -1
- package/CHANGELOG.md +47 -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 +12 -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/analyticResult.js +1 -1
- package/models/channelConstants.js +3 -2
- package/models/dataTable.js +16 -0
- package/models/location.js +6 -12
- package/models/quotaUsage.js +71 -0
- package/models/request.js +71 -61
- package/models/requestSnapshot.js +12 -0
- package/models/routerLogger.js +1 -1
- package/models/webhook.js +44 -0
- package/package.json +9 -7
- package/pubmodules/emailNotification/requestNotification.js +14 -22
- package/pubmodules/events/test/eventRoute.js +7 -6
- package/pubmodules/rules/conciergeBot.js +9 -4
- package/routes/auth.js +1 -12
- package/routes/campaigns.js +0 -13
- package/routes/dataTable.js +23 -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/dataTableService.js +436 -42
- 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 +3 -2
- package/test/agentTokensQuota.js +237 -0
- package/test/botEventHitlFallback.js +19 -0
- package/test/chat21HandlerJoinWiring.js +59 -0
- package/test/dataTablesRoute.test.js +649 -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/dataTableUtils.js +99 -9
- 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
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
const axios = require("axios").default;
|
|
2
|
+
const mongoose = require("mongoose");
|
|
2
3
|
const winston = require('../config/winston');
|
|
3
4
|
const botEvent = require('../event/botEvent');
|
|
4
5
|
let Faq_kb = require("../models/faq_kb");
|
|
6
|
+
let Faq = require("../models/faq");
|
|
7
|
+
const AppError = require("../utils/AppError");
|
|
8
|
+
const intentFieldNames = require("../utils/intentFieldNames");
|
|
5
9
|
|
|
6
10
|
class ChatbotService {
|
|
7
11
|
|
|
@@ -156,13 +160,63 @@ class ChatbotService {
|
|
|
156
160
|
return endpoint;
|
|
157
161
|
}
|
|
158
162
|
|
|
163
|
+
/**
|
|
164
|
+
* 422 naming the agent attributes and every block of the source whose field names MongoDB cannot
|
|
165
|
+
* insert. Only the project's own source is read: a source of another project is left to the fork,
|
|
166
|
+
* which refuses it without telling anything about its content.
|
|
167
|
+
*/
|
|
168
|
+
async assertPublishable(sourceId, project_id) {
|
|
169
|
+
if (!mongoose.Types.ObjectId.isValid(String(sourceId))) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
const source = await Faq_kb.findOne({ _id: sourceId, id_project: String(project_id) }).lean().exec();
|
|
173
|
+
if (!source) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
const intents = await Faq.find({ id_faq_kb: String(sourceId), id_project: String(project_id) }).lean().exec();
|
|
177
|
+
const errors = [
|
|
178
|
+
...intentFieldNames.collectAgentErrors(source.name, source.attributes),
|
|
179
|
+
...intentFieldNames.collectIntentErrors(intents)
|
|
180
|
+
];
|
|
181
|
+
if (errors.length > 0) {
|
|
182
|
+
winston.warn("(ChatbotService) publish of " + sourceId + " refused: " + JSON.stringify(errors));
|
|
183
|
+
throw intentFieldNames.publishError(errors);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** The fork (copy) failed: say so in plain words, keeping the copy's own reasons. */
|
|
188
|
+
publishFailure(err) {
|
|
189
|
+
const data = (err && err.response && err.response.data) || {};
|
|
190
|
+
const status = err && err.response && err.response.status;
|
|
191
|
+
if (Array.isArray(data.errors) && data.errors.length > 0 && status >= 400 && status < 500) {
|
|
192
|
+
return intentFieldNames.publishError(data.errors);
|
|
193
|
+
}
|
|
194
|
+
const reason = data.message || data.error || (err && err.message) || "the copy could not be made";
|
|
195
|
+
const failure = new AppError(status >= 400 && status < 500 ? 422 : 500,
|
|
196
|
+
"The flow was not published: " + reason + ". The published version was not changed.");
|
|
197
|
+
if (Array.isArray(data.errors)) {
|
|
198
|
+
failure.errors = data.errors;
|
|
199
|
+
}
|
|
200
|
+
return failure;
|
|
201
|
+
}
|
|
202
|
+
|
|
159
203
|
async publish({ id_faq_kb, chatbot_id, api_url, token, project_id, user_id, release_note, req }) {
|
|
160
204
|
const sourceId = chatbot_id || id_faq_kb;
|
|
161
205
|
winston.debug("(ChatbotService) publish id_faq_kb: " + id_faq_kb + " source: " + sourceId);
|
|
162
206
|
|
|
207
|
+
// All or nothing. The copy is a new bot and the draft's url moves to it only at the end, so the
|
|
208
|
+
// published version changes only when every block was copied. A block MongoDB cannot insert is
|
|
209
|
+
// found before anything is written; any other failure of the copy removes the copy (fork rollback).
|
|
210
|
+
await this.assertPublishable(sourceId, project_id);
|
|
211
|
+
|
|
163
212
|
// Keep callsubagent.botId on the development subagent. Its url points at the published snapshot.
|
|
164
213
|
// for_publish skips FAQ_KB_CREATE on the trashed snapshot; FAQ_KB_PUBLISH is emitted below.
|
|
165
|
-
|
|
214
|
+
let forked;
|
|
215
|
+
try {
|
|
216
|
+
forked = await this.fork(sourceId, api_url, token, project_id, { skipSubagents: true, forPublish: true });
|
|
217
|
+
} catch (err) {
|
|
218
|
+
throw this.publishFailure(err);
|
|
219
|
+
}
|
|
166
220
|
const forkedChatBotId = forked.bot_id;
|
|
167
221
|
winston.debug("(ChatbotService) publish forkedChatBotId: " + forkedChatBotId);
|
|
168
222
|
|