Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/A2A/Models/AgentCard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,22 @@ public class AgentCard
/// </remarks>
[JsonPropertyName("supportsAuthenticatedExtendedCard")]
public bool SupportsAuthenticatedExtendedCard { get; set; } = false;

/// <summary>
/// Announcement of additional supported transports.
/// </summary>
/// <remarks>
/// The client can use any of the supported transports.
/// </remarks>
[JsonPropertyName("additionalInterfaces")]
public List<AgentInterface>? AdditionalInterfaces { get; set; }

/// <summary>
/// The transport of the preferred endpoint.
/// </summary>
/// <remarks>
/// If empty, defaults to JSONRPC.
/// </remarks>
[JsonPropertyName("preferredTransport")]
public AgentTransport? PreferredTransport { get; set; }
}
28 changes: 28 additions & 0 deletions src/A2A/Models/AgentInterface.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;

namespace A2A;

/// <summary>
/// Provides a declaration of a combination of target URL and supported transport to interact with an agent.
/// </summary>
public class AgentInterface
{
/// <summary>
/// The transport supported by this URL.
/// </summary>
/// <remarks>
/// This is an open form string, to be easily extended for many transport protocols.
/// The core ones officially supported are JSONRPC, GRPC, and HTTP+JSON.
/// </remarks>
[JsonPropertyName("transport")]
[Required]
public required AgentTransport Transport { get; set; }

/// <summary>
/// The target URL for the agent interface.
/// </summary>
[JsonPropertyName("url")]
[Required]
public required string Url { get; set; }
}
79 changes: 79 additions & 0 deletions src/A2A/Models/AgentTransport.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using System.Text.Json.Serialization;

namespace A2A;

/// <summary>
/// Represents the transport protocol for an AgentInterface.
/// </summary>
public readonly struct AgentTransport : IEquatable<AgentTransport>
{
/// <summary>
/// JSON-RPC transport.
/// </summary>
public static AgentTransport JsonRpc { get; } = new("JSONRPC");

/// <summary>
/// Gets the label associated with this <see cref="AgentTransport"/>.
/// </summary>
[JsonPropertyName("transport")]
public string Label { get; }

/// <summary>
/// Creates a new <see cref="AgentTransport"/> instance with the provided label.
/// </summary>
/// <param name="label">The label to associate with this <see cref="AgentTransport"/>.</param>
[JsonConstructor]
public AgentTransport(string label)
{
if (string.IsNullOrWhiteSpace(label))
throw new ArgumentException("Transport label cannot be null or whitespace.", nameof(label));
this.Label = label;
}

/// <summary>
/// Determines whether two <see cref="AgentTransport"/> instances are equal.
/// </summary>
/// <param name="left">The first <see cref="AgentTransport"/> to compare.</param>
/// <param name="right">The second <see cref="AgentTransport"/> to compare.</param>
/// <returns><c>true</c> if the instances are equal; otherwise, <c>false</c>.</returns>
public static bool operator ==(AgentTransport left, AgentTransport right)
=> left.Equals(right);

/// <summary>
/// Determines whether two <see cref="AgentTransport"/> instances are not equal.
/// </summary>
/// <param name="left">The first <see cref="AgentTransport"/> to compare.</param>
/// <param name="right">The second <see cref="AgentTransport"/> to compare.</param>
/// <returns><c>true</c> if the instances are not equal; otherwise, <c>false</c>.</returns>
public static bool operator !=(AgentTransport left, AgentTransport right)
=> !(left == right);

/// <summary>
/// Determines whether the specified object is equal to the current <see cref="AgentTransport"/>.
/// </summary>
/// <param name="obj">The object to compare with the current <see cref="AgentTransport"/>.</param>
/// <returns><c>true</c> if the specified object is equal to the current <see cref="AgentTransport"/>; otherwise, <c>false</c>.</returns>
public override bool Equals(object? obj)
=> obj is AgentTransport other && this == other;

/// <summary>
/// Determines whether the specified <see cref="AgentTransport"/> is equal to the current <see cref="AgentTransport"/>.
/// </summary>
/// <param name="other">The <see cref="AgentTransport"/> to compare with the current <see cref="AgentTransport"/>.</param>
/// <returns><c>true</c> if the specified <see cref="AgentTransport"/> is equal to the current <see cref="AgentTransport"/>; otherwise, <c>false</c>.</returns>
public bool Equals(AgentTransport other)
=> string.Equals(this.Label, other.Label, StringComparison.OrdinalIgnoreCase);

/// <summary>
/// Returns the hash code for this <see cref="AgentTransport"/>.
/// </summary>
/// <returns>A hash code for the current <see cref="AgentTransport"/>.</returns>
public override int GetHashCode()
=> StringComparer.OrdinalIgnoreCase.GetHashCode(this.Label);

/// <summary>
/// Returns the string representation of this <see cref="AgentTransport"/>.
/// </summary>
/// <returns>The label of this <see cref="AgentTransport"/>.</returns>
public override string ToString() => this.Label;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#if !NETCOREAPP
namespace System.Runtime.CompilerServices;

[AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = false)]
internal sealed class CompilerFeatureRequiredAttribute : Attribute
{
public CompilerFeatureRequiredAttribute(string featureName)
{
this.FeatureName = featureName;
}

/// <summary>
/// The name of the compiler feature.
/// </summary>
public string FeatureName { get; }

/// <summary>
/// If true, the compiler can choose to allow access to the location where this attribute is applied if it does not understand <see cref="FeatureName"/>.
/// </summary>
public bool IsOptional { get; init; }

/// <summary>
/// The <see cref="FeatureName"/> used for the ref structs C# feature.
/// </summary>
public const string RefStructs = nameof(RefStructs);

/// <summary>
/// The <see cref="FeatureName"/> used for the required members C# feature.
/// </summary>
public const string RequiredMembers = nameof(RequiredMembers);
}
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#if !NETCOREAPP
namespace System.Runtime.CompilerServices;

