hazo_chat 1.1.0 → 2.0.1
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 +161 -152
- package/SETUP_CHECKLIST.md +191 -587
- package/dist/api/index.d.ts +24 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +24 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/messages.d.ts +34 -0
- package/dist/api/messages.d.ts.map +1 -0
- package/dist/api/messages.js +210 -0
- package/dist/api/messages.js.map +1 -0
- package/dist/api/types.d.ts +69 -0
- package/dist/api/types.d.ts.map +1 -0
- package/dist/api/types.js +8 -0
- package/dist/api/types.js.map +1 -0
- package/dist/components/hazo_chat/hazo_chat.d.ts +13 -1
- package/dist/components/hazo_chat/hazo_chat.d.ts.map +1 -1
- package/dist/components/hazo_chat/hazo_chat.js +26 -14
- package/dist/components/hazo_chat/hazo_chat.js.map +1 -1
- package/dist/components/hazo_chat/hazo_chat_context.d.ts +11 -5
- package/dist/components/hazo_chat/hazo_chat_context.d.ts.map +1 -1
- package/dist/components/hazo_chat/hazo_chat_context.js +22 -10
- package/dist/components/hazo_chat/hazo_chat_context.js.map +1 -1
- package/dist/components/hazo_chat/hazo_chat_header.d.ts +1 -1
- package/dist/components/hazo_chat/hazo_chat_header.d.ts.map +1 -1
- package/dist/components/hazo_chat/hazo_chat_header.js +3 -3
- package/dist/components/hazo_chat/hazo_chat_header.js.map +1 -1
- package/dist/hooks/use_chat_messages.d.ts +14 -9
- package/dist/hooks/use_chat_messages.d.ts.map +1 -1
- package/dist/hooks/use_chat_messages.js +117 -115
- package/dist/hooks/use_chat_messages.js.map +1 -1
- package/dist/types/index.d.ts +39 -28
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -1
- package/package.json +17 -7
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* hazo_chat API Module
|
|
3
|
+
*
|
|
4
|
+
* Provides exportable API route handlers for Next.js applications.
|
|
5
|
+
* These handlers can be imported and re-exported in your API routes.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* // app/api/hazo_chat/messages/route.ts
|
|
10
|
+
* import { createMessagesHandler } from 'hazo_chat/api';
|
|
11
|
+
* import { getHazoConnectSingleton } from 'hazo_connect/nextjs/setup';
|
|
12
|
+
*
|
|
13
|
+
* export const dynamic = 'force-dynamic';
|
|
14
|
+
*
|
|
15
|
+
* const { GET, POST } = createMessagesHandler({
|
|
16
|
+
* getHazoConnect: () => getHazoConnectSingleton()
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* export { GET, POST };
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export { createMessagesHandler } from './messages.js';
|
|
23
|
+
export type { MessagesHandlerOptions, ChatMessageInput, ChatMessageRecord } from './types.js';
|
|
24
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAGtD,YAAY,EACV,sBAAsB,EACtB,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* hazo_chat API Module
|
|
3
|
+
*
|
|
4
|
+
* Provides exportable API route handlers for Next.js applications.
|
|
5
|
+
* These handlers can be imported and re-exported in your API routes.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* // app/api/hazo_chat/messages/route.ts
|
|
10
|
+
* import { createMessagesHandler } from 'hazo_chat/api';
|
|
11
|
+
* import { getHazoConnectSingleton } from 'hazo_connect/nextjs/setup';
|
|
12
|
+
*
|
|
13
|
+
* export const dynamic = 'force-dynamic';
|
|
14
|
+
*
|
|
15
|
+
* const { GET, POST } = createMessagesHandler({
|
|
16
|
+
* getHazoConnect: () => getHazoConnectSingleton()
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* export { GET, POST };
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
// Export handler factories
|
|
23
|
+
export { createMessagesHandler } from './messages.js';
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,2BAA2B;AAC3B,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Messages API Handler Factory
|
|
3
|
+
*
|
|
4
|
+
* Creates GET and POST handlers for the /api/hazo_chat/messages endpoint.
|
|
5
|
+
* These handlers should be used in a Next.js API route.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* // app/api/hazo_chat/messages/route.ts
|
|
10
|
+
* import { createMessagesHandler } from 'hazo_chat/api';
|
|
11
|
+
* import { getHazoConnectSingleton } from 'hazo_connect/nextjs/setup';
|
|
12
|
+
*
|
|
13
|
+
* export const dynamic = 'force-dynamic';
|
|
14
|
+
*
|
|
15
|
+
* const { GET, POST } = createMessagesHandler({
|
|
16
|
+
* getHazoConnect: () => getHazoConnectSingleton()
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* export { GET, POST };
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
23
|
+
import type { MessagesHandlerOptions } from './types.js';
|
|
24
|
+
/**
|
|
25
|
+
* Creates GET and POST handlers for chat messages
|
|
26
|
+
*
|
|
27
|
+
* @param options - Configuration options
|
|
28
|
+
* @returns Object with GET and POST handlers
|
|
29
|
+
*/
|
|
30
|
+
export declare function createMessagesHandler(options: MessagesHandlerOptions): {
|
|
31
|
+
GET: (request: NextRequest) => Promise<NextResponse>;
|
|
32
|
+
POST: (request: NextRequest) => Promise<NextResponse>;
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=messages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/api/messages.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAIxD,OAAO,KAAK,EAAE,sBAAsB,EAAuC,MAAM,YAAY,CAAC;AAmB9F;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,sBAAsB;mBAWvC,WAAW,KAAG,OAAO,CAAC,YAAY,CAAC;oBA+FlC,WAAW,KAAG,OAAO,CAAC,YAAY,CAAC;EAsGjE"}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Messages API Handler Factory
|
|
3
|
+
*
|
|
4
|
+
* Creates GET and POST handlers for the /api/hazo_chat/messages endpoint.
|
|
5
|
+
* These handlers should be used in a Next.js API route.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* // app/api/hazo_chat/messages/route.ts
|
|
10
|
+
* import { createMessagesHandler } from 'hazo_chat/api';
|
|
11
|
+
* import { getHazoConnectSingleton } from 'hazo_connect/nextjs/setup';
|
|
12
|
+
*
|
|
13
|
+
* export const dynamic = 'force-dynamic';
|
|
14
|
+
*
|
|
15
|
+
* const { GET, POST } = createMessagesHandler({
|
|
16
|
+
* getHazoConnect: () => getHazoConnectSingleton()
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* export { GET, POST };
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
import { NextResponse } from 'next/server';
|
|
23
|
+
import { cookies } from 'next/headers';
|
|
24
|
+
import { createCrudService } from 'hazo_connect/server';
|
|
25
|
+
// UUID generation for message IDs
|
|
26
|
+
function generateUUID() {
|
|
27
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
28
|
+
const r = Math.random() * 16 | 0;
|
|
29
|
+
const v = c === 'x' ? r : (r & 0x3 | 0x8);
|
|
30
|
+
return v.toString(16);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Default function to get user ID from request cookies
|
|
35
|
+
*/
|
|
36
|
+
function defaultGetUserIdFromRequest() {
|
|
37
|
+
const cookieStore = cookies();
|
|
38
|
+
return cookieStore.get('hazo_auth_user_id')?.value || null;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Creates GET and POST handlers for chat messages
|
|
42
|
+
*
|
|
43
|
+
* @param options - Configuration options
|
|
44
|
+
* @returns Object with GET and POST handlers
|
|
45
|
+
*/
|
|
46
|
+
export function createMessagesHandler(options) {
|
|
47
|
+
const { getHazoConnect, getUserIdFromRequest } = options;
|
|
48
|
+
/**
|
|
49
|
+
* GET handler - Fetch chat messages
|
|
50
|
+
*
|
|
51
|
+
* Query params:
|
|
52
|
+
* - receiver_user_id (required): The other user in the conversation
|
|
53
|
+
* - reference_id (optional): Filter by reference ID
|
|
54
|
+
* - reference_type (optional): Filter by reference type
|
|
55
|
+
*/
|
|
56
|
+
async function GET(request) {
|
|
57
|
+
try {
|
|
58
|
+
// Get current user ID
|
|
59
|
+
const current_user_id = getUserIdFromRequest
|
|
60
|
+
? await getUserIdFromRequest(request)
|
|
61
|
+
: defaultGetUserIdFromRequest();
|
|
62
|
+
if (!current_user_id) {
|
|
63
|
+
console.error('[hazo_chat/messages GET] No user ID - not authenticated');
|
|
64
|
+
return NextResponse.json({ success: false, error: 'User not authenticated', messages: [] }, { status: 401 });
|
|
65
|
+
}
|
|
66
|
+
// Get query params
|
|
67
|
+
const { searchParams } = new URL(request.url);
|
|
68
|
+
const receiver_user_id = searchParams.get('receiver_user_id');
|
|
69
|
+
const reference_id = searchParams.get('reference_id') || '';
|
|
70
|
+
const reference_type = searchParams.get('reference_type') || '';
|
|
71
|
+
if (!receiver_user_id) {
|
|
72
|
+
console.error('[hazo_chat/messages GET] Missing receiver_user_id');
|
|
73
|
+
return NextResponse.json({ success: false, error: 'receiver_user_id is required', messages: [] }, { status: 400 });
|
|
74
|
+
}
|
|
75
|
+
console.log('[hazo_chat/messages GET] Fetching messages:', {
|
|
76
|
+
current_user_id,
|
|
77
|
+
receiver_user_id,
|
|
78
|
+
reference_id,
|
|
79
|
+
reference_type,
|
|
80
|
+
});
|
|
81
|
+
// Get hazo_connect instance and create CRUD service
|
|
82
|
+
const hazoConnect = getHazoConnect();
|
|
83
|
+
const chatService = createCrudService(hazoConnect, 'hazo_chat');
|
|
84
|
+
let messages = [];
|
|
85
|
+
try {
|
|
86
|
+
// Fetch all messages with reference filters
|
|
87
|
+
const all_messages = await chatService.list((qb) => {
|
|
88
|
+
let builder = qb.select('*');
|
|
89
|
+
if (reference_id) {
|
|
90
|
+
builder = builder.where('reference_id', 'eq', reference_id);
|
|
91
|
+
}
|
|
92
|
+
if (reference_type) {
|
|
93
|
+
builder = builder.where('reference_type', 'eq', reference_type);
|
|
94
|
+
}
|
|
95
|
+
return builder.order('created_at', 'asc');
|
|
96
|
+
});
|
|
97
|
+
// Filter to only messages between current user and receiver
|
|
98
|
+
messages = all_messages.filter((msg) => {
|
|
99
|
+
const is_sent_by_me = msg.sender_user_id === current_user_id && msg.receiver_user_id === receiver_user_id;
|
|
100
|
+
const is_sent_to_me = msg.sender_user_id === receiver_user_id && msg.receiver_user_id === current_user_id;
|
|
101
|
+
return is_sent_by_me || is_sent_to_me;
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
catch (dbError) {
|
|
105
|
+
console.error('[hazo_chat/messages GET] Database error:', dbError);
|
|
106
|
+
throw dbError;
|
|
107
|
+
}
|
|
108
|
+
console.log('[hazo_chat/messages GET] Found messages:', messages.length);
|
|
109
|
+
return NextResponse.json({
|
|
110
|
+
success: true,
|
|
111
|
+
messages,
|
|
112
|
+
current_user_id,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
const error_message = error instanceof Error ? error.message : 'Unknown error';
|
|
117
|
+
console.error('[hazo_chat/messages GET] Error:', error_message, error);
|
|
118
|
+
return NextResponse.json({ success: false, error: 'Failed to fetch messages', messages: [] }, { status: 500 });
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* POST handler - Create a new chat message
|
|
123
|
+
*
|
|
124
|
+
* Request body:
|
|
125
|
+
* - receiver_user_id (required): The recipient user ID
|
|
126
|
+
* - message_text (required): The message content
|
|
127
|
+
* - reference_id (optional): Reference ID for context grouping
|
|
128
|
+
* - reference_type (optional): Reference type (default: 'chat')
|
|
129
|
+
*/
|
|
130
|
+
async function POST(request) {
|
|
131
|
+
try {
|
|
132
|
+
// Get current user ID (sender)
|
|
133
|
+
const sender_user_id = getUserIdFromRequest
|
|
134
|
+
? await getUserIdFromRequest(request)
|
|
135
|
+
: defaultGetUserIdFromRequest();
|
|
136
|
+
if (!sender_user_id) {
|
|
137
|
+
console.error('[hazo_chat/messages POST] No user ID - not authenticated');
|
|
138
|
+
return NextResponse.json({ success: false, error: 'User not authenticated' }, { status: 401 });
|
|
139
|
+
}
|
|
140
|
+
// Parse request body
|
|
141
|
+
const body = await request.json();
|
|
142
|
+
const { receiver_user_id, message_text, reference_id, reference_type } = body;
|
|
143
|
+
// Validate required fields
|
|
144
|
+
if (!receiver_user_id) {
|
|
145
|
+
console.error('[hazo_chat/messages POST] Missing receiver_user_id');
|
|
146
|
+
return NextResponse.json({ success: false, error: 'receiver_user_id is required' }, { status: 400 });
|
|
147
|
+
}
|
|
148
|
+
if (!message_text || message_text.trim() === '') {
|
|
149
|
+
console.error('[hazo_chat/messages POST] Missing or empty message_text');
|
|
150
|
+
return NextResponse.json({ success: false, error: 'message_text is required' }, { status: 400 });
|
|
151
|
+
}
|
|
152
|
+
// Get hazo_connect instance and create CRUD service
|
|
153
|
+
const hazoConnect = getHazoConnect();
|
|
154
|
+
const chatService = createCrudService(hazoConnect, 'hazo_chat');
|
|
155
|
+
// Generate message ID and timestamps
|
|
156
|
+
const message_id = generateUUID();
|
|
157
|
+
const now = new Date().toISOString();
|
|
158
|
+
// Create message record
|
|
159
|
+
const message_record = {
|
|
160
|
+
id: message_id,
|
|
161
|
+
reference_id: reference_id || '',
|
|
162
|
+
reference_type: reference_type || 'chat',
|
|
163
|
+
sender_user_id,
|
|
164
|
+
receiver_user_id,
|
|
165
|
+
message_text: message_text.trim(),
|
|
166
|
+
reference_list: null,
|
|
167
|
+
read_at: null,
|
|
168
|
+
deleted_at: null,
|
|
169
|
+
created_at: now,
|
|
170
|
+
changed_at: now,
|
|
171
|
+
};
|
|
172
|
+
console.log('[hazo_chat/messages POST] Saving message:', {
|
|
173
|
+
id: message_id,
|
|
174
|
+
sender_user_id,
|
|
175
|
+
receiver_user_id,
|
|
176
|
+
reference_id: reference_id || '',
|
|
177
|
+
reference_type: reference_type || 'chat',
|
|
178
|
+
message_length: message_text.length,
|
|
179
|
+
});
|
|
180
|
+
// Save to database
|
|
181
|
+
try {
|
|
182
|
+
await chatService.insert(message_record);
|
|
183
|
+
}
|
|
184
|
+
catch (dbError) {
|
|
185
|
+
console.error('[hazo_chat/messages POST] Database error:', dbError);
|
|
186
|
+
throw dbError;
|
|
187
|
+
}
|
|
188
|
+
console.log('[hazo_chat/messages POST] Message saved successfully:', message_id);
|
|
189
|
+
return NextResponse.json({
|
|
190
|
+
success: true,
|
|
191
|
+
message: {
|
|
192
|
+
id: message_id,
|
|
193
|
+
sender_user_id,
|
|
194
|
+
receiver_user_id,
|
|
195
|
+
reference_id: reference_id || '',
|
|
196
|
+
reference_type: reference_type || 'chat',
|
|
197
|
+
message_text: message_text.trim(),
|
|
198
|
+
created_at: now,
|
|
199
|
+
},
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
catch (error) {
|
|
203
|
+
const error_message = error instanceof Error ? error.message : 'Unknown error';
|
|
204
|
+
console.error('[hazo_chat/messages POST] Error:', error_message, error);
|
|
205
|
+
return NextResponse.json({ success: false, error: 'Failed to save message' }, { status: 500 });
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return { GET, POST };
|
|
209
|
+
}
|
|
210
|
+
//# sourceMappingURL=messages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.js","sourceRoot":"","sources":["../../src/api/messages.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAe,YAAY,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAIxD,kCAAkC;AAClC,SAAS,YAAY;IACnB,OAAO,sCAAsC,CAAC,OAAO,CAAC,OAAO,EAAE,UAAS,CAAC;QACvE,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;QACjC,MAAM,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC;QAC1C,OAAO,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACxB,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,SAAS,2BAA2B;IAClC,MAAM,WAAW,GAAG,OAAO,EAAE,CAAC;IAC9B,OAAO,WAAW,CAAC,GAAG,CAAC,mBAAmB,CAAC,EAAE,KAAK,IAAI,IAA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@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API Handler Types
|
|
3
|
+
*
|
|
4
|
+
* Shared types for the exportable API route handlers.
|
|
5
|
+
* These are used by consumers when setting up their API routes.
|
|
6
|
+
*/
|
|
7
|
+
import type { NextRequest } from 'next/server';
|
|
8
|
+
/**
|
|
9
|
+
* Options for creating message API handlers
|
|
10
|
+
*/
|
|
11
|
+
export interface MessagesHandlerOptions {
|
|
12
|
+
/**
|
|
13
|
+
* Function to get the hazo_connect adapter instance.
|
|
14
|
+
* Called on each request to get a fresh connection.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import { getHazoConnectSingleton } from 'hazo_connect/nextjs/setup';
|
|
19
|
+
*
|
|
20
|
+
* const options = {
|
|
21
|
+
* getHazoConnect: () => getHazoConnectSingleton()
|
|
22
|
+
* };
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
getHazoConnect: () => unknown;
|
|
26
|
+
/**
|
|
27
|
+
* Optional function to extract user ID from the request.
|
|
28
|
+
* Defaults to reading from 'hazo_auth_user_id' cookie.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* // Custom auth extraction
|
|
33
|
+
* const options = {
|
|
34
|
+
* getUserIdFromRequest: (request) => {
|
|
35
|
+
* const token = request.headers.get('Authorization');
|
|
36
|
+
* return decodeToken(token)?.userId || null;
|
|
37
|
+
* }
|
|
38
|
+
* };
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
getUserIdFromRequest?: (request: NextRequest) => string | null | Promise<string | null>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Chat message input for creating new messages
|
|
45
|
+
*/
|
|
46
|
+
export interface ChatMessageInput {
|
|
47
|
+
receiver_user_id: string;
|
|
48
|
+
message_text: string;
|
|
49
|
+
reference_id?: string;
|
|
50
|
+
reference_type?: string;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Chat message database record
|
|
54
|
+
*/
|
|
55
|
+
export interface ChatMessageRecord {
|
|
56
|
+
id: string;
|
|
57
|
+
reference_id: string;
|
|
58
|
+
reference_type: string;
|
|
59
|
+
sender_user_id: string;
|
|
60
|
+
receiver_user_id: string;
|
|
61
|
+
message_text: string;
|
|
62
|
+
reference_list: string | null;
|
|
63
|
+
read_at: string | null;
|
|
64
|
+
deleted_at: string | null;
|
|
65
|
+
created_at: string;
|
|
66
|
+
changed_at: string;
|
|
67
|
+
[key: string]: unknown;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/api/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC;;;;;;;;;;;;OAYG;IACH,cAAc,EAAE,MAAM,OAAO,CAAC;IAE9B;;;;;;;;;;;;;;OAcG;IACH,oBAAoB,CAAC,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;CACzF;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/api/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
|
@@ -4,11 +4,23 @@
|
|
|
4
4
|
* Main chat UI component with:
|
|
5
5
|
* - Responsive grid layout (sidebar + chat area)
|
|
6
6
|
* - Context provider for shared state
|
|
7
|
-
* - Integration with hazo_connect, hazo_auth
|
|
8
7
|
* - Document viewer and reference list
|
|
9
8
|
* - Message polling and pagination
|
|
9
|
+
*
|
|
10
|
+
* Uses API calls internally - no server-side dependencies required.
|
|
10
11
|
*/
|
|
11
12
|
import type { HazoChatProps } from '../../types/index.js';
|
|
13
|
+
/**
|
|
14
|
+
* HazoChat - Main chat component
|
|
15
|
+
*
|
|
16
|
+
* Uses API calls internally for all data operations.
|
|
17
|
+
* Requires the following API routes to be set up:
|
|
18
|
+
* - GET/POST /api/hazo_chat/messages
|
|
19
|
+
* - GET /api/hazo_auth/me
|
|
20
|
+
* - POST /api/hazo_auth/profiles
|
|
21
|
+
*
|
|
22
|
+
* See SETUP_CHECKLIST.md for detailed setup instructions.
|
|
23
|
+
*/
|
|
12
24
|
export declare function HazoChat(props: HazoChatProps): import("react/jsx-runtime").JSX.Element;
|
|
13
25
|
export declare namespace HazoChat {
|
|
14
26
|
var displayName: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hazo_chat.d.ts","sourceRoot":"","sources":["../../../src/components/hazo_chat/hazo_chat.tsx"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"hazo_chat.d.ts","sourceRoot":"","sources":["../../../src/components/hazo_chat/hazo_chat.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAMH,OAAO,KAAK,EACV,aAAa,EAId,MAAM,sBAAsB,CAAC;AA6T9B;;;;;;;;;;GAUG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,aAAa,2CA6C5C;yBA7Ce,QAAQ"}
|
|
@@ -4,9 +4,10 @@
|
|
|
4
4
|
* Main chat UI component with:
|
|
5
5
|
* - Responsive grid layout (sidebar + chat area)
|
|
6
6
|
* - Context provider for shared state
|
|
7
|
-
* - Integration with hazo_connect, hazo_auth
|
|
8
7
|
* - Document viewer and reference list
|
|
9
8
|
* - Message polling and pagination
|
|
9
|
+
*
|
|
10
|
+
* Uses API calls internally - no server-side dependencies required.
|
|
10
11
|
*/
|
|
11
12
|
'use client';
|
|
12
13
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
@@ -25,24 +26,24 @@ import { TooltipProvider } from '../ui/tooltip.js';
|
|
|
25
26
|
import { useChatMessages } from '../../hooks/use_chat_messages.js';
|
|
26
27
|
import { useChatReferences } from '../../hooks/use_chat_references.js';
|
|
27
28
|
import { useFileUpload } from '../../hooks/use_file_upload.js';
|
|
28
|
-
function HazoChatInner({
|
|
29
|
+
function HazoChatInner({ receiver_user_id, reference_id = '', reference_type = 'chat', api_base_url = '/api/hazo_chat', additional_references = [], timezone = DEFAULT_TIMEZONE, title, subtitle, on_close, className, polling_interval = DEFAULT_POLLING_INTERVAL, messages_per_page = DEFAULT_MESSAGES_PER_PAGE }) {
|
|
29
30
|
// Get context
|
|
30
31
|
const { current_user, selected_reference, highlighted_message_id, pending_attachments, is_sidebar_open, set_selected_reference, set_highlighted_message_id, add_pending_attachment, remove_pending_attachment, clear_pending_attachments, toggle_sidebar, set_sidebar_open, add_reference } = useHazoChatContext();
|
|
31
32
|
// -------------------------------------------------------------------------
|
|
32
|
-
// Messages hook
|
|
33
|
+
// Messages hook (uses API calls)
|
|
33
34
|
// -------------------------------------------------------------------------
|
|
34
|
-
const { messages, is_loading: is_loading_messages, has_more, load_more, send_message, delete_message, polling_status } = useChatMessages({
|
|
35
|
-
hazo_connect,
|
|
36
|
-
hazo_auth: { hazo_get_auth: async () => current_user ? { id: current_user.id } : null, hazo_get_user_profiles: async () => [] },
|
|
37
|
-
reference_id,
|
|
35
|
+
const { messages, is_loading: is_loading_messages, has_more, load_more, send_message, delete_message, polling_status, refresh: refresh_messages } = useChatMessages({
|
|
38
36
|
receiver_user_id,
|
|
37
|
+
reference_id,
|
|
38
|
+
reference_type,
|
|
39
|
+
api_base_url,
|
|
39
40
|
polling_interval,
|
|
40
41
|
messages_per_page
|
|
41
42
|
});
|
|
42
43
|
// -------------------------------------------------------------------------
|
|
43
44
|
// References hook
|
|
44
45
|
// -------------------------------------------------------------------------
|
|
45
|
-
const { references, select_reference
|
|
46
|
+
const { references, select_reference } = useChatReferences({
|
|
46
47
|
messages,
|
|
47
48
|
initial_references: additional_references.map((ref) => ({
|
|
48
49
|
...ref,
|
|
@@ -62,13 +63,13 @@ function HazoChatInner({ hazo_connect, receiver_user_id, document_save_location,
|
|
|
62
63
|
// File upload hook
|
|
63
64
|
// -------------------------------------------------------------------------
|
|
64
65
|
const { add_files, remove_file, upload_all, is_uploading } = useFileUpload({
|
|
65
|
-
upload_location:
|
|
66
|
+
upload_location: `${api_base_url}/uploads`
|
|
66
67
|
});
|
|
67
68
|
// -------------------------------------------------------------------------
|
|
68
69
|
// Handle send message
|
|
69
70
|
// -------------------------------------------------------------------------
|
|
70
71
|
const handle_send = useCallback(async (text, attachments) => {
|
|
71
|
-
if (!current_user
|
|
72
|
+
if (!current_user)
|
|
72
73
|
return;
|
|
73
74
|
// Upload pending files first
|
|
74
75
|
const uploaded = await upload_all();
|
|
@@ -86,7 +87,7 @@ function HazoChatInner({ hazo_connect, receiver_user_id, document_save_location,
|
|
|
86
87
|
file_size: file.file_size
|
|
87
88
|
}));
|
|
88
89
|
const payload = {
|
|
89
|
-
reference_id,
|
|
90
|
+
reference_id: reference_id || '',
|
|
90
91
|
reference_type,
|
|
91
92
|
receiver_user_id,
|
|
92
93
|
message_text: text,
|
|
@@ -133,7 +134,7 @@ function HazoChatInner({ hazo_connect, receiver_user_id, document_save_location,
|
|
|
133
134
|
// -------------------------------------------------------------------------
|
|
134
135
|
// Render
|
|
135
136
|
// -------------------------------------------------------------------------
|
|
136
|
-
return (_jsxs("div", { className: cn('cls_hazo_chat', 'flex flex-col h-full w-full', 'bg-background rounded-lg border overflow-hidden', className), children: [_jsx(HazoChatHeader, { title: title, subtitle: subtitle, on_close: on_close, on_toggle_sidebar: toggle_sidebar, is_sidebar_open: is_sidebar_open }), _jsx("div", { className: "cls_references_row border-b bg-muted/30", children: _jsxs("div", { className: "cls_references_container px-3 py-2", children: [_jsx("h3", { className: "text-[10px] font-medium text-muted-foreground uppercase tracking-wider mb-1.5", children: "References" }), _jsx(HazoChatReferenceList, { references: references, selected_reference_id: selected_reference?.id, on_select: handle_reference_select, className: "flex-wrap" })] }) }), _jsxs("div", { className: "cls_main_content flex flex-1 overflow-hidden relative", children: [_jsx("div", { className: cn('cls_doc_preview_column', 'border-r bg-muted/20', 'w-[280px] md:w-[320px] lg:w-[380px]', 'flex-shrink-0', 'flex flex-col',
|
|
137
|
+
return (_jsxs("div", { className: cn('cls_hazo_chat', 'flex flex-col h-full w-full', 'bg-background rounded-lg border overflow-hidden', className), children: [_jsx(HazoChatHeader, { title: title, subtitle: subtitle, on_close: on_close, on_refresh: refresh_messages, is_refreshing: is_loading_messages, on_toggle_sidebar: toggle_sidebar, is_sidebar_open: is_sidebar_open }), _jsx("div", { className: "cls_references_row border-b bg-muted/30", children: _jsxs("div", { className: "cls_references_container px-3 py-2", children: [_jsx("h3", { className: "text-[10px] font-medium text-muted-foreground uppercase tracking-wider mb-1.5", children: "References" }), _jsx(HazoChatReferenceList, { references: references, selected_reference_id: selected_reference?.id, on_select: handle_reference_select, className: "flex-wrap" })] }) }), _jsxs("div", { className: "cls_main_content flex flex-1 overflow-hidden relative", children: [_jsx("div", { className: cn('cls_doc_preview_column', 'border-r bg-muted/20', 'w-[280px] md:w-[320px] lg:w-[380px]', 'flex-shrink-0', 'flex flex-col',
|
|
137
138
|
// Mobile: hidden by default, shown when sidebar is open
|
|
138
139
|
is_sidebar_open ? 'flex' : 'hidden md:flex'), children: _jsx(HazoChatDocumentViewer, { reference: selected_reference || undefined }) }), _jsx("div", { className: "cls_chat_column flex flex-col flex-1 min-w-0", children: _jsx(HazoChatMessages, { messages: messages, current_user_id: current_user?.id || '', timezone: timezone, is_loading: is_loading_messages, has_more: has_more, on_load_more: load_more, on_delete_message: delete_message, highlighted_message_id: highlighted_message_id || undefined }) })] }), _jsx("div", { className: "cls_input_row border-t bg-background", children: _jsx(HazoChatInput, { on_send: handle_send, pending_attachments: pending_attachments, on_add_attachment: handle_add_attachment, on_remove_attachment: handle_remove_attachment, is_disabled: !current_user || is_uploading }) }), polling_status !== 'connected' && (_jsx("div", { className: cn('cls_connection_status', 'absolute bottom-20 left-1/2 -translate-x-1/2', 'px-3 py-1.5 rounded-full text-xs font-medium z-10', polling_status === 'reconnecting'
|
|
139
140
|
? 'bg-yellow-100 text-yellow-800'
|
|
@@ -142,14 +143,25 @@ function HazoChatInner({ hazo_connect, receiver_user_id, document_save_location,
|
|
|
142
143
|
// ============================================================================
|
|
143
144
|
// Main Component (with Provider)
|
|
144
145
|
// ============================================================================
|
|
146
|
+
/**
|
|
147
|
+
* HazoChat - Main chat component
|
|
148
|
+
*
|
|
149
|
+
* Uses API calls internally for all data operations.
|
|
150
|
+
* Requires the following API routes to be set up:
|
|
151
|
+
* - GET/POST /api/hazo_chat/messages
|
|
152
|
+
* - GET /api/hazo_auth/me
|
|
153
|
+
* - POST /api/hazo_auth/profiles
|
|
154
|
+
*
|
|
155
|
+
* See SETUP_CHECKLIST.md for detailed setup instructions.
|
|
156
|
+
*/
|
|
145
157
|
export function HazoChat(props) {
|
|
146
|
-
const {
|
|
158
|
+
const { receiver_user_id, reference_id, reference_type = 'chat', api_base_url = '/api/hazo_chat', additional_references = [], timezone = DEFAULT_TIMEZONE, title, subtitle, on_close, className } = props;
|
|
147
159
|
// Convert ReferenceItem[] to ChatReferenceItem[]
|
|
148
160
|
const initial_refs = useMemo(() => additional_references.map((ref) => ({
|
|
149
161
|
...ref,
|
|
150
162
|
scope: ref.scope || 'field'
|
|
151
163
|
})), [additional_references]);
|
|
152
|
-
return (_jsx(TooltipProvider, { children: _jsx(HazoChatProvider, {
|
|
164
|
+
return (_jsx(TooltipProvider, { children: _jsx(HazoChatProvider, { api_base_url: api_base_url, initial_references: initial_refs, children: _jsx(HazoChatInner, { receiver_user_id: receiver_user_id, reference_id: reference_id, reference_type: reference_type, api_base_url: api_base_url, additional_references: initial_refs, timezone: timezone, title: title, subtitle: subtitle, on_close: on_close, className: className }) }) }));
|
|
153
165
|
}
|
|
154
166
|
HazoChat.displayName = 'HazoChat';
|
|
155
167
|
//# sourceMappingURL=hazo_chat.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hazo_chat.js","sourceRoot":"","sources":["../../../src/components/hazo_chat/hazo_chat.tsx"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"hazo_chat.js","sourceRoot":"","sources":["../../../src/components/hazo_chat/hazo_chat.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,YAAY,CAAC;;AAEb,OAAc,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AACpD,OAAO,EAAE,EAAE,EAAE,MAAM,oBAAoB,CAAC;AAOxC,OAAO,EACL,gBAAgB,EAChB,wBAAwB,EACxB,yBAAyB,EAC1B,MAAM,wBAAwB,CAAC;AAEhC,iBAAiB;AACjB,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC9E,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OA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,GAAG,GAAG;QACN,KAAK,EAAE,GAAG,CAAC,KAAK,IAAI,OAAO;KAC5B,CAAC,CAAC,EACL,CAAC,qBAAqB,CAAC,CACxB,CAAC;IAEF,OAAO,CACL,KAAC,eAAe,cACd,KAAC,gBAAgB,IACf,YAAY,EAAE,YAAY,EAC1B,kBAAkB,EAAE,YAAY,YAEhC,KAAC,aAAa,IACZ,gBAAgB,EAAE,gBAAgB,EAClC,YAAY,EAAE,YAAY,EAC1B,cAAc,EAAE,cAAc,EAC9B,YAAY,EAAE,YAAY,EAC1B,qBAAqB,EAAE,YAAY,EACnC,QAAQ,EAAE,QAAQ,EAClB,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,SAAS,EAAE,SAAS,GACpB,GACe,GACH,CACnB,CAAC;AACJ,CAAC;AAED,QAAQ,CAAC,WAAW,GAAG,UAAU,CAAC"}
|
|
@@ -3,28 +3,34 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Provides centralized state management for:
|
|
5
5
|
* - Selected reference/document
|
|
6
|
-
* - Current user profile (
|
|
6
|
+
* - Current user profile (fetched via API)
|
|
7
7
|
* - Pending file attachments
|
|
8
8
|
* - Sidebar collapsed state (mobile)
|
|
9
9
|
* - Polling connection status
|
|
10
10
|
* - Error handling
|
|
11
|
+
*
|
|
12
|
+
* Uses API calls to fetch user data - no server-side dependencies.
|
|
11
13
|
*/
|
|
12
14
|
import React, { type ReactNode } from 'react';
|
|
13
|
-
import type { HazoChatContextValue, ChatReferenceItem
|
|
15
|
+
import type { HazoChatContextValue, ChatReferenceItem } from '../../types/index.js';
|
|
14
16
|
declare const HazoChatContext: React.Context<HazoChatContextValue | null>;
|
|
15
17
|
interface HazoChatProviderProps {
|
|
16
18
|
children: ReactNode;
|
|
17
|
-
|
|
19
|
+
/** Base URL for API endpoints (default: '/api/hazo_chat') */
|
|
20
|
+
api_base_url?: string;
|
|
21
|
+
/** Initial references from props */
|
|
18
22
|
initial_references?: ChatReferenceItem[];
|
|
19
23
|
}
|
|
20
24
|
/**
|
|
21
25
|
* HazoChatProvider - Context provider for HazoChat component tree
|
|
22
26
|
*
|
|
27
|
+
* Fetches current user via API on mount.
|
|
28
|
+
*
|
|
23
29
|
* @param children - Child components
|
|
24
|
-
* @param
|
|
30
|
+
* @param api_base_url - Base URL for API endpoints
|
|
25
31
|
* @param initial_references - Initial references from props
|
|
26
32
|
*/
|
|
27
|
-
export declare function HazoChatProvider({ children,
|
|
33
|
+
export declare function HazoChatProvider({ children, api_base_url, initial_references }: HazoChatProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
28
34
|
/**
|
|
29
35
|
* useHazoChatContext - Hook to access HazoChat context
|
|
30
36
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hazo_chat_context.d.ts","sourceRoot":"","sources":["../../../src/components/hazo_chat/hazo_chat_context.tsx"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"hazo_chat_context.d.ts","sourceRoot":"","sources":["../../../src/components/hazo_chat/hazo_chat_context.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,OAAO,KAAK,EAAE,EAOZ,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EACV,oBAAoB,EAEpB,iBAAiB,EAIlB,MAAM,sBAAsB,CAAC;AAyH9B,QAAA,MAAM,eAAe,4CAAmD,CAAC;AAMzE,UAAU,qBAAqB;IAC7B,QAAQ,EAAE,SAAS,CAAC;IACpB,6DAA6D;IAC7D,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,oCAAoC;IACpC,kBAAkB,CAAC,EAAE,iBAAiB,EAAE,CAAC;CAC1C;AAMD;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,EAC/B,QAAQ,EACR,YAA+B,EAC/B,kBAAuB,EACxB,EAAE,qBAAqB,2CA2KvB;AAMD;;;;;GAKG;AACH,wBAAgB,kBAAkB,IAAI,oBAAoB,CAUzD;AAMD,OAAO,EAAE,eAAe,EAAE,CAAC"}
|