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
@@ -22,7 +22,7 @@ from app.core.logger import get_logger
|
||||
from app.channels.constants import is_widget_channel
|
||||
from app.tools.knowledge_search_byagent import KnowledgeSearchByAgent
|
||||
from app.tools.mcp_manager import ChatAgentMCPMixin
|
||||
from app.database import get_db, SessionLocal, engine
|
||||
from app.database import SessionLocal, engine
|
||||
from app.agents.choice_prompt import choice_instructions
|
||||
from app.channels.interactive_limits import InteractiveLimits
|
||||
from app.agents.encrypted_storage import EncryptedPostgresAgentStorage
|
||||
@@ -45,7 +45,7 @@ from app.agents.guardrail_policy import (
|
||||
guardrail_scope_prompt,
|
||||
wrap_operator_block,
|
||||
)
|
||||
from app.utils.guardrail_runtime import BLOCK_REPLY, Surface, check_inbound, check_output
|
||||
from app.utils.guardrail_runtime import Surface, check_inbound, check_output
|
||||
from app.services.notifications import ChatNotificationEvent, notify_chat_event
|
||||
from app.models.user import User, user_groups
|
||||
from datetime import datetime
|
||||
@@ -654,14 +654,8 @@ Keep your responses concise and focused. Provide clear, actionable information i
|
||||
# Only prompt while the lead is still pending — once captured, don't nag.
|
||||
lead_pending = self.lead_capture_enabled and not self.lead_already_captured
|
||||
if lead_pending:
|
||||
# Standard contact fields map to explicit scalar response fields
|
||||
# (lead_email/lead_name/lead_company/lead_phone) — these populate reliably
|
||||
# under strict structured outputs, unlike a free-form dict. Split the
|
||||
# configured fields into required vs optional and describe how to report each.
|
||||
STANDARD_FIELD_SLOT = {
|
||||
'email': 'lead_email', 'name': 'lead_name',
|
||||
'company': 'lead_company', 'phone': 'lead_phone',
|
||||
}
|
||||
# Split the configured fields into required vs optional and describe
|
||||
# how to report each using the structured scalar response fields.
|
||||
required_labels, optional_labels = [], []
|
||||
for f in self.lead_capture_fields:
|
||||
if not f.get('enabled', True):
|
||||
@@ -1357,6 +1351,10 @@ Keep your responses concise and focused. Provide clear, actionable information i
|
||||
button a channel customer tapped). The stored reply's row id is left
|
||||
on `last_bot_message_id` so a caller can annotate that exact row.
|
||||
"""
|
||||
# Import after app/model initialization: importing the socket server
|
||||
# while model modules are still registering would initialize CORS too early.
|
||||
from app.services.agent_rooms import notify_conversation_changed
|
||||
|
||||
self.last_bot_message_id = None
|
||||
try:
|
||||
# Update session and IDs if provided
|
||||
@@ -1395,6 +1393,9 @@ Keep your responses concise and focused. Provide clear, actionable information i
|
||||
"customer_id": customer_id,
|
||||
"attributes": {**(user_attributes or {}), **guardrail_verdict.as_attributes()}
|
||||
})
|
||||
# The visitor's turn is already committed; do not wait for
|
||||
# the model before making it visible to the inbox.
|
||||
await notify_conversation_changed(org_id, session_id)
|
||||
|
||||
if guardrail_verdict.block:
|
||||
# Blocked pre-inference: reply with the canned line, store
|
||||
@@ -1605,6 +1606,9 @@ Keep your responses concise and focused. Provide clear, actionable information i
|
||||
logger.error(f"Failed to store error message: {str(store_error)}")
|
||||
|
||||
return error_response
|
||||
finally:
|
||||
if self.last_bot_message_id is not None:
|
||||
await notify_conversation_changed(org_id, session_id)
|
||||
|
||||
@staticmethod
|
||||
async def test_api_key(api_key: str, model_type: str, model_name: str, base_url: str = None) -> bool:
|
||||
|
||||
Reference in new issue
Block a user