Files
agent-framework/dotnet/samples/AgentWebChat/AgentWebChat.AgentHost/HttpActorApiRouteBuilderExtensions.cs
T
Aditya Mandaleeka 28ad256931 .NET: Change Runtime namespaces to Microsoft.Agents.AI.Runtime (#957)
* Rename MEAI.Runtime to MAAI.Runtime.

* Missed.
2025-09-27 06:10:14 +00:00

73 lines
2.6 KiB
C#

// Copyright (c) Microsoft. All rights reserved.
using System.Diagnostics.CodeAnalysis;
using Microsoft.Agents.AI.Runtime;
using Microsoft.AspNetCore.Mvc;
namespace AgentWebChat.AgentHost;
internal static partial class HttpActorApiRouteBuilderExtensions
{
private const string BasePath = "/actors/v1";
public static void MapActors(this IEndpointRouteBuilder endpoints, IActorClient? actorClient = null, [StringSyntax("Route")] string? path = default)
{
path ??= BasePath;
actorClient ??= endpoints.ServiceProvider.GetRequiredService<IActorClient>();
var routeGroup = endpoints.MapGroup(path);
// GET /actors/v1/{actorType}/{actorKey}/{messageId}
routeGroup.MapGet(
"/{actorType}/{actorKey}/{messageId}", async (
string actorType,
string actorKey,
string messageId,
[FromQuery] bool? blocking,
[FromQuery] bool? streaming,
HttpContext context,
CancellationToken cancellationToken) =>
await HttpActorProcessor.GetResponseAsync(
actorType,
actorKey,
messageId,
blocking: blocking,
streaming: streaming,
context,
actorClient,
cancellationToken))
.WithName("GetActorResponse");
// POST /actors/v1/{actorType}/{actorKey}/{messageId}
routeGroup.MapPost(
"/{actorType}/{actorKey}/{messageId}", async (
string actorType,
string actorKey,
string messageId,
[FromQuery] bool? blocking,
[FromQuery] bool? streaming,
[FromBody] ActorRequest request,
CancellationToken cancellationToken) =>
await HttpActorProcessor.SendRequestAsync(
actorType,
actorKey,
messageId,
blocking: blocking,
streaming: streaming,
request,
actorClient,
cancellationToken))
.WithName("SendActorRequest");
// POST /actors/v1/{actorType}/{actorKey}/{messageId}:cancel
routeGroup.MapPost(
"/{actorType}/{actorKey}/{messageId}:cancel", async (
string actorType,
string actorKey,
string messageId,
CancellationToken cancellationToken) =>
await HttpActorProcessor.CancelRequestAsync(actorType, actorKey, messageId, actorClient, cancellationToken))
.WithName("CancelActorRequest");
}
}