Introduce message kinds, and handle them appropriately in user and agent chat

This commit is contained in:
Shivering Ocelot committed 2025-07-08 18:01:46 -05:00
1 parent cba41f1e7e
commit 396b06b05c
4 files changed
+89 -18

No files matched your search

+3 -2
View File
@@ -86,14 +86,15 @@ class ChatMixin:
print(f"Added agent #{agent_id} to chat #{chat_id}")
# If an integer is passed in sender, it is interpreted as an agent id
def send_chat_message(self, chat_id, content, sender='user', thread_id=None):
def send_chat_message(self, chat_id, content, sender='user', thread_id=None, kind=None, subkind=None, format=None):
with self.sql_session() as session:
message = db.Message()
message.chat_id = chat_id
message.time = int(datetime.now().timestamp())
message.last_edit = message.time
message.sender = sender
message.kind = 'text' # default kind
message.kind = kind or 'message'
message.subkind = subkind
message.content = content
message.thread_id = thread_id
+16 -3
View File
@@ -7,11 +7,13 @@ import database as db
MESSAGE_PAGE_SIZE = 256
class Message:
def __init__(self, id, content, sender, time=None):
def __init__(self, id, content, sender, time=None, kind='message', subkind=None):
self.id = id
self.content = content
self.sender = sender
self.time = time
self.kind = kind
self.subkind = subkind
def from_db_record(record):
return Message(record.id, record.content, record.sender, record.time)
@@ -27,6 +29,8 @@ class Thread:
self.description = description
self.messages = []
self.notes = []
self.memories = []
class ChatView:
def __init__(self, app, chat_id):
@@ -44,6 +48,9 @@ class ChatView:
self.thread_map = {}
# Long term summary of this chat
self.summary = None
# Separate list for note messages from any thread
# Is it better to exclude them or include them from threads? atm they're included
self.notes = []
# Id of the thread currently in focus, by default the last thread appearing in the conversation
self.current_thread_id = None
@@ -92,8 +99,14 @@ class ChatView:
self.thread_map[thread.id] = thread
self.threads.insert(0, thread)
# This is the oldest message so far, add it to the start of the chat
message = Message(record.id, record.content, record.sender, record.time)
thread.messages.insert(0, message)
message = Message(record.id, record.content, record.sender, record.time, record.kind, record.subkind)
if message.kind == 'note':
thread.notes.insert(0, message)
elif message.kind == 'memory':
thread.memories.insert(0, message)
else:
thread.messages.insert(0, message)
def get_thread(self, thread_id):
if thread_id == None:
+4 -1
View File
@@ -185,8 +185,11 @@ def start_server(app):
elif action == "send-chat-message":
message = app.send_chat_message(
chat_id=body['chatId'],
content=body['content'],
thread_id=body.get('threadId'),
content=body['content'],
kind=body.get('kind'),
subkind=body.get('subkind'),
format=body.get('format'),
)
await send({'message': "message sent", 'messageId': message['id'], 'nonce': nonce})