Skip to content

API Reference parrot.handlers.ui_surfaces

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.handlers.ui_surfaces

View source

SurfaceNegotiationService + UISurfacesHandler — REST lane for the ui_surfaces plane (FEAT-492, Module 3).

SurfaceNegotiationService is the SHARED JSON/HTML negotiation service: both this handler's GET and A2UIHandler's mirror route (TASK-2703) delegate to the same instance/logic so negotiation behavior cannot drift.

UISurfacesHandler (navigator.views.BaseView + @is_authenticated()/ @user_session(), the AgentTalk/DashboardHandler idiom) dispatches on match_info/path suffix inside get/post/delete — one handler class for the whole REST lane (InfographicTalk precedent).

Route registration itself is TASK-2703's job — this module only defines the service + handler classes.

Class MintShareRequest

Body of POST /api/v1/ui/surfaces/{id}/share.

Fields:

Field Type Default Description
expires_at datetime | None None
ttl bool False

Class PublishSurfaceRequest

Body of POST /api/v1/ui/surfaces (frontend pin/save).

Note: adds session_id beyond the spec's Data Models block — copying from ArtifactStore needs the full (user_id, agent_id, session_id, artifact_id) composite key (storage/artifacts.py); user_id comes from the authenticated session, but session_id has no other source. Optional and additive — inline-envelope publishes never need it.

Fields:

Field Type Default Description
kind UISurfaceKind
title str
envelope dict[str, Any] | None None
source_artifact_id str | None None
agent_id str | None None
session_id str | None None
recipe_name str | None None
recipe_owner str | None None
recipe_params dict[str, Any]
visibility SurfaceVisibility SurfaceVisibility.private
allowed_groups list[str]

Class RefreshSurfaceRequest

Body of POST /api/v1/ui/surfaces/{id}/refresh.

Fields:

Field Type Default Description
params dict[str, Any]

Class SourceDataRequest

Body of POST /api/v1/ui/surfaces/{id}/sources/{key}/data — placeholder overrides only (FEAT-636 S2).

Conditions are NEVER accepted from the client: the server rebuilds them from the persisted descriptor, so locked filters, tenant routing and querylimit cannot be tampered with.

Fields:

Field Type Default Description
params dict[str, Any]

Class SurfaceNegotiationService

Shared JSON/HTML negotiation over a stored surface (used by BOTH handlers).

UISurfacesHandler.get() and A2UIHandler's mirror route (TASK-2703) both delegate to the SAME logic here so negotiation behavior cannot drift between the two routes (spec §2 resolved decision).

Method SurfaceNegotiationService.negotiate

Resolve the desired content type for the response.

Priority: ?format= query param (wins) > Accept header > default application/json (unlike InfographicTalk, whose default is HTML — this lane defaults to JSON, spec §2).

negotiate(request: web.Request) -> str

Parameter Type Default Description
request web.Request The incoming aiohttp request.

Returns: str — "application/json" or "text/html".

Method SurfaceNegotiationService.respond

Build the negotiated response for a resolved surface record.

respond(record: UISurfaceRecord, accept: str) -> web.Response

Parameter Type Default Description
record UISurfaceRecord The persisted surface to serve.
accept str "application/json" or "text/html" (from :meth:negotiate).

Returns: web.Response — A JSON envelope+metadata response, or an on-the-fly rendered interactive HTML response (501 with an install hint when ai-parrot-visualizations is not installed).

Class UISurfacesHandler

REST lane for the ui_surfaces plane (spec §3 Module 3).

Dispatches on match_info/path suffix inside get/post/ delete — one handler class, InfographicTalk/RecipeHandler idiom — rather than a route per sub-path.

Attributes:

Attribute Type Description
store PgUISurfaceStore
negotiation SurfaceNegotiationService

Method UISurfacesHandler.post_init

post_init(*args, **kwargs) -> None

Parameter Type Default Description
*args ()
**kwargs {}

Method UISurfacesHandler.get

GET /api/v1/ui/surfaces[/{surface_id}].

get() -> web.Response

Returns: web.Response

Method UISurfacesHandler.post

Dispatch POST by path suffix: /sources/{key}/data, /refresh, /share, or pin/save.

post() -> web.Response

Returns: web.Response

Method UISurfacesHandler.patch

PATCH /api/v1/ui/surfaces/{surface_id} — owner-only visibility change.

Rides the existing /{surface_id} view (manager.py untouched, spec §2/§6) — aiohttp's View dispatches any HTTP verb to a same-named coroutine.

patch() -> web.Response

Returns: web.Response

Method UISurfacesHandler.delete

Dispatch DELETE: revoke a share token, or delete a surface.

delete() -> web.Response

Returns: web.Response

Function resolve_surface_access

Resolve owner-or-scope-or-share access to a surface.

SHARED between UISurfacesHandler (this module) and A2UIHandler's mirror route (handlers/a2ui.py, TASK-2703/2935) — code review follow-up: this rule set was originally duplicated between the two handlers (each building its own web.Response); promoted to a module-level, framework-response-agnostic function so it cannot drift between the two routes. Returns (record, None) on success, or (None, (message, status)) on failure — the caller builds the actual web.Response with its own response helper.

Access order (FEAT-535): owner -> scope (tenant/group/superuser) -> share token -> 404. The scope check runs BEFORE the token check because it never needs the caller to have anything out-of-band, but a share token still grants access to a surface from a FOREIGN tenant — minting/handing out a token is explicit, out-of-band consent that the tenant/group rule must not block (spec §2).

Unknown/foreign-without-token-or-scope id -> 404 (no existence oracle). Revoked/expired/missing token (when one WAS supplied) -> 410.

resolve_surface_access(store: PgUISurfaceStore, surface_id: str, user_id: str | None, token: str | None, *, scope: SurfaceScope | None = None) -> tuple[UISurfaceRecord | None, tuple[str, int] | None]

Parameter Type Default Description
store PgUISurfaceStore
surface_id str
user_id str | None
token str | None
scope SurfaceScope | None None

Returns: tuple[UISurfaceRecord | None, tuple[str, int] | None]

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally