Skip to main content

objectiveai_api/functions/profiles/
client.rs

1//! Profile client for listing and retrieving Profiles.
2
3use crate::ctx;
4use std::sync::Arc;
5
6/// Client for Profile operations.
7///
8/// Provides methods to list Profiles, retrieve Profile definitions,
9/// and get Profile usage statistics.
10pub struct Client<CTXEXT, PFN, RTRVL> {
11    /// Fetcher for Profile definitions.
12    pub profile_fetcher: Arc<PFN>,
13    /// Client for listing Profiles and getting usage statistics.
14    pub retrieval_client: Arc<RTRVL>,
15    /// Phantom data for context extension type.
16    pub _ctx_ext: std::marker::PhantomData<CTXEXT>,
17}
18
19impl<CTXEXT, PFN, RTRVL> Client<CTXEXT, PFN, RTRVL> {
20    /// Creates a new Profile client.
21    pub fn new(
22        profile_fetcher: Arc<PFN>,
23        retrieval_client: Arc<RTRVL>,
24    ) -> Self {
25        Self {
26            profile_fetcher,
27            retrieval_client,
28            _ctx_ext: std::marker::PhantomData,
29        }
30    }
31}
32
33impl<CTXEXT, PFN, RTRVL> Client<CTXEXT, PFN, RTRVL>
34where
35    CTXEXT: Send + Sync + 'static,
36    PFN: crate::functions::profile_fetcher::Fetcher<CTXEXT> + Send + Sync + 'static,
37    RTRVL: super::retrieval_client::Client<CTXEXT> + Send + Sync + 'static,
38{
39    /// Lists all available Profiles.
40    pub async fn list_profiles(
41        &self,
42        ctx: ctx::Context<CTXEXT>,
43    ) -> Result<
44        objectiveai::functions::profiles::response::ListProfile,
45        objectiveai::error::ResponseError,
46    > {
47        self.retrieval_client.list_profiles(ctx).await
48    }
49
50    /// Retrieves a Profile definition by owner/repository/commit.
51    pub async fn get_profile(
52        &self,
53        ctx: ctx::Context<CTXEXT>,
54        owner: &str,
55        repository: &str,
56        commit: Option<&str>,
57    ) -> Result<
58        objectiveai::functions::profiles::response::GetProfile,
59        objectiveai::error::ResponseError,
60    > {
61        self.profile_fetcher
62            .fetch(ctx, owner, repository, commit)
63            .await?
64            .ok_or_else(|| objectiveai::error::ResponseError {
65                code: 404,
66                message: serde_json::json!({
67                    "kind": "profiles",
68                    "error": "Profile not found"
69                }),
70            })
71    }
72
73    /// Retrieves usage statistics for a Profile.
74    pub async fn get_profile_usage(
75        &self,
76        ctx: ctx::Context<CTXEXT>,
77        owner: &str,
78        repository: &str,
79        commit: Option<&str>,
80    ) -> Result<
81        objectiveai::functions::profiles::response::UsageProfile,
82        objectiveai::error::ResponseError,
83    > {
84        self.retrieval_client
85            .get_profile_usage(ctx, owner, repository, commit)
86            .await
87    }
88}