@thrillee/aegischat 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/dist/index.d.mts +452 -0
- package/dist/index.d.ts +452 -0
- package/dist/index.js +1065 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1024 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +60 -0
- package/src/hooks/index.ts +27 -0
- package/src/hooks/useAutoRead.ts +78 -0
- package/src/hooks/useChannels.ts +99 -0
- package/src/hooks/useChat.ts +731 -0
- package/src/hooks/useFileUpload.ts +25 -0
- package/src/hooks/useMentions.ts +36 -0
- package/src/hooks/useMessages.ts +37 -0
- package/src/hooks/useReactions.ts +28 -0
- package/src/hooks/useTypingIndicator.ts +28 -0
- package/src/index.ts +68 -0
- package/src/services/api.ts +370 -0
- package/src/types/index.ts +373 -0
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// AegisChat React SDK - TypeScript Types
|
|
3
|
+
// ============================================================================
|
|
4
|
+
|
|
5
|
+
// ----------------------------------------------------------------------------
|
|
6
|
+
// User Types
|
|
7
|
+
// ----------------------------------------------------------------------------
|
|
8
|
+
|
|
9
|
+
export type UserStatus = 'online' | 'offline' | 'away' | 'busy';
|
|
10
|
+
|
|
11
|
+
export interface UserSummary {
|
|
12
|
+
id: string;
|
|
13
|
+
display_name: string;
|
|
14
|
+
avatar_url?: string;
|
|
15
|
+
status: UserStatus;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface User extends UserSummary {
|
|
19
|
+
external_id: string;
|
|
20
|
+
email?: string;
|
|
21
|
+
last_seen_at?: string;
|
|
22
|
+
metadata: Record<string, unknown>;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// ----------------------------------------------------------------------------
|
|
26
|
+
// Channel Types
|
|
27
|
+
// ----------------------------------------------------------------------------
|
|
28
|
+
|
|
29
|
+
export type ChannelType = 'dm' | 'public' | 'private';
|
|
30
|
+
|
|
31
|
+
export interface Channel {
|
|
32
|
+
id: string;
|
|
33
|
+
name: string;
|
|
34
|
+
type: ChannelType;
|
|
35
|
+
description?: string;
|
|
36
|
+
metadata: Record<string, unknown>;
|
|
37
|
+
created_at: string;
|
|
38
|
+
updated_at: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface ChannelMember {
|
|
42
|
+
id: string;
|
|
43
|
+
user_id: string;
|
|
44
|
+
user: UserSummary;
|
|
45
|
+
role: 'owner' | 'admin' | 'member';
|
|
46
|
+
joined_at: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface ChannelWithMembers extends Channel {
|
|
50
|
+
members: ChannelMember[];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface MessageSummary {
|
|
54
|
+
id: string;
|
|
55
|
+
content: string;
|
|
56
|
+
created_at: string;
|
|
57
|
+
sender?: UserSummary;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface ChannelListItem {
|
|
61
|
+
id: string;
|
|
62
|
+
name: string;
|
|
63
|
+
type: ChannelType;
|
|
64
|
+
unread_count: number;
|
|
65
|
+
last_message: MessageSummary | null;
|
|
66
|
+
/** Only present for direct message channels */
|
|
67
|
+
other_member?: UserSummary;
|
|
68
|
+
metadata: Record<string, unknown>;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// ----------------------------------------------------------------------------
|
|
72
|
+
// Message Types
|
|
73
|
+
// ----------------------------------------------------------------------------
|
|
74
|
+
|
|
75
|
+
export type MessageType = 'text' | 'file' | 'system';
|
|
76
|
+
|
|
77
|
+
export interface FileAttachment {
|
|
78
|
+
id: string;
|
|
79
|
+
filename: string;
|
|
80
|
+
mime_type: string;
|
|
81
|
+
size: number;
|
|
82
|
+
url: string;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export interface MessageReactions {
|
|
86
|
+
[emoji: string]: string[]; // emoji -> user IDs
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface MessageMetadata {
|
|
90
|
+
edited?: boolean;
|
|
91
|
+
edited_at?: string;
|
|
92
|
+
reactions?: MessageReactions;
|
|
93
|
+
mentions?: string[];
|
|
94
|
+
files?: FileAttachment[];
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export type MessageStatus = 'sending' | 'sent' | 'delivered' | 'read' | 'failed';
|
|
98
|
+
|
|
99
|
+
export interface Message {
|
|
100
|
+
id: string;
|
|
101
|
+
channel_id: string;
|
|
102
|
+
sender_id: string;
|
|
103
|
+
content: string;
|
|
104
|
+
type: MessageType;
|
|
105
|
+
parent_id?: string;
|
|
106
|
+
metadata: MessageMetadata;
|
|
107
|
+
created_at: string;
|
|
108
|
+
updated_at: string;
|
|
109
|
+
/** Client-side only: temporary ID for optimistic updates */
|
|
110
|
+
tempId?: string;
|
|
111
|
+
/** Client-side only: delivery status */
|
|
112
|
+
status?: MessageStatus;
|
|
113
|
+
/** Client-side only: error message for failed messages */
|
|
114
|
+
errorMessage?: string;
|
|
115
|
+
/** Client-side only: if message was deleted */
|
|
116
|
+
deleted?: boolean;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export interface SendMessageParams {
|
|
120
|
+
content: string;
|
|
121
|
+
type?: MessageType;
|
|
122
|
+
parent_id?: string;
|
|
123
|
+
metadata?: Record<string, unknown>;
|
|
124
|
+
file_ids?: string[];
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export interface UpdateMessageParams {
|
|
128
|
+
content?: string;
|
|
129
|
+
metadata?: Record<string, unknown>;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// ----------------------------------------------------------------------------
|
|
133
|
+
// Typing Types
|
|
134
|
+
// ----------------------------------------------------------------------------
|
|
135
|
+
|
|
136
|
+
export interface TypingUser {
|
|
137
|
+
id: string;
|
|
138
|
+
displayName: string;
|
|
139
|
+
avatarUrl?: string;
|
|
140
|
+
startedAt: number;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export interface TypingEvent {
|
|
144
|
+
channel_id: string;
|
|
145
|
+
user: UserSummary;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// ----------------------------------------------------------------------------
|
|
149
|
+
// Reaction Types
|
|
150
|
+
// ----------------------------------------------------------------------------
|
|
151
|
+
|
|
152
|
+
export interface ReactionEvent {
|
|
153
|
+
channel_id: string;
|
|
154
|
+
message_id: string;
|
|
155
|
+
emoji: string;
|
|
156
|
+
user: UserSummary;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export interface ReactionSummary {
|
|
160
|
+
emoji: string;
|
|
161
|
+
count: number;
|
|
162
|
+
users: UserSummary[];
|
|
163
|
+
hasReacted: boolean;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// ----------------------------------------------------------------------------
|
|
167
|
+
// File Types
|
|
168
|
+
// ----------------------------------------------------------------------------
|
|
169
|
+
|
|
170
|
+
export interface UploadUrlRequest {
|
|
171
|
+
file_name: string;
|
|
172
|
+
file_type: string;
|
|
173
|
+
file_size: number;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export interface UploadUrlResponse {
|
|
177
|
+
upload_url: string;
|
|
178
|
+
file_id: string;
|
|
179
|
+
expires_at: string;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export interface DownloadUrlResponse {
|
|
183
|
+
url: string;
|
|
184
|
+
expires_at: string;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export interface UploadProgress {
|
|
188
|
+
fileId: string;
|
|
189
|
+
fileName: string;
|
|
190
|
+
progress: number;
|
|
191
|
+
status: 'pending' | 'uploading' | 'confirming' | 'complete' | 'error';
|
|
192
|
+
error?: string;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// ----------------------------------------------------------------------------
|
|
196
|
+
// API Types
|
|
197
|
+
// ----------------------------------------------------------------------------
|
|
198
|
+
|
|
199
|
+
export interface ApiResponse<T> {
|
|
200
|
+
data: T;
|
|
201
|
+
message?: string;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export interface ApiError {
|
|
205
|
+
message: string;
|
|
206
|
+
code?: string;
|
|
207
|
+
details?: Record<string, unknown>;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export interface PaginationParams {
|
|
211
|
+
limit?: number;
|
|
212
|
+
offset?: number;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export interface PaginationMeta {
|
|
216
|
+
total: number;
|
|
217
|
+
limit: number;
|
|
218
|
+
offset: number;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export interface PaginatedResponse<T> {
|
|
222
|
+
data: T[];
|
|
223
|
+
meta: PaginationMeta;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// ----------------------------------------------------------------------------
|
|
227
|
+
// WebSocket Types
|
|
228
|
+
// ----------------------------------------------------------------------------
|
|
229
|
+
|
|
230
|
+
export type WebSocketEventType =
|
|
231
|
+
| 'message.new'
|
|
232
|
+
| 'message.updated'
|
|
233
|
+
| 'message.deleted'
|
|
234
|
+
| 'message.delivered'
|
|
235
|
+
| 'message.read'
|
|
236
|
+
| 'message.delivered.batch'
|
|
237
|
+
| 'message.read.batch'
|
|
238
|
+
| 'typing.start'
|
|
239
|
+
| 'typing.stop'
|
|
240
|
+
| 'reaction.added'
|
|
241
|
+
| 'reaction.removed'
|
|
242
|
+
| 'user.online'
|
|
243
|
+
| 'user.offline'
|
|
244
|
+
| 'channel.created'
|
|
245
|
+
| 'channel.updated'
|
|
246
|
+
| 'channel.deleted';
|
|
247
|
+
|
|
248
|
+
export interface WebSocketMessage {
|
|
249
|
+
type: WebSocketEventType;
|
|
250
|
+
payload: unknown;
|
|
251
|
+
timestamp?: string;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export interface WebSocketConfig {
|
|
255
|
+
url: string;
|
|
256
|
+
accessToken: string;
|
|
257
|
+
reconnect?: boolean;
|
|
258
|
+
reconnectInterval?: number;
|
|
259
|
+
maxReconnectAttempts?: number;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
export type WebSocketStatus = 'connecting' | 'connected' | 'disconnected' | 'error';
|
|
263
|
+
|
|
264
|
+
// ----------------------------------------------------------------------------
|
|
265
|
+
// Authentication Types
|
|
266
|
+
// ----------------------------------------------------------------------------
|
|
267
|
+
|
|
268
|
+
export interface ChatSession {
|
|
269
|
+
user_id: string;
|
|
270
|
+
comms_user_id: string;
|
|
271
|
+
access_token: string;
|
|
272
|
+
refresh_token: string;
|
|
273
|
+
expires_at: number;
|
|
274
|
+
websocket_url: string;
|
|
275
|
+
api_url: string;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export interface ChatConnectParams {
|
|
279
|
+
role: 'lawyer' | 'client';
|
|
280
|
+
client_id?: string;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// ----------------------------------------------------------------------------
|
|
284
|
+
// Config Types
|
|
285
|
+
// ----------------------------------------------------------------------------
|
|
286
|
+
|
|
287
|
+
export interface AegisConfig {
|
|
288
|
+
apiUrl: string;
|
|
289
|
+
wsUrl: string;
|
|
290
|
+
getAccessToken: () => Promise<string> | string;
|
|
291
|
+
onUnauthorized?: () => void;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
export interface CommsConfig extends AegisConfig {}
|
|
295
|
+
|
|
296
|
+
// ----------------------------------------------------------------------------
|
|
297
|
+
// Response Types
|
|
298
|
+
// ----------------------------------------------------------------------------
|
|
299
|
+
|
|
300
|
+
export interface MessagesResponse {
|
|
301
|
+
messages: Message[];
|
|
302
|
+
has_more: boolean;
|
|
303
|
+
oldest_id?: string;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
export interface ChannelsResponse {
|
|
307
|
+
channels: ChannelListItem[];
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
export interface UsersResponse {
|
|
311
|
+
users: UserSummary[];
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// ----------------------------------------------------------------------------
|
|
315
|
+
// Hook Return Types
|
|
316
|
+
// ----------------------------------------------------------------------------
|
|
317
|
+
|
|
318
|
+
export interface UseChannelsReturn {
|
|
319
|
+
channels: ChannelListItem[];
|
|
320
|
+
isLoading: boolean;
|
|
321
|
+
error: Error | null;
|
|
322
|
+
refetch: () => Promise<void>;
|
|
323
|
+
getOrCreateDM: (userId: string) => Promise<Channel>;
|
|
324
|
+
markAsRead: (channelId: string) => Promise<void>;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
export interface UseMessagesReturn {
|
|
328
|
+
messages: Message[];
|
|
329
|
+
isLoading: boolean;
|
|
330
|
+
hasMore: boolean;
|
|
331
|
+
sendMessage: (params: SendMessageParams) => Promise<void>;
|
|
332
|
+
sendMessageWithFiles: (params: SendMessageParams, files: File[]) => Promise<void>;
|
|
333
|
+
retryMessage: (tempId: string) => Promise<void>;
|
|
334
|
+
deleteFailedMessage: (tempId: string) => void;
|
|
335
|
+
loadMore: () => Promise<void>;
|
|
336
|
+
uploadProgress: UploadProgress[];
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
export interface UseWebSocketReturn {
|
|
340
|
+
isConnected: boolean;
|
|
341
|
+
isConnecting: boolean;
|
|
342
|
+
connect: () => void;
|
|
343
|
+
disconnect: () => void;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
export interface UseTypingIndicatorReturn {
|
|
347
|
+
startTyping: () => void;
|
|
348
|
+
stopTyping: () => void;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
export interface UseTypingUsersReturn {
|
|
352
|
+
typingUsers: TypingUser[];
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
export interface UseReactionsReturn {
|
|
356
|
+
reactions: ReactionSummary[];
|
|
357
|
+
addReaction: (messageId: string, emoji: string) => Promise<void>;
|
|
358
|
+
removeReaction: (messageId: string, emoji: string) => Promise<void>;
|
|
359
|
+
hasUserReacted: (emoji: string) => boolean;
|
|
360
|
+
getReactionCount: (emoji: string) => number;
|
|
361
|
+
getReactionsList: (emoji: string) => UserSummary[];
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
export interface UseFileUploadReturn {
|
|
365
|
+
upload: (file: File) => Promise<FileAttachment | null>;
|
|
366
|
+
uploadProgress: UploadProgress[];
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
export interface UseMentionsReturn {
|
|
370
|
+
parseMentions: (content: string) => string[];
|
|
371
|
+
highlightMentions: (content: string) => string;
|
|
372
|
+
isUserMentioned: (content: string, userId: string) => boolean;
|
|
373
|
+
}
|