@min98/chat-sdk 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,146 @@
1
+ import React from 'react';
2
+
3
+ declare class ChatApiClient {
4
+ private axiosInstance;
5
+ constructor(apiBaseUrl: string, token: string | (() => string));
6
+ getActiveSession(userId?: string): Promise<any>;
7
+ startSession(title?: string, userId?: string): Promise<any>;
8
+ closeSession(userId?: string): Promise<any>;
9
+ getMessages(userId?: string, limit?: number, before?: string): Promise<any>;
10
+ sendMessage(content: string, userId?: string, attachments?: unknown[]): Promise<any>;
11
+ markAsRead(userId?: string): Promise<any>;
12
+ uploadFile(file: File): Promise<any>;
13
+ getRooms(): Promise<any>;
14
+ getSseTicket(): Promise<any>;
15
+ }
16
+
17
+ interface Message {
18
+ _id: string;
19
+ userId: string;
20
+ senderId: string;
21
+ content: string;
22
+ attachments?: {
23
+ type: 'image' | 'audio';
24
+ url: string;
25
+ name: string;
26
+ }[];
27
+ isRead: boolean;
28
+ createdAt: string;
29
+ }
30
+ interface ChatRoom {
31
+ userId: string;
32
+ user: {
33
+ name: string;
34
+ email: string;
35
+ image?: string;
36
+ };
37
+ lastMessage: {
38
+ content: string;
39
+ attachments: {
40
+ type: 'image' | 'audio';
41
+ url: string;
42
+ name: string;
43
+ }[];
44
+ senderId: string;
45
+ createdAt: string;
46
+ };
47
+ unreadCount: number;
48
+ isOnline: boolean;
49
+ activeSession?: {
50
+ _id: string;
51
+ title: string;
52
+ status: 'active' | 'closed';
53
+ startedAt: string;
54
+ } | null;
55
+ }
56
+ interface ChatContextProps {
57
+ apiClient: ChatApiClient | null;
58
+ messages: Message[];
59
+ activeSession: any | null;
60
+ isConnected: boolean;
61
+ sseError: string | null;
62
+ isLoading: boolean;
63
+ isLoadingSession: boolean;
64
+ isUploading: boolean;
65
+ hasMore: boolean;
66
+ isLoadingMore: boolean;
67
+ unreadCount: number;
68
+ rooms: ChatRoom[];
69
+ selectedRoom: ChatRoom | null;
70
+ setSelectedRoom: (room: ChatRoom | null) => void;
71
+ sendMessage: (content: string, attachments?: any[]) => Promise<void>;
72
+ startSession: (title?: string, userId?: string) => Promise<void>;
73
+ closeSession: (userId?: string) => Promise<void>;
74
+ markAsRead: (userId?: string) => Promise<void>;
75
+ loadMessages: (userId?: string) => Promise<void>;
76
+ loadMoreMessages: (userId?: string) => Promise<void>;
77
+ uploadFile: (file: File) => Promise<any>;
78
+ loadRooms: () => Promise<void>;
79
+ }
80
+ interface ChatProviderProps {
81
+ apiBaseUrl: string;
82
+ token: string | (() => string);
83
+ isAdmin?: boolean;
84
+ children: React.ReactNode;
85
+ }
86
+ declare const ChatProvider: React.FC<ChatProviderProps>;
87
+ declare const useChatContext: () => ChatContextProps;
88
+
89
+ declare function useChat(): {
90
+ messages: Message[];
91
+ activeSession: any;
92
+ isConnected: boolean;
93
+ sseError: string | null;
94
+ isLoading: boolean;
95
+ isLoadingSession: boolean;
96
+ isUploading: boolean;
97
+ hasMore: boolean;
98
+ isLoadingMore: boolean;
99
+ unreadCount: number;
100
+ sendMessage: (content: string, attachments?: any[]) => Promise<void>;
101
+ startSession: (title?: string) => Promise<void>;
102
+ closeSession: () => Promise<void>;
103
+ markAsRead: () => Promise<void>;
104
+ loadMessages: () => Promise<void>;
105
+ loadMoreMessages: () => Promise<void>;
106
+ uploadFile: (file: File) => Promise<any>;
107
+ };
108
+
109
+ declare function useChatAdmin(): {
110
+ messages: Message[];
111
+ isConnected: boolean;
112
+ sseError: string | null;
113
+ isLoading: boolean;
114
+ isLoadingSession: boolean;
115
+ isUploading: boolean;
116
+ hasMore: boolean;
117
+ isLoadingMore: boolean;
118
+ rooms: ChatRoom[];
119
+ selectedRoom: ChatRoom | null;
120
+ setSelectedRoom: (room: ChatRoom | null) => void;
121
+ sendMessage: (content: string, attachments?: any[]) => Promise<void>;
122
+ startSession: (title?: string) => Promise<void>;
123
+ closeSession: () => Promise<void>;
124
+ markAsRead: () => Promise<void>;
125
+ loadMessages: () => Promise<void>;
126
+ loadMoreMessages: () => Promise<void>;
127
+ uploadFile: (file: File) => Promise<any>;
128
+ loadRooms: () => Promise<void>;
129
+ };
130
+
131
+ interface ChatWindowProps {
132
+ isAdminMode?: boolean;
133
+ onClose?: () => void;
134
+ title?: string;
135
+ quickQuestions?: string[];
136
+ cannedResponses?: string[];
137
+ }
138
+ declare const ChatWindow: React.FC<ChatWindowProps>;
139
+
140
+ interface ChatWidgetProps {
141
+ title?: string;
142
+ quickQuestions?: string[];
143
+ }
144
+ declare const ChatWidget: React.FC<ChatWidgetProps>;
145
+
146
+ export { ChatProvider, type ChatRoom, ChatWidget, ChatWindow, type Message, useChat, useChatAdmin, useChatContext };
@@ -0,0 +1,146 @@
1
+ import React from 'react';
2
+
3
+ declare class ChatApiClient {
4
+ private axiosInstance;
5
+ constructor(apiBaseUrl: string, token: string | (() => string));
6
+ getActiveSession(userId?: string): Promise<any>;
7
+ startSession(title?: string, userId?: string): Promise<any>;
8
+ closeSession(userId?: string): Promise<any>;
9
+ getMessages(userId?: string, limit?: number, before?: string): Promise<any>;
10
+ sendMessage(content: string, userId?: string, attachments?: unknown[]): Promise<any>;
11
+ markAsRead(userId?: string): Promise<any>;
12
+ uploadFile(file: File): Promise<any>;
13
+ getRooms(): Promise<any>;
14
+ getSseTicket(): Promise<any>;
15
+ }
16
+
17
+ interface Message {
18
+ _id: string;
19
+ userId: string;
20
+ senderId: string;
21
+ content: string;
22
+ attachments?: {
23
+ type: 'image' | 'audio';
24
+ url: string;
25
+ name: string;
26
+ }[];
27
+ isRead: boolean;
28
+ createdAt: string;
29
+ }
30
+ interface ChatRoom {
31
+ userId: string;
32
+ user: {
33
+ name: string;
34
+ email: string;
35
+ image?: string;
36
+ };
37
+ lastMessage: {
38
+ content: string;
39
+ attachments: {
40
+ type: 'image' | 'audio';
41
+ url: string;
42
+ name: string;
43
+ }[];
44
+ senderId: string;
45
+ createdAt: string;
46
+ };
47
+ unreadCount: number;
48
+ isOnline: boolean;
49
+ activeSession?: {
50
+ _id: string;
51
+ title: string;
52
+ status: 'active' | 'closed';
53
+ startedAt: string;
54
+ } | null;
55
+ }
56
+ interface ChatContextProps {
57
+ apiClient: ChatApiClient | null;
58
+ messages: Message[];
59
+ activeSession: any | null;
60
+ isConnected: boolean;
61
+ sseError: string | null;
62
+ isLoading: boolean;
63
+ isLoadingSession: boolean;
64
+ isUploading: boolean;
65
+ hasMore: boolean;
66
+ isLoadingMore: boolean;
67
+ unreadCount: number;
68
+ rooms: ChatRoom[];
69
+ selectedRoom: ChatRoom | null;
70
+ setSelectedRoom: (room: ChatRoom | null) => void;
71
+ sendMessage: (content: string, attachments?: any[]) => Promise<void>;
72
+ startSession: (title?: string, userId?: string) => Promise<void>;
73
+ closeSession: (userId?: string) => Promise<void>;
74
+ markAsRead: (userId?: string) => Promise<void>;
75
+ loadMessages: (userId?: string) => Promise<void>;
76
+ loadMoreMessages: (userId?: string) => Promise<void>;
77
+ uploadFile: (file: File) => Promise<any>;
78
+ loadRooms: () => Promise<void>;
79
+ }
80
+ interface ChatProviderProps {
81
+ apiBaseUrl: string;
82
+ token: string | (() => string);
83
+ isAdmin?: boolean;
84
+ children: React.ReactNode;
85
+ }
86
+ declare const ChatProvider: React.FC<ChatProviderProps>;
87
+ declare const useChatContext: () => ChatContextProps;
88
+
89
+ declare function useChat(): {
90
+ messages: Message[];
91
+ activeSession: any;
92
+ isConnected: boolean;
93
+ sseError: string | null;
94
+ isLoading: boolean;
95
+ isLoadingSession: boolean;
96
+ isUploading: boolean;
97
+ hasMore: boolean;
98
+ isLoadingMore: boolean;
99
+ unreadCount: number;
100
+ sendMessage: (content: string, attachments?: any[]) => Promise<void>;
101
+ startSession: (title?: string) => Promise<void>;
102
+ closeSession: () => Promise<void>;
103
+ markAsRead: () => Promise<void>;
104
+ loadMessages: () => Promise<void>;
105
+ loadMoreMessages: () => Promise<void>;
106
+ uploadFile: (file: File) => Promise<any>;
107
+ };
108
+
109
+ declare function useChatAdmin(): {
110
+ messages: Message[];
111
+ isConnected: boolean;
112
+ sseError: string | null;
113
+ isLoading: boolean;
114
+ isLoadingSession: boolean;
115
+ isUploading: boolean;
116
+ hasMore: boolean;
117
+ isLoadingMore: boolean;
118
+ rooms: ChatRoom[];
119
+ selectedRoom: ChatRoom | null;
120
+ setSelectedRoom: (room: ChatRoom | null) => void;
121
+ sendMessage: (content: string, attachments?: any[]) => Promise<void>;
122
+ startSession: (title?: string) => Promise<void>;
123
+ closeSession: () => Promise<void>;
124
+ markAsRead: () => Promise<void>;
125
+ loadMessages: () => Promise<void>;
126
+ loadMoreMessages: () => Promise<void>;
127
+ uploadFile: (file: File) => Promise<any>;
128
+ loadRooms: () => Promise<void>;
129
+ };
130
+
131
+ interface ChatWindowProps {
132
+ isAdminMode?: boolean;
133
+ onClose?: () => void;
134
+ title?: string;
135
+ quickQuestions?: string[];
136
+ cannedResponses?: string[];
137
+ }
138
+ declare const ChatWindow: React.FC<ChatWindowProps>;
139
+
140
+ interface ChatWidgetProps {
141
+ title?: string;
142
+ quickQuestions?: string[];
143
+ }
144
+ declare const ChatWidget: React.FC<ChatWidgetProps>;
145
+
146
+ export { ChatProvider, type ChatRoom, ChatWidget, ChatWindow, type Message, useChat, useChatAdmin, useChatContext };