@cuadra-ai/uikit 0.1.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 ADDED
@@ -0,0 +1,272 @@
1
+ # @cuadra-ai/uikit
2
+
3
+ A production-ready React UI kit for building AI chat experiences with the [Cuadra AI](https://cuadra.ai) API, built on top of [assistant-ui](https://www.assistant-ui.com/).
4
+
5
+ ๐Ÿ“š **[Full Documentation](https://docs.cuadra.ai)** | ๐ŸŒ **[Website](https://cuadra.ai)**
6
+
7
+ ## Features
8
+
9
+ - ๐Ÿš€ **Ready-to-use chat components** - Pre-built thread list, message display, and composer
10
+ - ๐ŸŽจ **Beautiful UI** - Textured card design with theme support (light/dark/system)
11
+ - ๐Ÿ”„ **Multiple chat modes** - Single chat or multi-thread support
12
+ - ๐Ÿค– **Model selection** - Fixed model or dynamic model selector
13
+ - ๐Ÿ“ฆ **Two build formats**:
14
+ - **Library build** (ESM/CJS) - For use in React applications
15
+ - **Widget build** (UMD) - For direct browser embedding via script tag
16
+ - ๐Ÿ” **Flexible authentication** - Bearer token or proxy mode for backend-handled auth
17
+ - โšก **Streaming support** - Real-time message streaming via SSE
18
+ - ๐Ÿงต **Thread management** - Create, rename, delete, and switch between chat threads
19
+ - ๐ŸŒ **i18n ready** - Language/locale support
20
+
21
+ ## Installation
22
+
23
+ ```bash
24
+ npm install @cuadra-ai/uikit
25
+ ```
26
+
27
+ ### Peer Dependencies
28
+
29
+ This package requires the following peer dependencies:
30
+
31
+ ```bash
32
+ npm install react react-dom
33
+ ```
34
+
35
+ Note: `@assistant-ui/react` and `@assistant-ui/react-markdown` are bundled dependencies and don't need to be installed separately.
36
+
37
+ ## Usage
38
+
39
+ ### Using CuadraChat Component (Recommended)
40
+
41
+ The `CuadraChat` component is the easiest way to get started. It's an all-in-one component that handles everything for you.
42
+
43
+ #### Basic Example
44
+
45
+ ```tsx
46
+ import { CuadraChat } from '@cuadra-ai/uikit';
47
+ import '@cuadra-ai/uikit/styles';
48
+
49
+ function App() {
50
+ return (
51
+ <div style={{ height: '100vh' }}>
52
+ <CuadraChat
53
+ baseUrl="https://api.cuadra.ai"
54
+ sessionToken="your-session-token"
55
+ mode="multiChat"
56
+ modelMode="fixed"
57
+ modelId="your-model-id" // Get this from dashboard.cuadra.ai
58
+ />
59
+ </div>
60
+ );
61
+ }
62
+ ```
63
+
64
+ **Note:** Model IDs are provided in your [Cuadra AI Dashboard](https://dashboard.cuadra.ai). Create and manage your models there, then use the model ID in your code.
65
+
66
+ #### With Model Selector
67
+
68
+ ```tsx
69
+ import { CuadraChat } from '@cuadra-ai/uikit';
70
+ import '@cuadra-ai/uikit/styles';
71
+ import { useState } from 'react';
72
+
73
+ function App() {
74
+ const [modelId, setModelId] = useState<string | null>(null);
75
+
76
+ return (
77
+ <div style={{ height: '100vh' }}>
78
+ <CuadraChat
79
+ baseUrl="https://api.cuadra.ai"
80
+ sessionToken="your-session-token"
81
+ mode="multiChat"
82
+ modelMode="selector"
83
+ modelId={modelId || undefined}
84
+ onModelChange={setModelId}
85
+ />
86
+ </div>
87
+ );
88
+ }
89
+ ```
90
+
91
+ #### Proxy Mode (Backend Authentication)
92
+
93
+ When your backend handles authentication, use `proxyUrl` instead of `baseUrl`:
94
+
95
+ ```tsx
96
+ import { CuadraChat } from '@cuadra-ai/uikit';
97
+ import '@cuadra-ai/uikit/styles';
98
+
99
+ function App() {
100
+ return (
101
+ <div style={{ height: '100vh' }}>
102
+ <CuadraChat
103
+ proxyUrl="/api/chat"
104
+ mode="multiChat"
105
+ modelMode="fixed"
106
+ modelId="your-model-id"
107
+ />
108
+ </div>
109
+ );
110
+ }
111
+ ```
112
+
113
+ #### Customization Options
114
+
115
+ ```tsx
116
+ import { CuadraChat } from '@cuadra-ai/uikit';
117
+ import '@cuadra-ai/uikit/styles';
118
+
119
+ function App() {
120
+ return (
121
+ <div style={{ height: '100vh' }}>
122
+ <CuadraChat
123
+ baseUrl="https://api.cuadra.ai"
124
+ sessionToken="your-session-token"
125
+ mode="multiChat"
126
+ modelMode="fixed"
127
+ modelId="your-model-id"
128
+ className="my-custom-class"
129
+ showThemeToggle={true}
130
+ theme="system"
131
+ language="en"
132
+ welcomeTitle="Welcome to Chat"
133
+ welcomeSubtitle="How can I help you today?"
134
+ extraTopPadding="2rem"
135
+ suggestions={[
136
+ { prompt: "What is Cuadra AI?" },
137
+ { prompt: "How do I get started?" },
138
+ { prompt: "Show me examples" }
139
+ ]}
140
+ onChatCreated={(chatId) => {
141
+ console.log('Chat created:', chatId);
142
+ }}
143
+ onThreadIdUpdate={(oldId, newId) => {
144
+ console.log('Thread updated:', oldId, '->', newId);
145
+ }}
146
+ onError={(error) => {
147
+ console.error('Error:', error);
148
+ }}
149
+ />
150
+ </div>
151
+ );
152
+ }
153
+ ```
154
+
155
+ ### Widget Mode (Script Tag - Compiled JS)
156
+
157
+ The widget build allows you to embed the chat interface directly in any HTML page without a build step.
158
+
159
+ #### Basic HTML Setup
160
+
161
+ ```html
162
+ <!DOCTYPE html>
163
+ <html>
164
+ <head>
165
+ <meta charset="UTF-8">
166
+ <title>Cuadra Chat</title>
167
+ <link rel="stylesheet" href="https://unpkg.com/@cuadra-ai/uikit@latest/dist/widget/cuadra-uikit.css">
168
+ <style>
169
+ body {
170
+ margin: 0;
171
+ padding: 0;
172
+ height: 100vh;
173
+ }
174
+ #cuadra-chat {
175
+ height: 100vh;
176
+ width: 100%;
177
+ }
178
+ </style>
179
+ </head>
180
+ <body>
181
+ <div id="cuadra-chat"></div>
182
+
183
+ <script src="https://unpkg.com/@cuadra-ai/uikit@latest/dist/widget/cuadra-uikit.umd.js"></script>
184
+ <script>
185
+ CuadraUIKit.init({
186
+ baseUrl: 'https://api.cuadra.ai',
187
+ sessionToken: 'your-session-token',
188
+ mode: 'multiChat',
189
+ modelMode: 'fixed',
190
+ modelId: 'your-model-id',
191
+ });
192
+ </script>
193
+ </body>
194
+ </html>
195
+ ```
196
+
197
+ #### With Data Attributes (Auto-initialization)
198
+
199
+ ```html
200
+ <div id="cuadra-chat"
201
+ data-base-url="https://api.cuadra.ai"
202
+ data-session-token="your-session-token"
203
+ data-mode="multiChat"
204
+ data-model-mode="fixed"
205
+ data-model-id="your-model-id"
206
+ style="height: 100vh; width: 100%;">
207
+ </div>
208
+
209
+ <script src="https://unpkg.com/@cuadra-ai/uikit@latest/dist/widget/cuadra-uikit.umd.js"></script>
210
+ ```
211
+
212
+ #### Proxy Mode (Widget)
213
+
214
+ ```html
215
+ <div id="cuadra-chat" style="height: 100vh; width: 100%;"></div>
216
+
217
+ <script src="https://unpkg.com/@cuadra-ai/uikit@latest/dist/widget/cuadra-uikit.umd.js"></script>
218
+ <script>
219
+ CuadraUIKit.init({
220
+ proxyUrl: '/api/chat',
221
+ mode: 'multiChat',
222
+ modelMode: 'fixed',
223
+ modelId: 'your-model-id',
224
+ });
225
+ </script>
226
+ ```
227
+
228
+ For detailed widget API documentation, see the [full documentation](https://docs.cuadra.ai).
229
+
230
+ ## API Reference
231
+
232
+ ### CuadraChat Props
233
+
234
+ | Prop | Type | Required | Default | Description |
235
+ |------|------|----------|---------|-------------|
236
+ | `baseUrl` | `string` | Yes* | - | Cuadra API base URL (e.g., `'https://api.cuadra.ai'`) |
237
+ | `proxyUrl` | `string` | Yes* | - | Proxy URL for backend-handled auth (e.g., `'/api/chat'`) |
238
+ | `sessionToken` | `string \| null` | No | `null` | Bearer token for authentication |
239
+ | `tenantId` | `string` | No | - | Tenant ID for multi-tenant support |
240
+ | `mode` | `'singleChat' \| 'multiChat'` | No | `'multiChat'` | Chat mode |
241
+ | `modelMode` | `'fixed' \| 'selector'` | No | `'fixed'` | Model selection mode |
242
+ | `modelId` | `string` | Yes** | - | Model ID from [dashboard.cuadra.ai](https://dashboard.cuadra.ai) (required if `modelMode='fixed'`) |
243
+ | `onModelChange` | `(modelId: string) => void` | No | - | Callback when model changes (selector mode) |
244
+ | `ephemeral` | `boolean` | No | `false` | Create temporary chats that auto-delete |
245
+ | `systemPrompt` | `string` | No | - | System prompt for the assistant |
246
+ | `initialThreadId` | `string` | No | - | Load existing thread (multiChat mode) |
247
+ | `className` | `string` | No | - | Container className for styling |
248
+ | `showThemeToggle` | `boolean` | No | `true` | Show theme toggle button |
249
+ | `theme` | `'light' \| 'dark' \| 'system'` | No | `'system'` | Initial theme |
250
+ | `language` | `string` | No | - | Language/locale for i18n (e.g., 'en', 'es', 'fr') |
251
+ | `welcomeTitle` | `string` | No | - | Welcome screen title |
252
+ | `welcomeSubtitle` | `string` | No | - | Welcome screen subtitle |
253
+ | `extraTopPadding` | `string` | No | - | Extra top padding for thread viewport (e.g., '1rem', '2rem') |
254
+ | `suggestions` | `Array<{ prompt: string }>` | No | - | Suggestions to show in welcome screen |
255
+ | `onError` | `(error: Error) => void` | No | - | Error callback |
256
+ | `onChatCreated` | `(chatId: string) => void` | No | - | Callback when chat is created |
257
+ | `onThreadIdUpdate` | `(oldId: string, newId: string) => void` | No | - | Callback when thread ID updates |
258
+
259
+ \* Either `baseUrl` or `proxyUrl` is required
260
+ \** Required if `modelMode='fixed'`
261
+
262
+ ## License
263
+
264
+ MIT License - see [LICENSE](./LICENSE) file for details.
265
+
266
+ ## Support
267
+
268
+ For issues and questions:
269
+ - ๐Ÿ“š **[Documentation](https://docs.cuadra.ai)** - Full API reference and guides
270
+ - ๐ŸŒ **[Website](https://cuadra.ai)** - Learn more about Cuadra AI
271
+ - ๐Ÿ’ฌ **GitHub Issues**: https://github.com/cuadra-ai/cuadra-ai-uikit/issues
272
+ - ๐Ÿ“ง **Support**: support@cuadra.ai