|
| 1 | +package io.a2a.client.transport; |
| 2 | + |
| 3 | +import java.util.List; |
| 4 | +import java.util.function.Consumer; |
| 5 | + |
| 6 | +import io.a2a.client.ClientCallContext; |
| 7 | +import io.a2a.spec.A2AClientException; |
| 8 | +import io.a2a.spec.A2AServerException; |
| 9 | +import io.a2a.spec.AgentCard; |
| 10 | +import io.a2a.spec.DeleteTaskPushNotificationConfigParams; |
| 11 | +import io.a2a.spec.EventKind; |
| 12 | +import io.a2a.spec.GetTaskPushNotificationConfigParams; |
| 13 | +import io.a2a.spec.ListTaskPushNotificationConfigParams; |
| 14 | +import io.a2a.spec.MessageSendParams; |
| 15 | +import io.a2a.spec.StreamingEventKind; |
| 16 | +import io.a2a.spec.Task; |
| 17 | +import io.a2a.spec.TaskIdParams; |
| 18 | +import io.a2a.spec.TaskPushNotificationConfig; |
| 19 | +import io.a2a.spec.TaskQueryParams; |
| 20 | + |
| 21 | +/** |
| 22 | + * Abstract base class for a client transport. |
| 23 | + */ |
| 24 | +public abstract class ClientTransport { |
| 25 | + |
| 26 | + /** |
| 27 | + * Send a non-streaming message request to the agent. |
| 28 | + * |
| 29 | + * @param request the message send parameters |
| 30 | + * @param context optional client call context for the request (may be {@code null}) |
| 31 | + * @return the response, either a Task or Message |
| 32 | + * @throws A2AClientException if sending the message fails for any reason |
| 33 | + */ |
| 34 | + public abstract EventKind sendMessage(MessageSendParams request, ClientCallContext context) |
| 35 | + throws A2AClientException; |
| 36 | + |
| 37 | + /** |
| 38 | + * Send a streaming message request to the agent and receive responses as they arrive. |
| 39 | + * |
| 40 | + * @param request the message send parameters |
| 41 | + * @param eventConsumer consumer that will receive streaming events as they arrive |
| 42 | + * @param errorConsumer consumer that will be called if an error occurs during streaming |
| 43 | + * @param context optional client call context for the request (may be {@code null}) |
| 44 | + * @throws A2AClientException if setting up the streaming connection fails |
| 45 | + */ |
| 46 | + public abstract void sendMessageStreaming(MessageSendParams request, Consumer<StreamingEventKind> eventConsumer, |
| 47 | + Consumer<Throwable> errorConsumer, ClientCallContext context) throws A2AClientException; |
| 48 | + |
| 49 | + /** |
| 50 | + * Retrieve the current state and history of a specific task. |
| 51 | + * |
| 52 | + * @param request the task query parameters specifying which task to retrieve |
| 53 | + * @param context optional client call context for the request (may be {@code null}) |
| 54 | + * @return the task |
| 55 | + * @throws A2AClientException if retrieving the task fails for any reason |
| 56 | + */ |
| 57 | + public abstract Task getTask(TaskQueryParams request, ClientCallContext context) throws A2AClientException; |
| 58 | + |
| 59 | + /** |
| 60 | + * Request the agent to cancel a specific task. |
| 61 | + * |
| 62 | + * @param request the task ID parameters specifying which task to cancel |
| 63 | + * @param context optional client call context for the request (may be {@code null}) |
| 64 | + * @return the cancelled task |
| 65 | + * @throws A2AClientException if cancelling the task fails for any reason |
| 66 | + */ |
| 67 | + public abstract Task cancelTask(TaskIdParams request, ClientCallContext context) throws A2AClientException; |
| 68 | + |
| 69 | + /** |
| 70 | + * Set or update the push notification configuration for a specific task. |
| 71 | + * |
| 72 | + * @param request the push notification configuration to set for the task |
| 73 | + * @param context optional client call context for the request (may be {@code null}) |
| 74 | + * @return the configured TaskPushNotificationConfig |
| 75 | + * @throws A2AClientException if setting the task push notification configuration fails for any reason |
| 76 | + */ |
| 77 | + public abstract TaskPushNotificationConfig setTaskPushNotificationConfiguration(TaskPushNotificationConfig request, |
| 78 | + ClientCallContext context) throws A2AClientException; |
| 79 | + |
| 80 | + /** |
| 81 | + * Retrieve the push notification configuration for a specific task. |
| 82 | + * |
| 83 | + * @param request the parameters specifying which task's notification config to retrieve |
| 84 | + * @param context optional client call context for the request (may be {@code null}) |
| 85 | + * @return the task push notification config |
| 86 | + * @throws A2AClientException if getting the task push notification config fails for any reason |
| 87 | + */ |
| 88 | + public abstract TaskPushNotificationConfig getTaskPushNotificationConfiguration( |
| 89 | + GetTaskPushNotificationConfigParams request, |
| 90 | + ClientCallContext context) throws A2AClientException; |
| 91 | + |
| 92 | + /** |
| 93 | + * Retrieve the list of push notification configurations for a specific task. |
| 94 | + * |
| 95 | + * @param request the parameters specifying which task's notification configs to retrieve |
| 96 | + * @param context optional client call context for the request (may be {@code null}) |
| 97 | + * @return the list of task push notification configs |
| 98 | + * @throws A2AClientException if getting the task push notification configs fails for any reason |
| 99 | + */ |
| 100 | + public abstract List<TaskPushNotificationConfig> listTaskPushNotificationConfigurations( |
| 101 | + ListTaskPushNotificationConfigParams request, |
| 102 | + ClientCallContext context) throws A2AClientException; |
| 103 | + |
| 104 | + /** |
| 105 | + * Delete the list of push notification configurations for a specific task. |
| 106 | + * |
| 107 | + * @param request the parameters specifying which task's notification configs to delete |
| 108 | + * @param context optional client call context for the request (may be {@code null}) |
| 109 | + * @throws A2AClientException if deleting the task push notification configs fails for any reason |
| 110 | + */ |
| 111 | + public abstract void deleteTaskPushNotificationConfigurations( |
| 112 | + DeleteTaskPushNotificationConfigParams request, |
| 113 | + ClientCallContext context) throws A2AClientException; |
| 114 | + |
| 115 | + /** |
| 116 | + * Reconnect to get task updates for an existing task. |
| 117 | + * |
| 118 | + * @param request the task ID parameters specifying which task to resubscribe to |
| 119 | + * @param eventConsumer consumer that will receive streaming events as they arrive |
| 120 | + * @param errorConsumer consumer that will be called if an error occurs during streaming |
| 121 | + * @param context optional client call context for the request (may be {@code null}) |
| 122 | + * @throws A2AClientException if resubscribing to the task fails for any reason |
| 123 | + */ |
| 124 | + public abstract void resubscribe(TaskIdParams request, Consumer<StreamingEventKind> eventConsumer, |
| 125 | + Consumer<Throwable> errorConsumer, ClientCallContext context) throws A2AClientException; |
| 126 | + |
| 127 | + /** |
| 128 | + * Retrieve the AgentCard. |
| 129 | + * |
| 130 | + * @param context optional client call context for the request (may be {@code null}) |
| 131 | + * @return the AgentCard |
| 132 | + * @throws A2AClientException if retrieving the agent card fails for any reason |
| 133 | + */ |
| 134 | + public abstract AgentCard getAgentCard(ClientCallContext context) throws A2AClientException; |
| 135 | + |
| 136 | + /** |
| 137 | + * Close the transport and release any associated resources. |
| 138 | + */ |
| 139 | + public abstract void close(); |
| 140 | +} |
0 commit comments