fix: improve maintenance and synchronize live conversations
This commit is contained in:
1 parent
bb541bd212
commit
ef86a5d3af
297 files changed
+2983
-1274
No files matched your search
@@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
from app.core.logger import get_logger
|
||||
from app.agents.chat_agent import ChatAgent, ChatResponse
|
||||
from app.repositories.chat import ChatRepository
|
||||
@@ -64,6 +63,8 @@ class WorkflowChatService:
|
||||
ChatResponse: The response from workflow execution
|
||||
"""
|
||||
|
||||
from app.services.agent_rooms import notify_conversation_changed
|
||||
|
||||
# Store user message in chat history
|
||||
self.chat_repo.create_message({
|
||||
"message": message,
|
||||
@@ -73,6 +74,7 @@ class WorkflowChatService:
|
||||
"agent_id": session['agent_id'],
|
||||
"customer_id": customer_id,
|
||||
})
|
||||
await notify_conversation_changed(org_id, session_id)
|
||||
|
||||
# Execute workflow
|
||||
workflow_result = await self.workflow_service.execute_workflow(
|
||||
@@ -92,14 +94,16 @@ class WorkflowChatService:
|
||||
)
|
||||
|
||||
if workflow_result.success:
|
||||
return await self._handle_successful_workflow(
|
||||
response = await self._handle_successful_workflow(
|
||||
workflow_result, active_session, session_id, org_id,
|
||||
customer_id, session, sio, namespace
|
||||
)
|
||||
else:
|
||||
return await self._handle_failed_workflow(
|
||||
response = await self._handle_failed_workflow(
|
||||
workflow_result, session_id, org_id, session, customer_id
|
||||
)
|
||||
await notify_conversation_changed(org_id, session_id)
|
||||
return response
|
||||
|
||||
async def _handle_successful_workflow(
|
||||
self,
|
||||
@@ -174,6 +178,7 @@ class WorkflowChatService:
|
||||
namespace: str
|
||||
):
|
||||
"""Handle intermediate messages from MESSAGE nodes"""
|
||||
from app.services.agent_rooms import notify_conversation_changed
|
||||
|
||||
logger.info(f"Found {len(intermediate_messages)} intermediate messages from MESSAGE nodes")
|
||||
|
||||
@@ -195,6 +200,7 @@ class WorkflowChatService:
|
||||
"message_node": True
|
||||
}
|
||||
})
|
||||
await notify_conversation_changed(org_id, session_id)
|
||||
|
||||
# Emit intermediate message to client immediately
|
||||
await sio.emit('chat_response', {
|
||||
@@ -390,4 +396,4 @@ class WorkflowChatService:
|
||||
}
|
||||
})
|
||||
|
||||
return response
|
||||
return response
|
||||
Reference in new issue
Block a user