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

Method registerCanvases

nodejs/src/session.ts:800–849  ·  view source on GitHub ↗

* Registers canvas declarations and handlers for this session. * * @param canvases - Canvases created via `createCanvas`, or undefined to clear all canvases * @internal Called by the SDK when creating/resuming a session with `canvases`.

(canvases?: Canvas[])

Source from the content-addressed store, hash-verified

798 * @internal Called by the SDK when creating/resuming a session with `canvases`.
799 */
800 registerCanvases(canvases?: Canvas[]): void {
801 this.canvases.clear();
802 if (!canvases || canvases.length === 0) {
803 delete this.clientSessionApis.canvas;
804 return;
805 }
806 for (const canvas of canvases) {
807 this.canvases.set(canvas.declaration.id, canvas);
808 }
809
810 const self = this;
811 this.clientSessionApis.canvas = {
812 async open(params) {
813 const canvas = self.canvases.get(params.canvasId);
814 if (!canvas) throw new Error(`No canvas registered with id "${params.canvasId}"`);
815 try {
816 return (await canvas.open(params)) ?? {};
817 } catch (error) {
818 throw toCanvasRpcError(error);
819 }
820 },
821 async close(params) {
822 const canvas = self.canvases.get(params.canvasId);
823 if (!canvas) throw new Error(`No canvas registered with id "${params.canvasId}"`);
824 try {
825 if (canvas.onClose) {
826 await canvas.onClose(params);
827 }
828 } catch (error) {
829 throw toCanvasRpcError(error);
830 }
831 },
832 async invoke(params) {
833 const canvas = self.canvases.get(params.canvasId);
834 if (!canvas) throw new Error(`No canvas registered with id "${params.canvasId}"`);
835 const handler = canvas.actionHandlers.get(params.actionName);
836 if (!handler) {
837 throw new CanvasError(
838 "canvas_action_no_handler",
839 "No handler implemented for this canvas action"
840 );
841 }
842 try {
843 return (await handler(params)) as CanvasActionInvokeResult;
844 } catch (error) {
845 throw toCanvasRpcError(error);
846 }
847 },
848 };
849 }
850
851 /**
852 * Registers per-provider {@link BearerTokenProvider} callbacks for BYOK providers

Callers 3

initializeSessionMethod · 0.95
resumeSessionMethod · 0.95
client.test.tsFile · 0.80

Calls 2

clearMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected