@openchamber/web 2.0.4 → 2.1.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 (264) hide show
  1. package/dist/assets/{CodeMirrorCommentWidgets-C_zL-eri.js → CodeMirrorCommentWidgets-qlshRzAf.js} +1 -1
  2. package/dist/assets/{DiffView-BeN2_YYF.js → DiffView-BI_YgdKl.js} +3 -3
  3. package/dist/assets/FilesView-B_NJFLBH.js +17 -0
  4. package/dist/assets/{GitView-DLDazOo1.js → GitView-BWKg6TNS.js} +4 -4
  5. package/dist/assets/{GuestAttachDialog-C0xe_Lyy.js → GuestAttachDialog-DO4x4vIR.js} +1 -1
  6. package/dist/assets/{GuestSurfacePane-BdaurnDr.js → GuestSurfacePane-4PY11vEP.js} +1 -1
  7. package/dist/assets/JsonTreeView-u4yx65zn.js +1 -0
  8. package/dist/assets/{LinearIssuesView-BryoAHow.js → LinearIssuesView-C4gGBhU8.js} +1 -1
  9. package/dist/assets/{MarkdownImageGallery-DfuEoaGq.js → MarkdownImageGallery-fqVRCTdC.js} +1 -1
  10. package/dist/assets/MarkdownRendererImpl-Cfb5fTnq.js +39 -0
  11. package/dist/assets/OnboardingScreen-CiTV2_OT.js +1 -0
  12. package/dist/assets/PatchDiff-BrjhzXDM.js +1 -0
  13. package/dist/assets/{PierreDiffViewer-BC950e3F.js → PierreDiffViewer-CVx2e1cx.js} +5 -5
  14. package/dist/assets/{PlanView-B7Xgihqk.js → PlanView-DP9DOnI-.js} +4 -4
  15. package/dist/assets/{PluginPane-2C71F8uF.js → PluginPane-rZvoMQSi.js} +3 -3
  16. package/dist/assets/SettingsView-Dp9jubRs.js +30 -0
  17. package/dist/assets/SettingsWindow-Dst0yiV7.js +1 -0
  18. package/dist/assets/{SubmoduleDiffSummary-BSA9gnIO.js → SubmoduleDiffSummary-CixkM4fI.js} +1 -1
  19. package/dist/assets/{ToolOutputDialog-DprkVKcj.js → ToolOutputDialog-f0cS2DIf.js} +6 -6
  20. package/dist/assets/ToolPartDiffPreview-CFFIAFFY.js +8 -0
  21. package/dist/assets/{VirtualizedFileDiff-Kp8hKJdT.js → VirtualizedFileDiff-B-U_aQwV.js} +4 -4
  22. package/dist/assets/{WalkthroughView-DGnTzqIU.js → WalkthroughView-C1uB3Pl3.js} +2 -2
  23. package/dist/assets/{appThemeRegistry-BdEHBA4s.js → appThemeRegistry-DU-UKEHq.js} +1 -1
  24. package/dist/assets/{commitAndPush-LwtVa2Oc.js → commitAndPush-CtWGqrtW.js} +1 -1
  25. package/dist/assets/{computeVirtualFileMetrics-6V1xNpO9.js → computeVirtualFileMetrics-BmhViPMt.js} +1 -1
  26. package/dist/assets/de-D4hpTCNY.js +10 -0
  27. package/dist/assets/es-Bw9m3H62.js +16 -0
  28. package/dist/assets/fileTreeStatus-CvPnAWSi.js +1 -0
  29. package/dist/assets/fr-Bhll42P0.js +14 -0
  30. package/dist/assets/index-Btd2mmYT.js +42 -0
  31. package/dist/assets/index-C-7hQnEc.css +1 -0
  32. package/dist/assets/{index-CmNPYddV.js → index-DwtCnbiK.js} +1 -1
  33. package/dist/assets/{isDiffPlainText-1bXcWCrw.js → isDiffPlainText-CPDhzF1K.js} +1 -1
  34. package/dist/assets/{isFilePlainText-CBAppvy1.js → isFilePlainText-n8k0lMTZ.js} +1 -1
  35. package/dist/assets/ja-CsHoT43d.js +16 -0
  36. package/dist/assets/ko-BBNdtFa4.js +16 -0
  37. package/dist/assets/{main-CzjTMTfW.js → main-D6rlXjug.js} +2 -2
  38. package/dist/assets/main-kYkr_urz.js +1000 -0
  39. package/dist/assets/markdownCore-CHm8ycaW.js +7 -0
  40. package/dist/assets/{miniChat-CP68IL8Q.js → miniChat-2JY8K3Qw.js} +2 -2
  41. package/dist/assets/mobile-CviaXnnU.js +2 -0
  42. package/dist/assets/nl-DszyktfH.js +16 -0
  43. package/dist/assets/openSessionFromRoute-BIlcJIf3.js +1 -0
  44. package/dist/assets/{web-components-ngpHPEDU.js → parseDiffFromFile-DeZzEah8.js} +5 -5
  45. package/dist/assets/{patchFileDiff-pqRSHLHI.js → patchFileDiff-BnEHIdM2.js} +2 -2
  46. package/dist/assets/pl-Bk9_mUXc.js +16 -0
  47. package/dist/assets/pt-BR-BIXmm3Gw.js +16 -0
  48. package/dist/assets/{renderElectronMiniChatApp-DKIilR7N.js → renderElectronMiniChatApp-DvUphkjj.js} +2 -2
  49. package/dist/assets/renderMobileApp-Cdc49X8Y.js +25 -0
  50. package/dist/assets/runtimeEndpointReset-Cu6RUve4.js +56 -0
  51. package/dist/assets/shikiHighlight-CcVzlYit.js +1 -0
  52. package/dist/assets/space-apply-CgJ5JYPK.js +1 -0
  53. package/dist/assets/space-close-C1tL-_0t.js +1 -0
  54. package/dist/assets/{textMateThemeFromAppTheme-BSUFChBY.js → textMateThemeFromAppTheme-CAOCeVjl.js} +1 -1
  55. package/dist/assets/tr-C_13w7CX.js +7 -0
  56. package/dist/assets/uk-BZTsG-q_.js +16 -0
  57. package/dist/assets/{useAppFontEffects-Dsl_sLrj.js → useAppFontEffects-CeMgbeVa.js} +185 -177
  58. package/dist/assets/{useInlineCommentController-d5vntsQ_.js → useInlineCommentController-U97JJifS.js} +2 -2
  59. package/dist/assets/useRootScrollLock-DMBY2aTT.js +2 -0
  60. package/dist/assets/{vendor-base-ui-DnNniUWp.js → vendor-base-ui-DWgyZK2k.js} +1 -1
  61. package/dist/assets/vendor-codemirror-autocomplete-DetzHhtC.js +1 -0
  62. package/dist/assets/{vendor-codemirror-commands-B7H_j0iU.js → vendor-codemirror-commands-ConqfjLn.js} +1 -1
  63. package/dist/assets/{vendor-codemirror-lang-angular-DEPs2M5t.js → vendor-codemirror-lang-angular-Dbpx8qe-.js} +1 -1
  64. package/dist/assets/{vendor-codemirror-lang-cpp-DhkseaMo.js → vendor-codemirror-lang-cpp-TRtQWrpl.js} +1 -1
  65. package/dist/assets/{vendor-codemirror-lang-css-O0cZX78y.js → vendor-codemirror-lang-css-DY4CGDG2.js} +1 -1
  66. package/dist/assets/{vendor-codemirror-lang-go-fMdQYcON.js → vendor-codemirror-lang-go-CLKXh6B8.js} +1 -1
  67. package/dist/assets/{vendor-codemirror-lang-html-CfgK872x.js → vendor-codemirror-lang-html-CQnNjmg9.js} +1 -1
  68. package/dist/assets/{vendor-codemirror-lang-java-CQj4S3zl.js → vendor-codemirror-lang-java-CokZKqls.js} +1 -1
  69. package/dist/assets/{vendor-codemirror-lang-javascript-Cc2ZYbgX.js → vendor-codemirror-lang-javascript-Kgp6fZRE.js} +1 -1
  70. package/dist/assets/{vendor-codemirror-lang-jinja-BmZZv8g-.js → vendor-codemirror-lang-jinja-DZchyrN1.js} +1 -1
  71. package/dist/assets/{vendor-codemirror-lang-json-CMBS2tG9.js → vendor-codemirror-lang-json-CkdBRvqj.js} +1 -1
  72. package/dist/assets/{vendor-codemirror-lang-less-C6Eo8hVS.js → vendor-codemirror-lang-less-_k-GKz0A.js} +1 -1
  73. package/dist/assets/{vendor-codemirror-lang-liquid-DSTR47-H.js → vendor-codemirror-lang-liquid-DuHUMKoh.js} +1 -1
  74. package/dist/assets/{vendor-codemirror-lang-markdown-BPGOH9ye.js → vendor-codemirror-lang-markdown-CdG1RXm1.js} +1 -1
  75. package/dist/assets/{vendor-codemirror-lang-php-DD9udfPH.js → vendor-codemirror-lang-php-Ca15KQSA.js} +1 -1
  76. package/dist/assets/{vendor-codemirror-lang-python-HahnQaAS.js → vendor-codemirror-lang-python-B4MRHRva.js} +1 -1
  77. package/dist/assets/{vendor-codemirror-lang-rust-nLTovbjv.js → vendor-codemirror-lang-rust-8fLJdxQA.js} +1 -1
  78. package/dist/assets/{vendor-codemirror-lang-sass-pL2Yc72v.js → vendor-codemirror-lang-sass-CASr_yQ1.js} +1 -1
  79. package/dist/assets/{vendor-codemirror-lang-sql-BVBnan19.js → vendor-codemirror-lang-sql-Dc4ER-re.js} +1 -1
  80. package/dist/assets/{vendor-codemirror-lang-vue-BqGzJVm1.js → vendor-codemirror-lang-vue-fu2BqdK2.js} +1 -1
  81. package/dist/assets/{vendor-codemirror-lang-wast-B0_m5DqU.js → vendor-codemirror-lang-wast-BkCOgSpV.js} +1 -1
  82. package/dist/assets/{vendor-codemirror-lang-xml-Dj3voadT.js → vendor-codemirror-lang-xml-7e-kPepH.js} +1 -1
  83. package/dist/assets/{vendor-codemirror-lang-yaml-yu-9Z5u7.js → vendor-codemirror-lang-yaml-Cq3p_9DI.js} +1 -1
  84. package/dist/assets/vendor-codemirror-language-CZcLdzDM.js +3 -0
  85. package/dist/assets/{vendor-codemirror-language-data-B1EetJur.js → vendor-codemirror-language-data-B8HKnqZy.js} +2 -2
  86. package/dist/assets/vendor-codemirror-search-BZNojiZO.js +2 -0
  87. package/dist/assets/{vendor-codemirror-state-C9awkmn-.js → vendor-codemirror-state--21VQleR.js} +1 -1
  88. package/dist/assets/vendor-codemirror-view-8PpN-8l4.js +4 -0
  89. package/dist/assets/vendor-opencode-client-Byb4ZSqI.js +12 -0
  90. package/dist/assets/vendor-remend-DcBOpbSu.js +24 -0
  91. package/dist/assets/{vendor-replit-codemirror-vim-B2DJlAhT.js → vendor-replit-codemirror-vim-EX7OnecQ.js} +1 -1
  92. package/dist/assets/zh-CN-C62wm2Tg.js +16 -0
  93. package/dist/assets/zh-TW-BgGTiQA6.js +16 -0
  94. package/dist/index.html +4 -4
  95. package/dist/mini-chat.html +4 -4
  96. package/dist/mobile.html +4 -4
  97. package/package.json +4 -4
  98. package/server/index.js +58 -1
  99. package/server/lib/browser-control/DOCUMENTATION.md +8 -1
  100. package/server/lib/dev-tunnel/DOCUMENTATION.md +6 -0
  101. package/server/lib/dev-tunnel/runtime.js +94 -38
  102. package/server/lib/dev-tunnel/tunnel.test.js +16 -2
  103. package/server/lib/dictation/DOCUMENTATION.md +23 -10
  104. package/server/lib/dictation/audio.js +28 -0
  105. package/server/lib/dictation/local/sherpa-recognizer.js +33 -7
  106. package/server/lib/dictation/local/sherpa-recognizer.test.js +94 -0
  107. package/server/lib/dictation/local/worker-client.js +28 -10
  108. package/server/lib/dictation/local/worker-process.js +25 -1
  109. package/server/lib/dictation/stream-manager.js +160 -53
  110. package/server/lib/dictation/stream-manager.test.js +108 -7
  111. package/server/lib/enterprise-mode.d.ts +2 -0
  112. package/server/lib/enterprise-mode.js +84 -9
  113. package/server/lib/enterprise-mode.test.js +115 -0
  114. package/server/lib/fs/DOCUMENTATION.md +3 -2
  115. package/server/lib/fs/routes.js +28 -1
  116. package/server/lib/fs/routes.test.js +31 -5
  117. package/server/lib/git/DOCUMENTATION.md +1 -1
  118. package/server/lib/git/service.js +61 -2
  119. package/server/lib/git/service.test.js +141 -0
  120. package/server/lib/github/DOCUMENTATION.md +18 -0
  121. package/server/lib/github/checks-summary.js +76 -0
  122. package/server/lib/github/pr-summaries.js +282 -0
  123. package/server/lib/github/pr-summaries.test.js +209 -0
  124. package/server/lib/github/routes.js +42 -77
  125. package/server/lib/github/routes.test.js +77 -0
  126. package/server/lib/inherited-env.js +51 -0
  127. package/server/lib/inherited-env.test.js +59 -0
  128. package/server/lib/message-search/DOCUMENTATION.md +83 -0
  129. package/server/lib/message-search/indexer.js +336 -0
  130. package/server/lib/message-search/indexer.test.js +341 -0
  131. package/server/lib/message-search/routes.js +92 -0
  132. package/server/lib/message-search/runtime.js +234 -0
  133. package/server/lib/message-search/runtime.test.js +108 -0
  134. package/server/lib/message-search/sqlite.js +74 -0
  135. package/server/lib/message-search/store.js +289 -0
  136. package/server/lib/openchamber-control/DOCUMENTATION.md +6 -1
  137. package/server/lib/openchamber-control/actions.js +1 -1
  138. package/server/lib/openchamber-control/service.js +21 -2
  139. package/server/lib/openchamber-control/service.test.js +50 -0
  140. package/server/lib/openchamber-sessions/routes.js +15 -0
  141. package/server/lib/openchamber-sessions/routes.test.js +31 -0
  142. package/server/lib/opencode/DOCUMENTATION.md +43 -38
  143. package/server/lib/opencode/auth.d.ts +24 -0
  144. package/server/lib/opencode/auth.js +130 -66
  145. package/server/lib/opencode/auth.test.js +114 -70
  146. package/server/lib/opencode/compatibility.js +4 -3
  147. package/server/lib/opencode/compatibility.test.js +10 -10
  148. package/server/lib/opencode/feature-routes-runtime.js +3 -0
  149. package/server/lib/opencode/lifecycle.js +21 -12
  150. package/server/lib/opencode/lifecycle.test.js +38 -5
  151. package/server/lib/opencode/provider-source-route.test.js +55 -2
  152. package/server/lib/opencode/routes.js +17 -4
  153. package/server/lib/opencode/settings-helpers.js +6 -0
  154. package/server/lib/opencode/settings-helpers.test.js +1 -1
  155. package/server/lib/opencode/settings-registry.json +16 -0
  156. package/server/lib/opencode/settings-runtime.js +9 -0
  157. package/server/lib/opencode/shutdown-runtime.js +2 -0
  158. package/server/lib/opencode/v1-migration-topup.js +13 -3
  159. package/server/lib/opencode/v2-install.test.js +13 -13
  160. package/server/lib/quota/DOCUMENTATION.md +11 -5
  161. package/server/lib/quota/providers/claude/auth.js +19 -6
  162. package/server/lib/quota/providers/claude/auth.test.js +22 -9
  163. package/server/lib/quota/providers/claude/index.js +3 -3
  164. package/server/lib/quota/providers/claude/index.test.js +3 -2
  165. package/server/lib/quota/providers/cline-pass.js +4 -4
  166. package/server/lib/quota/providers/codex.js +3 -4
  167. package/server/lib/quota/providers/codex.test.js +1 -1
  168. package/server/lib/quota/providers/copilot.js +4 -5
  169. package/server/lib/quota/providers/copilot.test.js +1 -1
  170. package/server/lib/quota/providers/deepseek.js +3 -4
  171. package/server/lib/quota/providers/deepseek.test.js +1 -1
  172. package/server/lib/quota/providers/google/auth.js +1 -3
  173. package/server/lib/quota/providers/google/index.js +3 -2
  174. package/server/lib/quota/providers/hyper.js +4 -4
  175. package/server/lib/quota/providers/index.js +9 -2
  176. package/server/lib/quota/providers/index.test.js +5 -3
  177. package/server/lib/quota/providers/kimi.js +16 -11
  178. package/server/lib/quota/providers/kimi.test.js +81 -38
  179. package/server/lib/quota/providers/minimax-shared.js +3 -4
  180. package/server/lib/quota/providers/nanogpt.js +3 -4
  181. package/server/lib/quota/providers/neuralwatt.js +3 -4
  182. package/server/lib/quota/providers/neuralwatt.test.js +1 -1
  183. package/server/lib/quota/providers/openai.js +2 -8
  184. package/server/lib/quota/providers/opencode-go.js +5 -5
  185. package/server/lib/quota/providers/opencode-go.test.js +1 -1
  186. package/server/lib/quota/providers/openrouter.js +30 -6
  187. package/server/lib/quota/providers/openrouter.test.js +122 -1
  188. package/server/lib/quota/providers/wafer.js +3 -4
  189. package/server/lib/quota/providers/xai.js +12 -12
  190. package/server/lib/quota/providers/zai.js +3 -4
  191. package/server/lib/quota/providers/zai.test.js +1 -1
  192. package/server/lib/quota/providers/zhipuai-coding-plan.js +5 -6
  193. package/server/lib/quota/providers/zhipuai-coding-plan.test.js +1 -1
  194. package/server/lib/quota/routes.js +1 -1
  195. package/server/lib/routing/DOCUMENTATION.md +4 -0
  196. package/server/lib/routing/runtime.js +45 -4
  197. package/server/lib/routing/runtime.test.js +35 -6
  198. package/server/lib/scheduled-tasks/DOCUMENTATION.md +27 -0
  199. package/server/lib/scheduled-tasks/chats-scope.js +50 -0
  200. package/server/lib/scheduled-tasks/runtime.js +57 -23
  201. package/server/lib/scheduled-tasks/runtime.test.js +103 -1
  202. package/server/lib/scheduled-tasks/service.js +37 -29
  203. package/server/lib/scheduled-tasks/service.test.js +39 -0
  204. package/server/lib/spaces/DOCUMENTATION.md +54 -9
  205. package/server/lib/spaces/host.js +24 -3
  206. package/server/lib/spaces/journey.js +111 -11
  207. package/server/lib/spaces/journey.test.js +189 -8
  208. package/server/lib/spaces/places/docker-disk.js +151 -0
  209. package/server/lib/spaces/places/docker-disk.test.js +167 -0
  210. package/server/lib/spaces/places/docker-tools.js +11 -1
  211. package/server/lib/spaces/places/docker.js +4 -2
  212. package/server/lib/spaces/places/fake-docker.js +36 -2
  213. package/server/lib/spaces/routes.js +21 -4
  214. package/server/lib/spaces/routes.test.js +6 -2
  215. package/server/lib/spaces/space-archive.js +275 -0
  216. package/server/lib/spaces/space-archive.test.js +194 -0
  217. package/server/lib/spaces/space-opencode.js +139 -6
  218. package/server/lib/spaces/space-opencode.test.js +82 -1
  219. package/server/lib/spaces/space-records.js +3 -0
  220. package/server/lib/spaces/space-setup.js +10 -5
  221. package/server/lib/spaces/space-setup.test.js +8 -2
  222. package/server/lib/terminal/DOCUMENTATION.md +1 -0
  223. package/server/lib/terminal/runtime.js +6 -1
  224. package/server/lib/terminal/runtime.test.js +19 -0
  225. package/server/lib/tts/routes.js +2 -2
  226. package/server/lib/tts/service.js +8 -8
  227. package/dist/assets/FilesView-CN34wm_N.js +0 -17
  228. package/dist/assets/JsonTreeView-B1Xq-k2t.js +0 -1
  229. package/dist/assets/MarkdownRendererImpl-B_ZcWOvX.js +0 -12
  230. package/dist/assets/OnboardingScreen-C22bGmnP.js +0 -1
  231. package/dist/assets/PatchDiff-0xd6UeFB.js +0 -1
  232. package/dist/assets/SettingsView-m_zoFiaT.js +0 -30
  233. package/dist/assets/SettingsWindow-CofS020b.js +0 -1
  234. package/dist/assets/ToolPartDiffPreview-Dq0go_fX.js +0 -8
  235. package/dist/assets/de-DlgBHUAI.js +0 -10
  236. package/dist/assets/es-BC8G41U8.js +0 -16
  237. package/dist/assets/fr-I0z3vVjy.js +0 -14
  238. package/dist/assets/index-CgR5rJq_.js +0 -41
  239. package/dist/assets/index-adyy_sEk.css +0 -1
  240. package/dist/assets/ja-BIElEsY8.js +0 -16
  241. package/dist/assets/ko-DRnnHetA.js +0 -16
  242. package/dist/assets/main-DVX34beR.js +0 -886
  243. package/dist/assets/markdownCore-Cxbkn5NR.js +0 -7
  244. package/dist/assets/mobile-BrlBrNfZ.js +0 -2
  245. package/dist/assets/nl-DzUV-kwp.js +0 -16
  246. package/dist/assets/pl-Bb-cb7k7.js +0 -16
  247. package/dist/assets/pt-BR-CyIWrTcE.js +0 -16
  248. package/dist/assets/renderMobileApp-B0z6-x58.js +0 -25
  249. package/dist/assets/runtimeEndpointReset-uu1DBwLL.js +0 -52
  250. package/dist/assets/scheduledTasksApi-BuzWT445.js +0 -1
  251. package/dist/assets/shikiHighlight-BWGrY5YU.js +0 -1
  252. package/dist/assets/tr-DXEDSoYO.js +0 -7
  253. package/dist/assets/uk-C8hN--q_.js +0 -16
  254. package/dist/assets/useRootScrollLock-2rd5Y6gR.js +0 -2
  255. package/dist/assets/vendor-codemirror-autocomplete-DzPz9Wgq.js +0 -1
  256. package/dist/assets/vendor-codemirror-language-BgPj_McA.js +0 -3
  257. package/dist/assets/vendor-codemirror-search-BmS-GmcX.js +0 -2
  258. package/dist/assets/vendor-codemirror-view-CiLROUVV.js +0 -4
  259. package/dist/assets/vendor-opencode-client-DSZl7jSi.js +0 -12
  260. package/dist/assets/vendor-remend-BWYYytN3.js +0 -22
  261. package/dist/assets/zh-CN-CtzXdjMZ.js +0 -16
  262. package/dist/assets/zh-TW-Ds0CADSz.js +0 -16
  263. package/server/lib/opencode/credential-db.js +0 -144
  264. package/server/lib/opencode/credential-db.test.js +0 -104
