兑现「看到的=写章用的」信任牌(不变量 #6),替换写作页右栏过时假占位
(「M1 暂未接 / M2 开放」)。
后端:
- GET /projects/{id}/chapters/{no}/injection → InjectionResponse(selected
实体 + 入选理由 + recent_n);调既有 assemble() 回放确定性 SelectionTrace,
无 LLM / 无 commit / 无 DDL;项目不存在→404,无大纲→selected:[]。
- 新 schemas/injection.py;tests/test_injection.py(3 测)。
前端:
- gen:api 纳入端点;纯逻辑 lib/workbench/injection.ts(理由/类型→中文徽标
+ 4 vitest)+ useInjection 读 hook。
- ChapterAssistant 改 client 组件:列出选中实体 + 理由徽标 + 空/载/错三态,
四审段指向审稿页;Workbench 传 projectId/chapterNo。
门禁:后端 ruff/format/mypy 159/alembic 无漂移/pytest 454;
前端 lint/typecheck/vitest 167/build。
B0 可控版(PUT override pin/排除/recent_n + selection 加参 + draft 同读
override + 持久化)+ F1 可控控件待后续。
31 lines
1.0 KiB
TypeScript
31 lines
1.0 KiB
TypeScript
// 本章注入透明(B0/F1)纯逻辑:入选理由 / 实体类型 → 中文徽标。
|
||
// 纯函数,便于 node 环境单测;渲染层只管样式。
|
||
|
||
import type { components } from "@/lib/api/schema";
|
||
|
||
export type InjectionResponse = components["schemas"]["InjectionResponse"];
|
||
export type InjectionEntity = components["schemas"]["InjectionEntity"];
|
||
|
||
// SelectionReason → 作者可读徽标(对齐 ARCH §3.4 的四来源)。
|
||
export const REASON_LABELS: Record<string, string> = {
|
||
explicit_beat: "本章点名",
|
||
main_character: "主角常驻",
|
||
recent_digest: "近章出现",
|
||
foreshadow_window: "伏笔窗口",
|
||
};
|
||
|
||
// EntityKind → 中文。
|
||
export const KIND_LABELS: Record<string, string> = {
|
||
character: "角色",
|
||
world_entity: "设定",
|
||
};
|
||
|
||
// 未知 code 时回退原值(不吞,便于发现新理由)。
|
||
export function reasonLabel(reason: string): string {
|
||
return REASON_LABELS[reason] ?? reason;
|
||
}
|
||
|
||
export function kindLabel(kind: string): string {
|
||
return KIND_LABELS[kind] ?? kind;
|
||
}
|