fix: wire PII redaction + token empty warnings for plugin platforms

PII redaction: build_session_context_prompt() now checks the plugin
registry's pii_safe flag in addition to the hardcoded _PII_SAFE_PLATFORMS
frozenset. Plugin platforms that set pii_safe=True (e.g. phone-based
messaging bridges) get their user IDs redacted before LLM context.

Token empty warnings: the empty-token diagnostic at config load now
checks the plugin registry's required_env when a platform isn't in the
hardcoded _token_env_names dict. Catches 'enabled but empty' for
plugin platforms too.
This commit is contained in:
Teknium 2026-04-11 15:34:59 -07:00 committed by Teknium
parent 2e20f6ae2d
commit 457128d4e8
2 changed files with 32 additions and 13 deletions

View file

@ -891,6 +891,15 @@ def _validate_gateway_config(config: "GatewayConfig") -> None:
if not pconfig.enabled: if not pconfig.enabled:
continue continue
env_name = _token_env_names.get(platform) env_name = _token_env_names.get(platform)
if not env_name:
# Check plugin registry for required_env
try:
from gateway.platform_registry import platform_registry
entry = platform_registry.get(platform.value)
if entry and entry.required_env:
env_name = entry.required_env[0] # primary env var
except Exception:
pass
if env_name and pconfig.token is not None and not pconfig.token.strip(): if env_name and pconfig.token is not None and not pconfig.token.strip():
logger.warning( logger.warning(
"%s is enabled but %s is empty. " "%s is enabled but %s is empty. "

View file

@ -246,8 +246,18 @@ def build_session_context_prompt(
Platforms like Discord are excluded because mentions need real IDs. Platforms like Discord are excluded because mentions need real IDs.
Routing still uses the original values (they stay in SessionSource). Routing still uses the original values (they stay in SessionSource).
""" """
# Only apply redaction on platforms where IDs aren't needed for mentions # Only apply redaction on platforms where IDs aren't needed for mentions.
redact_pii = redact_pii and context.source.platform in _PII_SAFE_PLATFORMS # Check both the hardcoded set (builtins) and the plugin registry.
_is_pii_safe = context.source.platform in _PII_SAFE_PLATFORMS
if not _is_pii_safe:
try:
from gateway.platform_registry import platform_registry
entry = platform_registry.get(context.source.platform.value)
if entry and entry.pii_safe:
_is_pii_safe = True
except Exception:
pass
redact_pii = redact_pii and _is_pii_safe
lines = [ lines = [
"## Current Session Context", "## Current Session Context",
"", "",