/// <summary>
/// Reserved to be used by the compiler for tracking metadata.
/// This class should not be used by developers in source code.
/// </summary>
internal static class IsExternalInit;
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#if !NETCOREAPP
namespace System.Runtime.CompilerServices;

/// <summary>
/// Specifies that a type has required members or that a member is required.
/// </summary>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
internal sealed class RequiredMemberAttribute : Attribute;
#endif
79 changes: 79 additions & 0 deletions tests/A2A.UnitTests/Models/AgentTransportTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using System.Text.Json;

namespace A2A.UnitTests.Models;

public class AgentTransportTests
{
[Fact]
public void Constructor_SetsLabelCorrectly()
{
// Arrange & Act
var sut = new AgentTransport("JSONRPC");

// Assert
Assert.Equal("JSONRPC", sut.Label);
}

[Theory]
[InlineData(null)]
[InlineData("")]
[InlineData(" ")]
public void Constructor_ThrowsOnNullOrWhitespace(string? label)
{
// Act & Assert
Assert.Throws<ArgumentException>(() => new AgentTransport(label!));
}

[Fact]
public void Equality_Works_CaseInsensitive()
{
// Arrange
var sut = new AgentTransport("jsonrpc");
var other = new AgentTransport("JSONRPC");

// Act & Assert
Assert.True(sut == other);
Assert.False(sut != other);
Assert.True(sut.Equals(other));
Assert.True(sut.Equals((object)other));
Assert.Equal(sut.GetHashCode(), other.GetHashCode());
}

[Fact]
public void ToString_ReturnsLabel()
{
// Arrange
var sut = new AgentTransport("HTTP+JSON");

// Act
var result = sut.ToString();

// Assert
Assert.Equal("HTTP+JSON", result);
}

[Fact]
public void JsonRpc_StaticProperty_ReturnsExpected()
{
// Act
var sut = AgentTransport.JsonRpc;

// Assert
Assert.Equal("JSONRPC", sut.Label);
}

[Fact]
public void CanSerializeAndDeserialize()
{
// Arrange
var sut = new AgentTransport("GRPC");

// Act
var json = JsonSerializer.Serialize(sut);
var deserialized = JsonSerializer.Deserialize<AgentTransport>(json);

// Assert
Assert.Equal(sut, deserialized);
Assert.Equal("GRPC", deserialized!.Label);
}
}