refactor(ai_client): 14 module globals → provider_state.get_history() pattern

This commit is contained in:
ed
2026-06-24 17:17:58 -04:00
parent 20236546d7
commit 25a2205722
2 changed files with 47 additions and 30 deletions
+27
View File
@@ -22,11 +22,28 @@ from dataclasses import dataclass, field
from src.type_aliases import HistoryMessage, Metadata
@dataclass
@dataclass
class ProviderHistory:
messages: list[HistoryMessage] = field(default_factory=list)
lock: threading.Lock = field(default_factory=threading.Lock)
def __bool__(self) -> bool:
with self.lock:
return bool(self.messages)
def __len__(self) -> int:
with self.lock:
return len(self.messages)
def __iter__(self):
with self.lock:
return iter(list(self.messages))
def __getitem__(self, idx):
with self.lock:
return self.messages[idx]
def append(self, message: HistoryMessage) -> None:
with self.lock:
self.messages.append(message)
@@ -54,6 +71,16 @@ _PROVIDER_HISTORIES: dict[str, ProviderHistory] = {
}
_PROVIDER_HISTORIES: dict[str, ProviderHistory] = {
"anthropic": ProviderHistory(),
"deepseek": ProviderHistory(),
"minimax": ProviderHistory(),
"qwen": ProviderHistory(),
"grok": ProviderHistory(),
"llama": ProviderHistory(),
}
def get_history(provider: str) -> ProviderHistory:
if provider not in _PROVIDER_HISTORIES:
raise KeyError(f"Unknown provider: {provider!r}")