mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
* Initial plan * Infrastructure setup * Plan for minimal client * Plan update * Basic agentic chat * cleanup * Cleanups * More cleanups * Cleanups * More cleanups * Test plan * Sample * Fix streaming and error handling * Fix notifications * Cleanups * cleanup sample * Additional tests * Additional tests * Run dotnet format * Remove unnecessary files * Mark packages as non packable * Fix build * Address feedback * Fix build * Fix remaining warnings * Feedback * Feedback and cleanup * Cleanup * Cleanups * Cleanups * Cleanups * Retrieve existing messages from the store to send them along the way and update the sample client * Run dotnet format * Add ADR for AG-UI * Switch to use the SG and use a convention for run ids * Cleanup MapAGUI API * Fix formatting * Fix solution * Fix solution
49 lines
1.6 KiB
C#
49 lines
1.6 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using Microsoft.Extensions.AI;
|
|
|
|
#if ASPNETCORE
|
|
namespace Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.Shared;
|
|
#else
|
|
namespace Microsoft.Agents.AI.AGUI.Shared;
|
|
#endif
|
|
|
|
internal static class AGUIChatMessageExtensions
|
|
{
|
|
private static readonly ChatRole s_developerChatRole = new("developer");
|
|
|
|
public static IEnumerable<ChatMessage> AsChatMessages(
|
|
this IEnumerable<AGUIMessage> aguiMessages)
|
|
{
|
|
foreach (var message in aguiMessages)
|
|
{
|
|
yield return new ChatMessage(
|
|
MapChatRole(message.Role),
|
|
message.Content);
|
|
}
|
|
}
|
|
|
|
public static IEnumerable<AGUIMessage> AsAGUIMessages(
|
|
this IEnumerable<ChatMessage> chatMessages)
|
|
{
|
|
foreach (var message in chatMessages)
|
|
{
|
|
yield return new AGUIMessage
|
|
{
|
|
Id = message.MessageId,
|
|
Role = message.Role.Value,
|
|
Content = message.Text,
|
|
};
|
|
}
|
|
}
|
|
|
|
public static ChatRole MapChatRole(string role) =>
|
|
string.Equals(role, AGUIRoles.System, StringComparison.OrdinalIgnoreCase) ? ChatRole.System :
|
|
string.Equals(role, AGUIRoles.User, StringComparison.OrdinalIgnoreCase) ? ChatRole.User :
|
|
string.Equals(role, AGUIRoles.Assistant, StringComparison.OrdinalIgnoreCase) ? ChatRole.Assistant :
|
|
string.Equals(role, AGUIRoles.Developer, StringComparison.OrdinalIgnoreCase) ? s_developerChatRole :
|
|
throw new InvalidOperationException($"Unknown chat role: {role}");
|
|
}
|