@d-id/client-sdk 1.0.19 → 1.0.29-beta.55
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/README.md +4 -0
- package/dist/index.js +399 -362
- package/dist/index.umd.cjs +1 -1
- package/dist/src/{lib/api → api}/agents.d.ts +1 -1
- package/dist/src/{lib/api → api}/clipStream.d.ts +1 -1
- package/dist/src/{lib/api → api}/getClient.d.ts +1 -1
- package/dist/src/{lib/api → api}/knowledge.d.ts +2 -1
- package/dist/src/{lib/api → api}/ratings.d.ts +1 -1
- package/dist/src/{lib/api → api}/talkStream.d.ts +1 -1
- package/dist/src/{lib/auth → auth}/getAuthHeader.d.ts +1 -1
- package/dist/src/connectToSocket.d.ts +9 -0
- package/dist/src/{lib/createAgentManager.d.ts → createAgentManager.d.ts} +5 -4
- package/dist/src/{lib/createStreamingManager.d.ts → createStreamingManager.d.ts} +3 -9
- package/dist/src/{lib/environment.d.ts → environment.d.ts} +0 -1
- package/dist/src/index.d.ts +1 -7
- package/dist/src/types/StreamScript.d.ts +1 -1
- package/dist/src/types/auth.d.ts +2 -4
- package/dist/src/types/entities/agents/agent.d.ts +24 -1
- package/dist/src/types/entities/agents/chat.d.ts +8 -2
- package/dist/src/types/entities/agents/manager.d.ts +20 -14
- package/dist/src/types/stream/stream.d.ts +5 -3
- package/dist/src/{lib/utils → utils}/webrtc.d.ts +1 -1
- package/package.json +9 -10
- package/dist/src/lib/connectToSocket.d.ts +0 -9
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
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";const h="https://api.d-id.com",O="wss://notifications.d-id.com";function E(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 C(e,i=h){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:E(e),"Content-Type":"application/json"}});if(!r.ok){let d=await r.text().catch(()=>"Failed to fetch");throw new Error(d)}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 T(e,i=h){const a=C(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,d){return a.post(`/${t}/chat/${n}`,r,d)}}}function W(e,i=h){const a=C(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)}}}function H(e,i=h){const a=C(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)}}}const x=e=>new Promise(i=>setTimeout(i,e));function ee(e){return new Promise((i,a)=>{const{callbacks:t,host:n,auth:r}=e,{onMessage:d=null,onOpen:l=null,onClose:p=null,onError:g=null}=t||{},u=new WebSocket(`${n}?authorization=${E(r)}`);u.onmessage=d,u.onclose=p,u.onerror=s=>{console.log(s),g==null||g(s),a(s)},u.onopen=s=>{l==null||l(s),i(u)}})}async function te(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 ee(e)}catch(n){if(t===i)throw n;await x(t*500)}return a}async function q(e,i,a=O){const t=i?[i]:[],n=await te({auth:e,host:a,callbacks:{onMessage:r=>{const d=JSON.parse(r.data);t.forEach(l=>l(d.event,d))}}});return{socket:n,terminate:()=>n.close(),subscribeToEvents:r=>t.push(r)}}var N=(e=>(e.Amazon="amazon",e.Microsoft="microsoft",e.Afflorithmics="afflorithmics",e.Elevenlabs="elevenlabs",e))(N||{}),U=(e=>(e.Public="public",e.Premium="premium",e.Private="private",e))(U||{}),M=(e=>(e.Start="START",e.Stop="STOP",e))(M||{}),k=(e=>(e.ChatAnswer="chat/answer",e.ChatPartial="chat/partial",e.StreamDone="stream/done",e.StreamStarted="stream/started",e))(k||{}),z=(e=>(e.Unrated="Unrated",e.Positive="Positive",e.Negative="Negative",e))(z||{}),I=(e=>(e.Embed="embed",e.Query="query",e.Partial="partial",e.Answer="answer",e.Complete="done",e))(I||{}),B=(e=>(e.KnowledgeProcessing="knowledge/processing",e.KnowledgeIndexing="knowledge/indexing",e.KnowledgeFailed="knowledge/error",e.KnowledgeDone="knowledge/done",e))(B||{}),J=(e=>(e.Knowledge="knowledge",e.Document="document",e.Record="record",e))(J||{}),D=(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))(D||{}),$=(e=>(e.Clip="clip",e.Talk="talk",e))($||{});function F(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 V(e,i,a,t){return new Promise(async(n,r)=>{const d=await Q(F(e),{...i,callbacks:{...i.callbacks,onConnectionStateChange:async l=>{var p,g;l==="connected"?(t||(t=await a.newChat(e.id)),n({chat:t,streamingManager:d})):l==="failed"&&r(new Error("Cannot create connection")),(g=(p=i.callbacks).onConnectionStateChange)==null||g.call(p,l)},onMessage:(l,p)=>{var g,u;l===k.ChatPartial&&((u=(g=i.callbacks).onChatEvents)==null||u.call(g,I.Partial,{content:p,event:I.Partial}))}}})})}async function ne(e,i){const a=i.baseURL||h,t=new AbortController,n=T(i.auth,a),r=H(i.auth,a),d=W(i.auth,a),l=await n.getById(e),p=await q(i.auth,i.callbacks.onChatEvents);let{chat:g,streamingManager:u}=await V(l,i,n);return{agent:l,async reconnectToChat(){const{streamingManager:s}=await V(l,i,n,g);u=s},terminate(){return t.abort(),p.terminate(),u.terminate()},chatId:g.id,chat(s){return n.chat(e,g.id,{sessionId:u.sessionId,streamId:u.streamId,messages:s},{signal:t.signal})},rate(s,f){return f?r.update(f,s):r.create(s)},deleteRate(s){return r.delete(s)},speak(s){let f;return s.type==="text"?f={script:{type:"text",provider:s.provider,input:s.input,ssml:s.ssml||!1}}:s.type==="audio"&&(f={script:{type:"audio",audio_url:s.audio_url}}),u.speak(f)},getStarterMessages(){var s,f;return(s=l.knowledge)!=null&&s.id?d.getKnowledge((f=l.knowledge)==null?void 0:f.id).then(R=>(R==null?void 0:R.starter_message)||[]):Promise.resolve([])}}}function ae(e,i){const a=C(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 re(e,i){const a=C(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,d){return a.post(`/talks/streams/${t}/sdp`,{session_id:r,answer:n},d)},addIceCandidate(t,n,r,d){return a.post(`/talks/streams/${t}/ice`,{session_id:r,...n},d)},sendStreamRequest(t,n,r,d){return a.post(`/talks/streams/${t}`,{session_id:n,...r},d)},close(t,n,r){return a.delete(`/talks/streams/${t}`,{session_id:n},r)}}}function ie(e,i){return e.map((a,t)=>t===0?i?{index:t,timestamp:a.timestamp,bytesReceived:a.bytesReceived-i.bytesReceived,packetsReceived:a.packetsReceived-i.packetsReceived,packetsLost:a.packetsLost-i.packetsLost,jitter:a.jitter,frameWidth:a.frameWidth,frameHeight:a.frameHeight,frameRate:a.frameRate}:{index:t,timestamp:a.timestamp,bytesReceived:a.bytesReceived,packetsReceived:a.packetsReceived,packetsLost:a.packetsLost,jitter:a.jitter,frameWidth:a.frameWidth,frameHeight:a.frameHeight,frameRate:a.frameRate}:{index:t,timestamp:a.timestamp,bytesReceived:a.bytesReceived-e[t-1].bytesReceived,packetsReceived:a.packetsReceived-e[t-1].packetsReceived,packetsLost:a.packetsLost-e[t-1].packetsLost,jitter:a.jitter,frameWidth:a.frameWidth,frameHeight:a.frameHeight,frameRate:a.frameRate})}let G=!1;const v=(e,i)=>G&&console.log(e,i),se=(window.RTCPeerConnection||window.webkitRTCPeerConnection||window.mozRTCPeerConnection).bind(window);async function Q(e,{debug:i=!1,callbacks:a,auth:t,baseURL:n=h}){G=i;const r={...a},{startConnection:d,sendStreamRequest:l,close:p,createStream:g,addIceCandidate:u}=e.videoType===$.Clip?ae(t,n):re(t,n),{id:s,offer:f,ice_servers:R,session_id:S}=await g(e),m=new se({iceServers:R}),X=m.createDataChannel("JanusDataChannel"),y=[];let A=0,Y;if(!S)throw new Error("Could not create session_id");m.onicecandidate=o=>{v("peerConnection.onicecandidate",o),o.candidate&&o.candidate.sdpMid&&o.candidate.sdpMLineIndex!==null&&u(s,{candidate:o.candidate.candidate,sdpMid:o.candidate.sdpMid,sdpMLineIndex:o.candidate.sdpMLineIndex},S)},m.oniceconnectionstatechange=()=>{var o;v("peerConnection.oniceconnectionstatechange => "+m.iceConnectionState),(o=r.onConnectionStateChange)==null||o.call(r,m.iceConnectionState)},m.ontrack=o=>{var w;v("peerConnection.ontrack",o),(w=r.onSrcObjectReady)==null||w.call(r,o.streams[0])},X.onmessage=o=>{var w,P,j;if(X.readyState==="open"){const[b,oe]=o.data.split(":");if(b===k.StreamStarted)A=y.length,Y=setInterval(()=>{m.getStats().then(L=>{L.forEach(_=>{_.type==="inbound-rtp"&&_.kind==="video"&&y.push(_)})})},1e3),(w=r.onVideoStateChange)==null||w.call(r,M.Start);else if(b===k.StreamDone){clearInterval(Y);const K=y.slice(A);if(K){const L=A===0?void 0:y[A-1],_=ie(K,L);A=y.length,(P=r.onVideoStateChange)==null||P.call(r,M.Stop,_.sort((ce,de)=>de.packetsLost-ce.packetsLost).slice(0,5))}}else(j=r.onMessage)==null||j.call(r,b,decodeURIComponent(oe))}},await m.setRemoteDescription(f),v("set remote description OK");const Z=await m.createAnswer();return v("create answer OK"),await m.setLocalDescription(Z),v("set local description OK"),await d(s,Z,S),v("start connection OK"),{speak(o){return l(s,S,o)},async terminate(){var o,w;s&&(m&&(m.close(),m.oniceconnectionstatechange=null,m.onnegotiationneeded=null,m.onicecandidate=null,m.ontrack=null),await p(s,S).catch(P=>{}),(o=r.onConnectionStateChange)==null||o.call(r,"closed"),(w=r.onVideoStateChange)==null||w.call(r,M.Stop))},sessionId:S,streamId:s,onCallback(o,w){r[o]=w}}}c.ChatProgress=I,c.DocumentType=D,c.KnowledgeType=J,c.Providers=N,c.RateState=z,c.SocketManager=q,c.StreamEvents=k,c.Subject=B,c.VoiceAccess=U,c.createAgentManager=ne,c.createAgentsApi=T,c.createClient=C,c.createKnowledgeApi=W,c.createRatingsApi=H,c.createStreamingManager=Q,c.getAgentStreamArgs=F,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(g,$){typeof exports=="object"&&typeof module<"u"?$(exports):typeof define=="function"&&define.amd?define(["exports"],$):(g=typeof globalThis<"u"?globalThis:g||self,$(g.index={}))})(this,function(g){"use strict";var $=(e=>(e.Amazon="amazon",e.Microsoft="microsoft",e.Afflorithmics="afflorithmics",e.Elevenlabs="elevenlabs",e))($||{}),P=(e=>(e.Public="public",e.Premium="premium",e.Private="private",e))(P||{}),k=(e=>(e.Start="START",e.Stop="STOP",e))(k||{}),M=(e=>(e.ChatAnswer="chat/answer",e.ChatPartial="chat/partial",e.StreamDone="stream/done",e.StreamStarted="stream/started",e.StreamFailed="stream/error",e))(M||{}),b=(e=>(e.TRIAL="trial",e.BASIC="basic",e.ENTERPRISE="enterprise",e.LITE="lite",e.ADVANCED="advanced",e))(b||{}),K=(e=>(e.TRIAL="deid-trial",e.PRO="deid-pro",e.ENTERPRISE="deid-enterprise",e.LITE="deid-lite",e.ADVANCED="deid-advanced",e.BUILD="deid-api-build",e.LAUNCH="deid-api-launch",e.SCALE="deid-api-scale",e))(K||{}),T=(e=>(e.Unrated="Unrated",e.Positive="Positive",e.Negative="Negative",e))(T||{}),O=(e=>(e.Functional="Functional",e.TextOnly="TextOnly",e.Maintenance="Maintenance",e))(O||{}),N=(e=>(e.Embed="embed",e.Query="query",e.Partial="partial",e.Answer="answer",e.Complete="done",e))(N||{}),B=(e=>(e.KnowledgeProcessing="knowledge/processing",e.KnowledgeIndexing="knowledge/indexing",e.KnowledgeFailed="knowledge/error",e.KnowledgeDone="knowledge/done",e))(B||{}),D=(e=>(e.Knowledge="knowledge",e.Document="document",e.Record="record",e))(D||{}),W=(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))(W||{}),E=(e=>(e.Clip="clip",e.Talk="talk",e))(E||{});const _="https://api.d-id.com",q="wss://notifications.d-id.com",z=()=>Math.random().toString(16).slice(2);function J(){let e=window.localStorage.getItem("did_external_key_id");return e||(e=Math.random().toString(16).slice(2),window.localStorage.setItem("did_external_key_id",e)),e}let x=z();function H(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}.${J()}_${x}`;throw new Error(`Unknown auth type: ${e}`)}function L(e,a=_){const n=async(t,r)=>{const i=await fetch(a+(t!=null&&t.startsWith("/")?t:`/${t}`),{...r,headers:{...r==null?void 0:r.headers,Authorization:H(e),"Content-Type":"application/json"}});if(!i.ok){let o=await i.text().catch(()=>"Failed to fetch");throw new Error(o)}return i.json()};return{get(t,r){return n(t,{...r,method:"GET"})},post(t,r,i){return n(t,{...i,body:JSON.stringify(r),method:"POST"})},delete(t,r,i){return n(t,{...i,body:JSON.stringify(r),method:"DELETE"})},patch(t,r,i){return n(t,{...i,body:JSON.stringify(r),method:"PATCH"})}}}function j(e,a=_){const n=L(e,`${a}/agents`);return{create(t,r){return n.post("/",t,r)},getAgents(t,r){return n.get(`/${t?`?tag=${t}`:""}`,r).then(i=>i??[])},getById(t,r){return n.get(`/${t}`,r)},delete(t,r){return n.delete(`/${t}`,void 0,r)},update(t,r,i){return n.patch(`/${t}`,r,i)},newChat(t,r){return n.post(`/${t}/chat`,void 0,r)},chat(t,r,i,o){return n.post(`/${t}/chat/${r}`,i,o)}}}function Q(e,a=_){const n=L(e,`${a}/knowledge`);return{createKnowledge(t,r){return n.post("/",t,r)},getKnowledgeBase(t){return n.get("/",t)},getKnowledge(t,r){return n.get(`/${t}`,r)},deleteKnowledge(t,r){return n.delete(`/${t}`,void 0,r)},createDocument(t,r,i){return n.post(`/${t}/documents`,r,i)},deleteDocument(t,r,i){return n.delete(`/${t}/documents/${r}`,void 0,i)},getDocuments(t,r){return n.get(`/${t}/documents`,r)},getDocument(t,r,i){return n.get(`/${t}/documents/${r}`,i)},getRecords(t,r,i){return n.get(`/${t}/documents/${r}/records`,i)},query(t,r,i){return n.post(`/${t}/query`,{query:r},i)}}}function V(e,a=_){const n=L(e,`${a}/chats/ratings`);return{create(t,r){return n.post("/",t,r)},getByKnowledge(t,r){return n.get(`/${t}`,r).then(i=>i??[])},update(t,r,i){return n.patch(`/${t}`,r,i)},delete(t,r){return n.delete(`/${t}`,r)}}}const X=e=>new Promise(a=>setTimeout(a,e));function Y(e){return new Promise((a,n)=>{const{callbacks:t,host:r,auth:i}=e,{onMessage:o=null,onOpen:m=null,onClose:d=null,onError:h=null}=t||{},l=new WebSocket(`${r}?authorization=${H(i)}`);l.onmessage=o,l.onclose=d,l.onerror=f=>{console.error(f),h==null||h(f),n(f)},l.onopen=f=>{m==null||m(f),a(l)}})}async function Z(e){const{retries:a=1}=e;let n=null;for(let t=0;(n==null?void 0:n.readyState)!==WebSocket.OPEN;t++)try{n=await Y(e)}catch(r){if(t===a)throw r;await X(t*500)}return n}async function G(e,a,n){const t=n?[n]:[],r=await Z({auth:e,host:a,callbacks:{onMessage:i=>{const o=JSON.parse(i.data);t.forEach(m=>m(o.event,o))}}});return{socket:r,disconnect:()=>r.close(),subscribeToEvents:i=>t.push(i)}}function ee(e,a){const n=L(e,a);return{createStream(t){return n.post("/clips/streams",{driver_id:t.driver_id,presenter_id:t.presenter_id,compatibility_mode:t.compatibility_mode,idle_video_url:t==null?void 0:t.idle_video_url})},startConnection(t,r,i){return n.post(`/clips/streams/${t}/sdp`,{session_id:i,answer:r})},addIceCandidate(t,r,i){return n.post(`/clips/streams/${t}/ice`,{session_id:i,...r})},sendStreamRequest(t,r,i){return n.post(`/clips/streams/${t}`,{session_id:r,...i})},close(t,r){return n.delete(`/clips/streams/${t}`,{session_id:r})}}}function te(e,a){const n=L(e,a);return{createStream(t,r){return n.post("/talks/streams",{source_url:t.source_url,driver_url:t.driver_url,face:t.face,config:t.config},r)},startConnection(t,r,i,o){return n.post(`/talks/streams/${t}/sdp`,{session_id:i,answer:r},o)},addIceCandidate(t,r,i,o){return n.post(`/talks/streams/${t}/ice`,{session_id:i,...r},o)},sendStreamRequest(t,r,i,o){return n.post(`/talks/streams/${t}`,{session_id:r,...i},o)},close(t,r,i){return n.delete(`/talks/streams/${t}`,{session_id:r},i)}}}function ne(e,a){return e.map((n,t)=>t===0?a?{index:t,timestamp:n.timestamp,bytesReceived:n.bytesReceived-a.bytesReceived,packetsReceived:n.packetsReceived-a.packetsReceived,packetsLost:n.packetsLost-a.packetsLost,jitter:n.jitter,frameWidth:n.frameWidth,frameHeight:n.frameHeight,framesPerSecond:n.framesPerSecond}:{index:t,timestamp:n.timestamp,bytesReceived:n.bytesReceived,packetsReceived:n.packetsReceived,packetsLost:n.packetsLost,jitter:n.jitter,frameWidth:n.frameWidth,frameHeight:n.frameHeight,framesPerSecond:n.framesPerSecond}:{index:t,timestamp:n.timestamp,bytesReceived:n.bytesReceived-e[t-1].bytesReceived,packetsReceived:n.packetsReceived-e[t-1].packetsReceived,packetsLost:n.packetsLost-e[t-1].packetsLost,jitter:n.jitter,frameWidth:n.frameWidth,frameHeight:n.frameHeight,framesPerSecond:n.framesPerSecond})}let F=!1;const R=(e,a)=>F&&console.log(e,a),re=(window.RTCPeerConnection||window.webkitRTCPeerConnection||window.mozRTCPeerConnection).bind(window);function ie(e,a){let n=[],t=0,r=0,i;return setInterval(()=>{e.getStats().then(m=>{m.forEach(d=>{if(d.type==="inbound-rtp"&&d.kind==="video"){if(r=n.length-1,d&&n[r]){const h=d.bytesReceived,l=n[r].bytesReceived;let f=i;i=h-l>0;let S;if(f!==i){if(i)t=n.length;else{const w=n.slice(t),u=t===0?void 0:n[t-1];S=ne(w,u),S=S.sort((s,y)=>y.packetsLost-s.packetsLost).slice(0,5)}a==null||a(i?k.Start:k.Stop,S)}}n.push(d)}})})},500)}async function ae(e,{debug:a=!1,callbacks:n,auth:t,baseURL:r=_}){F=a;const{startConnection:i,sendStreamRequest:o,close:m,createStream:d,addIceCandidate:h}=e.videoType===E.Clip?ee(t,r):te(t,r),{id:l,offer:f,ice_servers:S,session_id:w}=await d(e),u=new re({iceServers:S}),s=u.createDataChannel("JanusDataChannel");if(!w)throw new Error("Could not create session_id");const y=ie(u,n.onVideoStateChange);u.onicecandidate=c=>{R("peerConnection.onicecandidate",c),c.candidate&&c.candidate.sdpMid&&c.candidate.sdpMLineIndex!==null&&h(l,{candidate:c.candidate.candidate,sdpMid:c.candidate.sdpMid,sdpMLineIndex:c.candidate.sdpMLineIndex},w)},u.oniceconnectionstatechange=()=>{var c;R("peerConnection.oniceconnectionstatechange => "+u.iceConnectionState),(c=n.onConnectionStateChange)==null||c.call(n,u.iceConnectionState)},u.ontrack=c=>{var p;R("peerConnection.ontrack",c),(p=n.onSrcObjectReady)==null||p.call(n,c.streams[0])},s.onmessage=c=>{var p,A;if(s.readyState==="open"){const[v,I]=c.data.split(":");v===M.StreamStarted?console.log("StreamStarted",v,I):v===M.StreamDone?console.log("StreamDone"):v===M.StreamFailed?((p=n.onVideoStateChange)==null||p.call(n,k.Stop,{event:v,data:I}),clearInterval(y),console.log("StreamFailed")):(A=n.onMessage)==null||A.call(n,v,decodeURIComponent(I))}},await u.setRemoteDescription(f),R("set remote description OK");const C=await u.createAnswer();return R("create answer OK"),await u.setLocalDescription(C),R("set local description OK"),await i(l,C,w),R("start connection OK"),{speak(c){return o(l,w,c)},async disconnect(){var c,p;l&&(u&&(u.close(),u.oniceconnectionstatechange=null,u.onnegotiationneeded=null,u.onicecandidate=null,u.ontrack=null),await m(l,w).catch(A=>{}),(c=n.onConnectionStateChange)==null||c.call(n,"closed"),(p=n.onVideoStateChange)==null||p.call(n,k.Stop),clearInterval(y))},sessionId:w,streamId:l}}function se(e,a){var n;return(n=e.knowledge)!=null&&n.id?a.getKnowledge(e.knowledge.id).then(t=>(t==null?void 0:t.starter_message)||[]):[]}function de(e){var a;return e.presenter.type===E.Clip?{videoType:E.Clip,driver_id:e.presenter.driver_id,presenter_id:e.presenter.presenter_id,idle_video_url:(a=e.presenter)==null?void 0:a.idle_video}:{videoType:E.Talk,source_url:e.presenter.source_url}}function U(e,a,n,t){return new Promise(async(r,i)=>{const o=await ae(de(e),{...a,callbacks:{...a.callbacks,onConnectionStateChange:async m=>{var d,h;if(m==="connected")try{t||(t=await n.newChat(e.id)),r({chat:t,streamingManager:o})}catch(l){console.error(l),i(new Error("Cannot create new chat"))}else m==="failed"&&i(new Error("Cannot create connection"));(h=(d=a.callbacks).onConnectionStateChange)==null||h.call(d,m)}}})})}function oe(e,a,n){return j(a,n||_).getById(e)}async function ce(e,a){var w,u;const n=a.baseURL||_,t=a.wsURL||q,r=new AbortController,i=j(a.auth,n),o=V(a.auth,n),m=Q(a.auth,n),d=typeof e=="string"?await i.getById(e):e;(u=(w=a.callbacks)==null?void 0:w.onAgentReady)==null||u.call(w,d);const h=await G(a.auth,t,a.callbacks.onChatEvents);let{chat:l,streamingManager:f}=await U(d,a,i);const S=await se(d,m);return{agent:d,chatId:l.id,starterMessages:S,async reconnect(){const{streamingManager:s}=await U(d,a,i,l);f=s},disconnect(){return r.abort(),h.disconnect(),f.disconnect()},chat(s){if(s.length===0)throw new Error("Messages cannot be empty");return s[s.length-1].created_at=new Date().toISOString(),s[s.length-1].role||(s[s.length-1].role="user"),i.chat(d.id,l.id,{sessionId:f.sessionId,streamId:f.streamId,messages:s},{signal:r.signal})},rate(s,y,C){var p,A,v;const c=((p=y.matches)==null?void 0:p.map(I=>[I.document_id,I.id]))??[];return C?o.update(C,{agent_id:d.id,knowledge_id:((A=d.knowledge)==null?void 0:A.id)??"",chat_id:l.id,score:s,matches:c}):o.create({agent_id:d.id,knowledge_id:((v=d.knowledge)==null?void 0:v.id)??"",chat_id:l.id,score:s,matches:c})},deleteRate(s){return o.delete(s)},speak(s){function y(){if(s.type==="text"){let C=d.presenter.voice;return s.provider&&(C=s.provider),{type:"text",provider:C,input:s.input,ssml:s.ssml||!1}}else if(s.type==="audio")return{type:"audio",audio_url:s.audio_url};throw new Error("Invalid payload")}return f.speak({script:y()})}}}g.ChatMode=O,g.ChatProgress=N,g.DocumentType=W,g.KnowledgeType=D,g.PlanGroup=K,g.Providers=$,g.RateState=T,g.Subject=B,g.UserPlan=b,g.VoiceAccess=P,g.createAgentManager=ce,g.getAgent=oe,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -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[]>;
|
|
@@ -11,3 +11,4 @@ export declare function createKnowledgeApi(auth: Auth, host?: string): {
|
|
|
11
11
|
getRecords(knowledgeId: string, documentId: string, options?: RequestInit): Promise<RecordData[]>;
|
|
12
12
|
query(knowledgeId: string, query: string, options?: RequestInit): Promise<QueryResult>;
|
|
13
13
|
};
|
|
14
|
+
export type KnowledegeApi = ReturnType<typeof createKnowledgeApi>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Auth, RatingEntity, RatingPayload } from '
|
|
1
|
+
import { Auth, RatingEntity, RatingPayload } from '../index';
|
|
2
2
|
export declare function createRatingsApi(auth: Auth, host?: string): {
|
|
3
3
|
create(payload: RatingPayload, options?: RequestInit): Promise<RatingEntity>;
|
|
4
4
|
getByKnowledge(knowledgeId?: string, options?: RequestInit): Promise<RatingEntity[]>;
|
|
@@ -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;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Auth } from './types/auth';
|
|
2
|
+
import { ChatProgressCallback } from '.';
|
|
3
|
+
interface SocketManager {
|
|
4
|
+
socket?: WebSocket;
|
|
5
|
+
disconnect: () => void;
|
|
6
|
+
subscribeToEvents: (data: any) => void;
|
|
7
|
+
}
|
|
8
|
+
export declare function SocketManager(auth: Auth, host: string, onMessage?: ChatProgressCallback): Promise<SocketManager>;
|
|
9
|
+
export {};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { Agent, AgentManager, AgentManagerOptions
|
|
2
|
-
|
|
1
|
+
import { Agent, AgentManager, AgentManagerOptions } from './types/index';
|
|
2
|
+
import { Auth } from '.';
|
|
3
|
+
export declare function getAgent(agentId: string, auth: Auth, baseURL?: string): Promise<Agent>;
|
|
3
4
|
/**
|
|
4
5
|
* Creates a new Agent Manager instance for interacting with an agent, chat, and related connections.
|
|
5
6
|
*
|
|
6
|
-
* @param {string}
|
|
7
|
+
* @param {string} agent - The ID or instance of the agent to chat with.
|
|
7
8
|
* @param {AgentManagerOptions} options - Configurations for the Agent Manager API.
|
|
8
9
|
* * @returns {Promise<AgentManager>} - A promise that resolves to an instance of the AgentsAPI interface.
|
|
9
10
|
*
|
|
@@ -12,4 +13,4 @@ export declare function getAgentStreamArgs(agent: Agent): CreateStreamOptions;
|
|
|
12
13
|
* @example
|
|
13
14
|
* const agentManager = await createAgentManager('id-agent123', { auth: { type: 'key', clientKey: '123', externalId: '123' } });
|
|
14
15
|
*/
|
|
15
|
-
export declare function createAgentManager(
|
|
16
|
+
export declare function createAgentManager(agent: string | Agent, options: AgentManagerOptions): Promise<AgentManager>;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { CreateStreamOptions,
|
|
1
|
+
import { CreateStreamOptions, 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
|
*/
|
|
11
|
-
|
|
11
|
+
disconnect(): Promise<void>;
|
|
12
12
|
/**
|
|
13
13
|
* Session identifier information, should be returned in the body of all streaming requests
|
|
14
14
|
*/
|
|
@@ -17,11 +17,5 @@ export declare function createStreamingManager<T extends CreateStreamOptions>(ag
|
|
|
17
17
|
* Id of current RTC stream
|
|
18
18
|
*/
|
|
19
19
|
streamId: string;
|
|
20
|
-
/**
|
|
21
|
-
* Method to add callback that will be trigered on supported events
|
|
22
|
-
* @param eventName
|
|
23
|
-
* @param callback
|
|
24
|
-
*/
|
|
25
|
-
onCallback<T_1 extends keyof ManagerCallbacks>(eventName: T_1, callback: ManagerCallbacks[T_1]): void;
|
|
26
20
|
}>;
|
|
27
21
|
export type StreamingManager<T extends CreateStreamOptions> = Awaited<ReturnType<typeof createStreamingManager<T>>>;
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,8 +1,2 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './lib/api/getClient';
|
|
3
|
-
export * from './lib/api/knowledge';
|
|
4
|
-
export * from './lib/api/ratings';
|
|
5
|
-
export * from './lib/connectToSocket';
|
|
6
|
-
export * from './lib/createAgentManager';
|
|
7
|
-
export * from './lib/createStreamingManager';
|
|
1
|
+
export * from './createAgentManager';
|
|
8
2
|
export * from './types/index';
|
|
@@ -12,7 +12,7 @@ export interface Stream_Text_Script extends BaseStreamScript {
|
|
|
12
12
|
/**
|
|
13
13
|
* text-to-speech provider from list of supported providers. default is microsoft tts
|
|
14
14
|
*/
|
|
15
|
-
provider
|
|
15
|
+
provider?: StreamTextToSpeechProviders;
|
|
16
16
|
/**
|
|
17
17
|
* The input text that will be synthesized to an audio file.
|
|
18
18
|
* Note that each provider has its own limitations on the text length.
|
package/dist/src/types/auth.d.ts
CHANGED
|
@@ -7,16 +7,14 @@ export interface BasicAuth {
|
|
|
7
7
|
username: string;
|
|
8
8
|
password: string;
|
|
9
9
|
}
|
|
10
|
-
export interface
|
|
10
|
+
export interface ClientKeyAuth {
|
|
11
11
|
type: 'key';
|
|
12
12
|
clientKey: string;
|
|
13
|
-
externalId: string;
|
|
14
13
|
}
|
|
15
|
-
export type Auth = BearerToken | BasicAuth |
|
|
14
|
+
export type Auth = BearerToken | BasicAuth | ClientKeyAuth;
|
|
16
15
|
export interface GetAuthParams {
|
|
17
16
|
token?: string | null;
|
|
18
17
|
username?: string | null;
|
|
19
18
|
password?: string | null;
|
|
20
19
|
clientKey?: string | null;
|
|
21
|
-
externalId?: string | null;
|
|
22
20
|
}
|
|
@@ -2,6 +2,23 @@ import { Chat, ChatPayload, ChatResponse } from './chat';
|
|
|
2
2
|
import { Knowledge } from './knowledge';
|
|
3
3
|
import { LLM } from './llm';
|
|
4
4
|
import { Presenter } from './presenter';
|
|
5
|
+
export declare enum UserPlan {
|
|
6
|
+
TRIAL = "trial",
|
|
7
|
+
BASIC = "basic",
|
|
8
|
+
ENTERPRISE = "enterprise",
|
|
9
|
+
LITE = "lite",
|
|
10
|
+
ADVANCED = "advanced"
|
|
11
|
+
}
|
|
12
|
+
export declare enum PlanGroup {
|
|
13
|
+
TRIAL = "deid-trial",
|
|
14
|
+
PRO = "deid-pro",
|
|
15
|
+
ENTERPRISE = "deid-enterprise",
|
|
16
|
+
LITE = "deid-lite",
|
|
17
|
+
ADVANCED = "deid-advanced",
|
|
18
|
+
BUILD = "deid-api-build",
|
|
19
|
+
LAUNCH = "deid-api-launch",
|
|
20
|
+
SCALE = "deid-api-scale"
|
|
21
|
+
}
|
|
5
22
|
export interface Agent {
|
|
6
23
|
id: string;
|
|
7
24
|
username?: string;
|
|
@@ -11,12 +28,18 @@ export interface Agent {
|
|
|
11
28
|
use_case?: string;
|
|
12
29
|
tags?: string[];
|
|
13
30
|
chats?: number;
|
|
31
|
+
greetings?: string[];
|
|
14
32
|
access?: 'private' | 'pending-public' | 'unlisted' | 'rejected' | 'public';
|
|
33
|
+
metadata?: {
|
|
34
|
+
plan: PlanGroup | UserPlan;
|
|
35
|
+
};
|
|
15
36
|
preview_name?: string;
|
|
16
37
|
preview_description?: string;
|
|
17
38
|
preview_thumbnail?: string;
|
|
39
|
+
preview_url?: string;
|
|
40
|
+
idle_video?: string;
|
|
18
41
|
}
|
|
19
|
-
export type AgentPayload = Omit<Agent, 'type' | 'created_at' | 'modified_at' | 'id' | 'owner_id' | 'idle_video_url'>;
|
|
42
|
+
export type AgentPayload = Omit<Agent, 'type' | 'created_at' | 'modified_at' | 'id' | 'owner_id' | 'metadata' | 'idle_video_url'>;
|
|
20
43
|
export interface AgentsAPI {
|
|
21
44
|
create(payload: AgentPayload, options?: RequestInit): Promise<Agent>;
|
|
22
45
|
getAgents(tag?: string, options?: RequestInit): Promise<Agent[]>;
|
|
@@ -18,9 +18,9 @@ export interface RatingEntity {
|
|
|
18
18
|
}
|
|
19
19
|
export type RatingPayload = Omit<RatingEntity, 'owner_id' | 'id' | 'created_at' | 'modified_at' | 'created_by' | 'external_id'>;
|
|
20
20
|
export interface Message {
|
|
21
|
-
role
|
|
21
|
+
role?: 'system' | 'assistant' | 'user' | 'function' | 'tool';
|
|
22
22
|
content: string;
|
|
23
|
-
created_at
|
|
23
|
+
created_at?: string;
|
|
24
24
|
matches?: ChatResponse['matches'];
|
|
25
25
|
}
|
|
26
26
|
export interface ChatPayload {
|
|
@@ -36,10 +36,16 @@ export interface IRetrivalMetadata {
|
|
|
36
36
|
knowledge_id: string;
|
|
37
37
|
source_url: string;
|
|
38
38
|
}
|
|
39
|
+
export declare enum ChatMode {
|
|
40
|
+
Functional = "Functional",
|
|
41
|
+
TextOnly = "TextOnly",
|
|
42
|
+
Maintenance = "Maintenance"
|
|
43
|
+
}
|
|
39
44
|
export interface ChatResponse {
|
|
40
45
|
result?: string;
|
|
41
46
|
documentIds?: string[];
|
|
42
47
|
matches?: IRetrivalMetadata[];
|
|
48
|
+
chatMode?: ChatMode;
|
|
43
49
|
}
|
|
44
50
|
export interface Chat {
|
|
45
51
|
id: string;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { SupportedStreamScipt } from '
|
|
1
|
+
import { SupportedStreamScipt } from '../../StreamScript';
|
|
2
2
|
import { Auth } from '../../auth';
|
|
3
|
-
import { SendStreamPayloadResponse,
|
|
3
|
+
import { SendStreamPayloadResponse, StreamingState } from '../../stream';
|
|
4
4
|
import { Agent } from './agent';
|
|
5
|
-
import { ChatResponse, Message, RatingEntity
|
|
5
|
+
import { ChatResponse, Message, RatingEntity } from './chat';
|
|
6
6
|
/**
|
|
7
7
|
* Types of events provided in Chat Progress Callback
|
|
8
8
|
*/
|
|
@@ -30,7 +30,7 @@ export declare enum ChatProgress {
|
|
|
30
30
|
}
|
|
31
31
|
export type ChatProgressCallback = (progress: ChatProgress, data: string) => void;
|
|
32
32
|
export type ConnectionStateChangeCallback = (state: RTCIceConnectionState) => void;
|
|
33
|
-
export type VideoStateChangeCallback = (state: StreamingState,
|
|
33
|
+
export type VideoStateChangeCallback = (state: StreamingState, data: any) => void;
|
|
34
34
|
interface ManagerCallbacks {
|
|
35
35
|
/**
|
|
36
36
|
* Optional callback will be triggered each time the RTC connection changes state
|
|
@@ -41,7 +41,7 @@ interface ManagerCallbacks {
|
|
|
41
41
|
* Optional callback function that will be triggered each time video events happen
|
|
42
42
|
* @param state
|
|
43
43
|
*/
|
|
44
|
-
onVideoStateChange?(state: StreamingState): void;
|
|
44
|
+
onVideoStateChange?(state: StreamingState, data?: any): void;
|
|
45
45
|
/**
|
|
46
46
|
* Callback function that will be triggered each time the video stream starts or stops to update html element on webpage
|
|
47
47
|
* Required callback for SDK
|
|
@@ -56,10 +56,16 @@ interface ManagerCallbacks {
|
|
|
56
56
|
* @param progress
|
|
57
57
|
*/
|
|
58
58
|
onChatEvents?(progress: ChatProgress, data: any): void;
|
|
59
|
+
/**
|
|
60
|
+
* Optional callback function that will be triggered when the agent is ready
|
|
61
|
+
* @param agent - Agent instance you are working with
|
|
62
|
+
*/
|
|
63
|
+
onAgentReady?(agent: Agent): void;
|
|
59
64
|
}
|
|
60
65
|
export interface AgentManagerOptions {
|
|
61
66
|
callbacks: ManagerCallbacks;
|
|
62
67
|
baseURL?: string;
|
|
68
|
+
wsURL?: string;
|
|
63
69
|
debug?: boolean;
|
|
64
70
|
auth: Auth;
|
|
65
71
|
}
|
|
@@ -69,15 +75,19 @@ export interface AgentManager {
|
|
|
69
75
|
* To know more about agents go to https://docs.d-id.com/reference/agents
|
|
70
76
|
*/
|
|
71
77
|
agent: Agent;
|
|
78
|
+
/**
|
|
79
|
+
* Array of starter messages that will be sent to the agent when the chat starts
|
|
80
|
+
*/
|
|
81
|
+
starterMessages: string[];
|
|
72
82
|
/**
|
|
73
83
|
* Method to be reconnected to chat
|
|
74
84
|
* Since chat uses an RTC connection to communicate with the agent, it could be dropped and to continue to chat you need to reconnect
|
|
75
85
|
*/
|
|
76
|
-
|
|
86
|
+
reconnect: () => Promise<void>;
|
|
77
87
|
/**
|
|
78
88
|
* Method to close all connections with agent, stream and web socket
|
|
79
89
|
*/
|
|
80
|
-
|
|
90
|
+
disconnect: () => Promise<void>;
|
|
81
91
|
/**
|
|
82
92
|
* ID of chat you are working on now
|
|
83
93
|
*/
|
|
@@ -89,10 +99,11 @@ export interface AgentManager {
|
|
|
89
99
|
chat: (messages: Message[]) => Promise<ChatResponse>;
|
|
90
100
|
/**
|
|
91
101
|
* Method to rate the answer in chat
|
|
92
|
-
* @param
|
|
102
|
+
* @param score: 1 | -1 - score of the answer. 1 for positive, -1 for negative
|
|
103
|
+
* @param matches - array of matches that were used to find the answer
|
|
93
104
|
* @param id - id of Rating entity. Leave it empty to create a new, one or pass it to work with the existing one
|
|
94
105
|
*/
|
|
95
|
-
rate: (
|
|
106
|
+
rate: (score: 1 | -1, Message: Message, id?: string) => Promise<RatingEntity>;
|
|
96
107
|
/**
|
|
97
108
|
* Method to delete rating from answer in chat
|
|
98
109
|
* @param id - id of Rating entity.
|
|
@@ -103,10 +114,5 @@ export interface AgentManager {
|
|
|
103
114
|
* @param payload
|
|
104
115
|
*/
|
|
105
116
|
speak: (payload: SupportedStreamScipt) => Promise<SendStreamPayloadResponse>;
|
|
106
|
-
/**
|
|
107
|
-
* Optional callback function that will be triggered each time any changes happen in the chat
|
|
108
|
-
* @param callback
|
|
109
|
-
*/
|
|
110
|
-
getStarterMessages: () => Promise<string[]>;
|
|
111
117
|
}
|
|
112
118
|
export {};
|
|
@@ -11,12 +11,13 @@ export declare enum StreamEvents {
|
|
|
11
11
|
ChatAnswer = "chat/answer",
|
|
12
12
|
ChatPartial = "chat/partial",
|
|
13
13
|
StreamDone = "stream/done",
|
|
14
|
-
StreamStarted = "stream/started"
|
|
14
|
+
StreamStarted = "stream/started",
|
|
15
|
+
StreamFailed = "stream/error"
|
|
15
16
|
}
|
|
16
17
|
export interface ManagerCallbacks {
|
|
17
18
|
onMessage?: (event: string, data: string) => void;
|
|
18
19
|
onConnectionStateChange?: (state: RTCIceConnectionState) => void;
|
|
19
|
-
onVideoStateChange?: (state: StreamingState,
|
|
20
|
+
onVideoStateChange?: (state: StreamingState, data?: any) => void;
|
|
20
21
|
onSrcObjectReady?: (value: MediaStream) => void;
|
|
21
22
|
}
|
|
22
23
|
export type ManagerCallbackKeys = keyof ManagerCallbacks;
|
|
@@ -25,6 +26,7 @@ export interface TalkStreamOptions extends CreateTalkStreamRequest {
|
|
|
25
26
|
}
|
|
26
27
|
export interface ClipStreamOptions extends CreateClipStreamRequest {
|
|
27
28
|
videoType: VideoType.Clip;
|
|
29
|
+
idle_video_url?: string;
|
|
28
30
|
}
|
|
29
31
|
export type CreateStreamOptions = TalkStreamOptions | ClipStreamOptions;
|
|
30
32
|
export type PayloadType<T> = T extends TalkStreamOptions ? SendTalkStreamPayload : T extends ClipStreamOptions ? SendClipStreamPayload : never;
|
|
@@ -50,5 +52,5 @@ export interface SlimRTCStatsReport {
|
|
|
50
52
|
jitter: any;
|
|
51
53
|
frameWidth: any;
|
|
52
54
|
frameHeight: any;
|
|
53
|
-
|
|
55
|
+
framesPerSecond: any;
|
|
54
56
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { SlimRTCStatsReport } from
|
|
1
|
+
import { SlimRTCStatsReport } from '../types';
|
|
2
2
|
export declare function createVideoStatsReport(stats: SlimRTCStatsReport[], previousStats?: SlimRTCStatsReport): SlimRTCStatsReport[];
|
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.
|
|
4
|
+
"version": "1.0.29-beta.55",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "d-id client sdk",
|
|
7
7
|
"repository": {
|
|
@@ -25,24 +25,23 @@
|
|
|
25
25
|
"dev": "vite",
|
|
26
26
|
"build": "node ./infra/build.js -m production",
|
|
27
27
|
"build:dev": "node ./infra/build.js -m development",
|
|
28
|
-
"deploy:prod": "node ./infra/deploy.js --version
|
|
28
|
+
"deploy:prod": "node ./infra/deploy.js --version beta",
|
|
29
29
|
"preview": "vite preview",
|
|
30
30
|
"test-build": "node .infra/build.js -m development",
|
|
31
31
|
"build:docs": "typedoc"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@preact/preset-vite": "^2.
|
|
34
|
+
"@preact/preset-vite": "^2.8.1",
|
|
35
35
|
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
|
|
36
|
+
"@types/node": "^20.11.24",
|
|
36
37
|
"commander": "^11.1.0",
|
|
37
38
|
"glob": "^10.3.10",
|
|
38
|
-
"preact": "^10.
|
|
39
|
-
"prettier": "^3.
|
|
39
|
+
"preact": "^10.19.6",
|
|
40
|
+
"prettier": "^3.2.5",
|
|
40
41
|
"prettier-plugin-organize-imports": "^3.2.4",
|
|
41
|
-
"serverless": "3.32.2",
|
|
42
42
|
"typedoc": "^0.25.7",
|
|
43
|
-
"typescript": "^5.3.
|
|
44
|
-
"vite": "^
|
|
45
|
-
"vite-plugin-dts": "^3.
|
|
46
|
-
"vite-plugin-html-env": "^1.2.8"
|
|
43
|
+
"typescript": "^5.3.3",
|
|
44
|
+
"vite": "^5.1.4",
|
|
45
|
+
"vite-plugin-dts": "^3.7.3"
|
|
47
46
|
}
|
|
48
47
|
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Auth } from '../types/auth';
|
|
2
|
-
import { ChatProgressCallback } from '..';
|
|
3
|
-
interface SocketManager {
|
|
4
|
-
socket?: WebSocket;
|
|
5
|
-
terminate: () => void;
|
|
6
|
-
subscribeToEvents: (data: any) => void;
|
|
7
|
-
}
|
|
8
|
-
export declare function SocketManager(auth: Auth, onMessage?: ChatProgressCallback, host?: string): Promise<SocketManager>;
|
|
9
|
-
export {};
|