Skip to content

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

chore: files changed crates/openhuman-core/src/integrations/composio/ops/sync.rs,crates/openhuman-co

Steven Enamakel0ec78dbc0640
diff --git a/crates/openhuman-core/src/integrations/composio/ops/sync.rs b/crates/openhuman-core/src/integrations/composio/ops/sync.rs
index 27d8e50cc1..4eabfb905e 100644
--- a/crates/openhuman-core/src/integrations/composio/ops/sync.rs
+++ b/crates/openhuman-core/src/integrations/composio/ops/sync.rs
@@ -240,11 +240,12 @@ pub async fn run_sync_pass(
0
} else {
store_records(
+ config,
bound,
toolkit,
connection_id,
source_id,
- &crate::memory::sources::namespace_of(config, source_id),
+ &crate::memory::sources::layout_of(config, source_id),
&response.batch.records,
)
.await
diff --git a/crates/openhuman-core/src/memory/sources/composio.rs b/crates/openhuman-core/src/memory/sources/composio.rs
index 2e36216111..5a0651a450 100644
--- a/crates/openhuman-core/src/memory/sources/composio.rs
+++ b/crates/openhuman-core/src/memory/sources/composio.rs
@@ -67,21 +67,29 @@ pub fn record_item(
})
}
-/// Stores every non-empty record at `namespace`. Returns how many were
-/// stored.
+/// Files every non-empty record into `layout`'s brain, under the toolkit's
+/// brain source. Returns how many were stored.
pub async fn store_records(
+ config: &Config,
bound: &BoundEngine,
toolkit: &str,
connection_id: &str,
source_id: &str,
- namespace: &tinymemory_api::Namespace,
+ layout: &tinymemory_tools::MemoryLayout,
records: &[ConnectorRecord],
) -> MemoryResult<u64> {
let items: Vec<StoreItem> = records
.iter()
.filter_map(|record| record_item(toolkit, connection_id, source_id, record))
.collect();
- super::sync::store_all(bound, items, source_id, namespace).await
+ super::sync::store_all(
+ config,
+ bound,
+ items,
+ (crate::config::schema::MemorySourceKind::Composio, toolkit, source_id),
+ layout,
+ )
+ .await
}
/// Syncs every active connection of the source's toolkit.
diff --git a/crates/openhuman-core/src/memory/sources/mod.rs b/crates/openhuman-core/src/memory/sources/mod.rs
index a2c44c4793..a08e4a3990 100644
--- a/crates/openhuman-core/src/memory/sources/mod.rs
+++ b/crates/openhuman-core/src/memory/sources/mod.rs
@@ -41,7 +41,7 @@ pub fn view(source: &MemorySourceConfig, state: Option<&state::SourceState>) ->
status: state.status,
error: state.error,
items: state.items,
- namespace: namespace_of_source(source).to_string(),
+ namespace: source.namespace.clone().unwrap_or_default(),
}
}
@@ -204,30 +204,36 @@ pub fn is_due(
}
}
-/// The memory node `source` stores at: its configured `namespace`, else the
-/// root. An invalid one (hand-edited config) is logged and stored at the
-/// root.
+/// The layout source `source` files into: its own `namespace` (a layout
+/// root such as `team:acme`) when set, else the configured root.
#[must_use]
-pub fn namespace_of_source(source: &MemorySourceConfig) -> tinymemory_api::Namespace {
- let Some(raw) = source.namespace.as_deref() else {
- return tinymemory_api::Namespace::ROOT;
+pub fn layout_of_source(config: &Config, source: &MemorySourceConfig) -> tinymemory_tools::MemoryLayout {
+ let default = || crate::memory::scope::MemoryIdentity::root().resolve(config).layout;
+ let Some(raw) = source.namespace.as_deref().filter(|raw| !raw.trim().is_empty()) else {
+ return default();
};
- raw.parse().unwrap_or_else(|error| {
- tracing::warn!(id = %source.id, %error, "[memory:sources] invalid namespace; storing at the root");
- tinymemory_api::Namespace::ROOT
- })
+ raw.parse::<tinymemory_api::Namespace>()
+ .map_err(|error| error.to_string())
+ .and_then(|root| tinymemory_tools::MemoryLayout::new(root).map_err(|error| error.to_string()))
+ .unwrap_or_else(|error| {
+ tracing::warn!(id = %source.id, %error, "[memory:sources] invalid root; using the configured one");
+ default()
+ })
}
-/// The memory node the configured source `source_id` stores at; the root
-/// for an unknown id.
+/// The layout the configured source `source_id` files into; the configured
+/// root for an unknown id.
#[must_use]
-pub fn namespace_of(config: &Config, source_id: &str) -> tinymemory_api::Namespace {
+pub fn layout_of(config: &Config, source_id: &str) -> tinymemory_tools::MemoryLayout {
config
.memory
.sources
.iter()
.find(|source| source.id == source_id)
- .map_or(tinymemory_api::Namespace::ROOT, namespace_of_source)
+ .map_or_else(
+ || crate::memory::scope::MemoryIdentity::root().resolve(config).layout,
+ |source| layout_of_source(config, source),
+ )
}
#[cfg(test)]
diff --git a/crates/openhuman-core/src/memory/sources/sync.rs b/crates/openhuman-core/src/memory/sources/sync.rs
index 4fb0755eaf..b10649dd0b 100644
--- a/crates/openhuman-core/src/memory/sources/sync.rs
+++ b/crates/openhuman-core/src/memory/sources/sync.rs
@@ -94,27 +94,36 @@ pub async fn sync_one(config: &Config, source: &MemorySourceConfig) -> MemoryRes
);
}
store_all(
+ config,
&bound,
collected.items,
- &source.id,
- &super::namespace_of_source(source),
+ (source.kind, &source.target, &source.id),
+ &super::layout_of_source(config, source),
)
.await
}
-/// Stores `items` at `namespace`, the source's memory node.
-pub(super) async fn store_all(
+/// Files `items` into `layout`'s brain, each under the brain source it
+/// belongs to (`memory::brain::brain_source`), and queues one belief build
+/// per source it touched. Returns how many were stored.
+pub(crate) async fn store_all(
+ config: &Config,
bound: &BoundEngine,
items: Vec<tinymemory_api::StoreItem>,
- source_id: &str,
- namespace: &tinymemory_api::Namespace,
+ (kind, target, source_id): (crate::config::schema::MemorySourceKind, &str, &str),
+ layout: &tinymemory_tools::MemoryLayout,
) -> MemoryResult<u64> {
let mut stored = 0u64;
let mut last_error = None;
- for mut item in items {
- item.meta_mut().namespace = namespace.clone();
+ let mut touched = std::collections::BTreeSet::new();
+ for item in items {
+ let brain_source = crate::memory::brain::brain_source(kind, target, &item);
+ let item = crate::memory::brain::file_into(layout, &brain_source, item)?;
match store_on(bound, item).await {
- Ok(_) => stored += 1,
+ Ok(_) => {
+ stored += 1;
+ touched.insert(brain_source);
+ }
Err(error @ (MemoryError::Unauthorized(_) | MemoryError::Off(_))) => return Err(error),
Err(error) => {
tracing::debug!(id = %source_id, code = error.code(), "[memory:sources] item store failed");
@@ -122,6 +131,15 @@ pub(super) async fn store_all(
}
}
}
+ let jobs = touched
+ .iter()
+ .filter_map(|source| layout.brain(source).ok())
+ .map(|node| tinymemory_tools::BackgroundJob::BuildBeliefs {
+ request: tinymemory_api::ConsolidateRequest::new(tinymemory_api::Reach::exact(node))
+ .kinds([tinymemory_api::ItemKind::Document]),
+ })
+ .collect();
+ crate::memory::lifecycle::jobs::enqueue(config, layout.root(), jobs).await;
match (stored, last_error) {
(0, Some(error)) => Err(error),
_ => Ok(stored),