mirror of
https://github.com/openai/codex.git
synced 2026-11-26 23:40:43 +00:00
[codex][device-stable-id][12/n] Send source stable ID with managed auth requests
This commit is contained in:
@@ -64,6 +64,7 @@ use crate::outgoing_message::OutgoingMessage;
|
||||
use crate::outgoing_message::OutgoingMessageSender;
|
||||
use crate::outgoing_message::QueuedOutgoingMessage;
|
||||
use crate::transport::CHANNEL_CAPACITY;
|
||||
use crate::transport::ConnectionOrigin;
|
||||
use crate::transport::OutboundConnectionState;
|
||||
use crate::transport::route_outgoing_envelope;
|
||||
use codex_analytics::AppServerRpcTransport;
|
||||
@@ -382,6 +383,7 @@ async fn start_uninitialized(args: InProcessStartArgs) -> IoResult<InProcessClie
|
||||
let auth_manager =
|
||||
AuthManager::shared_from_config(args.config.as_ref(), args.enable_codex_api_key_env)
|
||||
.await;
|
||||
auth_manager.set_source_surface_stable_id(Some(installation_id.clone()));
|
||||
let analytics_events_client =
|
||||
analytics_events_client_from_config(Arc::clone(&auth_manager), args.config.as_ref());
|
||||
let outgoing_message_sender = Arc::new(OutgoingMessageSender::new(
|
||||
@@ -442,7 +444,7 @@ async fn start_uninitialized(args: InProcessStartArgs) -> IoResult<InProcessClie
|
||||
plugin_startup_tasks: crate::PluginStartupTasks::Start,
|
||||
}));
|
||||
let mut thread_created_rx = processor.thread_created_receiver();
|
||||
let session = Arc::new(ConnectionSessionState::new());
|
||||
let session = Arc::new(ConnectionSessionState::new(ConnectionOrigin::InProcess));
|
||||
let mut listen_for_threads = true;
|
||||
|
||||
loop {
|
||||
|
||||
@@ -750,6 +750,9 @@ pub async fn run_main_with_transport_options(
|
||||
|
||||
let auth_manager =
|
||||
AuthManager::shared_from_config(&config, /*enable_codex_api_key_env*/ false).await;
|
||||
if !single_client_mode {
|
||||
auth_manager.set_source_surface_stable_id(Some(installation_id.clone()));
|
||||
}
|
||||
|
||||
let remote_control_enabled = remote_control_policy == RemoteControlPolicy::Allowed
|
||||
&& remote_control_explicitly_requested
|
||||
|
||||
@@ -46,6 +46,7 @@ use crate::skills_watcher::SkillsWatcher;
|
||||
use crate::thread_state::ConnectionCapabilities;
|
||||
use crate::thread_state::ThreadStateManager;
|
||||
use crate::transport::AppServerTransport;
|
||||
use crate::transport::ConnectionOrigin;
|
||||
use crate::transport::RemoteControlHandle;
|
||||
use codex_analytics::AnalyticsEventsClient;
|
||||
use codex_analytics::AppServerRpcTransport;
|
||||
@@ -213,6 +214,7 @@ pub(crate) struct MessageProcessor {
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct ConnectionSessionState {
|
||||
pub(crate) rpc_gate: Arc<ConnectionRpcGate>,
|
||||
origin: ConnectionOrigin,
|
||||
initialized: OnceLock<InitializedConnectionSessionState>,
|
||||
}
|
||||
|
||||
@@ -225,16 +227,11 @@ pub(crate) struct InitializedConnectionSessionState {
|
||||
pub(crate) request_attestation: bool,
|
||||
}
|
||||
|
||||
impl Default for ConnectionSessionState {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl ConnectionSessionState {
|
||||
pub(crate) fn new() -> Self {
|
||||
pub(crate) fn new(origin: ConnectionOrigin) -> Self {
|
||||
Self {
|
||||
rpc_gate: Arc::new(ConnectionRpcGate::new()),
|
||||
origin,
|
||||
initialized: OnceLock::new(),
|
||||
}
|
||||
}
|
||||
@@ -884,6 +881,7 @@ 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 accepts_client_source_surface_stable_id = session.origin == ConnectionOrigin::Stdio;
|
||||
let error_request_id = connection_request_id.clone();
|
||||
let rpc_gate = Arc::clone(&session.rpc_gate);
|
||||
let processor = Arc::clone(self);
|
||||
@@ -899,6 +897,7 @@ impl MessageProcessor {
|
||||
request_context,
|
||||
app_server_client_name,
|
||||
client_version,
|
||||
accepts_client_source_surface_stable_id,
|
||||
)
|
||||
.await;
|
||||
if let Err(error) = result {
|
||||
@@ -928,6 +927,7 @@ impl MessageProcessor {
|
||||
request_context: RequestContext,
|
||||
app_server_client_name: Option<String>,
|
||||
client_version: Option<String>,
|
||||
accepts_client_source_surface_stable_id: bool,
|
||||
) -> Result<(), JSONRPCErrorError> {
|
||||
let connection_id = connection_request_id.connection_id;
|
||||
let request_id = ConnectionRequestId {
|
||||
@@ -1378,7 +1378,11 @@ impl MessageProcessor {
|
||||
}
|
||||
ClientRequest::LoginAccount { params, .. } => {
|
||||
self.account_processor
|
||||
.login_account(request_id.clone(), params)
|
||||
.login_account(
|
||||
request_id.clone(),
|
||||
params,
|
||||
accepts_client_source_surface_stable_id,
|
||||
)
|
||||
.await
|
||||
}
|
||||
ClientRequest::LogoutAccount { .. } => {
|
||||
@@ -1390,7 +1394,9 @@ impl MessageProcessor {
|
||||
self.account_processor.cancel_login_account(params).await
|
||||
}
|
||||
ClientRequest::GetAccount { params, .. } => {
|
||||
self.account_processor.get_account(params).await
|
||||
self.account_processor
|
||||
.get_account(params, accepts_client_source_surface_stable_id)
|
||||
.await
|
||||
}
|
||||
ClientRequest::GetAuthStatus { params, .. } => {
|
||||
self.account_processor.get_auth_status(params).await
|
||||
|
||||
@@ -6,6 +6,7 @@ use crate::config_manager::ConfigManager;
|
||||
use crate::outgoing_message::ConnectionId;
|
||||
use crate::outgoing_message::OutgoingMessageSender;
|
||||
use crate::transport::AppServerTransport;
|
||||
use crate::transport::ConnectionOrigin;
|
||||
use anyhow::Result;
|
||||
use app_test_support::create_mock_responses_server_repeating_assistant;
|
||||
use app_test_support::write_mock_responses_config_toml;
|
||||
@@ -128,7 +129,7 @@ impl TracingHarness {
|
||||
_codex_home: codex_home,
|
||||
processor,
|
||||
outgoing_rx,
|
||||
session: Arc::new(ConnectionSessionState::new()),
|
||||
session: Arc::new(ConnectionSessionState::new(ConnectionOrigin::WebSocket)),
|
||||
tracing,
|
||||
};
|
||||
|
||||
|
||||
@@ -88,7 +88,23 @@ impl AccountRequestProcessor {
|
||||
&self,
|
||||
request_id: ConnectionRequestId,
|
||||
params: LoginAccountParams,
|
||||
accepts_client_source_surface_stable_id: bool,
|
||||
) -> Result<Option<ClientResponsePayload>, JSONRPCErrorError> {
|
||||
let source_surface_stable_id = match ¶ms {
|
||||
LoginAccountParams::Chatgpt {
|
||||
source_surface_stable_id,
|
||||
..
|
||||
}
|
||||
| LoginAccountParams::ChatgptDeviceCode {
|
||||
source_surface_stable_id,
|
||||
} => source_surface_stable_id.clone(),
|
||||
_ => None,
|
||||
};
|
||||
self.set_client_source_surface_stable_id(
|
||||
accepts_client_source_surface_stable_id,
|
||||
source_surface_stable_id,
|
||||
);
|
||||
|
||||
self.login_v2(request_id, params).await.map(|()| None)
|
||||
}
|
||||
|
||||
@@ -111,7 +127,13 @@ impl AccountRequestProcessor {
|
||||
pub(crate) async fn get_account(
|
||||
&self,
|
||||
params: GetAccountParams,
|
||||
accepts_client_source_surface_stable_id: bool,
|
||||
) -> Result<Option<ClientResponsePayload>, JSONRPCErrorError> {
|
||||
self.set_client_source_surface_stable_id(
|
||||
accepts_client_source_surface_stable_id,
|
||||
params.source_surface_stable_id.clone(),
|
||||
);
|
||||
|
||||
self.get_account_response(params)
|
||||
.await
|
||||
.map(|response| Some(response.into()))
|
||||
@@ -239,11 +261,12 @@ impl AccountRequestProcessor {
|
||||
}
|
||||
LoginAccountParams::Chatgpt {
|
||||
codex_streamlined_login,
|
||||
..
|
||||
} => {
|
||||
self.login_chatgpt_v2(request_id, codex_streamlined_login)
|
||||
.await;
|
||||
}
|
||||
LoginAccountParams::ChatgptDeviceCode => {
|
||||
LoginAccountParams::ChatgptDeviceCode { .. } => {
|
||||
self.login_chatgpt_device_code_v2(request_id).await;
|
||||
}
|
||||
LoginAccountParams::ChatgptAuthTokens {
|
||||
@@ -342,6 +365,7 @@ impl AccountRequestProcessor {
|
||||
let opts = LoginServerOptions {
|
||||
open_browser: false,
|
||||
codex_streamlined_login,
|
||||
source_surface_stable_id: self.auth_manager.source_surface_stable_id(),
|
||||
..LoginServerOptions::new(
|
||||
config.codex_home.to_path_buf(),
|
||||
oauth_client_id(),
|
||||
@@ -364,6 +388,16 @@ impl AccountRequestProcessor {
|
||||
Ok(opts)
|
||||
}
|
||||
|
||||
fn set_client_source_surface_stable_id(
|
||||
&self,
|
||||
accepts_client_source_surface_stable_id: bool,
|
||||
value: Option<String>,
|
||||
) {
|
||||
if accepts_client_source_surface_stable_id && let Some(value) = value {
|
||||
self.auth_manager.set_source_surface_stable_id(Some(value));
|
||||
}
|
||||
}
|
||||
|
||||
fn login_chatgpt_device_code_start_error(err: IoError) -> JSONRPCErrorError {
|
||||
let is_not_found = err.kind() == std::io::ErrorKind::NotFound;
|
||||
if is_not_found {
|
||||
|
||||
@@ -45,7 +45,7 @@ pub(crate) struct ConnectionState {
|
||||
|
||||
impl ConnectionState {
|
||||
pub(crate) fn new(
|
||||
_origin: ConnectionOrigin,
|
||||
origin: ConnectionOrigin,
|
||||
outbound_initialized: Arc<AtomicBool>,
|
||||
outbound_experimental_api_enabled: Arc<AtomicBool>,
|
||||
outbound_opted_out_notification_methods: Arc<RwLock<HashSet<String>>>,
|
||||
@@ -54,7 +54,7 @@ impl ConnectionState {
|
||||
outbound_initialized,
|
||||
outbound_experimental_api_enabled,
|
||||
outbound_opted_out_notification_methods,
|
||||
session: Arc::new(ConnectionSessionState::new()),
|
||||
session: Arc::new(ConnectionSessionState::new(origin)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user