use super::{
AgentPhase, AgentPhaseIndicator, ChatView, DecryptVerb, MessageRole, StreamingDecrypt,
};
impl ChatView {
pub fn start_streaming(&mut self) {
self.is_streaming = true;
self.partial_response.clear();
self.streaming_decrypt.clear();
}
pub fn start_streaming_with_verb(&mut self, verb: DecryptVerb) {
self.is_streaming = true;
self.partial_response.clear();
self.streaming_decrypt = StreamingDecrypt::new()
.with_verb(verb) .with_reveal_speed(0.4) .with_wave_factor(2.5) .with_initial_chaos(12); }
pub fn append_streaming(&mut self, chunk: &str) {
self.partial_response.push_str(chunk);
if self.matrix_effect_enabled {
self.streaming_decrypt.push_text(chunk);
}
self.auto_scroll_to_bottom();
}
pub fn finish_streaming(&mut self) -> String {
self.is_streaming = false;
self.streaming_decrypt.reveal_all();
self.on_agent_complete();
self.auto_scroll_to_bottom();
std::mem::take(&mut self.partial_response)
}
}
impl ChatView {
pub fn trigger_rain_effect(&mut self) {
self.rain_opacity = 0.6; self.rain_fading = true; }
}
impl ChatView {
pub fn on_agent_start(&mut self) {
self.agent_phase = AgentPhase::Syncing;
self.phase_indicator = AgentPhaseIndicator::new(AgentPhase::Syncing);
self.agent_phase_tool = None;
self.trigger_rain_effect();
}
pub fn on_agent_turn(&mut self, _turn_index: u32) {
self.agent_phase = AgentPhase::Planning;
self.phase_indicator.set_phase(AgentPhase::Planning);
self.agent_phase_tool = None;
}
pub fn on_mcp_invoke(&mut self, tool: &str, _server: &str) {
self.agent_phase = AgentPhase::Invoking;
self.agent_phase_tool = Some(tool.to_string());
self.phase_indicator = AgentPhaseIndicator::new(AgentPhase::Invoking).with_tool(tool);
self.trigger_rain_effect();
}
pub fn on_mcp_response(&mut self) {
self.agent_phase = AgentPhase::Processing;
self.phase_indicator.set_phase(AgentPhase::Processing);
}
pub fn on_provider_called(&mut self) {
self.agent_phase = AgentPhase::Inferring;
self.phase_indicator.set_phase(AgentPhase::Inferring);
self.agent_phase_tool = None;
}
pub fn on_streaming_start(&mut self) {
self.agent_phase = AgentPhase::Streaming;
self.phase_indicator.set_phase(AgentPhase::Streaming);
self.trigger_rain_effect();
}
pub fn on_agent_complete(&mut self) {
self.agent_phase = AgentPhase::Idle;
self.phase_indicator.set_phase(AgentPhase::Idle);
self.agent_phase_tool = None;
}
pub fn tick_phase_indicator(&mut self) {
if self.agent_phase.is_active() {
self.phase_indicator.tick();
}
}
pub fn total_tokens(&self) -> u64 {
self.session_context.tokens_used
}
pub fn add_tokens(&mut self, input_tokens: u64, output_tokens: u64) {
self.session_context.add_tokens(input_tokens, output_tokens);
}
}
impl ChatView {
pub fn append_thinking(&mut self, thinking: &str) {
match &mut self.pending_thinking {
Some(existing) => {
existing.push('\n');
existing.push_str(thinking);
}
None => {
self.pending_thinking = Some(thinking.to_string());
}
}
}
pub fn finalize_thinking(&mut self) {
if let Some(thinking) = self.pending_thinking.take() {
if let Some(last) = self.messages.last_mut() {
if last.role == MessageRole::Nika {
last.thinking = Some(thinking);
}
}
}
}
}