arch + features: Lua jarvis.speak() / jarvis.llm() API, /commands GUI page, games / mouse / random_choice packs

Architecture — DRY at the Lua API surface:

  lua/api/tts.rs (new): jarvis.speak(text, opts?). opts.lang = ISO
  two-letter code (default "ru"); auto-picks first installed voice
  matching the culture. opts.async = true|false (default true). The
  9 packs that previously inlined a 60-character PS-SAPI string for
  every spoken reply can now reduce to one line. Refactored fun/,
  dice/, clipboard_read/ as proof — fun/ask.lua went from 75 lines
  of HTTP+SAPI boilerplate to ~28 lines of intent code.

  lua/api/llm.rs (new): jarvis.llm(messages, opts?). messages is a
  list of {role, content} tables, opts.max_tokens / .temperature /
  .top_p. Returns the assistant string or nil. Gated by sandbox
  allows_http() (so Standard+ packs only). Internally uses the
  existing jarvis_core::llm::LlmClient::complete_with, no duplicated
  HTTP plumbing.

  llm/client.rs: split complete() into complete_with(messages,
  max_tokens, temperature, top_p) for the new caller; old complete()
  is now a thin wrapper at temp=0.7 top_p=1.0 for backward compat.

GUI — /commands page rewrite:

  Replaces the "Раздел в разработке" placeholder. Calls Tauri command
  get_commands_list (already existed in tauri_commands/commands.rs,
  was wired but unused). Renders a search-filterable card grid:
    - cmd id (monospace)
    - type badge with colour by kind (lua=blue, ahk=red, cli=grey,
      voice=green, terminate=red, stop_chaining=violet)
    - sandbox badge
    - description line (if non-empty)
    - all phrases for currentLanguage, fallback to en, fallback to
      first available; each phrase in a small inline pill
  Toolbar: text input with magnifier icon + reload button (↻).
  Counter line shows visible/total + "Скажи Джарвис + любую фразу"
  hint. Counts down as you type the filter.

New packs (3, total 33 → 36):

  games/ — launch_game / list_games. Reads or creates
  %USERPROFILE%\Documents\jarvis-games.json (the sample preloads dota,
  cs2, elden ring, witcher 3, factorio + minecraft launcher path +
  fortnite epic URI). Trigger-strip + fuzzy name/alias match, then
  launches via steam://rungameid/N (Steam), epic:// (Epic Games), or
  start "" "path" (anything else). list_games speaks the configured
  library.

  mouse/ — left/right/middle/double click + scroll up/down. Single
  dispatch.lua + _mouse_helper.ps1. PS P/Invokes user32!mouse_event
  with the right flag pair (LEFTDOWN+LEFTUP / etc.), 30ms gap, doubles
  do two LEFT cycles with a 50ms gap, wheel uses ±360 ticks.

  random_choice/ — "выбери из X или Y или Z". Strips the trigger,
  splits on " или " / " or " / ", " / " либо " / " чи ", math.random
  picks one, speaks "Я выбираю N".

cargo test commands::tests still 3/3. 36 packs verified via
jarvis-gui startup log.
This commit is contained in:
Bossiara13 2026-05-15 12:58:16 +03:00
parent 9d8b917149
commit a16d2401e7
17 changed files with 765 additions and 83 deletions

View file

@ -0,0 +1,33 @@
param(
[Parameter(Mandatory=$true)]
[ValidateSet("left","right","middle","double","scroll_up","scroll_down")]
[string]$Action
)
Add-Type -Name MouseM -Namespace Win32 -MemberDefinition @'
[DllImport("user32.dll")]
public static extern void mouse_event(uint flags, int dx, int dy, int data, System.UIntPtr extra);
'@
$LEFTDOWN = 0x0002
$LEFTUP = 0x0004
$RIGHTDOWN = 0x0008
$RIGHTUP = 0x0010
$MIDDOWN = 0x0020
$MIDUP = 0x0040
$WHEEL = 0x0800
function Click([uint32]$down, [uint32]$up) {
[Win32.MouseM]::mouse_event($down, 0, 0, 0, [UIntPtr]::Zero)
Start-Sleep -Milliseconds 30
[Win32.MouseM]::mouse_event($up, 0, 0, 0, [UIntPtr]::Zero)
}
switch ($Action) {
"left" { Click $LEFTDOWN $LEFTUP }
"right" { Click $RIGHTDOWN $RIGHTUP }
"middle" { Click $MIDDOWN $MIDUP }
"double" { Click $LEFTDOWN $LEFTUP; Start-Sleep -Milliseconds 50; Click $LEFTDOWN $LEFTUP }
"scroll_up" { [Win32.MouseM]::mouse_event($WHEEL, 0, 0, 360, [UIntPtr]::Zero) }
"scroll_down" { [Win32.MouseM]::mouse_event($WHEEL, 0, 0, -360, [UIntPtr]::Zero) }
}

View file

@ -0,0 +1,63 @@
[[commands]]
id = "mouse_left_click"
type = "lua"
script = "dispatch.lua"
sandbox = "full"
timeout = 3000
[commands.phrases]
ru = ["клик", "кликни", "нажми мышкой"]
en = ["click", "left click"]
ua = ["клік", "клікни"]
[[commands]]
id = "mouse_right_click"
type = "lua"
script = "dispatch.lua"
sandbox = "full"
timeout = 3000
[commands.phrases]
ru = ["правый клик", "клик правой", "правой кнопкой"]
en = ["right click"]
ua = ["правий клік"]
[[commands]]
id = "mouse_double_click"
type = "lua"
script = "dispatch.lua"
sandbox = "full"
timeout = 3000
[commands.phrases]
ru = ["двойной клик", "дабл клик", "двойное нажатие"]
en = ["double click"]
ua = ["подвійний клік"]
[[commands]]
id = "mouse_scroll_down"
type = "lua"
script = "dispatch.lua"
sandbox = "full"
timeout = 3000
[commands.phrases]
ru = ["промотай вниз", "прокрути вниз", "вниз промотай"]
en = ["scroll down"]
ua = ["прокрути вниз"]
[[commands]]
id = "mouse_scroll_up"
type = "lua"
script = "dispatch.lua"
sandbox = "full"
timeout = 3000
[commands.phrases]
ru = ["промотай вверх", "прокрути вверх", "наверх промотай"]
en = ["scroll up"]
ua = ["прокрути вгору"]

View file

@ -0,0 +1,31 @@
local cmd_id = jarvis.context.command_id
local helper = jarvis.context.command_path .. "\\_mouse_helper.ps1"
local actions = {
mouse_left_click = "left",
mouse_right_click = "right",
mouse_middle_click = "middle",
mouse_double_click = "double",
mouse_scroll_up = "scroll_up",
mouse_scroll_down = "scroll_down",
}
local action = actions[cmd_id]
if not action then
jarvis.audio.play_error()
return { chain = false }
end
local res = jarvis.system.exec(string.format(
'powershell -NoProfile -ExecutionPolicy Bypass -File "%s" -Action %s',
helper, action
))
if res.success then
jarvis.audio.play_ok()
else
jarvis.log("error", "mouse " .. action .. " failed: " .. tostring(res.stderr))
jarvis.audio.play_error()
end
return { chain = false }