P0: fix doc:// -> docs:// across standards src/server/registry and regenerate stale mongo-ops bundle. P1: build recipe + spec-first routing now document the openapi-first codegen fast path (models/routes with --inject-request/--package). P4: CRUD template documents the model-vs-document id rule (BaseDocument owns id). P5: authless guidance (omit security keys). P6: template gains generic infra (http_cache, keyed SSE bus, KV port+in-memory+Redis), interfaces/openapi.py + .dockerignore + generic build test registered as components, and a get_app_template tool; genericity matrix marks LLM pool + human-in-loop as reference-app patterns. P7: intake/build/start_app/trial prompts. P8: template ships tests/integration/test_openapi_app_builds.py. Rebuilt standards + openapi-first bundles and re-collected.
55 lines
1.5 KiB
Python
55 lines
1.5 KiB
Python
"""# Summary
|
|
|
|
SSEInMemoryBus — in-memory event bus for SSE progress events.
|
|
|
|
---
|
|
|
|
Buffer published progress events so they can be replayed (and streamed) per
|
|
correlation key, such as a job, upload, or fetch-request id.
|
|
"""
|
|
from typing import Generic, List, TypeVar
|
|
|
|
T = TypeVar("T")
|
|
|
|
|
|
class SSEInMemoryBus(Generic[T]):
|
|
"""Buffer SSE progress events in memory, keyed by an event attribute.
|
|
|
|
Attributes:
|
|
_events (List[T]): Events published since the last clear.
|
|
_key_attr (str): Event attribute used to correlate a stream.
|
|
"""
|
|
|
|
def __init__(self, key_attr: str = "id"):
|
|
"""Initialize an empty event buffer.
|
|
|
|
Args:
|
|
key_attr (str): Attribute name on each event holding the stream
|
|
correlation key (for example ``"job_id"``).
|
|
"""
|
|
self._events: List[T] = []
|
|
self._key_attr = key_attr
|
|
|
|
async def publish(self, event: T) -> None:
|
|
"""Append an event to the buffer.
|
|
|
|
Args:
|
|
event (T): Event to append.
|
|
"""
|
|
self._events.append(event)
|
|
|
|
def get_events(self, key: str) -> List[T]:
|
|
"""Return buffered events for a correlation key.
|
|
|
|
Args:
|
|
key (str): Value matched against the configured ``key_attr``.
|
|
|
|
Returns:
|
|
List[T]: Events whose ``key_attr`` equals ``key``.
|
|
"""
|
|
return [e for e in self._events if getattr(e, self._key_attr, None) == key]
|
|
|
|
def clear(self) -> None:
|
|
"""Remove all buffered events."""
|
|
self._events.clear()
|