MCPcopy Create free account
hub / github.com/aws/amazon-q-developer-cli / new

Method new

crates/chat-cli/src/cli/chat/mod.rs:687–821  ·  view source on GitHub ↗
(
        os: &mut Os,
        conversation_id: &str,
        mut agents: Agents,
        mut input: Option<String>,
        input_source: InputSource,
        resume_conversation: bool,
        termi

Source from the content-addressed store, hash-verified

685impl ChatSession {
686 #[allow(clippy::too_many_arguments)]
687 pub async fn new(
688 os: &mut Os,
689 conversation_id: &str,
690 mut agents: Agents,
691 mut input: Option<String>,
692 input_source: InputSource,
693 resume_conversation: bool,
694 terminal_width_provider: fn() -> Option<usize>,
695 tool_manager: ToolManager,
696 model_id: Option<String>,
697 tool_config: HashMap<String, ToolSpec>,
698 interactive: bool,
699 mcp_enabled: bool,
700 wrap: Option<WrapMode>,
701 ) -> Result<Self> {
702 // Only load prior conversation if we need to resume
703 let mut existing_conversation = false;
704
705 let should_send_structured_msg = should_send_structured_message(os);
706 let (view_end, _byte_receiver, mut control_end_stderr, control_end_stdout) =
707 get_legacy_conduits(should_send_structured_msg);
708 let (prompt_ack_tx, prompt_ack_rx) = std::sync::mpsc::channel::<()>();
709
710 tokio::task::spawn_blocking(move || {
711 let stderr = std::io::stderr();
712 let stdout = std::io::stdout();
713 if let Err(e) = view_end.into_legacy_mode(StyledText, Some(prompt_ack_tx), stderr, stdout) {
714 error!("Conduit view end legacy mode exited: {:?}", e);
715 }
716 });
717
718 let conversation = match resume_conversation {
719 true => {
720 let previous_conversation = std::env::current_dir()
721 .ok()
722 .and_then(|cwd| os.database.get_conversation_by_path(cwd).ok())
723 .flatten();
724
725 // Only restore conversations where there were actual messages
726 // Prevents edge case where user clears conversation then exits without chatting.
727 match previous_conversation.filter(|cs| !cs.history().is_empty()) {
728 Some(mut cs) => {
729 existing_conversation = true;
730 input = Some(input.unwrap_or("In a few words, summarize our conversation so far.".to_owned()));
731 cs.tool_manager = tool_manager;
732 if let Some(profile) = cs.current_profile() {
733 if agents.switch(profile).is_err() {
734 execute!(
735 &mut control_end_stderr,
736 StyledText::error_fg(),
737 style::Print("Error"),
738 StyledText::reset(),
739 style::Print(format!(
740 ": cannot resume conversation with {profile} because it no longer exists. Using default.\n"
741 ))
742 )?;
743 let _ = agents.switch(DEFAULT_AGENT_NAME);
744 }

Callers

nothing calls this directly

Calls 11

get_legacy_conduitsFunction · 0.85
into_legacy_modeMethod · 0.80
current_profileMethod · 0.80
switchMethod · 0.80
update_stateMethod · 0.80
is_emptyMethod · 0.45
historyMethod · 0.45
sendMethod · 0.45

Tested by

no test coverage detected