mirror of
https://github.com/openai/codex.git
synced 2026-11-23 23:10:47 +00:00
feat: annotate experimental fields in app server protocol
This commit is contained in:
@@ -16,7 +16,6 @@ use anyhow::anyhow;
|
||||
use codex_protocol::protocol::EventMsg;
|
||||
use schemars::JsonSchema;
|
||||
use schemars::schema_for;
|
||||
use serde::Serialize;
|
||||
use serde_json::Map;
|
||||
use serde_json::Value;
|
||||
use std::collections::HashMap;
|
||||
@@ -328,13 +327,38 @@ where
|
||||
write_json_schema_with_return::<T>(out_dir, name)
|
||||
}
|
||||
|
||||
fn write_pretty_json(path: PathBuf, value: &impl Serialize) -> Result<()> {
|
||||
let json = serde_json::to_vec_pretty(value)
|
||||
fn write_pretty_json(path: PathBuf, value: &Value) -> Result<()> {
|
||||
let mut canonical = value.clone();
|
||||
sort_json_value(&mut canonical);
|
||||
let json = serde_json::to_vec_pretty(&canonical)
|
||||
.with_context(|| format!("Failed to serialize JSON schema to {}", path.display()))?;
|
||||
fs::write(&path, json).with_context(|| format!("Failed to write {}", path.display()))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Sort JSON object keys recursively to produce deterministic output even when
|
||||
/// serde_json is built with `preserve_order`.
|
||||
fn sort_json_value(value: &mut Value) {
|
||||
match value {
|
||||
Value::Object(map) => {
|
||||
for child in map.values_mut() {
|
||||
sort_json_value(child);
|
||||
}
|
||||
let mut entries: Vec<(String, Value)> = std::mem::take(map).into_iter().collect();
|
||||
entries.sort_by(|(left, _), (right, _)| left.cmp(right));
|
||||
for (key, value) in entries {
|
||||
map.insert(key, value);
|
||||
}
|
||||
}
|
||||
Value::Array(items) => {
|
||||
for child in items {
|
||||
sort_json_value(child);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
/// Split a fully-qualified type name like "v2::Type" into its namespace and logical name.
|
||||
fn split_namespace(name: &str) -> (Option<&str>, &str) {
|
||||
name.split_once("::")
|
||||
|
||||
@@ -39,6 +39,7 @@ pub enum AuthMode {
|
||||
///
|
||||
/// ChatGPT auth tokens are supplied by an external host app and are only
|
||||
/// stored in memory. Token refresh must be handled by the external host app.
|
||||
#[cfg(feature = "codex-experimental-api")]
|
||||
#[serde(rename = "chatgptAuthTokens")]
|
||||
#[ts(rename = "chatgptAuthTokens")]
|
||||
#[strum(serialize = "chatgptAuthTokens")]
|
||||
@@ -56,6 +57,7 @@ macro_rules! client_request_definitions {
|
||||
$variant:ident $(=> $wire:literal)? {
|
||||
params: $(#[$params_meta:meta])* $params:ty,
|
||||
response: $response:ty,
|
||||
$(cfg: $cfg:meta,)?
|
||||
}
|
||||
),* $(,)?
|
||||
) => {
|
||||
@@ -65,6 +67,7 @@ macro_rules! client_request_definitions {
|
||||
pub enum ClientRequest {
|
||||
$(
|
||||
$(#[$variant_meta])*
|
||||
$(#[cfg($cfg)])?
|
||||
$(#[serde(rename = $wire)] #[ts(rename = $wire)])?
|
||||
$variant {
|
||||
#[serde(rename = "id")]
|
||||
@@ -79,7 +82,10 @@ macro_rules! client_request_definitions {
|
||||
out_dir: &::std::path::Path,
|
||||
) -> ::std::result::Result<(), ::ts_rs::ExportError> {
|
||||
$(
|
||||
<$response as ::ts_rs::TS>::export_all_to(out_dir)?;
|
||||
$(#[cfg($cfg)])?
|
||||
{
|
||||
<$response as ::ts_rs::TS>::export_all_to(out_dir)?;
|
||||
}
|
||||
)*
|
||||
Ok(())
|
||||
}
|
||||
@@ -90,7 +96,10 @@ macro_rules! client_request_definitions {
|
||||
) -> ::anyhow::Result<Vec<GeneratedSchema>> {
|
||||
let mut schemas = Vec::new();
|
||||
$(
|
||||
schemas.push(write_json_schema::<$response>(out_dir, stringify!($response))?);
|
||||
$(#[cfg($cfg)])?
|
||||
{
|
||||
schemas.push(write_json_schema::<$response>(out_dir, stringify!($response))?);
|
||||
}
|
||||
)*
|
||||
Ok(schemas)
|
||||
}
|
||||
@@ -101,7 +110,10 @@ macro_rules! client_request_definitions {
|
||||
) -> ::anyhow::Result<Vec<GeneratedSchema>> {
|
||||
let mut schemas = Vec::new();
|
||||
$(
|
||||
schemas.push(write_json_schema::<$params>(out_dir, stringify!($params))?);
|
||||
$(#[cfg($cfg)])?
|
||||
{
|
||||
schemas.push(write_json_schema::<$params>(out_dir, stringify!($params))?);
|
||||
}
|
||||
)*
|
||||
Ok(schemas)
|
||||
}
|
||||
@@ -185,6 +197,7 @@ client_request_definitions! {
|
||||
CollaborationModeList => "collaborationMode/list" {
|
||||
params: v2::CollaborationModeListParams,
|
||||
response: v2::CollaborationModeListResponse,
|
||||
cfg: feature = "codex-experimental-api",
|
||||
},
|
||||
|
||||
McpServerOauthLogin => "mcpServer/oauth/login" {
|
||||
@@ -368,6 +381,7 @@ macro_rules! server_request_definitions {
|
||||
$variant:ident $(=> $wire:literal)? {
|
||||
params: $params:ty,
|
||||
response: $response:ty,
|
||||
$(cfg: $cfg:meta,)?
|
||||
}
|
||||
),* $(,)?
|
||||
) => {
|
||||
@@ -377,6 +391,7 @@ macro_rules! server_request_definitions {
|
||||
pub enum ServerRequest {
|
||||
$(
|
||||
$(#[$variant_meta])*
|
||||
$(#[cfg($cfg)])?
|
||||
$(#[serde(rename = $wire)] #[ts(rename = $wire)])?
|
||||
$variant {
|
||||
#[serde(rename = "id")]
|
||||
@@ -388,13 +403,16 @@ macro_rules! server_request_definitions {
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, JsonSchema)]
|
||||
pub enum ServerRequestPayload {
|
||||
$( $variant($params), )*
|
||||
$( $(#[$variant_meta])* $(#[cfg($cfg)])? $variant($params), )*
|
||||
}
|
||||
|
||||
impl ServerRequestPayload {
|
||||
pub fn request_with_id(self, request_id: RequestId) -> ServerRequest {
|
||||
match self {
|
||||
$(Self::$variant(params) => ServerRequest::$variant { request_id, params },)*
|
||||
$(
|
||||
$(#[cfg($cfg)])?
|
||||
Self::$variant(params) => ServerRequest::$variant { request_id, params },
|
||||
)*
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -403,7 +421,10 @@ macro_rules! server_request_definitions {
|
||||
out_dir: &::std::path::Path,
|
||||
) -> ::std::result::Result<(), ::ts_rs::ExportError> {
|
||||
$(
|
||||
<$response as ::ts_rs::TS>::export_all_to(out_dir)?;
|
||||
$(#[cfg($cfg)])?
|
||||
{
|
||||
<$response as ::ts_rs::TS>::export_all_to(out_dir)?;
|
||||
}
|
||||
)*
|
||||
Ok(())
|
||||
}
|
||||
@@ -414,10 +435,13 @@ macro_rules! server_request_definitions {
|
||||
) -> ::anyhow::Result<Vec<GeneratedSchema>> {
|
||||
let mut schemas = Vec::new();
|
||||
$(
|
||||
schemas.push(crate::export::write_json_schema::<$response>(
|
||||
out_dir,
|
||||
concat!(stringify!($variant), "Response"),
|
||||
)?);
|
||||
$(#[cfg($cfg)])?
|
||||
{
|
||||
schemas.push(crate::export::write_json_schema::<$response>(
|
||||
out_dir,
|
||||
concat!(stringify!($variant), "Response"),
|
||||
)?);
|
||||
}
|
||||
)*
|
||||
Ok(schemas)
|
||||
}
|
||||
@@ -428,10 +452,13 @@ macro_rules! server_request_definitions {
|
||||
) -> ::anyhow::Result<Vec<GeneratedSchema>> {
|
||||
let mut schemas = Vec::new();
|
||||
$(
|
||||
schemas.push(crate::export::write_json_schema::<$params>(
|
||||
out_dir,
|
||||
concat!(stringify!($variant), "Params"),
|
||||
)?);
|
||||
$(#[cfg($cfg)])?
|
||||
{
|
||||
schemas.push(crate::export::write_json_schema::<$params>(
|
||||
out_dir,
|
||||
concat!(stringify!($variant), "Params"),
|
||||
)?);
|
||||
}
|
||||
)*
|
||||
Ok(schemas)
|
||||
}
|
||||
@@ -541,6 +568,7 @@ server_request_definitions! {
|
||||
ToolRequestUserInput => "item/tool/requestUserInput" {
|
||||
params: v2::ToolRequestUserInputParams,
|
||||
response: v2::ToolRequestUserInputResponse,
|
||||
cfg: feature = "codex-experimental-api",
|
||||
},
|
||||
|
||||
/// Execute a dynamic tool call on the client.
|
||||
@@ -552,6 +580,7 @@ server_request_definitions! {
|
||||
ChatgptAuthTokensRefresh => "account/chatgptAuthTokens/refresh" {
|
||||
params: v2::ChatgptAuthTokensRefreshParams,
|
||||
response: v2::ChatgptAuthTokensRefreshResponse,
|
||||
cfg: feature = "codex-experimental-api",
|
||||
},
|
||||
|
||||
/// DEPRECATED APIs below
|
||||
@@ -773,6 +802,7 @@ mod tests {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(feature = "codex-experimental-api")]
|
||||
#[test]
|
||||
fn serialize_chatgpt_auth_tokens_refresh_request() -> Result<()> {
|
||||
let request = ServerRequest::ChatgptAuthTokensRefresh {
|
||||
@@ -885,6 +915,7 @@ mod tests {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(feature = "codex-experimental-api")]
|
||||
#[test]
|
||||
fn serialize_account_login_chatgpt_auth_tokens() -> Result<()> {
|
||||
let request = ClientRequest::LoginAccount {
|
||||
@@ -976,6 +1007,7 @@ mod tests {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(feature = "codex-experimental-api")]
|
||||
#[test]
|
||||
fn serialize_list_collaboration_modes() -> Result<()> {
|
||||
let request = ClientRequest::CollaborationModeList {
|
||||
|
||||
@@ -432,6 +432,7 @@ pub struct SendUserMessageResponse {}
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct AddConversationListenerParams {
|
||||
pub conversation_id: ThreadId,
|
||||
#[cfg(feature = "codex-experimental-api")]
|
||||
#[serde(default)]
|
||||
pub experimental_raw_events: bool,
|
||||
}
|
||||
|
||||
@@ -4,7 +4,9 @@ use std::path::PathBuf;
|
||||
use crate::protocol::common::AuthMode;
|
||||
use codex_protocol::account::PlanType;
|
||||
use codex_protocol::approvals::ExecPolicyAmendment as CoreExecPolicyAmendment;
|
||||
#[cfg(feature = "codex-experimental-api")]
|
||||
use codex_protocol::config_types::CollaborationMode;
|
||||
#[cfg(feature = "codex-experimental-api")]
|
||||
use codex_protocol::config_types::CollaborationModeMask;
|
||||
use codex_protocol::config_types::ForcedLoginMethod;
|
||||
use codex_protocol::config_types::Personality;
|
||||
@@ -835,6 +837,7 @@ pub enum LoginAccountParams {
|
||||
#[serde(rename = "chatgpt")]
|
||||
#[ts(rename = "chatgpt")]
|
||||
Chatgpt,
|
||||
#[cfg(feature = "codex-experimental-api")]
|
||||
/// [UNSTABLE] FOR OPENAI INTERNAL USE ONLY - DO NOT USE.
|
||||
/// The access token must contain the same scopes that Codex-managed ChatGPT auth tokens have.
|
||||
#[serde(rename = "chatgptAuthTokens")]
|
||||
@@ -872,6 +875,7 @@ pub enum LoginAccountResponse {
|
||||
/// URL the client should open in a browser to initiate the OAuth flow.
|
||||
auth_url: String,
|
||||
},
|
||||
#[cfg(feature = "codex-experimental-api")]
|
||||
#[serde(rename = "chatgptAuthTokens", rename_all = "camelCase")]
|
||||
#[ts(rename = "chatgptAuthTokens", rename_all = "camelCase")]
|
||||
ChatgptAuthTokens {},
|
||||
@@ -905,6 +909,7 @@ pub struct CancelLoginAccountResponse {
|
||||
#[ts(export_to = "v2/")]
|
||||
pub struct LogoutAccountResponse {}
|
||||
|
||||
#[cfg(feature = "codex-experimental-api")]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(export_to = "v2/")]
|
||||
@@ -913,6 +918,7 @@ pub enum ChatgptAuthTokensRefreshReason {
|
||||
Unauthorized,
|
||||
}
|
||||
|
||||
#[cfg(feature = "codex-experimental-api")]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(export_to = "v2/")]
|
||||
@@ -928,6 +934,7 @@ pub struct ChatgptAuthTokensRefreshParams {
|
||||
pub previous_account_id: Option<String>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "codex-experimental-api")]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(export_to = "v2/")]
|
||||
@@ -1008,12 +1015,14 @@ pub struct ModelListResponse {
|
||||
pub next_cursor: Option<String>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "codex-experimental-api")]
|
||||
/// EXPERIMENTAL - list collaboration mode presets.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default, JsonSchema, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(export_to = "v2/")]
|
||||
pub struct CollaborationModeListParams {}
|
||||
|
||||
#[cfg(feature = "codex-experimental-api")]
|
||||
/// EXPERIMENTAL - collaboration mode presets response.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
@@ -1172,6 +1181,7 @@ pub struct ThreadStartParams {
|
||||
pub personality: Option<Personality>,
|
||||
pub ephemeral: Option<bool>,
|
||||
pub dynamic_tools: Option<Vec<DynamicToolSpec>>,
|
||||
#[cfg(feature = "codex-experimental-api")]
|
||||
/// If true, opt into emitting raw response items on the event stream.
|
||||
///
|
||||
/// This is for internal use only (e.g. Codex Cloud).
|
||||
@@ -1208,11 +1218,13 @@ pub struct ThreadStartResponse {
|
||||
pub struct ThreadResumeParams {
|
||||
pub thread_id: String,
|
||||
|
||||
#[cfg(feature = "codex-experimental-api")]
|
||||
/// [UNSTABLE] FOR CODEX CLOUD - DO NOT USE.
|
||||
/// If specified, the thread will be resumed with the provided history
|
||||
/// instead of loaded from disk.
|
||||
pub history: Option<Vec<ResponseItem>>,
|
||||
|
||||
#[cfg(feature = "codex-experimental-api")]
|
||||
/// [UNSTABLE] Specify the rollout path to resume from.
|
||||
/// If specified, the thread_id param will be ignored.
|
||||
pub path: Option<PathBuf>,
|
||||
@@ -1255,6 +1267,7 @@ pub struct ThreadResumeResponse {
|
||||
pub struct ThreadForkParams {
|
||||
pub thread_id: String,
|
||||
|
||||
#[cfg(feature = "codex-experimental-api")]
|
||||
/// [UNSTABLE] Specify the rollout path to fork from.
|
||||
/// If specified, the thread_id param will be ignored.
|
||||
pub path: Option<PathBuf>,
|
||||
@@ -1647,6 +1660,7 @@ pub struct Thread {
|
||||
/// Unix timestamp (in seconds) when the thread was last updated.
|
||||
#[ts(type = "number")]
|
||||
pub updated_at: i64,
|
||||
#[cfg(feature = "codex-experimental-api")]
|
||||
/// [UNSTABLE] Path to the thread on disk.
|
||||
pub path: Option<PathBuf>,
|
||||
/// Working directory captured for the thread.
|
||||
@@ -1800,6 +1814,7 @@ pub struct TurnStartParams {
|
||||
/// Optional JSON Schema used to constrain the final assistant message for this turn.
|
||||
pub output_schema: Option<JsonValue>,
|
||||
|
||||
#[cfg(feature = "codex-experimental-api")]
|
||||
/// EXPERIMENTAL - set a pre-set collaboration mode.
|
||||
/// Takes precedence over model, reasoning_effort, and developer instructions if set.
|
||||
pub collaboration_mode: Option<CollaborationMode>,
|
||||
@@ -2551,6 +2566,7 @@ pub struct FileChangeRequestApprovalParams {
|
||||
pub item_id: String,
|
||||
/// Optional explanatory reason (e.g. request for extra write access).
|
||||
pub reason: Option<String>,
|
||||
#[cfg(feature = "codex-experimental-api")]
|
||||
/// [UNSTABLE] When set, the agent is asking the user to allow writes under this root
|
||||
/// for the remainder of the session (unclear if this is honored today).
|
||||
pub grant_root: Option<PathBuf>,
|
||||
@@ -2581,6 +2597,7 @@ pub struct DynamicToolCallResponse {
|
||||
pub success: bool,
|
||||
}
|
||||
|
||||
#[cfg(feature = "codex-experimental-api")]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(export_to = "v2/")]
|
||||
@@ -2590,6 +2607,7 @@ pub struct ToolRequestUserInputOption {
|
||||
pub description: String,
|
||||
}
|
||||
|
||||
#[cfg(feature = "codex-experimental-api")]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(export_to = "v2/")]
|
||||
@@ -2605,6 +2623,7 @@ pub struct ToolRequestUserInputQuestion {
|
||||
pub options: Option<Vec<ToolRequestUserInputOption>>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "codex-experimental-api")]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(export_to = "v2/")]
|
||||
@@ -2616,6 +2635,7 @@ pub struct ToolRequestUserInputParams {
|
||||
pub questions: Vec<ToolRequestUserInputQuestion>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "codex-experimental-api")]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(export_to = "v2/")]
|
||||
@@ -2624,6 +2644,7 @@ pub struct ToolRequestUserInputAnswer {
|
||||
pub answers: Vec<String>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "codex-experimental-api")]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(export_to = "v2/")]
|
||||
|
||||
Reference in New Issue
Block a user