feat: 完成 K 群組 — 對話模式:群聊與角色自聊
群聊/自聊子系統(apps/api/src/room/):在場者名冊與共用場景記錄(純記憶體, 同 C-1 工作記憶的設計)、發言權分配(點名/話題相關度/性格基線/情緒/角色間 關係/發言冷卻與冷落累積算衝動值)、群聊矜持(重用 G-3 親密度分層模板、 下修有效親密度而非另建模板庫)、隱私邊界(EpisodicMemory.isPrivate + KeywordMemoryRetriever.excludePrivate,天然呆為口風不緊例外)、群聊記憶 投影(各角色依自身視角固化,被虧的那位權重較高)、角色自聊(沿用發言權 機制、空轉偵測注入轉折或收尾、輪數硬上限、使用者插話切換群聊)。 新增 CharacterRelationship 表供角色間關係使用。 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
3503cc0be6
commit
6125d6e27f
@@ -0,0 +1,25 @@
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { PrismaService } from "../prisma/prisma.service.js";
|
||||
|
||||
// K-2/K-4 角色間關係:同作品角色互損、拆台、護短、吃醋等化學反應的資料來源。
|
||||
// 有向邊:characterId 對 otherCharacterId 的觀感,兩邊可以各自設定、不必對稱。
|
||||
@Injectable()
|
||||
export class CharacterRelationshipService {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
async set(characterId: string, otherCharacterId: string, affinity: number, dynamic?: string) {
|
||||
return this.prisma.client.characterRelationship.upsert({
|
||||
where: { characterId_otherCharacterId: { characterId, otherCharacterId } },
|
||||
update: { affinity, dynamic },
|
||||
create: { characterId, otherCharacterId, affinity, dynamic },
|
||||
});
|
||||
}
|
||||
|
||||
// 未設定關係時,回傳中性值(50)——同作品角色預設不特別親近也不特別有心結。
|
||||
async getAffinity(characterId: string, otherCharacterId: string): Promise<number> {
|
||||
const row = await this.prisma.client.characterRelationship.findUnique({
|
||||
where: { characterId_otherCharacterId: { characterId, otherCharacterId } },
|
||||
});
|
||||
return row?.affinity ?? 50;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user