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.
- 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 +20 -17
- 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 +116 -52
- 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 +14 -9
- 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 +43 -20
- microsoft_agents/hosting/core/app/state/state.py +50 -6
- microsoft_agents/hosting/core/app/typing_indicator.py +51 -27
- microsoft_agents/hosting/core/authorization/access_token_provider_base.py +4 -1
- microsoft_agents/hosting/core/authorization/agent_auth_configuration.py +3 -0
- microsoft_agents/hosting/core/authorization/anonymous_token_provider.py +4 -1
- 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 +9 -4
- 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 +65 -10
- 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 +1 -4
- 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/storage/transcript_file_store.py +1 -5
- microsoft_agents/hosting/core/turn_context.py +2 -1
- microsoft_agents_hosting_core-0.5.0.dist-info/METADATA +191 -0
- {microsoft_agents_hosting_core-0.4.0.dev16.dist-info → microsoft_agents_hosting_core-0.5.0.dist-info}/RECORD +64 -59
- microsoft_agents_hosting_core-0.5.0.dist-info/licenses/LICENSE +21 -0
- microsoft_agents/hosting/core/app/route.py +0 -32
- microsoft_agents_hosting_core-0.4.0.dev16.dist-info/METADATA +0 -16
- {microsoft_agents_hosting_core-0.4.0.dev16.dist-info → microsoft_agents_hosting_core-0.5.0.dist-info}/WHEEL +0 -0
- {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:
|
|
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.
|
|
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.
|
|
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,
|
|
269
|
+
activity_type: Union[str, ActivityTypes, list[Union[str, ActivityTypes]]],
|
|
210
270
|
*,
|
|
211
|
-
auth_handlers: Optional[
|
|
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.
|
|
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],
|
|
304
|
+
select: Union[str, Pattern[str], list[Union[str, Pattern[str]]]],
|
|
246
305
|
*,
|
|
247
|
-
auth_handlers: Optional[
|
|
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.
|
|
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[
|
|
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,
|
|
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,
|
|
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.
|
|
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,
|
|
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,
|
|
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,
|
|
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.
|
|
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,
|
|
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.
|
|
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(
|
|
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.
|
|
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
|
-
|
|
661
|
+
typing = None
|
|
602
662
|
try:
|
|
603
663
|
if context.activity.type != ActivityTypes.typing:
|
|
604
|
-
|
|
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
|
-
|
|
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:
|
|
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.
|
|
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
|
-
|
|
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__(
|
|
@@ -113,20 +118,20 @@ class AgenticUserAuthorization(_AuthorizationHandler):
|
|
|
113
118
|
connection = self._connection_manager.get_token_provider(
|
|
114
119
|
context.identity, "agentic"
|
|
115
120
|
)
|
|
116
|
-
|
|
121
|
+
agentic_user_id = context.activity.get_agentic_user()
|
|
117
122
|
agentic_instance_id = context.activity.get_agentic_instance_id()
|
|
118
|
-
if not
|
|
123
|
+
if not agentic_user_id or not agentic_instance_id:
|
|
119
124
|
logger.error(
|
|
120
|
-
"Unable to retrieve agentic user token: missing
|
|
121
|
-
|
|
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
|
|
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,
|
|
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],
|
|
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 []
|