@elqnt/chat 2.0.8 → 3.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.
Files changed (52) hide show
  1. package/README.md +433 -0
  2. package/dist/api/index.d.mts +250 -8
  3. package/dist/api/index.d.ts +250 -8
  4. package/dist/api/index.js +115 -0
  5. package/dist/api/index.js.map +1 -1
  6. package/dist/api/index.mjs +109 -0
  7. package/dist/api/index.mjs.map +1 -1
  8. package/dist/hooks/index.d.mts +80 -0
  9. package/dist/hooks/index.d.ts +80 -0
  10. package/dist/hooks/index.js +741 -0
  11. package/dist/hooks/index.js.map +1 -0
  12. package/dist/hooks/index.mjs +715 -0
  13. package/dist/hooks/index.mjs.map +1 -0
  14. package/dist/index.d.mts +4 -109
  15. package/dist/index.d.ts +4 -109
  16. package/dist/index.js +731 -2039
  17. package/dist/index.js.map +1 -1
  18. package/dist/index.mjs +722 -2016
  19. package/dist/index.mjs.map +1 -1
  20. package/dist/models/index.d.mts +76 -6
  21. package/dist/models/index.d.ts +76 -6
  22. package/dist/models/index.js +21 -0
  23. package/dist/models/index.js.map +1 -1
  24. package/dist/models/index.mjs +14 -0
  25. package/dist/models/index.mjs.map +1 -1
  26. package/dist/transport/index.d.mts +243 -0
  27. package/dist/transport/index.d.ts +243 -0
  28. package/dist/transport/index.js +972 -0
  29. package/dist/transport/index.js.map +1 -0
  30. package/dist/transport/index.mjs +940 -0
  31. package/dist/transport/index.mjs.map +1 -0
  32. package/dist/types-7UNI1iYv.d.ts +250 -0
  33. package/dist/types-CQHtUQ6p.d.mts +250 -0
  34. package/package.json +20 -38
  35. package/dist/hooks/use-websocket-chat-admin.d.mts +0 -17
  36. package/dist/hooks/use-websocket-chat-admin.d.ts +0 -17
  37. package/dist/hooks/use-websocket-chat-admin.js +0 -1196
  38. package/dist/hooks/use-websocket-chat-admin.js.map +0 -1
  39. package/dist/hooks/use-websocket-chat-admin.mjs +0 -1172
  40. package/dist/hooks/use-websocket-chat-admin.mjs.map +0 -1
  41. package/dist/hooks/use-websocket-chat-base.d.mts +0 -81
  42. package/dist/hooks/use-websocket-chat-base.d.ts +0 -81
  43. package/dist/hooks/use-websocket-chat-base.js +0 -1025
  44. package/dist/hooks/use-websocket-chat-base.js.map +0 -1
  45. package/dist/hooks/use-websocket-chat-base.mjs +0 -1001
  46. package/dist/hooks/use-websocket-chat-base.mjs.map +0 -1
  47. package/dist/hooks/use-websocket-chat-customer.d.mts +0 -24
  48. package/dist/hooks/use-websocket-chat-customer.d.ts +0 -24
  49. package/dist/hooks/use-websocket-chat-customer.js +0 -1092
  50. package/dist/hooks/use-websocket-chat-customer.js.map +0 -1
  51. package/dist/hooks/use-websocket-chat-customer.mjs +0 -1068
  52. package/dist/hooks/use-websocket-chat-customer.mjs.map +0 -1
