63 lines
2.0 KiB
TypeScript
63 lines
2.0 KiB
TypeScript
import type { UserProfile } from "@skills/onboarding/state/user-memory";
|
|
import type { DerivedState } from "@skills/onboarding/state/onboarding-state";
|
|
|
|
export interface ProfilePromptSnippet {
|
|
block: string;
|
|
reason: "frequent-intent" | "preferred-style" | "repeated-issue";
|
|
}
|
|
|
|
function normalizeIssue(issue: string): string {
|
|
return issue
|
|
.normalize("NFKC")
|
|
.replace(/\[[^\]]+\]/gu, "")
|
|
.replace(/[0-9]/gu, "")
|
|
.replace(/\s+/gu, " ")
|
|
.trim()
|
|
.slice(0, 32);
|
|
}
|
|
|
|
export function deriveProfilePromptSnippets(
|
|
profile: UserProfile,
|
|
derived: DerivedState,
|
|
): ProfilePromptSnippet[] {
|
|
const snippets: ProfilePromptSnippet[] = [];
|
|
const frequentIntent = profile.pastIntents.find(
|
|
(intent) => intent.kind === derived.intent.kind && intent.count >= 5,
|
|
);
|
|
if (frequentIntent) {
|
|
snippets.push({
|
|
reason: "frequent-intent",
|
|
block: `사용자는 ${frequentIntent.kind} 유형을 자주 물어봤어요. 핵심 답부터 짧게 말하고, 질문 범위를 넘기지 마세요.`,
|
|
});
|
|
}
|
|
|
|
const issueCounts = new Map<string, number>();
|
|
for (const issue of profile.flaggedIssues) {
|
|
const normalized = normalizeIssue(issue);
|
|
if (normalized) {
|
|
issueCounts.set(normalized, (issueCounts.get(normalized) ?? 0) + 1);
|
|
}
|
|
}
|
|
const repeatedIssue = [...issueCounts.entries()].find(([, count]) => count >= 3);
|
|
if (repeatedIssue) {
|
|
snippets.push({
|
|
reason: "repeated-issue",
|
|
block: `반복된 이슈가 있었어요: ${repeatedIssue[0]}. 같은 실수가 이어지지 않도록 정확한 형식 예시를 먼저 확인하세요.`,
|
|
});
|
|
}
|
|
|
|
if (profile.preferredStyle === "concise") {
|
|
snippets.push({
|
|
reason: "preferred-style",
|
|
block: "사용자는 짧고 바로 실행 가능한 답변을 선호해요.",
|
|
});
|
|
} else if (profile.preferredStyle === "warm") {
|
|
snippets.push({
|
|
reason: "preferred-style",
|
|
block: "사용자는 따뜻한 톤에 잘 반응했어요. 다만 불필요한 절차 설명은 붙이지 마세요.",
|
|
});
|
|
}
|
|
|
|
return snippets;
|
|
}
|