-
Notifications
You must be signed in to change notification settings - Fork 3.2k
feat(vscode): prewarm microphone capture before showing voice input as recording #12001
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6ad16cd
feat(vscode): prewarm microphone capture before showing voice input a…
marius-kilocode ce8fa36
Merge remote-tracking branch 'origin/main' into obtainable-olive
marius-kilocode 2235212
style(vscode): format speech-to-text prewarm test
marius-kilocode 13f00fc
fix(vscode): address speech-to-text review findings
marius-kilocode File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "kilo-code": patch | ||
| --- | ||
|
|
||
| Wait for microphone capture to start before showing voice input as recording. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
packages/kilo-vscode/tests/unit/speech-to-text-prewarm.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| import { describe, expect, it } from "bun:test" | ||
| import path from "node:path" | ||
|
|
||
| // Run from webview-ui so the child transpiles JSX with solid-js (its tsconfig sets | ||
| // jsxImportSource: solid-js). The package root tsconfig has no jsx setting, which makes | ||
| // bun fall back to react/jsx-dev-runtime and fail whenever react isn't hoisted nearby. | ||
| const WEBVIEW = path.resolve(import.meta.dir, "../../webview-ui") | ||
|
|
||
| // solid-js effects only run under the browser export condition, so the component has to be | ||
| // exercised in a child process resolved with `--conditions=browser`. The child prints an | ||
| // explicit PASS/FAIL sentinel: a FAIL means the prewarm logic is wrong (fail immediately), | ||
| // while any other non-zero exit is a transient spawn failure under load and is retried so | ||
| // the suite stays deterministic. | ||
| const PASS = "PREWARM_PASS" | ||
| const FAIL = "PREWARM_FAIL:" | ||
|
|
||
| const SCRIPT = ` | ||
| import { Window } from "happy-dom" | ||
|
|
||
| const window = new Window() | ||
| globalThis.window = window | ||
| globalThis.document = window.document | ||
| globalThis.Node = window.Node | ||
|
|
||
| const sent = [] | ||
| globalThis.acquireVsCodeApi = () => ({ | ||
| postMessage: (message) => sent.push(message), | ||
| getState: () => undefined, | ||
| setState: () => {}, | ||
| }) | ||
|
|
||
| const { createComponent, createSignal } = await import("solid-js") | ||
| const { render } = await import("solid-js/web") | ||
| const { ConfigContext } = await import("./src/context/config.tsx") | ||
| const { ProviderContext } = await import("./src/context/provider.tsx") | ||
| const { SpeechToTextPrewarm } = await import( | ||
| "./src/components/speech-to-text/SpeechToTextPrewarm.tsx" | ||
| ) | ||
|
|
||
| const fail = (reason) => { | ||
| console.log("${FAIL}" + reason) | ||
| process.exit(2) | ||
| } | ||
|
|
||
| const [config, setConfig] = createSignal({ disabled_providers: ["kilo"] }) | ||
| const [auth, setAuth] = createSignal({}) | ||
| const root = document.createElement("div") | ||
| const dispose = render( | ||
| () => | ||
| createComponent(ProviderContext.Provider, { | ||
| value: { authStates: auth }, | ||
| get children() { | ||
| return createComponent(ConfigContext.Provider, { | ||
| value: { config }, | ||
| get children() { | ||
| return createComponent(SpeechToTextPrewarm, {}) | ||
| }, | ||
| }) | ||
| }, | ||
| }), | ||
| root, | ||
| ) | ||
|
|
||
| if (sent.length !== 0) fail("prewarmed without Kilo access") | ||
| setAuth({ kilo: "api" }) | ||
| if (sent.length !== 0) fail("prewarmed while Kilo was disabled") | ||
| setConfig({}) | ||
| if (sent.length !== 1 || sent[0]?.type !== "speechToTextPrewarm") { | ||
| fail("did not prewarm after Kilo access became available") | ||
| } | ||
| setAuth({ kilo: "oauth" }) | ||
| if (sent.length !== 1) fail("prewarmed more than once") | ||
| dispose() | ||
| console.log("${PASS}") | ||
| ` | ||
|
|
||
| describe("speech-to-text prewarm", () => { | ||
| it("starts only after Kilo speech access becomes available", () => { | ||
| const attempts = 3 | ||
| const failures: string[] = [] | ||
|
|
||
| for (let attempt = 1; attempt <= attempts; attempt++) { | ||
|
marius-kilocode marked this conversation as resolved.
|
||
| const result = Bun.spawnSync(["bun", "--conditions=browser", "-e", SCRIPT], { | ||
| cwd: WEBVIEW, | ||
| stdout: "pipe", | ||
| stderr: "pipe", | ||
| }) | ||
| const output = result.stdout.toString() + result.stderr.toString() | ||
|
|
||
| if (output.includes(PASS)) return | ||
|
|
||
| const logic = output.indexOf(FAIL) | ||
| // A FAIL sentinel is a real assertion failure in the prewarm logic — surface it now. | ||
| if (logic !== -1) { | ||
| expect.unreachable( | ||
| output | ||
| .slice(logic + FAIL.length) | ||
| .split("\n")[0] | ||
| ?.trim(), | ||
| ) | ||
| } | ||
|
|
||
| // Otherwise the child died before it could run (starved/transient spawn) — retry. | ||
| failures.push(`attempt ${attempt} exit ${result.exitCode}: ${output.trim() || "<no output>"}`) | ||
| } | ||
|
|
||
| expect.unreachable(`prewarm child never reported success:\n${failures.join("\n")}`) | ||
| }) | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
packages/kilo-vscode/webview-ui/src/components/speech-to-text/SpeechToTextPrewarm.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { createEffect, type Component } from "solid-js" | ||
| import { useConfig } from "../../context/config" | ||
| import { useProvider } from "../../context/provider" | ||
| import { getVSCodeAPI } from "../../context/vscode" | ||
| import { canUseSpeechToText } from "./availability" | ||
|
|
||
| export const SpeechToTextPrewarm: Component = () => { | ||
| const vscode = getVSCodeAPI() | ||
| const provider = useProvider() | ||
| const { config } = useConfig() | ||
| let prepared = false | ||
|
|
||
| createEffect(() => { | ||
| if (prepared || !canUseSpeechToText(config(), provider.authStates())) return | ||
| prepared = true | ||
| vscode.postMessage({ type: "speechToTextPrewarm" }) | ||
| }) | ||
|
|
||
| return null | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.