|
11 | 11 | /** |
12 | 12 | * Output for a pre-tool-use hook. |
13 | 13 | * |
| 14 | + * @param permissionDecision |
| 15 | + * "allow", "deny", or "ask" |
| 16 | + * @param permissionDecisionReason |
| 17 | + * the reason for the permission decision |
| 18 | + * @param modifiedArgs |
| 19 | + * the modified tool arguments, or {@code null} to use original |
| 20 | + * @param additionalContext |
| 21 | + * additional context to provide to the model |
| 22 | + * @param suppressOutput |
| 23 | + * {@code true} to suppress output |
14 | 24 | * @since 1.0.6 |
15 | 25 | */ |
16 | 26 | @JsonInclude(JsonInclude.Include.NON_NULL) |
17 | | -public class PreToolUseHookOutput { |
18 | | - |
19 | | - @JsonProperty("permissionDecision") |
20 | | - private String permissionDecision; |
21 | | - |
22 | | - @JsonProperty("permissionDecisionReason") |
23 | | - private String permissionDecisionReason; |
24 | | - |
25 | | - @JsonProperty("modifiedArgs") |
26 | | - private JsonNode modifiedArgs; |
27 | | - |
28 | | - @JsonProperty("additionalContext") |
29 | | - private String additionalContext; |
30 | | - |
31 | | - @JsonProperty("suppressOutput") |
32 | | - private Boolean suppressOutput; |
| 27 | +public record PreToolUseHookOutput(@JsonProperty("permissionDecision") String permissionDecision, |
| 28 | + @JsonProperty("permissionDecisionReason") String permissionDecisionReason, |
| 29 | + @JsonProperty("modifiedArgs") JsonNode modifiedArgs, |
| 30 | + @JsonProperty("additionalContext") String additionalContext, |
| 31 | + @JsonProperty("suppressOutput") Boolean suppressOutput) { |
33 | 32 |
|
34 | 33 | /** |
35 | | - * Gets the permission decision. |
| 34 | + * Creates an output that allows the tool to execute. |
36 | 35 | * |
37 | | - * @return "allow", "deny", or "ask" |
| 36 | + * @return a new PreToolUseHookOutput with permission decision "allow" |
38 | 37 | */ |
39 | | - public String getPermissionDecision() { |
40 | | - return permissionDecision; |
| 38 | + public static PreToolUseHookOutput allow() { |
| 39 | + return new PreToolUseHookOutput("allow", null, null, null, null); |
41 | 40 | } |
42 | 41 |
|
43 | 42 | /** |
44 | | - * Sets the permission decision. |
| 43 | + * Creates an output that denies the tool execution. |
45 | 44 | * |
46 | | - * @param permissionDecision |
47 | | - * "allow", "deny", or "ask" |
48 | | - * @return this instance for method chaining |
| 45 | + * @return a new PreToolUseHookOutput with permission decision "deny" |
49 | 46 | */ |
50 | | - public PreToolUseHookOutput setPermissionDecision(String permissionDecision) { |
51 | | - this.permissionDecision = permissionDecision; |
52 | | - return this; |
| 47 | + public static PreToolUseHookOutput deny() { |
| 48 | + return new PreToolUseHookOutput("deny", null, null, null, null); |
53 | 49 | } |
54 | 50 |
|
55 | 51 | /** |
56 | | - * Gets the reason for the permission decision. |
| 52 | + * Creates an output that denies the tool execution with a reason. |
57 | 53 | * |
58 | | - * @return the reason text |
| 54 | + * @param reason |
| 55 | + * the reason for denying the tool execution |
| 56 | + * @return a new PreToolUseHookOutput with permission decision "deny" and reason |
59 | 57 | */ |
60 | | - public String getPermissionDecisionReason() { |
61 | | - return permissionDecisionReason; |
| 58 | + public static PreToolUseHookOutput deny(String reason) { |
| 59 | + return new PreToolUseHookOutput("deny", reason, null, null, null); |
62 | 60 | } |
63 | 61 |
|
64 | 62 | /** |
65 | | - * Sets the reason for the permission decision. |
| 63 | + * Creates an output that asks for user confirmation before executing the tool. |
66 | 64 | * |
67 | | - * @param permissionDecisionReason |
68 | | - * the reason text |
69 | | - * @return this instance for method chaining |
| 65 | + * @return a new PreToolUseHookOutput with permission decision "ask" |
70 | 66 | */ |
71 | | - public PreToolUseHookOutput setPermissionDecisionReason(String permissionDecisionReason) { |
72 | | - this.permissionDecisionReason = permissionDecisionReason; |
73 | | - return this; |
| 67 | + public static PreToolUseHookOutput ask() { |
| 68 | + return new PreToolUseHookOutput("ask", null, null, null, null); |
74 | 69 | } |
75 | 70 |
|
76 | 71 | /** |
77 | | - * Gets the modified tool arguments. |
78 | | - * |
79 | | - * @return the modified arguments, or {@code null} to use original |
80 | | - */ |
81 | | - public JsonNode getModifiedArgs() { |
82 | | - return modifiedArgs; |
83 | | - } |
84 | | - |
85 | | - /** |
86 | | - * Sets the modified tool arguments. |
| 72 | + * Creates an output with modified tool arguments. |
87 | 73 | * |
| 74 | + * @param permissionDecision |
| 75 | + * "allow", "deny", or "ask" |
88 | 76 | * @param modifiedArgs |
89 | | - * the modified arguments |
90 | | - * @return this instance for method chaining |
91 | | - */ |
92 | | - public PreToolUseHookOutput setModifiedArgs(JsonNode modifiedArgs) { |
93 | | - this.modifiedArgs = modifiedArgs; |
94 | | - return this; |
95 | | - } |
96 | | - |
97 | | - /** |
98 | | - * Gets additional context to provide to the model. |
99 | | - * |
100 | | - * @return the additional context |
101 | | - */ |
102 | | - public String getAdditionalContext() { |
103 | | - return additionalContext; |
104 | | - } |
105 | | - |
106 | | - /** |
107 | | - * Sets additional context to provide to the model. |
108 | | - * |
109 | | - * @param additionalContext |
110 | | - * the additional context |
111 | | - * @return this instance for method chaining |
112 | | - */ |
113 | | - public PreToolUseHookOutput setAdditionalContext(String additionalContext) { |
114 | | - this.additionalContext = additionalContext; |
115 | | - return this; |
116 | | - } |
117 | | - |
118 | | - /** |
119 | | - * Returns whether to suppress output. |
120 | | - * |
121 | | - * @return {@code true} to suppress output |
122 | | - */ |
123 | | - public Boolean getSuppressOutput() { |
124 | | - return suppressOutput; |
125 | | - } |
126 | | - |
127 | | - /** |
128 | | - * Sets whether to suppress output. |
129 | | - * |
130 | | - * @param suppressOutput |
131 | | - * {@code true} to suppress output |
132 | | - * @return this instance for method chaining |
| 77 | + * the modified tool arguments |
| 78 | + * @return a new PreToolUseHookOutput with the specified permission and modified |
| 79 | + * arguments |
133 | 80 | */ |
134 | | - public PreToolUseHookOutput setSuppressOutput(Boolean suppressOutput) { |
135 | | - this.suppressOutput = suppressOutput; |
136 | | - return this; |
| 81 | + public static PreToolUseHookOutput withModifiedArgs(String permissionDecision, JsonNode modifiedArgs) { |
| 82 | + return new PreToolUseHookOutput(permissionDecision, null, modifiedArgs, null, null); |
137 | 83 | } |
138 | 84 | } |
0 commit comments