5a581c78a2
Build / build (push) Has been cancelled
Docker / build (push) Has been cancelled
Lint / ruff (push) Has been cancelled
Test / pytest (ubuntu-latest, 3.11) (push) Has been cancelled
Test / pytest (ubuntu-latest, 3.12) (push) Has been cancelled
Test / pytest (windows-latest, 3.11) (push) Has been cancelled
Test / pytest (windows-latest, 3.12) (push) Has been cancelled
Introduce provider, model, and invocation contracts with encrypted configuration persistence. Add web runtime fencing, route fallback, recovery middleware, workspace scoping, and comprehensive tests.
71 lines
2.5 KiB
Python
71 lines
2.5 KiB
Python
"""Shared LangGraph SDK plumbing for the local langgraph-dev server."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
from collections.abc import Mapping
|
|
|
|
DEFAULT_LANGGRAPH_DEV_PORT = 3076
|
|
LANGGRAPH_DEV_AUTH_HEADERS = {"x-auth-scheme": "langsmith"}
|
|
|
|
|
|
def langgraph_dev_url(config: object | None = None, *, port: int | None = None) -> str:
|
|
"""Return the local langgraph-dev base URL for a config or explicit port."""
|
|
runtime_url = os.environ.get("LANGGRAPH_SERVER_URL", "").strip().rstrip("/")
|
|
if port is None and runtime_url:
|
|
return runtime_url
|
|
selected_port = (
|
|
int(port)
|
|
if port is not None
|
|
else int(getattr(config, "langgraph_dev_port", DEFAULT_LANGGRAPH_DEV_PORT))
|
|
)
|
|
return f"http://localhost:{selected_port}"
|
|
|
|
|
|
def configured_langgraph_dev_url() -> str:
|
|
"""Return the local langgraph-dev URL from the effective application config."""
|
|
from ..EvoScientist import _ensure_config
|
|
|
|
return langgraph_dev_url(_ensure_config())
|
|
|
|
|
|
def langgraph_dev_headers(headers: Mapping[str, str] | None = None) -> dict[str, str]:
|
|
"""Return SDK headers, defaulting to the local langgraph-dev auth scheme."""
|
|
return dict(LANGGRAPH_DEV_AUTH_HEADERS if headers is None else headers)
|
|
|
|
|
|
def get_langgraph_sync_client(*, url: str, headers: Mapping[str, str] | None = None):
|
|
"""Build a sync LangGraph SDK client with EvoScientist's default headers."""
|
|
from langgraph_sdk import get_sync_client
|
|
|
|
return get_sync_client(url=url, headers=langgraph_dev_headers(headers))
|
|
|
|
|
|
def get_langgraph_async_client(*, url: str, headers: Mapping[str, str] | None = None):
|
|
"""Build an async LangGraph SDK client with EvoScientist's default headers."""
|
|
from langgraph_sdk import get_client
|
|
|
|
return get_client(url=url, headers=langgraph_dev_headers(headers))
|
|
|
|
|
|
def default_scheduler_timezone(config: object | None = None) -> str | None:
|
|
"""Return configured scheduler timezone, falling back to the host timezone."""
|
|
if config is None:
|
|
from ..EvoScientist import _ensure_config
|
|
|
|
config = _ensure_config()
|
|
timezone = str(getattr(config, "scheduler_default_timezone", "") or "")
|
|
if timezone:
|
|
return timezone
|
|
try:
|
|
from tzlocal import get_localzone_name
|
|
|
|
return get_localzone_name()
|
|
except Exception:
|
|
return None
|
|
|
|
|
|
def messages_input(content: str) -> dict[str, list[dict[str, str]]]:
|
|
"""Return the standard LangGraph chat input shape for one user message."""
|
|
return {"messages": [{"role": "user", "content": content}]}
|