@d-id/client-sdk 1.0.19 → 1.0.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const
|
|
2
|
-
function
|
|
1
|
+
const C = "https://api.d-id.com", B = "wss://notifications.d-id.com";
|
|
2
|
+
function U(e) {
|
|
3
3
|
if (e.type === "bearer")
|
|
4
4
|
return `Bearer ${e.token}`;
|
|
5
5
|
if (e.type === "basic")
|
|
@@ -8,19 +8,19 @@ function q(e) {
|
|
|
8
8
|
return `Client-Key ${e.clientKey}`;
|
|
9
9
|
throw new Error(`Unknown auth type: ${e}`);
|
|
10
10
|
}
|
|
11
|
-
function y(e, i =
|
|
11
|
+
function y(e, i = C) {
|
|
12
12
|
const r = async (t, n) => {
|
|
13
13
|
const a = await fetch(i + (t != null && t.startsWith("/") ? t : `/${t}`), {
|
|
14
14
|
...n,
|
|
15
15
|
headers: {
|
|
16
16
|
...n == null ? void 0 : n.headers,
|
|
17
|
-
Authorization:
|
|
17
|
+
Authorization: U(e),
|
|
18
18
|
"Content-Type": "application/json"
|
|
19
19
|
}
|
|
20
20
|
});
|
|
21
21
|
if (!a.ok) {
|
|
22
|
-
let
|
|
23
|
-
throw new Error(
|
|
22
|
+
let s = await a.text().catch(() => "Failed to fetch");
|
|
23
|
+
throw new Error(s);
|
|
24
24
|
}
|
|
25
25
|
return a.json();
|
|
26
26
|
};
|
|
@@ -54,7 +54,7 @@ function y(e, i = v) {
|
|
|
54
54
|
}
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
|
-
function
|
|
57
|
+
function J(e, i = C) {
|
|
58
58
|
const r = y(e, `${i}/agents`);
|
|
59
59
|
return {
|
|
60
60
|
create(t, n) {
|
|
@@ -75,12 +75,12 @@ function T(e, i = v) {
|
|
|
75
75
|
newChat(t, n) {
|
|
76
76
|
return r.post(`/${t}/chat`, void 0, n);
|
|
77
77
|
},
|
|
78
|
-
chat(t, n, a,
|
|
79
|
-
return r.post(`/${t}/chat/${n}`, a,
|
|
78
|
+
chat(t, n, a, s) {
|
|
79
|
+
return r.post(`/${t}/chat/${n}`, a, s);
|
|
80
80
|
}
|
|
81
81
|
};
|
|
82
82
|
}
|
|
83
|
-
function
|
|
83
|
+
function F(e, i = C) {
|
|
84
84
|
const r = y(e, `${i}/knowledge`);
|
|
85
85
|
return {
|
|
86
86
|
createKnowledge(t, n) {
|
|
@@ -117,7 +117,7 @@ function D(e, i = v) {
|
|
|
117
117
|
}
|
|
118
118
|
};
|
|
119
119
|
}
|
|
120
|
-
function
|
|
120
|
+
function D(e, i = C) {
|
|
121
121
|
const r = y(e, `${i}/chats/ratings`);
|
|
122
122
|
return {
|
|
123
123
|
create(t, n) {
|
|
@@ -142,15 +142,15 @@ function G(e) {
|
|
|
142
142
|
host: n,
|
|
143
143
|
auth: a
|
|
144
144
|
} = e, {
|
|
145
|
-
onMessage:
|
|
146
|
-
onOpen:
|
|
147
|
-
onClose:
|
|
148
|
-
onError:
|
|
149
|
-
} = t || {},
|
|
150
|
-
|
|
151
|
-
console.log(
|
|
152
|
-
},
|
|
153
|
-
|
|
145
|
+
onMessage: s = null,
|
|
146
|
+
onOpen: u = null,
|
|
147
|
+
onClose: m = null,
|
|
148
|
+
onError: f = null
|
|
149
|
+
} = t || {}, g = new WebSocket(`${n}?authorization=${U(a)}`);
|
|
150
|
+
g.onmessage = s, g.onclose = m, g.onerror = (d) => {
|
|
151
|
+
console.log(d), f == null || f(d), r(d);
|
|
152
|
+
}, g.onopen = (d) => {
|
|
153
|
+
u == null || u(d), i(g);
|
|
154
154
|
};
|
|
155
155
|
});
|
|
156
156
|
}
|
|
@@ -169,14 +169,14 @@ async function Q(e) {
|
|
|
169
169
|
}
|
|
170
170
|
return r;
|
|
171
171
|
}
|
|
172
|
-
async function X(e, i, r
|
|
173
|
-
const t =
|
|
172
|
+
async function X(e, i, r) {
|
|
173
|
+
const t = r ? [r] : [], n = await Q({
|
|
174
174
|
auth: e,
|
|
175
|
-
host:
|
|
175
|
+
host: i,
|
|
176
176
|
callbacks: {
|
|
177
177
|
onMessage: (a) => {
|
|
178
|
-
const
|
|
179
|
-
t.forEach((
|
|
178
|
+
const s = JSON.parse(a.data);
|
|
179
|
+
t.forEach((u) => u(s.event, s));
|
|
180
180
|
}
|
|
181
181
|
}
|
|
182
182
|
});
|
|
@@ -186,8 +186,8 @@ async function X(e, i, r = J) {
|
|
|
186
186
|
subscribeToEvents: (a) => t.push(a)
|
|
187
187
|
};
|
|
188
188
|
}
|
|
189
|
-
var Y = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(Y || {}), Z = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(Z || {}), _ = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(_ || {}), A = /* @__PURE__ */ ((e) => (e.ChatAnswer = "chat/answer", e.ChatPartial = "chat/partial", e.StreamDone = "stream/done", e.StreamStarted = "stream/started", e))(A || {}), O = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(O || {}),
|
|
190
|
-
function
|
|
189
|
+
var Y = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(Y || {}), Z = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(Z || {}), _ = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(_ || {}), A = /* @__PURE__ */ ((e) => (e.ChatAnswer = "chat/answer", e.ChatPartial = "chat/partial", e.StreamDone = "stream/done", e.StreamStarted = "stream/started", e))(A || {}), O = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(O || {}), j = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e))(j || {}), K = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Complete = "done", e))(K || {}), ee = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(ee || {}), te = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(te || {}), ne = /* @__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))(ne || {}), R = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e))(R || {});
|
|
190
|
+
function re(e) {
|
|
191
191
|
return e.presenter.type === R.Clip ? {
|
|
192
192
|
videoType: R.Clip,
|
|
193
193
|
driver_id: e.presenter.driver_id,
|
|
@@ -197,87 +197,87 @@ function ne(e) {
|
|
|
197
197
|
source_url: e.presenter.source_url
|
|
198
198
|
};
|
|
199
199
|
}
|
|
200
|
-
function
|
|
200
|
+
function H(e, i, r, t) {
|
|
201
201
|
return new Promise(async (n, a) => {
|
|
202
|
-
const
|
|
202
|
+
const s = await ce(re(e), {
|
|
203
203
|
...i,
|
|
204
204
|
callbacks: {
|
|
205
205
|
...i.callbacks,
|
|
206
|
-
onConnectionStateChange: async (
|
|
207
|
-
var
|
|
208
|
-
|
|
206
|
+
onConnectionStateChange: async (u) => {
|
|
207
|
+
var m, f;
|
|
208
|
+
u === "connected" ? (t || (t = await r.newChat(e.id)), n({
|
|
209
209
|
chat: t,
|
|
210
|
-
streamingManager:
|
|
211
|
-
})) :
|
|
210
|
+
streamingManager: s
|
|
211
|
+
})) : u === "failed" && a(new Error("Cannot create connection")), (f = (m = i.callbacks).onConnectionStateChange) == null || f.call(m, u);
|
|
212
212
|
},
|
|
213
213
|
// TODO remove when webscoket will return partial
|
|
214
|
-
onMessage: (
|
|
215
|
-
var
|
|
216
|
-
|
|
217
|
-
content:
|
|
218
|
-
event:
|
|
214
|
+
onMessage: (u, m) => {
|
|
215
|
+
var f, g;
|
|
216
|
+
u === A.ChatPartial && ((g = (f = i.callbacks).onChatEvents) == null || g.call(f, K.Partial, {
|
|
217
|
+
content: m,
|
|
218
|
+
event: K.Partial
|
|
219
219
|
}));
|
|
220
220
|
}
|
|
221
221
|
}
|
|
222
222
|
});
|
|
223
223
|
});
|
|
224
224
|
}
|
|
225
|
-
async function
|
|
226
|
-
const r = i.baseURL ||
|
|
225
|
+
async function de(e, i) {
|
|
226
|
+
const r = i.baseURL || C, t = i.wsURL || B, n = new AbortController(), a = J(i.auth, r), s = D(i.auth, r), u = F(i.auth, r), m = await a.getById(e), f = await X(i.auth, t, i.callbacks.onChatEvents);
|
|
227
227
|
let {
|
|
228
|
-
chat:
|
|
229
|
-
streamingManager:
|
|
230
|
-
} = await
|
|
228
|
+
chat: g,
|
|
229
|
+
streamingManager: d
|
|
230
|
+
} = await H(m, i, a);
|
|
231
231
|
return {
|
|
232
|
-
agent:
|
|
232
|
+
agent: m,
|
|
233
233
|
async reconnectToChat() {
|
|
234
234
|
const {
|
|
235
|
-
streamingManager:
|
|
236
|
-
} = await
|
|
237
|
-
|
|
235
|
+
streamingManager: c
|
|
236
|
+
} = await H(m, i, a, g);
|
|
237
|
+
d = c;
|
|
238
238
|
},
|
|
239
239
|
terminate() {
|
|
240
|
-
return
|
|
241
|
-
},
|
|
242
|
-
chatId:
|
|
243
|
-
chat(
|
|
244
|
-
return
|
|
245
|
-
sessionId:
|
|
246
|
-
streamId:
|
|
247
|
-
messages:
|
|
240
|
+
return n.abort(), f.terminate(), d.terminate();
|
|
241
|
+
},
|
|
242
|
+
chatId: g.id,
|
|
243
|
+
chat(c) {
|
|
244
|
+
return a.chat(e, g.id, {
|
|
245
|
+
sessionId: d.sessionId,
|
|
246
|
+
streamId: d.streamId,
|
|
247
|
+
messages: c
|
|
248
248
|
}, {
|
|
249
|
-
signal:
|
|
249
|
+
signal: n.signal
|
|
250
250
|
});
|
|
251
251
|
},
|
|
252
|
-
rate(
|
|
253
|
-
return
|
|
252
|
+
rate(c, p) {
|
|
253
|
+
return p ? s.update(p, c) : s.create(c);
|
|
254
254
|
},
|
|
255
|
-
deleteRate(
|
|
256
|
-
return
|
|
255
|
+
deleteRate(c) {
|
|
256
|
+
return s.delete(c);
|
|
257
257
|
},
|
|
258
|
-
speak(
|
|
259
|
-
let
|
|
260
|
-
return
|
|
258
|
+
speak(c) {
|
|
259
|
+
let p;
|
|
260
|
+
return c.type === "text" ? p = {
|
|
261
261
|
script: {
|
|
262
262
|
type: "text",
|
|
263
|
-
provider:
|
|
264
|
-
input:
|
|
265
|
-
ssml:
|
|
263
|
+
provider: c.provider,
|
|
264
|
+
input: c.input,
|
|
265
|
+
ssml: c.ssml || !1
|
|
266
266
|
}
|
|
267
|
-
} :
|
|
267
|
+
} : c.type === "audio" && (p = {
|
|
268
268
|
script: {
|
|
269
269
|
type: "audio",
|
|
270
|
-
audio_url:
|
|
270
|
+
audio_url: c.audio_url
|
|
271
271
|
}
|
|
272
|
-
}),
|
|
272
|
+
}), d.speak(p);
|
|
273
273
|
},
|
|
274
274
|
getStarterMessages() {
|
|
275
|
-
var
|
|
276
|
-
return (
|
|
275
|
+
var c, p;
|
|
276
|
+
return (c = m.knowledge) != null && c.id ? u.getKnowledge((p = m.knowledge) == null ? void 0 : p.id).then((w) => (w == null ? void 0 : w.starter_message) || []) : Promise.resolve([]);
|
|
277
277
|
}
|
|
278
278
|
};
|
|
279
279
|
}
|
|
280
|
-
function
|
|
280
|
+
function ae(e, i) {
|
|
281
281
|
const r = y(e, i);
|
|
282
282
|
return {
|
|
283
283
|
createStream(t) {
|
|
@@ -312,7 +312,7 @@ function re(e, i) {
|
|
|
312
312
|
}
|
|
313
313
|
};
|
|
314
314
|
}
|
|
315
|
-
function
|
|
315
|
+
function ie(e, i) {
|
|
316
316
|
const r = y(e, i);
|
|
317
317
|
return {
|
|
318
318
|
createStream(t, n) {
|
|
@@ -323,23 +323,23 @@ function ae(e, i) {
|
|
|
323
323
|
config: t.config
|
|
324
324
|
}, n);
|
|
325
325
|
},
|
|
326
|
-
startConnection(t, n, a,
|
|
326
|
+
startConnection(t, n, a, s) {
|
|
327
327
|
return r.post(`/talks/streams/${t}/sdp`, {
|
|
328
328
|
session_id: a,
|
|
329
329
|
answer: n
|
|
330
|
-
},
|
|
330
|
+
}, s);
|
|
331
331
|
},
|
|
332
|
-
addIceCandidate(t, n, a,
|
|
332
|
+
addIceCandidate(t, n, a, s) {
|
|
333
333
|
return r.post(`/talks/streams/${t}/ice`, {
|
|
334
334
|
session_id: a,
|
|
335
335
|
...n
|
|
336
|
-
},
|
|
336
|
+
}, s);
|
|
337
337
|
},
|
|
338
|
-
sendStreamRequest(t, n, a,
|
|
338
|
+
sendStreamRequest(t, n, a, s) {
|
|
339
339
|
return r.post(`/talks/streams/${t}`, {
|
|
340
340
|
session_id: n,
|
|
341
341
|
...a
|
|
342
|
-
},
|
|
342
|
+
}, s);
|
|
343
343
|
},
|
|
344
344
|
close(t, n, a) {
|
|
345
345
|
return r.delete(`/talks/streams/${t}`, {
|
|
@@ -348,7 +348,7 @@ function ae(e, i) {
|
|
|
348
348
|
}
|
|
349
349
|
};
|
|
350
350
|
}
|
|
351
|
-
function
|
|
351
|
+
function se(e, i) {
|
|
352
352
|
return e.map((r, t) => t === 0 ? i ? {
|
|
353
353
|
index: t,
|
|
354
354
|
timestamp: r.timestamp,
|
|
@@ -381,85 +381,85 @@ function ie(e, i) {
|
|
|
381
381
|
frameRate: r.frameRate
|
|
382
382
|
});
|
|
383
383
|
}
|
|
384
|
-
let
|
|
385
|
-
const
|
|
386
|
-
async function
|
|
384
|
+
let T = !1;
|
|
385
|
+
const v = (e, i) => T && console.log(e, i), oe = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
|
|
386
|
+
async function ce(e, {
|
|
387
387
|
debug: i = !1,
|
|
388
388
|
callbacks: r,
|
|
389
389
|
auth: t,
|
|
390
|
-
baseURL: n =
|
|
390
|
+
baseURL: n = C
|
|
391
391
|
}) {
|
|
392
|
-
|
|
392
|
+
T = i;
|
|
393
393
|
const a = {
|
|
394
394
|
...r
|
|
395
395
|
}, {
|
|
396
|
-
startConnection:
|
|
397
|
-
sendStreamRequest:
|
|
398
|
-
close:
|
|
399
|
-
createStream:
|
|
400
|
-
addIceCandidate:
|
|
401
|
-
} = e.videoType === R.Clip ?
|
|
402
|
-
id:
|
|
403
|
-
offer:
|
|
404
|
-
ice_servers:
|
|
396
|
+
startConnection: s,
|
|
397
|
+
sendStreamRequest: u,
|
|
398
|
+
close: m,
|
|
399
|
+
createStream: f,
|
|
400
|
+
addIceCandidate: g
|
|
401
|
+
} = e.videoType === R.Clip ? ae(t, n) : ie(t, n), {
|
|
402
|
+
id: d,
|
|
403
|
+
offer: c,
|
|
404
|
+
ice_servers: p,
|
|
405
405
|
session_id: w
|
|
406
|
-
} = await
|
|
407
|
-
iceServers:
|
|
408
|
-
}), b =
|
|
406
|
+
} = await f(e), l = new oe({
|
|
407
|
+
iceServers: p
|
|
408
|
+
}), b = l.createDataChannel("JanusDataChannel"), k = [];
|
|
409
409
|
let $ = 0, E;
|
|
410
410
|
if (!w)
|
|
411
411
|
throw new Error("Could not create session_id");
|
|
412
|
-
|
|
413
|
-
|
|
412
|
+
l.onicecandidate = (o) => {
|
|
413
|
+
v("peerConnection.onicecandidate", o), o.candidate && o.candidate.sdpMid && o.candidate.sdpMLineIndex !== null && g(d, {
|
|
414
414
|
candidate: o.candidate.candidate,
|
|
415
415
|
sdpMid: o.candidate.sdpMid,
|
|
416
416
|
sdpMLineIndex: o.candidate.sdpMLineIndex
|
|
417
417
|
}, w);
|
|
418
|
-
},
|
|
418
|
+
}, l.oniceconnectionstatechange = () => {
|
|
419
419
|
var o;
|
|
420
|
-
|
|
421
|
-
},
|
|
422
|
-
var
|
|
423
|
-
|
|
420
|
+
v("peerConnection.oniceconnectionstatechange => " + l.iceConnectionState), (o = a.onConnectionStateChange) == null || o.call(a, l.iceConnectionState);
|
|
421
|
+
}, l.ontrack = (o) => {
|
|
422
|
+
var h;
|
|
423
|
+
v("peerConnection.ontrack", o), (h = a.onSrcObjectReady) == null || h.call(a, o.streams[0]);
|
|
424
424
|
}, b.onmessage = (o) => {
|
|
425
|
-
var
|
|
425
|
+
var h, I, x;
|
|
426
426
|
if (b.readyState === "open") {
|
|
427
|
-
const [M,
|
|
427
|
+
const [M, q] = o.data.split(":");
|
|
428
428
|
if (M === A.StreamStarted)
|
|
429
429
|
$ = k.length, E = setInterval(() => {
|
|
430
|
-
|
|
431
|
-
|
|
430
|
+
l.getStats().then((L) => {
|
|
431
|
+
L.forEach((S) => {
|
|
432
432
|
S.type === "inbound-rtp" && S.kind === "video" && k.push(S);
|
|
433
433
|
});
|
|
434
434
|
});
|
|
435
|
-
}, 1e3), (
|
|
435
|
+
}, 1e3), (h = a.onVideoStateChange) == null || h.call(a, _.Start);
|
|
436
436
|
else if (M === A.StreamDone) {
|
|
437
437
|
clearInterval(E);
|
|
438
438
|
const P = k.slice($);
|
|
439
439
|
if (P) {
|
|
440
|
-
const
|
|
441
|
-
$ = k.length, (I = a.onVideoStateChange) == null || I.call(a, _.Stop, S.sort((
|
|
440
|
+
const L = $ === 0 ? void 0 : k[$ - 1], S = se(P, L);
|
|
441
|
+
$ = k.length, (I = a.onVideoStateChange) == null || I.call(a, _.Stop, S.sort((N, z) => z.packetsLost - N.packetsLost).slice(0, 5));
|
|
442
442
|
}
|
|
443
443
|
} else
|
|
444
|
-
(
|
|
444
|
+
(x = a.onMessage) == null || x.call(a, M, decodeURIComponent(q));
|
|
445
445
|
}
|
|
446
|
-
}, await
|
|
447
|
-
const W = await
|
|
448
|
-
return
|
|
446
|
+
}, await l.setRemoteDescription(c), v("set remote description OK");
|
|
447
|
+
const W = await l.createAnswer();
|
|
448
|
+
return v("create answer OK"), await l.setLocalDescription(W), v("set local description OK"), await s(d, W, w), v("start connection OK"), {
|
|
449
449
|
/**
|
|
450
450
|
* Method to send request to server to get clip or talk depend on you payload
|
|
451
451
|
* @param payload
|
|
452
452
|
*/
|
|
453
453
|
speak(o) {
|
|
454
|
-
return d
|
|
454
|
+
return u(d, w, o);
|
|
455
455
|
},
|
|
456
456
|
/**
|
|
457
457
|
* Method to close RTC connection
|
|
458
458
|
*/
|
|
459
459
|
async terminate() {
|
|
460
|
-
var o,
|
|
461
|
-
|
|
462
|
-
}), (o = a.onConnectionStateChange) == null || o.call(a, "closed"), (
|
|
460
|
+
var o, h;
|
|
461
|
+
d && (l && (l.close(), l.oniceconnectionstatechange = null, l.onnegotiationneeded = null, l.onicecandidate = null, l.ontrack = null), await m(d, w).catch((I) => {
|
|
462
|
+
}), (o = a.onConnectionStateChange) == null || o.call(a, "closed"), (h = a.onVideoStateChange) == null || h.call(a, _.Stop));
|
|
463
463
|
},
|
|
464
464
|
/**
|
|
465
465
|
* Session identifier information, should be returned in the body of all streaming requests
|
|
@@ -468,32 +468,33 @@ async function oe(e, {
|
|
|
468
468
|
/**
|
|
469
469
|
* Id of current RTC stream
|
|
470
470
|
*/
|
|
471
|
-
streamId:
|
|
471
|
+
streamId: d,
|
|
472
472
|
/**
|
|
473
473
|
* Method to add callback that will be trigered on supported events
|
|
474
474
|
* @param eventName
|
|
475
475
|
* @param callback
|
|
476
476
|
*/
|
|
477
|
-
onCallback(o,
|
|
478
|
-
a[o] =
|
|
477
|
+
onCallback(o, h) {
|
|
478
|
+
a[o] = h;
|
|
479
479
|
}
|
|
480
480
|
};
|
|
481
481
|
}
|
|
482
482
|
export {
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
483
|
+
j as ChatMode,
|
|
484
|
+
K as ChatProgress,
|
|
485
|
+
ne as DocumentType,
|
|
486
|
+
te as KnowledgeType,
|
|
486
487
|
Y as Providers,
|
|
487
488
|
O as RateState,
|
|
488
489
|
X as SocketManager,
|
|
489
490
|
A as StreamEvents,
|
|
490
|
-
|
|
491
|
+
ee as Subject,
|
|
491
492
|
Z as VoiceAccess,
|
|
492
|
-
|
|
493
|
-
|
|
493
|
+
de as createAgentManager,
|
|
494
|
+
J as createAgentsApi,
|
|
494
495
|
y as createClient,
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
496
|
+
F as createKnowledgeApi,
|
|
497
|
+
D as createRatingsApi,
|
|
498
|
+
ce as createStreamingManager,
|
|
499
|
+
re as getAgentStreamArgs
|
|
499
500
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(c,h){typeof exports=="object"&&typeof module<"u"?h(exports):typeof define=="function"&&define.amd?define(["exports"],h):(c=typeof globalThis<"u"?globalThis:c||self,h(c.index={}))})(this,function(c){"use strict";const h="https://api.d-id.com",O="wss://notifications.d-id.com";function E(e){if(e.type==="bearer")return`Bearer ${e.token}`;if(e.type==="basic")return`Basic ${btoa(`${e.username}:${e.password}`)}`;if(e.type==="key")return`Client-Key ${e.clientKey}`;throw new Error(`Unknown auth type: ${e}`)}function C(e,i=h){const a=async(t,n)=>{const r=await fetch(i+(t!=null&&t.startsWith("/")?t:`/${t}`),{...n,headers:{...n==null?void 0:n.headers,Authorization:E(e),"Content-Type":"application/json"}});if(!r.ok){let d=await r.text().catch(()=>"Failed to fetch");throw new Error(d)}return r.json()};return{get(t,n){return a(t,{...n,method:"GET"})},post(t,n,r){return a(t,{...r,body:JSON.stringify(n),method:"POST"})},delete(t,n,r){return a(t,{...r,body:JSON.stringify(n),method:"DELETE"})},patch(t,n,r){return a(t,{...r,body:JSON.stringify(n),method:"PATCH"})}}}function T(e,i=h){const a=C(e,`${i}/agents`);return{create(t,n){return a.post("/",t,n)},getAgents(t,n){return a.get(`/${t?`?tag=${t}`:""}`,n).then(r=>r??[])},getById(t,n){return a.get(`/${t}`,n)},delete(t,n){return a.delete(`/${t}`,void 0,n)},update(t,n,r){return a.patch(`/${t}`,n,r)},newChat(t,n){return a.post(`/${t}/chat`,void 0,n)},chat(t,n,r,d){return a.post(`/${t}/chat/${n}`,r,d)}}}function W(e,i=h){const a=C(e,`${i}/knowledge`);return{createKnowledge(t,n){return a.post("/",t,n)},getKnowledgeBase(t){return a.get("/",t)},getKnowledge(t,n){return a.get(`/${t}`,n)},deleteKnowledge(t,n){return a.delete(`/${t}`,void 0,n)},createDocument(t,n,r){return a.post(`/${t}/documents`,n,r)},deleteDocument(t,n,r){return a.delete(`/${t}/documents/${n}`,void 0,r)},getDocuments(t,n){return a.get(`/${t}/documents`,n)},getDocument(t,n,r){return a.get(`/${t}/documents/${n}`,r)},getRecords(t,n,r){return a.get(`/${t}/documents/${n}/records`,r)},query(t,n,r){return a.post(`/${t}/query`,{query:n},r)}}}function H(e,i=h){const a=C(e,`${i}/chats/ratings`);return{create(t,n){return a.post("/",t,n)},getByKnowledge(t,n){return a.get(`/${t}`,n).then(r=>r??[])},update(t,n,r){return a.patch(`/${t}`,n,r)},delete(t,n){return a.delete(`/${t}`,n)}}}const x=e=>new Promise(i=>setTimeout(i,e));function ee(e){return new Promise((i,a)=>{const{callbacks:t,host:n,auth:r}=e,{onMessage:d=null,onOpen:l=null,onClose:p=null,onError:g=null}=t||{},u=new WebSocket(`${n}?authorization=${E(r)}`);u.onmessage=d,u.onclose=p,u.onerror=s=>{console.log(s),g==null||g(s),a(s)},u.onopen=s=>{l==null||l(s),i(u)}})}async function te(e){const{retries:i=1}=e;let a=null;for(let t=0;(a==null?void 0:a.readyState)!==WebSocket.OPEN;t++)try{a=await ee(e)}catch(n){if(t===i)throw n;await x(t*500)}return a}async function q(e,i,a=O){const t=i?[i]:[],n=await te({auth:e,host:a,callbacks:{onMessage:r=>{const d=JSON.parse(r.data);t.forEach(l=>l(d.event,d))}}});return{socket:n,terminate:()=>n.close(),subscribeToEvents:r=>t.push(r)}}var N=(e=>(e.Amazon="amazon",e.Microsoft="microsoft",e.Afflorithmics="afflorithmics",e.Elevenlabs="elevenlabs",e))(N||{}),U=(e=>(e.Public="public",e.Premium="premium",e.Private="private",e))(U||{}),M=(e=>(e.Start="START",e.Stop="STOP",e))(M||{}),k=(e=>(e.ChatAnswer="chat/answer",e.ChatPartial="chat/partial",e.StreamDone="stream/done",e.StreamStarted="stream/started",e))(k||{}),z=(e=>(e.Unrated="Unrated",e.Positive="Positive",e.Negative="Negative",e))(z||{}),I=(e=>(e.Embed="embed",e.Query="query",e.Partial="partial",e.Answer="answer",e.Complete="done",e))(I||{}),B=(e=>(e.KnowledgeProcessing="knowledge/processing",e.KnowledgeIndexing="knowledge/indexing",e.KnowledgeFailed="knowledge/error",e.KnowledgeDone="knowledge/done",e))(B||{}),J=(e=>(e.Knowledge="knowledge",e.Document="document",e.Record="record",e))(J||{}),D=(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))(D||{}),$=(e=>(e.Clip="clip",e.Talk="talk",e))($||{});function F(e){return e.presenter.type===$.Clip?{videoType:$.Clip,driver_id:e.presenter.driver_id,presenter_id:e.presenter.presenter_id}:{videoType:$.Talk,source_url:e.presenter.source_url}}function V(e,i,a,t){return new Promise(async(n,r)=>{const d=await Q(F(e),{...i,callbacks:{...i.callbacks,onConnectionStateChange:async l=>{var p,g;l==="connected"?(t||(t=await a.newChat(e.id)),n({chat:t,streamingManager:d})):l==="failed"&&r(new Error("Cannot create connection")),(g=(p=i.callbacks).onConnectionStateChange)==null||g.call(p,l)},onMessage:(l,p)=>{var g,u;l===k.ChatPartial&&((u=(g=i.callbacks).onChatEvents)==null||u.call(g,I.Partial,{content:p,event:I.Partial}))}}})})}async function ne(e,i){const a=i.baseURL||h,t=new AbortController,n=T(i.auth,a),r=H(i.auth,a),d=W(i.auth,a),l=await n.getById(e),p=await q(i.auth,i.callbacks.onChatEvents);let{chat:g,streamingManager:u}=await V(l,i,n);return{agent:l,async reconnectToChat(){const{streamingManager:s}=await V(l,i,n,g);u=s},terminate(){return t.abort(),p.terminate(),u.terminate()},chatId:g.id,chat(s){return n.chat(e,g.id,{sessionId:u.sessionId,streamId:u.streamId,messages:s},{signal:t.signal})},rate(s,f){return f?r.update(f,s):r.create(s)},deleteRate(s){return r.delete(s)},speak(s){let f;return s.type==="text"?f={script:{type:"text",provider:s.provider,input:s.input,ssml:s.ssml||!1}}:s.type==="audio"&&(f={script:{type:"audio",audio_url:s.audio_url}}),u.speak(f)},getStarterMessages(){var s,f;return(s=l.knowledge)!=null&&s.id?d.getKnowledge((f=l.knowledge)==null?void 0:f.id).then(R=>(R==null?void 0:R.starter_message)||[]):Promise.resolve([])}}}function ae(e,i){const a=C(e,i);return{createStream(t){return a.post("/clips/streams",{driver_id:t.driver_id,presenter_id:t.presenter_id,compatibility_mode:t.compatibility_mode})},startConnection(t,n,r){return a.post(`/clips/streams/${t}/sdp`,{session_id:r,answer:n})},addIceCandidate(t,n,r){return a.post(`/clips/streams/${t}/ice`,{session_id:r,...n})},sendStreamRequest(t,n,r){return a.post(`/clips/streams/${t}`,{session_id:n,...r})},close(t,n){return a.delete(`/clips/streams/${t}`,{session_id:n})}}}function re(e,i){const a=C(e,i);return{createStream(t,n){return a.post("/talks/streams",{source_url:t.source_url,driver_url:t.driver_url,face:t.face,config:t.config},n)},startConnection(t,n,r,d){return a.post(`/talks/streams/${t}/sdp`,{session_id:r,answer:n},d)},addIceCandidate(t,n,r,d){return a.post(`/talks/streams/${t}/ice`,{session_id:r,...n},d)},sendStreamRequest(t,n,r,d){return a.post(`/talks/streams/${t}`,{session_id:n,...r},d)},close(t,n,r){return a.delete(`/talks/streams/${t}`,{session_id:n},r)}}}function ie(e,i){return e.map((a,t)=>t===0?i?{index:t,timestamp:a.timestamp,bytesReceived:a.bytesReceived-i.bytesReceived,packetsReceived:a.packetsReceived-i.packetsReceived,packetsLost:a.packetsLost-i.packetsLost,jitter:a.jitter,frameWidth:a.frameWidth,frameHeight:a.frameHeight,frameRate:a.frameRate}:{index:t,timestamp:a.timestamp,bytesReceived:a.bytesReceived,packetsReceived:a.packetsReceived,packetsLost:a.packetsLost,jitter:a.jitter,frameWidth:a.frameWidth,frameHeight:a.frameHeight,frameRate:a.frameRate}:{index:t,timestamp:a.timestamp,bytesReceived:a.bytesReceived-e[t-1].bytesReceived,packetsReceived:a.packetsReceived-e[t-1].packetsReceived,packetsLost:a.packetsLost-e[t-1].packetsLost,jitter:a.jitter,frameWidth:a.frameWidth,frameHeight:a.frameHeight,frameRate:a.frameRate})}let G=!1;const v=(e,i)=>G&&console.log(e,i),se=(window.RTCPeerConnection||window.webkitRTCPeerConnection||window.mozRTCPeerConnection).bind(window);async function Q(e,{debug:i=!1,callbacks:a,auth:t,baseURL:n=h}){G=i;const r={...a},{startConnection:d,sendStreamRequest:l,close:p,createStream:g,addIceCandidate:u}=e.videoType===$.Clip?ae(t,n):re(t,n),{id:s,offer:f,ice_servers:R,session_id:S}=await g(e),m=new se({iceServers:R}),X=m.createDataChannel("JanusDataChannel"),y=[];let A=0,Y;if(!S)throw new Error("Could not create session_id");m.onicecandidate=o=>{v("peerConnection.onicecandidate",o),o.candidate&&o.candidate.sdpMid&&o.candidate.sdpMLineIndex!==null&&u(s,{candidate:o.candidate.candidate,sdpMid:o.candidate.sdpMid,sdpMLineIndex:o.candidate.sdpMLineIndex},S)},m.oniceconnectionstatechange=()=>{var o;v("peerConnection.oniceconnectionstatechange => "+m.iceConnectionState),(o=r.onConnectionStateChange)==null||o.call(r,m.iceConnectionState)},m.ontrack=o=>{var w;v("peerConnection.ontrack",o),(w=r.onSrcObjectReady)==null||w.call(r,o.streams[0])},X.onmessage=o=>{var w,P,j;if(X.readyState==="open"){const[b,oe]=o.data.split(":");if(b===k.StreamStarted)A=y.length,Y=setInterval(()=>{m.getStats().then(L=>{L.forEach(_=>{_.type==="inbound-rtp"&&_.kind==="video"&&y.push(_)})})},1e3),(w=r.onVideoStateChange)==null||w.call(r,M.Start);else if(b===k.StreamDone){clearInterval(Y);const K=y.slice(A);if(K){const L=A===0?void 0:y[A-1],_=ie(K,L);A=y.length,(P=r.onVideoStateChange)==null||P.call(r,M.Stop,_.sort((ce,de)=>de.packetsLost-ce.packetsLost).slice(0,5))}}else(j=r.onMessage)==null||j.call(r,b,decodeURIComponent(oe))}},await m.setRemoteDescription(f),v("set remote description OK");const Z=await m.createAnswer();return v("create answer OK"),await m.setLocalDescription(Z),v("set local description OK"),await d(s,Z,S),v("start connection OK"),{speak(o){return l(s,S,o)},async terminate(){var o,w;s&&(m&&(m.close(),m.oniceconnectionstatechange=null,m.onnegotiationneeded=null,m.onicecandidate=null,m.ontrack=null),await p(s,S).catch(P=>{}),(o=r.onConnectionStateChange)==null||o.call(r,"closed"),(w=r.onVideoStateChange)==null||w.call(r,M.Stop))},sessionId:S,streamId:s,onCallback(o,w){r[o]=w}}}c.ChatProgress=I,c.DocumentType=D,c.KnowledgeType=J,c.Providers=N,c.RateState=z,c.SocketManager=q,c.StreamEvents=k,c.Subject=B,c.VoiceAccess=U,c.createAgentManager=ne,c.createAgentsApi=T,c.createClient=C,c.createKnowledgeApi=W,c.createRatingsApi=H,c.createStreamingManager=Q,c.getAgentStreamArgs=F,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(s,p){typeof exports=="object"&&typeof module<"u"?p(exports):typeof define=="function"&&define.amd?define(["exports"],p):(s=typeof globalThis<"u"?globalThis:s||self,p(s.index={}))})(this,function(s){"use strict";const p="https://api.d-id.com",x="wss://notifications.d-id.com";function E(e){if(e.type==="bearer")return`Bearer ${e.token}`;if(e.type==="basic")return`Basic ${btoa(`${e.username}:${e.password}`)}`;if(e.type==="key")return`Client-Key ${e.clientKey}`;throw new Error(`Unknown auth type: ${e}`)}function k(e,i=p){const a=async(t,n)=>{const r=await fetch(i+(t!=null&&t.startsWith("/")?t:`/${t}`),{...n,headers:{...n==null?void 0:n.headers,Authorization:E(e),"Content-Type":"application/json"}});if(!r.ok){let c=await r.text().catch(()=>"Failed to fetch");throw new Error(c)}return r.json()};return{get(t,n){return a(t,{...n,method:"GET"})},post(t,n,r){return a(t,{...r,body:JSON.stringify(n),method:"POST"})},delete(t,n,r){return a(t,{...r,body:JSON.stringify(n),method:"DELETE"})},patch(t,n,r){return a(t,{...r,body:JSON.stringify(n),method:"PATCH"})}}}function T(e,i=p){const a=k(e,`${i}/agents`);return{create(t,n){return a.post("/",t,n)},getAgents(t,n){return a.get(`/${t?`?tag=${t}`:""}`,n).then(r=>r??[])},getById(t,n){return a.get(`/${t}`,n)},delete(t,n){return a.delete(`/${t}`,void 0,n)},update(t,n,r){return a.patch(`/${t}`,n,r)},newChat(t,n){return a.post(`/${t}/chat`,void 0,n)},chat(t,n,r,c){return a.post(`/${t}/chat/${n}`,r,c)}}}function W(e,i=p){const a=k(e,`${i}/knowledge`);return{createKnowledge(t,n){return a.post("/",t,n)},getKnowledgeBase(t){return a.get("/",t)},getKnowledge(t,n){return a.get(`/${t}`,n)},deleteKnowledge(t,n){return a.delete(`/${t}`,void 0,n)},createDocument(t,n,r){return a.post(`/${t}/documents`,n,r)},deleteDocument(t,n,r){return a.delete(`/${t}/documents/${n}`,void 0,r)},getDocuments(t,n){return a.get(`/${t}/documents`,n)},getDocument(t,n,r){return a.get(`/${t}/documents/${n}`,r)},getRecords(t,n,r){return a.get(`/${t}/documents/${n}/records`,r)},query(t,n,r){return a.post(`/${t}/query`,{query:n},r)}}}function H(e,i=p){const a=k(e,`${i}/chats/ratings`);return{create(t,n){return a.post("/",t,n)},getByKnowledge(t,n){return a.get(`/${t}`,n).then(r=>r??[])},update(t,n,r){return a.patch(`/${t}`,n,r)},delete(t,n){return a.delete(`/${t}`,n)}}}const ee=e=>new Promise(i=>setTimeout(i,e));function te(e){return new Promise((i,a)=>{const{callbacks:t,host:n,auth:r}=e,{onMessage:c=null,onOpen:m=null,onClose:g=null,onError:h=null}=t||{},f=new WebSocket(`${n}?authorization=${E(r)}`);f.onmessage=c,f.onclose=g,f.onerror=l=>{console.log(l),h==null||h(l),a(l)},f.onopen=l=>{m==null||m(l),i(f)}})}async function ne(e){const{retries:i=1}=e;let a=null;for(let t=0;(a==null?void 0:a.readyState)!==WebSocket.OPEN;t++)try{a=await te(e)}catch(n){if(t===i)throw n;await ee(t*500)}return a}async function U(e,i,a){const t=a?[a]:[],n=await ne({auth:e,host:i,callbacks:{onMessage:r=>{const c=JSON.parse(r.data);t.forEach(m=>m(c.event,c))}}});return{socket:n,terminate:()=>n.close(),subscribeToEvents:r=>t.push(r)}}var q=(e=>(e.Amazon="amazon",e.Microsoft="microsoft",e.Afflorithmics="afflorithmics",e.Elevenlabs="elevenlabs",e))(q||{}),N=(e=>(e.Public="public",e.Premium="premium",e.Private="private",e))(N||{}),M=(e=>(e.Start="START",e.Stop="STOP",e))(M||{}),R=(e=>(e.ChatAnswer="chat/answer",e.ChatPartial="chat/partial",e.StreamDone="stream/done",e.StreamStarted="stream/started",e))(R||{}),z=(e=>(e.Unrated="Unrated",e.Positive="Positive",e.Negative="Negative",e))(z||{}),B=(e=>(e.Functional="Functional",e.TextOnly="TextOnly",e.Maintenance="Maintenance",e))(B||{}),I=(e=>(e.Embed="embed",e.Query="query",e.Partial="partial",e.Answer="answer",e.Complete="done",e))(I||{}),J=(e=>(e.KnowledgeProcessing="knowledge/processing",e.KnowledgeIndexing="knowledge/indexing",e.KnowledgeFailed="knowledge/error",e.KnowledgeDone="knowledge/done",e))(J||{}),F=(e=>(e.Knowledge="knowledge",e.Document="document",e.Record="record",e))(F||{}),D=(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))(D||{}),$=(e=>(e.Clip="clip",e.Talk="talk",e))($||{});function V(e){return e.presenter.type===$.Clip?{videoType:$.Clip,driver_id:e.presenter.driver_id,presenter_id:e.presenter.presenter_id}:{videoType:$.Talk,source_url:e.presenter.source_url}}function G(e,i,a,t){return new Promise(async(n,r)=>{const c=await X(V(e),{...i,callbacks:{...i.callbacks,onConnectionStateChange:async m=>{var g,h;m==="connected"?(t||(t=await a.newChat(e.id)),n({chat:t,streamingManager:c})):m==="failed"&&r(new Error("Cannot create connection")),(h=(g=i.callbacks).onConnectionStateChange)==null||h.call(g,m)},onMessage:(m,g)=>{var h,f;m===R.ChatPartial&&((f=(h=i.callbacks).onChatEvents)==null||f.call(h,I.Partial,{content:g,event:I.Partial}))}}})})}async function ae(e,i){const a=i.baseURL||p,t=i.wsURL||x,n=new AbortController,r=T(i.auth,a),c=H(i.auth,a),m=W(i.auth,a),g=await r.getById(e),h=await U(i.auth,t,i.callbacks.onChatEvents);let{chat:f,streamingManager:l}=await G(g,i,r);return{agent:g,async reconnectToChat(){const{streamingManager:d}=await G(g,i,r,f);l=d},terminate(){return n.abort(),h.terminate(),l.terminate()},chatId:f.id,chat(d){return r.chat(e,f.id,{sessionId:l.sessionId,streamId:l.streamId,messages:d},{signal:n.signal})},rate(d,w){return w?c.update(w,d):c.create(d)},deleteRate(d){return c.delete(d)},speak(d){let w;return d.type==="text"?w={script:{type:"text",provider:d.provider,input:d.input,ssml:d.ssml||!1}}:d.type==="audio"&&(w={script:{type:"audio",audio_url:d.audio_url}}),l.speak(w)},getStarterMessages(){var d,w;return(d=g.knowledge)!=null&&d.id?m.getKnowledge((w=g.knowledge)==null?void 0:w.id).then(v=>(v==null?void 0:v.starter_message)||[]):Promise.resolve([])}}}function re(e,i){const a=k(e,i);return{createStream(t){return a.post("/clips/streams",{driver_id:t.driver_id,presenter_id:t.presenter_id,compatibility_mode:t.compatibility_mode})},startConnection(t,n,r){return a.post(`/clips/streams/${t}/sdp`,{session_id:r,answer:n})},addIceCandidate(t,n,r){return a.post(`/clips/streams/${t}/ice`,{session_id:r,...n})},sendStreamRequest(t,n,r){return a.post(`/clips/streams/${t}`,{session_id:n,...r})},close(t,n){return a.delete(`/clips/streams/${t}`,{session_id:n})}}}function ie(e,i){const a=k(e,i);return{createStream(t,n){return a.post("/talks/streams",{source_url:t.source_url,driver_url:t.driver_url,face:t.face,config:t.config},n)},startConnection(t,n,r,c){return a.post(`/talks/streams/${t}/sdp`,{session_id:r,answer:n},c)},addIceCandidate(t,n,r,c){return a.post(`/talks/streams/${t}/ice`,{session_id:r,...n},c)},sendStreamRequest(t,n,r,c){return a.post(`/talks/streams/${t}`,{session_id:n,...r},c)},close(t,n,r){return a.delete(`/talks/streams/${t}`,{session_id:n},r)}}}function se(e,i){return e.map((a,t)=>t===0?i?{index:t,timestamp:a.timestamp,bytesReceived:a.bytesReceived-i.bytesReceived,packetsReceived:a.packetsReceived-i.packetsReceived,packetsLost:a.packetsLost-i.packetsLost,jitter:a.jitter,frameWidth:a.frameWidth,frameHeight:a.frameHeight,frameRate:a.frameRate}:{index:t,timestamp:a.timestamp,bytesReceived:a.bytesReceived,packetsReceived:a.packetsReceived,packetsLost:a.packetsLost,jitter:a.jitter,frameWidth:a.frameWidth,frameHeight:a.frameHeight,frameRate:a.frameRate}:{index:t,timestamp:a.timestamp,bytesReceived:a.bytesReceived-e[t-1].bytesReceived,packetsReceived:a.packetsReceived-e[t-1].packetsReceived,packetsLost:a.packetsLost-e[t-1].packetsLost,jitter:a.jitter,frameWidth:a.frameWidth,frameHeight:a.frameHeight,frameRate:a.frameRate})}let Q=!1;const S=(e,i)=>Q&&console.log(e,i),ce=(window.RTCPeerConnection||window.webkitRTCPeerConnection||window.mozRTCPeerConnection).bind(window);async function X(e,{debug:i=!1,callbacks:a,auth:t,baseURL:n=p}){Q=i;const r={...a},{startConnection:c,sendStreamRequest:m,close:g,createStream:h,addIceCandidate:f}=e.videoType===$.Clip?re(t,n):ie(t,n),{id:l,offer:d,ice_servers:w,session_id:v}=await h(e),u=new ce({iceServers:w}),Y=u.createDataChannel("JanusDataChannel"),y=[];let A=0,Z;if(!v)throw new Error("Could not create session_id");u.onicecandidate=o=>{S("peerConnection.onicecandidate",o),o.candidate&&o.candidate.sdpMid&&o.candidate.sdpMLineIndex!==null&&f(l,{candidate:o.candidate.candidate,sdpMid:o.candidate.sdpMid,sdpMLineIndex:o.candidate.sdpMLineIndex},v)},u.oniceconnectionstatechange=()=>{var o;S("peerConnection.oniceconnectionstatechange => "+u.iceConnectionState),(o=r.onConnectionStateChange)==null||o.call(r,u.iceConnectionState)},u.ontrack=o=>{var C;S("peerConnection.ontrack",o),(C=r.onSrcObjectReady)==null||C.call(r,o.streams[0])},Y.onmessage=o=>{var C,P,j;if(Y.readyState==="open"){const[b,oe]=o.data.split(":");if(b===R.StreamStarted)A=y.length,Z=setInterval(()=>{u.getStats().then(L=>{L.forEach(_=>{_.type==="inbound-rtp"&&_.kind==="video"&&y.push(_)})})},1e3),(C=r.onVideoStateChange)==null||C.call(r,M.Start);else if(b===R.StreamDone){clearInterval(Z);const K=y.slice(A);if(K){const L=A===0?void 0:y[A-1],_=se(K,L);A=y.length,(P=r.onVideoStateChange)==null||P.call(r,M.Stop,_.sort((de,le)=>le.packetsLost-de.packetsLost).slice(0,5))}}else(j=r.onMessage)==null||j.call(r,b,decodeURIComponent(oe))}},await u.setRemoteDescription(d),S("set remote description OK");const O=await u.createAnswer();return S("create answer OK"),await u.setLocalDescription(O),S("set local description OK"),await c(l,O,v),S("start connection OK"),{speak(o){return m(l,v,o)},async terminate(){var o,C;l&&(u&&(u.close(),u.oniceconnectionstatechange=null,u.onnegotiationneeded=null,u.onicecandidate=null,u.ontrack=null),await g(l,v).catch(P=>{}),(o=r.onConnectionStateChange)==null||o.call(r,"closed"),(C=r.onVideoStateChange)==null||C.call(r,M.Stop))},sessionId:v,streamId:l,onCallback(o,C){r[o]=C}}}s.ChatMode=B,s.ChatProgress=I,s.DocumentType=D,s.KnowledgeType=F,s.Providers=q,s.RateState=z,s.SocketManager=U,s.StreamEvents=R,s.Subject=J,s.VoiceAccess=N,s.createAgentManager=ae,s.createAgentsApi=T,s.createClient=k,s.createKnowledgeApi=W,s.createRatingsApi=H,s.createStreamingManager=X,s.getAgentStreamArgs=V,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -5,5 +5,5 @@ interface SocketManager {
|
|
|
5
5
|
terminate: () => void;
|
|
6
6
|
subscribeToEvents: (data: any) => void;
|
|
7
7
|
}
|
|
8
|
-
export declare function SocketManager(auth: Auth,
|
|
8
|
+
export declare function SocketManager(auth: Auth, host: string, onMessage?: ChatProgressCallback): Promise<SocketManager>;
|
|
9
9
|
export {};
|
|
@@ -36,10 +36,16 @@ export interface IRetrivalMetadata {
|
|
|
36
36
|
knowledge_id: string;
|
|
37
37
|
source_url: string;
|
|
38
38
|
}
|
|
39
|
+
export declare enum ChatMode {
|
|
40
|
+
Functional = "Functional",
|
|
41
|
+
TextOnly = "TextOnly",
|
|
42
|
+
Maintenance = "Maintenance"
|
|
43
|
+
}
|
|
39
44
|
export interface ChatResponse {
|
|
40
45
|
result?: string;
|
|
41
46
|
documentIds?: string[];
|
|
42
47
|
matches?: IRetrivalMetadata[];
|
|
48
|
+
chatMode?: ChatMode;
|
|
43
49
|
}
|
|
44
50
|
export interface Chat {
|
|
45
51
|
id: string;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@d-id/client-sdk",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.20",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "d-id client sdk",
|
|
7
7
|
"repository": {
|
|
@@ -45,4 +45,4 @@
|
|
|
45
45
|
"vite-plugin-dts": "^3.6.0",
|
|
46
46
|
"vite-plugin-html-env": "^1.2.8"
|
|
47
47
|
}
|
|
48
|
-
}
|
|
48
|
+
}
|