summaryrefslogtreecommitdiff
path: root/makima/src
diff options
context:
space:
mode:
Diffstat (limited to 'makima/src')
-rw-r--r--makima/src/server/handlers/chat.rs42
1 files changed, 36 insertions, 6 deletions
diff --git a/makima/src/server/handlers/chat.rs b/makima/src/server/handlers/chat.rs
index 306093a..158805b 100644
--- a/makima/src/server/handlers/chat.rs
+++ b/makima/src/server/handlers/chat.rs
@@ -33,6 +33,15 @@ const CONTEXT_COMPACTION_THRESHOLD: f32 = 0.90;
/// Approximate characters per token (rough estimate for English text)
const CHARS_PER_TOKEN: usize = 4;
+#[derive(Debug, Clone, Deserialize, ToSchema)]
+#[serde(rename_all = "camelCase")]
+pub struct ChatHistoryMessage {
+ /// Role: "user" or "assistant"
+ pub role: String,
+ /// Message content
+ pub content: String,
+}
+
#[derive(Debug, Deserialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct ChatRequest {
@@ -41,6 +50,9 @@ pub struct ChatRequest {
/// Optional model selection: "claude-sonnet" (default), "claude-opus", or "groq"
#[serde(default)]
pub model: Option<String>,
+ /// Optional conversation history for context continuity
+ #[serde(default)]
+ pub history: Option<Vec<ChatHistoryMessage>>,
}
#[derive(Debug, Serialize, ToSchema)]
@@ -276,14 +288,32 @@ You have access to tools for:
tool_calls: None,
tool_call_id: None,
},
- Message {
- role: "user".to_string(),
- content: Some(request.message.clone()),
- tool_calls: None,
- tool_call_id: None,
- },
];
+ // Add conversation history if provided (for context continuity)
+ if let Some(history) = &request.history {
+ for hist_msg in history {
+ messages.push(Message {
+ role: hist_msg.role.clone(),
+ content: Some(hist_msg.content.clone()),
+ tool_calls: None,
+ tool_call_id: None,
+ });
+ }
+ tracing::info!(
+ history_messages = history.len(),
+ "Loaded conversation history"
+ );
+ }
+
+ // Add current user message
+ messages.push(Message {
+ role: "user".to_string(),
+ content: Some(request.message.clone()),
+ tool_calls: None,
+ tool_call_id: None,
+ });
+
// State for tracking changes
let mut current_body = file.body.clone();
let mut current_summary = file.summary.clone();