@smarter.sh/ui-chat 0.2.5 → 0.2.7
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 +13 -11
- package/dist/smarter-chat-library.es.js.map +1 -1
- package/dist/smarter-chat-library.umd.js +2 -2
- package/dist/smarter-chat-library.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/components/SmarterChat/Component.jsx +36 -32
- package/src/components/SmarterChat/api.js +7 -7
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.7",
|
|
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",
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
|
|
8
8
|
// React stuff
|
|
9
9
|
import React, { useRef, useState, useEffect } from "react";
|
|
10
|
-
import PropTypes from
|
|
11
|
-
import ConfigPropTypes from
|
|
10
|
+
import PropTypes from "prop-types";
|
|
11
|
+
import ConfigPropTypes from "../../types/propTypes.js";
|
|
12
12
|
|
|
13
13
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
14
14
|
import { faCheckCircle, faTimesCircle, faRocket } from "@fortawesome/free-solid-svg-icons";
|
|
@@ -29,18 +29,16 @@ import {
|
|
|
29
29
|
|
|
30
30
|
// this repo
|
|
31
31
|
import { ErrorModal } from "../ErrorModal/ErrorModal.jsx";
|
|
32
|
-
import { Console} from "../Console/index.js";
|
|
32
|
+
import { Console } from "../Console/index.js";
|
|
33
33
|
|
|
34
34
|
// This component
|
|
35
35
|
import "./styles.css";
|
|
36
|
-
import { ContainerLayout, ContentLayout, WorkbenchLayout, ChatAppLayout, ConsoleLayout} from "./Layout.js"
|
|
36
|
+
import { ContainerLayout, ContentLayout, WorkbenchLayout, ChatAppLayout, ConsoleLayout } from "./Layout.js";
|
|
37
37
|
import { MessageDirectionEnum, SenderRoleEnum } from "./enums.js";
|
|
38
38
|
import { setCookie, fetchConfig, fetchPrompt } from "./api.js";
|
|
39
39
|
import { cookieMetaFactory, messageFactory, chatMessages2RequestMessages, chatInit } from "./utils.jsx";
|
|
40
40
|
import { ErrorBoundary } from "./ErrorBoundary.jsx";
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
44
42
|
const DEBUG_MODE = false;
|
|
45
43
|
|
|
46
44
|
// The main chat component. This is the top-level component that
|
|
@@ -48,19 +46,18 @@ const DEBUG_MODE = false;
|
|
|
48
46
|
// managing the chat message thread, sending messages to the backend
|
|
49
47
|
// Api, and rendering the chat UI.
|
|
50
48
|
function SmarterChat({
|
|
51
|
-
apiUrl,
|
|
52
|
-
apiKey,
|
|
53
|
-
toggleMetadata,
|
|
54
|
-
csrfCookieName,
|
|
55
|
-
debugCookieName,
|
|
56
|
-
debugCookieExpiration,
|
|
57
|
-
sessionCookieName,
|
|
58
|
-
sessionCookieExpiration,
|
|
59
|
-
authSessionCookieName,
|
|
60
|
-
showConsole=true,
|
|
61
|
-
cookieDomain
|
|
49
|
+
apiUrl, // the URL of the Smarter chatbot API. example: https://smarter.3141-5926-5359.beta.api.smarter.sh/
|
|
50
|
+
apiKey, // NOT USED. TO DELETE.
|
|
51
|
+
toggleMetadata, // show/hide toggle button to show/hide the chat thread metadata
|
|
52
|
+
csrfCookieName = "csrftoken", // the Django CSRF cookie.
|
|
53
|
+
debugCookieName, // the Smarter chat debug cookie. Set here.
|
|
54
|
+
debugCookieExpiration, // the Smarter chat debug cookie. Set here.
|
|
55
|
+
sessionCookieName = "session_key", // the Smarter chat session cookie. Set here, where the user creates a new chat session.
|
|
56
|
+
sessionCookieExpiration, // the Smarter chat session cookie. Set here, where the user creates a new chat session.
|
|
57
|
+
authSessionCookieName = "sessionid", // the Django session cookie. Set when the user logs in to the Smarter web console app.
|
|
58
|
+
showConsole = true, // show the server console log component
|
|
59
|
+
cookieDomain, // the domain of the cookie. This is added to the cookie meta data to restrict the domain that this component will read cookie data.
|
|
62
60
|
}) {
|
|
63
|
-
|
|
64
61
|
const [configApiUrl, setConfigApiUrl] = useState(apiUrl);
|
|
65
62
|
|
|
66
63
|
const [showMetadata, setShowMetadata] = useState(toggleMetadata);
|
|
@@ -97,16 +94,15 @@ function SmarterChat({
|
|
|
97
94
|
const sessionCookie = cookieMetaFactory(sessionCookieName, sessionCookieExpiration, cookieDomain);
|
|
98
95
|
const debugCookie = cookieMetaFactory(debugCookieName, debugCookieExpiration, cookieDomain);
|
|
99
96
|
const cookies = {
|
|
100
|
-
authTokenCookie: authTokenCookie,
|
|
101
|
-
|
|
102
|
-
|
|
97
|
+
authTokenCookie: authTokenCookie, // the Django session cookie. Set when the user logs in to the Smarter web console app.
|
|
98
|
+
// typically this is not required for the chat app when running inside the
|
|
99
|
+
// Smarter web console workbench, since it is already authenticated.
|
|
103
100
|
|
|
104
|
-
csrfCookie: csrfCookie,
|
|
105
|
-
sessionCookie: sessionCookie,
|
|
106
|
-
debugCookie: debugCookie,
|
|
101
|
+
csrfCookie: csrfCookie, // the Django CSRF cookie. This is required for requests to the Smarter web console workbench.
|
|
102
|
+
sessionCookie: sessionCookie, // the Smarter chat session cookie. Set here, where the user creates a new chat session.
|
|
103
|
+
debugCookie: debugCookie, // the Smarter chat debug cookie. Set here. Controls browser console logging.
|
|
107
104
|
};
|
|
108
105
|
|
|
109
|
-
|
|
110
106
|
const refetchConfig = async () => {
|
|
111
107
|
const newConfig = await fetchConfig(configApiUrl, cookies);
|
|
112
108
|
|
|
@@ -115,7 +111,7 @@ function SmarterChat({
|
|
|
115
111
|
console.log("fetchAndSetConfig() config:", newConfig);
|
|
116
112
|
}
|
|
117
113
|
|
|
118
|
-
PropTypes.checkPropTypes(ConfigPropTypes, newConfig,
|
|
114
|
+
PropTypes.checkPropTypes(ConfigPropTypes, newConfig, "prop", "SmarterChat");
|
|
119
115
|
setConfig(newConfig);
|
|
120
116
|
return newConfig;
|
|
121
117
|
};
|
|
@@ -369,12 +365,20 @@ function SmarterChat({
|
|
|
369
365
|
<ChatContainer style={chatContainerStyleOverrides}>
|
|
370
366
|
<ConversationHeader>
|
|
371
367
|
<ConversationHeader.Content
|
|
372
|
-
userName={
|
|
373
|
-
|
|
368
|
+
userName={
|
|
369
|
+
isReady ? (
|
|
370
|
+
<AppTitle title={title} isValid={isValid} isDeployed={isDeployed} />
|
|
371
|
+
) : (
|
|
372
|
+
"Configuring workbench..."
|
|
373
|
+
)
|
|
374
|
+
}
|
|
375
|
+
info={isReady ? info : ""}
|
|
374
376
|
/>
|
|
375
377
|
<ConversationHeader.Actions>
|
|
376
378
|
<AddUserButton onClick={handleAddUserButtonClick} title="Start a new chat" />
|
|
377
|
-
{toggleMetadata &&
|
|
379
|
+
{toggleMetadata && (
|
|
380
|
+
<InfoButton onClick={handleInfoButtonClick} title="Toggle system meta data" />
|
|
381
|
+
)}
|
|
378
382
|
</ConversationHeader.Actions>
|
|
379
383
|
</ConversationHeader>
|
|
380
384
|
<MessageList
|
|
@@ -408,9 +412,9 @@ function SmarterChat({
|
|
|
408
412
|
</div>
|
|
409
413
|
</ChatAppLayout>
|
|
410
414
|
{showConsole && (
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
415
|
+
<ConsoleLayout>
|
|
416
|
+
<Console config={config} />
|
|
417
|
+
</ConsoleLayout>
|
|
414
418
|
)}
|
|
415
419
|
</WorkbenchLayout>
|
|
416
420
|
</ContentLayout>
|
|
@@ -29,23 +29,23 @@ const userAgent = "SmarterChat/1.0";
|
|
|
29
29
|
const applicationJson = "application/json";
|
|
30
30
|
|
|
31
31
|
function getCookie(cookie, defaultValue = null) {
|
|
32
|
+
console.log("getCookie(): cookie", cookie);
|
|
32
33
|
let cookieValue = null;
|
|
33
|
-
|
|
34
|
+
const expectedDomain = cookie.domain;
|
|
35
|
+
|
|
36
|
+
// Check if the cookie is set for the expected domain. example: alpha.platform.smarter.sh
|
|
37
|
+
if (window.location.hostname === expectedDomain && document.cookie && document.cookie !== "") {
|
|
34
38
|
const cookies = document.cookie.split(";");
|
|
35
39
|
for (let i = 0; i < cookies.length; i++) {
|
|
36
40
|
const thisCookie = cookies[i].trim();
|
|
37
41
|
if (thisCookie.substring(0, cookie.name.length + 1) === cookie.name + "=") {
|
|
38
42
|
cookieValue = decodeURIComponent(thisCookie.substring(cookie.name.length + 1));
|
|
39
|
-
|
|
40
|
-
console.log("getCookie(): found ", cookieValue, "for cookie", cookie.name);
|
|
41
|
-
}
|
|
43
|
+
console.log("getCookie(): ", cookie.domain, cookie.name, cookieValue);
|
|
42
44
|
break;
|
|
43
45
|
}
|
|
44
46
|
}
|
|
45
47
|
}
|
|
46
|
-
|
|
47
|
-
console.warn("getCookie(): no value found for", cookie.name);
|
|
48
|
-
}
|
|
48
|
+
|
|
49
49
|
return cookieValue || defaultValue;
|
|
50
50
|
}
|
|
51
51
|
|