Hosting request adapter code deduplication - #499
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request refactors the hosting-layer request adapters for FastAPI and aiohttp by extracting framework-specific *RequestAdapter implementations into dedicated modules and updating call sites, while also standardizing file headers. This improves organization and reduces duplication across hosting adapters.
Changes:
- Extracted
FastApiRequestAdapterintofastapi/_fastapi_request_adapter.pyand updated FastAPI imports/usages. - Extracted
AiohttpRequestAdapterintoaiohttp/_aiohttp_request_adapter.pyand removed the in-file definition from the aiohttpcloud_adapter. - Added copyright/license headers to several FastAPI/aiohttp hosting modules.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| libraries/microsoft-agents-hosting-fastapi/microsoft_agents/hosting/fastapi/cloud_adapter.py | Removes inline FastAPI request adapter and switches to the new dedicated module; updates optional type syntax. |
| libraries/microsoft-agents-hosting-fastapi/microsoft_agents/hosting/fastapi/channel_service_route_table.py | Replaces inline FastAPI adapter with import from the new shared module. |
| libraries/microsoft-agents-hosting-fastapi/microsoft_agents/hosting/fastapi/_start_agent_process.py | Adds copyright/license header. |
| libraries/microsoft-agents-hosting-fastapi/microsoft_agents/hosting/fastapi/_fastapi_request_adapter.py | Introduces dedicated FastAPI request adapter module. |
| libraries/microsoft-agents-hosting-fastapi/microsoft_agents/hosting/fastapi/init.py | Adds copyright/license header. |
| libraries/microsoft-agents-hosting-aiohttp/microsoft_agents/hosting/aiohttp/cloud_adapter.py | Removes inline aiohttp request adapter in preparation for using the new dedicated module. |
| libraries/microsoft-agents-hosting-aiohttp/microsoft_agents/hosting/aiohttp/_start_agent_process.py | Adds copyright/license header. |
| libraries/microsoft-agents-hosting-aiohttp/microsoft_agents/hosting/aiohttp/_aiohttp_request_adapter.py | Introduces dedicated aiohttp request adapter module. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
a7e12a1
into
main
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (2)
libraries/microsoft-agents-hosting-fastapi/microsoft_agents/hosting/fastapi/_fastapi_request_adapter.py:22
HttpRequestProtocol.headers/json()are typed asdict[...], but this adapter currently returns framework-specific header objects and an unvalidated JSON payload. This breaks structural typing and can allow non-object JSON through until later validation. Consider normalizing headers into a plain dict (while preserving common header-case lookups) and enforcing thatjson()returns a JSON object.
@property
def headers(self):
return self._request.headers
async def json(self):
return await self._request.json()
libraries/microsoft-agents-hosting-aiohttp/microsoft_agents/hosting/aiohttp/_aiohttp_request_adapter.py:22
HttpRequestProtocol.headers/json()are typed asdict[...], but this adapter currently returns aiohttp's multi-dict headers object and an unvalidated JSON payload. This breaks structural typing and can allow non-object JSON through until later validation. Normalize headers into a plain dict (preserving common header-case lookups), enforce thatjson()returns a JSON object, and makeget_path_paramreturn a default value instead of raisingKeyError.
@property
def headers(self):
return self._request.headers
async def json(self):
return await self._request.json()
This pull request refactors the
FastApiRequestAdapterandAiohttpRequestAdapterclasses to improve code organization and reusability. The adapter classes are moved from multiple locations into their dedicated modules, and all relevant imports are updated. Additionally, copyright headers are added to several files.Adapter class refactoring and code organization:
FastApiRequestAdapterimplementation fromcloud_adapter.pyandchannel_service_route_table.pyinto a new dedicated module,_fastapi_request_adapter.py, and updated imports accordingly. [1] [2] [3]AiohttpRequestAdapterimplementation fromcloud_adapter.pyinto a new dedicated module,_aiohttp_request_adapter.py, and updated imports accordingly. [1] [2]Code style and documentation:
__init__.py. [1] [2] [3] [4] [5]Type annotations:
CloudAdapterconstructor to use| Nonesyntax for optional parameters.