@d-id/client-sdk 0.0.1
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 +2 -0
- package/dist/index.js +289 -0
- package/dist/index.umd.cjs +1 -0
- package/dist/lib/api/agents.d.ts +10 -0
- package/dist/lib/api/clipStream.d.ts +2 -0
- package/dist/lib/api/getClient.d.ts +7 -0
- package/dist/lib/api/knowledge.d.ts +13 -0
- package/dist/lib/api/talkStream.d.ts +2 -0
- package/dist/lib/auth/getAuthHeader.d.ts +2 -0
- package/dist/lib/createAgentManager.d.ts +9 -0
- package/dist/lib/createStreamingManager.d.ts +8 -0
- package/dist/lib/index.d.ts +5 -0
- package/dist/types/StreamScript.d.ts +40 -0
- package/dist/types/auth.d.ts +20 -0
- package/dist/types/entities/agents/agent.d.ts +18 -0
- package/dist/types/entities/agents/chat.d.ts +34 -0
- package/dist/types/entities/agents/index.d.ts +3 -0
- package/dist/types/entities/agents/knowledge.d.ts +10 -0
- package/dist/types/entities/agents/llm.d.ts +19 -0
- package/dist/types/entities/agents/manager.d.ts +21 -0
- package/dist/types/entities/agents/presenter.d.ts +20 -0
- package/dist/types/entities/index.d.ts +3 -0
- package/dist/types/entities/knowledge/document.d.ts +21 -0
- package/dist/types/entities/knowledge/index.d.ts +4 -0
- package/dist/types/entities/knowledge/knowledge.d.ts +35 -0
- package/dist/types/entities/knowledge/record.d.ts +15 -0
- package/dist/types/entities/knowledge/retrival.d.ts +5 -0
- package/dist/types/entities/video.d.ts +4 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/stream/api/clip.d.ts +110 -0
- package/dist/types/stream/api/index.d.ts +2 -0
- package/dist/types/stream/api/talk.d.ts +45 -0
- package/dist/types/stream/index.d.ts +3 -0
- package/dist/types/stream/rtc.d.ts +61 -0
- package/dist/types/stream/stream.d.ts +35 -0
- package/dist/types/tts.d.ts +146 -0
- package/package.json +46 -0
package/README.md
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
function A(o) {
|
|
2
|
+
return o.type === "bearer" ? "Bearer " + o.token : o.type === "basic" ? "Basic " + btoa(`${o.username}:${o.password}`) : "Client-Key " + o.clientKey;
|
|
3
|
+
}
|
|
4
|
+
function h(o, s = "https://api.d-id.com") {
|
|
5
|
+
const n = async (e, t) => {
|
|
6
|
+
const r = await fetch(s + (e != null && e.startsWith("/") ? e : `/${e}`), {
|
|
7
|
+
...t,
|
|
8
|
+
headers: {
|
|
9
|
+
...t == null ? void 0 : t.headers,
|
|
10
|
+
Authorization: A(o),
|
|
11
|
+
"Content-Type": "application/json"
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
if (!r.ok) {
|
|
15
|
+
let a = await r.text().catch(() => "Failed to fetch");
|
|
16
|
+
throw new Error(a);
|
|
17
|
+
}
|
|
18
|
+
return r.json();
|
|
19
|
+
};
|
|
20
|
+
return {
|
|
21
|
+
get(e, t) {
|
|
22
|
+
return n(e, {
|
|
23
|
+
...t,
|
|
24
|
+
method: "GET"
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
post(e, t, r) {
|
|
28
|
+
return n(e, {
|
|
29
|
+
...r,
|
|
30
|
+
body: JSON.stringify(t),
|
|
31
|
+
method: "POST"
|
|
32
|
+
});
|
|
33
|
+
},
|
|
34
|
+
delete(e, t, r) {
|
|
35
|
+
return n(e, {
|
|
36
|
+
...r,
|
|
37
|
+
body: JSON.stringify(t),
|
|
38
|
+
method: "DELETE"
|
|
39
|
+
});
|
|
40
|
+
},
|
|
41
|
+
patch(e, t, r) {
|
|
42
|
+
return n(e, {
|
|
43
|
+
...r,
|
|
44
|
+
body: JSON.stringify(t),
|
|
45
|
+
method: "PATCH"
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function R(o, s = "https://api.d-id.com") {
|
|
51
|
+
const n = h(o, `${s}/agents`);
|
|
52
|
+
return {
|
|
53
|
+
create(e, t) {
|
|
54
|
+
return n.post("/", e, t);
|
|
55
|
+
},
|
|
56
|
+
getAgents(e, t) {
|
|
57
|
+
return n.get(`/${e ? `?tag=${e}` : ""}`, t).then((r) => r ?? []);
|
|
58
|
+
},
|
|
59
|
+
getById(e, t) {
|
|
60
|
+
return n.get(`/${e}`, t);
|
|
61
|
+
},
|
|
62
|
+
delete(e, t) {
|
|
63
|
+
return n.delete(`/${e}`, void 0, t);
|
|
64
|
+
},
|
|
65
|
+
update(e, t, r) {
|
|
66
|
+
return n.patch(`/${e}`, t, r);
|
|
67
|
+
},
|
|
68
|
+
newChat(e, t) {
|
|
69
|
+
return n.post(`/${e}/chat`, void 0, t);
|
|
70
|
+
},
|
|
71
|
+
chat(e, t, r, a) {
|
|
72
|
+
return n.post(`/${e}/chat/${t}`, r, a);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function P(o, s = "https://api.d-id.com") {
|
|
77
|
+
const n = h(o, `${s}/knowledge`);
|
|
78
|
+
return {
|
|
79
|
+
createKnowledge(e, t) {
|
|
80
|
+
return n.post("/", e, t);
|
|
81
|
+
},
|
|
82
|
+
getKnowledgeBase(e) {
|
|
83
|
+
return n.get("/", e);
|
|
84
|
+
},
|
|
85
|
+
getKnowledge(e, t) {
|
|
86
|
+
return n.get(`/${e}`, t);
|
|
87
|
+
},
|
|
88
|
+
deleteKnowledge(e, t) {
|
|
89
|
+
return n.delete(`/${e}`, void 0, t);
|
|
90
|
+
},
|
|
91
|
+
createDocument(e, t, r) {
|
|
92
|
+
return n.post(`/${e}/documents`, t, r);
|
|
93
|
+
},
|
|
94
|
+
deleteDocument(e, t, r) {
|
|
95
|
+
return n.delete(`/${e}/documents/${t}`, void 0, r);
|
|
96
|
+
},
|
|
97
|
+
getDocuments(e, t) {
|
|
98
|
+
return n.get(`/${e}/documents`, t);
|
|
99
|
+
},
|
|
100
|
+
getDocument(e, t, r) {
|
|
101
|
+
return n.get(`/${e}/documents/${t}`, r);
|
|
102
|
+
},
|
|
103
|
+
getRecords(e, t, r) {
|
|
104
|
+
return n.get(`/${e}/documents/${t}/records`, r);
|
|
105
|
+
},
|
|
106
|
+
query(e, t, r) {
|
|
107
|
+
return n.post(`/${e}/query`, {
|
|
108
|
+
query: t
|
|
109
|
+
}, r);
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
var m = /* @__PURE__ */ ((o) => (o[o.START = 0] = "START", o[o.STOP = 1] = "STOP", o))(m || {}), C = /* @__PURE__ */ ((o) => (o.Clip = "clip", o.Talk = "talk", o))(C || {});
|
|
114
|
+
function I(o) {
|
|
115
|
+
return o.presenter.type === C.Clip ? {
|
|
116
|
+
videoType: C.Clip,
|
|
117
|
+
driver_id: o.presenter.driver_id,
|
|
118
|
+
presenter_id: o.presenter.presenter_id
|
|
119
|
+
} : {
|
|
120
|
+
videoType: C.Talk,
|
|
121
|
+
source_url: o.presenter.source_url
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
async function M(o, {
|
|
125
|
+
callbacks: s,
|
|
126
|
+
...n
|
|
127
|
+
}) {
|
|
128
|
+
const e = new AbortController(), t = R(n.auth, n.baseURL), r = await t.getById(o), a = await t.newChat(o), {
|
|
129
|
+
terminate: w,
|
|
130
|
+
sessionId: $,
|
|
131
|
+
streamId: f
|
|
132
|
+
} = await D(I(r), {
|
|
133
|
+
...n,
|
|
134
|
+
callbacks: {
|
|
135
|
+
onSrcObjectReady: s.onSrcObjectReady,
|
|
136
|
+
onVideoStateChange: s == null ? void 0 : s.onVideoStateChange,
|
|
137
|
+
onConnectionStateChange: s.onConnectionStateChange
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
return {
|
|
141
|
+
agent: r,
|
|
142
|
+
terminate() {
|
|
143
|
+
return e.abort(), w();
|
|
144
|
+
},
|
|
145
|
+
chatId: a.id,
|
|
146
|
+
chat(c) {
|
|
147
|
+
return t.chat(o, a.id, {
|
|
148
|
+
sessionId: $,
|
|
149
|
+
streamId: f,
|
|
150
|
+
messages: c
|
|
151
|
+
}, {
|
|
152
|
+
signal: e.signal
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
function O(o, s) {
|
|
158
|
+
const n = h(o, s);
|
|
159
|
+
return {
|
|
160
|
+
createStream(e) {
|
|
161
|
+
return n.post("/clips/streams", {
|
|
162
|
+
driver_id: e.driver_id,
|
|
163
|
+
presenter_id: e.presenter_id,
|
|
164
|
+
compatibility_mode: e.compatibility_mode
|
|
165
|
+
});
|
|
166
|
+
},
|
|
167
|
+
startConnection(e, t, r) {
|
|
168
|
+
return n.post(`/clips/streams/${e}/sdp`, {
|
|
169
|
+
session_id: r,
|
|
170
|
+
answer: t
|
|
171
|
+
});
|
|
172
|
+
},
|
|
173
|
+
addIceCandidate(e, t, r) {
|
|
174
|
+
return n.post(`/clips/streams/${e}/ice`, {
|
|
175
|
+
session_id: r,
|
|
176
|
+
...t
|
|
177
|
+
});
|
|
178
|
+
},
|
|
179
|
+
sendStreamRequest(e, t, r) {
|
|
180
|
+
return n.post(`/clips/streams/${e}`, {
|
|
181
|
+
session_id: t,
|
|
182
|
+
...r
|
|
183
|
+
});
|
|
184
|
+
},
|
|
185
|
+
close(e, t) {
|
|
186
|
+
return n.delete(`/clips/streams/${e}`, {
|
|
187
|
+
session_id: t
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
function v(o, s) {
|
|
193
|
+
const n = h(o, s);
|
|
194
|
+
return {
|
|
195
|
+
createStream(e, t) {
|
|
196
|
+
return n.post("/talks/streams", {
|
|
197
|
+
source_url: e.source_url,
|
|
198
|
+
driver_url: e.driver_url,
|
|
199
|
+
face: e.face,
|
|
200
|
+
config: e.config
|
|
201
|
+
}, t);
|
|
202
|
+
},
|
|
203
|
+
startConnection(e, t, r, a) {
|
|
204
|
+
return n.post(`/talks/streams/${e}/sdp`, {
|
|
205
|
+
session_id: r,
|
|
206
|
+
answer: t
|
|
207
|
+
}, a);
|
|
208
|
+
},
|
|
209
|
+
addIceCandidate(e, t, r, a) {
|
|
210
|
+
return n.post(`/talks/streams/${e}/ice`, {
|
|
211
|
+
session_id: r,
|
|
212
|
+
...t
|
|
213
|
+
}, a);
|
|
214
|
+
},
|
|
215
|
+
sendStreamRequest(e, t, r, a) {
|
|
216
|
+
return n.post(`/talks/streams/${e}`, {
|
|
217
|
+
session_id: t,
|
|
218
|
+
...r
|
|
219
|
+
}, a);
|
|
220
|
+
},
|
|
221
|
+
close(e, t, r) {
|
|
222
|
+
return n.delete(`/talks/streams/${e}`, {
|
|
223
|
+
session_id: t
|
|
224
|
+
}, r);
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
let _ = !1;
|
|
229
|
+
const p = (o, s) => _ && console.log(o, s), K = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
|
|
230
|
+
async function D(o, {
|
|
231
|
+
debug: s = !1,
|
|
232
|
+
callbacks: n,
|
|
233
|
+
auth: e,
|
|
234
|
+
baseURL: t = "https://api.d-id.com"
|
|
235
|
+
}) {
|
|
236
|
+
_ = s;
|
|
237
|
+
const {
|
|
238
|
+
startConnection: r,
|
|
239
|
+
sendStreamRequest: a,
|
|
240
|
+
close: w,
|
|
241
|
+
createStream: $,
|
|
242
|
+
addIceCandidate: f
|
|
243
|
+
} = o.videoType === C.Clip ? O(e, t) : v(e, t), {
|
|
244
|
+
id: c,
|
|
245
|
+
offer: l,
|
|
246
|
+
ice_servers: T,
|
|
247
|
+
session_id: g
|
|
248
|
+
} = await $(o), d = new K({
|
|
249
|
+
iceServers: T
|
|
250
|
+
}), S = d.createDataChannel("JanusDataChannel");
|
|
251
|
+
if (!g)
|
|
252
|
+
throw new Error("Could not create session_id");
|
|
253
|
+
d.onicecandidate = (i) => {
|
|
254
|
+
p("peerConnection.onicecandidate", i), i.candidate && i.candidate.sdpMid && i.candidate.sdpMLineIndex !== null && f(c, {
|
|
255
|
+
candidate: i.candidate.candidate,
|
|
256
|
+
sdpMid: i.candidate.sdpMid,
|
|
257
|
+
sdpMLineIndex: i.candidate.sdpMLineIndex
|
|
258
|
+
}, g);
|
|
259
|
+
}, d.oniceconnectionstatechange = () => {
|
|
260
|
+
var i;
|
|
261
|
+
p("peerConnection.oniceconnectionstatechange => " + d.iceConnectionState), (i = n.onConnectionStateChange) == null || i.call(n, d.iceConnectionState);
|
|
262
|
+
}, d.ontrack = (i) => {
|
|
263
|
+
var u;
|
|
264
|
+
p("peerConnection.ontrack", i), (u = n.onSrcObjectReady) == null || u.call(n, i.streams[0]);
|
|
265
|
+
}, S.onmessage = (i) => {
|
|
266
|
+
var u;
|
|
267
|
+
S.readyState === "open" && ((u = n.onVideoStateChange) == null || u.call(n, i.data === "stream/done" ? m.STOP : m.START));
|
|
268
|
+
}, await d.setRemoteDescription(l), p("set remote description OK");
|
|
269
|
+
const y = await d.createAnswer();
|
|
270
|
+
return p("create answer OK"), await d.setLocalDescription(y), p("set local description OK"), await r(c, y, g), p("start connection OK"), {
|
|
271
|
+
speak(i) {
|
|
272
|
+
return a(c, g, i);
|
|
273
|
+
},
|
|
274
|
+
async terminate() {
|
|
275
|
+
var i, u;
|
|
276
|
+
c && (d && (d.close(), d.oniceconnectionstatechange = null, d.onnegotiationneeded = null, d.onicecandidate = null, d.ontrack = null), await w(c, g), (i = n.onConnectionStateChange) == null || i.call(n, "closed"), (u = n.onVideoStateChange) == null || u.call(n, m.STOP));
|
|
277
|
+
},
|
|
278
|
+
sessionId: g,
|
|
279
|
+
streamId: c
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
export {
|
|
283
|
+
M as createAgentManager,
|
|
284
|
+
R as createAgentsApi,
|
|
285
|
+
h as createClient,
|
|
286
|
+
P as createKnowledgeApi,
|
|
287
|
+
D as createStreamingManager,
|
|
288
|
+
I as getAgentStreamArgs
|
|
289
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(c,C){typeof exports=="object"&&typeof module<"u"?C(exports):typeof define=="function"&&define.amd?define(["exports"],C):(c=typeof globalThis<"u"?globalThis:c||self,C(c.index={}))})(this,function(c){"use strict";function C(i){return i.type==="bearer"?"Bearer "+i.token:i.type==="basic"?"Basic "+btoa(`${i.username}:${i.password}`):"Client-Key "+i.clientKey}function f(i,d="https://api.d-id.com"){const n=async(e,t)=>{const r=await fetch(d+(e!=null&&e.startsWith("/")?e:`/${e}`),{...t,headers:{...t==null?void 0:t.headers,Authorization:C(i),"Content-Type":"application/json"}});if(!r.ok){let a=await r.text().catch(()=>"Failed to fetch");throw new Error(a)}return r.json()};return{get(e,t){return n(e,{...t,method:"GET"})},post(e,t,r){return n(e,{...r,body:JSON.stringify(t),method:"POST"})},delete(e,t,r){return n(e,{...r,body:JSON.stringify(t),method:"DELETE"})},patch(e,t,r){return n(e,{...r,body:JSON.stringify(t),method:"PATCH"})}}}function y(i,d="https://api.d-id.com"){const n=f(i,`${d}/agents`);return{create(e,t){return n.post("/",e,t)},getAgents(e,t){return n.get(`/${e?`?tag=${e}`:""}`,t).then(r=>r??[])},getById(e,t){return n.get(`/${e}`,t)},delete(e,t){return n.delete(`/${e}`,void 0,t)},update(e,t,r){return n.patch(`/${e}`,t,r)},newChat(e,t){return n.post(`/${e}/chat`,void 0,t)},chat(e,t,r,a){return n.post(`/${e}/chat/${t}`,r,a)}}}function v(i,d="https://api.d-id.com"){const n=f(i,`${d}/knowledge`);return{createKnowledge(e,t){return n.post("/",e,t)},getKnowledgeBase(e){return n.get("/",e)},getKnowledge(e,t){return n.get(`/${e}`,t)},deleteKnowledge(e,t){return n.delete(`/${e}`,void 0,t)},createDocument(e,t,r){return n.post(`/${e}/documents`,t,r)},deleteDocument(e,t,r){return n.delete(`/${e}/documents/${t}`,void 0,r)},getDocuments(e,t){return n.get(`/${e}/documents`,t)},getDocument(e,t,r){return n.get(`/${e}/documents/${t}`,r)},getRecords(e,t,r){return n.get(`/${e}/documents/${t}/records`,r)},query(e,t,r){return n.post(`/${e}/query`,{query:t},r)}}}var w=(i=>(i[i.START=0]="START",i[i.STOP=1]="STOP",i))(w||{}),h=(i=>(i.Clip="clip",i.Talk="talk",i))(h||{});function _(i){return i.presenter.type===h.Clip?{videoType:h.Clip,driver_id:i.presenter.driver_id,presenter_id:i.presenter.presenter_id}:{videoType:h.Talk,source_url:i.presenter.source_url}}async function I(i,{callbacks:d,...n}){const e=new AbortController,t=y(n.auth,n.baseURL),r=await t.getById(i),a=await t.newChat(i),{terminate:S,sessionId:$,streamId:l}=await A(_(r),{...n,callbacks:{onSrcObjectReady:d.onSrcObjectReady,onVideoStateChange:d==null?void 0:d.onVideoStateChange,onConnectionStateChange:d.onConnectionStateChange}});return{agent:r,terminate(){return e.abort(),S()},chatId:a.id,chat(u){return t.chat(i,a.id,{sessionId:$,streamId:l,messages:u},{signal:e.signal})}}}function K(i,d){const n=f(i,d);return{createStream(e){return n.post("/clips/streams",{driver_id:e.driver_id,presenter_id:e.presenter_id,compatibility_mode:e.compatibility_mode})},startConnection(e,t,r){return n.post(`/clips/streams/${e}/sdp`,{session_id:r,answer:t})},addIceCandidate(e,t,r){return n.post(`/clips/streams/${e}/ice`,{session_id:r,...t})},sendStreamRequest(e,t,r){return n.post(`/clips/streams/${e}`,{session_id:t,...r})},close(e,t){return n.delete(`/clips/streams/${e}`,{session_id:t})}}}function M(i,d){const n=f(i,d);return{createStream(e,t){return n.post("/talks/streams",{source_url:e.source_url,driver_url:e.driver_url,face:e.face,config:e.config},t)},startConnection(e,t,r,a){return n.post(`/talks/streams/${e}/sdp`,{session_id:r,answer:t},a)},addIceCandidate(e,t,r,a){return n.post(`/talks/streams/${e}/ice`,{session_id:r,...t},a)},sendStreamRequest(e,t,r,a){return n.post(`/talks/streams/${e}`,{session_id:t,...r},a)},close(e,t,r){return n.delete(`/talks/streams/${e}`,{session_id:t},r)}}}let T=!1;const g=(i,d)=>T&&console.log(i,d),P=(window.RTCPeerConnection||window.webkitRTCPeerConnection||window.mozRTCPeerConnection).bind(window);async function A(i,{debug:d=!1,callbacks:n,auth:e,baseURL:t="https://api.d-id.com"}){T=d;const{startConnection:r,sendStreamRequest:a,close:S,createStream:$,addIceCandidate:l}=i.videoType===h.Clip?K(e,t):M(e,t),{id:u,offer:D,ice_servers:j,session_id:m}=await $(i),s=new P({iceServers:j}),R=s.createDataChannel("JanusDataChannel");if(!m)throw new Error("Could not create session_id");s.onicecandidate=o=>{g("peerConnection.onicecandidate",o),o.candidate&&o.candidate.sdpMid&&o.candidate.sdpMLineIndex!==null&&l(u,{candidate:o.candidate.candidate,sdpMid:o.candidate.sdpMid,sdpMLineIndex:o.candidate.sdpMLineIndex},m)},s.oniceconnectionstatechange=()=>{var o;g("peerConnection.oniceconnectionstatechange => "+s.iceConnectionState),(o=n.onConnectionStateChange)==null||o.call(n,s.iceConnectionState)},s.ontrack=o=>{var p;g("peerConnection.ontrack",o),(p=n.onSrcObjectReady)==null||p.call(n,o.streams[0])},R.onmessage=o=>{var p;R.readyState==="open"&&((p=n.onVideoStateChange)==null||p.call(n,o.data==="stream/done"?w.STOP:w.START))},await s.setRemoteDescription(D),g("set remote description OK");const O=await s.createAnswer();return g("create answer OK"),await s.setLocalDescription(O),g("set local description OK"),await r(u,O,m),g("start connection OK"),{speak(o){return a(u,m,o)},async terminate(){var o,p;u&&(s&&(s.close(),s.oniceconnectionstatechange=null,s.onnegotiationneeded=null,s.onicecandidate=null,s.ontrack=null),await S(u,m),(o=n.onConnectionStateChange)==null||o.call(n,"closed"),(p=n.onVideoStateChange)==null||p.call(n,w.STOP))},sessionId:m,streamId:u}}c.createAgentManager=I,c.createAgentsApi=y,c.createClient=f,c.createKnowledgeApi=v,c.createStreamingManager=A,c.getAgentStreamArgs=_,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Agent, AgentPayload, Auth, Chat, ChatPayload, ChatResponse } from '../../types/index';
|
|
2
|
+
export declare function createAgentsApi(auth: Auth, host?: string): {
|
|
3
|
+
create(payload: AgentPayload, options?: RequestInit): Promise<Agent>;
|
|
4
|
+
getAgents(tag?: string, options?: RequestInit): Promise<Agent[]>;
|
|
5
|
+
getById(id: string, options?: RequestInit): Promise<Agent>;
|
|
6
|
+
delete(id: string, options?: RequestInit): Promise<any>;
|
|
7
|
+
update(id: string, payload: AgentPayload, options?: RequestInit): Promise<Agent>;
|
|
8
|
+
newChat(agentId: string, options?: RequestInit): Promise<Chat>;
|
|
9
|
+
chat(agentId: string, chatId: string, payload: ChatPayload, options?: RequestInit): Promise<string | ChatResponse>;
|
|
10
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Auth } from '../../types/auth';
|
|
2
|
+
export declare function createClient(auth: Auth, host?: string): {
|
|
3
|
+
get<T = any>(url: string, options?: RequestInit): Promise<T>;
|
|
4
|
+
post<T_1 = any>(url: string, body?: any, options?: RequestInit): Promise<T_1>;
|
|
5
|
+
delete<T_2 = any>(url: string, body?: any, options?: RequestInit): Promise<T_2>;
|
|
6
|
+
patch<T_3 = any>(url: string, body?: any, options?: RequestInit): Promise<T_3>;
|
|
7
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Auth, CreateDocumentPayload, DocumentData, KnowledgeData, KnowledgePayload, QueryResult, RecordData } from '../../types/index';
|
|
2
|
+
export declare function createKnowledgeApi(auth: Auth, host?: string): {
|
|
3
|
+
createKnowledge(payload: KnowledgePayload, options?: RequestInit): Promise<KnowledgeData>;
|
|
4
|
+
getKnowledgeBase(options?: RequestInit): Promise<KnowledgeData[]>;
|
|
5
|
+
getKnowledge(knowledgeId: string, options?: RequestInit): Promise<KnowledgeData>;
|
|
6
|
+
deleteKnowledge(knowledgeId: string, options?: RequestInit): Promise<any>;
|
|
7
|
+
createDocument(knowledgeId: string, payload: CreateDocumentPayload, options?: RequestInit): Promise<DocumentData>;
|
|
8
|
+
deleteDocument(knowledgeId: string, documentId: string, options?: RequestInit): Promise<any>;
|
|
9
|
+
getDocuments(knowledgeId: string, options?: RequestInit): Promise<DocumentData[]>;
|
|
10
|
+
getDocument(knowledgeId: string, documentId: string, options?: RequestInit): Promise<DocumentData>;
|
|
11
|
+
getRecords(knowledgeId: string, documentId: string, options?: RequestInit): Promise<RecordData[]>;
|
|
12
|
+
query(knowledgeId: string, query: string, options?: RequestInit): Promise<QueryResult>;
|
|
13
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Agent, AgentManagerOptions, CreateStreamOptions, Message } from '../types/index';
|
|
2
|
+
export declare function getAgentStreamArgs(agent: Agent): CreateStreamOptions;
|
|
3
|
+
export declare function createAgentManager(agentId: string, { callbacks, ...options }: AgentManagerOptions): Promise<{
|
|
4
|
+
agent: Agent;
|
|
5
|
+
terminate(): Promise<void>;
|
|
6
|
+
chatId: string;
|
|
7
|
+
chat(messages: Message[]): Promise<string | import('../types/index').ChatResponse>;
|
|
8
|
+
}>;
|
|
9
|
+
export type AgentManager = Awaited<ReturnType<typeof createAgentManager>>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CreateStreamOptions, PayloadType, StreamingManagerOptions } from '../types/index';
|
|
2
|
+
export declare function createStreamingManager<T extends CreateStreamOptions>(agent: T, { debug, callbacks, auth, baseURL }: StreamingManagerOptions): Promise<{
|
|
3
|
+
speak(payload: PayloadType<T>): Promise<import('../types/index').SendStreamPayloadResponse>;
|
|
4
|
+
terminate(): Promise<void>;
|
|
5
|
+
sessionId: string;
|
|
6
|
+
streamId: string;
|
|
7
|
+
}>;
|
|
8
|
+
export type StreamingManager<T extends CreateStreamOptions> = Awaited<ReturnType<typeof createStreamingManager<T>>>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { StreamTextToSpeechProviders } from './tts';
|
|
2
|
+
export type StreamScriptType = 'text' | 'audio';
|
|
3
|
+
export interface BaseStreamScript {
|
|
4
|
+
type: StreamScriptType;
|
|
5
|
+
}
|
|
6
|
+
export interface Stream_Text_Script extends BaseStreamScript {
|
|
7
|
+
/**
|
|
8
|
+
* The type of the script.
|
|
9
|
+
*/
|
|
10
|
+
type: 'text';
|
|
11
|
+
/**
|
|
12
|
+
* text-to-speech provider from list of supported providers. default is microsoft tts
|
|
13
|
+
*/
|
|
14
|
+
provider?: StreamTextToSpeechProviders;
|
|
15
|
+
/**
|
|
16
|
+
* The input text that will be synthesized to an audio file.
|
|
17
|
+
* Note that each provider has its own limitations on the text length.
|
|
18
|
+
* @example "This is an example text"
|
|
19
|
+
* @maxLength 40000
|
|
20
|
+
* @minLength 3
|
|
21
|
+
*/
|
|
22
|
+
input: string;
|
|
23
|
+
/**
|
|
24
|
+
* Is the text provided in ssml form.
|
|
25
|
+
* @default false
|
|
26
|
+
*/
|
|
27
|
+
ssml?: boolean;
|
|
28
|
+
}
|
|
29
|
+
export interface Stream_Audio_Script extends BaseStreamScript {
|
|
30
|
+
/**
|
|
31
|
+
* The type of the script.
|
|
32
|
+
*/
|
|
33
|
+
type: 'audio';
|
|
34
|
+
/**
|
|
35
|
+
* The URL of the audio file which will be used by the actor.
|
|
36
|
+
* File size is limit to 15MB.
|
|
37
|
+
*/
|
|
38
|
+
audio_url: string;
|
|
39
|
+
}
|
|
40
|
+
export type StreamScript = Stream_Text_Script | Stream_Audio_Script;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface BearerToken {
|
|
2
|
+
type: 'bearer';
|
|
3
|
+
token: string;
|
|
4
|
+
}
|
|
5
|
+
export interface BasicAuth {
|
|
6
|
+
type: 'basic';
|
|
7
|
+
username: string;
|
|
8
|
+
password: string;
|
|
9
|
+
}
|
|
10
|
+
export interface ApiKeyAuth {
|
|
11
|
+
type: 'key';
|
|
12
|
+
clientKey: string;
|
|
13
|
+
}
|
|
14
|
+
export type Auth = BearerToken | BasicAuth | ApiKeyAuth;
|
|
15
|
+
export interface GetAuthParams {
|
|
16
|
+
token?: string | null;
|
|
17
|
+
username?: string | null;
|
|
18
|
+
password?: string | null;
|
|
19
|
+
clientKey?: string | null;
|
|
20
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Knowledge } from './knowledge';
|
|
2
|
+
import { LLM } from './llm';
|
|
3
|
+
import { Presenter } from './presenter';
|
|
4
|
+
export interface Agent {
|
|
5
|
+
id: string;
|
|
6
|
+
username?: string;
|
|
7
|
+
presenter: Presenter;
|
|
8
|
+
llm?: LLM;
|
|
9
|
+
knowledge?: Knowledge;
|
|
10
|
+
use_case?: string;
|
|
11
|
+
tags?: string[];
|
|
12
|
+
chats?: number;
|
|
13
|
+
access?: 'private' | 'pending-public' | 'unlisted' | 'rejected' | 'public';
|
|
14
|
+
preview_name?: string;
|
|
15
|
+
preview_description?: string;
|
|
16
|
+
preview_thumbnail?: string;
|
|
17
|
+
}
|
|
18
|
+
export type AgentPayload = Omit<Agent, 'type' | 'created_at' | 'modified_at' | 'id' | 'owner_id' | 'idle_video_url'>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export interface Message {
|
|
2
|
+
role: 'system' | 'assistant' | 'user' | 'function' | 'tool';
|
|
3
|
+
content: string;
|
|
4
|
+
name?: string;
|
|
5
|
+
created_at: string;
|
|
6
|
+
}
|
|
7
|
+
export interface ChatPayload {
|
|
8
|
+
messages: Message[];
|
|
9
|
+
streamId: string;
|
|
10
|
+
sessionId: string;
|
|
11
|
+
}
|
|
12
|
+
export interface IRetrivalMetadata {
|
|
13
|
+
id: string;
|
|
14
|
+
data: string;
|
|
15
|
+
title: string;
|
|
16
|
+
document_id: string;
|
|
17
|
+
knowledge_id: string;
|
|
18
|
+
source_url: string;
|
|
19
|
+
}
|
|
20
|
+
export interface ChatResponse {
|
|
21
|
+
result: string;
|
|
22
|
+
documentIds?: string[];
|
|
23
|
+
matches?: IRetrivalMetadata[];
|
|
24
|
+
}
|
|
25
|
+
export interface Chat {
|
|
26
|
+
id: string;
|
|
27
|
+
agent_id: string;
|
|
28
|
+
created: string;
|
|
29
|
+
modified: string;
|
|
30
|
+
owner_id: string;
|
|
31
|
+
messages: Message[];
|
|
32
|
+
agent_id__created_at: string;
|
|
33
|
+
agent_id__modified_at: string;
|
|
34
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type LLMType = 'knowledge' | 'custom';
|
|
2
|
+
export type LLM = KnowledgeLLM | CustomLLM;
|
|
3
|
+
export interface BaseLLM {
|
|
4
|
+
type: LLMType;
|
|
5
|
+
instructions?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface KnowledgeLLM extends BaseLLM {
|
|
8
|
+
type: 'knowledge';
|
|
9
|
+
knowledge_id: string;
|
|
10
|
+
store?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface CustomLLM extends BaseLLM {
|
|
13
|
+
type: 'custom';
|
|
14
|
+
api_key?: string;
|
|
15
|
+
model?: string;
|
|
16
|
+
provider?: string;
|
|
17
|
+
version?: string;
|
|
18
|
+
config?: string;
|
|
19
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Auth } from '../../auth';
|
|
2
|
+
import { StreamingState } from '../../stream';
|
|
3
|
+
declare enum ChatProgress {
|
|
4
|
+
Embed = 0,
|
|
5
|
+
Query = 1,
|
|
6
|
+
Answer = 2,
|
|
7
|
+
Complete = 3
|
|
8
|
+
}
|
|
9
|
+
interface ManagerCallbacks {
|
|
10
|
+
onConnectionStateChange?(state: RTCIceConnectionState): void;
|
|
11
|
+
onVideoStateChange?(state: StreamingState): void;
|
|
12
|
+
onSrcObjectReady?(srcObject: MediaStream): void;
|
|
13
|
+
onChatEvents?(progress: ChatProgress): void;
|
|
14
|
+
}
|
|
15
|
+
export interface AgentManagerOptions {
|
|
16
|
+
callbacks: ManagerCallbacks;
|
|
17
|
+
baseURL?: string;
|
|
18
|
+
debug?: boolean;
|
|
19
|
+
auth: Auth;
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ExtendedTextToSpeechProviders } from '../../tts';
|
|
2
|
+
export type videoType = 'talk' | 'clip';
|
|
3
|
+
export type Presenter = TalkPresenter | ClipPresenter;
|
|
4
|
+
export interface BasePresenter {
|
|
5
|
+
type: videoType;
|
|
6
|
+
voice?: ExtendedTextToSpeechProviders;
|
|
7
|
+
idle_video?: string;
|
|
8
|
+
thumbnail?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface TalkPresenter extends BasePresenter {
|
|
11
|
+
type: 'talk';
|
|
12
|
+
source_url: string;
|
|
13
|
+
driver_url?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface ClipPresenter extends BasePresenter {
|
|
16
|
+
type: 'clip';
|
|
17
|
+
driver_id: string;
|
|
18
|
+
background?: string;
|
|
19
|
+
presenter_id: string;
|
|
20
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { KnowledgeType } from './knowledge';
|
|
2
|
+
export declare enum Subject {
|
|
3
|
+
KnowledgeProcessing = "knowledge/processing",
|
|
4
|
+
KnowledgeIndexing = "knowledge/indexing",
|
|
5
|
+
KnowledgeFailed = "knowledge/error",
|
|
6
|
+
KnowledgeDone = "knowledge/done"
|
|
7
|
+
}
|
|
8
|
+
export interface DocumentData {
|
|
9
|
+
created_at: string;
|
|
10
|
+
modified_at: string;
|
|
11
|
+
owner_id: string;
|
|
12
|
+
id: string;
|
|
13
|
+
created_by: string;
|
|
14
|
+
status: Subject;
|
|
15
|
+
documentType: DocumentType;
|
|
16
|
+
type: KnowledgeType;
|
|
17
|
+
source_url: string;
|
|
18
|
+
parsed_url: string;
|
|
19
|
+
title: string;
|
|
20
|
+
}
|
|
21
|
+
export type CreateDocumentPayload = Omit<DocumentData, 'created_by' | 'parsed_url' | 'status' | 'type' | 'created_at' | 'modified_at' | 'id' | 'owner_id'>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export declare enum KnowledgeType {
|
|
2
|
+
Knowledge = "knowledge",
|
|
3
|
+
Document = "document",
|
|
4
|
+
Record = "record"
|
|
5
|
+
}
|
|
6
|
+
export declare enum DocumentType {
|
|
7
|
+
Pdf = "pdf",
|
|
8
|
+
Text = "text",
|
|
9
|
+
Html = "html",
|
|
10
|
+
Word = "word",
|
|
11
|
+
Json = "json",
|
|
12
|
+
Markdown = "markdown",
|
|
13
|
+
Csv = "csv",
|
|
14
|
+
Excel = "excel",
|
|
15
|
+
Powerpoint = "powerpoint",
|
|
16
|
+
Archive = "archive",
|
|
17
|
+
Image = "image",
|
|
18
|
+
Audio = "audio",
|
|
19
|
+
Video = "video"
|
|
20
|
+
}
|
|
21
|
+
export interface IParserResult {
|
|
22
|
+
data: string;
|
|
23
|
+
}
|
|
24
|
+
export interface KnowledgeData {
|
|
25
|
+
created_at: string;
|
|
26
|
+
modified_at: string;
|
|
27
|
+
owner_id: string;
|
|
28
|
+
id: string;
|
|
29
|
+
created_by: string;
|
|
30
|
+
type: KnowledgeType;
|
|
31
|
+
vector_store: string;
|
|
32
|
+
description: string;
|
|
33
|
+
name: string;
|
|
34
|
+
}
|
|
35
|
+
export type KnowledgePayload = Omit<KnowledgeData, 'created_by' | 'type' | 'created_at' | 'modified_at' | 'id' | 'owner_id'>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { KnowledgeType } from './knowledge';
|
|
2
|
+
export interface RecordData {
|
|
3
|
+
created_at: string;
|
|
4
|
+
modified_at: string;
|
|
5
|
+
owner_id: string;
|
|
6
|
+
id: string;
|
|
7
|
+
created_by: string;
|
|
8
|
+
type: KnowledgeType;
|
|
9
|
+
embedding_id: string;
|
|
10
|
+
start_index: number;
|
|
11
|
+
source_url: string;
|
|
12
|
+
title: string;
|
|
13
|
+
data: string;
|
|
14
|
+
}
|
|
15
|
+
export type CreateRecordPayload = Omit<RecordData, 'created_by' | 'type' | 'created_at' | 'modified_at' | 'id' | 'owner_id'>;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { StickyRequest, StreamScript } from '../..';
|
|
2
|
+
import { CompatibilityMode } from '../stream';
|
|
3
|
+
interface Logo {
|
|
4
|
+
/**
|
|
5
|
+
* https url to an ARGB jpg/png image, a default logo is used otherwise
|
|
6
|
+
* @pattern ((https|s3):\/\/.+) must be a valid https URL
|
|
7
|
+
* @example https://url.to/image.png
|
|
8
|
+
*/
|
|
9
|
+
url: string;
|
|
10
|
+
/**
|
|
11
|
+
* position of the logo in pixels from the top left corner (w,h) negative values are subtracted from last pixel
|
|
12
|
+
* @example [0, 500]
|
|
13
|
+
* @minItems 2
|
|
14
|
+
* @maxItems 2
|
|
15
|
+
* @isInt
|
|
16
|
+
*/
|
|
17
|
+
position: number[];
|
|
18
|
+
}
|
|
19
|
+
interface ClipConfig {
|
|
20
|
+
logo?: Logo | boolean;
|
|
21
|
+
/** File format of the animated result
|
|
22
|
+
* @default mp4
|
|
23
|
+
*/
|
|
24
|
+
result_format?: 'mp4' | 'gif' | 'mov' | 'webm';
|
|
25
|
+
}
|
|
26
|
+
export interface CreateClipStreamRequest {
|
|
27
|
+
/**
|
|
28
|
+
* ID of the selected presenter.
|
|
29
|
+
* @example "rian-lZC6MmWfC1"
|
|
30
|
+
*/
|
|
31
|
+
presenter_id: string;
|
|
32
|
+
/**
|
|
33
|
+
* ID of the selected driver.
|
|
34
|
+
* If not provided a driver video will be selected for you from the predefined drivers bank.
|
|
35
|
+
* @example "mXra4jY38i"
|
|
36
|
+
*/
|
|
37
|
+
driver_id?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Defines the video codec to be used in the stream.
|
|
40
|
+
* When set to on: VP8 will be used.
|
|
41
|
+
* When set to off: H264 will be used
|
|
42
|
+
* When set to auto the codec will be selected according to the browser.
|
|
43
|
+
* @default auto
|
|
44
|
+
*/
|
|
45
|
+
compatibility_mode?: CompatibilityMode;
|
|
46
|
+
}
|
|
47
|
+
export interface SendClipStreamPayload extends StickyRequest {
|
|
48
|
+
script: StreamScript;
|
|
49
|
+
/**
|
|
50
|
+
* Advanced configuration options.
|
|
51
|
+
*/
|
|
52
|
+
config?: ClipConfig;
|
|
53
|
+
/**
|
|
54
|
+
* The user created the clip.
|
|
55
|
+
*/
|
|
56
|
+
created_by?: string;
|
|
57
|
+
/**
|
|
58
|
+
* Advanced presenter configuration options.
|
|
59
|
+
*/
|
|
60
|
+
presenter_config?: {
|
|
61
|
+
crop?: {
|
|
62
|
+
/**
|
|
63
|
+
* The type of the crop.
|
|
64
|
+
*/
|
|
65
|
+
type: 'rectangle';
|
|
66
|
+
/**
|
|
67
|
+
* A set of numbers between 0 and 1 representing the top, left, right and bottom of the crop.
|
|
68
|
+
* Each number correlates to the distance from the top left corner of the image, relative the the image width.
|
|
69
|
+
* For example, right: 0.75 means that the right side of the crop is 75% of the image width from the left side.
|
|
70
|
+
*/
|
|
71
|
+
rectangle: {
|
|
72
|
+
top: number;
|
|
73
|
+
left: number;
|
|
74
|
+
right: number;
|
|
75
|
+
bottom: number;
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Background color of the clip result
|
|
81
|
+
*/
|
|
82
|
+
background?: {
|
|
83
|
+
/**
|
|
84
|
+
* Background color of the animated result, or false to use transparent background in-case of webm result format.
|
|
85
|
+
* @example "#47ffff"
|
|
86
|
+
* @pattern ^#[a-fA-F0-9]{6}$ must be a valid 6-characters long color css code
|
|
87
|
+
*/
|
|
88
|
+
color?: string | false;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Non-sensitive custom data that will be added to the clip response and webhook.
|
|
92
|
+
*/
|
|
93
|
+
user_data?: string;
|
|
94
|
+
/**
|
|
95
|
+
* The name of the clip
|
|
96
|
+
*/
|
|
97
|
+
name?: string;
|
|
98
|
+
/**
|
|
99
|
+
* The URL of the clip video, if not provided use default destination.
|
|
100
|
+
* @example "https://path.to.directory/"
|
|
101
|
+
*/
|
|
102
|
+
result_url?: string;
|
|
103
|
+
/**
|
|
104
|
+
* The URL of the raw clip video, if not provided use default destination.
|
|
105
|
+
* @hidden
|
|
106
|
+
* @example "https://path.to.directory/"
|
|
107
|
+
*/
|
|
108
|
+
raw_result_url?: string;
|
|
109
|
+
}
|
|
110
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { StreamScript } from '../..';
|
|
2
|
+
export interface CreateTalkStreamRequest {
|
|
3
|
+
source_url: string;
|
|
4
|
+
driver_url?: string;
|
|
5
|
+
face?: {
|
|
6
|
+
size: number;
|
|
7
|
+
top_left: [number, number];
|
|
8
|
+
overlap?: 'NO' | 'YES' | 'PARTIAL' | 'UNKNOWN';
|
|
9
|
+
face_id?: string;
|
|
10
|
+
detect_confidence?: number;
|
|
11
|
+
detection?: {
|
|
12
|
+
top: number;
|
|
13
|
+
left: number;
|
|
14
|
+
right: number;
|
|
15
|
+
bottom: number;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
config?: {
|
|
19
|
+
motion_factor?: number;
|
|
20
|
+
align_expand_factor?: number;
|
|
21
|
+
stitch?: boolean;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export interface SendTalkStreamPayload {
|
|
25
|
+
script: StreamScript;
|
|
26
|
+
resultUrl?: string;
|
|
27
|
+
config?: {
|
|
28
|
+
align_driver?: boolean;
|
|
29
|
+
auto_match?: boolean;
|
|
30
|
+
normalization_factor?: number;
|
|
31
|
+
sharpen?: boolean;
|
|
32
|
+
result_format?: 'mp4' | 'gif' | 'mov';
|
|
33
|
+
fluent?: boolean;
|
|
34
|
+
driver_expressions?: {
|
|
35
|
+
expressions: {
|
|
36
|
+
start_frame: number;
|
|
37
|
+
expression: string;
|
|
38
|
+
intensity: number;
|
|
39
|
+
};
|
|
40
|
+
transition_frames?: number;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
user_data?: Record<string, any>;
|
|
44
|
+
name?: string;
|
|
45
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export interface StickyRequest {
|
|
2
|
+
/**
|
|
3
|
+
* session identifier information, should be returned in the body of all streaming requests
|
|
4
|
+
*/
|
|
5
|
+
session_id?: string;
|
|
6
|
+
}
|
|
7
|
+
interface Jsep {
|
|
8
|
+
/**
|
|
9
|
+
* The type of the message - should normally be `answer` when replying to the offer
|
|
10
|
+
*/
|
|
11
|
+
type: 'offer' | 'answer';
|
|
12
|
+
/**
|
|
13
|
+
* Describe the media communication sessions to accept the session the is being negotiated
|
|
14
|
+
*/
|
|
15
|
+
sdp: string;
|
|
16
|
+
}
|
|
17
|
+
export interface IceServer {
|
|
18
|
+
/**
|
|
19
|
+
* URL of the server - can be multiple addresses
|
|
20
|
+
*/
|
|
21
|
+
urls: string[] | string;
|
|
22
|
+
/**
|
|
23
|
+
* Username for authentication
|
|
24
|
+
*/
|
|
25
|
+
username?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Credintials for secure connection to the server
|
|
28
|
+
*/
|
|
29
|
+
credential?: string;
|
|
30
|
+
}
|
|
31
|
+
export interface ICreateStreamRequestResponse extends StickyRequest {
|
|
32
|
+
id: string;
|
|
33
|
+
jsep: Jsep;
|
|
34
|
+
offer: any;
|
|
35
|
+
ice_servers: IceServer[];
|
|
36
|
+
}
|
|
37
|
+
export interface IceCandidate {
|
|
38
|
+
/**
|
|
39
|
+
* A string representing the transport address for the candidate that can be used for connectivity checks.
|
|
40
|
+
* The format of this address is a candidate-attribute as defined in RFC 5245. This string is empty ("") if the
|
|
41
|
+
* RTCIceCandidate is an "end of candidates" indicator.
|
|
42
|
+
*/
|
|
43
|
+
candidate: string;
|
|
44
|
+
/**
|
|
45
|
+
* A string specifying the candidate's media stream identification tag which uniquely identifies the media stream
|
|
46
|
+
* within the component with which the candidate is associated, or null if no such association exists.
|
|
47
|
+
*/
|
|
48
|
+
sdpMid: string;
|
|
49
|
+
/**
|
|
50
|
+
* If not null, sdpMLineIndex indicates the zero-based index number of the media description (as defined in RFC
|
|
51
|
+
* 4566) in the SDP with which the candidate is associated.
|
|
52
|
+
*/
|
|
53
|
+
sdpMLineIndex: number;
|
|
54
|
+
}
|
|
55
|
+
export interface Status {
|
|
56
|
+
status: string;
|
|
57
|
+
}
|
|
58
|
+
export interface SendStreamPayloadResponse extends Status, StickyRequest {
|
|
59
|
+
duration: number;
|
|
60
|
+
}
|
|
61
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Auth } from '../auth';
|
|
2
|
+
import { VideoType } from '../entities';
|
|
3
|
+
import { CreateClipStreamRequest, CreateTalkStreamRequest, SendClipStreamPayload, SendTalkStreamPayload } from './api';
|
|
4
|
+
import { ICreateStreamRequestResponse, IceCandidate, SendStreamPayloadResponse, Status } from './rtc';
|
|
5
|
+
export type CompatibilityMode = 'on' | 'off' | 'auto';
|
|
6
|
+
export declare enum StreamingState {
|
|
7
|
+
START = 0,
|
|
8
|
+
STOP = 1
|
|
9
|
+
}
|
|
10
|
+
export interface ManagerCallbacks {
|
|
11
|
+
onConnectionStateChange?: (state: RTCIceConnectionState) => void;
|
|
12
|
+
onVideoStateChange?: (state: StreamingState) => void;
|
|
13
|
+
onSrcObjectReady?: (value: MediaStream) => void;
|
|
14
|
+
}
|
|
15
|
+
export interface TalkStreamOptions extends CreateTalkStreamRequest {
|
|
16
|
+
videoType: VideoType.Talk;
|
|
17
|
+
}
|
|
18
|
+
export interface ClipStreamOptions extends CreateClipStreamRequest {
|
|
19
|
+
videoType: VideoType.Clip;
|
|
20
|
+
}
|
|
21
|
+
export type CreateStreamOptions = TalkStreamOptions | ClipStreamOptions;
|
|
22
|
+
export type PayloadType<T> = T extends TalkStreamOptions ? SendTalkStreamPayload : T extends ClipStreamOptions ? SendClipStreamPayload : never;
|
|
23
|
+
export interface RtcApi {
|
|
24
|
+
createStream(options: CreateStreamOptions): Promise<ICreateStreamRequestResponse>;
|
|
25
|
+
startConnection(streamId: string, answer: RTCSessionDescriptionInit, sessionId?: string): Promise<Status>;
|
|
26
|
+
addIceCandidate(streamId: string, candidate: IceCandidate, sessionId: string): Promise<Status>;
|
|
27
|
+
sendStreamRequest(streamId: string, sessionId: string, payload: SendClipStreamPayload | SendTalkStreamPayload): Promise<SendStreamPayloadResponse>;
|
|
28
|
+
close(streamId: string, sessionId: string): Promise<Status>;
|
|
29
|
+
}
|
|
30
|
+
export interface StreamingManagerOptions {
|
|
31
|
+
callbacks: ManagerCallbacks;
|
|
32
|
+
baseURL?: string;
|
|
33
|
+
debug?: boolean;
|
|
34
|
+
auth: Auth;
|
|
35
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
export declare enum Providers {
|
|
2
|
+
Amazon = "amazon",
|
|
3
|
+
Microsoft = "microsoft",
|
|
4
|
+
Afflorithmics = "afflorithmics",
|
|
5
|
+
Elevenlabs = "elevenlabs"
|
|
6
|
+
}
|
|
7
|
+
export declare enum VoiceAccess {
|
|
8
|
+
Public = "public",
|
|
9
|
+
Premium = "premium",
|
|
10
|
+
Private = "private"
|
|
11
|
+
}
|
|
12
|
+
export interface IVoice {
|
|
13
|
+
id: string;
|
|
14
|
+
name: string;
|
|
15
|
+
gender: string;
|
|
16
|
+
locale: string;
|
|
17
|
+
access: VoiceAccess;
|
|
18
|
+
provider: Providers;
|
|
19
|
+
styles: string[];
|
|
20
|
+
language: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Elevenlabs provider details, contains the provider type and requested voice id, available for premium users.
|
|
24
|
+
*/
|
|
25
|
+
export interface Elevenlabs_tts_provider {
|
|
26
|
+
type: Providers.Elevenlabs;
|
|
27
|
+
/**
|
|
28
|
+
* The voice_id from the list of available voices. https://api.elevenlabs.io/v1/voices.
|
|
29
|
+
* @example "21m00Tcm4TlvDq8ikWAM"
|
|
30
|
+
* @default 21m00Tcm4TlvDq8ikWAM
|
|
31
|
+
*/
|
|
32
|
+
voice_id: string;
|
|
33
|
+
/**
|
|
34
|
+
* Voice customization options. Read more here: https://docs.elevenlabs.io/speech-synthesis/voice-settings
|
|
35
|
+
*/
|
|
36
|
+
voice_config?: VoiceConfigElevenlabs;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Afflorithmics provider details, contains the provider type and requested voice id, available for enterprise users.
|
|
40
|
+
*/
|
|
41
|
+
export interface Afflorithmics_tts_provider {
|
|
42
|
+
type: Providers.Afflorithmics;
|
|
43
|
+
/**
|
|
44
|
+
* The voice_id from the list of available voices.
|
|
45
|
+
* @example "abc123DEF456"
|
|
46
|
+
* @default abc123DEF456
|
|
47
|
+
*/
|
|
48
|
+
voice_id: string;
|
|
49
|
+
/**
|
|
50
|
+
* Voice customization options. Read more here: https://docs.audiostack.ai/reference/postspeech
|
|
51
|
+
*/
|
|
52
|
+
voice_config?: VoiceConfigAfflorithmics;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* AzureMicrosoft provider details, contains the provider type and requested voice id and style
|
|
56
|
+
*/
|
|
57
|
+
export interface Microsoft_tts_provider {
|
|
58
|
+
type: Providers.Microsoft;
|
|
59
|
+
/**
|
|
60
|
+
* The voice_id from the list of available voices.
|
|
61
|
+
* For full list of voice_ids: https://docs.d-id.com/reference/microsoft-azure
|
|
62
|
+
* @example "en-US-JennyNeural"
|
|
63
|
+
* @default en-US-JennyNeural
|
|
64
|
+
*/
|
|
65
|
+
voice_id: string;
|
|
66
|
+
/**
|
|
67
|
+
* Voice customization options
|
|
68
|
+
*/
|
|
69
|
+
voice_config?: VoiceConfigMicrosoft;
|
|
70
|
+
/**
|
|
71
|
+
* Voice name
|
|
72
|
+
*/
|
|
73
|
+
voice_name?: string;
|
|
74
|
+
/**
|
|
75
|
+
* Voice language
|
|
76
|
+
*/
|
|
77
|
+
voice_language?: string;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Amazon provider details, contains the provider type and requested voice id
|
|
81
|
+
*/
|
|
82
|
+
export interface Amazon_tts_provider {
|
|
83
|
+
type: Providers.Amazon;
|
|
84
|
+
/**
|
|
85
|
+
* The voice_id from the list of available voices.
|
|
86
|
+
* For full list of voice_ids: https://docs.d-id.com/reference/text-to-speech-providers
|
|
87
|
+
* @example "Joanna"
|
|
88
|
+
*/
|
|
89
|
+
voice_id: string;
|
|
90
|
+
}
|
|
91
|
+
export interface VoiceConfigMicrosoft {
|
|
92
|
+
/**
|
|
93
|
+
* The style of the voice.
|
|
94
|
+
* Available styles change between voices.
|
|
95
|
+
*/
|
|
96
|
+
style?: string;
|
|
97
|
+
/**
|
|
98
|
+
* The speed of the voice.
|
|
99
|
+
* The value is relative to 1, 0.5 being half speed, 2 being twice as fast, etc.
|
|
100
|
+
* Another option is a constant value from x-slow/slow/medium/fast/x-fast.
|
|
101
|
+
* @example "0.5"
|
|
102
|
+
*/
|
|
103
|
+
rate?: string;
|
|
104
|
+
/**
|
|
105
|
+
* The pitch of the voice.
|
|
106
|
+
* Value could be an absolute value in Hz (including units), a relative value in Hz or st(semitones)
|
|
107
|
+
* or a constant value from x-low/low/medium/high/x-high.
|
|
108
|
+
* @example "+2st"
|
|
109
|
+
*/
|
|
110
|
+
pitch?: string;
|
|
111
|
+
}
|
|
112
|
+
export interface VoiceConfigElevenlabs {
|
|
113
|
+
/**
|
|
114
|
+
* How stable the voice is and the randomness of each new generation.
|
|
115
|
+
* @example "0"
|
|
116
|
+
*/
|
|
117
|
+
stability?: number;
|
|
118
|
+
/**
|
|
119
|
+
* The similarity slider dictates how closely the AI should adhere to the original voice when attempting to replicate it.
|
|
120
|
+
* @example "0"
|
|
121
|
+
*/
|
|
122
|
+
similarity_boost?: number;
|
|
123
|
+
}
|
|
124
|
+
export interface VoiceConfigAfflorithmics {
|
|
125
|
+
/**
|
|
126
|
+
* The speed of the voice.
|
|
127
|
+
* The value is relative to 1, 0.5 being half speed, 2 being twice as fast, etc.
|
|
128
|
+
* Another option is a constant value from x-slow/slow/medium/fast/x-fast.
|
|
129
|
+
* @example "1.2"
|
|
130
|
+
* @min 0.5
|
|
131
|
+
* @max 1.5
|
|
132
|
+
* @default 1
|
|
133
|
+
*/
|
|
134
|
+
rate?: string;
|
|
135
|
+
/**
|
|
136
|
+
* Amount of microseconds for silence padding. Half of the amount is inserted as silence at the beginning and at the end of each Speech file.
|
|
137
|
+
*/
|
|
138
|
+
silencePadding?: number;
|
|
139
|
+
/**
|
|
140
|
+
* Flag to apply lexicographical text corrections
|
|
141
|
+
*/
|
|
142
|
+
voiceIntelligence?: boolean;
|
|
143
|
+
}
|
|
144
|
+
export type TextToSpeechProviders = Microsoft_tts_provider | Afflorithmics_tts_provider | Elevenlabs_tts_provider;
|
|
145
|
+
export type ExtendedTextToSpeechProviders = TextToSpeechProviders | Amazon_tts_provider;
|
|
146
|
+
export type StreamTextToSpeechProviders = Microsoft_tts_provider | Afflorithmics_tts_provider | Elevenlabs_tts_provider | Amazon_tts_provider;
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@d-id/client-sdk",
|
|
3
|
+
"private": false,
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"description": "d-id client sdk",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/de-id/agents-sdk"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"d-id",
|
|
13
|
+
"sdk",
|
|
14
|
+
"client-sdk"
|
|
15
|
+
],
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"author": "d-id",
|
|
18
|
+
"files": [
|
|
19
|
+
"dist/*"
|
|
20
|
+
],
|
|
21
|
+
"main": "./dist/index.umd.cjs",
|
|
22
|
+
"module": "./dist/index.js",
|
|
23
|
+
"types": "./dist/types/index.d.ts",
|
|
24
|
+
"scripts": {
|
|
25
|
+
"dev": "vite",
|
|
26
|
+
"build": "node ./infra/build.js -m production",
|
|
27
|
+
"build:dev": "node ./infra/build.js -m development",
|
|
28
|
+
"deploy:prod": "node ./infra/deploy.js --version patch",
|
|
29
|
+
"preview": "vite preview",
|
|
30
|
+
"test-build": "node .infra/build.js -m development"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@preact/preset-vite": "^2.5.0",
|
|
34
|
+
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
|
|
35
|
+
"commander": "^11.1.0",
|
|
36
|
+
"glob": "^10.3.10",
|
|
37
|
+
"preact": "^10.5.13",
|
|
38
|
+
"prettier": "^3.1.0",
|
|
39
|
+
"prettier-plugin-organize-imports": "^3.2.4",
|
|
40
|
+
"serverless": "3.32.2",
|
|
41
|
+
"typescript": "^5.3.2",
|
|
42
|
+
"vite": "^4.4.5",
|
|
43
|
+
"vite-plugin-dts": "^3.6.0",
|
|
44
|
+
"vite-plugin-html-env": "^1.2.8"
|
|
45
|
+
}
|
|
46
|
+
}
|