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
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package io.a2a.client.transport.grpc;

import static io.a2a.grpc.A2AServiceGrpc.A2AServiceBlockingV2Stub;
import static io.a2a.grpc.A2AServiceGrpc.A2AServiceStub;
import static io.a2a.grpc.utils.ProtoUtils.FromProto;
import static io.a2a.grpc.utils.ProtoUtils.ToProto;
import static io.a2a.util.Assert.checkNotNullParam;

import java.util.List;
Expand Down Expand Up @@ -127,9 +123,7 @@ public Task getTask(TaskQueryParams request, @Nullable ClientCallContext context

GetTaskRequest.Builder requestBuilder = GetTaskRequest.newBuilder();
requestBuilder.setName("tasks/" + request.id());
if (request.historyLength() != null) {
requestBuilder.setHistoryLength(request.historyLength());
}
requestBuilder.setHistoryLength(request.historyLength());
GetTaskRequest getTaskRequest = requestBuilder.build();
PayloadAndHeaders payloadAndHeaders = applyInterceptors(io.a2a.spec.GetTaskRequest.METHOD, getTaskRequest,
agentCard, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public Task getTask(TaskQueryParams taskQueryParams, @Nullable ClientCallContext
agentCard, context);
try {
String url;
if (taskQueryParams.historyLength() != null) {
if (taskQueryParams.historyLength() > 0) {
url = agentUrl + String.format("/v1/tasks/%1s?historyLength=%2d", taskQueryParams.id(), taskQueryParams.historyLength());
} else {
url = agentUrl + String.format("/v1/tasks/%1s", taskQueryParams.id());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ public void getTask(RoutingContext rc) {
if (taskId == null || taskId.isEmpty()) {
response = jsonRestHandler.createErrorResponse(new InvalidParamsError("bad task id"));
} else {
Integer historyLength = null;
int historyLength = 0;
if (rc.request().params().contains("history_length")) {
historyLength = Integer.valueOf(rc.request().params().get("history_length"));
historyLength = Integer.parseInt(rc.request().params().get("history_length"));
}
response = jsonRestHandler.getTask(taskId, historyLength, context);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -137,15 +138,15 @@ public void testGetTask_MethodNameSetInContext() {
when(mockHttpResponse.getStatusCode()).thenReturn(200);
when(mockHttpResponse.getContentType()).thenReturn("application/json");
when(mockHttpResponse.getBody()).thenReturn("{test:value}");
when(mockRestHandler.getTask(anyString(), any(), any(ServerCallContext.class))).thenReturn(mockHttpResponse);
when(mockRestHandler.getTask(anyString(), anyInt(), any(ServerCallContext.class))).thenReturn(mockHttpResponse);

ArgumentCaptor<ServerCallContext> contextCaptor = ArgumentCaptor.forClass(ServerCallContext.class);

// Act
routes.getTask(mockRoutingContext);

// Assert
verify(mockRestHandler).getTask(eq("task123"), eq(null), contextCaptor.capture());
verify(mockRestHandler).getTask(eq("task123"), anyInt(), contextCaptor.capture());
ServerCallContext capturedContext = contextCaptor.getValue();
assertNotNull(capturedContext);
assertEquals(GetTaskRequest.METHOD, capturedContext.getState().get(METHOD_NAME_KEY));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.util.function.Supplier;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Instance;
import jakarta.inject.Inject;

import io.a2a.server.ServerCallContext;
Expand All @@ -34,7 +33,6 @@
import io.a2a.server.events.TaskQueueExistsException;
import io.a2a.server.tasks.PushNotificationConfigStore;
import io.a2a.server.tasks.PushNotificationSender;
import io.a2a.server.tasks.TaskStateProvider;
import io.a2a.server.tasks.ResultAggregator;
import io.a2a.server.tasks.TaskManager;
import io.a2a.server.tasks.TaskStore;
Expand Down Expand Up @@ -103,14 +101,14 @@ public Task onGetTask(TaskQueryParams params, ServerCallContext context) throws
LOGGER.debug("No task found for {}. Throwing TaskNotFoundError", params.id());
throw new TaskNotFoundError();
}
if (params.historyLength() != null && task.getHistory() != null && params.historyLength() < task.getHistory().size()) {
if (task.getHistory() != null && params.historyLength() < task.getHistory().size()) {
List<Message> history;
if (params.historyLength() <= 0) {
history = new ArrayList<>();
history = task.getHistory();
} else {
history = task.getHistory().subList(
task.getHistory().size() - params.historyLength(),
task.getHistory().size() - 1);
task.getHistory().size());
}

task = new Task.Builder(task)
Expand Down
Loading