MCPcopy Index your code
hub / github.com/ChrisFeldmeier/OpenCodeRust / run_chat_session

Function run_chat_session

crates/opencode-cli/src/main.rs:1426–1584  ·  view source on GitHub ↗
(
    model: Option<String>,
    provider: Option<String>,
    agent_name: String,
    initial_prompt: Option<String>,
    single_shot: bool,
)

Source from the content-addressed store, hash-verified

1424}
1425
1426async fn run_chat_session(
1427 model: Option<String>,
1428 provider: Option<String>,
1429 agent_name: String,
1430 initial_prompt: Option<String>,
1431 single_shot: bool,
1432) -> anyhow::Result<()> {
1433 let current_dir = std::env::current_dir()?;
1434 let config = load_config(&current_dir)?;
1435
1436 let provider_registry = Arc::new(setup_providers(&config).await?);
1437
1438 if provider_registry.list().is_empty() {
1439 eprintln!("Error: No API keys configured.");
1440 eprintln!("Set one of the following environment variables:");
1441 eprintln!(" - ANTHROPIC_API_KEY");
1442 eprintln!(" - OPENAI_API_KEY");
1443 eprintln!(" - OPENROUTER_API_KEY");
1444 eprintln!(" - GOOGLE_API_KEY");
1445 eprintln!(" - MISTRAL_API_KEY");
1446 eprintln!(" - GROQ_API_KEY");
1447 eprintln!(" - XAI_API_KEY");
1448 eprintln!(" - DEEPSEEK_API_KEY");
1449 eprintln!(" - COHERE_API_KEY");
1450 eprintln!(" - TOGETHER_API_KEY");
1451 eprintln!(" - PERPLEXITY_API_KEY");
1452 eprintln!(" - CEREBRAS_API_KEY");
1453 eprintln!(" - DEEPINFRA_API_KEY");
1454 eprintln!(" - VERCEL_API_KEY");
1455 eprintln!(" - GITLAB_TOKEN");
1456 eprintln!(" - GITHUB_COPILOT_TOKEN");
1457 eprintln!(" - GOOGLE_VERTEX_API_KEY + GOOGLE_VERTEX_PROJECT_ID + GOOGLE_VERTEX_LOCATION");
1458 std::process::exit(1);
1459 }
1460
1461 let tool_registry = Arc::new(create_default_registry().await);
1462
1463 let agent_registry = AgentRegistry::from_config(&config);
1464 let mut agent_info = agent_registry
1465 .get(&agent_name)
1466 .cloned()
1467 .unwrap_or_else(|| AgentInfo::build());
1468
1469 if let Some(ref model_id) = model {
1470 let provider_id = provider.clone().unwrap_or_else(|| {
1471 if model_id.starts_with("claude") {
1472 "anthropic".to_string()
1473 } else {
1474 "openai".to_string()
1475 }
1476 });
1477 agent_info = agent_info.with_model(model_id.clone(), provider_id);
1478 }
1479
1480 println!("\n╔══════════════════════════════════════════╗");
1481 println!("║ OpenCode Interactive Mode ║");
1482 println!("╚══════════════════════════════════════════╝");
1483 println!();

Callers 1

run_non_interactiveFunction · 0.85

Calls 15

load_configFunction · 0.85
newFunction · 0.85
setup_providersFunction · 0.85
from_configFunction · 0.85
process_messageFunction · 0.85
show_helpFunction · 0.85
list_models_interactiveFunction · 0.85
select_modelFunction · 0.85
is_emptyMethod · 0.80
create_default_registryFunction · 0.50
listMethod · 0.45

Tested by

no test coverage detected