Skip to content

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

refactor(core): integrate file_store into legacy ui bridge

Steven Enamakelfb80367708e5
diff --git a/crates/openhuman-core/src/artifacts/tiny_store.rs b/crates/openhuman-core/src/artifacts/tiny_store.rs
index d8c11aa13c..1260e95723 100644
--- a/crates/openhuman-core/src/artifacts/tiny_store.rs
+++ b/crates/openhuman-core/src/artifacts/tiny_store.rs
@@ -30,7 +30,7 @@ use std::sync::Arc;
use async_trait::async_trait;
use tiny_artifacts::{
ArtifactEvent, ArtifactEventKind, ArtifactKind, ArtifactObserver, ArtifactRecord, Artifacts,
- Author, Content,
+ Author, Content, FileStore,
};
use super::files::FileRoots;
@@ -100,6 +100,7 @@ pub fn legacy_versioned_dir(workspace_dir: &Path) -> PathBuf {
pub struct LegacyUiBridge {
workspace_dir: PathBuf,
files: FileRoots,
+ file_store: Arc<dyn FileStore>,
chat: Option<ApprovalChatContext>,
}
@@ -109,11 +110,13 @@ impl LegacyUiBridge {
pub fn new(
workspace_dir: impl Into<PathBuf>,
files: FileRoots,
+ file_store: Arc<dyn FileStore>,
chat: Option<&ApprovalChatContext>,
) -> Self {
Self {
workspace_dir: workspace_dir.into(),
files,
+ file_store,
chat: chat.cloned(),
}
}
@@ -139,12 +142,9 @@ impl LegacyUiBridge {
== Some(ext.clone())
});
if let Some(owned) = owned {
- let source = Path::new(&file.path);
- let size = if same_file(owned, source) {
- tokio::fs::metadata(source).await?.len()
- } else {
- tokio::fs::copy(source, owned).await?
- };
+ let bytes = self.file_store.read(&file.key).await?;
+ tokio::fs::write(owned, &bytes).await?;
+ let size = bytes.len() as u64;
super::store::finalize_artifact(
&self.workspace_dir,
&record.id,
@@ -170,14 +170,17 @@ impl LegacyUiBridge {
.await
.map_err(anyhow::Error::msg)?;
let size = if record.holds_file() {
- let source = latest
- .file
- .as_ref()
- .map_or_else(|| PathBuf::from(&latest.body), |f| PathBuf::from(&f.path));
- if same_file(&source, &dest) {
- tokio::fs::metadata(&dest).await?.len()
+ if let Some(file) = latest.file.as_ref() {
+ let bytes = self.file_store.read(&file.key).await?;
+ tokio::fs::write(&dest, &bytes).await?;
+ bytes.len() as u64
} else {
- tokio::fs::copy(&source, &dest).await?
+ let source = PathBuf::from(&latest.body);
+ if same_file(&source, &dest) {
+ tokio::fs::metadata(&dest).await?.len()
+ } else {
+ tokio::fs::copy(&source, &dest).await?
+ }
}
} else {
tokio::fs::write(&dest, latest.body.as_bytes()).await?;
@@ -301,10 +304,22 @@ pub fn artifacts_service(
chat: Option<&ApprovalChatContext>,
) -> Artifacts {
let roots = file_roots(workspace_dir, &files, action_dir);
+ let scoped = crate::storage::sessions::artifact_scoped_for_in(
+ workspace_dir,
+ &crate::core::runtime::DispatchCtx::ambient(),
+ );
+ let file_store: Arc<dyn FileStore> = Arc::new(tiny_artifacts::BlobFileStore::new(
+ &scoped.expect("artifact storage scope is required"),
+ ));
Artifacts::new(Arc::new(versioned_store(workspace_dir)))
- .with_observer(Arc::new(LegacyUiBridge::new(workspace_dir, files, chat)))
+ .with_observer(Arc::new(LegacyUiBridge::new(
+ workspace_dir,
+ files,
+ file_store.clone(),
+ chat,
+ )))
.with_file_roots(guarded_roots(roots))
- .with_version_files(version_files_dir(workspace_dir))
+ .with_file_store(file_store)
}
/// Where each file version keeps its own copy: