@blaxel/core 0.2.9-dev.75 → 0.2.9-dev.76

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.
@@ -1,3 +1,5 @@
1
1
  declare let fs: typeof import("fs") | null;
2
2
  declare let os: typeof import("os") | null;
3
- export { fs, os };
3
+ declare let path: typeof import("path") | null;
4
+ declare let FormData: typeof import("form-data") | null;
5
+ export { FormData, fs, os, path };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.os = exports.fs = void 0;
3
+ exports.path = exports.os = exports.fs = exports.FormData = void 0;
4
4
  /* eslint-disable */
5
5
  const isNode = typeof process !== "undefined" &&
6
6
  process.versions != null &&
@@ -9,10 +9,16 @@ let fs = null;
9
9
  exports.fs = fs;
10
10
  let os = null;
11
11
  exports.os = os;
12
+ let path = null;
13
+ exports.path = path;
14
+ let FormData = null;
15
+ exports.FormData = FormData;
12
16
  if (isNode) {
13
17
  try {
14
18
  exports.fs = fs = eval("require")("fs");
15
19
  exports.os = os = eval("require")("os");
20
+ exports.path = path = eval("require")("path");
21
+ exports.FormData = FormData = eval("require")("form-data");
16
22
  }
17
23
  catch (e) {
18
24
  console.warn("fs and os are not available in this environment");
@@ -24,7 +24,7 @@ export declare const deleteFilesystemByPath: <ThrowOnError extends boolean = fal
24
24
  */
25
25
  export declare const getFilesystemByPath: <ThrowOnError extends boolean = false>(options: Options<GetFilesystemByPathData, ThrowOnError>) => import("@hey-api/client-fetch").RequestResult<import("./types.gen").Directory | import("./types.gen").FileWithContent, import("./types.gen").ErrorResponse, ThrowOnError>;
26
26
  /**
27
- * Create or update file or directory
27
+ * Create or update a file or directory
28
28
  * Create or update a file or directory
29
29
  */
30
30
  export declare const putFilesystemByPath: <ThrowOnError extends boolean = false>(options: Options<PutFilesystemByPathData, ThrowOnError>) => import("@hey-api/client-fetch").RequestResult<import("./types.gen").SuccessResponse, import("./types.gen").ErrorResponse, ThrowOnError>;
@@ -78,9 +78,7 @@ export declare const deleteProcessByIdentifierKill: <ThrowOnError extends boolea
78
78
  * Get process logs
79
79
  * Get the stdout and stderr output of a process
80
80
  */
81
- export declare const getProcessByIdentifierLogs: <ThrowOnError extends boolean = false>(options: Options<GetProcessByIdentifierLogsData, ThrowOnError>) => import("@hey-api/client-fetch").RequestResult<{
82
- [key: string]: string;
83
- }, import("./types.gen").ErrorResponse, ThrowOnError>;
81
+ export declare const getProcessByIdentifierLogs: <ThrowOnError extends boolean = false>(options: Options<GetProcessByIdentifierLogsData, ThrowOnError>) => import("@hey-api/client-fetch").RequestResult<import("./types.gen").ProcessLogs, import("./types.gen").ErrorResponse, ThrowOnError>;
84
82
  /**
85
83
  * Stream process logs in real time
86
84
  * Streams the stdout and stderr output of a process in real time, one line per log, prefixed with 'stdout:' or 'stderr:'. Closes when the process exits or the client disconnects.
@@ -93,7 +91,7 @@ export declare const getProcessByIdentifierLogsStream: <ThrowOnError extends boo
93
91
  export declare const getWatchFilesystemByPath: <ThrowOnError extends boolean = false>(options: Options<GetWatchFilesystemByPathData, ThrowOnError>) => import("@hey-api/client-fetch").RequestResult<string, import("./types.gen").ErrorResponse, ThrowOnError>;
94
92
  /**
95
93
  * Stream process logs in real time via WebSocket
96
- * Streams the stdout and stderr output of a process in real time as JSON messages. Closes when the process exits or the client disconnects.
94
+ * Streams the stdout and stderr output of a process in real time as JSON messages.
97
95
  */
98
96
  export declare const getWsProcessByIdentifierLogsStream: <ThrowOnError extends boolean = false>(options: Options<GetWsProcessByIdentifierLogsStreamData, ThrowOnError>) => import("@hey-api/client-fetch").RequestResult<unknown, import("./types.gen").ErrorResponse, ThrowOnError>;
99
97
  /**
@@ -26,7 +26,7 @@ const getFilesystemByPath = (options) => {
26
26
  };
27
27
  exports.getFilesystemByPath = getFilesystemByPath;
28
28
  /**
29
- * Create or update file or directory
29
+ * Create or update a file or directory
30
30
  * Create or update a file or directory
31
31
  */
32
32
  const putFilesystemByPath = (options) => {
@@ -175,7 +175,7 @@ const getWatchFilesystemByPath = (options) => {
175
175
  exports.getWatchFilesystemByPath = getWatchFilesystemByPath;
176
176
  /**
177
177
  * Stream process logs in real time via WebSocket
178
- * Streams the stdout and stderr output of a process in real time as JSON messages. Closes when the process exits or the client disconnects.
178
+ * Streams the stdout and stderr output of a process in real time as JSON messages.
179
179
  */
180
180
  const getWsProcessByIdentifierLogsStream = (options) => {
181
181
  return (options.client ?? client_gen_1.client).get({
@@ -1,5 +1,6 @@
1
1
  export type Directory = {
2
2
  files?: Array<File>;
3
+ name?: string;
3
4
  path?: string;
4
5
  /**
5
6
  * @name Subdirectories
@@ -12,6 +13,7 @@ export type ErrorResponse = {
12
13
  export type File = {
13
14
  group?: string;
14
15
  lastModified?: string;
16
+ name?: string;
15
17
  owner?: string;
16
18
  path?: string;
17
19
  permissions?: string;
@@ -26,6 +28,7 @@ export type FileWithContent = {
26
28
  content?: string;
27
29
  group?: string;
28
30
  lastModified?: string;
31
+ name?: string;
29
32
  owner?: string;
30
33
  path?: string;
31
34
  permissions?: string;
@@ -40,6 +43,11 @@ export type PortMonitorRequest = {
40
43
  export type ProcessKillRequest = {
41
44
  signal?: string;
42
45
  };
46
+ export type ProcessLogs = {
47
+ logs?: string;
48
+ stderr?: string;
49
+ stdout?: string;
50
+ };
43
51
  export type ProcessRequest = {
44
52
  command: string;
45
53
  name?: string;
@@ -55,10 +63,11 @@ export type ProcessResponse = {
55
63
  name?: string;
56
64
  pid?: string;
57
65
  startedAt?: string;
58
- status?: string;
66
+ status?: 'failed' | 'killed' | 'stopped' | 'running' | 'completed';
59
67
  workingDir?: string;
60
68
  };
61
69
  export type Subdirectory = {
70
+ name?: string;
62
71
  path?: string;
63
72
  };
64
73
  export type SuccessResponse = {
@@ -86,6 +95,10 @@ export type DeleteFilesystemByPathErrors = {
86
95
  * File or directory not found
87
96
  */
88
97
  404: ErrorResponse;
98
+ /**
99
+ * Unprocessable entity
100
+ */
101
+ 422: ErrorResponse;
89
102
  /**
90
103
  * Internal server error
91
104
  */
@@ -115,6 +128,10 @@ export type GetFilesystemByPathErrors = {
115
128
  * File or directory not found
116
129
  */
117
130
  404: ErrorResponse;
131
+ /**
132
+ * Unprocessable entity
133
+ */
134
+ 422: ErrorResponse;
118
135
  /**
119
136
  * Internal server error
120
137
  */
@@ -130,7 +147,7 @@ export type GetFilesystemByPathResponses = {
130
147
  export type GetFilesystemByPathResponse = GetFilesystemByPathResponses[keyof GetFilesystemByPathResponses];
131
148
  export type PutFilesystemByPathData = {
132
149
  /**
133
- * File or directory information
150
+ * File or directory details
134
151
  */
135
152
  body: FileRequest;
136
153
  path: {
@@ -144,9 +161,13 @@ export type PutFilesystemByPathData = {
144
161
  };
145
162
  export type PutFilesystemByPathErrors = {
146
163
  /**
147
- * Invalid request
164
+ * Bad request
148
165
  */
149
166
  400: ErrorResponse;
167
+ /**
168
+ * Unprocessable entity
169
+ */
170
+ 422: ErrorResponse;
150
171
  /**
151
172
  * Internal server error
152
173
  */
@@ -176,6 +197,10 @@ export type DeleteNetworkProcessByPidMonitorErrors = {
176
197
  * Invalid process ID
177
198
  */
178
199
  400: ErrorResponse;
200
+ /**
201
+ * Unprocessable entity
202
+ */
203
+ 422: ErrorResponse;
179
204
  /**
180
205
  * Internal server error
181
206
  */
@@ -210,6 +235,10 @@ export type PostNetworkProcessByPidMonitorErrors = {
210
235
  * Invalid request
211
236
  */
212
237
  400: ErrorResponse;
238
+ /**
239
+ * Unprocessable entity
240
+ */
241
+ 422: ErrorResponse;
213
242
  /**
214
243
  * Internal server error
215
244
  */
@@ -241,6 +270,10 @@ export type GetNetworkProcessByPidPortsErrors = {
241
270
  * Invalid process ID
242
271
  */
243
272
  400: ErrorResponse;
273
+ /**
274
+ * Unprocessable entity
275
+ */
276
+ 422: ErrorResponse;
244
277
  /**
245
278
  * Internal server error
246
279
  */
@@ -283,6 +316,10 @@ export type PostProcessErrors = {
283
316
  * Invalid request
284
317
  */
285
318
  400: ErrorResponse;
319
+ /**
320
+ * Unprocessable entity
321
+ */
322
+ 422: ErrorResponse;
286
323
  /**
287
324
  * Internal server error
288
325
  */
@@ -312,6 +349,10 @@ export type DeleteProcessByIdentifierErrors = {
312
349
  * Process not found
313
350
  */
314
351
  404: ErrorResponse;
352
+ /**
353
+ * Unprocessable entity
354
+ */
355
+ 422: ErrorResponse;
315
356
  /**
316
357
  * Internal server error
317
358
  */
@@ -369,6 +410,10 @@ export type DeleteProcessByIdentifierKillErrors = {
369
410
  * Process not found
370
411
  */
371
412
  404: ErrorResponse;
413
+ /**
414
+ * Unprocessable entity
415
+ */
416
+ 422: ErrorResponse;
372
417
  /**
373
418
  * Internal server error
374
419
  */
@@ -398,6 +443,10 @@ export type GetProcessByIdentifierLogsErrors = {
398
443
  * Process not found
399
444
  */
400
445
  404: ErrorResponse;
446
+ /**
447
+ * Unprocessable entity
448
+ */
449
+ 422: ErrorResponse;
401
450
  /**
402
451
  * Internal server error
403
452
  */
@@ -408,9 +457,7 @@ export type GetProcessByIdentifierLogsResponses = {
408
457
  /**
409
458
  * Process logs
410
459
  */
411
- 200: {
412
- [key: string]: string;
413
- };
460
+ 200: ProcessLogs;
414
461
  };
415
462
  export type GetProcessByIdentifierLogsResponse = GetProcessByIdentifierLogsResponses[keyof GetProcessByIdentifierLogsResponses];
416
463
  export type GetProcessByIdentifierLogsStreamData = {
@@ -429,6 +476,10 @@ export type GetProcessByIdentifierLogsStreamErrors = {
429
476
  * Process not found
430
477
  */
431
478
  404: ErrorResponse;
479
+ /**
480
+ * Unprocessable entity
481
+ */
482
+ 422: ErrorResponse;
432
483
  /**
433
484
  * Internal server error
434
485
  */
@@ -450,7 +501,12 @@ export type GetWatchFilesystemByPathData = {
450
501
  */
451
502
  path: string;
452
503
  };
453
- query?: never;
504
+ query?: {
505
+ /**
506
+ * Ignore patterns (comma-separated)
507
+ */
508
+ ignore?: string;
509
+ };
454
510
  url: '/watch/filesystem/{path}';
455
511
  };
456
512
  export type GetWatchFilesystemByPathErrors = {
@@ -487,6 +543,10 @@ export type GetWsProcessByIdentifierLogsStreamErrors = {
487
543
  * Process not found
488
544
  */
489
545
  404: ErrorResponse;
546
+ /**
547
+ * Unprocessable entity
548
+ */
549
+ 422: ErrorResponse;
490
550
  /**
491
551
  * Internal server error
492
552
  */
@@ -7,15 +7,21 @@ export type CopyResponse = {
7
7
  destination: string;
8
8
  };
9
9
  export type WatchEvent = {
10
- op: "CREATE" | "WRITE" | "REMOVE";
10
+ op: "CREATE" | "WRITE" | "REMOVE" | "RENAME" | "CHMOD";
11
11
  path: string;
12
12
  name: string;
13
13
  content?: string;
14
14
  };
15
+ export type SandboxFilesystemFile = {
16
+ path: string;
17
+ content: string;
18
+ };
15
19
  export declare class SandboxFileSystem extends SandboxAction {
16
20
  constructor(sandbox: Sandbox);
17
21
  mkdir(path: string, permissions?: string): Promise<SuccessResponse>;
18
22
  write(path: string, content: string): Promise<SuccessResponse>;
23
+ writeBinary(path: string, content: Buffer | Blob | File | Uint8Array): Promise<any>;
24
+ writeTree(files: SandboxFilesystemFile[], destinationPath?: string | null): Promise<Directory | undefined>;
19
25
  read(path: string): Promise<string>;
20
26
  rm(path: string, recursive?: boolean): Promise<SuccessResponse>;
21
27
  ls(path: string): Promise<Directory>;
@@ -23,6 +29,7 @@ export declare class SandboxFileSystem extends SandboxAction {
23
29
  watch(path: string, callback: (fileEvent: WatchEvent) => void | Promise<void>, options?: {
24
30
  onError?: (error: Error) => void;
25
31
  withContent: boolean;
32
+ ignore?: string[];
26
33
  }): {
27
34
  close: () => void;
28
35
  };
@@ -1,6 +1,12 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.SandboxFileSystem = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ const node_js_1 = require("../common/node.js");
9
+ const settings_js_1 = require("../common/settings.js");
4
10
  const action_js_1 = require("./action.js");
5
11
  const index_js_1 = require("./client/index.js");
6
12
  class SandboxFileSystem extends action_js_1.SandboxAction {
@@ -29,6 +35,82 @@ class SandboxFileSystem extends action_js_1.SandboxAction {
29
35
  this.handleResponseError(response, data, error);
30
36
  return data;
31
37
  }
38
+ async writeBinary(path, content) {
39
+ path = this.formatPath(path);
40
+ let formData;
41
+ if (typeof globalThis !== "undefined" && typeof globalThis.FormData !== "undefined" && !(typeof process !== "undefined" && process.versions && process.versions.node)) {
42
+ // Browser environment
43
+ formData = new globalThis.FormData();
44
+ formData.append("permissions", "0644");
45
+ formData.append("path", path);
46
+ let fileContent;
47
+ if (content instanceof Blob || content instanceof File) {
48
+ fileContent = content;
49
+ }
50
+ else if (content instanceof Uint8Array) {
51
+ fileContent = new Blob([content]);
52
+ }
53
+ else {
54
+ fileContent = new Blob([content]);
55
+ }
56
+ formData.append("file", fileContent, "test-binary.bin");
57
+ }
58
+ else {
59
+ // Node.js environment
60
+ // @ts-expect-error: Only available in Node.js
61
+ formData = new node_js_1.FormData();
62
+ let fileContent;
63
+ if (Buffer.isBuffer(content)) {
64
+ fileContent = content;
65
+ }
66
+ else if (content instanceof Uint8Array) {
67
+ fileContent = Buffer.from(content);
68
+ }
69
+ else {
70
+ throw new Error("Unsupported content type in Node.js");
71
+ }
72
+ formData.append("file", fileContent, "test-binary.bin");
73
+ }
74
+ // Get the correct headers from form-data
75
+ const formHeaders = formData.getHeaders ? formData.getHeaders() : {};
76
+ let url = `${this.url}/filesystem/${path}`;
77
+ if (this.sandbox.forceUrl) {
78
+ url = `${this.sandbox.forceUrl}/filesystem/${path}`;
79
+ }
80
+ let headers = { ...settings_js_1.settings.headers, ...formHeaders };
81
+ if (this.sandbox.headers) {
82
+ headers = { ...headers, ...this.sandbox.headers };
83
+ }
84
+ const response = await axios_1.default.put(url, formData, {
85
+ headers,
86
+ });
87
+ if (response.status !== 200) {
88
+ throw new Error(response.data);
89
+ }
90
+ return response.data;
91
+ }
92
+ async writeTree(files, destinationPath = null) {
93
+ const options = {
94
+ body: {
95
+ files: files.reduce((acc, file) => {
96
+ acc[file.path] = file.content;
97
+ return acc;
98
+ }, {}),
99
+ },
100
+ baseUrl: this.url,
101
+ client: this.client,
102
+ };
103
+ const path = destinationPath ?? "";
104
+ const { response, data, error } = await this.client.put({
105
+ url: `/filesystem/tree/${path}`,
106
+ ...options,
107
+ headers: {
108
+ 'Content-Type': 'application/json',
109
+ }
110
+ });
111
+ this.handleResponseError(response, data, error);
112
+ return data;
113
+ }
32
114
  async read(path) {
33
115
  path = this.formatPath(path);
34
116
  const { response, data, error } = await (0, index_js_1.getFilesystemByPath)({
@@ -122,9 +204,14 @@ class SandboxFileSystem extends action_js_1.SandboxAction {
122
204
  let closed = false;
123
205
  let controller = new AbortController();
124
206
  const start = async () => {
207
+ const query = {};
208
+ if (options?.ignore) {
209
+ query.ignore = options.ignore.join(",");
210
+ }
125
211
  const { response, data, error } = await (0, index_js_1.getWatchFilesystemByPath)({
126
212
  client: this.client,
127
213
  path: { path },
214
+ query,
128
215
  baseUrl: this.url,
129
216
  parseAs: 'stream',
130
217
  signal: controller.signal,
@@ -163,7 +250,6 @@ class SandboxFileSystem extends action_js_1.SandboxAction {
163
250
  await callback({ ...fileEvent, content });
164
251
  }
165
252
  catch (e) {
166
- console.log(e);
167
253
  await callback({ ...fileEvent, content: undefined });
168
254
  }
169
255
  }
@@ -19,5 +19,5 @@ export declare class SandboxProcess extends SandboxAction {
19
19
  list(): Promise<GetProcessResponse>;
20
20
  stop(identifier: string): Promise<DeleteProcessByIdentifierResponse>;
21
21
  kill(identifier: string): Promise<DeleteProcessByIdentifierKillResponse>;
22
- logs(identifier: string, type?: "stdout" | "stderr"): Promise<string>;
22
+ logs(identifier: string, type?: "stdout" | "stderr" | "all"): Promise<string>;
23
23
  }
@@ -122,15 +122,21 @@ class SandboxProcess extends action_js_1.SandboxAction {
122
122
  this.handleResponseError(response, data, error);
123
123
  return data;
124
124
  }
125
- async logs(identifier, type = "stdout") {
125
+ async logs(identifier, type = "all") {
126
126
  const { response, data, error } = await (0, index_js_1.getProcessByIdentifierLogs)({
127
127
  path: { identifier },
128
128
  baseUrl: this.url,
129
129
  client: this.client,
130
130
  });
131
131
  this.handleResponseError(response, data, error);
132
- if (data && type in data) {
133
- return data[type];
132
+ if (type === "all") {
133
+ return data?.logs || "";
134
+ }
135
+ else if (type === "stdout") {
136
+ return data?.stdout || "";
137
+ }
138
+ else if (type === "stderr") {
139
+ return data?.stderr || "";
134
140
  }
135
141
  throw new Error("Unsupported log type");
136
142
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blaxel/core",
3
- "version": "0.2.9-dev.75",
3
+ "version": "0.2.9-dev.76",
4
4
  "description": "Blaxel Core SDK for TypeScript",
5
5
  "license": "MIT",
6
6
  "author": "Blaxel, INC (https://blaxel.ai)",
@@ -55,7 +55,9 @@
55
55
  "dependencies": {
56
56
  "@hey-api/client-fetch": "^0.10.0",
57
57
  "@modelcontextprotocol/sdk": "^1.11.0",
58
+ "axios": "^1.9.0",
58
59
  "dotenv": "^16.5.0",
60
+ "form-data": "^4.0.2",
59
61
  "jwt-decode": "^4.0.0",
60
62
  "toml": "^3.0.0",
61
63
  "uuid": "^11.1.0",