@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.
@@ -0,0 +1,452 @@
1
+ type UserStatus = 'online' | 'offline' | 'away' | 'busy';
2
+ interface UserSummary {
3
+ id: string;
4
+ display_name: string;
5
+ avatar_url?: string;
6
+ status: UserStatus;
7
+ }
8
+ type ChannelType = 'dm' | 'public' | 'private';
9
+ interface Channel {
10
+ id: string;
11
+ name: string;
12
+ type: ChannelType;
13
+ description?: string;
14
+ metadata: Record<string, unknown>;
15
+ created_at: string;
16
+ updated_at: string;
17
+ }
18
+ interface MessageSummary {
19
+ id: string;
20
+ content: string;
21
+ created_at: string;
22
+ sender?: UserSummary;
23
+ }
24
+ interface ChannelListItem {
25
+ id: string;
26
+ name: string;
27
+ type: ChannelType;
28
+ unread_count: number;
29
+ last_message: MessageSummary | null;
30
+ /** Only present for direct message channels */
31
+ other_member?: UserSummary;
32
+ metadata: Record<string, unknown>;
33
+ }
34
+ type MessageType = 'text' | 'file' | 'system';
35
+ interface FileAttachment {
36
+ id: string;
37
+ filename: string;
38
+ mime_type: string;
39
+ size: number;
40
+ url: string;
41
+ }
42
+ interface MessageReactions {
43
+ [emoji: string]: string[];
44
+ }
45
+ interface MessageMetadata {
46
+ edited?: boolean;
47
+ edited_at?: string;
48
+ reactions?: MessageReactions;
49
+ mentions?: string[];
50
+ files?: FileAttachment[];
51
+ }
52
+ type MessageStatus = 'sending' | 'sent' | 'delivered' | 'read' | 'failed';
53
+ interface Message {
54
+ id: string;
55
+ channel_id: string;
56
+ sender_id: string;
57
+ content: string;
58
+ type: MessageType;
59
+ parent_id?: string;
60
+ metadata: MessageMetadata;
61
+ created_at: string;
62
+ updated_at: string;
63
+ /** Client-side only: temporary ID for optimistic updates */
64
+ tempId?: string;
65
+ /** Client-side only: delivery status */
66
+ status?: MessageStatus;
67
+ /** Client-side only: error message for failed messages */
68
+ errorMessage?: string;
69
+ /** Client-side only: if message was deleted */
70
+ deleted?: boolean;
71
+ }
72
+ interface TypingUser {
73
+ id: string;
74
+ displayName: string;
75
+ avatarUrl?: string;
76
+ startedAt: number;
77
+ }
78
+ interface TypingEvent {
79
+ channel_id: string;
80
+ user: UserSummary;
81
+ }
82
+ interface ReactionEvent {
83
+ channel_id: string;
84
+ message_id: string;
85
+ emoji: string;
86
+ user: UserSummary;
87
+ }
88
+ interface ReactionSummary {
89
+ emoji: string;
90
+ count: number;
91
+ users: UserSummary[];
92
+ hasReacted: boolean;
93
+ }
94
+ interface UploadUrlResponse {
95
+ upload_url: string;
96
+ file_id: string;
97
+ expires_at: string;
98
+ }
99
+ interface UploadProgress {
100
+ fileId: string;
101
+ fileName: string;
102
+ progress: number;
103
+ status: 'pending' | 'uploading' | 'confirming' | 'complete' | 'error';
104
+ error?: string;
105
+ }
106
+ interface ApiResponse<T> {
107
+ data: T;
108
+ message?: string;
109
+ }
110
+ interface ApiError {
111
+ message: string;
112
+ code?: string;
113
+ details?: Record<string, unknown>;
114
+ }
115
+ interface PaginationParams {
116
+ limit?: number;
117
+ offset?: number;
118
+ }
119
+ interface PaginationMeta {
120
+ total: number;
121
+ limit: number;
122
+ offset: number;
123
+ }
124
+ interface PaginatedResponse<T> {
125
+ data: T[];
126
+ meta: PaginationMeta;
127
+ }
128
+ type WebSocketEventType = 'message.new' | 'message.updated' | 'message.deleted' | 'message.delivered' | 'message.read' | 'message.delivered.batch' | 'message.read.batch' | 'typing.start' | 'typing.stop' | 'reaction.added' | 'reaction.removed' | 'user.online' | 'user.offline' | 'channel.created' | 'channel.updated' | 'channel.deleted';
129
+ interface WebSocketMessage {
130
+ type: WebSocketEventType;
131
+ payload: unknown;
132
+ timestamp?: string;
133
+ }
134
+ type WebSocketStatus = 'connecting' | 'connected' | 'disconnected' | 'error';
135
+ interface ChatSession {
136
+ user_id: string;
137
+ comms_user_id: string;
138
+ access_token: string;
139
+ refresh_token: string;
140
+ expires_at: number;
141
+ websocket_url: string;
142
+ api_url: string;
143
+ }
144
+ interface ChatConnectParams {
145
+ role: 'lawyer' | 'client';
146
+ client_id?: string;
147
+ }
148
+ interface AegisConfig {
149
+ apiUrl: string;
150
+ wsUrl: string;
151
+ getAccessToken: () => Promise<string> | string;
152
+ onUnauthorized?: () => void;
153
+ }
154
+ interface MessagesResponse {
155
+ messages: Message[];
156
+ has_more: boolean;
157
+ oldest_id?: string;
158
+ }
159
+ interface ChannelsResponse {
160
+ channels: ChannelListItem[];
161
+ }
162
+
163
+ interface UseChatOptions {
164
+ config: AegisConfig;
165
+ role: 'lawyer' | 'client';
166
+ clientId?: string;
167
+ autoConnect?: boolean;
168
+ onMessage?: (message: Message) => void;
169
+ onTyping?: (channelId: string, user: TypingUser) => void;
170
+ onConnectionChange?: (connected: boolean) => void;
171
+ }
172
+ interface UseChatReturn {
173
+ session: ChatSession | null;
174
+ isConnected: boolean;
175
+ isConnecting: boolean;
176
+ channels: ChannelListItem[];
177
+ messages: Message[];
178
+ activeChannelId: string | null;
179
+ typingUsers: TypingUser[];
180
+ isLoadingChannels: boolean;
181
+ isLoadingMessages: boolean;
182
+ hasMoreMessages: boolean;
183
+ uploadProgress: UploadProgress[];
184
+ connect: () => Promise<void>;
185
+ disconnect: () => void;
186
+ selectChannel: (channelId: string) => void;
187
+ sendMessage: (content: string, options?: {
188
+ type?: string;
189
+ parent_id?: string;
190
+ metadata?: Record<string, unknown>;
191
+ }) => Promise<void>;
192
+ sendMessageWithFiles: (content: string, files: File[], options?: {
193
+ type?: string;
194
+ parent_id?: string;
195
+ metadata?: Record<string, unknown>;
196
+ }) => Promise<void>;
197
+ uploadFile: (file: File) => Promise<FileAttachment | null>;
198
+ loadMoreMessages: () => Promise<void>;
199
+ startTyping: () => void;
200
+ stopTyping: () => void;
201
+ refreshChannels: () => Promise<void>;
202
+ createDMWithUser: (userId: string) => Promise<string | null>;
203
+ retryMessage: (tempId: string) => Promise<void>;
204
+ deleteFailedMessage: (tempId: string) => void;
205
+ markAsRead: (channelId: string) => Promise<void>;
206
+ }
207
+ declare function useChat(options: UseChatOptions): UseChatReturn;
208
+
209
+ interface UseAutoReadOptions {
210
+ onMarkAsRead?: (channelId: string) => void;
211
+ }
212
+ interface UseAutoReadReturn {
213
+ markAsRead: (channelId: string) => Promise<void>;
214
+ markAllAsRead: () => Promise<void>;
215
+ isFocused: boolean;
216
+ }
217
+ declare function useAutoRead(options?: UseAutoReadOptions): UseAutoReadReturn;
218
+
219
+ interface UseChannelsOptions {
220
+ type?: 'direct' | 'public' | 'private';
221
+ limit?: number;
222
+ autoFetch?: boolean;
223
+ onChannelCreated?: (channel: Channel) => void;
224
+ onError?: (error: Error) => void;
225
+ }
226
+ interface UseChannelsReturn {
227
+ channels: ChannelListItem[];
228
+ isLoading: boolean;
229
+ error: Error | null;
230
+ refetch: () => Promise<void>;
231
+ getOrCreateDM: (userId: string) => Promise<Channel>;
232
+ markAsRead: (channelId: string) => Promise<void>;
233
+ }
234
+ declare function useChannels(options?: UseChannelsOptions): UseChannelsReturn;
235
+
236
+ interface UseMessagesOptions {
237
+ channelId: string;
238
+ }
239
+ interface UseMessagesReturn {
240
+ messages: Message[];
241
+ isLoading: boolean;
242
+ hasMore: boolean;
243
+ sendMessage: (params: {
244
+ content: string;
245
+ type?: string;
246
+ metadata?: Record<string, unknown>;
247
+ }) => Promise<void>;
248
+ loadMore: () => Promise<void>;
249
+ }
250
+ declare function useMessages(_options: UseMessagesOptions): UseMessagesReturn;
251
+
252
+ interface UseTypingIndicatorOptions {
253
+ channelId: string;
254
+ ws?: WebSocket | null;
255
+ }
256
+ interface UseTypingIndicatorReturn {
257
+ typingUsers: TypingUser[];
258
+ startTyping: () => void;
259
+ stopTyping: () => void;
260
+ }
261
+ declare function useTypingIndicator(_options: UseTypingIndicatorOptions): UseTypingIndicatorReturn;
262
+
263
+ interface UseReactionsOptions {
264
+ channelId: string;
265
+ messageId: string;
266
+ }
267
+ interface UseReactionsReturn {
268
+ reactions: ReactionSummary[];
269
+ addReaction: (emoji: string) => Promise<void>;
270
+ removeReaction: (emoji: string) => Promise<void>;
271
+ }
272
+ declare function useReactions(_options: UseReactionsOptions): UseReactionsReturn;
273
+
274
+ interface UseFileUploadOptions {
275
+ channelId: string;
276
+ }
277
+ interface UseFileUploadReturn {
278
+ uploadProgress: UploadProgress[];
279
+ upload: (file: File) => Promise<FileAttachment | null>;
280
+ }
281
+ declare function useFileUpload(_options: UseFileUploadOptions): UseFileUploadReturn;
282
+
283
+ interface UseMentionsOptions {
284
+ }
285
+ interface UseMentionsReturn {
286
+ parseMentions: (content: string) => string[];
287
+ highlightMentions: (content: string) => string;
288
+ isUserMentioned: (content: string, userId: string) => boolean;
289
+ }
290
+ declare function useMentions(_options?: UseMentionsOptions): UseMentionsReturn;
291
+
292
+ declare function configureApiClient(config: {
293
+ baseUrl: string;
294
+ getAccessToken: () => Promise<string> | string;
295
+ onUnauthorized?: () => void;
296
+ }): void;
297
+ declare const chatApi: {
298
+ /**
299
+ * Connect to chat session
300
+ */
301
+ connect(params: ChatConnectParams, signal?: AbortSignal): Promise<ApiResponse<ChatSession>>;
302
+ /**
303
+ * Refresh access token
304
+ */
305
+ refreshToken(refreshToken: string, signal?: AbortSignal): Promise<ApiResponse<{
306
+ access_token: string;
307
+ expires_in: number;
308
+ }>>;
309
+ };
310
+ declare const channelsApi: {
311
+ /**
312
+ * List channels
313
+ */
314
+ list(options?: {
315
+ type?: string;
316
+ limit?: number;
317
+ }, signal?: AbortSignal): Promise<ApiResponse<{
318
+ channels: ChannelListItem[];
319
+ }>>;
320
+ /**
321
+ * Get channel by ID
322
+ */
323
+ get(channelId: string, signal?: AbortSignal): Promise<ApiResponse<Channel>>;
324
+ /**
325
+ * Get or create DM channel
326
+ */
327
+ getOrCreateDM(userId: string, signal?: AbortSignal): Promise<ApiResponse<Channel>>;
328
+ /**
329
+ * Create channel
330
+ */
331
+ create(data: {
332
+ name: string;
333
+ type?: string;
334
+ description?: string;
335
+ metadata?: Record<string, unknown>;
336
+ }, signal?: AbortSignal): Promise<ApiResponse<Channel>>;
337
+ /**
338
+ * Mark channel as read
339
+ */
340
+ markAsRead(channelId: string, signal?: AbortSignal): Promise<ApiResponse<{
341
+ unread_count: number;
342
+ }>>;
343
+ /**
344
+ * Get channel members
345
+ */
346
+ getMembers(channelId: string, signal?: AbortSignal): Promise<ApiResponse<{
347
+ members: UserSummary[];
348
+ }>>;
349
+ /**
350
+ * Update channel
351
+ */
352
+ update(channelId: string, data: {
353
+ name?: string;
354
+ description?: string;
355
+ metadata?: Record<string, unknown>;
356
+ }, signal?: AbortSignal): Promise<ApiResponse<Channel>>;
357
+ };
358
+ declare const messagesApi: {
359
+ /**
360
+ * List messages in a channel
361
+ */
362
+ list(channelId: string, options?: {
363
+ limit?: number;
364
+ before?: string;
365
+ }, signal?: AbortSignal): Promise<ApiResponse<MessagesResponse>>;
366
+ /**
367
+ * Send a message
368
+ */
369
+ send(channelId: string, data: {
370
+ content: string;
371
+ type?: string;
372
+ parent_id?: string;
373
+ metadata?: Record<string, unknown>;
374
+ file_ids?: string[];
375
+ }, signal?: AbortSignal): Promise<ApiResponse<Message>>;
376
+ /**
377
+ * Update a message
378
+ */
379
+ update(channelId: string, messageId: string, data: {
380
+ content?: string;
381
+ metadata?: Record<string, unknown>;
382
+ }, signal?: AbortSignal): Promise<ApiResponse<Message>>;
383
+ /**
384
+ * Delete a message
385
+ */
386
+ delete(channelId: string, messageId: string, signal?: AbortSignal): Promise<ApiResponse<{
387
+ success: boolean;
388
+ }>>;
389
+ /**
390
+ * Mark messages as delivered
391
+ */
392
+ markDelivered(channelId: string, signal?: AbortSignal): Promise<ApiResponse<{
393
+ success: boolean;
394
+ }>>;
395
+ /**
396
+ * Mark messages as read
397
+ */
398
+ markRead(channelId: string, signal?: AbortSignal): Promise<ApiResponse<{
399
+ success: boolean;
400
+ }>>;
401
+ };
402
+ declare const reactionsApi: {
403
+ /**
404
+ * Add reaction to a message
405
+ */
406
+ add(channelId: string, messageId: string, emoji: string, signal?: AbortSignal): Promise<ApiResponse<{
407
+ reactions: ReactionSummary[];
408
+ }>>;
409
+ /**
410
+ * Remove reaction from a message
411
+ */
412
+ remove(channelId: string, messageId: string, emoji: string, signal?: AbortSignal): Promise<ApiResponse<{
413
+ reactions: ReactionSummary[];
414
+ }>>;
415
+ };
416
+ declare const filesApi: {
417
+ /**
418
+ * Get upload URL
419
+ */
420
+ getUploadUrl(data: {
421
+ file_name: string;
422
+ file_type: string;
423
+ file_size: number;
424
+ }, signal?: AbortSignal): Promise<ApiResponse<UploadUrlResponse>>;
425
+ /**
426
+ * Confirm file upload
427
+ */
428
+ confirm(fileId: string, signal?: AbortSignal): Promise<ApiResponse<{
429
+ file: FileAttachment;
430
+ }>>;
431
+ /**
432
+ * Get download URL
433
+ */
434
+ getDownloadUrl(fileId: string, signal?: AbortSignal): Promise<ApiResponse<{
435
+ url: string;
436
+ expires_at: string;
437
+ }>>;
438
+ };
439
+ declare const usersApi: {
440
+ /**
441
+ * Search users
442
+ */
443
+ search(query: string, signal?: AbortSignal): Promise<ApiResponse<{
444
+ users: UserSummary[];
445
+ }>>;
446
+ /**
447
+ * Get user by ID
448
+ */
449
+ get(userId: string, signal?: AbortSignal): Promise<ApiResponse<UserSummary>>;
450
+ };
451
+
452
+ export { type AegisConfig, type ApiError, type ApiResponse, type Channel, type ChannelListItem, type ChannelType, type ChannelsResponse, type ChatConnectParams, type ChatSession, type FileAttachment, type Message, type MessageMetadata, type MessageStatus, type MessageSummary, type MessageType, type MessagesResponse, type PaginatedResponse, type PaginationMeta, type PaginationParams, type ReactionEvent, type ReactionSummary, type TypingEvent, type TypingUser, type UploadProgress, type UseAutoReadOptions, type UseAutoReadReturn, type UseChannelsOptions, type UseChannelsReturn, type UseChatOptions, type UseChatReturn, type UseFileUploadOptions, type UseMentionsOptions, type UseMessagesOptions, type UseMessagesReturn, type UseReactionsOptions, type UseTypingIndicatorOptions, type UserStatus, type UserSummary, type WebSocketMessage, type WebSocketStatus, channelsApi, chatApi, configureApiClient, filesApi, messagesApi, reactionsApi, useAutoRead, useChannels, useChat, useFileUpload, useMentions, useMessages, useReactions, useTypingIndicator, usersApi };