feat(file-check): 持久化 chat_tool_runs 并统一 agent_runtime_context 注入

新增跨 worker 进度绑定表与显式 hxops_turn_id 链路;Dify Start 仅注入
agent_runtime_context,task_id/turn_id 写入 refs 供画布解析后回传 Tool。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
hugoandCursor committed 2026-07-09 18:39:05 +08:00
1 parent c778f40fbc
commit f4e74f7b07
23 files changed
+1580 -196

No files matched your search

+22 -5
View File
@@ -268,11 +268,31 @@ def _prepare_bind_payload(data: dict | None) -> dict:
def _record_run_bind(run: ScheduleRun, data: dict) -> None:
from app.services.file_check_tools.chat_log_run_binding import merge_chat_log_bind_context
from app.services.file_check_tools.chat_tool_run_binding import (
_has_ambiguous_pending_turns,
bind_schedule_run,
)
from app.services.file_check_tools.chat_turn_registry import attach_run_to_turn
merge_chat_log_bind_context(run, data)
turn_id = str(data.get("hxops_turn_id") or "").strip()
if turn_id:
session_id = str(data.get("hxops_session_id") or "").strip() or None
user_message = str(data.get("user_message") or "").strip() or None
bound = bind_schedule_run(
schedule_run_id=int(run.id),
turn_id=turn_id or None,
session_id=session_id,
user_message=user_message,
schedule_task_id=int(run.schedule_task_id) if run.schedule_task_id else None,
bind_source='tool_start',
)
ambiguous = _has_ambiguous_pending_turns(
session_id=session_id,
user_message=user_message,
schedule_task_id=int(run.schedule_task_id) if run.schedule_task_id else None,
)
if bound or (not ambiguous and (turn_id or session_id)):
merge_chat_log_bind_context(run, data)
if bound and turn_id:
attach_run_to_turn(turn_id, int(run.id))
@@ -371,9 +391,6 @@ def run_file_check():
api_request_json={
"trigger_source": data.get("trigger_source") or "dify_chatflow",
"conversation_id": data.get("conversation_id"),
"hxops_session_id": data.get("hxops_session_id"),
"hxops_turn_id": data.get("hxops_turn_id"),
"user_message": data.get("user_message"),
},
)
db.session.add(run)
+7 -3
View File
@@ -14,7 +14,7 @@ from flask import Blueprint, jsonify, request, send_file
from app.core.auth.jwt import get_current_user
from app.core.errors import NotFoundError, UnauthorizedError, ValidationError
from app.models import ScheduleRun, ScheduleTask
from app.services.file_check_tools.chat_log_run_resolver import find_run_for_chat_log
from app.services.file_check_tools.chat_log_run_resolver import find_run_for_chat_log_with_source
from app.services.schedule.query_service import get_run, serialize_run
workspace_file_check_bp = Blueprint("workspace_file_check", __name__)
@@ -78,8 +78,12 @@ def workspace_file_check_run_for_log():
raise ValidationError("task_id_required")
if not chat_log_id or chat_log_id <= 0:
raise ValidationError("chat_log_id_required")
run = find_run_for_chat_log(task_id=task_id, chat_log_id=chat_log_id)
return jsonify({'ok': True, 'run': _serialize_progress_run(run) if run else None, 'match_source': 'chat_log' if run else None})
match = find_run_for_chat_log_with_source(task_id=task_id, chat_log_id=chat_log_id)
return jsonify({
'ok': True,
'run': _serialize_progress_run(match.run) if match.run else None,
'match_source': match.match_source,
})
@workspace_file_check_bp.route('/file-check/runs/for-session', methods=['GET'])
def workspace_file_check_run_for_session():