@d-id/client-sdk 1.0.10 → 1.0.11

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.
@@ -1,10 +1,10 @@
1
- import { Agent, AgentPayload, Auth, ChatPayload } from '../../../../common/types/src/index';
1
+ import { Agent, AgentPayload, Auth, Chat, ChatPayload } from '../../../../common/types/src/index';
2
2
  export declare function createAgentsApi(auth: Auth, host?: string): {
3
3
  create(payload: AgentPayload): Promise<Agent>;
4
4
  getAgents(tag?: string): Promise<Agent[]>;
5
5
  getById(id: string): Promise<Agent>;
6
6
  delete(id: string): Promise<any>;
7
7
  update(id: string, payload: AgentPayload): Promise<Agent>;
8
- newChat(agentId: string): Promise<Agent>;
9
- chat(agentId: string, payload: ChatPayload): Promise<Agent>;
8
+ newChat(agentId: string): Promise<Chat>;
9
+ chat(agentId: string, chatId: string, payload: ChatPayload): Promise<string>;
10
10
  };
@@ -1,7 +1,7 @@
1
1
  import { Auth } from '../../../../common/types/src/auth';
2
2
  export declare function createClient(auth: Auth, host?: string): {
3
3
  get<T = any>(url: string, options?: RequestInit): Promise<T>;
4
- post<T_1 = any>(url: string, body: any, options?: RequestInit): Promise<T_1>;
4
+ post<T_1 = any>(url: string, body?: any, options?: RequestInit): Promise<T_1>;
5
5
  delete<T_2 = any>(url: string, body?: any, options?: RequestInit): Promise<T_2>;
6
6
  patch<T_3 = any>(url: string, body?: any, options?: RequestInit): Promise<T_3>;
7
7
  };
@@ -15,14 +15,3 @@ export interface Agent {
15
15
  preview_thumbnail?: string;
16
16
  }
17
17
  export type AgentPayload = Omit<Agent, 'type' | 'created_at' | 'modified_at' | 'id' | 'owner_id' | 'idle_video_url'>;
18
- export interface Message {
19
- role: 'system' | 'assistant' | 'user' | 'function' | 'tool';
20
- content: string;
21
- name?: string;
22
- }
23
- export interface ChatPayload {
24
- messages: Message[];
25
- chatId: string;
26
- streamId: string;
27
- sessionId: string;
28
- }
@@ -0,0 +1,20 @@
1
+ export interface Message {
2
+ role: 'system' | 'assistant' | 'user' | 'function' | 'tool';
3
+ content: string;
4
+ name?: string;
5
+ }
6
+ export interface ChatPayload {
7
+ messages: Message[];
8
+ streamId: string;
9
+ sessionId: string;
10
+ }
11
+ export interface Chat {
12
+ agent_id: string;
13
+ created: Message[];
14
+ messages: string;
15
+ agent_id__created_at: string;
16
+ agent_id__modified_at: string;
17
+ modified: string;
18
+ owner_id: string;
19
+ id: string;
20
+ }
@@ -1 +1,2 @@
1
1
  export * from './agent';
2
+ export * from './chat';
package/dist/index.js CHANGED
@@ -108,10 +108,10 @@ function O(r, o = "https://api.d-id.com") {
108
108
  return n.patch(`/${e}`, t);
109
109
  },
110
110
  newChat(e) {
111
- return n.patch(`/${e}/chat/new`);
111
+ return n.post(`/${e}/chat`);
112
112
  },
113
- chat(e, t) {
114
- return n.post(`/${e}/chat`, t);
113
+ chat(e, t, s) {
114
+ return n.post(`/${e}/chat/${t}`, s);
115
115
  }
116
116
  };
117
117
  }
@@ -186,16 +186,16 @@ function T(r, o) {
186
186
  }
187
187
  };
188
188
  }
