Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
"Middleware",
"RestChannelServiceClientFactory",
"TurnContext",
"RouteRank",
"OutboundHostValidator",
"HttpRequestProtocol",
"HttpResponse",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@
RouteSelector = Callable[[TurnContext], bool]

StateT = TypeVar("StateT", bound=TurnState)
_StateContra = TypeVar("_StateContra", bound=TurnState, contravariant=True)
_RouteHandlerT = TypeVar("_RouteHandlerT", bound=Callable)


class _RouteDecorator(Protocol[_RouteHandlerT]):
"""Protocol for a decorator that registers *func* as a route and returns it unchanged."""

def __call__(self, func: _RouteHandlerT) -> _RouteHandlerT:
"""Register *func* as a route handler and return it.

:param func: The handler to register.
:return: The same handler, unmodified, so it can be used as a plain callable.
"""
...


class RouteHandler(Protocol[StateT]):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
RouteHandler,
HandoffHandler,
RouteSelector,
_RouteDecorator,
)
from ._routes import _RouteList, _Route, RouteRank, _agentic_selector
from .proactive import Proactive
Expand Down Expand Up @@ -377,7 +378,7 @@ def activity(
*,
auth_handlers: Optional[list[str]] = None,
**kwargs,
) -> Callable[[RouteHandler[StateT]], RouteHandler[StateT]]:
) -> _RouteDecorator[RouteHandler[StateT]]:
"""
Register a new activity event listener as either a decorator or a method.

Expand Down Expand Up @@ -416,7 +417,7 @@ def message(
*,
auth_handlers: Optional[list[str]] = None,
**kwargs,
) -> Callable[[RouteHandler[StateT]], RouteHandler[StateT]]:
) -> _RouteDecorator[RouteHandler[StateT]]:
"""
Register a new message activity event listener as either a decorator or a method.

Expand Down Expand Up @@ -470,7 +471,7 @@ def conversation_update(
*,
auth_handlers: Optional[list[str]] = None,
**kwargs,
) -> Callable[[RouteHandler[StateT]], RouteHandler[StateT]]:
) -> _RouteDecorator[RouteHandler[StateT]]:
"""
Register a handler for conversation update activities as either a decorator or a method.

Expand Down Expand Up @@ -526,7 +527,7 @@ def message_reaction(
*,
auth_handlers: Optional[list[str]] = None,
**kwargs,
) -> Callable[[RouteHandler[StateT]], RouteHandler[StateT]]:
) -> _RouteDecorator[RouteHandler[StateT]]:
"""
Register a handler for message reaction activities as either a decorator or a method.

Expand Down Expand Up @@ -578,7 +579,7 @@ def message_update(
*,
auth_handlers: Optional[list[str]] = None,
**kwargs,
) -> Callable[[RouteHandler[StateT]], RouteHandler[StateT]]:
) -> _RouteDecorator[RouteHandler[StateT]]:
"""
Register a handler for message update activities as either a decorator or a method.

Expand Down Expand Up @@ -652,24 +653,15 @@ def handoff(
*,
auth_handlers: Optional[list[str]] = None,
**kwargs: Any,
) -> Callable[
[HandoffHandler[StateT]],
HandoffHandler[StateT],
]: ...
) -> _RouteDecorator[HandoffHandler[StateT]]: ...

def handoff(
self,
func: Optional[HandoffHandler[StateT]] = None,
*,
auth_handlers: Optional[list[str]] = None,
**kwargs,
) -> (
HandoffHandler[StateT]
| Callable[
[HandoffHandler[StateT]],
HandoffHandler[StateT],
]
):
) -> HandoffHandler[StateT] | _RouteDecorator[HandoffHandler[StateT]]:
"""
Register a handler to hand off conversations from one copilot to another.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
RouteRank,
TurnContext,
)

