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