Skip to main content

systemprompt_traits/
managed_resources.rs

1//! Runtime resolution of a skill through an installation's managed-resource
2//! authority.
3//!
4//! A skill key is either not managed at all (the caller may fall back to the
5//! disk catalogue), published (its retained content is returned), or managed
6//! but withheld — never adopted, withdrawn — in which case nothing is served
7//! for that key and the disk copy must not be used either. Corrupt retained
8//! content is an error, not a withholding.
9//!
10//! Copyright (c) systemprompt.io — Business Source License 1.1.
11//! See <https://systemprompt.io> for licensing details.
12
13use async_trait::async_trait;
14use std::sync::Arc;
15use systemprompt_identifiers::{SkillId, UserId};
16
17#[derive(Debug, Clone, PartialEq, Eq)]
18pub struct ResolvedManagedSkill {
19    pub id: SkillId,
20    pub name: String,
21    pub description: String,
22    pub instructions: String,
23}
24
25#[derive(Debug, Clone, Copy, PartialEq, Eq)]
26pub enum WithheldReason {
27    NeverAdopted,
28    NotGranted,
29    Withdrawn,
30}
31
32impl WithheldReason {
33    #[must_use]
34    pub const fn as_str(self) -> &'static str {
35        match self {
36            Self::NotGranted => "not granted",
37            Self::NeverAdopted => "never adopted",
38            Self::Withdrawn => "withdrawn",
39        }
40    }
41}
42
43#[derive(Debug, Clone, PartialEq, Eq)]
44pub enum SkillResolution {
45    NotManaged,
46    Published(ResolvedManagedSkill),
47    Withheld(WithheldReason),
48}
49
50#[derive(Debug, thiserror::Error)]
51pub enum ManagedSkillResolverError {
52    #[error("managed skill `{key}` failed integrity verification")]
53    Integrity { key: String },
54    #[error("managed skill resolver unavailable: {0}")]
55    Unavailable(String),
56}
57
58/// Held as `Arc<dyn ManagedSkillResolver>` so the agent runtime can use
59/// whichever authority the composition root wires in without depending on
60/// the marketplace domain; hence `#[async_trait]`.
61#[async_trait]
62pub trait ManagedSkillResolver: Send + Sync + std::fmt::Debug {
63    async fn resolve_skill(
64        &self,
65        owner: &UserId,
66        key: &str,
67    ) -> Result<SkillResolution, ManagedSkillResolverError>;
68}
69
70pub type DynManagedSkillResolver = Arc<dyn ManagedSkillResolver>;