Skip to content

Commit a3a6367

Browse files
committed
Document session lifecycle events and foreground session control
1 parent 71f8931 commit a3a6367

1 file changed

Lines changed: 61 additions & 0 deletions

File tree

src/site/markdown/advanced.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,67 @@ client.stop().get(); // Stop manually
312312

313313
---
314314

315+
## Session Lifecycle Events
316+
317+
Subscribe to lifecycle events to be notified when sessions are created, deleted, updated, or change foreground/background state.
318+
319+
### Subscribing to All Lifecycle Events
320+
321+
```java
322+
AutoCloseable subscription = client.onLifecycle(event -> {
323+
System.out.println("Session " + event.getSessionId() + ": " + event.getType());
324+
325+
if (event.getMetadata() != null) {
326+
System.out.println(" Summary: " + event.getMetadata().getSummary());
327+
}
328+
});
329+
330+
// Later, when done listening:
331+
subscription.close();
332+
```
333+
334+
### Subscribing to Specific Event Types
335+
336+
```java
337+
import com.github.copilot.sdk.json.SessionLifecycleEventTypes;
338+
339+
// Listen only for session creation
340+
AutoCloseable subscription = client.onLifecycle(
341+
SessionLifecycleEventTypes.CREATED,
342+
event -> System.out.println("New session: " + event.getSessionId())
343+
);
344+
```
345+
346+
Available event types:
347+
- `SessionLifecycleEventTypes.CREATED` - Session was created
348+
- `SessionLifecycleEventTypes.DELETED` - Session was deleted
349+
- `SessionLifecycleEventTypes.UPDATED` - Session was updated
350+
- `SessionLifecycleEventTypes.FOREGROUND` - Session moved to foreground (TUI+server mode)
351+
- `SessionLifecycleEventTypes.BACKGROUND` - Session moved to background (TUI+server mode)
352+
353+
---
354+
355+
## Foreground Session Control (TUI+Server Mode)
356+
357+
When connecting to a server running in TUI+server mode (`--ui-server`), you can control which session is displayed in the TUI.
358+
359+
### Getting the Foreground Session
360+
361+
```java
362+
String sessionId = client.getForegroundSessionId().get();
363+
if (sessionId != null) {
364+
System.out.println("TUI is displaying session: " + sessionId);
365+
}
366+
```
367+
368+
### Setting the Foreground Session
369+
370+
```java
371+
client.setForegroundSessionId("session-123").get();
372+
```
373+
374+
---
375+
315376
## Error Handling
316377

317378
All SDK methods return `CompletableFuture`. Errors surface via `ExecutionException`:

0 commit comments

Comments
 (0)