Refine onboarding state and nickname checks
This commit is contained in:
1 parent
5579db54da
commit
9c013f7d4f
33 files changed
+1523
-119
No files matched your search
@@ -33,4 +33,22 @@ describe("OnboardingIntentClassifier", () => {
|
||||
expect(result.intent.kind).toBe("nickname-question");
|
||||
expect(result.source).toBe("regex");
|
||||
});
|
||||
|
||||
it("classifies discord verification via regex", async () => {
|
||||
const result = await classifier.classify(
|
||||
"디코 닉변 확인해줘",
|
||||
"user-message",
|
||||
);
|
||||
expect(result.intent.kind).toBe("discord-verify-question");
|
||||
expect(result.source).toBe("regex");
|
||||
});
|
||||
|
||||
it("classifies discord nickname completion reports as verification", async () => {
|
||||
const result = await classifier.classify(
|
||||
"디스코드 프로필 닉네임 설정 완료했어요",
|
||||
"user-message",
|
||||
);
|
||||
expect(result.intent.kind).toBe("discord-verify-question");
|
||||
expect(result.source).toBe("regex");
|
||||
});
|
||||
});
|
||||
@@ -76,6 +76,24 @@ function classifyByRegex(userMessage: string): ClassifiedIntent {
|
||||
return { intent: intent("help-how"), confidence: 0.9, source: "regex" };
|
||||
}
|
||||
|
||||
const mentionsDiscord = /(디스코드|디코|discord)/u.test(lower);
|
||||
const asksDiscordVerification =
|
||||
/(확인|조회|찾아|검색|검사|바뀌|변경|닉변|맞(?:아|나요)?|됐(?:나|나요)?|완료됐(?:나|나요)?)/u.test(
|
||||
trimmed,
|
||||
);
|
||||
const reportsDiscordNicknameCompletion =
|
||||
/(닉네임|닉변|프로필\s*닉네임|서버\s*닉네임)/u.test(trimmed) &&
|
||||
/(완료했(?:어|어요|습니다)?|끝냈(?:어|어요|습니다)?|설정했(?:어|어요|습니다)?|바꿨(?:어|어요|습니다)?|변경했(?:어|어요|습니다)?|다\s*했(?:어|어요|습니다)?|해놨(?:어|어요|습니다)?|해뒀(?:어|어요|습니다)?|적용됐(?:어|어요|습니다)?)/u.test(
|
||||
trimmed,
|
||||
);
|
||||
if (mentionsDiscord && (asksDiscordVerification || reportsDiscordNicknameCompletion)) {
|
||||
return {
|
||||
intent: intent("discord-verify-question"),
|
||||
confidence: 0.96,
|
||||
source: "regex",
|
||||
};
|
||||
}
|
||||
|
||||
if (/(디스코드|디코|discord)/u.test(lower)) {
|
||||
return {
|
||||
intent: intent("discord-question"),
|
||||
@@ -123,6 +141,7 @@ function parseIntent(raw: unknown): Intent {
|
||||
raw === "nickname-question" ||
|
||||
raw === "photo-question" ||
|
||||
raw === "discord-question" ||
|
||||
raw === "discord-verify-question" ||
|
||||
raw === "age-question" ||
|
||||
raw === "chitchat" ||
|
||||
raw === "off-topic-to-other"
|
||||
@@ -147,7 +166,7 @@ async function classifyByLlm(
|
||||
{
|
||||
role: "system",
|
||||
content:
|
||||
'다음 유저 메시지의 intent를 JSON으로만 분류해. {"intent":"..."} 형식만 출력하고, intent는 greeting, acknowledgement, status-question, help-how, help-where, nickname-question, photo-question, discord-question, age-question, chitchat, off-topic-to-other, unknown 중 하나만 사용해.',
|
||||
'다음 유저 메시지의 intent를 JSON으로만 분류해. {"intent":"..."} 형식만 출력하고, intent는 greeting, acknowledgement, status-question, help-how, help-where, nickname-question, photo-question, discord-question, discord-verify-question, age-question, chitchat, off-topic-to-other, unknown 중 하나만 사용해.',
|
||||
},
|
||||
{
|
||||
role: "user",
|
||||
|
||||
@@ -11,8 +11,10 @@ function makeSession(
|
||||
chatroomId: "room-1",
|
||||
deadlineAt: new Date(Date.now() + 2 * 60 * 60 * 1000).toISOString(),
|
||||
joinedAt: new Date().toISOString(),
|
||||
kakaotalkNickname: "프리리/95/여/D",
|
||||
kakaotalkNicknameAliases: [],
|
||||
kakaotalkNicknameVerified: false,
|
||||
lastEventAt: new Date().toISOString(),
|
||||
nickname: "프리리/95/여/D",
|
||||
nicknameVerified: false,
|
||||
photoVerified: false,
|
||||
status: "pending",
|
||||
@@ -58,4 +60,38 @@ describe("deriveState", () => {
|
||||
expect(derived.allowShortResponse).toBe(true);
|
||||
expect(derived.suggestedMaxTokens).toBe(96);
|
||||
});
|
||||
|
||||
it("uses tool mode for discord verification questions", () => {
|
||||
const derived = deriveState(
|
||||
makeSession(),
|
||||
"user-message",
|
||||
intent("discord-verify-question"),
|
||||
);
|
||||
expect(derived.responseMode).toBe("llm-with-tools");
|
||||
expect(derived.tier).toBe(1);
|
||||
});
|
||||
|
||||
it("does not mark completed when only step1 is done for extended sessions", () => {
|
||||
const derived = deriveState(
|
||||
makeSession({
|
||||
discordProfileMessageVerified: false,
|
||||
discordProfileNicknameVerified: false,
|
||||
identityRoomJoined: true,
|
||||
nicknameVerified: true,
|
||||
photoVerified: true,
|
||||
recruitingRoomJoined: true,
|
||||
step1CompletedAt: new Date().toISOString(),
|
||||
}),
|
||||
"user-message",
|
||||
intent("status-question"),
|
||||
);
|
||||
|
||||
expect(derived.phase.kind).toBe("step1-completed");
|
||||
if (derived.phase.kind === "step1-completed") {
|
||||
expect(derived.phase.remaining).toEqual([
|
||||
"discord-profile-nickname",
|
||||
"discord-profile-message",
|
||||
]);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -27,6 +27,7 @@ function getSuggestedMaxTokens(
|
||||
intent.kind === "help-where" ||
|
||||
intent.kind === "nickname-question" ||
|
||||
intent.kind === "photo-question" ||
|
||||
intent.kind === "discord-verify-question" ||
|
||||
trigger === "nickname-invalid" ||
|
||||
trigger === "photo-failed"
|
||||
) {
|
||||
@@ -76,6 +77,9 @@ export function deriveState(
|
||||
if (phase.kind === "nickname-rejected") {
|
||||
responseMode = "llm-with-tools";
|
||||
tier = 1;
|
||||
} else if (intent.kind === "discord-verify-question") {
|
||||
responseMode = "llm-with-tools";
|
||||
tier = 1;
|
||||
} else if (phase.kind === "deadline-near") {
|
||||
responseMode = "llm";
|
||||
tier = 1;
|
||||
|
||||
@@ -4,7 +4,8 @@ export const EXPECTED_KEYWORDS: Record<Intent["kind"], string[]> = {
|
||||
acknowledgement: ["네", "좋아요", "천천히"],
|
||||
"age-question": ["27", "가입", "가능"],
|
||||
chitchat: [],
|
||||
"discord-question": ["디스코드", "권한", "완료"],
|
||||
"discord-question": ["디스코드", "프로필", "권한", "설정"],
|
||||
"discord-verify-question": ["디스코드", "확인", "닉네임"],
|
||||
greeting: ["반갑", "환영", "어서 오세요"],
|
||||
"help-how": ["하트", "닉네임", "스크린샷", "형식", "커버 보기"],
|
||||
"help-where": ["오른쪽 상단", "커버 보기", "프로필"],
|
||||
|
||||
@@ -1,12 +1,19 @@
|
||||
import type { NicknameIssue } from "../types.js";
|
||||
|
||||
export type RemainingStep = "nickname" | "photo";
|
||||
export type RemainingStep =
|
||||
| "nickname"
|
||||
| "photo"
|
||||
| "identity-room"
|
||||
| "recruiting-room"
|
||||
| "discord-profile-nickname"
|
||||
| "discord-profile-message";
|
||||
|
||||
export type OnboardingPhase =
|
||||
| { kind: "fresh" }
|
||||
| { kind: "nickname-pending"; current: string }
|
||||
| { kind: "photo-pending" }
|
||||
| { kind: "both-pending" }
|
||||
| { kind: "step1-completed"; remaining: RemainingStep[] }
|
||||
| { kind: "nickname-rejected"; current: string; issues: NicknameIssue[] }
|
||||
| { kind: "photo-rejected"; reason?: string | undefined }
|
||||
| { kind: "deadline-near"; remaining: RemainingStep[] }
|
||||
@@ -22,6 +29,7 @@ export type Intent =
|
||||
| { kind: "nickname-question" }
|
||||
| { kind: "photo-question" }
|
||||
| { kind: "discord-question" }
|
||||
| { kind: "discord-verify-question" }
|
||||
| { kind: "age-question" }
|
||||
| { kind: "chitchat" }
|
||||
| { kind: "off-topic-to-other" }
|
||||
|
||||
@@ -0,0 +1,173 @@
|
||||
import type { OnboardingSession } from '../types.js';
|
||||
import type { RemainingStep } from './onboarding-state.js';
|
||||
|
||||
const REMAINING_STEP_LABELS: Record<RemainingStep, string> = {
|
||||
nickname: '카카오톡 닉네임 변경',
|
||||
photo: '방 하트 인증',
|
||||
'identity-room': '디스코드 본인인증방 입장',
|
||||
'recruiting-room': '디스코드 구인방 입장',
|
||||
'discord-profile-nickname': '디스코드 프로필 닉네임 설정',
|
||||
'discord-profile-message': '디스코드 주민신청 채널에 메시지 남기기',
|
||||
};
|
||||
|
||||
export function isStep1Completed(session: OnboardingSession | null): boolean {
|
||||
return Boolean(session?.nicknameVerified && session?.photoVerified);
|
||||
}
|
||||
|
||||
export function hasExtendedOnboardingTracking(session: OnboardingSession | null): boolean {
|
||||
if (!session) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (
|
||||
session.step1CompletedAt !== undefined ||
|
||||
session.identityRoomJoined !== undefined ||
|
||||
session.identityRoomJoinedAt !== undefined ||
|
||||
session.recruitingRoomJoined !== undefined ||
|
||||
session.recruitingRoomJoinedAt !== undefined ||
|
||||
session.discordProfileNicknameVerified !== undefined ||
|
||||
session.discordProfileNicknameVerifiedAt !== undefined ||
|
||||
session.discordProfileMessageVerified !== undefined ||
|
||||
session.discordProfileMessageVerifiedAt !== undefined
|
||||
);
|
||||
}
|
||||
|
||||
function shouldTrackDiscordRooms(session: OnboardingSession | null): boolean {
|
||||
if (!session) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (
|
||||
session.identityRoomJoined !== undefined ||
|
||||
session.identityRoomJoinedAt !== undefined ||
|
||||
session.recruitingRoomJoined !== undefined ||
|
||||
session.recruitingRoomJoinedAt !== undefined
|
||||
);
|
||||
}
|
||||
|
||||
function shouldTrackDiscordProfile(session: OnboardingSession | null): boolean {
|
||||
if (!session) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (
|
||||
session.discordProfileNicknameVerified !== undefined ||
|
||||
session.discordProfileNicknameVerifiedAt !== undefined ||
|
||||
session.discordProfileMessageVerified !== undefined ||
|
||||
session.discordProfileMessageVerifiedAt !== undefined
|
||||
);
|
||||
}
|
||||
|
||||
function hasJoinedAllTrackedDiscordRooms(session: OnboardingSession | null): boolean {
|
||||
if (!session) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!shouldTrackDiscordRooms(session)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return session.identityRoomJoined !== false && session.recruitingRoomJoined !== false;
|
||||
}
|
||||
|
||||
export function getRemainingSteps(session: OnboardingSession | null): RemainingStep[] {
|
||||
if (!session) {
|
||||
return ['nickname', 'photo'];
|
||||
}
|
||||
|
||||
const remaining: RemainingStep[] = [];
|
||||
|
||||
if (!session.nicknameVerified) {
|
||||
remaining.push('nickname');
|
||||
}
|
||||
|
||||
if (!session.photoVerified) {
|
||||
remaining.push('photo');
|
||||
}
|
||||
|
||||
if (remaining.length > 0) {
|
||||
return remaining;
|
||||
}
|
||||
|
||||
if (!hasExtendedOnboardingTracking(session)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (shouldTrackDiscordRooms(session)) {
|
||||
if (session.identityRoomJoined === false) {
|
||||
remaining.push('identity-room');
|
||||
}
|
||||
if (session.recruitingRoomJoined === false) {
|
||||
remaining.push('recruiting-room');
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasJoinedAllTrackedDiscordRooms(session)) {
|
||||
return remaining;
|
||||
}
|
||||
|
||||
if (shouldTrackDiscordProfile(session)) {
|
||||
if (session.discordProfileNicknameVerified === false) {
|
||||
remaining.push('discord-profile-nickname');
|
||||
}
|
||||
if (session.discordProfileMessageVerified === false) {
|
||||
remaining.push('discord-profile-message');
|
||||
}
|
||||
}
|
||||
|
||||
return remaining;
|
||||
}
|
||||
|
||||
export function isOnboardingCompleted(session: OnboardingSession | null): boolean {
|
||||
if (!session) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (session.status === 'completed') {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!isStep1Completed(session)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!hasExtendedOnboardingTracking(session)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return getRemainingSteps(session).length === 0;
|
||||
}
|
||||
|
||||
export function isDiscordGuidanceUnlocked(session: OnboardingSession | null): boolean {
|
||||
return isStep1Completed(session);
|
||||
}
|
||||
|
||||
export function formatRemainingStep(step: RemainingStep): string {
|
||||
return REMAINING_STEP_LABELS[step];
|
||||
}
|
||||
|
||||
function appendKoreanAnd(left: string, right: string): string {
|
||||
const lastChar = left.charCodeAt(left.length - 1);
|
||||
const hasBatchim = lastChar >= 0xac00 && lastChar <= 0xd7a3 && (lastChar - 0xac00) % 28 !== 0;
|
||||
|
||||
return `${left}${hasBatchim ? '과' : '와'} ${right}`;
|
||||
}
|
||||
|
||||
export function formatRemainingSteps(steps: RemainingStep[]): string {
|
||||
const labels = steps.map(formatRemainingStep);
|
||||
if (labels.length === 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (labels.length === 1) {
|
||||
return labels[0] ?? '';
|
||||
}
|
||||
|
||||
if (labels.length === 2) {
|
||||
return appendKoreanAnd(labels[0] ?? '', labels[1] ?? '');
|
||||
}
|
||||
|
||||
const head = labels.slice(0, -1).join(', ');
|
||||
const tail = labels[labels.length - 1] ?? '';
|
||||
return appendKoreanAnd(head, tail);
|
||||
}
|
||||
@@ -2,23 +2,11 @@ import { DEADLINE_NEAR_THRESHOLD_MIN } from "../constants.js";
|
||||
import { analyzeNicknameIssues } from "../onboarding-templates.js";
|
||||
import type { OnboardingSession } from "../types.js";
|
||||
import type { OnboardingPhase, RemainingStep } from "./onboarding-state.js";
|
||||
|
||||
function getRemainingSteps(
|
||||
session: OnboardingSession | null,
|
||||
): RemainingStep[] {
|
||||
if (!session) {
|
||||
return ["nickname", "photo"];
|
||||
}
|
||||
|
||||
const remaining: RemainingStep[] = [];
|
||||
if (!session.nicknameVerified) {
|
||||
remaining.push("nickname");
|
||||
}
|
||||
if (!session.photoVerified) {
|
||||
remaining.push("photo");
|
||||
}
|
||||
return remaining;
|
||||
}
|
||||
import {
|
||||
getRemainingSteps,
|
||||
isOnboardingCompleted,
|
||||
isStep1Completed,
|
||||
} from "./progress.js";
|
||||
|
||||
function isDeadlineNear(session: OnboardingSession | null): boolean {
|
||||
if (!session?.deadlineAt) {
|
||||
@@ -45,15 +33,15 @@ export function derivePhaseFromSession(
|
||||
return { kind: "timed-out" };
|
||||
}
|
||||
|
||||
if (session.status === "completed" || (session.nicknameVerified && session.photoVerified)) {
|
||||
if (isOnboardingCompleted(session)) {
|
||||
return { kind: "completed" };
|
||||
}
|
||||
|
||||
if (trigger === "nickname-invalid") {
|
||||
return {
|
||||
kind: "nickname-rejected",
|
||||
current: session.nickname,
|
||||
issues: analyzeNicknameIssues(session.nickname),
|
||||
current: session.kakaotalkNickname,
|
||||
issues: analyzeNicknameIssues(session.kakaotalkNickname),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -73,7 +61,7 @@ export function derivePhaseFromSession(
|
||||
if (!session.nicknameVerified) {
|
||||
return {
|
||||
kind: "nickname-pending",
|
||||
current: session.nickname,
|
||||
current: session.kakaotalkNickname,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -81,5 +69,12 @@ export function derivePhaseFromSession(
|
||||
return { kind: "photo-pending" };
|
||||
}
|
||||
|
||||
if (isStep1Completed(session) && remaining.length > 0) {
|
||||
return {
|
||||
kind: "step1-completed",
|
||||
remaining,
|
||||
};
|
||||
}
|
||||
|
||||
return { kind: "fresh" };
|
||||
}
|
||||
Reference in new issue
Block a user