@d-id/client-sdk 1.0.7 → 1.0.9
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.
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { StreamTextToSpeechProviders } from '../../tts';
|
|
2
|
+
import { Knowledge } from './knowledge';
|
|
2
3
|
import { LLM } from './llm';
|
|
3
4
|
import { Presenter } from './presenter';
|
|
4
5
|
export interface Agent {
|
|
5
6
|
id: string;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
use_case?: string;
|
|
9
|
-
created_at: string;
|
|
10
|
-
modified_at: string;
|
|
11
|
-
knowledge_id: string;
|
|
12
|
-
voice_provider: ExtendedTextToSpeechProviders;
|
|
7
|
+
username?: string;
|
|
8
|
+
presenter: Presenter;
|
|
13
9
|
llm?: LLM;
|
|
14
|
-
|
|
10
|
+
knowledge?: Knowledge;
|
|
11
|
+
use_case?: string;
|
|
12
|
+
tags?: string[];
|
|
15
13
|
access?: 'private' | 'pending-public' | 'unlisted' | 'rejected' | 'public';
|
|
14
|
+
preview_name?: string;
|
|
16
15
|
preview_description?: string;
|
|
17
16
|
preview_thumbnail?: string;
|
|
18
|
-
preview_name: string;
|
|
19
17
|
}
|
|
20
18
|
export type AgentPayload = Omit<Agent, 'type' | 'created_at' | 'modified_at' | 'id' | 'owner_id' | 'idle_video_url'>;
|
|
21
19
|
export interface IChatPayload {
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
function k(r) {
|
|
2
2
|
return r.type === "bearer" ? "Bearer " + r.token : r.type === "basic" ? "Basic " + btoa(`${r.username}:${r.password}`) : "Client-Key " + r.clientKey;
|
|
3
3
|
}
|
|
4
|
-
function
|
|
4
|
+
function g(r, o = "https://api.d-id.com") {
|
|
5
5
|
const n = async (e, t) => {
|
|
6
6
|
const s = await fetch(o + (e != null && e.startsWith("/") ? e : `/${e}`), {
|
|
7
7
|
...t,
|
|
@@ -12,12 +12,13 @@ function m(r, o = "https://api.d-id.com") {
|
|
|
12
12
|
}
|
|
13
13
|
});
|
|
14
14
|
if (!s.ok) {
|
|
15
|
-
let
|
|
15
|
+
let u = await s.text().catch(() => "Failed to fetch");
|
|
16
16
|
try {
|
|
17
|
-
c = JSON.parse(
|
|
17
|
+
const c = JSON.parse(u);
|
|
18
|
+
c.description ? u = c.description : c.message && (u = c.message);
|
|
18
19
|
} catch {
|
|
19
20
|
}
|
|
20
|
-
throw new Error(
|
|
21
|
+
throw new Error(u);
|
|
21
22
|
}
|
|
22
23
|
return s.json();
|
|
23
24
|
};
|
|
@@ -52,7 +53,7 @@ function m(r, o = "https://api.d-id.com") {
|
|
|
52
53
|
};
|
|
53
54
|
}
|
|
54
55
|
function K(r, o = "https://api.d-id.com") {
|
|
55
|
-
const n =
|
|
56
|
+
const n = g(r, `${o}/knowledge`);
|
|
56
57
|
return {
|
|
57
58
|
createKnowledge(e) {
|
|
58
59
|
return n.post("/", e);
|
|
@@ -89,7 +90,7 @@ function K(r, o = "https://api.d-id.com") {
|
|
|
89
90
|
};
|
|
90
91
|
}
|
|
91
92
|
function O(r, o = "https://api.d-id.com") {
|
|
92
|
-
const n =
|
|
93
|
+
const n = g(r, `${o}/agents`);
|
|
93
94
|
return {
|
|
94
95
|
create(e) {
|
|
95
96
|
return n.post("/", e);
|
|
@@ -112,7 +113,7 @@ function O(r, o = "https://api.d-id.com") {
|
|
|
112
113
|
};
|
|
113
114
|
}
|
|
114
115
|
function A(r, o) {
|
|
115
|
-
const n =
|
|
116
|
+
const n = g(r, o);
|
|
116
117
|
return {
|
|
117
118
|
createStream(e) {
|
|
118
119
|
return n.post("/clips/streams", {
|
|
@@ -147,7 +148,7 @@ function A(r, o) {
|
|
|
147
148
|
};
|
|
148
149
|
}
|
|
149
150
|
function T(r, o) {
|
|
150
|
-
const n =
|
|
151
|
+
const n = g(r, o);
|
|
151
152
|
return {
|
|
152
153
|
createStream(e) {
|
|
153
154
|
return n.post("/talks/streams", {
|
|
@@ -182,10 +183,10 @@ function T(r, o) {
|
|
|
182
183
|
}
|
|
183
184
|
};
|
|
184
185
|
}
|
|
185
|
-
var
|
|
186
|
+
var m = /* @__PURE__ */ ((r) => (r.Idle = "IDLE", r.Streaming = "STREAMING", r))(m || {}), w = /* @__PURE__ */ ((r) => (r.Clip = "clip", r.Talk = "talk", r))(w || {});
|
|
186
187
|
let $ = !1;
|
|
187
188
|
const d = (r, o) => $ && console.log(r, o), D = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
|
|
188
|
-
async function
|
|
189
|
+
async function E(r, {
|
|
189
190
|
debug: o = !1,
|
|
190
191
|
callbacks: n,
|
|
191
192
|
auth: e,
|
|
@@ -194,49 +195,49 @@ async function R(r, {
|
|
|
194
195
|
$ = o;
|
|
195
196
|
let s = null;
|
|
196
197
|
const {
|
|
197
|
-
startConnection:
|
|
198
|
-
sendStreamRequest:
|
|
198
|
+
startConnection: u,
|
|
199
|
+
sendStreamRequest: c,
|
|
199
200
|
close: h,
|
|
200
201
|
createStream: S,
|
|
201
202
|
addIceCandidate: _
|
|
202
|
-
} = r.videoType ===
|
|
203
|
-
id:
|
|
203
|
+
} = r.videoType === w.Clip ? A(e, t) : T(e, t), {
|
|
204
|
+
id: l,
|
|
204
205
|
offer: y,
|
|
205
206
|
ice_servers: I,
|
|
206
|
-
session_id:
|
|
207
|
+
session_id: p
|
|
207
208
|
} = await S(r), a = new D({
|
|
208
209
|
iceServers: I
|
|
209
210
|
}), C = a.createDataChannel("JanusDataChannel");
|
|
210
|
-
if (!
|
|
211
|
+
if (!p)
|
|
211
212
|
throw new Error("Could not create session_id");
|
|
212
213
|
a.onicecandidate = (i) => {
|
|
213
|
-
d("peerConnection.onicecandidate", i), i.candidate && i.candidate.sdpMid && i.candidate.sdpMLineIndex !== null && _(
|
|
214
|
+
d("peerConnection.onicecandidate", i), i.candidate && i.candidate.sdpMid && i.candidate.sdpMLineIndex !== null && _(l, {
|
|
214
215
|
candidate: i.candidate.candidate,
|
|
215
216
|
sdpMid: i.candidate.sdpMid,
|
|
216
217
|
sdpMLineIndex: i.candidate.sdpMLineIndex
|
|
217
|
-
},
|
|
218
|
+
}, p);
|
|
218
219
|
}, a.oniceconnectionstatechange = () => {
|
|
219
220
|
d("peerConnection.oniceconnectionstatechange => " + a.iceConnectionState), n.onConnectionStateChange(a.iceConnectionState);
|
|
220
221
|
}, a.ontrack = (i) => {
|
|
221
222
|
d("peerConnection.ontrack", i), s = i.streams[0], n.onSrcObjectReady(s);
|
|
222
223
|
}, C.onmessage = (i) => {
|
|
223
|
-
C.readyState === "open" && n.onStreamingStateChange(i.data === "stream/done" ?
|
|
224
|
+
C.readyState === "open" && n.onStreamingStateChange(i.data === "stream/done" ? m.Idle : m.Streaming);
|
|
224
225
|
}, await a.setRemoteDescription(y), d("set remote description OK");
|
|
225
|
-
const
|
|
226
|
-
return d("create answer OK"), await a.setLocalDescription(
|
|
226
|
+
const f = await a.createAnswer();
|
|
227
|
+
return d("create answer OK"), await a.setLocalDescription(f), d("set local description OK"), await u(l, f, p), d("start connection OK"), {
|
|
227
228
|
speak(i) {
|
|
228
|
-
return
|
|
229
|
+
return c(l, p, i);
|
|
229
230
|
},
|
|
230
231
|
async terminate() {
|
|
231
|
-
|
|
232
|
+
l && (s && (s.getTracks().forEach((i) => i.stop()), s = null), a && (a.close(), a.oniceconnectionstatechange = null, a.onnegotiationneeded = null, a.onicecandidate = null, a.ontrack = null), await h(l, p), n.onConnectionStateChange("closed"), n.onStreamingStateChange(m.Idle));
|
|
232
233
|
},
|
|
233
|
-
sessionId:
|
|
234
|
-
streamId:
|
|
234
|
+
sessionId: p,
|
|
235
|
+
streamId: l
|
|
235
236
|
};
|
|
236
237
|
}
|
|
237
238
|
export {
|
|
238
239
|
O as createAgentsApi,
|
|
239
|
-
|
|
240
|
+
g as createClient,
|
|
240
241
|
K as createKnowledgeApi,
|
|
241
|
-
|
|
242
|
+
E as createStreamingManager
|
|
242
243
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(c,
|
|
1
|
+
(function(c,g){typeof exports=="object"&&typeof module<"u"?g(exports):typeof define=="function"&&define.amd?define(["exports"],g):(c=typeof globalThis<"u"?globalThis:c||self,g(c.index={}))})(this,function(c){"use strict";function g(r){return r.type==="bearer"?"Bearer "+r.token:r.type==="basic"?"Basic "+btoa(`${r.username}:${r.password}`):"Client-Key "+r.clientKey}function f(r,a="https://api.d-id.com"){const n=async(e,t)=>{const i=await fetch(a+(e!=null&&e.startsWith("/")?e:`/${e}`),{...t,headers:{...t==null?void 0:t.headers,Authorization:g(r),"Content-Type":"application/json"}});if(!i.ok){let l=await i.text().catch(()=>"Failed to fetch");try{const u=JSON.parse(l);u.description?l=u.description:u.message&&(l=u.message)}catch{}throw new Error(l)}return i.json()};return{get(e,t){return n(e,{...t,method:"GET"})},post(e,t,i){return n(e,{...i,body:JSON.stringify(t),method:"POST"})},delete(e,t,i){return n(e,{...i,body:JSON.stringify(t),method:"DELETE"})},patch(e,t,i){return n(e,{...i,body:JSON.stringify(t),method:"PATCH"})}}}function y(r,a="https://api.d-id.com"){const n=f(r,`${a}/knowledge`);return{createKnowledge(e){return n.post("/",e)},getKnowledgeBase(){return n.get("/")},getKnowledge(e){return n.get(`/${e}`)},deleteKnowledge(e){return n.delete(`/${e}`)},createDocument(e,t){return n.post(`/${e}/documents`,t)},deleteDocument(e,t){return n.delete(`/${e}/documents/${t}`)},getDocuments(e){return n.get(`/${e}/documents`)},getDocument(e,t){return n.get(`/${e}/documents/${t}`)},getRecords(e,t){return n.get(`/${e}/documents/${t}/records`)},query(e,t){return n.post(`/${e}/query`,{query:t})}}}function _(r,a="https://api.d-id.com"){const n=f(r,`${a}/agents`);return{create(e){return n.post("/",e)},getAgents(e){return n.get(`/${e?`?tag=${e}`:""}`)},getById(e){return n.get(`/${e}`)},delete(e){return n.delete(`/${e}`)},update(e,t){return n.patch(`/${e}`,t)},chat(e,t){return n.post(`/${e}/chat`,t)}}}function A(r,a){const n=f(r,a);return{createStream(e){return n.post("/clips/streams",{driver_id:e.driver_id,presenter_id:e.presenter_id,compatibility_mode:e.compatibility_mode})},startConnection(e,t,i){return n.post(`/clips/streams/${e}/sdp`,{session_id:i,answer:t})},addIceCandidate(e,t,i){return n.post(`/clips/streams/${e}/ice`,{session_id:i,...t})},sendStreamRequest(e,t,i){return n.post(`/clips/streams/${e}`,{session_id:t,...i})},close(e,t){return n.delete(`/clips/streams/${e}`,{session_id:t})}}}function I(r,a){const n=f(r,a);return{createStream(e){return n.post("/talks/streams",{source_url:e.source_url,driver_url:e.driver_url,face:e.face,config:e.config})},startConnection(e,t,i){return n.post(`/talks/streams/${e}/sdp`,{session_id:i,answer:t})},addIceCandidate(e,t,i){return n.post(`/talks/streams/${e}/ice`,{session_id:i,...t})},sendStreamRequest(e,t,i){return n.post(`/talks/streams/${e}`,{session_id:t,...i})},close(e,t){return n.delete(`/talks/streams/${e}`,{session_id:t})}}}var C=(r=>(r.Idle="IDLE",r.Streaming="STREAMING",r))(C||{}),w=(r=>(r.Clip="clip",r.Talk="talk",r))(w||{});let h=!1;const d=(r,a)=>h&&console.log(r,a),T=(window.RTCPeerConnection||window.webkitRTCPeerConnection||window.mozRTCPeerConnection).bind(window);async function k(r,{debug:a=!1,callbacks:n,auth:e,baseURL:t="https://api.d-id.com"}){h=a;let i=null;const{startConnection:l,sendStreamRequest:u,close:K,createStream:O,addIceCandidate:b}=r.videoType===w.Clip?A(e,t):I(e,t),{id:p,offer:D,ice_servers:E,session_id:m}=await O(r),o=new T({iceServers:E}),$=o.createDataChannel("JanusDataChannel");if(!m)throw new Error("Could not create session_id");o.onicecandidate=s=>{d("peerConnection.onicecandidate",s),s.candidate&&s.candidate.sdpMid&&s.candidate.sdpMLineIndex!==null&&b(p,{candidate:s.candidate.candidate,sdpMid:s.candidate.sdpMid,sdpMLineIndex:s.candidate.sdpMLineIndex},m)},o.oniceconnectionstatechange=()=>{d("peerConnection.oniceconnectionstatechange => "+o.iceConnectionState),n.onConnectionStateChange(o.iceConnectionState)},o.ontrack=s=>{d("peerConnection.ontrack",s),i=s.streams[0],n.onSrcObjectReady(i)},$.onmessage=s=>{$.readyState==="open"&&n.onStreamingStateChange(s.data==="stream/done"?C.Idle:C.Streaming)},await o.setRemoteDescription(D),d("set remote description OK");const S=await o.createAnswer();return d("create answer OK"),await o.setLocalDescription(S),d("set local description OK"),await l(p,S,m),d("start connection OK"),{speak(s){return u(p,m,s)},async terminate(){p&&(i&&(i.getTracks().forEach(s=>s.stop()),i=null),o&&(o.close(),o.oniceconnectionstatechange=null,o.onnegotiationneeded=null,o.onicecandidate=null,o.ontrack=null),await K(p,m),n.onConnectionStateChange("closed"),n.onStreamingStateChange(C.Idle))},sessionId:m,streamId:p}}c.createAgentsApi=_,c.createClient=f,c.createKnowledgeApi=y,c.createStreamingManager=k,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
|