package/README.md ADDED
@@ -0,0 +1,433 @@
1
+ # @elqnt/chat
2
+
3
+ Platform-agnostic chat SDK for React and React Native. Uses HTTP + SSE for reliable real-time communication.
4
+
5
+ **Key Features:**
6
+ - **Mutations via HTTP** - `startChat()`, `loadChat()` return data directly (no waiting for SSE events)
7
+ - **Events via SSE** - Real-time messages, typing indicators, agent updates
8
+ - **Multi-transport** - Browser EventSource, React Native fetch-based SSE, WhatsApp webhooks
9
+ - **TypeScript-first** - Full type definitions for all models and events
10
+
11
+ ## Installation
12
+
13
+ ```bash
14
+ pnpm add @elqnt/chat
15
+ ```
16
+
17
+ ## Quick Start
18
+
19
+ ```tsx
20
+ import { useChat } from "@elqnt/chat/hooks";
21
+
22
+ function ChatComponent() {
23
+ const {
24
+ connect,
25
+ disconnect,
26
+ sendMessage,
27
+ startChat,
28
+ loadChat,
29
+ messages,
30
+ isConnected,
31
+ currentChat,
32
+ } = useChat({
33
+ baseUrl: "https://api.example.com/chat",
34
+ orgId: "org-123",
35
+ userId: "user-456",
36
+ });
37
+
38
+ useEffect(() => {
39
+ connect();
40
+ return () => disconnect();
41
+ }, []);
42
+
43
+ // Start a new chat - returns chatKey immediately
44
+ const handleNewChat = async () => {
45
+ const chatKey = await startChat({ agentId: "support-agent" });
46
+ console.log("Created chat:", chatKey);
47
+ };
48
+
49
+ // Load existing chat - returns Chat immediately
50
+ const handleLoadChat = async (chatKey: string) => {
51
+ const chat = await loadChat(chatKey);
52
+ console.log("Loaded chat with", chat.messages.length, "messages");
53
+ };
54
+
55
+ const handleSend = async (text: string) => {
56
+ await sendMessage(text);
57
+ };
58
+
59
+ return (
60
+ <div>
61
+ <ConnectionStatus connected={isConnected} />
62
+ <MessageList messages={messages} />
63
+ <MessageInput onSend={handleSend} />
64
+ </div>
65
+ );
66
+ }
67
+ ```
68
+
69
+ ## Architecture
70
+
71
+ ```
72
+ ┌─────────────────────────────────────────────────────────────┐
73
+ │ Your App │
74
+ ├─────────────────────────────────────────────────────────────┤
75
+ │ useChat Hook │
76
+ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────┐ │
77
+ │ │ State │ │ Events │ │ Chat Operations │ │
78
+ │ │ messages │ │ onMessage │ │ sendMessage │ │
79
+ │ │ chatKey │ │ on(type) │ │ startChat │ │
80
+ │ │ isConnected│ │ │ │ loadChat │ │
81
+ │ └─────────────┘ └─────────────┘ └─────────────────────┘ │
82
+ ├─────────────────────────────────────────────────────────────┤
83
+ │ Transport Layer │
84
+ │ ┌──────────────┐ ┌──────────────┐ ┌──────────────────┐ │
85
+ │ │ SSE │ │ SSE-Fetch │ │ WhatsApp │ │
86
+ │ │ (Browser) │ │ (React │ │ (Backend │ │
87
+ │ │ │ │ Native) │ │ Webhook) │ │
88
+ │ └──────────────┘ └──────────────┘ └──────────────────┘ │
89
+ ├─────────────────────────────────────────────────────────────┤
90
+ │ Chat Server │
91
+ │ ┌──────────────────────────────────────────────────────┐ │
92
+ │ │ POST /create, /send, /load, /end, /typing, /event │ │
93
+ │ │ GET /stream (SSE) │ │
94
+ │ └──────────────────────────────────────────────────────┘ │
95
+ └─────────────────────────────────────────────────────────────┘
96
+ ```
97
+
98
+ ## Exports
99
+
100
+ ### `/hooks` - React Hooks
101
+
102
+ ```typescript
103
+ import { useChat } from "@elqnt/chat/hooks";
104
+ ```
105
+
106
+ **useChat Options:**
107
+
108
+ | Option | Type | Required | Description |
109
+ |--------|------|----------|-------------|
110
+ | `baseUrl` | `string` | Yes | Chat server URL |
111
+ | `orgId` | `string` | Yes | Organization ID |
112
+ | `userId` | `string` | Yes | User ID |
113
+ | `clientType` | `"customer" \| "humanAgent" \| "observer"` | No | Client type (default: "customer") |
114
+ | `transport` | `ChatTransport \| "sse" \| "sse-fetch"` | No | Transport to use |
115
+ | `onMessage` | `(event: ChatEvent) => void` | No | Event callback |
116
+ | `onError` | `(error: TransportError) => void` | No | Error callback |
117
+ | `autoConnect` | `boolean` | No | Connect on mount |
118
+ | `debug` | `boolean` | No | Enable logging |
119
+
120
+ **useChat Return:**
121
+
122
+ ```typescript
123
+ interface UseChatReturn {
124
+ // Connection
125
+ connect: () => Promise<void>;
126
+ disconnect: () => void;
127
+ connectionState: TransportState;
128
+ isConnected: boolean;
129
+
130
+ // Chat Operations (return data directly via HTTP)
131
+ startChat: (metadata?: Record<string, unknown>) => Promise<string>; // Returns chatKey
132
+ loadChat: (chatKey: string) => Promise<Chat>; // Returns loaded Chat
133
+ sendMessage: (content: string, attachments?: unknown[]) => Promise<void>;
134
+ sendEvent: (event: Omit<ChatEvent, "timestamp">) => Promise<void>;
135
+ endChat: (reason?: string) => Promise<void>;
136
+
137
+ // Typing Indicators
138
+ startTyping: () => void;
139
+ stopTyping: () => void;
140
+
141
+ // State (auto-updated by hook)
142
+ currentChat: Chat | null;
143
+ chatKey: string | null;
144
+ messages: ChatMessage[];
145
+ error: TransportError | null;
146
+ metrics: ConnectionMetrics;
147
+
148
+ // Events (SSE push events)
149
+ on: (eventType: string, handler: (event: ChatEvent) => void) => () => void;
150
+ clearError: () => void;
151
+ }
152
+ ```
153
+
154
+ > **Note:** `startChat()` and `loadChat()` use direct HTTP calls and return data immediately.
155
+ > You don't need to listen for `new_chat_created` or `load_chat_response` events - those are
156
+ > only broadcast for multi-tab synchronization.
157
+
158
+ ### `/api` - Low-Level API Functions
159
+
160
+ ```typescript
161
+ import {
162
+ // Browser API (uses @elqnt/api-client)
163
+ getChatHistoryApi,
164
+ getChatApi,
165
+ updateChatApi,
166
+ deleteChatApi,
167
+ getActiveChatsApi,
168
+ getActiveChatsCountApi,
169
+
170
+ // Stream API (direct HTTP)
171
+ createChat,
172
+ sendChatMessage,
173
+ loadChat,
174
+ endChat,
175
+ sendTypingIndicator,
176
+ sendEvent,
177
+ } from "@elqnt/chat/api";
178
+ ```
179
+
180
+ ### `/models` - TypeScript Types
181
+
182
+ ```typescript
183
+ import type {
184
+ Chat,
185
+ ChatMessage,
186
+ ChatEvent,
187
+ ChatEventTypeTS,
188
+ ChatUser,
189
+ ChatStatusTS,
190
+ MessageStatusTS,
191
+ Attachment,
192
+ } from "@elqnt/chat/models";
193
+ ```
194
+
195
+ ### `/transport` - Transport Adapters
196
+
197
+ ```typescript
198
+ import {
199
+ createSSETransport, // Browser EventSource
200
+ createFetchSSETransport, // React Native / Fetch-based
201
+ createWhatsAppTransport, // WhatsApp Business API (stub)
202
+ } from "@elqnt/chat/transport";
203
+
204
+ import type {
205
+ ChatTransport,
206
+ TransportConfig,
207
+ TransportState,
208
+ TransportError,
209
+ ConnectionMetrics,
210
+ CreateChatOptions,
211
+ CreateChatResponse,
212
+ LoadChatOptions,
213
+ LoadChatResponse,
214
+ } from "@elqnt/chat/transport";
215
+ ```
216
+
217
+ ## Transport Options
218
+
219
+ ### Browser (Default)
220
+
221
+ Uses native `EventSource` for SSE. This is the default and recommended transport for browser environments.
222
+
223
+ ```typescript
224
+ const chat = useChat({
225
+ baseUrl: "...",
226
+ orgId: "...",
227
+ userId: "...",
228
+ // transport defaults to "sse"
229
+ });
230
+ ```
231
+
232
+ ### React Native
233
+
234
+ Uses `fetch` with `ReadableStream` for SSE. Required for React Native since it doesn't have native `EventSource`.
235
+
236
+ ```typescript
237
+ import { createFetchSSETransport } from "@elqnt/chat/transport";
238
+
239
+ const transport = createFetchSSETransport();
240
+
241
+ const chat = useChat({
242
+ baseUrl: "...",
243
+ orgId: "...",
244
+ userId: "...",
245
+ transport,
246
+ });
247
+ ```
248
+
249
+ ### Custom Transport
250
+
251
+ Implement the `ChatTransport` interface for custom integrations:
252
+
253
+ ```typescript
254
+ import type { ChatTransport } from "@elqnt/chat/transport";
255
+
256
+ const customTransport: ChatTransport = {
257
+ // Connection
258
+ async connect(config) { /* ... */ },
259
+ disconnect() { /* ... */ },
260
+
261
+ // Mutations (return data directly)
262
+ async createChat(options) { /* returns { chatKey } */ },
263
+ async loadChatData(options) { /* returns { chat, agentId? } */ },
264
+
265
+ // Fire-and-forget operations
266
+ async send(event) { /* ... */ },
267
+ async sendMessage(message) { /* ... */ },
268
+
269
+ // Event subscriptions
270
+ onMessage(handler) { /* returns unsubscribe */ },
271
+ on(eventType, handler) { /* returns unsubscribe */ },
272
+
273
+ // State
274
+ getState() { /* returns TransportState */ },
275
+ getMetrics() { /* returns ConnectionMetrics */ },
276
+ getError() { /* returns TransportError | undefined */ },
277
+ clearError() { /* ... */ },
278
+ };
279
+ ```
280
+
281
+ ## Event Types
282
+
283
+ Subscribe to specific events:
284
+
285
+ ```typescript
286
+ const { on } = useChat({ ... });
287
+
288
+ // Subscribe to typing events
289
+ const unsubscribe = on("typing", (event) => {
290
+ console.log("User typing:", event.userId);
291
+ });
292
+
293
+ // Clean up
294
+ unsubscribe();
295
+ ```
296
+
297
+ Common event types:
298
+
299
+ | Event | Description |
300
+ |-------|-------------|
301
+ | `message` | New message received |
302
+ | `typing` | User started typing |
303
+ | `stopped_typing` | User stopped typing |
304
+ | `new_chat_created` | New chat session created |
305
+ | `load_chat_response` | Chat loaded |
306
+ | `chat_ended` | Chat session ended |
307
+ | `human_agent_joined` | Human agent joined chat |
308
+ | `human_agent_left` | Human agent left chat |
309
+ | `agent_execution_started` | AI agent started processing |
310
+ | `agent_execution_ended` | AI agent finished processing |
311
+
312
+ ## WhatsApp Integration
313
+
314
+ WhatsApp Business API integration happens via backend webhooks. The `createWhatsAppTransport` is a stub that documents the integration pattern.
315
+
316
+ ### Backend Setup
317
+
318
+ 1. Create a Meta Business App with WhatsApp integration
319
+ 2. Configure webhook URL pointing to your chat service
320
+ 3. Implement webhook handlers:
321
+
322
+ ```go
323
+ // Webhook verification
324
+ func HandleWhatsAppWebhook(w http.ResponseWriter, r *http.Request) {
325
+ if r.Method == "GET" {
326
+ verifyToken := r.URL.Query().Get("hub.verify_token")
327
+ if verifyToken == os.Getenv("WHATSAPP_VERIFY_TOKEN") {
328
+ w.Write([]byte(r.URL.Query().Get("hub.challenge")))
329
+ return
330
+ }
331
+ http.Error(w, "Invalid verify token", 403)
332
+ return
333
+ }
334
+
335
+ // Handle incoming message
336
+ var payload WhatsAppPayload
337
+ json.NewDecoder(r.Body).Decode(&payload)
338
+
339
+ // Map to chat event and publish
340
+ chatEvent := mapWhatsAppToChatEvent(payload)
341
+ publishToChatService(chatEvent)
342
+ }
343
+ ```
344
+
345
+ ### Helper Functions
346
+
347
+ ```typescript
348
+ import { mapWhatsAppToChatEvent } from "@elqnt/chat/transport";
349
+
350
+ // In your webhook handler
351
+ const events = mapWhatsAppToChatEvent(webhookPayload, orgId);
352
+ events.forEach(event => publishToChatService(event));
353
+ ```
354
+
355
+ ## Migration from v2
356
+
357
+ ### Breaking Changes in v3.0
358
+
359
+ 1. **UI Components Removed** - Build your own UI
360
+ 2. **Contexts Removed** - Use `useChat` hook directly
361
+ 3. **WebSocket Removed** - SSE only (more reliable)
362
+ 4. **Redux Integration Removed** - Use hook state
363
+
364
+ ### Changes in v3.0.1
365
+
366
+ 1. **`loadChat()` returns `Promise<Chat>`** - Previously returned `Promise<void>`, now returns the loaded chat directly
367
+ 2. **`startChat()` returns immediately** - No longer waits for SSE event, returns chatKey from HTTP response
368
+ 3. **Transport interface extended** - Added `createChat()` and `loadChatData()` methods for direct HTTP responses
369
+ 4. **Event handlers simplified** - `new_chat_created` and `load_chat_response` events are now only for multi-tab sync
370
+
371
+ ### Migration Steps
372
+
373
+ ```tsx
374
+ // Before (v2)
375
+ import { WebSocketChatCustomerProvider, useWebSocketChatCustomer } from "@elqnt/chat";
376
+
377
+ function App() {
378
+ return (
379
+ <WebSocketChatCustomerProvider config={...}>
380
+ <ChatComponent />
381
+ </WebSocketChatCustomerProvider>
382
+ );
383
+ }
384
+
385
+ function ChatComponent() {
386
+ const { messages, sendMessage } = useWebSocketChatCustomer();
387
+ return <ChatUI messages={messages} onSend={sendMessage} />;
388
+ }
389
+
390
+ // After (v3)
391
+ import { useChat } from "@elqnt/chat/hooks";
392
+
393
+ function ChatComponent() {
394
+ const { messages, sendMessage, connect, disconnect } = useChat({
395
+ baseUrl: "...",
396
+ orgId: "...",
397
+ userId: "...",
398
+ });
399
+
400
+ useEffect(() => {
401
+ connect();
402
+ return () => disconnect();
403
+ }, []);
404
+
405
+ return <ChatUI messages={messages} onSend={sendMessage} />;
406
+ }
407
+ ```
408
+
409
+ ### Removed Exports
410
+
411
+ - `WebSocketChatCustomerProvider`
412
+ - `WebSocketChatAdminProvider`
413
+ - `useWebSocketChatCustomer`
414
+ - `useWebSocketChatAdmin`
415
+ - `useWebSocketChatBase`
416
+ - All UI components (`ChatMessages`, `ChatInput`, etc.)
417
+
418
+ ## Development
419
+
420
+ ```bash
421
+ # Build
422
+ pnpm build
423
+
424
+ # Type check
425
+ pnpm typecheck
426
+
427
+ # Watch mode
428
+ pnpm dev
429
+ ```
430
+
431
+ ## License
432
+
433
+ MIT
@@ -1,15 +1,257 @@
1
1
  import { ApiClientOptions, ApiResponse } from '@elqnt/api-client';
