systemprompt_models/artifacts/text/
mod.rs1use crate::artifacts::metadata::ExecutionMetadata;
2use crate::artifacts::traits::Artifact;
3use crate::artifacts::types::ArtifactType;
4use crate::execution::context::RequestContext;
5use schemars::JsonSchema;
6use serde::{Deserialize, Serialize};
7use serde_json::{json, Value as JsonValue};
8use systemprompt_identifiers::SkillId;
9
10fn default_artifact_type() -> String {
11 "text".to_string()
12}
13
14#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
15pub struct TextArtifact {
16 #[serde(rename = "x-artifact-type")]
17 #[serde(default = "default_artifact_type")]
18 pub artifact_type: String,
19 pub content: String,
20 #[serde(skip_serializing_if = "Option::is_none")]
21 pub title: Option<String>,
22 #[serde(skip)]
23 #[schemars(skip)]
24 metadata: ExecutionMetadata,
25}
26
27impl TextArtifact {
28 pub fn new(content: impl Into<String>, ctx: &RequestContext) -> Self {
29 Self {
30 artifact_type: "text".to_string(),
31 content: content.into(),
32 title: None,
33 metadata: ExecutionMetadata::with_request(ctx),
34 }
35 }
36
37 pub fn with_title(mut self, title: impl Into<String>) -> Self {
38 self.title = Some(title.into());
39 self
40 }
41
42 pub fn with_execution_id(mut self, id: impl Into<String>) -> Self {
43 self.metadata.execution_id = Some(id.into());
44 self
45 }
46
47 pub fn with_skill(
48 mut self,
49 skill_id: impl Into<SkillId>,
50 skill_name: impl Into<String>,
51 ) -> Self {
52 self.metadata.skill_id = Some(skill_id.into());
53 self.metadata.skill_name = Some(skill_name.into());
54 self
55 }
56}
57
58impl Artifact for TextArtifact {
59 fn artifact_type(&self) -> ArtifactType {
60 ArtifactType::Text
61 }
62
63 fn to_schema(&self) -> JsonValue {
64 json!({
65 "type": "object",
66 "properties": {
67 "content": {
68 "type": "string",
69 "description": "Text content"
70 },
71 "title": {
72 "type": "string",
73 "description": "Optional title for the text"
74 }
75 },
76 "required": ["content"],
77 "x-artifact-type": "text"
78 })
79 }
80}