@d-id/client-sdk 1.0.2 → 1.0.3

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 CHANGED
@@ -1,18 +1,24 @@
1
- function T(r) {
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 p(r, o = "https://api.d-id.com") {
4
+ function m(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,
8
8
  headers: {
9
9
  ...t == null ? void 0 : t.headers,
10
- Authorization: T(r),
10
+ Authorization: k(r),
11
11
  "Content-Type": "application/json"
12
12
  }
13
13
  });
14
- if (!s.ok)
15
- throw new Error(s.statusText);
14
+ if (!s.ok) {
15
+ let c = await s.text().catch(() => "Failed to fetch");
16
+ try {
17
+ c = JSON.parse(c), c.description && (c = c.description);
18
+ } catch {
19
+ }
20
+ throw new Error(c);
21
+ }
16
22
  return s.json();
17
23
  };
18
24
  return {
@@ -46,7 +52,7 @@ function p(r, o = "https://api.d-id.com") {
46
52
  };
47
53
  }
48
54
  function K(r, o = "https://api.d-id.com") {
49
- const n = p(r, `${o}/knowledge`);
55
+ const n = m(r, `${o}/knowledge`);
50
56
  return {
51
57
  createKnowledge(e) {
52
58
  return n.post("/", e);
@@ -83,7 +89,7 @@ function K(r, o = "https://api.d-id.com") {
83
89
  };
84
90
  }
85
91
  function O(r, o = "https://api.d-id.com") {
86
- const n = p(r, `${o}/agents`);
92
+ const n = m(r, `${o}/agents`);
87
93
  return {
88
94
  create(e) {
89
95
  return n.post("/", e);
@@ -102,8 +108,9 @@ function O(r, o = "https://api.d-id.com") {
102
108
  }
103
109
  };
104
110
  }
105
- function k(r, o) {
106
- const n = p(r, o);
111
+ var p = /* @__PURE__ */ ((r) => (r.Idle = "IDLE", r.Streaming = "STREAMING", r))(p || {}), f = /* @__PURE__ */ ((r) => (r.Clip = "clip", r.Talk = "talk", r))(f || {});
112
+ function A(r, o) {
113
+ const n = m(r, o);
107
114
  return {
108
115
  createStream(e) {
109
116
  return n.post("/clips/streams", {
@@ -137,8 +144,8 @@ function k(r, o) {
137
144
  }
138
145
  };
139
146
  }
140
- function A(r, o) {
141
- const n = p(r, o);
147
+ function T(r, o) {
148
+ const n = m(r, o);
142
149
  return {
143
150
  createStream(e) {
144
151
  return n.post("/talks/streams", {
@@ -173,61 +180,60 @@ function A(r, o) {
173
180
  }
174
181
  };
175
182
  }
176
- var l = /* @__PURE__ */ ((r) => (r.Idle = "IDLE", r.Streaming = "STREAMING", r))(l || {}), C = /* @__PURE__ */ ((r) => (r.Clip = "clip", r.Talk = "talk", r))(C || {});
177
- let w = !1;
178
- const c = (r, o) => w && console.log(r, o), D = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
183
+ let $ = !1;
184
+ const d = (r, o) => $ && console.log(r, o), D = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
179
185
  async function R(r, {
180
186
  debug: o = !1,
181
187
  callbacks: n,
182
188
  auth: e,
183
189
  baseURL: t = "https://api.d-id.com"
184
190
  }) {
185
- w = o;
191
+ $ = o;
186
192
  let s = null;
187
193
  const {
188
- startConnection: $,
189
- sendStreamRequest: f,
190
- close: S,
191
- createStream: h,
194
+ startConnection: c,
195
+ sendStreamRequest: g,
196
+ close: h,
197
+ createStream: S,
192
198
  addIceCandidate: _
193
- } = r.videoType === C.Clip ? k(e, t) : A(e, t), {
194
- id: d,
199
+ } = r.videoType === f.Clip ? A(e, t) : T(e, t), {
200
+ id: u,
195
201
  offer: y,
196
202
  ice_servers: I,
197
- session_id: u
198
- } = await h(r), a = new D({
203
+ session_id: l
204
+ } = await S(r), a = new D({
199
205
  iceServers: I
200
- }), m = a.createDataChannel("JanusDataChannel");
201
- if (!u)
206
+ }), C = a.createDataChannel("JanusDataChannel");
207
+ if (!l)
202
208
  throw new Error("Could not create session_id");
203
209
  a.onicecandidate = (i) => {
204
- c("peerConnection.onicecandidate", i), i.candidate && i.candidate.sdpMid && i.candidate.sdpMLineIndex !== null && _(d, {
210
+ d("peerConnection.onicecandidate", i), i.candidate && i.candidate.sdpMid && i.candidate.sdpMLineIndex !== null && _(u, {
205
211
  candidate: i.candidate.candidate,
206
212
  sdpMid: i.candidate.sdpMid,
207
213
  sdpMLineIndex: i.candidate.sdpMLineIndex
208
- }, u);
214
+ }, l);
209
215
  }, a.oniceconnectionstatechange = () => {
210
- c("peerConnection.oniceconnectionstatechange => " + a.iceConnectionState), n.onConnectionStateChange(a.iceConnectionState);
216
+ d("peerConnection.oniceconnectionstatechange => " + a.iceConnectionState), n.onConnectionStateChange(a.iceConnectionState);
211
217
  }, a.ontrack = (i) => {
212
- c("peerConnection.ontrack", i), s = i.streams[0], n.onSrcObjectReady(s);
213
- }, m.onmessage = (i) => {
214
- m.readyState === "open" && n.onStreamingStateChange(i.data === "stream/done" ? l.Idle : l.Streaming);
215
- }, await a.setRemoteDescription(y), c("set remote description OK");
216
- const g = await a.createAnswer();
217
- return c("create answer OK"), await a.setLocalDescription(g), c("set local description OK"), await $(d, g, u), c("start connection OK"), {
218
+ d("peerConnection.ontrack", i), s = i.streams[0], n.onSrcObjectReady(s);
219
+ }, C.onmessage = (i) => {
220
+ C.readyState === "open" && n.onStreamingStateChange(i.data === "stream/done" ? p.Idle : p.Streaming);
221
+ }, await a.setRemoteDescription(y), d("set remote description OK");
222
+ const w = await a.createAnswer();
223
+ return d("create answer OK"), await a.setLocalDescription(w), d("set local description OK"), await c(u, w, l), d("start connection OK"), {
218
224
  speak(i) {
219
- return f(d, u, i);
225
+ return g(u, l, i);
220
226
  },
221
227
  async terminate() {
222
- d && (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 S(d, u), n.onConnectionStateChange("closed"), n.onStreamingStateChange(l.Idle));
228
+ u && (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(u, l), n.onConnectionStateChange("closed"), n.onStreamingStateChange(p.Idle));
223
229
  },
224
- sessionId: u,
225
- streamId: d
230
+ sessionId: l,
231
+ streamId: u
226
232
  };
227
233
  }
228
234
  export {
229
235
  O as createAgentsApi,
230
- p as createClient,
236
+ m as createClient,
231
237
  K as createKnowledgeApi,
232
238
  R as createStreamingManager
233
239
  };
@@ -1 +1 @@
1
- (function(c,p){typeof exports=="object"&&typeof module<"u"?p(exports):typeof define=="function"&&define.amd?define(["exports"],p):(c=typeof globalThis<"u"?globalThis:c||self,p(c.index={}))})(this,function(c){"use strict";function p(r){return r.type==="bearer"?"Bearer "+r.token:r.type==="basic"?"Basic "+btoa(`${r.username}:${r.password}`):"Client-Key "+r.clientKey}function m(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:p(r),"Content-Type":"application/json"}});if(!i.ok)throw new Error(i.statusText);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 S(r,a="https://api.d-id.com"){const n=m(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 h(r,a="https://api.d-id.com"){const n=m(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)}}}function y(r,a){const n=m(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 _(r,a){const n=m(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 g=(r=>(r.Idle="IDLE",r.Streaming="STREAMING",r))(g||{}),f=(r=>(r.Clip="clip",r.Talk="talk",r))(f||{});let C=!1;const d=(r,a)=>C&&console.log(r,a),T=(window.RTCPeerConnection||window.webkitRTCPeerConnection||window.mozRTCPeerConnection).bind(window);async function A(r,{debug:a=!1,callbacks:n,auth:e,baseURL:t="https://api.d-id.com"}){C=a;let i=null;const{startConnection:I,sendStreamRequest:k,close:K,createStream:b,addIceCandidate:D}=r.videoType===f.Clip?y(e,t):_(e,t),{id:u,offer:O,ice_servers:M,session_id:l}=await b(r),o=new T({iceServers:M}),w=o.createDataChannel("JanusDataChannel");if(!l)throw new Error("Could not create session_id");o.onicecandidate=s=>{d("peerConnection.onicecandidate",s),s.candidate&&s.candidate.sdpMid&&s.candidate.sdpMLineIndex!==null&&D(u,{candidate:s.candidate.candidate,sdpMid:s.candidate.sdpMid,sdpMLineIndex:s.candidate.sdpMLineIndex},l)},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)},w.onmessage=s=>{w.readyState==="open"&&n.onStreamingStateChange(s.data==="stream/done"?g.Idle:g.Streaming)},await o.setRemoteDescription(O),d("set remote description OK");const $=await o.createAnswer();return d("create answer OK"),await o.setLocalDescription($),d("set local description OK"),await I(u,$,l),d("start connection OK"),{speak(s){return k(u,l,s)},async terminate(){u&&(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(u,l),n.onConnectionStateChange("closed"),n.onStreamingStateChange(g.Idle))},sessionId:l,streamId:u}}c.createAgentsApi=h,c.createClient=m,c.createKnowledgeApi=S,c.createStreamingManager=A,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
1
+ (function(c,m){typeof exports=="object"&&typeof module<"u"?m(exports):typeof define=="function"&&define.amd?define(["exports"],m):(c=typeof globalThis<"u"?globalThis:c||self,m(c.index={}))})(this,function(c){"use strict";function m(r){return r.type==="bearer"?"Bearer "+r.token:r.type==="basic"?"Basic "+btoa(`${r.username}:${r.password}`):"Client-Key "+r.clientKey}function g(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:m(r),"Content-Type":"application/json"}});if(!i.ok){let d=await i.text().catch(()=>"Failed to fetch");try{d=JSON.parse(d),d.description&&(d=d.description)}catch{}throw new Error(d)}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=g(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=g(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)}}}var f=(r=>(r.Idle="IDLE",r.Streaming="STREAMING",r))(f||{}),C=(r=>(r.Clip="clip",r.Talk="talk",r))(C||{});function A(r,a){const n=g(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=g(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})}}}let w=!1;const u=(r,a)=>w&&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"}){w=a;let i=null;const{startConnection:d,sendStreamRequest:$,close:K,createStream:O,addIceCandidate:b}=r.videoType===C.Clip?A(e,t):I(e,t),{id:l,offer:D,ice_servers:M,session_id:p}=await O(r),o=new T({iceServers:M}),h=o.createDataChannel("JanusDataChannel");if(!p)throw new Error("Could not create session_id");o.onicecandidate=s=>{u("peerConnection.onicecandidate",s),s.candidate&&s.candidate.sdpMid&&s.candidate.sdpMLineIndex!==null&&b(l,{candidate:s.candidate.candidate,sdpMid:s.candidate.sdpMid,sdpMLineIndex:s.candidate.sdpMLineIndex},p)},o.oniceconnectionstatechange=()=>{u("peerConnection.oniceconnectionstatechange => "+o.iceConnectionState),n.onConnectionStateChange(o.iceConnectionState)},o.ontrack=s=>{u("peerConnection.ontrack",s),i=s.streams[0],n.onSrcObjectReady(i)},h.onmessage=s=>{h.readyState==="open"&&n.onStreamingStateChange(s.data==="stream/done"?f.Idle:f.Streaming)},await o.setRemoteDescription(D),u("set remote description OK");const S=await o.createAnswer();return u("create answer OK"),await o.setLocalDescription(S),u("set local description OK"),await d(l,S,p),u("start connection OK"),{speak(s){return $(l,p,s)},async terminate(){l&&(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(l,p),n.onConnectionStateChange("closed"),n.onStreamingStateChange(f.Idle))},sessionId:p,streamId:l}}c.createAgentsApi=_,c.createClient=g,c.createKnowledgeApi=y,c.createStreamingManager=k,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
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.2",
4
+ "version": "1.0.3",
5
5
  "type": "module",
6
6
  "description": "d-id client sdk",
7
7
  "repository": {