agent_first_http/sdk/fetch/artifacts/
content.rs1use 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}