@blaxel/core 0.2.18-dev.150 → 0.2.18-dev.156
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/client/types.gen.d.ts +25 -7
- package/dist/sandbox/client/types.gen.d.ts +36 -35
- package/dist/sandbox/client/types.gen.js +0 -1
- package/dist/sandbox/process/process.d.ts +1 -1
- package/dist/sandbox/process/process.js +32 -2
- package/dist/sandbox/sandbox.d.ts +3 -3
- package/dist/sandbox/sandbox.js +45 -6
- package/dist/sandbox/types.d.ts +5 -0
- package/package.json +1 -1
|
@@ -733,7 +733,9 @@ export type JobMetrics = {
|
|
|
733
733
|
/**
|
|
734
734
|
* Job specification
|
|
735
735
|
*/
|
|
736
|
-
export type JobSpec = CoreSpec &
|
|
736
|
+
export type JobSpec = CoreSpec & {
|
|
737
|
+
triggers?: Triggers;
|
|
738
|
+
};
|
|
737
739
|
/**
|
|
738
740
|
* Jobs chart
|
|
739
741
|
*/
|
|
@@ -2439,12 +2441,7 @@ export type TraceIdsResponse = {
|
|
|
2439
2441
|
* Trigger configuration
|
|
2440
2442
|
*/
|
|
2441
2443
|
export type Trigger = {
|
|
2442
|
-
|
|
2443
|
-
* The configuration of the trigger
|
|
2444
|
-
*/
|
|
2445
|
-
configuration?: {
|
|
2446
|
-
[key: string]: unknown;
|
|
2447
|
-
};
|
|
2444
|
+
configuration?: TriggerConfiguration;
|
|
2448
2445
|
/**
|
|
2449
2446
|
* The id of the trigger
|
|
2450
2447
|
*/
|
|
@@ -2454,6 +2451,27 @@ export type Trigger = {
|
|
|
2454
2451
|
*/
|
|
2455
2452
|
type?: string;
|
|
2456
2453
|
};
|
|
2454
|
+
/**
|
|
2455
|
+
* Trigger configuration
|
|
2456
|
+
*/
|
|
2457
|
+
export type TriggerConfiguration = {
|
|
2458
|
+
/**
|
|
2459
|
+
* The authentication type of the trigger
|
|
2460
|
+
*/
|
|
2461
|
+
authenticationType?: string;
|
|
2462
|
+
/**
|
|
2463
|
+
* The path of the trigger
|
|
2464
|
+
*/
|
|
2465
|
+
path?: string;
|
|
2466
|
+
/**
|
|
2467
|
+
* The retry of the trigger
|
|
2468
|
+
*/
|
|
2469
|
+
retry?: number;
|
|
2470
|
+
/**
|
|
2471
|
+
* The schedule of the trigger, cron expression * * * * *
|
|
2472
|
+
*/
|
|
2473
|
+
schedule?: string;
|
|
2474
|
+
};
|
|
2457
2475
|
/**
|
|
2458
2476
|
* Triggers to use your agent
|
|
2459
2477
|
*/
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
export type Directory = {
|
|
2
|
-
files
|
|
3
|
-
name
|
|
4
|
-
path
|
|
2
|
+
files: Array<File>;
|
|
3
|
+
name: string;
|
|
4
|
+
path: string;
|
|
5
5
|
/**
|
|
6
6
|
* @name Subdirectories
|
|
7
7
|
*/
|
|
8
|
-
subdirectories
|
|
8
|
+
subdirectories: Array<Subdirectory>;
|
|
9
9
|
};
|
|
10
10
|
export type ErrorResponse = {
|
|
11
|
-
error
|
|
11
|
+
error: string;
|
|
12
12
|
};
|
|
13
13
|
export type File = {
|
|
14
|
-
group
|
|
15
|
-
lastModified
|
|
16
|
-
name
|
|
17
|
-
owner
|
|
18
|
-
path
|
|
19
|
-
permissions
|
|
20
|
-
size
|
|
14
|
+
group: string;
|
|
15
|
+
lastModified: string;
|
|
16
|
+
name: string;
|
|
17
|
+
owner: string;
|
|
18
|
+
path: string;
|
|
19
|
+
permissions: string;
|
|
20
|
+
size: number;
|
|
21
21
|
};
|
|
22
22
|
export type FileRequest = {
|
|
23
23
|
content?: string;
|
|
@@ -25,14 +25,14 @@ export type FileRequest = {
|
|
|
25
25
|
permissions?: string;
|
|
26
26
|
};
|
|
27
27
|
export type FileWithContent = {
|
|
28
|
-
content
|
|
29
|
-
group
|
|
30
|
-
lastModified
|
|
31
|
-
name
|
|
32
|
-
owner
|
|
33
|
-
path
|
|
34
|
-
permissions
|
|
35
|
-
size
|
|
28
|
+
content: string;
|
|
29
|
+
group: string;
|
|
30
|
+
lastModified: string;
|
|
31
|
+
name: string;
|
|
32
|
+
owner: string;
|
|
33
|
+
path: string;
|
|
34
|
+
permissions: string;
|
|
35
|
+
size: number;
|
|
36
36
|
};
|
|
37
37
|
export type PortMonitorRequest = {
|
|
38
38
|
/**
|
|
@@ -41,9 +41,9 @@ export type PortMonitorRequest = {
|
|
|
41
41
|
callback?: string;
|
|
42
42
|
};
|
|
43
43
|
export type ProcessLogs = {
|
|
44
|
-
logs
|
|
45
|
-
stderr
|
|
46
|
-
stdout
|
|
44
|
+
logs: string;
|
|
45
|
+
stderr: string;
|
|
46
|
+
stdout: string;
|
|
47
47
|
};
|
|
48
48
|
export type ProcessRequest = {
|
|
49
49
|
command: string;
|
|
@@ -57,22 +57,23 @@ export type ProcessRequest = {
|
|
|
57
57
|
workingDir?: string;
|
|
58
58
|
};
|
|
59
59
|
export type ProcessResponse = {
|
|
60
|
-
command
|
|
61
|
-
completedAt
|
|
62
|
-
exitCode
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
60
|
+
command: string;
|
|
61
|
+
completedAt: string;
|
|
62
|
+
exitCode: number;
|
|
63
|
+
logs: string;
|
|
64
|
+
name: string;
|
|
65
|
+
pid: string;
|
|
66
|
+
startedAt: string;
|
|
67
|
+
status: 'failed' | 'killed' | 'stopped' | 'running' | 'completed';
|
|
68
|
+
workingDir: string;
|
|
68
69
|
};
|
|
69
70
|
export type Subdirectory = {
|
|
70
|
-
name
|
|
71
|
-
path
|
|
71
|
+
name: string;
|
|
72
|
+
path: string;
|
|
72
73
|
};
|
|
73
74
|
export type SuccessResponse = {
|
|
74
|
-
message
|
|
75
|
-
path
|
|
75
|
+
message: string;
|
|
76
|
+
path: string;
|
|
76
77
|
};
|
|
77
78
|
export type DeleteFilesystemByPathData = {
|
|
78
79
|
body?: never;
|
|
@@ -10,7 +10,7 @@ export declare class SandboxProcess extends SandboxAction {
|
|
|
10
10
|
}): {
|
|
11
11
|
close: () => void;
|
|
12
12
|
};
|
|
13
|
-
exec(process: ProcessRequest): Promise<PostProcessResponse>;
|
|
13
|
+
exec(process: ProcessRequest, onLog?: (log: string) => void): Promise<PostProcessResponse>;
|
|
14
14
|
wait(identifier: string, { maxWait, interval }?: {
|
|
15
15
|
maxWait?: number;
|
|
16
16
|
interval?: number;
|
|
@@ -61,14 +61,44 @@ class SandboxProcess extends action_js_1.SandboxAction {
|
|
|
61
61
|
close: () => controller.abort(),
|
|
62
62
|
};
|
|
63
63
|
}
|
|
64
|
-
async exec(process) {
|
|
64
|
+
async exec(process, onLog) {
|
|
65
|
+
// Store original wait_for_completion setting
|
|
66
|
+
const shouldWaitForCompletion = process.waitForCompletion;
|
|
67
|
+
// Always start process without wait_for_completion to avoid server-side blocking
|
|
68
|
+
if (shouldWaitForCompletion && onLog) {
|
|
69
|
+
process.waitForCompletion = false;
|
|
70
|
+
}
|
|
65
71
|
const { response, data, error } = await (0, index_js_1.postProcess)({
|
|
66
72
|
body: process,
|
|
67
73
|
baseUrl: this.url,
|
|
68
74
|
client: this.client,
|
|
69
75
|
});
|
|
70
76
|
this.handleResponseError(response, data, error);
|
|
71
|
-
|
|
77
|
+
let result = data;
|
|
78
|
+
// Handle wait_for_completion with parallel log streaming
|
|
79
|
+
if (shouldWaitForCompletion) {
|
|
80
|
+
let streamControl;
|
|
81
|
+
if (onLog) {
|
|
82
|
+
streamControl = this.streamLogs(result.pid, { onLog });
|
|
83
|
+
}
|
|
84
|
+
try {
|
|
85
|
+
// Wait for process completion
|
|
86
|
+
result = await this.wait(result.pid, { interval: 50 });
|
|
87
|
+
}
|
|
88
|
+
finally {
|
|
89
|
+
// Clean up log streaming
|
|
90
|
+
if (streamControl) {
|
|
91
|
+
streamControl.close();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
// For non-blocking execution, set up log streaming immediately if requested
|
|
97
|
+
if (onLog) {
|
|
98
|
+
this.streamLogs(result.pid, { onLog });
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return result;
|
|
72
102
|
}
|
|
73
103
|
async wait(identifier, { maxWait = 60000, interval = 1000 } = {}) {
|
|
74
104
|
const startTime = Date.now();
|
|
@@ -4,7 +4,7 @@ import { SandboxNetwork } from "./network/index.js";
|
|
|
4
4
|
import { SandboxPreviews } from "./preview.js";
|
|
5
5
|
import { SandboxProcess } from "./process/index.js";
|
|
6
6
|
import { SandboxSessions } from "./session.js";
|
|
7
|
-
import { SandboxConfiguration, SessionWithToken } from "./types.js";
|
|
7
|
+
import { SandboxConfiguration, SandboxCreateConfiguration, SessionWithToken } from "./types.js";
|
|
8
8
|
export declare class SandboxInstance {
|
|
9
9
|
private sandbox;
|
|
10
10
|
fs: SandboxFileSystem;
|
|
@@ -21,10 +21,10 @@ export declare class SandboxInstance {
|
|
|
21
21
|
maxWait?: number;
|
|
22
22
|
interval?: number;
|
|
23
23
|
}): Promise<void>;
|
|
24
|
-
static create(sandbox
|
|
24
|
+
static create(sandbox?: SandboxModel | SandboxCreateConfiguration): Promise<SandboxInstance>;
|
|
25
25
|
static get(sandboxName: string): Promise<SandboxInstance>;
|
|
26
26
|
static list(): Promise<SandboxInstance[]>;
|
|
27
27
|
static delete(sandboxName: string): Promise<SandboxModel>;
|
|
28
|
-
static createIfNotExists(sandbox: SandboxModel): Promise<SandboxInstance>;
|
|
28
|
+
static createIfNotExists(sandbox: SandboxModel | SandboxCreateConfiguration): Promise<SandboxInstance>;
|
|
29
29
|
static fromSession(session: SessionWithToken): Promise<SandboxInstance>;
|
|
30
30
|
}
|
package/dist/sandbox/sandbox.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SandboxInstance = void 0;
|
|
4
|
+
const uuid_1 = require("uuid");
|
|
4
5
|
const index_js_1 = require("../client/index.js");
|
|
5
6
|
const logger_js_1 = require("../common/logger.js");
|
|
6
7
|
const index_js_2 = require("./filesystem/index.js");
|
|
@@ -61,11 +62,36 @@ class SandboxInstance {
|
|
|
61
62
|
}
|
|
62
63
|
}
|
|
63
64
|
static async create(sandbox) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
const defaultName = `sandbox-${(0, uuid_1.v4)().replace(/-/g, '').substring(0, 8)}`;
|
|
66
|
+
const defaultImage = "blaxel/prod-base:latest";
|
|
67
|
+
const defaultMemory = 4096;
|
|
68
|
+
if (!sandbox || 'name' in sandbox || 'image' in sandbox || 'memory' in sandbox) {
|
|
69
|
+
if (!sandbox)
|
|
70
|
+
sandbox = {};
|
|
71
|
+
if (!sandbox.name)
|
|
72
|
+
sandbox.name = defaultName;
|
|
73
|
+
if (!sandbox.image)
|
|
74
|
+
sandbox.image = defaultImage;
|
|
75
|
+
if (!sandbox.memory)
|
|
76
|
+
sandbox.memory = defaultMemory;
|
|
77
|
+
sandbox = {
|
|
78
|
+
metadata: { name: sandbox.name },
|
|
79
|
+
spec: { runtime: { image: sandbox.image, memory: sandbox.memory, generation: "mk3" } }
|
|
80
|
+
};
|
|
68
81
|
}
|
|
82
|
+
sandbox = sandbox;
|
|
83
|
+
if (!sandbox.metadata) {
|
|
84
|
+
sandbox.metadata = { name: crypto.randomUUID().replace(/-/g, '') };
|
|
85
|
+
}
|
|
86
|
+
if (!sandbox.spec) {
|
|
87
|
+
sandbox.spec = { runtime: { image: "blaxel/prod-base:latest" } };
|
|
88
|
+
}
|
|
89
|
+
if (!sandbox.spec.runtime) {
|
|
90
|
+
sandbox.spec.runtime = { image: defaultImage, memory: defaultMemory };
|
|
91
|
+
}
|
|
92
|
+
sandbox.spec.runtime.image = sandbox.spec.runtime.image || defaultImage;
|
|
93
|
+
sandbox.spec.runtime.memory = sandbox.spec.runtime.memory || defaultMemory;
|
|
94
|
+
sandbox.spec.runtime.generation = sandbox.spec.runtime.generation || "mk3";
|
|
69
95
|
const { data } = await (0, index_js_1.createSandbox)({
|
|
70
96
|
body: sandbox,
|
|
71
97
|
throwOnError: true,
|
|
@@ -96,7 +122,11 @@ class SandboxInstance {
|
|
|
96
122
|
}
|
|
97
123
|
static async createIfNotExists(sandbox) {
|
|
98
124
|
try {
|
|
99
|
-
const
|
|
125
|
+
const name = 'name' in sandbox ? sandbox.name : sandbox.metadata?.name;
|
|
126
|
+
if (!name) {
|
|
127
|
+
throw new Error("Sandbox name is required");
|
|
128
|
+
}
|
|
129
|
+
const sandboxInstance = await SandboxInstance.get(name);
|
|
100
130
|
return sandboxInstance;
|
|
101
131
|
}
|
|
102
132
|
catch (e) {
|
|
@@ -108,7 +138,16 @@ class SandboxInstance {
|
|
|
108
138
|
}
|
|
109
139
|
/* eslint-disable */
|
|
110
140
|
static async fromSession(session) {
|
|
111
|
-
|
|
141
|
+
// Create a minimal sandbox configuration for session-based access
|
|
142
|
+
const sandboxName = session.name.includes("-") ? session.name.split("-")[0] : session.name;
|
|
143
|
+
const sandbox = {
|
|
144
|
+
metadata: { name: sandboxName },
|
|
145
|
+
forceUrl: session.url,
|
|
146
|
+
headers: { "X-Blaxel-Preview-Token": session.token },
|
|
147
|
+
params: { bl_preview_token: session.token }
|
|
148
|
+
};
|
|
149
|
+
// Create instance using constructor instead of direct property assignment
|
|
150
|
+
return new SandboxInstance(sandbox);
|
|
112
151
|
}
|
|
113
152
|
}
|
|
114
153
|
exports.SandboxInstance = SandboxInstance;
|
package/dist/sandbox/types.d.ts
CHANGED