Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src-tauri/src/services/chat_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -669,8 +669,9 @@ async fn stream_anthropic_sse(
// subsequent `data:` line. Some gateways omit the `"type"` field from
// the JSON payload, so we fall back to the SSE event name.
let mut current_event = String::new();
let mut message_stop_received = false;

loop {
'outer: loop {
tokio::select! {
_ = cancel_token.cancelled() => {
return Err(AppError::Cancelled);
Expand All @@ -688,7 +689,8 @@ async fn stream_anthropic_sse(
}

if parse_anthropic_sse_line(&line, &mut current_event, on_token, &mut output)? {
return Ok(output);
message_stop_received = true;
break 'outer;
}
}
}
Expand All @@ -699,6 +701,12 @@ async fn stream_anthropic_sse(
}
}

if !message_stop_received {
return Err(AppError::Http(
"Stream ended without completion signal — connection may have been interrupted. Please retry.".to_string(),
));
}

Ok(output)
}

Expand Down Expand Up @@ -734,10 +742,7 @@ fn parse_anthropic_sse_line(
};
let payload = payload.trim();

let value: Value = match serde_json::from_str(payload) {
Ok(v) => v,
Err(_) => return Ok(false),
};
let value: Value = serde_json::from_str(payload)?;

// Prefer `"type"` from the JSON payload; fall back to the preceding
// `event:` line when the gateway strips it.
Expand Down
6 changes: 5 additions & 1 deletion src-tauri/src/tools/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::time::Duration;
use globset::GlobSet;
use regex::Regex;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use tokio::process::Command;
use walkdir::WalkDir;

Expand Down Expand Up @@ -34,7 +35,10 @@ fn sensitive_globset() -> &'static GlobSet {
}
builder.build().unwrap_or_else(|error| {
log::error!("sensitive_globset build failed: {error} — all file access will require permission");
GlobSetBuilder::new().build().expect("empty GlobSet always builds")
match GlobSetBuilder::new().build() {
Ok(globset) => globset,
Err(inner_error) => panic!("empty GlobSet build failed: {inner_error}"),
}
})
})
}
Expand Down
Loading