Skip to main content

systemprompt_cli/session/
context.rs

1use systemprompt_cloud::CliSession;
2use systemprompt_identifiers::{AgentName, ContextId, SessionToken, TraceId};
3use systemprompt_models::execution::context::RequestContext;
4use systemprompt_models::Profile;
5
6#[derive(Debug)]
7pub struct CliSessionContext {
8    pub session: CliSession,
9    pub profile: Profile,
10}
11
12impl CliSessionContext {
13    pub const fn session_token(&self) -> &SessionToken {
14        &self.session.session_token
15    }
16
17    pub const fn context_id(&self) -> &ContextId {
18        &self.session.context_id
19    }
20
21    pub fn api_url(&self) -> &str {
22        &self.profile.server.api_external_url
23    }
24
25    pub fn to_request_context(&self, agent_name: &str) -> RequestContext {
26        RequestContext::new(
27            self.session.session_id.clone(),
28            TraceId::generate(),
29            self.session.context_id.clone(),
30            AgentName::new(agent_name.to_string()),
31        )
32        .with_user_id(self.session.user_id.clone())
33        .with_auth_token(self.session.session_token.as_str())
34        .with_user_type(self.session.user_type)
35    }
36}