contribute-now 0.10.0-patch.647137a → 0.10.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.
- package/dist/cli.js +356 -1244
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -6427,44 +6427,18 @@ function createServerRpc(connection) {
|
|
|
6427
6427
|
return {
|
|
6428
6428
|
ping: async (params) => connection.sendRequest("ping", params),
|
|
6429
6429
|
models: {
|
|
6430
|
-
list: async (
|
|
6430
|
+
list: async () => connection.sendRequest("models.list", {})
|
|
6431
6431
|
},
|
|
6432
6432
|
tools: {
|
|
6433
6433
|
list: async (params) => connection.sendRequest("tools.list", params)
|
|
6434
6434
|
},
|
|
6435
6435
|
account: {
|
|
6436
|
-
getQuota: async (
|
|
6437
|
-
},
|
|
6438
|
-
mcp: {
|
|
6439
|
-
config: {
|
|
6440
|
-
list: async () => connection.sendRequest("mcp.config.list", {}),
|
|
6441
|
-
add: async (params) => connection.sendRequest("mcp.config.add", params),
|
|
6442
|
-
update: async (params) => connection.sendRequest("mcp.config.update", params),
|
|
6443
|
-
remove: async (params) => connection.sendRequest("mcp.config.remove", params),
|
|
6444
|
-
enable: async (params) => connection.sendRequest("mcp.config.enable", params),
|
|
6445
|
-
disable: async (params) => connection.sendRequest("mcp.config.disable", params)
|
|
6446
|
-
},
|
|
6447
|
-
discover: async (params) => connection.sendRequest("mcp.discover", params)
|
|
6448
|
-
},
|
|
6449
|
-
skills: {
|
|
6450
|
-
config: {
|
|
6451
|
-
setDisabledSkills: async (params) => connection.sendRequest("skills.config.setDisabledSkills", params)
|
|
6452
|
-
},
|
|
6453
|
-
discover: async (params) => connection.sendRequest("skills.discover", params)
|
|
6454
|
-
},
|
|
6455
|
-
sessionFs: {
|
|
6456
|
-
setProvider: async (params) => connection.sendRequest("sessionFs.setProvider", params)
|
|
6457
|
-
},
|
|
6458
|
-
sessions: {
|
|
6459
|
-
fork: async (params) => connection.sendRequest("sessions.fork", params)
|
|
6436
|
+
getQuota: async () => connection.sendRequest("account.getQuota", {})
|
|
6460
6437
|
}
|
|
6461
6438
|
};
|
|
6462
6439
|
}
|
|
6463
6440
|
function createSessionRpc(connection, sessionId) {
|
|
6464
6441
|
return {
|
|
6465
|
-
auth: {
|
|
6466
|
-
getStatus: async () => connection.sendRequest("session.auth.getStatus", { sessionId })
|
|
6467
|
-
},
|
|
6468
6442
|
model: {
|
|
6469
6443
|
getCurrent: async () => connection.sendRequest("session.model.getCurrent", { sessionId }),
|
|
6470
6444
|
switchTo: async (params) => connection.sendRequest("session.model.switchTo", { sessionId, ...params })
|
|
@@ -6473,849 +6447,231 @@ function createSessionRpc(connection, sessionId) {
|
|
|
6473
6447
|
get: async () => connection.sendRequest("session.mode.get", { sessionId }),
|
|
6474
6448
|
set: async (params) => connection.sendRequest("session.mode.set", { sessionId, ...params })
|
|
6475
6449
|
},
|
|
6476
|
-
name: {
|
|
6477
|
-
get: async () => connection.sendRequest("session.name.get", { sessionId }),
|
|
6478
|
-
set: async (params) => connection.sendRequest("session.name.set", { sessionId, ...params })
|
|
6479
|
-
},
|
|
6480
6450
|
plan: {
|
|
6481
6451
|
read: async () => connection.sendRequest("session.plan.read", { sessionId }),
|
|
6482
6452
|
update: async (params) => connection.sendRequest("session.plan.update", { sessionId, ...params }),
|
|
6483
6453
|
delete: async () => connection.sendRequest("session.plan.delete", { sessionId })
|
|
6484
6454
|
},
|
|
6485
|
-
|
|
6486
|
-
|
|
6487
|
-
|
|
6488
|
-
|
|
6489
|
-
createFile: async (params) => connection.sendRequest("session.workspaces.createFile", { sessionId, ...params })
|
|
6490
|
-
},
|
|
6491
|
-
instructions: {
|
|
6492
|
-
getSources: async () => connection.sendRequest("session.instructions.getSources", { sessionId })
|
|
6455
|
+
workspace: {
|
|
6456
|
+
listFiles: async () => connection.sendRequest("session.workspace.listFiles", { sessionId }),
|
|
6457
|
+
readFile: async (params) => connection.sendRequest("session.workspace.readFile", { sessionId, ...params }),
|
|
6458
|
+
createFile: async (params) => connection.sendRequest("session.workspace.createFile", { sessionId, ...params })
|
|
6493
6459
|
},
|
|
6494
6460
|
fleet: {
|
|
6495
6461
|
start: async (params) => connection.sendRequest("session.fleet.start", { sessionId, ...params })
|
|
6496
|
-
},
|
|
6497
|
-
agent: {
|
|
6498
|
-
list: async () => connection.sendRequest("session.agent.list", { sessionId }),
|
|
6499
|
-
getCurrent: async () => connection.sendRequest("session.agent.getCurrent", { sessionId }),
|
|
6500
|
-
select: async (params) => connection.sendRequest("session.agent.select", { sessionId, ...params }),
|
|
6501
|
-
deselect: async () => connection.sendRequest("session.agent.deselect", { sessionId }),
|
|
6502
|
-
reload: async () => connection.sendRequest("session.agent.reload", { sessionId })
|
|
6503
|
-
},
|
|
6504
|
-
skills: {
|
|
6505
|
-
list: async () => connection.sendRequest("session.skills.list", { sessionId }),
|
|
6506
|
-
enable: async (params) => connection.sendRequest("session.skills.enable", { sessionId, ...params }),
|
|
6507
|
-
disable: async (params) => connection.sendRequest("session.skills.disable", { sessionId, ...params }),
|
|
6508
|
-
reload: async () => connection.sendRequest("session.skills.reload", { sessionId })
|
|
6509
|
-
},
|
|
6510
|
-
mcp: {
|
|
6511
|
-
list: async () => connection.sendRequest("session.mcp.list", { sessionId }),
|
|
6512
|
-
enable: async (params) => connection.sendRequest("session.mcp.enable", { sessionId, ...params }),
|
|
6513
|
-
disable: async (params) => connection.sendRequest("session.mcp.disable", { sessionId, ...params }),
|
|
6514
|
-
reload: async () => connection.sendRequest("session.mcp.reload", { sessionId }),
|
|
6515
|
-
oauth: {
|
|
6516
|
-
login: async (params) => connection.sendRequest("session.mcp.oauth.login", { sessionId, ...params })
|
|
6517
|
-
}
|
|
6518
|
-
},
|
|
6519
|
-
plugins: {
|
|
6520
|
-
list: async () => connection.sendRequest("session.plugins.list", { sessionId })
|
|
6521
|
-
},
|
|
6522
|
-
extensions: {
|
|
6523
|
-
list: async () => connection.sendRequest("session.extensions.list", { sessionId }),
|
|
6524
|
-
enable: async (params) => connection.sendRequest("session.extensions.enable", { sessionId, ...params }),
|
|
6525
|
-
disable: async (params) => connection.sendRequest("session.extensions.disable", { sessionId, ...params }),
|
|
6526
|
-
reload: async () => connection.sendRequest("session.extensions.reload", { sessionId })
|
|
6527
|
-
},
|
|
6528
|
-
tools: {
|
|
6529
|
-
handlePendingToolCall: async (params) => connection.sendRequest("session.tools.handlePendingToolCall", { sessionId, ...params })
|
|
6530
|
-
},
|
|
6531
|
-
commands: {
|
|
6532
|
-
handlePendingCommand: async (params) => connection.sendRequest("session.commands.handlePendingCommand", { sessionId, ...params })
|
|
6533
|
-
},
|
|
6534
|
-
ui: {
|
|
6535
|
-
elicitation: async (params) => connection.sendRequest("session.ui.elicitation", { sessionId, ...params }),
|
|
6536
|
-
handlePendingElicitation: async (params) => connection.sendRequest("session.ui.handlePendingElicitation", { sessionId, ...params })
|
|
6537
|
-
},
|
|
6538
|
-
permissions: {
|
|
6539
|
-
handlePendingPermissionRequest: async (params) => connection.sendRequest("session.permissions.handlePendingPermissionRequest", { sessionId, ...params }),
|
|
6540
|
-
setApproveAll: async (params) => connection.sendRequest("session.permissions.setApproveAll", { sessionId, ...params }),
|
|
6541
|
-
resetSessionApprovals: async () => connection.sendRequest("session.permissions.resetSessionApprovals", { sessionId })
|
|
6542
|
-
},
|
|
6543
|
-
log: async (params) => connection.sendRequest("session.log", { sessionId, ...params }),
|
|
6544
|
-
shell: {
|
|
6545
|
-
exec: async (params) => connection.sendRequest("session.shell.exec", { sessionId, ...params }),
|
|
6546
|
-
kill: async (params) => connection.sendRequest("session.shell.kill", { sessionId, ...params })
|
|
6547
|
-
},
|
|
6548
|
-
history: {
|
|
6549
|
-
compact: async () => connection.sendRequest("session.history.compact", { sessionId }),
|
|
6550
|
-
truncate: async (params) => connection.sendRequest("session.history.truncate", { sessionId, ...params })
|
|
6551
|
-
},
|
|
6552
|
-
usage: {
|
|
6553
|
-
getMetrics: async () => connection.sendRequest("session.usage.getMetrics", { sessionId })
|
|
6554
6462
|
}
|
|
6555
6463
|
};
|
|
6556
6464
|
}
|
|
6557
|
-
function registerClientSessionApiHandlers(connection, getHandlers) {
|
|
6558
|
-
connection.onRequest("sessionFs.readFile", async (params) => {
|
|
6559
|
-
const handler = getHandlers(params.sessionId).sessionFs;
|
|
6560
|
-
if (!handler)
|
|
6561
|
-
throw new Error(`No sessionFs handler registered for session: ${params.sessionId}`);
|
|
6562
|
-
return handler.readFile(params);
|
|
6563
|
-
});
|
|
6564
|
-
connection.onRequest("sessionFs.writeFile", async (params) => {
|
|
6565
|
-
const handler = getHandlers(params.sessionId).sessionFs;
|
|
6566
|
-
if (!handler)
|
|
6567
|
-
throw new Error(`No sessionFs handler registered for session: ${params.sessionId}`);
|
|
6568
|
-
return handler.writeFile(params);
|
|
6569
|
-
});
|
|
6570
|
-
connection.onRequest("sessionFs.appendFile", async (params) => {
|
|
6571
|
-
const handler = getHandlers(params.sessionId).sessionFs;
|
|
6572
|
-
if (!handler)
|
|
6573
|
-
throw new Error(`No sessionFs handler registered for session: ${params.sessionId}`);
|
|
6574
|
-
return handler.appendFile(params);
|
|
6575
|
-
});
|
|
6576
|
-
connection.onRequest("sessionFs.exists", async (params) => {
|
|
6577
|
-
const handler = getHandlers(params.sessionId).sessionFs;
|
|
6578
|
-
if (!handler)
|
|
6579
|
-
throw new Error(`No sessionFs handler registered for session: ${params.sessionId}`);
|
|
6580
|
-
return handler.exists(params);
|
|
6581
|
-
});
|
|
6582
|
-
connection.onRequest("sessionFs.stat", async (params) => {
|
|
6583
|
-
const handler = getHandlers(params.sessionId).sessionFs;
|
|
6584
|
-
if (!handler)
|
|
6585
|
-
throw new Error(`No sessionFs handler registered for session: ${params.sessionId}`);
|
|
6586
|
-
return handler.stat(params);
|
|
6587
|
-
});
|
|
6588
|
-
connection.onRequest("sessionFs.mkdir", async (params) => {
|
|
6589
|
-
const handler = getHandlers(params.sessionId).sessionFs;
|
|
6590
|
-
if (!handler)
|
|
6591
|
-
throw new Error(`No sessionFs handler registered for session: ${params.sessionId}`);
|
|
6592
|
-
return handler.mkdir(params);
|
|
6593
|
-
});
|
|
6594
|
-
connection.onRequest("sessionFs.readdir", async (params) => {
|
|
6595
|
-
const handler = getHandlers(params.sessionId).sessionFs;
|
|
6596
|
-
if (!handler)
|
|
6597
|
-
throw new Error(`No sessionFs handler registered for session: ${params.sessionId}`);
|
|
6598
|
-
return handler.readdir(params);
|
|
6599
|
-
});
|
|
6600
|
-
connection.onRequest("sessionFs.readdirWithTypes", async (params) => {
|
|
6601
|
-
const handler = getHandlers(params.sessionId).sessionFs;
|
|
6602
|
-
if (!handler)
|
|
6603
|
-
throw new Error(`No sessionFs handler registered for session: ${params.sessionId}`);
|
|
6604
|
-
return handler.readdirWithTypes(params);
|
|
6605
|
-
});
|
|
6606
|
-
connection.onRequest("sessionFs.rm", async (params) => {
|
|
6607
|
-
const handler = getHandlers(params.sessionId).sessionFs;
|
|
6608
|
-
if (!handler)
|
|
6609
|
-
throw new Error(`No sessionFs handler registered for session: ${params.sessionId}`);
|
|
6610
|
-
return handler.rm(params);
|
|
6611
|
-
});
|
|
6612
|
-
connection.onRequest("sessionFs.rename", async (params) => {
|
|
6613
|
-
const handler = getHandlers(params.sessionId).sessionFs;
|
|
6614
|
-
if (!handler)
|
|
6615
|
-
throw new Error(`No sessionFs handler registered for session: ${params.sessionId}`);
|
|
6616
|
-
return handler.rename(params);
|
|
6617
|
-
});
|
|
6618
|
-
}
|
|
6619
6465
|
var init_rpc = () => {};
|
|
6620
6466
|
|
|
6621
6467
|
// node_modules/@github/copilot-sdk/dist/sdkProtocolVersion.js
|
|
6622
6468
|
function getSdkProtocolVersion() {
|
|
6623
6469
|
return SDK_PROTOCOL_VERSION;
|
|
6624
6470
|
}
|
|
6625
|
-
var SDK_PROTOCOL_VERSION =
|
|
6471
|
+
var SDK_PROTOCOL_VERSION = 2;
|
|
6626
6472
|
var init_sdkProtocolVersion = () => {};
|
|
6627
6473
|
|
|
6628
|
-
// node_modules/@github/copilot-sdk/dist/telemetry.js
|
|
6629
|
-
async function getTraceContext(provider) {
|
|
6630
|
-
if (!provider)
|
|
6631
|
-
return {};
|
|
6632
|
-
try {
|
|
6633
|
-
return await provider() ?? {};
|
|
6634
|
-
} catch {
|
|
6635
|
-
return {};
|
|
6636
|
-
}
|
|
6637
|
-
}
|
|
6638
|
-
var init_telemetry = () => {};
|
|
6639
|
-
|
|
6640
6474
|
// node_modules/@github/copilot-sdk/dist/session.js
|
|
6641
|
-
|
|
6642
|
-
|
|
6643
|
-
|
|
6644
|
-
|
|
6645
|
-
|
|
6646
|
-
|
|
6475
|
+
class CopilotSession {
|
|
6476
|
+
constructor(sessionId, connection, _workspacePath) {
|
|
6477
|
+
this.sessionId = sessionId;
|
|
6478
|
+
this.connection = connection;
|
|
6479
|
+
this._workspacePath = _workspacePath;
|
|
6480
|
+
}
|
|
6481
|
+
eventHandlers = /* @__PURE__ */ new Set;
|
|
6482
|
+
typedEventHandlers = /* @__PURE__ */ new Map;
|
|
6483
|
+
toolHandlers = /* @__PURE__ */ new Map;
|
|
6484
|
+
permissionHandler;
|
|
6485
|
+
userInputHandler;
|
|
6486
|
+
hooks;
|
|
6487
|
+
_rpc = null;
|
|
6488
|
+
get rpc() {
|
|
6489
|
+
if (!this._rpc) {
|
|
6490
|
+
this._rpc = createSessionRpc(this.connection, this.sessionId);
|
|
6491
|
+
}
|
|
6492
|
+
return this._rpc;
|
|
6647
6493
|
}
|
|
6648
|
-
|
|
6649
|
-
return
|
|
6494
|
+
get workspacePath() {
|
|
6495
|
+
return this._workspacePath;
|
|
6650
6496
|
}
|
|
6651
|
-
|
|
6652
|
-
"
|
|
6653
|
-
|
|
6654
|
-
|
|
6655
|
-
|
|
6656
|
-
|
|
6657
|
-
|
|
6658
|
-
|
|
6659
|
-
}
|
|
6660
|
-
|
|
6661
|
-
|
|
6662
|
-
|
|
6663
|
-
|
|
6664
|
-
|
|
6665
|
-
|
|
6666
|
-
|
|
6667
|
-
|
|
6668
|
-
|
|
6669
|
-
|
|
6670
|
-
|
|
6671
|
-
|
|
6672
|
-
|
|
6673
|
-
|
|
6674
|
-
|
|
6675
|
-
|
|
6676
|
-
|
|
6677
|
-
|
|
6678
|
-
|
|
6679
|
-
|
|
6680
|
-
|
|
6681
|
-
|
|
6682
|
-
|
|
6683
|
-
|
|
6684
|
-
|
|
6685
|
-
get rpc() {
|
|
6686
|
-
if (!this._rpc) {
|
|
6687
|
-
this._rpc = createSessionRpc(this.connection, this.sessionId);
|
|
6688
|
-
}
|
|
6689
|
-
return this._rpc;
|
|
6690
|
-
}
|
|
6691
|
-
get workspacePath() {
|
|
6692
|
-
return this._workspacePath;
|
|
6693
|
-
}
|
|
6694
|
-
get capabilities() {
|
|
6695
|
-
return this._capabilities;
|
|
6696
|
-
}
|
|
6697
|
-
get ui() {
|
|
6698
|
-
return {
|
|
6699
|
-
elicitation: (params) => this._elicitation(params),
|
|
6700
|
-
confirm: (message) => this._confirm(message),
|
|
6701
|
-
select: (message, options) => this._select(message, options),
|
|
6702
|
-
input: (message, options) => this._input(message, options)
|
|
6703
|
-
};
|
|
6704
|
-
}
|
|
6705
|
-
async send(options) {
|
|
6706
|
-
const response = await this.connection.sendRequest("session.send", {
|
|
6707
|
-
...await getTraceContext(this.traceContextProvider),
|
|
6708
|
-
sessionId: this.sessionId,
|
|
6709
|
-
prompt: options.prompt,
|
|
6710
|
-
attachments: options.attachments,
|
|
6711
|
-
mode: options.mode,
|
|
6712
|
-
requestHeaders: options.requestHeaders
|
|
6713
|
-
});
|
|
6714
|
-
return response.messageId;
|
|
6715
|
-
}
|
|
6716
|
-
async sendAndWait(options, timeout) {
|
|
6717
|
-
const effectiveTimeout = timeout ?? 60000;
|
|
6718
|
-
let resolveIdle;
|
|
6719
|
-
let rejectWithError;
|
|
6720
|
-
const idlePromise = new Promise((resolve4, reject) => {
|
|
6721
|
-
resolveIdle = resolve4;
|
|
6722
|
-
rejectWithError = reject;
|
|
6723
|
-
});
|
|
6724
|
-
let lastAssistantMessage;
|
|
6725
|
-
const unsubscribe = this.on((event) => {
|
|
6726
|
-
if (event.type === "assistant.message") {
|
|
6727
|
-
lastAssistantMessage = event;
|
|
6728
|
-
} else if (event.type === "session.idle") {
|
|
6729
|
-
resolveIdle();
|
|
6730
|
-
} else if (event.type === "session.error") {
|
|
6731
|
-
const error2 = new Error(event.data.message);
|
|
6732
|
-
error2.stack = event.data.stack;
|
|
6733
|
-
rejectWithError(error2);
|
|
6734
|
-
}
|
|
6497
|
+
async send(options) {
|
|
6498
|
+
const response = await this.connection.sendRequest("session.send", {
|
|
6499
|
+
sessionId: this.sessionId,
|
|
6500
|
+
prompt: options.prompt,
|
|
6501
|
+
attachments: options.attachments,
|
|
6502
|
+
mode: options.mode
|
|
6503
|
+
});
|
|
6504
|
+
return response.messageId;
|
|
6505
|
+
}
|
|
6506
|
+
async sendAndWait(options, timeout) {
|
|
6507
|
+
const effectiveTimeout = timeout ?? 60000;
|
|
6508
|
+
let resolveIdle;
|
|
6509
|
+
let rejectWithError;
|
|
6510
|
+
const idlePromise = new Promise((resolve4, reject) => {
|
|
6511
|
+
resolveIdle = resolve4;
|
|
6512
|
+
rejectWithError = reject;
|
|
6513
|
+
});
|
|
6514
|
+
let lastAssistantMessage;
|
|
6515
|
+
const unsubscribe = this.on((event) => {
|
|
6516
|
+
if (event.type === "assistant.message") {
|
|
6517
|
+
lastAssistantMessage = event;
|
|
6518
|
+
} else if (event.type === "session.idle") {
|
|
6519
|
+
resolveIdle();
|
|
6520
|
+
} else if (event.type === "session.error") {
|
|
6521
|
+
const error2 = new Error(event.data.message);
|
|
6522
|
+
error2.stack = event.data.stack;
|
|
6523
|
+
rejectWithError(error2);
|
|
6524
|
+
}
|
|
6525
|
+
});
|
|
6526
|
+
let timeoutId;
|
|
6527
|
+
try {
|
|
6528
|
+
await this.send(options);
|
|
6529
|
+
const timeoutPromise = new Promise((_4, reject) => {
|
|
6530
|
+
timeoutId = setTimeout(() => reject(new Error(`Timeout after ${effectiveTimeout}ms waiting for session.idle`)), effectiveTimeout);
|
|
6735
6531
|
});
|
|
6736
|
-
|
|
6737
|
-
|
|
6738
|
-
|
|
6739
|
-
|
|
6740
|
-
|
|
6741
|
-
});
|
|
6742
|
-
await Promise.race([idlePromise, timeoutPromise]);
|
|
6743
|
-
return lastAssistantMessage;
|
|
6744
|
-
} finally {
|
|
6745
|
-
if (timeoutId !== undefined) {
|
|
6746
|
-
clearTimeout(timeoutId);
|
|
6747
|
-
}
|
|
6748
|
-
unsubscribe();
|
|
6532
|
+
await Promise.race([idlePromise, timeoutPromise]);
|
|
6533
|
+
return lastAssistantMessage;
|
|
6534
|
+
} finally {
|
|
6535
|
+
if (timeoutId !== undefined) {
|
|
6536
|
+
clearTimeout(timeoutId);
|
|
6749
6537
|
}
|
|
6538
|
+
unsubscribe();
|
|
6750
6539
|
}
|
|
6751
|
-
|
|
6752
|
-
|
|
6753
|
-
|
|
6754
|
-
|
|
6755
|
-
|
|
6756
|
-
|
|
6757
|
-
const storedHandler = handler;
|
|
6758
|
-
this.typedEventHandlers.get(eventType).add(storedHandler);
|
|
6759
|
-
return () => {
|
|
6760
|
-
const handlers = this.typedEventHandlers.get(eventType);
|
|
6761
|
-
if (handlers) {
|
|
6762
|
-
handlers.delete(storedHandler);
|
|
6763
|
-
}
|
|
6764
|
-
};
|
|
6540
|
+
}
|
|
6541
|
+
on(eventTypeOrHandler, handler) {
|
|
6542
|
+
if (typeof eventTypeOrHandler === "string" && handler) {
|
|
6543
|
+
const eventType = eventTypeOrHandler;
|
|
6544
|
+
if (!this.typedEventHandlers.has(eventType)) {
|
|
6545
|
+
this.typedEventHandlers.set(eventType, /* @__PURE__ */ new Set);
|
|
6765
6546
|
}
|
|
6766
|
-
const
|
|
6767
|
-
this.
|
|
6547
|
+
const storedHandler = handler;
|
|
6548
|
+
this.typedEventHandlers.get(eventType).add(storedHandler);
|
|
6768
6549
|
return () => {
|
|
6769
|
-
this.
|
|
6550
|
+
const handlers = this.typedEventHandlers.get(eventType);
|
|
6551
|
+
if (handlers) {
|
|
6552
|
+
handlers.delete(storedHandler);
|
|
6553
|
+
}
|
|
6770
6554
|
};
|
|
6771
6555
|
}
|
|
6772
|
-
|
|
6773
|
-
|
|
6774
|
-
|
|
6775
|
-
|
|
6776
|
-
|
|
6777
|
-
|
|
6778
|
-
|
|
6779
|
-
|
|
6780
|
-
|
|
6781
|
-
|
|
6782
|
-
for (const handler of this.eventHandlers) {
|
|
6556
|
+
const wildcardHandler = eventTypeOrHandler;
|
|
6557
|
+
this.eventHandlers.add(wildcardHandler);
|
|
6558
|
+
return () => {
|
|
6559
|
+
this.eventHandlers.delete(wildcardHandler);
|
|
6560
|
+
};
|
|
6561
|
+
}
|
|
6562
|
+
_dispatchEvent(event) {
|
|
6563
|
+
const typedHandlers = this.typedEventHandlers.get(event.type);
|
|
6564
|
+
if (typedHandlers) {
|
|
6565
|
+
for (const handler of typedHandlers) {
|
|
6783
6566
|
try {
|
|
6784
6567
|
handler(event);
|
|
6785
6568
|
} catch (_error) {}
|
|
6786
6569
|
}
|
|
6787
6570
|
}
|
|
6788
|
-
|
|
6789
|
-
if (event.type === "external_tool.requested") {
|
|
6790
|
-
const { requestId, toolName } = event.data;
|
|
6791
|
-
const args = event.data.arguments;
|
|
6792
|
-
const toolCallId = event.data.toolCallId;
|
|
6793
|
-
const traceparent = event.data.traceparent;
|
|
6794
|
-
const tracestate = event.data.tracestate;
|
|
6795
|
-
const handler = this.toolHandlers.get(toolName);
|
|
6796
|
-
if (handler) {
|
|
6797
|
-
this._executeToolAndRespond(requestId, toolName, toolCallId, args, handler, traceparent, tracestate);
|
|
6798
|
-
}
|
|
6799
|
-
} else if (event.type === "permission.requested") {
|
|
6800
|
-
const { requestId, permissionRequest, resolvedByHook } = event.data;
|
|
6801
|
-
if (resolvedByHook) {
|
|
6802
|
-
return;
|
|
6803
|
-
}
|
|
6804
|
-
if (this.permissionHandler) {
|
|
6805
|
-
this._executePermissionAndRespond(requestId, permissionRequest);
|
|
6806
|
-
}
|
|
6807
|
-
} else if (event.type === "command.execute") {
|
|
6808
|
-
const { requestId, commandName, command, args } = event.data;
|
|
6809
|
-
this._executeCommandAndRespond(requestId, commandName, command, args);
|
|
6810
|
-
} else if (event.type === "elicitation.requested") {
|
|
6811
|
-
if (this.elicitationHandler) {
|
|
6812
|
-
const { message, requestedSchema, mode, elicitationSource, url, requestId } = event.data;
|
|
6813
|
-
this._handleElicitationRequest({
|
|
6814
|
-
sessionId: this.sessionId,
|
|
6815
|
-
message,
|
|
6816
|
-
requestedSchema,
|
|
6817
|
-
mode,
|
|
6818
|
-
elicitationSource,
|
|
6819
|
-
url
|
|
6820
|
-
}, requestId);
|
|
6821
|
-
}
|
|
6822
|
-
} else if (event.type === "capabilities.changed") {
|
|
6823
|
-
this._capabilities = { ...this._capabilities, ...event.data };
|
|
6824
|
-
}
|
|
6825
|
-
}
|
|
6826
|
-
async _executeToolAndRespond(requestId, toolName, toolCallId, args, handler, traceparent, tracestate) {
|
|
6827
|
-
try {
|
|
6828
|
-
const rawResult = await handler(args, {
|
|
6829
|
-
sessionId: this.sessionId,
|
|
6830
|
-
toolCallId,
|
|
6831
|
-
toolName,
|
|
6832
|
-
arguments: args,
|
|
6833
|
-
traceparent,
|
|
6834
|
-
tracestate
|
|
6835
|
-
});
|
|
6836
|
-
let result;
|
|
6837
|
-
if (rawResult == null) {
|
|
6838
|
-
result = "";
|
|
6839
|
-
} else if (typeof rawResult === "string") {
|
|
6840
|
-
result = rawResult;
|
|
6841
|
-
} else if (isToolResultObject(rawResult)) {
|
|
6842
|
-
result = rawResult;
|
|
6843
|
-
} else {
|
|
6844
|
-
result = JSON.stringify(rawResult);
|
|
6845
|
-
}
|
|
6846
|
-
await this.rpc.tools.handlePendingToolCall({ requestId, result });
|
|
6847
|
-
} catch (error2) {
|
|
6848
|
-
const message = error2 instanceof Error ? error2.message : String(error2);
|
|
6849
|
-
try {
|
|
6850
|
-
await this.rpc.tools.handlePendingToolCall({ requestId, error: message });
|
|
6851
|
-
} catch (rpcError) {
|
|
6852
|
-
if (!(rpcError instanceof import_node.ConnectionError || rpcError instanceof import_node.ResponseError)) {
|
|
6853
|
-
throw rpcError;
|
|
6854
|
-
}
|
|
6855
|
-
}
|
|
6856
|
-
}
|
|
6857
|
-
}
|
|
6858
|
-
async _executePermissionAndRespond(requestId, permissionRequest) {
|
|
6571
|
+
for (const handler of this.eventHandlers) {
|
|
6859
6572
|
try {
|
|
6860
|
-
|
|
6861
|
-
|
|
6862
|
-
});
|
|
6863
|
-
if (result.kind === "no-result") {
|
|
6864
|
-
return;
|
|
6865
|
-
}
|
|
6866
|
-
await this.rpc.permissions.handlePendingPermissionRequest({ requestId, result });
|
|
6867
|
-
} catch (_error) {
|
|
6868
|
-
try {
|
|
6869
|
-
await this.rpc.permissions.handlePendingPermissionRequest({
|
|
6870
|
-
requestId,
|
|
6871
|
-
result: {
|
|
6872
|
-
kind: "user-not-available"
|
|
6873
|
-
}
|
|
6874
|
-
});
|
|
6875
|
-
} catch (rpcError) {
|
|
6876
|
-
if (!(rpcError instanceof import_node.ConnectionError || rpcError instanceof import_node.ResponseError)) {
|
|
6877
|
-
throw rpcError;
|
|
6878
|
-
}
|
|
6879
|
-
}
|
|
6880
|
-
}
|
|
6881
|
-
}
|
|
6882
|
-
async _executeCommandAndRespond(requestId, commandName, command, args) {
|
|
6883
|
-
const handler = this.commandHandlers.get(commandName);
|
|
6884
|
-
if (!handler) {
|
|
6885
|
-
try {
|
|
6886
|
-
await this.rpc.commands.handlePendingCommand({
|
|
6887
|
-
requestId,
|
|
6888
|
-
error: `Unknown command: ${commandName}`
|
|
6889
|
-
});
|
|
6890
|
-
} catch (rpcError) {
|
|
6891
|
-
if (!(rpcError instanceof import_node.ConnectionError || rpcError instanceof import_node.ResponseError)) {
|
|
6892
|
-
throw rpcError;
|
|
6893
|
-
}
|
|
6894
|
-
}
|
|
6895
|
-
return;
|
|
6896
|
-
}
|
|
6897
|
-
try {
|
|
6898
|
-
await handler({ sessionId: this.sessionId, command, commandName, args });
|
|
6899
|
-
await this.rpc.commands.handlePendingCommand({ requestId });
|
|
6900
|
-
} catch (error2) {
|
|
6901
|
-
const message = error2 instanceof Error ? error2.message : String(error2);
|
|
6902
|
-
try {
|
|
6903
|
-
await this.rpc.commands.handlePendingCommand({ requestId, error: message });
|
|
6904
|
-
} catch (rpcError) {
|
|
6905
|
-
if (!(rpcError instanceof import_node.ConnectionError || rpcError instanceof import_node.ResponseError)) {
|
|
6906
|
-
throw rpcError;
|
|
6907
|
-
}
|
|
6908
|
-
}
|
|
6909
|
-
}
|
|
6910
|
-
}
|
|
6911
|
-
registerTools(tools) {
|
|
6912
|
-
this.toolHandlers.clear();
|
|
6913
|
-
if (!tools) {
|
|
6914
|
-
return;
|
|
6915
|
-
}
|
|
6916
|
-
for (const tool of tools) {
|
|
6917
|
-
this.toolHandlers.set(tool.name, tool.handler);
|
|
6918
|
-
}
|
|
6919
|
-
}
|
|
6920
|
-
getToolHandler(name) {
|
|
6921
|
-
return this.toolHandlers.get(name);
|
|
6922
|
-
}
|
|
6923
|
-
registerCommands(commands) {
|
|
6924
|
-
this.commandHandlers.clear();
|
|
6925
|
-
if (!commands) {
|
|
6926
|
-
return;
|
|
6927
|
-
}
|
|
6928
|
-
for (const cmd of commands) {
|
|
6929
|
-
this.commandHandlers.set(cmd.name, cmd.handler);
|
|
6930
|
-
}
|
|
6931
|
-
}
|
|
6932
|
-
registerElicitationHandler(handler) {
|
|
6933
|
-
this.elicitationHandler = handler;
|
|
6934
|
-
}
|
|
6935
|
-
async _handleElicitationRequest(context, requestId) {
|
|
6936
|
-
if (!this.elicitationHandler) {
|
|
6937
|
-
return;
|
|
6938
|
-
}
|
|
6939
|
-
try {
|
|
6940
|
-
const result = await this.elicitationHandler(context);
|
|
6941
|
-
await this.rpc.ui.handlePendingElicitation({ requestId, result });
|
|
6942
|
-
} catch {
|
|
6943
|
-
try {
|
|
6944
|
-
await this.rpc.ui.handlePendingElicitation({
|
|
6945
|
-
requestId,
|
|
6946
|
-
result: { action: "cancel" }
|
|
6947
|
-
});
|
|
6948
|
-
} catch (rpcError) {
|
|
6949
|
-
if (!(rpcError instanceof import_node.ConnectionError || rpcError instanceof import_node.ResponseError)) {
|
|
6950
|
-
throw rpcError;
|
|
6951
|
-
}
|
|
6952
|
-
}
|
|
6953
|
-
}
|
|
6954
|
-
}
|
|
6955
|
-
setCapabilities(capabilities) {
|
|
6956
|
-
this._capabilities = capabilities ?? {};
|
|
6957
|
-
}
|
|
6958
|
-
assertElicitation() {
|
|
6959
|
-
if (!this._capabilities.ui?.elicitation) {
|
|
6960
|
-
throw new Error("Elicitation is not supported by the host. Check session.capabilities.ui?.elicitation before calling UI methods.");
|
|
6961
|
-
}
|
|
6962
|
-
}
|
|
6963
|
-
async _elicitation(params) {
|
|
6964
|
-
this.assertElicitation();
|
|
6965
|
-
return this.rpc.ui.elicitation({
|
|
6966
|
-
message: params.message,
|
|
6967
|
-
requestedSchema: params.requestedSchema
|
|
6968
|
-
});
|
|
6969
|
-
}
|
|
6970
|
-
async _confirm(message) {
|
|
6971
|
-
this.assertElicitation();
|
|
6972
|
-
const result = await this.rpc.ui.elicitation({
|
|
6973
|
-
message,
|
|
6974
|
-
requestedSchema: {
|
|
6975
|
-
type: "object",
|
|
6976
|
-
properties: {
|
|
6977
|
-
confirmed: { type: "boolean", default: true }
|
|
6978
|
-
},
|
|
6979
|
-
required: ["confirmed"]
|
|
6980
|
-
}
|
|
6981
|
-
});
|
|
6982
|
-
return result.action === "accept" && result.content?.confirmed === true;
|
|
6983
|
-
}
|
|
6984
|
-
async _select(message, options) {
|
|
6985
|
-
this.assertElicitation();
|
|
6986
|
-
const result = await this.rpc.ui.elicitation({
|
|
6987
|
-
message,
|
|
6988
|
-
requestedSchema: {
|
|
6989
|
-
type: "object",
|
|
6990
|
-
properties: {
|
|
6991
|
-
selection: { type: "string", enum: options }
|
|
6992
|
-
},
|
|
6993
|
-
required: ["selection"]
|
|
6994
|
-
}
|
|
6995
|
-
});
|
|
6996
|
-
if (result.action === "accept" && result.content?.selection != null) {
|
|
6997
|
-
return result.content.selection;
|
|
6998
|
-
}
|
|
6999
|
-
return null;
|
|
7000
|
-
}
|
|
7001
|
-
async _input(message, options) {
|
|
7002
|
-
this.assertElicitation();
|
|
7003
|
-
const field = { type: "string" };
|
|
7004
|
-
if (options?.title)
|
|
7005
|
-
field.title = options.title;
|
|
7006
|
-
if (options?.description)
|
|
7007
|
-
field.description = options.description;
|
|
7008
|
-
if (options?.minLength != null)
|
|
7009
|
-
field.minLength = options.minLength;
|
|
7010
|
-
if (options?.maxLength != null)
|
|
7011
|
-
field.maxLength = options.maxLength;
|
|
7012
|
-
if (options?.format)
|
|
7013
|
-
field.format = options.format;
|
|
7014
|
-
if (options?.default != null)
|
|
7015
|
-
field.default = options.default;
|
|
7016
|
-
const result = await this.rpc.ui.elicitation({
|
|
7017
|
-
message,
|
|
7018
|
-
requestedSchema: {
|
|
7019
|
-
type: "object",
|
|
7020
|
-
properties: {
|
|
7021
|
-
value: field
|
|
7022
|
-
},
|
|
7023
|
-
required: ["value"]
|
|
7024
|
-
}
|
|
7025
|
-
});
|
|
7026
|
-
if (result.action === "accept" && result.content?.value != null) {
|
|
7027
|
-
return result.content.value;
|
|
7028
|
-
}
|
|
7029
|
-
return null;
|
|
7030
|
-
}
|
|
7031
|
-
registerPermissionHandler(handler) {
|
|
7032
|
-
this.permissionHandler = handler;
|
|
7033
|
-
}
|
|
7034
|
-
registerUserInputHandler(handler) {
|
|
7035
|
-
this.userInputHandler = handler;
|
|
7036
|
-
}
|
|
7037
|
-
registerHooks(hooks) {
|
|
7038
|
-
this.hooks = hooks;
|
|
7039
|
-
}
|
|
7040
|
-
registerTransformCallbacks(callbacks) {
|
|
7041
|
-
this.transformCallbacks = callbacks;
|
|
7042
|
-
}
|
|
7043
|
-
async _handleSystemMessageTransform(sections) {
|
|
7044
|
-
const result = {};
|
|
7045
|
-
for (const [sectionId, { content }] of Object.entries(sections)) {
|
|
7046
|
-
const callback = this.transformCallbacks?.get(sectionId);
|
|
7047
|
-
if (callback) {
|
|
7048
|
-
try {
|
|
7049
|
-
const transformed = await callback(content);
|
|
7050
|
-
result[sectionId] = { content: transformed };
|
|
7051
|
-
} catch (_error) {
|
|
7052
|
-
result[sectionId] = { content };
|
|
7053
|
-
}
|
|
7054
|
-
} else {
|
|
7055
|
-
result[sectionId] = { content };
|
|
7056
|
-
}
|
|
7057
|
-
}
|
|
7058
|
-
return { sections: result };
|
|
7059
|
-
}
|
|
7060
|
-
async _handlePermissionRequestV2(request) {
|
|
7061
|
-
if (!this.permissionHandler) {
|
|
7062
|
-
return { kind: "user-not-available" };
|
|
7063
|
-
}
|
|
7064
|
-
try {
|
|
7065
|
-
const result = await this.permissionHandler(request, {
|
|
7066
|
-
sessionId: this.sessionId
|
|
7067
|
-
});
|
|
7068
|
-
if (result.kind === "no-result") {
|
|
7069
|
-
throw new Error(NO_RESULT_PERMISSION_V2_ERROR);
|
|
7070
|
-
}
|
|
7071
|
-
return result;
|
|
7072
|
-
} catch (error2) {
|
|
7073
|
-
if (error2 instanceof Error && error2.message === NO_RESULT_PERMISSION_V2_ERROR) {
|
|
7074
|
-
throw error2;
|
|
7075
|
-
}
|
|
7076
|
-
return { kind: "user-not-available" };
|
|
7077
|
-
}
|
|
6573
|
+
handler(event);
|
|
6574
|
+
} catch (_error) {}
|
|
7078
6575
|
}
|
|
7079
|
-
|
|
7080
|
-
|
|
7081
|
-
|
|
7082
|
-
|
|
7083
|
-
|
|
7084
|
-
const result = await this.userInputHandler(request, {
|
|
7085
|
-
sessionId: this.sessionId
|
|
7086
|
-
});
|
|
7087
|
-
return result;
|
|
7088
|
-
} catch (error2) {
|
|
7089
|
-
throw error2;
|
|
7090
|
-
}
|
|
6576
|
+
}
|
|
6577
|
+
registerTools(tools) {
|
|
6578
|
+
this.toolHandlers.clear();
|
|
6579
|
+
if (!tools) {
|
|
6580
|
+
return;
|
|
7091
6581
|
}
|
|
7092
|
-
|
|
7093
|
-
|
|
7094
|
-
return;
|
|
7095
|
-
}
|
|
7096
|
-
const handlerMap = {
|
|
7097
|
-
preToolUse: this.hooks.onPreToolUse,
|
|
7098
|
-
postToolUse: this.hooks.onPostToolUse,
|
|
7099
|
-
userPromptSubmitted: this.hooks.onUserPromptSubmitted,
|
|
7100
|
-
sessionStart: this.hooks.onSessionStart,
|
|
7101
|
-
sessionEnd: this.hooks.onSessionEnd,
|
|
7102
|
-
errorOccurred: this.hooks.onErrorOccurred
|
|
7103
|
-
};
|
|
7104
|
-
const handler = handlerMap[hookType];
|
|
7105
|
-
if (!handler) {
|
|
7106
|
-
return;
|
|
7107
|
-
}
|
|
7108
|
-
try {
|
|
7109
|
-
const result = await handler(input, { sessionId: this.sessionId });
|
|
7110
|
-
return result;
|
|
7111
|
-
} catch (_error) {
|
|
7112
|
-
return;
|
|
7113
|
-
}
|
|
6582
|
+
for (const tool of tools) {
|
|
6583
|
+
this.toolHandlers.set(tool.name, tool.handler);
|
|
7114
6584
|
}
|
|
7115
|
-
|
|
7116
|
-
|
|
7117
|
-
|
|
7118
|
-
|
|
7119
|
-
|
|
6585
|
+
}
|
|
6586
|
+
getToolHandler(name) {
|
|
6587
|
+
return this.toolHandlers.get(name);
|
|
6588
|
+
}
|
|
6589
|
+
registerPermissionHandler(handler) {
|
|
6590
|
+
this.permissionHandler = handler;
|
|
6591
|
+
}
|
|
6592
|
+
registerUserInputHandler(handler) {
|
|
6593
|
+
this.userInputHandler = handler;
|
|
6594
|
+
}
|
|
6595
|
+
registerHooks(hooks) {
|
|
6596
|
+
this.hooks = hooks;
|
|
6597
|
+
}
|
|
6598
|
+
async _handlePermissionRequest(request) {
|
|
6599
|
+
if (!this.permissionHandler) {
|
|
6600
|
+
return { kind: "denied-no-approval-rule-and-could-not-request-from-user" };
|
|
7120
6601
|
}
|
|
7121
|
-
|
|
7122
|
-
await this.
|
|
6602
|
+
try {
|
|
6603
|
+
const result = await this.permissionHandler(request, {
|
|
7123
6604
|
sessionId: this.sessionId
|
|
7124
6605
|
});
|
|
7125
|
-
|
|
7126
|
-
|
|
7127
|
-
|
|
7128
|
-
this.permissionHandler = undefined;
|
|
7129
|
-
}
|
|
7130
|
-
async destroy() {
|
|
7131
|
-
return this.disconnect();
|
|
6606
|
+
return result;
|
|
6607
|
+
} catch (_error) {
|
|
6608
|
+
return { kind: "denied-no-approval-rule-and-could-not-request-from-user" };
|
|
7132
6609
|
}
|
|
7133
|
-
|
|
7134
|
-
|
|
6610
|
+
}
|
|
6611
|
+
async _handleUserInputRequest(request) {
|
|
6612
|
+
if (!this.userInputHandler) {
|
|
6613
|
+
throw new Error("User input requested but no handler registered");
|
|
7135
6614
|
}
|
|
7136
|
-
|
|
7137
|
-
await this.
|
|
6615
|
+
try {
|
|
6616
|
+
const result = await this.userInputHandler(request, {
|
|
7138
6617
|
sessionId: this.sessionId
|
|
7139
6618
|
});
|
|
6619
|
+
return result;
|
|
6620
|
+
} catch (error2) {
|
|
6621
|
+
throw error2;
|
|
7140
6622
|
}
|
|
7141
|
-
|
|
7142
|
-
|
|
7143
|
-
|
|
7144
|
-
|
|
7145
|
-
await this.rpc.log({ message, ...options });
|
|
6623
|
+
}
|
|
6624
|
+
async _handleHooksInvoke(hookType, input) {
|
|
6625
|
+
if (!this.hooks) {
|
|
6626
|
+
return;
|
|
7146
6627
|
}
|
|
7147
|
-
|
|
7148
|
-
|
|
7149
|
-
|
|
7150
|
-
|
|
7151
|
-
|
|
7152
|
-
|
|
7153
|
-
|
|
7154
|
-
|
|
7155
|
-
|
|
7156
|
-
|
|
7157
|
-
|
|
7158
|
-
return { content: "", error: toSessionFsError(err) };
|
|
7159
|
-
}
|
|
7160
|
-
},
|
|
7161
|
-
writeFile: async ({ path: path2, content, mode }) => {
|
|
7162
|
-
try {
|
|
7163
|
-
await provider.writeFile(path2, content, mode);
|
|
7164
|
-
return;
|
|
7165
|
-
} catch (err) {
|
|
7166
|
-
return toSessionFsError(err);
|
|
7167
|
-
}
|
|
7168
|
-
},
|
|
7169
|
-
appendFile: async ({ path: path2, content, mode }) => {
|
|
7170
|
-
try {
|
|
7171
|
-
await provider.appendFile(path2, content, mode);
|
|
7172
|
-
return;
|
|
7173
|
-
} catch (err) {
|
|
7174
|
-
return toSessionFsError(err);
|
|
7175
|
-
}
|
|
7176
|
-
},
|
|
7177
|
-
exists: async ({ path: path2 }) => {
|
|
7178
|
-
try {
|
|
7179
|
-
return { exists: await provider.exists(path2) };
|
|
7180
|
-
} catch {
|
|
7181
|
-
return { exists: false };
|
|
7182
|
-
}
|
|
7183
|
-
},
|
|
7184
|
-
stat: async ({ path: path2 }) => {
|
|
7185
|
-
try {
|
|
7186
|
-
return await provider.stat(path2);
|
|
7187
|
-
} catch (err) {
|
|
7188
|
-
return {
|
|
7189
|
-
isFile: false,
|
|
7190
|
-
isDirectory: false,
|
|
7191
|
-
size: 0,
|
|
7192
|
-
mtime: (/* @__PURE__ */ new Date()).toISOString(),
|
|
7193
|
-
birthtime: (/* @__PURE__ */ new Date()).toISOString(),
|
|
7194
|
-
error: toSessionFsError(err)
|
|
7195
|
-
};
|
|
7196
|
-
}
|
|
7197
|
-
},
|
|
7198
|
-
mkdir: async ({ path: path2, recursive, mode }) => {
|
|
7199
|
-
try {
|
|
7200
|
-
await provider.mkdir(path2, recursive ?? false, mode);
|
|
7201
|
-
return;
|
|
7202
|
-
} catch (err) {
|
|
7203
|
-
return toSessionFsError(err);
|
|
7204
|
-
}
|
|
7205
|
-
},
|
|
7206
|
-
readdir: async ({ path: path2 }) => {
|
|
7207
|
-
try {
|
|
7208
|
-
const entries = await provider.readdir(path2);
|
|
7209
|
-
return { entries };
|
|
7210
|
-
} catch (err) {
|
|
7211
|
-
return { entries: [], error: toSessionFsError(err) };
|
|
7212
|
-
}
|
|
7213
|
-
},
|
|
7214
|
-
readdirWithTypes: async ({ path: path2 }) => {
|
|
7215
|
-
try {
|
|
7216
|
-
const entries = await provider.readdirWithTypes(path2);
|
|
7217
|
-
return { entries };
|
|
7218
|
-
} catch (err) {
|
|
7219
|
-
return { entries: [], error: toSessionFsError(err) };
|
|
7220
|
-
}
|
|
7221
|
-
},
|
|
7222
|
-
rm: async ({ path: path2, recursive, force }) => {
|
|
7223
|
-
try {
|
|
7224
|
-
await provider.rm(path2, recursive ?? false, force ?? false);
|
|
7225
|
-
return;
|
|
7226
|
-
} catch (err) {
|
|
7227
|
-
return toSessionFsError(err);
|
|
7228
|
-
}
|
|
7229
|
-
},
|
|
7230
|
-
rename: async ({ src: src2, dest }) => {
|
|
7231
|
-
try {
|
|
7232
|
-
await provider.rename(src2, dest);
|
|
7233
|
-
return;
|
|
7234
|
-
} catch (err) {
|
|
7235
|
-
return toSessionFsError(err);
|
|
7236
|
-
}
|
|
6628
|
+
const handlerMap = {
|
|
6629
|
+
preToolUse: this.hooks.onPreToolUse,
|
|
6630
|
+
postToolUse: this.hooks.onPostToolUse,
|
|
6631
|
+
userPromptSubmitted: this.hooks.onUserPromptSubmitted,
|
|
6632
|
+
sessionStart: this.hooks.onSessionStart,
|
|
6633
|
+
sessionEnd: this.hooks.onSessionEnd,
|
|
6634
|
+
errorOccurred: this.hooks.onErrorOccurred
|
|
6635
|
+
};
|
|
6636
|
+
const handler = handlerMap[hookType];
|
|
6637
|
+
if (!handler) {
|
|
6638
|
+
return;
|
|
7237
6639
|
}
|
|
7238
|
-
|
|
7239
|
-
}
|
|
7240
|
-
|
|
7241
|
-
|
|
7242
|
-
|
|
7243
|
-
return { code, message: e3.message ?? String(err) };
|
|
7244
|
-
}
|
|
7245
|
-
var init_sessionFsProvider = () => {};
|
|
7246
|
-
|
|
7247
|
-
// node_modules/@github/copilot-sdk/dist/types.js
|
|
7248
|
-
function convertMcpCallToolResult(callResult) {
|
|
7249
|
-
const textParts = [];
|
|
7250
|
-
const binaryResults = [];
|
|
7251
|
-
for (const block of callResult.content) {
|
|
7252
|
-
switch (block.type) {
|
|
7253
|
-
case "text":
|
|
7254
|
-
if (typeof block.text === "string") {
|
|
7255
|
-
textParts.push(block.text);
|
|
7256
|
-
}
|
|
7257
|
-
break;
|
|
7258
|
-
case "image":
|
|
7259
|
-
if (typeof block.data === "string" && block.data && typeof block.mimeType === "string") {
|
|
7260
|
-
binaryResults.push({
|
|
7261
|
-
data: block.data,
|
|
7262
|
-
mimeType: block.mimeType,
|
|
7263
|
-
type: "image"
|
|
7264
|
-
});
|
|
7265
|
-
}
|
|
7266
|
-
break;
|
|
7267
|
-
case "resource": {
|
|
7268
|
-
if (block.resource?.text) {
|
|
7269
|
-
textParts.push(block.resource.text);
|
|
7270
|
-
}
|
|
7271
|
-
if (block.resource?.blob) {
|
|
7272
|
-
binaryResults.push({
|
|
7273
|
-
data: block.resource.blob,
|
|
7274
|
-
mimeType: block.resource.mimeType ?? "application/octet-stream",
|
|
7275
|
-
type: "resource",
|
|
7276
|
-
description: block.resource.uri
|
|
7277
|
-
});
|
|
7278
|
-
}
|
|
7279
|
-
break;
|
|
7280
|
-
}
|
|
6640
|
+
try {
|
|
6641
|
+
const result = await handler(input, { sessionId: this.sessionId });
|
|
6642
|
+
return result;
|
|
6643
|
+
} catch (_error) {
|
|
6644
|
+
return;
|
|
7281
6645
|
}
|
|
7282
6646
|
}
|
|
7283
|
-
|
|
7284
|
-
|
|
7285
|
-
|
|
7286
|
-
|
|
7287
|
-
|
|
7288
|
-
}
|
|
7289
|
-
|
|
7290
|
-
|
|
7291
|
-
|
|
6647
|
+
async getMessages() {
|
|
6648
|
+
const response = await this.connection.sendRequest("session.getMessages", {
|
|
6649
|
+
sessionId: this.sessionId
|
|
6650
|
+
});
|
|
6651
|
+
return response.events;
|
|
6652
|
+
}
|
|
6653
|
+
async destroy() {
|
|
6654
|
+
await this.connection.sendRequest("session.destroy", {
|
|
6655
|
+
sessionId: this.sessionId
|
|
6656
|
+
});
|
|
6657
|
+
this.eventHandlers.clear();
|
|
6658
|
+
this.typedEventHandlers.clear();
|
|
6659
|
+
this.toolHandlers.clear();
|
|
6660
|
+
this.permissionHandler = undefined;
|
|
6661
|
+
}
|
|
6662
|
+
async abort() {
|
|
6663
|
+
await this.connection.sendRequest("session.abort", {
|
|
6664
|
+
sessionId: this.sessionId
|
|
6665
|
+
});
|
|
6666
|
+
}
|
|
7292
6667
|
}
|
|
7293
|
-
var
|
|
7294
|
-
|
|
7295
|
-
});
|
|
7296
|
-
var init_types2 = __esm(() => {
|
|
7297
|
-
init_sessionFsProvider();
|
|
7298
|
-
SYSTEM_PROMPT_SECTIONS = {
|
|
7299
|
-
identity: { description: "Agent identity preamble and mode statement" },
|
|
7300
|
-
tone: { description: "Response style, conciseness rules, output formatting preferences" },
|
|
7301
|
-
tool_efficiency: { description: "Tool usage patterns, parallel calling, batching guidelines" },
|
|
7302
|
-
environment_context: { description: "CWD, OS, git root, directory listing, available tools" },
|
|
7303
|
-
code_change_rules: { description: "Coding rules, linting/testing, ecosystem tools, style" },
|
|
7304
|
-
guidelines: { description: "Tips, behavioral best practices, behavioral guidelines" },
|
|
7305
|
-
safety: { description: "Environment limitations, prohibited actions, security policies" },
|
|
7306
|
-
tool_instructions: { description: "Per-tool usage instructions" },
|
|
7307
|
-
custom_instructions: { description: "Repository and organization custom instructions" },
|
|
7308
|
-
last_instructions: {
|
|
7309
|
-
description: "End-of-prompt instructions: parallel tool calling, persistence, task completion"
|
|
7310
|
-
}
|
|
7311
|
-
};
|
|
6668
|
+
var init_session = __esm(() => {
|
|
6669
|
+
init_rpc();
|
|
7312
6670
|
});
|
|
7313
6671
|
|
|
7314
6672
|
// node_modules/@github/copilot-sdk/dist/client.js
|
|
7315
6673
|
import { spawn } from "child_process";
|
|
7316
|
-
import { randomUUID } from "crypto";
|
|
7317
6674
|
import { existsSync as existsSync4 } from "fs";
|
|
7318
|
-
import { createRequire } from "module";
|
|
7319
6675
|
import { Socket } from "net";
|
|
7320
6676
|
import { dirname as dirname4, join as join4 } from "path";
|
|
7321
6677
|
import { fileURLToPath } from "url";
|
|
@@ -7330,31 +6686,6 @@ function toJsonSchema(parameters) {
|
|
|
7330
6686
|
}
|
|
7331
6687
|
return parameters;
|
|
7332
6688
|
}
|
|
7333
|
-
function extractTransformCallbacks(systemMessage) {
|
|
7334
|
-
if (!systemMessage || systemMessage.mode !== "customize" || !systemMessage.sections) {
|
|
7335
|
-
return { wirePayload: systemMessage, transformCallbacks: undefined };
|
|
7336
|
-
}
|
|
7337
|
-
const transformCallbacks = /* @__PURE__ */ new Map;
|
|
7338
|
-
const wireSections = {};
|
|
7339
|
-
for (const [sectionId, override] of Object.entries(systemMessage.sections)) {
|
|
7340
|
-
if (!override)
|
|
7341
|
-
continue;
|
|
7342
|
-
if (typeof override.action === "function") {
|
|
7343
|
-
transformCallbacks.set(sectionId, override.action);
|
|
7344
|
-
wireSections[sectionId] = { action: "transform" };
|
|
7345
|
-
} else {
|
|
7346
|
-
wireSections[sectionId] = { action: override.action, content: override.content };
|
|
7347
|
-
}
|
|
7348
|
-
}
|
|
7349
|
-
if (transformCallbacks.size === 0) {
|
|
7350
|
-
return { wirePayload: systemMessage, transformCallbacks: undefined };
|
|
7351
|
-
}
|
|
7352
|
-
const wirePayload = {
|
|
7353
|
-
...systemMessage,
|
|
7354
|
-
sections: wireSections
|
|
7355
|
-
};
|
|
7356
|
-
return { wirePayload, transformCallbacks };
|
|
7357
|
-
}
|
|
7358
6689
|
function getNodeExecPath() {
|
|
7359
6690
|
if (process.versions.bun) {
|
|
7360
6691
|
return "node";
|
|
@@ -7362,24 +6693,12 @@ function getNodeExecPath() {
|
|
|
7362
6693
|
return process.execPath;
|
|
7363
6694
|
}
|
|
7364
6695
|
function getBundledCliPath() {
|
|
7365
|
-
|
|
7366
|
-
|
|
7367
|
-
|
|
7368
|
-
return join4(dirname4(dirname4(sdkPath)), "index.js");
|
|
7369
|
-
}
|
|
7370
|
-
const req = createRequire(__filename);
|
|
7371
|
-
const searchPaths = req.resolve.paths("@github/copilot") ?? [];
|
|
7372
|
-
for (const base of searchPaths) {
|
|
7373
|
-
const candidate = join4(base, "@github", "copilot", "index.js");
|
|
7374
|
-
if (existsSync4(candidate)) {
|
|
7375
|
-
return candidate;
|
|
7376
|
-
}
|
|
7377
|
-
}
|
|
7378
|
-
throw new Error(`Could not find @github/copilot package. Searched ${searchPaths.length} paths. Ensure it is installed, or pass cliPath/cliUrl to CopilotClient.`);
|
|
6696
|
+
const sdkUrl = import.meta.resolve("@github/copilot/sdk");
|
|
6697
|
+
const sdkPath = fileURLToPath(sdkUrl);
|
|
6698
|
+
return join4(dirname4(dirname4(sdkPath)), "index.js");
|
|
7379
6699
|
}
|
|
7380
6700
|
|
|
7381
6701
|
class CopilotClient {
|
|
7382
|
-
cliStartTimeout = null;
|
|
7383
6702
|
cliProcess = null;
|
|
7384
6703
|
connection = null;
|
|
7385
6704
|
socket = null;
|
|
@@ -7391,16 +6710,12 @@ class CopilotClient {
|
|
|
7391
6710
|
options;
|
|
7392
6711
|
isExternalServer = false;
|
|
7393
6712
|
forceStopping = false;
|
|
7394
|
-
onListModels;
|
|
7395
|
-
onGetTraceContext;
|
|
7396
6713
|
modelsCache = null;
|
|
7397
6714
|
modelsCacheLock = Promise.resolve();
|
|
7398
6715
|
sessionLifecycleHandlers = /* @__PURE__ */ new Set;
|
|
7399
6716
|
typedLifecycleHandlers = /* @__PURE__ */ new Map;
|
|
7400
6717
|
_rpc = null;
|
|
7401
6718
|
processExitPromise = null;
|
|
7402
|
-
negotiatedProtocolVersion = null;
|
|
7403
|
-
sessionFsConfig = null;
|
|
7404
6719
|
get rpc() {
|
|
7405
6720
|
if (!this.connection) {
|
|
7406
6721
|
throw new Error("Client is not connected. Call start() first.");
|
|
@@ -7414,14 +6729,8 @@ class CopilotClient {
|
|
|
7414
6729
|
if (options.cliUrl && (options.useStdio === true || options.cliPath)) {
|
|
7415
6730
|
throw new Error("cliUrl is mutually exclusive with useStdio and cliPath");
|
|
7416
6731
|
}
|
|
7417
|
-
if (options.
|
|
7418
|
-
throw new Error("
|
|
7419
|
-
}
|
|
7420
|
-
if (options.cliUrl && (options.gitHubToken || options.useLoggedInUser !== undefined)) {
|
|
7421
|
-
throw new Error("gitHubToken and useLoggedInUser cannot be used with cliUrl (external server manages its own auth)");
|
|
7422
|
-
}
|
|
7423
|
-
if (options.sessionFs) {
|
|
7424
|
-
this.validateSessionFsConfig(options.sessionFs);
|
|
6732
|
+
if (options.cliUrl && (options.githubToken || options.useLoggedInUser !== undefined)) {
|
|
6733
|
+
throw new Error("githubToken and useLoggedInUser cannot be used with cliUrl (external server manages its own auth)");
|
|
7425
6734
|
}
|
|
7426
6735
|
if (options.cliUrl) {
|
|
7427
6736
|
const { host, port } = this.parseCliUrl(options.cliUrl);
|
|
@@ -7429,29 +6738,19 @@ class CopilotClient {
|
|
|
7429
6738
|
this.actualPort = port;
|
|
7430
6739
|
this.isExternalServer = true;
|
|
7431
6740
|
}
|
|
7432
|
-
if (options.isChildProcess) {
|
|
7433
|
-
this.isExternalServer = true;
|
|
7434
|
-
}
|
|
7435
|
-
this.onListModels = options.onListModels;
|
|
7436
|
-
this.onGetTraceContext = options.onGetTraceContext;
|
|
7437
|
-
this.sessionFsConfig = options.sessionFs ?? null;
|
|
7438
|
-
const effectiveEnv = options.env ?? process.env;
|
|
7439
6741
|
this.options = {
|
|
7440
|
-
cliPath: options.
|
|
6742
|
+
cliPath: options.cliPath || getBundledCliPath(),
|
|
7441
6743
|
cliArgs: options.cliArgs ?? [],
|
|
7442
6744
|
cwd: options.cwd ?? process.cwd(),
|
|
7443
6745
|
port: options.port || 0,
|
|
7444
6746
|
useStdio: options.cliUrl ? false : options.useStdio ?? true,
|
|
7445
|
-
isChildProcess: options.isChildProcess ?? false,
|
|
7446
6747
|
cliUrl: options.cliUrl,
|
|
7447
6748
|
logLevel: options.logLevel || "debug",
|
|
7448
6749
|
autoStart: options.autoStart ?? true,
|
|
7449
|
-
autoRestart:
|
|
7450
|
-
env:
|
|
7451
|
-
|
|
7452
|
-
useLoggedInUser: options.useLoggedInUser ?? (options.
|
|
7453
|
-
telemetry: options.telemetry,
|
|
7454
|
-
sessionIdleTimeoutSeconds: options.sessionIdleTimeoutSeconds ?? 0
|
|
6750
|
+
autoRestart: options.autoRestart ?? true,
|
|
6751
|
+
env: options.env ?? process.env,
|
|
6752
|
+
githubToken: options.githubToken,
|
|
6753
|
+
useLoggedInUser: options.useLoggedInUser ?? (options.githubToken ? false : true)
|
|
7455
6754
|
};
|
|
7456
6755
|
}
|
|
7457
6756
|
parseCliUrl(url) {
|
|
@@ -7470,17 +6769,6 @@ class CopilotClient {
|
|
|
7470
6769
|
}
|
|
7471
6770
|
return { host, port };
|
|
7472
6771
|
}
|
|
7473
|
-
validateSessionFsConfig(config) {
|
|
7474
|
-
if (!config.initialCwd) {
|
|
7475
|
-
throw new Error("sessionFs.initialCwd is required");
|
|
7476
|
-
}
|
|
7477
|
-
if (!config.sessionStatePath) {
|
|
7478
|
-
throw new Error("sessionFs.sessionStatePath is required");
|
|
7479
|
-
}
|
|
7480
|
-
if (config.conventions !== "windows" && config.conventions !== "posix") {
|
|
7481
|
-
throw new Error("sessionFs.conventions must be either 'windows' or 'posix'");
|
|
7482
|
-
}
|
|
7483
|
-
}
|
|
7484
6772
|
async start() {
|
|
7485
6773
|
if (this.state === "connected") {
|
|
7486
6774
|
return;
|
|
@@ -7492,13 +6780,6 @@ class CopilotClient {
|
|
|
7492
6780
|
}
|
|
7493
6781
|
await this.connectToServer();
|
|
7494
6782
|
await this.verifyProtocolVersion();
|
|
7495
|
-
if (this.sessionFsConfig) {
|
|
7496
|
-
await this.connection.sendRequest("sessionFs.setProvider", {
|
|
7497
|
-
initialCwd: this.sessionFsConfig.initialCwd,
|
|
7498
|
-
sessionStatePath: this.sessionFsConfig.sessionStatePath,
|
|
7499
|
-
conventions: this.sessionFsConfig.conventions
|
|
7500
|
-
});
|
|
7501
|
-
}
|
|
7502
6783
|
this.state = "connected";
|
|
7503
6784
|
} catch (error2) {
|
|
7504
6785
|
this.state = "error";
|
|
@@ -7512,7 +6793,7 @@ class CopilotClient {
|
|
|
7512
6793
|
let lastError = null;
|
|
7513
6794
|
for (let attempt = 1;attempt <= 3; attempt++) {
|
|
7514
6795
|
try {
|
|
7515
|
-
await session.
|
|
6796
|
+
await session.destroy();
|
|
7516
6797
|
lastError = null;
|
|
7517
6798
|
break;
|
|
7518
6799
|
} catch (error2) {
|
|
@@ -7524,7 +6805,7 @@ class CopilotClient {
|
|
|
7524
6805
|
}
|
|
7525
6806
|
}
|
|
7526
6807
|
if (lastError) {
|
|
7527
|
-
errors.push(new Error(`Failed to
|
|
6808
|
+
errors.push(new Error(`Failed to destroy session ${sessionId} after 3 attempts: ${lastError.message}`));
|
|
7528
6809
|
}
|
|
7529
6810
|
}
|
|
7530
6811
|
this.sessions.clear();
|
|
@@ -7554,10 +6835,6 @@ class CopilotClient {
|
|
|
7554
6835
|
}
|
|
7555
6836
|
this.cliProcess = null;
|
|
7556
6837
|
}
|
|
7557
|
-
if (this.cliStartTimeout) {
|
|
7558
|
-
clearTimeout(this.cliStartTimeout);
|
|
7559
|
-
this.cliStartTimeout = null;
|
|
7560
|
-
}
|
|
7561
6838
|
this.state = "disconnected";
|
|
7562
6839
|
this.actualPort = null;
|
|
7563
6840
|
this.stderrBuffer = "";
|
|
@@ -7587,19 +6864,12 @@ class CopilotClient {
|
|
|
7587
6864
|
} catch {}
|
|
7588
6865
|
this.cliProcess = null;
|
|
7589
6866
|
}
|
|
7590
|
-
if (this.cliStartTimeout) {
|
|
7591
|
-
clearTimeout(this.cliStartTimeout);
|
|
7592
|
-
this.cliStartTimeout = null;
|
|
7593
|
-
}
|
|
7594
6867
|
this.state = "disconnected";
|
|
7595
6868
|
this.actualPort = null;
|
|
7596
6869
|
this.stderrBuffer = "";
|
|
7597
6870
|
this.processExitPromise = null;
|
|
7598
6871
|
}
|
|
7599
|
-
async createSession(config) {
|
|
7600
|
-
if (!config?.onPermissionRequest) {
|
|
7601
|
-
throw new Error("An onPermissionRequest handler is required when creating a session. For example, to allow all permissions, use { onPermissionRequest: approveAll }.");
|
|
7602
|
-
}
|
|
6872
|
+
async createSession(config = {}) {
|
|
7603
6873
|
if (!this.connection) {
|
|
7604
6874
|
if (this.options.autoStart) {
|
|
7605
6875
|
await this.start();
|
|
@@ -7607,90 +6877,49 @@ class CopilotClient {
|
|
|
7607
6877
|
throw new Error("Client not connected. Call start() first.");
|
|
7608
6878
|
}
|
|
7609
6879
|
}
|
|
7610
|
-
const
|
|
7611
|
-
|
|
6880
|
+
const response = await this.connection.sendRequest("session.create", {
|
|
6881
|
+
model: config.model,
|
|
6882
|
+
sessionId: config.sessionId,
|
|
6883
|
+
clientName: config.clientName,
|
|
6884
|
+
reasoningEffort: config.reasoningEffort,
|
|
6885
|
+
tools: config.tools?.map((tool) => ({
|
|
6886
|
+
name: tool.name,
|
|
6887
|
+
description: tool.description,
|
|
6888
|
+
parameters: toJsonSchema(tool.parameters)
|
|
6889
|
+
})),
|
|
6890
|
+
systemMessage: config.systemMessage,
|
|
6891
|
+
availableTools: config.availableTools,
|
|
6892
|
+
excludedTools: config.excludedTools,
|
|
6893
|
+
provider: config.provider,
|
|
6894
|
+
requestPermission: true,
|
|
6895
|
+
requestUserInput: !!config.onUserInputRequest,
|
|
6896
|
+
hooks: !!(config.hooks && Object.values(config.hooks).some(Boolean)),
|
|
6897
|
+
workingDirectory: config.workingDirectory,
|
|
6898
|
+
streaming: config.streaming,
|
|
6899
|
+
mcpServers: config.mcpServers,
|
|
6900
|
+
envValueMode: "direct",
|
|
6901
|
+
customAgents: config.customAgents,
|
|
6902
|
+
configDir: config.configDir,
|
|
6903
|
+
skillDirectories: config.skillDirectories,
|
|
6904
|
+
disabledSkills: config.disabledSkills,
|
|
6905
|
+
infiniteSessions: config.infiniteSessions
|
|
6906
|
+
});
|
|
6907
|
+
const { sessionId, workspacePath } = response;
|
|
6908
|
+
const session = new CopilotSession(sessionId, this.connection, workspacePath);
|
|
7612
6909
|
session.registerTools(config.tools);
|
|
7613
|
-
|
|
7614
|
-
|
|
6910
|
+
if (config.onPermissionRequest) {
|
|
6911
|
+
session.registerPermissionHandler(config.onPermissionRequest);
|
|
6912
|
+
}
|
|
7615
6913
|
if (config.onUserInputRequest) {
|
|
7616
6914
|
session.registerUserInputHandler(config.onUserInputRequest);
|
|
7617
6915
|
}
|
|
7618
|
-
if (config.onElicitationRequest) {
|
|
7619
|
-
session.registerElicitationHandler(config.onElicitationRequest);
|
|
7620
|
-
}
|
|
7621
6916
|
if (config.hooks) {
|
|
7622
6917
|
session.registerHooks(config.hooks);
|
|
7623
6918
|
}
|
|
7624
|
-
const { wirePayload: wireSystemMessage, transformCallbacks } = extractTransformCallbacks(config.systemMessage);
|
|
7625
|
-
if (transformCallbacks) {
|
|
7626
|
-
session.registerTransformCallbacks(transformCallbacks);
|
|
7627
|
-
}
|
|
7628
|
-
if (config.onEvent) {
|
|
7629
|
-
session.on(config.onEvent);
|
|
7630
|
-
}
|
|
7631
6919
|
this.sessions.set(sessionId, session);
|
|
7632
|
-
if (this.sessionFsConfig) {
|
|
7633
|
-
if (config.createSessionFsHandler) {
|
|
7634
|
-
session.clientSessionApis.sessionFs = createSessionFsAdapter(config.createSessionFsHandler(session));
|
|
7635
|
-
} else {
|
|
7636
|
-
throw new Error("createSessionFsHandler is required in session config when sessionFs is enabled in client options.");
|
|
7637
|
-
}
|
|
7638
|
-
}
|
|
7639
|
-
try {
|
|
7640
|
-
const response = await this.connection.sendRequest("session.create", {
|
|
7641
|
-
...await getTraceContext(this.onGetTraceContext),
|
|
7642
|
-
model: config.model,
|
|
7643
|
-
sessionId,
|
|
7644
|
-
clientName: config.clientName,
|
|
7645
|
-
reasoningEffort: config.reasoningEffort,
|
|
7646
|
-
tools: config.tools?.map((tool) => ({
|
|
7647
|
-
name: tool.name,
|
|
7648
|
-
description: tool.description,
|
|
7649
|
-
parameters: toJsonSchema(tool.parameters),
|
|
7650
|
-
overridesBuiltInTool: tool.overridesBuiltInTool,
|
|
7651
|
-
skipPermission: tool.skipPermission
|
|
7652
|
-
})),
|
|
7653
|
-
commands: config.commands?.map((cmd) => ({
|
|
7654
|
-
name: cmd.name,
|
|
7655
|
-
description: cmd.description
|
|
7656
|
-
})),
|
|
7657
|
-
systemMessage: wireSystemMessage,
|
|
7658
|
-
availableTools: config.availableTools,
|
|
7659
|
-
excludedTools: config.excludedTools,
|
|
7660
|
-
provider: config.provider,
|
|
7661
|
-
modelCapabilities: config.modelCapabilities,
|
|
7662
|
-
requestPermission: true,
|
|
7663
|
-
requestUserInput: !!config.onUserInputRequest,
|
|
7664
|
-
requestElicitation: !!config.onElicitationRequest,
|
|
7665
|
-
hooks: !!(config.hooks && Object.values(config.hooks).some(Boolean)),
|
|
7666
|
-
workingDirectory: config.workingDirectory,
|
|
7667
|
-
streaming: config.streaming,
|
|
7668
|
-
includeSubAgentStreamingEvents: config.includeSubAgentStreamingEvents ?? true,
|
|
7669
|
-
mcpServers: config.mcpServers,
|
|
7670
|
-
envValueMode: "direct",
|
|
7671
|
-
customAgents: config.customAgents,
|
|
7672
|
-
defaultAgent: config.defaultAgent,
|
|
7673
|
-
agent: config.agent,
|
|
7674
|
-
configDir: config.configDir,
|
|
7675
|
-
enableConfigDiscovery: config.enableConfigDiscovery,
|
|
7676
|
-
skillDirectories: config.skillDirectories,
|
|
7677
|
-
disabledSkills: config.disabledSkills,
|
|
7678
|
-
infiniteSessions: config.infiniteSessions,
|
|
7679
|
-
gitHubToken: config.gitHubToken
|
|
7680
|
-
});
|
|
7681
|
-
const { workspacePath, capabilities } = response;
|
|
7682
|
-
session["_workspacePath"] = workspacePath;
|
|
7683
|
-
session.setCapabilities(capabilities);
|
|
7684
|
-
} catch (e3) {
|
|
7685
|
-
this.sessions.delete(sessionId);
|
|
7686
|
-
throw e3;
|
|
7687
|
-
}
|
|
7688
6920
|
return session;
|
|
7689
6921
|
}
|
|
7690
|
-
async resumeSession(sessionId, config) {
|
|
7691
|
-
if (!config?.onPermissionRequest) {
|
|
7692
|
-
throw new Error("An onPermissionRequest handler is required when resuming a session. For example, to allow all permissions, use { onPermissionRequest: approveAll }.");
|
|
7693
|
-
}
|
|
6922
|
+
async resumeSession(sessionId, config = {}) {
|
|
7694
6923
|
if (!this.connection) {
|
|
7695
6924
|
if (this.options.autoStart) {
|
|
7696
6925
|
await this.start();
|
|
@@ -7698,84 +6927,47 @@ class CopilotClient {
|
|
|
7698
6927
|
throw new Error("Client not connected. Call start() first.");
|
|
7699
6928
|
}
|
|
7700
6929
|
}
|
|
7701
|
-
const
|
|
6930
|
+
const response = await this.connection.sendRequest("session.resume", {
|
|
6931
|
+
sessionId,
|
|
6932
|
+
clientName: config.clientName,
|
|
6933
|
+
model: config.model,
|
|
6934
|
+
reasoningEffort: config.reasoningEffort,
|
|
6935
|
+
systemMessage: config.systemMessage,
|
|
6936
|
+
availableTools: config.availableTools,
|
|
6937
|
+
excludedTools: config.excludedTools,
|
|
6938
|
+
tools: config.tools?.map((tool) => ({
|
|
6939
|
+
name: tool.name,
|
|
6940
|
+
description: tool.description,
|
|
6941
|
+
parameters: toJsonSchema(tool.parameters)
|
|
6942
|
+
})),
|
|
6943
|
+
provider: config.provider,
|
|
6944
|
+
requestPermission: true,
|
|
6945
|
+
requestUserInput: !!config.onUserInputRequest,
|
|
6946
|
+
hooks: !!(config.hooks && Object.values(config.hooks).some(Boolean)),
|
|
6947
|
+
workingDirectory: config.workingDirectory,
|
|
6948
|
+
configDir: config.configDir,
|
|
6949
|
+
streaming: config.streaming,
|
|
6950
|
+
mcpServers: config.mcpServers,
|
|
6951
|
+
envValueMode: "direct",
|
|
6952
|
+
customAgents: config.customAgents,
|
|
6953
|
+
skillDirectories: config.skillDirectories,
|
|
6954
|
+
disabledSkills: config.disabledSkills,
|
|
6955
|
+
infiniteSessions: config.infiniteSessions,
|
|
6956
|
+
disableResume: config.disableResume
|
|
6957
|
+
});
|
|
6958
|
+
const { sessionId: resumedSessionId, workspacePath } = response;
|
|
6959
|
+
const session = new CopilotSession(resumedSessionId, this.connection, workspacePath);
|
|
7702
6960
|
session.registerTools(config.tools);
|
|
7703
|
-
|
|
7704
|
-
|
|
6961
|
+
if (config.onPermissionRequest) {
|
|
6962
|
+
session.registerPermissionHandler(config.onPermissionRequest);
|
|
6963
|
+
}
|
|
7705
6964
|
if (config.onUserInputRequest) {
|
|
7706
6965
|
session.registerUserInputHandler(config.onUserInputRequest);
|
|
7707
6966
|
}
|
|
7708
|
-
if (config.onElicitationRequest) {
|
|
7709
|
-
session.registerElicitationHandler(config.onElicitationRequest);
|
|
7710
|
-
}
|
|
7711
6967
|
if (config.hooks) {
|
|
7712
6968
|
session.registerHooks(config.hooks);
|
|
7713
6969
|
}
|
|
7714
|
-
|
|
7715
|
-
if (transformCallbacks) {
|
|
7716
|
-
session.registerTransformCallbacks(transformCallbacks);
|
|
7717
|
-
}
|
|
7718
|
-
if (config.onEvent) {
|
|
7719
|
-
session.on(config.onEvent);
|
|
7720
|
-
}
|
|
7721
|
-
this.sessions.set(sessionId, session);
|
|
7722
|
-
if (this.sessionFsConfig) {
|
|
7723
|
-
if (config.createSessionFsHandler) {
|
|
7724
|
-
session.clientSessionApis.sessionFs = createSessionFsAdapter(config.createSessionFsHandler(session));
|
|
7725
|
-
} else {
|
|
7726
|
-
throw new Error("createSessionFsHandler is required in session config when sessionFs is enabled in client options.");
|
|
7727
|
-
}
|
|
7728
|
-
}
|
|
7729
|
-
try {
|
|
7730
|
-
const response = await this.connection.sendRequest("session.resume", {
|
|
7731
|
-
...await getTraceContext(this.onGetTraceContext),
|
|
7732
|
-
sessionId,
|
|
7733
|
-
clientName: config.clientName,
|
|
7734
|
-
model: config.model,
|
|
7735
|
-
reasoningEffort: config.reasoningEffort,
|
|
7736
|
-
systemMessage: wireSystemMessage,
|
|
7737
|
-
availableTools: config.availableTools,
|
|
7738
|
-
excludedTools: config.excludedTools,
|
|
7739
|
-
tools: config.tools?.map((tool) => ({
|
|
7740
|
-
name: tool.name,
|
|
7741
|
-
description: tool.description,
|
|
7742
|
-
parameters: toJsonSchema(tool.parameters),
|
|
7743
|
-
overridesBuiltInTool: tool.overridesBuiltInTool,
|
|
7744
|
-
skipPermission: tool.skipPermission
|
|
7745
|
-
})),
|
|
7746
|
-
commands: config.commands?.map((cmd) => ({
|
|
7747
|
-
name: cmd.name,
|
|
7748
|
-
description: cmd.description
|
|
7749
|
-
})),
|
|
7750
|
-
provider: config.provider,
|
|
7751
|
-
modelCapabilities: config.modelCapabilities,
|
|
7752
|
-
requestPermission: config.onPermissionRequest !== defaultJoinSessionPermissionHandler,
|
|
7753
|
-
requestUserInput: !!config.onUserInputRequest,
|
|
7754
|
-
requestElicitation: !!config.onElicitationRequest,
|
|
7755
|
-
hooks: !!(config.hooks && Object.values(config.hooks).some(Boolean)),
|
|
7756
|
-
workingDirectory: config.workingDirectory,
|
|
7757
|
-
configDir: config.configDir,
|
|
7758
|
-
enableConfigDiscovery: config.enableConfigDiscovery,
|
|
7759
|
-
streaming: config.streaming,
|
|
7760
|
-
includeSubAgentStreamingEvents: config.includeSubAgentStreamingEvents ?? true,
|
|
7761
|
-
mcpServers: config.mcpServers,
|
|
7762
|
-
envValueMode: "direct",
|
|
7763
|
-
customAgents: config.customAgents,
|
|
7764
|
-
defaultAgent: config.defaultAgent,
|
|
7765
|
-
agent: config.agent,
|
|
7766
|
-
skillDirectories: config.skillDirectories,
|
|
7767
|
-
disabledSkills: config.disabledSkills,
|
|
7768
|
-
infiniteSessions: config.infiniteSessions,
|
|
7769
|
-
disableResume: config.disableResume,
|
|
7770
|
-
gitHubToken: config.gitHubToken
|
|
7771
|
-
});
|
|
7772
|
-
const { workspacePath, capabilities } = response;
|
|
7773
|
-
session["_workspacePath"] = workspacePath;
|
|
7774
|
-
session.setCapabilities(capabilities);
|
|
7775
|
-
} catch (e3) {
|
|
7776
|
-
this.sessions.delete(sessionId);
|
|
7777
|
-
throw e3;
|
|
7778
|
-
}
|
|
6970
|
+
this.sessions.set(resumedSessionId, session);
|
|
7779
6971
|
return session;
|
|
7780
6972
|
}
|
|
7781
6973
|
getState() {
|
|
@@ -7803,6 +6995,9 @@ class CopilotClient {
|
|
|
7803
6995
|
return result;
|
|
7804
6996
|
}
|
|
7805
6997
|
async listModels() {
|
|
6998
|
+
if (!this.connection) {
|
|
6999
|
+
throw new Error("Client not connected");
|
|
7000
|
+
}
|
|
7806
7001
|
await this.modelsCacheLock;
|
|
7807
7002
|
let resolveLock;
|
|
7808
7003
|
this.modelsCacheLock = new Promise((resolve4) => {
|
|
@@ -7812,42 +7007,17 @@ class CopilotClient {
|
|
|
7812
7007
|
if (this.modelsCache !== null) {
|
|
7813
7008
|
return [...this.modelsCache];
|
|
7814
7009
|
}
|
|
7815
|
-
|
|
7816
|
-
|
|
7817
|
-
|
|
7818
|
-
|
|
7819
|
-
if (!this.connection) {
|
|
7820
|
-
throw new Error("Client not connected");
|
|
7821
|
-
}
|
|
7822
|
-
const result = await this.connection.sendRequest("models.list", {});
|
|
7823
|
-
const response = result;
|
|
7824
|
-
models = response.models;
|
|
7825
|
-
for (const model of models) {
|
|
7826
|
-
const m2 = model;
|
|
7827
|
-
if (!m2.capabilities) {
|
|
7828
|
-
m2.capabilities = {
|
|
7829
|
-
supports: {},
|
|
7830
|
-
limits: { max_context_window_tokens: 0 }
|
|
7831
|
-
};
|
|
7832
|
-
} else {
|
|
7833
|
-
if (!m2.capabilities.supports)
|
|
7834
|
-
m2.capabilities.supports = {};
|
|
7835
|
-
if (!m2.capabilities.limits) {
|
|
7836
|
-
m2.capabilities.limits = { max_context_window_tokens: 0 };
|
|
7837
|
-
} else if (m2.capabilities.limits.max_context_window_tokens === undefined) {
|
|
7838
|
-
m2.capabilities.limits.max_context_window_tokens = 0;
|
|
7839
|
-
}
|
|
7840
|
-
}
|
|
7841
|
-
}
|
|
7842
|
-
}
|
|
7843
|
-
this.modelsCache = [...models];
|
|
7010
|
+
const result = await this.connection.sendRequest("models.list", {});
|
|
7011
|
+
const response = result;
|
|
7012
|
+
const models = response.models;
|
|
7013
|
+
this.modelsCache = models;
|
|
7844
7014
|
return [...models];
|
|
7845
7015
|
} finally {
|
|
7846
7016
|
resolveLock();
|
|
7847
7017
|
}
|
|
7848
7018
|
}
|
|
7849
7019
|
async verifyProtocolVersion() {
|
|
7850
|
-
const
|
|
7020
|
+
const expectedVersion = getSdkProtocolVersion();
|
|
7851
7021
|
let pingResult;
|
|
7852
7022
|
if (this.processExitPromise) {
|
|
7853
7023
|
pingResult = await Promise.race([this.ping(), this.processExitPromise]);
|
|
@@ -7856,12 +7026,11 @@ class CopilotClient {
|
|
|
7856
7026
|
}
|
|
7857
7027
|
const serverVersion = pingResult.protocolVersion;
|
|
7858
7028
|
if (serverVersion === undefined) {
|
|
7859
|
-
throw new Error(`SDK protocol version mismatch: SDK
|
|
7029
|
+
throw new Error(`SDK protocol version mismatch: SDK expects version ${expectedVersion}, but server does not report a protocol version. Please update your server to ensure compatibility.`);
|
|
7860
7030
|
}
|
|
7861
|
-
if (serverVersion
|
|
7862
|
-
throw new Error(`SDK protocol version mismatch: SDK
|
|
7031
|
+
if (serverVersion !== expectedVersion) {
|
|
7032
|
+
throw new Error(`SDK protocol version mismatch: SDK expects version ${expectedVersion}, but server reports version ${serverVersion}. Please update your SDK or server to ensure compatibility.`);
|
|
7863
7033
|
}
|
|
7864
|
-
this.negotiatedProtocolVersion = serverVersion;
|
|
7865
7034
|
}
|
|
7866
7035
|
async getLastSessionId() {
|
|
7867
7036
|
if (!this.connection) {
|
|
@@ -7887,32 +7056,16 @@ class CopilotClient {
|
|
|
7887
7056
|
if (!this.connection) {
|
|
7888
7057
|
throw new Error("Client not connected");
|
|
7889
7058
|
}
|
|
7890
|
-
const response = await this.connection.sendRequest("session.list", {
|
|
7891
|
-
filter
|
|
7892
|
-
});
|
|
7059
|
+
const response = await this.connection.sendRequest("session.list", { filter });
|
|
7893
7060
|
const { sessions } = response;
|
|
7894
|
-
return sessions.map(
|
|
7895
|
-
|
|
7896
|
-
|
|
7897
|
-
|
|
7898
|
-
|
|
7899
|
-
|
|
7900
|
-
|
|
7901
|
-
|
|
7902
|
-
if (!session) {
|
|
7903
|
-
return;
|
|
7904
|
-
}
|
|
7905
|
-
return CopilotClient.toSessionMetadata(session);
|
|
7906
|
-
}
|
|
7907
|
-
static toSessionMetadata(raw) {
|
|
7908
|
-
return {
|
|
7909
|
-
sessionId: raw.sessionId,
|
|
7910
|
-
startTime: new Date(raw.startTime),
|
|
7911
|
-
modifiedTime: new Date(raw.modifiedTime),
|
|
7912
|
-
summary: raw.summary,
|
|
7913
|
-
isRemote: raw.isRemote,
|
|
7914
|
-
context: raw.context
|
|
7915
|
-
};
|
|
7061
|
+
return sessions.map((s2) => ({
|
|
7062
|
+
sessionId: s2.sessionId,
|
|
7063
|
+
startTime: new Date(s2.startTime),
|
|
7064
|
+
modifiedTime: new Date(s2.modifiedTime),
|
|
7065
|
+
summary: s2.summary,
|
|
7066
|
+
isRemote: s2.isRemote,
|
|
7067
|
+
context: s2.context
|
|
7068
|
+
}));
|
|
7916
7069
|
}
|
|
7917
7070
|
async getForegroundSessionId() {
|
|
7918
7071
|
if (!this.connection) {
|
|
@@ -7967,36 +7120,16 @@ class CopilotClient {
|
|
|
7967
7120
|
} else if (this.options.port > 0) {
|
|
7968
7121
|
args.push("--port", this.options.port.toString());
|
|
7969
7122
|
}
|
|
7970
|
-
if (this.options.
|
|
7123
|
+
if (this.options.githubToken) {
|
|
7971
7124
|
args.push("--auth-token-env", "COPILOT_SDK_AUTH_TOKEN");
|
|
7972
7125
|
}
|
|
7973
7126
|
if (!this.options.useLoggedInUser) {
|
|
7974
7127
|
args.push("--no-auto-login");
|
|
7975
7128
|
}
|
|
7976
|
-
if (this.options.sessionIdleTimeoutSeconds !== undefined && this.options.sessionIdleTimeoutSeconds > 0) {
|
|
7977
|
-
args.push("--session-idle-timeout", this.options.sessionIdleTimeoutSeconds.toString());
|
|
7978
|
-
}
|
|
7979
7129
|
const envWithoutNodeDebug = { ...this.options.env };
|
|
7980
7130
|
delete envWithoutNodeDebug.NODE_DEBUG;
|
|
7981
|
-
if (this.options.
|
|
7982
|
-
envWithoutNodeDebug.COPILOT_SDK_AUTH_TOKEN = this.options.
|
|
7983
|
-
}
|
|
7984
|
-
if (!this.options.cliPath) {
|
|
7985
|
-
throw new Error("Path to Copilot CLI is required. Please provide it via the cliPath option, or use cliUrl to rely on a remote CLI.");
|
|
7986
|
-
}
|
|
7987
|
-
if (this.options.telemetry) {
|
|
7988
|
-
const t2 = this.options.telemetry;
|
|
7989
|
-
envWithoutNodeDebug.COPILOT_OTEL_ENABLED = "true";
|
|
7990
|
-
if (t2.otlpEndpoint !== undefined)
|
|
7991
|
-
envWithoutNodeDebug.OTEL_EXPORTER_OTLP_ENDPOINT = t2.otlpEndpoint;
|
|
7992
|
-
if (t2.filePath !== undefined)
|
|
7993
|
-
envWithoutNodeDebug.COPILOT_OTEL_FILE_EXPORTER_PATH = t2.filePath;
|
|
7994
|
-
if (t2.exporterType !== undefined)
|
|
7995
|
-
envWithoutNodeDebug.COPILOT_OTEL_EXPORTER_TYPE = t2.exporterType;
|
|
7996
|
-
if (t2.sourceName !== undefined)
|
|
7997
|
-
envWithoutNodeDebug.COPILOT_OTEL_SOURCE_NAME = t2.sourceName;
|
|
7998
|
-
if (t2.captureContent !== undefined)
|
|
7999
|
-
envWithoutNodeDebug.OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT = String(t2.captureContent);
|
|
7131
|
+
if (this.options.githubToken) {
|
|
7132
|
+
envWithoutNodeDebug.COPILOT_SDK_AUTH_TOKEN = this.options.githubToken;
|
|
8000
7133
|
}
|
|
8001
7134
|
if (!existsSync4(this.options.cliPath)) {
|
|
8002
7135
|
throw new Error(`Copilot CLI not found at ${this.options.cliPath}. Ensure @github/copilot is installed.`);
|
|
@@ -8081,9 +7214,11 @@ stderr: ${stderrOutput}`));
|
|
|
8081
7214
|
} else {
|
|
8082
7215
|
reject(new Error(`CLI server exited with code ${code}`));
|
|
8083
7216
|
}
|
|
7217
|
+
} else if (this.options.autoRestart && this.state === "connected") {
|
|
7218
|
+
this.reconnect();
|
|
8084
7219
|
}
|
|
8085
7220
|
});
|
|
8086
|
-
|
|
7221
|
+
setTimeout(() => {
|
|
8087
7222
|
if (!resolved) {
|
|
8088
7223
|
resolved = true;
|
|
8089
7224
|
reject(new Error("Timeout waiting for CLI server to start"));
|
|
@@ -8092,15 +7227,13 @@ stderr: ${stderrOutput}`));
|
|
|
8092
7227
|
});
|
|
8093
7228
|
}
|
|
8094
7229
|
async connectToServer() {
|
|
8095
|
-
if (this.options.
|
|
8096
|
-
return this.
|
|
8097
|
-
} else if (this.options.useStdio) {
|
|
8098
|
-
return this.connectToChildProcessViaStdio();
|
|
7230
|
+
if (this.options.useStdio) {
|
|
7231
|
+
return this.connectViaStdio();
|
|
8099
7232
|
} else {
|
|
8100
7233
|
return this.connectViaTcp();
|
|
8101
7234
|
}
|
|
8102
7235
|
}
|
|
8103
|
-
async
|
|
7236
|
+
async connectViaStdio() {
|
|
8104
7237
|
if (!this.cliProcess) {
|
|
8105
7238
|
throw new Error("CLI process not started");
|
|
8106
7239
|
}
|
|
@@ -8109,15 +7242,7 @@ stderr: ${stderrOutput}`));
|
|
|
8109
7242
|
throw err;
|
|
8110
7243
|
}
|
|
8111
7244
|
});
|
|
8112
|
-
this.connection =
|
|
8113
|
-
this.attachConnectionHandlers();
|
|
8114
|
-
this.connection.listen();
|
|
8115
|
-
}
|
|
8116
|
-
async connectToParentProcessViaStdio() {
|
|
8117
|
-
if (this.cliProcess) {
|
|
8118
|
-
throw new Error("CLI child process was unexpectedly started in parent process mode");
|
|
8119
|
-
}
|
|
8120
|
-
this.connection = import_node2.createMessageConnection(new import_node2.StreamMessageReader(process.stdin), new import_node2.StreamMessageWriter(process.stdout));
|
|
7245
|
+
this.connection = import_node.createMessageConnection(new import_node.StreamMessageReader(this.cliProcess.stdout), new import_node.StreamMessageWriter(this.cliProcess.stdin));
|
|
8121
7246
|
this.attachConnectionHandlers();
|
|
8122
7247
|
this.connection.listen();
|
|
8123
7248
|
}
|
|
@@ -8128,7 +7253,7 @@ stderr: ${stderrOutput}`));
|
|
|
8128
7253
|
return new Promise((resolve4, reject) => {
|
|
8129
7254
|
this.socket = new Socket;
|
|
8130
7255
|
this.socket.connect(this.actualPort, this.actualHost, () => {
|
|
8131
|
-
this.connection =
|
|
7256
|
+
this.connection = import_node.createMessageConnection(new import_node.StreamMessageReader(this.socket), new import_node.StreamMessageWriter(this.socket));
|
|
8132
7257
|
this.attachConnectionHandlers();
|
|
8133
7258
|
this.connection.listen();
|
|
8134
7259
|
resolve4();
|
|
@@ -8148,24 +7273,16 @@ stderr: ${stderrOutput}`));
|
|
|
8148
7273
|
this.connection.onNotification("session.lifecycle", (notification) => {
|
|
8149
7274
|
this.handleSessionLifecycleNotification(notification);
|
|
8150
7275
|
});
|
|
8151
|
-
this.connection.onRequest("tool.call", async (params) => await this.
|
|
8152
|
-
this.connection.onRequest("permission.request", async (params) => await this.
|
|
7276
|
+
this.connection.onRequest("tool.call", async (params) => await this.handleToolCallRequest(params));
|
|
7277
|
+
this.connection.onRequest("permission.request", async (params) => await this.handlePermissionRequest(params));
|
|
8153
7278
|
this.connection.onRequest("userInput.request", async (params) => await this.handleUserInputRequest(params));
|
|
8154
7279
|
this.connection.onRequest("hooks.invoke", async (params) => await this.handleHooksInvoke(params));
|
|
8155
|
-
this.connection.onRequest("systemMessage.transform", async (params) => await this.handleSystemMessageTransform(params));
|
|
8156
|
-
const sessions = this.sessions;
|
|
8157
|
-
registerClientSessionApiHandlers(this.connection, (sessionId) => {
|
|
8158
|
-
const session = sessions.get(sessionId);
|
|
8159
|
-
if (!session)
|
|
8160
|
-
throw new Error(`No session found for sessionId: ${sessionId}`);
|
|
8161
|
-
return session.clientSessionApis;
|
|
8162
|
-
});
|
|
8163
7280
|
this.connection.onClose(() => {
|
|
8164
|
-
this.state
|
|
8165
|
-
|
|
8166
|
-
|
|
8167
|
-
this.state = "disconnected";
|
|
7281
|
+
if (this.state === "connected" && this.options.autoRestart) {
|
|
7282
|
+
this.reconnect();
|
|
7283
|
+
}
|
|
8168
7284
|
});
|
|
7285
|
+
this.connection.onError((_error) => {});
|
|
8169
7286
|
}
|
|
8170
7287
|
handleSessionEventNotification(notification) {
|
|
8171
7288
|
if (typeof notification !== "object" || !notification || !("sessionId" in notification) || typeof notification.sessionId !== "string" || !("event" in notification)) {
|
|
@@ -8195,43 +7312,7 @@ stderr: ${stderrOutput}`));
|
|
|
8195
7312
|
} catch {}
|
|
8196
7313
|
}
|
|
8197
7314
|
}
|
|
8198
|
-
async
|
|
8199
|
-
if (!params || typeof params.sessionId !== "string" || typeof params.question !== "string") {
|
|
8200
|
-
throw new Error("Invalid user input request payload");
|
|
8201
|
-
}
|
|
8202
|
-
const session = this.sessions.get(params.sessionId);
|
|
8203
|
-
if (!session) {
|
|
8204
|
-
throw new Error(`Session not found: ${params.sessionId}`);
|
|
8205
|
-
}
|
|
8206
|
-
const result = await session._handleUserInputRequest({
|
|
8207
|
-
question: params.question,
|
|
8208
|
-
choices: params.choices,
|
|
8209
|
-
allowFreeform: params.allowFreeform
|
|
8210
|
-
});
|
|
8211
|
-
return result;
|
|
8212
|
-
}
|
|
8213
|
-
async handleHooksInvoke(params) {
|
|
8214
|
-
if (!params || typeof params.sessionId !== "string" || typeof params.hookType !== "string") {
|
|
8215
|
-
throw new Error("Invalid hooks invoke payload");
|
|
8216
|
-
}
|
|
8217
|
-
const session = this.sessions.get(params.sessionId);
|
|
8218
|
-
if (!session) {
|
|
8219
|
-
throw new Error(`Session not found: ${params.sessionId}`);
|
|
8220
|
-
}
|
|
8221
|
-
const output = await session._handleHooksInvoke(params.hookType, params.input);
|
|
8222
|
-
return { output };
|
|
8223
|
-
}
|
|
8224
|
-
async handleSystemMessageTransform(params) {
|
|
8225
|
-
if (!params || typeof params.sessionId !== "string" || !params.sections || typeof params.sections !== "object") {
|
|
8226
|
-
throw new Error("Invalid systemMessage.transform payload");
|
|
8227
|
-
}
|
|
8228
|
-
const session = this.sessions.get(params.sessionId);
|
|
8229
|
-
if (!session) {
|
|
8230
|
-
throw new Error(`Session not found: ${params.sessionId}`);
|
|
8231
|
-
}
|
|
8232
|
-
return await session._handleSystemMessageTransform(params.sections);
|
|
8233
|
-
}
|
|
8234
|
-
async handleToolCallRequestV2(params) {
|
|
7315
|
+
async handleToolCallRequest(params) {
|
|
8235
7316
|
if (!params || typeof params.sessionId !== "string" || typeof params.toolCallId !== "string" || typeof params.toolName !== "string") {
|
|
8236
7317
|
throw new Error("Invalid tool call payload");
|
|
8237
7318
|
}
|
|
@@ -8241,28 +7322,20 @@ stderr: ${stderrOutput}`));
|
|
|
8241
7322
|
}
|
|
8242
7323
|
const handler = session.getToolHandler(params.toolName);
|
|
8243
7324
|
if (!handler) {
|
|
8244
|
-
return {
|
|
8245
|
-
result: {
|
|
8246
|
-
textResultForLlm: `Tool '${params.toolName}' is not supported by this client instance.`,
|
|
8247
|
-
resultType: "failure",
|
|
8248
|
-
error: `tool '${params.toolName}' not supported`,
|
|
8249
|
-
toolTelemetry: {}
|
|
8250
|
-
}
|
|
8251
|
-
};
|
|
7325
|
+
return { result: this.buildUnsupportedToolResult(params.toolName) };
|
|
8252
7326
|
}
|
|
7327
|
+
return await this.executeToolCall(handler, params);
|
|
7328
|
+
}
|
|
7329
|
+
async executeToolCall(handler, request) {
|
|
8253
7330
|
try {
|
|
8254
|
-
const traceparent = params.traceparent;
|
|
8255
|
-
const tracestate = params.tracestate;
|
|
8256
7331
|
const invocation = {
|
|
8257
|
-
sessionId:
|
|
8258
|
-
toolCallId:
|
|
8259
|
-
toolName:
|
|
8260
|
-
arguments:
|
|
8261
|
-
traceparent,
|
|
8262
|
-
tracestate
|
|
7332
|
+
sessionId: request.sessionId,
|
|
7333
|
+
toolCallId: request.toolCallId,
|
|
7334
|
+
toolName: request.toolName,
|
|
7335
|
+
arguments: request.arguments
|
|
8263
7336
|
};
|
|
8264
|
-
const result = await handler(
|
|
8265
|
-
return { result: this.
|
|
7337
|
+
const result = await handler(request.arguments, invocation);
|
|
7338
|
+
return { result: this.normalizeToolResult(result) };
|
|
8266
7339
|
} catch (error2) {
|
|
8267
7340
|
const message = error2 instanceof Error ? error2.message : String(error2);
|
|
8268
7341
|
return {
|
|
@@ -8275,7 +7348,7 @@ stderr: ${stderrOutput}`));
|
|
|
8275
7348
|
};
|
|
8276
7349
|
}
|
|
8277
7350
|
}
|
|
8278
|
-
async
|
|
7351
|
+
async handlePermissionRequest(params) {
|
|
8279
7352
|
if (!params || typeof params.sessionId !== "string" || !params.permissionRequest) {
|
|
8280
7353
|
throw new Error("Invalid permission request payload");
|
|
8281
7354
|
}
|
|
@@ -8284,20 +7357,43 @@ stderr: ${stderrOutput}`));
|
|
|
8284
7357
|
throw new Error(`Session not found: ${params.sessionId}`);
|
|
8285
7358
|
}
|
|
8286
7359
|
try {
|
|
8287
|
-
const result = await session.
|
|
7360
|
+
const result = await session._handlePermissionRequest(params.permissionRequest);
|
|
8288
7361
|
return { result };
|
|
8289
|
-
} catch (
|
|
8290
|
-
if (error2 instanceof Error && error2.message === NO_RESULT_PERMISSION_V2_ERROR) {
|
|
8291
|
-
throw error2;
|
|
8292
|
-
}
|
|
7362
|
+
} catch (_error) {
|
|
8293
7363
|
return {
|
|
8294
7364
|
result: {
|
|
8295
|
-
kind: "
|
|
7365
|
+
kind: "denied-no-approval-rule-and-could-not-request-from-user"
|
|
8296
7366
|
}
|
|
8297
7367
|
};
|
|
8298
7368
|
}
|
|
8299
7369
|
}
|
|
8300
|
-
|
|
7370
|
+
async handleUserInputRequest(params) {
|
|
7371
|
+
if (!params || typeof params.sessionId !== "string" || typeof params.question !== "string") {
|
|
7372
|
+
throw new Error("Invalid user input request payload");
|
|
7373
|
+
}
|
|
7374
|
+
const session = this.sessions.get(params.sessionId);
|
|
7375
|
+
if (!session) {
|
|
7376
|
+
throw new Error(`Session not found: ${params.sessionId}`);
|
|
7377
|
+
}
|
|
7378
|
+
const result = await session._handleUserInputRequest({
|
|
7379
|
+
question: params.question,
|
|
7380
|
+
choices: params.choices,
|
|
7381
|
+
allowFreeform: params.allowFreeform
|
|
7382
|
+
});
|
|
7383
|
+
return result;
|
|
7384
|
+
}
|
|
7385
|
+
async handleHooksInvoke(params) {
|
|
7386
|
+
if (!params || typeof params.sessionId !== "string" || typeof params.hookType !== "string") {
|
|
7387
|
+
throw new Error("Invalid hooks invoke payload");
|
|
7388
|
+
}
|
|
7389
|
+
const session = this.sessions.get(params.sessionId);
|
|
7390
|
+
if (!session) {
|
|
7391
|
+
throw new Error(`Session not found: ${params.sessionId}`);
|
|
7392
|
+
}
|
|
7393
|
+
const output = await session._handleHooksInvoke(params.hookType, params.input);
|
|
7394
|
+
return { output };
|
|
7395
|
+
}
|
|
7396
|
+
normalizeToolResult(result) {
|
|
8301
7397
|
if (result === undefined || result === null) {
|
|
8302
7398
|
return {
|
|
8303
7399
|
textResultForLlm: "Tool returned no result",
|
|
@@ -8319,26 +7415,42 @@ stderr: ${stderrOutput}`));
|
|
|
8319
7415
|
isToolResultObject(value) {
|
|
8320
7416
|
return typeof value === "object" && value !== null && "textResultForLlm" in value && typeof value.textResultForLlm === "string" && "resultType" in value;
|
|
8321
7417
|
}
|
|
7418
|
+
buildUnsupportedToolResult(toolName) {
|
|
7419
|
+
return {
|
|
7420
|
+
textResultForLlm: `Tool '${toolName}' is not supported by this client instance.`,
|
|
7421
|
+
resultType: "failure",
|
|
7422
|
+
error: `tool '${toolName}' not supported`,
|
|
7423
|
+
toolTelemetry: {}
|
|
7424
|
+
};
|
|
7425
|
+
}
|
|
7426
|
+
async reconnect() {
|
|
7427
|
+
this.state = "disconnected";
|
|
7428
|
+
try {
|
|
7429
|
+
await this.stop();
|
|
7430
|
+
await this.start();
|
|
7431
|
+
} catch (_error) {}
|
|
7432
|
+
}
|
|
8322
7433
|
}
|
|
8323
|
-
var
|
|
7434
|
+
var import_node;
|
|
8324
7435
|
var init_client = __esm(() => {
|
|
8325
7436
|
init_rpc();
|
|
8326
7437
|
init_sdkProtocolVersion();
|
|
8327
7438
|
init_session();
|
|
8328
|
-
|
|
8329
|
-
init_telemetry();
|
|
8330
|
-
init_types2();
|
|
8331
|
-
import_node2 = __toESM(require_main(), 1);
|
|
7439
|
+
import_node = __toESM(require_main(), 1);
|
|
8332
7440
|
});
|
|
8333
7441
|
|
|
7442
|
+
// node_modules/@github/copilot-sdk/dist/types.js
|
|
7443
|
+
function defineTool(name, config) {
|
|
7444
|
+
return { name, ...config };
|
|
7445
|
+
}
|
|
7446
|
+
var approveAll = () => ({ kind: "approved" });
|
|
7447
|
+
var init_types2 = () => {};
|
|
7448
|
+
|
|
8334
7449
|
// node_modules/@github/copilot-sdk/dist/index.js
|
|
8335
7450
|
var exports_dist2 = {};
|
|
8336
7451
|
__export(exports_dist2, {
|
|
8337
7452
|
defineTool: () => defineTool,
|
|
8338
|
-
createSessionFsAdapter: () => createSessionFsAdapter,
|
|
8339
|
-
convertMcpCallToolResult: () => convertMcpCallToolResult,
|
|
8340
7453
|
approveAll: () => approveAll,
|
|
8341
|
-
SYSTEM_PROMPT_SECTIONS: () => SYSTEM_PROMPT_SECTIONS,
|
|
8342
7454
|
CopilotSession: () => CopilotSession,
|
|
8343
7455
|
CopilotClient: () => CopilotClient
|
|
8344
7456
|
});
|
|
@@ -14654,7 +13766,7 @@ var import_picocolors12 = __toESM(require_picocolors(), 1);
|
|
|
14654
13766
|
// package.json
|
|
14655
13767
|
var package_default = {
|
|
14656
13768
|
name: "contribute-now",
|
|
14657
|
-
version: "0.10.0
|
|
13769
|
+
version: "0.10.0",
|
|
14658
13770
|
description: "Developer CLI that automates git workflows \u2014 branching, syncing, committing, and PRs \u2014 with multi-workflow and commit convention support.",
|
|
14659
13771
|
type: "module",
|
|
14660
13772
|
bin: {
|
|
@@ -14700,7 +13812,7 @@ var package_default = {
|
|
|
14700
13812
|
},
|
|
14701
13813
|
dependencies: {
|
|
14702
13814
|
"@clack/prompts": "^1.0.1",
|
|
14703
|
-
"@github/copilot-sdk": "^0.
|
|
13815
|
+
"@github/copilot-sdk": "^0.1.25",
|
|
14704
13816
|
"@wgtechlabs/log-engine": "^2.3.1",
|
|
14705
13817
|
citty: "^0.1.6",
|
|
14706
13818
|
picocolors: "^1.1.1"
|