@d-id/client-sdk 1.1.14-staging.56 → 1.1.14-staging.58
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-DWVsKwu3.js → index-DN5MqwMt.js} +424 -402
- package/dist/index.js +6 -6
- package/dist/index.umd.cjs +5 -5
- package/dist/{livekit-manager-D_9qu7Fm.js → livekit-manager-B2cn3NW6.js} +16 -15
- package/dist/src/services/agent-manager/connect-to-manager.d.ts +3 -2
- package/dist/src/services/streaming-manager/common.d.ts +2 -2
- package/dist/src/services/streaming-manager/factory.d.ts +12 -2
- package/dist/src/services/streaming-manager/index.d.ts +2 -1
- package/dist/src/services/streaming-manager/livekit-manager.d.ts +2 -2
- package/dist/src/types/stream/streams-v2.d.ts +3 -2
- package/dist/src/utils/agent.d.ts +1 -0
- package/package.json +1 -1
- package/dist/src/services/agent-manager/connect-to-manager.test.d.ts +0 -1
- package/dist/src/services/agent-manager/index.test.d.ts +0 -1
- package/dist/src/services/streaming-manager/advanced.test.d.ts +0 -5
- package/dist/src/services/streaming-manager/business-flows.test.d.ts +0 -5
- package/dist/src/services/streaming-manager/disconnect.test.d.ts +0 -5
- package/dist/src/services/streaming-manager/edge-cases.test.d.ts +0 -5
- package/dist/src/services/streaming-manager/factory.test.d.ts +0 -1
- package/dist/src/services/streaming-manager/webrtc-core.test.d.ts +0 -5
- package/dist/src/services/streaming-manager/webrtc-utils.test.d.ts +0 -5
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var Z = (e, t, n) =>
|
|
1
|
+
var Ce = Object.defineProperty;
|
|
2
|
+
var Re = (e, t, n) => t in e ? Ce(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
+
var Z = (e, t, n) => Re(e, typeof t != "symbol" ? t + "" : t, n);
|
|
4
4
|
class te extends Error {
|
|
5
5
|
constructor({ kind: n, description: r, error: i }) {
|
|
6
6
|
super(JSON.stringify({ kind: n, description: r }));
|
|
@@ -10,7 +10,7 @@ class te extends Error {
|
|
|
10
10
|
this.kind = n, this.description = r, this.error = i;
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
class
|
|
13
|
+
class Se extends te {
|
|
14
14
|
constructor(t, n) {
|
|
15
15
|
super({
|
|
16
16
|
kind: "ChatCreationFailed",
|
|
@@ -18,7 +18,7 @@ class Ce extends te {
|
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
class
|
|
21
|
+
class Ie extends te {
|
|
22
22
|
constructor(t) {
|
|
23
23
|
super({ kind: "ChatModeDowngraded", description: `Chat mode downgraded to ${t}` });
|
|
24
24
|
}
|
|
@@ -30,13 +30,13 @@ class H extends te {
|
|
|
30
30
|
this.key = r;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
class
|
|
33
|
+
class Ee extends te {
|
|
34
34
|
constructor(t) {
|
|
35
35
|
super({ kind: "WSError", description: t });
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
var
|
|
39
|
-
const
|
|
38
|
+
var Me = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(Me || {}), _e = /* @__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))(_e || {}), Te = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(Te || {}), Ae = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(Ae || {}), E = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(E || {}), V = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Complete = "done", e))(V || {}), je = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(je || {}), be = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(be || {}), Pe = /* @__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))(Pe || {}), ue = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(ue || {});
|
|
39
|
+
const Pt = (e) => {
|
|
40
40
|
switch (e) {
|
|
41
41
|
case "clip":
|
|
42
42
|
return "clip";
|
|
@@ -46,16 +46,16 @@ const At = (e) => {
|
|
|
46
46
|
throw new Error(`Unknown video type: ${e}`);
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
|
-
var w = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(w || {}), G = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(G || {}), O = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Talking = "TALKING", e))(O || {}),
|
|
50
|
-
const
|
|
49
|
+
var w = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(w || {}), G = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(G || {}), O = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Talking = "TALKING", e))(O || {}), j = /* @__PURE__ */ ((e) => (e.ChatAnswer = "chat/answer", e.ChatPartial = "chat/partial", e.StreamDone = "stream/done", e.StreamStarted = "stream/started", e.StreamFailed = "stream/error", e.StreamReady = "stream/ready", e.StreamCreated = "stream/created", e.StreamInterrupt = "stream/interrupt", e.StreamVideoCreated = "stream-video/started", e.StreamVideoDone = "stream-video/done", e.StreamVideoError = "stream-video/error", e.StreamVideoRejected = "stream-video/rejected", e))(j || {}), R = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnected = "disconnected", e))(R || {}), J = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(J || {}), oe = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(oe || {}), Le = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(Le || {}), Be = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(Be || {});
|
|
50
|
+
const $e = 45 * 1e3, xe = "X-Playground-Chat", ee = "https://api.d-id.com", ze = "wss://notifications.d-id.com", Fe = "79f81a83a67430be2bc0fd61042b8faa", fe = (e) => new Promise((t) => setTimeout(t, e)), q = (e = 16) => {
|
|
51
51
|
const t = new Uint8Array(e);
|
|
52
52
|
return window.crypto.getRandomValues(t), Array.from(t, (n) => n.toString(16).padStart(2, "0")).join("").slice(0, 13);
|
|
53
|
-
},
|
|
54
|
-
function
|
|
53
|
+
}, Ne = (e) => [E.TextOnly, E.Playground, E.Maintenance].includes(e), me = (e) => e && [E.DirectPlayback, E.Off].includes(e);
|
|
54
|
+
function Je(e, t) {
|
|
55
55
|
let n;
|
|
56
56
|
return {
|
|
57
|
-
promise: new Promise((i,
|
|
58
|
-
n = setTimeout(() =>
|
|
57
|
+
promise: new Promise((i, s) => {
|
|
58
|
+
n = setTimeout(() => s(new Error(t)), e);
|
|
59
59
|
}),
|
|
60
60
|
clear: () => clearTimeout(n)
|
|
61
61
|
};
|
|
@@ -75,135 +75,135 @@ async function ne(e, t) {
|
|
|
75
75
|
try {
|
|
76
76
|
if (!n.timeout)
|
|
77
77
|
return await e();
|
|
78
|
-
const { promise:
|
|
79
|
-
return await Promise.race([a,
|
|
80
|
-
} catch (
|
|
81
|
-
if (r =
|
|
82
|
-
throw
|
|
83
|
-
await
|
|
78
|
+
const { promise: s, clear: c } = Je(n.timeout, n.timeoutErrorMessage), a = e().finally(c);
|
|
79
|
+
return await Promise.race([a, s]);
|
|
80
|
+
} catch (s) {
|
|
81
|
+
if (r = s, !n.shouldRetryFn(s) || i >= n.limit)
|
|
82
|
+
throw s;
|
|
83
|
+
await fe(n.delayMs), n.onRetry(s);
|
|
84
84
|
}
|
|
85
85
|
throw r;
|
|
86
86
|
}
|
|
87
|
-
function
|
|
87
|
+
function ge() {
|
|
88
88
|
let e = window.localStorage.getItem("did_external_key_id");
|
|
89
89
|
if (!e) {
|
|
90
|
-
let t =
|
|
90
|
+
let t = q();
|
|
91
91
|
window.localStorage.setItem("did_external_key_id", t), e = t;
|
|
92
92
|
}
|
|
93
93
|
return e;
|
|
94
94
|
}
|
|
95
|
-
let
|
|
96
|
-
function
|
|
95
|
+
let We = q();
|
|
96
|
+
function he(e) {
|
|
97
97
|
if (e.type === "bearer")
|
|
98
98
|
return `Bearer ${e.token}`;
|
|
99
99
|
if (e.type === "basic")
|
|
100
100
|
return `Basic ${btoa(`${e.username}:${e.password}`)}`;
|
|
101
101
|
if (e.type === "key")
|
|
102
|
-
return `Client-Key ${e.clientKey}.${
|
|
102
|
+
return `Client-Key ${e.clientKey}.${ge()}_${We}`;
|
|
103
103
|
throw new Error(`Unknown auth type: ${e}`);
|
|
104
104
|
}
|
|
105
|
-
const
|
|
105
|
+
const Ue = (e) => ne(e, {
|
|
106
106
|
limit: 3,
|
|
107
107
|
delayMs: 1e3,
|
|
108
108
|
timeout: 0,
|
|
109
109
|
shouldRetryFn: (t) => t.status === 429
|
|
110
110
|
});
|
|
111
|
-
function
|
|
112
|
-
const r = async (i,
|
|
113
|
-
const { skipErrorHandler: c, ...a } =
|
|
111
|
+
function we(e, t = ee, n) {
|
|
112
|
+
const r = async (i, s) => {
|
|
113
|
+
const { skipErrorHandler: c, ...a } = s || {}, o = await Ue(
|
|
114
114
|
() => fetch(t + (i != null && i.startsWith("/") ? i : `/${i}`), {
|
|
115
115
|
...a,
|
|
116
116
|
headers: {
|
|
117
117
|
...a.headers,
|
|
118
|
-
Authorization:
|
|
118
|
+
Authorization: he(e),
|
|
119
119
|
"Content-Type": "application/json"
|
|
120
120
|
}
|
|
121
121
|
})
|
|
122
122
|
);
|
|
123
|
-
if (!
|
|
124
|
-
let d = await
|
|
123
|
+
if (!o.ok) {
|
|
124
|
+
let d = await o.text().catch(() => `Failed to fetch with status ${o.status}`);
|
|
125
125
|
const l = new Error(d);
|
|
126
|
-
throw n && !c && n(l, { url: i, options: a, headers:
|
|
126
|
+
throw n && !c && n(l, { url: i, options: a, headers: o.headers }), l;
|
|
127
127
|
}
|
|
128
|
-
return
|
|
128
|
+
return o.json();
|
|
129
129
|
};
|
|
130
130
|
return {
|
|
131
|
-
get(i,
|
|
132
|
-
return r(i, { ...
|
|
131
|
+
get(i, s) {
|
|
132
|
+
return r(i, { ...s, method: "GET" });
|
|
133
133
|
},
|
|
134
|
-
post(i,
|
|
135
|
-
return r(i, { ...c, body: JSON.stringify(
|
|
134
|
+
post(i, s, c) {
|
|
135
|
+
return r(i, { ...c, body: JSON.stringify(s), method: "POST" });
|
|
136
136
|
},
|
|
137
|
-
delete(i,
|
|
138
|
-
return r(i, { ...c, body: JSON.stringify(
|
|
137
|
+
delete(i, s, c) {
|
|
138
|
+
return r(i, { ...c, body: JSON.stringify(s), method: "DELETE" });
|
|
139
139
|
},
|
|
140
|
-
patch(i,
|
|
141
|
-
return r(i, { ...c, body: JSON.stringify(
|
|
140
|
+
patch(i, s, c) {
|
|
141
|
+
return r(i, { ...c, body: JSON.stringify(s), method: "PATCH" });
|
|
142
142
|
}
|
|
143
143
|
};
|
|
144
144
|
}
|
|
145
|
-
function
|
|
146
|
-
const r =
|
|
145
|
+
function pe(e, t = ee, n) {
|
|
146
|
+
const r = we(e, `${t}/agents`, n);
|
|
147
147
|
return {
|
|
148
|
-
create(i,
|
|
149
|
-
return r.post("/", i,
|
|
148
|
+
create(i, s) {
|
|
149
|
+
return r.post("/", i, s);
|
|
150
150
|
},
|
|
151
|
-
getAgents(i,
|
|
152
|
-
return r.get(`/${i ? `?tag=${i}` : ""}`,
|
|
151
|
+
getAgents(i, s) {
|
|
152
|
+
return r.get(`/${i ? `?tag=${i}` : ""}`, s).then((c) => c ?? []);
|
|
153
153
|
},
|
|
154
|
-
getById(i,
|
|
155
|
-
return r.get(`/${i}`,
|
|
154
|
+
getById(i, s) {
|
|
155
|
+
return r.get(`/${i}`, s);
|
|
156
156
|
},
|
|
157
|
-
delete(i,
|
|
158
|
-
return r.delete(`/${i}`, void 0,
|
|
157
|
+
delete(i, s) {
|
|
158
|
+
return r.delete(`/${i}`, void 0, s);
|
|
159
159
|
},
|
|
160
|
-
update(i,
|
|
161
|
-
return r.patch(`/${i}`,
|
|
160
|
+
update(i, s, c) {
|
|
161
|
+
return r.patch(`/${i}`, s, c);
|
|
162
162
|
},
|
|
163
|
-
newChat(i,
|
|
164
|
-
return r.post(`/${i}/chat`,
|
|
163
|
+
newChat(i, s, c) {
|
|
164
|
+
return r.post(`/${i}/chat`, s, c);
|
|
165
165
|
},
|
|
166
|
-
chat(i,
|
|
167
|
-
return r.post(`/${i}/chat/${
|
|
166
|
+
chat(i, s, c, a) {
|
|
167
|
+
return r.post(`/${i}/chat/${s}`, c, a);
|
|
168
168
|
},
|
|
169
|
-
createRating(i,
|
|
170
|
-
return r.post(`/${i}/chat/${
|
|
169
|
+
createRating(i, s, c, a) {
|
|
170
|
+
return r.post(`/${i}/chat/${s}/ratings`, c, a);
|
|
171
171
|
},
|
|
172
|
-
updateRating(i,
|
|
173
|
-
return r.patch(`/${i}/chat/${
|
|
172
|
+
updateRating(i, s, c, a, o) {
|
|
173
|
+
return r.patch(`/${i}/chat/${s}/ratings/${c}`, a, o);
|
|
174
174
|
},
|
|
175
|
-
deleteRating(i,
|
|
176
|
-
return r.delete(`/${i}/chat/${
|
|
175
|
+
deleteRating(i, s, c, a) {
|
|
176
|
+
return r.delete(`/${i}/chat/${s}/ratings/${c}`, a);
|
|
177
177
|
},
|
|
178
|
-
getSTTToken(i,
|
|
179
|
-
return r.get(`/${i}/stt-token`,
|
|
178
|
+
getSTTToken(i, s) {
|
|
179
|
+
return r.get(`/${i}/stt-token`, s);
|
|
180
180
|
}
|
|
181
181
|
};
|
|
182
182
|
}
|
|
183
|
-
const
|
|
184
|
-
function
|
|
185
|
-
var i,
|
|
183
|
+
const ve = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type, Ke = (e) => e === ue.Expressive;
|
|
184
|
+
function He(e) {
|
|
185
|
+
var i, s, c, a;
|
|
186
186
|
const t = () => /Mobi|Android/i.test(navigator.userAgent) ? "Mobile" : "Desktop", n = () => {
|
|
187
|
-
const
|
|
188
|
-
return
|
|
187
|
+
const o = navigator.platform;
|
|
188
|
+
return o.toLowerCase().includes("win") ? "Windows" : o.toLowerCase().includes("mac") ? "Mac OS X" : o.toLowerCase().includes("linux") ? "Linux" : "Unknown";
|
|
189
189
|
}, r = e.presenter;
|
|
190
190
|
return {
|
|
191
191
|
$os: `${n()}`,
|
|
192
192
|
isMobile: `${t() == "Mobile"}`,
|
|
193
193
|
browser: navigator.userAgent,
|
|
194
194
|
origin: window.location.origin,
|
|
195
|
-
agentType:
|
|
195
|
+
agentType: ve(r),
|
|
196
196
|
agentVoice: {
|
|
197
|
-
voiceId: (
|
|
197
|
+
voiceId: (s = (i = e.presenter) == null ? void 0 : i.voice) == null ? void 0 : s.voice_id,
|
|
198
198
|
provider: (a = (c = e.presenter) == null ? void 0 : c.voice) == null ? void 0 : a.type
|
|
199
199
|
}
|
|
200
200
|
};
|
|
201
201
|
}
|
|
202
|
-
function
|
|
203
|
-
var n, r, i,
|
|
202
|
+
function Ve(e) {
|
|
203
|
+
var n, r, i, s, c, a;
|
|
204
204
|
const t = (n = e.llm) == null ? void 0 : n.prompt_customization;
|
|
205
205
|
return {
|
|
206
|
-
agentType:
|
|
206
|
+
agentType: ve(e.presenter),
|
|
207
207
|
owner_id: e.owner_id ?? "",
|
|
208
208
|
promptVersion: (r = e.llm) == null ? void 0 : r.prompt_version,
|
|
209
209
|
behavior: {
|
|
@@ -211,7 +211,7 @@ function Ke(e) {
|
|
|
211
211
|
personality: t == null ? void 0 : t.personality,
|
|
212
212
|
instructions: (i = e.llm) == null ? void 0 : i.instructions
|
|
213
213
|
},
|
|
214
|
-
temperature: (
|
|
214
|
+
temperature: (s = e.llm) == null ? void 0 : s.temperature,
|
|
215
215
|
knowledgeSource: t == null ? void 0 : t.knowledge_source,
|
|
216
216
|
starterQuestionsCount: (a = (c = e.knowledge) == null ? void 0 : c.starter_message) == null ? void 0 : a.length,
|
|
217
217
|
topicsToAvoid: t == null ? void 0 : t.topics_to_avoid,
|
|
@@ -222,39 +222,39 @@ function Ke(e) {
|
|
|
222
222
|
...e.access === "public" ? { from: "agent-template" } : {}
|
|
223
223
|
};
|
|
224
224
|
}
|
|
225
|
-
const
|
|
226
|
-
function
|
|
227
|
-
var
|
|
228
|
-
const { event: r, ...i } = e, { template:
|
|
225
|
+
const qe = (e) => e.reduce((t, n) => t + n, 0), ce = (e) => qe(e) / e.length;
|
|
226
|
+
function Oe(e, t, n) {
|
|
227
|
+
var o, d, l;
|
|
228
|
+
const { event: r, ...i } = e, { template: s } = (t == null ? void 0 : t.llm) || {}, { language: c } = ((o = t == null ? void 0 : t.presenter) == null ? void 0 : o.voice) || {};
|
|
229
229
|
return {
|
|
230
230
|
...i,
|
|
231
|
-
llm: { ...i.llm, template:
|
|
231
|
+
llm: { ...i.llm, template: s },
|
|
232
232
|
script: { ...i.script, provider: { ...(d = i == null ? void 0 : i.script) == null ? void 0 : d.provider, language: c } },
|
|
233
233
|
stitch: (t == null ? void 0 : t.presenter.type) === "talk" ? (l = t == null ? void 0 : t.presenter) == null ? void 0 : l.stitch : void 0,
|
|
234
234
|
...n
|
|
235
235
|
};
|
|
236
236
|
}
|
|
237
237
|
let re = {};
|
|
238
|
-
const
|
|
239
|
-
function
|
|
238
|
+
const Xe = "https://api-js.mixpanel.com/track/?verbose=1&ip=1";
|
|
239
|
+
function Ye(e) {
|
|
240
240
|
const t = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk";
|
|
241
241
|
return {
|
|
242
242
|
token: e.token || "testKey",
|
|
243
|
-
distinct_id: e.distinctId ||
|
|
243
|
+
distinct_id: e.distinctId || ge(),
|
|
244
244
|
agentId: e.agentId,
|
|
245
245
|
additionalProperties: {
|
|
246
246
|
id: e.distinctId,
|
|
247
247
|
...e.mixpanelAdditionalProperties || {}
|
|
248
248
|
},
|
|
249
249
|
isEnabled: e.isEnabled ?? !0,
|
|
250
|
-
getRandom:
|
|
250
|
+
getRandom: q,
|
|
251
251
|
enrich(n) {
|
|
252
252
|
this.additionalProperties = { ...this.additionalProperties, ...n };
|
|
253
253
|
},
|
|
254
254
|
async track(n, r) {
|
|
255
255
|
if (!this.isEnabled)
|
|
256
256
|
return Promise.resolve();
|
|
257
|
-
const { audioPath: i, ...
|
|
257
|
+
const { audioPath: i, ...s } = r || {}, c = {
|
|
258
258
|
method: "POST",
|
|
259
259
|
headers: {
|
|
260
260
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
@@ -265,7 +265,7 @@ function Oe(e) {
|
|
|
265
265
|
event: n,
|
|
266
266
|
properties: {
|
|
267
267
|
...this.additionalProperties,
|
|
268
|
-
...
|
|
268
|
+
...s,
|
|
269
269
|
agentId: this.agentId,
|
|
270
270
|
source: t,
|
|
271
271
|
token: this.token,
|
|
@@ -281,28 +281,28 @@ function Oe(e) {
|
|
|
281
281
|
})
|
|
282
282
|
};
|
|
283
283
|
try {
|
|
284
|
-
return await fetch(
|
|
284
|
+
return await fetch(Xe, c).then((a) => a.json());
|
|
285
285
|
} catch (a) {
|
|
286
286
|
return console.error(a);
|
|
287
287
|
}
|
|
288
288
|
},
|
|
289
|
-
linkTrack(n, r, i,
|
|
290
|
-
re[n] || (re[n] = { events: {}, resolvedDependencies: [] }),
|
|
289
|
+
linkTrack(n, r, i, s) {
|
|
290
|
+
re[n] || (re[n] = { events: {}, resolvedDependencies: [] }), s.includes(i) || s.push(i);
|
|
291
291
|
const c = re[n];
|
|
292
|
-
if (c.events[i] = { props: r }, c.resolvedDependencies.push(i),
|
|
293
|
-
(
|
|
292
|
+
if (c.events[i] = { props: r }, c.resolvedDependencies.push(i), s.every(
|
|
293
|
+
(o) => c.resolvedDependencies.includes(o)
|
|
294
294
|
)) {
|
|
295
|
-
const
|
|
296
|
-
this.track(n,
|
|
297
|
-
(d) => !
|
|
298
|
-
),
|
|
295
|
+
const o = s.reduce((d, l) => c.events[l] ? { ...d, ...c.events[l].props } : d, {});
|
|
296
|
+
this.track(n, o), c.resolvedDependencies = c.resolvedDependencies.filter(
|
|
297
|
+
(d) => !s.includes(d)
|
|
298
|
+
), s.forEach((d) => {
|
|
299
299
|
delete c.events[d];
|
|
300
300
|
});
|
|
301
301
|
}
|
|
302
302
|
}
|
|
303
303
|
};
|
|
304
304
|
}
|
|
305
|
-
function
|
|
305
|
+
function ye() {
|
|
306
306
|
let e = 0;
|
|
307
307
|
return {
|
|
308
308
|
reset: () => e = 0,
|
|
@@ -310,17 +310,17 @@ function pe() {
|
|
|
310
310
|
get: (t = !1) => t ? Date.now() - e : e
|
|
311
311
|
};
|
|
312
312
|
}
|
|
313
|
-
const
|
|
314
|
-
function
|
|
315
|
-
return e === E.Playground ? { headers: { [
|
|
313
|
+
const B = ye(), ae = ye();
|
|
314
|
+
function ke(e) {
|
|
315
|
+
return e === E.Playground ? { headers: { [xe]: "true" } } : {};
|
|
316
316
|
}
|
|
317
|
-
async function
|
|
317
|
+
async function De(e, t, n, r, i = !1, s) {
|
|
318
318
|
try {
|
|
319
|
-
return !
|
|
319
|
+
return !s && !me(r) && (s = await t.newChat(e.id, { persist: i }, ke(r)), n.track("agent-chat", {
|
|
320
320
|
event: "created",
|
|
321
|
-
chatId:
|
|
321
|
+
chatId: s.id,
|
|
322
322
|
mode: r
|
|
323
|
-
})), { chat:
|
|
323
|
+
})), { chat: s, chatMode: (s == null ? void 0 : s.chat_mode) ?? r };
|
|
324
324
|
} catch (c) {
|
|
325
325
|
try {
|
|
326
326
|
const a = JSON.parse(c.message);
|
|
@@ -332,10 +332,10 @@ async function ve(e, t, n, r, i = !1, o) {
|
|
|
332
332
|
throw new Error("Cannot create new chat");
|
|
333
333
|
}
|
|
334
334
|
}
|
|
335
|
-
function
|
|
335
|
+
function Qe(e) {
|
|
336
336
|
return e && e.length > 0 ? e : [];
|
|
337
337
|
}
|
|
338
|
-
function
|
|
338
|
+
function Ze(e, t, n) {
|
|
339
339
|
if (!e)
|
|
340
340
|
throw new Error("Please connect to the agent first");
|
|
341
341
|
if (!e.interruptAvailable)
|
|
@@ -345,48 +345,48 @@ function Ye(e, t, n) {
|
|
|
345
345
|
if (!n)
|
|
346
346
|
throw new Error("No active video to interrupt");
|
|
347
347
|
}
|
|
348
|
-
async function
|
|
348
|
+
async function Ge(e, t) {
|
|
349
349
|
const n = {
|
|
350
|
-
type:
|
|
350
|
+
type: j.StreamInterrupt,
|
|
351
351
|
videoId: t,
|
|
352
352
|
timestamp: Date.now()
|
|
353
353
|
};
|
|
354
354
|
e.sendDataChannelMessage(JSON.stringify(n));
|
|
355
355
|
}
|
|
356
|
-
function
|
|
356
|
+
function et(e) {
|
|
357
357
|
return new Promise((t, n) => {
|
|
358
|
-
const { callbacks: r, host: i, auth:
|
|
359
|
-
l.onmessage = c, l.onclose =
|
|
360
|
-
console.error(
|
|
361
|
-
}, l.onopen = (
|
|
362
|
-
a == null || a(
|
|
358
|
+
const { callbacks: r, host: i, auth: s } = e, { onMessage: c = null, onOpen: a = null, onClose: o = null, onError: d = null } = r || {}, l = new WebSocket(`${i}?authorization=${he(s)}`);
|
|
359
|
+
l.onmessage = c, l.onclose = o, l.onerror = (v) => {
|
|
360
|
+
console.error(v), d == null || d("Websocket failed to connect", v), n(v);
|
|
361
|
+
}, l.onopen = (v) => {
|
|
362
|
+
a == null || a(v), t(l);
|
|
363
363
|
};
|
|
364
364
|
});
|
|
365
365
|
}
|
|
366
|
-
async function
|
|
366
|
+
async function tt(e) {
|
|
367
367
|
const { retries: t = 1 } = e;
|
|
368
368
|
let n = null;
|
|
369
369
|
for (let r = 0; (n == null ? void 0 : n.readyState) !== WebSocket.OPEN; r++)
|
|
370
370
|
try {
|
|
371
|
-
n = await
|
|
371
|
+
n = await et(e);
|
|
372
372
|
} catch (i) {
|
|
373
373
|
if (r === t)
|
|
374
374
|
throw i;
|
|
375
|
-
await
|
|
375
|
+
await fe(r * 500);
|
|
376
376
|
}
|
|
377
377
|
return n;
|
|
378
378
|
}
|
|
379
|
-
async function
|
|
380
|
-
const r = n != null && n.onMessage ? [n.onMessage] : [], i = await
|
|
379
|
+
async function rt(e, t, n) {
|
|
380
|
+
const r = n != null && n.onMessage ? [n.onMessage] : [], i = await tt({
|
|
381
381
|
auth: e,
|
|
382
382
|
host: t,
|
|
383
383
|
callbacks: {
|
|
384
|
-
onError: (
|
|
384
|
+
onError: (s) => {
|
|
385
385
|
var c;
|
|
386
|
-
return (c = n.onError) == null ? void 0 : c.call(n, new
|
|
386
|
+
return (c = n.onError) == null ? void 0 : c.call(n, new Ee(s));
|
|
387
387
|
},
|
|
388
|
-
onMessage(
|
|
389
|
-
const c = JSON.parse(
|
|
388
|
+
onMessage(s) {
|
|
389
|
+
const c = JSON.parse(s.data);
|
|
390
390
|
r.forEach((a) => a(c.event, c));
|
|
391
391
|
}
|
|
392
392
|
}
|
|
@@ -394,10 +394,10 @@ async function et(e, t, n) {
|
|
|
394
394
|
return {
|
|
395
395
|
socket: i,
|
|
396
396
|
disconnect: () => i.close(),
|
|
397
|
-
subscribeToEvents: (
|
|
397
|
+
subscribeToEvents: (s) => r.push(s)
|
|
398
398
|
};
|
|
399
399
|
}
|
|
400
|
-
function
|
|
400
|
+
function nt(e) {
|
|
401
401
|
if (e.answer !== void 0)
|
|
402
402
|
return e.answer;
|
|
403
403
|
let t = 0, n = "";
|
|
@@ -405,70 +405,70 @@ function tt(e) {
|
|
|
405
405
|
n += e[t++];
|
|
406
406
|
return n;
|
|
407
407
|
}
|
|
408
|
-
function
|
|
409
|
-
const
|
|
410
|
-
if (!(e ===
|
|
408
|
+
function at(e, t, n, r, i) {
|
|
409
|
+
const s = r.messages[r.messages.length - 1];
|
|
410
|
+
if (!(e === V.Partial || e === V.Answer) || (s == null ? void 0 : s.role) !== "assistant")
|
|
411
411
|
return;
|
|
412
412
|
const { content: c, sequence: a } = t;
|
|
413
|
-
e ===
|
|
414
|
-
const
|
|
415
|
-
(
|
|
413
|
+
e === V.Partial ? n[a] = c : n.answer = c;
|
|
414
|
+
const o = nt(n);
|
|
415
|
+
(s.content !== o || e === V.Answer) && (s.content = o, i == null || i([...r.messages], e));
|
|
416
416
|
}
|
|
417
|
-
function
|
|
418
|
-
let
|
|
417
|
+
function it(e, t, n, r, i) {
|
|
418
|
+
let s = {};
|
|
419
419
|
return {
|
|
420
|
-
clearQueue: () =>
|
|
420
|
+
clearQueue: () => s = {},
|
|
421
421
|
onMessage: (c, a) => {
|
|
422
|
-
var
|
|
422
|
+
var o, d;
|
|
423
423
|
if ("content" in a)
|
|
424
|
-
|
|
424
|
+
at(c, a, s, t, n.callbacks.onNewMessage), c === V.Answer && e.track("agent-message-received", {
|
|
425
425
|
messages: t.messages.length,
|
|
426
426
|
mode: t.chatMode
|
|
427
427
|
});
|
|
428
428
|
else {
|
|
429
|
-
const l =
|
|
429
|
+
const l = j, v = [l.StreamVideoDone, l.StreamVideoError, l.StreamVideoRejected], M = [l.StreamFailed, l.StreamVideoError, l.StreamVideoRejected], b = Oe(a, r, { mode: t.chatMode });
|
|
430
430
|
if (c = c, c === l.StreamVideoCreated)
|
|
431
|
-
e.linkTrack("agent-video",
|
|
432
|
-
else if (
|
|
433
|
-
const
|
|
434
|
-
M.includes(c) ? e.track("agent-video", { ...
|
|
431
|
+
e.linkTrack("agent-video", b, l.StreamVideoCreated, ["start"]);
|
|
432
|
+
else if (v.includes(c)) {
|
|
433
|
+
const $ = c.split("/")[1];
|
|
434
|
+
M.includes(c) ? e.track("agent-video", { ...b, event: $ }) : e.linkTrack("agent-video", { ...b, event: $ }, c, ["done"]);
|
|
435
435
|
}
|
|
436
|
-
M.includes(c) && ((d = (
|
|
436
|
+
M.includes(c) && ((d = (o = n.callbacks).onError) == null || d.call(o, new Error(`Stream failed with event ${c}`), { data: a })), a.event === l.StreamDone && i();
|
|
437
437
|
}
|
|
438
438
|
}
|
|
439
439
|
};
|
|
440
440
|
}
|
|
441
|
-
function
|
|
442
|
-
const i =
|
|
441
|
+
function st(e, t, n, r) {
|
|
442
|
+
const i = we(e, `${t}/agents/${n}`, r);
|
|
443
443
|
return {
|
|
444
|
-
createStream(
|
|
445
|
-
return i.post("/streams",
|
|
444
|
+
createStream(s) {
|
|
445
|
+
return i.post("/streams", s);
|
|
446
446
|
},
|
|
447
|
-
startConnection(
|
|
448
|
-
return i.post(`/streams/${
|
|
447
|
+
startConnection(s, c, a) {
|
|
448
|
+
return i.post(`/streams/${s}/sdp`, {
|
|
449
449
|
session_id: a,
|
|
450
450
|
answer: c
|
|
451
451
|
});
|
|
452
452
|
},
|
|
453
|
-
addIceCandidate(
|
|
454
|
-
return i.post(`/streams/${
|
|
453
|
+
addIceCandidate(s, c, a) {
|
|
454
|
+
return i.post(`/streams/${s}/ice`, {
|
|
455
455
|
session_id: a,
|
|
456
456
|
...c
|
|
457
457
|
});
|
|
458
458
|
},
|
|
459
|
-
sendStreamRequest(
|
|
460
|
-
return i.post(`/streams/${
|
|
459
|
+
sendStreamRequest(s, c, a) {
|
|
460
|
+
return i.post(`/streams/${s}`, {
|
|
461
461
|
session_id: c,
|
|
462
462
|
...a
|
|
463
463
|
});
|
|
464
464
|
},
|
|
465
|
-
close(
|
|
466
|
-
return i.delete(`/streams/${
|
|
465
|
+
close(s, c) {
|
|
466
|
+
return i.delete(`/streams/${s}`, { session_id: c });
|
|
467
467
|
}
|
|
468
468
|
};
|
|
469
469
|
}
|
|
470
|
-
const
|
|
471
|
-
function
|
|
470
|
+
const ot = (e, t) => (n, r) => e && console.log(`[${t}] ${n}`, r ?? "");
|
|
471
|
+
function ct(e, t, n) {
|
|
472
472
|
const r = (t.timestamp - e.timestamp) / 1e3;
|
|
473
473
|
return {
|
|
474
474
|
duration: r,
|
|
@@ -488,7 +488,7 @@ function st(e, t, n) {
|
|
|
488
488
|
lowFpsCount: n
|
|
489
489
|
};
|
|
490
490
|
}
|
|
491
|
-
function
|
|
491
|
+
function dt(e) {
|
|
492
492
|
return e.filter(
|
|
493
493
|
(t) => t.freezeCount > 0 || t.framesPerSecond < 21 || t.framesDropped > 0 || t.packetsLost > 0
|
|
494
494
|
).map((t) => {
|
|
@@ -499,7 +499,7 @@ function ot(e) {
|
|
|
499
499
|
};
|
|
500
500
|
});
|
|
501
501
|
}
|
|
502
|
-
function
|
|
502
|
+
function lt(e) {
|
|
503
503
|
let t = "", n = 0;
|
|
504
504
|
for (const r of e.values())
|
|
505
505
|
if (r && r.type === "codec" && r.mimeType.startsWith("video") && (t = r.mimeType.split("/")[1]), r && r.type === "candidate-pair" && (n = r.currentRoundTripTime), r && r.type === "inbound-rtp" && r.kind === "video")
|
|
@@ -524,107 +524,107 @@ function ct(e) {
|
|
|
524
524
|
};
|
|
525
525
|
return {};
|
|
526
526
|
}
|
|
527
|
-
function
|
|
528
|
-
const r = e.map((
|
|
529
|
-
timestamp:
|
|
527
|
+
function ut(e, t, n) {
|
|
528
|
+
const r = e.map((o, d) => d === 0 ? n ? {
|
|
529
|
+
timestamp: o.timestamp,
|
|
530
530
|
duration: 0,
|
|
531
|
-
rtt:
|
|
532
|
-
bytesReceived:
|
|
533
|
-
bitrate: (
|
|
534
|
-
packetsReceived:
|
|
535
|
-
packetsLost:
|
|
536
|
-
framesDropped:
|
|
537
|
-
framesDecoded:
|
|
538
|
-
jitter:
|
|
539
|
-
jitterBufferDelay:
|
|
540
|
-
jitterBufferEmittedCount:
|
|
541
|
-
avgJitterDelayInInterval: (
|
|
542
|
-
framesPerSecond:
|
|
543
|
-
freezeCount:
|
|
544
|
-
freezeDuration:
|
|
531
|
+
rtt: o.rtt,
|
|
532
|
+
bytesReceived: o.bytesReceived - n.bytesReceived,
|
|
533
|
+
bitrate: (o.bytesReceived - n.bytesReceived) * 8 / (t / 1e3),
|
|
534
|
+
packetsReceived: o.packetsReceived - n.packetsReceived,
|
|
535
|
+
packetsLost: o.packetsLost - n.packetsLost,
|
|
536
|
+
framesDropped: o.framesDropped - n.framesDropped,
|
|
537
|
+
framesDecoded: o.framesDecoded - n.framesDecoded,
|
|
538
|
+
jitter: o.jitter,
|
|
539
|
+
jitterBufferDelay: o.jitterBufferDelay - n.jitterBufferDelay,
|
|
540
|
+
jitterBufferEmittedCount: o.jitterBufferEmittedCount - n.jitterBufferEmittedCount,
|
|
541
|
+
avgJitterDelayInInterval: (o.jitterBufferDelay - n.jitterBufferDelay) / (o.jitterBufferEmittedCount - n.jitterBufferEmittedCount),
|
|
542
|
+
framesPerSecond: o.framesPerSecond,
|
|
543
|
+
freezeCount: o.freezeCount - n.freezeCount,
|
|
544
|
+
freezeDuration: o.freezeDuration - n.freezeDuration
|
|
545
545
|
} : {
|
|
546
|
-
timestamp:
|
|
547
|
-
rtt:
|
|
546
|
+
timestamp: o.timestamp,
|
|
547
|
+
rtt: o.rtt,
|
|
548
548
|
duration: 0,
|
|
549
|
-
bytesReceived:
|
|
550
|
-
bitrate:
|
|
551
|
-
packetsReceived:
|
|
552
|
-
packetsLost:
|
|
553
|
-
framesDropped:
|
|
554
|
-
framesDecoded:
|
|
555
|
-
jitter:
|
|
556
|
-
jitterBufferDelay:
|
|
557
|
-
jitterBufferEmittedCount:
|
|
558
|
-
avgJitterDelayInInterval:
|
|
559
|
-
framesPerSecond:
|
|
560
|
-
freezeCount:
|
|
561
|
-
freezeDuration:
|
|
549
|
+
bytesReceived: o.bytesReceived,
|
|
550
|
+
bitrate: o.bytesReceived * 8 / (t / 1e3),
|
|
551
|
+
packetsReceived: o.packetsReceived,
|
|
552
|
+
packetsLost: o.packetsLost,
|
|
553
|
+
framesDropped: o.framesDropped,
|
|
554
|
+
framesDecoded: o.framesDecoded,
|
|
555
|
+
jitter: o.jitter,
|
|
556
|
+
jitterBufferDelay: o.jitterBufferDelay,
|
|
557
|
+
jitterBufferEmittedCount: o.jitterBufferEmittedCount,
|
|
558
|
+
avgJitterDelayInInterval: o.jitterBufferDelay / o.jitterBufferEmittedCount,
|
|
559
|
+
framesPerSecond: o.framesPerSecond,
|
|
560
|
+
freezeCount: o.freezeCount,
|
|
561
|
+
freezeDuration: o.freezeDuration
|
|
562
562
|
} : {
|
|
563
|
-
timestamp:
|
|
563
|
+
timestamp: o.timestamp,
|
|
564
564
|
duration: t * d / 1e3,
|
|
565
|
-
rtt:
|
|
566
|
-
bytesReceived:
|
|
567
|
-
bitrate: (
|
|
568
|
-
packetsReceived:
|
|
569
|
-
packetsLost:
|
|
570
|
-
framesDropped:
|
|
571
|
-
framesDecoded:
|
|
572
|
-
jitter:
|
|
573
|
-
jitterBufferDelay:
|
|
574
|
-
jitterBufferEmittedCount:
|
|
575
|
-
avgJitterDelayInInterval: (
|
|
576
|
-
framesPerSecond:
|
|
577
|
-
freezeCount:
|
|
578
|
-
freezeDuration:
|
|
579
|
-
}), i =
|
|
565
|
+
rtt: o.rtt,
|
|
566
|
+
bytesReceived: o.bytesReceived - e[d - 1].bytesReceived,
|
|
567
|
+
bitrate: (o.bytesReceived - e[d - 1].bytesReceived) * 8 / (t / 1e3),
|
|
568
|
+
packetsReceived: o.packetsReceived - e[d - 1].packetsReceived,
|
|
569
|
+
packetsLost: o.packetsLost - e[d - 1].packetsLost,
|
|
570
|
+
framesDropped: o.framesDropped - e[d - 1].framesDropped,
|
|
571
|
+
framesDecoded: o.framesDecoded - e[d - 1].framesDecoded,
|
|
572
|
+
jitter: o.jitter,
|
|
573
|
+
jitterBufferDelay: o.jitterBufferDelay - e[d - 1].jitterBufferDelay,
|
|
574
|
+
jitterBufferEmittedCount: o.jitterBufferEmittedCount - e[d - 1].jitterBufferEmittedCount,
|
|
575
|
+
avgJitterDelayInInterval: (o.jitterBufferDelay - e[d - 1].jitterBufferDelay) / (o.jitterBufferEmittedCount - e[d - 1].jitterBufferEmittedCount),
|
|
576
|
+
framesPerSecond: o.framesPerSecond,
|
|
577
|
+
freezeCount: o.freezeCount - e[d - 1].freezeCount,
|
|
578
|
+
freezeDuration: o.freezeDuration - e[d - 1].freezeDuration
|
|
579
|
+
}), i = dt(r), s = i.reduce((o, d) => o + (d.causes.includes("low fps") ? 1 : 0), 0), c = r.filter((o) => !!o.avgJitterDelayInInterval).map((o) => o.avgJitterDelayInInterval), a = r.filter((o) => !!o.rtt).map((o) => o.rtt);
|
|
580
580
|
return {
|
|
581
581
|
webRTCStats: {
|
|
582
582
|
anomalies: i,
|
|
583
583
|
minRtt: Math.min(...a),
|
|
584
|
-
avgRtt:
|
|
584
|
+
avgRtt: ce(a),
|
|
585
585
|
maxRtt: Math.max(...a),
|
|
586
|
-
aggregateReport:
|
|
586
|
+
aggregateReport: ct(e[0], e[e.length - 1], s),
|
|
587
587
|
minJitterDelayInInterval: Math.min(...c),
|
|
588
588
|
maxJitterDelayInInterval: Math.max(...c),
|
|
589
|
-
avgJitterDelayInInterval:
|
|
589
|
+
avgJitterDelayInInterval: ce(c)
|
|
590
590
|
},
|
|
591
591
|
codec: e[0].codec,
|
|
592
592
|
resolution: `${e[0].frameWidth}x${e[0].frameHeight}`
|
|
593
593
|
};
|
|
594
594
|
}
|
|
595
|
-
const ie = 100,
|
|
596
|
-
function
|
|
595
|
+
const ie = 100, ft = Math.max(Math.ceil(400 / ie), 1), mt = 0.25, gt = 0.28;
|
|
596
|
+
function ht() {
|
|
597
597
|
let e = 0, t, n, r = 0;
|
|
598
598
|
return (i) => {
|
|
599
|
-
for (const
|
|
600
|
-
if (
|
|
601
|
-
const c =
|
|
599
|
+
for (const s of i.values())
|
|
600
|
+
if (s && s.type === "inbound-rtp" && s.kind === "video") {
|
|
601
|
+
const c = s.jitterBufferDelay, a = s.jitterBufferEmittedCount;
|
|
602
602
|
if (n && a > n) {
|
|
603
|
-
const l = c - t,
|
|
604
|
-
r = l /
|
|
603
|
+
const l = c - t, v = a - n;
|
|
604
|
+
r = l / v;
|
|
605
605
|
}
|
|
606
606
|
t = c, n = a;
|
|
607
|
-
const
|
|
608
|
-
return e =
|
|
607
|
+
const o = s.framesDecoded, d = o - e > 0;
|
|
608
|
+
return e = o, { isReceiving: d, avgJitterDelayInInterval: r, freezeCount: s.freezeCount };
|
|
609
609
|
}
|
|
610
610
|
return { isReceiving: !1, avgJitterDelayInInterval: r };
|
|
611
611
|
};
|
|
612
612
|
}
|
|
613
|
-
function
|
|
614
|
-
let c = [], a,
|
|
615
|
-
const
|
|
613
|
+
function wt(e, t, n, r, i, s = !1) {
|
|
614
|
+
let c = [], a, o = 0, d = !1, l = G.Unknown, v = G.Unknown, M = 0, b = 0;
|
|
615
|
+
const $ = ht();
|
|
616
616
|
return setInterval(async () => {
|
|
617
|
-
const z = await e.getStats(), { isReceiving: U, avgJitterDelayInInterval: W, freezeCount: C } =
|
|
617
|
+
const z = await e.getStats(), { isReceiving: U, avgJitterDelayInInterval: W, freezeCount: C } = $(z), K = lt(z);
|
|
618
618
|
if (U)
|
|
619
|
-
|
|
620
|
-
else if (d && (
|
|
621
|
-
const u =
|
|
622
|
-
r == null || r(w.Stop, u), t() || n(),
|
|
619
|
+
o = 0, M = C - b, v = W < mt ? G.Strong : W > gt && M > 1 ? G.Weak : l, v !== l && (i == null || i(v), l = v, b += M, M = 0), d || (r == null || r(w.Start), a = c[c.length - 1], c = [], d = !0), c.push(K);
|
|
620
|
+
else if (d && (o++, o >= ft)) {
|
|
621
|
+
const u = ut(c, ie, a);
|
|
622
|
+
r == null || r(w.Stop, u), t() || n(), b = C, d = !1;
|
|
623
623
|
}
|
|
624
624
|
}, ie);
|
|
625
625
|
}
|
|
626
|
-
const
|
|
627
|
-
function
|
|
626
|
+
const pt = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
|
|
627
|
+
function de(e) {
|
|
628
628
|
switch (e) {
|
|
629
629
|
case "connected":
|
|
630
630
|
return R.Connected;
|
|
@@ -644,7 +644,7 @@ function oe(e) {
|
|
|
644
644
|
return R.New;
|
|
645
645
|
}
|
|
646
646
|
}
|
|
647
|
-
const
|
|
647
|
+
const vt = (e) => (t) => {
|
|
648
648
|
const [n, r = ""] = t.split(/:(.+)/);
|
|
649
649
|
try {
|
|
650
650
|
const i = JSON.parse(r);
|
|
@@ -653,7 +653,7 @@ const wt = (e) => (t) => {
|
|
|
653
653
|
return e("Failed to parse data channel message, returning data as string", { subject: n, rawData: r, error: i }), { subject: n, data: r };
|
|
654
654
|
}
|
|
655
655
|
};
|
|
656
|
-
function
|
|
656
|
+
function yt({
|
|
657
657
|
statsSignal: e,
|
|
658
658
|
dataChannelSignal: t,
|
|
659
659
|
onVideoStateChange: n,
|
|
@@ -661,7 +661,7 @@ function pt({
|
|
|
661
661
|
}) {
|
|
662
662
|
e === w.Start && t === w.Start ? n == null || n(w.Start) : e === w.Stop && t === w.Stop && (n == null || n(w.Stop, r));
|
|
663
663
|
}
|
|
664
|
-
function
|
|
664
|
+
function kt({
|
|
665
665
|
statsSignal: e,
|
|
666
666
|
dataChannelSignal: t,
|
|
667
667
|
onVideoStateChange: n,
|
|
@@ -670,29 +670,29 @@ function yt({
|
|
|
670
670
|
}) {
|
|
671
671
|
e === w.Start ? n == null || n(w.Start) : e === w.Stop && (n == null || n(w.Stop, i)), t === w.Start ? r == null || r(O.Talking) : t === w.Stop && (r == null || r(O.Idle));
|
|
672
672
|
}
|
|
673
|
-
function
|
|
673
|
+
function le({
|
|
674
674
|
statsSignal: e,
|
|
675
675
|
dataChannelSignal: t,
|
|
676
676
|
onVideoStateChange: n,
|
|
677
677
|
onAgentActivityStateChange: r,
|
|
678
678
|
streamType: i,
|
|
679
|
-
report:
|
|
679
|
+
report: s
|
|
680
680
|
}) {
|
|
681
|
-
i === J.Legacy ?
|
|
681
|
+
i === J.Legacy ? yt({ statsSignal: e, dataChannelSignal: t, onVideoStateChange: n, report: s }) : i === J.Fluent && kt({
|
|
682
682
|
statsSignal: e,
|
|
683
683
|
dataChannelSignal: t,
|
|
684
684
|
onVideoStateChange: n,
|
|
685
685
|
onAgentActivityStateChange: r,
|
|
686
|
-
report:
|
|
686
|
+
report: s
|
|
687
687
|
});
|
|
688
688
|
}
|
|
689
|
-
async function
|
|
689
|
+
async function Dt(e, t, { debug: n = !1, callbacks: r, auth: i, baseURL: s = ee, analytics: c }) {
|
|
690
690
|
var Y;
|
|
691
|
-
const a =
|
|
692
|
-
let d = !1, l = !1,
|
|
693
|
-
const { startConnection:
|
|
691
|
+
const a = ot(n, "WebRTCStreamingManager"), o = vt(a);
|
|
692
|
+
let d = !1, l = !1, v = w.Stop, M = w.Stop;
|
|
693
|
+
const { startConnection: b, sendStreamRequest: $, close: z, createStream: U, addIceCandidate: W } = st(
|
|
694
694
|
i,
|
|
695
|
-
|
|
695
|
+
s,
|
|
696
696
|
e,
|
|
697
697
|
r.onError
|
|
698
698
|
), {
|
|
@@ -702,26 +702,26 @@ async function vt(e, t, { debug: n = !1, callbacks: r, auth: i, baseURL: o = ee,
|
|
|
702
702
|
session_id: h,
|
|
703
703
|
fluent: p,
|
|
704
704
|
interrupt_enabled: _,
|
|
705
|
-
triggers_enabled:
|
|
705
|
+
triggers_enabled: y
|
|
706
706
|
} = await U(t);
|
|
707
707
|
(Y = r.onStreamCreated) == null || Y.call(r, { stream_id: C, session_id: h, agent_id: e });
|
|
708
|
-
const f = new
|
|
708
|
+
const f = new pt({ iceServers: u }), S = f.createDataChannel("JanusDataChannel");
|
|
709
709
|
if (!h)
|
|
710
710
|
throw new Error("Could not create session_id");
|
|
711
711
|
const T = p ? J.Fluent : J.Legacy;
|
|
712
712
|
c.enrich({
|
|
713
713
|
"stream-type": T
|
|
714
714
|
});
|
|
715
|
-
const
|
|
715
|
+
const P = t.stream_warmup && !p, D = () => d, I = () => {
|
|
716
716
|
var m;
|
|
717
717
|
d = !0, l && ((m = r.onConnectionStateChange) == null || m.call(r, R.Connected));
|
|
718
|
-
}, k =
|
|
718
|
+
}, k = wt(
|
|
719
719
|
f,
|
|
720
720
|
D,
|
|
721
721
|
I,
|
|
722
|
-
(m, g) =>
|
|
722
|
+
(m, g) => le({
|
|
723
723
|
statsSignal: M = m,
|
|
724
|
-
dataChannelSignal: T === J.Legacy ?
|
|
724
|
+
dataChannelSignal: T === J.Legacy ? v : void 0,
|
|
725
725
|
onVideoStateChange: r.onVideoStateChange,
|
|
726
726
|
onAgentActivityStateChange: r.onAgentActivityStateChange,
|
|
727
727
|
report: g,
|
|
@@ -731,7 +731,7 @@ async function vt(e, t, { debug: n = !1, callbacks: r, auth: i, baseURL: o = ee,
|
|
|
731
731
|
var g;
|
|
732
732
|
return (g = r.onConnectivityStateChange) == null ? void 0 : g.call(r, m);
|
|
733
733
|
},
|
|
734
|
-
|
|
734
|
+
P
|
|
735
735
|
);
|
|
736
736
|
f.onicecandidate = (m) => {
|
|
737
737
|
var g;
|
|
@@ -746,59 +746,59 @@ async function vt(e, t, { debug: n = !1, callbacks: r, auth: i, baseURL: o = ee,
|
|
|
746
746
|
},
|
|
747
747
|
h
|
|
748
748
|
) : W(C, { candidate: null }, h);
|
|
749
|
-
} catch (
|
|
750
|
-
(g = r.onError) == null || g.call(r,
|
|
749
|
+
} catch (A) {
|
|
750
|
+
(g = r.onError) == null || g.call(r, A, { streamId: C });
|
|
751
751
|
}
|
|
752
752
|
}, S.onopen = () => {
|
|
753
|
-
l = !0, (!
|
|
753
|
+
l = !0, (!P || d) && I();
|
|
754
754
|
};
|
|
755
755
|
const x = (m) => {
|
|
756
756
|
var g;
|
|
757
757
|
(g = r.onVideoIdChange) == null || g.call(r, m);
|
|
758
758
|
};
|
|
759
|
-
function
|
|
760
|
-
if (m ===
|
|
761
|
-
const
|
|
762
|
-
x(
|
|
759
|
+
function L(m, g) {
|
|
760
|
+
if (m === j.StreamStarted && typeof g == "object" && "metadata" in g) {
|
|
761
|
+
const A = g.metadata;
|
|
762
|
+
x(A.videoId);
|
|
763
763
|
}
|
|
764
|
-
m ===
|
|
764
|
+
m === j.StreamDone && x(null), v = m === j.StreamStarted ? w.Start : w.Stop, le({
|
|
765
765
|
statsSignal: T === J.Legacy ? M : void 0,
|
|
766
|
-
dataChannelSignal:
|
|
766
|
+
dataChannelSignal: v,
|
|
767
767
|
onVideoStateChange: r.onVideoStateChange,
|
|
768
768
|
onAgentActivityStateChange: r.onAgentActivityStateChange,
|
|
769
769
|
streamType: T
|
|
770
770
|
});
|
|
771
771
|
}
|
|
772
772
|
function F(m, g) {
|
|
773
|
-
const
|
|
774
|
-
|
|
773
|
+
const A = typeof g == "string" ? g : g == null ? void 0 : g.metadata;
|
|
774
|
+
A && c.enrich({ streamMetadata: A }), c.track("agent-chat", { event: "ready" });
|
|
775
775
|
}
|
|
776
776
|
const N = {
|
|
777
|
-
[
|
|
778
|
-
[
|
|
779
|
-
[
|
|
777
|
+
[j.StreamStarted]: L,
|
|
778
|
+
[j.StreamDone]: L,
|
|
779
|
+
[j.StreamReady]: F
|
|
780
780
|
};
|
|
781
781
|
S.onmessage = (m) => {
|
|
782
782
|
var Q;
|
|
783
|
-
const { subject: g, data:
|
|
784
|
-
(Q = N[g]) == null || Q.call(N, g,
|
|
783
|
+
const { subject: g, data: A } = o(m.data);
|
|
784
|
+
(Q = N[g]) == null || Q.call(N, g, A);
|
|
785
785
|
}, f.oniceconnectionstatechange = () => {
|
|
786
786
|
var g;
|
|
787
787
|
a("peerConnection.oniceconnectionstatechange => " + f.iceConnectionState);
|
|
788
|
-
const m =
|
|
788
|
+
const m = de(f.iceConnectionState);
|
|
789
789
|
m !== R.Connected && ((g = r.onConnectionStateChange) == null || g.call(r, m));
|
|
790
790
|
}, f.ontrack = (m) => {
|
|
791
791
|
var g;
|
|
792
792
|
a("peerConnection.ontrack", m), (g = r.onSrcObjectReady) == null || g.call(r, m.streams[0]);
|
|
793
793
|
}, await f.setRemoteDescription(K), a("set remote description OK");
|
|
794
794
|
const X = await f.createAnswer();
|
|
795
|
-
return a("create answer OK"), await f.setLocalDescription(X), a("set local description OK"), await
|
|
795
|
+
return a("create answer OK"), await f.setLocalDescription(X), a("set local description OK"), await b(C, X, h), a("start connection OK"), {
|
|
796
796
|
/**
|
|
797
797
|
* Method to send request to server to get clip or talk depend on you payload
|
|
798
798
|
* @param payload
|
|
799
799
|
*/
|
|
800
800
|
speak(m) {
|
|
801
|
-
return
|
|
801
|
+
return $(C, h, m);
|
|
802
802
|
},
|
|
803
803
|
/**
|
|
804
804
|
* Method to close RTC connection
|
|
@@ -806,7 +806,7 @@ async function vt(e, t, { debug: n = !1, callbacks: r, auth: i, baseURL: o = ee,
|
|
|
806
806
|
async disconnect() {
|
|
807
807
|
var m;
|
|
808
808
|
if (C) {
|
|
809
|
-
const g =
|
|
809
|
+
const g = de(f.iceConnectionState);
|
|
810
810
|
if (f) {
|
|
811
811
|
if (g === R.New) {
|
|
812
812
|
clearInterval(k);
|
|
@@ -815,10 +815,10 @@ async function vt(e, t, { debug: n = !1, callbacks: r, auth: i, baseURL: o = ee,
|
|
|
815
815
|
f.close(), f.oniceconnectionstatechange = null, f.onnegotiationneeded = null, f.onicecandidate = null, f.ontrack = null;
|
|
816
816
|
}
|
|
817
817
|
try {
|
|
818
|
-
g === R.Connected && await z(C, h).catch((
|
|
818
|
+
g === R.Connected && await z(C, h).catch((A) => {
|
|
819
819
|
});
|
|
820
|
-
} catch (
|
|
821
|
-
a("Error on close stream connection",
|
|
820
|
+
} catch (A) {
|
|
821
|
+
a("Error on close stream connection", A);
|
|
822
822
|
}
|
|
823
823
|
(m = r.onAgentActivityStateChange) == null || m.call(r, O.Idle), clearInterval(k);
|
|
824
824
|
}
|
|
@@ -827,7 +827,7 @@ async function vt(e, t, { debug: n = !1, callbacks: r, auth: i, baseURL: o = ee,
|
|
|
827
827
|
* Method to send data channel messages to the server
|
|
828
828
|
*/
|
|
829
829
|
sendDataChannelMessage(m) {
|
|
830
|
-
var g,
|
|
830
|
+
var g, A;
|
|
831
831
|
if (!d || S.readyState !== "open") {
|
|
832
832
|
a("Data channel is not ready for sending messages"), (g = r.onError) == null || g.call(r, new Error("Data channel is not ready for sending messages"), {
|
|
833
833
|
streamId: C
|
|
@@ -837,7 +837,7 @@ async function vt(e, t, { debug: n = !1, callbacks: r, auth: i, baseURL: o = ee,
|
|
|
837
837
|
try {
|
|
838
838
|
S.send(m);
|
|
839
839
|
} catch (Q) {
|
|
840
|
-
a("Error sending data channel message", Q), (
|
|
840
|
+
a("Error sending data channel message", Q), (A = r.onError) == null || A.call(r, Q, { streamId: C });
|
|
841
841
|
}
|
|
842
842
|
},
|
|
843
843
|
/**
|
|
@@ -850,23 +850,42 @@ async function vt(e, t, { debug: n = !1, callbacks: r, auth: i, baseURL: o = ee,
|
|
|
850
850
|
streamId: C,
|
|
851
851
|
streamType: T,
|
|
852
852
|
interruptAvailable: _ ?? !1,
|
|
853
|
-
triggersAvailable:
|
|
853
|
+
triggersAvailable: y ?? !1
|
|
854
854
|
};
|
|
855
855
|
}
|
|
856
|
-
|
|
857
|
-
async function
|
|
856
|
+
var se = /* @__PURE__ */ ((e) => (e.V1 = "v1", e.V2 = "v2", e))(se || {});
|
|
857
|
+
async function Ct(e, t, n) {
|
|
858
858
|
const r = e.id;
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
859
|
+
switch (t.version) {
|
|
860
|
+
case "v1": {
|
|
861
|
+
const { version: i, ...s } = t;
|
|
862
|
+
return Dt(r, s, n);
|
|
863
|
+
}
|
|
864
|
+
case "v2": {
|
|
865
|
+
const { version: i, ...s } = t;
|
|
866
|
+
switch (s.transport_provider) {
|
|
867
|
+
case oe.Livekit:
|
|
868
|
+
const { createLiveKitStreamingManager: c } = await import("./livekit-manager-B2cn3NW6.js");
|
|
869
|
+
return c(r, s, n);
|
|
870
|
+
default:
|
|
871
|
+
throw new Error(`Unsupported transport provider: ${s.transport_provider}`);
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
default:
|
|
875
|
+
throw new Error(`Invalid stream version: ${t.version}`);
|
|
876
|
+
}
|
|
864
877
|
}
|
|
865
|
-
function
|
|
866
|
-
|
|
878
|
+
function Rt(e) {
|
|
879
|
+
return {
|
|
880
|
+
transport_provider: oe.Livekit,
|
|
881
|
+
chat_id: e == null ? void 0 : e.chatId
|
|
882
|
+
};
|
|
883
|
+
}
|
|
884
|
+
function St(e) {
|
|
885
|
+
var i, s, c;
|
|
867
886
|
const { streamOptions: t } = e ?? {}, n = e != null && e.distinctId || ((i = e == null ? void 0 : e.mixpanelAdditionalProperties) == null ? void 0 : i.plan) !== void 0 ? {
|
|
868
887
|
...e != null && e.distinctId ? { distinct_id: e.distinctId } : {},
|
|
869
|
-
...((
|
|
888
|
+
...((s = e == null ? void 0 : e.mixpanelAdditionalProperties) == null ? void 0 : s.plan) !== void 0 ? { plan: (c = e.mixpanelAdditionalProperties) == null ? void 0 : c.plan } : {}
|
|
870
889
|
} : void 0;
|
|
871
890
|
return { ...{
|
|
872
891
|
output_resolution: t == null ? void 0 : t.outputResolution,
|
|
@@ -876,10 +895,13 @@ function Ct(e) {
|
|
|
876
895
|
fluent: t == null ? void 0 : t.fluent
|
|
877
896
|
}, ...n && { end_user_data: n } };
|
|
878
897
|
}
|
|
879
|
-
function
|
|
880
|
-
|
|
898
|
+
function It(e, t) {
|
|
899
|
+
return Ke(e.presenter.type) ? { version: se.V2, ...Rt(t) } : { version: se.V1, ...St(t) };
|
|
881
900
|
}
|
|
882
|
-
function
|
|
901
|
+
function Et(e, t, n, r, i) {
|
|
902
|
+
i === J.Fluent ? Mt(e, t, n, r, i) : Tt(e, t, n, r, i);
|
|
903
|
+
}
|
|
904
|
+
function Mt(e, t, n, r, i) {
|
|
883
905
|
e === w.Start ? r.track("stream-session", { event: "start", "stream-type": i }) : e === w.Stop && r.track("stream-session", {
|
|
884
906
|
event: "stop",
|
|
885
907
|
is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
|
|
@@ -888,12 +910,12 @@ function St(e, t, n, r, i) {
|
|
|
888
910
|
...n
|
|
889
911
|
});
|
|
890
912
|
}
|
|
891
|
-
function
|
|
892
|
-
|
|
913
|
+
function _t(e, t, n, r) {
|
|
914
|
+
B.get() <= 0 || (e === w.Start ? n.linkTrack(
|
|
893
915
|
"agent-video",
|
|
894
|
-
{ event: "start", latency:
|
|
916
|
+
{ event: "start", latency: B.get(!0), "stream-type": r },
|
|
895
917
|
"start",
|
|
896
|
-
[
|
|
918
|
+
[j.StreamVideoCreated]
|
|
897
919
|
) : e === w.Stop && n.linkTrack(
|
|
898
920
|
"agent-video",
|
|
899
921
|
{
|
|
@@ -903,15 +925,15 @@ function It(e, t, n, r) {
|
|
|
903
925
|
"stream-type": r
|
|
904
926
|
},
|
|
905
927
|
"done",
|
|
906
|
-
[
|
|
928
|
+
[j.StreamVideoDone]
|
|
907
929
|
));
|
|
908
930
|
}
|
|
909
|
-
function
|
|
910
|
-
|
|
931
|
+
function Tt(e, t, n, r, i) {
|
|
932
|
+
B.get() <= 0 || (e === w.Start ? r.linkTrack(
|
|
911
933
|
"agent-video",
|
|
912
|
-
{ event: "start", latency:
|
|
934
|
+
{ event: "start", latency: B.get(!0), "stream-type": i },
|
|
913
935
|
"start",
|
|
914
|
-
[
|
|
936
|
+
[j.StreamVideoCreated]
|
|
915
937
|
) : e === w.Stop && r.linkTrack(
|
|
916
938
|
"agent-video",
|
|
917
939
|
{
|
|
@@ -922,71 +944,71 @@ function Et(e, t, n, r, i) {
|
|
|
922
944
|
...n
|
|
923
945
|
},
|
|
924
946
|
"done",
|
|
925
|
-
[
|
|
947
|
+
[j.StreamVideoDone]
|
|
926
948
|
));
|
|
927
949
|
}
|
|
928
|
-
function
|
|
929
|
-
return
|
|
950
|
+
function At(e, t, n) {
|
|
951
|
+
return B.reset(), new Promise(async (r, i) => {
|
|
930
952
|
try {
|
|
931
|
-
let
|
|
932
|
-
|
|
953
|
+
let s;
|
|
954
|
+
s = await Ct(e, It(e, t), {
|
|
933
955
|
...t,
|
|
934
956
|
analytics: n,
|
|
935
957
|
callbacks: {
|
|
936
958
|
...t.callbacks,
|
|
937
959
|
onConnectionStateChange: (c) => {
|
|
938
|
-
var a,
|
|
939
|
-
(
|
|
960
|
+
var a, o;
|
|
961
|
+
(o = (a = t.callbacks).onConnectionStateChange) == null || o.call(a, c), c === R.Connected && r(s);
|
|
940
962
|
},
|
|
941
963
|
onVideoStateChange: (c, a) => {
|
|
942
|
-
var
|
|
943
|
-
(d = (
|
|
964
|
+
var o, d;
|
|
965
|
+
(d = (o = t.callbacks).onVideoStateChange) == null || d.call(o, c), Et(
|
|
944
966
|
c,
|
|
945
967
|
e,
|
|
946
968
|
a,
|
|
947
969
|
n,
|
|
948
|
-
|
|
970
|
+
s.streamType
|
|
949
971
|
);
|
|
950
972
|
},
|
|
951
973
|
onAgentActivityStateChange: (c) => {
|
|
952
|
-
var a,
|
|
953
|
-
(
|
|
974
|
+
var a, o;
|
|
975
|
+
(o = (a = t.callbacks).onAgentActivityStateChange) == null || o.call(a, c), c === O.Talking ? ae.update() : ae.reset(), _t(
|
|
954
976
|
c === O.Talking ? w.Start : w.Stop,
|
|
955
977
|
e,
|
|
956
978
|
n,
|
|
957
|
-
|
|
979
|
+
s.streamType
|
|
958
980
|
);
|
|
959
981
|
}
|
|
960
982
|
}
|
|
961
983
|
});
|
|
962
|
-
} catch (
|
|
963
|
-
i(
|
|
984
|
+
} catch (s) {
|
|
985
|
+
i(s);
|
|
964
986
|
}
|
|
965
987
|
});
|
|
966
988
|
}
|
|
967
|
-
async function
|
|
968
|
-
var
|
|
969
|
-
const
|
|
970
|
-
return
|
|
989
|
+
async function jt(e, t, n, r, i) {
|
|
990
|
+
var d, l, v, M;
|
|
991
|
+
const s = await De(e, n, r, t.mode, t.persistentChat, i), { chat: c, chatMode: a } = s, o = await At(e, { ...t, chatId: c == null ? void 0 : c.id }, r);
|
|
992
|
+
return a && a !== t.mode && (t.mode = a, (l = (d = t.callbacks).onModeChange) == null || l.call(d, a), a !== E.Functional) ? ((M = (v = t.callbacks).onError) == null || M.call(v, new Ie(a)), o == null || o.disconnect(), { chat: c }) : { chat: c, streamingManager: o };
|
|
971
993
|
}
|
|
972
|
-
async function
|
|
994
|
+
async function Lt(e, t) {
|
|
973
995
|
var W, C, K;
|
|
974
996
|
let n = !0, r = null;
|
|
975
|
-
const i = t.mixpanelKey ||
|
|
997
|
+
const i = t.mixpanelKey || Fe, s = t.wsURL || ze, c = t.baseURL || ee, a = {
|
|
976
998
|
messages: [],
|
|
977
999
|
chatMode: t.mode || E.Functional
|
|
978
|
-
},
|
|
1000
|
+
}, o = Ye({
|
|
979
1001
|
token: i,
|
|
980
1002
|
agentId: e,
|
|
981
1003
|
isEnabled: t.enableAnalitics,
|
|
982
1004
|
distinctId: t.distinctId,
|
|
983
1005
|
mixpanelAdditionalProperties: t.mixpanelAdditionalProperties
|
|
984
1006
|
});
|
|
985
|
-
|
|
986
|
-
const d =
|
|
987
|
-
|
|
988
|
-
const { onMessage:
|
|
989
|
-
|
|
1007
|
+
o.track("agent-sdk", { event: "init" });
|
|
1008
|
+
const d = pe(t.auth, c, t.callbacks.onError), l = await d.getById(e);
|
|
1009
|
+
o.enrich(Ve(l));
|
|
1010
|
+
const { onMessage: v, clearQueue: M } = it(
|
|
1011
|
+
o,
|
|
990
1012
|
a,
|
|
991
1013
|
t,
|
|
992
1014
|
l,
|
|
@@ -995,37 +1017,37 @@ async function jt(e, t) {
|
|
|
995
1017
|
return (u = a.socketManager) == null ? void 0 : u.disconnect();
|
|
996
1018
|
}
|
|
997
1019
|
);
|
|
998
|
-
a.messages =
|
|
999
|
-
const
|
|
1020
|
+
a.messages = Qe(t.initialMessages), (C = (W = t.callbacks).onNewMessage) == null || C.call(W, [...a.messages], "answer");
|
|
1021
|
+
const b = (u) => {
|
|
1000
1022
|
r = u;
|
|
1001
1023
|
};
|
|
1002
|
-
|
|
1003
|
-
async function
|
|
1004
|
-
var S, T,
|
|
1005
|
-
(T = (S = t.callbacks).onConnectionStateChange) == null || T.call(S, R.Connecting),
|
|
1006
|
-
const h = t.mode === E.DirectPlayback ? Promise.resolve(void 0) :
|
|
1007
|
-
() =>
|
|
1024
|
+
o.track("agent-sdk", { event: "loaded", ...He(l) });
|
|
1025
|
+
async function $(u) {
|
|
1026
|
+
var S, T, P, D, I, k, x;
|
|
1027
|
+
(T = (S = t.callbacks).onConnectionStateChange) == null || T.call(S, R.Connecting), B.reset(), u && !n && (delete a.chat, (D = (P = t.callbacks).onNewMessage) == null || D.call(P, [...a.messages], "answer"));
|
|
1028
|
+
const h = t.mode === E.DirectPlayback ? Promise.resolve(void 0) : rt(t.auth, s, { onMessage: v, onError: t.callbacks.onError }), p = ne(
|
|
1029
|
+
() => jt(
|
|
1008
1030
|
l,
|
|
1009
|
-
{ ...t, callbacks: { ...t.callbacks, onVideoIdChange:
|
|
1031
|
+
{ ...t, callbacks: { ...t.callbacks, onVideoIdChange: b } },
|
|
1010
1032
|
d,
|
|
1011
|
-
|
|
1033
|
+
o,
|
|
1012
1034
|
a.chat
|
|
1013
1035
|
),
|
|
1014
1036
|
{
|
|
1015
1037
|
limit: 3,
|
|
1016
|
-
timeout:
|
|
1038
|
+
timeout: $e,
|
|
1017
1039
|
timeoutErrorMessage: "Timeout initializing the stream",
|
|
1018
1040
|
// Retry on all errors except for connection errors and rate limit errors, these are already handled in client level.
|
|
1019
|
-
shouldRetryFn: (
|
|
1041
|
+
shouldRetryFn: (L) => (L == null ? void 0 : L.message) !== "Could not connect" && L.status !== 429,
|
|
1020
1042
|
delayMs: 1e3
|
|
1021
1043
|
}
|
|
1022
|
-
).catch((
|
|
1044
|
+
).catch((L) => {
|
|
1023
1045
|
var F, N;
|
|
1024
|
-
throw U(E.Maintenance), (N = (F = t.callbacks).onConnectionStateChange) == null || N.call(F, R.Fail),
|
|
1025
|
-
}), [_, { streamingManager:
|
|
1026
|
-
f && f.id !== ((I = a.chat) == null ? void 0 : I.id) && ((x = (k = t.callbacks).onNewChat) == null || x.call(k, f.id)), a.streamingManager =
|
|
1046
|
+
throw U(E.Maintenance), (N = (F = t.callbacks).onConnectionStateChange) == null || N.call(F, R.Fail), L;
|
|
1047
|
+
}), [_, { streamingManager: y, chat: f }] = await Promise.all([h, p]);
|
|
1048
|
+
f && f.id !== ((I = a.chat) == null ? void 0 : I.id) && ((x = (k = t.callbacks).onNewChat) == null || x.call(k, f.id)), a.streamingManager = y, a.socketManager = _, a.chat = f, n = !1, o.enrich({
|
|
1027
1049
|
chatId: f == null ? void 0 : f.id,
|
|
1028
|
-
streamId:
|
|
1050
|
+
streamId: y == null ? void 0 : y.streamId,
|
|
1029
1051
|
mode: a.chatMode
|
|
1030
1052
|
}), U((f == null ? void 0 : f.chat_mode) ?? t.mode ?? E.Functional);
|
|
1031
1053
|
}
|
|
@@ -1035,7 +1057,7 @@ async function jt(e, t) {
|
|
|
1035
1057
|
}
|
|
1036
1058
|
async function U(u) {
|
|
1037
1059
|
var h, p;
|
|
1038
|
-
u !== a.chatMode && (
|
|
1060
|
+
u !== a.chatMode && (o.track("agent-mode-change", { mode: u }), a.chatMode = u, a.chatMode !== E.Functional && await z(), (p = (h = t.callbacks).onModeChange) == null || p.call(h, u));
|
|
1039
1061
|
}
|
|
1040
1062
|
return {
|
|
1041
1063
|
agent: l,
|
|
@@ -1054,29 +1076,29 @@ async function jt(e, t) {
|
|
|
1054
1076
|
starterMessages: ((K = l.knowledge) == null ? void 0 : K.starter_message) || [],
|
|
1055
1077
|
getSTTToken: () => d.getSTTToken(l.id),
|
|
1056
1078
|
changeMode: U,
|
|
1057
|
-
enrichAnalytics:
|
|
1079
|
+
enrichAnalytics: o.enrich,
|
|
1058
1080
|
async connect() {
|
|
1059
|
-
await
|
|
1081
|
+
await $(!0), o.track("agent-chat", {
|
|
1060
1082
|
event: "connect",
|
|
1061
1083
|
mode: a.chatMode
|
|
1062
1084
|
});
|
|
1063
1085
|
},
|
|
1064
1086
|
async reconnect() {
|
|
1065
|
-
await z(), await
|
|
1087
|
+
await z(), await $(!1), o.track("agent-chat", {
|
|
1066
1088
|
event: "reconnect",
|
|
1067
1089
|
mode: a.chatMode
|
|
1068
1090
|
});
|
|
1069
1091
|
},
|
|
1070
1092
|
async disconnect() {
|
|
1071
|
-
await z(),
|
|
1093
|
+
await z(), o.track("agent-chat", {
|
|
1072
1094
|
event: "disconnect",
|
|
1073
1095
|
mode: a.chatMode
|
|
1074
1096
|
});
|
|
1075
1097
|
},
|
|
1076
1098
|
async chat(u) {
|
|
1077
|
-
var
|
|
1099
|
+
var y, f, S, T, P;
|
|
1078
1100
|
const h = () => {
|
|
1079
|
-
if (
|
|
1101
|
+
if (me(t.mode))
|
|
1080
1102
|
throw new H(`${t.mode} is enabled, chat is disabled`);
|
|
1081
1103
|
if (u.length >= 800)
|
|
1082
1104
|
throw new H("Message cannot be more than 800 characters");
|
|
@@ -1093,15 +1115,15 @@ async function jt(e, t) {
|
|
|
1093
1115
|
}, p = async () => {
|
|
1094
1116
|
var D, I;
|
|
1095
1117
|
if (!a.chat) {
|
|
1096
|
-
const k = await
|
|
1118
|
+
const k = await De(
|
|
1097
1119
|
l,
|
|
1098
1120
|
d,
|
|
1099
|
-
|
|
1121
|
+
o,
|
|
1100
1122
|
a.chatMode,
|
|
1101
1123
|
t.persistentChat
|
|
1102
1124
|
);
|
|
1103
1125
|
if (!k.chat)
|
|
1104
|
-
throw new
|
|
1126
|
+
throw new Se(a.chatMode, !!t.persistentChat);
|
|
1105
1127
|
a.chat = k.chat, (I = (D = t.callbacks).onNewChat) == null || I.call(D, a.chat.id);
|
|
1106
1128
|
}
|
|
1107
1129
|
return a.chat.id;
|
|
@@ -1115,10 +1137,10 @@ async function jt(e, t) {
|
|
|
1115
1137
|
chatMode: a.chatMode,
|
|
1116
1138
|
streamId: (k = a.streamingManager) == null ? void 0 : k.streamId,
|
|
1117
1139
|
sessionId: (x = a.streamingManager) == null ? void 0 : x.sessionId,
|
|
1118
|
-
messages: D.map(({ matches:
|
|
1140
|
+
messages: D.map(({ matches: L, ...F }) => F)
|
|
1119
1141
|
},
|
|
1120
1142
|
{
|
|
1121
|
-
...
|
|
1143
|
+
...ke(a.chatMode),
|
|
1122
1144
|
skipErrorHandler: !0
|
|
1123
1145
|
}
|
|
1124
1146
|
);
|
|
@@ -1131,72 +1153,72 @@ async function jt(e, t) {
|
|
|
1131
1153
|
return !((N = k == null ? void 0 : k.message) == null ? void 0 : N.includes("Stream Error")) && !x ? ((Y = (X = t.callbacks).onError) == null || Y.call(X, k), !1) : !0;
|
|
1132
1154
|
},
|
|
1133
1155
|
onRetry: async () => {
|
|
1134
|
-
await z(), await
|
|
1156
|
+
await z(), await $(!1);
|
|
1135
1157
|
}
|
|
1136
1158
|
}
|
|
1137
1159
|
);
|
|
1138
1160
|
try {
|
|
1139
1161
|
M(), h(), a.messages.push({
|
|
1140
|
-
id:
|
|
1162
|
+
id: q(),
|
|
1141
1163
|
role: "user",
|
|
1142
1164
|
content: u,
|
|
1143
|
-
created_at: new Date(
|
|
1144
|
-
}), (f = (
|
|
1165
|
+
created_at: new Date(B.update()).toISOString()
|
|
1166
|
+
}), (f = (y = t.callbacks).onNewMessage) == null || f.call(y, [...a.messages], "user");
|
|
1145
1167
|
const D = await p(), I = await _([...a.messages], D);
|
|
1146
1168
|
return a.messages.push({
|
|
1147
|
-
id:
|
|
1169
|
+
id: q(),
|
|
1148
1170
|
role: "assistant",
|
|
1149
1171
|
content: I.result || "",
|
|
1150
1172
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1151
1173
|
context: I.context,
|
|
1152
1174
|
matches: I.matches
|
|
1153
|
-
}),
|
|
1175
|
+
}), o.track("agent-message-send", {
|
|
1154
1176
|
event: "success",
|
|
1155
1177
|
messages: a.messages.length + 1
|
|
1156
|
-
}), I.result && ((T = (S = t.callbacks).onNewMessage) == null || T.call(S, [...a.messages], "answer"),
|
|
1157
|
-
latency:
|
|
1178
|
+
}), I.result && ((T = (S = t.callbacks).onNewMessage) == null || T.call(S, [...a.messages], "answer"), o.track("agent-message-received", {
|
|
1179
|
+
latency: B.get(!0),
|
|
1158
1180
|
messages: a.messages.length
|
|
1159
1181
|
})), I;
|
|
1160
1182
|
} catch (D) {
|
|
1161
|
-
throw ((
|
|
1183
|
+
throw ((P = a.messages[a.messages.length - 1]) == null ? void 0 : P.role) === "assistant" && a.messages.pop(), o.track("agent-message-send", {
|
|
1162
1184
|
event: "error",
|
|
1163
1185
|
messages: a.messages.length
|
|
1164
1186
|
}), D;
|
|
1165
1187
|
}
|
|
1166
1188
|
},
|
|
1167
1189
|
rate(u, h, p) {
|
|
1168
|
-
var f, S, T,
|
|
1190
|
+
var f, S, T, P;
|
|
1169
1191
|
const _ = a.messages.find((D) => D.id === u);
|
|
1170
1192
|
if (a.chat) {
|
|
1171
1193
|
if (!_)
|
|
1172
1194
|
throw new Error("Message not found");
|
|
1173
1195
|
} else throw new Error("Chat is not initialized");
|
|
1174
|
-
const
|
|
1175
|
-
return
|
|
1196
|
+
const y = ((f = _.matches) == null ? void 0 : f.map((D) => [D.document_id, D.id])) ?? [];
|
|
1197
|
+
return o.track("agent-rate", {
|
|
1176
1198
|
event: p ? "update" : "create",
|
|
1177
1199
|
thumb: h === 1 ? "up" : "down",
|
|
1178
1200
|
knowledge_id: ((S = l.knowledge) == null ? void 0 : S.id) ?? "",
|
|
1179
|
-
matches:
|
|
1201
|
+
matches: y,
|
|
1180
1202
|
score: h
|
|
1181
1203
|
}), p ? d.updateRating(l.id, a.chat.id, p, {
|
|
1182
1204
|
knowledge_id: ((T = l.knowledge) == null ? void 0 : T.id) ?? "",
|
|
1183
1205
|
message_id: u,
|
|
1184
|
-
matches:
|
|
1206
|
+
matches: y,
|
|
1185
1207
|
score: h
|
|
1186
1208
|
}) : d.createRating(l.id, a.chat.id, {
|
|
1187
|
-
knowledge_id: ((
|
|
1209
|
+
knowledge_id: ((P = l.knowledge) == null ? void 0 : P.id) ?? "",
|
|
1188
1210
|
message_id: u,
|
|
1189
|
-
matches:
|
|
1211
|
+
matches: y,
|
|
1190
1212
|
score: h
|
|
1191
1213
|
});
|
|
1192
1214
|
},
|
|
1193
1215
|
deleteRate(u) {
|
|
1194
1216
|
if (!a.chat)
|
|
1195
1217
|
throw new Error("Chat is not initialized");
|
|
1196
|
-
return
|
|
1218
|
+
return o.track("agent-rate-delete", { type: "text" }), d.deleteRating(l.id, a.chat.id, u);
|
|
1197
1219
|
},
|
|
1198
1220
|
async speak(u) {
|
|
1199
|
-
var
|
|
1221
|
+
var y, f, S;
|
|
1200
1222
|
function h() {
|
|
1201
1223
|
if (typeof u == "string") {
|
|
1202
1224
|
if (!l.presenter.voice)
|
|
@@ -1221,12 +1243,12 @@ async function jt(e, t) {
|
|
|
1221
1243
|
return u;
|
|
1222
1244
|
}
|
|
1223
1245
|
const p = h();
|
|
1224
|
-
if (
|
|
1225
|
-
id:
|
|
1246
|
+
if (o.track("agent-speak", p), B.update(), a.messages && p.type === "text" && (a.messages.push({
|
|
1247
|
+
id: q(),
|
|
1226
1248
|
role: "assistant",
|
|
1227
1249
|
content: p.input,
|
|
1228
|
-
created_at: new Date(
|
|
1229
|
-
}), (f = (
|
|
1250
|
+
created_at: new Date(B.get(!0)).toISOString()
|
|
1251
|
+
}), (f = (y = t.callbacks).onNewMessage) == null || f.call(y, [...a.messages], "answer")), Ne(a.chatMode))
|
|
1230
1252
|
return {
|
|
1231
1253
|
duration: 0,
|
|
1232
1254
|
video_id: "",
|
|
@@ -1240,49 +1262,49 @@ async function jt(e, t) {
|
|
|
1240
1262
|
});
|
|
1241
1263
|
},
|
|
1242
1264
|
async interrupt({ type: u }) {
|
|
1243
|
-
var p, _,
|
|
1244
|
-
|
|
1265
|
+
var p, _, y;
|
|
1266
|
+
Ze(a.streamingManager, (p = a.streamingManager) == null ? void 0 : p.streamType, r);
|
|
1245
1267
|
const h = a.messages[a.messages.length - 1];
|
|
1246
|
-
|
|
1268
|
+
o.track("agent-video-interrupt", {
|
|
1247
1269
|
type: u || "click",
|
|
1248
1270
|
video_duration_to_interrupt: ae.get(!0),
|
|
1249
|
-
message_duration_to_interrupt:
|
|
1250
|
-
}), h.interrupted = !0, (
|
|
1271
|
+
message_duration_to_interrupt: B.get(!0)
|
|
1272
|
+
}), h.interrupted = !0, (y = (_ = t.callbacks).onNewMessage) == null || y.call(_, [...a.messages], "answer"), Ge(a.streamingManager, r);
|
|
1251
1273
|
}
|
|
1252
1274
|
};
|
|
1253
1275
|
}
|
|
1254
|
-
function
|
|
1255
|
-
const { getById: r } =
|
|
1276
|
+
function Bt(e, t, n) {
|
|
1277
|
+
const { getById: r } = pe(t, n || ee);
|
|
1256
1278
|
return r(e);
|
|
1257
1279
|
}
|
|
1258
1280
|
export {
|
|
1259
1281
|
O as A,
|
|
1260
1282
|
R as C,
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1283
|
+
Pe as D,
|
|
1284
|
+
be as K,
|
|
1285
|
+
_e as P,
|
|
1286
|
+
Ae as R,
|
|
1265
1287
|
J as S,
|
|
1266
|
-
|
|
1267
|
-
|
|
1288
|
+
oe as T,
|
|
1289
|
+
Me as U,
|
|
1268
1290
|
H as V,
|
|
1269
|
-
|
|
1270
|
-
|
|
1291
|
+
Ee as W,
|
|
1292
|
+
ot as a,
|
|
1271
1293
|
G as b,
|
|
1272
|
-
|
|
1294
|
+
we as c,
|
|
1273
1295
|
w as d,
|
|
1274
|
-
|
|
1296
|
+
j as e,
|
|
1275
1297
|
ee as f,
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1298
|
+
Se as g,
|
|
1299
|
+
Ie as h,
|
|
1300
|
+
Lt as i,
|
|
1301
|
+
Bt as j,
|
|
1302
|
+
Te as k,
|
|
1281
1303
|
E as l,
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1304
|
+
V as m,
|
|
1305
|
+
je as n,
|
|
1306
|
+
ue as o,
|
|
1307
|
+
Pt as p,
|
|
1308
|
+
Le as q,
|
|
1309
|
+
Be as r
|
|
1288
1310
|
};
|