fix(automod): flow real LLM analysis + descriptive fallback
Build & Deploy (Nix) / build-and-deploy (backend) (push) Successful in 3m2s
Build & Deploy (Nix) / build-and-deploy (discord-gateway) (push) Successful in 2m25s
Build & Deploy (Nix) / build-and-deploy (proxy) (push) Successful in 2m40s
Build & Deploy (Nix) / build-and-deploy (backend) (push) Successful in 3m2s
Build & Deploy (Nix) / build-and-deploy (discord-gateway) (push) Successful in 2m25s
Build & Deploy (Nix) / build-and-deploy (proxy) (push) Successful in 2m40s
Root cause: ai-analysis-worker read llmResult.explanation and llmResult.toxicityScore — fields the LLM pipeline never produces (canonical AnalysisResult uses analysis/score). Every message fell back to the bare template "Tidak ada indikasi pelanggaran." and the stored score was always 0. - Map analysis/score correctly; fallback now quotes the message content - Prompt: ban generic analysis phrasing, require reply context - LLM context: include replied-to message content (metadata.reference) so the model can explain what the user is replying to - Frontend: show thread/channel names from metadata instead of raw IDs (message card, detail views, search overlay); detail panel now displays the ai_analysis text - Auto-delete log/DM include the descriptive analysis as the reason
This commit is contained in:
@@ -43,3 +43,32 @@ export function safeParseJsonObject(
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a human-readable channel/thread label for a message.
|
||||
*
|
||||
* The channel name (and thread name, when the message lives in a thread)
|
||||
* is captured by the gateway into the message metadata JSON under
|
||||
* `metadata.channel.{channelName,threadName}`. Prefer names over raw IDs:
|
||||
* a thread message shows its thread name, otherwise the channel name,
|
||||
* falling back to a truncated channel ID only when names are unavailable.
|
||||
*/
|
||||
export function getMessageChannelLabel(msg: {
|
||||
channel_id?: string;
|
||||
metadata?: string | null;
|
||||
}): string {
|
||||
let channelName: string | undefined;
|
||||
let threadName: string | undefined;
|
||||
try {
|
||||
const m = JSON.parse(msg.metadata ?? "");
|
||||
const ch = m?.channel;
|
||||
channelName =
|
||||
typeof ch?.channelName === "string" ? ch.channelName : undefined;
|
||||
threadName = typeof ch?.threadName === "string" ? ch.threadName : undefined;
|
||||
} catch {
|
||||
// metadata malformed — fall through to ID fallback
|
||||
}
|
||||
if (threadName) return threadName;
|
||||
if (channelName) return channelName;
|
||||
return msg.channel_id?.slice(0, 8) ?? "";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user