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