feat(api): _deps factories for Open3DModel client + recipe cache
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
87abe26476
commit
430e342c48
1 file changed
+31
-1
@@ -3,12 +3,19 @@ updates (PUT /api/config) take effect without restart."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from ..clients import G1Client, MarkerClient, NuwaClient, Sam21Client, YoloClient
|
||||
from ..clients import (
|
||||
G1Client, MarkerClient, NuwaClient,
|
||||
Open3DModelClient, Sam21Client, YoloClient,
|
||||
)
|
||||
from ..clients.open3dmodel_cache import RecipeMeshCache
|
||||
from ..config import data_dir, get_config
|
||||
|
||||
_recipe_cache_singleton: RecipeMeshCache | None = None
|
||||
|
||||
|
||||
def _svc(cfg: dict[str, Any], key: str) -> dict[str, Any]:
|
||||
return cfg.get("services", {}).get(key, {})
|
||||
@@ -37,6 +44,29 @@ def sam21() -> Sam21Client:
|
||||
)
|
||||
|
||||
|
||||
def open3dmodel() -> Open3DModelClient:
|
||||
cfg = get_config()
|
||||
c = _svc(cfg, "open3dmodel")
|
||||
api_key_env = c.get("api_key_env")
|
||||
api_key = os.environ.get(api_key_env) if api_key_env else None
|
||||
return Open3DModelClient(
|
||||
base_url=c.get("base_url", "http://localhost:8878"),
|
||||
api_key=api_key,
|
||||
timeout_s=float(c.get("timeout_s", 30.0)),
|
||||
max_stl_bytes=int(c.get("max_stl_bytes", 20_000_000)),
|
||||
)
|
||||
|
||||
|
||||
def recipe_cache() -> RecipeMeshCache:
|
||||
"""Singleton mesh cache. Sopravvive a PUT /api/config; etag stale forza
|
||||
refetch al prossimo accesso. Inizializzata lazy con il client corrente
|
||||
al momento della prima get."""
|
||||
global _recipe_cache_singleton
|
||||
if _recipe_cache_singleton is None:
|
||||
_recipe_cache_singleton = RecipeMeshCache(open3dmodel(), capacity=8)
|
||||
return _recipe_cache_singleton
|
||||
|
||||
|
||||
def active_robot_key() -> str:
|
||||
"""Which robot the orchestrator is currently bound to ('g1' or 'h1').
|
||||
Read from `robot.active` in config; defaults to 'g1' for backward compat."""
|
||||
|
||||
Reference in new issue
Block a user