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/flows/bus/run_digest.rs,crates/openhuman-core/src/flo

Steven Enamakelc7e0c38a69fe
diff --git a/crates/openhuman-core/src/flows/bus/run_digest.rs b/crates/openhuman-core/src/flows/bus/run_digest.rs
index ec9dc59ab0..b813fdaf85 100644
--- a/crates/openhuman-core/src/flows/bus/run_digest.rs
+++ b/crates/openhuman-core/src/flows/bus/run_digest.rs
@@ -7,10 +7,10 @@ use crate::config::Config;
use crate::core::events::DomainEvent;
use crate::flows::store;
use crate::memory::types::{ForgetParams, ItemsListParams, MAX_LIMIT};
-use tinymemory_api::{Error, Result};
use async_trait::async_trait;
use std::sync::Arc;
use tinybus::EventHandler;
+use tinymemory_api::{Error, Result};
use tinymemory_api::{ItemKind, MetaFilter, StoreItem};
use {crate::flows::flow_meta, crate::flows::flow_tag, tinyflows_catalog::FlowRun};
diff --git a/crates/openhuman-core/src/flows/memory_tools.rs b/crates/openhuman-core/src/flows/memory_tools.rs
index d687e93afe..7615b21fae 100644
--- a/crates/openhuman-core/src/flows/memory_tools.rs
+++ b/crates/openhuman-core/src/flows/memory_tools.rs
@@ -35,9 +35,9 @@ use tinytools::{PermissionLevel, Tool, ToolResult};
use crate::agent::turn_origin::{AgentTurnOrigin, TrustedAutomationSource};
use crate::config::Config;
use crate::memory::types::{LearnParams, RecallParams};
-use tinymemory_api::{Error, Result};
use crate::security::policy::ToolOperation;
use crate::security::SecurityPolicy;
+use tinymemory_api::{Error, Result};
/// Prefix of a flow's own tag (see [`flow_tag`]).
pub const FLOW_TAG_PREFIX: &str = "flow:";
@@ -135,9 +135,9 @@ pub fn flow_meta(flow_id: &str, extra: &[String]) -> MemoryMeta {
/// off forgets nothing.
pub async fn forget_matching(config: &Config, filter: MetaFilter) -> Result<usize> {
if filter.is_empty() {
- return Err(Error::InvalidRequest((
- "refusing to forget with an empty filter"
- ).into()));
+ return Err(Error::InvalidRequest(
+ ("refusing to forget with an empty filter").into(),
+ ));
}
let bound = match crate::memory::engine::resolve(config).engine() {
Ok(bound) => bound,
diff --git a/crates/openhuman-core/src/flows/tinyflows/memory_adapter.rs b/crates/openhuman-core/src/flows/tinyflows/memory_adapter.rs
index d2dcb9f5f3..74c182e4b0 100644
--- a/crates/openhuman-core/src/flows/tinyflows/memory_adapter.rs
+++ b/crates/openhuman-core/src/flows/tinyflows/memory_adapter.rs
@@ -47,13 +47,13 @@ use crate::flows::{
FLOWS_TAG,
};
use crate::memory::types::{FetchParams, RecallParams};
-use tinymemory_api::Error;
use crate::security::approval::{
redact_args, summarize_action, ApprovalGate, ExecutionOutcome, GateOutcome,
};
use crate::security::SecurityPolicy;
use tinybox_bus::CommandClass;
use tinymemory_api::wrap_untrusted_for_agent;
+use tinymemory_api::Error;
use tinymemory_api::{Hit, LearningKind, MemoryMeta, MetaFilter, SourceKind};
use super::caps::{enforce_node_tier_gate, gate_call_for_tier};
diff --git a/crates/openhuman-core/src/memory/backfill.rs b/crates/openhuman-core/src/memory/backfill.rs
index a03ff9dc23..567dda778f 100644
--- a/crates/openhuman-core/src/memory/backfill.rs
+++ b/crates/openhuman-core/src/memory/backfill.rs
@@ -38,9 +38,9 @@ use serde::{Deserialize, Serialize};
use crate::config::Config;
use crate::memory::engine::{self, BoundEngine};
-use tinymemory_api::{Error, Result};
use crate::memory::scope::{MemoryIdentity, ResolvedIdentity};
use crate::threads::store::blocking as threads;
+use tinymemory_api::{Error, Result};
use tinymemory_integrations::import::ImportPhase;
use tinymemory_tools::backfill::{first_live_turn, group_items, turn_groups, ThreadMessage};
@@ -216,9 +216,9 @@ pub async fn start(
params: BackfillStartParams,
) -> Result<BackfillView> {
if !params.consent {
- return Err(Error::InvalidRequest((
- "storing past chats uploads them to the selected engine; pass consent: true"
- ).into()));
+ return Err(Error::InvalidRequest(
+ ("storing past chats uploads them to the selected engine; pass consent: true").into(),
+ ));
}
let bound = engine::resolve(config).engine()?;
let workspace_dir = config.workspace_dir.clone();
@@ -299,11 +299,7 @@ async fn run(
} else {
tinymemory_api::WriteOptions::accepted()
};
- let stored = bound
- .engine
- .store_many_with(items, options)
- .await
- ;
+ let stored = bound.engine.store_many_with(items, options).await;
if let Err(error) = stored {
tracing::warn!(
code = error.code(),
diff --git a/crates/openhuman-core/src/memory/brain.rs b/crates/openhuman-core/src/memory/brain.rs
index 51beda6fa4..6c58b17c8a 100644
--- a/crates/openhuman-core/src/memory/brain.rs
+++ b/crates/openhuman-core/src/memory/brain.rs
@@ -20,9 +20,9 @@ use crate::config::schema::MemorySourceKind;
use crate::config::Config;
use super::engine;
-use tinymemory_api::{Error, Result};
use super::lifecycle::jobs;
use super::scope::MemoryIdentity;
+use tinymemory_api::{Error, Result};
/// Largest file `memory_brain_ingest` reads, in bytes.
pub const MAX_INGEST_BYTES: u64 = 25 * 1024 * 1024;
@@ -260,7 +260,11 @@ pub async fn ingest(
(None, Some(text)) => {
tinymemory_tools::BrainDocument::new(source.unwrap_or_else(files_source), text)
}
- _ => return Err(Error::InvalidRequest(("pass exactly one of `path` or `text`").into())),
+ _ => {
+ return Err(Error::InvalidRequest(
+ ("pass exactly one of `path` or `text`").into(),
+ ))
+ }
};
if let Some(title) = params.title.filter(|title| !title.trim().is_empty()) {
document = document.titled(title);
diff --git a/crates/openhuman-core/src/memory/confine.rs b/crates/openhuman-core/src/memory/confine.rs
index 432e68d090..949074431b 100644
--- a/crates/openhuman-core/src/memory/confine.rs
+++ b/crates/openhuman-core/src/memory/confine.rs
@@ -21,7 +21,6 @@ use tinymemory_api::{ExplorePage, MemoryMeta, MetaFilter, Namespace, Reach};
use crate::config::Config;
-use tinymemory_api::{Error, Result};
use super::explore::{self, ExploreParams, ItemsGetParams, ItemsGetView};
use super::ops;
use super::scope::MemoryIdentity;
@@ -29,6 +28,7 @@ use super::types::{
FetchParams, FetchView, ForgetParams, ForgetView, ItemsListParams, ItemsListView, LearnParams,
LearnView, RecallParams, RecallView,
};
+use tinymemory_api::{Error, Result};
/// What `identity` under `config` may read and forget: the subtree of its
/// layout root.
diff --git a/crates/openhuman-core/src/memory/engine_tests.rs b/crates/openhuman-core/src/memory/engine_tests.rs
index 05a6318448..2782417bff 100644
--- a/crates/openhuman-core/src/memory/engine_tests.rs
+++ b/crates/openhuman-core/src/memory/engine_tests.rs
@@ -421,10 +421,7 @@ fn a_disabled_memory_component_binds_no_engine() {
assert!(off_reason(resolve(&config)).contains("components"));
assert!(!is_on(&config));
assert!(switched_off(&config));
- assert!(matches!(
- bind_with_root(&config, None),
- Err(Error::Off(_))
- ));
+ assert!(matches!(bind_with_root(&config, None), Err(Error::Off(_))));
}
#[test]
diff --git a/crates/openhuman-core/src/memory/error.rs b/crates/openhuman-core/src/memory/error.rs
index 44dbd441db..d6b2770f4d 100644
--- a/crates/openhuman-core/src/memory/error.rs
+++ b/crates/openhuman-core/src/memory/error.rs
@@ -8,8 +8,9 @@ impl From<tinymemory_api::Error> for StructuredRpcError {
fn from(error: tinymemory_api::Error) -> Self {
let code = error.code();
let message = match error {
- tinymemory_api::Error::NotFound(message)
- | tinymemory_api::Error::Config(message) => format!("invalid request: {message}"),
+ tinymemory_api::Error::NotFound(message) | tinymemory_api::Error::Config(message) => {
+ format!("invalid request: {message}")
+ }
tinymemory_api::Error::Conflict(message) => format!("engine error: {message}"),
error => error.to_string(),
};
diff --git a/crates/openhuman-core/src/memory/error_tests.rs b/crates/openhuman-core/src/memory/error_tests.rs
index 8318b7bc8d..e52922da54 100644
--- a/crates/openhuman-core/src/memory/error_tests.rs
+++ b/crates/openhuman-core/src/memory/error_tests.rs
@@ -3,7 +3,12 @@ use tinymemory_api::Error as MemoryApiError;
#[test]
fn upstream_errors_keep_the_memory_rpc_wire_codes_and_messages() {
let cases = [
- (MemoryApiError::Off("sign in".into()), "MEMORY_OFF", "memory is off: sign in", true),
+ (
+ MemoryApiError::Off("sign in".into()),
+ "MEMORY_OFF",
+ "memory is off: sign in",
+ true,
+ ),
(
MemoryApiError::Unsupported("fetch".into()),
"UNSUPPORTED",
diff --git a/crates/openhuman-core/src/memory/import.rs b/crates/openhuman-core/src/memory/import.rs
index 1b2c1e5949..6aafd205d3 100644
--- a/crates/openhuman-core/src/memory/import.rs
+++ b/crates/openhuman-core/src/memory/import.rs
@@ -21,8 +21,8 @@ use crate::config::Config;
use crate::security::secret_storage::file_store::write_atomic;
use super::engine;
-use tinymemory_api::{Error, Result};
use super::types::{ImportCounts, ImportScanView};
+use tinymemory_api::{Error, Result};
/// Whether background work is paused right now. An automatic resume asks
/// before it starts and again before every batch it stores.
@@ -121,9 +121,7 @@ fn importer(
Arc::new(TokioPacer),
Arc::new(move || consent),
)
- .with_describe(Arc::new(|error| {
- error.to_string()
- }));
+ .with_describe(Arc::new(|error| error.to_string()));
if let Some(paused) = paused {
importer = importer.with_pause(paused);
}
@@ -315,11 +313,14 @@ async fn launch(
// Items written to the legacy tree while it is being moved would be
// left behind there.
if super::layout_migration::service::is_running(config) {
- return Err(Error::InvalidRequest((if mode == Mode::Import {
- "memory is being organized; import once that finishes"
- } else {
- "memory is being organized; retry once that finishes"
- }).into()));
+ return Err(Error::InvalidRequest(
+ (if mode == Mode::Import {
+ "memory is being organized; import once that finishes"
+ } else {
+ "memory is being organized; retry once that finishes"
+ })
+ .into(),
+ ));
}
RUNNING
.lock()
diff --git a/crates/openhuman-core/src/memory/layout_migration/app_host.rs b/crates/openhuman-core/src/memory/layout_migration/app_host.rs
index 9807ec1080..b7448a891b 100644
--- a/crates/openhuman-core/src/memory/layout_migration/app_host.rs
+++ b/crates/openhuman-core/src/memory/layout_migration/app_host.rs
@@ -12,8 +12,8 @@ use super::claim::ClaimKey;
use super::state::FileStateStore;
use crate::config::{Config, MemoryLayoutMode};
use crate::memory::engine::{self, CORTEXDB_ENGINE};
-use tinymemory_api::{Error, Result};
use crate::memory::scope::{self, MemoryIdentity};
+use tinymemory_api::{Error, Result};
/// The app's [`lm::LayoutHost`], bound to one account's config.
pub struct AppHost {
@@ -46,11 +46,8 @@ pub(super) fn to_module(error: Error) -> lm::Error {
Error::Unsupported(message) => EngineError::Unsupported(message).into(),
Error::Unauthorized(message) => EngineError::Unauthorized(message).into(),
Error::Unavailable(message) => EngineError::Unavailable(message).into(),
- // Temporarily mirrors the old adapter behavior; the focused regression
- // run will pin the typed-credit loss before this arm is corrected.
- Error::InsufficientCredits(message) | Error::Engine(message) => {
- EngineError::Engine(message).into()
- }
+ Error::InsufficientCredits(message) => EngineError::InsufficientCredits(message).into(),
+ Error::Engine(message) => EngineError::Engine(message).into(),
}
}
diff --git a/crates/openhuman-core/src/memory/layout_migration/state.rs b/crates/openhuman-core/src/memory/layout_migration/state.rs
index 66de4e7150..4c45af42e3 100644
--- a/crates/openhuman-core/src/memory/layout_migration/state.rs
+++ b/crates/openhuman-core/src/memory/layout_migration/state.rs
@@ -59,9 +59,8 @@ fn detail(error: Error) -> String {
pub fn load(workspace_dir: &Path) -> Result<MigrationState> {
let file = path(workspace_dir);
match std::fs::read(&file) {
- Ok(bytes) => serde_json::from_slice(&bytes).map_err(|error| {
- Error::Engine(format!("layout migration state unreadable: {error}"))
- }),
+ Ok(bytes) => serde_json::from_slice(&bytes)
+ .map_err(|error| Error::Engine(format!("layout migration state unreadable: {error}"))),
Err(error) if error.kind() == std::io::ErrorKind::NotFound => Ok(MigrationState::default()),
Err(error) => Err(Error::Engine(format!(
"layout migration state unreadable: {error}"
@@ -87,8 +86,7 @@ pub fn save(workspace_dir: &Path, state: &MigrationState) -> Result<()> {
out.sync_all()?;
std::fs::rename(&temp, &file)
};
- write()
- .map_err(|error| Error::Engine(format!("layout migration state not saved: {error}")))
+ write().map_err(|error| Error::Engine(format!("layout migration state not saved: {error}")))
}
#[cfg(test)]
diff --git a/crates/openhuman-core/src/memory/lifecycle/hooks.rs b/crates/openhuman-core/src/memory/lifecycle/hooks.rs
index 996b43c745..365e831dd8 100644
--- a/crates/openhuman-core/src/memory/lifecycle/hooks.rs
+++ b/crates/openhuman-core/src/memory/lifecycle/hooks.rs
@@ -16,8 +16,8 @@ use std::time::Duration;
use chrono::{DateTime, Utc};
use serde::Serialize;
use tinymemory_api::{Error, ToolCallRef, Turn};
-use tinymemory_tools::{Compaction, ContextPack, PostTurn, PreTurn, SessionStart};
use tinymemory_tools::recall::SkipReason;
+use tinymemory_tools::{Compaction, ContextPack, PostTurn, PreTurn, SessionStart};
use crate::config::Config;
use crate::memory::engine;
diff --git a/crates/openhuman-core/src/memory/lifecycle/hooks_tests.rs b/crates/openhuman-core/src/memory/lifecycle/hooks_tests.rs
index fa7373f52b..cb863f056d 100644
--- a/crates/openhuman-core/src/memory/lifecycle/hooks_tests.rs
+++ b/crates/openhuman-core/src/memory/lifecycle/hooks_tests.rs
@@ -100,10 +100,7 @@ fn typed_skip_reasons_expose_only_account_wide_errors() {
MemoryApiError::Engine("corrupt index".into()),
];
for error in local {
- assert_eq!(
- account_wide_skip_reason(&SkipReason::Engine(error)),
- None
- );
+ assert_eq!(account_wide_skip_reason(&SkipReason::Engine(error)), None);
}
assert_eq!(account_wide_skip_reason(&SkipReason::Empty), None);
}
@@ -334,10 +331,7 @@ async fn an_out_of_credits_recall_tells_the_turn_memory_is_unavailable() {
.await
.expect("a refused recall still gives the turn a notice");
- assert_eq!(
- pack.refusal,
- Some("INSUFFICIENT_CREDITS")
- );
+ assert_eq!(pack.refusal, Some("INSUFFICIENT_CREDITS"));
assert!(
pack.markdown.contains("out of credits"),
"{}",
diff --git a/crates/openhuman-core/src/memory/lifecycle/mod.rs b/crates/openhuman-core/src/memory/lifecycle/mod.rs
index dd999cd223..f8565d22f8 100644
--- a/crates/openhuman-core/src/memory/lifecycle/mod.rs
+++ b/crates/openhuman-core/src/memory/lifecycle/mod.rs
@@ -32,8 +32,8 @@ use crate::config::schema::MemoryRecallConfig;
use crate::config::Config;
use super::engine;
-use tinymemory_api::{Error, Result};
use super::scope::ResolvedIdentity;
+use tinymemory_api::{Error, Result};
/// TinyMemory's recall policy from `[memory.recall]`.
#[must_use]
diff --git a/crates/openhuman-core/src/memory/lifecycle/views.rs b/crates/openhuman-core/src/memory/lifecycle/views.rs
index cc20c9731a..574ea26e0b 100644
--- a/crates/openhuman-core/src/memory/lifecycle/views.rs
+++ b/crates/openhuman-core/src/memory/lifecycle/views.rs
@@ -7,8 +7,8 @@ use tinymemory_tools::{ContextPack, SessionStart};
use crate::config::schema::MemoryRecallConfig;
use crate::config::Config;
-use tinymemory_api::{Error, Result};
use crate::memory::scope::{self, MemoryIdentity};
+use tinymemory_api::{Error, Result};
use super::jobs;
use tinymemory_tools::queue::{JobRun, QueueState, Selection};
@@ -168,9 +168,9 @@ fn validate_build_delay_secs(value: Option<u64>) -> Result<Option<u64>> {
.and_then(|delay| chrono::Utc::now().checked_sub_signed(delay))
.is_none()
{
- return Err(Error::InvalidRequest((
- "build_delay_secs must fit within the supported date range"
- ).into()));
+ return Err(Error::InvalidRequest(
+ ("build_delay_secs must fit within the supported date range").into(),
+ ));
}
Ok(Some(seconds))
}
diff --git a/crates/openhuman-core/src/memory/ops.rs b/crates/openhuman-core/src/memory/ops.rs
index 912530d799..b5d4ef7646 100644
--- a/crates/openhuman-core/src/memory/ops.rs
+++ b/crates/openhuman-core/src/memory/ops.rs
@@ -18,12 +18,12 @@ use crate::config::Config;
use super::engine::{
self, Binding, BoundEngine, CORTEXDB_ENGINE, DISABLED_ENGINE, TINYHUMANS_ENGINE,
};
-use tinymemory_api::{Error, Result};
use super::types::{
clamp_limit, EngineSetParams, EngineStatus, EngineView, EnginesListView, EraseAllParams,
EraseAllView, FetchParams, FetchView, ForgetParams, ForgetView, ItemsListParams, ItemsListView,
LearnParams, LearnView, RecallParams, RecallView, RefersTo,
};
+use tinymemory_api::{Error, Result};
/// Default confidence of a learning stored without one.
pub const DEFAULT_LEARNING_CONFIDENCE: f32 = 0.8;
@@ -92,9 +92,9 @@ pub fn apply_engine_set(config: &mut Config, params: &EngineSetParams) -> Result
// Turning memory off keeps every engine's endpoint and key, so
// switching back needs no re-entry.
if params.endpoint.is_some() || params.api_key.is_some() {
- return Err(Error::InvalidRequest((
- "disabling memory takes no endpoint or API key"
- ).into()));
+ return Err(Error::InvalidRequest(
+ ("disabling memory takes no endpoint or API key").into(),
+ ));
}
config.memory.engine = DISABLED_ENGINE.to_string();
tracing::info!("[memory:ops] memory disabled");
@@ -129,11 +129,15 @@ pub fn apply_engine_set(config: &mut Config, params: &EngineSetParams) -> Result
}
CORTEXDB_ENGINE => engine::store_cortexdb_key(config, key)?,
TINYHUMANS_ENGINE => {
- return Err(Error::InvalidRequest((
- "the tinyhumans engine uses your sign-in, not an API key"
- ).into()))
+ return Err(Error::InvalidRequest(
+ ("the tinyhumans engine uses your sign-in, not an API key").into(),
+ ))
+ }
+ _ => {
+ return Err(Error::InvalidRequest(
+ ("this engine takes no API key").into(),
+ ))
}
- _ => return Err(Error::InvalidRequest(("this engine takes no API key").into())),
}
}
config.memory.engine = engine_id.to_string();
@@ -145,9 +149,9 @@ fn validate_endpoint(endpoint: &str) -> Result<()> {
let parsed = url::Url::parse(endpoint)
.map_err(|_| Error::InvalidRequest(("the endpoint is not a valid URL").into()))?;
if !matches!(parsed.scheme(), "http" | "https") || parsed.host_str().is_none() {
- return Err(Error::InvalidRequest((
- "the endpoint must be an http(s) URL with a host"
- ).into()));
+ return Err(Error::InvalidRequest(
+ ("the endpoint must be an http(s) URL with a host").into(),
+ ));
}
Ok(())
}
@@ -162,9 +166,7 @@ fn time_hint(config: &Config, refers_to: Option<RefersTo>) -> Result<Option<Time
let Some(RefersTo { from, to }) = refers_to else {
return Ok(None);
};
- TimeHint::new(from, to.unwrap_or(from), Some(config.time_zone()))
- .map(Some)
-
+ TimeHint::new(from, to.unwrap_or(from), Some(config.time_zone())).map(Some)
}
/// `memory_recall`.
@@ -254,13 +256,12 @@ pub async fn fetch_with(
/// Builds the learning `memory_learn` (and the `memory` tool's `learn`)
/// stores. `host_meta` wins over the caller's `meta` field by field, so a
/// caller cannot overwrite what the host knows (thread, agent, tool call).
-pub fn learning_item(
- params: LearnParams,
- host_meta: Option<MemoryMeta>,
-) -> Result<StoreItem> {
+pub fn learning_item(params: LearnParams, host_meta: Option<MemoryMeta>) -> Result<StoreItem> {
let confidence = params.confidence.unwrap_or(DEFAULT_LEARNING_CONFIDENCE);
if !(0.0..=1.0).contains(&confidence) {
- return Err(Error::InvalidRequest(("confidence must be between 0 and 1").into()));
+ return Err(Error::InvalidRequest(
+ ("confidence must be between 0 and 1").into(),
+ ));
}
let mut meta = params.meta.unwrap_or_default();
if let Some(host) = host_meta {
@@ -376,7 +377,9 @@ pub async fn forget(config: &Config, params: ForgetParams) -> Result<ForgetView>
.map(ItemId)
.collect();
if ids.is_empty() {
- return Err(Error::InvalidRequest(("forget needs at least one id").into()));
+ return Err(Error::InvalidRequest(
+ ("forget needs at least one id").into(),
+ ));
}
let bound = bound(config)?;
// A SaaS user forgets only what lies in their own tree.
@@ -421,9 +424,9 @@ pub async fn erase_all(
params: EraseAllParams,
) -> Result<EraseAllView> {
if !params.confirm {
- return Err(Error::InvalidRequest((
- "erasing all memory needs confirm: true; nothing erased comes back"
- ).into()));
+ return Err(Error::InvalidRequest(
+ ("erasing all memory needs confirm: true; nothing erased comes back").into(),
+ ));
}
let bound = bound(config)?;
// Earlier durable tool writes must finish or be discarded before the
diff --git a/crates/openhuman-core/src/memory/schemas/handlers.rs b/crates/openhuman-core/src/memory/schemas/handlers.rs
index 223f50f6b1..e8cb56b3a0 100644
--- a/crates/openhuman-core/src/memory/schemas/handlers.rs
+++ b/crates/openhuman-core/src/memory/schemas/handlers.rs
@@ -7,7 +7,6 @@ use crate::config::Config;
use crate::core::all::ControllerFuture;
use crate::core::runtime::DispatchCtx;
use crate::core::{Outcome, StructuredRpcError};
-use tinymemory_api::{Error, Result};
use crate::memory::explore::{ExploreParams, ItemsGetParams};
use crate::memory::lifecycle::views::{self, JobsRunParams, PackPreviewParams, PolicySetParams};
use crate::memory::scope::MemoryIdentity;
@@ -21,6 +20,7 @@ use crate::memory::{backfill, brain, confine, engine, import, layout_migration,
use serde::de::DeserializeOwned;
use serde::Serialize;
use serde_json::{json, Map, Value};
+use tinymemory_api::{Error, Result};
/// The operation run after the common request parsing and config load.
trait RpcOperation<P, R>: Send + 'static {
@@ -59,11 +59,9 @@ where
}
fn parse<T: DeserializeOwned>(params: Map<String, Value>) -> std::result::Result<T, String> {
- serde_json::from_value(Value::Object(params))
- .map_err(|error| {
- StructuredRpcError::from(Error::InvalidRequest(format!("invalid params: {error}")))
- .encode()
- })
+ serde_json::from_value(Value::Object(params)).map_err(|error| {
+ StructuredRpcError::from(Error::InvalidRequest(format!("invalid params: {error}"))).encode()
+ })
}
fn to_json<T: Serialize>(value: T) -> std::result::Result<Value, String> {
diff --git a/crates/openhuman-core/src/memory/schemas_tests.rs b/crates/openhuman-core/src/memory/schemas_tests.rs
index e6839633b7..0b38a2cf31 100644
--- a/crates/openhuman-core/src/memory/schemas_tests.rs
+++ b/crates/openhuman-core/src/memory/schemas_tests.rs
@@ -54,7 +54,11 @@ fn object(value: Value) -> Map<String, Value> {
/// Runs `function`'s handler against `config` (as the embedder-supplied
/// config, so no on-disk config is read).
-async fn call(config: &Config, function: &str, params: Value) -> std::result::Result<Value, String> {
+async fn call(
+ config: &Config,
+ function: &str,
+ params: Value,
+) -> std::result::Result<Value, String> {
let handler = handler_for(function).expect("test function has a handler");
let ctx = CoreContext::for_test_with_config(DomainSet::full(), config.clone());
CoreContext::scope(ctx.clone(), async move {
diff --git a/crates/openhuman-core/src/memory/sources/mod.rs b/crates/openhuman-core/src/memory/sources/mod.rs
index d92ff3e1fd..276c2912dc 100644
--- a/crates/openhuman-core/src/memory/sources/mod.rs
+++ b/crates/openhuman-core/src/memory/sources/mod.rs
@@ -16,8 +16,8 @@ use crate::config::schema::{MemorySourceConfig, MemorySourceKind};
use crate::config::Config;
use super::engine;
-use tinymemory_api::{Error, Result};
use super::types::{SourceView, SourcesAddParams};
+use tinymemory_api::{Error, Result};
pub use sync::{start_sync, sync_due, sync_one};
@@ -72,9 +72,9 @@ pub fn normalize_target(kind: MemorySourceKind, target: &str) -> Result<String>
(Some(owner), Some(repo), None) if !owner.is_empty() && !repo.is_empty() => {
Ok(format!("https://github.com/{owner}/{repo}"))
}
- _ => Err(Error::InvalidRequest((
- "a GitHub target is `owner/repo` or a repository URL"
- ).into())),
+ _ => Err(Error::InvalidRequest(
+ ("a GitHub target is `owner/repo` or a repository URL").into(),
+ )),
}
}
MemorySourceKind::Link | MemorySourceKind::Rss => http_url(target),
@@ -82,19 +82,19 @@ pub fn normalize_target(kind: MemorySourceKind, target: &str) -> Result<String>
}
fn http_url(target: &str) -> Result<String> {
- let url = url::Url::parse(target).map_err(|_| Error::InvalidRequest(("target is not a URL").into()))?;
+ let url = url::Url::parse(target)
+ .map_err(|_| Error::InvalidRequest(("target is not a URL").into()))?;
if !matches!(url.scheme(), "http" | "https") || url.host_str().is_none() {
- return Err(Error::InvalidRequest(("target must be an http(s) URL").into()));
+ return Err(Error::InvalidRequest(
+ ("target must be an http(s) URL").into(),
+ ));
}
Ok(url.to_string())
}
/// Builds a new source from `memory_sources_add` params and appends it to
/// `config`; the caller persists `config`.
-pub fn apply_add(
- config: &mut Config,
- params: &SourcesAddParams,
-) -> Result<MemorySourceConfig> {
+pub fn apply_add(config: &mut Config, params: &SourcesAddParams) -> Result<MemorySourceConfig> {
let kind = MemorySourceKind::parse(&params.kind).ok_or_else(|| {
Error::InvalidRequest(format!(
"unknown source kind `{}` (folder, file, link, github, rss)",
@@ -115,7 +115,9 @@ pub fn apply_add(
.iter()
.any(|source| source.kind == kind && source.target == target)
{
- return Err(Error::InvalidRequest(("that source is already added").into()));
+ return Err(Error::InvalidRequest(
+ ("that source is already added").into(),
+ ));
}
let label = params
.label
diff --git a/crates/openhuman-core/src/memory/sources/sync.rs b/crates/openhuman-core/src/memory/sources/sync.rs
index 4486cb8715..6c12344eb0 100644
--- a/crates/openhuman-core/src/memory/sources/sync.rs
+++ b/crates/openhuman-core/src/memory/sources/sync.rs
@@ -20,8 +20,8 @@ use tinymemory_integrations::sources::SourceKind;
use crate::config::schema::{MemorySourceConfig, MemorySourceKind};
use crate::config::Config;
use crate::memory::engine;
-use tinymemory_api::{Error, Result};
use crate::memory::types::SourceStatus;
+use tinymemory_api::{Error, Result};
use super::state;
@@ -46,9 +46,7 @@ fn registered(source: &MemorySourceConfig) -> RegisteredSource {
fn host_error(error: SyncError) -> Error {
match error {
SyncError::Invalid(message) => Error::InvalidRequest((message).into()),
- SyncError::Read(message) => {
- Error::Engine(format!("reading the source failed: {message}"))
- }
+ SyncError::Read(message) => Error::Engine(format!("reading the source failed: {message}")),
SyncError::Engine(error) => error,
}
}
diff --git a/crates/openhuman-core/src/memory/status.rs b/crates/openhuman-core/src/memory/status.rs
index cc429bd43a..ae238876c5 100644
--- a/crates/openhuman-core/src/memory/status.rs
+++ b/crates/openhuman-core/src/memory/status.rs
@@ -37,7 +37,9 @@ fn subsystem_status_for_engine(
let health = match status.health {
tinymemory_api::EngineStatusHealth::Ready => "ready",
tinymemory_api::EngineStatusHealth::Degraded => "degraded",
- tinymemory_api::EngineStatusHealth::Down | tinymemory_api::EngineStatusHealth::Off => "down",
+ tinymemory_api::EngineStatusHealth::Down | tinymemory_api::EngineStatusHealth::Off => {
+ "down"
+ }
};
SubsystemStatus {
slot: "memory".to_string(),
@@ -46,7 +48,11 @@ fn subsystem_status_for_engine(
health: health.to_string(),
health_reason: status.reason,
contract_version: status.contract_version.to_string(),
- capabilities: status.capabilities.into_iter().map(str::to_string).collect(),
+ capabilities: status
+ .capabilities
+ .into_iter()
+ .map(str::to_string)
+ .collect(),
fell_back_from: None,
last_error: None,
}
diff --git a/crates/openhuman-core/src/memory/tool_writes.rs b/crates/openhuman-core/src/memory/tool_writes.rs
index 031ff142ef..dcb4847659 100644
--- a/crates/openhuman-core/src/memory/tool_writes.rs
+++ b/crates/openhuman-core/src/memory/tool_writes.rs
@@ -26,10 +26,10 @@ use tinymemory_tools::pending::{
WriteGate, WriteOperation,
};
-use tinymemory_api::{Error, Result};
use super::tools::CallFacts;
use super::types::{ForgetParams, LearnParams};
use crate::config::Config;
+use tinymemory_api::{Error, Result};
const MAX_PENDING: usize = 256;
const MAX_BYTES: usize = 2 * 1024 * 1024;
@@ -148,9 +148,7 @@ fn queue_path(config: &Config, root: &Namespace) -> PathBuf {
}
fn unavailable() -> Error {
- Error::Unavailable(
- "memory write queue unavailable; durable queueing was not confirmed".into(),
- )
+ Error::Unavailable("memory write queue unavailable; durable queueing was not confirmed".into())
}
/// Accepts a validated, scrubbed write locally. The acknowledgement means only
@@ -180,9 +178,9 @@ pub(super) fn enqueue(
super::user_scope::clamp_item(&mut item, &root);
}
if !super::user_scope::within(&item.meta().namespace, &reach.at) || reach.inherit {
- return Err(Error::InvalidRequest((
- "learning namespace is outside the trusted reach"
- ).into()));
+ return Err(Error::InvalidRequest(
+ ("learning namespace is outside the trusted reach").into(),
+ ));
}
WriteOperation::Learn {
item: super::guard::scrub(item),
@@ -200,7 +198,9 @@ pub(super) fn enqueue(
ids.sort();
ids.dedup();
if ids.is_empty() {
- return Err(Error::InvalidRequest(("forget needs at least one id").into()));
+ return Err(Error::InvalidRequest(
+ ("forget needs at least one id").into(),
+ ));
}
WriteOperation::Forget { ids, reach }
}
diff --git a/crates/openhuman-core/src/memory/tools.rs b/crates/openhuman-core/src/memory/tools.rs
index 73aedac39a..39e7ab8bc5 100644
--- a/crates/openhuman-core/src/memory/tools.rs
+++ b/crates/openhuman-core/src/memory/tools.rs
@@ -32,10 +32,10 @@ use crate::core::bus::BUS;
use crate::core::events::DomainEvent;
use crate::core::runtime::DispatchCtx;
-use tinymemory_api::Error;
use super::ops;
pub use super::tool_budget::is_budget_refusal;
use super::types::{FetchParams, ForgetParams, LearnParams, RecallParams, RecallView};
+use tinymemory_api::Error;
/// How many matches one `fetch` returns; the model pages on with `cursor`.
const FETCH_TOP: usize = 5;
@@ -503,9 +503,7 @@ impl Tool for MemoryTool {
.await;
return Ok(
match queued.unwrap_or_else(|_| {
- Err(Error::Unavailable(
- "memory write queue unavailable".into(),
- ))
+ Err(Error::Unavailable("memory write queue unavailable".into()))
}) {
Ok(value) => {
super::tool_writes::schedule(&dispatch, self.config.clone(), &queued_root);
diff --git a/crates/openhuman-core/src/memory/user_scope.rs b/crates/openhuman-core/src/memory/user_scope.rs
index ac57635810..522137bf26 100644
--- a/crates/openhuman-core/src/memory/user_scope.rs
+++ b/crates/openhuman-core/src/memory/user_scope.rs
@@ -22,8 +22,8 @@
use tinymemory_api::{MetaFilter, Namespace, Reach, StoreItem};
-use tinymemory_api::{Error, Result};
use crate::config::Config;
+use tinymemory_api::{Error, Result};
/// The root `config`'s memory is confined to, in SaaS mode (`None` in single
/// user mode). A SaaS config without a valid root is refused: neither the
@@ -45,9 +45,9 @@ pub fn confinement_in(saas: bool, config: &Config) -> Result<Option<Namespace>>
root = raw,
"[memory:user_scope] no valid confinement root in SaaS mode"
);
- Err(Error::InvalidRequest((
- "memory is unavailable: this agent has no valid memory root"
- ).into()))
+ Err(Error::InvalidRequest(
+ ("memory is unavailable: this agent has no valid memory root").into(),
+ ))
}
}
}