Skip to content

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

refactor(artifacts): update artifact service initialization

Steven Enamakel1c182c80a4f8
diff --git a/crates/openhuman-core/src/artifacts/preview.rs b/crates/openhuman-core/src/artifacts/preview.rs
index f89f479ec9..dcc6295692 100644
--- a/crates/openhuman-core/src/artifacts/preview.rs
+++ b/crates/openhuman-core/src/artifacts/preview.rs
@@ -51,14 +51,13 @@ pub async fn read_body(
ctx: &crate::core::runtime::DispatchCtx,
) -> Result<ArtifactBody, String> {
let files = super::files::FileRoots::from_config(config);
- let artifacts = super::tiny_store::artifacts_service(
+ let (artifacts, file_store) = super::tiny_store::artifacts_service_with_file_store(
&config.workspace_dir,
files.clone(),
Some(&config.action_dir),
None,
ctx,
);
- let file_store = super::tiny_store::file_store_for(&config.workspace_dir, ctx);
let versioned = artifacts.get(id).await.map_err(|e| e.to_string())?;
let record = match versioned {
Some(record) => record,
diff --git a/crates/openhuman-core/src/artifacts/production.rs b/crates/openhuman-core/src/artifacts/production.rs
index dd44eedd96..c8e70992d5 100644
--- a/crates/openhuman-core/src/artifacts/production.rs
+++ b/crates/openhuman-core/src/artifacts/production.rs
@@ -22,7 +22,7 @@ use std::path::{Path, PathBuf};
use tiny_artifacts::{ArtifactKind, Artifacts, Author, Content};
use super::files::FileRoots;
-use super::tiny_store::{artifacts_service, legacy_kind_for_extension};
+use super::tiny_store::legacy_kind_for_extension;
use super::types::ArtifactKind as LegacyArtifactKind;
use crate::security::approval::ApprovalChatContext;
@@ -37,7 +37,6 @@ pub struct Production {
workspace_dir: PathBuf,
files: FileRoots,
chat: Option<ApprovalChatContext>,
- ctx: crate::core::runtime::DispatchCtx,
file_store: Option<std::sync::Arc<dyn tiny_artifacts::FileStore>>,
id: String,
path: PathBuf,
@@ -133,7 +132,6 @@ impl Production {
workspace_dir: workspace_dir.to_path_buf(),
files,
chat: chat.cloned(),
- ctx: ctx.clone(),
file_store,
id: meta.id.clone(),
path,
diff --git a/crates/openhuman-embed/src/host_internals.rs b/crates/openhuman-embed/src/host_internals.rs
index ba410d42c1..742811897e 100644
--- a/crates/openhuman-embed/src/host_internals.rs
+++ b/crates/openhuman-embed/src/host_internals.rs
@@ -293,8 +293,8 @@ pub mod tool_sources {
/// The artifact publisher slot: the service that shares an artifact version.
pub mod artifact_publisher {
pub use openhuman_core::artifacts::{
- ArtifactPublisherFactory, register_artifact_publisher, register_artifact_publisher_in,
- unregister_artifact_publisher,
+ ArtifactPublisherBinder, ArtifactPublisherFactory, register_artifact_publisher,
+ register_artifact_publisher_in, unregister_artifact_publisher,
};
// tinyhumans file-storage publisher: the protected-path guard it re-checks
// before upload, and the store its tests save artifacts into.
diff --git a/crates/openhuman-tinyhumans/src/integrations/file_storage/artifact_publisher_tests.rs b/crates/openhuman-tinyhumans/src/integrations/file_storage/artifact_publisher_tests.rs
index bddcf2a572..8f7b6da121 100644
--- a/crates/openhuman-tinyhumans/src/integrations/file_storage/artifact_publisher_tests.rs
+++ b/crates/openhuman-tinyhumans/src/integrations/file_storage/artifact_publisher_tests.rs
@@ -3,8 +3,12 @@ use std::sync::Arc;
use serde_json::json;
use tiny_artifacts::{
ArtifactKind, ArtifactPublisher, ArtifactRecord, ArtifactVersion, Artifacts, Author, Content,
- FileRef, PublishOptions,
+ FileMetadata, FileRef, FileStore, PublishOptions,
};
+use anyhow::{Result, bail};
+use async_trait::async_trait;
+use std::collections::HashMap;
+use std::sync::Mutex;
use wiremock::matchers::{body_string_contains, method, path};
use wiremock::{Mock, MockServer, ResponseTemplate};
@@ -12,13 +16,55 @@ use super::*;
use openhuman_embed::__host::artifact_publisher::versioned_store;
use openhuman_embed::__host::security::AutonomyLevel;
+#[derive(Default)]
+struct MemoryFileStore(Mutex<HashMap<String, (Vec<u8>, Option<String>)>>);
+
+impl MemoryFileStore {
+ fn add(&self, key: &str, bytes: &[u8], media_type: Option<&str>) {
+ self.0.lock().unwrap().insert(
+ key.to_string(),
+ (bytes.to_vec(), media_type.map(str::to_string)),
+ );
+ }
+}
+
+#[async_trait]
+impl FileStore for MemoryFileStore {
+ async fn put(&self, key: &str, bytes: &[u8], media_type: Option<&str>) -> Result<FileMetadata> {
+ self.add(key, bytes, media_type);
+ Ok(FileMetadata { size_bytes: bytes.len() as u64, media_type: media_type.map(str::to_string) })
+ }
+
+ async fn read(&self, key: &str) -> Result<Vec<u8>> {
+ self.0.lock().unwrap().get(key).map(|(bytes, _)| bytes.clone()).ok_or_else(|| anyhow::anyhow!("missing file key"))
+ }
+
+ async fn metadata(&self, key: &str) -> Result<Option<FileMetadata>> {
+ Ok(self.0.lock().unwrap().get(key).map(|(bytes, media_type)| FileMetadata { size_bytes: bytes.len() as u64, media_type: media_type.clone() }))
+ }
+
+ async fn delete_prefix(&self, prefix: &str) -> Result<()> {
+ self.0.lock().unwrap().retain(|key, _| !key.starts_with(prefix));
+ Ok(())
+ }
+}
+
fn publisher(server_uri: String, autonomy: AutonomyLevel) -> StorageArtifactPublisher {
+ publisher_with_files(server_uri, autonomy, Arc::new(MemoryFileStore::default()))
+}
+
+fn publisher_with_files(
+ server_uri: String,
+ autonomy: AutonomyLevel,
+ files: Arc<dyn FileStore>,
+) -> StorageArtifactPublisher {
StorageArtifactPublisher::new(
Arc::new(IntegrationClient::new(server_uri, "tok".to_string())),
Arc::new(SecurityPolicy {
autonomy,
..SecurityPolicy::default()
}),
+ files,
)
}
@@ -112,18 +158,17 @@ async fn a_public_file_share_uses_the_public_url_and_makes_no_link() {
.await;
mount_link(&server, 0).await;
- let dir = tempfile::tempdir().unwrap();
- let file = dir.path().join("chart.png");
- std::fs::write(&file, b"PNG-BYTES").unwrap();
+ let files = Arc::new(MemoryFileStore::default());
+ files.add("chart.png", b"PNG-BYTES", Some("image/png"));
let mut version = ArtifactVersion::new(
1,
- file.display().to_string(),
+ "chart.png",
tiny_artifacts::ArtifactAuthor::Agent,
"agent",
1,
);
version.file = Some(FileRef {
- path: file.display().to_string(),
+ key: "chart.png".into(),
size_bytes: 9,
media_type: Some("image/png".into()),
});
@@ -134,7 +179,7 @@ async fn a_public_file_share_uses_the_public_url_and_makes_no_link() {
public: true,
..PublishOptions::default()
};
- let link = publisher(server.uri(), AutonomyLevel::Full)
+ let link = publisher_with_files(server.uri(), AutonomyLevel::Full, files)
.publish(&record, &version, &options)
.await
.unwrap();
@@ -342,9 +387,8 @@ async fn a_server_failure_on_the_link_is_not_retried() {
#[tokio::test]
async fn a_file_in_a_protected_location_is_never_uploaded() {
let dir = tempfile::tempdir().unwrap();
- let ssh = dir.path().join(".ssh");
- std::fs::create_dir_all(&ssh).unwrap();
- let key = ssh.join("id_ed25519");
+ let key = dir.path().join(".ssh").join("id_ed25519");
+ std::fs::create_dir_all(key.parent().unwrap()).unwrap();
std::fs::write(&key, b"PRIVATE").unwrap();
let mut version = ArtifactVersion::new(
1,
@@ -354,14 +398,15 @@ async fn a_file_in_a_protected_location_is_never_uploaded() {
1,
);
version.file = Some(FileRef {
- path: key.display().to_string(),
+ key: key.display().to_string(),
size_bytes: 7,
media_type: None,
});
let mut record = ArtifactRecord::pending("k-1", "Key", ArtifactKind::File, 1);
record.versions.push(version.clone());
- // An unreachable backend: an upload attempt would fail differently.
+ // The opaque storage key is not interpreted as a host path. The supplied
+ // file store has no object at that key, so local secret bytes stay unread.
let err = publisher("http://127.0.0.1:9".into(), AutonomyLevel::Full)
.publish(&record, &version, &PublishOptions::default())
.await