@d-id/client-sdk 1.1.27 → 1.1.28-staging.129
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
class
|
|
5
|
-
constructor({ kind:
|
|
6
|
-
super(JSON.stringify({ kind:
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
this.kind =
|
|
1
|
+
var He = Object.defineProperty;
|
|
2
|
+
var Qe = (e, t, a) => t in e ? He(e, t, { enumerable: !0, configurable: !0, writable: !0, value: a }) : e[t] = a;
|
|
3
|
+
var me = (e, t, a) => Qe(e, typeof t != "symbol" ? t + "" : t, a);
|
|
4
|
+
class we extends Error {
|
|
5
|
+
constructor({ kind: a, description: n, error: c }) {
|
|
6
|
+
super(JSON.stringify({ kind: a, description: n }));
|
|
7
|
+
me(this, "kind");
|
|
8
|
+
me(this, "description");
|
|
9
|
+
me(this, "error");
|
|
10
|
+
this.kind = a, this.description = n, this.error = c;
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
class
|
|
14
|
-
constructor(t,
|
|
13
|
+
class Xe extends we {
|
|
14
|
+
constructor(t, a) {
|
|
15
15
|
super({
|
|
16
16
|
kind: "ChatCreationFailed",
|
|
17
|
-
description: `Failed to create ${
|
|
17
|
+
description: `Failed to create ${a ? "persistent" : ""} chat, mode: ${t}`
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
class
|
|
21
|
+
class Ye extends we {
|
|
22
22
|
constructor(t) {
|
|
23
23
|
super({ kind: "ChatModeDowngraded", description: `Chat mode downgraded to ${t}` });
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
class
|
|
27
|
-
constructor(
|
|
28
|
-
super({ kind: "ValidationError", description:
|
|
29
|
-
|
|
26
|
+
class de extends we {
|
|
27
|
+
constructor(a, n) {
|
|
28
|
+
super({ kind: "ValidationError", description: a });
|
|
29
|
+
me(this, "key");
|
|
30
30
|
this.key = n;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
class
|
|
33
|
+
class Ge extends we {
|
|
34
34
|
constructor(t) {
|
|
35
35
|
super({ kind: "WSError", description: t });
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
var
|
|
39
|
-
const
|
|
38
|
+
var Ze = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(Ze || {}), et = /* @__PURE__ */ ((e) => (e.TRIAL = "deid-trial", e.PRO = "deid-pro", e.ENTERPRISE = "deid-enterprise", e.LITE = "deid-lite", e.ADVANCED = "deid-advanced", e.BUILD = "deid-api-build", e.LAUNCH = "deid-api-launch", e.SCALE = "deid-api-scale", e))(et || {}), tt = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(tt || {}), nt = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(nt || {}), F = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(F || {}), Y = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(Y || {}), rt = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(rt || {}), it = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(it || {}), at = /* @__PURE__ */ ((e) => (e.Pdf = "pdf", e.Text = "text", e.Html = "html", e.Word = "word", e.Json = "json", e.Markdown = "markdown", e.Csv = "csv", e.Excel = "excel", e.Powerpoint = "powerpoint", e.Archive = "archive", e.Image = "image", e.Audio = "audio", e.Video = "video", e))(at || {}), Ne = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(Ne || {});
|
|
39
|
+
const fn = (e) => {
|
|
40
40
|
switch (e) {
|
|
41
41
|
case "clip":
|
|
42
42
|
return "clip";
|
|
@@ -48,22 +48,22 @@ const dn = (e) => {
|
|
|
48
48
|
throw new Error(`Unknown video type: ${e}`);
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
|
-
var C = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(C || {}),
|
|
52
|
-
const
|
|
51
|
+
var C = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(C || {}), re = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(re || {}), J = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Loading = "LOADING", e.Talking = "TALKING", e))(J || {}), x = /* @__PURE__ */ ((e) => (e.ChatAnswer = "chat/answer", e.ChatPartial = "chat/partial", e.ChatAudioTranscribed = "chat/audio-transcribed", e.StreamDone = "stream/done", e.StreamStarted = "stream/started", e.StreamFailed = "stream/error", e.StreamReady = "stream/ready", e.StreamCreated = "stream/created", e.StreamInterrupt = "stream/interrupt", e.StreamVideoCreated = "stream-video/started", e.StreamVideoDone = "stream-video/done", e.StreamVideoError = "stream-video/error", e.StreamVideoRejected = "stream-video/rejected", e))(x || {}), S = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnected = "disconnected", e))(S || {}), ae = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(ae || {}), ye = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(ye || {}), ot = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(ot || {}), st = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(st || {});
|
|
52
|
+
const ct = 45 * 1e3, dt = "X-Playground-Chat", he = "https://api.d-id.com", ut = "wss://notifications.d-id.com", lt = "79f81a83a67430be2bc0fd61042b8faa", Ke = (e) => new Promise((t) => setTimeout(t, e)), ue = (e = 16) => {
|
|
53
53
|
const t = new Uint8Array(e);
|
|
54
|
-
return window.crypto.getRandomValues(t), Array.from(t, (
|
|
55
|
-
},
|
|
56
|
-
function
|
|
57
|
-
let
|
|
54
|
+
return window.crypto.getRandomValues(t), Array.from(t, (a) => a.toString(16).padStart(2, "0")).join("").slice(0, 13);
|
|
55
|
+
}, Je = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type, Ie = (e) => e === Ne.Expressive, ft = (e) => [F.TextOnly, F.Playground, F.Maintenance].includes(e), Ue = (e) => e && [F.DirectPlayback, F.Off].includes(e);
|
|
56
|
+
function mt(e, t) {
|
|
57
|
+
let a;
|
|
58
58
|
return {
|
|
59
59
|
promise: new Promise((c, o) => {
|
|
60
|
-
|
|
60
|
+
a = setTimeout(() => o(new Error(t)), e);
|
|
61
61
|
}),
|
|
62
|
-
clear: () => clearTimeout(
|
|
62
|
+
clear: () => clearTimeout(a)
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
|
-
async function
|
|
66
|
-
const
|
|
65
|
+
async function Ce(e, t) {
|
|
66
|
+
const a = {
|
|
67
67
|
limit: (t == null ? void 0 : t.limit) ?? 3,
|
|
68
68
|
delayMs: (t == null ? void 0 : t.delayMs) ?? 0,
|
|
69
69
|
timeout: (t == null ? void 0 : t.timeout) ?? 3e4,
|
|
@@ -73,61 +73,61 @@ async function ve(e, t) {
|
|
|
73
73
|
})
|
|
74
74
|
};
|
|
75
75
|
let n;
|
|
76
|
-
for (let c = 1; c <=
|
|
76
|
+
for (let c = 1; c <= a.limit; c++)
|
|
77
77
|
try {
|
|
78
|
-
if (!
|
|
78
|
+
if (!a.timeout)
|
|
79
79
|
return await e();
|
|
80
|
-
const { promise: o, clear: s } =
|
|
81
|
-
return await Promise.race([
|
|
80
|
+
const { promise: o, clear: s } = mt(a.timeout, a.timeoutErrorMessage), i = e().finally(s);
|
|
81
|
+
return await Promise.race([i, o]);
|
|
82
82
|
} catch (o) {
|
|
83
|
-
if (n = o, !
|
|
83
|
+
if (n = o, !a.shouldRetryFn(o) || c >= a.limit)
|
|
84
84
|
throw o;
|
|
85
|
-
await
|
|
85
|
+
await Ke(a.delayMs), a.onRetry(o);
|
|
86
86
|
}
|
|
87
87
|
throw n;
|
|
88
88
|
}
|
|
89
|
-
function
|
|
89
|
+
function ke(e) {
|
|
90
90
|
if (e !== void 0)
|
|
91
91
|
return window.localStorage.setItem("did_external_key_id", e), e;
|
|
92
92
|
let t = window.localStorage.getItem("did_external_key_id");
|
|
93
93
|
if (!t) {
|
|
94
|
-
let
|
|
95
|
-
window.localStorage.setItem("did_external_key_id",
|
|
94
|
+
let a = ue();
|
|
95
|
+
window.localStorage.setItem("did_external_key_id", a), t = a;
|
|
96
96
|
}
|
|
97
97
|
return t;
|
|
98
98
|
}
|
|
99
|
-
let
|
|
100
|
-
function
|
|
99
|
+
let gt = ue();
|
|
100
|
+
function We(e, t) {
|
|
101
101
|
if (e.type === "bearer")
|
|
102
102
|
return `Bearer ${e.token}`;
|
|
103
103
|
if (e.type === "basic")
|
|
104
104
|
return `Basic ${btoa(`${e.username}:${e.password}`)}`;
|
|
105
105
|
if (e.type === "key")
|
|
106
|
-
return `Client-Key ${e.clientKey}.${
|
|
106
|
+
return `Client-Key ${e.clientKey}.${ke(t)}_${gt}`;
|
|
107
107
|
throw new Error(`Unknown auth type: ${e}`);
|
|
108
108
|
}
|
|
109
|
-
const
|
|
109
|
+
const ht = (e) => Ce(e, {
|
|
110
110
|
limit: 3,
|
|
111
111
|
delayMs: 1e3,
|
|
112
112
|
timeout: 0,
|
|
113
113
|
shouldRetryFn: (t) => t.status === 429
|
|
114
114
|
});
|
|
115
|
-
function
|
|
115
|
+
function Te(e, t = he, a, n) {
|
|
116
116
|
const c = async (o, s) => {
|
|
117
|
-
const { skipErrorHandler:
|
|
117
|
+
const { skipErrorHandler: i, ...r } = s || {}, d = await ht(
|
|
118
118
|
() => fetch(t + (o != null && o.startsWith("/") ? o : `/${o}`), {
|
|
119
119
|
...r,
|
|
120
120
|
headers: {
|
|
121
121
|
...r.headers,
|
|
122
|
-
Authorization:
|
|
122
|
+
Authorization: We(e, n),
|
|
123
123
|
"Content-Type": "application/json"
|
|
124
124
|
}
|
|
125
125
|
})
|
|
126
126
|
);
|
|
127
127
|
if (!d.ok) {
|
|
128
|
-
let
|
|
129
|
-
const
|
|
130
|
-
throw
|
|
128
|
+
let g = await d.text().catch(() => `Failed to fetch with status ${d.status}`);
|
|
129
|
+
const w = new Error(g);
|
|
130
|
+
throw a && !i && a(w, { url: o, options: r, headers: d.headers }), w;
|
|
131
131
|
}
|
|
132
132
|
return d.json();
|
|
133
133
|
};
|
|
@@ -135,25 +135,25 @@ function Me(e, t = fe, i, n) {
|
|
|
135
135
|
get(o, s) {
|
|
136
136
|
return c(o, { ...s, method: "GET" });
|
|
137
137
|
},
|
|
138
|
-
post(o, s,
|
|
139
|
-
return c(o, { ...
|
|
138
|
+
post(o, s, i) {
|
|
139
|
+
return c(o, { ...i, body: JSON.stringify(s), method: "POST" });
|
|
140
140
|
},
|
|
141
|
-
delete(o, s,
|
|
142
|
-
return c(o, { ...
|
|
141
|
+
delete(o, s, i) {
|
|
142
|
+
return c(o, { ...i, body: JSON.stringify(s), method: "DELETE" });
|
|
143
143
|
},
|
|
144
|
-
patch(o, s,
|
|
145
|
-
return c(o, { ...
|
|
144
|
+
patch(o, s, i) {
|
|
145
|
+
return c(o, { ...i, body: JSON.stringify(s), method: "PATCH" });
|
|
146
146
|
}
|
|
147
147
|
};
|
|
148
148
|
}
|
|
149
|
-
function
|
|
150
|
-
const c =
|
|
149
|
+
function pt(e, t = he, a, n) {
|
|
150
|
+
const c = Te(e, `${t}/agents`, a, n);
|
|
151
151
|
return {
|
|
152
152
|
create(o, s) {
|
|
153
153
|
return c.post("/", o, s);
|
|
154
154
|
},
|
|
155
155
|
getAgents(o, s) {
|
|
156
|
-
return c.get(`/${o ? `?tag=${o}` : ""}`, s).then((
|
|
156
|
+
return c.get(`/${o ? `?tag=${o}` : ""}`, s).then((i) => i ?? []);
|
|
157
157
|
},
|
|
158
158
|
getById(o, s) {
|
|
159
159
|
return c.get(`/${o}`, s);
|
|
@@ -161,52 +161,52 @@ function mt(e, t = fe, i, n) {
|
|
|
161
161
|
delete(o, s) {
|
|
162
162
|
return c.delete(`/${o}`, void 0, s);
|
|
163
163
|
},
|
|
164
|
-
update(o, s,
|
|
165
|
-
return c.patch(`/${o}`, s,
|
|
164
|
+
update(o, s, i) {
|
|
165
|
+
return c.patch(`/${o}`, s, i);
|
|
166
166
|
},
|
|
167
|
-
newChat(o, s,
|
|
168
|
-
return c.post(`/${o}/chat`, s,
|
|
167
|
+
newChat(o, s, i) {
|
|
168
|
+
return c.post(`/${o}/chat`, s, i);
|
|
169
169
|
},
|
|
170
|
-
chat(o, s,
|
|
171
|
-
return c.post(`/${o}/chat/${s}`,
|
|
170
|
+
chat(o, s, i, r) {
|
|
171
|
+
return c.post(`/${o}/chat/${s}`, i, r);
|
|
172
172
|
},
|
|
173
|
-
createRating(o, s,
|
|
174
|
-
return c.post(`/${o}/chat/${s}/ratings`,
|
|
173
|
+
createRating(o, s, i, r) {
|
|
174
|
+
return c.post(`/${o}/chat/${s}/ratings`, i, r);
|
|
175
175
|
},
|
|
176
|
-
updateRating(o, s,
|
|
177
|
-
return c.patch(`/${o}/chat/${s}/ratings/${
|
|
176
|
+
updateRating(o, s, i, r, d) {
|
|
177
|
+
return c.patch(`/${o}/chat/${s}/ratings/${i}`, r, d);
|
|
178
178
|
},
|
|
179
|
-
deleteRating(o, s,
|
|
180
|
-
return c.delete(`/${o}/chat/${s}/ratings/${
|
|
179
|
+
deleteRating(o, s, i, r) {
|
|
180
|
+
return c.delete(`/${o}/chat/${s}/ratings/${i}`, r);
|
|
181
181
|
},
|
|
182
182
|
getSTTToken(o, s) {
|
|
183
183
|
return c.get(`/${o}/stt-token`, s);
|
|
184
184
|
}
|
|
185
185
|
};
|
|
186
186
|
}
|
|
187
|
-
function
|
|
188
|
-
var c, o, s,
|
|
189
|
-
const t = () => /Mobi|Android/i.test(navigator.userAgent) ? "Mobile" : "Desktop",
|
|
187
|
+
function wt(e) {
|
|
188
|
+
var c, o, s, i;
|
|
189
|
+
const t = () => /Mobi|Android/i.test(navigator.userAgent) ? "Mobile" : "Desktop", a = () => {
|
|
190
190
|
const r = navigator.platform;
|
|
191
191
|
return r.toLowerCase().includes("win") ? "Windows" : r.toLowerCase().includes("mac") ? "Mac OS X" : r.toLowerCase().includes("linux") ? "Linux" : "Unknown";
|
|
192
192
|
}, n = e.presenter;
|
|
193
193
|
return {
|
|
194
|
-
$os: `${
|
|
194
|
+
$os: `${a()}`,
|
|
195
195
|
isMobile: `${t() == "Mobile"}`,
|
|
196
196
|
browser: navigator.userAgent,
|
|
197
197
|
origin: window.location.origin,
|
|
198
|
-
agentType:
|
|
198
|
+
agentType: Je(n),
|
|
199
199
|
agentVoice: {
|
|
200
200
|
voiceId: (o = (c = e.presenter) == null ? void 0 : c.voice) == null ? void 0 : o.voice_id,
|
|
201
|
-
provider: (
|
|
201
|
+
provider: (i = (s = e.presenter) == null ? void 0 : s.voice) == null ? void 0 : i.type
|
|
202
202
|
}
|
|
203
203
|
};
|
|
204
204
|
}
|
|
205
|
-
function
|
|
206
|
-
var
|
|
207
|
-
const t = (
|
|
205
|
+
function yt(e) {
|
|
206
|
+
var a, n, c, o, s, i;
|
|
207
|
+
const t = (a = e.llm) == null ? void 0 : a.prompt_customization;
|
|
208
208
|
return {
|
|
209
|
-
agentType:
|
|
209
|
+
agentType: Je(e.presenter),
|
|
210
210
|
owner_id: e.owner_id ?? "",
|
|
211
211
|
promptVersion: (n = e.llm) == null ? void 0 : n.prompt_version,
|
|
212
212
|
behavior: {
|
|
@@ -216,7 +216,7 @@ function ht(e) {
|
|
|
216
216
|
},
|
|
217
217
|
temperature: (o = e.llm) == null ? void 0 : o.temperature,
|
|
218
218
|
knowledgeSource: t == null ? void 0 : t.knowledge_source,
|
|
219
|
-
starterQuestionsCount: (
|
|
219
|
+
starterQuestionsCount: (i = (s = e.knowledge) == null ? void 0 : s.starter_message) == null ? void 0 : i.length,
|
|
220
220
|
topicsToAvoid: t == null ? void 0 : t.topics_to_avoid,
|
|
221
221
|
maxResponseLength: t == null ? void 0 : t.max_response_length,
|
|
222
222
|
agentId: e.id,
|
|
@@ -225,42 +225,42 @@ function ht(e) {
|
|
|
225
225
|
...e.access === "public" ? { from: "agent-template" } : {}
|
|
226
226
|
};
|
|
227
227
|
}
|
|
228
|
-
const
|
|
229
|
-
function
|
|
230
|
-
var r, d,
|
|
228
|
+
const vt = (e) => e.reduce((t, a) => t + a, 0), je = (e) => vt(e) / e.length;
|
|
229
|
+
function St(e, t, a) {
|
|
230
|
+
var r, d, g;
|
|
231
231
|
const { event: n, ...c } = e, { template: o } = (t == null ? void 0 : t.llm) || {}, { language: s } = ((r = t == null ? void 0 : t.presenter) == null ? void 0 : r.voice) || {};
|
|
232
232
|
return {
|
|
233
233
|
...c,
|
|
234
234
|
llm: { ...c.llm, template: o },
|
|
235
235
|
script: { ...c.script, provider: { ...(d = c == null ? void 0 : c.script) == null ? void 0 : d.provider, language: s } },
|
|
236
|
-
stitch: (t == null ? void 0 : t.presenter.type) === "talk" ? (
|
|
237
|
-
...
|
|
236
|
+
stitch: (t == null ? void 0 : t.presenter.type) === "talk" ? (g = t == null ? void 0 : t.presenter) == null ? void 0 : g.stitch : void 0,
|
|
237
|
+
...a
|
|
238
238
|
};
|
|
239
239
|
}
|
|
240
|
-
function
|
|
240
|
+
function $e(e) {
|
|
241
241
|
"requestIdleCallback" in window ? requestIdleCallback(e, { timeout: 2e3 }) : setTimeout(e, 0);
|
|
242
242
|
}
|
|
243
|
-
let
|
|
244
|
-
const
|
|
245
|
-
function
|
|
243
|
+
let ve = {};
|
|
244
|
+
const Ct = "https://api-js.mixpanel.com/track/?verbose=1&ip=1";
|
|
245
|
+
function kt(e) {
|
|
246
246
|
const t = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk";
|
|
247
247
|
return {
|
|
248
248
|
token: e.token || "testKey",
|
|
249
|
-
distinct_id:
|
|
249
|
+
distinct_id: ke(e.externalId),
|
|
250
250
|
agentId: e.agentId,
|
|
251
251
|
additionalProperties: {
|
|
252
|
-
id:
|
|
252
|
+
id: ke(e.externalId),
|
|
253
253
|
...e.mixpanelAdditionalProperties || {}
|
|
254
254
|
},
|
|
255
255
|
isEnabled: e.isEnabled ?? !0,
|
|
256
|
-
getRandom:
|
|
257
|
-
enrich(
|
|
258
|
-
this.additionalProperties = { ...this.additionalProperties, ...
|
|
256
|
+
getRandom: ue,
|
|
257
|
+
enrich(a) {
|
|
258
|
+
this.additionalProperties = { ...this.additionalProperties, ...a };
|
|
259
259
|
},
|
|
260
|
-
async track(
|
|
260
|
+
async track(a, n, c) {
|
|
261
261
|
if (!this.isEnabled)
|
|
262
262
|
return Promise.resolve();
|
|
263
|
-
const { audioPath: o, ...s } = n || {},
|
|
263
|
+
const { audioPath: o, ...s } = n || {}, i = c || Date.now(), r = {
|
|
264
264
|
method: "POST",
|
|
265
265
|
headers: {
|
|
266
266
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
@@ -268,14 +268,14 @@ function vt(e) {
|
|
|
268
268
|
body: new URLSearchParams({
|
|
269
269
|
data: JSON.stringify([
|
|
270
270
|
{
|
|
271
|
-
event:
|
|
271
|
+
event: a,
|
|
272
272
|
properties: {
|
|
273
273
|
...this.additionalProperties,
|
|
274
274
|
...s,
|
|
275
275
|
agentId: this.agentId,
|
|
276
276
|
source: t,
|
|
277
277
|
token: this.token,
|
|
278
|
-
time:
|
|
278
|
+
time: i,
|
|
279
279
|
$insert_id: this.getRandom(),
|
|
280
280
|
origin: window.location.href,
|
|
281
281
|
"Screen Height": window.screen.height || window.innerWidth,
|
|
@@ -286,19 +286,19 @@ function vt(e) {
|
|
|
286
286
|
])
|
|
287
287
|
})
|
|
288
288
|
};
|
|
289
|
-
return fetch(
|
|
289
|
+
return fetch(Ct, {
|
|
290
290
|
...r,
|
|
291
291
|
keepalive: !0
|
|
292
292
|
}).catch((d) => console.error("Analytics tracking error:", d)), Promise.resolve();
|
|
293
293
|
},
|
|
294
|
-
linkTrack(
|
|
295
|
-
|
|
296
|
-
const s =
|
|
294
|
+
linkTrack(a, n, c, o) {
|
|
295
|
+
ve[a] || (ve[a] = { events: {}, resolvedDependencies: [] }), o.includes(c) || o.push(c);
|
|
296
|
+
const s = ve[a];
|
|
297
297
|
if (s.events[c] = { props: n }, s.resolvedDependencies.push(c), o.every(
|
|
298
298
|
(r) => s.resolvedDependencies.includes(r)
|
|
299
299
|
)) {
|
|
300
|
-
const r = o.reduce((d,
|
|
301
|
-
this.track(
|
|
300
|
+
const r = o.reduce((d, g) => s.events[g] ? { ...d, ...s.events[g].props } : d, {});
|
|
301
|
+
this.track(a, r), s.resolvedDependencies = s.resolvedDependencies.filter(
|
|
302
302
|
(d) => !o.includes(d)
|
|
303
303
|
), o.forEach((d) => {
|
|
304
304
|
delete s.events[d];
|
|
@@ -307,7 +307,7 @@ function vt(e) {
|
|
|
307
307
|
}
|
|
308
308
|
};
|
|
309
309
|
}
|
|
310
|
-
function
|
|
310
|
+
function _e() {
|
|
311
311
|
let e = 0;
|
|
312
312
|
return {
|
|
313
313
|
reset: () => e = 0,
|
|
@@ -315,22 +315,22 @@ function Ie() {
|
|
|
315
315
|
get: (t = !1) => t ? Date.now() - e : e
|
|
316
316
|
};
|
|
317
317
|
}
|
|
318
|
-
const
|
|
319
|
-
function
|
|
320
|
-
return e ===
|
|
318
|
+
const ie = _e(), Re = _e(), xe = _e();
|
|
319
|
+
function Oe(e) {
|
|
320
|
+
return e === F.Playground ? { headers: { [dt]: "true" } } : {};
|
|
321
321
|
}
|
|
322
|
-
async function
|
|
322
|
+
async function Ve(e, t, a, n, c = !1, o) {
|
|
323
323
|
try {
|
|
324
|
-
return !o && !
|
|
324
|
+
return !o && !Ue(n) && (o = await t.newChat(e.id, { persist: c }, Oe(n)), a.track("agent-chat", {
|
|
325
325
|
event: "created",
|
|
326
326
|
chatId: o.id,
|
|
327
327
|
mode: n
|
|
328
328
|
})), { chat: o, chatMode: (o == null ? void 0 : o.chat_mode) ?? n };
|
|
329
329
|
} catch (s) {
|
|
330
|
-
throw
|
|
330
|
+
throw Rt(s) === "InsufficientCreditsError" ? new Error("InsufficientCreditsError") : new Error("Cannot create new chat");
|
|
331
331
|
}
|
|
332
332
|
}
|
|
333
|
-
const
|
|
333
|
+
const Rt = (e) => {
|
|
334
334
|
try {
|
|
335
335
|
const t = JSON.parse(e.message);
|
|
336
336
|
return t == null ? void 0 : t.kind;
|
|
@@ -338,19 +338,19 @@ const St = (e) => {
|
|
|
338
338
|
return "UnknownError";
|
|
339
339
|
}
|
|
340
340
|
};
|
|
341
|
-
function
|
|
341
|
+
function Dt(e) {
|
|
342
342
|
return e && e.length > 0 ? e : [];
|
|
343
343
|
}
|
|
344
|
-
function
|
|
345
|
-
const c =
|
|
344
|
+
function Mt(e, t, a, n) {
|
|
345
|
+
const c = Te(e, `${t}/v2/agents/${a}`, n);
|
|
346
346
|
return {
|
|
347
347
|
async createStream(o) {
|
|
348
348
|
return c.post("/sessions", o);
|
|
349
349
|
}
|
|
350
350
|
};
|
|
351
351
|
}
|
|
352
|
-
const
|
|
353
|
-
async function
|
|
352
|
+
const qe = (e, t) => (a, n) => e && console.log(`[${t}] ${a}`, n ?? "");
|
|
353
|
+
async function Se() {
|
|
354
354
|
try {
|
|
355
355
|
return await import("./livekit-client.esm-C1GRQdZY.js");
|
|
356
356
|
} catch {
|
|
@@ -359,361 +359,374 @@ async function ye() {
|
|
|
359
359
|
);
|
|
360
360
|
}
|
|
361
361
|
}
|
|
362
|
-
const
|
|
363
|
-
excellent:
|
|
364
|
-
good:
|
|
365
|
-
poor:
|
|
366
|
-
lost:
|
|
367
|
-
unknown:
|
|
368
|
-
},
|
|
362
|
+
const Et = {
|
|
363
|
+
excellent: re.Strong,
|
|
364
|
+
good: re.Strong,
|
|
365
|
+
poor: re.Weak,
|
|
366
|
+
lost: re.Unknown,
|
|
367
|
+
unknown: re.Unknown
|
|
368
|
+
}, ge = JSON.stringify({
|
|
369
369
|
kind: "InternalServerError",
|
|
370
370
|
description: "Stream Error"
|
|
371
371
|
});
|
|
372
|
-
var
|
|
373
|
-
function
|
|
372
|
+
var Ae = /* @__PURE__ */ ((e) => (e.Chat = "lk.chat", e.Speak = "did.speak", e.Interrupt = "did.interrupt", e))(Ae || {});
|
|
373
|
+
function De(e, t, a, n) {
|
|
374
374
|
var c, o;
|
|
375
|
-
throw t("Failed to connect to LiveKit room:", e), n(), (c =
|
|
375
|
+
throw t("Failed to connect to LiveKit room:", e), n(), (c = a.onConnectionStateChange) == null || c.call(a, S.Fail), (o = a.onError) == null || o.call(a, e, { sessionId: "" }), e;
|
|
376
376
|
}
|
|
377
|
-
async function
|
|
378
|
-
var
|
|
379
|
-
const n =
|
|
377
|
+
async function It(e, t, a) {
|
|
378
|
+
var le, Pe;
|
|
379
|
+
const n = qe(a.debug || !1, "LiveKitStreamingManager"), { Room: c, RoomEvent: o, ConnectionState: s } = await Se(), { callbacks: i, auth: r, baseURL: d, analytics: g, microphoneStream: w } = a;
|
|
380
380
|
let u = null, M = !1;
|
|
381
|
-
const
|
|
382
|
-
let
|
|
381
|
+
const B = ae.Fluent;
|
|
382
|
+
let q = !0, E = null, I = null;
|
|
383
383
|
u = new c({
|
|
384
384
|
adaptiveStream: !1,
|
|
385
385
|
// Must be false to use mediaStreamTrack directly
|
|
386
386
|
dynacast: !0
|
|
387
387
|
});
|
|
388
|
-
let
|
|
389
|
-
const
|
|
390
|
-
let
|
|
388
|
+
let z = null;
|
|
389
|
+
const A = 2e4;
|
|
390
|
+
let W = J.Idle;
|
|
391
|
+
const ee = Mt(r, d || he, e, i.onError);
|
|
392
|
+
let T, G, Z;
|
|
391
393
|
try {
|
|
392
|
-
const l = await
|
|
393
|
-
transport_provider:
|
|
394
|
+
const l = await ee.createStream({
|
|
395
|
+
transport_provider: ye.Livekit,
|
|
394
396
|
chat_persist: t.chat_persist ?? !0
|
|
395
|
-
}), { id:
|
|
396
|
-
(
|
|
397
|
+
}), { id: h, session_token: v, session_url: R } = l;
|
|
398
|
+
(le = i.onStreamCreated) == null || le.call(i, { session_id: h, stream_id: h, agent_id: e }), T = h, G = v, Z = R, await u.prepareConnection(Z, G);
|
|
397
399
|
} catch (l) {
|
|
398
|
-
|
|
399
|
-
|
|
400
|
+
De(l, n, i, () => {
|
|
401
|
+
q = !1;
|
|
400
402
|
});
|
|
401
403
|
}
|
|
402
|
-
if (!
|
|
404
|
+
if (!Z || !G || !T)
|
|
403
405
|
return Promise.reject(new Error("Failed to initialize LiveKit stream"));
|
|
404
|
-
u.on(o.ConnectionStateChanged,
|
|
406
|
+
u.on(o.ConnectionStateChanged, m).on(o.ConnectionQualityChanged, y).on(o.ActiveSpeakersChanged, k).on(o.ParticipantConnected, P).on(o.ParticipantDisconnected, b).on(o.TrackSubscribed, _).on(o.TrackUnsubscribed, U).on(o.DataReceived, H).on(o.MediaDevicesError, Q).on(o.EncryptionError, j).on(o.TrackSubscriptionFailed, N), (Pe = i.onConnectionStateChange) == null || Pe.call(i, S.New);
|
|
405
407
|
try {
|
|
406
|
-
await u.connect(
|
|
408
|
+
await u.connect(Z, G), n("LiveKit room joined successfully"), z = setTimeout(() => {
|
|
407
409
|
var l;
|
|
408
|
-
n("Track subscription timeout - no track subscribed within 30 seconds after connect"),
|
|
410
|
+
n("Track subscription timeout - no track subscribed within 30 seconds after connect"), z = null, g.track("connectivity-error", {
|
|
409
411
|
error: "Track subscription timeout",
|
|
410
|
-
sessionId:
|
|
411
|
-
}), (l =
|
|
412
|
-
},
|
|
412
|
+
sessionId: T
|
|
413
|
+
}), (l = i.onError) == null || l.call(i, new Error("Track subscription timeout"), { sessionId: T }), ce();
|
|
414
|
+
}, A), q = !1;
|
|
413
415
|
} catch (l) {
|
|
414
|
-
|
|
415
|
-
|
|
416
|
+
De(l, n, i, () => {
|
|
417
|
+
q = !1;
|
|
416
418
|
});
|
|
417
419
|
}
|
|
418
|
-
|
|
419
|
-
"stream-type":
|
|
420
|
+
g.enrich({
|
|
421
|
+
"stream-type": B
|
|
420
422
|
});
|
|
421
|
-
function
|
|
422
|
-
var
|
|
423
|
+
function m(l) {
|
|
424
|
+
var h, v, R, D, K;
|
|
423
425
|
switch (n("Connection state changed:", l), l) {
|
|
424
426
|
case s.Connecting:
|
|
425
|
-
(
|
|
427
|
+
(h = i.onConnectionStateChange) == null || h.call(i, S.Connecting);
|
|
426
428
|
break;
|
|
427
429
|
case s.Connected:
|
|
428
|
-
n("LiveKit room connected successfully"), M = !0,
|
|
429
|
-
var
|
|
430
|
-
(
|
|
431
|
-
}) : (v =
|
|
430
|
+
n("LiveKit room connected successfully"), M = !0, q ? queueMicrotask(() => {
|
|
431
|
+
var L;
|
|
432
|
+
(L = i.onConnectionStateChange) == null || L.call(i, S.Connected);
|
|
433
|
+
}) : (v = i.onConnectionStateChange) == null || v.call(i, S.Connected);
|
|
432
434
|
break;
|
|
433
435
|
case s.Disconnected:
|
|
434
|
-
n("LiveKit room disconnected"), M = !1, (
|
|
436
|
+
n("LiveKit room disconnected"), M = !1, (R = i.onConnectionStateChange) == null || R.call(i, S.Disconnected);
|
|
435
437
|
break;
|
|
436
438
|
case s.Reconnecting:
|
|
437
|
-
n("LiveKit room reconnecting..."), (
|
|
439
|
+
n("LiveKit room reconnecting..."), (D = i.onConnectionStateChange) == null || D.call(i, S.Connecting);
|
|
438
440
|
break;
|
|
439
441
|
case s.SignalReconnecting:
|
|
440
|
-
n("LiveKit room signal reconnecting..."), (
|
|
442
|
+
n("LiveKit room signal reconnecting..."), (K = i.onConnectionStateChange) == null || K.call(i, S.Connecting);
|
|
441
443
|
break;
|
|
442
444
|
}
|
|
443
445
|
}
|
|
444
|
-
function
|
|
446
|
+
function y(l, h) {
|
|
445
447
|
var v;
|
|
446
|
-
n("Connection quality:", l),
|
|
448
|
+
n("Connection quality:", l), h != null && h.isLocal && ((v = i.onConnectivityStateChange) == null || v.call(i, Et[l]));
|
|
447
449
|
}
|
|
448
|
-
function
|
|
449
|
-
var
|
|
450
|
-
n("Active speakers changed:", l)
|
|
450
|
+
function k(l) {
|
|
451
|
+
var R, D, K, L;
|
|
452
|
+
n("Active speakers changed:", l);
|
|
453
|
+
const h = l.find((oe) => oe.isLocal), v = l.find((oe) => !oe.isLocal);
|
|
454
|
+
h ? ((R = i.onAgentActivityStateChange) == null || R.call(i, J.Idle), W !== J.Idle && ((D = i.onInterruptDetected) == null || D.call(i, { type: "audio" }), W = J.Idle)) : v ? (W = J.Talking, (K = i.onAgentActivityStateChange) == null || K.call(i, J.Talking)) : ((L = i.onAgentActivityStateChange) == null || L.call(i, J.Idle), W = J.Idle);
|
|
451
455
|
}
|
|
452
|
-
function
|
|
456
|
+
function P(l) {
|
|
453
457
|
n("Participant connected:", l.identity);
|
|
454
458
|
}
|
|
455
|
-
function
|
|
456
|
-
n("Participant disconnected:", l.identity),
|
|
459
|
+
function b(l) {
|
|
460
|
+
n("Participant disconnected:", l.identity), ce();
|
|
457
461
|
}
|
|
458
|
-
function _(l,
|
|
459
|
-
var
|
|
460
|
-
n(`Track subscribed: ${l.kind} from ${v.identity}`),
|
|
461
|
-
const
|
|
462
|
-
if (!
|
|
462
|
+
function _(l, h, v) {
|
|
463
|
+
var D, K, L;
|
|
464
|
+
n(`Track subscribed: ${l.kind} from ${v.identity}`), z && (clearTimeout(z), z = null, n("Track subscription timeout cleared"));
|
|
465
|
+
const R = l.mediaStreamTrack;
|
|
466
|
+
if (!R) {
|
|
463
467
|
n(`No mediaStreamTrack available for ${l.kind}`);
|
|
464
468
|
return;
|
|
465
469
|
}
|
|
466
|
-
|
|
470
|
+
E ? (E.addTrack(R), n(`Added ${l.kind} track to shared MediaStream`)) : (E = new MediaStream([R]), n(`Created shared MediaStream with ${l.kind} track`)), l.kind === "video" && ((D = i.onStreamReady) == null || D.call(i), (K = i.onSrcObjectReady) == null || K.call(i, E), (L = i.onVideoStateChange) == null || L.call(i, C.Start));
|
|
467
471
|
}
|
|
468
|
-
function
|
|
469
|
-
var
|
|
470
|
-
n(`Track unsubscribed: ${l.kind} from ${v.identity}`), l.kind === "video" && ((
|
|
472
|
+
function U(l, h, v) {
|
|
473
|
+
var R;
|
|
474
|
+
n(`Track unsubscribed: ${l.kind} from ${v.identity}`), l.kind === "video" && ((R = i.onVideoStateChange) == null || R.call(i, C.Stop));
|
|
471
475
|
}
|
|
472
|
-
function H(l,
|
|
473
|
-
var
|
|
474
|
-
const
|
|
475
|
-
n("Data received:",
|
|
476
|
+
function H(l, h, v, R) {
|
|
477
|
+
var K, L, oe, Le;
|
|
478
|
+
const D = new TextDecoder().decode(l);
|
|
479
|
+
n("Data received:", D);
|
|
476
480
|
try {
|
|
477
|
-
const
|
|
478
|
-
if (
|
|
479
|
-
const
|
|
480
|
-
(
|
|
481
|
-
event:
|
|
482
|
-
...
|
|
481
|
+
const te = JSON.parse(D), fe = R || te.subject;
|
|
482
|
+
if (fe === x.ChatAnswer) {
|
|
483
|
+
const ne = Y.Answer;
|
|
484
|
+
(K = i.onMessage) == null || K.call(i, ne, {
|
|
485
|
+
event: ne,
|
|
486
|
+
...te
|
|
483
487
|
});
|
|
484
|
-
} else if (
|
|
485
|
-
const
|
|
486
|
-
(
|
|
487
|
-
|
|
488
|
+
} else if (fe === x.ChatPartial) {
|
|
489
|
+
const ne = Y.Partial;
|
|
490
|
+
(L = i.onMessage) == null || L.call(i, ne, {
|
|
491
|
+
event: ne,
|
|
492
|
+
...te
|
|
488
493
|
});
|
|
489
|
-
} else if (
|
|
490
|
-
const
|
|
491
|
-
(
|
|
492
|
-
|
|
493
|
-
|
|
494
|
+
} else if ([x.StreamVideoCreated, x.StreamVideoDone].includes(fe)) {
|
|
495
|
+
const ne = (te == null ? void 0 : te.role) || (h == null ? void 0 : h.identity) || "datachannel";
|
|
496
|
+
(oe = i.onMessage) == null || oe.call(i, fe, {
|
|
497
|
+
[ne]: te
|
|
498
|
+
});
|
|
499
|
+
} else if (fe === x.ChatAudioTranscribed) {
|
|
500
|
+
const ne = Y.Transcribe;
|
|
501
|
+
(Le = i.onMessage) == null || Le.call(i, ne, {
|
|
502
|
+
event: ne,
|
|
503
|
+
...te
|
|
504
|
+
}), queueMicrotask(() => {
|
|
505
|
+
var be;
|
|
506
|
+
(be = i.onAgentActivityStateChange) == null || be.call(i, J.Loading);
|
|
494
507
|
});
|
|
495
508
|
}
|
|
496
|
-
} catch (
|
|
497
|
-
n("Failed to parse data channel message:",
|
|
509
|
+
} catch (te) {
|
|
510
|
+
n("Failed to parse data channel message:", te);
|
|
498
511
|
}
|
|
499
512
|
}
|
|
500
|
-
function
|
|
501
|
-
var
|
|
502
|
-
n("Media devices error:", l), (
|
|
513
|
+
function Q(l) {
|
|
514
|
+
var h;
|
|
515
|
+
n("Media devices error:", l), (h = i.onError) == null || h.call(i, new Error(ge), { sessionId: T });
|
|
503
516
|
}
|
|
504
517
|
function j(l) {
|
|
505
|
-
var
|
|
506
|
-
n("Encryption error:", l), (
|
|
518
|
+
var h;
|
|
519
|
+
n("Encryption error:", l), (h = i.onError) == null || h.call(i, new Error(ge), { sessionId: T });
|
|
507
520
|
}
|
|
508
|
-
function
|
|
509
|
-
n("Track subscription failed:", { trackSid: l, participant:
|
|
521
|
+
function N(l, h, v) {
|
|
522
|
+
n("Track subscription failed:", { trackSid: l, participant: h, reason: v });
|
|
510
523
|
}
|
|
511
|
-
async function
|
|
524
|
+
async function X(l) {
|
|
512
525
|
if (!u) return null;
|
|
513
|
-
const { Track:
|
|
526
|
+
const { Track: h } = await Se(), v = u.localParticipant.audioTrackPublications;
|
|
514
527
|
if (v) {
|
|
515
|
-
for (const [
|
|
516
|
-
if (
|
|
517
|
-
const
|
|
518
|
-
if (
|
|
519
|
-
return
|
|
528
|
+
for (const [R, D] of v)
|
|
529
|
+
if (D.source === h.Source.Microphone && D.track) {
|
|
530
|
+
const L = D.track.mediaStreamTrack;
|
|
531
|
+
if (L === l || L && L.id === l.id)
|
|
532
|
+
return D;
|
|
520
533
|
}
|
|
521
534
|
}
|
|
522
535
|
return null;
|
|
523
536
|
}
|
|
524
|
-
function
|
|
525
|
-
if (!
|
|
537
|
+
function se(l) {
|
|
538
|
+
if (!I || !I.track)
|
|
526
539
|
return !1;
|
|
527
|
-
const
|
|
528
|
-
return
|
|
540
|
+
const h = I.track.mediaStreamTrack;
|
|
541
|
+
return h !== l && (h == null ? void 0 : h.id) !== l.id;
|
|
529
542
|
}
|
|
530
|
-
async function
|
|
531
|
-
var
|
|
543
|
+
async function O(l) {
|
|
544
|
+
var K, L;
|
|
532
545
|
if (!M || !u)
|
|
533
546
|
throw n("Room is not connected, cannot publish microphone stream"), new Error("Room is not connected");
|
|
534
|
-
const
|
|
535
|
-
if (
|
|
547
|
+
const h = l.getAudioTracks();
|
|
548
|
+
if (h.length === 0) {
|
|
536
549
|
n("No audio track found in the provided MediaStream");
|
|
537
550
|
return;
|
|
538
551
|
}
|
|
539
|
-
const v =
|
|
540
|
-
if (
|
|
552
|
+
const v = h[0], { Track: R } = await Se(), D = await X(v);
|
|
553
|
+
if (D) {
|
|
541
554
|
n("Microphone track is already published, skipping", {
|
|
542
555
|
trackId: v.id,
|
|
543
|
-
publishedTrackId: (
|
|
544
|
-
}),
|
|
556
|
+
publishedTrackId: (L = (K = D.track) == null ? void 0 : K.mediaStreamTrack) == null ? void 0 : L.id
|
|
557
|
+
}), I = D;
|
|
545
558
|
return;
|
|
546
559
|
}
|
|
547
|
-
|
|
560
|
+
se(v) && (n("Unpublishing existing microphone track before publishing new one"), await f()), n("Publishing microphone track from provided MediaStream", { trackId: v.id });
|
|
548
561
|
try {
|
|
549
|
-
|
|
550
|
-
source:
|
|
551
|
-
}), n("Microphone track published successfully", { trackSid:
|
|
552
|
-
} catch (
|
|
553
|
-
throw n("Failed to publish microphone track:",
|
|
562
|
+
I = await u.localParticipant.publishTrack(v, {
|
|
563
|
+
source: R.Source.Microphone
|
|
564
|
+
}), n("Microphone track published successfully", { trackSid: I.trackSid });
|
|
565
|
+
} catch (oe) {
|
|
566
|
+
throw n("Failed to publish microphone track:", oe), oe;
|
|
554
567
|
}
|
|
555
568
|
}
|
|
556
|
-
async function
|
|
557
|
-
if (!(!
|
|
569
|
+
async function f() {
|
|
570
|
+
if (!(!I || !I.track))
|
|
558
571
|
try {
|
|
559
|
-
u && (await u.localParticipant.unpublishTrack(
|
|
572
|
+
u && (await u.localParticipant.unpublishTrack(I.track), n("Microphone track unpublished"));
|
|
560
573
|
} catch (l) {
|
|
561
574
|
n("Error unpublishing microphone track:", l);
|
|
562
575
|
} finally {
|
|
563
|
-
|
|
576
|
+
I = null;
|
|
564
577
|
}
|
|
565
578
|
}
|
|
566
|
-
function
|
|
567
|
-
|
|
579
|
+
function p() {
|
|
580
|
+
E && (E.getTracks().forEach((l) => l.stop()), E = null);
|
|
568
581
|
}
|
|
569
|
-
async function
|
|
570
|
-
var v,
|
|
582
|
+
async function $(l, h) {
|
|
583
|
+
var v, R;
|
|
571
584
|
if (!M || !u) {
|
|
572
|
-
n("Room is not connected for sending messages"), (v =
|
|
573
|
-
sessionId:
|
|
585
|
+
n("Room is not connected for sending messages"), (v = i.onError) == null || v.call(i, new Error(ge), {
|
|
586
|
+
sessionId: T
|
|
574
587
|
});
|
|
575
588
|
return;
|
|
576
589
|
}
|
|
577
590
|
try {
|
|
578
|
-
await u.localParticipant.sendText(l, { topic:
|
|
579
|
-
} catch (
|
|
580
|
-
n("Failed to send message:",
|
|
591
|
+
await u.localParticipant.sendText(l, { topic: h }), n("Message sent successfully:", l);
|
|
592
|
+
} catch (D) {
|
|
593
|
+
n("Failed to send message:", D), (R = i.onError) == null || R.call(i, new Error(ge), { sessionId: T });
|
|
581
594
|
}
|
|
582
595
|
}
|
|
583
|
-
async function
|
|
584
|
-
var
|
|
596
|
+
async function V(l) {
|
|
597
|
+
var h;
|
|
585
598
|
try {
|
|
586
|
-
const
|
|
587
|
-
return
|
|
599
|
+
const R = JSON.parse(l).topic;
|
|
600
|
+
return $("", R);
|
|
588
601
|
} catch (v) {
|
|
589
|
-
n("Failed to send data channel message:", v), (
|
|
602
|
+
n("Failed to send data channel message:", v), (h = i.onError) == null || h.call(i, new Error(ge), { sessionId: T });
|
|
590
603
|
}
|
|
591
604
|
}
|
|
592
|
-
function
|
|
593
|
-
return
|
|
605
|
+
function pe(l) {
|
|
606
|
+
return $(
|
|
594
607
|
l,
|
|
595
608
|
"lk.chat"
|
|
596
609
|
/* Chat */
|
|
597
610
|
);
|
|
598
611
|
}
|
|
599
|
-
async function
|
|
600
|
-
var l,
|
|
601
|
-
|
|
612
|
+
async function ce() {
|
|
613
|
+
var l, h;
|
|
614
|
+
z && (clearTimeout(z), z = null), u && (await f(), await u.disconnect()), p(), M = !1, (l = i.onConnectionStateChange) == null || l.call(i, S.Disconnected), (h = i.onAgentActivityStateChange) == null || h.call(i, J.Idle), W = J.Idle;
|
|
602
615
|
}
|
|
603
616
|
return {
|
|
604
617
|
speak(l) {
|
|
605
|
-
const
|
|
606
|
-
return
|
|
607
|
-
|
|
618
|
+
const h = typeof l == "string" ? l : JSON.stringify(l);
|
|
619
|
+
return $(
|
|
620
|
+
h,
|
|
608
621
|
"did.speak"
|
|
609
622
|
/* Speak */
|
|
610
623
|
);
|
|
611
624
|
},
|
|
612
|
-
disconnect:
|
|
625
|
+
disconnect: ce,
|
|
613
626
|
async reconnect() {
|
|
614
|
-
var l,
|
|
627
|
+
var l, h, v;
|
|
615
628
|
if ((u == null ? void 0 : u.state) === s.Connected) {
|
|
616
629
|
n("Room is already connected");
|
|
617
630
|
return;
|
|
618
631
|
}
|
|
619
|
-
if (!u || !
|
|
632
|
+
if (!u || !Z || !G)
|
|
620
633
|
throw n("Cannot reconnect: missing room, URL or token"), new Error("Cannot reconnect: session not available");
|
|
621
|
-
n("Reconnecting to LiveKit room, state:", u.state), (l =
|
|
634
|
+
n("Reconnecting to LiveKit room, state:", u.state), (l = i.onConnectionStateChange) == null || l.call(i, S.Connecting);
|
|
622
635
|
try {
|
|
623
|
-
if (await u.connect(
|
|
624
|
-
if (n("Waiting for agent to join..."), !await new Promise((
|
|
625
|
-
const
|
|
626
|
-
u == null || u.off(o.ParticipantConnected,
|
|
627
|
-
}, 5e3),
|
|
628
|
-
clearTimeout(
|
|
636
|
+
if (await u.connect(Z, G), n("Room reconnected"), M = !0, u.remoteParticipants.size === 0) {
|
|
637
|
+
if (n("Waiting for agent to join..."), !await new Promise((D) => {
|
|
638
|
+
const K = setTimeout(() => {
|
|
639
|
+
u == null || u.off(o.ParticipantConnected, L), D(!1);
|
|
640
|
+
}, 5e3), L = () => {
|
|
641
|
+
clearTimeout(K), u == null || u.off(o.ParticipantConnected, L), D(!0);
|
|
629
642
|
};
|
|
630
|
-
u == null || u.on(o.ParticipantConnected,
|
|
643
|
+
u == null || u.on(o.ParticipantConnected, L);
|
|
631
644
|
}))
|
|
632
645
|
throw n("Agent did not join within timeout"), await u.disconnect(), new Error("Agent did not rejoin the room");
|
|
633
646
|
n("Agent joined");
|
|
634
647
|
}
|
|
635
|
-
(
|
|
636
|
-
} catch (
|
|
637
|
-
throw n("Failed to reconnect:",
|
|
648
|
+
(h = i.onConnectionStateChange) == null || h.call(i, S.Connected);
|
|
649
|
+
} catch (R) {
|
|
650
|
+
throw n("Failed to reconnect:", R), (v = i.onConnectionStateChange) == null || v.call(i, S.Fail), R;
|
|
638
651
|
}
|
|
639
652
|
},
|
|
640
|
-
sendDataChannelMessage:
|
|
641
|
-
sendTextMessage:
|
|
642
|
-
publishMicrophoneStream:
|
|
643
|
-
unpublishMicrophoneStream:
|
|
644
|
-
sessionId:
|
|
645
|
-
streamId:
|
|
646
|
-
streamType:
|
|
653
|
+
sendDataChannelMessage: V,
|
|
654
|
+
sendTextMessage: pe,
|
|
655
|
+
publishMicrophoneStream: O,
|
|
656
|
+
unpublishMicrophoneStream: f,
|
|
657
|
+
sessionId: T,
|
|
658
|
+
streamId: T,
|
|
659
|
+
streamType: B,
|
|
647
660
|
interruptAvailable: !0,
|
|
648
661
|
triggersAvailable: !1
|
|
649
662
|
};
|
|
650
663
|
}
|
|
651
|
-
const
|
|
664
|
+
const Tt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
652
665
|
__proto__: null,
|
|
653
|
-
DataChannelTopic:
|
|
654
|
-
createLiveKitStreamingManager:
|
|
655
|
-
handleInitError:
|
|
666
|
+
DataChannelTopic: Ae,
|
|
667
|
+
createLiveKitStreamingManager: It,
|
|
668
|
+
handleInitError: De
|
|
656
669
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
657
|
-
function
|
|
670
|
+
function _t(e, t, a) {
|
|
658
671
|
if (!e)
|
|
659
672
|
throw new Error("Please connect to the agent first");
|
|
660
673
|
if (!e.interruptAvailable)
|
|
661
674
|
throw new Error("Interrupt is not enabled for this stream");
|
|
662
|
-
if (t !==
|
|
675
|
+
if (t !== ae.Fluent)
|
|
663
676
|
throw new Error("Interrupt only available for Fluent streams");
|
|
664
|
-
if (!
|
|
677
|
+
if (!a)
|
|
665
678
|
throw new Error("No active video to interrupt");
|
|
666
679
|
}
|
|
667
|
-
async function
|
|
668
|
-
const
|
|
669
|
-
type:
|
|
680
|
+
async function At(e, t) {
|
|
681
|
+
const a = {
|
|
682
|
+
type: x.StreamInterrupt,
|
|
670
683
|
videoId: t,
|
|
671
684
|
timestamp: Date.now()
|
|
672
685
|
};
|
|
673
|
-
e.sendDataChannelMessage(JSON.stringify(
|
|
686
|
+
e.sendDataChannelMessage(JSON.stringify(a));
|
|
674
687
|
}
|
|
675
|
-
async function
|
|
688
|
+
async function Pt(e) {
|
|
676
689
|
const t = {
|
|
677
|
-
topic:
|
|
690
|
+
topic: Ae.Interrupt
|
|
678
691
|
};
|
|
679
692
|
e.sendDataChannelMessage(JSON.stringify(t));
|
|
680
693
|
}
|
|
681
|
-
function
|
|
682
|
-
return new Promise((t,
|
|
683
|
-
const { callbacks: n, host: c, auth: o, externalId: s } = e, { onMessage:
|
|
684
|
-
|
|
685
|
-
console.error(u),
|
|
686
|
-
},
|
|
687
|
-
r == null || r(u), t(
|
|
694
|
+
function Lt(e) {
|
|
695
|
+
return new Promise((t, a) => {
|
|
696
|
+
const { callbacks: n, host: c, auth: o, externalId: s } = e, { onMessage: i = null, onOpen: r = null, onClose: d = null, onError: g = null } = n || {}, w = new WebSocket(`${c}?authorization=${encodeURIComponent(We(o, s))}`);
|
|
697
|
+
w.onmessage = i, w.onclose = d, w.onerror = (u) => {
|
|
698
|
+
console.error(u), g == null || g("Websocket failed to connect", u), a(u);
|
|
699
|
+
}, w.onopen = (u) => {
|
|
700
|
+
r == null || r(u), t(w);
|
|
688
701
|
};
|
|
689
702
|
});
|
|
690
703
|
}
|
|
691
|
-
async function
|
|
704
|
+
async function bt(e) {
|
|
692
705
|
const { retries: t = 1 } = e;
|
|
693
|
-
let
|
|
694
|
-
for (let n = 0; (
|
|
706
|
+
let a = null;
|
|
707
|
+
for (let n = 0; (a == null ? void 0 : a.readyState) !== WebSocket.OPEN; n++)
|
|
695
708
|
try {
|
|
696
|
-
|
|
709
|
+
a = await Lt(e);
|
|
697
710
|
} catch (c) {
|
|
698
711
|
if (n === t)
|
|
699
712
|
throw c;
|
|
700
|
-
await
|
|
713
|
+
await Ke(n * 500);
|
|
701
714
|
}
|
|
702
|
-
return
|
|
715
|
+
return a;
|
|
703
716
|
}
|
|
704
|
-
async function
|
|
705
|
-
const c =
|
|
717
|
+
async function jt(e, t, a, n) {
|
|
718
|
+
const c = a != null && a.onMessage ? [a.onMessage] : [], o = await bt({
|
|
706
719
|
auth: e,
|
|
707
720
|
host: t,
|
|
708
721
|
externalId: n,
|
|
709
722
|
callbacks: {
|
|
710
723
|
onError: (s) => {
|
|
711
|
-
var
|
|
712
|
-
return (
|
|
724
|
+
var i;
|
|
725
|
+
return (i = a.onError) == null ? void 0 : i.call(a, new Ge(s));
|
|
713
726
|
},
|
|
714
727
|
onMessage(s) {
|
|
715
|
-
const
|
|
716
|
-
c.forEach((r) => r(
|
|
728
|
+
const i = JSON.parse(s.data);
|
|
729
|
+
c.forEach((r) => r(i.event, i));
|
|
717
730
|
}
|
|
718
731
|
}
|
|
719
732
|
});
|
|
@@ -723,15 +736,15 @@ async function Pt(e, t, i, n) {
|
|
|
723
736
|
subscribeToEvents: (s) => c.push(s)
|
|
724
737
|
};
|
|
725
738
|
}
|
|
726
|
-
function
|
|
739
|
+
function $t(e) {
|
|
727
740
|
if (e.answer !== void 0)
|
|
728
741
|
return e.answer;
|
|
729
|
-
let t = 0,
|
|
742
|
+
let t = 0, a = "";
|
|
730
743
|
for (; t in e; )
|
|
731
|
-
|
|
732
|
-
return
|
|
744
|
+
a += e[t++];
|
|
745
|
+
return a;
|
|
733
746
|
}
|
|
734
|
-
function
|
|
747
|
+
function xt(e, t, a) {
|
|
735
748
|
if (!e.content)
|
|
736
749
|
return;
|
|
737
750
|
const n = t.messages[t.messages.length - 1];
|
|
@@ -743,11 +756,11 @@ function jt(e, t, i) {
|
|
|
743
756
|
created_at: e.created_at || (/* @__PURE__ */ new Date()).toISOString(),
|
|
744
757
|
transcribed: !0
|
|
745
758
|
};
|
|
746
|
-
t.messages.push(c),
|
|
759
|
+
t.messages.push(c), a == null || a([...t.messages], "user");
|
|
747
760
|
}
|
|
748
|
-
function
|
|
761
|
+
function Bt(e, t, a, n, c) {
|
|
749
762
|
if (e === Y.Transcribe && t.content) {
|
|
750
|
-
|
|
763
|
+
xt(t, n, c);
|
|
751
764
|
return;
|
|
752
765
|
}
|
|
753
766
|
if (!(e === Y.Partial || e === Y.Answer))
|
|
@@ -765,66 +778,66 @@ function Lt(e, t, i, n, c) {
|
|
|
765
778
|
s = o;
|
|
766
779
|
else
|
|
767
780
|
return;
|
|
768
|
-
const { content:
|
|
769
|
-
e === Y.Partial ?
|
|
770
|
-
const d =
|
|
781
|
+
const { content: i, sequence: r } = t;
|
|
782
|
+
e === Y.Partial ? a[r] = i : a.answer = i;
|
|
783
|
+
const d = $t(a);
|
|
771
784
|
(s.content !== d || e === Y.Answer) && (s.content = d, c == null || c([...n.messages], e));
|
|
772
785
|
}
|
|
773
|
-
function
|
|
786
|
+
function Ft(e, t, a, n, c) {
|
|
774
787
|
let o = {};
|
|
775
788
|
return {
|
|
776
789
|
clearQueue: () => o = {},
|
|
777
|
-
onMessage: (s,
|
|
790
|
+
onMessage: (s, i) => {
|
|
778
791
|
var r, d;
|
|
779
|
-
if ("content" in
|
|
780
|
-
const
|
|
781
|
-
|
|
792
|
+
if ("content" in i) {
|
|
793
|
+
const g = s === x.ChatAnswer ? Y.Answer : s === x.ChatAudioTranscribed ? Y.Transcribe : s;
|
|
794
|
+
Bt(g, i, o, t, a.callbacks.onNewMessage), g === Y.Answer && e.track("agent-message-received", {
|
|
782
795
|
messages: t.messages.length,
|
|
783
796
|
mode: t.chatMode
|
|
784
797
|
});
|
|
785
798
|
} else {
|
|
786
|
-
const
|
|
787
|
-
if (s = s, s ===
|
|
788
|
-
e.linkTrack("agent-video", M,
|
|
789
|
-
else if (
|
|
790
|
-
const
|
|
791
|
-
u.includes(s) ? e.track("agent-video", { ...M, event:
|
|
799
|
+
const g = x, w = [g.StreamVideoDone, g.StreamVideoError, g.StreamVideoRejected], u = [g.StreamFailed, g.StreamVideoError, g.StreamVideoRejected], M = St(i, n, { mode: t.chatMode });
|
|
800
|
+
if (s = s, s === g.StreamVideoCreated)
|
|
801
|
+
e.linkTrack("agent-video", M, g.StreamVideoCreated, ["start"]);
|
|
802
|
+
else if (w.includes(s)) {
|
|
803
|
+
const B = s.split("/")[1];
|
|
804
|
+
u.includes(s) ? e.track("agent-video", { ...M, event: B }) : e.linkTrack("agent-video", { ...M, event: B }, s, ["done"]);
|
|
792
805
|
}
|
|
793
|
-
u.includes(s) && ((d = (r =
|
|
806
|
+
u.includes(s) && ((d = (r = a.callbacks).onError) == null || d.call(r, new Error(`Stream failed with event ${s}`), { data: i })), i.event === g.StreamDone && c();
|
|
794
807
|
}
|
|
795
808
|
}
|
|
796
809
|
};
|
|
797
810
|
}
|
|
798
|
-
function
|
|
799
|
-
const c =
|
|
811
|
+
function zt(e, t, a, n) {
|
|
812
|
+
const c = Te(e, `${t}/agents/${a}`, n);
|
|
800
813
|
return {
|
|
801
814
|
createStream(o, s) {
|
|
802
815
|
return c.post("/streams", o, { signal: s });
|
|
803
816
|
},
|
|
804
|
-
startConnection(o, s,
|
|
817
|
+
startConnection(o, s, i, r) {
|
|
805
818
|
return c.post(
|
|
806
819
|
`/streams/${o}/sdp`,
|
|
807
820
|
{
|
|
808
|
-
session_id:
|
|
821
|
+
session_id: i,
|
|
809
822
|
answer: s
|
|
810
823
|
},
|
|
811
824
|
{ signal: r }
|
|
812
825
|
);
|
|
813
826
|
},
|
|
814
|
-
addIceCandidate(o, s,
|
|
827
|
+
addIceCandidate(o, s, i, r) {
|
|
815
828
|
return c.post(
|
|
816
829
|
`/streams/${o}/ice`,
|
|
817
830
|
{
|
|
818
|
-
session_id:
|
|
831
|
+
session_id: i,
|
|
819
832
|
...s
|
|
820
833
|
},
|
|
821
834
|
{ signal: r }
|
|
822
835
|
);
|
|
823
836
|
},
|
|
824
|
-
sendStreamRequest(o, s,
|
|
837
|
+
sendStreamRequest(o, s, i) {
|
|
825
838
|
return c.post(`/streams/${o}`, {
|
|
826
839
|
session_id: s,
|
|
827
|
-
...
|
|
840
|
+
...i
|
|
828
841
|
});
|
|
829
842
|
},
|
|
830
843
|
close(o, s) {
|
|
@@ -832,7 +845,7 @@ function xt(e, t, i, n) {
|
|
|
832
845
|
}
|
|
833
846
|
};
|
|
834
847
|
}
|
|
835
|
-
function
|
|
848
|
+
function Nt(e, t, a) {
|
|
836
849
|
const n = (t.timestamp - e.timestamp) / 1e3;
|
|
837
850
|
return {
|
|
838
851
|
duration: n,
|
|
@@ -849,31 +862,31 @@ function Bt(e, t, i) {
|
|
|
849
862
|
framesPerSecond: t.framesPerSecond,
|
|
850
863
|
freezeCount: t.freezeCount - e.freezeCount,
|
|
851
864
|
freezeDuration: t.freezeDuration - e.freezeDuration,
|
|
852
|
-
lowFpsCount:
|
|
865
|
+
lowFpsCount: a
|
|
853
866
|
};
|
|
854
867
|
}
|
|
855
|
-
function
|
|
868
|
+
function Kt(e) {
|
|
856
869
|
return e.filter(
|
|
857
870
|
(t) => t.freezeCount > 0 || t.framesPerSecond < 21 || t.framesDropped > 0 || t.packetsLost > 0
|
|
858
871
|
).map((t) => {
|
|
859
|
-
const { timestamp:
|
|
872
|
+
const { timestamp: a, ...n } = t, c = [];
|
|
860
873
|
return t.freezeCount > 0 && c.push("freeze"), t.framesPerSecond < 21 && c.push("low fps"), t.framesDropped > 0 && c.push("frames dropped"), t.packetsLost > 0 && c.push("packet loss"), {
|
|
861
874
|
...n,
|
|
862
875
|
causes: c
|
|
863
876
|
};
|
|
864
877
|
});
|
|
865
878
|
}
|
|
866
|
-
function
|
|
867
|
-
let t = "",
|
|
879
|
+
function Jt(e) {
|
|
880
|
+
let t = "", a = 0;
|
|
868
881
|
for (const n of e.values()) {
|
|
869
882
|
if (n && n.type === "codec" && n.mimeType.startsWith("video") && (t = n.mimeType.split("/")[1]), n && n.type === "candidate-pair") {
|
|
870
883
|
const c = n.currentRoundTripTime, s = n.nominated === !0;
|
|
871
|
-
c > 0 && (s ||
|
|
884
|
+
c > 0 && (s || a === 0) && (a = c);
|
|
872
885
|
}
|
|
873
886
|
if (n && n.type === "inbound-rtp" && n.kind === "video")
|
|
874
887
|
return {
|
|
875
888
|
codec: t,
|
|
876
|
-
rtt:
|
|
889
|
+
rtt: a,
|
|
877
890
|
timestamp: n.timestamp,
|
|
878
891
|
bytesReceived: n.bytesReceived,
|
|
879
892
|
packetsReceived: n.packetsReceived,
|
|
@@ -893,24 +906,24 @@ function zt(e) {
|
|
|
893
906
|
}
|
|
894
907
|
return {};
|
|
895
908
|
}
|
|
896
|
-
function
|
|
897
|
-
const n = e.map((r, d) => d === 0 ?
|
|
909
|
+
function Ut(e, t, a) {
|
|
910
|
+
const n = e.map((r, d) => d === 0 ? a ? {
|
|
898
911
|
timestamp: r.timestamp,
|
|
899
912
|
duration: 0,
|
|
900
913
|
rtt: r.rtt,
|
|
901
|
-
bytesReceived: r.bytesReceived -
|
|
902
|
-
bitrate: (r.bytesReceived -
|
|
903
|
-
packetsReceived: r.packetsReceived -
|
|
904
|
-
packetsLost: r.packetsLost -
|
|
905
|
-
framesDropped: r.framesDropped -
|
|
906
|
-
framesDecoded: r.framesDecoded -
|
|
914
|
+
bytesReceived: r.bytesReceived - a.bytesReceived,
|
|
915
|
+
bitrate: (r.bytesReceived - a.bytesReceived) * 8 / (t / 1e3),
|
|
916
|
+
packetsReceived: r.packetsReceived - a.packetsReceived,
|
|
917
|
+
packetsLost: r.packetsLost - a.packetsLost,
|
|
918
|
+
framesDropped: r.framesDropped - a.framesDropped,
|
|
919
|
+
framesDecoded: r.framesDecoded - a.framesDecoded,
|
|
907
920
|
jitter: r.jitter,
|
|
908
|
-
jitterBufferDelay: r.jitterBufferDelay -
|
|
909
|
-
jitterBufferEmittedCount: r.jitterBufferEmittedCount -
|
|
910
|
-
avgJitterDelayInInterval: (r.jitterBufferDelay -
|
|
921
|
+
jitterBufferDelay: r.jitterBufferDelay - a.jitterBufferDelay,
|
|
922
|
+
jitterBufferEmittedCount: r.jitterBufferEmittedCount - a.jitterBufferEmittedCount,
|
|
923
|
+
avgJitterDelayInInterval: (r.jitterBufferDelay - a.jitterBufferDelay) / (r.jitterBufferEmittedCount - a.jitterBufferEmittedCount),
|
|
911
924
|
framesPerSecond: r.framesPerSecond,
|
|
912
|
-
freezeCount: r.freezeCount -
|
|
913
|
-
freezeDuration: r.freezeDuration -
|
|
925
|
+
freezeCount: r.freezeCount - a.freezeCount,
|
|
926
|
+
freezeDuration: r.freezeDuration - a.freezeDuration
|
|
914
927
|
} : {
|
|
915
928
|
timestamp: r.timestamp,
|
|
916
929
|
rtt: r.rtt,
|
|
@@ -945,55 +958,55 @@ function Nt(e, t, i) {
|
|
|
945
958
|
framesPerSecond: r.framesPerSecond,
|
|
946
959
|
freezeCount: r.freezeCount - e[d - 1].freezeCount,
|
|
947
960
|
freezeDuration: r.freezeDuration - e[d - 1].freezeDuration
|
|
948
|
-
}), c =
|
|
961
|
+
}), c = Kt(n), o = c.reduce((r, d) => r + (d.causes.includes("low fps") ? 1 : 0), 0), s = n.filter((r) => !!r.avgJitterDelayInInterval).map((r) => r.avgJitterDelayInInterval), i = n.filter((r) => !!r.rtt).map((r) => r.rtt);
|
|
949
962
|
return {
|
|
950
963
|
webRTCStats: {
|
|
951
964
|
anomalies: c,
|
|
952
|
-
minRtt: Math.min(...
|
|
953
|
-
avgRtt:
|
|
954
|
-
maxRtt: Math.max(...
|
|
955
|
-
aggregateReport:
|
|
965
|
+
minRtt: Math.min(...i),
|
|
966
|
+
avgRtt: je(i),
|
|
967
|
+
maxRtt: Math.max(...i),
|
|
968
|
+
aggregateReport: Nt(e[0], e[e.length - 1], o),
|
|
956
969
|
minJitterDelayInInterval: Math.min(...s),
|
|
957
970
|
maxJitterDelayInInterval: Math.max(...s),
|
|
958
|
-
avgJitterDelayInInterval:
|
|
971
|
+
avgJitterDelayInInterval: je(s)
|
|
959
972
|
},
|
|
960
973
|
codec: e[0].codec,
|
|
961
974
|
resolution: `${e[0].frameWidth}x${e[0].frameHeight}`
|
|
962
975
|
};
|
|
963
976
|
}
|
|
964
|
-
const
|
|
965
|
-
function
|
|
966
|
-
let e = 0, t,
|
|
977
|
+
const Me = 100, Wt = Math.max(Math.ceil(400 / Me), 1), Ot = 0.25, Vt = 0.28;
|
|
978
|
+
function qt() {
|
|
979
|
+
let e = 0, t, a, n = 0;
|
|
967
980
|
return (c) => {
|
|
968
981
|
for (const o of c.values())
|
|
969
982
|
if (o && o.type === "inbound-rtp" && o.kind === "video") {
|
|
970
|
-
const s = o.jitterBufferDelay,
|
|
971
|
-
if (
|
|
972
|
-
const
|
|
973
|
-
n =
|
|
983
|
+
const s = o.jitterBufferDelay, i = o.jitterBufferEmittedCount;
|
|
984
|
+
if (a && i > a) {
|
|
985
|
+
const g = s - t, w = i - a;
|
|
986
|
+
n = g / w;
|
|
974
987
|
}
|
|
975
|
-
t = s,
|
|
988
|
+
t = s, a = i;
|
|
976
989
|
const r = o.framesDecoded, d = r - e > 0;
|
|
977
990
|
return e = r, { isReceiving: d, avgJitterDelayInInterval: n, freezeCount: o.freezeCount };
|
|
978
991
|
}
|
|
979
992
|
return { isReceiving: !1, avgJitterDelayInInterval: n };
|
|
980
993
|
};
|
|
981
994
|
}
|
|
982
|
-
function
|
|
983
|
-
let o = [], s,
|
|
984
|
-
const M =
|
|
995
|
+
function Ht(e, t, a, n, c) {
|
|
996
|
+
let o = [], s, i = 0, r = !1, d = re.Unknown, g = re.Unknown, w = 0, u = 0;
|
|
997
|
+
const M = qt();
|
|
985
998
|
return setInterval(async () => {
|
|
986
|
-
const
|
|
987
|
-
if (
|
|
988
|
-
|
|
989
|
-
else if (r && (
|
|
990
|
-
const
|
|
991
|
-
n == null || n(C.Stop,
|
|
999
|
+
const B = await e.getStats(), { isReceiving: q, avgJitterDelayInInterval: E, freezeCount: I } = M(B), z = Jt(B);
|
|
1000
|
+
if (q)
|
|
1001
|
+
i = 0, w = I - u, g = E < Ot ? re.Strong : E > Vt && w > 1 ? re.Weak : d, g !== d && (c == null || c(g), d = g, u += w, w = 0), r || (n == null || n(C.Start), s = o[o.length - 1], o = [], r = !0), o.push(z);
|
|
1002
|
+
else if (r && (i++, i >= Wt)) {
|
|
1003
|
+
const A = Ut(o, Me, s);
|
|
1004
|
+
n == null || n(C.Stop, A), t() || a(), u = I, r = !1;
|
|
992
1005
|
}
|
|
993
|
-
},
|
|
1006
|
+
}, Me);
|
|
994
1007
|
}
|
|
995
|
-
const
|
|
996
|
-
function
|
|
1008
|
+
const Qt = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
|
|
1009
|
+
function Be(e) {
|
|
997
1010
|
switch (e) {
|
|
998
1011
|
case "connected":
|
|
999
1012
|
return S.Connected;
|
|
@@ -1013,230 +1026,230 @@ function Le(e) {
|
|
|
1013
1026
|
return S.New;
|
|
1014
1027
|
}
|
|
1015
1028
|
}
|
|
1016
|
-
const
|
|
1017
|
-
const [
|
|
1029
|
+
const Xt = (e) => (t) => {
|
|
1030
|
+
const [a, n = ""] = t.split(/:(.+)/);
|
|
1018
1031
|
try {
|
|
1019
1032
|
const c = JSON.parse(n);
|
|
1020
|
-
return e("parsed data channel message", { subject:
|
|
1033
|
+
return e("parsed data channel message", { subject: a, data: c }), { subject: a, data: c };
|
|
1021
1034
|
} catch (c) {
|
|
1022
|
-
return e("Failed to parse data channel message, returning data as string", { subject:
|
|
1035
|
+
return e("Failed to parse data channel message, returning data as string", { subject: a, rawData: n, error: c }), { subject: a, data: n };
|
|
1023
1036
|
}
|
|
1024
1037
|
};
|
|
1025
|
-
function
|
|
1038
|
+
function Yt({
|
|
1026
1039
|
statsSignal: e,
|
|
1027
1040
|
dataChannelSignal: t,
|
|
1028
|
-
onVideoStateChange:
|
|
1041
|
+
onVideoStateChange: a,
|
|
1029
1042
|
report: n
|
|
1030
1043
|
}) {
|
|
1031
|
-
e === C.Start && t === C.Start ?
|
|
1044
|
+
e === C.Start && t === C.Start ? a == null || a(C.Start) : e === C.Stop && t === C.Stop && (a == null || a(C.Stop, n));
|
|
1032
1045
|
}
|
|
1033
|
-
function
|
|
1046
|
+
function Gt({
|
|
1034
1047
|
statsSignal: e,
|
|
1035
1048
|
dataChannelSignal: t,
|
|
1036
|
-
onVideoStateChange:
|
|
1049
|
+
onVideoStateChange: a,
|
|
1037
1050
|
onAgentActivityStateChange: n,
|
|
1038
1051
|
report: c
|
|
1039
1052
|
}) {
|
|
1040
|
-
e === C.Start ?
|
|
1053
|
+
e === C.Start ? a == null || a(C.Start) : e === C.Stop && (a == null || a(C.Stop, c)), t === C.Start ? n == null || n(J.Talking) : t === C.Stop && (n == null || n(J.Idle));
|
|
1041
1054
|
}
|
|
1042
|
-
function
|
|
1055
|
+
function Fe({
|
|
1043
1056
|
statsSignal: e,
|
|
1044
1057
|
dataChannelSignal: t,
|
|
1045
|
-
onVideoStateChange:
|
|
1058
|
+
onVideoStateChange: a,
|
|
1046
1059
|
onAgentActivityStateChange: n,
|
|
1047
1060
|
streamType: c,
|
|
1048
1061
|
report: o
|
|
1049
1062
|
}) {
|
|
1050
|
-
c ===
|
|
1063
|
+
c === ae.Legacy ? Yt({ statsSignal: e, dataChannelSignal: t, onVideoStateChange: a, report: o }) : c === ae.Fluent && Gt({
|
|
1051
1064
|
statsSignal: e,
|
|
1052
1065
|
dataChannelSignal: t,
|
|
1053
|
-
onVideoStateChange:
|
|
1066
|
+
onVideoStateChange: a,
|
|
1054
1067
|
onAgentActivityStateChange: n,
|
|
1055
1068
|
report: o
|
|
1056
1069
|
});
|
|
1057
1070
|
}
|
|
1058
|
-
async function
|
|
1059
|
-
var
|
|
1060
|
-
const r =
|
|
1061
|
-
let
|
|
1062
|
-
const { startConnection:
|
|
1071
|
+
async function Zt(e, t, { debug: a = !1, callbacks: n, auth: c, baseURL: o = he, analytics: s }, i) {
|
|
1072
|
+
var O;
|
|
1073
|
+
const r = qe(a, "WebRTCStreamingManager"), d = Xt(r);
|
|
1074
|
+
let g = !1, w = !1, u = C.Stop, M = C.Stop;
|
|
1075
|
+
const { startConnection: B, sendStreamRequest: q, close: E, createStream: I, addIceCandidate: z } = zt(
|
|
1063
1076
|
c,
|
|
1064
1077
|
o,
|
|
1065
1078
|
e,
|
|
1066
1079
|
n.onError
|
|
1067
1080
|
), {
|
|
1068
|
-
id:
|
|
1069
|
-
offer:
|
|
1070
|
-
ice_servers:
|
|
1071
|
-
session_id:
|
|
1072
|
-
fluent:
|
|
1073
|
-
interrupt_enabled:
|
|
1074
|
-
triggers_enabled:
|
|
1075
|
-
} = await
|
|
1076
|
-
(
|
|
1077
|
-
const y = new
|
|
1078
|
-
if (!
|
|
1081
|
+
id: A,
|
|
1082
|
+
offer: W,
|
|
1083
|
+
ice_servers: ee,
|
|
1084
|
+
session_id: T,
|
|
1085
|
+
fluent: G,
|
|
1086
|
+
interrupt_enabled: Z,
|
|
1087
|
+
triggers_enabled: m
|
|
1088
|
+
} = await I(t, i);
|
|
1089
|
+
(O = n.onStreamCreated) == null || O.call(n, { stream_id: A, session_id: T, agent_id: e });
|
|
1090
|
+
const y = new Qt({ iceServers: ee }), k = y.createDataChannel("JanusDataChannel");
|
|
1091
|
+
if (!T)
|
|
1079
1092
|
throw new Error("Could not create session_id");
|
|
1080
|
-
const
|
|
1093
|
+
const P = G ? ae.Fluent : ae.Legacy;
|
|
1081
1094
|
s.enrich({
|
|
1082
|
-
"stream-type":
|
|
1095
|
+
"stream-type": P
|
|
1083
1096
|
});
|
|
1084
|
-
const
|
|
1085
|
-
var
|
|
1086
|
-
|
|
1087
|
-
},
|
|
1097
|
+
const b = t.stream_warmup && !G, _ = () => g, U = () => {
|
|
1098
|
+
var f;
|
|
1099
|
+
g = !0, w && ((f = n.onConnectionStateChange) == null || f.call(n, S.Connected));
|
|
1100
|
+
}, H = Ht(
|
|
1088
1101
|
y,
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
(
|
|
1092
|
-
statsSignal: M =
|
|
1093
|
-
dataChannelSignal:
|
|
1102
|
+
_,
|
|
1103
|
+
U,
|
|
1104
|
+
(f, p) => Fe({
|
|
1105
|
+
statsSignal: M = f,
|
|
1106
|
+
dataChannelSignal: P === ae.Legacy ? u : void 0,
|
|
1094
1107
|
onVideoStateChange: n.onVideoStateChange,
|
|
1095
1108
|
onAgentActivityStateChange: n.onAgentActivityStateChange,
|
|
1096
|
-
report:
|
|
1097
|
-
streamType:
|
|
1109
|
+
report: p,
|
|
1110
|
+
streamType: P
|
|
1098
1111
|
}),
|
|
1099
|
-
(
|
|
1100
|
-
var
|
|
1101
|
-
return (
|
|
1112
|
+
(f) => {
|
|
1113
|
+
var p;
|
|
1114
|
+
return (p = n.onConnectivityStateChange) == null ? void 0 : p.call(n, f);
|
|
1102
1115
|
}
|
|
1103
1116
|
);
|
|
1104
|
-
y.onicecandidate = (
|
|
1105
|
-
var
|
|
1106
|
-
r("peerConnection.onicecandidate",
|
|
1117
|
+
y.onicecandidate = (f) => {
|
|
1118
|
+
var p;
|
|
1119
|
+
r("peerConnection.onicecandidate", f);
|
|
1107
1120
|
try {
|
|
1108
|
-
|
|
1109
|
-
|
|
1121
|
+
f.candidate && f.candidate.sdpMid && f.candidate.sdpMLineIndex !== null ? z(
|
|
1122
|
+
A,
|
|
1110
1123
|
{
|
|
1111
|
-
candidate:
|
|
1112
|
-
sdpMid:
|
|
1113
|
-
sdpMLineIndex:
|
|
1124
|
+
candidate: f.candidate.candidate,
|
|
1125
|
+
sdpMid: f.candidate.sdpMid,
|
|
1126
|
+
sdpMLineIndex: f.candidate.sdpMLineIndex
|
|
1114
1127
|
},
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
) :
|
|
1118
|
-
} catch (
|
|
1119
|
-
(
|
|
1128
|
+
T,
|
|
1129
|
+
i
|
|
1130
|
+
) : z(A, { candidate: null }, T, i);
|
|
1131
|
+
} catch ($) {
|
|
1132
|
+
(p = n.onError) == null || p.call(n, $, { streamId: A });
|
|
1120
1133
|
}
|
|
1121
|
-
},
|
|
1122
|
-
|
|
1134
|
+
}, k.onopen = () => {
|
|
1135
|
+
w = !0, (!b || g) && U();
|
|
1123
1136
|
};
|
|
1124
|
-
const
|
|
1125
|
-
var
|
|
1126
|
-
(
|
|
1137
|
+
const Q = (f) => {
|
|
1138
|
+
var p;
|
|
1139
|
+
(p = n.onVideoIdChange) == null || p.call(n, f);
|
|
1127
1140
|
};
|
|
1128
|
-
function
|
|
1129
|
-
if (
|
|
1130
|
-
const
|
|
1131
|
-
|
|
1141
|
+
function j(f, p) {
|
|
1142
|
+
if (f === x.StreamStarted && typeof p == "object" && "metadata" in p) {
|
|
1143
|
+
const $ = p.metadata;
|
|
1144
|
+
Q($.videoId);
|
|
1132
1145
|
}
|
|
1133
|
-
|
|
1134
|
-
statsSignal:
|
|
1146
|
+
f === x.StreamDone && Q(null), u = f === x.StreamStarted ? C.Start : C.Stop, Fe({
|
|
1147
|
+
statsSignal: P === ae.Legacy ? M : void 0,
|
|
1135
1148
|
dataChannelSignal: u,
|
|
1136
1149
|
onVideoStateChange: n.onVideoStateChange,
|
|
1137
1150
|
onAgentActivityStateChange: n.onAgentActivityStateChange,
|
|
1138
|
-
streamType:
|
|
1151
|
+
streamType: P
|
|
1139
1152
|
});
|
|
1140
1153
|
}
|
|
1141
|
-
function
|
|
1142
|
-
var
|
|
1143
|
-
const
|
|
1144
|
-
|
|
1154
|
+
function N(f, p) {
|
|
1155
|
+
var V;
|
|
1156
|
+
const $ = typeof p == "string" ? p : p == null ? void 0 : p.metadata;
|
|
1157
|
+
$ && s.enrich({ streamMetadata: $ }), (V = n.onStreamReady) == null || V.call(n);
|
|
1145
1158
|
}
|
|
1146
|
-
const
|
|
1147
|
-
[
|
|
1148
|
-
[
|
|
1149
|
-
[
|
|
1159
|
+
const X = {
|
|
1160
|
+
[x.StreamStarted]: j,
|
|
1161
|
+
[x.StreamDone]: j,
|
|
1162
|
+
[x.StreamReady]: N
|
|
1150
1163
|
};
|
|
1151
|
-
|
|
1152
|
-
var
|
|
1153
|
-
const { subject:
|
|
1154
|
-
(
|
|
1164
|
+
k.onmessage = (f) => {
|
|
1165
|
+
var V;
|
|
1166
|
+
const { subject: p, data: $ } = d(f.data);
|
|
1167
|
+
(V = X[p]) == null || V.call(X, p, $);
|
|
1155
1168
|
}, y.oniceconnectionstatechange = () => {
|
|
1156
|
-
var
|
|
1169
|
+
var p;
|
|
1157
1170
|
r("peerConnection.oniceconnectionstatechange => " + y.iceConnectionState);
|
|
1158
|
-
const
|
|
1159
|
-
|
|
1160
|
-
}, y.ontrack = (
|
|
1161
|
-
var
|
|
1162
|
-
r("peerConnection.ontrack",
|
|
1163
|
-
}, await y.setRemoteDescription(
|
|
1164
|
-
const
|
|
1165
|
-
return r("create answer OK"), await y.setLocalDescription(
|
|
1171
|
+
const f = Be(y.iceConnectionState);
|
|
1172
|
+
f !== S.Connected && ((p = n.onConnectionStateChange) == null || p.call(n, f));
|
|
1173
|
+
}, y.ontrack = (f) => {
|
|
1174
|
+
var p;
|
|
1175
|
+
r("peerConnection.ontrack", f), (p = n.onSrcObjectReady) == null || p.call(n, f.streams[0]);
|
|
1176
|
+
}, await y.setRemoteDescription(W), r("set remote description OK");
|
|
1177
|
+
const se = await y.createAnswer();
|
|
1178
|
+
return r("create answer OK"), await y.setLocalDescription(se), r("set local description OK"), await B(A, se, T, i), r("start connection OK"), {
|
|
1166
1179
|
/**
|
|
1167
1180
|
* Method to send request to server to get clip or talk depend on you payload
|
|
1168
1181
|
* @param payload
|
|
1169
1182
|
*/
|
|
1170
|
-
speak(
|
|
1171
|
-
return
|
|
1183
|
+
speak(f) {
|
|
1184
|
+
return q(A, T, f);
|
|
1172
1185
|
},
|
|
1173
1186
|
/**
|
|
1174
1187
|
* Method to close RTC connection
|
|
1175
1188
|
*/
|
|
1176
1189
|
async disconnect() {
|
|
1177
|
-
var
|
|
1178
|
-
if (
|
|
1179
|
-
const
|
|
1190
|
+
var f;
|
|
1191
|
+
if (A) {
|
|
1192
|
+
const p = Be(y.iceConnectionState);
|
|
1180
1193
|
if (y) {
|
|
1181
|
-
if (
|
|
1182
|
-
clearInterval(
|
|
1194
|
+
if (p === S.New) {
|
|
1195
|
+
clearInterval(H);
|
|
1183
1196
|
return;
|
|
1184
1197
|
}
|
|
1185
1198
|
y.close(), y.oniceconnectionstatechange = null, y.onnegotiationneeded = null, y.onicecandidate = null, y.ontrack = null;
|
|
1186
1199
|
}
|
|
1187
1200
|
try {
|
|
1188
|
-
|
|
1201
|
+
p === S.Connected && await E(A, T).catch(($) => {
|
|
1189
1202
|
});
|
|
1190
|
-
} catch (
|
|
1191
|
-
r("Error on close stream connection",
|
|
1203
|
+
} catch ($) {
|
|
1204
|
+
r("Error on close stream connection", $);
|
|
1192
1205
|
}
|
|
1193
|
-
(
|
|
1206
|
+
(f = n.onAgentActivityStateChange) == null || f.call(n, J.Idle), clearInterval(H);
|
|
1194
1207
|
}
|
|
1195
1208
|
},
|
|
1196
1209
|
/**
|
|
1197
1210
|
* Method to send data channel messages to the server
|
|
1198
1211
|
*/
|
|
1199
|
-
sendDataChannelMessage(
|
|
1200
|
-
var
|
|
1201
|
-
if (!
|
|
1202
|
-
r("Data channel is not ready for sending messages"), (
|
|
1203
|
-
streamId:
|
|
1212
|
+
sendDataChannelMessage(f) {
|
|
1213
|
+
var p, $;
|
|
1214
|
+
if (!g || k.readyState !== "open") {
|
|
1215
|
+
r("Data channel is not ready for sending messages"), (p = n.onError) == null || p.call(n, new Error("Data channel is not ready for sending messages"), {
|
|
1216
|
+
streamId: A
|
|
1204
1217
|
});
|
|
1205
1218
|
return;
|
|
1206
1219
|
}
|
|
1207
1220
|
try {
|
|
1208
|
-
|
|
1209
|
-
} catch (
|
|
1210
|
-
r("Error sending data channel message",
|
|
1221
|
+
k.send(f);
|
|
1222
|
+
} catch (V) {
|
|
1223
|
+
r("Error sending data channel message", V), ($ = n.onError) == null || $.call(n, V, { streamId: A });
|
|
1211
1224
|
}
|
|
1212
1225
|
},
|
|
1213
1226
|
/**
|
|
1214
1227
|
* Session identifier information, should be returned in the body of all streaming requests
|
|
1215
1228
|
*/
|
|
1216
|
-
sessionId:
|
|
1229
|
+
sessionId: T,
|
|
1217
1230
|
/**
|
|
1218
1231
|
* Id of current RTC stream
|
|
1219
1232
|
*/
|
|
1220
|
-
streamId:
|
|
1221
|
-
streamType:
|
|
1222
|
-
interruptAvailable:
|
|
1223
|
-
triggersAvailable:
|
|
1233
|
+
streamId: A,
|
|
1234
|
+
streamType: P,
|
|
1235
|
+
interruptAvailable: Z ?? !1,
|
|
1236
|
+
triggersAvailable: m ?? !1
|
|
1224
1237
|
};
|
|
1225
1238
|
}
|
|
1226
|
-
var
|
|
1227
|
-
async function
|
|
1239
|
+
var Ee = /* @__PURE__ */ ((e) => (e.V1 = "v1", e.V2 = "v2", e))(Ee || {});
|
|
1240
|
+
async function en(e, t, a, n) {
|
|
1228
1241
|
const c = e.id;
|
|
1229
1242
|
switch (t.version) {
|
|
1230
1243
|
case "v1": {
|
|
1231
1244
|
const { version: o, ...s } = t;
|
|
1232
|
-
return
|
|
1245
|
+
return Zt(c, s, a, n);
|
|
1233
1246
|
}
|
|
1234
1247
|
case "v2": {
|
|
1235
1248
|
const { version: o, ...s } = t;
|
|
1236
1249
|
switch (s.transport_provider) {
|
|
1237
|
-
case
|
|
1238
|
-
const { createLiveKitStreamingManager:
|
|
1239
|
-
return
|
|
1250
|
+
case ye.Livekit:
|
|
1251
|
+
const { createLiveKitStreamingManager: i } = await Promise.resolve().then(() => Tt);
|
|
1252
|
+
return i(c, s, a);
|
|
1240
1253
|
default:
|
|
1241
1254
|
throw new Error(`Unsupported transport provider: ${s.transport_provider}`);
|
|
1242
1255
|
}
|
|
@@ -1245,15 +1258,15 @@ async function Yt(e, t, i, n) {
|
|
|
1245
1258
|
throw new Error(`Invalid stream version: ${t.version}`);
|
|
1246
1259
|
}
|
|
1247
1260
|
}
|
|
1248
|
-
const
|
|
1249
|
-
function
|
|
1261
|
+
const tn = "cht";
|
|
1262
|
+
function nn() {
|
|
1250
1263
|
return {
|
|
1251
|
-
transport_provider:
|
|
1264
|
+
transport_provider: ye.Livekit
|
|
1252
1265
|
};
|
|
1253
1266
|
}
|
|
1254
|
-
function
|
|
1267
|
+
function rn(e) {
|
|
1255
1268
|
var c, o;
|
|
1256
|
-
const { streamOptions: t } = e ?? {},
|
|
1269
|
+
const { streamOptions: t } = e ?? {}, a = ((c = e == null ? void 0 : e.mixpanelAdditionalProperties) == null ? void 0 : c.plan) !== void 0 ? {
|
|
1257
1270
|
plan: (o = e.mixpanelAdditionalProperties) == null ? void 0 : o.plan
|
|
1258
1271
|
} : void 0;
|
|
1259
1272
|
return { ...{
|
|
@@ -1262,30 +1275,30 @@ function en(e) {
|
|
|
1262
1275
|
stream_warmup: t == null ? void 0 : t.streamWarmup,
|
|
1263
1276
|
compatibility_mode: t == null ? void 0 : t.compatibilityMode,
|
|
1264
1277
|
fluent: t == null ? void 0 : t.fluent
|
|
1265
|
-
}, ...
|
|
1278
|
+
}, ...a && { end_user_data: a } };
|
|
1266
1279
|
}
|
|
1267
|
-
function
|
|
1268
|
-
return
|
|
1280
|
+
function an(e, t) {
|
|
1281
|
+
return Ie(e.presenter.type) ? { version: Ee.V2, ...nn() } : { version: Ee.V1, ...rn(t) };
|
|
1269
1282
|
}
|
|
1270
|
-
function
|
|
1271
|
-
c ===
|
|
1283
|
+
function on(e, t, a, n, c) {
|
|
1284
|
+
c === ae.Fluent ? sn(e, t, a, n, c) : dn(e, t, a, n, c);
|
|
1272
1285
|
}
|
|
1273
|
-
function
|
|
1286
|
+
function sn(e, t, a, n, c) {
|
|
1274
1287
|
e === C.Start ? n.track("stream-session", { event: "start", "stream-type": c }) : e === C.Stop && n.track("stream-session", {
|
|
1275
1288
|
event: "stop",
|
|
1276
1289
|
is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
|
|
1277
1290
|
background: t.presenter.type === "clip" && t.presenter.background,
|
|
1278
1291
|
"stream-type": c,
|
|
1279
|
-
...
|
|
1292
|
+
...a
|
|
1280
1293
|
});
|
|
1281
1294
|
}
|
|
1282
|
-
function
|
|
1283
|
-
|
|
1295
|
+
function cn(e, t, a, n) {
|
|
1296
|
+
ie.get() <= 0 || (e === C.Start ? a.linkTrack(
|
|
1284
1297
|
"agent-video",
|
|
1285
|
-
{ event: "start", latency:
|
|
1298
|
+
{ event: "start", latency: ie.get(!0), "stream-type": n },
|
|
1286
1299
|
"start",
|
|
1287
|
-
[
|
|
1288
|
-
) : e === C.Stop &&
|
|
1300
|
+
[x.StreamVideoCreated]
|
|
1301
|
+
) : e === C.Stop && a.linkTrack(
|
|
1289
1302
|
"agent-video",
|
|
1290
1303
|
{
|
|
1291
1304
|
event: "stop",
|
|
@@ -1294,15 +1307,15 @@ function an(e, t, i, n) {
|
|
|
1294
1307
|
"stream-type": n
|
|
1295
1308
|
},
|
|
1296
1309
|
"done",
|
|
1297
|
-
[
|
|
1310
|
+
[x.StreamVideoDone]
|
|
1298
1311
|
));
|
|
1299
1312
|
}
|
|
1300
|
-
function
|
|
1301
|
-
|
|
1313
|
+
function dn(e, t, a, n, c) {
|
|
1314
|
+
ie.get() <= 0 || (e === C.Start ? n.linkTrack(
|
|
1302
1315
|
"agent-video",
|
|
1303
|
-
{ event: "start", latency:
|
|
1316
|
+
{ event: "start", latency: ie.get(!0), "stream-type": c },
|
|
1304
1317
|
"start",
|
|
1305
|
-
[
|
|
1318
|
+
[x.StreamVideoCreated]
|
|
1306
1319
|
) : e === C.Stop && n.linkTrack(
|
|
1307
1320
|
"agent-video",
|
|
1308
1321
|
{
|
|
@@ -1310,397 +1323,413 @@ function on(e, t, i, n, c) {
|
|
|
1310
1323
|
is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
|
|
1311
1324
|
background: t.presenter.type === "clip" && t.presenter.background,
|
|
1312
1325
|
"stream-type": c,
|
|
1313
|
-
...
|
|
1326
|
+
...a
|
|
1314
1327
|
},
|
|
1315
1328
|
"done",
|
|
1316
|
-
[
|
|
1329
|
+
[x.StreamVideoDone]
|
|
1317
1330
|
));
|
|
1318
1331
|
}
|
|
1319
|
-
function
|
|
1320
|
-
return
|
|
1332
|
+
function ze(e, t, a, n) {
|
|
1333
|
+
return ie.reset(), xe.update(), new Promise(async (c, o) => {
|
|
1321
1334
|
try {
|
|
1322
|
-
let s,
|
|
1323
|
-
const r =
|
|
1324
|
-
|
|
1335
|
+
let s, i = !1;
|
|
1336
|
+
const r = an(e, t);
|
|
1337
|
+
a.enrich({
|
|
1325
1338
|
"stream-version": r.version.toString()
|
|
1326
|
-
}), s = await
|
|
1339
|
+
}), s = await en(
|
|
1327
1340
|
e,
|
|
1328
1341
|
r,
|
|
1329
1342
|
{
|
|
1330
1343
|
...t,
|
|
1331
|
-
analytics:
|
|
1344
|
+
analytics: a,
|
|
1332
1345
|
callbacks: {
|
|
1333
1346
|
...t.callbacks,
|
|
1334
1347
|
onConnectionStateChange: (d) => {
|
|
1335
|
-
var
|
|
1336
|
-
(
|
|
1348
|
+
var g, w;
|
|
1349
|
+
(w = (g = t.callbacks).onConnectionStateChange) == null || w.call(g, d), d === S.Connected && (s ? c(s) : i = !0);
|
|
1337
1350
|
},
|
|
1338
|
-
onVideoStateChange: (d,
|
|
1339
|
-
var
|
|
1340
|
-
(u = (
|
|
1351
|
+
onVideoStateChange: (d, g) => {
|
|
1352
|
+
var w, u;
|
|
1353
|
+
(u = (w = t.callbacks).onVideoStateChange) == null || u.call(w, d), on(
|
|
1341
1354
|
d,
|
|
1342
1355
|
e,
|
|
1343
|
-
|
|
1344
|
-
|
|
1356
|
+
g,
|
|
1357
|
+
a,
|
|
1345
1358
|
s.streamType
|
|
1346
1359
|
);
|
|
1347
1360
|
},
|
|
1348
1361
|
onAgentActivityStateChange: (d) => {
|
|
1349
|
-
var
|
|
1350
|
-
(
|
|
1351
|
-
d ===
|
|
1362
|
+
var g, w;
|
|
1363
|
+
(w = (g = t.callbacks).onAgentActivityStateChange) == null || w.call(g, d), d === J.Talking ? Re.update() : Re.reset(), cn(
|
|
1364
|
+
d === J.Talking ? C.Start : C.Stop,
|
|
1352
1365
|
e,
|
|
1353
|
-
|
|
1366
|
+
a,
|
|
1354
1367
|
s.streamType
|
|
1355
1368
|
);
|
|
1356
1369
|
},
|
|
1357
1370
|
onStreamReady: () => {
|
|
1358
|
-
const d =
|
|
1359
|
-
|
|
1371
|
+
const d = xe.get(!0);
|
|
1372
|
+
a.track("agent-chat", { event: "ready", latency: d });
|
|
1360
1373
|
}
|
|
1361
1374
|
}
|
|
1362
1375
|
},
|
|
1363
1376
|
n
|
|
1364
|
-
),
|
|
1377
|
+
), i && c(s);
|
|
1365
1378
|
} catch (s) {
|
|
1366
1379
|
o(s);
|
|
1367
1380
|
}
|
|
1368
1381
|
});
|
|
1369
1382
|
}
|
|
1370
|
-
async function
|
|
1371
|
-
var
|
|
1383
|
+
async function un(e, t, a, n, c) {
|
|
1384
|
+
var g, w, u, M;
|
|
1372
1385
|
const o = async () => {
|
|
1373
|
-
if (
|
|
1374
|
-
const
|
|
1386
|
+
if (Ie(e.presenter.type)) {
|
|
1387
|
+
const B = await ze(e, t, n), q = `${tn}_${B.sessionId}`, E = (/* @__PURE__ */ new Date()).toISOString();
|
|
1375
1388
|
return { chatResult: {
|
|
1376
|
-
chatMode:
|
|
1389
|
+
chatMode: F.Functional,
|
|
1377
1390
|
chat: {
|
|
1378
|
-
id:
|
|
1391
|
+
id: q,
|
|
1379
1392
|
agent_id: e.id,
|
|
1380
1393
|
owner_id: e.owner_id ?? "",
|
|
1381
|
-
created:
|
|
1382
|
-
modified:
|
|
1383
|
-
agent_id__created_at:
|
|
1384
|
-
agent_id__modified_at:
|
|
1385
|
-
chat_mode:
|
|
1394
|
+
created: E,
|
|
1395
|
+
modified: E,
|
|
1396
|
+
agent_id__created_at: E,
|
|
1397
|
+
agent_id__modified_at: E,
|
|
1398
|
+
chat_mode: F.Functional,
|
|
1386
1399
|
messages: []
|
|
1387
1400
|
}
|
|
1388
|
-
}, streamingManager:
|
|
1401
|
+
}, streamingManager: B };
|
|
1389
1402
|
} else {
|
|
1390
|
-
const
|
|
1391
|
-
let
|
|
1403
|
+
const B = new AbortController(), q = B.signal;
|
|
1404
|
+
let E;
|
|
1392
1405
|
try {
|
|
1393
|
-
const
|
|
1406
|
+
const I = Ve(
|
|
1394
1407
|
e,
|
|
1395
|
-
|
|
1408
|
+
a,
|
|
1396
1409
|
n,
|
|
1397
1410
|
t.mode,
|
|
1398
1411
|
t.persistentChat,
|
|
1399
1412
|
c
|
|
1400
|
-
),
|
|
1401
|
-
return { chatResult:
|
|
1402
|
-
} catch (
|
|
1403
|
-
throw
|
|
1404
|
-
}),
|
|
1413
|
+
), z = ze(e, t, n, q).then((ee) => (E = ee, ee)), [A, W] = await Promise.all([I, z]);
|
|
1414
|
+
return { chatResult: A, streamingManager: W };
|
|
1415
|
+
} catch (I) {
|
|
1416
|
+
throw B.abort(), E && await E.disconnect().catch(() => {
|
|
1417
|
+
}), I;
|
|
1405
1418
|
}
|
|
1406
1419
|
}
|
|
1407
|
-
}, { chatResult: s, streamingManager:
|
|
1408
|
-
return d && t.mode !== void 0 && d !== t.mode && (t.mode = d, (
|
|
1420
|
+
}, { chatResult: s, streamingManager: i } = await o(), { chat: r, chatMode: d } = s;
|
|
1421
|
+
return d && t.mode !== void 0 && d !== t.mode && (t.mode = d, (w = (g = t.callbacks).onModeChange) == null || w.call(g, d), d !== F.Functional) ? ((M = (u = t.callbacks).onError) == null || M.call(u, new Ye(d)), i == null || i.disconnect(), { chat: r }) : { chat: r, streamingManager: i };
|
|
1409
1422
|
}
|
|
1410
|
-
async function
|
|
1411
|
-
var
|
|
1412
|
-
let
|
|
1413
|
-
const c = t.mixpanelKey ||
|
|
1423
|
+
async function mn(e, t) {
|
|
1424
|
+
var T, G, Z;
|
|
1425
|
+
let a = !0, n = null;
|
|
1426
|
+
const c = t.mixpanelKey || lt, o = t.wsURL || ut, s = t.baseURL || he, i = t.mode || F.Functional, r = {
|
|
1414
1427
|
messages: [],
|
|
1415
|
-
chatMode:
|
|
1416
|
-
}, d =
|
|
1428
|
+
chatMode: i
|
|
1429
|
+
}, d = kt({
|
|
1417
1430
|
token: c,
|
|
1418
1431
|
agentId: e,
|
|
1419
1432
|
isEnabled: t.enableAnalitics,
|
|
1420
1433
|
externalId: t.externalId,
|
|
1421
1434
|
mixpanelAdditionalProperties: t.mixpanelAdditionalProperties
|
|
1422
|
-
}),
|
|
1423
|
-
|
|
1424
|
-
d.track("agent-sdk", { event: "init" },
|
|
1435
|
+
}), g = Date.now();
|
|
1436
|
+
$e(() => {
|
|
1437
|
+
d.track("agent-sdk", { event: "init" }, g);
|
|
1425
1438
|
});
|
|
1426
|
-
const
|
|
1427
|
-
d.enrich(
|
|
1428
|
-
const { onMessage:
|
|
1439
|
+
const w = pt(t.auth, s, t.callbacks.onError, t.externalId), u = await w.getById(e), M = Ie(u.presenter.type);
|
|
1440
|
+
d.enrich(yt(u));
|
|
1441
|
+
const { onMessage: B, clearQueue: q } = Ft(
|
|
1429
1442
|
d,
|
|
1430
1443
|
r,
|
|
1431
1444
|
t,
|
|
1432
1445
|
u,
|
|
1433
1446
|
() => {
|
|
1434
|
-
var
|
|
1435
|
-
return (
|
|
1447
|
+
var m;
|
|
1448
|
+
return (m = r.socketManager) == null ? void 0 : m.disconnect();
|
|
1436
1449
|
}
|
|
1437
1450
|
);
|
|
1438
|
-
r.messages =
|
|
1439
|
-
const
|
|
1440
|
-
n =
|
|
1441
|
-
},
|
|
1442
|
-
|
|
1443
|
-
|
|
1451
|
+
r.messages = Dt(t.initialMessages), (G = (T = t.callbacks).onNewMessage) == null || G.call(T, [...r.messages], "answer");
|
|
1452
|
+
const E = (m) => {
|
|
1453
|
+
n = m;
|
|
1454
|
+
}, I = ({ type: m }) => {
|
|
1455
|
+
var k, P, b;
|
|
1456
|
+
const y = r.messages[r.messages.length - 1];
|
|
1457
|
+
d.track("agent-video-interrupt", {
|
|
1458
|
+
type: m || "click",
|
|
1459
|
+
video_duration_to_interrupt: Re.get(!0),
|
|
1460
|
+
message_duration_to_interrupt: ie.get(!0)
|
|
1461
|
+
}), y.interrupted = !0, (P = (k = t.callbacks).onNewMessage) == null || P.call(k, [...r.messages], "answer"), M ? Pt(r.streamingManager) : (_t(r.streamingManager, (b = r.streamingManager) == null ? void 0 : b.streamType, n), At(r.streamingManager, n));
|
|
1462
|
+
}, z = Date.now();
|
|
1463
|
+
$e(() => {
|
|
1464
|
+
d.track("agent-sdk", { event: "loaded", ...wt(u) }, z);
|
|
1444
1465
|
});
|
|
1445
|
-
async function
|
|
1446
|
-
var
|
|
1447
|
-
(H = (
|
|
1448
|
-
const
|
|
1466
|
+
async function A(m) {
|
|
1467
|
+
var U, H, Q, j, N, X, se;
|
|
1468
|
+
(H = (U = t.callbacks).onConnectionStateChange) == null || H.call(U, S.Connecting), ie.reset(), m && !a && (delete r.chat, (j = (Q = t.callbacks).onNewMessage) == null || j.call(Q, [...r.messages], "answer"));
|
|
1469
|
+
const y = i === F.DirectPlayback || M ? Promise.resolve(void 0) : jt(
|
|
1449
1470
|
t.auth,
|
|
1450
1471
|
o,
|
|
1451
|
-
{ onMessage:
|
|
1472
|
+
{ onMessage: B, onError: t.callbacks.onError },
|
|
1452
1473
|
t.externalId
|
|
1453
|
-
),
|
|
1454
|
-
() =>
|
|
1474
|
+
), k = Ce(
|
|
1475
|
+
() => un(
|
|
1455
1476
|
u,
|
|
1456
1477
|
{
|
|
1457
1478
|
...t,
|
|
1458
|
-
mode:
|
|
1459
|
-
callbacks: {
|
|
1479
|
+
mode: i,
|
|
1480
|
+
callbacks: {
|
|
1481
|
+
...t.callbacks,
|
|
1482
|
+
onVideoIdChange: E,
|
|
1483
|
+
onMessage: B,
|
|
1484
|
+
onInterruptDetected: I
|
|
1485
|
+
}
|
|
1460
1486
|
},
|
|
1461
|
-
|
|
1487
|
+
w,
|
|
1462
1488
|
d,
|
|
1463
1489
|
r.chat
|
|
1464
1490
|
),
|
|
1465
1491
|
{
|
|
1466
1492
|
limit: 3,
|
|
1467
|
-
timeout:
|
|
1493
|
+
timeout: ct,
|
|
1468
1494
|
timeoutErrorMessage: "Timeout initializing the stream",
|
|
1469
|
-
shouldRetryFn: (
|
|
1495
|
+
shouldRetryFn: (O) => (O == null ? void 0 : O.message) !== "Could not connect" && O.status !== 429 && (O == null ? void 0 : O.message) !== "InsufficientCreditsError",
|
|
1470
1496
|
delayMs: 1e3
|
|
1471
1497
|
}
|
|
1472
|
-
).catch((
|
|
1473
|
-
var
|
|
1474
|
-
throw
|
|
1475
|
-
}), [
|
|
1476
|
-
_ && _.id !== ((
|
|
1498
|
+
).catch((O) => {
|
|
1499
|
+
var f, p;
|
|
1500
|
+
throw ee(F.Maintenance), (p = (f = t.callbacks).onConnectionStateChange) == null || p.call(f, S.Fail), O;
|
|
1501
|
+
}), [P, { streamingManager: b, chat: _ }] = await Promise.all([y, k]);
|
|
1502
|
+
_ && _.id !== ((N = r.chat) == null ? void 0 : N.id) && ((se = (X = t.callbacks).onNewChat) == null || se.call(X, _.id)), r.streamingManager = b, r.socketManager = P, r.chat = _, a = !1, d.enrich({
|
|
1477
1503
|
chatId: _ == null ? void 0 : _.id,
|
|
1478
|
-
streamId:
|
|
1504
|
+
streamId: b == null ? void 0 : b.streamId,
|
|
1479
1505
|
mode: r.chatMode
|
|
1480
|
-
}),
|
|
1506
|
+
}), ee((_ == null ? void 0 : _.chat_mode) ?? i);
|
|
1481
1507
|
}
|
|
1482
|
-
async function
|
|
1483
|
-
var
|
|
1484
|
-
(
|
|
1508
|
+
async function W() {
|
|
1509
|
+
var m, y, k, P;
|
|
1510
|
+
(m = r.socketManager) == null || m.disconnect(), await ((y = r.streamingManager) == null ? void 0 : y.disconnect()), delete r.streamingManager, delete r.socketManager, (P = (k = t.callbacks).onConnectionStateChange) == null || P.call(k, S.Disconnected);
|
|
1485
1511
|
}
|
|
1486
|
-
async function
|
|
1487
|
-
var
|
|
1488
|
-
|
|
1512
|
+
async function ee(m) {
|
|
1513
|
+
var y, k;
|
|
1514
|
+
m !== r.chatMode && (d.track("agent-mode-change", { mode: m }), r.chatMode = m, r.chatMode !== F.Functional && await W(), (k = (y = t.callbacks).onModeChange) == null || k.call(y, m));
|
|
1489
1515
|
}
|
|
1490
1516
|
return {
|
|
1491
1517
|
agent: u,
|
|
1492
1518
|
getStreamType: () => {
|
|
1493
|
-
var
|
|
1494
|
-
return (
|
|
1519
|
+
var m;
|
|
1520
|
+
return (m = r.streamingManager) == null ? void 0 : m.streamType;
|
|
1495
1521
|
},
|
|
1496
1522
|
getIsInterruptAvailable: () => {
|
|
1497
|
-
var
|
|
1498
|
-
return ((
|
|
1523
|
+
var m;
|
|
1524
|
+
return ((m = r.streamingManager) == null ? void 0 : m.interruptAvailable) ?? !1;
|
|
1499
1525
|
},
|
|
1500
1526
|
getIsTriggersAvailable: () => {
|
|
1501
|
-
var
|
|
1502
|
-
return ((
|
|
1527
|
+
var m;
|
|
1528
|
+
return ((m = r.streamingManager) == null ? void 0 : m.triggersAvailable) ?? !1;
|
|
1503
1529
|
},
|
|
1504
|
-
starterMessages: ((
|
|
1505
|
-
getSTTToken: () =>
|
|
1506
|
-
changeMode:
|
|
1530
|
+
starterMessages: ((Z = u.knowledge) == null ? void 0 : Z.starter_message) || [],
|
|
1531
|
+
getSTTToken: () => w.getSTTToken(u.id),
|
|
1532
|
+
changeMode: ee,
|
|
1507
1533
|
enrichAnalytics: d.enrich,
|
|
1508
1534
|
async connect() {
|
|
1509
|
-
await
|
|
1535
|
+
await A(!0), d.track("agent-chat", {
|
|
1510
1536
|
event: "connect",
|
|
1511
1537
|
mode: r.chatMode
|
|
1512
1538
|
});
|
|
1513
1539
|
},
|
|
1514
1540
|
async reconnect() {
|
|
1515
|
-
const
|
|
1516
|
-
if (M && (
|
|
1541
|
+
const m = r.streamingManager;
|
|
1542
|
+
if (M && (m != null && m.reconnect)) {
|
|
1517
1543
|
try {
|
|
1518
|
-
await
|
|
1544
|
+
await m.reconnect(), d.track("agent-chat", {
|
|
1519
1545
|
event: "reconnect",
|
|
1520
1546
|
mode: r.chatMode
|
|
1521
1547
|
});
|
|
1522
1548
|
} catch {
|
|
1523
|
-
await
|
|
1549
|
+
await W(), await A(!1);
|
|
1524
1550
|
}
|
|
1525
1551
|
return;
|
|
1526
1552
|
}
|
|
1527
|
-
await
|
|
1553
|
+
await W(), await A(!1), d.track("agent-chat", {
|
|
1528
1554
|
event: "reconnect",
|
|
1529
1555
|
mode: r.chatMode
|
|
1530
1556
|
});
|
|
1531
1557
|
},
|
|
1532
1558
|
async disconnect() {
|
|
1533
|
-
await
|
|
1559
|
+
await W(), d.track("agent-chat", {
|
|
1534
1560
|
event: "disconnect",
|
|
1535
1561
|
mode: r.chatMode
|
|
1536
1562
|
});
|
|
1537
1563
|
},
|
|
1538
|
-
async publishMicrophoneStream(
|
|
1539
|
-
var
|
|
1540
|
-
if (!((
|
|
1564
|
+
async publishMicrophoneStream(m) {
|
|
1565
|
+
var y;
|
|
1566
|
+
if (!((y = r.streamingManager) != null && y.publishMicrophoneStream))
|
|
1541
1567
|
throw new Error("publishMicrophoneStream is not available for this streaming manager");
|
|
1542
|
-
return r.streamingManager.publishMicrophoneStream(
|
|
1568
|
+
return r.streamingManager.publishMicrophoneStream(m);
|
|
1543
1569
|
},
|
|
1544
1570
|
async unpublishMicrophoneStream() {
|
|
1545
|
-
var
|
|
1546
|
-
if (!((
|
|
1571
|
+
var m;
|
|
1572
|
+
if (!((m = r.streamingManager) != null && m.unpublishMicrophoneStream))
|
|
1547
1573
|
throw new Error("unpublishMicrophoneStream is not available for this streaming manager");
|
|
1548
1574
|
return r.streamingManager.unpublishMicrophoneStream();
|
|
1549
1575
|
},
|
|
1550
|
-
async chat(
|
|
1551
|
-
var
|
|
1552
|
-
const
|
|
1553
|
-
if (
|
|
1554
|
-
throw new
|
|
1555
|
-
if (
|
|
1556
|
-
throw new
|
|
1557
|
-
if (
|
|
1558
|
-
throw new
|
|
1559
|
-
if (r.chatMode ===
|
|
1560
|
-
throw new
|
|
1561
|
-
if (![
|
|
1576
|
+
async chat(m) {
|
|
1577
|
+
var b, _, U, H, Q;
|
|
1578
|
+
const y = () => {
|
|
1579
|
+
if (Ue(i))
|
|
1580
|
+
throw new de(`${i} is enabled, chat is disabled`);
|
|
1581
|
+
if (m.length >= 800)
|
|
1582
|
+
throw new de("Message cannot be more than 800 characters");
|
|
1583
|
+
if (m.length === 0)
|
|
1584
|
+
throw new de("Message cannot be empty");
|
|
1585
|
+
if (r.chatMode === F.Maintenance)
|
|
1586
|
+
throw new de("Chat is in maintenance mode");
|
|
1587
|
+
if (![F.TextOnly, F.Playground].includes(r.chatMode)) {
|
|
1562
1588
|
if (!r.streamingManager)
|
|
1563
|
-
throw new
|
|
1589
|
+
throw new de("Streaming manager is not initialized");
|
|
1564
1590
|
if (!r.chat)
|
|
1565
|
-
throw new
|
|
1591
|
+
throw new de("Chat is not initialized");
|
|
1566
1592
|
}
|
|
1567
|
-
},
|
|
1568
|
-
var j,
|
|
1593
|
+
}, k = async () => {
|
|
1594
|
+
var j, N;
|
|
1569
1595
|
if (!r.chat) {
|
|
1570
|
-
const
|
|
1596
|
+
const X = await Ve(
|
|
1571
1597
|
u,
|
|
1572
|
-
|
|
1598
|
+
w,
|
|
1573
1599
|
d,
|
|
1574
1600
|
r.chatMode,
|
|
1575
1601
|
t.persistentChat
|
|
1576
1602
|
);
|
|
1577
|
-
if (!
|
|
1578
|
-
throw new
|
|
1579
|
-
r.chat =
|
|
1603
|
+
if (!X.chat)
|
|
1604
|
+
throw new Xe(r.chatMode, !!t.persistentChat);
|
|
1605
|
+
r.chat = X.chat, (N = (j = t.callbacks).onNewChat) == null || N.call(j, r.chat.id);
|
|
1580
1606
|
}
|
|
1581
1607
|
return r.chat.id;
|
|
1582
|
-
},
|
|
1583
|
-
|
|
1584
|
-
return
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1608
|
+
}, P = async (j, N) => {
|
|
1609
|
+
const X = r.chatMode === F.Playground;
|
|
1610
|
+
return Ce(M && !X ? async () => {
|
|
1611
|
+
var f, p;
|
|
1612
|
+
return await ((p = (f = r.streamingManager) == null ? void 0 : f.sendTextMessage) == null ? void 0 : p.call(f, m)), Promise.resolve({});
|
|
1613
|
+
} : async () => {
|
|
1614
|
+
var f, p;
|
|
1615
|
+
return w.chat(
|
|
1616
|
+
u.id,
|
|
1617
|
+
N,
|
|
1618
|
+
{
|
|
1619
|
+
chatMode: r.chatMode,
|
|
1620
|
+
streamId: (f = r.streamingManager) == null ? void 0 : f.streamId,
|
|
1621
|
+
sessionId: (p = r.streamingManager) == null ? void 0 : p.sessionId,
|
|
1622
|
+
messages: j.map(({ matches: $, ...V }) => V)
|
|
1623
|
+
},
|
|
1624
|
+
{
|
|
1625
|
+
...Oe(r.chatMode),
|
|
1626
|
+
skipErrorHandler: !0
|
|
1627
|
+
}
|
|
1628
|
+
);
|
|
1629
|
+
}, {
|
|
1630
|
+
limit: 2,
|
|
1631
|
+
shouldRetryFn: (f) => {
|
|
1632
|
+
var V, pe, ce, le;
|
|
1633
|
+
const p = (V = f == null ? void 0 : f.message) == null ? void 0 : V.includes("missing or invalid session_id");
|
|
1634
|
+
return !((pe = f == null ? void 0 : f.message) == null ? void 0 : pe.includes("Stream Error")) && !p ? ((le = (ce = t.callbacks).onError) == null || le.call(ce, f), !1) : !0;
|
|
1595
1635
|
},
|
|
1596
|
-
{
|
|
1597
|
-
|
|
1598
|
-
skipErrorHandler: !0
|
|
1636
|
+
onRetry: async () => {
|
|
1637
|
+
await W(), await A(!1);
|
|
1599
1638
|
}
|
|
1600
|
-
);
|
|
1601
|
-
}
|
|
1602
|
-
limit: 2,
|
|
1603
|
-
shouldRetryFn: (E) => {
|
|
1604
|
-
var h, w, F, Q;
|
|
1605
|
-
const P = (h = E == null ? void 0 : E.message) == null ? void 0 : h.includes("missing or invalid session_id");
|
|
1606
|
-
return !((w = E == null ? void 0 : E.message) == null ? void 0 : w.includes("Stream Error")) && !P ? ((Q = (F = t.callbacks).onError) == null || Q.call(F, E), !1) : !0;
|
|
1607
|
-
},
|
|
1608
|
-
onRetry: async () => {
|
|
1609
|
-
await T(), await L(!1);
|
|
1610
|
-
}
|
|
1611
|
-
});
|
|
1639
|
+
});
|
|
1640
|
+
};
|
|
1612
1641
|
try {
|
|
1613
|
-
|
|
1614
|
-
id:
|
|
1642
|
+
q(), y(), r.messages.push({
|
|
1643
|
+
id: ue(),
|
|
1615
1644
|
role: "user",
|
|
1616
|
-
content:
|
|
1617
|
-
created_at: new Date(
|
|
1618
|
-
}), (_ = (
|
|
1619
|
-
const j = await
|
|
1645
|
+
content: m,
|
|
1646
|
+
created_at: new Date(ie.update()).toISOString()
|
|
1647
|
+
}), (_ = (b = t.callbacks).onNewMessage) == null || _.call(b, [...r.messages], "user");
|
|
1648
|
+
const j = await k(), N = await P([...r.messages], j);
|
|
1620
1649
|
return r.messages.push({
|
|
1621
|
-
id:
|
|
1650
|
+
id: ue(),
|
|
1622
1651
|
role: "assistant",
|
|
1623
|
-
content:
|
|
1652
|
+
content: N.result || "",
|
|
1624
1653
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1625
|
-
context:
|
|
1626
|
-
matches:
|
|
1654
|
+
context: N.context,
|
|
1655
|
+
matches: N.matches
|
|
1627
1656
|
}), d.track("agent-message-send", {
|
|
1628
1657
|
event: "success",
|
|
1629
1658
|
messages: r.messages.length + 1
|
|
1630
|
-
}),
|
|
1631
|
-
latency:
|
|
1659
|
+
}), N.result && ((H = (U = t.callbacks).onNewMessage) == null || H.call(U, [...r.messages], "answer"), d.track("agent-message-received", {
|
|
1660
|
+
latency: ie.get(!0),
|
|
1632
1661
|
messages: r.messages.length
|
|
1633
|
-
})),
|
|
1662
|
+
})), N;
|
|
1634
1663
|
} catch (j) {
|
|
1635
|
-
throw ((
|
|
1664
|
+
throw ((Q = r.messages[r.messages.length - 1]) == null ? void 0 : Q.role) === "assistant" && r.messages.pop(), d.track("agent-message-send", {
|
|
1636
1665
|
event: "error",
|
|
1637
1666
|
messages: r.messages.length
|
|
1638
1667
|
}), j;
|
|
1639
1668
|
}
|
|
1640
1669
|
},
|
|
1641
|
-
rate(
|
|
1642
|
-
var _,
|
|
1643
|
-
const
|
|
1670
|
+
rate(m, y, k) {
|
|
1671
|
+
var _, U, H, Q;
|
|
1672
|
+
const P = r.messages.find((j) => j.id === m);
|
|
1644
1673
|
if (r.chat) {
|
|
1645
|
-
if (
|
|
1674
|
+
if (!P)
|
|
1646
1675
|
throw new Error("Message not found");
|
|
1647
1676
|
} else throw new Error("Chat is not initialized");
|
|
1648
|
-
const
|
|
1677
|
+
const b = ((_ = P.matches) == null ? void 0 : _.map((j) => [j.document_id, j.id])) ?? [];
|
|
1649
1678
|
return d.track("agent-rate", {
|
|
1650
|
-
event:
|
|
1651
|
-
thumb:
|
|
1652
|
-
knowledge_id: ((
|
|
1653
|
-
matches:
|
|
1654
|
-
score:
|
|
1655
|
-
}),
|
|
1679
|
+
event: k ? "update" : "create",
|
|
1680
|
+
thumb: y === 1 ? "up" : "down",
|
|
1681
|
+
knowledge_id: ((U = u.knowledge) == null ? void 0 : U.id) ?? "",
|
|
1682
|
+
matches: b,
|
|
1683
|
+
score: y
|
|
1684
|
+
}), k ? w.updateRating(u.id, r.chat.id, k, {
|
|
1656
1685
|
knowledge_id: ((H = u.knowledge) == null ? void 0 : H.id) ?? "",
|
|
1657
|
-
message_id:
|
|
1658
|
-
matches:
|
|
1659
|
-
score:
|
|
1660
|
-
}) :
|
|
1661
|
-
knowledge_id: ((
|
|
1662
|
-
message_id:
|
|
1663
|
-
matches:
|
|
1664
|
-
score:
|
|
1686
|
+
message_id: m,
|
|
1687
|
+
matches: b,
|
|
1688
|
+
score: y
|
|
1689
|
+
}) : w.createRating(u.id, r.chat.id, {
|
|
1690
|
+
knowledge_id: ((Q = u.knowledge) == null ? void 0 : Q.id) ?? "",
|
|
1691
|
+
message_id: m,
|
|
1692
|
+
matches: b,
|
|
1693
|
+
score: y
|
|
1665
1694
|
});
|
|
1666
1695
|
},
|
|
1667
|
-
deleteRate(
|
|
1696
|
+
deleteRate(m) {
|
|
1668
1697
|
if (!r.chat)
|
|
1669
1698
|
throw new Error("Chat is not initialized");
|
|
1670
|
-
return d.track("agent-rate-delete", { type: "text" }),
|
|
1699
|
+
return d.track("agent-rate-delete", { type: "text" }), w.deleteRating(u.id, r.chat.id, m);
|
|
1671
1700
|
},
|
|
1672
|
-
async speak(
|
|
1673
|
-
var
|
|
1674
|
-
function
|
|
1675
|
-
if (typeof
|
|
1701
|
+
async speak(m) {
|
|
1702
|
+
var b, _, U;
|
|
1703
|
+
function y() {
|
|
1704
|
+
if (typeof m == "string") {
|
|
1676
1705
|
if (!u.presenter.voice)
|
|
1677
1706
|
throw new Error("Presenter voice is not initialized");
|
|
1678
1707
|
return {
|
|
1679
1708
|
type: "text",
|
|
1680
1709
|
provider: u.presenter.voice,
|
|
1681
|
-
input:
|
|
1710
|
+
input: m,
|
|
1682
1711
|
ssml: !1
|
|
1683
1712
|
};
|
|
1684
1713
|
}
|
|
1685
|
-
if (
|
|
1714
|
+
if (m.type === "text" && !m.provider) {
|
|
1686
1715
|
if (!u.presenter.voice)
|
|
1687
1716
|
throw new Error("Presenter voice is not initialized");
|
|
1688
1717
|
return {
|
|
1689
1718
|
type: "text",
|
|
1690
1719
|
provider: u.presenter.voice,
|
|
1691
|
-
input:
|
|
1692
|
-
ssml:
|
|
1720
|
+
input: m.input,
|
|
1721
|
+
ssml: m.ssml
|
|
1693
1722
|
};
|
|
1694
1723
|
}
|
|
1695
|
-
return
|
|
1724
|
+
return m;
|
|
1696
1725
|
}
|
|
1697
|
-
const
|
|
1698
|
-
if (d.track("agent-speak",
|
|
1699
|
-
id:
|
|
1726
|
+
const k = y();
|
|
1727
|
+
if (d.track("agent-speak", k), ie.update(), r.messages && k.type === "text" && (r.messages.push({
|
|
1728
|
+
id: ue(),
|
|
1700
1729
|
role: "assistant",
|
|
1701
|
-
content:
|
|
1730
|
+
content: k.input,
|
|
1702
1731
|
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1703
|
-
}), (_ = (
|
|
1732
|
+
}), (_ = (b = t.callbacks).onNewMessage) == null || _.call(b, [...r.messages], "answer")), ft(r.chatMode))
|
|
1704
1733
|
return {
|
|
1705
1734
|
duration: 0,
|
|
1706
1735
|
video_id: "",
|
|
@@ -1709,45 +1738,37 @@ async function un(e, t) {
|
|
|
1709
1738
|
if (!r.streamingManager)
|
|
1710
1739
|
throw new Error("Please connect to the agent first");
|
|
1711
1740
|
return r.streamingManager.speak({
|
|
1712
|
-
script:
|
|
1713
|
-
metadata: { chat_id: (
|
|
1741
|
+
script: k,
|
|
1742
|
+
metadata: { chat_id: (U = r.chat) == null ? void 0 : U.id, agent_id: u.id }
|
|
1714
1743
|
});
|
|
1715
1744
|
},
|
|
1716
|
-
|
|
1717
|
-
var y, $, D;
|
|
1718
|
-
const R = r.messages[r.messages.length - 1];
|
|
1719
|
-
d.track("agent-video-interrupt", {
|
|
1720
|
-
type: f || "click",
|
|
1721
|
-
video_duration_to_interrupt: Ce.get(!0),
|
|
1722
|
-
message_duration_to_interrupt: te.get(!0)
|
|
1723
|
-
}), R.interrupted = !0, ($ = (y = t.callbacks).onNewMessage) == null || $.call(y, [...r.messages], "answer"), M ? Tt(r.streamingManager) : (Mt(r.streamingManager, (D = r.streamingManager) == null ? void 0 : D.streamType, n), It(r.streamingManager, n));
|
|
1724
|
-
}
|
|
1745
|
+
interrupt: I
|
|
1725
1746
|
};
|
|
1726
1747
|
}
|
|
1727
1748
|
export {
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1749
|
+
J as AgentActivityState,
|
|
1750
|
+
tt as AgentStatus,
|
|
1751
|
+
Xe as ChatCreationFailed,
|
|
1752
|
+
F as ChatMode,
|
|
1753
|
+
Ye as ChatModeDowngraded,
|
|
1733
1754
|
Y as ChatProgress,
|
|
1734
1755
|
S as ConnectionState,
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1756
|
+
re as ConnectivityState,
|
|
1757
|
+
at as DocumentType,
|
|
1758
|
+
it as KnowledgeType,
|
|
1759
|
+
et as PlanGroup,
|
|
1760
|
+
ot as Providers,
|
|
1761
|
+
nt as RateState,
|
|
1762
|
+
x as StreamEvents,
|
|
1763
|
+
ae as StreamType,
|
|
1743
1764
|
C as StreamingState,
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1765
|
+
rt as Subject,
|
|
1766
|
+
ye as TransportProvider,
|
|
1767
|
+
Ze as UserPlan,
|
|
1768
|
+
de as ValidationError,
|
|
1769
|
+
Ne as VideoType,
|
|
1770
|
+
st as VoiceAccess,
|
|
1771
|
+
Ge as WsError,
|
|
1772
|
+
mn as createAgentManager,
|
|
1773
|
+
fn as mapVideoType
|
|
1753
1774
|
};
|