@onlive.ai/common-121 0.2.32 → 0.2.36
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/package.json +2 -4
- package/services/audio.service.cjs +2 -75
- package/services/audio.service.js +2 -52
- package/services/firebase/firebase-api.cjs +2 -108
- package/services/firebase/firebase-api.js +2 -105
- package/services/firebase/firebase.service.cjs +2 -193
- package/services/firebase/firebase.service.js +2 -190
- package/services/livekit.service.cjs +2 -353
- package/services/livekit.service.d.cts +1 -1
- package/services/livekit.service.d.ts +1 -1
- package/services/livekit.service.js +2 -329
- package/services/request.provider.cjs +2 -48
- package/services/request.provider.js +2 -22
- package/themes/dark.cjs +3 -32
- package/themes/dark.js +3 -7
- package/themes/light.cjs +3 -32
- package/themes/light.js +3 -7
- package/types/tracking-options.cjs +2 -18
- package/types/tracking-options.js +1 -0
- package/types/window-context.cjs +2 -18
- package/types/window-context.js +1 -0
- package/utils/adopt-styles.cjs +2 -66
- package/utils/adopt-styles.js +2 -41
- package/utils/browser-preferences.cjs +2 -67
- package/utils/browser-preferences.js +2 -42
- package/utils/classify-media.cjs +2 -38
- package/utils/classify-media.js +2 -13
- package/utils/decorators.cjs +2 -53
- package/utils/decorators.js +2 -28
- package/utils/detected-lang.cjs +2 -47
- package/utils/detected-lang.js +2 -22
- package/utils/fullscreen.cjs +2 -52
- package/utils/fullscreen.js +2 -26
- package/utils/insert-script.cjs +2 -55
- package/utils/insert-script.js +2 -30
- package/utils/markdown.cjs +2 -103
- package/utils/markdown.js +2 -68
- package/utils/merge.cjs +2 -47
- package/utils/merge.js +2 -22
- package/utils/multiband-track-volume.cjs +2 -90
- package/utils/multiband-track-volume.js +2 -65
- package/utils/onlive-url-params.cjs +2 -38
- package/utils/onlive-url-params.js +2 -13
- package/utils/pretty-distance.cjs +2 -45
- package/utils/pretty-distance.js +2 -20
- package/utils/random-string.cjs +2 -37
- package/utils/random-string.js +2 -12
- package/utils/resource-type.cjs +2 -50
- package/utils/resource-type.js +2 -24
- package/utils/safe-html.cjs +2 -112
- package/utils/safe-html.js +2 -77
- package/utils/sanitize.cjs +2 -94
- package/utils/sanitize.js +2 -59
- package/utils/spread.cjs +2 -70
- package/utils/spread.js +2 -47
- package/utils/watch.cjs +2 -54
- package/utils/watch.js +2 -29
- package/vite-env.d.ts +0 -22
|
@@ -1,190 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
-
|
|
5
|
-
// services/firebase/firebase.service.ts
|
|
6
|
-
import { Generator } from "@onlive.ai/tracker";
|
|
7
|
-
|
|
8
|
-
// services/firebase/firebase-api.ts
|
|
9
|
-
import { initializeApp } from "firebase/app";
|
|
10
|
-
import {
|
|
11
|
-
query as dbQuery,
|
|
12
|
-
get,
|
|
13
|
-
getDatabase,
|
|
14
|
-
limitToFirst,
|
|
15
|
-
limitToLast,
|
|
16
|
-
onChildAdded,
|
|
17
|
-
onChildChanged,
|
|
18
|
-
onChildRemoved,
|
|
19
|
-
onDisconnect,
|
|
20
|
-
onValue,
|
|
21
|
-
orderByChild,
|
|
22
|
-
orderByKey,
|
|
23
|
-
orderByValue,
|
|
24
|
-
push,
|
|
25
|
-
ref,
|
|
26
|
-
remove,
|
|
27
|
-
runTransaction,
|
|
28
|
-
set,
|
|
29
|
-
update
|
|
30
|
-
} from "firebase/database";
|
|
31
|
-
var FirebaseApi = class {
|
|
32
|
-
constructor(options) {
|
|
33
|
-
__publicField(this, "db");
|
|
34
|
-
/** Other listeners... */
|
|
35
|
-
__publicField(this, "onChildChanged", (path, cb) => onChildChanged(this.ref(path), (snap) => cb(snap.key, snap.val(), snap)));
|
|
36
|
-
__publicField(this, "onChildRemoved", (path, cb) => onChildRemoved(this.ref(path), (snap) => cb(snap.key, snap.val(), snap)));
|
|
37
|
-
const app = initializeApp(options.config);
|
|
38
|
-
this.db = getDatabase(app);
|
|
39
|
-
}
|
|
40
|
-
/** Get a DatabaseReference */
|
|
41
|
-
ref(path) {
|
|
42
|
-
return ref(this.db, path);
|
|
43
|
-
}
|
|
44
|
-
/** Read once */
|
|
45
|
-
async getOnce(path) {
|
|
46
|
-
const snap = await get(this.ref(path));
|
|
47
|
-
return snap.exists() ? snap.val() : null;
|
|
48
|
-
}
|
|
49
|
-
/** Listen to value changes */
|
|
50
|
-
onValue(path, cb) {
|
|
51
|
-
return onValue(
|
|
52
|
-
this.ref(path),
|
|
53
|
-
(snap) => cb(snap.key ?? "", snap.val(), snap),
|
|
54
|
-
(err) => console.error("onValue error", err)
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
/** Listen to child-added */
|
|
58
|
-
onChildAdded(path, cb) {
|
|
59
|
-
return onChildAdded(
|
|
60
|
-
this.ref(path),
|
|
61
|
-
(snap) => cb(snap.key, snap.val(), snap),
|
|
62
|
-
(err) => console.error("onChildAdded error", err)
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
/** Write/overwrite a node */
|
|
66
|
-
write(path, data) {
|
|
67
|
-
return set(this.ref(path), data);
|
|
68
|
-
}
|
|
69
|
-
/** Update (merge) a node */
|
|
70
|
-
update(path, data) {
|
|
71
|
-
return update(this.ref(path), data);
|
|
72
|
-
}
|
|
73
|
-
/** Remove a node */
|
|
74
|
-
remove(path) {
|
|
75
|
-
return remove(this.ref(path));
|
|
76
|
-
}
|
|
77
|
-
/** Push a child with generated key */
|
|
78
|
-
async push(path, data) {
|
|
79
|
-
const newRef = push(this.ref(path));
|
|
80
|
-
await set(newRef, data);
|
|
81
|
-
return newRef.key;
|
|
82
|
-
}
|
|
83
|
-
/** onDisconnect write */
|
|
84
|
-
onDisconnectUpdate(path, data) {
|
|
85
|
-
return onDisconnect(this.ref(path)).update(data);
|
|
86
|
-
}
|
|
87
|
-
/** Cancel onDisconnect operations */
|
|
88
|
-
cancelOnDisconnect(path) {
|
|
89
|
-
return onDisconnect(this.ref(path)).cancel();
|
|
90
|
-
}
|
|
91
|
-
/** Run a transaction */
|
|
92
|
-
transaction(path, updateFn) {
|
|
93
|
-
return runTransaction(this.ref(path), (cur) => updateFn(cur));
|
|
94
|
-
}
|
|
95
|
-
/** Build a query */
|
|
96
|
-
query(path, opts = {}) {
|
|
97
|
-
let q = this.ref(path);
|
|
98
|
-
if (opts.orderBy === "child" && opts.childKey) q = dbQuery(q, orderByChild(opts.childKey));
|
|
99
|
-
if (opts.orderBy === "key") q = dbQuery(q, orderByKey());
|
|
100
|
-
if (opts.orderBy === "value") q = dbQuery(q, orderByValue());
|
|
101
|
-
if (opts.limitFirst != null) q = dbQuery(q, limitToFirst(opts.limitFirst));
|
|
102
|
-
if (opts.limitLast != null) q = dbQuery(q, limitToLast(opts.limitLast));
|
|
103
|
-
return q;
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
// services/firebase/firebase.service.ts
|
|
108
|
-
var FirebaseService = class {
|
|
109
|
-
constructor(firebaseOptions, orgId) {
|
|
110
|
-
this.firebaseOptions = firebaseOptions;
|
|
111
|
-
this.orgId = orgId;
|
|
112
|
-
__publicField(this, "presencePath");
|
|
113
|
-
__publicField(this, "callsPath");
|
|
114
|
-
__publicField(this, "api");
|
|
115
|
-
this.api = new FirebaseApi({ config: this.firebaseOptions });
|
|
116
|
-
this.presencePath = `orgs/${this.orgId}/presence`;
|
|
117
|
-
this.callsPath = `orgs/${this.orgId}/calls`;
|
|
118
|
-
}
|
|
119
|
-
// Presence methods
|
|
120
|
-
getPresencePath(agentId) {
|
|
121
|
-
return `${this.presencePath}/${agentId}`;
|
|
122
|
-
}
|
|
123
|
-
async setAgentOnline(agentId, displayName) {
|
|
124
|
-
await this.api.write(this.getPresencePath(agentId), {
|
|
125
|
-
status: "online",
|
|
126
|
-
lastSeen: (/* @__PURE__ */ new Date()).toISOString(),
|
|
127
|
-
displayName
|
|
128
|
-
});
|
|
129
|
-
await this.api.onDisconnectUpdate(this.getPresencePath(agentId), {
|
|
130
|
-
status: "offline",
|
|
131
|
-
lastSeen: (/* @__PURE__ */ new Date()).toISOString()
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
onPresenceChange(cb) {
|
|
135
|
-
return this.api.onChildChanged(this.presencePath, (key, data) => cb(key, data));
|
|
136
|
-
}
|
|
137
|
-
onPresenceAgentChange(agentId, cb) {
|
|
138
|
-
return this.api.onValue(
|
|
139
|
-
this.getPresencePath(agentId),
|
|
140
|
-
(key, data) => cb(key, data)
|
|
141
|
-
);
|
|
142
|
-
}
|
|
143
|
-
// Requests methods
|
|
144
|
-
async createRequest(request) {
|
|
145
|
-
const id = Generator.uuid();
|
|
146
|
-
await this.api.write(`${this.callsPath}/${id}`, {
|
|
147
|
-
...request,
|
|
148
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
149
|
-
status: "pending",
|
|
150
|
-
assignedAgentId: null
|
|
151
|
-
});
|
|
152
|
-
this.api.onDisconnectUpdate(`${this.callsPath}/${id}`, {
|
|
153
|
-
status: "disconnected"
|
|
154
|
-
});
|
|
155
|
-
return id;
|
|
156
|
-
}
|
|
157
|
-
onNewRequest(cb) {
|
|
158
|
-
return this.api.onChildAdded(
|
|
159
|
-
this.callsPath,
|
|
160
|
-
(key, data) => cb(key, { ...data, id: key })
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
onRequestChange(cb) {
|
|
164
|
-
return this.api.onChildChanged(
|
|
165
|
-
this.callsPath,
|
|
166
|
-
(key, data) => cb(key, { ...data, id: key })
|
|
167
|
-
);
|
|
168
|
-
}
|
|
169
|
-
onRequestRemoved(cb) {
|
|
170
|
-
return this.api.onChildRemoved(this.callsPath, (key) => cb(key));
|
|
171
|
-
}
|
|
172
|
-
async acceptRequest(requestId) {
|
|
173
|
-
await this.api.cancelOnDisconnect(`${this.callsPath}/${requestId}`);
|
|
174
|
-
return this.api.update(`${this.callsPath}/${requestId}`, {
|
|
175
|
-
status: "accepted"
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
async cancelOnDisconnect(requestId) {
|
|
179
|
-
await this.api.cancelOnDisconnect(`${this.callsPath}/${requestId}`);
|
|
180
|
-
}
|
|
181
|
-
async cancelRequest(requestId) {
|
|
182
|
-
await this.api.cancelOnDisconnect(`${this.callsPath}/${requestId}`);
|
|
183
|
-
return this.api.update(`${this.callsPath}/${requestId}`, {
|
|
184
|
-
status: "cancelled"
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
export {
|
|
189
|
-
FirebaseService
|
|
190
|
-
};
|
|
1
|
+
/*! @onlive.ai/common-121 v0.2.36 | © 2025 onlive.ai */
|
|
2
|
+
var g=Object.defineProperty;var h=(n,e,t)=>e in n?g(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var s=(n,e,t)=>h(n,typeof e!="symbol"?e+"":e,t);import{Generator as O}from"@onlive.ai/tracker";import{initializeApp as u}from"firebase/app";import{query as r,get as p,getDatabase as y,limitToFirst as m,limitToLast as f,onChildAdded as P,onChildChanged as b,onChildRemoved as v,onDisconnect as o,onValue as C,orderByChild as T,orderByKey as R,orderByValue as D,push as $,ref as w,remove as A,runTransaction as q,set as c,update as I}from"firebase/database";var a=class{constructor(e){s(this,"db");s(this,"onChildChanged",(e,t)=>b(this.ref(e),i=>t(i.key,i.val(),i)));s(this,"onChildRemoved",(e,t)=>v(this.ref(e),i=>t(i.key,i.val(),i)));let t=u(e.config);this.db=y(t)}ref(e){return w(this.db,e)}async getOnce(e){let t=await p(this.ref(e));return t.exists()?t.val():null}onValue(e,t){return C(this.ref(e),i=>t(i.key??"",i.val(),i),i=>console.error("onValue error",i))}onChildAdded(e,t){return P(this.ref(e),i=>t(i.key,i.val(),i),i=>console.error("onChildAdded error",i))}write(e,t){return c(this.ref(e),t)}update(e,t){return I(this.ref(e),t)}remove(e){return A(this.ref(e))}async push(e,t){let i=$(this.ref(e));return await c(i,t),i.key}onDisconnectUpdate(e,t){return o(this.ref(e)).update(t)}cancelOnDisconnect(e){return o(this.ref(e)).cancel()}transaction(e,t){return q(this.ref(e),i=>t(i))}query(e,t={}){let i=this.ref(e);return t.orderBy==="child"&&t.childKey&&(i=r(i,T(t.childKey))),t.orderBy==="key"&&(i=r(i,R())),t.orderBy==="value"&&(i=r(i,D())),t.limitFirst!=null&&(i=r(i,m(t.limitFirst))),t.limitLast!=null&&(i=r(i,f(t.limitLast))),i}};var l=class{constructor(e,t){this.firebaseOptions=e;this.orgId=t;s(this,"presencePath");s(this,"callsPath");s(this,"api");this.api=new a({config:this.firebaseOptions}),this.presencePath=`orgs/${this.orgId}/presence`,this.callsPath=`orgs/${this.orgId}/calls`}getPresencePath(e){return`${this.presencePath}/${e}`}async setAgentOnline(e,t){await this.api.write(this.getPresencePath(e),{status:"online",lastSeen:new Date().toISOString(),displayName:t}),await this.api.onDisconnectUpdate(this.getPresencePath(e),{status:"offline",lastSeen:new Date().toISOString()})}onPresenceChange(e){return this.api.onChildChanged(this.presencePath,(t,i)=>e(t,i))}onPresenceAgentChange(e,t){return this.api.onValue(this.getPresencePath(e),(i,d)=>t(i,d))}async createRequest(e){let t=O.uuid();return await this.api.write(`${this.callsPath}/${t}`,{...e,createdAt:new Date().toISOString(),status:"pending",assignedAgentId:null}),this.api.onDisconnectUpdate(`${this.callsPath}/${t}`,{status:"disconnected"}),t}onNewRequest(e){return this.api.onChildAdded(this.callsPath,(t,i)=>e(t,{...i,id:t}))}onRequestChange(e){return this.api.onChildChanged(this.callsPath,(t,i)=>e(t,{...i,id:t}))}onRequestRemoved(e){return this.api.onChildRemoved(this.callsPath,t=>e(t))}async acceptRequest(e){return await this.api.cancelOnDisconnect(`${this.callsPath}/${e}`),this.api.update(`${this.callsPath}/${e}`,{status:"accepted"})}async cancelOnDisconnect(e){await this.api.cancelOnDisconnect(`${this.callsPath}/${e}`)}async cancelRequest(e){return await this.api.cancelOnDisconnect(`${this.callsPath}/${e}`),this.api.update(`${this.callsPath}/${e}`,{status:"cancelled"})}};export{l as FirebaseService};
|
|
@@ -1,353 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
21
|
-
|
|
22
|
-
// services/livekit.service.ts
|
|
23
|
-
var livekit_service_exports = {};
|
|
24
|
-
__export(livekit_service_exports, {
|
|
25
|
-
CHAT_TOPIC: () => CHAT_TOPIC,
|
|
26
|
-
LivekitService: () => LivekitService,
|
|
27
|
-
Room: () => Room,
|
|
28
|
-
TRANSCRIPTION_TOPIC: () => TRANSCRIPTION_TOPIC
|
|
29
|
-
});
|
|
30
|
-
module.exports = __toCommonJS(livekit_service_exports);
|
|
31
|
-
var import_components_core = require("@livekit/components-core");
|
|
32
|
-
var import_livekit_client = require("livekit-client");
|
|
33
|
-
|
|
34
|
-
// services/request.provider.ts
|
|
35
|
-
var request = async (input, init) => {
|
|
36
|
-
const response = await fetch(input, init);
|
|
37
|
-
if (!response.ok) {
|
|
38
|
-
const errorData = await response.json().catch(() => ({}));
|
|
39
|
-
throw new Error(
|
|
40
|
-
JSON.stringify({
|
|
41
|
-
status: response.status,
|
|
42
|
-
statusText: response.statusText,
|
|
43
|
-
...errorData
|
|
44
|
-
})
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
return response && response.json();
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
// services/livekit.service.ts
|
|
51
|
-
var Room = class extends import_livekit_client.Room {
|
|
52
|
-
constructor(options) {
|
|
53
|
-
super(options);
|
|
54
|
-
__publicField(this, "id");
|
|
55
|
-
__publicField(this, "groupId");
|
|
56
|
-
__publicField(this, "createdAt");
|
|
57
|
-
__publicField(this, "connectedAt");
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
var CHAT_TOPIC = "lk.chat";
|
|
61
|
-
var TRANSCRIPTION_TOPIC = "lk.transcription";
|
|
62
|
-
var LivekitService = class {
|
|
63
|
-
constructor(options) {
|
|
64
|
-
__publicField(this, "listeners", /* @__PURE__ */ new Set());
|
|
65
|
-
__publicField(this, "apiUrl");
|
|
66
|
-
__publicField(this, "version");
|
|
67
|
-
__publicField(this, "organizationId");
|
|
68
|
-
__publicField(this, "channelTopic");
|
|
69
|
-
__publicField(this, "transcriptionTopic");
|
|
70
|
-
__publicField(this, "setupChat");
|
|
71
|
-
__publicField(this, "abortControllers");
|
|
72
|
-
__publicField(this, "authToken", null);
|
|
73
|
-
__publicField(this, "messagePersistence");
|
|
74
|
-
__publicField(this, "room");
|
|
75
|
-
__publicField(this, "processMessage", async (reader, participantInfo) => {
|
|
76
|
-
const id = reader?.info?.id;
|
|
77
|
-
const participant = participantInfo?.identity ? this.room.getParticipantByIdentity(participantInfo.identity) : void 0;
|
|
78
|
-
let message = "";
|
|
79
|
-
for await (const chunk of reader) {
|
|
80
|
-
message += chunk;
|
|
81
|
-
this.emitMessage({
|
|
82
|
-
id,
|
|
83
|
-
timestamp: Date.now(),
|
|
84
|
-
message,
|
|
85
|
-
from: participant
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
if (this.messagePersistence === "client") {
|
|
89
|
-
this.persistMessage({
|
|
90
|
-
roomId: this.room.id,
|
|
91
|
-
content: message,
|
|
92
|
-
externalId: reader?.info?.id,
|
|
93
|
-
identity: participant?.identity,
|
|
94
|
-
kind: participant?.kind
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
__publicField(this, "emitMessage", (message) => {
|
|
99
|
-
for (const cb of this.listeners) {
|
|
100
|
-
cb([message]);
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
if ("room" in options) {
|
|
104
|
-
this.room = options.room;
|
|
105
|
-
} else {
|
|
106
|
-
this.apiUrl = options.apiUrl;
|
|
107
|
-
this.room = this.instanceRoom();
|
|
108
|
-
}
|
|
109
|
-
this.organizationId = options.organizationId;
|
|
110
|
-
this.version = options.version;
|
|
111
|
-
this.channelTopic = options.channelTopic || CHAT_TOPIC;
|
|
112
|
-
this.transcriptionTopic = options.transcriptionTopic || TRANSCRIPTION_TOPIC;
|
|
113
|
-
this.messagePersistence = options.messagePersistence || "disabled";
|
|
114
|
-
this.abortControllers = {
|
|
115
|
-
register: new AbortController(),
|
|
116
|
-
createRoom: new AbortController(),
|
|
117
|
-
closeRoom: new AbortController(),
|
|
118
|
-
evaluateRoom: new AbortController(),
|
|
119
|
-
persistMessage: new AbortController(),
|
|
120
|
-
sendMessageReport: new AbortController(),
|
|
121
|
-
deleteMessageReport: new AbortController(),
|
|
122
|
-
updateMessageReactions: new AbortController()
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
initialize() {
|
|
126
|
-
if (this.version === "v1") {
|
|
127
|
-
this.room.registerTextStreamHandler(this.channelTopic, this.processMessage);
|
|
128
|
-
this.room.registerTextStreamHandler(this.transcriptionTopic, this.processMessage);
|
|
129
|
-
} else {
|
|
130
|
-
this.setupChat = (0, import_components_core.setupChat)(this.room);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
async register(externalId, secret, name) {
|
|
134
|
-
const response = await request(`${this.apiUrl}/users/register`, {
|
|
135
|
-
method: "POST",
|
|
136
|
-
body: JSON.stringify({
|
|
137
|
-
externalId,
|
|
138
|
-
secret,
|
|
139
|
-
name
|
|
140
|
-
}),
|
|
141
|
-
headers: {
|
|
142
|
-
"X-Onlive-Organization-Id": this.organizationId,
|
|
143
|
-
"Content-Type": "application/json"
|
|
144
|
-
},
|
|
145
|
-
signal: this.abortControllers.register.signal
|
|
146
|
-
});
|
|
147
|
-
this.authToken = response.token;
|
|
148
|
-
return response;
|
|
149
|
-
}
|
|
150
|
-
async joinRoom(roomId, timezone, language) {
|
|
151
|
-
const response = await request(`${this.apiUrl}/rooms/${roomId}/join`, {
|
|
152
|
-
method: "POST",
|
|
153
|
-
body: JSON.stringify({ timezone, language }),
|
|
154
|
-
headers: {
|
|
155
|
-
Authorization: `Bearer ${this.authToken}`,
|
|
156
|
-
"X-Onlive-Organization-Id": this.organizationId,
|
|
157
|
-
"Content-Type": "application/json"
|
|
158
|
-
},
|
|
159
|
-
signal: this.abortControllers.createRoom.signal
|
|
160
|
-
});
|
|
161
|
-
this.room.connect(response.wsURL, response.token);
|
|
162
|
-
this.initialize();
|
|
163
|
-
return this.room;
|
|
164
|
-
}
|
|
165
|
-
instanceRoom() {
|
|
166
|
-
if (!this.room) {
|
|
167
|
-
this.room = new Room({
|
|
168
|
-
adaptiveStream: true,
|
|
169
|
-
dynacast: true
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
return this.room;
|
|
173
|
-
}
|
|
174
|
-
async createRoom(options) {
|
|
175
|
-
this.room = this.instanceRoom();
|
|
176
|
-
const response = await request(`${this.apiUrl}/rooms`, {
|
|
177
|
-
method: "POST",
|
|
178
|
-
body: JSON.stringify(options),
|
|
179
|
-
headers: {
|
|
180
|
-
Authorization: `Bearer ${this.authToken}`,
|
|
181
|
-
"X-Onlive-Organization-Id": this.organizationId,
|
|
182
|
-
"Content-Type": "application/json"
|
|
183
|
-
},
|
|
184
|
-
signal: this.abortControllers.createRoom.signal
|
|
185
|
-
});
|
|
186
|
-
this.room.id = response.id;
|
|
187
|
-
this.room.groupId = response.groupId;
|
|
188
|
-
this.room.createdAt = response.createdAt;
|
|
189
|
-
this.room.connectedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
190
|
-
this.room.connect(response.wsURL, response.token);
|
|
191
|
-
this.initialize();
|
|
192
|
-
return this.room;
|
|
193
|
-
}
|
|
194
|
-
async evaluateRoom(options) {
|
|
195
|
-
return request(`${this.apiUrl}/rooms/${this.room.id}/evaluate`, {
|
|
196
|
-
method: "POST",
|
|
197
|
-
body: JSON.stringify({
|
|
198
|
-
rating: options.rating,
|
|
199
|
-
comment: options.comment
|
|
200
|
-
}),
|
|
201
|
-
headers: {
|
|
202
|
-
Authorization: `Bearer ${this.authToken}`,
|
|
203
|
-
"X-Onlive-Organization-Id": this.organizationId,
|
|
204
|
-
"Content-Type": "application/json"
|
|
205
|
-
},
|
|
206
|
-
signal: this.abortControllers.evaluateRoom.signal
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
async closeRoom() {
|
|
210
|
-
return request(`${this.apiUrl}/rooms/${this.room.id}/close`, {
|
|
211
|
-
method: "POST",
|
|
212
|
-
headers: {
|
|
213
|
-
Authorization: `Bearer ${this.authToken}`,
|
|
214
|
-
"X-Onlive-Organization-Id": this.organizationId,
|
|
215
|
-
"Content-Type": "application/json"
|
|
216
|
-
},
|
|
217
|
-
signal: this.abortControllers.closeRoom.signal
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
async disconnect() {
|
|
221
|
-
if (this.room) {
|
|
222
|
-
this.room.removeAllListeners();
|
|
223
|
-
await this.room.disconnect();
|
|
224
|
-
this.closeRoom();
|
|
225
|
-
this.room = null;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
async sendMessage(message) {
|
|
229
|
-
if (this.version === "v1") {
|
|
230
|
-
const textStream = await this.room.localParticipant.sendText(message, {
|
|
231
|
-
topic: this.channelTopic
|
|
232
|
-
});
|
|
233
|
-
this.emitMessage({
|
|
234
|
-
id: textStream.id,
|
|
235
|
-
timestamp: Date.now(),
|
|
236
|
-
message,
|
|
237
|
-
from: this.room.localParticipant
|
|
238
|
-
});
|
|
239
|
-
if (this.messagePersistence === "client") {
|
|
240
|
-
this.persistMessage({
|
|
241
|
-
roomId: this.room.id,
|
|
242
|
-
content: message,
|
|
243
|
-
externalId: textStream.id,
|
|
244
|
-
identity: this.room.localParticipant?.identity,
|
|
245
|
-
kind: this.room.localParticipant?.kind
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
} else {
|
|
249
|
-
await this.setupChat.send(message);
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
async persistMessage(options) {
|
|
253
|
-
return request(`${this.apiUrl}/messages/create`, {
|
|
254
|
-
method: "POST",
|
|
255
|
-
body: JSON.stringify(options),
|
|
256
|
-
headers: {
|
|
257
|
-
Authorization: `Bearer ${this.authToken}`,
|
|
258
|
-
"X-Onlive-Organization-Id": this.organizationId,
|
|
259
|
-
"Content-Type": "application/json"
|
|
260
|
-
},
|
|
261
|
-
signal: this.abortControllers.persistMessage.signal
|
|
262
|
-
});
|
|
263
|
-
}
|
|
264
|
-
async getMessages(options) {
|
|
265
|
-
const query = new URLSearchParams();
|
|
266
|
-
if (options.with) {
|
|
267
|
-
query.append("with", options.with.join(","));
|
|
268
|
-
}
|
|
269
|
-
const response = await request(
|
|
270
|
-
`${this.apiUrl}/messages/search${query.size ? `?${query.toString()}` : ""}`,
|
|
271
|
-
{
|
|
272
|
-
method: "POST",
|
|
273
|
-
body: JSON.stringify(options),
|
|
274
|
-
headers: {
|
|
275
|
-
Authorization: `Bearer ${this.authToken}`,
|
|
276
|
-
"X-Onlive-Organization-Id": this.organizationId,
|
|
277
|
-
"Content-Type": "application/json"
|
|
278
|
-
},
|
|
279
|
-
signal: this.abortControllers.createRoom.signal
|
|
280
|
-
}
|
|
281
|
-
);
|
|
282
|
-
return response.items;
|
|
283
|
-
}
|
|
284
|
-
async sendMessageReport(options) {
|
|
285
|
-
try {
|
|
286
|
-
return request(`${this.apiUrl}/messages/${options.messageId}/report`, {
|
|
287
|
-
method: "POST",
|
|
288
|
-
headers: {
|
|
289
|
-
Authorization: `Bearer ${this.authToken}`,
|
|
290
|
-
"X-Onlive-Organization-Id": this.organizationId,
|
|
291
|
-
"Content-Type": "application/json"
|
|
292
|
-
},
|
|
293
|
-
signal: this.abortControllers.sendMessageReport.signal
|
|
294
|
-
});
|
|
295
|
-
} catch (error) {
|
|
296
|
-
console.error("Error sending message report:", error);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
async deleteMessageReport(options) {
|
|
300
|
-
try {
|
|
301
|
-
return request(`${this.apiUrl}/messages/${options.messageId}/report`, {
|
|
302
|
-
method: "DELETE",
|
|
303
|
-
headers: {
|
|
304
|
-
Authorization: `Bearer ${this.authToken}`,
|
|
305
|
-
"X-Onlive-Organization-Id": this.organizationId,
|
|
306
|
-
"Content-Type": "application/json"
|
|
307
|
-
},
|
|
308
|
-
signal: this.abortControllers.deleteMessageReport.signal
|
|
309
|
-
});
|
|
310
|
-
} catch (error) {
|
|
311
|
-
console.error("Error deleting message report:", error);
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
async updateMessageReactions(options) {
|
|
315
|
-
try {
|
|
316
|
-
return request(`${this.apiUrl}/messages/${options.messageId}/reactions`, {
|
|
317
|
-
method: "PATCH",
|
|
318
|
-
body: JSON.stringify({
|
|
319
|
-
add: options.add || [],
|
|
320
|
-
remove: options.remove || []
|
|
321
|
-
}),
|
|
322
|
-
headers: {
|
|
323
|
-
Authorization: `Bearer ${this.authToken}`,
|
|
324
|
-
"X-Onlive-Organization-Id": this.organizationId,
|
|
325
|
-
"Content-Type": "application/json"
|
|
326
|
-
},
|
|
327
|
-
signal: this.abortControllers.updateMessageReactions.signal
|
|
328
|
-
});
|
|
329
|
-
} catch (error) {
|
|
330
|
-
console.error("Error updating message reactions:", error);
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
subscribeMessages(callback) {
|
|
334
|
-
if (this.version === "v1") {
|
|
335
|
-
this.listeners.add(callback);
|
|
336
|
-
return () => {
|
|
337
|
-
this.listeners.delete(callback);
|
|
338
|
-
};
|
|
339
|
-
} else {
|
|
340
|
-
const subscription = this.setupChat.messageObservable.subscribe(
|
|
341
|
-
callback
|
|
342
|
-
);
|
|
343
|
-
return () => subscription.unsubscribe();
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
};
|
|
347
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
348
|
-
0 && (module.exports = {
|
|
349
|
-
CHAT_TOPIC,
|
|
350
|
-
LivekitService,
|
|
351
|
-
Room,
|
|
352
|
-
TRANSCRIPTION_TOPIC
|
|
353
|
-
});
|
|
1
|
+
/*! @onlive.ai/common-121 v0.2.36 | © 2025 onlive.ai */
|
|
2
|
+
"use strict";var a=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var v=Object.prototype.hasOwnProperty;var M=(i,e,t)=>e in i?a(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var O=(i,e)=>{for(var t in e)a(i,t,{get:e[t],enumerable:!0})},T=(i,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of y(e))!v.call(i,o)&&o!==t&&a(i,o,{get:()=>e[o],enumerable:!(r=R(e,o))||r.enumerable});return i};var A=i=>T(a({},"__esModule",{value:!0}),i);var s=(i,e,t)=>M(i,typeof e!="symbol"?e+"":e,t);var C={};O(C,{CHAT_TOPIC:()=>d,LivekitService:()=>l,Room:()=>g,TRANSCRIPTION_TOPIC:()=>m});module.exports=A(C);var c=require("@livekit/components-core"),h=require("livekit-client");var n=async(i,e)=>{let t=await fetch(i,e);if(!t.ok){let r=await t.json().catch(()=>({}));throw new Error(JSON.stringify({status:t.status,statusText:t.statusText,...r}))}return t&&t.json()};var g=class extends h.Room{constructor(t){super(t);s(this,"id");s(this,"groupId");s(this,"createdAt");s(this,"connectedAt")}},d="lk.chat",m="lk.transcription",l=class{constructor(e){s(this,"listeners",new Set);s(this,"apiUrl");s(this,"version");s(this,"organizationId");s(this,"channelTopic");s(this,"transcriptionTopic");s(this,"setupChat");s(this,"abortControllers");s(this,"authToken",null);s(this,"messagePersistence");s(this,"room");s(this,"processMessage",async(e,t)=>{let r=e?.info?.id,o=t?.identity?this.room.getParticipantByIdentity(t.identity):void 0,p="";for await(let u of e)p+=u,this.emitMessage({id:r,timestamp:Date.now(),message:p,from:o});this.messagePersistence==="client"&&this.persistMessage({roomId:this.room.id,content:p,externalId:e?.info?.id,identity:o?.identity,kind:o?.kind})});s(this,"emitMessage",e=>{for(let t of this.listeners)t([e])});"room"in e?this.room=e.room:(this.apiUrl=e.apiUrl,this.room=this.instanceRoom()),this.organizationId=e.organizationId,this.version=e.version,this.channelTopic=e.channelTopic||d,this.transcriptionTopic=e.transcriptionTopic||m,this.messagePersistence=e.messagePersistence||"disabled",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}}initialize(){this.version==="v1"?(this.room.registerTextStreamHandler(this.channelTopic,this.processMessage),this.room.registerTextStreamHandler(this.transcriptionTopic,this.processMessage)):this.setupChat=(0,c.setupChat)(this.room)}async register(e,t,r){let o=await n(`${this.apiUrl}/users/register`,{method:"POST",body:JSON.stringify({externalId:e,secret:t,name:r}),headers:{"X-Onlive-Organization-Id":this.organizationId,"Content-Type":"application/json"},signal:this.abortControllers.register.signal});return this.authToken=o.token,o}async joinRoom(e,t,r){let o=await n(`${this.apiUrl}/rooms/${e}/join`,{method:"POST",body:JSON.stringify({timezone:t,language:r}),headers:{Authorization:`Bearer ${this.authToken}`,"X-Onlive-Organization-Id":this.organizationId,"Content-Type":"application/json"},signal:this.abortControllers.createRoom.signal});return this.room.connect(o.wsURL,o.token),this.initialize(),this.room}instanceRoom(){return this.room||(this.room=new g({adaptiveStream:!0,dynacast:!0})),this.room}async createRoom(e){this.room=this.instanceRoom();let t=await n(`${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.room.id=t.id,this.room.groupId=t.groupId,this.room.createdAt=t.createdAt,this.room.connectedAt=new Date().toISOString(),this.room.connect(t.wsURL,t.token),this.initialize(),this.room}async evaluateRoom(e){return n(`${this.apiUrl}/rooms/${this.room.id}/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(){return n(`${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.closeRoom(),this.room=null)}async sendMessage(e){if(this.version==="v1"){let t=await this.room.localParticipant.sendText(e,{topic:this.channelTopic});this.emitMessage({id:t.id,timestamp:Date.now(),message:e,from:this.room.localParticipant}),this.messagePersistence==="client"&&this.persistMessage({roomId:this.room.id,content:e,externalId:t.id,identity:this.room.localParticipant?.identity,kind:this.room.localParticipant?.kind})}else await this.setupChat.send(e)}async persistMessage(e){return n(`${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.with&&t.append("with",e.with.join(",")),(await n(`${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 n(`${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 n(`${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 n(`${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){if(this.version==="v1")return this.listeners.add(e),()=>{this.listeners.delete(e)};{let t=this.setupChat.messageObservable.subscribe(e);return()=>t.unsubscribe()}}};0&&(module.exports={CHAT_TOPIC,LivekitService,Room,TRANSCRIPTION_TOPIC});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ReceivedChatMessage } from '@livekit/components-core';
|
|
2
|
-
import {
|
|
2
|
+
import { RoomOptions as RoomOptions$1, Room as Room$1, Participant } from 'livekit-client';
|
|
3
3
|
|
|
4
4
|
interface RoomOptions extends Partial<RoomOptions$1> {
|
|
5
5
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ReceivedChatMessage } from '@livekit/components-core';
|
|
2
|
-
import {
|
|
2
|
+
import { RoomOptions as RoomOptions$1, Room as Room$1, Participant } from 'livekit-client';
|
|
3
3
|
|
|
4
4
|
interface RoomOptions extends Partial<RoomOptions$1> {
|
|
5
5
|
}
|