Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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; }
}
120 changes: 120 additions & 0 deletions src/A2A/Models/AgentTransport.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
using System.Text.Json;
using System.Text.Json.Serialization;

namespace A2A;

/// <summary>
/// Represents the transport protocol for an AgentInterface.
/// </summary>
[JsonConverter(typeof(AgentTransportConverter))]
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>
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;

/// <summary>
/// Custom JSON converter for <see cref="AgentTransport"/> that serializes it as a simple string value.
/// </summary>
internal sealed class AgentTransportConverter : JsonConverter<AgentTransport>
{
/// <summary>
/// Reads and converts the JSON to <see cref="AgentTransport"/>.
/// </summary>
/// <param name="reader">The reader to read from.</param>
/// <param name="typeToConvert">The type to convert.</param>
/// <param name="options">Serializer options.</param>
/// <returns>The converted <see cref="AgentTransport"/>.</returns>
public override AgentTransport Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType != JsonTokenType.String)
{
throw new JsonException("Expected a string for AgentTransport.");
}

var label = reader.GetString();
if (string.IsNullOrWhiteSpace(label))
{
throw new JsonException("AgentTransport string value cannot be null or whitespace.");
}

return new AgentTransport(label!);
}

/// <summary>
/// Writes the <see cref="AgentTransport"/> as a JSON string.
/// </summary>
/// <param name="writer">The writer to write to.</param>
/// <param name="value">The value to convert.</param>
/// <param name="options">Serializer options.</param>
public override void Write(Utf8JsonWriter writer, AgentTransport value, JsonSerializerOptions options)
{
writer.WriteStringValue(value.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
Loading