- 缘契域 domains/yuanqi:covenants(当前版)+ covenant_events(不可变历史);提议—问心—铭契—撤回全链;边界变更立即生效;多维关系并存,服务层拒绝 affinity/好感度单一键;浪漫维度成人资格标记位 - 道体铸魂与分灵 domains/jingsheng/soul.py:soul_forgings 确认流(锚点变更 pending→confirmed 应用并签发新魂籍版本,确认前人物锚点不变);分灵创建新人物(继承资料与谱系 lineage 链、不继承原身份,魂籍从 v1 起) - 河图域 domains/hetu:persistent_worlds 境界 + world_entities/world_relations 境界作用域重建 + 世谱挂接;境界正史视图(scope=persistent_world 归真集合);canonize 后置推进正史计数 - 三界分流:reality→息壤提取(不变);persistent_world→境界实录+正史推进;simulation→只记试演实录;factual_records 增 scope 列——境界/幻境实录与真界本相隔离 - 正影打通:引文 target_type=memory 时被引记忆 superseded → 返回 successor_memory_id 提示,不静默替换 - 前端:人物详情页缘契面板(提议维度选择/铭契/撤回/事件史)+ 世界页重建(境界目录/实体/正史概览)+ covenants/worlds api 库 - 退役:旧 personality/drive/evolution/world 模块、服务、端点、仓储、schema、前端五页与组件样式;迁移 007 退役九张旧表与 characters.current_personality_version_id - 验收(test_m6_domains 六用例):多维无单一好感度/铭契版本链/事件不可抹除/撤回立即生效/边界即时/铸魂确认流+魂籍版本/分灵谱系/境界正史不进真界(实录 scope 隔离+真界候选=0)/引文正影后继 - 四套件:后端 379、前端 199、BFF 4、神识 5 包全绿(2 个预存环境失败不变);迁移 007 净库+±1 干净
109 lines
3.7 KiB
Python
109 lines
3.7 KiB
Python
"""河图世界 API(/worlds):境界 CRUD、实体关系、正史视图。"""
|
||
|
||
from fastapi import APIRouter, Depends, status
|
||
from pydantic import BaseModel, Field
|
||
|
||
from app.api.v1.deps import get_current_user
|
||
from app.domains.hetu import service
|
||
from app.schemas.auth import CurrentUser
|
||
|
||
world_router = APIRouter(prefix="/worlds", tags=["hetu"])
|
||
|
||
|
||
class CreateWorldRequest(BaseModel):
|
||
name: str = Field(min_length=1, max_length=120)
|
||
description: str = ""
|
||
rules: dict = Field(default_factory=dict)
|
||
lorebook_id: str | None = None
|
||
|
||
|
||
class UpdateWorldRequest(BaseModel):
|
||
name: str | None = None
|
||
description: str | None = None
|
||
rules: dict | None = None
|
||
lorebook_id: str | None = None
|
||
|
||
|
||
class EntityRequest(BaseModel):
|
||
kind: str = "concept"
|
||
name: str = Field(min_length=1, max_length=120)
|
||
description: str = ""
|
||
attrs: dict = Field(default_factory=dict)
|
||
|
||
|
||
class RelationRequest(BaseModel):
|
||
source_entity_id: str
|
||
target_entity_id: str
|
||
relation: str = Field(min_length=1, max_length=80)
|
||
note: str = ""
|
||
|
||
|
||
@world_router.post("", status_code=status.HTTP_201_CREATED)
|
||
async def create_world(
|
||
payload: CreateWorldRequest, user: CurrentUser = Depends(get_current_user)
|
||
) -> dict:
|
||
return await service.create_world(
|
||
owner_scope=user.owner_scope, name=payload.name, description=payload.description,
|
||
rules=payload.rules, lorebook_id=payload.lorebook_id,
|
||
)
|
||
|
||
|
||
@world_router.get("")
|
||
async def list_worlds(user: CurrentUser = Depends(get_current_user)) -> list[dict]:
|
||
return await service.list_worlds(user.owner_scope)
|
||
|
||
|
||
@world_router.get("/{world_id}")
|
||
async def get_world(world_id: str, user: CurrentUser = Depends(get_current_user)) -> dict:
|
||
return await service.get_world(world_id, user.owner_scope)
|
||
|
||
|
||
@world_router.patch("/{world_id}")
|
||
async def update_world(
|
||
world_id: str, payload: UpdateWorldRequest, user: CurrentUser = Depends(get_current_user)
|
||
) -> dict:
|
||
return await service.update_world(
|
||
world_id, user.owner_scope, name=payload.name, description=payload.description,
|
||
rules=payload.rules, lorebook_id=payload.lorebook_id,
|
||
)
|
||
|
||
|
||
@world_router.delete("/{world_id}")
|
||
async def archive_world(world_id: str, user: CurrentUser = Depends(get_current_user)) -> dict:
|
||
return await service.archive_world(world_id, user.owner_scope)
|
||
|
||
|
||
@world_router.post("/{world_id}/entities", status_code=status.HTTP_201_CREATED)
|
||
async def add_entity(
|
||
world_id: str, payload: EntityRequest, user: CurrentUser = Depends(get_current_user)
|
||
) -> dict:
|
||
return await service.add_entity(
|
||
world_id, user.owner_scope, kind=payload.kind, name=payload.name,
|
||
description=payload.description, attrs=payload.attrs,
|
||
)
|
||
|
||
|
||
@world_router.get("/{world_id}/entities")
|
||
async def list_entities(world_id: str, user: CurrentUser = Depends(get_current_user)) -> list[dict]:
|
||
return await service.list_entities(world_id, user.owner_scope)
|
||
|
||
|
||
@world_router.post("/{world_id}/relations", status_code=status.HTTP_201_CREATED)
|
||
async def add_relation(
|
||
world_id: str, payload: RelationRequest, user: CurrentUser = Depends(get_current_user)
|
||
) -> dict:
|
||
return await service.add_relation(
|
||
world_id, user.owner_scope, source_entity_id=payload.source_entity_id,
|
||
target_entity_id=payload.target_entity_id, relation=payload.relation, note=payload.note,
|
||
)
|
||
|
||
|
||
@world_router.get("/{world_id}/relations")
|
||
async def list_relations(world_id: str, user: CurrentUser = Depends(get_current_user)) -> list[dict]:
|
||
return await service.list_relations(world_id, user.owner_scope)
|
||
|
||
|
||
@world_router.get("/{world_id}/chronicle")
|
||
async def world_chronicle(world_id: str, user: CurrentUser = Depends(get_current_user)) -> dict:
|
||
return await service.world_chronicle(world_id, user.owner_scope)
|