@alfadocs/ui-kit 1.144.0 → 1.146.0

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 (94) hide show
  1. package/dist/_chunks/{calendar-appointment-editor-dialog-CA69bdbI.js → calendar-appointment-editor-dialog-sY-k0GGW.js} +3 -3
  2. package/dist/_chunks/{calendar-waiting-list-panel-Du_jtVbl.js → calendar-waiting-list-panel-Bm7NAZdk.js} +2 -2
  3. package/dist/_chunks/{calendar.sheets-CGwr4t2p.js → calendar.sheets-CCvdZF-R.js} +2 -2
  4. package/dist/_chunks/{editor-overlay-Cl6IhKNG.js → editor-overlay-jc9HUeQ2.js} +29 -26
  5. package/dist/_chunks/{help-me-write-templates-BdCQ-kFO.js → help-me-write-templates-DlA54nu5.js} +2 -2
  6. package/dist/_chunks/{notes-panel-DnBmONPb.js → notes-panel-C9aB1Cma.js} +2 -2
  7. package/dist/_chunks/prescription-history-CYCg6nxp.js +1772 -0
  8. package/dist/_chunks/registry-connection-panel-BEAkwivy.js +503 -0
  9. package/dist/_chunks/rich-text-editor-CJXc5GgH.js +4351 -0
  10. package/dist/agent-catalog.json +115 -1
  11. package/dist/agent-i18n/en.json +12 -0
  12. package/dist/appointment-editor-panel/index.js +1 -1
  13. package/dist/aws-transcribe/index.js +176 -152
  14. package/dist/browser-support.js +1 -1
  15. package/dist/components/_shared/medication.d.ts +4 -0
  16. package/dist/components/editor-overlay/index.js +1 -1
  17. package/dist/components/index.d.ts +1 -0
  18. package/dist/components/notes-panel/index.js +1 -1
  19. package/dist/components/registry-connection-panel/index.d.ts +3 -0
  20. package/dist/components/registry-connection-panel/index.js +5 -0
  21. package/dist/components/registry-connection-panel/registry-connection-panel.agent.d.ts +4 -0
  22. package/dist/components/registry-connection-panel/registry-connection-panel.d.ts +67 -0
  23. package/dist/components/rich-text-editor/help-me-write-overlay.d.ts +2 -0
  24. package/dist/components/rich-text-editor/index.js +1 -1
  25. package/dist/components/rich-text-editor/rich-text-editor.d.ts +7 -0
  26. package/dist/find-free-slots-panel/index.js +1 -1
  27. package/dist/i18n/locales/ar.d.ts +30 -0
  28. package/dist/i18n/locales/ar.js +31 -1
  29. package/dist/i18n/locales/de.d.ts +30 -0
  30. package/dist/i18n/locales/de.js +31 -1
  31. package/dist/i18n/locales/el.d.ts +30 -0
  32. package/dist/i18n/locales/el.js +31 -1
  33. package/dist/i18n/locales/en.d.ts +30 -0
  34. package/dist/i18n/locales/en.js +31 -1
  35. package/dist/i18n/locales/es.d.ts +30 -0
  36. package/dist/i18n/locales/es.js +31 -1
  37. package/dist/i18n/locales/fr.d.ts +30 -0
  38. package/dist/i18n/locales/fr.js +31 -1
  39. package/dist/i18n/locales/hi.d.ts +30 -0
  40. package/dist/i18n/locales/hi.js +31 -1
  41. package/dist/i18n/locales/it.d.ts +30 -0
  42. package/dist/i18n/locales/it.js +31 -1
  43. package/dist/i18n/locales/ja.d.ts +30 -0
  44. package/dist/i18n/locales/ja.js +31 -1
  45. package/dist/i18n/locales/nl.d.ts +30 -0
  46. package/dist/i18n/locales/nl.js +31 -1
  47. package/dist/i18n/locales/pl.d.ts +30 -0
  48. package/dist/i18n/locales/pl.js +31 -1
  49. package/dist/i18n/locales/pt.d.ts +30 -0
  50. package/dist/i18n/locales/pt.js +31 -1
  51. package/dist/i18n/locales/ro.d.ts +30 -0
  52. package/dist/i18n/locales/ro.js +31 -1
  53. package/dist/i18n/locales/ru.d.ts +30 -0
  54. package/dist/i18n/locales/ru.js +31 -1
  55. package/dist/i18n/locales/sq.d.ts +30 -0
  56. package/dist/i18n/locales/sq.js +31 -1
  57. package/dist/i18n/locales/sv.d.ts +30 -0
  58. package/dist/i18n/locales/sv.js +31 -1
  59. package/dist/i18n/locales/tr.d.ts +30 -0
  60. package/dist/i18n/locales/tr.js +31 -1
  61. package/dist/i18n/locales/zh.d.ts +30 -0
  62. package/dist/i18n/locales/zh.js +31 -1
  63. package/dist/index.js +860 -858
  64. package/dist/locales/ar.json +31 -1
  65. package/dist/locales/de.json +31 -1
  66. package/dist/locales/el.json +31 -1
  67. package/dist/locales/en.json +31 -1
  68. package/dist/locales/es.json +31 -1
  69. package/dist/locales/fr.json +31 -1
  70. package/dist/locales/hi.json +31 -1
  71. package/dist/locales/it.json +31 -1
  72. package/dist/locales/ja.json +31 -1
  73. package/dist/locales/nl.json +31 -1
  74. package/dist/locales/pl.json +31 -1
  75. package/dist/locales/pt.json +31 -1
  76. package/dist/locales/ro.json +31 -1
  77. package/dist/locales/ru.json +31 -1
  78. package/dist/locales/sq.json +31 -1
  79. package/dist/locales/sv.json +31 -1
  80. package/dist/locales/tr.json +31 -1
  81. package/dist/locales/zh.json +31 -1
  82. package/dist/online-bookings-panel/index.js +1 -1
  83. package/dist/patterns/calendar/index.js +2 -2
  84. package/dist/patterns/help-me-write-templates/index.js +1 -1
  85. package/dist/patterns/prescription/index.js +1 -1
  86. package/dist/patterns/prescription/prescription-sheet.d.ts +7 -1
  87. package/dist/patterns/prescription/prescription-validation.d.ts +7 -3
  88. package/dist/redactor.css +3 -0
  89. package/dist/speech/aws-transcribe.d.ts +9 -0
  90. package/dist/tokens.css +3 -0
  91. package/dist/waiting-list-panel/index.js +2 -2
  92. package/package.json +5 -1
  93. package/dist/_chunks/prescription-history-CD3e3U3I.js +0 -1719
  94. package/dist/_chunks/rich-text-editor-Cx9cA4pd.js +0 -4305
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
- "packageVersion": "1.144.0",
3
+ "packageVersion": "1.146.0",
4
4
  "components": [
5
5
  {
6
6
  "kind": "component",
@@ -15605,6 +15605,109 @@
15605
15605
  }
15606
15606
  }
