@ds-hu/dsh-bvi-local 0.0.0-stage → 0.2.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 the dsh-better-voice-input authors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/NOTICE ADDED
@@ -0,0 +1,31 @@
1
+ dsh-better-voice-input
2
+ Copyright (c) 2026 the dsh-better-voice-input authors
3
+
4
+ The `icon.svg` and `docs/preview*.svg` artwork is original to this project and is
5
+ distributed under the same MIT license as the rest of the package.
6
+
7
+ This project is a plugin for DeepSeek Harness and extends the official
8
+ experimental voice input bundle. The DeepSeek Harness packages it integrates
9
+ with are licensed under the MIT License:
10
+ https://github.com/deepseek-ai/deepseek-harness
11
+
12
+ The local-model runtime uses sherpa-onnx through the `sherpa-onnx-node` npm
13
+ package. sherpa-onnx is Copyright (c) 2023-2026 k2-fsa and is licensed under the
14
+ Apache License, Version 2.0:
15
+ https://github.com/k2-fsa/sherpa-onnx
16
+
17
+ Local speech models are downloaded by the user's explicit request from the
18
+ upstream sherpa-onnx model releases on Hugging Face, not redistributed in this
19
+ package. Each model keeps its own license and attribution, which the settings
20
+ page links to:
21
+ https://huggingface.co/csukuangfj
22
+
23
+ The provider/model list follows BryceWG/BiBi-Keyboard ("说点啥"), an Android
24
+ voice-input project licensed under the Apache License, Version 2.0. Only its
25
+ public model/provider list and public vendor API facts were used as a reference;
26
+ no Android implementation or user-interface code was copied:
27
+ https://github.com/BryceWG/BiBi-Keyboard
28
+
29
+ Cloud providers are implemented against each vendor's public HTTP API; their
30
+ names and trademarks belong to their owners. No endorsement by any vendor is
31
+ implied.
package/icon.svg ADDED
@@ -0,0 +1,14 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="36" height="36" viewBox="0 0 36 36">
2
+ <rect x="8" y="8" width="20" height="20" rx="4" fill="none" stroke="#3b82f6" stroke-width="2.2"/>
3
+ <g fill="none" stroke="#3b82f6" stroke-linecap="round" stroke-width="2">
4
+ <path d="M14 19.5v2"/>
5
+ <path d="M18 15.5v10"/>
6
+ <path d="M22 17.5v6"/>
7
+ </g>
8
+ <g fill="#3b82f6">
9
+ <rect x="6" y="12" width="4" height="2" rx="1"/>
10
+ <rect x="6" y="22" width="4" height="2" rx="1"/>
11
+ <rect x="26" y="12" width="4" height="2" rx="1"/>
12
+ <rect x="26" y="22" width="4" height="2" rx="1"/>
13
+ </g>
14
+ </svg>
package/lib/index.js ADDED
@@ -0,0 +1,112 @@
1
+ /**
2
+ * `bvi-local` — the local half of "more speech models".
3
+ *
4
+ * Registers one official `ctx.speechToText` provider per local sherpa-onnx family (7 in total)
5
+ * when the row is active. The row declares `speechToText` as a hard injection, so it stays
6
+ * inactive while the official experimental speech-to-text row is disabled — Cordis handles that,
7
+ * the plugin must not swallow registration errors.
8
+ *
9
+ * Model files live under the row's `dataRoot` (cordis.patch.yml points it at
10
+ * `<DSH_HOME>/better-voice-input/models`). The selected variant is normally passed by the service
11
+ * as `prepare({ variant })`; as a fallback the provider reads the bundle configuration document
12
+ * (`<DSH_HOME>/better-voice-input/config.json`, the service row's default data root) so a
13
+ * non-default variant also works when the provider is driven directly.
14
+ *
15
+ * @module @ds-hu/dsh-bvi-local
16
+ */
17
+ import { readConfig, resolveDataRoot } from '@ds-hu/dsh-bvi-core'
18
+ import { LOCAL_MODELS } from '@ds-hu/dsh-bvi-core/catalog/local.js'
19
+
20
+ import { createLocalProvider } from './provider.js'
21
+
22
+ export const name = 'bvi-local'
23
+ export const inject = ['speechToText']
24
+
25
+ /**
26
+ * @param {any} ctx cordis context of the row.
27
+ * @returns {((...segments: string[]) => string)|undefined} the `dshHomePath` helper when available.
28
+ */
29
+ function dshHomePathOf(ctx) {
30
+ const helper = typeof ctx.get === 'function' ? ctx.get('dshHomePath') : undefined
31
+ return typeof helper === 'function' ? helper : undefined
32
+ }
33
+
34
+ /**
35
+ * Resolve the absolute model directory.
36
+ *
37
+ * `config.dataRoot` wins (the patch supplies `<DSH_HOME>/better-voice-input/models`); otherwise the
38
+ * runtime `dshHomePath` service is the authoritative source. A guessed home directory is never
39
+ * used, because the host process does not necessarily export `DSH_HOME`.
40
+ * @param {any} ctx cordis context of the row.
41
+ * @param {{ dataRoot?: string } | undefined} config row config.
42
+ * @returns {string} absolute model root.
43
+ * @throws {Error} when neither the row config nor `dshHomePath` provides a directory.
44
+ */
45
+ function resolveModelsRoot(ctx, config) {
46
+ if (typeof config?.dataRoot === 'string' && config.dataRoot.trim() !== '') return resolveDataRoot(config.dataRoot)
47
+ const dshHomePath = dshHomePathOf(ctx)
48
+ if (dshHomePath === undefined) {
49
+ throw new Error('bvi-local: cannot resolve the model directory (set the row dataRoot or provide the dshHomePath service)')
50
+ }
51
+ return resolveDataRoot(dshHomePath('better-voice-input', 'models'))
52
+ }
53
+
54
+ /**
55
+ * Resolve the bundle state directory that holds `config.json` (the service row's default root).
56
+ * @param {any} ctx cordis context of the row.
57
+ * @returns {string|undefined} absolute state root, or undefined when only a custom model root exists.
58
+ */
59
+ function resolveStateRoot(ctx) {
60
+ const dshHomePath = dshHomePathOf(ctx)
61
+ if (dshHomePath === undefined) return undefined
62
+ try {
63
+ return resolveDataRoot(dshHomePath('better-voice-input'))
64
+ } catch {
65
+ return undefined
66
+ }
67
+ }
68
+
69
+ /**
70
+ * Register the seven local providers into the official speech registry.
71
+ *
72
+ * Registration comes first and cleanup last (unregister → dispose provider → await removal), the
73
+ * order the official seam documents. Every provider owns its worker process; unloading the row
74
+ * aborts an in-flight download and stops every worker.
75
+ * @param {any} ctx cordis context of the row.
76
+ * @param {{ dataRoot?: string } | undefined} config row config from cordis.patch.yml.
77
+ * @returns {void}
78
+ */
79
+ export function apply(ctx, config) {
80
+ const logger = typeof ctx.logger === 'function' ? ctx.logger('bvi-local') : undefined
81
+ const dataRoot = resolveModelsRoot(ctx, config)
82
+ const stateRoot = resolveStateRoot(ctx)
83
+ /**
84
+ * @param {string} message - diagnostic text.
85
+ * @returns {void}
86
+ */
87
+ const log = (message) => { logger?.debug?.(message) }
88
+ /**
89
+ * Read the variant selected in the bundle configuration document. The service normally passes it
90
+ * through `prepare({ variant })`; this fallback keeps direct provider use working.
91
+ * @param {string} providerId - local provider id.
92
+ * @returns {Promise<string|undefined>} configured variant id, when one is saved.
93
+ */
94
+ const readSelectedVariant = async (providerId) => {
95
+ if (stateRoot === undefined) return undefined
96
+ const document = await readConfig(stateRoot)
97
+ const variant = document.local?.[providerId]?.variant
98
+ return typeof variant === 'string' && variant !== '' ? variant : undefined
99
+ }
100
+
101
+ for (const model of LOCAL_MODELS) {
102
+ ctx.effect(() => {
103
+ const provider = createLocalProvider({ model, dataRoot, readSelectedVariant, logger: log })
104
+ const unregister = ctx.speechToText.register(provider)
105
+ return async () => {
106
+ const removing = unregister()
107
+ await provider.dispose()
108
+ await removing
109
+ }
110
+ })
111
+ }
112
+ }