@github/copilot-sdk 0.1.22 → 0.1.23-preview.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/client.d.ts CHANGED
@@ -1,38 +1,5 @@
1
1
  import { CopilotSession } from "./session.js";
2
2
  import type { ConnectionState, CopilotClientOptions, GetAuthStatusResponse, GetStatusResponse, ModelInfo, ResumeSessionConfig, SessionConfig, SessionLifecycleEventType, SessionLifecycleHandler, SessionMetadata, TypedSessionLifecycleHandler } from "./types.js";
3
- /**
4
- * Main client for interacting with the Copilot CLI.
5
- *
6
- * The CopilotClient manages the connection to the Copilot CLI server and provides
7
- * methods to create and manage conversation sessions. It can either spawn a CLI
8
- * server process or connect to an existing server.
9
- *
10
- * @example
11
- * ```typescript
12
- * import { CopilotClient } from "@github/copilot-sdk";
13
- *
14
- * // Create a client with default options (spawns CLI server)
15
- * const client = new CopilotClient();
16
- *
17
- * // Or connect to an existing server
18
- * const client = new CopilotClient({ cliUrl: "localhost:3000" });
19
- *
20
- * // Create a session
21
- * const session = await client.createSession({ model: "gpt-4" });
22
- *
23
- * // Send messages and handle responses
24
- * session.on((event) => {
25
- * if (event.type === "assistant.message") {
26
- * console.log(event.data.content);
27
- * }
28
- * });
29
- * await session.send({ prompt: "Hello!" });
30
- *
31
- * // Clean up
32
- * await session.destroy();
33
- * await client.stop();
34
- * ```
35
- */
36
3
  export declare class CopilotClient {
37
4
  private cliProcess;
38
5
  private connection;
package/dist/client.js CHANGED
@@ -1,5 +1,8 @@
1
1
  import { spawn } from "node:child_process";
2
+ import { existsSync } from "node:fs";
2
3
  import { Socket } from "node:net";
4
+ import { dirname, join } from "node:path";
5
+ import { fileURLToPath } from "node:url";
3
6
  import {
4
7
  createMessageConnection,
5
8
  StreamMessageReader,
@@ -17,6 +20,11 @@ function toJsonSchema(parameters) {
17
20
  }
18
21
  return parameters;
19
22
  }
23
+ function getBundledCliPath() {
24
+ const sdkUrl = import.meta.resolve("@github/copilot/sdk");
25
+ const sdkPath = fileURLToPath(sdkUrl);
26
+ return join(dirname(dirname(sdkPath)), "index.js");
27
+ }
20
28
  class CopilotClient {
21
29
  cliProcess = null;
22
30
  connection = null;
@@ -69,7 +77,7 @@ class CopilotClient {
69
77
  this.isExternalServer = true;
70
78
  }
71
79
  this.options = {
72
- cliPath: options.cliPath || "copilot",
80
+ cliPath: options.cliPath || getBundledCliPath(),
73
81
  cliArgs: options.cliArgs ?? [],
74
82
  cwd: options.cwd ?? process.cwd(),
75
83
  port: options.port || 0,
@@ -694,6 +702,7 @@ class CopilotClient {
694
702
  const args = [
695
703
  ...this.options.cliArgs,
696
704
  "--headless",
705
+ "--no-auto-update",
697
706
  "--log-level",
698
707
  this.options.logLevel
699
708
  ];
@@ -713,25 +722,26 @@ class CopilotClient {
713
722
  if (this.options.githubToken) {
714
723
  envWithoutNodeDebug.COPILOT_SDK_AUTH_TOKEN = this.options.githubToken;
715
724
  }
725
+ if (!existsSync(this.options.cliPath)) {
726
+ throw new Error(
727
+ `Copilot CLI not found at ${this.options.cliPath}. Ensure @github/copilot is installed.`
728
+ );
729
+ }
730
+ const stdioConfig = this.options.useStdio ? ["pipe", "pipe", "pipe"] : ["ignore", "pipe", "pipe"];
716
731
  const isJsFile = this.options.cliPath.endsWith(".js");
717
- const isAbsolutePath = this.options.cliPath.startsWith("/") || /^[a-zA-Z]:/.test(this.options.cliPath);
718
- let command;
719
- let spawnArgs;
720
732
  if (isJsFile) {
721
- command = "node";
722
- spawnArgs = [this.options.cliPath, ...args];
723
- } else if (process.platform === "win32" && !isAbsolutePath) {
724
- command = "cmd";
725
- spawnArgs = ["/c", `${this.options.cliPath}`, ...args];
733
+ this.cliProcess = spawn(process.execPath, [this.options.cliPath, ...args], {
734
+ stdio: stdioConfig,
735
+ cwd: this.options.cwd,
736
+ env: envWithoutNodeDebug
737
+ });
726
738
  } else {
727
- command = this.options.cliPath;
728
- spawnArgs = args;
739
+ this.cliProcess = spawn(this.options.cliPath, args, {
740
+ stdio: stdioConfig,
741
+ cwd: this.options.cwd,
742
+ env: envWithoutNodeDebug
743
+ });
729
744
  }
730
- this.cliProcess = spawn(command, spawnArgs, {
731
- stdio: this.options.useStdio ? ["pipe", "pipe", "pipe"] : ["ignore", "pipe", "pipe"],
732
- cwd: this.options.cwd,
733
- env: envWithoutNodeDebug
734
- });
735
745
  let stdout = "";
736
746
  let resolved = false;
737
747
  if (this.options.useStdio) {
package/dist/types.d.ts CHANGED
@@ -8,8 +8,8 @@ export type SessionEvent = GeneratedSessionEvent;
8
8
  */
9
9
  export interface CopilotClientOptions {
10
10
  /**
11
- * Path to the Copilot CLI executable
12
- * @default "copilot" (searches PATH)
11
+ * Path to the CLI executable or JavaScript entry point.
12
+ * If not specified, uses the bundled CLI from the @github/copilot package.
13
13
  */
14
14
  cliPath?: string;
15
15
  /**
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "type": "git",
5
5
  "url": "https://github.com/github/copilot-sdk.git"
6
6
  },
7
- "version": "0.1.22",
7
+ "version": "0.1.23-preview.1",
8
8
  "description": "TypeScript SDK for programmatic control of GitHub Copilot CLI via JSON-RPC",
9
9
  "main": "./dist/index.js",
10
10
  "types": "./dist/index.d.ts",
@@ -62,7 +62,7 @@
62
62
  "vitest": "^4.0.18"
63
63
  },
64
64
  "engines": {
65
- "node": ">=18.0.0"
65
+ "node": ">=24.0.0"
66
66
  },
67
67
  "files": [
68
68
  "dist/**/*",