#5 规则 DELETE + id:暴露 RuleView.id(PK);新增 DELETE /projects/{id}/rules/{rule_id} (项目/规则不存在→404,成功→204,按 (id,project_id) 限定);rule_repo 加 list_for_project/delete;RulesPage 每条加删除(乐观删+回滚+toast)。assemble 侧 RuleView(缓存前缀)不动,列表另立 RuleListItemView。 #7 codex 角色 relations:写侧本已持久化、读端点 _existing_characters 硬编码 []。 加 _relations_from_jsonb 解析 {name,kind,note},CodexPage 渲染关系 chip。 #8 角色入库幂等:SqlCharacterWriteRepo.create 改 (project_id,name) app 层 upsert—— 重复入库改更新而非插入;不加 UNIQUE/迁移(线上已有重复行会让约束迁移失败)。 #1 大纲卷过滤:GET /outline 支持可选 ?volume(无参=全部,向后兼容);OutlineEditor 加「查看:全部/卷N」筛选,与生成目标卷解耦。 H3/#9 文风回炉锚点:StyleDriftSegment 加 text(逐字命中段),style.md 指示审稿输出; 前端按内容锚点定位回炉目标(idx 仅排序),命中失败 → 提示「无法定位该段」而非 静默 no-op。style golden fixture 已重生成。 契约变更已 pnpm gen:api(RuleView.id / DELETE rules / outline ?volume)。无迁移 (alembic 无漂移)。门禁绿:ruff/mypy(210)/alembic/pytest 760 · 前端 tsc/lint/vitest 329。
140 lines
5.0 KiB
TypeScript
140 lines
5.0 KiB
TypeScript
"use client";
|
||
|
||
import { useMemo, useState } from "react";
|
||
|
||
import { AppShell } from "@/components/AppShell";
|
||
import type { OutlineChapterView, ProjectResponse } from "@/lib/api/types";
|
||
import {
|
||
distinctVolumes,
|
||
filterByViewVolume,
|
||
groupByVolume,
|
||
type ViewVolume,
|
||
} from "@/lib/outline/outline";
|
||
import { useOutline } from "@/lib/outline/useOutline";
|
||
import { OutlineChapterRow } from "./OutlineChapterRow";
|
||
|
||
interface OutlineEditorProps {
|
||
project: ProjectResponse;
|
||
initialChapters: OutlineChapterView[];
|
||
}
|
||
|
||
// 大纲编辑器主体(UX §6.7)。RSC 种入已存大纲;Client 承载生成(POST .../outline)。
|
||
// 无凭据 → 503 LLM_UNAVAILABLE 经 error 检出、引导去设置。
|
||
export function OutlineEditor({
|
||
project,
|
||
initialChapters,
|
||
}: OutlineEditorProps) {
|
||
const { chapters, status, error, generate } = useOutline(initialChapters);
|
||
const [volume, setVolume] = useState(1);
|
||
// 视图卷过滤("全部" 或某卷)——只影响展示,与生成的目标卷 `volume` 解耦。
|
||
const [viewVolume, setViewVolume] = useState<ViewVolume>("all");
|
||
const availableVolumes = useMemo(() => distinctVolumes(chapters), [chapters]);
|
||
const volumes = useMemo(
|
||
() => groupByVolume(filterByViewVolume(chapters, viewVolume)),
|
||
[chapters, viewVolume],
|
||
);
|
||
const generating = status === "generating";
|
||
|
||
return (
|
||
<AppShell
|
||
title={`〈${project.title}〉`}
|
||
subtitle="大纲"
|
||
projectId={project.id}
|
||
activeNav="outline"
|
||
>
|
||
<div className="flex h-[calc(100vh-var(--chrome,4rem))] flex-col p-6">
|
||
<div className="mb-4 flex items-center gap-3">
|
||
<h1 className="font-serif text-lg text-ink">大纲</h1>
|
||
{availableVolumes.length > 0 ? (
|
||
<label htmlFor="view-vol" className="ml-auto text-xs text-ink-soft">
|
||
查看
|
||
<select
|
||
id="view-vol"
|
||
value={viewVolume === "all" ? "all" : String(viewVolume)}
|
||
onChange={(e) =>
|
||
setViewVolume(
|
||
e.target.value === "all" ? "all" : Number(e.target.value),
|
||
)
|
||
}
|
||
className="ml-1 rounded border border-line bg-bg px-2 py-1 text-sm text-ink focus:border-cinnabar focus:outline-none"
|
||
>
|
||
<option value="all">全部</option>
|
||
{availableVolumes.map((v) => (
|
||
<option key={v} value={String(v)}>
|
||
卷 {v}
|
||
</option>
|
||
))}
|
||
</select>
|
||
</label>
|
||
) : null}
|
||
<label
|
||
htmlFor="vol"
|
||
className={`text-xs text-ink-soft${availableVolumes.length > 0 ? "" : " ml-auto"}`}
|
||
>
|
||
卷号
|
||
</label>
|
||
<input
|
||
id="vol"
|
||
inputMode="numeric"
|
||
value={volume}
|
||
onChange={(e) => setVolume(Math.max(1, Number(e.target.value) || 1))}
|
||
className="w-16 rounded border border-line bg-bg px-2 py-1 text-sm text-ink focus:border-cinnabar focus:outline-none"
|
||
/>
|
||
<button
|
||
type="button"
|
||
disabled={generating}
|
||
onClick={() => void generate(project.id, volume)}
|
||
className="rounded bg-cinnabar px-3 py-1.5 text-sm text-panel hover:opacity-90 disabled:opacity-40"
|
||
>
|
||
{generating ? "排大纲中…" : "✦ AI 排大纲"}
|
||
</button>
|
||
</div>
|
||
|
||
{error ? (
|
||
<p className="mb-4 text-sm text-conflict">
|
||
大纲生成失败({error.code}):{error.message}
|
||
{error.code === "LLM_UNAVAILABLE" ? (
|
||
<>
|
||
{" "}
|
||
<a
|
||
href="/settings/providers"
|
||
className="underline hover:text-cinnabar"
|
||
>
|
||
去设置提供商
|
||
</a>
|
||
</>
|
||
) : null}
|
||
</p>
|
||
) : null}
|
||
|
||
<div className="min-h-0 flex-1 overflow-auto">
|
||
{volumes.length === 0 ? (
|
||
<p className="rounded border border-dashed border-line p-6 text-sm text-ink-soft">
|
||
{chapters.length > 0 && viewVolume !== "all"
|
||
? `卷 ${viewVolume} 暂无大纲。切到「全部」查看其它卷,或点「✦ AI 排大纲」为本卷生成。`
|
||
: "暂无大纲。点「✦ AI 排大纲」生成逐章节拍与伏笔窗口。"}
|
||
</p>
|
||
) : (
|
||
volumes.map((group) => (
|
||
<section key={group.volume} className="mb-6">
|
||
<h2 className="mb-2 font-serif text-base text-ink">
|
||
卷 {group.volume}
|
||
</h2>
|
||
<ul className="space-y-1">
|
||
{group.chapters.map((ch) => (
|
||
<OutlineChapterRow
|
||
key={ch.no}
|
||
chapter={ch}
|
||
projectId={project.id}
|
||
/>
|
||
))}
|
||
</ul>
|
||
</section>
|
||
))
|
||
)}
|
||
</div>
|
||
</div>
|
||
</AppShell>
|
||
);
|
||
}
|