Skip to content

Commit c5a8b7e

Browse files
feat: model clean-up (#36)
* make required props not optional, use jsonrequired attribute instead of required one, etc * format test class * change type of FilePart.File property from the specific FileWithBytes to the FileContent base one.
1 parent 2cc12d2 commit c5a8b7e

26 files changed

+774
-721
lines changed

samples/AgentServer/AgentServer.http

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
### Query agent card for the echo agent
44
GET {{host}}/echo/.well-known/agent.json
55

6-
## curl -N -X GET http://localhost:5048/echo/.well-known/agent.json
6+
### curl -N -X GET http://localhost:5048/echo/.well-known/agent.json
77

88
### Send a message to the echo agent
99
POST {{host}}/echo
@@ -49,21 +49,19 @@ Content-Type: application/json
4949
}
5050
}
5151

52+
### curl -N -X POST http://localhost:5048/echo -H "Content-Type: application/json" -d '{ "id": "3","jsonrpc": "2.0","method": "task/sendsubscribe","params": {"id": "1234","message": {"role": "user","parts": [{"type": "text","text": "Hello, world!"}]}}}'
5253

53-
54-
## curl -N -X POST http://localhost:5048/echo -H "Content-Type: application/json" -d '{ "id": "3","jsonrpc": "2.0","method": "task/sendsubscribe","params": {"id": "1234","message": {"role": "user","parts": [{"type": "text","text": "Hello, world!"}]}}}'
55-
56-
###
54+
### Retrieve a task
5755
POST {{host}}/echotasks
5856
Content-Type: application/json
5957

6058
{
6159
"id": "3",
6260
"jsonrpc": "2.0",
63-
"method": "task/get",
61+
"method": "tasks/get",
6462
"params": {
6563
"id": "40dfa726-bc05-4fd4-aa3d-763d5972c9d0"
66-
}
64+
}
6765
}
6866

6967
### SendSubscribe the echo agent
@@ -132,17 +130,17 @@ Content-Type: application/json
132130
}
133131
}
134132

135-
###
133+
### Retrieve a task
136134
POST {{host}}/hostedclient
137135
Content-Type: application/json
138136

139137
{
140138
"id": "d589ff00-daba-49a0-a01c-fa2a0924ada3",
141139
"jsonrpc": "2.0",
142-
"method": "task/get",
140+
"method": "tasks/get",
143141
"params": {
144142
"id": "b6d9ce5c-c457-47af-be95-6bed646ab667"
145-
}
143+
}
146144
}
147145

148146

