Show the language model's opinion on a message
ci / version (pull_request) Skipped
ci / node (pull_request) Successful in 2m23s
ci / publish (pull_request) Skipped
ci / docker-build (pull_request) Successful in 1m24s

When inbuxa-server's AI spam classification is on, it records the model's
answer in an X-Spam-LLM header: a tag (LLM_<category>[_<confidence>]) and,
in parentheses, the model's explanation. The full message now asks for it,
and where it's there:

- the message details show "Language model's opinion" beside the spam
  filter's own working, with category, confidence and explanation;
- a message in Junk carries a banner saying the same.

Both say it's one of several signals the spam filter weighed, never the
reason on its own, as the server's spec requires. The explanation is model
output and is only ever rendered as text. Nothing shows without the header,
so a server without the feature, or with it off, looks as before.

Translations: two new strings, "Language model's opinion" and "One of
several signals the spam filter weighed", in all eight catalogues (16
entries). Category and confidence come from the server and aren't
translated.
This commit is contained in:
jcoffey-dev committed 2026-09-22 22:03:29 -07:00
1 parent c0c892dd33
commit e4926cfa7d
17 files changed
+319

No files matched your search

+67
View File
@@ -0,0 +1,67 @@
import { Bot } from "lucide-react";
import type { LlmOpinion } from "@/lib/llmOpinion";
import { t as translate } from "@/lib/i18n";
/*
* inbuxa: the language model's opinion on a message, where the server's AI
* spam classification recorded one (lib/llmOpinion).
*
* Two rules, both from the server's spec. It is always labeled as one signal
* the spam filter weighed among several, never as the reason a message was
* filed where it was: the model can add a bounded amount to the score and no
* more. And the explanation is the model's own output, so it is only ever
* rendered as text.
*
* The category and confidence come from the server's configuration and aren't
* translated; only the two framing strings are.
*/
function Verdict({ opinion }: { opinion: LlmOpinion }) {
return (
<>
<strong>{opinion.category}</strong>
{opinion.confidence && <span className="hint">{` · ${opinion.confidence}`}</span>}
</>
);
}
/** In the message details, beside the spam filter's own working. */
export function LlmOpinionDetail({ opinion }: { opinion: LlmOpinion }) {
return (
<div className="llm-opinion">
<div>
<Verdict opinion={opinion} />
</div>
{opinion.explanation && <div className="llm-explanation">{opinion.explanation}</div>}
<div className="hint">{translate("One of several signals the spam filter weighed")}</div>
</div>
);
}
/** Above a message that's in Junk. */
export function LlmOpinionBanner({ opinion }: { opinion: LlmOpinion }) {
return (
<div className="remote-banner llm-banner" role="note" style={{ margin: "0 16px 8px" }}>
<Bot size={16} />
<span className="grow llm-opinion">
<span className="llm-heading">
<span>{translate("Language model's opinion")}</span>
<span>
<Verdict opinion={opinion} />
</span>
</span>
{opinion.explanation && <span className="llm-explanation">{opinion.explanation}</span>}
<span className="hint">{translate("One of several signals the spam filter weighed")}</span>
</span>
</div>
);
}
/** The banner shows only for a message in Junk that carries an opinion. */
export function llmBannerOpinion(
opinion: LlmOpinion | null,
mailboxIds: Record<string, boolean>,
junkId: string | null | undefined,
): LlmOpinion | null {
return opinion && junkId && mailboxIds[junkId] ? opinion : null;
}