hazo_chat 1.1.0 → 2.0.2

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 (135) hide show
  1. package/README.md +161 -152
  2. package/SETUP_CHECKLIST.md +191 -587
  3. package/package.json +17 -7
  4. package/dist/components/hazo_chat/hazo_chat.d.ts +0 -16
  5. package/dist/components/hazo_chat/hazo_chat.d.ts.map +0 -1
  6. package/dist/components/hazo_chat/hazo_chat.js +0 -155
  7. package/dist/components/hazo_chat/hazo_chat.js.map +0 -1
  8. package/dist/components/hazo_chat/hazo_chat_attachment_preview.d.ts +0 -17
  9. package/dist/components/hazo_chat/hazo_chat_attachment_preview.d.ts.map +0 -1
  10. package/dist/components/hazo_chat/hazo_chat_attachment_preview.js +0 -60
  11. package/dist/components/hazo_chat/hazo_chat_attachment_preview.js.map +0 -1
  12. package/dist/components/hazo_chat/hazo_chat_context.d.ts +0 -36
  13. package/dist/components/hazo_chat/hazo_chat_context.d.ts.map +0 -1
  14. package/dist/components/hazo_chat/hazo_chat_context.js +0 -249
  15. package/dist/components/hazo_chat/hazo_chat_context.js.map +0 -1
  16. package/dist/components/hazo_chat/hazo_chat_document_viewer.d.ts +0 -15
  17. package/dist/components/hazo_chat/hazo_chat_document_viewer.d.ts.map +0 -1
  18. package/dist/components/hazo_chat/hazo_chat_document_viewer.js +0 -111
  19. package/dist/components/hazo_chat/hazo_chat_document_viewer.js.map +0 -1
  20. package/dist/components/hazo_chat/hazo_chat_header.d.ts +0 -16
  21. package/dist/components/hazo_chat/hazo_chat_header.d.ts.map +0 -1
  22. package/dist/components/hazo_chat/hazo_chat_header.js +0 -24
  23. package/dist/components/hazo_chat/hazo_chat_header.js.map +0 -1
  24. package/dist/components/hazo_chat/hazo_chat_input.d.ts +0 -18
  25. package/dist/components/hazo_chat/hazo_chat_input.d.ts.map +0 -1
  26. package/dist/components/hazo_chat/hazo_chat_input.js +0 -134
  27. package/dist/components/hazo_chat/hazo_chat_input.js.map +0 -1
  28. package/dist/components/hazo_chat/hazo_chat_messages.d.ts +0 -17
  29. package/dist/components/hazo_chat/hazo_chat_messages.d.ts.map +0 -1
  30. package/dist/components/hazo_chat/hazo_chat_messages.js +0 -109
  31. package/dist/components/hazo_chat/hazo_chat_messages.js.map +0 -1
  32. package/dist/components/hazo_chat/hazo_chat_reference_list.d.ts +0 -16
  33. package/dist/components/hazo_chat/hazo_chat_reference_list.d.ts.map +0 -1
  34. package/dist/components/hazo_chat/hazo_chat_reference_list.js +0 -59
  35. package/dist/components/hazo_chat/hazo_chat_reference_list.js.map +0 -1
  36. package/dist/components/hazo_chat/hazo_chat_sidebar.d.ts +0 -18
  37. package/dist/components/hazo_chat/hazo_chat_sidebar.d.ts.map +0 -1
  38. package/dist/components/hazo_chat/hazo_chat_sidebar.js +0 -72
  39. package/dist/components/hazo_chat/hazo_chat_sidebar.js.map +0 -1
  40. package/dist/components/hazo_chat/index.d.ts +0 -16
  41. package/dist/components/hazo_chat/index.d.ts.map +0 -1
  42. package/dist/components/hazo_chat/index.js +0 -19
  43. package/dist/components/hazo_chat/index.js.map +0 -1
  44. package/dist/components/index.d.ts +0 -9
  45. package/dist/components/index.d.ts.map +0 -1
  46. package/dist/components/index.js +0 -11
  47. package/dist/components/index.js.map +0 -1
  48. package/dist/components/ui/avatar.d.ts +0 -13
  49. package/dist/components/ui/avatar.d.ts.map +0 -1
  50. package/dist/components/ui/avatar.js +0 -28
  51. package/dist/components/ui/avatar.js.map +0 -1
  52. package/dist/components/ui/badge.d.ts +0 -16
  53. package/dist/components/ui/badge.d.ts.map +0 -1
  54. package/dist/components/ui/badge.js +0 -36
  55. package/dist/components/ui/badge.js.map +0 -1
  56. package/dist/components/ui/button.d.ts +0 -18
  57. package/dist/components/ui/button.d.ts.map +0 -1
  58. package/dist/components/ui/button.js +0 -47
  59. package/dist/components/ui/button.js.map +0 -1
  60. package/dist/components/ui/chat_bubble.d.ts +0 -19
  61. package/dist/components/ui/chat_bubble.d.ts.map +0 -1
  62. package/dist/components/ui/chat_bubble.js +0 -101
  63. package/dist/components/ui/chat_bubble.js.map +0 -1
  64. package/dist/components/ui/index.d.ts +0 -18
  65. package/dist/components/ui/index.d.ts.map +0 -1
  66. package/dist/components/ui/index.js +0 -20
  67. package/dist/components/ui/index.js.map +0 -1
  68. package/dist/components/ui/input.d.ts +0 -11
  69. package/dist/components/ui/input.d.ts.map +0 -1
  70. package/dist/components/ui/input.js +0 -18
  71. package/dist/components/ui/input.js.map +0 -1
  72. package/dist/components/ui/loading_skeleton.d.ts +0 -19
  73. package/dist/components/ui/loading_skeleton.d.ts.map +0 -1
  74. package/dist/components/ui/loading_skeleton.js +0 -30
  75. package/dist/components/ui/loading_skeleton.js.map +0 -1
  76. package/dist/components/ui/scroll-area.d.ts +0 -12
  77. package/dist/components/ui/scroll-area.d.ts.map +0 -1
  78. package/dist/components/ui/scroll-area.js +0 -25
  79. package/dist/components/ui/scroll-area.js.map +0 -1
  80. package/dist/components/ui/separator.d.ts +0 -11
  81. package/dist/components/ui/separator.d.ts.map +0 -1
  82. package/dist/components/ui/separator.js +0 -18
  83. package/dist/components/ui/separator.js.map +0 -1
  84. package/dist/components/ui/skeleton.d.ts +0 -9
  85. package/dist/components/ui/skeleton.d.ts.map +0 -1
  86. package/dist/components/ui/skeleton.js +0 -16
  87. package/dist/components/ui/skeleton.js.map +0 -1
  88. package/dist/components/ui/textarea.d.ts +0 -11
  89. package/dist/components/ui/textarea.d.ts.map +0 -1
  90. package/dist/components/ui/textarea.js +0 -18
  91. package/dist/components/ui/textarea.js.map +0 -1
  92. package/dist/components/ui/tooltip.d.ts +0 -14
  93. package/dist/components/ui/tooltip.d.ts.map +0 -1
  94. package/dist/components/ui/tooltip.js +0 -30
  95. package/dist/components/ui/tooltip.js.map +0 -1
  96. package/dist/hooks/index.d.ts +0 -10
  97. package/dist/hooks/index.d.ts.map +0 -1
  98. package/dist/hooks/index.js +0 -10
  99. package/dist/hooks/index.js.map +0 -1
  100. package/dist/hooks/use_chat_messages.d.ts +0 -25
  101. package/dist/hooks/use_chat_messages.d.ts.map +0 -1
  102. package/dist/hooks/use_chat_messages.js +0 -430
  103. package/dist/hooks/use_chat_messages.js.map +0 -1
  104. package/dist/hooks/use_chat_references.d.ts +0 -17
  105. package/dist/hooks/use_chat_references.d.ts.map +0 -1
  106. package/dist/hooks/use_chat_references.js +0 -133
  107. package/dist/hooks/use_chat_references.js.map +0 -1
  108. package/dist/hooks/use_file_upload.d.ts +0 -23
  109. package/dist/hooks/use_file_upload.d.ts.map +0 -1
  110. package/dist/hooks/use_file_upload.js +0 -212
  111. package/dist/hooks/use_file_upload.js.map +0 -1
  112. package/dist/index.d.ts +0 -13
  113. package/dist/index.d.ts.map +0 -1
  114. package/dist/index.js +0 -17
  115. package/dist/index.js.map +0 -1
  116. package/dist/lib/config.d.ts +0 -41
  117. package/dist/lib/config.d.ts.map +0 -1
  118. package/dist/lib/config.js +0 -93
  119. package/dist/lib/config.js.map +0 -1
  120. package/dist/lib/constants.d.ts +0 -39
  121. package/dist/lib/constants.d.ts.map +0 -1
  122. package/dist/lib/constants.js +0 -70
  123. package/dist/lib/constants.js.map +0 -1
  124. package/dist/lib/index.d.ts +0 -9
  125. package/dist/lib/index.d.ts.map +0 -1
  126. package/dist/lib/index.js +0 -9
  127. package/dist/lib/index.js.map +0 -1
  128. package/dist/lib/utils.d.ts +0 -17
  129. package/dist/lib/utils.d.ts.map +0 -1
  130. package/dist/lib/utils.js +0 -20
  131. package/dist/lib/utils.js.map +0 -1
  132. package/dist/types/index.d.ts +0 -367
  133. package/dist/types/index.d.ts.map +0 -1
  134. package/dist/types/index.js +0 -8
  135. package/dist/types/index.js.map +0 -1
