@smarter.sh/ui-chat 0.2.4 → 0.2.5
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/dist/smarter-chat-library.es.js +2449 -2427
- package/dist/smarter-chat-library.es.js.map +1 -1
- package/dist/smarter-chat-library.umd.js +39 -39
- package/dist/smarter-chat-library.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/components/SmarterChat/Component.jsx +22 -15
- package/src/components/SmarterChat/api.js +4 -2
- package/src/components/SmarterChat/utils.jsx +2 -1
- /package/src/components/SmarterChat/{errorBoundary.jsx → ErrorBoundary.jsx} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smarter.sh/ui-chat",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"description": "chatbot React.js component for the https://smarter.sh no-code, plugin based AI platform",
|
|
5
5
|
"homepage": "https://smarter.sh",
|
|
6
6
|
"main": "dist/smarter-chat-library.umd.js",
|
|
@@ -48,15 +48,17 @@ const DEBUG_MODE = false;
|
|
|
48
48
|
// managing the chat message thread, sending messages to the backend
|
|
49
49
|
// Api, and rendering the chat UI.
|
|
50
50
|
function SmarterChat({
|
|
51
|
-
apiUrl,
|
|
52
|
-
apiKey,
|
|
53
|
-
toggleMetadata,
|
|
54
|
-
csrfCookieName,
|
|
55
|
-
debugCookieName,
|
|
56
|
-
debugCookieExpiration,
|
|
57
|
-
sessionCookieName,
|
|
58
|
-
sessionCookieExpiration,
|
|
59
|
-
|
|
51
|
+
apiUrl, // the URL of the Smarter chatbot API. example: https://smarter.3141-5926-5359.beta.api.smarter.sh/
|
|
52
|
+
apiKey, // NOT USED. TO DELETE.
|
|
53
|
+
toggleMetadata, // show/hide toggle button to show/hide the chat thread metadata
|
|
54
|
+
csrfCookieName, // the Django CSRF cookie.
|
|
55
|
+
debugCookieName, // the Smarter chat debug cookie. Set here.
|
|
56
|
+
debugCookieExpiration, // the Smarter chat debug cookie. Set here.
|
|
57
|
+
sessionCookieName, // the Smarter chat session cookie. Set here, where the user creates a new chat session.
|
|
58
|
+
sessionCookieExpiration, // the Smarter chat session cookie. Set here, where the user creates a new chat session.
|
|
59
|
+
authSessionCookieName, // the Django session cookie. Set when the user logs in to the Smarter web console app.
|
|
60
|
+
showConsole=true, // show the server console log component
|
|
61
|
+
cookieDomain // the domain of the cookie. This is added to the cookie meta data, but it is not used.
|
|
60
62
|
}) {
|
|
61
63
|
|
|
62
64
|
const [configApiUrl, setConfigApiUrl] = useState(apiUrl);
|
|
@@ -90,13 +92,18 @@ function SmarterChat({
|
|
|
90
92
|
const fileInputRef = useRef(null);
|
|
91
93
|
|
|
92
94
|
// cookie management
|
|
93
|
-
const csrfCookie = cookieMetaFactory(csrfCookieName, null); // we read this but never set it.
|
|
94
|
-
const
|
|
95
|
-
const
|
|
95
|
+
const csrfCookie = cookieMetaFactory(csrfCookieName, null, cookieDomain); // we read this but never set it.
|
|
96
|
+
const authTokenCookie = cookieMetaFactory(authSessionCookieName, null, cookieDomain); // we read this but never set it.
|
|
97
|
+
const sessionCookie = cookieMetaFactory(sessionCookieName, sessionCookieExpiration, cookieDomain);
|
|
98
|
+
const debugCookie = cookieMetaFactory(debugCookieName, debugCookieExpiration, cookieDomain);
|
|
96
99
|
const cookies = {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
+
authTokenCookie: authTokenCookie, // the Django session cookie. Set when the user logs in to the Smarter web console app.
|
|
101
|
+
// typically this is not required for the chat app when running inside the
|
|
102
|
+
// Smarter web console workbench, since it is already authenticated.
|
|
103
|
+
|
|
104
|
+
csrfCookie: csrfCookie, // the Django CSRF cookie. This is required for requests to the Smarter web console workbench.
|
|
105
|
+
sessionCookie: sessionCookie, // the Smarter chat session cookie. Set here, where the user creates a new chat session.
|
|
106
|
+
debugCookie: debugCookie, // the Smarter chat debug cookie. Set here. Controls browser console logging.
|
|
100
107
|
};
|
|
101
108
|
|
|
102
109
|
|
|
@@ -101,9 +101,9 @@ function requestHeadersFactory(cookies) {
|
|
|
101
101
|
|
|
102
102
|
const requestCookies = getRequestCookies(cookies);
|
|
103
103
|
const csrftoken = getCookie(cookies.csrfCookie, "");
|
|
104
|
-
const authToken =
|
|
104
|
+
const authToken = getCookie(cookies.authTokenCookie, "");
|
|
105
105
|
|
|
106
|
-
|
|
106
|
+
const requestHeaders = {
|
|
107
107
|
Accept: applicationJson,
|
|
108
108
|
"Content-Type": applicationJson,
|
|
109
109
|
"X-CSRFToken": csrftoken,
|
|
@@ -112,6 +112,8 @@ function requestHeadersFactory(cookies) {
|
|
|
112
112
|
Authorization: `Bearer ${authToken}`,
|
|
113
113
|
"User-Agent": userAgent,
|
|
114
114
|
};
|
|
115
|
+
console.log("requestHeadersFactory(): requestHeaders", requestHeaders);
|
|
116
|
+
return requestHeaders;
|
|
115
117
|
}
|
|
116
118
|
|
|
117
119
|
function requestInitFactory(headers, body) {
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { MessageDirectionEnum, SenderRoleEnum, ValidMessageRolesEnum } from "./enums.js";
|
|
2
2
|
|
|
3
|
-
export function cookieMetaFactory(cookieName, cookieExpiration) {
|
|
3
|
+
export function cookieMetaFactory(cookieName, cookieExpiration, cookieDomain) {
|
|
4
4
|
/*
|
|
5
5
|
Create a cookie object.
|
|
6
6
|
*/
|
|
7
7
|
return {
|
|
8
8
|
name: cookieName,
|
|
9
9
|
expiration: cookieExpiration,
|
|
10
|
+
domain: cookieDomain,
|
|
10
11
|
};
|
|
11
12
|
}
|
|
12
13
|
|
|
File without changes
|