strapi-plugin-faqchatbot 1.0.2 → 1.0.3
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.
|
@@ -24975,7 +24975,7 @@ const ChatWindowWrapper = styled__default.default(designSystem.Box)`
|
|
|
24975
24975
|
height: 500px;
|
|
24976
24976
|
z-index: 1000;
|
|
24977
24977
|
overflow: hidden;
|
|
24978
|
-
box-shadow: 0 10px 40px rgba(0,0,0,0.2);
|
|
24978
|
+
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
|
|
24979
24979
|
border: 1px solid ${({ theme }) => theme.colors.neutral150};
|
|
24980
24980
|
transform-origin: bottom right;
|
|
24981
24981
|
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
|
@@ -25023,7 +25023,7 @@ const ChatbotPreview = () => {
|
|
|
25023
25023
|
setMessages((prev) => [...prev, { text: userText, isUser: true }]);
|
|
25024
25024
|
setChatInput("");
|
|
25025
25025
|
try {
|
|
25026
|
-
const res = await fetch("/api/faqchatbot/ask", {
|
|
25026
|
+
const res = await fetch("/api/faqchatbot-config/ask", {
|
|
25027
25027
|
method: "POST",
|
|
25028
25028
|
headers: { "Content-Type": "application/json" },
|
|
25029
25029
|
body: JSON.stringify({ question: userText })
|
|
@@ -25031,27 +25031,29 @@ const ChatbotPreview = () => {
|
|
|
25031
25031
|
if (!res.ok) throw new Error("Request failed");
|
|
25032
25032
|
const reader = res.body?.getReader();
|
|
25033
25033
|
if (!reader) throw new Error("No stream");
|
|
25034
|
+
const decoder = new TextDecoder();
|
|
25034
25035
|
let botMessage = "";
|
|
25035
|
-
let doneStream = false;
|
|
25036
25036
|
setMessages((prev) => [...prev, { text: "", isUser: false }]);
|
|
25037
|
-
while (
|
|
25037
|
+
while (true) {
|
|
25038
25038
|
const { done, value } = await reader.read();
|
|
25039
25039
|
if (done) break;
|
|
25040
|
-
const chunk =
|
|
25040
|
+
const chunk = decoder.decode(value, { stream: true });
|
|
25041
25041
|
const lines = chunk.split("\n");
|
|
25042
|
-
for (
|
|
25043
|
-
|
|
25044
|
-
|
|
25045
|
-
if (
|
|
25046
|
-
|
|
25047
|
-
|
|
25042
|
+
for (let rawLine of lines) {
|
|
25043
|
+
const line = rawLine.replace(/\r/g, "");
|
|
25044
|
+
if (line.includes("[DONE]")) return;
|
|
25045
|
+
if (line.startsWith("data: ")) {
|
|
25046
|
+
const token = line.replace("data: ", "");
|
|
25047
|
+
botMessage += token;
|
|
25048
|
+
setMessages((prev) => {
|
|
25049
|
+
const updated = [...prev];
|
|
25050
|
+
updated[updated.length - 1] = {
|
|
25051
|
+
text: botMessage,
|
|
25052
|
+
isUser: false
|
|
25053
|
+
};
|
|
25054
|
+
return updated;
|
|
25055
|
+
});
|
|
25048
25056
|
}
|
|
25049
|
-
botMessage += text;
|
|
25050
|
-
setMessages((prev) => {
|
|
25051
|
-
const updated = [...prev];
|
|
25052
|
-
updated[updated.length - 1] = { text: botMessage, isUser: false };
|
|
25053
|
-
return updated;
|
|
25054
|
-
});
|
|
25055
25057
|
}
|
|
25056
25058
|
}
|
|
25057
25059
|
} catch (err) {
|
|
@@ -25068,14 +25070,74 @@ const ChatbotPreview = () => {
|
|
|
25068
25070
|
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, children: [
|
|
25069
25071
|
/* @__PURE__ */ jsxRuntime.jsx(icons.Message, { color: "neutral0", width: 18 }),
|
|
25070
25072
|
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { fontWeight: "bold", textColor: "neutral0", children: "Chatbot Preview" }),
|
|
25071
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
25073
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
25074
|
+
designSystem.Box,
|
|
25075
|
+
{
|
|
25076
|
+
as: "button",
|
|
25077
|
+
onClick: handleClearHistory,
|
|
25078
|
+
style: { background: "none", border: "none", cursor: "pointer", display: "flex" },
|
|
25079
|
+
title: "Clear History",
|
|
25080
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowClockwise, { color: "neutral0", width: 14 })
|
|
25081
|
+
}
|
|
25082
|
+
)
|
|
25072
25083
|
] }),
|
|
25073
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
25084
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
25085
|
+
designSystem.Box,
|
|
25086
|
+
{
|
|
25087
|
+
as: "button",
|
|
25088
|
+
onClick: () => setIsOpen(false),
|
|
25089
|
+
style: { background: "none", border: "none", cursor: "pointer", display: "flex" },
|
|
25090
|
+
title: "Close Chat",
|
|
25091
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(icons.Cross, { color: "neutral0", width: 14 })
|
|
25092
|
+
}
|
|
25093
|
+
)
|
|
25074
25094
|
] }) }),
|
|
25075
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
25095
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
25096
|
+
designSystem.Box,
|
|
25097
|
+
{
|
|
25098
|
+
ref: scrollRef,
|
|
25099
|
+
padding: 4,
|
|
25100
|
+
background: "neutral100",
|
|
25101
|
+
style: { flex: 1, overflowY: "auto" },
|
|
25102
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 3, children: messages.map((msg, idx) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
25103
|
+
designSystem.Box,
|
|
25104
|
+
{
|
|
25105
|
+
padding: 3,
|
|
25106
|
+
hasRadius: true,
|
|
25107
|
+
background: msg.isUser ? "primary600" : "neutral0",
|
|
25108
|
+
shadow: "filterShadow",
|
|
25109
|
+
style: {
|
|
25110
|
+
alignSelf: msg.isUser ? "flex-end" : "flex-start",
|
|
25111
|
+
maxWidth: "85%",
|
|
25112
|
+
wordBreak: "break-word",
|
|
25113
|
+
overflowWrap: "anywhere",
|
|
25114
|
+
whiteSpace: "pre-wrap"
|
|
25115
|
+
},
|
|
25116
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: msg.isUser ? "neutral0" : "neutral800", children: msg.text })
|
|
25117
|
+
},
|
|
25118
|
+
idx
|
|
25119
|
+
)) })
|
|
25120
|
+
}
|
|
25121
|
+
),
|
|
25076
25122
|
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { padding: 3, background: "neutral0", style: { borderTop: "1px solid #f0f0f5" }, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, alignItems: "center", children: [
|
|
25077
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { style: { flexGrow: 1 }, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
25078
|
-
|
|
25123
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { style: { flexGrow: 1 }, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
25124
|
+
designSystem.TextInput,
|
|
25125
|
+
{
|
|
25126
|
+
placeholder: "Type a message...",
|
|
25127
|
+
value: chatInput,
|
|
25128
|
+
onChange: (e2) => setChatInput(e2.target.value),
|
|
25129
|
+
onKeyDown: (e2) => e2.key === "Enter" && handleSendMessage()
|
|
25130
|
+
}
|
|
25131
|
+
) }),
|
|
25132
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
25133
|
+
designSystem.Button,
|
|
25134
|
+
{
|
|
25135
|
+
onClick: handleSendMessage,
|
|
25136
|
+
style: { height: "40px" },
|
|
25137
|
+
startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.PaperPlane, {}),
|
|
25138
|
+
children: "Send"
|
|
25139
|
+
}
|
|
25140
|
+
)
|
|
25079
25141
|
] }) })
|
|
25080
25142
|
] }) })
|
|
25081
25143
|
] });
|
|
@@ -24974,7 +24974,7 @@ const ChatWindowWrapper = styled$1(Box)`
|
|
|
24974
24974
|
height: 500px;
|
|
24975
24975
|
z-index: 1000;
|
|
24976
24976
|
overflow: hidden;
|
|
24977
|
-
box-shadow: 0 10px 40px rgba(0,0,0,0.2);
|
|
24977
|
+
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
|
|
24978
24978
|
border: 1px solid ${({ theme }) => theme.colors.neutral150};
|
|
24979
24979
|
transform-origin: bottom right;
|
|
24980
24980
|
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
|
@@ -25022,7 +25022,7 @@ const ChatbotPreview = () => {
|
|
|
25022
25022
|
setMessages((prev) => [...prev, { text: userText, isUser: true }]);
|
|
25023
25023
|
setChatInput("");
|
|
25024
25024
|
try {
|
|
25025
|
-
const res = await fetch("/api/faqchatbot/ask", {
|
|
25025
|
+
const res = await fetch("/api/faqchatbot-config/ask", {
|
|
25026
25026
|
method: "POST",
|
|
25027
25027
|
headers: { "Content-Type": "application/json" },
|
|
25028
25028
|
body: JSON.stringify({ question: userText })
|
|
@@ -25030,27 +25030,29 @@ const ChatbotPreview = () => {
|
|
|
25030
25030
|
if (!res.ok) throw new Error("Request failed");
|
|
25031
25031
|
const reader = res.body?.getReader();
|
|
25032
25032
|
if (!reader) throw new Error("No stream");
|
|
25033
|
+
const decoder = new TextDecoder();
|
|
25033
25034
|
let botMessage = "";
|
|
25034
|
-
let doneStream = false;
|
|
25035
25035
|
setMessages((prev) => [...prev, { text: "", isUser: false }]);
|
|
25036
|
-
while (
|
|
25036
|
+
while (true) {
|
|
25037
25037
|
const { done, value } = await reader.read();
|
|
25038
25038
|
if (done) break;
|
|
25039
|
-
const chunk =
|
|
25039
|
+
const chunk = decoder.decode(value, { stream: true });
|
|
25040
25040
|
const lines = chunk.split("\n");
|
|
25041
|
-
for (
|
|
25042
|
-
|
|
25043
|
-
|
|
25044
|
-
if (
|
|
25045
|
-
|
|
25046
|
-
|
|
25041
|
+
for (let rawLine of lines) {
|
|
25042
|
+
const line = rawLine.replace(/\r/g, "");
|
|
25043
|
+
if (line.includes("[DONE]")) return;
|
|
25044
|
+
if (line.startsWith("data: ")) {
|
|
25045
|
+
const token = line.replace("data: ", "");
|
|
25046
|
+
botMessage += token;
|
|
25047
|
+
setMessages((prev) => {
|
|
25048
|
+
const updated = [...prev];
|
|
25049
|
+
updated[updated.length - 1] = {
|
|
25050
|
+
text: botMessage,
|
|
25051
|
+
isUser: false
|
|
25052
|
+
};
|
|
25053
|
+
return updated;
|
|
25054
|
+
});
|
|
25047
25055
|
}
|
|
25048
|
-
botMessage += text;
|
|
25049
|
-
setMessages((prev) => {
|
|
25050
|
-
const updated = [...prev];
|
|
25051
|
-
updated[updated.length - 1] = { text: botMessage, isUser: false };
|
|
25052
|
-
return updated;
|
|
25053
|
-
});
|
|
25054
25056
|
}
|
|
25055
25057
|
}
|
|
25056
25058
|
} catch (err) {
|
|
@@ -25067,14 +25069,74 @@ const ChatbotPreview = () => {
|
|
|
25067
25069
|
/* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
|
|
25068
25070
|
/* @__PURE__ */ jsx(Message, { color: "neutral0", width: 18 }),
|
|
25069
25071
|
/* @__PURE__ */ jsx(Typography, { fontWeight: "bold", textColor: "neutral0", children: "Chatbot Preview" }),
|
|
25070
|
-
/* @__PURE__ */ jsx(
|
|
25072
|
+
/* @__PURE__ */ jsx(
|
|
25073
|
+
Box,
|
|
25074
|
+
{
|
|
25075
|
+
as: "button",
|
|
25076
|
+
onClick: handleClearHistory,
|
|
25077
|
+
style: { background: "none", border: "none", cursor: "pointer", display: "flex" },
|
|
25078
|
+
title: "Clear History",
|
|
25079
|
+
children: /* @__PURE__ */ jsx(ArrowClockwise, { color: "neutral0", width: 14 })
|
|
25080
|
+
}
|
|
25081
|
+
)
|
|
25071
25082
|
] }),
|
|
25072
|
-
/* @__PURE__ */ jsx(
|
|
25083
|
+
/* @__PURE__ */ jsx(
|
|
25084
|
+
Box,
|
|
25085
|
+
{
|
|
25086
|
+
as: "button",
|
|
25087
|
+
onClick: () => setIsOpen(false),
|
|
25088
|
+
style: { background: "none", border: "none", cursor: "pointer", display: "flex" },
|
|
25089
|
+
title: "Close Chat",
|
|
25090
|
+
children: /* @__PURE__ */ jsx(Cross, { color: "neutral0", width: 14 })
|
|
25091
|
+
}
|
|
25092
|
+
)
|
|
25073
25093
|
] }) }),
|
|
25074
|
-
/* @__PURE__ */ jsx(
|
|
25094
|
+
/* @__PURE__ */ jsx(
|
|
25095
|
+
Box,
|
|
25096
|
+
{
|
|
25097
|
+
ref: scrollRef,
|
|
25098
|
+
padding: 4,
|
|
25099
|
+
background: "neutral100",
|
|
25100
|
+
style: { flex: 1, overflowY: "auto" },
|
|
25101
|
+
children: /* @__PURE__ */ jsx(Flex, { direction: "column", alignItems: "stretch", gap: 3, children: messages.map((msg, idx) => /* @__PURE__ */ jsx(
|
|
25102
|
+
Box,
|
|
25103
|
+
{
|
|
25104
|
+
padding: 3,
|
|
25105
|
+
hasRadius: true,
|
|
25106
|
+
background: msg.isUser ? "primary600" : "neutral0",
|
|
25107
|
+
shadow: "filterShadow",
|
|
25108
|
+
style: {
|
|
25109
|
+
alignSelf: msg.isUser ? "flex-end" : "flex-start",
|
|
25110
|
+
maxWidth: "85%",
|
|
25111
|
+
wordBreak: "break-word",
|
|
25112
|
+
overflowWrap: "anywhere",
|
|
25113
|
+
whiteSpace: "pre-wrap"
|
|
25114
|
+
},
|
|
25115
|
+
children: /* @__PURE__ */ jsx(Typography, { textColor: msg.isUser ? "neutral0" : "neutral800", children: msg.text })
|
|
25116
|
+
},
|
|
25117
|
+
idx
|
|
25118
|
+
)) })
|
|
25119
|
+
}
|
|
25120
|
+
),
|
|
25075
25121
|
/* @__PURE__ */ jsx(Box, { padding: 3, background: "neutral0", style: { borderTop: "1px solid #f0f0f5" }, children: /* @__PURE__ */ jsxs(Flex, { gap: 2, alignItems: "center", children: [
|
|
25076
|
-
/* @__PURE__ */ jsx(Box, { style: { flexGrow: 1 }, children: /* @__PURE__ */ jsx(
|
|
25077
|
-
|
|
25122
|
+
/* @__PURE__ */ jsx(Box, { style: { flexGrow: 1 }, children: /* @__PURE__ */ jsx(
|
|
25123
|
+
TextInput,
|
|
25124
|
+
{
|
|
25125
|
+
placeholder: "Type a message...",
|
|
25126
|
+
value: chatInput,
|
|
25127
|
+
onChange: (e2) => setChatInput(e2.target.value),
|
|
25128
|
+
onKeyDown: (e2) => e2.key === "Enter" && handleSendMessage()
|
|
25129
|
+
}
|
|
25130
|
+
) }),
|
|
25131
|
+
/* @__PURE__ */ jsx(
|
|
25132
|
+
Button,
|
|
25133
|
+
{
|
|
25134
|
+
onClick: handleSendMessage,
|
|
25135
|
+
style: { height: "40px" },
|
|
25136
|
+
startIcon: /* @__PURE__ */ jsx(PaperPlane, {}),
|
|
25137
|
+
children: "Send"
|
|
25138
|
+
}
|
|
25139
|
+
)
|
|
25078
25140
|
] }) })
|
|
25079
25141
|
] }) })
|
|
25080
25142
|
] });
|
package/dist/admin/index.js
CHANGED
|
@@ -26,7 +26,7 @@ const Initializer = ({ setPlugin }) => {
|
|
|
26
26
|
}, []);
|
|
27
27
|
return null;
|
|
28
28
|
};
|
|
29
|
-
const PluginIcon = () => /* @__PURE__ */ jsxRuntime.jsx(icons.
|
|
29
|
+
const PluginIcon = () => /* @__PURE__ */ jsxRuntime.jsx(icons.Discuss, {});
|
|
30
30
|
const index = {
|
|
31
31
|
register(app) {
|
|
32
32
|
app.addMenuLink({
|
|
@@ -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-
|
|
40
|
+
const { App } = await Promise.resolve().then(() => require("../_chunks/App-DXMGIi8p.js"));
|
|
41
41
|
return App;
|
|
42
42
|
}
|
|
43
43
|
});
|
package/dist/admin/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useRef, useEffect } from "react";
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
|
-
import {
|
|
3
|
+
import { Discuss } from "@strapi/icons";
|
|
4
4
|
const __variableDynamicImportRuntimeHelper = (glob, path, segs) => {
|
|
5
5
|
const v = glob[path];
|
|
6
6
|
if (v) {
|
|
@@ -25,7 +25,7 @@ const Initializer = ({ setPlugin }) => {
|
|
|
25
25
|
}, []);
|
|
26
26
|
return null;
|
|
27
27
|
};
|
|
28
|
-
const PluginIcon = () => /* @__PURE__ */ jsx(
|
|
28
|
+
const PluginIcon = () => /* @__PURE__ */ jsx(Discuss, {});
|
|
29
29
|
const index = {
|
|
30
30
|
register(app) {
|
|
31
31
|
app.addMenuLink({
|
|
@@ -36,7 +36,7 @@ const index = {
|
|
|
36
36
|
defaultMessage: PLUGIN_ID
|
|
37
37
|
},
|
|
38
38
|
Component: async () => {
|
|
39
|
-
const { App } = await import("../_chunks/App-
|
|
39
|
+
const { App } = await import("../_chunks/App-Dq5zlyVl.mjs");
|
|
40
40
|
return App;
|
|
41
41
|
}
|
|
42
42
|
});
|
package/package.json
CHANGED