mirror of
https://github.com/openai/codex.git
synced 2026-12-01 00:20:48 +00:00
Simplify client compatibility state
This commit is contained in:
@@ -189,6 +189,7 @@ pub(crate) struct InitializedConnectionSessionState {
|
||||
pub(crate) opted_out_notification_methods: HashSet<String>,
|
||||
pub(crate) app_server_client_name: String,
|
||||
pub(crate) client_version: String,
|
||||
pub(crate) client_compatibility_flags: ClientCompatibilityFlags,
|
||||
}
|
||||
|
||||
fn client_compatibility_flags_for_app_server_client(
|
||||
@@ -216,6 +217,27 @@ impl Default for ConnectionSessionState {
|
||||
}
|
||||
}
|
||||
|
||||
impl InitializedConnectionSessionState {
|
||||
pub(crate) fn new(
|
||||
experimental_api_enabled: bool,
|
||||
opted_out_notification_methods: HashSet<String>,
|
||||
app_server_client_name: String,
|
||||
client_version: String,
|
||||
) -> Self {
|
||||
let client_compatibility_flags = client_compatibility_flags_for_app_server_client(
|
||||
&app_server_client_name,
|
||||
&client_version,
|
||||
);
|
||||
Self {
|
||||
experimental_api_enabled,
|
||||
opted_out_notification_methods,
|
||||
app_server_client_name,
|
||||
client_version,
|
||||
client_compatibility_flags,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ConnectionSessionState {
|
||||
pub(crate) fn new(origin: ConnectionOrigin) -> Self {
|
||||
Self {
|
||||
@@ -261,12 +283,7 @@ impl ConnectionSessionState {
|
||||
pub(crate) fn client_compatibility_flags(&self) -> ClientCompatibilityFlags {
|
||||
self.initialized
|
||||
.get()
|
||||
.map(|session| {
|
||||
client_compatibility_flags_for_app_server_client(
|
||||
&session.app_server_client_name,
|
||||
&session.client_version,
|
||||
)
|
||||
})
|
||||
.map(|session| session.client_compatibility_flags)
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
@@ -789,12 +806,10 @@ impl MessageProcessor {
|
||||
);
|
||||
|
||||
let serialization_scope = codex_request.serialization_scope();
|
||||
let app_server_client_name = session.app_server_client_name().map(str::to_string);
|
||||
let client_version = session.client_version().map(str::to_string);
|
||||
let client_compatibility_flags = session.client_compatibility_flags();
|
||||
let device_key_requests_allowed = session.allows_device_key_requests();
|
||||
let error_request_id = connection_request_id.clone();
|
||||
let rpc_gate = Arc::clone(&session.rpc_gate);
|
||||
let client_session = Arc::clone(&session);
|
||||
let processor = Arc::clone(self);
|
||||
let span = request_context.span();
|
||||
let request = QueuedInitializedRequest::new(
|
||||
@@ -806,9 +821,7 @@ impl MessageProcessor {
|
||||
connection_request_id,
|
||||
codex_request,
|
||||
request_context,
|
||||
app_server_client_name,
|
||||
client_version,
|
||||
client_compatibility_flags,
|
||||
client_session,
|
||||
device_key_requests_allowed,
|
||||
)
|
||||
.await;
|
||||
@@ -832,15 +845,12 @@ impl MessageProcessor {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
async fn handle_initialized_client_request(
|
||||
self: Arc<Self>,
|
||||
connection_request_id: ConnectionRequestId,
|
||||
codex_request: ClientRequest,
|
||||
request_context: RequestContext,
|
||||
app_server_client_name: Option<String>,
|
||||
client_version: Option<String>,
|
||||
client_compatibility_flags: ClientCompatibilityFlags,
|
||||
client_session: Arc<ConnectionSessionState>,
|
||||
device_key_requests_allowed: bool,
|
||||
) -> Result<(), JSONRPCErrorError> {
|
||||
let connection_id = connection_request_id.connection_id;
|
||||
@@ -848,7 +858,6 @@ impl MessageProcessor {
|
||||
connection_id,
|
||||
request_id: codex_request.id().clone(),
|
||||
};
|
||||
|
||||
let result: Result<Option<ClientResponsePayload>, JSONRPCErrorError> = match codex_request {
|
||||
ClientRequest::Initialize { .. } => {
|
||||
panic!("Initialize should be handled before initialized request dispatch");
|
||||
@@ -963,9 +972,7 @@ impl MessageProcessor {
|
||||
.thread_start(
|
||||
request_id.clone(),
|
||||
params,
|
||||
app_server_client_name.clone(),
|
||||
client_version.clone(),
|
||||
client_compatibility_flags,
|
||||
client_session.as_ref(),
|
||||
request_context,
|
||||
)
|
||||
.await
|
||||
@@ -977,12 +984,12 @@ impl MessageProcessor {
|
||||
}
|
||||
ClientRequest::ThreadResume { params, .. } => {
|
||||
self.thread_processor
|
||||
.thread_resume(request_id.clone(), params, client_compatibility_flags)
|
||||
.thread_resume(request_id.clone(), params, client_session.as_ref())
|
||||
.await
|
||||
}
|
||||
ClientRequest::ThreadFork { params, .. } => {
|
||||
self.thread_processor
|
||||
.thread_fork(request_id.clone(), params, client_compatibility_flags)
|
||||
.thread_fork(request_id.clone(), params, client_session.as_ref())
|
||||
.await
|
||||
}
|
||||
ClientRequest::ThreadArchive { params, .. } => {
|
||||
@@ -1133,13 +1140,7 @@ impl MessageProcessor {
|
||||
}
|
||||
ClientRequest::TurnStart { params, .. } => {
|
||||
self.turn_processor
|
||||
.turn_start(
|
||||
request_id.clone(),
|
||||
params,
|
||||
app_server_client_name.clone(),
|
||||
client_version.clone(),
|
||||
client_compatibility_flags,
|
||||
)
|
||||
.turn_start(request_id.clone(), params, client_session.as_ref())
|
||||
.await
|
||||
}
|
||||
ClientRequest::ThreadInjectItems { params, .. } => {
|
||||
@@ -1178,13 +1179,7 @@ impl MessageProcessor {
|
||||
}
|
||||
ClientRequest::ReviewStart { params, .. } => {
|
||||
self.turn_processor
|
||||
.review_start(
|
||||
&request_id,
|
||||
params,
|
||||
app_server_client_name.clone(),
|
||||
client_version.clone(),
|
||||
client_compatibility_flags,
|
||||
)
|
||||
.review_start(&request_id, params, client_session.as_ref())
|
||||
.await
|
||||
}
|
||||
ClientRequest::McpServerOauthLogin { params, .. } => {
|
||||
@@ -1195,29 +1190,17 @@ impl MessageProcessor {
|
||||
}
|
||||
ClientRequest::McpServerStatusList { params, .. } => {
|
||||
self.mcp_processor
|
||||
.mcp_server_status_list(&request_id, params, client_compatibility_flags)
|
||||
.mcp_server_status_list(&request_id, params, client_session.as_ref())
|
||||
.await
|
||||
}
|
||||
ClientRequest::McpResourceRead { params, .. } => {
|
||||
self.mcp_processor
|
||||
.mcp_resource_read(
|
||||
&request_id,
|
||||
params,
|
||||
app_server_client_name.clone(),
|
||||
client_version.clone(),
|
||||
client_compatibility_flags,
|
||||
)
|
||||
.mcp_resource_read(&request_id, params, client_session.as_ref())
|
||||
.await
|
||||
}
|
||||
ClientRequest::McpServerToolCall { params, .. } => {
|
||||
self.mcp_processor
|
||||
.mcp_server_tool_call(
|
||||
&request_id,
|
||||
params,
|
||||
app_server_client_name.clone(),
|
||||
client_version.clone(),
|
||||
client_compatibility_flags,
|
||||
)
|
||||
.mcp_server_tool_call(&request_id, params)
|
||||
.await
|
||||
}
|
||||
ClientRequest::WindowsSandboxSetupStart { params, .. } => {
|
||||
|
||||
@@ -461,6 +461,7 @@ use crate::error_code::internal_error;
|
||||
use crate::error_code::invalid_request;
|
||||
use crate::filters::compute_source_filters;
|
||||
use crate::filters::source_kind_matches;
|
||||
use crate::message_processor::ConnectionSessionState;
|
||||
use crate::thread_state::ThreadListenerCommand;
|
||||
use crate::thread_state::ThreadState;
|
||||
use crate::thread_state::ThreadStateManager;
|
||||
@@ -483,6 +484,10 @@ pub(crate) use self::thread_summary::read_rollout_items_from_rollout;
|
||||
pub(crate) use self::thread_summary::read_summary_from_rollout;
|
||||
pub(crate) use self::thread_summary::summary_to_thread;
|
||||
|
||||
fn apply_client_compatibility(config: &mut Config, session: &ConnectionSessionState) {
|
||||
config.client_compatibility_flags = session.client_compatibility_flags();
|
||||
}
|
||||
|
||||
pub(crate) fn build_api_turns_from_rollout_items(items: &[RolloutItem]) -> Vec<Turn> {
|
||||
let mut builder = ThreadHistoryBuilder::new();
|
||||
for item in items {
|
||||
|
||||
@@ -90,12 +90,12 @@ impl InitializeRequestProcessor {
|
||||
let user_agent_suffix = format!("{name}; {version}");
|
||||
let codex_home = self.config.codex_home.clone();
|
||||
if session
|
||||
.initialize(InitializedConnectionSessionState {
|
||||
.initialize(InitializedConnectionSessionState::new(
|
||||
experimental_api_enabled,
|
||||
opted_out_notification_methods: opt_out_notification_methods.into_iter().collect(),
|
||||
app_server_client_name: name.clone(),
|
||||
client_version: version,
|
||||
})
|
||||
opt_out_notification_methods.into_iter().collect(),
|
||||
name.clone(),
|
||||
version,
|
||||
))
|
||||
.is_err()
|
||||
{
|
||||
return Err(invalid_request("Already initialized"));
|
||||
|
||||
@@ -47,9 +47,9 @@ impl McpRequestProcessor {
|
||||
&self,
|
||||
request_id: &ConnectionRequestId,
|
||||
params: ListMcpServerStatusParams,
|
||||
client_compatibility_flags: ClientCompatibilityFlags,
|
||||
client_session: &ConnectionSessionState,
|
||||
) -> Result<Option<ClientResponsePayload>, JSONRPCErrorError> {
|
||||
self.list_mcp_server_status(request_id, params, client_compatibility_flags)
|
||||
self.list_mcp_server_status(request_id, params, client_session)
|
||||
.await
|
||||
.map(|()| None)
|
||||
}
|
||||
@@ -58,38 +58,21 @@ impl McpRequestProcessor {
|
||||
&self,
|
||||
request_id: &ConnectionRequestId,
|
||||
params: McpResourceReadParams,
|
||||
app_server_client_name: Option<String>,
|
||||
app_server_client_version: Option<String>,
|
||||
client_compatibility_flags: ClientCompatibilityFlags,
|
||||
client_session: &ConnectionSessionState,
|
||||
) -> Result<Option<ClientResponsePayload>, JSONRPCErrorError> {
|
||||
self.read_mcp_resource(
|
||||
request_id,
|
||||
params,
|
||||
app_server_client_name,
|
||||
app_server_client_version,
|
||||
client_compatibility_flags,
|
||||
)
|
||||
.await
|
||||
.map(|()| None)
|
||||
self.read_mcp_resource(request_id, params, client_session)
|
||||
.await
|
||||
.map(|()| None)
|
||||
}
|
||||
|
||||
pub(crate) async fn mcp_server_tool_call(
|
||||
&self,
|
||||
request_id: &ConnectionRequestId,
|
||||
params: McpServerToolCallParams,
|
||||
app_server_client_name: Option<String>,
|
||||
app_server_client_version: Option<String>,
|
||||
client_compatibility_flags: ClientCompatibilityFlags,
|
||||
) -> Result<Option<ClientResponsePayload>, JSONRPCErrorError> {
|
||||
self.call_mcp_server_tool(
|
||||
request_id,
|
||||
params,
|
||||
app_server_client_name,
|
||||
app_server_client_version,
|
||||
client_compatibility_flags,
|
||||
)
|
||||
.await
|
||||
.map(|()| None)
|
||||
self.call_mcp_server_tool(request_id, params)
|
||||
.await
|
||||
.map(|()| None)
|
||||
}
|
||||
|
||||
async fn mcp_server_refresh_response(
|
||||
@@ -267,9 +250,10 @@ impl McpRequestProcessor {
|
||||
&self,
|
||||
request_id: &ConnectionRequestId,
|
||||
params: ListMcpServerStatusParams,
|
||||
client_compatibility_flags: ClientCompatibilityFlags,
|
||||
client_session: &ConnectionSessionState,
|
||||
) -> Result<(), JSONRPCErrorError> {
|
||||
let request = request_id.clone();
|
||||
let client_compatibility_flags = client_session.client_compatibility_flags();
|
||||
|
||||
let outgoing = Arc::clone(&self.outgoing);
|
||||
let config = self.load_latest_config(/*fallback_cwd*/ None).await?;
|
||||
@@ -400,11 +384,10 @@ impl McpRequestProcessor {
|
||||
&self,
|
||||
request_id: &ConnectionRequestId,
|
||||
params: McpResourceReadParams,
|
||||
app_server_client_name: Option<String>,
|
||||
app_server_client_version: Option<String>,
|
||||
client_compatibility_flags: ClientCompatibilityFlags,
|
||||
client_session: &ConnectionSessionState,
|
||||
) -> Result<(), JSONRPCErrorError> {
|
||||
let outgoing = Arc::clone(&self.outgoing);
|
||||
let client_compatibility_flags = client_session.client_compatibility_flags();
|
||||
let McpResourceReadParams {
|
||||
thread_id,
|
||||
server,
|
||||
@@ -413,13 +396,6 @@ impl McpRequestProcessor {
|
||||
|
||||
if let Some(thread_id) = thread_id {
|
||||
let (_, thread) = self.load_thread(&thread_id).await?;
|
||||
thread
|
||||
.set_app_server_client_info(
|
||||
app_server_client_name,
|
||||
app_server_client_version,
|
||||
client_compatibility_flags,
|
||||
)
|
||||
.await;
|
||||
let request_id = request_id.clone();
|
||||
|
||||
tokio::spawn(async move {
|
||||
@@ -482,20 +458,10 @@ impl McpRequestProcessor {
|
||||
&self,
|
||||
request_id: &ConnectionRequestId,
|
||||
params: McpServerToolCallParams,
|
||||
app_server_client_name: Option<String>,
|
||||
app_server_client_version: Option<String>,
|
||||
client_compatibility_flags: ClientCompatibilityFlags,
|
||||
) -> Result<(), JSONRPCErrorError> {
|
||||
let outgoing = Arc::clone(&self.outgoing);
|
||||
let thread_id = params.thread_id.clone();
|
||||
let (_, thread) = self.load_thread(&thread_id).await?;
|
||||
thread
|
||||
.set_app_server_client_info(
|
||||
app_server_client_name,
|
||||
app_server_client_version,
|
||||
client_compatibility_flags,
|
||||
)
|
||||
.await;
|
||||
let meta = with_mcp_tool_call_thread_id_meta(params.meta, &thread_id);
|
||||
let request_id = request_id.clone();
|
||||
|
||||
|
||||
@@ -301,21 +301,12 @@ impl ThreadRequestProcessor {
|
||||
&self,
|
||||
request_id: ConnectionRequestId,
|
||||
params: ThreadStartParams,
|
||||
app_server_client_name: Option<String>,
|
||||
app_server_client_version: Option<String>,
|
||||
client_compatibility_flags: ClientCompatibilityFlags,
|
||||
client_session: &ConnectionSessionState,
|
||||
request_context: RequestContext,
|
||||
) -> Result<Option<ClientResponsePayload>, JSONRPCErrorError> {
|
||||
self.thread_start_inner(
|
||||
request_id,
|
||||
params,
|
||||
app_server_client_name,
|
||||
app_server_client_version,
|
||||
client_compatibility_flags,
|
||||
request_context,
|
||||
)
|
||||
.await
|
||||
.map(|()| None)
|
||||
self.thread_start_inner(request_id, params, client_session, request_context)
|
||||
.await
|
||||
.map(|()| None)
|
||||
}
|
||||
|
||||
pub(crate) async fn thread_unsubscribe(
|
||||
@@ -332,9 +323,9 @@ impl ThreadRequestProcessor {
|
||||
&self,
|
||||
request_id: ConnectionRequestId,
|
||||
params: ThreadResumeParams,
|
||||
client_compatibility_flags: ClientCompatibilityFlags,
|
||||
client_session: &ConnectionSessionState,
|
||||
) -> Result<Option<ClientResponsePayload>, JSONRPCErrorError> {
|
||||
self.thread_resume_inner(request_id, params, client_compatibility_flags)
|
||||
self.thread_resume_inner(request_id, params, client_session)
|
||||
.await
|
||||
.map(|()| None)
|
||||
}
|
||||
@@ -343,9 +334,9 @@ impl ThreadRequestProcessor {
|
||||
&self,
|
||||
request_id: ConnectionRequestId,
|
||||
params: ThreadForkParams,
|
||||
client_compatibility_flags: ClientCompatibilityFlags,
|
||||
client_session: &ConnectionSessionState,
|
||||
) -> Result<Option<ClientResponsePayload>, JSONRPCErrorError> {
|
||||
self.thread_fork_inner(request_id, params, client_compatibility_flags)
|
||||
self.thread_fork_inner(request_id, params, client_session)
|
||||
.await
|
||||
.map(|()| None)
|
||||
}
|
||||
@@ -586,6 +577,22 @@ impl ThreadRequestProcessor {
|
||||
|
||||
Ok((thread_id, thread))
|
||||
}
|
||||
|
||||
async fn set_app_server_client_info(
|
||||
thread: &CodexThread,
|
||||
app_server_client_name: Option<String>,
|
||||
app_server_client_version: Option<String>,
|
||||
) -> Result<(), JSONRPCErrorError> {
|
||||
thread
|
||||
.set_app_server_client_info(app_server_client_name, app_server_client_version)
|
||||
.await
|
||||
.map_err(|err| JSONRPCErrorError {
|
||||
code: INTERNAL_ERROR_CODE,
|
||||
message: format!("failed to set app server client info: {err}"),
|
||||
data: None,
|
||||
})
|
||||
}
|
||||
|
||||
async fn acquire_thread_list_state_permit(
|
||||
&self,
|
||||
) -> Result<SemaphorePermit<'_>, JSONRPCErrorError> {
|
||||
@@ -705,9 +712,7 @@ impl ThreadRequestProcessor {
|
||||
&self,
|
||||
request_id: ConnectionRequestId,
|
||||
params: ThreadStartParams,
|
||||
app_server_client_name: Option<String>,
|
||||
app_server_client_version: Option<String>,
|
||||
client_compatibility_flags: ClientCompatibilityFlags,
|
||||
client_session: &ConnectionSessionState,
|
||||
request_context: RequestContext,
|
||||
) -> Result<(), JSONRPCErrorError> {
|
||||
let ThreadStartParams {
|
||||
@@ -767,6 +772,9 @@ impl ThreadRequestProcessor {
|
||||
let config_manager = self.config_manager.clone();
|
||||
let outgoing = Arc::clone(&listener_task_context.outgoing);
|
||||
let error_request_id = request_id.clone();
|
||||
let app_server_client_name = client_session.app_server_client_name().map(str::to_string);
|
||||
let app_server_client_version = client_session.client_version().map(str::to_string);
|
||||
let client_compatibility_flags = client_session.client_compatibility_flags();
|
||||
let thread_start_task = async move {
|
||||
if let Err(error) = Self::thread_start_task(
|
||||
listener_task_context,
|
||||
@@ -988,13 +996,12 @@ impl ThreadRequestProcessor {
|
||||
err => internal_error(format!("error creating thread: {err}")),
|
||||
})?;
|
||||
|
||||
thread
|
||||
.set_app_server_client_info(
|
||||
app_server_client_name,
|
||||
app_server_client_version,
|
||||
client_compatibility_flags,
|
||||
)
|
||||
.await;
|
||||
Self::set_app_server_client_info(
|
||||
thread.as_ref(),
|
||||
app_server_client_name,
|
||||
app_server_client_version,
|
||||
)
|
||||
.await?;
|
||||
|
||||
let config_snapshot = thread
|
||||
.config_snapshot()
|
||||
@@ -2290,7 +2297,7 @@ impl ThreadRequestProcessor {
|
||||
&self,
|
||||
request_id: ConnectionRequestId,
|
||||
params: ThreadResumeParams,
|
||||
client_compatibility_flags: ClientCompatibilityFlags,
|
||||
client_session: &ConnectionSessionState,
|
||||
) -> Result<(), JSONRPCErrorError> {
|
||||
if let Ok(thread_id) = ThreadId::from_string(¶ms.thread_id)
|
||||
&& self
|
||||
@@ -2407,7 +2414,7 @@ impl ThreadRequestProcessor {
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
config.client_compatibility_flags = client_compatibility_flags;
|
||||
apply_client_compatibility(&mut config, client_session);
|
||||
|
||||
let instruction_sources = Self::instruction_sources_from_config(&config).await;
|
||||
let response_history = thread_history.clone();
|
||||
@@ -2927,7 +2934,7 @@ impl ThreadRequestProcessor {
|
||||
&self,
|
||||
request_id: ConnectionRequestId,
|
||||
params: ThreadForkParams,
|
||||
client_compatibility_flags: ClientCompatibilityFlags,
|
||||
client_session: &ConnectionSessionState,
|
||||
) -> Result<(), JSONRPCErrorError> {
|
||||
let ThreadForkParams {
|
||||
thread_id,
|
||||
@@ -3011,7 +3018,7 @@ impl ThreadRequestProcessor {
|
||||
.load_for_cwd(request_overrides, typesafe_overrides, history_cwd)
|
||||
.await
|
||||
.map_err(|err| config_load_error(&err))?;
|
||||
config.client_compatibility_flags = client_compatibility_flags;
|
||||
apply_client_compatibility(&mut config, client_session);
|
||||
|
||||
let fallback_model_provider = config.model_provider_id.clone();
|
||||
let instruction_sources = Self::instruction_sources_from_config(&config).await;
|
||||
|
||||
@@ -49,19 +49,11 @@ impl TurnRequestProcessor {
|
||||
&self,
|
||||
request_id: ConnectionRequestId,
|
||||
params: TurnStartParams,
|
||||
app_server_client_name: Option<String>,
|
||||
app_server_client_version: Option<String>,
|
||||
client_compatibility_flags: ClientCompatibilityFlags,
|
||||
client_session: &ConnectionSessionState,
|
||||
) -> Result<Option<ClientResponsePayload>, JSONRPCErrorError> {
|
||||
self.turn_start_inner(
|
||||
request_id,
|
||||
params,
|
||||
app_server_client_name,
|
||||
app_server_client_version,
|
||||
client_compatibility_flags,
|
||||
)
|
||||
.await
|
||||
.map(|response| Some(response.into()))
|
||||
self.turn_start_inner(request_id, params, client_session)
|
||||
.await
|
||||
.map(|response| Some(response.into()))
|
||||
}
|
||||
|
||||
pub(crate) async fn thread_inject_items(
|
||||
@@ -148,19 +140,11 @@ impl TurnRequestProcessor {
|
||||
&self,
|
||||
request_id: &ConnectionRequestId,
|
||||
params: ReviewStartParams,
|
||||
app_server_client_name: Option<String>,
|
||||
app_server_client_version: Option<String>,
|
||||
client_compatibility_flags: ClientCompatibilityFlags,
|
||||
client_session: &ConnectionSessionState,
|
||||
) -> Result<Option<ClientResponsePayload>, JSONRPCErrorError> {
|
||||
self.review_start_inner(
|
||||
request_id,
|
||||
params,
|
||||
app_server_client_name,
|
||||
app_server_client_version,
|
||||
client_compatibility_flags,
|
||||
)
|
||||
.await
|
||||
.map(|()| None)
|
||||
self.review_start_inner(request_id, params, client_session)
|
||||
.await
|
||||
.map(|()| None)
|
||||
}
|
||||
|
||||
fn track_error_response(
|
||||
@@ -341,9 +325,7 @@ impl TurnRequestProcessor {
|
||||
&self,
|
||||
request_id: ConnectionRequestId,
|
||||
params: TurnStartParams,
|
||||
app_server_client_name: Option<String>,
|
||||
app_server_client_version: Option<String>,
|
||||
client_compatibility_flags: ClientCompatibilityFlags,
|
||||
client_session: &ConnectionSessionState,
|
||||
) -> Result<TurnStartResponse, JSONRPCErrorError> {
|
||||
if let Err(error) = Self::validate_v2_input_limit(¶ms.input) {
|
||||
self.track_error_response(
|
||||
@@ -359,13 +341,15 @@ impl TurnRequestProcessor {
|
||||
.inspect_err(|error| {
|
||||
self.track_error_response(&request_id, error, /*error_type*/ None);
|
||||
})?;
|
||||
thread
|
||||
.set_app_server_client_info(
|
||||
app_server_client_name,
|
||||
app_server_client_version,
|
||||
client_compatibility_flags,
|
||||
)
|
||||
.await;
|
||||
Self::set_app_server_client_info(
|
||||
thread.as_ref(),
|
||||
client_session.app_server_client_name().map(str::to_string),
|
||||
client_session.client_version().map(str::to_string),
|
||||
)
|
||||
.await
|
||||
.inspect_err(|error| {
|
||||
self.track_error_response(&request_id, error, /*error_type*/ None);
|
||||
})?;
|
||||
|
||||
let collaboration_mode = params
|
||||
.collaboration_mode
|
||||
@@ -566,6 +550,21 @@ impl TurnRequestProcessor {
|
||||
Ok(ThreadInjectItemsResponse {})
|
||||
}
|
||||
|
||||
async fn set_app_server_client_info(
|
||||
thread: &CodexThread,
|
||||
app_server_client_name: Option<String>,
|
||||
app_server_client_version: Option<String>,
|
||||
) -> Result<(), JSONRPCErrorError> {
|
||||
thread
|
||||
.set_app_server_client_info(app_server_client_name, app_server_client_version)
|
||||
.await
|
||||
.map_err(|err| JSONRPCErrorError {
|
||||
code: INTERNAL_ERROR_CODE,
|
||||
message: format!("failed to set app server client info: {err}"),
|
||||
data: None,
|
||||
})
|
||||
}
|
||||
|
||||
async fn turn_steer_inner(
|
||||
&self,
|
||||
request_id: &ConnectionRequestId,
|
||||
@@ -880,7 +879,7 @@ impl TurnRequestProcessor {
|
||||
request_id: &ConnectionRequestId,
|
||||
parent_thread_id: ThreadId,
|
||||
parent_thread: Arc<CodexThread>,
|
||||
client_compatibility_flags: ClientCompatibilityFlags,
|
||||
client_session: &ConnectionSessionState,
|
||||
review_request: ReviewRequest,
|
||||
display_text: &str,
|
||||
) -> std::result::Result<(), JSONRPCErrorError> {
|
||||
@@ -900,7 +899,7 @@ impl TurnRequestProcessor {
|
||||
};
|
||||
|
||||
let mut config = self.config.as_ref().clone();
|
||||
config.client_compatibility_flags = client_compatibility_flags;
|
||||
apply_client_compatibility(&mut config, client_session);
|
||||
if let Some(review_model) = &config.review_model {
|
||||
config.model = Some(review_model.clone());
|
||||
}
|
||||
@@ -993,9 +992,7 @@ impl TurnRequestProcessor {
|
||||
&self,
|
||||
request_id: &ConnectionRequestId,
|
||||
params: ReviewStartParams,
|
||||
app_server_client_name: Option<String>,
|
||||
app_server_client_version: Option<String>,
|
||||
client_compatibility_flags: ClientCompatibilityFlags,
|
||||
client_session: &ConnectionSessionState,
|
||||
) -> Result<(), JSONRPCErrorError> {
|
||||
let ReviewStartParams {
|
||||
thread_id,
|
||||
@@ -1004,13 +1001,6 @@ impl TurnRequestProcessor {
|
||||
} = params;
|
||||
|
||||
let (parent_thread_id, parent_thread) = self.load_thread(&thread_id).await?;
|
||||
parent_thread
|
||||
.set_app_server_client_info(
|
||||
app_server_client_name,
|
||||
app_server_client_version,
|
||||
client_compatibility_flags,
|
||||
)
|
||||
.await;
|
||||
let (review_request, display_text) = Self::review_request_from_target(target)?;
|
||||
match delivery.unwrap_or(ApiReviewDelivery::Inline).to_core() {
|
||||
CoreReviewDelivery::Inline => {
|
||||
@@ -1028,7 +1018,7 @@ impl TurnRequestProcessor {
|
||||
request_id,
|
||||
parent_thread_id,
|
||||
parent_thread,
|
||||
client_compatibility_flags,
|
||||
client_session,
|
||||
review_request,
|
||||
display_text.as_str(),
|
||||
)
|
||||
|
||||
@@ -17,7 +17,6 @@ use crate::codex_apps::CodexAppsToolsCacheContext;
|
||||
use crate::codex_apps::CodexAppsToolsCacheKey;
|
||||
use crate::codex_apps::write_cached_codex_apps_tools_if_needed;
|
||||
use crate::elicitation::ElicitationRequestManager;
|
||||
use crate::elicitation::McpElicitationCompatibility;
|
||||
use crate::mcp::CODEX_APPS_MCP_SERVER_NAME;
|
||||
use crate::mcp::ToolPluginProvenance;
|
||||
use crate::rmcp_client::AsyncManagedClient;
|
||||
@@ -129,12 +128,6 @@ impl McpConnectionManager {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_elicitation_compatibility(&self, compatibility: McpElicitationCompatibility) {
|
||||
if let Ok(mut manager_compatibility) = self.elicitation_requests.compatibility.lock() {
|
||||
*manager_compatibility = compatibility;
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::new_ret_no_self, clippy::too_many_arguments)]
|
||||
pub async fn new(
|
||||
mcp_servers: &HashMap<String, McpServerConfig>,
|
||||
@@ -149,7 +142,7 @@ impl McpConnectionManager {
|
||||
codex_apps_tools_cache_key: CodexAppsToolsCacheKey,
|
||||
tool_plugin_provenance: ToolPluginProvenance,
|
||||
auth: Option<&CodexAuth>,
|
||||
elicitation_compatibility: McpElicitationCompatibility,
|
||||
elicitation_compatibility: crate::elicitation::McpElicitationCompatibility,
|
||||
) -> (Self, CancellationToken) {
|
||||
let cancel_token = CancellationToken::new();
|
||||
let mut clients = HashMap::new();
|
||||
|
||||
@@ -268,14 +268,13 @@ async fn disabled_permissions_do_not_auto_accept_elicitation_with_requested_fiel
|
||||
|
||||
#[tokio::test]
|
||||
async fn codex_apps_only_custom_server_elicitation_is_declined_without_event() {
|
||||
let approval_policy = Constrained::allow_any(AskForApproval::OnRequest);
|
||||
let permission_profile = Constrained::allow_any(PermissionProfile::default());
|
||||
let manager = McpConnectionManager::new_uninitialized(&approval_policy, &permission_profile);
|
||||
manager.set_elicitation_compatibility(McpElicitationCompatibility::CodexAppsOnly);
|
||||
let manager = ElicitationRequestManager::new_with_compatibility(
|
||||
AskForApproval::OnRequest,
|
||||
PermissionProfile::default(),
|
||||
McpElicitationCompatibility::CodexAppsOnly,
|
||||
);
|
||||
let (tx_event, rx_event) = async_channel::bounded(1);
|
||||
let sender = manager
|
||||
.elicitation_requests
|
||||
.make_sender("custom_mcp".to_string(), tx_event);
|
||||
let sender = manager.make_sender("custom_mcp".to_string(), tx_event);
|
||||
|
||||
let response = sender(
|
||||
NumberOrString::Number(1),
|
||||
|
||||
@@ -37,7 +37,7 @@ pub(crate) struct ElicitationRequestManager {
|
||||
requests: Arc<Mutex<ResponderMap>>,
|
||||
pub(crate) approval_policy: Arc<StdMutex<AskForApproval>>,
|
||||
pub(crate) permission_profile: Arc<StdMutex<PermissionProfile>>,
|
||||
pub(crate) compatibility: Arc<StdMutex<McpElicitationCompatibility>>,
|
||||
pub(crate) compatibility: McpElicitationCompatibility,
|
||||
}
|
||||
|
||||
impl ElicitationRequestManager {
|
||||
@@ -61,7 +61,7 @@ impl ElicitationRequestManager {
|
||||
requests: Arc::new(Mutex::new(HashMap::new())),
|
||||
approval_policy: Arc::new(StdMutex::new(approval_policy)),
|
||||
permission_profile: Arc::new(StdMutex::new(permission_profile)),
|
||||
compatibility: Arc::new(StdMutex::new(compatibility)),
|
||||
compatibility,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,19 +88,14 @@ impl ElicitationRequestManager {
|
||||
let elicitation_requests = self.requests.clone();
|
||||
let approval_policy = self.approval_policy.clone();
|
||||
let permission_profile = self.permission_profile.clone();
|
||||
let compatibility = self.compatibility.clone();
|
||||
let compatibility = self.compatibility;
|
||||
Box::new(move |id, elicitation| {
|
||||
let elicitation_requests = elicitation_requests.clone();
|
||||
let tx_event = tx_event.clone();
|
||||
let server_name = server_name.clone();
|
||||
let approval_policy = approval_policy.clone();
|
||||
let permission_profile = permission_profile.clone();
|
||||
let compatibility = compatibility.clone();
|
||||
async move {
|
||||
let compatibility = compatibility
|
||||
.lock()
|
||||
.map(|compatibility| *compatibility)
|
||||
.unwrap_or_default();
|
||||
if !compatibility.allows_server_elicitation(&server_name) {
|
||||
return Ok(ElicitationResponse {
|
||||
action: ElicitationAction::Decline,
|
||||
|
||||
@@ -466,12 +466,8 @@ async fn start_server_task(
|
||||
elicitation_requests,
|
||||
codex_apps_tools_cache_context,
|
||||
} = params;
|
||||
let compatibility = elicitation_requests
|
||||
.compatibility
|
||||
.lock()
|
||||
.map(|compatibility| *compatibility)
|
||||
.unwrap_or_default();
|
||||
let elicitation = elicitation_capability_for_server(&server_name, compatibility);
|
||||
let elicitation =
|
||||
elicitation_capability_for_server(&server_name, elicitation_requests.compatibility);
|
||||
let params = InitializeRequestParams {
|
||||
meta: None,
|
||||
capabilities: ClientCapabilities {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use crate::ClientCompatibilityFlags;
|
||||
use crate::agent::AgentStatus;
|
||||
use crate::config::ConstraintResult;
|
||||
use crate::file_watcher::WatchRegistration;
|
||||
@@ -219,14 +218,9 @@ impl CodexThread {
|
||||
&self,
|
||||
app_server_client_name: Option<String>,
|
||||
app_server_client_version: Option<String>,
|
||||
client_compatibility_flags: ClientCompatibilityFlags,
|
||||
) {
|
||||
) -> ConstraintResult<()> {
|
||||
self.codex
|
||||
.set_app_server_client_info(
|
||||
app_server_client_name,
|
||||
app_server_client_version,
|
||||
client_compatibility_flags,
|
||||
)
|
||||
.set_app_server_client_info(app_server_client_name, app_server_client_version)
|
||||
.await
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ use std::sync::atomic::AtomicU64;
|
||||
use std::time::SystemTime;
|
||||
use std::time::UNIX_EPOCH;
|
||||
|
||||
use crate::ClientCompatibilityFlags;
|
||||
use crate::agent::AgentControl;
|
||||
use crate::agent::AgentStatus;
|
||||
use crate::agent::Mailbox;
|
||||
@@ -750,19 +749,14 @@ impl Codex {
|
||||
&self,
|
||||
app_server_client_name: Option<String>,
|
||||
app_server_client_version: Option<String>,
|
||||
client_compatibility_flags: ClientCompatibilityFlags,
|
||||
) {
|
||||
{
|
||||
let mut state = self.session.state.lock().await;
|
||||
state.session_configuration.app_server_client_name = app_server_client_name;
|
||||
state.session_configuration.app_server_client_version = app_server_client_version;
|
||||
let mut config = (*state.session_configuration.original_config_do_not_use).clone();
|
||||
config.client_compatibility_flags = client_compatibility_flags;
|
||||
state.session_configuration.original_config_do_not_use = Arc::new(config);
|
||||
}
|
||||
let mcp_connection_manager = self.session.services.mcp_connection_manager.read().await;
|
||||
mcp_connection_manager
|
||||
.set_elicitation_compatibility(client_compatibility_flags.mcp_elicitation);
|
||||
) -> ConstraintResult<()> {
|
||||
self.session
|
||||
.update_settings(SessionSettingsUpdate {
|
||||
app_server_client_name,
|
||||
app_server_client_version,
|
||||
..Default::default()
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
pub(crate) async fn agent_status(&self) -> AgentStatus {
|
||||
|
||||
Reference in New Issue
Block a user