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