统一:DSH 智能分析、Top100 与图表静默恢复

接入 DSH 专用运行时和对话界面,保留模型原始回答,支持会话分页、连续追问与显式报告。
补齐组合筛选、各维度 Top100、分组查询到排名图的转换,图表故障静默省略并基于保存数据自动恢复。
优化报告风格、图表顺序和表格换行,更新接入说明及构建输入。

验证:独立目录前后端构建通过;118 项 Java、102 项前端、102 项图表、14 项 DSH 应用和 13 项组合筛选检查通过。
仅提交相关源码、锁定依赖与测试;不包含凭据、会话、业务数据或本地产物。
This commit is contained in:
2026-11-12 11:57:41 +08:00
parent cc8832c8e5
commit f1a2fbd494
166 changed files with 26281 additions and 2248 deletions
+36 -9
View File
@@ -418,10 +418,10 @@ def public_tool_call(tool: str, raw_input: Any) -> dict[str, Any]:
if tool == "mcp_call" and value.get("tool") == "quality_data":
args = value.get("arguments") if isinstance(value.get("arguments"), dict) else {}
labels = {"catalog": "确认可用数据", "query": "查询质量指标", "compare": "比较期间变化",
"top": "查询重点对象排名", "changes": "追查变化较大对象", "defects": "分析具体缺陷",
"top": "查询重点对象排名", "rank": "查询重量排名", "changes": "追查变化较大对象", "defects": "分析具体缺陷",
"details": "核查来源明细", "investigate": "核对全量明细与原表"}
allowed = {"mode", "scope", "period", "comparisonPeriod", "filters", "view", "stage", "dimension",
"defect", "category", "limit", "sort", "action", "offset", "recordFilter", "sourceRevisionId"}
"defect", "category", "metric", "limit", "sort", "action", "offset", "recordFilter", "sourceRevisionId"}
nested = {"year", "month", "quarter", "monthStart", "monthEnd", "department", "group", "product", "projectGroup", "includeUnassigned"}
public_input = {}
for key, item in args.items():
@@ -482,7 +482,7 @@ def public_tool_failure(output: Any) -> str:
except ValueError:return "工具调用未成功,未提供可展示的错误原因"
if isinstance(output,dict):
error=output.get("error")
if isinstance(error,dict) and error.get("code")=="invalid_or_unavailable" and isinstance(error.get("message"),str):
if isinstance(error,dict) and error.get("code") in ('invalid_or_unavailable','invalid_arguments','forbidden','unavailable') and isinstance(error.get("message"),str):
return "查询未成功:"+public_progress_text(error["message"])[:450]
if isinstance(output.get("structuredContent"),dict):return public_tool_failure(output["structuredContent"])
for part in output.get("content",[]) if isinstance(output.get("content"),list) else []:
@@ -496,6 +496,7 @@ def public_tool_result(output: Any) -> str:
try: output = json.loads(output)
except ValueError: return "工具已返回;未提供可展示的结构化摘要"
if not isinstance(output, dict): return "工具已返回结果"
if output.get('status') == 'no_data': return '暂无数据:当前期间和范围没有已发布来源数据,未填零。'
content = output.get("content")
if isinstance(content, list):
for part in content:
@@ -2258,7 +2259,10 @@ def plan_agent_task(**kwargs):
if diagnostic_path is not None:
_atomic_json(diagnostic_path, {'error': str(error)[:600]})
record_turn('failed', error.details())
raise RuntimeErrorSafe('分析计划自动修复未通过,尚未查询数据;已有问题和条件已保留,可重试本轮。') from None
message = ('任务理解未完成,尚未查询数据;已有问题和条件已保留,可重试本轮。'
if kwargs.get('checks_enabled') is False else
'分析计划自动修复未通过,尚未查询数据;已有问题和条件已保留,可重试本轮。')
raise RuntimeErrorSafe(message) from None
except Exception:
if diagnostic_path is not None:
record_turn('failed')
@@ -2474,19 +2478,27 @@ def complete_agent_evidence(*, task, request, actor_root, access_path, manager,
return
def run_turn(payload: dict[str, Any], *, stdout: Any = sys.stdout, stdin: Any = sys.stdin) -> dict[str, Any]:
def run_turn(payload: dict[str, Any], *, stdout: Any = sys.stdout, stdin: Any = sys.stdin,
runtime_engine: str = 'NAO') -> dict[str, Any]:
if runtime_engine not in ('NAO', 'DSH'):
raise ValueError('分析引擎无效。')
with turn_scope():
return _run_turn(payload, stdout=stdout, stdin=stdin)
return _run_turn(payload, stdout=stdout, stdin=stdin, runtime_engine=runtime_engine)
def _run_turn(payload: dict[str, Any], *, stdout: Any = sys.stdout, stdin: Any = sys.stdin) -> dict[str, Any]:
def _run_turn(payload: dict[str, Any], *, stdout: Any = sys.stdout, stdin: Any = sys.stdin,
runtime_engine: str = 'NAO') -> dict[str, Any]:
output_lock = threading.Lock()
from nao_quality_tools import SourceCoverageUnavailable
from nao_thinking_stream import ThinkingPublisher
thinking = ThinkingPublisher(lambda block: _emit(stdout, output_lock,
{"type":"progress","thinkingUpdate":block}))
def emit(value):
if value.get('type') == 'result': thinking.close()
if value.get('type') == 'result':
thinking.close()
value['engine'] = runtime_engine
if runtime_engine == 'DSH' and isinstance(value.get('message'), str):
value['message'] = value['message'].replace('原装 NAO', 'DeepSeek Harness').replace('NAO', 'DSH')
_emit(stdout, output_lock, value)
actor_root: Path | None = None
actor_fd: int | None = None
@@ -2494,7 +2506,15 @@ def _run_turn(payload: dict[str, Any], *, stdout: Any = sys.stdout, stdin: Any =
model_gate: Any | None = None
try:
request = _normalize_request(payload)
request['runtimeEngine'] = runtime_engine
protocol_request = isinstance((request.get('context') or {}).get('_protocol'),dict)
if runtime_engine == 'DSH':
if not protocol_request:
raise RuntimeErrorSafe('DeepSeek Harness 需要启用正式分析协议,请检查服务配置。')
from setup_dsh_runtime import inspect_runtime
readiness = inspect_runtime()
if not readiness.get('ready'):
raise RuntimeErrorSafe('DeepSeek Harness 运行环境未就绪,请先完成安装检查。')
if protocol_request and request['context']['_protocol'].get('autonomousEnabled') is not True:
for legacy in ('_serverHistory','_serverQuestions','lastVisibleAnswer','_task','primaryEvidence'):
request['context'].pop(legacy,None)
@@ -2515,9 +2535,11 @@ def _run_turn(payload: dict[str, Any], *, stdout: Any = sys.stdout, stdin: Any =
def authorize_model() -> None:
delegated.call("/api/analysis/model-authorization", method="GET")
authorize_model()
engine_options = {'runtime_engine': runtime_engine} if runtime_engine == 'DSH' else {}
model_gate = ModelGate(upstream_base=upstream_base, upstream_key=upstream_key, model=selected_model,
port=port, client_key=gate_key, authorize=authorize_model,thinking_options=model_controls,
on_thinking=thinking.receive,native_turn_marker='quality-turn:'+request['turnId'])
on_thinking=thinking.receive,native_turn_marker='quality-turn:'+request['turnId'],
**engine_options)
del upstream_key
model_name = selected_model
# The model process receives only NAO's configured model credential. The delegated
@@ -2534,6 +2556,8 @@ def _run_turn(payload: dict[str, Any], *, stdout: Any = sys.stdout, stdin: Any =
cancel_event = threading.Event()
def request_cancel() -> None:
cancel_event.set()
if runtime_engine == 'DSH' and model_gate is not None:
model_gate.revoke()
_input_cancel_listener(stdin, request_cancel)
prior_evidence_files = frozenset(path.name for path in (actor_root / "evidence").glob("nao-quality-*.json"))
@@ -3141,6 +3165,9 @@ def _run_turn(payload: dict[str, Any], *, stdout: Any = sys.stdout, stdin: Any =
try:
_atomic_json(actor_root/'private'/'last-model-audit.json',{'model':selected_model,'requests':model_gate.request_audit,
'rejectedToolCalls':model_gate.rejected_tool_calls if isinstance(model_gate.rejected_tool_calls,int) else 0,
'rejectedToolNames':model_gate.rejected_tool_names if isinstance(model_gate.rejected_tool_names,list) else [],
'toolStreamFailures':model_gate.tool_stream_failures if isinstance(model_gate.tool_stream_failures,list) else [],
'toolStreamDiagnostics':model_gate.tool_stream_diagnostics if isinstance(model_gate.tool_stream_diagnostics,list) else [],
'rejectedStaleRequests':model_gate.rejected_stale_requests if isinstance(model_gate.rejected_stale_requests,int) else 0})
except (OSError,TypeError,ValueError):pass
model_gate.close()