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