-
Notifications
You must be signed in to change notification settings - Fork 736
Return InteractionReference from IInteractionService methods #13016
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
Co-authored-by: JamesNK <303201+JamesNK@users.noreply.github.com>
…assertions Co-authored-by: JamesNK <303201+JamesNK@users.noreply.github.com>
Co-authored-by: JamesNK <303201+JamesNK@users.noreply.github.com>
Co-authored-by: JamesNK <303201+JamesNK@users.noreply.github.com>
|
@copilot Rename Interaction to InteractionReference. Add id to reference. Add debuggerdisplayattribute to reference. |
… DebuggerDisplayAttribute Co-authored-by: JamesNK <303201+JamesNK@users.noreply.github.com>
Done in 675f44f. The class has been renamed to |
… GetResultAsync().DefaultTimeout() instead Co-authored-by: JamesNK <303201+JamesNK@users.noreply.github.com>
|
@copilot Id on the reference should be the same value as |
…ctionId Co-authored-by: JamesNK <303201+JamesNK@users.noreply.github.com>
Done in 9daddc3. The |
|
@davidfowl @mitchdenny @captainsafia @eerhardt What do you think of the interaction service returning an object that can act as a reference? I'm thinking about the situation where you want to link prompts together. var page1 = interactionService.PromptInputsAsync(inputs1);
var page2 = interactionService.PromptInputsAsync(inputs2, options: new { ShowAfterInteraction = page1 });
await page1;
await page2;It's a pretty niche scenario. But something to think about before making the API non-experimental. |
Return InteractionReference from IInteractionService methods
This PR implements the feature request to return a reference from IInteractionService methods before the result is available.
Changes completed:
InteractionReference<TResult>class (renamed fromInteraction<TResult>) that wraps a Task and provides:Idproperty - unique identifier matchingInteraction.InteractionIdGetResultAsync()method to get the resultCancel()method to cancel the interactionGetAwaiter()to support await directly on the InteractionReference objectConfigureAwait()for configurationIsCompletedproperty to check completion statusDebuggerDisplayAttributeshowing Id and IsCompletedInteractionReference<T>instead ofTask<InteractionResult<T>>Interactioninstances synchronously before creatingInteractionReferenceInteraction.InteractionIdtoInteractionReferenceconstructorInteractionReference<T>instances with matching IDsInteractionReference<T>instancesDefaultTimeoutextension methods forInteractionReference<T>- callers usereference.GetResultAsync().DefaultTimeout()insteadInteractionReference<T>objects usingGetResultAsync().DefaultTimeout()Technical approach:
The
InteractionReference<TResult>class implements the awaitable pattern so existing code that usesawaitcan continue to work with minimal changes. The class wraps the underlying task and provides additional control methods likeCancel().The
Interactionis now created synchronously at the start of each prompt method, ensuring the ID is available immediately. This ID is then passed to theInteractionReferenceconstructor, guaranteeing thatInteractionReference.IdmatchesInteraction.InteractionId.New API allows developers to:
Idproperty (matchesInteraction.InteractionId)IsCompletedpropertyCancel()methodGetResultAsync()for advanced scenariosExample usage:
Breaking change note:
This changes the return type of IInteractionService methods from
Task<InteractionResult<T>>toInteractionReference<T>. The InteractionReference class is awaitable, so existing code usingawaitwill continue to work. Code that explicitly typed variables asTask<InteractionResult<T>>will need to change toInteractionReference<T>or usevar.Implementation complete
All changes have been implemented and the full solution builds successfully.
Fixes #13015
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.