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