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