@d-id/client-sdk 1.0.19-beta.88 → 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 +292 -321
- 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
|
|
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,387 +31,353 @@ function z(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 =
|
|
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 ae = (e) => new Promise((
|
|
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
|
-
onOpen:
|
|
107
|
+
onOpen: d = null,
|
|
108
108
|
onClose: g = null,
|
|
109
109
|
onError: u = null
|
|
110
|
-
} = n || {},
|
|
111
|
-
|
|
110
|
+
} = n || {}, f = new WebSocket(`${r}?authorization=${H(i)}`);
|
|
111
|
+
f.onmessage = o, f.onclose = g, f.onerror = (p) => {
|
|
112
112
|
console.error(p), u == null || u("Websocket failed to connect", p), t(p);
|
|
113
|
-
},
|
|
114
|
-
|
|
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
|
|
125
|
+
t = await ie(e);
|
|
126
|
+
} catch (r) {
|
|
127
|
+
if (n === a)
|
|
128
|
+
throw r;
|
|
129
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) => {
|
|
140
140
|
const o = JSON.parse(i.data);
|
|
141
|
-
n.forEach((
|
|
141
|
+
n.forEach((d) => d(o.event, o));
|
|
142
142
|
}
|
|
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 =
|
|
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:
|
|
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
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
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
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
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
187
|
type: y.Clip
|
|
188
188
|
});
|
|
189
189
|
}
|
|
190
190
|
};
|
|
191
191
|
}
|
|
192
|
-
function
|
|
193
|
-
const n =
|
|
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
|
-
|
|
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
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
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
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
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
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 B = !1;
|
|
270
|
-
const $ = (e, r) => B && console.log(e, r), de = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
|
|
271
|
-
function ge(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
|
-
return
|
|
241
|
+
return M.Connected;
|
|
275
242
|
case "checking":
|
|
276
|
-
return
|
|
243
|
+
return M.Connecting;
|
|
277
244
|
case "failed":
|
|
278
|
-
return
|
|
245
|
+
return M.Fail;
|
|
279
246
|
case "new":
|
|
280
247
|
case "closed":
|
|
281
248
|
case "disconnected":
|
|
282
249
|
default:
|
|
283
|
-
return
|
|
250
|
+
return M.New;
|
|
284
251
|
}
|
|
285
252
|
}
|
|
286
|
-
function
|
|
287
|
-
let
|
|
288
|
-
return
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
if (c)
|
|
297
|
-
a = n.length, r == null || r(N.Start, _);
|
|
298
|
-
else {
|
|
299
|
-
const E = n.slice(a), M = a === 0 ? void 0 : n[a - 1];
|
|
300
|
-
_ = ce(E, M), _ = _.sort((s, m) => m.packetsLost - s.packetsLost).slice(0, 5);
|
|
301
|
-
}
|
|
302
|
-
!c && o === 1 && t.track("agent-video", {
|
|
303
|
-
event: "stats",
|
|
304
|
-
rtc: _
|
|
305
|
-
}), !c && o === 2 && (r == null || r(N.Stop, _));
|
|
306
|
-
}
|
|
307
|
-
n.push(h);
|
|
308
|
-
}
|
|
309
|
-
});
|
|
310
|
-
});
|
|
311
|
-
}, 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
|
+
};
|
|
312
263
|
}
|
|
313
|
-
|
|
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);
|
|
272
|
+
}
|
|
273
|
+
async function ue(e, a, {
|
|
314
274
|
debug: t = !1,
|
|
315
275
|
callbacks: n,
|
|
316
|
-
auth:
|
|
276
|
+
auth: r,
|
|
317
277
|
analytics: i,
|
|
318
|
-
baseURL: o =
|
|
278
|
+
baseURL: o = N
|
|
319
279
|
}) {
|
|
320
|
-
|
|
321
|
-
let
|
|
280
|
+
V = t;
|
|
281
|
+
let d;
|
|
322
282
|
const {
|
|
323
283
|
startConnection: g,
|
|
324
284
|
sendStreamRequest: u,
|
|
325
|
-
close:
|
|
285
|
+
close: f,
|
|
326
286
|
createStream: p,
|
|
327
|
-
addIceCandidate:
|
|
328
|
-
} =
|
|
329
|
-
id:
|
|
330
|
-
offer:
|
|
331
|
-
ice_servers:
|
|
332
|
-
session_id:
|
|
333
|
-
} = await p(
|
|
334
|
-
iceServers:
|
|
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
|
|
335
295
|
}), m = s.createDataChannel("JanusDataChannel");
|
|
336
|
-
if (!
|
|
296
|
+
if (!S)
|
|
337
297
|
throw new Error("Could not create session_id");
|
|
338
|
-
const l = le(s, n.onVideoStateChange
|
|
339
|
-
s.onicecandidate = (
|
|
340
|
-
|
|
341
|
-
candidate:
|
|
342
|
-
sdpMid:
|
|
343
|
-
sdpMLineIndex:
|
|
344
|
-
},
|
|
298
|
+
const l = le(s, n.onVideoStateChange);
|
|
299
|
+
s.onicecandidate = (c) => {
|
|
300
|
+
k("peerConnection.onicecandidate", c), c.candidate && c.candidate.sdpMid && c.candidate.sdpMLineIndex !== null ? $(_, {
|
|
301
|
+
candidate: c.candidate.candidate,
|
|
302
|
+
sdpMid: c.candidate.sdpMid,
|
|
303
|
+
sdpMLineIndex: c.candidate.sdpMLineIndex
|
|
304
|
+
}, S) : $(_, {
|
|
345
305
|
candidate: null
|
|
346
|
-
},
|
|
306
|
+
}, S);
|
|
347
307
|
}, s.oniceconnectionstatechange = () => {
|
|
348
308
|
var w;
|
|
349
|
-
|
|
350
|
-
const
|
|
351
|
-
|
|
309
|
+
k("peerConnection.oniceconnectionstatechange => " + s.iceConnectionState);
|
|
310
|
+
const c = U(s.iceConnectionState);
|
|
311
|
+
c === M.Connected ? d = setTimeout(() => {
|
|
352
312
|
var v;
|
|
353
|
-
(v = n.onConnectionStateChange) == null || v.call(n,
|
|
354
|
-
}, 5e3) : (clearTimeout(
|
|
355
|
-
}, s.ontrack = (
|
|
313
|
+
(v = n.onConnectionStateChange) == null || v.call(n, M.Connected);
|
|
314
|
+
}, 5e3) : (clearTimeout(d), (w = n.onConnectionStateChange) == null || w.call(n, c));
|
|
315
|
+
}, s.ontrack = (c) => {
|
|
356
316
|
var w;
|
|
357
|
-
|
|
358
|
-
}, m.onmessage = (
|
|
317
|
+
k("peerConnection.ontrack", c), (w = n.onSrcObjectReady) == null || w.call(n, c.streams[0]);
|
|
318
|
+
}, m.onmessage = (c) => {
|
|
359
319
|
var w;
|
|
360
320
|
if (m.readyState === "open") {
|
|
361
|
-
const [v,
|
|
362
|
-
v ===
|
|
321
|
+
const [v, C] = c.data.split(":");
|
|
322
|
+
v === A.StreamReady && (clearTimeout(d), (w = n.onConnectionStateChange) == null || w.call(n, M.Connected));
|
|
363
323
|
}
|
|
364
|
-
}, await s.setRemoteDescription(
|
|
365
|
-
const
|
|
366
|
-
return
|
|
324
|
+
}, await s.setRemoteDescription(L), k("set remote description OK");
|
|
325
|
+
const h = await s.createAnswer();
|
|
326
|
+
return k("create answer OK"), await s.setLocalDescription(h), k("set local description OK"), await g(_, h, S), k("start connection OK"), {
|
|
367
327
|
/**
|
|
368
328
|
* Method to send request to server to get clip or talk depend on you payload
|
|
369
329
|
* @param payload
|
|
370
330
|
*/
|
|
371
|
-
speak(
|
|
372
|
-
return u(
|
|
331
|
+
speak(c) {
|
|
332
|
+
return u(_, S, c);
|
|
373
333
|
},
|
|
374
334
|
/**
|
|
375
335
|
* Method to close RTC connection
|
|
376
336
|
*/
|
|
377
337
|
async disconnect() {
|
|
378
|
-
var
|
|
379
|
-
if (
|
|
380
|
-
|
|
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
|
+
}
|
|
381
347
|
try {
|
|
382
|
-
await
|
|
348
|
+
await f(_, S).catch((C) => {
|
|
383
349
|
});
|
|
384
|
-
} catch (
|
|
385
|
-
|
|
350
|
+
} catch (C) {
|
|
351
|
+
k("Error on close stream connection", C);
|
|
386
352
|
}
|
|
387
|
-
(
|
|
353
|
+
(w = n.onConnectionStateChange) == null || w.call(n, M.New), (v = n.onVideoStateChange) == null || v.call(n, T.Stop), clearInterval(l);
|
|
388
354
|
}
|
|
389
355
|
},
|
|
390
356
|
/**
|
|
391
357
|
* Session identifier information, should be returned in the body of all streaming requests
|
|
392
358
|
*/
|
|
393
|
-
sessionId:
|
|
359
|
+
sessionId: S,
|
|
394
360
|
/**
|
|
395
361
|
* Id of current RTC stream
|
|
396
362
|
*/
|
|
397
|
-
streamId:
|
|
363
|
+
streamId: _
|
|
398
364
|
};
|
|
399
365
|
}
|
|
400
|
-
function
|
|
401
|
-
const
|
|
366
|
+
function me(e) {
|
|
367
|
+
const a = {
|
|
402
368
|
token: e.token || "testKey",
|
|
403
|
-
distinct_id: e.distinctId ||
|
|
369
|
+
distinct_id: e.distinctId || W(),
|
|
404
370
|
isEnabled: e.isEnabled ?? !0,
|
|
405
371
|
agentId: e.agent.id,
|
|
406
372
|
owner_id: e.agent.owner_id ?? ""
|
|
407
373
|
};
|
|
408
374
|
return {
|
|
409
|
-
...
|
|
375
|
+
...a,
|
|
410
376
|
getRandom: () => Math.random().toString(16).slice(2),
|
|
411
377
|
track(t, n) {
|
|
412
378
|
if (!this.isEnabled)
|
|
413
379
|
return Promise.reject("MixPanel analytics is disabled on creation");
|
|
414
|
-
const
|
|
380
|
+
const r = {
|
|
415
381
|
method: "POST",
|
|
416
382
|
headers: {
|
|
417
383
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
@@ -421,7 +387,7 @@ function ue(e) {
|
|
|
421
387
|
event: t,
|
|
422
388
|
properties: {
|
|
423
389
|
...n,
|
|
424
|
-
...
|
|
390
|
+
...a,
|
|
425
391
|
time: Date.now(),
|
|
426
392
|
$insert_id: this.getRandom(),
|
|
427
393
|
origin: window.location.href,
|
|
@@ -432,29 +398,30 @@ function ue(e) {
|
|
|
432
398
|
}])
|
|
433
399
|
})
|
|
434
400
|
};
|
|
435
|
-
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));
|
|
436
402
|
}
|
|
437
403
|
};
|
|
438
404
|
}
|
|
439
405
|
function we(e) {
|
|
440
|
-
var n,
|
|
441
|
-
const
|
|
406
|
+
var n, r, i, o, d;
|
|
407
|
+
const a = () => /Mobi|Android/i.test(navigator.userAgent) ? "Mobile" : "Desktop";
|
|
442
408
|
return {
|
|
443
409
|
$os: `${(() => {
|
|
444
410
|
const g = navigator.platform;
|
|
445
411
|
return g.toLowerCase().includes("win") ? "Windows" : g.toLowerCase().includes("mac") ? "Mac OS X" : g.toLowerCase().includes("linux") ? "Linux" : "Unknown";
|
|
446
412
|
})()}`,
|
|
447
|
-
isMobile: `${
|
|
413
|
+
isMobile: `${a() == "Mobile"}`,
|
|
448
414
|
browser: navigator.userAgent,
|
|
449
415
|
origin: window.location.origin,
|
|
450
416
|
agentType: (n = e.presenter) == null ? void 0 : n.type,
|
|
451
417
|
agentVoice: {
|
|
452
|
-
voiceId: (i = (
|
|
453
|
-
provider: (
|
|
418
|
+
voiceId: (i = (r = e.presenter) == null ? void 0 : r.voice) == null ? void 0 : i.voice_id,
|
|
419
|
+
provider: (d = (o = e.presenter) == null ? void 0 : o.voice) == null ? void 0 : d.type
|
|
454
420
|
}
|
|
455
421
|
};
|
|
456
422
|
}
|
|
457
|
-
|
|
423
|
+
const he = 1080;
|
|
424
|
+
function fe(e, a) {
|
|
458
425
|
if (e.presenter) {
|
|
459
426
|
if (e.presenter.type === y.Clip)
|
|
460
427
|
return {
|
|
@@ -465,180 +432,184 @@ function he(e) {
|
|
|
465
432
|
};
|
|
466
433
|
} else
|
|
467
434
|
throw new Error("Presenter is not initialized");
|
|
435
|
+
const t = a || (e.presenter.stitch ? he : void 0);
|
|
468
436
|
return {
|
|
469
437
|
videoType: y.Talk,
|
|
470
438
|
source_url: e.presenter.source_url,
|
|
471
|
-
stream_warmup: !0
|
|
439
|
+
stream_warmup: !0,
|
|
440
|
+
...t && {
|
|
441
|
+
output_resolution: t
|
|
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
|
|
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
|
-
...
|
|
452
|
+
...a.callbacks,
|
|
482
453
|
onConnectionStateChange: async (u) => {
|
|
483
|
-
var
|
|
484
|
-
if (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",
|
|
488
|
-
chat_id:
|
|
459
|
+
chat_id: d.id,
|
|
489
460
|
agent_id: e.id
|
|
490
461
|
})), g && i({
|
|
491
|
-
chat:
|
|
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
|
-
u ===
|
|
499
|
-
(p = (
|
|
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(u
|
|
502
|
-
var
|
|
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 u =
|
|
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
|
|
515
|
+
const f = {
|
|
545
516
|
onMessage: (s, m) => {
|
|
546
|
-
var l,
|
|
517
|
+
var l, h;
|
|
547
518
|
if ("content" in m) {
|
|
548
519
|
const {
|
|
549
|
-
content:
|
|
520
|
+
content: c
|
|
550
521
|
} = m, w = t.messages[t.messages.length - 1];
|
|
551
|
-
(w == null ? void 0 : w.role) === "assistant" && (n < t.messages.length && (w.content = s ===
|
|
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
|
-
}), (
|
|
554
|
-
} else if ([
|
|
555
|
-
const
|
|
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)) {
|
|
526
|
+
const c = s.split("/")[1];
|
|
556
527
|
u.track("agent-video", {
|
|
557
528
|
...m,
|
|
558
|
-
event:
|
|
529
|
+
event: c
|
|
559
530
|
});
|
|
560
531
|
}
|
|
561
532
|
}
|
|
562
533
|
};
|
|
563
534
|
async function p() {
|
|
564
|
-
var
|
|
565
|
-
const s = await
|
|
535
|
+
var h, c, w, v, C;
|
|
536
|
+
const s = await K(a.auth, r, f), {
|
|
566
537
|
streamingManager: m,
|
|
567
538
|
chat: l
|
|
568
|
-
} = await
|
|
569
|
-
n = -1, t.messages.length === 0 && (t.messages =
|
|
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
542
|
chatId: l.id,
|
|
572
543
|
agentId: g.id
|
|
573
544
|
});
|
|
574
545
|
}
|
|
575
|
-
async function
|
|
576
|
-
var s, m, l,
|
|
577
|
-
(s = t.socketManager) == null || s.disconnect(), await ((m = t.streamingManager) == null ? void 0 : m.disconnect()), delete t.streamingManager, delete t.socketManager, t.messages =
|
|
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
|
-
chatId: (
|
|
550
|
+
chatId: (c = t.chat) == null ? void 0 : c.id,
|
|
580
551
|
agentId: g.id
|
|
581
552
|
});
|
|
582
553
|
}
|
|
583
|
-
async function
|
|
554
|
+
async function _(s) {
|
|
584
555
|
var m, l;
|
|
585
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: ((
|
|
562
|
+
starterMessages: ((S = g.knowledge) == null ? void 0 : S.starter_message) || [],
|
|
592
563
|
connect: p,
|
|
593
|
-
disconnect:
|
|
594
|
-
changeMode:
|
|
564
|
+
disconnect: $,
|
|
565
|
+
changeMode: _,
|
|
595
566
|
async reconnect() {
|
|
596
|
-
var
|
|
567
|
+
var h, c;
|
|
597
568
|
if (!t.chat)
|
|
598
569
|
return p();
|
|
599
|
-
(
|
|
600
|
-
const s = await
|
|
570
|
+
(h = t.socketManager) == null || h.disconnect(), await ((c = t.streamingManager) == null ? void 0 : c.disconnect());
|
|
571
|
+
const s = await K(a.auth, r, f), {
|
|
601
572
|
streamingManager: m,
|
|
602
573
|
chat: l
|
|
603
|
-
} = await
|
|
604
|
-
t.streamingManager = m, t.socketManager = s,
|
|
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
577
|
chatId: l.id,
|
|
607
578
|
agentId: g.id
|
|
608
579
|
});
|
|
609
580
|
},
|
|
610
581
|
async chat(s, m = !1) {
|
|
611
|
-
var
|
|
612
|
-
const l =
|
|
582
|
+
var h, c, w, v, C, E;
|
|
583
|
+
const l = z();
|
|
613
584
|
try {
|
|
614
585
|
const I = Date.now();
|
|
615
586
|
if (s.length >= 800)
|
|
616
587
|
throw new Error("Message cannot be more than 800 characters");
|
|
617
588
|
if (s.length === 0)
|
|
618
589
|
throw new Error("Message cannot be empty");
|
|
619
|
-
if (t.chatMode ===
|
|
590
|
+
if (t.chatMode === R.Maintenance)
|
|
620
591
|
throw new Error("Chat is in maintenance mode");
|
|
621
|
-
if (![
|
|
592
|
+
if (![R.TextOnly, R.Playground].includes(t.chatMode)) {
|
|
622
593
|
if (!t.streamingManager)
|
|
623
594
|
throw new Error("Streaming manager is not initialized");
|
|
624
595
|
if (!t.chat)
|
|
625
596
|
throw new Error("Chat is not initialized");
|
|
626
597
|
}
|
|
627
598
|
t.messages.push({
|
|
628
|
-
id:
|
|
599
|
+
id: z(),
|
|
629
600
|
role: "user",
|
|
630
601
|
content: s,
|
|
631
602
|
created_at: new Date(I).toISOString()
|
|
632
|
-
}), (
|
|
633
|
-
const
|
|
603
|
+
}), (c = (h = a.callbacks).onNewMessage) == null || c.call(h, t.messages), t.chat || (t.chat = await d.newChat(g.id));
|
|
604
|
+
const P = {
|
|
634
605
|
id: l,
|
|
635
606
|
role: "assistant",
|
|
636
607
|
content: "",
|
|
637
608
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
638
609
|
matches: []
|
|
639
610
|
};
|
|
640
|
-
t.messages.push(
|
|
641
|
-
const
|
|
611
|
+
t.messages.push(P);
|
|
612
|
+
const x = await d.chat(g.id, t.chat.id, {
|
|
642
613
|
sessionId: (w = t.streamingManager) == null ? void 0 : w.sessionId,
|
|
643
614
|
streamId: (v = t.streamingManager) == null ? void 0 : v.streamId,
|
|
644
615
|
messages: t.messages.slice(0, -1),
|
|
@@ -648,10 +619,10 @@ async function pe(e, r) {
|
|
|
648
619
|
return u.track("agent-message-send", {
|
|
649
620
|
event: "success",
|
|
650
621
|
messages: t.messages.length + 1
|
|
651
|
-
}), P.result && (
|
|
622
|
+
}), P.context = x.context, x.result && (P.content = x.result, P.matches = x.matches, u.track("agent-message-received", {
|
|
652
623
|
latency: Date.now() - I,
|
|
653
624
|
messages: t.messages.length
|
|
654
|
-
}), (
|
|
625
|
+
}), (E = (C = a.callbacks).onNewMessage) == null || E.call(C, t.messages)), x;
|
|
655
626
|
} catch (I) {
|
|
656
627
|
throw t.messages[t.messages.length - 1].id === l && t.messages.pop(), u.track("agent-message-send", {
|
|
657
628
|
event: "error",
|
|
@@ -660,29 +631,29 @@ async function pe(e, r) {
|
|
|
660
631
|
}
|
|
661
632
|
},
|
|
662
633
|
rate(s, m, l) {
|
|
663
|
-
var w, v,
|
|
664
|
-
const
|
|
634
|
+
var w, v, C, E;
|
|
635
|
+
const h = t.messages.find((I) => I.id === s);
|
|
665
636
|
if (t.chat) {
|
|
666
|
-
if (!
|
|
637
|
+
if (!h)
|
|
667
638
|
throw new Error("Message not found");
|
|
668
639
|
} else
|
|
669
640
|
throw new Error("Chat is not initialized");
|
|
670
|
-
const
|
|
641
|
+
const c = ((w = h.matches) == null ? void 0 : w.map((I) => [I.document_id, I.id])) ?? [];
|
|
671
642
|
return u.track("agent-rate", {
|
|
672
643
|
event: l ? "update" : "create",
|
|
673
644
|
thumb: m === 1 ? "up" : "down",
|
|
674
645
|
knowledge_id: ((v = g.knowledge) == null ? void 0 : v.id) ?? "",
|
|
675
|
-
matches:
|
|
646
|
+
matches: c,
|
|
676
647
|
score: m
|
|
677
|
-
}), l ?
|
|
678
|
-
knowledge_id: ((
|
|
648
|
+
}), l ? d.updateRating(g.id, t.chat.id, l, {
|
|
649
|
+
knowledge_id: ((C = g.knowledge) == null ? void 0 : C.id) ?? "",
|
|
679
650
|
message_id: s,
|
|
680
|
-
matches:
|
|
651
|
+
matches: c,
|
|
681
652
|
score: m
|
|
682
|
-
}) :
|
|
683
|
-
knowledge_id: ((
|
|
653
|
+
}) : d.createRating(g.id, t.chat.id, {
|
|
654
|
+
knowledge_id: ((E = g.knowledge) == null ? void 0 : E.id) ?? "",
|
|
684
655
|
message_id: s,
|
|
685
|
-
matches:
|
|
656
|
+
matches: c,
|
|
686
657
|
score: m
|
|
687
658
|
});
|
|
688
659
|
},
|
|
@@ -694,7 +665,7 @@ async function pe(e, r) {
|
|
|
694
665
|
type: "text",
|
|
695
666
|
chat_id: (m = t.chat) == null ? void 0 : m.id,
|
|
696
667
|
id: s
|
|
697
|
-
}),
|
|
668
|
+
}), d.deleteRating(g.id, t.chat.id, s);
|
|
698
669
|
},
|
|
699
670
|
speak(s) {
|
|
700
671
|
if (!t.streamingManager)
|
|
@@ -725,20 +696,20 @@ async function pe(e, r) {
|
|
|
725
696
|
};
|
|
726
697
|
}
|
|
727
698
|
export {
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
699
|
+
R as ChatMode,
|
|
700
|
+
b as ChatProgress,
|
|
701
|
+
M as ConnectionState,
|
|
702
|
+
Z as DocumentType,
|
|
703
|
+
Y as KnowledgeType,
|
|
733
704
|
q as PlanGroup,
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
705
|
+
G as Providers,
|
|
706
|
+
Q as RateState,
|
|
707
|
+
A as StreamEvents,
|
|
708
|
+
T as StreamingState,
|
|
709
|
+
X as Subject,
|
|
710
|
+
j as UserPlan,
|
|
740
711
|
y as VideoType,
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
712
|
+
ee as VoiceAccess,
|
|
713
|
+
ve as createAgentManager,
|
|
714
|
+
pe as getAgent
|
|
744
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||{}),H=(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))(H||{}),x=(e=>(e.Unrated="Unrated",e.Positive="Positive",e.Negative="Negative",e))(x||{}),I=(e=>(e.Functional="Functional",e.TextOnly="TextOnly",e.Maintenance="Maintenance",e.Playground="Playground",e))(I||{}),L=(e=>(e.Embed="embed",e.Query="query",e.Partial="partial",e.Answer="answer",e.Complete="done",e))(L||{}),U=(e=>(e.KnowledgeProcessing="knowledge/processing",e.KnowledgeIndexing="knowledge/indexing",e.KnowledgeFailed="knowledge/error",e.KnowledgeDone="knowledge/done",e))(U||{}),B=(e=>(e.Knowledge="knowledge",e.Document="document",e.Record="record",e))(B||{}),J=(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))(J||{}),y=(e=>(e.Clip="clip",e.Talk="talk",e))(y||{}),N=(e=>(e.Start="START",e.Stop="STOP",e))(N||{}),b=(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))(b||{}),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||{}),V=(e=>(e.Amazon="amazon",e.Microsoft="microsoft",e.Afflorithmics="afflorithmics",e.Elevenlabs="elevenlabs",e))(V||{}),q=(e=>(e.Public="public",e.Premium="premium",e.Private="private",e))(q||{});const O="https://api.d-id.com",te="wss://notifications.d-id.com",ne="79f81a83a67430be2bc0fd61042b8faa",K=()=>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 ae=K();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()}_${ae}`;throw new Error(`Unknown auth type: ${e}`)}function j(e,i=O){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:X(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 Y(e,i=O){const t=j(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,c){return t.patch(`/${n}/chat/${a}/ratings/${r}`,o,c)},deleteRating(n,a,r,o){return t.delete(`/${n}/chat/${a}/ratings/${r}`,o)}}}const ie=e=>new Promise(i=>setTimeout(i,e));function re(e){return new Promise((i,t)=>{const{callbacks:n,host:a,auth:r}=e,{onMessage:o=null,onOpen:c=null,onClose:g=null,onError:u=null}=n||{},f=new WebSocket(`${a}?authorization=${X(r)}`);f.onmessage=o,f.onclose=g,f.onerror=v=>{console.error(v),u==null||u("Websocket failed to connect",v),t(v)},f.onopen=v=>{c==null||c(v),i(f)}})}async function se(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 re(e)}catch(a){if(n===i)throw a;await ie(n*500)}return t}async function Z(e,i,t){const n=t!=null&&t.onMessage?[t.onMessage]:[],a=await se({auth:e,host:i,callbacks:{onError:t==null?void 0:t.onError,onMessage:r=>{const o=JSON.parse(r.data);n.forEach(c=>c(o.event,o))}}});return{socket:a,disconnect:()=>a.close(),subscribeToEvents:r=>n.push(r)}}function oe(e,i,t){const n=j(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:y.Clip})},startConnection(a,r,o){return n.post(`/streams/${a}/sdp`,{session_id:o,answer:r,type:y.Clip})},addIceCandidate(a,r,o){return n.post(`/streams/${a}/ice`,{session_id:o,...r,type:y.Clip})},sendStreamRequest(a,r,o){return n.post(`/streams/${a}`,{session_id:r,...o,type:y.Clip})},close(a,r){return n.delete(`/streams/${a}`,{session_id:r,type:y.Clip})}}}function ce(e,i,t){const n=j(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:y.Talk},r)},startConnection(a,r,o,c){return n.post(`/streams/${a}/sdp`,{session_id:o,answer:r,type:y.Talk},c)},addIceCandidate(a,r,o,c){return n.post(`/streams/${a}/ice`,{session_id:o,...r,type:y.Talk},c)},sendStreamRequest(a,r,o,c){return n.post(`/streams/${a}`,{session_id:r,...o,type:y.Talk},c)},close(a,r,o){return n.delete(`/streams/${a}`,{session_id:r,type:y.Talk},o)}}}function de(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 G=!1;const E=(e,i)=>G&&console.log(e,i),ge=(window.RTCPeerConnection||window.webkitRTCPeerConnection||window.mozRTCPeerConnection).bind(window);function le(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 me(e,i,t){let n=[],a=0,r=0,o=0,c;return setInterval(()=>{e.getStats().then(u=>{u.forEach(f=>{if(f.type==="inbound-rtp"&&f.kind==="video"){if(r=n.length-1,f&&n[r]){const v=f.bytesReceived,M=n[r].bytesReceived,S=c;let R;if(c=v-M>0,o=c?0:++o,S!==c)if(c)a=n.length,i==null||i(N.Start,R);else{const P=n.slice(a),_=a===0?void 0:n[a-1];R=de(P,_),R=R.sort((s,m)=>m.packetsLost-s.packetsLost).slice(0,5)}!c&&o===1&&t.track("agent-video",{event:"stats",rtc:R}),!c&&o===2&&(i==null||i(N.Stop,R))}n.push(f)}})})},500)}async function ue(e,i,{debug:t=!1,callbacks:n,auth:a,analytics:r,baseURL:o=O}){G=t;let c;const{startConnection:g,sendStreamRequest:u,close:f,createStream:v,addIceCandidate:M}=i.videoType===y.Clip?oe(a,o,e):ce(a,o,e),{id:S,offer:R,ice_servers:P,session_id:_}=await v(i),s=new ge({iceServers:P}),m=s.createDataChannel("JanusDataChannel");if(!_)throw new Error("Could not create session_id");const l=me(s,n.onVideoStateChange,r);s.onicecandidate=d=>{E("peerConnection.onicecandidate",d),d.candidate&&d.candidate.sdpMid&&d.candidate.sdpMLineIndex!==null?M(S,{candidate:d.candidate.candidate,sdpMid:d.candidate.sdpMid,sdpMLineIndex:d.candidate.sdpMLineIndex},_):M(S,{candidate:null},_)},s.oniceconnectionstatechange=()=>{var h;E("peerConnection.oniceconnectionstatechange => "+s.iceConnectionState);const d=le(s.iceConnectionState);d===k.Connected?c=setTimeout(()=>{var C;(C=n.onConnectionStateChange)==null||C.call(n,k.Connected)},5e3):(clearTimeout(c),(h=n.onConnectionStateChange)==null||h.call(n,d))},s.ontrack=d=>{var h;E("peerConnection.ontrack",d),(h=n.onSrcObjectReady)==null||h.call(n,d.streams[0])},m.onmessage=d=>{var h;if(m.readyState==="open"){const[C,A]=d.data.split(":");C===b.StreamReady&&(clearTimeout(c),(h=n.onConnectionStateChange)==null||h.call(n,k.Connected))}},await s.setRemoteDescription(R),E("set remote description OK");const p=await s.createAnswer();return E("create answer OK"),await s.setLocalDescription(p),E("set local description OK"),await g(S,p,_),E("start connection OK"),{speak(d){return u(S,_,d)},async disconnect(){var d,h;if(S){s&&(s.close(),s.oniceconnectionstatechange=null,s.onnegotiationneeded=null,s.onicecandidate=null,s.ontrack=null);try{await f(S,_).catch(C=>{})}catch(C){E("Error on close stream connection",C)}(d=n.onConnectionStateChange)==null||d.call(n,k.New),(h=n.onVideoStateChange)==null||h.call(n,N.Stop),clearInterval(l)}},sessionId:_,streamId:S}}function he(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 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 we(e){var n,a,r,o,c;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:(c=(o=e.presenter)==null?void 0:o.voice)==null?void 0:c.type}}}function fe(e){if(e.presenter){if(e.presenter.type===y.Clip)return{videoType:y.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:y.Talk,source_url:e.presenter.source_url,stream_warmup:!0}}function ee(e,i,t,n,a){return new Promise(async(r,o)=>{let c=a;const g=await ue(e.id,fe(e),{...i,analytics:n,callbacks:{...i.callbacks,onConnectionStateChange:async u=>{var f,v;if(u===k.Connected)try{c||(c=await t.newChat(e.id),n.track("agent-chat",{event:"created",chat_id:c.id,agent_id:e.id})),g&&r({chat:c,streamingManager:g})}catch(M){console.error(M),o("Cannot create new chat")}else u===k.Fail&&o(new Error("Cannot create connection"));(v=(f=i.callbacks).onConnectionStateChange)==null||v.call(f,u)},onVideoStateChange(u,f){var v,M;(M=(v=i.callbacks).onVideoStateChange)==null||M.call(v,u,f)}}}).catch(o)})}function pe(e,i,t){return Y(i,t||O).getById(e)}function z(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 ve(e,i){var R,P,_;const t={messages:[],chatMode:i.mode||I.Functional};let n=-1;const a=i.wsURL||te,r=i.baseURL||O,o=i.mixpanelKey||ne,c=Y(i.auth,r),g=await c.getById(e);t.messages=z(g),(P=(R=i.callbacks).onNewMessage)==null||P.call(R,t.messages);const u=he({token:o,agent:g,...i});u.track("agent-sdk",{event:"loaded",...we(g)});const f={onMessage:(s,m)=>{var l,p;if("content"in m){const{content:d}=m,h=t.messages[t.messages.length-1];(h==null?void 0:h.role)==="assistant"&&(n<t.messages.length&&(h.content=s===L.Partial?h.content+d:d),s===L.Answer&&(n=t.messages.length)),s===L.Answer&&u.track("agent-message-received",{messages:t.messages.length}),(p=(l=i.callbacks).onNewMessage)==null||p.call(l,t.messages)}else if([b.StreamVideoCreated,b.StreamVideoDone,b.StreamVideoError,b.StreamVideoRejected].includes(s)){const d=s.split("/")[1];u.track("agent-video",{...m,event:d})}}};async function v(){var p,d,h,C,A;const s=await Z(i.auth,a,f),{streamingManager:m,chat:l}=await ee(g,i,c,u,t.chat);n=-1,t.messages.length===0&&(t.messages=z(g),(d=(p=i.callbacks).onNewMessage)==null||d.call(p,t.messages)),l!=null&&l.id&&l.id!==((h=t.chat)==null?void 0:h.id)&&((A=(C=i.callbacks).onNewChat)==null||A.call(C,l==null?void 0:l.id)),t.streamingManager=m,t.socketManager=s,t.chat=l,S(I.Functional),u.track("agent-chat",{event:"connect",chatId:l.id,agentId:g.id})}async function M(){var s,m,l,p,d;(s=t.socketManager)==null||s.disconnect(),await((m=t.streamingManager)==null?void 0:m.disconnect()),delete t.streamingManager,delete t.socketManager,t.messages=z(g),(p=(l=i.callbacks).onNewMessage)==null||p.call(l,t.messages),u.track("agent-chat",{event:"disconnect",chatId:(d=t.chat)==null?void 0:d.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!==I.Functional&&await M(),(l=(m=i.callbacks).onModeChange)==null||l.call(m,s))}return{agent:g,starterMessages:((_=g.knowledge)==null?void 0:_.starter_message)||[],connect:v,disconnect:M,changeMode:S,async reconnect(){var p,d;if(!t.chat)return v();(p=t.socketManager)==null||p.disconnect(),await((d=t.streamingManager)==null?void 0:d.disconnect());const s=await Z(i.auth,a,f),{streamingManager:m,chat:l}=await ee(g,i,c,u,t.chat);t.streamingManager=m,t.socketManager=s,S(I.Functional),u.track("agent-chat",{event:"reconnect",chatId:l.id,agentId:g.id})},async chat(s,m=!1){var p,d,h,C,A,F;const l=K();try{const $=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===I.Maintenance)throw new Error("Chat is in maintenance mode");if(![I.TextOnly,I.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($).toISOString()}),(d=(p=i.callbacks).onNewMessage)==null||d.call(p,t.messages),t.chat||(t.chat=await c.newChat(g.id));const D={id:l,role:"assistant",content:"",created_at:new Date().toISOString(),matches:[]};t.messages.push(D);const W=await c.chat(g.id,t.chat.id,{sessionId:(h=t.streamingManager)==null?void 0:h.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}),W.result&&(D.content=W.result,D.matches=W.matches,u.track("agent-message-received",{latency:Date.now()-$,messages:t.messages.length}),(F=(A=i.callbacks).onNewMessage)==null||F.call(A,t.messages)),W}catch($){throw t.messages[t.messages.length-1].id===l&&t.messages.pop(),u.track("agent-message-send",{event:"error",messages:t.messages.length}),$}},rate(s,m,l){var h,C,A,F;const p=t.messages.find($=>$.id===s);if(t.chat){if(!p)throw new Error("Message not found")}else throw new Error("Chat is not initialized");const d=((h=p.matches)==null?void 0:h.map($=>[$.document_id,$.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:d,score:m}),l?c.updateRating(g.id,t.chat.id,l,{knowledge_id:((A=g.knowledge)==null?void 0:A.id)??"",message_id:s,matches:d,score:m}):c.createRating(g.id,t.chat.id,{knowledge_id:((F=g.knowledge)==null?void 0:F.id)??"",message_id:s,matches:d,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}),c.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})}}}w.ChatMode=I,w.ChatProgress=L,w.ConnectionState=k,w.DocumentType=J,w.KnowledgeType=B,w.PlanGroup=H,w.Providers=V,w.RateState=x,w.StreamEvents=b,w.StreamingState=N,w.Subject=U,w.UserPlan=T,w.VideoType=y,w.VoiceAccess=q,w.createAgentManager=ve,w.getAgent=pe,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
|
+
}
|