@@ -190,32 +190,58 @@ export class SherpaSegmentTranscriptionSession extends EventEmitter {
190
190
  this.pcm16 = this.pcm16.length === 0 ? chunk : Buffer.concat([this.pcm16, chunk]);
191
191
  }
192
192
 
193
- commit() {
193
+ /**
194
+ * Close the current segment and hand it back for decoding, WITHOUT decoding.
195
+ * The caller decodes later (e.g. on the next event-loop turn) so a long
196
+ * segment's quadratic decode never blocks the worker's IPC — see
197
+ * worker-process.js session.commit. Returns null when not connected or the
198
+ * segment holds no audio.
199
+ * @returns {{ segmentId: string, previousSegmentId: string|null, pcm16: Buffer } | null}
200
+ */
201
+ takePendingSegment() {
194
202
  if (!this.connected || !this.currentSegmentId) {
195
203
  this.emit('error', new Error('Sherpa transcription session not connected'));
196
- return;
204
+ return null;
197
205
  }
198
-
199
206
  const segmentId = this.currentSegmentId;
200
207
  const previousSegmentId = this.previousSegmentId;
201
208
  const pcm16 = this.pcm16;
202
209
 
203
- // Start the next segment before decoding: decoding blocks the worker for
204
- // seconds on long segments, and audio for the next one keeps arriving.
210
+ // Start the next segment before decoding: decoding can take seconds on
211
+ // long segments, and audio for the next one keeps arriving meanwhile.
205
212
  this.previousSegmentId = segmentId;
206
213
  this.currentSegmentId = randomUUID();
207
214
  this.pcm16 = Buffer.alloc(0);
208
215
 
209
216
  this.emit('committed', { segmentId, previousSegmentId });
210
217
 
218
+ if (pcm16.length === 0) {
219
+ return null;
220
+ }
221
+ return { segmentId, previousSegmentId, pcm16 };
222
+ }
223
+
224
+ /**
225
+ * Decode a segment previously returned by takePendingSegment() and emit its
226
+ * final transcript.
227
+ * @param {{ segmentId: string, pcm16: Buffer }} pending
228
+ */
229
+ decodeSegment(pending) {
211
230
  let transcript;
212
231
  try {
213
- transcript = this.engine.decodePcm16(pcm16);
232
+ transcript = this.engine.decodePcm16(pending.pcm16);
214
233
  } catch (err) {
215
234
  this.emit('error', err instanceof Error ? err : new Error(String(err)));
216
235
  return;
217
236
  }
218
- this.emit('transcript', { segmentId, transcript, isFinal: true });
237
+ this.emit('transcript', { segmentId: pending.segmentId, transcript, isFinal: true });
238
+ }
239
+
240
+ commit() {
241
+ const pending = this.takePendingSegment();
242
+ if (pending) {
243
+ this.decodeSegment(pending);
244
+ }
219
245
  }
220
246
 
221
247
  clear() {
@@ -0,0 +1,94 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { EventEmitter } from 'events';
3
+
4
+ import { SherpaSegmentTranscriptionSession } from './sherpa-recognizer.js';
5
+
6
+ /**
7
+ * Regression guard for the dictation timeout bug:
8
+ * a segment's decode must NOT run inside the commit() call that the worker
9
+ * acks. worker-process.js acks `session.commit` BEFORE decoding, which is only
10
+ * correct if the session can hand the segment back without decoding it.
11
+ *
12
+ * If takePendingSegment() ever starts decoding inline again, a long segment
13
+ * would block the worker's IPC past the parent's request timeout again — the
14
+ * exact "Dictation worker request timed out: session.commit" failure.
15
+ */
16
+
17
+ class RecordingEngine {
18
+ constructor() {
19
+ this.decoded = [];
20
+ this.decodeCalls = 0;
21
+ }
22
+ decodePcm16(pcm16) {
23
+ this.decodeCalls += 1;
24
+ this.decoded.push(pcm16);
25
+ return 'text';
26
+ }
27
+ }
28
+
29
+ function pcm(seconds) {
30
+ return Buffer.alloc(seconds * 16000 * 2, 1);
31
+ }
32
+
33
+ describe('SherpaSegmentTranscriptionSession', () => {
34
+ it('takePendingSegment does not decode; decodeSegment does', async () => {
35
+ const engine = new RecordingEngine();
36
+ const session = new SherpaSegmentTranscriptionSession({ engine });
37
+ await session.connect();
38
+
39
+ session.appendPcm16(pcm(5));
40
+ const pending = session.takePendingSegment();
41
+
42
+ // The whole point: handing back the segment must be decode-free.
43
+ expect(engine.decodeCalls).toBe(0);
44
+ expect(pending).not.toBeNull();
45
+ expect(pending.pcm16.length).toBe(pcm(5).length);
46
+
47
+ session.decodeSegment(pending);
48
+ expect(engine.decodeCalls).toBe(1);
49
+ });
50
+
51
+ it('emits committed before the caller decodes', async () => {
52
+ const engine = new RecordingEngine();
53
+ const session = new SherpaSegmentTranscriptionSession({ engine });
54
+ await session.connect();
55
+
56
+ const events = [];
57
+ session.on('committed', () => events.push('committed'));
58
+ session.on('transcript', () => events.push('transcript'));
59
+
60
+ session.appendPcm16(pcm(5));
61
+ const pending = session.takePendingSegment();
62
+ expect(events).toEqual(['committed']);
63
+ expect(engine.decodeCalls).toBe(0);
64
+
65
+ session.decodeSegment(pending);
66
+ expect(events).toEqual(['committed', 'transcript']);
67
+ });
68
+
69
+ it('takePendingSegment returns null for an empty segment', async () => {
70
+ const engine = new RecordingEngine();
71
+ const session = new SherpaSegmentTranscriptionSession({ engine });
72
+ await session.connect();
73
+
74
+ const pending = session.takePendingSegment();
75
+ expect(pending).toBeNull();
76
+ expect(engine.decodeCalls).toBe(0);
77
+ });
78
+
79
+ it('starts a fresh segment so appended audio is not lost', async () => {
80
+ const engine = new RecordingEngine();
81
+ const session = new SherpaSegmentTranscriptionSession({ engine });
82
+ await session.connect();
83
+
84
+ session.appendPcm16(pcm(2));
85
+ const first = session.takePendingSegment();
86
+
87
+ session.appendPcm16(pcm(3));
88
+ const second = session.takePendingSegment();
89
+
90
+ expect(first.pcm16.length).toBe(pcm(2).length);
91
+ expect(second.pcm16.length).toBe(pcm(3).length);
92
+ expect(first.segmentId).not.toBe(second.segmentId);
93
+ });
94
+ });
@@ -14,6 +14,10 @@ import { fileURLToPath } from 'url';
14
14
 
15
15
  import { applySherpaLoaderEnv } from './sherpa-loader.js';
16
16
 
17
+ // Every request is answered by the worker on its next event-loop turn, so this
18
+ // only has to cover IPC latency, not inference time. `session.commit` acks
19
+ // BEFORE the segment is decoded (see worker-process.js) precisely so a long
20
+ // segment can no longer trip this timeout.
17
21
  const DEFAULT_REQUEST_TIMEOUT_MS = 30000;
18
22
  const DEFAULT_IDLE_TTL_MS = 5 * 60 * 1000;
19
23
  const DEFAULT_LOCAL_SAMPLE_RATE = 16000;
@@ -88,26 +92,31 @@ export class DictationWorkerClient {
88
92
  }
89
93
 
90
94
  appendSessionAudio(sessionId, audio) {
91
- void this.sendRequest({ type: 'session.append', sessionId, audio }).catch((err) => {
95
+ // Fire-and-forget with no per-request timeout: audio queued behind a
96
+ // decode is accepted, just waiting its turn. A dead worker is caught by
97
+ // handleWorkerExit.
98
+ void this.sendRequest({ type: 'session.append', sessionId, audio }, { timeoutMs: 0 }).catch((err) => {
92
99
  this.emitSessionError(sessionId, err);
93
100
  });
94
101
  }
95
102
 
96
103
  commitSession(sessionId) {
97
- void this.sendRequest({ type: 'session.commit', sessionId }).catch((err) => {
104
+ // Fire-and-forget like appendSessionAudio: the committed/transcript events
105
+ // carry the result, and a dead worker is caught by handleWorkerExit.
106
+ void this.sendRequest({ type: 'session.commit', sessionId }, { timeoutMs: 0 }).catch((err) => {
98
107
  this.emitSessionError(sessionId, err);
99
108
  });
100
109
  }
101
110
 
102
111
  clearSession(sessionId) {
103
- void this.sendRequest({ type: 'session.clear', sessionId }).catch((err) => {
112
+ void this.sendRequest({ type: 'session.clear', sessionId }, { timeoutMs: 0 }).catch((err) => {
104
113
  this.emitSessionError(sessionId, err);
105
114
  });
106
115
  }
107
116
 
108
117
  closeSession(sessionId) {
109
118
  this.sessionEmitters.delete(sessionId);
110
- void this.sendRequest({ type: 'session.close', sessionId }).catch(() => {
119
+ void this.sendRequest({ type: 'session.close', sessionId }, { timeoutMs: 0 }).catch(() => {
111
120
  // Closing is best-effort; the parent already dropped the session.
112
121
  });
113
122
  this.scheduleIdleShutdownIfReady();
@@ -141,13 +150,22 @@ export class DictationWorkerClient {
141
150
  this.inFlightRequests += 1;
142
151
  this.clearIdleTimer();
143
152
 
153
+ const timeoutMs = options.timeoutMs ?? this.requestTimeoutMs;
154
+
144
155
  return new Promise((resolve, reject) => {
145
- const timeout = setTimeout(() => {
146
- this.pendingRequests.delete(requestId);
147
- this.inFlightRequests = Math.max(0, this.inFlightRequests - 1);
148
- this.scheduleIdleShutdownIfReady();
149
- reject(new Error(`Dictation worker request timed out: ${input.type}`));
150
- }, options.timeoutMs ?? this.requestTimeoutMs);
156
+ // timeoutMs === 0 means "no per-request timeout": used for fire-and-forget
157
+ // audio traffic whose result is discarded. A dead worker is still caught
158
+ // by the worker 'close' handler (handleWorkerExit), which rejects every
159
+ // pending request.
160
+ const timeout =
161
+ timeoutMs > 0
162
+ ? setTimeout(() => {
163
+ this.pendingRequests.delete(requestId);
164
+ this.inFlightRequests = Math.max(0, this.inFlightRequests - 1);
165
+ this.scheduleIdleShutdownIfReady();
166
+ reject(new Error(`Dictation worker request timed out: ${input.type}`));
167
+ }, timeoutMs)
168
+ : null;
151
169
 
152
170
  this.pendingRequests.set(requestId, { resolve, reject, timeout });
153
171
 
@@ -153,8 +153,32 @@ async function handleRequest(message) {
153
153
  return;
154
154
  }
155
155
  case 'session.commit': {
156
- sessions.get(message.sessionId)?.commit();
156
+ const session = sessions.get(message.sessionId);
157
+ if (!session) {
158
+ sendOk(message.requestId);
159
+ return;
160
+ }
161
+ // The segment's decode is synchronous. Acknowledging only after it made
162
+ // the parent's worker-request timeout fire on long segments and blocked
163
+ // every following IPC packet (session.append) behind the decode. So:
164
+ // take the segment, ack the commit immediately, and decode on the next
165
+ // turn of the event loop — the transcript still arrives as a
166
+ // session.transcript event.
167
+ const pending = session.takePendingSegment();
157
168
  sendOk(message.requestId);
169
+ if (pending) {
170
+ setImmediate(() => {
171
+ try {
172
+ session.decodeSegment(pending);
173
+ } catch (err) {
174
+ sendToParent({
175
+ type: 'session.error',
176
+ sessionId: message.sessionId,
177
+ error: err instanceof Error ? err.message : String(err),
178
+ });
179
+ }
180
+ });
181
+ }
158
182
  return;
159
183
  }
160
184
  case 'session.clear': {
@@ -8,8 +8,8 @@
8
8
  * - Reorders inbound chunks by `seq` and acks the highest contiguous seq.
9
9
  * - Resamples client PCM (16 kHz by default) to the provider's required rate.
10
10
  * - Segments long dictations at natural pauses: past `segmentMinSeconds` of
11
- * audio it commits on the first silent chunk, and `segmentMaxSeconds` is a
12
- * hard cap for speech with no pause in it. Silence-only segments are
11
+ * audio it cuts inside the first pause it finds, and `segmentMaxSeconds` is
12
+ * a hard cap for speech with no pause in it. Silence-only segments are
13
13
  * cleared instead of committed.
14
14
  * - Concatenates per-segment transcripts into live partials and emits the
15
15
  * final text once every committed segment has a final transcript. The
@@ -19,40 +19,140 @@
19
19
  * - Applies an adaptive finalization timeout budget based on pending work.
20
20
  */
21
21
 
22
- import { Pcm16MonoResampler, parsePcmRateFromFormat, pcm16lePeakAbs } from './audio.js';
22
+ import {
23
+ Pcm16MonoResampler,
24
+ parsePcmRateFromFormat,
25
+ pcm16leFrameRms,
26
+ pcm16lePeakAbs,
27
+ } from './audio.js';
23
28
 
24
29
  const DEFAULT_FINAL_TIMEOUT_MS = 10000;
25
- // Parakeet is a full-attention conformer: decode cost and peak memory grow
26
- // quadratically with segment length (measured: 60s -> 2.1s/+90MB,
27
- // 300s -> 21.3s/+1.5GB). Segmenting keeps a long dictation off that curve and
28
- // lets committed segments decode while the user is still speaking, so only the
29
- // tail is left to transcribe on stop. Typical dictations are shorter than the
30
- // minimum and are decoded as a single segment.
31
- const DEFAULT_SEGMENT_MIN_SECONDS = 60;
32
- const DEFAULT_SEGMENT_MAX_SECONDS = 90;
30
+ // Parakeet decode cost and peak memory grow quadratically with segment length,
31
+ // and a long enough segment aborts the worker inside the native runtime, not
32
+ // just slowly (the curve and the crash are in DOCUMENTATION.md#segmentation).
33
+ // Segmenting keeps a long dictation off that curve, and committed segments
34
+ // decode while the user is still speaking, so only the tail is left on stop.
35
+ //
36
+ // The minimum is low because a 15s segment decodes in well under a second.
37
+ // The hard cap stays small (25s) so even pauseless speech never piles up a
38
+ // segment that can hit the allocation abort.
39
+ const DEFAULT_SEGMENT_MIN_SECONDS = 15;
40
+ const DEFAULT_SEGMENT_MAX_SECONDS = 25;
33
41
  const FINAL_TIMEOUT_MAX_MS = 5 * 60 * 1000;
34
42
  const FINAL_TIMEOUT_PER_PENDING_SEGMENT_MS = 15 * 1000;
35
43
  const FINAL_TIMEOUT_PER_PENDING_AUDIO_SECOND_MS = 1500;
36
44
  const FINAL_TIMEOUT_PER_MISSING_SEQ_MS = 250;
37
45
  const SILENCE_PEAK_THRESHOLD = 300;
46
+ // Pause detection looks at ~50 ms frames. A frame is quiet when its RMS sits
47
+ // within ~10 dB of the quietest frame in the last ~10 s of the stream (the
48
+ // noise floor), so a laptop fan or a boosted mic does not hide every pause,
49
+ // and at least ~15 dB below the loudest frame, so before the first real pause
50
+ // the softest bit of speech does not pass for one. The floor is a sliding
51
+ // window rather than an all-time minimum because a gated mic often opens with
52
+ // a second of digital zeros, and a floor pinned there would call room noise
53
+ // speech for the rest of the dictation. The absolute minimum keeps a
54
+ // digitally silent stream from needing exact zeros. A pause is a quiet run of
55
+ // at least 200 ms: longer than the closure inside a word, and a fast speaker's
56
+ // pause between sentences is barely longer (a synthesized voice pauses
57
+ // 200–350 ms at a period), so a cut lands between words.
58
+ const PAUSE_FRAME_MS = 50;
59
+ const PAUSE_MIN_FRAMES = 4;
60
+ const NOISE_FLOOR_WINDOW_CHUNKS = 10;
61
+ const QUIET_ABOVE_FLOOR_RATIO = 3;
62
+ const QUIET_BELOW_SPEECH_RATIO = 6;
63
+ const QUIET_RMS_MIN = 200;
38
64
 
39
65
  const secondsToPcm16Bytes = (seconds, sampleRate) =>
40
66
  seconds > 0 ? Math.max(1, Math.round(seconds * sampleRate * 2)) : 0;
41
67
 
42
68
  /**
43
- * Split the current segment once it is long enough to be worth decoding on its
44
- * own and the speaker has just gone quiet, or unconditionally at the hard cap.
45
- * Client chunks are ~1s, so a quiet chunk is roughly a second of silence — long
46
- * enough to be a sentence boundary rather than a gap between words.
69
+ * Byte offset inside `pcm16` where the current segment should end, or null to
70
+ * keep the whole chunk in it.
71
+ *
72
+ * Past `segmentMinBytes` the cut goes into the middle of the first pause; a
73
+ * pause may have started in the previous chunk, which `state.quietRunFrames`
74
+ * carries over (when its middle already went by, the cut is where this chunk
75
+ * starts, still inside the pause). At the hard cap the cut goes into the quietest frame of this
76
+ * chunk rather than at its boundary, so even pauseless speech is cut between
77
+ * words when it can be. Bytes before the cut belong to the segment being
78
+ * committed, bytes after it start the next one.
47
79
  */
48
- function shouldSplitSegment(state) {
49
- if (state.segmentMaxBytes > 0 && state.bytesSinceCommit >= state.segmentMaxBytes) {
50
- return true;
80
+ function findSegmentCut(state, pcm16) {
81
+ if (state.finishRequested) {
82
+ return null;
83
+ }
84
+ const capReached =
85
+ state.segmentMaxBytes > 0 && state.bytesSinceCommit + pcm16.length >= state.segmentMaxBytes;
86
+ const frameSamples = state.pauseFrameSamples;
87
+ const frameBytes = frameSamples * 2;
88
+ const rms = pcm16leFrameRms(pcm16, frameSamples);
89
+ if (rms.length === 0) {
90
+ return capReached ? pcm16.length : null;
91
+ }
92
+
93
+ let chunkFloor = Infinity;
94
+ for (const value of rms) {
95
+ if (value < chunkFloor) {
96
+ chunkFloor = value;
97
+ }
98
+ if (value > state.loudestRms) {
99
+ state.loudestRms = value;
100
+ }
51
101
  }
52
- if (state.segmentMinBytes <= 0 || state.bytesSinceCommit < state.segmentMinBytes) {
53
- return false;
102
+ state.recentChunkFloors.push(chunkFloor);
103
+ if (state.recentChunkFloors.length > NOISE_FLOOR_WINDOW_CHUNKS) {
104
+ state.recentChunkFloors.shift();
54
105
  }
55
- return state.lastChunkPeak < SILENCE_PEAK_THRESHOLD;
106
+ const noiseFloor = Math.min(...state.recentChunkFloors);
107
+ const quietBelow = Math.min(
108
+ Math.max(noiseFloor * QUIET_ABOVE_FLOOR_RATIO, QUIET_RMS_MIN),
109
+ state.loudestRms / QUIET_BELOW_SPEECH_RATIO,
110
+ );
111
+ const quiet = rms.map((value) => value <= quietBelow);
112
+
113
+ let cut = null;
114
+ if (state.segmentMinBytes > 0) {
115
+ let runStart = -state.quietRunFrames;
116
+ let inRun = state.quietRunFrames > 0;
117
+ for (let i = 0; i <= quiet.length; i += 1) {
118
+ if (i < quiet.length && quiet[i]) {
119
+ if (!inRun) {
120
+ inRun = true;
121
+ runStart = i;
122
+ }
123
+ continue;
124
+ }
125
+ if (!inRun) {
126
+ continue;
127
+ }
128
+ inRun = false;
129
+ if (i - runStart < PAUSE_MIN_FRAMES) {
130
+ continue;
131
+ }
132
+ const bytes = Math.max(0, Math.floor((runStart + i) / 2)) * frameBytes;
133
+ if (state.bytesSinceCommit + bytes >= state.segmentMinBytes) {
134
+ cut = bytes;
135
+ break;
136
+ }
137
+ }
138
+ }
139
+
140
+ if (cut === null && capReached) {
141
+ let quietest = 0;
142
+ for (let i = 1; i < rms.length; i += 1) {
143
+ if (rms[i] < rms[quietest]) {
144
+ quietest = i;
145
+ }
146
+ }
147
+ cut = (quietest * frameSamples + (frameSamples >> 1)) * 2;
148
+ }
149
+
150
+ let trailing = 0;
151
+ while (trailing < quiet.length && quiet[quiet.length - 1 - trailing]) {
152
+ trailing += 1;
153
+ }
154
+ state.quietRunFrames = trailing;
155
+ return cut;
56
156
  }
57
157
 
58
158
  export class DictationStreamManager {
@@ -173,9 +273,12 @@ export class DictationStreamManager {
173
273
  ackSeq: -1,
174
274
  segmentMinBytes: secondsToPcm16Bytes(this.segmentMinSeconds, stt.requiredSampleRate),
175
275
  segmentMaxBytes: secondsToPcm16Bytes(this.segmentMaxSeconds, stt.requiredSampleRate),
276
+ pauseFrameSamples: Math.max(1, Math.round((stt.requiredSampleRate * PAUSE_FRAME_MS) / 1000)),
277
+ recentChunkFloors: [],
278
+ loudestRms: 0,
279
+ quietRunFrames: 0,
176
280
  bytesSinceCommit: 0,
177
281
  peakSinceCommit: 0,
178
- lastChunkPeak: 0,
179
282
  committedSegmentIds: [],
180
283
  transcriptsBySegmentId: new Map(),
181
284
  finalTranscriptSegmentIds: new Set(),
@@ -228,12 +331,8 @@ export class DictationStreamManager {
228
331
 
229
332
  const resampled = state.resampler ? state.resampler.processChunk(pcm16) : pcm16;
230
333
  if (resampled.length > 0) {
231
- state.stt.appendPcm16(resampled);
232
- state.bytesSinceCommit += resampled.length;
233
- state.lastChunkPeak = pcm16lePeakAbs(resampled);
234
- state.peakSinceCommit = Math.max(state.peakSinceCommit, state.lastChunkPeak);
235
334
  try {
236
- this.maybeAutoCommitSegment(state);
335
+ this.forwardAudio(state, resampled);
237
336
  } catch (error) {
238
337
  this.failAndCleanupStream(dictationId, error?.message || String(error), true);
239
338
  return;
@@ -369,24 +468,39 @@ export class DictationStreamManager {
369
468
  );
370
469
  }
371
470
 
372
- maybeAutoCommitSegment(state) {
373
- if (state.finishRequested) {
374
- return;
375
- }
376
- if (!shouldSplitSegment(state)) {
471
+ /**
472
+ * Append one chunk of provider-rate audio, ending the current segment inside
473
+ * the chunk when it holds a good place to cut.
474
+ */
475
+ forwardAudio(state, pcm16) {
476
+ const cutAt = findSegmentCut(state, pcm16);
477
+ if (cutAt === null) {
478
+ this.appendToSegment(state, pcm16);
377
479
  return;
378
480
  }
379
- if (state.peakSinceCommit < SILENCE_PEAK_THRESHOLD) {
380
- state.stt.clear();
381
- state.bytesSinceCommit = 0;
382
- state.peakSinceCommit = 0;
383
- state.lastChunkPeak = 0;
481
+ this.appendToSegment(state, pcm16.subarray(0, cutAt));
482
+ this.endSegment(state);
483
+ this.appendToSegment(state, pcm16.subarray(cutAt));
484
+ }
485
+
486
+ appendToSegment(state, pcm16) {
487
+ if (pcm16.length === 0) {
384
488
  return;
385
489
  }
490
+ state.stt.appendPcm16(pcm16);
491
+ state.bytesSinceCommit += pcm16.length;
492
+ state.peakSinceCommit = Math.max(state.peakSinceCommit, pcm16lePeakAbs(pcm16));
493
+ }
386
494
 
495
+ /** Commit the current segment, or drop it when it holds only silence. */
496
+ endSegment(state) {
497
+ const silent = state.peakSinceCommit < SILENCE_PEAK_THRESHOLD;
387
498
  state.bytesSinceCommit = 0;
388
499
  state.peakSinceCommit = 0;
389
- state.lastChunkPeak = 0;
500
+ if (silent) {
501
+ state.stt.clear();
502
+ return;
503
+ }
390
504
  this.commitSegment(state);
391
505
  }
392
506
 
@@ -421,22 +535,15 @@ export class DictationStreamManager {
421
535
  }
422
536
 
423
537
  if (state.bytesSinceCommit > 0) {
424
- if (state.peakSinceCommit < SILENCE_PEAK_THRESHOLD) {
425
- state.stt.clear();
426
- state.bytesSinceCommit = 0;
427
- state.peakSinceCommit = 0;
428
- state.lastChunkPeak = 0;
538
+ const silent = state.peakSinceCommit < SILENCE_PEAK_THRESHOLD;
539
+ try {
540
+ this.endSegment(state);
541
+ } catch (error) {
542
+ this.failAndCleanupStream(dictationId, error?.message || String(error), true);
543
+ return;
544
+ }
545
+ if (silent) {
429
546
  this.dropUncommittedNonFinalTranscripts(state);
430
- } else {
431
- state.bytesSinceCommit = 0;
432
- state.peakSinceCommit = 0;
433
- state.lastChunkPeak = 0;
434
- try {
435
- this.commitSegment(state);
436
- } catch (error) {
437
- this.failAndCleanupStream(dictationId, error?.message || String(error), true);
438
- return;
439
- }
440
547
  }
441
548
  }
442
549