package/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  A full-featured React chat component library for 1-1 communication with document sharing, file attachments, and real-time messaging capabilities.
4
4
 
5
+ **Version 2.0** - Now with API-first architecture! No server-side dependencies in client components.
6
+
5
7
  ## Features
6
8
 
7
9
  - 📱 **Responsive Design** - Works on desktop and mobile with adaptive layout
@@ -13,117 +15,107 @@ A full-featured React chat component library for 1-1 communication with document
13
15
  - ✅ **Read Receipts** - Track message read status
14
16
  - 🗑️ **Soft Delete** - Delete messages with undo capability
15
17
  - 🎨 **Customizable** - TailwindCSS-based theming
18
+ - 🚀 **API-First** - No server-side dependencies in client components
16
19
 
17
20
  ## Table of Contents
18
21
 
19
22
  - [Installation](#installation)
20
23
  - [Quick Start](#quick-start)
21
- - [Prerequisites](#prerequisites)
22
- - [Main Component](#main-component)
24
+ - [API Routes Setup](#api-routes-setup)
23
25
  - [Props Reference](#props-reference)
24
26
  - [Hooks](#hooks)
25
27
  - [Types](#types)
26
28
  - [Database Schema](#database-schema)
27
29
  - [Configuration](#configuration)
30
+ - [Migration from v1.x](#migration-from-v1x)
28
31
  - [Development](#development)
29
32
  - [License](#license)
30
33
 
31
34
  ## Installation
32
35
 
33
36
  ```bash
34
- npm install hazo_chat hazo_connect hazo_auth
37
+ npm install hazo_chat hazo_connect next
35
38
  ```
36
39
 
37
40
  ## Quick Start
38
41
 
42
+ ### Step 1: Create API Routes
43
+
44
+ The component communicates via API calls. Create the required endpoints:
45
+
46
+ ```typescript
47
+ // app/api/hazo_chat/messages/route.ts
48
+ import { createMessagesHandler } from 'hazo_chat/api';
49
+ import { getHazoConnectSingleton } from 'hazo_connect/nextjs/setup';
50
+
51
+ export const dynamic = 'force-dynamic';
52
+
53
+ const { GET, POST } = createMessagesHandler({
54
+ getHazoConnect: () => getHazoConnectSingleton()
55
+ });
56
+
57
+ export { GET, POST };
58
+ ```
59
+
60
+ ### Step 2: Use the Component
61
+
39
62
  ```tsx
40
63
  'use client';
41
64
 
42
65
  import { HazoChat } from 'hazo_chat';
43
- import { getHazoConnectSingleton } from 'hazo_connect/nextjs/setup';
44
66
 
45
- // Create hazo_auth service wrapper
46
- const hazo_auth = {
47
- hazo_get_auth: async () => {
48
- const response = await fetch('/api/hazo_auth/me');
49
- const data = await response.json();
50
- return data.is_authenticated ? { id: data.user_id, email: data.email } : null;
51
- },
52
- hazo_get_user_profiles: async (user_ids: string[]) => {
53
- const response = await fetch('/api/hazo_auth/profiles', {
54
- method: 'POST',
55
- headers: { 'Content-Type': 'application/json' },
56
- body: JSON.stringify({ user_ids }),
57
- });
58
- const data = await response.json();
59
- return data.profiles;
60
- },
61
- };
62
-
63
- function ChatPage() {
64
- const hazo_connect = getHazoConnectSingleton();
65
-
67
+ export default function ChatPage() {
66
68
  return (
67
- <HazoChat
68
- hazo_connect={hazo_connect}
69
- hazo_auth={hazo_auth}
70
- receiver_user_id="recipient-uuid"
71
- document_save_location="/uploads/chat"
72
- reference_id="conversation-123"
73
- reference_type="support"
74
- title="Chat with Support"
75
- subtitle="We're here to help"
76
- />
69
+ <div className="h-screen">
70
+ <HazoChat
71
+ receiver_user_id="recipient-uuid"
72
+ reference_id="conversation-123"
73
+ reference_type="support"
74
+ title="Chat with Support"
75
+ subtitle="We're here to help"
76
+ />
77
+ </div>
77
78
  );
78
79
  }
79
80
  ```
80
81
 
81
- ## Prerequisites
82
+ That's it! No need to pass database adapters or authentication services - everything works via API calls.
82
83
 
83
- ### Peer Dependencies
84
+ ## API Routes Setup
84
85
 
85
- | Package | Version | Description |
86
- |---------|---------|-------------|
87
- | `hazo_connect` | ^2.3.1 | Database adapter (required) |
88
- | `hazo_auth` | ^1.0.0 | Authentication service (required) |
89
- | `react` | ^18.0.0 | React framework |
90
- | `react-dom` | ^18.0.0 | React DOM |
86
+ hazo_chat requires these API endpoints:
91
87
 
92
- ### Required Setup
88
+ | Endpoint | Method | Description |
89
+ |----------|--------|-------------|
90
+ | `/api/hazo_chat/messages` | GET | Fetch chat messages |
91
+ | `/api/hazo_chat/messages` | POST | Send a new message |
92
+ | `/api/hazo_auth/me` | GET | Get current authenticated user |
93
+ | `/api/hazo_auth/profiles` | POST | Fetch user profiles by IDs |
93
94
 
94
- 1. **Database** - SQLite or PostgreSQL with the `hazo_chat` table
95
- 2. **Authentication** - Working hazo_auth setup with user management
96
- 3. **API Routes** - Backend endpoints for chat operations
97
- 4. **Configuration Files** - hazo_connect_config.ini for database connection
95
+ ### Using Exportable Handlers (Recommended)
98
96
 
99
- See [SETUP_CHECKLIST.md](./SETUP_CHECKLIST.md) for detailed setup instructions.
97
+ ```typescript
98
+ // app/api/hazo_chat/messages/route.ts
99
+ import { createMessagesHandler } from 'hazo_chat/api';
100
+ import { getHazoConnectSingleton } from 'hazo_connect/nextjs/setup';
100
101
 
101
- ## Main Component
102
+ export const dynamic = 'force-dynamic';
102
103
 
103
- ### HazoChat
104
+ const { GET, POST } = createMessagesHandler({
105
+ getHazoConnect: () => getHazoConnectSingleton(),
106
+ // Optional: custom authentication
107
+ getUserIdFromRequest: async (request) => {
108
+ // Return user ID from your auth system
109
+ return request.cookies.get('user_id')?.value || null;
110
+ }
111
+ });
104
112
 
105
- The primary component that provides a complete chat interface.
113
+ export { GET, POST };
114
+ ```
106
115
 
107
- ```tsx
108
- import { HazoChat } from 'hazo_chat';
116
+ ### Custom Implementation
109
117
 
110
- <HazoChat
111
- hazo_connect={adapter}
112
- hazo_auth={authService}
113
- receiver_user_id="user-123"
114
- document_save_location="/uploads"
115
- reference_id="project-456"
116
- reference_type="project_chat"
117
- timezone="Australia/Sydney"
118
- title="Project Discussion"
119
- subtitle="Design Review"
120
- additional_references={[
121
- { id: 'doc-1', type: 'document', name: 'Design.pdf', url: '/files/design.pdf', scope: 'field' }
122
- ]}
123
- on_close={() => console.log('Chat closed')}
124
- className="h-[600px]"
125
- />
126
- ```
118
+ If you need more control, implement the endpoints manually. See [SETUP_CHECKLIST.md](./SETUP_CHECKLIST.md) for detailed examples.
127
119
 
128
120
  ## Props Reference
129
121
 
@@ -131,12 +123,10 @@ import { HazoChat } from 'hazo_chat';
131
123
 
132
124
  | Prop | Type | Required | Default | Description |
133
125
  |------|------|----------|---------|-------------|
134
- | `hazo_connect` | `HazoConnectAdapter` | ✅ | - | Database adapter instance |
135
- | `hazo_auth` | `HazoAuthInstance` | ✅ | - | Authentication service |
136
126
  | `receiver_user_id` | `string` | ✅ | - | UUID of the chat recipient |
137
- | `document_save_location` | `string` | | - | Path for uploaded documents |
138
- | `reference_id` | `string` | ❌ | - | Main reference ID for the chat |
127
+ | `reference_id` | `string` | | - | Reference ID for chat context grouping |
139
128
  | `reference_type` | `string` | ❌ | `'chat'` | Type of reference |
129
+ | `api_base_url` | `string` | ❌ | `'/api/hazo_chat'` | Base URL for API endpoints |
140
130
  | `additional_references` | `ReferenceItem[]` | ❌ | `[]` | Pre-loaded document references |
141
131
  | `timezone` | `string` | ❌ | `'GMT+10'` | Timezone for timestamps |
142
132
  | `title` | `string` | ❌ | - | Chat header title |
@@ -144,25 +134,23 @@ import { HazoChat } from 'hazo_chat';
144
134
  | `on_close` | `() => void` | ❌ | - | Close button callback |
145
135
  | `className` | `string` | ❌ | - | Additional CSS classes |
146
136
 
147
- ### HazoAuthInstance
148
-
149
- The authentication service must implement these methods:
137
+ ### Example with All Props
150
138
 
151
- ```typescript
152
- interface HazoAuthInstance {
153
- /** Get current authenticated user */
154
- hazo_get_auth: () => Promise<{ id: string; email?: string } | null>;
155
-
156
- /** Get user profiles by IDs */
157
- hazo_get_user_profiles: (user_ids: string[]) => Promise<HazoUserProfile[]>;
158
- }
159
-
160
- interface HazoUserProfile {
161
- id: string;
162
- name: string;
163
- email?: string;
164
- avatar_url?: string;
165
- }
139
+ ```tsx
140
+ <HazoChat
141
+ receiver_user_id="user-123"
142
+ reference_id="project-456"
143
+ reference_type="project_chat"
144
+ api_base_url="/api/hazo_chat"
145
+ timezone="Australia/Sydney"
146
+ title="Project Discussion"
147
+ subtitle="Design Review"
148
+ additional_references={[
149
+ { id: 'doc-1', type: 'document', name: 'Design.pdf', url: '/files/design.pdf', scope: 'field' }
150
+ ]}
151
+ on_close={() => console.log('Chat closed')}
152
+ className="h-[600px]"
153
+ />
166
154
  ```
167
155
 
168
156
  ## Hooks
@@ -187,10 +175,10 @@ const {
187
175
  mark_as_read, // (message_id) => Promise<void>
188
176
  refresh, // () => void - Reload messages
189
177
  } = useChatMessages({
190
- hazo_connect,
191
- hazo_auth,
192
- reference_id: 'chat-123',
193
178
  receiver_user_id: 'user-456',
179
+ reference_id: 'chat-123',
180
+ reference_type: 'direct',
181
+ api_base_url: '/api/hazo_chat',
194
182
  polling_interval: 5000, // Optional, default: 5000ms
195
183
  messages_per_page: 20, // Optional, default: 20
196
184
  });
@@ -233,10 +221,9 @@ const {
233
221
  is_uploading, // boolean
234
222
  validation_errors, // string[]
235
223
  } = useFileUpload({
236
- upload_location: '/uploads/chat',
224
+ upload_location: '/api/hazo_chat/uploads',
237
225
  max_file_size_mb: 10, // Optional, default: 10
238
226
  allowed_types: ['pdf', 'png', 'jpg'], // Optional
239
- upload_function: customUploader, // Optional custom uploader
240
227
  });
241
228
  ```
242
229
 
@@ -264,6 +251,17 @@ interface ChatMessage {
264
251
  }
265
252
  ```
266
253
 
254
+ ### HazoUserProfile
255
+
256
+ ```typescript
257
+ interface HazoUserProfile {
258
+ id: string;
259
+ name: string;
260
+ email?: string;
261
+ avatar_url?: string;
262
+ }
263
+ ```
264
+
267
265
  ### ChatReferenceItem
268
266
 
269
267
  ```typescript
@@ -279,18 +277,6 @@ interface ChatReferenceItem {
279
277
  }
280
278
  ```
281
279
 
282
- ### CreateMessagePayload
283
-
284
- ```typescript
285
- interface CreateMessagePayload {
286
- reference_id: string;
287
- reference_type: string;
288
- receiver_user_id: string;
289
- message_text: string;
290
- reference_list?: ChatReferenceItem[];
291
- }
292
- ```
293
-
294
280
  ## Database Schema
295
281
 
296
282
  ### hazo_chat Table
@@ -307,11 +293,7 @@ CREATE TABLE hazo_chat (
307
293
  read_at TEXT,
308
294
  deleted_at TEXT,
309
295
  created_at TEXT NOT NULL,
310
- changed_at TEXT NOT NULL,
311
-
312
- -- Foreign keys (if using referential integrity)
313
- FOREIGN KEY (sender_user_id) REFERENCES hazo_users(id),
314
- FOREIGN KEY (receiver_user_id) REFERENCES hazo_users(id)
296
+ changed_at TEXT NOT NULL
315
297
  );
316
298
 
317
299
  -- Indexes for performance
@@ -341,14 +323,56 @@ max_file_size_mb = 10
341
323
  allowed_types = pdf,png,jpg,jpeg,gif,txt,doc,docx
342
324
  ```
343
325
 
344
- ### Default Values
326
+ ## Migration from v1.x
327
+
328
+ Version 2.0 introduces breaking changes for a simpler, more reliable architecture.
329
+
330
+ ### What Changed
331
+
332
+ | v1.x | v2.x |
333
+ |------|------|
334
+ | Pass `hazo_connect` prop | Not needed - uses API calls |
335
+ | Pass `hazo_auth` prop | Not needed - uses API calls |
336
+ | Pass `document_save_location` prop | Not needed |
337
+ | Direct database access | API-based data access |
338
+
339
+ ### Migration Steps
340
+
341
+ 1. **Remove adapter props:**
342
+
343
+ ```tsx
344
+ // Before (v1.x)
345
+ <HazoChat
346
+ hazo_connect={adapter}
347
+ hazo_auth={authService}
348
+ document_save_location="/uploads"
349
+ receiver_user_id="..."
350
+ />
351
+
352
+ // After (v2.x)
353
+ <HazoChat
354
+ receiver_user_id="..."
355
+ />
356
+ ```
357
+
358
+ 2. **Create API routes** (see [API Routes Setup](#api-routes-setup))
359
+
360
+ 3. **Update imports:**
361
+
362
+ ```typescript
363
+ // The API handler factory is new
364
+ import { createMessagesHandler } from 'hazo_chat/api';
365
+ ```
366
+
367
+ ### Why the Change?
368
+
369
+ The v1.x architecture required passing server-side adapters (`hazo_connect`, `hazo_auth`) to client components. This caused issues:
345
370
 
346
- | Setting | Default | Description |
347
- |---------|---------|-------------|
348
- | `polling_interval` | 5000ms | How often to check for new messages |
349
- | `messages_per_page` | 20 | Messages loaded per pagination request |
350
- | `max_file_size_mb` | 10 | Maximum upload file size |
351
- | `timezone` | 'GMT+10' | Default timezone for timestamps |
371
+ - "Module not found: Can't resolve 'fs'" errors
372
+ - Hydration mismatches
373
+ - Complex webpack configuration
374
+
375
+ The v2.x API-first architecture solves these by keeping all server code in API routes.
352
376
 
353
377
  ## Development
354
378
 
@@ -372,30 +396,17 @@ npm run dev:test-app
372
396
  npm run build:test-app
373
397
  ```
374
398
 
375
- ### Project Structure
376
-
377
- ```
378
- hazo_chat/
379
- ├── src/
380
- │ ├── components/
381
- │ │ ├── hazo_chat/ # Main chat components
382
- │ │ └── ui/ # Reusable UI components
383
- │ ├── hooks/ # React hooks
384
- │ ├── lib/ # Utilities and constants
385
- │ └── types/ # TypeScript definitions
386
- ├── test-app/ # Next.js test application
387
- ├── dist/ # Compiled output (git-ignored)
388
- └── package.json
389
- ```
390
-
391
399
  ### Package Exports
392
400
 
393
401
  ```typescript
394
402
  // Main export
395
403
  import { HazoChat, useChatMessages, useChatReferences, useFileUpload } from 'hazo_chat';
396
404
 
405
+ // API handlers (for server-side routes)
406
+ import { createMessagesHandler } from 'hazo_chat/api';
407
+
397
408
  // Components only
398
- import { HazoChat, ChatBubble, ChatInput } from 'hazo_chat/components';
409
+ import { HazoChat, ChatBubble } from 'hazo_chat/components';
399
410
 
400
411
  // Library utilities
401
412
  import { DEFAULT_POLLING_INTERVAL, MIME_TYPE_MAP } from 'hazo_chat/lib';
@@ -405,22 +416,20 @@ import { DEFAULT_POLLING_INTERVAL, MIME_TYPE_MAP } from 'hazo_chat/lib';
405
416
 
406
417
  ### Common Issues
407
418
 
408
- 1. **"hazo_connect.from is not a function"**
409
- - Ensure you're using `getHazoConnectSingleton()` from `hazo_connect/nextjs/setup`
410
- - The adapter must be the HazoConnectAdapter type, not a raw connection
419
+ 1. **"Module not found: Can't resolve 'fs'"**
420
+ - This shouldn't happen in v2.x. If it does, ensure you're not importing from `hazo_connect/server` in client components.
411
421
 
412
- 2. **Hydration errors**
413
- - Wrap client components in Suspense boundaries
414
- - Use `mounted` state to delay client-side rendering
422
+ 2. **Messages not loading**
423
+ - Check that API routes exist and return correct responses
424
+ - Verify authentication (check `/api/hazo_auth/me`)
425
+ - Check browser console and network tab for errors
415
426
 
416
- 3. **Module not found errors**
417
- - Add transpilePackages in next.config.js: `['hazo_chat', 'hazo_connect', 'hazo_auth']`
418
- - Check webpack aliases for hazo_auth imports
427
+ 3. **401 Unauthorized errors**
428
+ - Ensure the user is logged in
429
+ - Check that `hazo_auth_user_id` cookie is set
419
430
 
420
- 4. **Messages not loading**
421
- - Verify database connection in hazo_connect_config.ini
422
- - Check API route `/api/hazo_chat/messages` exists and works
423
- - Ensure `reference_id` is provided to the component
431
+ 4. **CORS errors**
432
+ - API routes should be on the same domain as the frontend
424
433
 
425
434
  ## Related Packages
426
435