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