spres-react 1.0.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.
Files changed (2) hide show
  1. package/README.md +204 -0
  2. package/package.json +41 -0
package/README.md ADDED
@@ -0,0 +1,204 @@
1
+ # Brainbox React SDK
2
+
3
+ A React UI SDK for Brainbox that includes built-in chat designs, a support bot, and streaming-ready backend communication.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install spres-react
9
+ # or
10
+ yarn add spres-react
11
+ ```
12
+
13
+ ## Deployment
14
+
15
+ `npm install spres-react` or `yarn add spres-react` only installs the library into your React project. It does not automatically deploy a live chat UI to a server.
16
+
17
+ To use the React UI:
18
+
19
+ 1. Install the package in your React app.
20
+ 2. Import `ChatWidget`, `ChatPanel`, or `useBrainboxChat`.
21
+ 3. Build your app with your normal React build command (`npm run build`, `yarn build`, etc.).
22
+ 4. Deploy the built frontend to your hosting platform or CDN.
23
+
24
+ The SDK provides client-side chat components. Your app must be served to users in a browser before the chat UI becomes live.
25
+
26
+ ## What it includes
27
+
28
+ - `BrainboxReactSDK` class for API and ingestion calls
29
+ - `ChatWidget` support bot UI
30
+ - `ChatPanel` full chat UI with sidebar and history
31
+ - `useBrainboxChat` hook for real-time chat state
32
+ - Customizable colors, button placement, and design variants
33
+
34
+ ## Quick Start
35
+
36
+ ```tsx
37
+ import { BrainboxReactSDK, ChatWidget } from 'spres-react';
38
+
39
+ const sdk = new BrainboxReactSDK(
40
+ 'https://api.yourbackend.com',
41
+ 'YOUR_API_KEY',
42
+ 'your-tenant-id'
43
+ );
44
+
45
+ export function App() {
46
+ return <ChatWidget sdk={sdk} />;
47
+ }
48
+ ```
49
+
50
+ ## Support chat UI
51
+
52
+ `ChatWidget` provides a launch button and popup chat bubble. It is styled by default to appear on the right side.
53
+
54
+ ```tsx
55
+ <ChatWidget
56
+ sdk={sdk}
57
+ position="bottom-right"
58
+ primaryColor="#2563EB"
59
+ accentColor="#111827"
60
+ backgroundColor="#F8FAFC"
61
+ buttonText="Support"
62
+ placeholder="Ask a question..."
63
+ width="360px"
64
+ height="520px"
65
+ design="support"
66
+ />
67
+ ```
68
+
69
+ ## Full chat panel UI
70
+
71
+ `ChatPanel` delivers a larger ChatGPT-style conversation experience with a sidebar for session status and history.
72
+
73
+ ```tsx
74
+ import { ChatPanel } from 'spres-react';
75
+
76
+ <ChatPanel
77
+ sdk={sdk}
78
+ headerText="Brainbox AI Chat"
79
+ sidebarTitle="Conversations"
80
+ primaryColor="#0F172A"
81
+ accentColor="#2563EB"
82
+ backgroundColor="#FFFFFF"
83
+ initialSessionId="session-123"
84
+ design="cloud"
85
+ />
86
+ ```
87
+
88
+ ## Customization options
89
+
90
+ You can customize the UI and behavior through props:
91
+
92
+ - `primaryColor` — button, header, and primary bubble color
93
+ - `accentColor` — secondary bubble and action color
94
+ - `backgroundColor` — panel background
95
+ - `buttonText` — launch button label
96
+ - `placeholder` — text input placeholder
97
+ - `position` — `bottom-right`, `bottom-left`, `top-right`, `top-left`, or `center`
98
+ - `width`, `height` — widget container size
99
+ - `design` — visual variant such as `support`, `assistant`, `cloud`, or `classic`
100
+
101
+ ## Platform compatibility
102
+
103
+ - React and Next.js: supported for browser-rendered React components. In Next.js, use client-only components or `useEffect` to avoid server-side rendering issues.
104
+ - Angular / AngularJS: the React UI components are not compatible directly. Use the backend API endpoints or the `sdk-web` plain JavaScript widget for those environments.
105
+ - React Native: the React web UI components are not supported. Use the new `brainbox-react-native-sdk` package for native mobile UI and backend chat calls.
106
+ - Plain HTML / Odoo / jQuery: use the `sdk-web` package and copy-paste widget example.
107
+
108
+ ## React Native guidance
109
+
110
+ The current React SDK does not include native mobile UI components for React Native. If you want React Native support:
111
+
112
+ - use `BrainboxReactNativeSDK` from `brainbox-react-native-sdk` for backend chat calls,
113
+ - use `ChatScreen` from `brainbox-react-native-sdk` for a mobile-ready chat UI,
114
+ - build your own React Native screen and message components if you need a custom experience,
115
+ - call `sdk.chat(...)` or `sdk.streamChat(...)` from your native UI.
116
+
117
+ This means React Native requires a separate deployment of your mobile app, not a browser-hosted web UI.
118
+
119
+ ## Real-time chat behavior
120
+
121
+ The SDK supports HTTP streaming through `/api/chat/stream` when the backend exposes that endpoint. Streaming allows the UI to display response text gradually as the server generates it, which feels faster than waiting for the full reply.
122
+
123
+ If streaming is not available, the SDK falls back to a normal chat request to `/api/chat` and still returns a full response.
124
+
125
+ The current SDK does not use WebSocket for chat. It uses HTTP fetch/streaming, which is enough for fast, chunked responses in supported browsers and environments.
126
+
127
+ Response speed depends mainly on your backend and model latency. The SDK will show user messages immediately and then render assistant text as soon as the backend returns it.
128
+
129
+ ## Real-time chat experience
130
+
131
+ The React SDK supports a streaming-friendly chat method. If your backend exposes `/api/chat/stream`, the widget will render incoming content in chunks.
132
+ If streaming is unavailable, the SDK falls back to a standard chat request and still delivers a full response.
133
+
134
+ ## Using the SDK class directly
135
+
136
+ ```tsx
137
+ import { BrainboxReactSDK } from 'spres-react';
138
+
139
+ const sdk = new BrainboxReactSDK(
140
+ 'https://api.yourbackend.com',
141
+ 'YOUR_API_KEY',
142
+ 'tenant-1'
143
+ );
144
+
145
+ const ingestResult = await sdk.ingest('logs', 'Error content');
146
+ const chatResponse = await sdk.chat('What happened?');
147
+ const session = await sdk.createChatSession('Support Session');
148
+ ```
149
+
150
+ ## React hook
151
+
152
+ `useBrainboxChat` is useful when you want to build a custom chat UI while reusing Brainbox chat state.
153
+
154
+ ```tsx
155
+ import { useBrainboxChat, BrainboxReactSDK } from 'spres-react';
156
+
157
+ const sdk = new BrainboxReactSDK('https://api.yourbackend.com', 'YOUR_API_KEY', 'tenant-1');
158
+
159
+ export function ChatApp() {
160
+ const { messages, loading, error, sendMessage } = useBrainboxChat(sdk);
161
+
162
+ return (
163
+ <div>
164
+ <button onClick={() => sendMessage('Hello')}>Send</button>
165
+ {loading && <p>Loading...</p>}
166
+ {error && <p>Error: {error}</p>}
167
+ <pre>{JSON.stringify(messages, null, 2)}</pre>
168
+ </div>
169
+ );
170
+ }
171
+ ```
172
+
173
+ ## Publish and install
174
+
175
+ ### Publish
176
+
177
+ ```bash
178
+ cd sdk-react
179
+ npm install
180
+ npm test
181
+ npm login
182
+ npm publish --access public
183
+ ```
184
+
185
+ ### Install in a project
186
+
187
+ ```bash
188
+ npm install spres-react
189
+ # or
190
+ yarn add spres-react
191
+ ```
192
+
193
+ ## Notes
194
+
195
+ - The React UI is designed for frontend chat and support experiences.
196
+ - Chat history is managed in memory by default.
197
+ - Use `sdk.ingest()` separately for data ingestion or log collection.
198
+ - Customize the widget styling without changing backend behavior.
199
+
200
+ ## See Also
201
+
202
+ - Backend: [Brainbox Backend](../brainBox/)
203
+ - Python SDK: [sdk-python](../sdk-python/)
204
+ - Node SDK: [sdk-node](../sdk-node/)
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "spres-react",
3
+ "version": "1.0.0",
4
+ "description": "React SDK and customizable chat UI for Spres AI Backend",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "scripts": {
11
+ "build": "tsc --project tsconfig.json",
12
+ "test": "jest"
13
+ },
14
+ "keywords": [
15
+ "ai",
16
+ "sdk",
17
+ "spres-ai",
18
+ "react",
19
+ "chat",
20
+ "widget"
21
+ ],
22
+ "author": "Resbrotherx",
23
+ "license": "MIT",
24
+ "peerDependencies": {
25
+ "react": ">=18.0.0"
26
+ },
27
+ "dependencies": {
28
+ "axios": "^1.16.1"
29
+ },
30
+ "devDependencies": {
31
+ "@types/react": "^18.0.0",
32
+ "@types/react-dom": "^18.0.0",
33
+ "typescript": "^5.4.5"
34
+ },
35
+ "publishConfig": {
36
+ "access": "public"
37
+ },
38
+ "engines": {
39
+ "node": ">=14.0.0"
40
+ }
41
+ }