@smarter.sh/ui-chat 0.2.5 → 0.2.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smarter.sh/ui-chat",
3
- "version": "0.2.5",
3
+ "version": "0.2.6",
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 'prop-types';
11
- import ConfigPropTypes from '../../types/propTypes.js';
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, // 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.
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, // the Django CSRF cookie.
53
+ debugCookieName, // the Smarter chat debug cookie. Set here.
54
+ debugCookieExpiration, // the Smarter chat debug cookie. Set here.
55
+ sessionCookieName, // 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, // 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, but it is not used.
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, // 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.
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, // 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.
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, 'prop', 'SmarterChat');
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={isReady ? <AppTitle title={title} isValid={isValid} isDeployed={isDeployed}/>: "Configuring workbench..."}
373
- info={isReady ? info: ""}
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 && <InfoButton onClick={handleInfoButtonClick} title="Toggle system meta data" />}
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
- <ConsoleLayout>
412
- <Console config={config} />
413
- </ConsoleLayout>
415
+ <ConsoleLayout>
416
+ <Console config={config} />
417
+ </ConsoleLayout>
414
418
  )}
415
419
  </WorkbenchLayout>
416
420
  </ContentLayout>
@@ -30,22 +30,20 @@ const applicationJson = "application/json";
30
30
 
31
31
  function getCookie(cookie, defaultValue = null) {
32
32
  let cookieValue = null;
33
- if (document.cookie && document.cookie !== "") {
33
+ const expectedDomain = cookie.domain;
34
+
35
+ // Check if the cookie is set for the expected domain. example: alpha.platform.smarter.sh
36
+ if (window.location.hostname === expectedDomain && document.cookie && document.cookie !== "") {
34
37
  const cookies = document.cookie.split(";");
35
38
  for (let i = 0; i < cookies.length; i++) {
36
39
  const thisCookie = cookies[i].trim();
37
40
  if (thisCookie.substring(0, cookie.name.length + 1) === cookie.name + "=") {
38
41
  cookieValue = decodeURIComponent(thisCookie.substring(cookie.name.length + 1));
39
- if (developerMode) {
40
- console.log("getCookie(): found ", cookieValue, "for cookie", cookie.name);
41
- }
42
42
  break;
43
43
  }
44
44
  }
45
45
  }
46
- if (developerMode && !cookieValue) {
47
- console.warn("getCookie(): no value found for", cookie.name);
48
- }
46
+
49
47
  return cookieValue || defaultValue;
50
48
  }
51
49