-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat(reborn): expose user-scoped tool settings #5256
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 5 commits
f201348
0c83023
69d10b9
8ae360e
e06400f
4e4ddc3
7cf4c40
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 |
|---|---|---|
|
|
@@ -64,6 +64,9 @@ use crate::router::{WebUiV2Capabilities, WebUiV2State}; | |
| use crate::schema::WebChatV2EventFrame; | ||
| use crate::sse_capacity::{SSE_MAX_LIFETIME, SseSlot}; | ||
|
|
||
| const SETTINGS_TOOLS_AUTO_APPROVE_KEY: &str = "agent.auto_approve_tools"; | ||
| const SETTINGS_TOOL_CONFIG_PREFIX: &str = "tool."; | ||
|
|
||
| #[derive(Debug, Clone, Serialize)] | ||
| pub struct WebUiV2SessionResponse { | ||
| pub tenant_id: String, | ||
|
|
@@ -1322,6 +1325,87 @@ pub async fn run_operator_setup( | |
| Ok(Json(response)) | ||
| } | ||
|
|
||
| /// `GET /api/webchat/v2/settings/tools` | ||
| pub async fn list_settings_tools( | ||
| State(state): State<WebUiV2State>, | ||
| Extension(caller): Extension<WebUiAuthenticatedCaller>, | ||
| ) -> Result<Json<RebornOperatorConfigListResponse>, WebUiV2HttpError> { | ||
| let mut response = state.services().list_operator_config(caller).await?; | ||
| response.entries.retain(|entry| { | ||
| entry.key == SETTINGS_TOOLS_AUTO_APPROVE_KEY | ||
| || entry.key.starts_with(SETTINGS_TOOL_CONFIG_PREFIX) | ||
| }); | ||
| Ok(Json(response)) | ||
| } | ||
|
|
||
| #[derive(Debug, Deserialize)] | ||
| pub struct SettingsToolsAutoApproveRequest { | ||
| pub enabled: bool, | ||
| } | ||
|
|
||
| /// `POST /api/webchat/v2/settings/tools` | ||
| pub async fn set_settings_tools_auto_approve( | ||
| State(state): State<WebUiV2State>, | ||
| Extension(caller): Extension<WebUiAuthenticatedCaller>, | ||
| Json(body): Json<SettingsToolsAutoApproveRequest>, | ||
| ) -> Result<Json<RebornOperatorConfigGetResponse>, WebUiV2HttpError> { | ||
| let response = state | ||
| .services() | ||
| .set_operator_config_key( | ||
| caller, | ||
| SETTINGS_TOOLS_AUTO_APPROVE_KEY.to_string(), | ||
| RebornOperatorConfigSetRequest { | ||
| value: serde_json::json!(body.enabled), | ||
| }, | ||
| ) | ||
| .await?; | ||
| Ok(Json(response)) | ||
| } | ||
|
|
||
| #[derive(Debug, Deserialize)] | ||
| pub struct SettingsToolPermissionPath { | ||
| pub capability_id: String, | ||
| } | ||
|
|
||
| #[derive(Debug, Deserialize)] | ||
| pub struct SettingsToolPermissionRequest { | ||
| pub state: String, | ||
| } | ||
|
|
||
| fn validate_settings_tool_permission_state(state: &str) -> Result<(), WebUiV2HttpError> { | ||
| match state { | ||
| "default" | "always_allow" | "ask_each_time" | "disabled" => Ok(()), | ||
| _ => Err(RebornServicesError::from(WebUiInboundValidationError::new( | ||
| "state", | ||
| WebUiInboundValidationCode::InvalidValue, | ||
| )) | ||
| .into()), | ||
| } | ||
| } | ||
|
|
||
| /// `POST /api/webchat/v2/settings/tools/{capability_id}` | ||
| pub async fn set_settings_tool_permission( | ||
| State(state): State<WebUiV2State>, | ||
| Extension(caller): Extension<WebUiAuthenticatedCaller>, | ||
| Path(SettingsToolPermissionPath { capability_id }): Path<SettingsToolPermissionPath>, | ||
| Json(body): Json<SettingsToolPermissionRequest>, | ||
| ) -> Result<Json<RebornOperatorConfigGetResponse>, WebUiV2HttpError> { | ||
| validate_settings_tool_permission_state(&body.state)?; | ||
| let key = | ||
| validate_operator_config_key(format!("{SETTINGS_TOOL_CONFIG_PREFIX}{capability_id}"))?; | ||
| let response = state | ||
| .services() | ||
| .set_operator_config_key( | ||
| caller, | ||
| key, | ||
| RebornOperatorConfigSetRequest { | ||
| value: serde_json::json!({ "state": body.state }), | ||
| }, | ||
| ) | ||
| .await?; | ||
| Ok(Json(response)) | ||
| } | ||
|
Comment on lines
+1389
to
+1412
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. The /// `POST /api/webchat/v2/settings/tools/{capability_id}`
pub async fn set_settings_tool_permission(
State(state): State<WebUiV2State>,
Extension(caller): Extension<WebUiAuthenticatedCaller>,
Path(SettingsToolPermissionPath { capability_id }): Path<SettingsToolPermissionPath>,
Json(body): Json<SettingsToolPermissionRequest>,
) -> Result<Json<RebornOperatorConfigGetResponse>, WebUiV2HttpError> {
match body.state.as_str() {
"default" | "always_allow" | "ask_each_time" | "disabled" => {}
_ => {
return Err(RebornServicesError::from(WebUiInboundValidationError::new(
"state",
WebUiInboundValidationCode::InvalidValue,
))
.into());
}
}
let key = validate_operator_config_key(format!("tool.{capability_id}"))?;
let response = state
.services()
.set_operator_config_key(
caller,
key,
RebornOperatorConfigSetRequest {
value: serde_json::json!({ "state": body.state }),
},
)
.await?;
Ok(Json(response))
}
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| /// `GET /api/webchat/v2/operator/config` | ||
| pub async fn list_operator_config( | ||
| State(state): State<WebUiV2State>, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.