import type { HandoffPacket } from "@agent/handoff-packet"; export interface SupervisorRuleRoute { confidence: number; target: string | null; } const RULES = [ { pattern: /(규칙|신고|제재|경고|욕설|광고|홍보|appeal|policy|moderation)/iu, target: "moderation", }, { pattern: /(가입|닉네임|하트|인증|디스코드|온보딩|onboarding)/iu, target: "onboarding", }, ] as const; function packetText(packet: HandoffPacket | undefined): string { return [ packet?.userGoal, packet?.summary, packet?.handoffReason, ].join(" "); } export function routeSupervisorByRules( packet: HandoffPacket | undefined, ): SupervisorRuleRoute { const text = packetText(packet); const matches = RULES.filter((rule) => rule.pattern.test(text)); if (matches.length === 1) { return { confidence: 0.9, target: matches[0]?.target ?? null, }; } if (matches.length > 1) { return { confidence: 0.6, target: matches[0]?.target ?? null, }; } return { confidence: 0, target: null, }; } export function routeSupervisorTarget(packet: HandoffPacket | undefined): string | null { return routeSupervisorByRules(packet).target; }