接入 DSH 专用运行时和对话界面,保留模型原始回答,支持会话分页、连续追问与显式报告。 补齐组合筛选、各维度 Top100、分组查询到排名图的转换,图表故障静默省略并基于保存数据自动恢复。 优化报告风格、图表顺序和表格换行,更新接入说明及构建输入。 验证:独立目录前后端构建通过;118 项 Java、102 项前端、102 项图表、14 项 DSH 应用和 13 项组合筛选检查通过。 仅提交相关源码、锁定依赖与测试;不包含凭据、会话、业务数据或本地产物。
51 lines
2.0 KiB
Python
51 lines
2.0 KiB
Python
"""Standard-library-only stdio transport for one immutable DSH turn capability."""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import os
|
|
import sys
|
|
from urllib.error import HTTPError
|
|
from urllib.request import ProxyHandler, Request, build_opener
|
|
|
|
MAX_LINE = 2 * 1024 * 1024
|
|
|
|
|
|
def main():
|
|
endpoint = os.environ['QUALITY_DSH_RELAY']
|
|
capability = os.environ['QUALITY_DSH_CAPABILITY']
|
|
if not endpoint.startswith('http://127.0.0.1:') or endpoint.count('/') != 2:
|
|
raise ValueError('invalid relay')
|
|
opener = build_opener(ProxyHandler({}))
|
|
while True:
|
|
raw = sys.stdin.readline(MAX_LINE + 1)
|
|
if not raw:
|
|
return 0
|
|
if len(raw) > MAX_LINE or not raw.endswith('\n'):
|
|
return 2
|
|
request = None
|
|
try:
|
|
request = json.loads(raw)
|
|
outgoing = Request(endpoint + '/mcp', data=raw.encode('utf-8'),
|
|
headers={'Content-Type': 'application/json',
|
|
'Authorization': 'Bearer ' + capability}, method='POST')
|
|
with opener.open(outgoing, timeout=190) as response:
|
|
body = response.read(8 * 1024 * 1024 + 1)
|
|
if len(body) > 8 * 1024 * 1024:
|
|
raise ValueError('response too large')
|
|
if body.strip():
|
|
result = json.loads(body)
|
|
print(json.dumps(result, ensure_ascii=False, separators=(',', ':')), flush=True)
|
|
except Exception:
|
|
# Neither transport exceptions nor response bodies may expose capabilities.
|
|
if isinstance(request, dict) and 'id' in request:
|
|
print(json.dumps({'jsonrpc': '2.0', 'id': request['id'], 'error': {
|
|
'code': -32603, 'message': '本轮质量查询未完成;没有返回空数据成功。'}},
|
|
ensure_ascii=False), flush=True)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
try:
|
|
raise SystemExit(main())
|
|
except Exception:
|
|
raise SystemExit('DSH quality bridge unavailable') from None
|