@d-id/client-sdk 1.0.19-beta.87 → 1.0.19-beta.89
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/index.js +330 -356
- package/dist/index.umd.cjs +1 -1
- package/dist/src/types/entities/agents/chat.d.ts +2 -0
- package/dist/src/types/entities/agents/manager.d.ts +7 -1
- package/dist/src/types/stream/api/talk.d.ts +1 -1
- package/dist/src/types/stream/stream.d.ts +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
var
|
|
2
|
-
const
|
|
3
|
-
function
|
|
1
|
+
var j = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(j || {}), q = /* @__PURE__ */ ((e) => (e.TRIAL = "deid-trial", e.PRO = "deid-pro", e.ENTERPRISE = "deid-enterprise", e.LITE = "deid-lite", e.ADVANCED = "deid-advanced", e.BUILD = "deid-api-build", e.LAUNCH = "deid-api-launch", e.SCALE = "deid-api-scale", e))(q || {}), Q = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(Q || {}), R = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e))(R || {}), b = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Complete = "done", e))(b || {}), X = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(X || {}), Y = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(Y || {}), Z = /* @__PURE__ */ ((e) => (e.Pdf = "pdf", e.Text = "text", e.Html = "html", e.Word = "word", e.Json = "json", e.Markdown = "markdown", e.Csv = "csv", e.Excel = "excel", e.Powerpoint = "powerpoint", e.Archive = "archive", e.Image = "image", e.Audio = "audio", e.Video = "video", e))(Z || {}), y = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e))(y || {}), T = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(T || {}), A = /* @__PURE__ */ ((e) => (e.ChatAnswer = "chat/answer", e.ChatPartial = "chat/partial", e.StreamDone = "stream/done", e.StreamStarted = "stream/started", e.StreamFailed = "stream/error", e.StreamReady = "stream/ready", e.StreamCreated = "stream/created", e.StreamVideoCreated = "stream-video/started", e.StreamVideoDone = "stream-video/done", e.StreamVideoError = "stream-video/error", e.StreamVideoRejected = "stream-video/rejected", e))(A || {}), M = /* @__PURE__ */ ((e) => (e[e.New = 0] = "New", e[e.Fail = 1] = "Fail", e[e.Connected = 2] = "Connected", e[e.Connecting = 3] = "Connecting", e[e.Terminating = 4] = "Terminating", e))(M || {}), G = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(G || {}), ee = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(ee || {});
|
|
2
|
+
const N = "https://api.d-id.com", te = "wss://notifications.d-id.com", ne = "79f81a83a67430be2bc0fd61042b8faa", z = () => Math.random().toString(16).slice(2);
|
|
3
|
+
function W() {
|
|
4
4
|
let e = window.localStorage.getItem("did_external_key_id");
|
|
5
5
|
return e || (e = Math.random().toString(16).slice(2), window.localStorage.setItem("did_external_key_id", e)), e;
|
|
6
6
|
}
|
|
7
|
-
let
|
|
8
|
-
function
|
|
7
|
+
let re = z();
|
|
8
|
+
function H(e) {
|
|
9
9
|
if (e.type === "bearer")
|
|
10
10
|
return `Bearer ${e.token}`;
|
|
11
11
|
if (e.type === "basic")
|
|
12
12
|
return `Basic ${btoa(`${e.username}:${e.password}`)}`;
|
|
13
13
|
if (e.type === "key")
|
|
14
|
-
return `Client-Key ${e.clientKey}.${
|
|
14
|
+
return `Client-Key ${e.clientKey}.${W()}_${re}`;
|
|
15
15
|
throw new Error(`Unknown auth type: ${e}`);
|
|
16
16
|
}
|
|
17
|
-
function F(e,
|
|
18
|
-
const t = async (n,
|
|
19
|
-
const i = await fetch(
|
|
20
|
-
...
|
|
17
|
+
function F(e, a = N) {
|
|
18
|
+
const t = async (n, r) => {
|
|
19
|
+
const i = await fetch(a + (n != null && n.startsWith("/") ? n : `/${n}`), {
|
|
20
|
+
...r,
|
|
21
21
|
headers: {
|
|
22
|
-
...
|
|
23
|
-
Authorization:
|
|
22
|
+
...r == null ? void 0 : r.headers,
|
|
23
|
+
Authorization: H(e),
|
|
24
24
|
"Content-Type": "application/json"
|
|
25
25
|
}
|
|
26
26
|
});
|
|
@@ -31,109 +31,109 @@ function F(e, r = T) {
|
|
|
31
31
|
return i.json();
|
|
32
32
|
};
|
|
33
33
|
return {
|
|
34
|
-
get(n,
|
|
34
|
+
get(n, r) {
|
|
35
35
|
return t(n, {
|
|
36
|
-
...
|
|
36
|
+
...r,
|
|
37
37
|
method: "GET"
|
|
38
38
|
});
|
|
39
39
|
},
|
|
40
|
-
post(n,
|
|
40
|
+
post(n, r, i) {
|
|
41
41
|
return t(n, {
|
|
42
42
|
...i,
|
|
43
|
-
body: JSON.stringify(
|
|
43
|
+
body: JSON.stringify(r),
|
|
44
44
|
method: "POST"
|
|
45
45
|
});
|
|
46
46
|
},
|
|
47
|
-
delete(n,
|
|
47
|
+
delete(n, r, i) {
|
|
48
48
|
return t(n, {
|
|
49
49
|
...i,
|
|
50
|
-
body: JSON.stringify(
|
|
50
|
+
body: JSON.stringify(r),
|
|
51
51
|
method: "DELETE"
|
|
52
52
|
});
|
|
53
53
|
},
|
|
54
|
-
patch(n,
|
|
54
|
+
patch(n, r, i) {
|
|
55
55
|
return t(n, {
|
|
56
56
|
...i,
|
|
57
|
-
body: JSON.stringify(
|
|
57
|
+
body: JSON.stringify(r),
|
|
58
58
|
method: "PATCH"
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
61
|
};
|
|
62
62
|
}
|
|
63
|
-
function
|
|
64
|
-
const t = F(e, `${
|
|
63
|
+
function J(e, a = N) {
|
|
64
|
+
const t = F(e, `${a}/agents`);
|
|
65
65
|
return {
|
|
66
|
-
create(n,
|
|
67
|
-
return t.post("/", n,
|
|
66
|
+
create(n, r) {
|
|
67
|
+
return t.post("/", n, r);
|
|
68
68
|
},
|
|
69
|
-
getAgents(n,
|
|
70
|
-
return t.get(`/${n ? `?tag=${n}` : ""}`,
|
|
69
|
+
getAgents(n, r) {
|
|
70
|
+
return t.get(`/${n ? `?tag=${n}` : ""}`, r).then((i) => i ?? []);
|
|
71
71
|
},
|
|
72
|
-
getById(n,
|
|
73
|
-
return t.get(`/${n}`,
|
|
72
|
+
getById(n, r) {
|
|
73
|
+
return t.get(`/${n}`, r);
|
|
74
74
|
},
|
|
75
|
-
delete(n,
|
|
76
|
-
return t.delete(`/${n}`, void 0,
|
|
75
|
+
delete(n, r) {
|
|
76
|
+
return t.delete(`/${n}`, void 0, r);
|
|
77
77
|
},
|
|
78
|
-
update(n,
|
|
79
|
-
return t.patch(`/${n}`,
|
|
78
|
+
update(n, r, i) {
|
|
79
|
+
return t.patch(`/${n}`, r, i);
|
|
80
80
|
},
|
|
81
|
-
newChat(n,
|
|
82
|
-
return t.post(`/${n}/chat`, void 0,
|
|
81
|
+
newChat(n, r) {
|
|
82
|
+
return t.post(`/${n}/chat`, void 0, r);
|
|
83
83
|
},
|
|
84
|
-
chat(n,
|
|
85
|
-
return t.post(`/${n}/chat/${
|
|
84
|
+
chat(n, r, i, o) {
|
|
85
|
+
return t.post(`/${n}/chat/${r}`, i, o);
|
|
86
86
|
},
|
|
87
|
-
createRating(n,
|
|
88
|
-
return t.post(`/${n}/chat/${
|
|
87
|
+
createRating(n, r, i, o) {
|
|
88
|
+
return t.post(`/${n}/chat/${r}/ratings`, i, o);
|
|
89
89
|
},
|
|
90
|
-
updateRating(n,
|
|
91
|
-
return t.patch(`/${n}/chat/${
|
|
90
|
+
updateRating(n, r, i, o, d) {
|
|
91
|
+
return t.patch(`/${n}/chat/${r}/ratings/${i}`, o, d);
|
|
92
92
|
},
|
|
93
|
-
deleteRating(n,
|
|
94
|
-
return t.delete(`/${n}/chat/${
|
|
93
|
+
deleteRating(n, r, i, o) {
|
|
94
|
+
return t.delete(`/${n}/chat/${r}/ratings/${i}`, o);
|
|
95
95
|
}
|
|
96
96
|
};
|
|
97
97
|
}
|
|
98
|
-
const
|
|
99
|
-
function
|
|
100
|
-
return new Promise((
|
|
98
|
+
const ae = (e) => new Promise((a) => setTimeout(a, e));
|
|
99
|
+
function ie(e) {
|
|
100
|
+
return new Promise((a, t) => {
|
|
101
101
|
const {
|
|
102
102
|
callbacks: n,
|
|
103
|
-
host:
|
|
103
|
+
host: r,
|
|
104
104
|
auth: i
|
|
105
105
|
} = e, {
|
|
106
106
|
onMessage: o = null,
|
|
107
107
|
onOpen: d = null,
|
|
108
108
|
onClose: g = null,
|
|
109
|
-
onError:
|
|
110
|
-
} = n || {},
|
|
111
|
-
|
|
112
|
-
console.error(
|
|
113
|
-
},
|
|
114
|
-
d == null || d(
|
|
109
|
+
onError: u = null
|
|
110
|
+
} = n || {}, f = new WebSocket(`${r}?authorization=${H(i)}`);
|
|
111
|
+
f.onmessage = o, f.onclose = g, f.onerror = (p) => {
|
|
112
|
+
console.error(p), u == null || u("Websocket failed to connect", p), t(p);
|
|
113
|
+
}, f.onopen = (p) => {
|
|
114
|
+
d == null || d(p), a(f);
|
|
115
115
|
};
|
|
116
116
|
});
|
|
117
117
|
}
|
|
118
|
-
async function
|
|
118
|
+
async function se(e) {
|
|
119
119
|
const {
|
|
120
|
-
retries:
|
|
120
|
+
retries: a = 1
|
|
121
121
|
} = e;
|
|
122
122
|
let t = null;
|
|
123
123
|
for (let n = 0; (t == null ? void 0 : t.readyState) !== WebSocket.OPEN; n++)
|
|
124
124
|
try {
|
|
125
|
-
t = await
|
|
126
|
-
} catch (
|
|
127
|
-
if (n ===
|
|
128
|
-
throw
|
|
129
|
-
await
|
|
125
|
+
t = await ie(e);
|
|
126
|
+
} catch (r) {
|
|
127
|
+
if (n === a)
|
|
128
|
+
throw r;
|
|
129
|
+
await ae(n * 500);
|
|
130
130
|
}
|
|
131
131
|
return t;
|
|
132
132
|
}
|
|
133
|
-
async function
|
|
134
|
-
const n = t != null && t.onMessage ? [t.onMessage] : [],
|
|
133
|
+
async function K(e, a, t) {
|
|
134
|
+
const n = t != null && t.onMessage ? [t.onMessage] : [], r = await se({
|
|
135
135
|
auth: e,
|
|
136
|
-
host:
|
|
136
|
+
host: a,
|
|
137
137
|
callbacks: {
|
|
138
138
|
onError: t == null ? void 0 : t.onError,
|
|
139
139
|
onMessage: (i) => {
|
|
@@ -143,132 +143,99 @@ async function W(e, r, t) {
|
|
|
143
143
|
}
|
|
144
144
|
});
|
|
145
145
|
return {
|
|
146
|
-
socket:
|
|
147
|
-
disconnect: () =>
|
|
146
|
+
socket: r,
|
|
147
|
+
disconnect: () => r.close(),
|
|
148
148
|
subscribeToEvents: (i) => n.push(i)
|
|
149
149
|
};
|
|
150
150
|
}
|
|
151
|
-
function
|
|
152
|
-
const n = F(e, `${
|
|
151
|
+
function oe(e, a, t) {
|
|
152
|
+
const n = F(e, `${a}/agents/${t}`);
|
|
153
153
|
return {
|
|
154
|
-
createStream(
|
|
154
|
+
createStream(r) {
|
|
155
155
|
return n.post("/streams", {
|
|
156
|
-
driver_id:
|
|
157
|
-
presenter_id:
|
|
158
|
-
compatibility_mode:
|
|
159
|
-
stream_warmup:
|
|
160
|
-
type:
|
|
156
|
+
driver_id: r.driver_id,
|
|
157
|
+
presenter_id: r.presenter_id,
|
|
158
|
+
compatibility_mode: r.compatibility_mode,
|
|
159
|
+
stream_warmup: r.stream_warmup,
|
|
160
|
+
type: y.Clip
|
|
161
161
|
});
|
|
162
162
|
},
|
|
163
|
-
startConnection(
|
|
164
|
-
return n.post(`/streams/${
|
|
163
|
+
startConnection(r, i, o) {
|
|
164
|
+
return n.post(`/streams/${r}/sdp`, {
|
|
165
165
|
session_id: o,
|
|
166
166
|
answer: i,
|
|
167
|
-
type:
|
|
167
|
+
type: y.Clip
|
|
168
168
|
});
|
|
169
169
|
},
|
|
170
|
-
addIceCandidate(
|
|
171
|
-
return n.post(`/streams/${
|
|
170
|
+
addIceCandidate(r, i, o) {
|
|
171
|
+
return n.post(`/streams/${r}/ice`, {
|
|
172
172
|
session_id: o,
|
|
173
173
|
...i,
|
|
174
|
-
type:
|
|
174
|
+
type: y.Clip
|
|
175
175
|
});
|
|
176
176
|
},
|
|
177
|
-
sendStreamRequest(
|
|
178
|
-
return n.post(`/streams/${
|
|
177
|
+
sendStreamRequest(r, i, o) {
|
|
178
|
+
return n.post(`/streams/${r}`, {
|
|
179
179
|
session_id: i,
|
|
180
180
|
...o,
|
|
181
|
-
type:
|
|
181
|
+
type: y.Clip
|
|
182
182
|
});
|
|
183
183
|
},
|
|
184
|
-
close(
|
|
185
|
-
return n.delete(`/streams/${
|
|
184
|
+
close(r, i) {
|
|
185
|
+
return n.delete(`/streams/${r}`, {
|
|
186
186
|
session_id: i,
|
|
187
|
-
type:
|
|
187
|
+
type: y.Clip
|
|
188
188
|
});
|
|
189
189
|
}
|
|
190
190
|
};
|
|
191
191
|
}
|
|
192
|
-
function
|
|
193
|
-
const n = F(e, `${
|
|
192
|
+
function ce(e, a, t) {
|
|
193
|
+
const n = F(e, `${a}/agents/${t}`);
|
|
194
194
|
return {
|
|
195
|
-
createStream(
|
|
195
|
+
createStream(r, i) {
|
|
196
196
|
return n.post("/streams", {
|
|
197
|
-
source_url:
|
|
198
|
-
driver_url:
|
|
199
|
-
face:
|
|
200
|
-
config:
|
|
201
|
-
compatibility_mode:
|
|
202
|
-
stream_warmup:
|
|
203
|
-
|
|
204
|
-
type:
|
|
197
|
+
source_url: r.source_url,
|
|
198
|
+
driver_url: r.driver_url,
|
|
199
|
+
face: r.face,
|
|
200
|
+
config: r.config,
|
|
201
|
+
compatibility_mode: r.compatibility_mode,
|
|
202
|
+
stream_warmup: r.stream_warmup,
|
|
203
|
+
output_resolution: r.output_resolution,
|
|
204
|
+
type: y.Talk
|
|
205
205
|
}, i);
|
|
206
206
|
},
|
|
207
|
-
startConnection(
|
|
208
|
-
return n.post(`/streams/${
|
|
207
|
+
startConnection(r, i, o, d) {
|
|
208
|
+
return n.post(`/streams/${r}/sdp`, {
|
|
209
209
|
session_id: o,
|
|
210
210
|
answer: i,
|
|
211
|
-
type:
|
|
211
|
+
type: y.Talk
|
|
212
212
|
}, d);
|
|
213
213
|
},
|
|
214
|
-
addIceCandidate(
|
|
215
|
-
return n.post(`/streams/${
|
|
214
|
+
addIceCandidate(r, i, o, d) {
|
|
215
|
+
return n.post(`/streams/${r}/ice`, {
|
|
216
216
|
session_id: o,
|
|
217
217
|
...i,
|
|
218
|
-
type:
|
|
218
|
+
type: y.Talk
|
|
219
219
|
}, d);
|
|
220
220
|
},
|
|
221
|
-
sendStreamRequest(
|
|
222
|
-
return n.post(`/streams/${
|
|
221
|
+
sendStreamRequest(r, i, o, d) {
|
|
222
|
+
return n.post(`/streams/${r}`, {
|
|
223
223
|
session_id: i,
|
|
224
224
|
...o,
|
|
225
|
-
type:
|
|
225
|
+
type: y.Talk
|
|
226
226
|
}, d);
|
|
227
227
|
},
|
|
228
|
-
close(
|
|
229
|
-
return n.delete(`/streams/${
|
|
228
|
+
close(r, i, o) {
|
|
229
|
+
return n.delete(`/streams/${r}`, {
|
|
230
230
|
session_id: i,
|
|
231
|
-
type:
|
|
231
|
+
type: y.Talk
|
|
232
232
|
}, o);
|
|
233
233
|
}
|
|
234
234
|
};
|
|
235
235
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
timestamp: t.timestamp,
|
|
240
|
-
bytesReceived: t.bytesReceived - r.bytesReceived,
|
|
241
|
-
packetsReceived: t.packetsReceived - r.packetsReceived,
|
|
242
|
-
packetsLost: t.packetsLost - r.packetsLost,
|
|
243
|
-
jitter: t.jitter,
|
|
244
|
-
frameWidth: t.frameWidth,
|
|
245
|
-
frameHeight: t.frameHeight,
|
|
246
|
-
framesPerSecond: t.framesPerSecond
|
|
247
|
-
} : {
|
|
248
|
-
index: n,
|
|
249
|
-
timestamp: t.timestamp,
|
|
250
|
-
bytesReceived: t.bytesReceived,
|
|
251
|
-
packetsReceived: t.packetsReceived,
|
|
252
|
-
packetsLost: t.packetsLost,
|
|
253
|
-
jitter: t.jitter,
|
|
254
|
-
frameWidth: t.frameWidth,
|
|
255
|
-
frameHeight: t.frameHeight,
|
|
256
|
-
framesPerSecond: t.framesPerSecond
|
|
257
|
-
} : {
|
|
258
|
-
index: n,
|
|
259
|
-
timestamp: t.timestamp,
|
|
260
|
-
bytesReceived: t.bytesReceived - e[n - 1].bytesReceived,
|
|
261
|
-
packetsReceived: t.packetsReceived - e[n - 1].packetsReceived,
|
|
262
|
-
packetsLost: t.packetsLost - e[n - 1].packetsLost,
|
|
263
|
-
jitter: t.jitter,
|
|
264
|
-
frameWidth: t.frameWidth,
|
|
265
|
-
frameHeight: t.frameHeight,
|
|
266
|
-
framesPerSecond: t.framesPerSecond
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
let j = !1;
|
|
270
|
-
const I = (e, r) => j && console.log(e, r), oe = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
|
|
271
|
-
function ce(e) {
|
|
236
|
+
let V = !1;
|
|
237
|
+
const k = (e, a) => V && console.log(e, a), de = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
|
|
238
|
+
function U(e) {
|
|
272
239
|
switch (e) {
|
|
273
240
|
case "connected":
|
|
274
241
|
return M.Connected;
|
|
@@ -283,132 +250,134 @@ function ce(e) {
|
|
|
283
250
|
return M.New;
|
|
284
251
|
}
|
|
285
252
|
}
|
|
286
|
-
function
|
|
287
|
-
let
|
|
288
|
-
return
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
}
|
|
306
|
-
});
|
|
307
|
-
});
|
|
308
|
-
}, 500);
|
|
253
|
+
function ge() {
|
|
254
|
+
let e = 0;
|
|
255
|
+
return (a) => {
|
|
256
|
+
for (const t of a.values())
|
|
257
|
+
if (t && t.type === "inbound-rtp" && t.kind === "video") {
|
|
258
|
+
const n = t.bytesReceived, r = n - e > 0;
|
|
259
|
+
return e = n, r;
|
|
260
|
+
}
|
|
261
|
+
return !1;
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
function le(e, a, t) {
|
|
265
|
+
const r = Math.max(Math.ceil(10), 1);
|
|
266
|
+
let i = 0, o = !1;
|
|
267
|
+
const d = ge();
|
|
268
|
+
return setInterval(async () => {
|
|
269
|
+
const g = await e.getStats();
|
|
270
|
+
d(g) ? (i = 0, o || (a == null || a(T.Start), o = !0)) : o && (i++, i >= r && (a == null || a(T.Stop), o = !1));
|
|
271
|
+
}, 100);
|
|
309
272
|
}
|
|
310
|
-
async function
|
|
273
|
+
async function ue(e, a, {
|
|
311
274
|
debug: t = !1,
|
|
312
275
|
callbacks: n,
|
|
313
|
-
auth:
|
|
276
|
+
auth: r,
|
|
314
277
|
analytics: i,
|
|
315
|
-
baseURL: o =
|
|
278
|
+
baseURL: o = N
|
|
316
279
|
}) {
|
|
317
|
-
|
|
280
|
+
V = t;
|
|
318
281
|
let d;
|
|
319
282
|
const {
|
|
320
283
|
startConnection: g,
|
|
321
|
-
sendStreamRequest:
|
|
322
|
-
close:
|
|
323
|
-
createStream:
|
|
324
|
-
addIceCandidate:
|
|
325
|
-
} =
|
|
326
|
-
id:
|
|
327
|
-
offer:
|
|
328
|
-
ice_servers:
|
|
329
|
-
session_id:
|
|
330
|
-
} = await
|
|
331
|
-
iceServers:
|
|
332
|
-
}),
|
|
333
|
-
if (!
|
|
284
|
+
sendStreamRequest: u,
|
|
285
|
+
close: f,
|
|
286
|
+
createStream: p,
|
|
287
|
+
addIceCandidate: $
|
|
288
|
+
} = a.videoType === y.Clip ? oe(r, o, e) : ce(r, o, e), {
|
|
289
|
+
id: _,
|
|
290
|
+
offer: L,
|
|
291
|
+
ice_servers: O,
|
|
292
|
+
session_id: S
|
|
293
|
+
} = await p(a), s = new de({
|
|
294
|
+
iceServers: O
|
|
295
|
+
}), m = s.createDataChannel("JanusDataChannel");
|
|
296
|
+
if (!S)
|
|
334
297
|
throw new Error("Could not create session_id");
|
|
335
|
-
const
|
|
298
|
+
const l = le(s, n.onVideoStateChange);
|
|
336
299
|
s.onicecandidate = (c) => {
|
|
337
|
-
|
|
300
|
+
k("peerConnection.onicecandidate", c), c.candidate && c.candidate.sdpMid && c.candidate.sdpMLineIndex !== null ? $(_, {
|
|
338
301
|
candidate: c.candidate.candidate,
|
|
339
302
|
sdpMid: c.candidate.sdpMid,
|
|
340
303
|
sdpMLineIndex: c.candidate.sdpMLineIndex
|
|
341
|
-
},
|
|
304
|
+
}, S) : $(_, {
|
|
342
305
|
candidate: null
|
|
343
|
-
},
|
|
306
|
+
}, S);
|
|
344
307
|
}, s.oniceconnectionstatechange = () => {
|
|
345
308
|
var w;
|
|
346
|
-
|
|
347
|
-
const c =
|
|
309
|
+
k("peerConnection.oniceconnectionstatechange => " + s.iceConnectionState);
|
|
310
|
+
const c = U(s.iceConnectionState);
|
|
348
311
|
c === M.Connected ? d = setTimeout(() => {
|
|
349
|
-
var
|
|
350
|
-
(
|
|
312
|
+
var v;
|
|
313
|
+
(v = n.onConnectionStateChange) == null || v.call(n, M.Connected);
|
|
351
314
|
}, 5e3) : (clearTimeout(d), (w = n.onConnectionStateChange) == null || w.call(n, c));
|
|
352
315
|
}, s.ontrack = (c) => {
|
|
353
316
|
var w;
|
|
354
|
-
|
|
355
|
-
},
|
|
317
|
+
k("peerConnection.ontrack", c), (w = n.onSrcObjectReady) == null || w.call(n, c.streams[0]);
|
|
318
|
+
}, m.onmessage = (c) => {
|
|
356
319
|
var w;
|
|
357
|
-
if (
|
|
358
|
-
const [
|
|
359
|
-
|
|
320
|
+
if (m.readyState === "open") {
|
|
321
|
+
const [v, C] = c.data.split(":");
|
|
322
|
+
v === A.StreamReady && (clearTimeout(d), (w = n.onConnectionStateChange) == null || w.call(n, M.Connected));
|
|
360
323
|
}
|
|
361
|
-
}, await s.setRemoteDescription(
|
|
324
|
+
}, await s.setRemoteDescription(L), k("set remote description OK");
|
|
362
325
|
const h = await s.createAnswer();
|
|
363
|
-
return
|
|
326
|
+
return k("create answer OK"), await s.setLocalDescription(h), k("set local description OK"), await g(_, h, S), k("start connection OK"), {
|
|
364
327
|
/**
|
|
365
328
|
* Method to send request to server to get clip or talk depend on you payload
|
|
366
329
|
* @param payload
|
|
367
330
|
*/
|
|
368
331
|
speak(c) {
|
|
369
|
-
return
|
|
332
|
+
return u(_, S, c);
|
|
370
333
|
},
|
|
371
334
|
/**
|
|
372
335
|
* Method to close RTC connection
|
|
373
336
|
*/
|
|
374
337
|
async disconnect() {
|
|
375
|
-
var c, w;
|
|
376
|
-
if (
|
|
377
|
-
|
|
338
|
+
var c, w, v;
|
|
339
|
+
if (_) {
|
|
340
|
+
if (s) {
|
|
341
|
+
if (U(s.iceConnectionState) === M.New) {
|
|
342
|
+
(c = n.onVideoStateChange) == null || c.call(n, T.Stop), clearInterval(l);
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
s.close(), s.oniceconnectionstatechange = null, s.onnegotiationneeded = null, s.onicecandidate = null, s.ontrack = null;
|
|
346
|
+
}
|
|
378
347
|
try {
|
|
379
|
-
await
|
|
348
|
+
await f(_, S).catch((C) => {
|
|
380
349
|
});
|
|
381
|
-
} catch (
|
|
382
|
-
|
|
350
|
+
} catch (C) {
|
|
351
|
+
k("Error on close stream connection", C);
|
|
383
352
|
}
|
|
384
|
-
(
|
|
353
|
+
(w = n.onConnectionStateChange) == null || w.call(n, M.New), (v = n.onVideoStateChange) == null || v.call(n, T.Stop), clearInterval(l);
|
|
385
354
|
}
|
|
386
355
|
},
|
|
387
356
|
/**
|
|
388
357
|
* Session identifier information, should be returned in the body of all streaming requests
|
|
389
358
|
*/
|
|
390
|
-
sessionId:
|
|
359
|
+
sessionId: S,
|
|
391
360
|
/**
|
|
392
361
|
* Id of current RTC stream
|
|
393
362
|
*/
|
|
394
|
-
streamId:
|
|
363
|
+
streamId: _
|
|
395
364
|
};
|
|
396
365
|
}
|
|
397
|
-
function
|
|
398
|
-
const
|
|
366
|
+
function me(e) {
|
|
367
|
+
const a = {
|
|
399
368
|
token: e.token || "testKey",
|
|
400
|
-
distinct_id: e.distinctId ||
|
|
369
|
+
distinct_id: e.distinctId || W(),
|
|
401
370
|
isEnabled: e.isEnabled ?? !0,
|
|
402
371
|
agentId: e.agent.id,
|
|
403
372
|
owner_id: e.agent.owner_id ?? ""
|
|
404
373
|
};
|
|
405
374
|
return {
|
|
406
|
-
...
|
|
375
|
+
...a,
|
|
407
376
|
getRandom: () => Math.random().toString(16).slice(2),
|
|
408
377
|
track(t, n) {
|
|
409
378
|
if (!this.isEnabled)
|
|
410
379
|
return Promise.reject("MixPanel analytics is disabled on creation");
|
|
411
|
-
const
|
|
380
|
+
const r = {
|
|
412
381
|
method: "POST",
|
|
413
382
|
headers: {
|
|
414
383
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
@@ -418,7 +387,7 @@ function le(e) {
|
|
|
418
387
|
event: t,
|
|
419
388
|
properties: {
|
|
420
389
|
...n,
|
|
421
|
-
...
|
|
390
|
+
...a,
|
|
422
391
|
time: Date.now(),
|
|
423
392
|
$insert_id: this.getRandom(),
|
|
424
393
|
origin: window.location.href,
|
|
@@ -429,59 +398,61 @@ function le(e) {
|
|
|
429
398
|
}])
|
|
430
399
|
})
|
|
431
400
|
};
|
|
432
|
-
return fetch("https://api-js.mixpanel.com/track/?verbose=1&ip=1",
|
|
401
|
+
return fetch("https://api-js.mixpanel.com/track/?verbose=1&ip=1", r).then((i) => i.json()).catch((i) => console.error(i));
|
|
433
402
|
}
|
|
434
403
|
};
|
|
435
404
|
}
|
|
436
|
-
function
|
|
437
|
-
var n,
|
|
438
|
-
const
|
|
405
|
+
function we(e) {
|
|
406
|
+
var n, r, i, o, d;
|
|
407
|
+
const a = () => /Mobi|Android/i.test(navigator.userAgent) ? "Mobile" : "Desktop";
|
|
439
408
|
return {
|
|
440
409
|
$os: `${(() => {
|
|
441
410
|
const g = navigator.platform;
|
|
442
411
|
return g.toLowerCase().includes("win") ? "Windows" : g.toLowerCase().includes("mac") ? "Mac OS X" : g.toLowerCase().includes("linux") ? "Linux" : "Unknown";
|
|
443
412
|
})()}`,
|
|
444
|
-
isMobile: `${
|
|
413
|
+
isMobile: `${a() == "Mobile"}`,
|
|
445
414
|
browser: navigator.userAgent,
|
|
446
415
|
origin: window.location.origin,
|
|
447
416
|
agentType: (n = e.presenter) == null ? void 0 : n.type,
|
|
448
417
|
agentVoice: {
|
|
449
|
-
voiceId: (i = (
|
|
418
|
+
voiceId: (i = (r = e.presenter) == null ? void 0 : r.voice) == null ? void 0 : i.voice_id,
|
|
450
419
|
provider: (d = (o = e.presenter) == null ? void 0 : o.voice) == null ? void 0 : d.type
|
|
451
420
|
}
|
|
452
421
|
};
|
|
453
422
|
}
|
|
454
|
-
|
|
423
|
+
const he = 1080;
|
|
424
|
+
function fe(e, a) {
|
|
455
425
|
if (e.presenter) {
|
|
456
|
-
if (e.presenter.type ===
|
|
426
|
+
if (e.presenter.type === y.Clip)
|
|
457
427
|
return {
|
|
458
|
-
videoType:
|
|
428
|
+
videoType: y.Clip,
|
|
459
429
|
driver_id: e.presenter.driver_id,
|
|
460
430
|
presenter_id: e.presenter.presenter_id,
|
|
461
431
|
stream_warmup: !0
|
|
462
432
|
};
|
|
463
433
|
} else
|
|
464
434
|
throw new Error("Presenter is not initialized");
|
|
435
|
+
const t = a || (e.presenter.stitch ? he : void 0);
|
|
465
436
|
return {
|
|
466
|
-
videoType:
|
|
437
|
+
videoType: y.Talk,
|
|
467
438
|
source_url: e.presenter.source_url,
|
|
468
439
|
stream_warmup: !0,
|
|
469
|
-
...
|
|
470
|
-
|
|
440
|
+
...t && {
|
|
441
|
+
output_resolution: t
|
|
471
442
|
}
|
|
472
443
|
};
|
|
473
444
|
}
|
|
474
|
-
function
|
|
445
|
+
function B(e, a, t, n, r) {
|
|
475
446
|
return new Promise(async (i, o) => {
|
|
476
|
-
let d =
|
|
477
|
-
const g = await
|
|
478
|
-
...
|
|
447
|
+
let d = r;
|
|
448
|
+
const g = await ue(e.id, fe(e, a.outputResolution), {
|
|
449
|
+
...a,
|
|
479
450
|
analytics: n,
|
|
480
451
|
callbacks: {
|
|
481
|
-
...
|
|
482
|
-
onConnectionStateChange: async (
|
|
483
|
-
var
|
|
484
|
-
if (
|
|
452
|
+
...a.callbacks,
|
|
453
|
+
onConnectionStateChange: async (u) => {
|
|
454
|
+
var f, p;
|
|
455
|
+
if (u === M.Connected)
|
|
485
456
|
try {
|
|
486
457
|
d || (d = await t.newChat(e.id), n.track("agent-chat", {
|
|
487
458
|
event: "created",
|
|
@@ -491,212 +462,215 @@ function z(e, r, t, n, a) {
|
|
|
491
462
|
chat: d,
|
|
492
463
|
streamingManager: g
|
|
493
464
|
});
|
|
494
|
-
} catch (
|
|
495
|
-
console.error(
|
|
465
|
+
} catch ($) {
|
|
466
|
+
console.error($), o("Cannot create new chat");
|
|
496
467
|
}
|
|
497
468
|
else
|
|
498
|
-
|
|
499
|
-
(
|
|
469
|
+
u === M.Fail && o(new Error("Cannot create connection"));
|
|
470
|
+
(p = (f = a.callbacks).onConnectionStateChange) == null || p.call(f, u);
|
|
500
471
|
},
|
|
501
|
-
onVideoStateChange(
|
|
502
|
-
var f,
|
|
503
|
-
(
|
|
472
|
+
onVideoStateChange(u) {
|
|
473
|
+
var f, p;
|
|
474
|
+
(p = (f = a.callbacks).onVideoStateChange) == null || p.call(f, u);
|
|
504
475
|
}
|
|
505
476
|
}
|
|
506
477
|
}).catch(o);
|
|
507
478
|
});
|
|
508
479
|
}
|
|
509
|
-
function
|
|
510
|
-
return
|
|
480
|
+
function pe(e, a, t) {
|
|
481
|
+
return J(a, t || N).getById(e);
|
|
511
482
|
}
|
|
512
|
-
function
|
|
513
|
-
let
|
|
483
|
+
function D(e) {
|
|
484
|
+
let a = "";
|
|
514
485
|
if (e.greetings && e.greetings.length > 0) {
|
|
515
486
|
const t = Math.floor(Math.random() * e.greetings.length);
|
|
516
|
-
|
|
487
|
+
a = e.greetings[t];
|
|
517
488
|
} else
|
|
518
|
-
|
|
489
|
+
a = `Hi! I'm ${e.preview_name}, welcome to agents. How can I help you?`;
|
|
519
490
|
return [{
|
|
520
|
-
content:
|
|
521
|
-
id:
|
|
491
|
+
content: a,
|
|
492
|
+
id: z(),
|
|
522
493
|
role: "assistant",
|
|
523
494
|
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
524
495
|
}];
|
|
525
496
|
}
|
|
526
|
-
async function
|
|
527
|
-
var
|
|
497
|
+
async function ve(e, a) {
|
|
498
|
+
var L, O, S;
|
|
528
499
|
const t = {
|
|
529
500
|
messages: [],
|
|
530
|
-
chatMode:
|
|
501
|
+
chatMode: a.mode || R.Functional
|
|
531
502
|
};
|
|
532
503
|
let n = -1;
|
|
533
|
-
const
|
|
534
|
-
t.messages =
|
|
535
|
-
const
|
|
504
|
+
const r = a.wsURL || te, i = a.baseURL || N, o = a.mixpanelKey || ne, d = J(a.auth, i), g = await d.getById(e);
|
|
505
|
+
t.messages = D(g), (O = (L = a.callbacks).onNewMessage) == null || O.call(L, t.messages);
|
|
506
|
+
const u = me({
|
|
536
507
|
token: o,
|
|
537
508
|
agent: g,
|
|
538
|
-
...
|
|
509
|
+
...a
|
|
539
510
|
});
|
|
540
|
-
|
|
511
|
+
u.track("agent-sdk", {
|
|
541
512
|
event: "loaded",
|
|
542
|
-
...
|
|
513
|
+
...we(g)
|
|
543
514
|
});
|
|
544
|
-
const
|
|
545
|
-
onMessage: (s,
|
|
546
|
-
var
|
|
547
|
-
if ("content" in
|
|
515
|
+
const f = {
|
|
516
|
+
onMessage: (s, m) => {
|
|
517
|
+
var l, h;
|
|
518
|
+
if ("content" in m) {
|
|
548
519
|
const {
|
|
549
520
|
content: c
|
|
550
|
-
} =
|
|
551
|
-
(w == null ? void 0 : w.role) === "assistant" && (n < t.messages.length && (w.content = s ===
|
|
521
|
+
} = m, w = t.messages[t.messages.length - 1];
|
|
522
|
+
(w == null ? void 0 : w.role) === "assistant" && (n < t.messages.length && (w.content = s === b.Partial ? w.content + c : c), s === b.Answer && (n = t.messages.length)), s === b.Answer && u.track("agent-message-received", {
|
|
552
523
|
messages: t.messages.length
|
|
553
|
-
}), (h = (
|
|
554
|
-
} else if ([
|
|
524
|
+
}), (h = (l = a.callbacks).onNewMessage) == null || h.call(l, t.messages);
|
|
525
|
+
} else if ([A.StreamVideoCreated, A.StreamVideoDone, A.StreamVideoError, A.StreamVideoRejected].includes(s)) {
|
|
555
526
|
const c = s.split("/")[1];
|
|
556
|
-
|
|
557
|
-
...
|
|
527
|
+
u.track("agent-video", {
|
|
528
|
+
...m,
|
|
558
529
|
event: c
|
|
559
530
|
});
|
|
560
531
|
}
|
|
561
532
|
}
|
|
562
533
|
};
|
|
563
|
-
async function
|
|
564
|
-
var h, c, w,
|
|
565
|
-
const s = await
|
|
566
|
-
streamingManager:
|
|
567
|
-
chat:
|
|
568
|
-
} = await
|
|
569
|
-
n = -1, t.messages.length === 0 && (t.messages =
|
|
534
|
+
async function p() {
|
|
535
|
+
var h, c, w, v, C;
|
|
536
|
+
const s = await K(a.auth, r, f), {
|
|
537
|
+
streamingManager: m,
|
|
538
|
+
chat: l
|
|
539
|
+
} = await B(g, a, d, u, t.chat);
|
|
540
|
+
n = -1, t.messages.length === 0 && (t.messages = D(g), (c = (h = a.callbacks).onNewMessage) == null || c.call(h, t.messages)), l != null && l.id && l.id !== ((w = t.chat) == null ? void 0 : w.id) && ((C = (v = a.callbacks).onNewChat) == null || C.call(v, l == null ? void 0 : l.id)), t.streamingManager = m, t.socketManager = s, t.chat = l, _(R.Functional), u.track("agent-chat", {
|
|
570
541
|
event: "connect",
|
|
571
|
-
chatId:
|
|
542
|
+
chatId: l.id,
|
|
572
543
|
agentId: g.id
|
|
573
544
|
});
|
|
574
545
|
}
|
|
575
|
-
async function
|
|
576
|
-
var s,
|
|
577
|
-
(s = t.socketManager) == null || s.disconnect(), await ((
|
|
546
|
+
async function $() {
|
|
547
|
+
var s, m, l, h, c;
|
|
548
|
+
(s = t.socketManager) == null || s.disconnect(), await ((m = t.streamingManager) == null ? void 0 : m.disconnect()), delete t.streamingManager, delete t.socketManager, t.messages = D(g), (h = (l = a.callbacks).onNewMessage) == null || h.call(l, t.messages), u.track("agent-chat", {
|
|
578
549
|
event: "disconnect",
|
|
579
550
|
chatId: (c = t.chat) == null ? void 0 : c.id,
|
|
580
551
|
agentId: g.id
|
|
581
552
|
});
|
|
582
553
|
}
|
|
583
|
-
async function
|
|
584
|
-
var
|
|
585
|
-
s !== t.chatMode && (
|
|
554
|
+
async function _(s) {
|
|
555
|
+
var m, l;
|
|
556
|
+
s !== t.chatMode && (u.track("agent-mode-change", {
|
|
586
557
|
mode: s
|
|
587
|
-
}), t.chatMode = s, t.chatMode !==
|
|
558
|
+
}), t.chatMode = s, t.chatMode !== R.Functional && await $(), (l = (m = a.callbacks).onModeChange) == null || l.call(m, s));
|
|
588
559
|
}
|
|
589
560
|
return {
|
|
590
561
|
agent: g,
|
|
591
|
-
starterMessages: ((
|
|
592
|
-
connect:
|
|
593
|
-
disconnect:
|
|
594
|
-
changeMode:
|
|
562
|
+
starterMessages: ((S = g.knowledge) == null ? void 0 : S.starter_message) || [],
|
|
563
|
+
connect: p,
|
|
564
|
+
disconnect: $,
|
|
565
|
+
changeMode: _,
|
|
595
566
|
async reconnect() {
|
|
596
567
|
var h, c;
|
|
597
568
|
if (!t.chat)
|
|
598
|
-
return
|
|
569
|
+
return p();
|
|
599
570
|
(h = t.socketManager) == null || h.disconnect(), await ((c = t.streamingManager) == null ? void 0 : c.disconnect());
|
|
600
|
-
const s = await
|
|
601
|
-
streamingManager:
|
|
602
|
-
chat:
|
|
603
|
-
} = await
|
|
604
|
-
t.streamingManager =
|
|
571
|
+
const s = await K(a.auth, r, f), {
|
|
572
|
+
streamingManager: m,
|
|
573
|
+
chat: l
|
|
574
|
+
} = await B(g, a, d, u, t.chat);
|
|
575
|
+
t.streamingManager = m, t.socketManager = s, _(R.Functional), u.track("agent-chat", {
|
|
605
576
|
event: "reconnect",
|
|
606
|
-
chatId:
|
|
577
|
+
chatId: l.id,
|
|
607
578
|
agentId: g.id
|
|
608
579
|
});
|
|
609
580
|
},
|
|
610
|
-
async chat(s,
|
|
611
|
-
var
|
|
581
|
+
async chat(s, m = !1) {
|
|
582
|
+
var h, c, w, v, C, E;
|
|
583
|
+
const l = z();
|
|
612
584
|
try {
|
|
613
|
-
const
|
|
585
|
+
const I = Date.now();
|
|
614
586
|
if (s.length >= 800)
|
|
615
587
|
throw new Error("Message cannot be more than 800 characters");
|
|
616
588
|
if (s.length === 0)
|
|
617
589
|
throw new Error("Message cannot be empty");
|
|
618
|
-
if (t.chatMode ===
|
|
590
|
+
if (t.chatMode === R.Maintenance)
|
|
619
591
|
throw new Error("Chat is in maintenance mode");
|
|
620
|
-
if (![
|
|
592
|
+
if (![R.TextOnly, R.Playground].includes(t.chatMode)) {
|
|
621
593
|
if (!t.streamingManager)
|
|
622
594
|
throw new Error("Streaming manager is not initialized");
|
|
623
595
|
if (!t.chat)
|
|
624
596
|
throw new Error("Chat is not initialized");
|
|
625
597
|
}
|
|
626
598
|
t.messages.push({
|
|
627
|
-
id:
|
|
599
|
+
id: z(),
|
|
628
600
|
role: "user",
|
|
629
601
|
content: s,
|
|
630
|
-
created_at: new Date(
|
|
631
|
-
}), (
|
|
632
|
-
const
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
602
|
+
created_at: new Date(I).toISOString()
|
|
603
|
+
}), (c = (h = a.callbacks).onNewMessage) == null || c.call(h, t.messages), t.chat || (t.chat = await d.newChat(g.id));
|
|
604
|
+
const P = {
|
|
605
|
+
id: l,
|
|
606
|
+
role: "assistant",
|
|
607
|
+
content: "",
|
|
608
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
609
|
+
matches: []
|
|
610
|
+
};
|
|
611
|
+
t.messages.push(P);
|
|
612
|
+
const x = await d.chat(g.id, t.chat.id, {
|
|
613
|
+
sessionId: (w = t.streamingManager) == null ? void 0 : w.sessionId,
|
|
614
|
+
streamId: (v = t.streamingManager) == null ? void 0 : v.streamId,
|
|
615
|
+
messages: t.messages.slice(0, -1),
|
|
636
616
|
chatMode: t.chatMode,
|
|
637
|
-
append_chat:
|
|
617
|
+
append_chat: m
|
|
638
618
|
});
|
|
639
|
-
return
|
|
619
|
+
return u.track("agent-message-send", {
|
|
640
620
|
event: "success",
|
|
641
621
|
messages: t.messages.length + 1
|
|
642
|
-
}),
|
|
643
|
-
|
|
644
|
-
role: "assistant",
|
|
645
|
-
content: R.result || "",
|
|
646
|
-
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
647
|
-
matches: R.matches
|
|
648
|
-
}), R.result && (l.track("agent-message-received", {
|
|
649
|
-
latency: Date.now() - A,
|
|
622
|
+
}), P.context = x.context, x.result && (P.content = x.result, P.matches = x.matches, u.track("agent-message-received", {
|
|
623
|
+
latency: Date.now() - I,
|
|
650
624
|
messages: t.messages.length
|
|
651
|
-
}), (
|
|
652
|
-
} catch (
|
|
653
|
-
throw l.track("agent-message-send", {
|
|
625
|
+
}), (E = (C = a.callbacks).onNewMessage) == null || E.call(C, t.messages)), x;
|
|
626
|
+
} catch (I) {
|
|
627
|
+
throw t.messages[t.messages.length - 1].id === l && t.messages.pop(), u.track("agent-message-send", {
|
|
654
628
|
event: "error",
|
|
655
629
|
messages: t.messages.length
|
|
656
|
-
}),
|
|
630
|
+
}), I;
|
|
657
631
|
}
|
|
658
632
|
},
|
|
659
|
-
rate(s,
|
|
660
|
-
var w,
|
|
661
|
-
const h = t.messages.find((
|
|
633
|
+
rate(s, m, l) {
|
|
634
|
+
var w, v, C, E;
|
|
635
|
+
const h = t.messages.find((I) => I.id === s);
|
|
662
636
|
if (t.chat) {
|
|
663
637
|
if (!h)
|
|
664
638
|
throw new Error("Message not found");
|
|
665
639
|
} else
|
|
666
640
|
throw new Error("Chat is not initialized");
|
|
667
|
-
const c = ((w = h.matches) == null ? void 0 : w.map((
|
|
668
|
-
return
|
|
669
|
-
event:
|
|
670
|
-
thumb:
|
|
671
|
-
knowledge_id: ((
|
|
641
|
+
const c = ((w = h.matches) == null ? void 0 : w.map((I) => [I.document_id, I.id])) ?? [];
|
|
642
|
+
return u.track("agent-rate", {
|
|
643
|
+
event: l ? "update" : "create",
|
|
644
|
+
thumb: m === 1 ? "up" : "down",
|
|
645
|
+
knowledge_id: ((v = g.knowledge) == null ? void 0 : v.id) ?? "",
|
|
672
646
|
matches: c,
|
|
673
|
-
score:
|
|
674
|
-
}),
|
|
675
|
-
knowledge_id: ((
|
|
647
|
+
score: m
|
|
648
|
+
}), l ? d.updateRating(g.id, t.chat.id, l, {
|
|
649
|
+
knowledge_id: ((C = g.knowledge) == null ? void 0 : C.id) ?? "",
|
|
676
650
|
message_id: s,
|
|
677
651
|
matches: c,
|
|
678
|
-
score:
|
|
652
|
+
score: m
|
|
679
653
|
}) : d.createRating(g.id, t.chat.id, {
|
|
680
|
-
knowledge_id: ((
|
|
654
|
+
knowledge_id: ((E = g.knowledge) == null ? void 0 : E.id) ?? "",
|
|
681
655
|
message_id: s,
|
|
682
656
|
matches: c,
|
|
683
|
-
score:
|
|
657
|
+
score: m
|
|
684
658
|
});
|
|
685
659
|
},
|
|
686
660
|
deleteRate(s) {
|
|
687
|
-
var
|
|
661
|
+
var m;
|
|
688
662
|
if (!t.chat)
|
|
689
663
|
throw new Error("Chat is not initialized");
|
|
690
|
-
return
|
|
664
|
+
return u.track("agent-rate-delete", {
|
|
691
665
|
type: "text",
|
|
692
|
-
chat_id: (
|
|
666
|
+
chat_id: (m = t.chat) == null ? void 0 : m.id,
|
|
693
667
|
id: s
|
|
694
668
|
}), d.deleteRating(g.id, t.chat.id, s);
|
|
695
669
|
},
|
|
696
670
|
speak(s) {
|
|
697
671
|
if (!t.streamingManager)
|
|
698
672
|
throw new Error("Streaming manager is not initialized");
|
|
699
|
-
function
|
|
673
|
+
function m() {
|
|
700
674
|
if (g.presenter) {
|
|
701
675
|
if (s.type === "text")
|
|
702
676
|
return {
|
|
@@ -714,28 +688,28 @@ async function he(e, r) {
|
|
|
714
688
|
throw new Error("Presenter is not initialized");
|
|
715
689
|
throw new Error("Invalid payload");
|
|
716
690
|
}
|
|
717
|
-
const
|
|
718
|
-
return
|
|
719
|
-
script:
|
|
691
|
+
const l = m();
|
|
692
|
+
return u.track("agent-speak", l), t.streamingManager.speak({
|
|
693
|
+
script: l
|
|
720
694
|
});
|
|
721
695
|
}
|
|
722
696
|
};
|
|
723
697
|
}
|
|
724
698
|
export {
|
|
725
|
-
|
|
726
|
-
|
|
699
|
+
R as ChatMode,
|
|
700
|
+
b as ChatProgress,
|
|
727
701
|
M as ConnectionState,
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
702
|
+
Z as DocumentType,
|
|
703
|
+
Y as KnowledgeType,
|
|
704
|
+
q as PlanGroup,
|
|
705
|
+
G as Providers,
|
|
706
|
+
Q as RateState,
|
|
707
|
+
A as StreamEvents,
|
|
708
|
+
T as StreamingState,
|
|
709
|
+
X as Subject,
|
|
710
|
+
j as UserPlan,
|
|
711
|
+
y as VideoType,
|
|
712
|
+
ee as VoiceAccess,
|
|
713
|
+
ve as createAgentManager,
|
|
714
|
+
pe as getAgent
|
|
741
715
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(w,T){typeof exports=="object"&&typeof module<"u"?T(exports):typeof define=="function"&&define.amd?define(["exports"],T):(w=typeof globalThis<"u"?globalThis:w||self,T(w.index={}))})(this,function(w){"use strict";var T=(e=>(e.TRIAL="trial",e.BASIC="basic",e.ENTERPRISE="enterprise",e.LITE="lite",e.ADVANCED="advanced",e))(T||{}),z=(e=>(e.TRIAL="deid-trial",e.PRO="deid-pro",e.ENTERPRISE="deid-enterprise",e.LITE="deid-lite",e.ADVANCED="deid-advanced",e.BUILD="deid-api-build",e.LAUNCH="deid-api-launch",e.SCALE="deid-api-scale",e))(z||{}),D=(e=>(e.Unrated="Unrated",e.Positive="Positive",e.Negative="Negative",e))(D||{}),R=(e=>(e.Functional="Functional",e.TextOnly="TextOnly",e.Maintenance="Maintenance",e.Playground="Playground",e))(R||{}),N=(e=>(e.Embed="embed",e.Query="query",e.Partial="partial",e.Answer="answer",e.Complete="done",e))(N||{}),H=(e=>(e.KnowledgeProcessing="knowledge/processing",e.KnowledgeIndexing="knowledge/indexing",e.KnowledgeFailed="knowledge/error",e.KnowledgeDone="knowledge/done",e))(H||{}),x=(e=>(e.Knowledge="knowledge",e.Document="document",e.Record="record",e))(x||{}),U=(e=>(e.Pdf="pdf",e.Text="text",e.Html="html",e.Word="word",e.Json="json",e.Markdown="markdown",e.Csv="csv",e.Excel="excel",e.Powerpoint="powerpoint",e.Archive="archive",e.Image="image",e.Audio="audio",e.Video="video",e))(U||{}),C=(e=>(e.Clip="clip",e.Talk="talk",e))(C||{}),O=(e=>(e.Start="START",e.Stop="STOP",e))(O||{}),E=(e=>(e.ChatAnswer="chat/answer",e.ChatPartial="chat/partial",e.StreamDone="stream/done",e.StreamStarted="stream/started",e.StreamFailed="stream/error",e.StreamReady="stream/ready",e.StreamCreated="stream/created",e.StreamVideoCreated="stream-video/started",e.StreamVideoDone="stream-video/done",e.StreamVideoError="stream-video/error",e.StreamVideoRejected="stream-video/rejected",e))(E||{}),k=(e=>(e[e.New=0]="New",e[e.Fail=1]="Fail",e[e.Connected=2]="Connected",e[e.Connecting=3]="Connecting",e[e.Terminating=4]="Terminating",e))(k||{}),B=(e=>(e.Amazon="amazon",e.Microsoft="microsoft",e.Afflorithmics="afflorithmics",e.Elevenlabs="elevenlabs",e))(B||{}),J=(e=>(e.Public="public",e.Premium="premium",e.Private="private",e))(J||{});const F="https://api.d-id.com",G="wss://notifications.d-id.com",ee="79f81a83a67430be2bc0fd61042b8faa",K=()=>Math.random().toString(16).slice(2);function V(){let e=window.localStorage.getItem("did_external_key_id");return e||(e=Math.random().toString(16).slice(2),window.localStorage.setItem("did_external_key_id",e)),e}let te=K();function q(e){if(e.type==="bearer")return`Bearer ${e.token}`;if(e.type==="basic")return`Basic ${btoa(`${e.username}:${e.password}`)}`;if(e.type==="key")return`Client-Key ${e.clientKey}.${V()}_${te}`;throw new Error(`Unknown auth type: ${e}`)}function W(e,i=F){const t=async(n,a)=>{const r=await fetch(i+(n!=null&&n.startsWith("/")?n:`/${n}`),{...a,headers:{...a==null?void 0:a.headers,Authorization:q(e),"Content-Type":"application/json"}});if(!r.ok){let o=await r.text().catch(()=>"Failed to fetch");throw new Error(o)}return r.json()};return{get(n,a){return t(n,{...a,method:"GET"})},post(n,a,r){return t(n,{...r,body:JSON.stringify(a),method:"POST"})},delete(n,a,r){return t(n,{...r,body:JSON.stringify(a),method:"DELETE"})},patch(n,a,r){return t(n,{...r,body:JSON.stringify(a),method:"PATCH"})}}}function Q(e,i=F){const t=W(e,`${i}/agents`);return{create(n,a){return t.post("/",n,a)},getAgents(n,a){return t.get(`/${n?`?tag=${n}`:""}`,a).then(r=>r??[])},getById(n,a){return t.get(`/${n}`,a)},delete(n,a){return t.delete(`/${n}`,void 0,a)},update(n,a,r){return t.patch(`/${n}`,a,r)},newChat(n,a){return t.post(`/${n}/chat`,void 0,a)},chat(n,a,r,o){return t.post(`/${n}/chat/${a}`,r,o)},createRating(n,a,r,o){return t.post(`/${n}/chat/${a}/ratings`,r,o)},updateRating(n,a,r,o,d){return t.patch(`/${n}/chat/${a}/ratings/${r}`,o,d)},deleteRating(n,a,r,o){return t.delete(`/${n}/chat/${a}/ratings/${r}`,o)}}}const ne=e=>new Promise(i=>setTimeout(i,e));function ae(e){return new Promise((i,t)=>{const{callbacks:n,host:a,auth:r}=e,{onMessage:o=null,onOpen:d=null,onClose:g=null,onError:l=null}=n||{},y=new WebSocket(`${a}?authorization=${q(r)}`);y.onmessage=o,y.onclose=g,y.onerror=p=>{console.error(p),l==null||l("Websocket failed to connect",p),t(p)},y.onopen=p=>{d==null||d(p),i(y)}})}async function ie(e){const{retries:i=1}=e;let t=null;for(let n=0;(t==null?void 0:t.readyState)!==WebSocket.OPEN;n++)try{t=await ae(e)}catch(a){if(n===i)throw a;await ne(n*500)}return t}async function X(e,i,t){const n=t!=null&&t.onMessage?[t.onMessage]:[],a=await ie({auth:e,host:i,callbacks:{onError:t==null?void 0:t.onError,onMessage:r=>{const o=JSON.parse(r.data);n.forEach(d=>d(o.event,o))}}});return{socket:a,disconnect:()=>a.close(),subscribeToEvents:r=>n.push(r)}}function re(e,i,t){const n=W(e,`${i}/agents/${t}`);return{createStream(a){return n.post("/streams",{driver_id:a.driver_id,presenter_id:a.presenter_id,compatibility_mode:a.compatibility_mode,stream_warmup:a.stream_warmup,type:C.Clip})},startConnection(a,r,o){return n.post(`/streams/${a}/sdp`,{session_id:o,answer:r,type:C.Clip})},addIceCandidate(a,r,o){return n.post(`/streams/${a}/ice`,{session_id:o,...r,type:C.Clip})},sendStreamRequest(a,r,o){return n.post(`/streams/${a}`,{session_id:r,...o,type:C.Clip})},close(a,r){return n.delete(`/streams/${a}`,{session_id:r,type:C.Clip})}}}function se(e,i,t){const n=W(e,`${i}/agents/${t}`);return{createStream(a,r){return n.post("/streams",{source_url:a.source_url,driver_url:a.driver_url,face:a.face,config:a.config,compatibility_mode:a.compatibility_mode,stream_warmup:a.stream_warmup,stream_resolution:a.stream_resolution,type:C.Talk},r)},startConnection(a,r,o,d){return n.post(`/streams/${a}/sdp`,{session_id:o,answer:r,type:C.Talk},d)},addIceCandidate(a,r,o,d){return n.post(`/streams/${a}/ice`,{session_id:o,...r,type:C.Talk},d)},sendStreamRequest(a,r,o,d){return n.post(`/streams/${a}`,{session_id:r,...o,type:C.Talk},d)},close(a,r,o){return n.delete(`/streams/${a}`,{session_id:r,type:C.Talk},o)}}}function oe(e,i){return e.map((t,n)=>n===0?i?{index:n,timestamp:t.timestamp,bytesReceived:t.bytesReceived-i.bytesReceived,packetsReceived:t.packetsReceived-i.packetsReceived,packetsLost:t.packetsLost-i.packetsLost,jitter:t.jitter,frameWidth:t.frameWidth,frameHeight:t.frameHeight,framesPerSecond:t.framesPerSecond}:{index:n,timestamp:t.timestamp,bytesReceived:t.bytesReceived,packetsReceived:t.packetsReceived,packetsLost:t.packetsLost,jitter:t.jitter,frameWidth:t.frameWidth,frameHeight:t.frameHeight,framesPerSecond:t.framesPerSecond}:{index:n,timestamp:t.timestamp,bytesReceived:t.bytesReceived-e[n-1].bytesReceived,packetsReceived:t.packetsReceived-e[n-1].packetsReceived,packetsLost:t.packetsLost-e[n-1].packetsLost,jitter:t.jitter,frameWidth:t.frameWidth,frameHeight:t.frameHeight,framesPerSecond:t.framesPerSecond})}let Y=!1;const $=(e,i)=>Y&&console.log(e,i),ce=(window.RTCPeerConnection||window.webkitRTCPeerConnection||window.mozRTCPeerConnection).bind(window);function de(e){switch(e){case"connected":return k.Connected;case"checking":return k.Connecting;case"failed":return k.Fail;case"new":case"closed":case"disconnected":default:return k.New}}function ge(e,i){let t=[],n=0,a=0,r=0,o;return setInterval(()=>{e.getStats().then(g=>{g.forEach(l=>{if(l.type==="inbound-rtp"&&l.kind==="video"){if(a=t.length-1,l&&t[a]){const y=l.bytesReceived,p=t[a].bytesReceived,M=o;let v;if(o=y-p>0,r=o?0:++r,M!==o)if(o)n=t.length,i==null||i(O.Start,v);else{const P=t.slice(n),L=n===0?void 0:t[n-1];v=oe(P,L),v=v.sort((_,s)=>s.packetsLost-_.packetsLost).slice(0,5)}!o&&r===2&&(i==null||i(O.Stop,v))}t.push(l)}})})},500)}async function le(e,i,{debug:t=!1,callbacks:n,auth:a,analytics:r,baseURL:o=F}){Y=t;let d;const{startConnection:g,sendStreamRequest:l,close:y,createStream:p,addIceCandidate:M}=i.videoType===C.Clip?re(a,o,e):se(a,o,e),{id:v,offer:P,ice_servers:L,session_id:_}=await p(i),s=new ce({iceServers:L}),u=s.createDataChannel("JanusDataChannel");if(!_)throw new Error("Could not create session_id");const m=ge(s,n.onVideoStateChange);s.onicecandidate=c=>{$("peerConnection.onicecandidate",c),c.candidate&&c.candidate.sdpMid&&c.candidate.sdpMLineIndex!==null?M(v,{candidate:c.candidate.candidate,sdpMid:c.candidate.sdpMid,sdpMLineIndex:c.candidate.sdpMLineIndex},_):M(v,{candidate:null},_)},s.oniceconnectionstatechange=()=>{var h;$("peerConnection.oniceconnectionstatechange => "+s.iceConnectionState);const c=de(s.iceConnectionState);c===k.Connected?d=setTimeout(()=>{var S;(S=n.onConnectionStateChange)==null||S.call(n,k.Connected)},5e3):(clearTimeout(d),(h=n.onConnectionStateChange)==null||h.call(n,c))},s.ontrack=c=>{var h;$("peerConnection.ontrack",c),(h=n.onSrcObjectReady)==null||h.call(n,c.streams[0])},u.onmessage=c=>{var h;if(u.readyState==="open"){const[S,I]=c.data.split(":");S===E.StreamReady&&(clearTimeout(d),(h=n.onConnectionStateChange)==null||h.call(n,k.Connected))}},await s.setRemoteDescription(P),$("set remote description OK");const f=await s.createAnswer();return $("create answer OK"),await s.setLocalDescription(f),$("set local description OK"),await g(v,f,_),$("start connection OK"),{speak(c){return l(v,_,c)},async disconnect(){var c,h;if(v){s&&(s.close(),s.oniceconnectionstatechange=null,s.onnegotiationneeded=null,s.onicecandidate=null,s.ontrack=null);try{await y(v,_).catch(S=>{})}catch(S){$("Error on close stream connection",S)}(c=n.onConnectionStateChange)==null||c.call(n,k.New),(h=n.onVideoStateChange)==null||h.call(n,O.Stop),clearInterval(m)}},sessionId:_,streamId:v}}function me(e){const i={token:e.token||"testKey",distinct_id:e.distinctId||V(),isEnabled:e.isEnabled??!0,agentId:e.agent.id,owner_id:e.agent.owner_id??""};return{...i,getRandom:()=>Math.random().toString(16).slice(2),track(t,n){if(!this.isEnabled)return Promise.reject("MixPanel analytics is disabled on creation");const a={method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({data:JSON.stringify([{event:t,properties:{...n,...i,time:Date.now(),$insert_id:this.getRandom(),origin:window.location.href,"Screen Height":window.screen.height||window.innerWidth,"Screen Width":window.screen.width||window.innerHeight,"User Agent":navigator.userAgent}}])})};return fetch("https://api-js.mixpanel.com/track/?verbose=1&ip=1",a).then(r=>r.json()).catch(r=>console.error(r))}}}function ue(e){var n,a,r,o,d;const i=()=>/Mobi|Android/i.test(navigator.userAgent)?"Mobile":"Desktop";return{$os:`${(()=>{const g=navigator.platform;return g.toLowerCase().includes("win")?"Windows":g.toLowerCase().includes("mac")?"Mac OS X":g.toLowerCase().includes("linux")?"Linux":"Unknown"})()}`,isMobile:`${i()=="Mobile"}`,browser:navigator.userAgent,origin:window.location.origin,agentType:(n=e.presenter)==null?void 0:n.type,agentVoice:{voiceId:(r=(a=e.presenter)==null?void 0:a.voice)==null?void 0:r.voice_id,provider:(d=(o=e.presenter)==null?void 0:o.voice)==null?void 0:d.type}}}function he(e){if(e.presenter){if(e.presenter.type===C.Clip)return{videoType:C.Clip,driver_id:e.presenter.driver_id,presenter_id:e.presenter.presenter_id,stream_warmup:!0}}else throw new Error("Presenter is not initialized");return{videoType:C.Talk,source_url:e.presenter.source_url,stream_warmup:!0,...e.presenter.stitch&&{stream_resolution:1080}}}function Z(e,i,t,n,a){return new Promise(async(r,o)=>{let d=a;const g=await le(e.id,he(e),{...i,analytics:n,callbacks:{...i.callbacks,onConnectionStateChange:async l=>{var y,p;if(l===k.Connected)try{d||(d=await t.newChat(e.id),n.track("agent-chat",{event:"created",chat_id:d.id,agent_id:e.id})),g&&r({chat:d,streamingManager:g})}catch(M){console.error(M),o("Cannot create new chat")}else l===k.Fail&&o(new Error("Cannot create connection"));(p=(y=i.callbacks).onConnectionStateChange)==null||p.call(y,l)},onVideoStateChange(l,y){var p,M;(M=(p=i.callbacks).onVideoStateChange)==null||M.call(p,l,y)}}}).catch(o)})}function we(e,i,t){return Q(i,t||F).getById(e)}function j(e){let i="";if(e.greetings&&e.greetings.length>0){const t=Math.floor(Math.random()*e.greetings.length);i=e.greetings[t]}else i=`Hi! I'm ${e.preview_name}, welcome to agents. How can I help you?`;return[{content:i,id:K(),role:"assistant",created_at:new Date().toISOString()}]}async function fe(e,i){var P,L,_;const t={messages:[],chatMode:i.mode||R.Functional};let n=-1;const a=i.wsURL||G,r=i.baseURL||F,o=i.mixpanelKey||ee,d=Q(i.auth,r),g=await d.getById(e);t.messages=j(g),(L=(P=i.callbacks).onNewMessage)==null||L.call(P,t.messages);const l=me({token:o,agent:g,...i});l.track("agent-sdk",{event:"loaded",...ue(g)});const y={onMessage:(s,u)=>{var m,f;if("content"in u){const{content:c}=u,h=t.messages[t.messages.length-1];(h==null?void 0:h.role)==="assistant"&&(n<t.messages.length&&(h.content=s===N.Partial?h.content+c:c),s===N.Answer&&(n=t.messages.length)),s===N.Answer&&l.track("agent-message-received",{messages:t.messages.length}),(f=(m=i.callbacks).onNewMessage)==null||f.call(m,t.messages)}else if([E.StreamVideoCreated,E.StreamVideoDone,E.StreamVideoError,E.StreamVideoRejected].includes(s)){const c=s.split("/")[1];l.track("agent-video",{...u,event:c})}}};async function p(){var f,c,h,S,I;const s=await X(i.auth,a,y),{streamingManager:u,chat:m}=await Z(g,i,d,l,t.chat);n=-1,t.messages.length===0&&(t.messages=j(g),(c=(f=i.callbacks).onNewMessage)==null||c.call(f,t.messages)),m!=null&&m.id&&m.id!==((h=t.chat)==null?void 0:h.id)&&((I=(S=i.callbacks).onNewChat)==null||I.call(S,m==null?void 0:m.id)),t.streamingManager=u,t.socketManager=s,t.chat=m,v(R.Functional),l.track("agent-chat",{event:"connect",chatId:m.id,agentId:g.id})}async function M(){var s,u,m,f,c;(s=t.socketManager)==null||s.disconnect(),await((u=t.streamingManager)==null?void 0:u.disconnect()),delete t.streamingManager,delete t.socketManager,t.messages=j(g),(f=(m=i.callbacks).onNewMessage)==null||f.call(m,t.messages),l.track("agent-chat",{event:"disconnect",chatId:(c=t.chat)==null?void 0:c.id,agentId:g.id})}async function v(s){var u,m;s!==t.chatMode&&(l.track("agent-mode-change",{mode:s}),t.chatMode=s,t.chatMode!==R.Functional&&await M(),(m=(u=i.callbacks).onModeChange)==null||m.call(u,s))}return{agent:g,starterMessages:((_=g.knowledge)==null?void 0:_.starter_message)||[],connect:p,disconnect:M,changeMode:v,async reconnect(){var f,c;if(!t.chat)return p();(f=t.socketManager)==null||f.disconnect(),await((c=t.streamingManager)==null?void 0:c.disconnect());const s=await X(i.auth,a,y),{streamingManager:u,chat:m}=await Z(g,i,d,l,t.chat);t.streamingManager=u,t.socketManager=s,v(R.Functional),l.track("agent-chat",{event:"reconnect",chatId:m.id,agentId:g.id})},async chat(s,u=!1){var m,f,c,h,S,I;try{const b=Date.now();if(s.length>=800)throw new Error("Message cannot be more than 800 characters");if(s.length===0)throw new Error("Message cannot be empty");if(t.chatMode===R.Maintenance)throw new Error("Chat is in maintenance mode");if(![R.TextOnly,R.Playground].includes(t.chatMode)){if(!t.streamingManager)throw new Error("Streaming manager is not initialized");if(!t.chat)throw new Error("Chat is not initialized")}t.messages.push({id:K(),role:"user",content:s,created_at:new Date(b).toISOString()}),(f=(m=i.callbacks).onNewMessage)==null||f.call(m,t.messages),t.chat||(t.chat=await d.newChat(g.id));const A=await d.chat(g.id,t.chat.id,{sessionId:(c=t.streamingManager)==null?void 0:c.sessionId,streamId:(h=t.streamingManager)==null?void 0:h.streamId,messages:t.messages,chatMode:t.chatMode,append_chat:u});return l.track("agent-message-send",{event:"success",messages:t.messages.length+1}),t.messages.push({id:K(),role:"assistant",content:A.result||"",created_at:new Date().toISOString(),matches:A.matches}),A.result&&(l.track("agent-message-received",{latency:Date.now()-b,messages:t.messages.length}),(I=(S=i.callbacks).onNewMessage)==null||I.call(S,t.messages)),A}catch(b){throw l.track("agent-message-send",{event:"error",messages:t.messages.length}),b}},rate(s,u,m){var h,S,I,b;const f=t.messages.find(A=>A.id===s);if(t.chat){if(!f)throw new Error("Message not found")}else throw new Error("Chat is not initialized");const c=((h=f.matches)==null?void 0:h.map(A=>[A.document_id,A.id]))??[];return l.track("agent-rate",{event:m?"update":"create",thumb:u===1?"up":"down",knowledge_id:((S=g.knowledge)==null?void 0:S.id)??"",matches:c,score:u}),m?d.updateRating(g.id,t.chat.id,m,{knowledge_id:((I=g.knowledge)==null?void 0:I.id)??"",message_id:s,matches:c,score:u}):d.createRating(g.id,t.chat.id,{knowledge_id:((b=g.knowledge)==null?void 0:b.id)??"",message_id:s,matches:c,score:u})},deleteRate(s){var u;if(!t.chat)throw new Error("Chat is not initialized");return l.track("agent-rate-delete",{type:"text",chat_id:(u=t.chat)==null?void 0:u.id,id:s}),d.deleteRating(g.id,t.chat.id,s)},speak(s){if(!t.streamingManager)throw new Error("Streaming manager is not initialized");function u(){if(g.presenter){if(s.type==="text")return{type:"text",provider:s.provider?s.provider:g.presenter.voice,input:s.input,ssml:s.ssml||!1};if(s.type==="audio")return{type:"audio",audio_url:s.audio_url}}else throw new Error("Presenter is not initialized");throw new Error("Invalid payload")}const m=u();return l.track("agent-speak",m),t.streamingManager.speak({script:m})}}}w.ChatMode=R,w.ChatProgress=N,w.ConnectionState=k,w.DocumentType=U,w.KnowledgeType=x,w.PlanGroup=z,w.Providers=B,w.RateState=D,w.StreamEvents=E,w.StreamingState=O,w.Subject=H,w.UserPlan=T,w.VideoType=C,w.VoiceAccess=J,w.createAgentManager=fe,w.getAgent=we,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(h,T){typeof exports=="object"&&typeof module<"u"?T(exports):typeof define=="function"&&define.amd?define(["exports"],T):(h=typeof globalThis<"u"?globalThis:h||self,T(h.index={}))})(this,function(h){"use strict";var T=(e=>(e.TRIAL="trial",e.BASIC="basic",e.ENTERPRISE="enterprise",e.LITE="lite",e.ADVANCED="advanced",e))(T||{}),B=(e=>(e.TRIAL="deid-trial",e.PRO="deid-pro",e.ENTERPRISE="deid-enterprise",e.LITE="deid-lite",e.ADVANCED="deid-advanced",e.BUILD="deid-api-build",e.LAUNCH="deid-api-launch",e.SCALE="deid-api-scale",e))(B||{}),V=(e=>(e.Unrated="Unrated",e.Positive="Positive",e.Negative="Negative",e))(V||{}),A=(e=>(e.Functional="Functional",e.TextOnly="TextOnly",e.Maintenance="Maintenance",e.Playground="Playground",e))(A||{}),P=(e=>(e.Embed="embed",e.Query="query",e.Partial="partial",e.Answer="answer",e.Complete="done",e))(P||{}),W=(e=>(e.KnowledgeProcessing="knowledge/processing",e.KnowledgeIndexing="knowledge/indexing",e.KnowledgeFailed="knowledge/error",e.KnowledgeDone="knowledge/done",e))(W||{}),j=(e=>(e.Knowledge="knowledge",e.Document="document",e.Record="record",e))(j||{}),H=(e=>(e.Pdf="pdf",e.Text="text",e.Html="html",e.Word="word",e.Json="json",e.Markdown="markdown",e.Csv="csv",e.Excel="excel",e.Powerpoint="powerpoint",e.Archive="archive",e.Image="image",e.Audio="audio",e.Video="video",e))(H||{}),p=(e=>(e.Clip="clip",e.Talk="talk",e))(p||{}),N=(e=>(e.Start="START",e.Stop="STOP",e))(N||{}),$=(e=>(e.ChatAnswer="chat/answer",e.ChatPartial="chat/partial",e.StreamDone="stream/done",e.StreamStarted="stream/started",e.StreamFailed="stream/error",e.StreamReady="stream/ready",e.StreamCreated="stream/created",e.StreamVideoCreated="stream-video/started",e.StreamVideoDone="stream-video/done",e.StreamVideoError="stream-video/error",e.StreamVideoRejected="stream-video/rejected",e))($||{}),M=(e=>(e[e.New=0]="New",e[e.Fail=1]="Fail",e[e.Connected=2]="Connected",e[e.Connecting=3]="Connecting",e[e.Terminating=4]="Terminating",e))(M||{}),J=(e=>(e.Amazon="amazon",e.Microsoft="microsoft",e.Afflorithmics="afflorithmics",e.Elevenlabs="elevenlabs",e))(J||{}),q=(e=>(e.Public="public",e.Premium="premium",e.Private="private",e))(q||{});const b="https://api.d-id.com",ne="wss://notifications.d-id.com",re="79f81a83a67430be2bc0fd61042b8faa",O=()=>Math.random().toString(16).slice(2);function Q(){let e=window.localStorage.getItem("did_external_key_id");return e||(e=Math.random().toString(16).slice(2),window.localStorage.setItem("did_external_key_id",e)),e}let ie=O();function X(e){if(e.type==="bearer")return`Bearer ${e.token}`;if(e.type==="basic")return`Basic ${btoa(`${e.username}:${e.password}`)}`;if(e.type==="key")return`Client-Key ${e.clientKey}.${Q()}_${ie}`;throw new Error(`Unknown auth type: ${e}`)}function F(e,i=b){const t=async(n,r)=>{const a=await fetch(i+(n!=null&&n.startsWith("/")?n:`/${n}`),{...r,headers:{...r==null?void 0:r.headers,Authorization:X(e),"Content-Type":"application/json"}});if(!a.ok){let o=await a.text().catch(()=>"Failed to fetch");throw new Error(o)}return a.json()};return{get(n,r){return t(n,{...r,method:"GET"})},post(n,r,a){return t(n,{...a,body:JSON.stringify(r),method:"POST"})},delete(n,r,a){return t(n,{...a,body:JSON.stringify(r),method:"DELETE"})},patch(n,r,a){return t(n,{...a,body:JSON.stringify(r),method:"PATCH"})}}}function Y(e,i=b){const t=F(e,`${i}/agents`);return{create(n,r){return t.post("/",n,r)},getAgents(n,r){return t.get(`/${n?`?tag=${n}`:""}`,r).then(a=>a??[])},getById(n,r){return t.get(`/${n}`,r)},delete(n,r){return t.delete(`/${n}`,void 0,r)},update(n,r,a){return t.patch(`/${n}`,r,a)},newChat(n,r){return t.post(`/${n}/chat`,void 0,r)},chat(n,r,a,o){return t.post(`/${n}/chat/${r}`,a,o)},createRating(n,r,a,o){return t.post(`/${n}/chat/${r}/ratings`,a,o)},updateRating(n,r,a,o,d){return t.patch(`/${n}/chat/${r}/ratings/${a}`,o,d)},deleteRating(n,r,a,o){return t.delete(`/${n}/chat/${r}/ratings/${a}`,o)}}}const ae=e=>new Promise(i=>setTimeout(i,e));function se(e){return new Promise((i,t)=>{const{callbacks:n,host:r,auth:a}=e,{onMessage:o=null,onOpen:d=null,onClose:g=null,onError:u=null}=n||{},y=new WebSocket(`${r}?authorization=${X(a)}`);y.onmessage=o,y.onclose=g,y.onerror=v=>{console.error(v),u==null||u("Websocket failed to connect",v),t(v)},y.onopen=v=>{d==null||d(v),i(y)}})}async function oe(e){const{retries:i=1}=e;let t=null;for(let n=0;(t==null?void 0:t.readyState)!==WebSocket.OPEN;n++)try{t=await se(e)}catch(r){if(n===i)throw r;await ae(n*500)}return t}async function Z(e,i,t){const n=t!=null&&t.onMessage?[t.onMessage]:[],r=await oe({auth:e,host:i,callbacks:{onError:t==null?void 0:t.onError,onMessage:a=>{const o=JSON.parse(a.data);n.forEach(d=>d(o.event,o))}}});return{socket:r,disconnect:()=>r.close(),subscribeToEvents:a=>n.push(a)}}function ce(e,i,t){const n=F(e,`${i}/agents/${t}`);return{createStream(r){return n.post("/streams",{driver_id:r.driver_id,presenter_id:r.presenter_id,compatibility_mode:r.compatibility_mode,stream_warmup:r.stream_warmup,type:p.Clip})},startConnection(r,a,o){return n.post(`/streams/${r}/sdp`,{session_id:o,answer:a,type:p.Clip})},addIceCandidate(r,a,o){return n.post(`/streams/${r}/ice`,{session_id:o,...a,type:p.Clip})},sendStreamRequest(r,a,o){return n.post(`/streams/${r}`,{session_id:a,...o,type:p.Clip})},close(r,a){return n.delete(`/streams/${r}`,{session_id:a,type:p.Clip})}}}function de(e,i,t){const n=F(e,`${i}/agents/${t}`);return{createStream(r,a){return n.post("/streams",{source_url:r.source_url,driver_url:r.driver_url,face:r.face,config:r.config,compatibility_mode:r.compatibility_mode,stream_warmup:r.stream_warmup,output_resolution:r.output_resolution,type:p.Talk},a)},startConnection(r,a,o,d){return n.post(`/streams/${r}/sdp`,{session_id:o,answer:a,type:p.Talk},d)},addIceCandidate(r,a,o,d){return n.post(`/streams/${r}/ice`,{session_id:o,...a,type:p.Talk},d)},sendStreamRequest(r,a,o,d){return n.post(`/streams/${r}`,{session_id:a,...o,type:p.Talk},d)},close(r,a,o){return n.delete(`/streams/${r}`,{session_id:a,type:p.Talk},o)}}}let G=!1;const R=(e,i)=>G&&console.log(e,i),ge=(window.RTCPeerConnection||window.webkitRTCPeerConnection||window.mozRTCPeerConnection).bind(window);function ee(e){switch(e){case"connected":return M.Connected;case"checking":return M.Connecting;case"failed":return M.Fail;case"new":case"closed":case"disconnected":default:return M.New}}function le(){let e=0;return i=>{for(const t of i.values())if(t&&t.type==="inbound-rtp"&&t.kind==="video"){const n=t.bytesReceived,r=n-e>0;return e=n,r}return!1}}function ue(e,i,t){const r=Math.max(Math.ceil(10),1);let a=0,o=!1;const d=le();return setInterval(async()=>{const g=await e.getStats();d(g)?(a=0,o||(i==null||i(N.Start),o=!0)):o&&(a++,a>=r&&(i==null||i(N.Stop),o=!1))},100)}async function me(e,i,{debug:t=!1,callbacks:n,auth:r,analytics:a,baseURL:o=b}){G=t;let d;const{startConnection:g,sendStreamRequest:u,close:y,createStream:v,addIceCandidate:E}=i.videoType===p.Clip?ce(r,o,e):de(r,o,e),{id:S,offer:z,ice_servers:D,session_id:I}=await v(i),s=new ge({iceServers:D}),m=s.createDataChannel("JanusDataChannel");if(!I)throw new Error("Could not create session_id");const l=ue(s,n.onVideoStateChange);s.onicecandidate=c=>{R("peerConnection.onicecandidate",c),c.candidate&&c.candidate.sdpMid&&c.candidate.sdpMLineIndex!==null?E(S,{candidate:c.candidate.candidate,sdpMid:c.candidate.sdpMid,sdpMLineIndex:c.candidate.sdpMLineIndex},I):E(S,{candidate:null},I)},s.oniceconnectionstatechange=()=>{var w;R("peerConnection.oniceconnectionstatechange => "+s.iceConnectionState);const c=ee(s.iceConnectionState);c===M.Connected?d=setTimeout(()=>{var C;(C=n.onConnectionStateChange)==null||C.call(n,M.Connected)},5e3):(clearTimeout(d),(w=n.onConnectionStateChange)==null||w.call(n,c))},s.ontrack=c=>{var w;R("peerConnection.ontrack",c),(w=n.onSrcObjectReady)==null||w.call(n,c.streams[0])},m.onmessage=c=>{var w;if(m.readyState==="open"){const[C,_]=c.data.split(":");C===$.StreamReady&&(clearTimeout(d),(w=n.onConnectionStateChange)==null||w.call(n,M.Connected))}},await s.setRemoteDescription(z),R("set remote description OK");const f=await s.createAnswer();return R("create answer OK"),await s.setLocalDescription(f),R("set local description OK"),await g(S,f,I),R("start connection OK"),{speak(c){return u(S,I,c)},async disconnect(){var c,w,C;if(S){if(s){if(ee(s.iceConnectionState)===M.New){(c=n.onVideoStateChange)==null||c.call(n,N.Stop),clearInterval(l);return}s.close(),s.oniceconnectionstatechange=null,s.onnegotiationneeded=null,s.onicecandidate=null,s.ontrack=null}try{await y(S,I).catch(_=>{})}catch(_){R("Error on close stream connection",_)}(w=n.onConnectionStateChange)==null||w.call(n,M.New),(C=n.onVideoStateChange)==null||C.call(n,N.Stop),clearInterval(l)}},sessionId:I,streamId:S}}function we(e){const i={token:e.token||"testKey",distinct_id:e.distinctId||Q(),isEnabled:e.isEnabled??!0,agentId:e.agent.id,owner_id:e.agent.owner_id??""};return{...i,getRandom:()=>Math.random().toString(16).slice(2),track(t,n){if(!this.isEnabled)return Promise.reject("MixPanel analytics is disabled on creation");const r={method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({data:JSON.stringify([{event:t,properties:{...n,...i,time:Date.now(),$insert_id:this.getRandom(),origin:window.location.href,"Screen Height":window.screen.height||window.innerWidth,"Screen Width":window.screen.width||window.innerHeight,"User Agent":navigator.userAgent}}])})};return fetch("https://api-js.mixpanel.com/track/?verbose=1&ip=1",r).then(a=>a.json()).catch(a=>console.error(a))}}}function he(e){var n,r,a,o,d;const i=()=>/Mobi|Android/i.test(navigator.userAgent)?"Mobile":"Desktop";return{$os:`${(()=>{const g=navigator.platform;return g.toLowerCase().includes("win")?"Windows":g.toLowerCase().includes("mac")?"Mac OS X":g.toLowerCase().includes("linux")?"Linux":"Unknown"})()}`,isMobile:`${i()=="Mobile"}`,browser:navigator.userAgent,origin:window.location.origin,agentType:(n=e.presenter)==null?void 0:n.type,agentVoice:{voiceId:(a=(r=e.presenter)==null?void 0:r.voice)==null?void 0:a.voice_id,provider:(d=(o=e.presenter)==null?void 0:o.voice)==null?void 0:d.type}}}const fe=1080;function pe(e,i){if(e.presenter){if(e.presenter.type===p.Clip)return{videoType:p.Clip,driver_id:e.presenter.driver_id,presenter_id:e.presenter.presenter_id,stream_warmup:!0}}else throw new Error("Presenter is not initialized");const t=i||(e.presenter.stitch?fe:void 0);return{videoType:p.Talk,source_url:e.presenter.source_url,stream_warmup:!0,...t&&{output_resolution:t}}}function te(e,i,t,n,r){return new Promise(async(a,o)=>{let d=r;const g=await me(e.id,pe(e,i.outputResolution),{...i,analytics:n,callbacks:{...i.callbacks,onConnectionStateChange:async u=>{var y,v;if(u===M.Connected)try{d||(d=await t.newChat(e.id),n.track("agent-chat",{event:"created",chat_id:d.id,agent_id:e.id})),g&&a({chat:d,streamingManager:g})}catch(E){console.error(E),o("Cannot create new chat")}else u===M.Fail&&o(new Error("Cannot create connection"));(v=(y=i.callbacks).onConnectionStateChange)==null||v.call(y,u)},onVideoStateChange(u){var y,v;(v=(y=i.callbacks).onVideoStateChange)==null||v.call(y,u)}}}).catch(o)})}function ye(e,i,t){return Y(i,t||b).getById(e)}function U(e){let i="";if(e.greetings&&e.greetings.length>0){const t=Math.floor(Math.random()*e.greetings.length);i=e.greetings[t]}else i=`Hi! I'm ${e.preview_name}, welcome to agents. How can I help you?`;return[{content:i,id:O(),role:"assistant",created_at:new Date().toISOString()}]}async function ve(e,i){var z,D,I;const t={messages:[],chatMode:i.mode||A.Functional};let n=-1;const r=i.wsURL||ne,a=i.baseURL||b,o=i.mixpanelKey||re,d=Y(i.auth,a),g=await d.getById(e);t.messages=U(g),(D=(z=i.callbacks).onNewMessage)==null||D.call(z,t.messages);const u=we({token:o,agent:g,...i});u.track("agent-sdk",{event:"loaded",...he(g)});const y={onMessage:(s,m)=>{var l,f;if("content"in m){const{content:c}=m,w=t.messages[t.messages.length-1];(w==null?void 0:w.role)==="assistant"&&(n<t.messages.length&&(w.content=s===P.Partial?w.content+c:c),s===P.Answer&&(n=t.messages.length)),s===P.Answer&&u.track("agent-message-received",{messages:t.messages.length}),(f=(l=i.callbacks).onNewMessage)==null||f.call(l,t.messages)}else if([$.StreamVideoCreated,$.StreamVideoDone,$.StreamVideoError,$.StreamVideoRejected].includes(s)){const c=s.split("/")[1];u.track("agent-video",{...m,event:c})}}};async function v(){var f,c,w,C,_;const s=await Z(i.auth,r,y),{streamingManager:m,chat:l}=await te(g,i,d,u,t.chat);n=-1,t.messages.length===0&&(t.messages=U(g),(c=(f=i.callbacks).onNewMessage)==null||c.call(f,t.messages)),l!=null&&l.id&&l.id!==((w=t.chat)==null?void 0:w.id)&&((_=(C=i.callbacks).onNewChat)==null||_.call(C,l==null?void 0:l.id)),t.streamingManager=m,t.socketManager=s,t.chat=l,S(A.Functional),u.track("agent-chat",{event:"connect",chatId:l.id,agentId:g.id})}async function E(){var s,m,l,f,c;(s=t.socketManager)==null||s.disconnect(),await((m=t.streamingManager)==null?void 0:m.disconnect()),delete t.streamingManager,delete t.socketManager,t.messages=U(g),(f=(l=i.callbacks).onNewMessage)==null||f.call(l,t.messages),u.track("agent-chat",{event:"disconnect",chatId:(c=t.chat)==null?void 0:c.id,agentId:g.id})}async function S(s){var m,l;s!==t.chatMode&&(u.track("agent-mode-change",{mode:s}),t.chatMode=s,t.chatMode!==A.Functional&&await E(),(l=(m=i.callbacks).onModeChange)==null||l.call(m,s))}return{agent:g,starterMessages:((I=g.knowledge)==null?void 0:I.starter_message)||[],connect:v,disconnect:E,changeMode:S,async reconnect(){var f,c;if(!t.chat)return v();(f=t.socketManager)==null||f.disconnect(),await((c=t.streamingManager)==null?void 0:c.disconnect());const s=await Z(i.auth,r,y),{streamingManager:m,chat:l}=await te(g,i,d,u,t.chat);t.streamingManager=m,t.socketManager=s,S(A.Functional),u.track("agent-chat",{event:"reconnect",chatId:l.id,agentId:g.id})},async chat(s,m=!1){var f,c,w,C,_,x;const l=O();try{const k=Date.now();if(s.length>=800)throw new Error("Message cannot be more than 800 characters");if(s.length===0)throw new Error("Message cannot be empty");if(t.chatMode===A.Maintenance)throw new Error("Chat is in maintenance mode");if(![A.TextOnly,A.Playground].includes(t.chatMode)){if(!t.streamingManager)throw new Error("Streaming manager is not initialized");if(!t.chat)throw new Error("Chat is not initialized")}t.messages.push({id:O(),role:"user",content:s,created_at:new Date(k).toISOString()}),(c=(f=i.callbacks).onNewMessage)==null||c.call(f,t.messages),t.chat||(t.chat=await d.newChat(g.id));const K={id:l,role:"assistant",content:"",created_at:new Date().toISOString(),matches:[]};t.messages.push(K);const L=await d.chat(g.id,t.chat.id,{sessionId:(w=t.streamingManager)==null?void 0:w.sessionId,streamId:(C=t.streamingManager)==null?void 0:C.streamId,messages:t.messages.slice(0,-1),chatMode:t.chatMode,append_chat:m});return u.track("agent-message-send",{event:"success",messages:t.messages.length+1}),K.context=L.context,L.result&&(K.content=L.result,K.matches=L.matches,u.track("agent-message-received",{latency:Date.now()-k,messages:t.messages.length}),(x=(_=i.callbacks).onNewMessage)==null||x.call(_,t.messages)),L}catch(k){throw t.messages[t.messages.length-1].id===l&&t.messages.pop(),u.track("agent-message-send",{event:"error",messages:t.messages.length}),k}},rate(s,m,l){var w,C,_,x;const f=t.messages.find(k=>k.id===s);if(t.chat){if(!f)throw new Error("Message not found")}else throw new Error("Chat is not initialized");const c=((w=f.matches)==null?void 0:w.map(k=>[k.document_id,k.id]))??[];return u.track("agent-rate",{event:l?"update":"create",thumb:m===1?"up":"down",knowledge_id:((C=g.knowledge)==null?void 0:C.id)??"",matches:c,score:m}),l?d.updateRating(g.id,t.chat.id,l,{knowledge_id:((_=g.knowledge)==null?void 0:_.id)??"",message_id:s,matches:c,score:m}):d.createRating(g.id,t.chat.id,{knowledge_id:((x=g.knowledge)==null?void 0:x.id)??"",message_id:s,matches:c,score:m})},deleteRate(s){var m;if(!t.chat)throw new Error("Chat is not initialized");return u.track("agent-rate-delete",{type:"text",chat_id:(m=t.chat)==null?void 0:m.id,id:s}),d.deleteRating(g.id,t.chat.id,s)},speak(s){if(!t.streamingManager)throw new Error("Streaming manager is not initialized");function m(){if(g.presenter){if(s.type==="text")return{type:"text",provider:s.provider?s.provider:g.presenter.voice,input:s.input,ssml:s.ssml||!1};if(s.type==="audio")return{type:"audio",audio_url:s.audio_url}}else throw new Error("Presenter is not initialized");throw new Error("Invalid payload")}const l=m();return u.track("agent-speak",l),t.streamingManager.speak({script:l})}}}h.ChatMode=A,h.ChatProgress=P,h.ConnectionState=M,h.DocumentType=H,h.KnowledgeType=j,h.PlanGroup=B,h.Providers=J,h.RateState=V,h.StreamEvents=$,h.StreamingState=N,h.Subject=W,h.UserPlan=T,h.VideoType=p,h.VoiceAccess=q,h.createAgentManager=ve,h.getAgent=ye,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -24,6 +24,7 @@ export interface Message {
|
|
|
24
24
|
content: string;
|
|
25
25
|
created_at?: string;
|
|
26
26
|
matches?: ChatResponse['matches'];
|
|
27
|
+
context?: string;
|
|
27
28
|
}
|
|
28
29
|
export interface ChatPayload {
|
|
29
30
|
messages: Message[];
|
|
@@ -51,6 +52,7 @@ export interface ChatResponse {
|
|
|
51
52
|
documentIds?: string[];
|
|
52
53
|
matches?: IRetrivalMetadata[];
|
|
53
54
|
chatMode?: ChatMode;
|
|
55
|
+
context?: string;
|
|
54
56
|
}
|
|
55
57
|
export interface Chat {
|
|
56
58
|
id: string;
|
|
@@ -41,7 +41,7 @@ interface ManagerCallbacks {
|
|
|
41
41
|
* Optional callback function that will be triggered each time video events happen
|
|
42
42
|
* @param state
|
|
43
43
|
*/
|
|
44
|
-
onVideoStateChange?(state: StreamingState
|
|
44
|
+
onVideoStateChange?(state: StreamingState): void;
|
|
45
45
|
/**
|
|
46
46
|
* Callback function that will be triggered each time the video stream starts or stops to update html element on webpage
|
|
47
47
|
* Required callback for SDK
|
|
@@ -80,6 +80,12 @@ export interface AgentManagerOptions {
|
|
|
80
80
|
*/
|
|
81
81
|
distinctId?: string;
|
|
82
82
|
mode?: ChatMode;
|
|
83
|
+
/**
|
|
84
|
+
* Desired stream resolution for the session
|
|
85
|
+
* @minimum 0
|
|
86
|
+
* @maximum 1080
|
|
87
|
+
*/
|
|
88
|
+
outputResolution?: number;
|
|
83
89
|
}
|
|
84
90
|
export interface AgentManager {
|
|
85
91
|
/**
|
|
@@ -31,7 +31,7 @@ export declare enum ConnectionState {
|
|
|
31
31
|
export interface ManagerCallbacks {
|
|
32
32
|
onMessage?: (event: string, data: string) => void;
|
|
33
33
|
onConnectionStateChange?: (state: ConnectionState) => void;
|
|
34
|
-
onVideoStateChange?: (state: StreamingState
|
|
34
|
+
onVideoStateChange?: (state: StreamingState) => void;
|
|
35
35
|
onSrcObjectReady?: (value: MediaStream) => void;
|
|
36
36
|
}
|
|
37
37
|
export type ManagerCallbackKeys = keyof ManagerCallbacks;
|
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.19-beta.
|
|
4
|
+
"version": "1.0.19-beta.89",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "d-id client sdk",
|
|
7
7
|
"repository": {
|
|
@@ -44,4 +44,4 @@
|
|
|
44
44
|
"vite": "^5.1.4",
|
|
45
45
|
"vite-plugin-dts": "^3.7.3"
|
|
46
46
|
}
|
|
47
|
-
}
|
|
47
|
+
}
|