M5: 포터블 exe 앱 (트레이·설정 창·첫 실행 마법사) + M6 사전 기능
- app/src/main: Electron 메인(트레이 상태 아이콘, 설정 창, 단일 실행, DPAPI safeStorage, 스모크 모드), IPC(window.gvr), 파인튜닝 관리 - app/src/renderer: 설정 8개 탭 + 5단계 첫 실행 마법사 (React) - electron-builder: GameVoiceRecorder.exe, zip(폴더 포터블) + 단일 exe 포터블, 워커·리소스 포함 - 사전: 사이트에서 단어·교정 규칙 추가/삭제(/api/dictionary), 게임 패치 이름 자동 추가, 묶음별 중복 허용 + DB 마이그레이션 - 사이트 서버: 종료 시 WebSocket 먼저 끊기(재시작 멈춤 수정) + 재연결 테스트 - scripts/finetune-e2e.mts, stt-eval.mts Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -210,9 +210,45 @@ export async function buildApi(d: ApiDeps): Promise<FastifyInstance> {
|
||||
return item;
|
||||
});
|
||||
|
||||
// 사이트에서 단어·교정 규칙 추가/삭제 (보고서 5-4: 사이트·설정에서 직접 추가·수정)
|
||||
app.post<{ Body: { word?: string; from?: string; to?: string } }>('/api/dictionary', async (req, reply) => {
|
||||
const b = req.body || {};
|
||||
const clean = (x: unknown) => String(x ?? '').trim().slice(0, 40);
|
||||
if (b.from !== undefined || b.to !== undefined) {
|
||||
const from = clean(b.from);
|
||||
const to = clean(b.to);
|
||||
if (!from || !to || from === to) return reply.code(400).send({ error: 'bad_rule' });
|
||||
store.addDict({ word: to, pack: 'site', kind: 'correction', from_text: from, source: 'site' });
|
||||
} else {
|
||||
const word = clean(b.word);
|
||||
if (!word) return reply.code(400).send({ error: 'empty_word' });
|
||||
store.addDict({ word, pack: 'site', kind: 'hotword', from_text: '', source: 'site' });
|
||||
}
|
||||
d.dict.invalidate();
|
||||
return { ok: true };
|
||||
});
|
||||
app.delete<{ Params: { id: string } }>('/api/dictionary/:id', async (req, reply) => {
|
||||
const row = store.listDict().find((r) => r.id === Number(req.params.id));
|
||||
if (!row) return reply.code(404).send({ error: 'not_found' });
|
||||
// 기본 사전은 사이트에서 지우지 않는다 (설정 창에서 끄기만)
|
||||
if (row.source === 'builtin') return reply.code(403).send({ error: 'builtin' });
|
||||
store.deleteDict(row.id);
|
||||
d.dict.invalidate();
|
||||
return { ok: true };
|
||||
});
|
||||
|
||||
app.get('/api/dictionary', async () => ({
|
||||
labels: d.dict.labels,
|
||||
entries: store.listDict().filter((r) => r.source !== 'builtin' || r.kind === 'correction').map((r) => ({ id: r.id, word: r.word, from: r.from_text || null, kind: r.kind, pack: r.pack, source: r.source, enabled: !!r.enabled })),
|
||||
entries: store
|
||||
.listDict()
|
||||
.filter((r) => r.source !== 'builtin' || r.kind === 'correction')
|
||||
.map((r) => ({ id: r.id, word: r.word, from: r.from_text || null, kind: r.kind, pack: r.pack, source: r.source, enabled: !!r.enabled, hits: r.hits })),
|
||||
packs: Object.entries(
|
||||
store.listDict().reduce<Record<string, number>>((m, r) => {
|
||||
if (r.kind === 'hotword' && r.source === 'builtin') m[r.pack] = (m[r.pack] || 0) + 1;
|
||||
return m;
|
||||
}, {}),
|
||||
).map(([key, count]) => ({ key, label: d.dict.labels[key] ?? key, count })),
|
||||
}));
|
||||
|
||||
return app;
|
||||
|
||||
@@ -94,6 +94,23 @@ export class Store {
|
||||
fs.mkdirSync(path.dirname(file), { recursive: true });
|
||||
this.db = new Database(file);
|
||||
this.db.exec(SCHEMA_SQL);
|
||||
this.migrate();
|
||||
}
|
||||
|
||||
/** 예전 DB 를 지금 스키마로 맞춘다 (스키마를 바꿀 때마다 여기에 단계 추가) */
|
||||
private migrate(): void {
|
||||
// v1.0 개발 중: dictionary UNIQUE 에 pack 추가 (같은 단어가 여러 묶음에 들어갈 수 있게)
|
||||
const idx = this.db.prepare(`SELECT sql FROM sqlite_master WHERE type='table' AND name='dictionary'`).get() as { sql: string } | undefined;
|
||||
if (idx && !/UNIQUE\s*\(kind,\s*word,\s*from_text,\s*pack\)/.test(idx.sql)) {
|
||||
this.db.exec(`
|
||||
BEGIN;
|
||||
ALTER TABLE dictionary RENAME TO dictionary_old;
|
||||
${SCHEMA_SQL.slice(SCHEMA_SQL.indexOf('CREATE TABLE IF NOT EXISTS dictionary'), SCHEMA_SQL.indexOf(');', SCHEMA_SQL.indexOf('CREATE TABLE IF NOT EXISTS dictionary')) + 2)}
|
||||
INSERT OR IGNORE INTO dictionary(id,word,pack,kind,from_text,source,enabled,hits,created_at)
|
||||
SELECT id,word,pack,kind,from_text,source,enabled,hits,created_at FROM dictionary_old;
|
||||
DROP TABLE dictionary_old;
|
||||
COMMIT;`);
|
||||
}
|
||||
}
|
||||
|
||||
close(): void {
|
||||
@@ -344,7 +361,7 @@ export class Store {
|
||||
this.db
|
||||
.prepare(
|
||||
`INSERT INTO dictionary(word,pack,kind,from_text,source,enabled,created_at) VALUES(?,?,?,?,?,?,?)
|
||||
ON CONFLICT(kind,word,from_text) DO UPDATE SET pack=excluded.pack, enabled=excluded.enabled`,
|
||||
ON CONFLICT(kind,word,from_text,pack) DO UPDATE SET enabled=excluded.enabled`,
|
||||
)
|
||||
.run(d.word, d.pack, d.kind, d.from_text ?? '', d.source, d.enabled ?? 1, Date.now());
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ CREATE TABLE IF NOT EXISTS dictionary (
|
||||
enabled INTEGER NOT NULL DEFAULT 1,
|
||||
hits INTEGER NOT NULL DEFAULT 0,
|
||||
created_at INTEGER NOT NULL,
|
||||
UNIQUE (kind, word, from_text)
|
||||
UNIQUE (kind, word, from_text, pack)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS training_samples (
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
// 자동 생성: schema.sql 사본 (npm run build 가 다시 만든다)
|
||||
export const SCHEMA_SQL = "PRAGMA journal_mode = WAL;\nPRAGMA foreign_keys = ON;\n\nCREATE TABLE IF NOT EXISTS meta (key TEXT PRIMARY KEY, value TEXT);\n\nCREATE TABLE IF NOT EXISTS users (\n id TEXT PRIMARY KEY,\n name TEXT NOT NULL,\n color TEXT NOT NULL,\n avatar TEXT,\n excluded INTEGER NOT NULL DEFAULT 0,\n gain_lufs REAL,\n gain_n INTEGER NOT NULL DEFAULT 0,\n updated_at INTEGER NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS game_accounts (\n user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,\n puuid TEXT NOT NULL,\n riot_id TEXT NOT NULL,\n PRIMARY KEY (user_id, puuid)\n);\nCREATE INDEX IF NOT EXISTS game_accounts_puuid ON game_accounts(puuid);\n\nCREATE TABLE IF NOT EXISTS sessions (\n id TEXT PRIMARY KEY,\n guild_id TEXT NOT NULL,\n channel_id TEXT NOT NULL,\n channel_name TEXT,\n started_at INTEGER NOT NULL,\n ended_at INTEGER\n);\n\nCREATE TABLE IF NOT EXISTS utterances (\n id TEXT PRIMARY KEY,\n session_id TEXT,\n user_id TEXT NOT NULL,\n started_at INTEGER NOT NULL,\n ended_at INTEGER NOT NULL,\n audio_path TEXT,\n audio_deleted INTEGER NOT NULL DEFAULT 0,\n text TEXT,\n raw_text TEXT,\n words TEXT NOT NULL DEFAULT '[]',\n noise INTEGER NOT NULL DEFAULT 0,\n noise_reason TEXT,\n confidence REAL,\n lufs REAL,\n gain_db REAL NOT NULL DEFAULT 0,\n model TEXT,\n status TEXT NOT NULL DEFAULT 'pending',\n match_id TEXT,\n corrected INTEGER NOT NULL DEFAULT 0,\n attempts INTEGER NOT NULL DEFAULT 0,\n created_at INTEGER NOT NULL\n);\nCREATE INDEX IF NOT EXISTS utterances_started ON utterances(started_at);\nCREATE INDEX IF NOT EXISTS utterances_user ON utterances(user_id, started_at);\nCREATE INDEX IF NOT EXISTS utterances_match ON utterances(match_id, started_at);\nCREATE INDEX IF NOT EXISTS utterances_status ON utterances(status);\n\nCREATE VIRTUAL TABLE IF NOT EXISTS utterances_fts USING fts5(text, content='utterances', content_rowid='rowid', tokenize='trigram');\nCREATE TRIGGER IF NOT EXISTS utterances_ai AFTER INSERT ON utterances BEGIN\n INSERT INTO utterances_fts(rowid, text) VALUES (new.rowid, coalesce(new.text, ''));\nEND;\nCREATE TRIGGER IF NOT EXISTS utterances_ad AFTER DELETE ON utterances BEGIN\n INSERT INTO utterances_fts(utterances_fts, rowid, text) VALUES ('delete', old.rowid, coalesce(old.text, ''));\nEND;\nCREATE TRIGGER IF NOT EXISTS utterances_au AFTER UPDATE OF text ON utterances BEGIN\n INSERT INTO utterances_fts(utterances_fts, rowid, text) VALUES ('delete', old.rowid, coalesce(old.text, ''));\n INSERT INTO utterances_fts(rowid, text) VALUES (new.rowid, coalesce(new.text, ''));\nEND;\n\nCREATE TABLE IF NOT EXISTS matches (\n id TEXT PRIMARY KEY,\n game TEXT NOT NULL,\n started_at INTEGER NOT NULL,\n ended_at INTEGER,\n map TEXT,\n mode TEXT,\n queue TEXT,\n result TEXT,\n detail TEXT,\n status TEXT NOT NULL DEFAULT 'live',\n clock_offset INTEGER NOT NULL DEFAULT 0\n);\nCREATE INDEX IF NOT EXISTS matches_started ON matches(started_at);\n\nCREATE TABLE IF NOT EXISTS rounds (\n match_id TEXT NOT NULL REFERENCES matches(id) ON DELETE CASCADE,\n num INTEGER NOT NULL,\n started_at INTEGER NOT NULL,\n combat_at INTEGER NOT NULL,\n ended_at INTEGER NOT NULL,\n win INTEGER,\n result TEXT,\n ally_score INTEGER,\n enemy_score INTEGER,\n economy TEXT,\n PRIMARY KEY (match_id, num)\n);\n\nCREATE TABLE IF NOT EXISTS game_events (\n id TEXT PRIMARY KEY,\n match_id TEXT NOT NULL,\n game TEXT NOT NULL,\n type TEXT NOT NULL,\n ts INTEGER NOT NULL,\n game_time_ms INTEGER,\n round INTEGER,\n actor_puuid TEXT,\n target_puuid TEXT,\n data TEXT NOT NULL DEFAULT '{}'\n);\nCREATE INDEX IF NOT EXISTS game_events_ts ON game_events(ts);\nCREATE INDEX IF NOT EXISTS game_events_match ON game_events(match_id, ts);\n\nCREATE TABLE IF NOT EXISTS dictionary (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n word TEXT NOT NULL,\n pack TEXT NOT NULL,\n kind TEXT NOT NULL,\n from_text TEXT NOT NULL DEFAULT '',\n source TEXT NOT NULL,\n enabled INTEGER NOT NULL DEFAULT 1,\n hits INTEGER NOT NULL DEFAULT 0,\n created_at INTEGER NOT NULL,\n UNIQUE (kind, word, from_text)\n);\n\nCREATE TABLE IF NOT EXISTS training_samples (\n id TEXT PRIMARY KEY,\n utterance_id TEXT,\n text TEXT NOT NULL,\n audio_path TEXT NOT NULL,\n used INTEGER NOT NULL DEFAULT 0,\n created_at INTEGER NOT NULL\n);\n";
|
||||
export const SCHEMA_SQL = "PRAGMA journal_mode = WAL;\nPRAGMA foreign_keys = ON;\n\nCREATE TABLE IF NOT EXISTS meta (key TEXT PRIMARY KEY, value TEXT);\n\nCREATE TABLE IF NOT EXISTS users (\n id TEXT PRIMARY KEY,\n name TEXT NOT NULL,\n color TEXT NOT NULL,\n avatar TEXT,\n excluded INTEGER NOT NULL DEFAULT 0,\n gain_lufs REAL,\n gain_n INTEGER NOT NULL DEFAULT 0,\n updated_at INTEGER NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS game_accounts (\n user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,\n puuid TEXT NOT NULL,\n riot_id TEXT NOT NULL,\n PRIMARY KEY (user_id, puuid)\n);\nCREATE INDEX IF NOT EXISTS game_accounts_puuid ON game_accounts(puuid);\n\nCREATE TABLE IF NOT EXISTS sessions (\n id TEXT PRIMARY KEY,\n guild_id TEXT NOT NULL,\n channel_id TEXT NOT NULL,\n channel_name TEXT,\n started_at INTEGER NOT NULL,\n ended_at INTEGER\n);\n\nCREATE TABLE IF NOT EXISTS utterances (\n id TEXT PRIMARY KEY,\n session_id TEXT,\n user_id TEXT NOT NULL,\n started_at INTEGER NOT NULL,\n ended_at INTEGER NOT NULL,\n audio_path TEXT,\n audio_deleted INTEGER NOT NULL DEFAULT 0,\n text TEXT,\n raw_text TEXT,\n words TEXT NOT NULL DEFAULT '[]',\n noise INTEGER NOT NULL DEFAULT 0,\n noise_reason TEXT,\n confidence REAL,\n lufs REAL,\n gain_db REAL NOT NULL DEFAULT 0,\n model TEXT,\n status TEXT NOT NULL DEFAULT 'pending',\n match_id TEXT,\n corrected INTEGER NOT NULL DEFAULT 0,\n attempts INTEGER NOT NULL DEFAULT 0,\n created_at INTEGER NOT NULL\n);\nCREATE INDEX IF NOT EXISTS utterances_started ON utterances(started_at);\nCREATE INDEX IF NOT EXISTS utterances_user ON utterances(user_id, started_at);\nCREATE INDEX IF NOT EXISTS utterances_match ON utterances(match_id, started_at);\nCREATE INDEX IF NOT EXISTS utterances_status ON utterances(status);\n\nCREATE VIRTUAL TABLE IF NOT EXISTS utterances_fts USING fts5(text, content='utterances', content_rowid='rowid', tokenize='trigram');\nCREATE TRIGGER IF NOT EXISTS utterances_ai AFTER INSERT ON utterances BEGIN\n INSERT INTO utterances_fts(rowid, text) VALUES (new.rowid, coalesce(new.text, ''));\nEND;\nCREATE TRIGGER IF NOT EXISTS utterances_ad AFTER DELETE ON utterances BEGIN\n INSERT INTO utterances_fts(utterances_fts, rowid, text) VALUES ('delete', old.rowid, coalesce(old.text, ''));\nEND;\nCREATE TRIGGER IF NOT EXISTS utterances_au AFTER UPDATE OF text ON utterances BEGIN\n INSERT INTO utterances_fts(utterances_fts, rowid, text) VALUES ('delete', old.rowid, coalesce(old.text, ''));\n INSERT INTO utterances_fts(rowid, text) VALUES (new.rowid, coalesce(new.text, ''));\nEND;\n\nCREATE TABLE IF NOT EXISTS matches (\n id TEXT PRIMARY KEY,\n game TEXT NOT NULL,\n started_at INTEGER NOT NULL,\n ended_at INTEGER,\n map TEXT,\n mode TEXT,\n queue TEXT,\n result TEXT,\n detail TEXT,\n status TEXT NOT NULL DEFAULT 'live',\n clock_offset INTEGER NOT NULL DEFAULT 0\n);\nCREATE INDEX IF NOT EXISTS matches_started ON matches(started_at);\n\nCREATE TABLE IF NOT EXISTS rounds (\n match_id TEXT NOT NULL REFERENCES matches(id) ON DELETE CASCADE,\n num INTEGER NOT NULL,\n started_at INTEGER NOT NULL,\n combat_at INTEGER NOT NULL,\n ended_at INTEGER NOT NULL,\n win INTEGER,\n result TEXT,\n ally_score INTEGER,\n enemy_score INTEGER,\n economy TEXT,\n PRIMARY KEY (match_id, num)\n);\n\nCREATE TABLE IF NOT EXISTS game_events (\n id TEXT PRIMARY KEY,\n match_id TEXT NOT NULL,\n game TEXT NOT NULL,\n type TEXT NOT NULL,\n ts INTEGER NOT NULL,\n game_time_ms INTEGER,\n round INTEGER,\n actor_puuid TEXT,\n target_puuid TEXT,\n data TEXT NOT NULL DEFAULT '{}'\n);\nCREATE INDEX IF NOT EXISTS game_events_ts ON game_events(ts);\nCREATE INDEX IF NOT EXISTS game_events_match ON game_events(match_id, ts);\n\nCREATE TABLE IF NOT EXISTS dictionary (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n word TEXT NOT NULL,\n pack TEXT NOT NULL,\n kind TEXT NOT NULL,\n from_text TEXT NOT NULL DEFAULT '',\n source TEXT NOT NULL,\n enabled INTEGER NOT NULL DEFAULT 1,\n hits INTEGER NOT NULL DEFAULT 0,\n created_at INTEGER NOT NULL,\n UNIQUE (kind, word, from_text, pack)\n);\n\nCREATE TABLE IF NOT EXISTS training_samples (\n id TEXT PRIMARY KEY,\n utterance_id TEXT,\n text TEXT NOT NULL,\n audio_path TEXT NOT NULL,\n used INTEGER NOT NULL DEFAULT 0,\n created_at INTEGER NOT NULL\n);\n";
|
||||
|
||||
@@ -59,6 +59,30 @@ export class Dictionary {
|
||||
log.info(`기본 사전 적재: ${Object.values(data.packs).reduce((n, p) => n + p.words.length, 0)}단어, 교정 ${corrections.length}개`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 게임 패치로 새 요원·챔피언·맵·무기가 나오면 자동으로 사전에 넣는다 (보고서 5-4: 공식 데이터로 자동 갱신).
|
||||
* 기본 사전에 이미 있는 이름은 건너뛴다. 반환: 새로 넣은 단어 수
|
||||
*/
|
||||
syncGameNames(names: { valorant: string[]; lol: string[] }): number {
|
||||
const have = new Set(this.rows().filter((r) => r.kind === 'hotword').map((r) => `${r.pack}|${r.word}`));
|
||||
let n = 0;
|
||||
const tx = this.store.db.transaction(() => {
|
||||
for (const [pack, list] of Object.entries(names))
|
||||
for (const w of list) {
|
||||
const word = w.replace('/', '').trim();
|
||||
if (!word || have.has(`${pack}|${word}`)) continue;
|
||||
this.store.addDict({ word, pack, kind: 'hotword', from_text: '', source: 'builtin' });
|
||||
n++;
|
||||
}
|
||||
});
|
||||
tx();
|
||||
if (n) {
|
||||
this.invalidate();
|
||||
log.info(`게임 데이터 갱신으로 사전에 ${n}단어 추가`);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
invalidate(): void {
|
||||
this.cache = null;
|
||||
}
|
||||
|
||||
@@ -136,6 +136,16 @@ export class GameAssets {
|
||||
log.info(`롤 목록 갱신: ${v}, 챔피언 ${Object.keys(champs).length}`);
|
||||
}
|
||||
|
||||
/** 사전 자동 갱신용 이름 목록 */
|
||||
names(): { valorant: string[]; lol: string[] } {
|
||||
const v = this.val;
|
||||
const l = this.lol;
|
||||
return {
|
||||
valorant: v ? [...Object.values(v.agents).map((a) => a.name), ...Object.values(v.maps).filter((m) => m.image).map((m) => m.name), ...Object.values(v.weapons).map((w) => w.name)] : [],
|
||||
lol: l ? [...new Set(Object.entries(l.champions).filter(([k]) => !k.includes(':')).map(([, c]) => c.name))] : [],
|
||||
};
|
||||
}
|
||||
|
||||
// ---- 발로란트 조회
|
||||
agent(id: string | null | undefined) {
|
||||
const a = id ? this.val?.agents[id.toLowerCase()] : undefined;
|
||||
|
||||
@@ -105,6 +105,7 @@ export async function startCore(opts: CoreOptions) {
|
||||
worker.start();
|
||||
stt.resumePending();
|
||||
games.start();
|
||||
void assets.refresh().then(() => dict.syncGameNames(assets.names())).catch(() => undefined);
|
||||
retention.start();
|
||||
relay.start();
|
||||
if (opts.apiPort) await api.listen({ host: '127.0.0.1', port: opts.apiPort });
|
||||
@@ -134,5 +135,5 @@ export async function startCore(opts: CoreOptions) {
|
||||
store.close();
|
||||
};
|
||||
|
||||
return { settings, store, bus, timeline, dict, worker, stt, assets, games, recorder, bot, api, relay, retention, paths, startBot, stop, version: opts.version };
|
||||
return { settings, store, bus, timeline, dict, worker, stt, assets, games, recorder, bot, api, relay, retention, paths, startBot, stop, version: opts.version, resourcesDir: opts.resourcesDir };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user