feat(memory): add message pagination support
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
- get_messages_paginated(session_id, limit, offset) for batch loading - count_messages(session_id) for total count queries - Enables frontend to load messages progressively instead of all-at-once
This commit is contained in:
@@ -324,6 +324,46 @@ impl MemoryStore {
|
|||||||
Ok(messages)
|
Ok(messages)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get messages for a session with pagination
|
||||||
|
pub async fn get_messages_paginated(
|
||||||
|
&self,
|
||||||
|
session_id: &SessionId,
|
||||||
|
limit: u32,
|
||||||
|
offset: u32,
|
||||||
|
) -> Result<Vec<Message>> {
|
||||||
|
let session_str = session_id.to_string();
|
||||||
|
|
||||||
|
let rows = sqlx::query_as::<_, (String,)>(
|
||||||
|
"SELECT content FROM messages WHERE session_id = ? ORDER BY seq LIMIT ? OFFSET ?"
|
||||||
|
)
|
||||||
|
.bind(&session_str)
|
||||||
|
.bind(limit)
|
||||||
|
.bind(offset)
|
||||||
|
.fetch_all(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(|e| ZclawError::StorageError(e.to_string()))?;
|
||||||
|
|
||||||
|
let messages = rows
|
||||||
|
.into_iter()
|
||||||
|
.filter_map(|(content,)| serde_json::from_str(&content).ok())
|
||||||
|
.collect();
|
||||||
|
Ok(messages)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Count messages in a session
|
||||||
|
pub async fn count_messages(&self, session_id: &SessionId) -> Result<u64> {
|
||||||
|
let session_str = session_id.to_string();
|
||||||
|
let count: i64 = sqlx::query_scalar(
|
||||||
|
"SELECT COUNT(*) FROM messages WHERE session_id = ?"
|
||||||
|
)
|
||||||
|
.bind(&session_str)
|
||||||
|
.fetch_one(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(|e| ZclawError::StorageError(e.to_string()))?;
|
||||||
|
|
||||||
|
Ok(count as u64)
|
||||||
|
}
|
||||||
|
|
||||||
// === KV Store ===
|
// === KV Store ===
|
||||||
|
|
||||||
/// Store a key-value pair for an agent
|
/// Store a key-value pair for an agent
|
||||||
|
|||||||
Reference in New Issue
Block a user