@blaxel/core 0.2.71-dev.101 → 0.2.71-dev.105
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 +207 -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 +202 -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
|
@@ -1,4 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
36
|
exports.SandboxInstance = void 0;
|
|
4
37
|
const uuid_1 = require("uuid");
|
|
@@ -24,6 +57,8 @@ class SandboxInstance {
|
|
|
24
57
|
codegen;
|
|
25
58
|
system;
|
|
26
59
|
drives;
|
|
60
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
61
|
+
h2Session;
|
|
27
62
|
constructor(sandbox) {
|
|
28
63
|
this.sandbox = sandbox;
|
|
29
64
|
this.process = new index_js_6.SandboxProcess(sandbox);
|
|
@@ -34,6 +69,7 @@ class SandboxInstance {
|
|
|
34
69
|
this.codegen = new index_js_2.SandboxCodegen(sandbox);
|
|
35
70
|
this.system = new system_js_1.SandboxSystem(sandbox);
|
|
36
71
|
this.drives = new index_js_3.SandboxDrive(sandbox);
|
|
72
|
+
this.h2Session = null;
|
|
37
73
|
}
|
|
38
74
|
get metadata() {
|
|
39
75
|
return this.sandbox.metadata;
|
|
@@ -50,6 +86,27 @@ class SandboxInstance {
|
|
|
50
86
|
get lastUsedAt() {
|
|
51
87
|
return this.sandbox.lastUsedAt;
|
|
52
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* Warm and attach an H2 session based on the sandbox's region.
|
|
91
|
+
* Shared by create(), get(), list(), and update helpers.
|
|
92
|
+
*/
|
|
93
|
+
static async attachH2Session(instance) {
|
|
94
|
+
const region = instance.spec?.region;
|
|
95
|
+
if (!region)
|
|
96
|
+
return instance;
|
|
97
|
+
const edgeSuffix = settings_js_1.settings.env === "prod" ? "bl.run" : "runv2.blaxel.dev";
|
|
98
|
+
const edgeDomain = `any.${region}.${edgeSuffix}`;
|
|
99
|
+
try {
|
|
100
|
+
const { h2Pool } = await Promise.resolve().then(() => __importStar(require("../common/h2pool.js")));
|
|
101
|
+
const h2Session = await h2Pool.get(edgeDomain);
|
|
102
|
+
instance.h2Session = h2Session;
|
|
103
|
+
instance.sandbox.h2Session = h2Session;
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
// H2 warming is best-effort; fall back to regular fetch
|
|
107
|
+
}
|
|
108
|
+
return instance;
|
|
109
|
+
}
|
|
53
110
|
get expiresIn() {
|
|
54
111
|
return this.sandbox.expiresIn;
|
|
55
112
|
}
|
|
@@ -131,11 +188,24 @@ class SandboxInstance {
|
|
|
131
188
|
}
|
|
132
189
|
sandbox.spec.runtime.image = sandbox.spec.runtime.image || defaultImage;
|
|
133
190
|
sandbox.spec.runtime.memory = sandbox.spec.runtime.memory || defaultMemory;
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
191
|
+
const edgeSuffix = settings_js_1.settings.env === "prod" ? "bl.run" : "runv2.blaxel.dev";
|
|
192
|
+
const edgeDomain = sandbox.spec?.region ? `any.${sandbox.spec.region}.${edgeSuffix}` : null;
|
|
193
|
+
// Kick off warming so h2Pool.get() can join it during the API call
|
|
194
|
+
if (edgeDomain) {
|
|
195
|
+
Promise.resolve().then(() => __importStar(require("../common/h2pool.js"))).then(({ h2Pool }) => h2Pool.warm(edgeDomain)).catch(() => { });
|
|
196
|
+
}
|
|
197
|
+
const [{ data }, h2Session] = await Promise.all([
|
|
198
|
+
(0, index_js_1.createSandbox)({
|
|
199
|
+
body: sandbox,
|
|
200
|
+
throwOnError: true,
|
|
201
|
+
}),
|
|
202
|
+
edgeDomain ? Promise.resolve().then(() => __importStar(require("../common/h2pool.js"))).then(({ h2Pool }) => h2Pool.get(edgeDomain)).catch(() => null) : Promise.resolve(null),
|
|
203
|
+
]);
|
|
204
|
+
// Inject the H2 session into the config so subsystems can use it
|
|
205
|
+
const config = { ...data, h2Session };
|
|
206
|
+
const instance = new SandboxInstance(config);
|
|
207
|
+
instance.h2Session = h2Session;
|
|
208
|
+
// Note: H2 session already attached via Promise.all above, no need for attachH2Session()
|
|
139
209
|
// TODO remove this part once we have a better way to handle this
|
|
140
210
|
if (safe) {
|
|
141
211
|
try {
|
|
@@ -152,11 +222,13 @@ class SandboxInstance {
|
|
|
152
222
|
},
|
|
153
223
|
throwOnError: true,
|
|
154
224
|
});
|
|
155
|
-
|
|
225
|
+
const instance = new SandboxInstance(data);
|
|
226
|
+
return SandboxInstance.attachH2Session(instance);
|
|
156
227
|
}
|
|
157
228
|
static async list() {
|
|
158
229
|
const { data } = await (0, index_js_1.listSandboxes)({ throwOnError: true });
|
|
159
|
-
|
|
230
|
+
const instances = data.map((sandbox) => new SandboxInstance(sandbox));
|
|
231
|
+
return Promise.all(instances.map((instance) => SandboxInstance.attachH2Session(instance)));
|
|
160
232
|
}
|
|
161
233
|
static async delete(sandboxName) {
|
|
162
234
|
const { data } = await (0, index_js_1.deleteSandbox)({
|
|
@@ -168,6 +240,8 @@ class SandboxInstance {
|
|
|
168
240
|
return data;
|
|
169
241
|
}
|
|
170
242
|
async delete() {
|
|
243
|
+
// Don't close the H2 session — it's shared via h2Pool
|
|
244
|
+
this.h2Session = null;
|
|
171
245
|
return await SandboxInstance.delete(this.metadata.name);
|
|
172
246
|
}
|
|
173
247
|
static async updateMetadata(sandboxName, metadata) {
|
|
@@ -179,7 +253,7 @@ class SandboxInstance {
|
|
|
179
253
|
throwOnError: true,
|
|
180
254
|
});
|
|
181
255
|
const instance = new SandboxInstance(data);
|
|
182
|
-
return instance;
|
|
256
|
+
return SandboxInstance.attachH2Session(instance);
|
|
183
257
|
}
|
|
184
258
|
static async updateTtl(sandboxName, ttl) {
|
|
185
259
|
const sandbox = await SandboxInstance.get(sandboxName);
|
|
@@ -190,7 +264,7 @@ class SandboxInstance {
|
|
|
190
264
|
throwOnError: true,
|
|
191
265
|
});
|
|
192
266
|
const instance = new SandboxInstance(data);
|
|
193
|
-
return instance;
|
|
267
|
+
return SandboxInstance.attachH2Session(instance);
|
|
194
268
|
}
|
|
195
269
|
static async updateLifecycle(sandboxName, lifecycle) {
|
|
196
270
|
const sandbox = await SandboxInstance.get(sandboxName);
|
|
@@ -201,7 +275,7 @@ class SandboxInstance {
|
|
|
201
275
|
throwOnError: true,
|
|
202
276
|
});
|
|
203
277
|
const instance = new SandboxInstance(data);
|
|
204
|
-
return instance;
|
|
278
|
+
return SandboxInstance.attachH2Session(instance);
|
|
205
279
|
}
|
|
206
280
|
static async createIfNotExists(sandbox) {
|
|
207
281
|
try {
|
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
import { Config } from "./settings.js";
|
|
2
2
|
export declare function initialize(config: Config): void;
|
|
3
3
|
export declare function authenticate(): Promise<void>;
|
|
4
|
+
/**
|
|
5
|
+
* Close all pooled H2 connections. Call this for explicit cleanup
|
|
6
|
+
* (e.g. in test teardown or before process exit).
|
|
7
|
+
*/
|
|
8
|
+
export declare function closeConnections(): Promise<void>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import http2 from "http2";
|
|
2
|
+
import type { h2Pool as H2PoolType } from "./h2pool.js";
|
|
3
|
+
/**
|
|
4
|
+
* Creates a fetch()-compatible function that sends requests over an existing
|
|
5
|
+
* HTTP/2 session. Falls back to global fetch() if the session is closed,
|
|
6
|
+
* destroyed, or if the H2 request times out.
|
|
7
|
+
*/
|
|
8
|
+
export declare function createH2Fetch(session: http2.ClientHttp2Session): (input: Request) => Promise<Response>;
|
|
9
|
+
/**
|
|
10
|
+
* Creates a fetch()-compatible function backed by the H2 session pool.
|
|
11
|
+
*
|
|
12
|
+
* Non-blocking: checks the pool cache synchronously. If a warm session is
|
|
13
|
+
* available it's used immediately; otherwise the request goes through
|
|
14
|
+
* regular fetch with zero delay (the pool keeps warming in the background
|
|
15
|
+
* so subsequent calls get H2).
|
|
16
|
+
*/
|
|
17
|
+
export declare function createPoolBackedH2Fetch(pool: typeof H2PoolType, domain: string): (input: Request) => Promise<Response>;
|
|
18
|
+
/**
|
|
19
|
+
* Low-level H2 request that takes raw URL + init, skipping Request construction.
|
|
20
|
+
* Used by SandboxAction.h2Fetch() for direct calls from subsystems.
|
|
21
|
+
*/
|
|
22
|
+
export declare function h2RequestDirect(session: http2.ClientHttp2Session, url: string, init?: RequestInit): Promise<Response>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type http2 from "http2";
|
|
2
|
+
/**
|
|
3
|
+
* Singleton H2 session pool keyed by edge domain.
|
|
4
|
+
*
|
|
5
|
+
* - `warm(domain)` starts a background connection (fire-and-forget).
|
|
6
|
+
* - `get(domain)` returns a live session immediately if cached, or awaits
|
|
7
|
+
* an in-flight warming, or establishes a fresh one.
|
|
8
|
+
* - Closed / destroyed sessions are automatically evicted.
|
|
9
|
+
*/
|
|
10
|
+
declare class H2Pool {
|
|
11
|
+
private sessions;
|
|
12
|
+
private inflight;
|
|
13
|
+
private _establish;
|
|
14
|
+
/**
|
|
15
|
+
* Lazily resolve the establish function so the http2 / tls / dns modules
|
|
16
|
+
* are only imported in Node.js environments.
|
|
17
|
+
*/
|
|
18
|
+
private establish;
|
|
19
|
+
/**
|
|
20
|
+
* Fire-and-forget background warming. Safe to call multiple times for
|
|
21
|
+
* the same domain — only one connection attempt per domain at a time.
|
|
22
|
+
*/
|
|
23
|
+
warm(domain: string): void;
|
|
24
|
+
/**
|
|
25
|
+
* Synchronous cache check. Returns a live cached session or `null`.
|
|
26
|
+
* Never blocks, never establishes — use for non-blocking fast paths.
|
|
27
|
+
*/
|
|
28
|
+
tryGet(domain: string): http2.ClientHttp2Session | null;
|
|
29
|
+
/**
|
|
30
|
+
* Get a live H2 session for `domain`. Returns immediately from cache,
|
|
31
|
+
* joins an in-flight warming, or starts a new one.
|
|
32
|
+
*/
|
|
33
|
+
get(domain: string): Promise<http2.ClientHttp2Session | null>;
|
|
34
|
+
/** Close all sessions (for cleanup). */
|
|
35
|
+
closeAll(): void;
|
|
36
|
+
}
|
|
37
|
+
export declare const h2Pool: H2Pool;
|
|
38
|
+
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type Client } from "@hey-api/client-fetch";
|
|
1
2
|
import { SandboxConfiguration } from "./types.js";
|
|
2
3
|
export declare class ResponseError extends Error {
|
|
3
4
|
response: Response;
|
|
@@ -7,12 +8,18 @@ export declare class ResponseError extends Error {
|
|
|
7
8
|
}
|
|
8
9
|
export declare class SandboxAction {
|
|
9
10
|
protected sandbox: SandboxConfiguration;
|
|
11
|
+
private _h2Client;
|
|
10
12
|
constructor(sandbox: SandboxConfiguration);
|
|
11
13
|
get name(): string;
|
|
12
14
|
get fallbackUrl(): string | null;
|
|
13
15
|
get externalUrl(): string;
|
|
14
16
|
get internalUrl(): string;
|
|
15
|
-
get client():
|
|
17
|
+
get client(): Client;
|
|
18
|
+
/**
|
|
19
|
+
* Routes through the H2 session when available, falling back to
|
|
20
|
+
* globalThis.fetch. Uses a direct H2 path that avoids Request allocation.
|
|
21
|
+
*/
|
|
22
|
+
protected h2Fetch(input: string | URL, init?: RequestInit): Promise<Response>;
|
|
16
23
|
get forcedUrl(): string | import("url").URL | null;
|
|
17
24
|
get url(): string;
|
|
18
25
|
handleResponseError(response: Response, data: unknown, error: unknown): void;
|
|
@@ -12,6 +12,7 @@ export declare class CodeInterpreter extends SandboxInstance {
|
|
|
12
12
|
safe?: boolean;
|
|
13
13
|
}): Promise<CodeInterpreter>;
|
|
14
14
|
get _jupyterUrl(): string;
|
|
15
|
+
private _fetch;
|
|
15
16
|
static OutputMessage: {
|
|
16
17
|
new (text: string, timestamp: number | null, isStderr: boolean): {
|
|
17
18
|
text: string;
|
|
@@ -18,12 +18,18 @@ export declare class SandboxInstance {
|
|
|
18
18
|
codegen: SandboxCodegen;
|
|
19
19
|
system: SandboxSystem;
|
|
20
20
|
drives: SandboxDrive;
|
|
21
|
+
h2Session: any;
|
|
21
22
|
constructor(sandbox: SandboxConfiguration);
|
|
22
23
|
get metadata(): import("../client/types.gen.js").Metadata;
|
|
23
24
|
get status(): import("../client/types.gen.js").Status | undefined;
|
|
24
25
|
get events(): import("../client/types.gen.js").CoreEvents | undefined;
|
|
25
26
|
get spec(): import("../client/types.gen.js").SandboxSpec;
|
|
26
27
|
get lastUsedAt(): string | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Warm and attach an H2 session based on the sandbox's region.
|
|
30
|
+
* Shared by create(), get(), list(), and update helpers.
|
|
31
|
+
*/
|
|
32
|
+
private static attachH2Session;
|
|
27
33
|
get expiresIn(): number | undefined;
|
|
28
34
|
wait({ maxWait, interval }?: {
|
|
29
35
|
maxWait?: number;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type http2 from "http2";
|
|
1
2
|
import { Port, Sandbox, SandboxLifecycle, VolumeAttachment, SandboxNetwork } from "../client/types.gen";
|
|
2
3
|
import { PostProcessResponse, ProcessRequest } from "./client";
|
|
3
4
|
export interface SessionCreateOptions {
|
|
@@ -24,6 +25,7 @@ export type SandboxConfiguration = {
|
|
|
24
25
|
forceUrl?: string;
|
|
25
26
|
headers?: Record<string, string>;
|
|
26
27
|
params?: Record<string, string>;
|
|
28
|
+
h2Session?: http2.ClientHttp2Session | null;
|
|
27
29
|
} & Sandbox;
|
|
28
30
|
export type SandboxUpdateMetadata = {
|
|
29
31
|
labels?: Record<string, string>;
|