189
- var m = /* @__PURE__ */ ((r) => (r.Idle = "IDLE", r.Streaming = "STREAMING", r))(m || {}), f = /* @__PURE__ */ ((r) => (r.Clip = "clip", r.Talk = "talk", r))(f || {});
190
- let $ = !1;
191
- const d = (r, o) => $ && console.log(r, o), D = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
189
+ var m = /* @__PURE__ */ ((r) => (r.Idle = "IDLE", r.Streaming = "STREAMING", r))(m || {}), $ = /* @__PURE__ */ ((r) => (r.Clip = "clip", r.Talk = "talk", r))($ || {});
190
+ let f = !1;
191
+ const d = (r, o) => f && console.log(r, o), D = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
192
192
  async function E(r, {
193
193
  debug: o = !1,
194
194
  callbacks: n,
195
195
  auth: e,
196
196
  baseURL: t = "https://api.d-id.com"
197
197
  }) {
198
- $ = o;
198
+ f = o;
199
199
  let s = null;
200
200
  const {
201
201
  startConnection: u,
@@ -203,7 +203,7 @@ async function E(r, {
203
203
  close: h,
204
204
  createStream: S,
205
205
  addIceCandidate: _
206
- } = r.videoType === f.Clip ? A(e, t) : T(e, t), {
206
+ } = r.videoType === $.Clip ? A(e, t) : T(e, t), {
207
207
  id: l,
208
208
  offer: y,
209
209
  ice_servers: I,
@@ -1 +1 @@
1
- (function(c,g){typeof exports=="object"&&typeof module<"u"?g(exports):typeof define=="function"&&define.amd?define(["exports"],g):(c=typeof globalThis<"u"?globalThis:c||self,g(c.index={}))})(this,function(c){"use strict";function g(r){return r.type==="bearer"?"Bearer "+r.token:r.type==="basic"?"Basic "+btoa(`${r.username}:${r.password}`):"Client-Key "+r.clientKey}function f(r,o="https://api.d-id.com"){const n=async(e,t)=>{const i=await fetch(o+(e!=null&&e.startsWith("/")?e:`/${e}`),{...t,headers:{...t==null?void 0:t.headers,Authorization:g(r),"Content-Type":"application/json"}});if(!i.ok){let l=await i.text().catch(()=>"Failed to fetch");try{const u=JSON.parse(l);u.description?l=u.description:u.message&&(l=u.message)}catch{}throw new Error(l)}return i.json()};return{get(e,t){return n(e,{...t,method:"GET"})},post(e,t,i){return n(e,{...i,body:JSON.stringify(t),method:"POST"})},delete(e,t,i){return n(e,{...i,body:JSON.stringify(t),method:"DELETE"})},patch(e,t,i){return n(e,{...i,body:JSON.stringify(t),method:"PATCH"})}}}function y(r,o="https://api.d-id.com"){const n=f(r,`${o}/knowledge`);return{createKnowledge(e){return n.post("/",e)},getKnowledgeBase(){return n.get("/")},getKnowledge(e){return n.get(`/${e}`)},deleteKnowledge(e){return n.delete(`/${e}`)},createDocument(e,t){return n.post(`/${e}/documents`,t)},deleteDocument(e,t){return n.delete(`/${e}/documents/${t}`)},getDocuments(e){return n.get(`/${e}/documents`)},getDocument(e,t){return n.get(`/${e}/documents/${t}`)},getRecords(e,t){return n.get(`/${e}/documents/${t}/records`)},query(e,t){return n.post(`/${e}/query`,{query:t})}}}function _(r,o="https://api.d-id.com"){const n=f(r,`${o}/agents`);return{create(e){return n.post("/",e)},getAgents(e){return n.get(`/${e?`?tag=${e}`:""}`)},getById(e){return n.get(`/${e}`)},delete(e){return n.delete(`/${e}`)},update(e,t){return n.patch(`/${e}`,t)},newChat(e){return n.patch(`/${e}/chat/new`)},chat(e,t){return n.post(`/${e}/chat`,t)}}}function A(r,o){const n=f(r,o);return{createStream(e){return n.post("/clips/streams",{driver_id:e.driver_id,presenter_id:e.presenter_id,compatibility_mode:e.compatibility_mode})},startConnection(e,t,i){return n.post(`/clips/streams/${e}/sdp`,{session_id:i,answer:t})},addIceCandidate(e,t,i){return n.post(`/clips/streams/${e}/ice`,{session_id:i,...t})},sendStreamRequest(e,t,i){return n.post(`/clips/streams/${e}`,{session_id:t,...i})},close(e,t){return n.delete(`/clips/streams/${e}`,{session_id:t})}}}function I(r,o){const n=f(r,o);return{createStream(e){return n.post("/talks/streams",{source_url:e.source_url,driver_url:e.driver_url,face:e.face,config:e.config})},startConnection(e,t,i){return n.post(`/talks/streams/${e}/sdp`,{session_id:i,answer:t})},addIceCandidate(e,t,i){return n.post(`/talks/streams/${e}/ice`,{session_id:i,...t})},sendStreamRequest(e,t,i){return n.post(`/talks/streams/${e}`,{session_id:t,...i})},close(e,t){return n.delete(`/talks/streams/${e}`,{session_id:t})}}}var C=(r=>(r.Idle="IDLE",r.Streaming="STREAMING",r))(C||{}),w=(r=>(r.Clip="clip",r.Talk="talk",r))(w||{});let h=!1;const d=(r,o)=>h&&console.log(r,o),T=(window.RTCPeerConnection||window.webkitRTCPeerConnection||window.mozRTCPeerConnection).bind(window);async function k(r,{debug:o=!1,callbacks:n,auth:e,baseURL:t="https://api.d-id.com"}){h=o;let i=null;const{startConnection:l,sendStreamRequest:u,close:K,createStream:O,addIceCandidate:b}=r.videoType===w.Clip?A(e,t):I(e,t),{id:p,offer:D,ice_servers:E,session_id:m}=await O(r),a=new T({iceServers:E}),$=a.createDataChannel("JanusDataChannel");if(!m)throw new Error("Could not create session_id");a.onicecandidate=s=>{d("peerConnection.onicecandidate",s),s.candidate&&s.candidate.sdpMid&&s.candidate.sdpMLineIndex!==null&&b(p,{candidate:s.candidate.candidate,sdpMid:s.candidate.sdpMid,sdpMLineIndex:s.candidate.sdpMLineIndex},m)},a.oniceconnectionstatechange=()=>{d("peerConnection.oniceconnectionstatechange => "+a.iceConnectionState),n.onConnectionStateChange(a.iceConnectionState)},a.ontrack=s=>{d("peerConnection.ontrack",s),i=s.streams[0],n.onSrcObjectReady(i)},$.onmessage=s=>{$.readyState==="open"&&n.onStreamingStateChange(s.data==="stream/done"?C.Idle:C.Streaming)},await a.setRemoteDescription(D),d("set remote description OK");const S=await a.createAnswer();return d("create answer OK"),await a.setLocalDescription(S),d("set local description OK"),await l(p,S,m),d("start connection OK"),{speak(s){return u(p,m,s)},async terminate(){p&&(i&&(i.getTracks().forEach(s=>s.stop()),i=null),a&&(a.close(),a.oniceconnectionstatechange=null,a.onnegotiationneeded=null,a.onicecandidate=null,a.ontrack=null),await K(p,m),n.onConnectionStateChange("closed"),n.onStreamingStateChange(C.Idle))},sessionId:m,streamId:p}}c.createAgentsApi=_,c.createClient=f,c.createKnowledgeApi=y,c.createStreamingManager=k,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
1
+ (function(c,g){typeof exports=="object"&&typeof module<"u"?g(exports):typeof define=="function"&&define.amd?define(["exports"],g):(c=typeof globalThis<"u"?globalThis:c||self,g(c.index={}))})(this,function(c){"use strict";function g(r){return r.type==="bearer"?"Bearer "+r.token:r.type==="basic"?"Basic "+btoa(`${r.username}:${r.password}`):"Client-Key "+r.clientKey}function f(r,o="https://api.d-id.com"){const n=async(e,t)=>{const i=await fetch(o+(e!=null&&e.startsWith("/")?e:`/${e}`),{...t,headers:{...t==null?void 0:t.headers,Authorization:g(r),"Content-Type":"application/json"}});if(!i.ok){let l=await i.text().catch(()=>"Failed to fetch");try{const u=JSON.parse(l);u.description?l=u.description:u.message&&(l=u.message)}catch{}throw new Error(l)}return i.json()};return{get(e,t){return n(e,{...t,method:"GET"})},post(e,t,i){return n(e,{...i,body:JSON.stringify(t),method:"POST"})},delete(e,t,i){return n(e,{...i,body:JSON.stringify(t),method:"DELETE"})},patch(e,t,i){return n(e,{...i,body:JSON.stringify(t),method:"PATCH"})}}}function y(r,o="https://api.d-id.com"){const n=f(r,`${o}/knowledge`);return{createKnowledge(e){return n.post("/",e)},getKnowledgeBase(){return n.get("/")},getKnowledge(e){return n.get(`/${e}`)},deleteKnowledge(e){return n.delete(`/${e}`)},createDocument(e,t){return n.post(`/${e}/documents`,t)},deleteDocument(e,t){return n.delete(`/${e}/documents/${t}`)},getDocuments(e){return n.get(`/${e}/documents`)},getDocument(e,t){return n.get(`/${e}/documents/${t}`)},getRecords(e,t){return n.get(`/${e}/documents/${t}/records`)},query(e,t){return n.post(`/${e}/query`,{query:t})}}}function _(r,o="https://api.d-id.com"){const n=f(r,`${o}/agents`);return{create(e){return n.post("/",e)},getAgents(e){return n.get(`/${e?`?tag=${e}`:""}`)},getById(e){return n.get(`/${e}`)},delete(e){return n.delete(`/${e}`)},update(e,t){return n.patch(`/${e}`,t)},newChat(e){return n.post(`/${e}/chat`)},chat(e,t,i){return n.post(`/${e}/chat/${t}`,i)}}}function A(r,o){const n=f(r,o);return{createStream(e){return n.post("/clips/streams",{driver_id:e.driver_id,presenter_id:e.presenter_id,compatibility_mode:e.compatibility_mode})},startConnection(e,t,i){return n.post(`/clips/streams/${e}/sdp`,{session_id:i,answer:t})},addIceCandidate(e,t,i){return n.post(`/clips/streams/${e}/ice`,{session_id:i,...t})},sendStreamRequest(e,t,i){return n.post(`/clips/streams/${e}`,{session_id:t,...i})},close(e,t){return n.delete(`/clips/streams/${e}`,{session_id:t})}}}function I(r,o){const n=f(r,o);return{createStream(e){return n.post("/talks/streams",{source_url:e.source_url,driver_url:e.driver_url,face:e.face,config:e.config})},startConnection(e,t,i){return n.post(`/talks/streams/${e}/sdp`,{session_id:i,answer:t})},addIceCandidate(e,t,i){return n.post(`/talks/streams/${e}/ice`,{session_id:i,...t})},sendStreamRequest(e,t,i){return n.post(`/talks/streams/${e}`,{session_id:t,...i})},close(e,t){return n.delete(`/talks/streams/${e}`,{session_id:t})}}}var C=(r=>(r.Idle="IDLE",r.Streaming="STREAMING",r))(C||{}),w=(r=>(r.Clip="clip",r.Talk="talk",r))(w||{});let h=!1;const d=(r,o)=>h&&console.log(r,o),T=(window.RTCPeerConnection||window.webkitRTCPeerConnection||window.mozRTCPeerConnection).bind(window);async function k(r,{debug:o=!1,callbacks:n,auth:e,baseURL:t="https://api.d-id.com"}){h=o;let i=null;const{startConnection:l,sendStreamRequest:u,close:K,createStream:O,addIceCandidate:b}=r.videoType===w.Clip?A(e,t):I(e,t),{id:p,offer:D,ice_servers:E,session_id:m}=await O(r),a=new T({iceServers:E}),$=a.createDataChannel("JanusDataChannel");if(!m)throw new Error("Could not create session_id");a.onicecandidate=s=>{d("peerConnection.onicecandidate",s),s.candidate&&s.candidate.sdpMid&&s.candidate.sdpMLineIndex!==null&&b(p,{candidate:s.candidate.candidate,sdpMid:s.candidate.sdpMid,sdpMLineIndex:s.candidate.sdpMLineIndex},m)},a.oniceconnectionstatechange=()=>{d("peerConnection.oniceconnectionstatechange => "+a.iceConnectionState),n.onConnectionStateChange(a.iceConnectionState)},a.ontrack=s=>{d("peerConnection.ontrack",s),i=s.streams[0],n.onSrcObjectReady(i)},$.onmessage=s=>{$.readyState==="open"&&n.onStreamingStateChange(s.data==="stream/done"?C.Idle:C.Streaming)},await a.setRemoteDescription(D),d("set remote description OK");const S=await a.createAnswer();return d("create answer OK"),await a.setLocalDescription(S),d("set local description OK"),await l(p,S,m),d("start connection OK"),{speak(s){return u(p,m,s)},async terminate(){p&&(i&&(i.getTracks().forEach(s=>s.stop()),i=null),a&&(a.close(),a.oniceconnectionstatechange=null,a.onnegotiationneeded=null,a.onicecandidate=null,a.ontrack=null),await K(p,m),n.onConnectionStateChange("closed"),n.onStreamingStateChange(C.Idle))},sessionId:m,streamId:p}}c.createAgentsApi=_,c.createClient=f,c.createKnowledgeApi=y,c.createStreamingManager=k,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
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.10",
4
+ "version": "1.0.11",
5
5
  "type": "module",
6
6
  "description": "d-id client sdk",
7
7
  "repository": {
@@ -23,7 +23,7 @@
23
23
  "types": "./dist/apps/sdk/lib/index.d.ts",
24
24
  "exports": {
25
25
  ".": {
26
- "types": "./dist/lib/index.d.ts",
26
+ "types": "./dist/apps/sdk/lib/index.d.ts",
27
27
  "import": "./dist/index.js",
28
28
  "require": "./dist/index.umd.cjs"
29
29
  }
@@ -38,9 +38,13 @@
38
38
  "@preact/preset-vite": "^2.5.0",
39
39
  "glob": "^10.3.10",
40
40
  "preact": "^10.5.13",
41
- "typescript": "^5.2.2",
42
41
  "vite": "^4.4.5",
43
42
  "vite-plugin-dts": "^3.6.0",
44
- "vite-plugin-html-env": "^1.2.8"
43
+ "vite-plugin-html-env": "^1.2.8",
44
+ "@trivago/prettier-plugin-sort-imports": "^4.3.0",
45
+ "prettier": "^3.1.0",
46
+ "prettier-plugin-organize-imports": "^3.2.4",
47
+ "serverless": "3.32.2",
48
+ "typescript": "^5.3.2"
45
49
  }
46
50
  }