@smarter.sh/ui-chat 0.2.14 → 0.3.0

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/README.md CHANGED
@@ -14,6 +14,8 @@ This project is also suitable for all front-end cross-platform projects. For exa
14
14
 
15
15
  ## Usage
16
16
 
17
+ Generic usage of the published npm package is as follows
18
+
17
19
  ```console
18
20
  npm install @smarter.sh/ui-chat
19
21
  ```
@@ -23,13 +25,13 @@ import React from "react";
23
25
  import ReactDOM from "react-dom/client";
24
26
  import { SmarterChat } from "@smarter.sh/ui-chat";
25
27
 
26
- const rootElement = document.getElementById("root");
28
+ const rootElement = document.getElementById("smarter-sh-v1-ui-chat-root");
27
29
  const root = ReactDOM.createRoot(rootElement);
28
- const apiUrl = rootElement.getAttribute("smarter-chatbot-api-url");
30
+ const apiUrl = rootElement.getAttribute("smarter-chatbot-api-url") || "http://localhost:9357/api/v1/chatbots/1/";
29
31
  const toggleMetadata = rootElement.getAttribute("smarter-toggle-metadata") === "true";
30
32
  const csrfCookieName = rootElement.getAttribute("smarter-csrf-cookie-name") || "csrftoken";
31
33
  const sessionCookieName = rootElement.getAttribute("smarter-session-cookie-name") || "session_key";
32
- const cookieDomain = rootElement.getAttribute("smarter-cookie-domain") || "platform.smarter.sh";
34
+ const cookieDomain = rootElement.getAttribute("smarter-cookie-domain") || "localhost";
33
35
  const authSessionCookieName = rootElement.getAttribute("django-session-cookie-name") || "sessionid";
34
36
  const csrftoken = rootElement.getAttribute("django-csrftoken");
35
37
  const debugMode = rootElement.getAttribute("smarter-debug-mode") === "true";
@@ -56,9 +58,22 @@ root.render(
56
58
  );
57
59
  ```
58
60
 
61
+ ### Build from source
62
+
63
+ To build and deploy for use in the Smarter Web Console Prompt Engineer Workbench, do the following.
64
+ This assumes that you have already built your AWS cloud infrastructure using [github.com/smarter-sh/smarter-infrastructure](https://github.com/smarter-sh/smarter-infrastructure) and that a CDN exists at cdn.platform.example.com.
65
+
66
+ ```console
67
+ export ROOT_DOMAIN=example.com
68
+ export PLATFORM_SUBDOMAIN=platform
69
+ npm install
70
+ make build
71
+ make release
72
+ ```
73
+
59
74
  ## Integrate to an existing web page
60
75
 
61
- We integrate this react component to the [Smarter developer workbench](https://platform.smarter.sh/) using this small repo, [github.com/smarter-sh/smarter-workbench](https://github.com/smarter-sh/smarter-workbench). This methodology provides a layer of separation between Django and react.js, which keeps things simple. smarter-workbench substantially consists of the following three files:
76
+ We integrate this react component to the [Smarter developer workbench](https://platform.smarter.sh/) using this small repo, [github.com/smarter-sh/web-integration-example](https://github.com/smarter-sh/web-integration-example). This methodology provides a layer of separation between Django and react.js, which keeps things simple. smarter-workbench substantially consists of the following three files:
62
77
 
63
78
  - [main.jsx](https://github.com/smarter-sh/smarter-workbench/blob/main/src/main.jsx): a 40-line react.js mini app for configuring this npm component with a Smarter Api url and any initialization settings we choose to include.
64
79
  - [app-loader.js](https://github.com/smarter-sh/smarter-workbench/blob/main/src/public/app-loader.js): a small js script that injects the react.js build assets into your DOM, initiating the React boot-up process.
@@ -80,6 +95,40 @@ Meanwhile, Django adds a pair of DOM elements like the following example, where
80
95
 
81
96
  SmarterChat is created with [React](https://react.dev/) leveraging [@chatscope/chat-ui-kit-react](https://www.npmjs.com/package/@chatscope/chat-ui-kit-react)
82
97
 
98
+ ### Setup
99
+
100
+ 1. Build your component
101
+
102
+ ```console
103
+ npm install -g yalc
104
+ npm run build
105
+ yalc publish
106
+ ```
107
+
108
+ 2. Create a separate test React app (outside your library folder)
109
+
110
+ ```console
111
+ npx create-react-app smarter-chat-test
112
+ cd smarter-chat-test
113
+ ```
114
+
115
+ 3. Link your local package to the test app. This is a 1-time operation.
116
+
117
+ ```console
118
+ yalc add @smarter.sh/ui-chat
119
+ npm install # verifies peer dependencies
120
+ ```
121
+
122
+ 4. In the test app, import and use your component as you described.
123
+
124
+ 5. Start the test app
125
+
126
+ ```console
127
+ yalc update @smarter.sh/ui-chat
128
+ npm run build
129
+ npm start
130
+ ```
131
+
83
132
  ### Backend integration
84
133
 
85
134
  See [Getting Started with the Smarter Chatbot Api](./doc/CHATBOT_API.md)