feat: add --experimental to generate-ts (#10402)
Adding a `--experimental` flag to the `generate-ts` fct in the app-sever. It can be called through one of those 2 command ``` just write-app-server-schema --experimental codex app-server generate-ts --experimental ```
This commit is contained in:
parent
74327fa59c
commit
059d386f03
5 changed files with 46 additions and 11 deletions
|
|
@ -13,6 +13,10 @@ struct Args {
|
|||
/// Optional path to the Prettier executable to format generated TypeScript files.
|
||||
#[arg(short = 'p', long = "prettier", value_name = "PRETTIER_BIN")]
|
||||
prettier: Option<PathBuf>,
|
||||
|
||||
/// Include experimental API methods and fields in generated fixtures.
|
||||
#[arg(long = "experimental")]
|
||||
experimental: bool,
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
|
|
@ -22,11 +26,17 @@ fn main() -> Result<()> {
|
|||
.schema_root
|
||||
.unwrap_or_else(|| PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("schema"));
|
||||
|
||||
codex_app_server_protocol::write_schema_fixtures(&schema_root, args.prettier.as_deref())
|
||||
.with_context(|| {
|
||||
format!(
|
||||
"failed to regenerate schema fixtures under {}",
|
||||
schema_root.display()
|
||||
)
|
||||
})
|
||||
codex_app_server_protocol::write_schema_fixtures_with_options(
|
||||
&schema_root,
|
||||
args.prettier.as_deref(),
|
||||
codex_app_server_protocol::SchemaFixtureOptions {
|
||||
experimental_api: args.experimental,
|
||||
},
|
||||
)
|
||||
.with_context(|| {
|
||||
format!(
|
||||
"failed to regenerate schema fixtures under {}",
|
||||
schema_root.display()
|
||||
)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,5 +16,7 @@ pub use protocol::common::*;
|
|||
pub use protocol::thread_history::*;
|
||||
pub use protocol::v1::*;
|
||||
pub use protocol::v2::*;
|
||||
pub use schema_fixtures::SchemaFixtureOptions;
|
||||
pub use schema_fixtures::read_schema_fixture_tree;
|
||||
pub use schema_fixtures::write_schema_fixtures;
|
||||
pub use schema_fixtures::write_schema_fixtures_with_options;
|
||||
|
|
|
|||
|
|
@ -6,6 +6,11 @@ use std::collections::BTreeMap;
|
|||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default)]
|
||||
pub struct SchemaFixtureOptions {
|
||||
pub experimental_api: bool,
|
||||
}
|
||||
|
||||
pub fn read_schema_fixture_tree(schema_root: &Path) -> Result<BTreeMap<PathBuf, Vec<u8>>> {
|
||||
let typescript_root = schema_root.join("typescript");
|
||||
let json_root = schema_root.join("json");
|
||||
|
|
@ -26,14 +31,30 @@ pub fn read_schema_fixture_tree(schema_root: &Path) -> Result<BTreeMap<PathBuf,
|
|||
/// This is intended to be used by tooling (e.g., `just write-app-server-schema`).
|
||||
/// It deletes any previously generated files so stale artifacts are removed.
|
||||
pub fn write_schema_fixtures(schema_root: &Path, prettier: Option<&Path>) -> Result<()> {
|
||||
write_schema_fixtures_with_options(schema_root, prettier, SchemaFixtureOptions::default())
|
||||
}
|
||||
|
||||
/// Regenerates schema fixtures with configurable options.
|
||||
pub fn write_schema_fixtures_with_options(
|
||||
schema_root: &Path,
|
||||
prettier: Option<&Path>,
|
||||
options: SchemaFixtureOptions,
|
||||
) -> Result<()> {
|
||||
let typescript_out_dir = schema_root.join("typescript");
|
||||
let json_out_dir = schema_root.join("json");
|
||||
|
||||
ensure_empty_dir(&typescript_out_dir)?;
|
||||
ensure_empty_dir(&json_out_dir)?;
|
||||
|
||||
crate::generate_ts(&typescript_out_dir, prettier)?;
|
||||
crate::generate_json(&json_out_dir)?;
|
||||
crate::generate_ts_with_options(
|
||||
&typescript_out_dir,
|
||||
prettier,
|
||||
crate::GenerateTsOptions {
|
||||
experimental_api: options.experimental_api,
|
||||
..crate::GenerateTsOptions::default()
|
||||
},
|
||||
)?;
|
||||
crate::generate_json_with_experimental(&json_out_dir, options.experimental_api)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -788,6 +788,8 @@ At runtime, clients must send `initialize` with `capabilities.experimentalApi =
|
|||
|
||||
```bash
|
||||
just write-app-server-schema
|
||||
# Include experimental API fields/methods in fixtures.
|
||||
just write-app-server-schema --experimental
|
||||
```
|
||||
|
||||
5. Verify the protocol crate:
|
||||
|
|
|
|||
4
justfile
4
justfile
|
|
@ -69,8 +69,8 @@ write-config-schema:
|
|||
cargo run -p codex-core --bin codex-write-config-schema
|
||||
|
||||
# Regenerate vendored app-server protocol schema artifacts.
|
||||
write-app-server-schema:
|
||||
cargo run -p codex-app-server-protocol --bin write_schema_fixtures
|
||||
write-app-server-schema *args:
|
||||
cargo run -p codex-app-server-protocol --bin write_schema_fixtures -- "$@"
|
||||
|
||||
# Tail logs from the state SQLite database
|
||||
log *args:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue