microsoft-agents-hosting-core 0.4.0.dev16__py3-none-any.whl → 0.5.0__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.
Files changed (66) hide show
  1. microsoft_agents/hosting/core/__init__.py +2 -1
  2. microsoft_agents/hosting/core/_oauth/__init__.py +3 -0
  3. microsoft_agents/hosting/core/_oauth/_flow_state.py +2 -2
  4. microsoft_agents/hosting/core/_oauth/_oauth_flow.py +26 -23
  5. microsoft_agents/hosting/core/activity_handler.py +20 -17
  6. microsoft_agents/hosting/core/app/__init__.py +2 -1
  7. microsoft_agents/hosting/core/app/_routes/__init__.py +13 -0
  8. microsoft_agents/hosting/core/app/_routes/_route.py +89 -0
  9. microsoft_agents/hosting/core/app/_routes/_route_list.py +32 -0
  10. microsoft_agents/hosting/core/app/_routes/route_rank.py +14 -0
  11. microsoft_agents/hosting/core/app/_type_defs.py +15 -0
  12. microsoft_agents/hosting/core/app/agent_application.py +116 -52
  13. microsoft_agents/hosting/core/app/input_file.py +15 -11
  14. microsoft_agents/hosting/core/app/oauth/__init__.py +4 -0
  15. microsoft_agents/hosting/core/app/oauth/_handlers/__init__.py +5 -0
  16. microsoft_agents/hosting/core/app/oauth/_handlers/_authorization_handler.py +9 -4
  17. microsoft_agents/hosting/core/app/oauth/_handlers/_user_authorization.py +6 -4
  18. microsoft_agents/hosting/core/app/oauth/_handlers/agentic_user_authorization.py +14 -9
  19. microsoft_agents/hosting/core/app/oauth/_sign_in_response.py +4 -0
  20. microsoft_agents/hosting/core/app/oauth/_sign_in_state.py +5 -0
  21. microsoft_agents/hosting/core/app/oauth/auth_handler.py +4 -2
  22. microsoft_agents/hosting/core/app/oauth/authorization.py +43 -20
  23. microsoft_agents/hosting/core/app/state/state.py +50 -6
  24. microsoft_agents/hosting/core/app/typing_indicator.py +51 -27
  25. microsoft_agents/hosting/core/authorization/access_token_provider_base.py +4 -1
  26. microsoft_agents/hosting/core/authorization/agent_auth_configuration.py +3 -0
  27. microsoft_agents/hosting/core/authorization/anonymous_token_provider.py +4 -1
  28. microsoft_agents/hosting/core/authorization/auth_types.py +3 -0
  29. microsoft_agents/hosting/core/authorization/connections.py +3 -0
  30. microsoft_agents/hosting/core/authorization/jwt_token_validator.py +9 -4
  31. microsoft_agents/hosting/core/channel_adapter.py +9 -9
  32. microsoft_agents/hosting/core/channel_api_handler_protocol.py +3 -0
  33. microsoft_agents/hosting/core/channel_service_adapter.py +65 -10
  34. microsoft_agents/hosting/core/channel_service_client_factory_base.py +3 -0
  35. microsoft_agents/hosting/core/client/agent_conversation_reference.py +3 -0
  36. microsoft_agents/hosting/core/client/channel_factory_protocol.py +3 -0
  37. microsoft_agents/hosting/core/client/channel_host_protocol.py +3 -0
  38. microsoft_agents/hosting/core/client/channel_info_protocol.py +3 -0
  39. microsoft_agents/hosting/core/client/channel_protocol.py +3 -0
  40. microsoft_agents/hosting/core/client/channels_configuration.py +3 -0
  41. microsoft_agents/hosting/core/client/configuration_channel_host.py +3 -0
  42. microsoft_agents/hosting/core/client/conversation_constants.py +3 -0
  43. microsoft_agents/hosting/core/client/conversation_id_factory.py +3 -0
  44. microsoft_agents/hosting/core/client/conversation_id_factory_options.py +3 -0
  45. microsoft_agents/hosting/core/client/conversation_id_factory_protocol.py +3 -0
  46. microsoft_agents/hosting/core/client/http_agent_channel.py +3 -0
  47. microsoft_agents/hosting/core/client/http_agent_channel_factory.py +3 -0
  48. microsoft_agents/hosting/core/connector/client/connector_client.py +1 -4
  49. microsoft_agents/hosting/core/connector/client/user_token_client.py +40 -43
  50. microsoft_agents/hosting/core/connector/user_token_base.py +77 -1
  51. microsoft_agents/hosting/core/connector/user_token_client_base.py +3 -0
  52. microsoft_agents/hosting/core/rest_channel_service_client_factory.py +3 -0
  53. microsoft_agents/hosting/core/state/agent_state.py +16 -20
  54. microsoft_agents/hosting/core/storage/error_handling.py +3 -0
  55. microsoft_agents/hosting/core/storage/memory_storage.py +3 -0
  56. microsoft_agents/hosting/core/storage/storage.py +3 -0
  57. microsoft_agents/hosting/core/storage/store_item.py +3 -0
  58. microsoft_agents/hosting/core/storage/transcript_file_store.py +1 -5
  59. microsoft_agents/hosting/core/turn_context.py +2 -1
  60. microsoft_agents_hosting_core-0.5.0.dist-info/METADATA +191 -0
  61. {microsoft_agents_hosting_core-0.4.0.dev16.dist-info → microsoft_agents_hosting_core-0.5.0.dist-info}/RECORD +64 -59
  62. microsoft_agents_hosting_core-0.5.0.dist-info/licenses/LICENSE +21 -0
  63. microsoft_agents/hosting/core/app/route.py +0 -32
  64. microsoft_agents_hosting_core-0.4.0.dev16.dist-info/METADATA +0 -16
  65. {microsoft_agents_hosting_core-0.4.0.dev16.dist-info → microsoft_agents_hosting_core-0.5.0.dist-info}/WHEEL +0 -0
  66. {microsoft_agents_hosting_core-0.4.0.dev16.dist-info → microsoft_agents_hosting_core-0.5.0.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,33 @@ 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: List[Callable[[TurnContext, StateT], Awaitable[bool]]] = []
72
- _internal_after_turn: List[Callable[[TurnContext, StateT], Awaitable[bool]]] = []
73
- _routes: List[Route[StateT]] = []
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.
86
+
87
+ :param options: Configuration options for the application.
88
+ :type options: Optional[:class:`microsoft_agents.hosting.core.app.app_options.ApplicationOptions`]
89
+ :param connection_manager: OAuth connection manager.
90
+ :type connection_manager: Optional[:class:`microsoft_agents.hosting.core.authorization.Connections`]
91
+ :param authorization: Authorization manager for handling authentication flows.
92
+ :type authorization: Optional[:class:`microsoft_agents.hosting.core.app.oauth.Authorization`]
93
+ :param kwargs: Additional configuration parameters.
94
+ :type kwargs: Any
87
95
  """
88
- self.typing = TypingIndicator()
89
- self._routes = []
96
+ self._route_list = _RouteList[StateT]()
90
97
 
91
98
  configuration = kwargs
92
99
 
@@ -162,6 +169,10 @@ class AgentApplication(Agent, Generic[StateT]):
162
169
  def adapter(self) -> ChannelServiceAdapter:
163
170
  """
164
171
  The bot's adapter.
172
+
173
+ :return: The channel service adapter for the bot.
174
+ :rtype: :class:`microsoft_agents.hosting.core.channel_service_adapter.ChannelServiceAdapter`
175
+ :raises ApplicationError: If the adapter is not configured.
165
176
  """
166
177
 
167
178
  if not self._adapter:
@@ -182,6 +193,10 @@ class AgentApplication(Agent, Generic[StateT]):
182
193
  def auth(self) -> Authorization:
183
194
  """
184
195
  The application's authentication manager
196
+
197
+ :return: The authentication manager for handling OAuth flows.
198
+ :rtype: :class:`microsoft_agents.hosting.core.app.oauth.Authorization`
199
+ :raises ApplicationError: If authentication is not configured.
185
200
  """
186
201
  if not self._auth:
187
202
  logger.error(
@@ -201,14 +216,60 @@ class AgentApplication(Agent, Generic[StateT]):
201
216
  def options(self) -> ApplicationOptions:
202
217
  """
203
218
  The application's configured options.
219
+
220
+ :return: The configuration options for the application.
221
+ :rtype: :class:`microsoft_agents.hosting.core.app.app_options.ApplicationOptions`
204
222
  """
205
223
  return self._options
206
224
 
225
+ def add_route(
226
+ self,
227
+ selector: RouteSelector,
228
+ handler: RouteHandler[StateT],
229
+ is_invoke: bool = False,
230
+ is_agentic: bool = False,
231
+ rank: RouteRank = RouteRank.DEFAULT,
232
+ auth_handlers: Optional[list[str]] = None,
233
+ ) -> None:
234
+ """Adds a new route to the application.
235
+
236
+ Routes are ordered by: is_agentic, is_invoke, rank (lower is higher priority), in that order.
237
+
238
+ :param selector: A function that takes a TurnContext and returns a boolean indicating whether the route should be selected.
239
+ :type selector: :class:`microsoft_agents.hosting.core.app._type_defs.RouteSelector`
240
+ :param handler: A function that takes a TurnContext and a TurnState and returns an Awaitable.
241
+ :type handler: :class:`microsoft_agents.hosting.core.app._type_defs.RouteHandler`[StateT]
242
+ :param is_invoke: Whether the route is for an invoke activity, defaults to False
243
+ :type is_invoke: bool, Optional
244
+ :param is_agentic: Whether the route is for an agentic request, defaults to False. For agentic requests
245
+ the selector will include a new check for `context.activity.is_agentic_request()`.
246
+ :type is_agentic: bool, Optional
247
+ :param rank: The rank of the route, defaults to RouteRank.DEFAULT
248
+ :type rank: :class:`microsoft_agents.hosting.core.app._routes.RouteRank`, Optional
249
+ :param auth_handlers: A list of authentication handler IDs to use for this route, defaults to None
250
+ :type auth_handlers: Optional[list[str]], Optional
251
+ :raises ApplicationError: If the selector or handler are not valid.
252
+ """
253
+ if not selector or not handler:
254
+ logger.error(
255
+ "AgentApplication.add_route(): selector and handler are required."
256
+ )
257
+ raise ApplicationError("selector and handler are required.")
258
+
259
+ if is_agentic:
260
+ selector = _agentic_selector(selector)
261
+
262
+ route = _Route[StateT](
263
+ selector, handler, is_invoke, rank, auth_handlers, is_agentic
264
+ )
265
+ self._route_list.add_route(route)
266
+
207
267
  def activity(
208
268
  self,
209
- activity_type: Union[str, ActivityTypes, List[Union[str, ActivityTypes]]],
269
+ activity_type: Union[str, ActivityTypes, list[Union[str, ActivityTypes]]],
210
270
  *,
211
- auth_handlers: Optional[List[str]] = None,
271
+ auth_handlers: Optional[list[str]] = None,
272
+ **kwargs,
212
273
  ) -> Callable[[RouteHandler[StateT]], RouteHandler[StateT]]:
213
274
  """
214
275
  Registers a new activity event listener. This method can be used as either
@@ -233,18 +294,17 @@ class AgentApplication(Agent, Generic[StateT]):
233
294
  logger.debug(
234
295
  f"Registering activity handler for route handler {func.__name__} with type: {activity_type} with auth handlers: {auth_handlers}"
235
296
  )
236
- self._routes.append(
237
- Route[StateT](__selector, func, auth_handlers=auth_handlers)
238
- )
297
+ self.add_route(__selector, func, auth_handlers=auth_handlers, **kwargs)
239
298
  return func
240
299
 
241
300
  return __call
242
301
 
243
302
  def message(
244
303
  self,
245
- select: Union[str, Pattern[str], List[Union[str, Pattern[str]]]],
304
+ select: Union[str, Pattern[str], list[Union[str, Pattern[str]]]],
246
305
  *,
247
- auth_handlers: Optional[List[str]] = None,
306
+ auth_handlers: Optional[list[str]] = None,
307
+ **kwargs,
248
308
  ) -> Callable[[RouteHandler[StateT]], RouteHandler[StateT]]:
249
309
  """
250
310
  Registers a new message activity event listener. This method can be used as either
@@ -276,9 +336,7 @@ class AgentApplication(Agent, Generic[StateT]):
276
336
  logger.debug(
277
337
  f"Registering message handler for route handler {func.__name__} with select: {select} with auth handlers: {auth_handlers}"
278
338
  )
279
- self._routes.append(
280
- Route[StateT](__selector, func, auth_handlers=auth_handlers)
281
- )
339
+ self.add_route(__selector, func, auth_handlers=auth_handlers, **kwargs)
282
340
  return func
283
341
 
284
342
  return __call
@@ -287,7 +345,8 @@ class AgentApplication(Agent, Generic[StateT]):
287
345
  self,
288
346
  type: ConversationUpdateTypes,
289
347
  *,
290
- auth_handlers: Optional[List[str]] = None,
348
+ auth_handlers: Optional[list[str]] = None,
349
+ **kwargs,
291
350
  ) -> Callable[[RouteHandler[StateT]], RouteHandler[StateT]]:
292
351
  """
293
352
  Registers a new message activity event listener. This method can be used as either
@@ -311,12 +370,12 @@ class AgentApplication(Agent, Generic[StateT]):
311
370
  return False
312
371
 
313
372
  if type == "membersAdded":
314
- if isinstance(context.activity.members_added, List):
373
+ if isinstance(context.activity.members_added, list):
315
374
  return len(context.activity.members_added) > 0
316
375
  return False
317
376
 
318
377
  if type == "membersRemoved":
319
- if isinstance(context.activity.members_removed, List):
378
+ if isinstance(context.activity.members_removed, list):
320
379
  return len(context.activity.members_removed) > 0
321
380
  return False
322
381
 
@@ -330,15 +389,17 @@ class AgentApplication(Agent, Generic[StateT]):
330
389
  logger.debug(
331
390
  f"Registering conversation update handler for route handler {func.__name__} with type: {type} with auth handlers: {auth_handlers}"
332
391
  )
333
- self._routes.append(
334
- Route[StateT](__selector, func, auth_handlers=auth_handlers)
335
- )
392
+ self.add_route(__selector, func, auth_handlers=auth_handlers, **kwargs)
336
393
  return func
337
394
 
338
395
  return __call
339
396
 
340
397
  def message_reaction(
341
- self, type: MessageReactionTypes, *, auth_handlers: Optional[List[str]] = None
398
+ self,
399
+ type: MessageReactionTypes,
400
+ *,
401
+ auth_handlers: Optional[list[str]] = None,
402
+ **kwargs,
342
403
  ) -> Callable[[RouteHandler[StateT]], RouteHandler[StateT]]:
343
404
  """
344
405
  Registers a new message activity event listener. This method can be used as either
@@ -361,12 +422,12 @@ class AgentApplication(Agent, Generic[StateT]):
361
422
  return False
362
423
 
363
424
  if type == "reactionsAdded":
364
- if isinstance(context.activity.reactions_added, List):
425
+ if isinstance(context.activity.reactions_added, list):
365
426
  return len(context.activity.reactions_added) > 0
366
427
  return False
367
428
 
368
429
  if type == "reactionsRemoved":
369
- if isinstance(context.activity.reactions_removed, List):
430
+ if isinstance(context.activity.reactions_removed, list):
370
431
  return len(context.activity.reactions_removed) > 0
371
432
  return False
372
433
 
@@ -376,15 +437,17 @@ class AgentApplication(Agent, Generic[StateT]):
376
437
  logger.debug(
377
438
  f"Registering message reaction handler for route handler {func.__name__} with type: {type} with auth handlers: {auth_handlers}"
378
439
  )
379
- self._routes.append(
380
- Route[StateT](__selector, func, auth_handlers=auth_handlers)
381
- )
440
+ self.add_route(__selector, func, auth_handlers=auth_handlers, **kwargs)
382
441
  return func
383
442
 
384
443
  return __call
385
444
 
386
445
  def message_update(
387
- self, type: MessageUpdateTypes, *, auth_handlers: Optional[List[str]] = None
446
+ self,
447
+ type: MessageUpdateTypes,
448
+ *,
449
+ auth_handlers: Optional[list[str]] = None,
450
+ **kwargs,
388
451
  ) -> Callable[[RouteHandler[StateT]], RouteHandler[StateT]]:
389
452
  """
390
453
  Registers a new message activity event listener. This method can be used as either
@@ -435,14 +498,14 @@ class AgentApplication(Agent, Generic[StateT]):
435
498
  logger.debug(
436
499
  f"Registering message update handler for route handler {func.__name__} with type: {type} with auth handlers: {auth_handlers}"
437
500
  )
438
- self._routes.append(
439
- Route[StateT](__selector, func, auth_handlers=auth_handlers)
440
- )
501
+ self.add_route(__selector, func, auth_handlers=auth_handlers, **kwargs)
441
502
  return func
442
503
 
443
504
  return __call
444
505
 
445
- def handoff(self, *, auth_handlers: Optional[List[str]] = None) -> Callable[
506
+ def handoff(
507
+ self, *, auth_handlers: Optional[list[str]] = None, **kwargs
508
+ ) -> Callable[
446
509
  [Callable[[TurnContext, StateT, str], Awaitable[None]]],
447
510
  Callable[[TurnContext, StateT, str], Awaitable[None]],
448
511
  ]:
@@ -483,10 +546,7 @@ class AgentApplication(Agent, Generic[StateT]):
483
546
  f"Registering handoff handler for route handler {func.__name__} with auth handlers: {auth_handlers}"
484
547
  )
485
548
 
486
- self._routes.append(
487
- Route[StateT](__selector, __handler, True, auth_handlers)
488
- )
489
- self._routes = sorted(self._routes, key=lambda route: not route.is_invoke)
549
+ self.add_route(__selector, func, auth_handlers=auth_handlers, **kwargs)
490
550
  return func
491
551
 
492
552
  return __call
@@ -598,10 +658,12 @@ class AgentApplication(Agent, Generic[StateT]):
598
658
  await self._start_long_running_call(context, self._on_turn)
599
659
 
600
660
  async def _on_turn(self, context: TurnContext):
601
- # robrandao: TODO
661
+ typing = None
602
662
  try:
603
663
  if context.activity.type != ActivityTypes.typing:
604
- await self._start_typing(context)
664
+ if self._options.start_typing_timer:
665
+ typing = TypingIndicator()
666
+ await typing.start(context)
605
667
 
606
668
  self._remove_mentions(context)
607
669
 
@@ -649,11 +711,8 @@ class AgentApplication(Agent, Generic[StateT]):
649
711
  )