@@ -179,7 +177,7 @@ Content-Type: application/json
179177
{
180178
"id": "2",
181179
"jsonrpc": "2.0",
182-
"method": "task/get",
180+
"method": "tasks/get",
183181
"params": {
184182
"id": "c65e7047-2938-432f-bae0-660d6d9fda50"
185183
}

src/A2A.AspNetCore/A2AHttpProcessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ internal static async Task<IResult> SetPushNotification(TaskManager taskManager,
252252
var taskIdParams = new TaskIdParams { Id = id };
253253
var result = await taskManager.SetPushNotificationAsync(new TaskPushNotificationConfig
254254
{
255-
Id = id,
255+
TaskId = id,
256256
PushNotificationConfig = pushNotificationConfig
257257
});
258258

src/A2A/JsonRpc/JsonRpcError.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Text.Json;
2+
using System.Text.Json.Serialization;
23

34
namespace A2A;
45

@@ -10,17 +11,22 @@ public class JsonRpcError
1011
/// <summary>
1112
/// Gets or sets the number that indicates the error type that occurred.
1213
/// </summary>
13-
public int Code { get; set; }
14+
[JsonPropertyName("code")]
15+
[JsonRequired]
16+
public int Code { get; set; } = 0;
1417

1518
/// <summary>
1619
/// Gets or sets the string providing a short description of the error.
1720
/// </summary>
21+
[JsonPropertyName("message")]
22+
[JsonRequired]
1823
public string Message { get; set; } = string.Empty;
1924

2025
/// <summary>
2126
/// Gets or sets the primitive or structured value that contains additional information about the error.
2227
/// This may be omitted.
2328
/// </summary>
29+
[JsonPropertyName("data")]
2430
public JsonElement? Data { get; set; }
2531

2632
/// <summary>

src/A2A/JsonRpc/JsonRpcRequest.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public class JsonRpcRequest
1515
/// MUST be exactly "2.0".
1616
/// </remarks>
1717
[JsonPropertyName("jsonrpc")]
18+
[JsonRequired]
19+
1820
public string JsonRpc { get; set; } = "2.0";
1921

2022
/// <summary>
@@ -30,6 +32,7 @@ public class JsonRpcRequest
3032
/// Gets or sets the string containing the name of the method to be invoked.
3133
/// </summary>
3234
[JsonPropertyName("method")]
35+
[JsonRequired]
3336
public string Method { get; set; } = string.Empty;
3437

3538
/// <summary>

src/A2A/Models/AgentCard.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.ComponentModel.DataAnnotations;
21
using System.Text.Json.Serialization;
32

43
namespace A2A;
@@ -18,7 +17,7 @@ public class AgentCard
1817
/// Gets or sets the human readable name of the agent.
1918
/// </summary>
2019
[JsonPropertyName("name")]
21-
[Required]
20+
[JsonRequired]
2221
public string Name { get; set; } = string.Empty;
2322

2423
/// <summary>
@@ -30,8 +29,8 @@ public class AgentCard
3029
/// (e.g., "This agent helps users find recipes, plan meals, and get cooking instructions.")
3130
/// </remarks>
3231
[JsonPropertyName("description")]
33-
[Required]
34-
public string? Description { get; set; }
32+
[JsonRequired]
33+
public string Description { get; set; } = string.Empty;
3534

3635
/// <summary>
3736
/// Gets or sets a URL to the address the agent is hosted at.
@@ -40,7 +39,7 @@ public class AgentCard
4039
/// This represents the preferred endpoint as declared by the agent.
4140
/// </remarks>
4241
[JsonPropertyName("url")]
43-
[Required]
42+
[JsonRequired]
4443
public string Url { get; set; } = string.Empty;
4544

4645
/// <summary>
@@ -53,14 +52,14 @@ public class AgentCard
5352
/// Gets or sets the version of the agent - format is up to the provider.
5453
/// </summary>
5554
[JsonPropertyName("version")]
56-
[Required]
55+
[JsonRequired]
5756
public string Version { get; set; } = string.Empty;
5857

5958
/// <summary>
6059
/// The version of the A2A protocol this agent supports.
6160
/// </summary>
6261
[JsonPropertyName("protocolVersion")]
63-
[Required]
62+
[JsonRequired]
6463
public string ProtocolVersion { get; set; } = "0.2.3";
6564

6665
/// <summary>
@@ -73,7 +72,7 @@ public class AgentCard
7372
/// Gets or sets the optional capabilities supported by the agent.
7473
/// </summary>
7574
[JsonPropertyName("capabilities")]
76-
[Required]
75+
[JsonRequired]
7776
public AgentCapabilities Capabilities { get; set; } = new AgentCapabilities();
7877

7978
/// <summary>
@@ -95,19 +94,21 @@ public class AgentCard
9594
/// This can be overridden per-skill. Supported media types for input.
9695
/// </remarks>
9796
[JsonPropertyName("defaultInputModes")]
97+
[JsonRequired]
9898
public List<string> DefaultInputModes { get; set; } = ["text"];
9999

100100
/// <summary>
101101
/// Gets or sets the supported media types for output.
102102
/// </summary>
103103
[JsonPropertyName("defaultOutputModes")]
104+
[JsonRequired]
104105
public List<string> DefaultOutputModes { get; set; } = ["text"];
105106

106107
/// <summary>
107108
/// Gets or sets the skills that are a unit of capability that an agent can perform.
108109
/// </summary>
109110
[JsonPropertyName("skills")]
110-
[Required]
111+
[JsonRequired]
111112
public List<AgentSkill> Skills { get; set; } = [];
112113

113114
/// <summary>

src/A2A/Models/AgentInterface.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System.ComponentModel.DataAnnotations;
2-
using System.Text.Json.Serialization;
1+
using System.Text.Json.Serialization;
32

43
namespace A2A;
54

@@ -16,13 +15,13 @@ public class AgentInterface
1615
/// The core ones officially supported are JSONRPC, GRPC, and HTTP+JSON.
1716
/// </remarks>
1817
[JsonPropertyName("transport")]
19-
[Required]
18+
[JsonRequired]
2019
public required AgentTransport Transport { get; set; }
2120

2221
/// <summary>
2322
/// The target URL for the agent interface.
2423
/// </summary>
2524
[JsonPropertyName("url")]
26-
[Required]
25+
[JsonRequired]
2726
public required string Url { get; set; }
2827
}

src/A2A/Models/AgentProvider.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.ComponentModel.DataAnnotations;
21
using System.Text.Json.Serialization;
32

43
namespace A2A;
@@ -12,13 +11,13 @@ public class AgentProvider
1211
/// Agent provider's organization name.
1312
/// </summary>
1413
[JsonPropertyName("organization")]
15-
[Required]
14+
[JsonRequired]
1615
public string Organization { get; set; } = string.Empty;
1716

1817
/// <summary>
1918
/// Agent provider's URL.
2019
/// </summary>
2120
[JsonPropertyName("url")]
22-
[Required]
21+
[JsonRequired]
2322
public string Url { get; set; } = string.Empty;
2423
}

