feat: add API connection state management and update status display

This commit is contained in:
asepharyana
2026-07-12 02:26:53 +07:00
parent a98fdb0c7b
commit d52ee967ee
4 changed files with 22 additions and 21 deletions
+6
View File
@@ -295,6 +295,7 @@ pub fn apply_action(state: &mut AppStateRest, action: Action) {
match event {
TurnEvent::AssistantMessage(msg) => {
state.misc.thinking = false;
state.misc.api_connected = true;
let display_content = msg.content.clone().unwrap_or_default();
if !display_content.is_empty() {
state.push_transcript(ChatMessageDisplay::new(Role::Assistant, display_content));
@@ -366,6 +367,7 @@ pub fn apply_action(state: &mut AppStateRest, action: Action) {
}
TurnEvent::StreamStart => {
state.misc.thinking = false;
state.misc.api_connected = true;
state.push_transcript(ChatMessageDisplay::new(Role::Assistant, String::new()));
}
TurnEvent::StreamToken(delta) => {
@@ -390,6 +392,7 @@ pub fn apply_action(state: &mut AppStateRest, action: Action) {
}
}
TurnEvent::Error(msg) => {
state.misc.api_connected = false;
let long_toast = Toast {
kind: ToastKind::Error,
message: msg.clone(),
@@ -468,6 +471,9 @@ fn spawn_turn(state: &AppStateRest) {
.unwrap_or_default();
}
}
if api_key.is_empty() {
api_key = crate::service::provider::DEFAULT_API_KEY.to_string();
}
let (temperature, max_tokens) = crate::app::mode::effort::generation_params(
state.misc.effort_level,
state.settings.max_tokens,
+2
View File
@@ -240,6 +240,7 @@ pub struct MiscState {
pub effort_level: usize,
pub selected_index: usize,
pub editor: Option<super::super::mode::editor::EditorState>,
pub api_connected: bool,
}
impl MiscState {
@@ -255,6 +256,7 @@ impl MiscState {
effort_level: 1,
selected_index: 0,
editor: None,
api_connected: false,
}
}