Advanced chat management via UI

This commit is contained in:
Shivering Ocelot committed 2025-05-22 07:48:36 -05:00
1 parent fbee31841d
commit 5351144edf
9 files changed
+396 -59

No files matched your search

+17 -6
View File
@@ -63,7 +63,7 @@ class App:
print(f"Created agent #{agent.id}: {agent.name}")
return agent.id
def create_chat(self, user_id, name, description, picture):
def create_chat(self, user_id, name, description, picture, members=[]):
with self.sql_session() as session:
chat = db.Chat()
chat.user_id = user_id
@@ -74,7 +74,13 @@ class App:
session.add(chat)
session.commit()
print(f"Created chat #{chat.id}: {chat.name}")
return chat.id
chat_id = chat.id
for agent_id in members:
self.add_agent_to_chat(chat_id, agent_id)
return chat_id
def get_chats(self, user_id):
with self.sql_session() as session:
@@ -96,6 +102,13 @@ class App:
"picture": agent.picture
} for agent in agents]
def delete_chat(self, chat_id):
with self.sql_session() as session:
session.execute(db.Membership.__table__.delete().where(db.Membership.chat_id == chat_id))
session.execute(db.Chat.__table__.delete().where(db.Chat.id == chat_id))
session.commit()
print(f"Deleted chat #{chat_id} and its memberships.")
def get_chat_messages(self, chat_id, earliest_index=0):
with self.sql_session() as session:
messages = session.execute(
@@ -237,12 +250,10 @@ class App:
user_id=user_id,
name="Initial Chat",
description=None,
picture=None
picture=None,
members=[agent_id],
)
# Add the agent to the chat
self.add_agent_to_chat(chat_id, agent_id)
if __name__ == "__main__":
if len(sys.argv) > 1:
data_directory = sys.argv[1]
+8 -1
View File
@@ -91,7 +91,8 @@ def start_server(app):
user_id=user_id,
name=body['name'],
description=body.get('description'),
picture=body.get('picture')
picture=body.get('picture'),
members=body.get('members', []),
)
await send({'message': "chat created", 'chatId': chat_id, 'nonce': nonce})
@@ -99,6 +100,12 @@ def start_server(app):
chats_data = app.get_chats(user_id)
await send({'message': "chats retrieved", 'chats': chats_data, 'nonce': nonce})
elif action == "delete-chat":
chat_id = app.delete_chat(
chat_id=body['chatId']
)
await send({'message': "chat deleted", 'chatId': chat_id, 'nonce': nonce})
elif action == "get-chat-messages":
messages_data = app.get_chat_messages(
body['chatId'],