Skip to content

Commit 190e7eb

Browse files
authored
[app-server] fix account/read response annotation (#5642)
The API schema export is currently broken: ``` > cargo run -p codex-app-server-protocol --bin export -- --out DIR Error: this type cannot be exported ``` This PR fixes the error message so we get more info: ``` > cargo run -p codex-app-server-protocol --bin export -- --out DIR Error: failed to export client responses: dependency core::option::Option<codex_protocol::account::Account> cannot be exported ``` And fixes the root cause which is the `account/read` response.
1 parent 061862a commit 190e7eb

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

codex-rs/app-server-protocol/src/export.rs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use std::io::Write;
2323
use std::path::Path;
2424
use std::path::PathBuf;
2525
use std::process::Command;
26+
use ts_rs::ExportError;
2627
use ts_rs::TS;
2728

2829
const HEADER: &str = "// GENERATED CODE! DO NOT MODIFY BY HAND!\n\n";
@@ -104,6 +105,19 @@ macro_rules! for_each_schema_type {
104105
};
105106
}
106107

108+
fn export_ts_with_context<F>(label: &str, export: F) -> Result<()>
109+
where
110+
F: FnOnce() -> std::result::Result<(), ExportError>,
111+
{
112+
match export() {
113+
Ok(()) => Ok(()),
114+
Err(ExportError::CannotBeExported(ty)) => Err(anyhow!(
115+
"failed to export {label}: dependency {ty} cannot be exported"
116+
)),
117+
Err(err) => Err(err.into()),
118+
}
119+
}
120+
107121
pub fn generate_types(out_dir: &Path, prettier: Option<&Path>) -> Result<()> {
108122
generate_ts(out_dir, prettier)?;
109123
generate_json(out_dir)?;
@@ -113,13 +127,17 @@ pub fn generate_types(out_dir: &Path, prettier: Option<&Path>) -> Result<()> {
113127
pub fn generate_ts(out_dir: &Path, prettier: Option<&Path>) -> Result<()> {
114128
ensure_dir(out_dir)?;
115129

116-
ClientRequest::export_all_to(out_dir)?;
117-
export_client_responses(out_dir)?;
118-
ClientNotification::export_all_to(out_dir)?;
119-
120-
ServerRequest::export_all_to(out_dir)?;
121-
export_server_responses(out_dir)?;
122-
ServerNotification::export_all_to(out_dir)?;
130+
export_ts_with_context("ClientRequest", || ClientRequest::export_all_to(out_dir))?;
131+
export_ts_with_context("client responses", || export_client_responses(out_dir))?;
132+
export_ts_with_context("ClientNotification", || {
133+
ClientNotification::export_all_to(out_dir)
134+
})?;
135+
136+
export_ts_with_context("ServerRequest", || ServerRequest::export_all_to(out_dir))?;
137+
export_ts_with_context("server responses", || export_server_responses(out_dir))?;
138+
export_ts_with_context("ServerNotification", || {
139+
ServerNotification::export_all_to(out_dir)
140+
})?;
123141

124142
generate_index_ts(out_dir)?;
125143

codex-rs/app-server-protocol/src/protocol.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ client_request_definitions! {
127127
#[ts(rename = "account/read")]
128128
GetAccount {
129129
params: #[ts(type = "undefined")] #[serde(skip_serializing_if = "Option::is_none")] Option<()>,
130-
response: Option<Account>,
130+
response: GetAccountResponse,
131131
},
132132

133133
/// DEPRECATED APIs below
@@ -534,6 +534,12 @@ pub struct GetAccountRateLimitsResponse {
534534
pub rate_limits: RateLimitSnapshot,
535535
}
536536

537+
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
538+
#[serde(transparent)]
539+
#[ts(export)]
540+
#[ts(type = "Account | null")]
541+
pub struct GetAccountResponse(#[ts(type = "Account | null")] pub Option<Account>);
542+
537543
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
538544
#[serde(rename_all = "camelCase")]
539545
pub struct GetAuthStatusResponse {

0 commit comments

Comments
 (0)