@d-id/client-sdk 1.0.19-beta.40 → 1.0.19-beta.41

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.
Files changed (41) hide show
  1. package/README.md +4 -0
  2. package/package.json +2 -2
  3. package/dist/index.js +0 -526
  4. package/dist/index.umd.cjs +0 -1
  5. package/dist/src/api/agents.d.ts +0 -10
  6. package/dist/src/api/clipStream.d.ts +0 -2
  7. package/dist/src/api/getClient.d.ts +0 -7
  8. package/dist/src/api/knowledge.d.ts +0 -13
  9. package/dist/src/api/ratings.d.ts +0 -7
  10. package/dist/src/api/talkStream.d.ts +0 -2
  11. package/dist/src/auth/getAuthHeader.d.ts +0 -2
  12. package/dist/src/connectToSocket.d.ts +0 -9
  13. package/dist/src/createAgentManager.d.ts +0 -16
  14. package/dist/src/createStreamingManager.d.ts +0 -21
  15. package/dist/src/environment.d.ts +0 -6
  16. package/dist/src/index.d.ts +0 -8
  17. package/dist/src/types/StreamScript.d.ts +0 -53
  18. package/dist/src/types/auth.d.ts +0 -20
  19. package/dist/src/types/entities/agents/agent.d.ts +0 -28
  20. package/dist/src/types/entities/agents/chat.d.ts +0 -59
  21. package/dist/src/types/entities/agents/index.d.ts +0 -3
  22. package/dist/src/types/entities/agents/knowledge.d.ts +0 -10
  23. package/dist/src/types/entities/agents/llm.d.ts +0 -19
  24. package/dist/src/types/entities/agents/manager.d.ts +0 -118
  25. package/dist/src/types/entities/agents/presenter.d.ts +0 -20
  26. package/dist/src/types/entities/index.d.ts +0 -3
  27. package/dist/src/types/entities/knowledge/document.d.ts +0 -21
  28. package/dist/src/types/entities/knowledge/index.d.ts +0 -4
  29. package/dist/src/types/entities/knowledge/knowledge.d.ts +0 -36
  30. package/dist/src/types/entities/knowledge/record.d.ts +0 -15
  31. package/dist/src/types/entities/knowledge/retrival.d.ts +0 -5
  32. package/dist/src/types/entities/video.d.ts +0 -4
  33. package/dist/src/types/index.d.ts +0 -6
  34. package/dist/src/types/stream/api/clip.d.ts +0 -110
  35. package/dist/src/types/stream/api/index.d.ts +0 -2
  36. package/dist/src/types/stream/api/talk.d.ts +0 -47
  37. package/dist/src/types/stream/index.d.ts +0 -3
  38. package/dist/src/types/stream/rtc.d.ts +0 -61
  39. package/dist/src/types/stream/stream.d.ts +0 -55
  40. package/dist/src/types/tts.d.ts +0 -146
  41. package/dist/src/utils/webrtc.d.ts +0 -2
package/README.md CHANGED
@@ -1,2 +1,6 @@
1
1
  # agents-sdk
2
2
  SDK for Agents
3
+
4
+ # Deploy
5
+ In order to deploy, you need to merge your branch into main. After branch is merged, run ```yarn build && yarn publish```. <br>
6
+ You will be prompted to enter the version.
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.19-beta.40",
4
+ "version": "1.0.19-beta.41",
5
5
  "type": "module",
6
6
  "description": "d-id client sdk",
7
7
  "repository": {
@@ -41,4 +41,4 @@
41
41
  "vite": "^5.1.4",
42
42
  "vite-plugin-dts": "^3.7.3"
43
43
  }
