@d-id/client-sdk 1.1.63-staging.290 → 1.1.64-staging.299
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-BkSUCJW5.js → index-CnW1r_Zz.js} +510 -505
- package/dist/index.js +1 -1
- package/dist/index.umd.cjs +1 -1
- package/dist/{livekit-manager-DylcG4TH.js → livekit-manager-RbiJiCkR.js} +1 -1
- package/dist/src/services/streaming-manager/stats/report.test.d.ts +1 -0
- package/package.json +1 -1
|
@@ -2,12 +2,12 @@ var Ue = Object.defineProperty;
|
|
|
2
2
|
var We = (e, t, r) => t in e ? Ue(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
3
|
var Q = (e, t, r) => We(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
4
|
class ce extends Error {
|
|
5
|
-
constructor({ kind: r, description:
|
|
6
|
-
super(JSON.stringify({ kind: r, description:
|
|
5
|
+
constructor({ kind: r, description: a, error: c }) {
|
|
6
|
+
super(JSON.stringify({ kind: r, description: a }));
|
|
7
7
|
Q(this, "kind");
|
|
8
8
|
Q(this, "description");
|
|
9
9
|
Q(this, "error");
|
|
10
|
-
this.kind = r, this.description =
|
|
10
|
+
this.kind = r, this.description = a, this.error = c;
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
class Oe extends ce {
|
|
@@ -24,10 +24,10 @@ class He extends ce {
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
class G extends ce {
|
|
27
|
-
constructor(r,
|
|
27
|
+
constructor(r, a) {
|
|
28
28
|
super({ kind: "ValidationError", description: r });
|
|
29
29
|
Q(this, "key");
|
|
30
|
-
this.key =
|
|
30
|
+
this.key = a;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
class qe extends ce {
|
|
@@ -35,7 +35,7 @@ class qe extends ce {
|
|
|
35
35
|
super({ kind: "WSError", description: t });
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
var Xe = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(Xe || {}), Ye = /* @__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))(Ye || {}), Ge = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(Ge || {}), Qe = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(Qe || {}), x = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(x || {}), J = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(J || {}), Ze = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(Ze || {}), et = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(et || {}), tt = /* @__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))(tt || {}),
|
|
38
|
+
var Xe = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(Xe || {}), Ye = /* @__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))(Ye || {}), Ge = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(Ge || {}), Qe = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(Qe || {}), x = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(x || {}), J = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(J || {}), Ze = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(Ze || {}), et = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(et || {}), tt = /* @__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))(tt || {}), Pe = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(Pe || {});
|
|
39
39
|
const nr = (e) => {
|
|
40
40
|
switch (e) {
|
|
41
41
|
case "clip":
|
|
@@ -48,7 +48,7 @@ const nr = (e) => {
|
|
|
48
48
|
throw new Error(`Unknown video type: ${e}`);
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
|
-
var S = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(S || {}), ee = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(ee || {}), ne = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Loading = "LOADING", e.Talking = "TALKING", e.ToolActive = "TOOL_ACTIVE", e))(ne || {}),
|
|
51
|
+
var S = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(S || {}), ee = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(ee || {}), ne = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Loading = "LOADING", e.Talking = "TALKING", e.ToolActive = "TOOL_ACTIVE", e))(ne || {}), P = /* @__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.ToolCallStarted = "tool-call/started", e.ToolCallDone = "tool-call/done", e.ToolCallError = "tool-call/error", e))(P || {}), L = /* @__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))(L || {}), U = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(U || {}), he = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(he || {}), rt = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(rt || {}), nt = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(nt || {});
|
|
52
52
|
const at = 45 * 1e3, it = "X-Playground-Chat", de = "https://api.d-id.com", st = "wss://notifications.d-id.com", ot = "79f81a83a67430be2bc0fd61042b8faa", ar = (...e) => {
|
|
53
53
|
}, je = (e) => new Promise((t) => setTimeout(t, e)), te = (e = 16) => {
|
|
54
54
|
const t = new Uint8Array(e);
|
|
@@ -62,7 +62,7 @@ const at = 45 * 1e3, it = "X-Playground-Chat", de = "https://api.d-id.com", st =
|
|
|
62
62
|
case "talk":
|
|
63
63
|
return "v2";
|
|
64
64
|
}
|
|
65
|
-
}, dt = (e) => e.type === "talk" ? e.source_url : e.presenter_id, pe = (e) => e ===
|
|
65
|
+
}, dt = (e) => e.type === "talk" ? e.source_url : e.presenter_id, pe = (e) => e === Pe.Expressive, lt = (e) => [x.TextOnly, x.Playground, x.Maintenance].includes(e), $e = (e) => e && [x.DirectPlayback, x.Off].includes(e), Se = /\[!\[([^\[\]]*)\]\(([^)\s]+)\)\]\(([^)\s]+)\)/g, ke = /!\[([^\[\]]*)\]\(([^)\s]+)\)/g, Re = new RegExp("(?<!!)\\[([^\\[\\]]+)\\]\\(([^)\\s]+)\\)", "g"), De = /<a\s+href="([^"]*)"[^>]*?>([^<]*)<\/a>/gi;
|
|
66
66
|
function ut(e) {
|
|
67
67
|
if (e.length === 0)
|
|
68
68
|
return [];
|
|
@@ -75,40 +75,40 @@ function ut(e) {
|
|
|
75
75
|
part: { type: "video", src: r[3], alt: r[1], thumbnail: r[2] }
|
|
76
76
|
});
|
|
77
77
|
for (ke.lastIndex = 0; (r = ke.exec(e)) !== null; )
|
|
78
|
-
if (!t.some((
|
|
79
|
-
const
|
|
80
|
-
|
|
78
|
+
if (!t.some((o) => r.index >= o.index && r.index < o.index + o.length)) {
|
|
79
|
+
const o = r[2], n = { type: "image", src: o, alt: r[1] };
|
|
80
|
+
o.toLowerCase().endsWith(".gif") && (n.mimeType = "image/gif"), t.push({ index: r.index, length: r[0].length, part: n });
|
|
81
81
|
}
|
|
82
82
|
for (Re.lastIndex = 0; (r = Re.exec(e)) !== null; )
|
|
83
|
-
t.some((
|
|
83
|
+
t.some((o) => r.index >= o.index && r.index < o.index + o.length) || t.push({
|
|
84
84
|
index: r.index,
|
|
85
85
|
length: r[0].length,
|
|
86
86
|
part: { type: "link", href: r[2], label: r[1] }
|
|
87
87
|
});
|
|
88
88
|
for (De.lastIndex = 0; (r = De.exec(e)) !== null; )
|
|
89
|
-
t.some((
|
|
89
|
+
t.some((o) => r.index >= o.index && r.index < o.index + o.length) || t.push({
|
|
90
90
|
index: r.index,
|
|
91
91
|
length: r[0].length,
|
|
92
92
|
part: { type: "link", href: r[1], label: r[2] }
|
|
93
93
|
});
|
|
94
94
|
if (t.length === 0)
|
|
95
95
|
return [{ type: "text", text: e }];
|
|
96
|
-
t.sort((
|
|
97
|
-
const
|
|
98
|
-
let
|
|
99
|
-
for (const
|
|
100
|
-
|
|
101
|
-
return
|
|
96
|
+
t.sort((s, o) => s.index - o.index);
|
|
97
|
+
const a = [];
|
|
98
|
+
let c = 0;
|
|
99
|
+
for (const s of t)
|
|
100
|
+
s.index > c && a.push({ type: "text", text: e.slice(c, s.index) }), a.push(s.part), c = s.index + s.length;
|
|
101
|
+
return c < e.length && a.push({ type: "text", text: e.slice(c) }), a;
|
|
102
102
|
}
|
|
103
|
-
let
|
|
103
|
+
let Ie = "", le = [];
|
|
104
104
|
function re(e) {
|
|
105
|
-
return e ===
|
|
105
|
+
return e === Ie || (Ie = e, le = ut(e)), le;
|
|
106
106
|
}
|
|
107
107
|
function mt(e, t) {
|
|
108
108
|
let r;
|
|
109
109
|
return {
|
|
110
|
-
promise: new Promise((
|
|
111
|
-
r = setTimeout(() =>
|
|
110
|
+
promise: new Promise((c, s) => {
|
|
111
|
+
r = setTimeout(() => s(new Error(t)), e);
|
|
112
112
|
}),
|
|
113
113
|
clear: () => clearTimeout(r)
|
|
114
114
|
};
|
|
@@ -123,19 +123,19 @@ async function ue(e, t) {
|
|
|
123
123
|
onRetry: (t == null ? void 0 : t.onRetry) ?? (() => {
|
|
124
124
|
})
|
|
125
125
|
};
|
|
126
|
-
let
|
|
127
|
-
for (let
|
|
126
|
+
let a;
|
|
127
|
+
for (let c = 1; c <= r.limit; c++)
|
|
128
128
|
try {
|
|
129
129
|
if (!r.timeout)
|
|
130
130
|
return await e();
|
|
131
|
-
const { promise:
|
|
132
|
-
return await Promise.race([
|
|
133
|
-
} catch (
|
|
134
|
-
if (
|
|
135
|
-
throw
|
|
136
|
-
await je(r.delayMs), r.onRetry(
|
|
131
|
+
const { promise: s, clear: o } = mt(r.timeout, r.timeoutErrorMessage), n = e().finally(o);
|
|
132
|
+
return await Promise.race([n, s]);
|
|
133
|
+
} catch (s) {
|
|
134
|
+
if (a = s, !r.shouldRetryFn(s) || c >= r.limit)
|
|
135
|
+
throw s;
|
|
136
|
+
await je(r.delayMs), r.onRetry(s);
|
|
137
137
|
}
|
|
138
|
-
throw
|
|
138
|
+
throw a;
|
|
139
139
|
}
|
|
140
140
|
function me(e) {
|
|
141
141
|
if (e !== void 0)
|
|
@@ -162,14 +162,14 @@ const ft = (e) => ue(e, {
|
|
|
162
162
|
timeout: 0,
|
|
163
163
|
shouldRetryFn: (t) => t.status === 429
|
|
164
164
|
});
|
|
165
|
-
function Fe(e, t = de, r,
|
|
166
|
-
const
|
|
167
|
-
const { skipErrorHandler:
|
|
168
|
-
() => fetch(t + (
|
|
165
|
+
function Fe(e, t = de, r, a) {
|
|
166
|
+
const c = async (s, o) => {
|
|
167
|
+
const { skipErrorHandler: n, ...i } = o || {}, d = await ft(
|
|
168
|
+
() => fetch(t + (s != null && s.startsWith("/") ? s : `/${s}`), {
|
|
169
169
|
...i,
|
|
170
170
|
headers: {
|
|
171
171
|
...i.headers,
|
|
172
|
-
Authorization: ze(e,
|
|
172
|
+
Authorization: ze(e, a),
|
|
173
173
|
"Content-Type": "application/json"
|
|
174
174
|
}
|
|
175
175
|
})
|
|
@@ -177,98 +177,98 @@ function Fe(e, t = de, r, n) {
|
|
|
177
177
|
if (!d.ok) {
|
|
178
178
|
let m = await d.text().catch(() => `Failed to fetch with status ${d.status}`);
|
|
179
179
|
const l = new Error(m);
|
|
180
|
-
throw r && !
|
|
180
|
+
throw r && !n && r(l, { url: s, options: i, headers: d.headers }), l;
|
|
181
181
|
}
|
|
182
182
|
return d.json();
|
|
183
183
|
};
|
|
184
184
|
return {
|
|
185
|
-
get(
|
|
186
|
-
return
|
|
185
|
+
get(s, o) {
|
|
186
|
+
return c(s, { ...o, method: "GET" });
|
|
187
187
|
},
|
|
188
|
-
post(
|
|
189
|
-
return
|
|
188
|
+
post(s, o, n) {
|
|
189
|
+
return c(s, { ...n, body: JSON.stringify(o), method: "POST" });
|
|
190
190
|
},
|
|
191
|
-
delete(
|
|
192
|
-
return
|
|
191
|
+
delete(s, o, n) {
|
|
192
|
+
return c(s, { ...n, body: JSON.stringify(o), method: "DELETE" });
|
|
193
193
|
},
|
|
194
|
-
patch(
|
|
195
|
-
return
|
|
194
|
+
patch(s, o, n) {
|
|
195
|
+
return c(s, { ...n, body: JSON.stringify(o), method: "PATCH" });
|
|
196
196
|
}
|
|
197
197
|
};
|
|
198
198
|
}
|
|
199
|
-
function gt(e, t = de, r,
|
|
200
|
-
const
|
|
199
|
+
function gt(e, t = de, r, a) {
|
|
200
|
+
const c = Fe(e, `${t}/agents`, r, a);
|
|
201
201
|
return {
|
|
202
|
-
create(
|
|
203
|
-
return
|
|
202
|
+
create(s, o) {
|
|
203
|
+
return c.post("/", s, o);
|
|
204
204
|
},
|
|
205
|
-
getAgents(
|
|
206
|
-
return
|
|
205
|
+
getAgents(s, o) {
|
|
206
|
+
return c.get(`/${s ? `?tag=${s}` : ""}`, o).then((n) => n ?? []);
|
|
207
207
|
},
|
|
208
|
-
getById(
|
|
209
|
-
return
|
|
208
|
+
getById(s, o) {
|
|
209
|
+
return c.get(`/${s}`, o);
|
|
210
210
|
},
|
|
211
|
-
delete(
|
|
212
|
-
return
|
|
211
|
+
delete(s, o) {
|
|
212
|
+
return c.delete(`/${s}`, void 0, o);
|
|
213
213
|
},
|
|
214
|
-
update(
|
|
215
|
-
return
|
|
214
|
+
update(s, o, n) {
|
|
215
|
+
return c.patch(`/${s}`, o, n);
|
|
216
216
|
},
|
|
217
|
-
newChat(
|
|
218
|
-
return
|
|
217
|
+
newChat(s, o, n) {
|
|
218
|
+
return c.post(`/${s}/chat`, o, n);
|
|
219
219
|
},
|
|
220
|
-
chat(
|
|
221
|
-
return
|
|
220
|
+
chat(s, o, n, i) {
|
|
221
|
+
return c.post(`/${s}/chat/${o}`, n, i);
|
|
222
222
|
},
|
|
223
|
-
createRating(
|
|
224
|
-
return
|
|
223
|
+
createRating(s, o, n, i) {
|
|
224
|
+
return c.post(`/${s}/chat/${o}/ratings`, n, i);
|
|
225
225
|
},
|
|
226
|
-
updateRating(
|
|
227
|
-
return
|
|
226
|
+
updateRating(s, o, n, i, d) {
|
|
227
|
+
return c.patch(`/${s}/chat/${o}/ratings/${n}`, i, d);
|
|
228
228
|
},
|
|
229
|
-
deleteRating(
|
|
230
|
-
return
|
|
229
|
+
deleteRating(s, o, n, i) {
|
|
230
|
+
return c.delete(`/${s}/chat/${o}/ratings/${n}`, i);
|
|
231
231
|
},
|
|
232
|
-
getSTTToken(
|
|
233
|
-
return
|
|
232
|
+
getSTTToken(s, o) {
|
|
233
|
+
return c.get(`/${s}/stt-token`, o);
|
|
234
234
|
}
|
|
235
235
|
};
|
|
236
236
|
}
|
|
237
237
|
function ht(e) {
|
|
238
|
-
var
|
|
238
|
+
var c, s, o, n;
|
|
239
239
|
const t = () => /Mobi|Android/i.test(navigator.userAgent) ? "Mobile" : "Desktop", r = () => {
|
|
240
240
|
const i = navigator.platform;
|
|
241
241
|
return i.toLowerCase().includes("win") ? "Windows" : i.toLowerCase().includes("mac") ? "Mac OS X" : i.toLowerCase().includes("linux") ? "Linux" : "Unknown";
|
|
242
|
-
},
|
|
242
|
+
}, a = e.presenter;
|
|
243
243
|
return {
|
|
244
244
|
$os: `${r()}`,
|
|
245
245
|
isMobile: `${t() == "Mobile"}`,
|
|
246
246
|
browser: navigator.userAgent,
|
|
247
247
|
origin: window.location.origin,
|
|
248
|
-
agentType: Be(
|
|
248
|
+
agentType: Be(a),
|
|
249
249
|
agentVoice: {
|
|
250
|
-
voiceId: (
|
|
251
|
-
provider: (
|
|
250
|
+
voiceId: (s = (c = e.presenter) == null ? void 0 : c.voice) == null ? void 0 : s.voice_id,
|
|
251
|
+
provider: (n = (o = e.presenter) == null ? void 0 : o.voice) == null ? void 0 : n.type
|
|
252
252
|
}
|
|
253
253
|
};
|
|
254
254
|
}
|
|
255
255
|
function pt(e) {
|
|
256
|
-
var r,
|
|
256
|
+
var r, a, c, s, o, n;
|
|
257
257
|
const t = (r = e.llm) == null ? void 0 : r.prompt_customization;
|
|
258
258
|
return {
|
|
259
259
|
agentType: Be(e.presenter),
|
|
260
260
|
presenterType: ct(e.presenter),
|
|
261
261
|
presenter: dt(e.presenter),
|
|
262
262
|
owner_id: e.owner_id ?? "",
|
|
263
|
-
promptVersion: (
|
|
263
|
+
promptVersion: (a = e.llm) == null ? void 0 : a.prompt_version,
|
|
264
264
|
behavior: {
|
|
265
265
|
role: t == null ? void 0 : t.role,
|
|
266
266
|
personality: t == null ? void 0 : t.personality,
|
|
267
|
-
instructions: (
|
|
267
|
+
instructions: (c = e.llm) == null ? void 0 : c.instructions
|
|
268
268
|
},
|
|
269
|
-
temperature: (
|
|
269
|
+
temperature: (s = e.llm) == null ? void 0 : s.temperature,
|
|
270
270
|
knowledgeSource: t == null ? void 0 : t.knowledge_source,
|
|
271
|
-
starterQuestionsCount: (
|
|
271
|
+
starterQuestionsCount: (n = (o = e.knowledge) == null ? void 0 : o.starter_message) == null ? void 0 : n.length,
|
|
272
272
|
topicsToAvoid: t == null ? void 0 : t.topics_to_avoid,
|
|
273
273
|
maxResponseLength: t == null ? void 0 : t.max_response_length,
|
|
274
274
|
agentId: e.id,
|
|
@@ -277,14 +277,14 @@ function pt(e) {
|
|
|
277
277
|
...e.access === "public" ? { from: "agent-template" } : {}
|
|
278
278
|
};
|
|
279
279
|
}
|
|
280
|
-
const wt = (e) => e.reduce((t, r) => t + r, 0),
|
|
281
|
-
function
|
|
280
|
+
const wt = (e) => e.reduce((t, r) => t + r, 0), Me = (e) => wt(e) / e.length;
|
|
281
|
+
function vt(e, t, r) {
|
|
282
282
|
var i, d, m;
|
|
283
|
-
const { event:
|
|
283
|
+
const { event: a, ...c } = e, { template: s } = (t == null ? void 0 : t.llm) || {}, { language: o } = ((i = t == null ? void 0 : t.presenter) == null ? void 0 : i.voice) || {};
|
|
284
284
|
return {
|
|
285
|
-
...
|
|
286
|
-
llm: { ...
|
|
287
|
-
script: { ...
|
|
285
|
+
...c,
|
|
286
|
+
llm: { ...c.llm, template: s },
|
|
287
|
+
script: { ...c.script, provider: { ...(d = c == null ? void 0 : c.script) == null ? void 0 : d.provider, language: o } },
|
|
288
288
|
stitch: (t == null ? void 0 : t.presenter.type) === "talk" ? (m = t == null ? void 0 : t.presenter) == null ? void 0 : m.stitch : void 0,
|
|
289
289
|
...r
|
|
290
290
|
};
|
|
@@ -292,7 +292,7 @@ function yt(e, t, r) {
|
|
|
292
292
|
function Ee(e) {
|
|
293
293
|
"requestIdleCallback" in window ? requestIdleCallback(e, { timeout: 2e3 }) : setTimeout(e, 0);
|
|
294
294
|
}
|
|
295
|
-
const
|
|
295
|
+
const yt = "https://api-js.mixpanel.com/track/?verbose=1&ip=1";
|
|
296
296
|
function Ct(e) {
|
|
297
297
|
const t = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk", r = {};
|
|
298
298
|
return {
|
|
@@ -305,13 +305,13 @@ function Ct(e) {
|
|
|
305
305
|
},
|
|
306
306
|
isEnabled: e.isEnabled ?? !0,
|
|
307
307
|
getRandom: te,
|
|
308
|
-
enrich(
|
|
309
|
-
this.additionalProperties = { ...this.additionalProperties, ...
|
|
308
|
+
enrich(a) {
|
|
309
|
+
this.additionalProperties = { ...this.additionalProperties, ...a };
|
|
310
310
|
},
|
|
311
|
-
async track(
|
|
311
|
+
async track(a, c, s) {
|
|
312
312
|
if (!this.isEnabled)
|
|
313
313
|
return Promise.resolve();
|
|
314
|
-
const { audioPath:
|
|
314
|
+
const { audioPath: o, ...n } = c || {}, i = s || Date.now(), d = {
|
|
315
315
|
method: "POST",
|
|
316
316
|
headers: {
|
|
317
317
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
@@ -319,10 +319,10 @@ function Ct(e) {
|
|
|
319
319
|
body: new URLSearchParams({
|
|
320
320
|
data: JSON.stringify([
|
|
321
321
|
{
|
|
322
|
-
event:
|
|
322
|
+
event: a,
|
|
323
323
|
properties: {
|
|
324
324
|
...this.additionalProperties,
|
|
325
|
-
...
|
|
325
|
+
...n,
|
|
326
326
|
agentId: this.agentId,
|
|
327
327
|
source: t,
|
|
328
328
|
token: this.token,
|
|
@@ -337,19 +337,19 @@ function Ct(e) {
|
|
|
337
337
|
])
|
|
338
338
|
})
|
|
339
339
|
};
|
|
340
|
-
return fetch(
|
|
340
|
+
return fetch(yt, d).catch((m) => console.error("Analytics tracking error:", m)), Promise.resolve();
|
|
341
341
|
},
|
|
342
|
-
linkTrack(
|
|
343
|
-
r[
|
|
344
|
-
const
|
|
345
|
-
if (
|
|
346
|
-
(d) =>
|
|
342
|
+
linkTrack(a, c, s, o) {
|
|
343
|
+
r[a] || (r[a] = { events: {}, resolvedDependencies: [] }), o.includes(s) || o.push(s);
|
|
344
|
+
const n = r[a];
|
|
345
|
+
if (n.events[s] = { props: c }, n.resolvedDependencies.push(s), o.every(
|
|
346
|
+
(d) => n.resolvedDependencies.includes(d)
|
|
347
347
|
)) {
|
|
348
|
-
const d =
|
|
349
|
-
this.track(
|
|
350
|
-
(m) => !
|
|
351
|
-
),
|
|
352
|
-
delete
|
|
348
|
+
const d = o.reduce((m, l) => n.events[l] ? { ...m, ...n.events[l].props } : m, {});
|
|
349
|
+
this.track(a, d), n.resolvedDependencies = n.resolvedDependencies.filter(
|
|
350
|
+
(m) => !o.includes(m)
|
|
351
|
+
), o.forEach((m) => {
|
|
352
|
+
delete n.events[m];
|
|
353
353
|
});
|
|
354
354
|
}
|
|
355
355
|
}
|
|
@@ -367,15 +367,15 @@ const H = we(), fe = we(), Te = we();
|
|
|
367
367
|
function Ne(e) {
|
|
368
368
|
return e === x.Playground ? { headers: { [it]: "true" } } : {};
|
|
369
369
|
}
|
|
370
|
-
async function Ke(e, t, r,
|
|
370
|
+
async function Ke(e, t, r, a, c = !1, s) {
|
|
371
371
|
try {
|
|
372
|
-
return !
|
|
372
|
+
return !s && !$e(a) && (s = await t.newChat(e.id, { persist: c }, Ne(a)), r.track("agent-chat", {
|
|
373
373
|
event: "created",
|
|
374
|
-
chatId:
|
|
375
|
-
mode:
|
|
376
|
-
})), { chat:
|
|
377
|
-
} catch (
|
|
378
|
-
throw St(
|
|
374
|
+
chatId: s.id,
|
|
375
|
+
mode: a
|
|
376
|
+
})), { chat: s, chatMode: (s == null ? void 0 : s.chat_mode) ?? a };
|
|
377
|
+
} catch (o) {
|
|
378
|
+
throw St(o) === "InsufficientCreditsError" ? new Error("InsufficientCreditsError") : new Error("Cannot create new chat");
|
|
379
379
|
}
|
|
380
380
|
}
|
|
381
381
|
const St = (e) => {
|
|
@@ -391,8 +391,8 @@ function kt(e) {
|
|
|
391
391
|
}
|
|
392
392
|
function Rt(e) {
|
|
393
393
|
return new Promise((t, r) => {
|
|
394
|
-
const { callbacks:
|
|
395
|
-
l.onmessage =
|
|
394
|
+
const { callbacks: a, host: c, auth: s, externalId: o } = e, { onMessage: n = null, onOpen: i = null, onClose: d = null, onError: m = null } = a || {}, l = new WebSocket(`${c}?authorization=${encodeURIComponent(ze(s, o))}`);
|
|
395
|
+
l.onmessage = n, l.onclose = d, l.onerror = (w) => {
|
|
396
396
|
console.error(w), m == null || m("Websocket failed to connect", w), r(w);
|
|
397
397
|
}, l.onopen = (w) => {
|
|
398
398
|
i == null || i(w), t(l);
|
|
@@ -402,39 +402,39 @@ function Rt(e) {
|
|
|
402
402
|
async function Dt(e) {
|
|
403
403
|
const { retries: t = 1 } = e;
|
|
404
404
|
let r = null;
|
|
405
|
-
for (let
|
|
405
|
+
for (let a = 0; (r == null ? void 0 : r.readyState) !== WebSocket.OPEN; a++)
|
|
406
406
|
try {
|
|
407
407
|
r = await Rt(e);
|
|
408
|
-
} catch (
|
|
409
|
-
if (
|
|
410
|
-
throw
|
|
411
|
-
await je(
|
|
408
|
+
} catch (c) {
|
|
409
|
+
if (a === t)
|
|
410
|
+
throw c;
|
|
411
|
+
await je(a * 500);
|
|
412
412
|
}
|
|
413
413
|
return r;
|
|
414
414
|
}
|
|
415
|
-
async function
|
|
416
|
-
const
|
|
415
|
+
async function It(e, t, r, a) {
|
|
416
|
+
const c = r != null && r.onMessage ? [r.onMessage] : [], s = await Dt({
|
|
417
417
|
auth: e,
|
|
418
418
|
host: t,
|
|
419
|
-
externalId:
|
|
419
|
+
externalId: a,
|
|
420
420
|
callbacks: {
|
|
421
|
-
onError: (
|
|
422
|
-
var
|
|
423
|
-
return (
|
|
421
|
+
onError: (o) => {
|
|
422
|
+
var n;
|
|
423
|
+
return (n = r.onError) == null ? void 0 : n.call(r, new qe(o));
|
|
424
424
|
},
|
|
425
|
-
onMessage(
|
|
426
|
-
const
|
|
427
|
-
|
|
425
|
+
onMessage(o) {
|
|
426
|
+
const n = JSON.parse(o.data);
|
|
427
|
+
c.forEach((i) => i(n.event, n));
|
|
428
428
|
}
|
|
429
429
|
}
|
|
430
430
|
});
|
|
431
431
|
return {
|
|
432
|
-
socket:
|
|
433
|
-
disconnect: () =>
|
|
434
|
-
subscribeToEvents: (
|
|
432
|
+
socket: s,
|
|
433
|
+
disconnect: () => s.close(),
|
|
434
|
+
subscribeToEvents: (o) => c.push(o)
|
|
435
435
|
};
|
|
436
436
|
}
|
|
437
|
-
function
|
|
437
|
+
function Mt(e) {
|
|
438
438
|
if (e.answer !== void 0)
|
|
439
439
|
return e.answer;
|
|
440
440
|
let t = 0, r = "";
|
|
@@ -445,9 +445,9 @@ function It(e) {
|
|
|
445
445
|
function Et(e, t, r) {
|
|
446
446
|
if (!e.content)
|
|
447
447
|
return;
|
|
448
|
-
const
|
|
449
|
-
(
|
|
450
|
-
const
|
|
448
|
+
const a = t.messages[t.messages.length - 1];
|
|
449
|
+
(a == null ? void 0 : a.role) === "assistant" && !a.interrupted && (a.interrupted = !0);
|
|
450
|
+
const c = {
|
|
451
451
|
id: e.id || `user-${Date.now()}`,
|
|
452
452
|
role: e.role,
|
|
453
453
|
content: e.content,
|
|
@@ -455,115 +455,115 @@ function Et(e, t, r) {
|
|
|
455
455
|
created_at: e.created_at || (/* @__PURE__ */ new Date()).toISOString(),
|
|
456
456
|
transcribed: !0
|
|
457
457
|
};
|
|
458
|
-
t.messages.push(
|
|
458
|
+
t.messages.push(c), r == null || r([...t.messages], "user");
|
|
459
459
|
}
|
|
460
|
-
function Tt(e, t, r,
|
|
460
|
+
function Tt(e, t, r, a, c, s) {
|
|
461
461
|
if (e === J.Transcribe && t.content) {
|
|
462
|
-
Et(t,
|
|
462
|
+
Et(t, a, c);
|
|
463
463
|
return;
|
|
464
464
|
}
|
|
465
465
|
if (!(e === J.Partial || e === J.Answer))
|
|
466
466
|
return;
|
|
467
|
-
const
|
|
467
|
+
const o = a.messages[a.messages.length - 1], n = t.id && (o == null ? void 0 : o.role) === "assistant" && o.id !== t.id;
|
|
468
468
|
let i;
|
|
469
|
-
if ((
|
|
470
|
-
i =
|
|
471
|
-
else if (!
|
|
472
|
-
|
|
469
|
+
if ((o == null ? void 0 : o.role) === "assistant" && !n)
|
|
470
|
+
i = o;
|
|
471
|
+
else if (!o || o.transcribed && o.role === "user" || n)
|
|
472
|
+
n && s(), i = {
|
|
473
473
|
id: t.id || `assistant-${Date.now()}`,
|
|
474
474
|
role: t.role || "assistant",
|
|
475
475
|
content: t.content || "",
|
|
476
476
|
parts: [],
|
|
477
477
|
created_at: t.created_at || (/* @__PURE__ */ new Date()).toISOString()
|
|
478
|
-
},
|
|
478
|
+
}, a.messages.push(i);
|
|
479
479
|
else
|
|
480
480
|
return;
|
|
481
481
|
const { content: d, sequence: m } = t;
|
|
482
482
|
e === J.Partial ? r[m] = d : r.answer = d;
|
|
483
|
-
const l =
|
|
484
|
-
(i.content !== l || e === J.Answer) && (i.content = l, i.parts = re(l),
|
|
483
|
+
const l = Mt(r);
|
|
484
|
+
(i.content !== l || e === J.Answer) && (i.content = l, i.parts = re(l), c == null || c([...a.messages], e));
|
|
485
485
|
}
|
|
486
|
-
function _t(e, t, r,
|
|
487
|
-
let
|
|
488
|
-
const
|
|
489
|
-
let
|
|
486
|
+
function _t(e, t, r, a, c) {
|
|
487
|
+
let s = {};
|
|
488
|
+
const o = () => s = {};
|
|
489
|
+
let n = "answer";
|
|
490
490
|
const i = (d, m) => {
|
|
491
491
|
var l, w;
|
|
492
|
-
m === "user" &&
|
|
492
|
+
m === "user" && o(), n = m, (w = (l = r.callbacks).onNewMessage) == null || w.call(l, d, m);
|
|
493
493
|
};
|
|
494
494
|
return {
|
|
495
|
-
clearQueue:
|
|
495
|
+
clearQueue: o,
|
|
496
496
|
onMessage: (d, m) => {
|
|
497
497
|
var l, w;
|
|
498
498
|
if ("content" in m) {
|
|
499
|
-
const
|
|
500
|
-
Tt(
|
|
499
|
+
const v = d === P.ChatAnswer ? J.Answer : d === P.ChatAudioTranscribed ? J.Transcribe : d;
|
|
500
|
+
Tt(v, m, s, t, i, o), v === J.Answer && e.track("agent-message-received", {
|
|
501
501
|
content: m.content,
|
|
502
502
|
messages: t.messages.length,
|
|
503
503
|
mode: t.chatMode
|
|
504
504
|
});
|
|
505
505
|
} else {
|
|
506
|
-
const
|
|
507
|
-
if (d = d, d ===
|
|
506
|
+
const v = P, k = [v.StreamVideoDone, v.StreamVideoError, v.StreamVideoRejected], B = [v.StreamFailed, v.StreamVideoError, v.StreamVideoRejected], M = vt(m, a, { mode: t.chatMode });
|
|
507
|
+
if (d = d, d === v.StreamVideoCreated && (e.linkTrack("agent-video", M, v.StreamVideoCreated, ["start"]), m.sentiment)) {
|
|
508
508
|
const D = t.messages[t.messages.length - 1];
|
|
509
509
|
if ((D == null ? void 0 : D.role) === "assistant") {
|
|
510
510
|
const $ = { ...D, sentiment: m.sentiment };
|
|
511
|
-
t.messages[t.messages.length - 1] = $, i == null || i([...t.messages],
|
|
511
|
+
t.messages[t.messages.length - 1] = $, i == null || i([...t.messages], n);
|
|
512
512
|
}
|
|
513
513
|
}
|
|
514
514
|
if (k.includes(d)) {
|
|
515
515
|
const D = d.split("/")[1];
|
|
516
|
-
B.includes(d) ? e.track("agent-video", { ...
|
|
516
|
+
B.includes(d) ? e.track("agent-video", { ...M, event: D }) : e.linkTrack("agent-video", { ...M, event: D }, d, ["done"]);
|
|
517
517
|
}
|
|
518
|
-
B.includes(d) && ((w = (l = r.callbacks).onError) == null || w.call(l, new Error(`Stream failed with event ${d}`), { data: m })), m.event ===
|
|
518
|
+
B.includes(d) && ((w = (l = r.callbacks).onError) == null || w.call(l, new Error(`Stream failed with event ${d}`), { data: m })), m.event === v.StreamDone && c();
|
|
519
519
|
}
|
|
520
520
|
}
|
|
521
521
|
};
|
|
522
522
|
}
|
|
523
|
-
function bt(e, t, r,
|
|
524
|
-
const
|
|
523
|
+
function bt(e, t, r, a) {
|
|
524
|
+
const c = Fe(e, `${t}/agents/${r}`, a);
|
|
525
525
|
return {
|
|
526
|
-
createStream(
|
|
527
|
-
return
|
|
526
|
+
createStream(s, o) {
|
|
527
|
+
return c.post("/streams", s, { signal: o });
|
|
528
528
|
},
|
|
529
|
-
startConnection(
|
|
530
|
-
return
|
|
531
|
-
`/streams/${
|
|
529
|
+
startConnection(s, o, n, i) {
|
|
530
|
+
return c.post(
|
|
531
|
+
`/streams/${s}/sdp`,
|
|
532
532
|
{
|
|
533
|
-
session_id:
|
|
534
|
-
answer:
|
|
533
|
+
session_id: n,
|
|
534
|
+
answer: o
|
|
535
535
|
},
|
|
536
536
|
{ signal: i }
|
|
537
537
|
);
|
|
538
538
|
},
|
|
539
|
-
addIceCandidate(
|
|
540
|
-
return
|
|
541
|
-
`/streams/${
|
|
539
|
+
addIceCandidate(s, o, n, i) {
|
|
540
|
+
return c.post(
|
|
541
|
+
`/streams/${s}/ice`,
|
|
542
542
|
{
|
|
543
|
-
session_id:
|
|
544
|
-
...
|
|
543
|
+
session_id: n,
|
|
544
|
+
...o
|
|
545
545
|
},
|
|
546
546
|
{ signal: i }
|
|
547
547
|
);
|
|
548
548
|
},
|
|
549
|
-
sendStreamRequest(
|
|
550
|
-
return
|
|
551
|
-
session_id:
|
|
552
|
-
...
|
|
549
|
+
sendStreamRequest(s, o, n) {
|
|
550
|
+
return c.post(`/streams/${s}`, {
|
|
551
|
+
session_id: o,
|
|
552
|
+
...n
|
|
553
553
|
});
|
|
554
554
|
},
|
|
555
|
-
close(
|
|
556
|
-
return
|
|
555
|
+
close(s, o) {
|
|
556
|
+
return c.delete(`/streams/${s}`, { session_id: o });
|
|
557
557
|
}
|
|
558
558
|
};
|
|
559
559
|
}
|
|
560
|
-
const At = (e, t) => (r,
|
|
560
|
+
const At = (e, t) => (r, a) => e && console.log(`[${t}] ${r}`, a ?? "");
|
|
561
561
|
function xt(e, t, r) {
|
|
562
|
-
const
|
|
562
|
+
const a = (t.timestamp - e.timestamp) / 1e3;
|
|
563
563
|
return {
|
|
564
|
-
duration:
|
|
564
|
+
duration: a,
|
|
565
565
|
bytesReceived: t.bytesReceived - e.bytesReceived,
|
|
566
|
-
bitrate: Math.round((t.bytesReceived - e.bytesReceived) * 8 /
|
|
566
|
+
bitrate: Math.round((t.bytesReceived - e.bytesReceived) * 8 / a),
|
|
567
567
|
packetsReceived: t.packetsReceived - e.packetsReceived,
|
|
568
568
|
packetsLost: t.packetsLost - e.packetsLost,
|
|
569
569
|
framesDropped: t.framesDropped - e.framesDropped,
|
|
@@ -571,56 +571,61 @@ function xt(e, t, r) {
|
|
|
571
571
|
jitter: t.jitter,
|
|
572
572
|
avgJitterDelayInInterval: (t.jitterBufferDelay - e.jitterBufferDelay) / (t.jitterBufferEmittedCount - e.jitterBufferEmittedCount),
|
|
573
573
|
jitterBufferEmittedCount: t.jitterBufferEmittedCount - e.jitterBufferEmittedCount,
|
|
574
|
-
jitterBufferDelay: (t.jitterBufferDelay - e.jitterBufferDelay) /
|
|
574
|
+
jitterBufferDelay: (t.jitterBufferDelay - e.jitterBufferDelay) / a,
|
|
575
575
|
framesPerSecond: t.framesPerSecond,
|
|
576
576
|
freezeCount: t.freezeCount - e.freezeCount,
|
|
577
577
|
freezeDuration: t.freezeDuration - e.freezeDuration,
|
|
578
578
|
lowFpsCount: r
|
|
579
579
|
};
|
|
580
580
|
}
|
|
581
|
-
function
|
|
581
|
+
function Lt(e) {
|
|
582
582
|
return e.filter(
|
|
583
583
|
(t) => t.freezeCount > 0 || t.framesPerSecond < 21 || t.framesDropped > 0 || t.packetsLost > 0
|
|
584
584
|
).map((t) => {
|
|
585
|
-
const { timestamp: r, ...
|
|
586
|
-
return t.freezeCount > 0 &&
|
|
587
|
-
...
|
|
588
|
-
causes:
|
|
585
|
+
const { timestamp: r, ...a } = t, c = [];
|
|
586
|
+
return t.freezeCount > 0 && c.push("freeze"), t.framesPerSecond < 21 && c.push("low fps"), t.framesDropped > 0 && c.push("frames dropped"), t.packetsLost > 0 && c.push("packet loss"), {
|
|
587
|
+
...a,
|
|
588
|
+
causes: c
|
|
589
589
|
};
|
|
590
590
|
});
|
|
591
591
|
}
|
|
592
|
-
function
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
592
|
+
function Pt(e) {
|
|
593
|
+
var o;
|
|
594
|
+
let t = "", r = 0, a = null;
|
|
595
|
+
const c = /* @__PURE__ */ new Map();
|
|
596
|
+
for (const n of e.values())
|
|
597
|
+
if (n)
|
|
598
|
+
if (n.type === "codec" && ((o = n.mimeType) != null && o.startsWith("video")))
|
|
599
|
+
c.set(n.id, n.mimeType.split("/")[1]);
|
|
600
|
+
else if (n.type === "candidate-pair") {
|
|
601
|
+
const i = n, d = i.currentRoundTripTime ?? 0;
|
|
602
|
+
d > 0 && (i.nominated === !0 || r === 0) && (r = d);
|
|
603
|
+
} else n.type === "inbound-rtp" && n.kind === "video" && (a = n);
|
|
604
|
+
if (!a)
|
|
605
|
+
return {};
|
|
606
|
+
const s = a;
|
|
607
|
+
return s.codecId && c.has(s.codecId) ? t = c.get(s.codecId) : c.size > 0 && (t = c.values().next().value ?? ""), {
|
|
608
|
+
codec: t,
|
|
609
|
+
rtt: r,
|
|
610
|
+
timestamp: s.timestamp,
|
|
611
|
+
bytesReceived: s.bytesReceived,
|
|
612
|
+
packetsReceived: s.packetsReceived,
|
|
613
|
+
packetsLost: s.packetsLost,
|
|
614
|
+
framesDropped: s.framesDropped,
|
|
615
|
+
framesDecoded: s.framesDecoded,
|
|
616
|
+
jitter: s.jitter,
|
|
617
|
+
jitterBufferDelay: s.jitterBufferDelay,
|
|
618
|
+
jitterBufferEmittedCount: s.jitterBufferEmittedCount,
|
|
619
|
+
avgJitterDelayInInterval: s.jitterBufferDelay / s.jitterBufferEmittedCount,
|
|
620
|
+
frameWidth: s.frameWidth,
|
|
621
|
+
frameHeight: s.frameHeight,
|
|
622
|
+
framesPerSecond: s.framesPerSecond,
|
|
623
|
+
freezeCount: s.freezeCount,
|
|
624
|
+
freezeDuration: s.totalFreezesDuration
|
|
625
|
+
};
|
|
621
626
|
}
|
|
622
627
|
function _e(e, t, r) {
|
|
623
|
-
const
|
|
628
|
+
const a = e.map((i, d) => d === 0 ? r ? {
|
|
624
629
|
timestamp: i.timestamp,
|
|
625
630
|
duration: 0,
|
|
626
631
|
rtt: i.rtt,
|
|
@@ -671,17 +676,17 @@ function _e(e, t, r) {
|
|
|
671
676
|
framesPerSecond: i.framesPerSecond,
|
|
672
677
|
freezeCount: i.freezeCount - e[d - 1].freezeCount,
|
|
673
678
|
freezeDuration: i.freezeDuration - e[d - 1].freezeDuration
|
|
674
|
-
}),
|
|
679
|
+
}), c = Lt(a), s = c.reduce((i, d) => i + (d.causes.includes("low fps") ? 1 : 0), 0), o = a.filter((i) => !!i.avgJitterDelayInInterval).map((i) => i.avgJitterDelayInInterval), n = a.filter((i) => !!i.rtt).map((i) => i.rtt);
|
|
675
680
|
return {
|
|
676
681
|
webRTCStats: {
|
|
677
|
-
anomalies:
|
|
678
|
-
minRtt: Math.min(...
|
|
679
|
-
avgRtt:
|
|
680
|
-
maxRtt: Math.max(...
|
|
681
|
-
aggregateReport: xt(e[0], e[e.length - 1],
|
|
682
|
-
minJitterDelayInInterval: Math.min(...
|
|
683
|
-
maxJitterDelayInInterval: Math.max(...
|
|
684
|
-
avgJitterDelayInInterval:
|
|
682
|
+
anomalies: c,
|
|
683
|
+
minRtt: Math.min(...n),
|
|
684
|
+
avgRtt: Me(n),
|
|
685
|
+
maxRtt: Math.max(...n),
|
|
686
|
+
aggregateReport: xt(e[0], e[e.length - 1], s),
|
|
687
|
+
minJitterDelayInInterval: Math.min(...o),
|
|
688
|
+
maxJitterDelayInInterval: Math.max(...o),
|
|
689
|
+
avgJitterDelayInInterval: Me(o)
|
|
685
690
|
},
|
|
686
691
|
codec: e[0].codec,
|
|
687
692
|
resolution: `${e[0].frameWidth}x${e[0].frameHeight}`
|
|
@@ -695,162 +700,162 @@ function Ve(e, t) {
|
|
|
695
700
|
}
|
|
696
701
|
const Z = 10;
|
|
697
702
|
function ir(e, t) {
|
|
698
|
-
let r = !1,
|
|
703
|
+
let r = !1, a = !1, c = null, s = 0, o = 0, n = {};
|
|
699
704
|
async function i() {
|
|
700
705
|
if (r) {
|
|
701
706
|
try {
|
|
702
707
|
const d = await e();
|
|
703
708
|
if (!d) {
|
|
704
|
-
|
|
709
|
+
c = setTimeout(i, Z);
|
|
705
710
|
return;
|
|
706
711
|
}
|
|
707
712
|
const m = Ve(d, "audio");
|
|
708
713
|
if (!m) {
|
|
709
|
-
|
|
714
|
+
c = setTimeout(i, Z);
|
|
710
715
|
return;
|
|
711
716
|
}
|
|
712
717
|
const l = m.totalAudioEnergy ?? 0, w = m.totalSamplesReceived ?? 0;
|
|
713
|
-
if (!
|
|
714
|
-
|
|
718
|
+
if (!a) {
|
|
719
|
+
s = l, o = w, a = !0, c = setTimeout(i, Z);
|
|
715
720
|
return;
|
|
716
721
|
}
|
|
717
|
-
const
|
|
718
|
-
if (
|
|
719
|
-
r = !1, t(
|
|
722
|
+
const v = l - s, k = w - o;
|
|
723
|
+
if (s = l, o = w, k > 0 && v > 0) {
|
|
724
|
+
r = !1, t(n);
|
|
720
725
|
return;
|
|
721
726
|
}
|
|
722
727
|
} catch {
|
|
723
728
|
}
|
|
724
|
-
r && (
|
|
729
|
+
r && (c = setTimeout(i, Z));
|
|
725
730
|
}
|
|
726
731
|
}
|
|
727
732
|
return {
|
|
728
733
|
arm(d = {}) {
|
|
729
|
-
|
|
734
|
+
n = d, r = !0, a = !1, performance.now(), c !== null && clearTimeout(c), c = setTimeout(i, Z);
|
|
730
735
|
},
|
|
731
736
|
destroy() {
|
|
732
|
-
r = !1,
|
|
737
|
+
r = !1, c !== null && (clearTimeout(c), c = null);
|
|
733
738
|
}
|
|
734
739
|
};
|
|
735
740
|
}
|
|
736
741
|
const oe = 100, jt = Math.max(Math.ceil(400 / oe), 1), Bt = 0.25, $t = 0.28;
|
|
737
742
|
function zt() {
|
|
738
|
-
let e = 0, t, r,
|
|
739
|
-
return (
|
|
740
|
-
const
|
|
741
|
-
if (!
|
|
742
|
-
return { isReceiving: !1, avgJitterDelayInInterval:
|
|
743
|
-
const
|
|
744
|
-
if (r &&
|
|
745
|
-
const m =
|
|
746
|
-
|
|
743
|
+
let e = 0, t, r, a = 0;
|
|
744
|
+
return (c) => {
|
|
745
|
+
const s = Ve(c, "video");
|
|
746
|
+
if (!s)
|
|
747
|
+
return { isReceiving: !1, avgJitterDelayInInterval: a };
|
|
748
|
+
const o = s.jitterBufferDelay, n = s.jitterBufferEmittedCount;
|
|
749
|
+
if (r && n > r) {
|
|
750
|
+
const m = o - t, l = n - r;
|
|
751
|
+
a = m / l;
|
|
747
752
|
}
|
|
748
|
-
t =
|
|
749
|
-
const i =
|
|
750
|
-
return e = i, { isReceiving: d, avgJitterDelayInInterval:
|
|
753
|
+
t = o, r = n;
|
|
754
|
+
const i = s.framesDecoded, d = i - e > 0;
|
|
755
|
+
return e = i, { isReceiving: d, avgJitterDelayInInterval: a, freezeCount: s.freezeCount };
|
|
751
756
|
};
|
|
752
757
|
}
|
|
753
|
-
function Ft(e, t, r,
|
|
754
|
-
let
|
|
758
|
+
function Ft(e, t, r, a, c) {
|
|
759
|
+
let s = null, o = [], n, i = 0, d = !1, m = ee.Unknown, l = ee.Unknown, w = 0, v = 0;
|
|
755
760
|
const k = zt();
|
|
756
761
|
async function B() {
|
|
757
|
-
const
|
|
758
|
-
if (!
|
|
762
|
+
const M = await e();
|
|
763
|
+
if (!M)
|
|
759
764
|
return;
|
|
760
|
-
const { isReceiving: D, avgJitterDelayInInterval: $, freezeCount: _ } = k(
|
|
765
|
+
const { isReceiving: D, avgJitterDelayInInterval: $, freezeCount: _ } = k(M), q = Pt(M);
|
|
761
766
|
if (D)
|
|
762
|
-
i = 0, w = _ -
|
|
767
|
+
i = 0, w = _ - v, l = $ < Bt ? ee.Strong : $ > $t && w > 1 ? ee.Weak : m, l !== m && (c == null || c(l), m = l, v += w, w = 0), d || (a == null || a(S.Start), n = o[o.length - 1], o = [], d = !0), o.push(q);
|
|
763
768
|
else if (d && (i++, i >= jt)) {
|
|
764
|
-
const W = _e(
|
|
765
|
-
|
|
769
|
+
const W = _e(o, oe, n);
|
|
770
|
+
a == null || a(S.Stop, W), t() || r(), v = _, d = !1;
|
|
766
771
|
}
|
|
767
772
|
}
|
|
768
773
|
return {
|
|
769
774
|
start: () => {
|
|
770
|
-
|
|
775
|
+
s || (s = setInterval(B, oe));
|
|
771
776
|
},
|
|
772
777
|
stop: () => {
|
|
773
|
-
|
|
778
|
+
s && (clearInterval(s), s = null);
|
|
774
779
|
},
|
|
775
|
-
getReport: () => _e(
|
|
780
|
+
getReport: () => _e(o, oe, n)
|
|
776
781
|
};
|
|
777
782
|
}
|
|
778
783
|
const Nt = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
|
|
779
784
|
function be(e) {
|
|
780
785
|
switch (e) {
|
|
781
786
|
case "connected":
|
|
782
|
-
return
|
|
787
|
+
return L.Connected;
|
|
783
788
|
case "checking":
|
|
784
|
-
return
|
|
789
|
+
return L.Connecting;
|
|
785
790
|
case "failed":
|
|
786
|
-
return
|
|
791
|
+
return L.Fail;
|
|
787
792
|
case "new":
|
|
788
|
-
return
|
|
793
|
+
return L.New;
|
|
789
794
|
case "closed":
|
|
790
|
-
return
|
|
795
|
+
return L.Closed;
|
|
791
796
|
case "disconnected":
|
|
792
|
-
return
|
|
797
|
+
return L.Disconnected;
|
|
793
798
|
case "completed":
|
|
794
|
-
return
|
|
799
|
+
return L.Completed;
|
|
795
800
|
default:
|
|
796
|
-
return
|
|
801
|
+
return L.New;
|
|
797
802
|
}
|
|
798
803
|
}
|
|
799
804
|
const Kt = (e) => (t) => {
|
|
800
|
-
const [r,
|
|
805
|
+
const [r, a = ""] = t.split(/:(.+)/);
|
|
801
806
|
try {
|
|
802
|
-
const
|
|
803
|
-
return e("parsed data channel message", { subject: r, data:
|
|
804
|
-
} catch (
|
|
805
|
-
return e("Failed to parse data channel message, returning data as string", { subject: r, rawData:
|
|
807
|
+
const c = JSON.parse(a);
|
|
808
|
+
return e("parsed data channel message", { subject: r, data: c }), { subject: r, data: c };
|
|
809
|
+
} catch (c) {
|
|
810
|
+
return e("Failed to parse data channel message, returning data as string", { subject: r, rawData: a, error: c }), { subject: r, data: a };
|
|
806
811
|
}
|
|
807
812
|
};
|
|
808
813
|
function Vt({
|
|
809
814
|
statsSignal: e,
|
|
810
815
|
dataChannelSignal: t,
|
|
811
816
|
onVideoStateChange: r,
|
|
812
|
-
report:
|
|
813
|
-
log:
|
|
817
|
+
report: a,
|
|
818
|
+
log: c
|
|
814
819
|
}) {
|
|
815
|
-
e === S.Start && t === S.Start ? (
|
|
820
|
+
e === S.Start && t === S.Start ? (c("CALLBACK: onVideoStateChange(Start)"), r == null || r(S.Start)) : e === S.Stop && t === S.Stop && (c("CALLBACK: onVideoStateChange(Stop)"), r == null || r(S.Stop, a));
|
|
816
821
|
}
|
|
817
822
|
function Jt({
|
|
818
823
|
statsSignal: e,
|
|
819
824
|
dataChannelSignal: t,
|
|
820
825
|
onVideoStateChange: r,
|
|
821
|
-
onAgentActivityStateChange:
|
|
822
|
-
report:
|
|
823
|
-
log:
|
|
826
|
+
onAgentActivityStateChange: a,
|
|
827
|
+
report: c,
|
|
828
|
+
log: s
|
|
824
829
|
}) {
|
|
825
|
-
e === S.Start ? (
|
|
830
|
+
e === S.Start ? (s("CALLBACK: onVideoStateChange(Start)"), r == null || r(S.Start)) : e === S.Stop && (s("CALLBACK: onVideoStateChange(Stop)"), r == null || r(S.Stop, c)), t === S.Start ? a == null || a(ne.Talking) : t === S.Stop && (a == null || a(ne.Idle));
|
|
826
831
|
}
|
|
827
832
|
function Ae({
|
|
828
833
|
statsSignal: e,
|
|
829
834
|
dataChannelSignal: t,
|
|
830
835
|
onVideoStateChange: r,
|
|
831
|
-
onAgentActivityStateChange:
|
|
832
|
-
streamType:
|
|
833
|
-
report:
|
|
834
|
-
log:
|
|
836
|
+
onAgentActivityStateChange: a,
|
|
837
|
+
streamType: c,
|
|
838
|
+
report: s,
|
|
839
|
+
log: o
|
|
835
840
|
}) {
|
|
836
|
-
|
|
841
|
+
c === U.Legacy ? Vt({ statsSignal: e, dataChannelSignal: t, onVideoStateChange: r, report: s, log: o }) : c === U.Fluent && Jt({
|
|
837
842
|
statsSignal: e,
|
|
838
843
|
dataChannelSignal: t,
|
|
839
844
|
onVideoStateChange: r,
|
|
840
|
-
onAgentActivityStateChange:
|
|
841
|
-
report:
|
|
842
|
-
log:
|
|
845
|
+
onAgentActivityStateChange: a,
|
|
846
|
+
report: s,
|
|
847
|
+
log: o
|
|
843
848
|
});
|
|
844
849
|
}
|
|
845
|
-
async function Ut(e, t, { debug: r = !1, callbacks:
|
|
850
|
+
async function Ut(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de, analytics: o }, n) {
|
|
846
851
|
var E;
|
|
847
852
|
const i = At(r, "WebRTCStreamingManager"), d = Kt(i);
|
|
848
|
-
let m = !1, l = !1, w = S.Stop,
|
|
849
|
-
const { startConnection: k, sendStreamRequest: B, close:
|
|
850
|
-
o,
|
|
853
|
+
let m = !1, l = !1, w = S.Stop, v = S.Stop;
|
|
854
|
+
const { startConnection: k, sendStreamRequest: B, close: M, createStream: D, addIceCandidate: $ } = bt(
|
|
851
855
|
c,
|
|
856
|
+
s,
|
|
852
857
|
e,
|
|
853
|
-
|
|
858
|
+
a.onError
|
|
854
859
|
), {
|
|
855
860
|
id: _,
|
|
856
861
|
offer: q,
|
|
@@ -858,37 +863,37 @@ async function Ut(e, t, { debug: r = !1, callbacks: n, auth: o, baseURL: c = de,
|
|
|
858
863
|
session_id: N,
|
|
859
864
|
fluent: X,
|
|
860
865
|
interrupt_enabled: O
|
|
861
|
-
} = await D(t,
|
|
862
|
-
(E =
|
|
863
|
-
const
|
|
866
|
+
} = await D(t, n);
|
|
867
|
+
(E = a.onStreamCreated) == null || E.call(a, { stream_id: _, session_id: N, agent_id: e });
|
|
868
|
+
const I = new Nt({ iceServers: W }), Y = I.createDataChannel("JanusDataChannel");
|
|
864
869
|
if (!N)
|
|
865
870
|
throw new Error("Could not create session_id");
|
|
866
871
|
const K = X ? U.Fluent : U.Legacy;
|
|
867
|
-
|
|
872
|
+
o.enrich({
|
|
868
873
|
"stream-type": K
|
|
869
874
|
});
|
|
870
875
|
const ae = t.stream_warmup && !X, ie = () => m, u = () => {
|
|
871
876
|
var f;
|
|
872
|
-
m = !0, l && (i("CALLBACK: onConnectionStateChange(Connected)"), (f =
|
|
877
|
+
m = !0, l && (i("CALLBACK: onConnectionStateChange(Connected)"), (f = a.onConnectionStateChange) == null || f.call(a, L.Connected));
|
|
873
878
|
}, g = Ft(
|
|
874
|
-
() =>
|
|
879
|
+
() => I.getStats(),
|
|
875
880
|
ie,
|
|
876
881
|
u,
|
|
877
882
|
(f, h) => Ae({
|
|
878
|
-
statsSignal:
|
|
883
|
+
statsSignal: v = f,
|
|
879
884
|
dataChannelSignal: K === U.Legacy ? w : void 0,
|
|
880
|
-
onVideoStateChange:
|
|
881
|
-
onAgentActivityStateChange:
|
|
885
|
+
onVideoStateChange: a.onVideoStateChange,
|
|
886
|
+
onAgentActivityStateChange: a.onAgentActivityStateChange,
|
|
882
887
|
report: h,
|
|
883
888
|
streamType: K,
|
|
884
889
|
log: i
|
|
885
890
|
}),
|
|
886
891
|
(f) => {
|
|
887
892
|
var h;
|
|
888
|
-
return (h =
|
|
893
|
+
return (h = a.onConnectivityStateChange) == null ? void 0 : h.call(a, f);
|
|
889
894
|
}
|
|
890
895
|
);
|
|
891
|
-
g.start(),
|
|
896
|
+
g.start(), I.onicecandidate = (f) => {
|
|
892
897
|
var h;
|
|
893
898
|
i("peerConnection.onicecandidate", f);
|
|
894
899
|
try {
|
|
@@ -900,29 +905,29 @@ async function Ut(e, t, { debug: r = !1, callbacks: n, auth: o, baseURL: c = de,
|
|
|
900
905
|
sdpMLineIndex: f.candidate.sdpMLineIndex
|
|
901
906
|
},
|
|
902
907
|
N,
|
|
903
|
-
|
|
904
|
-
) : $(_, { candidate: null }, N,
|
|
908
|
+
n
|
|
909
|
+
) : $(_, { candidate: null }, N, n);
|
|
905
910
|
} catch (b) {
|
|
906
|
-
(h =
|
|
911
|
+
(h = a.onError) == null || h.call(a, b, { streamId: _ });
|
|
907
912
|
}
|
|
908
913
|
}, Y.onopen = () => {
|
|
909
914
|
l = !0, (!ae || m) && u();
|
|
910
915
|
};
|
|
911
916
|
let p = null;
|
|
912
|
-
const
|
|
917
|
+
const y = (f) => {
|
|
913
918
|
var h;
|
|
914
|
-
p = f, (h =
|
|
919
|
+
p = f, (h = a.onVideoIdChange) == null || h.call(a, f);
|
|
915
920
|
};
|
|
916
921
|
function C(f, h) {
|
|
917
|
-
if (f ===
|
|
922
|
+
if (f === P.StreamStarted && typeof h == "object" && "metadata" in h) {
|
|
918
923
|
const b = h.metadata;
|
|
919
|
-
|
|
924
|
+
y(b.videoId);
|
|
920
925
|
}
|
|
921
|
-
f ===
|
|
922
|
-
statsSignal: K === U.Legacy ?
|
|
926
|
+
f === P.StreamDone && y(null), w = f === P.StreamStarted ? S.Start : S.Stop, Ae({
|
|
927
|
+
statsSignal: K === U.Legacy ? v : void 0,
|
|
923
928
|
dataChannelSignal: w,
|
|
924
|
-
onVideoStateChange:
|
|
925
|
-
onAgentActivityStateChange:
|
|
929
|
+
onVideoStateChange: a.onVideoStateChange,
|
|
930
|
+
onAgentActivityStateChange: a.onAgentActivityStateChange,
|
|
926
931
|
streamType: K,
|
|
927
932
|
log: i
|
|
928
933
|
});
|
|
@@ -930,32 +935,32 @@ async function Ut(e, t, { debug: r = !1, callbacks: n, auth: o, baseURL: c = de,
|
|
|
930
935
|
function R(f, h) {
|
|
931
936
|
var T;
|
|
932
937
|
const b = typeof h == "string" ? h : h == null ? void 0 : h.metadata;
|
|
933
|
-
b &&
|
|
938
|
+
b && o.enrich({ streamMetadata: b }), (T = a.onStreamReady) == null || T.call(a);
|
|
934
939
|
}
|
|
935
940
|
const j = {
|
|
936
|
-
[
|
|
937
|
-
[
|
|
938
|
-
[
|
|
941
|
+
[P.StreamStarted]: C,
|
|
942
|
+
[P.StreamDone]: C,
|
|
943
|
+
[P.StreamReady]: R
|
|
939
944
|
};
|
|
940
945
|
Y.onmessage = (f) => {
|
|
941
946
|
var T;
|
|
942
947
|
const { subject: h, data: b } = d(f.data);
|
|
943
948
|
(T = j[h]) == null || T.call(j, h, b);
|
|
944
|
-
},
|
|
949
|
+
}, I.oniceconnectionstatechange = () => {
|
|
945
950
|
var h;
|
|
946
|
-
i("peerConnection.oniceconnectionstatechange => " +
|
|
947
|
-
const f = be(
|
|
948
|
-
f !==
|
|
949
|
-
},
|
|
951
|
+
i("peerConnection.oniceconnectionstatechange => " + I.iceConnectionState);
|
|
952
|
+
const f = be(I.iceConnectionState);
|
|
953
|
+
f !== L.Connected && ((h = a.onConnectionStateChange) == null || h.call(a, f));
|
|
954
|
+
}, I.ontrack = (f) => {
|
|
950
955
|
var h;
|
|
951
|
-
i("peerConnection.ontrack", f), i("CALLBACK: onSrcObjectReady"), (h =
|
|
952
|
-
}, await
|
|
953
|
-
const z = await
|
|
954
|
-
i("create answer OK"), await
|
|
956
|
+
i("peerConnection.ontrack", f), i("CALLBACK: onSrcObjectReady"), (h = a.onSrcObjectReady) == null || h.call(a, f.streams[0]);
|
|
957
|
+
}, await I.setRemoteDescription(q), i("set remote description OK");
|
|
958
|
+
const z = await I.createAnswer();
|
|
959
|
+
i("create answer OK"), await I.setLocalDescription(z), i("set local description OK"), await k(_, z, N, n), i("start connection OK");
|
|
955
960
|
function F(f) {
|
|
956
961
|
var h, b;
|
|
957
962
|
if (!m || Y.readyState !== "open") {
|
|
958
|
-
i("Data channel is not ready for sending messages"), (h =
|
|
963
|
+
i("Data channel is not ready for sending messages"), (h = a.onError) == null || h.call(a, new Error("Data channel is not ready for sending messages"), {
|
|
959
964
|
streamId: _
|
|
960
965
|
});
|
|
961
966
|
return;
|
|
@@ -963,7 +968,7 @@ async function Ut(e, t, { debug: r = !1, callbacks: n, auth: o, baseURL: c = de,
|
|
|
963
968
|
try {
|
|
964
969
|
Y.send(f);
|
|
965
970
|
} catch (T) {
|
|
966
|
-
i("Error sending data channel message", T), (b =
|
|
971
|
+
i("Error sending data channel message", T), (b = a.onError) == null || b.call(a, T, { streamId: _ });
|
|
967
972
|
}
|
|
968
973
|
}
|
|
969
974
|
return {
|
|
@@ -980,21 +985,21 @@ async function Ut(e, t, { debug: r = !1, callbacks: n, auth: o, baseURL: c = de,
|
|
|
980
985
|
async disconnect() {
|
|
981
986
|
var f;
|
|
982
987
|
if (_) {
|
|
983
|
-
const h = be(
|
|
984
|
-
if (
|
|
985
|
-
if (h ===
|
|
988
|
+
const h = be(I.iceConnectionState);
|
|
989
|
+
if (I) {
|
|
990
|
+
if (h === L.New) {
|
|
986
991
|
g.stop();
|
|
987
992
|
return;
|
|
988
993
|
}
|
|
989
|
-
|
|
994
|
+
I.close(), I.oniceconnectionstatechange = null, I.onnegotiationneeded = null, I.onicecandidate = null, I.ontrack = null;
|
|
990
995
|
}
|
|
991
996
|
try {
|
|
992
|
-
h ===
|
|
997
|
+
h === L.Connected && await M(_, N).catch((b) => {
|
|
993
998
|
});
|
|
994
999
|
} catch (b) {
|
|
995
1000
|
i("Error on close stream connection", b);
|
|
996
1001
|
}
|
|
997
|
-
(f =
|
|
1002
|
+
(f = a.onAgentActivityStateChange) == null || f.call(a, ne.Idle), g.stop();
|
|
998
1003
|
}
|
|
999
1004
|
},
|
|
1000
1005
|
sendDataChannelMessage: F,
|
|
@@ -1017,7 +1022,7 @@ async function Ut(e, t, { debug: r = !1, callbacks: n, auth: o, baseURL: c = de,
|
|
|
1017
1022
|
if (!p)
|
|
1018
1023
|
throw new Error("No active video to interrupt");
|
|
1019
1024
|
const h = {
|
|
1020
|
-
type:
|
|
1025
|
+
type: P.StreamInterrupt,
|
|
1021
1026
|
videoId: p,
|
|
1022
1027
|
timestamp: Date.now()
|
|
1023
1028
|
};
|
|
@@ -1026,21 +1031,21 @@ async function Ut(e, t, { debug: r = !1, callbacks: n, auth: o, baseURL: c = de,
|
|
|
1026
1031
|
};
|
|
1027
1032
|
}
|
|
1028
1033
|
var ge = /* @__PURE__ */ ((e) => (e.V1 = "v1", e.V2 = "v2", e))(ge || {});
|
|
1029
|
-
async function Wt(e, t, r,
|
|
1030
|
-
const
|
|
1034
|
+
async function Wt(e, t, r, a) {
|
|
1035
|
+
const c = e.id;
|
|
1031
1036
|
switch (t.version) {
|
|
1032
1037
|
case "v1": {
|
|
1033
|
-
const { version:
|
|
1034
|
-
return Ut(
|
|
1038
|
+
const { version: s, ...o } = t;
|
|
1039
|
+
return Ut(c, o, r, a);
|
|
1035
1040
|
}
|
|
1036
1041
|
case "v2": {
|
|
1037
|
-
const { version:
|
|
1038
|
-
switch (
|
|
1042
|
+
const { version: s, ...o } = t;
|
|
1043
|
+
switch (o.transport.provider) {
|
|
1039
1044
|
case he.Livekit:
|
|
1040
|
-
const { createLiveKitStreamingManager:
|
|
1041
|
-
return
|
|
1045
|
+
const { createLiveKitStreamingManager: n } = await import("./livekit-manager-RbiJiCkR.js");
|
|
1046
|
+
return n(c, o, r);
|
|
1042
1047
|
default:
|
|
1043
|
-
throw new Error(`Unsupported transport provider: ${
|
|
1048
|
+
throw new Error(`Unsupported transport provider: ${o.transport.provider}`);
|
|
1044
1049
|
}
|
|
1045
1050
|
}
|
|
1046
1051
|
default:
|
|
@@ -1056,9 +1061,9 @@ function Ht() {
|
|
|
1056
1061
|
};
|
|
1057
1062
|
}
|
|
1058
1063
|
function qt(e) {
|
|
1059
|
-
var
|
|
1060
|
-
const { streamOptions: t } = e ?? {}, r = ((
|
|
1061
|
-
plan: (
|
|
1064
|
+
var c, s;
|
|
1065
|
+
const { streamOptions: t } = e ?? {}, r = ((c = e == null ? void 0 : e.mixpanelAdditionalProperties) == null ? void 0 : c.plan) !== void 0 ? {
|
|
1066
|
+
plan: (s = e.mixpanelAdditionalProperties) == null ? void 0 : s.plan
|
|
1062
1067
|
} : void 0;
|
|
1063
1068
|
return { ...{
|
|
1064
1069
|
output_resolution: t == null ? void 0 : t.outputResolution,
|
|
@@ -1074,80 +1079,80 @@ function Xt(e, t) {
|
|
|
1074
1079
|
function Yt(e, t, r) {
|
|
1075
1080
|
r.track("agent-connection-state-change", { state: e, ...t && { reason: t } });
|
|
1076
1081
|
}
|
|
1077
|
-
function Gt(e, t, r,
|
|
1078
|
-
|
|
1082
|
+
function Gt(e, t, r, a, c) {
|
|
1083
|
+
c === U.Fluent ? Qt(e, t, r, a, c) : Zt(e, t, r, a, c);
|
|
1079
1084
|
}
|
|
1080
|
-
function Qt(e, t, r,
|
|
1081
|
-
e === S.Start ?
|
|
1085
|
+
function Qt(e, t, r, a, c) {
|
|
1086
|
+
e === S.Start ? a.track("stream-session", { event: "start", "stream-type": c }) : e === S.Stop && a.track("stream-session", {
|
|
1082
1087
|
event: "stop",
|
|
1083
1088
|
is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
|
|
1084
1089
|
background: t.presenter.type === "clip" && t.presenter.background,
|
|
1085
|
-
"stream-type":
|
|
1090
|
+
"stream-type": c,
|
|
1086
1091
|
...r
|
|
1087
1092
|
});
|
|
1088
1093
|
}
|
|
1089
|
-
function xe(e, t, r,
|
|
1090
|
-
e === S.Start ? r.linkTrack("agent-video", { event: "start", ...
|
|
1091
|
-
|
|
1094
|
+
function xe(e, t, r, a, c) {
|
|
1095
|
+
e === S.Start ? r.linkTrack("agent-video", { event: "start", ...c, "stream-type": a }, "start", [
|
|
1096
|
+
P.StreamVideoCreated
|
|
1092
1097
|
]) : e === S.Stop && r.linkTrack(
|
|
1093
1098
|
"agent-video",
|
|
1094
1099
|
{
|
|
1095
1100
|
event: "stop",
|
|
1096
1101
|
is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
|
|
1097
1102
|
background: t.presenter.type === "clip" && t.presenter.background,
|
|
1098
|
-
"stream-type":
|
|
1103
|
+
"stream-type": a
|
|
1099
1104
|
},
|
|
1100
1105
|
"done",
|
|
1101
|
-
[
|
|
1106
|
+
[P.StreamVideoDone]
|
|
1102
1107
|
);
|
|
1103
1108
|
}
|
|
1104
|
-
function Zt(e, t, r,
|
|
1105
|
-
e === S.Start ?
|
|
1109
|
+
function Zt(e, t, r, a, c) {
|
|
1110
|
+
e === S.Start ? a.linkTrack(
|
|
1106
1111
|
"agent-video",
|
|
1107
|
-
{ event: "start", latency: H.get(!0), "stream-type":
|
|
1112
|
+
{ event: "start", latency: H.get(!0), "stream-type": c },
|
|
1108
1113
|
"start",
|
|
1109
|
-
[
|
|
1110
|
-
) : e === S.Stop &&
|
|
1114
|
+
[P.StreamVideoCreated]
|
|
1115
|
+
) : e === S.Stop && a.linkTrack(
|
|
1111
1116
|
"agent-video",
|
|
1112
1117
|
{
|
|
1113
1118
|
event: "stop",
|
|
1114
1119
|
is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
|
|
1115
1120
|
background: t.presenter.type === "clip" && t.presenter.background,
|
|
1116
|
-
"stream-type":
|
|
1121
|
+
"stream-type": c,
|
|
1117
1122
|
...r
|
|
1118
1123
|
},
|
|
1119
1124
|
"done",
|
|
1120
|
-
[
|
|
1125
|
+
[P.StreamVideoDone]
|
|
1121
1126
|
);
|
|
1122
1127
|
}
|
|
1123
1128
|
function er(e, t, r) {
|
|
1124
|
-
const
|
|
1129
|
+
const a = {
|
|
1125
1130
|
call_id: t.call_id,
|
|
1126
1131
|
name: t.name
|
|
1127
1132
|
};
|
|
1128
|
-
if (e ===
|
|
1129
|
-
r.track("agent-tool-call", { ...
|
|
1133
|
+
if (e === P.ToolCallStarted) {
|
|
1134
|
+
r.track("agent-tool-call", { ...a, event: "started" });
|
|
1130
1135
|
return;
|
|
1131
1136
|
}
|
|
1132
|
-
const
|
|
1137
|
+
const c = t;
|
|
1133
1138
|
r.track("agent-tool-call", {
|
|
1134
|
-
...
|
|
1135
|
-
event: e ===
|
|
1136
|
-
duration_ms:
|
|
1137
|
-
extra_keys:
|
|
1139
|
+
...a,
|
|
1140
|
+
event: e === P.ToolCallDone ? "done" : "error",
|
|
1141
|
+
duration_ms: c.duration_ms,
|
|
1142
|
+
extra_keys: c.extra ? Object.keys(c.extra).length : 0
|
|
1138
1143
|
});
|
|
1139
1144
|
}
|
|
1140
|
-
function
|
|
1141
|
-
return H.reset(), Te.update(), new Promise(async (
|
|
1145
|
+
function Le(e, t, r, a) {
|
|
1146
|
+
return H.reset(), Te.update(), new Promise(async (c, s) => {
|
|
1142
1147
|
try {
|
|
1143
|
-
let
|
|
1148
|
+
let o, n = !1;
|
|
1144
1149
|
const i = Xt(e, t);
|
|
1145
1150
|
r.enrich({
|
|
1146
1151
|
"stream-version": i.version.toString()
|
|
1147
1152
|
});
|
|
1148
1153
|
let d = null;
|
|
1149
1154
|
const m = e.presenter.type === "expressive";
|
|
1150
|
-
|
|
1155
|
+
o = await Wt(
|
|
1151
1156
|
e,
|
|
1152
1157
|
i,
|
|
1153
1158
|
{
|
|
@@ -1156,34 +1161,34 @@ function Pe(e, t, r, n) {
|
|
|
1156
1161
|
callbacks: {
|
|
1157
1162
|
...t.callbacks,
|
|
1158
1163
|
onConnectionStateChange: (l, w) => {
|
|
1159
|
-
var
|
|
1160
|
-
(k = (
|
|
1164
|
+
var v, k;
|
|
1165
|
+
(k = (v = t.callbacks).onConnectionStateChange) == null || k.call(v, l), Yt(l, w, r), l === L.Connected && (o ? c(o) : n = !0);
|
|
1161
1166
|
},
|
|
1162
1167
|
onVideoStateChange: (l, w) => {
|
|
1163
|
-
var
|
|
1164
|
-
(k = (
|
|
1168
|
+
var v, k;
|
|
1169
|
+
(k = (v = t.callbacks).onVideoStateChange) == null || k.call(v, l), Gt(
|
|
1165
1170
|
l,
|
|
1166
1171
|
e,
|
|
1167
1172
|
w,
|
|
1168
1173
|
r,
|
|
1169
|
-
|
|
1174
|
+
o.streamType
|
|
1170
1175
|
);
|
|
1171
1176
|
},
|
|
1172
1177
|
onAgentActivityStateChange: (l) => {
|
|
1173
|
-
var w,
|
|
1174
|
-
(
|
|
1178
|
+
var w, v;
|
|
1179
|
+
(v = (w = t.callbacks).onAgentActivityStateChange) == null || v.call(w, l), l === ne.Talking ? (fe.update(), d = (k) => {
|
|
1175
1180
|
xe(
|
|
1176
1181
|
S.Start,
|
|
1177
1182
|
e,
|
|
1178
1183
|
r,
|
|
1179
|
-
|
|
1184
|
+
o.streamType,
|
|
1180
1185
|
k
|
|
1181
1186
|
), d = null;
|
|
1182
1187
|
}, m || d({ latency: H.get(!0) })) : (fe.reset(), d = null, xe(
|
|
1183
1188
|
S.Stop,
|
|
1184
1189
|
e,
|
|
1185
1190
|
r,
|
|
1186
|
-
|
|
1191
|
+
o.streamType
|
|
1187
1192
|
));
|
|
1188
1193
|
},
|
|
1189
1194
|
onFirstAudioDetected: (l) => {
|
|
@@ -1194,66 +1199,66 @@ function Pe(e, t, r, n) {
|
|
|
1194
1199
|
r.track("agent-chat", { event: "ready", latency: l });
|
|
1195
1200
|
},
|
|
1196
1201
|
onToolEvent: (l, w) => {
|
|
1197
|
-
var
|
|
1198
|
-
(k = (
|
|
1202
|
+
var v, k;
|
|
1203
|
+
(k = (v = t.callbacks).onToolEvent) == null || k.call(v, l, w), er(l, w, r);
|
|
1199
1204
|
}
|
|
1200
1205
|
}
|
|
1201
1206
|
},
|
|
1202
|
-
|
|
1203
|
-
),
|
|
1204
|
-
} catch (
|
|
1205
|
-
|
|
1207
|
+
a
|
|
1208
|
+
), n && c(o);
|
|
1209
|
+
} catch (o) {
|
|
1210
|
+
s(o);
|
|
1206
1211
|
}
|
|
1207
1212
|
});
|
|
1208
1213
|
}
|
|
1209
|
-
async function tr(e, t, r,
|
|
1210
|
-
var m, l, w,
|
|
1211
|
-
const
|
|
1214
|
+
async function tr(e, t, r, a, c) {
|
|
1215
|
+
var m, l, w, v;
|
|
1216
|
+
const s = async () => {
|
|
1212
1217
|
if (pe(e.presenter.type)) {
|
|
1213
|
-
const k = await
|
|
1218
|
+
const k = await Le(e, t, a), B = `${Ot}_${k.sessionId}`, M = (/* @__PURE__ */ new Date()).toISOString();
|
|
1214
1219
|
return { chatResult: {
|
|
1215
1220
|
chatMode: x.Functional,
|
|
1216
1221
|
chat: {
|
|
1217
1222
|
id: B,
|
|
1218
1223
|
agent_id: e.id,
|
|
1219
1224
|
owner_id: e.owner_id ?? "",
|
|
1220
|
-
created:
|
|
1221
|
-
modified:
|
|
1222
|
-
agent_id__created_at:
|
|
1223
|
-
agent_id__modified_at:
|
|
1225
|
+
created: M,
|
|
1226
|
+
modified: M,
|
|
1227
|
+
agent_id__created_at: M,
|
|
1228
|
+
agent_id__modified_at: M,
|
|
1224
1229
|
chat_mode: x.Functional,
|
|
1225
1230
|
messages: []
|
|
1226
1231
|
}
|
|
1227
1232
|
}, streamingManager: k };
|
|
1228
1233
|
} else {
|
|
1229
1234
|
const k = new AbortController(), B = k.signal;
|
|
1230
|
-
let
|
|
1235
|
+
let M;
|
|
1231
1236
|
try {
|
|
1232
1237
|
const D = Ke(
|
|
1233
1238
|
e,
|
|
1234
1239
|
r,
|
|
1235
|
-
|
|
1240
|
+
a,
|
|
1236
1241
|
t.mode,
|
|
1237
1242
|
t.persistentChat,
|
|
1238
|
-
|
|
1239
|
-
), $ =
|
|
1243
|
+
c
|
|
1244
|
+
), $ = Le(e, t, a, B).then((W) => (M = W, W)), [_, q] = await Promise.all([D, $]);
|
|
1240
1245
|
return { chatResult: _, streamingManager: q };
|
|
1241
1246
|
} catch (D) {
|
|
1242
|
-
throw k.abort(),
|
|
1247
|
+
throw k.abort(), M && await M.disconnect().catch(() => {
|
|
1243
1248
|
}), D;
|
|
1244
1249
|
}
|
|
1245
1250
|
}
|
|
1246
|
-
}, { chatResult:
|
|
1247
|
-
return d && t.mode !== void 0 && d !== t.mode && (t.mode = d, (l = (m = t.callbacks).onModeChange) == null || l.call(m, d), d !== x.Functional) ? ((
|
|
1251
|
+
}, { chatResult: o, streamingManager: n } = await s(), { chat: i, chatMode: d } = o;
|
|
1252
|
+
return d && t.mode !== void 0 && d !== t.mode && (t.mode = d, (l = (m = t.callbacks).onModeChange) == null || l.call(m, d), d !== x.Functional) ? ((v = (w = t.callbacks).onError) == null || v.call(w, new He(d)), n == null || n.disconnect(), { chat: i }) : { chat: i, streamingManager: n };
|
|
1248
1253
|
}
|
|
1249
1254
|
async function sr(e, t) {
|
|
1250
1255
|
var Y, K, ae, ie;
|
|
1251
1256
|
let r = !0;
|
|
1252
|
-
const
|
|
1257
|
+
const a = t.mixpanelKey || ot, c = t.wsURL || st, s = t.baseURL || de, o = t.mode || x.Functional, n = {
|
|
1253
1258
|
messages: [],
|
|
1254
|
-
chatMode:
|
|
1259
|
+
chatMode: o
|
|
1255
1260
|
}, i = Ct({
|
|
1256
|
-
token:
|
|
1261
|
+
token: a,
|
|
1257
1262
|
agentId: e,
|
|
1258
1263
|
isEnabled: t.enableAnalitics,
|
|
1259
1264
|
externalId: t.externalId,
|
|
@@ -1262,25 +1267,25 @@ async function sr(e, t) {
|
|
|
1262
1267
|
Ee(() => {
|
|
1263
1268
|
i.track("agent-sdk", { event: "init" }, d);
|
|
1264
1269
|
});
|
|
1265
|
-
const m = gt(t.auth,
|
|
1270
|
+
const m = gt(t.auth, s, t.callbacks.onError, t.externalId), l = await m.getById(e);
|
|
1266
1271
|
t.debug = t.debug || ((Y = l == null ? void 0 : l.advanced_settings) == null ? void 0 : Y.ui_debug_mode);
|
|
1267
1272
|
const w = pe(l.presenter.type);
|
|
1268
1273
|
i.enrich(pt(l));
|
|
1269
|
-
const { onMessage:
|
|
1274
|
+
const { onMessage: v, clearQueue: k } = _t(i, n, t, l, () => {
|
|
1270
1275
|
var u, g, p;
|
|
1271
|
-
(u =
|
|
1276
|
+
(u = n.socketManager) == null || u.disconnect(), (p = (g = t.callbacks).onConnectionStateChange) == null || p.call(g, L.Disconnected);
|
|
1272
1277
|
});
|
|
1273
|
-
|
|
1278
|
+
n.messages = kt(t.initialMessages), (ae = (K = t.callbacks).onNewMessage) == null || ae.call(K, [...n.messages], "answer");
|
|
1274
1279
|
const B = (u) => {
|
|
1275
|
-
},
|
|
1276
|
-
var p,
|
|
1277
|
-
if (!((p =
|
|
1278
|
-
const g =
|
|
1280
|
+
}, M = ({ type: u }) => {
|
|
1281
|
+
var p, y, C, R;
|
|
1282
|
+
if (!((p = n.streamingManager) != null && p.interruptAvailable) || !((y = n.streamingManager) != null && y.isInterruptible)) return;
|
|
1283
|
+
const g = n.messages[n.messages.length - 1];
|
|
1279
1284
|
i.track("agent-video-interrupt", {
|
|
1280
1285
|
type: u || "click",
|
|
1281
1286
|
video_duration_to_interrupt: fe.get(!0),
|
|
1282
1287
|
message_duration_to_interrupt: H.get(!0)
|
|
1283
|
-
}), g.interrupted = !0, (R = (C = t.callbacks).onNewMessage) == null || R.call(C, [...
|
|
1288
|
+
}), g.interrupted = !0, (R = (C = t.callbacks).onNewMessage) == null || R.call(C, [...n.messages], "answer"), n.streamingManager.interrupt(u);
|
|
1284
1289
|
}, D = /* @__PURE__ */ new Map();
|
|
1285
1290
|
function $(u) {
|
|
1286
1291
|
return async (g) => {
|
|
@@ -1288,26 +1293,26 @@ async function sr(e, t) {
|
|
|
1288
1293
|
if (!p)
|
|
1289
1294
|
throw new Error(`No handler registered for client tool: ${u}`);
|
|
1290
1295
|
try {
|
|
1291
|
-
const
|
|
1292
|
-
return await p(
|
|
1293
|
-
} catch (
|
|
1294
|
-
throw new Error(`Client tool "${u}" failed: ${
|
|
1296
|
+
const y = JSON.parse(g.payload);
|
|
1297
|
+
return await p(y);
|
|
1298
|
+
} catch (y) {
|
|
1299
|
+
throw new Error(`Client tool "${u}" failed: ${y.message}`);
|
|
1295
1300
|
}
|
|
1296
1301
|
};
|
|
1297
1302
|
}
|
|
1298
1303
|
function _() {
|
|
1299
|
-
var u, g, p,
|
|
1304
|
+
var u, g, p, y;
|
|
1300
1305
|
for (const [C] of D)
|
|
1301
|
-
(g = (u =
|
|
1306
|
+
(g = (u = n.streamingManager) == null ? void 0 : u.unregisterRpcMethod) == null || g.call(u, C), (y = (p = n.streamingManager) == null ? void 0 : p.registerRpcMethod) == null || y.call(p, C, $(C));
|
|
1302
1307
|
}
|
|
1303
1308
|
function q(u, g) {
|
|
1304
|
-
var
|
|
1309
|
+
var y, C;
|
|
1305
1310
|
const p = !D.has(u);
|
|
1306
|
-
D.set(u, g), p && ((C = (
|
|
1311
|
+
D.set(u, g), p && ((C = (y = n.streamingManager) == null ? void 0 : y.registerRpcMethod) == null || C.call(y, u, $(u)));
|
|
1307
1312
|
}
|
|
1308
1313
|
function W(u) {
|
|
1309
1314
|
var g, p;
|
|
1310
|
-
D.delete(u), (p = (g =
|
|
1315
|
+
D.delete(u), (p = (g = n.streamingManager) == null ? void 0 : g.unregisterRpcMethod) == null || p.call(g, u);
|
|
1311
1316
|
}
|
|
1312
1317
|
const N = Date.now();
|
|
1313
1318
|
Ee(() => {
|
|
@@ -1315,27 +1320,27 @@ async function sr(e, t) {
|
|
|
1315
1320
|
});
|
|
1316
1321
|
async function X(u) {
|
|
1317
1322
|
var j, z, F, E, f, h, b;
|
|
1318
|
-
(z = (j = t.callbacks).onConnectionStateChange) == null || z.call(j,
|
|
1319
|
-
const g =
|
|
1323
|
+
(z = (j = t.callbacks).onConnectionStateChange) == null || z.call(j, L.Connecting), H.reset(), u && !r && (delete n.chat, (E = (F = t.callbacks).onNewMessage) == null || E.call(F, [...n.messages], "answer"));
|
|
1324
|
+
const g = o === x.DirectPlayback || w ? Promise.resolve(void 0) : It(
|
|
1320
1325
|
t.auth,
|
|
1321
|
-
|
|
1322
|
-
{ onMessage:
|
|
1326
|
+
c,
|
|
1327
|
+
{ onMessage: v, onError: t.callbacks.onError },
|
|
1323
1328
|
t.externalId
|
|
1324
1329
|
), p = ue(
|
|
1325
1330
|
() => tr(
|
|
1326
1331
|
l,
|
|
1327
1332
|
{
|
|
1328
1333
|
...t,
|
|
1329
|
-
mode:
|
|
1334
|
+
mode: o,
|
|
1330
1335
|
callbacks: {
|
|
1331
1336
|
...t.callbacks,
|
|
1332
1337
|
onVideoIdChange: B,
|
|
1333
|
-
onMessage:
|
|
1338
|
+
onMessage: v
|
|
1334
1339
|
}
|
|
1335
1340
|
},
|
|
1336
1341
|
m,
|
|
1337
1342
|
i,
|
|
1338
|
-
|
|
1343
|
+
n.chat
|
|
1339
1344
|
),
|
|
1340
1345
|
{
|
|
1341
1346
|
limit: 3,
|
|
@@ -1346,49 +1351,49 @@ async function sr(e, t) {
|
|
|
1346
1351
|
}
|
|
1347
1352
|
).catch((T) => {
|
|
1348
1353
|
var A, V;
|
|
1349
|
-
throw
|
|
1350
|
-
}), [
|
|
1351
|
-
R && R.id !== ((f =
|
|
1354
|
+
throw I(x.Maintenance), (V = (A = t.callbacks).onConnectionStateChange) == null || V.call(A, L.Fail), T;
|
|
1355
|
+
}), [y, { streamingManager: C, chat: R }] = await Promise.all([g, p]);
|
|
1356
|
+
R && R.id !== ((f = n.chat) == null ? void 0 : f.id) && ((b = (h = t.callbacks).onNewChat) == null || b.call(h, R.id)), n.streamingManager = C, n.socketManager = y, n.chat = R, _(), r = !1, i.enrich({
|
|
1352
1357
|
chatId: R == null ? void 0 : R.id,
|
|
1353
1358
|
streamId: C == null ? void 0 : C.streamId,
|
|
1354
|
-
mode:
|
|
1355
|
-
}),
|
|
1359
|
+
mode: n.chatMode
|
|
1360
|
+
}), I((R == null ? void 0 : R.chat_mode) ?? o);
|
|
1356
1361
|
}
|
|
1357
1362
|
async function O() {
|
|
1358
|
-
var u, g, p,
|
|
1359
|
-
(u =
|
|
1363
|
+
var u, g, p, y;
|
|
1364
|
+
(u = n.socketManager) == null || u.disconnect(), await ((g = n.streamingManager) == null ? void 0 : g.disconnect()), delete n.streamingManager, delete n.socketManager, (y = (p = t.callbacks).onConnectionStateChange) == null || y.call(p, L.Disconnected);
|
|
1360
1365
|
}
|
|
1361
|
-
async function
|
|
1366
|
+
async function I(u) {
|
|
1362
1367
|
var g, p;
|
|
1363
|
-
u !==
|
|
1368
|
+
u !== n.chatMode && (i.track("agent-mode-change", { mode: u }), n.chatMode = u, n.chatMode !== x.Functional && await O(), (p = (g = t.callbacks).onModeChange) == null || p.call(g, u));
|
|
1364
1369
|
}
|
|
1365
1370
|
return {
|
|
1366
1371
|
agent: l,
|
|
1367
1372
|
getStreamType: () => {
|
|
1368
1373
|
var u;
|
|
1369
|
-
return (u =
|
|
1374
|
+
return (u = n.streamingManager) == null ? void 0 : u.streamType;
|
|
1370
1375
|
},
|
|
1371
1376
|
getIsInterruptAvailable: () => {
|
|
1372
1377
|
var u;
|
|
1373
|
-
return ((u =
|
|
1378
|
+
return ((u = n.streamingManager) == null ? void 0 : u.interruptAvailable) ?? !1;
|
|
1374
1379
|
},
|
|
1375
1380
|
starterMessages: ((ie = l.knowledge) == null ? void 0 : ie.starter_message) || [],
|
|
1376
1381
|
getSTTToken: () => m.getSTTToken(l.id),
|
|
1377
|
-
changeMode:
|
|
1382
|
+
changeMode: I,
|
|
1378
1383
|
enrichAnalytics: i.enrich,
|
|
1379
1384
|
async connect() {
|
|
1380
1385
|
await X(!0), i.track("agent-chat", {
|
|
1381
1386
|
event: "connect",
|
|
1382
|
-
mode:
|
|
1387
|
+
mode: n.chatMode
|
|
1383
1388
|
});
|
|
1384
1389
|
},
|
|
1385
1390
|
async reconnect() {
|
|
1386
|
-
const u =
|
|
1391
|
+
const u = n.streamingManager;
|
|
1387
1392
|
if (w && (u != null && u.reconnect)) {
|
|
1388
1393
|
try {
|
|
1389
1394
|
await u.reconnect(), i.track("agent-chat", {
|
|
1390
1395
|
event: "reconnect",
|
|
1391
|
-
mode:
|
|
1396
|
+
mode: n.chatMode
|
|
1392
1397
|
});
|
|
1393
1398
|
} catch {
|
|
1394
1399
|
await O(), await X(!1);
|
|
@@ -1397,94 +1402,94 @@ async function sr(e, t) {
|
|
|
1397
1402
|
}
|
|
1398
1403
|
await O(), await X(!1), i.track("agent-chat", {
|
|
1399
1404
|
event: "reconnect",
|
|
1400
|
-
mode:
|
|
1405
|
+
mode: n.chatMode
|
|
1401
1406
|
});
|
|
1402
1407
|
},
|
|
1403
1408
|
async disconnect() {
|
|
1404
1409
|
await O(), i.track("agent-chat", {
|
|
1405
1410
|
event: "disconnect",
|
|
1406
|
-
mode:
|
|
1411
|
+
mode: n.chatMode
|
|
1407
1412
|
});
|
|
1408
1413
|
},
|
|
1409
1414
|
publishMicrophoneStream(u) {
|
|
1410
1415
|
var g;
|
|
1411
|
-
return (g =
|
|
1416
|
+
return (g = n.streamingManager) != null && g.publishMicrophoneStream ? n.streamingManager.publishMicrophoneStream(u) : Promise.reject(new Error("publishMicrophoneStream is not available for this streaming manager"));
|
|
1412
1417
|
},
|
|
1413
1418
|
unpublishMicrophoneStream() {
|
|
1414
1419
|
var u;
|
|
1415
|
-
return (u =
|
|
1420
|
+
return (u = n.streamingManager) != null && u.unpublishMicrophoneStream ? n.streamingManager.unpublishMicrophoneStream() : Promise.resolve();
|
|
1416
1421
|
},
|
|
1417
1422
|
replaceMicrophoneTrack(u) {
|
|
1418
1423
|
var g;
|
|
1419
|
-
return (g =
|
|
1424
|
+
return (g = n.streamingManager) != null && g.replaceMicrophoneTrack ? n.streamingManager.replaceMicrophoneTrack(u) : Promise.reject(new Error("replaceMicrophoneTrack is not available for this streaming manager"));
|
|
1420
1425
|
},
|
|
1421
1426
|
publishCameraStream(u) {
|
|
1422
1427
|
var g;
|
|
1423
|
-
return (g =
|
|
1428
|
+
return (g = n.streamingManager) != null && g.publishCameraStream ? n.streamingManager.publishCameraStream(u) : Promise.reject(new Error("publishCameraStream is not available for this streaming manager"));
|
|
1424
1429
|
},
|
|
1425
1430
|
unpublishCameraStream() {
|
|
1426
1431
|
var u;
|
|
1427
|
-
return (u =
|
|
1432
|
+
return (u = n.streamingManager) != null && u.unpublishCameraStream ? n.streamingManager.unpublishCameraStream() : Promise.resolve();
|
|
1428
1433
|
},
|
|
1429
1434
|
async chat(u) {
|
|
1430
1435
|
var C, R, j, z, F;
|
|
1431
1436
|
const g = () => {
|
|
1432
|
-
if ($e(
|
|
1433
|
-
throw new G(`${
|
|
1437
|
+
if ($e(o))
|
|
1438
|
+
throw new G(`${o} is enabled, chat is disabled`);
|
|
1434
1439
|
if (u.length >= 800)
|
|
1435
1440
|
throw new G("Message cannot be more than 800 characters");
|
|
1436
1441
|
if (u.length === 0)
|
|
1437
1442
|
throw new G("Message cannot be empty");
|
|
1438
|
-
if (
|
|
1443
|
+
if (n.chatMode === x.Maintenance)
|
|
1439
1444
|
throw new G("Chat is in maintenance mode");
|
|
1440
|
-
if (![x.TextOnly, x.Playground].includes(
|
|
1441
|
-
if (!
|
|
1445
|
+
if (![x.TextOnly, x.Playground].includes(n.chatMode)) {
|
|
1446
|
+
if (!n.streamingManager)
|
|
1442
1447
|
throw new G("Streaming manager is not initialized");
|
|
1443
|
-
if (!
|
|
1448
|
+
if (!n.chat)
|
|
1444
1449
|
throw new G("Chat is not initialized");
|
|
1445
1450
|
}
|
|
1446
1451
|
}, p = async () => {
|
|
1447
1452
|
var E, f;
|
|
1448
|
-
if (!
|
|
1453
|
+
if (!n.chat) {
|
|
1449
1454
|
const h = await Ke(
|
|
1450
1455
|
l,
|
|
1451
1456
|
m,
|
|
1452
1457
|
i,
|
|
1453
|
-
|
|
1458
|
+
n.chatMode,
|
|
1454
1459
|
t.persistentChat
|
|
1455
1460
|
);
|
|
1456
1461
|
if (!h.chat)
|
|
1457
|
-
throw new Oe(
|
|
1458
|
-
|
|
1462
|
+
throw new Oe(n.chatMode, !!t.persistentChat);
|
|
1463
|
+
n.chat = h.chat, (f = (E = t.callbacks).onNewChat) == null || f.call(E, n.chat.id);
|
|
1459
1464
|
}
|
|
1460
|
-
return
|
|
1461
|
-
},
|
|
1462
|
-
const h =
|
|
1465
|
+
return n.chat.id;
|
|
1466
|
+
}, y = async (E, f) => {
|
|
1467
|
+
const h = n.chatMode === x.Playground;
|
|
1463
1468
|
return ue(w && !h ? async () => {
|
|
1464
1469
|
var A, V;
|
|
1465
|
-
return await ((V = (A =
|
|
1470
|
+
return await ((V = (A = n.streamingManager) == null ? void 0 : A.sendTextMessage) == null ? void 0 : V.call(A, u)), Promise.resolve({});
|
|
1466
1471
|
} : async () => {
|
|
1467
1472
|
var A, V;
|
|
1468
1473
|
return m.chat(
|
|
1469
1474
|
l.id,
|
|
1470
1475
|
f,
|
|
1471
1476
|
{
|
|
1472
|
-
chatMode:
|
|
1473
|
-
streamId: (A =
|
|
1474
|
-
sessionId: (V =
|
|
1477
|
+
chatMode: n.chatMode,
|
|
1478
|
+
streamId: (A = n.streamingManager) == null ? void 0 : A.streamId,
|
|
1479
|
+
sessionId: (V = n.streamingManager) == null ? void 0 : V.sessionId,
|
|
1475
1480
|
messages: E.map(({ matches: Je, ...se }) => se)
|
|
1476
1481
|
},
|
|
1477
1482
|
{
|
|
1478
|
-
...Ne(
|
|
1483
|
+
...Ne(n.chatMode),
|
|
1479
1484
|
skipErrorHandler: !0
|
|
1480
1485
|
}
|
|
1481
1486
|
);
|
|
1482
1487
|
}, {
|
|
1483
1488
|
limit: 2,
|
|
1484
1489
|
shouldRetryFn: (A) => {
|
|
1485
|
-
var se,
|
|
1490
|
+
var se, ve, ye, Ce;
|
|
1486
1491
|
const V = (se = A == null ? void 0 : A.message) == null ? void 0 : se.includes("missing or invalid session_id");
|
|
1487
|
-
return !((
|
|
1492
|
+
return !((ve = A == null ? void 0 : A.message) == null ? void 0 : ve.includes("Stream Error")) && !V ? ((Ce = (ye = t.callbacks).onError) == null || Ce.call(ye, A), !1) : !0;
|
|
1488
1493
|
},
|
|
1489
1494
|
onRetry: async () => {
|
|
1490
1495
|
await O(), await X(!1);
|
|
@@ -1492,15 +1497,15 @@ async function sr(e, t) {
|
|
|
1492
1497
|
});
|
|
1493
1498
|
};
|
|
1494
1499
|
try {
|
|
1495
|
-
k(), g(),
|
|
1500
|
+
k(), g(), n.messages.push({
|
|
1496
1501
|
id: te(),
|
|
1497
1502
|
role: "user",
|
|
1498
1503
|
content: u,
|
|
1499
1504
|
parts: re(u),
|
|
1500
1505
|
created_at: new Date(H.update()).toISOString()
|
|
1501
|
-
}), (R = (C = t.callbacks).onNewMessage) == null || R.call(C, [...
|
|
1502
|
-
const E = await p(), f = await
|
|
1503
|
-
return
|
|
1506
|
+
}), (R = (C = t.callbacks).onNewMessage) == null || R.call(C, [...n.messages], "user");
|
|
1507
|
+
const E = await p(), f = await y([...n.messages], E);
|
|
1508
|
+
return n.messages.push({
|
|
1504
1509
|
id: te(),
|
|
1505
1510
|
role: "assistant",
|
|
1506
1511
|
content: f.result || "",
|
|
@@ -1510,38 +1515,38 @@ async function sr(e, t) {
|
|
|
1510
1515
|
matches: f.matches
|
|
1511
1516
|
}), i.track("agent-message-send", {
|
|
1512
1517
|
event: "success",
|
|
1513
|
-
messages:
|
|
1514
|
-
}), f.result && ((z = (j = t.callbacks).onNewMessage) == null || z.call(j, [...
|
|
1518
|
+
messages: n.messages.length + 1
|
|
1519
|
+
}), f.result && ((z = (j = t.callbacks).onNewMessage) == null || z.call(j, [...n.messages], "answer"), i.track("agent-message-received", {
|
|
1515
1520
|
latency: H.get(!0),
|
|
1516
|
-
messages:
|
|
1521
|
+
messages: n.messages.length
|
|
1517
1522
|
})), f;
|
|
1518
1523
|
} catch (E) {
|
|
1519
|
-
throw ((F =
|
|
1524
|
+
throw ((F = n.messages[n.messages.length - 1]) == null ? void 0 : F.role) === "assistant" && n.messages.pop(), i.track("agent-message-send", {
|
|
1520
1525
|
event: "error",
|
|
1521
|
-
messages:
|
|
1526
|
+
messages: n.messages.length
|
|
1522
1527
|
}), E;
|
|
1523
1528
|
}
|
|
1524
1529
|
},
|
|
1525
1530
|
rate(u, g, p) {
|
|
1526
1531
|
var R, j, z, F;
|
|
1527
|
-
const
|
|
1528
|
-
if (
|
|
1529
|
-
if (!
|
|
1532
|
+
const y = n.messages.find((E) => E.id === u);
|
|
1533
|
+
if (n.chat) {
|
|
1534
|
+
if (!y)
|
|
1530
1535
|
throw new Error("Message not found");
|
|
1531
1536
|
} else throw new Error("Chat is not initialized");
|
|
1532
|
-
const C = ((R =
|
|
1537
|
+
const C = ((R = y.matches) == null ? void 0 : R.map((E) => [E.document_id, E.id])) ?? [];
|
|
1533
1538
|
return i.track("agent-rate", {
|
|
1534
1539
|
event: p ? "update" : "create",
|
|
1535
1540
|
thumb: g === 1 ? "up" : "down",
|
|
1536
1541
|
knowledge_id: ((j = l.knowledge) == null ? void 0 : j.id) ?? "",
|
|
1537
1542
|
matches: C,
|
|
1538
1543
|
score: g
|
|
1539
|
-
}), p ? m.updateRating(l.id,
|
|
1544
|
+
}), p ? m.updateRating(l.id, n.chat.id, p, {
|
|
1540
1545
|
knowledge_id: ((z = l.knowledge) == null ? void 0 : z.id) ?? "",
|
|
1541
1546
|
message_id: u,
|
|
1542
1547
|
matches: C,
|
|
1543
1548
|
score: g
|
|
1544
|
-
}) : m.createRating(l.id,
|
|
1549
|
+
}) : m.createRating(l.id, n.chat.id, {
|
|
1545
1550
|
knowledge_id: ((F = l.knowledge) == null ? void 0 : F.id) ?? "",
|
|
1546
1551
|
message_id: u,
|
|
1547
1552
|
matches: C,
|
|
@@ -1549,9 +1554,9 @@ async function sr(e, t) {
|
|
|
1549
1554
|
});
|
|
1550
1555
|
},
|
|
1551
1556
|
deleteRate(u) {
|
|
1552
|
-
if (!
|
|
1557
|
+
if (!n.chat)
|
|
1553
1558
|
throw new Error("Chat is not initialized");
|
|
1554
|
-
return i.track("agent-rate-delete", { type: "text" }), m.deleteRating(l.id,
|
|
1559
|
+
return i.track("agent-rate-delete", { type: "text" }), m.deleteRating(l.id, n.chat.id, u);
|
|
1555
1560
|
},
|
|
1556
1561
|
async speak(u) {
|
|
1557
1562
|
var C, R, j;
|
|
@@ -1579,26 +1584,26 @@ async function sr(e, t) {
|
|
|
1579
1584
|
return u;
|
|
1580
1585
|
}
|
|
1581
1586
|
const p = g();
|
|
1582
|
-
if (i.track("agent-speak", p), H.update(),
|
|
1587
|
+
if (i.track("agent-speak", p), H.update(), n.messages && p.type === "text" && (n.messages.push({
|
|
1583
1588
|
id: te(),
|
|
1584
1589
|
role: "assistant",
|
|
1585
1590
|
content: p.input,
|
|
1586
1591
|
parts: re(p.input),
|
|
1587
1592
|
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1588
|
-
}), (R = (C = t.callbacks).onNewMessage) == null || R.call(C, [...
|
|
1593
|
+
}), (R = (C = t.callbacks).onNewMessage) == null || R.call(C, [...n.messages], "answer")), lt(n.chatMode))
|
|
1589
1594
|
return {
|
|
1590
1595
|
duration: 0,
|
|
1591
1596
|
video_id: "",
|
|
1592
1597
|
status: "success"
|
|
1593
1598
|
};
|
|
1594
|
-
if (!
|
|
1599
|
+
if (!n.streamingManager)
|
|
1595
1600
|
throw new Error("Please connect to the agent first");
|
|
1596
|
-
return
|
|
1601
|
+
return n.streamingManager.speak({
|
|
1597
1602
|
script: p,
|
|
1598
|
-
metadata: { chat_id: (j =
|
|
1603
|
+
metadata: { chat_id: (j = n.chat) == null ? void 0 : j.id, agent_id: l.id }
|
|
1599
1604
|
});
|
|
1600
1605
|
},
|
|
1601
|
-
interrupt:
|
|
1606
|
+
interrupt: M,
|
|
1602
1607
|
registerClientTool: q,
|
|
1603
1608
|
unregisterClientTool: W
|
|
1604
1609
|
};
|
|
@@ -1610,7 +1615,7 @@ export {
|
|
|
1610
1615
|
et as K,
|
|
1611
1616
|
Ye as P,
|
|
1612
1617
|
Qe as R,
|
|
1613
|
-
|
|
1618
|
+
P as S,
|
|
1614
1619
|
he as T,
|
|
1615
1620
|
Xe as U,
|
|
1616
1621
|
G as V,
|
|
@@ -1619,7 +1624,7 @@ export {
|
|
|
1619
1624
|
U as b,
|
|
1620
1625
|
Fe as c,
|
|
1621
1626
|
de as d,
|
|
1622
|
-
|
|
1627
|
+
L as e,
|
|
1623
1628
|
ee as f,
|
|
1624
1629
|
Ft as g,
|
|
1625
1630
|
ir as h,
|
|
@@ -1633,7 +1638,7 @@ export {
|
|
|
1633
1638
|
ut as p,
|
|
1634
1639
|
x as q,
|
|
1635
1640
|
Ze as r,
|
|
1636
|
-
|
|
1641
|
+
Pe as s,
|
|
1637
1642
|
nr as t,
|
|
1638
1643
|
rt as u,
|
|
1639
1644
|
nt as v
|