Skip to content

Commit 9d6ef2e

Browse files
authored
Update docs coverage and hooks reference (#141)
1 parent 02a5731 commit 9d6ef2e

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
target
33
examples-test/
44
.merge-env
5+
blog-copilotsdk/

src/site/markdown/documentation.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ This guide covers common use cases for the Copilot SDK for Java. For complete AP
2020
- [Message Delivery Mode](#Message_Delivery_Mode)
2121
- [Session Management](#Session_Management)
2222
- [SessionConfig Reference](#SessionConfig_Reference)
23+
- [Cloning SessionConfig](#Cloning_SessionConfig)
2324

2425
---
2526

@@ -167,6 +168,7 @@ The SDK supports event types organized by category. All events extend `AbstractS
167168
| `SessionUsageInfoEvent` | `session.usage_info` | Token usage information |
168169
| `SessionCompactionStartEvent` | `session.compaction_start` | Context compaction started (infinite sessions) |
169170
| `SessionCompactionCompleteEvent` | `session.compaction_complete` | Context compaction completed |
171+
| `SessionContextChangedEvent` | `session.context_changed` | Working directory context changed |
170172

171173
### Assistant Events
172174

@@ -645,6 +647,21 @@ Complete list of all `SessionConfig` options for `createSession()`:
645647
| `disabledSkills` | List<String> | Skills to disable by name | [Skills](advanced.html#Skills_Configuration) |
646648
| `configDir` | String | Custom configuration directory | [Config Dir](advanced.html#Custom_Configuration_Directory) |
647649

650+
### Cloning SessionConfig
651+
652+
Use `clone()` to copy a base configuration before making per-session changes:
653+
654+
```java
655+
var base = new SessionConfig()
656+
.setModel("gpt-4.1")
657+
.setStreaming(true);
658+
659+
var derived = base.clone()
660+
.setWorkingDirectory("/repo-a");
661+
```
662+
663+
`clone()` creates a shallow copy. Collection fields are copied into new collection instances, while nested objects/handlers are shared references.
664+
648665
See [SessionConfig](apidocs/com/github/copilot/sdk/json/SessionConfig.html) Javadoc for full details.
649666

650667
---

src/site/markdown/hooks.md

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Session hooks allow you to intercept and modify tool execution, user prompts, an
1515
| [User Prompt Submitted](#User_Prompt_Submitted_Hook) | When user sends a message | Nothing (observation only) |
1616
| [Session Start](#Session_Start_Hook) | When session begins | Nothing (observation only) |
1717
| [Session End](#Session_End_Hook) | When session ends | Nothing (observation only) |
18+
| [Checking Whether Hooks Are Registered](#Checking_Whether_Hooks_Are_Registered) | Before session creation | Whether any handlers are configured |
1819

1920
---
2021

@@ -133,7 +134,7 @@ Called **after** a tool executes. Use this to:
133134
|-------|------|-------------|
134135
| `getToolName()` | `String` | Name of the tool that was called |
135136
| `getToolArgs()` | `JsonNode` | Arguments that were passed |
136-
| `getToolResult()` | `String` | Result from the tool |
137+
| `getToolResult()` | `JsonNode` | Result from the tool |
137138
| `getCwd()` | `String` | Current working directory |
138139
| `getTimestamp()` | `long` | Timestamp in milliseconds |
139140

@@ -188,7 +189,7 @@ Called when the user submits a prompt, before the LLM processes it. This is an o
188189

189190
| Field | Type | Description |
190191
|-------|------|-------------|
191-
| `getPrompt()` | `String` | The user's prompt text |
192+
| `prompt()` | `String` | The user's prompt text |
192193
| `getTimestamp()` | `long` | Timestamp in milliseconds |
193194

194195
### Output
@@ -222,7 +223,7 @@ Called when a session starts (either new or resumed).
222223

223224
| Field | Type | Description |
224225
|-------|------|-------------|
225-
| `getSource()` | `String` | `"new"` or `"resumed"` |
226+
| `source()` | `String` | `"startup"`, `"resume"`, or `"new"` |
226227
| `getTimestamp()` | `long` | Timestamp in milliseconds |
227228

228229
### Output
@@ -254,7 +255,7 @@ Called when a session ends.
254255

255256
| Field | Type | Description |
256257
|-------|------|-------------|
257-
| `getReason()` | `String` | Why the session ended |
258+
| `reason()` | `String` | Why the session ended |
258259
| `getTimestamp()` | `long` | Timestamp in milliseconds |
259260

260261
### Output
@@ -358,6 +359,22 @@ All hook handlers receive a `HookInvocation` object as the second parameter:
358359

359360
This allows you to correlate hooks with specific sessions when managing multiple concurrent sessions.
360361

362+
## Checking Whether Hooks Are Registered
363+
364+
Use `hasHooks()` to quickly verify that at least one hook handler is configured:
365+
366+
```java
367+
var hooks = new SessionHooks()
368+
.setOnPreToolUse((input, invocation) ->
369+
CompletableFuture.completedFuture(PreToolUseHookOutput.allow()));
370+
371+
if (hooks.hasHooks()) {
372+
var session = client.createSession(
373+
new SessionConfig().setHooks(hooks)
374+
).get();
375+
}
376+
```
377+
361378
---
362379

363380
## Error Handling

0 commit comments

Comments
 (0)