-
Notifications
You must be signed in to change notification settings - Fork 668
Add Name property to InteractionInput and enable name-based access in results #10835
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…ests Co-authored-by: JamesNK <[email protected]>
Co-authored-by: JamesNK <[email protected]>
30dda1d
to
8b16283
Compare
@davidfowl @mitchdenny Alternatively, if you don't specify a name then the input isn't accessible by name, just using the index (current behavior). I'm not a fan of generating the name, but curious what you all think. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for accessing interaction inputs by name instead of just by index, implementing name-based access functionality for the interaction service. The changes enable users to specify optional names for inputs and access them through a new InteractionInputCollection
class.
- Adds an optional
Name
property toInteractionInput
for explicit naming - Introduces
InteractionInputCollection
that supports both indexed and name-based access with automatic name generation - Updates the interaction service API to return
InteractionInputCollection
instead ofIReadOnlyList<InteractionInput>
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
src/Aspire.Hosting/IInteractionService.cs | Adds InteractionInputCollection class with name-based access capabilities and updates InteractionInput with Name property |
src/Aspire.Hosting/InteractionService.cs | Updates method signatures to use InteractionInputCollection and handles early validation/name generation |
src/Aspire.Hosting/api/Aspire.Hosting.cs | Updates public API signatures to reflect the new collection type |
tests/Aspire.Hosting.Tests/InteractionServiceTests.cs | Comprehensive test coverage for name-based access, validation, and edge cases |
tests/Shared/TestInteractionService.cs | Updates test service implementation to work with new collection type |
Comments suppressed due to low confidence (1)
tests/Aspire.Hosting.Tests/InteractionServiceTests.cs:45
- This line creates a nested InteractionInputCollection by wrapping result.Data (which is already an InteractionInputCollection) in another collection. This could cause issues with the wrapped collection's functionality.
// Act 1
@JamesNK the API is experimental. We could make the Name required at this early stage? Better to be more explicit than less? |
There are scenarios where you don't want name to be required. For example: var result = await interactionService.PromptInputAsync(
title: "Hello world",
message: "What is your name?",
input: new InteractionInput { Label = "Name", InputType = InputType.Text }); You wouldn't want to require a name here because it's never used. |
This PR adds support for accessing interaction inputs by name instead of just by index, as requested in the issue.
Changes Made
1. Added optional
Name
property toInteractionInput
Users can now specify a name for each input that will be used for lookup:
2. Created
InteractionInputCollection
classA new collection type that supports both indexed and name-based access:
3. Automatic name generation
When no name is specified, names are automatically generated from labels:
"User Name"
becomes"User_Name"
"Email Address"
becomes"Email_Address"
"Input"
,"Input_1"
,"Input_2"
)4. Duplicate name validation
Clear error messages are thrown when duplicate names are provided:
5. Enhanced validation context
InputsDialogValidationContext.Inputs
now supports name-based access:Backward Compatibility
All existing code continues to work unchanged:
PromptInputsAsync
results still support indexed accessInputsDialogValidationContext.Inputs
still supports enumeration and indexingAdditional Features
TryGetByName(name, out input)
for safe name-based lookupContainsName(name)
to check if a name existsNames
property to enumerate all available namesFixes #10834.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.