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

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,
@@ -713,25 +721,26 @@ class CopilotClient {
713
721
  if (this.options.githubToken) {
714
722
  envWithoutNodeDebug.COPILOT_SDK_AUTH_TOKEN = this.options.githubToken;
715
723
  }
724
+ if (!existsSync(this.options.cliPath)) {
725
+ throw new Error(
726
+ `Copilot CLI not found at ${this.options.cliPath}. Ensure @github/copilot is installed.`
727
+ );
728
+ }
729
+ const stdioConfig = this.options.useStdio ? ["pipe", "pipe", "pipe"] : ["ignore", "pipe", "pipe"];
716
730
  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
731
  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];
732
+ this.cliProcess = spawn(process.execPath, [this.options.cliPath, ...args], {
733
+ stdio: stdioConfig,
734
+ cwd: this.options.cwd,
735
+ env: envWithoutNodeDebug
736
+ });
726
737
  } else {
727
- command = this.options.cliPath;
728
- spawnArgs = args;
738
+ this.cliProcess = spawn(this.options.cliPath, args, {
739
+ stdio: stdioConfig,
740
+ cwd: this.options.cwd,
741
+ env: envWithoutNodeDebug
742
+ });
729
743
  }
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
744
  let stdout = "";
736
745
  let resolved = false;
737
746
  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.0",
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/**/*",