@daytonaio/sdk 0.0.0-dev

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.
Files changed (59) hide show
  1. package/README.md +146 -0
  2. package/package.json +39 -0
  3. package/src/Daytona.d.ts +331 -0
  4. package/src/Daytona.js +400 -0
  5. package/src/Daytona.js.map +1 -0
  6. package/src/FileSystem.d.ts +270 -0
  7. package/src/FileSystem.js +302 -0
  8. package/src/FileSystem.js.map +1 -0
  9. package/src/Git.d.ts +211 -0
  10. package/src/Git.js +275 -0
  11. package/src/Git.js.map +1 -0
  12. package/src/Image.d.ts +264 -0
  13. package/src/Image.js +565 -0
  14. package/src/Image.js.map +1 -0
  15. package/src/LspServer.d.ts +173 -0
  16. package/src/LspServer.js +209 -0
  17. package/src/LspServer.js.map +1 -0
  18. package/src/ObjectStorage.d.ts +85 -0
  19. package/src/ObjectStorage.js +231 -0
  20. package/src/ObjectStorage.js.map +1 -0
  21. package/src/Process.d.ts +246 -0
  22. package/src/Process.js +290 -0
  23. package/src/Process.js.map +1 -0
  24. package/src/Sandbox.d.ts +266 -0
  25. package/src/Sandbox.js +389 -0
  26. package/src/Sandbox.js.map +1 -0
  27. package/src/Snapshot.d.ts +116 -0
  28. package/src/Snapshot.js +187 -0
  29. package/src/Snapshot.js.map +1 -0
  30. package/src/Volume.d.ts +79 -0
  31. package/src/Volume.js +97 -0
  32. package/src/Volume.js.map +1 -0
  33. package/src/code-toolbox/SandboxPythonCodeToolbox.d.ts +11 -0
  34. package/src/code-toolbox/SandboxPythonCodeToolbox.js +358 -0
  35. package/src/code-toolbox/SandboxPythonCodeToolbox.js.map +1 -0
  36. package/src/code-toolbox/SandboxTsCodeToolbox.d.ts +5 -0
  37. package/src/code-toolbox/SandboxTsCodeToolbox.js +17 -0
  38. package/src/code-toolbox/SandboxTsCodeToolbox.js.map +1 -0
  39. package/src/errors/DaytonaError.d.ts +10 -0
  40. package/src/errors/DaytonaError.js +20 -0
  41. package/src/errors/DaytonaError.js.map +1 -0
  42. package/src/index.d.ts +15 -0
  43. package/src/index.js +32 -0
  44. package/src/index.js.map +1 -0
  45. package/src/types/Charts.d.ts +151 -0
  46. package/src/types/Charts.js +46 -0
  47. package/src/types/Charts.js.map +1 -0
  48. package/src/types/ExecuteResponse.d.ts +26 -0
  49. package/src/types/ExecuteResponse.js +7 -0
  50. package/src/types/ExecuteResponse.js.map +1 -0
  51. package/src/utils/ArtifactParser.d.ts +13 -0
  52. package/src/utils/ArtifactParser.js +55 -0
  53. package/src/utils/ArtifactParser.js.map +1 -0
  54. package/src/utils/Path.d.ts +1 -0
  55. package/src/utils/Path.js +61 -0
  56. package/src/utils/Path.js.map +1 -0
  57. package/src/utils/Stream.d.ts +13 -0
  58. package/src/utils/Stream.js +82 -0
  59. package/src/utils/Stream.js.map +1 -0
