@d-id/client-sdk 1.0.2 → 1.0.4
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,8 +1,9 @@
|
|
|
1
|
-
import { Agent, AgentPayload, Auth } from '../../../../common/types/src/index';
|
|
1
|
+
import { Agent, AgentPayload, Auth, IChatPayload } 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
|
+
chat(id: string, payload: IChatPayload): Promise<Agent>;
|
|
8
9
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ExtendedTextToSpeechProviders } from '../../tts';
|
|
1
|
+
import { ExtendedTextToSpeechProviders, StreamTextToSpeechProviders } from '../../tts';
|
|
2
2
|
import { LLM } from './llm';
|
|
3
3
|
import { Presenter } from './presenter';
|
|
4
4
|
export interface Agent {
|
|
@@ -18,3 +18,9 @@ export interface Agent {
|
|
|
18
18
|
preview_name: string;
|
|
19
19
|
}
|
|
20
20
|
export type AgentPayload = Omit<Agent, 'type' | 'created_at' | 'modified_at' | 'id' | 'owner_id' | 'idle_video_url'>;
|
|
21
|
+
export interface IChatPayload {
|
|
22
|
+
voice: StreamTextToSpeechProviders;
|
|
23
|
+
streamId: string;
|
|
24
|
+
sessionId: string;
|
|
25
|
+
userQuery: string;
|
|
26
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -1,18 +1,24 @@
|
|
|
1
|
-
function
|
|
1
|
+
function k(r) {
|
|
2
2
|
return r.type === "bearer" ? "Bearer " + r.token : r.type === "basic" ? "Basic " + btoa(`${r.username}:${r.password}`) : "Client-Key " + r.clientKey;
|
|
3
3
|
}
|
|
4
|
-
function
|
|
4
|
+
function m(r, o = "https://api.d-id.com") {
|
|
5
5
|
const n = async (e, t) => {
|
|
6
6
|
const s = await fetch(o + (e != null && e.startsWith("/") ? e : `/${e}`), {
|
|
7
7
|
...t,
|
|
8
8
|
headers: {
|
|
9
9
|
...t == null ? void 0 : t.headers,
|
|
10
|
-
Authorization:
|
|
10
|
+
Authorization: k(r),
|
|
11
11
|
"Content-Type": "application/json"
|
|
12
12
|
}
|
|
13
13
|
});
|
|
14
|
-
if (!s.ok)
|
|
15
|
-
|
|
14
|
+
if (!s.ok) {
|
|
15
|
+
let c = await s.text().catch(() => "Failed to fetch");
|
|
16
|
+
try {
|
|
17
|
+
c = JSON.parse(c), c.description && (c = c.description);
|
|
18
|
+
} catch {
|
|
19
|
+
}
|
|
20
|
+
throw new Error(c);
|
|
21
|
+
}
|
|
16
22
|
return s.json();
|
|
17
23
|
};
|
|
18
24
|
return {
|
|
@@ -46,7 +52,7 @@ function p(r, o = "https://api.d-id.com") {
|
|
|
46
52
|
};
|
|
47
53
|
}
|
|
48
54
|
function K(r, o = "https://api.d-id.com") {
|
|
49
|
-
const n =
|
|
55
|
+
const n = m(r, `${o}/knowledge`);
|
|
50
56
|
return {
|
|
51
57
|
createKnowledge(e) {
|
|
52
58
|
return n.post("/", e);
|
|
@@ -83,7 +89,7 @@ function K(r, o = "https://api.d-id.com") {
|
|
|
83
89
|
};
|
|
84
90
|
}
|
|
85
91
|
function O(r, o = "https://api.d-id.com") {
|
|
86
|
-
const n =
|
|
92
|
+
const n = m(r, `${o}/agents`);
|
|
87
93
|
return {
|
|
88
94
|
create(e) {
|
|
89
95
|
return n.post("/", e);
|
|
@@ -99,11 +105,14 @@ function O(r, o = "https://api.d-id.com") {
|
|
|
99
105
|
},
|
|
100
106
|
update(e, t) {
|
|
101
107
|
return n.patch(`/${e}`, t);
|
|
108
|
+
},
|
|
109
|
+
chat(e, t) {
|
|
110
|
+
return n.patch(`/${e}/chat`, t);
|
|
102
111
|
}
|
|
103
112
|
};
|
|
104
113
|
}
|
|
105
|
-
function
|
|
106
|
-
const n =
|
|
114
|
+
function A(r, o) {
|
|
115
|
+
const n = m(r, o);
|
|
107
116
|
return {
|
|
108
117
|
createStream(e) {
|
|
109
118
|
return n.post("/clips/streams", {
|
|
@@ -137,8 +146,8 @@ function k(r, o) {
|
|
|
137
146
|
}
|
|
138
147
|
};
|
|
139
148
|
}
|
|
140
|
-
function
|
|
141
|
-
const n =
|
|
149
|
+
function T(r, o) {
|
|
150
|
+
const n = m(r, o);
|
|
142
151
|
return {
|
|
143
152
|
createStream(e) {
|
|
144
153
|
return n.post("/talks/streams", {
|
|
@@ -173,61 +182,61 @@ function A(r, o) {
|
|
|
173
182
|
}
|
|
174
183
|
};
|
|
175
184
|
}
|
|
176
|
-
var
|
|
177
|
-
let
|
|
178
|
-
const
|
|
185
|
+
var p = /* @__PURE__ */ ((r) => (r.Idle = "IDLE", r.Streaming = "STREAMING", r))(p || {}), f = /* @__PURE__ */ ((r) => (r.Clip = "clip", r.Talk = "talk", r))(f || {});
|
|
186
|
+
let $ = !1;
|
|
187
|
+
const d = (r, o) => $ && console.log(r, o), D = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
|
|
179
188
|
async function R(r, {
|
|
180
189
|
debug: o = !1,
|
|
181
190
|
callbacks: n,
|
|
182
191
|
auth: e,
|
|
183
192
|
baseURL: t = "https://api.d-id.com"
|
|
184
193
|
}) {
|
|
185
|
-
|
|
194
|
+
$ = o;
|
|
186
195
|
let s = null;
|
|
187
196
|
const {
|
|
188
|
-
startConnection:
|
|
189
|
-
sendStreamRequest:
|
|
190
|
-
close:
|
|
191
|
-
createStream:
|
|
197
|
+
startConnection: c,
|
|
198
|
+
sendStreamRequest: g,
|
|
199
|
+
close: h,
|
|
200
|
+
createStream: S,
|
|
192
201
|
addIceCandidate: _
|
|
193
|
-
} = r.videoType ===
|
|
194
|
-
id:
|
|
202
|
+
} = r.videoType === f.Clip ? A(e, t) : T(e, t), {
|
|
203
|
+
id: u,
|
|
195
204
|
offer: y,
|
|
196
205
|
ice_servers: I,
|
|
197
|
-
session_id:
|
|
198
|
-
} = await
|
|
206
|
+
session_id: l
|
|
207
|
+
} = await S(r), a = new D({
|
|
199
208
|
iceServers: I
|
|
200
|
-
}),
|
|
201
|
-
if (!
|
|
209
|
+
}), C = a.createDataChannel("JanusDataChannel");
|
|
210
|
+
if (!l)
|
|
202
211
|
throw new Error("Could not create session_id");
|
|
203
212
|
a.onicecandidate = (i) => {
|
|
204
|
-
|
|
213
|
+
d("peerConnection.onicecandidate", i), i.candidate && i.candidate.sdpMid && i.candidate.sdpMLineIndex !== null && _(u, {
|
|
205
214
|
candidate: i.candidate.candidate,
|
|
206
215
|
sdpMid: i.candidate.sdpMid,
|
|
207
216
|
sdpMLineIndex: i.candidate.sdpMLineIndex
|
|
208
|
-
},
|
|
217
|
+
}, l);
|
|
209
218
|
}, a.oniceconnectionstatechange = () => {
|
|
210
|
-
|
|
219
|
+
d("peerConnection.oniceconnectionstatechange => " + a.iceConnectionState), n.onConnectionStateChange(a.iceConnectionState);
|
|
211
220
|
}, a.ontrack = (i) => {
|
|
212
|
-
|
|
213
|
-
},
|
|
214
|
-
|
|
215
|
-
}, await a.setRemoteDescription(y),
|
|
216
|
-
const
|
|
217
|
-
return
|
|
221
|
+
d("peerConnection.ontrack", i), s = i.streams[0], n.onSrcObjectReady(s);
|
|
222
|
+
}, C.onmessage = (i) => {
|
|
223
|
+
C.readyState === "open" && n.onStreamingStateChange(i.data === "stream/done" ? p.Idle : p.Streaming);
|
|
224
|
+
}, await a.setRemoteDescription(y), d("set remote description OK");
|
|
225
|
+
const w = await a.createAnswer();
|
|
226
|
+
return d("create answer OK"), await a.setLocalDescription(w), d("set local description OK"), await c(u, w, l), d("start connection OK"), {
|
|
218
227
|
speak(i) {
|
|
219
|
-
return
|
|
228
|
+
return g(u, l, i);
|
|
220
229
|
},
|
|
221
230
|
async terminate() {
|
|
222
|
-
|
|
231
|
+
u && (s && (s.getTracks().forEach((i) => i.stop()), s = null), a && (a.close(), a.oniceconnectionstatechange = null, a.onnegotiationneeded = null, a.onicecandidate = null, a.ontrack = null), await h(u, l), n.onConnectionStateChange("closed"), n.onStreamingStateChange(p.Idle));
|
|
223
232
|
},
|
|
224
|
-
sessionId:
|
|
225
|
-
streamId:
|
|
233
|
+
sessionId: l,
|
|
234
|
+
streamId: u
|
|
226
235
|
};
|
|
227
236
|
}
|
|
228
237
|
export {
|
|
229
238
|
O as createAgentsApi,
|
|
230
|
-
|
|
239
|
+
m as createClient,
|
|
231
240
|
K as createKnowledgeApi,
|
|
232
241
|
R as createStreamingManager
|
|
233
242
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(c,
|
|
1
|
+
(function(c,m){typeof exports=="object"&&typeof module<"u"?m(exports):typeof define=="function"&&define.amd?define(["exports"],m):(c=typeof globalThis<"u"?globalThis:c||self,m(c.index={}))})(this,function(c){"use strict";function m(r){return r.type==="bearer"?"Bearer "+r.token:r.type==="basic"?"Basic "+btoa(`${r.username}:${r.password}`):"Client-Key "+r.clientKey}function g(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:m(r),"Content-Type":"application/json"}});if(!i.ok){let d=await i.text().catch(()=>"Failed to fetch");try{d=JSON.parse(d),d.description&&(d=d.description)}catch{}throw new Error(d)}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=g(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=g(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)},chat(e,t){return n.patch(`/${e}/chat`,t)}}}function A(r,o){const n=g(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=g(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 f=(r=>(r.Idle="IDLE",r.Streaming="STREAMING",r))(f||{}),C=(r=>(r.Clip="clip",r.Talk="talk",r))(C||{});let w=!1;const u=(r,o)=>w&&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"}){w=o;let i=null;const{startConnection:d,sendStreamRequest:h,close:K,createStream:O,addIceCandidate:b}=r.videoType===C.Clip?A(e,t):I(e,t),{id:l,offer:D,ice_servers:M,session_id:p}=await O(r),a=new T({iceServers:M}),$=a.createDataChannel("JanusDataChannel");if(!p)throw new Error("Could not create session_id");a.onicecandidate=s=>{u("peerConnection.onicecandidate",s),s.candidate&&s.candidate.sdpMid&&s.candidate.sdpMLineIndex!==null&&b(l,{candidate:s.candidate.candidate,sdpMid:s.candidate.sdpMid,sdpMLineIndex:s.candidate.sdpMLineIndex},p)},a.oniceconnectionstatechange=()=>{u("peerConnection.oniceconnectionstatechange => "+a.iceConnectionState),n.onConnectionStateChange(a.iceConnectionState)},a.ontrack=s=>{u("peerConnection.ontrack",s),i=s.streams[0],n.onSrcObjectReady(i)},$.onmessage=s=>{$.readyState==="open"&&n.onStreamingStateChange(s.data==="stream/done"?f.Idle:f.Streaming)},await a.setRemoteDescription(D),u("set remote description OK");const S=await a.createAnswer();return u("create answer OK"),await a.setLocalDescription(S),u("set local description OK"),await d(l,S,p),u("start connection OK"),{speak(s){return h(l,p,s)},async terminate(){l&&(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(l,p),n.onConnectionStateChange("closed"),n.onStreamingStateChange(f.Idle))},sessionId:p,streamId:l}}c.createAgentsApi=_,c.createClient=g,c.createKnowledgeApi=y,c.createStreamingManager=k,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
|