mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
* Initial plan * Update A2A conversion routines to ignore unknown content types Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com> * Fix dotnet format --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com> Co-authored-by: Stephen Toub <stoub@microsoft.com> Co-authored-by: SergeyMenshykh <68852919+SergeyMenshykh@users.noreply.github.com>
36 lines
1.2 KiB
C#
36 lines
1.2 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
using Microsoft.Extensions.AI;
|
|
|
|
namespace A2A;
|
|
|
|
/// <summary>
|
|
/// Extension methods for the <see cref="Part"/> class.
|
|
/// </summary>
|
|
internal static class A2APartExtensions
|
|
{
|
|
/// <summary>
|
|
/// Converts an A2A <see cref="Part"/> to an <see cref="AIContent"/>.
|
|
/// </summary>
|
|
/// <param name="part">The A2A part to convert.</param>
|
|
/// <returns>The corresponding <see cref="AIContent"/>, or null if the part type is not supported.</returns>
|
|
internal static AIContent? ToAIContent(this Part part) =>
|
|
part switch
|
|
{
|
|
TextPart textPart => new TextContent(textPart.Text)
|
|
{
|
|
RawRepresentation = textPart,
|
|
AdditionalProperties = textPart.Metadata.ToAdditionalProperties()
|
|
},
|
|
|
|
FilePart filePart when filePart.File is FileWithUri fileWithUrl => new HostedFileContent(fileWithUrl.Uri)
|
|
{
|
|
RawRepresentation = filePart,
|
|
AdditionalProperties = filePart.Metadata.ToAdditionalProperties()
|
|
},
|
|
|
|
// Ignore unknown part types (DataPart, etc.)
|
|
_ => null
|
|
};
|
|
}
|