@d-id/client-sdk 1.1.30 → 1.1.31-staging.145
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,20 +1,20 @@
|
|
|
1
1
|
var Qe = Object.defineProperty;
|
|
2
|
-
var Xe = (e, t,
|
|
3
|
-
var fe = (e, t,
|
|
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
13
|
class Ye extends we {
|
|
14
|
-
constructor(t,
|
|
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
|
}
|
|
@@ -23,9 +23,9 @@ class Ge extends we {
|
|
|
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
|
}
|
|
@@ -35,7 +35,7 @@ class Ze extends we {
|
|
|
35
35
|
super({ kind: "WSError", description: t });
|
|
36
36
|
}
|
|
37
37
|
}
|
|
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 || {}),
|
|
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
39
|
const mn = (e) => {
|
|
40
40
|
switch (e) {
|
|
41
41
|
case "clip":
|
|
@@ -48,22 +48,22 @@ const mn = (e) => {
|
|
|
48
48
|
throw new Error(`Unknown video type: ${e}`);
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
|
-
var
|
|
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)),
|
|
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
|
-
}, 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),
|
|
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
56
|
function gt(e, t) {
|
|
57
|
-
let
|
|
57
|
+
let i;
|
|
58
58
|
return {
|
|
59
|
-
promise: new Promise((
|
|
60
|
-
|
|
59
|
+
promise: new Promise((s, o) => {
|
|
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
|
|
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:
|
|
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 Je(
|
|
85
|
+
await Je(i.delayMs), i.onRetry(o);
|
|
86
86
|
}
|
|
87
87
|
throw n;
|
|
88
88
|
}
|
|
@@ -91,13 +91,13 @@ 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 ht =
|
|
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")
|
|
@@ -106,105 +106,105 @@ function Oe(e, t) {
|
|
|
106
106
|
return `Client-Key ${e.clientKey}.${ke(t)}_${ht}`;
|
|
107
107
|
throw new Error(`Unknown auth type: ${e}`);
|
|
108
108
|
}
|
|
109
|
-
const pt = (e) =>
|
|
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,
|
|
116
|
-
const
|
|
117
|
-
const { skipErrorHandler:
|
|
115
|
+
function Te(e, t = ge, i, n) {
|
|
116
|
+
const s = async (o, c) => {
|
|
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
|
})
|
|
126
126
|
);
|
|
127
127
|
if (!d.ok) {
|
|
128
|
-
let
|
|
129
|
-
const
|
|
130
|
-
throw
|
|
128
|
+
let w = await d.text().catch(() => `Failed to fetch with status ${d.status}`);
|
|
129
|
+
const p = new Error(w);
|
|
130
|
+
throw i && !a && i(p, { url: o, options: r, headers: d.headers }), p;
|
|
131
131
|
}
|
|
132
132
|
return d.json();
|
|
133
133
|
};
|
|
134
134
|
return {
|
|
135
|
-
get(o,
|
|
136
|
-
return
|
|
135
|
+
get(o, c) {
|
|
136
|
+
return s(o, { ...c, method: "GET" });
|
|
137
137
|
},
|
|
138
|
-
post(o,
|
|
139
|
-
return
|
|
138
|
+
post(o, c, a) {
|
|
139
|
+
return s(o, { ...a, body: JSON.stringify(c), method: "POST" });
|
|
140
140
|
},
|
|
141
|
-
delete(o,
|
|
142
|
-
return
|
|
141
|
+
delete(o, c, a) {
|
|
142
|
+
return s(o, { ...a, body: JSON.stringify(c), method: "DELETE" });
|
|
143
143
|
},
|
|
144
|
-
patch(o,
|
|
145
|
-
return
|
|
144
|
+
patch(o, c, a) {
|
|
145
|
+
return s(o, { ...a, body: JSON.stringify(c), method: "PATCH" });
|
|
146
146
|
}
|
|
147
147
|
};
|
|
148
148
|
}
|
|
149
|
-
function wt(e, t = ge,
|
|
150
|
-
const
|
|
149
|
+
function wt(e, t = ge, i, n) {
|
|
150
|
+
const s = Te(e, `${t}/agents`, i, n);
|
|
151
151
|
return {
|
|
152
|
-
create(o,
|
|
153
|
-
return
|
|
152
|
+
create(o, c) {
|
|
153
|
+
return s.post("/", o, c);
|
|
154
154
|
},
|
|
155
|
-
getAgents(o,
|
|
156
|
-
return
|
|
155
|
+
getAgents(o, c) {
|
|
156
|
+
return s.get(`/${o ? `?tag=${o}` : ""}`, c).then((a) => a ?? []);
|
|
157
157
|
},
|
|
158
|
-
getById(o,
|
|
159
|
-
return
|
|
158
|
+
getById(o, c) {
|
|
159
|
+
return s.get(`/${o}`, c);
|
|
160
160
|
},
|
|
161
|
-
delete(o,
|
|
162
|
-
return
|
|
161
|
+
delete(o, c) {
|
|
162
|
+
return s.delete(`/${o}`, void 0, c);
|
|
163
163
|
},
|
|
164
|
-
update(o,
|
|
165
|
-
return
|
|
164
|
+
update(o, c, a) {
|
|
165
|
+
return s.patch(`/${o}`, c, a);
|
|
166
166
|
},
|
|
167
|
-
newChat(o,
|
|
168
|
-
return
|
|
167
|
+
newChat(o, c, a) {
|
|
168
|
+
return s.post(`/${o}/chat`, c, a);
|
|
169
169
|
},
|
|
170
|
-
chat(o,
|
|
171
|
-
return
|
|
170
|
+
chat(o, c, a, r) {
|
|
171
|
+
return s.post(`/${o}/chat/${c}`, a, r);
|
|
172
172
|
},
|
|
173
|
-
createRating(o,
|
|
174
|
-
return
|
|
173
|
+
createRating(o, c, a, r) {
|
|
174
|
+
return s.post(`/${o}/chat/${c}/ratings`, a, r);
|
|
175
175
|
},
|
|
176
|
-
updateRating(o,
|
|
177
|
-
return
|
|
176
|
+
updateRating(o, c, a, r, d) {
|
|
177
|
+
return s.patch(`/${o}/chat/${c}/ratings/${a}`, r, d);
|
|
178
178
|
},
|
|
179
|
-
deleteRating(o,
|
|
180
|
-
return
|
|
179
|
+
deleteRating(o, c, a, r) {
|
|
180
|
+
return s.delete(`/${o}/chat/${c}/ratings/${a}`, r);
|
|
181
181
|
},
|
|
182
|
-
getSTTToken(o,
|
|
183
|
-
return
|
|
182
|
+
getSTTToken(o, c) {
|
|
183
|
+
return s.get(`/${o}/stt-token`, c);
|
|
184
184
|
}
|
|
185
185
|
};
|
|
186
186
|
}
|
|
187
187
|
function yt(e) {
|
|
188
|
-
var
|
|
189
|
-
const t = () => /Mobi|Android/i.test(navigator.userAgent) ? "Mobile" : "Desktop",
|
|
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
198
|
agentType: Ue(n),
|
|
199
199
|
agentVoice: {
|
|
200
|
-
voiceId: (o = (
|
|
201
|
-
provider: (
|
|
200
|
+
voiceId: (o = (s = e.presenter) == null ? void 0 : s.voice) == null ? void 0 : o.voice_id,
|
|
201
|
+
provider: (a = (c = e.presenter) == null ? void 0 : c.voice) == null ? void 0 : a.type
|
|
202
202
|
}
|
|
203
203
|
};
|
|
204
204
|
}
|
|
205
205
|
function vt(e) {
|
|
206
|
-
var
|
|
207
|
-
const t = (
|
|
206
|
+
var i, n, s, o, c, a;
|
|
207
|
+
const t = (i = e.llm) == null ? void 0 : i.prompt_customization;
|
|
208
208
|
return {
|
|
209
209
|
agentType: Ue(e.presenter),
|
|
210
210
|
owner_id: e.owner_id ?? "",
|
|
@@ -212,11 +212,11 @@ function vt(e) {
|
|
|
212
212
|
behavior: {
|
|
213
213
|
role: t == null ? void 0 : t.role,
|
|
214
214
|
personality: t == null ? void 0 : t.personality,
|
|
215
|
-
instructions: (
|
|
215
|
+
instructions: (s = e.llm) == null ? void 0 : s.instructions
|
|
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,19 +225,19 @@ function vt(e) {
|
|
|
225
225
|
...e.access === "public" ? { from: "agent-template" } : {}
|
|
226
226
|
};
|
|
227
227
|
}
|
|
228
|
-
const
|
|
229
|
-
function
|
|
230
|
-
var r, d,
|
|
231
|
-
const { event: n, ...
|
|
228
|
+
const Ct = (e) => e.reduce((t, i) => t + i, 0), $e = (e) => Ct(e) / e.length;
|
|
229
|
+
function St(e, t, i) {
|
|
230
|
+
var r, d, w;
|
|
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 {
|
|
233
|
-
...
|
|
234
|
-
llm: { ...
|
|
235
|
-
script: { ...
|
|
236
|
-
stitch: (t == null ? void 0 : t.presenter.type) === "talk" ? (
|
|
237
|
-
...
|
|
233
|
+
...s,
|
|
234
|
+
llm: { ...s.llm, template: o },
|
|
235
|
+
script: { ...s.script, provider: { ...(d = s == null ? void 0 : s.script) == null ? void 0 : d.provider, language: c } },
|
|
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
|
+
...i
|
|
238
238
|
};
|
|
239
239
|
}
|
|
240
|
-
function
|
|
240
|
+
function Be(e) {
|
|
241
241
|
"requestIdleCallback" in window ? requestIdleCallback(e, { timeout: 2e3 }) : setTimeout(e, 0);
|
|
242
242
|
}
|
|
243
243
|
let ve = {};
|
|
@@ -253,14 +253,14 @@ function Rt(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, ...
|
|
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 Rt(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,
|
|
@@ -291,17 +291,17 @@ function Rt(e) {
|
|
|
291
291
|
keepalive: !0
|
|
292
292
|
}).catch((d) => console.error("Analytics tracking error:", d)), Promise.resolve();
|
|
293
293
|
},
|
|
294
|
-
linkTrack(
|
|
295
|
-
ve[
|
|
296
|
-
const
|
|
297
|
-
if (
|
|
298
|
-
(r) =>
|
|
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
|
+
if (c.events[s] = { props: n }, c.resolvedDependencies.push(s), o.every(
|
|
298
|
+
(r) => c.resolvedDependencies.includes(r)
|
|
299
299
|
)) {
|
|
300
|
-
const r = o.reduce((d,
|
|
301
|
-
this.track(
|
|
300
|
+
const r = o.reduce((d, w) => c.events[w] ? { ...d, ...c.events[w].props } : d, {});
|
|
301
|
+
this.track(i, r), c.resolvedDependencies = c.resolvedDependencies.filter(
|
|
302
302
|
(d) => !o.includes(d)
|
|
303
303
|
), o.forEach((d) => {
|
|
304
|
-
delete
|
|
304
|
+
delete c.events[d];
|
|
305
305
|
});
|
|
306
306
|
}
|
|
307
307
|
}
|
|
@@ -315,19 +315,19 @@ function _e() {
|
|
|
315
315
|
get: (t = !1) => t ? Date.now() - e : e
|
|
316
316
|
};
|
|
317
317
|
}
|
|
318
|
-
const
|
|
319
|
-
function
|
|
318
|
+
const ee = _e(), Re = _e(), xe = _e();
|
|
319
|
+
function Oe(e) {
|
|
320
320
|
return e === F.Playground ? { headers: { [ut]: "true" } } : {};
|
|
321
321
|
}
|
|
322
|
-
async function
|
|
322
|
+
async function He(e, t, i, n, s = !1, o) {
|
|
323
323
|
try {
|
|
324
|
-
return !o && !
|
|
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
|
-
} catch (
|
|
330
|
-
throw Dt(
|
|
329
|
+
} catch (c) {
|
|
330
|
+
throw Dt(c) === "InsufficientCreditsError" ? new Error("InsufficientCreditsError") : new Error("Cannot create new chat");
|
|
331
331
|
}
|
|
332
332
|
}
|
|
333
333
|
const Dt = (e) => {
|
|
@@ -341,16 +341,16 @@ const Dt = (e) => {
|
|
|
341
341
|
function Mt(e) {
|
|
342
342
|
return e && e.length > 0 ? e : [];
|
|
343
343
|
}
|
|
344
|
-
function Et(e, t,
|
|
345
|
-
const
|
|
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
|
-
return
|
|
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 {
|
|
@@ -360,248 +360,241 @@ async function Se() {
|
|
|
360
360
|
}
|
|
361
361
|
}
|
|
362
362
|
const It = {
|
|
363
|
-
excellent:
|
|
364
|
-
good:
|
|
365
|
-
poor:
|
|
366
|
-
lost:
|
|
367
|
-
unknown:
|
|
363
|
+
excellent: ie.Strong,
|
|
364
|
+
good: ie.Strong,
|
|
365
|
+
poor: ie.Weak,
|
|
366
|
+
lost: ie.Unknown,
|
|
367
|
+
unknown: ie.Unknown
|
|
368
368
|
}, me = JSON.stringify({
|
|
369
369
|
kind: "InternalServerError",
|
|
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 Tt(e, t,
|
|
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
|
|
383
|
-
u = new
|
|
382
|
+
let A = null, C = null, B = !1;
|
|
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
|
|
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
|
-
const l = await
|
|
394
|
+
const l = await te.createStream({
|
|
395
395
|
transport_provider: ye.Livekit,
|
|
396
396
|
chat_persist: t.chat_persist ?? !0
|
|
397
|
-
}), { id:
|
|
398
|
-
(Pe =
|
|
397
|
+
}), { id: g, session_token: v, session_url: D } = l;
|
|
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
|
-
V = !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,
|
|
407
|
-
function f(l,
|
|
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);
|
|
405
|
+
function f(l, g) {
|
|
408
406
|
var v;
|
|
409
|
-
|
|
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
|
-
n("Track subscription timeout - no track subscribed within 30 seconds after connect"), z = null,
|
|
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
|
-
V = !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
|
|
424
|
+
var g, v, D, b;
|
|
429
425
|
switch (n("Connection state changed:", l), l) {
|
|
430
|
-
case
|
|
431
|
-
(
|
|
426
|
+
case c.Connecting:
|
|
427
|
+
n("CALLBACK: onConnectionStateChange(Connecting)"), (g = a.onConnectionStateChange) == null || g.call(a, R.Connecting);
|
|
432
428
|
break;
|
|
433
|
-
case
|
|
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);
|
|
429
|
+
case c.Connected:
|
|
430
|
+
n("LiveKit room connected successfully"), _ = !0;
|
|
438
431
|
break;
|
|
439
|
-
case
|
|
440
|
-
n("LiveKit room disconnected"),
|
|
432
|
+
case c.Disconnected:
|
|
433
|
+
n("LiveKit room disconnected"), _ = !1, B = !1, (v = a.onConnectionStateChange) == null || v.call(a, R.Disconnected);
|
|
441
434
|
break;
|
|
442
|
-
case
|
|
443
|
-
n("LiveKit room reconnecting..."), (D =
|
|
435
|
+
case c.Reconnecting:
|
|
436
|
+
n("LiveKit room reconnecting..."), (D = a.onConnectionStateChange) == null || D.call(a, R.Connecting);
|
|
444
437
|
break;
|
|
445
|
-
case
|
|
446
|
-
n("LiveKit room signal reconnecting..."), (
|
|
438
|
+
case c.SignalReconnecting:
|
|
439
|
+
n("LiveKit room signal reconnecting..."), (b = a.onConnectionStateChange) == null || b.call(a, R.Connecting);
|
|
447
440
|
break;
|
|
448
441
|
}
|
|
449
442
|
}
|
|
450
|
-
function k(l,
|
|
443
|
+
function k(l, g) {
|
|
451
444
|
var v;
|
|
452
|
-
n("Connection quality:", l),
|
|
445
|
+
n("Connection quality:", l), g != null && g.isLocal && ((v = a.onConnectivityStateChange) == null || v.call(a, It[l]));
|
|
453
446
|
}
|
|
454
|
-
function
|
|
455
|
-
|
|
456
|
-
n("Active speakers changed:", l), l.find((D) => !D.isLocal) ? (W = U.Talking, (v = i.onAgentActivityStateChange) == null || v.call(i, U.Talking)) : ((R = i.onAgentActivityStateChange) == null || R.call(i, U.Idle), W = U.Idle);
|
|
447
|
+
function T(l) {
|
|
448
|
+
n("Active speakers changed:", l);
|
|
457
449
|
}
|
|
458
|
-
function
|
|
450
|
+
function P(l) {
|
|
459
451
|
n("Participant connected:", l.identity);
|
|
460
452
|
}
|
|
461
|
-
function
|
|
462
|
-
n("Participant disconnected:", l.identity),
|
|
453
|
+
function E(l) {
|
|
454
|
+
n("Participant disconnected:", l.identity), ce();
|
|
463
455
|
}
|
|
464
|
-
function J(l,
|
|
465
|
-
var
|
|
456
|
+
function J(l, g, v) {
|
|
457
|
+
var b, Q, G, se;
|
|
466
458
|
n(`Track subscribed: ${l.kind} from ${v.identity}`), z && (clearTimeout(z), z = null, n("Track subscription timeout cleared"));
|
|
467
|
-
const
|
|
468
|
-
if (!
|
|
459
|
+
const D = l.mediaStreamTrack;
|
|
460
|
+
if (!D) {
|
|
469
461
|
n(`No mediaStreamTrack available for ${l.kind}`);
|
|
470
462
|
return;
|
|
471
463
|
}
|
|
472
|
-
|
|
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));
|
|
473
465
|
}
|
|
474
|
-
function
|
|
475
|
-
var
|
|
476
|
-
n(`Track unsubscribed: ${l.kind} from ${v.identity}`), l.kind === "video" && ((
|
|
466
|
+
function O(l, g, v) {
|
|
467
|
+
var D;
|
|
468
|
+
n(`Track unsubscribed: ${l.kind} from ${v.identity}`), l.kind === "video" && ((D = a.onVideoStateChange) == null || D.call(a, S.Stop));
|
|
477
469
|
}
|
|
478
|
-
function
|
|
479
|
-
var
|
|
480
|
-
const
|
|
481
|
-
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);
|
|
482
474
|
try {
|
|
483
|
-
const
|
|
484
|
-
if (
|
|
485
|
-
const
|
|
486
|
-
(
|
|
487
|
-
event:
|
|
488
|
-
...
|
|
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, {
|
|
479
|
+
event: re,
|
|
480
|
+
...ne
|
|
489
481
|
});
|
|
490
|
-
} else if (
|
|
491
|
-
const
|
|
492
|
-
(
|
|
493
|
-
event:
|
|
494
|
-
...
|
|
482
|
+
} else if (de === j.ChatPartial) {
|
|
483
|
+
const re = X.Partial;
|
|
484
|
+
(G = a.onMessage) == null || G.call(a, re, {
|
|
485
|
+
event: re,
|
|
486
|
+
...ne
|
|
495
487
|
});
|
|
496
|
-
} else if ([j.StreamVideoCreated, j.StreamVideoDone].includes(
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
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);
|
|
490
|
+
const re = (ne == null ? void 0 : ne.role) || (g == null ? void 0 : g.identity) || "datachannel";
|
|
491
|
+
(Le = a.onMessage) == null || Le.call(a, de, {
|
|
492
|
+
[re]: ne
|
|
500
493
|
});
|
|
501
|
-
} else if (
|
|
502
|
-
const
|
|
503
|
-
(be =
|
|
504
|
-
event:
|
|
505
|
-
...
|
|
494
|
+
} else if (de === j.ChatAudioTranscribed) {
|
|
495
|
+
const re = X.Transcribe;
|
|
496
|
+
(be = a.onMessage) == null || be.call(a, re, {
|
|
497
|
+
event: re,
|
|
498
|
+
...ne
|
|
506
499
|
}), queueMicrotask(() => {
|
|
507
500
|
var je;
|
|
508
|
-
(je =
|
|
501
|
+
(je = a.onAgentActivityStateChange) == null || je.call(a, W.Loading);
|
|
509
502
|
});
|
|
510
503
|
}
|
|
511
|
-
} catch (
|
|
512
|
-
n("Failed to parse data channel message:",
|
|
504
|
+
} catch (ne) {
|
|
505
|
+
n("Failed to parse data channel message:", ne);
|
|
513
506
|
}
|
|
514
507
|
}
|
|
515
|
-
function
|
|
516
|
-
var
|
|
517
|
-
n("Media devices error:", l), (
|
|
508
|
+
function L(l) {
|
|
509
|
+
var g;
|
|
510
|
+
n("Media devices error:", l), (g = a.onError) == null || g.call(a, new Error(me), { sessionId: M });
|
|
518
511
|
}
|
|
519
512
|
function N(l) {
|
|
520
|
-
var
|
|
521
|
-
n("Encryption error:", l), (
|
|
513
|
+
var g;
|
|
514
|
+
n("Encryption error:", l), (g = a.onError) == null || g.call(a, new Error(me), { sessionId: M });
|
|
522
515
|
}
|
|
523
|
-
function
|
|
524
|
-
n("Track subscription failed:", { trackSid: l, participant:
|
|
516
|
+
function q(l, g, v) {
|
|
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:
|
|
521
|
+
const { Track: g } = await Ce(), v = u.localParticipant.audioTrackPublications;
|
|
529
522
|
if (v) {
|
|
530
|
-
for (const [
|
|
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
|
-
function
|
|
540
|
-
if (!
|
|
532
|
+
function V(l) {
|
|
533
|
+
if (!C || !C.track)
|
|
541
534
|
return !1;
|
|
542
|
-
const
|
|
543
|
-
return
|
|
535
|
+
const g = C.track.mediaStreamTrack;
|
|
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
|
-
const
|
|
550
|
-
if (
|
|
542
|
+
const g = l.getAudioTracks();
|
|
543
|
+
if (g.length === 0) {
|
|
551
544
|
n("No audio track found in the provided MediaStream");
|
|
552
545
|
return;
|
|
553
546
|
}
|
|
554
|
-
const v =
|
|
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
|
-
|
|
565
|
-
source:
|
|
566
|
-
}), n("Microphone track published successfully", { trackSid:
|
|
567
|
-
} catch (
|
|
568
|
-
throw n("Failed to publish microphone track:",
|
|
557
|
+
C = await u.localParticipant.publishTrack(v, {
|
|
558
|
+
source: D.Source.Microphone
|
|
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
|
-
async function
|
|
572
|
-
if (!(!
|
|
564
|
+
async function h() {
|
|
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 K(l,
|
|
585
|
-
var v,
|
|
586
|
-
if (!
|
|
587
|
-
n("Room is not connected for sending messages"), (v =
|
|
588
|
-
sessionId:
|
|
577
|
+
async function K(l, g) {
|
|
578
|
+
var v, D;
|
|
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
|
-
await u.localParticipant.sendText(l, { topic:
|
|
594
|
-
} catch (
|
|
595
|
-
n("Failed to send message:",
|
|
586
|
+
await u.localParticipant.sendText(l, { topic: g }), n("Message sent successfully:", l);
|
|
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
|
-
var
|
|
592
|
+
var g;
|
|
600
593
|
try {
|
|
601
|
-
const
|
|
602
|
-
return K("",
|
|
594
|
+
const D = JSON.parse(l).topic;
|
|
595
|
+
return K("", D);
|
|
603
596
|
} catch (v) {
|
|
604
|
-
n("Failed to send data channel message:", v), (
|
|
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) {
|
|
@@ -611,53 +604,52 @@ async function Tt(e, t, a) {
|
|
|
611
604
|
/* Chat */
|
|
612
605
|
);
|
|
613
606
|
}
|
|
614
|
-
async function
|
|
615
|
-
var l,
|
|
616
|
-
z && (clearTimeout(z), z = null), u && (await
|
|
607
|
+
async function ce() {
|
|
608
|
+
var l, g;
|
|
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
|
-
const
|
|
613
|
+
const g = typeof l == "string" ? l : JSON.stringify(l);
|
|
621
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,
|
|
630
|
-
if ((u == null ? void 0 : u.state) ===
|
|
622
|
+
var l, g;
|
|
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,
|
|
631
|
+
if (await u.connect(Z, Y), n("Room reconnected"), _ = !0, u.remoteParticipants.size === 0) {
|
|
639
632
|
if (n("Waiting for agent to join..."), !await new Promise((D) => {
|
|
640
|
-
const
|
|
641
|
-
u == null || u.off(o.ParticipantConnected,
|
|
642
|
-
}, 5e3),
|
|
643
|
-
clearTimeout(
|
|
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:", R), (v = i.onConnectionStateChange) == null || v.call(i, S.Fail), R;
|
|
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
|
-
unpublishMicrophoneStream:
|
|
659
|
-
sessionId:
|
|
660
|
-
streamId:
|
|
650
|
+
unpublishMicrophoneStream: h,
|
|
651
|
+
sessionId: M,
|
|
652
|
+
streamId: M,
|
|
661
653
|
streamType: $,
|
|
662
654
|
interruptAvailable: !0,
|
|
663
655
|
triggersAvailable: !1
|
|
@@ -669,23 +661,23 @@ const _t = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
669
661
|
createLiveKitStreamingManager: Tt,
|
|
670
662
|
handleInitError: De
|
|
671
663
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
672
|
-
function At(e, t,
|
|
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
674
|
async function Pt(e, t) {
|
|
683
|
-
const
|
|
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 = {
|
|
@@ -694,160 +686,164 @@ async function Lt(e) {
|
|
|
694
686
|
e.sendDataChannelMessage(JSON.stringify(t));
|
|
695
687
|
}
|
|
696
688
|
function bt(e) {
|
|
697
|
-
return new Promise((t,
|
|
698
|
-
const { callbacks: n, host:
|
|
699
|
-
|
|
700
|
-
console.error(u),
|
|
701
|
-
},
|
|
702
|
-
r == null || r(u), t(
|
|
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);
|
|
693
|
+
}, p.onopen = (u) => {
|
|
694
|
+
r == null || r(u), t(p);
|
|
703
695
|
};
|
|
704
696
|
});
|
|
705
697
|
}
|
|
706
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
|
-
|
|
712
|
-
} catch (
|
|
703
|
+
i = await bt(e);
|
|
704
|
+
} catch (s) {
|
|
713
705
|
if (n === t)
|
|
714
|
-
throw
|
|
706
|
+
throw s;
|
|
715
707
|
await Je(n * 500);
|
|
716
708
|
}
|
|
717
|
-
return
|
|
709
|
+
return i;
|
|
718
710
|
}
|
|
719
|
-
async function $t(e, t,
|
|
720
|
-
const
|
|
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
|
-
onError: (
|
|
726
|
-
var
|
|
727
|
-
return (
|
|
717
|
+
onError: (c) => {
|
|
718
|
+
var a;
|
|
719
|
+
return (a = i.onError) == null ? void 0 : a.call(i, new Ze(c));
|
|
728
720
|
},
|
|
729
|
-
onMessage(
|
|
730
|
-
const
|
|
731
|
-
|
|
721
|
+
onMessage(c) {
|
|
722
|
+
const a = JSON.parse(c.data);
|
|
723
|
+
s.forEach((r) => r(a.event, a));
|
|
732
724
|
}
|
|
733
725
|
}
|
|
734
726
|
});
|
|
735
727
|
return {
|
|
736
728
|
socket: o,
|
|
737
729
|
disconnect: () => o.close(),
|
|
738
|
-
subscribeToEvents: (
|
|
730
|
+
subscribeToEvents: (c) => s.push(c)
|
|
739
731
|
};
|
|
740
732
|
}
|
|
741
|
-
function
|
|
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];
|
|
753
745
|
(n == null ? void 0 : n.role) === "assistant" && !n.interrupted && (n.interrupted = !0);
|
|
754
|
-
const
|
|
746
|
+
const s = {
|
|
755
747
|
id: e.id || `user-${Date.now()}`,
|
|
756
748
|
role: e.role,
|
|
757
749
|
content: e.content,
|
|
758
750
|
created_at: e.created_at || (/* @__PURE__ */ new Date()).toISOString(),
|
|
759
751
|
transcribed: !0
|
|
760
752
|
};
|
|
761
|
-
t.messages.push(
|
|
753
|
+
t.messages.push(s), i == null || i([...t.messages], "user");
|
|
762
754
|
}
|
|
763
|
-
function Ft(e, t,
|
|
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
|
-
let
|
|
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 || "",
|
|
777
769
|
created_at: t.created_at || (/* @__PURE__ */ new Date()).toISOString()
|
|
778
|
-
}, n.messages.push(
|
|
770
|
+
}, n.messages.push(c);
|
|
779
771
|
else if ((o == null ? void 0 : o.role) === "assistant")
|
|
780
|
-
|
|
772
|
+
c = o;
|
|
781
773
|
else
|
|
782
774
|
return;
|
|
783
|
-
const { content:
|
|
784
|
-
e ===
|
|
785
|
-
const d =
|
|
786
|
-
(
|
|
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 = {};
|
|
782
|
+
const c = () => o = {}, a = (r, d) => {
|
|
783
|
+
var w, p;
|
|
784
|
+
d === "user" && c(), (p = (w = i.callbacks).onNewMessage) == null || p.call(w, r, d);
|
|
785
|
+
};
|
|
790
786
|
return {
|
|
791
|
-
clearQueue:
|
|
792
|
-
onMessage: (
|
|
793
|
-
var
|
|
794
|
-
if ("content" in
|
|
795
|
-
const
|
|
796
|
-
Ft(
|
|
787
|
+
clearQueue: c,
|
|
788
|
+
onMessage: (r, d) => {
|
|
789
|
+
var w, p;
|
|
790
|
+
if ("content" in d) {
|
|
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", {
|
|
797
793
|
messages: t.messages.length,
|
|
798
794
|
mode: t.chatMode
|
|
799
795
|
});
|
|
800
796
|
} else {
|
|
801
|
-
const
|
|
802
|
-
if (
|
|
803
|
-
e.linkTrack("agent-video",
|
|
804
|
-
else if (
|
|
805
|
-
const
|
|
806
|
-
|
|
797
|
+
const u = j, _ = [u.StreamVideoDone, u.StreamVideoError, u.StreamVideoRejected], $ = [u.StreamFailed, u.StreamVideoError, u.StreamVideoRejected], A = St(d, n, { mode: t.chatMode });
|
|
798
|
+
if (r = r, r === u.StreamVideoCreated)
|
|
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"]);
|
|
807
803
|
}
|
|
808
|
-
|
|
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();
|
|
809
805
|
}
|
|
810
806
|
}
|
|
811
807
|
};
|
|
812
808
|
}
|
|
813
|
-
function Nt(e, t,
|
|
814
|
-
const
|
|
809
|
+
function Nt(e, t, i, n) {
|
|
810
|
+
const s = Te(e, `${t}/agents/${i}`, n);
|
|
815
811
|
return {
|
|
816
|
-
createStream(o,
|
|
817
|
-
return
|
|
812
|
+
createStream(o, c) {
|
|
813
|
+
return s.post("/streams", o, { signal: c });
|
|
818
814
|
},
|
|
819
|
-
startConnection(o,
|
|
820
|
-
return
|
|
815
|
+
startConnection(o, c, a, r) {
|
|
816
|
+
return s.post(
|
|
821
817
|
`/streams/${o}/sdp`,
|
|
822
818
|
{
|
|
823
|
-
session_id:
|
|
824
|
-
answer:
|
|
819
|
+
session_id: a,
|
|
820
|
+
answer: c
|
|
825
821
|
},
|
|
826
822
|
{ signal: r }
|
|
827
823
|
);
|
|
828
824
|
},
|
|
829
|
-
addIceCandidate(o,
|
|
830
|
-
return
|
|
825
|
+
addIceCandidate(o, c, a, r) {
|
|
826
|
+
return s.post(
|
|
831
827
|
`/streams/${o}/ice`,
|
|
832
828
|
{
|
|
833
|
-
session_id:
|
|
834
|
-
...
|
|
829
|
+
session_id: a,
|
|
830
|
+
...c
|
|
835
831
|
},
|
|
836
832
|
{ signal: r }
|
|
837
833
|
);
|
|
838
834
|
},
|
|
839
|
-
sendStreamRequest(o,
|
|
840
|
-
return
|
|
841
|
-
session_id:
|
|
842
|
-
...
|
|
835
|
+
sendStreamRequest(o, c, a) {
|
|
836
|
+
return s.post(`/streams/${o}`, {
|
|
837
|
+
session_id: c,
|
|
838
|
+
...a
|
|
843
839
|
});
|
|
844
840
|
},
|
|
845
|
-
close(o,
|
|
846
|
-
return
|
|
841
|
+
close(o, c) {
|
|
842
|
+
return s.delete(`/streams/${o}`, { session_id: c });
|
|
847
843
|
}
|
|
848
844
|
};
|
|
849
845
|
}
|
|
850
|
-
function Kt(e, t,
|
|
846
|
+
function Kt(e, t, i) {
|
|
851
847
|
const n = (t.timestamp - e.timestamp) / 1e3;
|
|
852
848
|
return {
|
|
853
849
|
duration: n,
|
|
@@ -864,31 +860,31 @@ function Kt(e, t, a) {
|
|
|
864
860
|
framesPerSecond: t.framesPerSecond,
|
|
865
861
|
freezeCount: t.freezeCount - e.freezeCount,
|
|
866
862
|
freezeDuration: t.freezeDuration - e.freezeDuration,
|
|
867
|
-
lowFpsCount:
|
|
863
|
+
lowFpsCount: i
|
|
868
864
|
};
|
|
869
865
|
}
|
|
870
866
|
function Jt(e) {
|
|
871
867
|
return e.filter(
|
|
872
868
|
(t) => t.freezeCount > 0 || t.framesPerSecond < 21 || t.framesDropped > 0 || t.packetsLost > 0
|
|
873
869
|
).map((t) => {
|
|
874
|
-
const { timestamp:
|
|
875
|
-
return t.freezeCount > 0 &&
|
|
870
|
+
const { timestamp: i, ...n } = t, s = [];
|
|
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"), {
|
|
876
872
|
...n,
|
|
877
|
-
causes:
|
|
873
|
+
causes: s
|
|
878
874
|
};
|
|
879
875
|
});
|
|
880
876
|
}
|
|
881
877
|
function Ut(e) {
|
|
882
|
-
let t = "",
|
|
878
|
+
let t = "", i = 0;
|
|
883
879
|
for (const n of e.values()) {
|
|
884
880
|
if (n && n.type === "codec" && n.mimeType.startsWith("video") && (t = n.mimeType.split("/")[1]), n && n.type === "candidate-pair") {
|
|
885
|
-
const
|
|
886
|
-
|
|
881
|
+
const s = n.currentRoundTripTime, c = n.nominated === !0;
|
|
882
|
+
s > 0 && (c || i === 0) && (i = s);
|
|
887
883
|
}
|
|
888
884
|
if (n && n.type === "inbound-rtp" && n.kind === "video")
|
|
889
885
|
return {
|
|
890
886
|
codec: t,
|
|
891
|
-
rtt:
|
|
887
|
+
rtt: i,
|
|
892
888
|
timestamp: n.timestamp,
|
|
893
889
|
bytesReceived: n.bytesReceived,
|
|
894
890
|
packetsReceived: n.packetsReceived,
|
|
@@ -908,24 +904,24 @@ function Ut(e) {
|
|
|
908
904
|
}
|
|
909
905
|
return {};
|
|
910
906
|
}
|
|
911
|
-
function
|
|
912
|
-
const n = e.map((r, d) => d === 0 ?
|
|
907
|
+
function Vt(e, t, i) {
|
|
908
|
+
const n = e.map((r, d) => d === 0 ? i ? {
|
|
913
909
|
timestamp: r.timestamp,
|
|
914
910
|
duration: 0,
|
|
915
911
|
rtt: r.rtt,
|
|
916
|
-
bytesReceived: r.bytesReceived -
|
|
917
|
-
bitrate: (r.bytesReceived -
|
|
918
|
-
packetsReceived: r.packetsReceived -
|
|
919
|
-
packetsLost: r.packetsLost -
|
|
920
|
-
framesDropped: r.framesDropped -
|
|
921
|
-
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,
|
|
922
918
|
jitter: r.jitter,
|
|
923
|
-
jitterBufferDelay: r.jitterBufferDelay -
|
|
924
|
-
jitterBufferEmittedCount: r.jitterBufferEmittedCount -
|
|
925
|
-
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),
|
|
926
922
|
framesPerSecond: r.framesPerSecond,
|
|
927
|
-
freezeCount: r.freezeCount -
|
|
928
|
-
freezeDuration: r.freezeDuration -
|
|
923
|
+
freezeCount: r.freezeCount - i.freezeCount,
|
|
924
|
+
freezeDuration: r.freezeDuration - i.freezeDuration
|
|
929
925
|
} : {
|
|
930
926
|
timestamp: r.timestamp,
|
|
931
927
|
rtt: r.rtt,
|
|
@@ -960,50 +956,50 @@ function Wt(e, t, a) {
|
|
|
960
956
|
framesPerSecond: r.framesPerSecond,
|
|
961
957
|
freezeCount: r.freezeCount - e[d - 1].freezeCount,
|
|
962
958
|
freezeDuration: r.freezeDuration - e[d - 1].freezeDuration
|
|
963
|
-
}),
|
|
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);
|
|
964
960
|
return {
|
|
965
961
|
webRTCStats: {
|
|
966
|
-
anomalies:
|
|
967
|
-
minRtt: Math.min(...
|
|
968
|
-
avgRtt: $e(
|
|
969
|
-
maxRtt: Math.max(...
|
|
962
|
+
anomalies: s,
|
|
963
|
+
minRtt: Math.min(...a),
|
|
964
|
+
avgRtt: $e(a),
|
|
965
|
+
maxRtt: Math.max(...a),
|
|
970
966
|
aggregateReport: Kt(e[0], e[e.length - 1], o),
|
|
971
|
-
minJitterDelayInInterval: Math.min(...
|
|
972
|
-
maxJitterDelayInInterval: Math.max(...
|
|
973
|
-
avgJitterDelayInInterval: $e(
|
|
967
|
+
minJitterDelayInInterval: Math.min(...c),
|
|
968
|
+
maxJitterDelayInInterval: Math.max(...c),
|
|
969
|
+
avgJitterDelayInInterval: $e(c)
|
|
974
970
|
},
|
|
975
971
|
codec: e[0].codec,
|
|
976
972
|
resolution: `${e[0].frameWidth}x${e[0].frameHeight}`
|
|
977
973
|
};
|
|
978
974
|
}
|
|
979
|
-
const Me = 100,
|
|
980
|
-
function
|
|
981
|
-
let e = 0, t,
|
|
982
|
-
return (
|
|
983
|
-
for (const o of
|
|
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;
|
|
978
|
+
return (s) => {
|
|
979
|
+
for (const o of s.values())
|
|
984
980
|
if (o && o.type === "inbound-rtp" && o.kind === "video") {
|
|
985
|
-
const
|
|
986
|
-
if (
|
|
987
|
-
const
|
|
988
|
-
n =
|
|
981
|
+
const c = o.jitterBufferDelay, a = o.jitterBufferEmittedCount;
|
|
982
|
+
if (i && a > i) {
|
|
983
|
+
const w = c - t, p = a - i;
|
|
984
|
+
n = w / p;
|
|
989
985
|
}
|
|
990
|
-
t =
|
|
986
|
+
t = c, i = a;
|
|
991
987
|
const r = o.framesDecoded, d = r - e > 0;
|
|
992
988
|
return e = r, { isReceiving: d, avgJitterDelayInInterval: n, freezeCount: o.freezeCount };
|
|
993
989
|
}
|
|
994
990
|
return { isReceiving: !1, avgJitterDelayInInterval: n };
|
|
995
991
|
};
|
|
996
992
|
}
|
|
997
|
-
function Qt(e, t,
|
|
998
|
-
let o = [],
|
|
999
|
-
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();
|
|
1000
996
|
return setInterval(async () => {
|
|
1001
|
-
const $ = await e.getStats(), { isReceiving:
|
|
1002
|
-
if (
|
|
1003
|
-
|
|
1004
|
-
else if (r && (
|
|
1005
|
-
const
|
|
1006
|
-
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;
|
|
1007
1003
|
}
|
|
1008
1004
|
}, Me);
|
|
1009
1005
|
}
|
|
@@ -1011,249 +1007,255 @@ const Xt = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window
|
|
|
1011
1007
|
function Fe(e) {
|
|
1012
1008
|
switch (e) {
|
|
1013
1009
|
case "connected":
|
|
1014
|
-
return
|
|
1010
|
+
return R.Connected;
|
|
1015
1011
|
case "checking":
|
|
1016
|
-
return
|
|
1012
|
+
return R.Connecting;
|
|
1017
1013
|
case "failed":
|
|
1018
|
-
return
|
|
1014
|
+
return R.Fail;
|
|
1019
1015
|
case "new":
|
|
1020
|
-
return
|
|
1016
|
+
return R.New;
|
|
1021
1017
|
case "closed":
|
|
1022
|
-
return
|
|
1018
|
+
return R.Closed;
|
|
1023
1019
|
case "disconnected":
|
|
1024
|
-
return
|
|
1020
|
+
return R.Disconnected;
|
|
1025
1021
|
case "completed":
|
|
1026
|
-
return
|
|
1022
|
+
return R.Completed;
|
|
1027
1023
|
default:
|
|
1028
|
-
return
|
|
1024
|
+
return R.New;
|
|
1029
1025
|
}
|
|
1030
1026
|
}
|
|
1031
1027
|
const Yt = (e) => (t) => {
|
|
1032
|
-
const [
|
|
1028
|
+
const [i, n = ""] = t.split(/:(.+)/);
|
|
1033
1029
|
try {
|
|
1034
|
-
const
|
|
1035
|
-
return e("parsed data channel message", { subject:
|
|
1036
|
-
} catch (
|
|
1037
|
-
return e("Failed to parse data channel message, returning data as string", { subject:
|
|
1030
|
+
const s = JSON.parse(n);
|
|
1031
|
+
return e("parsed data channel message", { subject: i, data: s }), { subject: i, data: s };
|
|
1032
|
+
} catch (s) {
|
|
1033
|
+
return e("Failed to parse data channel message, returning data as string", { subject: i, rawData: n, error: s }), { subject: i, data: n };
|
|
1038
1034
|
}
|
|
1039
1035
|
};
|
|
1040
1036
|
function Gt({
|
|
1041
1037
|
statsSignal: e,
|
|
1042
1038
|
dataChannelSignal: t,
|
|
1043
|
-
onVideoStateChange:
|
|
1044
|
-
report: n
|
|
1039
|
+
onVideoStateChange: i,
|
|
1040
|
+
report: n,
|
|
1041
|
+
log: s
|
|
1045
1042
|
}) {
|
|
1046
|
-
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));
|
|
1047
1044
|
}
|
|
1048
1045
|
function Zt({
|
|
1049
1046
|
statsSignal: e,
|
|
1050
1047
|
dataChannelSignal: t,
|
|
1051
|
-
onVideoStateChange:
|
|
1048
|
+
onVideoStateChange: i,
|
|
1052
1049
|
onAgentActivityStateChange: n,
|
|
1053
|
-
report:
|
|
1050
|
+
report: s,
|
|
1051
|
+
log: o
|
|
1054
1052
|
}) {
|
|
1055
|
-
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));
|
|
1056
1054
|
}
|
|
1057
1055
|
function ze({
|
|
1058
1056
|
statsSignal: e,
|
|
1059
1057
|
dataChannelSignal: t,
|
|
1060
|
-
onVideoStateChange:
|
|
1058
|
+
onVideoStateChange: i,
|
|
1061
1059
|
onAgentActivityStateChange: n,
|
|
1062
|
-
streamType:
|
|
1063
|
-
report: o
|
|
1060
|
+
streamType: s,
|
|
1061
|
+
report: o,
|
|
1062
|
+
log: c
|
|
1064
1063
|
}) {
|
|
1065
|
-
|
|
1064
|
+
s === ae.Legacy ? Gt({ statsSignal: e, dataChannelSignal: t, onVideoStateChange: i, report: o, log: c }) : s === ae.Fluent && Zt({
|
|
1066
1065
|
statsSignal: e,
|
|
1067
1066
|
dataChannelSignal: t,
|
|
1068
|
-
onVideoStateChange:
|
|
1067
|
+
onVideoStateChange: i,
|
|
1069
1068
|
onAgentActivityStateChange: n,
|
|
1070
|
-
report: o
|
|
1069
|
+
report: o,
|
|
1070
|
+
log: c
|
|
1071
1071
|
});
|
|
1072
1072
|
}
|
|
1073
|
-
async function en(e, t, { debug:
|
|
1074
|
-
var
|
|
1075
|
-
const r =
|
|
1076
|
-
let
|
|
1077
|
-
const { startConnection: $, sendStreamRequest:
|
|
1078
|
-
|
|
1073
|
+
async function en(e, t, { debug: i = !1, callbacks: n, auth: s, baseURL: o = ge, analytics: c }, a) {
|
|
1074
|
+
var V;
|
|
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(
|
|
1078
|
+
s,
|
|
1079
1079
|
o,
|
|
1080
1080
|
e,
|
|
1081
1081
|
n.onError
|
|
1082
1082
|
), {
|
|
1083
|
-
id:
|
|
1084
|
-
offer:
|
|
1085
|
-
ice_servers:
|
|
1086
|
-
session_id:
|
|
1087
|
-
fluent:
|
|
1083
|
+
id: I,
|
|
1084
|
+
offer: U,
|
|
1085
|
+
ice_servers: te,
|
|
1086
|
+
session_id: M,
|
|
1087
|
+
fluent: Y,
|
|
1088
1088
|
interrupt_enabled: Z,
|
|
1089
1089
|
triggers_enabled: f
|
|
1090
|
-
} = await
|
|
1091
|
-
(
|
|
1092
|
-
const y = new Xt({ iceServers:
|
|
1093
|
-
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)
|
|
1094
1094
|
throw new Error("Could not create session_id");
|
|
1095
|
-
const
|
|
1096
|
-
|
|
1097
|
-
"stream-type":
|
|
1095
|
+
const T = Y ? ae.Fluent : ae.Legacy;
|
|
1096
|
+
c.enrich({
|
|
1097
|
+
"stream-type": T
|
|
1098
1098
|
});
|
|
1099
|
-
const
|
|
1099
|
+
const P = t.stream_warmup && !Y, E = () => w, J = () => {
|
|
1100
1100
|
var m;
|
|
1101
|
-
|
|
1102
|
-
},
|
|
1101
|
+
w = !0, p && (r("CALLBACK: onConnectionStateChange(Connected)"), (m = n.onConnectionStateChange) == null || m.call(n, R.Connected));
|
|
1102
|
+
}, O = Qt(
|
|
1103
1103
|
y,
|
|
1104
|
-
|
|
1104
|
+
E,
|
|
1105
1105
|
J,
|
|
1106
|
-
(m,
|
|
1107
|
-
statsSignal:
|
|
1108
|
-
dataChannelSignal:
|
|
1106
|
+
(m, h) => ze({
|
|
1107
|
+
statsSignal: _ = m,
|
|
1108
|
+
dataChannelSignal: T === ae.Legacy ? u : void 0,
|
|
1109
1109
|
onVideoStateChange: n.onVideoStateChange,
|
|
1110
1110
|
onAgentActivityStateChange: n.onAgentActivityStateChange,
|
|
1111
|
-
report:
|
|
1112
|
-
streamType:
|
|
1111
|
+
report: h,
|
|
1112
|
+
streamType: T,
|
|
1113
|
+
log: r
|
|
1113
1114
|
}),
|
|
1114
1115
|
(m) => {
|
|
1115
|
-
var
|
|
1116
|
-
return (
|
|
1116
|
+
var h;
|
|
1117
|
+
return (h = n.onConnectivityStateChange) == null ? void 0 : h.call(n, m);
|
|
1117
1118
|
}
|
|
1118
1119
|
);
|
|
1119
1120
|
y.onicecandidate = (m) => {
|
|
1120
|
-
var
|
|
1121
|
+
var h;
|
|
1121
1122
|
r("peerConnection.onicecandidate", m);
|
|
1122
1123
|
try {
|
|
1123
1124
|
m.candidate && m.candidate.sdpMid && m.candidate.sdpMLineIndex !== null ? z(
|
|
1124
|
-
|
|
1125
|
+
I,
|
|
1125
1126
|
{
|
|
1126
1127
|
candidate: m.candidate.candidate,
|
|
1127
1128
|
sdpMid: m.candidate.sdpMid,
|
|
1128
1129
|
sdpMLineIndex: m.candidate.sdpMLineIndex
|
|
1129
1130
|
},
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
) : z(
|
|
1133
|
-
} catch (
|
|
1134
|
-
(
|
|
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 });
|
|
1135
1136
|
}
|
|
1136
1137
|
}, k.onopen = () => {
|
|
1137
|
-
|
|
1138
|
+
p = !0, (!P || w) && J();
|
|
1138
1139
|
};
|
|
1139
|
-
const
|
|
1140
|
-
var
|
|
1141
|
-
(
|
|
1140
|
+
const H = (m) => {
|
|
1141
|
+
var h;
|
|
1142
|
+
(h = n.onVideoIdChange) == null || h.call(n, m);
|
|
1142
1143
|
};
|
|
1143
|
-
function
|
|
1144
|
-
if (m === j.StreamStarted && typeof
|
|
1145
|
-
const
|
|
1146
|
-
|
|
1144
|
+
function L(m, h) {
|
|
1145
|
+
if (m === j.StreamStarted && typeof h == "object" && "metadata" in h) {
|
|
1146
|
+
const x = h.metadata;
|
|
1147
|
+
H(x.videoId);
|
|
1147
1148
|
}
|
|
1148
|
-
m === j.StreamDone &&
|
|
1149
|
-
statsSignal:
|
|
1149
|
+
m === j.StreamDone && H(null), u = m === j.StreamStarted ? S.Start : S.Stop, ze({
|
|
1150
|
+
statsSignal: T === ae.Legacy ? _ : void 0,
|
|
1150
1151
|
dataChannelSignal: u,
|
|
1151
1152
|
onVideoStateChange: n.onVideoStateChange,
|
|
1152
1153
|
onAgentActivityStateChange: n.onAgentActivityStateChange,
|
|
1153
|
-
streamType:
|
|
1154
|
+
streamType: T,
|
|
1155
|
+
log: r
|
|
1154
1156
|
});
|
|
1155
1157
|
}
|
|
1156
|
-
function N(m,
|
|
1158
|
+
function N(m, h) {
|
|
1157
1159
|
var K;
|
|
1158
|
-
const
|
|
1159
|
-
|
|
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);
|
|
1160
1162
|
}
|
|
1161
|
-
const
|
|
1162
|
-
[j.StreamStarted]:
|
|
1163
|
-
[j.StreamDone]:
|
|
1163
|
+
const q = {
|
|
1164
|
+
[j.StreamStarted]: L,
|
|
1165
|
+
[j.StreamDone]: L,
|
|
1164
1166
|
[j.StreamReady]: N
|
|
1165
1167
|
};
|
|
1166
1168
|
k.onmessage = (m) => {
|
|
1167
1169
|
var K;
|
|
1168
|
-
const { subject:
|
|
1169
|
-
(K =
|
|
1170
|
+
const { subject: h, data: x } = d(m.data);
|
|
1171
|
+
(K = q[h]) == null || K.call(q, h, x);
|
|
1170
1172
|
}, y.oniceconnectionstatechange = () => {
|
|
1171
|
-
var
|
|
1173
|
+
var h;
|
|
1172
1174
|
r("peerConnection.oniceconnectionstatechange => " + y.iceConnectionState);
|
|
1173
1175
|
const m = Fe(y.iceConnectionState);
|
|
1174
|
-
m !==
|
|
1176
|
+
m !== R.Connected && ((h = n.onConnectionStateChange) == null || h.call(n, m));
|
|
1175
1177
|
}, y.ontrack = (m) => {
|
|
1176
|
-
var
|
|
1177
|
-
r("peerConnection.ontrack", m), (
|
|
1178
|
-
}, await y.setRemoteDescription(
|
|
1178
|
+
var h;
|
|
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");
|
|
1179
1181
|
const oe = await y.createAnswer();
|
|
1180
|
-
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"), {
|
|
1181
1183
|
/**
|
|
1182
1184
|
* Method to send request to server to get clip or talk depend on you payload
|
|
1183
1185
|
* @param payload
|
|
1184
1186
|
*/
|
|
1185
1187
|
speak(m) {
|
|
1186
|
-
return
|
|
1188
|
+
return A(I, M, m);
|
|
1187
1189
|
},
|
|
1188
1190
|
/**
|
|
1189
1191
|
* Method to close RTC connection
|
|
1190
1192
|
*/
|
|
1191
1193
|
async disconnect() {
|
|
1192
1194
|
var m;
|
|
1193
|
-
if (
|
|
1194
|
-
const
|
|
1195
|
+
if (I) {
|
|
1196
|
+
const h = Fe(y.iceConnectionState);
|
|
1195
1197
|
if (y) {
|
|
1196
|
-
if (
|
|
1197
|
-
clearInterval(
|
|
1198
|
+
if (h === R.New) {
|
|
1199
|
+
clearInterval(O);
|
|
1198
1200
|
return;
|
|
1199
1201
|
}
|
|
1200
1202
|
y.close(), y.oniceconnectionstatechange = null, y.onnegotiationneeded = null, y.onicecandidate = null, y.ontrack = null;
|
|
1201
1203
|
}
|
|
1202
1204
|
try {
|
|
1203
|
-
|
|
1205
|
+
h === R.Connected && await C(I, M).catch((x) => {
|
|
1204
1206
|
});
|
|
1205
|
-
} catch (
|
|
1206
|
-
r("Error on close stream connection",
|
|
1207
|
+
} catch (x) {
|
|
1208
|
+
r("Error on close stream connection", x);
|
|
1207
1209
|
}
|
|
1208
|
-
(m = n.onAgentActivityStateChange) == null || m.call(n,
|
|
1210
|
+
(m = n.onAgentActivityStateChange) == null || m.call(n, W.Idle), clearInterval(O);
|
|
1209
1211
|
}
|
|
1210
1212
|
},
|
|
1211
1213
|
/**
|
|
1212
1214
|
* Method to send data channel messages to the server
|
|
1213
1215
|
*/
|
|
1214
1216
|
sendDataChannelMessage(m) {
|
|
1215
|
-
var
|
|
1216
|
-
if (!
|
|
1217
|
-
r("Data channel is not ready for sending messages"), (
|
|
1218
|
-
streamId:
|
|
1217
|
+
var h, x;
|
|
1218
|
+
if (!w || k.readyState !== "open") {
|
|
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"), {
|
|
1220
|
+
streamId: I
|
|
1219
1221
|
});
|
|
1220
1222
|
return;
|
|
1221
1223
|
}
|
|
1222
1224
|
try {
|
|
1223
1225
|
k.send(m);
|
|
1224
1226
|
} catch (K) {
|
|
1225
|
-
r("Error sending data channel message", K), (
|
|
1227
|
+
r("Error sending data channel message", K), (x = n.onError) == null || x.call(n, K, { streamId: I });
|
|
1226
1228
|
}
|
|
1227
1229
|
},
|
|
1228
1230
|
/**
|
|
1229
1231
|
* Session identifier information, should be returned in the body of all streaming requests
|
|
1230
1232
|
*/
|
|
1231
|
-
sessionId:
|
|
1233
|
+
sessionId: M,
|
|
1232
1234
|
/**
|
|
1233
1235
|
* Id of current RTC stream
|
|
1234
1236
|
*/
|
|
1235
|
-
streamId:
|
|
1236
|
-
streamType:
|
|
1237
|
+
streamId: I,
|
|
1238
|
+
streamType: T,
|
|
1237
1239
|
interruptAvailable: Z ?? !1,
|
|
1238
1240
|
triggersAvailable: f ?? !1
|
|
1239
1241
|
};
|
|
1240
1242
|
}
|
|
1241
1243
|
var Ee = /* @__PURE__ */ ((e) => (e.V1 = "v1", e.V2 = "v2", e))(Ee || {});
|
|
1242
|
-
async function tn(e, t,
|
|
1243
|
-
const
|
|
1244
|
+
async function tn(e, t, i, n) {
|
|
1245
|
+
const s = e.id;
|
|
1244
1246
|
switch (t.version) {
|
|
1245
1247
|
case "v1": {
|
|
1246
|
-
const { version: o, ...
|
|
1247
|
-
return en(
|
|
1248
|
+
const { version: o, ...c } = t;
|
|
1249
|
+
return en(s, c, i, n);
|
|
1248
1250
|
}
|
|
1249
1251
|
case "v2": {
|
|
1250
|
-
const { version: o, ...
|
|
1251
|
-
switch (
|
|
1252
|
+
const { version: o, ...c } = t;
|
|
1253
|
+
switch (c.transport_provider) {
|
|
1252
1254
|
case ye.Livekit:
|
|
1253
|
-
const { createLiveKitStreamingManager:
|
|
1254
|
-
return
|
|
1255
|
+
const { createLiveKitStreamingManager: a } = await Promise.resolve().then(() => _t);
|
|
1256
|
+
return a(s, c, i);
|
|
1255
1257
|
default:
|
|
1256
|
-
throw new Error(`Unsupported transport provider: ${
|
|
1258
|
+
throw new Error(`Unsupported transport provider: ${c.transport_provider}`);
|
|
1257
1259
|
}
|
|
1258
1260
|
}
|
|
1259
1261
|
default:
|
|
@@ -1267,8 +1269,8 @@ function rn() {
|
|
|
1267
1269
|
};
|
|
1268
1270
|
}
|
|
1269
1271
|
function an(e) {
|
|
1270
|
-
var
|
|
1271
|
-
const { streamOptions: t } = e ?? {},
|
|
1272
|
+
var s, o;
|
|
1273
|
+
const { streamOptions: t } = e ?? {}, i = ((s = e == null ? void 0 : e.mixpanelAdditionalProperties) == null ? void 0 : s.plan) !== void 0 ? {
|
|
1272
1274
|
plan: (o = e.mixpanelAdditionalProperties) == null ? void 0 : o.plan
|
|
1273
1275
|
} : void 0;
|
|
1274
1276
|
return { ...{
|
|
@@ -1277,30 +1279,30 @@ function an(e) {
|
|
|
1277
1279
|
stream_warmup: t == null ? void 0 : t.streamWarmup,
|
|
1278
1280
|
compatibility_mode: t == null ? void 0 : t.compatibilityMode,
|
|
1279
1281
|
fluent: t == null ? void 0 : t.fluent
|
|
1280
|
-
}, ...
|
|
1282
|
+
}, ...i && { end_user_data: i } };
|
|
1281
1283
|
}
|
|
1282
1284
|
function on(e, t) {
|
|
1283
1285
|
return Ie(e.presenter.type) ? { version: Ee.V2, ...rn() } : { version: Ee.V1, ...an(t) };
|
|
1284
1286
|
}
|
|
1285
|
-
function sn(e, t,
|
|
1286
|
-
|
|
1287
|
+
function sn(e, t, i, n, s) {
|
|
1288
|
+
s === ae.Fluent ? cn(e, t, i, n, s) : un(e, t, i, n, s);
|
|
1287
1289
|
}
|
|
1288
|
-
function cn(e, t,
|
|
1289
|
-
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", {
|
|
1290
1292
|
event: "stop",
|
|
1291
1293
|
is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
|
|
1292
1294
|
background: t.presenter.type === "clip" && t.presenter.background,
|
|
1293
|
-
"stream-type":
|
|
1294
|
-
...
|
|
1295
|
+
"stream-type": s,
|
|
1296
|
+
...i
|
|
1295
1297
|
});
|
|
1296
1298
|
}
|
|
1297
|
-
function dn(e, t,
|
|
1298
|
-
|
|
1299
|
+
function dn(e, t, i, n) {
|
|
1300
|
+
ee.get() <= 0 || (e === S.Start ? i.linkTrack(
|
|
1299
1301
|
"agent-video",
|
|
1300
|
-
{ event: "start", latency:
|
|
1302
|
+
{ event: "start", latency: ee.get(!0), "stream-type": n },
|
|
1301
1303
|
"start",
|
|
1302
1304
|
[j.StreamVideoCreated]
|
|
1303
|
-
) : e ===
|
|
1305
|
+
) : e === S.Stop && i.linkTrack(
|
|
1304
1306
|
"agent-video",
|
|
1305
1307
|
{
|
|
1306
1308
|
event: "stop",
|
|
@@ -1312,135 +1314,135 @@ function dn(e, t, a, n) {
|
|
|
1312
1314
|
[j.StreamVideoDone]
|
|
1313
1315
|
));
|
|
1314
1316
|
}
|
|
1315
|
-
function un(e, t,
|
|
1316
|
-
|
|
1317
|
+
function un(e, t, i, n, s) {
|
|
1318
|
+
ee.get() <= 0 || (e === S.Start ? n.linkTrack(
|
|
1317
1319
|
"agent-video",
|
|
1318
|
-
{ event: "start", latency:
|
|
1320
|
+
{ event: "start", latency: ee.get(!0), "stream-type": s },
|
|
1319
1321
|
"start",
|
|
1320
1322
|
[j.StreamVideoCreated]
|
|
1321
|
-
) : e ===
|
|
1323
|
+
) : e === S.Stop && n.linkTrack(
|
|
1322
1324
|
"agent-video",
|
|
1323
1325
|
{
|
|
1324
1326
|
event: "stop",
|
|
1325
1327
|
is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
|
|
1326
1328
|
background: t.presenter.type === "clip" && t.presenter.background,
|
|
1327
|
-
"stream-type":
|
|
1328
|
-
...
|
|
1329
|
+
"stream-type": s,
|
|
1330
|
+
...i
|
|
1329
1331
|
},
|
|
1330
1332
|
"done",
|
|
1331
1333
|
[j.StreamVideoDone]
|
|
1332
1334
|
));
|
|
1333
1335
|
}
|
|
1334
|
-
function Ne(e, t,
|
|
1335
|
-
return
|
|
1336
|
+
function Ne(e, t, i, n) {
|
|
1337
|
+
return ee.reset(), xe.update(), new Promise(async (s, o) => {
|
|
1336
1338
|
try {
|
|
1337
|
-
let
|
|
1339
|
+
let c, a = !1;
|
|
1338
1340
|
const r = on(e, t);
|
|
1339
|
-
|
|
1341
|
+
i.enrich({
|
|
1340
1342
|
"stream-version": r.version.toString()
|
|
1341
|
-
}),
|
|
1343
|
+
}), c = await tn(
|
|
1342
1344
|
e,
|
|
1343
1345
|
r,
|
|
1344
1346
|
{
|
|
1345
1347
|
...t,
|
|
1346
|
-
analytics:
|
|
1348
|
+
analytics: i,
|
|
1347
1349
|
callbacks: {
|
|
1348
1350
|
...t.callbacks,
|
|
1349
1351
|
onConnectionStateChange: (d) => {
|
|
1350
|
-
var
|
|
1351
|
-
(
|
|
1352
|
+
var w, p;
|
|
1353
|
+
(p = (w = t.callbacks).onConnectionStateChange) == null || p.call(w, d), d === R.Connected && (c ? s(c) : a = !0);
|
|
1352
1354
|
},
|
|
1353
|
-
onVideoStateChange: (d,
|
|
1354
|
-
var
|
|
1355
|
-
(u = (
|
|
1355
|
+
onVideoStateChange: (d, w) => {
|
|
1356
|
+
var p, u;
|
|
1357
|
+
(u = (p = t.callbacks).onVideoStateChange) == null || u.call(p, d), sn(
|
|
1356
1358
|
d,
|
|
1357
1359
|
e,
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1360
|
+
w,
|
|
1361
|
+
i,
|
|
1362
|
+
c.streamType
|
|
1361
1363
|
);
|
|
1362
1364
|
},
|
|
1363
1365
|
onAgentActivityStateChange: (d) => {
|
|
1364
|
-
var
|
|
1365
|
-
(
|
|
1366
|
-
d ===
|
|
1366
|
+
var w, p;
|
|
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,
|
|
1367
1369
|
e,
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
+
i,
|
|
1371
|
+
c.streamType
|
|
1370
1372
|
);
|
|
1371
1373
|
},
|
|
1372
1374
|
onStreamReady: () => {
|
|
1373
|
-
const d =
|
|
1374
|
-
|
|
1375
|
+
const d = xe.get(!0);
|
|
1376
|
+
i.track("agent-chat", { event: "ready", latency: d });
|
|
1375
1377
|
}
|
|
1376
1378
|
}
|
|
1377
1379
|
},
|
|
1378
1380
|
n
|
|
1379
|
-
),
|
|
1380
|
-
} catch (
|
|
1381
|
-
o(
|
|
1381
|
+
), a && s(c);
|
|
1382
|
+
} catch (c) {
|
|
1383
|
+
o(c);
|
|
1382
1384
|
}
|
|
1383
1385
|
});
|
|
1384
1386
|
}
|
|
1385
|
-
async function ln(e, t,
|
|
1386
|
-
var
|
|
1387
|
+
async function ln(e, t, i, n, s) {
|
|
1388
|
+
var w, p, u, _;
|
|
1387
1389
|
const o = async () => {
|
|
1388
1390
|
if (Ie(e.presenter.type)) {
|
|
1389
|
-
const $ = await Ne(e, t, n),
|
|
1391
|
+
const $ = await Ne(e, t, n), A = `${nn}_${$.sessionId}`, C = (/* @__PURE__ */ new Date()).toISOString();
|
|
1390
1392
|
return { chatResult: {
|
|
1391
1393
|
chatMode: F.Functional,
|
|
1392
1394
|
chat: {
|
|
1393
|
-
id:
|
|
1395
|
+
id: A,
|
|
1394
1396
|
agent_id: e.id,
|
|
1395
1397
|
owner_id: e.owner_id ?? "",
|
|
1396
|
-
created:
|
|
1397
|
-
modified:
|
|
1398
|
-
agent_id__created_at:
|
|
1399
|
-
agent_id__modified_at:
|
|
1398
|
+
created: C,
|
|
1399
|
+
modified: C,
|
|
1400
|
+
agent_id__created_at: C,
|
|
1401
|
+
agent_id__modified_at: C,
|
|
1400
1402
|
chat_mode: F.Functional,
|
|
1401
1403
|
messages: []
|
|
1402
1404
|
}
|
|
1403
1405
|
}, streamingManager: $ };
|
|
1404
1406
|
} else {
|
|
1405
|
-
const $ = new AbortController(),
|
|
1406
|
-
let
|
|
1407
|
+
const $ = new AbortController(), A = $.signal;
|
|
1408
|
+
let C;
|
|
1407
1409
|
try {
|
|
1408
|
-
const
|
|
1410
|
+
const B = He(
|
|
1409
1411
|
e,
|
|
1410
|
-
|
|
1412
|
+
i,
|
|
1411
1413
|
n,
|
|
1412
1414
|
t.mode,
|
|
1413
1415
|
t.persistentChat,
|
|
1414
|
-
|
|
1415
|
-
), z = Ne(e, t, n,
|
|
1416
|
-
return { chatResult:
|
|
1417
|
-
} catch (
|
|
1418
|
-
throw $.abort(),
|
|
1419
|
-
}),
|
|
1416
|
+
s
|
|
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;
|
|
1420
1422
|
}
|
|
1421
1423
|
}
|
|
1422
|
-
}, { chatResult:
|
|
1423
|
-
return d && t.mode !== void 0 && d !== t.mode && (t.mode = 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 };
|
|
1424
1426
|
}
|
|
1425
1427
|
async function gn(e, t) {
|
|
1426
|
-
var
|
|
1427
|
-
let
|
|
1428
|
-
const
|
|
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 = {
|
|
1429
1431
|
messages: [],
|
|
1430
|
-
chatMode:
|
|
1432
|
+
chatMode: a
|
|
1431
1433
|
}, d = Rt({
|
|
1432
|
-
token:
|
|
1434
|
+
token: s,
|
|
1433
1435
|
agentId: e,
|
|
1434
1436
|
isEnabled: t.enableAnalitics,
|
|
1435
1437
|
externalId: t.externalId,
|
|
1436
1438
|
mixpanelAdditionalProperties: t.mixpanelAdditionalProperties
|
|
1437
|
-
}),
|
|
1438
|
-
|
|
1439
|
-
d.track("agent-sdk", { event: "init" },
|
|
1439
|
+
}), w = Date.now();
|
|
1440
|
+
Be(() => {
|
|
1441
|
+
d.track("agent-sdk", { event: "init" }, w);
|
|
1440
1442
|
});
|
|
1441
|
-
const
|
|
1443
|
+
const p = wt(t.auth, c, t.callbacks.onError, t.externalId), u = await p.getById(e), _ = Ie(u.presenter.type);
|
|
1442
1444
|
d.enrich(vt(u));
|
|
1443
|
-
const { onMessage: $, clearQueue:
|
|
1445
|
+
const { onMessage: $, clearQueue: A } = zt(
|
|
1444
1446
|
d,
|
|
1445
1447
|
r,
|
|
1446
1448
|
t,
|
|
@@ -1450,43 +1452,43 @@ async function gn(e, t) {
|
|
|
1450
1452
|
return (f = r.socketManager) == null ? void 0 : f.disconnect();
|
|
1451
1453
|
}
|
|
1452
1454
|
);
|
|
1453
|
-
r.messages = Mt(t.initialMessages), (
|
|
1454
|
-
const
|
|
1455
|
+
r.messages = Mt(t.initialMessages), (Y = (M = t.callbacks).onNewMessage) == null || Y.call(M, [...r.messages], "answer");
|
|
1456
|
+
const C = (f) => {
|
|
1455
1457
|
n = f;
|
|
1456
|
-
},
|
|
1457
|
-
var k,
|
|
1458
|
+
}, B = ({ type: f }) => {
|
|
1459
|
+
var k, T, P;
|
|
1458
1460
|
const y = r.messages[r.messages.length - 1];
|
|
1459
1461
|
d.track("agent-video-interrupt", {
|
|
1460
1462
|
type: f || "click",
|
|
1461
1463
|
video_duration_to_interrupt: Re.get(!0),
|
|
1462
|
-
message_duration_to_interrupt:
|
|
1463
|
-
}), y.interrupted = !0, (
|
|
1464
|
+
message_duration_to_interrupt: ee.get(!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));
|
|
1464
1466
|
}, z = Date.now();
|
|
1465
|
-
|
|
1467
|
+
Be(() => {
|
|
1466
1468
|
d.track("agent-sdk", { event: "loaded", ...yt(u) }, z);
|
|
1467
1469
|
});
|
|
1468
|
-
async function
|
|
1469
|
-
var J,
|
|
1470
|
-
(
|
|
1471
|
-
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(
|
|
1472
1474
|
t.auth,
|
|
1473
1475
|
o,
|
|
1474
1476
|
{ onMessage: $, onError: t.callbacks.onError },
|
|
1475
1477
|
t.externalId
|
|
1476
|
-
), k =
|
|
1478
|
+
), k = Se(
|
|
1477
1479
|
() => ln(
|
|
1478
1480
|
u,
|
|
1479
1481
|
{
|
|
1480
1482
|
...t,
|
|
1481
|
-
mode:
|
|
1483
|
+
mode: a,
|
|
1482
1484
|
callbacks: {
|
|
1483
1485
|
...t.callbacks,
|
|
1484
|
-
onVideoIdChange:
|
|
1486
|
+
onVideoIdChange: C,
|
|
1485
1487
|
onMessage: $,
|
|
1486
|
-
onInterruptDetected:
|
|
1488
|
+
onInterruptDetected: B
|
|
1487
1489
|
}
|
|
1488
1490
|
},
|
|
1489
|
-
|
|
1491
|
+
p,
|
|
1490
1492
|
d,
|
|
1491
1493
|
r.chat
|
|
1492
1494
|
),
|
|
@@ -1494,26 +1496,26 @@ async function gn(e, t) {
|
|
|
1494
1496
|
limit: 3,
|
|
1495
1497
|
timeout: dt,
|
|
1496
1498
|
timeoutErrorMessage: "Timeout initializing the stream",
|
|
1497
|
-
shouldRetryFn: (
|
|
1499
|
+
shouldRetryFn: (V) => (V == null ? void 0 : V.message) !== "Could not connect" && V.status !== 429 && (V == null ? void 0 : V.message) !== "InsufficientCreditsError",
|
|
1498
1500
|
delayMs: 1e3
|
|
1499
1501
|
}
|
|
1500
|
-
).catch((
|
|
1501
|
-
var m,
|
|
1502
|
-
throw
|
|
1503
|
-
}), [
|
|
1504
|
-
|
|
1505
|
-
chatId:
|
|
1506
|
-
streamId:
|
|
1502
|
+
).catch((V) => {
|
|
1503
|
+
var m, h;
|
|
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,
|
|
1507
1509
|
mode: r.chatMode
|
|
1508
|
-
}),
|
|
1510
|
+
}), te((E == null ? void 0 : E.chat_mode) ?? a);
|
|
1509
1511
|
}
|
|
1510
|
-
async function
|
|
1511
|
-
var f, y, k,
|
|
1512
|
-
(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);
|
|
1513
1515
|
}
|
|
1514
|
-
async function
|
|
1516
|
+
async function te(f) {
|
|
1515
1517
|
var y, k;
|
|
1516
|
-
f !== r.chatMode && (d.track("agent-mode-change", { mode: f }), r.chatMode = f, r.chatMode !== F.Functional && await
|
|
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));
|
|
1517
1519
|
}
|
|
1518
1520
|
return {
|
|
1519
1521
|
agent: u,
|
|
@@ -1530,35 +1532,35 @@ async function gn(e, t) {
|
|
|
1530
1532
|
return ((f = r.streamingManager) == null ? void 0 : f.triggersAvailable) ?? !1;
|
|
1531
1533
|
},
|
|
1532
1534
|
starterMessages: ((Z = u.knowledge) == null ? void 0 : Z.starter_message) || [],
|
|
1533
|
-
getSTTToken: () =>
|
|
1534
|
-
changeMode:
|
|
1535
|
+
getSTTToken: () => p.getSTTToken(u.id),
|
|
1536
|
+
changeMode: te,
|
|
1535
1537
|
enrichAnalytics: d.enrich,
|
|
1536
1538
|
async connect() {
|
|
1537
|
-
await
|
|
1539
|
+
await I(!0), d.track("agent-chat", {
|
|
1538
1540
|
event: "connect",
|
|
1539
1541
|
mode: r.chatMode
|
|
1540
1542
|
});
|
|
1541
1543
|
},
|
|
1542
1544
|
async reconnect() {
|
|
1543
1545
|
const f = r.streamingManager;
|
|
1544
|
-
if (
|
|
1546
|
+
if (_ && (f != null && f.reconnect)) {
|
|
1545
1547
|
try {
|
|
1546
1548
|
await f.reconnect(), d.track("agent-chat", {
|
|
1547
1549
|
event: "reconnect",
|
|
1548
1550
|
mode: r.chatMode
|
|
1549
1551
|
});
|
|
1550
1552
|
} catch {
|
|
1551
|
-
await
|
|
1553
|
+
await U(), await I(!1);
|
|
1552
1554
|
}
|
|
1553
1555
|
return;
|
|
1554
1556
|
}
|
|
1555
|
-
await
|
|
1557
|
+
await U(), await I(!1), d.track("agent-chat", {
|
|
1556
1558
|
event: "reconnect",
|
|
1557
1559
|
mode: r.chatMode
|
|
1558
1560
|
});
|
|
1559
1561
|
},
|
|
1560
1562
|
async disconnect() {
|
|
1561
|
-
await
|
|
1563
|
+
await U(), d.track("agent-chat", {
|
|
1562
1564
|
event: "disconnect",
|
|
1563
1565
|
mode: r.chatMode
|
|
1564
1566
|
});
|
|
@@ -1576,80 +1578,80 @@ async function gn(e, t) {
|
|
|
1576
1578
|
return r.streamingManager.unpublishMicrophoneStream();
|
|
1577
1579
|
},
|
|
1578
1580
|
async chat(f) {
|
|
1579
|
-
var
|
|
1581
|
+
var P, E, J, O, H;
|
|
1580
1582
|
const y = () => {
|
|
1581
|
-
if (
|
|
1582
|
-
throw new
|
|
1583
|
+
if (Ve(a))
|
|
1584
|
+
throw new ue(`${a} is enabled, chat is disabled`);
|
|
1583
1585
|
if (f.length >= 800)
|
|
1584
|
-
throw new
|
|
1586
|
+
throw new ue("Message cannot be more than 800 characters");
|
|
1585
1587
|
if (f.length === 0)
|
|
1586
|
-
throw new
|
|
1588
|
+
throw new ue("Message cannot be empty");
|
|
1587
1589
|
if (r.chatMode === F.Maintenance)
|
|
1588
|
-
throw new
|
|
1590
|
+
throw new ue("Chat is in maintenance mode");
|
|
1589
1591
|
if (![F.TextOnly, F.Playground].includes(r.chatMode)) {
|
|
1590
1592
|
if (!r.streamingManager)
|
|
1591
|
-
throw new
|
|
1593
|
+
throw new ue("Streaming manager is not initialized");
|
|
1592
1594
|
if (!r.chat)
|
|
1593
|
-
throw new
|
|
1595
|
+
throw new ue("Chat is not initialized");
|
|
1594
1596
|
}
|
|
1595
1597
|
}, k = async () => {
|
|
1596
|
-
var
|
|
1598
|
+
var L, N;
|
|
1597
1599
|
if (!r.chat) {
|
|
1598
|
-
const
|
|
1600
|
+
const q = await He(
|
|
1599
1601
|
u,
|
|
1600
|
-
|
|
1602
|
+
p,
|
|
1601
1603
|
d,
|
|
1602
1604
|
r.chatMode,
|
|
1603
1605
|
t.persistentChat
|
|
1604
1606
|
);
|
|
1605
|
-
if (!
|
|
1607
|
+
if (!q.chat)
|
|
1606
1608
|
throw new Ye(r.chatMode, !!t.persistentChat);
|
|
1607
|
-
r.chat =
|
|
1609
|
+
r.chat = q.chat, (N = (L = t.callbacks).onNewChat) == null || N.call(L, r.chat.id);
|
|
1608
1610
|
}
|
|
1609
1611
|
return r.chat.id;
|
|
1610
|
-
},
|
|
1611
|
-
const
|
|
1612
|
-
return
|
|
1613
|
-
var m,
|
|
1614
|
-
return await ((
|
|
1612
|
+
}, T = async (L, N) => {
|
|
1613
|
+
const q = r.chatMode === F.Playground;
|
|
1614
|
+
return Se(_ && !q ? async () => {
|
|
1615
|
+
var m, h;
|
|
1616
|
+
return await ((h = (m = r.streamingManager) == null ? void 0 : m.sendTextMessage) == null ? void 0 : h.call(m, f)), Promise.resolve({});
|
|
1615
1617
|
} : async () => {
|
|
1616
|
-
var m,
|
|
1617
|
-
return
|
|
1618
|
+
var m, h;
|
|
1619
|
+
return p.chat(
|
|
1618
1620
|
u.id,
|
|
1619
1621
|
N,
|
|
1620
1622
|
{
|
|
1621
1623
|
chatMode: r.chatMode,
|
|
1622
1624
|
streamId: (m = r.streamingManager) == null ? void 0 : m.streamId,
|
|
1623
|
-
sessionId: (
|
|
1624
|
-
messages:
|
|
1625
|
+
sessionId: (h = r.streamingManager) == null ? void 0 : h.sessionId,
|
|
1626
|
+
messages: L.map(({ matches: x, ...K }) => K)
|
|
1625
1627
|
},
|
|
1626
1628
|
{
|
|
1627
|
-
...
|
|
1629
|
+
...Oe(r.chatMode),
|
|
1628
1630
|
skipErrorHandler: !0
|
|
1629
1631
|
}
|
|
1630
1632
|
);
|
|
1631
1633
|
}, {
|
|
1632
1634
|
limit: 2,
|
|
1633
1635
|
shouldRetryFn: (m) => {
|
|
1634
|
-
var K, he, pe,
|
|
1635
|
-
const
|
|
1636
|
-
return !((he = m == null ? void 0 : m.message) == null ? void 0 : he.includes("Stream Error")) && !
|
|
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;
|
|
1637
1639
|
},
|
|
1638
1640
|
onRetry: async () => {
|
|
1639
|
-
await
|
|
1641
|
+
await U(), await I(!1);
|
|
1640
1642
|
}
|
|
1641
1643
|
});
|
|
1642
1644
|
};
|
|
1643
1645
|
try {
|
|
1644
|
-
|
|
1645
|
-
id:
|
|
1646
|
+
A(), y(), r.messages.push({
|
|
1647
|
+
id: le(),
|
|
1646
1648
|
role: "user",
|
|
1647
1649
|
content: f,
|
|
1648
|
-
created_at: new Date(
|
|
1649
|
-
}), (
|
|
1650
|
-
const
|
|
1650
|
+
created_at: new Date(ee.update()).toISOString()
|
|
1651
|
+
}), (E = (P = t.callbacks).onNewMessage) == null || E.call(P, [...r.messages], "user");
|
|
1652
|
+
const L = await k(), N = await T([...r.messages], L);
|
|
1651
1653
|
return r.messages.push({
|
|
1652
|
-
id:
|
|
1654
|
+
id: le(),
|
|
1653
1655
|
role: "assistant",
|
|
1654
1656
|
content: N.result || "",
|
|
1655
1657
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -1658,50 +1660,50 @@ async function gn(e, t) {
|
|
|
1658
1660
|
}), d.track("agent-message-send", {
|
|
1659
1661
|
event: "success",
|
|
1660
1662
|
messages: r.messages.length + 1
|
|
1661
|
-
}), N.result && ((
|
|
1662
|
-
latency:
|
|
1663
|
+
}), N.result && ((O = (J = t.callbacks).onNewMessage) == null || O.call(J, [...r.messages], "answer"), d.track("agent-message-received", {
|
|
1664
|
+
latency: ee.get(!0),
|
|
1663
1665
|
messages: r.messages.length
|
|
1664
1666
|
})), N;
|
|
1665
|
-
} catch (
|
|
1666
|
-
throw ((
|
|
1667
|
+
} catch (L) {
|
|
1668
|
+
throw ((H = r.messages[r.messages.length - 1]) == null ? void 0 : H.role) === "assistant" && r.messages.pop(), d.track("agent-message-send", {
|
|
1667
1669
|
event: "error",
|
|
1668
1670
|
messages: r.messages.length
|
|
1669
|
-
}),
|
|
1671
|
+
}), L;
|
|
1670
1672
|
}
|
|
1671
1673
|
},
|
|
1672
1674
|
rate(f, y, k) {
|
|
1673
|
-
var
|
|
1674
|
-
const
|
|
1675
|
+
var E, J, O, H;
|
|
1676
|
+
const T = r.messages.find((L) => L.id === f);
|
|
1675
1677
|
if (r.chat) {
|
|
1676
|
-
if (!
|
|
1678
|
+
if (!T)
|
|
1677
1679
|
throw new Error("Message not found");
|
|
1678
1680
|
} else throw new Error("Chat is not initialized");
|
|
1679
|
-
const
|
|
1681
|
+
const P = ((E = T.matches) == null ? void 0 : E.map((L) => [L.document_id, L.id])) ?? [];
|
|
1680
1682
|
return d.track("agent-rate", {
|
|
1681
1683
|
event: k ? "update" : "create",
|
|
1682
1684
|
thumb: y === 1 ? "up" : "down",
|
|
1683
1685
|
knowledge_id: ((J = u.knowledge) == null ? void 0 : J.id) ?? "",
|
|
1684
|
-
matches:
|
|
1686
|
+
matches: P,
|
|
1685
1687
|
score: y
|
|
1686
|
-
}), k ?
|
|
1687
|
-
knowledge_id: ((
|
|
1688
|
+
}), k ? p.updateRating(u.id, r.chat.id, k, {
|
|
1689
|
+
knowledge_id: ((O = u.knowledge) == null ? void 0 : O.id) ?? "",
|
|
1688
1690
|
message_id: f,
|
|
1689
|
-
matches:
|
|
1691
|
+
matches: P,
|
|
1690
1692
|
score: y
|
|
1691
|
-
}) :
|
|
1692
|
-
knowledge_id: ((
|
|
1693
|
+
}) : p.createRating(u.id, r.chat.id, {
|
|
1694
|
+
knowledge_id: ((H = u.knowledge) == null ? void 0 : H.id) ?? "",
|
|
1693
1695
|
message_id: f,
|
|
1694
|
-
matches:
|
|
1696
|
+
matches: P,
|
|
1695
1697
|
score: y
|
|
1696
1698
|
});
|
|
1697
1699
|
},
|
|
1698
1700
|
deleteRate(f) {
|
|
1699
1701
|
if (!r.chat)
|
|
1700
1702
|
throw new Error("Chat is not initialized");
|
|
1701
|
-
return d.track("agent-rate-delete", { type: "text" }),
|
|
1703
|
+
return d.track("agent-rate-delete", { type: "text" }), p.deleteRating(u.id, r.chat.id, f);
|
|
1702
1704
|
},
|
|
1703
1705
|
async speak(f) {
|
|
1704
|
-
var
|
|
1706
|
+
var P, E, J;
|
|
1705
1707
|
function y() {
|
|
1706
1708
|
if (typeof f == "string") {
|
|
1707
1709
|
if (!u.presenter.voice)
|
|
@@ -1726,12 +1728,12 @@ async function gn(e, t) {
|
|
|
1726
1728
|
return f;
|
|
1727
1729
|
}
|
|
1728
1730
|
const k = y();
|
|
1729
|
-
if (d.track("agent-speak", k),
|
|
1730
|
-
id:
|
|
1731
|
+
if (d.track("agent-speak", k), ee.update(), r.messages && k.type === "text" && (r.messages.push({
|
|
1732
|
+
id: le(),
|
|
1731
1733
|
role: "assistant",
|
|
1732
1734
|
content: k.input,
|
|
1733
1735
|
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1734
|
-
}), (
|
|
1736
|
+
}), (E = (P = t.callbacks).onNewMessage) == null || E.call(P, [...r.messages], "answer")), mt(r.chatMode))
|
|
1735
1737
|
return {
|
|
1736
1738
|
duration: 0,
|
|
1737
1739
|
video_id: "",
|
|
@@ -1744,18 +1746,18 @@ async function gn(e, t) {
|
|
|
1744
1746
|
metadata: { chat_id: (J = r.chat) == null ? void 0 : J.id, agent_id: u.id }
|
|
1745
1747
|
});
|
|
1746
1748
|
},
|
|
1747
|
-
interrupt:
|
|
1749
|
+
interrupt: B
|
|
1748
1750
|
};
|
|
1749
1751
|
}
|
|
1750
1752
|
export {
|
|
1751
|
-
|
|
1753
|
+
W as AgentActivityState,
|
|
1752
1754
|
nt as AgentStatus,
|
|
1753
1755
|
Ye as ChatCreationFailed,
|
|
1754
1756
|
F as ChatMode,
|
|
1755
1757
|
Ge as ChatModeDowngraded,
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1758
|
+
X as ChatProgress,
|
|
1759
|
+
R as ConnectionState,
|
|
1760
|
+
ie as ConnectivityState,
|
|
1759
1761
|
ot as DocumentType,
|
|
1760
1762
|
at as KnowledgeType,
|
|
1761
1763
|
tt as PlanGroup,
|
|
@@ -1763,11 +1765,11 @@ export {
|
|
|
1763
1765
|
rt as RateState,
|
|
1764
1766
|
j as StreamEvents,
|
|
1765
1767
|
ae as StreamType,
|
|
1766
|
-
|
|
1768
|
+
S as StreamingState,
|
|
1767
1769
|
it as Subject,
|
|
1768
1770
|
ye as TransportProvider,
|
|
1769
1771
|
et as UserPlan,
|
|
1770
|
-
|
|
1772
|
+
ue as ValidationError,
|
|
1771
1773
|
Ke as VideoType,
|
|
1772
1774
|
ct as VoiceAccess,
|
|
1773
1775
|
Ze as WsError,
|