Package com.github.copilot.sdk.json
Class SessionHooks
java.lang.Object
com.github.copilot.sdk.json.SessionHooks
Hook handlers configuration for a session.
Hooks allow you to intercept and modify tool execution behavior. Currently supports pre-tool-use and post-tool-use hooks.
Example Usage
var hooks = new SessionHooks().setOnPreToolUse((input, invocation) -> {
System.out.println("Tool being called: " + input.getToolName());
return CompletableFuture.completedFuture(new PreToolUseHookOutput().setPermissionDecision("allow"));
}).setOnPostToolUse((input, invocation) -> {
System.out.println("Tool result: " + input.getToolResult());
return CompletableFuture.completedFuture(null);
});
var session = client.createSession(new SessionConfig().setHooks(hooks)).get();
- Since:
- 1.0.6
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGets the post-tool-use handler.Gets the pre-tool-use handler.booleanhasHooks()Returns whether any hooks are registered.setOnPostToolUse(PostToolUseHandler onPostToolUse) Sets the handler called after a tool has been executed.setOnPreToolUse(PreToolUseHandler onPreToolUse) Sets the handler called before a tool is executed.
-
Constructor Details
-
SessionHooks
public SessionHooks()
-
-
Method Details
-
getOnPreToolUse
Gets the pre-tool-use handler.- Returns:
- the handler, or
nullif not set
-
setOnPreToolUse
Sets the handler called before a tool is executed.- Parameters:
onPreToolUse- the handler- Returns:
- this instance for method chaining
-
getOnPostToolUse
Gets the post-tool-use handler.- Returns:
- the handler, or
nullif not set
-
setOnPostToolUse
Sets the handler called after a tool has been executed.- Parameters:
onPostToolUse- the handler- Returns:
- this instance for method chaining
-
hasHooks
public boolean hasHooks()Returns whether any hooks are registered.- Returns:
trueif at least one hook handler is set
-