@tiledesk/tiledesk-tybot-connector 2.0.31 → 2.0.32
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 = {
|
|
@@ -476,6 +496,51 @@ class DirAiPrompt {
|
|
|
476
496
|
})
|
|
477
497
|
}
|
|
478
498
|
|
|
499
|
+
arrayToObject(arr) {
|
|
500
|
+
if (!Array.isArray(arr)) {
|
|
501
|
+
winston.warn("DirAiPrompt Can't process MCP Severs: 'servers' must be an array")
|
|
502
|
+
this.logger.warn("[AI Prompt] Can't process MCP Severs: 'servers' must be an array");
|
|
503
|
+
return null;
|
|
504
|
+
}
|
|
505
|
+
return arr.reduce((acc, item) => {
|
|
506
|
+
const { name, ...rest } = item;
|
|
507
|
+
acc[name] = rest;
|
|
508
|
+
return acc;
|
|
509
|
+
}, {});
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
async detectAttach(source) {
|
|
513
|
+
let mime_type;
|
|
514
|
+
let type;
|
|
515
|
+
|
|
516
|
+
const ext = path.extname(source);
|
|
517
|
+
mime_type = mime.lookup(ext) || "application/octet-stream";
|
|
518
|
+
|
|
519
|
+
if (mime_type === "application/octet-stream") {
|
|
520
|
+
try {
|
|
521
|
+
const res = await axios.head(source);
|
|
522
|
+
if (res.headers["content-type"]) {
|
|
523
|
+
mime_type = res.headers["content-type"];
|
|
524
|
+
}
|
|
525
|
+
} catch (err) {
|
|
526
|
+
mime_type = "application/octet-stream";
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
if (mime_type.startsWith("image/")) type = "image";
|
|
531
|
+
else if (mime_type.startsWith("video/")) type = "video";
|
|
532
|
+
else if (mime_type.startsWith("audio/")) type = "audio";
|
|
533
|
+
else type = "file";
|
|
534
|
+
|
|
535
|
+
return {
|
|
536
|
+
type: type,
|
|
537
|
+
source: source,
|
|
538
|
+
mime_type: mime_type,
|
|
539
|
+
detail: "auto"
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
}
|
|
543
|
+
|
|
479
544
|
}
|
|
480
545
|
|
|
481
546
|
module.exports = { DirAiPrompt }
|