@smarter.sh/ui-chat 0.2.7 → 0.2.8
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 +1348 -1345
- package/dist/smarter-chat-library.es.js.map +1 -1
- package/dist/smarter-chat-library.umd.js +30 -30
- package/dist/smarter-chat-library.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/components/SmarterChat/Component.jsx +5 -4
- package/src/components/SmarterChat/api.js +11 -6
- package/src/components/SmarterChat/utils.jsx +2 -1
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.8",
|
|
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",
|
|
@@ -50,6 +50,7 @@ function SmarterChat({
|
|
|
50
50
|
apiKey, // NOT USED. TO DELETE.
|
|
51
51
|
toggleMetadata, // show/hide toggle button to show/hide the chat thread metadata
|
|
52
52
|
csrfCookieName = "csrftoken", // the Django CSRF cookie.
|
|
53
|
+
csrftoken, // the Django CSRF token. Passed from the Django template in the Smarter web console workbench.
|
|
53
54
|
debugCookieName, // the Smarter chat debug cookie. Set here.
|
|
54
55
|
debugCookieExpiration, // the Smarter chat debug cookie. Set here.
|
|
55
56
|
sessionCookieName = "session_key", // the Smarter chat session cookie. Set here, where the user creates a new chat session.
|
|
@@ -89,10 +90,10 @@ function SmarterChat({
|
|
|
89
90
|
const fileInputRef = useRef(null);
|
|
90
91
|
|
|
91
92
|
// cookie management
|
|
92
|
-
const csrfCookie = cookieMetaFactory(csrfCookieName, null, cookieDomain); // we read this but never set it.
|
|
93
|
-
const authTokenCookie = cookieMetaFactory(authSessionCookieName, null, cookieDomain); // we read this but never set it.
|
|
94
|
-
const sessionCookie = cookieMetaFactory(sessionCookieName, sessionCookieExpiration, cookieDomain);
|
|
95
|
-
const debugCookie = cookieMetaFactory(debugCookieName, debugCookieExpiration, cookieDomain);
|
|
93
|
+
const csrfCookie = cookieMetaFactory(csrfCookieName, null, cookieDomain, csrftoken); // we read this but never set it.
|
|
94
|
+
const authTokenCookie = cookieMetaFactory(authSessionCookieName, null, cookieDomain, null); // we read this but never set it.
|
|
95
|
+
const sessionCookie = cookieMetaFactory(sessionCookieName, sessionCookieExpiration, cookieDomain, null);
|
|
96
|
+
const debugCookie = cookieMetaFactory(debugCookieName, debugCookieExpiration, cookieDomain, null);
|
|
96
97
|
const cookies = {
|
|
97
98
|
authTokenCookie: authTokenCookie, // the Django session cookie. Set when the user logs in to the Smarter web console app.
|
|
98
99
|
// typically this is not required for the chat app when running inside the
|
|
@@ -30,15 +30,17 @@ const applicationJson = "application/json";
|
|
|
30
30
|
|
|
31
31
|
function getCookie(cookie, defaultValue = null) {
|
|
32
32
|
console.log("getCookie(): cookie", cookie);
|
|
33
|
+
if (cookie.value !== null) {
|
|
34
|
+
console.log("getCookie(): ", cookie.domain, cookie.name, cookie.value);
|
|
35
|
+
return cookie.value;
|
|
36
|
+
}
|
|
33
37
|
let cookieValue = null;
|
|
34
|
-
const expectedDomain = cookie.domain;
|
|
35
38
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const cookies = document.cookie.split(";");
|
|
39
|
+
if (window.location.hostname.endsWith(cookie.domain) && document.cookie && document.cookie !== "") {
|
|
40
|
+
const cookies = document.cookie.split(";").map(cookie => cookie.trim());
|
|
39
41
|
for (let i = 0; i < cookies.length; i++) {
|
|
40
|
-
const thisCookie = cookies[i]
|
|
41
|
-
if (thisCookie.
|
|
42
|
+
const thisCookie = cookies[i];
|
|
43
|
+
if (thisCookie.startsWith(`${cookie.name}=`)) {
|
|
42
44
|
cookieValue = decodeURIComponent(thisCookie.substring(cookie.name.length + 1));
|
|
43
45
|
console.log("getCookie(): ", cookie.domain, cookie.name, cookieValue);
|
|
44
46
|
break;
|
|
@@ -46,6 +48,7 @@ function getCookie(cookie, defaultValue = null) {
|
|
|
46
48
|
}
|
|
47
49
|
}
|
|
48
50
|
|
|
51
|
+
|
|
49
52
|
return cookieValue || defaultValue;
|
|
50
53
|
}
|
|
51
54
|
|
|
@@ -96,6 +99,8 @@ function requestHeadersFactory(cookies) {
|
|
|
96
99
|
return !trimmedCookie.startsWith(`${cookies.csrfCookie.name}=`);
|
|
97
100
|
});
|
|
98
101
|
const selectedCookies = cookiesArray.join("; ");
|
|
102
|
+
|
|
103
|
+
// example return value: "_ga=GA1.1.1244182935.1742308279; _ga_SK81M5HQYS=GS1.1.1742316653.3.1.1742320251.0.0.0"
|
|
99
104
|
return selectedCookies;
|
|
100
105
|
}
|
|
101
106
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MessageDirectionEnum, SenderRoleEnum, ValidMessageRolesEnum } from "./enums.js";
|
|
2
2
|
|
|
3
|
-
export function cookieMetaFactory(cookieName, cookieExpiration, cookieDomain) {
|
|
3
|
+
export function cookieMetaFactory(cookieName, cookieExpiration, cookieDomain, cookieValue = null) {
|
|
4
4
|
/*
|
|
5
5
|
Create a cookie object.
|
|
6
6
|
*/
|
|
@@ -8,6 +8,7 @@ export function cookieMetaFactory(cookieName, cookieExpiration, cookieDomain) {
|
|
|
8
8
|
name: cookieName,
|
|
9
9
|
expiration: cookieExpiration,
|
|
10
10
|
domain: cookieDomain,
|
|
11
|
+
value: cookieValue,
|
|
11
12
|
};
|
|
12
13
|
}
|
|
13
14
|
|