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