|
3 | 3 | import io.a2a.server.ServerCallContext; |
4 | 4 | import io.vertx.ext.web.RoutingContext; |
5 | 5 |
|
| 6 | +/** |
| 7 | + * Factory interface for creating {@link ServerCallContext} from Vert.x routing context. |
| 8 | + * |
| 9 | + * <p>This interface provides an extension point for customizing how {@link ServerCallContext} |
| 10 | + * instances are created in Quarkus REST applications. The default implementation in |
| 11 | + * {@link A2AServerRoutes} extracts standard information (user, headers, tenant, protocol version), |
| 12 | + * but applications can provide their own implementation to add custom context data. |
| 13 | + * |
| 14 | + * <h2>Default Behavior</h2> |
| 15 | + * <p>When no CDI bean implementing this interface is provided, {@link A2AServerRoutes} |
| 16 | + * creates contexts with: |
| 17 | + * <ul> |
| 18 | + * <li>User authentication from Quarkus Security</li> |
| 19 | + * <li>HTTP headers map</li> |
| 20 | + * <li>Tenant ID from URL path</li> |
| 21 | + * <li>A2A protocol version from {@code X-A2A-Version} header</li> |
| 22 | + * <li>Required extensions from {@code X-A2A-Extensions} header</li> |
| 23 | + * </ul> |
| 24 | + * |
| 25 | + * <h2>Custom Implementation Example</h2> |
| 26 | + * <pre>{@code |
| 27 | + * @ApplicationScoped |
| 28 | + * public class CustomCallContextFactory implements CallContextFactory { |
| 29 | + * @Override |
| 30 | + * public ServerCallContext build(RoutingContext rc) { |
| 31 | + * // Extract custom data from routing context |
| 32 | + * String orgId = rc.request().getHeader("X-Organization-ID"); |
| 33 | + * |
| 34 | + * Map<String, Object> state = new HashMap<>(); |
| 35 | + * state.put("organization", orgId); |
| 36 | + * state.put("requestId", UUID.randomUUID().toString()); |
| 37 | + * |
| 38 | + * return new ServerCallContext( |
| 39 | + * extractUser(rc), |
| 40 | + * state, |
| 41 | + * extractExtensions(rc), |
| 42 | + * extractVersion(rc) |
| 43 | + * ); |
| 44 | + * } |
| 45 | + * } |
| 46 | + * }</pre> |
| 47 | + * |
| 48 | + * @see ServerCallContext |
| 49 | + * @see A2AServerRoutes#createCallContext(RoutingContext, String) |
| 50 | + */ |
6 | 51 | public interface CallContextFactory { |
| 52 | + /** |
| 53 | + * Builds a {@link ServerCallContext} from a Vert.x routing context. |
| 54 | + * |
| 55 | + * <p>This method is called for each incoming HTTP request to create the context |
| 56 | + * that will be passed to the {@link io.a2a.server.requesthandlers.RequestHandler} |
| 57 | + * and eventually to the {@link io.a2a.server.agentexecution.AgentExecutor}. |
| 58 | + * |
| 59 | + * @param rc the Vert.x routing context containing request data |
| 60 | + * @return a new ServerCallContext with extracted authentication, headers, and metadata |
| 61 | + */ |
7 | 62 | ServerCallContext build(RoutingContext rc); |
8 | 63 | } |
0 commit comments