@openchamber/web 1.24.0 → 1.24.2

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 (227) hide show
  1. package/bin/cli.test.js +29 -6
  2. package/bin/lib/cli-http.js +5 -1
  3. package/bin/lib/commands-status.js +5 -0
  4. package/dist/assets/{CodeMirrorCommentWidgets-C9kV-n7r.js → CodeMirrorCommentWidgets-B_vBPQYm.js} +1 -1
  5. package/dist/assets/DiffView-Ce0oBXXQ.js +4 -0
  6. package/dist/assets/{FilesView-vjJx7VaM.js → FilesView-DtXueAWP.js} +6 -6
  7. package/dist/assets/GitView-k0hUF8KB.js +6 -0
  8. package/dist/assets/GuestAttachDialog-DIf2U85Z.js +1 -0
  9. package/dist/assets/{JsonTreeView-D_4G5X6-.js → JsonTreeView-4AnJ04Pw.js} +1 -1
  10. package/dist/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
  11. package/dist/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
  12. package/dist/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
  13. package/dist/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
  14. package/dist/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
  15. package/dist/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
  16. package/dist/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
  17. package/dist/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
  18. package/dist/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
  19. package/dist/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
  20. package/dist/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
  21. package/dist/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
  22. package/dist/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
  23. package/dist/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
  24. package/dist/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
  25. package/dist/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
  26. package/dist/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
  27. package/dist/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
  28. package/dist/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
  29. package/dist/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
  30. package/dist/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
  31. package/dist/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
  32. package/dist/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
  33. package/dist/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
  34. package/dist/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
  35. package/dist/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
  36. package/dist/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
  37. package/dist/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
  38. package/dist/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
  39. package/dist/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
  40. package/dist/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
  41. package/dist/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
  42. package/dist/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
  43. package/dist/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
  44. package/dist/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
  45. package/dist/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
  46. package/dist/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
  47. package/dist/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
  48. package/dist/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
  49. package/dist/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
  50. package/dist/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
  51. package/dist/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
  52. package/dist/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
  53. package/dist/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
  54. package/dist/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
  55. package/dist/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
  56. package/dist/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
  57. package/dist/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
  58. package/dist/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
  59. package/dist/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
  60. package/dist/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
  61. package/dist/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
  62. package/dist/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
  63. package/dist/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
  64. package/dist/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
  65. package/dist/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
  66. package/dist/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
  67. package/dist/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
  68. package/dist/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
  69. package/dist/assets/{LinearIssuesView-1uKhePfH.js → LinearIssuesView-z_9p2GuO.js} +1 -1
  70. package/dist/assets/{MarkdownImageGallery-Ix7N_2wp.js → MarkdownImageGallery-BC-BNN-s.js} +1 -1
  71. package/dist/assets/{MarkdownRendererImpl-Deel_y5S.js → MarkdownRendererImpl-DyaBTUbH.js} +6 -6
  72. package/dist/assets/{OnboardingScreen-ToIakxb_.js → OnboardingScreen-DKU_yTb6.js} +1 -1
  73. package/dist/assets/{PatchDiff-BjMgezr1.js → PatchDiff-DpGmHRnV.js} +1 -1
  74. package/dist/assets/PierreDiffViewer-CgLl_tp7.js +210 -0
  75. package/dist/assets/{PlanView-BGAzxDwD.js → PlanView-CrfB4qqY.js} +4 -4
  76. package/dist/assets/PluginPane-B5cn-jPy.js +3 -0
  77. package/dist/assets/SettingsView-DMKKwezx.js +29 -0
  78. package/dist/assets/SettingsWindow-DwbnVzOC.js +1 -0
  79. package/dist/assets/{SubmoduleDiffSummary--YFqK6Ih.js → SubmoduleDiffSummary-hkGcvs0E.js} +1 -1
  80. package/dist/assets/{ToolOutputDialog-DRWBvdaJ.js → ToolOutputDialog-DuoIOc0j.js} +6 -6
  81. package/dist/assets/{ToolPartDiffPreview-BxZJCU28.js → ToolPartDiffPreview-t1Bvq_2Y.js} +2 -2
  82. package/dist/assets/{VirtualizedFileDiff-DCXjBGRf.js → VirtualizedFileDiff-BK4aU5qJ.js} +1 -1
  83. package/dist/assets/{WalkthroughView-CfIPvWWa.js → WalkthroughView-Bk6TPNFw.js} +2 -2
  84. package/dist/assets/{appThemeRegistry-DDROzcUO.js → appThemeRegistry-DnOVbJjF.js} +1 -1
  85. package/dist/assets/commitAndPush-DLWNZkkY.js +1 -0
  86. package/dist/assets/{computeVirtualFileMetrics-DHgQIkUq.js → computeVirtualFileMetrics-BVTujWSX.js} +1 -1
  87. package/dist/assets/{de-CX_f-T5U.js → de-zEHaAIi3.js} +4 -4
  88. package/dist/assets/{es-BERmWNn_.js → es-CBDgEzgk.js} +4 -4
  89. package/dist/assets/{fr-BjYYE_-z.js → fr-DjiTptT_.js} +4 -4
  90. package/dist/assets/index-AgOdanig.css +1 -0
  91. package/dist/assets/index-B-2_X4DD.js +40 -0
  92. package/dist/assets/{index-WjufPkIV.js → index-CkA4p2IK.js} +1 -1
  93. package/dist/assets/{isDiffPlainText-D9faP70y.js → isDiffPlainText-D3yX_vx4.js} +1 -1
  94. package/dist/assets/{isFilePlainText-6qOcz5Ky.js → isFilePlainText-CZR9TcHV.js} +1 -1
  95. package/dist/assets/ja-CerMgj3r.js +16 -0
  96. package/dist/assets/{ko-Dty1aUod.js → ko-DHYDAze5.js} +4 -4
  97. package/dist/assets/main-BDka4W43.js +896 -0
  98. package/dist/assets/main-Dl7Dyge_.js +2 -0
  99. package/dist/assets/markdownCore-DFmr0rUR.js +5 -0
  100. package/dist/assets/miniChat-CLKQPPpO.js +2 -0
  101. package/dist/assets/mobile--giD2Q1L.js +2 -0
  102. package/dist/assets/{patchFileDiff-BvU6KOQC.js → patchFileDiff-DRh-AQvd.js} +1 -1
  103. package/dist/assets/{pl-CX-_ROkr.js → pl-BTB_93bq.js} +6 -6
  104. package/dist/assets/{pt-BR-DhRR1arx.js → pt-BR-BwA3oyCK.js} +4 -4
  105. package/dist/assets/renderElectronMiniChatApp-DmB7zpVK.js +2 -0
  106. package/dist/assets/renderMobileApp-pMfOuQfl.js +25 -0
  107. package/dist/assets/runtimeEndpointReset-Gqhmkm3U.js +25 -0
  108. package/dist/assets/{scheduledTasksApi-DW3xqMQ8.js → scheduledTasksApi-CeRAIUmW.js} +1 -1
  109. package/dist/assets/{shikiHighlight-DsxD9QEa.js → shikiHighlight-BfjuB3CD.js} +1 -1
  110. package/dist/assets/{textMateThemeFromAppTheme-Da7ed8qM.js → textMateThemeFromAppTheme-BP60t9SX.js} +1 -1
  111. package/dist/assets/tr-CcPsJoNM.js +7 -0
  112. package/dist/assets/{uk-CD21CXFV.js → uk-B68WibXi.js} +4 -4
  113. package/dist/assets/{useAppFontEffects-hfv2s6mZ.js → useAppFontEffects-DcdrFv2Z.js} +147 -147
  114. package/dist/assets/{useInlineCommentController-BmtfVbo8.js → useInlineCommentController-Cq4SUjsA.js} +2 -2
  115. package/dist/assets/useRootScrollLock-CSdR6Wnm.js +2 -0
  116. package/dist/assets/{vendor-codemirror-language-data-BPMJpOpT.js → vendor-codemirror-language-data-BFm1Ju2w.js} +2 -2
  117. package/dist/assets/vendor-katex-Cp579UoJ.css +1 -0
  118. package/dist/assets/{vendor-tanstack-react-virtual-g05Cx3z9.js → vendor-tanstack-react-virtual-ClYN8CzB.js} +1 -1
  119. package/dist/assets/{vendor-tanstack-virtual-core-Dubg10g5.js → vendor-tanstack-virtual-core-BewVQryB.js} +1 -1
  120. package/dist/assets/{vendor-zod-fZppILAM.js → vendor-zod-CgAdXWZO.js} +4 -4
  121. package/dist/assets/{web-components-U-hWbgJo.js → web-components-2vo9YsZc.js} +1 -1
  122. package/dist/assets/zh-CN-DbFHYXwP.js +16 -0
  123. package/dist/assets/{zh-TW-CRp5dJU2.js → zh-TW-DmXAwdty.js} +4 -4
  124. package/dist/index.html +6 -4
  125. package/dist/mini-chat.html +6 -4
  126. package/dist/mobile.html +6 -4
  127. package/package.json +6 -5
  128. package/server/index.js +29 -7
  129. package/server/lib/agent-tool/DOCUMENTATION.md +17 -4
  130. package/server/lib/agent-tool/runtime.js +62 -15
  131. package/server/lib/agent-tool/runtime.test.js +88 -2
  132. package/server/lib/changelog/update-notes.js +2 -1
  133. package/server/lib/changelog/update-notes.test.js +19 -0
  134. package/server/lib/event-stream/DOCUMENTATION.md +23 -0
  135. package/server/lib/event-stream/delta-coalescer.js +0 -0
  136. package/server/lib/event-stream/delta-coalescer.test.js +292 -0
  137. package/server/lib/event-stream/global-hub.js +53 -23
  138. package/server/lib/event-stream/global-hub.test.js +160 -0
  139. package/server/lib/event-stream/global-ws-bridge.js +1 -0
  140. package/server/lib/event-stream/index.js +4 -0
  141. package/server/lib/fs/DOCUMENTATION.md +2 -1
  142. package/server/lib/fs/routes.js +56 -4
  143. package/server/lib/fs/routes.test.js +116 -0
  144. package/server/lib/git/DOCUMENTATION.md +18 -5
  145. package/server/lib/git/routes.js +1 -1
  146. package/server/lib/git/serial-refresh.js +93 -0
  147. package/server/lib/git/serial-refresh.test.js +112 -0
  148. package/server/lib/git/service.js +325 -70
  149. package/server/lib/git/service.test.js +291 -0
  150. package/server/lib/github/pr-status.js +5 -5
  151. package/server/lib/github/pr-status.test.js +1 -1
  152. package/server/lib/github/routes.js +4 -4
  153. package/server/lib/guests/DOCUMENTATION.md +5 -3
  154. package/server/lib/guests/background.test.js +83 -0
  155. package/server/lib/guests/catalog.js +20 -9
  156. package/server/lib/guests/catalog.test.js +5 -5
  157. package/server/lib/guests/routes.js +2 -2
  158. package/server/lib/message-queue/DOCUMENTATION.md +10 -1
  159. package/server/lib/message-queue/runtime.js +21 -1
  160. package/server/lib/message-queue/runtime.test.js +52 -5
  161. package/server/lib/notifications/routes.js +5 -0
  162. package/server/lib/openchamber-sessions/routes.js +18 -18
  163. package/server/lib/openchamber-sessions/routes.test.js +49 -0
  164. package/server/lib/opencode/DOCUMENTATION.md +1 -1
  165. package/server/lib/opencode/bootstrap-runtime.js +1 -0
  166. package/server/lib/opencode/feature-routes-runtime.js +5 -0
  167. package/server/lib/opencode/session-runtime.js +68 -0
  168. package/server/lib/opencode/session-runtime.test.js +43 -0
  169. package/server/lib/opencode/settings-helpers.js +3 -0
  170. package/server/lib/opencode/settings-registry.json +8 -0
  171. package/server/lib/permission-auto-accept/DOCUMENTATION.md +8 -0
  172. package/server/lib/permission-auto-accept/runtime.js +13 -0
  173. package/server/lib/permission-auto-accept/runtime.test.js +37 -1
  174. package/server/lib/projects/project-config.js +2 -2
  175. package/server/lib/realtime-proxy-terminal.test.js +150 -0
  176. package/server/lib/realtime-proxy.js +2 -0
  177. package/server/lib/routing/DOCUMENTATION.md +83 -0
  178. package/server/lib/routing/defaults.js +98 -0
  179. package/server/lib/routing/feature-flag.js +11 -0
  180. package/server/lib/routing/history.js +34 -0
  181. package/server/lib/routing/jev.js +98 -0
  182. package/server/lib/routing/routes.http.test.js +100 -0
  183. package/server/lib/routing/routes.js +81 -0
  184. package/server/lib/routing/runtime.js +217 -0
  185. package/server/lib/routing/runtime.test.js +188 -0
  186. package/server/lib/routing/store.js +249 -0
  187. package/server/lib/routing/store.test.js +96 -0
  188. package/server/lib/scheduled-tasks/runtime.js +2 -2
  189. package/server/lib/scheduled-tasks/runtime.test.js +14 -0
  190. package/server/lib/security/request-security.js +9 -5
  191. package/server/lib/security/request-security.test.js +37 -0
  192. package/server/lib/small-model/DOCUMENTATION.md +14 -2
  193. package/server/lib/small-model/call.js +37 -6
  194. package/server/lib/small-model/call.test.js +182 -0
  195. package/server/lib/terminal/DOCUMENTATION.md +21 -2
  196. package/server/lib/terminal/runtime.js +10 -3
  197. package/server/lib/terminal/runtime.test.js +22 -0
  198. package/server/lib/terminal/shutdown.js +106 -0
  199. package/server/lib/terminal/shutdown.test.js +84 -0
  200. package/server/lib/tts/service.test.js +78 -0
  201. package/server/lib/ui-auth/DOCUMENTATION.md +8 -0
  202. package/server/lib/ui-auth/session-cookie.js +51 -0
  203. package/server/lib/ui-auth/session-cookie.test.js +46 -0
  204. package/server/lib/ui-auth/ui-auth.js +13 -9
  205. package/server/lib/ui-auth/ui-auth.test.js +56 -0
  206. package/dist/assets/DiffView-B7YkbY-u.js +0 -4
  207. package/dist/assets/DirtyBranchSwitchDialog-CU0A93Zx.js +0 -1
  208. package/dist/assets/GitView-BLhlMYEY.js +0 -6
  209. package/dist/assets/GuestAttachDialog-B-fwE8r3.js +0 -3
  210. package/dist/assets/PierreDiffViewer-53Ghfnlr.js +0 -161
  211. package/dist/assets/SettingsView-n2X-jfBB.js +0 -29
  212. package/dist/assets/SettingsWindow-Bi8LE9XI.js +0 -1
  213. package/dist/assets/index-DpzTz2UH.css +0 -1
  214. package/dist/assets/index-Dy8xgawx.js +0 -40
  215. package/dist/assets/ja-DxqeAk9N.js +0 -16
  216. package/dist/assets/main-BOYSXfYn.js +0 -896
  217. package/dist/assets/main-Bjcre_GE.js +0 -2
  218. package/dist/assets/markdownCore-DPrwM1rU.js +0 -5
  219. package/dist/assets/miniChat-Dz_bPgMc.js +0 -2
  220. package/dist/assets/mobile-BbZPBJrK.js +0 -2
  221. package/dist/assets/renderElectronMiniChatApp-uNEUkeAI.js +0 -2
  222. package/dist/assets/renderMobileApp-BK1kFlcJ.js +0 -25
  223. package/dist/assets/runtimeEndpointReset-BULHvOwb.js +0 -25
  224. package/dist/assets/tr-cIQtYBpg.js +0 -7
  225. package/dist/assets/useRootScrollLock-Cwc4kSl2.js +0 -1
  226. package/dist/assets/zh-CN-BWvlPHY-.js +0 -16
  227. /package/dist/assets/{vendor-katex-k3Ppq1Ha.js → vendor-katex-CHD9BdDO.js} +0 -0