@@ -0,0 +1,187 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2025 Daytona Platforms Inc.
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.SnapshotService = void 0;
8
+ const api_client_1 = require("@daytonaio/api-client");
9
+ const DaytonaError_1 = require("./errors/DaytonaError");
10
+ const ObjectStorage_1 = require("./ObjectStorage");
11
+ const Stream_1 = require("./utils/Stream");
12
+ const SNAPSHOTS_FETCH_LIMIT = 200;
13
+ /**
14
+ * Service for managing Daytona Snapshots. Can be used to list, get, create and delete Snapshots.
15
+ *
16
+ * @class
17
+ */
18
+ class SnapshotService {
19
+ snapshotsApi;
20
+ objectStorageApi;
21
+ constructor(snapshotsApi, objectStorageApi) {
22
+ this.snapshotsApi = snapshotsApi;
23
+ this.objectStorageApi = objectStorageApi;
24
+ }
25
+ /**
26
+ * List all Snapshots.
27
+ *
28
+ * @returns {Promise<Snapshot[]>} List of all Snapshots accessible to the user
29
+ *
30
+ * @example
31
+ * const daytona = new Daytona();
32
+ * const snapshots = await daytona.snapshot.list();
33
+ * console.log(`Found ${snapshots.length} snapshots`);
34
+ * snapshots.forEach(snapshot => console.log(`${snapshot.name} (${snapshot.imageName})`));
35
+ */
36
+ async list() {
37
+ let response = await this.snapshotsApi.getAllSnapshots(undefined, SNAPSHOTS_FETCH_LIMIT);
38
+ if (response.data.total > SNAPSHOTS_FETCH_LIMIT) {
39
+ response = await this.snapshotsApi.getAllSnapshots(undefined, response.data.total);
40
+ }
41
+ return response.data.items;
42
+ }
43
+ /**
44
+ * Gets a Snapshot by its name.
45
+ *
46
+ * @param {string} name - Name of the Snapshot to retrieve
47
+ * @returns {Promise<Snapshot>} The requested Snapshot
48
+ * @throws {Error} If the Snapshot does not exist or cannot be accessed
49
+ *
50
+ * @example
51
+ * const daytona = new Daytona();
52
+ * const snapshot = await daytona.snapshot.get("snapshot-name");
53
+ * console.log(`Snapshot ${snapshot.name} is in state ${snapshot.state}`);
54
+ */
55
+ async get(name) {
56
+ const response = await this.snapshotsApi.getSnapshot(name);
57
+ return response.data;
58
+ }
59
+ /**
60
+ * Deletes a Snapshot.
61
+ *
62
+ * @param {Snapshot} snapshot - Snapshot to delete
63
+ * @returns {Promise<void>}
64
+ * @throws {Error} If the Snapshot does not exist or cannot be deleted
65
+ *
66
+ * @example
67
+ * const daytona = new Daytona();
68
+ * const snapshot = await daytona.snapshot.get("snapshot-name");
69
+ * await daytona.snapshot.delete(snapshot);
70
+ * console.log("Snapshot deleted successfully");
71
+ */
72
+ async delete(snapshot) {
73
+ await this.snapshotsApi.removeSnapshot(snapshot.id);
74
+ }
75
+ /**
76
+ * Creates and registers a new snapshot from the given Image definition.
77
+ *
78
+ * @param {CreateSnapshotParams} params - Parameters for snapshot creation.
79
+ * @param {object} options - Options for the create operation.
80
+ * @param {boolean} options.onLogs - This callback function handles snapshot creation logs.
81
+ * @param {number} options.timeout - Default is no timeout. Timeout in seconds (0 means no timeout).
82
+ * @returns {Promise<void>}
83
+ *
84
+ * @example
85
+ * const image = Image.debianSlim('3.12').pipInstall('numpy');
86
+ * await daytona.snapshot.create({ name: 'my-snapshot', image: image }, { onLogs: console.log });
87
+ */
88
+ async create(params, options = {}) {
89
+ const createSnapshotReq = {
90
+ name: params.name,
91
+ };
92
+ if (typeof params.image === 'string') {
93
+ createSnapshotReq.imageName = params.image;
94
+ createSnapshotReq.entrypoint = params.entrypoint;
95
+ }
96
+ else {
97
+ const contextHashes = await SnapshotService.processImageContext(this.objectStorageApi, params.image);
98
+ createSnapshotReq.buildInfo = {
99
+ contextHashes,
100
+ dockerfileContent: params.entrypoint
101
+ ? params.image.entrypoint(params.entrypoint).dockerfile
102
+ : params.image.dockerfile,
103
+ };
104
+ }
105
+ if (params.resources) {
106
+ createSnapshotReq.cpu = params.resources.cpu;
107
+ createSnapshotReq.gpu = params.resources.gpu;
108
+ createSnapshotReq.memory = params.resources.memory;
109
+ createSnapshotReq.disk = params.resources.disk;
110
+ }
111
+ let createdSnapshot = (await this.snapshotsApi.createSnapshot(createSnapshotReq, undefined, {
112
+ timeout: (options.timeout || 0) * 1000,
113
+ })).data;
114
+ if (!createdSnapshot) {
115
+ throw new DaytonaError_1.DaytonaError("Failed to create snapshot. Didn't receive a snapshot from the server API.");
116
+ }
117
+ const terminalStates = [api_client_1.SnapshotState.ACTIVE, api_client_1.SnapshotState.ERROR, api_client_1.SnapshotState.BUILD_FAILED];
118
+ const snapshotRef = { createdSnapshot: createdSnapshot };
119
+ let streamPromise;
120
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
121
+ const startLogStreaming = async (onChunk = () => { }) => {
122
+ if (!streamPromise) {
123
+ streamPromise = (0, Stream_1.processStreamingResponse)(() => this.snapshotsApi.getSnapshotBuildLogs(createdSnapshot.id, undefined, true, { responseType: 'stream' }), (chunk) => onChunk(chunk.trimEnd()), async () => terminalStates.includes(snapshotRef.createdSnapshot.state));
124
+ }
125
+ };
126
+ if (options.onLogs) {
127
+ options.onLogs(`Creating snapshot ${createdSnapshot.name} (${createdSnapshot.state})`);
128
+ if (createdSnapshot.state !== api_client_1.SnapshotState.BUILD_PENDING) {
129
+ await startLogStreaming(options.onLogs);
130
+ }
131
+ }
132
+ let previousState = createdSnapshot.state;
133
+ while (!terminalStates.includes(createdSnapshot.state)) {
134
+ if (options.onLogs && previousState !== createdSnapshot.state) {
135
+ if (createdSnapshot.state !== api_client_1.SnapshotState.BUILD_PENDING && !streamPromise) {
136
+ await startLogStreaming(options.onLogs);
137
+ }
138
+ options.onLogs(`Creating snapshot ${createdSnapshot.name} (${createdSnapshot.state})`);
139
+ previousState = createdSnapshot.state;
140
+ }
141
+ await new Promise((resolve) => setTimeout(resolve, 1000));
142
+ createdSnapshot = await this.get(createdSnapshot.name);
143
+ snapshotRef.createdSnapshot = createdSnapshot;
144
+ }
145
+ if (options.onLogs) {
146
+ if (streamPromise) {
147
+ await streamPromise;
148
+ }
149
+ if (createdSnapshot.state === api_client_1.SnapshotState.ACTIVE) {
150
+ options.onLogs(`Created snapshot ${createdSnapshot.name} (${createdSnapshot.state})`);
151
+ }
152
+ }
153
+ if (createdSnapshot.state === api_client_1.SnapshotState.ERROR || createdSnapshot.state === api_client_1.SnapshotState.BUILD_FAILED) {
154
+ const errMsg = `Failed to create snapshot. Name: ${createdSnapshot.name} Reason: ${createdSnapshot.errorReason}`;
155
+ throw new DaytonaError_1.DaytonaError(errMsg);
156
+ }
157
+ return createdSnapshot;
158
+ }
159
+ /**
160
+ * Processes the image contexts by uploading them to object storage
161
+ *
162
+ * @private
163
+ * @param {Image} image - The Image instance.
164
+ * @returns {Promise<string[]>} The list of context hashes stored in object storage.
165
+ */
166
+ static async processImageContext(objectStorageApi, image) {
167
+ if (!image.contextList || !image.contextList.length) {
168
+ return [];
169
+ }
170
+ const pushAccessCreds = (await objectStorageApi.getPushAccess()).data;
171
+ const objectStorage = new ObjectStorage_1.ObjectStorage({
172
+ endpointUrl: pushAccessCreds.storageUrl,
173
+ accessKeyId: pushAccessCreds.accessKey,
174
+ secretAccessKey: pushAccessCreds.secret,
175
+ sessionToken: pushAccessCreds.sessionToken,
176
+ bucketName: pushAccessCreds.bucket,
177
+ });
178
+ const contextHashes = [];
179
+ for (const context of image.contextList) {
180
+ const contextHash = await objectStorage.upload(context.sourcePath, pushAccessCreds.organizationId, context.archivePath);
181
+ contextHashes.push(contextHash);
182
+ }
183
+ return contextHashes;
184
+ }
185
+ }
186
+ exports.SnapshotService = SnapshotService;
187
+ //# sourceMappingURL=Snapshot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Snapshot.js","sourceRoot":"","sources":["../../../../libs/sdk-typescript/src/Snapshot.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,sDAAkH;AAClH,wDAAoD;AACpD,mDAA+C;AAG/C,2CAAyD;AAEzD,MAAM,qBAAqB,GAAG,GAAG,CAAA;AAyCjC;;;;GAIG;AACH,MAAa,eAAe;IAEhB;IACA;IAFV,YACU,YAA0B,EAC1B,gBAAkC;QADlC,iBAAY,GAAZ,YAAY,CAAc;QAC1B,qBAAgB,GAAhB,gBAAgB,CAAkB;IACzC,CAAC;IAEJ;;;;;;;;;;OAUG;IACH,KAAK,CAAC,IAAI;QACR,IAAI,QAAQ,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,eAAe,CAAC,SAAS,EAAE,qBAAqB,CAAC,CAAA;QACxF,IAAI,QAAQ,CAAC,IAAI,CAAC,KAAK,GAAG,qBAAqB,EAAE,CAAC;YAChD,QAAQ,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,eAAe,CAAC,SAAS,EAAE,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QACpF,CAAC;QACD,OAAO,QAAQ,CAAC,IAAI,CAAC,KAAmB,CAAA;IAC1C,CAAC;IAED;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,GAAG,CAAC,IAAY;QACpB,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;QAC1D,OAAO,QAAQ,CAAC,IAAgB,CAAA;IAClC,CAAC;IAED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MAAM,MAAM,GAAG,oCAAoC,eAAe,CAAC,IAAI,YAAY,eAAe,CAAC,WAAW,EAAE,CAAA;YAChH,MAAM,IAAI,2BAAY,CAAC,MAAM,CAAC,CAAA;QAChC,CAAC;QAED,OAAO,eAA2B,CAAA;IACpC,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAC,KAAK,CAAC,mBAAmB,CAAC,gBAAkC,EAAE,KAAY;QAC/E,IAAI,CAAC,KAAK,CAAC,WAAW,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC;YACpD,OAAO,EAAE,CAAA;QACX,CAAC;QAED,MAAM,eAAe,GAAG,CAAC,MAAM,gBAAgB,CAAC,aAAa,EAAE,CAAC,CAAC,IAAI,CAAA;QACrE,MAAM,aAAa,GAAG,IAAI,6BAAa,CAAC;YACtC,WAAW,EAAE,eAAe,CAAC,UAAU;YACvC,WAAW,EAAE,eAAe,CAAC,SAAS;YACtC,eAAe,EAAE,eAAe,CAAC,MAAM;YACvC,YAAY,EAAE,eAAe,CAAC,YAAY;YAC1C,UAAU,EAAE,eAAe,CAAC,MAAM;SACnC,CAAC,CAAA;QAEF,MAAM,aAAa,GAAG,EAAE,CAAA;QACxB,KAAK,MAAM,OAAO,IAAI,KAAK,CAAC,WAAW,EAAE,CAAC;YACxC,MAAM,WAAW,GAAG,MAAM,aAAa,CAAC,MAAM,CAC5C,OAAO,CAAC,UAAU,EAClB,eAAe,CAAC,cAAc,EAC9B,OAAO,CAAC,WAAW,CACpB,CAAA;YACD,aAAa,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;QACjC,CAAC;QAED,OAAO,aAAa,CAAA;IACtB,CAAC;CACF;AApMD,0CAoMC"}
@@ -0,0 +1,79 @@
1
+ import { VolumeDto, VolumesApi } from '@daytonaio/api-client';
2
+ /**
3
+ * Represents a Daytona Volume which is a shared storage volume for Sandboxes.
4
+ *
5
+ * @property {string} id - Unique identifier for the Volume
6
+ * @property {string} name - Name of the Volume
7
+ * @property {string} organizationId - Organization ID that owns the Volume
8
+ * @property {string} state - Current state of the Volume
9
+ * @property {string} createdAt - Date and time when the Volume was created
10
+ * @property {string} updatedAt - Date and time when the Volume was last updated
11
+ * @property {string} lastUsedAt - Date and time when the Volume was last used
12
+ */
13
+ export type Volume = VolumeDto & {
14
+ __brand: 'Volume';
15
+ };
16
+ /**
17
+ * Service for managing Daytona Volumes.
18
+ *
19
+ * This service provides methods to list, get, create, and delete Volumes.
20
+ *
21
+ * @class
22
+ */
23
+ export declare class VolumeService {
24
+ private volumesApi;
25
+ constructor(volumesApi: VolumesApi);
26
+ /**
27
+ * Lists all available Volumes.
28
+ *
29
+ * @returns {Promise<Volume[]>} List of all Volumes accessible to the user
30
+ *
31
+ * @example
32
+ * const daytona = new Daytona();
33
+ * const volumes = await daytona.volume.list();
34
+ * console.log(`Found ${volumes.length} volumes`);
35
+ * volumes.forEach(vol => console.log(`${vol.name} (${vol.id})`));
36
+ */
37
+ list(): Promise<Volume[]>;
38
+ /**
39
+ * Gets a Volume by its name.
40
+ *
41
+ * @param {string} name - Name of the Volume to retrieve
42
+ * @param {boolean} create - Whether to create the Volume if it does not exist
43
+ * @returns {Promise<Volume>} The requested Volume
44
+ * @throws {Error} If the Volume does not exist or cannot be accessed
45
+ *
46
+ * @example
47
+ * const daytona = new Daytona();
48
+ * const volume = await daytona.volume.get("volume-name", true);
49
+ * console.log(`Volume ${volume.name} is in state ${volume.state}`);
50
+ */
51
+ get(name: string, create?: boolean): Promise<Volume>;
52
+ /**
53
+ * Creates a new Volume with the specified name.
54
+ *
55
+ * @param {string} name - Name for the new Volume
56
+ * @returns {Promise<Volume>} The newly created Volume
57
+ * @throws {Error} If the Volume cannot be created
58
+ *
59
+ * @example
60
+ * const daytona = new Daytona();
61
+ * const volume = await daytona.volume.create("my-data-volume");
62
+ * console.log(`Created volume ${volume.name} with ID ${volume.id}`);
63
+ */
64
+ create(name: string): Promise<Volume>;
65
+ /**
66
+ * Deletes a Volume.
67
+ *
68
+ * @param {Volume} volume - Volume to delete
69
+ * @returns {Promise<void>}
70
+ * @throws {Error} If the Volume does not exist or cannot be deleted
71
+ *
72
+ * @example
73
+ * const daytona = new Daytona();
74
+ * const volume = await daytona.volume.get("volume-name");
75
+ * await daytona.volume.delete(volume);
76
+ * console.log("Volume deleted successfully");
77
+ */
78
+ delete(volume: Volume): Promise<void>;
79
+ }
package/src/Volume.js ADDED
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2025 Daytona Platforms Inc.
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.VolumeService = void 0;
8
+ const DaytonaError_1 = require("./errors/DaytonaError");
9
+ /**
10
+ * Service for managing Daytona Volumes.
11
+ *
12
+ * This service provides methods to list, get, create, and delete Volumes.
13
+ *
14
+ * @class
15
+ */
16
+ class VolumeService {
17
+ volumesApi;
18
+ constructor(volumesApi) {
19
+ this.volumesApi = volumesApi;
20
+ }
21
+ /**
22
+ * Lists all available Volumes.
23
+ *
24
+ * @returns {Promise<Volume[]>} List of all Volumes accessible to the user
25
+ *
26
+ * @example
27
+ * const daytona = new Daytona();
28
+ * const volumes = await daytona.volume.list();
29
+ * console.log(`Found ${volumes.length} volumes`);
30
+ * volumes.forEach(vol => console.log(`${vol.name} (${vol.id})`));
31
+ */
32
+ async list() {
33
+ const response = await this.volumesApi.listVolumes();
34
+ return response.data;
35
+ }
36
+ /**
37
+ * Gets a Volume by its name.
38
+ *
39
+ * @param {string} name - Name of the Volume to retrieve
40
+ * @param {boolean} create - Whether to create the Volume if it does not exist
41
+ * @returns {Promise<Volume>} The requested Volume
42
+ * @throws {Error} If the Volume does not exist or cannot be accessed
43
+ *
44
+ * @example
45
+ * const daytona = new Daytona();
46
+ * const volume = await daytona.volume.get("volume-name", true);
47
+ * console.log(`Volume ${volume.name} is in state ${volume.state}`);
48
+ */
49
+ async get(name, create = false) {
50
+ try {
51
+ const response = await this.volumesApi.getVolumeByName(name);
52
+ return response.data;
53
+ }
54
+ catch (error) {
55
+ if (error instanceof DaytonaError_1.DaytonaNotFoundError &&
56
+ create &&
57
+ error.message.match(/Volume with name ([\w-]+) not found/)) {
58
+ return await this.create(name);
59
+ }
60
+ throw error;
61
+ }
62
+ }
63
+ /**
64
+ * Creates a new Volume with the specified name.
65
+ *
66
+ * @param {string} name - Name for the new Volume
67
+ * @returns {Promise<Volume>} The newly created Volume
68
+ * @throws {Error} If the Volume cannot be created
69
+ *
70
+ * @example
71
+ * const daytona = new Daytona();
72
+ * const volume = await daytona.volume.create("my-data-volume");
73
+ * console.log(`Created volume ${volume.name} with ID ${volume.id}`);
74
+ */
75
+ async create(name) {
76
+ const response = await this.volumesApi.createVolume({ name });
77
+ return response.data;
78
+ }
79
+ /**
80
+ * Deletes a Volume.
81
+ *
82
+ * @param {Volume} volume - Volume to delete
83
+ * @returns {Promise<void>}
84
+ * @throws {Error} If the Volume does not exist or cannot be deleted
85
+ *
86
+ * @example
87
+ * const daytona = new Daytona();
88
+ * const volume = await daytona.volume.get("volume-name");
89
+ * await daytona.volume.delete(volume);
90
+ * console.log("Volume deleted successfully");
91
+ */
92
+ async delete(volume) {
93
+ await this.volumesApi.deleteVolume(volume.id);
94
+ }
95
+ }
96
+ exports.VolumeService = VolumeService;
97
+ //# sourceMappingURL=Volume.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Volume.js","sourceRoot":"","sources":["../../../../libs/sdk-typescript/src/Volume.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,wDAA4D;AAe5D;;;;;;GAMG;AACH,MAAa,aAAa;IACJ;IAApB,YAAoB,UAAsB;QAAtB,eAAU,GAAV,UAAU,CAAY;IAAG,CAAC;IAE9C;;;;;;;;;;OAUG;IACH,KAAK,CAAC,IAAI;QACR,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,EAAE,CAAA;QACpD,OAAO,QAAQ,CAAC,IAAgB,CAAA;IAClC,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,KAAK,CAAC,GAAG,CAAC,IAAY,EAAE,MAAM,GAAG,KAAK;QACpC,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC,IAAI,CAAC,CAAA;YAC5D,OAAO,QAAQ,CAAC,IAAc,CAAA;QAChC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IACE,KAAK,YAAY,mCAAoB;gBACrC,MAAM;gBACN,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,qCAAqC,CAAC,EAC1D,CAAC;gBACD,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;YAChC,CAAC;YACD,MAAM,KAAK,CAAA;QACb,CAAC;IACH,CAAC;IAED;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,MAAM,CAAC,IAAY;QACvB,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,CAAC,CAAA;QAC7D,OAAO,QAAQ,CAAC,IAAc,CAAA;IAChC,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,KAAK,CAAC,MAAM,CAAC,MAAc;QACzB,MAAM,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;IAC/C,CAAC;CACF;AAjFD,sCAiFC"}
@@ -0,0 +1,11 @@
1
+ import { SandboxCodeToolbox } from '../Sandbox';
2
+ import { CodeRunParams } from '../Process';
3
+ export declare class SandboxPythonCodeToolbox implements SandboxCodeToolbox {
4
+ getRunCommand(code: string, params?: CodeRunParams): string;
5
+ /**
6
+ * Checks if matplotlib is imported in the given Python code string.
7
+ * @param codeString Python code as a string
8
+ * @returns True if matplotlib is imported, false otherwise
9
+ */
10
+ private static isMatplotlibImported;
11
+ }