Skip to main content

WebSocket coordination hub: handler registry, job cache, event broadcast, client

Project description

nodus-gateway

WebSocket coordination hub for Nodus AI systems.

A typed message exchange point where agents, channels, and tools connect to send RequestEnvelope / ResponseEnvelope / EventEnvelope messages. Provides handler dispatch, idempotency caching, event broadcasting, and an async client. No required dependencies — WebSocket transport is optional.

Status: v0.1.0 — published on PyPI.


Install

pip install nodus-gateway

# With WebSocket transport:
pip install "nodus-gateway[websockets]"

What it provides

Component Purpose
GatewayServer WebSocket server; registers handlers, dispatches requests
HandlerRegistry Maps method names → async handler functions
JobResultCache Idempotent result cache with TTL (dedup concurrent requests)
EventBroadcaster Fan-out execution events to all subscribers
GatewayClient Async client for connecting to a GatewayServer

GatewayServer

from nodus_gateway import GatewayServer, HandlerRegistry

registry = HandlerRegistry()

@registry.register("agent.run")
async def handle_agent_run(params: dict) -> dict:
    return {"status": "ok", "run_id": "run-123"}

server = GatewayServer(host="127.0.0.1", port=18789, registry=registry)
await server.start()   # blocks until stopped
# await server.stop()

Requires pip install "nodus-gateway[websockets]" for the WebSocket transport. Without websockets installed, GatewayServer raises ImportError on start.


HandlerRegistry

from nodus_gateway import HandlerRegistry

registry = HandlerRegistry()

# Decorator form
@registry.register("memory.read")
async def handle_memory_read(params: dict) -> dict:
    return {"value": "..."}

# Imperative form
registry.register("memory.write", handle_write)

handler = registry.get("memory.read")   # callable | None
methods = registry.list_methods()        # list[str]
registry.unregister("memory.read")

JobResultCache

from nodus_gateway import JobResultCache

cache = JobResultCache(ttl_seconds=300)

# Store and retrieve results by job ID
cache.set("job-abc", {"result": "done"})
result = cache.get("job-abc")    # dict | None (None if expired)
cache.evict_expired()            # remove expired entries
len(cache)

Used internally by GatewayServer to make concurrent duplicate requests idempotent — only the first call executes; subsequent calls get the cached result.


EventBroadcaster

from nodus_gateway import EventBroadcaster

broadcaster = EventBroadcaster()

def my_handler(event: dict) -> None:
    print(event["type"], event["payload"])

sub_id = broadcaster.subscribe(my_handler)
broadcaster.broadcast({"type": "flow.completed", "payload": {"id": "f1"}})
broadcaster.unsubscribe(sub_id)

GatewayClient

from nodus_gateway import GatewayClient

async with GatewayClient("ws://127.0.0.1:18789") as client:
    response = await client.send("agent.run", {"objective": "hello"})
    # response is the handler's return value

    # Subscribe to events
    client.subscribe(lambda event: print(event))

Requires websockets for the actual WebSocket connection.


Design

  • No required dependencies. Core components (HandlerRegistry, JobResultCache, EventBroadcaster) are pure stdlib. WebSocket transport is opt-in.
  • Thread-safe. JobResultCache and EventBroadcaster use threading.Lock.
  • Idempotent dispatch. JobResultCache deduplicates concurrent requests with the same job ID.

Development

pip install -e ".[dev]"
pytest tests/ -q

License

MIT — see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nodus_gateway-0.1.1.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nodus_gateway-0.1.1-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file nodus_gateway-0.1.1.tar.gz.

File metadata

  • Download URL: nodus_gateway-0.1.1.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for nodus_gateway-0.1.1.tar.gz
Algorithm Hash digest
SHA256 546a20a048039cd2ec3ce608f1bbde8afa004222eac0136d730ed692f4808c13
MD5 8554036e5f793525275dca0c8f4795b3
BLAKE2b-256 4b48614ed3bafd7b2d8a372f38367be1ad49ac27365b72d4c287bcf993248fb8

See more details on using hashes here.

File details

Details for the file nodus_gateway-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: nodus_gateway-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for nodus_gateway-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5663ddb7293f63d564616f293c4a1aeca0ce0d8dbc558351f1852a7bc26aae06
MD5 f34eb0ef382ebf521130ac49c4608726
BLAKE2b-256 6d5eab0c6e800d92e59c3446be581b0b8b0fe32d7a0c0ac5ec03d0597a0f262c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page