Skip to content

Commit cab7136

Browse files
authored
chore: add model/list call to app-server-test-client (#8331)
Allows us to run `cargo run -p codex-app-server-test-client -- model-list` to return the list of models over app-server.
1 parent 32db8ea commit cab7136

File tree

1 file changed

+28
-0
lines changed
  • codex-rs/app-server-test-client/src

1 file changed

+28
-0
lines changed

codex-rs/app-server-test-client/src/main.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ use codex_app_server_protocol::JSONRPCRequest;
3535
use codex_app_server_protocol::JSONRPCResponse;
3636
use codex_app_server_protocol::LoginChatGptCompleteNotification;
3737
use codex_app_server_protocol::LoginChatGptResponse;
38+
use codex_app_server_protocol::ModelListParams;
39+
use codex_app_server_protocol::ModelListResponse;
3840
use codex_app_server_protocol::NewConversationParams;
3941
use codex_app_server_protocol::NewConversationResponse;
4042
use codex_app_server_protocol::RequestId;
@@ -113,6 +115,9 @@ enum CliCommand {
113115
TestLogin,
114116
/// Fetch the current account rate limits from the Codex app-server.
115117
GetAccountRateLimits,
118+
/// List the available models from the Codex app-server.
119+
#[command(name = "model-list")]
120+
ModelList,
116121
}
117122

118123
fn main() -> Result<()> {
@@ -134,6 +139,7 @@ fn main() -> Result<()> {
134139
} => send_follow_up_v2(codex_bin, first_message, follow_up_message),
135140
CliCommand::TestLogin => test_login(codex_bin),
136141
CliCommand::GetAccountRateLimits => get_account_rate_limits(codex_bin),
142+
CliCommand::ModelList => model_list(codex_bin),
137143
}
138144
}
139145

@@ -301,6 +307,18 @@ fn get_account_rate_limits(codex_bin: String) -> Result<()> {
301307
Ok(())
302308
}
303309

310+
fn model_list(codex_bin: String) -> Result<()> {
311+
let mut client = CodexClient::spawn(codex_bin)?;
312+
313+
let initialize = client.initialize()?;
314+
println!("< initialize response: {initialize:?}");
315+
316+
let response = client.model_list(ModelListParams::default())?;
317+
println!("< model/list response: {response:?}");
318+
319+
Ok(())
320+
}
321+
304322
struct CodexClient {
305323
child: Child,
306324
stdin: Option<ChildStdin>,
@@ -452,6 +470,16 @@ impl CodexClient {
452470
self.send_request(request, request_id, "account/rateLimits/read")
453471
}
454472

473+
fn model_list(&mut self, params: ModelListParams) -> Result<ModelListResponse> {
474+
let request_id = self.request_id();
475+
let request = ClientRequest::ModelList {
476+
request_id: request_id.clone(),
477+
params,
478+
};
479+
480+
self.send_request(request, request_id, "model/list")
481+
}
482+
455483
fn stream_conversation(&mut self, conversation_id: &ConversationId) -> Result<()> {
456484
loop {
457485
let notification = self.next_notification()?;

0 commit comments

Comments
 (0)