Skip to content

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

feat(artifacts): producers mirror outputs into versioned artifact store (Phase 2d)

Sanil882786c19acc
diff --git a/crates/openhuman-core/src/media/generation/artifact_tool.rs b/crates/openhuman-core/src/media/generation/artifact_tool.rs
index 4cfcd5366e..cca843a236 100644
--- a/crates/openhuman-core/src/media/generation/artifact_tool.rs
+++ b/crates/openhuman-core/src/media/generation/artifact_tool.rs
@@ -39,6 +39,8 @@ use tinytools::{
use crate::agent::artifacts::{
create_artifact_for_call, fail_artifact, finalize_artifact, ArtifactKind,
};
+use crate::agent::artifacts::tiny_store::FsArtifactStore;
+use tiny_artifacts::{ArtifactRecord, ArtifactStore};
use crate::tools::host_extensions::tool_call_id;
/// Maximum characters of the prompt kept in a generated artifact's title.
@@ -168,6 +170,32 @@ impl<T: Tool> MediaArtifactTool<T> {
if let Some(obj) = entry.as_object_mut() {
obj.insert("artifact_id".into(), json!(updated.id));
}
+ // Phase 2d: mirror into the versioned artifact store
+ // (tiny-artifacts crate). Each generated file becomes
+ // a fresh versioned record – the shared model stores
+ // a workspace-path reference, not bytes. Best-effort:
+ // a failure here must not fail the filed artifact.
+ let versioned = FsArtifactStore::new(&self.workspace_dir);
+ let kind = match self.kind {
+ ArtifactKind::Image => tiny_artifacts::ArtifactKind::Image,
+ _ => tiny_artifacts::ArtifactKind::File,
+ };
+ let record = ArtifactRecord::new(
+ &updated.id,
+ &title,
+ kind,
+ dest.display().to_string(),
+ "agent",
+ tiny_artifacts::now_millis(),
+ );
+ if let Err(err) = versioned.upsert(&record).await {
+ tracing::warn!(
+ target: "media_generation",
+ err = %err,
+ artifact_id = %updated.id,
+ "[media_generation] failed to mirror artifact into versioned store"
+ );
+ }
}
Err(err) => {
let _ = fail_artifact(&self.workspace_dir, &self.files_dir, &meta.id, &err)
diff --git a/crates/openhuman-core/src/tools/impl/document/mod.rs b/crates/openhuman-core/src/tools/impl/document/mod.rs
index 3fddd85825..70a62731ad 100644
--- a/crates/openhuman-core/src/tools/impl/document/mod.rs
+++ b/crates/openhuman-core/src/tools/impl/document/mod.rs
@@ -33,8 +33,10 @@ use async_trait::async_trait;
use serde_json::{json, Value};
use crate::agent::artifacts::{create_artifact, fail_artifact, finalize_artifact, ArtifactKind};
+use crate::agent::artifacts::tiny_store::FsArtifactStore;
use crate::security::SecurityPolicy;
use tinytools::{PermissionLevel, Tool, ToolResult};
+use tiny_artifacts::{ArtifactAuthor, ArtifactRecord, ArtifactStore, ArtifactVersion};
mod engine;
/// The document wire contract, shared with the `tinydocs` module.
@@ -172,6 +174,10 @@ impl Tool for DocumentTool {
"description": "Optional author byline, rendered italic beneath the title.",
"maxLength": types::MAX_TEXT_CHARS,
},
+ "artifact_id": {
+ "type": "string",
+ "description": "Optional artifact id to update. Pass an id from a prior generate_document call to save this document as a new version of that artifact instead of creating a new one.",
+ },
"sections": {
"type": "array",
"minItems": 1,
@@ -194,7 +200,21 @@ impl Tool for DocumentTool {
}
async fn execute(&self, args: Value) -> anyhow::Result<ToolResult> {
- let input: GenerateDocumentInput = match serde_json::from_value(args.clone()) {
+ // The document wire contract is `deny_unknown_fields`, so the optional
+ // `artifact_id` is read here (and stripped from the args before
+ // deserialisation) rather than deserialised into
+ // `GenerateDocumentInput` (Phase 2d).
+ let artifact_id = args
+ .get("artifact_id")
+ .and_then(serde_json::Value::as_str)
+ .map(str::trim)
+ .filter(|s| !s.is_empty())
+ .map(str::to_string);
+ let mut spec_args = args.clone();
+ if let Some(obj) = spec_args.as_object_mut() {
+ obj.remove("artifact_id");
+ }
+ let input: GenerateDocumentInput = match serde_json::from_value(spec_args) {
Ok(v) => v,
Err(err) => {
let msg = format!("invalid generate_document arguments: {err}");
@@ -308,6 +328,83 @@ impl Tool for DocumentTool {
"[document] generation complete"
);
+ // Phase 2d: mirror the finished document into the versioned artifact
+ // store (tiny-artifacts crate). With an `artifact_id` arg the document
+ // is saved as a new version of that existing artifact, otherwise a
+ // fresh record is created. The body is the workspace path — the
+ // document is a binary file, and the shared model stores a reference,
+ // not bytes.
+ let versioned_store = FsArtifactStore::new(&self.workspace_dir);
+ let versioned_result = (|| async {
+ let body = output_path.display().to_string();
+ let now = tiny_artifacts::now_millis();
+ match &artifact_id {
+ Some(existing_id) => {
+ match versioned_store.get(existing_id).await? {
+ Some(mut record) => {
+ let v = ArtifactVersion::new(
+ 0,
+ body,
+ ArtifactAuthor::Agent,
+ "agent",
+ now,
+ );
+ record.push_version(v);
+ versioned_store.upsert(&record).await?;
+ tracing::info!(
+ target: "document",
+ artifact_id = existing_id,
+ "[document] versioned artifact updated"
+ );
+ }
+ None => {
+ let record = ArtifactRecord::new(
+ existing_id,
+ &input.title,
+ tiny_artifacts::ArtifactKind::File,
+ body,
+ "agent",
+ now,
+ );
+ versioned_store.upsert(&record).await?;
+ tracing::info!(
+ target: "document",
+ artifact_id = existing_id,
+ "[document] versioned artifact created from update target"
+ );
+ }
+ }
+ }
+ None => {
+ let record = ArtifactRecord::new(
+ &meta.id,
+ &input.title,
+ tiny_artifacts::ArtifactKind::File,
+ body,
+ "agent",
+ now,
+ );
+ versioned_store.upsert(&record).await?;
+ tracing::info!(
+ target: "document",
+ artifact_id = %meta.id,
+ "[document] versioned artifact created"
+ );
+ }
+ }
+ Ok::<(), anyhow::Error>(())
+ })()
+ .await;
+ if let Err(err) = versioned_result {
+ // The legacy meta.json flow already succeeded; a versioned-store
+ // write failure must not abort the reply.
+ tracing::warn!(
+ target: "document",
+ err = %err,
+ "[document] failed to mirror artifact into versioned store"
+ );
+ }
+
let out = GenerateDocumentOutput {
artifact_id: updated.id.clone(),
artifact_path: output_path.display().to_string(),
diff --git a/crates/openhuman-core/src/tools/impl/presentation/engine_tests.rs b/crates/openhuman-core/src/tools/impl/presentation/engine_tests.rs
index 801677185e..5d1e7761f0 100644
--- a/crates/openhuman-core/src/tools/impl/presentation/engine_tests.rs
+++ b/crates/openhuman-core/src/tools/impl/presentation/engine_tests.rs
@@ -25,6 +25,7 @@ fn slide(title: &str) -> SlideRequest {
fn input(slides: Vec<SlideRequest>) -> GeneratePresentationInput {
GeneratePresentationInput {
title: "Quarterly".to_string(),
+ artifact_id: None,
author: Some("Alice".to_string()),
theme: Some("plain".to_string()),
slides,
diff --git a/crates/openhuman-core/src/tools/impl/presentation/mod.rs b/crates/openhuman-core/src/tools/impl/presentation/mod.rs
index 605c49a360..ac641f0d80 100644
--- a/crates/openhuman-core/src/tools/impl/presentation/mod.rs
+++ b/crates/openhuman-core/src/tools/impl/presentation/mod.rs
@@ -37,6 +37,8 @@ use serde_json::{json, Value};
use crate::agent::artifacts::{
create_artifact, fail_artifact, finalize_artifact, read_artifact_bytes, ArtifactKind,
};
+use crate::agent::artifacts::tiny_store::FsArtifactStore;
+use tiny_artifacts::{ArtifactAuthor, ArtifactRecord, ArtifactStore, ArtifactVersion};
use crate::security::SecurityPolicy;
use tinytools::{PermissionLevel, Tool, ToolResult};
@@ -244,6 +246,10 @@ impl Tool for PresentationTool {
"description": "Deck title. Surfaced on the title slide and used as the artifact's human-readable name. Required, non-empty.",
"maxLength": types::MAX_TEXT_CHARS,
},
+ "artifact_id": {
+ "type": "string",
+ "description": "Optional artifact id to update. Pass an id from a prior generate_presentation call to save this deck as a new version of that artifact instead of creating a new one.",
+ },
"author": {
"type": "string",
"description": "Optional author byline shown on the title slide.",
@@ -410,6 +416,83 @@ impl Tool for PresentationTool {
"[presentation] generation complete"
);
+ // Phase 2d: mirror the finished deck into the versioned artifact
+ // store (tiny-artifacts crate). When the caller passed an
+ // `artifact_id`, the deck is saved as a new version of that existing
+ // artifact; otherwise a fresh record is created. The body is the
+ // workspace path — the deck is a binary file, and the shared model
+ // stores a reference, not bytes.
+ let versioned_store = FsArtifactStore::new(&self.workspace_dir);
+ let versioned_result = (|| async {
+ let body = output_path.display().to_string();
+ let now = tiny_artifacts::now_millis();
+ match &input.artifact_id {
+ Some(existing_id) => {
+ match versioned_store.get(existing_id).await? {
+ Some(mut record) => {
+ let v = ArtifactVersion::new(
+ 0,
+ body,
+ ArtifactAuthor::Agent,
+ "agent",
+ now,
+ );
+ record.push_version(v);
+ versioned_store.upsert(&record).await?;
+ tracing::info!(
+ target: "presentation",
+ artifact_id = existing_id,
+ "[presentation] versioned artifact updated"
+ );
+ }
+ None => {
+ let record = ArtifactRecord::new(
+ existing_id,
+ &input.title,
+ tiny_artifacts::ArtifactKind::File,
+ body,
+ "agent",
+ now,
+ );
+ versioned_store.upsert(&record).await?;
+ tracing::info!(
+ target: "presentation",
+ artifact_id = existing_id,
+ "[presentation] versioned artifact created from update target"
+ );
+ }
+ }
+ }
+ None => {
+ let record = ArtifactRecord::new(
+ &meta.id,
+ &input.title,
+ tiny_artifacts::ArtifactKind::File,
+ body,
+ "agent",
+ now,
+ );
+ versioned_store.upsert(&record).await?;
+ tracing::info!(
+ target: "presentation",
+ artifact_id = %meta.id,
+ "[presentation] versioned artifact created"
+ );
+ }
+ }
+ Ok::<(), anyhow::Error>(())
+ })()
+ .await;
+ if let Err(err) = versioned_result {
+ // The legacy meta.json flow already succeeded; a versioned-store
+ // write failure must not abort the reply.
+ tracing::warn!(
+ target: "presentation",
+ err = %err,
+ "[presentation] failed to mirror artifact into versioned store"
+ );
+ }
+
let out = GeneratePresentationOutput {
artifact_id: updated.id.clone(),
artifact_path: output_path.display().to_string(),
diff --git a/crates/openhuman-core/src/tools/impl/presentation/types.rs b/crates/openhuman-core/src/tools/impl/presentation/types.rs
index c886cee4d2..8a2f9d4b52 100644
--- a/crates/openhuman-core/src/tools/impl/presentation/types.rs
+++ b/crates/openhuman-core/src/tools/impl/presentation/types.rs
@@ -75,6 +75,11 @@ pub struct GeneratePresentationInput {
/// Deck title. Surfaces on the title slide and as the artifact's
/// human-readable name.
pub title: String,
+ /// Optional artifact id to update. Pass an artifact id from a prior
+ /// `generate_presentation` call to save this deck as a new version
+ /// of that artifact instead of creating a brand new one.
+ #[serde(default)]
+ pub artifact_id: Option<String>,
/// Optional author byline, surfaced on the title slide.
#[serde(default)]
pub author: Option<String>,