Story 43: Unified chat UI for Claude Code and regular chat

Integrate Claude Code provider into the chat UI alongside regular
Ollama/Anthropic providers. Updates AgentPanel and Chat components.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Dave
2026-02-20 14:09:59 +00:00
parent 42c21f680b
commit 44bc82d23a
4 changed files with 539 additions and 74 deletions

View File

@@ -1,4 +1,5 @@
use crate::llm::prompts::SYSTEM_PROMPT;
use crate::llm::providers::claude_code::ClaudeCodeResult;
use crate::llm::types::{Message, Role, ToolCall, ToolDefinition, ToolFunctionDefinition};
use crate::state::SessionState;
use crate::store::StoreOps;
@@ -209,7 +210,9 @@ where
// Claude Code provider: bypasses our tool loop entirely.
// Claude Code has its own agent loop, tools, and context management.
// We just pipe the user message in and stream raw output back.
// We pipe the user message in, stream text tokens for live display, and
// collect the structured messages (assistant turns + tool results) from
// the stream-json output for the final message history.
if is_claude_code {
use crate::llm::providers::claude_code::ClaudeCodeProvider;
@@ -225,7 +228,10 @@ where
.unwrap_or_else(|_| std::path::PathBuf::from("."));
let provider = ClaudeCodeProvider::new();
let response = provider
let ClaudeCodeResult {
messages: cc_messages,
session_id,
} = provider
.chat_stream(
&user_message,
&project_root.to_string_lossy(),
@@ -236,19 +242,24 @@ where
.await
.map_err(|e| format!("Claude Code Error: {e}"))?;
let assistant_msg = Message {
role: Role::Assistant,
content: response.content.unwrap_or_default(),
tool_calls: None,
tool_call_id: None,
};
// Build the final message history: user messages + Claude Code's turns.
// If the session produced no structured messages (e.g. empty response),
// fall back to an empty assistant message so the UI stops loading.
let mut result = messages.clone();
result.push(assistant_msg);
if cc_messages.is_empty() {
result.push(Message {
role: Role::Assistant,
content: String::new(),
tool_calls: None,
tool_call_id: None,
});
} else {
result.extend(cc_messages);
}
on_update(&result);
return Ok(ChatResult {
messages: result,
session_id: response.session_id,
session_id,
});
}