接入 DSH 专用运行时和对话界面,保留模型原始回答,支持会话分页、连续追问与显式报告。 补齐组合筛选、各维度 Top100、分组查询到排名图的转换,图表故障静默省略并基于保存数据自动恢复。 优化报告风格、图表顺序和表格换行,更新接入说明及构建输入。 验证:独立目录前后端构建通过;118 项 Java、102 项前端、102 项图表、14 项 DSH 应用和 13 项组合筛选检查通过。 仅提交相关源码、锁定依赖与测试;不包含凭据、会话、业务数据或本地产物。
87 lines
3.5 KiB
Python
87 lines
3.5 KiB
Python
#!/usr/bin/env python3
|
|
"""Versioned engine entry point for the platform's delegated analysis protocol.
|
|
|
|
Engine selection is frozen by Java when an analysis is created. Neither the
|
|
model nor a tool result may select an executable or change it during a turn.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import json
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
ENGINES = frozenset({'NAO', 'DSH'})
|
|
|
|
|
|
def engine_for_request(payload, *, settings_file=None):
|
|
if not isinstance(payload, dict):
|
|
raise ValueError('分析请求无效。')
|
|
context = payload.get('context')
|
|
context = context if isinstance(context, dict) else {}
|
|
frozen = [value for value in (payload.get('runtimeEngine'), context.get('_runtimeEngine'))
|
|
if value is not None]
|
|
if frozen:
|
|
if any(not isinstance(value, str) or value not in ENGINES for value in frozen):
|
|
raise ValueError('分析引擎无效。')
|
|
if len(set(frozen)) != 1:
|
|
raise ValueError('分析引擎与本轮已保存设置不一致。')
|
|
return frozen[0]
|
|
from nao_model_settings import SETTINGS_FILE, _read_private
|
|
path = Path(settings_file) if settings_file is not None else SETTINGS_FILE
|
|
if path.is_symlink() or path.parent.is_symlink():
|
|
raise ValueError('分析引擎配置无效。')
|
|
if not path.exists():
|
|
return 'NAO'
|
|
value = json.loads(_read_private(path, 32768))
|
|
if not isinstance(value, dict):
|
|
raise ValueError('分析引擎配置无效。')
|
|
selected = value.get('runtimeEngine', 'NAO')
|
|
if not isinstance(selected, str) or selected not in ENGINES:
|
|
raise ValueError('分析引擎配置无效。')
|
|
return selected
|
|
|
|
|
|
def run_turn(payload, *, stdout=sys.stdout, stdin=sys.stdin, settings_file=None):
|
|
engine = engine_for_request(payload, settings_file=settings_file)
|
|
# Existing business orchestration owns authorization, evidence, history,
|
|
# formal visuals, reports and completion. Only its actual agent loop varies.
|
|
from nao_quality_runtime import run_turn as run_platform_turn
|
|
return run_platform_turn(payload, stdout=stdout, stdin=stdin, runtime_engine=engine)
|
|
|
|
|
|
def main(argv=None):
|
|
os.umask(0o077)
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument('--stop-all', action='store_true')
|
|
args = parser.parse_args(argv)
|
|
if args.stop_all:
|
|
from nao_quality_runtime import RuntimeManager
|
|
nao_count = RuntimeManager().stop_idle_all()
|
|
try:
|
|
from dsh_agent_runtime import stop_all_dsh
|
|
except ImportError:
|
|
summary = {'naoStopped':nao_count, 'dshStopped':0, 'dshUnconfirmed':0}
|
|
else:
|
|
stopped = stop_all_dsh()
|
|
summary = {'naoStopped':nao_count, 'dshStopped':stopped['stopped'],
|
|
'dshUnconfirmed':stopped['unconfirmed']}
|
|
sys.stdout.write(json.dumps(summary, ensure_ascii=False)+'\n')
|
|
return 0 if summary['dshUnconfirmed']==0 else 1
|
|
try:
|
|
from nao_quality_runtime import _read_initial_request
|
|
run_turn(_read_initial_request(sys.stdin))
|
|
return 0
|
|
except Exception:
|
|
# Do not expose provider errors, request bodies, model keys or delegation.
|
|
sys.stdout.write(json.dumps({'type': 'result', 'status': 'FAILED',
|
|
'answer': '', 'stopReason': '分析引擎未能启动,请检查运行环境与引擎设置。'},
|
|
ensure_ascii=False) + '\n')
|
|
sys.stdout.flush()
|
|
return 1
|
|
|
|
|
|
if __name__ == '__main__':
|
|
raise SystemExit(main())
|