mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-02-03 19:35:15 -05:00
fix: address PR review feedback
- Remove inline comments per code style guidelines - Add scope checking to credential matching (was missing after refactor) - Update find_matching_credential to take CredentialsFieldInfo and check scopes - Remove redundant comments in routes.py, run_block.py, utils.py, validation.py
This commit is contained in:
@@ -21,8 +21,8 @@ config = ChatConfig()
|
||||
SSE_RESPONSE_HEADERS = {
|
||||
"Cache-Control": "no-cache",
|
||||
"Connection": "keep-alive",
|
||||
"X-Accel-Buffering": "no", # Disable nginx buffering
|
||||
"x-vercel-ai-ui-message-stream": "v1", # AI SDK protocol header
|
||||
"X-Accel-Buffering": "no",
|
||||
"x-vercel-ai-ui-message-stream": "v1",
|
||||
}
|
||||
|
||||
|
||||
@@ -91,7 +91,6 @@ async def _create_stream_generator(
|
||||
"first_chunk_type": first_chunk_type,
|
||||
},
|
||||
)
|
||||
# AI SDK protocol termination
|
||||
yield "data: [DONE]\n\n"
|
||||
|
||||
|
||||
|
||||
@@ -102,13 +102,11 @@ class RunBlockTool(BaseTool):
|
||||
Returns:
|
||||
tuple[matched_credentials, missing_credentials]
|
||||
"""
|
||||
# Get credential requirements from block
|
||||
requirements = self._get_credentials_requirements(block)
|
||||
|
||||
if not requirements:
|
||||
return {}, []
|
||||
|
||||
# Use shared matching logic
|
||||
return await match_credentials_to_requirements(user_id, requirements)
|
||||
|
||||
async def _execute(
|
||||
|
||||
@@ -241,28 +241,27 @@ async def get_user_credentials(user_id: str) -> list:
|
||||
|
||||
def find_matching_credential(
|
||||
available_creds: list,
|
||||
required_providers: frozenset[str] | set[str],
|
||||
required_types: frozenset[str] | set[str],
|
||||
field_info: CredentialsFieldInfo,
|
||||
):
|
||||
"""
|
||||
Find a credential that matches the required provider and type.
|
||||
Find a credential that matches the required provider, type, and scopes.
|
||||
|
||||
Args:
|
||||
available_creds: List of user's available credentials
|
||||
required_providers: Set of acceptable provider names
|
||||
required_types: Set of acceptable credential types
|
||||
field_info: CredentialsFieldInfo with provider, type, and scope requirements
|
||||
|
||||
Returns:
|
||||
Matching credential or None
|
||||
"""
|
||||
return next(
|
||||
(
|
||||
cred
|
||||
for cred in available_creds
|
||||
if cred.provider in required_providers and cred.type in required_types
|
||||
),
|
||||
None,
|
||||
)
|
||||
for cred in available_creds:
|
||||
if cred.provider not in field_info.provider:
|
||||
continue
|
||||
if cred.type not in field_info.supported_types:
|
||||
continue
|
||||
if not _credential_has_required_scopes(cred, field_info):
|
||||
continue
|
||||
return cred
|
||||
return None
|
||||
|
||||
|
||||
def create_credential_meta_from_match(
|
||||
@@ -310,11 +309,7 @@ async def match_credentials_to_requirements(
|
||||
available_creds = await get_user_credentials(user_id)
|
||||
|
||||
for field_name, field_info in requirements.items():
|
||||
matching_cred = find_matching_credential(
|
||||
available_creds,
|
||||
field_info.provider,
|
||||
field_info.supported_types,
|
||||
)
|
||||
matching_cred = find_matching_credential(available_creds, field_info)
|
||||
|
||||
if matching_cred:
|
||||
try:
|
||||
@@ -326,7 +321,6 @@ async def match_credentials_to_requirements(
|
||||
f"credential_id={matching_cred.id}",
|
||||
exc_info=True,
|
||||
)
|
||||
# Add to missing with validation error
|
||||
provider = next(iter(field_info.provider), "unknown")
|
||||
cred_type = next(iter(field_info.supported_types), "api_key")
|
||||
missing.append(
|
||||
@@ -338,7 +332,6 @@ async def match_credentials_to_requirements(
|
||||
)
|
||||
)
|
||||
else:
|
||||
# Create a placeholder for the missing credential
|
||||
provider = next(iter(field_info.provider), "unknown")
|
||||
cred_type = next(iter(field_info.supported_types), "api_key")
|
||||
missing.append(
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
import re
|
||||
|
||||
# UUID v4 pattern - matches standard UUID v4 format
|
||||
_UUID_V4_PATTERN = re.compile(
|
||||
r"[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}",
|
||||
re.IGNORECASE,
|
||||
|
||||
Reference in New Issue
Block a user