Skip to content

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

refactor(artifacts): inject dispatch context into artifact operations

Steven Enamakelbc5ab3722948
diff --git a/crates/openhuman-core/src/artifacts/ops.rs b/crates/openhuman-core/src/artifacts/ops.rs
index 54215e3db8..d5ead9d3cc 100644
--- a/crates/openhuman-core/src/artifacts/ops.rs
+++ b/crates/openhuman-core/src/artifacts/ops.rs
@@ -31,6 +31,7 @@ const MAX_LIMIT: usize = 200;
///
/// Returns `{ "artifacts": [...], "total": N, "offset": M, "limit": L }`.
pub async fn ai_list_artifacts(
+ ctx: &crate::core::runtime::DispatchCtx,
config: &Config,
offset: Option<usize>,
limit: Option<usize>,
@@ -44,8 +45,14 @@ pub async fn ai_list_artifacts(
thread_id,
);
- let (artifacts, total) =
- store::list_artifacts(&config.workspace_dir, offset, limit, thread_id).await?;
+ let (artifacts, total) = ctx
+ .enter(store::list_artifacts(
+ &config.workspace_dir,
+ offset,
+ limit,
+ thread_id,
+ ))
+ .await?;
log::debug!(
"[artifacts] ai_list_artifacts: returning {} of {total} total",
@@ -65,7 +72,11 @@ pub async fn ai_list_artifacts(
///
/// Returns the serialized `ArtifactMeta` plus an `absolute_path` field
/// pointing to the full on-disk location of the artifact files.
-pub async fn ai_get_artifact(config: &Config, artifact_id: &str) -> Result<Outcome<Value>, String> {
+pub async fn ai_get_artifact(
+ ctx: &crate::core::runtime::DispatchCtx,
+ config: &Config,
+ artifact_id: &str,
+) -> Result<Outcome<Value>, String> {
log::debug!(
"[artifacts] ai_get_artifact: id={artifact_id} workspace={:?}",
config.workspace_dir
@@ -75,14 +86,18 @@ pub async fn ai_get_artifact(config: &Config, artifact_id: &str) -> Result<Outco
return Err("[artifacts] artifact_id must not be empty".to_string());
}
- let meta = store::get_artifact(&config.workspace_dir, artifact_id).await?;
+ let meta = ctx
+ .enter(store::get_artifact(&config.workspace_dir, artifact_id))
+ .await?;
// Resolve through the escape guard (#5505): a record's `file` must sit
// inside its recorded files folder, a legacy `meta.path` inside the
// artifacts root. A Ready record whose file was moved or deleted outside
// OpenHuman is an error rather than a path that points at nothing.
let roots = super::files::FileRoots::from_config(config);
- let resolved = super::files::resolve_file(&config.workspace_dir, &meta, &roots).await?;
+ let resolved = ctx
+ .enter(super::files::resolve_file(&config.workspace_dir, &meta, &roots))
+ .await?;
if matches!(meta.status, super::types::ArtifactStatus::Ready)
&& !tokio::fs::try_exists(&resolved).await.unwrap_or(false)
{
@@ -109,6 +124,7 @@ pub async fn ai_get_artifact(config: &Config, artifact_id: &str) -> Result<Outco
///
/// Returns `{ "artifact_id": "...", "deleted": true }`.
pub async fn ai_delete_artifact(
+ ctx: &crate::core::runtime::DispatchCtx,
config: &Config,
artifact_id: &str,
) -> Result<Outcome<Value>, String> {
@@ -121,11 +137,11 @@ pub async fn ai_delete_artifact(
return Err("[artifacts] artifact_id must not be empty".to_string());
}
- store::delete_artifact(
+ ctx.enter(store::delete_artifact(
&config.workspace_dir,
super::files::FileRoots::from_config(config),
artifact_id,
- )
+ ))
.await?;
log::debug!("[artifacts] ai_delete_artifact: deleted id={artifact_id}");
@@ -178,7 +194,9 @@ pub async fn ai_regenerate(
);
}
- let meta = store::get_artifact(&config.workspace_dir, artifact_id).await?;
+ let meta = ctx
+ .enter(store::get_artifact(&config.workspace_dir, artifact_id))
+ .await?;
if meta.kind != ArtifactKind::Presentation {
return Err(format!(
"[artifacts] regenerate is only supported for presentations (artifact id={artifact_id} is {})",
@@ -201,7 +219,9 @@ async fn regenerate_presentation(
thread_id: &str,
client_id: &str,
) -> Result<Outcome<Value>, String> {
- let args = store::read_artifact_args(&config.workspace_dir, artifact_id).await?;
+ let args = ctx
+ .enter(store::read_artifact_args(&config.workspace_dir, artifact_id))
+ .await?;
// A fresh policy from the live config — cheap, sync, and mirrors how
// the agent harness builds the same tool (see `tools::ops`).
diff --git a/crates/openhuman-core/src/artifacts/schemas.rs b/crates/openhuman-core/src/artifacts/schemas.rs
index fef41af9ff..649e94c7d8 100644
--- a/crates/openhuman-core/src/artifacts/schemas.rs
+++ b/crates/openhuman-core/src/artifacts/schemas.rs
@@ -429,8 +429,14 @@ fn handle_list_artifacts(ctx: DispatchCtx, params: Map<String, Value>) -> Contro
.transpose()?;
let thread_id = read_optional_string(&params, "thread_id")?;
to_json(
- crate::artifacts::ops::ai_list_artifacts(&config, offset, limit, thread_id.as_deref())
- .await?,
+ crate::artifacts::ops::ai_list_artifacts(
+ &ctx,
+ &config,
+ offset,
+ limit,
+ thread_id.as_deref(),
+ )
+ .await?,
)
})
}
@@ -439,7 +445,9 @@ fn handle_get_artifact(ctx: DispatchCtx, params: Map<String, Value>) -> Controll
Box::pin(async move {
let config = ctx.load_config().await?;
let artifact_id = read_required::<String>(&params, "artifact_id")?;
- to_json(crate::artifacts::ops::ai_get_artifact(&config, artifact_id.trim()).await?)
+ to_json(
+ crate::artifacts::ops::ai_get_artifact(&ctx, &config, artifact_id.trim()).await?,
+ )
})
}
@@ -503,7 +511,9 @@ fn handle_delete_artifact(ctx: DispatchCtx, params: Map<String, Value>) -> Contr
Box::pin(async move {
let config = ctx.load_config().await?;
let artifact_id = read_required::<String>(&params, "artifact_id")?;
- to_json(crate::artifacts::ops::ai_delete_artifact(&config, artifact_id.trim()).await?)
+ to_json(
+ crate::artifacts::ops::ai_delete_artifact(&ctx, &config, artifact_id.trim()).await?,
+ )
})
}