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