@centive/aria-sdk 0.6.0 → 0.6.2
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/{AriaStandaloneUI-CIDTW7l1.js → AriaStandaloneUI-BBTTHhra.js} +2 -2
- package/dist/{AriaStandaloneUI-CIDTW7l1.js.map → AriaStandaloneUI-BBTTHhra.js.map} +1 -1
- package/dist/context/AriaProvider.d.ts.map +1 -1
- package/dist/index-gxG0JnP5.js +2561 -0
- package/dist/index-gxG0JnP5.js.map +1 -0
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5433 -36
- package/dist/index.js.map +1 -1
- package/dist/lib/AriaSessionManager.d.ts +18 -3
- package/dist/lib/AriaSessionManager.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/index-DU-J6kZV.js +0 -17
- package/dist/index-DU-J6kZV.js.map +0 -1
- package/dist/index-DfhP6F6y.js +0 -7959
- package/dist/index-DfhP6F6y.js.map +0 -1
|
@@ -0,0 +1,2561 @@
|
|
|
1
|
+
var me = {}, re = {}, be;
|
|
2
|
+
function et() {
|
|
3
|
+
if (be) return re;
|
|
4
|
+
be = 1, re.byteLength = a, re.toByteArray = g, re.fromByteArray = R;
|
|
5
|
+
for (var l = [], i = [], s = typeof Uint8Array < "u" ? Uint8Array : Array, o = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", f = 0, E = o.length; f < E; ++f)
|
|
6
|
+
l[f] = o[f], i[o.charCodeAt(f)] = f;
|
|
7
|
+
i[45] = 62, i[95] = 63;
|
|
8
|
+
function d(I) {
|
|
9
|
+
var C = I.length;
|
|
10
|
+
if (C % 4 > 0)
|
|
11
|
+
throw new Error("Invalid string. Length must be a multiple of 4");
|
|
12
|
+
var _ = I.indexOf("=");
|
|
13
|
+
_ === -1 && (_ = C);
|
|
14
|
+
var w = _ === C ? 0 : 4 - _ % 4;
|
|
15
|
+
return [_, w];
|
|
16
|
+
}
|
|
17
|
+
function a(I) {
|
|
18
|
+
var C = d(I), _ = C[0], w = C[1];
|
|
19
|
+
return (_ + w) * 3 / 4 - w;
|
|
20
|
+
}
|
|
21
|
+
function S(I, C, _) {
|
|
22
|
+
return (C + _) * 3 / 4 - _;
|
|
23
|
+
}
|
|
24
|
+
function g(I) {
|
|
25
|
+
var C, _ = d(I), w = _[0], N = _[1], O = new s(S(I, w, N)), B = 0, k = N > 0 ? w - 4 : w, b;
|
|
26
|
+
for (b = 0; b < k; b += 4)
|
|
27
|
+
C = i[I.charCodeAt(b)] << 18 | i[I.charCodeAt(b + 1)] << 12 | i[I.charCodeAt(b + 2)] << 6 | i[I.charCodeAt(b + 3)], O[B++] = C >> 16 & 255, O[B++] = C >> 8 & 255, O[B++] = C & 255;
|
|
28
|
+
return N === 2 && (C = i[I.charCodeAt(b)] << 2 | i[I.charCodeAt(b + 1)] >> 4, O[B++] = C & 255), N === 1 && (C = i[I.charCodeAt(b)] << 10 | i[I.charCodeAt(b + 1)] << 4 | i[I.charCodeAt(b + 2)] >> 2, O[B++] = C >> 8 & 255, O[B++] = C & 255), O;
|
|
29
|
+
}
|
|
30
|
+
function m(I) {
|
|
31
|
+
return l[I >> 18 & 63] + l[I >> 12 & 63] + l[I >> 6 & 63] + l[I & 63];
|
|
32
|
+
}
|
|
33
|
+
function u(I, C, _) {
|
|
34
|
+
for (var w, N = [], O = C; O < _; O += 3)
|
|
35
|
+
w = (I[O] << 16 & 16711680) + (I[O + 1] << 8 & 65280) + (I[O + 2] & 255), N.push(m(w));
|
|
36
|
+
return N.join("");
|
|
37
|
+
}
|
|
38
|
+
function R(I) {
|
|
39
|
+
for (var C, _ = I.length, w = _ % 3, N = [], O = 16383, B = 0, k = _ - w; B < k; B += O)
|
|
40
|
+
N.push(u(I, B, B + O > k ? k : B + O));
|
|
41
|
+
return w === 1 ? (C = I[_ - 1], N.push(
|
|
42
|
+
l[C >> 2] + l[C << 4 & 63] + "=="
|
|
43
|
+
)) : w === 2 && (C = (I[_ - 2] << 8) + I[_ - 1], N.push(
|
|
44
|
+
l[C >> 10] + l[C >> 4 & 63] + l[C << 2 & 63] + "="
|
|
45
|
+
)), N.join("");
|
|
46
|
+
}
|
|
47
|
+
return re;
|
|
48
|
+
}
|
|
49
|
+
var ce = {};
|
|
50
|
+
var De;
|
|
51
|
+
function tt() {
|
|
52
|
+
return De || (De = 1, ce.read = function(l, i, s, o, f) {
|
|
53
|
+
var E, d, a = f * 8 - o - 1, S = (1 << a) - 1, g = S >> 1, m = -7, u = s ? f - 1 : 0, R = s ? -1 : 1, I = l[i + u];
|
|
54
|
+
for (u += R, E = I & (1 << -m) - 1, I >>= -m, m += a; m > 0; E = E * 256 + l[i + u], u += R, m -= 8)
|
|
55
|
+
;
|
|
56
|
+
for (d = E & (1 << -m) - 1, E >>= -m, m += o; m > 0; d = d * 256 + l[i + u], u += R, m -= 8)
|
|
57
|
+
;
|
|
58
|
+
if (E === 0)
|
|
59
|
+
E = 1 - g;
|
|
60
|
+
else {
|
|
61
|
+
if (E === S)
|
|
62
|
+
return d ? NaN : (I ? -1 : 1) * (1 / 0);
|
|
63
|
+
d = d + Math.pow(2, o), E = E - g;
|
|
64
|
+
}
|
|
65
|
+
return (I ? -1 : 1) * d * Math.pow(2, E - o);
|
|
66
|
+
}, ce.write = function(l, i, s, o, f, E) {
|
|
67
|
+
var d, a, S, g = E * 8 - f - 1, m = (1 << g) - 1, u = m >> 1, R = f === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0, I = o ? 0 : E - 1, C = o ? 1 : -1, _ = i < 0 || i === 0 && 1 / i < 0 ? 1 : 0;
|
|
68
|
+
for (i = Math.abs(i), isNaN(i) || i === 1 / 0 ? (a = isNaN(i) ? 1 : 0, d = m) : (d = Math.floor(Math.log(i) / Math.LN2), i * (S = Math.pow(2, -d)) < 1 && (d--, S *= 2), d + u >= 1 ? i += R / S : i += R * Math.pow(2, 1 - u), i * S >= 2 && (d++, S /= 2), d + u >= m ? (a = 0, d = m) : d + u >= 1 ? (a = (i * S - 1) * Math.pow(2, f), d = d + u) : (a = i * Math.pow(2, u - 1) * Math.pow(2, f), d = 0)); f >= 8; l[s + I] = a & 255, I += C, a /= 256, f -= 8)
|
|
69
|
+
;
|
|
70
|
+
for (d = d << f | a, g += f; g > 0; l[s + I] = d & 255, I += C, d /= 256, g -= 8)
|
|
71
|
+
;
|
|
72
|
+
l[s + I - C] |= _ * 128;
|
|
73
|
+
}), ce;
|
|
74
|
+
}
|
|
75
|
+
var Ue;
|
|
76
|
+
function it() {
|
|
77
|
+
return Ue || (Ue = 1, (function(l) {
|
|
78
|
+
const i = et(), s = tt(), o = typeof Symbol == "function" && typeof Symbol.for == "function" ? /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom") : null;
|
|
79
|
+
l.Buffer = a, l.SlowBuffer = O, l.INSPECT_MAX_BYTES = 50;
|
|
80
|
+
const f = 2147483647;
|
|
81
|
+
l.kMaxLength = f, a.TYPED_ARRAY_SUPPORT = E(), !a.TYPED_ARRAY_SUPPORT && typeof console < "u" && typeof console.error == "function" && console.error(
|
|
82
|
+
"This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."
|
|
83
|
+
);
|
|
84
|
+
function E() {
|
|
85
|
+
try {
|
|
86
|
+
const n = new Uint8Array(1), e = { foo: function() {
|
|
87
|
+
return 42;
|
|
88
|
+
} };
|
|
89
|
+
return Object.setPrototypeOf(e, Uint8Array.prototype), Object.setPrototypeOf(n, e), n.foo() === 42;
|
|
90
|
+
} catch {
|
|
91
|
+
return !1;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
Object.defineProperty(a.prototype, "parent", {
|
|
95
|
+
enumerable: !0,
|
|
96
|
+
get: function() {
|
|
97
|
+
if (a.isBuffer(this))
|
|
98
|
+
return this.buffer;
|
|
99
|
+
}
|
|
100
|
+
}), Object.defineProperty(a.prototype, "offset", {
|
|
101
|
+
enumerable: !0,
|
|
102
|
+
get: function() {
|
|
103
|
+
if (a.isBuffer(this))
|
|
104
|
+
return this.byteOffset;
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
function d(n) {
|
|
108
|
+
if (n > f)
|
|
109
|
+
throw new RangeError('The value "' + n + '" is invalid for option "size"');
|
|
110
|
+
const e = new Uint8Array(n);
|
|
111
|
+
return Object.setPrototypeOf(e, a.prototype), e;
|
|
112
|
+
}
|
|
113
|
+
function a(n, e, t) {
|
|
114
|
+
if (typeof n == "number") {
|
|
115
|
+
if (typeof e == "string")
|
|
116
|
+
throw new TypeError(
|
|
117
|
+
'The "string" argument must be of type string. Received type number'
|
|
118
|
+
);
|
|
119
|
+
return u(n);
|
|
120
|
+
}
|
|
121
|
+
return S(n, e, t);
|
|
122
|
+
}
|
|
123
|
+
a.poolSize = 8192;
|
|
124
|
+
function S(n, e, t) {
|
|
125
|
+
if (typeof n == "string")
|
|
126
|
+
return R(n, e);
|
|
127
|
+
if (ArrayBuffer.isView(n))
|
|
128
|
+
return C(n);
|
|
129
|
+
if (n == null)
|
|
130
|
+
throw new TypeError(
|
|
131
|
+
"The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof n
|
|
132
|
+
);
|
|
133
|
+
if (H(n, ArrayBuffer) || n && H(n.buffer, ArrayBuffer) || typeof SharedArrayBuffer < "u" && (H(n, SharedArrayBuffer) || n && H(n.buffer, SharedArrayBuffer)))
|
|
134
|
+
return _(n, e, t);
|
|
135
|
+
if (typeof n == "number")
|
|
136
|
+
throw new TypeError(
|
|
137
|
+
'The "value" argument must not be of type number. Received type number'
|
|
138
|
+
);
|
|
139
|
+
const r = n.valueOf && n.valueOf();
|
|
140
|
+
if (r != null && r !== n)
|
|
141
|
+
return a.from(r, e, t);
|
|
142
|
+
const c = w(n);
|
|
143
|
+
if (c) return c;
|
|
144
|
+
if (typeof Symbol < "u" && Symbol.toPrimitive != null && typeof n[Symbol.toPrimitive] == "function")
|
|
145
|
+
return a.from(n[Symbol.toPrimitive]("string"), e, t);
|
|
146
|
+
throw new TypeError(
|
|
147
|
+
"The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof n
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
a.from = function(n, e, t) {
|
|
151
|
+
return S(n, e, t);
|
|
152
|
+
}, Object.setPrototypeOf(a.prototype, Uint8Array.prototype), Object.setPrototypeOf(a, Uint8Array);
|
|
153
|
+
function g(n) {
|
|
154
|
+
if (typeof n != "number")
|
|
155
|
+
throw new TypeError('"size" argument must be of type number');
|
|
156
|
+
if (n < 0)
|
|
157
|
+
throw new RangeError('The value "' + n + '" is invalid for option "size"');
|
|
158
|
+
}
|
|
159
|
+
function m(n, e, t) {
|
|
160
|
+
return g(n), n <= 0 ? d(n) : e !== void 0 ? typeof t == "string" ? d(n).fill(e, t) : d(n).fill(e) : d(n);
|
|
161
|
+
}
|
|
162
|
+
a.alloc = function(n, e, t) {
|
|
163
|
+
return m(n, e, t);
|
|
164
|
+
};
|
|
165
|
+
function u(n) {
|
|
166
|
+
return g(n), d(n < 0 ? 0 : N(n) | 0);
|
|
167
|
+
}
|
|
168
|
+
a.allocUnsafe = function(n) {
|
|
169
|
+
return u(n);
|
|
170
|
+
}, a.allocUnsafeSlow = function(n) {
|
|
171
|
+
return u(n);
|
|
172
|
+
};
|
|
173
|
+
function R(n, e) {
|
|
174
|
+
if ((typeof e != "string" || e === "") && (e = "utf8"), !a.isEncoding(e))
|
|
175
|
+
throw new TypeError("Unknown encoding: " + e);
|
|
176
|
+
const t = B(n, e) | 0;
|
|
177
|
+
let r = d(t);
|
|
178
|
+
const c = r.write(n, e);
|
|
179
|
+
return c !== t && (r = r.slice(0, c)), r;
|
|
180
|
+
}
|
|
181
|
+
function I(n) {
|
|
182
|
+
const e = n.length < 0 ? 0 : N(n.length) | 0, t = d(e);
|
|
183
|
+
for (let r = 0; r < e; r += 1)
|
|
184
|
+
t[r] = n[r] & 255;
|
|
185
|
+
return t;
|
|
186
|
+
}
|
|
187
|
+
function C(n) {
|
|
188
|
+
if (H(n, Uint8Array)) {
|
|
189
|
+
const e = new Uint8Array(n);
|
|
190
|
+
return _(e.buffer, e.byteOffset, e.byteLength);
|
|
191
|
+
}
|
|
192
|
+
return I(n);
|
|
193
|
+
}
|
|
194
|
+
function _(n, e, t) {
|
|
195
|
+
if (e < 0 || n.byteLength < e)
|
|
196
|
+
throw new RangeError('"offset" is outside of buffer bounds');
|
|
197
|
+
if (n.byteLength < e + (t || 0))
|
|
198
|
+
throw new RangeError('"length" is outside of buffer bounds');
|
|
199
|
+
let r;
|
|
200
|
+
return e === void 0 && t === void 0 ? r = new Uint8Array(n) : t === void 0 ? r = new Uint8Array(n, e) : r = new Uint8Array(n, e, t), Object.setPrototypeOf(r, a.prototype), r;
|
|
201
|
+
}
|
|
202
|
+
function w(n) {
|
|
203
|
+
if (a.isBuffer(n)) {
|
|
204
|
+
const e = N(n.length) | 0, t = d(e);
|
|
205
|
+
return t.length === 0 || n.copy(t, 0, 0, e), t;
|
|
206
|
+
}
|
|
207
|
+
if (n.length !== void 0)
|
|
208
|
+
return typeof n.length != "number" || pe(n.length) ? d(0) : I(n);
|
|
209
|
+
if (n.type === "Buffer" && Array.isArray(n.data))
|
|
210
|
+
return I(n.data);
|
|
211
|
+
}
|
|
212
|
+
function N(n) {
|
|
213
|
+
if (n >= f)
|
|
214
|
+
throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x" + f.toString(16) + " bytes");
|
|
215
|
+
return n | 0;
|
|
216
|
+
}
|
|
217
|
+
function O(n) {
|
|
218
|
+
return +n != n && (n = 0), a.alloc(+n);
|
|
219
|
+
}
|
|
220
|
+
a.isBuffer = function(e) {
|
|
221
|
+
return e != null && e._isBuffer === !0 && e !== a.prototype;
|
|
222
|
+
}, a.compare = function(e, t) {
|
|
223
|
+
if (H(e, Uint8Array) && (e = a.from(e, e.offset, e.byteLength)), H(t, Uint8Array) && (t = a.from(t, t.offset, t.byteLength)), !a.isBuffer(e) || !a.isBuffer(t))
|
|
224
|
+
throw new TypeError(
|
|
225
|
+
'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'
|
|
226
|
+
);
|
|
227
|
+
if (e === t) return 0;
|
|
228
|
+
let r = e.length, c = t.length;
|
|
229
|
+
for (let h = 0, p = Math.min(r, c); h < p; ++h)
|
|
230
|
+
if (e[h] !== t[h]) {
|
|
231
|
+
r = e[h], c = t[h];
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
return r < c ? -1 : c < r ? 1 : 0;
|
|
235
|
+
}, a.isEncoding = function(e) {
|
|
236
|
+
switch (String(e).toLowerCase()) {
|
|
237
|
+
case "hex":
|
|
238
|
+
case "utf8":
|
|
239
|
+
case "utf-8":
|
|
240
|
+
case "ascii":
|
|
241
|
+
case "latin1":
|
|
242
|
+
case "binary":
|
|
243
|
+
case "base64":
|
|
244
|
+
case "ucs2":
|
|
245
|
+
case "ucs-2":
|
|
246
|
+
case "utf16le":
|
|
247
|
+
case "utf-16le":
|
|
248
|
+
return !0;
|
|
249
|
+
default:
|
|
250
|
+
return !1;
|
|
251
|
+
}
|
|
252
|
+
}, a.concat = function(e, t) {
|
|
253
|
+
if (!Array.isArray(e))
|
|
254
|
+
throw new TypeError('"list" argument must be an Array of Buffers');
|
|
255
|
+
if (e.length === 0)
|
|
256
|
+
return a.alloc(0);
|
|
257
|
+
let r;
|
|
258
|
+
if (t === void 0)
|
|
259
|
+
for (t = 0, r = 0; r < e.length; ++r)
|
|
260
|
+
t += e[r].length;
|
|
261
|
+
const c = a.allocUnsafe(t);
|
|
262
|
+
let h = 0;
|
|
263
|
+
for (r = 0; r < e.length; ++r) {
|
|
264
|
+
let p = e[r];
|
|
265
|
+
if (H(p, Uint8Array))
|
|
266
|
+
h + p.length > c.length ? (a.isBuffer(p) || (p = a.from(p)), p.copy(c, h)) : Uint8Array.prototype.set.call(
|
|
267
|
+
c,
|
|
268
|
+
p,
|
|
269
|
+
h
|
|
270
|
+
);
|
|
271
|
+
else if (a.isBuffer(p))
|
|
272
|
+
p.copy(c, h);
|
|
273
|
+
else
|
|
274
|
+
throw new TypeError('"list" argument must be an Array of Buffers');
|
|
275
|
+
h += p.length;
|
|
276
|
+
}
|
|
277
|
+
return c;
|
|
278
|
+
};
|
|
279
|
+
function B(n, e) {
|
|
280
|
+
if (a.isBuffer(n))
|
|
281
|
+
return n.length;
|
|
282
|
+
if (ArrayBuffer.isView(n) || H(n, ArrayBuffer))
|
|
283
|
+
return n.byteLength;
|
|
284
|
+
if (typeof n != "string")
|
|
285
|
+
throw new TypeError(
|
|
286
|
+
'The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type ' + typeof n
|
|
287
|
+
);
|
|
288
|
+
const t = n.length, r = arguments.length > 2 && arguments[2] === !0;
|
|
289
|
+
if (!r && t === 0) return 0;
|
|
290
|
+
let c = !1;
|
|
291
|
+
for (; ; )
|
|
292
|
+
switch (e) {
|
|
293
|
+
case "ascii":
|
|
294
|
+
case "latin1":
|
|
295
|
+
case "binary":
|
|
296
|
+
return t;
|
|
297
|
+
case "utf8":
|
|
298
|
+
case "utf-8":
|
|
299
|
+
return fe(n).length;
|
|
300
|
+
case "ucs2":
|
|
301
|
+
case "ucs-2":
|
|
302
|
+
case "utf16le":
|
|
303
|
+
case "utf-16le":
|
|
304
|
+
return t * 2;
|
|
305
|
+
case "hex":
|
|
306
|
+
return t >>> 1;
|
|
307
|
+
case "base64":
|
|
308
|
+
return Oe(n).length;
|
|
309
|
+
default:
|
|
310
|
+
if (c)
|
|
311
|
+
return r ? -1 : fe(n).length;
|
|
312
|
+
e = ("" + e).toLowerCase(), c = !0;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
a.byteLength = B;
|
|
316
|
+
function k(n, e, t) {
|
|
317
|
+
let r = !1;
|
|
318
|
+
if ((e === void 0 || e < 0) && (e = 0), e > this.length || ((t === void 0 || t > this.length) && (t = this.length), t <= 0) || (t >>>= 0, e >>>= 0, t <= e))
|
|
319
|
+
return "";
|
|
320
|
+
for (n || (n = "utf8"); ; )
|
|
321
|
+
switch (n) {
|
|
322
|
+
case "hex":
|
|
323
|
+
return We(this, e, t);
|
|
324
|
+
case "utf8":
|
|
325
|
+
case "utf-8":
|
|
326
|
+
return Ce(this, e, t);
|
|
327
|
+
case "ascii":
|
|
328
|
+
return He(this, e, t);
|
|
329
|
+
case "latin1":
|
|
330
|
+
case "binary":
|
|
331
|
+
return je(this, e, t);
|
|
332
|
+
case "base64":
|
|
333
|
+
return $e(this, e, t);
|
|
334
|
+
case "ucs2":
|
|
335
|
+
case "ucs-2":
|
|
336
|
+
case "utf16le":
|
|
337
|
+
case "utf-16le":
|
|
338
|
+
return qe(this, e, t);
|
|
339
|
+
default:
|
|
340
|
+
if (r) throw new TypeError("Unknown encoding: " + n);
|
|
341
|
+
n = (n + "").toLowerCase(), r = !0;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
a.prototype._isBuffer = !0;
|
|
345
|
+
function b(n, e, t) {
|
|
346
|
+
const r = n[e];
|
|
347
|
+
n[e] = n[t], n[t] = r;
|
|
348
|
+
}
|
|
349
|
+
a.prototype.swap16 = function() {
|
|
350
|
+
const e = this.length;
|
|
351
|
+
if (e % 2 !== 0)
|
|
352
|
+
throw new RangeError("Buffer size must be a multiple of 16-bits");
|
|
353
|
+
for (let t = 0; t < e; t += 2)
|
|
354
|
+
b(this, t, t + 1);
|
|
355
|
+
return this;
|
|
356
|
+
}, a.prototype.swap32 = function() {
|
|
357
|
+
const e = this.length;
|
|
358
|
+
if (e % 4 !== 0)
|
|
359
|
+
throw new RangeError("Buffer size must be a multiple of 32-bits");
|
|
360
|
+
for (let t = 0; t < e; t += 4)
|
|
361
|
+
b(this, t, t + 3), b(this, t + 1, t + 2);
|
|
362
|
+
return this;
|
|
363
|
+
}, a.prototype.swap64 = function() {
|
|
364
|
+
const e = this.length;
|
|
365
|
+
if (e % 8 !== 0)
|
|
366
|
+
throw new RangeError("Buffer size must be a multiple of 64-bits");
|
|
367
|
+
for (let t = 0; t < e; t += 8)
|
|
368
|
+
b(this, t, t + 7), b(this, t + 1, t + 6), b(this, t + 2, t + 5), b(this, t + 3, t + 4);
|
|
369
|
+
return this;
|
|
370
|
+
}, a.prototype.toString = function() {
|
|
371
|
+
const e = this.length;
|
|
372
|
+
return e === 0 ? "" : arguments.length === 0 ? Ce(this, 0, e) : k.apply(this, arguments);
|
|
373
|
+
}, a.prototype.toLocaleString = a.prototype.toString, a.prototype.equals = function(e) {
|
|
374
|
+
if (!a.isBuffer(e)) throw new TypeError("Argument must be a Buffer");
|
|
375
|
+
return this === e ? !0 : a.compare(this, e) === 0;
|
|
376
|
+
}, a.prototype.inspect = function() {
|
|
377
|
+
let e = "";
|
|
378
|
+
const t = l.INSPECT_MAX_BYTES;
|
|
379
|
+
return e = this.toString("hex", 0, t).replace(/(.{2})/g, "$1 ").trim(), this.length > t && (e += " ... "), "<Buffer " + e + ">";
|
|
380
|
+
}, o && (a.prototype[o] = a.prototype.inspect), a.prototype.compare = function(e, t, r, c, h) {
|
|
381
|
+
if (H(e, Uint8Array) && (e = a.from(e, e.offset, e.byteLength)), !a.isBuffer(e))
|
|
382
|
+
throw new TypeError(
|
|
383
|
+
'The "target" argument must be one of type Buffer or Uint8Array. Received type ' + typeof e
|
|
384
|
+
);
|
|
385
|
+
if (t === void 0 && (t = 0), r === void 0 && (r = e ? e.length : 0), c === void 0 && (c = 0), h === void 0 && (h = this.length), t < 0 || r > e.length || c < 0 || h > this.length)
|
|
386
|
+
throw new RangeError("out of range index");
|
|
387
|
+
if (c >= h && t >= r)
|
|
388
|
+
return 0;
|
|
389
|
+
if (c >= h)
|
|
390
|
+
return -1;
|
|
391
|
+
if (t >= r)
|
|
392
|
+
return 1;
|
|
393
|
+
if (t >>>= 0, r >>>= 0, c >>>= 0, h >>>= 0, this === e) return 0;
|
|
394
|
+
let p = h - c, A = r - t;
|
|
395
|
+
const D = Math.min(p, A), v = this.slice(c, h), U = e.slice(t, r);
|
|
396
|
+
for (let y = 0; y < D; ++y)
|
|
397
|
+
if (v[y] !== U[y]) {
|
|
398
|
+
p = v[y], A = U[y];
|
|
399
|
+
break;
|
|
400
|
+
}
|
|
401
|
+
return p < A ? -1 : A < p ? 1 : 0;
|
|
402
|
+
};
|
|
403
|
+
function se(n, e, t, r, c) {
|
|
404
|
+
if (n.length === 0) return -1;
|
|
405
|
+
if (typeof t == "string" ? (r = t, t = 0) : t > 2147483647 ? t = 2147483647 : t < -2147483648 && (t = -2147483648), t = +t, pe(t) && (t = c ? 0 : n.length - 1), t < 0 && (t = n.length + t), t >= n.length) {
|
|
406
|
+
if (c) return -1;
|
|
407
|
+
t = n.length - 1;
|
|
408
|
+
} else if (t < 0)
|
|
409
|
+
if (c) t = 0;
|
|
410
|
+
else return -1;
|
|
411
|
+
if (typeof e == "string" && (e = a.from(e, r)), a.isBuffer(e))
|
|
412
|
+
return e.length === 0 ? -1 : oe(n, e, t, r, c);
|
|
413
|
+
if (typeof e == "number")
|
|
414
|
+
return e = e & 255, typeof Uint8Array.prototype.indexOf == "function" ? c ? Uint8Array.prototype.indexOf.call(n, e, t) : Uint8Array.prototype.lastIndexOf.call(n, e, t) : oe(n, [e], t, r, c);
|
|
415
|
+
throw new TypeError("val must be string, number or Buffer");
|
|
416
|
+
}
|
|
417
|
+
function oe(n, e, t, r, c) {
|
|
418
|
+
let h = 1, p = n.length, A = e.length;
|
|
419
|
+
if (r !== void 0 && (r = String(r).toLowerCase(), r === "ucs2" || r === "ucs-2" || r === "utf16le" || r === "utf-16le")) {
|
|
420
|
+
if (n.length < 2 || e.length < 2)
|
|
421
|
+
return -1;
|
|
422
|
+
h = 2, p /= 2, A /= 2, t /= 2;
|
|
423
|
+
}
|
|
424
|
+
function D(U, y) {
|
|
425
|
+
return h === 1 ? U[y] : U.readUInt16BE(y * h);
|
|
426
|
+
}
|
|
427
|
+
let v;
|
|
428
|
+
if (c) {
|
|
429
|
+
let U = -1;
|
|
430
|
+
for (v = t; v < p; v++)
|
|
431
|
+
if (D(n, v) === D(e, U === -1 ? 0 : v - U)) {
|
|
432
|
+
if (U === -1 && (U = v), v - U + 1 === A) return U * h;
|
|
433
|
+
} else
|
|
434
|
+
U !== -1 && (v -= v - U), U = -1;
|
|
435
|
+
} else
|
|
436
|
+
for (t + A > p && (t = p - A), v = t; v >= 0; v--) {
|
|
437
|
+
let U = !0;
|
|
438
|
+
for (let y = 0; y < A; y++)
|
|
439
|
+
if (D(n, v + y) !== D(e, y)) {
|
|
440
|
+
U = !1;
|
|
441
|
+
break;
|
|
442
|
+
}
|
|
443
|
+
if (U) return v;
|
|
444
|
+
}
|
|
445
|
+
return -1;
|
|
446
|
+
}
|
|
447
|
+
a.prototype.includes = function(e, t, r) {
|
|
448
|
+
return this.indexOf(e, t, r) !== -1;
|
|
449
|
+
}, a.prototype.indexOf = function(e, t, r) {
|
|
450
|
+
return se(this, e, t, r, !0);
|
|
451
|
+
}, a.prototype.lastIndexOf = function(e, t, r) {
|
|
452
|
+
return se(this, e, t, r, !1);
|
|
453
|
+
};
|
|
454
|
+
function de(n, e, t, r) {
|
|
455
|
+
t = Number(t) || 0;
|
|
456
|
+
const c = n.length - t;
|
|
457
|
+
r ? (r = Number(r), r > c && (r = c)) : r = c;
|
|
458
|
+
const h = e.length;
|
|
459
|
+
r > h / 2 && (r = h / 2);
|
|
460
|
+
let p;
|
|
461
|
+
for (p = 0; p < r; ++p) {
|
|
462
|
+
const A = parseInt(e.substr(p * 2, 2), 16);
|
|
463
|
+
if (pe(A)) return p;
|
|
464
|
+
n[t + p] = A;
|
|
465
|
+
}
|
|
466
|
+
return p;
|
|
467
|
+
}
|
|
468
|
+
function he(n, e, t, r) {
|
|
469
|
+
return ae(fe(e, n.length - t), n, t, r);
|
|
470
|
+
}
|
|
471
|
+
function ie(n, e, t, r) {
|
|
472
|
+
return ae(Ye(e), n, t, r);
|
|
473
|
+
}
|
|
474
|
+
function Pe(n, e, t, r) {
|
|
475
|
+
return ae(Oe(e), n, t, r);
|
|
476
|
+
}
|
|
477
|
+
function Ge(n, e, t, r) {
|
|
478
|
+
return ae(Xe(e, n.length - t), n, t, r);
|
|
479
|
+
}
|
|
480
|
+
a.prototype.write = function(e, t, r, c) {
|
|
481
|
+
if (t === void 0)
|
|
482
|
+
c = "utf8", r = this.length, t = 0;
|
|
483
|
+
else if (r === void 0 && typeof t == "string")
|
|
484
|
+
c = t, r = this.length, t = 0;
|
|
485
|
+
else if (isFinite(t))
|
|
486
|
+
t = t >>> 0, isFinite(r) ? (r = r >>> 0, c === void 0 && (c = "utf8")) : (c = r, r = void 0);
|
|
487
|
+
else
|
|
488
|
+
throw new Error(
|
|
489
|
+
"Buffer.write(string, encoding, offset[, length]) is no longer supported"
|
|
490
|
+
);
|
|
491
|
+
const h = this.length - t;
|
|
492
|
+
if ((r === void 0 || r > h) && (r = h), e.length > 0 && (r < 0 || t < 0) || t > this.length)
|
|
493
|
+
throw new RangeError("Attempt to write outside buffer bounds");
|
|
494
|
+
c || (c = "utf8");
|
|
495
|
+
let p = !1;
|
|
496
|
+
for (; ; )
|
|
497
|
+
switch (c) {
|
|
498
|
+
case "hex":
|
|
499
|
+
return de(this, e, t, r);
|
|
500
|
+
case "utf8":
|
|
501
|
+
case "utf-8":
|
|
502
|
+
return he(this, e, t, r);
|
|
503
|
+
case "ascii":
|
|
504
|
+
case "latin1":
|
|
505
|
+
case "binary":
|
|
506
|
+
return ie(this, e, t, r);
|
|
507
|
+
case "base64":
|
|
508
|
+
return Pe(this, e, t, r);
|
|
509
|
+
case "ucs2":
|
|
510
|
+
case "ucs-2":
|
|
511
|
+
case "utf16le":
|
|
512
|
+
case "utf-16le":
|
|
513
|
+
return Ge(this, e, t, r);
|
|
514
|
+
default:
|
|
515
|
+
if (p) throw new TypeError("Unknown encoding: " + c);
|
|
516
|
+
c = ("" + c).toLowerCase(), p = !0;
|
|
517
|
+
}
|
|
518
|
+
}, a.prototype.toJSON = function() {
|
|
519
|
+
return {
|
|
520
|
+
type: "Buffer",
|
|
521
|
+
data: Array.prototype.slice.call(this._arr || this, 0)
|
|
522
|
+
};
|
|
523
|
+
};
|
|
524
|
+
function $e(n, e, t) {
|
|
525
|
+
return e === 0 && t === n.length ? i.fromByteArray(n) : i.fromByteArray(n.slice(e, t));
|
|
526
|
+
}
|
|
527
|
+
function Ce(n, e, t) {
|
|
528
|
+
t = Math.min(n.length, t);
|
|
529
|
+
const r = [];
|
|
530
|
+
let c = e;
|
|
531
|
+
for (; c < t; ) {
|
|
532
|
+
const h = n[c];
|
|
533
|
+
let p = null, A = h > 239 ? 4 : h > 223 ? 3 : h > 191 ? 2 : 1;
|
|
534
|
+
if (c + A <= t) {
|
|
535
|
+
let D, v, U, y;
|
|
536
|
+
switch (A) {
|
|
537
|
+
case 1:
|
|
538
|
+
h < 128 && (p = h);
|
|
539
|
+
break;
|
|
540
|
+
case 2:
|
|
541
|
+
D = n[c + 1], (D & 192) === 128 && (y = (h & 31) << 6 | D & 63, y > 127 && (p = y));
|
|
542
|
+
break;
|
|
543
|
+
case 3:
|
|
544
|
+
D = n[c + 1], v = n[c + 2], (D & 192) === 128 && (v & 192) === 128 && (y = (h & 15) << 12 | (D & 63) << 6 | v & 63, y > 2047 && (y < 55296 || y > 57343) && (p = y));
|
|
545
|
+
break;
|
|
546
|
+
case 4:
|
|
547
|
+
D = n[c + 1], v = n[c + 2], U = n[c + 3], (D & 192) === 128 && (v & 192) === 128 && (U & 192) === 128 && (y = (h & 15) << 18 | (D & 63) << 12 | (v & 63) << 6 | U & 63, y > 65535 && y < 1114112 && (p = y));
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
p === null ? (p = 65533, A = 1) : p > 65535 && (p -= 65536, r.push(p >>> 10 & 1023 | 55296), p = 56320 | p & 1023), r.push(p), c += A;
|
|
551
|
+
}
|
|
552
|
+
return Ve(r);
|
|
553
|
+
}
|
|
554
|
+
const _e = 4096;
|
|
555
|
+
function Ve(n) {
|
|
556
|
+
const e = n.length;
|
|
557
|
+
if (e <= _e)
|
|
558
|
+
return String.fromCharCode.apply(String, n);
|
|
559
|
+
let t = "", r = 0;
|
|
560
|
+
for (; r < e; )
|
|
561
|
+
t += String.fromCharCode.apply(
|
|
562
|
+
String,
|
|
563
|
+
n.slice(r, r += _e)
|
|
564
|
+
);
|
|
565
|
+
return t;
|
|
566
|
+
}
|
|
567
|
+
function He(n, e, t) {
|
|
568
|
+
let r = "";
|
|
569
|
+
t = Math.min(n.length, t);
|
|
570
|
+
for (let c = e; c < t; ++c)
|
|
571
|
+
r += String.fromCharCode(n[c] & 127);
|
|
572
|
+
return r;
|
|
573
|
+
}
|
|
574
|
+
function je(n, e, t) {
|
|
575
|
+
let r = "";
|
|
576
|
+
t = Math.min(n.length, t);
|
|
577
|
+
for (let c = e; c < t; ++c)
|
|
578
|
+
r += String.fromCharCode(n[c]);
|
|
579
|
+
return r;
|
|
580
|
+
}
|
|
581
|
+
function We(n, e, t) {
|
|
582
|
+
const r = n.length;
|
|
583
|
+
(!e || e < 0) && (e = 0), (!t || t < 0 || t > r) && (t = r);
|
|
584
|
+
let c = "";
|
|
585
|
+
for (let h = e; h < t; ++h)
|
|
586
|
+
c += Qe[n[h]];
|
|
587
|
+
return c;
|
|
588
|
+
}
|
|
589
|
+
function qe(n, e, t) {
|
|
590
|
+
const r = n.slice(e, t);
|
|
591
|
+
let c = "";
|
|
592
|
+
for (let h = 0; h < r.length - 1; h += 2)
|
|
593
|
+
c += String.fromCharCode(r[h] + r[h + 1] * 256);
|
|
594
|
+
return c;
|
|
595
|
+
}
|
|
596
|
+
a.prototype.slice = function(e, t) {
|
|
597
|
+
const r = this.length;
|
|
598
|
+
e = ~~e, t = t === void 0 ? r : ~~t, e < 0 ? (e += r, e < 0 && (e = 0)) : e > r && (e = r), t < 0 ? (t += r, t < 0 && (t = 0)) : t > r && (t = r), t < e && (t = e);
|
|
599
|
+
const c = this.subarray(e, t);
|
|
600
|
+
return Object.setPrototypeOf(c, a.prototype), c;
|
|
601
|
+
};
|
|
602
|
+
function L(n, e, t) {
|
|
603
|
+
if (n % 1 !== 0 || n < 0) throw new RangeError("offset is not uint");
|
|
604
|
+
if (n + e > t) throw new RangeError("Trying to access beyond buffer length");
|
|
605
|
+
}
|
|
606
|
+
a.prototype.readUintLE = a.prototype.readUIntLE = function(e, t, r) {
|
|
607
|
+
e = e >>> 0, t = t >>> 0, r || L(e, t, this.length);
|
|
608
|
+
let c = this[e], h = 1, p = 0;
|
|
609
|
+
for (; ++p < t && (h *= 256); )
|
|
610
|
+
c += this[e + p] * h;
|
|
611
|
+
return c;
|
|
612
|
+
}, a.prototype.readUintBE = a.prototype.readUIntBE = function(e, t, r) {
|
|
613
|
+
e = e >>> 0, t = t >>> 0, r || L(e, t, this.length);
|
|
614
|
+
let c = this[e + --t], h = 1;
|
|
615
|
+
for (; t > 0 && (h *= 256); )
|
|
616
|
+
c += this[e + --t] * h;
|
|
617
|
+
return c;
|
|
618
|
+
}, a.prototype.readUint8 = a.prototype.readUInt8 = function(e, t) {
|
|
619
|
+
return e = e >>> 0, t || L(e, 1, this.length), this[e];
|
|
620
|
+
}, a.prototype.readUint16LE = a.prototype.readUInt16LE = function(e, t) {
|
|
621
|
+
return e = e >>> 0, t || L(e, 2, this.length), this[e] | this[e + 1] << 8;
|
|
622
|
+
}, a.prototype.readUint16BE = a.prototype.readUInt16BE = function(e, t) {
|
|
623
|
+
return e = e >>> 0, t || L(e, 2, this.length), this[e] << 8 | this[e + 1];
|
|
624
|
+
}, a.prototype.readUint32LE = a.prototype.readUInt32LE = function(e, t) {
|
|
625
|
+
return e = e >>> 0, t || L(e, 4, this.length), (this[e] | this[e + 1] << 8 | this[e + 2] << 16) + this[e + 3] * 16777216;
|
|
626
|
+
}, a.prototype.readUint32BE = a.prototype.readUInt32BE = function(e, t) {
|
|
627
|
+
return e = e >>> 0, t || L(e, 4, this.length), this[e] * 16777216 + (this[e + 1] << 16 | this[e + 2] << 8 | this[e + 3]);
|
|
628
|
+
}, a.prototype.readBigUInt64LE = W(function(e) {
|
|
629
|
+
e = e >>> 0, Z(e, "offset");
|
|
630
|
+
const t = this[e], r = this[e + 7];
|
|
631
|
+
(t === void 0 || r === void 0) && ne(e, this.length - 8);
|
|
632
|
+
const c = t + this[++e] * 2 ** 8 + this[++e] * 2 ** 16 + this[++e] * 2 ** 24, h = this[++e] + this[++e] * 2 ** 8 + this[++e] * 2 ** 16 + r * 2 ** 24;
|
|
633
|
+
return BigInt(c) + (BigInt(h) << BigInt(32));
|
|
634
|
+
}), a.prototype.readBigUInt64BE = W(function(e) {
|
|
635
|
+
e = e >>> 0, Z(e, "offset");
|
|
636
|
+
const t = this[e], r = this[e + 7];
|
|
637
|
+
(t === void 0 || r === void 0) && ne(e, this.length - 8);
|
|
638
|
+
const c = t * 2 ** 24 + this[++e] * 2 ** 16 + this[++e] * 2 ** 8 + this[++e], h = this[++e] * 2 ** 24 + this[++e] * 2 ** 16 + this[++e] * 2 ** 8 + r;
|
|
639
|
+
return (BigInt(c) << BigInt(32)) + BigInt(h);
|
|
640
|
+
}), a.prototype.readIntLE = function(e, t, r) {
|
|
641
|
+
e = e >>> 0, t = t >>> 0, r || L(e, t, this.length);
|
|
642
|
+
let c = this[e], h = 1, p = 0;
|
|
643
|
+
for (; ++p < t && (h *= 256); )
|
|
644
|
+
c += this[e + p] * h;
|
|
645
|
+
return h *= 128, c >= h && (c -= Math.pow(2, 8 * t)), c;
|
|
646
|
+
}, a.prototype.readIntBE = function(e, t, r) {
|
|
647
|
+
e = e >>> 0, t = t >>> 0, r || L(e, t, this.length);
|
|
648
|
+
let c = t, h = 1, p = this[e + --c];
|
|
649
|
+
for (; c > 0 && (h *= 256); )
|
|
650
|
+
p += this[e + --c] * h;
|
|
651
|
+
return h *= 128, p >= h && (p -= Math.pow(2, 8 * t)), p;
|
|
652
|
+
}, a.prototype.readInt8 = function(e, t) {
|
|
653
|
+
return e = e >>> 0, t || L(e, 1, this.length), this[e] & 128 ? (255 - this[e] + 1) * -1 : this[e];
|
|
654
|
+
}, a.prototype.readInt16LE = function(e, t) {
|
|
655
|
+
e = e >>> 0, t || L(e, 2, this.length);
|
|
656
|
+
const r = this[e] | this[e + 1] << 8;
|
|
657
|
+
return r & 32768 ? r | 4294901760 : r;
|
|
658
|
+
}, a.prototype.readInt16BE = function(e, t) {
|
|
659
|
+
e = e >>> 0, t || L(e, 2, this.length);
|
|
660
|
+
const r = this[e + 1] | this[e] << 8;
|
|
661
|
+
return r & 32768 ? r | 4294901760 : r;
|
|
662
|
+
}, a.prototype.readInt32LE = function(e, t) {
|
|
663
|
+
return e = e >>> 0, t || L(e, 4, this.length), this[e] | this[e + 1] << 8 | this[e + 2] << 16 | this[e + 3] << 24;
|
|
664
|
+
}, a.prototype.readInt32BE = function(e, t) {
|
|
665
|
+
return e = e >>> 0, t || L(e, 4, this.length), this[e] << 24 | this[e + 1] << 16 | this[e + 2] << 8 | this[e + 3];
|
|
666
|
+
}, a.prototype.readBigInt64LE = W(function(e) {
|
|
667
|
+
e = e >>> 0, Z(e, "offset");
|
|
668
|
+
const t = this[e], r = this[e + 7];
|
|
669
|
+
(t === void 0 || r === void 0) && ne(e, this.length - 8);
|
|
670
|
+
const c = this[e + 4] + this[e + 5] * 2 ** 8 + this[e + 6] * 2 ** 16 + (r << 24);
|
|
671
|
+
return (BigInt(c) << BigInt(32)) + BigInt(t + this[++e] * 2 ** 8 + this[++e] * 2 ** 16 + this[++e] * 2 ** 24);
|
|
672
|
+
}), a.prototype.readBigInt64BE = W(function(e) {
|
|
673
|
+
e = e >>> 0, Z(e, "offset");
|
|
674
|
+
const t = this[e], r = this[e + 7];
|
|
675
|
+
(t === void 0 || r === void 0) && ne(e, this.length - 8);
|
|
676
|
+
const c = (t << 24) + // Overflow
|
|
677
|
+
this[++e] * 2 ** 16 + this[++e] * 2 ** 8 + this[++e];
|
|
678
|
+
return (BigInt(c) << BigInt(32)) + BigInt(this[++e] * 2 ** 24 + this[++e] * 2 ** 16 + this[++e] * 2 ** 8 + r);
|
|
679
|
+
}), a.prototype.readFloatLE = function(e, t) {
|
|
680
|
+
return e = e >>> 0, t || L(e, 4, this.length), s.read(this, e, !0, 23, 4);
|
|
681
|
+
}, a.prototype.readFloatBE = function(e, t) {
|
|
682
|
+
return e = e >>> 0, t || L(e, 4, this.length), s.read(this, e, !1, 23, 4);
|
|
683
|
+
}, a.prototype.readDoubleLE = function(e, t) {
|
|
684
|
+
return e = e >>> 0, t || L(e, 8, this.length), s.read(this, e, !0, 52, 8);
|
|
685
|
+
}, a.prototype.readDoubleBE = function(e, t) {
|
|
686
|
+
return e = e >>> 0, t || L(e, 8, this.length), s.read(this, e, !1, 52, 8);
|
|
687
|
+
};
|
|
688
|
+
function G(n, e, t, r, c, h) {
|
|
689
|
+
if (!a.isBuffer(n)) throw new TypeError('"buffer" argument must be a Buffer instance');
|
|
690
|
+
if (e > c || e < h) throw new RangeError('"value" argument is out of bounds');
|
|
691
|
+
if (t + r > n.length) throw new RangeError("Index out of range");
|
|
692
|
+
}
|
|
693
|
+
a.prototype.writeUintLE = a.prototype.writeUIntLE = function(e, t, r, c) {
|
|
694
|
+
if (e = +e, t = t >>> 0, r = r >>> 0, !c) {
|
|
695
|
+
const A = Math.pow(2, 8 * r) - 1;
|
|
696
|
+
G(this, e, t, r, A, 0);
|
|
697
|
+
}
|
|
698
|
+
let h = 1, p = 0;
|
|
699
|
+
for (this[t] = e & 255; ++p < r && (h *= 256); )
|
|
700
|
+
this[t + p] = e / h & 255;
|
|
701
|
+
return t + r;
|
|
702
|
+
}, a.prototype.writeUintBE = a.prototype.writeUIntBE = function(e, t, r, c) {
|
|
703
|
+
if (e = +e, t = t >>> 0, r = r >>> 0, !c) {
|
|
704
|
+
const A = Math.pow(2, 8 * r) - 1;
|
|
705
|
+
G(this, e, t, r, A, 0);
|
|
706
|
+
}
|
|
707
|
+
let h = r - 1, p = 1;
|
|
708
|
+
for (this[t + h] = e & 255; --h >= 0 && (p *= 256); )
|
|
709
|
+
this[t + h] = e / p & 255;
|
|
710
|
+
return t + r;
|
|
711
|
+
}, a.prototype.writeUint8 = a.prototype.writeUInt8 = function(e, t, r) {
|
|
712
|
+
return e = +e, t = t >>> 0, r || G(this, e, t, 1, 255, 0), this[t] = e & 255, t + 1;
|
|
713
|
+
}, a.prototype.writeUint16LE = a.prototype.writeUInt16LE = function(e, t, r) {
|
|
714
|
+
return e = +e, t = t >>> 0, r || G(this, e, t, 2, 65535, 0), this[t] = e & 255, this[t + 1] = e >>> 8, t + 2;
|
|
715
|
+
}, a.prototype.writeUint16BE = a.prototype.writeUInt16BE = function(e, t, r) {
|
|
716
|
+
return e = +e, t = t >>> 0, r || G(this, e, t, 2, 65535, 0), this[t] = e >>> 8, this[t + 1] = e & 255, t + 2;
|
|
717
|
+
}, a.prototype.writeUint32LE = a.prototype.writeUInt32LE = function(e, t, r) {
|
|
718
|
+
return e = +e, t = t >>> 0, r || G(this, e, t, 4, 4294967295, 0), this[t + 3] = e >>> 24, this[t + 2] = e >>> 16, this[t + 1] = e >>> 8, this[t] = e & 255, t + 4;
|
|
719
|
+
}, a.prototype.writeUint32BE = a.prototype.writeUInt32BE = function(e, t, r) {
|
|
720
|
+
return e = +e, t = t >>> 0, r || G(this, e, t, 4, 4294967295, 0), this[t] = e >>> 24, this[t + 1] = e >>> 16, this[t + 2] = e >>> 8, this[t + 3] = e & 255, t + 4;
|
|
721
|
+
};
|
|
722
|
+
function Ae(n, e, t, r, c) {
|
|
723
|
+
ve(e, r, c, n, t, 7);
|
|
724
|
+
let h = Number(e & BigInt(4294967295));
|
|
725
|
+
n[t++] = h, h = h >> 8, n[t++] = h, h = h >> 8, n[t++] = h, h = h >> 8, n[t++] = h;
|
|
726
|
+
let p = Number(e >> BigInt(32) & BigInt(4294967295));
|
|
727
|
+
return n[t++] = p, p = p >> 8, n[t++] = p, p = p >> 8, n[t++] = p, p = p >> 8, n[t++] = p, t;
|
|
728
|
+
}
|
|
729
|
+
function Re(n, e, t, r, c) {
|
|
730
|
+
ve(e, r, c, n, t, 7);
|
|
731
|
+
let h = Number(e & BigInt(4294967295));
|
|
732
|
+
n[t + 7] = h, h = h >> 8, n[t + 6] = h, h = h >> 8, n[t + 5] = h, h = h >> 8, n[t + 4] = h;
|
|
733
|
+
let p = Number(e >> BigInt(32) & BigInt(4294967295));
|
|
734
|
+
return n[t + 3] = p, p = p >> 8, n[t + 2] = p, p = p >> 8, n[t + 1] = p, p = p >> 8, n[t] = p, t + 8;
|
|
735
|
+
}
|
|
736
|
+
a.prototype.writeBigUInt64LE = W(function(e, t = 0) {
|
|
737
|
+
return Ae(this, e, t, BigInt(0), BigInt("0xffffffffffffffff"));
|
|
738
|
+
}), a.prototype.writeBigUInt64BE = W(function(e, t = 0) {
|
|
739
|
+
return Re(this, e, t, BigInt(0), BigInt("0xffffffffffffffff"));
|
|
740
|
+
}), a.prototype.writeIntLE = function(e, t, r, c) {
|
|
741
|
+
if (e = +e, t = t >>> 0, !c) {
|
|
742
|
+
const D = Math.pow(2, 8 * r - 1);
|
|
743
|
+
G(this, e, t, r, D - 1, -D);
|
|
744
|
+
}
|
|
745
|
+
let h = 0, p = 1, A = 0;
|
|
746
|
+
for (this[t] = e & 255; ++h < r && (p *= 256); )
|
|
747
|
+
e < 0 && A === 0 && this[t + h - 1] !== 0 && (A = 1), this[t + h] = (e / p >> 0) - A & 255;
|
|
748
|
+
return t + r;
|
|
749
|
+
}, a.prototype.writeIntBE = function(e, t, r, c) {
|
|
750
|
+
if (e = +e, t = t >>> 0, !c) {
|
|
751
|
+
const D = Math.pow(2, 8 * r - 1);
|
|
752
|
+
G(this, e, t, r, D - 1, -D);
|
|
753
|
+
}
|
|
754
|
+
let h = r - 1, p = 1, A = 0;
|
|
755
|
+
for (this[t + h] = e & 255; --h >= 0 && (p *= 256); )
|
|
756
|
+
e < 0 && A === 0 && this[t + h + 1] !== 0 && (A = 1), this[t + h] = (e / p >> 0) - A & 255;
|
|
757
|
+
return t + r;
|
|
758
|
+
}, a.prototype.writeInt8 = function(e, t, r) {
|
|
759
|
+
return e = +e, t = t >>> 0, r || G(this, e, t, 1, 127, -128), e < 0 && (e = 255 + e + 1), this[t] = e & 255, t + 1;
|
|
760
|
+
}, a.prototype.writeInt16LE = function(e, t, r) {
|
|
761
|
+
return e = +e, t = t >>> 0, r || G(this, e, t, 2, 32767, -32768), this[t] = e & 255, this[t + 1] = e >>> 8, t + 2;
|
|
762
|
+
}, a.prototype.writeInt16BE = function(e, t, r) {
|
|
763
|
+
return e = +e, t = t >>> 0, r || G(this, e, t, 2, 32767, -32768), this[t] = e >>> 8, this[t + 1] = e & 255, t + 2;
|
|
764
|
+
}, a.prototype.writeInt32LE = function(e, t, r) {
|
|
765
|
+
return e = +e, t = t >>> 0, r || G(this, e, t, 4, 2147483647, -2147483648), this[t] = e & 255, this[t + 1] = e >>> 8, this[t + 2] = e >>> 16, this[t + 3] = e >>> 24, t + 4;
|
|
766
|
+
}, a.prototype.writeInt32BE = function(e, t, r) {
|
|
767
|
+
return e = +e, t = t >>> 0, r || G(this, e, t, 4, 2147483647, -2147483648), e < 0 && (e = 4294967295 + e + 1), this[t] = e >>> 24, this[t + 1] = e >>> 16, this[t + 2] = e >>> 8, this[t + 3] = e & 255, t + 4;
|
|
768
|
+
}, a.prototype.writeBigInt64LE = W(function(e, t = 0) {
|
|
769
|
+
return Ae(this, e, t, -BigInt("0x8000000000000000"), BigInt("0x7fffffffffffffff"));
|
|
770
|
+
}), a.prototype.writeBigInt64BE = W(function(e, t = 0) {
|
|
771
|
+
return Re(this, e, t, -BigInt("0x8000000000000000"), BigInt("0x7fffffffffffffff"));
|
|
772
|
+
});
|
|
773
|
+
function ye(n, e, t, r, c, h) {
|
|
774
|
+
if (t + r > n.length) throw new RangeError("Index out of range");
|
|
775
|
+
if (t < 0) throw new RangeError("Index out of range");
|
|
776
|
+
}
|
|
777
|
+
function Te(n, e, t, r, c) {
|
|
778
|
+
return e = +e, t = t >>> 0, c || ye(n, e, t, 4), s.write(n, e, t, r, 23, 4), t + 4;
|
|
779
|
+
}
|
|
780
|
+
a.prototype.writeFloatLE = function(e, t, r) {
|
|
781
|
+
return Te(this, e, t, !0, r);
|
|
782
|
+
}, a.prototype.writeFloatBE = function(e, t, r) {
|
|
783
|
+
return Te(this, e, t, !1, r);
|
|
784
|
+
};
|
|
785
|
+
function we(n, e, t, r, c) {
|
|
786
|
+
return e = +e, t = t >>> 0, c || ye(n, e, t, 8), s.write(n, e, t, r, 52, 8), t + 8;
|
|
787
|
+
}
|
|
788
|
+
a.prototype.writeDoubleLE = function(e, t, r) {
|
|
789
|
+
return we(this, e, t, !0, r);
|
|
790
|
+
}, a.prototype.writeDoubleBE = function(e, t, r) {
|
|
791
|
+
return we(this, e, t, !1, r);
|
|
792
|
+
}, a.prototype.copy = function(e, t, r, c) {
|
|
793
|
+
if (!a.isBuffer(e)) throw new TypeError("argument should be a Buffer");
|
|
794
|
+
if (r || (r = 0), !c && c !== 0 && (c = this.length), t >= e.length && (t = e.length), t || (t = 0), c > 0 && c < r && (c = r), c === r || e.length === 0 || this.length === 0) return 0;
|
|
795
|
+
if (t < 0)
|
|
796
|
+
throw new RangeError("targetStart out of bounds");
|
|
797
|
+
if (r < 0 || r >= this.length) throw new RangeError("Index out of range");
|
|
798
|
+
if (c < 0) throw new RangeError("sourceEnd out of bounds");
|
|
799
|
+
c > this.length && (c = this.length), e.length - t < c - r && (c = e.length - t + r);
|
|
800
|
+
const h = c - r;
|
|
801
|
+
return this === e && typeof Uint8Array.prototype.copyWithin == "function" ? this.copyWithin(t, r, c) : Uint8Array.prototype.set.call(
|
|
802
|
+
e,
|
|
803
|
+
this.subarray(r, c),
|
|
804
|
+
t
|
|
805
|
+
), h;
|
|
806
|
+
}, a.prototype.fill = function(e, t, r, c) {
|
|
807
|
+
if (typeof e == "string") {
|
|
808
|
+
if (typeof t == "string" ? (c = t, t = 0, r = this.length) : typeof r == "string" && (c = r, r = this.length), c !== void 0 && typeof c != "string")
|
|
809
|
+
throw new TypeError("encoding must be a string");
|
|
810
|
+
if (typeof c == "string" && !a.isEncoding(c))
|
|
811
|
+
throw new TypeError("Unknown encoding: " + c);
|
|
812
|
+
if (e.length === 1) {
|
|
813
|
+
const p = e.charCodeAt(0);
|
|
814
|
+
(c === "utf8" && p < 128 || c === "latin1") && (e = p);
|
|
815
|
+
}
|
|
816
|
+
} else typeof e == "number" ? e = e & 255 : typeof e == "boolean" && (e = Number(e));
|
|
817
|
+
if (t < 0 || this.length < t || this.length < r)
|
|
818
|
+
throw new RangeError("Out of range index");
|
|
819
|
+
if (r <= t)
|
|
820
|
+
return this;
|
|
821
|
+
t = t >>> 0, r = r === void 0 ? this.length : r >>> 0, e || (e = 0);
|
|
822
|
+
let h;
|
|
823
|
+
if (typeof e == "number")
|
|
824
|
+
for (h = t; h < r; ++h)
|
|
825
|
+
this[h] = e;
|
|
826
|
+
else {
|
|
827
|
+
const p = a.isBuffer(e) ? e : a.from(e, c), A = p.length;
|
|
828
|
+
if (A === 0)
|
|
829
|
+
throw new TypeError('The value "' + e + '" is invalid for argument "value"');
|
|
830
|
+
for (h = 0; h < r - t; ++h)
|
|
831
|
+
this[h + t] = p[h % A];
|
|
832
|
+
}
|
|
833
|
+
return this;
|
|
834
|
+
};
|
|
835
|
+
const Q = {};
|
|
836
|
+
function Ee(n, e, t) {
|
|
837
|
+
Q[n] = class extends t {
|
|
838
|
+
constructor() {
|
|
839
|
+
super(), Object.defineProperty(this, "message", {
|
|
840
|
+
value: e.apply(this, arguments),
|
|
841
|
+
writable: !0,
|
|
842
|
+
configurable: !0
|
|
843
|
+
}), this.name = `${this.name} [${n}]`, this.stack, delete this.name;
|
|
844
|
+
}
|
|
845
|
+
get code() {
|
|
846
|
+
return n;
|
|
847
|
+
}
|
|
848
|
+
set code(c) {
|
|
849
|
+
Object.defineProperty(this, "code", {
|
|
850
|
+
configurable: !0,
|
|
851
|
+
enumerable: !0,
|
|
852
|
+
value: c,
|
|
853
|
+
writable: !0
|
|
854
|
+
});
|
|
855
|
+
}
|
|
856
|
+
toString() {
|
|
857
|
+
return `${this.name} [${n}]: ${this.message}`;
|
|
858
|
+
}
|
|
859
|
+
};
|
|
860
|
+
}
|
|
861
|
+
Ee(
|
|
862
|
+
"ERR_BUFFER_OUT_OF_BOUNDS",
|
|
863
|
+
function(n) {
|
|
864
|
+
return n ? `${n} is outside of buffer bounds` : "Attempt to access memory outside buffer bounds";
|
|
865
|
+
},
|
|
866
|
+
RangeError
|
|
867
|
+
), Ee(
|
|
868
|
+
"ERR_INVALID_ARG_TYPE",
|
|
869
|
+
function(n, e) {
|
|
870
|
+
return `The "${n}" argument must be of type number. Received type ${typeof e}`;
|
|
871
|
+
},
|
|
872
|
+
TypeError
|
|
873
|
+
), Ee(
|
|
874
|
+
"ERR_OUT_OF_RANGE",
|
|
875
|
+
function(n, e, t) {
|
|
876
|
+
let r = `The value of "${n}" is out of range.`, c = t;
|
|
877
|
+
return Number.isInteger(t) && Math.abs(t) > 2 ** 32 ? c = Ne(String(t)) : typeof t == "bigint" && (c = String(t), (t > BigInt(2) ** BigInt(32) || t < -(BigInt(2) ** BigInt(32))) && (c = Ne(c)), c += "n"), r += ` It must be ${e}. Received ${c}`, r;
|
|
878
|
+
},
|
|
879
|
+
RangeError
|
|
880
|
+
);
|
|
881
|
+
function Ne(n) {
|
|
882
|
+
let e = "", t = n.length;
|
|
883
|
+
const r = n[0] === "-" ? 1 : 0;
|
|
884
|
+
for (; t >= r + 4; t -= 3)
|
|
885
|
+
e = `_${n.slice(t - 3, t)}${e}`;
|
|
886
|
+
return `${n.slice(0, t)}${e}`;
|
|
887
|
+
}
|
|
888
|
+
function Ke(n, e, t) {
|
|
889
|
+
Z(e, "offset"), (n[e] === void 0 || n[e + t] === void 0) && ne(e, n.length - (t + 1));
|
|
890
|
+
}
|
|
891
|
+
function ve(n, e, t, r, c, h) {
|
|
892
|
+
if (n > t || n < e) {
|
|
893
|
+
const p = typeof e == "bigint" ? "n" : "";
|
|
894
|
+
let A;
|
|
895
|
+
throw e === 0 || e === BigInt(0) ? A = `>= 0${p} and < 2${p} ** ${(h + 1) * 8}${p}` : A = `>= -(2${p} ** ${(h + 1) * 8 - 1}${p}) and < 2 ** ${(h + 1) * 8 - 1}${p}`, new Q.ERR_OUT_OF_RANGE("value", A, n);
|
|
896
|
+
}
|
|
897
|
+
Ke(r, c, h);
|
|
898
|
+
}
|
|
899
|
+
function Z(n, e) {
|
|
900
|
+
if (typeof n != "number")
|
|
901
|
+
throw new Q.ERR_INVALID_ARG_TYPE(e, "number", n);
|
|
902
|
+
}
|
|
903
|
+
function ne(n, e, t) {
|
|
904
|
+
throw Math.floor(n) !== n ? (Z(n, t), new Q.ERR_OUT_OF_RANGE("offset", "an integer", n)) : e < 0 ? new Q.ERR_BUFFER_OUT_OF_BOUNDS() : new Q.ERR_OUT_OF_RANGE(
|
|
905
|
+
"offset",
|
|
906
|
+
`>= 0 and <= ${e}`,
|
|
907
|
+
n
|
|
908
|
+
);
|
|
909
|
+
}
|
|
910
|
+
const Je = /[^+/0-9A-Za-z-_]/g;
|
|
911
|
+
function ze(n) {
|
|
912
|
+
if (n = n.split("=")[0], n = n.trim().replace(Je, ""), n.length < 2) return "";
|
|
913
|
+
for (; n.length % 4 !== 0; )
|
|
914
|
+
n = n + "=";
|
|
915
|
+
return n;
|
|
916
|
+
}
|
|
917
|
+
function fe(n, e) {
|
|
918
|
+
e = e || 1 / 0;
|
|
919
|
+
let t;
|
|
920
|
+
const r = n.length;
|
|
921
|
+
let c = null;
|
|
922
|
+
const h = [];
|
|
923
|
+
for (let p = 0; p < r; ++p) {
|
|
924
|
+
if (t = n.charCodeAt(p), t > 55295 && t < 57344) {
|
|
925
|
+
if (!c) {
|
|
926
|
+
if (t > 56319) {
|
|
927
|
+
(e -= 3) > -1 && h.push(239, 191, 189);
|
|
928
|
+
continue;
|
|
929
|
+
} else if (p + 1 === r) {
|
|
930
|
+
(e -= 3) > -1 && h.push(239, 191, 189);
|
|
931
|
+
continue;
|
|
932
|
+
}
|
|
933
|
+
c = t;
|
|
934
|
+
continue;
|
|
935
|
+
}
|
|
936
|
+
if (t < 56320) {
|
|
937
|
+
(e -= 3) > -1 && h.push(239, 191, 189), c = t;
|
|
938
|
+
continue;
|
|
939
|
+
}
|
|
940
|
+
t = (c - 55296 << 10 | t - 56320) + 65536;
|
|
941
|
+
} else c && (e -= 3) > -1 && h.push(239, 191, 189);
|
|
942
|
+
if (c = null, t < 128) {
|
|
943
|
+
if ((e -= 1) < 0) break;
|
|
944
|
+
h.push(t);
|
|
945
|
+
} else if (t < 2048) {
|
|
946
|
+
if ((e -= 2) < 0) break;
|
|
947
|
+
h.push(
|
|
948
|
+
t >> 6 | 192,
|
|
949
|
+
t & 63 | 128
|
|
950
|
+
);
|
|
951
|
+
} else if (t < 65536) {
|
|
952
|
+
if ((e -= 3) < 0) break;
|
|
953
|
+
h.push(
|
|
954
|
+
t >> 12 | 224,
|
|
955
|
+
t >> 6 & 63 | 128,
|
|
956
|
+
t & 63 | 128
|
|
957
|
+
);
|
|
958
|
+
} else if (t < 1114112) {
|
|
959
|
+
if ((e -= 4) < 0) break;
|
|
960
|
+
h.push(
|
|
961
|
+
t >> 18 | 240,
|
|
962
|
+
t >> 12 & 63 | 128,
|
|
963
|
+
t >> 6 & 63 | 128,
|
|
964
|
+
t & 63 | 128
|
|
965
|
+
);
|
|
966
|
+
} else
|
|
967
|
+
throw new Error("Invalid code point");
|
|
968
|
+
}
|
|
969
|
+
return h;
|
|
970
|
+
}
|
|
971
|
+
function Ye(n) {
|
|
972
|
+
const e = [];
|
|
973
|
+
for (let t = 0; t < n.length; ++t)
|
|
974
|
+
e.push(n.charCodeAt(t) & 255);
|
|
975
|
+
return e;
|
|
976
|
+
}
|
|
977
|
+
function Xe(n, e) {
|
|
978
|
+
let t, r, c;
|
|
979
|
+
const h = [];
|
|
980
|
+
for (let p = 0; p < n.length && !((e -= 2) < 0); ++p)
|
|
981
|
+
t = n.charCodeAt(p), r = t >> 8, c = t % 256, h.push(c), h.push(r);
|
|
982
|
+
return h;
|
|
983
|
+
}
|
|
984
|
+
function Oe(n) {
|
|
985
|
+
return i.toByteArray(ze(n));
|
|
986
|
+
}
|
|
987
|
+
function ae(n, e, t, r) {
|
|
988
|
+
let c;
|
|
989
|
+
for (c = 0; c < r && !(c + t >= e.length || c >= n.length); ++c)
|
|
990
|
+
e[c + t] = n[c];
|
|
991
|
+
return c;
|
|
992
|
+
}
|
|
993
|
+
function H(n, e) {
|
|
994
|
+
return n instanceof e || n != null && n.constructor != null && n.constructor.name != null && n.constructor.name === e.name;
|
|
995
|
+
}
|
|
996
|
+
function pe(n) {
|
|
997
|
+
return n !== n;
|
|
998
|
+
}
|
|
999
|
+
const Qe = (function() {
|
|
1000
|
+
const n = "0123456789abcdef", e = new Array(256);
|
|
1001
|
+
for (let t = 0; t < 16; ++t) {
|
|
1002
|
+
const r = t * 16;
|
|
1003
|
+
for (let c = 0; c < 16; ++c)
|
|
1004
|
+
e[r + c] = n[t] + n[c];
|
|
1005
|
+
}
|
|
1006
|
+
return e;
|
|
1007
|
+
})();
|
|
1008
|
+
function W(n) {
|
|
1009
|
+
return typeof BigInt > "u" ? Ze : n;
|
|
1010
|
+
}
|
|
1011
|
+
function Ze() {
|
|
1012
|
+
throw new Error("BigInt not supported");
|
|
1013
|
+
}
|
|
1014
|
+
})(me)), me;
|
|
1015
|
+
}
|
|
1016
|
+
var nt = it();
|
|
1017
|
+
const rt = "https://api.anam.ai", st = "/v1", Le = {
|
|
1018
|
+
client: "js-sdk",
|
|
1019
|
+
version: "4.7.0"
|
|
1020
|
+
};
|
|
1021
|
+
var ot = function(l, i, s, o) {
|
|
1022
|
+
function f(E) {
|
|
1023
|
+
return E instanceof s ? E : new s(function(d) {
|
|
1024
|
+
d(E);
|
|
1025
|
+
});
|
|
1026
|
+
}
|
|
1027
|
+
return new (s || (s = Promise))(function(E, d) {
|
|
1028
|
+
function a(m) {
|
|
1029
|
+
try {
|
|
1030
|
+
g(o.next(m));
|
|
1031
|
+
} catch (u) {
|
|
1032
|
+
d(u);
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
function S(m) {
|
|
1036
|
+
try {
|
|
1037
|
+
g(o.throw(m));
|
|
1038
|
+
} catch (u) {
|
|
1039
|
+
d(u);
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
function g(m) {
|
|
1043
|
+
m.done ? E(m.value) : f(m.value).then(a, S);
|
|
1044
|
+
}
|
|
1045
|
+
g((o = o.apply(l, i || [])).next());
|
|
1046
|
+
});
|
|
1047
|
+
};
|
|
1048
|
+
const Me = "https://api.anam.ai", ge = "/v1";
|
|
1049
|
+
var j;
|
|
1050
|
+
(function(l) {
|
|
1051
|
+
l.CLIENT_METRIC_MEASUREMENT_ERROR = "client_error", l.CLIENT_METRIC_MEASUREMENT_CONNECTION_CLOSED = "client_connection_closed", l.CLIENT_METRIC_MEASUREMENT_CONNECTION_ESTABLISHED = "client_connection_established", l.CLIENT_METRIC_MEASUREMENT_SESSION_ATTEMPT = "client_session_attempt", l.CLIENT_METRIC_MEASUREMENT_SESSION_SUCCESS = "client_session_success";
|
|
1052
|
+
})(j || (j = {}));
|
|
1053
|
+
let Se = Me, ke = ge, K, Fe = !1;
|
|
1054
|
+
const at = (l, i = ge) => {
|
|
1055
|
+
Se = l, ke = i;
|
|
1056
|
+
}, ct = (l) => {
|
|
1057
|
+
K = l;
|
|
1058
|
+
}, ut = (l) => {
|
|
1059
|
+
Fe = l;
|
|
1060
|
+
};
|
|
1061
|
+
let J = {
|
|
1062
|
+
sessionId: null,
|
|
1063
|
+
organizationId: null,
|
|
1064
|
+
attemptCorrelationId: null
|
|
1065
|
+
};
|
|
1066
|
+
const ee = (l) => {
|
|
1067
|
+
J = Object.assign(Object.assign({}, J), l);
|
|
1068
|
+
}, X = (l, i, s) => ot(void 0, void 0, void 0, function* () {
|
|
1069
|
+
if (!Fe)
|
|
1070
|
+
try {
|
|
1071
|
+
const o = Object.assign(Object.assign({}, Le), s);
|
|
1072
|
+
J.sessionId && (o.sessionId = J.sessionId), J.organizationId && (o.organizationId = J.organizationId), J.attemptCorrelationId && (o.attemptCorrelationId = J.attemptCorrelationId);
|
|
1073
|
+
const f = `${ke}/metrics/client`;
|
|
1074
|
+
let E, d = {
|
|
1075
|
+
"Content-Type": "application/json"
|
|
1076
|
+
};
|
|
1077
|
+
K?.enabled && K?.baseUrl ? (E = `${K.baseUrl}${f}`, d["X-Anam-Target-Url"] = `${Se}${f}`) : E = `${Se}${f}`, yield fetch(E, {
|
|
1078
|
+
method: "POST",
|
|
1079
|
+
headers: d,
|
|
1080
|
+
body: JSON.stringify({
|
|
1081
|
+
name: l,
|
|
1082
|
+
value: i,
|
|
1083
|
+
tags: o
|
|
1084
|
+
})
|
|
1085
|
+
});
|
|
1086
|
+
} catch (o) {
|
|
1087
|
+
console.error("Failed to send error metric:", o);
|
|
1088
|
+
}
|
|
1089
|
+
}), lt = (l, i = "console") => {
|
|
1090
|
+
var s, o, f;
|
|
1091
|
+
const E = {};
|
|
1092
|
+
l.forEach((u) => {
|
|
1093
|
+
E[u.type] || (E[u.type] = []), E[u.type].push(u);
|
|
1094
|
+
});
|
|
1095
|
+
const d = {
|
|
1096
|
+
issues: []
|
|
1097
|
+
}, a = ((s = E["inbound-rtp"]) === null || s === void 0 ? void 0 : s.filter((u) => u.kind === "video")) || [];
|
|
1098
|
+
a.length > 0 && (d.personaVideoStream = [], a.forEach((u) => {
|
|
1099
|
+
var R, I, C, _, w;
|
|
1100
|
+
const N = {
|
|
1101
|
+
framesReceived: (R = u.framesReceived) !== null && R !== void 0 ? R : "unknown",
|
|
1102
|
+
framesDropped: (I = u.framesDropped) !== null && I !== void 0 ? I : "unknown",
|
|
1103
|
+
framesPerSecond: (C = u.framesPerSecond) !== null && C !== void 0 ? C : "unknown",
|
|
1104
|
+
packetsReceived: (_ = u.packetsReceived) !== null && _ !== void 0 ? _ : "unknown",
|
|
1105
|
+
packetsLost: (w = u.packetsLost) !== null && w !== void 0 ? w : "unknown",
|
|
1106
|
+
resolution: u.frameWidth && u.frameHeight ? `${u.frameWidth}x${u.frameHeight}` : void 0,
|
|
1107
|
+
jitter: u.jitter !== void 0 ? u.jitter : void 0
|
|
1108
|
+
};
|
|
1109
|
+
d.personaVideoStream.push(N);
|
|
1110
|
+
}));
|
|
1111
|
+
const S = ((o = E["inbound-rtp"]) === null || o === void 0 ? void 0 : o.filter((u) => u.kind === "audio")) || [];
|
|
1112
|
+
S.length > 0 && (d.personaAudioStream = [], S.forEach((u) => {
|
|
1113
|
+
var R, I, C;
|
|
1114
|
+
const _ = {
|
|
1115
|
+
packetsReceived: (R = u.packetsReceived) !== null && R !== void 0 ? R : "unknown",
|
|
1116
|
+
packetsLost: (I = u.packetsLost) !== null && I !== void 0 ? I : "unknown",
|
|
1117
|
+
audioLevel: (C = u.audioLevel) !== null && C !== void 0 ? C : "unknown",
|
|
1118
|
+
jitter: u.jitter !== void 0 ? u.jitter : void 0,
|
|
1119
|
+
totalAudioEnergy: u.totalAudioEnergy !== void 0 ? u.totalAudioEnergy : void 0
|
|
1120
|
+
};
|
|
1121
|
+
d.personaAudioStream.push(_);
|
|
1122
|
+
}));
|
|
1123
|
+
const g = ((f = E["outbound-rtp"]) === null || f === void 0 ? void 0 : f.filter((u) => u.kind === "audio")) || [];
|
|
1124
|
+
g.length > 0 && (d.userAudioInput = [], g.forEach((u) => {
|
|
1125
|
+
var R, I;
|
|
1126
|
+
const C = {
|
|
1127
|
+
packetsSent: (R = u.packetsSent) !== null && R !== void 0 ? R : "unknown",
|
|
1128
|
+
retransmittedPackets: (I = u.retransmittedPacketsSent) !== null && I !== void 0 ? I : void 0,
|
|
1129
|
+
avgPacketSendDelay: u.totalPacketSendDelay !== void 0 ? u.totalPacketSendDelay / (u.packetsSent || 1) * 1e3 : void 0
|
|
1130
|
+
};
|
|
1131
|
+
d.userAudioInput.push(C);
|
|
1132
|
+
})), E.codec && (d.codecs = [], E.codec.forEach((u) => {
|
|
1133
|
+
const R = {
|
|
1134
|
+
status: u.payloadType ? "Active" : "Available",
|
|
1135
|
+
mimeType: u.mimeType || "Unknown",
|
|
1136
|
+
payloadType: u.payloadType || "N/A",
|
|
1137
|
+
clockRate: u.clockRate || void 0,
|
|
1138
|
+
channels: u.channels || void 0
|
|
1139
|
+
};
|
|
1140
|
+
d.codecs.push(R);
|
|
1141
|
+
})), E.transport && (d.transportLayer = [], E.transport.forEach((u) => {
|
|
1142
|
+
const R = {
|
|
1143
|
+
dtlsState: u.dtlsState || "unknown",
|
|
1144
|
+
iceState: u.iceState || "unknown",
|
|
1145
|
+
bytesSent: u.bytesSent || void 0,
|
|
1146
|
+
bytesReceived: u.bytesReceived || void 0
|
|
1147
|
+
};
|
|
1148
|
+
d.transportLayer.push(R);
|
|
1149
|
+
}));
|
|
1150
|
+
const m = [];
|
|
1151
|
+
if (a.forEach((u) => {
|
|
1152
|
+
typeof u.framesDropped == "number" && u.framesDropped > 0 && m.push(`Video: ${u.framesDropped} frames dropped`), typeof u.packetsLost == "number" && u.packetsLost > 0 && m.push(`Video: ${u.packetsLost} packets lost`), typeof u.framesPerSecond == "number" && u.framesPerSecond < 23 && m.push(`Video: Low frame rate (${u.framesPerSecond} fps)`);
|
|
1153
|
+
}), S.forEach((u) => {
|
|
1154
|
+
typeof u.packetsLost == "number" && u.packetsLost > 0 && m.push(`Audio: ${u.packetsLost} packets lost`), typeof u.jitter == "number" && u.jitter > 0.1 && m.push(`Audio: High jitter (${(u.jitter * 1e3).toFixed(1)}ms)`);
|
|
1155
|
+
}), d.issues = m, i === "json")
|
|
1156
|
+
return d;
|
|
1157
|
+
console.group("📊 WebRTC Session Statistics Report"), d.personaVideoStream && d.personaVideoStream.length > 0 && (console.group("📹 Persona Video Stream (Inbound)"), d.personaVideoStream.forEach((u) => {
|
|
1158
|
+
console.log(`Frames Received: ${u.framesReceived}`), console.log(`Frames Dropped: ${u.framesDropped}`), console.log(`Frames Per Second: ${u.framesPerSecond}`), console.log(`Packets Received: ${typeof u.packetsReceived == "number" ? u.packetsReceived.toLocaleString() : u.packetsReceived}`), console.log(`Packets Lost: ${u.packetsLost}`), u.resolution && console.log(`Resolution: ${u.resolution}`), u.jitter !== void 0 && console.log(`Jitter: ${u.jitter.toFixed(5)}ms`);
|
|
1159
|
+
}), console.groupEnd()), d.personaAudioStream && d.personaAudioStream.length > 0 && (console.group("🔊 Persona Audio Stream (Inbound)"), d.personaAudioStream.forEach((u) => {
|
|
1160
|
+
console.log(`Packets Received: ${typeof u.packetsReceived == "number" ? u.packetsReceived.toLocaleString() : u.packetsReceived}`), console.log(`Packets Lost: ${u.packetsLost}`), console.log(`Audio Level: ${u.audioLevel}`), u.jitter !== void 0 && console.log(`Jitter: ${u.jitter.toFixed(5)}ms`), u.totalAudioEnergy !== void 0 && console.log(`Total Audio Energy: ${u.totalAudioEnergy.toFixed(6)}`);
|
|
1161
|
+
}), console.groupEnd()), d.userAudioInput && d.userAudioInput.length > 0 && (console.group("🎤 User Audio Input (Outbound)"), d.userAudioInput.forEach((u) => {
|
|
1162
|
+
console.log(`Packets Sent: ${typeof u.packetsSent == "number" ? u.packetsSent.toLocaleString() : u.packetsSent}`), u.retransmittedPackets && console.log(`Retransmitted Packets: ${u.retransmittedPackets}`), u.avgPacketSendDelay !== void 0 && console.log(`Avg Packet Send Delay: ${u.avgPacketSendDelay.toFixed(5)}ms`);
|
|
1163
|
+
}), console.groupEnd()), d.codecs && d.codecs.length > 0 && (console.group("🔧 Codecs Used"), d.codecs.forEach((u) => {
|
|
1164
|
+
console.log(`${u.status} ${u.mimeType} - Payload Type: ${u.payloadType}`), u.clockRate && console.log(` Clock Rate: ${u.clockRate}Hz`), u.channels && console.log(` Channels: ${u.channels}`);
|
|
1165
|
+
}), console.groupEnd()), d.transportLayer && d.transportLayer.length > 0 && (console.group("🚚 Transport Layer"), d.transportLayer.forEach((u) => {
|
|
1166
|
+
console.log(`DTLS State: ${u.dtlsState}`), console.log(`ICE State: ${u.iceState}`), (u.bytesReceived || u.bytesSent) && console.log(`Data Transfer (bytes) - Sent: ${(u.bytesSent || 0).toLocaleString()}, Received: ${(u.bytesReceived || 0).toLocaleString()}`);
|
|
1167
|
+
}), console.groupEnd()), d.issues.length > 0 ? (console.group("⚠️ Potential Issues Detected"), d.issues.forEach((u) => console.warn(u)), console.groupEnd()) : console.log("✅ No significant issues detected"), console.groupEnd();
|
|
1168
|
+
};
|
|
1169
|
+
var M;
|
|
1170
|
+
(function(l) {
|
|
1171
|
+
l.CLIENT_ERROR_CODE_USAGE_LIMIT_REACHED = "CLIENT_ERROR_CODE_USAGE_LIMIT_REACHED", l.CLIENT_ERROR_CODE_SPEND_CAP_REACHED = "CLIENT_ERROR_CODE_SPEND_CAP_REACHED", l.CLIENT_ERROR_CODE_VALIDATION_ERROR = "CLIENT_ERROR_CODE_VALIDATION_ERROR", l.CLIENT_ERROR_CODE_AUTHENTICATION_ERROR = "CLIENT_ERROR_CODE_AUTHENTICATION_ERROR", l.CLIENT_ERROR_CODE_SERVER_ERROR = "CLIENT_ERROR_CODE_SERVER_ERROR", l.CLIENT_ERROR_CODE_MAX_CONCURRENT_SESSIONS_REACHED = "CLIENT_ERROR_CODE_MAX_CONCURRENT_SESSIONS_REACHED", l.CLIENT_ERROR_CODE_SERVICE_BUSY = "CLIENT_ERROR_CODE_SERVICE_BUSY", l.CLIENT_ERROR_CODE_NO_PLAN_FOUND = "CLIENT_ERROR_CODE_NO_PLAN_FOUND", l.CLIENT_ERROR_CODE_UNKNOWN_ERROR = "CLIENT_ERROR_CODE_UNKNOWN_ERROR", l.CLIENT_ERROR_CODE_CONFIGURATION_ERROR = "CLIENT_ERROR_CODE_CONFIGURATION_ERROR";
|
|
1172
|
+
})(M || (M = {}));
|
|
1173
|
+
class x extends Error {
|
|
1174
|
+
constructor(i, s, o = 500, f) {
|
|
1175
|
+
super(i), this.name = "ClientError", this.code = s, this.statusCode = o, this.details = f, Object.setPrototypeOf(this, x.prototype), X(j.CLIENT_METRIC_MEASUREMENT_ERROR, s, {
|
|
1176
|
+
details: f,
|
|
1177
|
+
statusCode: o
|
|
1178
|
+
});
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
function Be() {
|
|
1182
|
+
return typeof crypto < "u" && crypto.randomUUID ? crypto.randomUUID() : Date.now().toString(36) + Math.random().toString(36).substr(2, 9);
|
|
1183
|
+
}
|
|
1184
|
+
function dt(l) {
|
|
1185
|
+
if (!(!l || !l.enabled)) {
|
|
1186
|
+
if (!l.baseUrl)
|
|
1187
|
+
return "API Gateway baseUrl is required when enabled";
|
|
1188
|
+
try {
|
|
1189
|
+
const i = new URL(l.baseUrl);
|
|
1190
|
+
if (!["http:", "https:", "ws:", "wss:"].includes(i.protocol))
|
|
1191
|
+
return `Invalid API Gateway baseUrl protocol: ${i.protocol}. Must be http:, https:, ws:, or wss:`;
|
|
1192
|
+
} catch {
|
|
1193
|
+
return `Invalid API Gateway baseUrl: ${l.baseUrl}`;
|
|
1194
|
+
}
|
|
1195
|
+
if (l.wsPath && !l.wsPath.startsWith("/"))
|
|
1196
|
+
return "API Gateway wsPath must start with /";
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
var F;
|
|
1200
|
+
(function(l) {
|
|
1201
|
+
l.OFFER = "offer", l.ANSWER = "answer", l.ICE_CANDIDATE = "icecandidate", l.END_SESSION = "endsession", l.HEARTBEAT = "heartbeat", l.WARNING = "warning", l.TALK_STREAM_INTERRUPTED = "talkinputstreaminterrupted", l.TALK_STREAM_INPUT = "talkstream", l.SESSION_READY = "sessionready", l.AGENT_AUDIO_INPUT = "agentaudioinput", l.AGENT_AUDIO_INPUT_END = "agentaudioinputend";
|
|
1202
|
+
})(F || (F = {}));
|
|
1203
|
+
var ue;
|
|
1204
|
+
(function(l) {
|
|
1205
|
+
l.SPEECH_TEXT = "speechText", l.CLIENT_TOOL_EVENT = "clientToolEvent";
|
|
1206
|
+
})(ue || (ue = {}));
|
|
1207
|
+
var z;
|
|
1208
|
+
(function(l) {
|
|
1209
|
+
l.PENDING = "pending", l.GRANTED = "granted", l.DENIED = "denied", l.NOT_REQUESTED = "not_requested";
|
|
1210
|
+
})(z || (z = {}));
|
|
1211
|
+
var le;
|
|
1212
|
+
(function(l) {
|
|
1213
|
+
l.USER = "user", l.PERSONA = "persona";
|
|
1214
|
+
})(le || (le = {}));
|
|
1215
|
+
var T;
|
|
1216
|
+
(function(l) {
|
|
1217
|
+
l.MESSAGE_HISTORY_UPDATED = "MESSAGE_HISTORY_UPDATED", l.MESSAGE_STREAM_EVENT_RECEIVED = "MESSAGE_STREAM_EVENT_RECEIVED", l.CONNECTION_ESTABLISHED = "CONNECTION_ESTABLISHED", l.CONNECTION_CLOSED = "CONNECTION_CLOSED", l.INPUT_AUDIO_STREAM_STARTED = "INPUT_AUDIO_STREAM_STARTED", l.VIDEO_STREAM_STARTED = "VIDEO_STREAM_STARTED", l.VIDEO_PLAY_STARTED = "VIDEO_PLAY_STARTED", l.AUDIO_STREAM_STARTED = "AUDIO_STREAM_STARTED", l.TALK_STREAM_INTERRUPTED = "TALK_STREAM_INTERRUPTED", l.SESSION_READY = "SESSION_READY", l.SERVER_WARNING = "SERVER_WARNING", l.MIC_PERMISSION_PENDING = "MIC_PERMISSION_PENDING", l.MIC_PERMISSION_GRANTED = "MIC_PERMISSION_GRANTED", l.MIC_PERMISSION_DENIED = "MIC_PERMISSION_DENIED", l.INPUT_AUDIO_DEVICE_CHANGED = "INPUT_AUDIO_DEVICE_CHANGED", l.CLIENT_TOOL_EVENT_RECEIVED = "CLIENT_TOOL_EVENT_RECEIVED";
|
|
1218
|
+
})(T || (T = {}));
|
|
1219
|
+
var V;
|
|
1220
|
+
(function(l) {
|
|
1221
|
+
l.WEB_SOCKET_OPEN = "WEB_SOCKET_OPEN", l.SIGNAL_MESSAGE_RECEIVED = "SIGNAL_MESSAGE_RECEIVED", l.WEBRTC_CHAT_MESSAGE_RECEIVED = "WEBRTC_CHAT_MESSAGE_RECEIVED", l.WEBRTC_CLIENT_TOOL_EVENT_RECEIVED = "WEBRTC_CLIENT_TOOL_EVENT_RECEIVED";
|
|
1222
|
+
})(V || (V = {}));
|
|
1223
|
+
var Y;
|
|
1224
|
+
(function(l) {
|
|
1225
|
+
l.NORMAL = "CONNECTION_CLOSED_CODE_NORMAL", l.MICROPHONE_PERMISSION_DENIED = "CONNECTION_CLOSED_CODE_MICROPHONE_PERMISSION_DENIED", l.SIGNALLING_CLIENT_CONNECTION_FAILURE = "CONNECTION_CLOSED_CODE_SIGNALLING_CLIENT_CONNECTION_FAILURE", l.WEBRTC_FAILURE = "CONNECTION_CLOSED_CODE_WEBRTC_FAILURE", l.SERVER_CLOSED_CONNECTION = "CONNECTION_CLOSED_CODE_SERVER_CLOSED_CONNECTION";
|
|
1226
|
+
})(Y || (Y = {}));
|
|
1227
|
+
class ht {
|
|
1228
|
+
constructor(i, s) {
|
|
1229
|
+
this.sequenceNumber = 0, this.config = i, this.signallingClient = s;
|
|
1230
|
+
}
|
|
1231
|
+
/**
|
|
1232
|
+
* Send PCM audio chunk to server.
|
|
1233
|
+
* @param audioData - Raw PCM audio bytes (ArrayBuffer/Uint8Array) or base64-encoded string
|
|
1234
|
+
*/
|
|
1235
|
+
sendAudioChunk(i) {
|
|
1236
|
+
const o = {
|
|
1237
|
+
audioData: typeof i == "string" ? i : this.arrayBufferToBase64(i),
|
|
1238
|
+
encoding: this.config.encoding,
|
|
1239
|
+
sampleRate: this.config.sampleRate,
|
|
1240
|
+
channels: this.config.channels,
|
|
1241
|
+
sequenceNumber: this.sequenceNumber++
|
|
1242
|
+
};
|
|
1243
|
+
this.signallingClient.sendAgentAudioInput(o);
|
|
1244
|
+
}
|
|
1245
|
+
/**
|
|
1246
|
+
* Signal end of the current audio sequence/turn.
|
|
1247
|
+
* Sends AGENT_AUDIO_INPUT_END signal message and resets sequence number.
|
|
1248
|
+
*/
|
|
1249
|
+
endSequence() {
|
|
1250
|
+
this.signallingClient.sendAgentAudioInputEnd(), this.sequenceNumber = 0;
|
|
1251
|
+
}
|
|
1252
|
+
/**
|
|
1253
|
+
* Get the current sequence number (number of chunks sent in current sequence).
|
|
1254
|
+
*/
|
|
1255
|
+
getSequenceNumber() {
|
|
1256
|
+
return this.sequenceNumber;
|
|
1257
|
+
}
|
|
1258
|
+
/**
|
|
1259
|
+
* Get the audio format configuration for this stream.
|
|
1260
|
+
*/
|
|
1261
|
+
getConfig() {
|
|
1262
|
+
return this.config;
|
|
1263
|
+
}
|
|
1264
|
+
arrayBufferToBase64(i) {
|
|
1265
|
+
const s = i instanceof Uint8Array ? i : new Uint8Array(i), o = Array.from(s, (f) => String.fromCharCode(f)).join("");
|
|
1266
|
+
return btoa(o);
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
var te = function(l, i, s, o) {
|
|
1270
|
+
function f(E) {
|
|
1271
|
+
return E instanceof s ? E : new s(function(d) {
|
|
1272
|
+
d(E);
|
|
1273
|
+
});
|
|
1274
|
+
}
|
|
1275
|
+
return new (s || (s = Promise))(function(E, d) {
|
|
1276
|
+
function a(m) {
|
|
1277
|
+
try {
|
|
1278
|
+
g(o.next(m));
|
|
1279
|
+
} catch (u) {
|
|
1280
|
+
d(u);
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
function S(m) {
|
|
1284
|
+
try {
|
|
1285
|
+
g(o.throw(m));
|
|
1286
|
+
} catch (u) {
|
|
1287
|
+
d(u);
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
function g(m) {
|
|
1291
|
+
m.done ? E(m.value) : f(m.value).then(a, S);
|
|
1292
|
+
}
|
|
1293
|
+
g((o = o.apply(l, i || [])).next());
|
|
1294
|
+
});
|
|
1295
|
+
};
|
|
1296
|
+
const Et = 5, ft = 5;
|
|
1297
|
+
class pt {
|
|
1298
|
+
constructor(i, s, o, f, E) {
|
|
1299
|
+
var d, a, S, g, m;
|
|
1300
|
+
if (this.stopSignal = !1, this.sendingBuffer = [], this.wsConnectionAttempts = 0, this.socket = null, this.heartBeatIntervalRef = null, this.publicEventEmitter = o, this.internalEventEmitter = f, this.apiGatewayConfig = E, !i)
|
|
1301
|
+
throw new Error("Signalling Client: sessionId is required");
|
|
1302
|
+
this.sessionId = i;
|
|
1303
|
+
const { heartbeatIntervalSeconds: u, maxWsReconnectionAttempts: R, url: I } = s;
|
|
1304
|
+
if (this.heartbeatIntervalSeconds = u || Et, this.maxWsReconnectionAttempts = R || ft, !I.baseUrl)
|
|
1305
|
+
throw new Error("Signalling Client: baseUrl is required");
|
|
1306
|
+
if (!((d = this.apiGatewayConfig) === null || d === void 0) && d.enabled && (!((a = this.apiGatewayConfig) === null || a === void 0) && a.baseUrl)) {
|
|
1307
|
+
const C = new URL(this.apiGatewayConfig.baseUrl), _ = (S = this.apiGatewayConfig.wsPath) !== null && S !== void 0 ? S : "/ws";
|
|
1308
|
+
C.protocol = C.protocol.replace("http", "ws"), C.pathname = _, this.url = C;
|
|
1309
|
+
const w = I.protocol || "https", N = w === "http" ? "ws" : "wss", O = `${w}://${I.baseUrl}`, B = (g = I.signallingPath) !== null && g !== void 0 ? g : "/ws", k = new URL(O);
|
|
1310
|
+
k.protocol = N === "ws" ? "ws:" : "wss:", I.port && (k.port = I.port), k.pathname = B, k.searchParams.append("session_id", i), this.url.searchParams.append("target_url", k.href);
|
|
1311
|
+
} else {
|
|
1312
|
+
const _ = `${I.protocol || "https"}://${I.baseUrl}`;
|
|
1313
|
+
this.url = new URL(_), this.url.protocol = I.protocol === "http" ? "ws:" : "wss:", I.port && (this.url.port = I.port), this.url.pathname = (m = I.signallingPath) !== null && m !== void 0 ? m : "/ws", this.url.searchParams.append("session_id", i);
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
stop() {
|
|
1317
|
+
this.stopSignal = !0, this.closeSocket();
|
|
1318
|
+
}
|
|
1319
|
+
connect() {
|
|
1320
|
+
return this.socket = new WebSocket(this.url.href), this.socket.onopen = this.onOpen.bind(this), this.socket.onclose = this.onClose.bind(this), this.socket.onerror = this.onError.bind(this), this.socket;
|
|
1321
|
+
}
|
|
1322
|
+
sendOffer(i) {
|
|
1323
|
+
return te(this, void 0, void 0, function* () {
|
|
1324
|
+
const s = {
|
|
1325
|
+
connectionDescription: i,
|
|
1326
|
+
userUid: this.sessionId
|
|
1327
|
+
// TODO: this should be renamed to session Id on the server
|
|
1328
|
+
}, o = {
|
|
1329
|
+
actionType: F.OFFER,
|
|
1330
|
+
sessionId: this.sessionId,
|
|
1331
|
+
payload: s
|
|
1332
|
+
};
|
|
1333
|
+
this.sendSignalMessage(o);
|
|
1334
|
+
});
|
|
1335
|
+
}
|
|
1336
|
+
sendIceCandidate(i) {
|
|
1337
|
+
return te(this, void 0, void 0, function* () {
|
|
1338
|
+
const s = {
|
|
1339
|
+
actionType: F.ICE_CANDIDATE,
|
|
1340
|
+
sessionId: this.sessionId,
|
|
1341
|
+
payload: i.toJSON()
|
|
1342
|
+
};
|
|
1343
|
+
this.sendSignalMessage(s);
|
|
1344
|
+
});
|
|
1345
|
+
}
|
|
1346
|
+
sendSignalMessage(i) {
|
|
1347
|
+
var s;
|
|
1348
|
+
if (((s = this.socket) === null || s === void 0 ? void 0 : s.readyState) === WebSocket.OPEN)
|
|
1349
|
+
try {
|
|
1350
|
+
this.socket.send(JSON.stringify(i));
|
|
1351
|
+
} catch (o) {
|
|
1352
|
+
console.error("SignallingClient - sendSignalMessage: error sending message", o);
|
|
1353
|
+
}
|
|
1354
|
+
else
|
|
1355
|
+
this.sendingBuffer.push(i);
|
|
1356
|
+
}
|
|
1357
|
+
sendTalkMessage(i) {
|
|
1358
|
+
return te(this, void 0, void 0, function* () {
|
|
1359
|
+
const s = {
|
|
1360
|
+
actionType: F.TALK_STREAM_INPUT,
|
|
1361
|
+
sessionId: this.sessionId,
|
|
1362
|
+
payload: i
|
|
1363
|
+
};
|
|
1364
|
+
this.sendSignalMessage(s);
|
|
1365
|
+
});
|
|
1366
|
+
}
|
|
1367
|
+
sendAgentAudioInput(i) {
|
|
1368
|
+
const s = {
|
|
1369
|
+
actionType: F.AGENT_AUDIO_INPUT,
|
|
1370
|
+
sessionId: this.sessionId,
|
|
1371
|
+
payload: i
|
|
1372
|
+
};
|
|
1373
|
+
this.sendSignalMessage(s);
|
|
1374
|
+
}
|
|
1375
|
+
sendAgentAudioInputEnd() {
|
|
1376
|
+
const i = {
|
|
1377
|
+
actionType: F.AGENT_AUDIO_INPUT_END,
|
|
1378
|
+
sessionId: this.sessionId,
|
|
1379
|
+
payload: {}
|
|
1380
|
+
};
|
|
1381
|
+
this.sendSignalMessage(i);
|
|
1382
|
+
}
|
|
1383
|
+
closeSocket() {
|
|
1384
|
+
this.socket && (this.socket.close(), this.socket = null), this.heartBeatIntervalRef && (clearInterval(this.heartBeatIntervalRef), this.heartBeatIntervalRef = null);
|
|
1385
|
+
}
|
|
1386
|
+
onOpen() {
|
|
1387
|
+
return te(this, void 0, void 0, function* () {
|
|
1388
|
+
if (!this.socket)
|
|
1389
|
+
throw new Error("SignallingClient - onOpen: socket is null");
|
|
1390
|
+
try {
|
|
1391
|
+
this.wsConnectionAttempts = 0, this.flushSendingBuffer(), this.socket.onmessage = this.onMessage.bind(this), this.startSendingHeartBeats(), this.internalEventEmitter.emit(V.WEB_SOCKET_OPEN);
|
|
1392
|
+
} catch (i) {
|
|
1393
|
+
console.error("SignallingClient - onOpen: error in onOpen", i), this.publicEventEmitter.emit(T.CONNECTION_CLOSED, Y.SIGNALLING_CLIENT_CONNECTION_FAILURE);
|
|
1394
|
+
}
|
|
1395
|
+
});
|
|
1396
|
+
}
|
|
1397
|
+
onClose() {
|
|
1398
|
+
return te(this, void 0, void 0, function* () {
|
|
1399
|
+
this.wsConnectionAttempts += 1, !this.stopSignal && (this.wsConnectionAttempts <= this.maxWsReconnectionAttempts ? (this.socket = null, setTimeout(() => {
|
|
1400
|
+
this.connect();
|
|
1401
|
+
}, 100 * this.wsConnectionAttempts)) : (this.heartBeatIntervalRef && (clearInterval(this.heartBeatIntervalRef), this.heartBeatIntervalRef = null), this.publicEventEmitter.emit(T.CONNECTION_CLOSED, Y.SIGNALLING_CLIENT_CONNECTION_FAILURE)));
|
|
1402
|
+
});
|
|
1403
|
+
}
|
|
1404
|
+
onError(i) {
|
|
1405
|
+
this.stopSignal || console.error("SignallingClient - onError: ", i);
|
|
1406
|
+
}
|
|
1407
|
+
flushSendingBuffer() {
|
|
1408
|
+
const i = [];
|
|
1409
|
+
this.sendingBuffer.length > 0 && this.sendingBuffer.forEach((s) => {
|
|
1410
|
+
var o;
|
|
1411
|
+
((o = this.socket) === null || o === void 0 ? void 0 : o.readyState) === WebSocket.OPEN ? this.socket.send(JSON.stringify(s)) : i.push(s);
|
|
1412
|
+
}), this.sendingBuffer = i;
|
|
1413
|
+
}
|
|
1414
|
+
onMessage(i) {
|
|
1415
|
+
return te(this, void 0, void 0, function* () {
|
|
1416
|
+
const s = JSON.parse(i.data);
|
|
1417
|
+
this.internalEventEmitter.emit(V.SIGNAL_MESSAGE_RECEIVED, s);
|
|
1418
|
+
});
|
|
1419
|
+
}
|
|
1420
|
+
startSendingHeartBeats() {
|
|
1421
|
+
if (!this.socket)
|
|
1422
|
+
throw new Error("SignallingClient - startSendingHeartBeats: socket is null");
|
|
1423
|
+
this.heartBeatIntervalRef && console.warn("SignallingClient - startSendingHeartBeats: heartbeat interval already set");
|
|
1424
|
+
const i = this.heartbeatIntervalSeconds * 1e3, s = {
|
|
1425
|
+
actionType: F.HEARTBEAT,
|
|
1426
|
+
sessionId: this.sessionId,
|
|
1427
|
+
payload: ""
|
|
1428
|
+
}, o = JSON.stringify(s);
|
|
1429
|
+
this.heartBeatIntervalRef = setInterval(() => {
|
|
1430
|
+
var f;
|
|
1431
|
+
this.stopSignal || ((f = this.socket) === null || f === void 0 ? void 0 : f.readyState) === WebSocket.OPEN && this.socket.send(o);
|
|
1432
|
+
}, i);
|
|
1433
|
+
}
|
|
1434
|
+
}
|
|
1435
|
+
function mt(l) {
|
|
1436
|
+
return "brainType" in l || "llmId" in l;
|
|
1437
|
+
}
|
|
1438
|
+
var xe = function(l, i, s, o) {
|
|
1439
|
+
function f(E) {
|
|
1440
|
+
return E instanceof s ? E : new s(function(d) {
|
|
1441
|
+
d(E);
|
|
1442
|
+
});
|
|
1443
|
+
}
|
|
1444
|
+
return new (s || (s = Promise))(function(E, d) {
|
|
1445
|
+
function a(m) {
|
|
1446
|
+
try {
|
|
1447
|
+
g(o.next(m));
|
|
1448
|
+
} catch (u) {
|
|
1449
|
+
d(u);
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
function S(m) {
|
|
1453
|
+
try {
|
|
1454
|
+
g(o.throw(m));
|
|
1455
|
+
} catch (u) {
|
|
1456
|
+
d(u);
|
|
1457
|
+
}
|
|
1458
|
+
}
|
|
1459
|
+
function g(m) {
|
|
1460
|
+
m.done ? E(m.value) : f(m.value).then(a, S);
|
|
1461
|
+
}
|
|
1462
|
+
g((o = o.apply(l, i || [])).next());
|
|
1463
|
+
});
|
|
1464
|
+
};
|
|
1465
|
+
class It {
|
|
1466
|
+
constructor(i, s, o) {
|
|
1467
|
+
if (!i && !s)
|
|
1468
|
+
throw new Error("Either sessionToken or apiKey must be provided");
|
|
1469
|
+
this.sessionToken = i || null, this.apiKey = s || null, this.baseUrl = o?.baseUrl || rt, this.apiVersion = o?.apiVersion || st, this.apiGatewayConfig = o?.apiGateway || void 0;
|
|
1470
|
+
}
|
|
1471
|
+
/**
|
|
1472
|
+
* Builds URL and headers for a request, applying API Gateway configuration if enabled
|
|
1473
|
+
*/
|
|
1474
|
+
buildGatewayUrlAndHeaders(i, s) {
|
|
1475
|
+
var o, f;
|
|
1476
|
+
if (!((o = this.apiGatewayConfig) === null || o === void 0) && o.enabled && (!((f = this.apiGatewayConfig) === null || f === void 0) && f.baseUrl)) {
|
|
1477
|
+
const E = `${this.apiGatewayConfig.baseUrl}${i}`, d = new URL(`${this.baseUrl}${i}`), a = Object.assign(Object.assign({}, s), { "X-Anam-Target-Url": d.href });
|
|
1478
|
+
return { url: E, headers: a };
|
|
1479
|
+
} else
|
|
1480
|
+
return {
|
|
1481
|
+
url: `${this.baseUrl}${i}`,
|
|
1482
|
+
headers: s
|
|
1483
|
+
};
|
|
1484
|
+
}
|
|
1485
|
+
startSession(i, s) {
|
|
1486
|
+
return xe(this, void 0, void 0, function* () {
|
|
1487
|
+
if (!this.sessionToken) {
|
|
1488
|
+
if (!i)
|
|
1489
|
+
throw new x("Persona configuration must be provided when using apiKey", M.CLIENT_ERROR_CODE_VALIDATION_ERROR, 400);
|
|
1490
|
+
this.sessionToken = yield this.unsafe_getSessionToken(i);
|
|
1491
|
+
}
|
|
1492
|
+
i && "brainType" in i && console.warn("Warning: brainType is deprecated and will be removed in a future version. Please use llmId instead.");
|
|
1493
|
+
try {
|
|
1494
|
+
const o = `${this.apiVersion}/engine/session`, { url: f, headers: E } = this.buildGatewayUrlAndHeaders(o, {
|
|
1495
|
+
"Content-Type": "application/json",
|
|
1496
|
+
Authorization: `Bearer ${this.sessionToken}`
|
|
1497
|
+
}), d = yield fetch(f, {
|
|
1498
|
+
method: "POST",
|
|
1499
|
+
headers: E,
|
|
1500
|
+
body: JSON.stringify({
|
|
1501
|
+
personaConfig: i,
|
|
1502
|
+
sessionOptions: s,
|
|
1503
|
+
clientMetadata: Le
|
|
1504
|
+
})
|
|
1505
|
+
}), a = yield d.json(), S = a.error;
|
|
1506
|
+
switch (d.status) {
|
|
1507
|
+
case 200:
|
|
1508
|
+
case 201:
|
|
1509
|
+
return a;
|
|
1510
|
+
case 400:
|
|
1511
|
+
throw new x("Invalid request to start session", M.CLIENT_ERROR_CODE_VALIDATION_ERROR, 400, { cause: a.message });
|
|
1512
|
+
case 401:
|
|
1513
|
+
throw new x("Authentication failed when starting session", M.CLIENT_ERROR_CODE_AUTHENTICATION_ERROR, 401, { cause: a.message });
|
|
1514
|
+
case 402:
|
|
1515
|
+
throw new x("Please sign up for a plan to start a session", M.CLIENT_ERROR_CODE_NO_PLAN_FOUND, 402, { cause: a.message });
|
|
1516
|
+
case 403:
|
|
1517
|
+
throw new x("Authentication failed when starting session", M.CLIENT_ERROR_CODE_AUTHENTICATION_ERROR, 403, { cause: a.message });
|
|
1518
|
+
case 429:
|
|
1519
|
+
throw S === "Concurrent session limit reached" ? new x("Concurrency limit reached, please upgrade your plan", M.CLIENT_ERROR_CODE_MAX_CONCURRENT_SESSIONS_REACHED, 429, { cause: a.message }) : S === "Spend cap reached" ? new x("Spend cap reached, please upgrade your plan", M.CLIENT_ERROR_CODE_SPEND_CAP_REACHED, 429, { cause: a.message }) : new x("Usage limit reached, please upgrade your plan", M.CLIENT_ERROR_CODE_USAGE_LIMIT_REACHED, 429, { cause: a.message });
|
|
1520
|
+
case 503:
|
|
1521
|
+
throw new x("There are no available personas, please try again later", M.CLIENT_ERROR_CODE_SERVICE_BUSY, 503, { cause: a.message });
|
|
1522
|
+
default:
|
|
1523
|
+
throw new x("Unknown error when starting session", M.CLIENT_ERROR_CODE_SERVER_ERROR, 500, { cause: a.message });
|
|
1524
|
+
}
|
|
1525
|
+
} catch (o) {
|
|
1526
|
+
throw o instanceof x ? o : new x("Failed to start session", M.CLIENT_ERROR_CODE_SERVER_ERROR, 500, { cause: o instanceof Error ? o.message : String(o) });
|
|
1527
|
+
}
|
|
1528
|
+
});
|
|
1529
|
+
}
|
|
1530
|
+
unsafe_getSessionToken(i) {
|
|
1531
|
+
return xe(this, void 0, void 0, function* () {
|
|
1532
|
+
if (console.warn("Using unsecure method. This method should not be used in production."), !this.apiKey)
|
|
1533
|
+
throw new Error("No apiKey provided");
|
|
1534
|
+
i && "brainType" in i && console.warn("Warning: brainType is deprecated and will be removed in a future version. Please use llmId instead.");
|
|
1535
|
+
let s = {
|
|
1536
|
+
clientLabel: "js-sdk-api-key"
|
|
1537
|
+
};
|
|
1538
|
+
mt(i) && (s = Object.assign(Object.assign({}, s), { personaConfig: i }));
|
|
1539
|
+
try {
|
|
1540
|
+
const o = `${this.apiVersion}/auth/session-token`, { url: f, headers: E } = this.buildGatewayUrlAndHeaders(o, {
|
|
1541
|
+
"Content-Type": "application/json",
|
|
1542
|
+
Authorization: `Bearer ${this.apiKey}`
|
|
1543
|
+
});
|
|
1544
|
+
return (yield (yield fetch(f, {
|
|
1545
|
+
method: "POST",
|
|
1546
|
+
headers: E,
|
|
1547
|
+
body: JSON.stringify(s)
|
|
1548
|
+
})).json()).sessionToken;
|
|
1549
|
+
} catch {
|
|
1550
|
+
throw new Error("Failed to get session token");
|
|
1551
|
+
}
|
|
1552
|
+
});
|
|
1553
|
+
}
|
|
1554
|
+
getApiUrl() {
|
|
1555
|
+
return `${this.baseUrl}${this.apiVersion}`;
|
|
1556
|
+
}
|
|
1557
|
+
}
|
|
1558
|
+
var St = function(l, i, s, o) {
|
|
1559
|
+
function f(E) {
|
|
1560
|
+
return E instanceof s ? E : new s(function(d) {
|
|
1561
|
+
d(E);
|
|
1562
|
+
});
|
|
1563
|
+
}
|
|
1564
|
+
return new (s || (s = Promise))(function(E, d) {
|
|
1565
|
+
function a(m) {
|
|
1566
|
+
try {
|
|
1567
|
+
g(o.next(m));
|
|
1568
|
+
} catch (u) {
|
|
1569
|
+
d(u);
|
|
1570
|
+
}
|
|
1571
|
+
}
|
|
1572
|
+
function S(m) {
|
|
1573
|
+
try {
|
|
1574
|
+
g(o.throw(m));
|
|
1575
|
+
} catch (u) {
|
|
1576
|
+
d(u);
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1579
|
+
function g(m) {
|
|
1580
|
+
m.done ? E(m.value) : f(m.value).then(a, S);
|
|
1581
|
+
}
|
|
1582
|
+
g((o = o.apply(l, i || [])).next());
|
|
1583
|
+
});
|
|
1584
|
+
};
|
|
1585
|
+
class gt {
|
|
1586
|
+
constructor(i, s, o) {
|
|
1587
|
+
this.baseUrl = i, this.sessionId = s, this.apiGatewayConfig = o;
|
|
1588
|
+
}
|
|
1589
|
+
sendTalkCommand(i) {
|
|
1590
|
+
return St(this, void 0, void 0, function* () {
|
|
1591
|
+
var s, o;
|
|
1592
|
+
try {
|
|
1593
|
+
let f, E = {
|
|
1594
|
+
"Content-Type": "application/json"
|
|
1595
|
+
};
|
|
1596
|
+
const d = "/talk", a = `?session_id=${this.sessionId}`;
|
|
1597
|
+
if (!((s = this.apiGatewayConfig) === null || s === void 0) && s.enabled && (!((o = this.apiGatewayConfig) === null || o === void 0) && o.baseUrl)) {
|
|
1598
|
+
f = `${this.apiGatewayConfig.baseUrl}${d}${a}`;
|
|
1599
|
+
const g = new URL(`${this.baseUrl}${d}${a}`);
|
|
1600
|
+
E["X-Anam-Target-Url"] = g.href;
|
|
1601
|
+
} else
|
|
1602
|
+
f = `${this.baseUrl}${d}${a}`;
|
|
1603
|
+
const S = yield fetch(f, {
|
|
1604
|
+
method: "POST",
|
|
1605
|
+
headers: E,
|
|
1606
|
+
body: JSON.stringify({
|
|
1607
|
+
content: i
|
|
1608
|
+
})
|
|
1609
|
+
});
|
|
1610
|
+
if (!S.ok)
|
|
1611
|
+
throw new Error(`Failed to send talk command: ${S.status} ${S.statusText}`);
|
|
1612
|
+
} catch (f) {
|
|
1613
|
+
throw console.error(f), new Error("EngineApiRestClient - sendTalkCommand: Failed to send talk command");
|
|
1614
|
+
}
|
|
1615
|
+
});
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1618
|
+
class Ct {
|
|
1619
|
+
constructor() {
|
|
1620
|
+
this.listeners = {};
|
|
1621
|
+
}
|
|
1622
|
+
addListener(i, s) {
|
|
1623
|
+
this.listeners[i] || (this.listeners[i] = /* @__PURE__ */ new Set()), this.listeners[i].add(s);
|
|
1624
|
+
}
|
|
1625
|
+
removeListener(i, s) {
|
|
1626
|
+
this.listeners[i] && this.listeners[i].delete(s);
|
|
1627
|
+
}
|
|
1628
|
+
emit(i, ...s) {
|
|
1629
|
+
this.listeners[i] && this.listeners[i].forEach((o) => {
|
|
1630
|
+
o(...s);
|
|
1631
|
+
});
|
|
1632
|
+
}
|
|
1633
|
+
}
|
|
1634
|
+
class _t {
|
|
1635
|
+
constructor(i, s) {
|
|
1636
|
+
this.messages = [], this.publicEventEmitter = i, this.internalEventEmitter = s, this.internalEventEmitter.addListener(V.WEBRTC_CHAT_MESSAGE_RECEIVED, this.processWebRtcTextMessageEvent.bind(this));
|
|
1637
|
+
}
|
|
1638
|
+
webRtcTextMessageEventToMessageStreamEvent(i) {
|
|
1639
|
+
return {
|
|
1640
|
+
id: `${i.role}::${i.message_id}`,
|
|
1641
|
+
// id is the same for persona and user for a single question response, so we need to differentiate them
|
|
1642
|
+
content: i.content,
|
|
1643
|
+
role: i.role,
|
|
1644
|
+
endOfSpeech: i.end_of_speech,
|
|
1645
|
+
interrupted: i.interrupted
|
|
1646
|
+
};
|
|
1647
|
+
}
|
|
1648
|
+
processUserMessage(i) {
|
|
1649
|
+
const s = {
|
|
1650
|
+
id: i.id,
|
|
1651
|
+
content: i.content,
|
|
1652
|
+
role: i.role
|
|
1653
|
+
};
|
|
1654
|
+
this.messages.push(s);
|
|
1655
|
+
}
|
|
1656
|
+
processPersonaMessage(i) {
|
|
1657
|
+
const s = {
|
|
1658
|
+
id: i.id,
|
|
1659
|
+
content: i.content,
|
|
1660
|
+
role: i.role,
|
|
1661
|
+
interrupted: i.interrupted
|
|
1662
|
+
}, o = this.messages.findIndex((f) => f.id === s.id);
|
|
1663
|
+
if (o !== -1) {
|
|
1664
|
+
const f = this.messages[o];
|
|
1665
|
+
this.messages[o] = Object.assign(Object.assign({}, f), { content: f.content + s.content, interrupted: f.interrupted || s.interrupted });
|
|
1666
|
+
} else
|
|
1667
|
+
this.messages.push(s);
|
|
1668
|
+
}
|
|
1669
|
+
processWebRtcTextMessageEvent(i) {
|
|
1670
|
+
const s = this.webRtcTextMessageEventToMessageStreamEvent(i);
|
|
1671
|
+
switch (this.publicEventEmitter.emit(T.MESSAGE_STREAM_EVENT_RECEIVED, s), s.role) {
|
|
1672
|
+
case le.USER:
|
|
1673
|
+
this.processUserMessage(s);
|
|
1674
|
+
break;
|
|
1675
|
+
case le.PERSONA:
|
|
1676
|
+
this.processPersonaMessage(s);
|
|
1677
|
+
break;
|
|
1678
|
+
}
|
|
1679
|
+
s.endOfSpeech && this.publicEventEmitter.emit(T.MESSAGE_HISTORY_UPDATED, this.messages);
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
class At {
|
|
1683
|
+
constructor() {
|
|
1684
|
+
this.listeners = {};
|
|
1685
|
+
}
|
|
1686
|
+
addListener(i, s) {
|
|
1687
|
+
this.listeners[i] || (this.listeners[i] = /* @__PURE__ */ new Set()), this.listeners[i].add(s);
|
|
1688
|
+
}
|
|
1689
|
+
removeListener(i, s) {
|
|
1690
|
+
this.listeners[i] && this.listeners[i].delete(s);
|
|
1691
|
+
}
|
|
1692
|
+
emit(i, ...s) {
|
|
1693
|
+
if (i === T.CONNECTION_ESTABLISHED && X(j.CLIENT_METRIC_MEASUREMENT_CONNECTION_ESTABLISHED, "1"), i === T.CONNECTION_CLOSED) {
|
|
1694
|
+
const [o, f] = s;
|
|
1695
|
+
X(j.CLIENT_METRIC_MEASUREMENT_CONNECTION_CLOSED, o, f ? { details: f } : void 0);
|
|
1696
|
+
}
|
|
1697
|
+
this.listeners[i] && this.listeners[i].forEach((o) => {
|
|
1698
|
+
o(...s);
|
|
1699
|
+
});
|
|
1700
|
+
}
|
|
1701
|
+
}
|
|
1702
|
+
var P;
|
|
1703
|
+
(function(l) {
|
|
1704
|
+
l[l.UNSTARTED = 0] = "UNSTARTED", l[l.STREAMING = 1] = "STREAMING", l[l.INTERRUPTED = 2] = "INTERRUPTED", l[l.ENDED = 3] = "ENDED";
|
|
1705
|
+
})(P || (P = {}));
|
|
1706
|
+
var Ie = function(l, i, s, o) {
|
|
1707
|
+
function f(E) {
|
|
1708
|
+
return E instanceof s ? E : new s(function(d) {
|
|
1709
|
+
d(E);
|
|
1710
|
+
});
|
|
1711
|
+
}
|
|
1712
|
+
return new (s || (s = Promise))(function(E, d) {
|
|
1713
|
+
function a(m) {
|
|
1714
|
+
try {
|
|
1715
|
+
g(o.next(m));
|
|
1716
|
+
} catch (u) {
|
|
1717
|
+
d(u);
|
|
1718
|
+
}
|
|
1719
|
+
}
|
|
1720
|
+
function S(m) {
|
|
1721
|
+
try {
|
|
1722
|
+
g(o.throw(m));
|
|
1723
|
+
} catch (u) {
|
|
1724
|
+
d(u);
|
|
1725
|
+
}
|
|
1726
|
+
}
|
|
1727
|
+
function g(m) {
|
|
1728
|
+
m.done ? E(m.value) : f(m.value).then(a, S);
|
|
1729
|
+
}
|
|
1730
|
+
g((o = o.apply(l, i || [])).next());
|
|
1731
|
+
});
|
|
1732
|
+
};
|
|
1733
|
+
class Rt {
|
|
1734
|
+
constructor(i, s, o) {
|
|
1735
|
+
this.state = P.UNSTARTED, this.correlationId = i, this.internalEventEmitter = s, this.signallingClient = o, this.internalEventEmitter.addListener(V.SIGNAL_MESSAGE_RECEIVED, this.onSignalMessage.bind(this));
|
|
1736
|
+
}
|
|
1737
|
+
onDeactivate() {
|
|
1738
|
+
this.internalEventEmitter.removeListener(V.SIGNAL_MESSAGE_RECEIVED, this.onSignalMessage.bind(this));
|
|
1739
|
+
}
|
|
1740
|
+
onSignalMessage(i) {
|
|
1741
|
+
return Ie(this, void 0, void 0, function* () {
|
|
1742
|
+
i.actionType === F.TALK_STREAM_INTERRUPTED && i.payload.correlationId === this.correlationId && (this.state = P.INTERRUPTED, this.onDeactivate());
|
|
1743
|
+
});
|
|
1744
|
+
}
|
|
1745
|
+
endMessage() {
|
|
1746
|
+
return Ie(this, void 0, void 0, function* () {
|
|
1747
|
+
if (this.state === P.ENDED) {
|
|
1748
|
+
console.warn("Talk stream is already ended via end of speech. No need to call endMessage.");
|
|
1749
|
+
return;
|
|
1750
|
+
}
|
|
1751
|
+
if (this.state !== P.STREAMING) {
|
|
1752
|
+
console.warn("Talk stream is not active state: " + this.state);
|
|
1753
|
+
return;
|
|
1754
|
+
}
|
|
1755
|
+
const i = {
|
|
1756
|
+
content: "",
|
|
1757
|
+
startOfSpeech: !1,
|
|
1758
|
+
endOfSpeech: !0,
|
|
1759
|
+
correlationId: this.correlationId
|
|
1760
|
+
};
|
|
1761
|
+
yield this.signallingClient.sendTalkMessage(i), this.state = P.ENDED, this.onDeactivate();
|
|
1762
|
+
});
|
|
1763
|
+
}
|
|
1764
|
+
streamMessageChunk(i, s) {
|
|
1765
|
+
return Ie(this, void 0, void 0, function* () {
|
|
1766
|
+
if (this.state !== P.STREAMING && this.state !== P.UNSTARTED)
|
|
1767
|
+
throw new Error("Talk stream is not in an active state: " + this.state);
|
|
1768
|
+
const o = {
|
|
1769
|
+
content: i,
|
|
1770
|
+
startOfSpeech: this.state === P.UNSTARTED,
|
|
1771
|
+
endOfSpeech: s,
|
|
1772
|
+
correlationId: this.correlationId
|
|
1773
|
+
};
|
|
1774
|
+
this.state = s ? P.ENDED : P.STREAMING, this.state === P.ENDED && this.onDeactivate(), yield this.signallingClient.sendTalkMessage(o);
|
|
1775
|
+
});
|
|
1776
|
+
}
|
|
1777
|
+
getCorrelationId() {
|
|
1778
|
+
return this.correlationId;
|
|
1779
|
+
}
|
|
1780
|
+
isActive() {
|
|
1781
|
+
return this.state === P.STREAMING || this.state === P.UNSTARTED;
|
|
1782
|
+
}
|
|
1783
|
+
getState() {
|
|
1784
|
+
return this.state;
|
|
1785
|
+
}
|
|
1786
|
+
}
|
|
1787
|
+
var $ = function(l, i, s, o) {
|
|
1788
|
+
function f(E) {
|
|
1789
|
+
return E instanceof s ? E : new s(function(d) {
|
|
1790
|
+
d(E);
|
|
1791
|
+
});
|
|
1792
|
+
}
|
|
1793
|
+
return new (s || (s = Promise))(function(E, d) {
|
|
1794
|
+
function a(m) {
|
|
1795
|
+
try {
|
|
1796
|
+
g(o.next(m));
|
|
1797
|
+
} catch (u) {
|
|
1798
|
+
d(u);
|
|
1799
|
+
}
|
|
1800
|
+
}
|
|
1801
|
+
function S(m) {
|
|
1802
|
+
try {
|
|
1803
|
+
g(o.throw(m));
|
|
1804
|
+
} catch (u) {
|
|
1805
|
+
d(u);
|
|
1806
|
+
}
|
|
1807
|
+
}
|
|
1808
|
+
function g(m) {
|
|
1809
|
+
m.done ? E(m.value) : f(m.value).then(a, S);
|
|
1810
|
+
}
|
|
1811
|
+
g((o = o.apply(l, i || [])).next());
|
|
1812
|
+
});
|
|
1813
|
+
};
|
|
1814
|
+
const yt = 15e3, Tt = 5e3, wt = 2;
|
|
1815
|
+
class Nt {
|
|
1816
|
+
constructor(i, s, o, f) {
|
|
1817
|
+
var E, d, a, S;
|
|
1818
|
+
this.peerConnection = null, this.connectionReceivedAnswer = !1, this.remoteIceCandidateBuffer = [], this.inputAudioStream = null, this.dataChannel = null, this.videoElement = null, this.videoStream = null, this.audioStream = null, this.inputAudioState = {
|
|
1819
|
+
isMuted: !1,
|
|
1820
|
+
permissionState: z.NOT_REQUESTED
|
|
1821
|
+
}, this.successMetricPoller = null, this.successMetricFired = !1, this.showPeerConnectionStatsReport = !1, this.peerConnectionStatsReportOutputFormat = "console", this.statsCollectionInterval = null, this.agentAudioInputStream = null, this.publicEventEmitter = o, this.internalEventEmitter = f, this.apiGatewayConfig = s.apiGateway;
|
|
1822
|
+
const { inputAudio: g } = s;
|
|
1823
|
+
this.inputAudioState = g.inputAudioState, s.inputAudio.userProvidedMediaStream && (this.inputAudioStream = s.inputAudio.userProvidedMediaStream), this.disableInputAudio = s.inputAudio.disableInputAudio === !0, this.internalEventEmitter.addListener(V.WEB_SOCKET_OPEN, this.onSignallingClientConnected.bind(this)), this.internalEventEmitter.addListener(V.SIGNAL_MESSAGE_RECEIVED, this.onSignalMessage.bind(this)), this.iceServers = s.iceServers, this.signallingClient = new pt(i, s.signalling, this.publicEventEmitter, this.internalEventEmitter, this.apiGatewayConfig), this.engineApiRestClient = new gt(s.engine.baseUrl, i, this.apiGatewayConfig), this.audioDeviceId = s.inputAudio.audioDeviceId, this.showPeerConnectionStatsReport = (d = (E = s.metrics) === null || E === void 0 ? void 0 : E.showPeerConnectionStatsReport) !== null && d !== void 0 ? d : !1, this.peerConnectionStatsReportOutputFormat = (S = (a = s.metrics) === null || a === void 0 ? void 0 : a.peerConnectionStatsReportOutputFormat) !== null && S !== void 0 ? S : "console";
|
|
1824
|
+
}
|
|
1825
|
+
onInputAudioStateChange(i, s) {
|
|
1826
|
+
i.isMuted !== s.isMuted && (s.isMuted ? this.muteAllAudioTracks() : this.unmuteAllAudioTracks());
|
|
1827
|
+
}
|
|
1828
|
+
muteAllAudioTracks() {
|
|
1829
|
+
var i;
|
|
1830
|
+
(i = this.inputAudioStream) === null || i === void 0 || i.getAudioTracks().forEach((s) => {
|
|
1831
|
+
s.enabled = !1;
|
|
1832
|
+
});
|
|
1833
|
+
}
|
|
1834
|
+
unmuteAllAudioTracks() {
|
|
1835
|
+
var i;
|
|
1836
|
+
(i = this.inputAudioStream) === null || i === void 0 || i.getAudioTracks().forEach((s) => {
|
|
1837
|
+
s.enabled = !0;
|
|
1838
|
+
});
|
|
1839
|
+
}
|
|
1840
|
+
startStatsCollection() {
|
|
1841
|
+
this.statsCollectionInterval || (this.statsCollectionInterval = setInterval(() => $(this, void 0, void 0, function* () {
|
|
1842
|
+
if (!(!this.peerConnection || !this.dataChannel || this.dataChannel.readyState !== "open"))
|
|
1843
|
+
try {
|
|
1844
|
+
const i = yield this.peerConnection.getStats();
|
|
1845
|
+
this.sendClientSideMetrics(i);
|
|
1846
|
+
} catch (i) {
|
|
1847
|
+
console.error("Failed to collect and send stats:", i);
|
|
1848
|
+
}
|
|
1849
|
+
}), Tt));
|
|
1850
|
+
}
|
|
1851
|
+
sendClientSideMetrics(i) {
|
|
1852
|
+
i.forEach((s) => {
|
|
1853
|
+
if (s.type === "inbound-rtp") {
|
|
1854
|
+
const o = {
|
|
1855
|
+
message_type: "remote_rtp_stats",
|
|
1856
|
+
data: s
|
|
1857
|
+
};
|
|
1858
|
+
this.dataChannel && this.dataChannel.readyState === "open" && this.dataChannel.send(JSON.stringify(o));
|
|
1859
|
+
}
|
|
1860
|
+
});
|
|
1861
|
+
}
|
|
1862
|
+
startSuccessMetricPolling() {
|
|
1863
|
+
if (this.successMetricPoller || this.successMetricFired)
|
|
1864
|
+
return;
|
|
1865
|
+
const i = setTimeout(() => {
|
|
1866
|
+
this.successMetricPoller && (console.warn("No video frames received, there is a problem with the connection."), clearInterval(this.successMetricPoller), this.successMetricPoller = null);
|
|
1867
|
+
}, yt);
|
|
1868
|
+
this.successMetricPoller = setInterval(() => $(this, void 0, void 0, function* () {
|
|
1869
|
+
if (!this.peerConnection || this.successMetricFired) {
|
|
1870
|
+
this.successMetricPoller && clearInterval(this.successMetricPoller), clearTimeout(i);
|
|
1871
|
+
return;
|
|
1872
|
+
}
|
|
1873
|
+
try {
|
|
1874
|
+
const s = yield this.peerConnection.getStats();
|
|
1875
|
+
let o = !1, f = null;
|
|
1876
|
+
s.forEach((E) => {
|
|
1877
|
+
E.type === "inbound-rtp" && E.kind === "video" && (E.framesDecoded !== void 0 && E.framesDecoded > 0 ? (o = !0, f = "framesDecoded") : E.framesReceived !== void 0 && E.framesReceived > 0 ? (o = !0, f = "framesReceived") : E.bytesReceived > 0 && E.packetsReceived > 0 && // Additional check: ensure we've received enough data for actual video
|
|
1878
|
+
E.bytesReceived > 1e5 && (o = !0, f = "bytesReceived"));
|
|
1879
|
+
}), o && !this.successMetricFired && (this.successMetricFired = !0, X(j.CLIENT_METRIC_MEASUREMENT_SESSION_SUCCESS, "1", f ? { detectionMethod: f } : void 0), this.successMetricPoller && clearInterval(this.successMetricPoller), clearTimeout(i), this.successMetricPoller = null);
|
|
1880
|
+
} catch {
|
|
1881
|
+
}
|
|
1882
|
+
}), 500);
|
|
1883
|
+
}
|
|
1884
|
+
muteInputAudio() {
|
|
1885
|
+
const i = this.inputAudioState, s = Object.assign(Object.assign({}, this.inputAudioState), { isMuted: !0 });
|
|
1886
|
+
return this.inputAudioState = s, this.onInputAudioStateChange(i, s), this.inputAudioState;
|
|
1887
|
+
}
|
|
1888
|
+
unmuteInputAudio() {
|
|
1889
|
+
const i = this.inputAudioState, s = Object.assign(Object.assign({}, this.inputAudioState), { isMuted: !1 });
|
|
1890
|
+
return this.inputAudioState = s, this.onInputAudioStateChange(i, s), this.inputAudioState;
|
|
1891
|
+
}
|
|
1892
|
+
getInputAudioState() {
|
|
1893
|
+
return this.inputAudioState;
|
|
1894
|
+
}
|
|
1895
|
+
getPeerConnection() {
|
|
1896
|
+
return this.peerConnection;
|
|
1897
|
+
}
|
|
1898
|
+
changeAudioInputDevice(i) {
|
|
1899
|
+
return $(this, void 0, void 0, function* () {
|
|
1900
|
+
if (!this.peerConnection)
|
|
1901
|
+
throw new Error("StreamingClient - changeAudioInputDevice: peer connection is not initialized. Start streaming first.");
|
|
1902
|
+
if (i == null)
|
|
1903
|
+
throw new Error("StreamingClient - changeAudioInputDevice: deviceId is required");
|
|
1904
|
+
const s = this.inputAudioState.isMuted;
|
|
1905
|
+
try {
|
|
1906
|
+
this.inputAudioStream && this.inputAudioStream.getAudioTracks().forEach((f) => {
|
|
1907
|
+
f.stop();
|
|
1908
|
+
});
|
|
1909
|
+
const o = {
|
|
1910
|
+
echoCancellation: !0,
|
|
1911
|
+
deviceId: {
|
|
1912
|
+
exact: i
|
|
1913
|
+
}
|
|
1914
|
+
};
|
|
1915
|
+
this.inputAudioStream = yield navigator.mediaDevices.getUserMedia({
|
|
1916
|
+
audio: o
|
|
1917
|
+
}), this.audioDeviceId = i, yield this.setupAudioTrack(), s && this.muteAllAudioTracks(), this.publicEventEmitter.emit(T.INPUT_AUDIO_DEVICE_CHANGED, i);
|
|
1918
|
+
} catch (o) {
|
|
1919
|
+
throw console.error("Failed to change audio input device:", o), new Error(`StreamingClient - changeAudioInputDevice: ${o instanceof Error ? o.message : String(o)}`);
|
|
1920
|
+
}
|
|
1921
|
+
});
|
|
1922
|
+
}
|
|
1923
|
+
getInputAudioStream() {
|
|
1924
|
+
return this.inputAudioStream;
|
|
1925
|
+
}
|
|
1926
|
+
getVideoStream() {
|
|
1927
|
+
return this.videoStream;
|
|
1928
|
+
}
|
|
1929
|
+
getAudioStream() {
|
|
1930
|
+
return this.audioStream;
|
|
1931
|
+
}
|
|
1932
|
+
sendDataMessage(i) {
|
|
1933
|
+
this.dataChannel && this.dataChannel.readyState === "open" && this.dataChannel.send(i);
|
|
1934
|
+
}
|
|
1935
|
+
setMediaStreamTargetById(i) {
|
|
1936
|
+
if (i) {
|
|
1937
|
+
const s = document.getElementById(i);
|
|
1938
|
+
if (!s)
|
|
1939
|
+
throw new Error(`StreamingClient: video element with id ${i} not found`);
|
|
1940
|
+
this.videoElement = s;
|
|
1941
|
+
}
|
|
1942
|
+
}
|
|
1943
|
+
startConnection() {
|
|
1944
|
+
try {
|
|
1945
|
+
if (this.peerConnection) {
|
|
1946
|
+
console.error("StreamingClient - startConnection: peer connection already exists");
|
|
1947
|
+
return;
|
|
1948
|
+
}
|
|
1949
|
+
this.signallingClient.connect();
|
|
1950
|
+
} catch (i) {
|
|
1951
|
+
console.error("StreamingClient - startConnection: error", i), this.handleWebrtcFailure(i);
|
|
1952
|
+
}
|
|
1953
|
+
}
|
|
1954
|
+
stopConnection() {
|
|
1955
|
+
return $(this, void 0, void 0, function* () {
|
|
1956
|
+
yield this.shutdown();
|
|
1957
|
+
});
|
|
1958
|
+
}
|
|
1959
|
+
sendTalkCommand(i) {
|
|
1960
|
+
return $(this, void 0, void 0, function* () {
|
|
1961
|
+
if (!this.peerConnection)
|
|
1962
|
+
throw new Error("StreamingClient - sendTalkCommand: peer connection is null");
|
|
1963
|
+
yield this.engineApiRestClient.sendTalkCommand(i);
|
|
1964
|
+
});
|
|
1965
|
+
}
|
|
1966
|
+
startTalkMessageStream(i) {
|
|
1967
|
+
return i || (i = Math.random().toString(36).substring(2, 15)), new Rt(i, this.internalEventEmitter, this.signallingClient);
|
|
1968
|
+
}
|
|
1969
|
+
createAgentAudioInputStream(i) {
|
|
1970
|
+
return this.agentAudioInputStream = new ht(i, this.signallingClient), this.agentAudioInputStream;
|
|
1971
|
+
}
|
|
1972
|
+
getAgentAudioInputStream() {
|
|
1973
|
+
return this.agentAudioInputStream;
|
|
1974
|
+
}
|
|
1975
|
+
initPeerConnection() {
|
|
1976
|
+
return $(this, void 0, void 0, function* () {
|
|
1977
|
+
this.peerConnection = new RTCPeerConnection({
|
|
1978
|
+
iceServers: this.iceServers,
|
|
1979
|
+
iceCandidatePoolSize: wt
|
|
1980
|
+
}), this.peerConnection.onicecandidate = this.onIceCandidate.bind(this), this.peerConnection.oniceconnectionstatechange = this.onIceConnectionStateChange.bind(this), this.peerConnection.onconnectionstatechange = this.onConnectionStateChange.bind(this), this.peerConnection.addEventListener("track", this.onTrackEventHandler.bind(this)), yield this.setupDataChannels(), this.peerConnection.addTransceiver("video", { direction: "recvonly" }), this.disableInputAudio ? this.peerConnection.addTransceiver("audio", { direction: "recvonly" }) : (this.peerConnection.addTransceiver("audio", { direction: "sendrecv" }), this.inputAudioStream ? yield this.setupAudioTrack() : this.requestMicrophonePermissionAsync().catch((i) => {
|
|
1981
|
+
console.error("Async microphone permission request failed:", i);
|
|
1982
|
+
}));
|
|
1983
|
+
});
|
|
1984
|
+
}
|
|
1985
|
+
onSignalMessage(i) {
|
|
1986
|
+
return $(this, void 0, void 0, function* () {
|
|
1987
|
+
if (!this.peerConnection) {
|
|
1988
|
+
console.error("StreamingClient - onSignalMessage: peerConnection is not initialized");
|
|
1989
|
+
return;
|
|
1990
|
+
}
|
|
1991
|
+
switch (i.actionType) {
|
|
1992
|
+
case F.ANSWER:
|
|
1993
|
+
const s = i.payload;
|
|
1994
|
+
yield this.peerConnection.setRemoteDescription(s), this.connectionReceivedAnswer = !0, this.flushRemoteIceCandidateBuffer();
|
|
1995
|
+
break;
|
|
1996
|
+
case F.ICE_CANDIDATE:
|
|
1997
|
+
const o = i.payload, f = new RTCIceCandidate(o);
|
|
1998
|
+
this.connectionReceivedAnswer ? yield this.peerConnection.addIceCandidate(f) : this.remoteIceCandidateBuffer.push(f);
|
|
1999
|
+
break;
|
|
2000
|
+
case F.END_SESSION:
|
|
2001
|
+
const E = i.payload;
|
|
2002
|
+
this.publicEventEmitter.emit(T.CONNECTION_CLOSED, Y.SERVER_CLOSED_CONNECTION, E), this.shutdown();
|
|
2003
|
+
break;
|
|
2004
|
+
case F.WARNING:
|
|
2005
|
+
const d = i.payload;
|
|
2006
|
+
console.warn("Warning received from server: " + d), this.publicEventEmitter.emit(T.SERVER_WARNING, d);
|
|
2007
|
+
break;
|
|
2008
|
+
case F.TALK_STREAM_INTERRUPTED:
|
|
2009
|
+
const a = i.payload;
|
|
2010
|
+
this.publicEventEmitter.emit(T.TALK_STREAM_INTERRUPTED, a.correlationId);
|
|
2011
|
+
break;
|
|
2012
|
+
case F.SESSION_READY:
|
|
2013
|
+
const S = i.sessionId;
|
|
2014
|
+
this.publicEventEmitter.emit(T.SESSION_READY, S);
|
|
2015
|
+
break;
|
|
2016
|
+
case F.HEARTBEAT:
|
|
2017
|
+
break;
|
|
2018
|
+
default:
|
|
2019
|
+
console.warn("StreamingClient - onSignalMessage: unknown signal message action type. Is your anam-sdk version up to date?", i);
|
|
2020
|
+
}
|
|
2021
|
+
});
|
|
2022
|
+
}
|
|
2023
|
+
onSignallingClientConnected() {
|
|
2024
|
+
return $(this, void 0, void 0, function* () {
|
|
2025
|
+
if (!this.peerConnection)
|
|
2026
|
+
try {
|
|
2027
|
+
yield this.initPeerConnectionAndSendOffer();
|
|
2028
|
+
} catch (i) {
|
|
2029
|
+
console.error("StreamingClient - onSignallingClientConnected: Error initializing peer connection", i), this.handleWebrtcFailure(i);
|
|
2030
|
+
}
|
|
2031
|
+
});
|
|
2032
|
+
}
|
|
2033
|
+
flushRemoteIceCandidateBuffer() {
|
|
2034
|
+
this.remoteIceCandidateBuffer.forEach((i) => {
|
|
2035
|
+
var s;
|
|
2036
|
+
(s = this.peerConnection) === null || s === void 0 || s.addIceCandidate(i);
|
|
2037
|
+
}), this.remoteIceCandidateBuffer = [];
|
|
2038
|
+
}
|
|
2039
|
+
/**
|
|
2040
|
+
* ICE Candidate Trickle
|
|
2041
|
+
* As each ICE candidate is gathered from the STUN server it is sent to the
|
|
2042
|
+
* webRTC server immediately in an effort to reduce time to connection.
|
|
2043
|
+
*/
|
|
2044
|
+
onIceCandidate(i) {
|
|
2045
|
+
i.candidate && this.signallingClient.sendIceCandidate(i.candidate);
|
|
2046
|
+
}
|
|
2047
|
+
onIceConnectionStateChange() {
|
|
2048
|
+
var i, s;
|
|
2049
|
+
(((i = this.peerConnection) === null || i === void 0 ? void 0 : i.iceConnectionState) === "connected" || ((s = this.peerConnection) === null || s === void 0 ? void 0 : s.iceConnectionState) === "completed") && (this.publicEventEmitter.emit(T.CONNECTION_ESTABLISHED), this.startStatsCollection());
|
|
2050
|
+
}
|
|
2051
|
+
onConnectionStateChange() {
|
|
2052
|
+
var i;
|
|
2053
|
+
((i = this.peerConnection) === null || i === void 0 ? void 0 : i.connectionState) === "closed" && (console.error("StreamingClient - onConnectionStateChange: Connection closed"), this.handleWebrtcFailure("The connection to our servers was lost. Please try again."));
|
|
2054
|
+
}
|
|
2055
|
+
handleWebrtcFailure(i) {
|
|
2056
|
+
console.error({ message: "StreamingClient - handleWebrtcFailure: ", err: i }), i.name === "NotAllowedError" && i.message === "Permission denied" ? this.publicEventEmitter.emit(T.CONNECTION_CLOSED, Y.MICROPHONE_PERMISSION_DENIED) : this.publicEventEmitter.emit(T.CONNECTION_CLOSED, Y.WEBRTC_FAILURE);
|
|
2057
|
+
try {
|
|
2058
|
+
this.stopConnection();
|
|
2059
|
+
} catch (s) {
|
|
2060
|
+
console.error("StreamingClient - handleWebrtcFailure: error stopping connection", s);
|
|
2061
|
+
}
|
|
2062
|
+
}
|
|
2063
|
+
onTrackEventHandler(i) {
|
|
2064
|
+
if (i.track.kind === "video") {
|
|
2065
|
+
if (this.startSuccessMetricPolling(), this.videoStream = i.streams[0], this.publicEventEmitter.emit(T.VIDEO_STREAM_STARTED, this.videoStream), this.videoElement) {
|
|
2066
|
+
this.videoElement.srcObject = this.videoStream;
|
|
2067
|
+
const s = this.videoElement.requestVideoFrameCallback(() => {
|
|
2068
|
+
var o;
|
|
2069
|
+
(o = this.videoElement) === null || o === void 0 || o.cancelVideoFrameCallback(s), this.publicEventEmitter.emit(T.VIDEO_PLAY_STARTED), this.successMetricFired || (this.successMetricFired = !0, X(j.CLIENT_METRIC_MEASUREMENT_SESSION_SUCCESS, "1", { detectionMethod: "videoElement" }));
|
|
2070
|
+
});
|
|
2071
|
+
}
|
|
2072
|
+
} else i.track.kind === "audio" && (this.audioStream = i.streams[0], this.publicEventEmitter.emit(T.AUDIO_STREAM_STARTED, this.audioStream));
|
|
2073
|
+
}
|
|
2074
|
+
/**
|
|
2075
|
+
* Set up the data channels for sending and receiving messages
|
|
2076
|
+
*/
|
|
2077
|
+
setupDataChannels() {
|
|
2078
|
+
return $(this, void 0, void 0, function* () {
|
|
2079
|
+
if (!this.peerConnection) {
|
|
2080
|
+
console.error("StreamingClient - setupDataChannels: peer connection is not initialized");
|
|
2081
|
+
return;
|
|
2082
|
+
}
|
|
2083
|
+
if (!this.disableInputAudio && this.inputAudioStream && !this.inputAudioStream.getAudioTracks().length)
|
|
2084
|
+
throw new Error("StreamingClient - setupDataChannels: user provided stream does not have audio tracks");
|
|
2085
|
+
const i = this.peerConnection.createDataChannel("session", {
|
|
2086
|
+
ordered: !0
|
|
2087
|
+
});
|
|
2088
|
+
i.onopen = () => {
|
|
2089
|
+
this.dataChannel = i ?? null;
|
|
2090
|
+
}, i.onclose = () => {
|
|
2091
|
+
}, i.onmessage = (s) => {
|
|
2092
|
+
try {
|
|
2093
|
+
const o = JSON.parse(s.data);
|
|
2094
|
+
switch (o.messageType) {
|
|
2095
|
+
case ue.SPEECH_TEXT:
|
|
2096
|
+
this.internalEventEmitter.emit(V.WEBRTC_CHAT_MESSAGE_RECEIVED, o.data);
|
|
2097
|
+
break;
|
|
2098
|
+
case ue.CLIENT_TOOL_EVENT:
|
|
2099
|
+
const f = o.data;
|
|
2100
|
+
this.internalEventEmitter.emit(V.WEBRTC_CLIENT_TOOL_EVENT_RECEIVED, f);
|
|
2101
|
+
const E = vt.WebRTCClientToolEventToClientToolEvent(f);
|
|
2102
|
+
this.publicEventEmitter.emit(T.CLIENT_TOOL_EVENT_RECEIVED, E);
|
|
2103
|
+
break;
|
|
2104
|
+
// Unknown message types are silently ignored to maintain forward compatibility
|
|
2105
|
+
default:
|
|
2106
|
+
break;
|
|
2107
|
+
}
|
|
2108
|
+
} catch (o) {
|
|
2109
|
+
console.error("Failed to parse data channel message:", o);
|
|
2110
|
+
}
|
|
2111
|
+
};
|
|
2112
|
+
});
|
|
2113
|
+
}
|
|
2114
|
+
/**
|
|
2115
|
+
* Request microphone permission asynchronously without blocking connection
|
|
2116
|
+
*/
|
|
2117
|
+
requestMicrophonePermissionAsync() {
|
|
2118
|
+
return $(this, void 0, void 0, function* () {
|
|
2119
|
+
if (this.inputAudioState.permissionState !== z.PENDING) {
|
|
2120
|
+
this.inputAudioState = Object.assign(Object.assign({}, this.inputAudioState), { permissionState: z.PENDING }), this.publicEventEmitter.emit(T.MIC_PERMISSION_PENDING);
|
|
2121
|
+
try {
|
|
2122
|
+
const i = {
|
|
2123
|
+
echoCancellation: !0
|
|
2124
|
+
};
|
|
2125
|
+
this.audioDeviceId && (i.deviceId = {
|
|
2126
|
+
exact: this.audioDeviceId
|
|
2127
|
+
}), this.inputAudioStream = yield navigator.mediaDevices.getUserMedia({
|
|
2128
|
+
audio: i
|
|
2129
|
+
}), this.inputAudioState = Object.assign(Object.assign({}, this.inputAudioState), { permissionState: z.GRANTED }), this.publicEventEmitter.emit(T.MIC_PERMISSION_GRANTED), yield this.setupAudioTrack();
|
|
2130
|
+
} catch (i) {
|
|
2131
|
+
console.error("Failed to get microphone permission:", i), this.inputAudioState = Object.assign(Object.assign({}, this.inputAudioState), { permissionState: z.DENIED });
|
|
2132
|
+
const s = i instanceof Error ? i.message : String(i);
|
|
2133
|
+
this.publicEventEmitter.emit(T.MIC_PERMISSION_DENIED, s);
|
|
2134
|
+
}
|
|
2135
|
+
}
|
|
2136
|
+
});
|
|
2137
|
+
}
|
|
2138
|
+
/**
|
|
2139
|
+
* Set up audio track and add it to the peer connection using replaceTrack
|
|
2140
|
+
*/
|
|
2141
|
+
setupAudioTrack() {
|
|
2142
|
+
return $(this, void 0, void 0, function* () {
|
|
2143
|
+
if (!this.peerConnection || !this.inputAudioStream)
|
|
2144
|
+
return;
|
|
2145
|
+
if (!this.inputAudioStream.getAudioTracks().length) {
|
|
2146
|
+
console.error("StreamingClient - setupAudioTrack: stream does not have audio tracks");
|
|
2147
|
+
return;
|
|
2148
|
+
}
|
|
2149
|
+
this.inputAudioState.isMuted && this.muteAllAudioTracks();
|
|
2150
|
+
const i = this.inputAudioStream.getAudioTracks()[0], o = this.peerConnection.getSenders().find((f) => {
|
|
2151
|
+
var E;
|
|
2152
|
+
return ((E = f.track) === null || E === void 0 ? void 0 : E.kind) === "audio" || f.track === null && f.dtmf !== null;
|
|
2153
|
+
});
|
|
2154
|
+
if (o)
|
|
2155
|
+
try {
|
|
2156
|
+
yield o.replaceTrack(i);
|
|
2157
|
+
} catch (f) {
|
|
2158
|
+
console.error("Failed to replace audio track:", f), this.peerConnection.addTrack(i, this.inputAudioStream);
|
|
2159
|
+
}
|
|
2160
|
+
else
|
|
2161
|
+
this.peerConnection.addTrack(i, this.inputAudioStream);
|
|
2162
|
+
this.publicEventEmitter.emit(T.INPUT_AUDIO_STREAM_STARTED, this.inputAudioStream);
|
|
2163
|
+
});
|
|
2164
|
+
}
|
|
2165
|
+
initPeerConnectionAndSendOffer() {
|
|
2166
|
+
return $(this, void 0, void 0, function* () {
|
|
2167
|
+
if (yield this.initPeerConnection(), !this.peerConnection) {
|
|
2168
|
+
console.error("StreamingClient - initPeerConnectionAndSendOffer: peer connection is not initialized");
|
|
2169
|
+
return;
|
|
2170
|
+
}
|
|
2171
|
+
try {
|
|
2172
|
+
const i = yield this.peerConnection.createOffer();
|
|
2173
|
+
yield this.peerConnection.setLocalDescription(i);
|
|
2174
|
+
} catch (i) {
|
|
2175
|
+
console.error("StreamingClient - initPeerConnectionAndSendOffer: error creating offer", i);
|
|
2176
|
+
}
|
|
2177
|
+
if (!this.peerConnection.localDescription)
|
|
2178
|
+
throw new Error("StreamingClient - initPeerConnectionAndSendOffer: local description is null");
|
|
2179
|
+
yield this.signallingClient.sendOffer(this.peerConnection.localDescription);
|
|
2180
|
+
});
|
|
2181
|
+
}
|
|
2182
|
+
shutdown() {
|
|
2183
|
+
return $(this, void 0, void 0, function* () {
|
|
2184
|
+
var i;
|
|
2185
|
+
if (this.showPeerConnectionStatsReport) {
|
|
2186
|
+
const s = yield (i = this.peerConnection) === null || i === void 0 ? void 0 : i.getStats();
|
|
2187
|
+
if (s) {
|
|
2188
|
+
const o = lt(s, this.peerConnectionStatsReportOutputFormat);
|
|
2189
|
+
o && console.log(o, void 0, 2);
|
|
2190
|
+
}
|
|
2191
|
+
}
|
|
2192
|
+
this.statsCollectionInterval && (clearInterval(this.statsCollectionInterval), this.statsCollectionInterval = null), this.successMetricPoller && (clearInterval(this.successMetricPoller), this.successMetricPoller = null), this.successMetricFired = !1;
|
|
2193
|
+
try {
|
|
2194
|
+
this.inputAudioStream && this.inputAudioStream.getTracks().forEach((s) => {
|
|
2195
|
+
s.stop();
|
|
2196
|
+
}), this.inputAudioStream = null;
|
|
2197
|
+
} catch (s) {
|
|
2198
|
+
console.error("StreamingClient - shutdown: error stopping input audio stream", s);
|
|
2199
|
+
}
|
|
2200
|
+
try {
|
|
2201
|
+
this.signallingClient.stop();
|
|
2202
|
+
} catch (s) {
|
|
2203
|
+
console.error("StreamingClient - shutdown: error stopping signallilng", s);
|
|
2204
|
+
}
|
|
2205
|
+
try {
|
|
2206
|
+
this.peerConnection && this.peerConnection.connectionState !== "closed" && (this.peerConnection.onconnectionstatechange = null, this.peerConnection.close(), this.peerConnection = null);
|
|
2207
|
+
} catch (s) {
|
|
2208
|
+
console.error("StreamingClient - shutdown: error closing peer connection", s);
|
|
2209
|
+
}
|
|
2210
|
+
});
|
|
2211
|
+
}
|
|
2212
|
+
}
|
|
2213
|
+
class vt {
|
|
2214
|
+
/**
|
|
2215
|
+
* Converts a WebRtcClientToolEvent to a ClientToolEvent
|
|
2216
|
+
*/
|
|
2217
|
+
static WebRTCClientToolEventToClientToolEvent(i) {
|
|
2218
|
+
return {
|
|
2219
|
+
eventUid: i.event_uid,
|
|
2220
|
+
sessionId: i.session_id,
|
|
2221
|
+
eventName: i.event_name,
|
|
2222
|
+
eventData: i.event_data,
|
|
2223
|
+
timestamp: i.timestamp,
|
|
2224
|
+
timestampUserAction: i.timestamp_user_action,
|
|
2225
|
+
userActionCorrelationId: i.user_action_correlation_id
|
|
2226
|
+
};
|
|
2227
|
+
}
|
|
2228
|
+
}
|
|
2229
|
+
var q = function(l, i, s, o) {
|
|
2230
|
+
function f(E) {
|
|
2231
|
+
return E instanceof s ? E : new s(function(d) {
|
|
2232
|
+
d(E);
|
|
2233
|
+
});
|
|
2234
|
+
}
|
|
2235
|
+
return new (s || (s = Promise))(function(E, d) {
|
|
2236
|
+
function a(m) {
|
|
2237
|
+
try {
|
|
2238
|
+
g(o.next(m));
|
|
2239
|
+
} catch (u) {
|
|
2240
|
+
d(u);
|
|
2241
|
+
}
|
|
2242
|
+
}
|
|
2243
|
+
function S(m) {
|
|
2244
|
+
try {
|
|
2245
|
+
g(o.throw(m));
|
|
2246
|
+
} catch (u) {
|
|
2247
|
+
d(u);
|
|
2248
|
+
}
|
|
2249
|
+
}
|
|
2250
|
+
function g(m) {
|
|
2251
|
+
m.done ? E(m.value) : f(m.value).then(a, S);
|
|
2252
|
+
}
|
|
2253
|
+
g((o = o.apply(l, i || [])).next());
|
|
2254
|
+
});
|
|
2255
|
+
};
|
|
2256
|
+
class Ot {
|
|
2257
|
+
constructor(i, s, o) {
|
|
2258
|
+
var f, E, d, a, S;
|
|
2259
|
+
this.inputAudioState = {
|
|
2260
|
+
isMuted: !1,
|
|
2261
|
+
permissionState: z.NOT_REQUESTED
|
|
2262
|
+
}, this.sessionId = null, this.organizationId = null, this.streamingClient = null, this._isStreaming = !1;
|
|
2263
|
+
const g = this.validateClientConfig(i, s, o);
|
|
2264
|
+
if (g)
|
|
2265
|
+
throw new x(g, M.CLIENT_ERROR_CODE_CONFIGURATION_ERROR, 400);
|
|
2266
|
+
this.personaConfig = s, this.clientOptions = o, (!((f = o?.api) === null || f === void 0) && f.baseUrl || !((E = o?.api) === null || E === void 0) && E.apiVersion) && at(o.api.baseUrl || Me, o.api.apiVersion || ge), !((a = (d = o?.api) === null || d === void 0 ? void 0 : d.apiGateway) === null || a === void 0) && a.enabled && ct(o.api.apiGateway), !((S = o?.metrics) === null || S === void 0) && S.disableClientMetrics && ut(!0), this.publicEventEmitter = new At(), this.internalEventEmitter = new Ct(), this.apiClient = new It(i, o?.apiKey, o?.api), this.messageHistoryClient = new _t(this.publicEventEmitter, this.internalEventEmitter);
|
|
2267
|
+
}
|
|
2268
|
+
decodeJwt(i) {
|
|
2269
|
+
try {
|
|
2270
|
+
const s = i.split(".")[1], o = nt.Buffer.from(s, "base64").toString("utf8");
|
|
2271
|
+
return JSON.parse(o);
|
|
2272
|
+
} catch {
|
|
2273
|
+
throw new Error("Invalid session token format");
|
|
2274
|
+
}
|
|
2275
|
+
}
|
|
2276
|
+
validateClientConfig(i, s, o) {
|
|
2277
|
+
var f, E;
|
|
2278
|
+
if (!i && !o?.apiKey)
|
|
2279
|
+
return "Either sessionToken or apiKey must be provided";
|
|
2280
|
+
if (o?.apiKey && i)
|
|
2281
|
+
return "Only one of sessionToken or apiKey should be used";
|
|
2282
|
+
const d = dt((f = o?.api) === null || f === void 0 ? void 0 : f.apiGateway);
|
|
2283
|
+
if (d)
|
|
2284
|
+
return d;
|
|
2285
|
+
if (i) {
|
|
2286
|
+
const a = this.decodeJwt(i);
|
|
2287
|
+
this.organizationId = a.accountId, ee({
|
|
2288
|
+
organizationId: this.organizationId
|
|
2289
|
+
});
|
|
2290
|
+
const S = (E = a.type) === null || E === void 0 ? void 0 : E.toLowerCase();
|
|
2291
|
+
if (S === "legacy")
|
|
2292
|
+
return "Legacy session tokens are no longer supported. Please define your persona when creating your session token. See https://docs.anam.ai/resources/migrating-legacy for more information.";
|
|
2293
|
+
if ((S === "ephemeral" || S === "stateful") && s)
|
|
2294
|
+
return "This session token already contains a persona configuration. Please remove the personaConfig parameter.";
|
|
2295
|
+
} else if (!s)
|
|
2296
|
+
return "Missing persona config. Persona configuration must be provided when using apiKey";
|
|
2297
|
+
if (o?.voiceDetection) {
|
|
2298
|
+
if (o.disableInputAudio)
|
|
2299
|
+
return "Voice detection is disabled because input audio is disabled. Please set disableInputAudio to false to enable voice detection.";
|
|
2300
|
+
if (o.voiceDetection.endOfSpeechSensitivity !== void 0) {
|
|
2301
|
+
if (typeof o.voiceDetection.endOfSpeechSensitivity != "number")
|
|
2302
|
+
return "End of speech sensitivity must be a number";
|
|
2303
|
+
if (o.voiceDetection.endOfSpeechSensitivity < 0 || o.voiceDetection.endOfSpeechSensitivity > 1)
|
|
2304
|
+
return "End of speech sensitivity must be between 0 and 1";
|
|
2305
|
+
}
|
|
2306
|
+
}
|
|
2307
|
+
}
|
|
2308
|
+
buildStartSessionOptionsForClient() {
|
|
2309
|
+
var i;
|
|
2310
|
+
const s = {};
|
|
2311
|
+
if (!((i = this.clientOptions) === null || i === void 0) && i.voiceDetection && (s.voiceDetection = this.clientOptions.voiceDetection), Object.keys(s).length !== 0)
|
|
2312
|
+
return s;
|
|
2313
|
+
}
|
|
2314
|
+
startSession(i) {
|
|
2315
|
+
return q(this, void 0, void 0, function* () {
|
|
2316
|
+
var s, o, f, E, d, a, S, g, m, u, R, I;
|
|
2317
|
+
const C = this.personaConfig, _ = this.buildStartSessionOptionsForClient(), w = yield this.apiClient.startSession(C, _), { sessionId: N, clientConfig: O, engineHost: B, engineProtocol: k, signallingEndpoint: b } = w, { heartbeatIntervalSeconds: se, maxWsReconnectionAttempts: oe, iceServers: de } = O;
|
|
2318
|
+
this.sessionId = N, ee({
|
|
2319
|
+
sessionId: this.sessionId
|
|
2320
|
+
});
|
|
2321
|
+
const he = !((s = this.clientOptions) === null || s === void 0) && s.iceServers ? this.clientOptions.iceServers : de;
|
|
2322
|
+
try {
|
|
2323
|
+
this.streamingClient = new Nt(N, {
|
|
2324
|
+
engine: {
|
|
2325
|
+
baseUrl: `${k}://${B}`
|
|
2326
|
+
},
|
|
2327
|
+
signalling: {
|
|
2328
|
+
heartbeatIntervalSeconds: se,
|
|
2329
|
+
maxWsReconnectionAttempts: oe,
|
|
2330
|
+
url: {
|
|
2331
|
+
baseUrl: B,
|
|
2332
|
+
protocol: k,
|
|
2333
|
+
signallingPath: b
|
|
2334
|
+
}
|
|
2335
|
+
},
|
|
2336
|
+
iceServers: he,
|
|
2337
|
+
inputAudio: {
|
|
2338
|
+
inputAudioState: this.inputAudioState,
|
|
2339
|
+
userProvidedMediaStream: !((o = this.clientOptions) === null || o === void 0) && o.disableInputAudio ? void 0 : i,
|
|
2340
|
+
audioDeviceId: (f = this.clientOptions) === null || f === void 0 ? void 0 : f.audioDeviceId,
|
|
2341
|
+
disableInputAudio: (E = this.clientOptions) === null || E === void 0 ? void 0 : E.disableInputAudio
|
|
2342
|
+
},
|
|
2343
|
+
apiGateway: (a = (d = this.clientOptions) === null || d === void 0 ? void 0 : d.api) === null || a === void 0 ? void 0 : a.apiGateway,
|
|
2344
|
+
metrics: {
|
|
2345
|
+
showPeerConnectionStatsReport: (m = (g = (S = this.clientOptions) === null || S === void 0 ? void 0 : S.metrics) === null || g === void 0 ? void 0 : g.showPeerConnectionStatsReport) !== null && m !== void 0 ? m : !1,
|
|
2346
|
+
peerConnectionStatsReportOutputFormat: (I = (R = (u = this.clientOptions) === null || u === void 0 ? void 0 : u.metrics) === null || R === void 0 ? void 0 : R.peerConnectionStatsReportOutputFormat) !== null && I !== void 0 ? I : "console"
|
|
2347
|
+
}
|
|
2348
|
+
}, this.publicEventEmitter, this.internalEventEmitter);
|
|
2349
|
+
} catch (ie) {
|
|
2350
|
+
throw ee({
|
|
2351
|
+
sessionId: null
|
|
2352
|
+
}), new x("Failed to initialize streaming client", M.CLIENT_ERROR_CODE_SERVER_ERROR, 500, {
|
|
2353
|
+
cause: ie instanceof Error ? ie.message : String(ie),
|
|
2354
|
+
sessionId: N
|
|
2355
|
+
});
|
|
2356
|
+
}
|
|
2357
|
+
return N;
|
|
2358
|
+
});
|
|
2359
|
+
}
|
|
2360
|
+
startSessionIfNeeded(i) {
|
|
2361
|
+
return q(this, void 0, void 0, function* () {
|
|
2362
|
+
if ((!this.sessionId || !this.streamingClient) && (yield this.startSession(i), !this.sessionId || !this.streamingClient))
|
|
2363
|
+
throw new x("Session ID or streaming client is not available after starting session", M.CLIENT_ERROR_CODE_SERVER_ERROR, 500, {
|
|
2364
|
+
cause: "Failed to initialize session properly"
|
|
2365
|
+
});
|
|
2366
|
+
});
|
|
2367
|
+
}
|
|
2368
|
+
stream(i) {
|
|
2369
|
+
return q(this, void 0, void 0, function* () {
|
|
2370
|
+
var s;
|
|
2371
|
+
if (this._isStreaming)
|
|
2372
|
+
throw new Error("Already streaming");
|
|
2373
|
+
const o = Be();
|
|
2374
|
+
return ee({
|
|
2375
|
+
attemptCorrelationId: o,
|
|
2376
|
+
sessionId: null
|
|
2377
|
+
// reset sessionId
|
|
2378
|
+
}), X(j.CLIENT_METRIC_MEASUREMENT_SESSION_ATTEMPT, "1"), !((s = this.clientOptions) === null || s === void 0) && s.disableInputAudio && i && console.warn("AnamClient:Input audio is disabled. User provided audio stream will be ignored."), yield this.startSessionIfNeeded(i), this._isStreaming = !0, new Promise((f) => {
|
|
2379
|
+
var E;
|
|
2380
|
+
const d = [];
|
|
2381
|
+
let a = !1, S = !1;
|
|
2382
|
+
this.publicEventEmitter.addListener(T.VIDEO_STREAM_STARTED, (g) => {
|
|
2383
|
+
d.push(g), a = !0, S && f(d);
|
|
2384
|
+
}), this.publicEventEmitter.addListener(T.AUDIO_STREAM_STARTED, (g) => {
|
|
2385
|
+
d.push(g), S = !0, a && f(d);
|
|
2386
|
+
}), (E = this.streamingClient) === null || E === void 0 || E.startConnection();
|
|
2387
|
+
});
|
|
2388
|
+
});
|
|
2389
|
+
}
|
|
2390
|
+
/**
|
|
2391
|
+
* @deprecated This method is deprecated. Please use streamToVideoElement instead.
|
|
2392
|
+
*/
|
|
2393
|
+
streamToVideoAndAudioElements(i, s, o) {
|
|
2394
|
+
return q(this, void 0, void 0, function* () {
|
|
2395
|
+
console.warn("AnamClient: streamToVideoAndAudioElements is deprecated. To avoid possible audio issues, please use streamToVideoElement instead."), yield this.streamToVideoElement(i, o);
|
|
2396
|
+
});
|
|
2397
|
+
}
|
|
2398
|
+
streamToVideoElement(i, s) {
|
|
2399
|
+
return q(this, void 0, void 0, function* () {
|
|
2400
|
+
var o;
|
|
2401
|
+
const f = Be();
|
|
2402
|
+
ee({
|
|
2403
|
+
attemptCorrelationId: f,
|
|
2404
|
+
sessionId: null
|
|
2405
|
+
// reset sessionId
|
|
2406
|
+
}), X(j.CLIENT_METRIC_MEASUREMENT_SESSION_ATTEMPT, "1"), !((o = this.clientOptions) === null || o === void 0) && o.disableInputAudio && s && console.warn("AnamClient:Input audio is disabled. User provided audio stream will be ignored.");
|
|
2407
|
+
try {
|
|
2408
|
+
yield this.startSessionIfNeeded(s);
|
|
2409
|
+
} catch (E) {
|
|
2410
|
+
throw E instanceof x ? E : new x("Failed to start session", M.CLIENT_ERROR_CODE_SERVER_ERROR, 500, {
|
|
2411
|
+
cause: E instanceof Error ? E.message : String(E),
|
|
2412
|
+
sessionId: this.sessionId
|
|
2413
|
+
});
|
|
2414
|
+
}
|
|
2415
|
+
if (this._isStreaming)
|
|
2416
|
+
throw new Error("Already streaming");
|
|
2417
|
+
if (this._isStreaming = !0, !this.streamingClient)
|
|
2418
|
+
throw new Error("Failed to stream: streaming client is not available");
|
|
2419
|
+
this.streamingClient.setMediaStreamTargetById(i), this.streamingClient.startConnection();
|
|
2420
|
+
});
|
|
2421
|
+
}
|
|
2422
|
+
/**
|
|
2423
|
+
* Send a talk command to make the persona speak the provided content.
|
|
2424
|
+
* @param content - The text content for the persona to speak
|
|
2425
|
+
* @throws Error if session is not started or not currently streaming
|
|
2426
|
+
*/
|
|
2427
|
+
talk(i) {
|
|
2428
|
+
return q(this, void 0, void 0, function* () {
|
|
2429
|
+
if (!this.streamingClient)
|
|
2430
|
+
throw new Error("Failed to send talk command: session is not started. Have you called startSession?");
|
|
2431
|
+
if (!this._isStreaming)
|
|
2432
|
+
throw new Error("Failed to send talk command: not currently streaming. Have you called stream?");
|
|
2433
|
+
yield this.streamingClient.sendTalkCommand(i);
|
|
2434
|
+
});
|
|
2435
|
+
}
|
|
2436
|
+
/**
|
|
2437
|
+
* Send a raw data message through the WebRTC data channel.
|
|
2438
|
+
* @param message - The message string to send through the data channel
|
|
2439
|
+
* @throws Error if session is not started
|
|
2440
|
+
*/
|
|
2441
|
+
sendDataMessage(i) {
|
|
2442
|
+
if (this.streamingClient)
|
|
2443
|
+
this.streamingClient.sendDataMessage(i);
|
|
2444
|
+
else
|
|
2445
|
+
throw new Error("Failed to send message: session is not started.");
|
|
2446
|
+
}
|
|
2447
|
+
/**
|
|
2448
|
+
* Send a user text message in the active streaming session.
|
|
2449
|
+
* @param content - The text message content to send
|
|
2450
|
+
* @throws Error if not currently streaming or session is not started
|
|
2451
|
+
*/
|
|
2452
|
+
sendUserMessage(i) {
|
|
2453
|
+
if (!this._isStreaming)
|
|
2454
|
+
throw console.warn("AnamClient: Not currently streaming. User message will not be sent."), new Error("Failed to send user message: not currently streaming");
|
|
2455
|
+
const s = this.getActiveSessionId();
|
|
2456
|
+
if (!s)
|
|
2457
|
+
throw new Error("Failed to send user message: no active session");
|
|
2458
|
+
const o = (/* @__PURE__ */ new Date()).toISOString().replace("Z", ""), f = JSON.stringify({
|
|
2459
|
+
content: i,
|
|
2460
|
+
timestamp: o,
|
|
2461
|
+
session_id: s,
|
|
2462
|
+
message_type: "speech"
|
|
2463
|
+
});
|
|
2464
|
+
this.sendDataMessage(f);
|
|
2465
|
+
}
|
|
2466
|
+
interruptPersona() {
|
|
2467
|
+
if (!this._isStreaming)
|
|
2468
|
+
throw new Error("Failed to send interrupt command: not currently streaming");
|
|
2469
|
+
const i = this.getActiveSessionId();
|
|
2470
|
+
if (!i)
|
|
2471
|
+
throw new Error("Failed to send interrupt command: no active session");
|
|
2472
|
+
const s = JSON.stringify({
|
|
2473
|
+
message_type: "interrupt",
|
|
2474
|
+
session_id: i,
|
|
2475
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
2476
|
+
// removing Z not needed
|
|
2477
|
+
});
|
|
2478
|
+
this.sendDataMessage(s);
|
|
2479
|
+
}
|
|
2480
|
+
stopStreaming() {
|
|
2481
|
+
return q(this, void 0, void 0, function* () {
|
|
2482
|
+
this.streamingClient && (this.publicEventEmitter.emit(T.CONNECTION_CLOSED, Y.NORMAL), yield this.streamingClient.stopConnection(), this.streamingClient = null, this.sessionId = null, ee({
|
|
2483
|
+
attemptCorrelationId: null,
|
|
2484
|
+
sessionId: null,
|
|
2485
|
+
organizationId: this.organizationId
|
|
2486
|
+
}), this._isStreaming = !1);
|
|
2487
|
+
});
|
|
2488
|
+
}
|
|
2489
|
+
isStreaming() {
|
|
2490
|
+
return this._isStreaming;
|
|
2491
|
+
}
|
|
2492
|
+
setPersonaConfig(i) {
|
|
2493
|
+
this.personaConfig = i;
|
|
2494
|
+
}
|
|
2495
|
+
getPersonaConfig() {
|
|
2496
|
+
return this.personaConfig;
|
|
2497
|
+
}
|
|
2498
|
+
getInputAudioState() {
|
|
2499
|
+
var i;
|
|
2500
|
+
return !((i = this.clientOptions) === null || i === void 0) && i.disableInputAudio && console.warn("AnamClient: Audio state will not be used because input audio is disabled."), this.streamingClient && (this.inputAudioState = this.streamingClient.getInputAudioState()), this.inputAudioState;
|
|
2501
|
+
}
|
|
2502
|
+
muteInputAudio() {
|
|
2503
|
+
var i, s;
|
|
2504
|
+
return !((i = this.clientOptions) === null || i === void 0) && i.disableInputAudio && console.warn("AnamClient: Input audio is disabled. Muting input audio will have no effect."), this.streamingClient && !(!((s = this.clientOptions) === null || s === void 0) && s.disableInputAudio) ? this.inputAudioState = this.streamingClient.muteInputAudio() : this.inputAudioState = Object.assign(Object.assign({}, this.inputAudioState), { isMuted: !0 }), this.inputAudioState;
|
|
2505
|
+
}
|
|
2506
|
+
unmuteInputAudio() {
|
|
2507
|
+
var i, s;
|
|
2508
|
+
return !((i = this.clientOptions) === null || i === void 0) && i.disableInputAudio && console.warn("AnamClient: Input audio is disabled. Unmuting input audio will have no effect."), this.streamingClient && !(!((s = this.clientOptions) === null || s === void 0) && s.disableInputAudio) ? this.inputAudioState = this.streamingClient.unmuteInputAudio() : this.inputAudioState = Object.assign(Object.assign({}, this.inputAudioState), { isMuted: !1 }), this.inputAudioState;
|
|
2509
|
+
}
|
|
2510
|
+
changeAudioInputDevice(i) {
|
|
2511
|
+
return q(this, void 0, void 0, function* () {
|
|
2512
|
+
var s;
|
|
2513
|
+
if (!((s = this.clientOptions) === null || s === void 0) && s.disableInputAudio)
|
|
2514
|
+
throw new Error("AnamClient: Cannot change audio input device because input audio is disabled.");
|
|
2515
|
+
if (!this._isStreaming)
|
|
2516
|
+
throw new Error("AnamClient: Cannot change audio input device while not streaming. Start streaming first.");
|
|
2517
|
+
if (!this.streamingClient)
|
|
2518
|
+
throw new Error("AnamClient: Cannot change audio input device because streaming client is not available. Start streaming first.");
|
|
2519
|
+
yield this.streamingClient.changeAudioInputDevice(i);
|
|
2520
|
+
});
|
|
2521
|
+
}
|
|
2522
|
+
createTalkMessageStream(i) {
|
|
2523
|
+
if (!this.streamingClient)
|
|
2524
|
+
throw new Error("Failed to start talk message stream: session is not started.");
|
|
2525
|
+
if (i && i.trim() === "")
|
|
2526
|
+
throw new Error("Failed to start talk message stream: correlationId is empty");
|
|
2527
|
+
return this.streamingClient.startTalkMessageStream(i);
|
|
2528
|
+
}
|
|
2529
|
+
createAgentAudioInputStream(i) {
|
|
2530
|
+
if (!this.streamingClient)
|
|
2531
|
+
throw new Error("Failed to create agent audio input stream: session is not started.");
|
|
2532
|
+
return this.streamingClient.createAgentAudioInputStream(i);
|
|
2533
|
+
}
|
|
2534
|
+
/**
|
|
2535
|
+
* Event handling
|
|
2536
|
+
*/
|
|
2537
|
+
addListener(i, s) {
|
|
2538
|
+
this.publicEventEmitter.addListener(i, s);
|
|
2539
|
+
}
|
|
2540
|
+
removeListener(i, s) {
|
|
2541
|
+
this.publicEventEmitter.removeListener(i, s);
|
|
2542
|
+
}
|
|
2543
|
+
getActiveSessionId() {
|
|
2544
|
+
return this.sessionId;
|
|
2545
|
+
}
|
|
2546
|
+
}
|
|
2547
|
+
const Dt = (l, i) => new Ot(l, void 0, i);
|
|
2548
|
+
export {
|
|
2549
|
+
ht as AgentAudioInputStream,
|
|
2550
|
+
T as AnamEvent,
|
|
2551
|
+
z as AudioPermissionState,
|
|
2552
|
+
x as ClientError,
|
|
2553
|
+
Y as ConnectionClosedCode,
|
|
2554
|
+
ue as DataChannelMessage,
|
|
2555
|
+
M as ErrorCode,
|
|
2556
|
+
V as InternalEvent,
|
|
2557
|
+
le as MessageRole,
|
|
2558
|
+
F as SignalMessageAction,
|
|
2559
|
+
Dt as createClient
|
|
2560
|
+
};
|
|
2561
|
+
//# sourceMappingURL=index-gxG0JnP5.js.map
|