Skip to content

Commit 174b535

Browse files
Phase 7: SendAsync(string) / SendAndWaitAsync(string) convenience overloads
Most SDK uses end up looking like SendAsync(new MessageOptions { Prompt = ... }); add a plain-prompt overload that wraps it. Per ApiView #258. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 734d80d commit 174b535

1 file changed

Lines changed: 33 additions & 6 deletions

File tree

dotnet/src/Session.cs

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,19 +191,46 @@ private Task<T> InvokeRpcAsync<T>(string method, object?[]? args, CancellationTo
191191
}
192192

193193
/// <summary>
194-
/// Sends a message to the Copilot session and waits for the response.
194+
/// Sends a plain-text user message and returns the message ID without waiting for
195+
/// the assistant to reply. Convenience overload for <see cref="SendAsync(MessageOptions, CancellationToken)"/>.
196+
/// </summary>
197+
/// <param name="prompt">The user message text.</param>
198+
/// <param name="cancellationToken">A <see cref="CancellationToken"/> that can be used to cancel the operation.</param>
199+
/// <returns>A task that resolves with the message ID.</returns>
200+
public Task<string> SendAsync(string prompt, CancellationToken cancellationToken = default)
201+
{
202+
ArgumentNullException.ThrowIfNull(prompt);
203+
return SendAsync(new MessageOptions { Prompt = prompt }, cancellationToken);
204+
}
205+
206+
/// <summary>
207+
/// Sends a plain-text user message and waits until the session becomes idle.
208+
/// Convenience overload for <see cref="SendAndWaitAsync(MessageOptions, TimeSpan?, CancellationToken)"/>.
209+
/// </summary>
210+
/// <param name="prompt">The user message text.</param>
211+
/// <param name="timeout">Timeout duration (default: 60 seconds).</param>
212+
/// <param name="cancellationToken">A <see cref="CancellationToken"/> that can be used to cancel the operation.</param>
213+
/// <returns>A task that resolves with the final assistant message event, or null if none was received.</returns>
214+
public Task<AssistantMessageEvent?> SendAndWaitAsync(string prompt, TimeSpan? timeout = null, CancellationToken cancellationToken = default)
215+
{
216+
ArgumentNullException.ThrowIfNull(prompt);
217+
return SendAndWaitAsync(new MessageOptions { Prompt = prompt }, timeout, cancellationToken);
218+
}
219+
220+
/// <summary>
221+
/// Sends a message to the Copilot session.
195222
/// </summary>
196223
/// <param name="options">Options for the message to be sent, including the prompt and optional attachments.</param>
197224
/// <param name="cancellationToken">A <see cref="CancellationToken"/> that can be used to cancel the operation.</param>
198225
/// <returns>A task that resolves with the ID of the response message, which can be used to correlate events.</returns>
199226
/// <exception cref="InvalidOperationException">Thrown if the session has been disposed.</exception>
200227
/// <remarks>
201228
/// <para>
202-
/// This method returns immediately after the message is queued. Use <see cref="SendAndWaitAsync"/>
229+
/// This method returns immediately after the message is queued. Use <see cref="SendAndWaitAsync(MessageOptions, TimeSpan?, CancellationToken)"/>
203230
/// if you need to wait for the assistant to finish processing.
204231
/// </para>
205232
/// <para>
206-
/// Subscribe to events via <see cref="On"/> to receive streaming responses and other session events.
233+
/// Subscribe to events via <see cref="On{T}"/> to receive streaming responses and other session events.
207234
/// </para>
208235
/// </remarks>
209236
/// <example>
@@ -260,12 +287,12 @@ public async Task<string> SendAsync(MessageOptions options, CancellationToken ca
260287
/// <exception cref="InvalidOperationException">Thrown if the session has been disposed.</exception>
261288
/// <remarks>
262289
/// <para>
263-
/// This is a convenience method that combines <see cref="SendAsync"/> with waiting for
290+
/// This is a convenience method that combines <see cref="SendAsync(MessageOptions, CancellationToken)"/> with waiting for
264291
/// the <c>session.idle</c> event. Use this when you want to block until the assistant
265292
/// has finished processing the message.
266293
/// </para>
267294
/// <para>
268-
/// Events are still delivered to handlers registered via <see cref="On"/> while waiting.
295+
/// Events are still delivered to handlers registered via <see cref="On{T}"/> while waiting.
269296
/// </para>
270297
/// </remarks>
271298
/// <example>
@@ -1449,7 +1476,7 @@ public async Task LogAsync(string message, SessionLogLevel? level = null, bool?
14491476
/// <returns>A task representing the dispose operation.</returns>
14501477
/// <remarks>
14511478
/// <para>
1452-
/// The caller should ensure the session is idle (e.g., <see cref="SendAndWaitAsync"/>
1479+
/// The caller should ensure the session is idle (e.g., <see cref="SendAndWaitAsync(MessageOptions, TimeSpan?, CancellationToken)"/>
14531480
/// has returned) before disposing. If the session is not idle, in-flight event handlers
14541481
/// or tool handlers may observe failures.
14551482
/// </para>

0 commit comments

Comments
 (0)