microsoft-agents-activity 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.
Potentially problematic release.
This version of microsoft-agents-activity might be problematic. Click here for more details.
- microsoft_agents/activity/__init__.py +12 -0
- microsoft_agents/activity/_channel_id_field_mixin.py +96 -0
- microsoft_agents/activity/_load_configuration.py +3 -0
- microsoft_agents/activity/_model_utils.py +3 -0
- microsoft_agents/activity/_type_aliases.py +3 -1
- microsoft_agents/activity/action_types.py +3 -0
- microsoft_agents/activity/activity.py +132 -11
- microsoft_agents/activity/activity_event_names.py +3 -0
- microsoft_agents/activity/activity_importance.py +3 -0
- microsoft_agents/activity/activity_types.py +3 -0
- microsoft_agents/activity/adaptive_card_invoke_action.py +3 -0
- microsoft_agents/activity/adaptive_card_invoke_response.py +3 -0
- microsoft_agents/activity/adaptive_card_invoke_value.py +3 -0
- microsoft_agents/activity/agents_model.py +3 -0
- microsoft_agents/activity/animation_card.py +3 -0
- microsoft_agents/activity/attachment.py +3 -0
- microsoft_agents/activity/attachment_data.py +3 -0
- microsoft_agents/activity/attachment_info.py +3 -0
- microsoft_agents/activity/attachment_layout_types.py +3 -0
- microsoft_agents/activity/attachment_view.py +3 -0
- microsoft_agents/activity/audio_card.py +3 -0
- microsoft_agents/activity/basic_card.py +3 -0
- microsoft_agents/activity/caller_id_constants.py +3 -0
- microsoft_agents/activity/card_action.py +3 -0
- microsoft_agents/activity/card_image.py +3 -0
- microsoft_agents/activity/channel_account.py +3 -0
- microsoft_agents/activity/channel_adapter_protocol.py +3 -0
- microsoft_agents/activity/channel_id.py +95 -0
- microsoft_agents/activity/channels.py +2 -2
- microsoft_agents/activity/contact_relation_update_action_types.py +3 -0
- microsoft_agents/activity/conversation_account.py +3 -0
- microsoft_agents/activity/conversation_members.py +3 -0
- microsoft_agents/activity/conversation_parameters.py +3 -0
- microsoft_agents/activity/conversation_reference.py +12 -3
- microsoft_agents/activity/conversation_resource_response.py +3 -0
- microsoft_agents/activity/conversation_update_types.py +3 -0
- microsoft_agents/activity/conversations_result.py +3 -0
- microsoft_agents/activity/delivery_modes.py +3 -0
- microsoft_agents/activity/end_of_conversation_codes.py +3 -0
- microsoft_agents/activity/entity/__init__.py +7 -0
- microsoft_agents/activity/entity/entity.py +4 -3
- microsoft_agents/activity/entity/entity_types.py +14 -0
- microsoft_agents/activity/entity/geo_coordinates.py +9 -3
- microsoft_agents/activity/entity/mention.py +5 -2
- microsoft_agents/activity/entity/place.py +9 -3
- microsoft_agents/activity/entity/product_info.py +20 -0
- microsoft_agents/activity/entity/thing.py +9 -3
- microsoft_agents/activity/error.py +3 -0
- microsoft_agents/activity/error_response.py +3 -0
- microsoft_agents/activity/expected_replies.py +3 -0
- microsoft_agents/activity/fact.py +3 -0
- microsoft_agents/activity/hero_card.py +3 -0
- microsoft_agents/activity/inner_http_error.py +3 -0
- microsoft_agents/activity/installation_update_action_types.py +3 -0
- microsoft_agents/activity/invoke_response.py +3 -0
- microsoft_agents/activity/media_card.py +3 -0
- microsoft_agents/activity/media_event_value.py +3 -0
- microsoft_agents/activity/media_url.py +3 -0
- microsoft_agents/activity/message_reaction.py +3 -0
- microsoft_agents/activity/message_reaction_types.py +3 -0
- microsoft_agents/activity/message_update_types.py +3 -0
- microsoft_agents/activity/oauth_card.py +3 -0
- microsoft_agents/activity/paged_members_result.py +3 -0
- microsoft_agents/activity/receipt_card.py +3 -0
- microsoft_agents/activity/receipt_item.py +3 -0
- microsoft_agents/activity/resource_response.py +3 -0
- microsoft_agents/activity/role_types.py +3 -0
- microsoft_agents/activity/semantic_action.py +4 -1
- microsoft_agents/activity/semantic_actions_states.py +3 -0
- microsoft_agents/activity/sign_in_resource.py +3 -0
- microsoft_agents/activity/signin_card.py +3 -0
- microsoft_agents/activity/suggested_actions.py +3 -0
- microsoft_agents/activity/text_format_types.py +3 -0
- microsoft_agents/activity/text_highlight.py +3 -0
- microsoft_agents/activity/thumbnail_card.py +3 -0
- microsoft_agents/activity/thumbnail_url.py +3 -0
- microsoft_agents/activity/token_exchange_invoke_request.py +3 -0
- microsoft_agents/activity/token_exchange_invoke_response.py +3 -0
- microsoft_agents/activity/token_exchange_resource.py +3 -0
- microsoft_agents/activity/token_exchange_state.py +3 -0
- microsoft_agents/activity/token_or_sign_in_resource_response.py +21 -0
- microsoft_agents/activity/token_post_resource.py +3 -0
- microsoft_agents/activity/token_request.py +3 -0
- microsoft_agents/activity/transcript.py +3 -0
- microsoft_agents/activity/turn_context_protocol.py +3 -0
- microsoft_agents/activity/video_card.py +3 -0
- microsoft_agents_activity-0.5.0.dist-info/METADATA +173 -0
- {microsoft_agents_activity-0.4.0.dev16.dist-info → microsoft_agents_activity-0.5.0.dist-info}/RECORD +91 -85
- microsoft_agents_activity-0.5.0.dist-info/licenses/LICENSE +21 -0
- microsoft_agents_activity-0.4.0.dev16.dist-info/METADATA +0 -11
- {microsoft_agents_activity-0.4.0.dev16.dist-info → microsoft_agents_activity-0.5.0.dist-info}/WHEEL +0 -0
- {microsoft_agents_activity-0.4.0.dev16.dist-info → microsoft_agents_activity-0.5.0.dist-info}/top_level.txt +0 -0
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
+
# Licensed under the MIT License.
|
|
3
|
+
|
|
1
4
|
from .agents_model import AgentsModel
|
|
2
5
|
from .action_types import ActionTypes
|
|
3
6
|
from .activity import Activity
|
|
@@ -17,6 +20,8 @@ from .card_action import CardAction
|
|
|
17
20
|
from .card_image import CardImage
|
|
18
21
|
from .channels import Channels
|
|
19
22
|
from .channel_account import ChannelAccount
|
|
23
|
+
from ._channel_id_field_mixin import _ChannelIdFieldMixin
|
|
24
|
+
from .channel_id import ChannelId
|
|
20
25
|
from .conversation_account import ConversationAccount
|
|
21
26
|
from .conversation_members import ConversationMembers
|
|
22
27
|
from .conversation_parameters import ConversationParameters
|
|
@@ -26,6 +31,7 @@ from .conversations_result import ConversationsResult
|
|
|
26
31
|
from .expected_replies import ExpectedReplies
|
|
27
32
|
from .entity import (
|
|
28
33
|
Entity,
|
|
34
|
+
EntityTypes,
|
|
29
35
|
AIEntity,
|
|
30
36
|
ClientCitation,
|
|
31
37
|
ClientCitationAppearance,
|
|
@@ -36,6 +42,7 @@ from .entity import (
|
|
|
36
42
|
SensitivityPattern,
|
|
37
43
|
GeoCoordinates,
|
|
38
44
|
Place,
|
|
45
|
+
ProductInfo,
|
|
39
46
|
Thing,
|
|
40
47
|
)
|
|
41
48
|
from .error import Error
|
|
@@ -62,6 +69,7 @@ from .thumbnail_url import ThumbnailUrl
|
|
|
62
69
|
from .token_exchange_invoke_request import TokenExchangeInvokeRequest
|
|
63
70
|
from .token_exchange_invoke_response import TokenExchangeInvokeResponse
|
|
64
71
|
from .token_exchange_state import TokenExchangeState
|
|
72
|
+
from .token_or_sign_in_resource_response import TokenOrSignInResourceResponse
|
|
65
73
|
from .token_request import TokenRequest
|
|
66
74
|
from .token_response import TokenResponse
|
|
67
75
|
from .token_status import TokenStatus
|
|
@@ -114,6 +122,8 @@ __all__ = [
|
|
|
114
122
|
"CardImage",
|
|
115
123
|
"Channels",
|
|
116
124
|
"ChannelAccount",
|
|
125
|
+
"ChannelId",
|
|
126
|
+
"_ChannelIdFieldMixin",
|
|
117
127
|
"ConversationAccount",
|
|
118
128
|
"ConversationMembers",
|
|
119
129
|
"ConversationParameters",
|
|
@@ -144,6 +154,7 @@ __all__ = [
|
|
|
144
154
|
"OAuthCard",
|
|
145
155
|
"PagedMembersResult",
|
|
146
156
|
"Place",
|
|
157
|
+
"ProductInfo",
|
|
147
158
|
"ReceiptCard",
|
|
148
159
|
"ReceiptItem",
|
|
149
160
|
"ResourceResponse",
|
|
@@ -185,4 +196,5 @@ __all__ = [
|
|
|
185
196
|
"load_configuration_from_env",
|
|
186
197
|
"ChannelAdapterProtocol",
|
|
187
198
|
"TurnContextProtocol",
|
|
199
|
+
"TokenOrSignInResourceResponse",
|
|
188
200
|
]
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
+
# Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import logging
|
|
7
|
+
from typing import Optional, Any
|
|
8
|
+
|
|
9
|
+
from pydantic import (
|
|
10
|
+
ModelWrapValidatorHandler,
|
|
11
|
+
SerializerFunctionWrapHandler,
|
|
12
|
+
computed_field,
|
|
13
|
+
model_validator,
|
|
14
|
+
model_serializer,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
from .channel_id import ChannelId
|
|
18
|
+
|
|
19
|
+
logger = logging.getLogger(__name__)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
# can be generalized in the future, if needed
|
|
23
|
+
class _ChannelIdFieldMixin:
|
|
24
|
+
"""A mixin to add a computed field channel_id of type ChannelId to a Pydantic model."""
|
|
25
|
+
|
|
26
|
+
_channel_id: Optional[ChannelId] = None
|
|
27
|
+
|
|
28
|
+
# required to define the setter below
|
|
29
|
+
@computed_field(return_type=Optional[ChannelId], alias="channelId")
|
|
30
|
+
@property
|
|
31
|
+
def channel_id(self) -> Optional[ChannelId]:
|
|
32
|
+
"""Gets the _channel_id field"""
|
|
33
|
+
return self._channel_id
|
|
34
|
+
|
|
35
|
+
# necessary for backward compatibility
|
|
36
|
+
# previously, channel_id was directly assigned with strings
|
|
37
|
+
@channel_id.setter
|
|
38
|
+
def channel_id(self, value: Any):
|
|
39
|
+
"""Sets the channel_id after validating it as a ChannelId model."""
|
|
40
|
+
if isinstance(value, ChannelId):
|
|
41
|
+
self._channel_id = value
|
|
42
|
+
elif isinstance(value, str):
|
|
43
|
+
self._channel_id = ChannelId(value)
|
|
44
|
+
else:
|
|
45
|
+
raise ValueError(
|
|
46
|
+
f"Invalid type for channel_id: {type(value)}. "
|
|
47
|
+
"Expected ChannelId or str."
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
def _set_validated_channel_id(self, data: Any) -> None:
|
|
51
|
+
"""Sets the channel_id after validating it as a ChannelId model."""
|
|
52
|
+
if "channelId" in data:
|
|
53
|
+
self.channel_id = data["channelId"]
|
|
54
|
+
elif "channel_id" in data:
|
|
55
|
+
self.channel_id = data["channel_id"]
|
|
56
|
+
|
|
57
|
+
@model_validator(mode="wrap")
|
|
58
|
+
@classmethod
|
|
59
|
+
def _validate_channel_id(
|
|
60
|
+
cls, data: Any, handler: ModelWrapValidatorHandler
|
|
61
|
+
) -> _ChannelIdFieldMixin:
|
|
62
|
+
"""Validate the _channel_id field after model initialization.
|
|
63
|
+
|
|
64
|
+
:return: The model instance itself.
|
|
65
|
+
"""
|
|
66
|
+
try:
|
|
67
|
+
model = handler(data)
|
|
68
|
+
model._set_validated_channel_id(data)
|
|
69
|
+
return model
|
|
70
|
+
except Exception:
|
|
71
|
+
logging.error("Model %s failed to validate with data %s", cls, data)
|
|
72
|
+
raise
|
|
73
|
+
|
|
74
|
+
def _remove_serialized_unset_channel_id(
|
|
75
|
+
self, serialized: dict[str, object]
|
|
76
|
+
) -> None:
|
|
77
|
+
"""Remove the _channel_id field if it is not set."""
|
|
78
|
+
if not self._channel_id:
|
|
79
|
+
if "channelId" in serialized:
|
|
80
|
+
del serialized["channelId"]
|
|
81
|
+
elif "channel_id" in serialized:
|
|
82
|
+
del serialized["channel_id"]
|
|
83
|
+
|
|
84
|
+
@model_serializer(mode="wrap")
|
|
85
|
+
def _serialize_channel_id(
|
|
86
|
+
self, handler: SerializerFunctionWrapHandler
|
|
87
|
+
) -> dict[str, object]:
|
|
88
|
+
"""Serialize the model using Pydantic's standard serialization.
|
|
89
|
+
|
|
90
|
+
:param handler: The serialization handler provided by Pydantic.
|
|
91
|
+
:return: A dictionary representing the serialized model.
|
|
92
|
+
"""
|
|
93
|
+
serialized = handler(self)
|
|
94
|
+
if self: # serialization can be called with None
|
|
95
|
+
self._remove_serialized_unset_channel_id(serialized)
|
|
96
|
+
return serialized
|
|
@@ -1,7 +1,24 @@
|
|
|
1
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
+
# Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import logging
|
|
1
7
|
from copy import copy
|
|
2
8
|
from datetime import datetime, timezone
|
|
3
|
-
from typing import Optional
|
|
4
|
-
|
|
9
|
+
from typing import Optional, Any
|
|
10
|
+
|
|
11
|
+
from pydantic import (
|
|
12
|
+
Field,
|
|
13
|
+
SerializeAsAny,
|
|
14
|
+
model_serializer,
|
|
15
|
+
model_validator,
|
|
16
|
+
SerializerFunctionWrapHandler,
|
|
17
|
+
ModelWrapValidatorHandler,
|
|
18
|
+
computed_field,
|
|
19
|
+
ValidationError,
|
|
20
|
+
)
|
|
21
|
+
|
|
5
22
|
from .activity_types import ActivityTypes
|
|
6
23
|
from .channel_account import ChannelAccount
|
|
7
24
|
from .conversation_account import ConversationAccount
|
|
@@ -11,9 +28,11 @@ from .suggested_actions import SuggestedActions
|
|
|
11
28
|
from .attachment import Attachment
|
|
12
29
|
from .entity import (
|
|
13
30
|
Entity,
|
|
31
|
+
EntityTypes,
|
|
14
32
|
Mention,
|
|
15
33
|
AIEntity,
|
|
16
34
|
ClientCitation,
|
|
35
|
+
ProductInfo,
|
|
17
36
|
SensitivityUsageInfo,
|
|
18
37
|
)
|
|
19
38
|
from .conversation_reference import ConversationReference
|
|
@@ -21,12 +40,16 @@ from .text_highlight import TextHighlight
|
|
|
21
40
|
from .semantic_action import SemanticAction
|
|
22
41
|
from .agents_model import AgentsModel
|
|
23
42
|
from .role_types import RoleTypes
|
|
43
|
+
from ._channel_id_field_mixin import _ChannelIdFieldMixin
|
|
44
|
+
from .channel_id import ChannelId
|
|
24
45
|
from ._model_utils import pick_model, SkipNone
|
|
25
46
|
from ._type_aliases import NonEmptyString
|
|
26
47
|
|
|
48
|
+
logger = logging.getLogger(__name__)
|
|
49
|
+
|
|
27
50
|
|
|
28
51
|
# TODO: A2A Agent 2 is responding with None as id, had to mark it as optional (investigate)
|
|
29
|
-
class Activity(AgentsModel):
|
|
52
|
+
class Activity(AgentsModel, _ChannelIdFieldMixin):
|
|
30
53
|
"""An Activity is the basic communication type for the protocol.
|
|
31
54
|
|
|
32
55
|
:param type: Contains the activity type. Possible values include:
|
|
@@ -47,8 +70,8 @@ class Activity(AgentsModel):
|
|
|
47
70
|
:type local_timezone: str
|
|
48
71
|
:param service_url: Contains the URL that specifies the channel's service endpoint. Set by the channel.
|
|
49
72
|
:type service_url: str
|
|
50
|
-
:param channel_id: Contains an ID that uniquely identifies the channel. Set by the channel.
|
|
51
|
-
:type channel_id:
|
|
73
|
+
:param channel_id: Contains an ID that uniquely identifies the channel (and possibly the sub-channel). Set by the channel.
|
|
74
|
+
:type channel_id: ~microsoft_agents.activity.ChannelId
|
|
52
75
|
:param from_property: Identifies the sender of the message.
|
|
53
76
|
:type from_property: ~microsoft_agents.activity.ChannelAccount
|
|
54
77
|
:param conversation: Identifies the conversation to which the activity belongs.
|
|
@@ -133,7 +156,6 @@ class Activity(AgentsModel):
|
|
|
133
156
|
local_timestamp: datetime = None
|
|
134
157
|
local_timezone: NonEmptyString = None
|
|
135
158
|
service_url: NonEmptyString = None
|
|
136
|
-
channel_id: NonEmptyString = None
|
|
137
159
|
from_property: ChannelAccount = Field(None, alias="from")
|
|
138
160
|
conversation: ConversationAccount = None
|
|
139
161
|
recipient: ChannelAccount = None
|
|
@@ -170,6 +192,99 @@ class Activity(AgentsModel):
|
|
|
170
192
|
semantic_action: SemanticAction = None
|
|
171
193
|
caller_id: NonEmptyString = None
|
|
172
194
|
|
|
195
|
+
@model_validator(mode="wrap")
|
|
196
|
+
@classmethod
|
|
197
|
+
def _validate_channel_id(
|
|
198
|
+
cls, data: Any, handler: ModelWrapValidatorHandler[Activity]
|
|
199
|
+
) -> Activity:
|
|
200
|
+
"""Validate the Activity, ensuring consistency between channel_id.sub_channel and productInfo entity.
|
|
201
|
+
|
|
202
|
+
:param data: The input data to validate.
|
|
203
|
+
:param handler: The validation handler provided by Pydantic.
|
|
204
|
+
:return: The validated Activity instance.
|
|
205
|
+
"""
|
|
206
|
+
try:
|
|
207
|
+
# run Pydantic's standard validation first
|
|
208
|
+
activity = handler(data)
|
|
209
|
+
|
|
210
|
+
# needed to assign to a computed field
|
|
211
|
+
# needed because we override the mixin validator
|
|
212
|
+
activity._set_validated_channel_id(data)
|
|
213
|
+
|
|
214
|
+
# sync sub_channel with productInfo entity
|
|
215
|
+
product_info = activity.get_product_info_entity()
|
|
216
|
+
if product_info and activity.channel_id:
|
|
217
|
+
if (
|
|
218
|
+
activity.channel_id.sub_channel
|
|
219
|
+
and activity.channel_id.sub_channel != product_info.id
|
|
220
|
+
):
|
|
221
|
+
raise Exception(
|
|
222
|
+
"Conflict between channel_id.sub_channel and productInfo entity"
|
|
223
|
+
)
|
|
224
|
+
activity.channel_id = ChannelId(
|
|
225
|
+
channel=activity.channel_id.channel,
|
|
226
|
+
sub_channel=product_info.id,
|
|
227
|
+
)
|
|
228
|
+
|
|
229
|
+
return activity
|
|
230
|
+
except ValidationError as exc:
|
|
231
|
+
logger.error("Validation error for Activity: %s", exc, exc_info=True)
|
|
232
|
+
raise
|
|
233
|
+
|
|
234
|
+
@model_serializer(mode="wrap")
|
|
235
|
+
def _serialize_sub_channel_data(
|
|
236
|
+
self, handler: SerializerFunctionWrapHandler
|
|
237
|
+
) -> dict[str, object]:
|
|
238
|
+
"""Serialize the Activity, ensuring consistency between channel_id.sub_channel and productInfo entity.
|
|
239
|
+
|
|
240
|
+
:param handler: The serialization handler provided by Pydantic.
|
|
241
|
+
:return: A dictionary representing the serialized Activity.
|
|
242
|
+
"""
|
|
243
|
+
|
|
244
|
+
# run Pydantic's standard serialization first
|
|
245
|
+
serialized = handler(self)
|
|
246
|
+
if not self: # serialization can be called with None
|
|
247
|
+
return serialized
|
|
248
|
+
|
|
249
|
+
# find the ProductInfo entity
|
|
250
|
+
product_info = None
|
|
251
|
+
for i, entity in enumerate(serialized.get("entities") or []):
|
|
252
|
+
if entity.get("type", "") == EntityTypes.PRODUCT_INFO:
|
|
253
|
+
product_info = entity
|
|
254
|
+
break
|
|
255
|
+
|
|
256
|
+
# self.channel_id is the source of truth for serialization
|
|
257
|
+
if self.channel_id and self.channel_id.sub_channel:
|
|
258
|
+
if product_info and product_info.get("id") != self.channel_id.sub_channel:
|
|
259
|
+
raise Exception(
|
|
260
|
+
"Conflict between channel_id.sub_channel and productInfo entity"
|
|
261
|
+
)
|
|
262
|
+
elif not product_info:
|
|
263
|
+
if not serialized.get("entities"):
|
|
264
|
+
serialized["entities"] = []
|
|
265
|
+
serialized["entities"].append(
|
|
266
|
+
{
|
|
267
|
+
"type": EntityTypes.PRODUCT_INFO,
|
|
268
|
+
"id": self.channel_id.sub_channel,
|
|
269
|
+
}
|
|
270
|
+
)
|
|
271
|
+
|
|
272
|
+
# simply serialized channelId value in Activity and relatesTo
|
|
273
|
+
if "channelId" in serialized:
|
|
274
|
+
serialized["channelId"] = self.channel_id.channel
|
|
275
|
+
elif "channel_id" in serialized:
|
|
276
|
+
serialized["channel_id"] = self.channel_id.channel
|
|
277
|
+
|
|
278
|
+
elif product_info: # remove productInfo entity if sub_channel is not set
|
|
279
|
+
del serialized["entities"][i]
|
|
280
|
+
if not serialized["entities"]: # after removal above, list may be empty
|
|
281
|
+
del serialized["entities"]
|
|
282
|
+
|
|
283
|
+
# necessary due to computed_field serialization
|
|
284
|
+
self._remove_serialized_unset_channel_id(serialized)
|
|
285
|
+
|
|
286
|
+
return serialized
|
|
287
|
+
|
|
173
288
|
def apply_conversation_reference(
|
|
174
289
|
self, reference: ConversationReference, is_incoming: bool = False
|
|
175
290
|
):
|
|
@@ -429,7 +544,6 @@ class Activity(AgentsModel):
|
|
|
429
544
|
def create_trace(
|
|
430
545
|
self, name: str, value: object = None, value_type: str = None, label: str = None
|
|
431
546
|
):
|
|
432
|
-
# robrandao: TODO -> needs to handle Nones like create_reply
|
|
433
547
|
"""
|
|
434
548
|
Creates a new trace activity based on this activity.
|
|
435
549
|
|
|
@@ -476,7 +590,6 @@ class Activity(AgentsModel):
|
|
|
476
590
|
def create_trace_activity(
|
|
477
591
|
name: str, value: object = None, value_type: str = None, label: str = None
|
|
478
592
|
):
|
|
479
|
-
# robrandao: TODO -> SkipNone
|
|
480
593
|
"""
|
|
481
594
|
Creates an instance of the :class:`Activity` class as a TraceActivity object.
|
|
482
595
|
|
|
@@ -530,6 +643,14 @@ class Activity(AgentsModel):
|
|
|
530
643
|
service_url=self.service_url,
|
|
531
644
|
)
|
|
532
645
|
|
|
646
|
+
def get_product_info_entity(self) -> Optional[ProductInfo]:
|
|
647
|
+
if not self.entities:
|
|
648
|
+
return None
|
|
649
|
+
target = EntityTypes.PRODUCT_INFO.lower()
|
|
650
|
+
# validated entities can be Entity, and that prevents us from
|
|
651
|
+
# making assumptions about the casing of the 'type' attribute
|
|
652
|
+
return next(filter(lambda e: e.type.lower() == target, self.entities), None)
|
|
653
|
+
|
|
533
654
|
def get_mentions(self) -> list[Mention]:
|
|
534
655
|
"""
|
|
535
656
|
Resolves the mentions from the entities of this activity.
|
|
@@ -542,7 +663,7 @@ class Activity(AgentsModel):
|
|
|
542
663
|
"""
|
|
543
664
|
if not self.entities:
|
|
544
665
|
return []
|
|
545
|
-
return [x for x in self.entities if x.type.lower() ==
|
|
666
|
+
return [x for x in self.entities if x.type.lower() == EntityTypes.MENTION]
|
|
546
667
|
|
|
547
668
|
def get_reply_conversation_reference(
|
|
548
669
|
self, reply: ResourceResponse
|
|
@@ -663,7 +784,7 @@ class Activity(AgentsModel):
|
|
|
663
784
|
return self.recipient.agentic_app_id
|
|
664
785
|
|
|
665
786
|
def get_agentic_user(self) -> Optional[str]:
|
|
666
|
-
"""Gets the agentic user (
|
|
787
|
+
"""Gets the agentic user (agenticUserId) from the context if it's an agentic request."""
|
|
667
788
|
if not self.is_agentic_request() or not self.recipient:
|
|
668
789
|
return None
|
|
669
|
-
return self.recipient.
|
|
790
|
+
return self.recipient.agentic_user_id
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
+
# Licensed under the MIT License.
|
|
3
|
+
|
|
1
4
|
from .adaptive_card_invoke_action import AdaptiveCardInvokeAction
|
|
2
5
|
from .token_exchange_invoke_request import TokenExchangeInvokeRequest
|
|
3
6
|
from .agents_model import AgentsModel
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
+
# Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
from typing import Optional, Any
|
|
7
|
+
|
|
8
|
+
from pydantic_core import CoreSchema, core_schema
|
|
9
|
+
from pydantic import GetCoreSchemaHandler
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class ChannelId(str):
|
|
13
|
+
"""A ChannelId represents a channel and optional sub-channel in the format 'channel:sub_channel'."""
|
|
14
|
+
|
|
15
|
+
def __init__(
|
|
16
|
+
self,
|
|
17
|
+
value: Optional[str] = None,
|
|
18
|
+
*,
|
|
19
|
+
channel: Optional[str] = None,
|
|
20
|
+
sub_channel: Optional[str] = None,
|
|
21
|
+
) -> None:
|
|
22
|
+
"""Initialize a ChannelId instance.
|
|
23
|
+
|
|
24
|
+
:param value: The full channel ID string in the format 'channel:sub_channel'. Must be provided if channel is not provided.
|
|
25
|
+
:param channel: The main channel string. Must be provided if value is not provided.
|
|
26
|
+
:param sub_channel: The sub-channel string.
|
|
27
|
+
:raises ValueError: If the input parameters are invalid. value and channel cannot both be provided.
|
|
28
|
+
"""
|
|
29
|
+
super().__init__()
|
|
30
|
+
if not channel:
|
|
31
|
+
split = self.strip().split(":", 1)
|
|
32
|
+
self._channel = split[0].strip()
|
|
33
|
+
self._sub_channel = split[1].strip() if len(split) == 2 else None
|
|
34
|
+
else:
|
|
35
|
+
self._channel = channel
|
|
36
|
+
self._sub_channel = sub_channel
|
|
37
|
+
|
|
38
|
+
def __new__(
|
|
39
|
+
cls,
|
|
40
|
+
value: Optional[str] = None,
|
|
41
|
+
*,
|
|
42
|
+
channel: Optional[str] = None,
|
|
43
|
+
sub_channel: Optional[str] = None,
|
|
44
|
+
) -> ChannelId:
|
|
45
|
+
"""Create a new ChannelId instance.
|
|
46
|
+
|
|
47
|
+
:param value: The full channel ID string in the format 'channel:sub_channel'. Must be provided if channel is not provided.
|
|
48
|
+
:param channel: The main channel string. Must be provided if value is not provided. Must not contain ':', as it delimits channels and sub channels.
|
|
49
|
+
:param sub_channel: The sub-channel string.
|
|
50
|
+
:return: A new ChannelId instance.
|
|
51
|
+
:raises ValueError: If the input parameters are invalid. value and channel cannot both be provided.
|
|
52
|
+
"""
|
|
53
|
+
if isinstance(value, str):
|
|
54
|
+
if channel or sub_channel:
|
|
55
|
+
raise ValueError(
|
|
56
|
+
"If value is provided, channel and sub_channel must be None"
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
value = value.strip()
|
|
60
|
+
if value:
|
|
61
|
+
return str.__new__(cls, value)
|
|
62
|
+
raise TypeError("value must be a non empty string if provided")
|
|
63
|
+
else:
|
|
64
|
+
if (
|
|
65
|
+
not isinstance(channel, str)
|
|
66
|
+
or len(channel.strip()) == 0
|
|
67
|
+
or ":" in channel
|
|
68
|
+
):
|
|
69
|
+
raise TypeError(
|
|
70
|
+
"channel must be a non empty string, and must not contain the ':' character"
|
|
71
|
+
)
|
|
72
|
+
if sub_channel is not None and (not isinstance(sub_channel, str)):
|
|
73
|
+
raise TypeError("sub_channel must be a string if provided")
|
|
74
|
+
channel = channel.strip()
|
|
75
|
+
sub_channel = sub_channel.strip() if sub_channel else None
|
|
76
|
+
if sub_channel:
|
|
77
|
+
return str.__new__(cls, f"{channel}:{sub_channel}")
|
|
78
|
+
return str.__new__(cls, channel)
|
|
79
|
+
|
|
80
|
+
@property
|
|
81
|
+
def channel(self) -> str:
|
|
82
|
+
"""The main channel, e.g. 'email' in 'email:work'."""
|
|
83
|
+
return self._channel # type: ignore[return-value]
|
|
84
|
+
|
|
85
|
+
@property
|
|
86
|
+
def sub_channel(self) -> Optional[str]:
|
|
87
|
+
"""The sub-channel, e.g. 'work' in 'email:work'. May be None."""
|
|
88
|
+
return self._sub_channel
|
|
89
|
+
|
|
90
|
+
# https://docs.pydantic.dev/dev/concepts/types/#customizing-validation-with-__get_pydantic_core_schema__
|
|
91
|
+
@classmethod
|
|
92
|
+
def __get_pydantic_core_schema__(
|
|
93
|
+
cls, source_type: Any, handler: GetCoreSchemaHandler
|
|
94
|
+
) -> CoreSchema:
|
|
95
|
+
return core_schema.no_info_after_validator_function(cls, handler(str))
|