@alfadocs/ui-kit 1.148.0 → 1.149.1

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.
Files changed (90) hide show
  1. package/dist/_chunks/{calendar-appointment-editor-dialog-Cz8F2H4M.js → calendar-appointment-editor-dialog-fQleWmJE.js} +5 -5
  2. package/dist/_chunks/{calendar-waiting-list-panel-C4T85b4q.js → calendar-waiting-list-panel-BKBHfBpn.js} +2 -2
  3. package/dist/_chunks/{calendar.sheets-DsgPdycU.js → calendar.sheets-lgAqJB34.js} +2 -2
  4. package/dist/_chunks/notes-panel-Cw06dLDm.js +1135 -0
  5. package/dist/_chunks/rich-text-editor-eGdYDPK2.js +4405 -0
  6. package/dist/_chunks/task-editor-C-4I2sBa.js +1162 -0
  7. package/dist/_chunks/{tasks-panel-DufAoAxG.js → tasks-panel-BDPQPOP6.js} +475 -461
  8. package/dist/_chunks/{use-appointment-details-read-kYp-gfhb.js → use-appointment-details-read-Bl1DHXQ2.js} +568 -554
  9. package/dist/agent-catalog.json +9 -7
  10. package/dist/agent-i18n/en.json +4 -4
  11. package/dist/appointment-editor-panel/index.js +1 -1
  12. package/dist/aws-transcribe/index.js +287 -181
  13. package/dist/browser-support.js +1 -1
  14. package/dist/components/_shared/save-outcome.d.ts +23 -0
  15. package/dist/components/appointment-details-panel/index.js +1 -1
  16. package/dist/components/index.d.ts +1 -0
  17. package/dist/components/notes-panel/index.js +1 -1
  18. package/dist/components/rich-text-editor/help-me-write-overlay.d.ts +12 -1
  19. package/dist/components/rich-text-editor/index.js +1 -1
  20. package/dist/components/rich-text-editor/rich-text-editor.d.ts +5 -3
  21. package/dist/components/task-editor/index.js +1 -1
  22. package/dist/components/task-editor/use-task-editor-form.d.ts +7 -1
  23. package/dist/components/tasks-panel/index.js +1 -1
  24. package/dist/core.css +1 -1
  25. package/dist/find-free-slots-panel/index.js +1 -1
  26. package/dist/i18n/locales/ar.d.ts +1 -0
  27. package/dist/i18n/locales/ar.js +2 -1
  28. package/dist/i18n/locales/de.d.ts +1 -0
  29. package/dist/i18n/locales/de.js +2 -1
  30. package/dist/i18n/locales/el.d.ts +1 -0
  31. package/dist/i18n/locales/el.js +2 -1
  32. package/dist/i18n/locales/en.d.ts +1 -0
  33. package/dist/i18n/locales/en.js +2 -1
  34. package/dist/i18n/locales/es.d.ts +1 -0
  35. package/dist/i18n/locales/es.js +2 -1
  36. package/dist/i18n/locales/fr.d.ts +1 -0
  37. package/dist/i18n/locales/fr.js +2 -1
  38. package/dist/i18n/locales/hi.d.ts +1 -0
  39. package/dist/i18n/locales/hi.js +2 -1
  40. package/dist/i18n/locales/it.d.ts +1 -0
  41. package/dist/i18n/locales/it.js +2 -1
  42. package/dist/i18n/locales/ja.d.ts +1 -0
  43. package/dist/i18n/locales/ja.js +2 -1
  44. package/dist/i18n/locales/nl.d.ts +1 -0
  45. package/dist/i18n/locales/nl.js +2 -1
  46. package/dist/i18n/locales/pl.d.ts +1 -0
  47. package/dist/i18n/locales/pl.js +2 -1
  48. package/dist/i18n/locales/pt.d.ts +1 -0
  49. package/dist/i18n/locales/pt.js +2 -1
  50. package/dist/i18n/locales/ro.d.ts +1 -0
  51. package/dist/i18n/locales/ro.js +2 -1
  52. package/dist/i18n/locales/ru.d.ts +1 -0
  53. package/dist/i18n/locales/ru.js +2 -1
  54. package/dist/i18n/locales/sq.d.ts +1 -0
  55. package/dist/i18n/locales/sq.js +2 -1
  56. package/dist/i18n/locales/sv.d.ts +1 -0
  57. package/dist/i18n/locales/sv.js +2 -1
  58. package/dist/i18n/locales/tr.d.ts +1 -0
  59. package/dist/i18n/locales/tr.js +2 -1
  60. package/dist/i18n/locales/zh.d.ts +1 -0
  61. package/dist/i18n/locales/zh.js +2 -1
  62. package/dist/index.js +1407 -1403
  63. package/dist/locales/ar.json +2 -1
  64. package/dist/locales/de.json +2 -1
  65. package/dist/locales/el.json +2 -1
  66. package/dist/locales/en.json +2 -1
  67. package/dist/locales/es.json +2 -1
  68. package/dist/locales/fr.json +2 -1
  69. package/dist/locales/hi.json +2 -1
  70. package/dist/locales/it.json +2 -1
  71. package/dist/locales/ja.json +2 -1
  72. package/dist/locales/nl.json +2 -1
  73. package/dist/locales/pl.json +2 -1
  74. package/dist/locales/pt.json +2 -1
  75. package/dist/locales/ro.json +2 -1
  76. package/dist/locales/ru.json +2 -1
  77. package/dist/locales/sq.json +2 -1
  78. package/dist/locales/sv.json +2 -1
  79. package/dist/locales/tr.json +2 -1
  80. package/dist/locales/zh.json +2 -1
  81. package/dist/online-bookings-panel/index.js +1 -1
  82. package/dist/patterns/calendar/index.js +2 -2
  83. package/dist/save-outcome/index.js +20 -0
  84. package/dist/speech/aws-transcribe.d.ts +30 -6
  85. package/dist/tokens.css +1 -1
  86. package/dist/waiting-list-panel/index.js +2 -2
  87. package/package.json +5 -1
  88. package/dist/_chunks/notes-panel-BHMnLbEH.js +0 -1116
  89. package/dist/_chunks/rich-text-editor-BAcJq1PO.js +0 -4359
  90. package/dist/_chunks/task-editor-B9YpfwcW.js +0 -1095
