Skip to content

Commit 452ce73

Browse files
Copilot0xrinegade
andcommitted
Complete agent chat interface with cursive-multiplex and MCP integration
Co-authored-by: 0xrinegade <[email protected]>
1 parent 6927579 commit 452ce73

File tree

2 files changed

+61
-14
lines changed

2 files changed

+61
-14
lines changed

src/main.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
787787
return handle_mcp_command(&app_matches, sub_matches).await;
788788
}
789789

790+
// Handle chat command early to avoid config loading that might trigger self-repair
791+
if sub_command == "chat" {
792+
return crate::utils::agent_chat::run_agent_chat().await
793+
.map_err(|e| e.into());
794+
}
795+
790796
// Handle AI queries early to avoid config loading
791797
if !is_known_command(sub_command) {
792798
return handle_ai_query(sub_command, sub_matches, &app_matches).await;
@@ -1135,20 +1141,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
11351141
examples::display_all_examples();
11361142
}
11371143
}
1138-
"chat" => {
1139-
// Handle the agent chat interface
1140-
println!("🚀 Launching OSVM Agent Chat Interface...");
1141-
1142-
match crate::utils::agent_chat::run_agent_chat().await {
1143-
Ok(_) => {
1144-
println!("Chat session ended. Goodbye! 👋");
1145-
}
1146-
Err(e) => {
1147-
eprintln!("❌ Error running chat interface: {}", e);
1148-
exit(1);
1149-
}
1150-
}
1151-
}
11521144
"rpc-manager" => {
11531145
// Renamed from "rpc"
11541146
let Some((rpc_sub_command, rpc_sub_matches)) = matches.subcommand() else {

src/utils/agent_chat.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,11 +437,66 @@ fn show_help(siv: &mut Cursive) {
437437
pub async fn run_agent_chat() -> Result<()> {
438438
println!("🚀 Starting OSVM Agent Chat Interface...");
439439

440+
// Check if we're in a terminal environment
441+
if std::env::var("TERM").is_err() || std::env::var("CI").is_ok() {
442+
return run_demo_mode().await;
443+
}
444+
440445
let mut chat_ui = AgentChatUI::new()
441446
.context("Failed to initialize chat UI")?;
442447

443448
chat_ui.run().await
444449
.context("Failed to run chat interface")?;
445450

451+
Ok(())
452+
}
453+
454+
/// Run demo mode for non-terminal environments
455+
async fn run_demo_mode() -> Result<()> {
456+
println!("📱 Running in demo mode (terminal UI not available)");
457+
println!();
458+
459+
// Initialize chat state to show MCP integration
460+
let state = ChatState::new()?;
461+
state.refresh_tools_sync()?;
462+
463+
// Show what the interface provides
464+
println!("🎯 OSVM Agent Chat Interface Features:");
465+
println!(" • Interactive chat interface using cursive-multiplex");
466+
println!(" • Integration with configured MCP servers");
467+
println!(" • Real-time tool calling and blockchain operations");
468+
println!(" • Multi-panel layout with chat history and tool status");
469+
println!();
470+
471+
// Show MCP server status
472+
let tools = state.available_tools.lock().unwrap();
473+
if tools.is_empty() {
474+
println!("⚠️ No MCP servers configured.");
475+
println!(" Use 'osvm mcp setup' to configure Solana MCP server");
476+
println!(" or 'osvm mcp add <server_id> --server-url <url>' to add custom servers");
477+
} else {
478+
println!("🔌 Configured MCP Servers:");
479+
for (server_id, server_tools) in tools.iter() {
480+
println!(" • {}: Available (tools would be fetched in interactive mode)", server_id);
481+
}
482+
}
483+
484+
println!();
485+
println!("💡 Sample Chat Interaction:");
486+
println!(" User: What's the balance of my Solana wallet?");
487+
println!(" Agent: I'll check your wallet balance using the Solana MCP tools...");
488+
println!(" Agent: [Calls solana_get_balance tool with your wallet address]");
489+
println!(" Agent: Your wallet balance is 2.5 SOL");
490+
println!();
491+
492+
println!(" User: Show me recent transactions");
493+
println!(" Agent: [Calls solana_get_signatures tool]");
494+
println!(" Agent: Here are your recent transactions: [transaction list]");
495+
println!();
496+
497+
println!("💻 To use the full interactive interface:");
498+
println!(" Run 'osvm chat' in a proper terminal environment");
499+
println!();
500+
446501
Ok(())
447502
}

0 commit comments

Comments
 (0)