Refactor scrolling methods in ScrollState to accept an amount parameter

- Updated `scroll_up` and `scroll_down` methods to take an `amount` parameter for more flexible scrolling.
- Removed the `AgentMode` enum and related methods from the types module to simplify state management.
- Modified `AppStateRest` to remove the `mode` field and adjusted related logic.
- Enhanced `run_subagent` to build tool definitions and handle API key resolution from configuration.
- Updated command parsing to reflect changes in login handling.
- Removed onboarding overlays and related logic from input handling and rendering.
- Improved status bar to reflect connection status and agent readiness.
- Adjusted workflow panel rendering to simplify phase status display.
- Refactored edit log initialization to load from disk if available.
- Updated settings structure to use a HashMap for API keys.
- Enhanced error handling in LlmClient for authentication issues.
This commit is contained in:
asepharyana
2026-07-12 03:14:52 +07:00
parent 71d3494372
commit 36573e7e3b
28 changed files with 435 additions and 482 deletions
+13 -7
View File
@@ -121,7 +121,9 @@ impl LlmClient {
match result {
Ok((msg, usage)) => return Ok((msg, usage)),
Err(e) => {
if attempt >= max_retries {
let err_str = e.to_string();
let is_auth_error = err_str.contains("API error 401") || err_str.contains("API error 403");
if attempt >= max_retries || is_auth_error {
return Err(e);
}
eprintln!("Warning: {}. Retrying {}/{}...", e, attempt, max_retries);
@@ -143,7 +145,7 @@ impl LlmClient {
tools: Option<Vec<ToolDef>>,
temperature: Option<f32>,
max_tokens: Option<u32>,
mut on_event: impl FnMut(&StreamEvent),
mut on_event: impl FnMut(&StreamEvent) -> bool,
) -> Result<(ChatMessage, Option<(u64, u64)>)> {
let req = ChatRequest {
model: self.model.clone(),
@@ -164,14 +166,16 @@ impl LlmClient {
loop {
attempt += 1;
let mut wrapped = |event: &StreamEvent| {
let mut wrapped = |event: &StreamEvent| -> bool {
started = true;
on_event(event);
on_event(event)
};
match self.try_stream_once(&req, &url, &mut wrapped) {
Ok(result) => return Ok(result),
Err(e) => {
if started || attempt >= max_retries {
let err_str = e.to_string();
let is_auth_error = err_str.contains("API error 401") || err_str.contains("API error 403");
if started || attempt >= max_retries || is_auth_error {
return Err(e);
}
eprintln!("Warning: {}. Retrying {}/{}...", e, attempt, max_retries);
@@ -185,7 +189,7 @@ impl LlmClient {
&self,
req: &ChatRequest,
url: &str,
on_event: &mut dyn FnMut(&StreamEvent),
on_event: &mut dyn FnMut(&StreamEvent) -> bool,
) -> Result<(ChatMessage, Option<(u64, u64)>)> {
use std::io::Read;
@@ -237,7 +241,9 @@ impl LlmClient {
byte_buf.drain(..valid_len);
for event in parser.feed(&text) {
on_event(&event);
if !on_event(&event) {
anyhow::bail!("aborted");
}
match &event {
StreamEvent::Usage { prompt_tokens, completion_tokens, .. } => {
usage = Some((*prompt_tokens, *completion_tokens));