650
712
  await self._on_error(context, err)
651
713
  finally:
652
- self.typing.stop()
653
-
654
- async def _start_typing(self, context: TurnContext):
655
- if self._options.start_typing_timer:
656
- await self.typing.start(context)
714
+ if typing:
715
+ await typing.stop()
657
716
 
658
717
  def _remove_mentions(self, context: TurnContext):
659
718
  if (
@@ -663,9 +722,14 @@ class AgentApplication(Agent, Generic[StateT]):
663
722
  context.activity.text = context.remove_recipient_mention(context.activity)
664
723
 
665
724
  @staticmethod
666
- def parse_env_vars_configuration(vars: Dict[str, Any]) -> dict:
725
+ def parse_env_vars_configuration(vars: dict[str, Any]) -> dict:
667
726
  """
668
727
  Parses environment variables and returns a dictionary with the relevant configuration.
728
+
729
+ :param vars: Dictionary of environment variable names and values.
730
+ :type vars: dict[str, Any]
731
+ :return: Parsed configuration dictionary with nested structure.
732
+ :rtype: dict
669
733
  """
670
734
  result = {}
671
735
  for key, value in vars.items():
@@ -738,7 +802,7 @@ class AgentApplication(Agent, Generic[StateT]):
738
802
  return True
739
803
 
740
804
  async def _on_activity(self, context: TurnContext, state: StateT):
741
- for route in self._routes:
805
+ for route in self._route_list:
742
806
  if route.selector(context):
743
807
  if not route.auth_handlers:
744
808
  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
- Attributes:
20
- content (bytes): The downloaded content of the file.
21
- content_type (str): The content type of the file.
22
- content_url (Optional[str]): Optional. URL to the content of the file.
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
- A plugin responsible for downloading files relative to the current user's input.
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 relative to the current user's input.
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
- Returns:
44
- List[InputFile]: A list of input files.
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,7 @@
1
+ # Copyright (c) Microsoft Corporation. All rights reserved.
2
+ # Licensed under the MIT License.
3
+
4
+
1
5
  from .authorization import Authorization
2
6
  from .auth_handler import AuthHandler
3
7
  from ._sign_in_state import _SignInState
@@ -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], optional
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]], optional
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], optional
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]], optional
97
+ :type exchange_scopes: Optional[list[str]], Optional
93
98
  """
94
99
  raise NotImplementedError()
95
100
 
@@ -1,5 +1,7 @@
1
- # Copyright (c) Microsoft Corporation. All rights reserved.
2
- # Licensed under the MIT License.
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], optional
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]], optional
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], optional
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__(
@@ -113,20 +118,20 @@ class AgenticUserAuthorization(_AuthorizationHandler):
113
118
  connection = self._connection_manager.get_token_provider(
114
119
  context.identity, "agentic"
115
120
  )
116
- upn = context.activity.get_agentic_user()
121
+ agentic_user_id = context.activity.get_agentic_user()
117
122
  agentic_instance_id = context.activity.get_agentic_instance_id()
118
- if not upn or not agentic_instance_id:
123
+ if not agentic_user_id or not agentic_instance_id:
119
124
  logger.error(
120
- "Unable to retrieve agentic user token: missing UPN or agentic instance ID. UPN: %s, Agentic Instance ID: %s",
121
- upn,
125
+ "Unable to retrieve agentic user token: missing agentic user Id or agentic instance Id. agentic_user_id: %s, Agentic Instance ID: %s",
126
+ agentic_user_id,
122
127
  agentic_instance_id,
123
128
  )
124
129
  raise ValueError(
125
- f"Unable to retrieve agentic user token: missing UPN or agentic instance ID. UPN: {upn}, Agentic Instance ID: {agentic_instance_id}"
130
+ f"Unable to retrieve agentic user token: missing agentic User Id or agentic instance Id. agentic_user_id: {agentic_user_id}, Agentic Instance ID: {agentic_instance_id}"
126
131
  )
127
132
 
128
133
  token = await connection.get_agentic_user_token(
129
- agentic_instance_id, upn, scopes
134
+ agentic_instance_id, agentic_user_id, scopes
130
135
  )
131
136
  return TokenResponse(token=token) if token else TokenResponse()
132
137
 
@@ -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], optional
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]], optional
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,7 @@
1
+ # Copyright (c) Microsoft Corporation. All rights reserved.
2
+ # Licensed under the MIT License.
3
+
4
+
1
5
  from typing import Optional
2
6
 
3
7
  from microsoft_agents.activity import TokenResponse
@@ -1,3 +1,8 @@
1
+ """
2
+ Copyright (c) Microsoft Corporation. All rights reserved.
3
+ Licensed under the MIT License.
4
+ """
5
+
1
6
  from __future__ import annotations
2
7
 
3
8
  from typing import Optional
@@ -1,5 +1,7 @@
1
- # Copyright (c) Microsoft Corporation. All rights reserved.
2
- # Licensed under the MIT License.
1
+ """
2
+ Copyright (c) Microsoft Corporation. All rights reserved.
3
+ Licensed under the MIT License.
4
+ """
3
5
 
4
6
  import logging
5
7
  from typing import Optional