@github/copilot-sdk 1.0.29-preview.0 → 1.0.29-preview.2

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/session.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { createSessionRpc } from "./generated/rpc.js";
2
- import type { ModelSwitchAutoTierResult } from "./generated/rpc.js";
2
+ import type { ModelSwitchAutoTierResult, SessionManagementPolicy } from "./generated/rpc.js";
3
3
  import type { OpenCanvasInstance } from "./generated/rpc.js";
4
- import type { MessageOptions, ResponseSchema, ContextTier, ReasoningEffort, ReasoningSummary, AutoTier, ModelCapabilitiesOverride, SessionCapabilities, SessionConfig, SessionEvent, SessionEventHandler, SessionEventType, SessionUiApi, TranscriptRecovery, TypedSessionEventHandler } from "./types.js";
4
+ import type { MessageOptions, ResponseSchema, ContextTier, ReasoningEffort, ReasoningSummary, AutoTier, ModelCapabilitiesOverride, SessionCapabilities, SessionConfig, SessionEvent, SessionEventHandler, SessionEventType, SessionUiApi, SessionCreationHandler, TranscriptRecovery, TypedSessionEventHandler } from "./types.js";
5
5
  import { type SessionWorkflowApi } from "./workflow.js";
6
6
  /** Assistant message event - the final response from the assistant. */
