public interface SyncPromptContext
This is the synchronous equivalent of PromptContext, providing blocking
methods for use with AcpAgent.SyncPromptHandler.
Example usage:
AcpAgent.sync(transport)
.promptHandler((request, context) -> {
// Send an update (blocks until sent)
context.sendUpdate(sessionId, update);
// Read a file (blocks until complete)
var content = context.readTextFile(new ReadTextFileRequest(...));
// Request permission (blocks until user responds)
var permission = context.requestPermission(new RequestPermissionRequest(...));
return new PromptResponse(StopReason.END_TURN);
})
.build();
PromptContext,
AcpAgent.SyncPromptHandler| 限定符和类型 | 方法和说明 |
|---|---|
java.lang.String |
askChoice(java.lang.String question,
java.lang.String... options)
Asks the client to choose from multiple options.
|
boolean |
askPermission(java.lang.String action)
Asks the client for permission to perform an action.
|
AcpSchema.CreateTerminalResponse |
createTerminal(AcpSchema.CreateTerminalRequest request)
Requests the client to create a terminal.
|
CommandResult |
execute(Command command)
Executes a command with options and waits for completion.
|
CommandResult |
execute(java.lang.String... commandAndArgs)
Executes a command in a terminal and waits for completion.
|
NegotiatedCapabilities |
getClientCapabilities()
Returns the capabilities negotiated with the client during initialization.
|
java.lang.String |
getSessionId()
Returns the session ID for this prompt invocation.
|
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.
|
java.lang.String |
readFile(java.lang.String path)
Reads a text file from the client's file system.
|
java.lang.String |
readFile(java.lang.String path,
java.lang.Integer startLine,
java.lang.Integer lineCount)
Reads a portion of a text file from the client's file system.
|
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 |
sendMessage(java.lang.String text)
Sends a message to the client as an agent message chunk.
|
void |
sendThought(java.lang.String text)
Sends a thought to the client as an agent thought chunk.
|
void |
sendUpdate(java.lang.String sessionId,
AcpSchema.SessionUpdate update)
Sends a session update notification to the client.
|
java.util.Optional<java.lang.String> |
tryReadFile(java.lang.String path)
Attempts to read a text file, returning empty if the file cannot be read
or the client doesn't support file reading.
|
AcpSchema.WaitForTerminalExitResponse |
waitForTerminalExit(AcpSchema.WaitForTerminalExitRequest request)
Waits for a terminal to exit.
|
void |
writeFile(java.lang.String path,
java.lang.String content)
Writes content to a text file on the client's file system.
|
AcpSchema.WriteTextFileResponse |
writeTextFile(AcpSchema.WriteTextFileRequest request)
Requests the client to write a text file.
|
void sendUpdate(java.lang.String sessionId,
AcpSchema.SessionUpdate update)
sessionId - The session IDupdate - The session update to sendAcpSchema.ReadTextFileResponse readTextFile(AcpSchema.ReadTextFileRequest request)
request - The read file requestAcpCapabilityException - if client doesn't support file readingAcpSchema.WriteTextFileResponse writeTextFile(AcpSchema.WriteTextFileRequest request)
request - The write file requestAcpCapabilityException - if client doesn't support file writingAcpSchema.RequestPermissionResponse requestPermission(AcpSchema.RequestPermissionRequest request)
request - The permission requestAcpSchema.CreateTerminalResponse createTerminal(AcpSchema.CreateTerminalRequest request)
request - The create terminal requestAcpCapabilityException - if client doesn't support terminalsAcpSchema.TerminalOutputResponse getTerminalOutput(AcpSchema.TerminalOutputRequest request)
request - The terminal output requestAcpSchema.ReleaseTerminalResponse releaseTerminal(AcpSchema.ReleaseTerminalRequest request)
request - The release terminal requestAcpSchema.WaitForTerminalExitResponse waitForTerminalExit(AcpSchema.WaitForTerminalExitRequest request)
request - The wait for exit requestAcpSchema.KillTerminalCommandResponse killTerminal(AcpSchema.KillTerminalCommandRequest request)
request - The kill terminal requestNegotiatedCapabilities getClientCapabilities()
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).
java.lang.String getSessionId()
void sendMessage(java.lang.String text)
text - The message text to sendvoid sendThought(java.lang.String text)
text - The thought text to sendjava.lang.String readFile(java.lang.String path)
path - The path to the fileAcpCapabilityException - if client doesn't support file readingjava.lang.String readFile(java.lang.String path,
java.lang.Integer startLine,
java.lang.Integer lineCount)
path - The path to the filestartLine - The line number to start reading from (0-indexed, null for beginning)lineCount - The number of lines to read (null for all remaining)AcpCapabilityException - if client doesn't support file readingjava.util.Optional<java.lang.String> tryReadFile(java.lang.String path)
path - The path to the filevoid writeFile(java.lang.String path,
java.lang.String content)
path - The path to the filecontent - The content to writeAcpCapabilityException - if client doesn't support file writingboolean askPermission(java.lang.String action)
action - A description of the action to request permission forjava.lang.String askChoice(java.lang.String question,
java.lang.String... options)
question - The question to askoptions - The available options (at least 2)CommandResult execute(java.lang.String... commandAndArgs)
commandAndArgs - The command and arguments to executeAcpCapabilityException - if client doesn't support terminalsCommandResult execute(Command command)
command - The command configurationAcpCapabilityException - if client doesn't support terminals