[Blazor] Components.AI — Multimodal attachments, conversation threads, and form input#66185
Draft
javiercn wants to merge 1 commit intojaviercn/ai-components-shells-themingfrom
Draft
Conversation
Add cross-cutting features: - IConversationThread for conversation storage, restore, and new conversation support - RestoreAsync on UIAgent and AgentContext for replaying thread history - AgentFormBoundary and FormMessageInput for SSR form-based input - MessageInput attachment support using InputFile (no JS interop) - Thread integration tests and form component tests
6fe25dd to
19b72f3
Compare
c649146 to
08e98cf
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of the overall Components.AI design: #66178
Builds on #66184
Conversation Threads, Form Input, and Multimodal Attachments
Summary
Add three capabilities that complete the conversation experience: persistent conversation history via
IConversationThread, SSR-compatible form-based input viaAgentFormBoundaryandFormMessageInput, and file attachment support in messages.Motivation
Conversation persistence
Without persistence, refreshing the page or navigating away loses the entire conversation. Applications need to store and restore conversation history. The storage mechanism varies, so the library defines a minimal interface rather than a specific implementation.
Static SSR support
Not all Blazor applications use interactive render modes. Static SSR applications render HTML on the server and accept user input via form POST. The core
MessageInputusesonclickevents requiring an interactive circuit. SSR applications need a form-based alternative.File attachments
Users frequently need to share images, documents, and files in chat. The LLM receives these as
DataContentitems alongside text.Goals
IConversationThreadas a pluggable interface for conversation persistence.IConversationThreadintoUIAgent: record messages and updates, restore from history.AgentFormBoundaryfor SSR form-based chat interactions.FormMessageInputfor SSR text input.AgentBoundaryinitialization when a thread has history.ConversationIdis set, send only the latest message.Non-goals
DataContent.Detailed design
IConversationThread interface
Conversation restore flow
When
AgentBoundaryinitializes with a thread that has persisted updates, it callsRestoreAsync()which replays persistedChatResponseUpdateobjects through the pipeline, rebuilding the conversation turns.SSR form-based input
AgentFormBoundarybinds via[SupplyParameterFromForm]:UserMessage— text from the input.BlockAction— approval actions (format:"approve:blockId"or"reject:blockId").Multimodal attachment flow
MessageInputsupports file attachments whenAllowAttachments=true. Files are read asbyte[], stored asAttachedFileobjects, and sent asDataContentitems alongsideTextContent. Max 10MB per file.Stateful LLM support
When
IConversationThread.IsStatefulistrueandConversationIdis set,UIAgentsends only the latest message. The LLM service manages history server-side.Risks
CompleteTurn()acting as a commit marker.Drawbacks
AgentFormBoundaryduplicates some logic fromAgentBoundary. Accepted because the form boundary has genuinely different initialization logic.FormMessageInputis a separate component fromMessageInputbecause the rendering is fundamentally different.Test coverage
288 tests (cumulative) covering:
IConversationThreadcontract: append, read, commit lifecycle.UIAgentthread integration: message recording, update recording, restore replay.AgentContextrestore: turn reconstruction from thread history.AgentFormBoundaryform submission: text messages, approval actions, rejection actions.FormMessageInputrendering: disabled state, placeholder, name attribute.MessageInputattachments: file selection, preview, removal, size limit, submission withDataContent.ConversationIdpropagation.