Repository navigation
[Blazor] Add predictive state updates - #68335
Conversation
5b4151f to
8cc281f
Compare
|
/azp run aspnetcore-components-e2e |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
8cc281f to
90523c9
Compare
There was a problem hiding this comment.
Pull request overview
Adds a provider-neutral “predictive state” transaction mechanism to Components.AI so streamed state updates can be displayed immediately, then explicitly accepted or rejected at a UI confirmation boundary. This is integrated into a new Dojo scenario (and API endpoint) that streams document edits via state snapshots, plus an E2E recording/test that still exercises the real dual-host HTTP/SSE boundary.
Changes:
- Introduces predictive state mapping (
StateMapperContext.SetPredictiveState) and transactional state operations onAgentState<T>(accept/reject + pending flag). - Ensures all non-accept termination paths (completion without confirmation, cancellation, failure, disposal) roll back pending predictive state (
AgentContext+UIAgent<TState>dispatch). - Adds a new “Predictive State Updates” Dojo scenario + AGUIDojoApi endpoint, including deterministic replay support and an E2E test/recording.
Reviewed changes
Copilot reviewed 32 out of 32 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Components/AI/testassets/DojoClient/Shared/DojoConversationThread.cs | Renames/re-homes conversation thread type used by multiple scenarios. |
| src/Components/AI/testassets/DojoClient/Program.cs | Registers keyed chat client for the new predictive scenario endpoint. |
| src/Components/AI/testassets/DojoClient/DojoScenarios.cs | Adds the /predictive_state_updates scenario endpoint constant. |
| src/Components/AI/testassets/DojoClient/Components/Scenarios/SharedState/SharedStateScenario.razor | Updates scenario to use the shared DojoConversationThread type. |
| src/Components/AI/testassets/DojoClient/Components/Scenarios/PredictiveStateUpdates/PredictiveStateUpdatesScenario.razor.css | Styles for predictive document editor layout. |
| src/Components/AI/testassets/DojoClient/Components/Scenarios/PredictiveStateUpdates/PredictiveStateUpdatesScenario.razor | New scenario wiring predictive state mapping + confirmation UI action. |
| src/Components/AI/testassets/DojoClient/Components/Scenarios/PredictiveStateUpdates/DocumentSuggestions.razor.css | Styles for prompt suggestion buttons. |
| src/Components/AI/testassets/DojoClient/Components/Scenarios/PredictiveStateUpdates/DocumentSuggestions.razor | UI for common prompts that drive the predictive editing flow. |
| src/Components/AI/testassets/DojoClient/Components/Scenarios/PredictiveStateUpdates/DocumentState.cs | Scenario state model used by the client editor. |
| src/Components/AI/testassets/DojoClient/Components/Scenarios/PredictiveStateUpdates/DocumentPreview.razor.css | Styles for editable/read-only document preview + diff highlights. |
| src/Components/AI/testassets/DojoClient/Components/Scenarios/PredictiveStateUpdates/DocumentPreview.razor | Renders editable surface and read-only diff during predictive streaming. |
| src/Components/AI/testassets/DojoClient/Components/Scenarios/PredictiveStateUpdates/ConfirmChangesDialog.razor.css | Styles for the confirmation dialog UI action. |
| src/Components/AI/testassets/DojoClient/Components/Scenarios/PredictiveStateUpdates/ConfirmChangesDialog.razor | Implements the accept/reject UI action invocation UI. |
| src/Components/AI/testassets/DojoClient/Components/Pages/Home.razor | Adds navigation entry for the new scenario. |
| src/Components/AI/testassets/DojoClient/Components/_Imports.razor | Imports predictive scenario namespace for Razor compilation. |
| src/Components/AI/testassets/DojoClient.E2E.Tests/Tests/PredictiveStateUpdatesScenarioTests.cs | New E2E test covering streaming + accept/reject flows. |
| src/Components/AI/testassets/DojoClient.E2E.Tests/ServiceOverrides/RecordedScript.cs | Extends recorded frames to include predictive state snapshots. |
| src/Components/AI/testassets/DojoClient.E2E.Tests/ServiceOverrides/RecordedChatClient.cs | Emits predictive state snapshots as DataContent with a custom media type. |
| src/Components/AI/testassets/DojoClient.E2E.Tests/ServiceOverrides/DojoModelOverrides.cs | Adds deterministic model override wiring for predictive scenario. |
| src/Components/AI/testassets/DojoClient.E2E.Tests/Baselines/PredictiveStateUpdates.recording.json | New recorded model script driving predictive scenario E2E. |
| src/Components/AI/testassets/AGUIDojoApi/ScriptedChatClient.cs | Adds scripted behavior for confirmation-result messaging and predictive flow. |
| src/Components/AI/testassets/AGUIDojoApi/Program.cs | Maps new /predictive_state_updates dojo endpoint with keyed chat client. |
| src/Components/AI/testassets/AGUIDojoApi/PredictiveStateUpdates/DocumentState.cs | API-side document state model for snapshot serialization. |
| src/Components/AI/testassets/AGUIDojoApi/ChatClientAgentFactory.cs | Adds predictive system prompt, tool set, and snapshot/confirmation stream mapping. |
| src/Components/AI/testassets/AGUIDojoApi/AGUIEndpoint.cs | Adds keyed chat client resolution and “client tools as declarations” mode. |
| src/Components/AI/test/Engine/PredictiveStateTests.cs | Adds runtime tests for accept/reject and rollback on cancellation/completion. |
| src/Components/AI/src/PublicAPI.Unshipped.txt | Declares new public API surface for predictive state operations. |
| src/Components/AI/src/Pipeline/StateMapperContext.cs | Adds predictive-state mapping flag and public SetPredictiveState. |
| src/Components/AI/src/Engine/UIAgentOfT.cs | Routes predictive vs committed state updates and exposes rollback hook. |
| src/Components/AI/src/Engine/UIAgent.cs | Adds virtual rollback hook used by AgentContext. |
| src/Components/AI/src/Engine/AgentState.cs | Implements predictive transaction baseline + accept/reject APIs. |
| src/Components/AI/src/Engine/AgentContext.cs | Ensures rollback on dispose, completion without accept, cancellation, and error. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
90523c9 to
6c0a11d
Compare
6c0a11d to
5902fcc
Compare
5902fcc to
142ec32
Compare
142ec32 to
dca2ed2
Compare
Rationale: let provider-neutral Components.AI applications render provisional state immediately while retaining a committed value that can survive rejection, cancellation, or an incomplete confirmation flow. Implementation: add explicit predictive state mapping and observable accept/reject semantics, preserve the pre-prediction value across incremental updates, and roll unfinished predictions back when a turn is canceled, fails, is disposed, or completes without confirmation. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 323b0ef8-7905-4041-8388-a08586c0bd34
Rationale: demonstrate canonical Predictive State Updates across the real DojoClient to AGUIDojoApi HTTP/SSE boundary so a proposed document is visible before the user decides whether to keep it. Implementation: add the /predictive_state_updates raw-model endpoint, translate write_document_local into incremental AG-UI state snapshots plus a synthetic confirm_changes call, and render an editable document diff whose predictive state can be accepted or rejected before continuation. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 323b0ef8-7905-4041-8388-a08586c0bd34
Rationale: protect provisional state from being committed accidentally and prove that confirmation, rejection, cancellation, and incomplete turns preserve the correct document across the real client-to-API transport. Implementation: add focused engine tests for predictive transactions and rollback, extend API-side recorded replay with checkpointed state frames, and add a dual-host browser scenario that accepts one streamed document and rejects the next without replacing AGUIChatClient. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 323b0ef8-7905-4041-8388-a08586c0bd34
Rationale: make the predictive document browser scenario deterministic while retaining the real AG-UI request, HTTP/SSE response, and client-side confirmation flow. Implementation: record four threaded model calls with incremental document-state checkpoints, final write calls, accepted and rejected continuation summaries, and the expected message, tool, and state inputs. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 323b0ef8-7905-4041-8388-a08586c0bd34
Co-authored-by: Copilot App <[email protected]> Copilot-Session: 107505be-e7f2-4460-a204-829ed9f8b231
dd8b97e to
489a976
Compare
dariatiurina
left a comment
There was a problem hiding this comment.
I don't see anything of the note, except need to change dojo app, which has its own issue here: #68781
Overview
Adds transactional predictive state to
Microsoft.AspNetCore.Components.AIand demonstrates it in the document-edit dojo. Streamed edits are visible before confirmation, explicit acceptance commits them, and rejection or an unconfirmed terminal path restores the prior committed value.This PR is position 9 in native stack #68340 and depends directly on #68334. The shipping API remains provider-neutral while the sample and E2E test continue through the real
DojoClientto AG-UI HTTP and SSE boundary.Design
StateMapperContext.SetPredictiveStatemarks mapped state as provisional.AgentState<T>captures one baseline for the predictive transaction, replaces only the visible candidate as snapshots arrive, and exposes explicit accept and reject operations.AgentContextrejects pending predictive state on normal completion without confirmation, cancellation, failure, and disposal. Restore also rejects persisted predictive snapshots before committing restored state because the conversation thread does not currently record whether the user accepted them. Persistence of accepted predictive decisions is tracked in #68227.The predictive API mapping expands document writes into incremental state snapshots and one confirmation action for the request. Multiple writes update the same latest predictive value and do not create competing confirmations.
Review updates
No visual layout changes are included.
Validation
PredictiveStateTestspassed with 6 of 6 tests.PredictiveStateUpdatesScenarioTestspassed with 1 of 1 tests through the dual-host AG-UI path.