컴퓨터 플레이어 + GPU 로컬 모델(gemma3:4b): 생각 중/입력 중 표시, 성격대로 채팅·도발·심리전, 바퀴벌레 포커 블러핑, 마피아 대사

- ai/llm.ts: Ollama 클라이언트(동시 2개·대기열·시간 제한·연속 실패 시 쉬기), 꺼져 있으면 예전처럼 조용히 둔다
- ai/lines.ts: 성격 5가지(도발·허세·차분·수다·소심)×말투(존댓말/반말), 한 줄 정리(외국어·AI 말·욕·링크 거르기)
- ai/brain.ts: 수 두기 전 생각 중… → 가끔 입력 중…(타자 시간) → 채팅 → 수, 사람 수에 반응, 이름 부르면 대답, 시작·끝 한마디
  바퀴벌레 포커: 진실/블러핑과 건네는 말을 모델이 정함. 마피아: 계획한 대사를 모델이 자기 말로(직업 주장은 버림)
- RoomView.botActivity + 화면 표시(상태 줄, 채팅 칸), AI_URL/AI_MODEL 설정, /healthz에 ai 통계
- 테스트: 클라이언트·정리·방 동작(가짜 모델), 실제 GPU 모델 브라우저 E2E(e2e/ai.e2e.ts)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-11 03:37:04 +09:00
parent 65a0f34d93
commit 13974181e7
17 changed files with 1030 additions and 5 deletions

View File

@@ -44,6 +44,11 @@ export interface LiveBotDecision<A = any> {
action: A | null;
/** Ask again after this many ms. */
next: number;
/**
* For a chat line: what it means, so a language model may say it in the computer's own words (the action's text is
* the built-in wording, used when no model is available).
*/
hint?: string;
}
export type LiveBotStrategy<V = any, A = any> = (input: LiveBotInput<V>) => LiveBotDecision<A>;

View File

@@ -98,6 +98,31 @@ const L = {
};
type LineKey = keyof typeof L;
/**
* What a line means, for a language model to say it in its own words (docs/games/mafia.md §13). Lines that carry
* exact information (police results, role claims, mafia-chat plans) are not listed: they are always said as written.
*/
const HINT: Partial<Record<LineKey, string>> = {
greet: '게임을 시작하며 인사',
died: '밤사이 {V}이(가) 마피아에게 당한 것에 대한 반응',
healed: '의사가 살려서 밤에 아무도 안 죽은 것에 대한 반응',
soldier: '{V}이(가) 군인이라 공격을 버틴 것에 대한 반응',
quiet: '조용한 밤이었다는 반응',
accuse: '{X}이(가) 마피아 같다고 의심하며 지목',
unsure: '아직 누가 마피아인지 모르겠다며 다른 사람 의견을 묻기',
agree: '{X}이(가) 수상하다는 의견에 동의',
disagree: '{X}은(는) 마피아가 아닌 것 같다고 반박하고 차라리 {Y}을(를) 의심',
defend: '자신은 시민이라며 억울함을 호소하고 {Y}을(를) 의심해 보라고 하기',
role: '직업을 묻는 질문에 시민이라고 대답',
called: '이름이 불려서 짧게 반응',
copHeard: '경찰이라고 밝힌 사람의 말에 반응',
voted: '{X}에게 투표했다고 말하기',
yes: '처형에 찬성한다고 말하기',
no: '아직 확실하지 않아 처형에 반대한다고 말하기',
filler: '분위기를 띄우는 짧은 잡담',
dead: '탈락한 뒤 남은 사람들에게 한마디',
};
// ---------------------------------------------------------------- reading the chat
const ACCUSE = /마피아|마피|수상|의심|범인|찍|투표|죽이|처형|거짓|가짜|너지|이상|맞는|맞음|맞아/;
@@ -243,10 +268,15 @@ class MafiaBot {
return m ? `${m[1]}번` : n;
}
/** The meaning of the last line made (for the language model), or null for exact-information lines. */
lastHint: string | null = null;
/** A line of this character; skips ones it already said and ones just said by others (people don't echo). */
private line(key: LineKey, salt: string | number, vars?: Record<string, string>): string;
private line(key: LineKey, salt: string | number, vars: Record<string, string>, optional: true): string | null;
private line(key: LineKey, salt: string | number, vars: Record<string, string> = {}, optional = false): string | null {
const h = HINT[key];
this.lastHint = h ? fill(h, { ...vars, R: '' }) + (key === 'accuse' && vars.R ? ` (이유:${vars.R})` : '') : null;
const set = L[key];
const pool = this.smart ? set.smart : set.dumb;
const used = new Set([
@@ -725,8 +755,12 @@ export function mafiaBot(input: In): LiveBotDecision<MafiaAction> {
continue;
}
done[it.key] = true;
bot.lastHint = null;
const action = it.make();
if (action) return { action, next: Math.round(400 + 600 * input.persona.pace) };
if (action) {
const hint = action.type === 'chat' && (action.channel === 'day' || action.channel === 'dead') ? bot.lastHint : null;
return { action, next: Math.round(400 + 600 * input.persona.pace), ...(hint ? { hint } : {}) };
}
}
const idle = v.my.alive ? 1500 : 4000;
const wait = soonest === Infinity ? idle : soonest - input.now;

View File

@@ -56,6 +56,8 @@ export interface RoomView {
lastSeed: string | null;
/** The game that just ended (for 다시 보기), null while playing or before the first game. */
lastGamePk: string | null;
/** Computers doing something people can see (docs/06 §12.1): "생각 중…" / "입력 중…". */
botActivity?: Record<string, 'thinking' | 'typing'>;
}
export interface GameResultView {