@blaxel/core 0.3.34 → 0.3.35-preview.343
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/dist/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/common/settings.js +2 -2
- package/dist/cjs/sandbox/filesystem/copy-no-overwrite.js +20 -0
- package/dist/cjs/sandbox/filesystem/filesystem.js +49 -1
- package/dist/cjs/sandbox/filesystem/index.js +3 -0
- package/dist/cjs/types/sandbox/filesystem/copy-no-overwrite.d.ts +13 -0
- package/dist/cjs/types/sandbox/filesystem/filesystem.d.ts +3 -1
- package/dist/cjs/types/sandbox/filesystem/index.d.ts +1 -0
- package/dist/cjs-browser/.tsbuildinfo +1 -1
- package/dist/cjs-browser/common/settings.js +2 -2
- package/dist/cjs-browser/sandbox/filesystem/copy-no-overwrite.js +20 -0
- package/dist/cjs-browser/sandbox/filesystem/filesystem.js +49 -1
- package/dist/cjs-browser/sandbox/filesystem/index.js +3 -0
- package/dist/cjs-browser/types/sandbox/filesystem/copy-no-overwrite.d.ts +13 -0
- package/dist/cjs-browser/types/sandbox/filesystem/filesystem.d.ts +3 -1
- package/dist/cjs-browser/types/sandbox/filesystem/index.d.ts +1 -0
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/common/settings.js +2 -2
- package/dist/esm/sandbox/filesystem/copy-no-overwrite.js +16 -0
- package/dist/esm/sandbox/filesystem/filesystem.js +49 -1
- package/dist/esm/sandbox/filesystem/index.js +1 -0
- package/dist/esm-browser/.tsbuildinfo +1 -1
- package/dist/esm-browser/common/settings.js +2 -2
- package/dist/esm-browser/sandbox/filesystem/copy-no-overwrite.js +16 -0
- package/dist/esm-browser/sandbox/filesystem/filesystem.js +49 -1
- package/dist/esm-browser/sandbox/filesystem/index.js +1 -0
- package/package.json +2 -2
|
@@ -30,8 +30,8 @@ function missingCredentialsMessage() {
|
|
|
30
30
|
return "No Blaxel credentials found. Set the BL_API_KEY and BL_WORKSPACE environment variables, or run `bl login`.";
|
|
31
31
|
}
|
|
32
32
|
// Build info - these placeholders are replaced at build time by build:replace-imports
|
|
33
|
-
const BUILD_VERSION = "0.3.
|
|
34
|
-
const BUILD_COMMIT = "
|
|
33
|
+
const BUILD_VERSION = "0.3.35-preview.343";
|
|
34
|
+
const BUILD_COMMIT = "e66e8bf5e0039bfc9727326f22348a237c42d737";
|
|
35
35
|
const BUILD_SENTRY_DSN = "https://fd5e60e1c9820e1eef5ccebb84a07127@o4508714045276160.ingest.us.sentry.io/4510465864564736";
|
|
36
36
|
const BLAXEL_API_VERSION = "2026-09-22";
|
|
37
37
|
// Bun < 1.3.11 never sends connection-level WINDOW_UPDATE: the pooled h2
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SandboxFileExistsError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Thrown by `cp(..., { noOverwrite: true })` when the sandbox API reports that the
|
|
6
|
+
* final target already exists (HTTP 409, code `FILE_ALREADY_EXISTS`). The target is
|
|
7
|
+
* left unchanged. Paths are the original request strings, not the resolved child path.
|
|
8
|
+
*/
|
|
9
|
+
class SandboxFileExistsError extends Error {
|
|
10
|
+
source;
|
|
11
|
+
destination;
|
|
12
|
+
code = "FILE_ALREADY_EXISTS";
|
|
13
|
+
constructor(source, destination, options) {
|
|
14
|
+
super(`Could not copy ${source} to ${destination}: destination already exists`, options);
|
|
15
|
+
this.source = source;
|
|
16
|
+
this.destination = destination;
|
|
17
|
+
this.name = "SandboxFileExistsError";
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.SandboxFileExistsError = SandboxFileExistsError;
|
|
@@ -9,6 +9,7 @@ const transient_retry_js_1 = require("../../common/transient-retry.js");
|
|
|
9
9
|
const shell_js_1 = require("../../common/shell.js");
|
|
10
10
|
const action_js_1 = require("../action.js");
|
|
11
11
|
const index_js_1 = require("../client/index.js");
|
|
12
|
+
const copy_no_overwrite_js_1 = require("./copy-no-overwrite.js");
|
|
12
13
|
// Multipart upload constants
|
|
13
14
|
const MULTIPART_THRESHOLD = 5 * 1024 * 1024; // 5MB
|
|
14
15
|
const CHUNK_SIZE = 5 * 1024 * 1024; // 5MB per part
|
|
@@ -380,7 +381,10 @@ class SandboxFileSystem extends action_js_1.SandboxAction {
|
|
|
380
381
|
return result.data;
|
|
381
382
|
});
|
|
382
383
|
}
|
|
383
|
-
async cp(source, destination, { maxWait = 180000 } = {}) {
|
|
384
|
+
async cp(source, destination, { maxWait = 180000, noOverwrite = false } = {}) {
|
|
385
|
+
if (noOverwrite) {
|
|
386
|
+
return this.copyNoOverwrite(source, destination, maxWait);
|
|
387
|
+
}
|
|
384
388
|
// Quote both paths so the shell that runs this command treats them as
|
|
385
389
|
// single literal arguments instead of interpreting metacharacters in them.
|
|
386
390
|
let process = await this.process.exec({
|
|
@@ -396,6 +400,50 @@ class SandboxFileSystem extends action_js_1.SandboxAction {
|
|
|
396
400
|
destination,
|
|
397
401
|
};
|
|
398
402
|
}
|
|
403
|
+
// One request: the sandbox API copies with exclusive creates and answers 409
|
|
404
|
+
// FILE_ALREADY_EXISTS when the final target exists. Not retried: a POST copy
|
|
405
|
+
// may have created entries before a connection reset.
|
|
406
|
+
// maxWait bounds the request like the default path's wait; -1 waits indefinitely.
|
|
407
|
+
async copyNoOverwrite(source, destination, maxWait) {
|
|
408
|
+
if (!source || !destination) {
|
|
409
|
+
throw new RangeError("source and destination must be nonempty paths");
|
|
410
|
+
}
|
|
411
|
+
if (!Number.isFinite(maxWait) || (maxWait < 0 && maxWait !== -1)) {
|
|
412
|
+
throw new RangeError("maxWait must be -1 or finite and non-negative");
|
|
413
|
+
}
|
|
414
|
+
const controller = new AbortController();
|
|
415
|
+
const timeoutError = new Error(`Could not copy ${source} to ${destination} within ${maxWait} ms; the sandbox may still be copying`);
|
|
416
|
+
const timeout = maxWait === -1 ? undefined : setTimeout(() => controller.abort(timeoutError), maxWait);
|
|
417
|
+
let result;
|
|
418
|
+
try {
|
|
419
|
+
result = await this.client.post({
|
|
420
|
+
url: "/filesystem-copy",
|
|
421
|
+
body: { source, destination, noOverwrite: true },
|
|
422
|
+
headers: { "Content-Type": "application/json" },
|
|
423
|
+
baseUrl: this.url,
|
|
424
|
+
signal: controller.signal,
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
catch (error) {
|
|
428
|
+
// Fetch implementations differ in what they reject with on abort.
|
|
429
|
+
if (controller.signal.aborted)
|
|
430
|
+
throw timeoutError;
|
|
431
|
+
throw error;
|
|
432
|
+
}
|
|
433
|
+
finally {
|
|
434
|
+
clearTimeout(timeout);
|
|
435
|
+
}
|
|
436
|
+
const { response, data, error } = result;
|
|
437
|
+
if (response.status === 409 && error?.code === "FILE_ALREADY_EXISTS") {
|
|
438
|
+
throw new copy_no_overwrite_js_1.SandboxFileExistsError(source, destination, { cause: error });
|
|
439
|
+
}
|
|
440
|
+
if (response.status === 404 && !error?.code && !error?.error) {
|
|
441
|
+
// An older sandbox API has no copy endpoint. Never fall back to an overwriting copy.
|
|
442
|
+
throw new Error("cp with noOverwrite needs a newer sandbox API: this sandbox has no /filesystem-copy endpoint; update its image");
|
|
443
|
+
}
|
|
444
|
+
this.handleResponseError(response, data, error);
|
|
445
|
+
return { message: "Files copied", source, destination };
|
|
446
|
+
}
|
|
399
447
|
watch(path, callback, options) {
|
|
400
448
|
path = this.formatPath(path);
|
|
401
449
|
let closed = false;
|
|
@@ -14,5 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.SandboxFileExistsError = void 0;
|
|
17
18
|
__exportStar(require("./filesystem.js"), exports);
|
|
19
|
+
var copy_no_overwrite_js_1 = require("./copy-no-overwrite.js");
|
|
20
|
+
Object.defineProperty(exports, "SandboxFileExistsError", { enumerable: true, get: function () { return copy_no_overwrite_js_1.SandboxFileExistsError; } });
|
|
18
21
|
__exportStar(require("./types.js"), exports);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thrown by `cp(..., { noOverwrite: true })` when the sandbox API reports that the
|
|
3
|
+
* final target already exists (HTTP 409, code `FILE_ALREADY_EXISTS`). The target is
|
|
4
|
+
* left unchanged. Paths are the original request strings, not the resolved child path.
|
|
5
|
+
*/
|
|
6
|
+
export declare class SandboxFileExistsError extends Error {
|
|
7
|
+
readonly source: string;
|
|
8
|
+
readonly destination: string;
|
|
9
|
+
readonly code: "FILE_ALREADY_EXISTS";
|
|
10
|
+
constructor(source: string, destination: string, options?: {
|
|
11
|
+
cause?: unknown;
|
|
12
|
+
});
|
|
13
|
+
}
|
|
@@ -32,9 +32,11 @@ export declare class SandboxFileSystem extends SandboxAction {
|
|
|
32
32
|
search(query: string, path?: string, options?: FilesystemSearchOptions): Promise<FuzzySearchResponse>;
|
|
33
33
|
find(path: string, options?: FilesystemFindOptions): Promise<FindResponse>;
|
|
34
34
|
grep(query: string, path?: string, options?: FilesystemGrepOptions): Promise<ContentSearchResponse>;
|
|
35
|
-
cp(source: string, destination: string, { maxWait }?: {
|
|
35
|
+
cp(source: string, destination: string, { maxWait, noOverwrite }?: {
|
|
36
36
|
maxWait?: number;
|
|
37
|
+
noOverwrite?: boolean;
|
|
37
38
|
}): Promise<CopyResponse>;
|
|
39
|
+
private copyNoOverwrite;
|
|
38
40
|
watch(path: string, callback: (fileEvent: WatchEvent) => void | Promise<void>, options?: {
|
|
39
41
|
onError?: (error: Error) => void;
|
|
40
42
|
/** Called on each server keepalive (every ~30s). Use it to detect a silent, dead stream. */
|