__init__.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. """Connector integration boundary for managed gateway accounts and local MCP servers.
  2. Only the names below are cross-package surface; imports beyond it need a design decision.
  3. Siblings: ``contract`` (states, actors, transition table), ``operation`` (the record),
  4. ``live`` (open operation per session), ``run`` (the lifecycle loop), ``managed`` / ``mcp``
  5. (per-kind hooks), ``targets``, ``search``, ``dispatch``, ``gateway/`` (HTTP wire + client).
  6. The surface is exported lazily (PEP 562): eager submodule imports here deadlocked the
  7. concurrent registry scan and the Group Chat worker (see test_connectors_import_deadlock.py).
  8. """
  9. import importlib
  10. # name -> module owning it: the single source of truth for __all__ and __getattr__.
  11. _LAZY_EXPORTS: dict[str, str] = {
  12. "CONNECTOR_BATCH_SENTINEL": "tools.connectors.gateway.names",
  13. "MANAGE_CONNECTIONS_SCHEMA": "tools.connectors.tool",
  14. "connector_describe": "tools.connectors.gateway.bridge",
  15. "connector_search_hits": "tools.connectors.gateway.bridge",
  16. "connectors_available": "tools.connectors.gateway.config",
  17. "dispatch_connector_batch": "tools.connectors.dispatch",
  18. "dispatch_connector_call": "tools.connectors.dispatch",
  19. "ensure_guest_identity": "tools.connectors.gateway.config",
  20. "guest_identity_pending": "tools.connectors.gateway.config",
  21. "is_connector_name": "tools.connectors.gateway.names",
  22. "manage_connections": "tools.connectors.tool",
  23. }
  24. __all__ = sorted(_LAZY_EXPORTS)
  25. def __getattr__(name: str):
  26. """Resolve and cache a public name on first access (PEP 562)."""
  27. module_name = _LAZY_EXPORTS.get(name)
  28. if module_name is None:
  29. raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
  30. value = getattr(importlib.import_module(module_name), name)
  31. globals()[name] = value
  32. return value
  33. def __dir__() -> list[str]:
  34. return sorted(set(globals()) | set(__all__))