Files
agent-framework/dotnet/src/Microsoft.Agents.AI.A2A/Extensions/A2APartExtensions.cs
T
CopilotGitHubstephentoubcopilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>Stephen ToubSergeyMenshykh
62854197aa .NET: Fix A2A conversion routines to ignore unknown content types instead of throwing exceptions (#1154)
* 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>
2025-10-06 10:29:43 +00:00

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
};
}