@openchamber/web 1.21.0 → 1.22.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 (180) hide show
  1. package/bin/cli.test.js +35 -0
  2. package/bin/lib/DOCUMENTATION.md +12 -0
  3. package/bin/lib/cli-settings-accessors.js +111 -0
  4. package/bin/lib/cli-settings-accessors.test.js +189 -0
  5. package/bin/lib/cli-startup.js +29 -9
  6. package/bin/lib/commands-connect-url.js +12 -14
  7. package/dist/assets/{CodeMirrorCommentWidgets-C2BopIs3.js → CodeMirrorCommentWidgets-CPvfxh0N.js} +1 -1
  8. package/dist/assets/CommitSection-CC5mFzO2.js +1 -0
  9. package/dist/assets/DiffView-6xGdyI0n.js +4 -0
  10. package/dist/assets/FilesView-Bm3vT63N.js +17 -0
  11. package/dist/assets/GitView-B6y1Y69c.js +6 -0
  12. package/dist/assets/{JsonTreeView-osju7J70.js → JsonTreeView-rwHz84MX.js} +1 -1
  13. package/dist/assets/LinearIssuesView-B0UM_Rkx.js +1 -0
  14. package/dist/assets/MarkdownImageGallery-sGilV9Hs.js +1 -0
  15. package/dist/assets/MarkdownRendererImpl--4sRsKBn.js +12 -0
  16. package/dist/assets/OnboardingScreen-CECL_Cms.js +1 -0
  17. package/dist/assets/{PatchDiff-Dan3mADn.js → PatchDiff-BGPl1s-U.js} +1 -1
  18. package/dist/assets/{PierreDiffViewer-CGoI2v0q.js → PierreDiffViewer-Cvz9Z-io.js} +2 -2
  19. package/dist/assets/PlanView-BFMsnHk3.js +5 -0
  20. package/dist/assets/SettingsView-_Gtn5SdT.js +28 -0
  21. package/dist/assets/{SettingsWindow-DXF-MTHG.js → SettingsWindow-C1Qa09YO.js} +1 -1
  22. package/dist/assets/{ToolOutputDialog-DrCa1JRk.js → ToolOutputDialog-DzQlzMF4.js} +6 -6
  23. package/dist/assets/{ToolPartDiffPreview-B_tfvlNF.js → ToolPartDiffPreview-DfVOfwHy.js} +2 -2
  24. package/dist/assets/{VirtualizedFileDiff-CN_BctrR.js → VirtualizedFileDiff-DT5MDv-u.js} +1 -1
  25. package/dist/assets/WalkthroughView-D8sLH_M8.js +4 -0
  26. package/dist/assets/{computeVirtualFileMetrics-Gi1d5eU1.js → computeVirtualFileMetrics-DmpLWhll.js} +1 -1
  27. package/dist/assets/{contextPanelEmbeddedChat-CpzVNWAv.js → contextPanelEmbeddedChat-BK78t3M_.js} +1 -1
  28. package/dist/assets/de-C3luvSd_.js +9 -0
  29. package/dist/assets/es-CmU4HLv9.js +15 -0
  30. package/dist/assets/fr-Bgyni40l.js +13 -0
  31. package/dist/assets/index-C57jT0Sa.css +1 -0
  32. package/dist/assets/{index-Brm3X9rs.js → index-CWYs7sMK.js} +1 -1
  33. package/dist/assets/index-b0zDkWyg.js +7 -0
  34. package/dist/assets/{isDiffPlainText-pH9kAJQH.js → isDiffPlainText-BO_q5ezD.js} +1 -1
  35. package/dist/assets/{isFilePlainText-CVKy_dgB.js → isFilePlainText-D8qPqUAf.js} +1 -1
  36. package/dist/assets/ja-C1ImKinT.js +15 -0
  37. package/dist/assets/ko-CP7OdxYH.js +15 -0
  38. package/dist/assets/main-D4rd8Hy5.js +928 -0
  39. package/dist/assets/{main-vUCh0VB0.js → main-D7fwjW2z.js} +2 -2
  40. package/dist/assets/{markdown-shiki.worker-CKGJ1J33.js → markdown-shiki.worker-D5fBU-lw.js} +5 -5
  41. package/dist/assets/markdownCore-BcmkWZPO.js +3 -0
  42. package/dist/assets/{miniChat-BlzGEYgE.js → miniChat-D5rraz-g.js} +2 -2
  43. package/dist/assets/{mobile-CkX6H-IT.js → mobile-Cg_DE3KL.js} +2 -2
  44. package/dist/assets/{patchFileDiff-BCTsE43U.js → patchFileDiff-Bpql0QGw.js} +3 -3
  45. package/dist/assets/pl-DQYSiGYX.js +15 -0
  46. package/dist/assets/pt-BR-DytpsW4M.js +15 -0
  47. package/dist/assets/{renderElectronMiniChatApp-CJYe_KOL.js → renderElectronMiniChatApp-B_Bn7BbN.js} +2 -2
  48. package/dist/assets/renderMobileApp-DLfxMzGJ.js +25 -0
  49. package/dist/assets/runtimeEndpointReset-HlRmXFGW.js +16 -0
  50. package/dist/assets/scheduledTasksApi-BPvxrynl.js +1 -0
  51. package/dist/assets/{shikiHighlight-BgTPSITe.js → shikiHighlight-CFAVs_lu.js} +1 -1
  52. package/dist/assets/tr-aizaUvft.js +6 -0
  53. package/dist/assets/uk-DwnRxJZd.js +15 -0
  54. package/dist/assets/useAppFontEffects-DWXGRUPZ.js +7310 -0
  55. package/dist/assets/{useInlineCommentController-DFFv0hae.js → useInlineCommentController-Cc0OCXr0.js} +2 -2
  56. package/dist/assets/useRootScrollLock-BFZtfciC.js +1 -0
  57. package/dist/assets/{vendor-base-ui-_6j2xOWl.js → vendor-base-ui-BeMD8X_w.js} +1 -1
  58. package/dist/assets/{vendor-codemirror-language-data-DkQX2EBa.js → vendor-codemirror-language-data-BGFszm8n.js} +2 -2
  59. package/dist/assets/{vendor-floating-ui-core-CXmKXOXc.js → vendor-floating-ui-core-PuGzNPnN.js} +1 -1
  60. package/dist/assets/{vendor-floating-ui-dom-WyXykhNi.js → vendor-floating-ui-dom-BTvzWks8.js} +1 -1
  61. package/dist/assets/{vendor-floating-ui-react-dom-DKpLs02S.js → vendor-floating-ui-react-dom-DxYCWdHj.js} +1 -1
  62. package/dist/assets/{vendor-floating-ui-utils-BzXdqYpP.js → vendor-floating-ui-utils-D6FqdtJt.js} +1 -1
  63. package/dist/assets/vendor-linkify-it-DZCzzDkK.js +1 -0
  64. package/dist/assets/vendor-marked-linkify-it-CXI_LHIE.js +1 -0
  65. package/dist/assets/vendor-uc.micro-BAd0H0z4.js +1 -0
  66. package/dist/assets/{web-components-DLnGY4fs.js → web-components-CD-GFayc.js} +4 -4
  67. package/dist/assets/zh-CN-UDNMxm7r.js +15 -0
  68. package/dist/assets/zh-TW-BsswdYL-.js +15 -0
  69. package/dist/index.html +5 -5
  70. package/dist/mini-chat.html +3 -3
  71. package/dist/mobile.html +3 -3
  72. package/dist/site.webmanifest +1 -1
  73. package/dist/sw.js +1 -1
  74. package/package.json +2 -2
  75. package/public/site.webmanifest +1 -1
  76. package/server/index.js +6 -2
  77. package/server/lib/cloudflare-tunnel.js +1 -1
  78. package/server/lib/dictation/DOCUMENTATION.md +19 -6
  79. package/server/lib/dictation/local/model-catalog.js +220 -0
  80. package/server/lib/dictation/local/model-catalog.test.js +42 -0
  81. package/server/lib/dictation/local/sherpa-tts.js +41 -20
  82. package/server/lib/dictation/local/worker-process.js +2 -0
  83. package/server/lib/dictation/runtime.js +4 -0
  84. package/server/lib/dictation/service.js +27 -4
  85. package/server/lib/fs/DOCUMENTATION.md +5 -0
  86. package/server/lib/fs/routes.js +150 -0
  87. package/server/lib/fs/routes.test.js +308 -3
  88. package/server/lib/git/DOCUMENTATION.md +4 -3
  89. package/server/lib/git/service.js +128 -6
  90. package/server/lib/git/service.test.js +191 -1
  91. package/server/lib/linear/DOCUMENTATION.md +97 -0
  92. package/server/lib/linear/OAUTH-BROKER-HANDOFF.md +91 -0
  93. package/server/lib/linear/auth.js +436 -0
  94. package/server/lib/linear/auth.test.js +242 -0
  95. package/server/lib/linear/client.js +191 -0
  96. package/server/lib/linear/index.js +61 -0
  97. package/server/lib/linear/issues.js +499 -0
  98. package/server/lib/linear/issues.test.js +512 -0
  99. package/server/lib/linear/mapping.js +188 -0
  100. package/server/lib/linear/mapping.test.js +147 -0
  101. package/server/lib/linear/oauth.js +345 -0
  102. package/server/lib/linear/oauth.test.js +166 -0
  103. package/server/lib/linear/parse.js +23 -0
  104. package/server/lib/linear/routes.js +432 -0
  105. package/server/lib/linear/routes.test.js +661 -0
  106. package/server/lib/linear/status-runtime.js +64 -0
  107. package/server/lib/linear/status-runtime.test.js +167 -0
  108. package/server/lib/linear/status.js +280 -0
  109. package/server/lib/linear/status.test.js +271 -0
  110. package/server/lib/linear/teams.js +72 -0
  111. package/server/lib/linear/teams.test.js +94 -0
  112. package/server/lib/markdown-image-grants/DOCUMENTATION.md +4 -0
  113. package/server/lib/markdown-image-grants/routes.js +3 -1
  114. package/server/lib/markdown-image-grants/routes.test.js +14 -0
  115. package/server/lib/openchamber-sessions/routes.js +4 -1
  116. package/server/lib/openchamber-sessions/routes.test.js +23 -0
  117. package/server/lib/opencode/env-runtime.js +17 -1
  118. package/server/lib/opencode/env-runtime.test.js +56 -0
  119. package/server/lib/opencode/feature-routes-runtime.js +2 -0
  120. package/server/lib/opencode/lifecycle.js +48 -9
  121. package/server/lib/opencode/lifecycle.test.js +125 -1
  122. package/server/lib/opencode/managed-process-registry.d.ts +13 -0
  123. package/server/lib/opencode/managed-process-registry.js +213 -163
  124. package/server/lib/opencode/managed-process-registry.test.mjs +285 -0
  125. package/server/lib/opencode/project-directory-runtime.js +16 -11
  126. package/server/lib/opencode/project-directory-runtime.test.js +32 -12
  127. package/server/lib/opencode/pwa-manifest-routes.js +1 -1
  128. package/server/lib/opencode/routes-upgrade.test.js +96 -12
  129. package/server/lib/opencode/routes.js +53 -5
  130. package/server/lib/opencode/settings-helpers.js +3 -0
  131. package/server/lib/opencode/settings-helpers.test.js +10 -0
  132. package/server/lib/opencode/static-routes-runtime.js +3 -3
  133. package/server/lib/opencode/theme-runtime.js +1 -1
  134. package/server/lib/opencode/theme-runtime.test.js +129 -0
  135. package/server/lib/projects/project-config.js +33 -5
  136. package/server/lib/projects/project-config.test.js +85 -0
  137. package/server/lib/quota/DOCUMENTATION.md +19 -0
  138. package/server/lib/quota/providers/copilot.js +26 -10
  139. package/server/lib/quota/providers/copilot.test.js +78 -0
  140. package/server/lib/scheduled-tasks/DOCUMENTATION.md +7 -0
  141. package/server/lib/small-model/DOCUMENTATION.md +11 -5
  142. package/server/lib/small-model/call.js +64 -20
  143. package/server/lib/small-model/call.test.js +184 -2
  144. package/server/lib/tts/DOCUMENTATION.md +1 -0
  145. package/server/lib/tts/language-detect.js +210 -0
  146. package/server/lib/tts/language-detect.test.js +76 -0
  147. package/server/lib/tts/routes.js +23 -1
  148. package/server/lib/tts/routes.test.js +26 -0
  149. package/server/lib/tunnels/install-help.js +2 -2
  150. package/server/lib/tunnels/install-help.test.js +9 -0
  151. package/server/lib/walkthrough/languages.js +1 -0
  152. package/dist/assets/CommitSection-HJeMUAWb.js +0 -1
  153. package/dist/assets/DiffView-D5cvbEPb.js +0 -4
  154. package/dist/assets/FilesView-DPU8aNPL.js +0 -17
  155. package/dist/assets/GitView-Ct6xWrVH.js +0 -6
  156. package/dist/assets/MarkdownImageGallery-EujHSZ2M.js +0 -1
  157. package/dist/assets/MarkdownRendererImpl-CPzu4kIr.js +0 -12
  158. package/dist/assets/OnboardingScreen-w2VG4fWY.js +0 -1
  159. package/dist/assets/PlanView-Dgg-WTEc.js +0 -4
  160. package/dist/assets/SessionSwitcherDropdown-CJTrc8K7.js +0 -1
  161. package/dist/assets/SettingsView-D9yRuFZw.js +0 -28
  162. package/dist/assets/WalkthroughView-D9Q4lr5x.js +0 -4
  163. package/dist/assets/de-B_LdJwEM.js +0 -9
  164. package/dist/assets/es-CubfsAYV.js +0 -15
  165. package/dist/assets/fr-5qJM0nFS.js +0 -13
  166. package/dist/assets/index-BW82eK5v.css +0 -1
  167. package/dist/assets/index-rlLjZUM5.js +0 -7
  168. package/dist/assets/ja-DJYIBUlH.js +0 -15
  169. package/dist/assets/ko-DcUBkB7y.js +0 -15
  170. package/dist/assets/main-DLBxKIoX.js +0 -926
  171. package/dist/assets/markdownCore-DG6GHLF4.js +0 -3
  172. package/dist/assets/pl-rB6BLcio.js +0 -15
  173. package/dist/assets/pt-BR-DcwtlO-o.js +0 -15
  174. package/dist/assets/renderMobileApp-hQJTnr8B.js +0 -25
  175. package/dist/assets/runtimeEndpointReset-BDh7r8BL.js +0 -15
  176. package/dist/assets/scheduledTasksApi-CAGPh_gZ.js +0 -1
  177. package/dist/assets/uk-INZlFD9A.js +0 -15
  178. package/dist/assets/useAppFontEffects-Cll4gnsh.js +0 -7268
  179. package/dist/assets/zh-CN-Dzda8xa1.js +0 -15
  180. package/dist/assets/zh-TW-Cwn3rNYZ.js +0 -15
