24 lines
1.0 KiB
Python
24 lines
1.0 KiB
Python
"""Database-backed sys_config and audit adapters for客服 Agent runtime."""
|
|||
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
from repositories.sys_config import SysConfigRepo
|
||
|
|
from service.customer_agent.audit import write_anonymous_sensitive_audit
|
||
|
|
|
||
|
|
|
||
|
|
class DatabaseConfigProvider:
|
||
|
|
def __init__(self, *, session_factory, repo_factory=SysConfigRepo):
|
||
|
|
self.session_factory = session_factory
|
||
|
|
self.repo_factory = repo_factory
|
||
|
|
|
||
|
|
async def get(self, key: str, default: str | None = None) -> str | None:
|
||
|
|
async with self.session_factory() as session:
|
||
|
|
return await self.repo_factory(session).get_value(key, default)
|
||
|
|
|
||
|
|
async def write_audit(self, *, action: str, trace_id: str, session_id: str):
|
||
|
|
if action != "anon_sensitive_input":
|
||
|
|
raise ValueError(f"Unsupported anonymous audit action: {action}")
|
||
|
|
async with self.session_factory() as session:
|
||
|
|
await write_anonymous_sensitive_audit(
|
||
|
|
session, session_id=session_id, trace_id=trace_id
|
||
|
|
)
|