unique_toolkit 0.8.28__py3-none-any.whl → 0.8.30__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.
- unique_toolkit/app/schemas.py +4 -0
- unique_toolkit/chat/functions.py +467 -0
- unique_toolkit/chat/schemas.py +70 -0
- unique_toolkit/chat/service.py +569 -0
- unique_toolkit/tools/a2a/__init__.py +4 -0
- unique_toolkit/tools/a2a/config.py +29 -0
- unique_toolkit/tools/a2a/manager.py +50 -0
- unique_toolkit/tools/a2a/memory.py +27 -0
- unique_toolkit/tools/a2a/schema.py +15 -0
- unique_toolkit/tools/a2a/service.py +154 -0
- unique_toolkit/tools/config.py +1 -0
- unique_toolkit/tools/mcp/models.py +0 -1
- unique_toolkit/tools/test/test_mcp_manager.py +55 -1
- unique_toolkit/tools/tool_manager.py +10 -1
- {unique_toolkit-0.8.28.dist-info → unique_toolkit-0.8.30.dist-info}/METADATA +11 -1
- {unique_toolkit-0.8.28.dist-info → unique_toolkit-0.8.30.dist-info}/RECORD +18 -12
- {unique_toolkit-0.8.28.dist-info → unique_toolkit-0.8.30.dist-info}/LICENSE +0 -0
- {unique_toolkit-0.8.28.dist-info → unique_toolkit-0.8.30.dist-info}/WHEEL +0 -0
unique_toolkit/app/schemas.py
CHANGED
|
@@ -196,6 +196,10 @@ class ChatEventPayload(BaseModel):
|
|
|
196
196
|
default_factory=list,
|
|
197
197
|
description="A list of MCP servers with tools available for the chat session.",
|
|
198
198
|
)
|
|
199
|
+
message_execution_id: str | None = Field(
|
|
200
|
+
default=None,
|
|
201
|
+
description="The message execution id for triggering the chat event. Originates from the message execution service.",
|
|
202
|
+
)
|
|
199
203
|
|
|
200
204
|
@field_validator("raw_scope_rules", mode="before")
|
|
201
205
|
def validate_scope_rules(cls, value: dict[str, Any] | None) -> UniqueQL | None:
|
unique_toolkit/chat/functions.py
CHANGED
|
@@ -15,6 +15,13 @@ from unique_toolkit.chat.schemas import (
|
|
|
15
15
|
ChatMessageAssessmentStatus,
|
|
16
16
|
ChatMessageAssessmentType,
|
|
17
17
|
ChatMessageRole,
|
|
18
|
+
MessageExecution,
|
|
19
|
+
MessageExecutionType,
|
|
20
|
+
MessageExecutionUpdateStatus,
|
|
21
|
+
MessageLog,
|
|
22
|
+
MessageLogDetails,
|
|
23
|
+
MessageLogStatus,
|
|
24
|
+
MessageLogUncitedReferences,
|
|
18
25
|
)
|
|
19
26
|
from unique_toolkit.content.schemas import ContentChunk, ContentReference
|
|
20
27
|
from unique_toolkit.content.utils import count_tokens
|
|
@@ -174,6 +181,26 @@ def map_references(references: list[ContentReference]) -> list[dict[str, Any]]:
|
|
|
174
181
|
]
|
|
175
182
|
|
|
176
183
|
|
|
184
|
+
def map_references_with_original_index(
|
|
185
|
+
references: list[ContentReference],
|
|
186
|
+
) -> list[dict[str, Any]]:
|
|
187
|
+
"""Maps ContentReference objects to dict format for MessageLog API (complete format).
|
|
188
|
+
|
|
189
|
+
This function includes all fields including originalIndex for APIs that support it.
|
|
190
|
+
"""
|
|
191
|
+
return [
|
|
192
|
+
{
|
|
193
|
+
"name": ref.name,
|
|
194
|
+
"url": ref.url,
|
|
195
|
+
"sequenceNumber": ref.sequence_number,
|
|
196
|
+
"sourceId": ref.source_id,
|
|
197
|
+
"source": ref.source,
|
|
198
|
+
"originalIndex": ref.original_index,
|
|
199
|
+
}
|
|
200
|
+
for ref in references
|
|
201
|
+
]
|
|
202
|
+
|
|
203
|
+
|
|
177
204
|
def _construct_message_modify_params(
|
|
178
205
|
user_id: str,
|
|
179
206
|
company_id: str,
|
|
@@ -887,3 +914,443 @@ async def stream_complete_with_references_async(
|
|
|
887
914
|
except Exception as e:
|
|
888
915
|
logger.error(f"Error streaming completion: {e}")
|
|
889
916
|
raise e
|
|
917
|
+
|
|
918
|
+
|
|
919
|
+
def create_message_log(
|
|
920
|
+
user_id: str,
|
|
921
|
+
company_id: str,
|
|
922
|
+
message_id: str,
|
|
923
|
+
text: str,
|
|
924
|
+
status: MessageLogStatus,
|
|
925
|
+
order: int,
|
|
926
|
+
details: MessageLogDetails | None = None,
|
|
927
|
+
uncited_references: MessageLogUncitedReferences | None = None,
|
|
928
|
+
references: list[ContentReference] | None = None,
|
|
929
|
+
) -> MessageLog:
|
|
930
|
+
"""Creates a message log synchronously.
|
|
931
|
+
|
|
932
|
+
Args:
|
|
933
|
+
user_id (str): The user ID.
|
|
934
|
+
company_id (str): The company ID.
|
|
935
|
+
message_id (str): The ID of the message this log belongs to.
|
|
936
|
+
text (str): The log text content.
|
|
937
|
+
status (MessageLogStatus): The status of this log entry.
|
|
938
|
+
order (int): The order/sequence number of this log entry.
|
|
939
|
+
details (MessageLogDetails | None): Additional details about this log entry.
|
|
940
|
+
uncited_references (MessageLogUncitedReferences | None): References that are not cited.
|
|
941
|
+
references (list[ContentReference] | None): List of references for this log.
|
|
942
|
+
|
|
943
|
+
Returns:
|
|
944
|
+
MessageLog: The created message log.
|
|
945
|
+
|
|
946
|
+
Raises:
|
|
947
|
+
Exception: If the creation fails.
|
|
948
|
+
|
|
949
|
+
"""
|
|
950
|
+
try:
|
|
951
|
+
message_log = unique_sdk.MessageLog.create(
|
|
952
|
+
user_id=user_id,
|
|
953
|
+
company_id=company_id,
|
|
954
|
+
messageId=message_id,
|
|
955
|
+
text=text,
|
|
956
|
+
status=status.value,
|
|
957
|
+
order=order,
|
|
958
|
+
details=details.model_dump() if details else None,
|
|
959
|
+
uncitedReferences=uncited_references.model_dump()
|
|
960
|
+
if uncited_references
|
|
961
|
+
else None,
|
|
962
|
+
references=map_references_with_original_index(references)
|
|
963
|
+
if references
|
|
964
|
+
else [], # type: ignore
|
|
965
|
+
)
|
|
966
|
+
return MessageLog(**message_log)
|
|
967
|
+
except Exception as e:
|
|
968
|
+
logger.error(f"Failed to create message log: {e}")
|
|
969
|
+
raise e
|
|
970
|
+
|
|
971
|
+
|
|
972
|
+
async def create_message_log_async(
|
|
973
|
+
user_id: str,
|
|
974
|
+
company_id: str,
|
|
975
|
+
message_id: str,
|
|
976
|
+
text: str,
|
|
977
|
+
status: MessageLogStatus,
|
|
978
|
+
order: int,
|
|
979
|
+
details: MessageLogDetails | None = None,
|
|
980
|
+
uncited_references: MessageLogUncitedReferences | None = None,
|
|
981
|
+
references: list[ContentReference] | None = None,
|
|
982
|
+
) -> MessageLog:
|
|
983
|
+
"""Creates a message log asynchronously.
|
|
984
|
+
|
|
985
|
+
Args:
|
|
986
|
+
user_id (str): The user ID.
|
|
987
|
+
company_id (str): The company ID.
|
|
988
|
+
message_id (str): The ID of the message this log belongs to.
|
|
989
|
+
text (str): The log text content.
|
|
990
|
+
status (MessageLogStatus): The status of this log entry.
|
|
991
|
+
order (int): The order/sequence number of this log entry.
|
|
992
|
+
details (MessageLogDetails | None): Additional details about this log entry.
|
|
993
|
+
uncited_references (MessageLogUncitedReferences | None): References that are not cited.
|
|
994
|
+
references (list[ContentReference] | None): List of references for this log.
|
|
995
|
+
|
|
996
|
+
Returns:
|
|
997
|
+
MessageLog: The created message log.
|
|
998
|
+
|
|
999
|
+
Raises:
|
|
1000
|
+
Exception: If the creation fails.
|
|
1001
|
+
|
|
1002
|
+
"""
|
|
1003
|
+
try:
|
|
1004
|
+
message_log = await unique_sdk.MessageLog.create_async(
|
|
1005
|
+
user_id=user_id,
|
|
1006
|
+
company_id=company_id,
|
|
1007
|
+
messageId=message_id,
|
|
1008
|
+
text=text,
|
|
1009
|
+
status=status.value,
|
|
1010
|
+
order=order,
|
|
1011
|
+
details=details.model_dump() if details else None,
|
|
1012
|
+
uncitedReferences=uncited_references.model_dump()
|
|
1013
|
+
if uncited_references
|
|
1014
|
+
else None,
|
|
1015
|
+
references=map_references_with_original_index(references)
|
|
1016
|
+
if references
|
|
1017
|
+
else [], # type: ignore
|
|
1018
|
+
)
|
|
1019
|
+
return MessageLog(**message_log)
|
|
1020
|
+
except Exception as e:
|
|
1021
|
+
logger.error(f"Failed to create message log: {e}")
|
|
1022
|
+
raise e
|
|
1023
|
+
|
|
1024
|
+
|
|
1025
|
+
def update_message_log(
|
|
1026
|
+
user_id: str,
|
|
1027
|
+
company_id: str,
|
|
1028
|
+
message_log_id: str,
|
|
1029
|
+
order: int,
|
|
1030
|
+
text: str | None = None,
|
|
1031
|
+
status: MessageLogStatus | None = None,
|
|
1032
|
+
details: MessageLogDetails | None = None,
|
|
1033
|
+
uncited_references: MessageLogUncitedReferences | None = None,
|
|
1034
|
+
references: list[ContentReference] | None = None,
|
|
1035
|
+
) -> MessageLog:
|
|
1036
|
+
"""Updates a message log synchronously.
|
|
1037
|
+
|
|
1038
|
+
Args:
|
|
1039
|
+
user_id (str): The user ID.
|
|
1040
|
+
company_id (str): The company ID.
|
|
1041
|
+
message_log_id (str): The ID of the message log to update.
|
|
1042
|
+
order (int): The order/sequence number (required).
|
|
1043
|
+
text (str | None): The updated log text content.
|
|
1044
|
+
status (MessageLogStatus | None): The updated status.
|
|
1045
|
+
details (MessageLogDetails | None): Updated additional details.
|
|
1046
|
+
uncited_references (MessageLogUncitedReferences | None): Updated uncited references.
|
|
1047
|
+
references (list[ContentReference] | None): Updated list of references.
|
|
1048
|
+
|
|
1049
|
+
Returns:
|
|
1050
|
+
MessageLog: The updated message log.
|
|
1051
|
+
|
|
1052
|
+
Raises:
|
|
1053
|
+
Exception: If the update fails.
|
|
1054
|
+
|
|
1055
|
+
"""
|
|
1056
|
+
try:
|
|
1057
|
+
message_log = unique_sdk.MessageLog.update(
|
|
1058
|
+
user_id=user_id,
|
|
1059
|
+
company_id=company_id,
|
|
1060
|
+
message_log_id=message_log_id,
|
|
1061
|
+
text=text,
|
|
1062
|
+
status=status.value if status else None,
|
|
1063
|
+
order=order,
|
|
1064
|
+
details=details.model_dump() if details else None,
|
|
1065
|
+
uncitedReferences=uncited_references.model_dump()
|
|
1066
|
+
if uncited_references
|
|
1067
|
+
else None,
|
|
1068
|
+
references=map_references_with_original_index(references)
|
|
1069
|
+
if references
|
|
1070
|
+
else [], # type: ignore
|
|
1071
|
+
)
|
|
1072
|
+
return MessageLog(**message_log)
|
|
1073
|
+
except Exception as e:
|
|
1074
|
+
logger.error(f"Failed to update message log: {e}")
|
|
1075
|
+
raise e
|
|
1076
|
+
|
|
1077
|
+
|
|
1078
|
+
async def update_message_log_async(
|
|
1079
|
+
user_id: str,
|
|
1080
|
+
company_id: str,
|
|
1081
|
+
message_log_id: str,
|
|
1082
|
+
order: int,
|
|
1083
|
+
text: str | None = None,
|
|
1084
|
+
status: MessageLogStatus | None = None,
|
|
1085
|
+
details: MessageLogDetails | None = None,
|
|
1086
|
+
uncited_references: MessageLogUncitedReferences | None = None,
|
|
1087
|
+
references: list[ContentReference] | None = None,
|
|
1088
|
+
) -> MessageLog:
|
|
1089
|
+
"""Updates a message log asynchronously.
|
|
1090
|
+
|
|
1091
|
+
Args:
|
|
1092
|
+
user_id (str): The user ID.
|
|
1093
|
+
company_id (str): The company ID.
|
|
1094
|
+
message_log_id (str): The ID of the message log to update.
|
|
1095
|
+
order (int): The order/sequence number (required).
|
|
1096
|
+
text (str | None): The updated log text content.
|
|
1097
|
+
status (MessageLogStatus | None): The updated status.
|
|
1098
|
+
details (MessageLogDetails | None): Updated additional details.
|
|
1099
|
+
uncited_references (MessageLogUncitedReferences | None): Updated uncited references.
|
|
1100
|
+
references (list[ContentReference] | None): Updated list of references.
|
|
1101
|
+
|
|
1102
|
+
Returns:
|
|
1103
|
+
MessageLog: The updated message log.
|
|
1104
|
+
|
|
1105
|
+
Raises:
|
|
1106
|
+
Exception: If the update fails.
|
|
1107
|
+
|
|
1108
|
+
"""
|
|
1109
|
+
try:
|
|
1110
|
+
message_log = await unique_sdk.MessageLog.update_async(
|
|
1111
|
+
user_id=user_id,
|
|
1112
|
+
company_id=company_id,
|
|
1113
|
+
message_log_id=message_log_id,
|
|
1114
|
+
text=text,
|
|
1115
|
+
status=status.value if status else None,
|
|
1116
|
+
order=order,
|
|
1117
|
+
details=details.model_dump() if details else None,
|
|
1118
|
+
uncitedReferences=uncited_references.model_dump()
|
|
1119
|
+
if uncited_references
|
|
1120
|
+
else None,
|
|
1121
|
+
references=map_references_with_original_index(references)
|
|
1122
|
+
if references
|
|
1123
|
+
else [], # type: ignore
|
|
1124
|
+
)
|
|
1125
|
+
return MessageLog(**message_log)
|
|
1126
|
+
except Exception as e:
|
|
1127
|
+
logger.error(f"Failed to update message log: {e}")
|
|
1128
|
+
raise e
|
|
1129
|
+
|
|
1130
|
+
|
|
1131
|
+
def create_message_execution(
|
|
1132
|
+
user_id: str,
|
|
1133
|
+
company_id: str,
|
|
1134
|
+
message_id: str,
|
|
1135
|
+
chat_id: str,
|
|
1136
|
+
type: MessageExecutionType = MessageExecutionType.DEEP_RESEARCH,
|
|
1137
|
+
seconds_remaining: int | None = None,
|
|
1138
|
+
percentage_completed: int | None = None,
|
|
1139
|
+
) -> MessageExecution:
|
|
1140
|
+
"""Creates a message execution synchronously.
|
|
1141
|
+
|
|
1142
|
+
Args:
|
|
1143
|
+
user_id (str): The user ID.
|
|
1144
|
+
company_id (str): The company ID.
|
|
1145
|
+
message_id (str): The ID of the message this execution belongs to.
|
|
1146
|
+
chat_id (str): The chat ID.
|
|
1147
|
+
type (MessageExecutionType): The type of execution. Defaults to DEEP_RESEARCH.
|
|
1148
|
+
seconds_remaining (int | None): Estimated seconds remaining for completion.
|
|
1149
|
+
percentage_completed (int | None): Percentage of completion (0-100).
|
|
1150
|
+
|
|
1151
|
+
Returns:
|
|
1152
|
+
MessageExecution: The created message execution.
|
|
1153
|
+
|
|
1154
|
+
Raises:
|
|
1155
|
+
Exception: If the creation fails.
|
|
1156
|
+
|
|
1157
|
+
"""
|
|
1158
|
+
try:
|
|
1159
|
+
message_execution = unique_sdk.MessageExecution.create(
|
|
1160
|
+
user_id=user_id,
|
|
1161
|
+
company_id=company_id,
|
|
1162
|
+
messageId=message_id,
|
|
1163
|
+
chatId=chat_id,
|
|
1164
|
+
type=type.value,
|
|
1165
|
+
secondsRemaining=seconds_remaining,
|
|
1166
|
+
percentageCompleted=percentage_completed,
|
|
1167
|
+
)
|
|
1168
|
+
return MessageExecution(**message_execution)
|
|
1169
|
+
except Exception as e:
|
|
1170
|
+
logger.error(f"Failed to create message execution: {e}")
|
|
1171
|
+
raise e
|
|
1172
|
+
|
|
1173
|
+
|
|
1174
|
+
async def create_message_execution_async(
|
|
1175
|
+
user_id: str,
|
|
1176
|
+
company_id: str,
|
|
1177
|
+
message_id: str,
|
|
1178
|
+
chat_id: str,
|
|
1179
|
+
type: MessageExecutionType = MessageExecutionType.DEEP_RESEARCH,
|
|
1180
|
+
seconds_remaining: int | None = None,
|
|
1181
|
+
percentage_completed: int | None = None,
|
|
1182
|
+
) -> MessageExecution:
|
|
1183
|
+
"""Creates a message execution asynchronously.
|
|
1184
|
+
|
|
1185
|
+
Args:
|
|
1186
|
+
user_id (str): The user ID.
|
|
1187
|
+
company_id (str): The company ID.
|
|
1188
|
+
message_id (str): The ID of the message this execution belongs to.
|
|
1189
|
+
chat_id (str): The chat ID.
|
|
1190
|
+
type (MessageExecutionType): The type of execution. Defaults to DEEP_RESEARCH.
|
|
1191
|
+
seconds_remaining (int | None): Estimated seconds remaining for completion.
|
|
1192
|
+
percentage_completed (int | None): Percentage of completion (0-100).
|
|
1193
|
+
|
|
1194
|
+
Returns:
|
|
1195
|
+
MessageExecution: The created message execution.
|
|
1196
|
+
|
|
1197
|
+
Raises:
|
|
1198
|
+
Exception: If the creation fails.
|
|
1199
|
+
|
|
1200
|
+
"""
|
|
1201
|
+
try:
|
|
1202
|
+
message_execution = await unique_sdk.MessageExecution.create_async(
|
|
1203
|
+
user_id=user_id,
|
|
1204
|
+
company_id=company_id,
|
|
1205
|
+
messageId=message_id,
|
|
1206
|
+
chatId=chat_id,
|
|
1207
|
+
type=type.value,
|
|
1208
|
+
secondsRemaining=seconds_remaining,
|
|
1209
|
+
percentageCompleted=percentage_completed,
|
|
1210
|
+
)
|
|
1211
|
+
return MessageExecution(**message_execution)
|
|
1212
|
+
except Exception as e:
|
|
1213
|
+
logger.error(f"Failed to create message execution: {e}")
|
|
1214
|
+
raise e
|
|
1215
|
+
|
|
1216
|
+
|
|
1217
|
+
def get_message_execution(
|
|
1218
|
+
user_id: str,
|
|
1219
|
+
company_id: str,
|
|
1220
|
+
message_id: str,
|
|
1221
|
+
) -> MessageExecution:
|
|
1222
|
+
"""Gets a message execution by message ID synchronously.
|
|
1223
|
+
|
|
1224
|
+
Args:
|
|
1225
|
+
user_id (str): The user ID.
|
|
1226
|
+
company_id (str): The company ID.
|
|
1227
|
+
message_id (str): The ID of the message to get execution for.
|
|
1228
|
+
|
|
1229
|
+
Returns:
|
|
1230
|
+
MessageExecution: The message execution.
|
|
1231
|
+
|
|
1232
|
+
Raises:
|
|
1233
|
+
Exception: If the retrieval fails.
|
|
1234
|
+
|
|
1235
|
+
"""
|
|
1236
|
+
try:
|
|
1237
|
+
message_execution = unique_sdk.MessageExecution.get(
|
|
1238
|
+
user_id=user_id,
|
|
1239
|
+
company_id=company_id,
|
|
1240
|
+
messageId=message_id,
|
|
1241
|
+
)
|
|
1242
|
+
return MessageExecution(**message_execution)
|
|
1243
|
+
except Exception as e:
|
|
1244
|
+
logger.error(f"Failed to get message execution: {e}")
|
|
1245
|
+
raise e
|
|
1246
|
+
|
|
1247
|
+
|
|
1248
|
+
async def get_message_execution_async(
|
|
1249
|
+
user_id: str,
|
|
1250
|
+
company_id: str,
|
|
1251
|
+
message_id: str,
|
|
1252
|
+
) -> MessageExecution:
|
|
1253
|
+
"""Gets a message execution by message ID asynchronously.
|
|
1254
|
+
|
|
1255
|
+
Args:
|
|
1256
|
+
user_id (str): The user ID.
|
|
1257
|
+
company_id (str): The company ID.
|
|
1258
|
+
message_id (str): The ID of the message to get execution for.
|
|
1259
|
+
|
|
1260
|
+
Returns:
|
|
1261
|
+
MessageExecution: The message execution.
|
|
1262
|
+
|
|
1263
|
+
Raises:
|
|
1264
|
+
Exception: If the retrieval fails.
|
|
1265
|
+
|
|
1266
|
+
"""
|
|
1267
|
+
try:
|
|
1268
|
+
message_execution = await unique_sdk.MessageExecution.get_async(
|
|
1269
|
+
user_id=user_id,
|
|
1270
|
+
company_id=company_id,
|
|
1271
|
+
messageId=message_id,
|
|
1272
|
+
)
|
|
1273
|
+
return MessageExecution(**message_execution)
|
|
1274
|
+
except Exception as e:
|
|
1275
|
+
logger.error(f"Failed to get message execution: {e}")
|
|
1276
|
+
raise e
|
|
1277
|
+
|
|
1278
|
+
|
|
1279
|
+
def update_message_execution(
|
|
1280
|
+
user_id: str,
|
|
1281
|
+
company_id: str,
|
|
1282
|
+
message_id: str,
|
|
1283
|
+
status: MessageExecutionUpdateStatus,
|
|
1284
|
+
seconds_remaining: int | None = None,
|
|
1285
|
+
percentage_completed: int | None = None,
|
|
1286
|
+
) -> MessageExecution:
|
|
1287
|
+
"""Updates a message execution synchronously.
|
|
1288
|
+
|
|
1289
|
+
Args:
|
|
1290
|
+
user_id (str): The user ID.
|
|
1291
|
+
company_id (str): The company ID.
|
|
1292
|
+
message_id (str): The ID of the message to update execution for.
|
|
1293
|
+
status (MessageExecutionUpdateStatus): The updated status (COMPLETED or FAILED).
|
|
1294
|
+
seconds_remaining (int | None): Updated estimated seconds remaining.
|
|
1295
|
+
percentage_completed (int | None): Updated percentage of completion (0-100).
|
|
1296
|
+
|
|
1297
|
+
Returns:
|
|
1298
|
+
MessageExecution: The updated message execution.
|
|
1299
|
+
|
|
1300
|
+
Raises:
|
|
1301
|
+
Exception: If the update fails.
|
|
1302
|
+
|
|
1303
|
+
"""
|
|
1304
|
+
try:
|
|
1305
|
+
message_execution = unique_sdk.MessageExecution.update(
|
|
1306
|
+
user_id=user_id,
|
|
1307
|
+
company_id=company_id,
|
|
1308
|
+
messageId=message_id,
|
|
1309
|
+
status=status.value,
|
|
1310
|
+
secondsRemaining=seconds_remaining,
|
|
1311
|
+
percentageCompleted=percentage_completed,
|
|
1312
|
+
)
|
|
1313
|
+
return MessageExecution(**message_execution)
|
|
1314
|
+
except Exception as e:
|
|
1315
|
+
logger.error(f"Failed to update message execution: {e}")
|
|
1316
|
+
raise e
|
|
1317
|
+
|
|
1318
|
+
|
|
1319
|
+
async def update_message_execution_async(
|
|
1320
|
+
user_id: str,
|
|
1321
|
+
company_id: str,
|
|
1322
|
+
message_id: str,
|
|
1323
|
+
status: MessageExecutionUpdateStatus,
|
|
1324
|
+
seconds_remaining: int | None = None,
|
|
1325
|
+
percentage_completed: int | None = None,
|
|
1326
|
+
) -> MessageExecution:
|
|
1327
|
+
"""Updates a message execution asynchronously.
|
|
1328
|
+
|
|
1329
|
+
Args:
|
|
1330
|
+
user_id (str): The user ID.
|
|
1331
|
+
company_id (str): The company ID.
|
|
1332
|
+
message_id (str): The ID of the message to update execution for.
|
|
1333
|
+
status (MessageExecutionUpdateStatus): The updated status (COMPLETED or FAILED).
|
|
1334
|
+
seconds_remaining (int | None): Updated estimated seconds remaining.
|
|
1335
|
+
percentage_completed (int | None): Updated percentage of completion (0-100).
|
|
1336
|
+
|
|
1337
|
+
Returns:
|
|
1338
|
+
MessageExecution: The updated message execution.
|
|
1339
|
+
|
|
1340
|
+
Raises:
|
|
1341
|
+
Exception: If the update fails.
|
|
1342
|
+
|
|
1343
|
+
"""
|
|
1344
|
+
try:
|
|
1345
|
+
message_execution = await unique_sdk.MessageExecution.update_async(
|
|
1346
|
+
user_id=user_id,
|
|
1347
|
+
company_id=company_id,
|
|
1348
|
+
messageId=message_id,
|
|
1349
|
+
status=status.value,
|
|
1350
|
+
secondsRemaining=seconds_remaining,
|
|
1351
|
+
percentageCompleted=percentage_completed,
|
|
1352
|
+
)
|
|
1353
|
+
return MessageExecution(**message_execution)
|
|
1354
|
+
except Exception as e:
|
|
1355
|
+
logger.error(f"Failed to update message execution: {e}")
|
|
1356
|
+
raise e
|
unique_toolkit/chat/schemas.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from datetime import datetime
|
|
2
2
|
from enum import StrEnum
|
|
3
|
+
from typing import Literal
|
|
3
4
|
|
|
4
5
|
from humps import camelize
|
|
5
6
|
from openai.types.chat import (
|
|
@@ -161,3 +162,72 @@ class ChatMessageAssessment(BaseModel):
|
|
|
161
162
|
is_visible: bool
|
|
162
163
|
created_at: datetime | None = None
|
|
163
164
|
updated_at: datetime | None = None
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
class MessageLogStatus(StrEnum):
|
|
168
|
+
RUNNING = "RUNNING"
|
|
169
|
+
COMPLETED = "COMPLETED"
|
|
170
|
+
FAILED = "FAILED"
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
class MessageExecutionStatus(StrEnum):
|
|
174
|
+
PENDING = "PENDING"
|
|
175
|
+
RUNNING = "RUNNING"
|
|
176
|
+
COMPLETED = "COMPLETED"
|
|
177
|
+
FAILED = "FAILED"
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
class MessageExecutionType(StrEnum):
|
|
181
|
+
DEEP_RESEARCH = "DEEP_RESEARCH"
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
class MessageExecutionUpdateStatus(StrEnum):
|
|
185
|
+
COMPLETED = "COMPLETED"
|
|
186
|
+
FAILED = "FAILED"
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
class MessageLogUncitedReferences(BaseModel):
|
|
190
|
+
model_config = model_config
|
|
191
|
+
data: list[ContentReference]
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
class MessageLogEvent(BaseModel):
|
|
195
|
+
model_config = model_config
|
|
196
|
+
type: Literal["WebSearch", "InternalSearch"]
|
|
197
|
+
text: str
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
class MessageLogDetails(BaseModel):
|
|
201
|
+
model_config = model_config
|
|
202
|
+
data: list[MessageLogEvent] | None = None
|
|
203
|
+
status: str | None = Field(
|
|
204
|
+
default=None, description="Overarching status of the current message log"
|
|
205
|
+
)
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
class MessageLog(BaseModel):
|
|
209
|
+
model_config = model_config
|
|
210
|
+
|
|
211
|
+
message_log_id: str | None = None
|
|
212
|
+
message_id: str | None = None
|
|
213
|
+
status: MessageLogStatus
|
|
214
|
+
text: str | None = None
|
|
215
|
+
details: MessageLogDetails | None = None
|
|
216
|
+
uncited_references: MessageLogUncitedReferences | None = None
|
|
217
|
+
order: int
|
|
218
|
+
references: list[ContentReference] | None = None
|
|
219
|
+
created_at: datetime | None = None
|
|
220
|
+
updated_at: datetime | None = None
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
class MessageExecution(BaseModel):
|
|
224
|
+
model_config = model_config
|
|
225
|
+
|
|
226
|
+
message_execution_id: str | None = None
|
|
227
|
+
message_id: str | None = None
|
|
228
|
+
status: MessageExecutionStatus
|
|
229
|
+
type: MessageExecutionType = MessageExecutionType.DEEP_RESEARCH
|
|
230
|
+
seconds_remaining: int | None = None
|
|
231
|
+
percentage_completed: int | None = None
|
|
232
|
+
created_at: datetime | None = None
|
|
233
|
+
updated_at: datetime | None = None
|