@d-id/client-sdk 1.0.15 → 1.0.17
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/dist/apps/sdk/lib/api/agents.d.ts +1 -1
- package/dist/apps/sdk/lib/api/ratings.d.ts +9 -0
- package/dist/apps/sdk/lib/createAgentManager.d.ts +1 -1
- package/dist/apps/sdk/lib/index.d.ts +1 -0
- package/dist/common/types/src/StreamScript.d.ts +14 -2
- package/dist/common/types/src/entities/agents/chat.d.ts +20 -2
- package/dist/common/types/src/entities/knowledge/knowledge.d.ts +1 -0
- package/dist/common/types/src/stream/api/talk.d.ts +2 -0
- package/dist/common/types/src/stream/stream.d.ts +7 -0
- package/dist/index.js +80 -58
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
|
@@ -6,5 +6,5 @@ export declare function createAgentsApi(auth: Auth, host?: string): {
|
|
|
6
6
|
delete(id: string, options?: RequestInit): Promise<any>;
|
|
7
7
|
update(id: string, payload: AgentPayload, options?: RequestInit): Promise<Agent>;
|
|
8
8
|
newChat(agentId: string, options?: RequestInit): Promise<Chat>;
|
|
9
|
-
chat(agentId: string, chatId: string, payload: ChatPayload, options?: RequestInit): Promise<
|
|
9
|
+
chat(agentId: string, chatId: string, payload: ChatPayload, options?: RequestInit): Promise<ChatResponse>;
|
|
10
10
|
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Auth, RatingEntity } from '../../../../common/types/src/index';
|
|
2
|
+
type RatingPayload = Omit<RatingEntity, 'owner_id' | 'id' | 'created_at' | 'modified_at' | 'created_by' | 'external_id'>;
|
|
3
|
+
export declare function createRatingssApi(auth: Auth, host?: string): {
|
|
4
|
+
create(payload: RatingPayload, options?: RequestInit): Promise<RatingEntity>;
|
|
5
|
+
getByKnowledge(knowledgeId?: string, options?: RequestInit): Promise<RatingEntity[]>;
|
|
6
|
+
update(id: string, payload: Partial<RatingPayload>, options?: RequestInit): Promise<RatingEntity>;
|
|
7
|
+
delete(id: string, options?: RequestInit): Promise<RatingEntity>;
|
|
8
|
+
};
|
|
9
|
+
export {};
|
|
@@ -4,6 +4,6 @@ export declare function createAgentManager(agentId: string, { callbacks, ...opti
|
|
|
4
4
|
agent: Agent;
|
|
5
5
|
terminate(): Promise<void>;
|
|
6
6
|
chatId: string;
|
|
7
|
-
chat(messages: Message[]): Promise<
|
|
7
|
+
chat(messages: Message[]): Promise<import('../../../common/types/src/index').ChatResponse>;
|
|
8
8
|
}>;
|
|
9
9
|
export type AgentManager = Awaited<ReturnType<typeof createAgentManager>>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Message } from './entities';
|
|
1
2
|
import { StreamTextToSpeechProviders } from './tts';
|
|
2
3
|
export type StreamScriptType = 'text' | 'audio';
|
|
3
4
|
export interface BaseStreamScript {
|
|
@@ -11,7 +12,7 @@ export interface Stream_Text_Script extends BaseStreamScript {
|
|
|
11
12
|
/**
|
|
12
13
|
* text-to-speech provider from list of supported providers. default is microsoft tts
|
|
13
14
|
*/
|
|
14
|
-
provider
|
|
15
|
+
provider: StreamTextToSpeechProviders;
|
|
15
16
|
/**
|
|
16
17
|
* The input text that will be synthesized to an audio file.
|
|
17
18
|
* Note that each provider has its own limitations on the text length.
|
|
@@ -37,4 +38,15 @@ export interface Stream_Audio_Script extends BaseStreamScript {
|
|
|
37
38
|
*/
|
|
38
39
|
audio_url: string;
|
|
39
40
|
}
|
|
40
|
-
export
|
|
41
|
+
export interface Stream_LLM_Script {
|
|
42
|
+
type: 'llm';
|
|
43
|
+
provider: StreamTextToSpeechProviders;
|
|
44
|
+
ssml?: boolean;
|
|
45
|
+
llm: {
|
|
46
|
+
messages: Message[];
|
|
47
|
+
provider: 'openai';
|
|
48
|
+
};
|
|
49
|
+
input?: string;
|
|
50
|
+
stream_audio?: boolean;
|
|
51
|
+
}
|
|
52
|
+
export type StreamScript = Stream_Text_Script | Stream_Audio_Script | Stream_LLM_Script;
|
|
@@ -1,8 +1,26 @@
|
|
|
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
|
+
}
|
|
1
19
|
export interface Message {
|
|
2
20
|
role: 'system' | 'assistant' | 'user' | 'function' | 'tool';
|
|
3
21
|
content: string;
|
|
4
|
-
name?: string;
|
|
5
22
|
created_at: string;
|
|
23
|
+
matches?: ChatResponse['matches'];
|
|
6
24
|
}
|
|
7
25
|
export interface ChatPayload {
|
|
8
26
|
messages: Message[];
|
|
@@ -18,7 +36,7 @@ export interface IRetrivalMetadata {
|
|
|
18
36
|
source_url: string;
|
|
19
37
|
}
|
|
20
38
|
export interface ChatResponse {
|
|
21
|
-
result
|
|
39
|
+
result?: string;
|
|
22
40
|
documentIds?: string[];
|
|
23
41
|
matches?: IRetrivalMetadata[];
|
|
24
42
|
}
|
|
@@ -7,7 +7,14 @@ export declare enum StreamingState {
|
|
|
7
7
|
Start = "START",
|
|
8
8
|
Stop = "STOP"
|
|
9
9
|
}
|
|
10
|
+
export declare enum StreamEvents {
|
|
11
|
+
ChatAnswer = "chat/answer",
|
|
12
|
+
ChatPartial = "chat/partial",
|
|
13
|
+
StreamDone = "stream/done",
|
|
14
|
+
StreamStarted = "stream/started"
|
|
15
|
+
}
|
|
10
16
|
export interface ManagerCallbacks {
|
|
17
|
+
onMessage?: (event: string, data: string) => void;
|
|
11
18
|
onConnectionStateChange?: (state: RTCIceConnectionState) => void;
|
|
12
19
|
onVideoStateChange?: (state: StreamingState) => void;
|
|
13
20
|
onSrcObjectReady?: (value: MediaStream) => void;
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
function
|
|
1
|
+
function v(o) {
|
|
2
2
|
return o.type === "bearer" ? "Bearer " + o.token : o.type === "basic" ? "Basic " + btoa(`${o.username}:${o.password}`) : "Client-Key " + o.clientKey;
|
|
3
3
|
}
|
|
4
|
-
function
|
|
4
|
+
function C(o, i = "https://api.d-id.com") {
|
|
5
5
|
const n = async (e, t) => {
|
|
6
|
-
const r = await fetch(
|
|
6
|
+
const r = await fetch(i + (e != null && e.startsWith("/") ? e : `/${e}`), {
|
|
7
7
|
...t,
|
|
8
8
|
headers: {
|
|
9
9
|
...t == null ? void 0 : t.headers,
|
|
10
|
-
Authorization:
|
|
10
|
+
Authorization: v(o),
|
|
11
11
|
"Content-Type": "application/json"
|
|
12
12
|
}
|
|
13
13
|
});
|
|
@@ -47,8 +47,8 @@ function h(o, s = "https://api.d-id.com") {
|
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
|
-
function
|
|
51
|
-
const n =
|
|
50
|
+
function M(o, i = "https://api.d-id.com") {
|
|
51
|
+
const n = C(o, `${i}/agents`);
|
|
52
52
|
return {
|
|
53
53
|
create(e, t) {
|
|
54
54
|
return n.post("/", e, t);
|
|
@@ -73,8 +73,8 @@ function R(o, s = "https://api.d-id.com") {
|
|
|
73
73
|
}
|
|
74
74
|
};
|
|
75
75
|
}
|
|
76
|
-
function
|
|
77
|
-
const n =
|
|
76
|
+
function x(o, i = "https://api.d-id.com") {
|
|
77
|
+
const n = C(o, `${i}/knowledge`);
|
|
78
78
|
return {
|
|
79
79
|
createKnowledge(e, t) {
|
|
80
80
|
return n.post("/", e, t);
|
|
@@ -110,8 +110,25 @@ function M(o, s = "https://api.d-id.com") {
|
|
|
110
110
|
}
|
|
111
111
|
};
|
|
112
112
|
}
|
|
113
|
-
|
|
114
|
-
|
|
113
|
+
function L(o, i = "https://api.d-id.com") {
|
|
114
|
+
const n = C(o, `${i}/chats/ratings`);
|
|
115
|
+
return {
|
|
116
|
+
create(e, t) {
|
|
117
|
+
return n.post("/", e, t);
|
|
118
|
+
},
|
|
119
|
+
getByKnowledge(e, t) {
|
|
120
|
+
return n.get(`/${e}`, t).then((r) => r ?? []);
|
|
121
|
+
},
|
|
122
|
+
update(e, t, r) {
|
|
123
|
+
return n.patch(`/${e}`, t, r);
|
|
124
|
+
},
|
|
125
|
+
delete(e, t) {
|
|
126
|
+
return n.delete(`/${e}`, t);
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
var h = /* @__PURE__ */ ((o) => (o.Start = "START", o.Stop = "STOP", o))(h || {}), _ = /* @__PURE__ */ ((o) => (o.ChatAnswer = "chat/answer", o.ChatPartial = "chat/partial", o.StreamDone = "stream/done", o.StreamStarted = "stream/started", o))(_ || {}), m = /* @__PURE__ */ ((o) => (o.Clip = "clip", o.Talk = "talk", o))(m || {});
|
|
131
|
+
function O(o) {
|
|
115
132
|
return o.presenter.type === m.Clip ? {
|
|
116
133
|
videoType: m.Clip,
|
|
117
134
|
driver_id: o.presenter.driver_id,
|
|
@@ -121,20 +138,20 @@ function I(o) {
|
|
|
121
138
|
source_url: o.presenter.source_url
|
|
122
139
|
};
|
|
123
140
|
}
|
|
124
|
-
async function
|
|
125
|
-
callbacks:
|
|
141
|
+
async function J(o, {
|
|
142
|
+
callbacks: i,
|
|
126
143
|
...n
|
|
127
144
|
}) {
|
|
128
|
-
const e = new AbortController(), t =
|
|
145
|
+
const e = new AbortController(), t = M(n.auth, n.baseURL), r = await t.getById(o), a = await t.newChat(o), {
|
|
129
146
|
terminate: w,
|
|
130
147
|
sessionId: S,
|
|
131
148
|
streamId: $
|
|
132
|
-
} = await O(
|
|
149
|
+
} = await j(O(r), {
|
|
133
150
|
...n,
|
|
134
151
|
callbacks: {
|
|
135
|
-
onSrcObjectReady:
|
|
136
|
-
onVideoStateChange:
|
|
137
|
-
onConnectionStateChange:
|
|
152
|
+
onSrcObjectReady: i.onSrcObjectReady,
|
|
153
|
+
onVideoStateChange: i == null ? void 0 : i.onVideoStateChange,
|
|
154
|
+
onConnectionStateChange: i.onConnectionStateChange
|
|
138
155
|
}
|
|
139
156
|
});
|
|
140
157
|
return {
|
|
@@ -154,8 +171,8 @@ async function P(o, {
|
|
|
154
171
|
}
|
|
155
172
|
};
|
|
156
173
|
}
|
|
157
|
-
function
|
|
158
|
-
const n =
|
|
174
|
+
function P(o, i) {
|
|
175
|
+
const n = C(o, i);
|
|
159
176
|
return {
|
|
160
177
|
createStream(e) {
|
|
161
178
|
return n.post("/clips/streams", {
|
|
@@ -189,8 +206,8 @@ function v(o, s) {
|
|
|
189
206
|
}
|
|
190
207
|
};
|
|
191
208
|
}
|
|
192
|
-
function
|
|
193
|
-
const n =
|
|
209
|
+
function q(o, i) {
|
|
210
|
+
const n = C(o, i);
|
|
194
211
|
return {
|
|
195
212
|
createStream(e, t) {
|
|
196
213
|
return n.post("/talks/streams", {
|
|
@@ -225,65 +242,70 @@ function K(o, s) {
|
|
|
225
242
|
}
|
|
226
243
|
};
|
|
227
244
|
}
|
|
228
|
-
let
|
|
229
|
-
const p = (o,
|
|
230
|
-
async function
|
|
231
|
-
debug:
|
|
245
|
+
let l = !1;
|
|
246
|
+
const p = (o, i) => l && console.log(o, i), B = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
|
|
247
|
+
async function j(o, {
|
|
248
|
+
debug: i = !1,
|
|
232
249
|
callbacks: n,
|
|
233
250
|
auth: e,
|
|
234
251
|
baseURL: t = "https://api.d-id.com"
|
|
235
252
|
}) {
|
|
236
|
-
|
|
253
|
+
l = i;
|
|
237
254
|
const {
|
|
238
255
|
startConnection: r,
|
|
239
256
|
sendStreamRequest: a,
|
|
240
257
|
close: w,
|
|
241
258
|
createStream: S,
|
|
242
259
|
addIceCandidate: $
|
|
243
|
-
} = o.videoType === m.Clip ?
|
|
260
|
+
} = o.videoType === m.Clip ? P(e, t) : q(e, t), {
|
|
244
261
|
id: c,
|
|
245
|
-
offer:
|
|
246
|
-
ice_servers:
|
|
262
|
+
offer: I,
|
|
263
|
+
ice_servers: D,
|
|
247
264
|
session_id: g
|
|
248
|
-
} = await S(o),
|
|
249
|
-
iceServers:
|
|
250
|
-
}),
|
|
265
|
+
} = await S(o), s = new B({
|
|
266
|
+
iceServers: D
|
|
267
|
+
}), A = s.createDataChannel("JanusDataChannel");
|
|
251
268
|
if (!g)
|
|
252
269
|
throw new Error("Could not create session_id");
|
|
253
|
-
|
|
254
|
-
p("peerConnection.onicecandidate",
|
|
255
|
-
candidate:
|
|
256
|
-
sdpMid:
|
|
257
|
-
sdpMLineIndex:
|
|
270
|
+
s.onicecandidate = (d) => {
|
|
271
|
+
p("peerConnection.onicecandidate", d), d.candidate && d.candidate.sdpMid && d.candidate.sdpMLineIndex !== null && $(c, {
|
|
272
|
+
candidate: d.candidate.candidate,
|
|
273
|
+
sdpMid: d.candidate.sdpMid,
|
|
274
|
+
sdpMLineIndex: d.candidate.sdpMLineIndex
|
|
258
275
|
}, g);
|
|
259
|
-
},
|
|
260
|
-
var
|
|
261
|
-
p("peerConnection.oniceconnectionstatechange => " +
|
|
262
|
-
},
|
|
263
|
-
var u;
|
|
264
|
-
p("peerConnection.ontrack", i), (u = n.onSrcObjectReady) == null || u.call(n, i.streams[0]);
|
|
265
|
-
}, f.onmessage = (i) => {
|
|
276
|
+
}, s.oniceconnectionstatechange = () => {
|
|
277
|
+
var d;
|
|
278
|
+
p("peerConnection.oniceconnectionstatechange => " + s.iceConnectionState), (d = n.onConnectionStateChange) == null || d.call(n, s.iceConnectionState);
|
|
279
|
+
}, s.ontrack = (d) => {
|
|
266
280
|
var u;
|
|
267
|
-
|
|
268
|
-
},
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
281
|
+
p("peerConnection.ontrack", d), (u = n.onSrcObjectReady) == null || u.call(n, d.streams[0]);
|
|
282
|
+
}, A.onmessage = (d) => {
|
|
283
|
+
var u, f, R;
|
|
284
|
+
if (A.readyState === "open") {
|
|
285
|
+
const [y, K] = d.data.split(":");
|
|
286
|
+
y === _.StreamDone ? (u = n.onVideoStateChange) == null || u.call(n, h.Stop) : y === _.StreamStarted ? (f = n.onVideoStateChange) == null || f.call(n, h.Start) : (R = n.onMessage) == null || R.call(n, y, decodeURIComponent(K));
|
|
287
|
+
}
|
|
288
|
+
}, await s.setRemoteDescription(I), p("set remote description OK");
|
|
289
|
+
const T = await s.createAnswer();
|
|
290
|
+
return p("create answer OK"), await s.setLocalDescription(T), p("set local description OK"), await r(c, T, g), p("start connection OK"), {
|
|
291
|
+
speak(d) {
|
|
292
|
+
return a(c, g, d);
|
|
273
293
|
},
|
|
274
294
|
async terminate() {
|
|
275
|
-
var
|
|
276
|
-
c && (
|
|
295
|
+
var d, u;
|
|
296
|
+
c && (s && (s.close(), s.oniceconnectionstatechange = null, s.onnegotiationneeded = null, s.onicecandidate = null, s.ontrack = null), await w(c, g).catch((f) => {
|
|
297
|
+
}), (d = n.onConnectionStateChange) == null || d.call(n, "closed"), (u = n.onVideoStateChange) == null || u.call(n, h.Stop));
|
|
277
298
|
},
|
|
278
299
|
sessionId: g,
|
|
279
300
|
streamId: c
|
|
280
301
|
};
|
|
281
302
|
}
|
|
282
303
|
export {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
304
|
+
J as createAgentManager,
|
|
305
|
+
M as createAgentsApi,
|
|
306
|
+
C as createClient,
|
|
307
|
+
x as createKnowledgeApi,
|
|
308
|
+
L as createRatingssApi,
|
|
309
|
+
j as createStreamingManager,
|
|
310
|
+
O as getAgentStreamArgs
|
|
289
311
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(c,
|
|
1
|
+
(function(c,h){typeof exports=="object"&&typeof module<"u"?h(exports):typeof define=="function"&&define.amd?define(["exports"],h):(c=typeof globalThis<"u"?globalThis:c||self,h(c.index={}))})(this,function(c){"use strict";function h(i){return i.type==="bearer"?"Bearer "+i.token:i.type==="basic"?"Basic "+btoa(`${i.username}:${i.password}`):"Client-Key "+i.clientKey}function m(i,o="https://api.d-id.com"){const n=async(e,t)=>{const r=await fetch(o+(e!=null&&e.startsWith("/")?e:`/${e}`),{...t,headers:{...t==null?void 0:t.headers,Authorization:h(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 T(i,o="https://api.d-id.com"){const n=m(i,`${o}/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 O(i,o="https://api.d-id.com"){const n=m(i,`${o}/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)}}}function P(i,o="https://api.d-id.com"){const n=m(i,`${o}/chats/ratings`);return{create(e,t){return n.post("/",e,t)},getByKnowledge(e,t){return n.get(`/${e}`,t).then(r=>r??[])},update(e,t,r){return n.patch(`/${e}`,t,r)},delete(e,t){return n.delete(`/${e}`,t)}}}var w=(i=>(i.Start="START",i.Stop="STOP",i))(w||{}),S=(i=>(i.ChatAnswer="chat/answer",i.ChatPartial="chat/partial",i.StreamDone="stream/done",i.StreamStarted="stream/started",i))(S||{}),f=(i=>(i.Clip="clip",i.Talk="talk",i))(f||{});function R(i){return i.presenter.type===f.Clip?{videoType:f.Clip,driver_id:i.presenter.driver_id,presenter_id:i.presenter.presenter_id}:{videoType:f.Talk,source_url:i.presenter.source_url}}async function j(i,{callbacks:o,...n}){const e=new AbortController,t=T(n.auth,n.baseURL),r=await t.getById(i),a=await t.newChat(i),{terminate:$,sessionId:y,streamId:_}=await K(R(r),{...n,callbacks:{onSrcObjectReady:o.onSrcObjectReady,onVideoStateChange:o==null?void 0:o.onVideoStateChange,onConnectionStateChange:o.onConnectionStateChange}});return{agent:r,terminate(){return e.abort(),$()},chatId:a.id,chat(u){return t.chat(i,a.id,{sessionId:y,streamId:_,messages:u},{signal:e.signal})}}}function q(i,o){const n=m(i,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,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 B(i,o){const n=m(i,o);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 I=!1;const g=(i,o)=>I&&console.log(i,o),L=(window.RTCPeerConnection||window.webkitRTCPeerConnection||window.mozRTCPeerConnection).bind(window);async function K(i,{debug:o=!1,callbacks:n,auth:e,baseURL:t="https://api.d-id.com"}){I=o;const{startConnection:r,sendStreamRequest:a,close:$,createStream:y,addIceCandidate:_}=i.videoType===f.Clip?q(e,t):B(e,t),{id:u,offer:J,ice_servers:V,session_id:C}=await y(i),s=new L({iceServers:V}),D=s.createDataChannel("JanusDataChannel");if(!C)throw new Error("Could not create session_id");s.onicecandidate=d=>{g("peerConnection.onicecandidate",d),d.candidate&&d.candidate.sdpMid&&d.candidate.sdpMLineIndex!==null&&_(u,{candidate:d.candidate.candidate,sdpMid:d.candidate.sdpMid,sdpMLineIndex:d.candidate.sdpMLineIndex},C)},s.oniceconnectionstatechange=()=>{var d;g("peerConnection.oniceconnectionstatechange => "+s.iceConnectionState),(d=n.onConnectionStateChange)==null||d.call(n,s.iceConnectionState)},s.ontrack=d=>{var p;g("peerConnection.ontrack",d),(p=n.onSrcObjectReady)==null||p.call(n,d.streams[0])},D.onmessage=d=>{var p,A,v;if(D.readyState==="open"){const[l,E]=d.data.split(":");l===S.StreamDone?(p=n.onVideoStateChange)==null||p.call(n,w.Stop):l===S.StreamStarted?(A=n.onVideoStateChange)==null||A.call(n,w.Start):(v=n.onMessage)==null||v.call(n,l,decodeURIComponent(E))}},await s.setRemoteDescription(J),g("set remote description OK");const M=await s.createAnswer();return g("create answer OK"),await s.setLocalDescription(M),g("set local description OK"),await r(u,M,C),g("start connection OK"),{speak(d){return a(u,C,d)},async terminate(){var d,p;u&&(s&&(s.close(),s.oniceconnectionstatechange=null,s.onnegotiationneeded=null,s.onicecandidate=null,s.ontrack=null),await $(u,C).catch(A=>{}),(d=n.onConnectionStateChange)==null||d.call(n,"closed"),(p=n.onVideoStateChange)==null||p.call(n,w.Stop))},sessionId:C,streamId:u}}c.createAgentManager=j,c.createAgentsApi=T,c.createClient=m,c.createKnowledgeApi=O,c.createRatingssApi=P,c.createStreamingManager=K,c.getAgentStreamArgs=R,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
|