feat: 完成 B 群組 — 資料層與核心領域模型

- 導入 Prisma 7.9.1 + SQLite(better-sqlite3 driver adapter),prisma.config.ts 管理連線設定
- 完整資料模型:User/Work/Character/CharacterAlias/EpisodicMemory/SemanticMemory/
  ProceduralRule/EmotionState/Relationship/SentimentLedgerEntry
- packages/db:Prisma Client 存取層(ESM,因 Prisma 7 產出的 generated client 僅支援 ESM)
- apps/api 隨之改為 ESM 以相容 packages/db
- packages/shared:新增角色/記憶/情緒/關係共用型別,api 與 web 皆從此匯入
- prisma/seed.ts:建立測試使用者與元氣型測試角色,含完整關係帳本與記憶種子資料
- apps/api:新增 GET /characters
- scripts/smoke/B.mjs:驗證資料表齊全、API 讀出種子角色、關係與記憶可寫入讀出
- 保留 Prisma 官方隨 CLI 附的 agent skill 文件(.agents/skills 等),供後續群組查閱

npm run restart && npm run smoke -- B 皆通過(B-V),A 群組冒煙測試無回歸。
This commit is contained in:
Jeffery
2026-08-13 09:43:15 +08:00
parent ae9c44dde7
commit f44200f543
124 changed files with 13566 additions and 48 deletions
+27
View File
@@ -0,0 +1,27 @@
export type CharacterSource = "ORIGINAL" | "EXISTING_WORK";
export type CharacterBuildStatus = "CANDIDATE" | "BUILT";
export interface CharacterAlias {
id: string;
formalName: string;
nickname?: string | null;
calledByOthers?: string | null;
}
// 角色設定表七欄位 + 來源/建置狀態
export interface Character {
id: string;
workId?: string | null;
source: CharacterSource;
buildStatus: CharacterBuildStatus;
basicInfo: string;
backgroundStory: string;
personalityArchetype: string;
likesDislikes: string;
goalsObsessions: string;
speechStyle: string;
initialRelationValue?: string | null;
createdAt: string;
updatedAt: string;
aliases?: CharacterAlias[];
}
+10
View File
@@ -0,0 +1,10 @@
export interface EmotionState {
characterId: string;
calm: number; // 平靜
joy: number; // 愉悅
sad: number; // 低落
alert: number; // 警戒
shy: number; // 害羞
grumpy: number; // 彆扭
updatedAt: string;
}
+31
View File
@@ -0,0 +1,31 @@
// 情緒標籤類型:對應情緒子系統六種狀態(見 D 群組)
export type EmotionTag = "CALM" | "JOY" | "SAD" | "ALERT" | "SHY" | "GRUMPY";
export type MemorySource = "INTERACTION" | "OFFLINE_GENERATED" | "SOURCE_EXTRACTION";
export interface EpisodicMemory {
id: string;
characterId: string;
content: string;
occurredAt: string;
emotionTag: EmotionTag;
emotionIntensity: number;
retrievalCount: number;
lastRetrievedAt?: string | null;
source: MemorySource;
weight: number;
}
export interface SemanticMemory {
id: string;
characterId: string;
fact: string;
about: string;
}
export interface ProceduralRule {
id: string;
characterId: string;
situation: string;
responsePattern: string;
weight: number;
}
@@ -0,0 +1,26 @@
export type RelationshipStage =
| "STRANGER" // 陌生 0-19
| "ACQUAINTANCE" // 認識 20-39
| "FRIEND" // 朋友 40-59
| "CLOSE_AMBIGUOUS" // 摯友-曖昧 60-79
| "BONDED"; // 羈絆 80-100
export interface SentimentLedgerEntry {
id: string;
date: string;
event: string;
weight: number; // 允許正負
}
export interface Relationship {
id: string;
characterId: string;
userId: string;
intimacy: number; // 0~100
trust: number; // 0~100
firstMet?: string | null;
lastInteraction?: string | null;
interactionCount: number;
stage: RelationshipStage;
ledgerEntries?: SentimentLedgerEntry[];
}
+4
View File
@@ -1,2 +1,6 @@
export * from "./result.js";
export * from "./log.js";
export * from "./domain/character.js";
export * from "./domain/memory.js";
export * from "./domain/emotion.js";
export * from "./domain/relationship.js";