@github/copilot-sdk 1.0.0-beta.4 → 1.0.0-beta.6

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/README.md CHANGED
@@ -32,7 +32,7 @@ import { CopilotClient, approveAll } from "@github/copilot-sdk";
32
32
  const client = new CopilotClient();
33
33
  await client.start();
34
34
 
35
- // Create a session (onPermissionRequest is required)
35
+ // Create a session (onPermissionRequest is optional; approveAll allows every tool)
36
36
  const session = await client.createSession({
37
37
  model: "gpt-5",
38
38
  onPermissionRequest: approveAll,
@@ -79,18 +79,17 @@ new CopilotClient(options?: CopilotClientOptions)
79
79
 
80
80
  **Options:**
81
81
 
82
- - `cliPath?: string` - Path to CLI executable (default: uses COPILOT_CLI_PATH env var or bundled instance)
83
- - `cliArgs?: string[]` - Extra arguments prepended before SDK-managed flags (e.g. `["./dist-cli/index.js"]` when using `node`)
84
- - `cliUrl?: string` - URL of existing CLI server to connect to (e.g., `"localhost:8080"`, `"http://127.0.0.1:9000"`, or just `"8080"`). When provided, the client will not spawn a CLI process.
85
- - `port?: number` - Server port (default: 0 for random)
86
- - `useStdio?: boolean` - Use stdio transport instead of TCP (default: true)
87
- - `logLevel?: string` - Log level (default: "info")
88
- - `autoStart?: boolean` - Auto-start server (default: true)
82
+ - `connection?: RuntimeConnection` - How to connect to the Copilot runtime. Construct via the factory functions on `RuntimeConnection`:
83
+ - `RuntimeConnection.forStdio({ path?, args? })` (default) — spawn the runtime and communicate over its stdin/stdout.
84
+ - `RuntimeConnection.forTcp({ port?, connectionToken?, path?, args? })` — spawn the runtime as a TCP server.
85
+ - `RuntimeConnection.forUri(url, { connectionToken? })` — connect to an already-running runtime (mutually exclusive with `gitHubToken`/`useLoggedInUser`).
86
+ - `cwd?: string` - Working directory for the runtime process (default: current process cwd).
87
+ - `baseDirectory?: string` - Base directory for Copilot data (session state, config, etc.). Sets `COPILOT_HOME` on the spawned runtime. When not set, the runtime defaults to `~/.copilot`. Ignored when connecting via `RuntimeConnection.forUri`.
88
+ - `logLevel?: string` - Log level. When omitted, the runtime uses its own default (currently `"info"`).
89
89
  - `gitHubToken?: string` - GitHub token for authentication. When provided, takes priority over other auth methods.
90
- - `useLoggedInUser?: boolean` - Whether to use logged-in user for authentication (default: true, but false when `gitHubToken` is provided). Cannot be used with `cliUrl`.
91
- - `copilotHome?: string` - Base directory for Copilot data (session state, config, etc.). Sets `COPILOT_HOME` on the spawned CLI process. When not set, the CLI defaults to `~/.copilot`. Useful in restricted environments where only specific directories are writable. Ignored when using `cliUrl`.
92
- - `telemetry?: TelemetryConfig` - OpenTelemetry configuration for the CLI process. Providing this object enables telemetry — no separate flag needed. See [Telemetry](#telemetry) below.
93
- - `onGetTraceContext?: TraceContextProvider` - Advanced: callback for linking your application's own OpenTelemetry spans into the same distributed trace as the CLI's spans. Not needed for normal telemetry collection. See [Telemetry](#telemetry) below.
90
+ - `useLoggedInUser?: boolean` - Whether to use logged-in user for authentication (default: true, but false when `gitHubToken` is provided). Cannot be used with `RuntimeConnection.forUri`.
91
+ - `telemetry?: TelemetryConfig` - OpenTelemetry configuration for the runtime process. Providing this object enables telemetry — no separate flag needed. See [Telemetry](#telemetry) below.
92
+ - `onGetTraceContext?: TraceContextProvider` - Advanced: callback for linking your application's own OpenTelemetry spans into the same distributed trace as the runtime's spans. Not needed for normal telemetry collection. See [Telemetry](#telemetry) below.
94
93
 
95
94
  #### Methods
96
95
 
@@ -115,11 +114,11 @@ Create a new conversation session.
115
114
  - `sessionId?: string` - Custom session ID.
116
115
  - `model?: string` - Model to use ("gpt-5", "claude-sonnet-4.5", etc.). **Required when using custom provider.**
117
116
  - `reasoningEffort?: "low" | "medium" | "high" | "xhigh"` - Reasoning effort level for models that support it. Use `listModels()` to check which models support this option.
118
- - `tools?: Tool[]` - Custom tools exposed to the CLI
117
+ - `tools?: Tool[]` - Custom tools exposed to the CLI. Tools without `handler` are declaration-only and must be resolved via pending tool-call RPCs.
119
118
  - `systemMessage?: SystemMessageConfig` - System message customization (see below)
120
119
  - `infiniteSessions?: InfiniteSessionConfig` - Configure automatic context compaction (see below)
121
120
  - `provider?: ProviderConfig` - Custom API provider configuration (BYOK - Bring Your Own Key). See [Custom Providers](#custom-providers) section.
122
- - `onPermissionRequest: PermissionHandler` - **Required.** Handler called before each tool execution to approve or deny it. Use `approveAll` to allow everything, or provide a custom function for fine-grained control. See [Permission Handling](#permission-handling) section.
121
+ - `onPermissionRequest?: PermissionHandler` - Optional handler called before each tool execution to approve or deny it. When omitted, permission requests are emitted as events and left pending for manual resolution. Use `approveAll` to allow everything, or provide a custom function for fine-grained control. See [Permission Handling](#permission-handling) section.
123
122
  - `onUserInputRequest?: UserInputHandler` - Handler for user input requests from the agent. Enables the `ask_user` tool. See [User Input Requests](#user-input-requests) section.
124
123
  - `onElicitationRequest?: ElicitationHandler` - Handler for elicitation requests dispatched by the server. Enables this client to present form-based UI dialogs on behalf of the agent or other session participants. See [Elicitation Requests](#elicitation-requests) section.
125
124
  - `hooks?: SessionHooks` - Hook handlers for session lifecycle events. See [Session Hooks](#session-hooks) section.
@@ -128,7 +127,7 @@ Create a new conversation session.
128
127
 
129
128
  Resume an existing session. Returns the session with `workspacePath` populated if infinite sessions were enabled.
130
129
 
131
- ##### `ping(message?: string): Promise<{ message: string; timestamp: number }>`
130
+ ##### `ping(message?: string): Promise<{ message: string; timestamp: string }>`
132
131
 
133
132
  Ping the server to check connectivity.
134
133
 
@@ -173,7 +172,7 @@ Request the TUI to switch to displaying the specified session. Only available in
173
172
  Subscribe to a specific session lifecycle event type. Returns an unsubscribe function.
174
173
 
175
174
  ```typescript
176
- const unsubscribe = client.on("session.foreground", (event) => {
175
+ const unsubscribe = client.onLifecycle("session.foreground", (event) => {
177
176
  console.log(`Session ${event.sessionId} is now in foreground`);
178
177
  });
179
178
  ```
@@ -183,7 +182,7 @@ const unsubscribe = client.on("session.foreground", (event) => {
183
182
  Subscribe to all session lifecycle events. Returns an unsubscribe function.
184
183
 
185
184
  ```typescript
186
- const unsubscribe = client.on((event) => {
185
+ const unsubscribe = client.onLifecycle((event) => {
187
186
  console.log(`${event.type}: ${event.sessionId}`);
188
187
  });
189
188
  ```
@@ -277,7 +276,7 @@ unsubscribe();
277
276
 
278
277
  Abort the currently processing message in this session.
279
278
 
280
- ##### `getMessages(): Promise<SessionEvent[]>`
279
+ ##### `getEvents(): Promise<SessionEvent[]>`
281
280
 
282
281
  Get all events/messages from this session.
283
282
 
@@ -415,7 +414,7 @@ Note: `assistant.message` and `assistant.reasoning` (final events) are always se
415
414
  ### Manual Server Control
416
415
 
417
416
  ```typescript
418
- const client = new CopilotClient({ autoStart: false });
417
+ const client = new CopilotClient({});
419
418
 
420
419
  // Start manually
421
420
  await client.start();
@@ -802,7 +801,7 @@ Inbound trace context from the CLI is available on the `ToolInvocation` object p
802
801
 
803
802
  ## Permission Handling
804
803
 
805
- An `onPermissionRequest` handler is **required** whenever you create or resume a session. The handler is called before the agent executes each tool (file writes, shell commands, custom tools, etc.) and must return a decision.
804
+ An `onPermissionRequest` handler is optional when you create or resume a session. When provided, it is called before the agent executes each tool (file writes, shell commands, custom tools, etc.) and returns a decision. When omitted, permission requests are emitted as events and left pending for the consumer to resolve with the pending permission RPC.
806
805
 
807
806
  ### Approve All (simplest)
808
807
 
@@ -843,29 +842,32 @@ const session = await client.createSession({
843
842
  // request.fullCommandText — full shell command (for shell)
844
843
 
845
844
  if (request.kind === "shell") {
846
- // Deny shell commands
847
- return { kind: "denied-interactively-by-user" };
845
+ // Deny shell commands, optionally telling the model why
846
+ return { kind: "reject", feedback: "Shell commands are not allowed." };
848
847
  }
849
848
 
850
- return { kind: "approved" };
849
+ return { kind: "approve-once" };
851
850
  },
852
851
  });
853
852
  ```
854
853
 
855
854
  ### Permission Result Kinds
856
855
 
857
- | Kind | Meaning |
858
- | ----------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
859
- | `"approved"` | Allow the tool to run |
860
- | `"denied-interactively-by-user"` | User explicitly denied the request |
861
- | `"denied-no-approval-rule-and-could-not-request-from-user"` | No approval rule matched and user could not be asked |
862
- | `"denied-by-rules"` | Denied by a policy rule |
863
- | `"denied-by-content-exclusion-policy"` | Denied due to a content exclusion policy |
864
- | `"no-result"` | Leave the request unanswered (only valid with protocol v1; rejected by protocol v2 servers) |
856
+ The handler must return one of the `PermissionDecision` shapes (or `{ kind: "no-result" }`). Approval scopes are present-tense — they describe the decision to apply, not the outcome reported back on session events:
857
+
858
+ | Kind | Meaning | Extra fields |
859
+ | ------------------------ | -------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------- |
860
+ | `"approve-once"` | Allow this single request | — |
861
+ | `"approve-for-session"` | Allow this request and remember the approval for the rest of the session | `approval?` (rule to remember), `domain?` (for URL approvals) |
862
+ | `"approve-for-location"` | Allow this request and persist the approval for this project location (git root or cwd) | `approval` (rule to persist), `locationKey` (location to persist under) |
863
+ | `"approve-permanently"` | Allow this request and persist the approval across sessions (currently used for URL domains) | `domain` (URL domain to approve) |
864
+ | `"reject"` | Deny the request | `feedback?` (optional string surfaced to the agent) |
865
+ | `"user-not-available"` | Deny the request because no user is available to confirm it | — |
866
+ | `"no-result"` | Leave the request unanswered (only valid with protocol v1; rejected by protocol v2 servers) | — |
865
867
 
866
868
  ### Resuming Sessions
867
869
 
868
- Pass `onPermissionRequest` when resuming a session too — it is required:
870
+ You may pass `onPermissionRequest` when resuming a session too:
869
871
 
870
872
  ```typescript
871
873
  const session = await client.resumeSession("session-id", {
@@ -1023,7 +1025,7 @@ try {
1023
1025
  ## Requirements
1024
1026
 
1025
1027
  - Node.js >= 18.0.0
1026
- - GitHub Copilot CLI installed and in PATH (or provide custom `cliPath`)
1028
+ - GitHub Copilot CLI installed and in PATH (or provide a custom `connection`)
1027
1029
 
1028
1030
  ## License
1029
1031