2
2
  import { ResponseMetadata } from '@elqnt/types';
3
- import { ChatSummary } from '../models/index.mjs';
4
- export { Chat } from '../models/index.mjs';
5
- import '@elqnt/kg';
6
- import '@elqnt/docs';
3
+ import { Chat, ChatSummary } from '../models/index.mjs';
7
4
 
8
5
  /**
9
- * Chat API functions
6
+ * Stream API
10
7
  *
11
- * Browser-side API client for chat operations.
12
- * Uses @elqnt/api-client for HTTP requests with automatic token management.
8
+ * Low-level functions for chat streaming operations.
9
+ * These are used internally by the transport layer but can also
10
+ * be used directly for custom implementations.
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * import { createChat, sendChatMessage, loadChat } from "@elqnt/chat/api";
15
+ *
16
+ * // Create a new chat
17
+ * const chatKey = await createChat({
18
+ * baseUrl: "https://api.example.com/chat",
19
+ * orgId: "org-123",
20
+ * userId: "user-456",
21
+ * });
22
+ *
23
+ * // Send a message
24
+ * await sendChatMessage({
25
+ * baseUrl: "https://api.example.com/chat",
26
+ * orgId: "org-123",
27
+ * chatKey,
28
+ * userId: "user-456",
29
+ * content: "Hello!",
30
+ * });
31
+ * ```
32
+ */
33
+
34
+ /**
35
+ * Base options for all stream API calls
36
+ */
37
+ interface StreamApiOptions {
38
+ /** Base URL for the chat server */
39
+ baseUrl: string;
40
+ /** Organization ID */
41
+ orgId: string;
42
+ /** User ID */
43
+ userId: string;
44
+ }
45
+ /**
46
+ * Response from stream API calls
47
+ */
48
+ interface StreamApiResponse<T = unknown> {
49
+ success: boolean;
50
+ data?: T;
51
+ error?: string;
52
+ }
53
+ /**
54
+ * Create chat options
55
+ */
56
+ interface CreateChatApiOptions extends StreamApiOptions {
57
+ /** Optional metadata for the new chat */
58
+ metadata?: Record<string, unknown>;
59
+ }
60
+ /**
61
+ * Create chat response data
62
+ */
63
+ interface CreateChatResponseData {
64
+ chatKey: string;
65
+ }
66
+ /**
67
+ * Send message options
68
+ */
69
+ interface SendMessageApiOptions extends StreamApiOptions {
70
+ /** Chat key */
71
+ chatKey: string;
72
+ /** Message content */
73
+ content: string;
74
+ /** Optional attachments */
75
+ attachments?: unknown[];
76
+ /** Optional message metadata */
77
+ metadata?: Record<string, unknown>;
78
+ }
79
+ /**
80
+ * Load chat options
81
+ */
82
+ interface LoadChatApiOptions extends StreamApiOptions {
83
+ /** Chat key to load */
84
+ chatKey: string;
85
+ }
86
+ /**
87
+ * Load chat response data
88
+ */
89
+ interface LoadChatResponseData {
90
+ chat: Chat;
91
+ }
92
+ /**
93
+ * End chat options
94
+ */
95
+ interface EndChatApiOptions extends StreamApiOptions {
96
+ /** Chat key to end */
97
+ chatKey: string;
98
+ /** Optional end reason */
99
+ reason?: string;
100
+ }
101
+ /**
102
+ * Typing indicator options
103
+ */
104
+ interface TypingApiOptions extends StreamApiOptions {
105
+ /** Chat key */
106
+ chatKey: string;
107
+ /** Whether user is typing */
108
+ typing: boolean;
109
+ }
110
+ /**
111
+ * Generic event options
112
+ */
113
+ interface SendEventApiOptions extends StreamApiOptions {
114
+ /** Chat key */
115
+ chatKey: string;
116
+ /** Event type */
117
+ type: string;
118
+ /** Event data */
119
+ data?: Record<string, unknown>;
120
+ }
121
+ /**
122
+ * Create a new chat session
123
+ *
124
+ * @param options - Create chat options
125
+ * @returns Chat key of the created chat
126
+ *
127
+ * @example
128
+ * ```typescript
129
+ * const chatKey = await createChat({
130
+ * baseUrl: "https://api.example.com/chat",
131
+ * orgId: "org-123",
132
+ * userId: "user-456",
133
+ * metadata: { source: "website" },
134
+ * });
135
+ * ```
136
+ */
137
+ declare function createChat(options: CreateChatApiOptions): Promise<string>;
138
+ /**
139
+ * Send a message in a chat
140
+ *
141
+ * @param options - Send message options
142
+ *
143
+ * @example
144
+ * ```typescript
145
+ * await sendChatMessage({
146
+ * baseUrl: "https://api.example.com/chat",
147
+ * orgId: "org-123",
148
+ * chatKey: "chat-789",
149
+ * userId: "user-456",
150
+ * content: "Hello!",
151
+ * });
152
+ * ```
153
+ */
154
+ declare function sendChatMessage(options: SendMessageApiOptions): Promise<void>;
155
+ /**
156
+ * Load an existing chat
157
+ *
158
+ * @param options - Load chat options
159
+ * @returns The loaded chat object
160
+ *
161
+ * @example
162
+ * ```typescript
163
+ * const chat = await loadChat({
164
+ * baseUrl: "https://api.example.com/chat",
165
+ * orgId: "org-123",
166
+ * chatKey: "chat-789",
167
+ * userId: "user-456",
168
+ * });
169
+ * ```
170
+ */
171
+ declare function loadChat(options: LoadChatApiOptions): Promise<Chat>;
172
+ /**
173
+ * End a chat session
174
+ *
175
+ * @param options - End chat options
176
+ *
177
+ * @example
178
+ * ```typescript
179
+ * await endChat({
180
+ * baseUrl: "https://api.example.com/chat",
181
+ * orgId: "org-123",
182
+ * chatKey: "chat-789",
183
+ * userId: "user-456",
184
+ * reason: "User closed chat",
185
+ * });
186
+ * ```
187
+ */
188
+ declare function endChat(options: EndChatApiOptions): Promise<void>;
189
+ /**
190
+ * Send typing indicator
191
+ *
192
+ * @param options - Typing indicator options
193
+ *
194
+ * @example
195
+ * ```typescript
196
+ * // User started typing
197
+ * await sendTypingIndicator({
198
+ * baseUrl: "https://api.example.com/chat",
199
+ * orgId: "org-123",
200
+ * chatKey: "chat-789",
201
+ * userId: "user-456",
202
+ * typing: true,
203
+ * });
204
+ *
205
+ * // User stopped typing
206
+ * await sendTypingIndicator({
207
+ * baseUrl: "https://api.example.com/chat",
208
+ * orgId: "org-123",
209
+ * chatKey: "chat-789",
210
+ * userId: "user-456",
211
+ * typing: false,
212
+ * });
213
+ * ```
214
+ */
215
+ declare function sendTypingIndicator(options: TypingApiOptions): Promise<void>;
216
+ /**
217
+ * Send a generic event
218
+ *
219
+ * @param options - Event options
220
+ *
221
+ * @example
222
+ * ```typescript
223
+ * await sendEvent({
224
+ * baseUrl: "https://api.example.com/chat",
225
+ * orgId: "org-123",
226
+ * chatKey: "chat-789",
227
+ * userId: "user-456",
228
+ * type: "skill_activate",
229
+ * data: { skillId: "research" },
230
+ * });
231
+ * ```
232
+ */
233
+ declare function sendEvent(options: SendEventApiOptions): Promise<void>;
234
+
235
+ /**
236
+ * Chat API
237
+ *
238
+ * API functions for chat operations.
239
+ *
240
+ * ## Browser API (uses @elqnt/api-client)
241
+ * ```typescript
242
+ * import { getChatHistoryApi, getChatApi } from "@elqnt/chat/api";
243
+ *
244
+ * const history = await getChatHistoryApi({ baseUrl, orgId, limit: 10 });
245
+ * const chat = await getChatApi(chatKey, { baseUrl, orgId });
246
+ * ```
247
+ *
248
+ * ## Stream API (direct HTTP calls)
249
+ * ```typescript
250
+ * import { createChat, sendChatMessage, loadChat } from "@elqnt/chat/api";
251
+ *
252
+ * const chatKey = await createChat({ baseUrl, orgId, userId });
253
+ * await sendChatMessage({ baseUrl, orgId, chatKey, userId, content: "Hello!" });
254
+ * ```
13
255
  */