package/dist/index.html CHANGED
@@ -18,7 +18,7 @@
18
18
  <!-- Web app manifest (endpoint-first with data URL fallback) -->
19
19
  <script>
20
20
  const baseUrl = location.origin;
21
- const defaultAppName = 'OpenChamber - AI Coding Assistant';
21
+ const defaultAppName = 'OpenChamber';
22
22
  const defaultShortName = 'OpenChamber';
23
23
  const pwaNameStorageKey = 'openchamber.pwaName';
24
24
  const pwaOrientationStorageKey = 'openchamber.pwaOrientation';
@@ -509,16 +509,16 @@
509
509
  pointer-events: none;
510
510
  }
511
511
  </style>
512
- <script type="module" crossorigin src="/assets/main-vUCh0VB0.js"></script>
512
+ <script type="module" crossorigin src="/assets/main-D7fwjW2z.js"></script>
513
513
  <link rel="modulepreload" crossorigin href="/assets/vendor-vite-runtime-DD1OZmLC.js">
514
514
  <link rel="modulepreload" crossorigin href="/assets/vendor-scheduler-7OC5HNn7.js">
515
515
  <link rel="modulepreload" crossorigin href="/assets/vendor-react-BUCujlKS.js">
516
516
  <link rel="modulepreload" crossorigin href="/assets/vendor-zustand-BAGL70zf.js">
