@openchamber/web 1.18.4 → 1.20.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 (251) hide show
  1. package/README.md +1 -0
  2. package/dist/assets/{CodeMirrorCommentWidgets-4qZbrEXU.js → CodeMirrorCommentWidgets-C36E738Y.js} +1 -1
  3. package/dist/assets/{CommitSection-MJmntVPJ.js → CommitSection-C-F3AX6D.js} +1 -1
  4. package/dist/assets/{DiagramEditor-jnG3Hbxg.js → DiagramEditor-BPECg1jS.js} +1 -1
  5. package/dist/assets/DiagramView-D0YNMix8.js +1 -0
  6. package/dist/assets/DiffView-BHWaMYCC.js +4 -0
  7. package/dist/assets/FilesView-NMBCW2Tm.js +14 -0
  8. package/dist/assets/{GitView-DBFrDDBv.js → GitView-Rp8P1KEI.js} +4 -4
  9. package/dist/assets/{JsonTreeView-DLW2Wy1g.js → JsonTreeView-KnXFN2A-.js} +1 -1
  10. package/dist/assets/MarkdownImageGallery-BMn3mtor.js +1 -0
  11. package/dist/assets/MarkdownRendererImpl-kD6N03pH.js +12 -0
  12. package/dist/assets/OnboardingScreen-CenIeD4v.js +1 -0
  13. package/dist/assets/{PatchDiff-BuLPx7AN.js → PatchDiff-BzVOVog8.js} +1 -1
  14. package/dist/assets/{PierreDiffViewer-BHm4Yr0X.js → PierreDiffViewer-Dlby4XqT.js} +2 -2
  15. package/dist/assets/PlanView-Czu1KMJa.js +4 -0
  16. package/dist/assets/SessionSwitcherDropdown-IETz58DB.js +1 -0
  17. package/dist/assets/SettingsView-B6vmuf-c.js +28 -0
  18. package/dist/assets/SettingsWindow-CauZpdD3.js +1 -0
  19. package/dist/assets/ToolOutputDialog-BB1c--Zr.js +15 -0
  20. package/dist/assets/ToolPartDiffPreview-DaOIDISD.js +8 -0
  21. package/dist/assets/{VirtualizedFileDiff-CwGocYQd.js → VirtualizedFileDiff-lESMT-2b.js} +4 -4
  22. package/dist/assets/{WalkthroughView-5DyvN03T.js → WalkthroughView-CaSYE0lw.js} +2 -2
  23. package/dist/assets/{computeVirtualFileMetrics-Da00Jg7M.js → computeVirtualFileMetrics-DkRR5b75.js} +2 -2
  24. package/dist/assets/contextPanelEmbeddedChat-BEARQjgn.js +1 -0
  25. package/dist/assets/de-DFdX3ABv.js +9 -0
  26. package/dist/assets/document-attachments-DFAWlG3U.js +31 -0
  27. package/dist/assets/es-iC-FKvV9.js +15 -0
  28. package/dist/assets/fr-BBbi_1AL.js +13 -0
  29. package/dist/assets/index-BiEgzzkg.js +1 -0
  30. package/dist/assets/index-Cwmuwk3V.js +7 -0
  31. package/dist/assets/index-GNm1wgUH.css +1 -0
  32. package/dist/assets/{isDiffPlainText-D9YpoLrV.js → isDiffPlainText-BG53Ixxy.js} +1 -1
  33. package/dist/assets/{isFilePlainText-gTibdNIe.js → isFilePlainText-BbV-39jl.js} +1 -1
  34. package/dist/assets/ja-DQLQJL2J.js +15 -0
  35. package/dist/assets/ko-BeElEB4Y.js +15 -0
  36. package/dist/assets/{lua-BgMRiT3U.js → lua-VAEuO923.js} +1 -1
  37. package/dist/assets/main-Dpzo18z7.js +2 -0
  38. package/dist/assets/main-WMjtYzJs.js +921 -0
  39. package/dist/assets/markdownCore--tDmyI_v.js +2 -0
  40. package/dist/assets/miniChat-ldEghBLB.js +2 -0
  41. package/dist/assets/mobile-Dk-VGreF.js +2 -0
  42. package/dist/assets/{patchFileDiff-KNkxM1C1.js → patchFileDiff-BcFaMtMu.js} +1 -1
  43. package/dist/assets/pl-CLHt2_vV.js +15 -0
  44. package/dist/assets/pt-BR-C_MPUq7e.js +15 -0
  45. package/dist/assets/renderElectronMiniChatApp-DIgCOmXY.js +2 -0
  46. package/dist/assets/renderMobileApp-CDfHS5rr.js +25 -0
  47. package/dist/assets/runtimeEndpointReset-ovNbaZ-x.js +15 -0
  48. package/dist/assets/scheduledTasksApi-BFSlqgnG.js +1 -0
  49. package/dist/assets/{shikiHighlight-C7LTbwFx.js → shikiHighlight-DCT2Sq_z.js} +1 -1
  50. package/dist/assets/uk-PhsC-c4-.js +15 -0
  51. package/dist/assets/{useAppFontEffects-BikB6enL.js → useAppFontEffects-B53Rb6m7.js} +168 -164
  52. package/dist/assets/useInlineCommentController-DSfrIBKT.js +2 -0
  53. package/dist/assets/{vendor-base-ui-D_V6hAcE.js → vendor-base-ui-DsHmyMwp.js} +1 -1
  54. package/dist/assets/vendor-codemirror-autocomplete-DzPz9Wgq.js +1 -0
  55. package/dist/assets/vendor-codemirror-commands-B7H_j0iU.js +1 -0
  56. package/dist/assets/{vendor-codemirror-lang-angular-CgY7_gQ1.js → vendor-codemirror-lang-angular-DEPs2M5t.js} +1 -1
  57. package/dist/assets/{vendor-codemirror-lang-cpp-B5Ta4enQ.js → vendor-codemirror-lang-cpp-DhkseaMo.js} +1 -1
  58. package/dist/assets/{vendor-codemirror-lang-css-VgNqFSH-.js → vendor-codemirror-lang-css-O0cZX78y.js} +1 -1
  59. package/dist/assets/{vendor-codemirror-lang-go-LxLz62pp.js → vendor-codemirror-lang-go-fMdQYcON.js} +1 -1
  60. package/dist/assets/vendor-codemirror-lang-html-CfgK872x.js +1 -0
  61. package/dist/assets/{vendor-codemirror-lang-java-Bksi1PH4.js → vendor-codemirror-lang-java-CQj4S3zl.js} +1 -1
  62. package/dist/assets/vendor-codemirror-lang-javascript-Cc2ZYbgX.js +13 -0
  63. package/dist/assets/{vendor-codemirror-lang-jinja-C7npuDD7.js → vendor-codemirror-lang-jinja-BmZZv8g-.js} +1 -1
  64. package/dist/assets/{vendor-codemirror-lang-json-ryCw7nab.js → vendor-codemirror-lang-json-CMBS2tG9.js} +1 -1
  65. package/dist/assets/{vendor-codemirror-lang-less-BxsZJD6N.js → vendor-codemirror-lang-less-C6Eo8hVS.js} +1 -1
  66. package/dist/assets/{vendor-codemirror-lang-liquid-De6qch10.js → vendor-codemirror-lang-liquid-DSTR47-H.js} +1 -1
  67. package/dist/assets/vendor-codemirror-lang-markdown-BPGOH9ye.js +1 -0
  68. package/dist/assets/{vendor-codemirror-lang-php-Cm1es33p.js → vendor-codemirror-lang-php-DD9udfPH.js} +1 -1
  69. package/dist/assets/{vendor-codemirror-lang-python-N414WYK-.js → vendor-codemirror-lang-python-HahnQaAS.js} +1 -1
  70. package/dist/assets/{vendor-codemirror-lang-rust-C_WuUStH.js → vendor-codemirror-lang-rust-nLTovbjv.js} +1 -1
  71. package/dist/assets/{vendor-codemirror-lang-sass-8UHTCAOM.js → vendor-codemirror-lang-sass-pL2Yc72v.js} +1 -1
  72. package/dist/assets/{vendor-codemirror-lang-sql-CV3sMA5D.js → vendor-codemirror-lang-sql-BVBnan19.js} +1 -1
  73. package/dist/assets/{vendor-codemirror-lang-vue-DzvC1Dhk.js → vendor-codemirror-lang-vue-BqGzJVm1.js} +1 -1
  74. package/dist/assets/{vendor-codemirror-lang-wast-jlr-LDdA.js → vendor-codemirror-lang-wast-B0_m5DqU.js} +1 -1
  75. package/dist/assets/{vendor-codemirror-lang-xml-CrO63OVp.js → vendor-codemirror-lang-xml-Dj3voadT.js} +1 -1
  76. package/dist/assets/{vendor-codemirror-lang-yaml-dxi6CISW.js → vendor-codemirror-lang-yaml-yu-9Z5u7.js} +1 -1
  77. package/dist/assets/vendor-codemirror-language-BgPj_McA.js +3 -0
  78. package/dist/assets/{vendor-codemirror-language-data-CLHw8NWn.js → vendor-codemirror-language-data-vch3tJ4c.js} +2 -2
  79. package/dist/assets/vendor-codemirror-search-BmS-GmcX.js +2 -0
  80. package/dist/assets/{vendor-codemirror-state-CNWM3Q8V.js → vendor-codemirror-state-C9awkmn-.js} +5 -5
  81. package/dist/assets/vendor-codemirror-view-CiLROUVV.js +4 -0
  82. package/dist/assets/vendor-replit-codemirror-vim-B2DJlAhT.js +6 -0
  83. package/dist/assets/vendor-replit-codemirror-vim-core-FHzKdNUS.js +34 -0
  84. package/dist/assets/vendor-zod-C9ioTTSo.js +39 -0
  85. package/dist/assets/{web-components-GMc3oR3i.js → web-components-pcwCTWjC.js} +4 -4
  86. package/dist/assets/zh-CN-wF-NOFHM.js +15 -0
  87. package/dist/assets/zh-TW-4m4-A7rT.js +15 -0
  88. package/dist/index.html +5 -4
  89. package/dist/mini-chat.html +4 -3
  90. package/dist/mobile.html +4 -3
  91. package/package.json +3 -5
  92. package/server/index.js +152 -3
  93. package/server/lib/agent-memory/actions.js +243 -0
  94. package/server/lib/agent-memory/actions.test.js +343 -0
  95. package/server/lib/agent-memory/feature-flag.js +19 -0
  96. package/server/lib/agent-memory/feature-flag.test.js +38 -0
  97. package/server/lib/agent-memory/project-resolution.js +65 -0
  98. package/server/lib/agent-memory/project-resolution.test.js +94 -0
  99. package/server/lib/agent-memory/routes.http.test.js +270 -0
  100. package/server/lib/agent-memory/routes.js +169 -0
  101. package/server/lib/agent-memory/runtime.js +432 -0
  102. package/server/lib/agent-memory/runtime.test.js +344 -0
  103. package/server/lib/agent-memory/threat-patterns.js +61 -0
  104. package/server/lib/agent-memory/threat-patterns.test.js +61 -0
  105. package/server/lib/agent-tool/DOCUMENTATION.md +14 -0
  106. package/server/lib/agent-tool/runtime.js +63 -13
  107. package/server/lib/agent-tool/runtime.test.js +85 -2
  108. package/server/lib/context-obligatory/runtime.js +34 -3
  109. package/server/lib/context-obligatory/runtime.test.js +114 -0
  110. package/server/lib/dictation/DOCUMENTATION.md +32 -8
  111. package/server/lib/dictation/local/sherpa-recognizer.js +35 -78
  112. package/server/lib/dictation/local/worker-process.js +2 -2
  113. package/server/lib/dictation/openai-compatible-session.js +3 -2
  114. package/server/lib/dictation/stream-manager.js +77 -34
  115. package/server/lib/dictation/stream-manager.test.js +60 -2
  116. package/server/lib/fs/DOCUMENTATION.md +3 -0
  117. package/server/lib/fs/routes.js +149 -32
  118. package/server/lib/fs/routes.test.js +301 -0
  119. package/server/lib/git/DOCUMENTATION.md +8 -0
  120. package/server/lib/git/routes.js +43 -0
  121. package/server/lib/git/service.js +206 -72
  122. package/server/lib/git/service.test.js +222 -0
  123. package/server/lib/github/DOCUMENTATION.md +14 -3
  124. package/server/lib/github/pr-status.js +188 -83
  125. package/server/lib/github/pr-status.test.js +182 -0
  126. package/server/lib/github/routes.js +36 -30
  127. package/server/lib/notifications/template-runtime.js +2 -3
  128. package/server/lib/openchamber-control/action-resolution.test.js +65 -0
  129. package/server/lib/openchamber-control/actions.js +78 -0
  130. package/server/lib/openchamber-control/service.js +7 -0
  131. package/server/lib/openchamber-sessions/routes.js +14 -0
  132. package/server/lib/opencode/DOCUMENTATION.md +12 -6
  133. package/server/lib/opencode/claude-cli-auth.js +60 -0
  134. package/server/lib/opencode/claude-cli-auth.test.js +54 -0
  135. package/server/lib/opencode/feature-routes-runtime.js +16 -9
  136. package/server/lib/opencode/lifecycle.js +202 -26
  137. package/server/lib/opencode/lifecycle.test.js +179 -1
  138. package/server/lib/opencode/plugins.js +12 -3
  139. package/server/lib/opencode/plugins.test.js +18 -0
  140. package/server/lib/opencode/providers.js +9 -4
  141. package/server/lib/opencode/providers.test.js +27 -0
  142. package/server/lib/opencode/proxy-agent-wiring.test.js +152 -0
  143. package/server/lib/opencode/proxy.js +116 -6
  144. package/server/lib/opencode/proxy.test.js +158 -1
  145. package/server/lib/opencode/restart-session-recovery.test.js +59 -0
  146. package/server/lib/opencode/routes.js +4 -1
  147. package/server/lib/opencode/session-runtime.js +39 -2
  148. package/server/lib/opencode/session-runtime.test.js +74 -0
  149. package/server/lib/opencode/settings-helpers.js +26 -0
  150. package/server/lib/opencode/settings-helpers.test.js +57 -0
  151. package/server/lib/opencode/settings-normalization-runtime.js +3 -0
  152. package/server/lib/opencode/settings-normalization-runtime.test.js +16 -0
  153. package/server/lib/opencode/settings-runtime.js +83 -10
  154. package/server/lib/opencode/settings-runtime.test.js +85 -0
  155. package/server/lib/opencode/shared.js +120 -16
  156. package/server/lib/opencode/shared.test.js +185 -1
  157. package/server/lib/opencode/skill-routes.js +29 -73
  158. package/server/lib/opencode/skill-routes.test.js +2 -5
  159. package/server/lib/project-context/DOCUMENTATION.md +160 -0
  160. package/server/lib/project-context/routes.http.test.js +264 -0
  161. package/server/lib/project-context/routes.js +237 -0
  162. package/server/lib/project-context/runtime.js +672 -0
  163. package/server/lib/project-context/runtime.test.js +498 -0
  164. package/server/lib/projects/project-config.js +7 -2
  165. package/server/lib/quota/DOCUMENTATION.md +17 -2
  166. package/server/lib/quota/providers/claude/auth.js +113 -0
  167. package/server/lib/quota/providers/claude/auth.test.js +117 -0
  168. package/server/lib/quota/providers/claude/index.js +151 -0
  169. package/server/lib/quota/providers/claude/index.test.js +147 -0
  170. package/server/lib/quota/providers/claude/transforms.js +127 -0
  171. package/server/lib/quota/providers/claude/transforms.test.js +82 -0
  172. package/server/lib/quota/providers/command-code.js +90 -0
  173. package/server/lib/quota/providers/command-code.test.js +85 -0
  174. package/server/lib/quota/providers/index.js +30 -2
  175. package/server/lib/quota/providers/index.test.js +10 -1
  176. package/server/lib/quota/providers/zai.js +26 -6
  177. package/server/lib/quota/providers/zai.test.js +33 -0
  178. package/server/lib/quota/utils/formatters.js +2 -1
  179. package/server/lib/scheduled-tasks/runtime.js +21 -2
  180. package/server/lib/session-knowledge/DOCUMENTATION.md +89 -0
  181. package/server/lib/session-knowledge/routes.js +107 -0
  182. package/server/lib/session-knowledge/runtime.js +331 -0
  183. package/server/lib/session-knowledge/runtime.test.js +275 -0
  184. package/server/lib/skills-catalog/DOCUMENTATION.md +18 -45
  185. package/server/lib/skills-catalog/cache.js +120 -1
  186. package/server/lib/skills-catalog/cache.test.js +77 -0
  187. package/server/lib/skills-catalog/curated-sources.js +21 -5
  188. package/server/lib/skills-catalog/curated-sources.test.js +10 -0
  189. package/server/lib/skills-catalog/disk-cache.js +52 -0
  190. package/server/lib/skills-catalog/github-meta.js +139 -0
  191. package/server/lib/skills-catalog/github-meta.test.js +71 -0
  192. package/server/lib/skills-catalog/source.js +0 -5
  193. package/server/lib/small-model/DOCUMENTATION.md +74 -6
  194. package/server/lib/small-model/call.js +46 -12
  195. package/server/lib/small-model/call.test.js +79 -0
  196. package/server/lib/small-model/index.js +57 -6
  197. package/server/lib/small-model/index.test.js +102 -2
  198. package/server/lib/small-model/routes.js +4 -2
  199. package/server/lib/small-model/runtime-providers.js +156 -0
  200. package/server/lib/small-model/runtime-providers.test.js +112 -0
  201. package/dist/assets/DiagramView-CFXxgg_a.js +0 -1
  202. package/dist/assets/DiffView-DZIoOnV7.js +0 -4
  203. package/dist/assets/FilesView-BKL6YlKG.js +0 -14
  204. package/dist/assets/MarkdownImageGallery-DKIylIK7.js +0 -1
  205. package/dist/assets/MarkdownRendererImpl-CLv8hxvv.js +0 -12
  206. package/dist/assets/OnboardingScreen-D2Y6djMw.js +0 -1
  207. package/dist/assets/PlanView-ZYEJn8A_.js +0 -4
  208. package/dist/assets/SessionSwitcherDropdown-rro-SsaO.js +0 -1
  209. package/dist/assets/SettingsView-5RmswFZe.js +0 -28
  210. package/dist/assets/SettingsWindow-BZhAYFdS.js +0 -1
  211. package/dist/assets/ToolOutputDialog-Za6V4VMJ.js +0 -15
  212. package/dist/assets/ToolPartDiffPreview-BL-9ixyC.js +0 -8
  213. package/dist/assets/contextPanelEmbeddedChat-B-bSg3P5.js +0 -1
  214. package/dist/assets/de-u7gSnqWs.js +0 -9
  215. package/dist/assets/document-attachments-CX_YaDsu.js +0 -30
  216. package/dist/assets/es-T9O7aAOr.js +0 -15
  217. package/dist/assets/fr-Oor7ewbE.js +0 -13
  218. package/dist/assets/index-BzIpNlNE.css +0 -1
  219. package/dist/assets/index-C0yNhuZw.js +0 -1
  220. package/dist/assets/index-DRpChWux.js +0 -7
  221. package/dist/assets/ja-DHpqbVmr.js +0 -15
  222. package/dist/assets/ko-CwLkS3nx.js +0 -15
  223. package/dist/assets/main-D7UcL3VQ.js +0 -2
  224. package/dist/assets/main-DPMd2iKS.js +0 -915
  225. package/dist/assets/markdownCore-DDrHVneM.js +0 -2
  226. package/dist/assets/miniChat-O_GVoEbc.js +0 -2
  227. package/dist/assets/mobile-Br4TtAqc.js +0 -2
  228. package/dist/assets/pl-CcZILN8q.js +0 -15
  229. package/dist/assets/pt-BR-DYHhVK6o.js +0 -15
  230. package/dist/assets/renderElectronMiniChatApp-CJpdxTT1.js +0 -2
  231. package/dist/assets/renderMobileApp-toj9cXoh.js +0 -25
  232. package/dist/assets/runtimeEndpointReset-BVmispdD.js +0 -13
  233. package/dist/assets/scheduledTasksApi-ByKya3Un.js +0 -1
  234. package/dist/assets/uk-BA2kZR38.js +0 -15
  235. package/dist/assets/useInlineCommentController-CYPvYJDt.js +0 -2
  236. package/dist/assets/vendor-codemirror-autocomplete-BjbBRsUA.js +0 -1
  237. package/dist/assets/vendor-codemirror-commands-ARAOgp1x.js +0 -1
  238. package/dist/assets/vendor-codemirror-lang-html-B3Qe3OpS.js +0 -1
  239. package/dist/assets/vendor-codemirror-lang-javascript-Bbw3D7r0.js +0 -13
  240. package/dist/assets/vendor-codemirror-lang-markdown-FGQydhTc.js +0 -1
  241. package/dist/assets/vendor-codemirror-language-DUOssd4j.js +0 -3
  242. package/dist/assets/vendor-codemirror-search-8kyQdB3f.js +0 -2
  243. package/dist/assets/vendor-codemirror-view-DSzLbZiS.js +0 -4
  244. package/dist/assets/vendor-replit-codemirror-vim-B0Ecqnlh.js +0 -39
  245. package/dist/assets/zh-CN-dlOQK6v9.js +0 -15
  246. package/dist/assets/zh-TW-BnqQ-WL5.js +0 -15
  247. package/server/lib/quota/providers/claude.js +0 -107
  248. package/server/lib/skills-catalog/clawdhub/api.js +0 -126
  249. package/server/lib/skills-catalog/clawdhub/install.js +0 -238
  250. package/server/lib/skills-catalog/clawdhub/install.test.js +0 -100
  251. package/server/lib/skills-catalog/clawdhub/scan.js +0 -61
