@tiledesk/tiledesk-server 2.10.52 → 2.10.54
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +7 -0
- package/app.js +0 -5
- package/jobs.js +0 -5
- package/models/kb_setting.js +8 -0
- package/package.json +2 -3
- package/routes/kb.js +14 -16
- package/routes/kbsettings.js +4 -4
- package/routes/openai.js +2 -2
- package/routes/webhook.js +134 -1
- package/services/QuoteManager.js +37 -10
- package/services/aiReindexService.js +151 -0
- package/services/{openaiService.js → aiService.js} +3 -3
- package/services/requestService.js +449 -435
- package/test/kbRoute.js +74 -2
- package/utils/jobs-worker-queue-manager/queueManagerClassV2.js +15 -21
package/test/kbRoute.js
CHANGED
@@ -661,12 +661,12 @@ describe('KbRoute', () => {
|
|
661
661
|
chai.request(server)
|
662
662
|
.post('/' + savedProject._id + '/kb/multi?namespace=' + namespace_id)
|
663
663
|
.auth(email, pwd)
|
664
|
-
.send({ list:["https://gethelp.tiledesk.com/article"], scrape_type: 3 })
|
664
|
+
.send({ list:["https://gethelp.tiledesk.com/article"], refresh_rate: 'daily', scrape_type: 3 })
|
665
665
|
.end((err, res) => {
|
666
666
|
|
667
667
|
if (err) { console.error("err: ", err); }
|
668
668
|
if (log) { console.log("res.body: ", res.body) }
|
669
|
-
|
669
|
+
console.log("res.body: ", res.body)
|
670
670
|
res.should.have.status(200);
|
671
671
|
expect(res.body.length).to.equal(1)
|
672
672
|
expect(res.body[0].scrape_type).to.equal(3)
|
@@ -1437,6 +1437,78 @@ describe('KbRoute', () => {
|
|
1437
1437
|
|
1438
1438
|
|
1439
1439
|
|
1440
|
+
});
|
1441
|
+
});
|
1442
|
+
}).timeout(10000)
|
1443
|
+
|
1444
|
+
it('webhook-reindex', (done) => {
|
1445
|
+
|
1446
|
+
var email = "test-signup-" + Date.now() + "@email.com";
|
1447
|
+
var pwd = "pwd";
|
1448
|
+
|
1449
|
+
userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
|
1450
|
+
projectService.create("test-kb-webhook", savedUser._id).then(function (savedProject) {
|
1451
|
+
|
1452
|
+
chai.request(server)
|
1453
|
+
.get('/' + savedProject._id + '/kb/namespace/all')
|
1454
|
+
.auth(email, pwd)
|
1455
|
+
.end((err, res) => {
|
1456
|
+
|
1457
|
+
if (err) { console.log("error: ", err) };
|
1458
|
+
if (log) { console.log("res.body: ", res.body) };
|
1459
|
+
|
1460
|
+
res.should.have.status(200);
|
1461
|
+
res.body.should.be.a('array');
|
1462
|
+
|
1463
|
+
let namespace_id = res.body[0].id;
|
1464
|
+
|
1465
|
+
let kb = {
|
1466
|
+
name: "example_name6",
|
1467
|
+
type: "url",
|
1468
|
+
source: "https://www.exampleurl6.com",
|
1469
|
+
content: "",
|
1470
|
+
namespace: namespace_id
|
1471
|
+
}
|
1472
|
+
|
1473
|
+
chai.request(server)
|
1474
|
+
.post('/' + savedProject._id + '/kb/')
|
1475
|
+
.auth(email, pwd)
|
1476
|
+
.send(kb)
|
1477
|
+
.end((err, res) => {
|
1478
|
+
|
1479
|
+
if (err) { console.log("error: ", err) };
|
1480
|
+
if (log) { console.log("res.body: ", res.body) };
|
1481
|
+
|
1482
|
+
res.should.have.status(200);
|
1483
|
+
res.body.should.be.a('object');
|
1484
|
+
|
1485
|
+
let kb_id = res.body.value._id;
|
1486
|
+
|
1487
|
+
chai.request(server)
|
1488
|
+
.post('/webhook/kb/reindex')
|
1489
|
+
.set("x-auth-token", "testtoken")
|
1490
|
+
.send({ content_id: kb_id })
|
1491
|
+
.end((err, res) => {
|
1492
|
+
|
1493
|
+
if (err) { console.error("err: ", err) };
|
1494
|
+
if (log) { console.log("res.body: ", res.body) };
|
1495
|
+
|
1496
|
+
res.should.have.status(200);
|
1497
|
+
res.body.should.be.a('object');
|
1498
|
+
expect(res.body.success).to.equal(true);
|
1499
|
+
expect(res.body.message).to.equal("Content queued for reindexing");
|
1500
|
+
|
1501
|
+
done();
|
1502
|
+
|
1503
|
+
})
|
1504
|
+
|
1505
|
+
|
1506
|
+
})
|
1507
|
+
})
|
1508
|
+
|
1509
|
+
|
1510
|
+
|
1511
|
+
|
1440
1512
|
});
|
1441
1513
|
});
|
1442
1514
|
}).timeout(10000)
|
@@ -46,28 +46,24 @@ connect(callback) {
|
|
46
46
|
amqp.connect(this.url, function(err, conn) {
|
47
47
|
if (err) {
|
48
48
|
// if (this.debug) {console.log("[AMQP]", err.message);
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
return setTimeout(function() {
|
54
|
-
that.connect()
|
49
|
+
console.error("[JobWorker] AMQP error", err);
|
50
|
+
return setTimeout(function () {
|
51
|
+
if (that.debug) { console.log("[JobWorker] AMQP reconnecting"); }
|
52
|
+
that.connect(callback)
|
55
53
|
}, 1000);
|
54
|
+
|
56
55
|
}
|
57
56
|
conn.on("error", function(err) {
|
58
|
-
console.error("[JobWorker] err.message", err.message);
|
59
57
|
if (err.message !== "Connection closing") {
|
60
|
-
|
61
|
-
console.log("[JobWorker] AMQP conn error", err)
|
62
|
-
if (callback) {
|
63
|
-
callback(null, err)
|
64
|
-
}
|
58
|
+
console.log("[JobWorker] AMQP conn error", err);
|
65
59
|
}
|
66
60
|
});
|
67
61
|
conn.on("close", function() {
|
68
62
|
// if (that.debug) {console.log("[JobWorker] AMQP reconnecting");}
|
69
63
|
console.log("[JobWorker] AMQP reconnecting")
|
70
|
-
return setTimeout(
|
64
|
+
return setTimeout(() => {
|
65
|
+
that.connect(callback);
|
66
|
+
}, 1000);
|
71
67
|
});
|
72
68
|
|
73
69
|
console.log("[JobWorker] AMQP connected")
|
@@ -101,15 +97,13 @@ whenConnected(callback) {
|
|
101
97
|
|
102
98
|
startPublisher(callback) {
|
103
99
|
var that = this;
|
104
|
-
that.amqpConn.createConfirmChannel(function(err, ch) {
|
100
|
+
that.amqpConn.createConfirmChannel(function (err, ch) {
|
105
101
|
if (that.closeOnErr(err)) return;
|
106
|
-
ch.on("error", function(err) {
|
107
|
-
|
108
|
-
console.log("[JobWorker] - startPublisher AMQP channel error", err);
|
102
|
+
ch.on("error", function (err) {
|
103
|
+
if (that.debug) { console.log("[JobWorker] AMQP channel error", err); }
|
109
104
|
});
|
110
|
-
ch.on("close", function() {
|
111
|
-
|
112
|
-
console.log("[JobWorker] - startPublisher AMQP channel closed")
|
105
|
+
ch.on("close", function () {
|
106
|
+
if (that.debug) { console.log("[JobWorker] AMQP channel closed"); }
|
113
107
|
});
|
114
108
|
|
115
109
|
// if (this.debug) {console.log("[AMQP] pubChannel");
|
@@ -122,7 +116,7 @@ startPublisher(callback) {
|
|
122
116
|
// }
|
123
117
|
|
124
118
|
if (callback) {
|
125
|
-
|
119
|
+
callback(err);
|
126
120
|
}
|
127
121
|
|
128
122
|
});
|