@elqnt/chat 3.0.3 → 3.3.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/api/index.d.mts +17 -2
- package/dist/api/index.d.ts +17 -2
- package/dist/api/index.js +44 -14
- package/dist/api/index.js.map +1 -1
- package/dist/api/index.mjs +35 -14
- package/dist/api/index.mjs.map +1 -1
- package/dist/hooks/index.d.mts +40 -5
- package/dist/hooks/index.d.ts +40 -5
- package/dist/hooks/index.js +179 -18
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +178 -18
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +194 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +188 -18
- package/dist/index.mjs.map +1 -1
- package/dist/models/index.d.mts +129 -2
- package/dist/models/index.d.ts +129 -2
- package/dist/models/index.js +15 -0
- package/dist/models/index.js.map +1 -1
- package/dist/models/index.mjs +10 -0
- package/dist/models/index.mjs.map +1 -1
- package/dist/transport/index.js +72 -5
- package/dist/transport/index.js.map +1 -1
- package/dist/transport/index.mjs +72 -5
- package/dist/transport/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/api/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../api/index.ts","../../api/stream-api.ts"],"sourcesContent":["/**\n * Chat API\n *\n * API functions for chat operations.\n *\n * ## Browser API (uses @elqnt/api-client)\n * ```typescript\n * import { getChatHistoryApi, getChatApi } from \"@elqnt/chat/api\";\n *\n * const history = await getChatHistoryApi({ baseUrl, orgId, limit: 10 });\n * const chat = await getChatApi(chatKey, { baseUrl, orgId });\n * ```\n *\n * ## Stream API (direct HTTP calls)\n * ```typescript\n * import { createChat, sendChatMessage, loadChat } from \"@elqnt/chat/api\";\n *\n * const chatKey = await createChat({ baseUrl, orgId, userId });\n * await sendChatMessage({ baseUrl, orgId, chatKey, userId, content: \"Hello!\" });\n * ```\n */\n\nimport { browserApiRequest } from \"@elqnt/api-client/browser\";\nimport type { ApiResponse, ApiClientOptions } from \"@elqnt/api-client\";\nimport type { ResponseMetadata } from \"@elqnt/types\";\nimport type { ChatSummary, Chat } from \"../models\";\n\n// Re-export types from models\nexport type { ChatSummary, Chat } from \"../models\";\n\n// Re-export stream API functions\nexport {\n createChat,\n sendChatMessage,\n loadChat,\n endChat,\n sendTypingIndicator,\n sendEvent,\n} from \"./stream-api\";\n\nexport type {\n StreamApiOptions,\n StreamApiResponse,\n CreateChatApiOptions,\n CreateChatResponseData,\n SendMessageApiOptions,\n LoadChatApiOptions,\n LoadChatResponseData,\n EndChatApiOptions,\n TypingApiOptions,\n SendEventApiOptions,\n} from \"./stream-api\";\n\n// =============================================================================\n// TYPES\n// =============================================================================\n\nexport interface ChatHistoryResponse {\n chats: ChatSummary[];\n total: number;\n hasMore: boolean;\n metadata: ResponseMetadata;\n}\n\nexport interface ChatResponse {\n chat: ChatSummary;\n metadata: ResponseMetadata;\n}\n\nexport interface UpdateChatResponse {\n chatKey: string;\n title: string;\n pinned: boolean;\n metadata: ResponseMetadata;\n}\n\nexport interface ActiveChatsResponse {\n chats: ChatSummary[];\n metadata: ResponseMetadata;\n}\n\nexport interface ActiveChatsCountResponse {\n count: number;\n metadata: ResponseMetadata;\n}\n\nexport interface WaitingChatsCountResponse {\n count: number;\n metadata: ResponseMetadata;\n}\n\nexport interface QueueResponse {\n queues: Queue[];\n metadata: ResponseMetadata;\n}\n\nexport interface Queue {\n id: string;\n name: string;\n agentId: string;\n waitingCount: number;\n activeCount: number;\n}\n\nexport interface AgentSession {\n agentId: string;\n userId: string;\n userEmail: string;\n status: string;\n connectedAt: string;\n lastActivityAt: string;\n}\n\nexport interface OnlineSessionsResponse {\n sessions: AgentSession[];\n metadata: ResponseMetadata;\n}\n\nexport interface AgentSessionResponse {\n session: AgentSession;\n metadata: ResponseMetadata;\n}\n\n// =============================================================================\n// CHAT HISTORY\n// =============================================================================\n\nexport async function getChatHistoryApi(\n options: ApiClientOptions & { limit?: number; offset?: number; skipCache?: boolean }\n): Promise<ApiResponse<ChatHistoryResponse>> {\n return browserApiRequest(\"/api/v1/chats\", {\n method: \"POST\",\n body: {\n limit: options.limit || 15,\n offset: options.offset || 0,\n ...(options.skipCache ? { skipCache: true } : {}),\n },\n ...options,\n });\n}\n\nexport async function getChatApi(\n chatKey: string,\n options: ApiClientOptions\n): Promise<ApiResponse<ChatResponse>> {\n return browserApiRequest(`/api/v1/chats/${chatKey}`, {\n method: \"GET\",\n ...options,\n });\n}\n\nexport async function updateChatApi(\n chatKey: string,\n updates: { title?: string; pinned?: boolean },\n options: ApiClientOptions\n): Promise<ApiResponse<UpdateChatResponse>> {\n return browserApiRequest(`/api/v1/chats/${chatKey}`, {\n method: \"PATCH\",\n body: updates,\n ...options,\n });\n}\n\nexport async function deleteChatApi(\n chatKey: string,\n options: ApiClientOptions\n): Promise<ApiResponse<{ success: boolean; metadata: ResponseMetadata }>> {\n return browserApiRequest(`/api/v1/chats/${chatKey}`, {\n method: \"DELETE\",\n ...options,\n });\n}\n\n// =============================================================================\n// ACTIVE CHATS\n// =============================================================================\n\nexport async function getActiveChatsCountApi(\n options: ApiClientOptions\n): Promise<ApiResponse<ActiveChatsCountResponse>> {\n return browserApiRequest(\"/api/v1/chats/active/count\", {\n method: \"GET\",\n ...options,\n });\n}\n\nexport async function getActiveChatsApi(\n options: ApiClientOptions & { pastHours?: number }\n): Promise<ApiResponse<ActiveChatsResponse>> {\n const params = new URLSearchParams();\n if (options.pastHours) params.set(\"pastHours\", String(options.pastHours));\n const queryString = params.toString();\n return browserApiRequest(`/api/v1/chats/active${queryString ? `?${queryString}` : \"\"}`, {\n method: \"GET\",\n ...options,\n });\n}\n\n// =============================================================================\n// PROJECT CHATS\n// =============================================================================\n\nexport async function updateProjectChatTitleApi(\n projectId: string,\n chatKey: string,\n title: string,\n options: ApiClientOptions\n): Promise<ApiResponse<{ success: boolean; metadata: ResponseMetadata }>> {\n return browserApiRequest(`/api/v1/projects/${projectId}/chats/${chatKey}/title`, {\n method: \"PUT\",\n body: { title },\n ...options,\n });\n}\n\nexport async function addChatToProjectApi(\n projectId: string,\n chatKey: string,\n options: ApiClientOptions\n): Promise<ApiResponse<{ success: boolean; metadata: ResponseMetadata }>> {\n return browserApiRequest(`/api/v1/projects/${projectId}/chats`, {\n method: \"POST\",\n body: { chatKey },\n ...options,\n });\n}\n\n// =============================================================================\n// WAITING CHATS\n// =============================================================================\n\nexport async function getWaitingChatsCountApi(\n options: ApiClientOptions\n): Promise<ApiResponse<WaitingChatsCountResponse>> {\n return browserApiRequest(\"/api/v1/chats/waiting/count\", {\n method: \"GET\",\n ...options,\n });\n}\n\nexport async function getChatsByUserApi(\n userEmail: string,\n options: ApiClientOptions\n): Promise<ApiResponse<ChatHistoryResponse>> {\n return browserApiRequest(`/api/v1/chats/user/${encodeURIComponent(userEmail)}`, {\n method: \"GET\",\n ...options,\n });\n}\n\n// =============================================================================\n// QUEUES\n// =============================================================================\n\nexport async function listQueuesApi(\n options: ApiClientOptions\n): Promise<ApiResponse<QueueResponse>> {\n return browserApiRequest(\"/api/v1/queues\", {\n method: \"GET\",\n ...options,\n });\n}\n\n// =============================================================================\n// AGENT SESSIONS\n// =============================================================================\n\nexport async function getOnlineSessionsApi(\n options: ApiClientOptions\n): Promise<ApiResponse<OnlineSessionsResponse>> {\n return browserApiRequest(\"/api/v1/agents/sessions/online\", {\n method: \"GET\",\n ...options,\n });\n}\n\nexport async function getAgentSessionApi(\n agentId: string,\n options: ApiClientOptions\n): Promise<ApiResponse<AgentSessionResponse>> {\n return browserApiRequest(`/api/v1/agents/sessions/${agentId}`, {\n method: \"GET\",\n ...options,\n });\n}\n","/**\n * Stream API\n *\n * Low-level functions for chat streaming operations.\n * These are used internally by the transport layer but can also\n * be used directly for custom implementations.\n *\n * @example\n * ```typescript\n * import { createChat, sendChatMessage, loadChat } from \"@elqnt/chat/api\";\n *\n * // Create a new chat\n * const chatKey = await createChat({\n * baseUrl: \"https://api.example.com/chat\",\n * orgId: \"org-123\",\n * userId: \"user-456\",\n * });\n *\n * // Send a message\n * await sendChatMessage({\n * baseUrl: \"https://api.example.com/chat\",\n * orgId: \"org-123\",\n * chatKey,\n * userId: \"user-456\",\n * content: \"Hello!\",\n * });\n * ```\n */\n\nimport type { Chat, ChatMessage } from \"../models\";\n\n/**\n * Base options for all stream API calls\n */\nexport interface StreamApiOptions {\n /** Base URL for the chat server */\n baseUrl: string;\n /** Organization ID */\n orgId: string;\n /** User ID */\n userId: string;\n}\n\n/**\n * Response from stream API calls\n */\nexport interface StreamApiResponse<T = unknown> {\n success: boolean;\n data?: T;\n error?: string;\n}\n\n/**\n * Create chat options\n */\nexport interface CreateChatApiOptions extends StreamApiOptions {\n /** Optional metadata for the new chat */\n metadata?: Record<string, unknown>;\n}\n\n/**\n * Create chat response data\n */\nexport interface CreateChatResponseData {\n chatKey: string;\n}\n\n/**\n * Send message options\n */\nexport interface SendMessageApiOptions extends StreamApiOptions {\n /** Chat key */\n chatKey: string;\n /** Message content */\n content: string;\n /** Optional attachments */\n attachments?: unknown[];\n /** Optional message metadata */\n metadata?: Record<string, unknown>;\n}\n\n/**\n * Load chat options\n */\nexport interface LoadChatApiOptions extends StreamApiOptions {\n /** Chat key to load */\n chatKey: string;\n}\n\n/**\n * Load chat response data\n */\nexport interface LoadChatResponseData {\n chat: Chat;\n}\n\n/**\n * End chat options\n */\nexport interface EndChatApiOptions extends StreamApiOptions {\n /** Chat key to end */\n chatKey: string;\n /** Optional end reason */\n reason?: string;\n}\n\n/**\n * Typing indicator options\n */\nexport interface TypingApiOptions extends StreamApiOptions {\n /** Chat key */\n chatKey: string;\n /** Whether user is typing */\n typing: boolean;\n}\n\n/**\n * Generic event options\n */\nexport interface SendEventApiOptions extends StreamApiOptions {\n /** Chat key */\n chatKey: string;\n /** Event type */\n type: string;\n /** Event data */\n data?: Record<string, unknown>;\n}\n\n/**\n * Internal fetch helper\n */\nasync function streamFetch<T>(\n url: string,\n body: Record<string, unknown>\n): Promise<StreamApiResponse<T>> {\n const response = await fetch(url, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify(body),\n });\n\n if (!response.ok) {\n const errorText = await response.text();\n return {\n success: false,\n error: `API error: ${response.status} - ${errorText}`,\n };\n }\n\n const data = await response.json();\n return { success: true, data };\n}\n\n/**\n * Create a new chat session\n *\n * @param options - Create chat options\n * @returns Chat key of the created chat\n *\n * @example\n * ```typescript\n * const chatKey = await createChat({\n * baseUrl: \"https://api.example.com/chat\",\n * orgId: \"org-123\",\n * userId: \"user-456\",\n * metadata: { source: \"website\" },\n * });\n * ```\n */\nexport async function createChat(\n options: CreateChatApiOptions\n): Promise<string> {\n const { baseUrl, orgId, userId, metadata } = options;\n\n const result = await streamFetch<CreateChatResponseData>(\n `${baseUrl}/create`,\n { orgId, userId, metadata }\n );\n\n if (!result.success || !result.data?.chatKey) {\n throw new Error(result.error || \"Failed to create chat\");\n }\n\n return result.data.chatKey;\n}\n\n/**\n * Send a message in a chat\n *\n * @param options - Send message options\n *\n * @example\n * ```typescript\n * await sendChatMessage({\n * baseUrl: \"https://api.example.com/chat\",\n * orgId: \"org-123\",\n * chatKey: \"chat-789\",\n * userId: \"user-456\",\n * content: \"Hello!\",\n * });\n * ```\n */\nexport async function sendChatMessage(\n options: SendMessageApiOptions\n): Promise<void> {\n const { baseUrl, orgId, chatKey, userId, content, attachments, metadata } =\n options;\n\n const message: Partial<ChatMessage> = {\n id: `msg_${Date.now()}_${Math.random().toString(36).slice(2)}`,\n role: \"user\",\n content,\n time: Date.now(),\n status: \"sending\",\n senderId: userId,\n createdAt: Date.now(),\n attachments: attachments as ChatMessage[\"attachments\"],\n };\n\n const result = await streamFetch(`${baseUrl}/send`, {\n orgId,\n chatKey,\n userId,\n message,\n metadata,\n });\n\n if (!result.success) {\n throw new Error(result.error || \"Failed to send message\");\n }\n}\n\n/**\n * Load an existing chat\n *\n * @param options - Load chat options\n * @returns The loaded chat object\n *\n * @example\n * ```typescript\n * const chat = await loadChat({\n * baseUrl: \"https://api.example.com/chat\",\n * orgId: \"org-123\",\n * chatKey: \"chat-789\",\n * userId: \"user-456\",\n * });\n * ```\n */\nexport async function loadChat(options: LoadChatApiOptions): Promise<Chat> {\n const { baseUrl, orgId, chatKey, userId } = options;\n\n const result = await streamFetch<LoadChatResponseData>(`${baseUrl}/load`, {\n orgId,\n chatKey,\n userId,\n });\n\n if (!result.success || !result.data?.chat) {\n throw new Error(result.error || \"Failed to load chat\");\n }\n\n return result.data.chat;\n}\n\n/**\n * End a chat session\n *\n * @param options - End chat options\n *\n * @example\n * ```typescript\n * await endChat({\n * baseUrl: \"https://api.example.com/chat\",\n * orgId: \"org-123\",\n * chatKey: \"chat-789\",\n * userId: \"user-456\",\n * reason: \"User closed chat\",\n * });\n * ```\n */\nexport async function endChat(options: EndChatApiOptions): Promise<void> {\n const { baseUrl, orgId, chatKey, userId, reason } = options;\n\n const result = await streamFetch(`${baseUrl}/end`, {\n orgId,\n chatKey,\n userId,\n data: reason ? { reason } : undefined,\n });\n\n if (!result.success) {\n throw new Error(result.error || \"Failed to end chat\");\n }\n}\n\n/**\n * Send typing indicator\n *\n * @param options - Typing indicator options\n *\n * @example\n * ```typescript\n * // User started typing\n * await sendTypingIndicator({\n * baseUrl: \"https://api.example.com/chat\",\n * orgId: \"org-123\",\n * chatKey: \"chat-789\",\n * userId: \"user-456\",\n * typing: true,\n * });\n *\n * // User stopped typing\n * await sendTypingIndicator({\n * baseUrl: \"https://api.example.com/chat\",\n * orgId: \"org-123\",\n * chatKey: \"chat-789\",\n * userId: \"user-456\",\n * typing: false,\n * });\n * ```\n */\nexport async function sendTypingIndicator(\n options: TypingApiOptions\n): Promise<void> {\n const { baseUrl, orgId, chatKey, userId, typing } = options;\n\n const result = await streamFetch(`${baseUrl}/typing`, {\n orgId,\n chatKey,\n userId,\n typing,\n });\n\n if (!result.success) {\n throw new Error(result.error || \"Failed to send typing indicator\");\n }\n}\n\n/**\n * Send a generic event\n *\n * @param options - Event options\n *\n * @example\n * ```typescript\n * await sendEvent({\n * baseUrl: \"https://api.example.com/chat\",\n * orgId: \"org-123\",\n * chatKey: \"chat-789\",\n * userId: \"user-456\",\n * type: \"skill_activate\",\n * data: { skillId: \"research\" },\n * });\n * ```\n */\nexport async function sendEvent(options: SendEventApiOptions): Promise<void> {\n const { baseUrl, orgId, chatKey, userId, type, data } = options;\n\n const result = await streamFetch(`${baseUrl}/event`, {\n type,\n orgId,\n chatKey,\n userId,\n data,\n });\n\n if (!result.success) {\n throw new Error(result.error || \"Failed to send event\");\n }\n}\n"],"mappings":";;;AAsBA,SAAS,yBAAyB;;;AC6GlC,eAAe,YACb,KACA,MAC+B;AAC/B,QAAM,WAAW,MAAM,MAAM,KAAK;AAAA,IAChC,QAAQ;AAAA,IACR,SAAS,EAAE,gBAAgB,mBAAmB;AAAA,IAC9C,MAAM,KAAK,UAAU,IAAI;AAAA,EAC3B,CAAC;AAED,MAAI,CAAC,SAAS,IAAI;AAChB,UAAM,YAAY,MAAM,SAAS,KAAK;AACtC,WAAO;AAAA,MACL,SAAS;AAAA,MACT,OAAO,cAAc,SAAS,MAAM,MAAM,SAAS;AAAA,IACrD;AAAA,EACF;AAEA,QAAM,OAAO,MAAM,SAAS,KAAK;AACjC,SAAO,EAAE,SAAS,MAAM,KAAK;AAC/B;AAkBA,eAAsB,WACpB,SACiB;AACjB,QAAM,EAAE,SAAS,OAAO,QAAQ,SAAS,IAAI;AAE7C,QAAM,SAAS,MAAM;AAAA,IACnB,GAAG,OAAO;AAAA,IACV,EAAE,OAAO,QAAQ,SAAS;AAAA,EAC5B;AAEA,MAAI,CAAC,OAAO,WAAW,CAAC,OAAO,MAAM,SAAS;AAC5C,UAAM,IAAI,MAAM,OAAO,SAAS,uBAAuB;AAAA,EACzD;AAEA,SAAO,OAAO,KAAK;AACrB;AAkBA,eAAsB,gBACpB,SACe;AACf,QAA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,SAC4C;AAC5C,SAAO,kBAAkB,2BAA2B,OAAO,IAAI;AAAA,IAC7D,QAAQ;AAAA,IACR,GAAG;AAAA,EACL,CAAC;AACH;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../api/index.ts","../../api/stream-api.ts","../../api/memory.ts"],"sourcesContent":["/**\n * Chat API\n *\n * API functions for chat operations.\n *\n * ## Browser API (uses @elqnt/api-client)\n * ```typescript\n * import { getChatHistoryApi, getChatApi } from \"@elqnt/chat/api\";\n *\n * const history = await getChatHistoryApi({ baseUrl, orgId, limit: 10 });\n * const chat = await getChatApi(chatKey, { baseUrl, orgId });\n * ```\n *\n * ## Stream API (direct HTTP calls)\n * ```typescript\n * import { createChat, sendChatMessage, loadChat } from \"@elqnt/chat/api\";\n *\n * const chatKey = await createChat({ baseUrl, orgId, userId });\n * await sendChatMessage({ baseUrl, orgId, chatKey, userId, content: \"Hello!\" });\n * ```\n */\n\nimport { browserApiRequest } from \"@elqnt/api-client/browser\";\nimport type { ApiResponse, ApiClientOptions } from \"@elqnt/api-client\";\nimport type { ResponseMetadata } from \"@elqnt/types\";\nimport type { ChatSummary, Chat } from \"../models\";\n\n// Re-export types from models\nexport type { ChatSummary, Chat } from \"../models\";\n\n// Re-export stream API functions\nexport {\n createChat,\n sendChatMessage,\n loadChat,\n endChat,\n sendTypingIndicator,\n sendEvent,\n} from \"./stream-api\";\n\nexport type {\n StreamApiOptions,\n StreamApiResponse,\n CreateChatApiOptions,\n CreateChatResponseData,\n SendMessageApiOptions,\n LoadChatApiOptions,\n LoadChatResponseData,\n EndChatApiOptions,\n TypingApiOptions,\n SendEventApiOptions,\n} from \"./stream-api\";\n\n// =============================================================================\n// TYPES\n// =============================================================================\n\nexport interface ChatHistoryResponse {\n chats: ChatSummary[];\n total: number;\n hasMore: boolean;\n metadata: ResponseMetadata;\n}\n\nexport interface ChatResponse {\n chat: ChatSummary;\n metadata: ResponseMetadata;\n}\n\nexport interface UpdateChatResponse {\n chatKey: string;\n title: string;\n pinned: boolean;\n metadata: ResponseMetadata;\n}\n\nexport interface ActiveChatsResponse {\n chats: ChatSummary[];\n metadata: ResponseMetadata;\n}\n\nexport interface ActiveChatsCountResponse {\n count: number;\n metadata: ResponseMetadata;\n}\n\nexport interface WaitingChatsCountResponse {\n count: number;\n metadata: ResponseMetadata;\n}\n\nexport interface QueueResponse {\n queues: Queue[];\n metadata: ResponseMetadata;\n}\n\nexport interface Queue {\n id: string;\n name: string;\n agentId: string;\n waitingCount: number;\n activeCount: number;\n}\n\nexport interface AgentSession {\n agentId: string;\n userId: string;\n userEmail: string;\n status: string;\n connectedAt: string;\n lastActivityAt: string;\n}\n\nexport interface OnlineSessionsResponse {\n sessions: AgentSession[];\n metadata: ResponseMetadata;\n}\n\nexport interface AgentSessionResponse {\n session: AgentSession;\n metadata: ResponseMetadata;\n}\n\n// =============================================================================\n// CHAT HISTORY\n// =============================================================================\n\nexport async function getChatHistoryApi(\n options: ApiClientOptions & { limit?: number; offset?: number; skipCache?: boolean }\n): Promise<ApiResponse<ChatHistoryResponse>> {\n return browserApiRequest(\"/api/v1/chats\", {\n method: \"POST\",\n body: {\n limit: options.limit || 15,\n offset: options.offset || 0,\n ...(options.skipCache ? { skipCache: true } : {}),\n },\n ...options,\n });\n}\n\nexport async function getChatApi(\n chatKey: string,\n options: ApiClientOptions\n): Promise<ApiResponse<ChatResponse>> {\n return browserApiRequest(`/api/v1/chats/${chatKey}`, {\n method: \"GET\",\n ...options,\n });\n}\n\nexport async function updateChatApi(\n chatKey: string,\n updates: { title?: string; pinned?: boolean },\n options: ApiClientOptions\n): Promise<ApiResponse<UpdateChatResponse>> {\n return browserApiRequest(`/api/v1/chats/${chatKey}`, {\n method: \"PATCH\",\n body: updates,\n ...options,\n });\n}\n\nexport async function deleteChatApi(\n chatKey: string,\n options: ApiClientOptions\n): Promise<ApiResponse<{ success: boolean; metadata: ResponseMetadata }>> {\n return browserApiRequest(`/api/v1/chats/${chatKey}`, {\n method: \"DELETE\",\n ...options,\n });\n}\n\n// =============================================================================\n// ACTIVE CHATS\n// =============================================================================\n\nexport async function getActiveChatsCountApi(\n options: ApiClientOptions\n): Promise<ApiResponse<ActiveChatsCountResponse>> {\n return browserApiRequest(\"/api/v1/chats/active/count\", {\n method: \"GET\",\n ...options,\n });\n}\n\nexport async function getActiveChatsApi(\n options: ApiClientOptions & { pastHours?: number }\n): Promise<ApiResponse<ActiveChatsResponse>> {\n const params = new URLSearchParams();\n if (options.pastHours) params.set(\"pastHours\", String(options.pastHours));\n const queryString = params.toString();\n return browserApiRequest(`/api/v1/chats/active${queryString ? `?${queryString}` : \"\"}`, {\n method: \"GET\",\n ...options,\n });\n}\n\n// =============================================================================\n// PROJECT CHATS\n// =============================================================================\n\nexport async function updateProjectChatTitleApi(\n projectId: string,\n chatKey: string,\n title: string,\n options: ApiClientOptions\n): Promise<ApiResponse<{ success: boolean; metadata: ResponseMetadata }>> {\n return browserApiRequest(`/api/v1/projects/${projectId}/chats/${chatKey}/title`, {\n method: \"PUT\",\n body: { title },\n ...options,\n });\n}\n\nexport async function addChatToProjectApi(\n projectId: string,\n chatKey: string,\n options: ApiClientOptions\n): Promise<ApiResponse<{ success: boolean; metadata: ResponseMetadata }>> {\n return browserApiRequest(`/api/v1/projects/${projectId}/chats`, {\n method: \"POST\",\n body: { chatKey },\n ...options,\n });\n}\n\n// =============================================================================\n// WAITING CHATS\n// =============================================================================\n\nexport async function getWaitingChatsCountApi(\n options: ApiClientOptions\n): Promise<ApiResponse<WaitingChatsCountResponse>> {\n return browserApiRequest(\"/api/v1/chats/waiting/count\", {\n method: \"GET\",\n ...options,\n });\n}\n\nexport async function getChatsByUserApi(\n userEmail: string,\n options: ApiClientOptions\n): Promise<ApiResponse<ChatHistoryResponse>> {\n return browserApiRequest(`/api/v1/chats/user/${encodeURIComponent(userEmail)}`, {\n method: \"GET\",\n ...options,\n });\n}\n\n// =============================================================================\n// QUEUES\n// =============================================================================\n\nexport async function listQueuesApi(\n options: ApiClientOptions\n): Promise<ApiResponse<QueueResponse>> {\n return browserApiRequest(\"/api/v1/queues\", {\n method: \"GET\",\n ...options,\n });\n}\n\n// =============================================================================\n// AGENT SESSIONS\n// =============================================================================\n\nexport async function getOnlineSessionsApi(\n options: ApiClientOptions\n): Promise<ApiResponse<OnlineSessionsResponse>> {\n return browserApiRequest(\"/api/v1/agents/sessions/online\", {\n method: \"GET\",\n ...options,\n });\n}\n\nexport async function getAgentSessionApi(\n agentId: string,\n options: ApiClientOptions\n): Promise<ApiResponse<AgentSessionResponse>> {\n return browserApiRequest(`/api/v1/agents/sessions/${agentId}`, {\n method: \"GET\",\n ...options,\n });\n}\n\n// =============================================================================\n// MEMORY\n// =============================================================================\n\nexport {\n getProfileApi,\n patchProfileApi,\n replaceProfileApi,\n clearProfileApi,\n deleteContactApi,\n deleteNoteApi,\n getSummaryApi,\n clearSummaryApi,\n regenerateSummaryApi,\n} from \"./memory\";\n\nexport type { SummaryView } from \"./memory\";\n","/**\n * Stream API\n *\n * Low-level functions for chat streaming operations.\n * These are used internally by the transport layer but can also\n * be used directly for custom implementations.\n *\n * @example\n * ```typescript\n * import { createChat, sendChatMessage, loadChat } from \"@elqnt/chat/api\";\n *\n * // Create a new chat\n * const chatKey = await createChat({\n * baseUrl: \"https://api.example.com/chat\",\n * orgId: \"org-123\",\n * userId: \"user-456\",\n * });\n *\n * // Send a message\n * await sendChatMessage({\n * baseUrl: \"https://api.example.com/chat\",\n * orgId: \"org-123\",\n * chatKey,\n * userId: \"user-456\",\n * content: \"Hello!\",\n * });\n * ```\n */\n\nimport type { Chat, ChatMessage } from \"../models\";\n\n/**\n * Base options for all stream API calls\n */\nexport interface StreamApiOptions {\n /** Base URL for the chat server */\n baseUrl: string;\n /** Organization ID */\n orgId: string;\n /** User ID */\n userId: string;\n}\n\n/**\n * Response from stream API calls\n */\nexport interface StreamApiResponse<T = unknown> {\n success: boolean;\n data?: T;\n error?: string;\n}\n\n/**\n * Create chat options\n */\nexport interface CreateChatApiOptions extends StreamApiOptions {\n /** Optional metadata for the new chat */\n metadata?: Record<string, unknown>;\n}\n\n/**\n * Create chat response data\n */\nexport interface CreateChatResponseData {\n chatKey: string;\n}\n\n/**\n * Send message options\n */\nexport interface SendMessageApiOptions extends StreamApiOptions {\n /** Chat key */\n chatKey: string;\n /** Message content */\n content: string;\n /** Optional attachments */\n attachments?: unknown[];\n /** Optional message metadata */\n metadata?: Record<string, unknown>;\n}\n\n/**\n * Load chat options\n */\nexport interface LoadChatApiOptions extends StreamApiOptions {\n /** Chat key to load */\n chatKey: string;\n}\n\n/**\n * Load chat response data\n */\nexport interface LoadChatResponseData {\n chat: Chat;\n}\n\n/**\n * End chat options\n */\nexport interface EndChatApiOptions extends StreamApiOptions {\n /** Chat key to end */\n chatKey: string;\n /** Optional end reason */\n reason?: string;\n}\n\n/**\n * Typing indicator options\n */\nexport interface TypingApiOptions extends StreamApiOptions {\n /** Chat key */\n chatKey: string;\n /** Whether user is typing */\n typing: boolean;\n}\n\n/**\n * Generic event options\n */\nexport interface SendEventApiOptions extends StreamApiOptions {\n /** Chat key */\n chatKey: string;\n /** Event type */\n type: string;\n /** Event data */\n data?: Record<string, unknown>;\n}\n\n/**\n * Internal fetch helper\n */\nasync function streamFetch<T>(\n url: string,\n body: Record<string, unknown>\n): Promise<StreamApiResponse<T>> {\n const response = await fetch(url, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify(body),\n });\n\n if (!response.ok) {\n const errorText = await response.text();\n return {\n success: false,\n error: `API error: ${response.status} - ${errorText}`,\n };\n }\n\n const data = await response.json();\n return { success: true, data };\n}\n\n/**\n * Create a new chat session\n *\n * @param options - Create chat options\n * @returns Chat key of the created chat\n *\n * @example\n * ```typescript\n * const chatKey = await createChat({\n * baseUrl: \"https://api.example.com/chat\",\n * orgId: \"org-123\",\n * userId: \"user-456\",\n * metadata: { source: \"website\" },\n * });\n * ```\n */\nexport async function createChat(\n options: CreateChatApiOptions\n): Promise<string> {\n const { baseUrl, orgId, userId, metadata } = options;\n\n const result = await streamFetch<CreateChatResponseData>(\n `${baseUrl}/create`,\n { orgId, userId, metadata }\n );\n\n if (!result.success || !result.data?.chatKey) {\n throw new Error(result.error || \"Failed to create chat\");\n }\n\n return result.data.chatKey;\n}\n\n/**\n * Send a message in a chat\n *\n * @param options - Send message options\n *\n * @example\n * ```typescript\n * await sendChatMessage({\n * baseUrl: \"https://api.example.com/chat\",\n * orgId: \"org-123\",\n * chatKey: \"chat-789\",\n * userId: \"user-456\",\n * content: \"Hello!\",\n * });\n * ```\n */\nexport async function sendChatMessage(\n options: SendMessageApiOptions\n): Promise<void> {\n const { baseUrl, orgId, chatKey, userId, content, attachments, metadata } =\n options;\n\n const message: Partial<ChatMessage> = {\n id: `msg_${Date.now()}_${Math.random().toString(36).slice(2)}`,\n role: \"user\",\n content,\n time: Date.now(),\n status: \"sending\",\n senderId: userId,\n createdAt: Date.now(),\n attachments: attachments as ChatMessage[\"attachments\"],\n };\n\n const result = await streamFetch(`${baseUrl}/send`, {\n orgId,\n chatKey,\n userId,\n message,\n metadata,\n });\n\n if (!result.success) {\n throw new Error(result.error || \"Failed to send message\");\n }\n}\n\n/**\n * Load an existing chat\n *\n * @param options - Load chat options\n * @returns The loaded chat object\n *\n * @example\n * ```typescript\n * const chat = await loadChat({\n * baseUrl: \"https://api.example.com/chat\",\n * orgId: \"org-123\",\n * chatKey: \"chat-789\",\n * userId: \"user-456\",\n * });\n * ```\n */\nexport async function loadChat(options: LoadChatApiOptions): Promise<Chat> {\n const { baseUrl, orgId, chatKey, userId } = options;\n\n const result = await streamFetch<LoadChatResponseData>(`${baseUrl}/load`, {\n orgId,\n chatKey,\n userId,\n });\n\n if (!result.success || !result.data?.chat) {\n throw new Error(result.error || \"Failed to load chat\");\n }\n\n return result.data.chat;\n}\n\n/**\n * End a chat session\n *\n * @param options - End chat options\n *\n * @example\n * ```typescript\n * await endChat({\n * baseUrl: \"https://api.example.com/chat\",\n * orgId: \"org-123\",\n * chatKey: \"chat-789\",\n * userId: \"user-456\",\n * reason: \"User closed chat\",\n * });\n * ```\n */\nexport async function endChat(options: EndChatApiOptions): Promise<void> {\n const { baseUrl, orgId, chatKey, userId, reason } = options;\n\n const result = await streamFetch(`${baseUrl}/end`, {\n orgId,\n chatKey,\n userId,\n data: reason ? { reason } : undefined,\n });\n\n if (!result.success) {\n throw new Error(result.error || \"Failed to end chat\");\n }\n}\n\n/**\n * Send typing indicator\n *\n * @param options - Typing indicator options\n *\n * @example\n * ```typescript\n * // User started typing\n * await sendTypingIndicator({\n * baseUrl: \"https://api.example.com/chat\",\n * orgId: \"org-123\",\n * chatKey: \"chat-789\",\n * userId: \"user-456\",\n * typing: true,\n * });\n *\n * // User stopped typing\n * await sendTypingIndicator({\n * baseUrl: \"https://api.example.com/chat\",\n * orgId: \"org-123\",\n * chatKey: \"chat-789\",\n * userId: \"user-456\",\n * typing: false,\n * });\n * ```\n */\nexport async function sendTypingIndicator(\n options: TypingApiOptions\n): Promise<void> {\n const { baseUrl, orgId, chatKey, userId, typing } = options;\n\n const result = await streamFetch(`${baseUrl}/typing`, {\n orgId,\n chatKey,\n userId,\n typing,\n });\n\n if (!result.success) {\n throw new Error(result.error || \"Failed to send typing indicator\");\n }\n}\n\n/**\n * Send a generic event\n *\n * @param options - Event options\n *\n * @example\n * ```typescript\n * await sendEvent({\n * baseUrl: \"https://api.example.com/chat\",\n * orgId: \"org-123\",\n * chatKey: \"chat-789\",\n * userId: \"user-456\",\n * type: \"skill_activate\",\n * data: { skillId: \"research\" },\n * });\n * ```\n */\nexport async function sendEvent(options: SendEventApiOptions): Promise<void> {\n const { baseUrl, orgId, chatKey, userId, type, data } = options;\n\n const result = await streamFetch(`${baseUrl}/event`, {\n type,\n orgId,\n chatKey,\n userId,\n data,\n });\n\n if (!result.success) {\n throw new Error(result.error || \"Failed to send event\");\n }\n}\n","import { browserApiRequest } from \"@elqnt/api-client/browser\";\nimport type { ApiClientOptions, ApiResponse } from \"@elqnt/api-client\";\nimport type { MemoryProfile } from \"../models\";\n\nexport interface SummaryView {\n chatKey: string;\n text: string;\n updatedAt: string;\n}\n\nexport const getProfileApi = (o: ApiClientOptions): Promise<ApiResponse<MemoryProfile>> =>\n browserApiRequest(\"/api/v1/memory/profile\", { method: \"GET\", ...o });\n\nexport const patchProfileApi = (patch: Partial<MemoryProfile>, o: ApiClientOptions): Promise<ApiResponse<MemoryProfile>> =>\n browserApiRequest(\"/api/v1/memory/profile\", { method: \"PATCH\", body: patch, ...o });\n\nexport const replaceProfileApi = (p: MemoryProfile, o: ApiClientOptions): Promise<ApiResponse<MemoryProfile>> =>\n browserApiRequest(\"/api/v1/memory/profile\", { method: \"PUT\", body: p, ...o });\n\nexport const clearProfileApi = (o: ApiClientOptions): Promise<ApiResponse<MemoryProfile>> =>\n browserApiRequest(\"/api/v1/memory/profile\", { method: \"DELETE\", ...o });\n\nexport const deleteContactApi = (name: string, o: ApiClientOptions): Promise<ApiResponse<MemoryProfile>> =>\n browserApiRequest(`/api/v1/memory/profile/contacts/${encodeURIComponent(name)}`, { method: \"DELETE\", ...o });\n\nexport const deleteNoteApi = (index: number, o: ApiClientOptions): Promise<ApiResponse<MemoryProfile>> =>\n browserApiRequest(`/api/v1/memory/profile/notes/${index}`, { method: \"DELETE\", ...o });\n\nexport const getSummaryApi = (chatKey: string, o: ApiClientOptions): Promise<ApiResponse<SummaryView>> =>\n browserApiRequest(`/api/v1/chats/${chatKey}/summary`, { method: \"GET\", ...o });\n\nexport const clearSummaryApi = (chatKey: string, o: ApiClientOptions): Promise<ApiResponse<void>> =>\n browserApiRequest(`/api/v1/chats/${chatKey}/summary`, { method: \"DELETE\", ...o });\n\nexport const regenerateSummaryApi = (chatKey: string, o: ApiClientOptions): Promise<ApiResponse<SummaryView>> =>\n browserApiRequest(`/api/v1/chats/${chatKey}/summary/regenerate`, { method: \"POST\", ...o });\n"],"mappings":";;;AAsBA,SAAS,qBAAAA,0BAAyB;;;AC6GlC,eAAe,YACb,KACA,MAC+B;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BACpB,SACiD;AACjD,SAAOA,mBAAkB,+BAA+B;AAAA,IACtD,QAAQ;AAAA,IACR,GAAG;AAAA,EACL,CAAC;AACH;AAEA,eAAsB,kBACpB,WACA,SAC2C;AAC3C,SAAOA,mBAAkB,sBAAsB,mBAAmB,SAAS,CAAC,IAAI;AAAA,IAC9E,QAAQ;AAAA,IACR,GAAG;AAAA,EACL,CAAC;AACH;AAMA,eAAsB,cACpB,SACqC;AACrC,SAAOA,mBAAkB,kBAAkB;AAAA,IACzC,QAAQ;AAAA,IACR,GAAG;AAAA,EACL,CAAC;AACH;AAMA,eAAsB,qBACpB,SAC8C;AAC9C,SAAOA,mBAAkB,kCAAkC;AAAA,IACzD,QAAQ;AAAA,IACR,GAAG;AAAA,EACL,CAAC;AACH;AAEA,eAAsB,mBACpB,SACA,SAC4C;AAC5C,SAAOA,mBAAkB,2BAA2B,OAAO,IAAI;AAAA,IAC7D,QAAQ;AAAA,IACR,GAAG;AAAA,EACL,CAAC;AACH;","names":["browserApiRequest","browserApiRequest"]}
|
package/dist/hooks/index.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export { UseAsyncOptions, UseAsyncReturn, useApiAsync } from '@elqnt/api-client/hooks';
|
|
2
|
-
import { ChatEvent, Chat, ChatMessage, ChatSummary } from '../models/index.mjs';
|
|
2
|
+
import { ChatEvent, Chat, ChatMessage, ChatSummary, MemoryProfile } from '../models/index.mjs';
|
|
3
3
|
import { C as ChatTransport, e as TransportError, g as TransportState, R as RetryConfig, b as ConnectionMetrics, U as Unsubscribe } from '../types-CQHtUQ6p.mjs';
|
|
4
4
|
import { ApiClientOptions } from '@elqnt/api-client';
|
|
5
|
-
import { Queue, AgentSession } from '../api/index.mjs';
|
|
5
|
+
import { Queue, AgentSession, SummaryView } from '../api/index.mjs';
|
|
6
6
|
import '@elqnt/kg';
|
|
7
7
|
import '@elqnt/types';
|
|
8
8
|
import '@elqnt/docs';
|
|
@@ -50,8 +50,8 @@ interface UseChatReturn {
|
|
|
50
50
|
startChat: (metadata?: Record<string, unknown>) => Promise<string>;
|
|
51
51
|
/** Load an existing chat, returns the loaded chat */
|
|
52
52
|
loadChat: (chatKey: string) => Promise<Chat>;
|
|
53
|
-
/** Send a text message */
|
|
54
|
-
sendMessage: (content: string, attachments?: unknown[]) => Promise<void>;
|
|
53
|
+
/** Send a text message. Optional `data` is forwarded to the backend (e.g. { saveAttachments: true }). */
|
|
54
|
+
sendMessage: (content: string, attachments?: unknown[], data?: Record<string, unknown>) => Promise<void>;
|
|
55
55
|
/** Send a raw chat event (for custom event types) */
|
|
56
56
|
sendEvent: (event: Omit<ChatEvent, "timestamp">) => Promise<void>;
|
|
57
57
|
/** End the current chat */
|
|
@@ -169,6 +169,41 @@ declare function useHumanAgentSessions(options: UseHumanAgentSessionsOptions): {
|
|
|
169
169
|
getAgentSession: (agentId: string) => Promise<AgentSession | null>;
|
|
170
170
|
};
|
|
171
171
|
|
|
172
|
+
interface UseMemoryResult {
|
|
173
|
+
/** Current local copy of the user profile (null before first load/mutation) */
|
|
174
|
+
profile: MemoryProfile | null;
|
|
175
|
+
/** True while any profile mutation is in flight */
|
|
176
|
+
loading: boolean;
|
|
177
|
+
/** Apply a partial update to the profile */
|
|
178
|
+
patchProfile: (patch: Partial<MemoryProfile>) => Promise<MemoryProfile | null>;
|
|
179
|
+
/** Replace the profile entirely */
|
|
180
|
+
replaceProfile: (p: MemoryProfile) => Promise<MemoryProfile | null>;
|
|
181
|
+
/** Clear (reset) the full profile */
|
|
182
|
+
clearProfile: () => Promise<MemoryProfile | null>;
|
|
183
|
+
/** Remove a contact by name */
|
|
184
|
+
deleteContact: (name: string) => Promise<MemoryProfile | null>;
|
|
185
|
+
/** Remove a note by index */
|
|
186
|
+
deleteNote: (index: number) => Promise<MemoryProfile | null>;
|
|
187
|
+
/** Delete the summary for a chat */
|
|
188
|
+
clearSummary: (chatKey: string) => Promise<void>;
|
|
189
|
+
/** Trigger summary regeneration and return the new summary */
|
|
190
|
+
regenerateSummary: (chatKey: string) => Promise<SummaryView | null>;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Hook for managing memory (user profile + chat summaries)
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* ```tsx
|
|
197
|
+
* const { profile, loading, patchProfile, clearProfile } = useMemory(
|
|
198
|
+
* { baseUrl: apiGatewayUrl, orgId: selectedOrgId },
|
|
199
|
+
* initialProfile,
|
|
200
|
+
* );
|
|
201
|
+
*
|
|
202
|
+
* await patchProfile({ name: "Alice" });
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
declare function useMemory(options: ApiClientOptions, initialProfile?: MemoryProfile | null): UseMemoryResult;
|
|
206
|
+
|
|
172
207
|
/**
|
|
173
208
|
* Creates a ref that stays synchronized with the provided options.
|
|
174
209
|
* Useful for accessing current options values in callbacks without
|
|
@@ -176,4 +211,4 @@ declare function useHumanAgentSessions(options: UseHumanAgentSessionsOptions): {
|
|
|
176
211
|
*/
|
|
177
212
|
declare function useOptionsRef<T>(options: T): React.MutableRefObject<T>;
|
|
178
213
|
|
|
179
|
-
export { type ChatHistoryResult, type UseChatHistoryOptions, type UseChatMonitoringOptions, type UseChatOptions, type UseChatReturn, type UseHumanAgentSessionsOptions, useChat, useChatHistory, useChatMonitoring, useHumanAgentSessions, useOptionsRef };
|
|
214
|
+
export { type ChatHistoryResult, type UseChatHistoryOptions, type UseChatMonitoringOptions, type UseChatOptions, type UseChatReturn, type UseHumanAgentSessionsOptions, type UseMemoryResult, useChat, useChatHistory, useChatMonitoring, useHumanAgentSessions, useMemory, useOptionsRef };
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export { UseAsyncOptions, UseAsyncReturn, useApiAsync } from '@elqnt/api-client/hooks';
|
|
2
|
-
import { ChatEvent, Chat, ChatMessage, ChatSummary } from '../models/index.js';
|
|
2
|
+
import { ChatEvent, Chat, ChatMessage, ChatSummary, MemoryProfile } from '../models/index.js';
|
|
3
3
|
import { C as ChatTransport, e as TransportError, g as TransportState, R as RetryConfig, b as ConnectionMetrics, U as Unsubscribe } from '../types-7UNI1iYv.js';
|
|
4
4
|
import { ApiClientOptions } from '@elqnt/api-client';
|
|
5
|
-
import { Queue, AgentSession } from '../api/index.js';
|
|
5
|
+
import { Queue, AgentSession, SummaryView } from '../api/index.js';
|
|
6
6
|
import '@elqnt/kg';
|
|
7
7
|
import '@elqnt/types';
|
|
8
8
|
import '@elqnt/docs';
|
|
@@ -50,8 +50,8 @@ interface UseChatReturn {
|
|
|
50
50
|
startChat: (metadata?: Record<string, unknown>) => Promise<string>;
|
|
51
51
|
/** Load an existing chat, returns the loaded chat */
|
|
52
52
|
loadChat: (chatKey: string) => Promise<Chat>;
|
|
53
|
-
/** Send a text message */
|
|
54
|
-
sendMessage: (content: string, attachments?: unknown[]) => Promise<void>;
|
|
53
|
+
/** Send a text message. Optional `data` is forwarded to the backend (e.g. { saveAttachments: true }). */
|
|
54
|
+
sendMessage: (content: string, attachments?: unknown[], data?: Record<string, unknown>) => Promise<void>;
|
|
55
55
|
/** Send a raw chat event (for custom event types) */
|
|
56
56
|
sendEvent: (event: Omit<ChatEvent, "timestamp">) => Promise<void>;
|
|
57
57
|
/** End the current chat */
|
|
@@ -169,6 +169,41 @@ declare function useHumanAgentSessions(options: UseHumanAgentSessionsOptions): {
|
|
|
169
169
|
getAgentSession: (agentId: string) => Promise<AgentSession | null>;
|
|
170
170
|
};
|
|
171
171
|
|
|
172
|
+
interface UseMemoryResult {
|
|
173
|
+
/** Current local copy of the user profile (null before first load/mutation) */
|
|
174
|
+
profile: MemoryProfile | null;
|
|
175
|
+
/** True while any profile mutation is in flight */
|
|
176
|
+
loading: boolean;
|
|
177
|
+
/** Apply a partial update to the profile */
|
|
178
|
+
patchProfile: (patch: Partial<MemoryProfile>) => Promise<MemoryProfile | null>;
|
|
179
|
+
/** Replace the profile entirely */
|
|
180
|
+
replaceProfile: (p: MemoryProfile) => Promise<MemoryProfile | null>;
|
|
181
|
+
/** Clear (reset) the full profile */
|
|
182
|
+
clearProfile: () => Promise<MemoryProfile | null>;
|
|
183
|
+
/** Remove a contact by name */
|
|
184
|
+
deleteContact: (name: string) => Promise<MemoryProfile | null>;
|
|
185
|
+
/** Remove a note by index */
|
|
186
|
+
deleteNote: (index: number) => Promise<MemoryProfile | null>;
|
|
187
|
+
/** Delete the summary for a chat */
|
|
188
|
+
clearSummary: (chatKey: string) => Promise<void>;
|
|
189
|
+
/** Trigger summary regeneration and return the new summary */
|
|
190
|
+
regenerateSummary: (chatKey: string) => Promise<SummaryView | null>;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Hook for managing memory (user profile + chat summaries)
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* ```tsx
|
|
197
|
+
* const { profile, loading, patchProfile, clearProfile } = useMemory(
|
|
198
|
+
* { baseUrl: apiGatewayUrl, orgId: selectedOrgId },
|
|
199
|
+
* initialProfile,
|
|
200
|
+
* );
|
|
201
|
+
*
|
|
202
|
+
* await patchProfile({ name: "Alice" });
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
declare function useMemory(options: ApiClientOptions, initialProfile?: MemoryProfile | null): UseMemoryResult;
|
|
206
|
+
|
|
172
207
|
/**
|
|
173
208
|
* Creates a ref that stays synchronized with the provided options.
|
|
174
209
|
* Useful for accessing current options values in callbacks without
|
|
@@ -176,4 +211,4 @@ declare function useHumanAgentSessions(options: UseHumanAgentSessionsOptions): {
|
|
|
176
211
|
*/
|
|
177
212
|
declare function useOptionsRef<T>(options: T): React.MutableRefObject<T>;
|
|
178
213
|
|
|
179
|
-
export { type ChatHistoryResult, type UseChatHistoryOptions, type UseChatMonitoringOptions, type UseChatOptions, type UseChatReturn, type UseHumanAgentSessionsOptions, useChat, useChatHistory, useChatMonitoring, useHumanAgentSessions, useOptionsRef };
|
|
214
|
+
export { type ChatHistoryResult, type UseChatHistoryOptions, type UseChatMonitoringOptions, type UseChatOptions, type UseChatReturn, type UseHumanAgentSessionsOptions, type UseMemoryResult, useChat, useChatHistory, useChatMonitoring, useHumanAgentSessions, useMemory, useOptionsRef };
|
package/dist/hooks/index.js
CHANGED
|
@@ -26,6 +26,7 @@ __export(hooks_exports, {
|
|
|
26
26
|
useChatHistory: () => useChatHistory,
|
|
27
27
|
useChatMonitoring: () => useChatMonitoring,
|
|
28
28
|
useHumanAgentSessions: () => useHumanAgentSessions,
|
|
29
|
+
useMemory: () => useMemory,
|
|
29
30
|
useOptionsRef: () => useOptionsRef
|
|
30
31
|
});
|
|
31
32
|
module.exports = __toCommonJS(hooks_exports);
|
|
@@ -142,6 +143,7 @@ function createSSETransport(options = {}) {
|
|
|
142
143
|
function setupEventListeners(es) {
|
|
143
144
|
es.addEventListener("message", handleMessage);
|
|
144
145
|
const eventTypes = [
|
|
146
|
+
"error",
|
|
145
147
|
"reconnected",
|
|
146
148
|
"typing",
|
|
147
149
|
"stopped_typing",
|
|
@@ -151,21 +153,53 @@ function createSSETransport(options = {}) {
|
|
|
151
153
|
"human_agent_left",
|
|
152
154
|
"chat_ended",
|
|
153
155
|
"chat_updated",
|
|
156
|
+
"chat_removed",
|
|
154
157
|
"load_chat_response",
|
|
155
158
|
"new_chat_created",
|
|
156
159
|
"show_csat_survey",
|
|
157
160
|
"csat_response",
|
|
158
161
|
"user_suggested_actions",
|
|
162
|
+
"user_suggested_action_selected",
|
|
159
163
|
"agent_execution_started",
|
|
160
164
|
"agent_execution_ended",
|
|
161
165
|
"agent_context_update",
|
|
166
|
+
"load_agent_context_response",
|
|
162
167
|
"plan_pending_approval",
|
|
168
|
+
"plan_approved",
|
|
169
|
+
"plan_rejected",
|
|
163
170
|
"step_started",
|
|
164
171
|
"step_completed",
|
|
165
172
|
"step_failed",
|
|
166
173
|
"plan_completed",
|
|
167
174
|
"skills_changed",
|
|
168
|
-
"summary_update"
|
|
175
|
+
"summary_update",
|
|
176
|
+
"message_status_update",
|
|
177
|
+
"delivered",
|
|
178
|
+
"read",
|
|
179
|
+
"sync_metadata_response",
|
|
180
|
+
"sync_user_session_response",
|
|
181
|
+
"client_action",
|
|
182
|
+
"client_action_callback",
|
|
183
|
+
"attachment_processing_started",
|
|
184
|
+
"attachment_processing_progress",
|
|
185
|
+
"attachment_processing_complete",
|
|
186
|
+
"attachment_processing_error",
|
|
187
|
+
"observer_joined",
|
|
188
|
+
"observer_left",
|
|
189
|
+
"block_user",
|
|
190
|
+
"message_edited",
|
|
191
|
+
"message_deleted",
|
|
192
|
+
"message_reaction",
|
|
193
|
+
"user_presence_changed",
|
|
194
|
+
"online_users",
|
|
195
|
+
"get_agents_response",
|
|
196
|
+
"room_created",
|
|
197
|
+
"room_updated",
|
|
198
|
+
"room_deleted",
|
|
199
|
+
"rooms_response",
|
|
200
|
+
"room_user_joined",
|
|
201
|
+
"room_user_left",
|
|
202
|
+
"user_invited"
|
|
169
203
|
];
|
|
170
204
|
eventTypes.forEach((type) => {
|
|
171
205
|
es.addEventListener(type, handleMessage);
|
|
@@ -212,18 +246,34 @@ function createSSETransport(options = {}) {
|
|
|
212
246
|
state = retryCount > 0 ? "reconnecting" : "connecting";
|
|
213
247
|
return new Promise((resolve, reject) => {
|
|
214
248
|
const connectionStart = Date.now();
|
|
215
|
-
const
|
|
249
|
+
const streamParams = new URLSearchParams({
|
|
250
|
+
orgId: cfg.orgId,
|
|
251
|
+
userId: cfg.userId,
|
|
252
|
+
clientType: cfg.clientType
|
|
253
|
+
});
|
|
254
|
+
if (cfg.chatKey) streamParams.set("chatId", cfg.chatKey);
|
|
255
|
+
const url = `${cfg.baseUrl}/stream?${streamParams.toString()}`;
|
|
216
256
|
logger.debug("Connecting to:", url);
|
|
217
257
|
const es = new EventSource(url);
|
|
218
258
|
es.onopen = () => {
|
|
219
259
|
const connectionTime = Date.now() - connectionStart;
|
|
220
260
|
logger.info(`Connected in ${connectionTime}ms`);
|
|
261
|
+
const wasReconnect = retryCount > 0;
|
|
221
262
|
state = "connected";
|
|
222
263
|
error = void 0;
|
|
223
264
|
retryCount = 0;
|
|
224
265
|
metrics.connectedAt = Date.now();
|
|
225
266
|
metrics.latency = connectionTime;
|
|
226
267
|
setupEventListeners(es);
|
|
268
|
+
if (wasReconnect) {
|
|
269
|
+
emit({
|
|
270
|
+
type: "transport_reconnected",
|
|
271
|
+
orgId: cfg.orgId,
|
|
272
|
+
chatKey: cfg.chatKey || "",
|
|
273
|
+
userId: cfg.userId,
|
|
274
|
+
timestamp: Date.now()
|
|
275
|
+
});
|
|
276
|
+
}
|
|
227
277
|
resolve();
|
|
228
278
|
};
|
|
229
279
|
es.onerror = () => {
|
|
@@ -272,7 +322,8 @@ function createSSETransport(options = {}) {
|
|
|
272
322
|
orgId: event.orgId,
|
|
273
323
|
chatKey: event.chatKey,
|
|
274
324
|
userId: event.userId,
|
|
275
|
-
message: event.message
|
|
325
|
+
message: event.message,
|
|
326
|
+
...event.data ? { data: event.data } : {}
|
|
276
327
|
});
|
|
277
328
|
break;
|
|
278
329
|
case "typing":
|
|
@@ -493,7 +544,13 @@ function createFetchSSETransport(options = {}) {
|
|
|
493
544
|
return events;
|
|
494
545
|
}
|
|
495
546
|
async function startStream(cfg) {
|
|
496
|
-
const
|
|
547
|
+
const streamParams = new URLSearchParams({
|
|
548
|
+
orgId: cfg.orgId,
|
|
549
|
+
userId: cfg.userId,
|
|
550
|
+
clientType: cfg.clientType
|
|
551
|
+
});
|
|
552
|
+
if (cfg.chatKey) streamParams.set("chatId", cfg.chatKey);
|
|
553
|
+
const url = `${cfg.baseUrl}/stream?${streamParams.toString()}`;
|
|
497
554
|
logger.debug("Connecting to:", url);
|
|
498
555
|
abortController = new AbortController();
|
|
499
556
|
const response = await customFetch(url, {
|
|
@@ -599,6 +656,7 @@ function createFetchSSETransport(options = {}) {
|
|
|
599
656
|
state = retryCount > 0 ? "reconnecting" : "connecting";
|
|
600
657
|
const connectionStart = Date.now();
|
|
601
658
|
try {
|
|
659
|
+
const wasReconnect = retryCount > 0;
|
|
602
660
|
await startStream(cfg);
|
|
603
661
|
const connectionTime = Date.now() - connectionStart;
|
|
604
662
|
logger.info(`Connected in ${connectionTime}ms`);
|
|
@@ -607,6 +665,15 @@ function createFetchSSETransport(options = {}) {
|
|
|
607
665
|
retryCount = 0;
|
|
608
666
|
metrics.connectedAt = Date.now();
|
|
609
667
|
metrics.latency = connectionTime;
|
|
668
|
+
if (wasReconnect) {
|
|
669
|
+
emit({
|
|
670
|
+
type: "transport_reconnected",
|
|
671
|
+
orgId: cfg.orgId,
|
|
672
|
+
chatKey: cfg.chatKey || "",
|
|
673
|
+
userId: cfg.userId,
|
|
674
|
+
timestamp: Date.now()
|
|
675
|
+
});
|
|
676
|
+
}
|
|
610
677
|
} catch (err) {
|
|
611
678
|
const connectError = {
|
|
612
679
|
code: "CONNECTION_FAILED",
|
|
@@ -648,7 +715,8 @@ function createFetchSSETransport(options = {}) {
|
|
|
648
715
|
orgId: event.orgId,
|
|
649
716
|
chatKey: event.chatKey,
|
|
650
717
|
userId: event.userId,
|
|
651
|
-
message: event.message
|
|
718
|
+
message: event.message,
|
|
719
|
+
...event.data ? { data: event.data } : {}
|
|
652
720
|
});
|
|
653
721
|
break;
|
|
654
722
|
case "typing":
|
|
@@ -968,7 +1036,7 @@ function useChat(options) {
|
|
|
968
1036
|
[orgId, userId]
|
|
969
1037
|
);
|
|
970
1038
|
const sendMessage = (0, import_react.useCallback)(
|
|
971
|
-
async (content, attachments) => {
|
|
1039
|
+
async (content, attachments, data) => {
|
|
972
1040
|
const transport = transportRef.current;
|
|
973
1041
|
if (!transport) {
|
|
974
1042
|
throw new Error("Transport not initialized");
|
|
@@ -993,7 +1061,8 @@ function useChat(options) {
|
|
|
993
1061
|
chatKey,
|
|
994
1062
|
userId,
|
|
995
1063
|
timestamp: Date.now(),
|
|
996
|
-
message
|
|
1064
|
+
message,
|
|
1065
|
+
...data ? { data } : {}
|
|
997
1066
|
});
|
|
998
1067
|
setMetrics((prev) => ({
|
|
999
1068
|
...prev,
|
|
@@ -1132,9 +1201,21 @@ function useChat(options) {
|
|
|
1132
1201
|
var import_react3 = require("react");
|
|
1133
1202
|
|
|
1134
1203
|
// api/index.ts
|
|
1204
|
+
var import_browser2 = require("@elqnt/api-client/browser");
|
|
1205
|
+
|
|
1206
|
+
// api/memory.ts
|
|
1135
1207
|
var import_browser = require("@elqnt/api-client/browser");
|
|
1208
|
+
var patchProfileApi = (patch, o) => (0, import_browser.browserApiRequest)("/api/v1/memory/profile", { method: "PATCH", body: patch, ...o });
|
|
1209
|
+
var replaceProfileApi = (p, o) => (0, import_browser.browserApiRequest)("/api/v1/memory/profile", { method: "PUT", body: p, ...o });
|
|
1210
|
+
var clearProfileApi = (o) => (0, import_browser.browserApiRequest)("/api/v1/memory/profile", { method: "DELETE", ...o });
|
|
1211
|
+
var deleteContactApi = (name, o) => (0, import_browser.browserApiRequest)(`/api/v1/memory/profile/contacts/${encodeURIComponent(name)}`, { method: "DELETE", ...o });
|
|
1212
|
+
var deleteNoteApi = (index, o) => (0, import_browser.browserApiRequest)(`/api/v1/memory/profile/notes/${index}`, { method: "DELETE", ...o });
|
|
1213
|
+
var clearSummaryApi = (chatKey, o) => (0, import_browser.browserApiRequest)(`/api/v1/chats/${chatKey}/summary`, { method: "DELETE", ...o });
|
|
1214
|
+
var regenerateSummaryApi = (chatKey, o) => (0, import_browser.browserApiRequest)(`/api/v1/chats/${chatKey}/summary/regenerate`, { method: "POST", ...o });
|
|
1215
|
+
|
|
1216
|
+
// api/index.ts
|
|
1136
1217
|
async function getChatHistoryApi(options) {
|
|
1137
|
-
return (0,
|
|
1218
|
+
return (0, import_browser2.browserApiRequest)("/api/v1/chats", {
|
|
1138
1219
|
method: "POST",
|
|
1139
1220
|
body: {
|
|
1140
1221
|
limit: options.limit || 15,
|
|
@@ -1145,26 +1226,26 @@ async function getChatHistoryApi(options) {
|
|
|
1145
1226
|
});
|
|
1146
1227
|
}
|
|
1147
1228
|
async function getChatApi(chatKey, options) {
|
|
1148
|
-
return (0,
|
|
1229
|
+
return (0, import_browser2.browserApiRequest)(`/api/v1/chats/${chatKey}`, {
|
|
1149
1230
|
method: "GET",
|
|
1150
1231
|
...options
|
|
1151
1232
|
});
|
|
1152
1233
|
}
|
|
1153
1234
|
async function updateChatApi(chatKey, updates, options) {
|
|
1154
|
-
return (0,
|
|
1235
|
+
return (0, import_browser2.browserApiRequest)(`/api/v1/chats/${chatKey}`, {
|
|
1155
1236
|
method: "PATCH",
|
|
1156
1237
|
body: updates,
|
|
1157
1238
|
...options
|
|
1158
1239
|
});
|
|
1159
1240
|
}
|
|
1160
1241
|
async function deleteChatApi(chatKey, options) {
|
|
1161
|
-
return (0,
|
|
1242
|
+
return (0, import_browser2.browserApiRequest)(`/api/v1/chats/${chatKey}`, {
|
|
1162
1243
|
method: "DELETE",
|
|
1163
1244
|
...options
|
|
1164
1245
|
});
|
|
1165
1246
|
}
|
|
1166
1247
|
async function getActiveChatsCountApi(options) {
|
|
1167
|
-
return (0,
|
|
1248
|
+
return (0, import_browser2.browserApiRequest)("/api/v1/chats/active/count", {
|
|
1168
1249
|
method: "GET",
|
|
1169
1250
|
...options
|
|
1170
1251
|
});
|
|
@@ -1173,37 +1254,37 @@ async function getActiveChatsApi(options) {
|
|
|
1173
1254
|
const params = new URLSearchParams();
|
|
1174
1255
|
if (options.pastHours) params.set("pastHours", String(options.pastHours));
|
|
1175
1256
|
const queryString = params.toString();
|
|
1176
|
-
return (0,
|
|
1257
|
+
return (0, import_browser2.browserApiRequest)(`/api/v1/chats/active${queryString ? `?${queryString}` : ""}`, {
|
|
1177
1258
|
method: "GET",
|
|
1178
1259
|
...options
|
|
1179
1260
|
});
|
|
1180
1261
|
}
|
|
1181
1262
|
async function getWaitingChatsCountApi(options) {
|
|
1182
|
-
return (0,
|
|
1263
|
+
return (0, import_browser2.browserApiRequest)("/api/v1/chats/waiting/count", {
|
|
1183
1264
|
method: "GET",
|
|
1184
1265
|
...options
|
|
1185
1266
|
});
|
|
1186
1267
|
}
|
|
1187
1268
|
async function getChatsByUserApi(userEmail, options) {
|
|
1188
|
-
return (0,
|
|
1269
|
+
return (0, import_browser2.browserApiRequest)(`/api/v1/chats/user/${encodeURIComponent(userEmail)}`, {
|
|
1189
1270
|
method: "GET",
|
|
1190
1271
|
...options
|
|
1191
1272
|
});
|
|
1192
1273
|
}
|
|
1193
1274
|
async function listQueuesApi(options) {
|
|
1194
|
-
return (0,
|
|
1275
|
+
return (0, import_browser2.browserApiRequest)("/api/v1/queues", {
|
|
1195
1276
|
method: "GET",
|
|
1196
1277
|
...options
|
|
1197
1278
|
});
|
|
1198
1279
|
}
|
|
1199
1280
|
async function getOnlineSessionsApi(options) {
|
|
1200
|
-
return (0,
|
|
1281
|
+
return (0, import_browser2.browserApiRequest)("/api/v1/agents/sessions/online", {
|
|
1201
1282
|
method: "GET",
|
|
1202
1283
|
...options
|
|
1203
1284
|
});
|
|
1204
1285
|
}
|
|
1205
1286
|
async function getAgentSessionApi(agentId, options) {
|
|
1206
|
-
return (0,
|
|
1287
|
+
return (0, import_browser2.browserApiRequest)(`/api/v1/agents/sessions/${agentId}`, {
|
|
1207
1288
|
method: "GET",
|
|
1208
1289
|
...options
|
|
1209
1290
|
});
|
|
@@ -1338,6 +1419,85 @@ function useHumanAgentSessions(options) {
|
|
|
1338
1419
|
);
|
|
1339
1420
|
}
|
|
1340
1421
|
|
|
1422
|
+
// hooks/use-memory.ts
|
|
1423
|
+
var import_react6 = require("react");
|
|
1424
|
+
function useMemory(options, initialProfile = null) {
|
|
1425
|
+
const [profile, setProfile] = (0, import_react6.useState)(initialProfile);
|
|
1426
|
+
const [loading, setLoading] = (0, import_react6.useState)(false);
|
|
1427
|
+
const requestCountRef = (0, import_react6.useRef)(0);
|
|
1428
|
+
const runProfileMutation = (0, import_react6.useCallback)(
|
|
1429
|
+
async (fn) => {
|
|
1430
|
+
requestCountRef.current += 1;
|
|
1431
|
+
setLoading(true);
|
|
1432
|
+
try {
|
|
1433
|
+
const response = await fn();
|
|
1434
|
+
if (!response.error && response.data) {
|
|
1435
|
+
setProfile(response.data);
|
|
1436
|
+
return response.data;
|
|
1437
|
+
}
|
|
1438
|
+
return null;
|
|
1439
|
+
} catch {
|
|
1440
|
+
return null;
|
|
1441
|
+
} finally {
|
|
1442
|
+
requestCountRef.current -= 1;
|
|
1443
|
+
if (requestCountRef.current === 0) {
|
|
1444
|
+
setLoading(false);
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1447
|
+
},
|
|
1448
|
+
[]
|
|
1449
|
+
);
|
|
1450
|
+
const optionsRef = (0, import_react6.useRef)(options);
|
|
1451
|
+
optionsRef.current = options;
|
|
1452
|
+
const patchProfile = (0, import_react6.useCallback)(
|
|
1453
|
+
(patch) => runProfileMutation(() => patchProfileApi(patch, optionsRef.current)),
|
|
1454
|
+
[runProfileMutation]
|
|
1455
|
+
);
|
|
1456
|
+
const replaceProfile = (0, import_react6.useCallback)(
|
|
1457
|
+
(p) => runProfileMutation(() => replaceProfileApi(p, optionsRef.current)),
|
|
1458
|
+
[runProfileMutation]
|
|
1459
|
+
);
|
|
1460
|
+
const clearProfile = (0, import_react6.useCallback)(
|
|
1461
|
+
() => runProfileMutation(() => clearProfileApi(optionsRef.current)),
|
|
1462
|
+
[runProfileMutation]
|
|
1463
|
+
);
|
|
1464
|
+
const deleteContact = (0, import_react6.useCallback)(
|
|
1465
|
+
(name) => runProfileMutation(() => deleteContactApi(name, optionsRef.current)),
|
|
1466
|
+
[runProfileMutation]
|
|
1467
|
+
);
|
|
1468
|
+
const deleteNote = (0, import_react6.useCallback)(
|
|
1469
|
+
(index) => runProfileMutation(() => deleteNoteApi(index, optionsRef.current)),
|
|
1470
|
+
[runProfileMutation]
|
|
1471
|
+
);
|
|
1472
|
+
const clearSummary = (0, import_react6.useCallback)(
|
|
1473
|
+
async (chatKey) => {
|
|
1474
|
+
await clearSummaryApi(chatKey, optionsRef.current);
|
|
1475
|
+
},
|
|
1476
|
+
[]
|
|
1477
|
+
);
|
|
1478
|
+
const regenerateSummary = (0, import_react6.useCallback)(
|
|
1479
|
+
async (chatKey) => {
|
|
1480
|
+
const response = await regenerateSummaryApi(chatKey, optionsRef.current);
|
|
1481
|
+
if (!response.error && response.data) {
|
|
1482
|
+
return response.data;
|
|
1483
|
+
}
|
|
1484
|
+
return null;
|
|
1485
|
+
},
|
|
1486
|
+
[]
|
|
1487
|
+
);
|
|
1488
|
+
return {
|
|
1489
|
+
profile,
|
|
1490
|
+
loading,
|
|
1491
|
+
patchProfile,
|
|
1492
|
+
replaceProfile,
|
|
1493
|
+
clearProfile,
|
|
1494
|
+
deleteContact,
|
|
1495
|
+
deleteNote,
|
|
1496
|
+
clearSummary,
|
|
1497
|
+
regenerateSummary
|
|
1498
|
+
};
|
|
1499
|
+
}
|
|
1500
|
+
|
|
1341
1501
|
// hooks/index.ts
|
|
1342
1502
|
var import_hooks4 = require("@elqnt/api-client/hooks");
|
|
1343
1503
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1347,6 +1507,7 @@ var import_hooks4 = require("@elqnt/api-client/hooks");
|
|
|
1347
1507
|
useChatHistory,
|
|
1348
1508
|
useChatMonitoring,
|
|
1349
1509
|
useHumanAgentSessions,
|
|
1510
|
+
useMemory,
|
|
1350
1511
|
useOptionsRef
|
|
1351
1512
|
});
|
|
1352
1513
|
//# sourceMappingURL=index.js.map
|