greentic_types/
pack_manifest.rs

1//! Canonical pack manifest (.gtpack) representation embedding flows and components.
2
3use alloc::string::String;
4use alloc::vec::Vec;
5
6use semver::Version;
7
8use crate::{
9    ComponentManifest, Flow, FlowId, FlowKind, PackId, SecretRequirement, SemverReq, Signature,
10};
11
12#[cfg(feature = "schemars")]
13use schemars::JsonSchema;
14#[cfg(feature = "serde")]
15use serde::{Deserialize, Serialize};
16
17#[cfg(feature = "schemars")]
18fn empty_secret_requirements() -> Vec<SecretRequirement> {
19    Vec::new()
20}
21
22/// Hint describing the primary purpose of a pack.
23#[derive(Clone, Copy, Debug, PartialEq, Eq)]
24#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
25#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
26#[cfg_attr(feature = "schemars", derive(JsonSchema))]
27pub enum PackKind {
28    /// Application packs.
29    Application,
30    /// Provider packs exporting components.
31    Provider,
32    /// Infrastructure packs.
33    Infrastructure,
34    /// Library packs.
35    Library,
36}
37
38/// Pack manifest describing bundled flows and components.
39#[derive(Clone, Debug, PartialEq)]
40#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
41#[cfg_attr(
42    feature = "schemars",
43    derive(JsonSchema),
44    schemars(
45        title = "Greentic PackManifest v1",
46        description = "Canonical pack manifest embedding flows, components, dependencies and signatures.",
47        rename = "greentic.pack-manifest.v1"
48    )
49)]
50pub struct PackManifest {
51    /// Schema version for the pack manifest.
52    pub schema_version: String,
53    /// Logical pack identifier.
54    pub pack_id: PackId,
55    /// Pack semantic version.
56    #[cfg_attr(
57        feature = "schemars",
58        schemars(with = "String", description = "SemVer version")
59    )]
60    pub version: Version,
61    /// Pack kind hint.
62    pub kind: PackKind,
63    /// Pack publisher.
64    pub publisher: String,
65    /// Component descriptors bundled within the pack.
66    #[cfg_attr(feature = "serde", serde(default))]
67    pub components: Vec<ComponentManifest>,
68    /// Flow entries embedded in the pack.
69    #[cfg_attr(feature = "serde", serde(default))]
70    pub flows: Vec<PackFlowEntry>,
71    /// Pack dependencies.
72    #[cfg_attr(feature = "serde", serde(default))]
73    pub dependencies: Vec<PackDependency>,
74    /// Capability declarations for the pack.
75    #[cfg_attr(feature = "serde", serde(default))]
76    pub capabilities: Vec<ComponentCapability>,
77    /// Pack-level secret requirements.
78    #[cfg_attr(
79        feature = "serde",
80        serde(default, skip_serializing_if = "Vec::is_empty")
81    )]
82    #[cfg_attr(feature = "schemars", schemars(default = "empty_secret_requirements"))]
83    pub secret_requirements: Vec<SecretRequirement>,
84    /// Pack signatures.
85    #[cfg_attr(feature = "serde", serde(default))]
86    pub signatures: PackSignatures,
87}
88
89/// Flow entry embedded in a pack.
90#[derive(Clone, Debug, PartialEq)]
91#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
92#[cfg_attr(feature = "schemars", derive(JsonSchema))]
93pub struct PackFlowEntry {
94    /// Flow identifier.
95    pub id: FlowId,
96    /// Flow kind.
97    pub kind: FlowKind,
98    /// Flow definition.
99    pub flow: Flow,
100    /// Flow tags.
101    #[cfg_attr(feature = "serde", serde(default))]
102    pub tags: Vec<String>,
103    /// Additional entrypoint identifiers for discoverability.
104    #[cfg_attr(feature = "serde", serde(default))]
105    pub entrypoints: Vec<String>,
106}
107
108/// Dependency entry referencing another pack.
109#[derive(Clone, Debug, PartialEq, Eq)]
110#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
111#[cfg_attr(feature = "schemars", derive(JsonSchema))]
112pub struct PackDependency {
113    /// Local alias for the dependency.
114    pub alias: String,
115    /// Referenced pack identifier.
116    pub pack_id: PackId,
117    /// Required version.
118    pub version_req: SemverReq,
119    /// Required capabilities.
120    #[cfg_attr(feature = "serde", serde(default))]
121    pub required_capabilities: Vec<String>,
122}
123
124/// Named capability advertised by a pack or component collection.
125#[derive(Clone, Debug, PartialEq, Eq)]
126#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
127#[cfg_attr(feature = "schemars", derive(JsonSchema))]
128pub struct ComponentCapability {
129    /// Capability name.
130    pub name: String,
131    /// Optional description or metadata.
132    #[cfg_attr(
133        feature = "serde",
134        serde(default, skip_serializing_if = "Option::is_none")
135    )]
136    pub description: Option<String>,
137}
138
139/// Signature bundle accompanying a pack manifest.
140#[derive(Clone, Debug, PartialEq, Eq, Default)]
141#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
142#[cfg_attr(feature = "schemars", derive(JsonSchema))]
143pub struct PackSignatures {
144    /// Optional detached signatures.
145    #[cfg_attr(feature = "serde", serde(default))]
146    pub signatures: Vec<Signature>,
147}