-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Feat: appServer.requirementList for requirement.toml #8800
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
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 |
|---|---|---|
|
|
@@ -3,13 +3,18 @@ use crate::error_code::INVALID_REQUEST_ERROR_CODE; | |
| use codex_app_server_protocol::ConfigBatchWriteParams; | ||
| use codex_app_server_protocol::ConfigReadParams; | ||
| use codex_app_server_protocol::ConfigReadResponse; | ||
| use codex_app_server_protocol::ConfigRequirements; | ||
| use codex_app_server_protocol::ConfigRequirementsReadResponse; | ||
| use codex_app_server_protocol::ConfigValueWriteParams; | ||
| use codex_app_server_protocol::ConfigWriteErrorCode; | ||
| use codex_app_server_protocol::ConfigWriteResponse; | ||
| use codex_app_server_protocol::JSONRPCErrorError; | ||
| use codex_app_server_protocol::SandboxMode; | ||
| use codex_core::config::ConfigService; | ||
| use codex_core::config::ConfigServiceError; | ||
| use codex_core::config_loader::ConfigRequirementsToml; | ||
| use codex_core::config_loader::LoaderOverrides; | ||
| use codex_core::config_loader::SandboxModeRequirement as CoreSandboxModeRequirement; | ||
| use serde_json::json; | ||
| use std::path::PathBuf; | ||
| use toml::Value as TomlValue; | ||
|
|
@@ -37,6 +42,19 @@ impl ConfigApi { | |
| self.service.read(params).await.map_err(map_error) | ||
| } | ||
|
|
||
| pub(crate) async fn config_requirements_read( | ||
| &self, | ||
| ) -> Result<ConfigRequirementsReadResponse, JSONRPCErrorError> { | ||
| let requirements = self | ||
| .service | ||
| .read_requirements() | ||
| .await | ||
| .map_err(map_error)? | ||
| .map(map_requirements_toml_to_api); | ||
|
|
||
| Ok(ConfigRequirementsReadResponse { requirements }) | ||
| } | ||
|
|
||
| pub(crate) async fn write_value( | ||
| &self, | ||
| params: ConfigValueWriteParams, | ||
|
|
@@ -52,6 +70,32 @@ impl ConfigApi { | |
| } | ||
| } | ||
|
|
||
| fn map_requirements_toml_to_api(requirements: ConfigRequirementsToml) -> ConfigRequirements { | ||
| ConfigRequirements { | ||
| allowed_approval_policies: requirements.allowed_approval_policies.map(|policies| { | ||
| policies | ||
| .into_iter() | ||
| .map(codex_app_server_protocol::AskForApproval::from) | ||
| .collect() | ||
| }), | ||
| allowed_sandbox_modes: requirements.allowed_sandbox_modes.map(|modes| { | ||
| modes | ||
| .into_iter() | ||
| .filter_map(map_sandbox_mode_requirement_to_api) | ||
| .collect() | ||
| }), | ||
| } | ||
| } | ||
|
|
||
| fn map_sandbox_mode_requirement_to_api(mode: CoreSandboxModeRequirement) -> Option<SandboxMode> { | ||
| match mode { | ||
| CoreSandboxModeRequirement::ReadOnly => Some(SandboxMode::ReadOnly), | ||
| CoreSandboxModeRequirement::WorkspaceWrite => Some(SandboxMode::WorkspaceWrite), | ||
| CoreSandboxModeRequirement::DangerFullAccess => Some(SandboxMode::DangerFullAccess), | ||
| CoreSandboxModeRequirement::ExternalSandbox => None, | ||
| } | ||
| } | ||
|
|
||
| fn map_error(err: ConfigServiceError) -> JSONRPCErrorError { | ||
| if let Some(code) = err.write_error_code() { | ||
| return config_write_error(code, err.to_string()); | ||
|
|
@@ -73,3 +117,38 @@ fn config_write_error(code: ConfigWriteErrorCode, message: impl Into<String>) -> | |
| })), | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use codex_protocol::protocol::AskForApproval as CoreAskForApproval; | ||
| use pretty_assertions::assert_eq; | ||
|
|
||
| #[test] | ||
| fn map_requirements_toml_to_api_converts_core_enums() { | ||
| let requirements = ConfigRequirementsToml { | ||
| allowed_approval_policies: Some(vec![ | ||
| CoreAskForApproval::Never, | ||
| CoreAskForApproval::OnRequest, | ||
| ]), | ||
| allowed_sandbox_modes: Some(vec![ | ||
| CoreSandboxModeRequirement::ReadOnly, | ||
| CoreSandboxModeRequirement::ExternalSandbox, | ||
|
Collaborator
Author
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. A little bit counterintuitive - |
||
| ]), | ||
| }; | ||
|
|
||
| let mapped = map_requirements_toml_to_api(requirements); | ||
|
|
||
| assert_eq!( | ||
| mapped.allowed_approval_policies, | ||
| Some(vec![ | ||
| codex_app_server_protocol::AskForApproval::Never, | ||
| codex_app_server_protocol::AskForApproval::OnRequest, | ||
| ]) | ||
| ); | ||
| assert_eq!( | ||
| mapped.allowed_sandbox_modes, | ||
| Some(vec![SandboxMode::ReadOnly]), | ||
| ); | ||
| } | ||
| } | ||
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.
For now we are not support any additional params for workspace-write because requirements.toml does not support that yet either.