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