@tiledesk/tiledesk-server 2.17.3 → 2.17.4

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/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.17.5
9
+ - Refactor error handling and code structure in webhook.js
10
+
11
+ # 2.17.4
12
+ - Added support for Pinecone Reranking for Standard knowledge bases
13
+
8
14
  # 2.17.3
9
15
  - Added missing import path on kb route
10
16
 
package/archive.sh ADDED
@@ -0,0 +1,92 @@
1
+ #!/bin/bash
2
+
3
+ # ================================
4
+ # Script interattivo per archiviare branch
5
+ # ================================
6
+ # Usage: ./archive-branch.sh [mode]
7
+ # mode: tag (default) | rename
8
+ # ================================
9
+
10
+ REMOTE="tiledesk-server"
11
+ MODE="${1:-tag}" # default mode = tag
12
+
13
+ PROTECTED_BRANCHES=("master" "master-PRE" "master-COLLAUDO" "master-STAGE")
14
+
15
+ # Funzione per scegliere un branch valido
16
+ get_branch_to_archive() {
17
+ local branch="$1"
18
+
19
+ while true; do
20
+ # Se branch protetto, avvisa
21
+ if [[ " ${PROTECTED_BRANCHES[@]} " =~ " ${branch} " ]]; then
22
+ echo "❌ Il branch '$branch' è protetto e non può essere archiviato."
23
+ fi
24
+
25
+ # Controlla che il branch locale esista
26
+ if git show-ref --verify --quiet refs/heads/"$branch"; then
27
+ break # branch valido trovato
28
+ fi
29
+
30
+ # Richiedi input all’utente
31
+ read -p "Inserisci un branch locale valido da archiviare (oppure 'quit' per annullare): " branch
32
+ if [[ "$branch" == "quit" || "$branch" == "q" ]]; then
33
+ echo "Operazione annullata."
34
+ exit 0
35
+ fi
36
+ done
37
+
38
+ echo "$branch"
39
+ }
40
+
41
+ # Branch corrente
42
+ CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
43
+
44
+ # Se branch corrente non è protetto, chiedi conferma
45
+ if [[ ! " ${PROTECTED_BRANCHES[@]} " =~ " ${CURRENT_BRANCH} " ]]; then
46
+ echo "⚡ Branch corrente: $CURRENT_BRANCH"
47
+ read -p "Vuoi archiviare questo branch? (y/n): " CONFIRM
48
+ if [[ "$CONFIRM" != "y" ]]; then
49
+ read -p "Inserisci il branch da archiviare (oppure 'quit' per annullare): " USER_BRANCH
50
+ if [[ "$USER_BRANCH" == "quit" || "$USER_BRANCH" == "q" ]]; then
51
+ echo "Operazione annullata."
52
+ exit 0
53
+ fi
54
+ CURRENT_BRANCH=$(get_branch_to_archive "$USER_BRANCH")
55
+ fi
56
+ else
57
+ # Branch corrente è protetto, chiedi un branch alternativo
58
+ CURRENT_BRANCH=$(get_branch_to_archive "$CURRENT_BRANCH")
59
+ fi
60
+
61
+ # Operazione di archiviazione
62
+ if [ "$MODE" == "tag" ]; then
63
+ ARCHIVE_TAG="archive/$(echo $CURRENT_BRANCH | tr '/' '-')"
64
+ echo "Creando tag di archivio: $ARCHIVE_TAG"
65
+ git tag "$ARCHIVE_TAG" "$CURRENT_BRANCH"
66
+ git push "$REMOTE" "$ARCHIVE_TAG"
67
+
68
+ echo "Eliminando branch remoto $CURRENT_BRANCH"
69
+ git push "$REMOTE" --delete "$CURRENT_BRANCH"
70
+
71
+ echo "Eliminando branch locale $CURRENT_BRANCH"
72
+ git branch -d "$CURRENT_BRANCH"
73
+
74
+ echo "✅ Branch '$CURRENT_BRANCH' archiviato con tag '$ARCHIVE_TAG'"
75
+
76
+ elif [ "$MODE" == "rename" ]; then
77
+ ARCHIVE_BRANCH="archive/$CURRENT_BRANCH"
78
+ echo "Rinomino branch locale in: $ARCHIVE_BRANCH"
79
+ git branch -m "$CURRENT_BRANCH" "$ARCHIVE_BRANCH"
80
+
81
+ echo "Pusho nuovo branch su remote $REMOTE"
82
+ git push "$REMOTE" "$ARCHIVE_BRANCH"
83
+
84
+ echo "Eliminando branch remoto vecchio $CURRENT_BRANCH"
85
+ git push "$REMOTE" --delete "$CURRENT_BRANCH"
86
+
87
+ echo "✅ Branch '$CURRENT_BRANCH' archiviato come '$ARCHIVE_BRANCH'"
88
+
89
+ else
90
+ echo "❌ Modalità non valida. Usa 'tag' o 'rename'."
91
+ exit 1
92
+ fi
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tiledesk/tiledesk-server",
3
3
  "description": "The Tiledesk server module",
