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