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