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