src/A2A/Models/AgentSkill.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.ComponentModel.DataAnnotations;
21
using System.Text.Json.Serialization;
32

43
namespace A2A;
@@ -12,14 +11,14 @@ public class AgentSkill
1211
/// Unique identifier for the agent's skill.
1312
/// </summary>
1413
[JsonPropertyName("id")]
15-
[Required]
14+
[JsonRequired]
1615
public string Id { get; set; } = string.Empty;
1716

1817
/// <summary>
1918
/// Human readable name of the skill.
2019
/// </summary>
2120
[JsonPropertyName("name")]
22-
[Required]
21+
[JsonRequired]
2322
public string Name { get; set; } = string.Empty;
2423

2524
/// <summary>
@@ -29,15 +28,15 @@ public class AgentSkill
2928
/// Will be used by the client or a human as a hint to understand what the skill does.
3029
/// </remarks>
3130
[JsonPropertyName("description")]
32-
[Required]
33-
public string? Description { get; set; }
31+
[JsonRequired]
32+
public string Description { get; set; } = string.Empty;
3433

3534
/// <summary>
3635
/// Set of tagwords describing classes of capabilities for this specific skill.
3736
/// </summary>
3837
[JsonPropertyName("tags")]
39-
[Required]
40-
public List<string>? Tags { get; set; }
38+
[JsonRequired]
39+
public List<string> Tags { get; set; } = [];
4140

4241
/// <summary>
4342
/// The set of example scenarios that the skill can perform.

src/A2A/Models/AgentTask.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class AgentTask : A2AResponse
2020
/// </summary>
2121
[JsonPropertyName("contextId")]
2222
[JsonRequired]
23-
public string? ContextId { get; set; }
23+
public string ContextId { get; set; } = string.Empty;
2424

2525
/// <summary>
2626
/// Current status of the task.

src/A2A/Models/DataPart.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ public class DataPart : Part
1212
/// Structured data content.
1313
/// </summary>
1414
[JsonPropertyName("data")]
15+
[JsonRequired]
1516
public Dictionary<string, JsonElement> Data { get; set; } = [];
1617
}

0 commit comments

Comments
 (0)