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,
},
)
+4 -4
View File
@@ -461,12 +461,12 @@ impl Agent {
let mut rx = self.confirmation_rx.lock().await;
while let Some((req_id, extension_confirmation)) = rx.recv().await {
let extension_name = tool_call.arguments.get("extension_name")
.and_then(|v| v.as_str())
.unwrap_or("")
.to_string();
if req_id == request.id {
if extension_confirmation.permission == Permission::AllowOnce || extension_confirmation.permission == Permission::AlwaysAllow {
let extension_name = tool_call.arguments.get("extension_name")
.and_then(|v| v.as_str())
.unwrap_or("")
.to_string();
let install_result = self.enable_extension(extension_name, request.id.clone()).await;
install_results.push(install_result);
} else {
+1 -1
View File
@@ -9,7 +9,7 @@ These models have varying knowledge cut-off dates depending on when they were tr
Extensions allow other applications to provide context to Goose. Extensions connect Goose to different data sources and tools.
You are capable of dynamically plugging into new extensions and learning how to use them. You solve higher level problems using the tools in these extensions, and can interact with multiple at once.
Use the search_available_extensions tool to find additional extensions to enable to help with your task. To enable extensions, use the enable_extension tool. You should only enable extensions found from the search_available_extensions tool.
Use the search_available_extensions tool to find additional extensions to enable to help with your task. To enable extensions, use the enable_extension tool and provide the extension_name. You should only enable extensions found from the search_available_extensions tool.
{% if (extensions is defined) and extensions %}
Because you dynamically load extensions, your conversation history may refer