Refactor API integration and enhance command handling
- Removed unused modules and updated module paths for clarity. - Added autocomplete functionality for command input in InputState. - Updated AppStateRest to include a method for checking if a turn is in flight. - Refactored subagent engine to use new API client structure. - Changed default provider from "openrouter" to "zen" with updated API keys and models. - Implemented tests for memory management and edit log functionalities. - Enhanced error handling in API requests and improved response parsing. - Updated UI components to reflect new API provider and status indicators.
This commit is contained in:
@@ -68,8 +68,28 @@ pub struct InputState {
|
||||
pub cursor: usize,
|
||||
pub history: Vec<String>,
|
||||
pub history_idx: Option<usize>,
|
||||
pub autocomplete_prefix: String,
|
||||
pub autocomplete_candidates: Vec<String>,
|
||||
pub autocomplete_idx: usize,
|
||||
}
|
||||
|
||||
const COMMANDS: &[&str] = &[
|
||||
"/help",
|
||||
"/quit",
|
||||
"/resume",
|
||||
"/clear",
|
||||
"/save",
|
||||
"/lesson",
|
||||
"/lesson ls",
|
||||
"/lesson export",
|
||||
"/lesson import",
|
||||
"/mode chat",
|
||||
"/mode bash",
|
||||
"/mode help",
|
||||
"/mode settings",
|
||||
"/login",
|
||||
];
|
||||
|
||||
impl InputState {
|
||||
pub fn new() -> Self {
|
||||
InputState {
|
||||
@@ -77,6 +97,39 @@ impl InputState {
|
||||
cursor: 0,
|
||||
history: Vec::new(),
|
||||
history_idx: None,
|
||||
autocomplete_prefix: String::new(),
|
||||
autocomplete_candidates: Vec::new(),
|
||||
autocomplete_idx: 0,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn tab_complete(&mut self) {
|
||||
let trimmed = self.buffer.trim().to_string();
|
||||
if trimmed.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
if !trimmed.starts_with('/') {
|
||||
return;
|
||||
}
|
||||
|
||||
let prefix = trimmed.to_lowercase();
|
||||
|
||||
if prefix != self.autocomplete_prefix || self.autocomplete_candidates.is_empty() {
|
||||
self.autocomplete_candidates = COMMANDS
|
||||
.iter()
|
||||
.filter(|c| c.starts_with(&prefix))
|
||||
.map(|c| c.to_string())
|
||||
.collect();
|
||||
self.autocomplete_prefix = prefix;
|
||||
self.autocomplete_idx = 0;
|
||||
} else {
|
||||
self.autocomplete_idx = (self.autocomplete_idx + 1) % self.autocomplete_candidates.len();
|
||||
}
|
||||
|
||||
if let Some(candidate) = self.autocomplete_candidates.get(self.autocomplete_idx) {
|
||||
self.buffer = candidate.clone();
|
||||
self.cursor = self.buffer.len();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -106,6 +106,10 @@ impl AppStateRest {
|
||||
self.mode
|
||||
}
|
||||
|
||||
pub fn turn_in_flight(&self) -> bool {
|
||||
self.turn_in_flight.lock().map(|g| *g).unwrap_or(false)
|
||||
}
|
||||
|
||||
pub fn set_mode(&mut self, mode: AgentMode) {
|
||||
self.mode = mode;
|
||||
self.dirty = true;
|
||||
|
||||
Reference in New Issue
Block a user