( toolId: string, connections: readonly ToolkitConnectionRecord[], policies: readonly ToolkitPolicyRecord[], defaultRequiresApproval?: boolean, )
| 151 | }; |
| 152 | |
| 153 | const resolveToolkitPolicy = ( |
| 154 | toolId: string, |
| 155 | connections: readonly ToolkitConnectionRecord[], |
| 156 | policies: readonly ToolkitPolicyRecord[], |
| 157 | defaultRequiresApproval?: boolean, |
| 158 | ): EffectivePolicy => { |
| 159 | const legacyPolicyIds = legacyConnectionPolicyIds(policies, connections); |
| 160 | const connected = |
| 161 | connections.some((connection) => matchPattern(connection.pattern, toolId)) || |
| 162 | policies.some( |
| 163 | (policy) => legacyPolicyIds.has(policy.id) && matchPattern(policy.pattern, toolId), |
| 164 | ); |
| 165 | if (!connected) return blockedPolicy(); |
| 166 | |
| 167 | for (const policy of [...policies].sort(comparePositioned)) { |
| 168 | if (legacyPolicyIds.has(policy.id)) continue; |
| 169 | if (!matchPattern(policy.pattern, toolId)) continue; |
| 170 | return { |
| 171 | action: policy.action, |
| 172 | source: "user", |
| 173 | pattern: policy.pattern, |
| 174 | policyId: policy.id, |
| 175 | }; |
| 176 | } |
| 177 | return pluginDefaultPolicy(defaultRequiresApproval); |
| 178 | }; |
| 179 | |
| 180 | const legacyConnectionPolicyIds = ( |
| 181 | policies: readonly ToolkitPolicyRecord[], |
no test coverage detected