mirror of
https://github.com/outbackdingo/optimclaw.git
synced 2026-08-27 08:00:17 +00:00
* feat: Import OpenClaw memory, history and settings * review fixes * fix: address remaining code quality issues 1. Remove dead import_conversation() function - replaced by import_conversation_atomic() 2. Improve non-UTF-8 filename handling in list_agent_dbs() - log warning instead of silent 'unknown' 3. Remove emojis from CLI output per project style guide Co-Authored-By: Claude Haiku 4.5 <[email protected]> --------- Co-authored-by: Claude Haiku 4.5 <[email protected]>
64 lines
1.8 KiB
Rust
64 lines
1.8 KiB
Rust
//! OpenClaw memory chunk import.
|
|
|
|
use std::sync::Arc;
|
|
|
|
use crate::db::Database;
|
|
use crate::import::{ImportError, ImportOptions};
|
|
|
|
use super::reader::OpenClawMemoryChunk;
|
|
|
|
/// Import a single memory chunk into IronClaw.
|
|
pub async fn import_chunk(
|
|
db: &Arc<dyn Database>,
|
|
chunk: &OpenClawMemoryChunk,
|
|
opts: &ImportOptions,
|
|
) -> Result<(), ImportError> {
|
|
// Get or create document by path
|
|
let doc = db
|
|
.get_or_create_document_by_path(&opts.user_id, None, &chunk.path)
|
|
.await
|
|
.map_err(|e| ImportError::Database(e.to_string()))?;
|
|
|
|
// Insert chunk
|
|
let chunk_id = db
|
|
.insert_chunk(
|
|
doc.id,
|
|
chunk.chunk_index,
|
|
&chunk.content,
|
|
None, // Don't set embedding yet if dimensions might not match
|
|
)
|
|
.await
|
|
.map_err(|e| ImportError::Database(e.to_string()))?;
|
|
|
|
// If we have an embedding, try to update it
|
|
if let Some(ref embedding) = chunk.embedding {
|
|
// Note: dimension check would go here if we had target dimensions available
|
|
// For now, just store what we have
|
|
db.update_chunk_embedding(chunk_id, embedding)
|
|
.await
|
|
.map_err(|e| ImportError::Database(e.to_string()))?;
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn test_memory_chunk_import_structure() {
|
|
// Verify that OpenClawMemoryChunk can be created with test data
|
|
let chunk = OpenClawMemoryChunk {
|
|
path: "test/path.md".to_string(),
|
|
content: "Test content".to_string(),
|
|
embedding: Some(vec![0.1, 0.2, 0.3]),
|
|
chunk_index: 0,
|
|
};
|
|
|
|
assert_eq!(chunk.path, "test/path.md");
|
|
assert_eq!(chunk.chunk_index, 0);
|
|
assert!(chunk.embedding.is_some());
|
|
}
|
|
}
|