fix(chat): avoid idle runtime notice injection
This commit is contained in:
parent
1e83bc9f68
commit
b03d158ab6
@ -54,7 +54,7 @@ def _dispatch_runtime_mode_notice(terminal: WebTerminal, username: str, text: st
|
|||||||
if not notice:
|
if not notice:
|
||||||
return
|
return
|
||||||
|
|
||||||
# 若有运行任务,优先入队到该任务(下一轮工具后注入),确保会进入后续 API 请求上下文。
|
# 仅在“有运行中的任务”时注入 [系统通知|notify],空闲期切换不写入 user 消息。
|
||||||
try:
|
try:
|
||||||
from .tasks import task_manager
|
from .tasks import task_manager
|
||||||
|
|
||||||
@ -64,39 +64,21 @@ def _dispatch_runtime_mode_notice(terminal: WebTerminal, username: str, text: st
|
|||||||
]
|
]
|
||||||
if current_conv:
|
if current_conv:
|
||||||
running_tasks.sort(key=lambda r: 0 if r.conversation_id == current_conv else 1)
|
running_tasks.sort(key=lambda r: 0 if r.conversation_id == current_conv else 1)
|
||||||
if running_tasks:
|
if not running_tasks:
|
||||||
target = running_tasks[0]
|
debug_log(f"[RuntimeMode] idle switch ignored notify injection: {notice}")
|
||||||
result = task_manager.enqueue_runtime_guidance(
|
return
|
||||||
username=username,
|
|
||||||
task_id=target.task_id,
|
|
||||||
message=notice,
|
|
||||||
source="notify",
|
|
||||||
)
|
|
||||||
if result.get("success"):
|
|
||||||
return
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
# 无运行任务时,直接写入当前会话并广播前端显示(来源固定为 notify)。
|
target = running_tasks[0]
|
||||||
from .chat_flow_task_support import inject_runtime_user_message
|
result = task_manager.enqueue_runtime_guidance(
|
||||||
|
username=username,
|
||||||
conversation_id = getattr(getattr(terminal, "context_manager", None), "current_conversation_id", None)
|
task_id=target.task_id,
|
||||||
|
message=notice,
|
||||||
def _emit(event: str, payload: Dict[str, Any]) -> None:
|
source="notify",
|
||||||
try:
|
)
|
||||||
socketio.emit(event, payload, room=f"user_{username}")
|
if not result.get("success"):
|
||||||
except Exception:
|
debug_log(f"[RuntimeMode] enqueue runtime guidance failed: {result}")
|
||||||
pass
|
except Exception as exc:
|
||||||
|
debug_log(f"[RuntimeMode] dispatch notice failed: {exc}")
|
||||||
inject_runtime_user_message(
|
|
||||||
web_terminal=terminal,
|
|
||||||
messages=None,
|
|
||||||
text=notice,
|
|
||||||
source="notify",
|
|
||||||
sender=_emit,
|
|
||||||
conversation_id=conversation_id,
|
|
||||||
inline=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
@chat_bp.route('/api/thinking-mode', methods=['POST'])
|
@chat_bp.route('/api/thinking-mode', methods=['POST'])
|
||||||
@api_login_required
|
@api_login_required
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user