M2b:导入改造产出可审阅灵胚(启镜物化世谱)与组装管线(符文展开/火候进入 IR),Kernel 打通采样参数链路

This commit is contained in:
chenxin committed 2026-08-21 23:43:29 +08:00
1 parent e6a3b7121f
commit 5f36e3785c
86 files changed
+424 -14455

No files matched your search

+43
View File
@@ -194,6 +194,7 @@ async def activate_embryo(embryo_id: str, owner_scope: str) -> Character:
session.add(Custodianship(character_id=character.id, custodian_scope=owner_scope))
session.add(RuntimeSeat(character_id=character.id, epoch=1))
book_entry_count = await _materialize_import_book(session, baseline, character, owner_scope)
record = build_identity_record(
character_id=character.id,
@@ -205,6 +206,7 @@ async def activate_embryo(embryo_id: str, owner_scope: str) -> Character:
"activated_at": character.activated_at.isoformat(),
},
runtime_state={"status": "active", "seat_epoch": 1},
data_state={"imported_book_entries": book_entry_count},
)
session.add(record)
await session.flush() # 取魂籍 ID
@@ -307,3 +309,44 @@ async def _owned_character(
if character is None or character.owner_scope != owner_scope:
raise AppError("not_found", "人物不存在。")
return character
async def _materialize_import_book(
session: AsyncSession, baseline: dict, character: Character, owner_scope: str
) -> int:
"""启镜时把导入卡的 character_book 物化为新人物的世谱书与条目(待审语义随世谱状态治理)。"""
from app.models.lorebook import Lorebook, LorebookEntry
from app.modules.imports.mapping import character_book_to_entries
book = (baseline.get("import_card") or {}).get("character_book")
entries = character_book_to_entries(book)
if not entries:
return 0
lorebook = Lorebook(
character_id=character.id,
name=f"{character.name} 的世谱(导入)",
description="角色卡 character_book 启镜物化",
scope="character",
owner_scope=owner_scope,
)
session.add(lorebook)
await session.flush()
for spec in entries:
session.add(
LorebookEntry(
lorebook_id=lorebook.id,
keys_json=json.dumps(spec["keys"], ensure_ascii=False),
content=spec["content"],
secondary_keys_json=json.dumps(spec["secondary_keys"], ensure_ascii=False),
constant=spec["constant"],
selective=spec["selective"],
enabled=spec["enabled"],
case_sensitive=spec["case_sensitive"],
use_regex=spec["use_regex"],
position=spec["position"],
insertion_order=spec["insertion_order"],
priority=spec["priority"],
comment=spec["comment"][:500],
)
)
return len(entries)