@d-id/client-sdk 1.1.29 → 1.1.30-staging.138
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,16 +1,16 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
1
|
+
var Xe = Object.defineProperty;
|
|
2
|
+
var Ye = (e, t, a) => t in e ? Xe(e, t, { enumerable: !0, configurable: !0, writable: !0, value: a }) : e[t] = a;
|
|
3
|
+
var fe = (e, t, a) => Ye(e, typeof t != "symbol" ? t + "" : t, a);
|
|
4
4
|
class we extends Error {
|
|
5
|
-
constructor({ kind: a, description: n, error:
|
|
5
|
+
constructor({ kind: a, description: n, error: s }) {
|
|
6
6
|
super(JSON.stringify({ kind: a, description: n }));
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
this.kind = a, this.description = n, this.error =
|
|
7
|
+
fe(this, "kind");
|
|
8
|
+
fe(this, "description");
|
|
9
|
+
fe(this, "error");
|
|
10
|
+
this.kind = a, this.description = n, this.error = s;
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
class
|
|
13
|
+
class Ge extends we {
|
|
14
14
|
constructor(t, a) {
|
|
15
15
|
super({
|
|
16
16
|
kind: "ChatCreationFailed",
|
|
@@ -18,7 +18,7 @@ class Xe extends we {
|
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
class
|
|
21
|
+
class Ze extends we {
|
|
22
22
|
constructor(t) {
|
|
23
23
|
super({ kind: "ChatModeDowngraded", description: `Chat mode downgraded to ${t}` });
|
|
24
24
|
}
|
|
@@ -26,17 +26,17 @@ class Ye extends we {
|
|
|
26
26
|
class de extends we {
|
|
27
27
|
constructor(a, n) {
|
|
28
28
|
super({ kind: "ValidationError", description: a });
|
|
29
|
-
|
|
29
|
+
fe(this, "key");
|
|
30
30
|
this.key = n;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
class
|
|
33
|
+
class et extends we {
|
|
34
34
|
constructor(t) {
|
|
35
35
|
super({ kind: "WSError", description: t });
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
var
|
|
39
|
-
const
|
|
38
|
+
var tt = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(tt || {}), nt = /* @__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))(nt || {}), rt = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(rt || {}), it = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(it || {}), N = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(N || {}), Y = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(Y || {}), at = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(at || {}), ot = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(ot || {}), st = /* @__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))(st || {}), Je = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(Je || {});
|
|
39
|
+
const gn = (e) => {
|
|
40
40
|
switch (e) {
|
|
41
41
|
case "clip":
|
|
42
42
|
return "clip";
|
|
@@ -48,15 +48,15 @@ const fn = (e) => {
|
|
|
48
48
|
throw new Error(`Unknown video type: ${e}`);
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
|
-
var C = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(C || {}), re = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(re || {}),
|
|
52
|
-
const
|
|
51
|
+
var C = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(C || {}), re = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(re || {}), q = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Loading = "LOADING", e.Talking = "TALKING", e))(q || {}), j = /* @__PURE__ */ ((e) => (e.ChatAnswer = "chat/answer", e.ChatPartial = "chat/partial", e.ChatAudioTranscribed = "chat/audio-transcribed", e.StreamDone = "stream/done", e.StreamStarted = "stream/started", e.StreamFailed = "stream/error", e.StreamReady = "stream/ready", e.StreamCreated = "stream/created", e.StreamInterrupt = "stream/interrupt", e.StreamVideoCreated = "stream-video/started", e.StreamVideoDone = "stream-video/done", e.StreamVideoError = "stream-video/error", e.StreamVideoRejected = "stream-video/rejected", e))(j || {}), S = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnected = "disconnected", e))(S || {}), ae = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(ae || {}), ye = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(ye || {}), ct = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(ct || {}), dt = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(dt || {});
|
|
52
|
+
const ut = 45 * 1e3, lt = "X-Playground-Chat", ge = "https://api.d-id.com", ft = "wss://notifications.d-id.com", mt = "79f81a83a67430be2bc0fd61042b8faa", Ue = (e) => new Promise((t) => setTimeout(t, e)), ue = (e = 16) => {
|
|
53
53
|
const t = new Uint8Array(e);
|
|
54
54
|
return window.crypto.getRandomValues(t), Array.from(t, (a) => a.toString(16).padStart(2, "0")).join("").slice(0, 13);
|
|
55
|
-
},
|
|
56
|
-
function
|
|
55
|
+
}, We = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type, Ie = (e) => e === Je.Expressive, gt = (e) => [N.TextOnly, N.Playground, N.Maintenance].includes(e), Ve = (e) => e && [N.DirectPlayback, N.Off].includes(e);
|
|
56
|
+
function ht(e, t) {
|
|
57
57
|
let a;
|
|
58
58
|
return {
|
|
59
|
-
promise: new Promise((
|
|
59
|
+
promise: new Promise((s, o) => {
|
|
60
60
|
a = setTimeout(() => o(new Error(t)), e);
|
|
61
61
|
}),
|
|
62
62
|
clear: () => clearTimeout(a)
|
|
@@ -73,16 +73,16 @@ async function Ce(e, t) {
|
|
|
73
73
|
})
|
|
74
74
|
};
|
|
75
75
|
let n;
|
|
76
|
-
for (let
|
|
76
|
+
for (let s = 1; s <= a.limit; s++)
|
|
77
77
|
try {
|
|
78
78
|
if (!a.timeout)
|
|
79
79
|
return await e();
|
|
80
|
-
const { promise: o, clear:
|
|
80
|
+
const { promise: o, clear: c } = ht(a.timeout, a.timeoutErrorMessage), i = e().finally(c);
|
|
81
81
|
return await Promise.race([i, o]);
|
|
82
82
|
} catch (o) {
|
|
83
|
-
if (n = o, !a.shouldRetryFn(o) ||
|
|
83
|
+
if (n = o, !a.shouldRetryFn(o) || s >= a.limit)
|
|
84
84
|
throw o;
|
|
85
|
-
await
|
|
85
|
+
await Ue(a.delayMs), a.onRetry(o);
|
|
86
86
|
}
|
|
87
87
|
throw n;
|
|
88
88
|
}
|
|
@@ -96,96 +96,96 @@ function ke(e) {
|
|
|
96
96
|
}
|
|
97
97
|
return t;
|
|
98
98
|
}
|
|
99
|
-
let
|
|
100
|
-
function
|
|
99
|
+
let pt = ue();
|
|
100
|
+
function Oe(e, t) {
|
|
101
101
|
if (e.type === "bearer")
|
|
102
102
|
return `Bearer ${e.token}`;
|
|
103
103
|
if (e.type === "basic")
|
|
104
104
|
return `Basic ${btoa(`${e.username}:${e.password}`)}`;
|
|
105
105
|
if (e.type === "key")
|
|
106
|
-
return `Client-Key ${e.clientKey}.${ke(t)}_${
|
|
106
|
+
return `Client-Key ${e.clientKey}.${ke(t)}_${pt}`;
|
|
107
107
|
throw new Error(`Unknown auth type: ${e}`);
|
|
108
108
|
}
|
|
109
|
-
const
|
|
109
|
+
const wt = (e) => Ce(e, {
|
|
110
110
|
limit: 3,
|
|
111
111
|
delayMs: 1e3,
|
|
112
112
|
timeout: 0,
|
|
113
113
|
shouldRetryFn: (t) => t.status === 429
|
|
114
114
|
});
|
|
115
|
-
function Te(e, t =
|
|
116
|
-
const
|
|
117
|
-
const { skipErrorHandler: i, ...r } =
|
|
115
|
+
function Te(e, t = ge, a, n) {
|
|
116
|
+
const s = async (o, c) => {
|
|
117
|
+
const { skipErrorHandler: i, ...r } = c || {}, d = await wt(
|
|
118
118
|
() => fetch(t + (o != null && o.startsWith("/") ? o : `/${o}`), {
|
|
119
119
|
...r,
|
|
120
120
|
headers: {
|
|
121
121
|
...r.headers,
|
|
122
|
-
Authorization:
|
|
122
|
+
Authorization: Oe(e, n),
|
|
123
123
|
"Content-Type": "application/json"
|
|
124
124
|
}
|
|
125
125
|
})
|
|
126
126
|
);
|
|
127
127
|
if (!d.ok) {
|
|
128
|
-
let
|
|
129
|
-
const
|
|
130
|
-
throw a && !i && a(
|
|
128
|
+
let w = await d.text().catch(() => `Failed to fetch with status ${d.status}`);
|
|
129
|
+
const p = new Error(w);
|
|
130
|
+
throw a && !i && a(p, { url: o, options: r, headers: d.headers }), p;
|
|
131
131
|
}
|
|
132
132
|
return d.json();
|
|
133
133
|
};
|
|
134
134
|
return {
|
|
135
|
-
get(o,
|
|
136
|
-
return
|
|
135
|
+
get(o, c) {
|
|
136
|
+
return s(o, { ...c, method: "GET" });
|
|
137
137
|
},
|
|
138
|
-
post(o,
|
|
139
|
-
return
|
|
138
|
+
post(o, c, i) {
|
|
139
|
+
return s(o, { ...i, body: JSON.stringify(c), method: "POST" });
|
|
140
140
|
},
|
|
141
|
-
delete(o,
|
|
142
|
-
return
|
|
141
|
+
delete(o, c, i) {
|
|
142
|
+
return s(o, { ...i, body: JSON.stringify(c), method: "DELETE" });
|
|
143
143
|
},
|
|
144
|
-
patch(o,
|
|
145
|
-
return
|
|
144
|
+
patch(o, c, i) {
|
|
145
|
+
return s(o, { ...i, body: JSON.stringify(c), method: "PATCH" });
|
|
146
146
|
}
|
|
147
147
|
};
|
|
148
148
|
}
|
|
149
|
-
function
|
|
150
|
-
const
|
|
149
|
+
function yt(e, t = ge, a, n) {
|
|
150
|
+
const s = Te(e, `${t}/agents`, a, n);
|
|
151
151
|
return {
|
|
152
|
-
create(o,
|
|
153
|
-
return
|
|
152
|
+
create(o, c) {
|
|
153
|
+
return s.post("/", o, c);
|
|
154
154
|
},
|
|
155
|
-
getAgents(o,
|
|
156
|
-
return
|
|
155
|
+
getAgents(o, c) {
|
|
156
|
+
return s.get(`/${o ? `?tag=${o}` : ""}`, c).then((i) => i ?? []);
|
|
157
157
|
},
|
|
158
|
-
getById(o,
|
|
159
|
-
return
|
|
158
|
+
getById(o, c) {
|
|
159
|
+
return s.get(`/${o}`, c);
|
|
160
160
|
},
|
|
161
|
-
delete(o,
|
|
162
|
-
return
|
|
161
|
+
delete(o, c) {
|
|
162
|
+
return s.delete(`/${o}`, void 0, c);
|
|
163
163
|
},
|
|
164
|
-
update(o,
|
|
165
|
-
return
|
|
164
|
+
update(o, c, i) {
|
|
165
|
+
return s.patch(`/${o}`, c, i);
|
|
166
166
|
},
|
|
167
|
-
newChat(o,
|
|
168
|
-
return
|
|
167
|
+
newChat(o, c, i) {
|
|
168
|
+
return s.post(`/${o}/chat`, c, i);
|
|
169
169
|
},
|
|
170
|
-
chat(o,
|
|
171
|
-
return
|
|
170
|
+
chat(o, c, i, r) {
|
|
171
|
+
return s.post(`/${o}/chat/${c}`, i, r);
|
|
172
172
|
},
|
|
173
|
-
createRating(o,
|
|
174
|
-
return
|
|
173
|
+
createRating(o, c, i, r) {
|
|
174
|
+
return s.post(`/${o}/chat/${c}/ratings`, i, r);
|
|
175
175
|
},
|
|
176
|
-
updateRating(o,
|
|
177
|
-
return
|
|
176
|
+
updateRating(o, c, i, r, d) {
|
|
177
|
+
return s.patch(`/${o}/chat/${c}/ratings/${i}`, r, d);
|
|
178
178
|
},
|
|
179
|
-
deleteRating(o,
|
|
180
|
-
return
|
|
179
|
+
deleteRating(o, c, i, r) {
|
|
180
|
+
return s.delete(`/${o}/chat/${c}/ratings/${i}`, r);
|
|
181
181
|
},
|
|
182
|
-
getSTTToken(o,
|
|
183
|
-
return
|
|
182
|
+
getSTTToken(o, c) {
|
|
183
|
+
return s.get(`/${o}/stt-token`, c);
|
|
184
184
|
}
|
|
185
185
|
};
|
|
186
186
|
}
|
|
187
|
-
function
|
|
188
|
-
var
|
|
187
|
+
function vt(e) {
|
|
188
|
+
var s, o, c, i;
|
|
189
189
|
const t = () => /Mobi|Android/i.test(navigator.userAgent) ? "Mobile" : "Desktop", a = () => {
|
|
190
190
|
const r = navigator.platform;
|
|
191
191
|
return r.toLowerCase().includes("win") ? "Windows" : r.toLowerCase().includes("mac") ? "Mac OS X" : r.toLowerCase().includes("linux") ? "Linux" : "Unknown";
|
|
@@ -195,28 +195,28 @@ function wt(e) {
|
|
|
195
195
|
isMobile: `${t() == "Mobile"}`,
|
|
196
196
|
browser: navigator.userAgent,
|
|
197
197
|
origin: window.location.origin,
|
|
198
|
-
agentType:
|
|
198
|
+
agentType: We(n),
|
|
199
199
|
agentVoice: {
|
|
200
|
-
voiceId: (o = (
|
|
201
|
-
provider: (i = (
|
|
200
|
+
voiceId: (o = (s = e.presenter) == null ? void 0 : s.voice) == null ? void 0 : o.voice_id,
|
|
201
|
+
provider: (i = (c = e.presenter) == null ? void 0 : c.voice) == null ? void 0 : i.type
|
|
202
202
|
}
|
|
203
203
|
};
|
|
204
204
|
}
|
|
205
|
-
function
|
|
206
|
-
var a, n,
|
|
205
|
+
function St(e) {
|
|
206
|
+
var a, n, s, o, c, i;
|
|
207
207
|
const t = (a = e.llm) == null ? void 0 : a.prompt_customization;
|
|
208
208
|
return {
|
|
209
|
-
agentType:
|
|
209
|
+
agentType: We(e.presenter),
|
|
210
210
|
owner_id: e.owner_id ?? "",
|
|
211
211
|
promptVersion: (n = e.llm) == null ? void 0 : n.prompt_version,
|
|
212
212
|
behavior: {
|
|
213
213
|
role: t == null ? void 0 : t.role,
|
|
214
214
|
personality: t == null ? void 0 : t.personality,
|
|
215
|
-
instructions: (
|
|
215
|
+
instructions: (s = e.llm) == null ? void 0 : s.instructions
|
|
216
216
|
},
|
|
217
217
|
temperature: (o = e.llm) == null ? void 0 : o.temperature,
|
|
218
218
|
knowledgeSource: t == null ? void 0 : t.knowledge_source,
|
|
219
|
-
starterQuestionsCount: (i = (
|
|
219
|
+
starterQuestionsCount: (i = (c = e.knowledge) == null ? void 0 : c.starter_message) == null ? void 0 : i.length,
|
|
220
220
|
topicsToAvoid: t == null ? void 0 : t.topics_to_avoid,
|
|
221
221
|
maxResponseLength: t == null ? void 0 : t.max_response_length,
|
|
222
222
|
agentId: e.id,
|
|
@@ -225,24 +225,24 @@ function yt(e) {
|
|
|
225
225
|
...e.access === "public" ? { from: "agent-template" } : {}
|
|
226
226
|
};
|
|
227
227
|
}
|
|
228
|
-
const
|
|
229
|
-
function
|
|
230
|
-
var r, d,
|
|
231
|
-
const { event: n, ...
|
|
228
|
+
const Ct = (e) => e.reduce((t, a) => t + a, 0), xe = (e) => Ct(e) / e.length;
|
|
229
|
+
function kt(e, t, a) {
|
|
230
|
+
var r, d, w;
|
|
231
|
+
const { event: n, ...s } = e, { template: o } = (t == null ? void 0 : t.llm) || {}, { language: c } = ((r = t == null ? void 0 : t.presenter) == null ? void 0 : r.voice) || {};
|
|
232
232
|
return {
|
|
233
|
-
...
|
|
234
|
-
llm: { ...
|
|
235
|
-
script: { ...
|
|
236
|
-
stitch: (t == null ? void 0 : t.presenter.type) === "talk" ? (
|
|
233
|
+
...s,
|
|
234
|
+
llm: { ...s.llm, template: o },
|
|
235
|
+
script: { ...s.script, provider: { ...(d = s == null ? void 0 : s.script) == null ? void 0 : d.provider, language: c } },
|
|
236
|
+
stitch: (t == null ? void 0 : t.presenter.type) === "talk" ? (w = t == null ? void 0 : t.presenter) == null ? void 0 : w.stitch : void 0,
|
|
237
237
|
...a
|
|
238
238
|
};
|
|
239
239
|
}
|
|
240
|
-
function
|
|
240
|
+
function Be(e) {
|
|
241
241
|
"requestIdleCallback" in window ? requestIdleCallback(e, { timeout: 2e3 }) : setTimeout(e, 0);
|
|
242
242
|
}
|
|
243
243
|
let ve = {};
|
|
244
|
-
const
|
|
245
|
-
function
|
|
244
|
+
const Rt = "https://api-js.mixpanel.com/track/?verbose=1&ip=1";
|
|
245
|
+
function Dt(e) {
|
|
246
246
|
const t = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk";
|
|
247
247
|
return {
|
|
248
248
|
token: e.token || "testKey",
|
|
@@ -257,10 +257,10 @@ function kt(e) {
|
|
|
257
257
|
enrich(a) {
|
|
258
258
|
this.additionalProperties = { ...this.additionalProperties, ...a };
|
|
259
259
|
},
|
|
260
|
-
async track(a, n,
|
|
260
|
+
async track(a, n, s) {
|
|
261
261
|
if (!this.isEnabled)
|
|
262
262
|
return Promise.resolve();
|
|
263
|
-
const { audioPath: o, ...
|
|
263
|
+
const { audioPath: o, ...c } = n || {}, i = s || Date.now(), r = {
|
|
264
264
|
method: "POST",
|
|
265
265
|
headers: {
|
|
266
266
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
@@ -271,7 +271,7 @@ function kt(e) {
|
|
|
271
271
|
event: a,
|
|
272
272
|
properties: {
|
|
273
273
|
...this.additionalProperties,
|
|
274
|
-
...
|
|
274
|
+
...c,
|
|
275
275
|
agentId: this.agentId,
|
|
276
276
|
source: t,
|
|
277
277
|
token: this.token,
|
|
@@ -286,22 +286,22 @@ function kt(e) {
|
|
|
286
286
|
])
|
|
287
287
|
})
|
|
288
288
|
};
|
|
289
|
-
return fetch(
|
|
289
|
+
return fetch(Rt, {
|
|
290
290
|
...r,
|
|
291
291
|
keepalive: !0
|
|
292
292
|
}).catch((d) => console.error("Analytics tracking error:", d)), Promise.resolve();
|
|
293
293
|
},
|
|
294
|
-
linkTrack(a, n,
|
|
295
|
-
ve[a] || (ve[a] = { events: {}, resolvedDependencies: [] }), o.includes(
|
|
296
|
-
const
|
|
297
|
-
if (
|
|
298
|
-
(r) =>
|
|
294
|
+
linkTrack(a, n, s, o) {
|
|
295
|
+
ve[a] || (ve[a] = { events: {}, resolvedDependencies: [] }), o.includes(s) || o.push(s);
|
|
296
|
+
const c = ve[a];
|
|
297
|
+
if (c.events[s] = { props: n }, c.resolvedDependencies.push(s), o.every(
|
|
298
|
+
(r) => c.resolvedDependencies.includes(r)
|
|
299
299
|
)) {
|
|
300
|
-
const r = o.reduce((d,
|
|
301
|
-
this.track(a, r),
|
|
300
|
+
const r = o.reduce((d, w) => c.events[w] ? { ...d, ...c.events[w].props } : d, {});
|
|
301
|
+
this.track(a, r), c.resolvedDependencies = c.resolvedDependencies.filter(
|
|
302
302
|
(d) => !o.includes(d)
|
|
303
303
|
), o.forEach((d) => {
|
|
304
|
-
delete
|
|
304
|
+
delete c.events[d];
|
|
305
305
|
});
|
|
306
306
|
}
|
|
307
307
|
}
|
|
@@ -315,22 +315,22 @@ function _e() {
|
|
|
315
315
|
get: (t = !1) => t ? Date.now() - e : e
|
|
316
316
|
};
|
|
317
317
|
}
|
|
318
|
-
const ie = _e(), Re = _e(),
|
|
319
|
-
function
|
|
320
|
-
return e ===
|
|
318
|
+
const ie = _e(), Re = _e(), Fe = _e();
|
|
319
|
+
function qe(e) {
|
|
320
|
+
return e === N.Playground ? { headers: { [lt]: "true" } } : {};
|
|
321
321
|
}
|
|
322
|
-
async function
|
|
322
|
+
async function He(e, t, a, n, s = !1, o) {
|
|
323
323
|
try {
|
|
324
|
-
return !o && !
|
|
324
|
+
return !o && !Ve(n) && (o = await t.newChat(e.id, { persist: s }, qe(n)), a.track("agent-chat", {
|
|
325
325
|
event: "created",
|
|
326
326
|
chatId: o.id,
|
|
327
327
|
mode: n
|
|
328
328
|
})), { chat: o, chatMode: (o == null ? void 0 : o.chat_mode) ?? n };
|
|
329
|
-
} catch (
|
|
330
|
-
throw
|
|
329
|
+
} catch (c) {
|
|
330
|
+
throw Mt(c) === "InsufficientCreditsError" ? new Error("InsufficientCreditsError") : new Error("Cannot create new chat");
|
|
331
331
|
}
|
|
332
332
|
}
|
|
333
|
-
const
|
|
333
|
+
const Mt = (e) => {
|
|
334
334
|
try {
|
|
335
335
|
const t = JSON.parse(e.message);
|
|
336
336
|
return t == null ? void 0 : t.kind;
|
|
@@ -338,18 +338,18 @@ const Rt = (e) => {
|
|
|
338
338
|
return "UnknownError";
|
|
339
339
|
}
|
|
340
340
|
};
|
|
341
|
-
function
|
|
341
|
+
function Et(e) {
|
|
342
342
|
return e && e.length > 0 ? e : [];
|
|
343
343
|
}
|
|
344
|
-
function
|
|
345
|
-
const
|
|
344
|
+
function It(e, t, a, n) {
|
|
345
|
+
const s = Te(e, `${t}/v2/agents/${a}`, n);
|
|
346
346
|
return {
|
|
347
347
|
async createStream(o) {
|
|
348
|
-
return
|
|
348
|
+
return s.post("/sessions", o);
|
|
349
349
|
}
|
|
350
350
|
};
|
|
351
351
|
}
|
|
352
|
-
const
|
|
352
|
+
const Qe = (e, t) => (a, n) => e && console.log(`[${t}] ${a}`, n ?? "");
|
|
353
353
|
async function Se() {
|
|
354
354
|
try {
|
|
355
355
|
return await import("./livekit-client.esm-C1GRQdZY.js");
|
|
@@ -359,273 +359,275 @@ async function Se() {
|
|
|
359
359
|
);
|
|
360
360
|
}
|
|
361
361
|
}
|
|
362
|
-
const
|
|
362
|
+
const Tt = {
|
|
363
363
|
excellent: re.Strong,
|
|
364
364
|
good: re.Strong,
|
|
365
365
|
poor: re.Weak,
|
|
366
366
|
lost: re.Unknown,
|
|
367
367
|
unknown: re.Unknown
|
|
368
|
-
},
|
|
368
|
+
}, me = JSON.stringify({
|
|
369
369
|
kind: "InternalServerError",
|
|
370
370
|
description: "Stream Error"
|
|
371
371
|
});
|
|
372
372
|
var Ae = /* @__PURE__ */ ((e) => (e.Chat = "lk.chat", e.Speak = "did.speak", e.Interrupt = "did.interrupt", e))(Ae || {});
|
|
373
373
|
function De(e, t, a, n) {
|
|
374
|
-
var
|
|
375
|
-
throw t("Failed to connect to LiveKit room:", e), n(), (
|
|
374
|
+
var s, o;
|
|
375
|
+
throw t("Failed to connect to LiveKit room:", e), n(), (s = a.onConnectionStateChange) == null || s.call(a, S.Fail), (o = a.onError) == null || o.call(a, e, { sessionId: "" }), e;
|
|
376
376
|
}
|
|
377
|
-
async function
|
|
378
|
-
var
|
|
379
|
-
const n =
|
|
380
|
-
let u = null,
|
|
381
|
-
const
|
|
382
|
-
let
|
|
383
|
-
u = new
|
|
377
|
+
async function _t(e, t, a) {
|
|
378
|
+
var Pe, be;
|
|
379
|
+
const n = Qe(a.debug || !1, "LiveKitStreamingManager"), { Room: s, RoomEvent: o, ConnectionState: c } = await Se(), { callbacks: i, auth: r, baseURL: d, analytics: w, microphoneStream: p } = a;
|
|
380
|
+
let u = null, P = !1;
|
|
381
|
+
const $ = ae.Fluent;
|
|
382
|
+
let B = !0, R = null, M = null;
|
|
383
|
+
u = new s({
|
|
384
384
|
adaptiveStream: !1,
|
|
385
385
|
// Must be false to use mediaStreamTrack directly
|
|
386
386
|
dynacast: !0
|
|
387
387
|
});
|
|
388
388
|
let z = null;
|
|
389
|
-
const
|
|
390
|
-
let W =
|
|
391
|
-
const ee =
|
|
392
|
-
let
|
|
389
|
+
const T = 2e4;
|
|
390
|
+
let W = q.Idle;
|
|
391
|
+
const ee = It(r, d || ge, e, i.onError);
|
|
392
|
+
let E, G, Z;
|
|
393
393
|
try {
|
|
394
394
|
const l = await ee.createStream({
|
|
395
395
|
transport_provider: ye.Livekit,
|
|
396
396
|
chat_persist: t.chat_persist ?? !0
|
|
397
|
-
}), { id:
|
|
398
|
-
(
|
|
397
|
+
}), { id: g, session_token: v, session_url: D } = l;
|
|
398
|
+
(Pe = i.onStreamCreated) == null || Pe.call(i, { session_id: g, stream_id: g, agent_id: e }), E = g, G = v, Z = D, await u.prepareConnection(Z, G);
|
|
399
399
|
} catch (l) {
|
|
400
400
|
De(l, n, i, () => {
|
|
401
|
-
|
|
401
|
+
B = !1;
|
|
402
402
|
});
|
|
403
403
|
}
|
|
404
|
-
if (!Z || !G || !
|
|
404
|
+
if (!Z || !G || !E)
|
|
405
405
|
return Promise.reject(new Error("Failed to initialize LiveKit stream"));
|
|
406
|
-
u.on(o.ConnectionStateChanged,
|
|
406
|
+
u.on(o.ConnectionStateChanged, y).on(o.ConnectionQualityChanged, k).on(o.ActiveSpeakersChanged, _).on(o.ParticipantConnected, b).on(o.ParticipantDisconnected, I).on(o.TrackSubscribed, U).on(o.TrackUnsubscribed, H).on(o.DataReceived, Q).on(o.MediaDevicesError, L).on(o.TranscriptionReceived, f).on(o.EncryptionError, K).on(o.TrackSubscriptionFailed, X), (be = i.onConnectionStateChange) == null || be.call(i, S.New);
|
|
407
|
+
function f(l, g) {
|
|
408
|
+
var v;
|
|
409
|
+
g != null && g.isLocal && W === q.Talking && ((v = i.onInterruptDetected) == null || v.call(i, { type: "audio" }), W = q.Idle);
|
|
410
|
+
}
|
|
407
411
|
try {
|
|
408
412
|
await u.connect(Z, G), n("LiveKit room joined successfully"), z = setTimeout(() => {
|
|
409
413
|
var l;
|
|
410
|
-
n("Track subscription timeout - no track subscribed within 30 seconds after connect"), z = null,
|
|
414
|
+
n("Track subscription timeout - no track subscribed within 30 seconds after connect"), z = null, w.track("connectivity-error", {
|
|
411
415
|
error: "Track subscription timeout",
|
|
412
|
-
sessionId:
|
|
413
|
-
}), (l = i.onError) == null || l.call(i, new Error("Track subscription timeout"), { sessionId:
|
|
414
|
-
},
|
|
416
|
+
sessionId: E
|
|
417
|
+
}), (l = i.onError) == null || l.call(i, new Error("Track subscription timeout"), { sessionId: E }), se();
|
|
418
|
+
}, T), B = !1;
|
|
415
419
|
} catch (l) {
|
|
416
420
|
De(l, n, i, () => {
|
|
417
|
-
|
|
421
|
+
B = !1;
|
|
418
422
|
});
|
|
419
423
|
}
|
|
420
|
-
|
|
421
|
-
"stream-type":
|
|
424
|
+
w.enrich({
|
|
425
|
+
"stream-type": $
|
|
422
426
|
});
|
|
423
|
-
function
|
|
424
|
-
var
|
|
427
|
+
function y(l) {
|
|
428
|
+
var g, v, D, A, O;
|
|
425
429
|
switch (n("Connection state changed:", l), l) {
|
|
426
|
-
case
|
|
427
|
-
(
|
|
430
|
+
case c.Connecting:
|
|
431
|
+
(g = i.onConnectionStateChange) == null || g.call(i, S.Connecting);
|
|
428
432
|
break;
|
|
429
|
-
case
|
|
430
|
-
n("LiveKit room connected successfully"),
|
|
431
|
-
var
|
|
432
|
-
(
|
|
433
|
+
case c.Connected:
|
|
434
|
+
n("LiveKit room connected successfully"), P = !0, B ? queueMicrotask(() => {
|
|
435
|
+
var x;
|
|
436
|
+
(x = i.onConnectionStateChange) == null || x.call(i, S.Connected);
|
|
433
437
|
}) : (v = i.onConnectionStateChange) == null || v.call(i, S.Connected);
|
|
434
438
|
break;
|
|
435
|
-
case
|
|
436
|
-
n("LiveKit room disconnected"),
|
|
439
|
+
case c.Disconnected:
|
|
440
|
+
n("LiveKit room disconnected"), P = !1, (D = i.onConnectionStateChange) == null || D.call(i, S.Disconnected);
|
|
437
441
|
break;
|
|
438
|
-
case
|
|
439
|
-
n("LiveKit room reconnecting..."), (
|
|
442
|
+
case c.Reconnecting:
|
|
443
|
+
n("LiveKit room reconnecting..."), (A = i.onConnectionStateChange) == null || A.call(i, S.Connecting);
|
|
440
444
|
break;
|
|
441
|
-
case
|
|
442
|
-
n("LiveKit room signal reconnecting..."), (
|
|
445
|
+
case c.SignalReconnecting:
|
|
446
|
+
n("LiveKit room signal reconnecting..."), (O = i.onConnectionStateChange) == null || O.call(i, S.Connecting);
|
|
443
447
|
break;
|
|
444
448
|
}
|
|
445
449
|
}
|
|
446
|
-
function
|
|
450
|
+
function k(l, g) {
|
|
447
451
|
var v;
|
|
448
|
-
n("Connection quality:", l),
|
|
452
|
+
n("Connection quality:", l), g != null && g.isLocal && ((v = i.onConnectivityStateChange) == null || v.call(i, Tt[l]));
|
|
449
453
|
}
|
|
450
|
-
function
|
|
451
|
-
var R, D, K, L;
|
|
454
|
+
function _(l) {
|
|
452
455
|
n("Active speakers changed:", l);
|
|
453
|
-
const h = l.find((oe) => oe.isLocal), v = l.find((oe) => !oe.isLocal);
|
|
454
|
-
h ? ((R = i.onAgentActivityStateChange) == null || R.call(i, J.Idle), W !== J.Idle && ((D = i.onInterruptDetected) == null || D.call(i, { type: "audio" }), W = J.Idle)) : v ? (W = J.Talking, (K = i.onAgentActivityStateChange) == null || K.call(i, J.Talking)) : ((L = i.onAgentActivityStateChange) == null || L.call(i, J.Idle), W = J.Idle);
|
|
455
456
|
}
|
|
456
|
-
function
|
|
457
|
+
function b(l) {
|
|
457
458
|
n("Participant connected:", l.identity);
|
|
458
459
|
}
|
|
459
|
-
function
|
|
460
|
-
n("Participant disconnected:", l.identity),
|
|
460
|
+
function I(l) {
|
|
461
|
+
n("Participant disconnected:", l.identity), se();
|
|
461
462
|
}
|
|
462
|
-
function
|
|
463
|
-
var
|
|
463
|
+
function U(l, g, v) {
|
|
464
|
+
var A, O, x;
|
|
464
465
|
n(`Track subscribed: ${l.kind} from ${v.identity}`), z && (clearTimeout(z), z = null, n("Track subscription timeout cleared"));
|
|
465
|
-
const
|
|
466
|
-
if (!
|
|
466
|
+
const D = l.mediaStreamTrack;
|
|
467
|
+
if (!D) {
|
|
467
468
|
n(`No mediaStreamTrack available for ${l.kind}`);
|
|
468
469
|
return;
|
|
469
470
|
}
|
|
470
|
-
|
|
471
|
+
R ? (R.addTrack(D), n(`Added ${l.kind} track to shared MediaStream`)) : (R = new MediaStream([D]), n(`Created shared MediaStream with ${l.kind} track`)), l.kind === "video" && ((A = i.onStreamReady) == null || A.call(i), (O = i.onSrcObjectReady) == null || O.call(i, R), (x = i.onVideoStateChange) == null || x.call(i, C.Start));
|
|
471
472
|
}
|
|
472
|
-
function
|
|
473
|
-
var
|
|
474
|
-
n(`Track unsubscribed: ${l.kind} from ${v.identity}`), l.kind === "video" && ((
|
|
473
|
+
function H(l, g, v) {
|
|
474
|
+
var D;
|
|
475
|
+
n(`Track unsubscribed: ${l.kind} from ${v.identity}`), l.kind === "video" && ((D = i.onVideoStateChange) == null || D.call(i, C.Stop));
|
|
475
476
|
}
|
|
476
|
-
function
|
|
477
|
-
var
|
|
478
|
-
const
|
|
479
|
-
n("Data received:",
|
|
477
|
+
function Q(l, g, v, D) {
|
|
478
|
+
var O, x, le, Le, je;
|
|
479
|
+
const A = new TextDecoder().decode(l);
|
|
480
|
+
n("Data received:", A);
|
|
480
481
|
try {
|
|
481
|
-
const te = JSON.parse(
|
|
482
|
-
if (
|
|
482
|
+
const te = JSON.parse(A), ce = D || te.subject;
|
|
483
|
+
if (ce === j.ChatAnswer) {
|
|
483
484
|
const ne = Y.Answer;
|
|
484
|
-
(
|
|
485
|
+
(O = i.onMessage) == null || O.call(i, ne, {
|
|
485
486
|
event: ne,
|
|
486
487
|
...te
|
|
487
488
|
});
|
|
488
|
-
} else if (
|
|
489
|
+
} else if (ce === j.ChatPartial) {
|
|
489
490
|
const ne = Y.Partial;
|
|
490
|
-
(
|
|
491
|
+
(x = i.onMessage) == null || x.call(i, ne, {
|
|
491
492
|
event: ne,
|
|
492
493
|
...te
|
|
493
494
|
});
|
|
494
|
-
} else if ([
|
|
495
|
-
|
|
496
|
-
|
|
495
|
+
} else if ([j.StreamVideoCreated, j.StreamVideoDone].includes(ce)) {
|
|
496
|
+
W = ce === j.StreamVideoCreated ? q.Talking : q.Idle, (le = i.onAgentActivityStateChange) == null || le.call(i, W);
|
|
497
|
+
const ne = (te == null ? void 0 : te.role) || (g == null ? void 0 : g.identity) || "datachannel";
|
|
498
|
+
(Le = i.onMessage) == null || Le.call(i, ce, {
|
|
497
499
|
[ne]: te
|
|
498
500
|
});
|
|
499
|
-
} else if (
|
|
501
|
+
} else if (ce === j.ChatAudioTranscribed) {
|
|
500
502
|
const ne = Y.Transcribe;
|
|
501
|
-
(
|
|
503
|
+
(je = i.onMessage) == null || je.call(i, ne, {
|
|
502
504
|
event: ne,
|
|
503
505
|
...te
|
|
504
506
|
}), queueMicrotask(() => {
|
|
505
|
-
var
|
|
506
|
-
(
|
|
507
|
+
var $e;
|
|
508
|
+
($e = i.onAgentActivityStateChange) == null || $e.call(i, q.Loading);
|
|
507
509
|
});
|
|
508
510
|
}
|
|
509
511
|
} catch (te) {
|
|
510
512
|
n("Failed to parse data channel message:", te);
|
|
511
513
|
}
|
|
512
514
|
}
|
|
513
|
-
function
|
|
514
|
-
var
|
|
515
|
-
n("Media devices error:", l), (
|
|
515
|
+
function L(l) {
|
|
516
|
+
var g;
|
|
517
|
+
n("Media devices error:", l), (g = i.onError) == null || g.call(i, new Error(me), { sessionId: E });
|
|
516
518
|
}
|
|
517
|
-
function
|
|
518
|
-
var
|
|
519
|
-
n("Encryption error:", l), (
|
|
519
|
+
function K(l) {
|
|
520
|
+
var g;
|
|
521
|
+
n("Encryption error:", l), (g = i.onError) == null || g.call(i, new Error(me), { sessionId: E });
|
|
520
522
|
}
|
|
521
|
-
function
|
|
522
|
-
n("Track subscription failed:", { trackSid: l, participant:
|
|
523
|
+
function X(l, g, v) {
|
|
524
|
+
n("Track subscription failed:", { trackSid: l, participant: g, reason: v });
|
|
523
525
|
}
|
|
524
|
-
async function
|
|
526
|
+
async function oe(l) {
|
|
525
527
|
if (!u) return null;
|
|
526
|
-
const { Track:
|
|
528
|
+
const { Track: g } = await Se(), v = u.localParticipant.audioTrackPublications;
|
|
527
529
|
if (v) {
|
|
528
|
-
for (const [
|
|
529
|
-
if (
|
|
530
|
-
const
|
|
531
|
-
if (
|
|
532
|
-
return
|
|
530
|
+
for (const [D, A] of v)
|
|
531
|
+
if (A.source === g.Source.Microphone && A.track) {
|
|
532
|
+
const x = A.track.mediaStreamTrack;
|
|
533
|
+
if (x === l || x && x.id === l.id)
|
|
534
|
+
return A;
|
|
533
535
|
}
|
|
534
536
|
}
|
|
535
537
|
return null;
|
|
536
538
|
}
|
|
537
|
-
function
|
|
538
|
-
if (!
|
|
539
|
+
function V(l) {
|
|
540
|
+
if (!M || !M.track)
|
|
539
541
|
return !1;
|
|
540
|
-
const
|
|
541
|
-
return
|
|
542
|
+
const g = M.track.mediaStreamTrack;
|
|
543
|
+
return g !== l && (g == null ? void 0 : g.id) !== l.id;
|
|
542
544
|
}
|
|
543
|
-
async function
|
|
544
|
-
var
|
|
545
|
-
if (!
|
|
545
|
+
async function m(l) {
|
|
546
|
+
var O, x;
|
|
547
|
+
if (!P || !u)
|
|
546
548
|
throw n("Room is not connected, cannot publish microphone stream"), new Error("Room is not connected");
|
|
547
|
-
const
|
|
548
|
-
if (
|
|
549
|
+
const g = l.getAudioTracks();
|
|
550
|
+
if (g.length === 0) {
|
|
549
551
|
n("No audio track found in the provided MediaStream");
|
|
550
552
|
return;
|
|
551
553
|
}
|
|
552
|
-
const v =
|
|
553
|
-
if (
|
|
554
|
+
const v = g[0], { Track: D } = await Se(), A = await oe(v);
|
|
555
|
+
if (A) {
|
|
554
556
|
n("Microphone track is already published, skipping", {
|
|
555
557
|
trackId: v.id,
|
|
556
|
-
publishedTrackId: (
|
|
557
|
-
}),
|
|
558
|
+
publishedTrackId: (x = (O = A.track) == null ? void 0 : O.mediaStreamTrack) == null ? void 0 : x.id
|
|
559
|
+
}), M = A;
|
|
558
560
|
return;
|
|
559
561
|
}
|
|
560
|
-
|
|
562
|
+
V(v) && (n("Unpublishing existing microphone track before publishing new one"), await h()), n("Publishing microphone track from provided MediaStream", { trackId: v.id });
|
|
561
563
|
try {
|
|
562
|
-
|
|
563
|
-
source:
|
|
564
|
-
}), n("Microphone track published successfully", { trackSid:
|
|
565
|
-
} catch (
|
|
566
|
-
throw n("Failed to publish microphone track:",
|
|
564
|
+
M = await u.localParticipant.publishTrack(v, {
|
|
565
|
+
source: D.Source.Microphone
|
|
566
|
+
}), n("Microphone track published successfully", { trackSid: M.trackSid });
|
|
567
|
+
} catch (le) {
|
|
568
|
+
throw n("Failed to publish microphone track:", le), le;
|
|
567
569
|
}
|
|
568
570
|
}
|
|
569
|
-
async function
|
|
570
|
-
if (!(!
|
|
571
|
+
async function h() {
|
|
572
|
+
if (!(!M || !M.track))
|
|
571
573
|
try {
|
|
572
|
-
u && (await u.localParticipant.unpublishTrack(
|
|
574
|
+
u && (await u.localParticipant.unpublishTrack(M.track), n("Microphone track unpublished"));
|
|
573
575
|
} catch (l) {
|
|
574
576
|
n("Error unpublishing microphone track:", l);
|
|
575
577
|
} finally {
|
|
576
|
-
|
|
578
|
+
M = null;
|
|
577
579
|
}
|
|
578
580
|
}
|
|
579
|
-
function
|
|
580
|
-
|
|
581
|
+
function F() {
|
|
582
|
+
R && (R.getTracks().forEach((l) => l.stop()), R = null);
|
|
581
583
|
}
|
|
582
|
-
async function
|
|
583
|
-
var v,
|
|
584
|
-
if (!
|
|
585
|
-
n("Room is not connected for sending messages"), (v = i.onError) == null || v.call(i, new Error(
|
|
586
|
-
sessionId:
|
|
584
|
+
async function J(l, g) {
|
|
585
|
+
var v, D;
|
|
586
|
+
if (!P || !u) {
|
|
587
|
+
n("Room is not connected for sending messages"), (v = i.onError) == null || v.call(i, new Error(me), {
|
|
588
|
+
sessionId: E
|
|
587
589
|
});
|
|
588
590
|
return;
|
|
589
591
|
}
|
|
590
592
|
try {
|
|
591
|
-
await u.localParticipant.sendText(l, { topic:
|
|
592
|
-
} catch (
|
|
593
|
-
n("Failed to send message:",
|
|
593
|
+
await u.localParticipant.sendText(l, { topic: g }), n("Message sent successfully:", l);
|
|
594
|
+
} catch (A) {
|
|
595
|
+
n("Failed to send message:", A), (D = i.onError) == null || D.call(i, new Error(me), { sessionId: E });
|
|
594
596
|
}
|
|
595
597
|
}
|
|
596
|
-
async function
|
|
597
|
-
var
|
|
598
|
+
async function he(l) {
|
|
599
|
+
var g;
|
|
598
600
|
try {
|
|
599
|
-
const
|
|
600
|
-
return
|
|
601
|
+
const D = JSON.parse(l).topic;
|
|
602
|
+
return J("", D);
|
|
601
603
|
} catch (v) {
|
|
602
|
-
n("Failed to send data channel message:", v), (
|
|
604
|
+
n("Failed to send data channel message:", v), (g = i.onError) == null || g.call(i, new Error(me), { sessionId: E });
|
|
603
605
|
}
|
|
604
606
|
}
|
|
605
607
|
function pe(l) {
|
|
606
|
-
return
|
|
608
|
+
return J(
|
|
607
609
|
l,
|
|
608
610
|
"lk.chat"
|
|
609
611
|
/* Chat */
|
|
610
612
|
);
|
|
611
613
|
}
|
|
612
|
-
async function
|
|
613
|
-
var l,
|
|
614
|
-
z && (clearTimeout(z), z = null), u && (await
|
|
614
|
+
async function se() {
|
|
615
|
+
var l, g;
|
|
616
|
+
z && (clearTimeout(z), z = null), u && (await h(), await u.disconnect()), F(), P = !1, (l = i.onConnectionStateChange) == null || l.call(i, S.Disconnected), (g = i.onAgentActivityStateChange) == null || g.call(i, q.Idle), W = q.Idle;
|
|
615
617
|
}
|
|
616
618
|
return {
|
|
617
619
|
speak(l) {
|
|
618
|
-
const
|
|
619
|
-
return
|
|
620
|
-
|
|
620
|
+
const g = typeof l == "string" ? l : JSON.stringify(l);
|
|
621
|
+
return J(
|
|
622
|
+
g,
|
|
621
623
|
"did.speak"
|
|
622
624
|
/* Speak */
|
|
623
625
|
);
|
|
624
626
|
},
|
|
625
|
-
disconnect:
|
|
627
|
+
disconnect: se,
|
|
626
628
|
async reconnect() {
|
|
627
|
-
var l,
|
|
628
|
-
if ((u == null ? void 0 : u.state) ===
|
|
629
|
+
var l, g, v;
|
|
630
|
+
if ((u == null ? void 0 : u.state) === c.Connected) {
|
|
629
631
|
n("Room is already connected");
|
|
630
632
|
return;
|
|
631
633
|
}
|
|
@@ -633,41 +635,41 @@ async function It(e, t, a) {
|
|
|
633
635
|
throw n("Cannot reconnect: missing room, URL or token"), new Error("Cannot reconnect: session not available");
|
|
634
636
|
n("Reconnecting to LiveKit room, state:", u.state), (l = i.onConnectionStateChange) == null || l.call(i, S.Connecting);
|
|
635
637
|
try {
|
|
636
|
-
if (await u.connect(Z, G), n("Room reconnected"),
|
|
637
|
-
if (n("Waiting for agent to join..."), !await new Promise((
|
|
638
|
-
const
|
|
639
|
-
u == null || u.off(o.ParticipantConnected,
|
|
640
|
-
}, 5e3),
|
|
641
|
-
clearTimeout(
|
|
638
|
+
if (await u.connect(Z, G), n("Room reconnected"), P = !0, u.remoteParticipants.size === 0) {
|
|
639
|
+
if (n("Waiting for agent to join..."), !await new Promise((A) => {
|
|
640
|
+
const O = setTimeout(() => {
|
|
641
|
+
u == null || u.off(o.ParticipantConnected, x), A(!1);
|
|
642
|
+
}, 5e3), x = () => {
|
|
643
|
+
clearTimeout(O), u == null || u.off(o.ParticipantConnected, x), A(!0);
|
|
642
644
|
};
|
|
643
|
-
u == null || u.on(o.ParticipantConnected,
|
|
645
|
+
u == null || u.on(o.ParticipantConnected, x);
|
|
644
646
|
}))
|
|
645
647
|
throw n("Agent did not join within timeout"), await u.disconnect(), new Error("Agent did not rejoin the room");
|
|
646
648
|
n("Agent joined");
|
|
647
649
|
}
|
|
648
|
-
(
|
|
649
|
-
} catch (
|
|
650
|
-
throw n("Failed to reconnect:",
|
|
650
|
+
(g = i.onConnectionStateChange) == null || g.call(i, S.Connected);
|
|
651
|
+
} catch (D) {
|
|
652
|
+
throw n("Failed to reconnect:", D), (v = i.onConnectionStateChange) == null || v.call(i, S.Fail), D;
|
|
651
653
|
}
|
|
652
654
|
},
|
|
653
|
-
sendDataChannelMessage:
|
|
655
|
+
sendDataChannelMessage: he,
|
|
654
656
|
sendTextMessage: pe,
|
|
655
|
-
publishMicrophoneStream:
|
|
656
|
-
unpublishMicrophoneStream:
|
|
657
|
-
sessionId:
|
|
658
|
-
streamId:
|
|
659
|
-
streamType:
|
|
657
|
+
publishMicrophoneStream: m,
|
|
658
|
+
unpublishMicrophoneStream: h,
|
|
659
|
+
sessionId: E,
|
|
660
|
+
streamId: E,
|
|
661
|
+
streamType: $,
|
|
660
662
|
interruptAvailable: !0,
|
|
661
663
|
triggersAvailable: !1
|
|
662
664
|
};
|
|
663
665
|
}
|
|
664
|
-
const
|
|
666
|
+
const At = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
665
667
|
__proto__: null,
|
|
666
668
|
DataChannelTopic: Ae,
|
|
667
|
-
createLiveKitStreamingManager:
|
|
669
|
+
createLiveKitStreamingManager: _t,
|
|
668
670
|
handleInitError: De
|
|
669
671
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
670
|
-
function
|
|
672
|
+
function Pt(e, t, a) {
|
|
671
673
|
if (!e)
|
|
672
674
|
throw new Error("Please connect to the agent first");
|
|
673
675
|
if (!e.interruptAvailable)
|
|
@@ -677,66 +679,66 @@ function _t(e, t, a) {
|
|
|
677
679
|
if (!a)
|
|
678
680
|
throw new Error("No active video to interrupt");
|
|
679
681
|
}
|
|
680
|
-
async function
|
|
682
|
+
async function bt(e, t) {
|
|
681
683
|
const a = {
|
|
682
|
-
type:
|
|
684
|
+
type: j.StreamInterrupt,
|
|
683
685
|
videoId: t,
|
|
684
686
|
timestamp: Date.now()
|
|
685
687
|
};
|
|
686
688
|
e.sendDataChannelMessage(JSON.stringify(a));
|
|
687
689
|
}
|
|
688
|
-
async function
|
|
690
|
+
async function Lt(e) {
|
|
689
691
|
const t = {
|
|
690
692
|
topic: Ae.Interrupt
|
|
691
693
|
};
|
|
692
694
|
e.sendDataChannelMessage(JSON.stringify(t));
|
|
693
695
|
}
|
|
694
|
-
function
|
|
696
|
+
function jt(e) {
|
|
695
697
|
return new Promise((t, a) => {
|
|
696
|
-
const { callbacks: n, host:
|
|
697
|
-
|
|
698
|
-
console.error(u),
|
|
699
|
-
},
|
|
700
|
-
r == null || r(u), t(
|
|
698
|
+
const { callbacks: n, host: s, auth: o, externalId: c } = e, { onMessage: i = null, onOpen: r = null, onClose: d = null, onError: w = null } = n || {}, p = new WebSocket(`${s}?authorization=${encodeURIComponent(Oe(o, c))}`);
|
|
699
|
+
p.onmessage = i, p.onclose = d, p.onerror = (u) => {
|
|
700
|
+
console.error(u), w == null || w("Websocket failed to connect", u), a(u);
|
|
701
|
+
}, p.onopen = (u) => {
|
|
702
|
+
r == null || r(u), t(p);
|
|
701
703
|
};
|
|
702
704
|
});
|
|
703
705
|
}
|
|
704
|
-
async function
|
|
706
|
+
async function $t(e) {
|
|
705
707
|
const { retries: t = 1 } = e;
|
|
706
708
|
let a = null;
|
|
707
709
|
for (let n = 0; (a == null ? void 0 : a.readyState) !== WebSocket.OPEN; n++)
|
|
708
710
|
try {
|
|
709
|
-
a = await
|
|
710
|
-
} catch (
|
|
711
|
+
a = await jt(e);
|
|
712
|
+
} catch (s) {
|
|
711
713
|
if (n === t)
|
|
712
|
-
throw
|
|
713
|
-
await
|
|
714
|
+
throw s;
|
|
715
|
+
await Ue(n * 500);
|
|
714
716
|
}
|
|
715
717
|
return a;
|
|
716
718
|
}
|
|
717
|
-
async function
|
|
718
|
-
const
|
|
719
|
+
async function xt(e, t, a, n) {
|
|
720
|
+
const s = a != null && a.onMessage ? [a.onMessage] : [], o = await $t({
|
|
719
721
|
auth: e,
|
|
720
722
|
host: t,
|
|
721
723
|
externalId: n,
|
|
722
724
|
callbacks: {
|
|
723
|
-
onError: (
|
|
725
|
+
onError: (c) => {
|
|
724
726
|
var i;
|
|
725
|
-
return (i = a.onError) == null ? void 0 : i.call(a, new
|
|
727
|
+
return (i = a.onError) == null ? void 0 : i.call(a, new et(c));
|
|
726
728
|
},
|
|
727
|
-
onMessage(
|
|
728
|
-
const i = JSON.parse(
|
|
729
|
-
|
|
729
|
+
onMessage(c) {
|
|
730
|
+
const i = JSON.parse(c.data);
|
|
731
|
+
s.forEach((r) => r(i.event, i));
|
|
730
732
|
}
|
|
731
733
|
}
|
|
732
734
|
});
|
|
733
735
|
return {
|
|
734
736
|
socket: o,
|
|
735
737
|
disconnect: () => o.close(),
|
|
736
|
-
subscribeToEvents: (
|
|
738
|
+
subscribeToEvents: (c) => s.push(c)
|
|
737
739
|
};
|
|
738
740
|
}
|
|
739
|
-
function
|
|
741
|
+
function Bt(e) {
|
|
740
742
|
if (e.answer !== void 0)
|
|
741
743
|
return e.answer;
|
|
742
744
|
let t = 0, a = "";
|
|
@@ -744,108 +746,112 @@ function $t(e) {
|
|
|
744
746
|
a += e[t++];
|
|
745
747
|
return a;
|
|
746
748
|
}
|
|
747
|
-
function
|
|
749
|
+
function Ft(e, t, a) {
|
|
748
750
|
if (!e.content)
|
|
749
751
|
return;
|
|
750
752
|
const n = t.messages[t.messages.length - 1];
|
|
751
753
|
(n == null ? void 0 : n.role) === "assistant" && !n.interrupted && (n.interrupted = !0);
|
|
752
|
-
const
|
|
754
|
+
const s = {
|
|
753
755
|
id: e.id || `user-${Date.now()}`,
|
|
754
756
|
role: e.role,
|
|
755
757
|
content: e.content,
|
|
756
758
|
created_at: e.created_at || (/* @__PURE__ */ new Date()).toISOString(),
|
|
757
759
|
transcribed: !0
|
|
758
760
|
};
|
|
759
|
-
t.messages.push(
|
|
761
|
+
t.messages.push(s), a == null || a([...t.messages], "user");
|
|
760
762
|
}
|
|
761
|
-
function
|
|
763
|
+
function Nt(e, t, a, n, s) {
|
|
762
764
|
if (e === Y.Transcribe && t.content) {
|
|
763
|
-
|
|
765
|
+
Ft(t, n, s);
|
|
764
766
|
return;
|
|
765
767
|
}
|
|
766
768
|
if (!(e === Y.Partial || e === Y.Answer))
|
|
767
769
|
return;
|
|
768
770
|
const o = n.messages[n.messages.length - 1];
|
|
769
|
-
let
|
|
771
|
+
let c;
|
|
770
772
|
if (o != null && o.transcribed && o.role === "user")
|
|
771
|
-
e === Y.Answer && t.content,
|
|
773
|
+
e === Y.Answer && t.content, c = {
|
|
772
774
|
id: t.id || `assistant-${Date.now()}`,
|
|
773
775
|
role: t.role || "assistant",
|
|
774
776
|
content: t.content || "",
|
|
775
777
|
created_at: t.created_at || (/* @__PURE__ */ new Date()).toISOString()
|
|
776
|
-
}, n.messages.push(
|
|
778
|
+
}, n.messages.push(c);
|
|
777
779
|
else if ((o == null ? void 0 : o.role) === "assistant")
|
|
778
|
-
|
|
780
|
+
c = o;
|
|
779
781
|
else
|
|
780
782
|
return;
|
|
781
783
|
const { content: i, sequence: r } = t;
|
|
782
784
|
e === Y.Partial ? a[r] = i : a.answer = i;
|
|
783
|
-
const d =
|
|
784
|
-
(
|
|
785
|
+
const d = Bt(a);
|
|
786
|
+
(c.content !== d || e === Y.Answer) && (c.content = d, s == null || s([...n.messages], e));
|
|
785
787
|
}
|
|
786
|
-
function
|
|
788
|
+
function zt(e, t, a, n, s) {
|
|
787
789
|
let o = {};
|
|
790
|
+
const c = () => o = {}, i = (r, d) => {
|
|
791
|
+
var w, p;
|
|
792
|
+
d === "user" && c(), (p = (w = a.callbacks).onNewMessage) == null || p.call(w, r, d);
|
|
793
|
+
};
|
|
788
794
|
return {
|
|
789
|
-
clearQueue:
|
|
790
|
-
onMessage: (
|
|
791
|
-
var
|
|
792
|
-
if ("content" in
|
|
793
|
-
const
|
|
794
|
-
|
|
795
|
+
clearQueue: c,
|
|
796
|
+
onMessage: (r, d) => {
|
|
797
|
+
var w, p;
|
|
798
|
+
if ("content" in d) {
|
|
799
|
+
const u = r === j.ChatAnswer ? Y.Answer : r === j.ChatAudioTranscribed ? Y.Transcribe : r;
|
|
800
|
+
Nt(u, d, o, t, i), u === Y.Answer && e.track("agent-message-received", {
|
|
795
801
|
messages: t.messages.length,
|
|
796
802
|
mode: t.chatMode
|
|
797
803
|
});
|
|
798
804
|
} else {
|
|
799
|
-
const
|
|
800
|
-
if (
|
|
801
|
-
e.linkTrack("agent-video",
|
|
802
|
-
else if (
|
|
803
|
-
const
|
|
804
|
-
|
|
805
|
+
const u = j, P = [u.StreamVideoDone, u.StreamVideoError, u.StreamVideoRejected], $ = [u.StreamFailed, u.StreamVideoError, u.StreamVideoRejected], B = kt(d, n, { mode: t.chatMode });
|
|
806
|
+
if (r = r, r === u.StreamVideoCreated)
|
|
807
|
+
e.linkTrack("agent-video", B, u.StreamVideoCreated, ["start"]);
|
|
808
|
+
else if (P.includes(r)) {
|
|
809
|
+
const R = r.split("/")[1];
|
|
810
|
+
$.includes(r) ? e.track("agent-video", { ...B, event: R }) : e.linkTrack("agent-video", { ...B, event: R }, r, ["done"]);
|
|
805
811
|
}
|
|
806
|
-
|
|
812
|
+
$.includes(r) && ((p = (w = a.callbacks).onError) == null || p.call(w, new Error(`Stream failed with event ${r}`), { data: d })), d.event === u.StreamDone && s();
|
|
807
813
|
}
|
|
808
814
|
}
|
|
809
815
|
};
|
|
810
816
|
}
|
|
811
|
-
function
|
|
812
|
-
const
|
|
817
|
+
function Kt(e, t, a, n) {
|
|
818
|
+
const s = Te(e, `${t}/agents/${a}`, n);
|
|
813
819
|
return {
|
|
814
|
-
createStream(o,
|
|
815
|
-
return
|
|
820
|
+
createStream(o, c) {
|
|
821
|
+
return s.post("/streams", o, { signal: c });
|
|
816
822
|
},
|
|
817
|
-
startConnection(o,
|
|
818
|
-
return
|
|
823
|
+
startConnection(o, c, i, r) {
|
|
824
|
+
return s.post(
|
|
819
825
|
`/streams/${o}/sdp`,
|
|
820
826
|
{
|
|
821
827
|
session_id: i,
|
|
822
|
-
answer:
|
|
828
|
+
answer: c
|
|
823
829
|
},
|
|
824
830
|
{ signal: r }
|
|
825
831
|
);
|
|
826
832
|
},
|
|
827
|
-
addIceCandidate(o,
|
|
828
|
-
return
|
|
833
|
+
addIceCandidate(o, c, i, r) {
|
|
834
|
+
return s.post(
|
|
829
835
|
`/streams/${o}/ice`,
|
|
830
836
|
{
|
|
831
837
|
session_id: i,
|
|
832
|
-
...
|
|
838
|
+
...c
|
|
833
839
|
},
|
|
834
840
|
{ signal: r }
|
|
835
841
|
);
|
|
836
842
|
},
|
|
837
|
-
sendStreamRequest(o,
|
|
838
|
-
return
|
|
839
|
-
session_id:
|
|
843
|
+
sendStreamRequest(o, c, i) {
|
|
844
|
+
return s.post(`/streams/${o}`, {
|
|
845
|
+
session_id: c,
|
|
840
846
|
...i
|
|
841
847
|
});
|
|
842
848
|
},
|
|
843
|
-
close(o,
|
|
844
|
-
return
|
|
849
|
+
close(o, c) {
|
|
850
|
+
return s.delete(`/streams/${o}`, { session_id: c });
|
|
845
851
|
}
|
|
846
852
|
};
|
|
847
853
|
}
|
|
848
|
-
function
|
|
854
|
+
function Jt(e, t, a) {
|
|
849
855
|
const n = (t.timestamp - e.timestamp) / 1e3;
|
|
850
856
|
return {
|
|
851
857
|
duration: n,
|
|
@@ -865,23 +871,23 @@ function Nt(e, t, a) {
|
|
|
865
871
|
lowFpsCount: a
|
|
866
872
|
};
|
|
867
873
|
}
|
|
868
|
-
function
|
|
874
|
+
function Ut(e) {
|
|
869
875
|
return e.filter(
|
|
870
876
|
(t) => t.freezeCount > 0 || t.framesPerSecond < 21 || t.framesDropped > 0 || t.packetsLost > 0
|
|
871
877
|
).map((t) => {
|
|
872
|
-
const { timestamp: a, ...n } = t,
|
|
873
|
-
return t.freezeCount > 0 &&
|
|
878
|
+
const { timestamp: a, ...n } = t, s = [];
|
|
879
|
+
return t.freezeCount > 0 && s.push("freeze"), t.framesPerSecond < 21 && s.push("low fps"), t.framesDropped > 0 && s.push("frames dropped"), t.packetsLost > 0 && s.push("packet loss"), {
|
|
874
880
|
...n,
|
|
875
|
-
causes:
|
|
881
|
+
causes: s
|
|
876
882
|
};
|
|
877
883
|
});
|
|
878
884
|
}
|
|
879
|
-
function
|
|
885
|
+
function Wt(e) {
|
|
880
886
|
let t = "", a = 0;
|
|
881
887
|
for (const n of e.values()) {
|
|
882
888
|
if (n && n.type === "codec" && n.mimeType.startsWith("video") && (t = n.mimeType.split("/")[1]), n && n.type === "candidate-pair") {
|
|
883
|
-
const
|
|
884
|
-
|
|
889
|
+
const s = n.currentRoundTripTime, c = n.nominated === !0;
|
|
890
|
+
s > 0 && (c || a === 0) && (a = s);
|
|
885
891
|
}
|
|
886
892
|
if (n && n.type === "inbound-rtp" && n.kind === "video")
|
|
887
893
|
return {
|
|
@@ -906,7 +912,7 @@ function Jt(e) {
|
|
|
906
912
|
}
|
|
907
913
|
return {};
|
|
908
914
|
}
|
|
909
|
-
function
|
|
915
|
+
function Vt(e, t, a) {
|
|
910
916
|
const n = e.map((r, d) => d === 0 ? a ? {
|
|
911
917
|
timestamp: r.timestamp,
|
|
912
918
|
duration: 0,
|
|
@@ -958,55 +964,55 @@ function Ut(e, t, a) {
|
|
|
958
964
|
framesPerSecond: r.framesPerSecond,
|
|
959
965
|
freezeCount: r.freezeCount - e[d - 1].freezeCount,
|
|
960
966
|
freezeDuration: r.freezeDuration - e[d - 1].freezeDuration
|
|
961
|
-
}),
|
|
967
|
+
}), s = Ut(n), o = s.reduce((r, d) => r + (d.causes.includes("low fps") ? 1 : 0), 0), c = n.filter((r) => !!r.avgJitterDelayInInterval).map((r) => r.avgJitterDelayInInterval), i = n.filter((r) => !!r.rtt).map((r) => r.rtt);
|
|
962
968
|
return {
|
|
963
969
|
webRTCStats: {
|
|
964
|
-
anomalies:
|
|
970
|
+
anomalies: s,
|
|
965
971
|
minRtt: Math.min(...i),
|
|
966
|
-
avgRtt:
|
|
972
|
+
avgRtt: xe(i),
|
|
967
973
|
maxRtt: Math.max(...i),
|
|
968
|
-
aggregateReport:
|
|
969
|
-
minJitterDelayInInterval: Math.min(...
|
|
970
|
-
maxJitterDelayInInterval: Math.max(...
|
|
971
|
-
avgJitterDelayInInterval:
|
|
974
|
+
aggregateReport: Jt(e[0], e[e.length - 1], o),
|
|
975
|
+
minJitterDelayInInterval: Math.min(...c),
|
|
976
|
+
maxJitterDelayInInterval: Math.max(...c),
|
|
977
|
+
avgJitterDelayInInterval: xe(c)
|
|
972
978
|
},
|
|
973
979
|
codec: e[0].codec,
|
|
974
980
|
resolution: `${e[0].frameWidth}x${e[0].frameHeight}`
|
|
975
981
|
};
|
|
976
982
|
}
|
|
977
|
-
const Me = 100,
|
|
978
|
-
function
|
|
983
|
+
const Me = 100, Ot = Math.max(Math.ceil(400 / Me), 1), qt = 0.25, Ht = 0.28;
|
|
984
|
+
function Qt() {
|
|
979
985
|
let e = 0, t, a, n = 0;
|
|
980
|
-
return (
|
|
981
|
-
for (const o of
|
|
986
|
+
return (s) => {
|
|
987
|
+
for (const o of s.values())
|
|
982
988
|
if (o && o.type === "inbound-rtp" && o.kind === "video") {
|
|
983
|
-
const
|
|
989
|
+
const c = o.jitterBufferDelay, i = o.jitterBufferEmittedCount;
|
|
984
990
|
if (a && i > a) {
|
|
985
|
-
const
|
|
986
|
-
n =
|
|
991
|
+
const w = c - t, p = i - a;
|
|
992
|
+
n = w / p;
|
|
987
993
|
}
|
|
988
|
-
t =
|
|
994
|
+
t = c, a = i;
|
|
989
995
|
const r = o.framesDecoded, d = r - e > 0;
|
|
990
996
|
return e = r, { isReceiving: d, avgJitterDelayInInterval: n, freezeCount: o.freezeCount };
|
|
991
997
|
}
|
|
992
998
|
return { isReceiving: !1, avgJitterDelayInInterval: n };
|
|
993
999
|
};
|
|
994
1000
|
}
|
|
995
|
-
function
|
|
996
|
-
let o = [],
|
|
997
|
-
const
|
|
1001
|
+
function Xt(e, t, a, n, s) {
|
|
1002
|
+
let o = [], c, i = 0, r = !1, d = re.Unknown, w = re.Unknown, p = 0, u = 0;
|
|
1003
|
+
const P = Qt();
|
|
998
1004
|
return setInterval(async () => {
|
|
999
|
-
const
|
|
1000
|
-
if (
|
|
1001
|
-
i = 0,
|
|
1002
|
-
else if (r && (i++, i >=
|
|
1003
|
-
const
|
|
1004
|
-
n == null || n(C.Stop,
|
|
1005
|
+
const $ = await e.getStats(), { isReceiving: B, avgJitterDelayInInterval: R, freezeCount: M } = P($), z = Wt($);
|
|
1006
|
+
if (B)
|
|
1007
|
+
i = 0, p = M - u, w = R < qt ? re.Strong : R > Ht && p > 1 ? re.Weak : d, w !== d && (s == null || s(w), d = w, u += p, p = 0), r || (n == null || n(C.Start), c = o[o.length - 1], o = [], r = !0), o.push(z);
|
|
1008
|
+
else if (r && (i++, i >= Ot)) {
|
|
1009
|
+
const T = Vt(o, Me, c);
|
|
1010
|
+
n == null || n(C.Stop, T), t() || a(), u = M, r = !1;
|
|
1005
1011
|
}
|
|
1006
1012
|
}, Me);
|
|
1007
1013
|
}
|
|
1008
|
-
const
|
|
1009
|
-
function
|
|
1014
|
+
const Yt = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
|
|
1015
|
+
function Ne(e) {
|
|
1010
1016
|
switch (e) {
|
|
1011
1017
|
case "connected":
|
|
1012
1018
|
return S.Connected;
|
|
@@ -1026,16 +1032,16 @@ function Be(e) {
|
|
|
1026
1032
|
return S.New;
|
|
1027
1033
|
}
|
|
1028
1034
|
}
|
|
1029
|
-
const
|
|
1035
|
+
const Gt = (e) => (t) => {
|
|
1030
1036
|
const [a, n = ""] = t.split(/:(.+)/);
|
|
1031
1037
|
try {
|
|
1032
|
-
const
|
|
1033
|
-
return e("parsed data channel message", { subject: a, data:
|
|
1034
|
-
} catch (
|
|
1035
|
-
return e("Failed to parse data channel message, returning data as string", { subject: a, rawData: n, error:
|
|
1038
|
+
const s = JSON.parse(n);
|
|
1039
|
+
return e("parsed data channel message", { subject: a, data: s }), { subject: a, data: s };
|
|
1040
|
+
} catch (s) {
|
|
1041
|
+
return e("Failed to parse data channel message, returning data as string", { subject: a, rawData: n, error: s }), { subject: a, data: n };
|
|
1036
1042
|
}
|
|
1037
1043
|
};
|
|
1038
|
-
function
|
|
1044
|
+
function Zt({
|
|
1039
1045
|
statsSignal: e,
|
|
1040
1046
|
dataChannelSignal: t,
|
|
1041
1047
|
onVideoStateChange: a,
|
|
@@ -1043,24 +1049,24 @@ function Yt({
|
|
|
1043
1049
|
}) {
|
|
1044
1050
|
e === C.Start && t === C.Start ? a == null || a(C.Start) : e === C.Stop && t === C.Stop && (a == null || a(C.Stop, n));
|
|
1045
1051
|
}
|
|
1046
|
-
function
|
|
1052
|
+
function en({
|
|
1047
1053
|
statsSignal: e,
|
|
1048
1054
|
dataChannelSignal: t,
|
|
1049
1055
|
onVideoStateChange: a,
|
|
1050
1056
|
onAgentActivityStateChange: n,
|
|
1051
|
-
report:
|
|
1057
|
+
report: s
|
|
1052
1058
|
}) {
|
|
1053
|
-
e === C.Start ? a == null || a(C.Start) : e === C.Stop && (a == null || a(C.Stop,
|
|
1059
|
+
e === C.Start ? a == null || a(C.Start) : e === C.Stop && (a == null || a(C.Stop, s)), t === C.Start ? n == null || n(q.Talking) : t === C.Stop && (n == null || n(q.Idle));
|
|
1054
1060
|
}
|
|
1055
|
-
function
|
|
1061
|
+
function ze({
|
|
1056
1062
|
statsSignal: e,
|
|
1057
1063
|
dataChannelSignal: t,
|
|
1058
1064
|
onVideoStateChange: a,
|
|
1059
1065
|
onAgentActivityStateChange: n,
|
|
1060
|
-
streamType:
|
|
1066
|
+
streamType: s,
|
|
1061
1067
|
report: o
|
|
1062
1068
|
}) {
|
|
1063
|
-
|
|
1069
|
+
s === ae.Legacy ? Zt({ statsSignal: e, dataChannelSignal: t, onVideoStateChange: a, report: o }) : s === ae.Fluent && en({
|
|
1064
1070
|
statsSignal: e,
|
|
1065
1071
|
dataChannelSignal: t,
|
|
1066
1072
|
onVideoStateChange: a,
|
|
@@ -1068,205 +1074,205 @@ function Fe({
|
|
|
1068
1074
|
report: o
|
|
1069
1075
|
});
|
|
1070
1076
|
}
|
|
1071
|
-
async function
|
|
1072
|
-
var
|
|
1073
|
-
const r =
|
|
1074
|
-
let
|
|
1075
|
-
const { startConnection:
|
|
1076
|
-
|
|
1077
|
+
async function tn(e, t, { debug: a = !1, callbacks: n, auth: s, baseURL: o = ge, analytics: c }, i) {
|
|
1078
|
+
var V;
|
|
1079
|
+
const r = Qe(a, "WebRTCStreamingManager"), d = Gt(r);
|
|
1080
|
+
let w = !1, p = !1, u = C.Stop, P = C.Stop;
|
|
1081
|
+
const { startConnection: $, sendStreamRequest: B, close: R, createStream: M, addIceCandidate: z } = Kt(
|
|
1082
|
+
s,
|
|
1077
1083
|
o,
|
|
1078
1084
|
e,
|
|
1079
1085
|
n.onError
|
|
1080
1086
|
), {
|
|
1081
|
-
id:
|
|
1087
|
+
id: T,
|
|
1082
1088
|
offer: W,
|
|
1083
1089
|
ice_servers: ee,
|
|
1084
|
-
session_id:
|
|
1090
|
+
session_id: E,
|
|
1085
1091
|
fluent: G,
|
|
1086
1092
|
interrupt_enabled: Z,
|
|
1087
|
-
triggers_enabled:
|
|
1088
|
-
} = await
|
|
1089
|
-
(
|
|
1090
|
-
const y = new
|
|
1091
|
-
if (!
|
|
1093
|
+
triggers_enabled: f
|
|
1094
|
+
} = await M(t, i);
|
|
1095
|
+
(V = n.onStreamCreated) == null || V.call(n, { stream_id: T, session_id: E, agent_id: e });
|
|
1096
|
+
const y = new Yt({ iceServers: ee }), k = y.createDataChannel("JanusDataChannel");
|
|
1097
|
+
if (!E)
|
|
1092
1098
|
throw new Error("Could not create session_id");
|
|
1093
|
-
const
|
|
1094
|
-
|
|
1095
|
-
"stream-type":
|
|
1099
|
+
const _ = G ? ae.Fluent : ae.Legacy;
|
|
1100
|
+
c.enrich({
|
|
1101
|
+
"stream-type": _
|
|
1096
1102
|
});
|
|
1097
|
-
const b = t.stream_warmup && !G,
|
|
1098
|
-
var
|
|
1099
|
-
|
|
1100
|
-
}, H =
|
|
1103
|
+
const b = t.stream_warmup && !G, I = () => w, U = () => {
|
|
1104
|
+
var m;
|
|
1105
|
+
w = !0, p && ((m = n.onConnectionStateChange) == null || m.call(n, S.Connected));
|
|
1106
|
+
}, H = Xt(
|
|
1101
1107
|
y,
|
|
1102
|
-
|
|
1108
|
+
I,
|
|
1103
1109
|
U,
|
|
1104
|
-
(
|
|
1105
|
-
statsSignal:
|
|
1106
|
-
dataChannelSignal:
|
|
1110
|
+
(m, h) => ze({
|
|
1111
|
+
statsSignal: P = m,
|
|
1112
|
+
dataChannelSignal: _ === ae.Legacy ? u : void 0,
|
|
1107
1113
|
onVideoStateChange: n.onVideoStateChange,
|
|
1108
1114
|
onAgentActivityStateChange: n.onAgentActivityStateChange,
|
|
1109
|
-
report:
|
|
1110
|
-
streamType:
|
|
1115
|
+
report: h,
|
|
1116
|
+
streamType: _
|
|
1111
1117
|
}),
|
|
1112
|
-
(
|
|
1113
|
-
var
|
|
1114
|
-
return (
|
|
1118
|
+
(m) => {
|
|
1119
|
+
var h;
|
|
1120
|
+
return (h = n.onConnectivityStateChange) == null ? void 0 : h.call(n, m);
|
|
1115
1121
|
}
|
|
1116
1122
|
);
|
|
1117
|
-
y.onicecandidate = (
|
|
1118
|
-
var
|
|
1119
|
-
r("peerConnection.onicecandidate",
|
|
1123
|
+
y.onicecandidate = (m) => {
|
|
1124
|
+
var h;
|
|
1125
|
+
r("peerConnection.onicecandidate", m);
|
|
1120
1126
|
try {
|
|
1121
|
-
|
|
1122
|
-
|
|
1127
|
+
m.candidate && m.candidate.sdpMid && m.candidate.sdpMLineIndex !== null ? z(
|
|
1128
|
+
T,
|
|
1123
1129
|
{
|
|
1124
|
-
candidate:
|
|
1125
|
-
sdpMid:
|
|
1126
|
-
sdpMLineIndex:
|
|
1130
|
+
candidate: m.candidate.candidate,
|
|
1131
|
+
sdpMid: m.candidate.sdpMid,
|
|
1132
|
+
sdpMLineIndex: m.candidate.sdpMLineIndex
|
|
1127
1133
|
},
|
|
1128
|
-
|
|
1134
|
+
E,
|
|
1129
1135
|
i
|
|
1130
|
-
) : z(
|
|
1131
|
-
} catch (
|
|
1132
|
-
(
|
|
1136
|
+
) : z(T, { candidate: null }, E, i);
|
|
1137
|
+
} catch (F) {
|
|
1138
|
+
(h = n.onError) == null || h.call(n, F, { streamId: T });
|
|
1133
1139
|
}
|
|
1134
1140
|
}, k.onopen = () => {
|
|
1135
|
-
|
|
1141
|
+
p = !0, (!b || w) && U();
|
|
1136
1142
|
};
|
|
1137
|
-
const Q = (
|
|
1138
|
-
var
|
|
1139
|
-
(
|
|
1143
|
+
const Q = (m) => {
|
|
1144
|
+
var h;
|
|
1145
|
+
(h = n.onVideoIdChange) == null || h.call(n, m);
|
|
1140
1146
|
};
|
|
1141
|
-
function
|
|
1142
|
-
if (
|
|
1143
|
-
const
|
|
1144
|
-
Q(
|
|
1147
|
+
function L(m, h) {
|
|
1148
|
+
if (m === j.StreamStarted && typeof h == "object" && "metadata" in h) {
|
|
1149
|
+
const F = h.metadata;
|
|
1150
|
+
Q(F.videoId);
|
|
1145
1151
|
}
|
|
1146
|
-
|
|
1147
|
-
statsSignal:
|
|
1152
|
+
m === j.StreamDone && Q(null), u = m === j.StreamStarted ? C.Start : C.Stop, ze({
|
|
1153
|
+
statsSignal: _ === ae.Legacy ? P : void 0,
|
|
1148
1154
|
dataChannelSignal: u,
|
|
1149
1155
|
onVideoStateChange: n.onVideoStateChange,
|
|
1150
1156
|
onAgentActivityStateChange: n.onAgentActivityStateChange,
|
|
1151
|
-
streamType:
|
|
1157
|
+
streamType: _
|
|
1152
1158
|
});
|
|
1153
1159
|
}
|
|
1154
|
-
function
|
|
1155
|
-
var
|
|
1156
|
-
const
|
|
1157
|
-
|
|
1160
|
+
function K(m, h) {
|
|
1161
|
+
var J;
|
|
1162
|
+
const F = typeof h == "string" ? h : h == null ? void 0 : h.metadata;
|
|
1163
|
+
F && c.enrich({ streamMetadata: F }), (J = n.onStreamReady) == null || J.call(n);
|
|
1158
1164
|
}
|
|
1159
1165
|
const X = {
|
|
1160
|
-
[
|
|
1161
|
-
[
|
|
1162
|
-
[
|
|
1166
|
+
[j.StreamStarted]: L,
|
|
1167
|
+
[j.StreamDone]: L,
|
|
1168
|
+
[j.StreamReady]: K
|
|
1163
1169
|
};
|
|
1164
|
-
k.onmessage = (
|
|
1165
|
-
var
|
|
1166
|
-
const { subject:
|
|
1167
|
-
(
|
|
1170
|
+
k.onmessage = (m) => {
|
|
1171
|
+
var J;
|
|
1172
|
+
const { subject: h, data: F } = d(m.data);
|
|
1173
|
+
(J = X[h]) == null || J.call(X, h, F);
|
|
1168
1174
|
}, y.oniceconnectionstatechange = () => {
|
|
1169
|
-
var
|
|
1175
|
+
var h;
|
|
1170
1176
|
r("peerConnection.oniceconnectionstatechange => " + y.iceConnectionState);
|
|
1171
|
-
const
|
|
1172
|
-
|
|
1173
|
-
}, y.ontrack = (
|
|
1174
|
-
var
|
|
1175
|
-
r("peerConnection.ontrack",
|
|
1177
|
+
const m = Ne(y.iceConnectionState);
|
|
1178
|
+
m !== S.Connected && ((h = n.onConnectionStateChange) == null || h.call(n, m));
|
|
1179
|
+
}, y.ontrack = (m) => {
|
|
1180
|
+
var h;
|
|
1181
|
+
r("peerConnection.ontrack", m), (h = n.onSrcObjectReady) == null || h.call(n, m.streams[0]);
|
|
1176
1182
|
}, await y.setRemoteDescription(W), r("set remote description OK");
|
|
1177
|
-
const
|
|
1178
|
-
return r("create answer OK"), await y.setLocalDescription(
|
|
1183
|
+
const oe = await y.createAnswer();
|
|
1184
|
+
return r("create answer OK"), await y.setLocalDescription(oe), r("set local description OK"), await $(T, oe, E, i), r("start connection OK"), {
|
|
1179
1185
|
/**
|
|
1180
1186
|
* Method to send request to server to get clip or talk depend on you payload
|
|
1181
1187
|
* @param payload
|
|
1182
1188
|
*/
|
|
1183
|
-
speak(
|
|
1184
|
-
return
|
|
1189
|
+
speak(m) {
|
|
1190
|
+
return B(T, E, m);
|
|
1185
1191
|
},
|
|
1186
1192
|
/**
|
|
1187
1193
|
* Method to close RTC connection
|
|
1188
1194
|
*/
|
|
1189
1195
|
async disconnect() {
|
|
1190
|
-
var
|
|
1191
|
-
if (
|
|
1192
|
-
const
|
|
1196
|
+
var m;
|
|
1197
|
+
if (T) {
|
|
1198
|
+
const h = Ne(y.iceConnectionState);
|
|
1193
1199
|
if (y) {
|
|
1194
|
-
if (
|
|
1200
|
+
if (h === S.New) {
|
|
1195
1201
|
clearInterval(H);
|
|
1196
1202
|
return;
|
|
1197
1203
|
}
|
|
1198
1204
|
y.close(), y.oniceconnectionstatechange = null, y.onnegotiationneeded = null, y.onicecandidate = null, y.ontrack = null;
|
|
1199
1205
|
}
|
|
1200
1206
|
try {
|
|
1201
|
-
|
|
1207
|
+
h === S.Connected && await R(T, E).catch((F) => {
|
|
1202
1208
|
});
|
|
1203
|
-
} catch (
|
|
1204
|
-
r("Error on close stream connection",
|
|
1209
|
+
} catch (F) {
|
|
1210
|
+
r("Error on close stream connection", F);
|
|
1205
1211
|
}
|
|
1206
|
-
(
|
|
1212
|
+
(m = n.onAgentActivityStateChange) == null || m.call(n, q.Idle), clearInterval(H);
|
|
1207
1213
|
}
|
|
1208
1214
|
},
|
|
1209
1215
|
/**
|
|
1210
1216
|
* Method to send data channel messages to the server
|
|
1211
1217
|
*/
|
|
1212
|
-
sendDataChannelMessage(
|
|
1213
|
-
var
|
|
1214
|
-
if (!
|
|
1215
|
-
r("Data channel is not ready for sending messages"), (
|
|
1216
|
-
streamId:
|
|
1218
|
+
sendDataChannelMessage(m) {
|
|
1219
|
+
var h, F;
|
|
1220
|
+
if (!w || k.readyState !== "open") {
|
|
1221
|
+
r("Data channel is not ready for sending messages"), (h = n.onError) == null || h.call(n, new Error("Data channel is not ready for sending messages"), {
|
|
1222
|
+
streamId: T
|
|
1217
1223
|
});
|
|
1218
1224
|
return;
|
|
1219
1225
|
}
|
|
1220
1226
|
try {
|
|
1221
|
-
k.send(
|
|
1222
|
-
} catch (
|
|
1223
|
-
r("Error sending data channel message",
|
|
1227
|
+
k.send(m);
|
|
1228
|
+
} catch (J) {
|
|
1229
|
+
r("Error sending data channel message", J), (F = n.onError) == null || F.call(n, J, { streamId: T });
|
|
1224
1230
|
}
|
|
1225
1231
|
},
|
|
1226
1232
|
/**
|
|
1227
1233
|
* Session identifier information, should be returned in the body of all streaming requests
|
|
1228
1234
|
*/
|
|
1229
|
-
sessionId:
|
|
1235
|
+
sessionId: E,
|
|
1230
1236
|
/**
|
|
1231
1237
|
* Id of current RTC stream
|
|
1232
1238
|
*/
|
|
1233
|
-
streamId:
|
|
1234
|
-
streamType:
|
|
1239
|
+
streamId: T,
|
|
1240
|
+
streamType: _,
|
|
1235
1241
|
interruptAvailable: Z ?? !1,
|
|
1236
|
-
triggersAvailable:
|
|
1242
|
+
triggersAvailable: f ?? !1
|
|
1237
1243
|
};
|
|
1238
1244
|
}
|
|
1239
1245
|
var Ee = /* @__PURE__ */ ((e) => (e.V1 = "v1", e.V2 = "v2", e))(Ee || {});
|
|
1240
|
-
async function
|
|
1241
|
-
const
|
|
1246
|
+
async function nn(e, t, a, n) {
|
|
1247
|
+
const s = e.id;
|
|
1242
1248
|
switch (t.version) {
|
|
1243
1249
|
case "v1": {
|
|
1244
|
-
const { version: o, ...
|
|
1245
|
-
return
|
|
1250
|
+
const { version: o, ...c } = t;
|
|
1251
|
+
return tn(s, c, a, n);
|
|
1246
1252
|
}
|
|
1247
1253
|
case "v2": {
|
|
1248
|
-
const { version: o, ...
|
|
1249
|
-
switch (
|
|
1254
|
+
const { version: o, ...c } = t;
|
|
1255
|
+
switch (c.transport_provider) {
|
|
1250
1256
|
case ye.Livekit:
|
|
1251
|
-
const { createLiveKitStreamingManager: i } = await Promise.resolve().then(() =>
|
|
1252
|
-
return i(
|
|
1257
|
+
const { createLiveKitStreamingManager: i } = await Promise.resolve().then(() => At);
|
|
1258
|
+
return i(s, c, a);
|
|
1253
1259
|
default:
|
|
1254
|
-
throw new Error(`Unsupported transport provider: ${
|
|
1260
|
+
throw new Error(`Unsupported transport provider: ${c.transport_provider}`);
|
|
1255
1261
|
}
|
|
1256
1262
|
}
|
|
1257
1263
|
default:
|
|
1258
1264
|
throw new Error(`Invalid stream version: ${t.version}`);
|
|
1259
1265
|
}
|
|
1260
1266
|
}
|
|
1261
|
-
const
|
|
1262
|
-
function
|
|
1267
|
+
const rn = "cht";
|
|
1268
|
+
function an() {
|
|
1263
1269
|
return {
|
|
1264
1270
|
transport_provider: ye.Livekit
|
|
1265
1271
|
};
|
|
1266
1272
|
}
|
|
1267
|
-
function
|
|
1268
|
-
var
|
|
1269
|
-
const { streamOptions: t } = e ?? {}, a = ((
|
|
1273
|
+
function on(e) {
|
|
1274
|
+
var s, o;
|
|
1275
|
+
const { streamOptions: t } = e ?? {}, a = ((s = e == null ? void 0 : e.mixpanelAdditionalProperties) == null ? void 0 : s.plan) !== void 0 ? {
|
|
1270
1276
|
plan: (o = e.mixpanelAdditionalProperties) == null ? void 0 : o.plan
|
|
1271
1277
|
} : void 0;
|
|
1272
1278
|
return { ...{
|
|
@@ -1277,27 +1283,27 @@ function rn(e) {
|
|
|
1277
1283
|
fluent: t == null ? void 0 : t.fluent
|
|
1278
1284
|
}, ...a && { end_user_data: a } };
|
|
1279
1285
|
}
|
|
1280
|
-
function
|
|
1281
|
-
return Ie(e.presenter.type) ? { version: Ee.V2, ...
|
|
1286
|
+
function sn(e, t) {
|
|
1287
|
+
return Ie(e.presenter.type) ? { version: Ee.V2, ...an() } : { version: Ee.V1, ...on(t) };
|
|
1282
1288
|
}
|
|
1283
|
-
function
|
|
1284
|
-
|
|
1289
|
+
function cn(e, t, a, n, s) {
|
|
1290
|
+
s === ae.Fluent ? dn(e, t, a, n, s) : ln(e, t, a, n, s);
|
|
1285
1291
|
}
|
|
1286
|
-
function
|
|
1287
|
-
e === C.Start ? n.track("stream-session", { event: "start", "stream-type":
|
|
1292
|
+
function dn(e, t, a, n, s) {
|
|
1293
|
+
e === C.Start ? n.track("stream-session", { event: "start", "stream-type": s }) : e === C.Stop && n.track("stream-session", {
|
|
1288
1294
|
event: "stop",
|
|
1289
1295
|
is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
|
|
1290
1296
|
background: t.presenter.type === "clip" && t.presenter.background,
|
|
1291
|
-
"stream-type":
|
|
1297
|
+
"stream-type": s,
|
|
1292
1298
|
...a
|
|
1293
1299
|
});
|
|
1294
1300
|
}
|
|
1295
|
-
function
|
|
1301
|
+
function un(e, t, a, n) {
|
|
1296
1302
|
ie.get() <= 0 || (e === C.Start ? a.linkTrack(
|
|
1297
1303
|
"agent-video",
|
|
1298
1304
|
{ event: "start", latency: ie.get(!0), "stream-type": n },
|
|
1299
1305
|
"start",
|
|
1300
|
-
[
|
|
1306
|
+
[j.StreamVideoCreated]
|
|
1301
1307
|
) : e === C.Stop && a.linkTrack(
|
|
1302
1308
|
"agent-video",
|
|
1303
1309
|
{
|
|
@@ -1307,36 +1313,36 @@ function cn(e, t, a, n) {
|
|
|
1307
1313
|
"stream-type": n
|
|
1308
1314
|
},
|
|
1309
1315
|
"done",
|
|
1310
|
-
[
|
|
1316
|
+
[j.StreamVideoDone]
|
|
1311
1317
|
));
|
|
1312
1318
|
}
|
|
1313
|
-
function
|
|
1319
|
+
function ln(e, t, a, n, s) {
|
|
1314
1320
|
ie.get() <= 0 || (e === C.Start ? n.linkTrack(
|
|
1315
1321
|
"agent-video",
|
|
1316
|
-
{ event: "start", latency: ie.get(!0), "stream-type":
|
|
1322
|
+
{ event: "start", latency: ie.get(!0), "stream-type": s },
|
|
1317
1323
|
"start",
|
|
1318
|
-
[
|
|
1324
|
+
[j.StreamVideoCreated]
|
|
1319
1325
|
) : e === C.Stop && n.linkTrack(
|
|
1320
1326
|
"agent-video",
|
|
1321
1327
|
{
|
|
1322
1328
|
event: "stop",
|
|
1323
1329
|
is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
|
|
1324
1330
|
background: t.presenter.type === "clip" && t.presenter.background,
|
|
1325
|
-
"stream-type":
|
|
1331
|
+
"stream-type": s,
|
|
1326
1332
|
...a
|
|
1327
1333
|
},
|
|
1328
1334
|
"done",
|
|
1329
|
-
[
|
|
1335
|
+
[j.StreamVideoDone]
|
|
1330
1336
|
));
|
|
1331
1337
|
}
|
|
1332
|
-
function
|
|
1333
|
-
return ie.reset(),
|
|
1338
|
+
function Ke(e, t, a, n) {
|
|
1339
|
+
return ie.reset(), Fe.update(), new Promise(async (s, o) => {
|
|
1334
1340
|
try {
|
|
1335
|
-
let
|
|
1336
|
-
const r =
|
|
1341
|
+
let c, i = !1;
|
|
1342
|
+
const r = sn(e, t);
|
|
1337
1343
|
a.enrich({
|
|
1338
1344
|
"stream-version": r.version.toString()
|
|
1339
|
-
}),
|
|
1345
|
+
}), c = await nn(
|
|
1340
1346
|
e,
|
|
1341
1347
|
r,
|
|
1342
1348
|
{
|
|
@@ -1345,212 +1351,212 @@ function ze(e, t, a, n) {
|
|
|
1345
1351
|
callbacks: {
|
|
1346
1352
|
...t.callbacks,
|
|
1347
1353
|
onConnectionStateChange: (d) => {
|
|
1348
|
-
var
|
|
1349
|
-
(
|
|
1354
|
+
var w, p;
|
|
1355
|
+
(p = (w = t.callbacks).onConnectionStateChange) == null || p.call(w, d), d === S.Connected && (c ? s(c) : i = !0);
|
|
1350
1356
|
},
|
|
1351
|
-
onVideoStateChange: (d,
|
|
1352
|
-
var
|
|
1353
|
-
(u = (
|
|
1357
|
+
onVideoStateChange: (d, w) => {
|
|
1358
|
+
var p, u;
|
|
1359
|
+
(u = (p = t.callbacks).onVideoStateChange) == null || u.call(p, d), cn(
|
|
1354
1360
|
d,
|
|
1355
1361
|
e,
|
|
1356
|
-
|
|
1362
|
+
w,
|
|
1357
1363
|
a,
|
|
1358
|
-
|
|
1364
|
+
c.streamType
|
|
1359
1365
|
);
|
|
1360
1366
|
},
|
|
1361
1367
|
onAgentActivityStateChange: (d) => {
|
|
1362
|
-
var
|
|
1363
|
-
(
|
|
1364
|
-
d ===
|
|
1368
|
+
var w, p;
|
|
1369
|
+
(p = (w = t.callbacks).onAgentActivityStateChange) == null || p.call(w, d), d === q.Talking ? Re.update() : Re.reset(), un(
|
|
1370
|
+
d === q.Talking ? C.Start : C.Stop,
|
|
1365
1371
|
e,
|
|
1366
1372
|
a,
|
|
1367
|
-
|
|
1373
|
+
c.streamType
|
|
1368
1374
|
);
|
|
1369
1375
|
},
|
|
1370
1376
|
onStreamReady: () => {
|
|
1371
|
-
const d =
|
|
1377
|
+
const d = Fe.get(!0);
|
|
1372
1378
|
a.track("agent-chat", { event: "ready", latency: d });
|
|
1373
1379
|
}
|
|
1374
1380
|
}
|
|
1375
1381
|
},
|
|
1376
1382
|
n
|
|
1377
|
-
), i && c
|
|
1378
|
-
} catch (
|
|
1379
|
-
o(
|
|
1383
|
+
), i && s(c);
|
|
1384
|
+
} catch (c) {
|
|
1385
|
+
o(c);
|
|
1380
1386
|
}
|
|
1381
1387
|
});
|
|
1382
1388
|
}
|
|
1383
|
-
async function
|
|
1384
|
-
var
|
|
1389
|
+
async function fn(e, t, a, n, s) {
|
|
1390
|
+
var w, p, u, P;
|
|
1385
1391
|
const o = async () => {
|
|
1386
1392
|
if (Ie(e.presenter.type)) {
|
|
1387
|
-
const
|
|
1393
|
+
const $ = await Ke(e, t, n), B = `${rn}_${$.sessionId}`, R = (/* @__PURE__ */ new Date()).toISOString();
|
|
1388
1394
|
return { chatResult: {
|
|
1389
|
-
chatMode:
|
|
1395
|
+
chatMode: N.Functional,
|
|
1390
1396
|
chat: {
|
|
1391
|
-
id:
|
|
1397
|
+
id: B,
|
|
1392
1398
|
agent_id: e.id,
|
|
1393
1399
|
owner_id: e.owner_id ?? "",
|
|
1394
|
-
created:
|
|
1395
|
-
modified:
|
|
1396
|
-
agent_id__created_at:
|
|
1397
|
-
agent_id__modified_at:
|
|
1398
|
-
chat_mode:
|
|
1400
|
+
created: R,
|
|
1401
|
+
modified: R,
|
|
1402
|
+
agent_id__created_at: R,
|
|
1403
|
+
agent_id__modified_at: R,
|
|
1404
|
+
chat_mode: N.Functional,
|
|
1399
1405
|
messages: []
|
|
1400
1406
|
}
|
|
1401
|
-
}, streamingManager:
|
|
1407
|
+
}, streamingManager: $ };
|
|
1402
1408
|
} else {
|
|
1403
|
-
const
|
|
1404
|
-
let
|
|
1409
|
+
const $ = new AbortController(), B = $.signal;
|
|
1410
|
+
let R;
|
|
1405
1411
|
try {
|
|
1406
|
-
const
|
|
1412
|
+
const M = He(
|
|
1407
1413
|
e,
|
|
1408
1414
|
a,
|
|
1409
1415
|
n,
|
|
1410
1416
|
t.mode,
|
|
1411
1417
|
t.persistentChat,
|
|
1412
|
-
|
|
1413
|
-
), z =
|
|
1414
|
-
return { chatResult:
|
|
1415
|
-
} catch (
|
|
1416
|
-
throw
|
|
1417
|
-
}),
|
|
1418
|
+
s
|
|
1419
|
+
), z = Ke(e, t, n, B).then((ee) => (R = ee, ee)), [T, W] = await Promise.all([M, z]);
|
|
1420
|
+
return { chatResult: T, streamingManager: W };
|
|
1421
|
+
} catch (M) {
|
|
1422
|
+
throw $.abort(), R && await R.disconnect().catch(() => {
|
|
1423
|
+
}), M;
|
|
1418
1424
|
}
|
|
1419
1425
|
}
|
|
1420
|
-
}, { chatResult:
|
|
1421
|
-
return d && t.mode !== void 0 && d !== t.mode && (t.mode = d, (
|
|
1426
|
+
}, { chatResult: c, streamingManager: i } = await o(), { chat: r, chatMode: d } = c;
|
|
1427
|
+
return d && t.mode !== void 0 && d !== t.mode && (t.mode = d, (p = (w = t.callbacks).onModeChange) == null || p.call(w, d), d !== N.Functional) ? ((P = (u = t.callbacks).onError) == null || P.call(u, new Ze(d)), i == null || i.disconnect(), { chat: r }) : { chat: r, streamingManager: i };
|
|
1422
1428
|
}
|
|
1423
|
-
async function
|
|
1424
|
-
var
|
|
1429
|
+
async function hn(e, t) {
|
|
1430
|
+
var E, G, Z;
|
|
1425
1431
|
let a = !0, n = null;
|
|
1426
|
-
const
|
|
1432
|
+
const s = t.mixpanelKey || mt, o = t.wsURL || ft, c = t.baseURL || ge, i = t.mode || N.Functional, r = {
|
|
1427
1433
|
messages: [],
|
|
1428
1434
|
chatMode: i
|
|
1429
|
-
}, d =
|
|
1430
|
-
token:
|
|
1435
|
+
}, d = Dt({
|
|
1436
|
+
token: s,
|
|
1431
1437
|
agentId: e,
|
|
1432
1438
|
isEnabled: t.enableAnalitics,
|
|
1433
1439
|
externalId: t.externalId,
|
|
1434
1440
|
mixpanelAdditionalProperties: t.mixpanelAdditionalProperties
|
|
1435
|
-
}),
|
|
1436
|
-
|
|
1437
|
-
d.track("agent-sdk", { event: "init" },
|
|
1441
|
+
}), w = Date.now();
|
|
1442
|
+
Be(() => {
|
|
1443
|
+
d.track("agent-sdk", { event: "init" }, w);
|
|
1438
1444
|
});
|
|
1439
|
-
const
|
|
1440
|
-
d.enrich(
|
|
1441
|
-
const { onMessage:
|
|
1445
|
+
const p = yt(t.auth, c, t.callbacks.onError, t.externalId), u = await p.getById(e), P = Ie(u.presenter.type);
|
|
1446
|
+
d.enrich(St(u));
|
|
1447
|
+
const { onMessage: $, clearQueue: B } = zt(
|
|
1442
1448
|
d,
|
|
1443
1449
|
r,
|
|
1444
1450
|
t,
|
|
1445
1451
|
u,
|
|
1446
1452
|
() => {
|
|
1447
|
-
var
|
|
1448
|
-
return (
|
|
1453
|
+
var f;
|
|
1454
|
+
return (f = r.socketManager) == null ? void 0 : f.disconnect();
|
|
1449
1455
|
}
|
|
1450
1456
|
);
|
|
1451
|
-
r.messages =
|
|
1452
|
-
const
|
|
1453
|
-
n =
|
|
1454
|
-
},
|
|
1455
|
-
var k,
|
|
1457
|
+
r.messages = Et(t.initialMessages), (G = (E = t.callbacks).onNewMessage) == null || G.call(E, [...r.messages], "answer");
|
|
1458
|
+
const R = (f) => {
|
|
1459
|
+
n = f;
|
|
1460
|
+
}, M = ({ type: f }) => {
|
|
1461
|
+
var k, _, b;
|
|
1456
1462
|
const y = r.messages[r.messages.length - 1];
|
|
1457
1463
|
d.track("agent-video-interrupt", {
|
|
1458
|
-
type:
|
|
1464
|
+
type: f || "click",
|
|
1459
1465
|
video_duration_to_interrupt: Re.get(!0),
|
|
1460
1466
|
message_duration_to_interrupt: ie.get(!0)
|
|
1461
|
-
}), y.interrupted = !0, (
|
|
1467
|
+
}), y.interrupted = !0, (_ = (k = t.callbacks).onNewMessage) == null || _.call(k, [...r.messages], "answer"), P ? Lt(r.streamingManager) : (Pt(r.streamingManager, (b = r.streamingManager) == null ? void 0 : b.streamType, n), bt(r.streamingManager, n));
|
|
1462
1468
|
}, z = Date.now();
|
|
1463
|
-
|
|
1464
|
-
d.track("agent-sdk", { event: "loaded", ...
|
|
1469
|
+
Be(() => {
|
|
1470
|
+
d.track("agent-sdk", { event: "loaded", ...vt(u) }, z);
|
|
1465
1471
|
});
|
|
1466
|
-
async function
|
|
1467
|
-
var U, H, Q,
|
|
1468
|
-
(H = (U = t.callbacks).onConnectionStateChange) == null || H.call(U, S.Connecting), ie.reset(),
|
|
1469
|
-
const y = i ===
|
|
1472
|
+
async function T(f) {
|
|
1473
|
+
var U, H, Q, L, K, X, oe;
|
|
1474
|
+
(H = (U = t.callbacks).onConnectionStateChange) == null || H.call(U, S.Connecting), ie.reset(), f && !a && (delete r.chat, (L = (Q = t.callbacks).onNewMessage) == null || L.call(Q, [...r.messages], "answer"));
|
|
1475
|
+
const y = i === N.DirectPlayback || P ? Promise.resolve(void 0) : xt(
|
|
1470
1476
|
t.auth,
|
|
1471
1477
|
o,
|
|
1472
|
-
{ onMessage:
|
|
1478
|
+
{ onMessage: $, onError: t.callbacks.onError },
|
|
1473
1479
|
t.externalId
|
|
1474
1480
|
), k = Ce(
|
|
1475
|
-
() =>
|
|
1481
|
+
() => fn(
|
|
1476
1482
|
u,
|
|
1477
1483
|
{
|
|
1478
1484
|
...t,
|
|
1479
1485
|
mode: i,
|
|
1480
1486
|
callbacks: {
|
|
1481
1487
|
...t.callbacks,
|
|
1482
|
-
onVideoIdChange:
|
|
1483
|
-
onMessage:
|
|
1484
|
-
onInterruptDetected:
|
|
1488
|
+
onVideoIdChange: R,
|
|
1489
|
+
onMessage: $,
|
|
1490
|
+
onInterruptDetected: M
|
|
1485
1491
|
}
|
|
1486
1492
|
},
|
|
1487
|
-
|
|
1493
|
+
p,
|
|
1488
1494
|
d,
|
|
1489
1495
|
r.chat
|
|
1490
1496
|
),
|
|
1491
1497
|
{
|
|
1492
1498
|
limit: 3,
|
|
1493
|
-
timeout:
|
|
1499
|
+
timeout: ut,
|
|
1494
1500
|
timeoutErrorMessage: "Timeout initializing the stream",
|
|
1495
|
-
shouldRetryFn: (
|
|
1501
|
+
shouldRetryFn: (V) => (V == null ? void 0 : V.message) !== "Could not connect" && V.status !== 429 && (V == null ? void 0 : V.message) !== "InsufficientCreditsError",
|
|
1496
1502
|
delayMs: 1e3
|
|
1497
1503
|
}
|
|
1498
|
-
).catch((
|
|
1499
|
-
var
|
|
1500
|
-
throw ee(
|
|
1501
|
-
}), [
|
|
1502
|
-
|
|
1503
|
-
chatId:
|
|
1504
|
+
).catch((V) => {
|
|
1505
|
+
var m, h;
|
|
1506
|
+
throw ee(N.Maintenance), (h = (m = t.callbacks).onConnectionStateChange) == null || h.call(m, S.Fail), V;
|
|
1507
|
+
}), [_, { streamingManager: b, chat: I }] = await Promise.all([y, k]);
|
|
1508
|
+
I && I.id !== ((K = r.chat) == null ? void 0 : K.id) && ((oe = (X = t.callbacks).onNewChat) == null || oe.call(X, I.id)), r.streamingManager = b, r.socketManager = _, r.chat = I, a = !1, d.enrich({
|
|
1509
|
+
chatId: I == null ? void 0 : I.id,
|
|
1504
1510
|
streamId: b == null ? void 0 : b.streamId,
|
|
1505
1511
|
mode: r.chatMode
|
|
1506
|
-
}), ee((
|
|
1512
|
+
}), ee((I == null ? void 0 : I.chat_mode) ?? i);
|
|
1507
1513
|
}
|
|
1508
1514
|
async function W() {
|
|
1509
|
-
var
|
|
1510
|
-
(
|
|
1515
|
+
var f, y, k, _;
|
|
1516
|
+
(f = r.socketManager) == null || f.disconnect(), await ((y = r.streamingManager) == null ? void 0 : y.disconnect()), delete r.streamingManager, delete r.socketManager, (_ = (k = t.callbacks).onConnectionStateChange) == null || _.call(k, S.Disconnected);
|
|
1511
1517
|
}
|
|
1512
|
-
async function ee(
|
|
1518
|
+
async function ee(f) {
|
|
1513
1519
|
var y, k;
|
|
1514
|
-
|
|
1520
|
+
f !== r.chatMode && (d.track("agent-mode-change", { mode: f }), r.chatMode = f, r.chatMode !== N.Functional && await W(), (k = (y = t.callbacks).onModeChange) == null || k.call(y, f));
|
|
1515
1521
|
}
|
|
1516
1522
|
return {
|
|
1517
1523
|
agent: u,
|
|
1518
1524
|
getStreamType: () => {
|
|
1519
|
-
var
|
|
1520
|
-
return (
|
|
1525
|
+
var f;
|
|
1526
|
+
return (f = r.streamingManager) == null ? void 0 : f.streamType;
|
|
1521
1527
|
},
|
|
1522
1528
|
getIsInterruptAvailable: () => {
|
|
1523
|
-
var
|
|
1524
|
-
return ((
|
|
1529
|
+
var f;
|
|
1530
|
+
return ((f = r.streamingManager) == null ? void 0 : f.interruptAvailable) ?? !1;
|
|
1525
1531
|
},
|
|
1526
1532
|
getIsTriggersAvailable: () => {
|
|
1527
|
-
var
|
|
1528
|
-
return ((
|
|
1533
|
+
var f;
|
|
1534
|
+
return ((f = r.streamingManager) == null ? void 0 : f.triggersAvailable) ?? !1;
|
|
1529
1535
|
},
|
|
1530
1536
|
starterMessages: ((Z = u.knowledge) == null ? void 0 : Z.starter_message) || [],
|
|
1531
|
-
getSTTToken: () =>
|
|
1537
|
+
getSTTToken: () => p.getSTTToken(u.id),
|
|
1532
1538
|
changeMode: ee,
|
|
1533
1539
|
enrichAnalytics: d.enrich,
|
|
1534
1540
|
async connect() {
|
|
1535
|
-
await
|
|
1541
|
+
await T(!0), d.track("agent-chat", {
|
|
1536
1542
|
event: "connect",
|
|
1537
1543
|
mode: r.chatMode
|
|
1538
1544
|
});
|
|
1539
1545
|
},
|
|
1540
1546
|
async reconnect() {
|
|
1541
|
-
const
|
|
1542
|
-
if (
|
|
1547
|
+
const f = r.streamingManager;
|
|
1548
|
+
if (P && (f != null && f.reconnect)) {
|
|
1543
1549
|
try {
|
|
1544
|
-
await
|
|
1550
|
+
await f.reconnect(), d.track("agent-chat", {
|
|
1545
1551
|
event: "reconnect",
|
|
1546
1552
|
mode: r.chatMode
|
|
1547
1553
|
});
|
|
1548
1554
|
} catch {
|
|
1549
|
-
await W(), await
|
|
1555
|
+
await W(), await T(!1);
|
|
1550
1556
|
}
|
|
1551
1557
|
return;
|
|
1552
1558
|
}
|
|
1553
|
-
await W(), await
|
|
1559
|
+
await W(), await T(!1), d.track("agent-chat", {
|
|
1554
1560
|
event: "reconnect",
|
|
1555
1561
|
mode: r.chatMode
|
|
1556
1562
|
});
|
|
@@ -1561,167 +1567,167 @@ async function mn(e, t) {
|
|
|
1561
1567
|
mode: r.chatMode
|
|
1562
1568
|
});
|
|
1563
1569
|
},
|
|
1564
|
-
async publishMicrophoneStream(
|
|
1570
|
+
async publishMicrophoneStream(f) {
|
|
1565
1571
|
var y;
|
|
1566
1572
|
if (!((y = r.streamingManager) != null && y.publishMicrophoneStream))
|
|
1567
1573
|
throw new Error("publishMicrophoneStream is not available for this streaming manager");
|
|
1568
|
-
return r.streamingManager.publishMicrophoneStream(
|
|
1574
|
+
return r.streamingManager.publishMicrophoneStream(f);
|
|
1569
1575
|
},
|
|
1570
1576
|
async unpublishMicrophoneStream() {
|
|
1571
|
-
var
|
|
1572
|
-
if (!((
|
|
1577
|
+
var f;
|
|
1578
|
+
if (!((f = r.streamingManager) != null && f.unpublishMicrophoneStream))
|
|
1573
1579
|
throw new Error("unpublishMicrophoneStream is not available for this streaming manager");
|
|
1574
1580
|
return r.streamingManager.unpublishMicrophoneStream();
|
|
1575
1581
|
},
|
|
1576
|
-
async chat(
|
|
1577
|
-
var b,
|
|
1582
|
+
async chat(f) {
|
|
1583
|
+
var b, I, U, H, Q;
|
|
1578
1584
|
const y = () => {
|
|
1579
|
-
if (
|
|
1585
|
+
if (Ve(i))
|
|
1580
1586
|
throw new de(`${i} is enabled, chat is disabled`);
|
|
1581
|
-
if (
|
|
1587
|
+
if (f.length >= 800)
|
|
1582
1588
|
throw new de("Message cannot be more than 800 characters");
|
|
1583
|
-
if (
|
|
1589
|
+
if (f.length === 0)
|
|
1584
1590
|
throw new de("Message cannot be empty");
|
|
1585
|
-
if (r.chatMode ===
|
|
1591
|
+
if (r.chatMode === N.Maintenance)
|
|
1586
1592
|
throw new de("Chat is in maintenance mode");
|
|
1587
|
-
if (![
|
|
1593
|
+
if (![N.TextOnly, N.Playground].includes(r.chatMode)) {
|
|
1588
1594
|
if (!r.streamingManager)
|
|
1589
1595
|
throw new de("Streaming manager is not initialized");
|
|
1590
1596
|
if (!r.chat)
|
|
1591
1597
|
throw new de("Chat is not initialized");
|
|
1592
1598
|
}
|
|
1593
1599
|
}, k = async () => {
|
|
1594
|
-
var
|
|
1600
|
+
var L, K;
|
|
1595
1601
|
if (!r.chat) {
|
|
1596
|
-
const X = await
|
|
1602
|
+
const X = await He(
|
|
1597
1603
|
u,
|
|
1598
|
-
|
|
1604
|
+
p,
|
|
1599
1605
|
d,
|
|
1600
1606
|
r.chatMode,
|
|
1601
1607
|
t.persistentChat
|
|
1602
1608
|
);
|
|
1603
1609
|
if (!X.chat)
|
|
1604
|
-
throw new
|
|
1605
|
-
r.chat = X.chat, (
|
|
1610
|
+
throw new Ge(r.chatMode, !!t.persistentChat);
|
|
1611
|
+
r.chat = X.chat, (K = (L = t.callbacks).onNewChat) == null || K.call(L, r.chat.id);
|
|
1606
1612
|
}
|
|
1607
1613
|
return r.chat.id;
|
|
1608
|
-
},
|
|
1609
|
-
const X = r.chatMode ===
|
|
1610
|
-
return Ce(
|
|
1611
|
-
var
|
|
1612
|
-
return await ((
|
|
1614
|
+
}, _ = async (L, K) => {
|
|
1615
|
+
const X = r.chatMode === N.Playground;
|
|
1616
|
+
return Ce(P && !X ? async () => {
|
|
1617
|
+
var m, h;
|
|
1618
|
+
return await ((h = (m = r.streamingManager) == null ? void 0 : m.sendTextMessage) == null ? void 0 : h.call(m, f)), Promise.resolve({});
|
|
1613
1619
|
} : async () => {
|
|
1614
|
-
var
|
|
1615
|
-
return
|
|
1620
|
+
var m, h;
|
|
1621
|
+
return p.chat(
|
|
1616
1622
|
u.id,
|
|
1617
|
-
|
|
1623
|
+
K,
|
|
1618
1624
|
{
|
|
1619
1625
|
chatMode: r.chatMode,
|
|
1620
|
-
streamId: (
|
|
1621
|
-
sessionId: (
|
|
1622
|
-
messages:
|
|
1626
|
+
streamId: (m = r.streamingManager) == null ? void 0 : m.streamId,
|
|
1627
|
+
sessionId: (h = r.streamingManager) == null ? void 0 : h.sessionId,
|
|
1628
|
+
messages: L.map(({ matches: F, ...J }) => J)
|
|
1623
1629
|
},
|
|
1624
1630
|
{
|
|
1625
|
-
...
|
|
1631
|
+
...qe(r.chatMode),
|
|
1626
1632
|
skipErrorHandler: !0
|
|
1627
1633
|
}
|
|
1628
1634
|
);
|
|
1629
1635
|
}, {
|
|
1630
1636
|
limit: 2,
|
|
1631
|
-
shouldRetryFn: (
|
|
1632
|
-
var
|
|
1633
|
-
const
|
|
1634
|
-
return !((
|
|
1637
|
+
shouldRetryFn: (m) => {
|
|
1638
|
+
var J, he, pe, se;
|
|
1639
|
+
const h = (J = m == null ? void 0 : m.message) == null ? void 0 : J.includes("missing or invalid session_id");
|
|
1640
|
+
return !((he = m == null ? void 0 : m.message) == null ? void 0 : he.includes("Stream Error")) && !h ? ((se = (pe = t.callbacks).onError) == null || se.call(pe, m), !1) : !0;
|
|
1635
1641
|
},
|
|
1636
1642
|
onRetry: async () => {
|
|
1637
|
-
await W(), await
|
|
1643
|
+
await W(), await T(!1);
|
|
1638
1644
|
}
|
|
1639
1645
|
});
|
|
1640
1646
|
};
|
|
1641
1647
|
try {
|
|
1642
|
-
|
|
1648
|
+
B(), y(), r.messages.push({
|
|
1643
1649
|
id: ue(),
|
|
1644
1650
|
role: "user",
|
|
1645
|
-
content:
|
|
1651
|
+
content: f,
|
|
1646
1652
|
created_at: new Date(ie.update()).toISOString()
|
|
1647
|
-
}), (
|
|
1648
|
-
const
|
|
1653
|
+
}), (I = (b = t.callbacks).onNewMessage) == null || I.call(b, [...r.messages], "user");
|
|
1654
|
+
const L = await k(), K = await _([...r.messages], L);
|
|
1649
1655
|
return r.messages.push({
|
|
1650
1656
|
id: ue(),
|
|
1651
1657
|
role: "assistant",
|
|
1652
|
-
content:
|
|
1658
|
+
content: K.result || "",
|
|
1653
1659
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1654
|
-
context:
|
|
1655
|
-
matches:
|
|
1660
|
+
context: K.context,
|
|
1661
|
+
matches: K.matches
|
|
1656
1662
|
}), d.track("agent-message-send", {
|
|
1657
1663
|
event: "success",
|
|
1658
1664
|
messages: r.messages.length + 1
|
|
1659
|
-
}),
|
|
1665
|
+
}), K.result && ((H = (U = t.callbacks).onNewMessage) == null || H.call(U, [...r.messages], "answer"), d.track("agent-message-received", {
|
|
1660
1666
|
latency: ie.get(!0),
|
|
1661
1667
|
messages: r.messages.length
|
|
1662
|
-
})),
|
|
1663
|
-
} catch (
|
|
1668
|
+
})), K;
|
|
1669
|
+
} catch (L) {
|
|
1664
1670
|
throw ((Q = r.messages[r.messages.length - 1]) == null ? void 0 : Q.role) === "assistant" && r.messages.pop(), d.track("agent-message-send", {
|
|
1665
1671
|
event: "error",
|
|
1666
1672
|
messages: r.messages.length
|
|
1667
|
-
}),
|
|
1673
|
+
}), L;
|
|
1668
1674
|
}
|
|
1669
1675
|
},
|
|
1670
|
-
rate(
|
|
1671
|
-
var
|
|
1672
|
-
const
|
|
1676
|
+
rate(f, y, k) {
|
|
1677
|
+
var I, U, H, Q;
|
|
1678
|
+
const _ = r.messages.find((L) => L.id === f);
|
|
1673
1679
|
if (r.chat) {
|
|
1674
|
-
if (!
|
|
1680
|
+
if (!_)
|
|
1675
1681
|
throw new Error("Message not found");
|
|
1676
1682
|
} else throw new Error("Chat is not initialized");
|
|
1677
|
-
const b = ((
|
|
1683
|
+
const b = ((I = _.matches) == null ? void 0 : I.map((L) => [L.document_id, L.id])) ?? [];
|
|
1678
1684
|
return d.track("agent-rate", {
|
|
1679
1685
|
event: k ? "update" : "create",
|
|
1680
1686
|
thumb: y === 1 ? "up" : "down",
|
|
1681
1687
|
knowledge_id: ((U = u.knowledge) == null ? void 0 : U.id) ?? "",
|
|
1682
1688
|
matches: b,
|
|
1683
1689
|
score: y
|
|
1684
|
-
}), k ?
|
|
1690
|
+
}), k ? p.updateRating(u.id, r.chat.id, k, {
|
|
1685
1691
|
knowledge_id: ((H = u.knowledge) == null ? void 0 : H.id) ?? "",
|
|
1686
|
-
message_id:
|
|
1692
|
+
message_id: f,
|
|
1687
1693
|
matches: b,
|
|
1688
1694
|
score: y
|
|
1689
|
-
}) :
|
|
1695
|
+
}) : p.createRating(u.id, r.chat.id, {
|
|
1690
1696
|
knowledge_id: ((Q = u.knowledge) == null ? void 0 : Q.id) ?? "",
|
|
1691
|
-
message_id:
|
|
1697
|
+
message_id: f,
|
|
1692
1698
|
matches: b,
|
|
1693
1699
|
score: y
|
|
1694
1700
|
});
|
|
1695
1701
|
},
|
|
1696
|
-
deleteRate(
|
|
1702
|
+
deleteRate(f) {
|
|
1697
1703
|
if (!r.chat)
|
|
1698
1704
|
throw new Error("Chat is not initialized");
|
|
1699
|
-
return d.track("agent-rate-delete", { type: "text" }),
|
|
1705
|
+
return d.track("agent-rate-delete", { type: "text" }), p.deleteRating(u.id, r.chat.id, f);
|
|
1700
1706
|
},
|
|
1701
|
-
async speak(
|
|
1702
|
-
var b,
|
|
1707
|
+
async speak(f) {
|
|
1708
|
+
var b, I, U;
|
|
1703
1709
|
function y() {
|
|
1704
|
-
if (typeof
|
|
1710
|
+
if (typeof f == "string") {
|
|
1705
1711
|
if (!u.presenter.voice)
|
|
1706
1712
|
throw new Error("Presenter voice is not initialized");
|
|
1707
1713
|
return {
|
|
1708
1714
|
type: "text",
|
|
1709
1715
|
provider: u.presenter.voice,
|
|
1710
|
-
input:
|
|
1716
|
+
input: f,
|
|
1711
1717
|
ssml: !1
|
|
1712
1718
|
};
|
|
1713
1719
|
}
|
|
1714
|
-
if (
|
|
1720
|
+
if (f.type === "text" && !f.provider) {
|
|
1715
1721
|
if (!u.presenter.voice)
|
|
1716
1722
|
throw new Error("Presenter voice is not initialized");
|
|
1717
1723
|
return {
|
|
1718
1724
|
type: "text",
|
|
1719
1725
|
provider: u.presenter.voice,
|
|
1720
|
-
input:
|
|
1721
|
-
ssml:
|
|
1726
|
+
input: f.input,
|
|
1727
|
+
ssml: f.ssml
|
|
1722
1728
|
};
|
|
1723
1729
|
}
|
|
1724
|
-
return
|
|
1730
|
+
return f;
|
|
1725
1731
|
}
|
|
1726
1732
|
const k = y();
|
|
1727
1733
|
if (d.track("agent-speak", k), ie.update(), r.messages && k.type === "text" && (r.messages.push({
|
|
@@ -1729,7 +1735,7 @@ async function mn(e, t) {
|
|
|
1729
1735
|
role: "assistant",
|
|
1730
1736
|
content: k.input,
|
|
1731
1737
|
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1732
|
-
}), (
|
|
1738
|
+
}), (I = (b = t.callbacks).onNewMessage) == null || I.call(b, [...r.messages], "answer")), gt(r.chatMode))
|
|
1733
1739
|
return {
|
|
1734
1740
|
duration: 0,
|
|
1735
1741
|
video_id: "",
|
|
@@ -1742,33 +1748,33 @@ async function mn(e, t) {
|
|
|
1742
1748
|
metadata: { chat_id: (U = r.chat) == null ? void 0 : U.id, agent_id: u.id }
|
|
1743
1749
|
});
|
|
1744
1750
|
},
|
|
1745
|
-
interrupt:
|
|
1751
|
+
interrupt: M
|
|
1746
1752
|
};
|
|
1747
1753
|
}
|
|
1748
1754
|
export {
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1755
|
+
q as AgentActivityState,
|
|
1756
|
+
rt as AgentStatus,
|
|
1757
|
+
Ge as ChatCreationFailed,
|
|
1758
|
+
N as ChatMode,
|
|
1759
|
+
Ze as ChatModeDowngraded,
|
|
1754
1760
|
Y as ChatProgress,
|
|
1755
1761
|
S as ConnectionState,
|
|
1756
1762
|
re as ConnectivityState,
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
+
st as DocumentType,
|
|
1764
|
+
ot as KnowledgeType,
|
|
1765
|
+
nt as PlanGroup,
|
|
1766
|
+
ct as Providers,
|
|
1767
|
+
it as RateState,
|
|
1768
|
+
j as StreamEvents,
|
|
1763
1769
|
ae as StreamType,
|
|
1764
1770
|
C as StreamingState,
|
|
1765
|
-
|
|
1771
|
+
at as Subject,
|
|
1766
1772
|
ye as TransportProvider,
|
|
1767
|
-
|
|
1773
|
+
tt as UserPlan,
|
|
1768
1774
|
de as ValidationError,
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1775
|
+
Je as VideoType,
|
|
1776
|
+
dt as VoiceAccess,
|
|
1777
|
+
et as WsError,
|
|
1778
|
+
hn as createAgentManager,
|
|
1779
|
+
gn as mapVideoType
|
|
1774
1780
|
};
|