feat: connect chat and runs, cancellable chat messages, unified frontend runs module
This commit is contained in:
1 parent
d7e92f38f3
commit
bc71fa4d59
7 files changed
+244
-119
No files matched your search
+13
-17
@@ -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
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user