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:
asepharyana
2026-07-11 22:10:17 +07:00
parent f6389018f5
commit 3dee2a1427
30 changed files with 788 additions and 222 deletions
+3
View File
@@ -0,0 +1,3 @@
pub mod request;
pub mod response;
pub mod usage;
+34
View File
@@ -0,0 +1,34 @@
use serde::{Deserialize, Serialize};
use serde_json::Value;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ChatRequest {
pub model: String,
pub messages: Vec<super::super::chat::message::ChatMessage>,
#[serde(skip_serializing_if = "Option::is_none")]
pub max_tokens: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub temperature: Option<f32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub tools: Option<Vec<ToolDef>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub stream: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub top_p: Option<f32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub stop: Option<Vec<String>>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ToolDef {
#[serde(rename = "type")]
pub type_: String,
pub function: ToolFunctionDef,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ToolFunctionDef {
pub name: String,
pub description: String,
pub parameters: Value,
}
+57
View File
@@ -0,0 +1,57 @@
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ChatResponse {
pub id: String,
pub model: String,
pub choices: Vec<Choice>,
pub usage: Option<super::usage::Usage>,
pub created: Option<i64>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Choice {
pub index: u32,
pub message: super::super::chat::message::ChatMessage,
pub finish_reason: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StreamChunk {
pub id: Option<String>,
pub model: Option<String>,
pub choices: Vec<StreamChoice>,
pub usage: Option<super::usage::Usage>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StreamChoice {
pub index: u32,
pub delta: Delta,
pub finish_reason: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Delta {
#[serde(skip_serializing_if = "Option::is_none")]
pub role: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub content: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub tool_calls: Option<Vec<DeltaToolCall>>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DeltaToolCall {
pub index: u32,
pub id: Option<String>,
#[serde(rename = "type")]
pub type_: Option<String>,
pub function: Option<DeltaFunction>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DeltaFunction {
pub name: Option<String>,
pub arguments: Option<String>,
}
+18
View File
@@ -0,0 +1,18 @@
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct Usage {
pub prompt_tokens: Option<u32>,
pub completion_tokens: Option<u32>,
pub total_tokens: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub prompt_tokens_cost: Option<f64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub completion_tokens_cost: Option<f64>,
}
impl Usage {
pub fn total(&self) -> u32 {
self.total_tokens.unwrap_or(0)
}
}