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