@d-id/client-sdk 1.0.18-beta.5 → 1.0.18-beta.7
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 +143 -152
- package/dist/index.umd.cjs +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/lib/api/agents.d.ts +1 -1
- package/dist/src/lib/api/clipStream.d.ts +1 -1
- package/dist/src/lib/api/getClient.d.ts +1 -1
- package/dist/src/lib/api/knowledge.d.ts +1 -1
- package/dist/src/lib/api/talkStream.d.ts +1 -1
- package/dist/src/lib/auth/getAuthHeader.d.ts +1 -1
- package/dist/src/lib/connectToSocket.d.ts +1 -1
- package/dist/src/lib/createAgentManager.d.ts +1 -1
- package/dist/src/lib/createStreamingManager.d.ts +2 -6
- package/dist/src/lib/environment.d.ts +7 -2
- package/dist/{types → src/types}/entities/agents/manager.d.ts +1 -1
- package/dist/{types → src/types}/index.d.ts +1 -1
- package/package.json +2 -2
- /package/dist/{types → src/types}/StreamScript.d.ts +0 -0
- /package/dist/{types → src/types}/auth.d.ts +0 -0
- /package/dist/{types → src/types}/entities/agents/agent.d.ts +0 -0
- /package/dist/{types → src/types}/entities/agents/chat.d.ts +0 -0
- /package/dist/{types → src/types}/entities/agents/index.d.ts +0 -0
- /package/dist/{types → src/types}/entities/agents/knowledge.d.ts +0 -0
- /package/dist/{types → src/types}/entities/agents/llm.d.ts +0 -0
- /package/dist/{types → src/types}/entities/agents/presenter.d.ts +0 -0
- /package/dist/{types → src/types}/entities/index.d.ts +0 -0
- /package/dist/{types → src/types}/entities/knowledge/document.d.ts +0 -0
- /package/dist/{types → src/types}/entities/knowledge/index.d.ts +0 -0
- /package/dist/{types → src/types}/entities/knowledge/knowledge.d.ts +0 -0
- /package/dist/{types → src/types}/entities/knowledge/record.d.ts +0 -0
- /package/dist/{types → src/types}/entities/knowledge/retrival.d.ts +0 -0
- /package/dist/{types → src/types}/entities/video.d.ts +0 -0
- /package/dist/{types → src/types}/stream/api/clip.d.ts +0 -0
- /package/dist/{types → src/types}/stream/api/index.d.ts +0 -0
- /package/dist/{types → src/types}/stream/api/talk.d.ts +0 -0
- /package/dist/{types → src/types}/stream/index.d.ts +0 -0
- /package/dist/{types → src/types}/stream/rtc.d.ts +0 -0
- /package/dist/{types → src/types}/stream/stream.d.ts +0 -0
- /package/dist/{types → src/types}/tts.d.ts +0 -0
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const
|
|
2
|
-
function
|
|
1
|
+
const h = "https://api.d-id.com", z = "wss://notifications.d-id.com";
|
|
2
|
+
function P(e) {
|
|
3
3
|
if (e.type === "bearer")
|
|
4
4
|
return `Bearer ${e.token}`;
|
|
5
5
|
if (e.type === "basic")
|
|
@@ -8,13 +8,13 @@ function M(e) {
|
|
|
8
8
|
return `Client-Key ${e.clientKey}`;
|
|
9
9
|
throw new Error(`Unknown auth type: ${e}`);
|
|
10
10
|
}
|
|
11
|
-
function
|
|
11
|
+
function $(e, a = h) {
|
|
12
12
|
const o = async (t, n) => {
|
|
13
13
|
const r = await fetch(a + (t != null && t.startsWith("/") ? t : `/${t}`), {
|
|
14
14
|
...n,
|
|
15
15
|
headers: {
|
|
16
16
|
...n == null ? void 0 : n.headers,
|
|
17
|
-
Authorization:
|
|
17
|
+
Authorization: P(e),
|
|
18
18
|
"Content-Type": "application/json"
|
|
19
19
|
}
|
|
20
20
|
});
|
|
@@ -54,8 +54,8 @@ function S(e, a = f) {
|
|
|
54
54
|
}
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
|
-
function
|
|
58
|
-
const o =
|
|
57
|
+
function T(e, a = h) {
|
|
58
|
+
const o = $(e, `${a}/agents`);
|
|
59
59
|
return {
|
|
60
60
|
create(t, n) {
|
|
61
61
|
return o.post("/", t, n);
|
|
@@ -80,8 +80,8 @@ function z(e, a = f) {
|
|
|
80
80
|
}
|
|
81
81
|
};
|
|
82
82
|
}
|
|
83
|
-
function Z(e, a =
|
|
84
|
-
const o =
|
|
83
|
+
function Z(e, a = h) {
|
|
84
|
+
const o = $(e, `${a}/knowledge`);
|
|
85
85
|
return {
|
|
86
86
|
createKnowledge(t, n) {
|
|
87
87
|
return o.post("/", t, n);
|
|
@@ -117,8 +117,8 @@ function Z(e, a = f) {
|
|
|
117
117
|
}
|
|
118
118
|
};
|
|
119
119
|
}
|
|
120
|
-
const
|
|
121
|
-
function
|
|
120
|
+
const U = (e) => new Promise((a) => setTimeout(a, e));
|
|
121
|
+
function b(e) {
|
|
122
122
|
return new Promise((a, o) => {
|
|
123
123
|
const {
|
|
124
124
|
callbacks: t,
|
|
@@ -126,14 +126,14 @@ function U(e) {
|
|
|
126
126
|
auth: r
|
|
127
127
|
} = e, {
|
|
128
128
|
onMessage: c = null,
|
|
129
|
-
onOpen:
|
|
130
|
-
onClose:
|
|
131
|
-
onError:
|
|
132
|
-
} = t || {},
|
|
133
|
-
|
|
134
|
-
console.log(
|
|
135
|
-
},
|
|
136
|
-
|
|
129
|
+
onOpen: g = null,
|
|
130
|
+
onClose: p = null,
|
|
131
|
+
onError: l = null
|
|
132
|
+
} = t || {}, i = new WebSocket(`${n}?authorization=${P(r)}`);
|
|
133
|
+
i.onmessage = c, i.onclose = p, i.onerror = (d) => {
|
|
134
|
+
console.log(d), l == null || l(d), o(d);
|
|
135
|
+
}, i.onopen = (d) => {
|
|
136
|
+
g == null || g(d), a(i);
|
|
137
137
|
};
|
|
138
138
|
});
|
|
139
139
|
}
|
|
@@ -144,35 +144,33 @@ async function q(e) {
|
|
|
144
144
|
let o = null;
|
|
145
145
|
for (let t = 0; (o == null ? void 0 : o.readyState) !== WebSocket.OPEN; t++)
|
|
146
146
|
try {
|
|
147
|
-
o = await
|
|
147
|
+
o = await b(e);
|
|
148
148
|
} catch (n) {
|
|
149
149
|
if (t === a)
|
|
150
150
|
throw n;
|
|
151
|
-
await
|
|
151
|
+
await U(t * 500);
|
|
152
152
|
}
|
|
153
153
|
return o;
|
|
154
154
|
}
|
|
155
|
-
async function B(e, a =
|
|
155
|
+
async function B(e, a = z) {
|
|
156
156
|
const o = [], t = await q({
|
|
157
157
|
auth: e,
|
|
158
158
|
host: a,
|
|
159
159
|
callbacks: {
|
|
160
160
|
onMessage: (n) => {
|
|
161
|
-
|
|
161
|
+
o.forEach((r) => r(n));
|
|
162
162
|
}
|
|
163
163
|
}
|
|
164
164
|
});
|
|
165
165
|
return {
|
|
166
166
|
socket: t,
|
|
167
167
|
terminate: () => t.close(),
|
|
168
|
-
subscribeToEvents: (n) =>
|
|
169
|
-
o.push(n);
|
|
170
|
-
}
|
|
168
|
+
subscribeToEvents: (n) => o.push(n)
|
|
171
169
|
};
|
|
172
170
|
}
|
|
173
|
-
var L = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(L || {}), N = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(N || {}),
|
|
174
|
-
function V(e, a =
|
|
175
|
-
const o =
|
|
171
|
+
var L = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(L || {}), N = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(N || {}), S = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(S || {}), k = /* @__PURE__ */ ((e) => (e.ChatAnswer = "chat/answer", e.ChatPartial = "chat/partial", e.StreamDone = "stream/done", e.StreamStarted = "stream/started", e))(k || {}), J = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(J || {}), W = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(W || {}), F = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(F || {}), H = /* @__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))(H || {}), f = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e))(f || {});
|
|
172
|
+
function V(e, a = h) {
|
|
173
|
+
const o = $(e, `${a}/chats/ratings`);
|
|
176
174
|
return {
|
|
177
175
|
create(t, n) {
|
|
178
176
|
return o.post("/", t, n);
|
|
@@ -189,94 +187,93 @@ function V(e, a = f) {
|
|
|
189
187
|
};
|
|
190
188
|
}
|
|
191
189
|
function D(e) {
|
|
192
|
-
return e.presenter.type ===
|
|
193
|
-
videoType:
|
|
190
|
+
return e.presenter.type === f.Clip ? {
|
|
191
|
+
videoType: f.Clip,
|
|
194
192
|
driver_id: e.presenter.driver_id,
|
|
195
193
|
presenter_id: e.presenter.presenter_id
|
|
196
194
|
} : {
|
|
197
|
-
videoType:
|
|
195
|
+
videoType: f.Talk,
|
|
198
196
|
source_url: e.presenter.source_url
|
|
199
197
|
};
|
|
200
198
|
}
|
|
201
|
-
function
|
|
202
|
-
return new Promise(async (
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
199
|
+
function M(e, a, o, t) {
|
|
200
|
+
return new Promise(async (n, r) => {
|
|
201
|
+
const c = await Y(D(e), {
|
|
202
|
+
...a,
|
|
203
|
+
callbacks: {
|
|
204
|
+
...a.callbacks,
|
|
205
|
+
onConnectionStateChange: async (g) => {
|
|
206
|
+
var p, l;
|
|
207
|
+
g === "connected" ? (t || (t = await o.newChat(e.id)), n({
|
|
208
|
+
chat: t,
|
|
209
|
+
streamingManager: c
|
|
210
|
+
})) : g === "failed" && r(new Error("Cannot create connection")), (l = (p = a.callbacks).onConnectionStateChange) == null || l.call(p, g);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
});
|
|
216
214
|
});
|
|
217
215
|
}
|
|
218
216
|
async function O(e, a) {
|
|
219
|
-
const o = a.baseURL ||
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
});
|
|
217
|
+
const o = a.baseURL || h, t = new AbortController(), n = T(a.auth, o), r = V(a.auth, o), c = await n.getById(e), g = await B(a.auth);
|
|
218
|
+
let {
|
|
219
|
+
chat: p,
|
|
220
|
+
streamingManager: l
|
|
221
|
+
} = await M(c, a, n);
|
|
222
|
+
return {
|
|
223
|
+
agent: c,
|
|
224
|
+
async reconnectToChat() {
|
|
225
|
+
const {
|
|
226
|
+
streamingManager: i
|
|
227
|
+
} = await M(c, a, n, p);
|
|
228
|
+
l = i;
|
|
229
|
+
},
|
|
230
|
+
terminate() {
|
|
231
|
+
return t.abort(), g.terminate(), l.terminate();
|
|
232
|
+
},
|
|
233
|
+
chatId: p.id,
|
|
234
|
+
chat(i) {
|
|
235
|
+
return n.chat(e, p.id, {
|
|
236
|
+
sessionId: l.sessionId,
|
|
237
|
+
streamId: l.streamId,
|
|
238
|
+
messages: i
|
|
239
|
+
}, {
|
|
240
|
+
signal: t.signal
|
|
241
|
+
});
|
|
242
|
+
},
|
|
243
|
+
rate(i, d) {
|
|
244
|
+
return d ? r.update(d, i) : r.create(i);
|
|
245
|
+
},
|
|
246
|
+
speak(i) {
|
|
247
|
+
if (!c)
|
|
248
|
+
throw new Error("Agent not initializated");
|
|
249
|
+
let d;
|
|
250
|
+
return i.type === "text" ? d = {
|
|
251
|
+
script: {
|
|
252
|
+
type: "text",
|
|
253
|
+
provider: i.provider,
|
|
254
|
+
input: i.input,
|
|
255
|
+
ssml: i.ssml || !1
|
|
256
|
+
}
|
|
257
|
+
} : i.type === "audio" && (d = {
|
|
258
|
+
script: {
|
|
259
|
+
type: "audio",
|
|
260
|
+
audio_url: i.audio_url
|
|
261
|
+
}
|
|
262
|
+
}), l.speak(d);
|
|
263
|
+
},
|
|
264
|
+
onChatEvents(i) {
|
|
265
|
+
g.subscribeToEvents(i);
|
|
266
|
+
},
|
|
267
|
+
onConnectionEvents(i) {
|
|
268
|
+
l.onCallback("onConnectionStateChange", i);
|
|
269
|
+
},
|
|
270
|
+
onVideoEvents(i) {
|
|
271
|
+
l.onCallback("onVideoStateChange", i);
|
|
272
|
+
}
|
|
273
|
+
};
|
|
277
274
|
}
|
|
278
275
|
function G(e, a) {
|
|
279
|
-
const o =
|
|
276
|
+
const o = $(e, a);
|
|
280
277
|
return {
|
|
281
278
|
createStream(t) {
|
|
282
279
|
return o.post("/clips/streams", {
|
|
@@ -311,7 +308,7 @@ function G(e, a) {
|
|
|
311
308
|
};
|
|
312
309
|
}
|
|
313
310
|
function Q(e, a) {
|
|
314
|
-
const o =
|
|
311
|
+
const o = $(e, a);
|
|
315
312
|
return {
|
|
316
313
|
createStream(t, n) {
|
|
317
314
|
return o.post("/talks/streams", {
|
|
@@ -346,90 +343,84 @@ function Q(e, a) {
|
|
|
346
343
|
}
|
|
347
344
|
};
|
|
348
345
|
}
|
|
349
|
-
let
|
|
350
|
-
const
|
|
346
|
+
let K = !1;
|
|
347
|
+
const m = (e, a) => K && console.log(e, a), X = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
|
|
351
348
|
async function Y(e, {
|
|
352
349
|
debug: a = !1,
|
|
353
350
|
callbacks: o,
|
|
354
351
|
auth: t,
|
|
355
|
-
baseURL: n =
|
|
352
|
+
baseURL: n = h
|
|
356
353
|
}) {
|
|
357
|
-
|
|
354
|
+
K = a;
|
|
358
355
|
const r = {
|
|
359
356
|
...o
|
|
360
357
|
}, {
|
|
361
358
|
startConnection: c,
|
|
362
|
-
sendStreamRequest:
|
|
363
|
-
close:
|
|
364
|
-
createStream:
|
|
365
|
-
addIceCandidate:
|
|
366
|
-
} = e.videoType ===
|
|
367
|
-
id:
|
|
368
|
-
offer:
|
|
359
|
+
sendStreamRequest: g,
|
|
360
|
+
close: p,
|
|
361
|
+
createStream: l,
|
|
362
|
+
addIceCandidate: i
|
|
363
|
+
} = e.videoType === f.Clip ? G(t, n) : Q(t, n), {
|
|
364
|
+
id: d,
|
|
365
|
+
offer: E,
|
|
369
366
|
ice_servers: R,
|
|
370
|
-
session_id:
|
|
371
|
-
} = await
|
|
367
|
+
session_id: C
|
|
368
|
+
} = await l(e), u = new X({
|
|
372
369
|
iceServers: R
|
|
373
|
-
}),
|
|
374
|
-
if (!
|
|
370
|
+
}), A = u.createDataChannel("JanusDataChannel");
|
|
371
|
+
if (!C)
|
|
375
372
|
throw new Error("Could not create session_id");
|
|
376
|
-
|
|
377
|
-
|
|
373
|
+
u.onicecandidate = (s) => {
|
|
374
|
+
m("peerConnection.onicecandidate", s), s.candidate && s.candidate.sdpMid && s.candidate.sdpMLineIndex !== null && i(d, {
|
|
378
375
|
candidate: s.candidate.candidate,
|
|
379
376
|
sdpMid: s.candidate.sdpMid,
|
|
380
377
|
sdpMLineIndex: s.candidate.sdpMLineIndex
|
|
381
|
-
},
|
|
382
|
-
},
|
|
378
|
+
}, C);
|
|
379
|
+
}, u.oniceconnectionstatechange = () => {
|
|
383
380
|
var s;
|
|
384
|
-
|
|
385
|
-
},
|
|
386
|
-
var
|
|
387
|
-
|
|
388
|
-
},
|
|
389
|
-
var
|
|
390
|
-
if (
|
|
381
|
+
m("peerConnection.oniceconnectionstatechange => " + u.iceConnectionState), (s = r.onConnectionStateChange) == null || s.call(r, u.iceConnectionState);
|
|
382
|
+
}, u.ontrack = (s) => {
|
|
383
|
+
var w;
|
|
384
|
+
m("peerConnection.ontrack", s), (w = r.onSrcObjectReady) == null || w.call(r, s.streams[0]);
|
|
385
|
+
}, A.onmessage = (s) => {
|
|
386
|
+
var w, v, I;
|
|
387
|
+
if (A.readyState === "open") {
|
|
391
388
|
const [_, x] = s.data.split(":");
|
|
392
|
-
_ ===
|
|
389
|
+
_ === k.StreamDone ? (w = r.onVideoStateChange) == null || w.call(r, S.Stop) : _ === k.StreamStarted ? (v = r.onVideoStateChange) == null || v.call(r, S.Start) : (I = r.onMessage) == null || I.call(r, _, decodeURIComponent(x));
|
|
393
390
|
}
|
|
394
|
-
}, await
|
|
395
|
-
const
|
|
396
|
-
return
|
|
391
|
+
}, await u.setRemoteDescription(E), m("set remote description OK");
|
|
392
|
+
const y = await u.createAnswer();
|
|
393
|
+
return m("create answer OK"), await u.setLocalDescription(y), m("set local description OK"), await c(d, y, C), m("start connection OK"), {
|
|
397
394
|
/**
|
|
398
395
|
* Method to send request to server to get clip or talk depend on you payload
|
|
399
396
|
* @param payload
|
|
400
397
|
*/
|
|
401
398
|
speak(s) {
|
|
402
|
-
return
|
|
399
|
+
return g(d, C, s);
|
|
403
400
|
},
|
|
404
401
|
/**
|
|
405
402
|
* Method to close RTC connection
|
|
406
403
|
*/
|
|
407
404
|
async terminate() {
|
|
408
|
-
var s,
|
|
409
|
-
|
|
410
|
-
}), (s = r.onConnectionStateChange) == null || s.call(r, "closed"), (
|
|
405
|
+
var s, w;
|
|
406
|
+
d && (u && (u.close(), u.oniceconnectionstatechange = null, u.onnegotiationneeded = null, u.onicecandidate = null, u.ontrack = null), await p(d, C).catch((v) => {
|
|
407
|
+
}), (s = r.onConnectionStateChange) == null || s.call(r, "closed"), (w = r.onVideoStateChange) == null || w.call(r, S.Stop));
|
|
411
408
|
},
|
|
412
409
|
/**
|
|
413
410
|
* Session identifier information, should be returned in the body of all streaming requests
|
|
414
411
|
*/
|
|
415
|
-
sessionId:
|
|
412
|
+
sessionId: C,
|
|
416
413
|
/**
|
|
417
414
|
* Id of current RTC stream
|
|
418
415
|
*/
|
|
419
|
-
streamId:
|
|
416
|
+
streamId: d,
|
|
420
417
|
/**
|
|
421
418
|
* Method to add callback that will be trigered on supported events
|
|
422
419
|
* @param eventName
|
|
423
420
|
* @param callback
|
|
424
421
|
*/
|
|
425
|
-
onCallback(s,
|
|
426
|
-
r[s] =
|
|
427
|
-
},
|
|
428
|
-
/**
|
|
429
|
-
* existing callback is internal method to pass calbacks added after create in new connection
|
|
430
|
-
*/
|
|
431
|
-
getCallbacks() {
|
|
432
|
-
return r;
|
|
422
|
+
onCallback(s, w) {
|
|
423
|
+
r[s] = w;
|
|
433
424
|
}
|
|
434
425
|
};
|
|
435
426
|
}
|
|
@@ -442,8 +433,8 @@ export {
|
|
|
442
433
|
W as Subject,
|
|
443
434
|
N as VoiceAccess,
|
|
444
435
|
O as createAgentManager,
|
|
445
|
-
|
|
446
|
-
|
|
436
|
+
T as createAgentsApi,
|
|
437
|
+
$ as createClient,
|
|
447
438
|
Z as createKnowledgeApi,
|
|
448
439
|
Y as createStreamingManager,
|
|
449
440
|
D as getAgentStreamArgs
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(l,w){typeof exports=="object"&&typeof module<"u"?w(exports):typeof define=="function"&&define.amd?define(["exports"],w):(l=typeof globalThis<"u"?globalThis:l||self,w(l.index={}))})(this,function(l){"use strict";const w="https://api.d-id.com",W="wss://notifications.d-id.com";function y(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 h(e,i=w){const a=async(t,n)=>{const r=await fetch(i+(t!=null&&t.startsWith("/")?t:`/${t}`),{...n,headers:{...n==null?void 0:n.headers,Authorization:y(e),"Content-Type":"application/json"}});if(!r.ok){let c=await r.text().catch(()=>"Failed to fetch");throw new Error(c)}return r.json()};return{get(t,n){return a(t,{...n,method:"GET"})},post(t,n,r){return a(t,{...r,body:JSON.stringify(n),method:"POST"})},delete(t,n,r){return a(t,{...r,body:JSON.stringify(n),method:"DELETE"})},patch(t,n,r){return a(t,{...r,body:JSON.stringify(n),method:"PATCH"})}}}function M(e,i=w){const a=h(e,`${i}/agents`);return{create(t,n){return a.post("/",t,n)},getAgents(t,n){return a.get(`/${t?`?tag=${t}`:""}`,n).then(r=>r??[])},getById(t,n){return a.get(`/${t}`,n)},delete(t,n){return a.delete(`/${t}`,void 0,n)},update(t,n,r){return a.patch(`/${t}`,n,r)},newChat(t,n){return a.post(`/${t}/chat`,void 0,n)},chat(t,n,r,c){return a.post(`/${t}/chat/${n}`,r,c)}}}function V(e,i=w){const a=h(e,`${i}/knowledge`);return{createKnowledge(t,n){return a.post("/",t,n)},getKnowledgeBase(t){return a.get("/",t)},getKnowledge(t,n){return a.get(`/${t}`,n)},deleteKnowledge(t,n){return a.delete(`/${t}`,void 0,n)},createDocument(t,n,r){return a.post(`/${t}/documents`,n,r)},deleteDocument(t,n,r){return a.delete(`/${t}/documents/${n}`,void 0,r)},getDocuments(t,n){return a.get(`/${t}/documents`,n)},getDocument(t,n,r){return a.get(`/${t}/documents/${n}`,r)},getRecords(t,n,r){return a.get(`/${t}/documents/${n}/records`,r)},query(t,n,r){return a.post(`/${t}/query`,{query:n},r)}}}const x=e=>new Promise(i=>setTimeout(i,e));function D(e){return new Promise((i,a)=>{const{callbacks:t,host:n,auth:r}=e,{onMessage:c=null,onOpen:m=null,onClose:p=null,onError:u=null}=t||{},o=new WebSocket(`${n}?authorization=${y(r)}`);o.onmessage=c,o.onclose=p,o.onerror=d=>{console.log(d),u==null||u(d),a(d)},o.onopen=d=>{m==null||m(d),i(o)}})}async function F(e){const{retries:i=1}=e;let a=null;for(let t=0;(a==null?void 0:a.readyState)!==WebSocket.OPEN;t++)try{a=await D(e)}catch(n){if(t===i)throw n;await x(t*500)}return a}async function P(e,i=W){const a=[],t=await F({auth:e,host:i,callbacks:{onMessage:n=>{a.forEach(r=>r(n))}}});return{socket:t,terminate:()=>t.close(),subscribeToEvents:n=>a.push(n)}}var I=(e=>(e.Amazon="amazon",e.Microsoft="microsoft",e.Afflorithmics="afflorithmics",e.Elevenlabs="elevenlabs",e))(I||{}),K=(e=>(e.Public="public",e.Premium="premium",e.Private="private",e))(K||{}),v=(e=>(e.Start="START",e.Stop="STOP",e))(v||{}),A=(e=>(e.ChatAnswer="chat/answer",e.ChatPartial="chat/partial",e.StreamDone="stream/done",e.StreamStarted="stream/started",e))(A||{}),R=(e=>(e.Unrated="Unrated",e.Positive="Positive",e.Negative="Negative",e))(R||{}),E=(e=>(e.KnowledgeProcessing="knowledge/processing",e.KnowledgeIndexing="knowledge/indexing",e.KnowledgeFailed="knowledge/error",e.KnowledgeDone="knowledge/done",e))(E||{}),T=(e=>(e.Knowledge="knowledge",e.Document="document",e.Record="record",e))(T||{}),b=(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))(b||{}),$=(e=>(e.Clip="clip",e.Talk="talk",e))($||{});function H(e,i=w){const a=h(e,`${i}/chats/ratings`);return{create(t,n){return a.post("/",t,n)},getByKnowledge(t,n){return a.get(`/${t}`,n).then(r=>r??[])},update(t,n,r){return a.patch(`/${t}`,n,r)},delete(t,n){return a.delete(`/${t}`,n)}}}function z(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 U(e,i,a,t){return new Promise(async(n,r)=>{const c=await B(z(e),{...i,callbacks:{...i.callbacks,onConnectionStateChange:async m=>{var p,u;m==="connected"?(t||(t=await a.newChat(e.id)),n({chat:t,streamingManager:c})):m==="failed"&&r(new Error("Cannot create connection")),(u=(p=i.callbacks).onConnectionStateChange)==null||u.call(p,m)}}})})}async function G(e,i){const a=i.baseURL||w,t=new AbortController,n=M(i.auth,a),r=H(i.auth,a),c=await n.getById(e),m=await P(i.auth);let{chat:p,streamingManager:u}=await U(c,i,n);return{agent:c,async reconnectToChat(){const{streamingManager:o}=await U(c,i,n,p);u=o},terminate(){return t.abort(),m.terminate(),u.terminate()},chatId:p.id,chat(o){return n.chat(e,p.id,{sessionId:u.sessionId,streamId:u.streamId,messages:o},{signal:t.signal})},rate(o,d){return d?r.update(d,o):r.create(o)},speak(o){if(!c)throw new Error("Agent not initializated");let d;return o.type==="text"?d={script:{type:"text",provider:o.provider,input:o.input,ssml:o.ssml||!1}}:o.type==="audio"&&(d={script:{type:"audio",audio_url:o.audio_url}}),u.speak(d)},onChatEvents(o){m.subscribeToEvents(o)},onConnectionEvents(o){u.onCallback("onConnectionStateChange",o)},onVideoEvents(o){u.onCallback("onVideoStateChange",o)}}}function Q(e,i){const a=h(e,i);return{createStream(t){return a.post("/clips/streams",{driver_id:t.driver_id,presenter_id:t.presenter_id,compatibility_mode:t.compatibility_mode})},startConnection(t,n,r){return a.post(`/clips/streams/${t}/sdp`,{session_id:r,answer:n})},addIceCandidate(t,n,r){return a.post(`/clips/streams/${t}/ice`,{session_id:r,...n})},sendStreamRequest(t,n,r){return a.post(`/clips/streams/${t}`,{session_id:n,...r})},close(t,n){return a.delete(`/clips/streams/${t}`,{session_id:n})}}}function X(e,i){const a=h(e,i);return{createStream(t,n){return a.post("/talks/streams",{source_url:t.source_url,driver_url:t.driver_url,face:t.face,config:t.config},n)},startConnection(t,n,r,c){return a.post(`/talks/streams/${t}/sdp`,{session_id:r,answer:n},c)},addIceCandidate(t,n,r,c){return a.post(`/talks/streams/${t}/ice`,{session_id:r,...n},c)},sendStreamRequest(t,n,r,c){return a.post(`/talks/streams/${t}`,{session_id:n,...r},c)},close(t,n,r){return a.delete(`/talks/streams/${t}`,{session_id:n},r)}}}let q=!1;const C=(e,i)=>q&&console.log(e,i),Y=(window.RTCPeerConnection||window.webkitRTCPeerConnection||window.mozRTCPeerConnection).bind(window);async function B(e,{debug:i=!1,callbacks:a,auth:t,baseURL:n=w}){q=i;const r={...a},{startConnection:c,sendStreamRequest:m,close:p,createStream:u,addIceCandidate:o}=e.videoType===$.Clip?Q(t,n):X(t,n),{id:d,offer:Z,ice_servers:O,session_id:S}=await u(e),g=new Y({iceServers:O}),L=g.createDataChannel("JanusDataChannel");if(!S)throw new Error("Could not create session_id");g.onicecandidate=s=>{C("peerConnection.onicecandidate",s),s.candidate&&s.candidate.sdpMid&&s.candidate.sdpMLineIndex!==null&&o(d,{candidate:s.candidate.candidate,sdpMid:s.candidate.sdpMid,sdpMLineIndex:s.candidate.sdpMLineIndex},S)},g.oniceconnectionstatechange=()=>{var s;C("peerConnection.oniceconnectionstatechange => "+g.iceConnectionState),(s=r.onConnectionStateChange)==null||s.call(r,g.iceConnectionState)},g.ontrack=s=>{var f;C("peerConnection.ontrack",s),(f=r.onSrcObjectReady)==null||f.call(r,s.streams[0])},L.onmessage=s=>{var f,_,J;if(L.readyState==="open"){const[k,j]=s.data.split(":");k===A.StreamDone?(f=r.onVideoStateChange)==null||f.call(r,v.Stop):k===A.StreamStarted?(_=r.onVideoStateChange)==null||_.call(r,v.Start):(J=r.onMessage)==null||J.call(r,k,decodeURIComponent(j))}},await g.setRemoteDescription(Z),C("set remote description OK");const N=await g.createAnswer();return C("create answer OK"),await g.setLocalDescription(N),C("set local description OK"),await c(d,N,S),C("start connection OK"),{speak(s){return m(d,S,s)},async terminate(){var s,f;d&&(g&&(g.close(),g.oniceconnectionstatechange=null,g.onnegotiationneeded=null,g.onicecandidate=null,g.ontrack=null),await p(d,S).catch(_=>{}),(s=r.onConnectionStateChange)==null||s.call(r,"closed"),(f=r.onVideoStateChange)==null||f.call(r,v.Stop))},sessionId:S,streamId:d,onCallback(s,f){r[s]=f}}}l.DocumentType=b,l.KnowledgeType=T,l.Providers=I,l.RateState=R,l.SocketManager=P,l.Subject=E,l.VoiceAccess=K,l.createAgentManager=G,l.createAgentsApi=M,l.createClient=h,l.createKnowledgeApi=V,l.createStreamingManager=B,l.getAgentStreamArgs=z,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Agent, AgentPayload, Auth, Chat, ChatPayload, ChatResponse } from '
|
|
1
|
+
import { Agent, AgentPayload, Auth, Chat, ChatPayload, ChatResponse } from '../../types/index';
|
|
2
2
|
export declare function createAgentsApi(auth: Auth, host?: string): {
|
|
3
3
|
create(payload: AgentPayload, options?: RequestInit): Promise<Agent>;
|
|
4
4
|
getAgents(tag?: string, options?: RequestInit): Promise<Agent[]>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Auth, RtcApi } from '
|
|
1
|
+
import { Auth, RtcApi } from '../../types/index';
|
|
2
2
|
export declare function createApi(auth: Auth, host: string): RtcApi;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Auth } from '
|
|
1
|
+
import { Auth } from '../../types/auth';
|
|
2
2
|
export declare function createClient(auth: Auth, host?: string): {
|
|
3
3
|
get<T = any>(url: string, options?: RequestInit): Promise<T>;
|
|
4
4
|
post<T_1 = any>(url: string, body?: any, options?: RequestInit): Promise<T_1>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Auth, CreateDocumentPayload, DocumentData, KnowledgeData, KnowledgePayload, QueryResult, RecordData } from '
|
|
1
|
+
import { Auth, CreateDocumentPayload, DocumentData, KnowledgeData, KnowledgePayload, QueryResult, RecordData } from '../../types/index';
|
|
2
2
|
export declare function createKnowledgeApi(auth: Auth, host?: string): {
|
|
3
3
|
createKnowledge(payload: KnowledgePayload, options?: RequestInit): Promise<KnowledgeData>;
|
|
4
4
|
getKnowledgeBase(options?: RequestInit): Promise<KnowledgeData[]>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Auth, RtcApi } from '
|
|
1
|
+
import { Auth, RtcApi } from '../../types/index';
|
|
2
2
|
export declare function createApi(auth: Auth, host: string): RtcApi;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Auth } from '
|
|
1
|
+
import { Auth } from '../../types/auth';
|
|
2
2
|
export declare function getAuthHeader(auth: Auth): string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Agent, AgentManagerOptions, AgentsManagerAPI, CreateStreamOptions } from '
|
|
1
|
+
import { Agent, AgentManagerOptions, AgentsManagerAPI, CreateStreamOptions } from '../types/index';
|
|
2
2
|
export declare function getAgentStreamArgs(agent: Agent): CreateStreamOptions;
|
|
3
3
|
/**
|
|
4
4
|
* Creates a new Agent Manager instance for interacting with an agent, chat, and related connections.
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { CreateStreamOptions, ManagerCallbacks, PayloadType, StreamingManagerOptions } from '
|
|
1
|
+
import { CreateStreamOptions, ManagerCallbacks, PayloadType, StreamingManagerOptions } from '../types/index';
|
|
2
2
|
export declare function createStreamingManager<T extends CreateStreamOptions>(agent: T, { debug, callbacks, auth, baseURL }: StreamingManagerOptions): Promise<{
|
|
3
3
|
/**
|
|
4
4
|
* Method to send request to server to get clip or talk depend on you payload
|
|
5
5
|
* @param payload
|
|
6
6
|
*/
|
|
7
|
-
speak(payload: PayloadType<T>): Promise<import('
|
|
7
|
+
speak(payload: PayloadType<T>): Promise<import('../types/index').SendStreamPayloadResponse>;
|
|
8
8
|
/**
|
|
9
9
|
* Method to close RTC connection
|
|
10
10
|
*/
|
|
@@ -23,9 +23,5 @@ export declare function createStreamingManager<T extends CreateStreamOptions>(ag
|
|
|
23
23
|
* @param callback
|
|
24
24
|
*/
|
|
25
25
|
onCallback<T_1 extends keyof ManagerCallbacks>(eventName: T_1, callback: ManagerCallbacks[T_1]): void;
|
|
26
|
-
/**
|
|
27
|
-
* existing callback is internal method to pass calbacks added after create in new connection
|
|
28
|
-
*/
|
|
29
|
-
getCallbacks(): ManagerCallbacks;
|
|
30
26
|
}>;
|
|
31
27
|
export type StreamingManager<T extends CreateStreamOptions> = Awaited<ReturnType<typeof createStreamingManager<T>>>;
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
export declare const
|
|
2
|
-
export declare const
|
|
1
|
+
export declare const nodeEnv: string;
|
|
2
|
+
export declare const didApiUrl: string;
|
|
3
|
+
export declare const didSocketApiUrl: string;
|
|
4
|
+
export declare const mixpanelKey: string;
|
|
5
|
+
export declare const clientKey: string;
|
|
6
|
+
export declare const agentId: string;
|
|
7
|
+
export declare const externalId = "temp";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SupportedStreamScipt } from '
|
|
1
|
+
import { SupportedStreamScipt } from '../../../types/StreamScript';
|
|
2
2
|
import { Auth } from '../../auth';
|
|
3
3
|
import { SendStreamPayloadResponse, StreamingState } from '../../stream';
|
|
4
4
|
import { Agent } from './agent';
|
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.18-beta.
|
|
4
|
+
"version": "1.0.18-beta.7",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "d-id client sdk",
|
|
7
7
|
"repository": {
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
],
|
|
21
21
|
"main": "./dist/index.umd.cjs",
|
|
22
22
|
"module": "./dist/index.js",
|
|
23
|
-
"types": "./dist/types/index.d.ts",
|
|
23
|
+
"types": "./dist/src/types/index.d.ts",
|
|
24
24
|
"scripts": {
|
|
25
25
|
"dev": "vite",
|
|
26
26
|
"build": "node ./infra/build.js -m production",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|