@bojackduy/opencode-voice 0.11.1 → 0.11.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -35
- package/index.js +12 -11
- package/lib/boot.js +4 -4
- package/lib/conversation.js +1 -1
- package/lib/llm-client.js +3 -1
- package/lib/stt.js +20 -11
- package/lib/v2-compat.js +77 -23
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,13 +18,13 @@ One package runs on both OpenCode 1.x and 2.x. The plugin detects the host
|
|
|
18
18
|
by capability (never by version string) and adapts; the v1 path is unchanged.
|
|
19
19
|
|
|
20
20
|
> [!IMPORTANT]
|
|
21
|
-
> **
|
|
22
|
-
>
|
|
23
|
-
>
|
|
24
|
-
>
|
|
25
|
-
>
|
|
26
|
-
>
|
|
27
|
-
>
|
|
21
|
+
> **Dictation inserts; it does not send.** On both v1 and v2 the transcript
|
|
22
|
+
> is typed at the cursor of whichever editable field currently has focus —
|
|
23
|
+
> the session composer, a dialog/search input, or another plugin's text
|
|
24
|
+
> field — leaving the text editable. Nothing is submitted unless you asked
|
|
25
|
+
> for it (`/stt-submit`, `sttAutoSubmit`, or conversation mode). If no
|
|
26
|
+
> editable field is focused, v2 keeps the transcript in a recovery dialog
|
|
27
|
+
> instead of sending it as a prompt.
|
|
28
28
|
|
|
29
29
|
### v1 (OpenCode 1.x)
|
|
30
30
|
|
|
@@ -84,21 +84,25 @@ capability detection already picks the right path per host.
|
|
|
84
84
|
every one reliably; the `Ctrl+P` palette shows them for matching queries
|
|
85
85
|
but its search occasionally reports no results for queries that should
|
|
86
86
|
match — when in doubt, use `/slash`.
|
|
87
|
-
- **STT (batch):**
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
87
|
+
- **STT (batch):** the transcript is typed at the cursor of the focused
|
|
88
|
+
editable field and nothing is sent unless submission is requested.
|
|
89
|
+
On home the composer is focused, so dictation works before a session
|
|
90
|
+
exists; an explicit submit creates the session, carries the selected
|
|
91
|
+
model into it, and sends once. Existing sessions retain their
|
|
92
|
+
agent/model. On home, v2's public plugin API exposes the selected model
|
|
93
|
+
but no selected-agent getter, so session creation uses the host's
|
|
94
|
+
default agent. Create/submit failures show the full transcript in a
|
|
95
|
+
recovery dialog. With no editable field focused, the transcript is kept
|
|
96
|
+
in that dialog instead of being sent as a prompt.
|
|
94
97
|
- **STT (streaming dictation):** enable with `"sttMode": "streaming"` in plugin
|
|
95
98
|
options. Local whisper streaming displays a bounded live transcript above
|
|
96
99
|
the prompt footer on home and session screens. Stable words are plain;
|
|
97
100
|
the tentative tail is bracketed and may change. Press the record key again
|
|
98
|
-
to finalize
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
101
|
+
to finalize: the full text is inserted once at the focused cursor (and
|
|
102
|
+
submitted when `sttAutoSubmit` is set), or cancel to clear the preview
|
|
103
|
+
without sending. Batch remains the default and produces text after
|
|
104
|
+
recording stops; the hosted `sttEndpoint` option is for batch
|
|
105
|
+
transcription, not this local streaming preview.
|
|
102
106
|
- **TTS / conversation / live notes / cancel:** same semantics as v1 (auto
|
|
103
107
|
TTS on idle/permission/question gates, conversation barge-in, live-notes
|
|
104
108
|
background saves, one-key cancel).
|
|
@@ -747,7 +751,7 @@ Idle invocations toast `Nothing to cancel`. Keybind override:
|
|
|
747
751
|
|
|
748
752
|
Live local dictation for short prompts: the mic stays on, partial
|
|
749
753
|
transcriptions stream in as you speak, and one press of `/stt-record`
|
|
750
|
-
finalizes the text
|
|
754
|
+
finalizes the text at the focused cursor on both hosts.
|
|
751
755
|
Set `"sttMode": "streaming"` in the
|
|
752
756
|
plugin options (default `"batch"` keeps the record-then-transcribe flow
|
|
753
757
|
exactly as before).
|
|
@@ -764,18 +768,18 @@ there is never a silent gap — `Loading speech model…` during cold start,
|
|
|
764
768
|
(plus a `(listening…)` note when inference runs slow), and `Finalizing…`
|
|
765
769
|
between the second keypress and finalization. On v2, a bounded transcript
|
|
766
770
|
above the prompt footer updates during recording: stable words are plain,
|
|
767
|
-
tentative words are bracketed. Finalization
|
|
768
|
-
|
|
769
|
-
|
|
771
|
+
tentative words are bracketed. Finalization inserts the full text once at
|
|
772
|
+
the focused cursor; cancel clears the preview without sending.
|
|
773
|
+
The OpenCode renderer only
|
|
770
774
|
exposes `insertText`/`submit`, with no live range-replacement API, so
|
|
771
775
|
partials render as preview toasts (`🎙 ...`) alongside (not instead of)
|
|
772
776
|
the sticky status, and the full text is inserted EXACTLY ONCE at
|
|
773
|
-
finalize. If no editable field is focused, the transcript is kept
|
|
774
|
-
toast instead of being redirected into the chat.
|
|
775
|
-
only through the dictated field's own `submit()` — a
|
|
776
|
-
submit keeps its text un-submitted rather than falling
|
|
777
|
-
primary chat. `/stt-stop` cancels and removes only
|
|
778
|
-
text, never your typed prefix/suffix.
|
|
777
|
+
finalize. If no editable field is focused, the transcript is kept visibly
|
|
778
|
+
(v2 recovery dialog, v1 toast) instead of being redirected into the chat.
|
|
779
|
+
`/stt-submit` submits only through the dictated field's own `submit()` — a
|
|
780
|
+
field that cannot submit keeps its text un-submitted rather than falling
|
|
781
|
+
through to the primary chat. `/stt-stop` cancels and removes only
|
|
782
|
+
plugin-dictated text, never your typed prefix/suffix.
|
|
779
783
|
|
|
780
784
|
Warm server: the whisper model stays loaded across dictations (finalize
|
|
781
785
|
and cancel keep the lease); it reloads only on model/language change,
|
|
@@ -796,9 +800,8 @@ Options:
|
|
|
796
800
|
- `sttMode` _(optional, default `"batch"`)_ - `"streaming"` selects this mode
|
|
797
801
|
- `sttStreamWindowMs` _(optional, default `10000`)_ - rolling audio window
|
|
798
802
|
- `sttStreamStepMs` _(optional, default `1000`)_ - live transcription cadence
|
|
799
|
-
- `sttAutoSubmit` applies after streaming finalize on
|
|
800
|
-
dictated field only, as above).
|
|
801
|
-
is no composer append/edit API.
|
|
803
|
+
- `sttAutoSubmit` applies after streaming finalize on both hosts (submit via
|
|
804
|
+
the dictated field only, as above).
|
|
802
805
|
|
|
803
806
|
Measured latencies (Apple M3 Pro, 36 GB, whisper.cpp 1.9.4 with Metal,
|
|
804
807
|
`ggml-large-v3-turbo-q5_0.bin`, scripted speech through the real
|
|
@@ -839,10 +842,11 @@ real streaming controller in `test/v2-preview.test.js`.
|
|
|
839
842
|
3. LLM normalizes the transcription: fixes punctuation, removes filler words,
|
|
840
843
|
corrects software engineering homophones ("Jason" to "JSON", "bullion" to
|
|
841
844
|
"boolean", etc.)
|
|
842
|
-
4. Cleaned text is
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
845
|
+
4. Cleaned text is inserted at the cursor of the focused editable field
|
|
846
|
+
(composer, search, or plugin input), or submitted immediately when
|
|
847
|
+
`/stt-submit` (or `sttAutoSubmit`) is used. If normalization fails (e.g.
|
|
848
|
+
LLM endpoint unreachable), the raw transcription is used as a fallback
|
|
849
|
+
so you never lose your input
|
|
846
850
|
|
|
847
851
|
### TTS pipeline
|
|
848
852
|
|
package/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// opencode-voice: Speech-to-text and text-to-speech for OpenCode.
|
|
2
2
|
//
|
|
3
3
|
// STT: Record voice via sox, transcribe with whisper-cpp, normalize with
|
|
4
|
-
// an OpenAI-compatible LLM,
|
|
5
|
-
//
|
|
6
|
-
//
|
|
4
|
+
// an OpenAI-compatible LLM, and insert the text at the cursor of the
|
|
5
|
+
// focused input (composer, dialog search, or plugin field) on both
|
|
6
|
+
// hosts. Explicit submits only: /stt-submit, sttAutoSubmit, conversation.
|
|
7
7
|
//
|
|
8
8
|
// TTS: Auto-speak assistant responses (or read on demand) via Piper,
|
|
9
9
|
// with LLM normalization for natural speech.
|
|
@@ -46,7 +46,8 @@ import { adaptV2Context } from "./lib/v2-compat.js";
|
|
|
46
46
|
// Dual-compat export: v1's loader reads `tui`, v2's reads `setup`
|
|
47
47
|
// (`Plugin.define` is an identity wrapper, so a plain object carries both).
|
|
48
48
|
// Each host ignores the other's key. The core (`bootVoice`) is shared; v2
|
|
49
|
-
// runs it over the v2-compat adapted api
|
|
49
|
+
// runs it over the v2-compat adapted api, which forwards the live renderer
|
|
50
|
+
// so dictation lands in whatever input currently has focus.
|
|
50
51
|
export default {
|
|
51
52
|
id: "opencode-voice",
|
|
52
53
|
tui: async (api, options) => {
|
|
@@ -55,16 +56,16 @@ export default {
|
|
|
55
56
|
setup: async (ctx) => {
|
|
56
57
|
const adapted = adaptV2Context(ctx);
|
|
57
58
|
await bootVoice(adapted.api, ctx.options, {
|
|
58
|
-
|
|
59
|
+
v2: true,
|
|
59
60
|
onReady: async ({ logger }) => {
|
|
60
|
-
// First-run
|
|
61
|
-
//
|
|
61
|
+
// First-run v2 notice (required UX disclosure): text is typed into
|
|
62
|
+
// the focused field and is never sent automatically.
|
|
62
63
|
const notice =
|
|
63
|
-
"Voice on OpenCode v2: transcripts
|
|
64
|
-
"(
|
|
65
|
-
"
|
|
64
|
+
"Voice on OpenCode v2: transcripts are inserted at the cursor of the focused text field " +
|
|
65
|
+
"(prompt, search, or dialog input) and are not sent automatically. " +
|
|
66
|
+
"Set sttAutoSubmit to submit after recording.";
|
|
66
67
|
adapted.api.ui.toast({ message: notice, variant: "warning", duration: 8000 });
|
|
67
|
-
logger?.log?.("plugin", `v2
|
|
68
|
+
logger?.log?.("plugin", `v2 focused-input mode: ${notice}`, "warn");
|
|
68
69
|
// v2 has no client.app.log, so the logger above is a no-op: compat
|
|
69
70
|
// warnings must surface as a toast or they are lost entirely.
|
|
70
71
|
if (adapted.warnMessages.length > 0) {
|
package/lib/boot.js
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
// an `api` object (raw v1 `TuiPluginApi` vs the v2-compat adapted `Context`).
|
|
5
5
|
// Everything below runs identically on both, so there is exactly one core to
|
|
6
6
|
// maintain. The v1 `tui` path calls `bootVoice(api, options)` with no extras
|
|
7
|
-
// and behaves exactly as before; the v2 `setup` path passes
|
|
8
|
-
//
|
|
9
|
-
//
|
|
7
|
+
// and behaves exactly as before; the v2 `setup` path passes `{ v2: true }`
|
|
8
|
+
// for the first-run notice. No STT/TTS/routing/keybind behavior branches
|
|
9
|
+
// live here.
|
|
10
10
|
|
|
11
11
|
import fs from "node:fs";
|
|
12
12
|
import os from "node:os";
|
|
@@ -98,7 +98,7 @@ export async function bootVoice(api, options, extras = {}) {
|
|
|
98
98
|
...cancel.commands,
|
|
99
99
|
]);
|
|
100
100
|
|
|
101
|
-
if (extras?.
|
|
101
|
+
if (extras?.v2 && typeof extras?.onReady === "function") {
|
|
102
102
|
await extras.onReady({ logger, stt, tts, conversation, liveNotes, voiceModel, cancel });
|
|
103
103
|
}
|
|
104
104
|
|
package/lib/conversation.js
CHANGED
|
@@ -373,7 +373,7 @@ export function registerConversation(api, opts, logger, { stt, tts, isLiveNotesA
|
|
|
373
373
|
// v2 prompt dispatch may emit the entire reply before its promise returns.
|
|
374
374
|
// Home creation navigates before prompting, so resolve the ID at event time.
|
|
375
375
|
let earlyWait = null;
|
|
376
|
-
if (api.client?.tui?.
|
|
376
|
+
if (api.client?.tui?.v2) {
|
|
377
377
|
phase = "waiting";
|
|
378
378
|
startReplyStream(currentSessionID, turnStart);
|
|
379
379
|
earlyWait = waitForReply(currentSessionID);
|
package/lib/llm-client.js
CHANGED
|
@@ -102,7 +102,9 @@ export function resolveProviderConfig(provider, model) {
|
|
|
102
102
|
const exported = envVars.find((name) => name && process.env[name]);
|
|
103
103
|
return {
|
|
104
104
|
endpoint,
|
|
105
|
-
model
|
|
105
|
+
// v2 keeps the upstream provider's model id in `modelID` (`id` is the
|
|
106
|
+
// selection id and can differ for configured aliases), so prefer it.
|
|
107
|
+
model: model.modelID ?? model.id,
|
|
106
108
|
apiKeyEnv: exported || envVars[0] || null,
|
|
107
109
|
};
|
|
108
110
|
}
|
package/lib/stt.js
CHANGED
|
@@ -1376,9 +1376,11 @@ async function appendTranscription(client, renderer, text, submit, isCurrent) {
|
|
|
1376
1376
|
return true;
|
|
1377
1377
|
}
|
|
1378
1378
|
|
|
1379
|
-
// Only the
|
|
1380
|
-
//
|
|
1381
|
-
|
|
1379
|
+
// Only the v2 adapter consumes this fence; v1 request bodies remain
|
|
1380
|
+
// unchanged. Re-check after an asynchronous home session create. The
|
|
1381
|
+
// `submit` flag lets the adapter distinguish an explicit submit from a
|
|
1382
|
+
// plain append with no editable field focused (append must not send).
|
|
1383
|
+
const fence = client.tui?.v2 ? { isCurrent, submit } : {};
|
|
1382
1384
|
let appendResult = await client.tui.appendPrompt({ body: { text }, ...fence });
|
|
1383
1385
|
|
|
1384
1386
|
if (appendResult?.error?.data?.message === "Expected object, got undefined") {
|
|
@@ -1391,7 +1393,9 @@ async function appendTranscription(client, renderer, text, submit, isCurrent) {
|
|
|
1391
1393
|
);
|
|
1392
1394
|
}
|
|
1393
1395
|
|
|
1394
|
-
if (
|
|
1396
|
+
if (appendResult?.retained) return appendResult;
|
|
1397
|
+
|
|
1398
|
+
if (submit && !appendResult?.submitted) {
|
|
1395
1399
|
await client.tui.submitPrompt();
|
|
1396
1400
|
}
|
|
1397
1401
|
return appendResult;
|
|
@@ -1515,15 +1519,15 @@ async function appendTurnText(client, renderer, toast, text, logger) {
|
|
|
1515
1519
|
);
|
|
1516
1520
|
clearProcessingToast();
|
|
1517
1521
|
logger?.log("STT", `Turn appended chars=${text.length}`, "debug");
|
|
1518
|
-
//
|
|
1519
|
-
//
|
|
1520
|
-
// the text was "added to prompt" for editing there. v1 results carry no
|
|
1522
|
+
// The v2 adapter retains the transcript when no editable field has
|
|
1523
|
+
// focus — it never sends an unrequested prompt. v1 results carry no
|
|
1521
1524
|
// marker and keep the original toast.
|
|
1525
|
+
const retained = appendResult?.retained === true;
|
|
1522
1526
|
toast(
|
|
1523
|
-
|
|
1524
|
-
? "
|
|
1527
|
+
retained
|
|
1528
|
+
? "No text field focused - transcription kept (not sent)"
|
|
1525
1529
|
: "Transcription added to prompt",
|
|
1526
|
-
"success",
|
|
1530
|
+
retained ? "warning" : "success",
|
|
1527
1531
|
);
|
|
1528
1532
|
return { text };
|
|
1529
1533
|
} catch (err) {
|
|
@@ -2136,7 +2140,12 @@ export function registerSTT(api, kv, complete, prompts, opts, logger, deps = {})
|
|
|
2136
2140
|
cancel: () => cancelRecording(logger),
|
|
2137
2141
|
discard: () => discardTurn(),
|
|
2138
2142
|
transcribeTurn: () => transcribeTurn(kv, complete, client, api, toast, systemPrompt, logger),
|
|
2139
|
-
|
|
2143
|
+
// Conversation turns are hands-free submissions, not dictation: on v2
|
|
2144
|
+
// they must not press Enter in whatever field happens to have focus (a
|
|
2145
|
+
// permission dialog could own it), so they always go through the
|
|
2146
|
+
// session.prompt submit path. v1 keeps its focused-insert + submit.
|
|
2147
|
+
submitTurnText: (text) =>
|
|
2148
|
+
submitTurnText(client, client.tui?.v2 ? null : renderer, toast, text, logger),
|
|
2140
2149
|
startStreaming: startStreamingDictation,
|
|
2141
2150
|
finalizeStreaming: finalizeStreamingDictation,
|
|
2142
2151
|
cancelStreaming: cancelStreamingDictation,
|
package/lib/v2-compat.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createV2Preview } from "./v2-preview.js";
|
|
2
2
|
|
|
3
|
-
// OpenCode v2 compatibility shim
|
|
3
|
+
// OpenCode v2 compatibility shim.
|
|
4
4
|
//
|
|
5
5
|
// WHY this file exists: v2's TUI plugin `Context` renamed or replaced every
|
|
6
6
|
// v1 `TuiPluginApi` surface this plugin uses (see the drift table in the
|
|
@@ -10,12 +10,15 @@ import { createV2Preview } from "./v2-preview.js";
|
|
|
10
10
|
// presence, never version strings), and every surface with no v2 path
|
|
11
11
|
// degrades loudly (warn log + honest toast), never silently.
|
|
12
12
|
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
//
|
|
17
|
-
//
|
|
18
|
-
//
|
|
13
|
+
// Composer editing on v2: there is no plugin-reachable append-to-composer
|
|
14
|
+
// call (`tui.prompt.append` exists only as a server→TUI event type, not a
|
|
15
|
+
// client method), but `Context.renderer` IS the live `CliRenderer`. So the
|
|
16
|
+
// adapted api forwards it, and the shared `insertIntoFocusedInput` helper
|
|
17
|
+
// types at the cursor of whatever editable field currently has focus — the
|
|
18
|
+
// session composer, a dialog search box, or another plugin's input. Only an
|
|
19
|
+
// explicit submit (`/stt-submit`, `sttAutoSubmit`, conversation) presses
|
|
20
|
+
// Enter. With no editable field focused, text is retained in a recovery
|
|
21
|
+
// dialog instead of being sent as a prompt.
|
|
19
22
|
|
|
20
23
|
// Event renames with no same-named v2 equivalent. Values are the v2 event
|
|
21
24
|
// type to subscribe to instead (both verified present in the v2
|
|
@@ -301,6 +304,20 @@ export function adaptV2Context(ctx) {
|
|
|
301
304
|
return task;
|
|
302
305
|
}
|
|
303
306
|
|
|
307
|
+
// Reached only when no focused renderable accepts text. Never redirect the
|
|
308
|
+
// transcript into a chat prompt the user did not ask for: keep it visible
|
|
309
|
+
// in a recovery dialog and let the caller report `retained`.
|
|
310
|
+
function retainTranscript(text) {
|
|
311
|
+
const captured = String(text || "");
|
|
312
|
+
try {
|
|
313
|
+
void ctx.ui.dialog.alert({
|
|
314
|
+
title: "Voice transcript — no text field focused",
|
|
315
|
+
message: captured,
|
|
316
|
+
});
|
|
317
|
+
} catch {}
|
|
318
|
+
return { data: null, retained: true };
|
|
319
|
+
}
|
|
320
|
+
|
|
304
321
|
// `Object.create` (not spread) so client methods keep their `this`.
|
|
305
322
|
// v2 `session.message` is a `{get}` namespace, not the v1 callable, so
|
|
306
323
|
// the v1 call shape `client.session.message({sessionID, messageID})` is
|
|
@@ -323,14 +340,21 @@ export function adaptV2Context(ctx) {
|
|
|
323
340
|
app: { value: { log: async () => {} } },
|
|
324
341
|
tui: {
|
|
325
342
|
value: {
|
|
326
|
-
|
|
327
|
-
//
|
|
328
|
-
//
|
|
329
|
-
|
|
330
|
-
//
|
|
343
|
+
// Marker for v1-shaped callers: this host has no composer-append API
|
|
344
|
+
// and dispatches prompts through `session.prompt` below (an explicit
|
|
345
|
+
// submit may resolve after the reply stream has started).
|
|
346
|
+
v2: true,
|
|
347
|
+
// Called only after `insertIntoFocusedInput` found no editable field.
|
|
348
|
+
// Accepts both v1 call shapes ({body:{text}} and {text}) used by
|
|
349
|
+
// stt.js. Explicit submits still go out via `session.prompt`; plain
|
|
350
|
+
// appends are retained visibly instead of being sent.
|
|
331
351
|
appendPrompt: async (input) => {
|
|
332
|
-
|
|
333
|
-
|
|
352
|
+
const text = input?.body?.text ?? input?.text ?? "";
|
|
353
|
+
if (input?.submit === true) {
|
|
354
|
+
await submitTextAsPrompt(text, input?.isCurrent);
|
|
355
|
+
return { data: null, submitted: true };
|
|
356
|
+
}
|
|
357
|
+
return retainTranscript(text);
|
|
334
358
|
},
|
|
335
359
|
submitPrompt: async () => {},
|
|
336
360
|
},
|
|
@@ -341,11 +365,11 @@ export function adaptV2Context(ctx) {
|
|
|
341
365
|
|
|
342
366
|
const api = {
|
|
343
367
|
client,
|
|
344
|
-
//
|
|
345
|
-
//
|
|
346
|
-
//
|
|
368
|
+
// The live CliRenderer: `currentFocusedRenderable` lets the shared
|
|
369
|
+
// `insertIntoFocusedInput` helper type into the focused composer, dialog
|
|
370
|
+
// search box, or plugin input. Streaming display is separate:
|
|
347
371
|
// voicePreview uses additive slots without composer editing.
|
|
348
|
-
renderer: null,
|
|
372
|
+
renderer: ctx.renderer ?? null,
|
|
349
373
|
voicePreview: preview,
|
|
350
374
|
ui: { toast, dialog, DialogSelect },
|
|
351
375
|
event: {
|
|
@@ -527,13 +551,44 @@ export function adaptV2Context(ctx) {
|
|
|
527
551
|
},
|
|
528
552
|
};
|
|
529
553
|
|
|
530
|
-
// v1 reads `api.state.provider` as an array
|
|
531
|
-
//
|
|
532
|
-
//
|
|
554
|
+
// v1 reads `api.state.provider` as an array of `{models, env, options}`
|
|
555
|
+
// (`voice-model.js` / `llm-client.js`). v2 splits those across collections:
|
|
556
|
+
// providers carry NO models (they live in `location.model`), auth env names
|
|
557
|
+
// live on the provider's integration method `{type:"env", names}`, and the
|
|
558
|
+
// endpoint is `settings.baseURL` (`options` in v1). Recombining them here is
|
|
559
|
+
// what keeps /voice-model from seeing every provider as model-less.
|
|
533
560
|
Object.defineProperty(api.state, "provider", {
|
|
534
561
|
get() {
|
|
535
562
|
try {
|
|
536
|
-
|
|
563
|
+
const providers = ctx.data.location.provider.list() || [];
|
|
564
|
+
const models = ctx.data.location.model?.list?.() || [];
|
|
565
|
+
const integrations = ctx.data.location.integration?.list?.() || [];
|
|
566
|
+
const envByIntegration = new Map();
|
|
567
|
+
for (const integration of integrations) {
|
|
568
|
+
const names = (integration?.methods || [])
|
|
569
|
+
.filter((method) => method?.type === "env")
|
|
570
|
+
.flatMap((method) => method?.names || []);
|
|
571
|
+
if (names.length > 0) envByIntegration.set(integration.id, names);
|
|
572
|
+
}
|
|
573
|
+
const modelsByProvider = new Map();
|
|
574
|
+
for (const model of models) {
|
|
575
|
+
const providerID = model?.providerID;
|
|
576
|
+
if (!providerID) continue;
|
|
577
|
+
const list = modelsByProvider.get(providerID);
|
|
578
|
+
if (list) list.push(model);
|
|
579
|
+
else modelsByProvider.set(providerID, [model]);
|
|
580
|
+
}
|
|
581
|
+
return providers.map((provider) => {
|
|
582
|
+
const own = modelsByProvider.get(provider.id) || [];
|
|
583
|
+
return {
|
|
584
|
+
...provider,
|
|
585
|
+
models: Object.fromEntries(own.map((model) => [model.id, model])),
|
|
586
|
+
env:
|
|
587
|
+
envByIntegration.get(provider.integrationID ?? provider.id) ??
|
|
588
|
+
(Array.isArray(provider.env) ? provider.env : []),
|
|
589
|
+
options: provider.settings || {},
|
|
590
|
+
};
|
|
591
|
+
});
|
|
537
592
|
} catch {
|
|
538
593
|
return [];
|
|
539
594
|
}
|
|
@@ -554,7 +609,6 @@ export function adaptV2Context(ctx) {
|
|
|
554
609
|
return {
|
|
555
610
|
api,
|
|
556
611
|
cleanup,
|
|
557
|
-
submitOnly: true,
|
|
558
612
|
warnMessages,
|
|
559
613
|
onWarn: (sink) => void (warnSink = sink),
|
|
560
614
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bojackduy/opencode-voice",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.2",
|
|
4
4
|
"description": "Speech-to-text and text-to-speech for OpenCode. Record voice prompts with whisper-cpp, hear responses via Piper TTS, with LLM normalization through any OpenAI-compatible endpoint.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"opencode",
|