@d-id/client-sdk 1.0.19-beta.106 → 1.0.19-beta.108
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 +428 -385
- package/dist/index.umd.cjs +1 -1
- package/dist/src/utils/analytics.d.ts +2 -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(
|
|
117
|
-
},
|
|
118
|
-
|
|
114
|
+
} = t || {}, h = new WebSocket(`${a}?authorization=${J(n)}`);
|
|
115
|
+
h.onmessage = i, h.onclose = d, h.onerror = (p) => {
|
|
116
|
+
console.error(p), l == null || l("Websocket failed to connect", p), c(p);
|
|
117
|
+
}, h.onopen = (p) => {
|
|
118
|
+
s == null || s(p), 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,129 +208,129 @@ 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 E = (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:
|
|
293
|
-
createStream:
|
|
294
|
-
addIceCandidate:
|
|
295
|
-
} =
|
|
292
|
+
close: h,
|
|
293
|
+
createStream: p,
|
|
294
|
+
addIceCandidate: A
|
|
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
299
|
session_id: R
|
|
300
|
-
} = await
|
|
300
|
+
} = await p(r), o = new fe({
|
|
301
301
|
iceServers: z
|
|
302
|
-
}),
|
|
302
|
+
}), u = o.createDataChannel("JanusDataChannel");
|
|
303
303
|
if (!R)
|
|
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
|
+
E("peerConnection.onicecandidate", g), g.candidate && g.candidate.sdpMid && g.candidate.sdpMLineIndex !== null ? A(I, {
|
|
308
308
|
candidate: g.candidate.candidate,
|
|
309
309
|
sdpMid: g.candidate.sdpMid,
|
|
310
310
|
sdpMLineIndex: g.candidate.sdpMLineIndex
|
|
311
|
-
}, R) :
|
|
311
|
+
}, R) : A(I, {
|
|
312
312
|
candidate: null
|
|
313
313
|
}, R);
|
|
314
314
|
}, o.oniceconnectionstatechange = () => {
|
|
315
|
-
var
|
|
316
|
-
|
|
315
|
+
var m;
|
|
316
|
+
E("peerConnection.oniceconnectionstatechange => " + o.iceConnectionState);
|
|
317
317
|
const g = H(o.iceConnectionState);
|
|
318
|
-
g ===
|
|
319
|
-
var
|
|
320
|
-
(
|
|
321
|
-
}, 5e3) : (clearTimeout(
|
|
318
|
+
g === k.Connected ? s = setTimeout(() => {
|
|
319
|
+
var w;
|
|
320
|
+
(w = t.onConnectionStateChange) == null || w.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 [
|
|
329
|
-
|
|
323
|
+
var m;
|
|
324
|
+
E("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 [w, y] = g.data.split(":");
|
|
329
|
+
w === F.StreamReady && (clearTimeout(s), (m = t.onConnectionStateChange) == null || m.call(t, k.Connected));
|
|
330
330
|
}
|
|
331
|
-
}, await o.setRemoteDescription(L),
|
|
332
|
-
const
|
|
333
|
-
return
|
|
331
|
+
}, await o.setRemoteDescription(L), E("set remote description OK");
|
|
332
|
+
const _ = await o.createAnswer();
|
|
333
|
+
return E("create answer OK"), await o.setLocalDescription(_), E("set local description OK"), await d(I, _, R), E("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
|
|
@@ -342,22 +342,22 @@ async function ve(e, a, {
|
|
|
342
342
|
* Method to close RTC connection
|
|
343
343
|
*/
|
|
344
344
|
async disconnect() {
|
|
345
|
-
var g,
|
|
345
|
+
var g, m, w;
|
|
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, R).catch((y) => {
|
|
356
356
|
});
|
|
357
|
-
} catch (
|
|
358
|
-
|
|
357
|
+
} catch (y) {
|
|
358
|
+
E("Error on close stream connection", y);
|
|
359
359
|
}
|
|
360
|
-
(
|
|
360
|
+
(m = t.onConnectionStateChange) == null || m.call(t, k.New), (w = t.onVideoStateChange) == null || w.call(t, x.Stop), clearInterval(f);
|
|
361
361
|
}
|
|
362
362
|
},
|
|
363
363
|
/**
|
|
@@ -370,34 +370,37 @@ async function ve(e, a, {
|
|
|
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,83 @@ 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, p) => s.events[p] ? {
|
|
426
|
+
...h,
|
|
427
|
+
...s.events[p].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
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
454
|
+
function Se(e, r, c) {
|
|
455
|
+
var l, h;
|
|
456
|
+
const {
|
|
457
|
+
event: t,
|
|
458
|
+
...a
|
|
459
|
+
} = e, {
|
|
460
|
+
template: n
|
|
461
|
+
} = (r == null ? void 0 : r.llm) || {}, {
|
|
462
|
+
language: i
|
|
463
|
+
} = ((l = r == null ? void 0 : r.presenter) == null ? void 0 : l.voice) || {}, {
|
|
464
|
+
stitch: s
|
|
465
|
+
} = (r == null ? void 0 : r.presenter) || {};
|
|
466
|
+
return {
|
|
467
|
+
...a,
|
|
468
|
+
llm: {
|
|
469
|
+
...a.llm,
|
|
470
|
+
template: n
|
|
471
|
+
},
|
|
472
|
+
script: {
|
|
473
|
+
...a.script,
|
|
474
|
+
provider: {
|
|
475
|
+
...(h = a == null ? void 0 : a.script) == null ? void 0 : h.provider,
|
|
476
|
+
language: i
|
|
477
|
+
}
|
|
478
|
+
},
|
|
479
|
+
stitch: s,
|
|
480
|
+
...c
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
const Me = 1080;
|
|
484
|
+
let D = 0;
|
|
485
|
+
function ke(e, r) {
|
|
486
|
+
var c, t, a;
|
|
455
487
|
if (e.presenter) {
|
|
456
|
-
if (e.presenter.type ===
|
|
488
|
+
if (e.presenter.type === v.Clip)
|
|
457
489
|
return {
|
|
458
|
-
videoType:
|
|
490
|
+
videoType: v.Clip,
|
|
459
491
|
driver_id: e.presenter.driver_id,
|
|
460
492
|
presenter_id: e.presenter.presenter_id,
|
|
461
493
|
stream_warmup: !0
|
|
@@ -463,31 +495,32 @@ function Me(e, a) {
|
|
|
463
495
|
} else
|
|
464
496
|
throw new Error("Presenter is not initialized");
|
|
465
497
|
return {
|
|
466
|
-
videoType:
|
|
498
|
+
videoType: v.Talk,
|
|
467
499
|
source_url: e.presenter.source_url,
|
|
468
|
-
session_timeout: (
|
|
469
|
-
stream_warmup: ((
|
|
470
|
-
compatibility_mode: (
|
|
471
|
-
output_resolution: (
|
|
500
|
+
session_timeout: (c = r == null ? void 0 : r.streamOptions) == null ? void 0 : c.session_timeout,
|
|
501
|
+
stream_warmup: ((t = r == null ? void 0 : r.streamOptions) == null ? void 0 : t.stream_warmup) ?? !0,
|
|
502
|
+
compatibility_mode: (a = r == null ? void 0 : r.streamOptions) == null ? void 0 : a.compatibility_mode,
|
|
503
|
+
output_resolution: (r == null ? void 0 : r.outputResolution) || (e.presenter.stitch ? Me : void 0)
|
|
472
504
|
};
|
|
473
505
|
}
|
|
474
|
-
function
|
|
475
|
-
return e ===
|
|
476
|
-
[
|
|
506
|
+
function Y(e) {
|
|
507
|
+
return e === M.Playground ? {
|
|
508
|
+
[me]: "true"
|
|
477
509
|
} : {};
|
|
478
510
|
}
|
|
479
|
-
async function
|
|
511
|
+
async function Z(e, r, c, t) {
|
|
480
512
|
try {
|
|
481
|
-
const
|
|
482
|
-
return
|
|
513
|
+
const a = await r.newChat(e, Y(t));
|
|
514
|
+
return c.track("agent-chat", {
|
|
483
515
|
event: "created",
|
|
484
|
-
chat_id:
|
|
485
|
-
agent_id: e
|
|
486
|
-
|
|
487
|
-
|
|
516
|
+
chat_id: a.id,
|
|
517
|
+
agent_id: e,
|
|
518
|
+
mode: t
|
|
519
|
+
}), a;
|
|
520
|
+
} catch (a) {
|
|
488
521
|
try {
|
|
489
|
-
console.error(
|
|
490
|
-
const n = JSON.parse(
|
|
522
|
+
console.error(a);
|
|
523
|
+
const n = JSON.parse(a.message);
|
|
491
524
|
if ((n == null ? void 0 : n.kind) === "InsufficientCreditsError")
|
|
492
525
|
throw new Error("InsufficientCreditsError");
|
|
493
526
|
} catch (n) {
|
|
@@ -496,130 +529,134 @@ async function Y(e, a, t, i) {
|
|
|
496
529
|
throw new Error("Cannot create new chat");
|
|
497
530
|
}
|
|
498
531
|
}
|
|
499
|
-
function
|
|
500
|
-
return new Promise(async (n,
|
|
501
|
-
|
|
502
|
-
const
|
|
503
|
-
...
|
|
504
|
-
analytics:
|
|
532
|
+
function Ie(e, r, c, t, a) {
|
|
533
|
+
return new Promise(async (n, i) => {
|
|
534
|
+
D = 0;
|
|
535
|
+
const s = await ve(e.id, ke(e, r), {
|
|
536
|
+
...r,
|
|
537
|
+
analytics: t,
|
|
505
538
|
callbacks: {
|
|
506
|
-
...
|
|
539
|
+
...r.callbacks,
|
|
507
540
|
onConnectionStateChange: async (d) => {
|
|
508
|
-
var l,
|
|
509
|
-
d ===
|
|
510
|
-
|
|
511
|
-
})),
|
|
512
|
-
chat:
|
|
513
|
-
streamingManager:
|
|
514
|
-
}) :
|
|
541
|
+
var l, h;
|
|
542
|
+
d === k.Connected && (!a && r.mode !== M.DirectPlayback && (a = await Z(e.id, c, t, r.mode).catch((p) => {
|
|
543
|
+
i(p);
|
|
544
|
+
})), s ? n({
|
|
545
|
+
chat: a,
|
|
546
|
+
streamingManager: s
|
|
547
|
+
}) : a && i(new Error("Something went wrong while initializing the manager"))), (h = (l = r.callbacks).onConnectionStateChange) == null || h.call(l, d);
|
|
515
548
|
},
|
|
516
549
|
onVideoStateChange(d) {
|
|
517
|
-
var l,
|
|
518
|
-
(
|
|
550
|
+
var l, h;
|
|
551
|
+
(h = (l = r.callbacks).onVideoStateChange) == null || h.call(l, d), D > 0 && d === x.Start && t.linkTrack("agent-video", {
|
|
519
552
|
event: "start",
|
|
520
|
-
latency: Date.now() -
|
|
521
|
-
}, "start", [
|
|
553
|
+
latency: Date.now() - D
|
|
554
|
+
}, "start", [F.StreamVideoCreated]);
|
|
522
555
|
}
|
|
523
556
|
}
|
|
524
|
-
}).catch(
|
|
557
|
+
}).catch(i);
|
|
525
558
|
});
|
|
526
559
|
}
|
|
527
560
|
function W(e) {
|
|
528
|
-
let
|
|
561
|
+
let r = "";
|
|
529
562
|
if (e.greetings && e.greetings.length > 0) {
|
|
530
|
-
const
|
|
531
|
-
|
|
563
|
+
const c = Math.floor(Math.random() * e.greetings.length);
|
|
564
|
+
r = e.greetings[c];
|
|
532
565
|
} else
|
|
533
|
-
|
|
566
|
+
r = `Hi! I'm ${e.preview_name || "My Agent"}. How can I help you?`;
|
|
534
567
|
return [{
|
|
535
|
-
content:
|
|
536
|
-
id:
|
|
568
|
+
content: r,
|
|
569
|
+
id: K(),
|
|
537
570
|
role: "assistant",
|
|
538
571
|
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
539
572
|
}];
|
|
540
573
|
}
|
|
541
|
-
|
|
574
|
+
function Re(e) {
|
|
575
|
+
if (e.answer !== void 0)
|
|
576
|
+
return e.answer;
|
|
577
|
+
let r = 0, c = "";
|
|
578
|
+
for (; r in e; )
|
|
579
|
+
c += e[r], r++;
|
|
580
|
+
return c;
|
|
581
|
+
}
|
|
582
|
+
function Ee(e, r, c, t, a) {
|
|
583
|
+
if (!(e === N.Partial || e === N.Answer))
|
|
584
|
+
return;
|
|
585
|
+
const n = t.messages[t.messages.length - 1];
|
|
586
|
+
if ((n == null ? void 0 : n.role) !== "assistant")
|
|
587
|
+
return;
|
|
588
|
+
const {
|
|
589
|
+
content: i,
|
|
590
|
+
sequence: s
|
|
591
|
+
} = r;
|
|
592
|
+
e === N.Partial ? c[s] = i : c.answer = i;
|
|
593
|
+
const d = Re(c);
|
|
594
|
+
n.content !== d && (n.content = d, a == null || a(t.messages, e));
|
|
595
|
+
}
|
|
596
|
+
async function Ae(e, r) {
|
|
542
597
|
var L, z, R;
|
|
598
|
+
let c = {};
|
|
543
599
|
const t = {
|
|
544
600
|
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");
|
|
601
|
+
chatMode: r.mode || M.Functional
|
|
602
|
+
}, 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);
|
|
603
|
+
t.messages = W(d), (z = (L = r.callbacks).onNewMessage) == null || z.call(L, t.messages, "answer");
|
|
550
604
|
const l = Ce({
|
|
551
|
-
token:
|
|
605
|
+
token: i,
|
|
552
606
|
agent: d,
|
|
553
|
-
...
|
|
607
|
+
...r
|
|
554
608
|
});
|
|
555
609
|
l.track("agent-sdk", {
|
|
556
610
|
event: "loaded",
|
|
557
611
|
..._e(d)
|
|
558
612
|
});
|
|
559
|
-
const
|
|
560
|
-
onMessage: (o,
|
|
561
|
-
var f,
|
|
562
|
-
if ("content" in
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
o = o
|
|
572
|
-
|
|
573
|
-
if (o
|
|
574
|
-
const
|
|
575
|
-
|
|
576
|
-
...
|
|
577
|
-
|
|
578
|
-
A.llm = {
|
|
579
|
-
...A.llm,
|
|
580
|
-
template: D
|
|
581
|
-
}, l.linkTrack("agent-video", {
|
|
582
|
-
...A
|
|
583
|
-
}, h.StreamVideoCreated, ["start"]);
|
|
584
|
-
} else if (M.includes(o)) {
|
|
585
|
-
const P = o.split("/")[1], A = {
|
|
586
|
-
...m,
|
|
587
|
-
event: P
|
|
588
|
-
};
|
|
589
|
-
A.llm = {
|
|
590
|
-
...A.llm,
|
|
591
|
-
template: D
|
|
592
|
-
}, l.track("agent-video", {
|
|
593
|
-
...A,
|
|
594
|
-
event: P
|
|
613
|
+
const h = {
|
|
614
|
+
onMessage: (o, u) => {
|
|
615
|
+
var f, _, g, m;
|
|
616
|
+
if ("content" in u)
|
|
617
|
+
Ee(o, u, c, t, r.callbacks.onNewMessage), o === N.Answer && l.track("agent-message-received", {
|
|
618
|
+
messages: t.messages.length,
|
|
619
|
+
mode: t.chatMode
|
|
620
|
+
});
|
|
621
|
+
else {
|
|
622
|
+
const w = F, y = [w.StreamVideoDone, w.StreamVideoError, w.StreamVideoRejected], C = [w.StreamFailed, w.StreamVideoError, w.StreamVideoRejected], S = Se(u, d, {
|
|
623
|
+
mode: t.chatMode
|
|
624
|
+
});
|
|
625
|
+
if (o = o, o === w.StreamVideoCreated)
|
|
626
|
+
l.linkTrack("agent-video", S, w.StreamVideoCreated, ["start"]);
|
|
627
|
+
else if (y.includes(o)) {
|
|
628
|
+
const $ = o.split("/")[1];
|
|
629
|
+
l.track("agent-video", {
|
|
630
|
+
...S,
|
|
631
|
+
event: $
|
|
595
632
|
});
|
|
596
633
|
}
|
|
597
|
-
|
|
598
|
-
data:
|
|
599
|
-
})),
|
|
634
|
+
C.includes(o) && ((_ = (f = r.callbacks).onError) == null || _.call(f, new Error(`Stream failed with event ${o}`), {
|
|
635
|
+
data: u
|
|
636
|
+
})), u.event === w.StreamDone && ((m = (g = r.callbacks).onConnectionStateChange) == null || m.call(g, k.New));
|
|
600
637
|
}
|
|
601
638
|
}
|
|
602
639
|
};
|
|
603
|
-
async function
|
|
604
|
-
var
|
|
605
|
-
|
|
606
|
-
const
|
|
607
|
-
throw I(
|
|
608
|
-
}), [
|
|
640
|
+
async function p(o) {
|
|
641
|
+
var w, y, C, S, $;
|
|
642
|
+
D = 0, o && (delete t.chat, t.messages = W(d), (y = (w = r.callbacks).onNewMessage) == null || y.call(w, t.messages, "answer"));
|
|
643
|
+
const u = r.mode === M.DirectPlayback ? Promise.resolve(void 0) : ue(r.auth, n, h), f = Ie(d, r, s, l, t.chat).catch((P) => {
|
|
644
|
+
throw I(M.Maintenance), P;
|
|
645
|
+
}), [_, {
|
|
609
646
|
streamingManager: g,
|
|
610
|
-
chat:
|
|
611
|
-
}] = await Promise.all([
|
|
612
|
-
|
|
647
|
+
chat: m
|
|
648
|
+
}] = await Promise.all([u, f]);
|
|
649
|
+
m && m.id !== ((C = t.chat) == null ? void 0 : C.id) && (($ = (S = r.callbacks).onNewChat) == null || $.call(S, m.id)), t.streamingManager = g, t.socketManager = _, t.chat = m, I((m == null ? void 0 : m.chat_mode) ?? r.mode ?? M.Functional);
|
|
613
650
|
}
|
|
614
|
-
async function
|
|
615
|
-
var o,
|
|
616
|
-
(o = t.socketManager) == null || o.disconnect(), await ((
|
|
651
|
+
async function A() {
|
|
652
|
+
var o, u;
|
|
653
|
+
(o = t.socketManager) == null || o.disconnect(), await ((u = t.streamingManager) == null ? void 0 : u.disconnect()), delete t.streamingManager, delete t.socketManager;
|
|
617
654
|
}
|
|
618
655
|
async function I(o) {
|
|
619
|
-
var
|
|
656
|
+
var u, f;
|
|
620
657
|
o !== t.chatMode && (l.track("agent-mode-change", {
|
|
621
658
|
mode: o
|
|
622
|
-
}), t.chatMode = o, t.chatMode !==
|
|
659
|
+
}), t.chatMode = o, t.chatMode !== M.Functional && await A(), (f = (u = r.callbacks).onModeChange) == null || f.call(u, o));
|
|
623
660
|
}
|
|
624
661
|
return {
|
|
625
662
|
agent: d,
|
|
@@ -627,7 +664,7 @@ async function Ee(e, a) {
|
|
|
627
664
|
changeMode: I,
|
|
628
665
|
async connect() {
|
|
629
666
|
var o;
|
|
630
|
-
await
|
|
667
|
+
await p(!0), l.track("agent-chat", {
|
|
631
668
|
event: "connect",
|
|
632
669
|
chatId: (o = t.chat) == null ? void 0 : o.id,
|
|
633
670
|
agentId: d.id,
|
|
@@ -636,7 +673,7 @@ async function Ee(e, a) {
|
|
|
636
673
|
},
|
|
637
674
|
async reconnect() {
|
|
638
675
|
var o;
|
|
639
|
-
await
|
|
676
|
+
await A(), await p(!1), l.track("agent-chat", {
|
|
640
677
|
event: "reconnect",
|
|
641
678
|
chatId: (o = t.chat) == null ? void 0 : o.id,
|
|
642
679
|
agentId: d.id,
|
|
@@ -645,7 +682,7 @@ async function Ee(e, a) {
|
|
|
645
682
|
},
|
|
646
683
|
async disconnect() {
|
|
647
684
|
var o;
|
|
648
|
-
await
|
|
685
|
+
await A(), l.track("agent-chat", {
|
|
649
686
|
event: "disconnect",
|
|
650
687
|
chatId: (o = t.chat) == null ? void 0 : o.id,
|
|
651
688
|
agentId: d.id,
|
|
@@ -653,106 +690,112 @@ async function Ee(e, a) {
|
|
|
653
690
|
});
|
|
654
691
|
},
|
|
655
692
|
async chat(o) {
|
|
656
|
-
var f,
|
|
657
|
-
const
|
|
693
|
+
var f, _, g, m, w, y;
|
|
694
|
+
const u = K();
|
|
695
|
+
c = {};
|
|
658
696
|
try {
|
|
659
|
-
if (
|
|
697
|
+
if (D = Date.now(), r.mode === M.DirectPlayback)
|
|
660
698
|
throw new Error("Direct playback is enabled, chat is disabled");
|
|
661
699
|
if (o.length >= 800)
|
|
662
700
|
throw new Error("Message cannot be more than 800 characters");
|
|
663
701
|
if (o.length === 0)
|
|
664
702
|
throw new Error("Message cannot be empty");
|
|
665
|
-
if (t.chatMode ===
|
|
703
|
+
if (t.chatMode === M.Maintenance)
|
|
666
704
|
throw new Error("Chat is in maintenance mode");
|
|
667
|
-
if (![
|
|
705
|
+
if (![M.TextOnly, M.Playground].includes(t.chatMode))
|
|
668
706
|
if (t.streamingManager) {
|
|
669
707
|
if (!t.chat)
|
|
670
708
|
throw new Error("Chat is not initialized");
|
|
671
709
|
} else
|
|
672
710
|
throw new Error("Streaming manager is not initialized");
|
|
673
|
-
t.chat || (t.chat = await
|
|
674
|
-
id:
|
|
711
|
+
t.chat || (t.chat = await Z(d.id, s, l, t.chatMode), (_ = (f = r.callbacks).onNewChat) == null || _.call(f, t.chat.id)), t.messages.push({
|
|
712
|
+
id: K(),
|
|
675
713
|
role: "user",
|
|
676
714
|
content: o,
|
|
677
|
-
created_at: new Date(
|
|
678
|
-
}), (
|
|
715
|
+
created_at: new Date(D).toISOString()
|
|
716
|
+
}), (m = (g = r.callbacks).onNewMessage) == null || m.call(g, t.messages, "user");
|
|
679
717
|
const C = {
|
|
680
|
-
id:
|
|
718
|
+
id: u,
|
|
681
719
|
role: "assistant",
|
|
682
720
|
content: "",
|
|
683
721
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
684
722
|
matches: []
|
|
685
|
-
},
|
|
723
|
+
}, S = [...t.messages];
|
|
686
724
|
t.messages.push(C);
|
|
687
|
-
const
|
|
688
|
-
var
|
|
689
|
-
return
|
|
690
|
-
sessionId: (
|
|
691
|
-
streamId: (
|
|
725
|
+
const $ = (T) => {
|
|
726
|
+
var b, B;
|
|
727
|
+
return s.chat(d.id, T, {
|
|
728
|
+
sessionId: (b = t.streamingManager) == null ? void 0 : b.sessionId,
|
|
729
|
+
streamId: (B = t.streamingManager) == null ? void 0 : B.streamId,
|
|
692
730
|
chatMode: t.chatMode,
|
|
693
|
-
messages:
|
|
694
|
-
},
|
|
695
|
-
},
|
|
696
|
-
var
|
|
697
|
-
if (!((
|
|
698
|
-
throw
|
|
699
|
-
return await
|
|
731
|
+
messages: S
|
|
732
|
+
}, Y(t.chatMode));
|
|
733
|
+
}, P = await $(t.chat.id).catch(async (T) => {
|
|
734
|
+
var b;
|
|
735
|
+
if (!((b = T == null ? void 0 : T.message) != null && b.includes("missing or invalid session_id")))
|
|
736
|
+
throw T;
|
|
737
|
+
return await A(), await p(!1), $(t.chat.id);
|
|
700
738
|
});
|
|
701
739
|
return l.track("agent-message-send", {
|
|
702
740
|
event: "success",
|
|
741
|
+
mode: t.chatMode,
|
|
703
742
|
messages: t.messages.length + 1
|
|
704
|
-
}),
|
|
705
|
-
latency: Date.now() -
|
|
743
|
+
}), P.result && (C.content = P.result, C.matches = P.matches, C.context = P.context, l.track("agent-message-received", {
|
|
744
|
+
latency: Date.now() - D,
|
|
745
|
+
mode: t.chatMode,
|
|
706
746
|
messages: t.messages.length
|
|
707
|
-
}), (
|
|
747
|
+
}), (y = (w = r.callbacks).onNewMessage) == null || y.call(w, t.messages, "answer")), P;
|
|
708
748
|
} catch (C) {
|
|
709
|
-
throw t.messages[t.messages.length - 1].id ===
|
|
749
|
+
throw t.messages[t.messages.length - 1].id === u && t.messages.pop(), l.track("agent-message-send", {
|
|
710
750
|
event: "error",
|
|
751
|
+
mode: t.chatMode,
|
|
711
752
|
messages: t.messages.length
|
|
712
753
|
}), C;
|
|
713
754
|
}
|
|
714
755
|
},
|
|
715
|
-
rate(o,
|
|
716
|
-
var
|
|
717
|
-
const
|
|
756
|
+
rate(o, u, f) {
|
|
757
|
+
var m, w, y, C;
|
|
758
|
+
const _ = t.messages.find((S) => S.id === o);
|
|
718
759
|
if (t.chat) {
|
|
719
|
-
if (!
|
|
760
|
+
if (!_)
|
|
720
761
|
throw new Error("Message not found");
|
|
721
762
|
} else
|
|
722
763
|
throw new Error("Chat is not initialized");
|
|
723
|
-
const g = ((
|
|
764
|
+
const g = ((m = _.matches) == null ? void 0 : m.map((S) => [S.document_id, S.id])) ?? [];
|
|
724
765
|
return l.track("agent-rate", {
|
|
725
766
|
event: f ? "update" : "create",
|
|
726
|
-
thumb:
|
|
727
|
-
knowledge_id: ((
|
|
767
|
+
thumb: u === 1 ? "up" : "down",
|
|
768
|
+
knowledge_id: ((w = d.knowledge) == null ? void 0 : w.id) ?? "",
|
|
769
|
+
mode: t.chatMode,
|
|
728
770
|
matches: g,
|
|
729
|
-
score:
|
|
730
|
-
}), f ?
|
|
731
|
-
knowledge_id: ((
|
|
771
|
+
score: u
|
|
772
|
+
}), f ? s.updateRating(d.id, t.chat.id, f, {
|
|
773
|
+
knowledge_id: ((y = d.knowledge) == null ? void 0 : y.id) ?? "",
|
|
732
774
|
message_id: o,
|
|
733
775
|
matches: g,
|
|
734
|
-
score:
|
|
735
|
-
}) :
|
|
776
|
+
score: u
|
|
777
|
+
}) : s.createRating(d.id, t.chat.id, {
|
|
736
778
|
knowledge_id: ((C = d.knowledge) == null ? void 0 : C.id) ?? "",
|
|
737
779
|
message_id: o,
|
|
738
780
|
matches: g,
|
|
739
|
-
score:
|
|
781
|
+
score: u
|
|
740
782
|
});
|
|
741
783
|
},
|
|
742
784
|
deleteRate(o) {
|
|
743
|
-
var
|
|
785
|
+
var u;
|
|
744
786
|
if (!t.chat)
|
|
745
787
|
throw new Error("Chat is not initialized");
|
|
746
788
|
return l.track("agent-rate-delete", {
|
|
747
789
|
type: "text",
|
|
748
|
-
chat_id: (
|
|
749
|
-
id: o
|
|
750
|
-
|
|
790
|
+
chat_id: (u = t.chat) == null ? void 0 : u.id,
|
|
791
|
+
id: o,
|
|
792
|
+
mode: t.chatMode
|
|
793
|
+
}), s.deleteRating(d.id, t.chat.id, o);
|
|
751
794
|
},
|
|
752
795
|
speak(o) {
|
|
753
796
|
if (!t.streamingManager)
|
|
754
797
|
throw new Error("Please connect to the agent first");
|
|
755
|
-
function
|
|
798
|
+
function u() {
|
|
756
799
|
if (typeof o == "string") {
|
|
757
800
|
if (!d.presenter)
|
|
758
801
|
throw new Error("Presenter is not initialized");
|
|
@@ -765,34 +808,34 @@ async function Ee(e, a) {
|
|
|
765
808
|
}
|
|
766
809
|
return o;
|
|
767
810
|
}
|
|
768
|
-
const f =
|
|
811
|
+
const f = u();
|
|
769
812
|
return l.track("agent-speak", f), t.streamingManager.speak({
|
|
770
813
|
script: f
|
|
771
814
|
});
|
|
772
815
|
}
|
|
773
816
|
};
|
|
774
817
|
}
|
|
775
|
-
function
|
|
818
|
+
function $e(e, r, c) {
|
|
776
819
|
const {
|
|
777
|
-
getById:
|
|
778
|
-
} =
|
|
779
|
-
return
|
|
820
|
+
getById: t
|
|
821
|
+
} = j(r, c || O);
|
|
822
|
+
return t(e);
|
|
780
823
|
}
|
|
781
824
|
export {
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
825
|
+
M as ChatMode,
|
|
826
|
+
N as ChatProgress,
|
|
827
|
+
k as ConnectionState,
|
|
785
828
|
re as DocumentType,
|
|
786
829
|
ne as KnowledgeType,
|
|
787
830
|
G as PlanGroup,
|
|
788
831
|
ae as Providers,
|
|
789
832
|
ee as RateState,
|
|
790
|
-
|
|
791
|
-
|
|
833
|
+
F as StreamEvents,
|
|
834
|
+
x as StreamingState,
|
|
792
835
|
te as Subject,
|
|
793
|
-
|
|
794
|
-
|
|
836
|
+
Q as UserPlan,
|
|
837
|
+
v as VideoType,
|
|
795
838
|
ie as VoiceAccess,
|
|
796
|
-
|
|
797
|
-
|
|
839
|
+
Ae as createAgentManager,
|
|
840
|
+
$e as getAgent
|
|
798
841
|
};
|