-
Notifications
You must be signed in to change notification settings - Fork 6.7k
[app-server-protocol] Add types for config #7658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,14 +5,17 @@ use crate::protocol::common::AuthMode; | |
| use codex_protocol::account::PlanType; | ||
| use codex_protocol::approvals::ExecPolicyAmendment as CoreExecPolicyAmendment; | ||
| use codex_protocol::approvals::SandboxCommandAssessment as CoreSandboxCommandAssessment; | ||
| use codex_protocol::config_types::ForcedLoginMethod; | ||
| use codex_protocol::config_types::ReasoningSummary; | ||
| use codex_protocol::config_types::Verbosity; | ||
| use codex_protocol::items::AgentMessageContent as CoreAgentMessageContent; | ||
| use codex_protocol::items::TurnItem as CoreTurnItem; | ||
| use codex_protocol::models::ResponseItem; | ||
| use codex_protocol::openai_models::ReasoningEffort; | ||
| use codex_protocol::parse_command::ParsedCommand as CoreParsedCommand; | ||
| use codex_protocol::plan_tool::PlanItemArg as CorePlanItemArg; | ||
| use codex_protocol::plan_tool::StepStatus as CorePlanStepStatus; | ||
| use codex_protocol::protocol::AskForApproval as CoreAskForApproval; | ||
| use codex_protocol::protocol::CodexErrorInfo as CoreCodexErrorInfo; | ||
| use codex_protocol::protocol::CreditsSnapshot as CoreCreditsSnapshot; | ||
| use codex_protocol::protocol::RateLimitSnapshot as CoreRateLimitSnapshot; | ||
|
|
@@ -160,6 +163,123 @@ pub enum ConfigLayerName { | |
| User, | ||
| } | ||
|
|
||
| #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default, JsonSchema, TS)] | ||
| #[serde(rename_all = "snake_case")] | ||
| #[ts(export_to = "v2/")] | ||
| pub struct SandboxWorkspaceWrite { | ||
| #[serde(default)] | ||
| pub writable_roots: Vec<PathBuf>, | ||
| #[serde(default)] | ||
| pub network_access: bool, | ||
| #[serde(default)] | ||
| pub exclude_tmpdir_env_var: bool, | ||
| #[serde(default)] | ||
| pub exclude_slash_tmp: bool, | ||
| } | ||
|
|
||
| #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)] | ||
| #[serde(rename_all = "snake_case")] | ||
| #[ts(export_to = "v2/")] | ||
| pub struct ToolsV2 { | ||
| pub web_search: Option<bool>, | ||
| pub view_image: Option<bool>, | ||
| } | ||
|
|
||
| #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)] | ||
| #[serde(rename_all = "snake_case")] | ||
| #[ts(export_to = "v2/")] | ||
| pub struct ProfileV2 { | ||
| pub model: Option<String>, | ||
| pub model_provider: Option<String>, | ||
| #[serde( | ||
| default, | ||
| deserialize_with = "deserialize_approval_policy", | ||
| serialize_with = "serialize_approval_policy" | ||
| )] | ||
| pub approval_policy: Option<AskForApproval>, | ||
| pub model_reasoning_effort: Option<ReasoningEffort>, | ||
| pub model_reasoning_summary: Option<ReasoningSummary>, | ||
| pub model_verbosity: Option<Verbosity>, | ||
| pub chatgpt_base_url: Option<String>, | ||
| } | ||
|
|
||
| #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)] | ||
| #[serde(rename_all = "snake_case")] | ||
| #[ts(export_to = "v2/")] | ||
| pub struct Config { | ||
| pub model: Option<String>, | ||
| pub review_model: Option<String>, | ||
| pub model_context_window: Option<i64>, | ||
| pub model_auto_compact_token_limit: Option<i64>, | ||
| pub model_provider: Option<String>, | ||
| #[serde( | ||
| default, | ||
| deserialize_with = "deserialize_approval_policy", | ||
| serialize_with = "serialize_approval_policy" | ||
| )] | ||
| pub approval_policy: Option<AskForApproval>, | ||
| #[serde( | ||
| default, | ||
| deserialize_with = "deserialize_sandbox_mode", | ||
| serialize_with = "serialize_sandbox_mode" | ||
| )] | ||
| pub sandbox_mode: Option<SandboxMode>, | ||
| pub sandbox_workspace_write: Option<SandboxWorkspaceWrite>, | ||
| pub forced_chatgpt_workspace_id: Option<String>, | ||
| pub forced_login_method: Option<ForcedLoginMethod>, | ||
| pub tools: Option<ToolsV2>, | ||
| pub profile: Option<String>, | ||
| #[serde(default)] | ||
| pub profiles: HashMap<String, ProfileV2>, | ||
| pub instructions: Option<String>, | ||
| pub developer_instructions: Option<String>, | ||
| pub compact_prompt: Option<String>, | ||
| pub model_reasoning_effort: Option<ReasoningEffort>, | ||
| pub model_reasoning_summary: Option<ReasoningSummary>, | ||
| pub model_verbosity: Option<Verbosity>, | ||
| #[serde(default, flatten)] | ||
| pub additional: HashMap<String, JsonValue>, | ||
| } | ||
|
|
||
| fn deserialize_approval_policy<'de, D>(deserializer: D) -> Result<Option<AskForApproval>, D::Error> | ||
| where | ||
| D: serde::Deserializer<'de>, | ||
| { | ||
| let value = Option::<CoreAskForApproval>::deserialize(deserializer)?; | ||
| Ok(value.map(AskForApproval::from)) | ||
| } | ||
|
|
||
| fn serialize_approval_policy<S>( | ||
| value: &Option<AskForApproval>, | ||
| serializer: S, | ||
| ) -> Result<S::Ok, S::Error> | ||
| where | ||
| S: serde::Serializer, | ||
| { | ||
| value | ||
| .as_ref() | ||
| .map(|policy| policy.to_core()) | ||
| .serialize(serializer) | ||
|
Comment on lines
+258
to
+262
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Config now serializes approval/sandbox enums via the core helpers ( Useful? React with 👍 / 👎. |
||
| } | ||
|
|
||
| fn deserialize_sandbox_mode<'de, D>(deserializer: D) -> Result<Option<SandboxMode>, D::Error> | ||
| where | ||
| D: serde::Deserializer<'de>, | ||
| { | ||
| let value = Option::<codex_protocol::config_types::SandboxMode>::deserialize(deserializer)?; | ||
| Ok(value.map(SandboxMode::from)) | ||
| } | ||
|
|
||
| fn serialize_sandbox_mode<S>(value: &Option<SandboxMode>, serializer: S) -> Result<S::Ok, S::Error> | ||
| where | ||
| S: serde::Serializer, | ||
| { | ||
| value | ||
| .as_ref() | ||
| .map(|mode| mode.to_core()) | ||
| .serialize(serializer) | ||
| } | ||
|
|
||
| #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)] | ||
| #[serde(rename_all = "camelCase")] | ||
| #[ts(export_to = "v2/")] | ||
|
|
@@ -238,7 +358,7 @@ pub struct ConfigReadParams { | |
| #[serde(rename_all = "camelCase")] | ||
| #[ts(export_to = "v2/")] | ||
| pub struct ConfigReadResponse { | ||
| pub config: JsonValue, | ||
| pub config: Config, | ||
| pub origins: HashMap<String, ConfigLayerMetadata>, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| pub layers: Option<Vec<ConfigLayer>>, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need all those custom serializers? (make sure to just explain in comment)