Skip to content

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

refactor(storage): simplify storage schema definitions

Steven Enamakeldc0fb84755b0
diff --git a/crates/openhuman-core/src/config/schema/load/source/storage_schema.rs b/crates/openhuman-core/src/config/schema/load/source/storage_schema.rs
index b6f5304342..80329457d8 100644
--- a/crates/openhuman-core/src/config/schema/load/source/storage_schema.rs
+++ b/crates/openhuman-core/src/config/schema/load/source/storage_schema.rs
@@ -5,30 +5,17 @@
//! |---|---|---|
//! | `config` (id = the scope string) | `config.documents` (id `Key::of([scope])`) | rename; `toml_enc` (an encrypted value) is kept as is |
-use tinystoragedrivers::schema::{Schema, ScopeClass, SourceRecord, Step, TargetRecord};
-use tinystoragedrivers::{CollectionSpec, Result};
+use tinystoragedrivers::CollectionSpec;
-use crate::storage::schema_support::{key_of, owner};
+use crate::storage::schema_support::key_of;
/// The v2 collection holding one config document per scope.
pub(crate) const CONFIG_COLLECTION: &str = "config.documents";
/// The v1 name.
pub(crate) const LEGACY_CONFIG_COLLECTION: &str = "config";
-const SCHEMA: u32 = 2;
-
-/// What the config source keeps and the step from the v1 collection.
-#[must_use]
-pub fn storage_schema() -> Schema {
- Schema::new(owner("config"))
- .collection_with(
- SCHEMA,
- CollectionSpec::new(CONFIG_COLLECTION),
- ScopeClass::Tenant,
- )
- .step(
- Step::new("documents_v2", CONFIG_COLLECTION, 1, SCHEMA, documents_v2)
- .source(LEGACY_CONFIG_COLLECTION),
- )
+/// The config source's persisted collection declaration.
+pub(crate) fn collection_specs() -> Vec<CollectionSpec> {
+ vec![CollectionSpec::new(CONFIG_COLLECTION)]
}
/// The document id of the config of `scope`.
@@ -42,18 +29,6 @@ pub(crate) fn document_id(
key_of(scope)
}
-fn documents_v2(batch: Vec<SourceRecord>) -> Result<Vec<TargetRecord>> {
- batch
- .into_iter()
- .map(|record| {
- Ok(
- TargetRecord::new(CONFIG_COLLECTION, document_id(&record.id)?, record.body)
- .created_ms(record.meta.created_ms),
- )
- })
- .collect()
-}
-
#[cfg(test)]
#[path = "storage_schema_tests.rs"]
mod tests;
diff --git a/crates/openhuman-core/src/storage/agents.rs b/crates/openhuman-core/src/storage/agents.rs
index b4b4fb9e67..a1b5fcf71b 100644
--- a/crates/openhuman-core/src/storage/agents.rs
+++ b/crates/openhuman-core/src/storage/agents.rs
@@ -29,40 +29,17 @@ use std::future::Future;
use std::sync::{Arc, LazyLock, Mutex};
use serde_json::{json, Value};
-use tinystoragedrivers::schema::{Schema, ScopeClass, SourceRecord, Step, TargetRecord};
use tinystoragedrivers::{CollectionSpec, Precondition, Query, Scope};
-use super::schema_support::{key_of, owner};
+use super::schema_support::key_of;
use super::{block_on, installed, DocumentStoreExt, StorageBackend};
use crate::core::runtime::{AgentContextRegistry, CoreContext, DispatchCtx};
/// The `local`-scope collection recording which agents have their own scope.
pub(super) const AGENTS: &str = "agents.registry";
-/// The v1 name, `{}` per agent under the agent id.
-const LEGACY_AGENTS: &str = "storage_agents";
-
-/// What the agent registry keeps and the step from the v1 collection: the
-/// document id is `Key::of([agent id])` and the body names the agent, so a
-/// listing needs no unescaping.
-#[must_use]
-pub fn storage_schema() -> Schema {
- Schema::new(owner("agents"))
- .collection_with(2, CollectionSpec::new(AGENTS), ScopeClass::Tenant)
- .step(Step::new("registry_v2", AGENTS, 1, 2, registry_v2).source(LEGACY_AGENTS))
-}
-
-fn registry_v2(batch: Vec<SourceRecord>) -> tinystoragedrivers::Result<Vec<TargetRecord>> {
- batch
- .into_iter()
- .map(|record| {
- Ok(TargetRecord::new(
- AGENTS,
- key_of(&record.id)?,
- json!({ "agent_id": record.id }),
- )
- .created_ms(record.meta.created_ms))
- })
- .collect()
+/// Collections owned by the host's agent registry.
+pub(crate) fn collection_specs() -> Vec<CollectionSpec> {
+ vec![CollectionSpec::new(AGENTS)]
}
/// `(backend, agent id)` pairs this process has already recorded, the