Ports her yinduzhanxing 17a135457ec16b621f86dd57ba3926612ce1b9b8 (docs ee34700357): timing_evidence_packets.py (new), kp_monthly_report_packet / theme_support / vimshottari / transits, kp_system, with her tests. The report path (frozen engine, no timing systems supplied) keeps its earlier packet byte for byte; her profile and window run when the caller supplies the periods it already computed (engine tool kp_timing_packet, cached per chart and window). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DbBXp2Vp62Ur3C7yRWQdSq
52 lines
2.6 KiB
Python
52 lines
2.6 KiB
Python
"""按需计算工具注册表(#173)。
|
||
|
||
加新工具(#174–#178):在 `TOOLS` 里加一行 `"<tool>": <module>.run`,其余不用改。
|
||
"""
|
||
|
||
from __future__ import annotations
|
||
|
||
from typing import Any, Callable, Dict
|
||
|
||
from . import dasha_date, kp_timing_packet, kp_transit_lords, prashna, solar_return, transit_date, transit_window, varga
|
||
from .contract import OnDemandInputError, blocked_envelope
|
||
|
||
# 工具名 → run(body) -> envelope
|
||
TOOLS: Dict[str, Callable[[Dict[str, Any]], Dict[str, Any]]] = {
|
||
# 指定日期的行运:必填 date、地点(lat/lon)、时区(tz 或 timezone_id)、ayanamsa;
|
||
# node_mode / position_mode 缺省用产品默认值(mean / apparent)。
|
||
'transit_date': transit_date.run,
|
||
# 一段时间的行运变化:必填 start_date、end_date、地点、时区、ayanamsa、events;
|
||
# planets / target / natal 按事件类型选填。
|
||
'transit_window': transit_window.run,
|
||
# 指定年份的太阳回归年盘:必填 target_year、birth(出生日期时间与地点、时区)、ayanamsa;
|
||
# return_location / node_mode / position_mode 选填。
|
||
'solar_return': solar_return.run,
|
||
# 指定分盘及其变体:必填 birth(出生日期时间与地点、时区)、ayanamsa、divisions;
|
||
# variants / node_mode / position_mode 选填。
|
||
'varga': varga.run,
|
||
'dasha_date': dasha_date.run,
|
||
'prashna': prashna.run, # question_text, question_time, location, ayanamsa
|
||
# BUG-2325:KP 推运用的太阳、月亮、木星每天的星宿主 / 子主(start_date、days ≤ 400、地点、时区、ayanamsa=kp)。
|
||
'kp_transit_lords': kp_transit_lords.run,
|
||
# BUG-2333:问答推运的 KP 月度包和多体系时间窗(birth、start_date、end_date ≤ 400 天、timing_systems、natal;
|
||
# 占星师 17a13545 的 build_kp_monthly_report_packet,KP 口径;问题原文和反馈不收)。
|
||
'kp_timing_packet': kp_timing_packet.run,
|
||
}
|
||
|
||
__all__ = ['TOOLS', 'OnDemandInputError', 'ondemand_calc_api']
|
||
|
||
|
||
def ondemand_calc_api(body: Dict[str, Any]) -> Dict[str, Any]:
|
||
"""唯一入口:按 body["tool"] 分派。未知工具返回 blocked 信封。"""
|
||
tool = None
|
||
if isinstance(body, dict):
|
||
tool = body.get('tool')
|
||
if not tool:
|
||
error = OnDemandInputError('missing required field: tool', 'tool')
|
||
return blocked_envelope(tool='unknown', body=body if isinstance(body, dict) else {}, error=error)
|
||
handler = TOOLS.get(str(tool))
|
||
if handler is None:
|
||
error = OnDemandInputError(f'unknown tool: {tool}', 'tool')
|
||
return blocked_envelope(tool=str(tool), body=body, error=error)
|
||
return handler(body)
|