diff --git a/autogpt_platform/backend/backend/api/features/chat/routes.py b/autogpt_platform/backend/backend/api/features/chat/routes.py index b1b865d1dc..270671d3f8 100644 --- a/autogpt_platform/backend/backend/api/features/chat/routes.py +++ b/autogpt_platform/backend/backend/api/features/chat/routes.py @@ -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" diff --git a/autogpt_platform/backend/backend/api/features/chat/tools/run_block.py b/autogpt_platform/backend/backend/api/features/chat/tools/run_block.py index 7ed6585a2a..73eb433584 100644 --- a/autogpt_platform/backend/backend/api/features/chat/tools/run_block.py +++ b/autogpt_platform/backend/backend/api/features/chat/tools/run_block.py @@ -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( diff --git a/autogpt_platform/backend/backend/api/features/chat/tools/utils.py b/autogpt_platform/backend/backend/api/features/chat/tools/utils.py index 64b004327f..6e78011721 100644 --- a/autogpt_platform/backend/backend/api/features/chat/tools/utils.py +++ b/autogpt_platform/backend/backend/api/features/chat/tools/utils.py @@ -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( diff --git a/autogpt_platform/backend/backend/util/validation.py b/autogpt_platform/backend/backend/util/validation.py index 14e6c15a49..3c22bc3c4c 100644 --- a/autogpt_platform/backend/backend/util/validation.py +++ b/autogpt_platform/backend/backend/util/validation.py @@ -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,