Tune LLM routing and prompts
This commit is contained in:
1 parent
9c013f7d4f
commit
60f33b8f4b
19 files changed
+736
-803
No files matched your search
@@ -50,7 +50,42 @@ describe("checkOnboardingProgressTool", () => {
|
||||
]);
|
||||
expect(result.remainingStepLabels).toEqual([
|
||||
"디스코드 프로필 닉네임 설정",
|
||||
"디스코드 프로필 메시지 설정",
|
||||
"디스코드 주민신청 채널에 메시지 남기기",
|
||||
]);
|
||||
});
|
||||
|
||||
it("returns all remaining discord steps when rooms and profile setup are both incomplete", async () => {
|
||||
const result = await checkOnboardingProgressTool.execute(
|
||||
{
|
||||
chatroomId: "room-1",
|
||||
userId: "user-1",
|
||||
},
|
||||
{
|
||||
chatroomId: "room-1",
|
||||
session: makeSession({
|
||||
discordProfileMessageVerified: false,
|
||||
discordProfileNicknameVerified: false,
|
||||
identityRoomJoined: false,
|
||||
recruitingRoomJoined: false,
|
||||
step1CompletedAt: "2026-04-21T16:57:44.767Z",
|
||||
}),
|
||||
userId: "user-1",
|
||||
},
|
||||
);
|
||||
|
||||
expect(result.step1Done).toBe(true);
|
||||
expect(result.overallDone).toBe(false);
|
||||
expect(result.remainingSteps).toEqual([
|
||||
"identity-room",
|
||||
"recruiting-room",
|
||||
"discord-profile-nickname",
|
||||
"discord-profile-message",
|
||||
]);
|
||||
expect(result.remainingStepLabels).toEqual([
|
||||
"카카오톡 본인인증방 입장",
|
||||
"카카오톡 구인방 입장",
|
||||
"디스코드 프로필 닉네임 설정",
|
||||
"디스코드 주민신청 채널에 메시지 남기기",
|
||||
]);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,48 +1,49 @@
|
||||
import { z } from "zod";
|
||||
import { z } from 'zod';
|
||||
import {
|
||||
getDiscordMemberLookupSubject,
|
||||
getDiscordVerifyTimeoutMs,
|
||||
getOnboardingSessionKeyPrefix,
|
||||
} from "../../config.js";
|
||||
} from '../../config.js';
|
||||
import type {
|
||||
DiscordMemberCandidate,
|
||||
DiscordMemberLookupRequest,
|
||||
DiscordMemberLookupResponse,
|
||||
} from "@common/nats-subjects";
|
||||
import { getContext, getRequestLogger } from "@obs/context";
|
||||
} from '@common/nats-subjects';
|
||||
import { getContext, getRequestLogger } from '@obs/context';
|
||||
import {
|
||||
NICKNAME_FORMAT_EXAMPLE,
|
||||
KAKAOTALK_NICKNAME_FORMAT_EXAMPLE,
|
||||
DISCORD_NICKNAME_FORMAT_EXAMPLE,
|
||||
NICKNAME_FORMAT_TEXT,
|
||||
} from "@skills/onboarding/constants";
|
||||
import { analyzeNicknameIssues } from "@skills/onboarding/onboarding-templates";
|
||||
} from '@skills/onboarding/constants';
|
||||
import { analyzeNicknameIssues } from '@skills/onboarding/onboarding-templates';
|
||||
import {
|
||||
getKakaotalkNickname,
|
||||
matchesDiscordNicknameRule,
|
||||
parseKakaoNickname,
|
||||
} from "@skills/onboarding/session";
|
||||
import type { Tool, ToolContext } from "../tool.js";
|
||||
} from '@skills/onboarding/session';
|
||||
import type { Tool, ToolContext } from '../tool.js';
|
||||
|
||||
const argsSchema = z.object({}).passthrough();
|
||||
|
||||
const resultSchema = z.object({
|
||||
status: z.enum([
|
||||
"invalid-nickname-format",
|
||||
"lookup-unavailable",
|
||||
"matched-pending-rename",
|
||||
"matched-renamed",
|
||||
"not-confirmed",
|
||||
'invalid-nickname-format',
|
||||
'lookup-unavailable',
|
||||
'matched-pending-rename',
|
||||
'matched-renamed',
|
||||
'not-confirmed',
|
||||
]),
|
||||
message: z.string(),
|
||||
reason: z
|
||||
.enum([
|
||||
"joined-after-ambiguous",
|
||||
"joined-after-none",
|
||||
"lookup-error",
|
||||
"missing-search-name",
|
||||
"missing-session",
|
||||
"nickname-search-ambiguous",
|
||||
"nickname-search-none",
|
||||
"request-budget-exhausted",
|
||||
'joined-after-ambiguous',
|
||||
'joined-after-none',
|
||||
'lookup-error',
|
||||
'missing-search-name',
|
||||
'missing-session',
|
||||
'nickname-search-ambiguous',
|
||||
'nickname-search-none',
|
||||
'request-budget-exhausted',
|
||||
])
|
||||
.optional(),
|
||||
expectedNickname: z.string().optional(),
|
||||
@@ -53,18 +54,14 @@ const resultSchema = z.object({
|
||||
guidance: z.string().optional(),
|
||||
issueMessages: z.array(z.string()).optional(),
|
||||
joinedAfterMatchCount: z.number().int().nonnegative().optional(),
|
||||
matchSource: z.enum(["joined-after", "nickname"]).optional(),
|
||||
matchedBy: z
|
||||
.enum(["global-name", "guild-nickname", "joined-after", "username"])
|
||||
.optional(),
|
||||
matchSource: z.enum(['joined-after', 'nickname']).optional(),
|
||||
matchedBy: z.enum(['global-name', 'guild-nickname', 'joined-after', 'username']).optional(),
|
||||
nicknameMatchCount: z.number().int().nonnegative().optional(),
|
||||
});
|
||||
|
||||
function pickDisplayName(candidate: DiscordMemberCandidate): string {
|
||||
return (
|
||||
candidate.guildNickname?.trim() ||
|
||||
candidate.globalName?.trim() ||
|
||||
candidate.username.trim()
|
||||
candidate.guildNickname?.trim() || candidate.globalName?.trim() || candidate.username.trim()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -84,10 +81,7 @@ function resolveTimeoutMs(): number | null {
|
||||
return Math.min(configured, remainingMs);
|
||||
}
|
||||
|
||||
async function persistDiscordMemberId(
|
||||
memberId: string,
|
||||
ctx: ToolContext,
|
||||
): Promise<void> {
|
||||
async function persistDiscordMemberId(memberId: string, ctx: ToolContext): Promise<void> {
|
||||
if (!ctx.garnetClient || !ctx.session) {
|
||||
return;
|
||||
}
|
||||
@@ -105,19 +99,19 @@ export const verifyDiscordNicknameTool: Tool<
|
||||
z.infer<typeof argsSchema>,
|
||||
z.infer<typeof resultSchema>
|
||||
> = {
|
||||
name: "verify-discord-nickname",
|
||||
name: 'verify-discord-nickname',
|
||||
description:
|
||||
"현재 유저의 카카오톡 인증 닉네임과 세션 입장 시각을 기준으로 디스코드 멤버를 찾아, 닉네임 변경이 확인됐는지 구조화해서 반환한다.",
|
||||
'현재 유저의 카카오톡 인증 닉네임과 세션 입장 시각을 기준으로 디스코드 멤버를 찾아, 닉네임 변경이 확인됐는지 구조화해서 반환한다.',
|
||||
argsSchema,
|
||||
resultSchema,
|
||||
async execute(_args, ctx) {
|
||||
const logger = getRequestLogger();
|
||||
if (!ctx.session) {
|
||||
logger.debug("[VerifyDiscordNickname] Missing session in tool context");
|
||||
logger.debug('[VerifyDiscordNickname] Missing session in tool context');
|
||||
return {
|
||||
status: "lookup-unavailable" as const,
|
||||
message: "세션 정보를 찾을 수 없어서 디스코드 닉네임을 조회할 수 없어요.",
|
||||
reason: "missing-session" as const,
|
||||
status: 'lookup-unavailable' as const,
|
||||
message: '세션 정보를 찾을 수 없어서 디스코드 닉네임을 조회할 수 없어요.',
|
||||
reason: 'missing-session' as const,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -129,7 +123,7 @@ export const verifyDiscordNicknameTool: Tool<
|
||||
nicknameVerified: ctx.session.nicknameVerified,
|
||||
photoVerified: ctx.session.photoVerified,
|
||||
},
|
||||
"[VerifyDiscordNickname] Starting verification",
|
||||
'[VerifyDiscordNickname] Starting verification',
|
||||
);
|
||||
const issues = analyzeNicknameIssues(expectedNickname);
|
||||
if (issues.length > 0) {
|
||||
@@ -138,31 +132,31 @@ export const verifyDiscordNicknameTool: Tool<
|
||||
expectedNickname,
|
||||
issueMessages: issues.map((issue) => issue.message),
|
||||
},
|
||||
"[VerifyDiscordNickname] Nickname format invalid",
|
||||
'[VerifyDiscordNickname] Nickname format invalid',
|
||||
);
|
||||
return {
|
||||
status: "invalid-nickname-format" as const,
|
||||
status: 'invalid-nickname-format' as const,
|
||||
message: `카카오톡 닉네임 형식이 올바르지 않아요. ${NICKNAME_FORMAT_TEXT}`,
|
||||
expectedNickname,
|
||||
formatExample: NICKNAME_FORMAT_EXAMPLE,
|
||||
formatExample: KAKAOTALK_NICKNAME_FORMAT_EXAMPLE,
|
||||
guidance: NICKNAME_FORMAT_TEXT,
|
||||
issueMessages: issues.map((issue) => issue.message),
|
||||
};
|
||||
}
|
||||
|
||||
const parsedKakaoNickname = parseKakaoNickname(expectedNickname);
|
||||
const searchName = parsedKakaoNickname?.baseName ?? "";
|
||||
const searchName = parsedKakaoNickname?.baseName ?? '';
|
||||
if (!searchName) {
|
||||
logger.debug(
|
||||
{
|
||||
expectedNickname,
|
||||
},
|
||||
"[VerifyDiscordNickname] Failed to derive search name",
|
||||
'[VerifyDiscordNickname] Failed to derive search name',
|
||||
);
|
||||
return {
|
||||
status: "lookup-unavailable" as const,
|
||||
message: "닉네임에서 검색할 이름을 추출할 수 없어서 디스코드 조회가 불가능해요.",
|
||||
reason: "missing-search-name" as const,
|
||||
status: 'lookup-unavailable' as const,
|
||||
message: '닉네임에서 검색할 이름을 추출할 수 없어서 디스코드 조회가 불가능해요.',
|
||||
reason: 'missing-search-name' as const,
|
||||
expectedNickname,
|
||||
};
|
||||
}
|
||||
@@ -173,12 +167,12 @@ export const verifyDiscordNicknameTool: Tool<
|
||||
expectedNickname,
|
||||
searchName,
|
||||
},
|
||||
"[VerifyDiscordNickname] Missing NATS client in tool context",
|
||||
'[VerifyDiscordNickname] Missing NATS client in tool context',
|
||||
);
|
||||
return {
|
||||
status: "lookup-unavailable" as const,
|
||||
message: "지금은 디스코드 서버 조회가 불가능해요. 잠시 후 다시 시도해주세요.",
|
||||
reason: "lookup-error" as const,
|
||||
status: 'lookup-unavailable' as const,
|
||||
message: '지금은 디스코드 서버 조회가 불가능해요. 잠시 후 다시 시도해주세요.',
|
||||
reason: 'lookup-error' as const,
|
||||
expectedNickname,
|
||||
searchName,
|
||||
};
|
||||
@@ -191,12 +185,12 @@ export const verifyDiscordNicknameTool: Tool<
|
||||
expectedNickname,
|
||||
searchName,
|
||||
},
|
||||
"[VerifyDiscordNickname] No timeout budget left for lookup",
|
||||
'[VerifyDiscordNickname] No timeout budget left for lookup',
|
||||
);
|
||||
return {
|
||||
status: "lookup-unavailable" as const,
|
||||
message: "응답 시간이 부족해서 디스코드 조회를 건너뛰었어요. 다시 물어봐 주세요.",
|
||||
reason: "request-budget-exhausted" as const,
|
||||
status: 'lookup-unavailable' as const,
|
||||
message: '응답 시간이 부족해서 디스코드 조회를 건너뛰었어요. 다시 물어봐 주세요.',
|
||||
reason: 'request-budget-exhausted' as const,
|
||||
expectedNickname,
|
||||
searchName,
|
||||
};
|
||||
@@ -217,7 +211,7 @@ export const verifyDiscordNicknameTool: Tool<
|
||||
subject: getDiscordMemberLookupSubject(),
|
||||
timeoutMs,
|
||||
},
|
||||
"[VerifyDiscordNickname] Sending lookup request",
|
||||
'[VerifyDiscordNickname] Sending lookup request',
|
||||
);
|
||||
lookupResult = await ctx.natsClient.request<
|
||||
DiscordMemberLookupRequest,
|
||||
@@ -231,30 +225,30 @@ export const verifyDiscordNicknameTool: Tool<
|
||||
expectedNickname,
|
||||
searchName,
|
||||
},
|
||||
"[VerifyDiscordNickname] Lookup request failed",
|
||||
'[VerifyDiscordNickname] Lookup request failed',
|
||||
);
|
||||
return {
|
||||
status: "lookup-unavailable" as const,
|
||||
message: "디스코드 서버 조회 중 오류가 발생했어요. 잠시 후 다시 시도해주세요.",
|
||||
reason: "lookup-error" as const,
|
||||
status: 'lookup-unavailable' as const,
|
||||
message: '디스코드 서버 조회 중 오류가 발생했어요. 잠시 후 다시 시도해주세요.',
|
||||
reason: 'lookup-error' as const,
|
||||
expectedNickname,
|
||||
searchName,
|
||||
};
|
||||
}
|
||||
|
||||
if (lookupResult.status === "error") {
|
||||
if (lookupResult.status === 'error') {
|
||||
logger.debug(
|
||||
{
|
||||
expectedNickname,
|
||||
reason: lookupResult.reason,
|
||||
searchName,
|
||||
},
|
||||
"[VerifyDiscordNickname] Lookup service returned error",
|
||||
'[VerifyDiscordNickname] Lookup service returned error',
|
||||
);
|
||||
return {
|
||||
status: "lookup-unavailable" as const,
|
||||
message: "디스코드 서버에서 오류가 반환됐어요. 잠시 후 다시 시도해주세요.",
|
||||
reason: "lookup-error" as const,
|
||||
status: 'lookup-unavailable' as const,
|
||||
message: '디스코드 서버에서 오류가 반환됐어요. 잠시 후 다시 시도해주세요.',
|
||||
reason: 'lookup-error' as const,
|
||||
expectedNickname,
|
||||
searchName,
|
||||
};
|
||||
@@ -269,30 +263,27 @@ export const verifyDiscordNicknameTool: Tool<
|
||||
nicknameMatches: nicknameMatches.length,
|
||||
searchName,
|
||||
},
|
||||
"[VerifyDiscordNickname] Lookup response received",
|
||||
'[VerifyDiscordNickname] Lookup response received',
|
||||
);
|
||||
let candidate: DiscordMemberCandidate | null = null;
|
||||
let matchSource: "joined-after" | "nickname" | undefined;
|
||||
let matchSource: 'joined-after' | 'nickname' | undefined;
|
||||
let reason:
|
||||
| "joined-after-ambiguous"
|
||||
| "joined-after-none"
|
||||
| "nickname-search-ambiguous"
|
||||
| "nickname-search-none"
|
||||
| 'joined-after-ambiguous'
|
||||
| 'joined-after-none'
|
||||
| 'nickname-search-ambiguous'
|
||||
| 'nickname-search-none'
|
||||
| undefined;
|
||||
|
||||
if (nicknameMatches.length === 1) {
|
||||
candidate = nicknameMatches[0] ?? null;
|
||||
matchSource = "nickname";
|
||||
matchSource = 'nickname';
|
||||
} else if (nicknameMatches.length > 1) {
|
||||
reason = "nickname-search-ambiguous";
|
||||
reason = 'nickname-search-ambiguous';
|
||||
} else if (joinedAfterMatches.length === 1) {
|
||||
candidate = joinedAfterMatches[0] ?? null;
|
||||
matchSource = "joined-after";
|
||||
matchSource = 'joined-after';
|
||||
} else {
|
||||
reason =
|
||||
joinedAfterMatches.length === 0
|
||||
? "joined-after-none"
|
||||
: "joined-after-ambiguous";
|
||||
reason = joinedAfterMatches.length === 0 ? 'joined-after-none' : 'joined-after-ambiguous';
|
||||
}
|
||||
|
||||
if (!candidate) {
|
||||
@@ -303,21 +294,17 @@ export const verifyDiscordNicknameTool: Tool<
|
||||
nicknameMatchCount: nicknameMatches.length,
|
||||
reason:
|
||||
reason ??
|
||||
(nicknameMatches.length === 0
|
||||
? "nickname-search-none"
|
||||
: "nickname-search-ambiguous"),
|
||||
(nicknameMatches.length === 0 ? 'nickname-search-none' : 'nickname-search-ambiguous'),
|
||||
searchName,
|
||||
},
|
||||
"[VerifyDiscordNickname] Verification not confirmed",
|
||||
'[VerifyDiscordNickname] Verification not confirmed',
|
||||
);
|
||||
return {
|
||||
status: "not-confirmed" as const,
|
||||
status: 'not-confirmed' as const,
|
||||
message: `디스코드 서버에서 "${searchName}" 닉네임을 찾을 수 없었어요. 디스코드 서버에 가입했는지, 닉네임이 올바른지 확인해주세요.`,
|
||||
reason:
|
||||
reason ??
|
||||
(nicknameMatches.length === 0
|
||||
? "nickname-search-none"
|
||||
: "nickname-search-ambiguous"),
|
||||
(nicknameMatches.length === 0 ? 'nickname-search-none' : 'nickname-search-ambiguous'),
|
||||
expectedNickname,
|
||||
searchName,
|
||||
joinedAfterMatchCount: joinedAfterMatches.length,
|
||||
@@ -329,16 +316,14 @@ export const verifyDiscordNicknameTool: Tool<
|
||||
|
||||
const currentDisplayName = pickDisplayName(candidate);
|
||||
const currentGuildNickname = candidate.guildNickname?.trim();
|
||||
const isRenamed = matchesDiscordNicknameRule(
|
||||
currentGuildNickname,
|
||||
expectedNickname,
|
||||
);
|
||||
const status = isRenamed ? "matched-renamed" : "matched-pending-rename";
|
||||
const isRenamed = matchesDiscordNicknameRule(currentGuildNickname, expectedNickname);
|
||||
const status = isRenamed ? 'matched-renamed' : 'matched-pending-rename';
|
||||
const discordFormatGuide = `디스코드 서버 닉네임은 이름#태그/출생연도/티어 형식이에요. 카카오톡 형식과 달리 성별은 빼고 태그(#)가 들어가요. 예: ${DISCORD_NICKNAME_FORMAT_EXAMPLE}`;
|
||||
const message = isRenamed
|
||||
? "디스코드 서버 닉네임이 올바른 형식으로 설정되어 있어요. 확인 완료!"
|
||||
? '디스코드 서버 닉네임이 올바른 형식으로 설정되어 있어요. 확인 완료!'
|
||||
: currentGuildNickname
|
||||
? `디스코드에서 유저를 찾았지만 서버 닉네임이 아직 올바른 형식으로 확인되지는 않았어요. 현재 서버 닉네임은 "${currentGuildNickname}"으로 보여요. 이름#태그/출생연도/티어 형식인지 확인해주세요.`
|
||||
: `디스코드에서 유저를 찾았지만 서버 닉네임이 아직 설정되지 않았거나 확인되지 않았어요. 현재 표시 이름은 "${currentDisplayName}"으로 보여요. 서버 닉네임이 이름#태그/출생연도/티어 형식인지 확인해주세요.`;
|
||||
? `디스코드에서 유저를 찾았지만 서버 닉네임이 아직 올바른 형식으로 확인되지는 않았어요. 현재 서버 닉네임은 "${currentGuildNickname}"으로 보여요. ${discordFormatGuide}`
|
||||
: `디스코드에서 유저를 찾았지만 서버 닉네임이 아직 설정되지 않았거나 확인되지 않았어요. 현재 표시 이름은 "${currentDisplayName}"으로 보여요. ${discordFormatGuide}`;
|
||||
|
||||
logger.debug(
|
||||
{
|
||||
@@ -349,7 +334,7 @@ export const verifyDiscordNicknameTool: Tool<
|
||||
matchedBy: candidate.matchedBy,
|
||||
status,
|
||||
},
|
||||
"[VerifyDiscordNickname] Verification resolved",
|
||||
'[VerifyDiscordNickname] Verification resolved',
|
||||
);
|
||||
|
||||
return {
|
||||
|
||||
Reference in new issue
Block a user