-
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 all commits
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,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); | ||
| } | ||
| } | ||
| } |
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 |
Oops, something went wrong.
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.