@@ -772,6 +772,188 @@ describe('callSmallModel — Google thinking configuration', () => {
772
772
  });
773
773
  });
774
774
 
775
+ describe('callSmallModel — OpenAI-compatible thinking toggle', () => {
776
+ let fetchMock;
777
+ let originalFetch;
778
+
779
+ beforeEach(() => {
780
+ fetchMock = vi.fn();
781
+ originalFetch = globalThis.fetch;
782
+ globalThis.fetch = fetchMock;
783
+ readConfig.mockReset();
784
+ readConfig.mockReturnValue({});
785
+ readConfigLayers.mockReset();
786
+ readConfigLayers.mockReturnValue({ mergedConfig: {} });
787
+ });
788
+
789
+ afterEach(() => {
790
+ globalThis.fetch = originalFetch;
791
+ });
792
+
793
+ const requestBody = async ({ providerID, modelID }) => {
794
+ fetchMock.mockResolvedValue(ok('done'));
795
+ await callSmallModel({
796
+ auth: { [providerID]: { type: 'api', key: 'sk-test' } },
797
+ catalog: { [providerID]: { id: providerID, api: 'https://provider.test/v1', models: {} } },
798
+ workingDirectory: '/proj',
799
+ providerID,
800
+ modelID,
801
+ prompt: 'summarize',
802
+ });
803
+ return JSON.parse(lastCall(fetchMock).init.body);
804
+ };
805
+
806
+ it('does not send the thinking field for a GLM model served by OpenCode Go', async () => {
807
+ const body = await requestBody({ providerID: 'opencode-go', modelID: 'glm-5.3-flash' });
808
+ expect(body.thinking).toBeUndefined();
809
+ });
810
+
811
+ it('disables thinking on the Z.ai and Zhipu endpoints', async () => {
812
+ const zai = await requestBody({ providerID: 'zai-coding-plan', modelID: 'glm-5.3-flash' });
813
+ expect(zai.thinking).toEqual({ type: 'disabled' });
814
+ const zhipu = await requestBody({ providerID: 'zhipuai', modelID: 'glm-5.3-flash' });
815
+ expect(zhipu.thinking).toEqual({ type: 'disabled' });
816
+ });
817
+
818
+ it('keeps the GLM switch for a custom-named provider pointed at a Z.ai endpoint', async () => {
819
+ fetchMock.mockResolvedValue(ok('done'));
820
+ await callSmallModel({
821
+ auth: { 'my-glm': { type: 'api', key: 'sk-test' } },
822
+ catalog: { 'my-glm': { id: 'my-glm', api: 'https://api.z.ai/api/coding/paas/v4', models: {} } },
823
+ workingDirectory: '/proj',
824
+ providerID: 'my-glm',
825
+ modelID: 'glm-5.3-flash',
826
+ prompt: 'summarize',
827
+ });
828
+ expect(JSON.parse(lastCall(fetchMock).init.body).thinking).toEqual({ type: 'disabled' });
829
+ });
830
+
831
+ const minimaxBody = async (providerEntry) => {
832
+ fetchMock.mockResolvedValue(ok('done'));
833
+ await callSmallModel({
834
+ auth: { host: { type: 'api', key: 'sk-test' } },
835
+ catalog: { host: { id: 'host', api: 'https://provider.test/v1', ...providerEntry } },
836
+ workingDirectory: '/proj',
837
+ providerID: 'host',
838
+ modelID: 'minimax-m3',
839
+ prompt: 'summarize',
840
+ });
841
+ return JSON.parse(lastCall(fetchMock).init.body);
842
+ };
843
+
844
+ it('disables MiniMax M3 thinking behind an OpenAI-compatible adapter', async () => {
845
+ const body = await minimaxBody({ npm: '@ai-sdk/openai-compatible', models: {} });
846
+ expect(body.thinking).toEqual({ type: 'disabled' });
847
+ });
848
+
849
+ it('honors a model-level adapter over the provider one for MiniMax M3', async () => {
850
+ const body = await minimaxBody({
851
+ npm: '@ai-sdk/deepinfra',
852
+ models: { 'minimax-m3': { provider: { npm: '@ai-sdk/anthropic' } } },
853
+ });
854
+ expect(body.thinking).toEqual({ type: 'disabled' });
855
+ });
856
+
857
+ it('does not send the MiniMax M3 switch through an adapter that has none', async () => {
858
+ const body = await minimaxBody({ npm: '@ai-sdk/deepinfra', models: {} });
859
+ expect(body.thinking).toBeUndefined();
860
+ });
861
+
862
+ it('treats a provider with no reported adapter as OpenAI-compatible for MiniMax M3', async () => {
863
+ const body = await minimaxBody({ models: {} });
864
+ expect(body.thinking).toEqual({ type: 'disabled' });
865
+ });
866
+ });
867
+
868
+ describe('callSmallModel — providers with an SDK-owned endpoint', () => {
869
+ let fetchMock;
870
+ let originalFetch;
871
+
872
+ beforeEach(() => {
873
+ fetchMock = vi.fn();
874
+ originalFetch = globalThis.fetch;
875
+ globalThis.fetch = fetchMock;
876
+ readConfig.mockReset();
877
+ readConfig.mockReturnValue({});
878
+ readConfigLayers.mockReset();
879
+ readConfigLayers.mockReturnValue({ mergedConfig: {} });
880
+ });
881
+
882
+ afterEach(() => {
883
+ globalThis.fetch = originalFetch;
884
+ });
885
+
886
+ it.each([
887
+ ['groq', 'https://api.groq.com/openai/v1'],
888
+ ['xai', 'https://api.x.ai/v1'],
889
+ ['mistral', 'https://api.mistral.ai/v1'],
890
+ ['cerebras', 'https://api.cerebras.ai/v1'],
891
+ ['togetherai', 'https://api.together.xyz/v1'],
892
+ ['deepinfra', 'https://api.deepinfra.com/v1/openai'],
893
+ ['perplexity', 'https://api.perplexity.ai'],
894
+ ['cohere', 'https://api.cohere.ai/compatibility/v1'],
895
+ ])('calls %s at its default endpoint when the catalog has no api URL', async (providerID, baseURL) => {
896
+ fetchMock.mockResolvedValue(ok('done'));
897
+
898
+ const text = await callSmallModel({
899
+ auth: { [providerID]: { type: 'api', key: 'key-test' } },
900
+ catalog: { [providerID]: { id: providerID, api: null, models: {} } },
901
+ workingDirectory: '/proj',
902
+ providerID,
903
+ modelID: 'some-model',
904
+ prompt: 'summarize',
905
+ });
906
+
907
+ expect(text).toBe('done');
908
+ expect(lastCall(fetchMock).url).toBe(`${baseURL}/chat/completions`);
909
+ });
910
+
911
+ it('prefers a catalog api URL over the default endpoint', async () => {
912
+ fetchMock.mockResolvedValue(ok('done'));
913
+
914
+ await callSmallModel({
915
+ auth: { groq: { type: 'api', key: 'key-test' } },
916
+ catalog: { groq: { id: 'groq', api: 'https://catalog.test/v1', models: {} } },
917
+ workingDirectory: '/proj',
918
+ providerID: 'groq',
919
+ modelID: 'some-model',
920
+ prompt: 'summarize',
921
+ });
922
+
923
+ expect(lastCall(fetchMock).url).toBe('https://catalog.test/v1/chat/completions');
924
+ });
925
+
926
+ it('prefers a configured baseURL over the default endpoint', async () => {
927
+ readConfig.mockReturnValue({
928
+ provider: { groq: { options: { baseURL: 'https://proxy.test/v1' } } },
929
+ });
930
+ fetchMock.mockResolvedValue(ok('done'));
931
+
932
+ await callSmallModel({
933
+ auth: { groq: { type: 'api', key: 'key-test' } },
934
+ catalog: { groq: { id: 'groq', api: null, models: {} } },
935
+ workingDirectory: '/proj',
936
+ providerID: 'groq',
937
+ modelID: 'some-model',
938
+ prompt: 'summarize',
939
+ });
940
+
941
+ expect(lastCall(fetchMock).url).toBe('https://proxy.test/v1/chat/completions');
942
+ });
943
+
944
+ it('still fails clearly for a provider with no endpoint anywhere', async () => {
945
+ await expect(callSmallModel({
946
+ auth: { mystery: { type: 'api', key: 'sk-test' } },
947
+ catalog: {},
948
+ workingDirectory: '/proj',
949
+ providerID: 'mystery',
950
+ modelID: 'some-model',
951
+ prompt: 'summarize',
952
+ })).rejects.toThrow('has no known API base URL');
953
+ expect(fetchMock).not.toHaveBeenCalled();
954
+ });
955
+ });
956
+
775
957
  describe('callSmallModel — GitHub Copilot endpoint routing', () => {
776
958
  let fetchMock;
777
959
  let originalFetch;
@@ -2,7 +2,7 @@
2
2
 
3
3
  ## Ownership
4
4
 
5
- `runtime.js` owns terminal identity, PTY processes, launch mode, session purpose, ordered output, bounded scrollback, WebSocket attachments, and lifecycle routes. `shells.js` discovers executable shell families, resolves the persisted shell ID, and builds the per-shell argv for interactive versus command launches. Clients own tab arrangement. Interactive terminals use stable IDs; project actions keep a stable UI tab and allocate a fresh terminal ID for each command execution. Electron uses this same runtime in-process; VS Code returns an explicit unsupported error.
5
+ `runtime.js` owns terminal identity, PTY processes, launch mode, session purpose, ordered output, bounded scrollback, WebSocket attachments, and lifecycle routes. `shutdown.js` owns bounded runtime-wide process cleanup. `shells.js` discovers executable shell families, resolves the persisted shell ID, and builds the per-shell argv for interactive versus command launches. Clients own tab arrangement. Interactive terminals use stable IDs; project actions keep a stable UI tab and allocate a fresh terminal ID for each command execution. Electron uses this same runtime in-process; VS Code returns an explicit unsupported error.
6
6
 
7
7
  ## Protocol
8
8
 
@@ -39,8 +39,9 @@ HTTP remains the authenticated command plane for create, resize, appearance upda
39
39
  - Restarts are serialized per terminal. Each restart spawns and wires the replacement before terminating the old process, retaining the terminal ID. Command-mode sessions reject restart with HTTP 400 instead of silently turning into interactive shells with stale action metadata.
40
40
  - A restart rechecks session ownership before and after PTY creation. Close, force-kill, idle removal, or shutdown can invalidate it while spawn is pending. A late replacement is terminated instead of being attached to a retired session.
41
41
  - A delete that arrives while create is still pending leaves a cancellation tombstone. When the PTY arrives, the runtime terminates it immediately, never inserts the session into the live map, and returns a create error while the delete still succeeds.
42
- - Close uses SIGTERM with bounded SIGKILL escalation. Force-kill, idle cleanup, and runtime shutdown terminate process groups immediately where supported. Removal explicitly sends a fatal scoped closure and evicts client projections even when a PTY backend fails to emit `onExit`; attached terminals are not considered idle.
42
+ - Close uses SIGTERM with bounded SIGKILL escalation. Force-kill and idle cleanup terminate process groups immediately where supported. Removal explicitly sends a fatal scoped closure and evicts client projections even when a PTY backend fails to emit `onExit`; attached terminals are not considered idle.
43
43
  - Shutdown is single-flight, rejects new creates, cancels pending creates, and waits for pending creates and restarts before clearing live sessions. A PTY that arrives during shutdown follows the same cancellation cleanup as a pending create that was explicitly closed.
44
+ - On POSIX, shutdown disconnects input and gives terminal workloads a shared 20-second SIGTERM grace. Process-table snapshots retain descendant ownership across shell exit and separate job-control groups; PID start times guard against reused PIDs. Linux reads `/proc` directly so minimal containers do not need `ps`. Shells remain open until the workloads exit, then receive SIGHUP. An exec'ed server receives SIGTERM and the full grace even though it occupies the shell PID. Remaining processes receive SIGKILL at the deadline. A process-table failure warns and forces known owned processes closed. Windows retains ConPTY-owned teardown because it has no POSIX signal protocol.
44
45
 
45
46
  ## Security And Relay
46
47
 
@@ -52,5 +53,23 @@ Run:
52
53
 
53
54
  ```sh
54
55
  bun test packages/web/server/lib/terminal/runtime.test.js packages/web/server/lib/terminal/terminal-ws-protocol.test.js
56
+ bun run --cwd packages/web test server/lib/terminal/shutdown.test.js
55
57
  bun test packages/web/server/lib/ui-auth/ui-auth.test.js packages/web/server/lib/relay/cross-compat.test.js
56
58
  ```
59
+
60
+ The #3389 macOS ARM64 reproduction used real Electron 43.7.0 PTYs and HTTP
61
+ servers with signal handlers that took 15 seconds to finish cleanup. On the
62
+ baseline, File > Restart and Quit sent SIGKILL to the exec'ed server within
63
+ 3–4 ms; a foreground child in another process group received SIGHUP and outlived
64
+ Electron. After the fix, both workloads completed after SIGTERM before Electron
65
+ exited, in bundled and HMR runs. A noncooperative workload was killed after the
66
+ shared 20-second deadline.
67
+
68
+ Packaged test builds 1.24.90 and 1.24.91 exercised the real macOS Squirrel install
69
+ with a loopback feed, isolated app identity/profile, and a shared test signing
70
+ requirement. Both the normal update and closing the window during cleanup
71
+ installed and relaunched N+1 after the terminal workloads finished. The installed
72
+ ASAR matched N+1, and OpenCode remained bundled after its own restart. A rejected
73
+ signature also reached the installer error handler after the 15-second cleanup.
74
+ Linux ARM64 process regressions pass without `ps` installed. Native Windows
75
+ ConPTY and Linux Electron installer behavior were not exercised for this fix.
@@ -11,6 +11,7 @@ import { sanitizeTerminalHistoryChunk } from './history.js';
11
11
  import { consumeTerminalThemeQueries, terminalThemeModeReport } from './theme-response.js';
12
12
  import { buildTerminalShellLaunch, createTerminalShellResolver, normalizeTerminalShell } from './shells.js';
13
13
  import { stripAppImageArgv0Leak, resolvePosixPtyLaunch } from '../inherited-env.js';
14
+ import { shutdownTerminalProcesses } from './shutdown.js';
14
15
 
15
16
  const MAX_SESSIONS = 20;
16
17
  const MAX_HISTORY_BYTES = 512 * 1024;
@@ -91,7 +92,7 @@ const trimHistory = (history) => {
91
92
  export function createTerminalRuntime({
92
93
  app, server, fs, path, uiAuthController, buildAugmentedPath, searchPathFor, isExecutable,
93
94
  isRequestOriginAllowed, rejectWebSocketUpgrade, TERMINAL_INPUT_WS_HEARTBEAT_INTERVAL_MS,
94
- loadPtyProvider, terminalTerminationGraceMs = TERMINATION_GRACE_MS,
95
+ loadPtyProvider, terminalTerminationGraceMs = TERMINATION_GRACE_MS, shutdownProcesses = shutdownTerminalProcesses,
95
96
  }) {
96
97
  const sessions = new Map();
97
98
  const pendingSessionCreates = new Map();
@@ -136,7 +137,7 @@ export function createTerminalRuntime({
136
137
  const launch = resolvePosixPtyLaunch(shellLaunch.executable, shellLaunch.args);
137
138
  const options = { name: 'xterm-256color', cwd, cols, rows, env };
138
139
  if (process.platform === 'win32') options.useConpty = true;
139
- return { process: await provider.spawn(launch.executable, launch.args, options), backend: provider.backend, shell: resolvedShell.id, loginShell };
140
+ return { process: await provider.spawn(launch.executable, launch.args, options), backend: provider.backend, shell: resolvedShell.id, shellExecutable: executable, loginShell };
140
141
  } catch (error) { lastError = error; }
141
142
  }
142
143
  throw lastError ?? new Error('No executable shell found');
@@ -274,6 +275,7 @@ export function createTerminalRuntime({
274
275
  if (clear) { session.history = ''; session.pendingHistoryControlSequence = ''; session.pendingThemeControlSequence = ''; session.themeModeEnabled = false; }
275
276
  session.cwd = cwd; session.cols = cols; session.rows = rows; session.process = spawned.process;
276
277
  session.backend = spawned.backend; session.shell = spawned.shell; session.loginShell = spawned.loginShell; session.status = 'running'; session.exitCode = null; session.signal = null;
278
+ session.shellExecutable = spawned.shellExecutable;
277
279
  session.mode = mode; session.command = mode === COMMAND_TERMINAL_MODE ? command : null;
278
280
  session.purpose = purpose;
279
281
  session.themeMode = themeMode === 'light' ? 'light' : 'dark'; session.terminalBackground = terminalBackground; session.terminalForeground = terminalForeground;
@@ -519,6 +521,7 @@ export function createTerminalRuntime({
519
521
  throw new Error('Terminal session was closed during restart');
520
522
  }
521
523
  session.process = spawned.process; session.backend = spawned.backend; session.shell = spawned.shell; session.loginShell = spawned.loginShell; session.cwd = cwd; session.cols = cols; session.rows = rows;
524
+ session.shellExecutable = spawned.shellExecutable;
522
525
  session.history = ''; session.pendingHistoryControlSequence = ''; session.pendingThemeControlSequence = ''; session.themeModeEnabled = false; session.status = 'running'; session.exitCode = null; session.signal = null; session.eventQueue.length = 0;
523
526
  session.themeMode = themeMode === 'light' ? 'light' : 'dark'; session.terminalBackground = terminalBackground; session.terminalForeground = terminalForeground;
524
527
  wire(session, spawned.process); void terminateProcess(oldProcess); publish(session, { t: 'restarted', history: '' });
@@ -569,13 +572,17 @@ export function createTerminalRuntime({
569
572
 
570
573
  const stop = async () => {
571
574
  server.off('upgrade', upgradeHandler); clearInterval(idleSweep);
575
+ for (const client of wsServer?.clients ?? []) client.terminate();
572
576
  for (const pending of pendingSessionCreates.values()) pending.cancelled = true;
573
577
  await Promise.allSettled([
574
578
  ...[...pendingSessionCreates.values()].map((pending) => pending.promise),
575
579
  ...pendingSessionRestarts.values(),
576
580
  ]);
577
- for (const session of sessions.values()) void terminateProcess(session.process, true);
581
+ const terminals = [...sessions.values()]
582
+ .filter(session => session.status === 'running' && session.process)
583
+ .map(session => ({ process: session.process, shellExecutable: session.shellExecutable }));
578
584
  sessions.clear();
585
+ await shutdownProcesses(terminals);
579
586
  await Promise.allSettled([...pendingTerminations]);
580
587
  if (!wsServer) return;
581
588
  for (const client of wsServer.clients) client.terminate();
@@ -134,6 +134,7 @@ function createRuntime(server, overrides = {}) {
134
134
  isExecutable: () => false,
135
135
  isRequestOriginAllowed: async () => true,
136
136
  rejectWebSocketUpgrade() {},
137
+ shutdownProcesses: async terminals => { for (const terminal of terminals) terminal.process.kill('SIGKILL'); },
137
138
  TERMINAL_INPUT_WS_HEARTBEAT_INTERVAL_MS: 30_000,
138
139
  TERMINAL_INPUT_WS_REBIND_WINDOW_MS: 1_000,
139
140
  TERMINAL_INPUT_WS_MAX_REBINDS_PER_WINDOW: 3,
@@ -229,6 +230,27 @@ describe('terminal runtime', () => {
229
230
  await harness.runtime.shutdown();
230
231
  });
231
232
 
233
+ it('joins terminal cleanup and retires sessions before waiting for shutdown', async () => {
234
+ const gate = deferred();
235
+ let terminals;
236
+ const harness = createHarness({ shutdownProcesses: async current => { terminals = current; await gate.promise; } });
237
+ await harness.routes.post.get('/api/terminal/create')({ body: { sessionId: 'running', cwd: '/repo' } }, createResponse());
238
+ let done = false;
239
+ const closing = harness.runtime.shutdown();
240
+ expect(harness.runtime.shutdown()).toBe(closing);
241
+ closing.then(() => { done = true; });
242
+ await new Promise(resolve => setImmediate(resolve));
243
+ expect(terminals).toHaveLength(1);
244
+ expect(terminals[0].process).toBe(harness.processes[0]);
245
+ expect(done).toBe(false);
246
+ const later = createResponse();
247
+ await harness.routes.post.get('/api/terminal/create')({ body: { sessionId: 'later', cwd: '/repo' } }, later);
248
+ expect(later.statusCode).toBe(400);
249
+ gate.resolve();
250
+ await closing;
251
+ expect(done).toBe(true);
252
+ });
253
+
232
254
  for (const removal of ['close', 'force-kill']) {
233
255
  it(`reaps a replacement PTY when ${removal} wins a pending restart`, async () => {
234
256
  const gate = { promise: Promise.resolve() };
@@ -0,0 +1,106 @@
1
+ import { execFile } from 'node:child_process';
2
+ import fs from 'node:fs/promises';
3
+ import path from 'node:path';
4
+ import { promisify } from 'node:util';
5
+
6
+ const execFileAsync = promisify(execFile);
7
+ const SHUTDOWN_GRACE_MS = 20_000;
8
+
9
+ // Job-control shells give foreground/background jobs their own process groups.
10
+ // Killing only -pty.pid misses those jobs; closing the PTY first sends SIGHUP.
11
+ const readProcesses = async () => {
12
+ // Minimal server/container installations need not ship procps.
13
+ if (process.platform === 'linux') {
14
+ const processes = new Map();
15
+ for (const entry of await fs.readdir('/proc')) {
16
+ if (!/^\d+$/.test(entry)) continue;
17
+ let stat;
18
+ try { stat = await fs.readFile(`/proc/${entry}/stat`, 'utf8'); }
19
+ catch (error) { if (error.code === 'ENOENT' || error.code === 'ESRCH') continue; throw error; }
20
+ const end = stat.lastIndexOf(')');
21
+ const fields = stat.slice(end + 2).trim().split(/\s+/);
22
+ const pid = Number(entry);
23
+ processes.set(pid, { pid, parent: Number(fields[1]), group: Number(fields[2]), zombie: fields[0] === 'Z', started: fields[19], command: stat.slice(stat.indexOf('(') + 1, end) });
24
+ }
25
+ return processes;
26
+ }
27
+ const { stdout } = await execFileAsync('/bin/ps', ['-axo', 'pid=,ppid=,pgid=,stat=,lstart=,comm='], { timeout: 1000, maxBuffer: 4 * 1024 * 1024 });
28
+ return new Map(stdout.trim().split('\n').map(line => {
29
+ const fields = line.trim().split(/\s+/);
30
+ return [Number(fields[0]), { pid: Number(fields[0]), parent: Number(fields[1]), group: Number(fields[2]), zombie: fields[3].startsWith('Z'), started: fields.slice(4, 9).join(' '), command: fields.slice(9).join(' ') }];
31
+ }));
32
+ };
33
+
34
+ const signal = (pid, name) => {
35
+ try { process.kill(pid, name); } catch (error) { if (error.code !== 'ESRCH') throw error; }
36
+ };
37
+
38
+ export async function shutdownTerminalProcesses(terminals, { graceMs = SHUTDOWN_GRACE_MS } = {}) {
39
+ if (!terminals.length) return;
40
+ // ConPTY has no POSIX signal protocol. Its backend owns tree teardown.
41
+ if (process.platform === 'win32') {
42
+ for (const { process: pty } of terminals) {
43
+ try { pty.kill(); } catch { /* already gone; other terminals still need cleanup */ }
44
+ }
45
+ return;
46
+ }
47
+
48
+ const deadline = Date.now() + graceMs;
49
+ const owned = new Map();
50
+ const shells = new Map();
51
+ try {
52
+ let snapshot = await readProcesses();
53
+ for (const terminal of terminals) {
54
+ const current = snapshot.get(terminal.process.pid);
55
+ if (!current || current.zombie) continue;
56
+ owned.set(current.pid, { ...current, terminal: current.pid });
57
+ // An exec'ed server occupies the shell PID, but must get the same grace
58
+ // as a child. Only an actual shell is held open until its jobs finish.
59
+ if (path.basename(current.command) === path.basename(terminal.shellExecutable)) shells.set(current.pid, terminal.process);
60
+ }
61
+ const signalled = new Set();
62
+ while (owned.size) {
63
+ for (const [pid, previous] of owned) {
64
+ const current = snapshot.get(pid);
65
+ if (!current || current.zombie || current.started !== previous.started) { owned.delete(pid); shells.delete(pid); }
66
+ else if (current.command !== previous.command) shells.delete(pid);
67
+ }
68
+ // Retain descendants before signalling anything, including separate job
69
+ // groups and children still cleaning up after their parent has exited.
70
+ let added;
71
+ do {
72
+ added = false;
73
+ for (const current of snapshot.values()) {
74
+ if (!current.zombie && !owned.has(current.pid) && owned.has(current.parent)) {
75
+ owned.set(current.pid, { ...current, terminal: owned.get(current.parent).terminal });
76
+ added = true;
77
+ }
78
+ }
79
+ } while (added);
80
+ for (const pid of owned.keys()) {
81
+ if (!shells.has(pid) && !signalled.has(pid)) { signal(pid, 'SIGTERM'); signalled.add(pid); }
82
+ }
83
+ for (const [pid, pty] of shells) {
84
+ const hasJobs = [...owned.values()].some(current => current.terminal === pid && current.pid !== pid);
85
+ if (!hasJobs && !signalled.has(pid)) { pty.kill('SIGHUP'); signalled.add(pid); }
86
+ }
87
+ if (!owned.size) return;
88
+ if (Date.now() >= deadline) {
89
+ for (const current of owned.values()) {
90
+ if (current.group === current.pid) signal(-current.group, 'SIGKILL');
91
+ signal(current.pid, 'SIGKILL');
92
+ }
93
+ return;
94
+ }
95
+ await new Promise(resolve => setTimeout(resolve, 250));
96
+ snapshot = await readProcesses();
97
+ }
98
+ } catch (error) {
99
+ // A failed process-table read is not evidence that the jobs exited.
100
+ console.warn('Terminal graceful shutdown failed; forcing owned PTYs closed:', error.message);
101
+ for (const pid of owned.keys()) { try { signal(pid, 'SIGKILL'); } catch { /* best effort */ } }
102
+ for (const { process: pty } of terminals) {
103
+ try { pty.kill('SIGKILL'); } catch { /* continue with the remaining PTYs */ }
104
+ }
105
+ }
106
+ }
@@ -0,0 +1,84 @@
1
+ import assert from 'node:assert/strict';
2
+ import { spawn } from 'node:child_process';
3
+ import fs from 'node:fs/promises';
4
+ import os from 'node:os';
5
+ import path from 'node:path';
6
+ import { test } from 'vitest';
7
+ import { shutdownTerminalProcesses } from './shutdown.js';
8
+
9
+ const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
10
+ const script = `
11
+ const fs = require('node:fs');
12
+ const [file, mode] = process.argv.slice(1);
13
+ const record = event => fs.appendFileSync(file, JSON.stringify({ pid: process.pid, event }) + '\\n');
14
+ process.on('SIGHUP', () => record('SIGHUP'));
15
+ process.on('SIGTERM', () => {
16
+ record('SIGTERM');
17
+ if (mode === 'ignore') return;
18
+ if (mode === 'parent') return process.exit(0);
19
+ setTimeout(() => { record('complete'); process.exit(0); }, 250);
20
+ });
21
+ record('ready');
22
+ setInterval(() => {}, 1000);
23
+ `;
24
+
25
+ async function fixture(t, mode) {
26
+ const dir = await fs.mkdtemp(path.join(os.tmpdir(), 'terminal-shutdown-'));
27
+ const file = path.join(dir, 'events.jsonl');
28
+ const source = script + (mode === 'parent' ? `require('node:child_process').spawn(process.execPath, ['-e', ${JSON.stringify(script)}, file, 'worker'], { detached: true, stdio: 'ignore' }).unref();` : '');
29
+ const child = spawn(process.execPath, ['-e', source, file, mode], { detached: true, stdio: 'ignore' });
30
+ const exit = new Promise(resolve => child.once('exit', (code, signal) => resolve({ code, signal })));
31
+ const events = async () => { try { return (await fs.readFile(file, 'utf8')).trim().split('\n').map(line => JSON.parse(line)); } catch (error) { if (error.code === 'ENOENT') return []; throw error; } };
32
+ t.onTestFinished(async () => {
33
+ for (const pid of new Set([child.pid, ...(await events()).map(event => event.pid)])) {
34
+ try { process.kill(pid, 'SIGKILL'); } catch { /* already exited */ }
35
+ }
36
+ await exit;
37
+ await fs.rm(dir, { recursive: true, force: true });
38
+ });
39
+ const count = mode === 'parent' ? 2 : 1;
40
+ for (let i = 0; i < 100 && (await events()).filter(event => event.event === 'ready').length < count; i++) await delay(20);
41
+ assert.equal((await events()).filter(event => event.event === 'ready').length, count);
42
+ return { terminal: { process: { pid: child.pid, kill: signal => child.kill(signal) }, shellExecutable: '/bin/sh' }, events, exit };
43
+ }
44
+
45
+ test('graceful shutdown lets concurrent exec workloads finish without SIGHUP or SIGKILL', { skip: process.platform === 'win32' }, async t => {
46
+ const first = await fixture(t, 'worker');
47
+ const second = await fixture(t, 'worker');
48
+ await shutdownTerminalProcesses([first.terminal, second.terminal], { graceMs: 1500 });
49
+ for (const run of [first, second]) {
50
+ assert.deepEqual((await run.events()).map(event => event.event), ['ready', 'SIGTERM', 'complete']);
51
+ assert.deepEqual(await run.exit, { code: 0, signal: null });
52
+ }
53
+ });
54
+
55
+ test('waits for a separate process group after its parent exits', { skip: process.platform === 'win32' }, async t => {
56
+ const run = await fixture(t, 'parent');
57
+ await shutdownTerminalProcesses([run.terminal], { graceMs: 1500 });
58
+ const events = await run.events();
59
+ assert.equal(events.filter(event => event.event === 'SIGTERM').length, 2);
60
+ assert.equal(events.filter(event => event.event === 'complete').length, 1);
61
+ assert.deepEqual(await run.exit, { code: 0, signal: null });
62
+ });
63
+
64
+ test('escalates a noncooperative workload only after the shared deadline', { skip: process.platform === 'win32' }, async t => {
65
+ const run = await fixture(t, 'ignore');
66
+ const start = Date.now();
67
+ await shutdownTerminalProcesses([run.terminal], { graceMs: 350 });
68
+ assert.ok(Date.now() - start >= 350);
69
+ assert.deepEqual((await run.events()).map(event => event.event), ['ready', 'SIGTERM']);
70
+ assert.deepEqual(await run.exit, { code: null, signal: 'SIGKILL' });
71
+ });
72
+
73
+ test('an idle shell closes promptly and shutdown waits for its exit', { skip: process.platform === 'win32' }, async t => {
74
+ const child = spawn('/bin/sh', ['-i'], { detached: true, stdio: 'pipe' });
75
+ child.stdout.resume();
76
+ child.stderr.resume();
77
+ const exit = new Promise(resolve => child.once('exit', (code, signal) => resolve({ code, signal })));
78
+ t.onTestFinished(async () => { child.kill('SIGKILL'); await exit; });
79
+ await delay(100);
80
+ const start = Date.now();
81
+ await shutdownTerminalProcesses([{ process: { pid: child.pid, kill: signal => child.kill(signal) }, shellExecutable: '/bin/sh' }]);
82
+ assert.ok(Date.now() - start < 3000);
83
+ assert.equal((await exit).signal, 'SIGHUP');
84
+ });
@@ -0,0 +1,78 @@
1
+ import { afterEach, describe, expect, it } from 'vitest';
2
+ import { createServer } from 'node:http';
3
+ import { once } from 'node:events';
4
+ import { TTSService } from './service.js';
5
+ import { transcribeAudio } from './stt.js';
6
+
7
+ describe('OpenAI audio SDK compatibility', () => {
8
+ let server;
9
+
10
+ afterEach(async () => {
11
+ if (server) {
12
+ await new Promise((resolve, reject) => {
13
+ server.close((error) => error ? reject(error) : resolve());
14
+ server.closeAllConnections();
15
+ });
16
+ server = undefined;
17
+ }
18
+ });
19
+
20
+ const listen = async (handler) => {
21
+ server = createServer(handler);
22
+ server.listen(0, '127.0.0.1');
23
+ await once(server, 'listening');
24
+ return `http://127.0.0.1:${server.address().port}/v1`;
25
+ };
26
+
27
+ it('sends custom speech options and returns the audio bytes', async () => {
28
+ const audio = Buffer.from('speech-response');
29
+ let received;
30
+ const baseURL = await listen(async (request, response) => {
31
+ const chunks = [];
32
+ for await (const chunk of request) chunks.push(chunk);
33
+ received = { url: request.url, method: request.method, body: JSON.parse(Buffer.concat(chunks).toString()) };
34
+ response.writeHead(200, { 'Content-Type': 'audio/mpeg' });
35
+ response.end(audio);
36
+ });
37
+
38
+ const result = await new TTSService().generateSpeechStream({
39
+ text: 'Hello', model: 'custom-tts', voice: 'coral', speed: 1.2, baseURL,
40
+ });
41
+
42
+ expect(received).toEqual({
43
+ url: '/v1/audio/speech', method: 'POST',
44
+ body: { input: 'Hello', model: 'custom-tts', voice: 'coral', speed: 1.2 },
45
+ });
46
+ expect(result).toEqual({ buffer: audio, contentType: 'audio/mpeg' });
47
+ });
48
+
49
+ it('uploads transcription audio as multipart data and reads the text', async () => {
50
+ const audio = Buffer.from('transcription-input');
51
+ let received;
52
+ const baseURL = await listen(async (request, response) => {
53
+ const chunks = [];
54
+ for await (const chunk of request) chunks.push(chunk);
55
+ const form = await new Response(Buffer.concat(chunks), {
56
+ headers: { 'Content-Type': request.headers['content-type'] },
57
+ }).formData();
58
+ const file = form.get('file');
59
+ received = {
60
+ url: request.url, method: request.method,
61
+ model: form.get('model'), language: form.get('language'), format: form.get('response_format'),
62
+ filename: file.name, audio: Buffer.from(await file.arrayBuffer()),
63
+ };
64
+ response.writeHead(200, { 'Content-Type': 'application/json' });
65
+ response.end(JSON.stringify({ text: 'Hello from transcription' }));
66
+ });
67
+
68
+ const result = await transcribeAudio({
69
+ audioBuffer: audio, mimeType: 'audio/webm', model: 'whisper-1', language: 'en', baseURL,
70
+ });
71
+
72
+ expect(received).toEqual({
73
+ url: '/v1/audio/transcriptions', method: 'POST', model: 'whisper-1', language: 'en',
74
+ format: 'json', filename: 'audio.webm', audio,
75
+ });
76
+ expect(result).toBe('Hello from transcription');
77
+ });
78
+ });
@@ -10,9 +10,17 @@ Pairing v2 is implemented by `packages/web/server/lib/client-auth/pairing.js`. I
10
10
  ## Entrypoints and structure
11
11
  - `packages/web/server/lib/ui-auth/ui-auth.js`: UI auth controller runtime, cookie/session issuance, rate limiting, and auth route handlers.
12
12
  - `packages/web/server/lib/ui-auth/ui-passkeys.js`: passkey store and WebAuthn registration/authentication verification helpers.
13
+ - `packages/web/server/lib/ui-auth/session-cookie.js`: resolves the session cookie name from a request's `Host` port; shared by session issuance and validation in `ui-auth.js` and notification/session identity extraction in `packages/web/server/lib/security/request-security.js`.
13
14
  - `packages/web/server/lib/client-auth/remote-clients.js`: trusted-device client token storage, bearer authentication, last-used tracking, and revocation.
14
15
  - `packages/web/server/lib/client-auth/pairing.js`: short-lived Pairing v2 sessions and one-time secret redemption into trusted-device client tokens.
15
16
 
17
+ ## Session cookie scoping
18
+ Browsers key a cookie jar on the host only, never the port (RFC 6265). Two OpenChamber instances reached through the same hostname on different ports therefore shared a single `oc_ui_session` cookie. Logging into the second overwrote the first instance's session cookie (issue #2377). This affects LAN and loopback hosts alike.
19
+
20
+ `sessionCookieNameForRequest(req, base)` folds the request `Host` port into the cookie name: `oc_ui_session_<port>` when the host carries an explicit port (including a port from `x-forwarded-host`), or the bare `oc_ui_session` when it does not. `localhost:3000` and `localhost:3001` use separate names, just like two ports on one LAN address. Password and browser passkey login both call `issueSession` and receive this cookie. Session validation, clearing, and notification identity extraction use the same resolver; identity extraction does not provide a CSRF token. Bearer-token validation is unchanged.
21
+
22
+ Compatibility: upgrading renames the cookie for any explicit-port host, so already-signed-in browser sessions must log in once again. No on-disk format changes.
23
+
16
24
  ## Public exports (ui-auth.js)
17
25
  - `createUiAuth({ password, cookieName, sessionTtlMs, readSettingsFromDiskMigrated })`: creates UI auth controller with methods:
18
26
  - `enabled`