vidpipe 1.3.29 → 1.3.31

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/index.js CHANGED
@@ -5270,18 +5270,45 @@ function createServerRpc(connection) {
5270
5270
  return {
5271
5271
  ping: async (params) => connection.sendRequest("ping", params),
5272
5272
  models: {
5273
- list: async () => connection.sendRequest("models.list", {})
5273
+ list: async (params) => connection.sendRequest("models.list", params)
5274
5274
  },
5275
5275
  tools: {
5276
5276
  list: async (params) => connection.sendRequest("tools.list", params)
5277
5277
  },
5278
5278
  account: {
5279
- getQuota: async () => connection.sendRequest("account.getQuota", {})
5279
+ getQuota: async (params) => connection.sendRequest("account.getQuota", params)
5280
+ },
5281
+ mcp: {
5282
+ config: {
5283
+ list: async () => connection.sendRequest("mcp.config.list", {}),
5284
+ add: async (params) => connection.sendRequest("mcp.config.add", params),
5285
+ update: async (params) => connection.sendRequest("mcp.config.update", params),
5286
+ remove: async (params) => connection.sendRequest("mcp.config.remove", params),
5287
+ enable: async (params) => connection.sendRequest("mcp.config.enable", params),
5288
+ disable: async (params) => connection.sendRequest("mcp.config.disable", params)
5289
+ },
5290
+ discover: async (params) => connection.sendRequest("mcp.discover", params)
5291
+ },
5292
+ skills: {
5293
+ config: {
5294
+ setDisabledSkills: async (params) => connection.sendRequest("skills.config.setDisabledSkills", params)
5295
+ },
5296
+ discover: async (params) => connection.sendRequest("skills.discover", params)
5297
+ },
5298
+ sessionFs: {
5299
+ setProvider: async (params) => connection.sendRequest("sessionFs.setProvider", params)
5300
+ },
5301
+ /** @experimental */
5302
+ sessions: {
5303
+ fork: async (params) => connection.sendRequest("sessions.fork", params)
5280
5304
  }
5281
5305
  };
5282
5306
  }
