Skip to content
Merged
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
Expand Up @@ -16,8 +16,13 @@
import io.a2a.spec.TaskArtifactUpdateEvent;
import io.a2a.spec.TaskStatus;
import io.a2a.spec.TaskStatusUpdateEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TaskManager {

private static final Logger LOGGER = LoggerFactory.getLogger(TaskManager.class);

private volatile String taskId;
private volatile String contextId;
private final TaskStore taskStore;
Expand Down Expand Up @@ -101,16 +106,18 @@ Task saveTaskEvent(TaskArtifactUpdateEvent event) throws A2AServerException {
// This represents the first chunk for this artifact index
if (existingArtifactIndex >= 0) {
// Replace the existing artifact entirely with the new artifact
LOGGER.debug("Replacing artifact at id {} for task {}", artifactId, taskId);
artifacts.set(existingArtifactIndex, newArtifact);
} else {
// Append the new artifact since no artifact with this id/index exists yet
LOGGER.debug("Adding artifact at id {} for task {}", artifactId, taskId);
artifacts.add(newArtifact);
}

} else if (existingArtifact != null) {
// Append new parts to the existing artifact's parts list
// Do this to a copy

LOGGER.debug("Appending parts to artifact id {} for task {}", artifactId, taskId);
List<Part<?>> parts = new ArrayList<>(existingArtifact.parts());
parts.addAll(newArtifact.parts());
Artifact updated = new Artifact.Builder(existingArtifact)
Expand All @@ -120,6 +127,9 @@ Task saveTaskEvent(TaskArtifactUpdateEvent event) throws A2AServerException {
} else {
// We received a chunk to append, but we don't have an existing artifact.
// We will ignore this chunk
LOGGER.warn(
"Received append=true for nonexistent artifact index for artifact {} in task {}. Ignoring chunk.",
artifactId, taskId);
}

task = new Task.Builder(task)
Expand Down