from microsoft_agents.hosting.msteams.teams_turn_context import TeamsTurnContext
from microsoft_agents.hosting.msteams.type_defs import (
_RouteDecorator,
from microsoft_agents.hosting.core.app._type_defs import (
StateT,
_RouteDecorator,
)

from microsoft_agents.hosting.msteams.teams_turn_context import TeamsTurnContext
from microsoft_agents.hosting.msteams._utils import (
_get_channel_event_type,
_get_channel_info,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
from typing import Awaitable, Protocol

from microsoft_teams.api.models.channel_data import ChannelInfo

from microsoft_agents.hosting.core.app._type_defs import _StateContra
from microsoft_agents.hosting.msteams.teams_turn_context import TeamsTurnContext
from microsoft_agents.hosting.msteams.type_defs import _StateContra


class ChannelUpdateHandler(Protocol[_StateContra]):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
RouteRank,
TurnContext,
)

from microsoft_agents.hosting.msteams.teams_turn_context import TeamsTurnContext
from microsoft_agents.hosting.msteams.type_defs import (
_RouteDecorator,
from microsoft_agents.hosting.core.app._type_defs import (
StateT,
_RouteDecorator,
)

from microsoft_agents.hosting.msteams.teams_turn_context import TeamsTurnContext
from microsoft_agents.hosting.msteams._utils import _send_invoke_response

from .route_handlers import ConfigHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
from typing import Any, Awaitable, Protocol

from microsoft_teams.api.models.config import ConfigResponse

from microsoft_agents.hosting.core.app._type_defs import _StateContra
from microsoft_agents.hosting.msteams.teams_turn_context import TeamsTurnContext
from microsoft_agents.hosting.msteams.type_defs import _StateContra


class ConfigHandler(Protocol[_StateContra]):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
RouteRank,
TurnContext,
)

from microsoft_agents.hosting.msteams.teams_turn_context import TeamsTurnContext
from microsoft_agents.hosting.msteams.type_defs import (
_RouteDecorator,
from microsoft_agents.hosting.core.app._type_defs import (
StateT,
_RouteDecorator,
)

from microsoft_agents.hosting.msteams.teams_turn_context import TeamsTurnContext
from microsoft_agents.hosting.msteams._utils import _send_invoke_response

from .route_handlers import FileConsentHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
from typing import Awaitable, Protocol

from microsoft_teams.api.models import FileConsentCardResponse

from microsoft_agents.hosting.core.app._type_defs import _StateContra
from microsoft_agents.hosting.msteams.teams_turn_context import TeamsTurnContext
from microsoft_agents.hosting.msteams.type_defs import _StateContra


class FileConsentHandler(Protocol[_StateContra]):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
RouteRank,
TurnContext,
)

from microsoft_agents.hosting.msteams.teams_turn_context import TeamsTurnContext
from microsoft_agents.hosting.msteams.type_defs import (
_RouteDecorator,
from microsoft_agents.hosting.core.app._type_defs import (
StateT,
_RouteDecorator,
)

from microsoft_agents.hosting.msteams.teams_turn_context import TeamsTurnContext

from .route_handlers import (
MeetingStartHandler,
MeetingEndHandler,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
from microsoft_teams.api.models.meetings import MeetingDetails
from microsoft_agents.activity.teams import MeetingParticipantsEventDetails

from microsoft_agents.hosting.core.app._type_defs import _StateContra
from microsoft_agents.hosting.msteams.teams_turn_context import TeamsTurnContext
from microsoft_agents.hosting.msteams.type_defs import _StateContra


class MeetingStartHandler(Protocol[_StateContra]):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
RouteRank,
TurnContext,
)
from microsoft_agents.hosting.core.app._type_defs import (
StateT,
_RouteDecorator,
)

from microsoft_agents.hosting.msteams.route_handlers import (
TeamsRouteHandler,
wrap_teams_route_handler,
)
from microsoft_agents.hosting.msteams.teams_turn_context import TeamsTurnContext
from microsoft_agents.hosting.msteams.type_defs import (
_RouteDecorator,
StateT,
)
from microsoft_agents.hosting.msteams._utils import (
_get_channel_event_type,
_send_invoke_response,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

from microsoft_teams.api.models.o365 import O365ConnectorCardActionQuery

from microsoft_agents.hosting.core.app._type_defs import _StateContra

from microsoft_agents.hosting.msteams.teams_turn_context import TeamsTurnContext
from microsoft_agents.hosting.msteams.type_defs import _StateContra


class ExecuteActionHandler(Protocol[_StateContra]):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
RouteRank,
TurnContext,
)

from microsoft_agents.hosting.msteams.teams_turn_context import TeamsTurnContext
from microsoft_agents.hosting.msteams.type_defs import (
from microsoft_agents.hosting.core.app._type_defs import (
StateT,
CommandSelector,
_RouteDecorator,
)

from microsoft_agents.hosting.msteams.teams_turn_context import TeamsTurnContext

from microsoft_agents.hosting.msteams.type_defs import CommandSelector

from microsoft_agents.hosting.msteams._utils import (
_get_command_id,
_match_selector,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
)

from microsoft_agents.activity import Activity
from microsoft_agents.hosting.core.app._type_defs import _StateContra

from microsoft_agents.hosting.msteams.teams_turn_context import TeamsTurnContext
from microsoft_agents.hosting.msteams.type_defs import _StateContra


class FetchActionHandler(Protocol[_StateContra]):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
from microsoft_agents.hosting.core.app._type_defs import (
RouteHandler,
HandoffHandler,
_StateContra,
)

from .teams_turn_context import TeamsTurnContext
from .type_defs import _StateContra


class TeamsRouteHandler(Protocol[_StateContra]):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

from microsoft_teams.api.models import TaskModuleRequest, TaskModuleResponse

from microsoft_agents.hosting.core.app._type_defs import _StateContra

from microsoft_agents.hosting.msteams.teams_turn_context import TeamsTurnContext
from microsoft_agents.hosting.msteams.type_defs import _StateContra


class FetchHandler(Protocol[_StateContra]):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@
from microsoft_agents.activity import ActivityTypes

from microsoft_agents.hosting.core import AgentApplication, RouteRank, TurnContext
from microsoft_agents.hosting.core.app._type_defs import _RouteDecorator, StateT

from microsoft_agents.hosting.msteams.teams_turn_context import TeamsTurnContext
from microsoft_agents.hosting.msteams.type_defs import (
CommandSelector,
_RouteDecorator,
StateT,
)
from microsoft_agents.hosting.msteams.type_defs import CommandSelector

from microsoft_agents.hosting.msteams._utils import (
_match_selector,
_send_invoke_response,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
from typing import Awaitable, Protocol

from microsoft_teams.api.models.channel_data import TeamInfo

from microsoft_agents.hosting.core.app._type_defs import _StateContra
from microsoft_agents.hosting.msteams.teams_turn_context import TeamsTurnContext
from microsoft_agents.hosting.msteams.type_defs import _StateContra


class TeamUpdateHandler(Protocol[_StateContra]):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
RouteRank,
TurnContext,
)

from microsoft_agents.hosting.msteams.teams_turn_context import TeamsTurnContext
from microsoft_agents.hosting.msteams.type_defs import (
from microsoft_agents.hosting.core.app._type_defs import (
_RouteDecorator,
StateT,
)

from microsoft_agents.hosting.msteams.teams_turn_context import TeamsTurnContext
from microsoft_agents.hosting.msteams._utils import (
_get_channel_event_type,
_get_team_info,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@
AgentApplication,
TurnContext,
)
from microsoft_agents.hosting.core.app._type_defs import RouteHandler, HandoffHandler
from microsoft_agents.hosting.core.app._type_defs import (
RouteHandler,
HandoffHandler,
StateT,
)

from .channel import Channel
from .config import Config
Expand Down Expand Up @@ -63,9 +67,6 @@
)
from ._utils import _try_get_channel_data

from .teams_activity import TeamsActivity
from .type_defs import StateT


class _AppRouteDecorator(Protocol[StateT]):
"""Protocol for a decorator returned by :class:`TeamsAgentExtension` route methods."""
Expand Down
Loading