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
72 changes: 35 additions & 37 deletions src/A2A/A2A.csproj
Original file line number Diff line number Diff line change
@@ -1,46 +1,44 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net9.0;net8.0;netstandard2.0</TargetFrameworks>
<PropertyGroup>
<TargetFrameworks>net9.0;net8.0;netstandard2.0</TargetFrameworks>

<!-- NuGet Package Properties -->
<PackageId>A2A</PackageId>
<Description>.NET SDK for the Agent2Agent (A2A) protocol.</Description>
<PackageTags>Agent2Agent;a2a;agent;ai;llm;aspnetcore</PackageTags>
<PackageReadmeFile>README.md</PackageReadmeFile>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<!-- Don't suggest using ArgumentNullException.ThrowIfNull as we target NS2.0 where it's not present -->
<NoWarn>$(NoWarn);CA1510</NoWarn>
</PropertyGroup>
<!-- NuGet Package Properties -->
<PackageId>A2A</PackageId>
<Description>.NET SDK for the Agent2Agent (A2A) protocol.</Description>
<PackageTags>Agent2Agent;a2a;agent;ai;llm;aspnetcore</PackageTags>
<PackageReadmeFile>README.md</PackageReadmeFile>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' != 'netstandard2.0'">
<IsAotCompatible>true</IsAotCompatible>
</PropertyGroup>
<!-- Dependencies only needed by netstandard2.0 -->
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="System.Text.Json" />
<PropertyGroup Condition="'$(TargetFramework)' != 'netstandard2.0'">
<IsAotCompatible>true</IsAotCompatible>
</PropertyGroup>

<!-- Dependencies only needed by netstandard2.0 -->
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="System.Text.Json" />
<PackageReference Include="System.Threading.Channels" />
</ItemGroup>
</ItemGroup>

<!-- Dependencies needed by all -->
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" />
<PackageReference Include="Microsoft.Extensions.ExtraAnalyzers">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging" />
<PackageReference Include="System.Linq.AsyncEnumerable" />
<PackageReference Include="System.Net.ServerSentEvents" />
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<!-- Dependencies needed by all -->
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" />
<PackageReference Include="Microsoft.Extensions.ExtraAnalyzers">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging" />
<PackageReference Include="System.Linq.AsyncEnumerable" />
<PackageReference Include="System.Net.ServerSentEvents" />
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<None Include="..\..\README.md" Pack="true" PackagePath="\" />
</ItemGroup>
<ItemGroup>
<None Include="..\..\README.md" Pack="true" PackagePath="\" />
</ItemGroup>

</Project>
5 changes: 3 additions & 2 deletions src/A2A/JsonRpc/JsonRpcRequestConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,12 @@ private static JsonRpcId ReadAndValidateIdField(JsonElement rootElement)
{
if (rootElement.TryGetProperty("id", out var idElement))
{
if (idElement.ValueKind != JsonValueKind.String &&
if ((idElement.ValueKind != JsonValueKind.String &&
idElement.ValueKind != JsonValueKind.Number &&
idElement.ValueKind != JsonValueKind.Null)
|| (idElement.ValueKind is JsonValueKind.Number && !idElement.TryGetInt64(out var _)))
{
throw new A2AException("Invalid JSON-RPC request: 'id' field must be a string, number, or null.", A2AErrorCode.InvalidRequest);
throw new A2AException("Invalid JSON-RPC request: 'id' field must be a string, non-fractional number, or null.", A2AErrorCode.InvalidRequest);
}

return idElement.ValueKind switch
Expand Down
3 changes: 2 additions & 1 deletion tests/A2A.AspNetCore.UnitTests/A2AJsonRpcProcessorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ public class A2AJsonRpcProcessorTests
{
[Theory]
[InlineData("\"test-id\"", true)] // String ID - valid
//[InlineData(42, true)] // Number ID - valid: Uncomment when numeric IDs are supported
[InlineData(42, true)] // Number ID - valid: Uncomment when numeric IDs are supported
[InlineData(42.1, false)] // Fractional number ID - invalid (should throw error)
[InlineData("null", true)] // Null ID - valid
[InlineData("true", false)] // Boolean ID - invalid (should throw error)
public async Task ValidateIdField_HandlesVariousIdTypes(object? idValue, bool isValid)
Expand Down
3 changes: 2 additions & 1 deletion tests/A2A.UnitTests/JsonRpc/JsonRpcRequestConverterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ public void Read_InvalidMethod_ThrowsA2AException(string methodJson)
[Theory]
[InlineData("true")]
[InlineData("[]")]
[InlineData("42.1")]
public void Read_InvalidIdType_ThrowsA2AException(string idJson)
{
// Arrange
Expand All @@ -288,7 +289,7 @@ public void Read_InvalidIdType_ThrowsA2AException(string idJson)
JsonSerializer.Deserialize<JsonRpcRequest>(json, _options));

Assert.Equal(A2AErrorCode.InvalidRequest, exception.ErrorCode);
Assert.Contains("'id' field must be a string, number, or null", exception.Message);
Assert.Contains("'id' field must be a string, non-fractional number, or null", exception.Message);
}

[Theory]
Expand Down