@tiledesk/tiledesk-server 2.8.5 → 2.8.7
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +6 -0
- package/package.json +1 -1
- package/routes/kb.js +39 -14
- package/routes/project.js +4 -0
- package/test/kbRoute.js +87 -0
package/CHANGELOG.md
CHANGED
@@ -5,6 +5,12 @@
|
|
5
5
|
🚀 IN PRODUCTION 🚀
|
6
6
|
(https://www.npmjs.com/package/@tiledesk/tiledesk-server/v/2.3.77)
|
7
7
|
|
8
|
+
# 2.8.7
|
9
|
+
- Update project update endpoint with agent chats only function
|
10
|
+
|
11
|
+
# 2.8.6
|
12
|
+
- Bug fix: token count was incremented in action preview and kb preview even with a private key in integration
|
13
|
+
|
8
14
|
# 2.8.5
|
9
15
|
- Restored sandbox limits for free trial plan
|
10
16
|
|
package/package.json
CHANGED
package/routes/kb.js
CHANGED
@@ -13,6 +13,7 @@ const Sitemapper = require('sitemapper');
|
|
13
13
|
var mongoose = require('mongoose');
|
14
14
|
const faq = require('../models/faq');
|
15
15
|
const faq_kb = require('../models/faq_kb');
|
16
|
+
let Integration = require('../models/integrations');
|
16
17
|
|
17
18
|
const { MODELS_MULTIPLIER } = require('../utils/aiUtils');
|
18
19
|
|
@@ -186,20 +187,22 @@ router.post('/qa', async (req, res) => {
|
|
186
187
|
}
|
187
188
|
|
188
189
|
let namespaceIds = namespaces.map(namespace => namespace.id);
|
189
|
-
|
190
190
|
if (!namespaceIds.includes(data.namespace)) {
|
191
191
|
return res.status(403).send({ success: false, error: "Not allowed. The namespace does not belong to the current project." })
|
192
192
|
}
|
193
|
-
|
193
|
+
|
194
194
|
winston.debug("/qa data: ", data);
|
195
195
|
|
196
196
|
if (!data.gptkey) {
|
197
|
-
let gptkey =
|
197
|
+
let gptkey = await getKeyFromIntegrations(project_id);
|
198
|
+
if (!gptkey) {
|
199
|
+
gptkey = process.env.GPTKEY;
|
200
|
+
publicKey = true;
|
201
|
+
}
|
198
202
|
if (!gptkey) {
|
199
203
|
return res.status(403).send({ success: false, error: "GPT apikey undefined" })
|
200
204
|
}
|
201
205
|
data.gptkey = gptkey;
|
202
|
-
publicKey = true;
|
203
206
|
}
|
204
207
|
|
205
208
|
let obj = { createdAt: new Date() };
|
@@ -221,6 +224,10 @@ router.post('/qa', async (req, res) => {
|
|
221
224
|
}
|
222
225
|
}
|
223
226
|
|
227
|
+
// if (process.env.NODE_ENV === 'test') {
|
228
|
+
// return res.status(200).send({ success: true, message: "Question skipped in test environment"});
|
229
|
+
// }
|
230
|
+
|
224
231
|
openaiService.askNamespace(data).then((resp) => {
|
225
232
|
winston.debug("qa resp: ", resp.data);
|
226
233
|
let answer = resp.data;
|
@@ -233,16 +240,18 @@ router.post('/qa', async (req, res) => {
|
|
233
240
|
|
234
241
|
KB.findById(id, (err, resource) => {
|
235
242
|
|
236
|
-
|
237
|
-
|
238
|
-
multiplier
|
239
|
-
|
243
|
+
if (publicKey === true) {
|
244
|
+
let multiplier = MODELS_MULTIPLIER[data.model];
|
245
|
+
if (!multiplier) {
|
246
|
+
multiplier = 1;
|
247
|
+
winston.info("No multiplier found for AI model")
|
248
|
+
}
|
249
|
+
obj.multiplier = multiplier;
|
250
|
+
obj.tokens = answer.prompt_token_size;
|
251
|
+
|
252
|
+
let incremented_key = quoteManager.incrementTokenCount(req.project, obj);
|
253
|
+
winston.verbose("incremented_key: ", incremented_key);
|
240
254
|
}
|
241
|
-
obj.multiplier = multiplier;
|
242
|
-
obj.tokens = answer.prompt_token_size;
|
243
|
-
|
244
|
-
let incremented_key = quoteManager.incrementTokenCount(req.project, obj);
|
245
|
-
winston.verbose("incremented_key: ", incremented_key);
|
246
255
|
|
247
256
|
if (err) {
|
248
257
|
winston.error("Unable to find resource with id " + id + " in namespace " + answer.namespace + ". The standard answer is returned.")
|
@@ -517,7 +526,7 @@ router.post('/namespace', async (req, res) => {
|
|
517
526
|
let quoteManager = req.app.get('quote_manager');
|
518
527
|
let limits = await quoteManager.getPlanLimits(req.project);
|
519
528
|
let ns_limit = limits.namespace;
|
520
|
-
console.log("Limit of namespaces for current plan " + ns_limit);
|
529
|
+
//console.log("Limit of namespaces for current plan " + ns_limit);
|
521
530
|
|
522
531
|
if (namespaces.length >= ns_limit) {
|
523
532
|
return res.status(403).send({ success: false, error: "Maximum number of resources reached for the current plan", plan_limit: ns_limit });
|
@@ -1199,6 +1208,22 @@ async function startScrape(data) {
|
|
1199
1208
|
})
|
1200
1209
|
})
|
1201
1210
|
}
|
1211
|
+
|
1212
|
+
async function getKeyFromIntegrations(project_id) {
|
1213
|
+
|
1214
|
+
return new Promise( async (resolve) => {
|
1215
|
+
|
1216
|
+
let integration = await Integration.findOne({ id_project: project_id, name: 'openai' }).catch((err) => {
|
1217
|
+
winston.error("Unable to find openai integration for the current project " + project_id);
|
1218
|
+
resolve(null);
|
1219
|
+
})
|
1220
|
+
if (integration && integration.value && integration.value.apikey) {
|
1221
|
+
resolve(integration.value.apikey);
|
1222
|
+
} else {
|
1223
|
+
resolve(null);
|
1224
|
+
}
|
1225
|
+
})
|
1226
|
+
}
|
1202
1227
|
/**
|
1203
1228
|
* ****************************************
|
1204
1229
|
* Utils Methods Section - End
|
package/routes/project.js
CHANGED
@@ -419,6 +419,10 @@ router.put('/:projectid', [passport.authenticate(['basic', 'jwt'], { session: fa
|
|
419
419
|
if (req.body["settings.automatic_idle_chats"]!=undefined) {
|
420
420
|
update["settings.automatic_idle_chats"] = req.body["settings.automatic_idle_chats"];
|
421
421
|
}
|
422
|
+
|
423
|
+
if (req.body["settings.current_agent_my_chats_only"]!=undefined) {
|
424
|
+
update["settings.current_agent_my_chats_only"] = req.body["settings.current_agent_my_chats_only"];
|
425
|
+
}
|
422
426
|
|
423
427
|
if (req.body.widget!=undefined) {
|
424
428
|
update.widget = req.body.widget;
|
package/test/kbRoute.js
CHANGED
@@ -1003,6 +1003,93 @@ describe('KbRoute', () => {
|
|
1003
1003
|
|
1004
1004
|
// }).timeout(10000)
|
1005
1005
|
|
1006
|
+
// Ask KB
|
1007
|
+
// it('askkb-key-from-integrations', (done) => {
|
1008
|
+
|
1009
|
+
// var email = "test-signup-" + Date.now() + "@email.com";
|
1010
|
+
// var pwd = "pwd";
|
1011
|
+
|
1012
|
+
// userService.signup(email, pwd, "Test Firstname", "Test Lastname").then((savedUser) => {
|
1013
|
+
// projectService.create("test-kb-qa", savedUser._id).then((savedProject) => {
|
1014
|
+
|
1015
|
+
// chai.request(server)
|
1016
|
+
// .post('/' + savedProject._id + "/integration/")
|
1017
|
+
// .auth(email, pwd)
|
1018
|
+
// .send({ name: "openai", value: { apikey: "sk-testkey", organization: "Testkey" } })
|
1019
|
+
// .end((err, res) => {
|
1020
|
+
|
1021
|
+
// if (err) { console.error("err: ", err) };
|
1022
|
+
// if (log) { console.log("res.body: ", res.body) };
|
1023
|
+
// console.log("Integration created..")
|
1024
|
+
|
1025
|
+
// chai.request(server)
|
1026
|
+
// .get('/' + savedProject._id + '/kb/namespace/all')
|
1027
|
+
// .auth(email, pwd)
|
1028
|
+
// .end((err, res) => {
|
1029
|
+
|
1030
|
+
// if (err) { console.error("err: ", err); }
|
1031
|
+
// if (log) { console.log("get all namespaces res.body: ", res.body); }
|
1032
|
+
|
1033
|
+
// console.log("namespace created..")
|
1034
|
+
|
1035
|
+
// chai.request(server)
|
1036
|
+
// .post('/' + savedProject._id + "/kb/qa")
|
1037
|
+
// .auth(email, pwd)
|
1038
|
+
// .send({ model: "gpt-4o", namespace: savedProject._id, question: "sample question" })
|
1039
|
+
// .end((err, res) => {
|
1040
|
+
|
1041
|
+
// if (err) { console.error("err: ", err) };
|
1042
|
+
// if (log) { console.log("res.body: ", res.body) };
|
1043
|
+
// console.log("res.body: ", res.body)
|
1044
|
+
// done();
|
1045
|
+
// })
|
1046
|
+
|
1047
|
+
|
1048
|
+
// })
|
1049
|
+
|
1050
|
+
// })
|
1051
|
+
// })
|
1052
|
+
// })
|
1053
|
+
// }).timeout(10000)
|
1054
|
+
|
1055
|
+
// Ask KB
|
1056
|
+
// it('askkb-key-from-env', (done) => {
|
1057
|
+
|
1058
|
+
// var email = "test-signup-" + Date.now() + "@email.com";
|
1059
|
+
// var pwd = "pwd";
|
1060
|
+
|
1061
|
+
// userService.signup(email, pwd, "Test Firstname", "Test Lastname").then((savedUser) => {
|
1062
|
+
// projectService.create("test-kb-qa", savedUser._id).then((savedProject) => {
|
1063
|
+
|
1064
|
+
// chai.request(server)
|
1065
|
+
// .get('/' + savedProject._id + '/kb/namespace/all')
|
1066
|
+
// .auth(email, pwd)
|
1067
|
+
// .end((err, res) => {
|
1068
|
+
|
1069
|
+
// if (err) { console.error("err: ", err); }
|
1070
|
+
// if (log) { console.log("get all namespaces res.body: ", res.body); }
|
1071
|
+
|
1072
|
+
// console.log("namespace created..")
|
1073
|
+
|
1074
|
+
// chai.request(server)
|
1075
|
+
// .post('/' + savedProject._id + "/kb/qa")
|
1076
|
+
// .auth(email, pwd)
|
1077
|
+
// .send({ model: "gpt-4o", namespace: savedProject._id, question: "sample question" })
|
1078
|
+
// .end((err, res) => {
|
1079
|
+
|
1080
|
+
// if (err) { console.error("err: ", err) };
|
1081
|
+
// if (log) { console.log("res.body: ", res.body) };
|
1082
|
+
// console.log("res.body: ", res.body)
|
1083
|
+
// done();
|
1084
|
+
// })
|
1085
|
+
|
1086
|
+
|
1087
|
+
// })
|
1088
|
+
// })
|
1089
|
+
// })
|
1090
|
+
// }).timeout(10000)
|
1091
|
+
|
1092
|
+
|
1006
1093
|
it('webhook', (done) => {
|
1007
1094
|
|
1008
1095
|
var email = "test-signup-" + Date.now() + "@email.com";
|