|
2 | 2 |
|
3 | 3 |
|
4 | 4 | <!-- |
5 | | - | Generated by Apache Maven Doxia Site Renderer 2.0.0 from target/filtered-site/markdown/advanced.md at 2026-02-04 |
| 5 | + | Generated by Apache Maven Doxia Site Renderer 2.0.0 from target/filtered-site/markdown/advanced.md at 2026-02-05 |
6 | 6 | | Rendered using Apache Maven Fluido Skin 2.1.0 |
7 | 7 | --> |
8 | 8 | <html xmlns="http://www.w3.org/1999/xhtml" lang="en"> |
|
101 | 101 |
|
102 | 102 | <div id="breadcrumbs"> |
103 | 103 | <ul class="breadcrumb"> |
104 | | - <li id="publishDate">Last Published: 2026-02-04<span class="divider">|</span> |
| 104 | + <li id="publishDate">Last Published: 2026-02-05<span class="divider">|</span> |
105 | 105 | </li> |
106 | 106 | <li id="projectVersion">Version: 1.0.7-SNAPSHOT<span class="divider">|</span></li> |
107 | 107 | <li><a href="index.html">Home</a><span class="divider">/</span></li> |
@@ -386,7 +386,54 @@ <h2>Manual Server Control</h2> |
386 | 386 | client.start().get(); // Start manually |
387 | 387 | // ... use client ... |
388 | 388 | client.stop().get(); // Stop manually |
389 | | -</code></pre><hr /></section><section><a id="Error_Handling"></a> |
| 389 | +</code></pre><hr /></section><section><a id="Session_Lifecycle_Events"></a> |
| 390 | +<h2>Session Lifecycle Events</h2> |
| 391 | +<p>Subscribe to lifecycle events to be notified when sessions are created, deleted, updated, or change foreground/background state.</p><section><a id="Subscribing_to_All_Lifecycle_Events"></a> |
| 392 | +<h3>Subscribing to All Lifecycle Events</h3> |
| 393 | + |
| 394 | +<pre class="prettyprint"><code class="language-java">AutoCloseable subscription = client.onLifecycle(event -> { |
| 395 | + System.out.println("Session " + event.getSessionId() + ": " + event.getType()); |
| 396 | + |
| 397 | + if (event.getMetadata() != null) { |
| 398 | + System.out.println(" Summary: " + event.getMetadata().getSummary()); |
| 399 | + } |
| 400 | +}); |
| 401 | + |
| 402 | +// Later, when done listening: |
| 403 | +subscription.close(); |
| 404 | +</code></pre></section><section><a id="Subscribing_to_Specific_Event_Types"></a> |
| 405 | +<h3>Subscribing to Specific Event Types</h3> |
| 406 | + |
| 407 | +<pre class="prettyprint"><code class="language-java">import com.github.copilot.sdk.json.SessionLifecycleEventTypes; |
| 408 | + |
| 409 | +// Listen only for session creation |
| 410 | +AutoCloseable subscription = client.onLifecycle( |
| 411 | + SessionLifecycleEventTypes.CREATED, |
| 412 | + event -> System.out.println("New session: " + event.getSessionId()) |
| 413 | +); |
| 414 | +</code></pre> |
| 415 | +<p>Available event types:</p> |
| 416 | +<ul> |
| 417 | + |
| 418 | +<li><code>SessionLifecycleEventTypes.CREATED</code> - Session was created</li> |
| 419 | +<li><code>SessionLifecycleEventTypes.DELETED</code> - Session was deleted</li> |
| 420 | +<li><code>SessionLifecycleEventTypes.UPDATED</code> - Session was updated</li> |
| 421 | +<li><code>SessionLifecycleEventTypes.FOREGROUND</code> - Session moved to foreground (TUI+server mode)</li> |
| 422 | +<li><code>SessionLifecycleEventTypes.BACKGROUND</code> - Session moved to background (TUI+server mode)</li> |
| 423 | +</ul><hr /></section></section><section><a id="Foreground_Session_Control_.28TUI.2BServer_Mode.29"></a> |
| 424 | +<h2>Foreground Session Control (TUI+Server Mode)</h2> |
| 425 | +<p>When connecting to a server running in TUI+server mode (<code>--ui-server</code>), you can control which session is displayed in the TUI.</p><section><a id="Getting_the_Foreground_Session"></a> |
| 426 | +<h3>Getting the Foreground Session</h3> |
| 427 | + |
| 428 | +<pre class="prettyprint"><code class="language-java">String sessionId = client.getForegroundSessionId().get(); |
| 429 | +if (sessionId != null) { |
| 430 | + System.out.println("TUI is displaying session: " + sessionId); |
| 431 | +} |
| 432 | +</code></pre></section><section><a id="Setting_the_Foreground_Session"></a> |
| 433 | +<h3>Setting the Foreground Session</h3> |
| 434 | + |
| 435 | +<pre class="prettyprint"><code class="language-java">client.setForegroundSessionId("session-123").get(); |
| 436 | +</code></pre><hr /></section></section><section><a id="Error_Handling"></a> |
390 | 437 | <h2>Error Handling</h2> |
391 | 438 | <p>All SDK methods return <code>CompletableFuture</code>. Errors surface via <code>ExecutionException</code>:</p> |
392 | 439 |
|
|
0 commit comments