feat: M4 文风 + M5 生成/多provider/Skill + Kimi Code 订阅接入 + 本地联调修复

M4(文风): style-auditor 双轨(提取指纹/漂移第四审)+ jobs 长任务框架(zombie reaper) + 回炉 refine + GET /style read-back。
M5(生成+扩展): worldbuilder/character-gen(入库 continuity 409 gate + partition_writes 白名单 + schema→JSONB 形变);
  网关多 provider 回退链/熔断/能力降级(Anthropic/Gemini 适配器);Skill registry + 表权限沙箱 + 规则;
  前端 角色生成器/世界观/Codex/规则页/技能库/⌘K 命令面板。
K1(Kimi Code 订阅接入): OAuth device-flow(kimi-code)+ 静态 Console key(kimi-code-key)两路径;
  coding 端点 KimiCLI 伪造头(实测 UA allow-list 门禁,缺则 403)+ JSON 模式结构化(thinking ⊥ tool_choice)。
本地联调修复: CORS 中间件;assemble 注入 premise+「写第N章」指令(修空 prompt 400);
  GET /outline·/draft read-back + 大纲/工作台/审稿页重载;写页 client/server 常量边界 + notFound 健壮化;
  字数 toLocaleString locale 水合;审稿页终稿从已存草稿 seed(修 accept 422)。
门禁: backend ruff/mypy(157)/alembic 无漂移/pytest 451 · frontend lint/tsc/vitest/build。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Yaojia Wang
2026-06-20 10:39:58 +02:00
parent 5fb7bfb1de
commit 765dbdfbd4
161 changed files with 17330 additions and 208 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,68 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import { fetchDraft, fetchOutline } from "./server";
// 纯加载/降级逻辑mock fetch无网络/DOM大纲解包/降级、草稿 404→null。
function mockFetch(status: number, body: unknown): void {
vi.stubGlobal(
"fetch",
vi.fn(async () =>
new Response(JSON.stringify(body), {
status,
headers: { "content-type": "application/json" },
}),
),
);
}
afterEach(() => {
vi.unstubAllGlobals();
});
describe("fetchOutline", () => {
it("returns the persisted chapters on 200", async () => {
mockFetch(200, { chapters: [{ no: 1, volume: 1, beats: ["开场"] }] });
const chapters = await fetchOutline("p1");
expect(chapters).toHaveLength(1);
expect(chapters[0].no).toBe(1);
});
it("returns empty array when the project has no outline", async () => {
mockFetch(200, { chapters: [] });
expect(await fetchOutline("p1")).toEqual([]);
});
it("falls back to empty array on any error (does not throw)", async () => {
mockFetch(404, { error: { code: "NOT_FOUND", message: "no project" } });
expect(await fetchOutline("missing")).toEqual([]);
});
});
describe("fetchDraft", () => {
it("returns the saved draft view on 200", async () => {
mockFetch(200, {
project_id: "p1",
chapter_no: 1,
volume: 1,
status: "draft",
version: 2,
content: "第一章正文",
length: 5,
});
const draft = await fetchDraft("p1", 1);
expect(draft?.content).toBe("第一章正文");
expect(draft?.version).toBe(2);
});
it("returns null when no draft exists (404 → empty editor)", async () => {
mockFetch(404, { error: { code: "NOT_FOUND", message: "no draft" } });
expect(await fetchDraft("p1", 9)).toBeNull();
});
});

View File

