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