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