4
- "version": "2.17.3",
4
+ "version": "2.17.4",
5
5
  "scripts": {
6
6
  "start": "node ./bin/www",
7
7
  "pretest": "mongodb-runner start",
package/routes/kb.js CHANGED
@@ -26,6 +26,7 @@ const AMQP_MANAGER_URL = process.env.AMQP_MANAGER_URL;
26
26
  const JOB_TOPIC_EXCHANGE = process.env.JOB_TOPIC_EXCHANGE_TRAIN || 'tiledesk-trainer';
27
27
  const JOB_TOPIC_EXCHANGE_HYBRID = process.env.JOB_TOPIC_EXCHANGE_TRAIN_HYBRID || 'tiledesk-trainer-hybrid';
28
28
  const KB_WEBHOOK_TOKEN = process.env.KB_WEBHOOK_TOKEN || 'kbcustomtoken';
29
+ const PINECONE_RERANKING = process.env.PINECONE_RERANKING === true || process.env.PINECONE_RERANKING === "true";
29
30
  const apiUrl = process.env.API_URL || configGlobal.apiUrl;
30
31
 
31
32
 
@@ -408,7 +409,7 @@ router.post('/qa', async (req, res) => {
408
409
  data.search_type = 'hybrid';
409
410
 
410
411
  if (data.reranking === true) {
411
- data.reranker_model = "cross-encoder/ms-marco-MiniLM-L-6-v2";
412
+ data.reranker_model = process.env.RERANKING_MODEL || "cross-encoder/ms-marco-MiniLM-L-6-v2";
412
413
 
413
414
  if (!data.reranking_multiplier) {
414
415
  data.reranking_multiplier = 3;
@@ -422,6 +423,27 @@ router.post('/qa', async (req, res) => {
422
423
  data.reranking_multiplier = calculatedRerankingMultiplier;
423
424
  }
424
425
  }
426
+ }
427
+
428
+ if (!namespace.hybrid && data.reranking === true && PINECONE_RERANKING) {
429
+
430
+ data.reranking = {
431
+ "provider": "pinecone",
432
+ "api_key": process.env.PINECONE_API_KEY,
433
+ "model": process.env.PINECONE_RERANKING_MODEL || process.env.RERANKING_MODEL || "bge-reranker-v2-m3"
434
+ }
435
+
436
+ if (!data.reranking_multiplier) {
437
+ data.reranking_multiplier = 3;
438
+ }
439
+
440
+ if ((data.top_k * data.reranking_multiplier) > 100) {
441
+ let calculatedRerankingMultiplier = Math.floor(100 / data.top_k);
442
+ if (calculatedRerankingMultiplier < 1) {
443
+ calculatedRerankingMultiplier = 1;
444
+ }
445
+ data.reranking_multiplier = calculatedRerankingMultiplier;
446
+ }
425
447
  }
426
448
 
427
449
  data.stream = data.stream === true;
@@ -429,6 +451,8 @@ router.post('/qa', async (req, res) => {
429
451
  delete data.advancedPrompt;
430
452
  winston.verbose("ask data: ", data);
431
453
 
454
+ console.log("data: ", data);
455
+
432
456
  if (process.env.NODE_ENV === 'test') {
433
457
  return res.status(200).send({ success: true, message: "Question skipped in test environment", data: data });
434
458
  }
package/routes/webhook.js CHANGED
@@ -12,7 +12,7 @@ var ObjectId = require('mongoose').Types.ObjectId;
12
12
  const default_embedding = require('../config/kb/embedding');
13
13
 
14
14
  const port = process.env.PORT || '3000';
15
- let TILEBOT_ENDPOINT = "http://localhost:" + port + "/modules/tilebot/";;
15
+ let TILEBOT_ENDPOINT = "http://localhost:" + port + "/modules/tilebot/";
16
16
  if (process.env.TILEBOT_ENDPOINT) {
17
17
  TILEBOT_ENDPOINT = process.env.TILEBOT_ENDPOINT + "/"
18
18
  }
@@ -69,18 +69,12 @@ router.post('/kb/reindex', async (req, res) => {
69
69
 
70
70
  let content_id = req.body.content_id;
71
71
 
72
- let kb = await KB.findById(content_id).catch( async (err) => {
73
- winston.error("(webhook) Error getting kb content: ", err);
74
- return res.status(500).send({ success: false, error: "Error getting content with id " + content_id });
75
- })
76
-
77
- const namespace_id = kb.namespace;
78
- let namespace;
72
+ let kb;
79
73
  try {
80
- namespace = await aiManager.checkNamespace(kb.id_project, namespace_id);
74
+ kb = await KB.findById(content_id);
81
75
  } catch (err) {
82
- let errorCode = err?.errorCode ?? 500;
83
- return res.status(errorCode).send({ success: false, error: err.error });
76
+ winston.error("(webhook) Error getting kb content: ", err);
77
+ return res.status(500).send({ success: false, error: "Error getting content with id " + content_id });
84
78
  }
85
79
 
86
80
  if (!kb) {
@@ -99,8 +93,19 @@ router.post('/kb/reindex', async (req, res) => {
99
93
  winston.verbose("(webhook) delete response: ", deleteResponse);
100
94
  return;
101
95
  }, 10000);
102
-
103
- } else if (kb.type === 'sitemap') {
96
+ return;
97
+ }
98
+
99
+ const namespace_id = kb.namespace;
100
+ let namespace;
101
+ try {
102
+ namespace = await aiManager.checkNamespace(kb.id_project, namespace_id);
103
+ } catch (err) {
104
+ let errorCode = err?.errorCode ?? 500;
105
+ return res.status(errorCode).send({ success: false, error: err.error });
106
+ }
107
+
108
+ if (kb.type === 'sitemap') {
104
109
 
105
110
  const urls = await aiManager.fetchSitemap(kb.source).catch((err) => {
106
111
  winston.error("(webhook) Error fetching sitemap: ", err);