15607
15607
  },
15608
+ {
15609
+ "kind": "component",
15610
+ "id": "registry-connection-panel",
15611
+ "capabilities": [
15612
+ "view_change",
15613
+ "submit"
15614
+ ],
15615
+ "state": [
15616
+ {
15617
+ "name": "status",
15618
+ "type": "'connected' | 'disconnected' | 'incomplete'",
15619
+ "description": "Connection state: connected (a session is open), disconnected (settings saved, no session) or incomplete (settings not saved yet).",
15620
+ "descriptionKey": "ui.agent.registryConnectionPanel.state.status"
15621
+ },
15622
+ {
15623
+ "name": "view",
15624
+ "type": "'overview' | 'connect'",
15625
+ "description": "The open view: the overview (status and settings) or the connect view (the one-time code step).",
15626
+ "descriptionKey": "ui.agent.registryConnectionPanel.state.view"
15627
+ }
15628
+ ],
15629
+ "actions": [
15630
+ {
15631
+ "name": "set_view",
15632
+ "safety": "write",
15633
+ "argsType": "{ view: 'overview' | 'connect' }",
15634
+ "argsSchema": {
15635
+ "type": "object",
15636
+ "properties": {
15637
+ "view": {
15638
+ "type": "string",
15639
+ "enum": [
15640
+ "overview",
15641
+ "connect"
15642
+ ]
15643
+ }
15644
+ },
15645
+ "required": [
15646
+ "view"
15647
+ ]
15648
+ },
15649
+ "idempotent": true,
15650
+ "examples": [
15651
+ {
15652
+ "args": {
15653
+ "view": "connect"
15654
+ },
15655
+ "note": "Open the code step."
15656
+ }
15657
+ ],
15658
+ "description": "Open the overview or the connect view (the code step). Nothing is sent to the registry.",
15659
+ "descriptionKey": "ui.agent.registryConnectionPanel.actions.setView"
15660
+ },
15661
+ {
15662
+ "name": "submit_settings",
15663
+ "safety": "write",
15664
+ "idempotent": true,
15665
+ "openWorld": true,
15666
+ "errors": [
15667
+ "A required field is empty: the panel shows the message and does not call the host.",
15668
+ "The host refused the settings. The panel shows the host's message."
15669
+ ],
15670
+ "description": "Save the settings as they stand in the panel, through the host. The agent supplies no values and reads none: the fields hold credentials. Required fields are checked first.",
15671
+ "descriptionKey": "ui.agent.registryConnectionPanel.actions.submitSettings"
15672
+ },
15673
+ {
15674
+ "name": "confirm_code",
15675
+ "safety": "write",
15676
+ "argsType": "{ code: string }",
15677
+ "argsSchema": {
15678
+ "type": "object",
15679
+ "properties": {
15680
+ "code": {
15681
+ "type": "string",
15682
+ "description": "The one-time code the registry sent."
15683
+ }
15684
+ },
15685
+ "required": [
15686
+ "code"
15687
+ ]
15688
+ },
15689
+ "openWorld": true,
15690
+ "errors": [
15691
+ "The code is empty: the panel refuses it without calling the host.",
15692
+ "The host refused the code. The panel shows the host's message."
15693
+ ],
15694
+ "description": "Confirm the one-time code, through the host, to open a session. Read status afterwards: the host changes it on success and the panel returns to the overview.",
15695
+ "descriptionKey": "ui.agent.registryConnectionPanel.actions.confirmCode"
15696
+ }
15697
+ ],
15698
+ "domHooks": {
15699
+ "root": {
15700
+ "attr": "data-component",
15701
+ "value": "registry-connection-panel",
15702
+ "description": "Marks the RegistryConnectionPanel region."
15703
+ },
15704
+ "instanceId": {
15705
+ "attr": "data-component-id",
15706
+ "sourceProp": "id",
15707
+ "description": "Sourced from the id prop. Required to address a specific panel from the agent. The root also carries data-status and data-view."
15708
+ }
15709
+ }
15710
+ },
15608
15711
  {
15609
15712
  "kind": "component",
15610
15713
  "id": "resizable",
@@ -26036,6 +26139,17 @@
26036
26139
  "prescription.send"
26037
26140
  ]
