systemprompt-models 0.64.0

Foundation data models for systemprompt.io AI governance infrastructure. Shared DTOs, config, and domain types consumed by every layer of the MCP governance pipeline.
Documentation
//! Request-context construction error types.
//!
//! Copyright (c) systemprompt.io — Business Source License 1.1.
//! See <https://systemprompt.io> for licensing details.

use systemprompt_identifiers::TaskId;
use systemprompt_traits::BoxedSource;
use thiserror::Error;

#[derive(Debug, Clone)]
pub enum ContextIdSource {
    Direct(String),
    FromTask { task_id: TaskId },
}

#[derive(Debug, Error)]
pub enum ContextExtractionError {
    #[error("Missing required header: {0}")]
    MissingHeader(String),

    #[error("Missing Authorization header")]
    MissingAuthHeader,

    #[error("Invalid JWT token: {0}")]
    InvalidToken(#[source] BoxedSource),

    #[error("Token revoked")]
    Revoked,

    #[error("JWT missing required 'session_id' claim")]
    MissingSessionId,

    #[error("JWT missing required 'sub' (user_id) claim")]
    MissingUserId,

    #[error(
        "Missing required 'x-context-id' header (for MCP routes) or contextId in body (for A2A \
         routes)"
    )]
    MissingContextId,

    #[error("Invalid header value: {header}, reason: {reason}")]
    InvalidHeaderValue { header: String, reason: String },

    #[error("Invalid user_id: {0}")]
    InvalidUserId(String),

    #[error("Database error: {context}: {source}")]
    DatabaseError {
        context: String,
        #[source]
        source: BoxedSource,
    },

    #[error("User not found: {0}")]
    UserNotFound(String),

    #[error("Forbidden header '{header}': {reason}")]
    ForbiddenHeader { header: String, reason: String },
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
pub enum RequestContextValidationError {
    #[error("Missing task_id for task execution")]
    MissingTaskId,

    #[error("Missing authentication token")]
    MissingAuthToken,

    #[error("User is not authenticated")]
    Unauthenticated,
}