@mnexium/chat-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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Marius Ndini
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,250 @@
1
+ # @mnexium/chat-react
2
+
3
+ A drop-in React chat widget that gives any web app a full AI chat experience backed by [Mnexium](https://mnexium.com).
4
+
5
+ ![Mnexium Chat Demo](img/embed.png)
6
+
7
+ ## Features
8
+
9
+ - **Floating Widget** - Modern glassmorphism design with smooth animations
10
+ - **Persistent Memory** - Conversations and user context persist across sessions
11
+ - **Streaming Responses** - Real-time streaming with typing effect
12
+ - **Multi-Provider Support** - Works with OpenAI, Anthropic Claude, and Google Gemini
13
+ - **Markdown Rendering** - Rich formatting for assistant messages
14
+ - **Zero Client-Side Keys** - All API keys stay on your server
15
+ - **Theming** - Light and dark themes with customizable primary color
16
+ - **Eager Initialization** - Pre-loads on page load for instant chat opening
17
+ - **Framework Agnostic** - Works with Next.js, Vite, CRA, and any React app
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ npm install @mnexium/chat-react
23
+ ```
24
+
25
+ ## Quick Start
26
+
27
+ ### 1. Add the Chat Widget
28
+
29
+ ```tsx
30
+ import { MnexiumChat } from '@mnexium/chat-react';
31
+
32
+ export default function Layout({ children }) {
33
+ return (
34
+ <>
35
+ {children}
36
+ <MnexiumChat endpoint="/api/mnx" />
37
+ </>
38
+ );
39
+ }
40
+ ```
41
+
42
+ This adds a floating "Ask AI" button to the bottom-right of your page. Click it to open the chat.
43
+
44
+ ### 2. Set Up Server Routes (Recommended Pattern)
45
+
46
+ Create a shared configuration file to avoid repeating options across routes:
47
+
48
+ **`app/api/mnx/_mnx.ts`**
49
+
50
+ ```ts
51
+ import { createHandlers } from '@mnexium/chat-react/server';
52
+
53
+ export const mnx = createHandlers({
54
+ model: process.env.MODEL ?? 'gpt-4o-mini',
55
+ cookiePrefix: 'mnx',
56
+ mnxOptions: {
57
+ history: true,
58
+ learn: true,
59
+ recall: true,
60
+ profile: true,
61
+ summarize: 'balanced',
62
+ },
63
+ });
64
+ ```
65
+
66
+ Then create simple route files:
67
+
68
+ **`app/api/mnx/bootstrap/route.ts`**
69
+
70
+ ```ts
71
+ import { mnx } from '../_mnx';
72
+ export const GET = mnx.bootstrap;
73
+ ```
74
+
75
+ **`app/api/mnx/chat/route.ts`**
76
+
77
+ ```ts
78
+ import { mnx } from '../_mnx';
79
+ export const POST = mnx.chat;
80
+ ```
81
+
82
+ **`app/api/mnx/new-chat/route.ts`** (optional)
83
+
84
+ ```ts
85
+ import { mnx } from '../_mnx';
86
+ export const POST = mnx.newChat;
87
+ ```
88
+
89
+ **`app/api/mnx/history/route.ts`** (optional)
90
+
91
+ ```ts
92
+ import { mnx } from '../_mnx';
93
+ export const GET = mnx.history;
94
+ ```
95
+
96
+ **`app/api/mnx/conversations/[chatId]/route.ts`** (optional)
97
+
98
+ ```ts
99
+ import { mnx } from '../../_mnx';
100
+
101
+ export async function GET(
102
+ req: Request,
103
+ { params }: { params: { chatId: string } }
104
+ ) {
105
+ return mnx.conversation(req, params.chatId);
106
+ }
107
+ ```
108
+
109
+ ### 3. Configure Environment Variables
110
+
111
+ ```bash
112
+ # .env.local
113
+ MNX_API_KEY=mnx_live_...
114
+
115
+ # Include one or all of the following provider keys:
116
+ OPENAI_API_KEY=sk-...
117
+ ANTHROPIC_API_KEY=sk-ant-...
118
+ GOOGLE_API_KEY=...
119
+
120
+ # Optionally set the model (defaults to gpt-4o-mini)
121
+ # MODEL=gpt-4o-mini
122
+ # MODEL=claude-3-haiku-20240307
123
+ # MODEL=gemini-2.0-flash-lite
124
+ ```
125
+
126
+ ## Component Props
127
+
128
+ | Prop | Type | Default | Description |
129
+ |------|------|---------|-------------|
130
+ | `endpoint` | `string` | `'/api/mnx'` | Base URL for API routes |
131
+ | `title` | `string` | `'Ask AI'` | Chat window header title |
132
+ | `buttonLabel` | `string` | `'Ask AI'` | Floating button label |
133
+ | `placeholder` | `string` | `'Type a message...'` | Input placeholder |
134
+ | `position` | `'bottom-right' \| 'bottom-left'` | `'bottom-right'` | Widget position |
135
+ | `primaryColor` | `string` | `'#facc15'` | Accent color (use 6-char hex, e.g. `#45b1eb`) |
136
+ | `theme` | `'light' \| 'dark'` | `'dark'` | Color theme |
137
+ | `defaultOpen` | `boolean` | `false` | Start with chat open |
138
+ | `eagerInit` | `boolean` | `true` | Initialize on page load (no "Initializing..." delay) |
139
+ | `logo` | `string` | - | URL to custom logo image |
140
+ | `welcomeIcon` | `string` | `'👋'` | Emoji shown in empty chat |
141
+ | `welcomeMessage` | `string` | `'How can I help you today?'` | Welcome message |
142
+ | `history` | `boolean` | `false` | Load previous conversation on open |
143
+
144
+ ## Server Handler Options
145
+
146
+ ### `createHandlers(config)` (Recommended)
147
+
148
+ Creates all handlers with shared configuration:
149
+
150
+ ```ts
151
+ const mnx = createHandlers({
152
+ model: 'gpt-4o-mini',
153
+ cookiePrefix: 'mnx',
154
+ mnxOptions: { ... },
155
+ });
156
+
157
+ // Returns: { bootstrap, chat, newChat, history, conversation }
158
+ ```
159
+
160
+ | Option | Type | Default | Description |
161
+ |--------|------|---------|-------------|
162
+ | `model` | `string` | `'gpt-4o-mini'` | LLM model to use |
163
+ | `cookiePrefix` | `string` | `'mnx'` | Prefix for session cookies |
164
+ | `mnxOptions.history` | `boolean` | `true` | Enable conversation history |
165
+ | `mnxOptions.learn` | `boolean \| 'force'` | `true` | Extract and store memories |
166
+ | `mnxOptions.recall` | `boolean` | `true` | Inject relevant memories |
167
+ | `mnxOptions.profile` | `boolean` | `true` | Include user profile |
168
+ | `mnxOptions.summarize` | `'light' \| 'balanced' \| 'aggressive' \| false` | `'balanced'` | Summarization mode |
169
+
170
+ ### Individual Handlers
171
+
172
+ You can also import handlers individually:
173
+
174
+ ```ts
175
+ import { bootstrapHandler, chatHandler, newChatHandler, historyHandler, conversationHandler } from '@mnexium/chat-react/server';
176
+ ```
177
+
178
+ ## Supported Models
179
+
180
+ **OpenAI:** `gpt-4o`, `gpt-4o-mini`, `gpt-4-turbo`, `gpt-4`, `gpt-3.5-turbo`, `o1`, `o1-mini`
181
+
182
+ **Anthropic:** `claude-3-opus`, `claude-3-sonnet`, `claude-3-haiku`, `claude-3-5-sonnet`, `claude-sonnet-4`
183
+
184
+ **Google Gemini:** `gemini-2.0-flash-lite`, `gemini-2.5-flash`, `gemini-1.5-pro`, `gemini-1.5-flash`
185
+
186
+ ## How It Works
187
+
188
+ 1. **On mount**, the client calls `GET /api/mnx/bootstrap`
189
+ 2. Server generates or retrieves `subject_id` and `chat_id` from cookies
190
+ 3. If a previous chat exists, it's loaded from Mnexium history
191
+ 4. **On send**, the client `POST`s to `/api/mnx/chat`
192
+ 5. Server forwards to Mnexium with memory/history flags
193
+ 6. Response streams back to client in real-time
194
+
195
+ All API keys remain server-side. The client never sees or constructs Mnexium requests.
196
+
197
+ ## Full Next.js Example
198
+
199
+ ```
200
+ app/
201
+ ├── api/
202
+ │ └── mnx/
203
+ │ ├── _mnx.ts # Shared config
204
+ │ ├── bootstrap/
205
+ │ │ └── route.ts
206
+ │ ├── chat/
207
+ │ │ └── route.ts
208
+ │ ├── new-chat/
209
+ │ │ └── route.ts
210
+ │ ├── history/
211
+ │ │ └── route.ts
212
+ │ └── conversations/
213
+ │ └── [chatId]/
214
+ │ └── route.ts
215
+ └── layout.tsx
216
+ ```
217
+
218
+ **`app/layout.tsx`**
219
+
220
+ ```tsx
221
+ import { MnexiumChat } from '@mnexium/chat-react';
222
+
223
+ export default function RootLayout({ children }: { children: React.ReactNode }) {
224
+ return (
225
+ <html lang="en">
226
+ <body>
227
+ {children}
228
+ <MnexiumChat
229
+ endpoint="/api/mnx"
230
+ title="Ask AI"
231
+ buttonLabel="Ask AI"
232
+ position="bottom-right"
233
+ primaryColor="#45b1eb"
234
+ theme="dark"
235
+ logo="/logo.png"
236
+ welcomeIcon="🤖"
237
+ welcomeMessage="Ask me anything!"
238
+ history={true}
239
+ />
240
+ </body>
241
+ </html>
242
+ );
243
+ }
244
+ ```
245
+
246
+ The widget appears as a floating button on every page. Click to open the chat with smooth animations.
247
+
248
+ ## License
249
+
250
+ MIT
@@ -0,0 +1,26 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+
3
+ interface Message {
4
+ id: string;
5
+ role: 'user' | 'assistant';
6
+ content: string;
7
+ timestamp: Date;
8
+ }
9
+ interface MnexiumChatProps {
10
+ endpoint?: string;
11
+ placeholder?: string;
12
+ title?: string;
13
+ buttonLabel?: string;
14
+ position?: 'bottom-right' | 'bottom-left';
15
+ primaryColor?: string;
16
+ defaultOpen?: boolean;
17
+ logo?: string;
18
+ theme?: 'light' | 'dark';
19
+ welcomeIcon?: string;
20
+ welcomeMessage?: string;
21
+ history?: boolean;
22
+ eagerInit?: boolean;
23
+ }
24
+ declare function MnexiumChat({ endpoint, placeholder, title, buttonLabel, position, primaryColor, defaultOpen, logo, theme, welcomeIcon, welcomeMessage, history, eagerInit, }: MnexiumChatProps): react_jsx_runtime.JSX.Element;
25
+
26
+ export { type Message, MnexiumChat, type MnexiumChatProps, MnexiumChat as default };
@@ -0,0 +1,26 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+
3
+ interface Message {
4
+ id: string;
5
+ role: 'user' | 'assistant';
6
+ content: string;
7
+ timestamp: Date;
8
+ }
9
+ interface MnexiumChatProps {
10
+ endpoint?: string;
11
+ placeholder?: string;
12
+ title?: string;
13
+ buttonLabel?: string;
14
+ position?: 'bottom-right' | 'bottom-left';
15
+ primaryColor?: string;
16
+ defaultOpen?: boolean;
17
+ logo?: string;
18
+ theme?: 'light' | 'dark';
19
+ welcomeIcon?: string;
20
+ welcomeMessage?: string;
21
+ history?: boolean;
22
+ eagerInit?: boolean;
23
+ }
24
+ declare function MnexiumChat({ endpoint, placeholder, title, buttonLabel, position, primaryColor, defaultOpen, logo, theme, welcomeIcon, welcomeMessage, history, eagerInit, }: MnexiumChatProps): react_jsx_runtime.JSX.Element;
25
+
26
+ export { type Message, MnexiumChat, type MnexiumChatProps, MnexiumChat as default };