From 5bc7185dc2275a8bb69ad2de955eb5dcdae9dea9 Mon Sep 17 00:00:00 2001 From: Jonathan McPherson Date: Tue, 10 Dec 2024 11:02:18 -0800 Subject: [PATCH 1/3] regenerate API with new fields --- .../src/kcclient/.openapi-generator/FILES | 2 + .../src/kcclient/api/defaultApi.ts | 70 +++++++++++ .../src/kcclient/model/adoptedSession.ts | 42 +++++++ .../src/kcclient/model/connectionInfo.ts | 109 ++++++++++++++++++ .../src/kcclient/model/models.ts | 6 + .../src/kcclient/model/newSession.ts | 9 ++ 6 files changed, 238 insertions(+) create mode 100644 extensions/positron-supervisor/src/kcclient/model/adoptedSession.ts create mode 100644 extensions/positron-supervisor/src/kcclient/model/connectionInfo.ts diff --git a/extensions/positron-supervisor/src/kcclient/.openapi-generator/FILES b/extensions/positron-supervisor/src/kcclient/.openapi-generator/FILES index aa0614849ba..29853d7ec5e 100644 --- a/extensions/positron-supervisor/src/kcclient/.openapi-generator/FILES +++ b/extensions/positron-supervisor/src/kcclient/.openapi-generator/FILES @@ -4,6 +4,8 @@ api/apis.ts api/defaultApi.ts git_push.sh model/activeSession.ts +model/adoptedSession.ts +model/connectionInfo.ts model/executionQueue.ts model/interruptMode.ts model/modelError.ts diff --git a/extensions/positron-supervisor/src/kcclient/api/defaultApi.ts b/extensions/positron-supervisor/src/kcclient/api/defaultApi.ts index 8056d7edd21..3cd6bed4a83 100644 --- a/extensions/positron-supervisor/src/kcclient/api/defaultApi.ts +++ b/extensions/positron-supervisor/src/kcclient/api/defaultApi.ts @@ -16,6 +16,7 @@ import http from 'http'; /* tslint:disable:no-unused-locals */ import { ActiveSession } from '../model/activeSession'; +import { AdoptedSession } from '../model/adoptedSession'; import { ModelError } from '../model/modelError'; import { NewSession } from '../model/newSession'; import { NewSession200Response } from '../model/newSession200Response'; @@ -98,6 +99,75 @@ export class DefaultApi { this.interceptors.push(interceptor); } + /** + * + * @summary Adopt an existing session + * @param adoptedSession + */ + public async adoptSession (adoptedSession: AdoptedSession, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: NewSession200Response; }> { + const localVarPath = this.basePath + '/sessions/adopt'; + let localVarQueryParameters: any = {}; + let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders); + const produces = ['application/json']; + // give precedence to 'application/json' + if (produces.indexOf('application/json') >= 0) { + localVarHeaderParams.Accept = 'application/json'; + } else { + localVarHeaderParams.Accept = produces.join(','); + } + let localVarFormParams: any = {}; + + // verify required parameter 'adoptedSession' is not null or undefined + if (adoptedSession === null || adoptedSession === undefined) { + throw new Error('Required parameter adoptedSession was null or undefined when calling adoptSession.'); + } + + (Object).assign(localVarHeaderParams, options.headers); + + let localVarUseFormData = false; + + let localVarRequestOptions: localVarRequest.Options = { + method: 'PUT', + qs: localVarQueryParameters, + headers: localVarHeaderParams, + uri: localVarPath, + useQuerystring: this._useQuerystring, + json: true, + body: ObjectSerializer.serialize(adoptedSession, "AdoptedSession") + }; + + let authenticationPromise = Promise.resolve(); + authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); + + let interceptorPromise = authenticationPromise; + for (const interceptor of this.interceptors) { + interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions)); + } + + return interceptorPromise.then(() => { + if (Object.keys(localVarFormParams).length) { + if (localVarUseFormData) { + (localVarRequestOptions).formData = localVarFormParams; + } else { + localVarRequestOptions.form = localVarFormParams; + } + } + return new Promise<{ response: http.IncomingMessage; body: NewSession200Response; }>((resolve, reject) => { + localVarRequest(localVarRequestOptions, (error, response, body) => { + if (error) { + reject(error); + } else { + if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { + body = ObjectSerializer.deserialize(body, "NewSession200Response"); + resolve({ response: response, body: body }); + } else { + reject(new HttpError(response, body, response.statusCode)); + } + } + }); + }); + }); + } /** * * @summary Upgrade to a WebSocket for channel communication diff --git a/extensions/positron-supervisor/src/kcclient/model/adoptedSession.ts b/extensions/positron-supervisor/src/kcclient/model/adoptedSession.ts new file mode 100644 index 00000000000..b094e6b27a5 --- /dev/null +++ b/extensions/positron-supervisor/src/kcclient/model/adoptedSession.ts @@ -0,0 +1,42 @@ +/** + * Kallichore API + * Kallichore is a Jupyter kernel gateway and supervisor + * + * The version of the OpenAPI document: 1.0.0 + * Contact: info@posit.co + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +import { RequestFile } from './models'; +import { ConnectionInfo } from './connectionInfo'; +import { NewSession } from './newSession'; + +/** +* The session to adopt +*/ +export class AdoptedSession { + 'session': NewSession; + 'connectionInfo': ConnectionInfo; + + static discriminator: string | undefined = undefined; + + static attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [ + { + "name": "session", + "baseName": "session", + "type": "NewSession" + }, + { + "name": "connectionInfo", + "baseName": "connection_info", + "type": "ConnectionInfo" + } ]; + + static getAttributeTypeMap() { + return AdoptedSession.attributeTypeMap; + } +} + diff --git a/extensions/positron-supervisor/src/kcclient/model/connectionInfo.ts b/extensions/positron-supervisor/src/kcclient/model/connectionInfo.ts new file mode 100644 index 00000000000..59c5ecb7e55 --- /dev/null +++ b/extensions/positron-supervisor/src/kcclient/model/connectionInfo.ts @@ -0,0 +1,109 @@ +/** + * Kallichore API + * Kallichore is a Jupyter kernel gateway and supervisor + * + * The version of the OpenAPI document: 1.0.0 + * Contact: info@posit.co + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +import { RequestFile } from './models'; + +/** +* Connection information for an existing session +*/ +export class ConnectionInfo { + /** + * The port for control messages + */ + 'controlPort': number; + /** + * The port for shell messages + */ + 'shellPort': number; + /** + * The port for stdin messages + */ + 'stdinPort': number; + /** + * The port for heartbeat messages + */ + 'hbPort': number; + /** + * The port for IOPub messages + */ + 'iopubPort': number; + /** + * The signature scheme for messages + */ + 'signatureScheme': string; + /** + * The key for messages + */ + 'key': string; + /** + * The transport protocol + */ + 'transport': string; + /** + * The IP address for the connection + */ + 'ip': string; + + static discriminator: string | undefined = undefined; + + static attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [ + { + "name": "controlPort", + "baseName": "control_port", + "type": "number" + }, + { + "name": "shellPort", + "baseName": "shell_port", + "type": "number" + }, + { + "name": "stdinPort", + "baseName": "stdin_port", + "type": "number" + }, + { + "name": "hbPort", + "baseName": "hb_port", + "type": "number" + }, + { + "name": "iopubPort", + "baseName": "iopub_port", + "type": "number" + }, + { + "name": "signatureScheme", + "baseName": "signature_scheme", + "type": "string" + }, + { + "name": "key", + "baseName": "key", + "type": "string" + }, + { + "name": "transport", + "baseName": "transport", + "type": "string" + }, + { + "name": "ip", + "baseName": "ip", + "type": "string" + } ]; + + static getAttributeTypeMap() { + return ConnectionInfo.attributeTypeMap; + } +} + diff --git a/extensions/positron-supervisor/src/kcclient/model/models.ts b/extensions/positron-supervisor/src/kcclient/model/models.ts index 31465e3cbf2..dd9ed9fd296 100644 --- a/extensions/positron-supervisor/src/kcclient/model/models.ts +++ b/extensions/positron-supervisor/src/kcclient/model/models.ts @@ -1,6 +1,8 @@ import localVarRequest from 'request'; export * from './activeSession'; +export * from './adoptedSession'; +export * from './connectionInfo'; export * from './executionQueue'; export * from './interruptMode'; export * from './modelError'; @@ -25,6 +27,8 @@ export type RequestFile = string | Buffer | fs.ReadStream | RequestDetailedFile; import { ActiveSession } from './activeSession'; +import { AdoptedSession } from './adoptedSession'; +import { ConnectionInfo } from './connectionInfo'; import { ExecutionQueue } from './executionQueue'; import { InterruptMode } from './interruptMode'; import { ModelError } from './modelError'; @@ -54,6 +58,8 @@ let enumsMap: {[index: string]: any} = { let typeMap: {[index: string]: any} = { "ActiveSession": ActiveSession, + "AdoptedSession": AdoptedSession, + "ConnectionInfo": ConnectionInfo, "ExecutionQueue": ExecutionQueue, "ModelError": ModelError, "NewSession": NewSession, diff --git a/extensions/positron-supervisor/src/kcclient/model/newSession.ts b/extensions/positron-supervisor/src/kcclient/model/newSession.ts index 565fbd30fb8..d6294de749b 100644 --- a/extensions/positron-supervisor/src/kcclient/model/newSession.ts +++ b/extensions/positron-supervisor/src/kcclient/model/newSession.ts @@ -50,6 +50,10 @@ export class NewSession { * Environment variables to set for the session */ 'env': { [key: string]: string; }; + /** + * The number of seconds to wait for a connection to the session\'s ZeroMQ sockets before timing out + */ + 'connectionTimeout'?: number = 30; 'interruptMode': InterruptMode; static discriminator: string | undefined = undefined; @@ -100,6 +104,11 @@ export class NewSession { "baseName": "env", "type": "{ [key: string]: string; }" }, + { + "name": "connectionTimeout", + "baseName": "connection_timeout", + "type": "number" + }, { "name": "interruptMode", "baseName": "interrupt_mode", From 6fde22a3906e13441440a56cf40dbd6d3f1f1842 Mon Sep 17 00:00:00 2001 From: Jonathan McPherson Date: Tue, 10 Dec 2024 11:21:31 -0800 Subject: [PATCH 2/3] respect connection timeout --- extensions/positron-supervisor/package.json | 5 +++++ extensions/positron-supervisor/package.nls.json | 1 + extensions/positron-supervisor/src/KallichoreSession.ts | 4 +++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/extensions/positron-supervisor/package.json b/extensions/positron-supervisor/package.json index 2e5e38564e2..43271fc1de8 100644 --- a/extensions/positron-supervisor/package.json +++ b/extensions/positron-supervisor/package.json @@ -39,6 +39,11 @@ "default": false, "description": "%configuration.showTerminal.description%" }, + "positronKernelSupervisor.connectionTimeout": { + "type": "integer", + "default": 30, + "description": "%configuration.connectionTimeout.description%" + }, "positronKernelSupervisor.logLevel": { "scope": "window", "type": "string", diff --git a/extensions/positron-supervisor/package.nls.json b/extensions/positron-supervisor/package.nls.json index ce4d37addbb..8f4b97ae176 100644 --- a/extensions/positron-supervisor/package.nls.json +++ b/extensions/positron-supervisor/package.nls.json @@ -9,6 +9,7 @@ "configuration.logLevel.description": "Log level for the kernel supervisor (restart Positron to apply)", "configuration.enable.description": "Run Jupyter kernels under the Positron kernel supervisor.", "configuration.showTerminal.description": "Show the host terminal for the Positron kernel supervisor", + "configuration.connectionTimeout.description": "Timeout in seconds for connecting to the kernel's sockets", "configuration.attachOnStartup.description": "Run before starting up Jupyter kernel (when supported)", "configuration.sleepOnStartup.description": "Sleep for n seconds before starting up Jupyter kernel (when supported)", "command.positron.supervisor.category": "Kernel Supervisor", diff --git a/extensions/positron-supervisor/src/KallichoreSession.ts b/extensions/positron-supervisor/src/KallichoreSession.ts index 4bb8333ac85..8bac75d7a81 100644 --- a/extensions/positron-supervisor/src/KallichoreSession.ts +++ b/extensions/positron-supervisor/src/KallichoreSession.ts @@ -254,6 +254,7 @@ export class KallichoreSession implements JupyterLanguageRuntimeSession { const config = vscode.workspace.getConfiguration('positronKernelSupervisor'); const attachOnStartup = config.get('attachOnStartup', false) && this._extra?.attachOnStartup; const sleepOnStartup = config.get('sleepOnStartup', undefined) && this._extra?.sleepOnStartup; + const connectionTimeout = config.get('connectionTimeout', 30); if (attachOnStartup) { this._extra!.attachOnStartup!.init(args); } @@ -273,7 +274,8 @@ export class KallichoreSession implements JupyterLanguageRuntimeSession { env, workingDirectory: workingDir, username: os.userInfo().username, - interruptMode + interruptMode, + connectionTimeout, }; await this._api.newSession(session); this.log(`${kernelSpec.display_name} session '${this.metadata.sessionId}' created in ${workingDir} with command:`, vscode.LogLevel.Info); From c4aa8fbab9678c468d45c878f3038288ab38fc1b Mon Sep 17 00:00:00 2001 From: Jonathan McPherson Date: Tue, 10 Dec 2024 11:56:35 -0800 Subject: [PATCH 3/3] bump kallichore version --- extensions/positron-supervisor/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/positron-supervisor/package.json b/extensions/positron-supervisor/package.json index 43271fc1de8..fe381b41a62 100644 --- a/extensions/positron-supervisor/package.json +++ b/extensions/positron-supervisor/package.json @@ -102,7 +102,7 @@ }, "positron": { "binaryDependencies": { - "kallichore": "0.1.21" + "kallichore": "0.1.22" } }, "dependencies": {