diff --git a/libraries/microsoft-agents-hosting-aiohttp/microsoft_agents/hosting/aiohttp/_aiohttp_request_adapter.py b/libraries/microsoft-agents-hosting-aiohttp/microsoft_agents/hosting/aiohttp/_aiohttp_request_adapter.py new file mode 100644 index 00000000..97362cee --- /dev/null +++ b/libraries/microsoft-agents-hosting-aiohttp/microsoft_agents/hosting/aiohttp/_aiohttp_request_adapter.py @@ -0,0 +1,28 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +from aiohttp.web import Request + + +class AiohttpRequestAdapter: + """Adapter to make aiohttp Request compatible with HttpRequestProtocol.""" + + def __init__(self, request: Request): + self._request = request + + @property + def method(self) -> str: + return self._request.method + + @property + def headers(self): + return self._request.headers + + async def json(self): + return await self._request.json() + + def get_claims_identity(self): + return self._request.get("claims_identity") + + def get_path_param(self, name: str) -> str: + return self._request.match_info[name] diff --git a/libraries/microsoft-agents-hosting-aiohttp/microsoft_agents/hosting/aiohttp/_start_agent_process.py b/libraries/microsoft-agents-hosting-aiohttp/microsoft_agents/hosting/aiohttp/_start_agent_process.py index bba42c8f..c05da7db 100644 --- a/libraries/microsoft-agents-hosting-aiohttp/microsoft_agents/hosting/aiohttp/_start_agent_process.py +++ b/libraries/microsoft-agents-hosting-aiohttp/microsoft_agents/hosting/aiohttp/_start_agent_process.py @@ -1,3 +1,6 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + from typing import Optional from aiohttp.web import Request, Response from microsoft_agents.hosting.core import error_resources diff --git a/libraries/microsoft-agents-hosting-aiohttp/microsoft_agents/hosting/aiohttp/channel_service_route_table.py b/libraries/microsoft-agents-hosting-aiohttp/microsoft_agents/hosting/aiohttp/channel_service_route_table.py index eb9ace8d..676082f3 100644 --- a/libraries/microsoft-agents-hosting-aiohttp/microsoft_agents/hosting/aiohttp/channel_service_route_table.py +++ b/libraries/microsoft-agents-hosting-aiohttp/microsoft_agents/hosting/aiohttp/channel_service_route_table.py @@ -6,29 +6,7 @@ from microsoft_agents.hosting.core import ChannelApiHandlerProtocol from microsoft_agents.hosting.core.http import ChannelServiceRoutes - -class AiohttpRequestAdapter: - """Adapter for aiohttp requests to use with ChannelServiceRoutes.""" - - def __init__(self, request: Request): - self._request = request - - @property - def method(self) -> str: - return self._request.method - - @property - def headers(self): - return self._request.headers - - async def json(self): - return await self._request.json() - - def get_claims_identity(self): - return self._request.get("claims_identity") - - def get_path_param(self, name: str) -> str: - return self._request.match_info[name] +from ._aiohttp_request_adapter import AiohttpRequestAdapter def channel_service_route_table( diff --git a/libraries/microsoft-agents-hosting-aiohttp/microsoft_agents/hosting/aiohttp/cloud_adapter.py b/libraries/microsoft-agents-hosting-aiohttp/microsoft_agents/hosting/aiohttp/cloud_adapter.py index 90757981..17aef2f3 100644 --- a/libraries/microsoft-agents-hosting-aiohttp/microsoft_agents/hosting/aiohttp/cloud_adapter.py +++ b/libraries/microsoft-agents-hosting-aiohttp/microsoft_agents/hosting/aiohttp/cloud_adapter.py @@ -13,30 +13,7 @@ from microsoft_agents.hosting.core import ChannelServiceClientFactoryBase from .agent_http_adapter import AgentHttpAdapter - - -class AiohttpRequestAdapter: - """Adapter to make aiohttp Request compatible with HttpRequestProtocol.""" - - def __init__(self, request: Request): - self._request = request - - @property - def method(self) -> str: - return self._request.method - - @property - def headers(self): - return self._request.headers - - async def json(self): - return await self._request.json() - - def get_claims_identity(self): - return self._request.get("claims_identity") - - def get_path_param(self, name: str) -> str: - return self._request.match_info[name] +from ._aiohttp_request_adapter import AiohttpRequestAdapter class CloudAdapter(HttpAdapterBase, AgentHttpAdapter): diff --git a/libraries/microsoft-agents-hosting-fastapi/microsoft_agents/hosting/fastapi/_fastapi_request_adapter.py b/libraries/microsoft-agents-hosting-fastapi/microsoft_agents/hosting/fastapi/_fastapi_request_adapter.py new file mode 100644 index 00000000..d733a450 --- /dev/null +++ b/libraries/microsoft-agents-hosting-fastapi/microsoft_agents/hosting/fastapi/_fastapi_request_adapter.py @@ -0,0 +1,28 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +from fastapi import Request + + +class FastApiRequestAdapter: + """Adapter to make FastAPI Request compatible with HttpRequestProtocol.""" + + def __init__(self, request: Request): + self._request = request + + @property + def method(self) -> str: + return self._request.method + + @property + def headers(self): + return self._request.headers + + async def json(self): + return await self._request.json() + + def get_claims_identity(self): + return getattr(self._request.state, "claims_identity", None) + + def get_path_param(self, name: str) -> str: + return self._request.path_params.get(name, "") diff --git a/libraries/microsoft-agents-hosting-fastapi/microsoft_agents/hosting/fastapi/channel_service_route_table.py b/libraries/microsoft-agents-hosting-fastapi/microsoft_agents/hosting/fastapi/channel_service_route_table.py index b8a44b5e..144244eb 100644 --- a/libraries/microsoft-agents-hosting-fastapi/microsoft_agents/hosting/fastapi/channel_service_route_table.py +++ b/libraries/microsoft-agents-hosting-fastapi/microsoft_agents/hosting/fastapi/channel_service_route_table.py @@ -7,29 +7,7 @@ from microsoft_agents.hosting.core import ChannelApiHandlerProtocol from microsoft_agents.hosting.core.http import ChannelServiceRoutes - -class FastApiRequestAdapter: - """Adapter for FastAPI requests to use with ChannelServiceRoutes.""" - - def __init__(self, request: Request): - self._request = request - - @property - def method(self) -> str: - return self._request.method - - @property - def headers(self): - return self._request.headers - - async def json(self): - return await self._request.json() - - def get_claims_identity(self): - return getattr(self._request.state, "claims_identity", None) - - def get_path_param(self, name: str) -> str: - return self._request.path_params.get(name, "") +from ._fastapi_request_adapter import FastApiRequestAdapter def channel_service_route_table( diff --git a/libraries/microsoft-agents-hosting-fastapi/microsoft_agents/hosting/fastapi/cloud_adapter.py b/libraries/microsoft-agents-hosting-fastapi/microsoft_agents/hosting/fastapi/cloud_adapter.py index 88df51e3..15f477fa 100644 --- a/libraries/microsoft-agents-hosting-fastapi/microsoft_agents/hosting/fastapi/cloud_adapter.py +++ b/libraries/microsoft-agents-hosting-fastapi/microsoft_agents/hosting/fastapi/cloud_adapter.py @@ -14,30 +14,7 @@ from microsoft_agents.hosting.core import ChannelServiceClientFactoryBase from .agent_http_adapter import AgentHttpAdapter - - -class FastApiRequestAdapter: - """Adapter to make FastAPI Request compatible with HttpRequestProtocol.""" - - def __init__(self, request: Request): - self._request = request - - @property - def method(self) -> str: - return self._request.method - - @property - def headers(self): - return self._request.headers - - async def json(self): - return await self._request.json() - - def get_claims_identity(self): - return getattr(self._request.state, "claims_identity", None) - - def get_path_param(self, name: str) -> str: - return self._request.path_params.get(name, "") +from ._fastapi_request_adapter import FastApiRequestAdapter class CloudAdapter(HttpAdapterBase, AgentHttpAdapter): @@ -46,8 +23,8 @@ class CloudAdapter(HttpAdapterBase, AgentHttpAdapter): def __init__( self, *, - connection_manager: Connections = None, - channel_service_client_factory: ChannelServiceClientFactoryBase = None, + connection_manager: Connections | None = None, + channel_service_client_factory: ChannelServiceClientFactoryBase | None = None, ): """ Initializes a new instance of the CloudAdapter class.