범인찾기 v1.3.2: 외부 전적 사이트 접속 제거 — OP.GG · LOL.PS 는 계산법만 참고

- 사용자 결정: 실제 OP.GG 연결이 아니라 계산법 참고 → 분석 때 OP.GG 를 찾아보던 opgg.ts · 결과의 OP.GG 점수 · 조회 상태 · 지시문 줄 · Riot 태그/경기 찾기 정보 제거
- 남은 것: 기록 점수(OP.GG OP스코어 계산법, 앱이 경기 기록으로 계산) · 10/15분 라인전(LOL.PS 정의)
- 실제 E2E (Claude Opus 5.5 high, 외부 접속 없음): 발로란트 33초 $0.138, 롤 36초 $0.123
- 테스트: 앱 40 · 서버 16 통과

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-15 16:11:53 +09:00
parent 2ddba2e4e5
commit b8e76aba25
17 changed files with 88 additions and 600 deletions

View File

@@ -14,7 +14,6 @@ import {
} from '@gvr/shared';
import { CULPRIT_DEFAULTS, type Config } from './config.js';
import { buildSystemPrompt, KnowledgeAuto, outputSchema } from './culprit-prompt.js';
import { lookupOpgg, opggCaller, opggLines, type ToolCaller } from './opgg.js';
import type { RelayHub } from './relay.js';
import type { ServerStore, Session } from './store.js';
@@ -255,8 +254,6 @@ export interface CulpritOptions {
log: { info: (o: any, m?: string) => void; warn: (o: any, m?: string) => void; error: (o: any, m?: string) => void };
call?: ModelCall;
knowledge?: KnowledgeAuto;
/** OP.GG 실제 점수 찾기 (테스트에서 바꿔 끼운다, null = 끔) */
opgg?: ToolCaller | null;
}
export function registerCulprit(app: FastifyInstance, o: CulpritOptions) {
@@ -265,7 +262,6 @@ export function registerCulprit(app: FastifyInstance, o: CulpritOptions) {
const ledger = new Ledger(cfg.dataDir);
const call: ModelCall | null = o.call ?? (c.apiKey ? anthropicCall(c.apiKey) : null);
const knowledge = o.knowledge ?? new KnowledgeAuto(undefined, log);
const opgg: ToolCaller | null = o.opgg !== undefined ? o.opgg : c.opgg === false ? null : opggCaller();
const running = new Map<string, { by: string; at: number; stage: CulpritStage }>();
/** (가) 등록된 앱 유저 이상만 분석 버튼, 다시 분석은 관리자 이상 (사용자 결정 ②) */
@@ -352,27 +348,17 @@ export function registerCulprit(app: FastifyInstance, o: CulpritOptions) {
log.error(e, '범인찾기 자료 받기 실패');
return reply.code(502).send({ error: 'input_failed' });
}
publish(matchId, 'thinking');
void run(matchId, input, { id: s.user.id, name: s.user.name }).finally(() => running.delete(matchId));
return reply.code(202).send({ ok: true });
});
/** AI 분석 (버튼 응답 뒤에 돈다. 창을 닫아도 계속, 끝나면 실시간 알림) */
async function run(matchId: string, raw: CulpritInput, by: { id: string; name: string }): Promise<void> {
async function run(matchId: string, input: CulpritInput, by: { id: string; name: string }): Promise<void> {
const started = Date.now();
const usages: Usage[] = [];
let fallback = false;
try {
// 전적 사이트 점수: 이 경기가 OP.GG 에 있으면 실제 OP스코어를 자료에 붙인다 (없거나 실패해도 기록 점수로 계속)
let opggMeta: { found: boolean; error?: boolean; note?: string } | undefined;
let input = raw;
if (opgg && raw.lookup) {
publish(matchId, 'collect', 'OP.GG 점수 찾는 중');
const r = await lookupOpgg(raw, opgg).catch((e) => ({ scores: new Map(), found: false, error: true, note: `OP.GG 연결 실패 (${String(e?.message ?? e).slice(0, 80)})` }));
opggMeta = { found: r.found, ...(r.error ? { error: true } : {}), ...(r.note ? { note: r.note } : {}) };
input = withOpgg(raw, r);
log.info({ matchId, opgg: opggMeta, n: r.scores.size }, '범인찾기 OP.GG 점수');
}
publish(matchId, 'thinking');
const system = buildSystemPrompt(input.game, c.tone, await knowledge.get(input.game));
const schema = outputSchema();
const user = `<match>\n${input.text}\n</match>`;
@@ -413,7 +399,7 @@ export function registerCulprit(app: FastifyInstance, o: CulpritOptions) {
players: input.players,
model: usages.at(-1)?.model ?? c.model,
createdBy: by,
meta: { tone: c.tone, durationMs: Date.now() - started, costUsd: totalCost, usage: sumUsage(usages), inputStats: input.stats, fallback, ...(opggMeta ? { opgg: opggMeta } : {}) },
meta: { tone: c.tone, durationMs: Date.now() - started, costUsd: totalCost, usage: sumUsage(usages), inputStats: input.stats, fallback },
},
60000,
);
@@ -435,20 +421,6 @@ export function registerCulprit(app: FastifyInstance, o: CulpritOptions) {
return { budget, ledger, running };
}
/** OP.GG 점수를 자료(시간 순서 기록 앞)와 참가자에 붙인다 */
export function withOpgg(input: CulpritInput, r: Awaited<ReturnType<typeof lookupOpgg>>): CulpritInput {
const lines = opggLines(input, r);
if (!lines.length) return input;
const text = input.text.split('\n');
const at = text.indexOf('# 시간 순서 기록');
text.splice(at < 0 ? text.length : at, 0, ...lines);
return {
...input,
text: text.join('\n'),
players: input.players.map((p) => (r.scores.has(p.id) ? { ...p, opgg: r.scores.get(p.id)! } : p)),
};
}
function sumUsage(us: Usage[]) {
return us.reduce((a, u) => ({ input: a.input + u.input, output: a.output + u.output, cacheRead: a.cacheRead + u.cacheRead, cacheWrite: a.cacheWrite + u.cacheWrite }), { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 });
}