strapi-plugin-faqchatbot 1.0.1 → 1.0.2

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.
@@ -25026,20 +25026,36 @@ const ChatbotPreview = () => {
25026
25026
  const res = await fetch("/api/faqchatbot/ask", {
25027
25027
  method: "POST",
25028
25028
  headers: { "Content-Type": "application/json" },
25029
- body: JSON.stringify({
25030
- question: userText
25031
- })
25029
+ body: JSON.stringify({ question: userText })
25032
25030
  });
25033
- const data = await res.json();
25034
- setMessages((prev) => [
25035
- ...prev,
25036
- { text: data.content || "No response", isUser: false }
25037
- ]);
25031
+ if (!res.ok) throw new Error("Request failed");
25032
+ const reader = res.body?.getReader();
25033
+ if (!reader) throw new Error("No stream");
25034
+ let botMessage = "";
25035
+ let doneStream = false;
25036
+ setMessages((prev) => [...prev, { text: "", isUser: false }]);
25037
+ while (!doneStream) {
25038
+ const { done, value } = await reader.read();
25039
+ if (done) break;
25040
+ const chunk = new TextDecoder().decode(value);
25041
+ const lines = chunk.split("\n");
25042
+ for (const line of lines) {
25043
+ if (!line.startsWith("data: ")) continue;
25044
+ const text = line.replace("data: ", "").trim();
25045
+ if (text === "[DONE]") {
25046
+ doneStream = true;
25047
+ break;
25048
+ }
25049
+ botMessage += text;
25050
+ setMessages((prev) => {
25051
+ const updated = [...prev];
25052
+ updated[updated.length - 1] = { text: botMessage, isUser: false };
25053
+ return updated;
25054
+ });
25055
+ }
25056
+ }
25038
25057
  } catch (err) {
25039
- setMessages((prev) => [
25040
- ...prev,
25041
- { text: "Error contacting chatbot", isUser: false }
25042
- ]);
25058
+ setMessages((prev) => [...prev, { text: "Error contacting chatbot", isUser: false }]);
25043
25059
  }
25044
25060
  };
25045
25061
  const handleClearHistory = () => {
@@ -25025,20 +25025,36 @@ const ChatbotPreview = () => {
25025
25025
  const res = await fetch("/api/faqchatbot/ask", {
25026
25026
  method: "POST",
25027
25027
  headers: { "Content-Type": "application/json" },
25028
- body: JSON.stringify({
25029
- question: userText
25030
- })
25028
+ body: JSON.stringify({ question: userText })
25031
25029
  });
25032
- const data = await res.json();
25033
- setMessages((prev) => [
25034
- ...prev,
25035
- { text: data.content || "No response", isUser: false }
25036
- ]);
25030
+ if (!res.ok) throw new Error("Request failed");
25031
+ const reader = res.body?.getReader();
25032
+ if (!reader) throw new Error("No stream");
25033
+ let botMessage = "";
25034
+ let doneStream = false;
25035
+ setMessages((prev) => [...prev, { text: "", isUser: false }]);
25036
+ while (!doneStream) {
25037
+ const { done, value } = await reader.read();
25038
+ if (done) break;
25039
+ const chunk = new TextDecoder().decode(value);
25040
+ const lines = chunk.split("\n");
25041
+ for (const line of lines) {
25042
+ if (!line.startsWith("data: ")) continue;
25043
+ const text = line.replace("data: ", "").trim();
25044
+ if (text === "[DONE]") {
25045
+ doneStream = true;
25046
+ break;
25047
+ }
25048
+ botMessage += text;
25049
+ setMessages((prev) => {
25050
+ const updated = [...prev];
25051
+ updated[updated.length - 1] = { text: botMessage, isUser: false };
25052
+ return updated;
25053
+ });
25054
+ }
25055
+ }
25037
25056
  } catch (err) {
25038
- setMessages((prev) => [
25039
- ...prev,
25040
- { text: "Error contacting chatbot", isUser: false }
25041
- ]);
25057
+ setMessages((prev) => [...prev, { text: "Error contacting chatbot", isUser: false }]);
25042
25058
  }
25043
25059
  };
25044
25060
  const handleClearHistory = () => {
@@ -37,7 +37,7 @@ const index = {
37
37
  defaultMessage: PLUGIN_ID
38
38
  },
39
39
  Component: async () => {
40
- const { App } = await Promise.resolve().then(() => require("../_chunks/App-Cn0wk9Bd.js"));
40
+ const { App } = await Promise.resolve().then(() => require("../_chunks/App-BegikOzF.js"));
41
41
  return App;
42
42
  }
43
43
  });
@@ -36,7 +36,7 @@ const index = {
36
36
  defaultMessage: PLUGIN_ID
37
37
  },
38
38
  Component: async () => {
39
- const { App } = await import("../_chunks/App-B02Agl-6.mjs");
39
+ const { App } = await import("../_chunks/App-_ybXHESK.mjs");
40
40
  return App;
41
41
  }
42
42
  });
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.1",
2
+ "version": "1.0.2",
3
3
  "keywords": [],
4
4
  "type": "commonjs",
5
5
  "main": "dist/server/index.js",