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