44
- }
44
+ }
package/dist/index.js DELETED
@@ -1,526 +0,0 @@
1
- const C = "https://api.d-id.com", b = "wss://notifications.d-id.com";
2
- function W() {
3
- let e = window.localStorage.getItem("did_external_key_id");
4
- return e || (e = Math.random().toString(16).slice(2), window.localStorage.setItem("did_external_key_id", e)), e;
5
- }
6
- function K(e) {
7
- if (e.type === "bearer")
8
- return `Bearer ${e.token}`;
9
- if (e.type === "basic")
10
- return `Basic ${btoa(`${e.username}:${e.password}`)}`;
11
- if (e.type === "key")
12
- return `Client-Key ${e.clientKey}.${W()}`;
13
- throw new Error(`Unknown auth type: ${e}`);
14
- }
15
- function _(e, i = C) {
16
- const n = async (t, r) => {
17
- const a = await fetch(i + (t != null && t.startsWith("/") ? t : `/${t}`), {
18
- ...r,
19
- headers: {
20
- ...r == null ? void 0 : r.headers,
21
- Authorization: K(e),
22
- "Content-Type": "application/json"
23
- }
24
- });
25
- if (!a.ok) {
26
- let o = await a.text().catch(() => "Failed to fetch");
27
- throw new Error(o);
28
- }
29
- return a.json();
30
- };
31
- return {
32
- get(t, r) {
33
- return n(t, {
34
- ...r,
35
- method: "GET"
36
- });
37
- },
38
- post(t, r, a) {
39
- return n(t, {
40
- ...a,
41
- body: JSON.stringify(r),
42
- method: "POST"
43
- });
44
- },
45
- delete(t, r, a) {
46
- return n(t, {
47
- ...a,
48
- body: JSON.stringify(r),
49
- method: "DELETE"
50
- });
51
- },
52
- patch(t, r, a) {
53
- return n(t, {
54
- ...a,
55
- body: JSON.stringify(r),
56
- method: "PATCH"
57
- });
58
- }
59
- };
60
- }
61
- function E(e, i = C) {
62
- const n = _(e, `${i}/agents`);
63
- return {
64
- create(t, r) {
65
- return n.post("/", t, r);
66
- },
67
- getAgents(t, r) {
68
- return n.get(`/${t ? `?tag=${t}` : ""}`, r).then((a) => a ?? []);
69
- },
70
- getById(t, r) {
71
- return n.get(`/${t}`, r);
72
- },
73
- delete(t, r) {
74
- return n.delete(`/${t}`, void 0, r);
75
- },
76
- update(t, r, a) {
77
- return n.patch(`/${t}`, r, a);
78
- },
79
- newChat(t, r) {
80
- return n.post(`/${t}/chat`, void 0, r);
81
- },
82
- chat(t, r, a, o) {
83
- return n.post(`/${t}/chat/${r}`, a, o);
84
- }
85
- };
86
- }
87
- function O(e, i = C) {
88
- const n = _(e, `${i}/knowledge`);
89
- return {
90
- createKnowledge(t, r) {
91
- return n.post("/", t, r);
92
- },
93
- getKnowledgeBase(t) {
94
- return n.get("/", t);
95
- },
96
- getKnowledge(t, r) {
97
- return n.get(`/${t}`, r);
98
- },
99
- deleteKnowledge(t, r) {
100
- return n.delete(`/${t}`, void 0, r);
101
- },
102
- createDocument(t, r, a) {
103
- return n.post(`/${t}/documents`, r, a);
104
- },
105
- deleteDocument(t, r, a) {
106
- return n.delete(`/${t}/documents/${r}`, void 0, a);
107
- },
108
- getDocuments(t, r) {
109
- return n.get(`/${t}/documents`, r);
110
- },
111
- getDocument(t, r, a) {
112
- return n.get(`/${t}/documents/${r}`, a);
113
- },
114
- getRecords(t, r, a) {
115
- return n.get(`/${t}/documents/${r}/records`, a);
116
- },
117
- query(t, r, a) {
118
- return n.post(`/${t}/query`, {
119
- query: r
120
- }, a);
121
- }
122
- };
123
- }
124
- function B(e, i = C) {
125
- const n = _(e, `${i}/chats/ratings`);
126
- return {
127
- create(t, r) {
128
- return n.post("/", t, r);
129
- },
130
- getByKnowledge(t, r) {
131
- return n.get(`/${t}`, r).then((a) => a ?? []);
132
- },
133
- update(t, r, a) {
134
- return n.patch(`/${t}`, r, a);
135
- },
136
- delete(t, r) {
137
- return n.delete(`/${t}`, r);
138
- }
139
- };
140
- }
141
- const H = (e) => new Promise((i) => setTimeout(i, e));
142
- function U(e) {
143
- return new Promise((i, n) => {
144
- const {
145
- callbacks: t,
146
- host: r,
147
- auth: a
148
- } = e, {
149
- onMessage: o = null,
150
- onOpen: u = null,
151
- onClose: c = null,
152
- onError: m = null
153
- } = t || {}, d = new WebSocket(`${r}?authorization=${K(a)}`);
154
- d.onmessage = o, d.onclose = c, d.onerror = (g) => {
155
- console.error(g), m == null || m(g), n(g);
156
- }, d.onopen = (g) => {
157
- u == null || u(g), i(d);
158
- };
159
- });
160
- }
161
- async function F(e) {
162
- const {
163
- retries: i = 1
164
- } = e;
165
- let n = null;
166
- for (let t = 0; (n == null ? void 0 : n.readyState) !== WebSocket.OPEN; t++)
167
- try {
168
- n = await U(e);
169
- } catch (r) {
170
- if (t === i)
171
- throw r;
172
- await H(t * 500);
173
- }
174
- return n;
175
- }
176
- async function T(e, i, n) {
177
- const t = n ? [n] : [], r = await F({
178
- auth: e,
179
- host: i,
180
- callbacks: {
181
- onMessage: (a) => {
182
- const o = JSON.parse(a.data);
183
- t.forEach((u) => u(o.event, o));
184
- }
185
- }
186
- });
187
- return {
188
- socket: r,
189
- terminate: () => r.close(),
190
- subscribeToEvents: (a) => t.push(a)
191
- };
192
- }
193
- var q = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(q || {}), N = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(N || {}), $ = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))($ || {}), y = /* @__PURE__ */ ((e) => (e.ChatAnswer = "chat/answer", e.ChatPartial = "chat/partial", e.StreamDone = "stream/done", e.StreamStarted = "stream/started", e.StreamFailed = "stream/error", e))(y || {}), j = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(j || {}), z = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e))(z || {}), M = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Complete = "done", e))(M || {}), J = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(J || {}), D = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(D || {}), G = /* @__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))(G || {}), R = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e))(R || {});
194
- function Q(e) {
195
- return e.presenter.type === R.Clip ? {
196
- videoType: R.Clip,
197
- driver_id: e.presenter.driver_id,
198
- presenter_id: e.presenter.presenter_id
199
- } : {
200
- videoType: R.Talk,
201
- source_url: e.presenter.source_url
202
- };
203
- }
204
- function P(e, i, n, t) {
205
- return new Promise(async (r, a) => {
206
- const o = await te(Q(e), {
207
- ...i,
208
- callbacks: {
209
- ...i.callbacks,
210
- onConnectionStateChange: async (u) => {
211
- var c, m;
212
- if (u === "connected")
213
- try {
214
- t || (t = await n.newChat(e.id)), r({
215
- chat: t,
216
- streamingManager: o
217
- });
218
- } catch (d) {
219
- console.error(d), a(new Error("Cannot create new chat"));
220
- }
221
- else
222
- u === "failed" && a(new Error("Cannot create connection"));
223
- (m = (c = i.callbacks).onConnectionStateChange) == null || m.call(c, u);
224
- },
225
- // TODO remove when webscoket will return partial
226
- onMessage: (u, c) => {
227
- var m, d;
228
- u === y.ChatAnswer && (console.log("ChatAnswer", u, c), (d = (m = i.callbacks).onChatEvents) == null || d.call(m, M.Answer, {
229
- content: c,
230
- event: M.Answer
231
- }));
232
- }
233
- }
234
- });
235
- });
236
- }
237
- function ne(e, i, n) {
238
- return E(i, n || C).getById(e);
239
- }
240
- async function re(e, i) {
241
- var w, p;
242
- const n = i.baseURL || C, t = i.wsURL || b, r = new AbortController(), a = E(i.auth, n), o = B(i.auth, n), u = O(i.auth, n), c = typeof e == "string" ? await a.getById(e) : e;
243
- (p = (w = i.callbacks) == null ? void 0 : w.onAgentReady) == null || p.call(w, c);
244
- const m = await T(i.auth, t, i.callbacks.onChatEvents);
245
- let {
246
- chat: d,
247
- streamingManager: g
248
- } = await P(c, i, a);
249
- return {
250
- agent: c,
251
- chatId: d.id,
252
- async reconnectToChat() {
253
- const {
254
- streamingManager: s
255
- } = await P(c, i, a, d);
256
- g = s;
257
- },
258
- terminate() {
259
- return r.abort(), m.terminate(), g.terminate();
260
- },
261
- chat(s) {
262
- return a.chat(c.id, d.id, {
263
- sessionId: g.sessionId,
264
- streamId: g.streamId,
265
- messages: s
266
- }, {
267
- signal: r.signal
268
- });
269
- },
270
- rate(s, f) {
271
- return f ? o.update(f, s) : o.create(s);
272
- },
273
- deleteRate(s) {
274
- return o.delete(s);
275
- },
276
- speak(s) {
277
- function f() {
278
- if (s.type === "text")
279
- return {
280
- type: "text",
281
- provider: s.provider,
282
- input: s.input,
283
- ssml: s.ssml || !1
284
- };
285
- if (s.type === "audio")
286
- return {
287
- type: "audio",
288
- audio_url: s.audio_url
289
- };
290
- throw new Error("Invalid payload");
291
- }
292
- return g.speak({
293
- script: f()
294
- });
295
- },
296
- async getStarterMessages() {
297
- var s;
298
- return (s = c.knowledge) != null && s.id ? u.getKnowledge(c.knowledge.id).then((f) => (f == null ? void 0 : f.starter_message) || []) : [];
299
- }
300
- };
301
- }
302
- function X(e, i) {
303
- const n = _(e, i);
304
- return {
305
- createStream(t) {
306
- return n.post("/clips/streams", {
307
- driver_id: t.driver_id,
308
- presenter_id: t.presenter_id,
309
- compatibility_mode: t.compatibility_mode
310
- });
311
- },
312
- startConnection(t, r, a) {
313
- return n.post(`/clips/streams/${t}/sdp`, {
314
- session_id: a,
315
- answer: r
316
- });
317
- },
318
- addIceCandidate(t, r, a) {
319
- return n.post(`/clips/streams/${t}/ice`, {
320
- session_id: a,
321
- ...r
322
- });
323
- },
324
- sendStreamRequest(t, r, a) {
325
- return n.post(`/clips/streams/${t}`, {
326
- session_id: r,
327
- ...a
328
- });
329
- },
330
- close(t, r) {
331
- return n.delete(`/clips/streams/${t}`, {
332
- session_id: r
333
- });
334
- }
335
- };
336
- }
337
- function Y(e, i) {
338
- const n = _(e, i);
339
- return {
340
- createStream(t, r) {
341
- return n.post("/talks/streams", {
342
- source_url: t.source_url,
343
- driver_url: t.driver_url,
344
- face: t.face,
345
- config: t.config
346
- }, r);
347
- },
348
- startConnection(t, r, a, o) {
349
- return n.post(`/talks/streams/${t}/sdp`, {
350
- session_id: a,
351
- answer: r
352
- }, o);
353
- },
354
- addIceCandidate(t, r, a, o) {
355
- return n.post(`/talks/streams/${t}/ice`, {
356
- session_id: a,
357
- ...r
358
- }, o);
359
- },
360
- sendStreamRequest(t, r, a, o) {
361
- return n.post(`/talks/streams/${t}`, {
362
- session_id: r,
363
- ...a
364
- }, o);
365
- },
366
- close(t, r, a) {
367
- return n.delete(`/talks/streams/${t}`, {
368
- session_id: r
369
- }, a);
370
- }
371
- };
372
- }
373
- function Z(e, i) {
374
- return e.map((n, t) => t === 0 ? i ? {
375
- index: t,
376
- timestamp: n.timestamp,
377
- bytesReceived: n.bytesReceived - i.bytesReceived,
378
- packetsReceived: n.packetsReceived - i.packetsReceived,
379
- packetsLost: n.packetsLost - i.packetsLost,
380
- jitter: n.jitter,
381
- frameWidth: n.frameWidth,
382
- frameHeight: n.frameHeight,
383
- frameRate: n.frameRate
384
- } : {
385
- index: t,
386
- timestamp: n.timestamp,
387
- bytesReceived: n.bytesReceived,
388
- packetsReceived: n.packetsReceived,
389
- packetsLost: n.packetsLost,
390
- jitter: n.jitter,
391
- frameWidth: n.frameWidth,
392
- frameHeight: n.frameHeight,
393
- frameRate: n.frameRate
394
- } : {
395
- index: t,
396
- timestamp: n.timestamp,
397
- bytesReceived: n.bytesReceived - e[t - 1].bytesReceived,
398
- packetsReceived: n.packetsReceived - e[t - 1].packetsReceived,
399
- packetsLost: n.packetsLost - e[t - 1].packetsLost,
400
- jitter: n.jitter,
401
- frameWidth: n.frameWidth,
402
- frameHeight: n.frameHeight,
403
- frameRate: n.frameRate
404
- });
405
- }
406
- let x = !1;
407
- const v = (e, i) => x && console.log(e, i), V = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
408
- function ee(e, i) {
409
- let n = [], t = 0, r = 0, a;
410
- return setInterval(() => {
411
- e.getStats().then((u) => {
412
- u.forEach((c) => {
413
- if (c.type === "inbound-rtp" && c.kind === "video") {
414
- if (r = n.length - 1, c && n[r]) {
415
- const m = c.bytesReceived, d = n[r].bytesReceived;
416
- let g = a;
417
- a = m - d > 0;
418
- let w;
419
- if (g !== a) {
420
- if (a)
421
- t = n.length;
422
- else {
423
- const p = n.slice(t), s = t === 0 ? void 0 : n[t - 1];
424
- w = Z(p, s), w = w.sort((f, A) => A.packetsLost - f.packetsLost).slice(0, 5);
425
- }
426
- i == null || i(a ? $.Start : $.Stop, w);
427
- }
428
- }
429
- n.push(c);
430
- }
431
- });
432
- });
433
- }, 500);
434
- }
435
- async function te(e, {
436
- debug: i = !1,
437
- callbacks: n,
438
- auth: t,
439
- baseURL: r = C
440
- }) {
441
- x = i;
442
- const {
443
- startConnection: a,
444
- sendStreamRequest: o,
445
- close: u,
446
- createStream: c,
447
- addIceCandidate: m
448
- } = e.videoType === R.Clip ? X(t, r) : Y(t, r), {
449
- id: d,
450
- offer: g,
451
- ice_servers: w,
452
- session_id: p
453
- } = await c(e), s = new V({
454
- iceServers: w
455
- }), f = s.createDataChannel("JanusDataChannel");
456
- if (!p)
457
- throw new Error("Could not create session_id");
458
- const A = ee(s, n.onVideoStateChange);
459
- s.onicecandidate = (l) => {
460
- v("peerConnection.onicecandidate", l), l.candidate && l.candidate.sdpMid && l.candidate.sdpMLineIndex !== null && m(d, {
461
- candidate: l.candidate.candidate,
462
- sdpMid: l.candidate.sdpMid,
463
- sdpMLineIndex: l.candidate.sdpMLineIndex
464
- }, p);
465
- }, s.oniceconnectionstatechange = () => {
466
- var l;
467
- v("peerConnection.oniceconnectionstatechange => " + s.iceConnectionState), (l = n.onConnectionStateChange) == null || l.call(n, s.iceConnectionState);
468
- }, s.ontrack = (l) => {
469
- var h;
470
- v("peerConnection.ontrack", l), (h = n.onSrcObjectReady) == null || h.call(n, l.streams[0]);
471
- }, f.onmessage = (l) => {
472
- var h, k;
473
- if (f.readyState === "open") {
474
- const [S, I] = l.data.split(":");
475
- S === y.StreamStarted ? console.log("StreamStarted", S, I) : S === y.StreamDone ? console.log("StreamDone") : S === y.StreamFailed ? ((h = n.onVideoStateChange) == null || h.call(n, $.Stop, {
476
- event: S,
477
- data: I
478
- }), clearInterval(A), console.log("StreamFailed")) : (k = n.onMessage) == null || k.call(n, S, decodeURIComponent(I));
479
- }
480
- }, await s.setRemoteDescription(g), v("set remote description OK");
481
- const L = await s.createAnswer();
482
- return v("create answer OK"), await s.setLocalDescription(L), v("set local description OK"), await a(d, L, p), v("start connection OK"), {
483
- /**
484
- * Method to send request to server to get clip or talk depend on you payload
485
- * @param payload
486
- */
487
- speak(l) {
488
- return o(d, p, l);
489
- },
490
- /**
491
- * Method to close RTC connection
492
- */
493
- async terminate() {
494
- var l, h;
495
- d && (s && (s.close(), s.oniceconnectionstatechange = null, s.onnegotiationneeded = null, s.onicecandidate = null, s.ontrack = null), await u(d, p).catch((k) => {
496
- }), (l = n.onConnectionStateChange) == null || l.call(n, "closed"), (h = n.onVideoStateChange) == null || h.call(n, $.Stop), clearInterval(A));
497
- },
498
- /**
499
- * Session identifier information, should be returned in the body of all streaming requests
500
- */
501
- sessionId: p,
502
- /**
503
- * Id of current RTC stream
504
- */
505
- streamId: d
506
- };
507
- }
508
- export {
509
- z as ChatMode,
510
- M as ChatProgress,
511
- G as DocumentType,
512
- D as KnowledgeType,
513
- q as Providers,
514
- j as RateState,
515
- T as SocketManager,
516
- y as StreamEvents,
517
- J as Subject,
518
- N as VoiceAccess,
519
- re as createAgentManager,
520
- E as createAgentsApi,
521
- _ as createClient,
522
- O as createKnowledgeApi,
523
- B as createRatingsApi,
524
- te as createStreamingManager,
525
- ne as getAgent
526
- };
@@ -1 +0,0 @@
1
- (function(l,h){typeof exports=="object"&&typeof module<"u"?h(exports):typeof define=="function"&&define.amd?define(["exports"],h):(l=typeof globalThis<"u"?globalThis:l||self,h(l.index={}))})(this,function(l){"use strict";const h="https://api.d-id.com",D="wss://notifications.d-id.com";function G(){let e=window.localStorage.getItem("did_external_key_id");return e||(e=Math.random().toString(16).slice(2),window.localStorage.setItem("did_external_key_id",e)),e}function K(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}.${G()}`;throw new Error(`Unknown auth type: ${e}`)}function y(e,i=h){const n=async(t,r)=>{const a=await fetch(i+(t!=null&&t.startsWith("/")?t:`/${t}`),{...r,headers:{...r==null?void 0:r.headers,Authorization:K(e),"Content-Type":"application/json"}});if(!a.ok){let o=await a.text().catch(()=>"Failed to fetch");throw new Error(o)}return a.json()};return{get(t,r){return n(t,{...r,method:"GET"})},post(t,r,a){return n(t,{...a,body:JSON.stringify(r),method:"POST"})},delete(t,r,a){return n(t,{...a,body:JSON.stringify(r),method:"DELETE"})},patch(t,r,a){return n(t,{...a,body:JSON.stringify(r),method:"PATCH"})}}}function M(e,i=h){const n=y(e,`${i}/agents`);return{create(t,r){return n.post("/",t,r)},getAgents(t,r){return n.get(`/${t?`?tag=${t}`:""}`,r).then(a=>a??[])},getById(t,r){return n.get(`/${t}`,r)},delete(t,r){return n.delete(`/${t}`,void 0,r)},update(t,r,a){return n.patch(`/${t}`,r,a)},newChat(t,r){return n.post(`/${t}/chat`,void 0,r)},chat(t,r,a,o){return n.post(`/${t}/chat/${r}`,a,o)}}}function b(e,i=h){const n=y(e,`${i}/knowledge`);return{createKnowledge(t,r){return n.post("/",t,r)},getKnowledgeBase(t){return n.get("/",t)},getKnowledge(t,r){return n.get(`/${t}`,r)},deleteKnowledge(t,r){return n.delete(`/${t}`,void 0,r)},createDocument(t,r,a){return n.post(`/${t}/documents`,r,a)},deleteDocument(t,r,a){return n.delete(`/${t}/documents/${r}`,void 0,a)},getDocuments(t,r){return n.get(`/${t}/documents`,r)},getDocument(t,r,a){return n.get(`/${t}/documents/${r}`,a)},getRecords(t,r,a){return n.get(`/${t}/documents/${r}/records`,a)},query(t,r,a){return n.post(`/${t}/query`,{query:r},a)}}}function E(e,i=h){const n=y(e,`${i}/chats/ratings`);return{create(t,r){return n.post("/",t,r)},getByKnowledge(t,r){return n.get(`/${t}`,r).then(a=>a??[])},update(t,r,a){return n.patch(`/${t}`,r,a)},delete(t,r){return n.delete(`/${t}`,r)}}}const Q=e=>new Promise(i=>setTimeout(i,e));function x(e){return new Promise((i,n)=>{const{callbacks:t,host:r,auth:a}=e,{onMessage:o=null,onOpen:g=null,onClose:c=null,onError:m=null}=t||{},d=new WebSocket(`${r}?authorization=${K(a)}`);d.onmessage=o,d.onclose=c,d.onerror=f=>{console.error(f),m==null||m(f),n(f)},d.onopen=f=>{g==null||g(f),i(d)}})}async function X(e){const{retries:i=1}=e;let n=null;for(let t=0;(n==null?void 0:n.readyState)!==WebSocket.OPEN;t++)try{n=await x(e)}catch(r){if(t===i)throw r;await Q(t*500)}return n}async function T(e,i,n){const t=n?[n]:[],r=await X({auth:e,host:i,callbacks:{onMessage:a=>{const o=JSON.parse(a.data);t.forEach(g=>g(o.event,o))}}});return{socket:r,terminate:()=>r.close(),subscribeToEvents:a=>t.push(a)}}var O=(e=>(e.Amazon="amazon",e.Microsoft="microsoft",e.Afflorithmics="afflorithmics",e.Elevenlabs="elevenlabs",e))(O||{}),W=(e=>(e.Public="public",e.Premium="premium",e.Private="private",e))(W||{}),A=(e=>(e.Start="START",e.Stop="STOP",e))(A||{}),R=(e=>(e.ChatAnswer="chat/answer",e.ChatPartial="chat/partial",e.StreamDone="stream/done",e.StreamStarted="stream/started",e.StreamFailed="stream/error",e))(R||{}),j=(e=>(e.Unrated="Unrated",e.Positive="Positive",e.Negative="Negative",e))(j||{}),B=(e=>(e.Functional="Functional",e.TextOnly="TextOnly",e.Maintenance="Maintenance",e))(B||{}),k=(e=>(e.Embed="embed",e.Query="query",e.Partial="partial",e.Answer="answer",e.Complete="done",e))(k||{}),H=(e=>(e.KnowledgeProcessing="knowledge/processing",e.KnowledgeIndexing="knowledge/indexing",e.KnowledgeFailed="knowledge/error",e.KnowledgeDone="knowledge/done",e))(H||{}),U=(e=>(e.Knowledge="knowledge",e.Document="document",e.Record="record",e))(U||{}),F=(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))(F||{}),_=(e=>(e.Clip="clip",e.Talk="talk",e))(_||{});function Y(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 q(e,i,n,t){return new Promise(async(r,a)=>{const o=await z(Y(e),{...i,callbacks:{...i.callbacks,onConnectionStateChange:async g=>{var c,m;if(g==="connected")try{t||(t=await n.newChat(e.id)),r({chat:t,streamingManager:o})}catch(d){console.error(d),a(new Error("Cannot create new chat"))}else g==="failed"&&a(new Error("Cannot create connection"));(m=(c=i.callbacks).onConnectionStateChange)==null||m.call(c,g)},onMessage:(g,c)=>{var m,d;g===R.ChatAnswer&&(console.log("ChatAnswer",g,c),(d=(m=i.callbacks).onChatEvents)==null||d.call(m,k.Answer,{content:c,event:k.Answer}))}}})})}function Z(e,i,n){return M(i,n||h).getById(e)}async function V(e,i){var p,v;const n=i.baseURL||h,t=i.wsURL||D,r=new AbortController,a=M(i.auth,n),o=E(i.auth,n),g=b(i.auth,n),c=typeof e=="string"?await a.getById(e):e;(v=(p=i.callbacks)==null?void 0:p.onAgentReady)==null||v.call(p,c);const m=await T(i.auth,t,i.callbacks.onChatEvents);let{chat:d,streamingManager:f}=await q(c,i,a);return{agent:c,chatId:d.id,async reconnectToChat(){const{streamingManager:s}=await q(c,i,a,d);f=s},terminate(){return r.abort(),m.terminate(),f.terminate()},chat(s){return a.chat(c.id,d.id,{sessionId:f.sessionId,streamId:f.streamId,messages:s},{signal:r.signal})},rate(s,w){return w?o.update(w,s):o.create(s)},deleteRate(s){return o.delete(s)},speak(s){function w(){if(s.type==="text")return{type:"text",provider:s.provider,input:s.input,ssml:s.ssml||!1};if(s.type==="audio")return{type:"audio",audio_url:s.audio_url};throw new Error("Invalid payload")}return f.speak({script:w()})},async getStarterMessages(){var s;return(s=c.knowledge)!=null&&s.id?g.getKnowledge(c.knowledge.id).then(w=>(w==null?void 0:w.starter_message)||[]):[]}}}function ee(e,i){const n=y(e,i);return{createStream(t){return n.post("/clips/streams",{driver_id:t.driver_id,presenter_id:t.presenter_id,compatibility_mode:t.compatibility_mode})},startConnection(t,r,a){return n.post(`/clips/streams/${t}/sdp`,{session_id:a,answer:r})},addIceCandidate(t,r,a){return n.post(`/clips/streams/${t}/ice`,{session_id:a,...r})},sendStreamRequest(t,r,a){return n.post(`/clips/streams/${t}`,{session_id:r,...a})},close(t,r){return n.delete(`/clips/streams/${t}`,{session_id:r})}}}function te(e,i){const n=y(e,i);return{createStream(t,r){return n.post("/talks/streams",{source_url:t.source_url,driver_url:t.driver_url,face:t.face,config:t.config},r)},startConnection(t,r,a,o){return n.post(`/talks/streams/${t}/sdp`,{session_id:a,answer:r},o)},addIceCandidate(t,r,a,o){return n.post(`/talks/streams/${t}/ice`,{session_id:a,...r},o)},sendStreamRequest(t,r,a,o){return n.post(`/talks/streams/${t}`,{session_id:r,...a},o)},close(t,r,a){return n.delete(`/talks/streams/${t}`,{session_id:r},a)}}}function ne(e,i){return e.map((n,t)=>t===0?i?{index:t,timestamp:n.timestamp,bytesReceived:n.bytesReceived-i.bytesReceived,packetsReceived:n.packetsReceived-i.packetsReceived,packetsLost:n.packetsLost-i.packetsLost,jitter:n.jitter,frameWidth:n.frameWidth,frameHeight:n.frameHeight,frameRate:n.frameRate}:{index:t,timestamp:n.timestamp,bytesReceived:n.bytesReceived,packetsReceived:n.packetsReceived,packetsLost:n.packetsLost,jitter:n.jitter,frameWidth:n.frameWidth,frameHeight:n.frameHeight,frameRate:n.frameRate}:{index:t,timestamp:n.timestamp,bytesReceived:n.bytesReceived-e[t-1].bytesReceived,packetsReceived:n.packetsReceived-e[t-1].packetsReceived,packetsLost:n.packetsLost-e[t-1].packetsLost,jitter:n.jitter,frameWidth:n.frameWidth,frameHeight:n.frameHeight,frameRate:n.frameRate})}let N=!1;const C=(e,i)=>N&&console.log(e,i),re=(window.RTCPeerConnection||window.webkitRTCPeerConnection||window.mozRTCPeerConnection).bind(window);function ae(e,i){let n=[],t=0,r=0,a;return setInterval(()=>{e.getStats().then(g=>{g.forEach(c=>{if(c.type==="inbound-rtp"&&c.kind==="video"){if(r=n.length-1,c&&n[r]){const m=c.bytesReceived,d=n[r].bytesReceived;let f=a;a=m-d>0;let p;if(f!==a){if(a)t=n.length;else{const v=n.slice(t),s=t===0?void 0:n[t-1];p=ne(v,s),p=p.sort((w,I)=>I.packetsLost-w.packetsLost).slice(0,5)}i==null||i(a?A.Start:A.Stop,p)}}n.push(c)}})})},500)}async function z(e,{debug:i=!1,callbacks:n,auth:t,baseURL:r=h}){N=i;const{startConnection:a,sendStreamRequest:o,close:g,createStream:c,addIceCandidate:m}=e.videoType===_.Clip?ee(t,r):te(t,r),{id:d,offer:f,ice_servers:p,session_id:v}=await c(e),s=new re({iceServers:p}),w=s.createDataChannel("JanusDataChannel");if(!v)throw new Error("Could not create session_id");const I=ae(s,n.onVideoStateChange);s.onicecandidate=u=>{C("peerConnection.onicecandidate",u),u.candidate&&u.candidate.sdpMid&&u.candidate.sdpMLineIndex!==null&&m(d,{candidate:u.candidate.candidate,sdpMid:u.candidate.sdpMid,sdpMLineIndex:u.candidate.sdpMLineIndex},v)},s.oniceconnectionstatechange=()=>{var u;C("peerConnection.oniceconnectionstatechange => "+s.iceConnectionState),(u=n.onConnectionStateChange)==null||u.call(n,s.iceConnectionState)},s.ontrack=u=>{var S;C("peerConnection.ontrack",u),(S=n.onSrcObjectReady)==null||S.call(n,u.streams[0])},w.onmessage=u=>{var S,P;if(w.readyState==="open"){const[$,L]=u.data.split(":");$===R.StreamStarted?console.log("StreamStarted",$,L):$===R.StreamDone?console.log("StreamDone"):$===R.StreamFailed?((S=n.onVideoStateChange)==null||S.call(n,A.Stop,{event:$,data:L}),clearInterval(I),console.log("StreamFailed")):(P=n.onMessage)==null||P.call(n,$,decodeURIComponent(L))}},await s.setRemoteDescription(f),C("set remote description OK");const J=await s.createAnswer();return C("create answer OK"),await s.setLocalDescription(J),C("set local description OK"),await a(d,J,v),C("start connection OK"),{speak(u){return o(d,v,u)},async terminate(){var u,S;d&&(s&&(s.close(),s.oniceconnectionstatechange=null,s.onnegotiationneeded=null,s.onicecandidate=null,s.ontrack=null),await g(d,v).catch(P=>{}),(u=n.onConnectionStateChange)==null||u.call(n,"closed"),(S=n.onVideoStateChange)==null||S.call(n,A.Stop),clearInterval(I))},sessionId:v,streamId:d}}l.ChatMode=B,l.ChatProgress=k,l.DocumentType=F,l.KnowledgeType=U,l.Providers=O,l.RateState=j,l.SocketManager=T,l.StreamEvents=R,l.Subject=H,l.VoiceAccess=W,l.createAgentManager=V,l.createAgentsApi=M,l.createClient=y,l.createKnowledgeApi=b,l.createRatingsApi=E,l.createStreamingManager=z,l.getAgent=Z,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
@@ -1,10 +0,0 @@
1
- import { Agent, AgentPayload, Auth, Chat, ChatPayload, ChatResponse } from '../types/index';
2
- export declare function createAgentsApi(auth: Auth, host?: string): {
3
- create(payload: AgentPayload, options?: RequestInit): Promise<Agent>;
4
- getAgents(tag?: string, options?: RequestInit): Promise<Agent[]>;
5
- getById(id: string, options?: RequestInit): Promise<Agent>;
6
- delete(id: string, options?: RequestInit): Promise<any>;
7
- update(id: string, payload: AgentPayload, options?: RequestInit): Promise<Agent>;
8
- newChat(agentId: string, options?: RequestInit): Promise<Chat>;
9
- chat(agentId: string, chatId: string, payload: ChatPayload, options?: RequestInit): Promise<ChatResponse>;
10
- };
@@ -1,2 +0,0 @@
1
- import { Auth, RtcApi } from '../types/index';
2
- export declare function createApi(auth: Auth, host: string): RtcApi;
@@ -1,7 +0,0 @@
1
- import { Auth } from '../types/auth';
2
- export declare function createClient(auth: Auth, host?: string): {
3
- get<T = any>(url: string, options?: RequestInit): Promise<T>;
4
- post<T_1 = any>(url: string, body?: any, options?: RequestInit): Promise<T_1>;
5
- delete<T_2 = any>(url: string, body?: any, options?: RequestInit): Promise<T_2>;
6
- patch<T_3 = any>(url: string, body?: any, options?: RequestInit): Promise<T_3>;
7
- };
@@ -1,13 +0,0 @@
1
- import { Auth, CreateDocumentPayload, DocumentData, KnowledgeData, KnowledgePayload, QueryResult, RecordData } from '../types/index';
2
- export declare function createKnowledgeApi(auth: Auth, host?: string): {
3
- createKnowledge(payload: KnowledgePayload, options?: RequestInit): Promise<KnowledgeData>;
4
- getKnowledgeBase(options?: RequestInit): Promise<KnowledgeData[]>;
5
- getKnowledge(knowledgeId: string, options?: RequestInit): Promise<KnowledgeData>;
6
- deleteKnowledge(knowledgeId: string, options?: RequestInit): Promise<any>;
7
- createDocument(knowledgeId: string, payload: CreateDocumentPayload, options?: RequestInit): Promise<DocumentData>;
8
- deleteDocument(knowledgeId: string, documentId: string, options?: RequestInit): Promise<any>;
9
- getDocuments(knowledgeId: string, options?: RequestInit): Promise<DocumentData[]>;
10
- getDocument(knowledgeId: string, documentId: string, options?: RequestInit): Promise<DocumentData>;
11
- getRecords(knowledgeId: string, documentId: string, options?: RequestInit): Promise<RecordData[]>;
12
- query(knowledgeId: string, query: string, options?: RequestInit): Promise<QueryResult>;
13
- };
@@ -1,7 +0,0 @@
1
- import { Auth, RatingEntity, RatingPayload } from '../index';
2
- export declare function createRatingsApi(auth: Auth, host?: string): {
3
- create(payload: RatingPayload, options?: RequestInit): Promise<RatingEntity>;
4
- getByKnowledge(knowledgeId?: string, options?: RequestInit): Promise<RatingEntity[]>;
5
- update(id: string, payload: Partial<RatingPayload>, options?: RequestInit): Promise<RatingEntity>;
6
- delete(id: string, options?: RequestInit): Promise<RatingEntity>;
7
- };
@@ -1,2 +0,0 @@
1
- import { Auth, RtcApi } from '../types/index';
2
- export declare function createApi(auth: Auth, host: string): RtcApi;
@@ -1,2 +0,0 @@
1
- import { Auth } from '../types/auth';
2
- export declare function getAuthHeader(auth: Auth): string;
@@ -1,9 +0,0 @@
1
- import { Auth } from './types/auth';
2
- import { ChatProgressCallback } from '.';
3
- interface SocketManager {
4
- socket?: WebSocket;
5
- terminate: () => void;
6
- subscribeToEvents: (data: any) => void;
7
- }
8
- export declare function SocketManager(auth: Auth, host: string, onMessage?: ChatProgressCallback): Promise<SocketManager>;
9
- export {};
@@ -1,16 +0,0 @@
1
- import { Agent, AgentManager, AgentManagerOptions } from './types/index';
2
- import { Auth } from '.';
3
- export declare function getAgent(agentId: string, auth: Auth, baseURL?: string): Promise<Agent>;
4
- /**
5
- * Creates a new Agent Manager instance for interacting with an agent, chat, and related connections.
6
- *
7
- * @param {string} agent - The ID or instance of the agent to chat with.
8
- * @param {AgentManagerOptions} options - Configurations for the Agent Manager API.
9
- * * @returns {Promise<AgentManager>} - A promise that resolves to an instance of the AgentsAPI interface.
10
- *
11
- * @throws {Error} Throws an error if the agent is not initialized.
12
- *
13
- * @example
14
- * const agentManager = await createAgentManager('id-agent123', { auth: { type: 'key', clientKey: '123', externalId: '123' } });
15
- */
16
- export declare function createAgentManager(agent: string | Agent, options: AgentManagerOptions): Promise<AgentManager>;
@@ -1,21 +0,0 @@
1
- import { CreateStreamOptions, PayloadType, StreamingManagerOptions } from './types/index';
2
- export declare function createStreamingManager<T extends CreateStreamOptions>(agent: T, { debug, callbacks, auth, baseURL }: StreamingManagerOptions): Promise<{
3
- /**
4
- * Method to send request to server to get clip or talk depend on you payload
5
- * @param payload
6
- */
7
- speak(payload: PayloadType<T>): Promise<import('./types/index').SendStreamPayloadResponse>;
8
- /**
9
- * Method to close RTC connection
10
- */
11
- terminate(): Promise<void>;
12
- /**
13
- * Session identifier information, should be returned in the body of all streaming requests
14
- */
15
- sessionId: string;
16
- /**
17
- * Id of current RTC stream
18
- */
19
- streamId: string;
20
- }>;
21
- export type StreamingManager<T extends CreateStreamOptions> = Awaited<ReturnType<typeof createStreamingManager<T>>>;