Skip to content

Commit 78494f1

Browse files
committed
fix: allow omitted task push config id
Fixes a2aproject#1081
1 parent 46936c4 commit 78494f1

4 files changed

Lines changed: 32 additions & 12 deletions

File tree

‎server-common/src/main/java/org/a2aproject/sdk/server/tasks/InMemoryPushNotificationConfigStore.java‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,13 @@ public InMemoryPushNotificationConfigStore() {
4848
public TaskPushNotificationConfig setInfo(TaskPushNotificationConfig notificationConfig) {
4949
String taskId = Assert.checkNotNullParam("taskId", notificationConfig.taskId());
5050
TaskPushNotificationConfig.Builder builder = TaskPushNotificationConfig.builder(notificationConfig);
51-
if (notificationConfig.id().isEmpty()) {
51+
String requestedConfigId = notificationConfig.id();
52+
boolean configIdIsMissing = requestedConfigId == null || requestedConfigId.isEmpty();
53+
String configId = configIdIsMissing ? taskId : requestedConfigId;
54+
if (configIdIsMissing) {
5255
builder.id(taskId);
5356
}
5457
TaskPushNotificationConfig config = builder.build();
55-
String configId = config.id();
5658
int maxPerTask = PushNotificationConfigStore.maxPushConfigsPerTask(configProvider);
5759

5860
pushNotificationInfos.compute(taskId, (key, list) -> {

‎server-common/src/test/java/org/a2aproject/sdk/server/tasks/InMemoryPushNotificationConfigStoreTest.java‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ public void testSetInfoAppendsToExistingConfig() {
154154
public void testSetInfoWithoutConfigId() {
155155
String taskId = "task1";
156156
TaskPushNotificationConfig initialConfig = TaskPushNotificationConfig.builder()
157-
.id("") // No ID set
158157
.url("http://initial.url/callback")
159158
.taskId(taskId)
160159
.build();
@@ -167,7 +166,6 @@ public void testSetInfoWithoutConfigId() {
167166
assertEquals(taskId, configResult.configs().get(0).id());
168167

169168
TaskPushNotificationConfig updatedConfig = TaskPushNotificationConfig.builder()
170-
.id("") // No ID set
171169
.url("http://initial.url/callback_new")
172170
.taskId(taskId)
173171
.build();

‎spec/src/main/java/org/a2aproject/sdk/spec/TaskPushNotificationConfig.java‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
* Used for managing task-specific push notification settings via the push notification
2222
* management methods ({@code tasks/pushNotificationConfig/set}, {@code tasks/pushNotificationConfig/get}, etc.).
2323
*
24-
* @param id unique identifier (e.g. UUID) for this push notification configuration
24+
* @param id optional unique identifier (e.g. UUID) for this push notification configuration.
25+
* When omitted while creating a configuration, the server assigns one.
2526
* @param taskId the unique identifier of the task to receive push notifications for
2627
* @param url the HTTP/HTTPS endpoint URL to receive push notifications (required)
2728
* @param token optional bearer token for simple authentication
@@ -31,22 +32,21 @@
3132
* @see MessageSendConfiguration for configuring push notifications on message send
3233
* @see <a href="https://a2a-protocol.org/latest/">A2A Protocol Specification</a>
3334
*/
34-
public record TaskPushNotificationConfig(String id, @Nullable String taskId, String url, @Nullable String token,
35+
public record TaskPushNotificationConfig(@Nullable String id, @Nullable String taskId, String url, @Nullable String token,
3536
@Nullable AuthenticationInfo authentication, @Nullable String tenant) {
3637

3738
/**
3839
* Compact constructor for validation.
3940
* Validates that required parameters are not null.
4041
*
41-
* @param id the configuration identifier
42+
* @param id the optional configuration identifier
4243
* @param taskId the task identifier
4344
* @param url the notification endpoint URL
4445
* @param token optional bearer token
4546
* @param authentication optional authentication info
4647
* @param tenant the tenant identifier
4748
*/
4849
public TaskPushNotificationConfig {
49-
Assert.checkNotNullParam("id", id);
5050
Assert.checkNotNullParam("url", url);
5151
Utils.validateTenant(tenant);
5252
}
@@ -105,10 +105,10 @@ private Builder(TaskPushNotificationConfig config) {
105105
/**
106106
* Sets the configuration identifier.
107107
*
108-
* @param id the configuration ID
108+
* @param id the optional configuration ID
109109
* @return this builder
110110
*/
111-
public Builder id(String id) {
111+
public Builder id(@Nullable String id) {
112112
this.id = id;
113113
return this;
114114
}
@@ -172,11 +172,11 @@ public Builder tenant(String tenant) {
172172
* Builds the {@link TaskPushNotificationConfig}.
173173
*
174174
* @return a new push notification configuration
175-
* @throws IllegalArgumentException if id or url is null
175+
* @throws IllegalArgumentException if url is null
176176
*/
177177
public TaskPushNotificationConfig build() {
178178
return new TaskPushNotificationConfig(
179-
Assert.checkNotNullParam("id", id),
179+
id,
180180
taskId,
181181
Assert.checkNotNullParam("url", url),
182182
token,
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package org.a2aproject.sdk.spec;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertNull;
5+
6+
import org.junit.jupiter.api.Test;
7+
8+
class TaskPushNotificationConfigTest {
9+
10+
@Test
11+
void builderAllowsAnOmittedConfigurationId() {
12+
TaskPushNotificationConfig config = TaskPushNotificationConfig.builder()
13+
.taskId("task-123")
14+
.url("https://example.com/callback")
15+
.build();
16+
17+
assertNull(config.id());
18+
assertEquals("task-123", config.taskId());
19+
}
20+
}

0 commit comments

Comments
 (0)