|
| 1 | +# Copyright 2026 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +from __future__ import annotations |
| 16 | + |
| 17 | +from typing import Any |
| 18 | + |
| 19 | +from pydantic import alias_generators |
| 20 | +from pydantic import BaseModel |
| 21 | +from pydantic import ConfigDict |
| 22 | +from pydantic import Field |
| 23 | + |
| 24 | + |
| 25 | +class UiWidget(BaseModel): |
| 26 | + """Rendering metadata for a UI widget associated with an event. |
| 27 | +
|
| 28 | + When present on an Event.actions, the UI renders the widget using the |
| 29 | + specified provider's renderer component. |
| 30 | + """ |
| 31 | + |
| 32 | + model_config = ConfigDict( |
| 33 | + extra='forbid', |
| 34 | + alias_generator=alias_generators.to_camel, |
| 35 | + populate_by_name=True, |
| 36 | + ) |
| 37 | + |
| 38 | + id: str |
| 39 | + """The unique identifier of the UI widget.""" |
| 40 | + |
| 41 | + provider: str |
| 42 | + """Widget provider identifier. Determines which rendering strategy |
| 43 | + the UI uses. |
| 44 | +
|
| 45 | + Known values: |
| 46 | + - 'mcp': MCP App iframe, rendered with the MCP Apps AppBridge. |
| 47 | + """ |
| 48 | + |
| 49 | + payload: dict[str, Any] = Field(default_factory=dict) |
| 50 | + """Provider-specific data required for rendering. |
| 51 | +
|
| 52 | + If provider is 'mcp', the payload is a dictionary with the following fields: |
| 53 | + { |
| 54 | + "resource_uri: "ui://...", |
| 55 | + "tool": {...}, |
| 56 | + "tool_args": {...} |
| 57 | + } |
| 58 | + Future providers can have their set of payload fields. |
| 59 | + """ |
0 commit comments