@blaxel/core 0.2.67-preview.88 → 0.2.67-preview.89
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/image/image.browser.js +84 -0
- package/dist/cjs/image/image.js +567 -0
- package/dist/cjs/image/image.test.js +545 -0
- package/dist/cjs/image/index.js +7 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/types/image/image.browser.d.ts +59 -0
- package/dist/cjs/types/image/image.d.ts +202 -0
- package/dist/cjs/types/image/image.test.d.ts +4 -0
- package/dist/cjs/types/image/index.d.ts +1 -0
- package/dist/cjs/types/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/image/image.js +84 -0
- package/dist/cjs-browser/image/image.test.js +545 -0
- package/dist/cjs-browser/image/index.js +7 -0
- package/dist/cjs-browser/index.js +1 -0
- package/dist/cjs-browser/types/image/image.browser.d.ts +59 -0
- package/dist/cjs-browser/types/image/image.d.ts +202 -0
- package/dist/cjs-browser/types/image/image.test.d.ts +4 -0
- package/dist/cjs-browser/types/image/index.d.ts +1 -0
- package/dist/cjs-browser/types/index.d.ts +1 -0
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/common/settings.js +2 -2
- package/dist/esm/image/image.browser.js +80 -0
- package/dist/esm/image/image.js +560 -0
- package/dist/esm/image/image.test.js +543 -0
- package/dist/esm/image/index.js +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm-browser/.tsbuildinfo +1 -1
- package/dist/esm-browser/common/settings.js +2 -2
- package/dist/esm-browser/image/image.js +80 -0
- package/dist/esm-browser/image/image.test.js +543 -0
- package/dist/esm-browser/image/index.js +1 -0
- package/dist/esm-browser/index.js +1 -0
- package/package.json +4 -1
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { Sandbox } from "../client/types.gen.js";
|
|
2
|
+
export declare const SANDBOX_API_IMAGE = "ghcr.io/blaxel-ai/sandbox";
|
|
3
|
+
export declare const SANDBOX_API_PATH = "/usr/local/bin/sandbox-api";
|
|
4
|
+
/**
|
|
5
|
+
* Represents a local file to be copied into the build context.
|
|
6
|
+
*/
|
|
7
|
+
export interface LocalFile {
|
|
8
|
+
sourcePath: string;
|
|
9
|
+
destinationPath: string;
|
|
10
|
+
contextName: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Contains all information needed to generate a deployable folder.
|
|
14
|
+
*/
|
|
15
|
+
export interface ImageBuildContext {
|
|
16
|
+
baseImage: string;
|
|
17
|
+
instructions: string[];
|
|
18
|
+
localFiles: LocalFile[];
|
|
19
|
+
hasEntrypoint: boolean;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Options for building and deploying an image
|
|
23
|
+
*/
|
|
24
|
+
export interface ImageBuildOptions {
|
|
25
|
+
name: string;
|
|
26
|
+
memory?: number;
|
|
27
|
+
timeout?: number;
|
|
28
|
+
onStatusChange?: (status: string) => void;
|
|
29
|
+
sandboxVersion?: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* A fluent builder for creating sandbox images programmatically.
|
|
33
|
+
*
|
|
34
|
+
* Similar to Modal's Image class, allows chaining operations to build
|
|
35
|
+
* a custom image from a base image.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* const image = ImageInstance.fromRegistry("python:3.11-slim")
|
|
40
|
+
* .runCommands("apt-get update && apt-get install -y git curl")
|
|
41
|
+
* .workdir("/app")
|
|
42
|
+
* .runCommands("pip install --upgrade pip")
|
|
43
|
+
* .env({ PYTHONUNBUFFERED: "1" });
|
|
44
|
+
*
|
|
45
|
+
* await image.build({
|
|
46
|
+
* name: "my-sandbox",
|
|
47
|
+
* memory: 4096,
|
|
48
|
+
* timeout: 900000,
|
|
49
|
+
* onStatusChange: console.log,
|
|
50
|
+
* sandboxVersion: "latest",
|
|
51
|
+
* });
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare class ImageInstance {
|
|
55
|
+
private _context;
|
|
56
|
+
constructor(context: ImageBuildContext);
|
|
57
|
+
/**
|
|
58
|
+
* Create an image from a Docker registry image.
|
|
59
|
+
*
|
|
60
|
+
* @param tag - The image tag (e.g., "python:3.11-slim", "ubuntu:22.04")
|
|
61
|
+
* @returns A new Image instance
|
|
62
|
+
*/
|
|
63
|
+
static fromRegistry(tag: string): ImageInstance;
|
|
64
|
+
/**
|
|
65
|
+
* Set the working directory for subsequent instructions.
|
|
66
|
+
*
|
|
67
|
+
* @param path - The working directory path inside the container
|
|
68
|
+
* @returns A new Image instance with the working directory set
|
|
69
|
+
*/
|
|
70
|
+
workdir(path: string): ImageInstance;
|
|
71
|
+
/**
|
|
72
|
+
* Run shell commands in the image.
|
|
73
|
+
*
|
|
74
|
+
* @param commands - One or more shell commands to run
|
|
75
|
+
* @returns A new Image instance with the commands added
|
|
76
|
+
*/
|
|
77
|
+
runCommands(...commands: string[]): ImageInstance;
|
|
78
|
+
/**
|
|
79
|
+
* Set environment variables.
|
|
80
|
+
*
|
|
81
|
+
* @param variables - Environment variables as an object
|
|
82
|
+
* @returns A new Image instance with the environment variables set
|
|
83
|
+
*/
|
|
84
|
+
env(variables: Record<string, string>): ImageInstance;
|
|
85
|
+
/**
|
|
86
|
+
* Copy files or directories from the build context to the image.
|
|
87
|
+
*
|
|
88
|
+
* @param source - Source path (relative to build context)
|
|
89
|
+
* @param destination - Destination path in the image
|
|
90
|
+
* @returns A new Image instance with the copy instruction
|
|
91
|
+
*/
|
|
92
|
+
copy(source: string, destination: string): ImageInstance;
|
|
93
|
+
/**
|
|
94
|
+
* Add a local file to the build context and copy it to the image.
|
|
95
|
+
*
|
|
96
|
+
* @param sourcePath - Path to the local file
|
|
97
|
+
* @param destination - Destination path in the image
|
|
98
|
+
* @param contextName - Optional name for the file in the build context
|
|
99
|
+
* @returns A new Image instance with the file added
|
|
100
|
+
*/
|
|
101
|
+
addLocalFile(sourcePath: string, destination: string, contextName?: string): ImageInstance;
|
|
102
|
+
/**
|
|
103
|
+
* Add a local directory to the build context and copy it to the image.
|
|
104
|
+
*
|
|
105
|
+
* @param sourcePath - Path to the local directory
|
|
106
|
+
* @param destination - Destination path in the image
|
|
107
|
+
* @param contextName - Optional name for the directory in the build context
|
|
108
|
+
* @returns A new Image instance with the directory added
|
|
109
|
+
*/
|
|
110
|
+
addLocalDir(sourcePath: string, destination: string, contextName?: string): ImageInstance;
|
|
111
|
+
/**
|
|
112
|
+
* Expose ports.
|
|
113
|
+
*
|
|
114
|
+
* @param ports - Port numbers to expose
|
|
115
|
+
* @returns A new Image instance with the ports exposed
|
|
116
|
+
*/
|
|
117
|
+
expose(...ports: number[]): ImageInstance;
|
|
118
|
+
/**
|
|
119
|
+
* Set the entrypoint for the image.
|
|
120
|
+
*
|
|
121
|
+
* @param args - Entrypoint command and arguments
|
|
122
|
+
* @returns A new Image instance with the entrypoint set
|
|
123
|
+
*/
|
|
124
|
+
entrypoint(...args: string[]): ImageInstance;
|
|
125
|
+
/**
|
|
126
|
+
* Set the user for subsequent instructions.
|
|
127
|
+
*
|
|
128
|
+
* @param user - Username or UID
|
|
129
|
+
* @returns A new Image instance with the user set
|
|
130
|
+
*/
|
|
131
|
+
user(user: string): ImageInstance;
|
|
132
|
+
/**
|
|
133
|
+
* Add labels to the image.
|
|
134
|
+
*
|
|
135
|
+
* @param labels - Labels as an object
|
|
136
|
+
* @returns A new Image instance with the labels added
|
|
137
|
+
*/
|
|
138
|
+
label(labels: Record<string, string>): ImageInstance;
|
|
139
|
+
/**
|
|
140
|
+
* Define a build argument.
|
|
141
|
+
*
|
|
142
|
+
* @param name - Argument name
|
|
143
|
+
* @param defaultValue - Optional default value
|
|
144
|
+
* @returns A new Image instance with the argument defined
|
|
145
|
+
*/
|
|
146
|
+
arg(name: string, defaultValue?: string): ImageInstance;
|
|
147
|
+
/**
|
|
148
|
+
* Get the generated Dockerfile content.
|
|
149
|
+
*/
|
|
150
|
+
get dockerfile(): string;
|
|
151
|
+
/**
|
|
152
|
+
* Get a hash of the image configuration.
|
|
153
|
+
*/
|
|
154
|
+
get hash(): string;
|
|
155
|
+
/**
|
|
156
|
+
* Get the base image tag.
|
|
157
|
+
*/
|
|
158
|
+
get baseImage(): string;
|
|
159
|
+
private _hasSandboxApi;
|
|
160
|
+
private _prepareForSandbox;
|
|
161
|
+
/**
|
|
162
|
+
* Write the image to a deployable folder structure.
|
|
163
|
+
*
|
|
164
|
+
* @param outputPath - Path to the output directory
|
|
165
|
+
* @param name - Optional name for the generated folder (defaults to hash-based name)
|
|
166
|
+
* @returns Path to the generated folder
|
|
167
|
+
*/
|
|
168
|
+
write(outputPath: string, name?: string): string;
|
|
169
|
+
/**
|
|
170
|
+
* Write the image to a deployable folder in a temporary directory.
|
|
171
|
+
*
|
|
172
|
+
* @returns Path to the generated folder
|
|
173
|
+
*/
|
|
174
|
+
writeTemp(): string;
|
|
175
|
+
private _createZip;
|
|
176
|
+
private _createSandboxPayload;
|
|
177
|
+
private _createSandboxWithUpload;
|
|
178
|
+
private _uploadZip;
|
|
179
|
+
private _getSandboxStatus;
|
|
180
|
+
private _waitForDeployment;
|
|
181
|
+
/**
|
|
182
|
+
* Build and deploy the image as a sandbox.
|
|
183
|
+
*
|
|
184
|
+
* This method:
|
|
185
|
+
* 1. Prepares the image for sandbox deployment (adds sandbox-api)
|
|
186
|
+
* 2. Builds the image folder
|
|
187
|
+
* 3. Creates a zip of the folder
|
|
188
|
+
* 4. Creates/updates the sandbox resource
|
|
189
|
+
* 5. Uploads the zip to Blaxel
|
|
190
|
+
* 6. Waits for deployment to complete
|
|
191
|
+
*
|
|
192
|
+
* @param options - Build options
|
|
193
|
+
* @returns The deployed Sandbox object
|
|
194
|
+
*/
|
|
195
|
+
build(options: ImageBuildOptions): Promise<Sandbox>;
|
|
196
|
+
/**
|
|
197
|
+
* Build and deploy the image as a sandbox (sync version).
|
|
198
|
+
*
|
|
199
|
+
* @deprecated Use build() instead - this is provided for API parity with Python SDK
|
|
200
|
+
*/
|
|
201
|
+
buildSync(options: ImageBuildOptions): Promise<Sandbox>;
|
|
202
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ImageInstance, ImageBuildContext, ImageBuildOptions, LocalFile, SANDBOX_API_IMAGE, SANDBOX_API_PATH, } from "./image.js";
|
|
@@ -9,6 +9,7 @@ export * from "./common/internal.js";
|
|
|
9
9
|
export * from "./common/logger.js";
|
|
10
10
|
export * from "./common/settings.js";
|
|
11
11
|
export * from "./common/webhook.js";
|
|
12
|
+
export * from "./image/index.js";
|
|
12
13
|
export * from "./jobs/index.js";
|
|
13
14
|
export * from "./mcp/index.js";
|
|
14
15
|
export * from "./models/index.js";
|