@d-id/client-sdk 1.1.0-beta.4 → 1.1.0-beta.6
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 +524 -515
- 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/index.d.ts +1 -1
- 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/dist/src/utils/chat.d.ts +2 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
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 H = (e, t, n) => (he(e, typeof t != "symbol" ? t + "" : t, n), n);
|
|
4
4
|
class Q 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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
this.kind =
|
|
14
|
+
H(this, "kind");
|
|
15
|
+
H(this, "description");
|
|
16
|
+
H(this, "error");
|
|
17
|
+
this.kind = n, this.description = a, this.error = o;
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
-
class
|
|
21
|
-
constructor(t,
|
|
20
|
+
class we extends Q {
|
|
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 Q {
|
|
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
|
|
37
|
-
constructor(
|
|
36
|
+
class F extends Q {
|
|
37
|
+
constructor(n, a) {
|
|
38
38
|
super({
|
|
39
39
|
kind: "ValidationError",
|
|
40
|
-
description:
|
|
40
|
+
description: n
|
|
41
41
|
});
|
|
42
|
-
|
|
43
|
-
this.key =
|
|
42
|
+
H(this, "key");
|
|
43
|
+
this.key = a;
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
-
class
|
|
46
|
+
class ye extends Q {
|
|
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 || {}), Ce = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(Ce || {}), De = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(De || {}), j = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e))(j || {}), 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 || {}), K = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Talking = "TALKING", e))(K || {});
|
|
66
|
+
const te = {
|
|
67
67
|
"stream/started": "START",
|
|
68
68
|
"stream/done": "STOP"
|
|
69
69
|
/* Stop */
|
|
70
70
|
};
|
|
71
|
-
var
|
|
72
|
-
const
|
|
71
|
+
var Y = /* @__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))(Y || {}), I = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnected = "disconnected", e))(I || {}), N = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(N || {}), _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", q = "https://api.d-id.com", be = "wss://notifications.d-id.com", Pe = "79f81a83a67430be2bc0fd61042b8faa", se = (e) => new Promise((t) => setTimeout(t, e)), X = () => Math.random().toString(16).slice(2), Be = (e) => [j.TextOnly, j.Playground, j.Maintenance].includes(e);
|
|
73
73
|
function $e(e, t) {
|
|
74
|
-
let
|
|
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 Z(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,45 +89,45 @@ 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
|
-
} = $e(
|
|
100
|
+
} = $e(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 Le =
|
|
114
|
-
function
|
|
113
|
+
let Le = X();
|
|
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()}_${Le}`;
|
|
121
121
|
throw new Error(`Unknown auth type: ${e}`);
|
|
122
122
|
}
|
|
123
|
-
const Ae = (e) =>
|
|
123
|
+
const Ae = (e) => Z(e, {
|
|
124
124
|
limit: 3,
|
|
125
125
|
delayMs: 1e3,
|
|
126
126
|
timeout: 0,
|
|
127
127
|
shouldRetryFn: (t) => t.status === 429
|
|
128
128
|
});
|
|
129
|
-
function O(e, t =
|
|
130
|
-
const
|
|
129
|
+
function O(e, t = q, n) {
|
|
130
|
+
const a = async (o, s) => {
|
|
131
131
|
const {
|
|
132
132
|
skipErrorHandler: r,
|
|
133
133
|
...i
|
|
@@ -135,44 +135,44 @@ function O(e, t = K, a) {
|
|
|
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 u = new Error(l);
|
|
145
|
+
throw n && !r && n(u, {
|
|
146
146
|
url: o,
|
|
147
147
|
options: i,
|
|
148
148
|
headers: c.headers
|
|
149
|
-
}),
|
|
149
|
+
}), u;
|
|
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 = q, n) {
|
|
184
|
+
const a = O(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
|
|
221
|
+
const le = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type;
|
|
222
222
|
function ze(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 xe = (e) => e.reduce((t, n) => t + n, 0), Ne = (e) => xe(e) / e.length;
|
|
241
|
+
function Fe(e, t, n) {
|
|
242
|
+
var c, l, u;
|
|
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" ? (u = t == null ? void 0 : t.presenter) == null ? void 0 : u.stitch : void 0,
|
|
265
|
+
...n
|
|
266
266
|
};
|
|
267
267
|
}
|
|
268
268
|
let V = {};
|
|
269
269
|
const Je = "https://api-js.mixpanel.com/track/?verbose=1&ip=1";
|
|
270
270
|
function We(e) {
|
|
271
|
-
var s, r, i, c,
|
|
272
|
-
const t = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk",
|
|
271
|
+
var s, r, i, c, l, u;
|
|
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: (u = (l = e.agent.knowledge) == null ? void 0 : l.starter_message) == null ? void 0 : u.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(
|
|
296
|
-
const
|
|
297
|
-
if (
|
|
295
|
+
enrich(f) {
|
|
296
|
+
const k = {};
|
|
297
|
+
if (f && typeof f != "object")
|
|
298
298
|
throw new Error("properties must be a flat json object");
|
|
299
|
-
for (let
|
|
300
|
-
(typeof
|
|
299
|
+
for (let y in f)
|
|
300
|
+
(typeof f[y] == "string" || typeof f[y] == "number") && (k[y] = f[y]);
|
|
301
301
|
this.additionalProperties = {
|
|
302
302
|
...this.additionalProperties,
|
|
303
|
-
...
|
|
303
|
+
...k
|
|
304
304
|
};
|
|
305
305
|
},
|
|
306
|
-
async track(
|
|
306
|
+
async track(f, k) {
|
|
307
307
|
if (!this.isEnabled)
|
|
308
308
|
return Promise.resolve();
|
|
309
309
|
const {
|
|
310
|
-
audioPath:
|
|
311
|
-
...
|
|
312
|
-
} =
|
|
310
|
+
audioPath: y,
|
|
311
|
+
...C
|
|
312
|
+
} = k || {}, S = {
|
|
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: f,
|
|
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(Je,
|
|
337
|
-
} catch (
|
|
338
|
-
return console.error(
|
|
336
|
+
return await fetch(Je, S).then((B) => B.json());
|
|
337
|
+
} catch (B) {
|
|
338
|
+
return console.error(B);
|
|
339
339
|
}
|
|
340
340
|
},
|
|
341
|
-
linkTrack(
|
|
342
|
-
V[
|
|
341
|
+
linkTrack(f, k, y, C) {
|
|
342
|
+
V[f] || (V[f] = {
|
|
343
343
|
events: {},
|
|
344
344
|
resolvedDependencies: []
|
|
345
|
-
}),
|
|
346
|
-
const
|
|
347
|
-
if (
|
|
348
|
-
props:
|
|
349
|
-
},
|
|
350
|
-
const
|
|
351
|
-
...
|
|
352
|
-
...
|
|
353
|
-
} :
|
|
354
|
-
this.track(
|
|
355
|
-
delete
|
|
345
|
+
}), C.includes(y) || C.push(y);
|
|
346
|
+
const S = V[f];
|
|
347
|
+
if (S.events[y] = {
|
|
348
|
+
props: k
|
|
349
|
+
}, S.resolvedDependencies.push(y), C.every((M) => S.resolvedDependencies.includes(M))) {
|
|
350
|
+
const M = C.reduce((d, w) => S.events[w] ? {
|
|
351
|
+
...d,
|
|
352
|
+
...S.events[w].props
|
|
353
|
+
} : d, {});
|
|
354
|
+
this.track(f, M), S.resolvedDependencies = S.resolvedDependencies.filter((d) => !C.includes(d)), C.forEach((d) => {
|
|
355
|
+
delete S.events[d];
|
|
356
356
|
});
|
|
357
357
|
}
|
|
358
358
|
}
|
|
359
359
|
};
|
|
360
360
|
}
|
|
361
|
-
function
|
|
361
|
+
function Ue() {
|
|
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 x = Ue();
|
|
370
|
+
function ue(e) {
|
|
371
|
+
return e === j.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 !== j.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 {
|
|
@@ -398,35 +398,25 @@ async function me(e, t, a, n, o = !1, s) {
|
|
|
398
398
|
throw new Error("Cannot create new chat");
|
|
399
399
|
}
|
|
400
400
|
}
|
|
401
|
-
function
|
|
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?`;
|
|
405
|
-
}
|
|
406
|
-
function ae(e, t) {
|
|
407
|
-
return t && t.length > 0 ? t : [{
|
|
408
|
-
content: e,
|
|
409
|
-
id: Y(),
|
|
410
|
-
role: "assistant",
|
|
411
|
-
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
412
|
-
}];
|
|
401
|
+
function He(e) {
|
|
402
|
+
return e && e.length > 0 ? e : [];
|
|
413
403
|
}
|
|
414
404
|
function Ke(e) {
|
|
415
|
-
return new Promise((t,
|
|
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 || {}, u = new WebSocket(`${o}?authorization=${ce(s)}`);
|
|
416
|
+
u.onmessage = r, u.onclose = c, u.onerror = (f) => {
|
|
417
|
+
console.error(f), l == null || l("Websocket failed to connect", f), n(f);
|
|
418
|
+
}, u.onopen = (f) => {
|
|
419
|
+
i == null || i(f), t(u);
|
|
430
420
|
};
|
|
431
421
|
});
|
|
432
422
|
}
|
|
@@ -434,94 +424,94 @@ async function qe(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 Ke(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 Xe(e, t,
|
|
449
|
-
const
|
|
438
|
+
async function Xe(e, t, n) {
|
|
439
|
+
const a = n != null && n.onMessage ? [n.onMessage] : [], o = await qe({
|
|
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
459
|
function Ye(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 Qe(e, t,
|
|
478
|
-
const s =
|
|
467
|
+
function Qe(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 = Ye(
|
|
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 = Ye(n);
|
|
477
|
+
(s.content !== c || e === J.Answer) && (s.content = c, o == null || o([...a.messages], e));
|
|
488
478
|
}
|
|
489
|
-
function Ve(e, t,
|
|
479
|
+
function Ve(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
|
-
Qe(r, i, s, t,
|
|
486
|
+
Qe(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 u = Y, f = [u.StreamVideoDone, u.StreamVideoError, u.StreamVideoRejected], k = [u.StreamFailed, u.StreamVideoError, u.StreamVideoRejected], y = 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
|
|
508
|
-
|
|
509
|
-
...
|
|
510
|
-
event:
|
|
494
|
+
if (r = r, r === u.StreamVideoCreated)
|
|
495
|
+
e.linkTrack("agent-video", y, u.StreamVideoCreated, ["start"]);
|
|
496
|
+
else if (f.includes(r)) {
|
|
497
|
+
const C = r.split("/")[1];
|
|
498
|
+
k.includes(r) ? e.track("agent-video", {
|
|
499
|
+
...y,
|
|
500
|
+
event: C
|
|
511
501
|
}) : e.linkTrack("agent-video", {
|
|
512
|
-
...
|
|
513
|
-
event:
|
|
502
|
+
...y,
|
|
503
|
+
event: C
|
|
514
504
|
}, r, ["done"]);
|
|
515
505
|
}
|
|
516
|
-
|
|
506
|
+
k.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 === u.StreamDone && o();
|
|
519
509
|
}
|
|
520
510
|
}
|
|
521
511
|
};
|
|
522
512
|
}
|
|
523
|
-
function
|
|
524
|
-
const o = O(e, `${t}/agents/${
|
|
513
|
+
function Ze(e, t, n, a) {
|
|
514
|
+
const o = O(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
|
|
561
|
-
const o = O(e, `${t}/agents/${
|
|
550
|
+
function Ge(e, t, n, a) {
|
|
551
|
+
const o = O(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 Oe(e, t,
|
|
601
|
-
const
|
|
590
|
+
function Oe(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
610
|
function et(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
622
|
function tt(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 rt(e, t,
|
|
657
|
-
const
|
|
646
|
+
function rt(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,365 @@ 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 = et(
|
|
695
|
+
}), o = et(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
699
|
aggregateReport: Oe(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
|
|
708
|
+
const G = 100, nt = Math.max(Math.ceil(400 / G), 1), at = 0.25, it = 0.28;
|
|
719
709
|
function st() {
|
|
720
|
-
let e = 0, t,
|
|
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 u = r - t, f = i - n;
|
|
717
|
+
a = u / f;
|
|
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 ot(e, t,
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
const $ = st();
|
|
733
|
+
function ot(e, t, n, a, o, s = !1) {
|
|
734
|
+
let r = [], i, c = 0, l = !1, u = W.Unknown, f = W.Unknown, k = 0, y = 0;
|
|
735
|
+
const C = st();
|
|
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 S = await e.getStats(), {
|
|
738
|
+
isReceiving: B,
|
|
739
|
+
avgJitterDelayInInterval: M,
|
|
740
|
+
freezeCount: d
|
|
741
|
+
} = C(S), w = tt(S);
|
|
742
|
+
if (B)
|
|
743
|
+
c = 0, k = d - y, f = M < at ? W.Strong : M > it && k > 1 ? W.Weak : u, f !== u && (o == null || o(f), u = f, y += k, k = 0), l || (a == null || a(v.Start), i = r[r.length - 1], r = [], l = !0), r.push(w);
|
|
744
|
+
else if (l && (c++, c >= nt)) {
|
|
745
|
+
const h = rt(r, G, i);
|
|
746
|
+
a == null || a(v.Stop, h), t() || n(), l = !1;
|
|
758
747
|
}
|
|
759
|
-
},
|
|
748
|
+
}, G);
|
|
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), ct = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
|
|
752
|
+
function re(e) {
|
|
764
753
|
switch (e) {
|
|
765
754
|
case "connected":
|
|
766
|
-
return
|
|
755
|
+
return I.Connected;
|
|
767
756
|
case "checking":
|
|
768
|
-
return
|
|
757
|
+
return I.Connecting;
|
|
769
758
|
case "failed":
|
|
770
|
-
return
|
|
759
|
+
return I.Fail;
|
|
771
760
|
case "new":
|
|
772
|
-
return
|
|
761
|
+
return I.New;
|
|
773
762
|
case "closed":
|
|
774
|
-
return
|
|
763
|
+
return I.Closed;
|
|
775
764
|
case "disconnected":
|
|
776
|
-
return
|
|
765
|
+
return I.Disconnected;
|
|
777
766
|
case "completed":
|
|
778
|
-
return
|
|
767
|
+
return I.Completed;
|
|
779
768
|
default:
|
|
780
|
-
return
|
|
769
|
+
return I.New;
|
|
781
770
|
}
|
|
782
771
|
}
|
|
783
772
|
function dt({
|
|
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
780
|
function lt({
|
|
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(K.Talking) : t === v.Stop && (a == null || a(K.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
797
|
o === N.Legacy ? dt({
|
|
809
798
|
statsSignal: e,
|
|
810
799
|
dataChannelSignal: t,
|
|
811
|
-
onVideoStateChange:
|
|
800
|
+
onVideoStateChange: n,
|
|
812
801
|
report: s
|
|
813
802
|
}) : o === N.Fluent && lt({
|
|
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
810
|
async function ut(e, t, {
|
|
822
|
-
debug:
|
|
823
|
-
callbacks:
|
|
811
|
+
debug: n = !1,
|
|
812
|
+
callbacks: a,
|
|
824
813
|
auth: o,
|
|
825
|
-
baseURL: s =
|
|
814
|
+
baseURL: s = q,
|
|
815
|
+
analytics: r
|
|
826
816
|
}) {
|
|
827
|
-
|
|
828
|
-
let
|
|
817
|
+
me = n;
|
|
818
|
+
let i = !1, c = !1, l = v.Stop, u = v.Stop, f = W.Unknown;
|
|
829
819
|
const {
|
|
830
|
-
startConnection:
|
|
831
|
-
sendStreamRequest:
|
|
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 (!
|
|
820
|
+
startConnection: k,
|
|
821
|
+
sendStreamRequest: y,
|
|
822
|
+
close: C,
|
|
823
|
+
createStream: S,
|
|
824
|
+
addIceCandidate: B
|
|
825
|
+
} = t.videoType === ie.Clip ? Ze(o, s, e, a.onError) : Ge(o, s, e, a.onError), {
|
|
826
|
+
id: M,
|
|
827
|
+
offer: d,
|
|
828
|
+
ice_servers: w,
|
|
829
|
+
session_id: h,
|
|
830
|
+
fluent: b
|
|
831
|
+
} = await S(t), g = new ct({
|
|
832
|
+
iceServers: w
|
|
833
|
+
}), D = g.createDataChannel("JanusDataChannel");
|
|
834
|
+
if (!h)
|
|
845
835
|
throw new Error("Could not create session_id");
|
|
846
|
-
const
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
}
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
var
|
|
862
|
-
|
|
836
|
+
const _ = b ? N.Fluent : N.Legacy;
|
|
837
|
+
r.enrich({
|
|
838
|
+
"stream-type": _
|
|
839
|
+
});
|
|
840
|
+
const P = t.stream_warmup && !b, L = () => i, R = () => {
|
|
841
|
+
var m;
|
|
842
|
+
i = !0, c && ((m = a.onConnectionStateChange) == null || m.call(a, I.Connected));
|
|
843
|
+
}, T = ot(g, L, R, (m, p) => ne({
|
|
844
|
+
statsSignal: u = m,
|
|
845
|
+
dataChannelSignal: _ === N.Legacy ? l : void 0,
|
|
846
|
+
onVideoStateChange: a.onVideoStateChange,
|
|
847
|
+
onAgentActivityStateChange: a.onAgentActivityStateChange,
|
|
848
|
+
report: p,
|
|
849
|
+
streamType: _
|
|
850
|
+
}), (m) => {
|
|
851
|
+
var p;
|
|
852
|
+
return (p = a.onConnectivityStateChange) == null ? void 0 : p.call(a, f);
|
|
853
|
+
}, P);
|
|
854
|
+
g.onicecandidate = (m) => {
|
|
855
|
+
var p;
|
|
856
|
+
z("peerConnection.onicecandidate", m);
|
|
863
857
|
try {
|
|
864
|
-
|
|
865
|
-
candidate:
|
|
866
|
-
sdpMid:
|
|
867
|
-
sdpMLineIndex:
|
|
868
|
-
},
|
|
858
|
+
m.candidate && m.candidate.sdpMid && m.candidate.sdpMLineIndex !== null ? B(M, {
|
|
859
|
+
candidate: m.candidate.candidate,
|
|
860
|
+
sdpMid: m.candidate.sdpMid,
|
|
861
|
+
sdpMLineIndex: m.candidate.sdpMLineIndex
|
|
862
|
+
}, h) : B(M, {
|
|
869
863
|
candidate: null
|
|
870
|
-
},
|
|
871
|
-
} catch (
|
|
872
|
-
(
|
|
873
|
-
streamId:
|
|
864
|
+
}, h);
|
|
865
|
+
} catch ($) {
|
|
866
|
+
(p = a.onError) == null || p.call(a, $, {
|
|
867
|
+
streamId: M
|
|
874
868
|
});
|
|
875
869
|
}
|
|
876
|
-
},
|
|
877
|
-
|
|
878
|
-
},
|
|
879
|
-
|
|
880
|
-
statsSignal:
|
|
881
|
-
dataChannelSignal:
|
|
882
|
-
onVideoStateChange:
|
|
883
|
-
onAgentActivityStateChange:
|
|
884
|
-
streamType:
|
|
870
|
+
}, D.onopen = () => {
|
|
871
|
+
c = !0, (!P || i) && R();
|
|
872
|
+
}, D.onmessage = (m) => {
|
|
873
|
+
m.data in te && (l = te[m.data], ne({
|
|
874
|
+
statsSignal: _ === N.Legacy ? u : void 0,
|
|
875
|
+
dataChannelSignal: l,
|
|
876
|
+
onVideoStateChange: a.onVideoStateChange,
|
|
877
|
+
onAgentActivityStateChange: a.onAgentActivityStateChange,
|
|
878
|
+
streamType: _
|
|
885
879
|
}));
|
|
886
|
-
},
|
|
887
|
-
var
|
|
888
|
-
z("peerConnection.oniceconnectionstatechange => " +
|
|
889
|
-
const
|
|
890
|
-
|
|
891
|
-
},
|
|
892
|
-
var
|
|
893
|
-
z("peerConnection.ontrack",
|
|
894
|
-
}, await
|
|
895
|
-
const
|
|
896
|
-
return z("create answer OK"), await
|
|
880
|
+
}, g.oniceconnectionstatechange = () => {
|
|
881
|
+
var p;
|
|
882
|
+
z("peerConnection.oniceconnectionstatechange => " + g.iceConnectionState);
|
|
883
|
+
const m = re(g.iceConnectionState);
|
|
884
|
+
m !== I.Connected && ((p = a.onConnectionStateChange) == null || p.call(a, m));
|
|
885
|
+
}, g.ontrack = (m) => {
|
|
886
|
+
var p;
|
|
887
|
+
z("peerConnection.ontrack", m), (p = a.onSrcObjectReady) == null || p.call(a, m.streams[0]);
|
|
888
|
+
}, await g.setRemoteDescription(d), z("set remote description OK");
|
|
889
|
+
const E = await g.createAnswer();
|
|
890
|
+
return z("create answer OK"), await g.setLocalDescription(E), z("set local description OK"), await k(M, E, h), z("start connection OK"), {
|
|
897
891
|
/**
|
|
898
892
|
* Method to send request to server to get clip or talk depend on you payload
|
|
899
893
|
* @param payload
|
|
900
894
|
*/
|
|
901
|
-
speak(
|
|
902
|
-
return
|
|
895
|
+
speak(m) {
|
|
896
|
+
return y(M, h, m);
|
|
903
897
|
},
|
|
904
898
|
/**
|
|
905
899
|
* Method to close RTC connection
|
|
906
900
|
*/
|
|
907
901
|
async disconnect() {
|
|
908
|
-
var
|
|
909
|
-
if (
|
|
910
|
-
const
|
|
911
|
-
if (
|
|
912
|
-
if (
|
|
913
|
-
(
|
|
902
|
+
var m, p, $;
|
|
903
|
+
if (M) {
|
|
904
|
+
const A = re(g.iceConnectionState);
|
|
905
|
+
if (g) {
|
|
906
|
+
if (A === I.New) {
|
|
907
|
+
(m = a.onVideoStateChange) == null || m.call(a, v.Stop), clearInterval(T);
|
|
914
908
|
return;
|
|
915
909
|
}
|
|
916
|
-
|
|
910
|
+
g.close(), g.oniceconnectionstatechange = null, g.onnegotiationneeded = null, g.onicecandidate = null, g.ontrack = null;
|
|
917
911
|
}
|
|
918
912
|
try {
|
|
919
|
-
|
|
913
|
+
A === I.Connected && await C(M, h).catch((U) => {
|
|
920
914
|
});
|
|
921
|
-
} catch (
|
|
922
|
-
z("Error on close stream connection",
|
|
915
|
+
} catch (U) {
|
|
916
|
+
z("Error on close stream connection", U);
|
|
923
917
|
}
|
|
924
|
-
(
|
|
918
|
+
(p = a.onVideoStateChange) == null || p.call(a, v.Stop), ($ = a.onAgentActivityStateChange) == null || $.call(a, K.Idle), clearInterval(T);
|
|
925
919
|
}
|
|
926
920
|
},
|
|
927
921
|
/**
|
|
928
922
|
* Session identifier information, should be returned in the body of all streaming requests
|
|
929
923
|
*/
|
|
930
|
-
sessionId:
|
|
924
|
+
sessionId: h,
|
|
931
925
|
/**
|
|
932
926
|
* Id of current RTC stream
|
|
933
927
|
*/
|
|
934
|
-
streamId:
|
|
935
|
-
streamType:
|
|
928
|
+
streamId: M,
|
|
929
|
+
streamType: _
|
|
936
930
|
};
|
|
937
931
|
}
|
|
938
|
-
function ft(e, t
|
|
939
|
-
var o;
|
|
932
|
+
function ft(e, t) {
|
|
940
933
|
const {
|
|
941
934
|
streamOptions: n
|
|
942
935
|
} = t ?? {};
|
|
943
936
|
return {
|
|
944
|
-
videoType:
|
|
937
|
+
videoType: Me(e.presenter.type),
|
|
945
938
|
output_resolution: n == null ? void 0 : n.outputResolution,
|
|
946
939
|
session_timeout: n == null ? void 0 : n.sessionTimeout,
|
|
947
940
|
stream_warmup: n == null ? void 0 : n.streamWarmup,
|
|
948
941
|
compatibility_mode: n == null ? void 0 : n.compatibilityMode,
|
|
949
|
-
|
|
942
|
+
fluent: n == null ? void 0 : n.fluent
|
|
950
943
|
};
|
|
951
944
|
}
|
|
952
|
-
function
|
|
953
|
-
|
|
945
|
+
function ae(e, t, n, a, o) {
|
|
946
|
+
x.get() > 0 && (e === v.Start ? a.linkTrack("agent-video", {
|
|
954
947
|
event: "start",
|
|
955
|
-
latency:
|
|
956
|
-
|
|
948
|
+
latency: x.get(!0),
|
|
949
|
+
"stream-type": o
|
|
950
|
+
}, "start", [Y.StreamVideoCreated]) : e === v.Stop && a.linkTrack("agent-video", {
|
|
957
951
|
event: "stop",
|
|
958
952
|
is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
|
|
959
953
|
background: t.presenter.type === "clip" && t.presenter.background,
|
|
960
|
-
|
|
961
|
-
|
|
954
|
+
"stream-type": o,
|
|
955
|
+
...n
|
|
956
|
+
}, "done", [Y.StreamVideoDone]));
|
|
962
957
|
}
|
|
963
|
-
function
|
|
964
|
-
return
|
|
958
|
+
function mt(e, t, n) {
|
|
959
|
+
return x.reset(), new Promise(async (a, o) => {
|
|
965
960
|
try {
|
|
966
|
-
const
|
|
961
|
+
const s = await ut(e.id, ft(e, t), {
|
|
967
962
|
...t,
|
|
968
|
-
analytics:
|
|
963
|
+
analytics: n,
|
|
969
964
|
callbacks: {
|
|
970
965
|
...t.callbacks,
|
|
971
|
-
onConnectionStateChange: (
|
|
972
|
-
var
|
|
973
|
-
(
|
|
966
|
+
onConnectionStateChange: (r) => {
|
|
967
|
+
var i, c;
|
|
968
|
+
(c = (i = t.callbacks).onConnectionStateChange) == null || c.call(i, r), r === I.Connected && a(s);
|
|
969
|
+
},
|
|
970
|
+
onVideoStateChange: (r, i) => {
|
|
971
|
+
var c, l;
|
|
972
|
+
(l = (c = t.callbacks).onVideoStateChange) == null || l.call(c, r), ae(r, e, i, n, s.streamType);
|
|
974
973
|
},
|
|
975
|
-
|
|
976
|
-
var
|
|
977
|
-
(
|
|
974
|
+
onAgentActivityStateChange: (r) => {
|
|
975
|
+
var i, c;
|
|
976
|
+
(c = (i = t.callbacks).onAgentActivityStateChange) == null || c.call(i, r), ae(r === K.Talking ? v.Start : v.Stop, e, void 0, n, s.streamType);
|
|
978
977
|
}
|
|
979
978
|
}
|
|
980
979
|
});
|
|
981
|
-
} catch (
|
|
982
|
-
s
|
|
980
|
+
} catch (s) {
|
|
981
|
+
o(s);
|
|
983
982
|
}
|
|
984
983
|
});
|
|
985
984
|
}
|
|
986
|
-
async function
|
|
987
|
-
var
|
|
985
|
+
async function gt(e, t, n, a, o) {
|
|
986
|
+
var c, l, u, f;
|
|
988
987
|
const {
|
|
989
|
-
chat:
|
|
990
|
-
chatMode:
|
|
991
|
-
} = await
|
|
992
|
-
if (
|
|
993
|
-
return (
|
|
994
|
-
chat:
|
|
988
|
+
chat: s,
|
|
989
|
+
chatMode: r
|
|
990
|
+
} = await fe(e, n, a, t.mode, t.persistentChat, o);
|
|
991
|
+
if (r && r !== t.mode && (t.mode = r, (l = (c = t.callbacks).onModeChange) == null || l.call(c, r), r === j.TextOnly))
|
|
992
|
+
return (f = (u = t.callbacks).onError) == null || f.call(u, new pe(r)), {
|
|
993
|
+
chat: s
|
|
995
994
|
};
|
|
996
|
-
const
|
|
995
|
+
const i = await mt(e, t, a);
|
|
997
996
|
return {
|
|
998
|
-
chat:
|
|
999
|
-
streamingManager:
|
|
997
|
+
chat: s,
|
|
998
|
+
streamingManager: i
|
|
1000
999
|
};
|
|
1001
1000
|
}
|
|
1002
|
-
async function
|
|
1003
|
-
var
|
|
1004
|
-
let
|
|
1005
|
-
const
|
|
1001
|
+
async function wt(e, t) {
|
|
1002
|
+
var S, B, M;
|
|
1003
|
+
let n = !0;
|
|
1004
|
+
const a = t.mixpanelKey || Pe, o = t.wsURL || be, s = t.baseURL || q, r = {
|
|
1006
1005
|
messages: [],
|
|
1007
|
-
chatMode: t.mode ||
|
|
1008
|
-
}, i =
|
|
1009
|
-
token:
|
|
1006
|
+
chatMode: t.mode || j.Functional
|
|
1007
|
+
}, i = de(t.auth, s, t.callbacks.onError), c = await i.getById(e), l = We({
|
|
1008
|
+
token: a,
|
|
1010
1009
|
agent: c,
|
|
1011
1010
|
isEnabled: t.enableAnalitics,
|
|
1012
1011
|
distinctId: t.distinctId
|
|
1013
1012
|
}), {
|
|
1014
|
-
onMessage:
|
|
1015
|
-
clearQueue:
|
|
1013
|
+
onMessage: u,
|
|
1014
|
+
clearQueue: f
|
|
1016
1015
|
} = Ve(l, r, t, c, () => {
|
|
1017
1016
|
var d;
|
|
1018
1017
|
return (d = r.socketManager) == null ? void 0 : d.disconnect();
|
|
1019
1018
|
});
|
|
1020
|
-
r.messages =
|
|
1019
|
+
r.messages = He(t.initialMessages), (B = (S = t.callbacks).onNewMessage) == null || B.call(S, [...r.messages], "answer"), l.track("agent-sdk", {
|
|
1021
1020
|
event: "loaded",
|
|
1022
1021
|
...ze(c)
|
|
1023
1022
|
});
|
|
1024
|
-
async function
|
|
1025
|
-
var
|
|
1026
|
-
(
|
|
1027
|
-
const w = t.mode ===
|
|
1028
|
-
onMessage:
|
|
1023
|
+
async function k(d) {
|
|
1024
|
+
var _, P, L, R, T, E, m;
|
|
1025
|
+
(P = (_ = t.callbacks).onConnectionStateChange) == null || P.call(_, I.Connecting), x.reset(), d && !n && (delete r.chat, (R = (L = t.callbacks).onNewMessage) == null || R.call(L, [...r.messages], "answer"));
|
|
1026
|
+
const w = t.mode === j.DirectPlayback ? Promise.resolve(void 0) : Xe(t.auth, o, {
|
|
1027
|
+
onMessage: u,
|
|
1029
1028
|
onError: t.callbacks.onError
|
|
1030
|
-
}),
|
|
1029
|
+
}), h = Z(() => gt(c, t, i, l, r.chat), {
|
|
1031
1030
|
limit: 3,
|
|
1032
|
-
timeout:
|
|
1031
|
+
timeout: Te,
|
|
1033
1032
|
timeoutErrorMessage: "Timeout initializing the stream",
|
|
1034
1033
|
// Retry on all errors except for connection errors and rate limit errors, these are already handled in client level.
|
|
1035
|
-
shouldRetryFn: (
|
|
1034
|
+
shouldRetryFn: (p) => (p == null ? void 0 : p.message) !== "Could not connect" && p.status !== 429,
|
|
1036
1035
|
delayMs: 1e3
|
|
1037
|
-
}).catch((
|
|
1038
|
-
var A
|
|
1039
|
-
throw
|
|
1040
|
-
}), [
|
|
1041
|
-
streamingManager:
|
|
1042
|
-
chat:
|
|
1043
|
-
}] = await Promise.all([w,
|
|
1044
|
-
|
|
1036
|
+
}).catch((p) => {
|
|
1037
|
+
var $, A;
|
|
1038
|
+
throw C(j.Maintenance), (A = ($ = t.callbacks).onConnectionStateChange) == null || A.call($, I.Fail), p;
|
|
1039
|
+
}), [b, {
|
|
1040
|
+
streamingManager: g,
|
|
1041
|
+
chat: D
|
|
1042
|
+
}] = await Promise.all([w, h]);
|
|
1043
|
+
D && D.id !== ((T = r.chat) == null ? void 0 : T.id) && ((m = (E = t.callbacks).onNewChat) == null || m.call(E, D.id)), r.streamingManager = g, r.socketManager = b, r.chat = D, n = !1, C((D == null ? void 0 : D.chat_mode) ?? t.mode ?? j.Functional);
|
|
1045
1044
|
}
|
|
1046
1045
|
async function y() {
|
|
1047
|
-
var d, w,
|
|
1048
|
-
(d = r.socketManager) == null || d.disconnect(), await ((w = r.streamingManager) == null ? void 0 : w.disconnect()), delete r.streamingManager, delete r.socketManager, (
|
|
1046
|
+
var d, w, h, b;
|
|
1047
|
+
(d = r.socketManager) == null || d.disconnect(), await ((w = r.streamingManager) == null ? void 0 : w.disconnect()), delete r.streamingManager, delete r.socketManager, (b = (h = t.callbacks).onConnectionStateChange) == null || b.call(h, I.Disconnected);
|
|
1049
1048
|
}
|
|
1050
|
-
async function
|
|
1051
|
-
var w,
|
|
1049
|
+
async function C(d) {
|
|
1050
|
+
var w, h;
|
|
1052
1051
|
d !== r.chatMode && (l.track("agent-mode-change", {
|
|
1053
1052
|
mode: d
|
|
1054
|
-
}), r.chatMode = d, r.chatMode !==
|
|
1053
|
+
}), r.chatMode = d, r.chatMode !== j.Functional && await y(), (h = (w = t.callbacks).onModeChange) == null || h.call(w, d));
|
|
1055
1054
|
}
|
|
1056
1055
|
return {
|
|
1057
1056
|
agent: c,
|
|
@@ -1059,13 +1058,13 @@ async function pt(e, t) {
|
|
|
1059
1058
|
var d;
|
|
1060
1059
|
return (d = r.streamingManager) == null ? void 0 : d.streamType;
|
|
1061
1060
|
},
|
|
1062
|
-
starterMessages: ((
|
|
1061
|
+
starterMessages: ((M = c.knowledge) == null ? void 0 : M.starter_message) || [],
|
|
1063
1062
|
getSTTToken: () => i.getSTTToken(c.id),
|
|
1064
|
-
changeMode:
|
|
1063
|
+
changeMode: C,
|
|
1065
1064
|
enrichAnalytics: l.enrich,
|
|
1066
1065
|
async connect() {
|
|
1067
1066
|
var d;
|
|
1068
|
-
await
|
|
1067
|
+
await k(!0), l.track("agent-chat", {
|
|
1069
1068
|
event: "connect",
|
|
1070
1069
|
chatId: (d = r.chat) == null ? void 0 : d.id,
|
|
1071
1070
|
agentId: c.id,
|
|
@@ -1074,7 +1073,7 @@ async function pt(e, t) {
|
|
|
1074
1073
|
},
|
|
1075
1074
|
async reconnect() {
|
|
1076
1075
|
var d;
|
|
1077
|
-
await y(), await
|
|
1076
|
+
await y(), await k(!1), l.track("agent-chat", {
|
|
1078
1077
|
event: "reconnect",
|
|
1079
1078
|
chatId: (d = r.chat) == null ? void 0 : d.id,
|
|
1080
1079
|
agentId: c.id,
|
|
@@ -1091,113 +1090,113 @@ async function pt(e, t) {
|
|
|
1091
1090
|
});
|
|
1092
1091
|
},
|
|
1093
1092
|
async chat(d) {
|
|
1094
|
-
var
|
|
1093
|
+
var g, D, _, P, L;
|
|
1095
1094
|
const w = () => {
|
|
1096
|
-
if (t.mode ===
|
|
1097
|
-
throw new
|
|
1095
|
+
if (t.mode === j.DirectPlayback)
|
|
1096
|
+
throw new F("Direct playback is enabled, chat is disabled");
|
|
1098
1097
|
if (d.length >= 800)
|
|
1099
|
-
throw new
|
|
1098
|
+
throw new F("Message cannot be more than 800 characters");
|
|
1100
1099
|
if (d.length === 0)
|
|
1101
|
-
throw new
|
|
1102
|
-
if (r.chatMode ===
|
|
1103
|
-
throw new
|
|
1104
|
-
if (![
|
|
1100
|
+
throw new F("Message cannot be empty");
|
|
1101
|
+
if (r.chatMode === j.Maintenance)
|
|
1102
|
+
throw new F("Chat is in maintenance mode");
|
|
1103
|
+
if (![j.TextOnly, j.Playground].includes(r.chatMode)) {
|
|
1105
1104
|
if (!r.streamingManager)
|
|
1106
|
-
throw new
|
|
1105
|
+
throw new F("Streaming manager is not initialized");
|
|
1107
1106
|
if (!r.chat)
|
|
1108
|
-
throw new
|
|
1107
|
+
throw new F("Chat is not initialized");
|
|
1109
1108
|
}
|
|
1110
|
-
},
|
|
1111
|
-
var R,
|
|
1109
|
+
}, h = async () => {
|
|
1110
|
+
var R, T;
|
|
1112
1111
|
if (!r.chat) {
|
|
1113
|
-
const
|
|
1114
|
-
if (!
|
|
1115
|
-
throw new
|
|
1116
|
-
r.chat =
|
|
1112
|
+
const E = await fe(c, i, l, r.chatMode, t.persistentChat);
|
|
1113
|
+
if (!E.chat)
|
|
1114
|
+
throw new we(r.chatMode, !!t.persistentChat);
|
|
1115
|
+
r.chat = E.chat, (T = (R = t.callbacks).onNewChat) == null || T.call(R, r.chat.id);
|
|
1117
1116
|
}
|
|
1118
1117
|
return r.chat.id;
|
|
1119
|
-
},
|
|
1120
|
-
var
|
|
1121
|
-
return i.chat(c.id,
|
|
1118
|
+
}, b = async (R, T) => Z(() => {
|
|
1119
|
+
var E, m;
|
|
1120
|
+
return i.chat(c.id, T, {
|
|
1122
1121
|
chatMode: r.chatMode,
|
|
1123
|
-
streamId: (
|
|
1124
|
-
sessionId: (
|
|
1122
|
+
streamId: (E = r.streamingManager) == null ? void 0 : E.streamId,
|
|
1123
|
+
sessionId: (m = r.streamingManager) == null ? void 0 : m.sessionId,
|
|
1125
1124
|
messages: R.map(({
|
|
1126
|
-
matches:
|
|
1127
|
-
|
|
1128
|
-
}) =>
|
|
1125
|
+
matches: p,
|
|
1126
|
+
...$
|
|
1127
|
+
}) => $)
|
|
1129
1128
|
}, {
|
|
1130
|
-
...
|
|
1129
|
+
...ue(r.chatMode),
|
|
1131
1130
|
skipErrorHandler: !0
|
|
1132
1131
|
});
|
|
1133
1132
|
}, {
|
|
1134
1133
|
limit: 2,
|
|
1135
|
-
shouldRetryFn: (
|
|
1136
|
-
var A,
|
|
1137
|
-
const
|
|
1138
|
-
return !((
|
|
1134
|
+
shouldRetryFn: (E) => {
|
|
1135
|
+
var $, A, U, ee;
|
|
1136
|
+
const m = ($ = E == null ? void 0 : E.message) == null ? void 0 : $.includes("missing or invalid session_id");
|
|
1137
|
+
return !((A = E == null ? void 0 : E.message) == null ? void 0 : A.includes("Stream Error")) && !m ? ((ee = (U = t.callbacks).onError) == null || ee.call(U, E), !1) : !0;
|
|
1139
1138
|
},
|
|
1140
1139
|
onRetry: async () => {
|
|
1141
|
-
await y(), await
|
|
1140
|
+
await y(), await k(!1);
|
|
1142
1141
|
}
|
|
1143
1142
|
});
|
|
1144
1143
|
try {
|
|
1145
|
-
|
|
1146
|
-
id:
|
|
1144
|
+
f(), w(), r.messages.push({
|
|
1145
|
+
id: X(),
|
|
1147
1146
|
role: "user",
|
|
1148
1147
|
content: d,
|
|
1149
|
-
created_at: new Date(
|
|
1150
|
-
}), (
|
|
1151
|
-
const R = await
|
|
1148
|
+
created_at: new Date(x.update()).toISOString()
|
|
1149
|
+
}), (D = (g = t.callbacks).onNewMessage) == null || D.call(g, [...r.messages], "user");
|
|
1150
|
+
const R = await h(), T = await b([...r.messages], R);
|
|
1152
1151
|
return r.messages.push({
|
|
1153
|
-
id:
|
|
1152
|
+
id: X(),
|
|
1154
1153
|
role: "assistant",
|
|
1155
|
-
content:
|
|
1154
|
+
content: T.result || "",
|
|
1156
1155
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1157
|
-
context:
|
|
1158
|
-
matches:
|
|
1156
|
+
context: T.context,
|
|
1157
|
+
matches: T.matches
|
|
1159
1158
|
}), l.track("agent-message-send", {
|
|
1160
1159
|
event: "success",
|
|
1161
1160
|
mode: r.chatMode,
|
|
1162
1161
|
messages: r.messages.length + 1
|
|
1163
|
-
}),
|
|
1164
|
-
latency:
|
|
1162
|
+
}), T.result && ((P = (_ = t.callbacks).onNewMessage) == null || P.call(_, [...r.messages], "answer"), l.track("agent-message-received", {
|
|
1163
|
+
latency: x.get(!0),
|
|
1165
1164
|
mode: r.chatMode,
|
|
1166
1165
|
messages: r.messages.length
|
|
1167
|
-
})),
|
|
1166
|
+
})), T;
|
|
1168
1167
|
} catch (R) {
|
|
1169
|
-
throw ((
|
|
1168
|
+
throw ((L = r.messages[r.messages.length - 1]) == null ? void 0 : L.role) === "assistant" && r.messages.pop(), l.track("agent-message-send", {
|
|
1170
1169
|
event: "error",
|
|
1171
1170
|
mode: r.chatMode,
|
|
1172
1171
|
messages: r.messages.length
|
|
1173
1172
|
}), R;
|
|
1174
1173
|
}
|
|
1175
1174
|
},
|
|
1176
|
-
rate(d, w,
|
|
1177
|
-
var
|
|
1178
|
-
const
|
|
1175
|
+
rate(d, w, h) {
|
|
1176
|
+
var D, _, P, L;
|
|
1177
|
+
const b = r.messages.find((R) => R.id === d);
|
|
1179
1178
|
if (r.chat) {
|
|
1180
|
-
if (!
|
|
1179
|
+
if (!b)
|
|
1181
1180
|
throw new Error("Message not found");
|
|
1182
1181
|
} else
|
|
1183
1182
|
throw new Error("Chat is not initialized");
|
|
1184
|
-
const
|
|
1183
|
+
const g = ((D = b.matches) == null ? void 0 : D.map((R) => [R.document_id, R.id])) ?? [];
|
|
1185
1184
|
return l.track("agent-rate", {
|
|
1186
|
-
event:
|
|
1185
|
+
event: h ? "update" : "create",
|
|
1187
1186
|
thumb: w === 1 ? "up" : "down",
|
|
1188
|
-
knowledge_id: ((
|
|
1187
|
+
knowledge_id: ((_ = c.knowledge) == null ? void 0 : _.id) ?? "",
|
|
1189
1188
|
mode: r.chatMode,
|
|
1190
|
-
matches:
|
|
1189
|
+
matches: g,
|
|
1191
1190
|
score: w
|
|
1192
|
-
}),
|
|
1193
|
-
knowledge_id: ((
|
|
1191
|
+
}), h ? i.updateRating(c.id, r.chat.id, h, {
|
|
1192
|
+
knowledge_id: ((P = c.knowledge) == null ? void 0 : P.id) ?? "",
|
|
1194
1193
|
message_id: d,
|
|
1195
|
-
matches:
|
|
1194
|
+
matches: g,
|
|
1196
1195
|
score: w
|
|
1197
1196
|
}) : i.createRating(c.id, r.chat.id, {
|
|
1198
|
-
knowledge_id: ((
|
|
1197
|
+
knowledge_id: ((L = c.knowledge) == null ? void 0 : L.id) ?? "",
|
|
1199
1198
|
message_id: d,
|
|
1200
|
-
matches:
|
|
1199
|
+
matches: g,
|
|
1201
1200
|
score: w
|
|
1202
1201
|
});
|
|
1203
1202
|
},
|
|
@@ -1212,8 +1211,8 @@ async function pt(e, t) {
|
|
|
1212
1211
|
mode: r.chatMode
|
|
1213
1212
|
}), i.deleteRating(c.id, r.chat.id, d);
|
|
1214
1213
|
},
|
|
1215
|
-
speak(d) {
|
|
1216
|
-
var
|
|
1214
|
+
async speak(d) {
|
|
1215
|
+
var g, D, _, P;
|
|
1217
1216
|
if (!r.streamingManager)
|
|
1218
1217
|
throw new Error("Please connect to the agent first");
|
|
1219
1218
|
function w() {
|
|
@@ -1239,48 +1238,58 @@ async function pt(e, t) {
|
|
|
1239
1238
|
}
|
|
1240
1239
|
return d;
|
|
1241
1240
|
}
|
|
1242
|
-
const
|
|
1243
|
-
|
|
1244
|
-
|
|
1241
|
+
const h = w();
|
|
1242
|
+
l.track("agent-speak", h), x.update(), (g = r.chat) != null && g.id && h.type === "text" && (r.messages.push({
|
|
1243
|
+
id: X(),
|
|
1244
|
+
role: "assistant",
|
|
1245
|
+
content: h.input,
|
|
1246
|
+
created_at: new Date(x.get(!0)).toISOString()
|
|
1247
|
+
}), (_ = (D = t.callbacks).onNewMessage) == null || _.call(D, [...r.messages], "answer"));
|
|
1248
|
+
const b = Be(r.chatMode);
|
|
1249
|
+
return r.chat && b ? {
|
|
1250
|
+
duration: 0,
|
|
1251
|
+
status: "success"
|
|
1252
|
+
} : r.streamingManager.speak({
|
|
1253
|
+
script: h,
|
|
1245
1254
|
metadata: {
|
|
1246
|
-
chat_id: (
|
|
1255
|
+
chat_id: (P = r.chat) == null ? void 0 : P.id,
|
|
1247
1256
|
agent_id: c.id
|
|
1248
1257
|
}
|
|
1249
1258
|
});
|
|
1250
1259
|
}
|
|
1251
1260
|
};
|
|
1252
1261
|
}
|
|
1253
|
-
function
|
|
1262
|
+
function pt(e, t, n) {
|
|
1254
1263
|
const {
|
|
1255
|
-
getById:
|
|
1256
|
-
} =
|
|
1257
|
-
return
|
|
1264
|
+
getById: a
|
|
1265
|
+
} = de(t, n || q);
|
|
1266
|
+
return a(e);
|
|
1258
1267
|
}
|
|
1259
1268
|
export {
|
|
1260
|
-
|
|
1269
|
+
K as AgentActivityState,
|
|
1261
1270
|
Ce as AgentStatus,
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1271
|
+
we as ChatCreationFailed,
|
|
1272
|
+
j as ChatMode,
|
|
1273
|
+
pe as ChatModeDowngraded,
|
|
1265
1274
|
J as ChatProgress,
|
|
1266
|
-
|
|
1275
|
+
I as ConnectionState,
|
|
1267
1276
|
W as ConnectivityState,
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1277
|
+
te as DataChannelSignalMap,
|
|
1278
|
+
Se as DocumentType,
|
|
1279
|
+
Ee as KnowledgeType,
|
|
1280
|
+
ke as PlanGroup,
|
|
1281
|
+
_e as Providers,
|
|
1282
|
+
De as RateState,
|
|
1283
|
+
Y as StreamEvents,
|
|
1275
1284
|
N as StreamType,
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1285
|
+
v as StreamingState,
|
|
1286
|
+
Re as Subject,
|
|
1287
|
+
ve as UserPlan,
|
|
1288
|
+
F as ValidationError,
|
|
1289
|
+
ie as VideoType,
|
|
1290
|
+
Ie as VoiceAccess,
|
|
1291
|
+
ye as WsError,
|
|
1292
|
+
wt as createAgentManager,
|
|
1293
|
+
pt as getAgent,
|
|
1294
|
+
Me as mapVideoType
|
|
1286
1295
|
};
|