//! Context for /v1/responses endpoint handlers //! //! Bundles all dependencies needed by responses handlers to avoid passing //! 10+ parameters to every function (fixes clippy::too_many_arguments). use std::{collections::HashMap, sync::Arc}; use tokio::sync::RwLock; use super::types::BackgroundTaskInfo; use crate::{ core::WorkerRegistry, data_connector::{ConversationItemStorage, ConversationStorage, ResponseStorage}, mcp::McpManager, routers::grpc::{context::SharedComponents, pipeline::RequestPipeline}, }; /// Context for /v1/responses endpoint /// /// All fields are Arc/shared references, so cloning this context is cheap. #[derive(Clone)] pub struct ResponsesContext { /// Chat pipeline for executing requests pub pipeline: Arc, /// Shared components (tokenizer, parsers, worker_registry) pub components: Arc, /// Worker registry for validation pub worker_registry: Arc, /// Response storage backend pub response_storage: Arc, /// Conversation storage backend pub conversation_storage: Arc, /// Conversation item storage backend pub conversation_item_storage: Arc, /// MCP manager for tool support pub mcp_manager: Arc, /// Background task handles for cancellation support pub background_tasks: Arc>>, } impl ResponsesContext { /// Create a new responses context pub fn new( pipeline: Arc, components: Arc, worker_registry: Arc, response_storage: Arc, conversation_storage: Arc, conversation_item_storage: Arc, mcp_manager: Arc, ) -> Self { Self { pipeline, components, worker_registry, response_storage, conversation_storage, conversation_item_storage, mcp_manager, background_tasks: Arc::new(RwLock::new(HashMap::new())), } } }