@tiledesk/tiledesk-server 2.13.49 → 2.13.51
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/CHANGELOG.md +9 -0
- package/app.js +7 -4
- package/config/kb/embedding.js +7 -0
- package/config/kb/engine.hybrid.js +10 -0
- package/config/kb/engine.js +10 -0
- package/jobs.js +6 -2
- package/jobsManager.js +6 -1
- package/models/kb_setting.js +60 -15
- package/models/profile.js +54 -5
- package/models/request.js +1 -1
- package/package.json +4 -4
- package/pubmodules/apps/listener.js +2 -1
- package/pubmodules/queue/reconnect.js +16 -3
- package/pubmodules/queue/reconnectFanout.js +4 -0
- package/routes/kb.js +548 -626
- package/routes/request.js +3 -0
- package/routes/webhook.js +86 -38
- package/services/aiManager.js +464 -0
- package/services/aiService.js +4 -2
- package/services/requestService.js +392 -813
- package/services/subscriptionNotifier.js +12 -1
- package/services/updateRequestSnapshotQueued.js +71 -0
- package/test/kbRoute.js +956 -910
- package/test/messageRoute.js +12 -12
- package/test/requestRoute.js +46 -44
- package/test/requestService.js +84 -84
- package/test/webhookRoute.js +1 -1
|
@@ -27,6 +27,13 @@ var webhook_origin = process.env.WEBHOOK_ORIGIN || "http://localhost:3000";
|
|
|
27
27
|
winston.debug("webhook_origin: "+webhook_origin);
|
|
28
28
|
|
|
29
29
|
|
|
30
|
+
var SUBSCRIPTION_LOG_ENABLED = false;
|
|
31
|
+
if (process.env.SUBSCRIPTION_LOG_ENABLED==true || process.env.SUBSCRIPTION_LOG_ENABLED=="true") {
|
|
32
|
+
SUBSCRIPTION_LOG_ENABLED = true;
|
|
33
|
+
}
|
|
34
|
+
winston.info("SUBSCRIPTION_LOG_ENABLED: "+SUBSCRIPTION_LOG_ENABLED);
|
|
35
|
+
|
|
36
|
+
|
|
30
37
|
var request = require('retry-request', {
|
|
31
38
|
request: require('request')
|
|
32
39
|
});
|
|
@@ -124,6 +131,8 @@ class SubscriptionNotifier {
|
|
|
124
131
|
winston.debug("SubscriptionLog response", response);
|
|
125
132
|
winston.debug("SubscriptionLog jsonResponse", jsonResponse);
|
|
126
133
|
|
|
134
|
+
if (SUBSCRIPTION_LOG_ENABLED==true) {
|
|
135
|
+
|
|
127
136
|
var subscriptionLog = new SubscriptionLog({event: s.event, target: s.target,
|
|
128
137
|
response: JSON.stringify(response),
|
|
129
138
|
body: JSON.stringify(jsonResponse),
|
|
@@ -137,7 +146,9 @@ class SubscriptionNotifier {
|
|
|
137
146
|
}
|
|
138
147
|
winston.debug("SubscriptionLog saved", sl);
|
|
139
148
|
});
|
|
140
|
-
|
|
149
|
+
|
|
150
|
+
}
|
|
151
|
+
|
|
141
152
|
if (err) {
|
|
142
153
|
winston.error("Error sending webhook for event " + s.event + " TO " + s.target + " with error " , err);
|
|
143
154
|
if (callback) {
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var Request = require("../models/request");
|
|
4
|
+
const requestEvent = require('../event/requestEvent');
|
|
5
|
+
var winston = require('../config/winston');
|
|
6
|
+
|
|
7
|
+
class UpdateRequestSnapshotQueued {
|
|
8
|
+
|
|
9
|
+
constructor() {
|
|
10
|
+
// this.listen();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
listen() {
|
|
14
|
+
this.updateRequestSnapshot();
|
|
15
|
+
winston.info("Listening UpdateRequestSnapshotQueued started")
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
updateRequestSnapshot() {
|
|
19
|
+
var snapshotUpdateKey = 'request.snapshot.update';
|
|
20
|
+
if (requestEvent.queueEnabled) {
|
|
21
|
+
snapshotUpdateKey = 'request.snapshot.update.queue';
|
|
22
|
+
}
|
|
23
|
+
winston.debug("snapshotUpdateKey: " + snapshotUpdateKey);
|
|
24
|
+
|
|
25
|
+
requestEvent.on(snapshotUpdateKey, function (data) {
|
|
26
|
+
setImmediate(() => {
|
|
27
|
+
winston.debug("updateRequestSnapshot on request.snapshot.update ", data);
|
|
28
|
+
|
|
29
|
+
var request = data.request;
|
|
30
|
+
var snapshot = data.snapshot;
|
|
31
|
+
|
|
32
|
+
if (!request || !request.request_id || !request.id_project) {
|
|
33
|
+
winston.error("updateRequestSnapshot: Invalid request data", data);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (!snapshot || Object.keys(snapshot).length === 0) {
|
|
38
|
+
winston.debug("updateRequestSnapshot: Empty snapshot, skipping update");
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
var query = { request_id: request.request_id, id_project: request.id_project };
|
|
43
|
+
winston.debug("updateRequestSnapshot query ", query);
|
|
44
|
+
|
|
45
|
+
Request.findOneAndUpdate(
|
|
46
|
+
query,
|
|
47
|
+
{ "$set": { "snapshot": snapshot } },
|
|
48
|
+
{ new: true },
|
|
49
|
+
function (err, updatedRequest) {
|
|
50
|
+
if (err) {
|
|
51
|
+
winston.error("Error updating request snapshot updateRequestSnapshot", err);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (updatedRequest) {
|
|
55
|
+
winston.debug("updateRequestSnapshot updated request " + updatedRequest.request_id);
|
|
56
|
+
requestEvent.emit('request.update.snapshot', { request: updatedRequest, snapshot: snapshot });
|
|
57
|
+
} else {
|
|
58
|
+
winston.warn("updateRequestSnapshot: Request not found for " + request.request_id);
|
|
59
|
+
}
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
var updateRequestSnapshotQueued = new UpdateRequestSnapshotQueued();
|
|
69
|
+
|
|
70
|
+
module.exports = updateRequestSnapshotQueued;
|
|
71
|
+
|