517
517
  <link rel="modulepreload" crossorigin href="/assets/vendor-zod-BLfBSgBh.js">
518
518
  <link rel="modulepreload" crossorigin href="/assets/vendor-opencode-sdk-BJ73u-bH.js">
519
- <link rel="modulepreload" crossorigin href="/assets/index-rlLjZUM5.js">
520
- <link rel="modulepreload" crossorigin href="/assets/contextPanelEmbeddedChat-CpzVNWAv.js">
521
- <link rel="stylesheet" crossorigin href="/assets/index-BW82eK5v.css">
519
+ <link rel="modulepreload" crossorigin href="/assets/index-b0zDkWyg.js">
520
+ <link rel="modulepreload" crossorigin href="/assets/contextPanelEmbeddedChat-BK78t3M_.js">
521
+ <link rel="stylesheet" crossorigin href="/assets/index-C57jT0Sa.css">
522
522
  </head>
523
523
  <body class="h-full bg-background text-foreground">
524
524
  <div id="root" class="h-full">
@@ -74,15 +74,15 @@
74
74
  }
75
75
  </style>
76
76
 
77
- <script type="module" crossorigin src="/assets/miniChat-BlzGEYgE.js"></script>
77
+ <script type="module" crossorigin src="/assets/miniChat-D5rraz-g.js"></script>
78
78
  <link rel="modulepreload" crossorigin href="/assets/vendor-vite-runtime-DD1OZmLC.js">
79
79
  <link rel="modulepreload" crossorigin href="/assets/vendor-scheduler-7OC5HNn7.js">
80
80
  <link rel="modulepreload" crossorigin href="/assets/vendor-react-BUCujlKS.js">
81
81
  <link rel="modulepreload" crossorigin href="/assets/vendor-zustand-BAGL70zf.js">
82
82
  <link rel="modulepreload" crossorigin href="/assets/vendor-zod-BLfBSgBh.js">
83
83
  <link rel="modulepreload" crossorigin href="/assets/vendor-opencode-sdk-BJ73u-bH.js">
84
- <link rel="modulepreload" crossorigin href="/assets/index-rlLjZUM5.js">
85
- <link rel="stylesheet" crossorigin href="/assets/index-BW82eK5v.css">
84
+ <link rel="modulepreload" crossorigin href="/assets/index-b0zDkWyg.js">
85
+ <link rel="stylesheet" crossorigin href="/assets/index-C57jT0Sa.css">
86
86
  </head>
87
87
  <body class="h-full bg-background text-foreground">
88
88
  <div id="root" class="h-full">
package/dist/mobile.html CHANGED
@@ -63,15 +63,15 @@
63
63
  })();
64
64
  </script>
65
65
 
66
- <script type="module" crossorigin src="/assets/mobile-CkX6H-IT.js"></script>
66
+ <script type="module" crossorigin src="/assets/mobile-Cg_DE3KL.js"></script>
67
67
  <link rel="modulepreload" crossorigin href="/assets/vendor-vite-runtime-DD1OZmLC.js">
68
68
  <link rel="modulepreload" crossorigin href="/assets/vendor-scheduler-7OC5HNn7.js">
69
69
  <link rel="modulepreload" crossorigin href="/assets/vendor-react-BUCujlKS.js">
