@d-id/client-sdk 0.0.2 → 1.0.0-beta.74
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 +664 -254
- package/dist/index.umd.cjs +1 -1
- package/dist/{lib → src}/api/agents.d.ts +4 -1
- package/dist/src/api/clipStream.d.ts +2 -0
- package/dist/{lib → src}/api/getClient.d.ts +1 -1
- package/dist/{lib → src}/api/knowledge.d.ts +2 -1
- package/dist/src/api/talkStream.d.ts +2 -0
- package/dist/src/auth/getAuthHeader.d.ts +4 -0
- package/dist/src/connectToSocket.d.ts +11 -0
- package/dist/src/createAgentManager.d.ts +16 -0
- package/dist/src/createStreamingManager.d.ts +21 -0
- package/dist/src/environment.d.ts +6 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/services/mixpanel.d.ts +18 -0
- package/dist/{types → src/types}/StreamScript.d.ts +2 -1
- package/dist/{types → src/types}/auth.d.ts +2 -4
- package/dist/src/types/entities/agents/agent.d.ts +51 -0
- package/dist/src/types/entities/agents/chat.d.ts +63 -0
- package/dist/{types → src/types}/entities/agents/knowledge.d.ts +1 -0
- package/dist/src/types/entities/agents/manager.d.ts +135 -0
- package/dist/{types → src/types}/index.d.ts +2 -3
- package/dist/{types → src/types}/stream/api/clip.d.ts +6 -0
- package/dist/{types → src/types}/stream/api/talk.d.ts +2 -1
- package/dist/{types → src/types}/stream/rtc.d.ts +3 -3
- package/dist/{types → src/types}/stream/stream.d.ts +37 -2
- package/dist/src/utils/analytics.d.ts +12 -0
- package/dist/src/utils/webrtc.d.ts +2 -0
- package/package.json +13 -12
- package/dist/lib/api/clipStream.d.ts +0 -2
- package/dist/lib/api/talkStream.d.ts +0 -2
- package/dist/lib/auth/getAuthHeader.d.ts +0 -2
- package/dist/lib/connectToSocket.d.ts +0 -14
- package/dist/lib/createAgentManager.d.ts +0 -9
- package/dist/lib/createStreamingManager.d.ts +0 -8
- package/dist/lib/index.d.ts +0 -6
- package/dist/types/entities/agents/agent.d.ts +0 -18
- package/dist/types/entities/agents/chat.d.ts +0 -34
- package/dist/types/entities/agents/manager.d.ts +0 -21
- /package/dist/{types → src/types}/entities/agents/index.d.ts +0 -0
- /package/dist/{types → src/types}/entities/agents/llm.d.ts +0 -0
- /package/dist/{types → src/types}/entities/agents/presenter.d.ts +0 -0
- /package/dist/{types → src/types}/entities/index.d.ts +0 -0
- /package/dist/{types → src/types}/entities/knowledge/document.d.ts +0 -0
- /package/dist/{types → src/types}/entities/knowledge/index.d.ts +0 -0
- /package/dist/{types → src/types}/entities/knowledge/knowledge.d.ts +0 -0
- /package/dist/{types → src/types}/entities/knowledge/record.d.ts +0 -0
- /package/dist/{types → src/types}/entities/knowledge/retrival.d.ts +0 -0
- /package/dist/{types → src/types}/entities/video.d.ts +0 -0
- /package/dist/{types → src/types}/stream/api/index.d.ts +0 -0
- /package/dist/{types → src/types}/stream/index.d.ts +0 -0
- /package/dist/{types → src/types}/tts.d.ts +0 -0
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(u,w){typeof exports=="object"&&typeof module<"u"?w(exports):typeof define=="function"&&define.amd?define(["exports"],w):(u=typeof globalThis<"u"?globalThis:u||self,w(u.index={}))})(this,function(u){"use strict";function w(r){return r.type==="bearer"?"Bearer "+r.token:r.type==="basic"?"Basic "+btoa(`${r.username}:${r.password}`):"Client-Key "+r.clientKey}function h(r,i="https://api.d-id.com"){const n=async(e,t)=>{const o=await fetch(i+(e!=null&&e.startsWith("/")?e:`/${e}`),{...t,headers:{...t==null?void 0:t.headers,Authorization:w(r),"Content-Type":"application/json"}});if(!o.ok){let a=await o.text().catch(()=>"Failed to fetch");throw new Error(a)}return o.json()};return{get(e,t){return n(e,{...t,method:"GET"})},post(e,t,o){return n(e,{...o,body:JSON.stringify(t),method:"POST"})},delete(e,t,o){return n(e,{...o,body:JSON.stringify(t),method:"DELETE"})},patch(e,t,o){return n(e,{...o,body:JSON.stringify(t),method:"PATCH"})}}}function _(r,i="https://api.d-id.com"){const n=h(r,`${i}/agents`);return{create(e,t){return n.post("/",e,t)},getAgents(e,t){return n.get(`/${e?`?tag=${e}`:""}`,t).then(o=>o??[])},getById(e,t){return n.get(`/${e}`,t)},delete(e,t){return n.delete(`/${e}`,void 0,t)},update(e,t,o){return n.patch(`/${e}`,t,o)},newChat(e,t){return n.post(`/${e}/chat`,void 0,t)},chat(e,t,o,a){return n.post(`/${e}/chat/${t}`,o,a)}}}function I(r,i="https://api.d-id.com"){const n=h(r,`${i}/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,o){return n.post(`/${e}/documents`,t,o)},deleteDocument(e,t,o){return n.delete(`/${e}/documents/${t}`,void 0,o)},getDocuments(e,t){return n.get(`/${e}/documents`,t)},getDocument(e,t,o){return n.get(`/${e}/documents/${t}`,o)},getRecords(e,t,o){return n.get(`/${e}/documents/${t}/records`,o)},query(e,t,o){return n.post(`/${e}/query`,{query:t},o)}}}function M(r){if(r.type==="bearer")return`Bearer ${r.token}`;if(r.type==="basic")return`Basic ${btoa(`${r.username}:${r.password}`)}`;if(r.type==="key")return`Client-Key ${r.clientKey}`;throw new Error(`Unknown auth type: ${r}`)}const P=r=>new Promise(i=>setTimeout(i,r));function D(r){return new Promise((i,n)=>{const{callbacks:e,host:t,auth:o}=r,{onMessage:a,onOpen:m,onClose:S=null,onError:C}=e,c=new WebSocket(`${t}?authorization=${M(o)}`);c.onmessage=a,c.onclose=S,c.onerror=f=>{console.log(f),C==null||C(f),n(f)},c.onopen=f=>{m==null||m(f),i(c)}})}async function O(r){const{retries:i=1}=r;let n=null;for(let e=0;(n==null?void 0:n.readyState)!==WebSocket.OPEN;e++)try{n=await D(r)}catch(t){if(e===i)throw t;await P(e*500)}return n}var $=(r=>(r.Start="START",r.Stop="STOP",r))($||{}),y=(r=>(r.Clip="clip",r.Talk="talk",r))(y||{});function A(r){return r.presenter.type===y.Clip?{videoType:y.Clip,driver_id:r.presenter.driver_id,presenter_id:r.presenter.presenter_id}:{videoType:y.Talk,source_url:r.presenter.source_url}}async function j(r,{callbacks:i,...n}){const e=new AbortController,t=_(n.auth,n.baseURL),o=await t.getById(r),a=await t.newChat(r),{terminate:m,sessionId:S,streamId:C}=await K(A(o),{...n,callbacks:{onSrcObjectReady:i.onSrcObjectReady,onVideoStateChange:i==null?void 0:i.onVideoStateChange,onConnectionStateChange:i.onConnectionStateChange}});return{agent:o,terminate(){return e.abort(),m()},chatId:a.id,chat(c){return t.chat(r,a.id,{sessionId:S,streamId:C,messages:c},{signal:e.signal})}}}function B(r,i){const n=h(r,i);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,o){return n.post(`/clips/streams/${e}/sdp`,{session_id:o,answer:t})},addIceCandidate(e,t,o){return n.post(`/clips/streams/${e}/ice`,{session_id:o,...t})},sendStreamRequest(e,t,o){return n.post(`/clips/streams/${e}`,{session_id:t,...o})},close(e,t){return n.delete(`/clips/streams/${e}`,{session_id:t})}}}function E(r,i){const n=h(r,i);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,o,a){return n.post(`/talks/streams/${e}/sdp`,{session_id:o,answer:t},a)},addIceCandidate(e,t,o,a){return n.post(`/talks/streams/${e}/ice`,{session_id:o,...t},a)},sendStreamRequest(e,t,o,a){return n.post(`/talks/streams/${e}`,{session_id:t,...o},a)},close(e,t,o){return n.delete(`/talks/streams/${e}`,{session_id:t},o)}}}let T=!1;const g=(r,i)=>T&&console.log(r,i),q=(window.RTCPeerConnection||window.webkitRTCPeerConnection||window.mozRTCPeerConnection).bind(window);async function K(r,{debug:i=!1,callbacks:n,auth:e,baseURL:t="https://api.d-id.com"}){T=i;const{startConnection:o,sendStreamRequest:a,close:m,createStream:S,addIceCandidate:C}=r.videoType===y.Clip?B(e,t):E(e,t),{id:c,offer:f,ice_servers:L,session_id:l}=await S(r),d=new q({iceServers:L}),R=d.createDataChannel("JanusDataChannel");if(!l)throw new Error("Could not create session_id");d.onicecandidate=s=>{g("peerConnection.onicecandidate",s),s.candidate&&s.candidate.sdpMid&&s.candidate.sdpMLineIndex!==null&&C(c,{candidate:s.candidate.candidate,sdpMid:s.candidate.sdpMid,sdpMLineIndex:s.candidate.sdpMLineIndex},l)},d.oniceconnectionstatechange=()=>{var s;g("peerConnection.oniceconnectionstatechange => "+d.iceConnectionState),(s=n.onConnectionStateChange)==null||s.call(n,d.iceConnectionState)},d.ontrack=s=>{var p;g("peerConnection.ontrack",s),(p=n.onSrcObjectReady)==null||p.call(n,s.streams[0])},R.onmessage=s=>{var p;R.readyState==="open"&&((p=n.onVideoStateChange)==null||p.call(n,s.data==="stream/done"?$.Stop:$.Start))},await d.setRemoteDescription(f),g("set remote description OK");const v=await d.createAnswer();return g("create answer OK"),await d.setLocalDescription(v),g("set local description OK"),await o(c,v,l),g("start connection OK"),{speak(s){return a(c,l,s)},async terminate(){var s,p;c&&(d&&(d.close(),d.oniceconnectionstatechange=null,d.onnegotiationneeded=null,d.onicecandidate=null,d.ontrack=null),await m(c,l),(s=n.onConnectionStateChange)==null||s.call(n,"closed"),(p=n.onVideoStateChange)==null||p.call(n,$.Stop))},sessionId:l,streamId:c}}u.connectToSocket=O,u.createAgentManager=j,u.createAgentsApi=_,u.createClient=h,u.createKnowledgeApi=I,u.createStreamingManager=K,u.getAgentStreamArgs=A,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(w,L){typeof exports=="object"&&typeof module<"u"?L(exports):typeof define=="function"&&define.amd?define(["exports"],L):(w=typeof globalThis<"u"?globalThis:w||self,L(w.index={}))})(this,function(w){"use strict";var L=(e=>(e.TRIAL="trial",e.BASIC="basic",e.ENTERPRISE="enterprise",e.LITE="lite",e.ADVANCED="advanced",e))(L||{}),W=(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))(W||{}),z=(e=>(e.Unrated="Unrated",e.Positive="Positive",e.Negative="Negative",e))(z||{}),E=(e=>(e.Functional="Functional",e.TextOnly="TextOnly",e.Maintenance="Maintenance",e))(E||{}),O=(e=>(e.Embed="embed",e.Query="query",e.Partial="partial",e.Answer="answer",e.Complete="done",e))(O||{}),H=(e=>(e.KnowledgeProcessing="knowledge/processing",e.KnowledgeIndexing="knowledge/indexing",e.KnowledgeFailed="knowledge/error",e.KnowledgeDone="knowledge/done",e))(H||{}),j=(e=>(e.Knowledge="knowledge",e.Document="document",e.Record="record",e))(j||{}),U=(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))(U||{}),S=(e=>(e.Clip="clip",e.Talk="talk",e))(S||{}),P=(e=>(e.Start="START",e.Stop="STOP",e))(P||{}),I=(e=>(e.ChatAnswer="chat/answer",e.ChatPartial="chat/partial",e.StreamDone="stream/done",e.StreamStarted="stream/started",e.StreamFailed="stream/error",e.StreamReady="stream/ready",e.StreamCreated="stream/created",e.StreamVideoCreated="stream-video/started",e.StreamVideoDone="stream-video/done",e.StreamVideoError="stream-video/error",e.StreamVideoRejected="stream-video/rejected",e))(I||{}),y=(e=>(e[e.New=0]="New",e[e.Fail=1]="Fail",e[e.Connected=2]="Connected",e[e.Connecting=3]="Connecting",e[e.Terminating=4]="Terminating",e))(y||{}),V=(e=>(e.Amazon="amazon",e.Microsoft="microsoft",e.Afflorithmics="afflorithmics",e.Elevenlabs="elevenlabs",e))(V||{}),B=(e=>(e.Public="public",e.Premium="premium",e.Private="private",e))(B||{});const K="https://api.d-id.com",G="wss://notifications.d-id.com",ee="79f81a83a67430be2bc0fd61042b8faa",x=()=>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 te=x();function q(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()}_${te}`;throw new Error(`Unknown auth type: ${e}`)}function D(e,a=K){const t=async(n,r)=>{const i=await fetch(a+(n!=null&&n.startsWith("/")?n:`/${n}`),{...r,headers:{...r==null?void 0:r.headers,Authorization:q(e),"Content-Type":"application/json"}});if(!i.ok){let d=await i.text().catch(()=>"Failed to fetch");throw new Error(d)}return i.json()};return{get(n,r){return t(n,{...r,method:"GET"})},post(n,r,i){return t(n,{...i,body:JSON.stringify(r),method:"POST"})},delete(n,r,i){return t(n,{...i,body:JSON.stringify(r),method:"DELETE"})},patch(n,r,i){return t(n,{...i,body:JSON.stringify(r),method:"PATCH"})}}}function Q(e,a=K){const t=D(e,`${a}/agents`);return{create(n,r){return t.post("/",n,r)},getAgents(n,r){return t.get(`/${n?`?tag=${n}`:""}`,r).then(i=>i??[])},getById(n,r){return t.get(`/${n}`,r)},delete(n,r){return t.delete(`/${n}`,void 0,r)},update(n,r,i){return t.patch(`/${n}`,r,i)},newChat(n,r){return t.post(`/${n}/chat`,void 0,r)},chat(n,r,i,d){return t.post(`/${n}/chat/${r}`,i,d)},createRating(n,r,i,d){return t.post(`/${n}/chat/${r}/ratings`,i,d)},updateRating(n,r,i,d,g){return t.patch(`/${n}/chat/${r}/ratings/${i}`,d,g)},deleteRating(n,r,i,d){return t.delete(`/${n}/chat/${r}/ratings/${i}`,d)}}}const ne=e=>new Promise(a=>setTimeout(a,e));function re(e){return new Promise((a,t)=>{const{callbacks:n,host:r,auth:i}=e,{onMessage:d=null,onOpen:g=null,onClose:c=null,onError:l=null}=n||{},f=new WebSocket(`${r}?authorization=${q(i)}`);f.onmessage=d,f.onclose=c,f.onerror=p=>{console.error(p),l==null||l("Websocket failed to connect",p),t(p)},f.onopen=p=>{g==null||g(p),a(f)}})}async function ie(e){const{retries:a=1}=e;let t=null;for(let n=0;(t==null?void 0:t.readyState)!==WebSocket.OPEN;n++)try{t=await re(e)}catch(r){if(n===a)throw r;await ne(n*500)}return t}async function X(e,a,t){const n=t!=null&&t.onMessage?[t.onMessage]:[],r=await ie({auth:e,host:a,callbacks:{onError:t==null?void 0:t.onError,onMessage:i=>{const d=JSON.parse(i.data);n.forEach(g=>g(d.event,d))}}});return{socket:r,disconnect:()=>r.close(),subscribeToEvents:i=>n.push(i)}}function ae(e,a,t){const n=D(e,`${a}/agents/${t}`);return{createStream(r){return n.post("/streams",{driver_id:r.driver_id,presenter_id:r.presenter_id,compatibility_mode:r.compatibility_mode,stream_warmup:r.stream_warmup,type:S.Clip})},startConnection(r,i,d){return n.post(`/streams/${r}/sdp`,{session_id:d,answer:i,type:S.Clip})},addIceCandidate(r,i,d){return n.post(`/streams/${r}/ice`,{session_id:d,...i,type:S.Clip})},sendStreamRequest(r,i,d){return n.post(`/streams/${r}`,{session_id:i,...d,type:S.Clip})},close(r,i){return n.delete(`/streams/${r}`,{session_id:i,type:S.Clip})}}}function se(e,a,t){const n=D(e,`${a}/agents/${t}`);return{createStream(r,i){return n.post("/streams",{source_url:r.source_url,driver_url:r.driver_url,face:r.face,config:r.config,stream_warmup:r.stream_warmup,type:S.Talk},i)},startConnection(r,i,d,g){return n.post(`/streams/${r}/sdp`,{session_id:d,answer:i,type:S.Talk},g)},addIceCandidate(r,i,d,g){return n.post(`/streams/${r}/ice`,{session_id:d,...i,type:S.Talk},g)},sendStreamRequest(r,i,d,g){return n.post(`/streams/${r}`,{session_id:i,...d,type:S.Talk},g)},close(r,i,d){return n.delete(`/streams/${r}`,{session_id:i,type:S.Talk},d)}}}function oe(e,a){return e.map((t,n)=>n===0?a?{index:n,timestamp:t.timestamp,bytesReceived:t.bytesReceived-a.bytesReceived,packetsReceived:t.packetsReceived-a.packetsReceived,packetsLost:t.packetsLost-a.packetsLost,jitter:t.jitter,frameWidth:t.frameWidth,frameHeight:t.frameHeight,framesPerSecond:t.framesPerSecond}:{index:n,timestamp:t.timestamp,bytesReceived:t.bytesReceived,packetsReceived:t.packetsReceived,packetsLost:t.packetsLost,jitter:t.jitter,frameWidth:t.frameWidth,frameHeight:t.frameHeight,framesPerSecond:t.framesPerSecond}:{index:n,timestamp:t.timestamp,bytesReceived:t.bytesReceived-e[n-1].bytesReceived,packetsReceived:t.packetsReceived-e[n-1].packetsReceived,packetsLost:t.packetsLost-e[n-1].packetsLost,jitter:t.jitter,frameWidth:t.frameWidth,frameHeight:t.frameHeight,framesPerSecond:t.framesPerSecond})}let Y=!1;const T=(e,a)=>Y&&console.log(e,a),de=(window.RTCPeerConnection||window.webkitRTCPeerConnection||window.mozRTCPeerConnection).bind(window);function ce(e){switch(e){case"connected":return y.Connected;case"checking":return y.Connecting;case"failed":return y.Fail;case"new":case"closed":case"disconnected":default:return y.New}}function ge(e,a){let t=[],n=0,r=0,i;return setInterval(()=>{e.getStats().then(g=>{g.forEach(c=>{if(c.type==="inbound-rtp"&&c.kind==="video"){if(r=t.length-1,c&&t[r]){const l=c.bytesReceived,f=t[r].bytesReceived;let p=i;i=l-f>0;let M;if(p!==i){if(i)n=t.length;else{const _=t.slice(n),b=n===0?void 0:t[n-1];M=oe(_,b),M=M.sort((N,R)=>R.packetsLost-N.packetsLost).slice(0,5)}a==null||a(i?P.Start:P.Stop,M)}}t.push(c)}})})},500)}async function me(e,a,{debug:t=!1,callbacks:n,auth:r,analytics:i,baseURL:d=K}){Y=t;let g;const{startConnection:c,sendStreamRequest:l,close:f,createStream:p,addIceCandidate:M}=a.videoType===S.Clip?ae(r,d,e):se(r,d,e),{id:_,offer:b,ice_servers:N,session_id:R}=await p(a),s=new de({iceServers:N}),u=s.createDataChannel("JanusDataChannel");if(!R)throw new Error("Could not create session_id");const m=ge(s,n.onVideoStateChange);s.onicecandidate=o=>{T("peerConnection.onicecandidate",o),o.candidate&&o.candidate.sdpMid&&o.candidate.sdpMLineIndex!==null?M(_,{candidate:o.candidate.candidate,sdpMid:o.candidate.sdpMid,sdpMLineIndex:o.candidate.sdpMLineIndex},R):M(_,{candidate:null},R)},s.oniceconnectionstatechange=()=>{var h;T("peerConnection.oniceconnectionstatechange => "+s.iceConnectionState);const o=ce(s.iceConnectionState);o===y.Connected?g=setTimeout(()=>{var k;(k=n.onConnectionStateChange)==null||k.call(n,y.Connected)},5e3):(clearTimeout(g),(h=n.onConnectionStateChange)==null||h.call(n,o))},s.ontrack=o=>{var h;T("peerConnection.ontrack",o),(h=n.onSrcObjectReady)==null||h.call(n,o.streams[0])},u.onmessage=o=>{var h,k;if(u.readyState==="open"){const[C,A]=o.data.split(":");C===I.StreamStarted?i==null||i.track("agent-video",{event:"start",...o}):C===I.StreamDone?i==null||i.track("agent-video",{event:"stop",...o}):C===I.StreamFailed?((h=n.onVideoStateChange)==null||h.call(n,P.Stop,{event:C,data:A}),clearInterval(m)):C===I.StreamReady?(clearTimeout(g),(k=n.onConnectionStateChange)==null||k.call(n,y.Connected)):C===I.StreamCreated?i==null||i.track("agent-video",{event:"created",...o}):C===I.StreamVideoCreated?i==null||i.track("agent-video",{event:"video-created",...o}):C===I.StreamVideoDone?i==null||i.track("agent-video",{event:"video-done",...o}):C===I.StreamVideoError&&(i==null||i.track("agent-video",{event:"video-error",...o}))}},await s.setRemoteDescription(b),T("set remote description OK");const v=await s.createAnswer();return T("create answer OK"),await s.setLocalDescription(v),T("set local description OK"),await c(_,v,R),T("start connection OK"),{speak(o){return l(_,R,o)},async disconnect(){var o,h;_&&(s&&(s.close(),s.oniceconnectionstatechange=null,s.onnegotiationneeded=null,s.onicecandidate=null,s.ontrack=null),await f(_,R).catch(k=>{}),(o=n.onConnectionStateChange)==null||o.call(n,y.New),(h=n.onVideoStateChange)==null||h.call(n,P.Stop),clearInterval(m))},sessionId:R,streamId:_}}function le(e){const a={mixPanelKey:e.mixPanelKey||"testKey",distinct_id:e.distinctId||J(),isEnabled:e.isEnabled??!0,agentId:e.agent.id,owner_id:e.agent.owner_id??""};return{...a,getRandom:()=>Math.random().toString(16).slice(2),track(t,n){if(!this.isEnabled)return Promise.reject("MixPanel analytics is disabled on creation");const r={method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({data:JSON.stringify([{event:t,properties:{...n,...a,time:Date.now(),$insert_id:this.getRandom(),origin:window.location.href,"Screen Height":window.screen.height||window.innerWidth,"Screen Width":window.screen.width||window.innerHeight,"User Agent":navigator.userAgent}}])})};return fetch("https://api-js.mixpanel.com/track/?verbose=1&ip=1",r).then(i=>i.json()).catch(i=>console.error(i))}}}function ue(e){var n,r,i,d,g;const a=()=>/Mobi|Android/i.test(navigator.userAgent)?"Mobile":"Desktop";return{$os:`${(()=>{const c=navigator.platform;return c.toLowerCase().includes("win")?"Windows":c.toLowerCase().includes("mac")?"Mac OS X":c.toLowerCase().includes("linux")?"Linux":"Unknown"})()}`,isMobile:`${a()=="Mobile"}`,browser:navigator.userAgent,origin:window.location.origin,agentType:(n=e.presenter)==null?void 0:n.type,agentVoice:{voiceId:(i=(r=e.presenter)==null?void 0:r.voice)==null?void 0:i.voice_id,provider:(g=(d=e.presenter)==null?void 0:d.voice)==null?void 0:g.type}}}function he(e){if(e.presenter){if(e.presenter.type===S.Clip)return{videoType:S.Clip,driver_id:e.presenter.driver_id,presenter_id:e.presenter.presenter_id,stream_warmup:!0}}else throw new Error("Presenter is not initialized");return{videoType:S.Talk,source_url:e.presenter.source_url,stream_warmup:!0}}function Z(e,a,t,n,r){return new Promise(async(i,d)=>{let g=r;const c=await me(e.id,he(e),{...a,callbacks:{...a.callbacks,onConnectionStateChange:async l=>{var f,p;if(l===y.Connected)try{g||(g=await t.newChat(e.id),n.track("agent-chat",{event:"created",chat_id:g.id,agent_id:e.id})),c&&i({chat:g,streamingManager:c})}catch(M){console.error(M),d("Cannot create new chat")}else l===y.Fail&&d(new Error("Cannot create connection"));(p=(f=a.callbacks).onConnectionStateChange)==null||p.call(f,l)},onVideoStateChange(l,f){var p,M;n.track("agent-video",{event:l,rtc_stats:f??[]}),(M=(p=a.callbacks).onVideoStateChange)==null||M.call(p,l,f)}}}).catch(d)})}function we(e,a,t){return Q(a,t||K).getById(e)}function F(e){let a="";if(e.greetings&&e.greetings.length>0){const t=Math.floor(Math.random()*e.greetings.length);a=e.greetings[t]}else a=`Hi! I'm ${e.preview_name}, welcome to agents. How can I help you?`;return[{content:a,id:x(),role:"assistant",created_at:new Date().toISOString()}]}async function fe(e,a){var b,N,R;const t={messages:[],chatMode:a.mode||E.Functional};let n=-1;const r=a.wsURL||G,i=a.baseURL||K,d=a.mixpanelKey||ee,g=Q(a.auth,i),c=await g.getById(e);t.messages=F(c),(N=(b=a.callbacks).onNewMessage)==null||N.call(b,t.messages);const l=le({mixPanelKey:d,agent:c,...a});l.track("agent-sdk",{event:"loaded",...ue(c)});const f={onMessage:(s,u)=>{var m,v;if("content"in u){const{content:o}=u,h=t.messages[t.messages.length-1];(h==null?void 0:h.role)==="assistant"&&(n<t.messages.length&&(h.content=s===O.Partial?h.content+o:o),s===O.Answer&&(n=t.messages.length)),s===O.Complete&&l.track("agent-message-received",{messages:t.messages.length}),(v=(m=a.callbacks).onNewMessage)==null||v.call(m,t.messages)}}};async function p(){var v,o,h,k,C;const s=await X(a.auth,r,f),{streamingManager:u,chat:m}=await Z(c,a,g,l,t.chat);n=-1,t.messages=F(c),(o=(v=a.callbacks).onNewMessage)==null||o.call(v,t.messages),m!=null&&m.id&&m.id!==((h=t.chat)==null?void 0:h.id)&&((C=(k=a.callbacks).onNewChat)==null||C.call(k,m==null?void 0:m.id)),t.streamingManager=u,t.socketManager=s,t.chat=m,_(E.Functional),l.track("agent-chat",{event:"connect",chatId:m.id,agentId:c.id})}async function M(){var s,u,m,v,o;(s=t.socketManager)==null||s.disconnect(),await((u=t.streamingManager)==null?void 0:u.disconnect()),delete t.streamingManager,delete t.socketManager,t.messages=F(c),(v=(m=a.callbacks).onNewMessage)==null||v.call(m,t.messages),l.track("agent-chat",{event:"disconnect",chatId:(o=t.chat)==null?void 0:o.id,agentId:c.id})}async function _(s){var u,m;s!==t.chatMode&&(l.track("agent-mode-change",{mode:s}),t.chatMode=s,t.chatMode!==E.Functional&&await M(),(m=(u=a.callbacks).onModeChange)==null||m.call(u,s))}return{agent:c,starterMessages:((R=c.knowledge)==null?void 0:R.starter_message)||[],connect:p,disconnect:M,changeMode:_,async reconnect(){if(!t.chat)return p();const s=await X(a.auth,r,f),{streamingManager:u,chat:m}=await Z(c,a,g,l,t.chat);t.streamingManager=u,t.socketManager=s,_(E.Functional),l.track("agent-chat",{event:"reconnect",chatId:m.id,agentId:c.id})},async chat(s,u=!1){var m,v,o,h,k,C;try{const A=Date.now();if(t.messages.push({id:x(),role:"user",content:s,created_at:new Date(A).toISOString()}),(v=(m=a.callbacks).onNewMessage)==null||v.call(m,t.messages),s.length===0)throw new Error("Message cannot be empty");if(t.chatMode===E.Maintenance)throw new Error("Chat is in maintenance mode");if(t.chatMode!==E.TextOnly){if(!t.streamingManager)throw new Error("Streaming manager is not initialized");if(!t.chat)throw new Error("Chat is not initialized")}else t.chat||(t.chat=await g.newChat(c.id));const $=await g.chat(c.id,t.chat.id,{sessionId:(o=t.streamingManager)==null?void 0:o.sessionId,streamId:(h=t.streamingManager)==null?void 0:h.streamId,messages:t.messages,chatMode:t.chatMode,append_chat:u});return l.track("agent-message-send",{event:"success",messages:t.messages.length+1}),t.messages.push({id:x(),role:"assistant",content:$.result??"",created_at:new Date().toISOString(),matches:$.matches}),$.result&&l.track("agent-message-received",{latency:Date.now()-A,messages:t.messages.length}),(C=(k=a.callbacks).onNewMessage)==null||C.call(k,t.messages),$}catch(A){throw l.track("agent-message-send",{event:"error",messages:t.messages.length}),A}},rate(s,u,m){var h,k,C,A;const v=t.messages.find($=>$.id===s);if(t.chat){if(!v)throw new Error("Message not found")}else throw new Error("Chat is not initialized");const o=((h=v.matches)==null?void 0:h.map($=>[$.document_id,$.id]))??[];return l.track("agent-rate",{event:m?"update":"create",thumb:u===1?"up":"down",knowledge_id:((k=c.knowledge)==null?void 0:k.id)??"",matches:o,score:u}),m?g.updateRating(c.id,t.chat.id,m,{knowledge_id:((C=c.knowledge)==null?void 0:C.id)??"",message_id:s,matches:o,score:u}):g.createRating(c.id,t.chat.id,{knowledge_id:((A=c.knowledge)==null?void 0:A.id)??"",message_id:s,matches:o,score:u})},deleteRate(s){var u;if(!t.chat)throw new Error("Chat is not initialized");return l.track("agent-rate-delete",{type:"text",chat_id:(u=t.chat)==null?void 0:u.id,id:s}),g.deleteRating(c.id,t.chat.id,s)},speak(s){if(!t.streamingManager)throw new Error("Streaming manager is not initialized");function u(){if(c.presenter){if(s.type==="text")return{type:"text",provider:s.provider?s.provider:c.presenter.voice,input:s.input,ssml:s.ssml||!1};if(s.type==="audio")return{type:"audio",audio_url:s.audio_url}}else throw new Error("Presenter is not initialized");throw new Error("Invalid payload")}const m=u();return l.track("agent-speak",m),t.streamingManager.speak({script:m})}}}w.ChatMode=E,w.ChatProgress=O,w.ConnectionState=y,w.DocumentType=U,w.KnowledgeType=j,w.PlanGroup=W,w.Providers=V,w.RateState=z,w.StreamEvents=I,w.StreamingState=P,w.Subject=H,w.UserPlan=L,w.VideoType=S,w.VoiceAccess=B,w.createAgentManager=fe,w.getAgent=we,Object.defineProperty(w,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, RatingEntity, RatingPayload } 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[]>;
|
|
@@ -7,4 +7,7 @@ export declare function createAgentsApi(auth: Auth, host?: string): {
|
|
|
7
7
|
update(id: string, payload: AgentPayload, options?: RequestInit): Promise<Agent>;
|
|
8
8
|
newChat(agentId: string, options?: RequestInit): Promise<Chat>;
|
|
9
9
|
chat(agentId: string, chatId: string, payload: ChatPayload, options?: RequestInit): Promise<ChatResponse>;
|
|
10
|
+
createRating(agentId: string, chatId: string, payload: RatingPayload, options?: RequestInit): Promise<RatingEntity>;
|
|
11
|
+
updateRating(agentId: string, chatId: string, ratingId: string, payload: Partial<RatingPayload>, options?: RequestInit): Promise<RatingEntity>;
|
|
12
|
+
deleteRating(agentId: string, chatId: string, ratingId: string, options?: RequestInit): Promise<RatingEntity>;
|
|
10
13
|
};
|
|
@@ -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>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Auth } from './types/auth';
|
|
2
|
+
import { ChatProgressCallback } from '.';
|
|
3
|
+
export interface SocketManager {
|
|
4
|
+
socket?: WebSocket;
|
|
5
|
+
disconnect: () => void;
|
|
6
|
+
subscribeToEvents: (data: any) => void;
|
|
7
|
+
}
|
|
8
|
+
export declare function createSocketManager(auth: Auth, host: string, callback?: {
|
|
9
|
+
onMessage?: ChatProgressCallback;
|
|
10
|
+
onError?: (error: string, event: Event) => void;
|
|
11
|
+
}): Promise<SocketManager>;
|
|
@@ -0,0 +1,16 @@
|
|
|
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>;
|
|
4
|
+
/**
|
|
5
|
+
* Creates a new Agent Manager instance for interacting with an agent, chat, and related connections.
|
|
6
|
+
*
|
|
7
|
+
* @param {string} agent - The ID or instance of the agent to chat with.
|
|
8
|
+
* @param {AgentManagerOptions} options - Configurations for the Agent Manager API.
|
|
9
|
+
* * @returns {Promise<AgentManager>} - A promise that resolves to an instance of the AgentsAPI interface.
|
|
10
|
+
*
|
|
11
|
+
* @throws {Error} Throws an error if the agent is not initialized.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const agentManager = await createAgentManager('id-agent123', { auth: { type: 'key', clientKey: '123', externalId: '123' } });
|
|
15
|
+
*/
|
|
16
|
+
export declare function createAgentManager(agent: string, options: AgentManagerOptions): Promise<AgentManager>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { CreateStreamOptions, PayloadType, StreamingManagerOptions } from './types/index';
|
|
2
|
+
export declare function createStreamingManager<T extends CreateStreamOptions>(agentId: string, agent: T, { debug, callbacks, auth, analytics, baseURL }: StreamingManagerOptions): Promise<{
|
|
3
|
+
/**
|
|
4
|
+
* Method to send request to server to get clip or talk depend on you payload
|
|
5
|
+
* @param payload
|
|
6
|
+
*/
|
|
7
|
+
speak(payload: PayloadType<T>): Promise<import('./types/index').SendStreamPayloadResponse>;
|
|
8
|
+
/**
|
|
9
|
+
* Method to close RTC connection
|
|
10
|
+
*/
|
|
11
|
+
disconnect(): Promise<void>;
|
|
12
|
+
/**
|
|
13
|
+
* Session identifier information, should be returned in the body of all streaming requests
|
|
14
|
+
*/
|
|
15
|
+
sessionId: string;
|
|
16
|
+
/**
|
|
17
|
+
* Id of current RTC stream
|
|
18
|
+
*/
|
|
19
|
+
streamId: string;
|
|
20
|
+
}>;
|
|
21
|
+
export type StreamingManager<T extends CreateStreamOptions> = Awaited<ReturnType<typeof createStreamingManager<T>>>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Agent } from '..';
|
|
2
|
+
export interface AnalyticsOptions {
|
|
3
|
+
mixPanelKey: string;
|
|
4
|
+
agent: Agent;
|
|
5
|
+
isEnabled?: boolean;
|
|
6
|
+
distinctId?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface Analytics {
|
|
9
|
+
mixPanelKey: string;
|
|
10
|
+
distinct_id?: string;
|
|
11
|
+
isEnabled: boolean;
|
|
12
|
+
chatId?: string;
|
|
13
|
+
agentId: string;
|
|
14
|
+
owner_id: string;
|
|
15
|
+
getRandom(): string;
|
|
16
|
+
track(event: string, props?: Record<string, any>): Promise<any>;
|
|
17
|
+
}
|
|
18
|
+
export declare function initializeAnalytics(config: AnalyticsOptions): Analytics;
|
|
@@ -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.
|
|
@@ -50,3 +50,4 @@ export interface Stream_LLM_Script {
|
|
|
50
50
|
stream_audio?: boolean;
|
|
51
51
|
}
|
|
52
52
|
export type StreamScript = Stream_Text_Script | Stream_Audio_Script | Stream_LLM_Script;
|
|
53
|
+
export type SupportedStreamScipt = Stream_Text_Script | Stream_Audio_Script;
|
|
@@ -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
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Chat, ChatPayload, ChatResponse } from './chat';
|
|
2
|
+
import { Knowledge } from './knowledge';
|
|
3
|
+
import { LLM } from './llm';
|
|
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
|
+
}
|
|
22
|
+
export interface Agent {
|
|
23
|
+
id: string;
|
|
24
|
+
username?: string;
|
|
25
|
+
presenter: Presenter;
|
|
26
|
+
llm?: LLM;
|
|
27
|
+
knowledge?: Knowledge;
|
|
28
|
+
use_case?: string;
|
|
29
|
+
tags?: string[];
|
|
30
|
+
chats?: number;
|
|
31
|
+
greetings?: string[];
|
|
32
|
+
access?: 'private' | 'pending-public' | 'unlisted' | 'rejected' | 'public';
|
|
33
|
+
metadata?: {
|
|
34
|
+
plan: PlanGroup | UserPlan;
|
|
35
|
+
};
|
|
36
|
+
preview_name?: string;
|
|
37
|
+
preview_description?: string;
|
|
38
|
+
preview_thumbnail?: string;
|
|
39
|
+
preview_url?: string;
|
|
40
|
+
owner_id?: string;
|
|
41
|
+
}
|
|
42
|
+
export type AgentPayload = Omit<Agent, 'type' | 'created_at' | 'modified_at' | 'id' | 'owner_id' | 'metadata' | 'idle_video_url'>;
|
|
43
|
+
export interface AgentsAPI {
|
|
44
|
+
create(payload: AgentPayload, options?: RequestInit): Promise<Agent>;
|
|
45
|
+
getAgents(tag?: string, options?: RequestInit): Promise<Agent[]>;
|
|
46
|
+
getById(id: string, options?: RequestInit): Promise<Agent>;
|
|
47
|
+
delete(id: string, options?: RequestInit): Promise<void>;
|
|
48
|
+
update(id: string, payload: AgentPayload, options?: RequestInit): Promise<Agent>;
|
|
49
|
+
newChat(agentId: string, options?: RequestInit): Promise<Chat>;
|
|
50
|
+
chat(agentId: string, chatId: string, payload: ChatPayload, options?: RequestInit): Promise<ChatResponse>;
|
|
51
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
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
|
+
message_id: string;
|
|
19
|
+
}
|
|
20
|
+
export type RatingPayload = Omit<RatingEntity, 'owner_id' | 'id' | 'created_at' | 'modified_at' | 'created_by' | 'external_id' | 'agent_id' | 'chat_id'>;
|
|
21
|
+
export interface Message {
|
|
22
|
+
id: string;
|
|
23
|
+
role?: 'system' | 'assistant' | 'user' | 'function' | 'tool';
|
|
24
|
+
content: string;
|
|
25
|
+
created_at?: string;
|
|
26
|
+
matches?: ChatResponse['matches'];
|
|
27
|
+
}
|
|
28
|
+
export interface ChatPayload {
|
|
29
|
+
messages: Message[];
|
|
30
|
+
append_chat?: boolean;
|
|
31
|
+
streamId?: string;
|
|
32
|
+
sessionId?: string;
|
|
33
|
+
chatMode?: ChatMode;
|
|
34
|
+
}
|
|
35
|
+
export interface IRetrivalMetadata {
|
|
36
|
+
id: string;
|
|
37
|
+
data: string;
|
|
38
|
+
title: string;
|
|
39
|
+
document_id: string;
|
|
40
|
+
knowledge_id: string;
|
|
41
|
+
source_url: string;
|
|
42
|
+
}
|
|
43
|
+
export declare enum ChatMode {
|
|
44
|
+
Functional = "Functional",
|
|
45
|
+
TextOnly = "TextOnly",
|
|
46
|
+
Maintenance = "Maintenance"
|
|
47
|
+
}
|
|
48
|
+
export interface ChatResponse {
|
|
49
|
+
result?: string;
|
|
50
|
+
documentIds?: string[];
|
|
51
|
+
matches?: IRetrivalMetadata[];
|
|
52
|
+
chatMode?: ChatMode;
|
|
53
|
+
}
|
|
54
|
+
export interface Chat {
|
|
55
|
+
id: string;
|
|
56
|
+
agent_id: string;
|
|
57
|
+
created: string;
|
|
58
|
+
modified: string;
|
|
59
|
+
owner_id: string;
|
|
60
|
+
messages: Message[];
|
|
61
|
+
agent_id__created_at: string;
|
|
62
|
+
agent_id__modified_at: string;
|
|
63
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { SupportedStreamScipt } from '../../StreamScript';
|
|
2
|
+
import { Auth } from '../../auth';
|
|
3
|
+
import { ConnectionState, SendStreamPayloadResponse, StreamingState } from '../../stream';
|
|
4
|
+
import { Agent } from './agent';
|
|
5
|
+
import { ChatMode, ChatResponse, Message, RatingEntity } from './chat';
|
|
6
|
+
/**
|
|
7
|
+
* Types of events provided in Chat Progress Callback
|
|
8
|
+
*/
|
|
9
|
+
export declare enum ChatProgress {
|
|
10
|
+
/**
|
|
11
|
+
* Chat was successfully embedded
|
|
12
|
+
*/
|
|
13
|
+
Embed = "embed",
|
|
14
|
+
/**
|
|
15
|
+
* Server processing chat message
|
|
16
|
+
*/
|
|
17
|
+
Query = "query",
|
|
18
|
+
/**
|
|
19
|
+
* Server returns a part of the message
|
|
20
|
+
*/
|
|
21
|
+
Partial = "partial",
|
|
22
|
+
/**
|
|
23
|
+
* Server processed message and returned response
|
|
24
|
+
*/
|
|
25
|
+
Answer = "answer",
|
|
26
|
+
/**
|
|
27
|
+
* Chat was closed
|
|
28
|
+
*/
|
|
29
|
+
Complete = "done"
|
|
30
|
+
}
|
|
31
|
+
export type ChatProgressCallback = (progress: ChatProgress, data: any) => void;
|
|
32
|
+
export type ConnectionStateChangeCallback = (state: ConnectionState) => void;
|
|
33
|
+
export type VideoStateChangeCallback = (state: StreamingState, data: any) => void;
|
|
34
|
+
interface ManagerCallbacks {
|
|
35
|
+
/**
|
|
36
|
+
* Optional callback will be triggered each time the RTC connection changes state
|
|
37
|
+
* @param state
|
|
38
|
+
*/
|
|
39
|
+
onConnectionStateChange?(state: ConnectionState): void;
|
|
40
|
+
/**
|
|
41
|
+
* Optional callback function that will be triggered each time video events happen
|
|
42
|
+
* @param state
|
|
43
|
+
*/
|
|
44
|
+
onVideoStateChange?(state: StreamingState, data?: any): void;
|
|
45
|
+
/**
|
|
46
|
+
* Callback function that will be triggered each time the video stream starts or stops to update html element on webpage
|
|
47
|
+
* Required callback for SDK
|
|
48
|
+
* @param srcObject
|
|
49
|
+
* @example
|
|
50
|
+
* const videoRef = useRef<HTMLVideoElement>(null);
|
|
51
|
+
* onSrcObjectReady(value) { videoRef.current.srcObject = value }
|
|
52
|
+
*/
|
|
53
|
+
onSrcObjectReady(srcObject: MediaStream): void;
|
|
54
|
+
/**
|
|
55
|
+
* Optional callback function that will be triggered each time new message is received
|
|
56
|
+
* @param messages - array of messages
|
|
57
|
+
*/
|
|
58
|
+
onNewMessage?(messages: Message[]): void;
|
|
59
|
+
/**
|
|
60
|
+
* Optional callback function that will be triggered each time new chat is created
|
|
61
|
+
* @param chatId - id of the new chat
|
|
62
|
+
*/
|
|
63
|
+
onNewChat?(chatId: string): void;
|
|
64
|
+
/**
|
|
65
|
+
* Optional callback function that will be triggered each time the chat mode changes
|
|
66
|
+
* @param mode - ChatMode
|
|
67
|
+
*/
|
|
68
|
+
onModeChange?(mode: ChatMode): void;
|
|
69
|
+
}
|
|
70
|
+
export interface AgentManagerOptions {
|
|
71
|
+
auth: Auth;
|
|
72
|
+
callbacks: ManagerCallbacks;
|
|
73
|
+
baseURL?: string;
|
|
74
|
+
wsURL?: string;
|
|
75
|
+
debug?: boolean;
|
|
76
|
+
enableAnalitics?: boolean;
|
|
77
|
+
mixpanelKey?: string;
|
|
78
|
+
/**
|
|
79
|
+
* Unique ID of agent user used in analytics. Pass it to override the default way to get distinctId
|
|
80
|
+
*/
|
|
81
|
+
distinctId?: string;
|
|
82
|
+
mode?: ChatMode;
|
|
83
|
+
}
|
|
84
|
+
export interface AgentManager {
|
|
85
|
+
/**
|
|
86
|
+
* Agent instance you are working with.
|
|
87
|
+
* To know more about agents go to https://docs.d-id.com/reference/agents
|
|
88
|
+
*/
|
|
89
|
+
agent: Agent;
|
|
90
|
+
/**
|
|
91
|
+
* Array of starter messages that will be sent to the agent when the chat starts
|
|
92
|
+
*/
|
|
93
|
+
starterMessages: string[];
|
|
94
|
+
/**
|
|
95
|
+
* Method to connect to stream and chat
|
|
96
|
+
*/
|
|
97
|
+
connect: () => Promise<void>;
|
|
98
|
+
/**
|
|
99
|
+
* Method to reconnect to stream and continue chat
|
|
100
|
+
*/
|
|
101
|
+
reconnect: () => Promise<void>;
|
|
102
|
+
/**
|
|
103
|
+
* Method to close all connections with agent, stream and web socket
|
|
104
|
+
*/
|
|
105
|
+
disconnect: () => Promise<void>;
|
|
106
|
+
/**
|
|
107
|
+
* Method to send a chat message to existing chat with the agent
|
|
108
|
+
* @param messages
|
|
109
|
+
* @param append_chat: when true, append to existing agent chat, rather than creating a new one.
|
|
110
|
+
*/
|
|
111
|
+
chat: (userMessage: string, append_chat?: boolean) => Promise<ChatResponse>;
|
|
112
|
+
/**
|
|
113
|
+
* Method to rate the answer in chat
|
|
114
|
+
* @param score: 1 | -1 - score of the answer. 1 for positive, -1 for negative
|
|
115
|
+
* @param matches - array of matches that were used to find the answer
|
|
116
|
+
* @param id - id of Rating entity. Leave it empty to create a new, one or pass it to work with the existing one
|
|
117
|
+
*/
|
|
118
|
+
rate: (messageId: string, score: 1 | -1, rateId?: string) => Promise<RatingEntity>;
|
|
119
|
+
/**
|
|
120
|
+
* Method to delete rating from answer in chat
|
|
121
|
+
* @param id - id of Rating entity.
|
|
122
|
+
*/
|
|
123
|
+
deleteRate: (id: string) => Promise<RatingEntity>;
|
|
124
|
+
/**
|
|
125
|
+
* Method to make your agent read the text you provide or reproduce sound
|
|
126
|
+
* @param payload
|
|
127
|
+
*/
|
|
128
|
+
speak: (payload: SupportedStreamScipt) => Promise<SendStreamPayloadResponse>;
|
|
129
|
+
/**
|
|
130
|
+
* Method to change the mode of the chat
|
|
131
|
+
* @param mode - ChatMode
|
|
132
|
+
*/
|
|
133
|
+
changeMode(mode: ChatMode): void;
|
|
134
|
+
}
|
|
135
|
+
export {};
|
|
@@ -43,6 +43,12 @@ export interface CreateClipStreamRequest {
|
|
|
43
43
|
* @default auto
|
|
44
44
|
*/
|
|
45
45
|
compatibility_mode?: CompatibilityMode;
|
|
46
|
+
/**
|
|
47
|
+
* Whether to stream wamrup video on the connection.
|
|
48
|
+
* If set to true, will stream a warmup video when connection is established.
|
|
49
|
+
* At the end of the warmup video, a message containing "stream/ready" will be sent on the data channel.
|
|
50
|
+
*/
|
|
51
|
+
stream_warmup?: boolean;
|
|
46
52
|
}
|
|
47
53
|
export interface SendClipStreamPayload extends StickyRequest {
|
|
48
54
|
script: StreamScript;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { StreamScript } from '
|
|
1
|
+
import { StreamScript } from '../..';
|
|
2
2
|
export interface CreateTalkStreamRequest {
|
|
3
3
|
source_url: string;
|
|
4
4
|
driver_url?: string;
|
|
@@ -20,6 +20,7 @@ export interface CreateTalkStreamRequest {
|
|
|
20
20
|
align_expand_factor?: number;
|
|
21
21
|
stitch?: boolean;
|
|
22
22
|
};
|
|
23
|
+
stream_warmup?: boolean;
|
|
23
24
|
}
|
|
24
25
|
export interface SendTalkStreamPayload {
|
|
25
26
|
script: StreamScript;
|
|
@@ -40,17 +40,17 @@ export interface IceCandidate {
|
|
|
40
40
|
* The format of this address is a candidate-attribute as defined in RFC 5245. This string is empty ("") if the
|
|
41
41
|
* RTCIceCandidate is an "end of candidates" indicator.
|
|
42
42
|
*/
|
|
43
|
-
candidate: string;
|
|
43
|
+
candidate: string | null;
|
|
44
44
|
/**
|
|
45
45
|
* A string specifying the candidate's media stream identification tag which uniquely identifies the media stream
|
|
46
46
|
* within the component with which the candidate is associated, or null if no such association exists.
|
|
47
47
|
*/
|
|
48
|
-
sdpMid
|
|
48
|
+
sdpMid?: string;
|
|
49
49
|
/**
|
|
50
50
|
* If not null, sdpMLineIndex indicates the zero-based index number of the media description (as defined in RFC
|
|
51
51
|
* 4566) in the SDP with which the candidate is associated.
|
|
52
52
|
*/
|
|
53
|
-
sdpMLineIndex
|
|
53
|
+
sdpMLineIndex?: number;
|
|
54
54
|
}
|
|
55
55
|
export interface Status {
|
|
56
56
|
status: string;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Analytics } from '../../services/mixpanel';
|
|
1
2
|
import { Auth } from '../auth';
|
|
2
3
|
import { VideoType } from '../entities';
|
|
3
4
|
import { CreateClipStreamRequest, CreateTalkStreamRequest, SendClipStreamPayload, SendTalkStreamPayload } from './api';
|
|
@@ -7,11 +8,33 @@ export declare enum StreamingState {
|
|
|
7
8
|
Start = "START",
|
|
8
9
|
Stop = "STOP"
|
|
9
10
|
}
|
|
11
|
+
export declare enum StreamEvents {
|
|
12
|
+
ChatAnswer = "chat/answer",
|
|
13
|
+
ChatPartial = "chat/partial",
|
|
14
|
+
StreamDone = "stream/done",
|
|
15
|
+
StreamStarted = "stream/started",
|
|
16
|
+
StreamFailed = "stream/error",
|
|
17
|
+
StreamReady = "stream/ready",
|
|
18
|
+
StreamCreated = "stream/created",
|
|
19
|
+
StreamVideoCreated = "stream-video/started",
|
|
20
|
+
StreamVideoDone = "stream-video/done",
|
|
21
|
+
StreamVideoError = "stream-video/error",
|
|
22
|
+
StreamVideoRejected = "stream-video/rejected"
|
|
23
|
+
}
|
|
24
|
+
export declare enum ConnectionState {
|
|
25
|
+
New = 0,
|
|
26
|
+
Fail = 1,
|
|
27
|
+
Connected = 2,
|
|
28
|
+
Connecting = 3,
|
|
29
|
+
Terminating = 4
|
|
30
|
+
}
|
|
10
31
|
export interface ManagerCallbacks {
|
|
11
|
-
|
|
12
|
-
|
|
32
|
+
onMessage?: (event: string, data: string) => void;
|
|
33
|
+
onConnectionStateChange?: (state: ConnectionState) => void;
|
|
34
|
+
onVideoStateChange?: (state: StreamingState, data?: any) => void;
|
|
13
35
|
onSrcObjectReady?: (value: MediaStream) => void;
|
|
14
36
|
}
|
|
37
|
+
export type ManagerCallbackKeys = keyof ManagerCallbacks;
|
|
15
38
|
export interface TalkStreamOptions extends CreateTalkStreamRequest {
|
|
16
39
|
videoType: VideoType.Talk;
|
|
17
40
|
}
|
|
@@ -32,4 +55,16 @@ export interface StreamingManagerOptions {
|
|
|
32
55
|
baseURL?: string;
|
|
33
56
|
debug?: boolean;
|
|
34
57
|
auth: Auth;
|
|
58
|
+
analytics?: Analytics;
|
|
59
|
+
}
|
|
60
|
+
export interface SlimRTCStatsReport {
|
|
61
|
+
index: number;
|
|
62
|
+
timestamp: any;
|
|
63
|
+
bytesReceived: any;
|
|
64
|
+
packetsReceived: any;
|
|
65
|
+
packetsLost: any;
|
|
66
|
+
jitter: any;
|
|
67
|
+
frameWidth: any;
|
|
68
|
+
frameHeight: any;
|
|
69
|
+
framesPerSecond: any;
|
|
35
70
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Agent } from '../types/index';
|
|
2
|
+
export declare function getAnaliticsInfo(agent: Agent): {
|
|
3
|
+
$os: string;
|
|
4
|
+
isMobile: string;
|
|
5
|
+
browser: string;
|
|
6
|
+
origin: string;
|
|
7
|
+
agentType: "talk" | "clip";
|
|
8
|
+
agentVoice: {
|
|
9
|
+
voiceId: string | undefined;
|
|
10
|
+
provider: import('../types/tts').Providers | undefined;
|
|
11
|
+
};
|
|
12
|
+
};
|