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