Files
writer-work-flow/packages/agents/ww_agents/schema_catalog.py
Yaojia Wang 02d19019f6 feat(web): AI 立项方案生成+预填(种子门控 + 按字段接受)
向导阶段(project 未建)一键推演结构化书级蓝图预填立项向导。

- 新 SPEC project_plan_spec(analyst 档,纯预览 reads/writes=())+ schema
  ProjectPlanResult(书名候选 + 时空背景/叙事结构/故事核心/结局设计/基调,
  全字段默认值守解析韧性)+ 注册 SCHEMA_CATALOG;计数三处 21→22 + regen golden。
- 端点 POST /skills/project-plan/generate(不带 project 前缀,绕开 toolbox 404):
  请求体序列化向导草稿为 project_context,复用 build_brief_context + run_generator;
  种子门控(缺 genre/logline→422);请求 schema 加 max_length 上界。
- run_generator/_build_request 的 project_id 放宽 uuid.UUID|None(向导无 project)。
- 前端 wizard.ts 加 mapPlanResultToWizardForm(错配字段折进 premise 不静默丢)+
  applyPlanPatch(仅回填空字段、保护已编辑)+ useProjectPlan hook + PlanAssistant。
2026-07-06 16:26:08 +02:00

70 lines
2.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""`SCHEMA_CATALOG`name → output schema 的唯一真相源Prompt 外置方案A · 步4
Pydantic 类型承载结构化解析与 `isinstance` 校验,无法从文本推导、无法运行时安全构造,
必须留 Python。`SPECS[name].output_schema` 一律从这里派生(单向派生,避免双真相)。
`input_schema` 全 22 个恒为 None入参为序列化文本本波不建入参槽YAGNI
`refiner` 是唯一纯文本 writer`None` 是合法值(无结构化 schema
"""
from __future__ import annotations
from typing import Final
from pydantic import BaseModel
from .schemas import (
BlurbResult,
BookTeardownResult,
CharacterGenResult,
ContinuationResult,
ContinuityReview,
DeAiResult,
DetailedOutlineResult,
ForeshadowReview,
GlossaryResult,
GoldenFingerResult,
IdeaListResult,
NameListResult,
OpeningResult,
OutlineResult,
PaceReview,
PolishResult,
ProjectPlanResult,
StyleDriftReview,
StyleFingerprintResult,
TitleListResult,
WorldGenResult,
)
# name → output_schemainput 全 None本波不建入参槽——YAGNI
SCHEMA_CATALOG: Final[dict[str, type[BaseModel] | None]] = {
"continuity": ContinuityReview,
"outliner": OutlineResult,
"foreshadow": ForeshadowReview,
"pace": PaceReview,
"style_extract": StyleFingerprintResult,
"style": StyleDriftReview,
"refiner": None, # 唯一纯文本 writerNone 是合法值
"worldbuilder": WorldGenResult,
"character-gen": CharacterGenResult,
"brainstorm": IdeaListResult,
"book-title": TitleListResult,
"blurb": BlurbResult,
"name": NameListResult,
"golden-finger": GoldenFingerResult,
"glossary": GlossaryResult,
"opening": OpeningResult,
"fine-outline": DetailedOutlineResult,
"continue": ContinuationResult,
"expand": PolishResult,
"de-ai": DeAiResult,
"teardown": BookTeardownResult,
"project-plan": ProjectPlanResult,
}
def output_schema_for(name: str) -> type[BaseModel] | None:
"""name → output schema精确字符串相等命中未知 name → KeyError"""
return SCHEMA_CATALOG[name]