Skip to content

UIMessageStreamResult

Namespace: Vercel.AI.AspNetCore

public sealed class UIMessageStreamResult : IResult

SSE result for the AI SDK UI message protocol.

Inheritance: object

Implements: IResult

View source

UIMessageStreamResult(StreamTextResult, int?, Func<string, string>?)

Section titled “UIMessageStreamResult(StreamTextResult, int?, Func<string, string>?)”
public UIMessageStreamResult(StreamTextResult result, int? keepAliveMs = null, Func<string, string>? onError = null)

Creates a result that writes <code class=“paramref”>result</code>.

Parameters

Name Type Description
result StreamTextResult The stream to write.
keepAliveMs int? Optional idle interval, in milliseconds. Null sends no SSE comments.
onError Func<string, string> Optional mapper for error chunk text. Null writes An error occurred..

View source

public Task ExecuteAsync(HttpContext httpContext)

Write an HTTP response reflecting the result.

Parameters

Name Type Description
httpContext HttpContext The HttpContext for the current request.

Returns: Task — A task that represents the asynchronous execute operation.

View source

WriteAsync(StreamTextResult, Stream, int?, CancellationToken, Func<string, string>?)

Section titled “WriteAsync(StreamTextResult, Stream, int?, CancellationToken, Func<string, string>?)”
public static Task WriteAsync(StreamTextResult result, Stream destination, int? keepAliveMs = null, CancellationToken cancellationToken = default, Func<string, string>? onError = null)

Writes the UI message stream to <code class=“paramref”>destination</code>.

Parameters

Name Type Description
result StreamTextResult The stream to write.
destination Stream The response body or another writable stream.
keepAliveMs int? Optional idle interval, in milliseconds. Null sends no SSE comments. A positive value up to 2147483647 writes : stream-open before the start event and : keep-alive while the next part is still pending.
cancellationToken CancellationToken Cancels the write and stops keep-alive comments. ASP.NET Core passes HttpContext.RequestAborted.
onError Func<string, string> Optional mapper for error chunk text. Null writes An error occurred..

Returns: Task

View source

WriteChunksAsync(IReadOnlyList<JsonObject>, Stream, CancellationToken)

Section titled “WriteChunksAsync(IReadOnlyList<JsonObject>, Stream, CancellationToken)”
public static Task WriteChunksAsync(IReadOnlyList<JsonObject> chunks, Stream destination, CancellationToken cancellationToken = default)

Writes already-built UI message chunks as SSE, then data: [DONE].

Parameters

Name Type Description
chunks IReadOnlyList<JsonObject> Chunk objects. Each one is one data: frame.
destination Stream The response body or another writable stream.
cancellationToken CancellationToken Cancels the write.

Returns: Task

View source

Apache-2.0 · Copyright 2023 Vercel, Inc. · unofficial community port, not an official Vercel product