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