@tiledesk/tiledesk-tybot-connector 2.0.31 → 2.0.33
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
|
@@ -14,6 +14,8 @@ const integrationService = require("../../services/IntegrationService");
|
|
|
14
14
|
const { Logger } = require("../../Logger");
|
|
15
15
|
const assert = require("assert");
|
|
16
16
|
const quotasService = require("../../services/QuotasService");
|
|
17
|
+
const path = require("path");
|
|
18
|
+
const mime = require("mime-types");
|
|
17
19
|
|
|
18
20
|
|
|
19
21
|
class DirAiPrompt {
|
|
@@ -102,7 +104,7 @@ class DirAiPrompt {
|
|
|
102
104
|
winston.debug("DirAiPrompt transcript string: " + transcript_string)
|
|
103
105
|
|
|
104
106
|
if (transcript_string) {
|
|
105
|
-
transcript =
|
|
107
|
+
transcript = TiledeskChatbotUtil.transcriptJSON(transcript_string);
|
|
106
108
|
winston.debug("DirAiPrompt transcript: ", transcript)
|
|
107
109
|
} else {
|
|
108
110
|
this.logger.warn("[AI Prompt] no chat transcript found, skipping history translation");
|
|
@@ -212,6 +214,24 @@ class DirAiPrompt {
|
|
|
212
214
|
|
|
213
215
|
}
|
|
214
216
|
|
|
217
|
+
if (action.attach) {
|
|
218
|
+
json.attach = await this.detectAttach(action.attach);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (action.servers) {
|
|
222
|
+
json.servers = this.arrayToObject(action.servers);
|
|
223
|
+
if (!json.servers) {
|
|
224
|
+
await this.chatbot.addParameter("flowError", "Can't process MCP Servers");
|
|
225
|
+
if (falseIntent) {
|
|
226
|
+
await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
|
|
227
|
+
callback();
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
callback();
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
215
235
|
winston.debug("DirAiPrompt json: ", json);
|
|
216
236
|
|
|
217
237
|
const HTTPREQUEST = {
|
|
@@ -232,8 +252,10 @@ class DirAiPrompt {
|
|
|
232
252
|
error = err.response.data.detail[0]?.msg;
|
|
233
253
|
} else if (err.response?.data?.detail?.answer) {
|
|
234
254
|
error = err.response.data.detail.answer;
|
|
235
|
-
} else {
|
|
255
|
+
} else if (err.response?.data) {
|
|
236
256
|
error = JSON.stringify(err.response.data);
|
|
257
|
+
} else {
|
|
258
|
+
error = err.message || "General error executing action" // String(err);
|
|
237
259
|
}
|
|
238
260
|
this.logger.error("[AI Prompt] error executing action: ", error);
|
|
239
261
|
if (falseIntent) {
|
|
@@ -476,6 +498,51 @@ class DirAiPrompt {
|
|
|
476
498
|
})
|
|
477
499
|
}
|
|
478
500
|
|
|
501
|
+
arrayToObject(arr) {
|
|
502
|
+
if (!Array.isArray(arr)) {
|
|
503
|
+
winston.warn("DirAiPrompt Can't process MCP Severs: 'servers' must be an array")
|
|
504
|
+
this.logger.warn("[AI Prompt] Can't process MCP Severs: 'servers' must be an array");
|
|
505
|
+
return null;
|
|
506
|
+
}
|
|
507
|
+
return arr.reduce((acc, item) => {
|
|
508
|
+
const { name, ...rest } = item;
|
|
509
|
+
acc[name] = rest;
|
|
510
|
+
return acc;
|
|
511
|
+
}, {});
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
async detectAttach(source) {
|
|
515
|
+
let mime_type;
|
|
516
|
+
let type;
|
|
517
|
+
|
|
518
|
+
const ext = path.extname(source);
|
|
519
|
+
mime_type = mime.lookup(ext) || "application/octet-stream";
|
|
520
|
+
|
|
521
|
+
if (mime_type === "application/octet-stream") {
|
|
522
|
+
try {
|
|
523
|
+
const res = await axios.head(source);
|
|
524
|
+
if (res.headers["content-type"]) {
|
|
525
|
+
mime_type = res.headers["content-type"];
|
|
526
|
+
}
|
|
527
|
+
} catch (err) {
|
|
528
|
+
mime_type = "application/octet-stream";
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
if (mime_type.startsWith("image/")) type = "image";
|
|
533
|
+
else if (mime_type.startsWith("video/")) type = "video";
|
|
534
|
+
else if (mime_type.startsWith("audio/")) type = "audio";
|
|
535
|
+
else type = "file";
|
|
536
|
+
|
|
537
|
+
return {
|
|
538
|
+
type: type,
|
|
539
|
+
source: source,
|
|
540
|
+
mime_type: mime_type,
|
|
541
|
+
detail: "auto"
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
}
|
|
545
|
+
|
|
479
546
|
}
|
|
480
547
|
|
|
481
548
|
module.exports = { DirAiPrompt }
|
|
@@ -287,10 +287,11 @@ class DirAskGPTV2 {
|
|
|
287
287
|
}
|
|
288
288
|
|
|
289
289
|
if (!action.advancedPrompt) {
|
|
290
|
+
const contextTemplate = contexts[model] || contexts["general"];
|
|
290
291
|
if (filled_context) {
|
|
291
|
-
json.system_context = filled_context + "\n" +
|
|
292
|
+
json.system_context = filled_context + "\n" + contextTemplate;
|
|
292
293
|
} else {
|
|
293
|
-
json.system_context =
|
|
294
|
+
json.system_context = contextTemplate;
|
|
294
295
|
}
|
|
295
296
|
} else {
|
|
296
297
|
json.system_context = filled_context;
|
|
@@ -908,7 +908,7 @@ class TiledeskChatbotUtil {
|
|
|
908
908
|
winston.debug("(TiledeskChatbotUtil) Adding Globals to context: ", _bot);
|
|
909
909
|
|
|
910
910
|
if (_bot.attributes && _bot.attributes.globals) {
|
|
911
|
-
winston.
|
|
911
|
+
winston.debug("(TiledeskChatbotUtil) Got Globals: ", _bot.attributes.globals);
|
|
912
912
|
_bot.attributes.globals.forEach(async (global_var) => {
|
|
913
913
|
winston.error("(TiledeskChatbotUtil) Adding global: " + global_var.key + " value: " + global_var.value);
|
|
914
914
|
await chatbot.addParameter(global_var.key, global_var.value);
|