feat: hot-swap LLM backend + media keys + codebase Q&A + scheduler cancel-by-text + TTS pre-warm
Single biggest user-facing change: you can now switch local↔cloud LLM by voice
without restarting. Plus four new packs and a perf nudge.
Shared LLM global (crates/jarvis-core/src/llm/mod.rs)
- GLOBAL: Lazy<RwLock<Option<Arc<LlmClient>>>>. Single source of truth.
- init_global() / current() / swap_to(LlmBackend) / current_backend_name() / parse_backend(str).
- llm_fallback + llm_router migrated: they no longer own a separate LlmClient,
they read from the global on each request. Hot-swap is now LIVE — change
backend, next chat call uses the new one.
- parse_backend accepts both english and russian aliases:
"groq"/"cloud"/"облако"/"клауд" → Groq
"ollama"/"local"/"локал"/"локальный" → Ollama
Voice + Lua LLM switcher (resources/commands/llm_switch/, 3 commands)
- "переключись на локальный" / "перейди на оллама" → swap to Ollama
- "переключись на облако" / "используй грок" → swap to Groq
- "какой у тебя мозг" / "облако или локально" → status query
Underlying Lua API (registered globally):
jarvis.llm({messages}, opts) -- as before, now uses global client
jarvis.llm_status() -> "groq" | "ollama" | "none"
jarvis.llm_switch(name) -> name on success, nil on failure
Media keys pack (resources/commands/media_keys/, 4 commands)
- "пауза" / "плей" → VK_MEDIA_PLAY_PAUSE
- "следующий трек" → VK_MEDIA_NEXT_TRACK
- "предыдущий трек" → VK_MEDIA_PREV_TRACK
- "стоп музыка" → VK_MEDIA_STOP
- Helper _media.ps1 uses user32.keybd_event (P/Invoke through Add-Type).
- Works with anything that listens to global media keys: Spotify, Yandex Music,
YouTube (focused tab), Foobar2000, Winamp, etc. No OAuth, no API keys.
Codebase Q&A pack (resources/commands/codebase_qa/, 3 commands)
- "укажи проект <path>" → stores path in jarvis.memory under codebase.root
- "какой проект сейчас" → speaks current path
- "что делает функция X" / "найди в коде Y" / "объясни код"
→ walks the folder (depth 3, 30 files cap, 4KB per file, 50KB total),
filters by source extensions (rs/py/ts/lua/go/...), feeds digest to LLM
with a "senior reviewer" system prompt, speaks 3-5 sentence answer.
Scheduler cancel-by-text (crates/jarvis-core/src/scheduler.rs)
- new pub fn find_by_text(query, limit) -> Vec<ScheduledTask>
- new pub fn remove_by_text(query) -> usize (count removed)
- new pure helper find_by_text_in(tasks, query, limit) for tests
- Lua: jarvis.scheduler.{find_by_text, remove_by_text}
- Voice: "отмени напоминание про воду" / "удали задачу про разминку"
- 3 new unit tests (52 total in jarvis-core).
TTS pre-warm (crates/jarvis-app/src/main.rs)
- Call jarvis_core::tts::backend() once on startup so the first speak()
doesn't pay Piper binary discovery + voice loading cost. Cuts first-speak
latency by ~150-300ms depending on backend.
Build: cargo build --release -p jarvis-app -p jarvis-gui both green.
Tests: 52/52 jarvis-core unit tests pass.
This commit is contained in:
parent
6225198821
commit
5c7245012e
19 changed files with 709 additions and 34 deletions
18
resources/commands/media_keys/_media.ps1
Normal file
18
resources/commands/media_keys/_media.ps1
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# Helper: send a Windows media key via user32.keybd_event.
|
||||
# Called by key.lua with one argument = decimal VK code.
|
||||
param([int]$Vk)
|
||||
|
||||
if (-not $Vk) { exit 1 }
|
||||
|
||||
Add-Type -TypeDefinition @"
|
||||
using System.Runtime.InteropServices;
|
||||
public class MediaKey {
|
||||
[DllImport("user32.dll")]
|
||||
public static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, int dwExtraInfo);
|
||||
}
|
||||
"@
|
||||
|
||||
# down + up
|
||||
[MediaKey]::keybd_event([byte]$Vk, 0, 0, 0)
|
||||
[MediaKey]::keybd_event([byte]$Vk, 0, 2, 0)
|
||||
exit 0
|
||||
80
resources/commands/media_keys/command.toml
Normal file
80
resources/commands/media_keys/command.toml
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
# Media playback control via Windows virtual media keys.
|
||||
# Works with anything that listens to global media keys: Spotify, Yandex Music,
|
||||
# YouTube in browser (when tab is focused), Foobar2000, Winamp, etc.
|
||||
# No OAuth, no API keys — just sends VK_MEDIA_* via PowerShell SendKeys.
|
||||
|
||||
[[commands]]
|
||||
id = "media.play_pause"
|
||||
type = "lua"
|
||||
script = "key.lua"
|
||||
sandbox = "full"
|
||||
timeout = 2000
|
||||
|
||||
[commands.phrases]
|
||||
ru = [
|
||||
"пауза",
|
||||
"продолжи",
|
||||
"плей",
|
||||
"включи музыку",
|
||||
"выключи музыку",
|
||||
"приостанови музыку",
|
||||
"снова музыку",
|
||||
]
|
||||
en = ["pause", "play", "resume music", "stop music"]
|
||||
ua = ["пауза", "продовжи"]
|
||||
|
||||
|
||||
[[commands]]
|
||||
id = "media.next"
|
||||
type = "lua"
|
||||
script = "key.lua"
|
||||
sandbox = "full"
|
||||
timeout = 2000
|
||||
|
||||
[commands.phrases]
|
||||
ru = [
|
||||
"следующий трек",
|
||||
"следующую песню",
|
||||
"перемотай вперёд",
|
||||
"вперёд трек",
|
||||
"переключи на следующую",
|
||||
"next",
|
||||
]
|
||||
en = ["next track", "next song", "skip"]
|
||||
ua = ["наступний трек"]
|
||||
|
||||
|
||||
[[commands]]
|
||||
id = "media.prev"
|
||||
type = "lua"
|
||||
script = "key.lua"
|
||||
sandbox = "full"
|
||||
timeout = 2000
|
||||
|
||||
[commands.phrases]
|
||||
ru = [
|
||||
"предыдущий трек",
|
||||
"предыдущую песню",
|
||||
"перемотай назад",
|
||||
"назад трек",
|
||||
"переключи на предыдущую",
|
||||
"previous",
|
||||
]
|
||||
en = ["previous track", "previous song", "back"]
|
||||
ua = ["попередній трек"]
|
||||
|
||||
|
||||
[[commands]]
|
||||
id = "media.stop"
|
||||
type = "lua"
|
||||
script = "key.lua"
|
||||
sandbox = "full"
|
||||
timeout = 2000
|
||||
|
||||
[commands.phrases]
|
||||
ru = [
|
||||
"стоп музыка",
|
||||
"останови плеер",
|
||||
]
|
||||
en = ["stop", "stop player"]
|
||||
ua = ["зупини плеєр"]
|
||||
26
resources/commands/media_keys/key.lua
Normal file
26
resources/commands/media_keys/key.lua
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
-- Map command id → VK_MEDIA_* virtual key code.
|
||||
-- See https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes
|
||||
local cmd_id = jarvis.context.command_id or ""
|
||||
|
||||
local VK = {
|
||||
["media.play_pause"] = 179, -- VK_MEDIA_PLAY_PAUSE (0xB3)
|
||||
["media.next"] = 176, -- VK_MEDIA_NEXT_TRACK (0xB0)
|
||||
["media.prev"] = 177, -- VK_MEDIA_PREV_TRACK (0xB1)
|
||||
["media.stop"] = 178, -- VK_MEDIA_STOP (0xB2)
|
||||
}
|
||||
|
||||
local code = VK[cmd_id]
|
||||
if not code then
|
||||
return jarvis.cmd.error("Неизвестная медиа-команда.")
|
||||
end
|
||||
|
||||
local helper = jarvis.context.command_path .. "\\_media.ps1"
|
||||
local cmd_str = string.format(
|
||||
'powershell -NoProfile -ExecutionPolicy Bypass -File "%s" %d',
|
||||
helper, code
|
||||
)
|
||||
|
||||
jarvis.system.exec(cmd_str)
|
||||
|
||||
-- silent — feedback would be annoying for media-key spam
|
||||
return jarvis.cmd.silent_ok()
|
||||
Loading…
Add table
Add a link
Reference in a new issue