|
30 | 30 | import com.github.copilot.sdk.json.ResumeSessionResponse; |
31 | 31 | import com.github.copilot.sdk.json.SessionConfig; |
32 | 32 | import com.github.copilot.sdk.json.SessionLifecycleHandler; |
| 33 | +import com.github.copilot.sdk.json.SessionListFilter; |
33 | 34 | import com.github.copilot.sdk.json.SessionMetadata; |
34 | 35 |
|
35 | 36 | /** |
@@ -474,9 +475,41 @@ public CompletableFuture<Void> deleteSession(String sessionId) { |
474 | 475 | * @see #resumeSession(String) |
475 | 476 | */ |
476 | 477 | public CompletableFuture<List<SessionMetadata>> listSessions() { |
477 | | - return ensureConnected() |
478 | | - .thenCompose(connection -> connection.rpc.invoke("session.list", Map.of(), ListSessionsResponse.class) |
479 | | - .thenApply(ListSessionsResponse::sessions)); |
| 478 | + return listSessions(null); |
| 479 | + } |
| 480 | + |
| 481 | + /** |
| 482 | + * Lists all available sessions with optional filtering. |
| 483 | + * <p> |
| 484 | + * Returns metadata about all sessions that can be resumed, including their IDs, |
| 485 | + * start times, summaries, and context information. Use the filter parameter to |
| 486 | + * narrow down sessions by working directory, git repository, or branch. |
| 487 | + * |
| 488 | + * <h2>Example Usage</h2> |
| 489 | + * |
| 490 | + * <pre>{@code |
| 491 | + * // List all sessions |
| 492 | + * var allSessions = client.listSessions().get(); |
| 493 | + * |
| 494 | + * // Filter by repository |
| 495 | + * var filter = new SessionListFilter().setRepository("owner/repo"); |
| 496 | + * var repoSessions = client.listSessions(filter).get(); |
| 497 | + * }</pre> |
| 498 | + * |
| 499 | + * @param filter |
| 500 | + * optional filter to narrow down sessions by context fields, or |
| 501 | + * {@code null} to list all sessions |
| 502 | + * @return a future that resolves with a list of session metadata |
| 503 | + * @see SessionMetadata |
| 504 | + * @see SessionListFilter |
| 505 | + * @see #resumeSession(String) |
| 506 | + */ |
| 507 | + public CompletableFuture<List<SessionMetadata>> listSessions(SessionListFilter filter) { |
| 508 | + return ensureConnected().thenCompose(connection -> { |
| 509 | + Map<String, Object> params = filter != null ? Map.of("filter", filter) : Map.of(); |
| 510 | + return connection.rpc.invoke("session.list", params, ListSessionsResponse.class) |
| 511 | + .thenApply(ListSessionsResponse::sessions); |
| 512 | + }); |
480 | 513 | } |
481 | 514 |
|
482 | 515 | /** |
|
0 commit comments