@@ -7,23 +7,54 @@
7
7
  * Responsibilities:
8
8
  * - Reorders inbound chunks by `seq` and acks the highest contiguous seq.
9
9
  * - Resamples client PCM (16 kHz by default) to the provider's required rate.
10
- * - Auto-commits a segment every `autoCommitSeconds` of audio, but clears
11
- * silence-only segments instead of committing them.
10
+ * - Segments long dictations at natural pauses: past `segmentMinSeconds` of
11
+ * audio it commits on the first silent chunk, and `segmentMaxSeconds` is a
12
+ * hard cap for speech with no pause in it. Silence-only segments are
13
+ * cleared instead of committed.
12
14
  * - Concatenates per-segment transcripts into live partials and emits the
13
- * final text once every committed segment has a final transcript.
15
+ * final text once every committed segment has a final transcript. The
16
+ * manager counts the commits it issued rather than trusting the session's
17
+ * echoed events, so a commit still in flight when the client finishes
18
+ * cannot be silently dropped from the transcript.
14
19
  * - Applies an adaptive finalization timeout budget based on pending work.
15
20
  */
16
21
 
17
22
  import { Pcm16MonoResampler, parsePcmRateFromFormat, pcm16lePeakAbs } from './audio.js';
18
23
 
19
24
  const DEFAULT_FINAL_TIMEOUT_MS = 10000;
