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