@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.
- package/README.md +1 -0
- package/dist/assets/{CodeMirrorCommentWidgets-4qZbrEXU.js → CodeMirrorCommentWidgets-C36E738Y.js} +1 -1
- package/dist/assets/{CommitSection-MJmntVPJ.js → CommitSection-C-F3AX6D.js} +1 -1
- package/dist/assets/{DiagramEditor-jnG3Hbxg.js → DiagramEditor-BPECg1jS.js} +1 -1
- package/dist/assets/DiagramView-D0YNMix8.js +1 -0
- package/dist/assets/DiffView-BHWaMYCC.js +4 -0
- package/dist/assets/FilesView-NMBCW2Tm.js +14 -0
- package/dist/assets/{GitView-DBFrDDBv.js → GitView-Rp8P1KEI.js} +4 -4
- package/dist/assets/{JsonTreeView-DLW2Wy1g.js → JsonTreeView-KnXFN2A-.js} +1 -1
- package/dist/assets/MarkdownImageGallery-BMn3mtor.js +1 -0
- package/dist/assets/MarkdownRendererImpl-kD6N03pH.js +12 -0
- package/dist/assets/OnboardingScreen-CenIeD4v.js +1 -0
- package/dist/assets/{PatchDiff-BuLPx7AN.js → PatchDiff-BzVOVog8.js} +1 -1
- package/dist/assets/{PierreDiffViewer-BHm4Yr0X.js → PierreDiffViewer-Dlby4XqT.js} +2 -2
- package/dist/assets/PlanView-Czu1KMJa.js +4 -0
- package/dist/assets/SessionSwitcherDropdown-IETz58DB.js +1 -0
- package/dist/assets/SettingsView-B6vmuf-c.js +28 -0
- package/dist/assets/SettingsWindow-CauZpdD3.js +1 -0
- package/dist/assets/ToolOutputDialog-BB1c--Zr.js +15 -0
- package/dist/assets/ToolPartDiffPreview-DaOIDISD.js +8 -0
- package/dist/assets/{VirtualizedFileDiff-CwGocYQd.js → VirtualizedFileDiff-lESMT-2b.js} +4 -4
- package/dist/assets/{WalkthroughView-5DyvN03T.js → WalkthroughView-CaSYE0lw.js} +2 -2
- package/dist/assets/{computeVirtualFileMetrics-Da00Jg7M.js → computeVirtualFileMetrics-DkRR5b75.js} +2 -2
- package/dist/assets/contextPanelEmbeddedChat-BEARQjgn.js +1 -0
- package/dist/assets/de-DFdX3ABv.js +9 -0
- package/dist/assets/document-attachments-DFAWlG3U.js +31 -0
- package/dist/assets/es-iC-FKvV9.js +15 -0
- package/dist/assets/fr-BBbi_1AL.js +13 -0
- package/dist/assets/index-BiEgzzkg.js +1 -0
- package/dist/assets/index-Cwmuwk3V.js +7 -0
- package/dist/assets/index-GNm1wgUH.css +1 -0
- package/dist/assets/{isDiffPlainText-D9YpoLrV.js → isDiffPlainText-BG53Ixxy.js} +1 -1
- package/dist/assets/{isFilePlainText-gTibdNIe.js → isFilePlainText-BbV-39jl.js} +1 -1
- package/dist/assets/ja-DQLQJL2J.js +15 -0
- package/dist/assets/ko-BeElEB4Y.js +15 -0
- package/dist/assets/{lua-BgMRiT3U.js → lua-VAEuO923.js} +1 -1
- package/dist/assets/main-Dpzo18z7.js +2 -0
- package/dist/assets/main-WMjtYzJs.js +921 -0
- package/dist/assets/markdownCore--tDmyI_v.js +2 -0
- package/dist/assets/miniChat-ldEghBLB.js +2 -0
- package/dist/assets/mobile-Dk-VGreF.js +2 -0
- package/dist/assets/{patchFileDiff-KNkxM1C1.js → patchFileDiff-BcFaMtMu.js} +1 -1
- package/dist/assets/pl-CLHt2_vV.js +15 -0
- package/dist/assets/pt-BR-C_MPUq7e.js +15 -0
- package/dist/assets/renderElectronMiniChatApp-DIgCOmXY.js +2 -0
- package/dist/assets/renderMobileApp-CDfHS5rr.js +25 -0
- package/dist/assets/runtimeEndpointReset-ovNbaZ-x.js +15 -0
- package/dist/assets/scheduledTasksApi-BFSlqgnG.js +1 -0
- package/dist/assets/{shikiHighlight-C7LTbwFx.js → shikiHighlight-DCT2Sq_z.js} +1 -1
- package/dist/assets/uk-PhsC-c4-.js +15 -0
- package/dist/assets/{useAppFontEffects-BikB6enL.js → useAppFontEffects-B53Rb6m7.js} +168 -164
- package/dist/assets/useInlineCommentController-DSfrIBKT.js +2 -0
- package/dist/assets/{vendor-base-ui-D_V6hAcE.js → vendor-base-ui-DsHmyMwp.js} +1 -1
- package/dist/assets/vendor-codemirror-autocomplete-DzPz9Wgq.js +1 -0
- package/dist/assets/vendor-codemirror-commands-B7H_j0iU.js +1 -0
- package/dist/assets/{vendor-codemirror-lang-angular-CgY7_gQ1.js → vendor-codemirror-lang-angular-DEPs2M5t.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-cpp-B5Ta4enQ.js → vendor-codemirror-lang-cpp-DhkseaMo.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-css-VgNqFSH-.js → vendor-codemirror-lang-css-O0cZX78y.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-go-LxLz62pp.js → vendor-codemirror-lang-go-fMdQYcON.js} +1 -1
- package/dist/assets/vendor-codemirror-lang-html-CfgK872x.js +1 -0
- package/dist/assets/{vendor-codemirror-lang-java-Bksi1PH4.js → vendor-codemirror-lang-java-CQj4S3zl.js} +1 -1
- package/dist/assets/vendor-codemirror-lang-javascript-Cc2ZYbgX.js +13 -0
- package/dist/assets/{vendor-codemirror-lang-jinja-C7npuDD7.js → vendor-codemirror-lang-jinja-BmZZv8g-.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-json-ryCw7nab.js → vendor-codemirror-lang-json-CMBS2tG9.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-less-BxsZJD6N.js → vendor-codemirror-lang-less-C6Eo8hVS.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-liquid-De6qch10.js → vendor-codemirror-lang-liquid-DSTR47-H.js} +1 -1
- package/dist/assets/vendor-codemirror-lang-markdown-BPGOH9ye.js +1 -0
- package/dist/assets/{vendor-codemirror-lang-php-Cm1es33p.js → vendor-codemirror-lang-php-DD9udfPH.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-python-N414WYK-.js → vendor-codemirror-lang-python-HahnQaAS.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-rust-C_WuUStH.js → vendor-codemirror-lang-rust-nLTovbjv.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-sass-8UHTCAOM.js → vendor-codemirror-lang-sass-pL2Yc72v.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-sql-CV3sMA5D.js → vendor-codemirror-lang-sql-BVBnan19.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-vue-DzvC1Dhk.js → vendor-codemirror-lang-vue-BqGzJVm1.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-wast-jlr-LDdA.js → vendor-codemirror-lang-wast-B0_m5DqU.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-xml-CrO63OVp.js → vendor-codemirror-lang-xml-Dj3voadT.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-yaml-dxi6CISW.js → vendor-codemirror-lang-yaml-yu-9Z5u7.js} +1 -1
- package/dist/assets/vendor-codemirror-language-BgPj_McA.js +3 -0
- package/dist/assets/{vendor-codemirror-language-data-CLHw8NWn.js → vendor-codemirror-language-data-vch3tJ4c.js} +2 -2
- package/dist/assets/vendor-codemirror-search-BmS-GmcX.js +2 -0
- package/dist/assets/{vendor-codemirror-state-CNWM3Q8V.js → vendor-codemirror-state-C9awkmn-.js} +5 -5
- package/dist/assets/vendor-codemirror-view-CiLROUVV.js +4 -0
- package/dist/assets/vendor-replit-codemirror-vim-B2DJlAhT.js +6 -0
- package/dist/assets/vendor-replit-codemirror-vim-core-FHzKdNUS.js +34 -0
- package/dist/assets/vendor-zod-C9ioTTSo.js +39 -0
- package/dist/assets/{web-components-GMc3oR3i.js → web-components-pcwCTWjC.js} +4 -4
- package/dist/assets/zh-CN-wF-NOFHM.js +15 -0
- package/dist/assets/zh-TW-4m4-A7rT.js +15 -0
- package/dist/index.html +5 -4
- package/dist/mini-chat.html +4 -3
- package/dist/mobile.html +4 -3
- package/package.json +3 -5
- package/server/index.js +152 -3
- package/server/lib/agent-memory/actions.js +243 -0
- package/server/lib/agent-memory/actions.test.js +343 -0
- package/server/lib/agent-memory/feature-flag.js +19 -0
- package/server/lib/agent-memory/feature-flag.test.js +38 -0
- package/server/lib/agent-memory/project-resolution.js +65 -0
- package/server/lib/agent-memory/project-resolution.test.js +94 -0
- package/server/lib/agent-memory/routes.http.test.js +270 -0
- package/server/lib/agent-memory/routes.js +169 -0
- package/server/lib/agent-memory/runtime.js +432 -0
- package/server/lib/agent-memory/runtime.test.js +344 -0
- package/server/lib/agent-memory/threat-patterns.js +61 -0
- package/server/lib/agent-memory/threat-patterns.test.js +61 -0
- package/server/lib/agent-tool/DOCUMENTATION.md +14 -0
- package/server/lib/agent-tool/runtime.js +63 -13
- package/server/lib/agent-tool/runtime.test.js +85 -2
- package/server/lib/context-obligatory/runtime.js +34 -3
- package/server/lib/context-obligatory/runtime.test.js +114 -0
- package/server/lib/dictation/DOCUMENTATION.md +32 -8
- package/server/lib/dictation/local/sherpa-recognizer.js +35 -78
- package/server/lib/dictation/local/worker-process.js +2 -2
- package/server/lib/dictation/openai-compatible-session.js +3 -2
- package/server/lib/dictation/stream-manager.js +77 -34
- package/server/lib/dictation/stream-manager.test.js +60 -2
- package/server/lib/fs/DOCUMENTATION.md +3 -0
- package/server/lib/fs/routes.js +149 -32
- package/server/lib/fs/routes.test.js +301 -0
- package/server/lib/git/DOCUMENTATION.md +8 -0
- package/server/lib/git/routes.js +43 -0
- package/server/lib/git/service.js +206 -72
- package/server/lib/git/service.test.js +222 -0
- package/server/lib/github/DOCUMENTATION.md +14 -3
- package/server/lib/github/pr-status.js +188 -83
- package/server/lib/github/pr-status.test.js +182 -0
- package/server/lib/github/routes.js +36 -30
- package/server/lib/notifications/template-runtime.js +2 -3
- package/server/lib/openchamber-control/action-resolution.test.js +65 -0
- package/server/lib/openchamber-control/actions.js +78 -0
- package/server/lib/openchamber-control/service.js +7 -0
- package/server/lib/openchamber-sessions/routes.js +14 -0
- package/server/lib/opencode/DOCUMENTATION.md +12 -6
- package/server/lib/opencode/claude-cli-auth.js +60 -0
- package/server/lib/opencode/claude-cli-auth.test.js +54 -0
- package/server/lib/opencode/feature-routes-runtime.js +16 -9
- package/server/lib/opencode/lifecycle.js +202 -26
- package/server/lib/opencode/lifecycle.test.js +179 -1
- package/server/lib/opencode/plugins.js +12 -3
- package/server/lib/opencode/plugins.test.js +18 -0
- package/server/lib/opencode/providers.js +9 -4
- package/server/lib/opencode/providers.test.js +27 -0
- package/server/lib/opencode/proxy-agent-wiring.test.js +152 -0
- package/server/lib/opencode/proxy.js +116 -6
- package/server/lib/opencode/proxy.test.js +158 -1
- package/server/lib/opencode/restart-session-recovery.test.js +59 -0
- package/server/lib/opencode/routes.js +4 -1
- package/server/lib/opencode/session-runtime.js +39 -2
- package/server/lib/opencode/session-runtime.test.js +74 -0
- package/server/lib/opencode/settings-helpers.js +26 -0
- package/server/lib/opencode/settings-helpers.test.js +57 -0
- package/server/lib/opencode/settings-normalization-runtime.js +3 -0
- package/server/lib/opencode/settings-normalization-runtime.test.js +16 -0
- package/server/lib/opencode/settings-runtime.js +83 -10
- package/server/lib/opencode/settings-runtime.test.js +85 -0
- package/server/lib/opencode/shared.js +120 -16
- package/server/lib/opencode/shared.test.js +185 -1
- package/server/lib/opencode/skill-routes.js +29 -73
- package/server/lib/opencode/skill-routes.test.js +2 -5
- package/server/lib/project-context/DOCUMENTATION.md +160 -0
- package/server/lib/project-context/routes.http.test.js +264 -0
- package/server/lib/project-context/routes.js +237 -0
- package/server/lib/project-context/runtime.js +672 -0
- package/server/lib/project-context/runtime.test.js +498 -0
- package/server/lib/projects/project-config.js +7 -2
- package/server/lib/quota/DOCUMENTATION.md +17 -2
- package/server/lib/quota/providers/claude/auth.js +113 -0
- package/server/lib/quota/providers/claude/auth.test.js +117 -0
- package/server/lib/quota/providers/claude/index.js +151 -0
- package/server/lib/quota/providers/claude/index.test.js +147 -0
- package/server/lib/quota/providers/claude/transforms.js +127 -0
- package/server/lib/quota/providers/claude/transforms.test.js +82 -0
- package/server/lib/quota/providers/command-code.js +90 -0
- package/server/lib/quota/providers/command-code.test.js +85 -0
- package/server/lib/quota/providers/index.js +30 -2
- package/server/lib/quota/providers/index.test.js +10 -1
- package/server/lib/quota/providers/zai.js +26 -6
- package/server/lib/quota/providers/zai.test.js +33 -0
- package/server/lib/quota/utils/formatters.js +2 -1
- package/server/lib/scheduled-tasks/runtime.js +21 -2
- package/server/lib/session-knowledge/DOCUMENTATION.md +89 -0
- package/server/lib/session-knowledge/routes.js +107 -0
- package/server/lib/session-knowledge/runtime.js +331 -0
- package/server/lib/session-knowledge/runtime.test.js +275 -0
- package/server/lib/skills-catalog/DOCUMENTATION.md +18 -45
- package/server/lib/skills-catalog/cache.js +120 -1
- package/server/lib/skills-catalog/cache.test.js +77 -0
- package/server/lib/skills-catalog/curated-sources.js +21 -5
- package/server/lib/skills-catalog/curated-sources.test.js +10 -0
- package/server/lib/skills-catalog/disk-cache.js +52 -0
- package/server/lib/skills-catalog/github-meta.js +139 -0
- package/server/lib/skills-catalog/github-meta.test.js +71 -0
- package/server/lib/skills-catalog/source.js +0 -5
- package/server/lib/small-model/DOCUMENTATION.md +74 -6
- package/server/lib/small-model/call.js +46 -12
- package/server/lib/small-model/call.test.js +79 -0
- package/server/lib/small-model/index.js +57 -6
- package/server/lib/small-model/index.test.js +102 -2
- package/server/lib/small-model/routes.js +4 -2
- package/server/lib/small-model/runtime-providers.js +156 -0
- package/server/lib/small-model/runtime-providers.test.js +112 -0
- package/dist/assets/DiagramView-CFXxgg_a.js +0 -1
- package/dist/assets/DiffView-DZIoOnV7.js +0 -4
- package/dist/assets/FilesView-BKL6YlKG.js +0 -14
- package/dist/assets/MarkdownImageGallery-DKIylIK7.js +0 -1
- package/dist/assets/MarkdownRendererImpl-CLv8hxvv.js +0 -12
- package/dist/assets/OnboardingScreen-D2Y6djMw.js +0 -1
- package/dist/assets/PlanView-ZYEJn8A_.js +0 -4
- package/dist/assets/SessionSwitcherDropdown-rro-SsaO.js +0 -1
- package/dist/assets/SettingsView-5RmswFZe.js +0 -28
- package/dist/assets/SettingsWindow-BZhAYFdS.js +0 -1
- package/dist/assets/ToolOutputDialog-Za6V4VMJ.js +0 -15
- package/dist/assets/ToolPartDiffPreview-BL-9ixyC.js +0 -8
- package/dist/assets/contextPanelEmbeddedChat-B-bSg3P5.js +0 -1
- package/dist/assets/de-u7gSnqWs.js +0 -9
- package/dist/assets/document-attachments-CX_YaDsu.js +0 -30
- package/dist/assets/es-T9O7aAOr.js +0 -15
- package/dist/assets/fr-Oor7ewbE.js +0 -13
- package/dist/assets/index-BzIpNlNE.css +0 -1
- package/dist/assets/index-C0yNhuZw.js +0 -1
- package/dist/assets/index-DRpChWux.js +0 -7
- package/dist/assets/ja-DHpqbVmr.js +0 -15
- package/dist/assets/ko-CwLkS3nx.js +0 -15
- package/dist/assets/main-D7UcL3VQ.js +0 -2
- package/dist/assets/main-DPMd2iKS.js +0 -915
- package/dist/assets/markdownCore-DDrHVneM.js +0 -2
- package/dist/assets/miniChat-O_GVoEbc.js +0 -2
- package/dist/assets/mobile-Br4TtAqc.js +0 -2
- package/dist/assets/pl-CcZILN8q.js +0 -15
- package/dist/assets/pt-BR-DYHhVK6o.js +0 -15
- package/dist/assets/renderElectronMiniChatApp-CJpdxTT1.js +0 -2
- package/dist/assets/renderMobileApp-toj9cXoh.js +0 -25
- package/dist/assets/runtimeEndpointReset-BVmispdD.js +0 -13
- package/dist/assets/scheduledTasksApi-ByKya3Un.js +0 -1
- package/dist/assets/uk-BA2kZR38.js +0 -15
- package/dist/assets/useInlineCommentController-CYPvYJDt.js +0 -2
- package/dist/assets/vendor-codemirror-autocomplete-BjbBRsUA.js +0 -1
- package/dist/assets/vendor-codemirror-commands-ARAOgp1x.js +0 -1
- package/dist/assets/vendor-codemirror-lang-html-B3Qe3OpS.js +0 -1
- package/dist/assets/vendor-codemirror-lang-javascript-Bbw3D7r0.js +0 -13
- package/dist/assets/vendor-codemirror-lang-markdown-FGQydhTc.js +0 -1
- package/dist/assets/vendor-codemirror-language-DUOssd4j.js +0 -3
- package/dist/assets/vendor-codemirror-search-8kyQdB3f.js +0 -2
- package/dist/assets/vendor-codemirror-view-DSzLbZiS.js +0 -4
- package/dist/assets/vendor-replit-codemirror-vim-B0Ecqnlh.js +0 -39
- package/dist/assets/zh-CN-dlOQK6v9.js +0 -15
- package/dist/assets/zh-TW-BnqQ-WL5.js +0 -15
- package/server/lib/quota/providers/claude.js +0 -107
- package/server/lib/skills-catalog/clawdhub/api.js +0 -126
- package/server/lib/skills-catalog/clawdhub/install.js +0 -238
- package/server/lib/skills-catalog/clawdhub/install.test.js +0 -100
- package/server/lib/skills-catalog/clawdhub/scan.js +0 -61
|
@@ -181,7 +181,7 @@ describe('managed agent tool runtime', () => {
|
|
|
181
181
|
|
|
182
182
|
it('omits a tool the user turned off', async () => {
|
|
183
183
|
const { runtime, dataDir } = await createRuntime();
|
|
184
|
-
await runtime.prepareManagedOpenCodeEnv({ includeControl: false, includeWeb: true });
|
|
184
|
+
await runtime.prepareManagedOpenCodeEnv({ includeControl: false, includeWeb: true, includeMemory: false });
|
|
185
185
|
const pluginPath = path.join(dataDir, 'agent-tool', 'openchamber-plugin.js');
|
|
186
186
|
const pluginModule = await import(`${pathToFileURL(pluginPath).href}?web=${Date.now()}`);
|
|
187
187
|
const { tool } = await pluginModule.OpenChamberPlugin();
|
|
@@ -189,17 +189,100 @@ describe('managed agent tool runtime', () => {
|
|
|
189
189
|
expect(Object.keys(tool)).toEqual(['openchamber_web']);
|
|
190
190
|
});
|
|
191
191
|
|
|
192
|
+
it('exposes memory as its own tool carrying only its own inputs', async () => {
|
|
193
|
+
const { runtime, dataDir } = await createRuntime();
|
|
194
|
+
await runtime.prepareManagedOpenCodeEnv({ includeControl: true, includeWeb: false, includeMemory: true });
|
|
195
|
+
const pluginPath = path.join(dataDir, 'agent-tool', 'openchamber-plugin.js');
|
|
196
|
+
const pluginModule = await import(`${pathToFileURL(pluginPath).href}?memory=${Date.now()}`);
|
|
197
|
+
const { tool } = await pluginModule.OpenChamberPlugin();
|
|
198
|
+
|
|
199
|
+
expect(Object.keys(tool)).toEqual(['openchamber', 'openchamber_memory']);
|
|
200
|
+
expect(Object.keys(tool.openchamber_memory.args.parameters.properties).sort())
|
|
201
|
+
.toEqual(['body', 'memoryId', 'scope', 'title', 'type']);
|
|
202
|
+
// Memory inputs must not leak into the control tool's schema, which the
|
|
203
|
+
// model pays for on every unrelated call.
|
|
204
|
+
expect(Object.keys(tool.openchamber.args.parameters.properties)).not.toContain('memoryId');
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it('omits memory entirely when the user turns it off', async () => {
|
|
208
|
+
const { runtime, dataDir } = await createRuntime();
|
|
209
|
+
await runtime.prepareManagedOpenCodeEnv({ includeControl: true, includeWeb: false, includeMemory: false });
|
|
210
|
+
const pluginPath = path.join(dataDir, 'agent-tool', 'openchamber-plugin.js');
|
|
211
|
+
const pluginModule = await import(`${pathToFileURL(pluginPath).href}?nomemory=${Date.now()}`);
|
|
212
|
+
const { tool } = await pluginModule.OpenChamberPlugin();
|
|
213
|
+
|
|
214
|
+
expect(Object.keys(tool)).toEqual(['openchamber']);
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
it('injects the plugin when memory is the only tool left on', async () => {
|
|
218
|
+
const { runtime, dataDir } = await createRuntime();
|
|
219
|
+
await runtime.prepareManagedOpenCodeEnv({ includeControl: false, includeWeb: false, includeMemory: true });
|
|
220
|
+
const pluginPath = path.join(dataDir, 'agent-tool', 'openchamber-plugin.js');
|
|
221
|
+
const pluginModule = await import(`${pathToFileURL(pluginPath).href}?onlymemory=${Date.now()}`);
|
|
222
|
+
const { tool } = await pluginModule.OpenChamberPlugin();
|
|
223
|
+
|
|
224
|
+
expect(Object.keys(tool)).toEqual(['openchamber_memory']);
|
|
225
|
+
});
|
|
226
|
+
|
|
192
227
|
it('refuses to inject a plugin with no tools in it', async () => {
|
|
193
228
|
const { runtime } = await createRuntime();
|
|
194
229
|
let failed = false;
|
|
195
230
|
try {
|
|
196
|
-
await runtime.prepareManagedOpenCodeEnv({ includeControl: false, includeWeb: false });
|
|
231
|
+
await runtime.prepareManagedOpenCodeEnv({ includeControl: false, includeWeb: false, includeMemory: false });
|
|
197
232
|
} catch {
|
|
198
233
|
failed = true;
|
|
199
234
|
}
|
|
200
235
|
expect(failed).toBe(true);
|
|
201
236
|
});
|
|
202
237
|
|
|
238
|
+
it('accepts the bare action a tool name already qualifies', async () => {
|
|
239
|
+
// Observed: the model called `read` on openchamber_memory, having taken the
|
|
240
|
+
// tool's own name for the namespace.
|
|
241
|
+
const executeAction = vi.fn(async () => ({ memory: {} }));
|
|
242
|
+
const { runtime } = await createRuntime({ executeAction });
|
|
243
|
+
|
|
244
|
+
const result = await runtime.execute({
|
|
245
|
+
input: { action: 'read', title: 'Uses bun' },
|
|
246
|
+
contextDirectory: '/work/project',
|
|
247
|
+
tool: 'openchamber_memory',
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
expect(result.ok).toBe(true);
|
|
251
|
+
expect(result.action).toBe('memory.read');
|
|
252
|
+
expect(executeAction).toHaveBeenCalledWith(
|
|
253
|
+
'memory.read',
|
|
254
|
+
{ action: 'memory.read', title: 'Uses bun' },
|
|
255
|
+
'/work/project',
|
|
256
|
+
{},
|
|
257
|
+
);
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it('tells an unresolvable action what the calling tool can do', async () => {
|
|
261
|
+
const { runtime } = await createRuntime();
|
|
262
|
+
|
|
263
|
+
const result = await runtime.execute({
|
|
264
|
+
input: { action: 'get' },
|
|
265
|
+
tool: 'openchamber_memory',
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
expect(result.ok).toBe(false);
|
|
269
|
+
expect(result.error.message).toContain('memory.read');
|
|
270
|
+
expect(result.error.message).not.toContain('browser.open');
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
it('does not let one tool reach another tool\'s actions', async () => {
|
|
274
|
+
const executeAction = vi.fn(async () => ({}));
|
|
275
|
+
const { runtime } = await createRuntime({ executeAction });
|
|
276
|
+
|
|
277
|
+
const result = await runtime.execute({
|
|
278
|
+
input: { action: 'open', url: 'https://example.test' },
|
|
279
|
+
tool: 'openchamber_memory',
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
expect(result.ok).toBe(false);
|
|
283
|
+
expect(executeAction).not.toHaveBeenCalled();
|
|
284
|
+
});
|
|
285
|
+
|
|
203
286
|
it('executes actions through the shared control service', async () => {
|
|
204
287
|
const executeAction = vi.fn(async () => ({ projects: [] }));
|
|
205
288
|
const { runtime } = await createRuntime({ executeAction });
|
|
@@ -33,6 +33,7 @@ const buildContextPrompt = (entries) => {
|
|
|
33
33
|
export const createContextObligatoryRuntime = ({
|
|
34
34
|
buildOpenCodeUrl,
|
|
35
35
|
getOpenCodeAuthHeaders,
|
|
36
|
+
sessionKnowledgeRuntime = null,
|
|
36
37
|
}) => {
|
|
37
38
|
const inflight = new Set();
|
|
38
39
|
let stopped = false;
|
|
@@ -59,7 +60,26 @@ export const createContextObligatoryRuntime = ({
|
|
|
59
60
|
const session = await openCodeFetch(`/session/${encodeURIComponent(sessionId)}`, { directory });
|
|
60
61
|
if (session?.parentID) return;
|
|
61
62
|
const state = readContextState(session);
|
|
62
|
-
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Project knowledge rides along with the pinned messages. Compaction takes
|
|
66
|
+
* both away, and both are restored for the same reason, so they travel as
|
|
67
|
+
* one message: two synthetic turns back to back would read as the agent
|
|
68
|
+
* being interrupted twice.
|
|
69
|
+
*/
|
|
70
|
+
const knowledge = sessionKnowledgeRuntime
|
|
71
|
+
? await sessionKnowledgeRuntime
|
|
72
|
+
.resolvePending(
|
|
73
|
+
directory,
|
|
74
|
+
// Compaction removed the previously delivered block, so its stored
|
|
75
|
+
// signature is no longer evidence that the session still carries it.
|
|
76
|
+
'',
|
|
77
|
+
sessionKnowledgeRuntime.readPins(session),
|
|
78
|
+
)
|
|
79
|
+
.catch(() => ({ text: '', signature: '' }))
|
|
80
|
+
: { text: '', signature: '' };
|
|
81
|
+
|
|
82
|
+
if (state.messages.length === 0 && !knowledge.text) return;
|
|
63
83
|
|
|
64
84
|
const recent = await openCodeFetch(`/session/${encodeURIComponent(sessionId)}/message`, {
|
|
65
85
|
directory,
|
|
@@ -86,7 +106,7 @@ export const createContextObligatoryRuntime = ({
|
|
|
86
106
|
.filter((result) => result.status === 'fulfilled' && result.value.text)
|
|
87
107
|
.map((result) => result.value)
|
|
88
108
|
.sort((left, right) => left.pinned.createdAt - right.pinned.createdAt);
|
|
89
|
-
if (entries.length === 0) return;
|
|
109
|
+
if (entries.length === 0 && !knowledge.text) return;
|
|
90
110
|
|
|
91
111
|
const executionInfo = recent.toReversed().find((message) =>
|
|
92
112
|
message?.info?.role === 'assistant' && message.info.summary !== true)?.info;
|
|
@@ -100,7 +120,13 @@ export const createContextObligatoryRuntime = ({
|
|
|
100
120
|
body: {
|
|
101
121
|
model: { providerID, modelID },
|
|
102
122
|
...(typeof agent === 'string' && agent ? { agent } : {}),
|
|
103
|
-
parts: [{
|
|
123
|
+
parts: [{
|
|
124
|
+
type: 'text',
|
|
125
|
+
text: [knowledge.text, entries.length > 0 ? buildContextPrompt(entries) : '']
|
|
126
|
+
.filter(Boolean)
|
|
127
|
+
.join('\n\n---\n\n'),
|
|
128
|
+
synthetic: true,
|
|
129
|
+
}],
|
|
104
130
|
},
|
|
105
131
|
});
|
|
106
132
|
|
|
@@ -115,6 +141,11 @@ export const createContextObligatoryRuntime = ({
|
|
|
115
141
|
openchamber: {
|
|
116
142
|
...freshState.openchamber,
|
|
117
143
|
context_obligatory_last_compaction_message_id: summary.id,
|
|
144
|
+
// Recorded together with the cursor: the session now carries this
|
|
145
|
+
// knowledge again, so the next send must not repeat it.
|
|
146
|
+
...(knowledge.signature
|
|
147
|
+
? { [sessionKnowledgeRuntime.metadataKey]: knowledge.signature }
|
|
148
|
+
: {}),
|
|
118
149
|
},
|
|
119
150
|
},
|
|
120
151
|
},
|
|
@@ -63,6 +63,120 @@ describe('context obligatory runtime', () => {
|
|
|
63
63
|
runtime.stop();
|
|
64
64
|
});
|
|
65
65
|
|
|
66
|
+
|
|
67
|
+
it('restores project knowledge after compaction even with nothing pinned', async () => {
|
|
68
|
+
// Pinned messages are already in the conversation until compaction removes
|
|
69
|
+
// them; project knowledge was never there at all, so a session with no
|
|
70
|
+
// pinned messages still has something to get back.
|
|
71
|
+
const requests = [];
|
|
72
|
+
vi.stubGlobal('fetch', vi.fn(async (input, init = {}) => {
|
|
73
|
+
const url = new URL(typeof input === 'string' ? input : input.url);
|
|
74
|
+
requests.push({ path: url.pathname, method: init.method ?? 'GET', body: init.body });
|
|
75
|
+
if (url.pathname === '/session/ses_1' && init.method === 'PATCH') return json({});
|
|
76
|
+
if (url.pathname === '/session/ses_1') return json({
|
|
77
|
+
id: 'ses_1',
|
|
78
|
+
metadata: { openchamber: { knowledge_context_delivered: 'sig-before-compaction' } },
|
|
79
|
+
});
|
|
80
|
+
if (url.pathname === '/session/ses_1/message') return json([
|
|
81
|
+
{ info: { id: 'msg_agent', role: 'assistant', providerID: 'provider', modelID: 'model', agent: 'build' } },
|
|
82
|
+
{ info: { id: 'msg_summary', role: 'assistant', summary: true, time: { completed: 30 } } },
|
|
83
|
+
]);
|
|
84
|
+
if (url.pathname === '/session/ses_1/prompt_async') return json({});
|
|
85
|
+
throw new Error(`Unexpected ${url.pathname}`);
|
|
86
|
+
}));
|
|
87
|
+
const resolvePending = vi.fn(async () => ({
|
|
88
|
+
text: '## Pinned notes\n\n- Remember this.',
|
|
89
|
+
signature: 'sig-1',
|
|
90
|
+
}));
|
|
91
|
+
const runtime = createContextObligatoryRuntime({
|
|
92
|
+
buildOpenCodeUrl: (path) => `http://opencode.test${path}`,
|
|
93
|
+
getOpenCodeAuthHeaders: () => ({}),
|
|
94
|
+
sessionKnowledgeRuntime: {
|
|
95
|
+
metadataKey: 'knowledge_context_delivered',
|
|
96
|
+
readPins: () => ({ notes: ['n1'], plans: [] }),
|
|
97
|
+
resolvePending,
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
await runtime.processPayload({
|
|
102
|
+
type: 'session.compacted',
|
|
103
|
+
properties: { sessionID: 'ses_1', directory: '/work/project' },
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
expect(resolvePending).toHaveBeenCalledWith(
|
|
107
|
+
'/work/project',
|
|
108
|
+
'',
|
|
109
|
+
{ notes: ['n1'], plans: [] },
|
|
110
|
+
);
|
|
111
|
+
const prompt = requests.find((request) => request.path.endsWith('/prompt_async'));
|
|
112
|
+
expect(JSON.parse(prompt.body).parts[0].text).toContain('Remember this.');
|
|
113
|
+
const patch = requests.find((request) => request.method === 'PATCH');
|
|
114
|
+
// Recorded with the cursor, so the next ordinary send does not repeat it.
|
|
115
|
+
expect(JSON.parse(patch.body).metadata.openchamber.knowledge_context_delivered).toBe('sig-1');
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('sends pinned messages and project knowledge as one message', async () => {
|
|
119
|
+
const requests = [];
|
|
120
|
+
vi.stubGlobal('fetch', vi.fn(async (input, init = {}) => {
|
|
121
|
+
const url = new URL(typeof input === 'string' ? input : input.url);
|
|
122
|
+
requests.push({ path: url.pathname, method: init.method ?? 'GET', body: init.body });
|
|
123
|
+
if (url.pathname === '/session/ses_1' && init.method === 'PATCH') return json({});
|
|
124
|
+
if (url.pathname === '/session/ses_1') return json({
|
|
125
|
+
id: 'ses_1',
|
|
126
|
+
metadata: { openchamber: { context_obligatory_messages: [{ id: 'msg_1', createdAt: 10, role: 'user' }] } },
|
|
127
|
+
});
|
|
128
|
+
if (url.pathname === '/session/ses_1/message') return json([
|
|
129
|
+
{ info: { id: 'msg_agent', role: 'assistant', providerID: 'provider', modelID: 'model', agent: 'build' } },
|
|
130
|
+
{ info: { id: 'msg_summary', role: 'assistant', summary: true, time: { completed: 30 } } },
|
|
131
|
+
]);
|
|
132
|
+
if (url.pathname === '/session/ses_1/message/msg_1') return json({ parts: [{ type: 'text', text: 'Pinned message' }] });
|
|
133
|
+
if (url.pathname === '/session/ses_1/prompt_async') return json({});
|
|
134
|
+
throw new Error(`Unexpected ${url.pathname}`);
|
|
135
|
+
}));
|
|
136
|
+
const runtime = createContextObligatoryRuntime({
|
|
137
|
+
buildOpenCodeUrl: (path) => `http://opencode.test${path}`,
|
|
138
|
+
getOpenCodeAuthHeaders: () => ({}),
|
|
139
|
+
sessionKnowledgeRuntime: {
|
|
140
|
+
metadataKey: 'knowledge_context_delivered',
|
|
141
|
+
readPins: () => ({ notes: ['n1'], plans: [] }),
|
|
142
|
+
resolvePending: async () => ({ text: 'Pinned notes block', signature: 'sig-1' }),
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
await runtime.processPayload({ type: 'session.compacted', properties: { sessionID: 'ses_1' } });
|
|
147
|
+
|
|
148
|
+
// One turn, not two: back-to-back synthetic messages read as the agent
|
|
149
|
+
// being interrupted twice.
|
|
150
|
+
const prompts = requests.filter((request) => request.path.endsWith('/prompt_async'));
|
|
151
|
+
expect(prompts).toHaveLength(1);
|
|
152
|
+
const text = JSON.parse(prompts[0].body).parts[0].text;
|
|
153
|
+
expect(text).toContain('Pinned notes block');
|
|
154
|
+
expect(text).toContain('Pinned message');
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it('does nothing when the session already carries the knowledge and has no pins', async () => {
|
|
158
|
+
const requests = [];
|
|
159
|
+
vi.stubGlobal('fetch', vi.fn(async (input, init = {}) => {
|
|
160
|
+
const url = new URL(typeof input === 'string' ? input : input.url);
|
|
161
|
+
requests.push({ path: url.pathname, method: init.method ?? 'GET' });
|
|
162
|
+
if (url.pathname === '/session/ses_1') return json({ id: 'ses_1', metadata: {} });
|
|
163
|
+
throw new Error(`Unexpected ${url.pathname}`);
|
|
164
|
+
}));
|
|
165
|
+
const runtime = createContextObligatoryRuntime({
|
|
166
|
+
buildOpenCodeUrl: (path) => `http://opencode.test${path}`,
|
|
167
|
+
getOpenCodeAuthHeaders: () => ({}),
|
|
168
|
+
sessionKnowledgeRuntime: {
|
|
169
|
+
metadataKey: 'knowledge_context_delivered',
|
|
170
|
+
readPins: () => ({ notes: [], plans: [] }),
|
|
171
|
+
resolvePending: async () => ({ text: '', signature: 'sig-1' }),
|
|
172
|
+
},
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
await runtime.processPayload({ type: 'session.compacted', properties: { sessionID: 'ses_1' } });
|
|
176
|
+
|
|
177
|
+
expect(requests.some((request) => request.path.endsWith('/prompt_async'))).toBe(false);
|
|
178
|
+
});
|
|
179
|
+
|
|
66
180
|
it('ignores ordinary idle events without making requests', async () => {
|
|
67
181
|
const fetchImpl = vi.fn();
|
|
68
182
|
vi.stubGlobal('fetch', fetchImpl);
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
# Dictation module
|
|
2
2
|
|
|
3
|
-
Server-authoritative
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
Server-authoritative speech-to-text for the chat composer, plus local
|
|
4
|
+
text-to-speech. The client streams 16 kHz mono PCM16 chunks (base64) over a
|
|
5
|
+
WebSocket while the user speaks; the server buffers them and transcribes each
|
|
6
|
+
segment exactly once, when the segment is committed.
|
|
7
|
+
|
|
8
|
+
Transcription is deliberately not incremental. Parakeet is an offline model
|
|
9
|
+
trained on whole utterances, so re-decoding the growing buffer to animate a
|
|
10
|
+
live transcript costs O(n^2) work for a result the final decode replaces. The
|
|
11
|
+
composer shows no text while recording and inserts the full transcript on
|
|
12
|
+
stop.
|
|
7
13
|
|
|
8
14
|
Local TTS (Kokoro via sherpa-onnx OfflineTts) runs in the same worker process
|
|
9
15
|
and is exposed as `POST /api/dictation/tts/speak` (JSON `{text, speakerId?,
|
|
@@ -21,9 +27,9 @@ same status/download/delete routes.
|
|
|
21
27
|
Created from the startup pipeline (`startup-pipeline-runtime.js`) before
|
|
22
28
|
the generic OpenCode proxy so routes are not shadowed.
|
|
23
29
|
- `stream-manager.js` — `DictationStreamManager`, one per WS connection.
|
|
24
|
-
Chunk reordering by `seq` + ack, resampling to the provider rate,
|
|
25
|
-
|
|
26
|
-
|
|
30
|
+
Chunk reordering by `seq` + ack, resampling to the provider rate, segment
|
|
31
|
+
splitting, silence suppression by PCM peak, partial-transcript
|
|
32
|
+
concatenation, adaptive finalization timeout.
|
|
27
33
|
- `service.js` — provider resolution and readiness. Providers:
|
|
28
34
|
- `local` (default): sherpa-onnx Parakeet TDT in a forked worker process.
|
|
29
35
|
Models auto-download in the background on first use; while missing, the
|
|
@@ -33,7 +39,7 @@ same status/download/delete routes.
|
|
|
33
39
|
OpenAI-compatible `/v1/audio/transcriptions` endpoint
|
|
34
40
|
(`openai-compatible-session.js`, reuses `../tts/stt.js`).
|
|
35
41
|
- `local/` — worker process + client (IPC, idle shutdown TTL), sherpa
|
|
36
|
-
recognizer engine and
|
|
42
|
+
recognizer engine and segment session (one decode per committed segment),
|
|
37
43
|
model catalog and downloader. The native `sherpa-onnx-node` addon is only
|
|
38
44
|
ever loaded inside the worker process.
|
|
39
45
|
- `audio.js` — PCM16 helpers: format parsing, peak, WAV wrapping, streaming
|
|
@@ -53,9 +59,27 @@ Server → client: `ready`, `ack {ackSeq}`, `partial {text}`,
|
|
|
53
59
|
`{ provider: 'local' | 'openai-compatible', language?, localModel?,
|
|
54
60
|
openaiCompatible?: { baseUrl, model, apiKey } }`.
|
|
55
61
|
|
|
62
|
+
## Segmentation
|
|
63
|
+
|
|
64
|
+
A dictation is one segment unless it runs long. Past `segmentMinSeconds`
|
|
65
|
+
(60 s) the manager commits on the first silent chunk, so cuts land at a pause
|
|
66
|
+
rather than mid-word; `segmentMaxSeconds` (90 s) is a hard cap for speech with
|
|
67
|
+
no pause in it. Client chunks are ~1 s, so "silent chunk" is roughly a second
|
|
68
|
+
of silence.
|
|
69
|
+
|
|
70
|
+
The bounds exist because Parakeet is a full-attention conformer: decode cost
|
|
71
|
+
and peak memory grow quadratically with segment length. Measured on Parakeet
|
|
72
|
+
v3 int8 with 2 threads: 60 s took 2.1 s and +90 MB, 180 s took 9.3 s and
|
|
73
|
+
+490 MB, 300 s took 21.3 s and +1.5 GB. Committed segments decode while the
|
|
74
|
+
user is still speaking, so only the tail is left to transcribe on stop.
|
|
75
|
+
|
|
56
76
|
## Invariants
|
|
57
77
|
|
|
58
78
|
- Never load `sherpa-onnx-node` in the main server process.
|
|
79
|
+
- Transcription happens on commit only; sessions never emit non-final
|
|
80
|
+
transcripts. The `partial` messages a client receives are the concatenation
|
|
81
|
+
of already-committed segments, and exist so a dictation that fails partway
|
|
82
|
+
can be salvaged instead of losing minutes of speech.
|
|
59
83
|
- The stream manager acks only the highest contiguous seq; the client is
|
|
60
84
|
expected to retain unacked segments for retry/replay.
|
|
61
85
|
- Silence-only segments (peak < 300) are cleared, never committed, so
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Sherpa-onnx offline recognizer engine (NeMo transducer / Parakeet) plus a
|
|
3
|
-
*
|
|
4
|
-
* segment
|
|
3
|
+
* segment transcription session that decodes each segment exactly once, when
|
|
4
|
+
* the segment is committed.
|
|
5
|
+
*
|
|
6
|
+
* Parakeet is an offline model: it is trained to see a whole utterance at
|
|
7
|
+
* once. Decoding the accumulated audio repeatedly to animate a live transcript
|
|
8
|
+
* costs O(n^2) work for a result the final decode throws away, so this session
|
|
9
|
+
* only decodes on commit.
|
|
5
10
|
*
|
|
6
11
|
* Runs inside the dictation worker process only — never load the native
|
|
7
12
|
* addon in the main server process.
|
|
@@ -147,31 +152,26 @@ export class SherpaOfflineRecognizerEngine {
|
|
|
147
152
|
}
|
|
148
153
|
|
|
149
154
|
/**
|
|
150
|
-
*
|
|
151
|
-
* Accumulates the current segment's PCM and
|
|
152
|
-
*
|
|
153
|
-
* finalizes the segment and starts a new one.
|
|
155
|
+
* Segment transcription session backed by the offline recognizer.
|
|
156
|
+
* Accumulates the current segment's PCM and decodes it once in `commit()`,
|
|
157
|
+
* which emits the segment's final transcript and starts a new segment.
|
|
154
158
|
*
|
|
155
159
|
* Implements the StreamingTranscriptionSession contract used by
|
|
156
|
-
* DictationStreamManager.
|
|
160
|
+
* DictationStreamManager. It never emits non-final transcripts: the manager's
|
|
161
|
+
* live `partial` messages are the concatenation of already-committed segments.
|
|
157
162
|
*/
|
|
158
|
-
export class
|
|
163
|
+
export class SherpaSegmentTranscriptionSession extends EventEmitter {
|
|
159
164
|
/**
|
|
160
|
-
* @param {{ engine: SherpaOfflineRecognizerEngine
|
|
165
|
+
* @param {{ engine: SherpaOfflineRecognizerEngine }} params
|
|
161
166
|
*/
|
|
162
|
-
constructor({ engine
|
|
167
|
+
constructor({ engine }) {
|
|
163
168
|
super();
|
|
164
169
|
this.engine = engine;
|
|
165
170
|
this.requiredSampleRate = engine.sampleRate;
|
|
166
|
-
this.minDecodeIntervalMs = minDecodeIntervalMs ?? 350;
|
|
167
171
|
this.connected = false;
|
|
168
172
|
this.currentSegmentId = null;
|
|
169
173
|
this.previousSegmentId = null;
|
|
170
|
-
this.lastPartialText = '';
|
|
171
174
|
this.pcm16 = Buffer.alloc(0);
|
|
172
|
-
this.lastDecodeAt = 0;
|
|
173
|
-
this.decoding = false;
|
|
174
|
-
this.pendingDecode = false;
|
|
175
175
|
}
|
|
176
176
|
|
|
177
177
|
async connect() {
|
|
@@ -184,39 +184,38 @@ export class SherpaRealtimeTranscriptionSession extends EventEmitter {
|
|
|
184
184
|
|
|
185
185
|
appendPcm16(chunk) {
|
|
186
186
|
if (!this.connected || !this.currentSegmentId) {
|
|
187
|
-
this.emit('error', new Error('Sherpa
|
|
187
|
+
this.emit('error', new Error('Sherpa transcription session not connected'));
|
|
188
188
|
return;
|
|
189
189
|
}
|
|
190
190
|
this.pcm16 = this.pcm16.length === 0 ? chunk : Buffer.concat([this.pcm16, chunk]);
|
|
191
|
-
this.maybeDecode(false).catch((err) => {
|
|
192
|
-
this.emit('error', err instanceof Error ? err : new Error(String(err)));
|
|
193
|
-
});
|
|
194
191
|
}
|
|
195
192
|
|
|
196
193
|
commit() {
|
|
197
194
|
if (!this.connected || !this.currentSegmentId) {
|
|
198
|
-
this.emit('error', new Error('Sherpa
|
|
195
|
+
this.emit('error', new Error('Sherpa transcription session not connected'));
|
|
199
196
|
return;
|
|
200
197
|
}
|
|
201
198
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
const finalText = this.lastPartialText;
|
|
206
|
-
const segmentId = this.currentSegmentId;
|
|
207
|
-
const previousSegmentId = this.previousSegmentId;
|
|
199
|
+
const segmentId = this.currentSegmentId;
|
|
200
|
+
const previousSegmentId = this.previousSegmentId;
|
|
201
|
+
const pcm16 = this.pcm16;
|
|
208
202
|
|
|
209
|
-
|
|
210
|
-
|
|
203
|
+
// Start the next segment before decoding: decoding blocks the worker for
|
|
204
|
+
// seconds on long segments, and audio for the next one keeps arriving.
|
|
205
|
+
this.previousSegmentId = segmentId;
|
|
206
|
+
this.currentSegmentId = randomUUID();
|
|
207
|
+
this.pcm16 = Buffer.alloc(0);
|
|
211
208
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
209
|
+
this.emit('committed', { segmentId, previousSegmentId });
|
|
210
|
+
|
|
211
|
+
let transcript;
|
|
212
|
+
try {
|
|
213
|
+
transcript = this.engine.decodePcm16(pcm16);
|
|
214
|
+
} catch (err) {
|
|
215
|
+
this.emit('error', err instanceof Error ? err : new Error(String(err)));
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
this.emit('transcript', { segmentId, transcript, isFinal: true });
|
|
220
219
|
}
|
|
221
220
|
|
|
222
221
|
clear() {
|
|
@@ -225,7 +224,6 @@ export class SherpaRealtimeTranscriptionSession extends EventEmitter {
|
|
|
225
224
|
}
|
|
226
225
|
this.pcm16 = Buffer.alloc(0);
|
|
227
226
|
this.currentSegmentId = randomUUID();
|
|
228
|
-
this.lastPartialText = '';
|
|
229
227
|
}
|
|
230
228
|
|
|
231
229
|
close() {
|
|
@@ -233,45 +231,4 @@ export class SherpaRealtimeTranscriptionSession extends EventEmitter {
|
|
|
233
231
|
this.currentSegmentId = null;
|
|
234
232
|
this.pcm16 = Buffer.alloc(0);
|
|
235
233
|
}
|
|
236
|
-
|
|
237
|
-
async maybeDecode(force) {
|
|
238
|
-
if (!this.connected || !this.currentSegmentId) {
|
|
239
|
-
return;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
const now = Date.now();
|
|
243
|
-
if (!force && now - this.lastDecodeAt < this.minDecodeIntervalMs) {
|
|
244
|
-
return;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
if (this.decoding) {
|
|
248
|
-
this.pendingDecode = true;
|
|
249
|
-
return;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
this.decoding = true;
|
|
253
|
-
try {
|
|
254
|
-
const decodeStartedAt = Date.now();
|
|
255
|
-
const text = this.engine.decodePcm16(this.pcm16);
|
|
256
|
-
this.lastDecodeAt = Date.now();
|
|
257
|
-
// Adaptive throttle: on slow hardware (or heavy models) re-decoding the
|
|
258
|
-
// growing segment every 350ms would monopolize the worker. Space partial
|
|
259
|
-
// decodes to ~1.5x the observed decode time.
|
|
260
|
-
this.minDecodeIntervalMs = Math.max(350, (this.lastDecodeAt - decodeStartedAt) * 1.5);
|
|
261
|
-
if (text !== this.lastPartialText) {
|
|
262
|
-
this.lastPartialText = text;
|
|
263
|
-
this.emit('transcript', {
|
|
264
|
-
segmentId: this.currentSegmentId,
|
|
265
|
-
transcript: text,
|
|
266
|
-
isFinal: false,
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
} finally {
|
|
270
|
-
this.decoding = false;
|
|
271
|
-
if (this.pendingDecode) {
|
|
272
|
-
this.pendingDecode = false;
|
|
273
|
-
await this.maybeDecode(true);
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
234
|
}
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
import {
|
|
19
19
|
SherpaOfflineRecognizerEngine,
|
|
20
|
-
|
|
20
|
+
SherpaSegmentTranscriptionSession,
|
|
21
21
|
} from './sherpa-recognizer.js';
|
|
22
22
|
import { SherpaTtsEngine } from './sherpa-tts.js';
|
|
23
23
|
import { getLocalSttModelDir, getLocalSttModelSpec } from './model-catalog.js';
|
|
@@ -126,7 +126,7 @@ async function handleRequest(message) {
|
|
|
126
126
|
case 'session.create': {
|
|
127
127
|
cleanupSession(message.sessionId);
|
|
128
128
|
const engine = getEngine(message.modelsDir, message.modelId);
|
|
129
|
-
const session = new
|
|
129
|
+
const session = new SherpaSegmentTranscriptionSession({ engine });
|
|
130
130
|
session.on('committed', (payload) => {
|
|
131
131
|
sendToParent({ type: 'session.committed', sessionId: message.sessionId, payload });
|
|
132
132
|
});
|
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
* endpoints (faster-whisper, whisper.cpp, OpenAI, ...).
|
|
4
4
|
*
|
|
5
5
|
* The Whisper HTTP API cannot stream, so audio is buffered per segment and
|
|
6
|
-
* transcribed on commit().
|
|
7
|
-
*
|
|
6
|
+
* transcribed on commit(). This matches how the local session behaves: the
|
|
7
|
+
* DictationStreamManager splits long dictations at pauses, and everything
|
|
8
|
+
* shorter is one request on stop.
|
|
8
9
|
*
|
|
9
10
|
* Implements the StreamingTranscriptionSession contract used by
|
|
10
11
|
* DictationStreamManager.
|