5283
5307
  function createSessionRpc(connection, sessionId) {
5284
5308
  return {
5309
+ auth: {
5310
+ getStatus: async () => connection.sendRequest("session.auth.getStatus", { sessionId })
5311
+ },
5285
5312
  model: {
5286
5313
  getCurrent: async () => connection.sendRequest("session.model.getCurrent", { sessionId }),
5287
5314
  switchTo: async (params) => connection.sendRequest("session.model.switchTo", { sessionId, ...params })
@@ -5290,15 +5317,23 @@ function createSessionRpc(connection, sessionId) {
5290
5317
  get: async () => connection.sendRequest("session.mode.get", { sessionId }),
5291
5318
  set: async (params) => connection.sendRequest("session.mode.set", { sessionId, ...params })
5292
5319
  },
5320
+ name: {
5321
+ get: async () => connection.sendRequest("session.name.get", { sessionId }),
5322
+ set: async (params) => connection.sendRequest("session.name.set", { sessionId, ...params })
5323
+ },
5293
5324
  plan: {
5294
5325
  read: async () => connection.sendRequest("session.plan.read", { sessionId }),
5295
5326
  update: async (params) => connection.sendRequest("session.plan.update", { sessionId, ...params }),
5296
5327
  delete: async () => connection.sendRequest("session.plan.delete", { sessionId })
5297
5328
  },
5298
- workspace: {
5299
- listFiles: async () => connection.sendRequest("session.workspace.listFiles", { sessionId }),
5300
- readFile: async (params) => connection.sendRequest("session.workspace.readFile", { sessionId, ...params }),
5301
- createFile: async (params) => connection.sendRequest("session.workspace.createFile", { sessionId, ...params })
5329
+ workspaces: {
5330
+ getWorkspace: async () => connection.sendRequest("session.workspaces.getWorkspace", { sessionId }),
5331
+ listFiles: async () => connection.sendRequest("session.workspaces.listFiles", { sessionId }),
5332
+ readFile: async (params) => connection.sendRequest("session.workspaces.readFile", { sessionId, ...params }),
5333
+ createFile: async (params) => connection.sendRequest("session.workspaces.createFile", { sessionId, ...params })
5334
+ },
5335
+ instructions: {
5336
+ getSources: async () => connection.sendRequest("session.instructions.getSources", { sessionId })
5302
5337
  },
5303
5338
  /** @experimental */
5304
5339
  fleet: {
@@ -5324,7 +5359,11 @@ function createSessionRpc(connection, sessionId) {
5324
5359
  list: async () => connection.sendRequest("session.mcp.list", { sessionId }),
5325
5360
  enable: async (params) => connection.sendRequest("session.mcp.enable", { sessionId, ...params }),
5326
5361
  disable: async (params) => connection.sendRequest("session.mcp.disable", { sessionId, ...params }),
5327
- reload: async () => connection.sendRequest("session.mcp.reload", { sessionId })
5362
+ reload: async () => connection.sendRequest("session.mcp.reload", { sessionId }),
5363
+ /** @experimental */
5364
+ oauth: {
5365
+ login: async (params) => connection.sendRequest("session.mcp.oauth.login", { sessionId, ...params })
5366
+ }
5328
5367
  },
5329
5368
  /** @experimental */
5330
5369
  plugins: {
@@ -5337,10 +5376,6 @@ function createSessionRpc(connection, sessionId) {
5337
5376
  disable: async (params) => connection.sendRequest("session.extensions.disable", { sessionId, ...params }),
5338
5377
  reload: async () => connection.sendRequest("session.extensions.reload", { sessionId })
5339
5378
  },
5340
- /** @experimental */
5341
- compaction: {
5342
- compact: async () => connection.sendRequest("session.compaction.compact", { sessionId })
5343
- },
5344
5379
  tools: {
5345
5380
  handlePendingToolCall: async (params) => connection.sendRequest("session.tools.handlePendingToolCall", { sessionId, ...params })
5346
5381
  },
@@ -5348,18 +5383,82 @@ function createSessionRpc(connection, sessionId) {
5348
5383
  handlePendingCommand: async (params) => connection.sendRequest("session.commands.handlePendingCommand", { sessionId, ...params })
5349
5384
  },
5350
5385
  ui: {
5351
- elicitation: async (params) => connection.sendRequest("session.ui.elicitation", { sessionId, ...params })
5386
+ elicitation: async (params) => connection.sendRequest("session.ui.elicitation", { sessionId, ...params }),
5387
+ handlePendingElicitation: async (params) => connection.sendRequest("session.ui.handlePendingElicitation", { sessionId, ...params })
5352
5388
  },
5353
5389
  permissions: {
5354
- handlePendingPermissionRequest: async (params) => connection.sendRequest("session.permissions.handlePendingPermissionRequest", { sessionId, ...params })
5390
+ handlePendingPermissionRequest: async (params) => connection.sendRequest("session.permissions.handlePendingPermissionRequest", { sessionId, ...params }),
5391
+ setApproveAll: async (params) => connection.sendRequest("session.permissions.setApproveAll", { sessionId, ...params }),
5392
+ resetSessionApprovals: async () => connection.sendRequest("session.permissions.resetSessionApprovals", { sessionId })
5355
5393
  },
5356
5394
  log: async (params) => connection.sendRequest("session.log", { sessionId, ...params }),
5357
5395
  shell: {
5358
5396
  exec: async (params) => connection.sendRequest("session.shell.exec", { sessionId, ...params }),
5359
5397
  kill: async (params) => connection.sendRequest("session.shell.kill", { sessionId, ...params })
5398
+ },
5399
+ /** @experimental */
5400
+ history: {
5401
+ compact: async () => connection.sendRequest("session.history.compact", { sessionId }),
5402
+ truncate: async (params) => connection.sendRequest("session.history.truncate", { sessionId, ...params })
5403
+ },
5404
+ /** @experimental */
5405
+ usage: {
5406
+ getMetrics: async () => connection.sendRequest("session.usage.getMetrics", { sessionId })
5360
5407
  }
5361
5408
  };
5362
5409
  }
5410
+ function registerClientSessionApiHandlers(connection, getHandlers) {
5411
+ connection.onRequest("sessionFs.readFile", async (params) => {
5412
+ const handler = getHandlers(params.sessionId).sessionFs;
5413
+ if (!handler) throw new Error(`No sessionFs handler registered for session: ${params.sessionId}`);
5414
+ return handler.readFile(params);
5415
+ });
5416
+ connection.onRequest("sessionFs.writeFile", async (params) => {
5417
+ const handler = getHandlers(params.sessionId).sessionFs;
5418
+ if (!handler) throw new Error(`No sessionFs handler registered for session: ${params.sessionId}`);
5419
+ return handler.writeFile(params);
5420
+ });
5421
+ connection.onRequest("sessionFs.appendFile", async (params) => {
5422
+ const handler = getHandlers(params.sessionId).sessionFs;
5423
+ if (!handler) throw new Error(`No sessionFs handler registered for session: ${params.sessionId}`);
5424
+ return handler.appendFile(params);
5425
+ });
5426
+ connection.onRequest("sessionFs.exists", async (params) => {
5427
+ const handler = getHandlers(params.sessionId).sessionFs;
5428
+ if (!handler) throw new Error(`No sessionFs handler registered for session: ${params.sessionId}`);
5429
+ return handler.exists(params);
5430
+ });
5431
+ connection.onRequest("sessionFs.stat", async (params) => {
5432
+ const handler = getHandlers(params.sessionId).sessionFs;
5433
+ if (!handler) throw new Error(`No sessionFs handler registered for session: ${params.sessionId}`);
5434
+ return handler.stat(params);
5435
+ });
5436
+ connection.onRequest("sessionFs.mkdir", async (params) => {
5437
+ const handler = getHandlers(params.sessionId).sessionFs;
5438
+ if (!handler) throw new Error(`No sessionFs handler registered for session: ${params.sessionId}`);
5439
+ return handler.mkdir(params);
5440
+ });
5441
+ connection.onRequest("sessionFs.readdir", async (params) => {
5442
+ const handler = getHandlers(params.sessionId).sessionFs;
5443
+ if (!handler) throw new Error(`No sessionFs handler registered for session: ${params.sessionId}`);
5444
+ return handler.readdir(params);
5445
+ });
5446
+ connection.onRequest("sessionFs.readdirWithTypes", async (params) => {
5447
+ const handler = getHandlers(params.sessionId).sessionFs;
5448
+ if (!handler) throw new Error(`No sessionFs handler registered for session: ${params.sessionId}`);
5449
+ return handler.readdirWithTypes(params);
5450
+ });
5451
+ connection.onRequest("sessionFs.rm", async (params) => {
5452
+ const handler = getHandlers(params.sessionId).sessionFs;
5453
+ if (!handler) throw new Error(`No sessionFs handler registered for session: ${params.sessionId}`);
5454
+ return handler.rm(params);
5455
+ });
5456
+ connection.onRequest("sessionFs.rename", async (params) => {
5457
+ const handler = getHandlers(params.sessionId).sessionFs;
5458
+ if (!handler) throw new Error(`No sessionFs handler registered for session: ${params.sessionId}`);
5459
+ return handler.rename(params);
5460
+ });
5461
+ }
5363
5462
  var init_rpc = __esm({
5364
5463
  "node_modules/@github/copilot-sdk/dist/generated/rpc.js"() {
5365
5464
  "use strict";
@@ -5394,6 +5493,25 @@ var init_telemetry = __esm({
5394
5493
  });
5395
5494
 
5396
5495
  // node_modules/@github/copilot-sdk/dist/session.js
5496
+ function isToolResultObject(value) {
5497
+ if (typeof value !== "object" || value === null) {
5498
+ return false;
5499
+ }
5500
+ if (!("textResultForLlm" in value) || typeof value.textResultForLlm !== "string") {
5501
+ return false;
5502
+ }
5503
+ if (!("resultType" in value) || typeof value.resultType !== "string") {
5504
+ return false;
5505
+ }
5506
+ const allowedResultTypes = [
5507
+ "success",
5508
+ "failure",
5509
+ "rejected",
5510
+ "denied",
5511
+ "timeout"
5512
+ ];
5513
+ return allowedResultTypes.includes(value.resultType);
5514
+ }
5397
5515
  var import_node, NO_RESULT_PERMISSION_V2_ERROR, CopilotSession;
5398
5516
  var init_session = __esm({
5399
5517
  "node_modules/@github/copilot-sdk/dist/session.js"() {
@@ -5421,12 +5539,17 @@ var init_session = __esm({
5421
5539
  eventHandlers = /* @__PURE__ */ new Set();
5422
5540
  typedEventHandlers = /* @__PURE__ */ new Map();
5423
5541
  toolHandlers = /* @__PURE__ */ new Map();
5542
+ commandHandlers = /* @__PURE__ */ new Map();
5424
5543
  permissionHandler;
5425
5544
  userInputHandler;
5545
+ elicitationHandler;
5426
5546
  hooks;
5427
5547
  transformCallbacks;
5428
5548
  _rpc = null;
5429
5549
  traceContextProvider;
5550
+ _capabilities = {};
5551
+ /** @internal Client session API handlers, populated by CopilotClient during create/resume. */
5552
+ clientSessionApis = {};
5430
5553
  /**
5431
5554
  * Typed session-scoped RPC methods.
5432
5555
  */
@@ -5444,6 +5567,33 @@ var init_session = __esm({
5444
5567
  get workspacePath() {
5445
5568
  return this._workspacePath;
5446
5569
  }
5570
+ /**
5571
+ * Host capabilities reported when the session was created or resumed.
5572
+ * Use this to check feature support before calling capability-gated APIs.
5573
+ */
5574
+ get capabilities() {
5575
+ return this._capabilities;
5576
+ }
5577
+ /**
5578
+ * Interactive UI methods for showing dialogs to the user.
5579
+ * Only available when the CLI host supports elicitation
5580
+ * (`session.capabilities.ui?.elicitation === true`).
5581
+ *
5582
+ * @example
5583
+ * ```typescript
5584
+ * if (session.capabilities.ui?.elicitation) {
5585
+ * const ok = await session.ui.confirm("Deploy to production?");
5586
+ * }
5587
+ * ```
5588
+ */
5589
+ get ui() {
5590
+ return {
5591
+ elicitation: (params) => this._elicitation(params),
5592
+ confirm: (message) => this._confirm(message),
5593
+ select: (message, options) => this._select(message, options),
5594
+ input: (message, options) => this._input(message, options)
5595
+ };
5596
+ }
5447
5597
  /**
5448
5598
  * Sends a message to this session and waits for the response.
5449
5599
  *
@@ -5468,7 +5618,8 @@ var init_session = __esm({
5468
5618
  sessionId: this.sessionId,
5469
5619
  prompt: options.prompt,
5470
5620
  attachments: options.attachments,
5471
- mode: options.mode
5621
+ mode: options.mode,
5622
+ requestHeaders: options.requestHeaders
5472
5623
  });
5473
5624
  return response.messageId;
5474
5625
  }
@@ -5609,10 +5760,33 @@ var init_session = __esm({
5609
5760
  );
5610
5761
  }
5611
5762
  } else if (event.type === "permission.requested") {
5612
- const { requestId, permissionRequest } = event.data;
5763
+ const { requestId, permissionRequest, resolvedByHook } = event.data;
5764
+ if (resolvedByHook) {
5765
+ return;
5766
+ }
5613
5767
  if (this.permissionHandler) {
5614
5768
  void this._executePermissionAndRespond(requestId, permissionRequest);
5615
5769
  }
5770
+ } else if (event.type === "command.execute") {
5771
+ const { requestId, commandName, command, args } = event.data;
5772
+ void this._executeCommandAndRespond(requestId, commandName, command, args);
5773
+ } else if (event.type === "elicitation.requested") {
5774
+ if (this.elicitationHandler) {
5775
+ const { message, requestedSchema, mode, elicitationSource, url, requestId } = event.data;
5776
+ void this._handleElicitationRequest(
5777
+ {
5778
+ sessionId: this.sessionId,
5779
+ message,
5780
+ requestedSchema,
5781
+ mode,
5782
+ elicitationSource,
5783
+ url
5784
+ },
5785
+ requestId
5786
+ );
5787
+ }
5788
+ } else if (event.type === "capabilities.changed") {
5789
+ this._capabilities = { ...this._capabilities, ...event.data };
5616
5790
  }
5617
5791
  }
5618
5792
  /**
@@ -5634,6 +5808,8 @@ var init_session = __esm({
5634
5808
  result = "";
5635
5809
  } else if (typeof rawResult === "string") {
5636
5810
  result = rawResult;
5811
+ } else if (isToolResultObject(rawResult)) {
5812
+ result = rawResult;
5637
5813
  } else {
5638
5814
  result = JSON.stringify(rawResult);
5639
5815
  }
@@ -5667,7 +5843,7 @@ var init_session = __esm({
5667
5843
  await this.rpc.permissions.handlePendingPermissionRequest({
5668
5844
  requestId,
5669
5845
  result: {
5670
- kind: "denied-no-approval-rule-and-could-not-request-from-user"
5846
+ kind: "user-not-available"
5671
5847
  }
5672
5848
  });
5673
5849
  } catch (rpcError) {
@@ -5677,6 +5853,39 @@ var init_session = __esm({
5677
5853
  }
5678
5854
  }
5679
5855
  }
5856
+ /**
5857
+ * Executes a command handler and sends the result back via RPC.
5858
+ * @internal
5859
+ */
5860
+ async _executeCommandAndRespond(requestId, commandName, command, args) {
5861
+ const handler = this.commandHandlers.get(commandName);
5862
+ if (!handler) {
5863
+ try {
5864
+ await this.rpc.commands.handlePendingCommand({
5865
+ requestId,
5866
+ error: `Unknown command: ${commandName}`
5867
+ });
5868
+ } catch (rpcError) {
5869
+ if (!(rpcError instanceof import_node.ConnectionError || rpcError instanceof import_node.ResponseError)) {
5870
+ throw rpcError;
5871
+ }
5872
+ }
5873
+ return;
5874
+ }
5875
+ try {
5876
+ await handler({ sessionId: this.sessionId, command, commandName, args });
5877
+ await this.rpc.commands.handlePendingCommand({ requestId });
5878
+ } catch (error) {
5879
+ const message = error instanceof Error ? error.message : String(error);
5880
+ try {
5881
+ await this.rpc.commands.handlePendingCommand({ requestId, error: message });
5882
+ } catch (rpcError) {
5883
+ if (!(rpcError instanceof import_node.ConnectionError || rpcError instanceof import_node.ResponseError)) {
5884
+ throw rpcError;
5885
+ }
5886
+ }
5887
+ }
5888
+ }
5680
5889
  /**
5681
5890
  * Registers custom tool handlers for this session.
5682
5891
  *
@@ -5705,6 +5914,133 @@ var init_session = __esm({
5705
5914
  getToolHandler(name) {
5706
5915
  return this.toolHandlers.get(name);
5707
5916
  }
5917
+ /**
5918
+ * Registers command handlers for this session.
5919
+ *
5920
+ * @param commands - An array of command definitions with handlers, or undefined to clear
5921
+ * @internal This method is typically called internally when creating/resuming a session.
5922
+ */
5923
+ registerCommands(commands) {
5924
+ this.commandHandlers.clear();
5925
+ if (!commands) {
5926
+ return;
5927
+ }
5928
+ for (const cmd of commands) {
5929
+ this.commandHandlers.set(cmd.name, cmd.handler);
5930
+ }
5931
+ }
5932
+ /**
5933
+ * Registers the elicitation handler for this session.
5934
+ *
5935
+ * @param handler - The handler to invoke when the server dispatches an elicitation request
5936
+ * @internal This method is typically called internally when creating/resuming a session.
5937
+ */
5938
+ registerElicitationHandler(handler) {
5939
+ this.elicitationHandler = handler;
5940
+ }
5941
+ /**
5942
+ * Handles an elicitation.requested broadcast event.
5943
+ * Invokes the registered handler and responds via handlePendingElicitation RPC.
5944
+ * @internal
5945
+ */
5946
+ async _handleElicitationRequest(context, requestId) {
5947
+ if (!this.elicitationHandler) {
5948
+ return;
5949
+ }
5950
+ try {
5951
+ const result = await this.elicitationHandler(context);
5952
+ await this.rpc.ui.handlePendingElicitation({ requestId, result });
5953
+ } catch {
5954
+ try {
5955
+ await this.rpc.ui.handlePendingElicitation({
5956
+ requestId,
5957
+ result: { action: "cancel" }
5958
+ });
5959
+ } catch (rpcError) {
5960
+ if (!(rpcError instanceof import_node.ConnectionError || rpcError instanceof import_node.ResponseError)) {
5961
+ throw rpcError;
5962
+ }
5963
+ }
5964
+ }
5965
+ }
5966
+ /**
5967
+ * Sets the host capabilities for this session.
5968
+ *
5969
+ * @param capabilities - The capabilities object from the create/resume response
5970
+ * @internal This method is typically called internally when creating/resuming a session.
5971
+ */
5972
+ setCapabilities(capabilities) {
5973
+ this._capabilities = capabilities ?? {};
5974
+ }
5975
+ assertElicitation() {
5976
+ if (!this._capabilities.ui?.elicitation) {
5977
+ throw new Error(
5978
+ "Elicitation is not supported by the host. Check session.capabilities.ui?.elicitation before calling UI methods."
5979
+ );
5980
+ }
5981
+ }
5982
+ async _elicitation(params) {
5983
+ this.assertElicitation();
5984
+ return this.rpc.ui.elicitation({
5985
+ message: params.message,
5986
+ requestedSchema: params.requestedSchema
5987
+ });
5988
+ }
5989
+ async _confirm(message) {
5990
+ this.assertElicitation();
5991
+ const result = await this.rpc.ui.elicitation({
5992
+ message,
5993
+ requestedSchema: {
5994
+ type: "object",
5995
+ properties: {
5996
+ confirmed: { type: "boolean", default: true }
5997
+ },
5998
+ required: ["confirmed"]
5999
+ }
6000
+ });
6001
+ return result.action === "accept" && result.content?.confirmed === true;
6002
+ }
6003
+ async _select(message, options) {
6004
+ this.assertElicitation();
6005
+ const result = await this.rpc.ui.elicitation({
6006
+ message,
6007
+ requestedSchema: {
6008
+ type: "object",
6009
+ properties: {
6010
+ selection: { type: "string", enum: options }
6011
+ },
6012
+ required: ["selection"]
6013
+ }
6014
+ });
6015
+ if (result.action === "accept" && result.content?.selection != null) {
6016
+ return result.content.selection;
6017
+ }
6018
+ return null;
6019
+ }
6020
+ async _input(message, options) {
6021
+ this.assertElicitation();
6022
+ const field = { type: "string" };
6023
+ if (options?.title) field.title = options.title;
6024
+ if (options?.description) field.description = options.description;
6025
+ if (options?.minLength != null) field.minLength = options.minLength;
6026
+ if (options?.maxLength != null) field.maxLength = options.maxLength;
6027
+ if (options?.format) field.format = options.format;
6028
+ if (options?.default != null) field.default = options.default;
6029
+ const result = await this.rpc.ui.elicitation({
6030
+ message,
6031
+ requestedSchema: {
6032
+ type: "object",
6033
+ properties: {
6034
+ value: field
6035
+ },
6036
+ required: ["value"]
6037
+ }
6038
+ });
6039
+ if (result.action === "accept" && result.content?.value != null) {
6040
+ return result.content.value;
6041
+ }
6042
+ return null;
6043
+ }
5708
6044
  /**
5709
6045
  * Registers a handler for permission requests.
5710
6046
  *
@@ -5785,7 +6121,7 @@ var init_session = __esm({
5785
6121
  */
5786
6122
  async _handlePermissionRequestV2(request) {
5787
6123
  if (!this.permissionHandler) {
5788
- return { kind: "denied-no-approval-rule-and-could-not-request-from-user" };
6124
+ return { kind: "user-not-available" };
5789
6125
  }
5790
6126
  try {
5791
6127
  const result = await this.permissionHandler(request, {
@@ -5799,7 +6135,7 @@ var init_session = __esm({
5799
6135
  if (error instanceof Error && error.message === NO_RESULT_PERMISSION_V2_ERROR) {
5800
6136
  throw error;
5801
6137
  }
5802
- return { kind: "denied-no-approval-rule-and-could-not-request-from-user" };
6138
+ return { kind: "user-not-available" };
5803
6139
  }
5804
6140
  }
5805
6141
  /**
@@ -5988,6 +6324,120 @@ var init_session = __esm({
5988
6324
  }
5989
6325
  });
5990
6326
 
6327
+ // node_modules/@github/copilot-sdk/dist/sessionFsProvider.js
6328
+ function createSessionFsAdapter(provider) {
6329
+ return {
6330
+ readFile: async ({ path }) => {
6331
+ try {
6332
+ const content = await provider.readFile(path);
6333
+ return { content };
6334
+ } catch (err) {
6335
+ return { content: "", error: toSessionFsError(err) };
6336
+ }
6337
+ },
6338
+ writeFile: async ({ path, content, mode }) => {
6339
+ try {
6340
+ await provider.writeFile(path, content, mode);
6341
+ return void 0;
6342
+ } catch (err) {
6343
+ return toSessionFsError(err);
6344
+ }
6345
+ },
6346
+ appendFile: async ({ path, content, mode }) => {
6347
+ try {
6348
+ await provider.appendFile(path, content, mode);
6349
+ return void 0;
6350
+ } catch (err) {
6351
+ return toSessionFsError(err);
6352
+ }
6353
+ },
6354
+ exists: async ({ path }) => {
6355
+ try {
6356
+ return { exists: await provider.exists(path) };
6357
+ } catch {
6358
+ return { exists: false };
6359
+ }
6360
+ },
6361
+ stat: async ({ path }) => {
6362
+ try {
6363
+ return await provider.stat(path);
6364
+ } catch (err) {
6365
+ return {
6366
+ isFile: false,
6367
+ isDirectory: false,
6368
+ size: 0,
6369
+ mtime: (/* @__PURE__ */ new Date()).toISOString(),
6370
+ birthtime: (/* @__PURE__ */ new Date()).toISOString(),
6371
+ error: toSessionFsError(err)
6372
+ };
6373
+ }
6374
+ },
6375
+ mkdir: async ({ path, recursive, mode }) => {
6376
+ try {
6377
+ await provider.mkdir(path, recursive ?? false, mode);
6378
+ return void 0;
6379
+ } catch (err) {
6380
+ return toSessionFsError(err);
6381
+ }
6382
+ },
6383
+ readdir: async ({ path }) => {
6384
+ try {
6385
+ const entries = await provider.readdir(path);
6386
+ return { entries };
6387
+ } catch (err) {
6388
+ return { entries: [], error: toSessionFsError(err) };
6389
+ }
6390
+ },
6391
+ readdirWithTypes: async ({ path }) => {
6392
+ try {
6393
+ const entries = await provider.readdirWithTypes(path);
6394
+ return { entries };
6395
+ } catch (err) {
6396
+ return { entries: [], error: toSessionFsError(err) };
6397
+ }
6398
+ },
6399
+ rm: async ({ path, recursive, force }) => {
6400
+ try {
6401
+ await provider.rm(path, recursive ?? false, force ?? false);
6402
+ return void 0;
6403
+ } catch (err) {
6404
+ return toSessionFsError(err);
6405
+ }
6406
+ },
6407
+ rename: async ({ src, dest }) => {
6408
+ try {
6409
+ await provider.rename(src, dest);
6410
+ return void 0;
6411
+ } catch (err) {
6412
+ return toSessionFsError(err);
6413
+ }
6414
+ }
6415
+ };
6416
+ }
6417
+ function toSessionFsError(err) {
6418
+ const e = err;
6419
+ const code = e.code === "ENOENT" ? "ENOENT" : "UNKNOWN";
6420
+ return { code, message: e.message ?? String(err) };
6421
+ }
6422
+ var init_sessionFsProvider = __esm({
6423
+ "node_modules/@github/copilot-sdk/dist/sessionFsProvider.js"() {
6424
+ "use strict";
6425
+ }
6426
+ });
6427
+
6428
+ // node_modules/@github/copilot-sdk/dist/types.js
6429
+ var approveAll, defaultJoinSessionPermissionHandler;
6430
+ var init_types3 = __esm({
6431
+ "node_modules/@github/copilot-sdk/dist/types.js"() {
6432
+ "use strict";
6433
+ init_sessionFsProvider();
6434
+ approveAll = () => ({ kind: "approve-once" });
6435
+ defaultJoinSessionPermissionHandler = () => ({
6436
+ kind: "no-result"
6437
+ });
6438
+ }
6439
+ });
6440
+
5991
6441
  // node_modules/@github/copilot-sdk/dist/client.js
5992
6442
  import { spawn } from "child_process";
5993
6443
  import { randomUUID } from "crypto";
@@ -6062,9 +6512,12 @@ var init_client = __esm({
6062
6512
  init_rpc();
6063
6513
  init_sdkProtocolVersion();
6064
6514
  init_session();
6515
+ init_sessionFsProvider();
6065
6516
  init_telemetry();
6517
+ init_types3();
6066
6518
  MIN_PROTOCOL_VERSION = 2;
6067
- CopilotClient = class {
6519
+ CopilotClient = class _CopilotClient {
6520
+ cliStartTimeout = null;
6068
6521
  cliProcess = null;
6069
6522
  connection = null;
6070
6523
  socket = null;
@@ -6087,6 +6540,8 @@ var init_client = __esm({
6087
6540
  processExitPromise = null;
6088
6541
  // Rejects when CLI process exits
6089
6542
  negotiatedProtocolVersion = null;
6543
+ /** Connection-level session filesystem config, set via constructor option. */
6544
+ sessionFsConfig = null;
6090
6545
  /**
6091
6546
  * Typed server-scoped RPC methods.
6092
6547
  * @throws Error if the client is not connected
@@ -6130,11 +6585,14 @@ var init_client = __esm({
6130
6585
  "isChildProcess must be used in conjunction with useStdio and not with cliUrl"
6131
6586
  );
6132
6587
  }
6133
- if (options.cliUrl && (options.githubToken || options.useLoggedInUser !== void 0)) {
6588
+ if (options.cliUrl && (options.gitHubToken || options.useLoggedInUser !== void 0)) {
6134
6589
  throw new Error(
6135
- "githubToken and useLoggedInUser cannot be used with cliUrl (external server manages its own auth)"
6590
+ "gitHubToken and useLoggedInUser cannot be used with cliUrl (external server manages its own auth)"
6136
6591
  );
6137
6592
  }
6593
+ if (options.sessionFs) {
6594
+ this.validateSessionFsConfig(options.sessionFs);
6595
+ }
6138
6596
  if (options.cliUrl) {
6139
6597
  const { host, port } = this.parseCliUrl(options.cliUrl);
6140
6598
  this.actualHost = host;
@@ -6146,8 +6604,10 @@ var init_client = __esm({
6146
6604
  }
6147
6605
  this.onListModels = options.onListModels;
6148
6606
  this.onGetTraceContext = options.onGetTraceContext;
6607
+ this.sessionFsConfig = options.sessionFs ?? null;
6608
+ const effectiveEnv = options.env ?? process.env;
6149
6609
  this.options = {
6150
- cliPath: options.cliUrl ? void 0 : options.cliPath || getBundledCliPath(),
6610
+ cliPath: options.cliUrl ? void 0 : options.cliPath || effectiveEnv.COPILOT_CLI_PATH || getBundledCliPath(),
6151
6611
  cliArgs: options.cliArgs ?? [],
6152
6612
  cwd: options.cwd ?? process.cwd(),
6153
6613
  port: options.port || 0,
@@ -6158,11 +6618,12 @@ var init_client = __esm({
6158
6618
  logLevel: options.logLevel || "debug",
6159
6619
  autoStart: options.autoStart ?? true,
6160
6620
  autoRestart: false,
6161
- env: options.env ?? process.env,
6162
- githubToken: options.githubToken,
6163
- // Default useLoggedInUser to false when githubToken is provided, otherwise true
6164
- useLoggedInUser: options.useLoggedInUser ?? (options.githubToken ? false : true),
6165
- telemetry: options.telemetry
6621
+ env: effectiveEnv,
6622
+ gitHubToken: options.gitHubToken,
6623
+ // Default useLoggedInUser to false when gitHubToken is provided, otherwise true
6624
+ useLoggedInUser: options.useLoggedInUser ?? (options.gitHubToken ? false : true),
6625
+ telemetry: options.telemetry,
6626
+ sessionIdleTimeoutSeconds: options.sessionIdleTimeoutSeconds ?? 0
6166
6627
  };
6167
6628
  }
6168
6629
  /**
@@ -6187,6 +6648,17 @@ var init_client = __esm({
6187
6648
  }
6188
6649
  return { host, port };
6189
6650
  }
6651
+ validateSessionFsConfig(config2) {
6652
+ if (!config2.initialCwd) {
6653
+ throw new Error("sessionFs.initialCwd is required");
6654
+ }
6655
+ if (!config2.sessionStatePath) {
6656
+ throw new Error("sessionFs.sessionStatePath is required");
6657
+ }
6658
+ if (config2.conventions !== "windows" && config2.conventions !== "posix") {
6659
+ throw new Error("sessionFs.conventions must be either 'windows' or 'posix'");
6660
+ }
6661
+ }
6190
6662
  /**
6191
6663
  * Starts the CLI server and establishes a connection.
6192
6664
  *
@@ -6216,6 +6688,13 @@ var init_client = __esm({
6216
6688
  }
6217
6689
  await this.connectToServer();
6218
6690
  await this.verifyProtocolVersion();
6691
+ if (this.sessionFsConfig) {
6692
+ await this.connection.sendRequest("sessionFs.setProvider", {
6693
+ initialCwd: this.sessionFsConfig.initialCwd,
6694
+ sessionStatePath: this.sessionFsConfig.sessionStatePath,
6695
+ conventions: this.sessionFsConfig.conventions
6696
+ });
6697
+ }
6219
6698
  this.state = "connected";
6220
6699
  } catch (error) {
6221
6700
  this.state = "error";
@@ -6310,6 +6789,10 @@ var init_client = __esm({
6310
6789
  }
6311
6790
  this.cliProcess = null;
6312
6791
  }
6792
+ if (this.cliStartTimeout) {
6793
+ clearTimeout(this.cliStartTimeout);
6794
+ this.cliStartTimeout = null;
6795
+ }
6313
6796
  this.state = "disconnected";
6314
6797
  this.actualPort = null;
6315
6798
  this.stderrBuffer = "";
@@ -6367,6 +6850,10 @@ var init_client = __esm({
6367
6850
  }
6368
6851
  this.cliProcess = null;
6369
6852
  }
6853
+ if (this.cliStartTimeout) {
6854
+ clearTimeout(this.cliStartTimeout);
6855
+ this.cliStartTimeout = null;
6856
+ }
6370
6857
  this.state = "disconnected";
6371
6858
  this.actualPort = null;
6372
6859
  this.stderrBuffer = "";
@@ -6422,10 +6909,14 @@ var init_client = __esm({
6422
6909
  this.onGetTraceContext
6423
6910
  );
6424
6911
  session.registerTools(config2.tools);
6912
+ session.registerCommands(config2.commands);
6425
6913
  session.registerPermissionHandler(config2.onPermissionRequest);
6426
6914
  if (config2.onUserInputRequest) {
6427
6915
  session.registerUserInputHandler(config2.onUserInputRequest);
6428
6916
  }
6917
+ if (config2.onElicitationRequest) {
6918
+ session.registerElicitationHandler(config2.onElicitationRequest);
6919
+ }
6429
6920
  if (config2.hooks) {
6430
6921
  session.registerHooks(config2.hooks);
6431
6922
  }
@@ -6439,6 +6930,17 @@ var init_client = __esm({
6439
6930
  session.on(config2.onEvent);
6440
6931
  }
6441
6932
  this.sessions.set(sessionId, session);
6933
+ if (this.sessionFsConfig) {
6934
+ if (config2.createSessionFsHandler) {
6935
+ session.clientSessionApis.sessionFs = createSessionFsAdapter(
6936
+ config2.createSessionFsHandler(session)
6937
+ );
6938
+ } else {
6939
+ throw new Error(
6940
+ "createSessionFsHandler is required in session config when sessionFs is enabled in client options."
6941
+ );
6942
+ }
6943
+ }
6442
6944
  try {
6443
6945
  const response = await this.connection.sendRequest("session.create", {
6444
6946
  ...await getTraceContext(this.onGetTraceContext),
@@ -6453,26 +6955,37 @@ var init_client = __esm({
6453
6955
  overridesBuiltInTool: tool.overridesBuiltInTool,
6454
6956
  skipPermission: tool.skipPermission
6455
6957
  })),
6958
+ commands: config2.commands?.map((cmd) => ({
6959
+ name: cmd.name,
6960
+ description: cmd.description
6961
+ })),
6456
6962
  systemMessage: wireSystemMessage,
6457
6963
  availableTools: config2.availableTools,
6458
6964
  excludedTools: config2.excludedTools,
6459
6965
  provider: config2.provider,
6966
+ modelCapabilities: config2.modelCapabilities,
6460
6967
  requestPermission: true,
6461
6968
  requestUserInput: !!config2.onUserInputRequest,
6969
+ requestElicitation: !!config2.onElicitationRequest,
6462
6970
  hooks: !!(config2.hooks && Object.values(config2.hooks).some(Boolean)),
6463
6971
  workingDirectory: config2.workingDirectory,
6464
6972
  streaming: config2.streaming,
6973
+ includeSubAgentStreamingEvents: config2.includeSubAgentStreamingEvents ?? true,
6465
6974
  mcpServers: config2.mcpServers,
6466
6975
  envValueMode: "direct",
6467
6976
  customAgents: config2.customAgents,
6977
+ defaultAgent: config2.defaultAgent,
6468
6978
  agent: config2.agent,
6469
6979
  configDir: config2.configDir,
6980
+ enableConfigDiscovery: config2.enableConfigDiscovery,
6470
6981
  skillDirectories: config2.skillDirectories,
6471
6982
  disabledSkills: config2.disabledSkills,
6472
- infiniteSessions: config2.infiniteSessions
6983
+ infiniteSessions: config2.infiniteSessions,
6984
+ gitHubToken: config2.gitHubToken
6473
6985
  });
6474
- const { workspacePath } = response;
6986
+ const { workspacePath, capabilities } = response;
6475
6987
  session["_workspacePath"] = workspacePath;
6988
+ session.setCapabilities(capabilities);
6476
6989
  } catch (e) {
6477
6990
  this.sessions.delete(sessionId);
6478
6991
  throw e;
@@ -6523,10 +7036,14 @@ var init_client = __esm({
6523
7036
  this.onGetTraceContext
6524
7037
  );
6525
7038
  session.registerTools(config2.tools);
7039
+ session.registerCommands(config2.commands);
6526
7040
  session.registerPermissionHandler(config2.onPermissionRequest);
6527
7041
  if (config2.onUserInputRequest) {
6528
7042
  session.registerUserInputHandler(config2.onUserInputRequest);
6529
7043
  }
7044
+ if (config2.onElicitationRequest) {
7045
+ session.registerElicitationHandler(config2.onElicitationRequest);
7046
+ }
6530
7047
  if (config2.hooks) {
6531
7048
  session.registerHooks(config2.hooks);
6532
7049
  }
@@ -6540,6 +7057,17 @@ var init_client = __esm({
6540
7057
  session.on(config2.onEvent);
6541
7058
  }
6542
7059
  this.sessions.set(sessionId, session);
7060
+ if (this.sessionFsConfig) {
7061
+ if (config2.createSessionFsHandler) {
7062
+ session.clientSessionApis.sessionFs = createSessionFsAdapter(
7063
+ config2.createSessionFsHandler(session)
7064
+ );
7065
+ } else {
7066
+ throw new Error(
7067
+ "createSessionFsHandler is required in session config when sessionFs is enabled in client options."
7068
+ );
7069
+ }
7070
+ }
6543
7071
  try {
6544
7072
  const response = await this.connection.sendRequest("session.resume", {
6545
7073
  ...await getTraceContext(this.onGetTraceContext),
@@ -6557,24 +7085,35 @@ var init_client = __esm({
6557
7085
  overridesBuiltInTool: tool.overridesBuiltInTool,
6558
7086
  skipPermission: tool.skipPermission
6559
7087
  })),
7088
+ commands: config2.commands?.map((cmd) => ({
7089
+ name: cmd.name,
7090
+ description: cmd.description
7091
+ })),
6560
7092
  provider: config2.provider,
6561
- requestPermission: true,
7093
+ modelCapabilities: config2.modelCapabilities,
7094
+ requestPermission: config2.onPermissionRequest !== defaultJoinSessionPermissionHandler,
6562
7095
  requestUserInput: !!config2.onUserInputRequest,
7096
+ requestElicitation: !!config2.onElicitationRequest,
6563
7097
  hooks: !!(config2.hooks && Object.values(config2.hooks).some(Boolean)),
6564
7098
  workingDirectory: config2.workingDirectory,
6565
7099
  configDir: config2.configDir,
7100
+ enableConfigDiscovery: config2.enableConfigDiscovery,
6566
7101
  streaming: config2.streaming,
7102
+ includeSubAgentStreamingEvents: config2.includeSubAgentStreamingEvents ?? true,
6567
7103
  mcpServers: config2.mcpServers,
6568
7104
  envValueMode: "direct",
6569
7105
  customAgents: config2.customAgents,
7106
+ defaultAgent: config2.defaultAgent,
6570
7107
  agent: config2.agent,
6571
7108
  skillDirectories: config2.skillDirectories,
6572
7109
  disabledSkills: config2.disabledSkills,
6573
7110
  infiniteSessions: config2.infiniteSessions,
6574
- disableResume: config2.disableResume
7111
+ disableResume: config2.disableResume,
7112
+ gitHubToken: config2.gitHubToken
6575
7113
  });
6576
- const { workspacePath } = response;
7114
+ const { workspacePath, capabilities } = response;
6577
7115
  session["_workspacePath"] = workspacePath;
7116
+ session.setCapabilities(capabilities);
6578
7117
  } catch (e) {
6579
7118
  this.sessions.delete(sessionId);
6580
7119
  throw e;
@@ -6667,6 +7206,22 @@ var init_client = __esm({
6667
7206
  const result = await this.connection.sendRequest("models.list", {});
6668
7207
  const response = result;
6669
7208
  models = response.models;
7209
+ for (const model of models) {
7210
+ const m = model;
7211
+ if (!m.capabilities) {
7212
+ m.capabilities = {
7213
+ supports: {},
7214
+ limits: { max_context_window_tokens: 0 }
7215
+ };
7216
+ } else {
7217
+ if (!m.capabilities.supports) m.capabilities.supports = {};
7218
+ if (!m.capabilities.limits) {
7219
+ m.capabilities.limits = { max_context_window_tokens: 0 };
7220
+ } else if (m.capabilities.limits.max_context_window_tokens === void 0) {
7221
+ m.capabilities.limits.max_context_window_tokens = 0;
7222
+ }
7223
+ }
7224
+ }
6670
7225
  }
6671
7226
  this.modelsCache = [...models];
6672
7227
  return [...models];
@@ -6770,16 +7325,50 @@ var init_client = __esm({
6770
7325
  if (!this.connection) {
6771
7326
  throw new Error("Client not connected");
6772
7327
  }
6773
- const response = await this.connection.sendRequest("session.list", { filter });
7328
+ const response = await this.connection.sendRequest("session.list", {
7329
+ filter
7330
+ });
6774
7331
  const { sessions } = response;
6775
- return sessions.map((s) => ({
6776
- sessionId: s.sessionId,
6777
- startTime: new Date(s.startTime),
6778
- modifiedTime: new Date(s.modifiedTime),
6779
- summary: s.summary,
6780
- isRemote: s.isRemote,
6781
- context: s.context
6782
- }));
7332
+ return sessions.map(_CopilotClient.toSessionMetadata);
7333
+ }
7334
+ /**
7335
+ * Gets metadata for a specific session by ID.
7336
+ *
7337
+ * This provides an efficient O(1) lookup of a single session's metadata
7338
+ * instead of listing all sessions. Returns undefined if the session is not found.
7339
+ *
7340
+ * @param sessionId - The ID of the session to look up
7341
+ * @returns A promise that resolves with the session metadata, or undefined if not found
7342
+ * @throws Error if the client is not connected
7343
+ *
7344
+ * @example
7345
+ * ```typescript
7346
+ * const metadata = await client.getSessionMetadata("session-123");
7347
+ * if (metadata) {
7348
+ * console.log(`Session started at: ${metadata.startTime}`);
7349
+ * }
7350
+ * ```
7351
+ */
7352
+ async getSessionMetadata(sessionId) {
7353
+ if (!this.connection) {
7354
+ throw new Error("Client not connected");
7355
+ }
7356
+ const response = await this.connection.sendRequest("session.getMetadata", { sessionId });
7357
+ const { session } = response;
7358
+ if (!session) {
7359
+ return void 0;
7360
+ }
7361
+ return _CopilotClient.toSessionMetadata(session);
7362
+ }
7363
+ static toSessionMetadata(raw) {
7364
+ return {
7365
+ sessionId: raw.sessionId,
7366
+ startTime: new Date(raw.startTime),
7367
+ modifiedTime: new Date(raw.modifiedTime),
7368
+ summary: raw.summary,
7369
+ isRemote: raw.isRemote,
7370
+ context: raw.context
7371
+ };
6783
7372
  }
6784
7373
  /**
6785
7374
  * Gets the foreground session ID in TUI+server mode.
@@ -6870,16 +7459,22 @@ var init_client = __esm({
6870
7459
  } else if (this.options.port > 0) {
6871
7460
  args.push("--port", this.options.port.toString());
6872
7461
  }
6873
- if (this.options.githubToken) {
7462
+ if (this.options.gitHubToken) {
6874
7463
  args.push("--auth-token-env", "COPILOT_SDK_AUTH_TOKEN");
6875
7464
  }
6876
7465
  if (!this.options.useLoggedInUser) {
6877
7466
  args.push("--no-auto-login");
6878
7467
  }
7468
+ if (this.options.sessionIdleTimeoutSeconds !== void 0 && this.options.sessionIdleTimeoutSeconds > 0) {
7469
+ args.push(
7470
+ "--session-idle-timeout",
7471
+ this.options.sessionIdleTimeoutSeconds.toString()
7472
+ );
7473
+ }
6879
7474
  const envWithoutNodeDebug = { ...this.options.env };
6880
7475
  delete envWithoutNodeDebug.NODE_DEBUG;
6881
- if (this.options.githubToken) {
6882
- envWithoutNodeDebug.COPILOT_SDK_AUTH_TOKEN = this.options.githubToken;
7476
+ if (this.options.gitHubToken) {
7477
+ envWithoutNodeDebug.COPILOT_SDK_AUTH_TOKEN = this.options.gitHubToken;
6883
7478
  }
6884
7479
  if (!this.options.cliPath) {
6885
7480
  throw new Error(
@@ -7003,7 +7598,7 @@ stderr: ${stderrOutput}`
7003
7598
  }
7004
7599
  }
7005
7600
  });
7006
- setTimeout(() => {
7601
+ this.cliStartTimeout = setTimeout(() => {
7007
7602
  if (!resolved) {
7008
7603
  resolved = true;
7009
7604
  reject(new Error("Timeout waiting for CLI server to start"));
@@ -7109,6 +7704,12 @@ stderr: ${stderrOutput}`
7109
7704
  "systemMessage.transform",
7110
7705
  async (params) => await this.handleSystemMessageTransform(params)
7111
7706
  );
7707
+ const sessions = this.sessions;
7708
+ registerClientSessionApiHandlers(this.connection, (sessionId) => {
7709
+ const session = sessions.get(sessionId);
7710
+ if (!session) throw new Error(`No session found for sessionId: ${sessionId}`);
7711
+ return session.clientSessionApis;
7712
+ });
7112
7713
  this.connection.onClose(() => {
7113
7714
  this.state = "disconnected";
7114
7715
  });
@@ -7254,7 +7855,7 @@ stderr: ${stderrOutput}`
7254
7855
  }
7255
7856
  return {
7256
7857
  result: {
7257
- kind: "denied-no-approval-rule-and-could-not-request-from-user"
7858
+ kind: "user-not-available"
7258
7859
  }
7259
7860
  };
7260
7861
  }
@@ -7285,15 +7886,6 @@ stderr: ${stderrOutput}`
7285
7886
  }
7286
7887
  });
7287
7888
 
7288
- // node_modules/@github/copilot-sdk/dist/types.js
7289
- var approveAll;
7290
- var init_types3 = __esm({
7291
- "node_modules/@github/copilot-sdk/dist/types.js"() {
7292
- "use strict";
7293
- approveAll = () => ({ kind: "approved" });
7294
- }
7295
- });
7296
-
7297
7889
  // node_modules/@github/copilot-sdk/dist/index.js
7298
7890
  var init_dist = __esm({
7299
7891
  "node_modules/@github/copilot-sdk/dist/index.js"() {