mirror of
https://github.com/block/goose.git
synced 2026-07-17 12:56:20 +02:00
Fix out of order messages
This commit is contained in:
@@ -1638,6 +1638,7 @@ impl Agent {
|
||||
session_manager.add_message(&session_config.id, msg).await?;
|
||||
}
|
||||
conversation.extend(messages_to_add);
|
||||
conversation.sort_by_created();
|
||||
if exit_chat {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -103,6 +103,10 @@ impl Conversation {
|
||||
self.0.clear();
|
||||
}
|
||||
|
||||
pub fn sort_by_created(&mut self) {
|
||||
self.0.sort_by_key(|m| m.created);
|
||||
}
|
||||
|
||||
pub fn filtered_messages<F>(&self, filter: F) -> Vec<Message>
|
||||
where
|
||||
F: Fn(&MessageMetadata) -> bool,
|
||||
|
||||
@@ -1082,7 +1082,7 @@ impl SessionStorage {
|
||||
async fn get_conversation(&self, session_id: &str) -> Result<Conversation> {
|
||||
let pool = self.pool().await?;
|
||||
let rows = sqlx::query_as::<_, (String, String, i64, Option<String>, Option<String>)>(
|
||||
"SELECT role, content_json, created_timestamp, metadata_json, message_id FROM messages WHERE session_id = ? ORDER BY timestamp",
|
||||
"SELECT role, content_json, created_timestamp, metadata_json, message_id FROM messages WHERE session_id = ? ORDER BY created_timestamp",
|
||||
)
|
||||
.bind(session_id)
|
||||
.fetch_all(pool)
|
||||
|
||||
Reference in New Issue
Block a user