🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@github/copilot-sdk

Package Overview
Dependencies
Maintainers
22
Versions
72
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@github/copilot-sdk - npm Package Compare versions

Comparing version
0.1.22
to
0.1.23-preview.0
+0
-33
dist/client.d.ts
import { CopilotSession } from "./session.js";
import type { ConnectionState, CopilotClientOptions, GetAuthStatusResponse, GetStatusResponse, ModelInfo, ResumeSessionConfig, SessionConfig, SessionLifecycleEventType, SessionLifecycleHandler, SessionMetadata, TypedSessionLifecycleHandler } from "./types.js";
/**
* Main client for interacting with the Copilot CLI.
*
* The CopilotClient manages the connection to the Copilot CLI server and provides
* methods to create and manage conversation sessions. It can either spawn a CLI
* server process or connect to an existing server.
*
* @example
* ```typescript
* import { CopilotClient } from "@github/copilot-sdk";
*
* // Create a client with default options (spawns CLI server)
* const client = new CopilotClient();
*
* // Or connect to an existing server
* const client = new CopilotClient({ cliUrl: "localhost:3000" });
*
* // Create a session
* const session = await client.createSession({ model: "gpt-4" });
*
* // Send messages and handle responses
* session.on((event) => {
* if (event.type === "assistant.message") {
* console.log(event.data.content);
* }
* });
* await session.send({ prompt: "Hello!" });
*
* // Clean up
* await session.destroy();
* await client.stop();
* ```
*/
export declare class CopilotClient {

@@ -37,0 +4,0 @@ private cliProcess;

+25
-16
import { spawn } from "node:child_process";
import { existsSync } from "node:fs";
import { Socket } from "node:net";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
import {

@@ -20,2 +23,7 @@ createMessageConnection,

}
function getBundledCliPath() {
const sdkUrl = import.meta.resolve("@github/copilot/sdk");
const sdkPath = fileURLToPath(sdkUrl);
return join(dirname(dirname(sdkPath)), "index.js");
}
class CopilotClient {

@@ -73,3 +81,3 @@ cliProcess = null;

this.options = {
cliPath: options.cliPath || "copilot",
cliPath: options.cliPath || getBundledCliPath(),
cliArgs: options.cliArgs ?? [],

@@ -718,21 +726,22 @@ cwd: options.cwd ?? process.cwd(),

}
if (!existsSync(this.options.cliPath)) {
throw new Error(
`Copilot CLI not found at ${this.options.cliPath}. Ensure @github/copilot is installed.`
);
}
const stdioConfig = this.options.useStdio ? ["pipe", "pipe", "pipe"] : ["ignore", "pipe", "pipe"];
const isJsFile = this.options.cliPath.endsWith(".js");
const isAbsolutePath = this.options.cliPath.startsWith("/") || /^[a-zA-Z]:/.test(this.options.cliPath);
let command;
let spawnArgs;
if (isJsFile) {
command = "node";
spawnArgs = [this.options.cliPath, ...args];
} else if (process.platform === "win32" && !isAbsolutePath) {
command = "cmd";
spawnArgs = ["/c", `${this.options.cliPath}`, ...args];
this.cliProcess = spawn(process.execPath, [this.options.cliPath, ...args], {
stdio: stdioConfig,
cwd: this.options.cwd,
env: envWithoutNodeDebug
});
} else {
command = this.options.cliPath;
spawnArgs = args;
this.cliProcess = spawn(this.options.cliPath, args, {
stdio: stdioConfig,
cwd: this.options.cwd,
env: envWithoutNodeDebug
});
}
this.cliProcess = spawn(command, spawnArgs, {
stdio: this.options.useStdio ? ["pipe", "pipe", "pipe"] : ["ignore", "pipe", "pipe"],
cwd: this.options.cwd,
env: envWithoutNodeDebug
});
let stdout = "";

@@ -739,0 +748,0 @@ let resolved = false;

@@ -11,4 +11,4 @@ /**

/**
* Path to the Copilot CLI executable
* @default "copilot" (searches PATH)
* Path to the CLI executable or JavaScript entry point.
* If not specified, uses the bundled CLI from the @github/copilot package.
*/

@@ -15,0 +15,0 @@ cliPath?: string;

@@ -7,3 +7,3 @@ {

},
"version": "0.1.22",
"version": "0.1.23-preview.0",
"description": "TypeScript SDK for programmatic control of GitHub Copilot CLI via JSON-RPC",

@@ -66,3 +66,3 @@ "main": "./dist/index.js",

"engines": {
"node": ">=18.0.0"
"node": ">=24.0.0"
},

@@ -69,0 +69,0 @@ "files": [