26038
26141
  },
26142
+ {
26143
+ "name": "edit_failed_prescription",
26144
+ "safety": "phi",
26145
+ "description": "Correct a prescription the registry refused. The sheet shows an \"Edit\" button beside \"Send again\" only for a failed send, and only when the host passes onEdit. The kit only calls the host callback: the host reopens the prescription in the composer, prefilled, and sends the corrected one. The packs of a medication may be capped by the host (maxPacks), which is a common reason for a refusal.",
26146
+ "descriptionKey": "ui.agent.prescription.workflows.editFailedPrescription",
26147
+ "uiActions": [],
26148
+ "apiActions": [
26149
+ "prescription.update",
26150
+ "prescription.send"
26151
+ ]
26152
+ },
26039
26153
  {
26040
26154
  "name": "review_history",
26041
26155
  "safety": "phi",
@@ -1500,6 +1500,17 @@
1500
1500
  "reset": "Clear the current token and re-roll the captcha. Irreversible."
1501
1501
  }
1502
1502
  },
1503
+ "registryConnectionPanel": {
1504
+ "state": {
1505
+ "status": "Connection state: connected (a session is open), disconnected (settings saved, no session) or incomplete (settings not saved yet).",
1506
+ "view": "The open view: the overview (status and settings) or the connect view (the one-time code step)."
1507
+ },
1508
+ "actions": {
1509
+ "setView": "Open the overview or the connect view (the code step). Nothing is sent to the registry.",
1510
+ "submitSettings": "Save the settings as they stand in the panel, through the host. The agent supplies no values and reads none: the fields hold credentials. Required fields are checked first.",
1511
+ "confirmCode": "Confirm the one-time code, through the host, to open a session. Read status afterwards: the host changes it on success and the panel returns to the overview."
1512
+ }
1513
+ },
1503
1514
  "resizable": {
1504
1515
  "state": {
1505
1516
  "sizes": "Current per-panel sizes as percentages of the group."
@@ -2321,6 +2332,7 @@
2321
2332
  "printPrescription": "Print the saved prescription. Who prints follows the sheet's printMode, which is 'host' when the record has a send status (an electronic prescription) and 'sheet' otherwise. In host mode the sheet is an on-screen summary: Print and Download PDF only call the host's callbacks, and the host opens the official document the registry issues. In sheet mode the kit prints the sheet through the browser's print dialog, forced to the light theme; under privacy mode it prints masked, exactly as shown. A prescription whose send is under way or failed cannot be printed or shared in either mode. The sheet registers no print action with the agent runtime, so an assistant asks the host to print.",
2322
2333
  "sendPrescription": "Share the sent prescription with the patient by email, SMS or WhatsApp. It cannot be printed or shared until the registry has accepted it. The kit only calls the host callback for the chosen channel: the host builds and sends the message.",
2323
2334
  "resendPrescription": "Send a prescription again after the send to the national registry failed. The sheet shows a \"Send again\" button only for a failed send. The kit only calls the host callback: the host sends to the registry and passes the updated record.",
2335
+ "editFailedPrescription": "Correct a prescription the registry refused. The sheet shows an \"Edit\" button beside \"Send again\" only for a failed send, and only when the host passes onEdit. The kit only calls the host callback: the host reopens the prescription in the composer, prefilled, and sends the corrected one. The packs of a medication may be capped by the host (maxPacks), which is a common reason for a refusal.",
2324
2336
  "reviewHistory": "Read saved prescriptions, newest first: one patient's, or the whole practice's when the table shows a Patient column (date, number, send status, patient name, treatment, care plan, one tag per medication, prescriber, specialty), sorted and filtered by column. Reopening a row and printing it again are host callbacks: the host shows that record in a sheet, which then prints like any other. The table never shows a fiscal code or date of birth, and under privacy mode it masks the patient name."
2325
2337
  }
2326
2338
  },
