1
1
// Copyright (c) Microsoft Corporation.
2
2
// Licensed under the MIT License.
3
3
4
- import type { ServerConnection } from '@jupyterlab/services' ;
4
+ import type { KernelMessage , ServerConnection } from '@jupyterlab/services' ;
5
5
import * as path from '../../platform/vscode-path/path' ;
6
6
import { ConfigurationTarget , Uri , window } from 'vscode' ;
7
7
import { IJupyterConnection } from '../types' ;
@@ -137,7 +137,36 @@ export function createJupyterConnectionInfo(
137
137
requestInit = { ...requestInit , agent : requestAgent } ;
138
138
}
139
139
140
- const { ServerConnection } = require ( '@jupyterlab/services' ) ;
140
+ const { ServerConnection } = require ( '@jupyterlab/services' ) as typeof import ( '@jupyterlab/services' ) ;
141
+ const { deserialize, serialize } =
142
+ require ( '@jupyterlab/services/lib/kernel/serialize' ) as typeof import ( '@jupyterlab/services/lib/kernel/serialize' ) ;
143
+ const { supportedKernelWebSocketProtocols } =
144
+ require ( '@jupyterlab/services/lib/kernel/messages' ) as typeof import ( '@jupyterlab/services/lib/kernel/messages' ) ;
145
+
146
+ const serializer : import ( '@jupyterlab/services' ) . ServerConnection . ISettings [ 'serializer' ] = {
147
+ deserialize : ( data : ArrayBuffer , protocol ?: string ) => {
148
+ try {
149
+ return deserialize ( data , protocol ) ;
150
+ } catch ( ex ) {
151
+ if ( protocol ) {
152
+ return deserialize ( data , '' ) ;
153
+ } else {
154
+ return deserialize ( data , supportedKernelWebSocketProtocols . v1KernelWebsocketJupyterOrg ) ;
155
+ }
156
+ }
157
+ } ,
158
+ serialize : ( msg : KernelMessage . IMessage , protocol ?: string ) => {
159
+ try {
160
+ return serialize ( msg , protocol ) ;
161
+ } catch ( ex ) {
162
+ if ( protocol ) {
163
+ return serialize ( msg , '' ) ;
164
+ } else {
165
+ return serialize ( msg , supportedKernelWebSocketProtocols . v1KernelWebsocketJupyterOrg ) ;
166
+ }
167
+ }
168
+ }
169
+ } ;
141
170
// This replaces the WebSocket constructor in jupyter lab services with our own implementation
142
171
// See _createSocket here:
143
172
// https://github.com/jupyterlab/jupyterlab/blob/cfc8ebda95e882b4ed2eefd54863bb8cdb0ab763/packages/services/src/kernel/default.ts
@@ -155,7 +184,8 @@ export function createJupyterConnectionInfo(
155
184
) as any ) ,
156
185
fetch : serverUri . fetch || requestCreator . getFetchMethod ( ) ,
157
186
Request : requestCreator . getRequestCtor ( undefined , allowUnauthorized , getAuthHeader ) ,
158
- Headers : requestCreator . getHeadersCtor ( )
187
+ Headers : requestCreator . getHeadersCtor ( ) ,
188
+ serializer
159
189
} ;
160
190
161
191
const connection : IJupyterConnection = {
0 commit comments