- Tool interface declares required permissions via requires field - scoped-context builds a least-privileged ToolContext per call - ToolAuditLogger appends each tool invocation to a Garnet stream - Operations CLI gains tool-audit:list and tool-audit:show commands - All onboarding and moderation tools annotated with explicit requires
129 lines
3.7 KiB
TypeScript
129 lines
3.7 KiB
TypeScript
import { z } from "zod";
|
|
import {
|
|
getRagEnabled,
|
|
getRagHybridEnabled,
|
|
getRagRerankerEnabled,
|
|
} from "../../config.js";
|
|
import { getRequestLogger } from "../../observability/context.js";
|
|
import {
|
|
DEADLINE_NEAR_THRESHOLD_MIN,
|
|
DISCORD_GUIDE_TEXT,
|
|
HEART_RULE_TEXT,
|
|
MIN_AGE,
|
|
NICKNAME_FORMAT_TEXT,
|
|
TIER_CODES_TEXT,
|
|
} from "@skills/onboarding/constants";
|
|
import type { Tool } from "../tool.js";
|
|
|
|
const argsSchema = z.object({
|
|
topic: z.string().min(1).describe("검색할 온보딩 규칙 주제"),
|
|
topK: z.number().int().min(1).max(10).optional(),
|
|
});
|
|
|
|
const resultSchema = z.object({
|
|
topic: argsSchema.shape.topic,
|
|
text: z.string(),
|
|
source: z.enum(["constants", "knowledge_documents"]),
|
|
matches: z
|
|
.array(
|
|
z.object({
|
|
id: z.string(),
|
|
score: z.number(),
|
|
text: z.string(),
|
|
}),
|
|
)
|
|
.optional(),
|
|
});
|
|
|
|
type LegacyTopic =
|
|
| "age"
|
|
| "tier-codes"
|
|
| "discord-link"
|
|
| "heart-rule"
|
|
| "nickname-format"
|
|
| "deadline";
|
|
|
|
const TOPIC_TEXT: Record<LegacyTopic, string> = {
|
|
age: `가입 가능 연령은 ${MIN_AGE}세 이상이에요.`,
|
|
"tier-codes": `사용 가능한 티어 코드는 ${TIER_CODES_TEXT}예요.`,
|
|
"discord-link": DISCORD_GUIDE_TEXT,
|
|
"heart-rule": HEART_RULE_TEXT,
|
|
"nickname-format": NICKNAME_FORMAT_TEXT,
|
|
deadline: `데드라인이 ${DEADLINE_NEAR_THRESHOLD_MIN}분 이하로 남으면 마감이 임박한 상태로 안내해요.`,
|
|
};
|
|
|
|
function resolveLegacyTopic(topic: string): LegacyTopic | null {
|
|
if (
|
|
topic === "age" ||
|
|
topic === "tier-codes" ||
|
|
topic === "discord-link" ||
|
|
topic === "heart-rule" ||
|
|
topic === "nickname-format" ||
|
|
topic === "deadline"
|
|
) {
|
|
return topic;
|
|
}
|
|
if (/(나이|연령|age)/iu.test(topic)) return "age";
|
|
if (/(티어|tier|랭크)/iu.test(topic)) return "tier-codes";
|
|
if (/(디스코드|디코|discord)/iu.test(topic)) return "discord-link";
|
|
if (/(하트|인증|사진|heart)/iu.test(topic)) return "heart-rule";
|
|
if (/(닉네임|형식|이름|nickname)/iu.test(topic)) return "nickname-format";
|
|
if (/(마감|데드라인|deadline|시간)/iu.test(topic)) return "deadline";
|
|
return null;
|
|
}
|
|
|
|
function legacyLookupCommunityRule(topic: string): z.infer<typeof resultSchema> {
|
|
const resolved = resolveLegacyTopic(topic);
|
|
return {
|
|
topic,
|
|
text: resolved
|
|
? TOPIC_TEXT[resolved]
|
|
: Object.values(TOPIC_TEXT).join("\n"),
|
|
source: "constants",
|
|
};
|
|
}
|
|
|
|
export const lookupCommunityRuleTool: Tool<
|
|
z.infer<typeof argsSchema>,
|
|
z.infer<typeof resultSchema>
|
|
> = {
|
|
name: "lookup-community-rule",
|
|
description:
|
|
"나이 제한, 닉네임 형식, 티어 코드, 하트 인증 규칙, 디스코드 안내 같은 커뮤니티 규칙을 조회한다.",
|
|
requires: ["memory-search"],
|
|
argsSchema,
|
|
resultSchema,
|
|
async execute(args, ctx) {
|
|
if (ctx.memoryService && getRagEnabled()) {
|
|
try {
|
|
const docs = await ctx.memoryService.longTerm.search(args.topic, {
|
|
category: "onboarding-step",
|
|
hybrid: getRagHybridEnabled(),
|
|
rerank: getRagRerankerEnabled(),
|
|
skill: "onboarding",
|
|
topK: args.topK ?? 3,
|
|
});
|
|
if (docs.length > 0) {
|
|
return {
|
|
topic: args.topic,
|
|
text: docs.map((doc) => doc.text).join("\n\n"),
|
|
source: "knowledge_documents",
|
|
matches: docs.map((doc) => ({
|
|
id: doc.id,
|
|
score: doc.score,
|
|
text: doc.text,
|
|
})),
|
|
};
|
|
}
|
|
} catch (error) {
|
|
getRequestLogger().warn(
|
|
{ err: error, topic: args.topic },
|
|
"[lookup-community-rule] Knowledge retrieval failed; using constants",
|
|
);
|
|
}
|
|
}
|
|
|
|
return legacyLookupCommunityRule(args.topic);
|
|
},
|
|
};
|