@tiledesk/tiledesk-tybot-connector 2.0.30 → 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiledesk/tiledesk-tybot-connector",
3
- "version": "2.0.30",
3
+ "version": "2.0.32",
4
4
  "description": "Tiledesk Tybot connector",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -211,7 +211,6 @@ class DirectivesChatbotPlug {
211
211
  }
212
212
 
213
213
  async process(directive) {
214
- const t3 = Date.now();
215
214
  let context = this.context;
216
215
  if (directive) {
217
216
  winston.verbose("(DirectivesChatbotPlug) directive['name']: " + directive["name"]);
@@ -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 = await TiledeskChatbotUtil.transcriptJSON(transcript_string);
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 = {
@@ -252,7 +272,7 @@ class DirAiPrompt {
252
272
 
253
273
  if (publicKey === true) {
254
274
  let tokens_usage = {
255
- tokens: resbody.usage.total_token,
275
+ tokens: resbody.prompt_token_info?.total_tokens || 0,
256
276
  model: json.model
257
277
  }
258
278
  quotasService.updateQuote(this.projectId, this.token, tokens_usage);
@@ -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 }