def handle_message(state: State, message: MesopMessage) -> None:
conversation = state.conversation
messages = conversation.messages
level = message.conversation.level
conversation_id = message.conversation.id
io_message = message.io_message
message_dict = io_message.model_dump()
message_json = json.dumps(message_dict)
conversation_message = ConversationMessage(
level=level,
conversation_id=conversation_id,
io_message_json=message_json,
feedback=[],
)
messages.append(conversation_message)
conversation.messages = list(messages)
if isinstance(io_message, AskingMessage):
conversation.waiting_for_feedback = True
conversation.completed = False
if isinstance(io_message, WorkflowCompleted):
conversation.completed = True
conversation.waiting_for_feedback = False
if not conversation.is_from_the_past:
uuid: str = uuid4().hex
becomme_past = Conversation(
id=uuid,
title=find_suitable_title(conversation),
messages=conversation.messages,
completed=True,
is_from_the_past=True,
waiting_for_feedback=False,
)
state.past_conversations.insert(0, becomme_past)