@kabmo-labs/kabmo 0.48.0 → 0.49.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.
- package/dist/client/index.html +1 -1
- package/dist/client/index.js +521 -507
- package/dist/client/static/js/{Body-3tspyjtk.js → Body-9h5hd351.js} +3 -3
- package/dist/client/static/js/{CsvGrid-3pwsfmxp.js → CsvGrid-s05k1q18.js} +2 -2
- package/dist/client/static/js/{DocxView-xcg9jktb.js → DocxView-x6sjw5ht.js} +22 -22
- package/dist/client/static/js/{DrawioView-2q19tgkx.js → DrawioView-jashn8sf.js} +2 -2
- package/dist/client/static/js/{HtmlPreview-92cadvbr.js → HtmlPreview-eygzgtyc.js} +1 -1
- package/dist/client/static/js/ImageView-g50pk5pt.js +1 -0
- package/dist/client/static/js/LayoutWrapper-tag0qpts.js +2 -0
- package/dist/client/static/js/MergeDiffView-c4mb8m1w.js +1 -0
- package/dist/client/static/js/Modal-pf9p6m1k.js +59 -0
- package/dist/client/static/js/PdfView-syhjmyqf.js +1 -0
- package/dist/client/static/js/SessionsView-2r1grxxs.js +1 -0
- package/dist/client/static/js/{SheetView-w5w2m2de.js → SheetView-26r0e506.js} +45 -45
- package/dist/client/static/js/{SvgPreview-mtk6de6h.js → SvgPreview-2fk85jzz.js} +1 -1
- package/dist/client/static/js/{abnfDiagram-O67JEVCF-tha4j2fn.js → abnfDiagram-O67JEVCF-fdka7pxr.js} +1 -1
- package/dist/client/static/js/architecture-7GRP2DOG-ee9wjsht.js +1 -0
- package/dist/client/static/js/architectureDiagram-NJMV4G6O-278nx8rt.js +36 -0
- package/dist/client/static/js/{astro-r4dp34pw.js → astro-rn2bvwpm.js} +1 -1
- package/dist/client/static/js/bash-36shcpcw.js +1 -0
- package/dist/client/static/js/{blockDiagram-BEXU5L5S-6mzgfqh8.js → blockDiagram-BEXU5L5S-vpcmd3vx.js} +9 -9
- package/dist/client/static/js/c-kxeqssf9.js +1 -0
- package/dist/client/static/js/{c4Diagram-YGBWAQC7-sfkcw7g9.js → c4Diagram-YGBWAQC7-1rgpdnbq.js} +3 -3
- package/dist/client/static/js/{classDiagram-v2-NBCMYWYE-v530ny5e.js → classDiagram-v2-NBCMYWYE-fbsejvb9.js} +9 -9
- package/dist/client/static/js/{cose-bilkent-JH36ORCC-ybv1ttbx.js → cose-bilkent-JH36ORCC-ydq7mvy0.js} +1 -1
- package/dist/client/static/js/cpp-wtk1s3d7.js +1 -0
- package/dist/client/static/js/css-0a0r6rp3.js +1 -0
- package/dist/client/static/js/css-xhnrhg4e.js +1 -0
- package/dist/client/static/js/cynefin-OW5HDTMX-gs16zjqa.js +1 -0
- package/dist/client/static/js/{cynefinDiagram-VND7K2PF-k8f3z0mm.js → cynefinDiagram-VND7K2PF-7ta5vbrw.js} +2 -2
- package/dist/client/static/js/dagre-6A5THRUB-b8gtt32x.js +4 -0
- package/dist/client/static/js/{diagram-22UHCM2B-2zh2957c.js → diagram-22UHCM2B-7emepy7h.js} +30 -30
- package/dist/client/static/js/{diagram-3UASUU5V-bzstt5e2.js → diagram-3UASUU5V-06nptkzc.js} +1 -1
- package/dist/client/static/js/{diagram-ATOU4E4O-16adx4g0.js → diagram-ATOU4E4O-t113exk3.js} +3 -3
- package/dist/client/static/js/{diagram-CDSNMT55-1ja98ens.js → diagram-CDSNMT55-pyj3x97y.js} +5 -5
- package/dist/client/static/js/{diagram-MLGK6HIB-f9nnyjbq.js → diagram-MLGK6HIB-183sgpjh.js} +2 -2
- package/dist/client/static/js/{diagram-MPIPVDR6-3qgadfjz.js → diagram-MPIPVDR6-fmbj4hcx.js} +2 -2
- package/dist/client/static/js/{dockerfile-04tc68pq.js → dockerfile-qay672za.js} +1 -1
- package/dist/client/static/js/{ebnfDiagram-ZINNZB2B-022cz603.js → ebnfDiagram-ZINNZB2B-eafvfws2.js} +1 -1
- package/dist/client/static/js/{elixir-61gbjv6c.js → elixir-t8bep87c.js} +1 -1
- package/dist/client/static/js/{elk-276RUBZZ-2anf1c36.js → elk-276RUBZZ-573f1vfs.js} +1 -1
- package/dist/client/static/js/{erDiagram-OPXOYQCR-ndd27fz1.js → erDiagram-OPXOYQCR-4z1r88ej.js} +14 -14
- package/dist/client/static/js/{erlang-bh5cbm8m.js → erlang-261km7r1.js} +1 -1
- package/dist/client/static/js/eventmodeling-NTZA5JFV-ftz7zrz5.js +1 -0
- package/dist/client/static/js/flowDiagram-KWPJA3E3-ax0qfmp3.js +1 -0
- package/dist/client/static/js/{ganttDiagram-FUAMR5RP-9gm6hkgn.js → ganttDiagram-FUAMR5RP-49jd7msz.js} +4 -4
- package/dist/client/static/js/gitGraph-4MIJSDKK-3rtkds4s.js +1 -0
- package/dist/client/static/js/{gitGraphDiagram-X574FWY7-78bxa67c.js → gitGraphDiagram-X574FWY7-5p9mgq7n.js} +22 -22
- package/dist/client/static/js/graphql-w9ajhndp.js +1 -0
- package/dist/client/static/js/html-krfbq5wp.js +1 -0
- package/dist/client/static/js/index-05n22cg9.js +4 -0
- package/dist/client/static/js/{index-he4k2j91.js → index-0857zpr0.js} +2 -2
- package/dist/client/static/js/{index-2n1fgpjv.js → index-0w4jqzqk.js} +2 -2
- package/dist/client/static/js/{index-4n7t26ap.js → index-14dgbjsm.js} +1 -1
- package/dist/client/static/js/{index-mqzgf7rw.js → index-1p880x6e.js} +2 -2
- package/dist/client/static/js/{index-34aq5bz5.js → index-1yq96wpa.js} +2 -2
- package/dist/client/static/js/{index-hq28918s.js → index-2bf0txsp.js} +2 -2
- package/dist/client/static/js/index-2jgx68m0.js +1 -0
- package/dist/client/static/js/{index-g3rg6vsd.js → index-2yzt8h3d.js} +2 -2
- package/dist/client/static/js/{index-m39gbcxn.js → index-333rq9yy.js} +1 -1
- package/dist/client/static/js/{index-aa3hmn6j.js → index-38g2eevc.js} +76 -76
- package/dist/client/static/js/{index-aabp7nt6.js → index-3v8k8ms3.js} +1 -1
- package/dist/client/static/js/{index-0e51wknc.js → index-473hk8nb.js} +10 -10
- package/dist/client/static/js/{index-xny7vsfz.js → index-4ccs971z.js} +2 -2
- package/dist/client/static/js/{index-ya9yqj5w.js → index-4dnc1kys.js} +2 -2
- package/dist/client/static/js/{index-7whstwc7.js → index-4z5ram7g.js} +2 -2
- package/dist/client/static/js/{index-pzsp1src.js → index-5dn4159w.js} +2 -2
- package/dist/client/static/js/{index-k39be93q.js → index-5p8dwr4y.js} +1 -1
- package/dist/client/static/js/{index-2bsnywea.js → index-5ztdqm1w.js} +2 -2
- package/dist/client/static/js/{index-m0fatq7c.js → index-7dqq7cjp.js} +13 -13
- package/dist/client/static/js/{index-417fbrqk.js → index-7ff9scbm.js} +2 -2
- package/dist/client/static/js/{index-zcgqacvx.js → index-7rmps91t.js} +2 -2
- package/dist/client/static/js/{index-gpmcth0x.js → index-80fjn77c.js} +2 -2
- package/dist/client/static/js/{index-rgxg0azs.css → index-9wc36am3.css} +1 -1
- package/dist/client/static/js/{index-kaxvwh07.js → index-a4636gt1.js} +2 -2
- package/dist/client/static/js/{index-hwzxdwwg.js → index-bmaktvm2.js} +1 -1
- package/dist/client/static/js/index-bvpzzhn2.js +4 -0
- package/dist/client/static/js/{index-dxnkwf39.js → index-c3whkrwa.js} +47 -47
- package/dist/client/static/js/{index-kjr68pcj.js → index-dh060b7r.js} +2 -2
- package/dist/client/static/js/{index-hkz2mz34.js → index-dmc82cxb.js} +2 -2
- package/dist/client/static/js/index-e19dbqd3.js +2 -0
- package/dist/client/static/js/{index-ep6bqcmg.js → index-e8mt8rag.js} +2 -2
- package/dist/client/static/js/index-epzvftkq.js +1 -0
- package/dist/client/static/js/{index-ac2q5903.js → index-fbg5vhhw.js} +2 -2
- package/dist/client/static/js/{index-qxzj780x.js → index-gaqjrzdb.js} +2 -2
- package/dist/client/static/js/{index-3en15m75.js → index-gg910gpv.js} +2 -2
- package/dist/client/static/js/{index-qe0vfv6s.js → index-gr8sqjpz.js} +1 -1
- package/dist/client/static/js/{index-13g17wa3.js → index-gz7kvpnm.js} +1 -1
- package/dist/client/static/js/{index-x7rajphe.js → index-h8hjcdj1.js} +2 -2
- package/dist/client/static/js/{index-jnkc9p53.js → index-j37m7pn9.js} +2 -2
- package/dist/client/static/js/{index-e6ny4gd9.js → index-mbtenbyc.js} +6 -6
- package/dist/client/static/js/{index-7pz6n3pg.js → index-nbm5r9g1.js} +2 -2
- package/dist/client/static/js/{index-8tvrzce0.js → index-nzvte8s5.js} +2 -2
- package/dist/client/static/js/index-pv4z2mp2.js +463 -0
- package/dist/client/static/js/{index-abrrqhne.js → index-pygy21w5.js} +2 -2
- package/dist/client/static/js/{index-g8rpydkr.js → index-qs4n116g.js} +2 -2
- package/dist/client/static/js/{index-seekt5k3.js → index-qwxawph7.js} +2 -2
- package/dist/client/static/js/index-rz0tz4hg.js +1 -0
- package/dist/client/static/js/{index-sng4prpr.js → index-s5vegk6q.js} +2 -2
- package/dist/client/static/js/{index-c250nzm1.js → index-t522tpxt.js} +3 -3
- package/dist/client/static/js/{index-30a8py59.js → index-taev57jw.js} +2 -2
- package/dist/client/static/js/{index-t4s10406.js → index-tb35a328.js} +2 -2
- package/dist/client/static/js/{index-fb2s080r.js → index-tc6k8qt7.js} +2 -2
- package/dist/client/static/js/{index-hcmhdpp4.js → index-tcfpzqb9.js} +36 -36
- package/dist/client/static/js/{index-45p59fxq.js → index-wbsvg1d9.js} +2 -2
- package/dist/client/static/js/{index-axtm1aq8.js → index-xw1bptp5.js} +2 -2
- package/dist/client/static/js/{index-a58rkn3f.js → index-yg083mk0.js} +6 -6
- package/dist/client/static/js/{index-tzz5gp8a.js → index-ykc14gez.js} +5 -5
- package/dist/client/static/js/index-yr3exz70.js +2 -0
- package/dist/client/static/js/{index-55pqvh82.js → index-yyjw1ty9.js} +2 -2
- package/dist/client/static/js/{index-ebf50mrs.js → index-z6y8j93w.js} +7 -7
- package/dist/client/static/js/{index-869vdnz8.js → index-zdw8bd5t.js} +2 -2
- package/dist/client/static/js/{index-5mpv57fn.js → index-zp40g8ah.js} +12 -12
- package/dist/client/static/js/{index-gkmn4y1v.js → index-zyefab6q.js} +1 -1
- package/dist/client/static/js/info-A6RAGUB7-vr5mxm6f.js +1 -0
- package/dist/client/static/js/{infoDiagram-VRGFBTTK-bxk0g0pe.js → infoDiagram-VRGFBTTK-xsar9j6v.js} +2 -2
- package/dist/client/static/js/ini-zx7x1jj1.js +1 -0
- package/dist/client/static/js/{ishikawaDiagram-OU5B5YK6-d1kdkhth.js → ishikawaDiagram-OU5B5YK6-g2rvt9jp.js} +6 -6
- package/dist/client/static/js/java-bbw6kdcr.js +1 -0
- package/dist/client/static/js/javascript-p2a8rbpw.js +1 -0
- package/dist/client/static/js/{journeyDiagram-ZHPQQLJL-cahg3zjq.js → journeyDiagram-ZHPQQLJL-q95v18zc.js} +5 -5
- package/dist/client/static/js/json-zh7m2fyg.js +1 -0
- package/dist/client/static/js/jsx-3zyyt0eh.js +1 -0
- package/dist/client/static/js/{julia-2n5k898q.js → julia-pe5vpc2m.js} +1 -1
- package/dist/client/static/js/{kanban-definition-PNTS6WVX-nq7t83en.js → kanban-definition-PNTS6WVX-2e7m7ds3.js} +11 -11
- package/dist/client/static/js/lua-d656k76a.js +1 -0
- package/dist/client/static/js/markdown-b5w681mm.js +1 -0
- package/dist/client/static/js/{mermaid.core-6nw0853j.js → mermaid.core-dzajkp0g.js} +7 -7
- package/dist/client/static/js/{mindmap-definition-NLK3R4M7-cm7ykxf2.js → mindmap-definition-NLK3R4M7-banecvf8.js} +4 -4
- package/dist/client/static/js/one-dark-pro-z965dedc.js +1 -0
- package/dist/client/static/js/one-light-capdx801.js +1 -0
- package/dist/client/static/js/packet-AYTQ26CC-ncb5xxtn.js +1 -0
- package/dist/client/static/js/{pegDiagram-GJSIUBJH-xwxz8nsq.js → pegDiagram-GJSIUBJH-6erykm1c.js} +1 -1
- package/dist/client/static/js/{perl-66vb5pz7.js → perl-cc2eqye8.js} +1 -1
- package/dist/client/static/js/{php-4e9we8am.js → php-p9bvnpsv.js} +1 -1
- package/dist/client/static/js/pie-WAS4IAKB-ff8fpvc4.js +1 -0
- package/dist/client/static/js/{pieDiagram-5QR66LMP-n910k9th.js → pieDiagram-5QR66LMP-jn1d905q.js} +3 -3
- package/dist/client/static/js/properties-3c6rmnqp.js +1 -0
- package/dist/client/static/js/python-a3x3zpv1.js +1 -0
- package/dist/client/static/js/{quadrantDiagram-O4NWA36T-dxkwxbqb.js → quadrantDiagram-O4NWA36T-sz4afnp1.js} +6 -6
- package/dist/client/static/js/r-7h3gwype.js +1 -0
- package/dist/client/static/js/radar-RG4KPBEZ-gbj4b1hf.js +1 -0
- package/dist/client/static/js/railroad-74A4TZTK-ndv5tqgr.js +1 -0
- package/dist/client/static/js/railroad-abnf-HS5TGJTU-yjzj09s1.js +1 -0
- package/dist/client/static/js/railroad-ebnf-LZEXJU2U-e6pw7e5z.js +1 -0
- package/dist/client/static/js/railroad-peg-WCYAUIDC-9734dxy4.js +1 -0
- package/dist/client/static/js/{railroadDiagram-XR7U4H2S-xb1smt7r.js → railroadDiagram-XR7U4H2S-ewzhhth2.js} +1 -1
- package/dist/client/static/js/{requirementDiagram-PLB6GJNP-6kb21b9f.js → requirementDiagram-PLB6GJNP-fcs3xd42.js} +7 -7
- package/dist/client/static/js/{ruby-v7nmcvyr.js → ruby-65s2ca5d.js} +1 -1
- package/dist/client/static/js/{rust-5ersd7be.js → rust-ec1j2hwy.js} +1 -1
- package/dist/client/static/js/{sankeyDiagram-IPEJSGJF-74z0fskw.js → sankeyDiagram-IPEJSGJF-2r829rjf.js} +4 -4
- package/dist/client/static/js/{sass-h3nvy4c8.js → sass-p6cssgq8.js} +1 -1
- package/dist/client/static/js/{scss-kvev49ga.js → scss-qfx8wt3b.js} +1 -1
- package/dist/client/static/js/{sequenceDiagram-PO4LG4MO-apn6kezn.js → sequenceDiagram-PO4LG4MO-3mnte9tv.js} +21 -21
- package/dist/client/static/js/{sizeCapture-INFHLROL-2drzcjb8.js → sizeCapture-INFHLROL-r6hf9265.js} +1 -1
- package/dist/client/static/js/sql-7a5vavm0.js +1 -0
- package/dist/client/static/js/{stateDiagram-v2-GCMORJYK-ma09vhby.js → stateDiagram-v2-GCMORJYK-hm2f0wdb.js} +6 -6
- package/dist/client/static/js/{svelte-dhspkgss.js → svelte-jz3a190v.js} +1 -1
- package/dist/client/static/js/{swimlanes-2SLR337P-f6y9xqnx.js → swimlanes-2SLR337P-s58xzqhw.js} +1 -1
- package/dist/client/static/js/swimlanesDiagram-TC7HE7FX-z4pt2kn1.js +8 -0
- package/dist/client/static/js/{timeline-definition-EJHVYXUP-zmcmvq00.js → timeline-definition-EJHVYXUP-ezm1c4pz.js} +7 -7
- package/dist/client/static/js/treeView-Q6P3EWNA-rs10d4p5.js +1 -0
- package/dist/client/static/js/treemap-WGGIJYW6-ey6c5x9f.js +1 -0
- package/dist/client/static/js/tsx-4a9b8tqf.js +1 -0
- package/dist/client/static/js/typescript-kas107wb.js +1 -0
- package/dist/client/static/js/{usecaseDiagram-POWQR4AR-wfaa019a.js → usecaseDiagram-POWQR4AR-ryvgs5ac.js} +47 -47
- package/dist/client/static/js/{vennDiagram-UO4OBE2U-46wf2pgd.js → vennDiagram-UO4OBE2U-rd5prsf1.js} +7 -7
- package/dist/client/static/js/{vue-ffngx2b3.js → vue-rv4pea8r.js} +1 -1
- package/dist/client/static/js/wardley-WFR3VGLG-kd9swrdr.js +1 -0
- package/dist/client/static/js/wardleyDiagram-VNRHLVJA-1kt8q8a4.js +78 -0
- package/dist/client/static/js/xml-3g4bdtpa.js +1 -0
- package/dist/client/static/js/{xychartDiagram-PMCCYNJV-2ba825z9.js → xychartDiagram-PMCCYNJV-q39bbgq4.js} +5 -5
- package/dist/client/static/js/yaml-ktxjn917.js +1 -0
- package/package.json +1 -1
- package/src/client/components/common/MarkdownRenderer.tsx +29 -28
- package/src/client/components/common/header-controls/index.test.tsx +1 -0
- package/src/client/components/common/header-controls/phone-row.test.tsx +1 -0
- package/src/client/components/common/header-controls/plugin-entry.test.tsx +1 -0
- package/src/client/components/common/header-controls/shell-chrome.test.tsx +1 -0
- package/src/client/components/layout/ActivityBar.tsx +2 -1
- package/src/client/components/layout/LeftActivityBar.test.ts +1 -0
- package/src/client/components/settings/Modal.tsx +1 -1
- package/src/client/components/settings/Sidebar.tsx +2 -1
- package/src/client/components/settings/apply-side-effects.ts +8 -0
- package/src/client/components/settings/categories/DictationSettings.test.tsx +152 -0
- package/src/client/components/settings/categories/DictationSettings.tsx +76 -0
- package/src/client/components/settings/categories/VoiceSettings.tsx +77 -0
- package/src/client/components/settings/categories/dictation-settings/CaptureSection.tsx +153 -0
- package/src/client/components/settings/categories/dictation-settings/EngineSection.tsx +123 -0
- package/src/client/components/settings/categories/dictation-settings/ExternalSection.tsx +221 -0
- package/src/client/components/settings/categories/dictation-settings/LanguageSection.tsx +73 -0
- package/src/client/components/settings/categories/panel-plugins/InstallForm.tsx +24 -17
- package/src/client/components/settings/categories/panel-plugins/Registries.test.tsx +164 -0
- package/src/client/components/settings/categories/panel-plugins/Registries.tsx +180 -0
- package/src/client/components/settings/categories/panel-plugins/Section.tsx +15 -6
- package/src/client/components/settings/categories/voice-settings/SpeechSettings.test.tsx +112 -0
- package/src/client/components/settings/categories/voice-settings/SpeechSettings.tsx +84 -0
- package/src/client/components/settings/categories/voice-settings/groups.test.ts +23 -0
- package/src/client/components/settings/categories/voice-settings/groups.ts +48 -0
- package/src/client/components/settings/categories/voice-settings/speech/AutoplaySection.tsx +49 -0
- package/src/client/components/settings/categories/voice-settings/speech/EndpointSection.tsx +161 -0
- package/src/client/components/settings/categories/voice-settings/speech/EngineSection.tsx +108 -0
- package/src/client/components/settings/categories/voice-settings/speech/TestSection.tsx +56 -0
- package/src/client/components/settings/categories/voice-settings/speech/VoiceSection.tsx +157 -0
- package/src/client/components/settings/categories/voice-settings/speech/styles.ts +15 -0
- package/src/client/components/settings/category-content.tsx +3 -0
- package/src/client/components/workspace/chat-timeline/AiMessageFooter.speech.test.tsx +140 -0
- package/src/client/components/workspace/chat-timeline/AiMessageFooter.tsx +41 -97
- package/src/client/components/workspace/chat-timeline/AiMessageFooterSheet.tsx +143 -0
- package/src/client/components/workspace/chat-timeline/MessageItem.tsx +5 -1
- package/src/client/components/workspace/chat-timeline/MessageList.tsx +1 -0
- package/src/client/components/workspace/chat-timeline/RunFooter.tsx +1 -0
- package/src/client/components/workspace/chat-timeline/SpeechButton.tsx +110 -0
- package/src/client/components/workspace/chat-timeline/chat-input/AccessDropdown.test.ts +26 -10
- package/src/client/components/workspace/chat-timeline/chat-input/AccessDropdown.tsx +13 -8
- package/src/client/components/workspace/chat-timeline/chat-input/AttachmentToolbar.tsx +9 -2
- package/src/client/components/workspace/chat-timeline/chat-input/ComposerRows.tsx +6 -0
- package/src/client/components/workspace/chat-timeline/chat-input/ModeToggles.tsx +18 -7
- package/src/client/components/workspace/chat-timeline/chat-input/SessionModeDropdown.tsx +4 -2
- package/src/client/components/workspace/chat-timeline/chat-input/ThinkingLevelDropdown.tsx +4 -4
- package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.tsx +19 -11
- package/src/client/components/workspace/chat-timeline/chat-input/WaitingDependencyPicker.tsx +8 -6
- package/src/client/components/workspace/chat-timeline/chat-input/index.tsx +38 -30
- package/src/client/components/workspace/chat-timeline/chat-input/narrow.test.tsx +185 -0
- package/src/client/components/workspace/chat-timeline/chat-input/paste-attach.test.tsx +194 -0
- package/src/client/components/workspace/chat-timeline/index.tsx +4 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/index.tsx +5 -11
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Bash.test.ts +10 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Edit.tsx +2 -7
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/task-rows.ts +6 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/registry.test.ts +38 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/registry.ts +10 -2
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/tool-input.ts +5 -5
- package/src/client/hooks/chat/composer/attachments.ts +18 -2
- package/src/client/hooks/chat/composer/capture.test.ts +282 -0
- package/src/client/hooks/chat/composer/capture.ts +166 -0
- package/src/client/hooks/chat/composer/dictation-settings.ts +53 -0
- package/src/client/hooks/chat/composer/narrow.test.ts +130 -0
- package/src/client/hooks/chat/composer/narrow.ts +82 -0
- package/src/client/hooks/chat/composer/paste-attachments.test.ts +215 -0
- package/src/client/hooks/chat/composer/paste-attachments.ts +173 -0
- package/src/client/hooks/chat/composer/pipeline.ts +16 -3
- package/src/client/hooks/chat/composer/speech-to-text.test.tsx +314 -0
- package/src/client/hooks/chat/composer/speech-to-text.ts +158 -134
- package/src/client/hooks/chat/composer/voice-input.ts +24 -9
- package/src/client/hooks/chat/timeline/scroll.test.ts +44 -3
- package/src/client/hooks/chat/timeline/scroll.ts +31 -14
- package/src/client/hooks/chat/timeline/send-helpers.ts +3 -0
- package/src/client/hooks/chat/timeline/send.ts +5 -1
- package/src/client/hooks/settings/dictation.ts +153 -0
- package/src/client/hooks/settings/speech.ts +170 -0
- package/src/client/hooks/tts/provider.tsx +50 -0
- package/src/client/hooks/tts/tts-context.ts +39 -0
- package/src/client/hooks/tts/use-speech-autoplay.test.tsx +122 -0
- package/src/client/hooks/tts/use-speech-autoplay.ts +106 -0
- package/src/client/hooks/tts/use-tts-player.ts +33 -0
- package/src/client/hooks/ui/markdown-hydration.test.tsx +83 -0
- package/src/client/hooks/ui/markdown-hydration.ts +31 -0
- package/src/client/hooks/ui/markdown-render.ts +119 -0
- package/src/client/hooks/workspace/journal-diff.ts +8 -1
- package/src/client/hooks/workspace/panel-actions.ts +184 -0
- package/src/client/hooks/workspace/panel-registry.ts +6 -139
- package/src/client/hooks/workspace/panel-visibility-menu.ts +2 -1
- package/src/client/lib/plugins/bootstrap.test.ts +1 -0
- package/src/client/lib/tts/player.test.ts +103 -0
- package/src/client/lib/tts/player.ts +213 -0
- package/src/client/tailwind.css +11 -0
- package/src/server/lib/changes/capture-bash.server.ts +6 -3
- package/src/server/lib/changes/capture-fs.server.ts +2 -2
- package/src/server/lib/changes/capture-races.test.ts +33 -1
- package/src/server/lib/changes/capture-scan.test.ts +1 -1
- package/src/server/lib/changes/capture-test-util.ts +1 -1
- package/src/server/lib/changes/capture-types.ts +1 -1
- package/src/server/lib/changes/capture.server.ts +1 -1
- package/src/server/lib/changes/journal-read.server.ts +21 -0
- package/src/server/lib/changes/reader.server.ts +92 -14
- package/src/server/lib/changes/reader.test.ts +99 -0
- package/src/server/lib/changes/records.ts +2 -0
- package/src/server/lib/dictation/capability.server.test.ts +113 -0
- package/src/server/lib/dictation/capability.server.ts +57 -0
- package/src/server/lib/dictation/engines/adapter.ts +147 -0
- package/src/server/lib/dictation/engines/adapters.test.ts +215 -0
- package/src/server/lib/dictation/engines/deepgram.ts +77 -0
- package/src/server/lib/dictation/engines/elevenlabs.ts +44 -0
- package/src/server/lib/dictation/engines/index.ts +55 -0
- package/src/server/lib/dictation/engines/openai.ts +51 -0
- package/src/server/lib/dictation/language.server.test.ts +21 -22
- package/src/server/lib/dictation/language.server.ts +16 -19
- package/src/server/lib/dictation/omp-stt-worker.test.ts +183 -0
- package/src/server/lib/dictation/omp-stt-worker.ts +130 -78
- package/src/server/lib/dictation/settings.server.ts +74 -0
- package/src/server/lib/dictation/speech-frames.test.ts +125 -0
- package/src/server/lib/dictation/speech-frames.ts +146 -0
- package/src/server/lib/dictation/worker-process.ts +122 -0
- package/src/server/lib/harness/acp/calls.ts +20 -0
- package/src/server/lib/harness/acp/client-capabilities.ts +8 -1
- package/src/server/lib/harness/acp/client-fs.ts +17 -5
- package/src/server/lib/harness/acp/client-initialize.test.ts +32 -1
- package/src/server/lib/harness/acp/client-initialize.ts +51 -6
- package/src/server/lib/harness/acp/client-requests.ts +49 -0
- package/src/server/lib/harness/acp/client.ts +33 -36
- package/src/server/lib/harness/acp/frames-rows.test.ts +144 -0
- package/src/server/lib/harness/acp/frames-tool-shapes.test.ts +238 -0
- package/src/server/lib/harness/acp/frames-v2.test.ts +21 -0
- package/src/server/lib/harness/acp/frames.test.ts +3 -15
- package/src/server/lib/harness/acp/frames.ts +43 -67
- package/src/server/lib/harness/acp/grants.ts +20 -5
- package/src/server/lib/harness/acp/mapper.test.ts +40 -1
- package/src/server/lib/harness/acp/mapper.ts +69 -9
- package/src/server/lib/harness/acp/message-rows.ts +219 -0
- package/src/server/lib/harness/acp/prompt.ts +20 -2
- package/src/server/lib/harness/acp/protocol.ts +24 -0
- package/src/server/lib/harness/acp/replay-window.test.ts +66 -0
- package/src/server/lib/harness/acp/replay.ts +33 -8
- package/src/server/lib/harness/acp/session-addressing.test.ts +99 -0
- package/src/server/lib/harness/acp/session-approvals.ts +4 -0
- package/src/server/lib/harness/acp/session-cancel-policy.test.ts +86 -0
- package/src/server/lib/harness/acp/session-close.test.ts +89 -0
- package/src/server/lib/harness/acp/session-config.ts +8 -3
- package/src/server/lib/harness/acp/session-handshake.ts +6 -0
- package/src/server/lib/harness/acp/session-inbound.ts +126 -0
- package/src/server/lib/harness/acp/session-intake.ts +9 -2
- package/src/server/lib/harness/acp/session-lifecycle.ts +25 -0
- package/src/server/lib/harness/acp/session-notifications.ts +36 -0
- package/src/server/lib/harness/acp/session-permissions.ts +22 -1
- package/src/server/lib/harness/acp/session-requests.ts +19 -1
- package/src/server/lib/harness/acp/session-stop.ts +54 -0
- package/src/server/lib/harness/acp/session-wiring.ts +1 -0
- package/src/server/lib/harness/acp/session.test-util.ts +8 -3
- package/src/server/lib/harness/acp/session.ts +75 -75
- package/src/server/lib/harness/acp/stdio.ts +8 -1
- package/src/server/lib/harness/acp/subagent-frames.test.ts +82 -0
- package/src/server/lib/harness/acp/subagent-frames.ts +124 -0
- package/src/server/lib/harness/acp/subagents.test.ts +124 -0
- package/src/server/lib/harness/acp/subagents.ts +182 -0
- package/src/server/lib/harness/acp/tool-calls.ts +115 -45
- package/src/server/lib/harness/acp/tool-identity.test.ts +8 -0
- package/src/server/lib/harness/acp/tool-identity.ts +13 -1
- package/src/server/lib/harness/acp/tool-shape.ts +99 -0
- package/src/server/lib/harness/acp/turn.test.ts +1 -0
- package/src/server/lib/harness/acp/turn.ts +4 -1
- package/src/server/lib/harness/acp/v2.test.ts +21 -1
- package/src/server/lib/harness/acp/v2.ts +6 -1
- package/src/server/lib/lifecycle/paths.ts +22 -0
- package/src/server/lib/omp/session/changes-patch.test.ts +120 -0
- package/src/server/lib/omp/session/changes-patch.ts +190 -0
- package/src/server/lib/omp/session/changes.test.ts +55 -61
- package/src/server/lib/omp/session/changes.ts +79 -127
- package/src/server/lib/omp/session/merge-stored.ts +2 -0
- package/src/server/lib/panels/catalog-offers.server.ts +1 -1
- package/src/server/lib/panels/catalog.server.test.ts +71 -2
- package/src/server/lib/panels/catalog.server.ts +80 -0
- package/src/server/lib/panels/install.server.test.ts +15 -0
- package/src/server/lib/panels/install.server.ts +7 -0
- package/src/server/lib/panels/manifest.test.ts +1 -76
- package/src/server/lib/panels/manifest.ts +3 -60
- package/src/server/lib/panels/marketplace-catalog.server.test.ts +154 -0
- package/src/server/lib/panels/marketplace-catalog.server.ts +131 -0
- package/src/server/lib/panels/offers.server.test.ts +5 -5
- package/src/server/lib/panels/offers.server.ts +20 -2
- package/src/server/lib/panels/registries.server.test.ts +216 -0
- package/src/server/lib/panels/registries.server.ts +118 -0
- package/src/server/lib/panels/registry-cache.server.ts +104 -0
- package/src/server/lib/panels/registry-refresh.server.ts +195 -0
- package/src/server/lib/panels/registry.server.test.ts +2 -2
- package/src/server/lib/panels/registry.server.ts +19 -1
- package/src/server/lib/panels/seed.server.ts +4 -1
- package/src/server/lib/tts/engines/adapter.ts +133 -0
- package/src/server/lib/tts/engines/adapters.test.ts +129 -0
- package/src/server/lib/tts/engines/deepgram.ts +43 -0
- package/src/server/lib/tts/engines/elevenlabs.ts +53 -0
- package/src/server/lib/tts/engines/index.ts +75 -0
- package/src/server/lib/tts/engines/openai.ts +52 -0
- package/src/server/lib/tts/engines/xai.ts +44 -0
- package/src/server/lib/tts/local.server.ts +160 -0
- package/src/server/lib/tts/settings.server.ts +103 -0
- package/src/server/routes/dictation/ws.ts +99 -27
- package/src/server/routes/index.ts +2 -0
- package/src/server/routes/panels/install-route.test.ts +110 -0
- package/src/server/routes/panels/install.ts +82 -3
- package/src/server/routes/sessions/index.ts +5 -0
- package/src/server/routes/sessions/local-image.test.ts +94 -0
- package/src/server/routes/sessions/local-image.ts +141 -0
- package/src/server/routes/settings/dictation.test.ts +139 -0
- package/src/server/routes/settings/dictation.ts +86 -0
- package/src/server/routes/settings/index.ts +4 -0
- package/src/server/routes/settings/speech.test.ts +156 -0
- package/src/server/routes/settings/speech.ts +98 -0
- package/src/server/routes/tts/index.ts +11 -0
- package/src/server/routes/tts/speak.test.ts +160 -0
- package/src/server/routes/tts/speak.ts +87 -0
- package/src/shared/lib/chat/attachments.ts +17 -3
- package/src/shared/lib/chat/composer/attachment-labels.test.ts +154 -0
- package/src/shared/lib/chat/composer/attachment-labels.ts +166 -0
- package/src/shared/lib/chat/omp/subagent-card-fold.test.ts +75 -0
- package/src/shared/lib/chat/timeline/changed-files.test.ts +13 -0
- package/src/shared/lib/chat/timeline/changed-files.ts +4 -2
- package/src/shared/lib/chat/timeline/local-image.test.ts +88 -0
- package/src/shared/lib/chat/timeline/local-image.ts +110 -0
- package/src/shared/lib/chat/timeline/omp-callbacks.ts +3 -2
- package/src/shared/lib/chat/timeline/run-signals.ts +2 -2
- package/src/shared/lib/chat/timeline/stream-callbacks.ts +8 -6
- package/src/shared/lib/chat/timeline/stream-coalescer.ts +7 -0
- package/src/shared/lib/chat/timeline/stream.test.ts +3 -1
- package/src/shared/lib/chat/timeline/tool-verbs.test.ts +5 -0
- package/src/shared/lib/chat/timeline/tool-verbs.ts +3 -1
- package/src/shared/lib/chat/todo/parser.test.ts +54 -0
- package/src/shared/lib/chat/todo/parser.ts +56 -0
- package/src/shared/lib/chat/tool/tool-aliases.test.ts +37 -0
- package/src/shared/lib/chat/tool/tool-aliases.ts +75 -0
- package/src/shared/lib/chat/tool/tool-input-path.test.ts +44 -0
- package/src/shared/lib/chat/tool/tool-input-path.ts +47 -0
- package/src/shared/lib/dictation/capability.ts +32 -0
- package/src/shared/lib/dictation/constraints.test.ts +41 -0
- package/src/shared/lib/dictation/constraints.ts +48 -0
- package/src/shared/lib/dictation/engines.test.ts +117 -0
- package/src/shared/lib/dictation/engines.ts +190 -0
- package/src/shared/lib/dictation/gate.test.ts +118 -0
- package/src/shared/lib/dictation/gate.ts +85 -0
- package/src/shared/lib/dictation/languages.test.ts +88 -0
- package/src/shared/lib/dictation/languages.ts +90 -0
- package/src/shared/lib/dictation/models.ts +9 -5
- package/src/shared/lib/dictation/protocol.ts +74 -34
- package/src/shared/lib/dictation/settings.test.ts +94 -0
- package/src/shared/lib/dictation/settings.ts +111 -0
- package/src/shared/lib/dictation/wav.test.ts +66 -0
- package/src/shared/lib/dictation/wav.ts +48 -0
- package/src/shared/lib/fs/journal-unavailable.test.ts +30 -0
- package/src/shared/lib/fs/journal-unavailable.ts +35 -0
- package/src/shared/lib/icons/tint-hues.generated.ts +35 -35
- package/src/shared/lib/net/base-url.test.ts +25 -0
- package/src/shared/lib/net/base-url.ts +29 -0
- package/src/shared/lib/omp/config/schema-extras.ts +9 -8
- package/src/shared/lib/omp/session/parse-message-blocks.ts +2 -2
- package/src/shared/lib/panels/plugin-repo.test.ts +113 -0
- package/src/shared/lib/panels/plugin-repo.ts +149 -0
- package/src/shared/lib/settings/defaults.ts +4 -0
- package/src/shared/lib/tts/capability.ts +16 -0
- package/src/shared/lib/tts/engines.test.ts +79 -0
- package/src/shared/lib/tts/engines.ts +313 -0
- package/src/shared/lib/tts/settings.test.ts +56 -0
- package/src/shared/lib/tts/settings.ts +108 -0
- package/src/shared/lib/tts/speakable.test.ts +76 -0
- package/src/shared/lib/tts/speakable.ts +179 -0
- package/src/shared/types/chat.ts +8 -1
- package/src/shared/types/panels-registry.ts +32 -0
- package/src/shared/types/panels.ts +23 -0
- package/src/shared/types/session-changes.ts +15 -1
- package/src/shared/types/settings/state.ts +25 -0
- package/src/test-support/pristine-globals.ts +5 -0
- package/dist/client/static/js/ImageView-pr4h38hb.js +0 -1
- package/dist/client/static/js/LayoutWrapper-n4tzhjes.js +0 -2
- package/dist/client/static/js/MergeDiffView-0t15nh9f.js +0 -1
- package/dist/client/static/js/Modal-77hgx4dw.js +0 -59
- package/dist/client/static/js/PdfView-gzxhvxe8.js +0 -1
- package/dist/client/static/js/SessionsView-2tdqrvk0.js +0 -1
- package/dist/client/static/js/architecture-7GRP2DOG-zs15nydj.js +0 -1
- package/dist/client/static/js/architectureDiagram-NJMV4G6O-heep78p6.js +0 -36
- package/dist/client/static/js/bash-8d3wrx5c.js +0 -1
- package/dist/client/static/js/c-rn3z0csz.js +0 -1
- package/dist/client/static/js/cpp-99ws9nak.js +0 -1
- package/dist/client/static/js/css-drfs4n12.js +0 -1
- package/dist/client/static/js/css-narcr42w.js +0 -1
- package/dist/client/static/js/cynefin-OW5HDTMX-p3y1b4ap.js +0 -1
- package/dist/client/static/js/dagre-6A5THRUB-gk0gp124.js +0 -4
- package/dist/client/static/js/eventmodeling-NTZA5JFV-sx2cwkz3.js +0 -1
- package/dist/client/static/js/flowDiagram-KWPJA3E3-dsc17mty.js +0 -1
- package/dist/client/static/js/gitGraph-4MIJSDKK-yqhbscsd.js +0 -1
- package/dist/client/static/js/graphql-tr0jcndy.js +0 -1
- package/dist/client/static/js/html-n8fdvrdk.js +0 -1
- package/dist/client/static/js/index-1hb8fvw9.js +0 -1
- package/dist/client/static/js/index-9a78xmkk.js +0 -462
- package/dist/client/static/js/index-b2cs4c51.js +0 -4
- package/dist/client/static/js/index-fryp0kgf.js +0 -2
- package/dist/client/static/js/index-qek9mt5w.js +0 -1
- package/dist/client/static/js/index-rq4dk4tp.js +0 -4
- package/dist/client/static/js/index-vnv9z0a1.js +0 -1
- package/dist/client/static/js/index-xr4hjv01.js +0 -2
- package/dist/client/static/js/info-A6RAGUB7-0sd3zzgg.js +0 -1
- package/dist/client/static/js/ini-tnaw7zjy.js +0 -1
- package/dist/client/static/js/java-m4dpc2vw.js +0 -1
- package/dist/client/static/js/javascript-8y26t991.js +0 -1
- package/dist/client/static/js/json-azm7bdqd.js +0 -1
- package/dist/client/static/js/jsx-p9j1k773.js +0 -1
- package/dist/client/static/js/lua-hbm9rhz9.js +0 -1
- package/dist/client/static/js/markdown-tk3cd3vs.js +0 -1
- package/dist/client/static/js/one-dark-pro-2cdc2nk7.js +0 -1
- package/dist/client/static/js/one-light-bt6z4jf0.js +0 -1
- package/dist/client/static/js/packet-AYTQ26CC-13w2v5bb.js +0 -1
- package/dist/client/static/js/pie-WAS4IAKB-swtnysgn.js +0 -1
- package/dist/client/static/js/properties-6911ckw7.js +0 -1
- package/dist/client/static/js/python-44cvj250.js +0 -1
- package/dist/client/static/js/r-t3sepzm4.js +0 -1
- package/dist/client/static/js/radar-RG4KPBEZ-vtvxkx55.js +0 -1
- package/dist/client/static/js/railroad-74A4TZTK-5sp2d63r.js +0 -1
- package/dist/client/static/js/railroad-abnf-HS5TGJTU-kg706fan.js +0 -1
- package/dist/client/static/js/railroad-ebnf-LZEXJU2U-4ra1gzx5.js +0 -1
- package/dist/client/static/js/railroad-peg-WCYAUIDC-hms3zpjm.js +0 -1
- package/dist/client/static/js/sql-zdkawqx3.js +0 -1
- package/dist/client/static/js/swimlanesDiagram-TC7HE7FX-3dwas56m.js +0 -8
- package/dist/client/static/js/treeView-Q6P3EWNA-7t5k6rs2.js +0 -1
- package/dist/client/static/js/treemap-WGGIJYW6-w56ry3bg.js +0 -1
- package/dist/client/static/js/tsx-b7eabr17.js +0 -1
- package/dist/client/static/js/typescript-nnkvhwfy.js +0 -1
- package/dist/client/static/js/wardley-WFR3VGLG-rtjb9kgv.js +0 -1
- package/dist/client/static/js/wardleyDiagram-VNRHLVJA-10ph3bzq.js +0 -78
- package/dist/client/static/js/xml-xy1tw6b2.js +0 -1
- package/dist/client/static/js/yaml-0fexqg2d.js +0 -1
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The composer's dictation pipeline, from the microphone to the socket.
|
|
8
|
+
*
|
|
9
|
+
* The reported bug: in the macOS shell the mic button recorded for as long as
|
|
10
|
+
* the user held it and then said "No speech was detected in that recording."
|
|
11
|
+
* The capture unit had failed to start (`BaseAudioCaptureUnit::captureFailed`
|
|
12
|
+
* ends the track) and every sample was zero, so the sentence blamed the speaker
|
|
13
|
+
* for a dead device. Two things had to change and both are pinned here:
|
|
14
|
+
*
|
|
15
|
+
* - the utterance is refused as NO AUDIO when it is bit-exact zeros, before the
|
|
16
|
+
* silence floor can answer "no speech";
|
|
17
|
+
* - a real capture still reaches the socket as ONE 16 kHz PCM16 frame, which is
|
|
18
|
+
* the hand-off this file's fake `AudioContext` exists to prove — the device
|
|
19
|
+
* rate (48 kHz here) is resampled on the way out, not assumed.
|
|
20
|
+
*
|
|
21
|
+
* `AudioContext`, `getUserMedia` and `WebSocket` are fakes because `bun test` has
|
|
22
|
+
* no microphone; everything between them is the shipped code.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, test } from 'bun:test';
|
|
26
|
+
import { Window } from 'happy-dom';
|
|
27
|
+
import { h, render } from 'preact';
|
|
28
|
+
import { act } from 'preact/test-utils';
|
|
29
|
+
|
|
30
|
+
import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
|
|
31
|
+
import type { UseSpeechToTextReturn } from '@/client/hooks/chat/composer/speech-to-text';
|
|
32
|
+
import type { DictationConfig } from '@/shared/lib/dictation/settings';
|
|
33
|
+
|
|
34
|
+
const CONFIG: DictationConfig = {
|
|
35
|
+
engine: 'omp',
|
|
36
|
+
model: '',
|
|
37
|
+
language: 'en',
|
|
38
|
+
baseUrl: '',
|
|
39
|
+
prompt: '',
|
|
40
|
+
deviceId: '',
|
|
41
|
+
minMs: 300,
|
|
42
|
+
maxMs: 120_000,
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const DEVICE_RATE = 48_000;
|
|
46
|
+
/** 0.5 s of a 220 Hz tone at the device rate: 24 000 samples, well over `minMs`. */
|
|
47
|
+
const TONE = Float32Array.from({ length: DEVICE_RATE / 2 }, (_, i) => Math.sin((2 * Math.PI * 220 * i) / DEVICE_RATE) * 0.2);
|
|
48
|
+
const ZEROS = new Float32Array(DEVICE_RATE / 2);
|
|
49
|
+
|
|
50
|
+
type ProcessHandler = (event: { inputBuffer: { getChannelData: () => Float32Array } }) => void;
|
|
51
|
+
|
|
52
|
+
/** The one node the test drives: whatever the hook sets as `onaudioprocess`. */
|
|
53
|
+
class FakeProcessor {
|
|
54
|
+
static last: FakeProcessor | null = null;
|
|
55
|
+
onaudioprocess: ProcessHandler | null = null;
|
|
56
|
+
constructor() {
|
|
57
|
+
FakeProcessor.last = this;
|
|
58
|
+
}
|
|
59
|
+
connect() {}
|
|
60
|
+
disconnect() {}
|
|
61
|
+
/** One render quantum of `samples`. */
|
|
62
|
+
deliver(samples: Float32Array) {
|
|
63
|
+
this.onaudioprocess?.({ inputBuffer: { getChannelData: () => samples } });
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
class FakeNode {
|
|
68
|
+
connect() {}
|
|
69
|
+
disconnect() {}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
class FakeAudioContext {
|
|
73
|
+
static last: FakeAudioContext | null = null;
|
|
74
|
+
readonly sampleRate = DEVICE_RATE;
|
|
75
|
+
readonly state = 'running';
|
|
76
|
+
readonly destination = new FakeNode();
|
|
77
|
+
closed = false;
|
|
78
|
+
constructor() {
|
|
79
|
+
FakeAudioContext.last = this;
|
|
80
|
+
}
|
|
81
|
+
async resume() {}
|
|
82
|
+
createMediaStreamSource() {
|
|
83
|
+
return new FakeNode();
|
|
84
|
+
}
|
|
85
|
+
createScriptProcessor() {
|
|
86
|
+
return new FakeProcessor();
|
|
87
|
+
}
|
|
88
|
+
createGain() {
|
|
89
|
+
return Object.assign(new FakeNode(), { gain: { value: 1 } });
|
|
90
|
+
}
|
|
91
|
+
async close() {
|
|
92
|
+
this.closed = true;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
class FakeTrack {
|
|
97
|
+
readyState = 'live';
|
|
98
|
+
stop() {
|
|
99
|
+
this.readyState = 'ended';
|
|
100
|
+
}
|
|
101
|
+
addEventListener() {}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** What the hook sends, and what the server would answer. */
|
|
105
|
+
class FakeSocket {
|
|
106
|
+
static last: FakeSocket | null = null;
|
|
107
|
+
readonly url: string;
|
|
108
|
+
readonly sent: ArrayBuffer[] = [];
|
|
109
|
+
onopen: (() => void) | null = null;
|
|
110
|
+
onmessage: ((event: { data: string }) => void) | null = null;
|
|
111
|
+
onerror: (() => void) | null = null;
|
|
112
|
+
onclose: (() => void) | null = null;
|
|
113
|
+
closed = false;
|
|
114
|
+
binaryType = 'blob';
|
|
115
|
+
|
|
116
|
+
constructor(url: string) {
|
|
117
|
+
this.url = url;
|
|
118
|
+
FakeSocket.last = this;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
send(data: ArrayBuffer) {
|
|
122
|
+
this.sent.push(data);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** The handshake completing; the hook sends the utterance from `onopen`. */
|
|
126
|
+
open() {
|
|
127
|
+
this.onopen?.();
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
close() {
|
|
131
|
+
this.closed = true;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** The server's side of one frame. */
|
|
135
|
+
answer(frame: unknown) {
|
|
136
|
+
this.onmessage?.({ data: JSON.stringify(frame) });
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const realAudioContext = globalThis.AudioContext;
|
|
141
|
+
const realWebSocket = globalThis.WebSocket;
|
|
142
|
+
const realMediaDevices = Object.getOwnPropertyDescriptor(navigator, 'mediaDevices');
|
|
143
|
+
let permissionError: DOMException | null = null;
|
|
144
|
+
|
|
145
|
+
function installFakes() {
|
|
146
|
+
FakeProcessor.last = null;
|
|
147
|
+
FakeAudioContext.last = null;
|
|
148
|
+
FakeSocket.last = null;
|
|
149
|
+
globalThis.AudioContext = FakeAudioContext as unknown as typeof AudioContext;
|
|
150
|
+
globalThis.WebSocket = FakeSocket as unknown as typeof WebSocket;
|
|
151
|
+
Object.defineProperty(navigator, 'mediaDevices', {
|
|
152
|
+
configurable: true,
|
|
153
|
+
value: {
|
|
154
|
+
getUserMedia: async () => {
|
|
155
|
+
if (permissionError) throw permissionError;
|
|
156
|
+
return { getTracks: () => [new FakeTrack()], getAudioTracks: () => [new FakeTrack()] };
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function restoreFakes() {
|
|
163
|
+
globalThis.AudioContext = realAudioContext;
|
|
164
|
+
globalThis.WebSocket = realWebSocket;
|
|
165
|
+
if (realMediaDevices) Object.defineProperty(navigator, 'mediaDevices', realMediaDevices);
|
|
166
|
+
else delete (navigator as unknown as { mediaDevices?: unknown }).mediaDevices;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
let container: HTMLElement | undefined;
|
|
170
|
+
let api: UseSpeechToTextReturn | null = null;
|
|
171
|
+
let results: string[] = [];
|
|
172
|
+
let useSpeechToText: (options: { onResult: (text: string) => void; config: DictationConfig }) => UseSpeechToTextReturn;
|
|
173
|
+
|
|
174
|
+
beforeAll(async () => {
|
|
175
|
+
// Dynamic on purpose: these modules capture `document`/`navigator` when they
|
|
176
|
+
// load, and a static import is evaluated before any hook below runs — the
|
|
177
|
+
// window this file installs would arrive too late (the documented exception in
|
|
178
|
+
// `use-draft.test.ts`).
|
|
179
|
+
installDomGlobals(new Window({ url: 'http://127.0.0.1/' }));
|
|
180
|
+
({ useSpeechToText } = await import('@/client/hooks/chat/composer/speech-to-text'));
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
beforeEach(() => {
|
|
184
|
+
api = null;
|
|
185
|
+
results = [];
|
|
186
|
+
permissionError = null;
|
|
187
|
+
installFakes();
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
afterEach(() => {
|
|
191
|
+
if (container) render(null, container);
|
|
192
|
+
container?.remove();
|
|
193
|
+
container = undefined;
|
|
194
|
+
restoreFakes();
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
afterAll(() => {
|
|
198
|
+
restoreDomGlobals();
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
/** Mount the hook and hand back its latest API. */
|
|
202
|
+
async function mount() {
|
|
203
|
+
function Probe() {
|
|
204
|
+
api = useSpeechToText({ onResult: (text) => results.push(text), config: CONFIG });
|
|
205
|
+
return null;
|
|
206
|
+
}
|
|
207
|
+
container = document.body.appendChild(document.createElement('div'));
|
|
208
|
+
await act(async () => {
|
|
209
|
+
render(h(Probe, null), container!);
|
|
210
|
+
});
|
|
211
|
+
return api!;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** Let the capture's promises settle: `getUserMedia` and `resume` are awaited. */
|
|
215
|
+
async function flush() {
|
|
216
|
+
await act(async () => {
|
|
217
|
+
for (let i = 0; i < 4; i++) await Promise.resolve();
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/** Press the mic, feed one quantum of `chunk`, and release it. */
|
|
222
|
+
async function record(chunk: Float32Array) {
|
|
223
|
+
await act(async () => {
|
|
224
|
+
api!.startListening();
|
|
225
|
+
});
|
|
226
|
+
await flush();
|
|
227
|
+
expect(api!.isListening).toBe(true);
|
|
228
|
+
await act(async () => {
|
|
229
|
+
FakeProcessor.last!.deliver(chunk);
|
|
230
|
+
});
|
|
231
|
+
await act(async () => {
|
|
232
|
+
api!.stopListening();
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
describe('useSpeechToText', () => {
|
|
237
|
+
test('a real capture is sent as ONE 16 kHz PCM16 frame', async () => {
|
|
238
|
+
await mount();
|
|
239
|
+
await record(TONE);
|
|
240
|
+
|
|
241
|
+
const socket = FakeSocket.last!;
|
|
242
|
+
// Nothing is sent before the socket is open.
|
|
243
|
+
expect(socket.sent).toHaveLength(0);
|
|
244
|
+
await act(async () => {
|
|
245
|
+
socket.open();
|
|
246
|
+
});
|
|
247
|
+
expect(socket.sent).toHaveLength(1);
|
|
248
|
+
// 0.5 s at the device rate becomes 0.5 s at the rate every engine takes.
|
|
249
|
+
expect(socket.sent[0].byteLength).toBe(16_000 * 2 * 0.5);
|
|
250
|
+
// The query string carries the engine and language, never the audio.
|
|
251
|
+
expect(socket.url).toContain('engine=omp');
|
|
252
|
+
expect(socket.url).toContain('language=en');
|
|
253
|
+
|
|
254
|
+
await act(async () => {
|
|
255
|
+
socket.answer({ type: 'final', text: 'hello there' });
|
|
256
|
+
});
|
|
257
|
+
expect(results).toEqual(['hello there']);
|
|
258
|
+
expect(api!.isTranscribing).toBe(false);
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
test('a dead capture never opens a socket and names the device', async () => {
|
|
262
|
+
await mount();
|
|
263
|
+
await record(ZEROS);
|
|
264
|
+
|
|
265
|
+
expect(FakeSocket.last).toBeNull();
|
|
266
|
+
expect(api!.error).toBe('The microphone sent no audio — check the input device in Settings → Dictation.');
|
|
267
|
+
expect(api!.isTranscribing).toBe(false);
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
test('a quiet room is still "no speech", not a dead device', async () => {
|
|
271
|
+
await mount();
|
|
272
|
+
// The measured floor of a working microphone in silence (~0.0009 RMS).
|
|
273
|
+
await record(Float32Array.from({ length: DEVICE_RATE / 2 }, (_, i) => (i % 2 ? 1 : -1) * 0.0009));
|
|
274
|
+
|
|
275
|
+
expect(FakeSocket.last).toBeNull();
|
|
276
|
+
expect(api!.error).toBe('No speech was detected in that recording.');
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
test('a tap under the minimum is refused before anything is sent', async () => {
|
|
280
|
+
await mount();
|
|
281
|
+
await record(Float32Array.from({ length: 1_600 }, () => 0.2));
|
|
282
|
+
|
|
283
|
+
expect(FakeSocket.last).toBeNull();
|
|
284
|
+
expect(api!.error).toBe('That was too short to transcribe (under 300 ms).');
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
test('a refused microphone keeps its own sentence', async () => {
|
|
288
|
+
permissionError = new DOMException('denied', 'NotAllowedError');
|
|
289
|
+
await mount();
|
|
290
|
+
await act(async () => {
|
|
291
|
+
api!.startListening();
|
|
292
|
+
});
|
|
293
|
+
await flush();
|
|
294
|
+
|
|
295
|
+
expect(api!.error).toBe('Microphone permission denied.');
|
|
296
|
+
expect(api!.isListening).toBe(false);
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
test('a server refusal is shown, and the capture is released', async () => {
|
|
300
|
+
await mount();
|
|
301
|
+
await record(TONE);
|
|
302
|
+
const socket = FakeSocket.last!;
|
|
303
|
+
await act(async () => {
|
|
304
|
+
socket.open();
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
await act(async () => {
|
|
308
|
+
socket.answer({ type: 'error', error: 'STT worker exited.', retryable: true });
|
|
309
|
+
});
|
|
310
|
+
expect(api!.error).toBe('STT worker exited.');
|
|
311
|
+
expect(api!.isTranscribing).toBe(false);
|
|
312
|
+
expect(FakeAudioContext.last?.closed).toBe(true);
|
|
313
|
+
});
|
|
314
|
+
});
|
|
@@ -5,33 +5,41 @@
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Composer dictation: capture the browser's microphone, hand the utterance to
|
|
8
|
-
* Kabmo's dictation socket, and insert what
|
|
8
|
+
* Kabmo's dictation socket, and insert what the configured engine returns.
|
|
9
9
|
*
|
|
10
|
-
* Audio is captured as raw PCM16LE mono @16 kHz — the rate
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
10
|
+
* Audio is captured as raw PCM16LE mono @16 kHz — the rate every engine takes —
|
|
11
|
+
* and sent as ONE binary frame on release. The engine, the language and the
|
|
12
|
+
* model are fixed before recording starts and travel in the socket's query
|
|
13
|
+
* string, so the server can refuse an unusable combination at the upgrade rather
|
|
14
|
+
* than after a minute of audio.
|
|
14
15
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
16
|
+
* Two local refusals happen BEFORE the round trip, because both are cheaper to
|
|
17
|
+
* answer here and both otherwise produce text nobody said: a recording shorter
|
|
18
|
+
* than `minMs`, and one whose level never rises above the silence floor (a
|
|
19
|
+
* ~100 ms tap is the classic input for a Whisper "Thank you." hallucination).
|
|
20
|
+
* A third refusal names a dead capture — every sample exactly zero — because
|
|
21
|
+
* that is a microphone that never delivered, not a user who spoke softly; the
|
|
22
|
+
* device side of it, including the macOS constraints that keep the capture
|
|
23
|
+
* alive, is `capture.ts`.
|
|
20
24
|
*/
|
|
21
25
|
|
|
22
26
|
import { useCallback, useEffect, useRef, useState } from 'preact/hooks';
|
|
27
|
+
import { openCapture, type DictationCapture } from '@/client/hooks/chat/composer/capture';
|
|
23
28
|
import { concatSamples, float32ToPcm16 } from '@/shared/lib/dictation/audio';
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
|
|
29
|
+
import { DICTATION_NO_AUDIO, isDeadCapture, isSilent, utteranceMs } from '@/shared/lib/dictation/gate';
|
|
30
|
+
import {
|
|
31
|
+
DICTATION_SAMPLE_RATE,
|
|
32
|
+
decodeDictationServerFrame,
|
|
33
|
+
dictationSocketPath,
|
|
34
|
+
type DictationRequest,
|
|
35
|
+
} from '@/shared/lib/dictation/protocol';
|
|
36
|
+
import type { DictationConfig } from '@/shared/lib/dictation/settings';
|
|
27
37
|
|
|
28
38
|
export interface UseSpeechToTextOptions {
|
|
29
39
|
/** Called with the final transcript. */
|
|
30
40
|
onResult: (text: string) => void;
|
|
31
|
-
/**
|
|
32
|
-
|
|
33
|
-
/** BCP 47 tag (`id-ID`, `en-US`). Omitted lets the model auto-detect. */
|
|
34
|
-
language?: string;
|
|
41
|
+
/** The stored preference; read live so a settings edit applies next time. */
|
|
42
|
+
config: DictationConfig;
|
|
35
43
|
}
|
|
36
44
|
|
|
37
45
|
export interface UseSpeechToTextReturn {
|
|
@@ -48,51 +56,45 @@ export interface UseSpeechToTextReturn {
|
|
|
48
56
|
error: string | null;
|
|
49
57
|
}
|
|
50
58
|
|
|
51
|
-
/**
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
+
/** A pending timer; the handle differs between the DOM and Bun typings. */
|
|
60
|
+
type CaptureTimer = ReturnType<typeof setTimeout>;
|
|
61
|
+
|
|
62
|
+
/** The socket path for this config: engine, language and model, no audio. */
|
|
63
|
+
export function dictationRequestFor(config: DictationConfig): DictationRequest {
|
|
64
|
+
return {
|
|
65
|
+
engine: config.engine,
|
|
66
|
+
language: config.language,
|
|
67
|
+
...(config.model.trim() ? { model: config.model.trim() } : {}),
|
|
68
|
+
};
|
|
59
69
|
}
|
|
60
70
|
|
|
61
|
-
function dictationUrl(): string {
|
|
71
|
+
function dictationUrl(request: DictationRequest): string {
|
|
62
72
|
const scheme = location.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
63
|
-
return `${scheme}//${location.host}
|
|
73
|
+
return `${scheme}//${location.host}${dictationSocketPath(request)}`;
|
|
64
74
|
}
|
|
65
75
|
|
|
66
|
-
export function useSpeechToText({ onResult,
|
|
76
|
+
export function useSpeechToText({ onResult, config }: UseSpeechToTextOptions): UseSpeechToTextReturn {
|
|
67
77
|
const [isListening, setIsListening] = useState(false);
|
|
68
78
|
const [isTranscribing, setIsTranscribing] = useState(false);
|
|
69
79
|
const [progressText, setProgressText] = useState<string | null>(null);
|
|
70
80
|
const [error, setError] = useState<string | null>(null);
|
|
71
81
|
|
|
72
|
-
const
|
|
73
|
-
const contextRef = useRef<AudioContext | null>(null);
|
|
74
|
-
const sourceRef = useRef<MediaStreamAudioSourceNode | null>(null);
|
|
75
|
-
const processorRef = useRef<ScriptProcessorNode | null>(null);
|
|
76
|
-
const chunksRef = useRef<Float32Array[]>([]);
|
|
77
|
-
const inputRateRef = useRef(DICTATION_SAMPLE_RATE);
|
|
82
|
+
const captureRef = useRef<DictationCapture | null>(null);
|
|
78
83
|
const socketRef = useRef<WebSocket | null>(null);
|
|
84
|
+
const autoStopRef = useRef<CaptureTimer | undefined>(undefined);
|
|
85
|
+
/** Set by `stopListening` below; the auto-stop timer needs a stable seam. */
|
|
86
|
+
const stopListeningRef = useRef<(() => void) | null>(null);
|
|
79
87
|
|
|
80
88
|
const isSupported =
|
|
81
89
|
typeof navigator !== 'undefined' && typeof navigator.mediaDevices?.getUserMedia === 'function';
|
|
82
90
|
|
|
83
91
|
/** Stop capturing and release the microphone; returns the recorded samples. */
|
|
84
92
|
const releaseCapture = useCallback((): Float32Array[] => {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
contextRef.current = null;
|
|
91
|
-
for (const track of streamRef.current?.getTracks() ?? []) track.stop();
|
|
92
|
-
streamRef.current = null;
|
|
93
|
-
const chunks = chunksRef.current;
|
|
94
|
-
chunksRef.current = [];
|
|
95
|
-
return chunks;
|
|
93
|
+
clearTimeout(autoStopRef.current);
|
|
94
|
+
autoStopRef.current = undefined;
|
|
95
|
+
const capture = captureRef.current;
|
|
96
|
+
captureRef.current = null;
|
|
97
|
+
return capture?.release() ?? [];
|
|
96
98
|
}, []);
|
|
97
99
|
|
|
98
100
|
const fail = useCallback(
|
|
@@ -108,105 +110,127 @@ export function useSpeechToText({ onResult, modelKey, language }: UseSpeechToTex
|
|
|
108
110
|
[releaseCapture],
|
|
109
111
|
);
|
|
110
112
|
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
navigator.mediaDevices
|
|
118
|
-
.getUserMedia({ audio: true })
|
|
119
|
-
.then((stream) => {
|
|
120
|
-
streamRef.current = stream;
|
|
121
|
-
try {
|
|
122
|
-
const context = new AudioContext({ sampleRate: DICTATION_SAMPLE_RATE });
|
|
123
|
-
contextRef.current = context;
|
|
124
|
-
inputRateRef.current = context.sampleRate;
|
|
125
|
-
|
|
126
|
-
const source = context.createMediaStreamSource(stream);
|
|
127
|
-
sourceRef.current = source;
|
|
128
|
-
const processor = context.createScriptProcessor(4096, 1, 1);
|
|
129
|
-
processorRef.current = processor;
|
|
130
|
-
processor.onaudioprocess = (event) => {
|
|
131
|
-
chunksRef.current.push(new Float32Array(event.inputBuffer.getChannelData(0)));
|
|
132
|
-
};
|
|
133
|
-
source.connect(processor);
|
|
134
|
-
processor.connect(context.destination);
|
|
135
|
-
setIsListening(true);
|
|
136
|
-
} catch {
|
|
137
|
-
// The microphone IS open at this point, so the failure is the audio
|
|
138
|
-
// graph, not the permission — and the stream has to be released or
|
|
139
|
-
// the OS keeps showing the microphone in use.
|
|
140
|
-
fail('Could not start audio capture.');
|
|
141
|
-
}
|
|
142
|
-
})
|
|
143
|
-
.catch((cause: unknown) => {
|
|
144
|
-
setError(describeCaptureFailure(cause));
|
|
145
|
-
});
|
|
146
|
-
}, [fail, isSupported]);
|
|
147
|
-
|
|
148
|
-
const stopListening = useCallback(() => {
|
|
149
|
-
setIsListening(false);
|
|
150
|
-
const chunks = releaseCapture();
|
|
151
|
-
if (chunks.length === 0) return;
|
|
152
|
-
|
|
153
|
-
const samples = concatSamples(chunks);
|
|
154
|
-
if (samples.length === 0) return;
|
|
155
|
-
const pcm16 = float32ToPcm16(samples, inputRateRef.current, DICTATION_SAMPLE_RATE);
|
|
156
|
-
const audio = toBase64(new Uint8Array(pcm16.buffer, pcm16.byteOffset, pcm16.byteLength));
|
|
157
|
-
|
|
158
|
-
setIsTranscribing(true);
|
|
159
|
-
setProgressText('Transcribing…');
|
|
160
|
-
|
|
161
|
-
const socket = new WebSocket(dictationUrl());
|
|
162
|
-
socketRef.current = socket;
|
|
113
|
+
const send = useCallback(
|
|
114
|
+
(chunks: Float32Array[], inputRate: number) => {
|
|
115
|
+
const samples = concatSamples(chunks);
|
|
116
|
+
const pcm16 = float32ToPcm16(samples, inputRate, DICTATION_SAMPLE_RATE);
|
|
117
|
+
const bytes = new Uint8Array(pcm16.buffer, pcm16.byteOffset, pcm16.byteLength);
|
|
163
118
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
socket.onmessage = (event) => {
|
|
169
|
-
let frame: DictationServerFrame;
|
|
170
|
-
try {
|
|
171
|
-
frame = JSON.parse(String(event.data)) as DictationServerFrame;
|
|
172
|
-
} catch {
|
|
119
|
+
if (utteranceMs(bytes.byteLength) < config.minMs) {
|
|
120
|
+
fail(`That was too short to transcribe (under ${config.minMs} ms).`);
|
|
173
121
|
return;
|
|
174
122
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
? 'Transcribing…'
|
|
180
|
-
: frame.percent !== null
|
|
181
|
-
? `Downloading speech model ${frame.percent}%`
|
|
182
|
-
: 'Downloading speech model…',
|
|
183
|
-
);
|
|
123
|
+
// Before the silence floor: bit-exact zeros are a capture that delivered
|
|
124
|
+
// nothing (a track WebKit ended, a muted device), not a quiet speaker.
|
|
125
|
+
if (isDeadCapture(bytes)) {
|
|
126
|
+
fail(DICTATION_NO_AUDIO);
|
|
184
127
|
return;
|
|
185
128
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
setProgressText(null);
|
|
189
|
-
setIsTranscribing(false);
|
|
190
|
-
socket.close();
|
|
191
|
-
socketRef.current = null;
|
|
192
|
-
onResult(frame.text);
|
|
129
|
+
if (isSilent(bytes)) {
|
|
130
|
+
fail('No speech was detected in that recording.');
|
|
193
131
|
return;
|
|
194
132
|
}
|
|
195
133
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
134
|
+
setIsTranscribing(true);
|
|
135
|
+
setProgressText('Transcribing…');
|
|
136
|
+
|
|
137
|
+
const socket = new WebSocket(dictationUrl(dictationRequestFor(config)));
|
|
138
|
+
socketRef.current = socket;
|
|
139
|
+
socket.binaryType = 'arraybuffer';
|
|
140
|
+
|
|
141
|
+
socket.onopen = () => {
|
|
142
|
+
// A copy: the buffer is a view over the resampled array and Bun's
|
|
143
|
+
// serializer wants an owned frame.
|
|
144
|
+
socket.send(bytes.slice().buffer);
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
socket.onmessage = (event) => {
|
|
148
|
+
const frame = decodeDictationServerFrame(event.data);
|
|
149
|
+
if (!frame) return;
|
|
150
|
+
|
|
151
|
+
if (frame.type === 'progress') {
|
|
152
|
+
setProgressText(
|
|
153
|
+
frame.decoding
|
|
154
|
+
? 'Transcribing…'
|
|
155
|
+
: frame.percent !== null
|
|
156
|
+
? `Downloading speech model ${frame.percent}%`
|
|
157
|
+
: 'Downloading speech model…',
|
|
158
|
+
);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (frame.type === 'final') {
|
|
163
|
+
setProgressText(null);
|
|
164
|
+
setIsTranscribing(false);
|
|
165
|
+
socket.close();
|
|
166
|
+
socketRef.current = null;
|
|
167
|
+
onResult(frame.text);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (frame.type === 'error') {
|
|
172
|
+
fail(frame.error);
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
socket.onerror = () => {
|
|
177
|
+
if (socketRef.current === socket) fail('Could not reach the dictation service.');
|
|
178
|
+
};
|
|
200
179
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
180
|
+
socket.onclose = () => {
|
|
181
|
+
// A close before a final/error frame means the transcription never landed.
|
|
182
|
+
if (socketRef.current === socket) fail('The dictation connection closed unexpectedly.');
|
|
183
|
+
};
|
|
184
|
+
},
|
|
185
|
+
[config, fail, onResult],
|
|
186
|
+
);
|
|
204
187
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
188
|
+
const startListening = useCallback(() => {
|
|
189
|
+
if (!isSupported) return;
|
|
190
|
+
setError(null);
|
|
191
|
+
setProgressText(null);
|
|
192
|
+
|
|
193
|
+
void openCapture(config.deviceId, fail, { onDead: () => fail(DICTATION_NO_AUDIO) }).then(
|
|
194
|
+
(capture) => {
|
|
195
|
+
if (!capture) return;
|
|
196
|
+
captureRef.current = capture;
|
|
197
|
+
setIsListening(true);
|
|
198
|
+
|
|
199
|
+
// A recording nobody stops would grow until the browser kills it.
|
|
200
|
+
autoStopRef.current = setTimeout(() => {
|
|
201
|
+
autoStopRef.current = undefined;
|
|
202
|
+
stopListeningRef.current?.();
|
|
203
|
+
}, config.maxMs);
|
|
204
|
+
},
|
|
205
|
+
);
|
|
206
|
+
}, [config.deviceId, config.maxMs, fail, isSupported]);
|
|
207
|
+
|
|
208
|
+
// The auto-stop timer is armed inside `startListening`, which must not depend
|
|
209
|
+
// on `stopListening` (it would re-create the callback on every render and
|
|
210
|
+
// restart the timer). One ref is the seam.
|
|
211
|
+
const stopListening = useCallback(() => {
|
|
212
|
+
setIsListening(false);
|
|
213
|
+
const capture = captureRef.current;
|
|
214
|
+
captureRef.current = null;
|
|
215
|
+
clearTimeout(autoStopRef.current);
|
|
216
|
+
autoStopRef.current = undefined;
|
|
217
|
+
if (!capture) return;
|
|
218
|
+
const inputRate = capture.inputRate();
|
|
219
|
+
const chunks = capture.release();
|
|
220
|
+
// No callback ran at all, so the recording ended inside the first 85 ms
|
|
221
|
+
// buffer — necessarily under `minMs`. A dead capture is NOT this case: it
|
|
222
|
+
// still runs callbacks (measured 11 in 1.2 s) and is refused by the gate in
|
|
223
|
+
// `send`, so this cannot mask it.
|
|
224
|
+
if (chunks.length === 0) {
|
|
225
|
+
fail(`That was too short to transcribe (under ${config.minMs} ms).`);
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
send(chunks, inputRate);
|
|
229
|
+
}, [config.minMs, fail, send]);
|
|
230
|
+
|
|
231
|
+
useEffect(() => {
|
|
232
|
+
stopListeningRef.current = stopListening;
|
|
233
|
+
}, [stopListening]);
|
|
210
234
|
|
|
211
235
|
useEffect(
|
|
212
236
|
() => () => {
|