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