Skip to content

Commit ff6fed5

Browse files
Phase C: CopilotClientOptions / MCP / streaming shape changes
- Remove autoStart and autoRestart from CopilotClientOptions. The client now always starts on first createSession/resumeSession; users can still call client.start() explicitly for eager startup. - Make MCPServerConfigBase.tools optional (undefined = all, [] = none). - Fix streaming JSDoc block comment that wasn't attached due to single-star. Mirrors C# PR #1343 Phase 4c. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 6b62308 commit ff6fed5

6 files changed

Lines changed: 17 additions & 39 deletions

File tree

nodejs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ Note: `assistant.message` and `assistant.reasoning` (final events) are always se
415415
### Manual Server Control
416416

417417
```typescript
418-
const client = new CopilotClient({ autoStart: false });
418+
const client = new CopilotClient({ });
419419

420420
// Start manually
421421
await client.start();

nodejs/src/client.ts

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,6 @@ export class CopilotClient {
379379
isChildProcess: options.isChildProcess ?? false,
380380
cliUrl: options.cliUrl,
381381
logLevel: options.logLevel || "debug",
382-
autoStart: options.autoStart ?? true,
383-
autoRestart: false,
384382

385383
env: effectiveEnv,
386384
gitHubToken: options.gitHubToken,
@@ -465,14 +463,14 @@ export class CopilotClient {
465463
* If connecting to an external server (via cliUrl), only establishes the connection.
466464
* Otherwise, spawns the CLI server process and then connects.
467465
*
468-
* This method is called automatically when creating a session if `autoStart` is true (default).
466+
* This method is called automatically the first time you create or resume a session.
469467
*
470468
* @returns A promise that resolves when the connection is established
471469
* @throws Error if the server fails to start or the connection fails
472470
*
473471
* @example
474472
* ```typescript
475-
* const client = new CopilotClient({ autoStart: false });
473+
* const client = new CopilotClient();
476474
* await client.start();
477475
* // Now ready to create sessions
478476
* ```
@@ -707,12 +705,11 @@ export class CopilotClient {
707705
* Creates a new conversation session with the Copilot CLI.
708706
*
709707
* Sessions maintain conversation state, handle events, and manage tool execution.
710-
* If the client is not connected and `autoStart` is enabled, this will automatically
711-
* start the connection.
708+
* If the client is not connected, this method automatically starts the connection.
712709
*
713710
* @param config - Optional configuration for the session
714711
* @returns A promise that resolves with the created session
715-
* @throws Error if the client is not connected and autoStart is disabled
712+
* @throws Error if the client fails to start
716713
*
717714
* @example
718715
* ```typescript
@@ -734,11 +731,7 @@ export class CopilotClient {
734731
*/
735732
async createSession(config: SessionConfig): Promise<CopilotSession> {
736733
if (!this.connection) {
737-
if (this.options.autoStart) {
738-
await this.start();
739-
} else {
740-
throw new Error("Client not connected. Call start() first.");
741-
}
734+
await this.start();
742735
}
743736

744737
const sessionId = config.sessionId ?? randomUUID();
@@ -874,11 +867,7 @@ export class CopilotClient {
874867
*/
875868
async resumeSession(sessionId: string, config: ResumeSessionConfig): Promise<CopilotSession> {
876869
if (!this.connection) {
877-
if (this.options.autoStart) {
878-
await this.start();
879-
} else {
880-
throw new Error("Client not connected. Call start() first.");
881-
}
870+
await this.start();
882871
}
883872

884873
// Create and register the session before issuing the RPC so that

nodejs/src/types.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,6 @@ export interface CopilotClientOptions {
119119
*/
120120
logLevel?: "none" | "error" | "warning" | "info" | "debug" | "all";
121121

122-
/**
123-
* Auto-start the CLI server on first use
124-
* @default true
125-
*/
126-
autoStart?: boolean;
127-
128-
/**
129-
* @deprecated This option has no effect and will be removed in a future release.
130-
*/
131-
autoRestart?: boolean;
132-
133122
/**
134123
* Environment variables to pass to the CLI process. If not set, inherits process.env.
135124
*/
@@ -1145,9 +1134,11 @@ export interface SessionHooks {
11451134
*/
11461135
interface MCPServerConfigBase {
11471136
/**
1148-
* List of tools to include from this server. [] means none. "*" means all.
1137+
* List of tools to include from this server.
1138+
* `undefined` (the default) or `"*"` means include all tools.
1139+
* `[]` means include none.
11491140
*/
1150-
tools: string[];
1141+
tools?: string[];
11511142
/**
11521143
* Indicates the server type: "stdio" for local/subprocess servers, "http"/"sse" for remote servers.
11531144
* If not specified, defaults to "stdio".
@@ -1433,7 +1424,7 @@ export interface SessionConfig {
14331424
*/
14341425
workingDirectory?: string;
14351426

1436-
/*
1427+
/**
14371428
* Enable streaming of assistant message and reasoning chunks.
14381429
* When true, ephemeral assistant.message_delta and assistant.reasoning_delta
14391430
* events are sent as the response is generated. Clients should accumulate

nodejs/test/cjs-compat.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe("Dual ESM/CJS build (#528)", () => {
4343
it("CJS build resolves bundled CLI path", () => {
4444
const script = `
4545
const sdk = require(${JSON.stringify(join(distDir, "cjs/index.js"))});
46-
const client = new sdk.CopilotClient({ autoStart: false });
46+
const client = new sdk.CopilotClient({ });
4747
console.log('CJS CLI resolved: OK');
4848
`;
4949
const output = execFileSync(process.execPath, ["--eval", script], {
@@ -59,7 +59,7 @@ describe("Dual ESM/CJS build (#528)", () => {
5959
const script = `
6060
import { pathToFileURL } from 'node:url';
6161
const sdk = await import(pathToFileURL(${JSON.stringify(esmPath)}).href);
62-
const client = new sdk.CopilotClient({ autoStart: false });
62+
const client = new sdk.CopilotClient({ });
6363
console.log('ESM CLI resolved: OK');
6464
`;
6565
const output = execFileSync(process.execPath, ["--input-type=module", "--eval", script], {

nodejs/test/client.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import { defaultJoinSessionPermissionHandler } from "../src/types.js";
88

99
describe("CopilotClient", () => {
1010
it("allows createSession without onPermissionRequest", async () => {
11-
const client = new CopilotClient({ autoStart: false });
11+
const client = new CopilotClient({ });
1212

1313
await expect(client.createSession({})).rejects.toThrow(/Client not connected/);
1414
});
1515

1616
it("allows resumeSession without onPermissionRequest", async () => {
17-
const client = new CopilotClient({ autoStart: false });
17+
const client = new CopilotClient({ });
1818

1919
await expect(client.resumeSession("session-1", {})).rejects.toThrow(/Client not connected/);
2020
});

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,7 @@ describe("Client options", async () => {
144144
const client = new CopilotClient({
145145
cwd: workDir,
146146
env,
147-
cliPath: process.env.COPILOT_CLI_PATH,
148-
autoStart: false,
147+
cliPath: process.env.COPILOT_CLI_PATH
149148
});
150149
onTestFinished(async () => {
151150
try {
@@ -247,7 +246,6 @@ describe("Client options", async () => {
247246
const client = new CopilotClient({
248247
cwd: workDir,
249248
env: { ...env, COPILOT_HOME: copilotHomeFromEnv },
250-
autoStart: false,
251249
cliPath,
252250
cliArgs: ["--capture-file", capturePath],
253251
copilotHome: copilotHomeFromOption,

0 commit comments

Comments
 (0)