feat: connect chat and runs, cancellable chat messages, unified frontend runs module

This commit is contained in:
Shivering Ocelot committed 2026-05-31 12:48:06 -05:00
1 parent d7e92f38f3
commit bc71fa4d59
7 files changed
+244 -119

No files matched your search

+13 -17
View File
@@ -75,14 +75,20 @@ class Agent:
"thread_id": message.thread_id,
},
)
await self.run(run)
await self.app.send_chat_message(
chat_id=message.chat_id,
new_message = await self.app.send_chat_message(
sender=self.id,
content=run.stream,
chat_id=message.chat_id,
thread_id=message.thread_id,
content=run.stream,
)
return run.stream;
run.emit_event('chat-message', {
'messageId': new_message['id'],
'chatId': message.chat_id,
'threadId': message.thread_id,
})
return run.stream
def _role_for_message(self, message):
sender = message.sender
@@ -140,18 +146,17 @@ class AgentRun:
# Cancellation tracking
self.task = None # For asyncio tasks
self.thread = None # For threads
self.cancelled = False
app.tmp.runs[self.id] = self
# Emit run start event
app.emit_event("run-started", {
"runId": self.id,
self.emit_event('created', {
"agentId": self.agent_id,
"userId": self.user_id,
"startTime": self.start_time,
"input": self.input
"input": self.input,
"streamId": self.stream.id,
})
return self
@@ -259,12 +264,3 @@ class AgentRun:
self.output = self.stream.content
self.stream.close()
self.emit_event("done", {"output": self.output, "agent_id": self.agent_id})
# Broadcast run completion event
self.app.emit_event("run-completed", {
"runId": self.id,
"agentId": self.agent_id,
"endTime": self.end_time,
"output": self.output
})
+1 -7
View File
@@ -141,7 +141,7 @@ async def start_server(app):
# Listen for events and broadcast them
async def on_event(name, data):
await send({"action": "event", "name": name, "data": data})
await send({"action": name, "data": data})
app.on_event(on_event)
while True:
@@ -153,12 +153,6 @@ async def start_server(app):
body = req.get('body', {})
nonce = req.get('nonce', None)
def get_agent_id ():
raise Exception("Cannot get agent id")
def get_chat_id ():
raise Exception("Cannot get chat id")
if action == "ping":
await send({'message': "pong"})