7
7
  export type AssistantMessageEvent = Extract<SessionEvent, {
@@ -48,6 +48,7 @@ export declare class CopilotSession {
48
48
  /** Settles once every earlier `setTools` call has finished. */
49
49
  private setToolsQueue;
50
50
  private pendingExternalTools;
51
+ private pendingSessionCreations;
51
52
  private canvases;
52
53
  private bearerTokenProviders;
53
54
  private commandHandlers;
@@ -60,6 +61,7 @@ export declare class CopilotSession {
60
61
  private exitPlanModeHandler?;
61
62
  private autoModeSwitchHandler?;
62
63
  private skillProvider?;
64
+ private sessionCreationHandler?;
63
65
  private hooks?;
64
66
  private transformCallbacks?;
65
67
  private _rpc;
@@ -244,6 +246,11 @@ export declare class CopilotSession {
244
246
  private _confirm;
245
247
  private _select;
246
248
  private _input;
249
+ /**
250
+ * Registers the host's creation callback without enabling the tool group.
251
+ * Enable it separately with `session.rpc.management.configure({ enabled: true })`.
252
+ */
253
+ setSessionCreationHandler(handler?: SessionCreationHandler): Promise<SessionManagementPolicy>;
247
254
  private requireSkillProvider;
248
255
  /**
249
256
  * Runs a provider call with an abort signal tied to the runtime's request
package/dist/session.js CHANGED
@@ -157,6 +157,11 @@ class WorkflowProgressBuffer {
157
157
  if (this.closed) {
158
158
  throw new Error("Cannot log after the workflow run has settled");
159
159
  }
160
+ if (typeof text !== "string") {
161
+ throw new TypeError(
162
+ `${kind}() expects a string; got ${text === null ? "null" : typeof text}.`
163
+ );
164
+ }
160
165
  this.pending.push({ seq: this.nextSeq++, kind, text });
161
166
  this.scheduleFlush();
162
167
  }
@@ -284,6 +289,7 @@ class CopilotSession {
284
289
  /** Settles once every earlier `setTools` call has finished. */
285
290
  setToolsQueue = Promise.resolve();
286
291
  pendingExternalTools = /* @__PURE__ */ new Map();
292
+ pendingSessionCreations = /* @__PURE__ */ new Set();
287
293
  canvases = /* @__PURE__ */ new Map();
288
294
  bearerTokenProviders = /* @__PURE__ */ new Map();
289
295
  commandHandlers = /* @__PURE__ */ new Map();
@@ -296,6 +302,7 @@ class CopilotSession {
296
302
  exitPlanModeHandler;
297
303
  autoModeSwitchHandler;
298
304
  skillProvider;
305
+ sessionCreationHandler;
299
306
  hooks;
300
307
  transformCallbacks;
301
308
  _rpc = null;
@@ -883,6 +890,10 @@ class CopilotSession {
883
890
  controller.abort();
884
891
  }
885
892
  this.pendingExternalTools.clear();
893
+ for (const controller of this.pendingSessionCreations) {
894
+ controller.abort();
895
+ }
896
+ this.pendingSessionCreations.clear();
886
897
  this.eventHandlers.clear();
887
898
  this.typedEventHandlers.clear();
888
899
  this.toolHandlers.clear();
@@ -893,6 +904,7 @@ class CopilotSession {
893
904
  this.exitPlanModeHandler = void 0;
894
905
  this.autoModeSwitchHandler = void 0;
895
906
  this.skillProvider = void 0;
907
+ this.sessionCreationHandler = void 0;
896
908
  this.hooks = void 0;
897
909
  this.traceContextProvider = void 0;
898
910
  this.bearerTokenProviders.clear();
@@ -1856,6 +1868,41 @@ class CopilotSession {
1856
1868
  this.assertConnected();
1857
1869
  this.skillProvider = provider;
1858
1870
  }
1871
+ /**
1872
+ * Registers the host's creation callback without enabling the tool group.
1873
+ * Enable it separately with `session.rpc.management.configure({ enabled: true })`.
1874
+ */
1875
+ async setSessionCreationHandler(handler) {
1876
+ this.assertConnected();
1877
+ const previous = this.sessionCreationHandler;
1878
+ this.sessionCreationHandler = handler;
1879
+ try {
1880
+ return await this.rpc.management.configure({ hasCreateHandler: handler !== void 0 });
1881
+ } catch (error) {
1882
+ if (this.sessionCreationHandler === handler) this.sessionCreationHandler = previous;
1883
+ throw error;
1884
+ }
1885
+ }
1886
+ /** @internal */
1887
+ async _handleSessionManagementCreate(request, token) {
1888
+ this.assertConnected();
1889
+ const handler = this.sessionCreationHandler;
1890
+ if (!handler || request.parentSessionId !== this.sessionId || request.sessionId !== this.sessionId) {
1891
+ throw new Error("Session creation handler is unavailable");
1892
+ }
1893
+ const controller = new AbortController();
1894
+ this.pendingSessionCreations.add(controller);
1895
+ const subscription = token.onCancellationRequested(() => controller.abort());
1896
+ if (token.isCancellationRequested) controller.abort();
1897
+ try {
1898
+ return await handler(request, { signal: controller.signal });
1899
+ } catch {
1900
+ throw new Error("Session creation callback failed");
1901
+ } finally {
1902
+ subscription.dispose();
1903
+ this.pendingSessionCreations.delete(controller);
1904
+ }
1905
+ }
1859
1906
  /**
1860
1907
  * Handles a `skillProvider.list` request from the runtime.
1861
1908
  *
package/dist/types.d.ts CHANGED
@@ -9,13 +9,23 @@ export type { InstallationConfirmationHandler } from "./installationConfirmation
9
9
  import type { AgentModelPolicy, AttachmentExtensionContext as GeneratedExtensionContextAttachment, AutoTier, ModelProviderRef, PermissionRequest as GeneratedPermissionRequest, PermissionRequestedData as GeneratedPermissionRequestedData, PermissionRequestedEvent as GeneratedPermissionRequestedEvent, ReasoningSummary, SessionLimitsConfig, SessionEvent as GeneratedSessionEvent } from "./generated/session-events.js";
10
10
  import type { CopilotSession } from "./session.js";
11
11
  import type { JsonValue } from "./workflow.js";
12
- import type { ExtensionLaunchProviderHandler as GeneratedExtensionLaunchProvider, AutopilotOptions, GitHubTokenAcquireRequest, GitHubTokenAcquireResult, GitHubTelemetryNotification, HostDiagnostics, ModelBillingTokenPrices, DiagnosticsConfiguration, OpenCanvasInstance, ProtocolExternalToolNamespace, CurrentToolMetadata, KerberosAuthAcquireRequest, KerberosAuthMode, KerberosAuthScope, SandboxConfig } from "./generated/rpc.js";
12
+ import type { ExtensionLaunchProviderHandler as GeneratedExtensionLaunchProvider, AutopilotOptions, GitHubTokenAcquireRequest, GitHubTokenAcquireResult, GitHubTelemetryNotification, HostDiagnostics, ModelBillingTokenPrices, DiagnosticsConfiguration, OpenCanvasInstance, ProtocolExternalToolNamespace, CurrentToolMetadata, KerberosAuthAcquireRequest, KerberosAuthMode, KerberosAuthScope, SandboxConfig, SessionManagementCreateHostRequest, SessionManagementCreateResult } from "./generated/rpc.js";
13
13
  import type { ToolSet } from "./toolSet.js";
14
14
  export type { KerberosAuthAcquireRequest, KerberosAuthMode, KerberosAuthScope, } from "./generated/rpc.js";
15
15
  export type { RemoteSessionMode } from "./generated/rpc.js";
16
16
  export type { AutopilotOptions } from "./generated/rpc.js";
17
17
  export type { CurrentToolMetadata } from "./generated/rpc.js";
18
18
  export type { SandboxConfig, SandboxConfigSource } from "./generated/rpc.js";
19
+ export type { ManagedSessionInfo, SessionManagementCloseRequest, SessionManagementCloseResult, SessionManagementConfigureRequest, SessionManagementCreateHostRequest, SessionManagementCreateRequest, SessionManagementCreateResult, SessionManagementListRequest, SessionManagementListResult, SessionManagementMessageRequest, SessionManagementMessageResult, SessionManagementPolicy, SessionManagementScope, SessionManagementToolOverrides, } from "./generated/rpc.js";
20
+ /**
21
+ * Creates and supervises a separate session for this session's management tools.
22
+ * Use newSessionId as the child's exact identity and apply the requested launch
23
+ * options and permission ceiling. Route approvals independently, retain the new
24
+ * session, and dispose it with the host. Do not copy the parent's conversation.
25
+ */
26
+ export type SessionCreationHandler = (request: SessionManagementCreateHostRequest, options: {
27
+ signal: AbortSignal;
28
+ }) => SessionManagementCreateResult | Promise<SessionManagementCreateResult>;
19
29
  export type { AuthIdentityMetadata, AuthInfoType, ConnectorAccountRequest, ConnectorAvailability, ConnectorCapabilities, ConnectorCatalogEntry, ConnectorCatalogResult, ConnectorCatalogStatus, ConnectorConnectRequest, ConnectorConnectResult, ConnectorContinueRequest, ConnectorDisconnectResult, ConnectorMcpStatus, ConnectorReconcileRequest, ConnectorRuntimeStatus, ConnectorSessionAccount, ConnectorSessionAccountResult, ConnectorStatus, ExtensionLaunchProfile, ExtensionLaunchProviderResolveRequest, ExtensionLaunchProviderResolveResult, GitHubTokenAcquireReason, GitHubTokenAcquireResult, GitHubTelemetryNotification, GitHubTelemetryEvent, GitHubTelemetryClientInfo, HostDiagnostics, HostErrorReportingStatus, InstallationConfirmationRequest, InstallationConfirmationResponse, InstallationDecision, InstallationReview, McpInstallationReview, } from "./generated/rpc.js";
20
30
  /**
21
31
  * Arguments passed to a session's {@link GitHubTokenProvider}.
@@ -363,7 +373,8 @@ export interface CopilotClientOptions {
363
373
  /**
364
374
  * Whether to use the logged-in user for authentication.
365
375
  * When true, the runtime will attempt to use stored OAuth tokens or gh CLI auth.
366
- * When false, only explicit tokens (gitHubToken or environment variables) are used.
376
+ * When false, only explicit tokens such as gitHubToken are used; environment variable
377
+ * tokens (COPILOT_GITHUB_TOKEN, GH_TOKEN, GITHUB_TOKEN) are ignored.
367
378
  * @default true (but defaults to false when gitHubToken is provided)
368
379
  */
369
380
  useLoggedInUser?: boolean;
@@ -1854,9 +1865,10 @@ export interface LargeToolOutputConfig {
1854
1865
  outputDirectory?: string;
1855
1866
  }
1856
1867
  /**
1857
- * Valid reasoning effort levels for models that support it.
1868
+ * Model-defined reasoning effort for models that support it.
1869
+ * Use client.listModels() to discover supported values; BYOK providers can define additional levels.
1858
1870
  */
1859
- export type ReasoningEffort = "low" | "medium" | "high" | "xhigh" | "max";
1871
+ export type ReasoningEffort = string;
1860
1872
  /**
1861
1873
  * Context window tier for the session. "long_context" pins the session to the
1862
1874
  * long-context tier when the selected model supports it.
package/docs/examples.md CHANGED
@@ -198,7 +198,7 @@ Use `session.send()` to programmatically inject a new user message.
198
198
  ```js
199
199
  hooks: {
200
200
  onUserPromptSubmitted: async (input) => {
201
- if (/\\burgent\\b/i.test(input.prompt)) {
201
+ if (/\burgent\b/i.test(input.prompt)) {
202
202
  // Fire-and-forget a follow-up message
203
203
  setTimeout(() => session.send({ prompt: "Please prioritize this." }), 0);
204
204
  }
@@ -217,7 +217,7 @@ hooks: {
217
217
  onPreToolUse: async (input) => {
218
218
  if (input.toolName === "bash") {
219
219
  const cmd = String(input.toolArgs?.command || "");
220
- if (/rm\\s+-rf/i.test(cmd) || /Remove-Item\\s+.*-Recurse/i.test(cmd)) {
220
+ if (/rm\s+-rf/i.test(cmd) || /Remove-Item\s+.*-Recurse/i.test(cmd)) {
221
221
  return {
222
222
  permissionDecision: "deny",
223
223
  permissionDecisionReason: "Destructive commands are not allowed.",
@@ -394,7 +394,7 @@ function copyToClipboard(text) {
394
394
  const session = await joinSession({
395
395
  hooks: {
396
396
  onUserPromptSubmitted: async (input) => {
397
- if (/\\bcopy\\b/i.test(input.prompt)) {
397
+ if (/\bcopy\b/i.test(input.prompt)) {
398
398
  copyNextResponse = true;
399
399
  }
400
400
  },
@@ -513,7 +513,7 @@ const debounce = new Map();
513
513
 
514
514
  watch(cwd, { recursive: true }, (eventType, filename) => {
515
515
  if (!filename || eventType !== "change") return;
516
- if (filename.split(/[\\\\\\/]/).some((p) => IGNORE.has(p))) return;
516
+ if (filename.split(/[\\/]/).some((p) => IGNORE.has(p))) return;
517
517
 
518
518
  if (debounce.has(filename)) clearTimeout(debounce.get(filename));
519
519
  debounce.set(filename, setTimeout(() => {
@@ -524,7 +524,7 @@ watch(cwd, { recursive: true }, (eventType, filename) => {
524
524
  try { if (!statSync(fullPath).isFile()) return; } catch { return; }
525
525
  const relPath = relative(cwd, fullPath);
526
526
  session.send({
527
- prompt: `The user edited \\`${relPath}\\`.`,
527
+ prompt: `The user edited \`${relPath}\`.`,
528
528
  attachments: [{ type: "file", path: fullPath }],
529
529
  });
530
530
  }, 500));
@@ -619,7 +619,7 @@ function openInEditor(filePath) {
619
619
  const session = await joinSession({
620
620
  hooks: {
621
621
  onUserPromptSubmitted: async (input) => {
622
- if (/\\bcopy this\\b/i.test(input.prompt)) {
622
+ if (/\bcopy this\b/i.test(input.prompt)) {
623
623
  copyNextResponse = true;
624
624
  }
625
625
  return {
@@ -629,7 +629,7 @@ const session = await joinSession({
629
629
  onPreToolUse: async (input) => {
630
630
  if (input.toolName === "bash") {
631
631
  const cmd = String(input.toolArgs?.command || "");
632
- if (/rm\\s+-rf\\s+\//i.test(cmd) || /Remove-Item\\s+.*-Recurse/i.test(cmd)) {
632
+ if (/rm\s+-rf\s+\//i.test(cmd) || /Remove-Item\s+.*-Recurse/i.test(cmd)) {
633
633
  return {
634
634
  permissionDecision: "deny",
635
635
  permissionDecisionReason: "Destructive commands are not allowed.",
package/package.json CHANGED
@@ -5,8 +5,8 @@
5
5
  "url": "https://github.com/github/copilot-agent-runtime.git",
6
6
  "directory": "src/sdk/nodejs"
7
7
  },
8
- "version": "1.0.29-preview.0",
9
- "copilotCliVersion": "1.0.106-1",
8
+ "version": "1.0.29-preview.2",
9
+ "copilotCliVersion": "1.0.106-3",
10
10
  "description": "TypeScript SDK for programmatic control of GitHub Copilot CLI via JSON-RPC",
11
11
  "main": "./dist/cjs/index.js",
12
12
  "types": "./dist/index.d.ts",
@@ -79,8 +79,9 @@
79
79
  "@types/node": "^26.6.5",
80
80
  "@types/semver": "7.8.0",
81
81
  "@types/ws": "^8.18.1",
82
- "@typescript-eslint/eslint-plugin": "^8.72.1",
83
- "@typescript-eslint/parser": "^8.72.1",
82
+ "@typescript-eslint/eslint-plugin": "^8.72.0",
83
+ "@typescript-eslint/parser": "^8.72.0",
84
+ "@vitest/coverage-v8": "^5.0.5",
84
85
  "esbuild": "^0.28.1",
85
86
  "eslint": "^10.13.0",
86
87
  "file-entry-cache": "file:./scripts/eslint-file-cache",
@@ -114,18 +115,18 @@
114
115
  "README.md"
115
116
  ],
116
117
  "copilotRuntime": {
117
- "sourceSha": "1fb35cfaf220f19b8983d5cbd2f7aa2128e58b3c",
118
- "version": "1.0.106-1",
118
+ "sourceSha": "70ffdab66d4c7eb84302789a8536c02d955da3ed",
119
+ "version": "1.0.106-3",
119
120
  "visibility": "public"
120
121
  },
121
122
  "optionalDependencies": {
122
- "@github/copilot-sdk-darwin-arm64": "1.0.29-preview.0",
123
- "@github/copilot-sdk-darwin-x64": "1.0.29-preview.0",
124
- "@github/copilot-sdk-linux-arm64": "1.0.29-preview.0",
125
- "@github/copilot-sdk-linux-x64": "1.0.29-preview.0",
126
- "@github/copilot-sdk-linuxmusl-arm64": "1.0.29-preview.0",
127
- "@github/copilot-sdk-linuxmusl-x64": "1.0.29-preview.0",
128
- "@github/copilot-sdk-win32-arm64": "1.0.29-preview.0",
129
- "@github/copilot-sdk-win32-x64": "1.0.29-preview.0"
123
+ "@github/copilot-sdk-darwin-arm64": "1.0.29-preview.2",
124
+ "@github/copilot-sdk-darwin-x64": "1.0.29-preview.2",
125
+ "@github/copilot-sdk-linux-arm64": "1.0.29-preview.2",
126
+ "@github/copilot-sdk-linux-x64": "1.0.29-preview.2",
127
+ "@github/copilot-sdk-linuxmusl-arm64": "1.0.29-preview.2",
128
+ "@github/copilot-sdk-linuxmusl-x64": "1.0.29-preview.2",
129
+ "@github/copilot-sdk-win32-arm64": "1.0.29-preview.2",
130
+ "@github/copilot-sdk-win32-x64": "1.0.29-preview.2"
130
131
  }
131
132
  }