Skip to content

Local, full Windows search replacement, clipboard manager, and launcher: files, apps, settings and semantic media search with Google's EmbeddingGemma 2.

Improve Quick Look and clipboard search; add AI read aloud

ampersandru59537c19ea49
diff --git a/Build-Rust.ps1 b/Build-Rust.ps1
index 196c9c7..b15fee0 100644
--- a/Build-Rust.ps1
+++ b/Build-Rust.ps1
@@ -82,8 +82,8 @@ if (Test-Path $taskPortable) { throw 'Portable staging directory already exists.
New-Item -ItemType Directory -Force $taskPortable | Out-Null
Get-ChildItem -LiteralPath $taskBundle | Copy-Item -Destination $taskPortable -Recurse -Force
Set-Content -LiteralPath (Join-Path $taskPortable 'portable.flag') -Value '' -Encoding ascii
-Compress-Archive -Path (Join-Path $taskPortable '*') -DestinationPath 'dist/installer/VectorDash-Rust-0.3.14-x64.zip' -Force
-$taskInstaller='dist/installer/VectorDash-Rust-Setup-0.3.14-x64.exe'
-$taskZip='dist/installer/VectorDash-Rust-0.3.14-x64.zip'
+Compress-Archive -Path (Join-Path $taskPortable '*') -DestinationPath 'dist/installer/VectorDash-Rust-0.3.15-x64.zip' -Force
+$taskInstaller='dist/installer/VectorDash-Rust-Setup-0.3.15-x64.exe'
+$taskZip='dist/installer/VectorDash-Rust-0.3.15-x64.zip'
@($taskInstaller,$taskZip) | ForEach-Object {((Get-FileHash -LiteralPath $_ -Algorithm SHA256).Hash.ToLowerInvariant()+' '+(Split-Path $_ -Leaf))} | Set-Content 'dist/installer/RUST-SHA256SUMS.txt' -Encoding ascii
Write-Output "Native installer and portable ZIP ready."
diff --git a/README.md b/README.md
index c3a7f2e..c1a5f6e 100644
--- a/README.md
+++ b/README.md
@@ -35,7 +35,7 @@ Search by name or exact words, or describe what you remember. Google's **Embeddi
Switch to **AI** to ask questions using your own local or remote **OpenAI-compatible server**. In **AI settings**, enter a base URL such as `http://localhost:8080/v1`, an optional API key, and your model; refresh to select from the server's models and set a maximum context size.
-Enable **AI chat** and select a model to show the AI tab; disabled AI and clipboard modes stay hidden and are skipped by Tab. Press **Enter** to send, ask follow-up questions, or **Stop** a request. A purple-to-blue trail indicates AI processing. Answers support Markdown, full-color emoji and scrolling; **Ctrl+C** copies the reply. With a vision-capable model, attach a monitor, window or selected screen area to ask about what you see. AI requests and screenshots go to your configured server.
+Enable **AI chat** and select a model to show the AI tab; disabled AI and clipboard modes stay hidden and are skipped by Tab. Press **Enter** to send, ask follow-up questions, or **Stop** a request. A purple-to-blue trail indicates AI processing. Answers support Markdown, full-color emoji and scrolling; **Ctrl+C** or the reply’s Copy button copies the last answer. Follow-up questions scroll to the new response. Reported prompt/decode speeds appear when the server supplies them. With a vision-capable model, attach a monitor, window or selected screen area to ask about what you see. Sent screenshots appear as clickable thumbnails with a copy option. AI requests and screenshots go to your configured server. Optional **Text to speech** settings connect a separate OpenAI-compatible speech server: refresh models/voices, select a voice, and use the reply’s speaker button or **Read Aloud**.
The optional **MCP server**, on the same settings page, lets compatible agents search indexed files and retrieve file information. Keep it local or enable access on your LAN, with optional bearer authentication. See [MCP setup](docs/MCP.md) for connection details. AI chat and MCP are optional; ordinary file search works independently.
diff --git a/native/Cargo.lock b/native/Cargo.lock
index 7317911..2f8fb3d 100644
--- a/native/Cargo.lock
+++ b/native/Cargo.lock
@@ -5705,7 +5705,7 @@ checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
[[package]]
name = "vectordash"
-version = "0.3.14"
+version = "0.3.15"
dependencies = [
"anyhow",
"arboard",
diff --git a/native/Cargo.toml b/native/Cargo.toml
index ccba14a..708f008 100644
--- a/native/Cargo.toml
+++ b/native/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "vectordash"
-version = "0.3.14"
+version = "0.3.15"
edition = "2024"
license = "MIT"
[dependencies]
diff --git a/native/assets/mdi/volume-high.svg b/native/assets/mdi/volume-high.svg
new file mode 100644
index 0000000..6b992fd
--- /dev/null
+++ b/native/assets/mdi/volume-high.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="#ffffff" d="M3 9v6h4l5 5V4L7 9H3m13 3c0-1.77-1-3.29-2.5-4.03v8.05A4.5 4.5 0 0 0 16 12m-2.5-8.77v2.06C16.39 6.15 18.5 8.83 18.5 12s-2.11 5.85-5 6.71v2.06c4.01-.91 7-4.49 7-8.77s-2.99-7.86-7-8.77Z"/></svg>
\ No newline at end of file
diff --git a/native/docs/0.3.15.md b/native/docs/0.3.15.md
new file mode 100644
index 0000000..39934ca
--- /dev/null
+++ b/native/docs/0.3.15.md
@@ -0,0 +1,12 @@
+# VectorDash 0.3.15 preview
+
+- Quick Look stays hidden until its image and first frame are ready, then opens centered over search at the displayed image size with path, score and match reason below.
+- Ctrl+F returns to the search input and selects the whole query.
+- Clipboard word matching handles multiple words in any order. Literal text matches come before image-meaning results. Rows are left aligned with full date/time; image thumbnails appear on the left. Thumbnail caching is bounded and released in tray mode.
+- Optional Text to speech settings in AI: base URL, protected API key, model and voice. Refresh reads models and tries server voice lists; manual IDs remain available when discovery is unsupported. Uses the [OpenAI-compatible speech endpoint](https://developers.openai.com/api/reference/resources/audio/subresources/speech/methods/create). Read aloud sends answer text to this configured server and plays generated audio locally. Long answers are split into bounded requests; Stop interrupts downloads/playback and temporary audio is removed.
+- AI buttons are ordered Screenshot, New Conversation and Send, with a smaller Read Aloud toggle under Send. Follow-up questions return to the newest response after scrolling up.
+- Replies have larger bold You/AI labels, clickable/copyable sent screenshot thumbnails, last-response Copy and speaker controls, and prompt/decode rates when reported by the server.
+
+Validation: 108 automated tests passed. Native main/popup fixtures checked clipboard layout/word matching, select-all search, screenshot rendering and AI controls. A silent local TTS fixture verified automatic playback and bearer authentication, with no real microphone or user data. A native Quick Look visibility test found stable image-sized geometry from first appearance. A follow-up after scrolling up returned to the bottom of the conversation. Setup and portable packages were built with checksum verification.
+
+TTS voice discovery is a server extension: Refresh tries GET audio/voices then GET voices; unavailable lists leave a manual Voice ID field. Timing rates are shown only if returned by the server, not inferred from local elapsed time. The optional TTS service does not load a local TTS model in VectorDash.
diff --git a/native/src/ai.rs b/native/src/ai.rs
index ee258db..5bab78d 100644
--- a/native/src/ai.rs
+++ b/native/src/ai.rs
@@ -184,14 +184,23 @@ pub fn body(s: &Settings, messages: &[Message]) -> Result<Value> {
"Conversation exceeds the context budget"
);
Ok(
- json!({"model":s.llm_model,"messages":wire_messages(messages)?,"max_tokens":output,"stream":true}),
+ json!({"model":s.llm_model,"messages":wire_messages(messages)?,"max_tokens":output,"stream":true,"stream_options":{"include_usage":true}}),
)
}
pub fn ask(
+ s: &Settings,
+ messages: &[Message],
+ cancel: &Arc<AtomicBool>,
+ chunk: impl FnMut(String),
+) -> Result<()> {
+ ask_details(s, messages, cancel, chunk, |_| {})
+}
+pub fn ask_details(
s: &Settings,
messages: &[Message],
cancel: &Arc<AtomicBool>,
mut chunk: impl FnMut(String),
+ mut metrics: impl FnMut(Metrics),
) -> Result<()> {
let body = body(s, messages)?;
let url = endpoint(&s.llm_url, "chat/completions")?;
@@ -219,6 +228,7 @@ pub fn ask(
if let Some(data)=line.strip_prefix("data:").map(str::trim) {
if data=="[DONE]"{anyhow::ensure!(received,"Server returned no answer");return Ok(())}
let value:Value=serde_json::from_str(data)?;
+ let stats=Metrics::from_json(&value);if stats.any(){metrics(stats);}
anyhow::ensure!(value.get("error").is_none(),"LLM server reported an error");
if let Some(text)=value["choices"][0]["delta"]["content"].as_str() {
total+=text.len();anyhow::ensure!(total<=128*1024,"Answer exceeded the display limit");
@@ -230,6 +240,7 @@ pub fn ask(
}
if json_response {
let v:Value=serde_json::from_slice(&pending)?;
+ let stats=Metrics::from_json(&v);if stats.any(){metrics(stats);}
let text=v["choices"][0]["message"]["content"].as_str().context("Server returned no answer")?;
anyhow::ensure!(text.len()<=128*1024,"Answer exceeded the display limit");
chunk(text.into());return Ok(())
@@ -438,3 +449,56 @@ mod disabled_chat_tests {
);
}
}
+
+#[derive(Clone, Debug, Default)]
+pub struct Metrics {
+ pub prompt: Option<f64>,
+ pub decode: Option<f64>,
+}
+impl Metrics {
+ pub fn any(&self) -> bool {
+ self.prompt.is_some() || self.decode.is_some()
+ }
+ pub fn from_json(v: &Value) -> Self {
+ fn positive(v: &Value) -> Option<f64> {
+ v.as_f64().filter(|n| n.is_finite() && *n > 0.0)
+ }
+ fn rate(t: &Value, direct: &str, count: &str, ms: &str) -> Option<f64> {
+ positive(&t[direct]).or_else(|| Some(positive(&t[count])? * 1000.0 / positive(&t[ms])?))
+ }
+ Self {
+ prompt: rate(&v["timings"], "prompt_per_second", "prompt_n", "prompt_ms"),
+ decode: rate(
+ &v["timings"],
+ "predicted_per_second",
+ "predicted_n",
+ "predicted_ms",
+ ),
+ }
+ }
+ pub fn label(&self) -> String {
+ let mut fields = vec![];
+ if let Some(n) = self.prompt {
+ fields.push(format!("Prompt: {n:.1} tok/s"));
+ }
+ if let Some(n) = self.decode {
+ fields.push(format!("Decode: {n:.1} tok/s"));
+ }
+ fields.join(" · ")
+ }
+}
+#[cfg(test)]
+mod metrics_tests {
+ #[test]
+ fn reported_rates_only() {
+ let m = super::Metrics::from_json(
+ &serde_json::json!({"timings":{"prompt_n":100,"prompt_ms":500,"predicted_per_second":25}}),
+ );
+ assert_eq!(m.prompt, Some(200.0));
+ assert_eq!(m.decode, Some(25.0));
+ assert!(
+ !super::Metrics::from_json(&serde_json::json!({"usage":{"completion_tokens":20}}))
+ .any()
+ );
+ }
+}
diff --git a/native/src/app.rs b/native/src/app.rs
index 4310677..f790223 100644
--- a/native/src/app.rs
+++ b/native/src/app.rs
@@ -194,6 +194,25 @@ pub struct App {
ai_context_trimmed: bool,
ai_scroll: f32,
popup_outside_down: bool,
+ select_query: bool,
+ preview_ready_frame: bool,
+ ai_follow_bottom: bool,
+ ai_scroll_offset: f32,
+ qa_ai_scrolled: bool,
+ qa_ai_followup_sent: bool,
+ qa_ai_scroll_before: f32,
+ ai_metrics: crate::ai::Metrics,
+ ai_image_view: Option<String>,
+ tts_models: Vec<String>,
+ tts_voices: Vec<String>,
+ tts_catalog_busy: bool,
+ tts_status: String,
+ tts_busy: bool,
+ tts_job: u64,
+ tts_cancel: Arc<AtomicBool>,
+ read_aloud: bool,
+ clipboard_thumbs: HashMap<i64, egui::TextureHandle>,
+ clipboard_thumb_pending: std::collections::HashSet<i64>,
}
impl App {
pub fn new(
@@ -267,10 +286,16 @@ impl App {
family.retain(|name| name != "segoeui.ttf");
family.insert(0, "segoeui.ttf".into());
}
+ let fallback = fonts.families[&egui::FontFamily::Proportional].clone();
+ fonts
+ .families
+ .entry(egui::FontFamily::Name("bold".into()))
+ .or_insert(fallback);
cc.egui_ctx.set_fonts(fonts);
egui_extras::install_image_loaders(&cc.egui_ctx);
let saved_start_hidden = s.start_hidden;
let window_state = crate::config::WindowState::load(&home);
+ let read_aloud = s.tts_auto;
let mut app = Self {
home,
collapsed: s.sidebar_collapsed,
@@ -441,6 +466,25 @@ impl App {
ai_context_trimmed: false,
ai_scroll: 0.0,
popup_outside_down: false,
+ select_query: false,
+ preview_ready_frame: false,
+ ai_follow_bottom: false,
+ ai_scroll_offset: 0.0,
+ qa_ai_scrolled: false,
+ qa_ai_followup_sent: false,
+ qa_ai_scroll_before: 0.0,
+ ai_metrics: crate::ai::Metrics::default(),
+ ai_image_view: None,
+ tts_models: vec![],
+ tts_voices: vec![],
+ tts_catalog_busy: false,
+ tts_status: String::new(),
+ tts_busy: false,
+ tts_job: 0,
+ tts_cancel: Arc::new(AtomicBool::new(false)),
+ read_aloud,
+ clipboard_thumbs: HashMap::new(),
+ clipboard_thumb_pending: std::collections::HashSet::new(),
};
if app.smoke.is_none() {
crate::launcher::monitor(
@@ -496,12 +540,30 @@ impl App {
app.switch_tool(&tool);
}
if let Some(answer) = get("--smoke-ai-answer") {
+ app.ai_answer = answer.clone();
app.ai_messages.push(crate::ai::Message {
role: "assistant".into(),
content: answer,
images: vec![],
});
}
+ if let Some(path) = get("--smoke-ai-image") {
+ if let Ok(bytes) = std::fs::read(path) {
+ if let Ok(url) = crate::capture::vision(&bytes, None) {
+ app.ai_messages.insert(
+ 0,
+ crate::ai::Message {
+ role: "user".into(),
+ content: "Explain this picture".into(),
+ images: vec![url],
+ },
+ );
+ }
+ }
+ }
+ if std::env::args().any(|a| a == "--smoke-select-query") {
+ app.select_query = true;
+ }
if let Some(path) = get("--smoke-preview") {
app.hits = vec![Hit {
path,
@@ -515,6 +577,8 @@ impl App {
}];
app.query = "Image fixture".into();
app.large_preview = true;
+ app.dirty = false;
+ app.search_pending = false;
}
}
if app.smoke.is_some() {
@@ -559,6 +623,7 @@ impl App {
Ok(()) => {
self.engine.control.update_settings(self.s.clone());
self.saved_settings = self.s.clone();
+ self.read_aloud = self.s.tts_auto;
crate::platform::set_game_names(&self.s.game_processes);
self.model_warm_attempted = false;
self.model_warm_error = None;
@@ -783,18 +848,34 @@ impl App {
self.run(result.map_err(anyhow::Error::msg));
}
Event::ClipboardImage(id, result) => {
- if id == self.clipboard_preview_id {
+ self.clipboard_thumb_pending.remove(&id);
+ {
match result {
Ok(bytes) => match crate::capture::rgba(&bytes) {
Ok(image) => {
- self.clipboard_texture = Some(ctx.load_texture(
- "clipboard-preview",
+ let thumb = image::imageops::thumbnail(&image, 112, 112);
+ let texture = ctx.load_texture(
+ format!("clipboard-thumb-{id}"),
egui::ColorImage::from_rgba_unmultiplied(
- [image.width() as usize, image.height() as usize],
- image.as_raw(),
+ [thumb.width() as usize, thumb.height() as usize],
+ thumb.as_raw(),
),
egui::TextureOptions::LINEAR,
- ));
+ );
+ if self.clipboard_thumbs.len() >= 64 {
+ self.clipboard_thumbs.clear();
+ }
+ self.clipboard_thumbs.insert(id, texture);
+ if id == self.clipboard_preview_id {
+ self.clipboard_texture = Some(ctx.load_texture(
+ "clipboard-preview",
+ egui::ColorImage::from_rgba_unmultiplied(
+ [image.width() as usize, image.height() as usize],
+ image.as_raw(),
+ ),
+ egui::TextureOptions::LINEAR,
+ ));
+ }
}
Err(e) => self.status = e.to_string(),
},
@@ -832,6 +913,35 @@ impl App {
}
}
+ Event::TtsCatalog(url, result) => {
+ self.tts_catalog_busy = false;
+ if url == self.s.tts_url {
+ match result {
+ Ok((models, voices, notice)) => {
+ self.tts_models = models;
+ self.tts_voices = voices;
+ self.tts_status = notice;
+ }
+ Err(e) => self.tts_status = e,
+ }
+ }
+ }
+ Event::TtsDone(id, result) => {
+ if id == self.tts_job {
+ self.tts_busy = false;
+ self.tts_status = result.err().unwrap_or_default();
+ }
+ }
+ Event::AiMetrics(id, metrics) => {
+ if id == self.ai_job {
+ if metrics.prompt.is_some() {
+ self.ai_metrics.prompt = metrics.prompt;
+ }
+ if metrics.decode.is_some() {
+ self.ai_metrics.decode = metrics.decode;
+ }
+ }
+ }
Event::AiChunk(id, text) => {
if id == self.ai_job
&& self.ai_busy
@@ -852,6 +962,9 @@ impl App {
images: vec![],
});
}
+ if self.read_aloud && !self.ai_answer.is_empty() {
+ self.start_read_aloud(self.ai_answer.clone());
+ }
if self.query.trim() == self.ai_question {
self.query.clear();
}
@@ -1721,6 +1834,19 @@ impl App {
if recording {
self.paint_waveform(ui, response.rect);
}
+ if self.select_query && !recording {
+ self.select_query = false;
+ let id = egui::Id::new("query");
+ let mut state = egui::text_edit::TextEditState::load(ctx, id).unwrap_or_default();
+ state
+ .cursor
+ .set_char_range(Some(egui::text::CCursorRange::two(
+ egui::text::CCursor::new(0),
+ egui::text::CCursor::new(self.query.chars().count()),
+ )));
+ state.store(ctx, id);
+ response.request_focus();
+ }
if self.quick && self.startup.elapsed() < Duration::from_secs(2) {
response.request_focus();
}
@@ -1811,7 +1937,7 @@ impl App {
self.scope.clone(),
self.exclude_types.clone(),
);
- ui.horizontal(|ui| {
+ ui.horizontal_top(|ui| {
for label in self.saved_settings.search_tools() {
if ui
.add(
@@ -1836,20 +1962,46 @@ impl App {
}
}
if self.tool == "AI" {
- ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
- if self.ai_busy {
- if ui.button("Stop").clicked() {
- self.stop_ai();
- self.ai_error = Some("Request stopped".into());
- }
- } else if ui
- .add_enabled(
- !self.query.trim().is_empty() && !self.dictation_busy,
- egui::Button::new("Ask · Enter"),
- )
+ ui.with_layout(egui::Layout::right_to_left(egui::Align::Min), |ui| {
+ ui.allocate_ui_with_layout(
+ egui::vec2(88.0, 54.0),
+ egui::Layout::top_down(egui::Align::Min),
+ |ui| {
+ ui.spacing_mut().item_spacing.y = 1.0;
+ ui.spacing_mut().interact_size.y = 16.0;
+ ui.spacing_mut().icon_width = 12.0;
+ ui.spacing_mut().icon_width_inner = 8.0;
+ if self.ai_busy {
+ if ui
+ .add_sized([88.0, 34.0], egui::Button::new("Stop"))
+ .clicked()
+ {
+ self.stop_ai();
+ self.ai_error = Some("Request stopped".into());
+ }
+ } else if ui
+ .add_enabled(
+ !self.query.trim().is_empty() && !self.dictation_busy,
+ egui::Button::new("Send").min_size(egui::vec2(88.0, 34.0)),
+ )
+ .clicked()
+ {
+ self.ask_ai();
+ }
+ ui.add(egui::Checkbox::new(
+ &mut self.read_aloud,
+ RichText::new("Read Aloud").size(11.0),
+ ))
+ .on_hover_text(
+ "Automatically read completed AI replies using your TTS server",
+ );
+ },
+ );
+ if ui
+ .add_enabled(!self.ai_busy, egui::Button::new("New Conversation"))
.clicked()
{
- self.ask_ai();
+ self.new_conversation();
}
if ui
.add_enabled(
@@ -2334,8 +2486,9 @@ impl App {
} else if path.to_lowercase().ends_with(".pdf") {
crate::pdf::preview(Path::new(&path), hit.page.max(1), &query)
} else {
- crate::content::decode(Path::new(&path), &s)
- .and_then(|i| crate::content::jpeg(&i, 1024))
+ crate::content::decode(Path::new(&path), &s).and_then(|i| {
+ crate::content::jpeg(&i, 1024.min(i.width().max(i.height())))
+ })
}
.map_err(|e| e.to_string());
let _ = tx.send(Event::Preview(path, result));
@@ -2345,7 +2498,11 @@ impl App {
if path == &hit.path {
let image = egui::Image::new(texture).max_size(egui::vec2(
ui.available_width(),
- ui.available_height() * if self.large_preview { 0.80 } else { 0.65 },
+ if self.large_preview {
+ (ui.available_height() - 105.0).max(80.0)
+ } else {
+ ui.available_height() * 0.65
+ },
));
ui.add(if hit.kind == "application" {
image.fit_to_exact_size(egui::vec2(
@@ -3496,6 +3653,9 @@ impl App {
}
self.ai_error = None;
self.ai_answer.clear();
+ self.ai_metrics = crate::ai::Metrics::default();
+ self.ai_follow_bottom = true;
+ self.stop_read_aloud();
self.markdown = egui_commonmark::CommonMarkCache::default();
self.ai_question = self.query.trim().into();
match crate::ai::prepare(&self.saved_settings, &self.ai_messages, &self.ai_question) {
@@ -3525,9 +3685,17 @@ impl App {
let messages = self.ai_messages.clone();
let tx = self.engine.tx.clone();
std::thread::spawn(move || {
- let result = crate::ai::ask(&s, &messages, &cancel, |text| {
- let _ = tx.send(Event::AiChunk(id, text));
- })
+ let result = crate::ai::ask_details(
+ &s,
+ &messages,
+ &cancel,
+ |text| {
+ let _ = tx.send(Event::AiChunk(id, text));
+ },
+ |metrics| {
+ let _ = tx.send(Event::AiMetrics(id, metrics));
+ },
+ )
.map_err(|e| e.to_string());
let _ = tx.send(Event::AiDone(id, result));
});
@@ -3548,6 +3716,41 @@ impl App {
self.status = "Copied".into();
}
}
+ fn stop_read_aloud(&mut self) {
+ self.tts_cancel.store(true, Ordering::Release);
+ if self.tts_busy {
+ crate::platform::stop_playback();
+ }
+ self.tts_job += 1;
+ self.tts_busy = false;
+ }
+ fn start_read_aloud(&mut self, text: String) {
+ self.stop_read_aloud();
+ self.tts_job += 1;
+ let id = self.tts_job;
+ self.tts_busy = true;
+ self.tts_status = String::new();
+ self.tts_cancel = Arc::new(AtomicBool::new(false));
+ let cancel = self.tts_cancel.clone();
+ let s = self.saved_settings.clone();
+ let tx = self.engine.tx.clone();
+ std::thread::spawn(move || {
+ let result = crate::tts::speak(&s, &text, &cancel).map_err(|e| e.to_string());
+ let _ = tx.send(Event::TtsDone(id, result));
+ });
+ }
+ fn new_conversation(&mut self) {
+ self.stop_read_aloud();
+ self.ai_messages.clear();
+ self.ai_images.clear();
+ self.ai_attachment = None;
+ self.ai_answer.clear();
+ self.ai_question.clear();
+ self.ai_error = None;
+ self.ai_context_trimmed = false;
+ self.ai_metrics = crate::ai::Metrics::default();
+ self.markdown = egui_commonmark::CommonMarkCache::default();
+ }
fn toggle_dictation(&mut self) {
if self.dictation_busy {
self.dictation_stop.store(true, Ordering::Release);
@@ -3594,7 +3797,7 @@ impl App {
}
let mut open = true;
egui::Window::new("Screenshot for AI").open(&mut open).default_width(860.0).resizable(true).show(ctx,|ui|{
- ui.label("Choose a window or monitor and review its preview. Attach first; Ask sends it to the selected vision model.");
+ ui.label("Choose a window or monitor and review its preview. Attach a screenshot; Send submits it to the selected vision model.");
if ui.add_enabled(!self.capture_busy,egui::Button::new("Select area anywhere on screen")).clicked(){
self.capture_busy=true;self.capture_target=None;self.capture_preview_key=None;self.capture_texture=None;self.capture_bytes=None;
let tx=self.engine.tx.clone();
@@ -3635,31 +3838,9 @@ impl App {
}
fn tools_ui(&mut self, ui: &mut egui::Ui, ctx: &egui::Context) {
if self.tool == "AI" {
- ui.horizontal(|ui| {
- if ui
- .add_enabled(!self.ai_busy, egui::Button::new("New conversation"))
- .clicked()
- {
- self.ai_messages.clear();
- self.ai_images.clear();
- self.ai_attachment = None;
- self.ai_answer.clear();
- self.ai_question.clear();
- self.ai_error = None;
- self.ai_context_trimmed = false;
- self.markdown = egui_commonmark::CommonMarkCache::default();
- }
- if !self.ai_images.is_empty() {
- ui.label("Screenshot attached");
- if ui.button("Remove attachment").clicked() {
- self.ai_images.clear();
- self.ai_attachment = None;
- }
- }
- });
let scroll = self.ai_scroll;
self.ai_scroll = 0.0;
- egui::ScrollArea::vertical()
+ let output = egui::ScrollArea::vertical()
.id_salt("ai-answer")
.stick_to_bottom(self.ai_busy)
.max_height(ui.available_height().max(80.0))
@@ -3667,10 +3848,28 @@ impl App {
for message in &self.ai_messages {
ui.label(
RichText::new(if message.role == "user" { "You" } else { "AI" })
+ .size(20.0)
+ .family(egui::FontFamily::Name("bold".into()))
.strong(),
);
- if !message.images.is_empty() {
- ui.weak("Screenshot");
+ for image in &message.images {
+ if let Ok(bytes) = image_bytes(image) {
+ let uri = format!("bytes://ai-screenshot-{}.jpg", image_key(image));
+ let response = ui.add(
+ egui::Image::from_bytes(uri, bytes)
+ .max_size(egui::vec2(200.0, 130.0))
+ .sense(egui::Sense::click()),
+ );
+ if response.clicked() {
+ self.ai_image_view = Some(image.clone());
+ }
+ response.context_menu(|ui| {
+ if ui.button("Copy screenshot").clicked() {
+ let _ = copy_ai_image(image);
+ ui.close();
+ }
+ });
+ }
}
egui_commonmark::CommonMarkViewer::new().show(
ui,
@@ -3680,16 +3879,58 @@ impl App {
ui.add_space(10.0);
}
if self.ai_busy || self.ai_error.is_some() {
+ ui.label(
+ RichText::new("AI")
+ .size(20.0)
+ .family(egui::FontFamily::Name("bold".into()))
+ .strong(),
+ );
egui_commonmark::CommonMarkViewer::new().show(
ui,
&mut self.markdown,
&self.color_emoji.markdown(ctx, &self.ai_answer),
);
}
+ if !self.ai_busy && !self.ai_answer.is_empty() {
+ ui.horizontal(|ui| {
+ if ui
+ .button("Copy")
+ .on_hover_text("Copy last response")
+ .clicked()
+ {
+ ctx.copy_text(self.ai_answer.clone());
+ }
+ if ui
+ .add(egui::Button::image(crate::icons::image(
+ crate::icons::Icon::Speaker,
+ self.accent(),
+ 20.0,
+ )))
+ .on_hover_text(if self.tts_busy {
+ "Stop read aloud"
+ } else {
+ "Read last response aloud"
+ })
+ .clicked()
+ {
+ if self.tts_busy {
+ self.stop_read_aloud();
+ } else {
+ self.start_read_aloud(self.ai_answer.clone());
+ }
+ }
+ ui.weak(self.ai_metrics.label());
+ });
+ }
+ if self.ai_follow_bottom {
+ ui.scroll_to_cursor(Some(egui::Align::BOTTOM));
+ self.ai_follow_bottom = false;
+ }
if scroll != 0.0 {
ui.scroll_with_delta(egui::vec2(0.0, scroll));
}
});
+ self.ai_scroll_offset = output.state.offset.y;
return;
}
if self.tool == "Emoji" {
@@ -3788,10 +4029,84 @@ impl App {
scroll.show_rows(ui, 72.0, self.tool_items.len(), |ui, range| {
for i in range {
let item = self.tool_items[i].clone();
- let response = ui.add_sized(
- [ui.available_width(), 72.0],
- egui::Button::new(format!("{}\n{}", item.label, item.detail))
- .selected(self.selected == i),
+ if item.image
+ && !self.clipboard_thumbs.contains_key(&item.id)
+ && self.clipboard_thumb_pending.insert(item.id)
+ {
+ let home = self.home.clone();
+ let tx = self.engine.tx.clone();
+ let id = item.id;
+ std::thread::spawn(move || {
+ let _ = tx.send(Event::ClipboardImage(
+ id,
+ crate::launcher::Clipboard::new(&home)
+ .image(id)
+ .map_err(|e| e.to_string()),
+ ));
+ });
+ }
+ let (rect, response) = ui.allocate_exact_size(
+ egui::vec2(ui.available_width(), 72.0),
+ egui::Sense::click(),
+ );
+ let fill = if self.selected == i {
+ ui.visuals().selection.bg_fill
+ } else if response.hovered() {
+ ui.visuals().widgets.hovered.bg_fill
+ } else {
+ ui.visuals().widgets.inactive.bg_fill
+ };
+ ui.painter().rect(
+ rect,
+ 8.0,
+ fill,
+ ui.visuals().widgets.inactive.bg_stroke,
+ egui::StrokeKind::Inside,
+ );
+ let mut left = rect.left() + 10.0;
+ if item.image {
+ let thumb = egui::Rect::from_min_size(
+ egui::pos2(left, rect.top() + 8.0),
+ egui::vec2(56.0, 56.0),
+ );
+ if let Some(texture) = self.clipboard_thumbs.get(&item.id) {
+ let size = texture.size_vec2();
+ let fit = size * (56.0 / size.x).min(56.0 / size.y);
+ let dst = egui::Rect::from_center_size(thumb.center(), fit);
+ ui.painter().image(
+ texture.id(),
+ dst,
+ egui::Rect::from_min_max(
+ egui::Pos2::ZERO,
+ egui::pos2(1.0, 1.0),
+ ),
+ Color32::WHITE,
+ );
+ } else {
+ crate::icons::image(crate::icons::Icon::Image, self.accent(), 30.0)
+ .paint_at(ui, thumb);
+ }
+ left += 66.0;
+ }
+ let text_rect = egui::Rect::from_min_max(
+ egui::pos2(left, rect.top() + 7.0),
+ egui::pos2(rect.right() - 10.0, rect.top() + 45.0),
+ );
+ let galley = ui.painter().layout(
+ item.label.clone(),
+ egui::FontId::proportional(14.0),
+ ui.visuals().text_color(),
+ text_rect.width(),
+ );
+ ui.painter()
+ .with_clip_rect(text_rect.intersect(ui.clip_rect()))
+ .galley(text_rect.min, galley, ui.visuals().text_color());
+ ui.painter().text(
+ egui::pos2(left, rect.bottom() - 17.0),
+ egui::Align2::LEFT_CENTER,
+ &item.detail,
+ egui::FontId::proportional(11.0),
+ ui.visuals().weak_text_color(),
);
if response.clicked() {
self.selected = i;
@@ -3906,7 +4221,7 @@ impl App {
&mut self.s.llm_vision,
"Selected model supports vision (screenshots)",
);
- ui.weak("Screenshots are attached only after capture and pressing Ask / Enter. Your configured server receives the image.");
+ ui.weak("Screenshots are attached only after capture and pressing Send / Enter. Your configured server receives the image.");
ui.add(
egui::DragValue::new(&mut self.s.llm_context)
@@ -3916,6 +4231,61 @@ impl App {
);
ui.weak("Estimated conversation + response budget, not a server context resize. Tokenizers differ. Old turns are removed automatically when needed.");
ui.separator();
+ ui.heading("Text to speech");
+ ui.label("API base URL");
+ ui.text_edit_singleline(&mut self.s.tts_url);
+ ui.weak("Example: http://localhost:8880/v1 (include /v1)");
+ secret(ui, "TTS API key (optional)", &mut self.s.tts_key);
+ if ui
+ .add_enabled(
+ !self.tts_catalog_busy,
+ egui::Button::new("Refresh TTS models and voices"),
+ )
+ .clicked()
+ {
+ self.tts_catalog_busy = true;
+ let s = self.s.clone();
+ let tx = self.engine.tx.clone();
+ std::thread::spawn(move || {
+ let result = crate::tts::catalog(&s).map_err(|e| e.to_string());
+ let _ = tx.send(Event::TtsCatalog(s.tts_url, result));
+ });
+ }
+ if self.tts_catalog_busy {
+ ui.spinner();
+ }
+ egui::ComboBox::from_id_salt("tts-model")
+ .selected_text(if self.s.tts_model.is_empty() {
+ "Select TTS model"
+ } else {
+ &self.s.tts_model
+ })
+ .show_ui(ui, |ui| {
+ for model in &self.tts_models {
+ ui.selectable_value(&mut self.s.tts_model, model.clone(), model);
+ }
+ });
+ ui.label("Model ID");
+ ui.text_edit_singleline(&mut self.s.tts_model);
+ egui::ComboBox::from_id_salt("tts-voice")
+ .selected_text(if self.s.tts_voice.is_empty() {
+ "Select voice"
+ } else {
+ &self.s.tts_voice
+ })
+ .show_ui(ui, |ui| {
+ for voice in &self.tts_voices {
+ ui.selectable_value(&mut self.s.tts_voice, voice.clone(), voice);
+ }
+ });
+ ui.label("Voice ID");
+ ui.text_edit_singleline(&mut self.s.tts_voice);
+ ui.checkbox(&mut self.s.tts_auto, "Read AI responses aloud by default");
+ ui.weak("Generated voice audio. Answers are sent to your TTS server only when read aloud is enabled or requested. Some servers do not offer voice discovery; enter the voice ID manually.");
+ if !self.tts_status.is_empty() {
+ ui.label(&self.tts_status);
+ }
+ ui.separator();
ui.heading("MCP server");
ui.checkbox(&mut self.s.mcp_enabled, "Enable read-only agent access");
ui.checkbox(&mut self.s.mcp_lan, "Allow local-network access");
@@ -4256,8 +4626,32 @@ impl App {
impl eframe::App for App {
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
use raw_window_handle::HasWindowHandle;
+ if self.smoke.is_some() && self.tool == "AI" {
+ let args = std::env::args().collect::<Vec<_>>();
+ if let Some(question) = args
+ .iter()
+ .position(|v| v == "--smoke-followup")
+ .and_then(|i| args.get(i + 1))
+ {
+ if self.startup.elapsed() > Duration::from_secs(2) && !self.qa_ai_scrolled {
+ self.qa_ai_scrolled = true;
+ self.ai_scroll = 10000.0;
+ }
+ if self.startup.elapsed() > Duration::from_secs(3) && !self.qa_ai_followup_sent {
+ self.qa_ai_followup_sent = true;
+ self.qa_ai_scroll_before = self.ai_scroll_offset;
+ self.query = question.clone();
+ self.ask_ai();
+ self.qa_capture_sent = false;
+ self.qa_captured = false;
+ }
+ }
+ }
if ctx.input(|i| i.modifiers.ctrl && i.key_pressed(egui::Key::F)) {
self.page = 0;
+ self.select_query = true;
+ self.filter_open = false;
+ self.save_search_open = false;
ctx.memory_mut(|m| m.request_focus(egui::Id::new("query")));
}
if self.page == 0
@@ -4474,6 +4868,8 @@ impl eframe::App for App {
{
self.texture = None;
self.clipboard_texture = None;
+ self.clipboard_thumbs.clear();
+ self.clipboard_preview_id = -1;
self.color_emoji.clear(ctx);
self.preview_pending = None;
self.search_visible = false;
@@ -4628,6 +5024,17 @@ impl eframe::App for App {
.frame(egui::Frame::NONE.inner_margin(egui::Margin::symmetric(20, 9)))
.show(ctx, |ui| {
if self.page == 0 {
+ if !self.tts_status.is_empty() {
+ ui.label(&self.tts_status);
+ }
+ if self.tts_busy {
+ ui.horizontal(|ui| {
+ ui.label("Reading aloud…");
+ if ui.button("Stop voice").clicked() {
+ self.stop_read_aloud();
+ }
+ });
+ }
if !self.dictation_status.is_empty()
&& !self.dictation_status.starts_with("Recording")
{
@@ -4669,7 +5076,7 @@ impl eframe::App for App {
(
"Enter",
if self.tool == "AI" {
- "ask"
+ "send"
} else if self.tool == "Search" {
"open"
} else {
@@ -5000,6 +5407,29 @@ impl eframe::App for App {
paint_ai_outline(ctx);
}
self.capture_ui(ctx);
+ if let Some(image) = self.ai_image_view.clone() {
+ let mut open = true;
+ egui::Window::new("Sent screenshot")
+ .open(&mut open)
+ .default_width(700.0)
+ .show(ctx, |ui| {
+ if let Ok(bytes) = image_bytes(&image) {
+ ui.add(
+ egui::Image::from_bytes(
+ format!("bytes://ai-screenshot-{}.jpg", image_key(&image)),
+ bytes,
+ )
+ .max_size(egui::vec2(ui.available_width(), 500.0)),
+ );
+ }
+ if ui.button("Copy screenshot").clicked() {
+ self.run(copy_ai_image(&image));
+ }
+ });
+ if !open {
+ self.ai_image_view = None;
+ }
+ }
if let Some(key) = self.remove_component.clone() {
egui::Window::new("Uninstall downloaded item?").collapsible(false).resizable(false).show(ctx,|ui|{
ui.label(format!("Remove the downloaded {key} files? Index data is kept. Active indexing and model work will stop."));
@@ -5101,20 +5531,38 @@ impl eframe::App for App {
}
if !self.large_preview {
self.child_theme_key.clear();
+ self.preview_ready_frame = false;
}
if self.large_preview {
+ let monitor = ctx
+ .input(|i| i.viewport().monitor_size)
+ .unwrap_or(egui::vec2(1920.0, 1080.0));
+ let selected = self.hits.get(self.selected);
+ let image = self
+ .texture
+ .as_ref()
+ .filter(|(path, _)| selected.is_some_and(|h| h.path == *path))
+ .map(|(_, t)| t.size_vec2());
+ let awaiting_image = selected.is_some_and(|h| {
+ crate::content::is_image(&crate::content::extension(Path::new(&h.path)))
+ || h.path.to_lowercase().ends_with(".pdf")
+ }) && image.is_none()
+ && self.preview_error.is_none();
+ let size = quick_look_size(image, monitor);
+ let position = ctx.input(|i| {
+ i.viewport()
+ .outer_rect
+ .map(|r| r.center() - size * 0.5)
+ .unwrap_or(egui::pos2(100.0, 100.0))
+ });
ctx.show_viewport_immediate(
egui::ViewportId::from_hash_of("vectordash-quick-look"),
egui::ViewportBuilder::default()
.with_title("VectorDash — Quick Look")
- .with_position(ctx.input(|i| {
- i.viewport()
- .outer_rect
- .map(|r| r.min)
- .unwrap_or(egui::pos2(100.0, 100.0))
- }))
- .with_inner_size([1040.0, 800.0])
- .with_min_inner_size([700.0, 500.0])
+ .with_position(position)
+ .with_visible(self.preview_ready_frame && !awaiting_image)
+ .with_inner_size(size)
+ .with_min_inner_size([240.0, 180.0])
.with_window_level(egui::WindowLevel::AlwaysOnTop),
|child, class| {
if child.input(|i| {
@@ -5188,6 +5636,14 @@ impl eframe::App for App {
)
.show(child, |ui| self.preview(ui, child));
}
+ if awaiting_image {
+ self.preview_ready_frame = false;
+ ctx.request_repaint_after(Duration::from_millis(30));
+ } else if !self.preview_ready_frame {
+ self.preview_ready_frame = true;
+ child.request_repaint();
+ ctx.request_repaint();
+ }
},
);
}
@@ -5240,7 +5696,7 @@ impl eframe::App for App {
if self.startup.elapsed() > Duration::from_secs(self.smoke_seconds)
&& (self.qa_screenshot.is_none() || self.qa_captured)
{
- let data = serde_json::json!({"ok":true,"native_rust":true,"tool":self.tool,"tools":self.saved_settings.search_tools(),"footer":self.footer_text(),"dictation_status":self.dictation_status,"query":self.query,"ai_busy":self.ai_busy,"ai_answer":self.ai_answer,"model_loaded":self.engine.models.loaded.load(Ordering::Relaxed),"frames":self.frames,"max_frame_interval_ms":self.max_frame_ms,"dark_mode":ctx.style().visuals.dark_mode,"hidden_reopened":self.qa_hidden_reopened,"ocr_enabled":self.s.ocr_enabled,"ocr_setup_selected":self.ocr_setup,"results":self.hits.len(),"selected":self.selected,"result_scroll_offset":self.result_scroll_offset,"scope":self.scope,"quick_look":self.large_preview,"quick_look_size":self.qa_child_size,"cpu":crate::scheduling::metrics().cpu,"gpu":crate::scheduling::metrics().gpu,"query_focus":ctx.memory(|m|m.has_focus(egui::Id::new("query")))});
+ let data = serde_json::json!({"ok":true,"native_rust":true,"tool":self.tool,"tools":self.saved_settings.search_tools(),"footer":self.footer_text(),"dictation_status":self.dictation_status,"query":self.query,"ai_busy":self.ai_busy,"ai_answer":self.ai_answer,"model_loaded":self.engine.models.loaded.load(Ordering::Relaxed),"frames":self.frames,"max_frame_interval_ms":self.max_frame_ms,"dark_mode":ctx.style().visuals.dark_mode,"hidden_reopened":self.qa_hidden_reopened,"ocr_enabled":self.s.ocr_enabled,"ocr_setup_selected":self.ocr_setup,"results":self.hits.len(),"selected":self.selected,"result_scroll_offset":self.result_scroll_offset,"scope":self.scope,"quick_look":self.large_preview,"quick_look_size":self.qa_child_size,"cpu":crate::scheduling::metrics().cpu,"gpu":crate::scheduling::metrics().gpu,"query_focus":ctx.memory(|m|m.has_focus(egui::Id::new("query"))),"ai_metrics":self.ai_metrics.label(),"tts_busy":self.tts_busy,"ai_scroll_offset":self.ai_scroll_offset,"qa_ai_scroll_before":self.qa_ai_scroll_before,"qa_ai_followup_sent":self.qa_ai_followup_sent,"tts_status":self.tts_status,"query_selected":egui::text_edit::TextEditState::load(ctx,egui::Id::new("query")).and_then(|s|s.cursor.char_range()).map(|r|r.as_sorted_char_range().len()).unwrap_or(0)});
let _ = std::fs::write(report, data.to_string());
self.exiting = true;
ctx.send_viewport_cmd(egui::ViewportCommand::Close);
@@ -5254,6 +5710,7 @@ impl eframe::App for App {
let _ = self.window_state.save(&self.home);
self.dictation_cancel.store(true, Ordering::Release);
self.stop_ai();
+ self.stop_read_aloud();
self.shutdown.store(true, Ordering::Relaxed);
self.scheduler_shutdown.store(true, Ordering::Relaxed);
self.engine.control.cancel.store(true, Ordering::Relaxed);
@@ -5545,3 +6002,59 @@ mod activity_trail_tests {
assert!(purple.r() > blue.r() && purple.g() < blue.g());
}
}
+
+fn image_key(value: &str) -> u64 {
+ use std::hash::{Hash, Hasher};
+ let mut hash = std::collections::hash_map::DefaultHasher::new();
+ value.hash(&mut hash);
+ hash.finish()
+}
+fn image_bytes(value: &str) -> anyhow::Result<Vec<u8>> {
+ use base64::Engine;
+ anyhow::ensure!(value.len() <= 3 * 1024 * 1024, "Screenshot exceeds limit");
+ Ok(base64::engine::general_purpose::STANDARD.decode(
+ value
+ .strip_prefix("data:image/jpeg;base64,")
+ .ok_or_else(|| anyhow::anyhow!("Invalid screenshot"))?,
+ )?)
+}
+fn copy_ai_image(value: &str) -> anyhow::Result<()> {
+ let image = crate::capture::rgba(&image_bytes(value)?)?;
+ arboard::Clipboard::new()?.set_image(arboard::ImageData {
+ width: image.width() as usize,
+ height: image.height() as usize,
+ bytes: std::borrow::Cow::Owned(image.into_raw()),
+ })?;
+ Ok(())
+}
+
+fn quick_look_size(image: Option<egui::Vec2>, monitor: egui::Vec2) -> egui::Vec2 {
+ let bounds = egui::vec2(
+ (monitor.x - 100.0).max(240.0),
+ (monitor.y - 130.0).max(180.0),
+ );
+ let picture = image.unwrap_or(egui::vec2(640.0, 400.0));
+ let scale = ((bounds.x - 48.0) / picture.x.max(1.0))
+ .min((bounds.y - 153.0) / picture.y.max(1.0))
+ .min(1.0);
+ egui::vec2(
+ (picture.x * scale + 48.0).max(300.0),
+ (picture.y * scale + 153.0).max(240.0),
+ )
+}
+#[cfg(test)]
+mod quick_look_tests {
+ #[test]
+ fn fits_image_plus_metadata() {
+ let size = super::quick_look_size(
+ Some(eframe::egui::vec2(800.0, 600.0)),
+ eframe::egui::vec2(1920.0, 1080.0),
+ );
+ assert_eq!(size, eframe::egui::vec2(848.0, 753.0));
+ let portrait = super::quick_look_size(
+ Some(eframe::egui::vec2(1000.0, 2000.0)),
+ eframe::egui::vec2(1920.0, 1080.0),
+ );
+ assert!(portrait.x < 500.0 && portrait.y <= 950.0);
+ }
+}
diff --git a/native/src/config.rs b/native/src/config.rs
index b0d1a71..01f278e 100644
--- a/native/src/config.rs
+++ b/native/src/config.rs
@@ -117,6 +117,11 @@ pub struct Settings {
pub llm_vision: bool,
pub llm_url: String,
pub llm_key: String,
+ pub tts_url: String,
+ pub tts_key: String,
+ pub tts_model: String,
+ pub tts_voice: String,
+ pub tts_auto: bool,
pub llm_model: String,
pub llm_context: u32,
pub llm_hotkey: String,
@@ -231,6 +236,11 @@ impl Default for Settings {
llm_vision: false,
llm_url: "http://localhost:8080/v1".into(),
llm_key: String::new(),
+ tts_url: String::new(),
+ tts_key: String::new(),
+ tts_model: String::new(),
+ tts_voice: String::new(),
+ tts_auto: false,
llm_model: String::new(),
llm_context: 4096,
llm_hotkey: "Tab".into(),
@@ -359,6 +369,7 @@ impl Settings {
s.voice_search_hotkey = s.dictation_hotkey.clone();
for value in [
&mut s.llm_key,
+ &mut s.tts_key,
&mut s.remote_key,
&mut s.hf_token,
&mut s.github_token,
@@ -374,6 +385,7 @@ impl Settings {
let mut s = self.clone();
for value in [
&mut s.llm_key,
+ &mut s.tts_key,
&mut s.remote_key,
&mut s.hf_token,
&mut s.github_token,
diff --git a/native/src/engine.rs b/native/src/engine.rs
index 877f766..db546e9 100644
--- a/native/src/engine.rs
+++ b/native/src/engine.rs
@@ -135,6 +135,9 @@ pub enum Event {
Screenshot(Result<Vec<u8>, String>),
Update(crate::updates::Update),
AiChunk(u64, String),
+ AiMetrics(u64, crate::ai::Metrics),
+ TtsCatalog(String, Result<(Vec<String>, Vec<String>, String), String>),
+ TtsDone(u64, Result<(), String>),
AiDone(u64, Result<(), String>),
AiModels(String, Result<Vec<String>, String>),
Launcher(u64, Result<Vec<crate::launcher::Item>, String>),
diff --git a/native/src/icons.rs b/native/src/icons.rs
index 36c0daa..8570166 100644
--- a/native/src/icons.rs
+++ b/native/src/icons.rs
@@ -12,6 +12,7 @@ pub enum Icon {
Emoji,
Clipboard,
Microphone,
+ Speaker,
Camera,
Image,
File,
@@ -46,6 +47,10 @@ pub fn image(icon: Icon, color: Color32, size: f32) -> egui::Image<'static> {
"clipboard-outline",
include_bytes!("../assets/mdi/clipboard-outline.svg"),
),
+ Icon::Speaker => (
+ "volume-high",
+ include_bytes!("../assets/mdi/volume-high.svg"),
+ ),
Icon::Microphone => ("microphone", include_bytes!("../assets/mdi/microphone.svg")),
Icon::Camera => ("camera", include_bytes!("../assets/mdi/camera.svg")),
Icon::Robot => ("robot-love", include_bytes!("../assets/mdi/robot-love.svg")),
diff --git a/native/src/launcher.rs b/native/src/launcher.rs
index 55ab49f..4828b3d 100644
--- a/native/src/launcher.rs
+++ b/native/src/launcher.rs
@@ -151,6 +151,9 @@ impl Clipboard {
models: &crate::models::Models,
) -> Result<Vec<Item>> {
let mut items = self.search(q, s.clipboard_hours)?;
+ if !q.trim().is_empty() {
+ items.sort_by_key(|item| item.image);
+ }
if !s.clipboard_image_embeddings || q.trim().is_empty() || !self.file.exists() {
return Ok(items);
}
@@ -193,7 +196,7 @@ impl Clipboard {
chrono::DateTime::from_timestamp(created, 0)
.map(|d| d
.with_timezone(&chrono::Local)
- .format("%b %d %H:%M")
+ .format("%b %d, %Y · %H:%M:%S")
.to_string())
.unwrap_or_default()
),
@@ -202,8 +205,8 @@ impl Clipboard {
}
scored.sort_by(|a, b| b.0.total_cmp(&a.0));
let mut found = std::collections::HashSet::new();
- let mut result = scored.into_iter().map(|(_, item)| item).collect::<Vec<_>>();
- result.append(&mut items);
+ let mut result = items;
+ result.extend(scored.into_iter().map(|(_, item)| item));
result.retain(|i| found.insert(i.id));
result.truncate(100);
Ok(result)
@@ -263,6 +266,7 @@ impl Clipboard {
.trim_start_matches("clipboard:")
.trim()
.to_lowercase();
+ let words = q.split_whitespace().collect::<Vec<_>>();
let mut result = Vec::new();
for row in statement.query_map([], |r| {
Ok((
@@ -279,9 +283,10 @@ impl Clipboard {
} else {
crate::config::reveal(&payload)?
};
+ let normalized = value.to_lowercase();
if q.is_empty()
|| image && "image picture screenshot".contains(&q)
- || value.to_lowercase().contains(&q)
+ || words.iter().all(|word| normalized.contains(*word))
{
let label = if image {
"Copied image".into()
@@ -302,7 +307,7 @@ impl Clipboard {
chrono::DateTime::from_timestamp(created, 0)
.map(|d| d
.with_timezone(&chrono::Local)
- .format("%b %d %H:%M")
+ .format("%b %d, %Y · %H:%M:%S")
.to_string())
.unwrap_or_default()
),
@@ -684,10 +689,16 @@ mod semantic_clipboard_tests {
!store.index_next_image(&s, &models).unwrap(),
"Already-indexed image must not be embedded again"
);
+ store.record("Dogs playing outside", 1, now).unwrap();
let hits = store.search_with_images("dogs", &s, &models).unwrap();
- assert_eq!(hits.len(), 1);
- assert!(hits[0].image);
- assert!(hits[0].detail.contains("Image meaning"));
+ assert_eq!(hits.len(), 2);
+ assert!(
+ !hits[0].image,
+ "Literal text must outrank semantic image matches"
+ );
+ assert!(hits[1].image);
+ assert!(hits[1].detail.contains("Image meaning"));
+ assert_eq!(store.search("outside dogs", 1).unwrap().len(), 1);
let disabled = crate::config::Settings {
clipboard_image_embeddings: false,
..s
@@ -696,7 +707,8 @@ mod semantic_clipboard_tests {
store
.search_with_images("dogs", &disabled, &models)
.unwrap()
- .is_empty()
+ .iter()
+ .all(|item| !item.image)
);
thread.join().unwrap();
let c = store.connect().unwrap();
diff --git a/native/src/main.rs b/native/src/main.rs
index ac7b0c6..96dd769 100644
--- a/native/src/main.rs
+++ b/native/src/main.rs
@@ -24,6 +24,7 @@ mod scheduling;
mod search_filters;
mod setup;
mod speech_ffi;
+mod tts;
mod updates;
mod vector_cache;
mod worker;
diff --git a/native/src/tts.rs b/native/src/tts.rs
new file mode 100644
index 0000000..84f4542
--- /dev/null
+++ b/native/src/tts.rs
@@ -0,0 +1,275 @@
+use crate::config::Settings;
+use anyhow::{Context, Result};
+use serde_json::{Value, json};
+use std::{
+ sync::{
+ Arc,
+ atomic::{AtomicBool, Ordering},
+ },
+ time::Duration,
+};
+
+pub fn voice_ids(v: &Value) -> Vec<String> {
+ let array = v
+ .as_array()
+ .or_else(|| v["voices"].as_array())
+ .or_else(|| v["data"].as_array());
+ let mut ids = array
+ .into_iter()
+ .flatten()
+ .filter_map(|v| {
+ v.as_str()
+ .or_else(|| v["id"].as_str())
+ .or_else(|| v["voice_id"].as_str())
+ .or_else(|| v["name"].as_str())
+ })
+ .take(1000)
+ .map(str::to_owned)
+ .collect::<Vec<_>>();
+ ids.sort();
+ ids.dedup();
+ ids
+}
+pub fn catalog(s: &Settings) -> Result<(Vec<String>, Vec<String>, String)> {
+ let mut config = s.clone();
+ config.llm_url = s.tts_url.clone();
+ config.llm_key = s.tts_key.clone();
+ let models = crate::ai::models(&config)?;
+ let agent: ureq::Agent = ureq::Agent::config_builder()
+ .timeout_global(Some(Duration::from_secs(15)))
+ .max_redirects(0)
+ .http_status_as_error(false)
+ .build()
+ .into();
+ for path in ["audio/voices", "voices"] {
+ let mut req = agent.get(crate::ai::endpoint(&s.tts_url, path)?);
+ if !s.tts_key.trim().is_empty() {
+ req = req.header("Authorization", format!("Bearer {}", s.tts_key.trim()));
+ }
+ let mut response = req.call().context("Could not refresh TTS voices")?;
+ if response.status().as_u16() == 404 || response.status().as_u16() == 405 {
+ continue;
+ }
+ anyhow::ensure!(
+ response.status().is_success(),
+ "TTS voice list returned HTTP {}",
+ response.status()
+ );
+ let data: Value = response
+ .body_mut()
+ .with_config()
+ .limit(1024 * 1024)
+ .read_json()?;
+ let voices = voice_ids(&data);
+ if !voices.is_empty() {
+ return Ok((models, voices, String::new()));
+ }
+ }
+ Ok((
+ models,
+ vec![],
+ "This server does not publish a voice list. Enter its voice ID below.".into(),
+ ))
+}
+pub fn speech_parts(markdown: &str) -> Vec<String> {
+ use pulldown_cmark::{Event, Parser};
+ let mut plain = String::new();
+ for event in Parser::new(markdown) {
+ match event {
+ Event::Text(t) | Event::Code(t) => plain.push_str(&t),
+ Event::SoftBreak | Event::HardBreak | Event::End(_) => plain.push(' '),
+ _ => {}
+ }
+ }
+ let plain = plain.split_whitespace().collect::<Vec<_>>().join(" ");
+ let mut parts = vec![];
+ let mut part = String::new();
+ let mut count = 0;
+ for word in plain.split_inclusive(' ') {
+ for ch in word.chars() {
+ if count >= 4000 {
+ parts.push(std::mem::take(&mut part));
+ count = 0;
+ }
+ part.push(ch);
+ count += 1;
+ }
+ }
+ if !part.trim().is_empty() {
+ parts.push(part);
+ }
+ parts
+}
+pub fn synthesize(s: &Settings, text: &str, cancel: &Arc<AtomicBool>) -> Result<Vec<u8>> {
+ anyhow::ensure!(
+ !s.tts_model.trim().is_empty() && !s.tts_voice.trim().is_empty(),
+ "Select a TTS model and voice in AI settings"
+ );
+ let url = crate::ai::endpoint(&s.tts_url, "audio/speech")?;
+ let runtime = tokio::runtime::Builder::new_current_thread()
+ .enable_all()
+ .build()?;
+ runtime.block_on(async {
+ let client=reqwest::Client::builder().connect_timeout(Duration::from_secs(5)).timeout(Duration::from_secs(120)).redirect(reqwest::redirect::Policy::none()).build()?;
+ let mut req=client.post(url).json(&json!({"model":s.tts_model,"voice":s.tts_voice,"input":text,"response_format":"wav"}));if !s.tts_key.trim().is_empty(){req=req.bearer_auth(s.tts_key.trim());}
+ let cancellation=async {while !cancel.load(Ordering::Acquire){tokio::time::sleep(Duration::from_millis(25)).await;}};tokio::pin!(cancellation);
+ let mut response=tokio::select!{biased;_=&mut cancellation=>anyhow::bail!("Read aloud stopped"),r=req.send()=>r.context("Could not connect to the TTS server")?};
+ anyhow::ensure!(response.status().is_success(),"TTS server returned HTTP {}",response.status());
+ let mut audio=vec![];loop {let bytes=tokio::select!{biased;_=&mut cancellation=>anyhow::bail!("Read aloud stopped"),r=response.chunk()=>r?};let Some(bytes)=bytes else {break};anyhow::ensure!(audio.len()+bytes.len()<=32*1024*1024,"TTS audio exceeded the limit");audio.extend_from_slice(&bytes);}
+ anyhow::ensure!(audio.starts_with(b"RIFF")&&audio.get(8..12)==Some(b"WAVE"),"TTS server did not return WAV audio");Ok(audio)
+ })
+}
+pub fn speak(s: &Settings, text: &str, cancel: &Arc<AtomicBool>) -> Result<()> {
+ use std::io::Write;
+ let parts = speech_parts(text);
+ anyhow::ensure!(!parts.is_empty(), "No answer to read aloud");
+ for part in parts {
+ if cancel.load(Ordering::Acquire) {
+ break;
+ }
+ let bytes = synthesize(s, &part, cancel)?;
+ if cancel.load(Ordering::Acquire) {
+ break;
+ }
+ let mut file = tempfile::Builder::new()
+ .prefix("vectordash-tts-")
+ .suffix(".wav")
+ .tempfile()?;
+ file.write_all(&bytes)?;
+ file.flush()?;
+ crate::platform::play_at(file.path().to_str().context("Invalid audio path")?, 0.0)?;
+ loop {
+ let errors = crate::platform::playback_errors();
+ anyhow::ensure!(errors.is_empty(), "{}", errors.join("; "));
+ if !crate::platform::playback_active() {
+ break;
+ }
+ if cancel.load(Ordering::Acquire) {
+ crate::platform::stop_playback();
+ break;
+ }
+ std::thread::sleep(Duration::from_millis(100));
+ }
+ }
+ Ok(())
+}
+#[cfg(test)]
+mod tests {
+ use super::*;
+ #[test]
+ fn voices_and_long_markdown() {
+ assert_eq!(
+ voice_ids(&json!({"voices":["af_heart",{"id":"nova"},{"voice_id":"custom"}]})),
+ vec!["af_heart", "custom", "nova"]
+ );
+ let parts = speech_parts(&format!(
+ "**Hello** [world](https://example.org) {}",
+ "犬".repeat(9000)
+ ));
+ assert!(parts.iter().all(|s| s.chars().count() <= 4000));
+ assert!(!parts.join("").contains("https://"));
+ assert!(parts.join("").starts_with("Hello world"));
+ }
+ #[test]
+ fn configured_auth_and_wav() {
+ let server = tiny_http::Server::http("127.0.0.1:0").unwrap();
+ let s = Settings {
+ tts_url: format!("http://{}/v1", server.server_addr()),
+ tts_key: "test-token".into(),
+ tts_model: "tts-test".into(),
+ tts_voice: "voice-test".into(),
+ ..Default::default()
+ };
+ let worker =
+ std::thread::spawn(move || {
+ let mut req = server.recv().unwrap();
+ assert_eq!(req.url(), "/v1/audio/speech");
+ assert!(
+ req.headers().iter().any(|h| h.field.equiv("Authorization")
+ && h.value.as_str() == "Bearer test-token")
+ );
+ let mut body = String::new();
+ req.as_reader().read_to_string(&mut body).unwrap();
+ let body: Value = serde_json::from_str(&body).unwrap();
+ assert_eq!(body["voice"], "voice-test");
+ assert_eq!(body["response_format"], "wav");
+ req.respond(tiny_http::Response::from_data(
+ b"RIFF0000WAVEfmt test".to_vec(),
+ ))
+ .unwrap();
+ });
+ assert!(
+ synthesize(&s, "Hello", &Arc::new(AtomicBool::new(false)))
+ .unwrap()
+ .starts_with(b"RIFF")
+ );
+ worker.join().unwrap();
+ }
+}
+
+#[cfg(test)]
+mod catalog_tests {
+ use super::*;
+ #[test]
+ fn refresh_falls_back_to_voices_and_preserves_auth() {
+ let server = tiny_http::Server::http("127.0.0.1:0").unwrap();
+ let s = Settings {
+ tts_url: format!("http://{}/v1", server.server_addr()),
+ tts_key: "secret".into(),
+ ..Default::default()
+ };
+ let worker =
+ std::thread::spawn(move || {
+ for (path, status, body) in [
+ ("/v1/models", 200, r#"{"data":[{"id":"tts-test"}]}"#),
+ ("/v1/audio/voices", 404, "{}"),
+ ("/v1/voices", 200, r#"{"voices":["af_heart","af_bella"]}"#),
+ ] {
+ let req = server.recv().unwrap();
+ assert_eq!(req.url(), path);
+ assert!(
+ req.headers().iter().any(|h| h.field.equiv("Authorization")
+ && h.value.as_str() == "Bearer secret")
+ );
+ req.respond(tiny_http::Response::from_string(body).with_status_code(status))
+ .unwrap();
+ }
+ });
+ let (models, voices, notice) = catalog(&s).unwrap();
+ assert_eq!(models, vec!["tts-test"]);
+ assert_eq!(voices, vec!["af_bella", "af_heart"]);
+ assert!(notice.is_empty());
+ worker.join().unwrap();
+ }
+ #[test]
+ fn cancellation_does_not_wait_for_audio() {
+ let server = tiny_http::Server::http("127.0.0.1:0").unwrap();
+ let s = Settings {
+ tts_url: format!("http://{}/v1", server.server_addr()),
+ tts_model: "test".into(),
+ tts_voice: "test".into(),
+ ..Default::default()
+ };
+ let start = std::time::Instant::now();
+ assert!(synthesize(&s, "hello", &Arc::new(AtomicBool::new(true))).is_err());
+ assert!(start.elapsed() < Duration::from_secs(1));
+ }
+ #[test]
+ fn tts_key_is_protected_in_settings() {
+ let home = tempfile::tempdir().unwrap();
+ let s = Settings {
+ tts_key: "tts-secret-key".into(),
+ ..Default::default()
+ };
+ s.save(home.path()).unwrap();
+ assert!(
+ !std::fs::read_to_string(home.path().join("settings.json"))
+ .unwrap()
+ .contains("tts-secret-key")
+ );
+ assert_eq!(
+ Settings::load(home.path()).unwrap().tts_key,
+ "tts-secret-key"
+ );
+ }
+}
diff --git a/packaging/VectorDash-Rust.iss b/packaging/VectorDash-Rust.iss
index 8f3a10b..0c0d20f 100644
--- a/packaging/VectorDash-Rust.iss
+++ b/packaging/VectorDash-Rust.iss
@@ -3,7 +3,7 @@ AppId={{C6AC1B4D-A119-4D73-B2C8-6C507DEFE923}
AppName=VectorDash
AppVerName=VectorDash
UninstallDisplayName=VectorDash
-AppVersion=0.3.14
+AppVersion=0.3.15
AppPublisher=VectorDash contributors
AppPublisherURL=https://github.com/ampersandru/VectorDash
DefaultDirName={localappdata}\Programs\VectorDash
@@ -13,7 +13,7 @@ ArchitecturesAllowed=x64compatible
ArchitecturesInstallIn64BitMode=x64compatible
MinVersion=10.0.22000
OutputDir=..\dist\installer
-OutputBaseFilename=VectorDash-Rust-Setup-0.3.14-x64
+OutputBaseFilename=VectorDash-Rust-Setup-0.3.15-x64
SetupIconFile=VectorDash.ico
UninstallDisplayIcon={app}\VectorDash.exe
LicenseFile=..\LICENSE