20
- const DEFAULT_AUTO_COMMIT_SECONDS = 15;
25
+ // Parakeet is a full-attention conformer: decode cost and peak memory grow
26
+ // quadratically with segment length (measured: 60s -> 2.1s/+90MB,
27
+ // 300s -> 21.3s/+1.5GB). Segmenting keeps a long dictation off that curve and
28
+ // lets committed segments decode while the user is still speaking, so only the
29
+ // tail is left to transcribe on stop. Typical dictations are shorter than the
30
+ // minimum and are decoded as a single segment.
31
+ const DEFAULT_SEGMENT_MIN_SECONDS = 60;
32
+ const DEFAULT_SEGMENT_MAX_SECONDS = 90;
21
33
  const FINAL_TIMEOUT_MAX_MS = 5 * 60 * 1000;
22
34
  const FINAL_TIMEOUT_PER_PENDING_SEGMENT_MS = 15 * 1000;
23
35
  const FINAL_TIMEOUT_PER_PENDING_AUDIO_SECOND_MS = 1500;
24
36
  const FINAL_TIMEOUT_PER_MISSING_SEQ_MS = 250;
25
37
  const SILENCE_PEAK_THRESHOLD = 300;
26
38
 
39
+ const secondsToPcm16Bytes = (seconds, sampleRate) =>
40
+ seconds > 0 ? Math.max(1, Math.round(seconds * sampleRate * 2)) : 0;
41
+
42
+ /**
43
+ * Split the current segment once it is long enough to be worth decoding on its
44
+ * own and the speaker has just gone quiet, or unconditionally at the hard cap.
45
+ * Client chunks are ~1s, so a quiet chunk is roughly a second of silence — long
46
+ * enough to be a sentence boundary rather than a gap between words.
47
+ */
48
+ function shouldSplitSegment(state) {
49
+ if (state.segmentMaxBytes > 0 && state.bytesSinceCommit >= state.segmentMaxBytes) {
50
+ return true;
51
+ }
52
+ if (state.segmentMinBytes <= 0 || state.bytesSinceCommit < state.segmentMinBytes) {
53
+ return false;
54
+ }
55
+ return state.lastChunkPeak < SILENCE_PEAK_THRESHOLD;
56
+ }
57
+
27
58
  export class DictationStreamManager {
28
59
  /**
29
60
  * @param {object} params
@@ -33,13 +64,15 @@ export class DictationStreamManager {
33
64
  * The streaming transcription session contract:
34
65
  * { requiredSampleRate, appendPcm16(buf), commit(), clear(), close(), on(event, handler) }
35
66
  * @param {number} [params.finalTimeoutMs]
36
- * @param {number} [params.autoCommitSeconds]
67
+ * @param {number} [params.segmentMinSeconds] audio before a pause may split a segment
68
+ * @param {number} [params.segmentMaxSeconds] hard segment cap for pauseless speech
37
69
  */
38
- constructor({ emit, createSttSession, finalTimeoutMs, autoCommitSeconds }) {
70
+ constructor({ emit, createSttSession, finalTimeoutMs, segmentMinSeconds, segmentMaxSeconds }) {
39
71
  this.emit = emit;
40
72
  this.createSttSession = createSttSession;
41
73
  this.finalTimeoutMs = finalTimeoutMs ?? DEFAULT_FINAL_TIMEOUT_MS;
42
- this.autoCommitSeconds = autoCommitSeconds ?? DEFAULT_AUTO_COMMIT_SECONDS;
74
+ this.segmentMinSeconds = segmentMinSeconds ?? DEFAULT_SEGMENT_MIN_SECONDS;
75
+ this.segmentMaxSeconds = segmentMaxSeconds ?? DEFAULT_SEGMENT_MAX_SECONDS;
43
76
  this.streams = new Map();
44
77
  }
45
78
 
@@ -87,13 +120,12 @@ export class DictationStreamManager {
87
120
  if (!state) {
88
121
  return;
89
122
  }
123
+ // Segment accounting is reset where the commit is issued, not here: this
124
+ // event arrives after an async hop, and zeroing the counters on arrival
125
+ // would discard audio that came in meanwhile — up to and including
126
+ // mistaking the tail of the dictation for silence and clearing it.
90
127
  state.committedSegmentIds.push(segmentId);
91
- state.bytesSinceCommit = 0;
92
- state.peakSinceCommit = 0;
93
-
94
- if (state.finishRequested && state.awaitingFinalCommit) {
95
- state.awaitingFinalCommit = false;
96
- }
128
+ state.pendingCommits = Math.max(0, state.pendingCommits - 1);
97
129
 
98
130
  this.maybeFinalizeStream(dictationId);
99
131
  });
@@ -108,10 +140,6 @@ export class DictationStreamManager {
108
140
  state.finalTranscriptSegmentIds.add(segmentId);
109
141
  }
110
142
 
111
- if (state.finishRequested && state.awaitingFinalCommit && isFinal) {
112
- state.awaitingFinalCommit = false;
113
- }
114
-
115
143
  const orderedIds = state.committedSegmentIds.includes(segmentId)
116
144
  ? state.committedSegmentIds
117
145
  : [...state.committedSegmentIds, segmentId];
@@ -143,16 +171,15 @@ export class DictationStreamManager {
143
171
  receivedChunks: new Map(),
144
172
  nextSeqToForward: 0,
145
173
  ackSeq: -1,
146
- autoCommitBytes:
147
- this.autoCommitSeconds > 0
148
- ? Math.max(1, Math.round(this.autoCommitSeconds * stt.requiredSampleRate * 2))
149
- : 0,
174
+ segmentMinBytes: secondsToPcm16Bytes(this.segmentMinSeconds, stt.requiredSampleRate),
175
+ segmentMaxBytes: secondsToPcm16Bytes(this.segmentMaxSeconds, stt.requiredSampleRate),
150
176
  bytesSinceCommit: 0,
151
177
  peakSinceCommit: 0,
178
+ lastChunkPeak: 0,
152
179
  committedSegmentIds: [],
153
180
  transcriptsBySegmentId: new Map(),
154
181
  finalTranscriptSegmentIds: new Set(),
155
- awaitingFinalCommit: false,
182
+ pendingCommits: 0,
156
183
  finishRequested: false,
157
184
  finishSealed: false,
158
185
  finalSeq: null,
@@ -203,7 +230,8 @@ export class DictationStreamManager {
203
230
  if (resampled.length > 0) {
204
231
  state.stt.appendPcm16(resampled);
205
232
  state.bytesSinceCommit += resampled.length;
206
- state.peakSinceCommit = Math.max(state.peakSinceCommit, pcm16lePeakAbs(resampled));
233
+ state.lastChunkPeak = pcm16lePeakAbs(resampled);
234
+ state.peakSinceCommit = Math.max(state.peakSinceCommit, state.lastChunkPeak);
207
235
  try {
208
236
  this.maybeAutoCommitSegment(state);
209
237
  } catch (error) {
@@ -325,9 +353,7 @@ export class DictationStreamManager {
325
353
  return state.finalTranscriptSegmentIds.has(segmentId) ? count : count + 1;
326
354
  }, 0);
327
355
  const pendingSegments =
328
- pendingCommittedSegments +
329
- pendingUncommittedTranscriptSegments +
330
- (state.awaitingFinalCommit ? 1 : 0);
356
+ pendingCommittedSegments + pendingUncommittedTranscriptSegments + state.pendingCommits;
331
357
  const pendingAudioSeconds = Math.ceil(Math.max(0, state.bytesSinceCommit) / bytesPerSecond);
332
358
  const missingSeqCount =
333
359
  state.finalSeq === null ? 0 : Math.max(0, state.finalSeq - state.ackSeq);
@@ -347,19 +373,36 @@ export class DictationStreamManager {
347
373
  if (state.finishRequested) {
348
374
  return;
349
375
  }
350
- if (state.autoCommitBytes <= 0 || state.bytesSinceCommit < state.autoCommitBytes) {
376
+ if (!shouldSplitSegment(state)) {
351
377
  return;
352
378
  }
353
379
  if (state.peakSinceCommit < SILENCE_PEAK_THRESHOLD) {
354
380
  state.stt.clear();
355
381
  state.bytesSinceCommit = 0;
356
382
  state.peakSinceCommit = 0;
383
+ state.lastChunkPeak = 0;
357
384
  return;
358
385
  }
359
386
 
360
387
  state.bytesSinceCommit = 0;
361
388
  state.peakSinceCommit = 0;
362
- state.stt.commit();
389
+ state.lastChunkPeak = 0;
390
+ this.commitSegment(state);
391
+ }
392
+
393
+ /**
394
+ * Issue a commit and record it as in flight. The session acknowledges with a
395
+ * `committed` event; until then the manager must not finalize, or the
396
+ * segment's transcript would be missing from the final text.
397
+ */
398
+ commitSegment(state) {
399
+ state.pendingCommits += 1;
400
+ try {
401
+ state.stt.commit();
402
+ } catch (error) {
403
+ state.pendingCommits -= 1;
404
+ throw error;
405
+ }
363
406
  }
364
407
 
365
408
  maybeSealStreamFinish(dictationId) {
@@ -382,19 +425,19 @@ export class DictationStreamManager {
382
425
  state.stt.clear();
383
426
  state.bytesSinceCommit = 0;
384
427
  state.peakSinceCommit = 0;
385
- state.awaitingFinalCommit = false;
428
+ state.lastChunkPeak = 0;
386
429
  this.dropUncommittedNonFinalTranscripts(state);
387
430
  } else {
388
- state.awaitingFinalCommit = true;
431
+ state.bytesSinceCommit = 0;
432
+ state.peakSinceCommit = 0;
433
+ state.lastChunkPeak = 0;
389
434
  try {
390
- state.stt.commit();
435
+ this.commitSegment(state);
391
436
  } catch (error) {
392
437
  this.failAndCleanupStream(dictationId, error?.message || String(error), true);
393
438
  return;
394
439
  }
395
440
  }
396
- } else {
397
- state.awaitingFinalCommit = false;
398
441
  }
399
442
 
400
443
  state.finishSealed = true;
@@ -425,7 +468,7 @@ export class DictationStreamManager {
425
468
  if (state.ackSeq < state.finalSeq) {
426
469
  return;
427
470
  }
428
- if (state.awaitingFinalCommit) {
471
+ if (state.pendingCommits > 0) {
429
472
  return;
430
473
  }
431
474
 
@@ -175,8 +175,8 @@ describe('DictationStreamManager', () => {
175
175
  },
176
176
  });
177
177
  const { manager, messages } = createManager(session);
178
- // Force auto-commit after ~0.05s of audio so two segments form.
179
- manager.autoCommitSeconds = 0.05;
178
+ // Force a hard-cap split after ~0.05s of audio so two segments form.
179
+ manager.segmentMaxSeconds = 0.05;
180
180
 
181
181
  await manager.handleStart('d1', FORMAT, {});
182
182
  manager.handleChunk({ dictationId: 'd1', seq: 0, audioBase64: loudChunkBase64(1600) });
@@ -191,4 +191,62 @@ describe('DictationStreamManager', () => {
191
191
  const partials = messages.filter((m) => m.type === 'partial');
192
192
  expect(partials.length).toBeGreaterThan(0);
193
193
  });
194
+
195
+ it('keeps a short dictation as one segment even across pauses', async () => {
196
+ const session = new FakeSttSession();
197
+ const { manager } = createManager(session);
198
+
199
+ await manager.handleStart('d1', FORMAT, {});
200
+ manager.handleChunk({ dictationId: 'd1', seq: 0, audioBase64: loudChunkBase64(16000) });
201
+ manager.handleChunk({ dictationId: 'd1', seq: 1, audioBase64: silentChunkBase64(16000) });
202
+ manager.handleChunk({ dictationId: 'd1', seq: 2, audioBase64: loudChunkBase64(16000) });
203
+
204
+ expect(session.commits).toBe(0);
205
+
206
+ manager.handleFinish('d1', 2);
207
+ await waitFor(() => session.commits === 1);
208
+ });
209
+
210
+ it('splits at a pause once the segment passes the minimum length', async () => {
211
+ const session = new FakeSttSession();
212
+ const { manager } = createManager(session);
213
+ manager.segmentMinSeconds = 3;
214
+
215
+ await manager.handleStart('d1', FORMAT, {});
216
+ // 2s of audio: below the minimum, so this pause must not split.
217
+ manager.handleChunk({ dictationId: 'd1', seq: 0, audioBase64: loudChunkBase64(16000) });
218
+ manager.handleChunk({ dictationId: 'd1', seq: 1, audioBase64: silentChunkBase64(16000) });
219
+ expect(session.commits).toBe(0);
220
+
221
+ // Past the minimum, the next quiet chunk is a segment boundary.
222
+ manager.handleChunk({ dictationId: 'd1', seq: 2, audioBase64: loudChunkBase64(16000) });
223
+ expect(session.commits).toBe(0);
224
+ manager.handleChunk({ dictationId: 'd1', seq: 3, audioBase64: silentChunkBase64(16000) });
225
+ expect(session.commits).toBe(1);
226
+ });
227
+
228
+ it('splits pauseless speech at the hard cap', async () => {
229
+ const session = new FakeSttSession();
230
+ const { manager } = createManager(session);
231
+ manager.segmentMinSeconds = 60;
232
+ manager.segmentMaxSeconds = 2;
233
+
234
+ await manager.handleStart('d1', FORMAT, {});
235
+ manager.handleChunk({ dictationId: 'd1', seq: 0, audioBase64: loudChunkBase64(16000) });
236
+ expect(session.commits).toBe(0);
237
+ manager.handleChunk({ dictationId: 'd1', seq: 1, audioBase64: loudChunkBase64(16000) });
238
+ expect(session.commits).toBe(1);
239
+ });
240
+
241
+ it('clears a silence-only segment at the hard cap instead of committing it', async () => {
242
+ const session = new FakeSttSession();
243
+ const { manager } = createManager(session);
244
+ manager.segmentMaxSeconds = 1;
245
+
246
+ await manager.handleStart('d1', FORMAT, {});
247
+ manager.handleChunk({ dictationId: 'd1', seq: 0, audioBase64: silentChunkBase64(16000) });
248
+
249
+ expect(session.commits).toBe(0);
250
+ expect(session.clears).toBe(1);
251
+ });
194
252
  });
@@ -16,6 +16,7 @@ Own filesystem API behavior for the web server runtime, including workspace-boun
16
16
  - `GET /api/fs/raw`
17
17
  - `GET /api/fs/serve/:path(*)`
18
18
  - `POST /api/fs/write`
19
+ - `POST /api/fs/upload`
19
20
  - `POST /api/fs/delete`
20
21
  - `POST /api/fs/rename`
21
22
  - `POST /api/fs/reveal`
@@ -35,5 +36,7 @@ Own filesystem API behavior for the web server runtime, including workspace-boun
35
36
  ## Notes for contributors
36
37
  - Keep filesystem policy (workspace root checks, error mapping, exec timeout behavior) inside this module, not in the composition root.
37
38
  - Filesystem `EPERM`/`EACCES` failures use the stable `reason: "os-permission"` response marker. Policy denials such as workspace-boundary or missing-grant failures must not use that marker because a native folder picker cannot remediate them.
39
+ - Read-only routes authorize the requested path against the workspace before resolving symlinks. A symlink reached through the workspace may therefore target a file outside it, while a directly requested outside path still requires an exact-path grant. Write routes keep canonical-target boundary checks.
38
40
  - If adding new `/api/fs/*` endpoints, add them in `routes.js` and extend this document.
39
41
  - `GET /api/fs/list` may resolve symlinks with `realpath` to read directory contents, but the response `path` and each entry `path` must stay in the caller's requested path space (`path.join(requestedPath, name)`). Returning real paths breaks file-tree expansion for directories reached through workspace symlinks.
42
+ - `POST /api/fs/upload` accepts one `application/octet-stream` body with `path` and optional `overwrite=true` query parameters. The body streams into a same-directory temp file with a 100 MiB default cap configurable through `OPENCHAMBER_FS_UPLOAD_MAX_BYTES`; failed and oversized uploads clean up that temp file. New files commit through an atomic no-replace link, existing files return `409` unless overwrite is explicit, directory targets are rejected, and the destination parent resolves before writing so uploads cannot escape through workspace symlinks.
@@ -108,6 +108,12 @@ const createGitCheckIgnoreTimeoutMs = () => {
108
108
  return 2500;
109
109
  };
110
110
 
111
+ const createUploadMaxBytes = () => {
112
+ const raw = Number(process.env.OPENCHAMBER_FS_UPLOAD_MAX_BYTES);
113
+ if (Number.isFinite(raw) && raw > 0) return Math.floor(raw);
114
+ return 100 * 1024 * 1024;
115
+ };
116
+
111
117
  const FILE_MIME_MAP = Object.freeze({
112
118
  '.html': 'text/html',
113
119
  '.htm': 'text/html',
@@ -140,6 +146,27 @@ const FILE_MIME_MAP = Object.freeze({
140
146
 
141
147
  const MAX_SERVE_BYTES = 100 * 1024 * 1024;
142
148
 
149
+ const streamUploadBody = async (req, handle, maxBytes) => {
150
+ let received = 0;
151
+ for await (const chunk of req) {
152
+ const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
153
+ received += buffer.length;
154
+ if (received > maxBytes) {
155
+ req.resume?.();
156
+ throw Object.assign(new Error('Upload exceeds the maximum allowed size'), { uploadTooLarge: true });
157
+ }
158
+
159
+ let offset = 0;
160
+ while (offset < buffer.length) {
161
+ const { bytesWritten } = await handle.write(buffer, offset, buffer.length - offset, null);
162
+ if (!Number.isFinite(bytesWritten) || bytesWritten <= 0) {
163
+ throw new Error('Failed to write upload');
164
+ }
165
+ offset += bytesWritten;
166
+ }
167
+ }
168
+ };
169
+
143
170
  // Only deterministic, side-effect-free git plumbing path queries are cacheable.
144
171
  // Anything outside this allowlist (including any non-git command) runs normally
145
172
  // — we never cache arbitrary exec.
@@ -758,14 +785,7 @@ export const registerFsRoutes = (app, dependencies) => {
758
785
  return res.status(400).json({ error: resolved.error });
759
786
  }
760
787
 
761
- const [canonicalPath, canonicalBase] = await Promise.all([
762
- fsPromises.realpath(resolved.resolved),
763
- fsPromises.realpath(resolved.base).catch(() => path.resolve(resolved.base)),
764
- ]);
765
-
766
- if (!isPathWithinRoot(canonicalPath, canonicalBase, path, os)) {
767
- return res.status(403).json({ error: 'Access to file denied' });
768
- }
788
+ const canonicalPath = await fsPromises.realpath(resolved.resolved);
769
789
 
770
790
  const stats = await fsPromises.stat(canonicalPath);
771
791
  if (!stats.isFile()) {
@@ -815,14 +835,7 @@ export const registerFsRoutes = (app, dependencies) => {
815
835
  return res.status(400).json({ error: resolved.error });
816
836
  }
817
837
 
818
- const [canonicalPath, canonicalBase] = await Promise.all([
819
- fsPromises.realpath(resolved.resolved),
820
- fsPromises.realpath(resolved.base).catch(() => path.resolve(resolved.base)),
821
- ]);
822
-
823
- if (!isPathWithinRoot(canonicalPath, canonicalBase, path, os)) {
824
- return res.status(403).json({ error: 'Access to file denied' });
825
- }
838
+ const canonicalPath = await fsPromises.realpath(resolved.resolved);
826
839
 
827
840
  const stats = await fsPromises.stat(canonicalPath);
828
841
  if (!stats.isFile()) {
@@ -886,14 +899,7 @@ export const registerFsRoutes = (app, dependencies) => {
886
899
  return res.status(400).json({ error: resolved.error });
887
900
  }
888
901
 
889
- const [canonicalPath, canonicalBase] = await Promise.all([
890
- fsPromises.realpath(resolved.resolved),
891
- fsPromises.realpath(resolved.base).catch(() => path.resolve(resolved.base)),
892
- ]);
893
-
894
- if (!isPathWithinRoot(canonicalPath, canonicalBase, path, os)) {
895
- return res.status(403).json({ error: 'Access to file denied' });
896
- }
902
+ const canonicalPath = await fsPromises.realpath(resolved.resolved);
897
903
 
898
904
  const stats = await fsPromises.stat(canonicalPath);
899
905
  if (!stats.isFile()) {
@@ -971,14 +977,7 @@ export const registerFsRoutes = (app, dependencies) => {
971
977
  return res.status(400).json({ error: resolved.error });
972
978
  }
973
979
 
974
- const [canonicalPath, canonicalBase] = await Promise.all([
975
- fsPromises.realpath(resolved.resolved),
976
- fsPromises.realpath(resolved.base).catch(() => path.resolve(resolved.base)),
977
- ]);
978
-
979
- if (!isPathWithinRoot(canonicalPath, canonicalBase, path, os)) {
980
- return res.status(403).json({ error: 'Access to file denied' });
981
- }
980
+ const canonicalPath = await fsPromises.realpath(resolved.resolved);
982
981
 
983
982
  const stats = await fsPromises.stat(canonicalPath);
984
983
  if (!stats.isFile()) {
@@ -1069,6 +1068,124 @@ export const registerFsRoutes = (app, dependencies) => {
1069
1068
  }
1070
1069
  });
1071
1070
 
1071
+ app.post('/api/fs/upload', async (req, res) => {
1072
+ const filePath = typeof req.query?.path === 'string' ? req.query.path.trim() : '';
1073
+ const overwrite = req.query?.overwrite === 'true';
1074
+ if (!filePath) {
1075
+ return res.status(400).json({ error: 'Path is required' });
1076
+ }
1077
+ if (!String(req.headers?.['content-type'] || '').toLowerCase().startsWith('application/octet-stream')) {
1078
+ return res.status(415).json({ error: 'Content-Type must be application/octet-stream' });
1079
+ }
1080
+
1081
+ const maxUploadBytes = createUploadMaxBytes();
1082
+ const declaredSize = Number(req.headers?.['content-length']);
1083
+ if (Number.isFinite(declaredSize) && declaredSize > maxUploadBytes) {
1084
+ req.resume?.();
1085
+ return res.status(413).json({ error: `File exceeds maximum size of ${maxUploadBytes} bytes` });
1086
+ }
1087
+
1088
+ try {
1089
+ const resolved = await resolveWorkspacePathFromContext({
1090
+ req,
1091
+ targetPath: filePath,
1092
+ resolveProjectDirectory,
1093
+ path,
1094
+ os,
1095
+ normalizeDirectoryPath,
1096
+ openchamberUserConfigRoot,
1097
+ });
1098
+ if (!resolved.ok) {
1099
+ return res.status(400).json({ error: resolved.error });
1100
+ }
1101
+
1102
+ const canonicalBase = await fsPromises.realpath(resolved.base).catch(() => path.resolve(resolved.base));
1103
+ const requestedParent = path.dirname(resolved.resolved);
1104
+ const canonicalParent = await fsPromises.realpath(requestedParent);
1105
+ if (!isPathWithinRoot(canonicalParent, canonicalBase, path, os)) {
1106
+ return res.status(403).json({ error: 'Access denied' });
1107
+ }
1108
+
1109
+ const existingPath = await fsPromises.realpath(resolved.resolved).catch((error) => {
1110
+ if (error && typeof error === 'object' && error.code === 'ENOENT') {
1111
+ return null;
1112
+ }
1113
+ throw error;
1114
+ });
1115
+ const writePath = existingPath || path.join(canonicalParent, path.basename(resolved.resolved));
1116
+ if (!isPathWithinRoot(writePath, canonicalBase, path, os)) {
1117
+ return res.status(403).json({ error: 'Access denied' });
1118
+ }
1119
+
1120
+ if (existingPath) {
1121
+ const stats = await fsPromises.stat(existingPath);
1122
+ if (stats.isDirectory()) {
1123
+ return res.status(400).json({ error: 'Specified path is a directory' });
1124
+ }
1125
+ if (!overwrite) {
1126
+ req.resume?.();
1127
+ return res.status(409).json({ error: 'File already exists', reason: 'already-exists' });
1128
+ }
1129
+ }
1130
+
1131
+ const tmp = `${writePath}.upload-${crypto.randomUUID()}`;
1132
+ let tempExists = false;
1133
+ try {
1134
+ const handle = await fsPromises.open(tmp, 'wx');
1135
+ tempExists = true;
1136
+ let streamError = null;
1137
+ try {
1138
+ await streamUploadBody(req, handle, maxUploadBytes);
1139
+ } catch (error) {
1140
+ streamError = error;
1141
+ }
1142
+ try {
1143
+ await handle.close();
1144
+ } catch (error) {
1145
+ if (!streamError) throw error;
1146
+ }
1147
+ if (streamError) throw streamError;
1148
+
1149
+ if (overwrite) {
1150
+ await fsPromises.rename(tmp, writePath);
1151
+ } else {
1152
+ // A same-directory hard link commits without replacing a target that
1153
+ // appeared after the existence check. The temp file is already fully
1154
+ // flushed, so readers never observe a partial upload.
1155
+ await fsPromises.link(tmp, writePath);
1156
+ await fsPromises.unlink(tmp).catch(() => {});
1157
+ }
1158
+ tempExists = false;
1159
+ } catch (error) {
1160
+ if (tempExists) {
1161
+ await fsPromises.unlink(tmp).catch(() => {});
1162
+ }
1163
+ throw error;
1164
+ }
1165
+
1166
+ return res.json({ success: true, path: resolved.resolved });
1167
+ } catch (error) {
1168
+ const err = error;
1169
+ if (err && typeof err === 'object' && err.code === 'EEXIST') {
1170
+ return res.status(409).json({ error: 'File already exists', reason: 'already-exists' });
1171
+ }
1172
+ if (err && typeof err === 'object' && err.code === 'ENOENT') {
1173
+ return res.status(404).json({ error: 'Destination directory not found', reason: 'not-found' });
1174
+ }
1175
+ if (err && typeof err === 'object' && err.uploadTooLarge) {
1176
+ return res.status(413).json({ error: `File exceeds maximum size of ${maxUploadBytes} bytes` });
1177
+ }
1178
+ if (err && typeof err === 'object' && (err.code === 'EISDIR' || err.code === 'ENOTDIR')) {
1179
+ return res.status(400).json({ error: 'Specified path is a directory' });
1180
+ }
1181
+ if (isOsPermissionError(err)) {
1182
+ return sendOsPermissionDenied(res, 'Access denied');
1183
+ }
1184
+ console.error('Failed to upload file:', error);
1185
+ return res.status(500).json({ error: (error && error.message) || 'Failed to upload file' });
1186
+ }
1187
+ });
1188
+
1072
1189
  app.post('/api/fs/delete', async (req, res) => {
1073
1190
  const { path: targetPath } = req.body || {};
1074
1191
  if (!targetPath || typeof targetPath !== 'string') {