"""Platform catalog APIs — durable org artifacts via server Connect RPC."""
import os
from collections.abc import Callable
from typing import Optional
from olo_protos.platform.v1 import platform_pb2
from olo.errors import OloPlatformNotConfigured
from olo.platform._transport import ConnectUnaryTransport
from olo.platform.types import (
BagInfo,
ImageCatalogInfo,
MapInfo,
NavConfigInfo,
NavConfigSource,
NavigationDeploymentInfo,
NavigationDesiredSpec,
NavigationDesiredState,
NavigationMode,
NavigationObservedState,
NavigationObservedStatus,
Pose2D,
CatalogLocation,
VideoCatalogInfo,
bag_from_proto,
deployment_from_proto,
image_catalog_from_proto,
map_from_proto,
nav_config_from_proto,
navigation_mode_to_proto,
video_catalog_from_proto,
)
NamespaceResolver = Callable[[Optional[str]], str]
ENV_PLATFORM_URL = "OLO_SDK_PLATFORM_URL"
ENV_PLATFORM_TOKEN = "OLO_SDK_PLATFORM_TOKEN"
ENV_ROBOT_ID = "OLO_SDK_ROBOT_ID"
_DEFAULT_TIMEOUT_SEC = 30.0
_SAVE_MAP_TIMEOUT_SEC = 65.0
def _resolve_config(
url: Optional[str],
token: Optional[str],
) -> tuple[str, str]:
resolved_url = (url or os.environ.get(ENV_PLATFORM_URL) or "").strip()
resolved_token = (token or os.environ.get(ENV_PLATFORM_TOKEN) or "").strip()
if not resolved_url or not resolved_token:
raise OloPlatformNotConfigured(
"client.platform requires OLO_SDK_PLATFORM_URL and OLO_SDK_PLATFORM_TOKEN "
"(or url=/token= kwargs). Create a personal access token at /developer."
)
return resolved_url, resolved_token
def resolve_robot_id(robot_id: Optional[str] = None) -> str:
"""Resolve the Platform robot UUID from an explicit value or ``OLO_SDK_ROBOT_ID``."""
resolved = (robot_id or os.environ.get(ENV_ROBOT_ID) or "").strip()
if not resolved:
raise OloPlatformNotConfigured(
"Platform robot id required. Pass robot_id=… or set OLO_SDK_ROBOT_ID "
"(injected automatically for Appliance-managed runs)."
)
return resolved
def _normalize_rpc_base(url: str) -> str:
"""Ensure the transport base ends with /rpc."""
trimmed = url.rstrip("/")
if trimmed.endswith("/rpc"):
return trimmed
return f"{trimmed}/rpc"
__all__ = [
"ENV_PLATFORM_TOKEN",
"ENV_PLATFORM_URL",
"ENV_ROBOT_ID",
"BagInfo",
"ImageCatalogInfo",
"MapInfo",
"NavConfigInfo",
"NavConfigSource",
"NavigationDeploymentInfo",
"NavigationDesiredSpec",
"NavigationDesiredState",
"NavigationMode",
"NavigationObservedState",
"NavigationObservedStatus",
"Platform",
"PlatformArchive",
"PlatformNavigation",
"Pose2D",
"CatalogLocation",
"VideoCatalogInfo",
"resolve_robot_id",
]