jupyterpack 0.2.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/lib/document/commands.d.ts +8 -0
- package/lib/document/commands.js +76 -0
- package/lib/document/iframePanel.d.ts +4 -1
- package/lib/document/plugin.d.ts +2 -1
- package/lib/document/plugin.js +22 -4
- package/lib/document/toolbar.d.ts +9 -0
- package/lib/document/toolbar.js +20 -0
- package/lib/document/widgetFactory.d.ts +2 -1
- package/lib/document/widgetFactory.js +15 -6
- package/lib/index.d.ts +1 -1
- package/lib/pythonServer/dash/dashServer.d.ts +22 -0
- package/lib/pythonServer/dash/dashServer.js +47 -0
- package/lib/pythonServer/index.d.ts +5 -0
- package/lib/pythonServer/index.js +9 -0
- package/lib/pythonServer/kernelExecutor.d.ts +71 -0
- package/lib/pythonServer/kernelExecutor.js +140 -0
- package/lib/pythonServer/streamlit/streamlitServer.d.ts +14 -0
- package/lib/pythonServer/streamlit/streamlitServer.js +51 -0
- package/lib/pythonServer/tornado/tornadoServer.d.ts +34 -0
- package/lib/pythonServer/tornado/tornadoServer.js +68 -0
- package/lib/pythonWidget/comm.d.ts +11 -0
- package/lib/pythonWidget/comm.js +52 -0
- package/lib/pythonWidget/pythonWidget.d.ts +6 -0
- package/lib/pythonWidget/pythonWidget.js +28 -3
- package/lib/pythonWidget/pythonWidgetModel.d.ts +27 -6
- package/lib/pythonWidget/pythonWidgetModel.js +101 -15
- package/lib/sandpackWidget/sandpackFilesModel.d.ts +6 -2
- package/lib/sandpackWidget/sandpackFilesModel.js +13 -2
- package/lib/sandpackWidget/sandpackPanel.d.ts +10 -1
- package/lib/sandpackWidget/sandpackPanel.js +38 -3
- package/lib/swConnection/index.js +2 -2
- package/lib/{pythonWidget/connectionManager.d.ts → swConnection/mainConnectionManager.d.ts} +10 -0
- package/lib/swConnection/mainConnectionManager.js +93 -0
- package/lib/swConnection/sw.js +1 -1
- package/lib/swConnection/swCommManager.d.ts +11 -0
- package/lib/swConnection/{comm_manager.js → swCommManager.js} +5 -0
- package/lib/token.d.ts +2 -1
- package/lib/token.js +1 -0
- package/lib/tools.d.ts +9 -0
- package/lib/tools.js +75 -0
- package/lib/type.d.ts +64 -3
- package/lib/type.js +2 -0
- package/lib/websocket/websocket.d.ts +0 -0
- package/lib/websocket/websocket.js +152 -0
- package/package.json +8 -5
- package/src/document/commands.ts +91 -0
- package/src/document/iframePanel.ts +4 -1
- package/src/document/plugin.ts +28 -7
- package/src/document/toolbar.ts +39 -0
- package/src/document/widgetFactory.ts +17 -6
- package/src/global.d.ts +9 -0
- package/src/pythonServer/dash/dashServer.ts +66 -0
- package/src/pythonServer/index.ts +18 -0
- package/src/pythonServer/kernelExecutor.ts +243 -0
- package/src/pythonServer/streamlit/streamlitServer.ts +67 -0
- package/src/pythonServer/tornado/tornadoServer.ts +97 -0
- package/src/pythonWidget/comm.ts +65 -0
- package/src/pythonWidget/pythonWidget.ts +38 -3
- package/src/pythonWidget/pythonWidgetModel.ts +155 -34
- package/src/sandpackWidget/sandpackFilesModel.ts +17 -3
- package/src/sandpackWidget/sandpackPanel.ts +45 -4
- package/src/swConnection/index.ts +5 -2
- package/src/swConnection/mainConnectionManager.ts +121 -0
- package/src/swConnection/sw.ts +1 -1
- package/src/swConnection/{comm_manager.ts → swCommManager.ts} +6 -0
- package/src/token.ts +5 -1
- package/src/tools.ts +91 -0
- package/src/type.ts +76 -4
- package/src/websocket/websocket.ts +216 -0
- package/style/base.css +7 -0
- package/style/icons/autoreload.svg +16 -0
- package/style/icons/box.svg +12 -0
- package/style/icons/externallink.svg +10 -0
- package/lib/pythonWidget/connectionManager.js +0 -27
- package/lib/pythonWidget/kernelExecutor.d.ts +0 -27
- package/lib/pythonWidget/kernelExecutor.js +0 -104
- package/lib/swConnection/comm_manager.d.ts +0 -6
- package/lib/swConnection/connection_manager.d.ts +0 -18
- package/lib/swConnection/connection_manager.js +0 -27
- package/src/pythonWidget/connectionManager.ts +0 -43
- package/src/pythonWidget/kernelExecutor.ts +0 -140
- package/src/swConnection/connection_manager.ts +0 -43
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { UUID } from '@lumino/coreutils';
|
|
2
|
-
export class ConnectionManager {
|
|
3
|
-
constructor(instanceId) {
|
|
4
|
-
this.instanceId = instanceId;
|
|
5
|
-
this._kernelExecutors = new Map();
|
|
6
|
-
}
|
|
7
|
-
async registerConnection(kernelExecutor) {
|
|
8
|
-
const uuid = UUID.uuid4();
|
|
9
|
-
this._kernelExecutors.set(uuid, kernelExecutor);
|
|
10
|
-
return { instanceId: this.instanceId, kernelClientId: uuid };
|
|
11
|
-
}
|
|
12
|
-
async generateResponse(options) {
|
|
13
|
-
const { urlPath, kernelClientId, method, params, requestBody, headers } = options;
|
|
14
|
-
const executor = this._kernelExecutors.get(kernelClientId);
|
|
15
|
-
if (!executor) {
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
const response = await executor.getResponse({
|
|
19
|
-
urlPath,
|
|
20
|
-
method,
|
|
21
|
-
params,
|
|
22
|
-
headers,
|
|
23
|
-
requestBody
|
|
24
|
-
});
|
|
25
|
-
return response;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { IConnectionManager, IDict, IKernelExecutor } from '../type';
|
|
2
|
-
import { UUID } from '@lumino/coreutils';
|
|
3
|
-
|
|
4
|
-
export class ConnectionManager implements IConnectionManager {
|
|
5
|
-
constructor(public instanceId: string) {}
|
|
6
|
-
|
|
7
|
-
async registerConnection(
|
|
8
|
-
kernelExecutor: IKernelExecutor
|
|
9
|
-
): Promise<{ instanceId: string; kernelClientId: string }> {
|
|
10
|
-
const uuid = UUID.uuid4();
|
|
11
|
-
|
|
12
|
-
this._kernelExecutors.set(uuid, kernelExecutor);
|
|
13
|
-
|
|
14
|
-
return { instanceId: this.instanceId, kernelClientId: uuid };
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
async generateResponse(options: {
|
|
18
|
-
kernelClientId: string;
|
|
19
|
-
urlPath: string;
|
|
20
|
-
method: string;
|
|
21
|
-
headers: IDict;
|
|
22
|
-
requestBody?: ArrayBuffer;
|
|
23
|
-
params?: string;
|
|
24
|
-
}): Promise<IDict | null> {
|
|
25
|
-
const { urlPath, kernelClientId, method, params, requestBody, headers } =
|
|
26
|
-
options;
|
|
27
|
-
const executor = this._kernelExecutors.get(kernelClientId);
|
|
28
|
-
if (!executor) {
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const response = await executor.getResponse({
|
|
33
|
-
urlPath,
|
|
34
|
-
method,
|
|
35
|
-
params,
|
|
36
|
-
headers,
|
|
37
|
-
requestBody
|
|
38
|
-
});
|
|
39
|
-
return response;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
private _kernelExecutors = new Map<string, IKernelExecutor>();
|
|
43
|
-
}
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import { PageConfig, URLExt } from '@jupyterlab/coreutils';
|
|
2
|
-
import { KernelMessage, Session } from '@jupyterlab/services';
|
|
3
|
-
|
|
4
|
-
import { arrayBufferToBase64 } from '../tools';
|
|
5
|
-
import { IDict, IKernelExecutor } from '../type';
|
|
6
|
-
|
|
7
|
-
export class KernelExecutor implements IKernelExecutor {
|
|
8
|
-
constructor(options: KernelExecutor.IOptions) {
|
|
9
|
-
this._sessionConnection = options.sessionConnection;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
get isDisposed(): boolean {
|
|
13
|
-
return this._isDisposed;
|
|
14
|
-
}
|
|
15
|
-
async init(options: {
|
|
16
|
-
initCode?: string;
|
|
17
|
-
instanceId: string;
|
|
18
|
-
kernelClientId: string;
|
|
19
|
-
}) {
|
|
20
|
-
const { initCode, instanceId, kernelClientId } = options;
|
|
21
|
-
const labBaseUrl = PageConfig.getOption('baseUrl');
|
|
22
|
-
const baseURL = URLExt.join(
|
|
23
|
-
labBaseUrl,
|
|
24
|
-
'extensions/jupyterpack/static',
|
|
25
|
-
instanceId,
|
|
26
|
-
'dash',
|
|
27
|
-
kernelClientId,
|
|
28
|
-
'/'
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
const osCode = `
|
|
32
|
-
import os
|
|
33
|
-
os.environ['DASH_URL_BASE_PATHNAME'] = '${baseURL}'
|
|
34
|
-
`;
|
|
35
|
-
await this.executeCode({ code: osCode });
|
|
36
|
-
if (initCode) {
|
|
37
|
-
await this.executeCode({ code: initCode });
|
|
38
|
-
}
|
|
39
|
-
const serverCode = `
|
|
40
|
-
import httpx, json, base64
|
|
41
|
-
__monstra_transport = httpx.WSGITransport(app=app.server)
|
|
42
|
-
def __monstra_get_response(method, url, headers, content=None, params=None):
|
|
43
|
-
decoded_content = None
|
|
44
|
-
if content is not None:
|
|
45
|
-
content = base64.b64decode(content)
|
|
46
|
-
decoded_content = content.decode()
|
|
47
|
-
with httpx.Client(transport=__monstra_transport, base_url="http://testserver") as client:
|
|
48
|
-
r = client.request(method, url, headers=headers, content=content, params=params)
|
|
49
|
-
response = {
|
|
50
|
-
"headers": dict(r.headers),
|
|
51
|
-
"content": r.text,
|
|
52
|
-
"status_code": r.status_code,
|
|
53
|
-
"original_request": {"method": method, "url": url, "content": decoded_content, "params": params, "headers": headers},
|
|
54
|
-
}
|
|
55
|
-
json_str = json.dumps(response)
|
|
56
|
-
b64_str = base64.b64encode(json_str.encode("utf-8")).decode("utf-8")
|
|
57
|
-
return b64_str
|
|
58
|
-
`;
|
|
59
|
-
await this.executeCode({ code: serverCode });
|
|
60
|
-
}
|
|
61
|
-
async getResponse(options: {
|
|
62
|
-
method: string;
|
|
63
|
-
urlPath: string;
|
|
64
|
-
headers: IDict;
|
|
65
|
-
requestBody?: ArrayBuffer;
|
|
66
|
-
params?: string;
|
|
67
|
-
}): Promise<IDict> {
|
|
68
|
-
const { method, urlPath, requestBody, params, headers } = options;
|
|
69
|
-
const content = requestBody ? arrayBufferToBase64(requestBody) : undefined;
|
|
70
|
-
const code = `__monstra_get_response("${method}", "${urlPath}", headers=${JSON.stringify(headers)} , content=${content ? `"${content}"` : 'None'}, params=${params ? `"${params}"` : 'None'})`;
|
|
71
|
-
const raw = await this.executeCode({ code });
|
|
72
|
-
const jsonStr = atob(raw.slice(1, -1));
|
|
73
|
-
const obj = JSON.parse(jsonStr);
|
|
74
|
-
|
|
75
|
-
return obj;
|
|
76
|
-
}
|
|
77
|
-
async executeCode(
|
|
78
|
-
code: KernelMessage.IExecuteRequestMsg['content']
|
|
79
|
-
): Promise<string> {
|
|
80
|
-
const kernel = this._sessionConnection?.kernel;
|
|
81
|
-
if (!kernel) {
|
|
82
|
-
throw new Error('Session has no kernel.');
|
|
83
|
-
}
|
|
84
|
-
return new Promise<string>((resolve, reject) => {
|
|
85
|
-
const future = kernel.requestExecute(code, false, undefined);
|
|
86
|
-
const parentMsgid = future.msg.header.msg_id;
|
|
87
|
-
let executeResult = '';
|
|
88
|
-
future.onIOPub = (msg: KernelMessage.IIOPubMessage): void => {
|
|
89
|
-
const msgType = msg.header.msg_type;
|
|
90
|
-
switch (msgType) {
|
|
91
|
-
case 'execute_result': {
|
|
92
|
-
const content = (msg as KernelMessage.IExecuteResultMsg).content
|
|
93
|
-
.data['text/plain'] as string;
|
|
94
|
-
executeResult += content;
|
|
95
|
-
break;
|
|
96
|
-
}
|
|
97
|
-
case 'status': {
|
|
98
|
-
if (
|
|
99
|
-
(msg as KernelMessage.IStatusMsg).content.execution_state ===
|
|
100
|
-
'idle' &&
|
|
101
|
-
msg.parent_header.msg_id === parentMsgid
|
|
102
|
-
) {
|
|
103
|
-
resolve(executeResult);
|
|
104
|
-
}
|
|
105
|
-
break;
|
|
106
|
-
}
|
|
107
|
-
case 'stream': {
|
|
108
|
-
const content = (msg as KernelMessage.IStreamMsg).content.text;
|
|
109
|
-
executeResult += content;
|
|
110
|
-
break;
|
|
111
|
-
}
|
|
112
|
-
case 'error': {
|
|
113
|
-
console.error('Kernel operation failed', msg.content);
|
|
114
|
-
reject(msg.content);
|
|
115
|
-
break;
|
|
116
|
-
}
|
|
117
|
-
default:
|
|
118
|
-
break;
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
dispose(): void {
|
|
125
|
-
if (this._isDisposed) {
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
this._isDisposed = true;
|
|
129
|
-
this._sessionConnection.dispose();
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
private _isDisposed: boolean = false;
|
|
133
|
-
private _sessionConnection: Session.ISessionConnection;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
export namespace KernelExecutor {
|
|
137
|
-
export interface IOptions {
|
|
138
|
-
sessionConnection: Session.ISessionConnection;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { IConnectionManager, IDict, IKernelExecutor } from '../type';
|
|
2
|
-
import { UUID } from '@lumino/coreutils';
|
|
3
|
-
|
|
4
|
-
export class ConnectionManager implements IConnectionManager {
|
|
5
|
-
constructor(public instanceId: string) {}
|
|
6
|
-
|
|
7
|
-
async registerConnection(
|
|
8
|
-
kernelExecutor: IKernelExecutor
|
|
9
|
-
): Promise<{ instanceId: string; kernelClientId: string }> {
|
|
10
|
-
const uuid = UUID.uuid4();
|
|
11
|
-
|
|
12
|
-
this._kernelExecutors.set(uuid, kernelExecutor);
|
|
13
|
-
|
|
14
|
-
return { instanceId: this.instanceId, kernelClientId: uuid };
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
async generateResponse(options: {
|
|
18
|
-
kernelClientId: string;
|
|
19
|
-
urlPath: string;
|
|
20
|
-
method: string;
|
|
21
|
-
headers: IDict;
|
|
22
|
-
requestBody?: ArrayBuffer;
|
|
23
|
-
params?: string;
|
|
24
|
-
}): Promise<IDict | null> {
|
|
25
|
-
const { urlPath, kernelClientId, method, params, requestBody, headers } =
|
|
26
|
-
options;
|
|
27
|
-
const executor = this._kernelExecutors.get(kernelClientId);
|
|
28
|
-
if (!executor) {
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const response = await executor.getResponse({
|
|
33
|
-
urlPath,
|
|
34
|
-
method,
|
|
35
|
-
params,
|
|
36
|
-
headers,
|
|
37
|
-
requestBody
|
|
38
|
-
});
|
|
39
|
-
return response;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
private _kernelExecutors = new Map<string, IKernelExecutor>();
|
|
43
|
-
}
|