@d-id/client-sdk 1.0.13 → 1.0.14

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,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 g(r, o = "https://api.d-id.com") {
4
+ function p(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,13 +12,8 @@ function g(r, o = "https://api.d-id.com") {
12
12
  }
13
13
  });
14
14
  if (!s.ok) {
15
- let u = await s.text().catch(() => "Failed to fetch");
16
- try {
17
- const c = JSON.parse(u);
18
- c.description ? u = c.description : c.message && (u = c.message);
19
- } catch {
20
- }
21
- throw new Error(u);
15
+ let m = await s.text().catch(() => "Failed to fetch");
16
+ throw new Error(m);
22
17
  }
23
18
  return s.json();
24
19
  };
@@ -53,7 +48,7 @@ function g(r, o = "https://api.d-id.com") {
53
48
  };
54
49
  }
55
50
  function K(r, o = "https://api.d-id.com") {
56
- const n = g(r, `${o}/knowledge`);
51
+ const n = p(r, `${o}/knowledge`);
57
52
  return {
58
53
  createKnowledge(e) {
59
54
  return n.post("/", e);
@@ -90,7 +85,7 @@ function K(r, o = "https://api.d-id.com") {
90
85
  };
91
86
  }
92
87
  function O(r, o = "https://api.d-id.com") {
93
- const n = g(r, `${o}/agents`);
88
+ const n = p(r, `${o}/agents`);
94
89
  return {
95
90
  create(e) {
96
91
  return n.post("/", e);
@@ -116,7 +111,7 @@ function O(r, o = "https://api.d-id.com") {
116
111
  };
117
112
  }
118
113
  function A(r, o) {
119
- const n = g(r, o);
114
+ const n = p(r, o);
120
115
  return {
121
116
  createStream(e) {
122
117
  return n.post("/clips/streams", {
@@ -151,7 +146,7 @@ function A(r, o) {
151
146
  };
152
147
  }
153
148
  function T(r, o) {
154
- const n = g(r, o);
149
+ const n = p(r, o);
155
150
  return {
156
151
  createStream(e) {
157
152
  return n.post("/talks/streams", {
@@ -186,61 +181,61 @@ function T(r, o) {
186
181
  }
187
182
  };
188
183
  }
189
- var m = /* @__PURE__ */ ((r) => (r.Idle = "IDLE", r.Streaming = "STREAMING", r))(m || {}), $ = /* @__PURE__ */ ((r) => (r.Clip = "clip", r.Talk = "talk", r))($ || {});
190
- let f = !1;
191
- const d = (r, o) => f && console.log(r, o), D = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
192
- async function E(r, {
184
+ var l = /* @__PURE__ */ ((r) => (r.Idle = "IDLE", r.Streaming = "STREAMING", r))(l || {}), w = /* @__PURE__ */ ((r) => (r.Clip = "clip", r.Talk = "talk", r))(w || {});
185
+ let $ = !1;
186
+ const c = (r, o) => $ && console.log(r, o), D = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
187
+ async function R(r, {
193
188
  debug: o = !1,
194
189
  callbacks: n,
195
190
  auth: e,
196
191
  baseURL: t = "https://api.d-id.com"
197
192
  }) {
198
- f = o;
193
+ $ = o;
199
194
  let s = null;
200
195
  const {
201
- startConnection: u,
202
- sendStreamRequest: c,
196
+ startConnection: m,
197
+ sendStreamRequest: f,
203
198
  close: h,
204
199
  createStream: S,
205
200
  addIceCandidate: _
206
- } = r.videoType === $.Clip ? A(e, t) : T(e, t), {
207
- id: l,
201
+ } = r.videoType === w.Clip ? A(e, t) : T(e, t), {
202
+ id: d,
208
203
  offer: y,
209
204
  ice_servers: I,
210
- session_id: p
211
- } = await S(r), a = new D({
205
+ session_id: u
206
+ } = await S(r), i = new D({
212
207
  iceServers: I
213
- }), C = a.createDataChannel("JanusDataChannel");
214
- if (!p)
208
+ }), g = i.createDataChannel("JanusDataChannel");
209
+ if (!u)
215
210
  throw new Error("Could not create session_id");
216
- a.onicecandidate = (i) => {
217
- d("peerConnection.onicecandidate", i), i.candidate && i.candidate.sdpMid && i.candidate.sdpMLineIndex !== null && _(l, {
218
- candidate: i.candidate.candidate,
219
- sdpMid: i.candidate.sdpMid,
220
- sdpMLineIndex: i.candidate.sdpMLineIndex
221
- }, p);
222
- }, a.oniceconnectionstatechange = () => {
223
- d("peerConnection.oniceconnectionstatechange => " + a.iceConnectionState), n.onConnectionStateChange(a.iceConnectionState);
224
- }, a.ontrack = (i) => {
225
- d("peerConnection.ontrack", i), s = i.streams[0], n.onSrcObjectReady(s);
226
- }, C.onmessage = (i) => {
227
- C.readyState === "open" && n.onStreamingStateChange(i.data === "stream/done" ? m.Idle : m.Streaming);
228
- }, await a.setRemoteDescription(y), d("set remote description OK");
229
- const w = await a.createAnswer();
230
- return d("create answer OK"), await a.setLocalDescription(w), d("set local description OK"), await u(l, w, p), d("start connection OK"), {
231
- speak(i) {
232
- return c(l, p, i);
211
+ i.onicecandidate = (a) => {
212
+ c("peerConnection.onicecandidate", a), a.candidate && a.candidate.sdpMid && a.candidate.sdpMLineIndex !== null && _(d, {
213
+ candidate: a.candidate.candidate,
214
+ sdpMid: a.candidate.sdpMid,
215
+ sdpMLineIndex: a.candidate.sdpMLineIndex
216
+ }, u);
217
+ }, i.oniceconnectionstatechange = () => {
218
+ c("peerConnection.oniceconnectionstatechange => " + i.iceConnectionState), n.onConnectionStateChange(i.iceConnectionState);
219
+ }, i.ontrack = (a) => {
220
+ c("peerConnection.ontrack", a), s = a.streams[0], n.onSrcObjectReady(s);
221
+ }, g.onmessage = (a) => {
222
+ g.readyState === "open" && n.onStreamingStateChange(a.data === "stream/done" ? l.Idle : l.Streaming);
223
+ }, await i.setRemoteDescription(y), c("set remote description OK");
224
+ const C = await i.createAnswer();
225
+ return c("create answer OK"), await i.setLocalDescription(C), c("set local description OK"), await m(d, C, u), c("start connection OK"), {
226
+ speak(a) {
227
+ return f(d, u, a);
233
228
  },
234
229
  async terminate() {
235
- 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));
230
+ d && (s && (s.getTracks().forEach((a) => a.stop()), s = null), i && (i.close(), i.oniceconnectionstatechange = null, i.onnegotiationneeded = null, i.onicecandidate = null, i.ontrack = null), await h(d, u), n.onConnectionStateChange("closed"), n.onStreamingStateChange(l.Idle));
236
231
  },
237
- sessionId: p,
238
- streamId: l
232
+ sessionId: u,
233
+ streamId: d
239
234
  };
240
235
  }
241
236
  export {
242
237
  O as createAgentsApi,
243
- g as createClient,
238
+ p as createClient,
244
239
  K as createKnowledgeApi,
245
- E as createStreamingManager
240
+ R as createStreamingManager
246
241
  };
@@ -1 +1 @@
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,o="https://api.d-id.com"){const n=async(e,t)=>{const i=await fetch(o+(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,o="https://api.d-id.com"){const n=f(r,`${o}/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,o="https://api.d-id.com"){const n=f(r,`${o}/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)},newChat(e){return n.post(`/${e}/chat`)},chat(e,t,i){return n.post(`/${e}/chat/${t}`,i)}}}function A(r,o){const n=f(r,o);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,o){const n=f(r,o);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,o)=>h&&console.log(r,o),T=(window.RTCPeerConnection||window.webkitRTCPeerConnection||window.mozRTCPeerConnection).bind(window);async function k(r,{debug:o=!1,callbacks:n,auth:e,baseURL:t="https://api.d-id.com"}){h=o;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),a=new T({iceServers:E}),$=a.createDataChannel("JanusDataChannel");if(!m)throw new Error("Could not create session_id");a.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)},a.oniceconnectionstatechange=()=>{d("peerConnection.oniceconnectionstatechange => "+a.iceConnectionState),n.onConnectionStateChange(a.iceConnectionState)},a.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 a.setRemoteDescription(D),d("set remote description OK");const S=await a.createAnswer();return d("create answer OK"),await a.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),a&&(a.close(),a.oniceconnectionstatechange=null,a.onnegotiationneeded=null,a.onicecandidate=null,a.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"})});
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,o="https://api.d-id.com"){const n=async(e,t)=>{const i=await fetch(o+(e!=null&&e.startsWith("/")?e:`/${e}`),{...t,headers:{...t==null?void 0:t.headers,Authorization:p(r),"Content-Type":"application/json"}});if(!i.ok){let f=await i.text().catch(()=>"Failed to fetch");throw new Error(f)}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,o="https://api.d-id.com"){const n=m(r,`${o}/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 y(r,o="https://api.d-id.com"){const n=m(r,`${o}/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)},newChat(e){return n.post(`/${e}/chat`)},chat(e,t,i){return n.post(`/${e}/chat/${t}`,i)}}}function _(r,o){const n=m(r,o);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 A(r,o){const n=m(r,o);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||{}),C=(r=>(r.Clip="clip",r.Talk="talk",r))(C||{});let w=!1;const d=(r,o)=>w&&console.log(r,o),I=(window.RTCPeerConnection||window.webkitRTCPeerConnection||window.mozRTCPeerConnection).bind(window);async function T(r,{debug:o=!1,callbacks:n,auth:e,baseURL:t="https://api.d-id.com"}){w=o;let i=null;const{startConnection:f,sendStreamRequest:k,close:K,createStream:b,addIceCandidate:D}=r.videoType===C.Clip?_(e,t):A(e,t),{id:u,offer:O,ice_servers:M,session_id:l}=await b(r),a=new I({iceServers:M}),$=a.createDataChannel("JanusDataChannel");if(!l)throw new Error("Could not create session_id");a.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)},a.oniceconnectionstatechange=()=>{d("peerConnection.oniceconnectionstatechange => "+a.iceConnectionState),n.onConnectionStateChange(a.iceConnectionState)},a.ontrack=s=>{d("peerConnection.ontrack",s),i=s.streams[0],n.onSrcObjectReady(i)},$.onmessage=s=>{$.readyState==="open"&&n.onStreamingStateChange(s.data==="stream/done"?g.Idle:g.Streaming)},await a.setRemoteDescription(O),d("set remote description OK");const h=await a.createAnswer();return d("create answer OK"),await a.setLocalDescription(h),d("set local description OK"),await f(u,h,l),d("start connection OK"),{speak(s){return k(u,l,s)},async terminate(){u&&(i&&(i.getTracks().forEach(s=>s.stop()),i=null),a&&(a.close(),a.oniceconnectionstatechange=null,a.onnegotiationneeded=null,a.onicecandidate=null,a.ontrack=null),await K(u,l),n.onConnectionStateChange("closed"),n.onStreamingStateChange(g.Idle))},sessionId:l,streamId:u}}c.createAgentsApi=y,c.createClient=m,c.createKnowledgeApi=S,c.createStreamingManager=T,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.13",
4
+ "version": "1.0.14",
5
5
  "type": "module",
6
6
  "description": "d-id client sdk",
7
7
  "repository": {