mirror of
https://github.com/chenyme/grok2api.git
synced 2026-12-05 08:01:07 +00:00
50 lines
1.4 KiB
Python
50 lines
1.4 KiB
Python
"""ProxyRuntime — thin hot-path wrapper around ProxyDirectory.
|
|
|
|
Delegates acquisition and feedback to the control-plane ProxyDirectory.
|
|
Kept as a thin shim so callers in the dataplane need not import control
|
|
modules directly.
|
|
"""
|
|
|
|
from app.control.proxy import ProxyDirectory, get_proxy_directory
|
|
from app.control.proxy.models import (
|
|
ProxyLease, ProxyFeedback, ProxyScope, RequestKind,
|
|
)
|
|
|
|
|
|
class ProxyRuntime:
|
|
"""Hot-path facade around ProxyDirectory."""
|
|
|
|
def __init__(self, directory: ProxyDirectory) -> None:
|
|
self._dir = directory
|
|
|
|
async def acquire(
|
|
self,
|
|
*,
|
|
scope: ProxyScope = ProxyScope.APP,
|
|
kind: RequestKind = RequestKind.HTTP,
|
|
resource: bool = False,
|
|
) -> ProxyLease:
|
|
return await self._dir.acquire(scope=scope, kind=kind, resource=resource)
|
|
|
|
async def feedback(self, lease: ProxyLease, result: ProxyFeedback) -> None:
|
|
await self._dir.feedback(lease, result)
|
|
|
|
@property
|
|
def has_proxy(self) -> bool:
|
|
from app.control.proxy.models import EgressMode
|
|
return self._dir.egress_mode != EgressMode.DIRECT
|
|
|
|
|
|
_runtime: ProxyRuntime | None = None
|
|
|
|
|
|
async def get_proxy_runtime() -> ProxyRuntime:
|
|
global _runtime
|
|
if _runtime is None:
|
|
directory = await get_proxy_directory()
|
|
_runtime = ProxyRuntime(directory)
|
|
return _runtime
|
|
|
|
|
|
__all__ = ["ProxyRuntime", "get_proxy_runtime"]
|