@@ -5,7 +5,7 @@ import { I as j } from "../_chunks/icon-button-u9VMQn3x.js";
5
5
  import { a as F } from "../_chunks/panel-header-CbtlTe85.js";
6
6
  import { a as G } from "../_chunks/tooltip-uEBdD1-5.js";
7
7
  import { C as N, E as O } from "../_chunks/calendar-editor-guard-9fShhNIA.js";
8
- import { A as W, S as q } from "../_chunks/calendar.sheets-CGwr4t2p.js";
8
+ import { A as W, S as q } from "../_chunks/calendar.sheets-CCvdZF-R.js";
9
9
  import { u as z, c as B } from "../_chunks/calendar-editor-discard-host-DWS_kM-a.js";
10
10
  import { X as M } from "../_chunks/x-B5YnXwCz.js";
11
11
  import { P as R } from "../_chunks/privacy-mask-zVh0ntm0.js";
@@ -1,7 +1,7 @@
1
- var V = Object.defineProperty;
2
- var $ = (t, e, n) => e in t ? V(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
3
- var D = (t, e, n) => $(t, typeof e != "symbol" ? e + "" : e, n);
4
- const J = (() => {
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 = (() => {
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 J = (() => {
11
11
  }
12
12
  return t;
13
13
  })();
14
- function C(t) {
14
+ function x(t) {
15
15
  let e = 4294967295;
16
16
  for (let n = 0; n < t.length; n++)
17
- e = (J[(e ^ t[n]) & 255] ^ e >>> 8) >>> 0;
17
+ e = (Z[(e ^ t[n]) & 255] ^ e >>> 8) >>> 0;
18
18
  return (e ^ 4294967295) >>> 0;
19
19
  }
20
- const B = 7, m = 12, W = new TextEncoder(), P = new TextDecoder();
21
- function K(t) {
22
- const e = Object.entries(t).map(([s, o]) => {
23
- const a = W.encode(s), u = W.encode(o), c = new Uint8Array(
24
- 1 + a.length + 1 + 2 + u.length
25
- ), i = new DataView(c.buffer);
26
- let h = 0;
27
- return i.setUint8(h, a.length), h += 1, c.set(a, h), h += a.length, i.setUint8(h, B), h += 1, i.setUint16(h, u.length), h += 2, c.set(u, h), c;
28
- }), n = new Uint8Array(e.reduce((s, o) => s + o.length, 0));
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));
29
29
  let r = 0;
30
30
  for (const s of e)
31
31
  n.set(s, r), r += s.length;
32
32
  return n;
33
33
  }
34
- function H(t, e) {
35
- const n = K(t), r = m + n.length + e.length + 4, s = new Uint8Array(r), o = new DataView(s.buffer);
36
- return o.setUint32(0, r), o.setUint32(4, n.length), o.setUint32(8, C(s.subarray(0, 8))), s.set(n, m), s.set(e, m + n.length), o.setUint32(r - 4, C(s.subarray(0, r - 4))), s;
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;
37
37
  }
38
- function Y(t) {
38
+ function ne(t) {
39
39
  const e = new Uint8Array(t);
40
- if (e.length < m + 4)
40
+ if (e.length < b + 4)
41
41
  throw new Error("event-stream: frame too short");
42
42
  const n = new DataView(t), r = n.getUint32(0), s = n.getUint32(4);
43
- if (r !== e.length || m + s + 4 > r)
43
+ if (r !== e.length || b + s + 4 > r)
44
44
  throw new Error("event-stream: lengths do not match the frame");
45
- if (n.getUint32(8) !== C(e.subarray(0, 8)))
45
+ if (n.getUint32(8) !== x(e.subarray(0, 8)))
46
46
  throw new Error("event-stream: prelude checksum mismatch");
47
- if (n.getUint32(r - 4) !== C(e.subarray(0, r - 4)))
47
+ if (n.getUint32(r - 4) !== x(e.subarray(0, r - 4)))
48
48
  throw new Error("event-stream: message checksum mismatch");
49
- const o = {};
50
- let a = m;
51
- const u = m + s;
52
- for (; a < u; ) {
53
- const c = n.getUint8(a);
54
- a += 1;
55
- const i = P.decode(e.subarray(a, a + c));
56
- if (a += c, n.getUint8(a) !== B) break;
57
- a += 1;
58
- const h = n.getUint16(a);
59
- a += 2, o[i] = P.decode(
60
- e.subarray(a, a + h)
61
- ), a += h;
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;
62
62
  }
63
- return { headers: o, payload: e.slice(u, r - 4) };
63
+ return { headers: c, payload: e.slice(u, r - 4) };
64
64
  }
65
- function j(t) {
66
- return H(
65
+ function z(t) {
66
+ return te(
67
67
  {
68
68
  ":content-type": "application/octet-stream",
69
69
  ":event-type": "AudioEvent",
@@ -72,16 +72,16 @@ function j(t) {
72
72
  t
73
73
  );
74
74
  }
75
- class g extends Error {
75
+ class w extends Error {
76
76
  constructor(n, r) {
77
77
  super(
78
78
  r ? `AWS Transcribe: ${n} (${r})` : `AWS Transcribe: ${n}`
79
79
  );
80
- D(this, "code");
80
+ B(this, "code");
81
81
  this.name = "AwsTranscribeError", this.code = n;
82
82
  }
83
83
  }
84
- const q = {
84
+ const re = {
85
85
  de: "de-DE",
86
86
  en: "en-GB",
87
87
  es: "es-ES",
@@ -89,26 +89,26 @@ const q = {
89
89
  it: "it-IT",
90
90
  pt: "pt-PT"
91
91
  };
92
- function ie(t) {
93
- return q[t.toLowerCase().split(/[-_]/)[0] ?? ""] ?? null;
92
+ function ge(t) {
93
+ return re[t.toLowerCase().split(/[-_]/)[0] ?? ""] ?? null;
94
94
  }
95
- const Q = [8e3, 16e3, 44100, 48e3];
96
- function X(t) {
95
+ const oe = [8e3, 16e3, 44100, 48e3];
96
+ function se(t) {
97
97
  const e = Math.round(t);
98
- return Q.reduce(
98
+ return oe.reduce(
99
99
  (n, r) => Math.abs(r - e) < Math.abs(n - e) ? r : n
100
100
  );
101
101
  }
102
- function Z(t, e, n) {
102
+ function ae(t, e, n) {
103
103
  if (e === n) return t;
104
104
  const r = e / n, s = new Float32Array(Math.max(1, Math.round(t.length / r)));
105
- for (let o = 0; o < s.length; o++) {
106
- const a = o * r, u = Math.floor(a), c = t[u] ?? 0, i = t[u + 1] ?? c;
107
- s[o] = c + (i - c) * (a - u);
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);
108
108
  }
109
109
  return s;
110
110
  }
111
- function ee(t) {
111
+ function ce(t) {
112
112
  const e = new Uint8Array(t.length * 2), n = new DataView(e.buffer);
113
113
  for (let r = 0; r < t.length; r++) {
114
114
  const s = Math.max(-1, Math.min(1, t[r] ?? 0));
@@ -116,25 +116,25 @@ function ee(t) {
116
116
  }
117
117
  return e;
118
118
  }
119
- function te(t) {
120
- var r, s, o;
119
+ function ie(t) {
120
+ var r, s, c;
121
121
  const e = t;
122
- return (((r = e == null ? void 0 : e.Transcript) == null ? void 0 : r.Results) ?? ((o = (s = e == null ? void 0 : e.TranscriptEvent) == null ? void 0 : s.Transcript) == null ? void 0 : o.Results) ?? []).flatMap((a) => {
123
- var c, i;
124
- const u = (i = (c = a.Alternatives) == null ? void 0 : c[0]) == null ? void 0 : i.Transcript;
125
- return typeof u == "string" ? [{ text: u, partial: a.IsPartial === !0 }] : [];
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 }] : [];
126
126
  });
127
127
  }
128
- function G() {
128
+ function $() {
129
129
  if (typeof window > "u") return;
130
130
  const t = window;
131
131
  return t.AudioContext ?? t.webkitAudioContext;
132
132
  }
133
- function ne() {
133
+ function ue() {
134
134
  var t;
135
- return typeof navigator < "u" && typeof ((t = navigator.mediaDevices) == null ? void 0 : t.getUserMedia) == "function" && G() !== void 0 && typeof WebSocket < "u";
135
+ return typeof navigator < "u" && typeof ((t = navigator.mediaDevices) == null ? void 0 : t.getUserMedia) == "function" && $() !== void 0 && typeof WebSocket < "u";
136
136
  }
137
- const re = 3e3, _ = "alfadocs-aws-transcribe-capture", oe = `class Capture extends AudioWorkletProcessor {
137
+ const le = 3e3, de = 10, K = "alfadocs-aws-transcribe-capture", fe = `class Capture extends AudioWorkletProcessor {
138
138
  constructor(options) {
139
139
  super();
140
140
  this.size = (options && options.processorOptions && options.processorOptions.chunk) || 2048;
@@ -154,62 +154,91 @@ const re = 3e3, _ = "alfadocs-aws-transcribe-capture", oe = `class Capture exten
154
154
  return true;
155
155
  }
156
156
  }
157
- registerProcessor(${JSON.stringify(_)}, Capture);`;
158
- async function se(t, e, n) {
157
+ registerProcessor(${JSON.stringify(K)}, Capture);`;
158
+ async function he(t, e, n) {
159
159
  if (t.audioWorklet && typeof AudioWorkletNode < "u") {
160
- const o = URL.createObjectURL(
161
- new Blob([oe], { type: "text/javascript" })
160
+ const c = URL.createObjectURL(
161
+ new Blob([fe], { type: "text/javascript" })
162
162
  );
163
163
  try {
164
- await t.audioWorklet.addModule(o);
165
- const a = new AudioWorkletNode(t, _, {
164
+ await t.audioWorklet.addModule(c);
165
+ const o = new AudioWorkletNode(t, K, {
166
166
  processorOptions: { chunk: e }
167
167
  });
168
- return a.port.onmessage = (u) => n(u.data), a;
168
+ return o.port.onmessage = (u) => n(u.data), o;
169
169
  } catch {
170
170
  } finally {
171
- URL.revokeObjectURL(o);
171
+ URL.revokeObjectURL(c);
172
172
  }
173
173
  }
174
174
  let r = 1024;
175
175
  for (; r < e && r < 16384; ) r *= 2;
176
176
  const s = t.createScriptProcessor(r, 1, 1);
177
- return s.onaudioprocess = (o) => n(o.inputBuffer.getChannelData(0).slice()), s;
177
+ return s.onaudioprocess = (c) => n(c.inputBuffer.getChannelData(0).slice()), s;
178
178
  }
179
- function ae(t) {
179
+ function pe(t) {
180
180
  return t && typeof t == "object" && "name" in t ? String(t.name) : void 0;
181
181
  }
182
- function ue(t) {
183
- return async ({ signal: e, onPartialTranscript: n, onFinalTranscript: r }) => {
184
- const s = G();
185
- if (!s || !ne())
186
- throw new g("unsupported");
182
+ function ye(t) {
183
+ return async ({
184
+ signal: e,
185
+ onPartialTranscript: n,
186
+ onFinalTranscript: r,
187
+ onStatus: s
188
+ }) => {
189
+ const c = $();
190
+ if (!c || !ue())
191
+ throw new w("unsupported");
187
192
  if (e.aborted) return;
188
193
  let o;
189
194
  try {
190
- o = new s({ sampleRate: 48e3 });
195
+ o = new c({ sampleRate: 48e3 });
191
196
  } catch {
192
- o = new s();
197
+ o = new c();
193
198
  }
194
- const a = o.sampleRate || 48e3, u = X(a), c = Math.max(1024, Math.round(a * 0.05));
199
+ const u = o.sampleRate || 48e3, l = se(u), h = Math.max(1024, Math.round(u * 0.05));
195
200
  let i = null;
196
- const h = [], v = () => {
197
- for (const p of h.splice(0)) {
198
- "port" in p && (p.port.onmessage = null), "onaudioprocess" in p && (p.onaudioprocess = 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);
199
204
  try {
200
- p.disconnect();
205
+ a.disconnect();
201
206
  } catch {
202
207
  }
203
208
  }
204
- i == null || i.getTracks().forEach((p) => p.stop()), i = null, o.state !== "closed" && o.close().catch(() => {
209
+ i == null || i.getTracks().forEach((a) => a.stop()), i = null, o.state !== "closed" && o.close().catch(() => {
205
210
  });
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)))
216
+ );
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));
222
+ }
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) {
229
+ "port" in f && (f.port.onmessage = null), "onaudioprocess" in f && (f.onaudioprocess = null);
230
+ return;
231
+ }
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);
206
234
  };
207
235
  try {
208
236
  o.state === "suspended" && await o.resume();
209
237
  } catch {
210
- throw v(), new g("unsupported", "audio context");
238
+ throw A(), new w("unsupported", "audio context");
211
239
  }
212
- const I = typeof t.languageCode == "function" ? t.languageCode() : t.languageCode, [E, A] = await Promise.allSettled([
240
+ s == null || s("connecting");
241
+ const X = typeof t.languageCode == "function" ? t.languageCode() : t.languageCode, [m, U] = await Promise.allSettled([
213
242
  navigator.mediaDevices.getUserMedia({
214
243
  audio: {
215
244
  channelCount: 1,
@@ -217,104 +246,99 @@ function ue(t) {
217
246
  noiseSuppression: !0,
218
247
  autoGainControl: !0
219
248
  }
249
+ }).then(async (a) => {
250
+ if (i = a, e.aborted) return a;
251
+ try {
252
+ await H(a);
253
+ } catch {
254
+ throw new w("unsupported", "audio graph");
255
+ }
256
+ return !e.aborted && i && (s == null || s("listening")), a;
220
257
  }),
221
258
  t.getUrl(
222
- { languageCode: I, mediaEncoding: "pcm", sampleRate: u },
259
+ { languageCode: X, mediaEncoding: "pcm", sampleRate: l },
223
260
  e
224
261
  )
225
262
  ]);
226
- if (E.status === "fulfilled" && (i = E.value), e.aborted || E.status === "rejected" || A.status === "rejected") {
227
- if (v(), e.aborted) return;
228
- if (E.status === "rejected") {
229
- const p = ae(E.reason);
230
- throw p === "NotAllowedError" || p === "PermissionDeniedError" || p === "SecurityError" ? new g("permission") : new g("unsupported", p);
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);
231
269
  }
232
- throw new g(
270
+ throw new w(
233
271
  "url",
234
- A.status === "rejected" && A.reason instanceof Error ? A.reason.message : void 0
272
+ U.status === "rejected" && U.reason instanceof Error ? U.reason.message : void 0
235
273
  );
236
274
  }
237
- const F = A.value;
238
- let l;
275
+ const Y = U.value;
276
+ let d;
239
277
  try {
240
- l = new WebSocket(F), l.binaryType = "arraybuffer";
278
+ d = new WebSocket(Y), d.binaryType = "arraybuffer";
241
279
  } catch {
242
- throw v(), new g("connection");
280
+ throw A(), new w("connection");
243
281
  }
244
- return new Promise((p, z) => {
245
- let U = !1, S = "", x = null, M, w = new Float32Array(0);
246
- const R = (d) => {
247
- l.readyState !== WebSocket.OPEN || d.length === 0 || l.send(
248
- j(ee(Z(d, a, u)))
249
- );
250
- }, k = (d) => {
251
- for (; w.length >= c; )
252
- R(w.subarray(0, c)), w = w.slice(c);
253
- d && w.length && (R(w), w = new Float32Array(0));
254
- }, b = (d) => {
255
- if (U) return;
256
- U = !0, clearTimeout(M), e.removeEventListener("abort", L), v(), l.onopen = l.onmessage = l.onerror = l.onclose = null, (l.readyState === WebSocket.OPEN || l.readyState === WebSocket.CONNECTING) && l.close();
257
- const f = S.trim();
258
- S = "", n(""), f && r(f), d && !e.aborted ? z(d) : p();
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();
259
291
  };
260
- function L() {
261
- U || (v(), l.readyState === WebSocket.OPEN ? (k(!0), l.send(j(new Uint8Array(0))), M = setTimeout(() => b(), re)) : b());
292
+ function P() {
293
+ v || (A(), d.readyState === WebSocket.OPEN ? D() : d.readyState === WebSocket.CONNECTING && p.length > 0 ? W = !0 : C());
262
294
  }
263
- e.addEventListener("abort", L, { once: !0 }), l.onopen = () => {
264
- if (!i) return b();
265
- se(o, c, (d) => {
266
- const f = new Float32Array(w.length + d.length);
267
- f.set(w), f.set(d, w.length), w = f, k(!1);
268
- }).then((d) => {
269
- if (U || !i) return;
270
- const f = o.createMediaStreamSource(i), y = o.createGain();
271
- y.gain.value = 0, h.push(f, d, y), f.connect(d), d.connect(y), y.connect(o.destination);
272
- }).catch(
273
- () => b(new g("unsupported", "audio graph"))
274
- );
275
- }, l.onmessage = (d) => {
276
- let f;
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;
277
301
  try {
278
- f = Y(d.data);
302
+ y = ne(S.data);
279
303
  } catch {
280
304
  return;
281
305
  }
282
- const y = f.headers[":message-type"];
283
- if (y === "exception") {
284
- x = new g(
306
+ const j = y.headers[":message-type"];
307
+ if (j === "exception") {
308
+ O = new w(
285
309
  "service",
286
- f.headers[":exception-type"] ?? f.headers[":error-code"]
310
+ y.headers[":exception-type"] ?? y.headers[":error-code"]
287
311
  );
288
312
  return;
289
313
  }
290
- if (y !== "event" || f.headers[":event-type"] !== "TranscriptEvent")
314
+ if (j !== "event" || y.headers[":event-type"] !== "TranscriptEvent")
291
315
  return;
292
- let N;
316
+ let G;
293
317
  try {
294
- N = JSON.parse(new TextDecoder().decode(f.payload));
318
+ G = JSON.parse(new TextDecoder().decode(y.payload));
295
319
  } catch {
296
320
  return;
297
321
  }
298
- for (const T of te(N))
322
+ for (const T of ie(G))
299
323
  if (T.partial)
300
- S = T.text, n(T.text);
324
+ g = T.text, n(T.text);
301
325
  else {
302
- S = "", n("");
303
- const O = T.text.trim();
304
- O && r(O);
326
+ g = "", n("");
327
+ const _ = T.text.trim();
328
+ _ && r(_);
305
329
  }
306
- }, l.onerror = () => b(x ?? new g("connection")), l.onclose = () => b(x ?? void 0);
330
+ }, d.onerror = () => C(O ?? new w("connection")), d.onclose = () => C(O ?? void 0);
307
331
  });
308
332
  };
309
333
  }
310
334
  export {
311
- g as AwsTranscribeError,
312
- ie as awsLanguageCode,
313
- ue as createAwsTranscribeDictation,
314
- ne as isAwsTranscribeSupported,
315
- Z as resample,
316
- ee as toPcm16,
317
- te as transcriptResults,
318
- X as transmitSampleRate
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
319
343
  };
320
344
  //# sourceMappingURL=index.js.map