@hxnnxs/opencode-voice 0.2.3 → 0.2.4
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/CHANGELOG.md +7 -0
- package/PUBLISHING.md +2 -2
- package/README.md +17 -9
- package/bin/opencode-voice.js +17 -4
- package/docs/README.es.md +3 -3
- package/docs/README.ru.md +10 -6
- package/docs/README.zh.md +3 -3
- package/index.js +231 -174
- package/lib/engine.js +141 -70
- package/lib/engines.js +14 -8
- package/lib/handy-model-catalog.js +79 -1
- package/lib/wav.js +23 -2
- package/package.json +9 -4
- package/tui.js +108 -0
package/tui.js
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import legacyPlugin, { setupVoice } from "./index.js";
|
|
5
|
+
|
|
6
|
+
function legacySettings() {
|
|
7
|
+
try {
|
|
8
|
+
const state = process.env.XDG_STATE_HOME || path.join(os.homedir(), ".local", "state");
|
|
9
|
+
const kv = JSON.parse(fs.readFileSync(path.join(state, "opencode", "kv.json"), "utf8"));
|
|
10
|
+
return Object.fromEntries(Object.entries(kv).filter(([key]) => key.startsWith("voice.")));
|
|
11
|
+
} catch {
|
|
12
|
+
return {};
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Translate the shared dialog callbacks to V2's promise-based dialogs.
|
|
17
|
+
export function createApi(context) {
|
|
18
|
+
const [settings, update] = context.storage.store("settings", { initial: legacySettings() });
|
|
19
|
+
const dialog = context.ui.dialog;
|
|
20
|
+
let size = "medium";
|
|
21
|
+
let revision = 0;
|
|
22
|
+
let disposed = false;
|
|
23
|
+
const report = (error) => context.ui.toast.show({ title: "Voice", message: String(error), variant: "error" });
|
|
24
|
+
|
|
25
|
+
function present(result, callback) {
|
|
26
|
+
const current = revision;
|
|
27
|
+
void result.then((value) => {
|
|
28
|
+
if (!disposed && current === revision) return callback?.(value);
|
|
29
|
+
}).catch(report);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return {
|
|
33
|
+
kv: {
|
|
34
|
+
get: (key, fallback) => settings[key] ?? fallback,
|
|
35
|
+
set: (key, value) => update((draft) => { draft[key] = value; }),
|
|
36
|
+
},
|
|
37
|
+
ui: {
|
|
38
|
+
toast: (options) => { if (!disposed) context.ui.toast.show(options); },
|
|
39
|
+
dialog: {
|
|
40
|
+
setSize(value) { size = value; },
|
|
41
|
+
replace(render) {
|
|
42
|
+
if (disposed) return;
|
|
43
|
+
revision++;
|
|
44
|
+
render();
|
|
45
|
+
dialog.set({ size });
|
|
46
|
+
},
|
|
47
|
+
clear() {
|
|
48
|
+
if (disposed) return;
|
|
49
|
+
revision++;
|
|
50
|
+
dialog.clear();
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
DialogAlert({ onConfirm, ...options }) {
|
|
54
|
+
present(dialog.alert(options), onConfirm);
|
|
55
|
+
},
|
|
56
|
+
DialogSelect({ onSelect, footer, options, ...input }) {
|
|
57
|
+
present(dialog.select({
|
|
58
|
+
...input,
|
|
59
|
+
options: options.map(({ value, title, description, details, category, disabled }) => ({
|
|
60
|
+
value, title, description: description || details?.join(" · "), category, disabled, footer,
|
|
61
|
+
})),
|
|
62
|
+
}), (value) => {
|
|
63
|
+
if (value !== undefined) return onSelect({ value });
|
|
64
|
+
});
|
|
65
|
+
},
|
|
66
|
+
DialogPrompt({ onConfirm, onCancel, ...options }) {
|
|
67
|
+
present(dialog.prompt(options), (value) => value === undefined ? onCancel?.() : onConfirm(value));
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
client: {
|
|
71
|
+
tui: {
|
|
72
|
+
appendPrompt({ text }) {
|
|
73
|
+
// V2 no longer exposes client.tui. Use the focused prompt editor and
|
|
74
|
+
// its normal content-change handler, leaving existing draft text intact.
|
|
75
|
+
const input = context.renderer.currentFocusedRenderable;
|
|
76
|
+
const route = context.ui.router.current();
|
|
77
|
+
const canSubmit = context.keymap.commands().some((command) => command.id === "prompt.submit");
|
|
78
|
+
if (disposed || !["home", "session"].includes(route.type) ||
|
|
79
|
+
context.keymap.mode.current() !== "base" || !canSubmit ||
|
|
80
|
+
!input?.focused || input.isDestroyed || typeof input.insertText !== "function" ||
|
|
81
|
+
typeof input.gotoBufferEnd !== "function") {
|
|
82
|
+
throw new Error("Focus the OpenCode prompt before inserting the transcription.");
|
|
83
|
+
}
|
|
84
|
+
input.gotoBufferEnd();
|
|
85
|
+
input.insertText(text);
|
|
86
|
+
context.renderer.requestRender();
|
|
87
|
+
},
|
|
88
|
+
submitPrompt() {
|
|
89
|
+
if (!disposed) context.keymap.dispatch("prompt.submit");
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
dispose() {
|
|
94
|
+
disposed = true;
|
|
95
|
+
revision++;
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Plugin.define is an identity helper in V2. Exporting its definition shape
|
|
101
|
+
// directly also lets V1 load this entrypoint without importing the V2 SDK.
|
|
102
|
+
export default {
|
|
103
|
+
id: legacyPlugin.id,
|
|
104
|
+
tui: legacyPlugin.tui,
|
|
105
|
+
setup(context) {
|
|
106
|
+
return setupVoice(createApi(context), context.options || {}, context);
|
|
107
|
+
},
|
|
108
|
+
};
|