@onlive.ai/common-121 0.2.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/README.md +151 -0
  2. package/package.json +39 -0
  3. package/services/audio.service.cjs +75 -0
  4. package/services/audio.service.d.cts +14 -0
  5. package/services/audio.service.d.ts +14 -0
  6. package/services/audio.service.js +52 -0
  7. package/services/firebase/firebase-api.cjs +108 -0
  8. package/services/firebase/firebase-api.d.cts +54 -0
  9. package/services/firebase/firebase-api.d.ts +54 -0
  10. package/services/firebase/firebase-api.js +105 -0
  11. package/services/firebase/firebase.service.cjs +193 -0
  12. package/services/firebase/firebase.service.d.cts +40 -0
  13. package/services/firebase/firebase.service.d.ts +40 -0
  14. package/services/firebase/firebase.service.js +190 -0
  15. package/services/livekit.service.cjs +353 -0
  16. package/services/livekit.service.d.cts +131 -0
  17. package/services/livekit.service.d.ts +131 -0
  18. package/services/livekit.service.js +329 -0
  19. package/services/request.provider.cjs +48 -0
  20. package/services/request.provider.d.cts +27 -0
  21. package/services/request.provider.d.ts +27 -0
  22. package/services/request.provider.js +22 -0
  23. package/themes/dark.cjs +433 -0
  24. package/themes/dark.d.cts +5 -0
  25. package/themes/dark.d.ts +5 -0
  26. package/themes/dark.js +408 -0
  27. package/themes/light.cjs +433 -0
  28. package/themes/light.d.cts +5 -0
  29. package/themes/light.d.ts +5 -0
  30. package/themes/light.js +408 -0
  31. package/types/tracking-options.cjs +18 -0
  32. package/types/tracking-options.d.cts +27 -0
  33. package/types/tracking-options.d.ts +27 -0
  34. package/types/tracking-options.js +0 -0
  35. package/types/window-context.cjs +18 -0
  36. package/types/window-context.d.cts +8 -0
  37. package/types/window-context.d.ts +8 -0
  38. package/types/window-context.js +0 -0
  39. package/utils/adopt-styles.cjs +66 -0
  40. package/utils/adopt-styles.d.cts +5 -0
  41. package/utils/adopt-styles.d.ts +5 -0
  42. package/utils/adopt-styles.js +41 -0
  43. package/utils/browser-preferences.cjs +67 -0
  44. package/utils/browser-preferences.d.cts +18 -0
  45. package/utils/browser-preferences.d.ts +18 -0
  46. package/utils/browser-preferences.js +42 -0
  47. package/utils/classify-media.cjs +38 -0
  48. package/utils/classify-media.d.cts +9 -0
  49. package/utils/classify-media.d.ts +9 -0
  50. package/utils/classify-media.js +13 -0
  51. package/utils/decorators.cjs +53 -0
  52. package/utils/decorators.d.cts +34 -0
  53. package/utils/decorators.d.ts +34 -0
  54. package/utils/decorators.js +28 -0
  55. package/utils/detected-lang.cjs +47 -0
  56. package/utils/detected-lang.d.cts +10 -0
  57. package/utils/detected-lang.d.ts +10 -0
  58. package/utils/detected-lang.js +22 -0
  59. package/utils/fullscreen.cjs +52 -0
  60. package/utils/fullscreen.d.cts +16 -0
  61. package/utils/fullscreen.d.ts +16 -0
  62. package/utils/fullscreen.js +26 -0
  63. package/utils/insert-script.cjs +55 -0
  64. package/utils/insert-script.d.cts +29 -0
  65. package/utils/insert-script.d.ts +29 -0
  66. package/utils/insert-script.js +30 -0
  67. package/utils/markdown.cjs +103 -0
  68. package/utils/markdown.d.cts +12 -0
  69. package/utils/markdown.d.ts +12 -0
  70. package/utils/markdown.js +68 -0
  71. package/utils/merge.cjs +47 -0
  72. package/utils/merge.d.cts +23 -0
  73. package/utils/merge.d.ts +23 -0
  74. package/utils/merge.js +22 -0
  75. package/utils/multiband-track-volume.cjs +90 -0
  76. package/utils/multiband-track-volume.d.cts +27 -0
  77. package/utils/multiband-track-volume.d.ts +27 -0
  78. package/utils/multiband-track-volume.js +65 -0
  79. package/utils/onlive-url-params.cjs +38 -0
  80. package/utils/onlive-url-params.d.cts +14 -0
  81. package/utils/onlive-url-params.d.ts +14 -0
  82. package/utils/onlive-url-params.js +13 -0
  83. package/utils/pretty-distance.cjs +45 -0
  84. package/utils/pretty-distance.d.cts +46 -0
  85. package/utils/pretty-distance.d.ts +46 -0
  86. package/utils/pretty-distance.js +20 -0
  87. package/utils/random-string.cjs +37 -0
  88. package/utils/random-string.d.cts +9 -0
  89. package/utils/random-string.d.ts +9 -0
  90. package/utils/random-string.js +12 -0
  91. package/utils/resource-type.cjs +50 -0
  92. package/utils/resource-type.d.cts +16 -0
  93. package/utils/resource-type.d.ts +16 -0
  94. package/utils/resource-type.js +24 -0
  95. package/utils/safe-html.cjs +112 -0
  96. package/utils/safe-html.d.cts +12 -0
  97. package/utils/safe-html.d.ts +12 -0
  98. package/utils/safe-html.js +77 -0
  99. package/utils/sanitize.cjs +94 -0
  100. package/utils/sanitize.d.cts +11 -0
  101. package/utils/sanitize.d.ts +11 -0
  102. package/utils/sanitize.js +59 -0
  103. package/utils/spread.cjs +70 -0
  104. package/utils/spread.d.cts +14 -0
  105. package/utils/spread.d.ts +14 -0
  106. package/utils/spread.js +47 -0
  107. package/utils/watch.cjs +54 -0
  108. package/utils/watch.d.cts +28 -0
  109. package/utils/watch.d.ts +28 -0
  110. package/utils/watch.js +29 -0
  111. package/vite-env.d.ts +22 -0
