fix(backend): 冻结 TOOLBOX 注册表为只读 MappingProxyType(CR-H7)
This commit is contained in:
@@ -16,6 +16,10 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Mapping
|
||||
from types import MappingProxyType
|
||||
from typing import Final
|
||||
|
||||
from ww_agents import SPECS
|
||||
from ww_agents.schemas import (
|
||||
BlurbResult,
|
||||
@@ -67,7 +71,7 @@ _SOURCE_TEXT_FIELD = InputField(
|
||||
|
||||
|
||||
# 创作工具箱注册表:key → 描述符。15 条(legacy 3 + 新 8 + Scope B 4:续写/扩写/降AI/拆书)。
|
||||
TOOLBOX: dict[str, GeneratorTool] = {
|
||||
_TOOLBOX_BY_KEY: dict[str, GeneratorTool] = {
|
||||
# ---- legacy(spec=None,前端走 legacy_route 跳现有页面)----
|
||||
"worldbuilding": GeneratorTool(
|
||||
key="worldbuilding",
|
||||
@@ -243,6 +247,10 @@ TOOLBOX: dict[str, GeneratorTool] = {
|
||||
),
|
||||
}
|
||||
|
||||
# MappingProxyType:只读视图,运行时 `TOOLBOX[x]=...` / `del TOOLBOX[x]` 抛 TypeError(单一
|
||||
# 真相源不可被污染;`Final` 仅静态检查、挡不住运行时变异,故须冻结成只读 Mapping)。
|
||||
TOOLBOX: Final[Mapping[str, GeneratorTool]] = MappingProxyType(_TOOLBOX_BY_KEY)
|
||||
|
||||
|
||||
def get_tool(key: str) -> GeneratorTool | None:
|
||||
"""按 key 取生成器描述符;未知 key → None(端点据此返 404)。"""
|
||||
|
||||
Reference in New Issue
Block a user