Skip to content

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

chore(storage): remove unused storage module

Steven Enamakelf840c518bbb0
diff --git a/crates/openhuman-core/src/storage/mod.rs b/crates/openhuman-core/src/storage/mod.rs
index 1ff9cf94e8..cfcac17dec 100644
--- a/crates/openhuman-core/src/storage/mod.rs
+++ b/crates/openhuman-core/src/storage/mod.rs
@@ -115,34 +115,42 @@ pub fn clear() -> bool {
BACKEND.clear()
}
-/// The storage scope of the current call: the acting agent's
-/// ([`scope_for_agent`]) when the dispatch carries one
-/// (`CoreContext::session_agent`), else [`Scope::local`] — except in SaaS
-/// mode, where a call with no acting agent is refused rather than given a
-/// bucket every user would share.
+/// The storage scope of the current call: the tenant's profile
+/// ([`scope_for_profile`]) when the work runs for one, else the acting
+/// agent's ([`scope_for_agent`], `CoreContext::session_agent`), else
+/// [`Scope::local`] — except in SaaS mode, where only a profile scope is
+/// handed out: a call with no profile (or no task scope at all) is refused
+/// rather than given a bucket other users could share.
///
/// # Errors
///
-/// In SaaS mode, when the current context names no agent.
+/// In SaaS mode, when the current task serves no profile.
pub fn current_scope() -> Result<Scope, StorageError> {
- let agent = crate::core::runtime::CoreContext::current()
- .and_then(|context| context.session_agent().map(str::to_string));
- scope_from(agent.as_deref(), crate::core::runtime::mode::is_saas())
+ let saas = crate::core::runtime::mode::is_saas();
+ match crate::core::runtime::current_tenant() {
+ Ok(tenant) => scope_from(tenant.profile.as_deref(), tenant.agent.as_deref(), saas),
+ Err(no_tenant) => Err(StorageError::invalid_input(no_tenant.to_string())),
+ }
}
-/// [`current_scope`] with its two inputs made explicit, so the rule is
-/// testable without a booted context or a locked mode.
+/// [`current_scope`] with its inputs made explicit, so the rule is testable
+/// without a booted context or a locked mode.
///
/// # Errors
///
-/// When `saas` and there is no `agent`.
-pub fn scope_from(agent: Option<&str>, saas: bool) -> Result<Scope, StorageError> {
- match agent {
- Some(agent) => Ok(scope_for_agent(agent)),
- None if saas => Err(StorageError::invalid_input(
- "no acting agent in SaaS mode; refusing a shared storage scope",
+/// When `saas` and there is no `profile`.
+pub fn scope_from(
+ profile: Option<&str>,
+ agent: Option<&str>,
+ saas: bool,
+) -> Result<Scope, StorageError> {
+ match (profile, agent) {
+ (Some(profile), _) => Ok(scope_for_profile(profile)),
+ (None, _) if saas => Err(StorageError::invalid_input(
+ "no profile in SaaS mode; refusing a shared storage scope",
)),
- None => Ok(Scope::local()),
+ (None, Some(agent)) => Ok(scope_for_agent(agent)),
+ (None, None) => Ok(Scope::local()),
}
}
@@ -219,6 +227,23 @@ pub fn scope_for_agent(agent_id: &str) -> Scope {
tinyagents_session::DriverSessionStores::scope_for(agent_id)
}
+/// The storage scope profile `profile_id`'s records live under:
+/// `profile:<id>`, or `sha256:<hex of profile:<id>>` when that is not a valid
+/// scope (too long, whitespace, control characters). Injective: a literal
+/// scope always starts with `profile:`, a hashed one never does, and two
+/// distinct profiles never share either form.
+pub fn scope_for_profile(profile_id: &str) -> Scope {
+ const PREFIX: &str = "profile:";
+ let literal = format!("{PREFIX}{profile_id}");
+ if let Ok(scope) = Scope::new(&literal) {
+ return scope;
+ }
+ use sha2::Digest;
+ let digest = sha2::Sha256::digest(literal.as_bytes());
+ Scope::new(format!("sha256:{}", hex::encode(digest)))
+ .unwrap_or_else(|_| unreachable!("a sha256 hex scope is always valid"))
+}
+
#[cfg(test)]
#[path = "mod_tests.rs"]
mod tests;