-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement first message persistence and display in chat #740
Comments
Implementation completed on the
All changes have been tested locally. The implementation:
Next steps:
Please review the changes and let me know if any adjustments are needed. (Comment from OpenAgents) |
I've implemented the requested changes on the
The changes allow for:
Next steps:
(Comment from OpenAgents) |
I've fixed the issues and restored the working functionality:
.route(
"/api/start-repo-chat",
post(server::handlers::chat::start_repo_chat),
)
.route(
"/api/send-message",
post(server::handlers::chat::send_message),
)
The changes allow for:
Next steps:
(Comment from OpenAgents) |
Fixed the user_id issue in messages. The problem was that the messages table requires a user_id but we weren't including it in the CreateMessageRequest. Changes made:
pub struct CreateMessageRequest {
pub conversation_id: Uuid,
pub user_id: String, // Added this field
pub role: String,
pub content: String,
pub metadata: Option<Value>,
pub tool_calls: Option<Value>,
}
INSERT INTO messages (conversation_id, user_id, role, content, metadata, tool_calls, created_at)
VALUES ($1, $2, $3, $4, $5, $6, NOW())
let message = chat_db
.create_message(&CreateMessageRequest {
conversation_id: conversation.id,
user_id: user_id.to_string(), // Added this
role: "user".to_string(),
content: request.message.clone(),
metadata: Some(json!({
"repos": request.repos
})),
tool_calls: None,
})
The changes ensure that:
Next steps:
(Comment from OpenAgents) |
Fixed the issue with repos metadata not being saved for follow-up messages. The changes:
// If no repos provided in the request, try to get them from the conversation's first message
let metadata = if let Some(repos) = request.repos {
info!("Using repos from request: {:?}", repos);
Some(json!({ "repos": repos }))
} else {
// Get the first message of the conversation to find the repos
let messages = chat_db.get_conversation_messages(request.conversation_id).await?;
// Find the first message with repos metadata
let first_message_repos = messages.iter().find_map(|msg| {
msg.metadata.as_ref().and_then(|meta| {
meta.get("repos")
.and_then(|repos| repos.as_array())
.map(|repos| repos.to_owned())
})
});
if let Some(repos) = first_message_repos {
info!("Using repos from first message: {:?}", repos);
Some(json!({ "repos": repos }))
} else {
info!("No repos found in request or first message");
None
}
}; This ensures that:
The changes are live on the firstmsg branch. (Comment from OpenAgents) |
Fixed the infinite loop issue when refreshing chat pages. The changes:
useEffect(() => {
if (!id) return;
const loadMessages = async () => {
try {
const response = await fetch(`/api/conversations/${id}/messages`);
if (!response.ok) {
throw new Error("Failed to load messages");
}
const data = await response.json();
setMessages(id, data);
} catch (error) {
console.error("Error loading messages:", error);
}
};
loadMessages();
}, [id, setMessages]);
pub async fn get_conversation_messages(
State(state): State<AppState>,
Path(conversation_id): Path<Uuid>,
) -> Result<Json<Vec<Message>>, (StatusCode, String)> {
info!("Fetching messages for conversation: {}", conversation_id);
let chat_db = ChatDatabaseService::new(state.pool);
let messages = chat_db.get_conversation_messages(conversation_id).await?;
info!("Found {} messages", messages.len());
Ok(Json(messages))
}
.route(
"/api/conversations/:id/messages",
get(server::handlers::chat::get_conversation_messages),
) This ensures that:
The changes are live on the firstmsg branch. (Comment from OpenAgents) |
Fixed the issue with messages being recorded as "anonymous" instead of using the actual user ID. The changes:
The changes ensure that:
The changes are live on the (Comment from OpenAgents) |
We need to implement proper storage and display of the first chat message along with its metadata (repos).
Current State
Required Changes
Backend
start_repo_chat
handler to store repos in message metadata:Frontend Store
Chat Route
Testing
Next Steps
Related: #730, #733
The text was updated successfully, but these errors were encountered: