@a.izzuddin/ai-chat 0.2.21 → 0.2.22-beta.1

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.
@@ -943,7 +943,7 @@
943
943
  }
944
944
  }
945
945
  ],
946
- "description": "Normalize suggested questions - handles multiple formats:\r\n- Objects with question_text (legacy format)\r\n- Objects with Id/QuestionType (new API format - question_text will be fetched)\r\n- String arrays (legacy format)"
946
+ "description": "Normalize suggested questions - handles multiple formats:\r\n- Objects with question_text (legacy format)\r\n- Objects with Id/QuestionType (new API format - question_text will be fetched)\r\n- String arrays (legacy format)\r\n- Nested format with question and related_questions (new API format - only extracts main questions)"
947
947
  },
948
948
  {
949
949
  "kind": "method",
package/dist/index.d.mts CHANGED
@@ -216,6 +216,7 @@ declare class AIChat extends LitElement {
216
216
  * - Objects with question_text (legacy format)
217
217
  * - Objects with Id/QuestionType (new API format - question_text will be fetched)
218
218
  * - String arrays (legacy format)
219
+ * - Nested format with question and related_questions (new API format - only extracts main questions)
219
220
  */
220
221
  private normalizeSuggestedQuestions;
221
222
  private handleInput;
package/dist/index.d.ts CHANGED
@@ -216,6 +216,7 @@ declare class AIChat extends LitElement {
216
216
  * - Objects with question_text (legacy format)
217
217
  * - Objects with Id/QuestionType (new API format - question_text will be fetched)
218
218
  * - String arrays (legacy format)
219
+ * - Nested format with question and related_questions (new API format - only extracts main questions)
219
220
  */
220
221
  private normalizeSuggestedQuestions;
221
222
  private handleInput;
package/dist/index.js CHANGED
@@ -5373,7 +5373,7 @@ MarkdownIt.prototype.renderInline = function(src, env) {
5373
5373
  var lib_default = MarkdownIt;
5374
5374
 
5375
5375
  // src/components/ai-chat.ts
5376
- console.log("Chatbot Ver = 0.2.21-beta.2");
5376
+ console.log("Chatbot Ver = 0.2.22-beta.0");
5377
5377
  var md = new lib_default({
5378
5378
  html: false,
5379
5379
  // Disable HTML tags in source for security
@@ -5569,11 +5569,26 @@ ${this.welcomeSubtitle}` : this.welcomeMessage;
5569
5569
  * - Objects with question_text (legacy format)
5570
5570
  * - Objects with Id/QuestionType (new API format - question_text will be fetched)
5571
5571
  * - String arrays (legacy format)
5572
+ * - Nested format with question and related_questions (new API format - only extracts main questions)
5572
5573
  */
5573
5574
  normalizeSuggestedQuestions(questions) {
5574
5575
  if (!questions || !Array.isArray(questions) || questions.length === 0) {
5575
5576
  return void 0;
5576
5577
  }
5578
+ if (typeof questions[0] === "object" && questions[0].question && questions[0].related_questions) {
5579
+ const mainQuestions = [];
5580
+ questions.forEach((item) => {
5581
+ if (item.question) {
5582
+ mainQuestions.push({
5583
+ id: item.question.id,
5584
+ question_type: item.question.question_type,
5585
+ question_text: item.question.question_text,
5586
+ category: item.question.category
5587
+ });
5588
+ }
5589
+ });
5590
+ return mainQuestions.length > 0 ? mainQuestions : void 0;
5591
+ }
5577
5592
  if (typeof questions[0] === "object" && questions[0].question_text) {
5578
5593
  return questions;
5579
5594
  }
@@ -5703,7 +5718,7 @@ ${this.welcomeSubtitle}` : this.welcomeMessage;
5703
5718
  } else {
5704
5719
  baseUrl = "http://43.217.183.120:8080";
5705
5720
  }
5706
- const url = `${baseUrl}/api/questions/${questionId}?question_type=${questionType}`;
5721
+ const url = `${baseUrl}/api/questions/${questionId}?question_type=${questionType}&language=${this.language}`;
5707
5722
  const response = await fetch(url, {
5708
5723
  method: "GET",
5709
5724
  headers: { "Content-Type": "application/json" }
@@ -5794,6 +5809,7 @@ ${this.welcomeSubtitle}` : this.welcomeMessage;
5794
5809
  let faqs = void 0;
5795
5810
  let suggestedQuestions = void 0;
5796
5811
  let confidence = void 0;
5812
+ let responseLanguage = void 0;
5797
5813
  if (data && typeof data === "object" && data.response && typeof data.response === "string") {
5798
5814
  const trimmedResponse = data.response.trim();
5799
5815
  if (trimmedResponse.startsWith("{") || trimmedResponse.startsWith("[")) {
@@ -5804,11 +5820,13 @@ ${this.welcomeSubtitle}` : this.welcomeMessage;
5804
5820
  faqs = innerData.faq_used || innerData.faqs_used || void 0;
5805
5821
  suggestedQuestions = this.normalizeSuggestedQuestions(innerData.suggested_follow_ups || innerData.suggested_questions);
5806
5822
  confidence = innerData.confident || innerData.confidence || "true";
5823
+ responseLanguage = innerData.language || void 0;
5807
5824
  } else {
5808
5825
  responseText = data.response;
5809
5826
  faqs = data.faq_used || data.faqs_used || void 0;
5810
5827
  suggestedQuestions = this.normalizeSuggestedQuestions(data.suggested_follow_ups || data.suggested_questions);
5811
5828
  confidence = data.confident || data.confidence || void 0;
5829
+ responseLanguage = data.language || void 0;
5812
5830
  }
5813
5831
  } catch (parseError) {
5814
5832
  const responsePattern = /"response"\s*:\s*"([^"]*(?:\\.[^"]*)*)"/s;
@@ -5860,6 +5878,7 @@ ${this.welcomeSubtitle}` : this.welcomeMessage;
5860
5878
  faqs = data.faq_used || data.faqs_used || void 0;
5861
5879
  suggestedQuestions = this.normalizeSuggestedQuestions(data.suggested_follow_ups || data.suggested_questions);
5862
5880
  confidence = data.confident || data.confidence || void 0;
5881
+ responseLanguage = data.language || void 0;
5863
5882
  }
5864
5883
  } else if (typeof data === "string") {
5865
5884
  responseText = data;
@@ -5868,6 +5887,7 @@ ${this.welcomeSubtitle}` : this.welcomeMessage;
5868
5887
  faqs = data.faq_used || data.faqs_used || void 0;
5869
5888
  suggestedQuestions = this.normalizeSuggestedQuestions(data.suggested_follow_ups || data.suggested_questions);
5870
5889
  confidence = data.confident || data.confidence || void 0;
5890
+ responseLanguage = data.language || void 0;
5871
5891
  }
5872
5892
  if (suggestedQuestions && suggestedQuestions.length > 0) {
5873
5893
  const questionsNeedingText = suggestedQuestions.filter(
@@ -5887,6 +5907,9 @@ ${this.welcomeSubtitle}` : this.welcomeMessage;
5887
5907
  ];
5888
5908
  }
5889
5909
  }
5910
+ if (responseLanguage) {
5911
+ this.language = responseLanguage;
5912
+ }
5890
5913
  const assistantMessage = {
5891
5914
  id: (Date.now() + 1).toString(),
5892
5915
  role: "assistant",