WIP fase 2b-2: rimosso login ChatGPT/OAuth/device code, agent/workload identity, backend-client; resta solo chiave API (test non tutti verdi)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -204,20 +204,14 @@ enum CliCommand {
|
||||
/// Follow-up user message for the second turn.
|
||||
follow_up_message: String,
|
||||
},
|
||||
/// Trigger a ChatGPT or Amazon Bedrock login flow.
|
||||
/// Trigger a Codex-managed Amazon Bedrock login flow.
|
||||
TestLogin {
|
||||
/// Use the device-code login flow instead of the browser callback flow.
|
||||
#[arg(long, default_value_t = false, conflicts_with = "amazon_bedrock")]
|
||||
device_code: bool,
|
||||
/// Use a Codex-managed Amazon Bedrock API key.
|
||||
#[arg(long, default_value_t = false, conflicts_with = "device_code")]
|
||||
amazon_bedrock: bool,
|
||||
/// Amazon Bedrock API key.
|
||||
#[arg(long, value_name = "API_KEY")]
|
||||
api_key: Option<String>,
|
||||
api_key: String,
|
||||
/// AWS Region for the Amazon Bedrock Mantle endpoint.
|
||||
#[arg(long, value_name = "REGION")]
|
||||
region: Option<String>,
|
||||
region: String,
|
||||
},
|
||||
/// Log out of the current account and wait for the account update.
|
||||
TestLogout,
|
||||
@@ -265,12 +259,6 @@ enum CliCommand {
|
||||
},
|
||||
}
|
||||
|
||||
enum TestLoginMode {
|
||||
ChatgptBrowser,
|
||||
ChatgptDeviceCode,
|
||||
AmazonBedrock { api_key: String, region: String },
|
||||
}
|
||||
|
||||
pub async fn run() -> Result<()> {
|
||||
let Cli {
|
||||
codex_bin,
|
||||
@@ -357,24 +345,10 @@ pub async fn run() -> Result<()> {
|
||||
)
|
||||
.await
|
||||
}
|
||||
CliCommand::TestLogin {
|
||||
device_code,
|
||||
amazon_bedrock,
|
||||
api_key,
|
||||
region,
|
||||
} => {
|
||||
CliCommand::TestLogin { api_key, region } => {
|
||||
ensure_dynamic_tools_unused(&dynamic_tools, "test-login")?;
|
||||
let endpoint = resolve_endpoint(codex_bin, url)?;
|
||||
let mode = if amazon_bedrock {
|
||||
let api_key = api_key.context("--api-key is required with --amazon-bedrock")?;
|
||||
let region = region.context("--region is required with --amazon-bedrock")?;
|
||||
TestLoginMode::AmazonBedrock { api_key, region }
|
||||
} else if device_code {
|
||||
TestLoginMode::ChatgptDeviceCode
|
||||
} else {
|
||||
TestLoginMode::ChatgptBrowser
|
||||
};
|
||||
test_login(&endpoint, &config_overrides, mode).await
|
||||
test_login(&endpoint, &config_overrides, api_key, region).await
|
||||
}
|
||||
CliCommand::TestLogout => {
|
||||
ensure_dynamic_tools_unused(&dynamic_tools, "test-logout")?;
|
||||
@@ -931,80 +905,40 @@ async fn send_follow_up_v2(
|
||||
async fn test_login(
|
||||
endpoint: &Endpoint,
|
||||
config_overrides: &[String],
|
||||
mode: TestLoginMode,
|
||||
api_key: String,
|
||||
region: String,
|
||||
) -> Result<()> {
|
||||
with_client("test-login", endpoint, config_overrides, |client| {
|
||||
let initialize = client.initialize()?;
|
||||
println!("< initialize response: {initialize:?}");
|
||||
|
||||
let login_response = match mode {
|
||||
TestLoginMode::ChatgptBrowser => client.login_account_chatgpt()?,
|
||||
TestLoginMode::ChatgptDeviceCode => client.login_account_chatgpt_device_code()?,
|
||||
TestLoginMode::AmazonBedrock { api_key, region } => {
|
||||
let request_id = client.request_id();
|
||||
let login_response: LoginAccountResponse = client.send_request(
|
||||
ClientRequest::LoginAccount {
|
||||
request_id: request_id.clone(),
|
||||
params: codex_app_server_protocol::LoginAccountParams::AmazonBedrock {
|
||||
api_key,
|
||||
region,
|
||||
},
|
||||
},
|
||||
request_id,
|
||||
"account/login/start",
|
||||
)?;
|
||||
println!("< account/login/start response: {login_response:?}");
|
||||
|
||||
let completion =
|
||||
client.wait_for_account_login_completion(/*expected_login_id*/ None)?;
|
||||
println!("< account/login/completed notification: {completion:?}");
|
||||
|
||||
loop {
|
||||
let notification = client.next_notification()?;
|
||||
if let Ok(ServerNotification::AccountUpdated(account_updated)) =
|
||||
ServerNotification::try_from(notification)
|
||||
{
|
||||
println!("< account/updated notification: {account_updated:?}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
let request_id = client.request_id();
|
||||
let login_response: LoginAccountResponse = client.send_request(
|
||||
ClientRequest::LoginAccount {
|
||||
request_id: request_id.clone(),
|
||||
params: codex_app_server_protocol::LoginAccountParams::AmazonBedrock {
|
||||
api_key,
|
||||
region,
|
||||
},
|
||||
},
|
||||
request_id,
|
||||
"account/login/start",
|
||||
)?;
|
||||
println!("< account/login/start response: {login_response:?}");
|
||||
let login_id = match login_response {
|
||||
LoginAccountResponse::Chatgpt { login_id, auth_url } => {
|
||||
println!("Open the following URL in your browser to continue:\n{auth_url}");
|
||||
login_id
|
||||
}
|
||||
LoginAccountResponse::ChatgptDeviceCode {
|
||||
login_id,
|
||||
verification_url,
|
||||
user_code,
|
||||
} => {
|
||||
println!(
|
||||
"Open the following URL and enter the code to continue:\n{verification_url}\n\nCode: {user_code}"
|
||||
);
|
||||
login_id
|
||||
}
|
||||
_ => bail!("expected chatgpt login response"),
|
||||
};
|
||||
|
||||
let completion = client.wait_for_account_login_completion(Some(&login_id))?;
|
||||
let completion = client.wait_for_account_login_completion(/*expected_login_id*/ None)?;
|
||||
println!("< account/login/completed notification: {completion:?}");
|
||||
|
||||
if completion.success {
|
||||
println!("Login succeeded.");
|
||||
Ok(())
|
||||
} else {
|
||||
bail!(
|
||||
"login failed: {}",
|
||||
completion
|
||||
.error
|
||||
.as_deref()
|
||||
.unwrap_or("unknown error from account/login/completed")
|
||||
);
|
||||
loop {
|
||||
let notification = client.next_notification()?;
|
||||
if let Ok(ServerNotification::AccountUpdated(account_updated)) =
|
||||
ServerNotification::try_from(notification)
|
||||
{
|
||||
println!("< account/updated notification: {account_updated:?}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
.await
|
||||
}
|
||||
@@ -1563,30 +1497,6 @@ impl CodexClient {
|
||||
self.send_request(request, request_id, "turn/start")
|
||||
}
|
||||
|
||||
fn login_account_chatgpt(&mut self) -> Result<LoginAccountResponse> {
|
||||
let request_id = self.request_id();
|
||||
let request = ClientRequest::LoginAccount {
|
||||
request_id: request_id.clone(),
|
||||
params: codex_app_server_protocol::LoginAccountParams::Chatgpt {
|
||||
app_brand: None,
|
||||
codex_streamlined_login: false,
|
||||
use_hosted_login_success_page: false,
|
||||
},
|
||||
};
|
||||
|
||||
self.send_request(request, request_id, "account/login/start")
|
||||
}
|
||||
|
||||
fn login_account_chatgpt_device_code(&mut self) -> Result<LoginAccountResponse> {
|
||||
let request_id = self.request_id();
|
||||
let request = ClientRequest::LoginAccount {
|
||||
request_id: request_id.clone(),
|
||||
params: codex_app_server_protocol::LoginAccountParams::ChatgptDeviceCode,
|
||||
};
|
||||
|
||||
self.send_request(request, request_id, "account/login/start")
|
||||
}
|
||||
|
||||
fn get_account_rate_limits(&mut self) -> Result<GetAccountRateLimitsResponse> {
|
||||
let request_id = self.request_id();
|
||||
let request = ClientRequest::GetAccountRateLimits {
|
||||
|
||||
Reference in New Issue
Block a user