@@ -1,7 +1,7 @@
1
- var q = Object.defineProperty;
2
- var Q = (t, e, n) => e in t ? q(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
3
- var B = (t, e, n) => Q(t, typeof e != "symbol" ? e + "" : e, n);
4
- const Z = (() => {
1
+ var we = Object.defineProperty;
2
+ var ye = (t, e, n) => e in t ? we(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
3
+ var re = (t, e, n) => ye(t, typeof e != "symbol" ? e + "" : e, n);
4
+ const me = (() => {
5
5
  const t = new Uint32Array(256);
6
6
  for (let e = 0; e < 256; e++) {
7
7
  let n = e;
@@ -11,59 +11,59 @@ const Z = (() => {
11
11
  }
12
12
  return t;
13
13
  })();
14
- function x(t) {
14
+ function j(t) {
15
15
  let e = 4294967295;
16
16
  for (let n = 0; n < t.length; n++)
17
- e = (Z[(e ^ t[n]) & 255] ^ e >>> 8) >>> 0;
17
+ e = (me[(e ^ t[n]) & 255] ^ e >>> 8) >>> 0;
18
18
  return (e ^ 4294967295) >>> 0;
19
19
  }
20
- const V = 7, b = 12, I = new TextEncoder(), F = new TextDecoder();
21
- function ee(t) {
22
- const e = Object.entries(t).map(([s, c]) => {
23
- const o = I.encode(s), u = I.encode(c), l = new Uint8Array(
24
- 1 + o.length + 1 + 2 + u.length
25
- ), h = new DataView(l.buffer);
26
- let i = 0;
27
- return h.setUint8(i, o.length), i += 1, l.set(o, i), i += o.length, h.setUint8(i, V), i += 1, h.setUint16(i, u.length), i += 2, l.set(u, i), l;
28
- }), n = new Uint8Array(e.reduce((s, c) => s + c.length, 0));
20
+ const ue = 7, k = 12, oe = new TextEncoder(), se = new TextDecoder();
21
+ function ge(t) {
22
+ const e = Object.entries(t).map(([o, i]) => {
23
+ const s = oe.encode(o), a = oe.encode(i), l = new Uint8Array(
24
+ 1 + s.length + 1 + 2 + a.length
25
+ ), w = new DataView(l.buffer);
26
+ let d = 0;
27
+ return w.setUint8(d, s.length), d += 1, l.set(s, d), d += s.length, w.setUint8(d, ue), d += 1, w.setUint16(d, a.length), d += 2, l.set(a, d), l;
28
+ }), n = new Uint8Array(e.reduce((o, i) => o + i.length, 0));
29
29
  let r = 0;
30
- for (const s of e)
31
- n.set(s, r), r += s.length;
30
+ for (const o of e)
31
+ n.set(o, r), r += o.length;
32
32
  return n;
33
33
  }
34
- function te(t, e) {
35
- const n = ee(t), r = b + n.length + e.length + 4, s = new Uint8Array(r), c = new DataView(s.buffer);
36
- return c.setUint32(0, r), c.setUint32(4, n.length), c.setUint32(8, x(s.subarray(0, 8))), s.set(n, b), s.set(e, b + n.length), c.setUint32(r - 4, x(s.subarray(0, r - 4))), s;
34
+ function be(t, e) {
35
+ const n = ge(t), r = k + n.length + e.length + 4, o = new Uint8Array(r), i = new DataView(o.buffer);
36
+ return i.setUint32(0, r), i.setUint32(4, n.length), i.setUint32(8, j(o.subarray(0, 8))), o.set(n, k), o.set(e, k + n.length), i.setUint32(r - 4, j(o.subarray(0, r - 4))), o;
37
37
  }
38
- function ne(t) {
38
+ function Ee(t) {
39
39
  const e = new Uint8Array(t);
40
- if (e.length < b + 4)
40
+ if (e.length < k + 4)
41
41
  throw new Error("event-stream: frame too short");
42
- const n = new DataView(t), r = n.getUint32(0), s = n.getUint32(4);
43
- if (r !== e.length || b + s + 4 > r)
42
+ const n = new DataView(t), r = n.getUint32(0), o = n.getUint32(4);
43
+ if (r !== e.length || k + o + 4 > r)
44
44
  throw new Error("event-stream: lengths do not match the frame");
45
- if (n.getUint32(8) !== x(e.subarray(0, 8)))
45
+ if (n.getUint32(8) !== j(e.subarray(0, 8)))
46
46
  throw new Error("event-stream: prelude checksum mismatch");
47
- if (n.getUint32(r - 4) !== x(e.subarray(0, r - 4)))
47
+ if (n.getUint32(r - 4) !== j(e.subarray(0, r - 4)))
48
48
  throw new Error("event-stream: message checksum mismatch");
49
- const c = {};
50
- let o = b;
51
- const u = b + s;
52
- for (; o < u; ) {
53
- const l = n.getUint8(o);
54
- o += 1;
55
- const h = F.decode(e.subarray(o, o + l));
56
- if (o += l, n.getUint8(o) !== V) break;
57
- o += 1;
58
- const i = n.getUint16(o);
59
- o += 2, c[h] = F.decode(
60
- e.subarray(o, o + i)
61
- ), o += i;
49
+ const i = {};
50
+ let s = k;
51
+ const a = k + o;
52
+ for (; s < a; ) {
53
+ const l = n.getUint8(s);
54
+ s += 1;
55
+ const w = se.decode(e.subarray(s, s + l));
56
+ if (s += l, n.getUint8(s) !== ue) break;
57
+ s += 1;
58
+ const d = n.getUint16(s);
59
+ s += 2, i[w] = se.decode(
60
+ e.subarray(s, s + d)
61
+ ), s += d;
62
62
  }
63
- return { headers: c, payload: e.slice(u, r - 4) };
63
+ return { headers: i, payload: e.slice(a, r - 4) };
64
64
  }
65
- function z(t) {
66
- return te(
65
+ function ce(t) {
66
+ return be(
67
67
  {
68
68
  ":content-type": "application/octet-stream",
69
69
  ":event-type": "AudioEvent",
@@ -72,16 +72,17 @@ function z(t) {
72
72
  t
73
73
  );
74
74
  }
75
- class w extends Error {
76
- constructor(n, r) {
75
+ class h extends Error {
76
+ constructor(n, r, o) {
77
77
  super(
78
- r ? `AWS Transcribe: ${n} (${r})` : `AWS Transcribe: ${n}`
78
+ r ? `AWS Transcribe: ${n} (${r})` : `AWS Transcribe: ${n}`,
79
+ o !== void 0 ? { cause: o } : void 0
79
80
  );
80
- B(this, "code");
81
+ re(this, "code");
81
82
  this.name = "AwsTranscribeError", this.code = n;
82
83
  }
83
84
  }
84
- const re = {
85
+ const Te = {
85
86
  de: "de-DE",
86
87
  en: "en-GB",
87
88
  es: "es-ES",
@@ -89,52 +90,62 @@ const re = {
89
90
  it: "it-IT",
90
91
  pt: "pt-PT"
91
92
  };
92
- function ge(t) {
93
- return re[t.toLowerCase().split(/[-_]/)[0] ?? ""] ?? null;
93
+ function Pe(t) {
94
+ return Te[t.toLowerCase().split(/[-_]/)[0] ?? ""] ?? null;
94
95
  }
95
- const oe = [8e3, 16e3, 44100, 48e3];
96
- function se(t) {
96
+ const ve = [8e3, 16e3, 44100, 48e3];
97
+ function Ae(t) {
97
98
  const e = Math.round(t);
98
- return oe.reduce(
99
+ return ve.reduce(
99
100
  (n, r) => Math.abs(r - e) < Math.abs(n - e) ? r : n
100
101
  );
101
102
  }
102
- function ae(t, e, n) {
103
+ function Ce(t, e, n) {
103
104
  if (e === n) return t;
104
- const r = e / n, s = new Float32Array(Math.max(1, Math.round(t.length / r)));
105
- for (let c = 0; c < s.length; c++) {
106
- const o = c * r, u = Math.floor(o), l = t[u] ?? 0, h = t[u + 1] ?? l;
107
- s[c] = l + (h - l) * (o - u);
105
+ const r = e / n, o = new Float32Array(Math.max(1, Math.round(t.length / r)));
106
+ for (let i = 0; i < o.length; i++) {
107
+ const s = i * r, a = Math.floor(s), l = t[a] ?? 0, w = t[a + 1] ?? l;
108
+ o[i] = l + (w - l) * (s - a);
108
109
  }
109
- return s;
110
+ return o;
110
111
  }
111
- function ce(t) {
112
+ function Se(t) {
112
113
  const e = new Uint8Array(t.length * 2), n = new DataView(e.buffer);
113
114
  for (let r = 0; r < t.length; r++) {
114
- const s = Math.max(-1, Math.min(1, t[r] ?? 0));
115
- n.setInt16(r * 2, s < 0 ? s * 32768 : s * 32767, !0);
115
+ const o = Math.max(-1, Math.min(1, t[r] ?? 0));
116
+ n.setInt16(r * 2, o < 0 ? o * 32768 : o * 32767, !0);
116
117
  }
117
118
  return e;
118
119
  }
119
- function ie(t) {
120
- var r, s, c;
120
+ function Ue(t) {
121
+ var r, o, i;
121
122
  const e = t;
122
- return (((r = e == null ? void 0 : e.Transcript) == null ? void 0 : r.Results) ?? ((c = (s = e == null ? void 0 : e.TranscriptEvent) == null ? void 0 : s.Transcript) == null ? void 0 : c.Results) ?? []).flatMap((o) => {
123
- var l, h;
124
- const u = (h = (l = o.Alternatives) == null ? void 0 : l[0]) == null ? void 0 : h.Transcript;
125
- return typeof u == "string" ? [{ text: u, partial: o.IsPartial === !0 }] : [];
123
+ return (((r = e == null ? void 0 : e.Transcript) == null ? void 0 : r.Results) ?? ((i = (o = e == null ? void 0 : e.TranscriptEvent) == null ? void 0 : o.Transcript) == null ? void 0 : i.Results) ?? []).flatMap((s) => {
124
+ var l, w;
125
+ const a = (w = (l = s.Alternatives) == null ? void 0 : l[0]) == null ? void 0 : w.Transcript;
126
+ return typeof a == "string" ? [{ text: a, partial: s.IsPartial === !0 }] : [];
126
127
  });
127
128
  }
128
- function $() {
129
+ function le() {
129
130
  if (typeof window > "u") return;
130
131
  const t = window;
131
132
  return t.AudioContext ?? t.webkitAudioContext;
132
133
  }
133
- function ue() {
134
+ function ke() {
134
135
  var t;
135
- return typeof navigator < "u" && typeof ((t = navigator.mediaDevices) == null ? void 0 : t.getUserMedia) == "function" && $() !== void 0 && typeof WebSocket < "u";
136
+ return typeof navigator < "u" && typeof ((t = navigator.mediaDevices) == null ? void 0 : t.getUserMedia) == "function" && le() !== void 0 && typeof WebSocket < "u";
136
137
  }
137
- const le = 3e3, de = 10, K = "alfadocs-aws-transcribe-capture", fe = `class Capture extends AudioWorkletProcessor {
138
+ const Ne = 3e3, Me = 10, Oe = 250, ie = 4, xe = 6e4, Re = 1e4;
139
+ function ae(t) {
140
+ if (typeof t == "string") return { url: t, reconnectToken: null };
141
+ if (!t || typeof t != "object") return null;
142
+ const { url: e, reconnectToken: n } = t;
143
+ return typeof e != "string" || e === "" ? null : {
144
+ url: e,
145
+ reconnectToken: typeof n == "string" && n !== "" ? n : null
146
+ };
147
+ }
148
+ const de = "alfadocs-aws-transcribe-capture", Le = `class Capture extends AudioWorkletProcessor {
138
149
  constructor(options) {
139
150
  super();
140
151
  this.size = (options && options.processorOptions && options.processorOptions.chunk) || 2048;
@@ -154,91 +165,91 @@ const le = 3e3, de = 10, K = "alfadocs-aws-transcribe-capture", fe = `class Capt
154
165
  return true;
155
166
  }
156
167
  }
157
- registerProcessor(${JSON.stringify(K)}, Capture);`;
158
- async function he(t, e, n) {
168
+ registerProcessor(${JSON.stringify(de)}, Capture);`;
169
+ async function We(t, e, n) {
159
170
  if (t.audioWorklet && typeof AudioWorkletNode < "u") {
160
- const c = URL.createObjectURL(
161
- new Blob([fe], { type: "text/javascript" })
171
+ const i = URL.createObjectURL(
172
+ new Blob([Le], { type: "text/javascript" })
162
173
  );
163
174
  try {
164
- await t.audioWorklet.addModule(c);
165
- const o = new AudioWorkletNode(t, K, {
175
+ await t.audioWorklet.addModule(i);
176
+ const s = new AudioWorkletNode(t, de, {
166
177
  processorOptions: { chunk: e }
167
178
  });
168
- return o.port.onmessage = (u) => n(u.data), o;
179
+ return s.port.onmessage = (a) => n(a.data), s;
169
180
  } catch {
170
181
  } finally {
171
- URL.revokeObjectURL(c);
182
+ URL.revokeObjectURL(i);
172
183
  }
173
184
  }
174
185
  let r = 1024;
175
186
  for (; r < e && r < 16384; ) r *= 2;
176
- const s = t.createScriptProcessor(r, 1, 1);
177
- return s.onaudioprocess = (c) => n(c.inputBuffer.getChannelData(0).slice()), s;
187
+ const o = t.createScriptProcessor(r, 1, 1);
188
+ return o.onaudioprocess = (i) => n(i.inputBuffer.getChannelData(0).slice()), o;
178
189
  }
179
- function pe(t) {
190
+ function De(t) {
180
191
  return t && typeof t == "object" && "name" in t ? String(t.name) : void 0;
181
192
  }
182
- function ye(t) {
193
+ function je(t) {
183
194
  return async ({
184
195
  signal: e,
185
196
  onPartialTranscript: n,
186
197
  onFinalTranscript: r,
187
- onStatus: s
198
+ onStatus: o
188
199
  }) => {
189
- const c = $();
190
- if (!c || !ue())
191
- throw new w("unsupported");
200
+ const i = le();
201
+ if (!i || !ke())
202
+ throw new h("unsupported");
192
203
  if (e.aborted) return;
193
- let o;
204
+ let s = null, a;
194
205
  try {
195
- o = new c({ sampleRate: 48e3 });
206
+ a = new i({ sampleRate: 48e3 });
196
207
  } catch {
197
- o = new c();
208
+ a = new i();
198
209
  }
199
- const u = o.sampleRate || 48e3, l = se(u), h = Math.max(1024, Math.round(u * 0.05));
200
- let i = null;
201
- const k = [], A = () => {
202
- for (const a of k.splice(0)) {
203
- "port" in a && (a.port.onmessage = null), "onaudioprocess" in a && (a.onaudioprocess = null);
210
+ const l = a.sampleRate || 48e3, w = Ae(l), d = Math.max(1024, Math.round(l * 0.05));
211
+ let T = null;
212
+ const $ = [], N = () => {
213
+ for (const c of $.splice(0)) {
214
+ "port" in c && (c.port.onmessage = null), "onaudioprocess" in c && (c.onaudioprocess = null);
204
215
  try {
205
- a.disconnect();
216
+ c.disconnect();
206
217
  } catch {
207
218
  }
208
219
  }
209
- i == null || i.getTracks().forEach((a) => a.stop()), i = null, o.state !== "closed" && o.close().catch(() => {
220
+ T == null || T.getTracks().forEach((c) => c.stop()), T = null, a.state !== "closed" && a.close().catch(() => {
210
221
  });
211
- }, N = Math.round(u * de);
212
- let p = new Float32Array(0), E = null;
213
- const R = (a) => {
214
- !E || E.readyState !== WebSocket.OPEN || a.length === 0 || E.send(
215
- z(ce(ae(a, u, l)))
222
+ }, K = Math.round(l * Me);
223
+ let m = new Float32Array(0), v = null;
224
+ const J = (c) => {
225
+ !v || v.readyState !== WebSocket.OPEN || c.length === 0 || v.send(
226
+ ce(Se(Ce(c, l, w)))
216
227
  );
217
- }, M = (a) => {
218
- if (!(!E || E.readyState !== WebSocket.OPEN)) {
219
- for (; p.length >= h; )
220
- R(p.subarray(0, h)), p = p.slice(h);
221
- a && p.length && (R(p), p = new Float32Array(0));
228
+ }, G = (c) => {
229
+ if (!(!v || v.readyState !== WebSocket.OPEN)) {
230
+ for (; m.length >= d; )
231
+ J(m.subarray(0, d)), m = m.slice(d);
232
+ c && m.length && (J(m), m = new Float32Array(0));
222
233
  }
223
- }, J = (a) => {
224
- const f = new Float32Array(p.length + a.length);
225
- f.set(p), f.set(a, p.length), p = f.length > N ? f.slice(f.length - N) : f, M(!1);
226
- }, H = async (a) => {
227
- const f = await he(o, h, J);
228
- if (!i) {
234
+ }, fe = (c) => {
235
+ const f = new Float32Array(m.length + c.length);
236
+ f.set(m), f.set(c, m.length), m = f.length > K ? f.slice(f.length - K) : f, G(!1);
237
+ }, he = async (c) => {
238
+ const f = await We(a, d, fe);
239
+ if (!T) {
229
240
  "port" in f && (f.port.onmessage = null), "onaudioprocess" in f && (f.onaudioprocess = null);
230
241
  return;
231
242
  }
232
- const v = o.createMediaStreamSource(a), g = o.createGain();
233
- g.gain.value = 0, k.push(v, f, g), v.connect(f), f.connect(g), g.connect(o.destination);
243
+ const b = a.createMediaStreamSource(c), g = a.createGain();
244
+ g.gain.value = 0, $.push(b, f, g), b.connect(f), f.connect(g), g.connect(a.destination);
234
245
  };
235
246
  try {
236
- o.state === "suspended" && await o.resume();
247
+ a.state === "suspended" && await a.resume();
237
248
  } catch {
238
- throw A(), new w("unsupported", "audio context");
249
+ throw N(), new h("unsupported", "audio context");
239
250
  }
240
- s == null || s("connecting");
241
- const X = typeof t.languageCode == "function" ? t.languageCode() : t.languageCode, [m, U] = await Promise.allSettled([
251
+ o == null || o("connecting");
252
+ const X = typeof t.languageCode == "function" ? t.languageCode() : t.languageCode, [S, x] = await Promise.allSettled([
242
253
  navigator.mediaDevices.getUserMedia({
243
254
  audio: {
244
255
  channelCount: 1,
@@ -246,99 +257,194 @@ function ye(t) {
246
257
  noiseSuppression: !0,
247
258
  autoGainControl: !0
248
259
  }
249
- }).then(async (a) => {
250
- if (i = a, e.aborted) return a;
260
+ }).then(async (c) => {
261
+ if (T = c, e.aborted) return c;
251
262
  try {
252
- await H(a);
263
+ await he(c);
253
264
  } catch {
254
- throw new w("unsupported", "audio graph");
265
+ throw new h("unsupported", "audio graph");
255
266
  }
256
- return !e.aborted && i && (s == null || s("listening")), a;
267
+ return !e.aborted && T && (o == null || o("listening")), c;
257
268
  }),
258
269
  t.getUrl(
259
- { languageCode: X, mediaEncoding: "pcm", sampleRate: l },
270
+ { languageCode: X, mediaEncoding: "pcm", sampleRate: w },
260
271
  e
261
272
  )
262
273
  ]);
263
- if (m.status === "fulfilled" && (i = m.value), e.aborted || m.status === "rejected" || U.status === "rejected") {
264
- if (A(), e.aborted) return;
265
- if (m.status === "rejected") {
266
- if (m.reason instanceof w) throw m.reason;
267
- const a = pe(m.reason);
268
- throw a === "NotAllowedError" || a === "PermissionDeniedError" || a === "SecurityError" ? new w("permission") : new w("unsupported", a);
274
+ if (S.status === "fulfilled" && (T = S.value), e.aborted || S.status === "rejected" || x.status === "rejected") {
275
+ if (N(), e.aborted) return;
276
+ if (S.status === "rejected") {
277
+ if (S.reason instanceof h) throw S.reason;
278
+ const c = De(S.reason);
279
+ throw c === "NotAllowedError" || c === "PermissionDeniedError" || c === "SecurityError" ? new h("permission") : new h("unsupported", c);
269
280
  }
270
- throw new w(
281
+ throw new h(
271
282
  "url",
272
- U.status === "rejected" && U.reason instanceof Error ? U.reason.message : void 0
283
+ x.status === "rejected" && x.reason instanceof Error ? x.reason.message : void 0
273
284
  );
274
285
  }
275
- const Y = U.value;
276
- let d;
286
+ const I = ae(x.value);
287
+ if (I === null)
288
+ throw N(), new h("url", "no url");
289
+ s = I.reconnectToken;
290
+ let R;
277
291
  try {
278
- d = new WebSocket(Y), d.binaryType = "arraybuffer";
292
+ R = new WebSocket(I.url), R.binaryType = "arraybuffer";
279
293
  } catch {
280
- throw A(), new w("connection");
294
+ throw N(), new h("connection");
281
295
  }
282
- return E = d, new Promise((a, f) => {
283
- let v = !1, g = "", O = null, L, W = !1;
284
- const D = () => {
285
- M(!0), d.send(z(new Uint8Array(0))), L = setTimeout(() => C(), le);
286
- }, C = (S) => {
287
- if (v) return;
288
- v = !0, clearTimeout(L), e.removeEventListener("abort", P), A(), d.onopen = d.onmessage = d.onerror = d.onclose = null, (d.readyState === WebSocket.OPEN || d.readyState === WebSocket.CONNECTING) && d.close();
289
- const y = g.trim();
290
- g = "", n(""), y && r(y), S && !e.aborted ? f(S) : a();
296
+ return v = R, new Promise((c, f) => {
297
+ let b = !1, g = "", B = null, Y, H = !1, y = R, z = 0;
298
+ const L = [];
299
+ let D = !1, F, V, M = null;
300
+ const q = () => {
301
+ G(!0), y == null || y.send(ce(new Uint8Array(0))), Y = setTimeout(() => A(), Ne);
302
+ }, Q = (u) => {
303
+ if (u && (u.onopen = u.onmessage = u.onerror = u.onclose = null, u.readyState === WebSocket.OPEN || u.readyState === WebSocket.CONNECTING))
304
+ try {
305
+ u.close();
306
+ } catch {
307
+ }
308
+ }, A = (u) => {
309
+ if (b) return;
310
+ b = !0, clearTimeout(Y), clearTimeout(F), clearTimeout(V), M == null || M.abort(), D = !1, e.removeEventListener("abort", Z), N(), Q(y), y = v = null;
311
+ const E = g.trim();
312
+ g = "", n(""), E && r(E), u && !e.aborted ? f(u) : c();
291
313
  };
292
- function P() {
293
- v || (A(), d.readyState === WebSocket.OPEN ? D() : d.readyState === WebSocket.CONNECTING && p.length > 0 ? W = !0 : C());
314
+ function Z() {
315
+ b || (N(), D || !y ? A() : y.readyState === WebSocket.OPEN ? q() : y.readyState === WebSocket.CONNECTING && m.length > 0 ? H = !0 : A());
294
316
  }
295
- e.addEventListener("abort", P, { once: !0 }), d.onopen = () => {
296
- if (W) return D();
297
- if (!i) return C();
298
- M(!1);
299
- }, d.onmessage = (S) => {
300
- let y;
301
- try {
302
- y = ne(S.data);
303
- } catch {
317
+ e.addEventListener("abort", Z, { once: !0 });
318
+ const ee = () => {
319
+ const u = Date.now();
320
+ for (; L.length > 0 && u - (L[0] ?? 0) >= xe; )
321
+ L.shift();
322
+ if (z >= ie || L.length >= ie) {
323
+ A(new h("connection", "reconnect limit"));
304
324
  return;
305
325
  }
306
- const j = y.headers[":message-type"];
307
- if (j === "exception") {
308
- O = new w(
309
- "service",
310
- y.headers[":exception-type"] ?? y.headers[":error-code"]
326
+ z += 1, L.push(u), D = !0, F = setTimeout(() => void pe(), Oe);
327
+ }, pe = async () => {
328
+ if (F = void 0, b || e.aborted) return;
329
+ let u;
330
+ const E = new AbortController();
331
+ M = E;
332
+ const W = () => E.abort();
333
+ e.addEventListener("abort", W, { once: !0 });
334
+ try {
335
+ const p = new Promise((O, _) => {
336
+ V = setTimeout(() => {
337
+ _(new h("url", "timeout")), E.abort();
338
+ }, Re);
339
+ });
340
+ u = await Promise.race([
341
+ t.getUrl(
342
+ {
343
+ languageCode: X,
344
+ mediaEncoding: "pcm",
345
+ sampleRate: w,
346
+ ...s !== null ? { reconnectToken: s } : {}
347
+ },
348
+ E.signal
349
+ ),
350
+ p
351
+ ]);
352
+ } catch (p) {
353
+ if (b || e.aborted) return;
354
+ A(
355
+ p instanceof h ? p : new h(
356
+ "url",
357
+ p instanceof Error ? p.message : void 0,
358
+ p
359
+ )
311
360
  );
312
361
  return;
362
+ } finally {
363
+ clearTimeout(V), e.removeEventListener("abort", W), M === E && (M = null);
313
364
  }
314
- if (j !== "event" || y.headers[":event-type"] !== "TranscriptEvent")
365
+ if (b || e.aborted) return;
366
+ const U = ae(u);
367
+ if (U === null) {
368
+ A(new h("url", "no url"));
315
369
  return;
316
- let G;
370
+ }
371
+ U.reconnectToken && (s = U.reconnectToken);
372
+ let C;
317
373
  try {
318
- G = JSON.parse(new TextDecoder().decode(y.payload));
374
+ C = new WebSocket(U.url), C.binaryType = "arraybuffer";
319
375
  } catch {
376
+ ee();
320
377
  return;
321
378
  }
322
- for (const T of ie(G))
323
- if (T.partial)
324
- g = T.text, n(T.text);
325
- else {
326
- g = "", n("");
327
- const _ = T.text.trim();
328
- _ && r(_);
379
+ D = !1, y = v = C, te(C, !0);
380
+ };
381
+ function te(u, E) {
382
+ let W = !1;
383
+ u.onopen = () => {
384
+ if (u === y) {
385
+ if (W = !0, H) return q();
386
+ if (!T) return A();
387
+ G(!1);
388
+ }
389
+ }, u.onmessage = (C) => {
390
+ if (u !== y) return;
391
+ let p;
392
+ try {
393
+ p = Ee(C.data);
394
+ } catch {
395
+ return;
329
396
  }
330
- }, d.onerror = () => C(O ?? new w("connection")), d.onclose = () => C(O ?? void 0);
397
+ const O = p.headers[":message-type"];
398
+ if (O === "exception") {
399
+ B = new h(
400
+ "service",
401
+ p.headers[":exception-type"] ?? p.headers[":error-code"]
402
+ );
403
+ return;
404
+ }
405
+ if (O !== "event" || p.headers[":event-type"] !== "TranscriptEvent")
406
+ return;
407
+ let _;
408
+ try {
409
+ _ = JSON.parse(new TextDecoder().decode(p.payload));
410
+ } catch {
411
+ return;
412
+ }
413
+ for (const P of Ue(_))
414
+ if (P.partial)
415
+ g = P.text, n(P.text);
416
+ else {
417
+ g = "", z = 0, n("");
418
+ const ne = P.text.trim();
419
+ ne && r(ne);
420
+ }
421
+ };
422
+ const U = (C) => {
423
+ if (u !== y) return;
424
+ if (!(!b && !e.aborted && B === null && s !== null && (W || E))) {
425
+ A(
426
+ B ?? (C ? new h("connection") : void 0)
427
+ );
428
+ return;
429
+ }
430
+ Q(u), y = v = null;
431
+ const O = g.trim();
432
+ g = "", n(""), O && r(O), ee();
433
+ };
434
+ u.onerror = () => U(!0), u.onclose = () => U(!1);
435
+ }
436
+ te(R, !1);
331
437
  });
332
438
  };
333
439
  }
334
440
  export {
335
- w as AwsTranscribeError,
336
- ge as awsLanguageCode,
337
- ye as createAwsTranscribeDictation,
338
- ue as isAwsTranscribeSupported,
339
- ae as resample,
340
- ce as toPcm16,
341
- ie as transcriptResults,
342
- se as transmitSampleRate
441
+ h as AwsTranscribeError,
442
+ Pe as awsLanguageCode,
443
+ je as createAwsTranscribeDictation,
444
+ ke as isAwsTranscribeSupported,
445
+ Ce as resample,
446
+ Se as toPcm16,
447
+ Ue as transcriptResults,
448
+ Ae as transmitSampleRate
343
449
  };
344
450
  //# sourceMappingURL=index.js.map