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