Skip to content

Commit bdbe4e2

Browse files
Implement A2UI catalog negotiation (#576)
1 parent be54230 commit bdbe4e2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+571
-150
lines changed

examples/catalog_gallery/lib/samples_view.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class _SamplesViewState extends State<SamplesView> {
4040
@override
4141
void initState() {
4242
super.initState();
43-
_genUiManager = GenUiManager(catalog: widget.catalog);
43+
_genUiManager = GenUiManager(catalogs: [widget.catalog]);
4444
_loadSamples();
4545
_setupSurfaceListener();
4646
}
@@ -109,7 +109,7 @@ class _SamplesViewState extends State<SamplesView> {
109109
});
110110
// Re-create GenUiManager to ensure a clean state for the new sample.
111111
_genUiManager.dispose();
112-
_genUiManager = GenUiManager(catalog: widget.catalog);
112+
_genUiManager = GenUiManager(catalogs: [widget.catalog]);
113113
_setupSurfaceListener();
114114

115115
try {

examples/custom_backend/lib/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class _IntegrationTesterState extends State<_IntegrationTester> {
7777
final _controller = TextEditingController(text: requestText);
7878

7979
final _protocol = Backend(uiSchema);
80-
late final GenUiManager _genUi = GenUiManager(catalog: _catalog);
80+
late final GenUiManager _genUi = GenUiManager(catalogs: [_catalog]);
8181
String? _selectedResponse;
8282
bool _isLoading = false;
8383
String? _errorMessage;

examples/simple_chat/lib/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class _ChatScreenState extends State<ChatScreen> {
7676
void initState() {
7777
super.initState();
7878
final Catalog catalog = CoreCatalogItems.asCatalog();
79-
_genUiManager = GenUiManager(catalog: catalog);
79+
_genUiManager = GenUiManager(catalogs: [catalog]);
8080

8181
final systemInstruction =
8282
'''You are a helpful assistant who chats with a user,

examples/travel_app/lib/src/catalog.dart

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -24,35 +24,20 @@ import 'catalog/travel_carousel.dart';
2424
/// for a travel planning experience, such as [travelCarousel], [itinerary],
2525
/// and [inputGroup]. The AI selects from these components to build a dynamic
2626
/// and interactive UI in response to user prompts.
27-
final Catalog travelAppCatalog = CoreCatalogItems.asCatalog()
28-
.copyWithout([
29-
CoreCatalogItems.audioPlayer,
30-
CoreCatalogItems.card,
31-
CoreCatalogItems.checkBox,
32-
CoreCatalogItems.dateTimeInput,
33-
CoreCatalogItems.divider,
34-
CoreCatalogItems.textField,
35-
CoreCatalogItems.list,
36-
CoreCatalogItems.modal,
37-
CoreCatalogItems.multipleChoice,
38-
CoreCatalogItems.slider,
39-
CoreCatalogItems.tabs,
40-
CoreCatalogItems.video,
41-
CoreCatalogItems.icon,
42-
CoreCatalogItems.row,
43-
CoreCatalogItems.image,
44-
])
45-
.copyWith([
46-
CoreCatalogItems.imageFixedSize,
47-
checkboxFilterChipsInput,
48-
dateInputChip,
49-
informationCard,
50-
inputGroup,
51-
itinerary,
52-
listingsBooker,
53-
optionsFilterChipInput,
54-
tabbedSections,
55-
textInputChip,
56-
trailhead,
57-
travelCarousel,
58-
]);
27+
final Catalog travelAppCatalog = Catalog([
28+
CoreCatalogItems.button,
29+
CoreCatalogItems.column,
30+
CoreCatalogItems.text,
31+
CoreCatalogItems.imageFixedSize,
32+
checkboxFilterChipsInput,
33+
dateInputChip,
34+
informationCard,
35+
inputGroup,
36+
itinerary,
37+
listingsBooker,
38+
optionsFilterChipInput,
39+
tabbedSections,
40+
textInputChip,
41+
trailhead,
42+
travelCarousel,
43+
], catalogId: 'example.com:travel_v0');

examples/travel_app/lib/src/travel_planner_page.dart

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,7 @@ class _TravelPlannerPageState extends State<TravelPlannerPage>
6363
@override
6464
void initState() {
6565
super.initState();
66-
final genUiManager = GenUiManager(
67-
catalog: travelAppCatalog,
68-
configuration: const GenUiConfiguration(
69-
actions: ActionsConfig(
70-
allowCreate: true,
71-
allowUpdate: true,
72-
allowDelete: true,
73-
),
74-
),
75-
);
66+
final genUiManager = GenUiManager(catalogs: [travelAppCatalog]);
7667
_userMessageSubscription = genUiManager.onSubmit.listen(
7768
_handleUserMessageFromUi,
7869
);

examples/travel_app/test/widgets/conversation_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ void main() {
1212
late GenUiManager manager;
1313

1414
setUp(() {
15-
manager = GenUiManager(catalog: CoreCatalogItems.asCatalog());
15+
manager = GenUiManager(catalogs: [CoreCatalogItems.asCatalog()]);
1616
});
1717

1818
testWidgets('renders a list of messages', (WidgetTester tester) async {

examples/verdure/client/lib/features/ai/ai_provider.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class AiClientState {
6767
class Ai extends _$Ai {
6868
@override
6969
Future<AiClientState> build() async {
70-
final genUiManager = GenUiManager(catalog: CoreCatalogItems.asCatalog());
70+
final genUiManager = GenUiManager(catalogs: [CoreCatalogItems.asCatalog()]);
7171
final A2uiAgentConnector connector = await ref.watch(
7272
a2uiAgentConnectorProvider.future,
7373
);

packages/genui/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
## 0.5.2 (in progress)
44
- Updated README sample code to reflect current `FirebaseAiContentGenerator` API (added `catalog` parameter and replaced `tools` with `additionalTools`).
55

6+
- **Feature**: `GenUiManager` now supports multiple catalogs by accepting an `Iterable<Catalog>` in its constructor.
7+
- **Feature**: `catalogId` property added to `UiDefinition` to specify which catalog a UI surface should use.
8+
- **Refactor**: Moved `standardCatalogId` constant from `core_catalog.dart` to `primitives/constants.dart` for better organization and accessibility.
9+
610
## 0.5.1
711

812
- Homepage URL was updated.

packages/genui/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ provider.
164164
165165
// Create a GenUiManager with a widget catalog.
166166
// The CoreCatalogItems contain basic widgets for text, markdown, and images.
167-
_genUiManager = GenUiManager(catalog: CoreCatalogItems.asCatalog());
167+
_genUiManager = GenUiManager(catalogs: [CoreCatalogItems.asCatalog()]);
168168
169169
// Create a ContentGenerator to communicate with the LLM.
170170
// Provide system instructions and the tools from the GenUiManager.
@@ -378,7 +378,7 @@ Include your catalog items when instantiating `GenUiManager`.
378378

379379
```dart
380380
_genUiManager = GenUiManager(
381-
catalog: CoreCatalogItems.asCatalog().copyWith([riddleCard]),
381+
catalogs: [CoreCatalogItems.asCatalog().copyWith([riddleCard])],
382382
);
383383
```
384384

packages/genui/lib/genui.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export 'src/core/widgets/chat_primitives.dart';
2222
export 'src/development_utilities/catalog_view.dart';
2323
export 'src/facade/direct_call_integration/model.dart';
2424
export 'src/facade/direct_call_integration/utils.dart';
25+
export 'src/model/a2ui_client_capabilities.dart';
2526
export 'src/model/a2ui_message.dart';
2627
export 'src/model/a2ui_schemas.dart';
2728
export 'src/model/catalog.dart';

0 commit comments

Comments
 (0)