Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

4.0 KB
Raw Blame
use chrono::Utc;
pub use item_filters::ast::agent_session::{AgentSessionSource, AgentSessionVisibility};
use model_owner::Owner;
use serde::{Deserialize, Serialize};
use uuid::Uuid;

/// Last synchronized state of a session's linked GitHub pull request.
#[derive(Serialize, Clone, Copy, Deserialize, Debug, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
#[cfg_attr(feature = "schema", derive(utoipa::ToSchema))]
pub enum AgentPullRequestState {
    /// The pull request accepts changes.
    Open,
    /// The pull request is still a draft.
    Draft,
    /// The pull request was closed without merging.
    Closed,
    /// The pull request was merged.
    Merged,
}

/// Who or what archived an agent session.
#[derive(
    Serialize, Clone, Copy, Deserialize, Debug, PartialEq, Eq, strum::EnumString, strum::AsRefStr,
)]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
#[cfg_attr(feature = "schema", derive(utoipa::ToSchema))]
pub enum AgentSessionArchiveCause {
    /// A person archived it.
    User,
    /// Every pull request linked to it closed, with at least one merged.
    PullRequestMerged,
    /// The runtime session backing it was deliberately closed.
    RuntimeClosed,
}

/// An agent session as displayed in Soup.
///
/// Includes the persisted runtime and repository metadata needed to render
/// coding and non-coding sessions without fetching each session separately.
#[derive(Serialize, Clone, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "schema", derive(utoipa::ToSchema))]
pub struct SoupAgentSession<T = ()> {
    /// The agent session uuid
    pub id: Uuid,

    /// The user-facing name of the session
    pub name: String,

    /// Who or what archived the session, or `None` while it is active. An archived session is
    /// read-only.
    pub archived_by: Option<AgentSessionArchiveCause>,

    /// When the session was archived, or `None` while it is active.
    pub archived_at: Option<chrono::DateTime<Utc>>,

    /// Who the session belongs to
    #[cfg_attr(feature = "schema", schema(value_type = String))]
    pub owner_id: Owner,

    /// The bot running this session
    pub bot_id: Uuid,

    /// The runtime snapshotted when the session was created.
    pub harness: String,

    /// The repository the session works with, when one was selected.
    pub repo_url: Option<String>,

    /// The starting branch selected for this session, not its current branch.
    pub repo_branch: Option<String>,

    /// The persisted pull request associated with the session.
    pub pull_request_url: Option<String>,

    /// Last captured working branch, when the runtime has reported one.
    pub working_branch: Option<String>,

    /// Last synchronized state of the linked pull request, when visible.
    pub pull_request_state: Option<AgentPullRequestState>,

    /// The linked pull request's Macro entity, when visible to the viewer.
    pub pull_request_id: Option<Uuid>,

    /// Last persisted fold turn state. Absent until an older session next runs.
    pub turn_state: Option<String>,

    /// The channel thread the session was opened from, when any
    #[serde(skip_serializing_if = "Option::is_none")]
    pub thread_id: Option<Uuid>,

    /// Who started the session
    #[serde(default)]
    pub source: AgentSessionSource,

    /// Where the session is shown
    #[serde(default)]
    pub visibility: AgentSessionVisibility,

    /// The session's last known status.
    ///
    /// `no_messages` until the first system event arrives, `disconnected` if
    /// the connection dropped without a clean close, otherwise the wire name
    /// of the most recent system event (for example `session/end`).
    pub status: String,

    /// The time the session was created
    pub created_at: chrono::DateTime<Utc>,

    /// The time the session was last modified
    pub updated_at: chrono::DateTime<Utc>,

    /// The time the session was last viewed by the requesting user
    pub viewed_at: Option<chrono::DateTime<Utc>>,

    /// Extra fields passed from above
    #[serde(flatten)]
    pub extra: T,
}