70
70
  <link rel="modulepreload" crossorigin href="/assets/vendor-zustand-BAGL70zf.js">
71
71
  <link rel="modulepreload" crossorigin href="/assets/vendor-zod-BLfBSgBh.js">
72
72
  <link rel="modulepreload" crossorigin href="/assets/vendor-opencode-sdk-BJ73u-bH.js">
73
- <link rel="modulepreload" crossorigin href="/assets/index-rlLjZUM5.js">
74
- <link rel="stylesheet" crossorigin href="/assets/index-BW82eK5v.css">
73
+ <link rel="modulepreload" crossorigin href="/assets/index-b0zDkWyg.js">
74
+ <link rel="stylesheet" crossorigin href="/assets/index-C57jT0Sa.css">
75
75
  </head>
76
76
  <body class="h-full bg-background text-foreground">
77
77
  <div id="root" class="h-full"></div>
@@ -1,5 +1,5 @@
1
1
  {
2
- "name": "OpenChamber - AI Coding Companion",
2
+ "name": "OpenChamber",
3
3
  "short_name": "OpenChamber",
4
4
  "description": "OpenChamber desktop companion for the OpenCode AI coding agent",
5
5
  "start_url": "/",
package/dist/sw.js CHANGED
@@ -1 +1 @@
1
- (function(){"use strict";self.addEventListener("install",t=>{t.waitUntil(self.skipWaiting())}),self.addEventListener("activate",t=>{t.waitUntil(self.clients.claim())}),self.addEventListener("push",t=>{t.waitUntil((async()=>{const i=t.data?.json()??null;if(!i||(await self.clients.matchAll({type:"window",includeUncontrolled:!0})).some(a=>a.visibilityState==="visible"||a.focused))return;const e=i.title||"OpenChamber",s=i.body??"",l=i.icon??"/apple-touch-icon-180x180.png",o=i.badge??"/favicon-32.png";await self.registration.showNotification(e,{body:s,icon:l,badge:o,tag:i.tag,data:i.data})})())}),self.addEventListener("notificationclick",t=>{t.notification.close();const n=(t.notification.data??null)?.url??"/";t.waitUntil(self.clients.openWindow(n))})})();
1
+ (function(){"use strict";self.addEventListener("install",t=>{t.waitUntil(self.skipWaiting())}),self.addEventListener("activate",t=>{t.waitUntil(self.clients.claim())}),self.addEventListener("push",t=>{t.waitUntil((async()=>{const i=t.data?.json()??null;if(!i||(await self.clients.matchAll({type:"window",includeUncontrolled:!0})).some(l=>l.visibilityState==="visible"||l.focused))return;const a=i.title||"OpenChamber",n=i.body??"",o=i.icon??"/apple-touch-icon-180x180.png",c=i.badge??"/favicon-32.png";await self.registration.showNotification(a,{body:n,icon:o,badge:c,tag:i.tag,data:i.data})})())}),self.addEventListener("notificationclick",t=>{t.notification.close();const s=(t.notification.data??null)?.url??"/";t.waitUntil((async()=>{const e=new URL(s,self.location.origin).href,a=await self.clients.matchAll({type:"window",includeUncontrolled:!0});for(const n of a){try{"navigate"in n&&await n.navigate(e)}catch{}if("focus"in n)return n.focus()}if(self.clients.openWindow)return self.clients.openWindow(e)})())})})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openchamber/web",
3
- "version": "1.21.0",
3
+ "version": "1.22.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./server/index.js",
@@ -25,7 +25,7 @@
25
25
  "dependencies": {
26
26
  "@clack/prompts": "^1.1.0",
27
27
  "@octokit/rest": "^22.0.1",
28
- "@opencode-ai/sdk": "1.18.23",
28
+ "@opencode-ai/sdk": "1.18.25",
29
29
  "@simplewebauthn/server": "13.3.1",
30
30
  "bun-pty": "^0.4.5",
31
31
  "compression": "^1.8.1",
@@ -1,5 +1,5 @@
1
1
  {
2
- "name": "OpenChamber - AI Coding Companion",
2
+ "name": "OpenChamber",
3
3
  "short_name": "OpenChamber",
4
4
  "description": "OpenChamber desktop companion for the OpenCode AI coding agent",
5
5
  "start_url": "/",
package/server/index.js CHANGED
@@ -77,6 +77,7 @@ import { createOpenCodeWatcherRuntime } from './lib/opencode/watcher.js';
77
77
  import { createSessionAssistRuntime } from './lib/session-assist/runtime.js';
78
78
  import { createSessionGoalRuntime } from './lib/session-goal/runtime.js';
79
79
  import { createContextObligatoryRuntime } from './lib/context-obligatory/runtime.js';
80
+ import { createLinearSessionStatusRuntime } from './lib/linear/status-runtime.js';
80
81
  import { createSessionKnowledgeRuntime } from './lib/session-knowledge/runtime.js';
81
82
  import { createScheduledTasksRuntime } from './lib/scheduled-tasks/runtime.js';
82
83
  import { createServerStartupRuntime } from './lib/opencode/server-startup-runtime.js';
@@ -856,6 +857,8 @@ const contextObligatoryRuntime = createContextObligatoryRuntime({
856
857
  sessionKnowledgeRuntime,
857
858
  });
858
859
 
860
+ const linearSessionStatusRuntime = createLinearSessionStatusRuntime();
861
+
859
862
  const globalMessageStreamHub = createGlobalMessageStreamHub({
860
863
  buildOpenCodeUrl,
861
864
  getOpenCodeAuthHeaders,
@@ -901,6 +904,7 @@ globalMessageStreamHub.subscribeEvent((event) => {
901
904
  sessionAssistRuntime.processPayload(payload, directory);
902
905
  sessionGoalRuntime.processPayload(payload, directory);
903
906
  contextObligatoryRuntime.processPayload(payload, directory);
907
+ linearSessionStatusRuntime.processPayload(payload);
904
908
  });
905
909
 
906
910
  const processForwardedEventPayload = (payload, emitSyntheticEvent) => {
@@ -1162,8 +1166,8 @@ const openCodeLifecycleRuntime = createOpenCodeLifecycleRuntime({
1162
1166
  return [...new Set(directories)];
1163
1167
  },
1164
1168
  // A managed restart can move OpenCode to a NEW port (the old one may stay
1165
- // occupied by an orphaned process, e.g. killProcessOnPort is a no-op on
1166
- // Windows). Rebind the message-stream upstream readers to the current port
1169
+ // occupied if killProcessOnPort/waitForPortRelease didn't free it in time,
1170
+ // on any platform). Rebind the message-stream upstream readers to the current port
1167
1171
  // so the UI keeps receiving events instead of staying pinned to the old
1168
1172
  // process (#2638). The runtime is created later by the startup pipeline;
1169
1173
  // by the time any restart runs, it is assigned.
@@ -64,7 +64,7 @@ Install instructions for your platform:
64
64
  Windows: winget install --id Cloudflare.cloudflared
65
65
  Linux: Download from https://github.com/cloudflare/cloudflared/releases
66
66
 
67
- Or visit: https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflared/downloads/
67
+ Or visit: https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/downloads/
68
68
  `);
69
69
  }
70
70
 
@@ -11,12 +11,25 @@ live transcript costs O(n^2) work for a result the final decode replaces. The
11
11
  composer shows no text while recording and inserts the full transcript on
12
12
  stop.
13
13
 
14
- Local TTS (Kokoro via sherpa-onnx OfflineTts) runs in the same worker process
15
- and is exposed as `POST /api/dictation/tts/speak` (JSON `{text, speakerId?,
16
- speed?, model?}` → WAV bytes; 503 with `reasonCode` while the model is
17
- downloading). TTS models live in the same catalog/downloader as STT models
18
- (`local/model-catalog.js` `LOCAL_TTS_MODEL_CATALOG`) and are managed by the
19
- same status/download/delete routes.
14
+ Local TTS (Kokoro and Piper/VITS via sherpa-onnx OfflineTts) runs in the same
15
+ worker process and is exposed as `POST /api/dictation/tts/speak` (JSON
16
+ `{text, speakerId?, speed?, model?, language?, languageSample?}` → WAV bytes; 503 with
17
+ `reasonCode` while the model is downloading). TTS models live in the same
18
+ catalog/downloader as STT models (`local/model-catalog.js`
19
+ `LOCAL_TTS_MODEL_CATALOG`) and are managed by the same status/download/delete
20
+ routes.
21
+
22
+ Each TTS catalog entry declares the `languages` it speaks. With
23
+ `language: 'auto'` the service detects the language of `languageSample` — the
24
+ whole message the chunk belongs to, sent by the client with every chunk — or
25
+ of `text` when no sample is given
26
+ (`../tts/language-detect.js`, script plus function-word scoring, no
27
+ dependencies) and keeps the caller's model when it speaks that language;
28
+ otherwise it switches to the catalog model for the language, downloading it on
29
+ first use like any other model, and starts from that model's default speaker
30
+ (`defaultSpeakerByLanguage`) instead of the caller's speaker id. A language no
31
+ catalog model covers keeps the caller's model, so text is always spoken. The
32
+ response carries `X-Speech-Model` and `X-Speech-Language`.
20
33
 
21
34
  ## Ownership
22
35
 
@@ -68,9 +68,19 @@ export const LOCAL_STT_MODEL_CATALOG = {
68
68
  * Local text-to-speech models (sherpa-onnx OfflineTts). Downloaded and
69
69
  * managed through the same pipeline as the STT models.
70
70
  */
71
+ /**
72
+ * Local text-to-speech models (sherpa-onnx OfflineTts). Downloaded and
73
+ * managed through the same pipeline as the STT models.
74
+ *
75
+ * `languages` lists the languages a model speaks well; the speech service
76
+ * uses it to pick a model for the language a text is written in. Kokoro
77
+ * models carry speaker ids (`voices`); a Piper model is one voice for one
78
+ * language. `lexicon` entries are joined with commas for sherpa-onnx.
79
+ */
71
80
  export const LOCAL_TTS_MODEL_CATALOG = {
72
81
  'kokoro-en-v0_19': {
73
82
  type: 'kokoro',
83
+ languages: ['en'],
74
84
  archiveUrl:
75
85
  'https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/kokoro-en-v0_19.tar.bz2',
76
86
  extractedDir: 'kokoro-en-v0_19',
@@ -82,6 +92,188 @@ export const LOCAL_TTS_MODEL_CATALOG = {
82
92
  },
83
93
  description: 'Kokoro TTS (English, natural voices)',
84
94
  },
95
+ 'kokoro-multi-lang-v1_1': {
96
+ type: 'kokoro',
97
+ languages: ['zh', 'en'],
98
+ // sherpa-onnx wires this Kokoro build for Chinese and English only;
99
+ // speakers 0-2 are English, 3-102 Chinese.
100
+ defaultSpeakerByLanguage: { en: 0, zh: 3 },
101
+ archiveUrl:
102
+ 'https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/kokoro-multi-lang-v1_1.tar.bz2',
103
+ extractedDir: 'kokoro-multi-lang-v1_1',
104
+ files: {
105
+ model: 'model.onnx',
106
+ voices: 'voices.bin',
107
+ tokens: 'tokens.txt',
108
+ espeakData: 'espeak-ng-data',
109
+ lexiconEnglish: 'lexicon-us-en.txt',
110
+ lexiconChinese: 'lexicon-zh.txt',
111
+ },
112
+ lexicon: ['lexiconEnglish', 'lexiconChinese'],
113
+ description: 'Kokoro TTS (Chinese and English, 103 voices)',
114
+ },
115
+ // The larger `ukrainian_tts-medium` build is a character-level model
116
+ // (`phoneme_type: text`); sherpa-onnx phonemizes every Piper model through
117
+ // espeak-ng, which turns that one into noise. `vits-coqui-uk-mai` sounds
118
+ // better but reads Cyrillic only and drops every Latin word (file names,
119
+ // product names), which is unusable in a coding chat. Lada is an espeak
120
+ // model: small, but it reads mixed text.
121
+ 'piper-uk_UA-lada-x_low': {
122
+ type: 'vits',
123
+ languages: ['uk'],
124
+ archiveUrl:
125
+ 'https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/vits-piper-uk_UA-lada-x_low.tar.bz2',
126
+ extractedDir: 'vits-piper-uk_UA-lada-x_low',
127
+ files: {
128
+ model: 'uk_UA-lada-x_low.onnx',
129
+ tokens: 'tokens.txt',
130
+ espeakData: 'espeak-ng-data',
131
+ },
132
+ description: 'Piper TTS (Ukrainian)',
133
+ },
134
+ 'piper-de_DE-thorsten-medium': {
135
+ type: 'vits',
136
+ languages: ['de'],
137
+ archiveUrl:
138
+ 'https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/vits-piper-de_DE-thorsten-medium.tar.bz2',
139
+ extractedDir: 'vits-piper-de_DE-thorsten-medium',
140
+ files: {
141
+ model: 'de_DE-thorsten-medium.onnx',
142
+ tokens: 'tokens.txt',
143
+ espeakData: 'espeak-ng-data',
144
+ },
145
+ description: 'Piper TTS (German)',
146
+ },
147
+ 'piper-fr_FR-siwis-medium': {
148
+ type: 'vits',
149
+ languages: ['fr'],
150
+ archiveUrl:
151
+ 'https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/vits-piper-fr_FR-siwis-medium.tar.bz2',
152
+ extractedDir: 'vits-piper-fr_FR-siwis-medium',
153
+ files: {
154
+ model: 'fr_FR-siwis-medium.onnx',
155
+ tokens: 'tokens.txt',
156
+ espeakData: 'espeak-ng-data',
157
+ },
158
+ description: 'Piper TTS (French)',
159
+ },
160
+ 'piper-es_ES-davefx-medium': {
161
+ type: 'vits',
162
+ languages: ['es'],
163
+ archiveUrl:
164
+ 'https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/vits-piper-es_ES-davefx-medium.tar.bz2',
165
+ extractedDir: 'vits-piper-es_ES-davefx-medium',
166
+ files: {
167
+ model: 'es_ES-davefx-medium.onnx',
168
+ tokens: 'tokens.txt',
169
+ espeakData: 'espeak-ng-data',
170
+ },
171
+ description: 'Piper TTS (Spanish)',
172
+ },
173
+ 'piper-it_IT-paola-medium': {
174
+ type: 'vits',
175
+ languages: ['it'],
176
+ archiveUrl:
177
+ 'https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/vits-piper-it_IT-paola-medium.tar.bz2',
178
+ extractedDir: 'vits-piper-it_IT-paola-medium',
179
+ files: {
180
+ model: 'it_IT-paola-medium.onnx',
181
+ tokens: 'tokens.txt',
182
+ espeakData: 'espeak-ng-data',
183
+ },
184
+ description: 'Piper TTS (Italian)',
185
+ },
186
+ 'piper-pt_BR-faber-medium': {
187
+ type: 'vits',
188
+ languages: ['pt'],
189
+ archiveUrl:
190
+ 'https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/vits-piper-pt_BR-faber-medium.tar.bz2',
191
+ extractedDir: 'vits-piper-pt_BR-faber-medium',
192
+ files: {
193
+ model: 'pt_BR-faber-medium.onnx',
194
+ tokens: 'tokens.txt',
195
+ espeakData: 'espeak-ng-data',
196
+ },
197
+ description: 'Piper TTS (Portuguese (Brazil))',
198
+ },
199
+ 'piper-pl_PL-gosia-medium': {
200
+ type: 'vits',
201
+ languages: ['pl'],
202
+ archiveUrl:
203
+ 'https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/vits-piper-pl_PL-gosia-medium.tar.bz2',
204
+ extractedDir: 'vits-piper-pl_PL-gosia-medium',
205
+ files: {
206
+ model: 'pl_PL-gosia-medium.onnx',
207
+ tokens: 'tokens.txt',
208
+ espeakData: 'espeak-ng-data',
209
+ },
210
+ description: 'Piper TTS (Polish)',
211
+ },
212
+ 'piper-ru_RU-irina-medium': {
213
+ type: 'vits',
214
+ languages: ['ru'],
215
+ archiveUrl:
216
+ 'https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/vits-piper-ru_RU-irina-medium.tar.bz2',
217
+ extractedDir: 'vits-piper-ru_RU-irina-medium',
218
+ files: {
219
+ model: 'ru_RU-irina-medium.onnx',
220
+ tokens: 'tokens.txt',
221
+ espeakData: 'espeak-ng-data',
222
+ },
223
+ description: 'Piper TTS (Russian)',
224
+ },
225
+ 'piper-nl_NL-pim-medium': {
226
+ type: 'vits',
227
+ languages: ['nl'],
228
+ archiveUrl:
229
+ 'https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/vits-piper-nl_NL-pim-medium.tar.bz2',
230
+ extractedDir: 'vits-piper-nl_NL-pim-medium',
231
+ files: {
232
+ model: 'nl_NL-pim-medium.onnx',
233
+ tokens: 'tokens.txt',
234
+ espeakData: 'espeak-ng-data',
235
+ },
236
+ description: 'Piper TTS (Dutch)',
237
+ },
238
+ 'piper-cs_CZ-jirka-medium': {
239
+ type: 'vits',
240
+ languages: ['cs'],
241
+ archiveUrl:
242
+ 'https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/vits-piper-cs_CZ-jirka-medium.tar.bz2',
243
+ extractedDir: 'vits-piper-cs_CZ-jirka-medium',
244
+ files: {
245
+ model: 'cs_CZ-jirka-medium.onnx',
246
+ tokens: 'tokens.txt',
247
+ espeakData: 'espeak-ng-data',
248
+ },
249
+ description: 'Piper TTS (Czech)',
250
+ },
251
+ 'piper-tr_TR-dfki-medium': {
252
+ type: 'vits',
253
+ languages: ['tr'],
254
+ archiveUrl:
255
+ 'https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/vits-piper-tr_TR-dfki-medium.tar.bz2',
256
+ extractedDir: 'vits-piper-tr_TR-dfki-medium',
257
+ files: {
258
+ model: 'tr_TR-dfki-medium.onnx',
259
+ tokens: 'tokens.txt',
260
+ espeakData: 'espeak-ng-data',
261
+ },
262
+ description: 'Piper TTS (Turkish)',
263
+ },
264
+ 'piper-sv_SE-nst-medium': {
265
+ type: 'vits',
266
+ languages: ['sv'],
267
+ archiveUrl:
268
+ 'https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/vits-piper-sv_SE-nst-medium.tar.bz2',
269
+ extractedDir: 'vits-piper-sv_SE-nst-medium',
270
+ files: {
271
+ model: 'sv_SE-nst-medium.onnx',
272
+ tokens: 'tokens.txt',
273
+ espeakData: 'espeak-ng-data',
274
+ },
275
+ description: 'Piper TTS (Swedish)',
276
+ },
85
277
  };
86
278
 
87
279
  export const DEFAULT_LOCAL_STT_MODEL = 'parakeet-tdt-0.6b-v2-int8';
@@ -131,6 +323,34 @@ export function getLocalSttModelSpec(modelId) {
131
323
  };
132
324
  }
133
325
 
326
+ /**
327
+ * The local TTS model to use for a language, preferring the model the user
328
+ * selected when it speaks that language. Returns null when no catalog model
329
+ * covers the language, in which case callers keep the selected model.
330
+ * @param {string} language BCP-47 primary subtag (`uk`, `zh`...)
331
+ * @param {string} [preferredModelId]
332
+ * @returns {string | null}
333
+ */
334
+ export function resolveLocalTtsModelForLanguage(language, preferredModelId) {
335
+ const speaks = (modelId) => LOCAL_TTS_MODEL_CATALOG[modelId]?.languages?.includes(language) === true;
336
+ if (preferredModelId && speaks(preferredModelId)) return preferredModelId;
337
+ const candidate = LOCAL_TTS_MODEL_IDS.find(speaks);
338
+ return candidate ?? null;
339
+ }
340
+
341
+ /**
342
+ * The speaker id a model should use for a language when the caller's
343
+ * speaker was chosen for another language. `undefined` keeps the caller's
344
+ * speaker.
345
+ * @param {string} modelId
346
+ * @param {string} language
347
+ * @returns {number | undefined}
348
+ */
349
+ export function getLocalTtsDefaultSpeaker(modelId, language) {
350
+ const speaker = LOCAL_TTS_MODEL_CATALOG[modelId]?.defaultSpeakerByLanguage?.[language];
351
+ return Number.isInteger(speaker) ? speaker : undefined;
352
+ }
353
+
134
354
  /**
135
355
  * @param {string} modelsDir
136
356
  * @param {string} modelId
@@ -0,0 +1,42 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import {
3
+ DEFAULT_LOCAL_TTS_MODEL,
4
+ LOCAL_TTS_MODEL_CATALOG,
5
+ getLocalSttModelSpec,
6
+ getLocalTtsDefaultSpeaker,
7
+ resolveLocalTtsModelForLanguage,
8
+ } from './model-catalog.js';
9
+
10
+ describe('local TTS catalog', () => {
11
+ it('keeps the selected model when it speaks the language', () => {
12
+ expect(resolveLocalTtsModelForLanguage('en', DEFAULT_LOCAL_TTS_MODEL)).toBe(DEFAULT_LOCAL_TTS_MODEL);
13
+ expect(resolveLocalTtsModelForLanguage('zh', 'kokoro-multi-lang-v1_1')).toBe('kokoro-multi-lang-v1_1');
14
+ });
15
+
16
+ it('picks a catalog model for a language the selected model lacks', () => {
17
+ expect(resolveLocalTtsModelForLanguage('uk', DEFAULT_LOCAL_TTS_MODEL)).toBe('piper-uk_UA-lada-x_low');
18
+ expect(resolveLocalTtsModelForLanguage('zh', DEFAULT_LOCAL_TTS_MODEL)).toBe('kokoro-multi-lang-v1_1');
19
+ });
20
+
21
+ it('returns null for a language no model covers', () => {
22
+ expect(resolveLocalTtsModelForLanguage('xx', DEFAULT_LOCAL_TTS_MODEL)).toBeNull();
23
+ });
24
+
25
+ it('gives Chinese a Chinese speaker on the multi-language Kokoro', () => {
26
+ expect(getLocalTtsDefaultSpeaker('kokoro-multi-lang-v1_1', 'zh')).toBe(3);
27
+ expect(getLocalTtsDefaultSpeaker('kokoro-multi-lang-v1_1', 'en')).toBe(0);
28
+ expect(getLocalTtsDefaultSpeaker('piper-uk_UA-lada-x_low', 'uk')).toBeUndefined();
29
+ });
30
+
31
+ it('every TTS entry declares its languages and installable files', () => {
32
+ for (const [id, spec] of Object.entries(LOCAL_TTS_MODEL_CATALOG)) {
33
+ expect(spec.languages.length, id).toBeGreaterThan(0);
34
+ expect(spec.archiveUrl, id).toMatch(/^https:\/\/github\.com\/k2-fsa\/sherpa-onnx\/releases\/download\/tts-models\//);
35
+ const resolved = getLocalSttModelSpec(id);
36
+ expect(resolved.requiredFiles, id).toContain(spec.files.model);
37
+ for (const key of spec.lexicon ?? []) {
38
+ expect(spec.files[key], `${id} lexicon ${key}`).toBeTruthy();
39
+ }
40
+ }
41
+ });
42
+ });
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Sherpa-onnx offline TTS (Kokoro). Runs inside the dictation worker process
2
+ * Sherpa-onnx offline TTS (Kokoro and Piper/VITS). Runs inside the dictation worker process
3
3
  * only — never load the native addon in the main server process.
4
4
  */
5
5
 
@@ -23,20 +23,49 @@ function float32ToPcm16le(samples) {
23
23
  return Buffer.from(out.buffer, out.byteOffset, out.byteLength);
24
24
  }
25
25
 
26
+ /**
27
+ * sherpa-onnx model config for one catalog entry. Kokoro carries a voices
28
+ * bank (speaker ids) and optional lexicons; a Piper/VITS model is a single
29
+ * voice with espeak-ng phonemization.
30
+ * @param {{ modelDir: string, type?: string, files: Record<string, string>, lexicon?: string[] }} config
31
+ */
32
+ function buildModelConfig(config) {
33
+ const file = (key, label) => {
34
+ const filePath = path.join(config.modelDir, config.files[key]);
35
+ assertFileExists(filePath, label);
36
+ return filePath;
37
+ };
38
+ const modelPath = file('model', 'TTS model');
39
+ const tokensPath = file('tokens', 'TTS tokens');
40
+
41
+ if (config.type === 'vits') {
42
+ // Piper models phonemize through espeak-ng (`espeakData`); character
43
+ // models (Coqui) read the text directly and carry no espeak data.
44
+ const dataDir = config.files.espeakData ? file('espeakData', 'TTS espeak-ng dataDir') : '';
45
+ return { vits: { model: modelPath, tokens: tokensPath, ...(dataDir ? { dataDir } : {}), lengthScale: 1.0 } };
46
+ }
47
+
48
+ const dataDir = file('espeakData', 'TTS espeak-ng dataDir');
49
+ const voicesPath = file('voices', 'TTS voices');
50
+ const lexicon = (config.lexicon ?? []).map((key) => file(key, 'TTS lexicon')).join(',');
51
+ return {
52
+ kokoro: {
53
+ model: modelPath,
54
+ voices: voicesPath,
55
+ tokens: tokensPath,
56
+ dataDir,
57
+ lengthScale: 1.0,
58
+ ...(lexicon ? { lexicon } : {}),
59
+ },
60
+ };
61
+ }
62
+
26
63
  export class SherpaTtsEngine {
27
64
  /**
28
- * @param {{ modelDir: string, files: { model: string, voices: string, tokens: string, espeakData: string }, numThreads?: number }} config
65
+ * @param {{ modelDir: string, type?: string, files: Record<string, string>, lexicon?: string[], numThreads?: number }} config
29
66
  */
30
67
  constructor(config) {
31
- const modelPath = path.join(config.modelDir, config.files.model);
32
- const voicesPath = path.join(config.modelDir, config.files.voices);
33
- const tokensPath = path.join(config.modelDir, config.files.tokens);
34
- const dataDir = path.join(config.modelDir, config.files.espeakData);
35
-
36
- assertFileExists(modelPath, 'TTS model');
37
- assertFileExists(voicesPath, 'TTS voices');
38
- assertFileExists(tokensPath, 'TTS tokens');
39
- assertFileExists(dataDir, 'TTS espeak-ng dataDir');
68
+ const model = buildModelConfig(config);
40
69
 
41
70
  const sherpa = loadSherpaOnnxNode();
42
71
  if (typeof sherpa.OfflineTts !== 'function') {
@@ -44,15 +73,7 @@ export class SherpaTtsEngine {
44
73
  }
45
74
 
46
75
  this.tts = new sherpa.OfflineTts({
47
- model: {
48
- kokoro: {
49
- model: modelPath,
50
- voices: voicesPath,
51
- tokens: tokensPath,
52
- dataDir,
53
- lengthScale: 1.0,
54
- },
55
- },
76
+ model,
56
77
  numThreads: config.numThreads ?? 2,
57
78
  provider: 'cpu',
58
79
  maxNumSentences: 1,
@@ -102,7 +102,9 @@ function getTtsEngine(modelsDir, modelId) {
102
102
  const spec = getLocalSttModelSpec(modelId);
103
103
  const created = new SherpaTtsEngine({
104
104
  modelDir: getLocalSttModelDir(modelsDir, modelId),
105
+ type: spec.type,
105
106
  files: spec.files,
107
+ lexicon: spec.lexicon,
106
108
  numThreads: 2,
107
109
  });
108
110
  ttsEngines.set(key, created);
@@ -63,6 +63,8 @@ export function createDictationRuntime({
63
63
  model: typeof req.body?.model === 'string' ? req.body.model : undefined,
64
64
  speakerId: Number.isInteger(req.body?.speakerId) ? req.body.speakerId : undefined,
65
65
  speed: typeof req.body?.speed === 'number' ? req.body.speed : undefined,
66
+ language: req.body?.language === 'auto' ? 'auto' : undefined,
67
+ languageSample: typeof req.body?.languageSample === 'string' ? req.body.languageSample.slice(0, 4000) : undefined,
66
68
  });
67
69
  if (result.error) {
68
70
  res.status(503).json({
@@ -73,6 +75,8 @@ export function createDictationRuntime({
73
75
  return;
74
76
  }
75
77
  res.setHeader('Content-Type', result.format || 'audio/wav');
78
+ res.setHeader('X-Speech-Model', result.modelId);
79
+ if (result.language) res.setHeader('X-Speech-Language', result.language);
76
80
  res.send(result.audio);
77
81
  } catch (error) {
78
82
  res.status(500).json({ error: error?.message || 'Failed to synthesize speech' });
@@ -1,3 +1,4 @@
1
+ import { detectTextLanguage } from '../tts/language-detect.js';
1
2
  /**
2
3
  * Dictation service: resolves STT providers, tracks local model download
3
4
  * state, and exposes a readiness snapshot for the status route.
@@ -16,6 +17,8 @@ import { OpenAICompatibleTranscriptionSession } from './openai-compatible-sessio
16
17
  import {
17
18
  DEFAULT_LOCAL_STT_MODEL,
18
19
  DEFAULT_LOCAL_TTS_MODEL,
20
+ getLocalTtsDefaultSpeaker,
21
+ resolveLocalTtsModelForLanguage,
19
22
  LOCAL_STT_MODEL_CATALOG,
20
23
  LOCAL_STT_MODEL_IDS,
21
24
  LOCAL_TTS_MODEL_CATALOG,
@@ -220,10 +223,30 @@ export function createDictationService({ modelsDir }) {
220
223
  /**
221
224
  * Synthesize speech with the local TTS model. Returns WAV bytes, or a
222
225
  * readiness error while the model is missing/downloading.
223
- * @param {{ text: string, model?: string, speakerId?: number, speed?: number }} options
226
+ *
227
+ * With `language: 'auto'` the text's language decides the model: the
228
+ * caller's model when it speaks that language, otherwise the catalog
229
+ * model for it (downloaded on first use, reported as in-progress until it
230
+ * lands). The caller's speaker id is kept only on the caller's model; a
231
+ * substitute model starts from its own default speaker for the language.
232
+ * A language no catalog model covers keeps the caller's model, so text is
233
+ * never silently dropped.
234
+ * `languageSample` is the whole message the chunk belongs to (or a prefix
235
+ * of it): the language is judged on that, never on a short chunk alone.
236
+ * @param {{ text: string, model?: string, speakerId?: number, speed?: number, language?: string, languageSample?: string }} options
224
237
  */
225
- const synthesizeSpeech = async ({ text, model, speakerId, speed }) => {
226
- const modelId = isLocalTtsModelId(model) ? model : DEFAULT_LOCAL_TTS_MODEL;
238
+ const synthesizeSpeech = async ({ text, model, speakerId, speed, language, languageSample }) => {
239
+ const requestedModelId = isLocalTtsModelId(model) ? model : DEFAULT_LOCAL_TTS_MODEL;
240
+ let modelId = requestedModelId;
241
+ let resolvedLanguage = null;
242
+ if (language === 'auto') {
243
+ resolvedLanguage = detectTextLanguage(languageSample || text).language;
244
+ const forLanguage = resolveLocalTtsModelForLanguage(resolvedLanguage, requestedModelId);
245
+ if (forLanguage && forLanguage !== requestedModelId) {
246
+ modelId = forLanguage;
247
+ speakerId = getLocalTtsDefaultSpeaker(modelId, resolvedLanguage);
248
+ }
249
+ }
227
250
  const installed = await isLocalSttModelInstalled(modelsDir, modelId);
228
251
  if (!installed) {
229
252
  const state = downloadStates.get(modelId);
@@ -251,7 +274,7 @@ export function createDictationService({ modelsDir }) {
251
274
  speakerId,
252
275
  speed,
253
276
  });
254
- return { audio: result.audio, format: result.format };
277
+ return { audio: result.audio, format: result.format, modelId, language: resolvedLanguage };
255
278
  };
256
279
 
257
280
  /**