Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/conat/service/jupyter.ts
1452 views
1
/*
2
Services in a project/compute server for working with a Jupyter notebook.
3
*/
4
5
import { createServiceClient, createServiceHandler } from "./typed";
6
import type { KernelInfo } from "@cocalc/util/jupyter/types";
7
8
const service = "api";
9
10
export interface JupyterApi {
11
signal: (signal: string) => Promise<void>;
12
13
save_ipynb_file: (opts?: {
14
version?: number;
15
timeout?: number;
16
}) => Promise<void>;
17
18
kernel_info: () => Promise<KernelInfo>;
19
20
more_output: (id: string) => Promise<any[]>;
21
22
complete: (opts: { code: string; cursor_pos: number }) => Promise<any>;
23
24
introspect: (opts: {
25
code: string;
26
cursor_pos: number;
27
level: 0 | 1;
28
}) => Promise<any>;
29
30
store: (opts: { key: string; value?: any }) => Promise<any>;
31
32
comm: (opts: {
33
msg_id: string;
34
comm_id: string;
35
target_name: string;
36
data: any;
37
buffers64?: string[];
38
buffers?: Buffer[];
39
}) => Promise<void>;
40
41
ipywidgetsGetBuffer: (opts: {
42
model_id;
43
buffer_path;
44
}) => Promise<{ buffer64: string }>;
45
}
46
47
export type JupyterApiEndpoint = keyof JupyterApi;
48
49
export function jupyterApiClient({
50
project_id,
51
path,
52
timeout,
53
}: {
54
project_id: string;
55
path: string;
56
timeout?: number;
57
}) {
58
return createServiceClient<JupyterApi>({
59
project_id,
60
path,
61
service,
62
timeout,
63
});
64
}
65
66
export async function createConatJupyterService({
67
path,
68
project_id,
69
impl,
70
}: {
71
project_id: string;
72
path: string;
73
impl: JupyterApi;
74
}) {
75
return await createServiceHandler<JupyterApi>({
76
project_id,
77
path,
78
service,
79
impl,
80
description: "Jupyter notebook compute API",
81
});
82
}
83
84