({
state,
ask,
text,
isProtected,
}: {
state?: Pick<ExtensionState, AutoApprovalState | AutoApprovalStateOptions>
ask: ClineAsk
text?: string
isProtected?: boolean
})
| 45 | } |
| 46 | |
| 47 | export async function checkAutoApproval({ |
| 48 | state, |
| 49 | ask, |
| 50 | text, |
| 51 | isProtected, |
| 52 | }: { |
| 53 | state?: Pick<ExtensionState, AutoApprovalState | AutoApprovalStateOptions> |
| 54 | ask: ClineAsk |
| 55 | text?: string |
| 56 | isProtected?: boolean |
| 57 | }): Promise<CheckAutoApprovalResult> { |
| 58 | if (isNonBlockingAsk(ask)) { |
| 59 | return { decision: "approve" } |
| 60 | } |
| 61 | |
| 62 | if (!state || !state.autoApprovalEnabled) { |
| 63 | return { decision: "ask" } |
| 64 | } |
| 65 | |
| 66 | if (ask === "followup") { |
| 67 | if (state.alwaysAllowFollowupQuestions === true) { |
| 68 | try { |
| 69 | const suggestion = (JSON.parse(text || "{}") as FollowUpData).suggest?.[0] |
| 70 | |
| 71 | if ( |
| 72 | suggestion && |
| 73 | typeof state.followupAutoApproveTimeoutMs === "number" && |
| 74 | state.followupAutoApproveTimeoutMs > 0 |
| 75 | ) { |
| 76 | return { |
| 77 | decision: "timeout", |
| 78 | timeout: state.followupAutoApproveTimeoutMs, |
| 79 | fn: () => ({ askResponse: "messageResponse", text: suggestion.answer }), |
| 80 | } |
| 81 | } else { |
| 82 | return { decision: "ask" } |
| 83 | } |
| 84 | } catch (error) { |
| 85 | return { decision: "ask" } |
| 86 | } |
| 87 | } else { |
| 88 | return { decision: "ask" } |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | if (ask === "use_mcp_server") { |
| 93 | if (!text) { |
| 94 | return { decision: "ask" } |
| 95 | } |
| 96 | |
| 97 | try { |
| 98 | const mcpServerUse = JSON.parse(text) as McpServerUse |
| 99 | |
| 100 | if (mcpServerUse.type === "use_mcp_tool") { |
| 101 | return state.alwaysAllowMcp === true && isMcpToolAlwaysAllowed(mcpServerUse, state.mcpServers) |
| 102 | ? { decision: "approve" } |
| 103 | : { decision: "ask" } |
| 104 | } else if (mcpServerUse.type === "access_mcp_resource") { |
no test coverage detected