Skip to content

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

feat(memory): place a legacy brain document by connector (legacy_brain_node)

M3gA-Mind8d64e60f1cfa
diff --git a/crates/openhuman-core/src/memory/brain.rs b/crates/openhuman-core/src/memory/brain.rs
index 926de2375a..9fafb3721c 100644
--- a/crates/openhuman-core/src/memory/brain.rs
+++ b/crates/openhuman-core/src/memory/brain.rs
@@ -53,6 +53,39 @@ pub fn brain_source(kind: MemorySourceKind, target: &str) -> BrainSource {
}
}
+/// The brain source a document filed under the old per-type layout belongs
+/// to now, for the migration that moves it: `old_source_id` is the id of
+/// the `source:<id>` node it sits at, `item` the document itself.
+///
+/// - Per-format nodes (`pdf`, `markdown`, `docx`, `xlsx`, `pptx`, `code`,
+/// `other`) held local files: `files`.
+/// - `web` held links and feeds, but also HTML files from a folder or an
+/// upload; a document with a file kind or a file path is a file.
+/// - Any other node was a connector: its canonical slug (`google_drive`
+/// becomes `googledrive`), so `notion`, `github` and `gmail` stay put.
+#[must_use]
+pub fn legacy_brain_node(old_source_id: &str, item: &StoreItem) -> BrainSource {
+ let id = crate::integrations::composio::tools::canonicalize_toolkit_slug(old_source_id);
+ match id.as_str() {
+ "files" | "pdf" | "markdown" | "md" | "docx" | "xlsx" | "pptx" | "code" | "other" => {
+ files_source()
+ }
+ "web" => {
+ let meta = item.meta();
+ let file = matches!(
+ meta.source.kind,
+ tinymemory_api::SourceKind::File | tinymemory_api::SourceKind::Folder
+ ) || meta.file_path.is_some();
+ if file {
+ files_source()
+ } else {
+ BrainSource::Web
+ }
+ }
+ _ => id.parse().unwrap_or_else(|_| files_source()),
+ }
+}
+
/// The repository a GitHub document belongs to, as the collection id
/// `<owner>--<repo>` (lowercase, as GitHub's names are case-insensitive):
/// from its `repo` (`owner/name` or a URL), else its URL. An owner name
diff --git a/crates/openhuman-core/src/memory/brain_tests.rs b/crates/openhuman-core/src/memory/brain_tests.rs
index 3d0ff07107..0c4713a4ee 100644
--- a/crates/openhuman-core/src/memory/brain_tests.rs
+++ b/crates/openhuman-core/src/memory/brain_tests.rs
@@ -301,3 +301,49 @@ async fn an_ingest_queues_a_belief_build_only_for_an_engine_that_waits_for_one()
assert_eq!(pending, queued, "{consolidation:?}");
}
}
+
+#[test]
+fn legacy_nodes_map_to_their_connector() {
+ use tinymemory_api::{SourceKind, SourceRef};
+ let item = |kind: SourceKind, path: Option<&str>| {
+ let mut item = document(None, path);
+ item.meta_mut().source = SourceRef { kind, id: None };
+ item
+ };
+ let link = item(SourceKind::Link, None);
+ for old in [
+ "pdf", "markdown", "md", "docx", "xlsx", "pptx", "code", "other", "files",
+ ] {
+ assert_eq!(legacy_brain_node(old, &link), files_source(), "{old}");
+ }
+ // `web` held links and feeds, and HTML files that were filed beside them.
+ assert_eq!(legacy_brain_node("web", &link), BrainSource::Web);
+ assert_eq!(
+ legacy_brain_node("web", &item(SourceKind::Rss, None)),
+ BrainSource::Web
+ );
+ assert_eq!(
+ legacy_brain_node("web", &item(SourceKind::Folder, None)),
+ files_source()
+ );
+ assert_eq!(
+ legacy_brain_node("web", &item(SourceKind::File, None)),
+ files_source()
+ );
+ // An upload carried the `Link` kind `web` implies, but kept its path.
+ assert_eq!(
+ legacy_brain_node("web", &item(SourceKind::Link, Some("/u/pricing.html"))),
+ files_source()
+ );
+ // Connectors keep their node, under the slug Composio uses.
+ assert_eq!(legacy_brain_node("notion", &link), BrainSource::Notion);
+ assert_eq!(legacy_brain_node("github", &link), BrainSource::Github);
+ assert_eq!(
+ legacy_brain_node("gmail", &link),
+ BrainSource::Other("gmail".into())
+ );
+ assert_eq!(
+ legacy_brain_node("google_drive", &link),
+ BrainSource::Other("googledrive".into())
+ );
+}