@d-id/client-sdk 1.0.16 → 1.0.18

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.
@@ -0,0 +1,9 @@
1
+ import { Auth, RatingEntity } from '../../../../common/types/src/index';
2
+ type RatingPayload = Omit<RatingEntity, 'owner_id' | 'id' | 'created_at' | 'modified_at' | 'created_by' | 'external_id'>;
3
+ export declare function createRatingssApi(auth: Auth, host?: string): {
4
+ create(payload: RatingPayload, options?: RequestInit): Promise<RatingEntity>;
5
+ getByKnowledge(knowledgeId?: string, options?: RequestInit): Promise<RatingEntity[]>;
6
+ update(id: string, payload: Partial<RatingPayload>, options?: RequestInit): Promise<RatingEntity>;
7
+ delete(id: string, options?: RequestInit): Promise<RatingEntity>;
8
+ };
9
+ export {};
@@ -1,5 +1,6 @@
1
1
  export * from './api/agents';
2
2
  export * from './api/getClient';
3
3
  export * from './api/knowledge';
4
+ export * from './api/ratings';
4
5
  export * from './createAgentManager';
5
6
  export * from './createStreamingManager';
@@ -1,8 +1,26 @@
1
+ export declare enum RateState {
2
+ Unrated = "Unrated",
3
+ Positive = "Positive",
4
+ Negative = "Negative"
5
+ }
6
+ export interface RatingEntity {
7
+ id: string;
8
+ owner_id: string;
9
+ agent_id: string;
10
+ matches: [string, string][];
11
+ knowledge_id: string;
12
+ external_id: string;
13
+ created_by: string;
14
+ chat_id: string;
15
+ score: 1 | -1;
16
+ created_at: string;
17
+ modified_at: string;
18
+ }
1
19
  export interface Message {
2
20
  role: 'system' | 'assistant' | 'user' | 'function' | 'tool';
3
21
  content: string;
4
- name?: string;
5
22
  created_at: string;
23
+ matches?: ChatResponse['matches'];
6
24
  }
