feat(web): F1/F2/F3 前端——拆书入库为规则 / 续写式链选择 / 模板库
- gen:api 纳入 /templates、chain continue_volume、teardown rules ingest 端点 - F1:GeneratorRunner 识别拆书为单对象入库(整 preview 作一条 teardown), ingestTable(BookTeardownResult)=rules,buildIngestRequest 组装 teardown 体, 按 isSingleObjectIngest 隐藏勾选框、改文案「入库为规则」 - F2:ChainStarter 加链类型单选(draft_volume 从头写 / continue_volume 续写), chain_key 作 path 参传给 run(CHAIN_KINDS 对齐后端 SUPPORTED_CHAINS) - F3:模板库页 app/templates + 全局 nav 入口 + TemplatesManager(列/建/删,乐观更新回滚); GeneratorRunner 加 TemplateFiller「从模板填入」(body 填进 brief/text,纯前端) - vitest 覆盖 templates/ingest teardown/templateFillTarget/CHAIN_KINDS 纯逻辑
This commit is contained in:
@@ -1,12 +1,17 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { buildIngestRequest, ingestTable } from "./ingest";
|
||||
import {
|
||||
buildIngestRequest,
|
||||
ingestTable,
|
||||
isSingleObjectIngest,
|
||||
} from "./ingest";
|
||||
|
||||
describe("ingestTable", () => {
|
||||
it("maps ingestable kinds to their target table", () => {
|
||||
expect(ingestTable("GoldenFingerResult")).toBe("world_entities");
|
||||
expect(ingestTable("GlossaryResult")).toBe("world_entities");
|
||||
expect(ingestTable("DetailedOutlineResult")).toBe("outline");
|
||||
expect(ingestTable("BookTeardownResult")).toBe("rules");
|
||||
});
|
||||
|
||||
it("returns null for non-ingestable kinds", () => {
|
||||
@@ -15,6 +20,18 @@ describe("ingestTable", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("isSingleObjectIngest", () => {
|
||||
it("flags teardown as single-object ingest", () => {
|
||||
expect(isSingleObjectIngest("BookTeardownResult")).toBe(true);
|
||||
});
|
||||
|
||||
it("treats row-based kinds as not single-object", () => {
|
||||
expect(isSingleObjectIngest("GoldenFingerResult")).toBe(false);
|
||||
expect(isSingleObjectIngest("DetailedOutlineResult")).toBe(false);
|
||||
expect(isSingleObjectIngest("unknown")).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("buildIngestRequest", () => {
|
||||
it("maps golden finger rows into world_entities with merged rules", () => {
|
||||
const body = buildIngestRequest({
|
||||
@@ -81,6 +98,36 @@ describe("buildIngestRequest", () => {
|
||||
expect(body?.acknowledge_conflicts).toBe(false);
|
||||
});
|
||||
|
||||
it("maps teardown single object to a teardown body", () => {
|
||||
const body = buildIngestRequest({
|
||||
outputKind: "BookTeardownResult",
|
||||
rows: [
|
||||
{
|
||||
themes: ["逆袭", "成长"],
|
||||
archetypes: ["废柴主角"],
|
||||
structure: "三幕式",
|
||||
hooks: ["开局打脸"],
|
||||
},
|
||||
],
|
||||
acknowledgeConflicts: true,
|
||||
});
|
||||
expect(body).toEqual({
|
||||
teardown: {
|
||||
themes: ["逆袭", "成长"],
|
||||
archetypes: ["废柴主角"],
|
||||
structure: "三幕式",
|
||||
hooks: ["开局打脸"],
|
||||
},
|
||||
acknowledge_conflicts: true,
|
||||
});
|
||||
});
|
||||
|
||||
it("returns null for teardown with no rows", () => {
|
||||
expect(
|
||||
buildIngestRequest({ outputKind: "BookTeardownResult", rows: [] }),
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
it("returns null for non-ingestable output kind", () => {
|
||||
expect(
|
||||
buildIngestRequest({ outputKind: "IdeaListResult", rows: [] }),
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
import type {
|
||||
OutlineSceneIngestView,
|
||||
TeardownIngestView,
|
||||
ToolIngestRequest,
|
||||
WorldEntityCardView,
|
||||
} from "@/lib/api/types";
|
||||
@@ -63,6 +64,17 @@ function rowToScene(
|
||||
};
|
||||
}
|
||||
|
||||
// 拆书结构化产物 → TeardownIngestView(贴后端 schema;后端再拍平为可读 rules 条目)。
|
||||
// 单对象产物:整个 preview 对象即一条入库项(无逐行勾选)。
|
||||
function rowToTeardown(row: Record<string, unknown>): TeardownIngestView {
|
||||
return {
|
||||
themes: asStringArray(row["themes"]),
|
||||
archetypes: asStringArray(row["archetypes"]),
|
||||
structure: asString(row["structure"]),
|
||||
hooks: asStringArray(row["hooks"]),
|
||||
};
|
||||
}
|
||||
|
||||
export interface IngestBuildInput {
|
||||
outputKind: string;
|
||||
// 作者勾选要入库的预览行(结构化产物原始记录)。
|
||||
@@ -72,6 +84,15 @@ export interface IngestBuildInput {
|
||||
acknowledgeConflicts?: boolean;
|
||||
}
|
||||
|
||||
// 单对象入库的 output_kind:整个 preview 即一条入库项(无逐行勾选)。
|
||||
// 当前仅拆书(结构化结论拍平为 rules)。行式产物(金手指/词条/细纲)不在此列。
|
||||
const SINGLE_OBJECT_INGEST_KINDS = new Set(["BookTeardownResult"]);
|
||||
|
||||
// 该产物是否「单对象入库」(UI 据此隐藏勾选框、改文案、用整个 rawPreview 作唯一行)。
|
||||
export function isSingleObjectIngest(outputKind: string): boolean {
|
||||
return SINGLE_OBJECT_INGEST_KINDS.has(outputKind);
|
||||
}
|
||||
|
||||
// 入库目标表(供 UI 文案 / 判定)。未知 → null(不可入库)。
|
||||
export function ingestTable(outputKind: string): string | null {
|
||||
switch (outputKind) {
|
||||
@@ -80,6 +101,8 @@ export function ingestTable(outputKind: string): string | null {
|
||||
return "world_entities";
|
||||
case "DetailedOutlineResult":
|
||||
return "outline";
|
||||
case "BookTeardownResult":
|
||||
return "rules";
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
@@ -107,6 +130,12 @@ export function buildIngestRequest(
|
||||
scenes: input.rows.map((row, i) => rowToScene(row, i)),
|
||||
acknowledge_conflicts,
|
||||
};
|
||||
case "BookTeardownResult": {
|
||||
// 单对象产物:取首行(整个拆书结论)作 teardown;无产物 → null。
|
||||
const row = input.rows[0];
|
||||
if (!row) return null;
|
||||
return { teardown: rowToTeardown(row), acknowledge_conflicts };
|
||||
}
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
missingRequiredFields,
|
||||
previewRows,
|
||||
resolveLegacyRoute,
|
||||
templateFillTarget,
|
||||
} from "./toolbox";
|
||||
|
||||
const field = (over: Partial<ToolInputFieldView> = {}): ToolInputFieldView => ({
|
||||
@@ -210,3 +211,20 @@ describe("isLegacyTool", () => {
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("templateFillTarget", () => {
|
||||
it("prefers brief when present", () => {
|
||||
expect(
|
||||
templateFillTarget([field({ name: "brief" }), field({ name: "text" })]),
|
||||
).toBe("brief");
|
||||
});
|
||||
|
||||
it("falls back to text when brief absent", () => {
|
||||
expect(templateFillTarget([field({ name: "text" })])).toBe("text");
|
||||
});
|
||||
|
||||
it("returns null when no fillable field exists", () => {
|
||||
expect(templateFillTarget([field({ name: "count" })])).toBeNull();
|
||||
expect(templateFillTarget(undefined)).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -292,6 +292,21 @@ function fallbackItem(row: Record<string, unknown>): PreviewItem {
|
||||
return { heading, fields, body: null };
|
||||
}
|
||||
|
||||
// —— 模板填入目标 ——
|
||||
// 模板 body 一键填入的目标输入字段:优先 brief(多数生成器主输入),否则 text(原文输入类)。
|
||||
// 都没有则 null(不渲染「从模板填入」)。F3:纯前端,不改生成器后端。
|
||||
const TEMPLATE_FILL_FIELDS = ["brief", "text"] as const;
|
||||
|
||||
export function templateFillTarget(
|
||||
fields: readonly ToolInputFieldView[] | undefined,
|
||||
): string | null {
|
||||
const names = new Set((fields ?? []).map((f) => f.name));
|
||||
for (const candidate of TEMPLATE_FILL_FIELDS) {
|
||||
if (names.has(candidate)) return candidate;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// —— legacy 路由解析 ——
|
||||
// legacy 工具的 legacy_route 含 {id} 占位(如 /projects/{id}/codex?gen=world)→ 替换为真实 projectId。
|
||||
export function resolveLegacyRoute(
|
||||
|
||||
Reference in New Issue
Block a user