@@ -0,0 +1,329 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
+
5
+ // services/livekit.service.ts
6
+ import { setupChat } from "@livekit/components-core";
7
+ import {
8
+ Room as LiveKitRoom
9
+ } from "livekit-client";
10
+
11
+ // services/request.provider.ts
12
+ var request = async (input, init) => {
13
+ const response = await fetch(input, init);
14
+ if (!response.ok) {
15
+ const errorData = await response.json().catch(() => ({}));
16
+ throw new Error(
17
+ JSON.stringify({
18
+ status: response.status,
19
+ statusText: response.statusText,
20
+ ...errorData
21
+ })
22
+ );
23
+ }
24
+ return response && response.json();
25
+ };
26
+
27
+ // services/livekit.service.ts
28
+ var Room = class extends LiveKitRoom {
29
+ constructor(options) {
30
+ super(options);
31
+ __publicField(this, "id");
32
+ __publicField(this, "groupId");
33
+ __publicField(this, "createdAt");
34
+ __publicField(this, "connectedAt");
35
+ }
36
+ };
37
+ var CHAT_TOPIC = "lk.chat";
38
+ var TRANSCRIPTION_TOPIC = "lk.transcription";
39
+ var LivekitService = class {
40
+ constructor(options) {
41
+ __publicField(this, "listeners", /* @__PURE__ */ new Set());
42
+ __publicField(this, "apiUrl");
43
+ __publicField(this, "version");
44
+ __publicField(this, "organizationId");
45
+ __publicField(this, "channelTopic");
46
+ __publicField(this, "transcriptionTopic");
47
+ __publicField(this, "setupChat");
48
+ __publicField(this, "abortControllers");
49
+ __publicField(this, "authToken", null);
50
+ __publicField(this, "messagePersistence");
51
+ __publicField(this, "room");
52
+ __publicField(this, "processMessage", async (reader, participantInfo) => {
53
+ const id = reader?.info?.id;
54
+ const participant = participantInfo?.identity ? this.room.getParticipantByIdentity(participantInfo.identity) : void 0;
55
+ let message = "";
56
+ for await (const chunk of reader) {
57
+ message += chunk;
58
+ this.emitMessage({
59
+ id,
60
+ timestamp: Date.now(),
61
+ message,
62
+ from: participant
63
+ });
64
+ }
65
+ if (this.messagePersistence === "client") {
66
+ this.persistMessage({
67
+ roomId: this.room.id,
68
+ content: message,
69
+ externalId: reader?.info?.id,
70
+ identity: participant?.identity,
71
+ kind: participant?.kind
72
+ });
73
+ }
74
+ });
75
+ __publicField(this, "emitMessage", (message) => {
76
+ for (const cb of this.listeners) {
77
+ cb([message]);
78
+ }
79
+ });
80
+ if ("room" in options) {
81
+ this.room = options.room;
82
+ } else {
83
+ this.apiUrl = options.apiUrl;
84
+ this.room = this.instanceRoom();
85
+ }
86
+ this.organizationId = options.organizationId;
87
+ this.version = options.version;
88
+ this.channelTopic = options.channelTopic || CHAT_TOPIC;
89
+ this.transcriptionTopic = options.transcriptionTopic || TRANSCRIPTION_TOPIC;
90
+ this.messagePersistence = options.messagePersistence || "disabled";
91
+ this.abortControllers = {
92
+ register: new AbortController(),
93
+ createRoom: new AbortController(),
94
+ closeRoom: new AbortController(),
95
+ evaluateRoom: new AbortController(),
96
+ persistMessage: new AbortController(),
97
+ sendMessageReport: new AbortController(),
98
+ deleteMessageReport: new AbortController(),
99
+ updateMessageReactions: new AbortController()
100
+ };
101
+ }
102
+ initialize() {
103
+ if (this.version === "v1") {
104
+ this.room.registerTextStreamHandler(this.channelTopic, this.processMessage);
105
+ this.room.registerTextStreamHandler(this.transcriptionTopic, this.processMessage);
106
+ } else {
107
+ this.setupChat = setupChat(this.room);
108
+ }
109
+ }
110
+ async register(externalId, secret, name) {
111
+ const response = await request(`${this.apiUrl}/users/register`, {
112
+ method: "POST",
113
+ body: JSON.stringify({
114
+ externalId,
115
+ secret,
116
+ name
117
+ }),
118
+ headers: {
119
+ "X-Onlive-Organization-Id": this.organizationId,
120
+ "Content-Type": "application/json"
121
+ },
122
+ signal: this.abortControllers.register.signal
123
+ });
124
+ this.authToken = response.token;
125
+ return response;
126
+ }
127
+ async joinRoom(roomId, timezone, language) {
128
+ const response = await request(`${this.apiUrl}/rooms/${roomId}/join`, {
129
+ method: "POST",
130
+ body: JSON.stringify({ timezone, language }),
131
+ headers: {
132
+ Authorization: `Bearer ${this.authToken}`,
133
+ "X-Onlive-Organization-Id": this.organizationId,
134
+ "Content-Type": "application/json"
135
+ },
136
+ signal: this.abortControllers.createRoom.signal
137
+ });
138
+ this.room.connect(response.wsURL, response.token);
139
+ this.initialize();
140
+ return this.room;
141
+ }
142
+ instanceRoom() {
143
+ if (!this.room) {
144
+ this.room = new Room({
145
+ adaptiveStream: true,
146
+ dynacast: true
147
+ });
148
+ }
149
+ return this.room;
150
+ }
151
+ async createRoom(options) {
152
+ this.room = this.instanceRoom();
153
+ const response = await request(`${this.apiUrl}/rooms`, {
154
+ method: "POST",
155
+ body: JSON.stringify(options),
156
+ headers: {
157
+ Authorization: `Bearer ${this.authToken}`,
158
+ "X-Onlive-Organization-Id": this.organizationId,
159
+ "Content-Type": "application/json"
160
+ },
161
+ signal: this.abortControllers.createRoom.signal
162
+ });
163
+ this.room.id = response.id;
164
+ this.room.groupId = response.groupId;
165
+ this.room.createdAt = response.createdAt;
166
+ this.room.connectedAt = (/* @__PURE__ */ new Date()).toISOString();
167
+ this.room.connect(response.wsURL, response.token);
168
+ this.initialize();
169
+ return this.room;
170
+ }
171
+ async evaluateRoom(options) {
172
+ return request(`${this.apiUrl}/rooms/${this.room.id}/evaluate`, {
173
+ method: "POST",
174
+ body: JSON.stringify({
175
+ rating: options.rating,
176
+ comment: options.comment
177
+ }),
178
+ headers: {
179
+ Authorization: `Bearer ${this.authToken}`,
180
+ "X-Onlive-Organization-Id": this.organizationId,
181
+ "Content-Type": "application/json"
182
+ },
183
+ signal: this.abortControllers.evaluateRoom.signal
184
+ });
185
+ }
186
+ async closeRoom() {
187
+ return request(`${this.apiUrl}/rooms/${this.room.id}/close`, {
188
+ method: "POST",
189
+ headers: {
190
+ Authorization: `Bearer ${this.authToken}`,
191
+ "X-Onlive-Organization-Id": this.organizationId,
192
+ "Content-Type": "application/json"
193
+ },
194
+ signal: this.abortControllers.closeRoom.signal
195
+ });
196
+ }
197
+ async disconnect() {
198
+ if (this.room) {
199
+ this.room.removeAllListeners();
200
+ await this.room.disconnect();
201
+ this.closeRoom();
202
+ this.room = null;
203
+ }
204
+ }
205
+ async sendMessage(message) {
206
+ if (this.version === "v1") {
207
+ const textStream = await this.room.localParticipant.sendText(message, {
208
+ topic: this.channelTopic
209
+ });
210
+ this.emitMessage({
211
+ id: textStream.id,
212
+ timestamp: Date.now(),
213
+ message,
214
+ from: this.room.localParticipant
215
+ });
216
+ if (this.messagePersistence === "client") {
217
+ this.persistMessage({
218
+ roomId: this.room.id,
219
+ content: message,
220
+ externalId: textStream.id,
221
+ identity: this.room.localParticipant?.identity,
222
+ kind: this.room.localParticipant?.kind
223
+ });
224
+ }
225
+ } else {
226
+ await this.setupChat.send(message);
227
+ }
228
+ }
229
+ async persistMessage(options) {
230
+ return request(`${this.apiUrl}/messages/create`, {
231
+ method: "POST",
232
+ body: JSON.stringify(options),
233
+ headers: {
234
+ Authorization: `Bearer ${this.authToken}`,
235
+ "X-Onlive-Organization-Id": this.organizationId,
236
+ "Content-Type": "application/json"
237
+ },
238
+ signal: this.abortControllers.persistMessage.signal
239
+ });
240
+ }
241
+ async getMessages(options) {
242
+ const query = new URLSearchParams();
243
+ if (options.with) {
244
+ query.append("with", options.with.join(","));
245
+ }
246
+ const response = await request(
247
+ `${this.apiUrl}/messages/search${query.size ? `?${query.toString()}` : ""}`,
248
+ {
249
+ method: "POST",
250
+ body: JSON.stringify(options),
251
+ headers: {
252
+ Authorization: `Bearer ${this.authToken}`,
253
+ "X-Onlive-Organization-Id": this.organizationId,
254
+ "Content-Type": "application/json"
255
+ },
256
+ signal: this.abortControllers.createRoom.signal
257
+ }
258
+ );
259
+ return response.items;
260
+ }
261
+ async sendMessageReport(options) {
262
+ try {
263
+ return request(`${this.apiUrl}/messages/${options.messageId}/report`, {
264
+ method: "POST",
265
+ headers: {
266
+ Authorization: `Bearer ${this.authToken}`,
267
+ "X-Onlive-Organization-Id": this.organizationId,
268
+ "Content-Type": "application/json"
269
+ },
270
+ signal: this.abortControllers.sendMessageReport.signal
271
+ });
272
+ } catch (error) {
273
+ console.error("Error sending message report:", error);
274
+ }
275
+ }
276
+ async deleteMessageReport(options) {
277
+ try {
278
+ return request(`${this.apiUrl}/messages/${options.messageId}/report`, {
279
+ method: "DELETE",
280
+ headers: {
281
+ Authorization: `Bearer ${this.authToken}`,
282
+ "X-Onlive-Organization-Id": this.organizationId,
283
+ "Content-Type": "application/json"
284
+ },
285
+ signal: this.abortControllers.deleteMessageReport.signal
286
+ });
287
+ } catch (error) {
288
+ console.error("Error deleting message report:", error);
289
+ }
290
+ }
291
+ async updateMessageReactions(options) {
292
+ try {
293
+ return request(`${this.apiUrl}/messages/${options.messageId}/reactions`, {
294
+ method: "PATCH",
295
+ body: JSON.stringify({
296
+ add: options.add || [],
297
+ remove: options.remove || []
298
+ }),
299
+ headers: {
300
+ Authorization: `Bearer ${this.authToken}`,
301
+ "X-Onlive-Organization-Id": this.organizationId,
302
+ "Content-Type": "application/json"
303
+ },
304
+ signal: this.abortControllers.updateMessageReactions.signal
305
+ });
306
+ } catch (error) {
307
+ console.error("Error updating message reactions:", error);
308
+ }
309
+ }
310
+ subscribeMessages(callback) {
311
+ if (this.version === "v1") {
312
+ this.listeners.add(callback);
313
+ return () => {
314
+ this.listeners.delete(callback);
315
+ };
316
+ } else {
317
+ const subscription = this.setupChat.messageObservable.subscribe(
318
+ callback
319
+ );
320
+ return () => subscription.unsubscribe();
321
+ }
322
+ }
323
+ };
324
+ export {
325
+ CHAT_TOPIC,
326
+ LivekitService,
327
+ Room,
328
+ TRANSCRIPTION_TOPIC
329
+ };
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // services/request.provider.ts
21
+ var request_provider_exports = {};
22
+ __export(request_provider_exports, {
23
+ removeTrailingSlash: () => removeTrailingSlash,
24
+ request: () => request
25
+ });
26
+ module.exports = __toCommonJS(request_provider_exports);
27
+ var request = async (input, init) => {
28
+ const response = await fetch(input, init);
29
+ if (!response.ok) {
30
+ const errorData = await response.json().catch(() => ({}));
31
+ throw new Error(
32
+ JSON.stringify({
33
+ status: response.status,
34
+ statusText: response.statusText,
35
+ ...errorData
36
+ })
37
+ );
38
+ }
39
+ return response && response.json();
40
+ };
41
+ var removeTrailingSlash = (url) => {
42
+ return url.replace(/\/$/, "");
43
+ };
44
+ // Annotate the CommonJS export names for ESM import in node:
45
+ 0 && (module.exports = {
46
+ removeTrailingSlash,
47
+ request
48
+ });
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Makes an HTTP request and returns the response as a JSON object.
3
+ * @param input - The URL or `Request` object for the HTTP request.
4
+ * @param init - The `RequestInit` object that contains additional request options.
5
+ * @returns A promise that resolves to the JSON response body of the HTTP request.
6
+ * @throws {Error} If the response is not successful (status code is not in the 200-299 range).
7
+ * @example
8
+ * const data = await request('https://api.example.com/data');
9
+ * console.log(data);
10
+ * // Output: { ... } (JSON object)
11
+ */
12
+ declare const request: <T>(input: RequestInfo | URL, init?: RequestInit) => Promise<T>;
13
+ /**
14
+ * Removes a trailing slash from a given URL.
15
+ *
16
+ * @param url - The URL from which the trailing slash needs to be removed.
17
+ * @returns The URL with the trailing slash removed.
18
+ *
19
+ * @example
20
+ * const url = 'https://www.example.com/';
21
+ * const result = removeTrailingSlash(url);
22
+ * console.log(result);
23
+ * // Output: 'https://www.example.com'
24
+ */
25
+ declare const removeTrailingSlash: (url: string) => string;
26
+
27
+ export { removeTrailingSlash, request };
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Makes an HTTP request and returns the response as a JSON object.
3
+ * @param input - The URL or `Request` object for the HTTP request.
4
+ * @param init - The `RequestInit` object that contains additional request options.
5
+ * @returns A promise that resolves to the JSON response body of the HTTP request.
6
+ * @throws {Error} If the response is not successful (status code is not in the 200-299 range).
7
+ * @example
8
+ * const data = await request('https://api.example.com/data');
9
+ * console.log(data);
10
+ * // Output: { ... } (JSON object)
11
+ */
12
+ declare const request: <T>(input: RequestInfo | URL, init?: RequestInit) => Promise<T>;
13
+ /**
14
+ * Removes a trailing slash from a given URL.
15
+ *
16
+ * @param url - The URL from which the trailing slash needs to be removed.
17
+ * @returns The URL with the trailing slash removed.
18
+ *
19
+ * @example
20
+ * const url = 'https://www.example.com/';
21
+ * const result = removeTrailingSlash(url);
22
+ * console.log(result);
23
+ * // Output: 'https://www.example.com'
24
+ */
25
+ declare const removeTrailingSlash: (url: string) => string;
26
+
27
+ export { removeTrailingSlash, request };
@@ -0,0 +1,22 @@
1
+ // services/request.provider.ts
2
+ var request = async (input, init) => {
3
+ const response = await fetch(input, init);
4
+ if (!response.ok) {
5
+ const errorData = await response.json().catch(() => ({}));
6
+ throw new Error(
7
+ JSON.stringify({
8
+ status: response.status,
9
+ statusText: response.statusText,
10
+ ...errorData
11
+ })
12
+ );
13
+ }
14
+ return response && response.json();
15
+ };
16
+ var removeTrailingSlash = (url) => {
17
+ return url.replace(/\/$/, "");
18
+ };
19
+ export {
20
+ removeTrailingSlash,
21
+ request
22
+ };