Skip to main content

agent_first_http/sdk/fetch/artifacts/
content.rs

1//! Agent-oriented composed content artifacts.
2//!
3//! `content.md` is the primary human/LLM-readable projection, while
4//! `content.json` keeps links and page structure machine-readable.
5
6use std::path::PathBuf;
7
8use serde_json::Value;
9
10use crate::sdk::fetch::writer;
11use crate::shared::artifacts::{Artifact, ArtifactPaths};
12use crate::shared::error::{Error, ErrorCode};
13
14#[derive(Debug, Clone)]
15pub struct ContentCapture {
16    pub markdown: String,
17    pub json: Value,
18}
19
20pub async fn write_markdown(paths: &ArtifactPaths, markdown: &str) -> Result<PathBuf, Error> {
21    let target = paths.file_for(Artifact::Content);
22    writer::write_bytes(&target, markdown.as_bytes()).await?;
23    Ok(target)
24}
25
26pub async fn write_json(paths: &ArtifactPaths, json: &Value) -> Result<PathBuf, Error> {
27    let target = paths.file_for(Artifact::ContentJson);
28    let bytes = serde_json::to_vec_pretty(json).map_err(|e| {
29        Error::new(
30            ErrorCode::InternalError,
31            format!("serialize content json: {e}"),
32        )
33    })?;
34    writer::write_bytes(&target, &bytes).await?;
35    Ok(target)
36}