同步:完善质量分析工作台并更新主题字体

同步已上线的智能分析执行协议、来源查询、图表报告与管理页面配套代码。
补齐数据库迁移、运行依赖和回归测试,保留原有指标计算口径。
统一午夜黑及其他主题的控件细节、中文和业务数字字体。
排除本地业务数据、凭据、预览、发布与验收产物。

验证:生产构建通过,320项前端回归通过;本轮仅同步Git,不再次部署。
This commit is contained in:
2026-10-30 22:40:58 +08:00
parent edef747e3b
commit ff7bbe3e46
393 changed files with 62999 additions and 1783 deletions
+184
View File
@@ -0,0 +1,184 @@
"""Run the upstream NAO loop; platform checks identity, reads and final claims."""
from __future__ import annotations
import copy
import time
def exploration_notices(scopes, coverage):
by_pair = {(s.get('nodeId'),s.get('scopeId')):s for s in scopes}
grouped = {}
purposes = {'defects':'细分缺陷','records':'原始记录','source':'原件核验',
'changes':'批量比较','metrics':'正式指标','trend':'趋势'}
for row in coverage if isinstance(coverage,list) else []:
if row.get('complete') is True: continue
scope = by_pair.get((row.get('nodeId'),row.get('scopeId')), {})
child = scope.get('task') or {}
stage = '/'.join({'black':'黑片','bright':'亮片'}.get(s,s) for s in child.get('stages',[]))
kind = stage + purposes.get(scope.get('purpose'),'补充调查')
grouped.setdefault(kind,[]).append(str(scope.get('label') or '当前范围'))
return [kind+'尚未完整核实:'+'、'.join(dict.fromkeys(labels))+';未用于已核实结论。'
for kind,labels in grouped.items()]
def run_native_exploration(*, request, task, authority, actor_root, delegated, connection,
manager, state, cancel_event, emit, prior_evidence_files, phase_timings=None):
from nao_quality_runtime import _atomic_json, _authenticate, _sse_request, _read_json
from nao_agent_task import bind_task
from nao_protocol_execution import _identity, _platform_visual_context
from nao_evidence_finalizer import evidence_summaries, synthesize_native
from analysis_visual_evidence import protocol_visual_result
from nao_runtime_policy import native_timeout
from nao_native_exploration import _proofs
timings = dict(phase_timings or {})
identity = _identity(authority)
# _serverHistory is already reconstructed and authorized by the server.
# A fresh NAO chat each turn prevents hidden native memory restoring filters.
context = bind_task({key: copy.deepcopy(value) for key, value in request['context'].items()
if key in ('_serverHistory', '_serverQuestions', '_protocol')}, task)
context['releaseId'] = request['releaseId']
context['_nativeExecutionId'] = identity['executionId']
request['context'] = context
_atomic_json(actor_root / 'private' / 'last-agent-task.json', {
'sessionId': request['sessionId'], 'releaseId': request['releaseId'],
'task': task, 'protocol': identity})
started = time.monotonic()
_, _, model, base_url = manager.ensure_instance(actor_root, request['sessionId'],
expected_actor_id=request['actorId'], model_connection=connection)
client = _authenticate(actor_root, base_url)
timings['nativeStartup'] = round((time.monotonic() - started) * 1000)
emit({'type': 'progress', 'message': '正在根据实际结果自主调查…', 'executionMode': 'native_agent'})
started = time.monotonic()
investigation_started = started
def track_progress(event):
if ('firstUsefulMs' not in timings and event.get('type') == 'progress'
and any(call.get('status') == 'completed' and (call.get('input') or {}).get('mode') not in (None, 'catalog')
and '证据:' in str(call.get('outputSummary', '')) for call in event.get('toolCalls', []))):
timings['firstUsefulMs'] = (sum(timings.get(key, 0) for key in
('planningAndReview', 'taskConfirmation', 'nativeStartup'))
+ round((time.monotonic() - investigation_started) * 1000))
emit(event)
accumulator, native_status, native_reason, stop_succeeded = _sse_request(
client=client, base_url=base_url, model=model, question=request['question'],
release_id=request['releaseId'], context=context, chat_id=None,
session_state=state, session_id=request['sessionId'], actor_root=actor_root,
emit=track_progress, cancel_event=cancel_event, timeout=native_timeout(),
prior_evidence_files=prior_evidence_files, turn_id=request['turnId'])
timings['investigation'] = round((time.monotonic() - started) * 1000)
draft_path = actor_root / 'private' / 'native-draft.json'
_atomic_json(draft_path, {'turnId': request['turnId'], 'executionId': identity['executionId'],
'answer': accumulator.answer, 'status': native_status,
'reason': native_reason})
if cancel_event.is_set() or native_status == 'CANCELLED':
result = {'type': 'result', 'engine': 'NAO', 'status': 'CANCELLED', 'answer': '',
'stopReason': '用户停止', 'finishReason': 'cancelled', 'agentTask': task,
'protocol': identity, 'executionMode': 'native_agent', 'toolCalls': accumulator.tool_calls,
'toolCount': len(accumulator.tool_calls), 'timeline': accumulator.timeline,
'queryEvidenceRefs': [], 'protocolEvidence': [], 'visuals': [], 'visualState': 'not_requested'}
emit(result)
return result
snapshot = delegated.call('/api/analysis/protocol/queries', payload={}, method='POST')
scopes = snapshot.get('scopes', [])
receipts = [q.get('proof', {}) for q in snapshot.get('queries', []) if isinstance(q, dict)]
accepted_ids = {p.get('queryId') for p in receipts if p.get('executionId') == identity['executionId']}
coverage_rows = snapshot.get('scopeCoverage')
complete_scopes = ({(row.get('nodeId'), row.get('scopeId')) for row in coverage_rows
if isinstance(row, dict) and row.get('complete') is True}
if isinstance(coverage_rows, list) else None)
documents = evidence_summaries(actor_root / 'evidence', request['releaseId'],
exclude_files=prior_evidence_files, allow_empty=True)
documents = [doc for doc in documents if _proofs(doc.get('result', {}))
and all(p.get('executionId') == identity['executionId'] and p.get('queryId') in accepted_ids
and (complete_scopes is None or (p.get('nodeId'), p.get('scopeId')) in complete_scopes)
for p in _proofs(doc.get('result', {})))]
warnings = list(snapshot.get('explorationWarnings', []))
summary_warnings = exploration_notices(scopes,coverage_rows) or list(warnings)
missing = list(snapshot.get('rootGoalGaps', []))
if complete_scopes is None:
missing.extend(snapshot.get('gaps', []))
progress_path = actor_root / 'private' / 'native-exploration-state.json'
progress = _read_json(progress_path) if progress_path.is_file() else {}
timings['formalQuery'] = progress.get('queryElapsedMs', 0)
controlled_no_progress = (progress.get('executionId') == identity['executionId']
and progress.get('halted')
and type(progress.get('noProgress')) is int and progress['noProgress'] >= 3)
if controlled_no_progress:
missing.append('连续三次没有取得新证据,调查已停止;其余线索尚未验证。')
natural_finish = 'stop' in accumulator.finish_reasons and stop_succeeded is not False
corrected_tool_errors = (native_reason == 'mcp_error' and natural_finish
and complete_scopes is not None and bool(documents)
and not missing and not progress.get('halted'))
if native_status != 'COMPLETED' and not corrected_tool_errors and not controlled_no_progress:
missing.append('自主调查未正常结束(' + str(native_reason or native_status) + '),已保留核实结果。')
if not documents:
missing.append('本轮未取得当前执行的可核验查询证据。')
context['_protocolScopes'] = {'scopes': scopes, 'pending': snapshot.get('pending', []), 'gaps': missing}
started = time.monotonic()
visuals = protocol_visual_result(documents, scopes, request['question'], request['turnId'],
release_id=request['releaseId'], base_context=context)
timings['visuals'] = round((time.monotonic() - started) * 1000)
context['_platformVisuals'] = _platform_visual_context(visuals)
started = time.monotonic()
final = synthesize_native(base_url=connection[0], api_key=connection[1], model=connection[2],
question=request['question'], evidence=documents, cancel_event=cancel_event,
context=context, native_answer=accumulator.answer)
timings['synthesis'] = round((time.monotonic() - started) * 1000)
_atomic_json(actor_root / 'private' / 'native-composition.json', {
'turnId': request['turnId'], 'rawModelResponses': final.get('rawModelResponses', []),
'compositionDiagnostics': final.get('compositionDiagnostics', {}),
'readingSummary': final.get('readingSummary')})
full_facts = final.get('fullEvidenceFacts', [])
if full_facts:
_atomic_json(actor_root / 'private' / 'native-full-evidence-facts.json', full_facts)
missing.extend(final.get('missingEvidence', []))
if task.get('visualPreference') == 'required':
missing.extend(visuals.get('missingEvidence', []))
else:
warnings.extend(str(item).replace('queryPlan共有', '共有').replace('结果为部分完成。', '已保留核实结果。')
for item in visuals.get('missingEvidence', []))
missing = list(dict.fromkeys(str(item) for item in missing if item))
complete = bool(documents and final.get('evidenceSufficient') and not missing)
used_refs = set(final.get('usedEvidenceRefs', []))
cited_ids = list(dict.fromkeys(p['queryId'] for doc in documents if doc.get('evidenceRef') in used_refs
for p in _proofs(doc.get('result', {}))))
if final.get('evidenceSufficient') and not cited_ids:
missing.append('解释未关联当前执行的实际查询证明。')
complete = False
if warnings:
def visible_warning(value):
text = str(value)
for scope in scopes:
text = text.replace('节点'+str(scope.get('nodeId'))+'范围','范围')
return text
final['answer'] += '\n\n## 调查局限\n\n' + '\n'.join('- ' + visible_warning(item) for item in dict.fromkeys(warnings))
if isinstance(final.get('readingSummary'), dict):
final['readingSummary']['notices'] = list(dict.fromkeys([
*final['readingSummary'].get('notices', []), *summary_warnings]))
if missing:
final['answer'] += '\n\n尚未解决:' + ';'.join(missing)
if isinstance(final.get('readingSummary'), dict):
final['readingSummary']['notices'] = list(dict.fromkeys([
*final['readingSummary'].get('notices', []), *missing]))
result = {'type': 'result', 'engine': 'NAO', 'status': 'COMPLETED' if complete else 'PARTIAL',
'answer': final['answer'], 'readingSummary': final.get('readingSummary'),
'reportTitle': final.get('reportTitle'), 'agentTask': task, 'protocol': identity,
'executionMode': 'native_agent', 'completionMethod': 'native_autonomous_analysis',
'stopReason': 'evidence_finalized' if complete else 'evidence_incomplete', 'finishReason': 'stop',
'nativeStopReason': native_reason, 'nativeStopSucceeded': stop_succeeded,
'nativeFinishReason': 'stop' if natural_finish else native_reason,
'conclusionProtocolQueryIds': cited_ids,
'actualModel': model, 'phaseTimingsMs': timings,
'protocolEvidence': receipts, 'queryEvidenceRefs': [doc['evidenceRef'] for doc in documents],
'toolCalls': accumulator.tool_calls, 'toolCount': len(accumulator.tool_calls),
'timeline': accumulator.timeline, 'factsComplete': bool(documents and not missing),
'evidenceCompletion': {'serverCoverageSufficient': not snapshot.get('rootGoalGaps'),
'missingEvidence': missing},
'agentContext': {key: copy.deepcopy(task[key]) for key in
('filters', 'period', 'comparisonPeriod') if task.get(key) is not None},
'visualSchemaVersion': 1, 'visualState': visuals.get('visualState', 'not_requested'),
'visuals': visuals.get('visuals', [])}
result['agentContext']['releaseId'] = request['releaseId']
_atomic_json(actor_root / 'private' / 'native-completion.json', result)
emit(result)
return result