microsoft-agents-hosting-core 0.4.0.dev16__py3-none-any.whl → 0.5.0.dev3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- microsoft_agents/hosting/core/__init__.py +2 -1
- microsoft_agents/hosting/core/_oauth/__init__.py +3 -0
- microsoft_agents/hosting/core/_oauth/_flow_state.py +2 -2
- microsoft_agents/hosting/core/_oauth/_oauth_flow.py +26 -23
- microsoft_agents/hosting/core/activity_handler.py +12 -11
- microsoft_agents/hosting/core/app/__init__.py +2 -1
- microsoft_agents/hosting/core/app/_routes/__init__.py +13 -0
- microsoft_agents/hosting/core/app/_routes/_route.py +89 -0
- microsoft_agents/hosting/core/app/_routes/_route_list.py +32 -0
- microsoft_agents/hosting/core/app/_routes/route_rank.py +14 -0
- microsoft_agents/hosting/core/app/_type_defs.py +15 -0
- microsoft_agents/hosting/core/app/agent_application.py +85 -45
- microsoft_agents/hosting/core/app/input_file.py +15 -11
- microsoft_agents/hosting/core/app/oauth/__init__.py +4 -0
- microsoft_agents/hosting/core/app/oauth/_handlers/__init__.py +5 -0
- microsoft_agents/hosting/core/app/oauth/_handlers/_authorization_handler.py +9 -4
- microsoft_agents/hosting/core/app/oauth/_handlers/_user_authorization.py +6 -4
- microsoft_agents/hosting/core/app/oauth/_handlers/agentic_user_authorization.py +8 -3
- microsoft_agents/hosting/core/app/oauth/_sign_in_response.py +4 -0
- microsoft_agents/hosting/core/app/oauth/_sign_in_state.py +5 -0
- microsoft_agents/hosting/core/app/oauth/auth_handler.py +4 -2
- microsoft_agents/hosting/core/app/oauth/authorization.py +6 -1
- microsoft_agents/hosting/core/authorization/access_token_provider_base.py +3 -0
- microsoft_agents/hosting/core/authorization/agent_auth_configuration.py +3 -0
- microsoft_agents/hosting/core/authorization/anonymous_token_provider.py +3 -0
- microsoft_agents/hosting/core/authorization/auth_types.py +3 -0
- microsoft_agents/hosting/core/authorization/connections.py +3 -0
- microsoft_agents/hosting/core/authorization/jwt_token_validator.py +3 -0
- microsoft_agents/hosting/core/channel_adapter.py +9 -9
- microsoft_agents/hosting/core/channel_api_handler_protocol.py +3 -0
- microsoft_agents/hosting/core/channel_service_adapter.py +1 -4
- microsoft_agents/hosting/core/channel_service_client_factory_base.py +3 -0
- microsoft_agents/hosting/core/client/agent_conversation_reference.py +3 -0
- microsoft_agents/hosting/core/client/channel_factory_protocol.py +3 -0
- microsoft_agents/hosting/core/client/channel_host_protocol.py +3 -0
- microsoft_agents/hosting/core/client/channel_info_protocol.py +3 -0
- microsoft_agents/hosting/core/client/channel_protocol.py +3 -0
- microsoft_agents/hosting/core/client/channels_configuration.py +3 -0
- microsoft_agents/hosting/core/client/configuration_channel_host.py +3 -0
- microsoft_agents/hosting/core/client/conversation_constants.py +3 -0
- microsoft_agents/hosting/core/client/conversation_id_factory.py +3 -0
- microsoft_agents/hosting/core/client/conversation_id_factory_options.py +3 -0
- microsoft_agents/hosting/core/client/conversation_id_factory_protocol.py +3 -0
- microsoft_agents/hosting/core/client/http_agent_channel.py +3 -0
- microsoft_agents/hosting/core/client/http_agent_channel_factory.py +3 -0
- microsoft_agents/hosting/core/connector/client/connector_client.py +0 -3
- microsoft_agents/hosting/core/connector/client/user_token_client.py +40 -43
- microsoft_agents/hosting/core/connector/user_token_base.py +77 -1
- microsoft_agents/hosting/core/connector/user_token_client_base.py +3 -0
- microsoft_agents/hosting/core/rest_channel_service_client_factory.py +3 -0
- microsoft_agents/hosting/core/state/agent_state.py +16 -20
- microsoft_agents/hosting/core/storage/error_handling.py +3 -0
- microsoft_agents/hosting/core/storage/memory_storage.py +3 -0
- microsoft_agents/hosting/core/storage/storage.py +3 -0
- microsoft_agents/hosting/core/storage/store_item.py +3 -0
- {microsoft_agents_hosting_core-0.4.0.dev16.dist-info → microsoft_agents_hosting_core-0.5.0.dev3.dist-info}/METADATA +2 -2
- {microsoft_agents_hosting_core-0.4.0.dev16.dist-info → microsoft_agents_hosting_core-0.5.0.dev3.dist-info}/RECORD +59 -55
- microsoft_agents/hosting/core/app/route.py +0 -32
- {microsoft_agents_hosting_core-0.4.0.dev16.dist-info → microsoft_agents_hosting_core-0.5.0.dev3.dist-info}/WHEEL +0 -0
- {microsoft_agents_hosting_core-0.4.0.dev16.dist-info → microsoft_agents_hosting_core-0.5.0.dev3.dist-info}/top_level.txt +0 -0
|
@@ -13,9 +13,7 @@ from typing import (
|
|
|
13
13
|
Any,
|
|
14
14
|
Awaitable,
|
|
15
15
|
Callable,
|
|
16
|
-
Dict,
|
|
17
16
|
Generic,
|
|
18
|
-
List,
|
|
19
17
|
Optional,
|
|
20
18
|
Pattern,
|
|
21
19
|
TypeVar,
|
|
@@ -38,16 +36,17 @@ from ..authorization import Connections
|
|
|
38
36
|
from .app_error import ApplicationError
|
|
39
37
|
from .app_options import ApplicationOptions
|
|
40
38
|
|
|
41
|
-
from .route import Route, RouteHandler
|
|
42
39
|
from .state import TurnState
|
|
43
40
|
from ..channel_service_adapter import ChannelServiceAdapter
|
|
44
41
|
from .oauth import Authorization
|
|
45
42
|
from .typing_indicator import TypingIndicator
|
|
46
43
|
|
|
44
|
+
from ._type_defs import RouteHandler, RouteSelector
|
|
45
|
+
from ._routes import _RouteList, _Route, RouteRank, _agentic_selector
|
|
46
|
+
|
|
47
47
|
logger = logging.getLogger(__name__)
|
|
48
48
|
|
|
49
49
|
StateT = TypeVar("StateT", bound=TurnState)
|
|
50
|
-
IN_SIGN_IN_KEY = "__InSignInFlow__"
|
|
51
50
|
|
|
52
51
|
|
|
53
52
|
class AgentApplication(Agent, Generic[StateT]):
|
|
@@ -68,25 +67,25 @@ class AgentApplication(Agent, Generic[StateT]):
|
|
|
68
67
|
_options: ApplicationOptions
|
|
69
68
|
_adapter: Optional[ChannelServiceAdapter] = None
|
|
70
69
|
_auth: Optional[Authorization] = None
|
|
71
|
-
_internal_before_turn:
|
|
72
|
-
_internal_after_turn:
|
|
73
|
-
|
|
70
|
+
_internal_before_turn: list[Callable[[TurnContext, StateT], Awaitable[bool]]] = []
|
|
71
|
+
_internal_after_turn: list[Callable[[TurnContext, StateT], Awaitable[bool]]] = []
|
|
72
|
+
_route_list: _RouteList[StateT] = _RouteList[StateT]()
|
|
74
73
|
_error: Optional[Callable[[TurnContext, Exception], Awaitable[None]]] = None
|
|
75
74
|
_turn_state_factory: Optional[Callable[[TurnContext], StateT]] = None
|
|
76
75
|
|
|
77
76
|
def __init__(
|
|
78
77
|
self,
|
|
79
|
-
options: ApplicationOptions = None,
|
|
78
|
+
options: Optional[ApplicationOptions] = None,
|
|
80
79
|
*,
|
|
81
|
-
connection_manager: Connections = None,
|
|
82
|
-
authorization: Authorization = None,
|
|
80
|
+
connection_manager: Optional[Connections] = None,
|
|
81
|
+
authorization: Optional[Authorization] = None,
|
|
83
82
|
**kwargs,
|
|
84
83
|
) -> None:
|
|
85
84
|
"""
|
|
86
85
|
Creates a new AgentApplication instance.
|
|
87
86
|
"""
|
|
88
87
|
self.typing = TypingIndicator()
|
|
89
|
-
self.
|
|
88
|
+
self._route_list = _RouteList[StateT]()
|
|
90
89
|
|
|
91
90
|
configuration = kwargs
|
|
92
91
|
|
|
@@ -204,11 +203,54 @@ class AgentApplication(Agent, Generic[StateT]):
|
|
|
204
203
|
"""
|
|
205
204
|
return self._options
|
|
206
205
|
|
|
206
|
+
def add_route(
|
|
207
|
+
self,
|
|
208
|
+
selector: RouteSelector,
|
|
209
|
+
handler: RouteHandler[StateT],
|
|
210
|
+
is_invoke: bool = False,
|
|
211
|
+
is_agentic: bool = False,
|
|
212
|
+
rank: RouteRank = RouteRank.DEFAULT,
|
|
213
|
+
auth_handlers: Optional[list[str]] = None,
|
|
214
|
+
) -> None:
|
|
215
|
+
"""Adds a new route to the application.
|
|
216
|
+
|
|
217
|
+
Routes are ordered by: is_agentic, is_invoke, rank (lower is higher priority), in that order.
|
|
218
|
+
|
|
219
|
+
:param selector: A function that takes a TurnContext and returns a boolean indicating whether the route should be selected.
|
|
220
|
+
:type selector: RouteSelector
|
|
221
|
+
:param handler: A function that takes a TurnContext and a TurnState and returns an Awaitable.
|
|
222
|
+
:type handler: RouteHandler[StateT]
|
|
223
|
+
:param is_invoke: Whether the route is for an invoke activity, defaults to False
|
|
224
|
+
:type is_invoke: bool, Optional
|
|
225
|
+
:param is_agentic: Whether the route is for an agentic request, defaults to False. For agentic requests
|
|
226
|
+
the selector will include a new check for `context.activity.is_agentic_request()`.
|
|
227
|
+
:type is_agentic: bool, Optional
|
|
228
|
+
:param rank: The rank of the route, defaults to RouteRank.DEFAULT
|
|
229
|
+
:type rank: RouteRank, Optional
|
|
230
|
+
:param auth_handlers: A list of authentication handler IDs to use for this route, defaults to None
|
|
231
|
+
:type auth_handlers: Optional[list[str]], Optional
|
|
232
|
+
:raises ApplicationError: If the selector or handler are not valid.
|
|
233
|
+
"""
|
|
234
|
+
if not selector or not handler:
|
|
235
|
+
logger.error(
|
|
236
|
+
"AgentApplication.add_route(): selector and handler are required."
|
|
237
|
+
)
|
|
238
|
+
raise ApplicationError("selector and handler are required.")
|
|
239
|
+
|
|
240
|
+
if is_agentic:
|
|
241
|
+
selector = _agentic_selector(selector)
|
|
242
|
+
|
|
243
|
+
route = _Route[StateT](
|
|
244
|
+
selector, handler, is_invoke, rank, auth_handlers, is_agentic
|
|
245
|
+
)
|
|
246
|
+
self._route_list.add_route(route)
|
|
247
|
+
|
|
207
248
|
def activity(
|
|
208
249
|
self,
|
|
209
|
-
activity_type: Union[str, ActivityTypes,
|
|
250
|
+
activity_type: Union[str, ActivityTypes, list[Union[str, ActivityTypes]]],
|
|
210
251
|
*,
|
|
211
|
-
auth_handlers: Optional[
|
|
252
|
+
auth_handlers: Optional[list[str]] = None,
|
|
253
|
+
**kwargs,
|
|
212
254
|
) -> Callable[[RouteHandler[StateT]], RouteHandler[StateT]]:
|
|
213
255
|
"""
|
|
214
256
|
Registers a new activity event listener. This method can be used as either
|
|
@@ -233,18 +275,17 @@ class AgentApplication(Agent, Generic[StateT]):
|
|
|
233
275
|
logger.debug(
|
|
234
276
|
f"Registering activity handler for route handler {func.__name__} with type: {activity_type} with auth handlers: {auth_handlers}"
|
|
235
277
|
)
|
|
236
|
-
self.
|
|
237
|
-
Route[StateT](__selector, func, auth_handlers=auth_handlers)
|
|
238
|
-
)
|
|
278
|
+
self.add_route(__selector, func, auth_handlers=auth_handlers, **kwargs)
|
|
239
279
|
return func
|
|
240
280
|
|
|
241
281
|
return __call
|
|
242
282
|
|
|
243
283
|
def message(
|
|
244
284
|
self,
|
|
245
|
-
select: Union[str, Pattern[str],
|
|
285
|
+
select: Union[str, Pattern[str], list[Union[str, Pattern[str]]]],
|
|
246
286
|
*,
|
|
247
|
-
auth_handlers: Optional[
|
|
287
|
+
auth_handlers: Optional[list[str]] = None,
|
|
288
|
+
**kwargs,
|
|
248
289
|
) -> Callable[[RouteHandler[StateT]], RouteHandler[StateT]]:
|
|
249
290
|
"""
|
|
250
291
|
Registers a new message activity event listener. This method can be used as either
|
|
@@ -276,9 +317,7 @@ class AgentApplication(Agent, Generic[StateT]):
|
|
|
276
317
|
logger.debug(
|
|
277
318
|
f"Registering message handler for route handler {func.__name__} with select: {select} with auth handlers: {auth_handlers}"
|
|
278
319
|
)
|
|
279
|
-
self.
|
|
280
|
-
Route[StateT](__selector, func, auth_handlers=auth_handlers)
|
|
281
|
-
)
|
|
320
|
+
self.add_route(__selector, func, auth_handlers=auth_handlers, **kwargs)
|
|
282
321
|
return func
|
|
283
322
|
|
|
284
323
|
return __call
|
|
@@ -287,7 +326,8 @@ class AgentApplication(Agent, Generic[StateT]):
|
|
|
287
326
|
self,
|
|
288
327
|
type: ConversationUpdateTypes,
|
|
289
328
|
*,
|
|
290
|
-
auth_handlers: Optional[
|
|
329
|
+
auth_handlers: Optional[list[str]] = None,
|
|
330
|
+
**kwargs,
|
|
291
331
|
) -> Callable[[RouteHandler[StateT]], RouteHandler[StateT]]:
|
|
292
332
|
"""
|
|
293
333
|
Registers a new message activity event listener. This method can be used as either
|
|
@@ -311,12 +351,12 @@ class AgentApplication(Agent, Generic[StateT]):
|
|
|
311
351
|
return False
|
|
312
352
|
|
|
313
353
|
if type == "membersAdded":
|
|
314
|
-
if isinstance(context.activity.members_added,
|
|
354
|
+
if isinstance(context.activity.members_added, list):
|
|
315
355
|
return len(context.activity.members_added) > 0
|
|
316
356
|
return False
|
|
317
357
|
|
|
318
358
|
if type == "membersRemoved":
|
|
319
|
-
if isinstance(context.activity.members_removed,
|
|
359
|
+
if isinstance(context.activity.members_removed, list):
|
|
320
360
|
return len(context.activity.members_removed) > 0
|
|
321
361
|
return False
|
|
322
362
|
|
|
@@ -330,15 +370,17 @@ class AgentApplication(Agent, Generic[StateT]):
|
|
|
330
370
|
logger.debug(
|
|
331
371
|
f"Registering conversation update handler for route handler {func.__name__} with type: {type} with auth handlers: {auth_handlers}"
|
|
332
372
|
)
|
|
333
|
-
self.
|
|
334
|
-
Route[StateT](__selector, func, auth_handlers=auth_handlers)
|
|
335
|
-
)
|
|
373
|
+
self.add_route(__selector, func, auth_handlers=auth_handlers, **kwargs)
|
|
336
374
|
return func
|
|
337
375
|
|
|
338
376
|
return __call
|
|
339
377
|
|
|
340
378
|
def message_reaction(
|
|
341
|
-
self,
|
|
379
|
+
self,
|
|
380
|
+
type: MessageReactionTypes,
|
|
381
|
+
*,
|
|
382
|
+
auth_handlers: Optional[list[str]] = None,
|
|
383
|
+
**kwargs,
|
|
342
384
|
) -> Callable[[RouteHandler[StateT]], RouteHandler[StateT]]:
|
|
343
385
|
"""
|
|
344
386
|
Registers a new message activity event listener. This method can be used as either
|
|
@@ -361,12 +403,12 @@ class AgentApplication(Agent, Generic[StateT]):
|
|
|
361
403
|
return False
|
|
362
404
|
|
|
363
405
|
if type == "reactionsAdded":
|
|
364
|
-
if isinstance(context.activity.reactions_added,
|
|
406
|
+
if isinstance(context.activity.reactions_added, list):
|
|
365
407
|
return len(context.activity.reactions_added) > 0
|
|
366
408
|
return False
|
|
367
409
|
|
|
368
410
|
if type == "reactionsRemoved":
|
|
369
|
-
if isinstance(context.activity.reactions_removed,
|
|
411
|
+
if isinstance(context.activity.reactions_removed, list):
|
|
370
412
|
return len(context.activity.reactions_removed) > 0
|
|
371
413
|
return False
|
|
372
414
|
|
|
@@ -376,15 +418,17 @@ class AgentApplication(Agent, Generic[StateT]):
|
|
|
376
418
|
logger.debug(
|
|
377
419
|
f"Registering message reaction handler for route handler {func.__name__} with type: {type} with auth handlers: {auth_handlers}"
|
|
378
420
|
)
|
|
379
|
-
self.
|
|
380
|
-
Route[StateT](__selector, func, auth_handlers=auth_handlers)
|
|
381
|
-
)
|
|
421
|
+
self.add_route(__selector, func, auth_handlers=auth_handlers, **kwargs)
|
|
382
422
|
return func
|
|
383
423
|
|
|
384
424
|
return __call
|
|
385
425
|
|
|
386
426
|
def message_update(
|
|
387
|
-
self,
|
|
427
|
+
self,
|
|
428
|
+
type: MessageUpdateTypes,
|
|
429
|
+
*,
|
|
430
|
+
auth_handlers: Optional[list[str]] = None,
|
|
431
|
+
**kwargs,
|
|
388
432
|
) -> Callable[[RouteHandler[StateT]], RouteHandler[StateT]]:
|
|
389
433
|
"""
|
|
390
434
|
Registers a new message activity event listener. This method can be used as either
|
|
@@ -435,14 +479,14 @@ class AgentApplication(Agent, Generic[StateT]):
|
|
|
435
479
|
logger.debug(
|
|
436
480
|
f"Registering message update handler for route handler {func.__name__} with type: {type} with auth handlers: {auth_handlers}"
|
|
437
481
|
)
|
|
438
|
-
self.
|
|
439
|
-
Route[StateT](__selector, func, auth_handlers=auth_handlers)
|
|
440
|
-
)
|
|
482
|
+
self.add_route(__selector, func, auth_handlers=auth_handlers, **kwargs)
|
|
441
483
|
return func
|
|
442
484
|
|
|
443
485
|
return __call
|
|
444
486
|
|
|
445
|
-
def handoff(
|
|
487
|
+
def handoff(
|
|
488
|
+
self, *, auth_handlers: Optional[list[str]] = None, **kwargs
|
|
489
|
+
) -> Callable[
|
|
446
490
|
[Callable[[TurnContext, StateT, str], Awaitable[None]]],
|
|
447
491
|
Callable[[TurnContext, StateT, str], Awaitable[None]],
|
|
448
492
|
]:
|
|
@@ -483,10 +527,7 @@ class AgentApplication(Agent, Generic[StateT]):
|
|
|
483
527
|
f"Registering handoff handler for route handler {func.__name__} with auth handlers: {auth_handlers}"
|
|
484
528
|
)
|
|
485
529
|
|
|
486
|
-
self.
|
|
487
|
-
Route[StateT](__selector, __handler, True, auth_handlers)
|
|
488
|
-
)
|
|
489
|
-
self._routes = sorted(self._routes, key=lambda route: not route.is_invoke)
|
|
530
|
+
self.add_route(__selector, func, auth_handlers=auth_handlers, **kwargs)
|
|
490
531
|
return func
|
|
491
532
|
|
|
492
533
|
return __call
|
|
@@ -598,7 +639,6 @@ class AgentApplication(Agent, Generic[StateT]):
|
|
|
598
639
|
await self._start_long_running_call(context, self._on_turn)
|
|
599
640
|
|
|
600
641
|
async def _on_turn(self, context: TurnContext):
|
|
601
|
-
# robrandao: TODO
|
|
602
642
|
try:
|
|
603
643
|
if context.activity.type != ActivityTypes.typing:
|
|
604
644
|
await self._start_typing(context)
|
|
@@ -663,7 +703,7 @@ class AgentApplication(Agent, Generic[StateT]):
|
|
|
663
703
|
context.activity.text = context.remove_recipient_mention(context.activity)
|
|
664
704
|
|
|
665
705
|
@staticmethod
|
|
666
|
-
def parse_env_vars_configuration(vars:
|
|
706
|
+
def parse_env_vars_configuration(vars: dict[str, Any]) -> dict:
|
|
667
707
|
"""
|
|
668
708
|
Parses environment variables and returns a dictionary with the relevant configuration.
|
|
669
709
|
"""
|
|
@@ -738,7 +778,7 @@ class AgentApplication(Agent, Generic[StateT]):
|
|
|
738
778
|
return True
|
|
739
779
|
|
|
740
780
|
async def _on_activity(self, context: TurnContext, state: StateT):
|
|
741
|
-
for route in self.
|
|
781
|
+
for route in self._route_list:
|
|
742
782
|
if route.selector(context):
|
|
743
783
|
if not route.auth_handlers:
|
|
744
784
|
await route.handler(context, state)
|
|
@@ -16,10 +16,12 @@ from microsoft_agents.hosting.core import TurnContext
|
|
|
16
16
|
class InputFile:
|
|
17
17
|
"""A file sent by the user to the bot.
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
:param content: The downloaded content of the file.
|
|
20
|
+
:type content: bytes
|
|
21
|
+
:param content_type: The content type of the file.
|
|
22
|
+
:type content_type: str
|
|
23
|
+
:param content_url: Optional. URL to the content of the file.
|
|
24
|
+
:type content_url: Optional[str]
|
|
23
25
|
"""
|
|
24
26
|
|
|
25
27
|
content: bytes
|
|
@@ -29,17 +31,19 @@ class InputFile:
|
|
|
29
31
|
|
|
30
32
|
class InputFileDownloader(ABC):
|
|
31
33
|
"""
|
|
32
|
-
|
|
34
|
+
Abstract base class for a plugin responsible for downloading files provided by the user.
|
|
35
|
+
|
|
36
|
+
Implementations should download any files referenced by the incoming activity and return a
|
|
37
|
+
list of :class:`InputFile` instances representing the downloaded content.
|
|
33
38
|
"""
|
|
34
39
|
|
|
35
40
|
@abstractmethod
|
|
36
41
|
async def download_files(self, context: TurnContext) -> List[InputFile]:
|
|
37
42
|
"""
|
|
38
|
-
Download any files
|
|
39
|
-
|
|
40
|
-
Args:
|
|
41
|
-
context (TurnContext): Context for the current turn of conversation.
|
|
43
|
+
Download any files referenced by the incoming activity for the current turn.
|
|
42
44
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
+
:param context: The turn context for the current request.
|
|
46
|
+
:type context: :class:`microsoft_agents.hosting.core.turn_context.TurnContext`
|
|
47
|
+
:return: A list of downloaded :class:`InputFile` objects.
|
|
48
|
+
:rtype: list[:class:`microsoft_agents.hosting.core.app.input_file.InputFile`]
|
|
45
49
|
"""
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
Licensed under the MIT License.
|
|
4
|
+
"""
|
|
5
|
+
|
|
1
6
|
from .agentic_user_authorization import AgenticUserAuthorization
|
|
2
7
|
from ._user_authorization import _UserAuthorization
|
|
3
8
|
from ._authorization_handler import _AuthorizationHandler
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
Licensed under the MIT License.
|
|
4
|
+
"""
|
|
5
|
+
|
|
1
6
|
from abc import ABC
|
|
2
7
|
from typing import Optional
|
|
3
8
|
import logging
|
|
@@ -38,7 +43,7 @@ class _AuthorizationHandler(ABC):
|
|
|
38
43
|
:param connection_manager: The connection manager for OAuth providers.
|
|
39
44
|
:type connection_manager: Connections
|
|
40
45
|
:param auth_handlers: Configuration for OAuth providers.
|
|
41
|
-
:type auth_handlers: dict[str, AuthHandler],
|
|
46
|
+
:type auth_handlers: dict[str, AuthHandler], Optional
|
|
42
47
|
:raises ValueError: When storage is None or no auth handlers provided.
|
|
43
48
|
"""
|
|
44
49
|
if not storage:
|
|
@@ -70,7 +75,7 @@ class _AuthorizationHandler(ABC):
|
|
|
70
75
|
:param context: The turn context for the current turn of conversation.
|
|
71
76
|
:type context: TurnContext
|
|
72
77
|
:param scopes: Optional list of scopes to request during sign-in. If None, default scopes will be used.
|
|
73
|
-
:type scopes: Optional[list[str]],
|
|
78
|
+
:type scopes: Optional[list[str]], Optional
|
|
74
79
|
:return: A SignInResponse indicating the result of the sign-in attempt.
|
|
75
80
|
:rtype: SignInResponse
|
|
76
81
|
"""
|
|
@@ -87,9 +92,9 @@ class _AuthorizationHandler(ABC):
|
|
|
87
92
|
:param context: The turn context for the current turn of conversation.
|
|
88
93
|
:type context: TurnContext
|
|
89
94
|
:param exchange_connection: Optional name of the connection to use for token exchange. If None, default connection will be used.
|
|
90
|
-
:type exchange_connection: Optional[str],
|
|
95
|
+
:type exchange_connection: Optional[str], Optional
|
|
91
96
|
:param exchange_scopes: Optional list of scopes to request during token exchange. If None, default scopes will be used.
|
|
92
|
-
:type exchange_scopes: Optional[list[str]],
|
|
97
|
+
:type exchange_scopes: Optional[list[str]], Optional
|
|
93
98
|
"""
|
|
94
99
|
raise NotImplementedError()
|
|
95
100
|
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"""
|
|
2
|
+
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
Licensed under the MIT License.
|
|
4
|
+
"""
|
|
3
5
|
|
|
4
6
|
from __future__ import annotations
|
|
5
7
|
import logging
|
|
@@ -247,9 +249,9 @@ class _UserAuthorization(_AuthorizationHandler):
|
|
|
247
249
|
:param context: The turn context for the current turn of conversation.
|
|
248
250
|
:type context: TurnContext
|
|
249
251
|
:param exchange_connection: Optional name of the connection to use for token exchange. If None, default connection will be used.
|
|
250
|
-
:type exchange_connection: Optional[str],
|
|
252
|
+
:type exchange_connection: Optional[str], Optional
|
|
251
253
|
:param exchange_scopes: Optional list of scopes to request during token exchange. If None, default scopes will be used.
|
|
252
|
-
:type exchange_scopes: Optional[list[str]],
|
|
254
|
+
:type exchange_scopes: Optional[list[str]], Optional
|
|
253
255
|
"""
|
|
254
256
|
flow, _ = await self._load_flow(context)
|
|
255
257
|
input_token_response = await flow.get_user_token()
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
Licensed under the MIT License.
|
|
4
|
+
"""
|
|
5
|
+
|
|
1
6
|
import logging
|
|
2
7
|
|
|
3
8
|
from typing import Optional
|
|
@@ -36,7 +41,7 @@ class AgenticUserAuthorization(_AuthorizationHandler):
|
|
|
36
41
|
:param connection_manager: The connection manager for OAuth providers.
|
|
37
42
|
:type connection_manager: Connections
|
|
38
43
|
:param auth_handlers: Configuration for OAuth providers.
|
|
39
|
-
:type auth_handlers: dict[str, AuthHandler],
|
|
44
|
+
:type auth_handlers: dict[str, AuthHandler], Optional
|
|
40
45
|
:raises ValueError: When storage is None or no auth handlers provided.
|
|
41
46
|
"""
|
|
42
47
|
super().__init__(
|
|
@@ -167,9 +172,9 @@ class AgenticUserAuthorization(_AuthorizationHandler):
|
|
|
167
172
|
:param context: The turn context for the current turn of conversation.
|
|
168
173
|
:type context: TurnContext
|
|
169
174
|
:param exchange_connection: Optional name of the connection to use for token exchange. If None, default connection will be used.
|
|
170
|
-
:type exchange_connection: Optional[str],
|
|
175
|
+
:type exchange_connection: Optional[str], Optional
|
|
171
176
|
:param exchange_scopes: Optional list of scopes to request during token exchange. If None, default scopes will be used.
|
|
172
|
-
:type exchange_scopes: Optional[list[str]],
|
|
177
|
+
:type exchange_scopes: Optional[list[str]], Optional
|
|
173
178
|
"""
|
|
174
179
|
if not exchange_scopes:
|
|
175
180
|
exchange_scopes = self._handler.scopes or []
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
Licensed under the MIT License.
|
|
4
|
+
"""
|
|
5
|
+
|
|
1
6
|
from datetime import datetime
|
|
2
7
|
import logging
|
|
3
8
|
from typing import TypeVar, Optional, Callable, Awaitable, Generic, cast
|
|
@@ -54,7 +59,7 @@ class Authorization:
|
|
|
54
59
|
:param connection_manager: The connection manager for OAuth providers.
|
|
55
60
|
:type connection_manager: Connections
|
|
56
61
|
:param auth_handlers: Configuration for OAuth providers.
|
|
57
|
-
:type auth_handlers: dict[str, AuthHandler],
|
|
62
|
+
:type auth_handlers: dict[str, AuthHandler], Optional
|
|
58
63
|
:raises ValueError: When storage is None or no auth handlers provided.
|
|
59
64
|
"""
|
|
60
65
|
if not storage:
|
|
@@ -40,7 +40,7 @@ class ChannelAdapter(ABC, ChannelAdapterProtocol):
|
|
|
40
40
|
Sends a set of activities to the user. An array of responses from the server will be returned.
|
|
41
41
|
|
|
42
42
|
:param context: The context object for the turn.
|
|
43
|
-
:type context: :class:`TurnContext`
|
|
43
|
+
:type context: :class:`microsoft_agents.hosting.core.turn_context.TurnContext`
|
|
44
44
|
:param activities: The activities to send.
|
|
45
45
|
:type activities: list[Activity]
|
|
46
46
|
:return:
|
|
@@ -53,7 +53,7 @@ class ChannelAdapter(ABC, ChannelAdapterProtocol):
|
|
|
53
53
|
Replaces an existing activity.
|
|
54
54
|
|
|
55
55
|
:param context: The context object for the turn.
|
|
56
|
-
:type context: :class:`TurnContext`
|
|
56
|
+
:type context: :class:`microsoft_agents.hosting.core.turn_context.TurnContext`
|
|
57
57
|
:param activity: New replacement activity.
|
|
58
58
|
:type activity: :class:`microsoft_agents.activity.Activity`
|
|
59
59
|
:return:
|
|
@@ -68,7 +68,7 @@ class ChannelAdapter(ABC, ChannelAdapterProtocol):
|
|
|
68
68
|
Deletes an existing activity.
|
|
69
69
|
|
|
70
70
|
:param context: The context object for the turn.
|
|
71
|
-
:type context: :class:`TurnContext`
|
|
71
|
+
:type context: :class:`microsoft_agents.hosting.core.turn_context.TurnContext`
|
|
72
72
|
:param reference: Conversation reference for the activity to delete.
|
|
73
73
|
:type reference: :class:`microsoft_agents.activity.ConversationReference`
|
|
74
74
|
:return:
|
|
@@ -102,7 +102,7 @@ class ChannelAdapter(ABC, ChannelAdapterProtocol):
|
|
|
102
102
|
:param reference: A reference to the conversation to continue.
|
|
103
103
|
:type reference: :class:`microsoft_agents.activity.ConversationReference`
|
|
104
104
|
:param callback: The method to call for the resulting agent turn.
|
|
105
|
-
:type callback: Callable[[TurnContext], Awaitable]
|
|
105
|
+
:type callback: Callable[[microsoft_agents.hosting.core.turn_context.TurnContext], Awaitable]
|
|
106
106
|
:param claims_identity: A :class:`microsoft_agents.hosting.core.ClaimsIdentity` for the conversation.
|
|
107
107
|
:type claims_identity: :class:`microsoft_agents.hosting.core.ClaimsIdentity`
|
|
108
108
|
:param audience:A value signifying the recipient of the proactive message.
|
|
@@ -124,11 +124,11 @@ class ChannelAdapter(ABC, ChannelAdapterProtocol):
|
|
|
124
124
|
to the user.
|
|
125
125
|
|
|
126
126
|
:param claims_identity: A :class:`microsoft_agents.hosting.core.ClaimsIdentity` for the conversation.
|
|
127
|
-
:type claims_identity: :class:`microsoft_agents.hosting.core.ClaimsIdentity`
|
|
127
|
+
:type claims_identity: :class:`microsoft_agents.hosting.core.authorization.ClaimsIdentity`
|
|
128
128
|
:param continuation_activity: The activity to send.
|
|
129
129
|
:type continuation_activity: :class:`microsoft_agents.activity.Activity`
|
|
130
130
|
:param callback: The method to call for the resulting agent turn.
|
|
131
|
-
:type callback: Callable[[TurnContext], Awaitable]
|
|
131
|
+
:type callback: Callable[[microsoft_agents.hosting.core.turn_context.TurnContext], Awaitable]
|
|
132
132
|
:param audience: A value signifying the recipient of the proactive message.
|
|
133
133
|
:type audience: str
|
|
134
134
|
"""
|
|
@@ -155,9 +155,9 @@ class ChannelAdapter(ABC, ChannelAdapterProtocol):
|
|
|
155
155
|
:param audience: A value signifying the recipient of the proactive message.
|
|
156
156
|
:type audience: str
|
|
157
157
|
:param conversation_parameters: The information to use to create the conversation
|
|
158
|
-
:type conversation_parameters: :class:`microsoft_agents.activity.
|
|
158
|
+
:type conversation_parameters: :class:`microsoft_agents.activity.ConversationParameters`
|
|
159
159
|
:param callback: The method to call for the resulting agent turn.
|
|
160
|
-
:type callback: Callable[[TurnContext], Awaitable]
|
|
160
|
+
:type callback: Callable[[microsoft_agents.hosting.core.turn_context.TurnContext], Awaitable]
|
|
161
161
|
|
|
162
162
|
:raises: Exception - Not implemented or when the implementation fails.
|
|
163
163
|
|
|
@@ -222,7 +222,7 @@ class ChannelAdapter(ABC, ChannelAdapterProtocol):
|
|
|
222
222
|
the end of the chain.
|
|
223
223
|
|
|
224
224
|
:param context: The context object for the turn.
|
|
225
|
-
:type context: :class:`TurnContext`
|
|
225
|
+
:type context: :class:`microsoft_agents.hosting.core.turn_context.TurnContext`
|
|
226
226
|
:param callback: A callback method to run at the end of the pipeline.
|
|
227
227
|
:type callback: Callable[[TurnContext], Awaitable]
|
|
228
228
|
:return:
|
|
@@ -66,10 +66,7 @@ class ChannelServiceAdapter(ChannelAdapter, ABC):
|
|
|
66
66
|
|
|
67
67
|
response = ResourceResponse()
|
|
68
68
|
|
|
69
|
-
if activity.type ==
|
|
70
|
-
delay_time = int((activity.value or 1000) / 1000)
|
|
71
|
-
await sleep(delay_time)
|
|
72
|
-
elif activity.type == ActivityTypes.invoke_response:
|
|
69
|
+
if activity.type == ActivityTypes.invoke_response:
|
|
73
70
|
context.turn_state[self.INVOKE_RESPONSE_KEY] = activity
|
|
74
71
|
elif (
|
|
75
72
|
activity.type == ActivityTypes.trace
|