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