forked from github/copilot-sdk-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSessionHooks.java
More file actions
84 lines (76 loc) · 2.44 KB
/
SessionHooks.java
File metadata and controls
84 lines (76 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
package com.github.copilot.sdk.json;
/**
* Hook handlers configuration for a session.
* <p>
* Hooks allow you to intercept and modify tool execution behavior. Currently
* supports pre-tool-use and post-tool-use hooks.
*
* <h2>Example Usage</h2>
*
* <pre>{@code
* 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();
* }</pre>
*
* @since 1.0.6
*/
public class SessionHooks {
private PreToolUseHandler onPreToolUse;
private PostToolUseHandler onPostToolUse;
/**
* Gets the pre-tool-use handler.
*
* @return the handler, or {@code null} if not set
*/
public PreToolUseHandler getOnPreToolUse() {
return onPreToolUse;
}
/**
* Sets the handler called before a tool is executed.
*
* @param onPreToolUse
* the handler
* @return this instance for method chaining
*/
public SessionHooks setOnPreToolUse(PreToolUseHandler onPreToolUse) {
this.onPreToolUse = onPreToolUse;
return this;
}
/**
* Gets the post-tool-use handler.
*
* @return the handler, or {@code null} if not set
*/
public PostToolUseHandler getOnPostToolUse() {
return onPostToolUse;
}
/**
* Sets the handler called after a tool has been executed.
*
* @param onPostToolUse
* the handler
* @return this instance for method chaining
*/
public SessionHooks setOnPostToolUse(PostToolUseHandler onPostToolUse) {
this.onPostToolUse = onPostToolUse;
return this;
}
/**
* Returns whether any hooks are registered.
*
* @return {@code true} if at least one hook handler is set
*/
public boolean hasHooks() {
return onPreToolUse != null || onPostToolUse != null;
}
}