@tiledesk/tiledesk-tybot-connector 2.1.9 → 2.1.10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiledesk/tiledesk-tybot-connector",
3
- "version": "2.1.9",
3
+ "version": "2.1.10",
4
4
  "description": "Tiledesk Tybot connector",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -43,36 +43,6 @@ class KBService {
43
43
  })
44
44
  }
45
45
 
46
- async getKeyFromKbSettings(id_project, token) {
47
-
48
- return new Promise((resolve) => {
49
- const http_request = {
50
- url: API_ENDPOINT + "/" + id_project + "/kbsettings",
51
- headers: {
52
- 'Content-Type': 'application/json',
53
- 'Authorization': 'JWT ' + token
54
- },
55
- method: "GET"
56
- }
57
- winston.debug("Kb HttpRequest", http_request);
58
-
59
- httpUtils.request(
60
- http_request, async (err, resbody) => {
61
- if (err) {
62
- winston.error("Error getting kb settings:", err?.response?.data);
63
- resolve(null);
64
- } else {
65
- if (!resbody || !resbody.gptkey) {
66
- resolve(null);
67
- } else {
68
- resolve(resbody.gptkey);
69
- }
70
- }
71
- }
72
- )
73
- })
74
- }
75
-
76
46
  async addUnansweredQuestion(id_project, data, token) {
77
47
 
78
48
  return new Promise((resolve, reject) => {
@@ -86,11 +86,6 @@ class DirAddKbContent {
86
86
  let key = await integrationService.getKeyFromIntegrations(this.projectId, 'openai', this.token);
87
87
  if (!key) {
88
88
  this.logger.native("[Add to KnwoledgeBase] Using shared OpenAI key");
89
- winston.verbose("[DirAddKbContent] - Key not found in Integrations. Searching in kb settings...");
90
- key = await this.getKeyFromKbSettings();
91
- }
92
-
93
- if (!key) {
94
89
  winston.verbose("[DirAddKbContent] - Retrieve public gptkey")
95
90
  key = process.env.GPTKEY;
96
91
  publicKey = true;
@@ -199,36 +194,6 @@ class DirAddKbContent {
199
194
  )
200
195
  }
201
196
 
202
- async getKeyFromKbSettings() {
203
- return new Promise((resolve) => {
204
-
205
- const KB_HTTPREQUEST = {
206
- url: this.API_ENDPOINT + "/" + this.context.projectId + "/kbsettings",
207
- headers: {
208
- 'Content-Type': 'application/json',
209
- 'Authorization': 'JWT ' + this.context.token
210
- },
211
- method: "GET"
212
- }
213
- winston.debug("DirAddKbContent KB HttpRequest", KB_HTTPREQUEST);
214
-
215
- httpUtils.request(
216
- KB_HTTPREQUEST, async (err, resbody) => {
217
- if (err) {
218
- winston.error("DirAddKbContent Get kb settings error ", err?.response?.data);
219
- resolve(null);
220
- } else {
221
- if (!resbody.gptkey) {
222
- resolve(null);
223
- } else {
224
- resolve(resbody.gptkey);
225
- }
226
- }
227
- }
228
- )
229
- })
230
- }
231
-
232
197
  async checkQuoteAvailability() {
233
198
  return new Promise((resolve) => {
234
199
 
@@ -519,36 +519,6 @@ class DirAiCondition {
519
519
  }
520
520
  }
521
521
 
522
- async getKeyFromKbSettings() {
523
- return new Promise((resolve) => {
524
-
525
- const KB_HTTPREQUEST = {
526
- url: this.API_ENDPOINT + "/" + this.context.projectId + "/kbsettings",
527
- headers: {
528
- 'Content-Type': 'application/json',
529
- 'Authorization': 'JWT ' + this.context.token
530
- },
531
- method: "GET"
532
- }
533
- winston.debug("DirAiCondition KB HttpRequest", KB_HTTPREQUEST);
534
-
535
- httpUtils.request(
536
- KB_HTTPREQUEST, async (err, resbody) => {
537
- if (err) {
538
- winston.error("(httprequest) DirAiCondition Get KnowledgeBase err: " + err.message);
539
- resolve(null);
540
- } else {
541
- if (!resbody.gptkey) {
542
- resolve(null);
543
- } else {
544
- resolve(resbody.gptkey);
545
- }
546
- }
547
- }
548
- )
549
- })
550
- }
551
-
552
522
  async checkQuoteAvailability() {
553
523
  return new Promise((resolve) => {
554
524
 
@@ -597,36 +597,6 @@ class DirAiPrompt {
597
597
  };
598
598
  }
599
599
 
600
- async getKeyFromKbSettings() {
601
- return new Promise((resolve) => {
602
-
603
- const KB_HTTPREQUEST = {
604
- url: this.API_ENDPOINT + "/" + this.context.projectId + "/kbsettings",
605
- headers: {
606
- 'Content-Type': 'application/json',
607
- 'Authorization': 'JWT ' + this.context.token
608
- },
609
- method: "GET"
610
- }
611
- winston.debug("DirAiPrompt KB HttpRequest", KB_HTTPREQUEST);
612
-
613
- httpUtils.request(
614
- KB_HTTPREQUEST, async (err, resbody) => {
615
- if (err) {
616
- winston.error("(httprequest) DirAiPrompt Get KnowledgeBase err: " + err.message);
617
- resolve(null);
618
- } else {
619
- if (!resbody.gptkey) {
620
- resolve(null);
621
- } else {
622
- resolve(resbody.gptkey);
623
- }
624
- }
625
- }
626
- )
627
- })
628
- }
629
-
630
600
  async checkQuoteAvailability() {
631
601
  return new Promise((resolve) => {
632
602
 
@@ -97,11 +97,6 @@ class DirAskGPT {
97
97
  winston.verbose("DirAskGPT KbEndpoint URL: ", kb_endpoint);
98
98
 
99
99
  let key = await integrationService.getKeyFromIntegrations(this.projectId, 'openai', this.token);
100
- if (!key) {
101
- winston.debug("(DirAskGPT) - Key not found in Integrations. Searching in kb settings...");
102
- key = await this.getKeyFromKbSettings();
103
- }
104
-
105
100
  if (!key) {
106
101
  winston.debug("(DirAskGPT) - Retrieve public gptkey")
107
102
  key = process.env.GPTKEY;
@@ -248,29 +243,28 @@ class DirAskGPT {
248
243
  }
249
244
  }
250
245
 
251
- async getKeyFromKbSettings() {
246
+ async checkQuoteAvailability() {
252
247
  return new Promise((resolve) => {
253
248
 
254
- const KB_HTTPREQUEST = {
255
- url: this.API_ENDPOINT + "/" + this.context.projectId + "/kbsettings",
249
+ const HTTPREQUEST = {
250
+ url: this.API_ENDPOINT + "/" + this.context.projectId + "/quotes/tokens",
256
251
  headers: {
257
252
  'Content-Type': 'application/json',
258
253
  'Authorization': 'JWT ' + this.context.token
259
254
  },
260
255
  method: "GET"
261
256
  }
262
- winston.debug("(DirAskGPT) KB HttpRequest ", KB_HTTPREQUEST);
257
+ winston.debug("(DirAskGPT) check quote availability HttpRequest ", HTTPREQUEST);
263
258
 
264
259
  httpUtils.request(
265
- KB_HTTPREQUEST, async (err, resbody) => {
260
+ HTTPREQUEST, async (err, resbody) => {
266
261
  if (err) {
267
- winston.error("DirAskGPT Get kb settings error ", err?.response?.data);
268
- resolve(null);
262
+ resolve(true)
269
263
  } else {
270
- if (!resbody.gptkey) {
271
- resolve(null);
264
+ if (resbody.isAvailable === true) {
265
+ resolve(true)
272
266
  } else {
273
- resolve(resbody.gptkey);
267
+ resolve(false)
274
268
  }
275
269
  }
276
270
  }
@@ -123,12 +123,6 @@ class DirGptTask {
123
123
  winston.debug("(DirGptTask) openai_url " + openai_url);
124
124
 
125
125
  let key = await integrationService.getKeyFromIntegrations(this.projectId, 'openai', this.token);
126
- if (!key) {
127
- this.logger.native("[ChatGPT Task] Key not found in Integrations.");
128
- winston.debug("(DirGptTask) - Key not found in Integrations. Searching in kb settings...");
129
- key = await this.getKeyFromKbSettings();
130
- }
131
-
132
126
  if (!key) {
133
127
  this.logger.native("[ChatGPT Task] Retrieve shared gptkey.");
134
128
  winston.debug("(DirGptTask) - Retrieve public gptkey")
@@ -319,36 +313,6 @@ class DirGptTask {
319
313
  }
320
314
  }
321
315
 
322
- async getKeyFromKbSettings() {
323
- return new Promise((resolve) => {
324
-
325
- const KB_HTTPREQUEST = {
326
- url: this.API_ENDPOINT + "/" + this.context.projectId + "/kbsettings",
327
- headers: {
328
- 'Content-Type': 'application/json',
329
- 'Authorization': 'JWT ' + this.context.token
330
- },
331
- method: "GET"
332
- }
333
- winston.debug("(DirGptTask) KB HttpRequest ", KB_HTTPREQUEST);
334
-
335
- httpUtils.request(
336
- KB_HTTPREQUEST, async (err, resbody) => {
337
- if (err) {
338
- winston.error("(DirGptTask) Get KnowledgeBase err:", err.message);
339
- resolve(null);
340
- } else {
341
- if (!resbody.gptkey) {
342
- resolve(null);
343
- } else {
344
- resolve(resbody.gptkey);
345
- }
346
- }
347
- }
348
- )
349
- })
350
- }
351
-
352
316
  async checkQuoteAvailability() {
353
317
  return new Promise((resolve) => {
354
318
 
@@ -116,121 +116,27 @@ class DirGptTask {
116
116
  key = integration.value.apikey;
117
117
  }
118
118
 
119
- // key not present in integrations - for retro compatibility search in kbsettings
119
+ // key not present in integrations - fall back to shared GPTKEY
120
120
  if (!key) {
121
121
 
122
- winston.debug("(DirGptTask) Key not found in Integrations. Searching in kb settings...");
122
+ winston.debug("(DirGptTask) Key not found in Integrations. Retrieve public gptkey");
123
+ key = process.env.GPTKEY;
123
124
 
124
- const KB_HTTPREQUEST = {
125
- url: this.API_ENDPOINT + "/" + this.context.projectId + "/kbsettings",
126
- headers: {
127
- 'Content-Type': 'application/json',
128
- 'Authorization': 'JWT ' + this.context.token
129
- },
130
- method: "GET"
125
+ if (!key) {
126
+ await this.#assignAttributes(action, answer);
127
+ if (falseIntent) {
128
+ await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
129
+ callback(true);
130
+ return;
131
+ }
132
+ callback();
133
+ return;
131
134
  }
132
- winston.debug("(DirGptTask) KB_HTTPREQUEST", KB_HTTPREQUEST);
133
-
134
- httpUtils.request(
135
- KB_HTTPREQUEST, async (err, resbody) => {
136
- if (err) {
137
- if (callback) {
138
- console.error("(httprequest) DirGptTask Get KnowledgeBase err:", err.message);
139
- console.error("(httprequest) DirGptTask Get KnowledgeBase full err", err);
140
-
141
- await this.#assignAttributes(action, answer);
142
- if (falseIntent) {
143
- await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
144
- callback(true);
145
- return;
146
- }
147
- callback();
148
- return;
149
- }
150
- } else if (callback) {
151
- winston.debug("(DirGptTask) Get KnowledgeBase settings resbody:", resbody);
152
-
153
- if (!resbody.gptkey) {
154
- await this.#assignAttributes(action, answer);
155
- if (falseIntent) {
156
- await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
157
- callback(true);
158
- return;
159
- }
160
- callback();
161
- return;
162
-
163
- } else {
164
-
165
- winston.debug("(DirGptTask) Key found in KbSettings");
166
-
167
- key = resbody.gptkey;
168
-
169
- let json = {
170
- "model": action.model,
171
- "messages": [
172
- {
173
- "role": "user",
174
- "content": filled_question
175
- }
176
- ],
177
- "max_tokens": action.max_tokens,
178
- "temperature": action.temperature
179
- }
180
-
181
- let message = { role: "", content: "" };
182
- if (action.context) {
183
- message.role = "system";
184
- message.content = action.context;
185
- json.messages.unshift(message);
186
- }
187
- winston.debug("(DirGptTask) json: ", json);
135
+ }
188
136
 
189
- const HTTPREQUEST = {
190
- url: openai_url,
191
- headers: {
192
- 'Content-Type': 'application/json',
193
- 'Authorization': 'Bearer ' + key
194
- },
195
- json: json,
196
- method: 'POST'
197
- }
198
- winston.debug("(DirGptTask) HTTPREQUEST: ", HTTPREQUEST);
199
- httpUtils.request(
200
- HTTPREQUEST, async (err, resbody) => {
201
- if (err) {
202
- console.error("(httprequest) DirGptTask openai err:", err);
203
- console.error("(httprequest) DirGptTask openai err:", err.response.data);
204
- await this.#assignAttributes(action, answer);
205
- if (falseIntent) {
206
- await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
207
- callback(true);
208
- return;
209
- }
210
- callback();
211
- return;
212
- } else {
213
- winston.debug("(DirGptTask) resbody: ", JSON.stringify(resbody));
214
- answer = resbody.choices[0].message.content;
215
- let answer_json = await this.convertToJson(answer);
216
- await this.#assignAttributes(action, answer_json);
217
- if (trueIntent) {
218
- await this.#executeCondition(true, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
219
- callback(true);
220
- return;
221
- }
222
- callback();
223
- return;
224
- }
225
- }
226
- )
227
- }
228
- }
229
- }
230
- )
231
- } else {
137
+ if (key) {
232
138
 
233
- winston.debug("(DirGptTask) Key found in Integrations");
139
+ winston.debug("(DirGptTask) Key found");
234
140
 
235
141
  let json = {
236
142
  "model": action.model,