Merge branch 'sophie' into hugo-shipping-notice

This commit is contained in:
hugo committed 2026-08-17 20:45:01 +08:00
commit 7fafe316e9
7 files changed
+192 -3

No files matched your search

+34
View File
@@ -301,6 +301,34 @@ def _record_run_bind(run: ScheduleRun, data: dict) -> None:
attach_run_to_turn(turn_id, int(run.id))
def _bind_queried_run_to_turn(run: ScheduleRun, data: dict) -> None:
"""
将已有检核批次关联到本轮查询对话,不改写批次原始执行上下文。
查询最近/指定批次时触发;仅更新 chat_tool_runs 与内存 turn registry,
使 message_end 可以把既有 ScheduleRun.id 写入当前 ChatLog.run_id。
"""
from app.services.file_check_tools.chat_tool_run_binding import bind_schedule_run
from app.services.file_check_tools.chat_turn_registry import attach_run_to_turn
turn_id = str(data.get("hxops_turn_id") or "").strip()
session_id = str(data.get("conversation_id") or "").strip() or None
user_message = str(data.get("user_message") or "").strip() or None
if not turn_id:
return
bound = bind_schedule_run(
schedule_run_id=int(run.id),
turn_id=turn_id,
session_id=session_id,
user_message=user_message,
schedule_task_id=int(run.schedule_task_id),
bind_source="tool_query_latest",
)
if bound:
attach_run_to_turn(turn_id, int(run.id))
def _build_no_data_response(task: ScheduleTask) -> dict:
"""无待检资料时直接返回提示,不创建批次也不绑定 run_id。"""
return {
@@ -534,10 +562,16 @@ def download_file_check_run_excel(run_id: int):
@file_check_bp.route("/tools/tasks/<int:task_id>/latest-run", methods=["GET"])
def get_latest_file_check_run(task_id: int):
"""查询任务最近批次;可绑定本轮对话以展示该批次进度。"""
task = _resolve_check_task(task_id=task_id)
run = ScheduleRun.query.filter_by(schedule_task_id=task.id).order_by(ScheduleRun.id.desc()).first()
if not run:
raise NotFoundError("run_not_found")
_bind_queried_run_to_turn(run, {
"hxops_turn_id": request.args.get("hxops_turn_id"),
"conversation_id": request.args.get("conversation_id"),
"user_message": request.args.get("user_message"),
})
return jsonify({"ok": True, "run": _serialize_tool_run(run)})