@github/copilot-sdk 1.0.5 → 1.0.6-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.
@@ -280,7 +280,8 @@ class CopilotClient {
280
280
  /** Connection-level session filesystem config, set via constructor option. */
281
281
  sessionFsConfig = null;
282
282
  requestHandler = null;
283
- llmInferenceHandlers = {};
283
+ onGitHubTelemetry;
284
+ clientGlobalHandlers = {};
284
285
  /**
285
286
  * Typed server-scoped RPC methods.
286
287
  * @throws Error if the client is not connected
@@ -381,7 +382,8 @@ class CopilotClient {
381
382
  this.onGetTraceContext = options.onGetTraceContext;
382
383
  this.sessionFsConfig = options.sessionFs ?? null;
383
384
  this.requestHandler = options.requestHandler ?? null;
384
- this.setupLlmInference();
385
+ this.onGitHubTelemetry = options.onGitHubTelemetry;
386
+ this.setupClientGlobalHandlers();
385
387
  const effectiveEnv = options.env ?? process.env;
386
388
  this.resolvedEnv = effectiveEnv;
387
389
  this.resolvedCliPath = conn.kind === "stdio" || conn.kind === "tcp" ? conn.path ?? effectiveEnv.COPILOT_CLI_PATH ?? getBundledCliPath() : void 0;
@@ -461,19 +463,29 @@ class CopilotClient {
461
463
  }
462
464
  session.clientSessionApis.sessionFs = (0, import_sessionFsProvider.createSessionFsAdapter)(provider);
463
465
  }
464
- setupLlmInference() {
465
- if (!this.requestHandler) {
466
- return;
467
- }
468
- this.llmInferenceHandlers = {
469
- llmInference: (0, import_copilotRequestHandler.createCopilotRequestAdapter)(this.requestHandler, () => {
466
+ setupClientGlobalHandlers() {
467
+ const handlers = {};
468
+ if (this.requestHandler) {
469
+ handlers.llmInference = (0, import_copilotRequestHandler.createCopilotRequestAdapter)(this.requestHandler, () => {
470
470
  if (!this.connection) {
471
471
  return void 0;
472
472
  }
473
473
  this._rpc ??= (0, import_rpc.createServerRpc)(this.connection);
474
474
  return this._rpc;
475
- })
476
- };
475
+ });
476
+ }
477
+ if (this.onGitHubTelemetry) {
478
+ const onGitHubTelemetry = this.onGitHubTelemetry;
479
+ handlers.gitHubTelemetry = {
480
+ event: async (notification) => {
481
+ try {
482
+ await onGitHubTelemetry(notification);
483
+ } catch {
484
+ }
485
+ }
486
+ };
487
+ }
488
+ this.clientGlobalHandlers = handlers;
477
489
  }
478
490
  /**
479
491
  * Starts the CLI server and establishes a connection.
@@ -1017,6 +1029,7 @@ class CopilotClient {
1017
1029
  workingDirectory: config.workingDirectory,
1018
1030
  streaming: config.streaming,
1019
1031
  includeSubAgentStreamingEvents: config.includeSubAgentStreamingEvents ?? true,
1032
+ ...this.onGitHubTelemetry != null ? { enableGitHubTelemetryForwarding: true } : {},
1020
1033
  mcpServers: toWireMcpServers(config.mcpServers),
1021
1034
  mcpOAuthTokenStorage: config.mcpOAuthTokenStorage,
1022
1035
  envValueMode: "direct",
@@ -1214,6 +1227,7 @@ class CopilotClient {
1214
1227
  enableSkills: config.enableSkills,
1215
1228
  streaming: config.streaming,
1216
1229
  includeSubAgentStreamingEvents: config.includeSubAgentStreamingEvents ?? true,
1230
+ ...this.onGitHubTelemetry != null ? { enableGitHubTelemetryForwarding: true } : {},
1217
1231
  mcpServers: toWireMcpServers(config.mcpServers),
1218
1232
  mcpOAuthTokenStorage: config.mcpOAuthTokenStorage,
1219
1233
  envValueMode: "direct",
@@ -1879,7 +1893,7 @@ stderr: ${stderrOutput}`
1879
1893
  if (!session) throw new Error(`No session found for sessionId: ${sessionId}`);
1880
1894
  return session.clientSessionApis;
1881
1895
  });
1882
- (0, import_rpc.registerClientGlobalApiHandlers)(this.connection, this.llmInferenceHandlers);
1896
+ (0, import_rpc.registerClientGlobalApiHandlers)(this.connection, this.clientGlobalHandlers);
1883
1897
  this.connection.onClose(() => {
1884
1898
  this.state = "disconnected";
1885
1899
  });
@@ -2086,10 +2086,10 @@ function registerClientGlobalApiHandlers(connection, handlers) {
2086
2086
  if (!handler) throw new Error("No llmInference client-global handler registered");
2087
2087
  return handler.httpRequestChunk(params);
2088
2088
  });
2089
- connection.onRequest("gitHubTelemetry.event", async (params) => {
2089
+ connection.onNotification("gitHubTelemetry.event", async (params) => {
2090
2090
  const handler = handlers.gitHubTelemetry;
2091
- if (!handler) throw new Error("No gitHubTelemetry client-global handler registered");
2092
- return handler.event(params);
2091
+ if (!handler) return;
2092
+ await handler.event(params);
2093
2093
  });
2094
2094
  }
2095
2095
  // Annotate the CommonJS export names for ESM import in node:
package/dist/client.d.ts CHANGED
@@ -36,7 +36,8 @@ export declare class CopilotClient {
36
36
  /** Connection-level session filesystem config, set via constructor option. */
37
37
  private sessionFsConfig;
38
38
  private requestHandler;
39
- private llmInferenceHandlers;
39
+ private onGitHubTelemetry?;
40
+ private clientGlobalHandlers;
40
41
  /**
41
42
  * Typed server-scoped RPC methods.
42
43
  * @throws Error if the client is not connected
@@ -80,7 +81,7 @@ export declare class CopilotClient {
80
81
  private parseCliUrl;
81
82
  private validateSessionFsConfig;
82
83
  private setupSessionFs;
83
- private setupLlmInference;
84
+ private setupClientGlobalHandlers;
84
85
  /**
85
86
  * Starts the CLI server and establishes a connection.
86
87
  *
package/dist/client.js CHANGED
@@ -267,7 +267,8 @@ class CopilotClient {
267
267
  /** Connection-level session filesystem config, set via constructor option. */
268
268
  sessionFsConfig = null;
269
269
  requestHandler = null;
270
- llmInferenceHandlers = {};
270
+ onGitHubTelemetry;
271
+ clientGlobalHandlers = {};
271
272
  /**
272
273
  * Typed server-scoped RPC methods.
273
274
  * @throws Error if the client is not connected
@@ -368,7 +369,8 @@ class CopilotClient {
368
369
  this.onGetTraceContext = options.onGetTraceContext;
369
370
  this.sessionFsConfig = options.sessionFs ?? null;
370
371
  this.requestHandler = options.requestHandler ?? null;
371
- this.setupLlmInference();
372
+ this.onGitHubTelemetry = options.onGitHubTelemetry;
373
+ this.setupClientGlobalHandlers();
372
374
  const effectiveEnv = options.env ?? process.env;
373
375
  this.resolvedEnv = effectiveEnv;
374
376
  this.resolvedCliPath = conn.kind === "stdio" || conn.kind === "tcp" ? conn.path ?? effectiveEnv.COPILOT_CLI_PATH ?? getBundledCliPath() : void 0;
@@ -448,19 +450,29 @@ class CopilotClient {
448
450
  }
449
451
  session.clientSessionApis.sessionFs = createSessionFsAdapter(provider);
450
452
  }
451
- setupLlmInference() {
452
- if (!this.requestHandler) {
453
- return;
454
- }
455
- this.llmInferenceHandlers = {
456
- llmInference: createCopilotRequestAdapter(this.requestHandler, () => {
453
+ setupClientGlobalHandlers() {
454
+ const handlers = {};
455
+ if (this.requestHandler) {
456
+ handlers.llmInference = createCopilotRequestAdapter(this.requestHandler, () => {
457
457
  if (!this.connection) {
458
458
  return void 0;
459
459
  }
460
460
  this._rpc ??= createServerRpc(this.connection);
461
461
  return this._rpc;
462
- })
463
- };
462
+ });
463
+ }
464
+ if (this.onGitHubTelemetry) {
465
+ const onGitHubTelemetry = this.onGitHubTelemetry;
466
+ handlers.gitHubTelemetry = {
467
+ event: async (notification) => {
468
+ try {
469
+ await onGitHubTelemetry(notification);
470
+ } catch {
471
+ }
472
+ }
473
+ };
474
+ }
475
+ this.clientGlobalHandlers = handlers;
464
476
  }
465
477
  /**
466
478
  * Starts the CLI server and establishes a connection.
@@ -1004,6 +1016,7 @@ class CopilotClient {
1004
1016
  workingDirectory: config.workingDirectory,
1005
1017
  streaming: config.streaming,
1006
1018
  includeSubAgentStreamingEvents: config.includeSubAgentStreamingEvents ?? true,
1019
+ ...this.onGitHubTelemetry != null ? { enableGitHubTelemetryForwarding: true } : {},
1007
1020
  mcpServers: toWireMcpServers(config.mcpServers),
1008
1021
  mcpOAuthTokenStorage: config.mcpOAuthTokenStorage,
1009
1022
  envValueMode: "direct",
@@ -1201,6 +1214,7 @@ class CopilotClient {
1201
1214
  enableSkills: config.enableSkills,
1202
1215
  streaming: config.streaming,
1203
1216
  includeSubAgentStreamingEvents: config.includeSubAgentStreamingEvents ?? true,
1217
+ ...this.onGitHubTelemetry != null ? { enableGitHubTelemetryForwarding: true } : {},
1204
1218
  mcpServers: toWireMcpServers(config.mcpServers),
1205
1219
  mcpOAuthTokenStorage: config.mcpOAuthTokenStorage,
1206
1220
  envValueMode: "direct",
@@ -1866,7 +1880,7 @@ stderr: ${stderrOutput}`
1866
1880
  if (!session) throw new Error(`No session found for sessionId: ${sessionId}`);
1867
1881
  return session.clientSessionApis;
1868
1882
  });
1869
- registerClientGlobalApiHandlers(this.connection, this.llmInferenceHandlers);
1883
+ registerClientGlobalApiHandlers(this.connection, this.clientGlobalHandlers);
1870
1884
  this.connection.onClose(() => {
1871
1885
  this.state = "disconnected";
1872
1886
  });
@@ -2058,10 +2058,10 @@ function registerClientGlobalApiHandlers(connection, handlers) {
2058
2058
  if (!handler) throw new Error("No llmInference client-global handler registered");
2059
2059
  return handler.httpRequestChunk(params);
2060
2060
  });
2061
- connection.onRequest("gitHubTelemetry.event", async (params) => {
2061
+ connection.onNotification("gitHubTelemetry.event", async (params) => {
2062
2062
  const handler = handlers.gitHubTelemetry;
2063
- if (!handler) throw new Error("No gitHubTelemetry client-global handler registered");
2064
- return handler.event(params);
2063
+ if (!handler) return;
2064
+ await handler.event(params);
2065
2065
  });
2066
2066
  }
2067
2067
  export {
package/dist/index.d.ts CHANGED
@@ -10,4 +10,4 @@ export { CopilotSession, type AssistantMessageEvent } from "./session.js";
10
10
  export { Canvas, CanvasError, createCanvas, type CanvasAction, type CanvasDeclaration, type CanvasHostContext, type CanvasHostContextCapabilities, type CanvasJsonSchema, type CanvasOptions, } from "./canvas.js";
11
11
  export { defineTool, approveAll, convertMcpCallToolResult, createSessionFsAdapter, CopilotRequestHandler, CopilotWebSocketHandler, CopilotWebSocketCloseStatus, CopilotWebSocketForwarder, SYSTEM_MESSAGE_SECTIONS, } from "./types.js";
12
12
  export type * from "./generated/session-events.js";
13
- export type { CommandContext, CommandDefinition, CommandHandler, CloudSessionOptions, CloudSessionRepository, AutoModeSwitchHandler, AutoModeSwitchRequest, AutoModeSwitchResponse, CopilotClientMode, CopilotClientOptions, StdioRuntimeConnection, TcpRuntimeConnection, UriRuntimeConnection, CustomAgentConfig, ElicitationFieldValue, ElicitationHandler, ElicitationParams, ElicitationContext, ElicitationResult, ElicitationSchema, ElicitationSchemaField, ExitPlanModeHandler, ExitPlanModeRequest, ExitPlanModeResult, ExtensionInfo, ForegroundSessionInfo, GetAuthStatusResponse, GetStatusResponse, InfiniteSessionConfig, LargeToolOutputConfig, MemoryConfiguration, UiInputOptions, MCPStdioServerConfig, MCPHTTPServerConfig, MCPServerConfig, DefaultAgentConfig, BearerTokenProvider, MessageOptions, ModelBilling, ModelBillingTokenPrices, ModelBillingTokenPricesLongContext, CapiSessionOptions, ModelCapabilities, ModelCapabilitiesOverride, ModelInfo, ModelPolicy, NamedProviderConfig, PermissionHandler, PermissionRequest, PermissionRequestResult, ProviderConfig, ProviderModelConfig, ProviderTokenArgs, RemoteSessionMode, ResumeSessionConfig, SectionOverride, SectionOverrideAction, SectionTransformFn, SessionCapabilities, SessionConfig, SessionConfigBase, SessionEvent, SessionEventHandler, SessionEventPayload, SessionEventType, SessionLifecycleEvent, SessionLifecycleEventMetadata, SessionLifecycleEventType, SessionLifecycleHandler, SessionCreatedEvent, SessionDeletedEvent, SessionUpdatedEvent, SessionForegroundEvent, SessionBackgroundEvent, SessionContext, SessionListFilter, SessionMetadata, SessionUiApi, SessionFsConfig, SessionFsProvider, SessionFsFileInfo, SessionFsSqliteQueryResult, SessionFsSqliteQueryType, SessionFsSqliteProvider, CopilotRequestContext, SystemMessageAppendConfig, SystemMessageConfig, SystemMessageCustomizeConfig, SystemMessageReplaceConfig, SystemMessageSection, TelemetryConfig, TraceContext, TraceContextProvider, Tool, ToolHandler, ToolInvocation, ToolTelemetry, ToolResultObject, TypedSessionEventHandler, TypedSessionLifecycleHandler, ZodSchema, } from "./types.js";
13
+ export type { CommandContext, CommandDefinition, CommandHandler, CloudSessionOptions, CloudSessionRepository, AutoModeSwitchHandler, AutoModeSwitchRequest, AutoModeSwitchResponse, CopilotClientMode, CopilotClientOptions, StdioRuntimeConnection, TcpRuntimeConnection, UriRuntimeConnection, CustomAgentConfig, ElicitationFieldValue, ElicitationHandler, ElicitationParams, ElicitationContext, ElicitationResult, ElicitationSchema, ElicitationSchemaField, ExitPlanModeHandler, ExitPlanModeRequest, ExitPlanModeResult, ExtensionInfo, ForegroundSessionInfo, GetAuthStatusResponse, GetStatusResponse, GitHubTelemetryNotification, GitHubTelemetryEvent, GitHubTelemetryClientInfo, InfiniteSessionConfig, LargeToolOutputConfig, MemoryConfiguration, UiInputOptions, MCPStdioServerConfig, MCPHTTPServerConfig, MCPServerConfig, DefaultAgentConfig, BearerTokenProvider, MessageOptions, ModelBilling, ModelBillingTokenPrices, ModelBillingTokenPricesLongContext, CapiSessionOptions, ModelCapabilities, ModelCapabilitiesOverride, ModelInfo, ModelPolicy, NamedProviderConfig, PermissionHandler, PermissionRequest, PermissionRequestResult, ProviderConfig, ProviderModelConfig, ProviderTokenArgs, RemoteSessionMode, ResumeSessionConfig, SectionOverride, SectionOverrideAction, SectionTransformFn, SessionCapabilities, SessionConfig, SessionConfigBase, SessionEvent, SessionEventHandler, SessionEventPayload, SessionEventType, SessionLifecycleEvent, SessionLifecycleEventMetadata, SessionLifecycleEventType, SessionLifecycleHandler, SessionCreatedEvent, SessionDeletedEvent, SessionUpdatedEvent, SessionForegroundEvent, SessionBackgroundEvent, SessionContext, SessionListFilter, SessionMetadata, SessionUiApi, SessionFsConfig, SessionFsProvider, SessionFsFileInfo, SessionFsSqliteQueryResult, SessionFsSqliteQueryType, SessionFsSqliteProvider, CopilotRequestContext, SystemMessageAppendConfig, SystemMessageConfig, SystemMessageCustomizeConfig, SystemMessageReplaceConfig, SystemMessageSection, TelemetryConfig, TraceContext, TraceContextProvider, Tool, ToolHandler, ToolInvocation, ToolTelemetry, ToolResultObject, TypedSessionEventHandler, TypedSessionLifecycleHandler, ZodSchema, } from "./types.js";
package/dist/types.d.ts CHANGED
@@ -6,9 +6,10 @@ import type { SessionFsProvider } from "./sessionFsProvider.js";
6
6
  import type { CopilotRequestHandler } from "./copilotRequestHandler.js";
7
7
  import type { ReasoningSummary, SessionLimitsConfig, SessionEvent as GeneratedSessionEvent } from "./generated/session-events.js";
8
8
  import type { CopilotSession } from "./session.js";
9
- import type { ModelBillingTokenPrices, OpenCanvasInstance, RemoteSessionMode } from "./generated/rpc.js";
9
+ import type { GitHubTelemetryNotification, ModelBillingTokenPrices, OpenCanvasInstance, RemoteSessionMode } from "./generated/rpc.js";
10
10
  import type { ToolSet } from "./toolSet.js";
11
11
  export type { RemoteSessionMode } from "./generated/rpc.js";
12
+ export type { GitHubTelemetryNotification, GitHubTelemetryEvent, GitHubTelemetryClientInfo, } from "./generated/rpc.js";
12
13
  export type { ModelBillingTokenPrices, ModelBillingTokenPricesLongContext, } from "./generated/rpc.js";
13
14
  export type SessionEvent = GeneratedSessionEvent;
14
15
  export type { ReasoningSummary } from "./generated/session-events.js";
@@ -270,6 +271,17 @@ export interface CopilotClientOptions {
270
271
  * @experimental
271
272
  */
272
273
  requestHandler?: CopilotRequestHandler;
274
+ /**
275
+ * Experimental. Receives GitHub telemetry events the runtime forwards to
276
+ * this connection. When set, the client opts each session it creates or
277
+ * resumes into telemetry forwarding and dispatches each
278
+ * `gitHubTelemetry.event` notification to this connection-global handler;
279
+ * each {@link GitHubTelemetryNotification} carries its originating
280
+ * `sessionId`.
281
+ *
282
+ * @experimental
283
+ */
284
+ onGitHubTelemetry?: (notification: GitHubTelemetryNotification) => void | Promise<void>;
273
285
  /**
274
286
  * Server-wide idle timeout for sessions in seconds.
275
287
  * Sessions without activity for this duration are automatically cleaned up.
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": "1.0.5",
7
+ "version": "1.0.6-preview.0",
8
8
  "description": "TypeScript SDK for programmatic control of GitHub Copilot CLI via JSON-RPC",
9
9
  "main": "./dist/cjs/index.js",
10
10
  "types": "./dist/index.d.ts",