7
25
  export interface ChatPayload {
8
26
  messages: Message[];
@@ -8,6 +8,7 @@ export declare enum StreamingState {
8
8
  Stop = "STOP"
9
9
  }
10
10
  export declare enum StreamEvents {
11
+ ChatAnswer = "chat/answer",
11
12
  ChatPartial = "chat/partial",
12
13
  StreamDone = "stream/done",
13
14
  StreamStarted = "stream/started"
package/dist/index.js CHANGED
@@ -1,13 +1,13 @@
1
- function l(o) {
1
+ function v(o) {
2
2
  return o.type === "bearer" ? "Bearer " + o.token : o.type === "basic" ? "Basic " + btoa(`${o.username}:${o.password}`) : "Client-Key " + o.clientKey;
3
3
  }
4
- function h(o, d = "https://api.d-id.com") {
4
+ function C(o, i = "https://api.d-id.com") {
5
5
  const n = async (e, t) => {
6
- const r = await fetch(d + (e != null && e.startsWith("/") ? e : `/${e}`), {
6
+ const r = await fetch(i + (e != null && e.startsWith("/") ? e : `/${e}`), {
7
7
  ...t,
8
8
  headers: {
9
9
  ...t == null ? void 0 : t.headers,
10
- Authorization: l(o),
10
+ Authorization: v(o),
11
11
  "Content-Type": "application/json"
12
12
  }
13
13
  });
@@ -47,8 +47,8 @@ function h(o, d = "https://api.d-id.com") {
47
47
  }
48
48
  };
49
49
  }
50
- function M(o, d = "https://api.d-id.com") {
51
- const n = h(o, `${d}/agents`);
50
+ function M(o, i = "https://api.d-id.com") {
51
+ const n = C(o, `${i}/agents`);
52
52
  return {
53
53
  create(e, t) {
54
54
  return n.post("/", e, t);
@@ -73,8 +73,8 @@ function M(o, d = "https://api.d-id.com") {
73
73
  }
74
74
  };
75
75
  }
76
- function B(o, d = "https://api.d-id.com") {
77
- const n = h(o, `${d}/knowledge`);
76
+ function x(o, i = "https://api.d-id.com") {
77
+ const n = C(o, `${i}/knowledge`);
78
78
  return {
79
79
  createKnowledge(e, t) {
80
80
  return n.post("/", e, t);
@@ -110,7 +110,24 @@ function B(o, d = "https://api.d-id.com") {
110
110
  }
111
111
  };
112
112
  }
113
- var C = /* @__PURE__ */ ((o) => (o.Start = "START", o.Stop = "STOP", o))(C || {}), y = /* @__PURE__ */ ((o) => (o.ChatPartial = "chat/partial", o.StreamDone = "stream/done", o.StreamStarted = "stream/started", o))(y || {}), m = /* @__PURE__ */ ((o) => (o.Clip = "clip", o.Talk = "talk", o))(m || {});
113
+ function L(o, i = "https://api.d-id.com") {
114
+ const n = C(o, `${i}/chats/ratings`);
115
+ return {
116
+ create(e, t) {
117
+ return n.post("/", e, t);
118
+ },
119
+ getByKnowledge(e, t) {
120
+ return n.get(`/${e}`, t).then((r) => r ?? []);
121
+ },
122
+ update(e, t, r) {
123
+ return n.patch(`/${e}`, t, r);
124
+ },
125
+ delete(e, t) {
126
+ return n.delete(`/${e}`, t);
127
+ }
128
+ };
129
+ }
130
+ var h = /* @__PURE__ */ ((o) => (o.Start = "START", o.Stop = "STOP", o))(h || {}), _ = /* @__PURE__ */ ((o) => (o.ChatAnswer = "chat/answer", o.ChatPartial = "chat/partial", o.StreamDone = "stream/done", o.StreamStarted = "stream/started", o))(_ || {}), m = /* @__PURE__ */ ((o) => (o.Clip = "clip", o.Talk = "talk", o))(m || {});
114
131
  function O(o) {
115
132
  return o.presenter.type === m.Clip ? {
116
133
  videoType: m.Clip,
@@ -121,20 +138,20 @@ function O(o) {
121
138
  source_url: o.presenter.source_url
122
139
  };
123
140
  }
124
- async function L(o, {
125
- callbacks: d,
141
+ async function J(o, {
142
+ callbacks: i,
126
143
  ...n
127
144
  }) {
128
145
  const e = new AbortController(), t = M(n.auth, n.baseURL), r = await t.getById(o), a = await t.newChat(o), {
129
146
  terminate: w,
130
147
  sessionId: S,
131
- streamId: f
132
- } = await x(O(r), {
148
+ streamId: $
149
+ } = await j(O(r), {
133
150
  ...n,
134
151
  callbacks: {
135
- onSrcObjectReady: d.onSrcObjectReady,
136
- onVideoStateChange: d == null ? void 0 : d.onVideoStateChange,
137
- onConnectionStateChange: d.onConnectionStateChange
152
+ onSrcObjectReady: i.onSrcObjectReady,
153
+ onVideoStateChange: i == null ? void 0 : i.onVideoStateChange,
154
+ onConnectionStateChange: i.onConnectionStateChange
138
155
  }
139
156
  });
140
157
  return {
@@ -146,7 +163,7 @@ async function L(o, {
146
163
  chat(c) {
147
164
  return t.chat(o, a.id, {
148
165
  sessionId: S,
149
- streamId: f,
166
+ streamId: $,
150
167
  messages: c
151
168
  }, {
152
169
  signal: e.signal
@@ -154,8 +171,8 @@ async function L(o, {
154
171
  }
155
172
  };
156
173
  }
157
- function P(o, d) {
158
- const n = h(o, d);
174
+ function P(o, i) {
175
+ const n = C(o, i);
159
176
  return {
160
177
  createStream(e) {
161
178
  return n.post("/clips/streams", {
@@ -189,8 +206,8 @@ function P(o, d) {
189
206
  }
190
207
  };
191
208
  }
192
- function q(o, d) {
193
- const n = h(o, d);
209
+ function q(o, i) {
210
+ const n = C(o, i);
194
211
  return {
195
212
  createStream(e, t) {
196
213
  return n.post("/talks/streams", {
@@ -225,69 +242,70 @@ function q(o, d) {
225
242
  }
226
243
  };
227
244
  }
228
- let I = !1;
229
- const p = (o, d) => I && console.log(o, d), j = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
230
- async function x(o, {
231
- debug: d = !1,
245
+ let l = !1;
246
+ const p = (o, i) => l && console.log(o, i), B = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
247
+ async function j(o, {
248
+ debug: i = !1,
232
249
  callbacks: n,
233
250
  auth: e,
234
251
  baseURL: t = "https://api.d-id.com"
235
252
  }) {
236
- I = d;
253
+ l = i;
237
254
  const {
238
255
  startConnection: r,
239
256
  sendStreamRequest: a,
240
257
  close: w,
241
258
  createStream: S,
242
- addIceCandidate: f
259
+ addIceCandidate: $
243
260
  } = o.videoType === m.Clip ? P(e, t) : q(e, t), {
244
261
  id: c,
245
- offer: D,
246
- ice_servers: v,
262
+ offer: I,
263
+ ice_servers: D,
247
264
  session_id: g
248
- } = await S(o), s = new j({
249
- iceServers: v
265
+ } = await S(o), s = new B({
266
+ iceServers: D
250
267
  }), A = s.createDataChannel("JanusDataChannel");
251
268
  if (!g)
252
269
  throw new Error("Could not create session_id");
253
- s.onicecandidate = (i) => {
254
- p("peerConnection.onicecandidate", i), i.candidate && i.candidate.sdpMid && i.candidate.sdpMLineIndex !== null && f(c, {
255
- candidate: i.candidate.candidate,
256
- sdpMid: i.candidate.sdpMid,
257
- sdpMLineIndex: i.candidate.sdpMLineIndex
270
+ s.onicecandidate = (d) => {
271
+ p("peerConnection.onicecandidate", d), d.candidate && d.candidate.sdpMid && d.candidate.sdpMLineIndex !== null && $(c, {
272
+ candidate: d.candidate.candidate,
273
+ sdpMid: d.candidate.sdpMid,
274
+ sdpMLineIndex: d.candidate.sdpMLineIndex
258
275
  }, g);
259
276
  }, s.oniceconnectionstatechange = () => {
260
- var i;
261
- p("peerConnection.oniceconnectionstatechange => " + s.iceConnectionState), (i = n.onConnectionStateChange) == null || i.call(n, s.iceConnectionState);
262
- }, s.ontrack = (i) => {
277
+ var d;
278
+ p("peerConnection.oniceconnectionstatechange => " + s.iceConnectionState), (d = n.onConnectionStateChange) == null || d.call(n, s.iceConnectionState);
279
+ }, s.ontrack = (d) => {
263
280
  var u;
264
- p("peerConnection.ontrack", i), (u = n.onSrcObjectReady) == null || u.call(n, i.streams[0]);
265
- }, A.onmessage = (i) => {
266
- var u, $, R;
281
+ p("peerConnection.ontrack", d), (u = n.onSrcObjectReady) == null || u.call(n, d.streams[0]);
282
+ }, A.onmessage = (d) => {
283
+ var u, f, R;
267
284
  if (A.readyState === "open") {
268
- const [_, K] = i.data.split(":");
269
- _ === y.StreamDone ? (u = n.onVideoStateChange) == null || u.call(n, C.Stop) : _ === y.StreamStarted ? ($ = n.onVideoStateChange) == null || $.call(n, C.Start) : (R = n.onMessage) == null || R.call(n, _, decodeURIComponent(K));
285
+ const [y, K] = d.data.split(":");
286
+ y === _.StreamDone ? (u = n.onVideoStateChange) == null || u.call(n, h.Stop) : y === _.StreamStarted ? (f = n.onVideoStateChange) == null || f.call(n, h.Start) : (R = n.onMessage) == null || R.call(n, y, decodeURIComponent(K));
270
287
  }
271
- }, await s.setRemoteDescription(D), p("set remote description OK");
288
+ }, await s.setRemoteDescription(I), p("set remote description OK");
272
289
  const T = await s.createAnswer();
273
290
  return p("create answer OK"), await s.setLocalDescription(T), p("set local description OK"), await r(c, T, g), p("start connection OK"), {
274
- speak(i) {
275
- return a(c, g, i);
291
+ speak(d) {
292
+ return a(c, g, d);
276
293
  },
277
294
  async terminate() {
278
- var i, u;
279
- c && (s && (s.close(), s.oniceconnectionstatechange = null, s.onnegotiationneeded = null, s.onicecandidate = null, s.ontrack = null), await w(c, g).catch(($) => {
280
- }), (i = n.onConnectionStateChange) == null || i.call(n, "closed"), (u = n.onVideoStateChange) == null || u.call(n, C.Stop));
295
+ var d, u;
296
+ c && (s && (s.close(), s.oniceconnectionstatechange = null, s.onnegotiationneeded = null, s.onicecandidate = null, s.ontrack = null), await w(c, g).catch((f) => {
297
+ }), (d = n.onConnectionStateChange) == null || d.call(n, "closed"), (u = n.onVideoStateChange) == null || u.call(n, h.Stop));
281
298
  },
282
299
  sessionId: g,
283
300
  streamId: c
284
301
  };
285
302
  }
286
303
  export {
287
- L as createAgentManager,
304
+ J as createAgentManager,
288
305
  M as createAgentsApi,
289
- h as createClient,
290
- B as createKnowledgeApi,
291
- x as createStreamingManager,
306
+ C as createClient,
307
+ x as createKnowledgeApi,
308
+ L as createRatingssApi,
309
+ j as createStreamingManager,
292
310
  O as getAgentStreamArgs
293
311
  };
@@ -1 +1 @@
1
- (function(c,C){typeof exports=="object"&&typeof module<"u"?C(exports):typeof define=="function"&&define.amd?define(["exports"],C):(c=typeof globalThis<"u"?globalThis:c||self,C(c.index={}))})(this,function(c){"use strict";function C(i){return i.type==="bearer"?"Bearer "+i.token:i.type==="basic"?"Basic "+btoa(`${i.username}:${i.password}`):"Client-Key "+i.clientKey}function h(i,d="https://api.d-id.com"){const n=async(e,t)=>{const r=await fetch(d+(e!=null&&e.startsWith("/")?e:`/${e}`),{...t,headers:{...t==null?void 0:t.headers,Authorization:C(i),"Content-Type":"application/json"}});if(!r.ok){let a=await r.text().catch(()=>"Failed to fetch");throw new Error(a)}return r.json()};return{get(e,t){return n(e,{...t,method:"GET"})},post(e,t,r){return n(e,{...r,body:JSON.stringify(t),method:"POST"})},delete(e,t,r){return n(e,{...r,body:JSON.stringify(t),method:"DELETE"})},patch(e,t,r){return n(e,{...r,body:JSON.stringify(t),method:"PATCH"})}}}function l(i,d="https://api.d-id.com"){const n=h(i,`${d}/agents`);return{create(e,t){return n.post("/",e,t)},getAgents(e,t){return n.get(`/${e?`?tag=${e}`:""}`,t).then(r=>r??[])},getById(e,t){return n.get(`/${e}`,t)},delete(e,t){return n.delete(`/${e}`,void 0,t)},update(e,t,r){return n.patch(`/${e}`,t,r)},newChat(e,t){return n.post(`/${e}/chat`,void 0,t)},chat(e,t,r,a){return n.post(`/${e}/chat/${t}`,r,a)}}}function O(i,d="https://api.d-id.com"){const n=h(i,`${d}/knowledge`);return{createKnowledge(e,t){return n.post("/",e,t)},getKnowledgeBase(e){return n.get("/",e)},getKnowledge(e,t){return n.get(`/${e}`,t)},deleteKnowledge(e,t){return n.delete(`/${e}`,void 0,t)},createDocument(e,t,r){return n.post(`/${e}/documents`,t,r)},deleteDocument(e,t,r){return n.delete(`/${e}/documents/${t}`,void 0,r)},getDocuments(e,t){return n.get(`/${e}/documents`,t)},getDocument(e,t,r){return n.get(`/${e}/documents/${t}`,r)},getRecords(e,t,r){return n.get(`/${e}/documents/${t}/records`,r)},query(e,t,r){return n.post(`/${e}/query`,{query:t},r)}}}var S=(i=>(i.Start="START",i.Stop="STOP",i))(S||{}),w=(i=>(i.ChatPartial="chat/partial",i.StreamDone="stream/done",i.StreamStarted="stream/started",i))(w||{}),f=(i=>(i.Clip="clip",i.Talk="talk",i))(f||{});function R(i){return i.presenter.type===f.Clip?{videoType:f.Clip,driver_id:i.presenter.driver_id,presenter_id:i.presenter.presenter_id}:{videoType:f.Talk,source_url:i.presenter.source_url}}async function P(i,{callbacks:d,...n}){const e=new AbortController,t=l(n.auth,n.baseURL),r=await t.getById(i),a=await t.newChat(i),{terminate:$,sessionId:y,streamId:_}=await v(R(r),{...n,callbacks:{onSrcObjectReady:d.onSrcObjectReady,onVideoStateChange:d==null?void 0:d.onVideoStateChange,onConnectionStateChange:d.onConnectionStateChange}});return{agent:r,terminate(){return e.abort(),$()},chatId:a.id,chat(u){return t.chat(i,a.id,{sessionId:y,streamId:_,messages:u},{signal:e.signal})}}}function j(i,d){const n=h(i,d);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,r){return n.post(`/clips/streams/${e}/sdp`,{session_id:r,answer:t})},addIceCandidate(e,t,r){return n.post(`/clips/streams/${e}/ice`,{session_id:r,...t})},sendStreamRequest(e,t,r){return n.post(`/clips/streams/${e}`,{session_id:t,...r})},close(e,t){return n.delete(`/clips/streams/${e}`,{session_id:t})}}}function q(i,d){const n=h(i,d);return{createStream(e,t){return n.post("/talks/streams",{source_url:e.source_url,driver_url:e.driver_url,face:e.face,config:e.config},t)},startConnection(e,t,r,a){return n.post(`/talks/streams/${e}/sdp`,{session_id:r,answer:t},a)},addIceCandidate(e,t,r,a){return n.post(`/talks/streams/${e}/ice`,{session_id:r,...t},a)},sendStreamRequest(e,t,r,a){return n.post(`/talks/streams/${e}`,{session_id:t,...r},a)},close(e,t,r){return n.delete(`/talks/streams/${e}`,{session_id:t},r)}}}let I=!1;const g=(i,d)=>I&&console.log(i,d),B=(window.RTCPeerConnection||window.webkitRTCPeerConnection||window.mozRTCPeerConnection).bind(window);async function v(i,{debug:d=!1,callbacks:n,auth:e,baseURL:t="https://api.d-id.com"}){I=d;const{startConnection:r,sendStreamRequest:a,close:$,createStream:y,addIceCandidate:_}=i.videoType===f.Clip?j(e,t):q(e,t),{id:u,offer:L,ice_servers:E,session_id:m}=await y(i),s=new B({iceServers:E}),D=s.createDataChannel("JanusDataChannel");if(!m)throw new Error("Could not create session_id");s.onicecandidate=o=>{g("peerConnection.onicecandidate",o),o.candidate&&o.candidate.sdpMid&&o.candidate.sdpMLineIndex!==null&&_(u,{candidate:o.candidate.candidate,sdpMid:o.candidate.sdpMid,sdpMLineIndex:o.candidate.sdpMLineIndex},m)},s.oniceconnectionstatechange=()=>{var o;g("peerConnection.oniceconnectionstatechange => "+s.iceConnectionState),(o=n.onConnectionStateChange)==null||o.call(n,s.iceConnectionState)},s.ontrack=o=>{var p;g("peerConnection.ontrack",o),(p=n.onSrcObjectReady)==null||p.call(n,o.streams[0])},D.onmessage=o=>{var p,A,M;if(D.readyState==="open"){const[T,J]=o.data.split(":");T===w.StreamDone?(p=n.onVideoStateChange)==null||p.call(n,S.Stop):T===w.StreamStarted?(A=n.onVideoStateChange)==null||A.call(n,S.Start):(M=n.onMessage)==null||M.call(n,T,decodeURIComponent(J))}},await s.setRemoteDescription(L),g("set remote description OK");const K=await s.createAnswer();return g("create answer OK"),await s.setLocalDescription(K),g("set local description OK"),await r(u,K,m),g("start connection OK"),{speak(o){return a(u,m,o)},async terminate(){var o,p;u&&(s&&(s.close(),s.oniceconnectionstatechange=null,s.onnegotiationneeded=null,s.onicecandidate=null,s.ontrack=null),await $(u,m).catch(A=>{}),(o=n.onConnectionStateChange)==null||o.call(n,"closed"),(p=n.onVideoStateChange)==null||p.call(n,S.Stop))},sessionId:m,streamId:u}}c.createAgentManager=P,c.createAgentsApi=l,c.createClient=h,c.createKnowledgeApi=O,c.createStreamingManager=v,c.getAgentStreamArgs=R,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
1
+ (function(c,h){typeof exports=="object"&&typeof module<"u"?h(exports):typeof define=="function"&&define.amd?define(["exports"],h):(c=typeof globalThis<"u"?globalThis:c||self,h(c.index={}))})(this,function(c){"use strict";function h(i){return i.type==="bearer"?"Bearer "+i.token:i.type==="basic"?"Basic "+btoa(`${i.username}:${i.password}`):"Client-Key "+i.clientKey}function m(i,o="https://api.d-id.com"){const n=async(e,t)=>{const r=await fetch(o+(e!=null&&e.startsWith("/")?e:`/${e}`),{...t,headers:{...t==null?void 0:t.headers,Authorization:h(i),"Content-Type":"application/json"}});if(!r.ok){let a=await r.text().catch(()=>"Failed to fetch");throw new Error(a)}return r.json()};return{get(e,t){return n(e,{...t,method:"GET"})},post(e,t,r){return n(e,{...r,body:JSON.stringify(t),method:"POST"})},delete(e,t,r){return n(e,{...r,body:JSON.stringify(t),method:"DELETE"})},patch(e,t,r){return n(e,{...r,body:JSON.stringify(t),method:"PATCH"})}}}function T(i,o="https://api.d-id.com"){const n=m(i,`${o}/agents`);return{create(e,t){return n.post("/",e,t)},getAgents(e,t){return n.get(`/${e?`?tag=${e}`:""}`,t).then(r=>r??[])},getById(e,t){return n.get(`/${e}`,t)},delete(e,t){return n.delete(`/${e}`,void 0,t)},update(e,t,r){return n.patch(`/${e}`,t,r)},newChat(e,t){return n.post(`/${e}/chat`,void 0,t)},chat(e,t,r,a){return n.post(`/${e}/chat/${t}`,r,a)}}}function O(i,o="https://api.d-id.com"){const n=m(i,`${o}/knowledge`);return{createKnowledge(e,t){return n.post("/",e,t)},getKnowledgeBase(e){return n.get("/",e)},getKnowledge(e,t){return n.get(`/${e}`,t)},deleteKnowledge(e,t){return n.delete(`/${e}`,void 0,t)},createDocument(e,t,r){return n.post(`/${e}/documents`,t,r)},deleteDocument(e,t,r){return n.delete(`/${e}/documents/${t}`,void 0,r)},getDocuments(e,t){return n.get(`/${e}/documents`,t)},getDocument(e,t,r){return n.get(`/${e}/documents/${t}`,r)},getRecords(e,t,r){return n.get(`/${e}/documents/${t}/records`,r)},query(e,t,r){return n.post(`/${e}/query`,{query:t},r)}}}function P(i,o="https://api.d-id.com"){const n=m(i,`${o}/chats/ratings`);return{create(e,t){return n.post("/",e,t)},getByKnowledge(e,t){return n.get(`/${e}`,t).then(r=>r??[])},update(e,t,r){return n.patch(`/${e}`,t,r)},delete(e,t){return n.delete(`/${e}`,t)}}}var w=(i=>(i.Start="START",i.Stop="STOP",i))(w||{}),S=(i=>(i.ChatAnswer="chat/answer",i.ChatPartial="chat/partial",i.StreamDone="stream/done",i.StreamStarted="stream/started",i))(S||{}),f=(i=>(i.Clip="clip",i.Talk="talk",i))(f||{});function R(i){return i.presenter.type===f.Clip?{videoType:f.Clip,driver_id:i.presenter.driver_id,presenter_id:i.presenter.presenter_id}:{videoType:f.Talk,source_url:i.presenter.source_url}}async function j(i,{callbacks:o,...n}){const e=new AbortController,t=T(n.auth,n.baseURL),r=await t.getById(i),a=await t.newChat(i),{terminate:$,sessionId:y,streamId:_}=await K(R(r),{...n,callbacks:{onSrcObjectReady:o.onSrcObjectReady,onVideoStateChange:o==null?void 0:o.onVideoStateChange,onConnectionStateChange:o.onConnectionStateChange}});return{agent:r,terminate(){return e.abort(),$()},chatId:a.id,chat(u){return t.chat(i,a.id,{sessionId:y,streamId:_,messages:u},{signal:e.signal})}}}function q(i,o){const n=m(i,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,r){return n.post(`/clips/streams/${e}/sdp`,{session_id:r,answer:t})},addIceCandidate(e,t,r){return n.post(`/clips/streams/${e}/ice`,{session_id:r,...t})},sendStreamRequest(e,t,r){return n.post(`/clips/streams/${e}`,{session_id:t,...r})},close(e,t){return n.delete(`/clips/streams/${e}`,{session_id:t})}}}function B(i,o){const n=m(i,o);return{createStream(e,t){return n.post("/talks/streams",{source_url:e.source_url,driver_url:e.driver_url,face:e.face,config:e.config},t)},startConnection(e,t,r,a){return n.post(`/talks/streams/${e}/sdp`,{session_id:r,answer:t},a)},addIceCandidate(e,t,r,a){return n.post(`/talks/streams/${e}/ice`,{session_id:r,...t},a)},sendStreamRequest(e,t,r,a){return n.post(`/talks/streams/${e}`,{session_id:t,...r},a)},close(e,t,r){return n.delete(`/talks/streams/${e}`,{session_id:t},r)}}}let I=!1;const g=(i,o)=>I&&console.log(i,o),L=(window.RTCPeerConnection||window.webkitRTCPeerConnection||window.mozRTCPeerConnection).bind(window);async function K(i,{debug:o=!1,callbacks:n,auth:e,baseURL:t="https://api.d-id.com"}){I=o;const{startConnection:r,sendStreamRequest:a,close:$,createStream:y,addIceCandidate:_}=i.videoType===f.Clip?q(e,t):B(e,t),{id:u,offer:J,ice_servers:V,session_id:C}=await y(i),s=new L({iceServers:V}),D=s.createDataChannel("JanusDataChannel");if(!C)throw new Error("Could not create session_id");s.onicecandidate=d=>{g("peerConnection.onicecandidate",d),d.candidate&&d.candidate.sdpMid&&d.candidate.sdpMLineIndex!==null&&_(u,{candidate:d.candidate.candidate,sdpMid:d.candidate.sdpMid,sdpMLineIndex:d.candidate.sdpMLineIndex},C)},s.oniceconnectionstatechange=()=>{var d;g("peerConnection.oniceconnectionstatechange => "+s.iceConnectionState),(d=n.onConnectionStateChange)==null||d.call(n,s.iceConnectionState)},s.ontrack=d=>{var p;g("peerConnection.ontrack",d),(p=n.onSrcObjectReady)==null||p.call(n,d.streams[0])},D.onmessage=d=>{var p,A,v;if(D.readyState==="open"){const[l,E]=d.data.split(":");l===S.StreamDone?(p=n.onVideoStateChange)==null||p.call(n,w.Stop):l===S.StreamStarted?(A=n.onVideoStateChange)==null||A.call(n,w.Start):(v=n.onMessage)==null||v.call(n,l,decodeURIComponent(E))}},await s.setRemoteDescription(J),g("set remote description OK");const M=await s.createAnswer();return g("create answer OK"),await s.setLocalDescription(M),g("set local description OK"),await r(u,M,C),g("start connection OK"),{speak(d){return a(u,C,d)},async terminate(){var d,p;u&&(s&&(s.close(),s.oniceconnectionstatechange=null,s.onnegotiationneeded=null,s.onicecandidate=null,s.ontrack=null),await $(u,C).catch(A=>{}),(d=n.onConnectionStateChange)==null||d.call(n,"closed"),(p=n.onVideoStateChange)==null||p.call(n,w.Stop))},sessionId:C,streamId:u}}c.createAgentManager=j,c.createAgentsApi=T,c.createClient=m,c.createKnowledgeApi=O,c.createRatingssApi=P,c.createStreamingManager=K,c.getAgentStreamArgs=R,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.16",
4
+ "version": "1.0.18",
5
5
  "type": "module",
6
6
  "description": "d-id client sdk",
7
7
  "repository": {