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