setForegroundSessionId(String sessionId) {
- return ensureConnected()
- .thenCompose(
- connection -> connection.rpc
- .invoke("session.setForeground", Map.of("sessionId", sessionId),
- com.github.copilot.sdk.json.SetForegroundSessionResponse.class)
- .thenAccept(response -> {
- if (!response.success()) {
- throw new RuntimeException(response.error() != null
- ? response.error()
- : "Failed to set foreground session");
- }
- }));
+ return ensureConnected().thenCompose(connection -> connection.rpc
+ .invoke("session.setForeground", new com.github.copilot.sdk.json.SetForegroundSessionRequest(sessionId),
+ com.github.copilot.sdk.json.SetForegroundSessionResponse.class)
+ .thenAccept(response -> {
+ if (!response.success()) {
+ throw new RuntimeException(
+ response.error() != null ? response.error() : "Failed to set foreground session");
+ }
+ }));
}
/**
diff --git a/src/main/java/com/github/copilot/sdk/json/SetForegroundSessionRequest.java b/src/main/java/com/github/copilot/sdk/json/SetForegroundSessionRequest.java
new file mode 100644
index 000000000..d3944871a
--- /dev/null
+++ b/src/main/java/com/github/copilot/sdk/json/SetForegroundSessionRequest.java
@@ -0,0 +1,20 @@
+/*---------------------------------------------------------------------------------------------
+ * Copyright (c) Microsoft Corporation. All rights reserved.
+ *--------------------------------------------------------------------------------------------*/
+
+package com.github.copilot.sdk.json;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+/**
+ * Request body for session.setForeground RPC call.
+ *
+ * Using an explicit record type (rather than an ad-hoc map) ensures correct
+ * JSON serialization in all execution environments.
+ *
+ * @since 1.0.0
+ */
+public record SetForegroundSessionRequest(
+ /** The session ID to bring to the foreground. */
+ @JsonProperty("sessionId") String sessionId) {
+}
diff --git a/src/test/java/com/github/copilot/sdk/DataObjectCoverageTest.java b/src/test/java/com/github/copilot/sdk/DataObjectCoverageTest.java
index 203f5faed..60849981d 100644
--- a/src/test/java/com/github/copilot/sdk/DataObjectCoverageTest.java
+++ b/src/test/java/com/github/copilot/sdk/DataObjectCoverageTest.java
@@ -18,6 +18,7 @@
import com.github.copilot.sdk.json.PreToolUseHookInput;
import com.github.copilot.sdk.json.PreToolUseHookOutput;
import com.github.copilot.sdk.json.SectionOverride;
+import com.github.copilot.sdk.json.SetForegroundSessionRequest;
import com.github.copilot.sdk.json.SetForegroundSessionResponse;
import com.github.copilot.sdk.json.ToolBinaryResult;
import com.github.copilot.sdk.json.ToolResultObject;
@@ -86,6 +87,14 @@ void getForegroundSessionResponseRecord() {
assertEquals("/home/user/project", response.workspacePath());
}
+ // ===== SetForegroundSessionRequest record =====
+
+ @Test
+ void setForegroundSessionRequestRecord() {
+ var request = new SetForegroundSessionRequest("session-123");
+ assertEquals("session-123", request.sessionId());
+ }
+
// ===== SetForegroundSessionResponse record =====
@Test
diff --git a/src/test/java/com/github/copilot/sdk/E2ETestContext.java b/src/test/java/com/github/copilot/sdk/E2ETestContext.java
index 45fcbc0a5..3d9180bf9 100644
--- a/src/test/java/com/github/copilot/sdk/E2ETestContext.java
+++ b/src/test/java/com/github/copilot/sdk/E2ETestContext.java
@@ -249,6 +249,7 @@ public List