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