public static class AcpClient.SyncSpec
extends java.lang.Object
The builder supports configuration of:
| 限定符和类型 | 方法和说明 |
|---|---|
AcpSyncClient |
build()
Creates an instance of
AcpSyncClient with the provided configurations
or sensible defaults. |
AcpClient.SyncSpec |
clientCapabilities(AcpSchema.ClientCapabilities clientCapabilities)
Sets the client capabilities that will be advertised to the agent during
initialization.
|
AcpClient.SyncSpec |
createTerminalHandler(java.util.function.Function<AcpSchema.CreateTerminalRequest,AcpSchema.CreateTerminalResponse> handler)
Adds a typed handler for terminal creation requests from the agent.
|
AcpClient.SyncSpec |
killTerminalHandler(java.util.function.Function<AcpSchema.KillTerminalCommandRequest,AcpSchema.KillTerminalCommandResponse> handler)
Adds a typed handler for terminal kill requests from the agent.
|
AcpClient.SyncSpec |
notificationHandler(java.lang.String method,
AcpClientSession.NotificationHandler handler)
Adds a custom notification handler for a specific method.
|
AcpClient.SyncSpec |
readTextFileHandler(java.util.function.Function<AcpSchema.ReadTextFileRequest,AcpSchema.ReadTextFileResponse> handler)
Adds a typed handler for file system read requests from the agent.
|
AcpClient.SyncSpec |
releaseTerminalHandler(java.util.function.Function<AcpSchema.ReleaseTerminalRequest,AcpSchema.ReleaseTerminalResponse> handler)
Adds a typed handler for terminal release requests from the agent.
|
<T> AcpClient.SyncSpec |
requestHandler(java.lang.String method,
AcpClient.SyncRequestHandler<T> handler)
Adds a synchronous custom request handler for a specific method.
|
AcpClient.SyncSpec |
requestPermissionHandler(java.util.function.Function<AcpSchema.RequestPermissionRequest,AcpSchema.RequestPermissionResponse> handler)
Adds a typed handler for permission requests from the agent.
|
AcpClient.SyncSpec |
requestTimeout(java.time.Duration requestTimeout)
Sets the duration to wait for agent responses before timing out requests.
|
AcpClient.SyncSpec |
sessionUpdateConsumer(java.util.function.Consumer<AcpSchema.SessionNotification> sessionUpdateConsumer)
Adds a synchronous consumer to be notified when session update notifications
are received from the agent.
|
AcpClient.SyncSpec |
terminalOutputHandler(java.util.function.Function<AcpSchema.TerminalOutputRequest,AcpSchema.TerminalOutputResponse> handler)
Adds a typed handler for terminal output requests from the agent.
|
AcpClient.SyncSpec |
waitForTerminalExitHandler(java.util.function.Function<AcpSchema.WaitForTerminalExitRequest,AcpSchema.WaitForTerminalExitResponse> handler)
Adds a typed handler for wait-for-terminal-exit requests from the agent.
|
AcpClient.SyncSpec |
writeTextFileHandler(java.util.function.Function<AcpSchema.WriteTextFileRequest,AcpSchema.WriteTextFileResponse> handler)
Adds a typed handler for file system write requests from the agent.
|
public AcpClient.SyncSpec requestTimeout(java.time.Duration requestTimeout)
requestTimeout - The duration to wait before timing out requests. Must not
be null.java.lang.IllegalArgumentException - if requestTimeout is nullpublic AcpClient.SyncSpec clientCapabilities(AcpSchema.ClientCapabilities clientCapabilities)
clientCapabilities - The client capabilities configuration. Must not be
null.java.lang.IllegalArgumentException - if clientCapabilities is nullpublic AcpClient.SyncSpec readTextFileHandler(java.util.function.Function<AcpSchema.ReadTextFileRequest,AcpSchema.ReadTextFileResponse> handler)
Example usage:
.readTextFileHandler(req ->
new ReadTextFileResponse(Files.readString(Path.of(req.path()))))
handler - The typed handler function that processes read requestsjava.lang.IllegalArgumentException - if handler is nullpublic AcpClient.SyncSpec writeTextFileHandler(java.util.function.Function<AcpSchema.WriteTextFileRequest,AcpSchema.WriteTextFileResponse> handler)
Example usage:
.writeTextFileHandler(req -> {
Files.writeString(Path.of(req.path()), req.content());
return new WriteTextFileResponse();
})
handler - The typed handler function that processes write requestsjava.lang.IllegalArgumentException - if handler is nullpublic AcpClient.SyncSpec requestPermissionHandler(java.util.function.Function<AcpSchema.RequestPermissionRequest,AcpSchema.RequestPermissionResponse> handler)
Example usage:
.requestPermissionHandler(req -> {
System.out.println("Permission requested: " + req.toolCall().title());
// Show UI or auto-approve
return new RequestPermissionResponse(
new RequestPermissionOutcome("approve", null));
})
handler - The typed handler function that processes permission requestsjava.lang.IllegalArgumentException - if handler is nullpublic AcpClient.SyncSpec createTerminalHandler(java.util.function.Function<AcpSchema.CreateTerminalRequest,AcpSchema.CreateTerminalResponse> handler)
Example usage:
.createTerminalHandler(req -> {
String terminalId = UUID.randomUUID().toString();
// Start process with req.command(), req.args(), req.cwd()
return new CreateTerminalResponse(terminalId);
})
handler - The typed handler function that processes terminal creation requestsjava.lang.IllegalArgumentException - if handler is nullpublic AcpClient.SyncSpec terminalOutputHandler(java.util.function.Function<AcpSchema.TerminalOutputRequest,AcpSchema.TerminalOutputResponse> handler)
Example usage:
.terminalOutputHandler(req -> {
String output = getTerminalOutput(req.terminalId());
return new TerminalOutputResponse(output, false, null);
})
handler - The typed handler function that processes terminal output requestsjava.lang.IllegalArgumentException - if handler is nullpublic AcpClient.SyncSpec releaseTerminalHandler(java.util.function.Function<AcpSchema.ReleaseTerminalRequest,AcpSchema.ReleaseTerminalResponse> handler)
Example usage:
.releaseTerminalHandler(req -> {
releaseTerminal(req.terminalId());
return new ReleaseTerminalResponse();
})
handler - The typed handler function that processes terminal release requestsjava.lang.IllegalArgumentException - if handler is nullpublic AcpClient.SyncSpec waitForTerminalExitHandler(java.util.function.Function<AcpSchema.WaitForTerminalExitRequest,AcpSchema.WaitForTerminalExitResponse> handler)
Example usage:
.waitForTerminalExitHandler(req -> {
int exitCode = waitForExit(req.terminalId());
return new WaitForTerminalExitResponse(exitCode, null);
})
handler - The typed handler function that processes wait-for-exit requestsjava.lang.IllegalArgumentException - if handler is nullpublic AcpClient.SyncSpec killTerminalHandler(java.util.function.Function<AcpSchema.KillTerminalCommandRequest,AcpSchema.KillTerminalCommandResponse> handler)
Example usage:
.killTerminalHandler(req -> {
killProcess(req.terminalId());
return new KillTerminalCommandResponse();
})
handler - The typed handler function that processes terminal kill requestsjava.lang.IllegalArgumentException - if handler is nullpublic AcpClient.SyncSpec sessionUpdateConsumer(java.util.function.Consumer<AcpSchema.SessionNotification> sessionUpdateConsumer)
Example usage:
.sessionUpdateConsumer(notification -> {
if (notification.update() instanceof AgentMessageChunk msg) {
System.out.println(msg.content());
}
})
sessionUpdateConsumer - A consumer that receives session update
notifications. Must not be null.java.lang.IllegalArgumentException - if sessionUpdateConsumer is nullpublic <T> AcpClient.SyncSpec requestHandler(java.lang.String method, AcpClient.SyncRequestHandler<T> handler)
T - The response typemethod - The method name (e.g., "custom/operation")handler - The synchronous handler function for this methodjava.lang.IllegalArgumentException - if method or handler is nullpublic AcpClient.SyncSpec notificationHandler(java.lang.String method, AcpClientSession.NotificationHandler handler)
method - The method name (e.g., "custom/notification")handler - The handler function for this methodjava.lang.IllegalArgumentException - if method or handler is nullpublic AcpSyncClient build()
AcpSyncClient with the provided configurations
or sensible defaults.AcpSyncClient