@d-id/client-sdk 1.0.19-beta.8 → 1.0.19-beta.80

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