@onlive.ai/common-121 0.2.66 → 0.2.163
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/README.md +0 -1
- package/components/asset/asset-modal-portal.cjs +550 -0
- package/components/asset/asset-modal-portal.d.cts +22 -0
- package/components/asset/asset-modal-portal.d.ts +22 -0
- package/components/asset/asset-modal-portal.js +550 -0
- package/components/asset/asset.cjs +3536 -0
- package/components/asset/asset.d.cts +37 -0
- package/components/asset/asset.d.ts +37 -0
- package/components/asset/asset.js +3536 -0
- package/components/asset/asset.loaders.cjs +2 -0
- package/components/asset/asset.loaders.d.cts +17 -0
- package/components/asset/asset.loaders.d.ts +17 -0
- package/components/asset/asset.loaders.js +2 -0
- package/components/asset/asset.renderer.cjs +2292 -0
- package/components/asset/asset.renderer.d.cts +29 -0
- package/components/asset/asset.renderer.d.ts +29 -0
- package/components/asset/asset.renderer.js +2292 -0
- package/components/asset/asset.styles.cjs +683 -0
- package/components/asset/asset.styles.d.cts +6 -0
- package/components/asset/asset.styles.d.ts +6 -0
- package/components/asset/asset.styles.js +683 -0
- package/components/asset/asset.types.cjs +2 -0
- package/components/asset/asset.types.d.cts +103 -0
- package/components/asset/asset.types.d.ts +103 -0
- package/components/asset/asset.types.js +1 -0
- package/components/asset/index.cjs +3536 -0
- package/components/asset/index.d.cts +8 -0
- package/components/asset/index.d.ts +8 -0
- package/components/asset/index.js +3536 -0
- package/components/player/player.cjs +2044 -0
- package/components/player/player.d.cts +25 -0
- package/components/player/player.d.ts +25 -0
- package/components/player/player.js +2044 -0
- package/components/player/player.styles.cjs +16 -0
- package/components/player/player.styles.d.cts +6 -0
- package/components/player/player.styles.d.ts +6 -0
- package/components/player/player.styles.js +16 -0
- package/components/side-bar/index.cjs +3185 -0
- package/components/side-bar/index.d.cts +11 -0
- package/components/side-bar/index.d.ts +11 -0
- package/components/side-bar/index.js +3185 -0
- package/components/side-bar/side-bar.cjs +3185 -0
- package/components/side-bar/side-bar.d.cts +83 -0
- package/components/side-bar/side-bar.d.ts +83 -0
- package/components/side-bar/side-bar.js +3185 -0
- package/components/side-bar/side-bar.styles.cjs +801 -0
- package/components/side-bar/side-bar.styles.d.cts +6 -0
- package/components/side-bar/side-bar.styles.d.ts +6 -0
- package/components/side-bar/side-bar.styles.js +801 -0
- package/components/side-bar/side-bar.types.cjs +2 -0
- package/components/side-bar/side-bar.types.d.cts +105 -0
- package/components/side-bar/side-bar.types.d.ts +105 -0
- package/components/side-bar/side-bar.types.js +2 -0
- package/components/upload/index.cjs +83 -0
- package/components/upload/index.d.cts +4 -0
- package/components/upload/index.d.ts +4 -0
- package/components/upload/index.js +83 -0
- package/components/upload/upload.cjs +83 -0
- package/components/upload/upload.d.cts +28 -0
- package/components/upload/upload.d.ts +28 -0
- package/components/upload/upload.js +83 -0
- package/components/upload/upload.styles.cjs +65 -0
- package/components/upload/upload.styles.d.cts +6 -0
- package/components/upload/upload.styles.d.ts +6 -0
- package/components/upload/upload.styles.js +65 -0
- package/components/upload/upload.types.cjs +2 -0
- package/components/upload/upload.types.d.cts +16 -0
- package/components/upload/upload.types.d.ts +16 -0
- package/components/upload/upload.types.js +1 -0
- package/index.cjs +4677 -0
- package/index.d.cts +338 -0
- package/index.d.ts +338 -0
- package/index.js +4677 -0
- package/package.json +32 -11
- package/react/components/asset/Asset.cjs +2 -0
- package/react/components/asset/Asset.d.cts +33 -0
- package/react/components/asset/Asset.d.ts +33 -0
- package/react/components/asset/Asset.jsx +2 -0
- package/react/components/side-bar/SideBar.cjs +2 -0
- package/react/components/side-bar/SideBar.d.cts +37 -0
- package/react/components/side-bar/SideBar.d.ts +37 -0
- package/react/components/side-bar/SideBar.jsx +2 -0
- package/react/components/upload/Upload.cjs +2 -0
- package/react/components/upload/Upload.d.cts +23 -0
- package/react/components/upload/Upload.d.ts +23 -0
- package/react/components/upload/Upload.jsx +2 -0
- package/services/audio.service.cjs +2 -2
- package/services/audio.service.d.cts +1 -0
- package/services/audio.service.d.ts +1 -0
- package/services/audio.service.js +2 -2
- package/services/conversation/conversation.service.cjs +2 -0
- package/services/conversation/conversation.service.d.cts +533 -0
- package/services/conversation/conversation.service.d.ts +533 -0
- package/services/conversation/conversation.service.js +2 -0
- package/services/conversation/conversation.types.cjs +2 -0
- package/services/conversation/conversation.types.d.cts +519 -0
- package/services/conversation/conversation.types.d.ts +519 -0
- package/services/conversation/conversation.types.js +2 -0
- package/services/conversation/index.cjs +2 -0
- package/services/conversation/index.d.cts +7 -0
- package/services/conversation/index.d.ts +7 -0
- package/services/conversation/index.js +2 -0
- package/services/faqs/faqs.service.cjs +2 -0
- package/services/faqs/faqs.service.d.cts +16 -0
- package/services/faqs/faqs.service.d.ts +16 -0
- package/services/faqs/faqs.service.js +2 -0
- package/services/faqs/faqs.types.cjs +2 -0
- package/services/faqs/faqs.types.d.cts +60 -0
- package/services/faqs/faqs.types.d.ts +60 -0
- package/services/faqs/faqs.types.js +1 -0
- package/services/faqs/index.cjs +2 -0
- package/services/faqs/index.d.cts +3 -0
- package/services/faqs/index.d.ts +3 -0
- package/services/faqs/index.js +2 -0
- package/services/file/file.service.cjs +2 -0
- package/services/file/file.service.d.cts +66 -0
- package/services/file/file.service.d.ts +66 -0
- package/services/file/file.service.js +2 -0
- package/services/file/file.types.cjs +2 -0
- package/services/file/file.types.d.cts +72 -0
- package/services/file/file.types.d.ts +72 -0
- package/services/file/file.types.js +1 -0
- package/services/file/index.cjs +2 -0
- package/services/file/index.d.cts +3 -0
- package/services/file/index.d.ts +3 -0
- package/services/file/index.js +2 -0
- package/services/firebase/firebase-api.cjs +2 -2
- package/services/firebase/firebase-api.d.cts +25 -9
- package/services/firebase/firebase-api.d.ts +25 -9
- package/services/firebase/firebase-api.js +2 -2
- package/services/multimedia/config.example.cjs +2 -0
- package/services/multimedia/config.example.d.cts +13 -0
- package/services/multimedia/config.example.d.ts +13 -0
- package/services/multimedia/config.example.js +2 -0
- package/services/multimedia/index.cjs +2 -0
- package/services/multimedia/index.d.cts +3 -0
- package/services/multimedia/index.d.ts +3 -0
- package/services/multimedia/index.js +2 -0
- package/services/multimedia/multimedia.service.cjs +2 -0
- package/services/multimedia/multimedia.service.d.cts +28 -0
- package/services/multimedia/multimedia.service.d.ts +28 -0
- package/services/multimedia/multimedia.service.js +2 -0
- package/services/multimedia/multimedia.types.cjs +2 -0
- package/services/multimedia/multimedia.types.d.cts +65 -0
- package/services/multimedia/multimedia.types.d.ts +65 -0
- package/services/multimedia/multimedia.types.js +1 -0
- package/services/product/index.cjs +2 -0
- package/services/product/index.d.cts +3 -0
- package/services/product/index.d.ts +3 -0
- package/services/product/index.js +2 -0
- package/services/product/product.service.cjs +2 -0
- package/services/product/product.service.d.cts +19 -0
- package/services/product/product.service.d.ts +19 -0
- package/services/product/product.service.js +2 -0
- package/services/product/product.types.cjs +2 -0
- package/services/product/product.types.d.cts +78 -0
- package/services/product/product.types.d.ts +78 -0
- package/services/product/product.types.js +1 -0
- package/services/request.provider.cjs +1 -1
- package/services/request.provider.d.cts +1 -0
- package/services/request.provider.d.ts +1 -0
- package/services/request.provider.js +1 -1
- package/services/session.service.cjs +2 -0
- package/services/session.service.d.cts +70 -0
- package/services/session.service.d.ts +70 -0
- package/services/session.service.js +2 -0
- package/services/upload/index.cjs +2 -0
- package/services/upload/index.d.cts +2 -0
- package/services/upload/index.d.ts +2 -0
- package/services/upload/index.js +2 -0
- package/services/upload/upload.service.cjs +2 -0
- package/services/upload/upload.service.d.cts +81 -0
- package/services/upload/upload.service.d.ts +81 -0
- package/services/upload/upload.service.js +2 -0
- package/themes/dark.cjs +4 -1
- package/themes/dark.d.cts +1 -0
- package/themes/dark.d.ts +1 -0
- package/themes/dark.js +4 -1
- package/themes/light.cjs +1 -1
- package/themes/light.d.cts +1 -0
- package/themes/light.d.ts +1 -0
- package/themes/light.js +1 -1
- package/types/globals.cjs +2 -0
- package/types/globals.d.cts +39 -0
- package/types/globals.d.ts +39 -0
- package/types/globals.js +1 -0
- package/types/tracking-options.cjs +2 -2
- package/types/tracking-options.d.cts +8 -6
- package/types/tracking-options.d.ts +8 -6
- package/types/tracking-options.js +1 -1
- package/utils/adopt-styles.cjs +2 -2
- package/utils/adopt-styles.d.cts +1 -0
- package/utils/adopt-styles.d.ts +1 -0
- package/utils/adopt-styles.js +2 -2
- package/utils/browser-preferences.cjs +2 -2
- package/utils/browser-preferences.d.cts +1 -0
- package/utils/browser-preferences.d.ts +1 -0
- package/utils/browser-preferences.js +2 -2
- package/utils/classify-media.cjs +1 -1
- package/utils/classify-media.d.cts +1 -0
- package/utils/classify-media.d.ts +1 -0
- package/utils/classify-media.js +1 -1
- package/utils/decorators.cjs +1 -1
- package/utils/decorators.d.cts +1 -0
- package/utils/decorators.d.ts +1 -0
- package/utils/decorators.js +1 -1
- package/utils/detected-lang.cjs +2 -2
- package/utils/detected-lang.d.cts +1 -0
- package/utils/detected-lang.d.ts +1 -0
- package/utils/detected-lang.js +2 -2
- package/utils/fullscreen.cjs +2 -2
- package/utils/fullscreen.d.cts +6 -5
- package/utils/fullscreen.d.ts +6 -5
- package/utils/fullscreen.js +2 -2
- package/utils/insert-script.cjs +1 -1
- package/utils/insert-script.d.cts +1 -0
- package/utils/insert-script.d.ts +1 -0
- package/utils/insert-script.js +1 -1
- package/utils/is-map-compatible.cjs +1 -1
- package/utils/is-map-compatible.d.cts +1 -0
- package/utils/is-map-compatible.d.ts +1 -0
- package/utils/is-map-compatible.js +1 -1
- package/utils/markdown.cjs +2 -2
- package/utils/markdown.d.cts +1 -0
- package/utils/markdown.d.ts +1 -0
- package/utils/markdown.js +2 -2
- package/utils/merge.cjs +2 -2
- package/utils/merge.d.cts +2 -1
- package/utils/merge.d.ts +2 -1
- package/utils/merge.js +2 -2
- package/utils/multiband-track-volume.cjs +2 -2
- package/utils/multiband-track-volume.d.cts +1 -0
- package/utils/multiband-track-volume.d.ts +1 -0
- package/utils/multiband-track-volume.js +2 -2
- package/utils/onlive-url-params.cjs +1 -1
- package/utils/onlive-url-params.d.cts +1 -0
- package/utils/onlive-url-params.d.ts +1 -0
- package/utils/onlive-url-params.js +1 -1
- package/utils/pretty-distance.cjs +2 -2
- package/utils/pretty-distance.d.cts +2 -1
- package/utils/pretty-distance.d.ts +2 -1
- package/utils/pretty-distance.js +2 -2
- package/utils/pretty-time.cjs +2 -0
- package/utils/pretty-time.d.cts +16 -0
- package/utils/pretty-time.d.ts +16 -0
- package/utils/pretty-time.js +2 -0
- package/utils/random-string.cjs +1 -1
- package/utils/random-string.d.cts +1 -0
- package/utils/random-string.d.ts +1 -0
- package/utils/random-string.js +1 -1
- package/utils/resource-type.cjs +1 -1
- package/utils/resource-type.d.cts +1 -0
- package/utils/resource-type.d.ts +1 -0
- package/utils/resource-type.js +1 -1
- package/utils/round-number.cjs +2 -0
- package/utils/round-number.d.cts +30 -0
- package/utils/round-number.d.ts +30 -0
- package/utils/round-number.js +2 -0
- package/utils/safe-html.cjs +2 -2
- package/utils/safe-html.d.cts +4 -3
- package/utils/safe-html.d.ts +4 -3
- package/utils/safe-html.js +2 -2
- package/utils/sanitize.cjs +2 -2
- package/utils/sanitize.d.cts +1 -0
- package/utils/sanitize.d.ts +1 -0
- package/utils/sanitize.js +2 -2
- package/utils/spread.cjs +2 -2
- package/utils/spread.d.cts +1 -0
- package/utils/spread.d.ts +1 -0
- package/utils/spread.js +2 -2
- package/utils/watch.cjs +1 -1
- package/utils/watch.d.cts +1 -0
- package/utils/watch.d.ts +1 -0
- package/utils/watch.js +1 -1
- package/services/firebase/firebase.service.cjs +0 -2
- package/services/firebase/firebase.service.d.cts +0 -40
- package/services/firebase/firebase.service.d.ts +0 -40
- package/services/firebase/firebase.service.js +0 -2
- package/services/livekit.service.cjs +0 -2
- package/services/livekit.service.d.cts +0 -217
- package/services/livekit.service.d.ts +0 -217
- package/services/livekit.service.js +0 -2
- package/types/window-context.cjs +0 -2
- package/types/window-context.d.cts +0 -8
- package/types/window-context.d.ts +0 -8
- package/types/window-context.js +0 -1
|
@@ -0,0 +1,533 @@
|
|
|
1
|
+
/*! @onlive.ai/common-121 v0.2.163 | © 2026 Onlive.ai */
|
|
2
|
+
import { Room as Room$1 } from 'livekit-client';
|
|
3
|
+
import { ConversationServiceOptions, UserApiResponse, AgentData, CreateRoomOptions, EvaluateRoomOptions, GetRoomsOptions, RoomsApiResponse, PersistMessageOptions, MessagesApiResponse, GetMessagesOptions, ApiMessage, MessageReportOptions, MessageReactionOptions, MessageListener, TypingListener, ContextualEvent, RequestNewRoomOptions, RoomApiResponse, CallRequest, CallRequestListener, RoomSyncData, NewRoomRequestData } from './conversation.types.js';
|
|
4
|
+
import '@livekit/components-core';
|
|
5
|
+
import '../firebase/firebase-api.js';
|
|
6
|
+
import 'firebase/database';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Extended Room class with persistent metadata.
|
|
10
|
+
*
|
|
11
|
+
* @description Extends LiveKit Room with additional properties for
|
|
12
|
+
* tracking room lifecycle and metadata.
|
|
13
|
+
*/
|
|
14
|
+
declare class Room extends Room$1 {
|
|
15
|
+
/** Unique room identifier */
|
|
16
|
+
id: string;
|
|
17
|
+
/** Group identifier for room categorization */
|
|
18
|
+
groupId: string;
|
|
19
|
+
/** ISO timestamp of room creation */
|
|
20
|
+
createdAt: string;
|
|
21
|
+
/** ISO timestamp when user connected */
|
|
22
|
+
connectedAt: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* @summary Unified service for conversation management.
|
|
26
|
+
*
|
|
27
|
+
* @description A comprehensive service that combines real-time communication (LiveKit)
|
|
28
|
+
* with presence and request management (Firebase) for handling conversations.
|
|
29
|
+
* This service manages room lifecycle, messaging, typing indicators, call requests,
|
|
30
|
+
* and agent presence in a unified API.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* const service = new ConversationService({
|
|
35
|
+
* organizationId: 'org-123',
|
|
36
|
+
* apiUrl: 'https://api.example.com',
|
|
37
|
+
* firebaseConfig: { ... }
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* // Register user and create room
|
|
41
|
+
* await service.registerUser('user-123', 'secret');
|
|
42
|
+
* const room = await service.createRoom({
|
|
43
|
+
* language: 'en',
|
|
44
|
+
* timezone: 'America/New_York'
|
|
45
|
+
* });
|
|
46
|
+
*
|
|
47
|
+
* // Subscribe to messages
|
|
48
|
+
* service.subscribeMessages((messages) => {
|
|
49
|
+
* console.log('New messages:', messages);
|
|
50
|
+
* });
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
declare class ConversationService {
|
|
54
|
+
/** Message event listeners */
|
|
55
|
+
private listeners;
|
|
56
|
+
/** Typing indicator listeners */
|
|
57
|
+
private typingListeners;
|
|
58
|
+
/** Map for deduplicating transcription segments */
|
|
59
|
+
private transcriptionMap;
|
|
60
|
+
/** Base API URL */
|
|
61
|
+
private apiUrl;
|
|
62
|
+
/** Authentication service URL */
|
|
63
|
+
private authUrl?;
|
|
64
|
+
/** Organization identifier */
|
|
65
|
+
private organizationId;
|
|
66
|
+
/** LiveKit chat topic */
|
|
67
|
+
private channelTopic;
|
|
68
|
+
/** LiveKit transcription topic */
|
|
69
|
+
private transcriptionTopic;
|
|
70
|
+
/** LiveKit events topic */
|
|
71
|
+
private eventsTopic;
|
|
72
|
+
/** Message persistence mode */
|
|
73
|
+
private messagePersistence;
|
|
74
|
+
/** Abort controllers for cancellable requests */
|
|
75
|
+
private abortControllers;
|
|
76
|
+
/** Current authentication token */
|
|
77
|
+
private authToken;
|
|
78
|
+
/** Firebase API instance (optional) */
|
|
79
|
+
private firebaseApi?;
|
|
80
|
+
/** Firebase presence path */
|
|
81
|
+
private presencePath?;
|
|
82
|
+
/** Firebase calls path */
|
|
83
|
+
private callsPath?;
|
|
84
|
+
/** Active Firebase unsubscribers */
|
|
85
|
+
private firebaseUnsubscribers;
|
|
86
|
+
/** Set of seen request IDs for deduplication */
|
|
87
|
+
private seenRequestIds;
|
|
88
|
+
/** Map for content-based deduplication */
|
|
89
|
+
private lastSnapshotById;
|
|
90
|
+
/** Current LiveKit room instance */
|
|
91
|
+
room: Room;
|
|
92
|
+
/**
|
|
93
|
+
* Initializes a new instance of the ConversationService.
|
|
94
|
+
*
|
|
95
|
+
* @param {ConversationServiceOptions} options - Service configuration options.
|
|
96
|
+
*/
|
|
97
|
+
constructor(options: ConversationServiceOptions);
|
|
98
|
+
/**
|
|
99
|
+
* Creates a new LiveKit Room instance with default settings.
|
|
100
|
+
*
|
|
101
|
+
* @private
|
|
102
|
+
* @returns {Room} New Room instance.
|
|
103
|
+
*/
|
|
104
|
+
private createRoomInstance;
|
|
105
|
+
/**
|
|
106
|
+
* Ensures a room instance exists, creating one if necessary.
|
|
107
|
+
*
|
|
108
|
+
* @returns {Room} Current or new Room instance.
|
|
109
|
+
*/
|
|
110
|
+
ensureRoom(): Room;
|
|
111
|
+
/**
|
|
112
|
+
* Initializes Firebase services for presence and request management.
|
|
113
|
+
*
|
|
114
|
+
* @private
|
|
115
|
+
* @param {FirebaseConfig} config - Firebase configuration.
|
|
116
|
+
*/
|
|
117
|
+
private initializeFirebase;
|
|
118
|
+
/**
|
|
119
|
+
* Sets up LiveKit room event handlers for messaging and typing.
|
|
120
|
+
*
|
|
121
|
+
* @private
|
|
122
|
+
*/
|
|
123
|
+
private initializeRoomHandlers;
|
|
124
|
+
/**
|
|
125
|
+
* Registers a user for conversation access.
|
|
126
|
+
*
|
|
127
|
+
* @async
|
|
128
|
+
* @param {string} externalId - External user identifier.
|
|
129
|
+
* @param {string} secret - User authentication secret.
|
|
130
|
+
* @param {Record<string, unknown>} [userData] - Additional user data.
|
|
131
|
+
* @param {Record<string, unknown>} [metadata] - User metadata.
|
|
132
|
+
* @returns {Promise<UserApiResponse>} User registration response with token.
|
|
133
|
+
*/
|
|
134
|
+
registerUser(externalId: string, secret: string, userData?: Record<string, unknown>, metadata?: Record<string, unknown>): Promise<UserApiResponse>;
|
|
135
|
+
/**
|
|
136
|
+
* Registers an agent for handling conversations.
|
|
137
|
+
*
|
|
138
|
+
* @async
|
|
139
|
+
* @param {string} externalId - External agent identifier.
|
|
140
|
+
* @param {AgentData} agentData - Agent profile data.
|
|
141
|
+
* @returns {Promise<string>} Authentication token.
|
|
142
|
+
*/
|
|
143
|
+
registerAgent(externalId: string, agentData: AgentData): Promise<string>;
|
|
144
|
+
/**
|
|
145
|
+
* Decodes a JWT token payload without verification.
|
|
146
|
+
*
|
|
147
|
+
* @private
|
|
148
|
+
* @param {string} token - JWT token string.
|
|
149
|
+
* @returns {{ username?: string; sub?: string; iat?: number; exp?: number } | null} Decoded payload or null if invalid.
|
|
150
|
+
*/
|
|
151
|
+
private decodeJwtPayload;
|
|
152
|
+
/**
|
|
153
|
+
* Creates a new conversation room.
|
|
154
|
+
*
|
|
155
|
+
* @async
|
|
156
|
+
* @param {CreateRoomOptions} options - Room creation options.
|
|
157
|
+
* @param {Record<string, string>} [userData] - User attributes to set.
|
|
158
|
+
* @returns {Promise<Room>} Connected room instance.
|
|
159
|
+
*/
|
|
160
|
+
createRoom(options: CreateRoomOptions, userData?: Record<string, string>): Promise<Room>;
|
|
161
|
+
/**
|
|
162
|
+
* Joins an existing conversation room.
|
|
163
|
+
*
|
|
164
|
+
* @async
|
|
165
|
+
* @param {string} roomId - Room identifier to join.
|
|
166
|
+
* @param {string} timezone - User's timezone.
|
|
167
|
+
* @param {string} language - Preferred language.
|
|
168
|
+
* @param {Record<string, unknown>} [attributes] - Additional attributes.
|
|
169
|
+
* @returns {Promise<Room>} Connected room instance.
|
|
170
|
+
*/
|
|
171
|
+
joinRoom(roomId: string, timezone: string, language: string, attributes?: Record<string, unknown>): Promise<Room>;
|
|
172
|
+
/**
|
|
173
|
+
* Sets room metadata from API response.
|
|
174
|
+
*
|
|
175
|
+
* @private
|
|
176
|
+
* @param {RoomApiResponse} response - Room API response.
|
|
177
|
+
*/
|
|
178
|
+
private setRoomMetadata;
|
|
179
|
+
/**
|
|
180
|
+
* Sets up handler for participant attribute changes.
|
|
181
|
+
*
|
|
182
|
+
* @private
|
|
183
|
+
*/
|
|
184
|
+
private setupParticipantAttributesHandler;
|
|
185
|
+
/**
|
|
186
|
+
* Evaluates/rates the current room.
|
|
187
|
+
*
|
|
188
|
+
* @async
|
|
189
|
+
* @param {EvaluateRoomOptions} options - Evaluation options.
|
|
190
|
+
* @returns {Promise<void>}
|
|
191
|
+
*/
|
|
192
|
+
evaluateRoom(options: EvaluateRoomOptions): Promise<void>;
|
|
193
|
+
/**
|
|
194
|
+
* Closes the current room on the server.
|
|
195
|
+
*
|
|
196
|
+
* @async
|
|
197
|
+
* @returns {Promise<void>}
|
|
198
|
+
*/
|
|
199
|
+
closeRoom(): Promise<void>;
|
|
200
|
+
/**
|
|
201
|
+
* Disconnects from the current room.
|
|
202
|
+
*
|
|
203
|
+
* @async
|
|
204
|
+
* @returns {Promise<void>}
|
|
205
|
+
*/
|
|
206
|
+
disconnect(): Promise<void>;
|
|
207
|
+
/**
|
|
208
|
+
* Closes the room on server and disconnects locally.
|
|
209
|
+
*
|
|
210
|
+
* @async
|
|
211
|
+
* @returns {Promise<void>}
|
|
212
|
+
*/
|
|
213
|
+
disconnectAndCloseRoom(): Promise<void>;
|
|
214
|
+
/**
|
|
215
|
+
* Marks a room as read.
|
|
216
|
+
*
|
|
217
|
+
* @async
|
|
218
|
+
* @param {string} roomId - Room identifier.
|
|
219
|
+
* @returns {Promise<void>}
|
|
220
|
+
*/
|
|
221
|
+
readRoom(roomId: string): Promise<void>;
|
|
222
|
+
/**
|
|
223
|
+
* Fetches a list of rooms based on options.
|
|
224
|
+
*
|
|
225
|
+
* @async
|
|
226
|
+
* @param {GetRoomsOptions} options - Room listing options.
|
|
227
|
+
* @returns {Promise<RoomsApiResponse>} Paginated room list.
|
|
228
|
+
*/
|
|
229
|
+
getRooms(options: GetRoomsOptions): Promise<RoomsApiResponse>;
|
|
230
|
+
/**
|
|
231
|
+
* Handles incoming messages from LiveKit.
|
|
232
|
+
*
|
|
233
|
+
* @private
|
|
234
|
+
*/
|
|
235
|
+
private handleIncomingMessage;
|
|
236
|
+
/**
|
|
237
|
+
* Emits a message to all subscribed listeners.
|
|
238
|
+
*
|
|
239
|
+
* @private
|
|
240
|
+
* @param {ApiMessage} message - Message to emit.
|
|
241
|
+
*/
|
|
242
|
+
private emitMessage;
|
|
243
|
+
/**
|
|
244
|
+
* Sends a message in the current room.
|
|
245
|
+
*
|
|
246
|
+
* @async
|
|
247
|
+
* @param {string} message - Message content.
|
|
248
|
+
* @param {Record<string, string>} [attributes] - Message attributes.
|
|
249
|
+
* @returns {Promise<void>}
|
|
250
|
+
*/
|
|
251
|
+
sendMessage(message: string, attributes?: Record<string, string>): Promise<void>;
|
|
252
|
+
/**
|
|
253
|
+
* Persists a message to the server.
|
|
254
|
+
*
|
|
255
|
+
* @async
|
|
256
|
+
* @param {PersistMessageOptions} options - Persistence options.
|
|
257
|
+
* @returns {Promise<MessagesApiResponse>}
|
|
258
|
+
*/
|
|
259
|
+
persistMessage(options: PersistMessageOptions): Promise<MessagesApiResponse>;
|
|
260
|
+
/**
|
|
261
|
+
* Fetches messages based on options.
|
|
262
|
+
*
|
|
263
|
+
* @async
|
|
264
|
+
* @param {GetMessagesOptions} options - Message fetching options.
|
|
265
|
+
* @returns {Promise<ApiMessage[]>} Array of messages.
|
|
266
|
+
*/
|
|
267
|
+
getMessages(options: GetMessagesOptions): Promise<ApiMessage[]>;
|
|
268
|
+
/**
|
|
269
|
+
* Reports a message for moderation.
|
|
270
|
+
*
|
|
271
|
+
* @async
|
|
272
|
+
* @param {MessageReportOptions} options - Report options.
|
|
273
|
+
* @returns {Promise<void>}
|
|
274
|
+
*/
|
|
275
|
+
sendMessageReport(options: MessageReportOptions): Promise<void>;
|
|
276
|
+
/**
|
|
277
|
+
* Deletes a message report.
|
|
278
|
+
*
|
|
279
|
+
* @async
|
|
280
|
+
* @param {MessageReportOptions} options - Report options.
|
|
281
|
+
* @returns {Promise<void>}
|
|
282
|
+
*/
|
|
283
|
+
deleteMessageReport(options: MessageReportOptions): Promise<void>;
|
|
284
|
+
/**
|
|
285
|
+
* Updates reactions on a message.
|
|
286
|
+
*
|
|
287
|
+
* @async
|
|
288
|
+
* @param {MessageReactionOptions} options - Reaction options.
|
|
289
|
+
* @returns {Promise<void>}
|
|
290
|
+
*/
|
|
291
|
+
updateMessageReactions(options: MessageReactionOptions): Promise<void>;
|
|
292
|
+
/**
|
|
293
|
+
* Subscribes to incoming messages.
|
|
294
|
+
*
|
|
295
|
+
* @param {MessageListener<M>} callback - Message listener callback.
|
|
296
|
+
* @returns {() => void} Unsubscribe function.
|
|
297
|
+
*/
|
|
298
|
+
subscribeMessages<M extends ApiMessage = ApiMessage>(callback: MessageListener<M>): () => void;
|
|
299
|
+
/**
|
|
300
|
+
* Handles data received events for typing indicators.
|
|
301
|
+
*
|
|
302
|
+
* @private
|
|
303
|
+
*/
|
|
304
|
+
private handleDataReceived;
|
|
305
|
+
/**
|
|
306
|
+
* Emits a typing indicator to all listeners.
|
|
307
|
+
*
|
|
308
|
+
* @private
|
|
309
|
+
* @param {TypingIndicator} indicator - Typing indicator data.
|
|
310
|
+
*/
|
|
311
|
+
private emitTypingIndicator;
|
|
312
|
+
/**
|
|
313
|
+
* Sends a typing indicator to other participants.
|
|
314
|
+
*
|
|
315
|
+
* @async
|
|
316
|
+
* @param {boolean} isTyping - Whether the user is currently typing.
|
|
317
|
+
* @returns {Promise<void>}
|
|
318
|
+
*/
|
|
319
|
+
sendTypingIndicator(isTyping: boolean): Promise<void>;
|
|
320
|
+
/**
|
|
321
|
+
* Subscribes to typing indicators from other participants.
|
|
322
|
+
*
|
|
323
|
+
* @param {TypingListener} listener - Typing indicator listener.
|
|
324
|
+
* @returns {() => void} Unsubscribe function.
|
|
325
|
+
*/
|
|
326
|
+
subscribeTypingIndicators(listener: TypingListener): () => void;
|
|
327
|
+
/**
|
|
328
|
+
* Unsubscribes a typing indicator listener.
|
|
329
|
+
*
|
|
330
|
+
* @param {TypingListener} listener - Listener to remove.
|
|
331
|
+
*/
|
|
332
|
+
unsubscribeTypingIndicators(listener: TypingListener): void;
|
|
333
|
+
/**
|
|
334
|
+
* Sends a contextual event to the room.
|
|
335
|
+
*
|
|
336
|
+
* @async
|
|
337
|
+
* @param {ContextualEvent} event - Event to send.
|
|
338
|
+
* @returns {Promise<void>}
|
|
339
|
+
*/
|
|
340
|
+
sendContextualEvent(event: ContextualEvent): Promise<void>;
|
|
341
|
+
/**
|
|
342
|
+
* Requests a new room (call transfer).
|
|
343
|
+
*
|
|
344
|
+
* @async
|
|
345
|
+
* @param {RequestNewRoomOptions} options - Request options.
|
|
346
|
+
* @returns {Promise<RoomApiResponse>} New room details.
|
|
347
|
+
*/
|
|
348
|
+
requestNewRoom(options: RequestNewRoomOptions): Promise<RoomApiResponse>;
|
|
349
|
+
/**
|
|
350
|
+
* Confirms an active room request.
|
|
351
|
+
*
|
|
352
|
+
* @async
|
|
353
|
+
* @param {string} roomId - Room identifier.
|
|
354
|
+
* @returns {Promise<{ success: boolean; message: string; roomId: string }>}
|
|
355
|
+
*/
|
|
356
|
+
confirmRoomRequest(roomId: string): Promise<{
|
|
357
|
+
success: boolean;
|
|
358
|
+
message: string;
|
|
359
|
+
roomId: string;
|
|
360
|
+
}>;
|
|
361
|
+
/**
|
|
362
|
+
* Cancels an active room request.
|
|
363
|
+
*
|
|
364
|
+
* @async
|
|
365
|
+
* @param {string} roomId - Room identifier.
|
|
366
|
+
* @returns {Promise<{ success: boolean; message: string; roomId: string }>}
|
|
367
|
+
*/
|
|
368
|
+
cancelRoomRequest(roomId: string): Promise<{
|
|
369
|
+
success: boolean;
|
|
370
|
+
message: string;
|
|
371
|
+
roomId: string;
|
|
372
|
+
}>;
|
|
373
|
+
/**
|
|
374
|
+
* Finishes an active call.
|
|
375
|
+
*
|
|
376
|
+
* @async
|
|
377
|
+
* @returns {Promise<void>}
|
|
378
|
+
*/
|
|
379
|
+
finishCall(): Promise<void>;
|
|
380
|
+
/**
|
|
381
|
+
* Checks if Firebase is initialized.
|
|
382
|
+
*
|
|
383
|
+
* @returns {boolean} True if Firebase features are available.
|
|
384
|
+
*/
|
|
385
|
+
isFirebaseEnabled(): boolean;
|
|
386
|
+
/**
|
|
387
|
+
* Gets Firebase API and paths, throwing if not initialized.
|
|
388
|
+
*
|
|
389
|
+
* @private
|
|
390
|
+
* @throws {Error} If Firebase is not initialized.
|
|
391
|
+
* @returns {{ api: FirebaseApi; presencePath: string; callsPath: string }}
|
|
392
|
+
*/
|
|
393
|
+
private getFirebase;
|
|
394
|
+
/**
|
|
395
|
+
* Gets the presence path for an agent.
|
|
396
|
+
*
|
|
397
|
+
* @private
|
|
398
|
+
* @param {string} agentId - Agent identifier.
|
|
399
|
+
* @returns {string} Firebase path.
|
|
400
|
+
*/
|
|
401
|
+
private buildAgentPresencePath;
|
|
402
|
+
/**
|
|
403
|
+
* Subscribes to presence changes for all agents.
|
|
404
|
+
*
|
|
405
|
+
* @param {(agentId: string, data: object | null) => void} callback - Change handler.
|
|
406
|
+
* @returns {() => void} Unsubscribe function.
|
|
407
|
+
*/
|
|
408
|
+
onPresenceChange(callback: (agentId: string, data: object | null) => void): () => void;
|
|
409
|
+
/**
|
|
410
|
+
* Subscribes to presence changes for a specific agent.
|
|
411
|
+
*
|
|
412
|
+
* @param {string} agentId - Agent identifier.
|
|
413
|
+
* @param {(agentId: string, data: object | null) => void} callback - Change handler.
|
|
414
|
+
* @returns {() => void} Unsubscribe function.
|
|
415
|
+
*/
|
|
416
|
+
onPresenceAgentChange(agentId: string, callback: (agentId: string, data: object | null) => void): () => void;
|
|
417
|
+
/**
|
|
418
|
+
* Creates a new call request via API.
|
|
419
|
+
*
|
|
420
|
+
* @async
|
|
421
|
+
* @param {Omit<CallRequest, "status" | "createdAt">} requestData - Request data.
|
|
422
|
+
* @returns {Promise<string>} Request identifier.
|
|
423
|
+
*/
|
|
424
|
+
createCallRequest(requestData: Omit<CallRequest, "status" | "createdAt" | "id">): Promise<string>;
|
|
425
|
+
/**
|
|
426
|
+
* Subscribes to new call requests.
|
|
427
|
+
*
|
|
428
|
+
* @param {CallRequestListener} callback - Request handler.
|
|
429
|
+
* @returns {() => void} Unsubscribe function.
|
|
430
|
+
*/
|
|
431
|
+
onNewCallRequest(callback: CallRequestListener): () => void;
|
|
432
|
+
/**
|
|
433
|
+
* Subscribes to call request changes.
|
|
434
|
+
*
|
|
435
|
+
* @param {CallRequestListener} callback - Change handler.
|
|
436
|
+
* @returns {() => void} Unsubscribe function.
|
|
437
|
+
*/
|
|
438
|
+
onCallRequestChange(callback: CallRequestListener): () => void;
|
|
439
|
+
/**
|
|
440
|
+
* Subscribes to call request removals.
|
|
441
|
+
*
|
|
442
|
+
* @param {(id: string) => void} callback - Removal handler.
|
|
443
|
+
* @returns {() => void} Unsubscribe function.
|
|
444
|
+
*/
|
|
445
|
+
onCallRequestRemoved(callback: (id: string) => void): () => void;
|
|
446
|
+
/**
|
|
447
|
+
* Accepts a call request.
|
|
448
|
+
*
|
|
449
|
+
* @async
|
|
450
|
+
* @param {string} requestId - Request identifier.
|
|
451
|
+
* @returns {Promise<void>}
|
|
452
|
+
*/
|
|
453
|
+
acceptCallRequest(requestId: string): Promise<void>;
|
|
454
|
+
/**
|
|
455
|
+
* Cancels a call request via API.
|
|
456
|
+
*
|
|
457
|
+
* @async
|
|
458
|
+
* @param {string} requestId - Request identifier.
|
|
459
|
+
* @returns {Promise<void>}
|
|
460
|
+
*/
|
|
461
|
+
cancelCallRequest(requestId: string): Promise<void>;
|
|
462
|
+
/**
|
|
463
|
+
* Cancels onDisconnect behavior for a request.
|
|
464
|
+
*
|
|
465
|
+
* @async
|
|
466
|
+
* @param {string} requestId - Request identifier.
|
|
467
|
+
* @returns {Promise<void>}
|
|
468
|
+
*/
|
|
469
|
+
cancelOnDisconnect(requestId: string): Promise<void>;
|
|
470
|
+
/**
|
|
471
|
+
* Subscribes to pending call requests with deduplication.
|
|
472
|
+
*
|
|
473
|
+
* @param {CallRequestListener} callback - Request handler.
|
|
474
|
+
* @param {{ resetSeen?: boolean }} [options] - Subscription options.
|
|
475
|
+
* @returns {() => void} Unsubscribe function.
|
|
476
|
+
*/
|
|
477
|
+
subscribePendingRequests(callback: CallRequestListener, options?: {
|
|
478
|
+
resetSeen?: boolean;
|
|
479
|
+
}): () => void;
|
|
480
|
+
/**
|
|
481
|
+
* Subscribes to request changes with content deduplication.
|
|
482
|
+
*
|
|
483
|
+
* @param {CallRequestListener} callback - Change handler.
|
|
484
|
+
* @returns {() => void} Unsubscribe function.
|
|
485
|
+
*/
|
|
486
|
+
subscribeRequestChanges(callback: CallRequestListener): () => void;
|
|
487
|
+
/**
|
|
488
|
+
* Attempts to safely accept a request if still pending.
|
|
489
|
+
*
|
|
490
|
+
* @async
|
|
491
|
+
* @param {string} requestId - Request identifier.
|
|
492
|
+
* @returns {Promise<boolean>} True if successfully accepted.
|
|
493
|
+
*/
|
|
494
|
+
tryAcceptRequest(requestId: string): Promise<boolean>;
|
|
495
|
+
/**
|
|
496
|
+
* Subscribes to room sync notifications.
|
|
497
|
+
*
|
|
498
|
+
* @param {string} roomId - Room identifier.
|
|
499
|
+
* @param {(data: RoomSyncData | null) => void} callback - Sync handler.
|
|
500
|
+
* @returns {() => void} Unsubscribe function.
|
|
501
|
+
*/
|
|
502
|
+
onRoomSync(roomId: string, callback: (data: RoomSyncData | null) => void): () => void;
|
|
503
|
+
/**
|
|
504
|
+
* Clears the sync flag for a room.
|
|
505
|
+
*
|
|
506
|
+
* @async
|
|
507
|
+
* @param {string} roomId - Room identifier.
|
|
508
|
+
* @param {string} [reason] - Reason for clearing.
|
|
509
|
+
* @returns {Promise<void>}
|
|
510
|
+
*/
|
|
511
|
+
clearRoomSync(roomId: string, reason?: string): Promise<void>;
|
|
512
|
+
/**
|
|
513
|
+
* Subscribes to new room request notifications.
|
|
514
|
+
*
|
|
515
|
+
* @param {string} roomId - Origin room identifier.
|
|
516
|
+
* @param {(data: NewRoomRequestData | null) => void} callback - Request handler.
|
|
517
|
+
* @returns {() => void} Unsubscribe function.
|
|
518
|
+
*/
|
|
519
|
+
onNewRoomRequest(roomId: string, callback: (data: NewRoomRequestData | null) => void): () => void;
|
|
520
|
+
/**
|
|
521
|
+
* Removes all Firebase listeners.
|
|
522
|
+
*/
|
|
523
|
+
unsubscribeAllFirebase(): void;
|
|
524
|
+
/**
|
|
525
|
+
* Cleans up all resources and connections.
|
|
526
|
+
*
|
|
527
|
+
* @async
|
|
528
|
+
* @returns {Promise<void>}
|
|
529
|
+
*/
|
|
530
|
+
destroy(): Promise<void>;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
export { ConversationService, Room };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! @onlive.ai/common-121 v0.2.163 | © 2026 Onlive.ai */
|
|
2
|
+
import{Session as m}from"@onlive.ai/tracker";import{Room as G,RoomEvent as y}from"livekit-client";import{initializeApp as z}from"firebase/app";import{query as g,endAt as q,equalTo as U,get as R,getDatabase as $,limitToFirst as j,limitToLast as D,onChildAdded as f,onChildChanged as v,onChildRemoved as T,onDisconnect as C,onValue as I,orderByChild as N,orderByKey as L,orderByValue as F,push as E,ref as B,remove as J,runTransaction as X,set as A,startAt as Q,update as K}from"firebase/database";var p=class{constructor(e){this.onChildChanged=(e,t)=>v(this.ref(e),i=>t(i.key||"",i.val(),i));this.onChildRemoved=(e,t)=>T(this.ref(e),i=>t(i.key||"",i.val(),i));this.onChildChangedQuery=(e,t)=>v(e,i=>t(i.key||"",i.val(),i));this.onChildRemovedQuery=(e,t)=>T(e,i=>t(i.key||"",i.val(),i));let t=z(e.config);this.db=$(t)}ref(e){return B(this.db,e)}async getOnce(e){let t=await R(this.ref(e));return t.exists()?t.val():null}async getOnceQuery(e){let t=await R(e),i=[];return t.exists()&&t.forEach(s=>{i.push({key:s.key||"",value:s.val()})}),i}onValue(e,t){return I(this.ref(e),i=>t(i.key??"",i.val(),i),i=>console.error("onValue error",i))}onValueQuery(e,t){return I(e,i=>t(i.key??"",i.val(),i),i=>console.error("onValueQuery error",i))}onChildAdded(e,t){return f(this.ref(e),i=>t(i.key||"",i.val(),i),i=>console.error("onChildAdded error",i))}onChildAddedQuery(e,t){return f(e,i=>t(i.key||"",i.val(),i),i=>console.error("onChildAddedQuery error",i))}write(e,t){return A(this.ref(e),t)}update(e,t){return K(this.ref(e),t)}remove(e){return J(this.ref(e))}async push(e,t){let i=E(this.ref(e));return await A(i,t),i.key}onDisconnectUpdate(e,t){return C(this.ref(e)).update(t)}cancelOnDisconnect(e){return C(this.ref(e)).cancel()}transaction(e,t){return X(this.ref(e),i=>t(i))}query(e,t={}){let i=this.ref(e);return t.orderBy==="child"&&t.childKey&&(i=g(i,N(t.childKey))),t.orderBy==="key"&&(i=g(i,L())),t.orderBy==="value"&&(i=g(i,F())),t.startAt!=null&&(i=g(i,Q(t.startAt))),t.endAt!=null&&(i=g(i,q(t.endAt))),t.equalTo!=null&&(i=g(i,U(t.equalTo))),t.limitFirst!=null&&(i=g(i,j(t.limitFirst))),t.limitLast!=null&&(i=g(i,D(t.limitLast))),i}};var a=async(o,e)=>{let t=await fetch(o,e);if(!t.ok){let i=await t.json().catch(()=>({}));throw new Error(JSON.stringify({status:t.status,statusText:t.statusText,...i}))}return t&&t.json()};var P=o=>{let e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",t="";for(let i=0;i<o;i++)t+=e.charAt(Math.floor(Math.random()*e.length));return t};import{Generator as _,Session as l}from"@onlive.ai/tracker";var d="chatbot",u=class o{static hasSession(){return!!l.getCookie(d)}static getSession(e={role:"guest",regenerate:!1}){e.regenerate&&(l.id=_.uuid(),l.deleteCookie(d));let t=l.getCookie(d);return t&&o.isValidSession(t,e.role)?t:o.createSession(e.role)}static createSession(e){let t={externalId:e==="agent"?String(o.getUserId()||l.id):l.id,secret:P(16),createdAt:new Date().toISOString()};return l.setCookie(d,t,3600*24*365),t}static isValidSession(e,t){if(t==="guest")return!0;let i=o.getUserId();return!!(i&&String(i)===e.externalId)}static getUserId(){return l.getCookie("user-id",{objectKey:"userId",storageKey:"user",storageType:"localStorage",ttl:3600*24*365,preserveData:!0})}static updateSessionWithRegistrationData(e){let t=l.getCookie(d);if(t||(t=o.createSession("guest")),t){let i={...t,registrationData:e};l.setCookie(d,i,3600*24*365)}}static hasRegistrationData(){return!!l.getCookie(d)?.registrationData}static async getAgentInfo(e){return fetch(`${e}/api/v1/auth/user-info`,{credentials:"include"}).then(t=>t.json())}static getRegistrationData(){return l.getCookie(d)?.registrationData}};var O="lk.chat",S="lk.transcription",w="lk.events",h="typing-indicator";var b=class extends G{},x=class{constructor(e){this.listeners=new Set;this.typingListeners=new Set;this.transcriptionMap=new Map;this.abortControllers={register:new AbortController,createRoom:new AbortController,closeRoom:new AbortController,evaluateRoom:new AbortController,persistMessage:new AbortController,sendMessageReport:new AbortController,deleteMessageReport:new AbortController,updateMessageReactions:new AbortController,getRooms:new AbortController};this.authToken=null;this.firebaseUnsubscribers={};this.seenRequestIds=new Set;this.lastSnapshotById=new Map;this.handleIncomingMessage=async(e,t)=>{let i=e?.info?.id,s=e.info?.attributes?.["lk.segment_id"];s&&(this.transcriptionMap.has(s)?i=this.transcriptionMap.get(s)||"":this.transcriptionMap.set(s,i));let n=t?.identity?this.room.getParticipantByIdentity(t.identity):void 0,r="";for await(let c of e)r+=c,this.emitMessage({id:i,timestamp:Date.now(),message:r,assets:JSON.parse(e.info?.attributes?.assets||"[]"),from:n});this.messagePersistence==="client"&&this.persistMessage({roomId:this.room.id,content:r,externalId:i,identity:n?.identity,kind:n?.kind})};this.emitMessage=e=>{for(let t of this.listeners)t([e])};this.handleDataReceived=(e,t,i,s)=>{if(s===h)try{let n=JSON.parse(new TextDecoder().decode(e));if(n.type==="typing"&&n.participantId!==this.room.localParticipant.identity){let r={type:"typing",isTyping:n.isTyping,timestamp:n.timestamp,participantId:n.participantId};this.emitTypingIndicator(r)}}catch(n){console.warn("Failed to parse typing indicator:",n)}};this.emitTypingIndicator=e=>{for(let t of this.typingListeners)t(e)};this.apiUrl=e.apiUrl,this.authUrl=e.authUrl,this.organizationId=e.organizationId,this.channelTopic=e.channelTopic||O,this.transcriptionTopic=e.transcriptionTopic||S,this.eventsTopic=e.eventsTopic||w,this.messagePersistence=e.messagePersistence||"disabled",this.room=this.createRoomInstance(),e.firebaseConfig&&this.initializeFirebase(e.firebaseConfig)}createRoomInstance(){return new b({adaptiveStream:!0,dynacast:!0})}ensureRoom(){return this.room||(this.room=this.createRoomInstance()),this.room}initializeFirebase(e){this.firebaseApi=new p({config:e}),this.presencePath=`orgs/${this.organizationId}/presence`,this.callsPath=`orgs/${this.organizationId}/calls`}initializeRoomHandlers(){try{this.room.unregisterTextStreamHandler(this.channelTopic),this.room.unregisterTextStreamHandler(this.transcriptionTopic)}catch{}this.room.off(y.DataReceived,this.handleDataReceived),this.room.registerTextStreamHandler(this.channelTopic,this.handleIncomingMessage),this.room.registerTextStreamHandler(this.transcriptionTopic,this.handleIncomingMessage),this.room.on(y.DataReceived,this.handleDataReceived)}async registerUser(e,t,i,s){let n=await a(`${this.apiUrl}/users/register`,{method:"POST",body:JSON.stringify({externalId:e,secret:t,...i,metadata:s}),headers:{"X-Onlive-Organization-Id":this.organizationId,"Content-Type":"application/json"},signal:this.abortControllers.register.signal});return this.authToken=n.token,n}async registerAgent(e,t){let i=m.getCookie("livekit-agent-token");if(i){if(this.decodeJwtPayload(i)?.username===t.name)return this.authToken=i,i;m.deleteCookie("livekit-agent-token")}let s=await a(`${this.authUrl}/admins/register`,{method:"POST",body:JSON.stringify({externalId:e,name:t.name,email:t.email,avatar:t.avatar}),headers:{"X-Onlive-Organization-Id":this.organizationId,"Content-Type":"application/json"},credentials:"include",signal:this.abortControllers.register.signal});return m.setCookie("livekit-agent-token",s.token,1440*60),this.authToken=s.token,s.token}decodeJwtPayload(e){try{let t=e.split(".");if(t.length!==3)return null;let i=t[1],s=atob(i.replace(/-/g,"+").replace(/_/g,"/"));return JSON.parse(s)}catch{return null}}async createRoom(e,t={}){this.room=this.ensureRoom();let i=await a(`${this.apiUrl}/rooms`,{method:"POST",body:JSON.stringify(e),headers:{Authorization:`Bearer ${this.authToken}`,"X-Onlive-Organization-Id":this.organizationId,"Content-Type":"application/json"},signal:this.abortControllers.createRoom.signal});return this.setRoomMetadata(i),this.setupParticipantAttributesHandler(),this.room.connect(i.wsURL,i.token).then(()=>{this.room.localParticipant.setAttributes(t)}),this.initializeRoomHandlers(),this.room}async joinRoom(e,t,i,s){let n=await a(`${this.apiUrl}/rooms/${e}/join`,{method:"POST",body:JSON.stringify({timezone:t,language:i,...s??{}}),headers:{Authorization:`Bearer ${this.authToken}`,"X-Onlive-Organization-Id":this.organizationId,"Content-Type":"application/json"},signal:this.abortControllers.createRoom.signal});return this.setRoomMetadata(n),this.setupParticipantAttributesHandler(),await this.room.connect(n.wsURL,n.token),this.initializeRoomHandlers(),this.room}setRoomMetadata(e){this.room.id=e.id,this.room.groupId=e.groupId,this.room.createdAt=e.createdAt,this.room.connectedAt=new Date().toISOString()}setupParticipantAttributesHandler(){this.room.on(y.ParticipantAttributesChanged,e=>{e.identity===this.room.localParticipant.identity&&u.updateSessionWithRegistrationData(e.attributes)})}async evaluateRoom(e){let t=e.roomId||this.room?.id;if(!t)throw new Error("Room ID is required for evaluation");return a(`${this.apiUrl}/rooms/${t}/evaluate`,{method:"POST",body:JSON.stringify({rating:e.rating,comment:e.comment}),headers:{Authorization:`Bearer ${this.authToken}`,"X-Onlive-Organization-Id":this.organizationId,"Content-Type":"application/json"},signal:this.abortControllers.evaluateRoom.signal})}async closeRoom(){if(this.room)return a(`${this.apiUrl}/rooms/${this.room.id}/close`,{method:"POST",headers:{Authorization:`Bearer ${this.authToken}`,"X-Onlive-Organization-Id":this.organizationId,"Content-Type":"application/json"},signal:this.abortControllers.closeRoom.signal})}async disconnect(){this.room&&(this.room.removeAllListeners(),await this.room.disconnect(),this.room=null)}async disconnectAndCloseRoom(){await this.closeRoom(),await this.disconnect()}async readRoom(e){return a(`${this.apiUrl}/rooms/${e}/read`,{method:"POST",headers:{Authorization:`Bearer ${this.authToken}`,"X-Onlive-Organization-Id":this.organizationId,"Content-Type":"application/json"},signal:this.abortControllers.persistMessage.signal})}async getRooms(e){let t=new URLSearchParams;return e.page&&t.append("page",e.page.toString()),e.limit&&t.append("limit",e.limit.toString()),e.offset&&t.append("offset",e.offset.toString()),e.orderBy&&t.append("orderBy",e.orderBy),e.orderDir&&t.append("orderDir",e.orderDir),e.ids?.length&&t.append("ids",e.ids.join(",")),e.with?.length&&t.append("with",e.with.join(",")),e.count?.length&&t.append("count",e.count.join(",")),e.latestOnly&&t.append("latestOnly",e.latestOnly.toString()),e.includeUnread&&t.append("includeUnread",e.includeUnread.toString()),e.roomStatus&&t.append("roomStatus",e.roomStatus),e.archived&&t.append("archived",e.archived.toString()),e.participantIds?.length&&t.append("participantIds",e.participantIds.join(",")),e.participantExternalIds?.length&&t.append("participantExternalIds",e.participantExternalIds.join(",")),e.groupId&&t.append("groupId",e.groupId),e.hasMessages!==void 0&&t.append("hasMessages",e.hasMessages.toString()),a(`${this.authUrl}/rooms?${t}`,{method:"GET",headers:{"X-Onlive-Organization-Id":this.organizationId,"Content-Type":"application/json"},credentials:"include",signal:this.abortControllers.getRooms.signal})}async sendMessage(e,t){let i=await this.room.localParticipant.sendText(e,{topic:this.channelTopic,attributes:t});this.emitMessage({id:i.id,timestamp:Date.now(),message:e,assets:JSON.parse(t?.assets||"[]"),from:this.room.localParticipant}),this.messagePersistence==="client"&&this.persistMessage({roomId:this.room.id,content:e,externalId:i.id,identity:this.room.localParticipant?.identity,kind:this.room.localParticipant?.kind})}async persistMessage(e){return a(`${this.apiUrl}/messages/create`,{method:"POST",body:JSON.stringify(e),headers:{Authorization:`Bearer ${this.authToken}`,"X-Onlive-Organization-Id":this.organizationId,"Content-Type":"application/json"},signal:this.abortControllers.persistMessage.signal})}async getMessages(e){let t=new URLSearchParams;return e.limit&&t.append("limit",e.limit.toString()),e.with&&t.append("with",e.with.join(",")),(await a(`${this.apiUrl}/messages/search${t.size?`?${t.toString()}`:""}`,{method:"POST",body:JSON.stringify(e),headers:{Authorization:`Bearer ${this.authToken}`,"X-Onlive-Organization-Id":this.organizationId,"Content-Type":"application/json"},signal:this.abortControllers.createRoom.signal})).items}async sendMessageReport(e){try{return a(`${this.apiUrl}/messages/${e.messageId}/report`,{method:"POST",headers:{Authorization:`Bearer ${this.authToken}`,"X-Onlive-Organization-Id":this.organizationId,"Content-Type":"application/json"},signal:this.abortControllers.sendMessageReport.signal})}catch(t){console.error("Error sending message report:",t)}}async deleteMessageReport(e){try{return a(`${this.apiUrl}/messages/${e.messageId}/report`,{method:"DELETE",headers:{Authorization:`Bearer ${this.authToken}`,"X-Onlive-Organization-Id":this.organizationId,"Content-Type":"application/json"},signal:this.abortControllers.deleteMessageReport.signal})}catch(t){console.error("Error deleting message report:",t)}}async updateMessageReactions(e){try{return a(`${this.apiUrl}/messages/${e.messageId}/reactions`,{method:"PATCH",body:JSON.stringify({add:e.add||[],remove:e.remove||[]}),headers:{Authorization:`Bearer ${this.authToken}`,"X-Onlive-Organization-Id":this.organizationId,"Content-Type":"application/json"},signal:this.abortControllers.updateMessageReactions.signal})}catch(t){console.error("Error updating message reactions:",t)}}subscribeMessages(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}async sendTypingIndicator(e){try{let t=new TextEncoder().encode(JSON.stringify({type:"typing",isTyping:e,timestamp:Date.now(),participantId:this.room.localParticipant.identity}));await this.room.localParticipant.publishData(t,{reliable:!1,topic:h})}catch(t){console.warn("Failed to send typing indicator:",t)}}subscribeTypingIndicators(e){return this.typingListeners.add(e),()=>{this.typingListeners.delete(e)}}unsubscribeTypingIndicators(e){this.typingListeners.delete(e)}async sendContextualEvent(e){try{let t=JSON.stringify(e);await this.room.localParticipant.sendText(t,{topic:this.eventsTopic})}catch(t){console.warn("Failed to send event:",t)}}async requestNewRoom(e){return a(`${this.apiUrl}/rooms/request-new`,{method:"POST",body:JSON.stringify(e),headers:{Authorization:`Bearer ${this.authToken}`,"X-Onlive-Organization-Id":this.organizationId,"Content-Type":"application/json"}})}async confirmRoomRequest(e){return a(`${this.apiUrl}/rooms/confirm-call`,{method:"POST",body:JSON.stringify({roomId:e}),headers:{Authorization:`Bearer ${this.authToken}`,"X-Onlive-Organization-Id":this.organizationId,"Content-Type":"application/json"}})}async cancelRoomRequest(e){return a(`${this.apiUrl}/rooms/cancel-call`,{method:"POST",body:JSON.stringify({roomId:e}),headers:{Authorization:`Bearer ${this.authToken}`,"X-Onlive-Organization-Id":this.organizationId,"Content-Type":"application/json"}})}async finishCall(){return a(`${this.apiUrl}/rooms/finish-call`,{method:"POST",body:JSON.stringify({roomId:this.room.id}),headers:{Authorization:`Bearer ${this.authToken}`,"X-Onlive-Organization-Id":this.organizationId,"Content-Type":"application/json"}})}isFirebaseEnabled(){return!!(this.firebaseApi&&this.presencePath&&this.callsPath)}getFirebase(){if(!this.firebaseApi||!this.presencePath||!this.callsPath)throw new Error("Firebase is not initialized. Provide firebaseConfig in constructor.");return{api:this.firebaseApi,presencePath:this.presencePath,callsPath:this.callsPath}}buildAgentPresencePath(e){return`${this.presencePath}/${e}`}onPresenceChange(e){let{api:t,presencePath:i}=this.getFirebase();return t.onChildChanged(i,(s,n)=>e(s,n))}onPresenceAgentChange(e,t){let{api:i}=this.getFirebase();return i.onValue(this.buildAgentPresencePath(e),(s,n)=>t(s,n))}async createCallRequest(e){let{api:t,callsPath:i}=this.getFirebase(),n=(await a(`${this.apiUrl}/rooms/call-request`,{method:"POST",headers:{Authorization:`Bearer ${this.authToken}`,"X-Onlive-Organization-Id":this.organizationId,"Content-Type":"application/json"},body:JSON.stringify(e)})).id;return t.onDisconnectUpdate(`${i}/${n}`,{status:"disconnected"}),n}onNewCallRequest(e){let{api:t,callsPath:i}=this.getFirebase();return t.onChildAdded(i,(s,n)=>e(s,{...n,id:s}))}onCallRequestChange(e){let{api:t,callsPath:i}=this.getFirebase();return t.onChildChanged(i,(s,n)=>e(s,{...n,id:s}))}onCallRequestRemoved(e){let{api:t,callsPath:i}=this.getFirebase();return t.onChildRemoved(i,s=>e(s))}async acceptCallRequest(e){let{api:t,callsPath:i}=this.getFirebase();return await t.cancelOnDisconnect(`${i}/${e}`),t.update(`${i}/${e}`,{status:"accepted"})}async cancelCallRequest(e){let{api:t,callsPath:i}=this.getFirebase();await t.cancelOnDisconnect(`${i}/${e}`),await a(`${this.apiUrl}/rooms/call-request/cancel`,{method:"POST",headers:{Authorization:`Bearer ${this.authToken}`,"X-Onlive-Organization-Id":this.organizationId,"Content-Type":"application/json"},body:JSON.stringify({callId:e})})}async cancelOnDisconnect(e){let{api:t,callsPath:i}=this.getFirebase();await t.cancelOnDisconnect(`${i}/${e}`)}subscribePendingRequests(e,t={}){let{api:i,callsPath:s}=this.getFirebase();t.resetSeen&&this.seenRequestIds.clear(),this.firebaseUnsubscribers["pending-requests"]?.();let n=i.query(s,{orderBy:"child",childKey:"status",equalTo:"pending"}),r=i.onChildAddedQuery(n,(c,k)=>{if(!c||this.seenRequestIds.has(c))return;let M={...k,id:c};this.seenRequestIds.add(c),e(c,M)});return this.firebaseUnsubscribers["pending-requests"]=r,()=>{r?.(),delete this.firebaseUnsubscribers["pending-requests"]}}subscribeRequestChanges(e){let{api:t,callsPath:i}=this.getFirebase();this.firebaseUnsubscribers["request-changes"]?.();let s=t.onChildChanged(i,(n,r)=>{if(!n)return;let c=JSON.stringify(r);this.lastSnapshotById.get(n)!==c&&(this.lastSnapshotById.set(n,c),e(n,{...r,id:n}))});return this.firebaseUnsubscribers["request-changes"]=s,()=>{s?.(),delete this.firebaseUnsubscribers["request-changes"]}}async tryAcceptRequest(e){let{api:t,callsPath:i}=this.getFirebase(),s=`${i}/${e}`;return await t.transaction(s,r=>r&&(r.status==="pending"?{...r,status:"accepted"}:r)),(await t.getOnce(s))?.status==="accepted"}onRoomSync(e,t){let{api:i}=this.getFirebase(),s=`orgs/${this.organizationId}/rooms/${e}/sync`;return i.onValue(s,(n,r)=>{t(r)})}async clearRoomSync(e,t){let{api:i}=this.getFirebase(),s=`orgs/${this.organizationId}/rooms/${e}/sync`;await i.write(s,{needsSync:!1,reason:t||null,timestamp:Date.now()})}onNewRoomRequest(e,t){let{api:i}=this.getFirebase(),s=`orgs/${this.organizationId}/rooms/${e}/call`;return i.onValue(s,(n,r)=>{t(r)})}unsubscribeAllFirebase(){Object.values(this.firebaseUnsubscribers).forEach(e=>e?.()),this.firebaseUnsubscribers={}}async destroy(){this.unsubscribeAllFirebase(),this.listeners.clear(),this.typingListeners.clear(),this.transcriptionMap.clear(),this.seenRequestIds.clear(),this.lastSnapshotById.clear(),Object.values(this.abortControllers).forEach(e=>e.abort()),await this.disconnect()}};export{x as ConversationService,b as Room};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! @onlive.ai/common-121 v0.2.163 | © 2026 Onlive.ai */
|
|
2
|
+
"use strict";var r=Object.defineProperty;var o=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var p=(e,t)=>{for(var s in t)r(e,s,{get:t[s],enumerable:!0})},d=(e,t,s,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of a(t))!g.call(e,n)&&n!==s&&r(e,n,{get:()=>t[n],enumerable:!(i=o(t,n))||i.enumerable});return e};var m=e=>d(r({},"__esModule",{value:!0}),e);var y={};p(y,{CHAT_TOPIC:()=>c,EVENTS_TOPIC:()=>l,TRANSCRIPTION_TOPIC:()=>u,TYPING_INDICATOR_TOPIC:()=>x});module.exports=m(y);var c="lk.chat",u="lk.transcription",l="lk.events",x="typing-indicator";0&&(module.exports={CHAT_TOPIC,EVENTS_TOPIC,TRANSCRIPTION_TOPIC,TYPING_INDICATOR_TOPIC});
|