Skip to content

Commit 11e3c92

Browse files
committed
Refactor tests for improved readability and consistency
- Reorganized imports in test files for clarity. - Standardized formatting and spacing in test assertions and function calls. - Enhanced readability by breaking long lines and using consistent indentation. - Added missing commas in struct initializations and function calls. - Improved error messages in assertions for better debugging. - Ensured all test functions maintain a consistent structure and style.
1 parent 0a2ef12 commit 11e3c92

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+4126
-1972
lines changed

src/main.rs

Lines changed: 165 additions & 90 deletions
Large diffs are not rendered by default.

src/services/ai_service.rs

Lines changed: 147 additions & 53 deletions
Large diffs are not rendered by default.

src/services/mcp_service.rs

Lines changed: 427 additions & 195 deletions
Large diffs are not rendered by default.

src/utils/agent_chat/ai_integration.rs

Lines changed: 131 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
//! AI service integration for chat functionality
22
3-
use crate::services::ai_service::{AiService, ToolPlan, PlannedTool};
4-
use crate::services::mcp_service::{McpService, McpServerConfig};
53
use super::{Colors, RealtimeSuggestion};
4+
use crate::services::ai_service::{AiService, PlannedTool, ToolPlan};
5+
use crate::services::mcp_service::{McpServerConfig, McpService};
66
use anyhow::Result;
7+
use log::{debug, error};
8+
use std::io::{self, Write};
79
use std::sync::Arc;
810
use tokio::time::{sleep, Duration};
9-
use log::{error, debug};
10-
use std::io::{self, Write};
1111