@@ -1,10 +1,19 @@
import { serverApiBase } from "./config";
import type {
CharacterListResponse,
DraftView,
ForeshadowBoardResponse,
OutlineChapterView,
OutlineResponse,
ProjectListResponse,
ProjectResponse,
OAuthStatusResponse,
ProvidersResponse,
ReviewHistoryResponse,
RuleListResponse,
SkillListResponse,
StyleFingerprintResponse,
WorldEntityListResponse,
} from "./types";
// 服务端只读取数据Server Components。失败时抛出由页面边界处理。
@@ -16,6 +25,16 @@ async function getJson<T>(path: string): Promise<T> {
return (await res.json()) as T;
}
// 像上面一样读取,但 404无指纹返回 null 而非抛出(首学前页面照常渲染)。
async function getJsonOrNull<T>(path: string): Promise<T | null> {
const res = await fetch(`${serverApiBase()}${path}`, { cache: "no-store" });
if (res.status === 404) return null;
if (!res.ok) {
throw new Error(`请求失败 ${res.status}: ${path}`);
}
return (await res.json()) as T;
}
export async function fetchProjects(): Promise<ProjectListResponse> {
return getJson<ProjectListResponse>("/projects");
}
@@ -28,6 +47,13 @@ export async function fetchProviders(): Promise<ProvidersResponse> {
return getJson<ProvidersResponse>("/settings/providers");
}
// Kimi Code OAuth 连接态GET .../oauth/status无 token 本体)。
export async function fetchKimiOauthStatus(): Promise<OAuthStatusResponse> {
return getJson<OAuthStatusResponse>(
"/settings/providers/kimi-code/oauth/status",
);
}
export async function fetchReviews(
projectId: string,
chapterNo: number,
@@ -43,3 +69,66 @@ export async function fetchForeshadow(
): Promise<ForeshadowBoardResponse> {
return getJson<ForeshadowBoardResponse>(`/projects/${projectId}/foreshadow`);
}
// 最新文风指纹GET /style无指纹404→ null首学前页面照常渲染
export async function fetchStyleFingerprint(
projectId: string,
): Promise<StyleFingerprintResponse | null> {
return getJsonOrNull<StyleFingerprintResponse>(
`/projects/${projectId}/style`,
);
}
// 规则列表GET .../rules规则页
export async function fetchRules(
projectId: string,
): Promise<RuleListResponse> {
return getJson<RuleListResponse>(`/projects/${projectId}/rules`);
}
// 技能库注册表GET /skills全局只读
export async function fetchSkills(): Promise<SkillListResponse> {
return getJson<SkillListResponse>("/skills");
}
// 设定库 Codex跨会话全量已入库角色GET .../characters无行→空列表非 404
export async function fetchCharacters(
projectId: string,
): Promise<CharacterListResponse> {
return getJson<CharacterListResponse>(`/projects/${projectId}/characters`);
}
// 设定库 Codex跨会话全量已入库世界观实体GET .../world_entities无行→空列表
export async function fetchWorldEntities(
projectId: string,
): Promise<WorldEntityListResponse> {
return getJson<WorldEntityListResponse>(
`/projects/${projectId}/world_entities`,
);
}
// 已存大纲GET .../outline与 POST 同形,按 chapter_no 排序)。
// 无大纲→空列表;任何错误亦降级为空(进页不阻塞,生成流照常工作)。
export async function fetchOutline(
projectId: string,
): Promise<OutlineChapterView[]> {
try {
const res = await getJson<OutlineResponse>(
`/projects/${projectId}/outline`,
);
return res.chapters ?? [];
} catch {
return [];
}
}
// 已存草稿GET .../draft含正文供工作台重访重载编辑器
// 404尚无草稿新章→ null由调用方当空编辑器处理不抛错。
export async function fetchDraft(
projectId: string,
chapterNo: number,
): Promise<DraftView | null> {
return getJsonOrNull<DraftView>(
`/projects/${projectId}/chapters/${chapterNo}/draft`,
);
}

View File

@@ -6,6 +6,8 @@ export type ProjectCreateRequest = components["schemas"]["ProjectCreateRequest"]
export type ProjectListResponse = components["schemas"]["ProjectListResponse"];
export type DraftSaveRequest = components["schemas"]["DraftSaveRequest"];
export type DraftResponse = components["schemas"]["DraftResponse"];
// GET .../draft 读端点含正文供工作台重访时重载编辑器404→空编辑器
export type DraftView = components["schemas"]["DraftView"];
export type ProvidersResponse = components["schemas"]["ProvidersResponse"];
export type ProviderView = components["schemas"]["ProviderView"];
export type TierRoutingView = components["schemas"]["TierRoutingView"];
@@ -40,3 +42,48 @@ export type OutlineChapterView = components["schemas"]["OutlineChapterView"];
export type OutlineGenerateRequest =
components["schemas"]["OutlineGenerateRequest"];
export type OutlineResponse = components["schemas"]["OutlineResponse"];
// M4 文风学文风jobs 异步)+ 最新指纹 + 回炉C3 扩 T4.3)。
export type StyleLearnRequest = components["schemas"]["StyleLearnRequest"];
export type StyleLearnResponse = components["schemas"]["StyleLearnResponse"];
export type StyleFingerprintResponse =
components["schemas"]["StyleFingerprintResponse"];
export type RefineRequest = components["schemas"]["RefineRequest"];
export type RefineResponse = components["schemas"]["RefineResponse"];
// M5 生成 + 设定库C3 扩 T5.2)。
export type WorldGenerateRequest =
components["schemas"]["WorldGenerateRequest"];
export type WorldGenPreviewResponse =
components["schemas"]["WorldGenPreviewResponse"];
export type WorldEntityCardView =
components["schemas"]["WorldEntityCardView"];
export type CharacterGenerateRequest =
components["schemas"]["CharacterGenerateRequest"];
export type CharacterGenPreviewResponse =
components["schemas"]["CharacterGenPreviewResponse"];
export type CharacterCardView = components["schemas"]["CharacterCardView"];
export type CharacterRelationView =
components["schemas"]["CharacterRelationView"];
export type CharacterIngestRequest =
components["schemas"]["CharacterIngestRequest"];
export type CharacterIngestResponse =
components["schemas"]["CharacterIngestResponse"];
// 设定库 Codex 读端点C3 扩 M5 R1 follow-up跨会话全量已入库角色/世界观。
export type CharacterListResponse =
components["schemas"]["CharacterListResponse"];
export type WorldEntityListResponse =
components["schemas"]["WorldEntityListResponse"];
// K1 Kimi Code OAuth device-flowC3 扩 K1.3)。
export type OAuthStartResponse = components["schemas"]["OAuthStartResponse"];
export type OAuthDisconnectResponse =
components["schemas"]["OAuthDisconnectResponse"];
export type OAuthStatusResponse = components["schemas"]["OAuthStatusResponse"];
// M5 规则 + 技能C3 扩 T5.2 / T5.5)。
export type RuleCreateRequest = components["schemas"]["RuleCreateRequest"];
export type RuleView = components["schemas"]["RuleView"];
export type RuleListResponse = components["schemas"]["RuleListResponse"];
export type SkillView = components["schemas"]["SkillView"];
export type SkillListResponse = components["schemas"]["SkillListResponse"];