refactor(rtvi): clarify UI message names
This commit is contained in:
@@ -33,28 +33,26 @@ class RTVIUICommandFrame(SystemFrame):
|
||||
"""A frame for sending a UI command to the client.
|
||||
|
||||
Pipeline-side counterpart of the ``ui-command`` RTVI message.
|
||||
The observer wraps the ``command_name`` + ``payload`` into a
|
||||
The observer wraps the ``command`` + ``payload`` into a
|
||||
``UICommandMessage`` envelope before pushing it to the transport,
|
||||
so the wire shape is:
|
||||
``{label, type: "ui-command", data: {name, payload}}``.
|
||||
``{label, type: "ui-command", data: {command, payload}}``.
|
||||
|
||||
Parameters:
|
||||
command_name: App-defined command name (e.g. ``"toast"``,
|
||||
``"navigate"``, or any app-specific name). The wire
|
||||
field is ``data.name``; this avoids shadowing
|
||||
``SystemFrame.name`` (the per-instance debug label).
|
||||
command: App-defined command (e.g. ``"toast"``,
|
||||
``"navigate"``, or any app-specific command).
|
||||
payload: App-defined payload. Pydantic command models
|
||||
(``Toast``, ``Navigate``, ``ScrollTo``, ...) should be
|
||||
converted to a plain dict via ``model_dump()`` before
|
||||
being placed here; an arbitrary dict works as well.
|
||||
"""
|
||||
|
||||
command_name: str = ""
|
||||
command: str = ""
|
||||
payload: Any = None
|
||||
|
||||
def __str__(self):
|
||||
"""String representation of the UI command frame."""
|
||||
return f"{self.name}(command: {self.command_name})"
|
||||
return f"{self.name}(command: {self.command})"
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -97,17 +95,17 @@ class RTVIUIEventFrame(SystemFrame):
|
||||
|
||||
Parameters:
|
||||
msg_id: The RTVI message id, as set by the client.
|
||||
event_name: App-defined event name (the ``data.name`` field).
|
||||
event: App-defined event (the ``data.event`` field).
|
||||
payload: App-defined payload (the ``data.payload`` field).
|
||||
"""
|
||||
|
||||
msg_id: str = ""
|
||||
event_name: str = ""
|
||||
event: str = ""
|
||||
payload: Any = None
|
||||
|
||||
def __str__(self):
|
||||
"""String representation of the UI event frame."""
|
||||
return f"{self.name}(event: {self.event_name})"
|
||||
return f"{self.name}(event: {self.event})"
|
||||
|
||||
|
||||
@dataclass
|
||||
|
||||
@@ -595,11 +595,11 @@ class UIEventData(BaseModel):
|
||||
"""Inner ``data`` for a ``ui-event`` message.
|
||||
|
||||
Parameters:
|
||||
name: App-defined event name.
|
||||
event: App-defined event.
|
||||
payload: App-defined payload, schemaless by design.
|
||||
"""
|
||||
|
||||
name: str
|
||||
event: str
|
||||
payload: Any | None = None
|
||||
|
||||
|
||||
@@ -607,13 +607,13 @@ class UICommandData(BaseModel):
|
||||
"""Inner ``data`` for a ``ui-command`` message.
|
||||
|
||||
Parameters:
|
||||
name: App-defined command name.
|
||||
command: App-defined command.
|
||||
payload: App-defined payload (already a plain dict by the
|
||||
time it lands on the wire). The standard payload models
|
||||
time it lands on the wire). The standard command payload models
|
||||
below produce the right shape via ``model_dump()``.
|
||||
"""
|
||||
|
||||
name: str
|
||||
command: str
|
||||
payload: Any | None = None
|
||||
|
||||
|
||||
|
||||
@@ -434,7 +434,7 @@ class RTVIObserver(BaseObserver):
|
||||
await self.send_rtvi_message(message)
|
||||
elif isinstance(frame, RTVIUICommandFrame):
|
||||
message = RTVI.UICommandMessage(
|
||||
data=RTVI.UICommandData(name=frame.command_name, payload=frame.payload)
|
||||
data=RTVI.UICommandData(command=frame.command, payload=frame.payload)
|
||||
)
|
||||
await self.send_rtvi_message(message)
|
||||
elif isinstance(frame, RTVIUITaskFrame):
|
||||
|
||||
@@ -299,7 +299,7 @@ class RTVIProcessor(FrameProcessor):
|
||||
await self.push_frame(
|
||||
RTVIUIEventFrame(
|
||||
msg_id=message.id,
|
||||
event_name=event_data.name,
|
||||
event=event_data.event,
|
||||
payload=event_data.payload,
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user