microsoft / vscode-jupyter

VS Code Jupyter extension
https://marketplace.visualstudio.com/items?itemName=ms-toolsai.jupyter
MIT License
1.3k stars 294 forks source link

Request for unstable API permission for an extension #16221

Closed gjsjohnmurray closed 6 days ago

gjsjohnmurray commented 1 week ago

Please allow the extension Jupyter Server Proxy for InterSystems IRIS (intersystems-community.iris-jupyter-server) to use unstable API in production.

DonJayamanne commented 1 week ago

@gjsjohnmurray

Thanks for looking into this. Please can you confirm the id of the extension is as follows intersystems-community.iris-jupyter-server I'll add this once confirmed,

Also added a general note on using proposed API https://github.com/microsoft/vscode-jupyter/wiki/Extension-API I'm sure you're no stranger to this. TLDR, with the API you are planning on using, we have no plans to change this, its used in at least 2 other extensions (Jupyter Hub and another inhouse extension) I.e. it is very safe to use this, though its not yet stable.

gjsjohnmurray commented 1 week ago

Yes, that is the correct id.

DonJayamanne commented 1 week ago

@gjsjohnmurray I think you should be able to use this today, npm i @vscode/jupyter-extension@proposed Please use just the following proposed API, I believe thats all you will need

    export interface JupyterServerConnectionInformation {
        /**
         * The `fetch` method to use.
         */
        readonly fetch?: (input: RequestInfo, init?: RequestInit) => Promise<Response>;
        /**
         * The `WebSocket` object constructor.
         */
        readonly WebSocket?: typeof WebSocket;

Let me know if it doesn't work for you. All you need is provide your own fetch implementation and the Jupyter extension will call into that for sure. similarly for websockets.

gjsjohnmurray commented 1 week ago

@DonJayamanne I am trying to use getKernelService

const jupyterKernelService = await jupyterApi.getKernelService();
if (!jupyterKernelService) {
    vscode.window.showErrorMessage('Cannot access jupyterApi.getKernelService() - try using VS Code Insiders');
    return;
}

Next I create a new notebook:

await vscode.commands.executeCommand('ipynb.newUntitledIpynb');
const nbEditor = vscode.window.activeNotebookEditor;

Get the kernel specifications:

const kernelConnectionMetadataArray = await jupyterKernelService.getKernelSpecifications();

I then search the array to get an id I can use as an argument to your API's openNotebook:

const kernelConnectionMetadata = kernelConnectionMetadataArray.find((item: any) => item.kind === 'startUsingRemoteKernelSpec' && item.baseUrl === myBaseUrl && item.kernelSpec.name === myKernelSpecName);
await jupyterApi.openNotebook(nbUri, kernelConnectionMetadata.id);

It's working well on VS Code Insiders, but on Stable I'm getting this notification:

Image

AFAIK you'd need to add my extension id to a list somewhere to make this possible on Stable.

DonJayamanne commented 1 week ago

‘ getKernelService’ should not be used Please have a look at the Jupyterhub extension https://github.com/microsoft/vscode-jupyter-hub/blob/5d684bbee59ab8911e99e89a08a7adb4600df3b8/src/jupyterIntegration.ts#L308

gjsjohnmurray commented 1 week ago

At this point I'm not trying to replace my fake jupyter server with your proxy fetch and websocket mechanism (see your comment https://github.com/intersystems-community/vscode-iris-jupyter-server/issues/6#issuecomment-1899499184). Rather, having successfully migrated to the finalized JupyterServerProvider API I've been trying to add a way from our UI's tree of servers to be able to launch a new notebook using one of the kernelspecs that the target server provides.

To visualize my goal, imagine adding "Create Interactive Window" and "Create Jupyter Notebook" buttons on the Kernel Specifications rows of your Jupyter Powertoys extension:

Image

I know the baseUrl and the kernelSpec.name but what I need to pass to your openNotebook function is the id of the matching kernelConnectionMetadata item.

Maybe a better solution than me using getKernelService is for you to make openNotebook accept this alternative object in its second argument:

{ kind: 'startUsingRemoteKernelSpec', baseUrl: 'http://localhost:50773/irislatest:USER', kernelSpecName: 'objectscript-int' }

leaving it down to you to match those values in your kernelConnectionMetadata[] array and get the id that I currently have to pass in on the openNotebook call.

DonJayamanne commented 6 days ago

Thank you for getting back Unfortunately at this stage we’re trying to deprecate that other api completely and remove it Just have to extensions that use that today (power toy and another)

Please can you file a new issue with your requirements so we can track and discuss that separately Let’s start with the assumption that the old api has been removed/don’t exist

Thanks again Going to close this issue so we can start a separate discussion on a new issue