Skip to content

Commit 2a77f12

Browse files
TypeScript: remove getState() and public ConnectionState
.NET removed `CopilotClient.State` and `ConnectionState` in commit b00fd8c (Phase 4d/4e). Python matched this in PR #1376. TypeScript was the last SDK still exposing both — drop them for cross-SDK consistency. - `CopilotClient.getState(): ConnectionState` removed. - Public `ConnectionState` type alias removed from `types.ts` and the index re-exports. - The private `state` field on `CopilotClient` stays (still used by start/stop to gate behavior); its type is now an inline union declaration instead of the exported alias. - Unit test for unexpected child-process death now reads the private `state` field via `(client as any).state` since the behaviour being tested (state transition on async disconnect) is genuinely internal. - E2E `client.getState() === "..."` assertions are dropped — they were pure tautologies once `start()` returned without throwing. - `nodejs/README.md` no longer documents `getState()`. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent f3321b2 commit 2a77f12

7 files changed

Lines changed: 3 additions & 39 deletions

File tree

nodejs/README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,6 @@ Resume an existing session. Returns the session with `workspacePath` populated i
131131

132132
Ping the server to check connectivity.
133133

134-
##### `getState(): ConnectionState`
135-
136-
Get current connection state.
137-
138134
##### `listSessions(filter?: SessionListFilter): Promise<SessionMetadata[]>`
139135

140136
List all available sessions. Optionally filter by working directory context.

nodejs/src/client.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import { getTraceContext } from "./telemetry.js";
3838
import type {
3939
AutoModeSwitchRequest,
4040
AutoModeSwitchResponse,
41-
ConnectionState,
4241
CopilotClientOptions,
4342
CustomAgentConfig,
4443
ExitPlanModeRequest,
@@ -251,7 +250,7 @@ export class CopilotClient {
251250
private socket: Socket | null = null;
252251
private runtimePort: number | null = null;
253252
private actualHost: string = "localhost";
254-
private state: ConnectionState = "disconnected";
253+
private state: "disconnected" | "connecting" | "connected" | "error" = "disconnected";
255254
private sessions: Map<string, CopilotSession> = new Map();
256255
private stderrBuffer: string = ""; // Captures CLI stderr for error messages
257256
/** Resolved connection mode chosen in the constructor. */
@@ -1039,22 +1038,6 @@ export class CopilotClient {
10391038
return session;
10401039
}
10411040

1042-
/**
1043-
* Gets the current connection state of the client.
1044-
*
1045-
* @returns The current connection state: "disconnected", "connecting", "connected", or "error"
1046-
*
1047-
* @example
1048-
* ```typescript
1049-
* if (client.getState() === "connected") {
1050-
* const session = await client.createSession({ onPermissionRequest: approveAll });
1051-
* }
1052-
* ```
1053-
*/
1054-
getState(): ConnectionState {
1055-
return this.state;
1056-
}
1057-
10581041
/**
10591042
* Sends a ping request to the server to verify connectivity.
10601043
*

nodejs/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ export type {
4040
AutoModeSwitchHandler,
4141
AutoModeSwitchRequest,
4242
AutoModeSwitchResponse,
43-
ConnectionState,
4443
CopilotClientOptions,
4544
StdioRuntimeConnection,
4645
TcpRuntimeConnection,

nodejs/src/types.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1842,11 +1842,6 @@ export type TypedSessionEventHandler<T extends SessionEventType> = (
18421842
*/
18431843
export type SessionEventHandler = (event: SessionEvent) => void;
18441844

1845-
/**
1846-
* Connection state
1847-
*/
1848-
export type ConnectionState = "disconnected" | "connecting" | "connected" | "error";
1849-
18501845
/**
18511846
* Working directory context for a session
18521847
*/

nodejs/test/client.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -984,15 +984,15 @@ describe("CopilotClient", () => {
984984
await client.start();
985985
onTestFinished(() => client.forceStop());
986986

987-
expect(client.getState()).toBe("connected");
987+
expect((client as any).state).toBe("connected");
988988

989989
// Kill the child process to simulate unexpected termination
990990
const proc = (client as any).cliProcess as import("node:child_process").ChildProcess;
991991
proc.kill();
992992

993993
// Wait for the connection.onClose handler to fire
994994
await vi.waitFor(() => {
995-
expect(client.getState()).toBe("disconnected");
995+
expect((client as any).state).toBe("disconnected");
996996
});
997997
});
998998
});

nodejs/test/e2e/client.e2e.test.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,29 +56,25 @@ describe("Client", () => {
5656
onTestFinishedForceStop(client);
5757

5858
await client.start();
59-
expect(client.getState()).toBe("connected");
6059

6160
const pong = await client.ping("test message");
6261
expect(pong.message).toBe("pong: test message");
6362
expect(Date.parse(pong.timestamp)).not.toBeNaN();
6463

6564
expect(await client.stop()).toHaveLength(0); // No errors on stop
66-
expect(client.getState()).toBe("disconnected");
6765
});
6866

6967
it("should start and connect to server using tcp", async () => {
7068
const client = new CopilotClient({ connection: RuntimeConnection.forTcp() });
7169
onTestFinishedForceStop(client);
7270

7371
await client.start();
74-
expect(client.getState()).toBe("connected");
7572

7673
const pong = await client.ping("test message");
7774
expect(pong.message).toBe("pong: test message");
7875
expect(Date.parse(pong.timestamp)).not.toBeNaN();
7976

8077
expect(await client.stop()).toHaveLength(0); // No errors on stop
81-
expect(client.getState()).toBe("disconnected");
8278
});
8379

8480
it.skipIf(process.platform === "darwin")(
@@ -101,7 +97,6 @@ describe("Client", () => {
10197
await new Promise((resolve) => setTimeout(resolve, 100));
10298

10399
const errors = await client.stop();
104-
expect(client.getState()).toBe("disconnected");
105100
if (errors.length > 0) {
106101
expect(errors[0].message).toContain("Failed to disconnect session");
107102
}
@@ -117,7 +112,6 @@ describe("Client", () => {
117112

118113
await client.createSession({ onPermissionRequest: approveAll });
119114
await client.forceStop();
120-
expect(client.getState()).toBe("disconnected");
121115
});
122116

123117
it("should get status with version and protocol info", async () => {

nodejs/test/e2e/client_options.e2e.test.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,8 @@ describe("Client options", async () => {
154154
}
155155
});
156156

157-
expect(client.getState()).toBe("disconnected");
158157

159158
const session = await client.createSession({ onPermissionRequest: approveAll });
160-
expect(client.getState()).toBe("connected");
161159
expect(session.sessionId).toMatch(/^[a-f0-9-]+$/);
162160

163161
await session.disconnect();
@@ -183,7 +181,6 @@ describe("Client options", async () => {
183181

184182
await client.start();
185183

186-
expect(client.getState()).toBe("connected");
187184
expect((client as unknown as { runtimePort: number }).runtimePort).toBe(port);
188185

189186
const response = await client.ping("fixed-port");

0 commit comments

Comments
 (0)