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
@@ -6,6 +6,8 @@ export interface RetrieveOptions {
|
||||
limit?: number;
|
||||
// E-5 關係加權檢索接點:與此使用者相關的記憶會被加權排到前面。
|
||||
relatedUserId?: string;
|
||||
// K-3 隱私邊界:群聊等有旁人在場的情境傳 true,標記為私密的記憶不會被檢索到。
|
||||
excludePrivate?: boolean;
|
||||
}
|
||||
|
||||
export interface MemoryRetriever {
|
||||
@@ -37,7 +39,9 @@ export class KeywordMemoryRetriever implements MemoryRetriever {
|
||||
|
||||
async retrieve(characterId: string, query: string, options: RetrieveOptions = {}): Promise<EpisodicMemory[]> {
|
||||
const limit = options.limit ?? DEFAULT_LIMIT;
|
||||
const rows = await this.prisma.client.episodicMemory.findMany({ where: { characterId } });
|
||||
const rows = await this.prisma.client.episodicMemory.findMany({
|
||||
where: { characterId, ...(options.excludePrivate ? { isPrivate: false } : {}) },
|
||||
});
|
||||
const now = Date.now();
|
||||
const keywords = query.split(/\s+/).filter(Boolean);
|
||||
|
||||
@@ -76,6 +80,7 @@ export class KeywordMemoryRetriever implements MemoryRetriever {
|
||||
lastRetrievedAt: new Date(now).toISOString(),
|
||||
source: row.source,
|
||||
weight: row.weight,
|
||||
isPrivate: row.isPrivate,
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,10 +55,12 @@ export class MemoryController {
|
||||
@Query("query") query: string,
|
||||
@Query("limit") limit?: string,
|
||||
@Query("relatedUserId") relatedUserId?: string,
|
||||
@Query("excludePrivate") excludePrivate?: string,
|
||||
) {
|
||||
const results = await this.retriever.retrieve(characterId, query ?? "", {
|
||||
limit: limit ? Number(limit) : undefined,
|
||||
relatedUserId,
|
||||
excludePrivate: excludePrivate === "true",
|
||||
});
|
||||
return { results };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user