refactor(suggestion): drive suggestion decisions from one core step and split SuggestionService collaborators

This commit is contained in:
Yun Chan 2026-09-28 00:53:42 +09:00
parent 9aa7302944
commit 190b6db284
13 changed files with 1994 additions and 496 deletions

View file

@ -24,7 +24,7 @@ import {
type RelatedCandidate
} from '@d3ro/core/personal-graph'
import { isLearnablePhrase, prefixTail } from '@d3ro/core/input-intelligence'
import { and, desc, eq, gte, inArray, sql } from 'drizzle-orm'
import { and, desc, eq, gte, inArray, or, sql } from 'drizzle-orm'
import { getDatabase } from '../db'
import { personalPhrases, phraseEdges } from '../db/schema'
import { getLogger } from './LoggerService'
@ -357,6 +357,22 @@ class PersonalGraphService {
}
}
/**
* 한 문장 노드에 닿는 엣지를 모두 지운다 (사용자가 문구를 삭제했을 때).
*
* 엣지는 문장 텍스트를 외래 키 없이 들고 있어, 노드만 지우면 follows 이웃으로
* 지운 문장이 계속 제안 문맥에 끌려 나온다. 호출자의 트랜잭션 안에서 부를 수 있도록
* 예외를 삼키지 않는다.
*/
removePhrase(phrase: string): number {
const db = getDatabase()
const result = db
.delete(phraseEdges)
.where(or(eq(phraseEdges.fromPhrase, phrase), eq(phraseEdges.toPhrase, phrase)))
.run()
return Number(result.changes ?? 0)
}
clearAll(): void {
try {
const db = getDatabase()