@blaxel/core 0.2.15-dev.95 → 0.2.15-dev.97

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.
@@ -2,5 +2,4 @@ declare let fs: typeof import("fs") | null;
2
2
  declare let os: typeof import("os") | null;
3
3
  declare let path: typeof import("path") | null;
4
4
  declare let dotenv: typeof import("dotenv") | null;
5
- declare let FormData: typeof import("form-data") | null;
6
- export { dotenv, FormData, fs, os, path };
5
+ export { dotenv, fs, os, path };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.path = exports.os = exports.fs = exports.FormData = exports.dotenv = void 0;
3
+ exports.path = exports.os = exports.fs = exports.dotenv = void 0;
4
4
  /* eslint-disable */
5
5
  const isNode = typeof process !== "undefined" &&
6
6
  process.versions != null &&
@@ -13,15 +13,12 @@ let path = null;
13
13
  exports.path = path;
14
14
  let dotenv = null;
15
15
  exports.dotenv = dotenv;
16
- let FormData = null;
17
- exports.FormData = FormData;
18
16
  if (isNode) {
19
17
  try {
20
18
  exports.fs = fs = eval("require")("fs");
21
19
  exports.os = os = eval("require")("os");
22
20
  exports.path = path = eval("require")("path");
23
21
  exports.dotenv = dotenv = eval("require")("dotenv");
24
- exports.FormData = FormData = eval("require")("form-data");
25
22
  }
26
23
  catch (e) {
27
24
  console.warn("fs and os are not available in this environment");
@@ -6,7 +6,7 @@ export declare class SandboxFileSystem extends SandboxAction {
6
6
  constructor(sandbox: Sandbox);
7
7
  mkdir(path: string, permissions?: string): Promise<SuccessResponse>;
8
8
  write(path: string, content: string): Promise<SuccessResponse>;
9
- writeBinary(path: string, content: Buffer | Blob | File | Uint8Array): Promise<any>;
9
+ writeBinary(path: string, content: Buffer | Blob | File | Uint8Array): Promise<unknown>;
10
10
  writeTree(files: SandboxFilesystemFile[], destinationPath?: string | null): Promise<Directory | undefined>;
11
11
  read(path: string): Promise<string>;
12
12
  rm(path: string, recursive?: boolean): Promise<SuccessResponse>;
@@ -1,11 +1,6 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.SandboxFileSystem = void 0;
7
- const axios_1 = __importDefault(require("axios"));
8
- const node_js_1 = require("../../common/node.js");
9
4
  const settings_js_1 = require("../../common/settings.js");
10
5
  const action_js_1 = require("../action.js");
11
6
  const index_js_1 = require("../client/index.js");
@@ -37,57 +32,45 @@ class SandboxFileSystem extends action_js_1.SandboxAction {
37
32
  }
38
33
  async writeBinary(path, content) {
39
34
  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");
35
+ const formData = new FormData();
36
+ // Convert content to Blob regardless of input type
37
+ let fileBlob;
38
+ if (content instanceof Blob || content instanceof File) {
39
+ fileBlob = content;
40
+ }
41
+ else if (Buffer.isBuffer(content)) {
42
+ // Convert Buffer to Blob
43
+ fileBlob = new Blob([content]);
44
+ }
45
+ else if (content instanceof Uint8Array) {
46
+ // Convert Uint8Array to Blob
47
+ fileBlob = new Blob([content]);
57
48
  }
58
49
  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");
50
+ throw new Error("Unsupported content type");
73
51
  }
74
- // Get the correct headers from form-data
75
- const formHeaders = formData.getHeaders ? formData.getHeaders() : {};
52
+ // Append the file as a Blob
53
+ formData.append("file", fileBlob, "test-binary.bin");
54
+ formData.append("permissions", "0644");
55
+ formData.append("path", path);
56
+ // Build URL
76
57
  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 };
58
+ if (this.forcedUrl) {
59
+ url = `${this.forcedUrl}/filesystem/${path}`;
83
60
  }
84
- const response = await axios_1.default.put(url, formData, {
85
- headers,
61
+ // Make the request using fetch instead of axios for better FormData handling
62
+ const response = await fetch(url, {
63
+ method: 'PUT',
64
+ headers: {
65
+ ...settings_js_1.settings.headers,
66
+ },
67
+ body: formData,
86
68
  });
87
- if (response.status !== 200) {
88
- throw new Error(response.data);
69
+ if (!response.ok) {
70
+ const errorText = await response.text();
71
+ throw new Error(`Failed to write binary: ${response.status} ${errorText}`);
89
72
  }
90
- return response.data;
73
+ return await response.json();
91
74
  }
92
75
  async writeTree(files, destinationPath = null) {
93
76
  const options = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blaxel/core",
3
- "version": "0.2.15-dev.95",
3
+ "version": "0.2.15-dev.97",
4
4
  "description": "Blaxel Core SDK for TypeScript",
5
5
  "license": "MIT",
6
6
  "author": "Blaxel, INC (https://blaxel.ai)",