-
Notifications
You must be signed in to change notification settings - Fork 50
feat: add AdditionalInterfaces and PreferredTransport props #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
SergeyMenshykh
merged 5 commits into
a2aproject:main
from
SergeyMenshykh:add-additional-transport
Jul 8, 2025
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1d0d3b7
add AdditionalInterfaces and PreferredTransport props
SergeyMenshykh 5081eaa
add converter and tests
SergeyMenshykh 4ef8f74
Merge branch 'main' into add-additional-transport
SergeyMenshykh 35cf032
address pr review comment
SergeyMenshykh e6a7049
Merge branch 'add-additional-transport' of https://github.com/SergeyM…
SergeyMenshykh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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")] | ||
SergeyMenshykh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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; | ||
| } | ||
SergeyMenshykh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /// <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; | ||
| } | ||
35 changes: 35 additions & 0 deletions
35
src/A2A/Polyfills/System/Runtime/CompilerServices/CompilerFeatureRequiredAttribute.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
12 changes: 12 additions & 0 deletions
12
src/A2A/Polyfills/System/Runtime/CompilerServices/IsExternalInit.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
12 changes: 12 additions & 0 deletions
12
src/A2A/Polyfills/System/Runtime/CompilerServices/RequiredMemberAttribute.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.