Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

refactor(memory): delegate source sync helpers to tinymemory

Steven Enamakelabb3423bcc85
diff --git a/crates/openhuman-core/src/memory/sources/mod.rs b/crates/openhuman-core/src/memory/sources/mod.rs
index 3cea48138b..61939ecf9d 100644
--- a/crates/openhuman-core/src/memory/sources/mod.rs
+++ b/crates/openhuman-core/src/memory/sources/mod.rs
@@ -22,8 +22,8 @@ use super::types::{SourceStatus, SourceView, SourcesAddParams};
pub use sync::{start_sync, sync_due, sync_one};
-/// Fewest minutes between scheduled syncs of one source.
-pub const MIN_SCHEDULE_MINS: u32 = 15;
+/// Fewest minutes between scheduled syncs of one source (the module's).
+pub use tinymemory_integrations::sources::sync::MIN_SCHEDULE_MINS;
/// The view of `source` with its sync state.
#[must_use]
@@ -140,7 +140,7 @@ pub fn apply_add(
schedule_mins: params.schedule_mins,
namespace,
};
- sync::reader_entry(&source)?;
+ sync::validate(&source)?;
config.memory.sources.push(source.clone());
tracing::info!(id = %source.id, kind = kind.as_str(), "[memory:sources] source added");
Ok(source)
@@ -186,26 +186,6 @@ pub async fn forget_items(config: &Config, id: &str) -> MemoryResult<usize> {
Ok(report.forgotten)
}
-/// Whether `source` is due for a scheduled sync at `now`.
-#[must_use]
-pub fn is_due(
- source: &MemorySourceConfig,
- last: Option<&state::SourceState>,
- now: DateTime<Utc>,
-) -> bool {
- let Some(mins) = source.schedule_mins else {
- return false;
- };
- match last {
- Some(state) if state.status == SourceStatus::Syncing => false,
- Some(state) => state.last_sync_at.is_none_or(|at| {
- now.signed_duration_since(at)
- >= chrono::Duration::minutes(i64::from(mins.max(MIN_SCHEDULE_MINS)))
- }),
- None => true,
- }
-}
-
/// The layout source `source` files into: its own `namespace` (a layout
/// root such as `team:acme`) when set, else the configured root.
#[must_use]
diff --git a/crates/openhuman-core/src/memory/sources/sync.rs b/crates/openhuman-core/src/memory/sources/sync.rs
index 60be797ad8..18894a2907 100644
--- a/crates/openhuman-core/src/memory/sources/sync.rs
+++ b/crates/openhuman-core/src/memory/sources/sync.rs
@@ -136,12 +136,9 @@ pub async fn sync_one(config: &Config, source: &MemorySourceConfig) -> MemoryRes
}
async fn run(config: &Config, source: &MemorySourceConfig) -> Result<u64, SyncError> {
- let bound = engine::resolve(config).engine().map_err(|error| {
- SyncError::Engine(tinymemory_api::Error::new(
- tinymemory_api::ErrorKind::Unavailable,
- error.to_string(),
- ))
- })?;
+ let bound = engine::resolve(config)
+ .engine()
+ .map_err(|error| SyncError::Invalid(error.to_string()))?;
let collected = module::read_source(
&registered(source),
&config.action_dir,