@d-id/client-sdk 1.0.29-beta.55 → 1.1.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +287 -5
- package/dist/index.js +1033 -383
- package/dist/index.umd.cjs +1 -1
- package/dist/src/api/agents.d.ts +16 -9
- package/dist/src/api/apiClient.d.ts +10 -0
- package/dist/src/api/knowledge.d.ts +1 -1
- package/dist/src/api/streams/clipStream.d.ts +2 -0
- package/dist/src/api/streams/index.d.ts +2 -0
- package/dist/src/api/streams/talkStream.d.ts +2 -0
- package/dist/src/auth/{getAuthHeader.d.ts → get-auth-header.d.ts} +1 -0
- package/dist/src/config/consts.d.ts +2 -0
- package/dist/src/{environment.d.ts → config/environment.d.ts} +0 -1
- package/dist/src/errors/base-error.d.ts +12 -0
- package/dist/src/errors/chat/chat-creation-failed.d.ts +5 -0
- package/dist/src/errors/chat/chat-mode-downgraded.d.ts +5 -0
- package/dist/src/errors/index.d.ts +4 -0
- package/dist/src/errors/validation-error.d.ts +5 -0
- package/dist/src/errors/ws-error.d.ts +4 -0
- package/dist/src/index.d.ts +3 -2
- package/dist/src/services/agent-manager/connect-to-manager.d.ts +7 -0
- package/dist/src/{createAgentManager.d.ts → services/agent-manager/index.d.ts} +12 -4
- package/dist/src/services/analytics/mixpanel.d.ts +21 -0
- package/dist/src/services/analytics/timestamp-tracker.d.ts +5 -0
- package/dist/src/services/chat/index.d.ts +7 -0
- package/dist/src/services/chat/intial-messages.d.ts +3 -0
- package/dist/src/services/socket-manager/index.d.ts +11 -0
- package/dist/src/services/socket-manager/message-queue.d.ts +11 -0
- package/dist/src/{createStreamingManager.d.ts → services/streaming-manager/index.d.ts} +3 -3
- package/dist/src/services/streaming-manager/stats/poll.d.ts +4 -0
- package/dist/src/services/streaming-manager/stats/report.d.ts +11 -0
- package/dist/src/types/entities/agents/agent.d.ts +14 -2
- package/dist/src/types/entities/agents/chat.d.ts +12 -4
- package/dist/src/types/entities/agents/knowledge.d.ts +2 -0
- package/dist/src/types/entities/agents/llm.d.ts +20 -17
- package/dist/src/types/entities/agents/manager.d.ts +92 -23
- package/dist/src/types/entities/agents/presenter.d.ts +8 -2
- package/dist/src/types/entities/video.d.ts +1 -0
- package/dist/src/types/face-rect.d.ts +6 -0
- package/dist/src/types/index.d.ts +4 -4
- package/dist/src/types/stream/api/clip.d.ts +20 -9
- package/dist/src/types/stream/api/talk.d.ts +31 -1
- package/dist/src/types/stream/rtc.d.ts +3 -3
- package/dist/src/types/stream/stream.d.ts +50 -4
- package/dist/src/types/{StreamScript.d.ts → stream-script.d.ts} +1 -1
- package/dist/src/types/voice/stt.d.ts +4 -0
- package/dist/src/utils/agent.d.ts +4 -0
- package/dist/src/utils/analytics.d.ts +13 -0
- package/dist/src/utils/index.d.ts +2 -0
- package/dist/src/utils/retry-operation.d.ts +38 -0
- package/package.json +4 -3
- package/dist/src/api/clipStream.d.ts +0 -2
- package/dist/src/api/getClient.d.ts +0 -7
- package/dist/src/api/ratings.d.ts +0 -7
- package/dist/src/api/talkStream.d.ts +0 -2
- package/dist/src/connectToSocket.d.ts +0 -9
- package/dist/src/utils/webrtc.d.ts +0 -2
- /package/dist/src/types/{tts.d.ts → voice/tts.d.ts} +0 -0
package/dist/index.js
CHANGED
|
@@ -1,536 +1,1186 @@
|
|
|
1
|
-
var
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
var me = Object.defineProperty;
|
|
2
|
+
var ue = (e, t, a) => t in e ? me(e, t, { enumerable: !0, configurable: !0, writable: !0, value: a }) : e[t] = a;
|
|
3
|
+
var H = (e, t, a) => (ue(e, typeof t != "symbol" ? t + "" : t, a), a);
|
|
4
|
+
class J extends Error {
|
|
5
|
+
constructor({
|
|
6
|
+
kind: a,
|
|
7
|
+
description: n,
|
|
8
|
+
error: s
|
|
9
|
+
}) {
|
|
10
|
+
super(JSON.stringify({
|
|
11
|
+
kind: a,
|
|
12
|
+
description: n
|
|
13
|
+
}));
|
|
14
|
+
H(this, "kind");
|
|
15
|
+
H(this, "description");
|
|
16
|
+
H(this, "error");
|
|
17
|
+
this.kind = a, this.description = n, this.error = s;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
class fe extends J {
|
|
21
|
+
constructor(t, a) {
|
|
22
|
+
super({
|
|
23
|
+
kind: "ChatCreationFailed",
|
|
24
|
+
description: `Failed to create ${a ? "persistent" : ""} chat, mode: ${t}`
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
class ge extends J {
|
|
29
|
+
constructor(t) {
|
|
30
|
+
super({
|
|
31
|
+
kind: "ChatModeDowngraded",
|
|
32
|
+
description: `Chat mode downgraded to ${t}`
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
class B extends J {
|
|
37
|
+
constructor(a, n) {
|
|
38
|
+
super({
|
|
39
|
+
kind: "ValidationError",
|
|
40
|
+
description: a
|
|
41
|
+
});
|
|
42
|
+
H(this, "key");
|
|
43
|
+
this.key = n;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
class he extends J {
|
|
47
|
+
constructor(t) {
|
|
48
|
+
super({
|
|
49
|
+
kind: "WSError",
|
|
50
|
+
description: t
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
var we = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(we || {}), pe = /* @__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))(pe || {}), ye = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(ye || {}), ve = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(ve || {}), b = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e))(b || {}), F = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Complete = "done", e))(F || {}), ke = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(ke || {}), Re = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(Re || {}), Ce = /* @__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))(Ce || {}), ne = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e))(ne || {});
|
|
55
|
+
const Se = (e) => {
|
|
56
|
+
switch (e) {
|
|
57
|
+
case "clip":
|
|
58
|
+
return "clip";
|
|
59
|
+
case "talk":
|
|
60
|
+
return "talk";
|
|
61
|
+
default:
|
|
62
|
+
throw new Error(`Unknown video type: ${e}`);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
var D = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(D || {}), U = /* @__PURE__ */ ((e) => (e.ChatAnswer = "chat/answer", e.ChatPartial = "chat/partial", e.StreamDone = "stream/done", e.StreamStarted = "stream/started", e.StreamFailed = "stream/error", e.StreamReady = "stream/ready", e.StreamCreated = "stream/created", e.StreamVideoCreated = "stream-video/started", e.StreamVideoDone = "stream-video/done", e.StreamVideoError = "stream-video/error", e.StreamVideoRejected = "stream-video/rejected", e))(U || {}), S = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnected = "disconnected", e))(S || {}), De = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(De || {}), _e = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(_e || {});
|
|
66
|
+
const Me = 45 * 1e3, Ee = "X-Playground-Chat", K = "https://api.d-id.com", be = "wss://notifications.d-id.com", Ie = "79f81a83a67430be2bc0fd61042b8faa", ae = (e) => new Promise((t) => setTimeout(t, e)), q = () => Math.random().toString(16).slice(2);
|
|
67
|
+
function Pe(e, t) {
|
|
68
|
+
let a;
|
|
69
|
+
return {
|
|
70
|
+
promise: new Promise((s, i) => {
|
|
71
|
+
a = setTimeout(() => i(new Error(t)), e);
|
|
72
|
+
}),
|
|
73
|
+
clear: () => clearTimeout(a)
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
async function X(e, t) {
|
|
77
|
+
const a = {
|
|
78
|
+
limit: (t == null ? void 0 : t.limit) ?? 3,
|
|
79
|
+
delayMs: (t == null ? void 0 : t.delayMs) ?? 0,
|
|
80
|
+
timeout: (t == null ? void 0 : t.timeout) ?? 3e4,
|
|
81
|
+
timeoutErrorMessage: (t == null ? void 0 : t.timeoutErrorMessage) || "Timeout error",
|
|
82
|
+
shouldRetryFn: (t == null ? void 0 : t.shouldRetryFn) ?? (() => !0),
|
|
83
|
+
onRetry: (t == null ? void 0 : t.onRetry) ?? (() => {
|
|
84
|
+
})
|
|
85
|
+
};
|
|
86
|
+
let n;
|
|
87
|
+
for (let s = 1; s <= a.limit; s++)
|
|
88
|
+
try {
|
|
89
|
+
if (!a.timeout)
|
|
90
|
+
return await e();
|
|
91
|
+
const {
|
|
92
|
+
promise: i,
|
|
93
|
+
clear: r
|
|
94
|
+
} = Pe(a.timeout, a.timeoutErrorMessage), o = e().finally(r);
|
|
95
|
+
return await Promise.race([o, i]);
|
|
96
|
+
} catch (i) {
|
|
97
|
+
if (n = i, !a.shouldRetryFn(i) || s >= a.limit)
|
|
98
|
+
throw i;
|
|
99
|
+
await ae(a.delayMs), a.onRetry(i);
|
|
100
|
+
}
|
|
101
|
+
throw n;
|
|
102
|
+
}
|
|
103
|
+
function ie() {
|
|
4
104
|
let e = window.localStorage.getItem("did_external_key_id");
|
|
5
105
|
return e || (e = Math.random().toString(16).slice(2), window.localStorage.setItem("did_external_key_id", e)), e;
|
|
6
106
|
}
|
|
7
|
-
let
|
|
8
|
-
function
|
|
107
|
+
let Te = q();
|
|
108
|
+
function se(e) {
|
|
9
109
|
if (e.type === "bearer")
|
|
10
110
|
return `Bearer ${e.token}`;
|
|
11
111
|
if (e.type === "basic")
|
|
12
112
|
return `Basic ${btoa(`${e.username}:${e.password}`)}`;
|
|
13
113
|
if (e.type === "key")
|
|
14
|
-
return `Client-Key ${e.clientKey}.${
|
|
114
|
+
return `Client-Key ${e.clientKey}.${ie()}_${Te}`;
|
|
15
115
|
throw new Error(`Unknown auth type: ${e}`);
|
|
16
116
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
117
|
+
const $e = (e) => X(e, {
|
|
118
|
+
limit: 3,
|
|
119
|
+
delayMs: 1e3,
|
|
120
|
+
timeout: 0,
|
|
121
|
+
shouldRetryFn: (t) => t.status === 429
|
|
122
|
+
});
|
|
123
|
+
function Q(e, t = K, a) {
|
|
124
|
+
const n = async (s, i) => {
|
|
125
|
+
const {
|
|
126
|
+
skipErrorHandler: r,
|
|
127
|
+
...o
|
|
128
|
+
} = i || {}, c = await $e(() => fetch(t + (s != null && s.startsWith("/") ? s : `/${s}`), {
|
|
129
|
+
...o,
|
|
21
130
|
headers: {
|
|
22
|
-
...
|
|
23
|
-
Authorization:
|
|
131
|
+
...o.headers,
|
|
132
|
+
Authorization: se(e),
|
|
24
133
|
"Content-Type": "application/json"
|
|
25
134
|
}
|
|
26
|
-
});
|
|
27
|
-
if (!
|
|
28
|
-
let
|
|
29
|
-
|
|
135
|
+
}));
|
|
136
|
+
if (!c.ok) {
|
|
137
|
+
let u = await c.text().catch(() => `Failed to fetch with status ${c.status}`);
|
|
138
|
+
const d = new Error(u);
|
|
139
|
+
throw a && !r && a(d, {
|
|
140
|
+
url: s,
|
|
141
|
+
options: o,
|
|
142
|
+
headers: c.headers
|
|
143
|
+
}), d;
|
|
30
144
|
}
|
|
31
|
-
return
|
|
145
|
+
return c.json();
|
|
32
146
|
};
|
|
33
147
|
return {
|
|
34
|
-
get(
|
|
35
|
-
return n(
|
|
36
|
-
...
|
|
148
|
+
get(s, i) {
|
|
149
|
+
return n(s, {
|
|
150
|
+
...i,
|
|
37
151
|
method: "GET"
|
|
38
152
|
});
|
|
39
153
|
},
|
|
40
|
-
post(
|
|
41
|
-
return n(
|
|
42
|
-
...
|
|
43
|
-
body: JSON.stringify(
|
|
154
|
+
post(s, i, r) {
|
|
155
|
+
return n(s, {
|
|
156
|
+
...r,
|
|
157
|
+
body: JSON.stringify(i),
|
|
44
158
|
method: "POST"
|
|
45
159
|
});
|
|
46
160
|
},
|
|
47
|
-
delete(
|
|
48
|
-
return n(
|
|
49
|
-
...
|
|
50
|
-
body: JSON.stringify(
|
|
161
|
+
delete(s, i, r) {
|
|
162
|
+
return n(s, {
|
|
163
|
+
...r,
|
|
164
|
+
body: JSON.stringify(i),
|
|
51
165
|
method: "DELETE"
|
|
52
166
|
});
|
|
53
167
|
},
|
|
54
|
-
patch(
|
|
55
|
-
return n(
|
|
56
|
-
...
|
|
57
|
-
body: JSON.stringify(
|
|
168
|
+
patch(s, i, r) {
|
|
169
|
+
return n(s, {
|
|
170
|
+
...r,
|
|
171
|
+
body: JSON.stringify(i),
|
|
58
172
|
method: "PATCH"
|
|
59
173
|
});
|
|
60
174
|
}
|
|
61
175
|
};
|
|
62
176
|
}
|
|
63
|
-
function
|
|
64
|
-
const n =
|
|
177
|
+
function oe(e, t = K, a) {
|
|
178
|
+
const n = Q(e, `${t}/agents`, a);
|
|
65
179
|
return {
|
|
66
|
-
create(
|
|
67
|
-
return n.post("/",
|
|
180
|
+
create(s, i) {
|
|
181
|
+
return n.post("/", s, i);
|
|
68
182
|
},
|
|
69
|
-
getAgents(
|
|
70
|
-
return n.get(`/${
|
|
183
|
+
getAgents(s, i) {
|
|
184
|
+
return n.get(`/${s ? `?tag=${s}` : ""}`, i).then((r) => r ?? []);
|
|
71
185
|
},
|
|
72
|
-
getById(
|
|
73
|
-
return n.get(`/${
|
|
186
|
+
getById(s, i) {
|
|
187
|
+
return n.get(`/${s}`, i);
|
|
74
188
|
},
|
|
75
|
-
delete(
|
|
76
|
-
return n.delete(`/${
|
|
189
|
+
delete(s, i) {
|
|
190
|
+
return n.delete(`/${s}`, void 0, i);
|
|
77
191
|
},
|
|
78
|
-
update(
|
|
79
|
-
return n.patch(`/${
|
|
192
|
+
update(s, i, r) {
|
|
193
|
+
return n.patch(`/${s}`, i, r);
|
|
80
194
|
},
|
|
81
|
-
newChat(
|
|
82
|
-
return n.post(`/${
|
|
195
|
+
newChat(s, i, r) {
|
|
196
|
+
return n.post(`/${s}/chat`, i, r);
|
|
83
197
|
},
|
|
84
|
-
chat(
|
|
85
|
-
return n.post(`/${
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
function J(e, a = y) {
|
|
90
|
-
const n = k(e, `${a}/knowledge`);
|
|
91
|
-
return {
|
|
92
|
-
createKnowledge(t, r) {
|
|
93
|
-
return n.post("/", t, r);
|
|
198
|
+
chat(s, i, r, o) {
|
|
199
|
+
return n.post(`/${s}/chat/${i}`, r, o);
|
|
94
200
|
},
|
|
95
|
-
|
|
96
|
-
return n.
|
|
201
|
+
createRating(s, i, r, o) {
|
|
202
|
+
return n.post(`/${s}/chat/${i}/ratings`, r, o);
|
|
97
203
|
},
|
|
98
|
-
|
|
99
|
-
return n.
|
|
204
|
+
updateRating(s, i, r, o, c) {
|
|
205
|
+
return n.patch(`/${s}/chat/${i}/ratings/${r}`, o, c);
|
|
100
206
|
},
|
|
101
|
-
|
|
102
|
-
return n.delete(`/${
|
|
207
|
+
deleteRating(s, i, r, o) {
|
|
208
|
+
return n.delete(`/${s}/chat/${i}/ratings/${r}`, o);
|
|
103
209
|
},
|
|
104
|
-
|
|
105
|
-
return n.
|
|
210
|
+
getSTTToken(s, i) {
|
|
211
|
+
return n.get(`/${s}/stt-token`, i);
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
const Z = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type;
|
|
216
|
+
function Ae(e) {
|
|
217
|
+
var s, i, r, o;
|
|
218
|
+
const t = () => /Mobi|Android/i.test(navigator.userAgent) ? "Mobile" : "Desktop", a = () => {
|
|
219
|
+
const c = navigator.platform;
|
|
220
|
+
return c.toLowerCase().includes("win") ? "Windows" : c.toLowerCase().includes("mac") ? "Mac OS X" : c.toLowerCase().includes("linux") ? "Linux" : "Unknown";
|
|
221
|
+
}, n = e.presenter;
|
|
222
|
+
return {
|
|
223
|
+
$os: `${a()}`,
|
|
224
|
+
isMobile: `${t() == "Mobile"}`,
|
|
225
|
+
browser: navigator.userAgent,
|
|
226
|
+
origin: window.location.origin,
|
|
227
|
+
agentType: Z(n),
|
|
228
|
+
agentVoice: {
|
|
229
|
+
voiceId: (i = (s = e.presenter) == null ? void 0 : s.voice) == null ? void 0 : i.voice_id,
|
|
230
|
+
provider: (o = (r = e.presenter) == null ? void 0 : r.voice) == null ? void 0 : o.type
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
function ze(e, t, a) {
|
|
235
|
+
var c, u, d;
|
|
236
|
+
const {
|
|
237
|
+
event: n,
|
|
238
|
+
...s
|
|
239
|
+
} = e, {
|
|
240
|
+
template: i
|
|
241
|
+
} = (t == null ? void 0 : t.llm) || {}, {
|
|
242
|
+
language: r
|
|
243
|
+
} = ((c = t == null ? void 0 : t.presenter) == null ? void 0 : c.voice) || {};
|
|
244
|
+
return {
|
|
245
|
+
...s,
|
|
246
|
+
llm: {
|
|
247
|
+
...s.llm,
|
|
248
|
+
template: i
|
|
106
249
|
},
|
|
107
|
-
|
|
108
|
-
|
|
250
|
+
script: {
|
|
251
|
+
...s.script,
|
|
252
|
+
provider: {
|
|
253
|
+
...(u = s == null ? void 0 : s.script) == null ? void 0 : u.provider,
|
|
254
|
+
language: r
|
|
255
|
+
}
|
|
109
256
|
},
|
|
110
|
-
|
|
111
|
-
|
|
257
|
+
stitch: (t == null ? void 0 : t.presenter.type) === "talk" ? (d = t == null ? void 0 : t.presenter) == null ? void 0 : d.stitch : void 0,
|
|
258
|
+
...a
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
let V = {};
|
|
262
|
+
const Le = "https://api-js.mixpanel.com/track/?verbose=1&ip=1";
|
|
263
|
+
function je(e) {
|
|
264
|
+
var i, r, o, c, u, d;
|
|
265
|
+
const t = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk", a = e.agent.presenter, n = (i = e.agent.llm) == null ? void 0 : i.prompt_customization, s = {
|
|
266
|
+
token: e.token || "testKey",
|
|
267
|
+
distinct_id: e.distinctId || ie(),
|
|
268
|
+
agentId: e.agent.id,
|
|
269
|
+
agentType: Z(a),
|
|
270
|
+
owner_id: e.agent.owner_id ?? "",
|
|
271
|
+
promptVersion: (r = e.agent.llm) == null ? void 0 : r.prompt_version,
|
|
272
|
+
behavior: {
|
|
273
|
+
role: n == null ? void 0 : n.role,
|
|
274
|
+
personality: n == null ? void 0 : n.personality,
|
|
275
|
+
instructions: (o = e.agent.llm) == null ? void 0 : o.instructions
|
|
112
276
|
},
|
|
113
|
-
|
|
114
|
-
|
|
277
|
+
temperature: (c = e.agent.llm) == null ? void 0 : c.temperature,
|
|
278
|
+
knowledgeSource: n == null ? void 0 : n.knowledge_source,
|
|
279
|
+
starterQuestionsCount: (d = (u = e.agent.knowledge) == null ? void 0 : u.starter_message) == null ? void 0 : d.length,
|
|
280
|
+
topicsToAvoid: n == null ? void 0 : n.topics_to_avoid,
|
|
281
|
+
maxResponseLength: n == null ? void 0 : n.max_response_length
|
|
282
|
+
};
|
|
283
|
+
return {
|
|
284
|
+
...s,
|
|
285
|
+
additionalProperties: {},
|
|
286
|
+
isEnabled: e.isEnabled ?? !0,
|
|
287
|
+
getRandom: () => Math.random().toString(16).slice(2),
|
|
288
|
+
enrich(g) {
|
|
289
|
+
const R = {};
|
|
290
|
+
if (g && typeof g != "object")
|
|
291
|
+
throw new Error("properties must be a flat json object");
|
|
292
|
+
for (let h in g)
|
|
293
|
+
(typeof g[h] == "string" || typeof g[h] == "number") && (R[h] = g[h]);
|
|
294
|
+
this.additionalProperties = {
|
|
295
|
+
...this.additionalProperties,
|
|
296
|
+
...R
|
|
297
|
+
};
|
|
115
298
|
},
|
|
116
|
-
|
|
117
|
-
|
|
299
|
+
async track(g, R) {
|
|
300
|
+
if (!this.isEnabled)
|
|
301
|
+
return Promise.resolve();
|
|
302
|
+
const {
|
|
303
|
+
audioPath: h,
|
|
304
|
+
...y
|
|
305
|
+
} = R || {}, v = {
|
|
306
|
+
method: "POST",
|
|
307
|
+
headers: {
|
|
308
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
309
|
+
},
|
|
310
|
+
body: new URLSearchParams({
|
|
311
|
+
data: JSON.stringify([{
|
|
312
|
+
event: g,
|
|
313
|
+
properties: {
|
|
314
|
+
...this.additionalProperties,
|
|
315
|
+
...y,
|
|
316
|
+
...s,
|
|
317
|
+
source: t,
|
|
318
|
+
time: Date.now(),
|
|
319
|
+
$insert_id: this.getRandom(),
|
|
320
|
+
origin: window.location.href,
|
|
321
|
+
"Screen Height": window.screen.height || window.innerWidth,
|
|
322
|
+
"Screen Width": window.screen.width || window.innerHeight,
|
|
323
|
+
"User Agent": navigator.userAgent
|
|
324
|
+
}
|
|
325
|
+
}])
|
|
326
|
+
})
|
|
327
|
+
};
|
|
328
|
+
try {
|
|
329
|
+
return await fetch(Le, v).then((C) => C.json());
|
|
330
|
+
} catch (C) {
|
|
331
|
+
return console.error(C);
|
|
332
|
+
}
|
|
118
333
|
},
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
334
|
+
linkTrack(g, R, h, y) {
|
|
335
|
+
V[g] || (V[g] = {
|
|
336
|
+
events: {},
|
|
337
|
+
resolvedDependencies: []
|
|
338
|
+
}), y.includes(h) || y.push(h);
|
|
339
|
+
const v = V[g];
|
|
340
|
+
if (v.events[h] = {
|
|
341
|
+
props: R
|
|
342
|
+
}, v.resolvedDependencies.push(h), y.every((A) => v.resolvedDependencies.includes(A))) {
|
|
343
|
+
const A = y.reduce((I, l) => v.events[l] ? {
|
|
344
|
+
...I,
|
|
345
|
+
...v.events[l].props
|
|
346
|
+
} : I, {});
|
|
347
|
+
this.track(g, A), v.resolvedDependencies = v.resolvedDependencies.filter((I) => !y.includes(I)), y.forEach((I) => {
|
|
348
|
+
delete v.events[I];
|
|
349
|
+
});
|
|
350
|
+
}
|
|
123
351
|
}
|
|
124
352
|
};
|
|
125
353
|
}
|
|
126
|
-
function
|
|
127
|
-
|
|
354
|
+
function xe() {
|
|
355
|
+
let e = 0;
|
|
128
356
|
return {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
getByKnowledge(t, r) {
|
|
133
|
-
return n.get(`/${t}`, r).then((i) => i ?? []);
|
|
134
|
-
},
|
|
135
|
-
update(t, r, i) {
|
|
136
|
-
return n.patch(`/${t}`, r, i);
|
|
137
|
-
},
|
|
138
|
-
delete(t, r) {
|
|
139
|
-
return n.delete(`/${t}`, r);
|
|
140
|
-
}
|
|
357
|
+
reset: () => e = 0,
|
|
358
|
+
update: () => e = Date.now(),
|
|
359
|
+
get: (t = !1) => t ? Date.now() - e : e
|
|
141
360
|
};
|
|
142
361
|
}
|
|
143
|
-
const
|
|
144
|
-
function
|
|
145
|
-
return
|
|
362
|
+
const N = xe();
|
|
363
|
+
function ce(e) {
|
|
364
|
+
return e === b.Playground ? {
|
|
365
|
+
headers: {
|
|
366
|
+
[Ee]: "true"
|
|
367
|
+
}
|
|
368
|
+
} : {};
|
|
369
|
+
}
|
|
370
|
+
async function de(e, t, a, n, s = !1, i) {
|
|
371
|
+
try {
|
|
372
|
+
return !i && n !== b.DirectPlayback && (i = await t.newChat(e.id, {
|
|
373
|
+
persist: s
|
|
374
|
+
}, ce(n)), a.track("agent-chat", {
|
|
375
|
+
event: "created",
|
|
376
|
+
chat_id: i.id,
|
|
377
|
+
agent_id: e.id,
|
|
378
|
+
mode: n
|
|
379
|
+
})), {
|
|
380
|
+
chat: i,
|
|
381
|
+
chatMode: (i == null ? void 0 : i.chat_mode) ?? n
|
|
382
|
+
};
|
|
383
|
+
} catch (r) {
|
|
384
|
+
try {
|
|
385
|
+
const o = JSON.parse(r.message);
|
|
386
|
+
if ((o == null ? void 0 : o.kind) === "InsufficientCreditsError")
|
|
387
|
+
throw new Error("InsufficientCreditsError");
|
|
388
|
+
} catch (o) {
|
|
389
|
+
console.error("Error parsing the error message:", o);
|
|
390
|
+
}
|
|
391
|
+
throw new Error("Cannot create new chat");
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
function Ne(e) {
|
|
395
|
+
var a;
|
|
396
|
+
const t = ((a = e.greetings) == null ? void 0 : a.filter((n) => n.length > 0)) ?? [];
|
|
397
|
+
return t.length > 0 ? t[Math.floor(Math.random() * t.length)] : `Hi! I'm ${e.preview_name || "My Agent"}. How can I help you?`;
|
|
398
|
+
}
|
|
399
|
+
function ee(e, t) {
|
|
400
|
+
return t && t.length > 0 ? t : [{
|
|
401
|
+
content: e,
|
|
402
|
+
id: q(),
|
|
403
|
+
role: "assistant",
|
|
404
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
405
|
+
}];
|
|
406
|
+
}
|
|
407
|
+
function Be(e) {
|
|
408
|
+
return new Promise((t, a) => {
|
|
146
409
|
const {
|
|
147
|
-
callbacks:
|
|
148
|
-
host:
|
|
410
|
+
callbacks: n,
|
|
411
|
+
host: s,
|
|
149
412
|
auth: i
|
|
150
413
|
} = e, {
|
|
151
|
-
onMessage:
|
|
152
|
-
onOpen:
|
|
153
|
-
onClose:
|
|
154
|
-
onError:
|
|
155
|
-
} =
|
|
156
|
-
|
|
157
|
-
console.error(
|
|
158
|
-
},
|
|
159
|
-
|
|
414
|
+
onMessage: r = null,
|
|
415
|
+
onOpen: o = null,
|
|
416
|
+
onClose: c = null,
|
|
417
|
+
onError: u = null
|
|
418
|
+
} = n || {}, d = new WebSocket(`${s}?authorization=${se(i)}`);
|
|
419
|
+
d.onmessage = r, d.onclose = c, d.onerror = (g) => {
|
|
420
|
+
console.error(g), u == null || u("Websocket failed to connect", g), a(g);
|
|
421
|
+
}, d.onopen = (g) => {
|
|
422
|
+
o == null || o(g), t(d);
|
|
160
423
|
};
|
|
161
424
|
});
|
|
162
425
|
}
|
|
163
|
-
async function
|
|
426
|
+
async function Fe(e) {
|
|
164
427
|
const {
|
|
165
|
-
retries:
|
|
428
|
+
retries: t = 1
|
|
166
429
|
} = e;
|
|
167
|
-
let
|
|
168
|
-
for (let
|
|
430
|
+
let a = null;
|
|
431
|
+
for (let n = 0; (a == null ? void 0 : a.readyState) !== WebSocket.OPEN; n++)
|
|
169
432
|
try {
|
|
170
|
-
|
|
171
|
-
} catch (
|
|
172
|
-
if (
|
|
173
|
-
throw
|
|
174
|
-
await
|
|
433
|
+
a = await Be(e);
|
|
434
|
+
} catch (s) {
|
|
435
|
+
if (n === t)
|
|
436
|
+
throw s;
|
|
437
|
+
await ae(n * 500);
|
|
175
438
|
}
|
|
176
|
-
return
|
|
439
|
+
return a;
|
|
177
440
|
}
|
|
178
|
-
async function
|
|
179
|
-
const
|
|
441
|
+
async function We(e, t, a) {
|
|
442
|
+
const n = a != null && a.onMessage ? [a.onMessage] : [], s = await Fe({
|
|
180
443
|
auth: e,
|
|
181
|
-
host:
|
|
444
|
+
host: t,
|
|
182
445
|
callbacks: {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
446
|
+
onError: (i) => {
|
|
447
|
+
var r;
|
|
448
|
+
return (r = a.onError) == null ? void 0 : r.call(a, new he(i));
|
|
449
|
+
},
|
|
450
|
+
onMessage(i) {
|
|
451
|
+
const r = JSON.parse(i.data);
|
|
452
|
+
n.forEach((o) => o(r.event, r));
|
|
186
453
|
}
|
|
187
454
|
}
|
|
188
455
|
});
|
|
189
456
|
return {
|
|
190
|
-
socket:
|
|
191
|
-
disconnect: () =>
|
|
192
|
-
subscribeToEvents: (i) =>
|
|
457
|
+
socket: s,
|
|
458
|
+
disconnect: () => s.close(),
|
|
459
|
+
subscribeToEvents: (i) => n.push(i)
|
|
193
460
|
};
|
|
194
461
|
}
|
|
195
|
-
function
|
|
196
|
-
|
|
462
|
+
function He(e) {
|
|
463
|
+
if (e.answer !== void 0)
|
|
464
|
+
return e.answer;
|
|
465
|
+
let t = 0, a = "";
|
|
466
|
+
for (; t in e; )
|
|
467
|
+
a += e[t++];
|
|
468
|
+
return a;
|
|
469
|
+
}
|
|
470
|
+
function Ke(e, t, a, n, s) {
|
|
471
|
+
const i = n.messages[n.messages.length - 1];
|
|
472
|
+
if (!(e === F.Partial || e === F.Answer) || (i == null ? void 0 : i.role) !== "assistant")
|
|
473
|
+
return;
|
|
474
|
+
const {
|
|
475
|
+
content: r,
|
|
476
|
+
sequence: o
|
|
477
|
+
} = t;
|
|
478
|
+
e === F.Partial ? a[o] = r : a.answer = r;
|
|
479
|
+
const c = He(a);
|
|
480
|
+
(i.content !== c || e === F.Answer) && (i.content = c, s == null || s([...n.messages], e));
|
|
481
|
+
}
|
|
482
|
+
function Ue(e, t, a, n, s) {
|
|
483
|
+
let i = {};
|
|
197
484
|
return {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
485
|
+
clearQueue: () => i = {},
|
|
486
|
+
onMessage: (r, o) => {
|
|
487
|
+
var c, u;
|
|
488
|
+
if ("content" in o)
|
|
489
|
+
Ke(r, o, i, t, a.callbacks.onNewMessage), r === F.Answer && e.track("agent-message-received", {
|
|
490
|
+
messages: t.messages.length,
|
|
491
|
+
mode: t.chatMode
|
|
492
|
+
});
|
|
493
|
+
else {
|
|
494
|
+
const d = U, g = [d.StreamVideoDone, d.StreamVideoError, d.StreamVideoRejected], R = [d.StreamFailed, d.StreamVideoError, d.StreamVideoRejected], h = ze(o, n, {
|
|
495
|
+
mode: t.chatMode
|
|
496
|
+
});
|
|
497
|
+
if (r = r, r === d.StreamVideoCreated)
|
|
498
|
+
e.linkTrack("agent-video", h, d.StreamVideoCreated, ["start"]);
|
|
499
|
+
else if (g.includes(r)) {
|
|
500
|
+
const y = r.split("/")[1];
|
|
501
|
+
R.includes(r) ? e.track("agent-video", {
|
|
502
|
+
...h,
|
|
503
|
+
event: y
|
|
504
|
+
}) : e.linkTrack("agent-video", {
|
|
505
|
+
...h,
|
|
506
|
+
event: y
|
|
507
|
+
}, r, ["done"]);
|
|
508
|
+
}
|
|
509
|
+
R.includes(r) && ((u = (c = a.callbacks).onError) == null || u.call(c, new Error(`Stream failed with event ${r}`), {
|
|
510
|
+
data: o
|
|
511
|
+
})), o.event === d.StreamDone && s();
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
function qe(e, t, a, n) {
|
|
517
|
+
const s = Q(e, `${t}/agents/${a}`, n);
|
|
518
|
+
return {
|
|
519
|
+
createStream(i) {
|
|
520
|
+
return s.post("/streams", {
|
|
521
|
+
output_resolution: i.output_resolution,
|
|
522
|
+
compatibility_mode: i.compatibility_mode,
|
|
523
|
+
stream_warmup: i.stream_warmup,
|
|
524
|
+
session_timeout: i.session_timeout,
|
|
525
|
+
stream_greeting: i.stream_greeting
|
|
204
526
|
});
|
|
205
527
|
},
|
|
206
|
-
startConnection(
|
|
207
|
-
return
|
|
208
|
-
session_id:
|
|
528
|
+
startConnection(i, r, o) {
|
|
529
|
+
return s.post(`/streams/${i}/sdp`, {
|
|
530
|
+
session_id: o,
|
|
209
531
|
answer: r
|
|
210
532
|
});
|
|
211
533
|
},
|
|
212
|
-
addIceCandidate(
|
|
213
|
-
return
|
|
214
|
-
session_id:
|
|
534
|
+
addIceCandidate(i, r, o) {
|
|
535
|
+
return s.post(`/streams/${i}/ice`, {
|
|
536
|
+
session_id: o,
|
|
215
537
|
...r
|
|
216
538
|
});
|
|
217
539
|
},
|
|
218
|
-
sendStreamRequest(
|
|
219
|
-
return
|
|
540
|
+
sendStreamRequest(i, r, o) {
|
|
541
|
+
return s.post(`/streams/${i}`, {
|
|
220
542
|
session_id: r,
|
|
221
|
-
...
|
|
543
|
+
...o
|
|
222
544
|
});
|
|
223
545
|
},
|
|
224
|
-
close(
|
|
225
|
-
return
|
|
546
|
+
close(i, r) {
|
|
547
|
+
return s.delete(`/streams/${i}`, {
|
|
226
548
|
session_id: r
|
|
227
549
|
});
|
|
228
550
|
}
|
|
229
551
|
};
|
|
230
552
|
}
|
|
231
|
-
function
|
|
232
|
-
const
|
|
553
|
+
function Je(e, t, a, n) {
|
|
554
|
+
const s = Q(e, `${t}/agents/${a}`, n);
|
|
233
555
|
return {
|
|
234
|
-
createStream(
|
|
235
|
-
return
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
556
|
+
createStream(i, r) {
|
|
557
|
+
return s.post("/streams", {
|
|
558
|
+
driver_url: i.driver_url,
|
|
559
|
+
face: i.face,
|
|
560
|
+
config: i.config,
|
|
561
|
+
output_resolution: i.output_resolution,
|
|
562
|
+
compatibility_mode: i.compatibility_mode,
|
|
563
|
+
stream_warmup: i.stream_warmup,
|
|
564
|
+
session_timeout: i.session_timeout,
|
|
565
|
+
stream_greeting: i.stream_greeting
|
|
240
566
|
}, r);
|
|
241
567
|
},
|
|
242
|
-
startConnection(
|
|
243
|
-
return
|
|
244
|
-
session_id:
|
|
568
|
+
startConnection(i, r, o, c) {
|
|
569
|
+
return s.post(`/streams/${i}/sdp`, {
|
|
570
|
+
session_id: o,
|
|
245
571
|
answer: r
|
|
246
|
-
},
|
|
572
|
+
}, c);
|
|
247
573
|
},
|
|
248
|
-
addIceCandidate(
|
|
249
|
-
return
|
|
250
|
-
session_id:
|
|
574
|
+
addIceCandidate(i, r, o, c) {
|
|
575
|
+
return s.post(`/streams/${i}/ice`, {
|
|
576
|
+
session_id: o,
|
|
251
577
|
...r
|
|
252
|
-
},
|
|
578
|
+
}, c);
|
|
253
579
|
},
|
|
254
|
-
sendStreamRequest(
|
|
255
|
-
return
|
|
580
|
+
sendStreamRequest(i, r, o, c) {
|
|
581
|
+
return s.post(`/streams/${i}`, {
|
|
256
582
|
session_id: r,
|
|
257
|
-
...
|
|
258
|
-
},
|
|
583
|
+
...o
|
|
584
|
+
}, c);
|
|
259
585
|
},
|
|
260
|
-
close(
|
|
261
|
-
return
|
|
586
|
+
close(i, r, o) {
|
|
587
|
+
return s.delete(`/streams/${i}`, {
|
|
262
588
|
session_id: r
|
|
263
|
-
},
|
|
589
|
+
}, o);
|
|
264
590
|
}
|
|
265
591
|
};
|
|
266
592
|
}
|
|
267
|
-
function
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
bytesReceived:
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
593
|
+
function Ve(e, t, a) {
|
|
594
|
+
const n = (t.timestamp - e.timestamp) / 1e3;
|
|
595
|
+
return {
|
|
596
|
+
duration: n,
|
|
597
|
+
bytesReceived: t.bytesReceived - e.bytesReceived,
|
|
598
|
+
bitrate: Math.round((t.bytesReceived - e.bytesReceived) * 8 / n),
|
|
599
|
+
packetsReceived: t.packetsReceived - e.packetsReceived,
|
|
600
|
+
packetsLost: t.packetsLost - e.packetsLost,
|
|
601
|
+
framesDropped: t.framesDropped - e.framesDropped,
|
|
602
|
+
framesDecoded: t.framesDecoded - e.framesDecoded,
|
|
603
|
+
jitter: t.jitter,
|
|
604
|
+
jitterBufferDelay: (t.jitterBufferDelay - e.jitterBufferDelay) / n,
|
|
605
|
+
framesPerSecond: t.framesPerSecond,
|
|
606
|
+
freezeCount: t.freezeCount - e.freezeCount,
|
|
607
|
+
freezeDuration: t.freezeDuration - e.freezeDuration,
|
|
608
|
+
lowFpsCount: a
|
|
609
|
+
};
|
|
610
|
+
}
|
|
611
|
+
function Xe(e) {
|
|
612
|
+
return e.filter((t) => t.freezeCount > 0 || t.framesPerSecond < 21 || t.framesDropped > 0 || t.packetsLost > 0).map((t) => {
|
|
613
|
+
const {
|
|
614
|
+
timestamp: a,
|
|
615
|
+
...n
|
|
616
|
+
} = t, s = [];
|
|
617
|
+
return t.freezeCount > 0 && s.push("freeze"), t.framesPerSecond < 21 && s.push("low fps"), t.framesDropped > 0 && s.push("frames dropped"), t.packetsLost > 0 && s.push("packet loss"), {
|
|
618
|
+
...n,
|
|
619
|
+
causes: s
|
|
620
|
+
};
|
|
621
|
+
});
|
|
622
|
+
}
|
|
623
|
+
function Ye(e) {
|
|
624
|
+
let t = "";
|
|
625
|
+
for (const a of e.values())
|
|
626
|
+
if (a && a.type === "codec" && a.mimeType.startsWith("video") && (t = a.mimeType.split("/")[1]), a && a.type === "inbound-rtp" && a.kind === "video")
|
|
627
|
+
return {
|
|
628
|
+
codec: t,
|
|
629
|
+
timestamp: a.timestamp,
|
|
630
|
+
bytesReceived: a.bytesReceived,
|
|
631
|
+
packetsReceived: a.packetsReceived,
|
|
632
|
+
packetsLost: a.packetsLost,
|
|
633
|
+
framesDropped: a.framesDropped,
|
|
634
|
+
framesDecoded: a.framesDecoded,
|
|
635
|
+
jitter: a.jitter,
|
|
636
|
+
jitterBufferDelay: a.jitterBufferDelay,
|
|
637
|
+
frameWidth: a.frameWidth,
|
|
638
|
+
frameHeight: a.frameHeight,
|
|
639
|
+
framesPerSecond: a.framesPerSecond,
|
|
640
|
+
freezeCount: a.freezeCount,
|
|
641
|
+
freezeDuration: a.totalFreezesDuration
|
|
642
|
+
};
|
|
643
|
+
return {};
|
|
644
|
+
}
|
|
645
|
+
function Qe(e, t, a) {
|
|
646
|
+
const n = e.map((r, o) => o === 0 ? a ? {
|
|
647
|
+
timestamp: r.timestamp,
|
|
648
|
+
duration: 0,
|
|
649
|
+
bytesReceived: r.bytesReceived - a.bytesReceived,
|
|
650
|
+
bitrate: (r.bytesReceived - a.bytesReceived) * 8 / (t / 1e3),
|
|
651
|
+
packetsReceived: r.packetsReceived - a.packetsReceived,
|
|
652
|
+
packetsLost: r.packetsLost - a.packetsLost,
|
|
653
|
+
framesDropped: r.framesDropped - a.framesDropped,
|
|
654
|
+
framesDecoded: r.framesDecoded - a.framesDecoded,
|
|
655
|
+
jitter: r.jitter,
|
|
656
|
+
jitterBufferDelay: r.jitterBufferDelay - a.jitterBufferDelay,
|
|
657
|
+
framesPerSecond: r.framesPerSecond,
|
|
658
|
+
freezeCount: r.freezeCount - a.freezeCount,
|
|
659
|
+
freezeDuration: r.freezeDuration - a.freezeDuration
|
|
278
660
|
} : {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
bytesReceived:
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
661
|
+
timestamp: r.timestamp,
|
|
662
|
+
duration: 0,
|
|
663
|
+
bytesReceived: r.bytesReceived,
|
|
664
|
+
bitrate: r.bytesReceived * 8 / (t / 1e3),
|
|
665
|
+
packetsReceived: r.packetsReceived,
|
|
666
|
+
packetsLost: r.packetsLost,
|
|
667
|
+
framesDropped: r.framesDropped,
|
|
668
|
+
framesDecoded: r.framesDecoded,
|
|
669
|
+
jitter: r.jitter,
|
|
670
|
+
jitterBufferDelay: r.jitterBufferDelay,
|
|
671
|
+
framesPerSecond: r.framesPerSecond,
|
|
672
|
+
freezeCount: r.freezeCount,
|
|
673
|
+
freezeDuration: r.freezeDuration
|
|
288
674
|
} : {
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
bytesReceived:
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
675
|
+
timestamp: r.timestamp,
|
|
676
|
+
duration: t * o / 1e3,
|
|
677
|
+
bytesReceived: r.bytesReceived - e[o - 1].bytesReceived,
|
|
678
|
+
bitrate: (r.bytesReceived - e[o - 1].bytesReceived) * 8 / (t / 1e3),
|
|
679
|
+
packetsReceived: r.packetsReceived - e[o - 1].packetsReceived,
|
|
680
|
+
packetsLost: r.packetsLost - e[o - 1].packetsLost,
|
|
681
|
+
framesDropped: r.framesDropped - e[o - 1].framesDropped,
|
|
682
|
+
framesDecoded: r.framesDecoded - e[o - 1].framesDecoded,
|
|
683
|
+
jitter: r.jitter,
|
|
684
|
+
jitterBufferDelay: r.jitterBufferDelay - e[o - 1].jitterBufferDelay,
|
|
685
|
+
framesPerSecond: r.framesPerSecond,
|
|
686
|
+
freezeCount: r.freezeCount - e[o - 1].freezeCount,
|
|
687
|
+
freezeDuration: r.freezeDuration - e[o - 1].freezeDuration
|
|
688
|
+
}), s = Xe(n), i = s.reduce((r, o) => r + (o.causes.includes("low fps") ? 1 : 0), 0);
|
|
689
|
+
return {
|
|
690
|
+
webRTCStats: {
|
|
691
|
+
anomalies: s,
|
|
692
|
+
aggregateReport: Ve(e[0], e[e.length - 1], i)
|
|
693
|
+
},
|
|
694
|
+
codec: e[0].codec,
|
|
695
|
+
resolution: `${e[0].frameWidth}x${e[0].frameHeight}`
|
|
696
|
+
};
|
|
299
697
|
}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
});
|
|
326
|
-
});
|
|
327
|
-
}, 500);
|
|
698
|
+
const Y = 200, Ze = Math.max(Math.ceil(400 / Y), 1);
|
|
699
|
+
function Ge() {
|
|
700
|
+
let e = 0;
|
|
701
|
+
return (t) => {
|
|
702
|
+
for (const a of t.values())
|
|
703
|
+
if (a && a.type === "inbound-rtp" && a.kind === "video") {
|
|
704
|
+
const n = a.bytesReceived, s = n - e > 0;
|
|
705
|
+
return e = n, s;
|
|
706
|
+
}
|
|
707
|
+
return !1;
|
|
708
|
+
};
|
|
709
|
+
}
|
|
710
|
+
function Oe(e, t, a, n, s = !1, i = !1) {
|
|
711
|
+
const r = s ? 1 : 0;
|
|
712
|
+
let o = [], c, u = 0, d = !1, g = 0;
|
|
713
|
+
const R = Ge();
|
|
714
|
+
return setInterval(async () => {
|
|
715
|
+
const h = await e.getStats(), y = R(h), v = Ye(h);
|
|
716
|
+
if (y)
|
|
717
|
+
u = 0, d || (n == null || n(D.Start), i && g >= r && !t() && a(), c = o[o.length - 1], o = [], g++, d = !0), o.push(v);
|
|
718
|
+
else if (d && (u++, u >= Ze)) {
|
|
719
|
+
const C = Qe(o, Y, c);
|
|
720
|
+
n == null || n(D.Stop, C), !i && !t() && a(), d = !1;
|
|
721
|
+
}
|
|
722
|
+
}, Y);
|
|
328
723
|
}
|
|
329
|
-
|
|
724
|
+
let le = !1;
|
|
725
|
+
const L = (e, t) => le && console.log(e, t), et = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
|
|
726
|
+
function te(e) {
|
|
727
|
+
switch (e) {
|
|
728
|
+
case "connected":
|
|
729
|
+
return S.Connected;
|
|
730
|
+
case "checking":
|
|
731
|
+
return S.Connecting;
|
|
732
|
+
case "failed":
|
|
733
|
+
return S.Fail;
|
|
734
|
+
case "new":
|
|
735
|
+
return S.New;
|
|
736
|
+
case "closed":
|
|
737
|
+
return S.Closed;
|
|
738
|
+
case "disconnected":
|
|
739
|
+
return S.Disconnected;
|
|
740
|
+
case "completed":
|
|
741
|
+
return S.Completed;
|
|
742
|
+
default:
|
|
743
|
+
return S.New;
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
function re(e, t, a, n) {
|
|
747
|
+
e === D.Start && t === D.Start ? a == null || a(D.Start) : e === D.Stop && t === D.Stop && (a == null || a(D.Stop, n));
|
|
748
|
+
}
|
|
749
|
+
async function tt(e, t, {
|
|
330
750
|
debug: a = !1,
|
|
331
751
|
callbacks: n,
|
|
332
|
-
auth:
|
|
333
|
-
baseURL:
|
|
752
|
+
auth: s,
|
|
753
|
+
baseURL: i = K,
|
|
754
|
+
warmup: r
|
|
334
755
|
}) {
|
|
335
|
-
|
|
756
|
+
le = a;
|
|
757
|
+
let o = !1, c = !1, u = D.Stop, d = D.Stop;
|
|
336
758
|
const {
|
|
337
|
-
startConnection:
|
|
338
|
-
sendStreamRequest:
|
|
339
|
-
close:
|
|
340
|
-
createStream:
|
|
341
|
-
addIceCandidate:
|
|
342
|
-
} =
|
|
343
|
-
id:
|
|
344
|
-
offer:
|
|
345
|
-
ice_servers:
|
|
346
|
-
session_id:
|
|
347
|
-
} = await
|
|
348
|
-
iceServers:
|
|
349
|
-
}),
|
|
350
|
-
if (!
|
|
759
|
+
startConnection: g,
|
|
760
|
+
sendStreamRequest: R,
|
|
761
|
+
close: h,
|
|
762
|
+
createStream: y,
|
|
763
|
+
addIceCandidate: v
|
|
764
|
+
} = t.videoType === ne.Clip ? qe(s, i, e, n.onError) : Je(s, i, e, n.onError), {
|
|
765
|
+
id: C,
|
|
766
|
+
offer: A,
|
|
767
|
+
ice_servers: I,
|
|
768
|
+
session_id: l
|
|
769
|
+
} = await y(t), m = new et({
|
|
770
|
+
iceServers: I
|
|
771
|
+
}), k = m.createDataChannel("JanusDataChannel");
|
|
772
|
+
if (!l)
|
|
351
773
|
throw new Error("Could not create session_id");
|
|
352
|
-
const
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
data: $
|
|
372
|
-
}), clearInterval(S), console.log("StreamFailed")) : (R = n.onMessage) == null || R.call(n, h, decodeURIComponent($));
|
|
774
|
+
const P = () => o, T = () => {
|
|
775
|
+
var f;
|
|
776
|
+
o = !0, c && ((f = n.onConnectionStateChange) == null || f.call(n, S.Connected));
|
|
777
|
+
}, _ = Oe(m, P, T, (f, w) => re(d = f, u, n.onVideoStateChange, w), r, !!t.stream_greeting);
|
|
778
|
+
m.onicecandidate = (f) => {
|
|
779
|
+
var w;
|
|
780
|
+
L("peerConnection.onicecandidate", f);
|
|
781
|
+
try {
|
|
782
|
+
f.candidate && f.candidate.sdpMid && f.candidate.sdpMLineIndex !== null ? v(C, {
|
|
783
|
+
candidate: f.candidate.candidate,
|
|
784
|
+
sdpMid: f.candidate.sdpMid,
|
|
785
|
+
sdpMLineIndex: f.candidate.sdpMLineIndex
|
|
786
|
+
}, l) : v(C, {
|
|
787
|
+
candidate: null
|
|
788
|
+
}, l);
|
|
789
|
+
} catch (p) {
|
|
790
|
+
(w = n.onError) == null || w.call(n, p, {
|
|
791
|
+
streamId: C
|
|
792
|
+
});
|
|
373
793
|
}
|
|
374
|
-
},
|
|
375
|
-
|
|
376
|
-
|
|
794
|
+
}, k.onopen = () => {
|
|
795
|
+
c = !0, (!t.stream_warmup && !t.stream_greeting || o) && T();
|
|
796
|
+
}, k.onmessage = (f) => {
|
|
797
|
+
f.data === "stream/started" ? u = D.Start : f.data === "stream/done" && (u = D.Stop), re(d, u, n.onVideoStateChange);
|
|
798
|
+
}, m.oniceconnectionstatechange = () => {
|
|
799
|
+
var w;
|
|
800
|
+
L("peerConnection.oniceconnectionstatechange => " + m.iceConnectionState);
|
|
801
|
+
const f = te(m.iceConnectionState);
|
|
802
|
+
f !== S.Connected && ((w = n.onConnectionStateChange) == null || w.call(n, f));
|
|
803
|
+
}, m.ontrack = (f) => {
|
|
804
|
+
var w;
|
|
805
|
+
L("peerConnection.ontrack", f), (w = n.onSrcObjectReady) == null || w.call(n, f.streams[0]);
|
|
806
|
+
}, await m.setRemoteDescription(A), L("set remote description OK");
|
|
807
|
+
const $ = await m.createAnswer();
|
|
808
|
+
return L("create answer OK"), await m.setLocalDescription($), L("set local description OK"), await g(C, $, l), L("start connection OK"), {
|
|
377
809
|
/**
|
|
378
810
|
* Method to send request to server to get clip or talk depend on you payload
|
|
379
811
|
* @param payload
|
|
380
812
|
*/
|
|
381
|
-
speak(
|
|
382
|
-
return
|
|
813
|
+
speak(f) {
|
|
814
|
+
return R(C, l, f);
|
|
383
815
|
},
|
|
384
816
|
/**
|
|
385
817
|
* Method to close RTC connection
|
|
386
818
|
*/
|
|
387
819
|
async disconnect() {
|
|
388
|
-
var
|
|
389
|
-
|
|
390
|
-
|
|
820
|
+
var f, w;
|
|
821
|
+
if (C) {
|
|
822
|
+
const p = te(m.iceConnectionState);
|
|
823
|
+
if (m) {
|
|
824
|
+
if (p === S.New) {
|
|
825
|
+
(f = n.onVideoStateChange) == null || f.call(n, D.Stop), clearInterval(_);
|
|
826
|
+
return;
|
|
827
|
+
}
|
|
828
|
+
m.close(), m.oniceconnectionstatechange = null, m.onnegotiationneeded = null, m.onicecandidate = null, m.ontrack = null;
|
|
829
|
+
}
|
|
830
|
+
try {
|
|
831
|
+
p === S.Connected && await h(C, l).catch((M) => {
|
|
832
|
+
});
|
|
833
|
+
} catch (M) {
|
|
834
|
+
L("Error on close stream connection", M);
|
|
835
|
+
}
|
|
836
|
+
(w = n.onVideoStateChange) == null || w.call(n, D.Stop), clearInterval(_);
|
|
837
|
+
}
|
|
391
838
|
},
|
|
392
839
|
/**
|
|
393
840
|
* Session identifier information, should be returned in the body of all streaming requests
|
|
394
841
|
*/
|
|
395
|
-
sessionId:
|
|
842
|
+
sessionId: l,
|
|
396
843
|
/**
|
|
397
844
|
* Id of current RTC stream
|
|
398
845
|
*/
|
|
399
|
-
streamId:
|
|
846
|
+
streamId: C
|
|
400
847
|
};
|
|
401
848
|
}
|
|
402
|
-
function
|
|
403
|
-
var
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
videoType: I.Talk,
|
|
415
|
-
source_url: e.presenter.source_url
|
|
849
|
+
function rt(e, t, a) {
|
|
850
|
+
var s;
|
|
851
|
+
const {
|
|
852
|
+
streamOptions: n
|
|
853
|
+
} = t ?? {};
|
|
854
|
+
return {
|
|
855
|
+
videoType: Se(e.presenter.type),
|
|
856
|
+
output_resolution: n == null ? void 0 : n.outputResolution,
|
|
857
|
+
session_timeout: n == null ? void 0 : n.sessionTimeout,
|
|
858
|
+
stream_warmup: n == null ? void 0 : n.streamWarmup,
|
|
859
|
+
compatibility_mode: n == null ? void 0 : n.compatibilityMode,
|
|
860
|
+
stream_greeting: Z(e.presenter) !== "clip" && ((s = t == null ? void 0 : t.streamOptions) != null && s.streamGreeting) ? a : void 0
|
|
416
861
|
};
|
|
417
862
|
}
|
|
418
|
-
function
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
863
|
+
function nt(e, t, a, n) {
|
|
864
|
+
N.get() > 0 && (e === D.Start ? n.linkTrack("agent-video", {
|
|
865
|
+
event: "start",
|
|
866
|
+
latency: N.get(!0)
|
|
867
|
+
}, "start", [U.StreamVideoCreated]) : e === D.Stop && n.linkTrack("agent-video", {
|
|
868
|
+
event: "stop",
|
|
869
|
+
is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
|
|
870
|
+
background: t.presenter.type === "clip" && t.presenter.background,
|
|
871
|
+
...a
|
|
872
|
+
}, "done", [U.StreamVideoDone]));
|
|
873
|
+
}
|
|
874
|
+
function at(e, t, a, n) {
|
|
875
|
+
return N.reset(), new Promise(async (s, i) => {
|
|
876
|
+
var r;
|
|
877
|
+
try {
|
|
878
|
+
const o = await tt(e.id, rt(e, t, n), {
|
|
879
|
+
...t,
|
|
880
|
+
analytics: a,
|
|
881
|
+
warmup: (r = t.streamOptions) == null ? void 0 : r.streamWarmup,
|
|
882
|
+
callbacks: {
|
|
883
|
+
...t.callbacks,
|
|
884
|
+
onConnectionStateChange: (c) => {
|
|
885
|
+
var u, d;
|
|
886
|
+
(d = (u = t.callbacks).onConnectionStateChange) == null || d.call(u, c), c === S.Connected && s(o);
|
|
887
|
+
},
|
|
888
|
+
onVideoStateChange: (c, u) => {
|
|
889
|
+
var d, g;
|
|
890
|
+
(g = (d = t.callbacks).onVideoStateChange) == null || g.call(d, c), nt(c, e, u, a);
|
|
891
|
+
}
|
|
438
892
|
}
|
|
439
|
-
}
|
|
440
|
-
})
|
|
893
|
+
});
|
|
894
|
+
} catch (o) {
|
|
895
|
+
i(o);
|
|
896
|
+
}
|
|
441
897
|
});
|
|
442
898
|
}
|
|
443
|
-
function
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
(
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
} = await L(o, a, i);
|
|
455
|
-
const v = await ae(o, g);
|
|
899
|
+
async function it(e, t, a, n, s, i) {
|
|
900
|
+
var u, d, g, R;
|
|
901
|
+
const {
|
|
902
|
+
chat: r,
|
|
903
|
+
chatMode: o
|
|
904
|
+
} = await de(e, a, n, t.mode, t.persistentChat, s);
|
|
905
|
+
if (o && o !== t.mode && (t.mode = o, (d = (u = t.callbacks).onModeChange) == null || d.call(u, o), o === b.TextOnly))
|
|
906
|
+
return (R = (g = t.callbacks).onError) == null || R.call(g, new ge(o)), {
|
|
907
|
+
chat: r
|
|
908
|
+
};
|
|
909
|
+
const c = await at(e, t, n, i);
|
|
456
910
|
return {
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
911
|
+
chat: r,
|
|
912
|
+
streamingManager: c
|
|
913
|
+
};
|
|
914
|
+
}
|
|
915
|
+
async function ot(e, t) {
|
|
916
|
+
var C, A, I;
|
|
917
|
+
let a = !0;
|
|
918
|
+
const n = t.mixpanelKey || Ie, s = t.wsURL || be, i = t.baseURL || K, r = {
|
|
919
|
+
messages: [],
|
|
920
|
+
chatMode: t.mode || b.Functional
|
|
921
|
+
}, o = oe(t.auth, i, t.callbacks.onError), c = await o.getById(e), u = Ne(c), d = je({
|
|
922
|
+
token: n,
|
|
923
|
+
agent: c,
|
|
924
|
+
isEnabled: t.enableAnalitics,
|
|
925
|
+
distinctId: t.distinctId
|
|
926
|
+
}), {
|
|
927
|
+
onMessage: g,
|
|
928
|
+
clearQueue: R
|
|
929
|
+
} = Ue(d, r, t, c, () => {
|
|
930
|
+
var l;
|
|
931
|
+
return (l = r.socketManager) == null ? void 0 : l.disconnect();
|
|
932
|
+
});
|
|
933
|
+
r.messages = ee(u, t.initialMessages), (A = (C = t.callbacks).onNewMessage) == null || A.call(C, [...r.messages], "answer"), d.track("agent-sdk", {
|
|
934
|
+
event: "loaded",
|
|
935
|
+
...Ae(c)
|
|
936
|
+
});
|
|
937
|
+
async function h(l) {
|
|
938
|
+
var $, f, w, p, M, E, j;
|
|
939
|
+
(f = ($ = t.callbacks).onConnectionStateChange) == null || f.call($, S.Connecting), N.reset(), l && !a && (delete r.chat, r.messages = ee(u), (p = (w = t.callbacks).onNewMessage) == null || p.call(w, [...r.messages], "answer"));
|
|
940
|
+
const m = t.mode === b.DirectPlayback ? Promise.resolve(void 0) : We(t.auth, s, {
|
|
941
|
+
onMessage: g,
|
|
942
|
+
onError: t.callbacks.onError
|
|
943
|
+
}), k = X(() => it(c, t, o, d, r.chat, l ? u : void 0), {
|
|
944
|
+
limit: 3,
|
|
945
|
+
timeout: Me,
|
|
946
|
+
timeoutErrorMessage: "Timeout initializing the stream",
|
|
947
|
+
// Retry on all errors except for connection errors and rate limit errors, these are already handled in client level.
|
|
948
|
+
shouldRetryFn: (z) => (z == null ? void 0 : z.message) !== "Could not connect" && z.status !== 429,
|
|
949
|
+
delayMs: 1e3
|
|
950
|
+
}).catch((z) => {
|
|
951
|
+
var x, W;
|
|
952
|
+
throw v(b.Maintenance), (W = (x = t.callbacks).onConnectionStateChange) == null || W.call(x, S.Fail), z;
|
|
953
|
+
}), [P, {
|
|
954
|
+
streamingManager: T,
|
|
955
|
+
chat: _
|
|
956
|
+
}] = await Promise.all([m, k]);
|
|
957
|
+
_ && _.id !== ((M = r.chat) == null ? void 0 : M.id) && ((j = (E = t.callbacks).onNewChat) == null || j.call(E, _.id)), r.streamingManager = T, r.socketManager = P, r.chat = _, a = !1, v((_ == null ? void 0 : _.chat_mode) ?? t.mode ?? b.Functional);
|
|
958
|
+
}
|
|
959
|
+
async function y() {
|
|
960
|
+
var l, m, k, P;
|
|
961
|
+
(l = r.socketManager) == null || l.disconnect(), await ((m = r.streamingManager) == null ? void 0 : m.disconnect()), delete r.streamingManager, delete r.socketManager, (P = (k = t.callbacks).onConnectionStateChange) == null || P.call(k, S.Disconnected);
|
|
962
|
+
}
|
|
963
|
+
async function v(l) {
|
|
964
|
+
var m, k;
|
|
965
|
+
l !== r.chatMode && (d.track("agent-mode-change", {
|
|
966
|
+
mode: l
|
|
967
|
+
}), r.chatMode = l, r.chatMode !== b.Functional && await y(), (k = (m = t.callbacks).onModeChange) == null || k.call(m, l));
|
|
968
|
+
}
|
|
969
|
+
return {
|
|
970
|
+
agent: c,
|
|
971
|
+
starterMessages: ((I = c.knowledge) == null ? void 0 : I.starter_message) || [],
|
|
972
|
+
getSTTToken: () => o.getSTTToken(c.id),
|
|
973
|
+
changeMode: v,
|
|
974
|
+
enrichAnalytics: d.enrich,
|
|
975
|
+
async connect() {
|
|
976
|
+
var l;
|
|
977
|
+
await h(!0), d.track("agent-chat", {
|
|
978
|
+
event: "connect",
|
|
979
|
+
chatId: (l = r.chat) == null ? void 0 : l.id,
|
|
980
|
+
agentId: c.id,
|
|
981
|
+
mode: r.chatMode
|
|
982
|
+
});
|
|
983
|
+
},
|
|
460
984
|
async reconnect() {
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
},
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
985
|
+
var l;
|
|
986
|
+
await y(), await h(!1), d.track("agent-chat", {
|
|
987
|
+
event: "reconnect",
|
|
988
|
+
chatId: (l = r.chat) == null ? void 0 : l.id,
|
|
989
|
+
agentId: c.id,
|
|
990
|
+
mode: r.chatMode
|
|
991
|
+
});
|
|
992
|
+
},
|
|
993
|
+
async disconnect() {
|
|
994
|
+
var l;
|
|
995
|
+
await y(), d.track("agent-chat", {
|
|
996
|
+
event: "disconnect",
|
|
997
|
+
chatId: (l = r.chat) == null ? void 0 : l.id,
|
|
998
|
+
agentId: c.id,
|
|
999
|
+
mode: r.chatMode
|
|
1000
|
+
});
|
|
1001
|
+
},
|
|
1002
|
+
async chat(l) {
|
|
1003
|
+
var T, _, $, f, w;
|
|
1004
|
+
const m = () => {
|
|
1005
|
+
if (t.mode === b.DirectPlayback)
|
|
1006
|
+
throw new B("Direct playback is enabled, chat is disabled");
|
|
1007
|
+
if (l.length >= 800)
|
|
1008
|
+
throw new B("Message cannot be more than 800 characters");
|
|
1009
|
+
if (l.length === 0)
|
|
1010
|
+
throw new B("Message cannot be empty");
|
|
1011
|
+
if (r.chatMode === b.Maintenance)
|
|
1012
|
+
throw new B("Chat is in maintenance mode");
|
|
1013
|
+
if (![b.TextOnly, b.Playground].includes(r.chatMode)) {
|
|
1014
|
+
if (!r.streamingManager)
|
|
1015
|
+
throw new B("Streaming manager is not initialized");
|
|
1016
|
+
if (!r.chat)
|
|
1017
|
+
throw new B("Chat is not initialized");
|
|
1018
|
+
}
|
|
1019
|
+
}, k = async () => {
|
|
1020
|
+
var p, M;
|
|
1021
|
+
if (!r.chat) {
|
|
1022
|
+
const E = await de(c, o, d, r.chatMode, t.persistentChat);
|
|
1023
|
+
if (!E.chat)
|
|
1024
|
+
throw new fe(r.chatMode, !!t.persistentChat);
|
|
1025
|
+
r.chat = E.chat, (M = (p = t.callbacks).onNewChat) == null || M.call(p, r.chat.id);
|
|
1026
|
+
}
|
|
1027
|
+
return r.chat.id;
|
|
1028
|
+
}, P = async (p, M) => X(() => {
|
|
1029
|
+
var E, j;
|
|
1030
|
+
return o.chat(c.id, M, {
|
|
1031
|
+
chatMode: r.chatMode,
|
|
1032
|
+
streamId: (E = r.streamingManager) == null ? void 0 : E.streamId,
|
|
1033
|
+
sessionId: (j = r.streamingManager) == null ? void 0 : j.sessionId,
|
|
1034
|
+
messages: p.map(({
|
|
1035
|
+
matches: z,
|
|
1036
|
+
...x
|
|
1037
|
+
}) => x)
|
|
1038
|
+
}, {
|
|
1039
|
+
...ce(r.chatMode),
|
|
1040
|
+
skipErrorHandler: !0
|
|
1041
|
+
});
|
|
476
1042
|
}, {
|
|
477
|
-
|
|
1043
|
+
limit: 2,
|
|
1044
|
+
shouldRetryFn: (E) => {
|
|
1045
|
+
var x, W, G, O;
|
|
1046
|
+
const j = (x = E == null ? void 0 : E.message) == null ? void 0 : x.includes("missing or invalid session_id");
|
|
1047
|
+
return !((W = E == null ? void 0 : E.message) == null ? void 0 : W.includes("Stream Error")) && !j ? ((O = (G = t.callbacks).onError) == null || O.call(G, E), !1) : !0;
|
|
1048
|
+
},
|
|
1049
|
+
onRetry: async () => {
|
|
1050
|
+
await y(), await h(!1);
|
|
1051
|
+
}
|
|
478
1052
|
});
|
|
1053
|
+
try {
|
|
1054
|
+
R(), m(), r.messages.push({
|
|
1055
|
+
id: q(),
|
|
1056
|
+
role: "user",
|
|
1057
|
+
content: l,
|
|
1058
|
+
created_at: new Date(N.update()).toISOString()
|
|
1059
|
+
}), (_ = (T = t.callbacks).onNewMessage) == null || _.call(T, [...r.messages], "user");
|
|
1060
|
+
const p = await k(), M = await P([...r.messages], p);
|
|
1061
|
+
return r.messages.push({
|
|
1062
|
+
id: q(),
|
|
1063
|
+
role: "assistant",
|
|
1064
|
+
content: M.result || "",
|
|
1065
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1066
|
+
context: M.context,
|
|
1067
|
+
matches: M.matches
|
|
1068
|
+
}), d.track("agent-message-send", {
|
|
1069
|
+
event: "success",
|
|
1070
|
+
mode: r.chatMode,
|
|
1071
|
+
messages: r.messages.length + 1
|
|
1072
|
+
}), M.result && ((f = ($ = t.callbacks).onNewMessage) == null || f.call($, [...r.messages], "answer"), d.track("agent-message-received", {
|
|
1073
|
+
latency: N.get(!0),
|
|
1074
|
+
mode: r.chatMode,
|
|
1075
|
+
messages: r.messages.length
|
|
1076
|
+
})), M;
|
|
1077
|
+
} catch (p) {
|
|
1078
|
+
throw ((w = r.messages[r.messages.length - 1]) == null ? void 0 : w.role) === "assistant" && r.messages.pop(), d.track("agent-message-send", {
|
|
1079
|
+
event: "error",
|
|
1080
|
+
mode: r.chatMode,
|
|
1081
|
+
messages: r.messages.length
|
|
1082
|
+
}), p;
|
|
1083
|
+
}
|
|
479
1084
|
},
|
|
480
|
-
rate(
|
|
481
|
-
var
|
|
482
|
-
const
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
matches:
|
|
1085
|
+
rate(l, m, k) {
|
|
1086
|
+
var _, $, f, w;
|
|
1087
|
+
const P = r.messages.find((p) => p.id === l);
|
|
1088
|
+
if (r.chat) {
|
|
1089
|
+
if (!P)
|
|
1090
|
+
throw new Error("Message not found");
|
|
1091
|
+
} else
|
|
1092
|
+
throw new Error("Chat is not initialized");
|
|
1093
|
+
const T = ((_ = P.matches) == null ? void 0 : _.map((p) => [p.document_id, p.id])) ?? [];
|
|
1094
|
+
return d.track("agent-rate", {
|
|
1095
|
+
event: k ? "update" : "create",
|
|
1096
|
+
thumb: m === 1 ? "up" : "down",
|
|
1097
|
+
knowledge_id: (($ = c.knowledge) == null ? void 0 : $.id) ?? "",
|
|
1098
|
+
mode: r.chatMode,
|
|
1099
|
+
matches: T,
|
|
1100
|
+
score: m
|
|
1101
|
+
}), k ? o.updateRating(c.id, r.chat.id, k, {
|
|
1102
|
+
knowledge_id: ((f = c.knowledge) == null ? void 0 : f.id) ?? "",
|
|
1103
|
+
message_id: l,
|
|
1104
|
+
matches: T,
|
|
1105
|
+
score: m
|
|
1106
|
+
}) : o.createRating(c.id, r.chat.id, {
|
|
1107
|
+
knowledge_id: ((w = c.knowledge) == null ? void 0 : w.id) ?? "",
|
|
1108
|
+
message_id: l,
|
|
1109
|
+
matches: T,
|
|
1110
|
+
score: m
|
|
495
1111
|
});
|
|
496
1112
|
},
|
|
497
|
-
deleteRate(
|
|
498
|
-
|
|
1113
|
+
deleteRate(l) {
|
|
1114
|
+
var m;
|
|
1115
|
+
if (!r.chat)
|
|
1116
|
+
throw new Error("Chat is not initialized");
|
|
1117
|
+
return d.track("agent-rate-delete", {
|
|
1118
|
+
type: "text",
|
|
1119
|
+
chat_id: (m = r.chat) == null ? void 0 : m.id,
|
|
1120
|
+
id: l,
|
|
1121
|
+
mode: r.chatMode
|
|
1122
|
+
}), o.deleteRating(c.id, r.chat.id, l);
|
|
499
1123
|
},
|
|
500
|
-
speak(
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
1124
|
+
speak(l) {
|
|
1125
|
+
if (!r.streamingManager)
|
|
1126
|
+
throw new Error("Please connect to the agent first");
|
|
1127
|
+
function m() {
|
|
1128
|
+
if (typeof l == "string") {
|
|
1129
|
+
if (!c.presenter.voice)
|
|
1130
|
+
throw new Error("Presenter voice is not initialized");
|
|
1131
|
+
return {
|
|
505
1132
|
type: "text",
|
|
506
|
-
provider:
|
|
507
|
-
input:
|
|
508
|
-
ssml:
|
|
1133
|
+
provider: c.presenter.voice,
|
|
1134
|
+
input: l,
|
|
1135
|
+
ssml: !1
|
|
509
1136
|
};
|
|
510
|
-
}
|
|
1137
|
+
}
|
|
1138
|
+
if (l.type === "text" && !l.provider) {
|
|
1139
|
+
if (!c.presenter.voice)
|
|
1140
|
+
throw new Error("Presenter voice is not initialized");
|
|
511
1141
|
return {
|
|
512
|
-
type: "
|
|
513
|
-
|
|
1142
|
+
type: "text",
|
|
1143
|
+
provider: c.presenter.voice,
|
|
1144
|
+
input: l.input,
|
|
1145
|
+
ssml: l.ssml
|
|
514
1146
|
};
|
|
515
|
-
|
|
1147
|
+
}
|
|
1148
|
+
return l;
|
|
516
1149
|
}
|
|
517
|
-
|
|
518
|
-
|
|
1150
|
+
const k = m();
|
|
1151
|
+
return d.track("agent-speak", k), N.update(), r.streamingManager.speak({
|
|
1152
|
+
script: k
|
|
519
1153
|
});
|
|
520
1154
|
}
|
|
521
1155
|
};
|
|
522
1156
|
}
|
|
1157
|
+
function ct(e, t, a) {
|
|
1158
|
+
const {
|
|
1159
|
+
getById: n
|
|
1160
|
+
} = oe(t, a || K);
|
|
1161
|
+
return n(e);
|
|
1162
|
+
}
|
|
523
1163
|
export {
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
1164
|
+
ye as AgentStatus,
|
|
1165
|
+
fe as ChatCreationFailed,
|
|
1166
|
+
b as ChatMode,
|
|
1167
|
+
ge as ChatModeDowngraded,
|
|
1168
|
+
F as ChatProgress,
|
|
1169
|
+
S as ConnectionState,
|
|
1170
|
+
Ce as DocumentType,
|
|
1171
|
+
Re as KnowledgeType,
|
|
1172
|
+
pe as PlanGroup,
|
|
1173
|
+
De as Providers,
|
|
1174
|
+
ve as RateState,
|
|
1175
|
+
U as StreamEvents,
|
|
1176
|
+
D as StreamingState,
|
|
1177
|
+
ke as Subject,
|
|
1178
|
+
we as UserPlan,
|
|
1179
|
+
B as ValidationError,
|
|
1180
|
+
ne as VideoType,
|
|
1181
|
+
_e as VoiceAccess,
|
|
1182
|
+
he as WsError,
|
|
1183
|
+
ot as createAgentManager,
|
|
1184
|
+
ct as getAgent,
|
|
1185
|
+
Se as mapVideoType
|
|
536
1186
|
};
|