Skip to content

Add facade class UiAgent.#184

Merged
polina-c merged 44 commits intoflutter:mainfrom
polina-c:ui_agent
Aug 27, 2025
Merged

Add facade class UiAgent.#184
polina-c merged 44 commits intoflutter:mainfrom
polina-c:ui_agent

Conversation

@polina-c
Copy link
Copy Markdown
Collaborator

@polina-c polina-c commented Aug 23, 2025

Fixes #114

There are two TODO here (in ui_agent.dart and genui_manager.dart), postponed to next PRs.

gemini-code-assist[bot]

This comment was marked as outdated.

@polina-c polina-c marked this pull request as draft August 25, 2025 13:18
@polina-c polina-c changed the title Add facade class for AiAgent. Add facade class UiAgent. Aug 26, 2025
@polina-c polina-c marked this pull request as ready for review August 26, 2025 20:57
@polina-c
Copy link
Copy Markdown
Collaborator Author

/gemini summary

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

This pull request introduces a new UiAgent facade class within the flutter_genui package, designed to simplify the integration and management of generative UI components in Flutter applications. It abstracts away the direct interaction with GenUiManager and AiClient, providing a streamlined interface for handling UI surfaces and AI conversations. The simple_chat example has been updated to demonstrate the usage of this new UiAgent, showcasing how it manages chat messages, UI rendering, and AI processing states. Additionally, the GenUiManager has been refactored to implement a new SurfaceBuilder interface, enhancing modularity and flexibility across the generative UI system.

Highlights

  • Introduced UiAgent Facade: A new UiAgent class is added to provide a high-level API for interacting with the generative UI system, encapsulating GenUiManager and AiClient functionalities.
  • Refactored GenUiManager: GenUiManager now implements the new SurfaceBuilder interface, promoting a more abstract and flexible way to build UI surfaces.
  • Updated GenUiSurface Usage: The GenUiSurface widget and other related components (like ChatWidget, ConversationWidget, and tests) have been updated to accept a SurfaceBuilder instead of a direct GenUiManager instance.
  • Enhanced simple_chat Example: The simple_chat example application has been significantly refactored to utilize the new UiAgent, including the introduction of MessageController and MessageView for better management and display of chat messages and dynamic UI surfaces.
  • Conversation History Management: The UiAgent now includes logic to limit the conversation history length, preventing excessive memory usage and token costs when interacting with the AI.
Changelog
  • examples/simple_chat/lib/main.dart
    • Updated imports to include flutter_genui and message.dart.
    • Replaced FirebaseAIService and List<String> messages with UiAgent and List<MessageController>.
    • Added _onSurfaceAdded and _onSurfaceRemoved callbacks for UiAgent.
    • Updated message display to use MessageView and _uiAgent.builder.
    • Changed loading indicator logic to use _uiAgent.isProcessing.
    • Modified _sendMessage to add MessageController instead of String and removed direct _aiService calls, implying UiAgent handles the AI interaction.
  • examples/simple_chat/lib/message.dart
    • Added MessageController to encapsulate chat messages (either text or a UI surface ID).
    • Added MessageView widget to display MessageController instances, using GenUiSurface for UI surfaces.
  • pkgs/flutter_genui/lib/flutter_genui.dart
    • Exported the new src/facade/ui_agent.dart.
  • pkgs/flutter_genui/lib/src/core/genui_manager.dart
    • Introduced SurfaceBuilder abstract interface.
    • Made GenUiManager implement the SurfaceBuilder interface.
    • Added @override annotations to the updates getter and surface method within GenUiManager.
  • pkgs/flutter_genui/lib/src/facade/genui_surface.dart
    • Changed the manager property to builder of type SurfaceBuilder.
    • Updated internal logic to use widget.builder instead of widget.manager.
  • pkgs/flutter_genui/lib/src/facade/to_refactor/chat_widget.dart
    • Updated GenUiSurface instantiation to use the builder property instead of manager.
  • pkgs/flutter_genui/lib/src/facade/to_refactor/conversation_widget.dart
    • Updated GenUiSurface instantiation to use the builder property instead of manager.
  • pkgs/flutter_genui/lib/src/facade/ui_agent.dart
    • Added the UiAgent class as a generic facade for the GenUi package.
    • Initialized GenUiManager and GeminiAiClient within UiAgent.
    • Implemented conversation history management with a _maxConversationLength limit.
    • Provided onSurfaceAdded and onSurfaceRemoved callbacks.
    • Exposed isProcessing as a ValueListenable.
    • Handled sendRequest to the AI client.
    • Included a dispose method for resource cleanup.
    • Defined a _technicalPrompt for AI instructions.
  • pkgs/flutter_genui/test/catalog/core_widgets_test.dart
    • Updated GenUiSurface instantiation to use the builder property instead of manager.
  • pkgs/flutter_genui/test/dynamic_ui_test.dart
    • Updated GenUiSurface instantiation to use the builder property instead of manager.
  • pkgs/spikes/catalog_gallery/lib/main.dart
    • Updated GenUiSurface instantiation to use the builder property instead of manager.
Activity
  • On 2025-08-23, gemini-code-assist[bot] commented on ui_agent.dart regarding the indefinite growth of the _conversation list, suggesting a fixed limit.
  • On 2025-08-26, polina-c replied "thanks fixed" to the conversation history comment, indicating the issue was addressed.
  • On 2025-08-23, gemini-code-assist[bot] commented on ui_agent.dart regarding UiAgent not forwarding UI updates, providing a detailed fix for subscribing to _genUiManager.updates.
  • On 2025-08-26, polina-c replied "outdated" to the UI updates forwarding comment, indicating the issue was addressed.
  • On 2025-08-26, polina-c requested a summary using /gemini summary.

Copy link
Copy Markdown
Collaborator

@gspencergoog gspencergoog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

32384589-a60f0e74-c078-11e7-9bc1-e5b5287aea9d

@polina-c polina-c merged commit 4265a23 into flutter:main Aug 27, 2025
11 checks passed
@polina-c polina-c deleted the ui_agent branch August 27, 2025 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement facade for simple chat.

2 participants