feat(web): 角色群像按定位配比生成(role_mix 缩减版)
- 契约: CharacterGenerateRequest 加 role_mix{定位:数量},model_validator 归一
count=各值之和(每项≥1、总和≤12),缺省退回单一 role+count
- @llm: build_character_gen_context/run_character_gen 加 role_mix 参并注入配比块
(确定性、无时间戳,守 assemble 纯函数);router 穿参
- character-gen.md 加"按配比严格分配 role"纪律 + regen prompt_hashes 金标准
- 前端: sanitizeRoleMix/roleMixTotal + buildCharacterGenerateRequest 第4参 +
useCharacterGen 穿参 + RoleMixEditor + CharacterGenerator 单一/配比双模
This commit is contained in:
@@ -16,6 +16,8 @@ import {
|
||||
mergeCharacterCards,
|
||||
mergeWorldEntities,
|
||||
MIN_CHARACTER_COUNT,
|
||||
roleMixTotal,
|
||||
sanitizeRoleMix,
|
||||
updateCard,
|
||||
worldEntityRules,
|
||||
} from "./cards";
|
||||
@@ -62,6 +64,62 @@ describe("buildCharacterGenerateRequest", () => {
|
||||
role: "对手",
|
||||
});
|
||||
});
|
||||
|
||||
it("uses role_mix (count=sum, no single role) when a mix is supplied", () => {
|
||||
expect(
|
||||
buildCharacterGenerateRequest("群像", 1, "忽略", {
|
||||
主角: 1,
|
||||
对手: 2,
|
||||
配角: 3,
|
||||
}),
|
||||
).toEqual({
|
||||
brief: "群像",
|
||||
count: 6,
|
||||
role_mix: { 主角: 1, 对手: 2, 配角: 3 },
|
||||
});
|
||||
});
|
||||
|
||||
it("falls back to count/role when role_mix is empty", () => {
|
||||
expect(buildCharacterGenerateRequest("群像", 4, "主角", {})).toEqual({
|
||||
brief: "群像",
|
||||
count: 4,
|
||||
role: "主角",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("sanitizeRoleMix", () => {
|
||||
it("trims roles, drops blanks, clamps counts to >=1, dedups", () => {
|
||||
expect(
|
||||
sanitizeRoleMix([
|
||||
{ role: " 主角 ", count: 2 },
|
||||
{ role: "", count: 3 }, // 空定位丢弃
|
||||
{ role: "对手", count: 0 }, // clamp 到 1
|
||||
{ role: "主角", count: 5 }, // 重复定位丢弃(先到先得)
|
||||
]),
|
||||
).toEqual({ 主角: 2, 对手: 1 });
|
||||
});
|
||||
|
||||
it("caps the running total at MAX_CHARACTER_COUNT", () => {
|
||||
const out = sanitizeRoleMix([
|
||||
{ role: "主角", count: 10 },
|
||||
{ role: "对手", count: 5 }, // 只剩 2 额度
|
||||
{ role: "配角", count: 3 }, // 无额度,丢弃
|
||||
]);
|
||||
expect(out).toEqual({ 主角: 10, 对手: 2 });
|
||||
expect(roleMixTotal(out)).toBe(MAX_CHARACTER_COUNT);
|
||||
});
|
||||
|
||||
it("returns empty object when no valid rows", () => {
|
||||
expect(sanitizeRoleMix([{ role: " ", count: 3 }])).toEqual({});
|
||||
});
|
||||
});
|
||||
|
||||
describe("roleMixTotal", () => {
|
||||
it("sums counts", () => {
|
||||
expect(roleMixTotal({ 主角: 1, 对手: 2 })).toBe(3);
|
||||
expect(roleMixTotal({})).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("buildCharacterIngestRequest", () => {
|
||||
|
||||
Reference in New Issue
Block a user