diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fbe268e..eed62ccf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ # Changelog + ## [Unreleased] **Multi-agent grouping.** How many agents share a process becomes a *deployment* parameter rather @@ -367,6 +368,9 @@ Full migration path, including the one decision to get right before the first de behaviour except `scheduler_mode`, which is required — see **Breaking**. - `pyyaml>=6.0` is now a declared dependency (it reads the group file). Already present in every environment via `uvicorn[standard]`, so no installed set changes. +- **`@RestApiBase.head(path, **kwargs)`** registers a HEAD route, like the other verb decorators + (#63). A service that needed one, for a cheap existence check before a GET, had to write its own + decorator. ### Changed @@ -401,6 +405,18 @@ Full migration path, including the one decision to get right before the first de ### Fixed +- **A handler that returns an `event_type` no longer fails its delivery where nothing can publish + it** (#40). A publishing service exists only beside an event-bus client, so with + `event_bus = "sessions"`, or without an event bus, the lookup raised after the handler had + finished, and every successful job was logged as `Unexpected error processing job` at ERROR. The + event is now skipped: a WARNING names the agent and the `event_type` once, later ones log at + DEBUG, and the delivery counts as processed. Two publishing services at one level still fail it. +- **The `/` service page lists the routes again** (#42). Since FastAPI 0.137, `include_router()` + leaves a wrapper in `app.routes` instead of the routes, and the page found none of them: every + route the framework mounts comes from an included router, so the table was empty. It is now built + from the OpenAPI schema, which works on every supported FastAPI version. A route declared with + `include_in_schema=False` is no longer listed, and an operation without a summary shows the one + FastAPI generates from the function name, as Swagger UI does. - **`asbs validate` no longer fails an image build on an unset `nats_url`.** Outside development it reported one as an issue, and an image that validates while it is built has no `nats_url` yet: the deployment injects it when the container starts. It is a notice now, as `event_bus` is; the diff --git a/README.md b/README.md index 61d90d2d..cb6d3f3c 100644 --- a/README.md +++ b/README.md @@ -149,7 +149,7 @@ Two things about that chain are worth knowing up front: |-----------|-----------|---------| | **Event Handler** | `EventHandlerBase` | Route CloudEvents (priority chain) and translate each into one service call; returns a result, `HandlerResult.skipped(reason)` or `None` | | **Service** | `ServiceBase` | All business logic, including whether an event needs work; runs the agents | -| **REST API** | `RestApiBase` | Define HTTP endpoints with `@get()`, `@post()`, `@put()`, `@delete()`, `@patch()` decorators | +| **REST API** | `RestApiBase` | Define HTTP endpoints with `@get()`, `@post()`, `@put()`, `@delete()`, `@patch()`, `@head()` decorators | | **Agent** | `AgentRuntime` | Run LLM agents with structured outputs, tool calling, and prompt management | | **Scheduler** | `SchedulerBase` | Execute cron-based background tasks with auto-registered trigger endpoints | diff --git a/src/blueprint/agent_generator/claude_docs/CLAUDE.md b/src/blueprint/agent_generator/claude_docs/CLAUDE.md index 57039147..720ef6b9 100644 --- a/src/blueprint/agent_generator/claude_docs/CLAUDE.md +++ b/src/blueprint/agent_generator/claude_docs/CLAUDE.md @@ -178,7 +178,7 @@ class OrderApi(RestApiBase): return await self._service.create(payload) ``` -Route decorators: `@RestApiBase.get()`, `.post()`, `.put()`, `.delete()`, `.patch()`. +Route decorators: `@RestApiBase.get()`, `.post()`, `.put()`, `.delete()`, `.patch()`, `.head()`. **Creating CloudEvents from REST payloads** — use `create_cloud_event()` when an API endpoint needs to feed a payload into the event processing pipeline: diff --git a/src/blueprint/agent_generator/claude_docs/skills/add-component/SKILL.md b/src/blueprint/agent_generator/claude_docs/skills/add-component/SKILL.md index 1d19cb3c..524d3567 100644 --- a/src/blueprint/agent_generator/claude_docs/skills/add-component/SKILL.md +++ b/src/blueprint/agent_generator/claude_docs/skills/add-component/SKILL.md @@ -62,7 +62,7 @@ After scaffolding, implement the component logic: - Resolve agent/cache dependencies in `on_startup()` ### RestApi -- Use `@RestApiBase.get/post/put/delete/patch()` decorators +- Use `@RestApiBase.get/post/put/delete/patch/head()` decorators - Use Pydantic models for request/response types - Resolve services in `on_startup()` diff --git a/src/blueprint/agent_generator/docs/reference/api.md b/src/blueprint/agent_generator/docs/reference/api.md index 8d446624..2fa57e54 100644 --- a/src/blueprint/agent_generator/docs/reference/api.md +++ b/src/blueprint/agent_generator/docs/reference/api.md @@ -262,6 +262,7 @@ Use these to decorate methods on your subclass: | `@RestApiBase.put(path, **kwargs)` | Register a PUT endpoint. | | `@RestApiBase.delete(path, **kwargs)` | Register a DELETE endpoint. | | `@RestApiBase.patch(path, **kwargs)` | Register a PATCH endpoint. | +| `@RestApiBase.head(path, **kwargs)` | Register a HEAD endpoint, e.g. a cheap existence check before a GET. | `**kwargs` are forwarded to the underlying FastAPI route registration. diff --git a/src/blueprint/agents/io/api/rest_api_base.py b/src/blueprint/agents/io/api/rest_api_base.py index 08595bc8..a8b60f16 100644 --- a/src/blueprint/agents/io/api/rest_api_base.py +++ b/src/blueprint/agents/io/api/rest_api_base.py @@ -59,7 +59,7 @@ class RestApiBase(IOBase, ABC): Routes are registered by decorating methods with the class-level HTTP verb helpers (``RestApiBase.get``, ``RestApiBase.post``, ``RestApiBase.put``, - ``RestApiBase.delete``, ``RestApiBase.patch``). The base class wires those + ``RestApiBase.delete``, ``RestApiBase.patch``, ``RestApiBase.head``). The base class wires those decorated methods onto ``self.router`` during ``__init__``, so subclasses never need to call ``_wire_routes()`` or touch the router directly. """ @@ -189,6 +189,16 @@ def decorator(func: Callable[..., Any]) -> Callable[..., Any]: return decorator + @staticmethod + def head(path: str, **kwargs: Any) -> Callable[[Callable[..., Any]], Callable[..., Any]]: + """Decorator: register a HEAD route on the instance router.""" + + def decorator(func: Callable[..., Any]) -> Callable[..., Any]: + func._route = ("head", path, kwargs) # type: ignore[attr-defined] + return func + + return decorator + def _wire_routes(self) -> None: """Discover and register all decorated route methods on self.router.""" diff --git a/src/blueprint/agents/io/api/utilities/root.py b/src/blueprint/agents/io/api/utilities/root.py index abf258de..bbded143 100644 --- a/src/blueprint/agents/io/api/utilities/root.py +++ b/src/blueprint/agents/io/api/utilities/root.py @@ -6,10 +6,12 @@ from fastapi import FastAPI from fastapi.responses import HTMLResponse -from fastapi.routing import APIRoute from ..rest_api_base import RestApiBase +_HTTP_METHODS = frozenset({"GET", "PUT", "POST", "DELETE", "OPTIONS", "HEAD", "PATCH", "TRACE"}) +"""Keys of an OpenAPI path item that are operations; the others (``parameters``, ...) are not.""" + class RootApi(RestApiBase): """Exposes a root endpoint listing service metadata and all registered routes.""" @@ -42,17 +44,13 @@ async def root(self) -> Any: doc_links = " | ".join(f'{label}' for label, url in [("Swagger UI", docs_url), ("ReDoc", redoc_url)] if url) rows = [] - for route in self._app.routes: - if not isinstance(route, APIRoute): - continue - route_methods = route.methods or set() + for path, route_methods, summary in self._operations(): methods = ", ".join(sorted(route_methods)) - summary = route.summary or "" if "GET" in route_methods: - path_cell = f'{route.path}' + path_cell = f'{path}' else: - anchor = route.path.replace("/", "-").strip("-") - path_cell = f'{route.path}' if docs_url else route.path + anchor = path.replace("/", "-").strip("-") + path_cell = f'{path}' if docs_url else path rows.append(f"