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