"""显式注册动作处理器""" from typing import Any from app.actions.add import AddHandler from app.actions.base import BaseActionHandler from app.actions.move import MoveHandler from app.actions.resize import ResizeHandler from app.actions.update import UpdateHandler from app.schemas.actions import Action from app.schemas.screen import Screen # 新增操作时在此注册,未实现的操作明确报错 ACTION_HANDLERS: dict[str, BaseActionHandler[Any]] = { "add": AddHandler(), "move": MoveHandler(), "resize": ResizeHandler(), "update": UpdateHandler(), } def apply_action(screen: Screen, action: Action) -> Screen: """接收已通过 Schema 校验的动作,返回执行后的副本""" handler = ACTION_HANDLERS.get(action.type) if handler is None: raise ValueError(f"尚未实现动作处理器: {action.type}") return handler.apply(screen, action)