1212
/// Generate real-time suggestions using AI
13-
pub async fn generate_realtime_suggestions(partial_input: &str, ai_service: &AiService) -> Result<Vec<String>> {
13+
pub async fn generate_realtime_suggestions(
14+
partial_input: &str,
15+
ai_service: &AiService,
16+
) -> Result<Vec<String>> {
1417
if partial_input.len() < 3 {
1518
return Ok(Vec::new());
1619
}
@@ -29,7 +32,7 @@ pub async fn generate_realtime_suggestions(partial_input: &str, ai_service: &AiS
2932
pub async fn process_with_realtime_ai(
3033
message: String,
3134
ai_service: &Arc<AiService>,
32-
chat_history: &mut Vec<String>
35+
chat_history: &mut Vec<String>,
3336
) -> Result<()> {
3437
// Show processing animation
3538
show_animated_status("Processing with AI", "⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏", 80).await;
@@ -66,7 +69,13 @@ pub async fn process_with_realtime_ai(
6669

6770
// Display AI response
6871
if !ai_response.is_empty() {
69-
println!("\n{}• Assistant: {}{}{}", Colors::CYAN, Colors::BOLD, ai_response, Colors::RESET);
72+
println!(
73+
"\n{}• Assistant: {}{}{}",
74+
Colors::CYAN,
75+
Colors::BOLD,
76+
ai_response,
77+
Colors::RESET
78+
);
7079
chat_history.push(format!("Assistant: {}", ai_response));
7180
}
7281

@@ -78,7 +87,14 @@ pub async fn show_animated_status(message: &str, chars: &str, duration_ms: u64)
7887
let frames: Vec<char> = chars.chars().collect();
7988

8089
for frame in frames.iter().take(10) {
81-
print!("\r{}{} {} {}{}", Colors::YELLOW, frame, message, Colors::DIM, Colors::RESET);
90+
print!(
91+
"\r{}{} {} {}{}",
92+
Colors::YELLOW,
93+
frame,
94+
message,
95+
Colors::DIM,
96+
Colors::RESET
97+
);
8298
io::stdout().flush().unwrap_or(());
8399
sleep(Duration::from_millis(duration_ms)).await;
84100
}
@@ -89,9 +105,19 @@ pub async fn show_animated_status(message: &str, chars: &str, duration_ms: u64)
89105

90106
/// Display colored plan diagram
91107
pub fn show_colored_plan_diagram(ai_plan: &ToolPlan) {
92-
println!("\n{}╔══════════════════════════════════════════════════╗", Colors::MAGENTA);
93-
println!("║ {}EXECUTION PLAN{} ║", Colors::BOLD, Colors::MAGENTA);
94-
println!("╚══════════════════════════════════════════════════╝{}", Colors::RESET);
108+
println!(
109+
"\n{}╔══════════════════════════════════════════════════╗",
110+
Colors::MAGENTA
111+
);
112+
println!(
113+
"║ {}EXECUTION PLAN{} ║",
114+
Colors::BOLD,
115+
Colors::MAGENTA
116+
);
117+
println!(
118+
"╚══════════════════════════════════════════════════╝{}",
119+
Colors::RESET
120+
);
95121

96122
// Show reasoning
97123
println!("\n{}📋 Reasoning:{}", Colors::CYAN, Colors::RESET);
@@ -103,7 +129,8 @@ pub fn show_colored_plan_diagram(ai_plan: &ToolPlan) {
103129
println!("\n{}🔧 Planned Tools:{}", Colors::YELLOW, Colors::RESET);
104130
for (i, tool) in ai_plan.osvm_tools_to_use.iter().enumerate() {
105131
let status_icon = "○";
106-
println!(" {} {}. {}{}{} {}({}){}",
132+
println!(
133+
" {} {}. {}{}{} {}({}){}",
107134
status_icon,
108135
i + 1,
109136
Colors::GREEN,
@@ -116,7 +143,12 @@ pub fn show_colored_plan_diagram(ai_plan: &ToolPlan) {
116143

117144
// PlannedTool doesn't have a reason field, show args instead
118145
if !tool.args.is_null() {
119-
println!(" {}└─ Args: {}{}", Colors::DIM, tool.args, Colors::RESET);
146+
println!(
147+
" {}└─ Args: {}{}",
148+
Colors::DIM,
149+
tool.args,
150+
Colors::RESET
151+
);
120152
}
121153
}
122154

@@ -168,12 +200,17 @@ pub async fn get_user_choice() -> Result<u32> {
168200
pub async fn execute_ai_plan_with_colors(
169201
ai_plan: &ToolPlan,
170202
original_message: &str,
171-
ai_service: &Arc<AiService>
203+
ai_service: &Arc<AiService>,
172204
) -> Result<()> {
173-
println!("\n{}═══ Executing Plan ═══{}", Colors::MAGENTA, Colors::RESET);
205+
println!(
206+
"\n{}═══ Executing Plan ═══{}",
207+
Colors::MAGENTA,
208+
Colors::RESET
209+
);
174210

175211
for (i, tool) in ai_plan.osvm_tools_to_use.iter().enumerate() {
176-
println!("\n{}[{}/{}] Executing: {}{}{}",
212+
println!(
213+
"\n{}[{}/{}] Executing: {}{}{}",
177214
Colors::CYAN,
178215
i + 1,
179216
ai_plan.osvm_tools_to_use.len(),
@@ -186,7 +223,8 @@ pub async fn execute_ai_plan_with_colors(
186223
show_animated_status(&format!("Running {}", tool.tool_name), "⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏", 50).await;
187224

188225
// Simulate execution result
189-
println!(" {}✓ {} completed successfully{}",
226+
println!(
227+
" {}✓ {} completed successfully{}",
190228
Colors::GREEN,
191229
tool.tool_name,
192230
Colors::RESET
@@ -195,18 +233,29 @@ pub async fn execute_ai_plan_with_colors(
195233
sleep(Duration::from_millis(500)).await;
196234
}
197235

198-
println!("\n{}✓ Plan execution complete!{}", Colors::GREEN, Colors::RESET);
236+
println!(
237+
"\n{}✓ Plan execution complete!{}",
238+
Colors::GREEN,
239+
Colors::RESET
240+
);
199241

200242
Ok(())
201243
}
202244

203245
/// Show contextual suggestions based on chat history
204246
pub async fn show_contextual_suggestions(ai_service: &Arc<AiService>, chat_history: &[String]) {
205-
println!("\n{}💡 Contextual Suggestions:{}", Colors::YELLOW, Colors::RESET);
247+
println!(
248+
"\n{}💡 Contextual Suggestions:{}",
249+
Colors::YELLOW,
250+
Colors::RESET
251+
);
206252

207253
let suggestions = vec![
208254
("Check wallet balance", "@solana/get_balance"),
209-
("View recent transactions", "@solana/get_recent_transactions"),
255+
(
256+
"View recent transactions",
257+
"@solana/get_recent_transactions",
258+
),
210259
("Monitor network status", "/network status"),
211260
];
212261

@@ -217,9 +266,19 @@ pub async fn show_contextual_suggestions(ai_service: &Arc<AiService>, chat_histo
217266

218267
/// Show help commands
219268
pub fn show_help_commands() {
220-
println!("\n{}╔════════════════════════════════════════════════╗", Colors::CYAN);
221-
println!("║ {}HELP - Commands{} ║", Colors::BOLD, Colors::CYAN);
222-
println!("╚════════════════════════════════════════════════╝{}", Colors::RESET);
269+
println!(
270+
"\n{}╔════════════════════════════════════════════════╗",
271+
Colors::CYAN
272+
);
273+
println!(
274+
"║ {}HELP - Commands{} ║",
275+
Colors::BOLD,
276+
Colors::CYAN
277+
);
278+
println!(
279+
"╚════════════════════════════════════════════════╝{}",
280+
Colors::RESET
281+
);
223282

224283
let commands = vec![
225284
("/help", "Show this help menu"),
@@ -242,13 +301,30 @@ pub fn show_help_commands() {
242301
}
243302

244303
/// Show context visualization
245-
pub async fn show_context_visualization(chat_history: &[String], ai_service: &Arc<AiService>) -> Result<()> {
246-
println!("\n{}╔════════════════════════════════════════════════╗", Colors::BLUE);
247-
println!("║ {}CONVERSATION CONTEXT{} ║", Colors::BOLD, Colors::BLUE);
248-
println!("╚════════════════════════════════════════════════╝{}", Colors::RESET);
304+
pub async fn show_context_visualization(
305+
chat_history: &[String],
306+
ai_service: &Arc<AiService>,
307+
) -> Result<()> {
308+
println!(
309+
"\n{}╔════════════════════════════════════════════════╗",
310+
Colors::BLUE
311+
);
312+
println!(
313+
"║ {}CONVERSATION CONTEXT{} ║",
314+
Colors::BOLD,
315+
Colors::BLUE
316+
);
317+
println!(
318+
"╚════════════════════════════════════════════════╝{}",
319+
Colors::RESET
320+
);
249321

250322
if chat_history.is_empty() {
251-
println!("{} No conversation history yet{}", Colors::DIM, Colors::RESET);
323+
println!(
324+
"{} No conversation history yet{}",
325+
Colors::DIM,
326+
Colors::RESET
327+
);
252328
} else {
253329
println!("\n{}Recent Messages:{}", Colors::CYAN, Colors::RESET);
254330
for (i, msg) in chat_history.iter().rev().take(5).enumerate() {
@@ -272,19 +348,34 @@ pub async fn show_context_visualization(chat_history: &[String], ai_service: &Ar
272348
/// Show status overview
273349
pub async fn show_status_overview(
274350
servers: &[(&String, &McpServerConfig)],
275-
chat_history: &[String]
351+
chat_history: &[String],
276352
) -> Result<()> {
277-
println!("\n{}╔════════════════════════════════════════════════╗", Colors::CYAN);
278-
println!("║ {}SYSTEM STATUS{} ║", Colors::BOLD, Colors::CYAN);
279-
println!("╚════════════════════════════════════════════════╝{}", Colors::RESET);
353+
println!(
354+
"\n{}╔════════════════════════════════════════════════╗",
355+
Colors::CYAN
356+
);
357+
println!(
358+
"║ {}SYSTEM STATUS{} ║",
359+
Colors::BOLD,
360+
Colors::CYAN
361+
);
362+
println!(
363+
"╚════════════════════════════════════════════════╝{}",
364+
Colors::RESET
365+
);
280366

281367
// MCP Servers
282368
println!("\n{}MCP Servers:{}", Colors::YELLOW, Colors::RESET);
283369
for (id, config) in servers {
284370
let status_icon = if config.enabled { "✓" } else { "✗" };
285-
let status_color = if config.enabled { Colors::GREEN } else { Colors::RED };
286-
287-
println!(" {} {}{}{} - {}",
371+
let status_color = if config.enabled {
372+
Colors::GREEN
373+
} else {
374+
Colors::RED
375+
};
376+
377+
println!(
378+
" {} {}{}{} - {}",
288379
status_color,
289380
status_icon,
290381
Colors::BLUE,
@@ -305,7 +396,11 @@ pub async fn show_status_overview(
305396

306397
/// Run demo mode for testing
307398
pub async fn run_demo_mode() -> Result<()> {
308-
println!("{}🎮 Demo Mode - Simulating chat interactions{}", Colors::MAGENTA, Colors::RESET);
399+
println!(
400+
"{}🎮 Demo Mode - Simulating chat interactions{}",
401+
Colors::MAGENTA,
402+
Colors::RESET
403+
);
309404

310405
let demo_messages = vec![
311406
"What's my wallet balance?",

0 commit comments

Comments
 (0)