public class AcpSyncAgent
extends java.lang.Object
This is a blocking wrapper around AcpAsyncAgent that uses block()
to convert reactive operations to blocking calls. Use this when you prefer a
simpler synchronous API and don't need the scalability of non-blocking operations.
AcpAsyncAgent,
AcpAgent| 构造器和说明 |
|---|
AcpSyncAgent(AcpAsyncAgent asyncAgent)
Creates a new synchronous agent wrapping the given async agent.
|
AcpSyncAgent(AcpAsyncAgent asyncAgent,
java.time.Duration blockTimeout)
Creates a new synchronous agent wrapping the given async agent.
|
| 限定符和类型 | 方法和说明 |
|---|---|
AcpAsyncAgent |
async()
Returns the underlying async agent.
|
void |
await()
Blocks until the agent terminates (transport closes).
|
void |
close()
Closes the agent immediately.
|
void |
closeGracefully()
Closes the agent gracefully, allowing pending operations to complete.
|
AcpSchema.CreateTerminalResponse |
createTerminal(AcpSchema.CreateTerminalRequest request)
Requests the client to create a terminal.
|
NegotiatedCapabilities |
getClientCapabilities()
Returns the capabilities negotiated with the client during initialization.
|
AcpSchema.TerminalOutputResponse |
getTerminalOutput(AcpSchema.TerminalOutputRequest request)
Requests terminal output from the client.
|
AcpSchema.KillTerminalCommandResponse |
killTerminal(AcpSchema.KillTerminalCommandRequest request)
Requests the client to kill a terminal.
|
AcpSchema.ReadTextFileResponse |
readTextFile(AcpSchema.ReadTextFileRequest request)
Requests the client to read a text file.
|
AcpSchema.ReleaseTerminalResponse |
releaseTerminal(AcpSchema.ReleaseTerminalRequest request)
Requests the client to release a terminal.
|
AcpSchema.RequestPermissionResponse |
requestPermission(AcpSchema.RequestPermissionRequest request)
Requests permission from the client for a sensitive operation.
|
void |
run()
Starts the agent and blocks until it terminates.
|
void |
sendSessionUpdate(java.lang.String sessionId,
AcpSchema.SessionUpdate update)
Sends a session update notification to the client.
|
void |
start()
Starts the agent, beginning to accept client connections.
|
AcpSchema.WaitForTerminalExitResponse |
waitForTerminalExit(AcpSchema.WaitForTerminalExitRequest request)
Waits for a terminal to exit.
|
AcpSchema.WriteTextFileResponse |
writeTextFile(AcpSchema.WriteTextFileRequest request)
Requests the client to write a text file.
|
public AcpSyncAgent(AcpAsyncAgent asyncAgent)
asyncAgent - The async agent to wrappublic AcpSyncAgent(AcpAsyncAgent asyncAgent, java.time.Duration blockTimeout)
asyncAgent - The async agent to wrapblockTimeout - The timeout for blocking operationspublic void start()
public void await()
Example usage:
agent.start();
agent.await(); // Blocks until stdin closes
public void run()
start() and await().
Example usage for a standalone agent:
public static void main(String[] args) {
AcpSyncAgent agent = AcpAgent.sync(transport)
.promptHandler(...)
.build();
agent.run(); // Start and block until done
}
public void sendSessionUpdate(java.lang.String sessionId,
AcpSchema.SessionUpdate update)
sessionId - The session IDupdate - The session update to sendpublic AcpSchema.RequestPermissionResponse requestPermission(AcpSchema.RequestPermissionRequest request)
request - The permission requestpublic AcpSchema.ReadTextFileResponse readTextFile(AcpSchema.ReadTextFileRequest request)
request - The read file requestpublic AcpSchema.WriteTextFileResponse writeTextFile(AcpSchema.WriteTextFileRequest request)
request - The write file requestpublic AcpSchema.CreateTerminalResponse createTerminal(AcpSchema.CreateTerminalRequest request)
request - The create terminal requestpublic AcpSchema.TerminalOutputResponse getTerminalOutput(AcpSchema.TerminalOutputRequest request)
request - The terminal output requestpublic AcpSchema.ReleaseTerminalResponse releaseTerminal(AcpSchema.ReleaseTerminalRequest request)
request - The release terminal requestpublic AcpSchema.WaitForTerminalExitResponse waitForTerminalExit(AcpSchema.WaitForTerminalExitRequest request)
request - The wait for exit requestpublic AcpSchema.KillTerminalCommandResponse killTerminal(AcpSchema.KillTerminalCommandRequest request)
request - The kill terminal requestpublic NegotiatedCapabilities getClientCapabilities()
This method returns null if initialization has not been completed yet.
Use this to check what features the client supports before calling
methods like readTextFile(com.agentclientprotocol.sdk.spec.AcpSchema.ReadTextFileRequest) or createTerminal(com.agentclientprotocol.sdk.spec.AcpSchema.CreateTerminalRequest).
public AcpAsyncAgent async()
public void closeGracefully()
public void close()