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