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