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