@d-id/client-sdk 1.0.19-beta.5 → 1.0.19-beta.50

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