feat: enable extension from ui (#2117)

This commit is contained in:
Wendy Tang
2025-04-11 13:06:59 -07:00
committed by GitHub
parent 387432ec86
commit b030f845ce
9 changed files with 254 additions and 13 deletions
+15 -4
View File
@@ -365,16 +365,23 @@ async fn ask_handler(
}))
}
#[derive(Debug, Deserialize)]
struct ToolConfirmationRequest {
#[derive(Debug, Deserialize, Serialize)]
struct PermissionConfirmationRequest {
id: String,
confirmed: bool,
#[serde(default = "default_principal_type")]
principal_type: PrincipalType,
action: String,
}
fn default_principal_type() -> PrincipalType {
PrincipalType::Tool
}
async fn confirm_handler(
State(state): State<AppState>,
headers: HeaderMap,
Json(request): Json<ToolConfirmationRequest>,
Json(request): Json<PermissionConfirmationRequest>,
) -> Result<Json<Value>, StatusCode> {
// Verify secret key
let secret_key = headers
@@ -385,6 +392,10 @@ async fn confirm_handler(
if secret_key != state.secret_key {
return Err(StatusCode::UNAUTHORIZED);
}
tracing::info!(
"Received confirmation request: {}",
serde_json::to_string_pretty(&request).unwrap()
);
let agent = state.agent.clone();
let agent = agent.read().await;
@@ -401,7 +412,7 @@ async fn confirm_handler(
.handle_confirmation(
request.id.clone(),
PermissionConfirmation {
principal_type: PrincipalType::Tool,
principal_type: request.principal_type,
permission,
},
)