1fdeda904b
* feat: add voice mode for chat input Adds a voice input button to the chat composer with three transcription engines: in-browser Web Speech API, in-browser Whisper via @huggingface/transformers, and a server-side OpenAI Whisper fallback gated on KANDEV_VOICE_OPENAI_API_KEY. User-configurable from a new /settings/voice-mode page: - Master on/off toggle (defaults to on; opt-out, not opt-in) - Engine preference (auto / Web Speech / Whisper Web / Whisper Server) - Language hint (auto-detect or BCP-47 pinned) - Activation mode (click-to-toggle or hold-to-talk) - Auto-send after transcription - Whisper Web model size (tiny / base / small) - Editable Cmd+Shift+M keyboard shortcut Voice settings live under user_settings.voice_mode as a nested JSON object — no schema migration. Setting changes broadcast via the existing user.settings.updated WS event so any open chat tab updates live. The mic button is rendered on the right of the composer alongside the send button (round primary fill; destructive fill with pulse ring while recording). On browsers without a usable engine (e.g. iOS Chrome over HTTP) the button stays visible as a muted greyed icon — tapping it surfaces a toast with the reason (typically a missing secure context). Whisper Web runs in a Web Worker with fp16 decoder weights (avoids the MatMulNBits scale-missing crash that q4/q8 hit on WASM). Models are pulled from the onnx-community/* mirror and cached by transformers.js in the Cache Storage on first use. * fix: address voice mode PR review feedback and E2E selector clash Bot-review fixes from #1159: - Map http.MaxBytesError from c.FormFile to 413 instead of bare 400. - Strip BCP-47 region suffix before passing language hint to Whisper Web. - Recover from worker crash: terminate + null worker + reset ready flag so next init/transcribe creates a fresh worker instead of hanging. - Read live store state via storeApi.getState() in voice-mode settings savers to avoid stale-closure clobbering concurrent settings updates. - Detach Web Speech callbacks before abort() so trailing onend/onerror events don't mutate hook state after cancel(). - Spread caller init before method/body in voice-api fetch so a caller- supplied init can't override the multipart POST. - Replace t.Fatalf with t.Errorf+return inside test HTTP handler goroutine (FailNow from non-test goroutine is unsafe). - Add Enabled/AutoSend zeroing assertions in partial-update test so the bool-overwrite-on-PATCH behavior is locked in explicitly. E2E fix: - toolbar-overflow spec used button.rounded-full which now matches both the send and voice buttons (strict-mode violation). Switched to the submit-message-button testid for an unambiguous locator. * fix: scope voice settings rollback + whisper worker error to changed keys Round 2 of PR review feedback on #1159: - voice-mode settings rollback now restores only the keys patched by the failing request (not the whole snapshot), preserving concurrent edits to unrelated voiceMode fields. - Shortcut rollback diffs previous vs next and reverts only the changed keys (restore prior value or delete if absent), preserving other concurrent shortcut edits. - Whisper worker error handler captures the worker reference at attach time and only clears refs when this.worker still matches it — a stale error from a previously replaced worker no longer nukes the active one. - Update stale whisper-web-models JSDoc that still pointed at Xenova mirrors. * fix: voice mode progress scale, hold-mode race, race-aware rollback Round 3 of PR review feedback on #1159: - Normalise Whisper progress to 0–1 in ensureWhisperClient (transformers.js emits 0–100, the button's display + the `ready: 1` convention expect 0–1 — fixes the 5000% mid-download display). - Claim driverRef synchronously at the top of finishCapture so concurrent pointerup + pointerleave invocations early-return instead of racing and clobbering a freshly-started recording's ref. - Race-aware rollback: voice-mode and shortcut catch branches now skip reverting a key when latest[key] !== next[key]. A failed earlier request no longer overwrites a later successful save to the same key. - Update the Worker wire-protocol comment to show onnx-community/whisper-base instead of the stale Xenova/* example. --------- Co-authored-by: Kandev Agent <agent@kandev.dev>
103 lines
5.4 KiB
Go
103 lines
5.4 KiB
Go
package models
|
|
|
|
import (
|
|
"encoding/json"
|
|
"time"
|
|
)
|
|
|
|
type User struct {
|
|
ID string `json:"id"`
|
|
Email string `json:"email"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
type UserSettings struct {
|
|
UserID string `json:"user_id"`
|
|
WorkspaceID string `json:"workspace_id"`
|
|
KanbanViewMode string `json:"kanban_view_mode"`
|
|
WorkflowFilterID string `json:"workflow_filter_id"`
|
|
RepositoryIDs []string `json:"repository_ids"`
|
|
InitialSetupComplete bool `json:"initial_setup_complete"`
|
|
PreferredShell string `json:"preferred_shell"`
|
|
DefaultEditorID string `json:"default_editor_id"`
|
|
EnablePreviewOnClick bool `json:"enable_preview_on_click"`
|
|
ChatSubmitKey string `json:"chat_submit_key"` // "enter" | "cmd_enter"
|
|
ReviewAutoMarkOnScroll bool `json:"review_auto_mark_on_scroll"`
|
|
ShowReleaseNotification bool `json:"show_release_notification"`
|
|
ReleaseNotesLastSeenVersion string `json:"release_notes_last_seen_version"`
|
|
LspAutoStartLanguages []string `json:"lsp_auto_start_languages"`
|
|
LspAutoInstallLanguages []string `json:"lsp_auto_install_languages"`
|
|
LspServerConfigs map[string]map[string]interface{} `json:"lsp_server_configs"`
|
|
SavedLayouts []SavedLayout `json:"saved_layouts"`
|
|
SidebarViews []SidebarView `json:"sidebar_views"`
|
|
DefaultUtilityAgentID string `json:"default_utility_agent_id"` // Default inference agent for utility agents
|
|
DefaultUtilityModel string `json:"default_utility_model"` // Default model for utility agents
|
|
KeyboardShortcuts map[string]interface{} `json:"keyboard_shortcuts"` // User-configured keyboard shortcut overrides
|
|
TerminalLinkBehavior string `json:"terminal_link_behavior"` // "new_tab" | "browser_panel"
|
|
TerminalFontFamily string `json:"terminal_font_family"`
|
|
TerminalFontSize int `json:"terminal_font_size"`
|
|
ChangesPanelLayout string `json:"changes_panel_layout"` // "flat" | "tree"
|
|
VoiceMode VoiceModeSettings `json:"voice_mode"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
// VoiceModeSettings is the per-user configuration surface for the chat
|
|
// voice-input feature. Stored as a nested JSON object inside the `users.settings`
|
|
// blob — adding fields here does not require a schema migration.
|
|
type VoiceModeSettings struct {
|
|
// Enabled gates the whole feature. When false, the mic button is hidden
|
|
// entirely and no voice-related hooks run on the chat input. Defaults to
|
|
// true for new users; pre-existing user rows that have no `enabled` field
|
|
// in their stored JSON are also treated as enabled (see store layer).
|
|
Enabled bool `json:"enabled"`
|
|
// Engine is the user's preferred transcription engine.
|
|
// "auto" | "webSpeech" | "whisperWeb" | "whisperServer". Default "auto".
|
|
Engine string `json:"engine"`
|
|
// Language is the BCP-47 tag or "auto" to use the browser's language.
|
|
// Examples: "en-US", "pt-PT", "ja-JP". Default "auto".
|
|
Language string `json:"language"`
|
|
// Mode controls how the mic button is activated: "toggle" (click to start/stop)
|
|
// or "hold" (push-to-talk). Default "toggle".
|
|
Mode string `json:"mode"`
|
|
// AutoSend submits the chat message immediately after the transcript is inserted.
|
|
AutoSend bool `json:"auto_send"`
|
|
// WhisperWebModel selects the in-browser Whisper model when engine = whisperWeb.
|
|
// "tiny" | "base" | "small". Default "base".
|
|
WhisperWebModel string `json:"whisper_web_model"`
|
|
}
|
|
|
|
// SavedLayout represents a user-saved dockview layout configuration.
|
|
type SavedLayout struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
IsDefault bool `json:"is_default"`
|
|
Layout json.RawMessage `json:"layout"`
|
|
CreatedAt string `json:"created_at"`
|
|
}
|
|
|
|
// SidebarView represents a user-saved sidebar filter/sort/group preset.
|
|
// The payload is stored and returned as-is; the server does not interpret
|
|
// clause values beyond passing them through.
|
|
type SidebarView struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
Filters []SidebarViewClause `json:"filters"`
|
|
Sort SidebarViewSort `json:"sort"`
|
|
Group string `json:"group"`
|
|
CollapsedGroups []string `json:"collapsed_groups"`
|
|
}
|
|
|
|
type SidebarViewClause struct {
|
|
ID string `json:"id"`
|
|
Dimension string `json:"dimension"`
|
|
Op string `json:"op"`
|
|
Value json.RawMessage `json:"value"`
|
|
}
|
|
|
|
type SidebarViewSort struct {
|
|
Key string `json:"key"`
|
|
Direction string `json:"direction"`
|
|
}
|