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