14
256
 
15
257
  interface ChatHistoryResponse {
@@ -63,4 +305,4 @@ declare function addChatToProjectApi(projectId: string, chatKey: string, options
63
305
  metadata: ResponseMetadata;
64
306
  }>>;
65
307
 
66
- export { type ActiveChatsCountResponse, type ActiveChatsResponse, type ChatHistoryResponse, type ChatResponse, ChatSummary, type UpdateChatResponse, addChatToProjectApi, deleteChatApi, getActiveChatsApi, getActiveChatsCountApi, getChatApi, getChatHistoryApi, updateChatApi, updateProjectChatTitleApi };
308
+ export { type ActiveChatsCountResponse, type ActiveChatsResponse, Chat, type ChatHistoryResponse, type ChatResponse, ChatSummary, type CreateChatApiOptions, type CreateChatResponseData, type EndChatApiOptions, type LoadChatApiOptions, type LoadChatResponseData, type SendEventApiOptions, type SendMessageApiOptions, type StreamApiOptions, type StreamApiResponse, type TypingApiOptions, type UpdateChatResponse, addChatToProjectApi, createChat, deleteChatApi, endChat, getActiveChatsApi, getActiveChatsCountApi, getChatApi, getChatHistoryApi, loadChat, sendChatMessage, sendEvent, sendTypingIndicator, updateChatApi, updateProjectChatTitleApi };