Skip to main content

systemprompt_models/artifacts/copy_paste_text/
mod.rs

1//! Copy-to-clipboard text artifact.
2//!
3//! A [`CopyPasteTextArtifact`] presents a block of text intended for one-click
4//! copying, with an optional title and language hint for syntax highlighting.
5//! It implements [`Artifact`].
6//!
7//! Copyright (c) systemprompt.io — Business Source License 1.1.
8//! See <https://systemprompt.io> for licensing details.
9
10use crate::artifacts::metadata::ArtifactProvenance;
11use crate::artifacts::traits::Artifact;
12use crate::artifacts::types::ArtifactType;
13use crate::execution::context::RequestContext;
14use schemars::JsonSchema;
15use serde::{Deserialize, Serialize};
16use serde_json::{Value as JsonValue, json};
17use systemprompt_identifiers::{McpExecutionId, SkillId, SkillName};
18
19fn default_artifact_type() -> String {
20    "copy_paste_text".to_owned()
21}
22
23#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
24pub struct CopyPasteTextArtifact {
25    #[serde(rename = "x-artifact-type")]
26    #[serde(default = "default_artifact_type")]
27    pub artifact_type: String,
28    pub content: String,
29    #[serde(skip_serializing_if = "Option::is_none")]
30    pub title: Option<String>,
31    #[serde(skip_serializing_if = "Option::is_none")]
32    pub language: Option<String>,
33    #[serde(skip)]
34    #[schemars(skip)]
35    metadata: ArtifactProvenance,
36}
37
38impl CopyPasteTextArtifact {
39    pub const ARTIFACT_TYPE_STR: &'static str = "copy_paste_text";
40
41    pub fn new(content: impl Into<String>) -> Self {
42        Self {
43            artifact_type: "copy_paste_text".to_owned(),
44            content: content.into(),
45            title: None,
46            language: None,
47            metadata: ArtifactProvenance::default(),
48        }
49    }
50
51    pub fn with_request(mut self, ctx: &RequestContext) -> Self {
52        self.metadata.set_request(ctx);
53        self
54    }
55
56    pub fn with_title(mut self, title: impl Into<String>) -> Self {
57        self.title = Some(title.into());
58        self
59    }
60
61    pub fn with_execution_id(mut self, id: McpExecutionId) -> Self {
62        self.metadata.set_execution_id(id);
63        self
64    }
65
66    pub fn with_skill(mut self, skill_id: SkillId, skill_name: SkillName) -> Self {
67        self.metadata.set_skill(skill_id, skill_name);
68        self
69    }
70}
71
72impl Artifact for CopyPasteTextArtifact {
73    fn artifact_type(&self) -> ArtifactType {
74        ArtifactType::CopyPasteText
75    }
76
77    // JSON: JSON Schema document describing the artifact for the model.
78    fn to_schema(&self) -> JsonValue {
79        json!({
80            "type": "object",
81            "properties": {
82                "content": {
83                    "type": "string",
84                    "description": "Text content to be copied"
85                },
86                "title": {
87                    "type": "string",
88                    "description": "Optional title for the content"
89                },
90                "language": {
91                    "type": "string",
92                    "description": "Optional language for syntax highlighting"
93                }
94            },
95            "required": ["content"],
96            "x-artifact-type": "copy_paste_text"
97        })
98    }
99}