@blaxel/core 0.2.71-dev.101 → 0.2.71-dev.106
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/autoload.js +64 -0
- package/dist/cjs/common/h2fetch.js +208 -0
- package/dist/cjs/common/h2pool.js +137 -0
- package/dist/cjs/common/h2warm.js +54 -0
- package/dist/cjs/common/settings.js +2 -2
- package/dist/cjs/sandbox/action.js +33 -0
- package/dist/cjs/sandbox/drive/drive.js +3 -3
- package/dist/cjs/sandbox/filesystem/filesystem.js +1 -2
- package/dist/cjs/sandbox/interpreter.js +12 -2
- package/dist/cjs/sandbox/process/process.js +2 -2
- package/dist/cjs/sandbox/sandbox.js +84 -10
- package/dist/cjs/types/common/autoload.d.ts +5 -0
- package/dist/cjs/types/common/h2fetch.d.ts +22 -0
- package/dist/cjs/types/common/h2pool.d.ts +38 -0
- package/dist/cjs/types/common/h2warm.d.ts +2 -0
- package/dist/cjs/types/sandbox/action.d.ts +8 -1
- package/dist/cjs/types/sandbox/interpreter.d.ts +1 -0
- package/dist/cjs/types/sandbox/sandbox.d.ts +6 -0
- package/dist/cjs/types/sandbox/types.d.ts +2 -0
- package/dist/cjs-browser/.tsbuildinfo +1 -1
- package/dist/cjs-browser/common/autoload.js +64 -0
- package/dist/cjs-browser/common/h2fetch.js +4 -0
- package/dist/cjs-browser/common/h2pool.js +4 -0
- package/dist/cjs-browser/common/h2warm.js +2 -0
- package/dist/cjs-browser/common/settings.js +2 -2
- package/dist/cjs-browser/sandbox/action.js +33 -0
- package/dist/cjs-browser/sandbox/drive/drive.js +3 -3
- package/dist/cjs-browser/sandbox/filesystem/filesystem.js +1 -2
- package/dist/cjs-browser/sandbox/interpreter.js +12 -2
- package/dist/cjs-browser/sandbox/process/process.js +2 -2
- package/dist/cjs-browser/sandbox/sandbox.js +84 -10
- package/dist/cjs-browser/types/common/autoload.d.ts +5 -0
- package/dist/cjs-browser/types/common/h2fetch.d.ts +22 -0
- package/dist/cjs-browser/types/common/h2pool.d.ts +38 -0
- package/dist/cjs-browser/types/common/h2warm.d.ts +2 -0
- package/dist/cjs-browser/types/sandbox/action.d.ts +8 -1
- package/dist/cjs-browser/types/sandbox/interpreter.d.ts +1 -0
- package/dist/cjs-browser/types/sandbox/sandbox.d.ts +6 -0
- package/dist/cjs-browser/types/sandbox/types.d.ts +2 -0
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/common/autoload.js +30 -0
- package/dist/esm/common/h2fetch.js +203 -0
- package/dist/esm/common/h2pool.js +101 -0
- package/dist/esm/common/h2warm.js +48 -0
- package/dist/esm/common/settings.js +2 -2
- package/dist/esm/sandbox/action.js +33 -0
- package/dist/esm/sandbox/drive/drive.js +3 -3
- package/dist/esm/sandbox/filesystem/filesystem.js +1 -2
- package/dist/esm/sandbox/interpreter.js +12 -2
- package/dist/esm/sandbox/process/process.js +2 -2
- package/dist/esm/sandbox/sandbox.js +51 -10
- package/dist/esm-browser/.tsbuildinfo +1 -1
- package/dist/esm-browser/common/autoload.js +30 -0
- package/dist/esm-browser/common/h2fetch.js +4 -0
- package/dist/esm-browser/common/h2pool.js +4 -0
- package/dist/esm-browser/common/h2warm.js +2 -0
- package/dist/esm-browser/common/settings.js +2 -2
- package/dist/esm-browser/sandbox/action.js +33 -0
- package/dist/esm-browser/sandbox/drive/drive.js +3 -3
- package/dist/esm-browser/sandbox/filesystem/filesystem.js +1 -2
- package/dist/esm-browser/sandbox/interpreter.js +12 -2
- package/dist/esm-browser/sandbox/process/process.js +2 -2
- package/dist/esm-browser/sandbox/sandbox.js +51 -10
- package/package.json +1 -1
|
@@ -21,6 +21,8 @@ export class SandboxInstance {
|
|
|
21
21
|
codegen;
|
|
22
22
|
system;
|
|
23
23
|
drives;
|
|
24
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
25
|
+
h2Session;
|
|
24
26
|
constructor(sandbox) {
|
|
25
27
|
this.sandbox = sandbox;
|
|
26
28
|
this.process = new SandboxProcess(sandbox);
|
|
@@ -31,6 +33,7 @@ export class SandboxInstance {
|
|
|
31
33
|
this.codegen = new SandboxCodegen(sandbox);
|
|
32
34
|
this.system = new SandboxSystem(sandbox);
|
|
33
35
|
this.drives = new SandboxDrive(sandbox);
|
|
36
|
+
this.h2Session = null;
|
|
34
37
|
}
|
|
35
38
|
get metadata() {
|
|
36
39
|
return this.sandbox.metadata;
|
|
@@ -47,6 +50,27 @@ export class SandboxInstance {
|
|
|
47
50
|
get lastUsedAt() {
|
|
48
51
|
return this.sandbox.lastUsedAt;
|
|
49
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Warm and attach an H2 session based on the sandbox's region.
|
|
55
|
+
* Shared by create(), get(), list(), and update helpers.
|
|
56
|
+
*/
|
|
57
|
+
static async attachH2Session(instance) {
|
|
58
|
+
const region = instance.spec?.region;
|
|
59
|
+
if (!region)
|
|
60
|
+
return instance;
|
|
61
|
+
const edgeSuffix = settings.env === "prod" ? "bl.run" : "runv2.blaxel.dev";
|
|
62
|
+
const edgeDomain = `any.${region}.${edgeSuffix}`;
|
|
63
|
+
try {
|
|
64
|
+
const { h2Pool } = await import("../common/h2pool.js");
|
|
65
|
+
const h2Session = await h2Pool.get(edgeDomain);
|
|
66
|
+
instance.h2Session = h2Session;
|
|
67
|
+
instance.sandbox.h2Session = h2Session;
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
// H2 warming is best-effort; fall back to regular fetch
|
|
71
|
+
}
|
|
72
|
+
return instance;
|
|
73
|
+
}
|
|
50
74
|
get expiresIn() {
|
|
51
75
|
return this.sandbox.expiresIn;
|
|
52
76
|
}
|
|
@@ -128,11 +152,24 @@ export class SandboxInstance {
|
|
|
128
152
|
}
|
|
129
153
|
sandbox.spec.runtime.image = sandbox.spec.runtime.image || defaultImage;
|
|
130
154
|
sandbox.spec.runtime.memory = sandbox.spec.runtime.memory || defaultMemory;
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
155
|
+
const edgeSuffix = settings.env === "prod" ? "bl.run" : "runv2.blaxel.dev";
|
|
156
|
+
const edgeDomain = sandbox.spec?.region ? `any.${sandbox.spec.region}.${edgeSuffix}` : null;
|
|
157
|
+
// Kick off warming so h2Pool.get() can join it during the API call
|
|
158
|
+
if (edgeDomain) {
|
|
159
|
+
import("../common/h2pool.js").then(({ h2Pool }) => h2Pool.warm(edgeDomain)).catch(() => { });
|
|
160
|
+
}
|
|
161
|
+
const [{ data }, h2Session] = await Promise.all([
|
|
162
|
+
createSandbox({
|
|
163
|
+
body: sandbox,
|
|
164
|
+
throwOnError: true,
|
|
165
|
+
}),
|
|
166
|
+
edgeDomain ? import("../common/h2pool.js").then(({ h2Pool }) => h2Pool.get(edgeDomain)).catch(() => null) : Promise.resolve(null),
|
|
167
|
+
]);
|
|
168
|
+
// Inject the H2 session into the config so subsystems can use it
|
|
169
|
+
const config = { ...data, h2Session };
|
|
170
|
+
const instance = new SandboxInstance(config);
|
|
171
|
+
instance.h2Session = h2Session;
|
|
172
|
+
// Note: H2 session already attached via Promise.all above, no need for attachH2Session()
|
|
136
173
|
// TODO remove this part once we have a better way to handle this
|
|
137
174
|
if (safe) {
|
|
138
175
|
try {
|
|
@@ -149,11 +186,13 @@ export class SandboxInstance {
|
|
|
149
186
|
},
|
|
150
187
|
throwOnError: true,
|
|
151
188
|
});
|
|
152
|
-
|
|
189
|
+
const instance = new SandboxInstance(data);
|
|
190
|
+
return SandboxInstance.attachH2Session(instance);
|
|
153
191
|
}
|
|
154
192
|
static async list() {
|
|
155
193
|
const { data } = await listSandboxes({ throwOnError: true });
|
|
156
|
-
|
|
194
|
+
const instances = data.map((sandbox) => new SandboxInstance(sandbox));
|
|
195
|
+
return Promise.all(instances.map((instance) => SandboxInstance.attachH2Session(instance)));
|
|
157
196
|
}
|
|
158
197
|
static async delete(sandboxName) {
|
|
159
198
|
const { data } = await deleteSandbox({
|
|
@@ -165,6 +204,8 @@ export class SandboxInstance {
|
|
|
165
204
|
return data;
|
|
166
205
|
}
|
|
167
206
|
async delete() {
|
|
207
|
+
// Don't close the H2 session — it's shared via h2Pool
|
|
208
|
+
this.h2Session = null;
|
|
168
209
|
return await SandboxInstance.delete(this.metadata.name);
|
|
169
210
|
}
|
|
170
211
|
static async updateMetadata(sandboxName, metadata) {
|
|
@@ -176,7 +217,7 @@ export class SandboxInstance {
|
|
|
176
217
|
throwOnError: true,
|
|
177
218
|
});
|
|
178
219
|
const instance = new SandboxInstance(data);
|
|
179
|
-
return instance;
|
|
220
|
+
return SandboxInstance.attachH2Session(instance);
|
|
180
221
|
}
|
|
181
222
|
static async updateTtl(sandboxName, ttl) {
|
|
182
223
|
const sandbox = await SandboxInstance.get(sandboxName);
|
|
@@ -187,7 +228,7 @@ export class SandboxInstance {
|
|
|
187
228
|
throwOnError: true,
|
|
188
229
|
});
|
|
189
230
|
const instance = new SandboxInstance(data);
|
|
190
|
-
return instance;
|
|
231
|
+
return SandboxInstance.attachH2Session(instance);
|
|
191
232
|
}
|
|
192
233
|
static async updateLifecycle(sandboxName, lifecycle) {
|
|
193
234
|
const sandbox = await SandboxInstance.get(sandboxName);
|
|
@@ -198,7 +239,7 @@ export class SandboxInstance {
|
|
|
198
239
|
throwOnError: true,
|
|
199
240
|
});
|
|
200
241
|
const instance = new SandboxInstance(data);
|
|
201
|
-
return instance;
|
|
242
|
+
return SandboxInstance.attachH2Session(instance);
|
|
202
243
|
}
|
|
203
244
|
static async createIfNotExists(sandbox) {
|
|
204
245
|
try {
|