MCPcopy Index your code
hub / github.com/github/copilot-sdk / _executeCommandAndRespond

Method _executeCommandAndRespond

nodejs/src/session.ts:719–759  ·  view source on GitHub ↗

* Executes a command handler and sends the result back via RPC. * @internal

(
        requestId: string,
        commandName: string,
        command: string,
        args: string
    )

Source from the content-addressed store, hash-verified

717 * @internal
718 */
719 private async _executeCommandAndRespond(
720 requestId: string,
721 commandName: string,
722 command: string,
723 args: string
724 ): Promise<void> {
725 const handler = this.commandHandlers.get(commandName);
726 if (!handler) {
727 try {
728 await this.rpc.commands.handlePendingCommand({
729 requestId,
730 error: `Unknown command: ${commandName}`,
731 });
732 } catch (rpcError) {
733 if (!(rpcError instanceof ConnectionError || rpcError instanceof ResponseError)) {
734 throw rpcError;
735 }
736 }
737 return;
738 }
739
740 try {
741 await handler({ sessionId: this.sessionId, command, commandName, args });
742 if (this.disconnected) {
743 return;
744 }
745 await this.rpc.commands.handlePendingCommand({ requestId });
746 } catch (error) {
747 if (this.disconnected) {
748 return;
749 }
750 const message = error instanceof Error ? error.message : String(error);
751 try {
752 await this.rpc.commands.handlePendingCommand({ requestId, error: message });
753 } catch (rpcError) {
754 if (!(rpcError instanceof ConnectionError || rpcError instanceof ResponseError)) {
755 throw rpcError;
756 }
757 }
758 }
759 }
760
761 /**
762 * Registers custom tool handlers for this session.

Callers 1

_handleBroadcastEventMethod · 0.95

Calls 4

handlerFunction · 0.85
StringFunction · 0.85
handlePendingCommandMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected