@alibaba-group/opensandbox 0.1.0-dev1 → 0.1.0-dev3
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/README.md +10 -0
- package/dist/adapters/filesystemAdapter.d.ts.map +1 -1
- package/dist/adapters/filesystemAdapter.js +44 -0
- package/dist/adapters/sse.d.ts.map +1 -1
- package/dist/adapters/sse.js +2 -0
- package/dist/config/connection.d.ts.map +1 -1
- package/dist/config/connection.js +61 -14
- package/dist/sandbox.d.ts.map +1 -1
- package/dist/sandbox.js +42 -28
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -165,6 +165,10 @@ console.log(list.items.map((s) => s.id));
|
|
|
165
165
|
|
|
166
166
|
The `ConnectionConfig` class manages API server connection settings.
|
|
167
167
|
|
|
168
|
+
Runtime notes:
|
|
169
|
+
- In browsers, the SDK uses the global `fetch` implementation.
|
|
170
|
+
- In Node.js, the SDK creates a dedicated internal `fetch` backed by an isolated connection pool.
|
|
171
|
+
|
|
168
172
|
| Parameter | Description | Default | Environment Variable |
|
|
169
173
|
| --- | --- | --- | --- |
|
|
170
174
|
| `apiKey` | API key for authentication | Optional | `OPEN_SANDBOX_API_KEY` |
|
|
@@ -210,3 +214,9 @@ const config2 = new ConnectionConfig({
|
|
|
210
214
|
| `readyTimeoutSeconds` | Max time to wait for readiness | 30 seconds |
|
|
211
215
|
| `healthCheckPollingInterval` | Poll interval while waiting (milliseconds) | 200 ms |
|
|
212
216
|
|
|
217
|
+
## Browser Notes
|
|
218
|
+
|
|
219
|
+
- The SDK can run in browsers, but **streaming file uploads are Node-only**.
|
|
220
|
+
- If you pass `ReadableStream` or `AsyncIterable` for `writeFiles`, the browser will fall back to **buffering in memory** before upload.
|
|
221
|
+
- Reason: browsers do not support streaming `multipart/form-data` bodies with custom boundaries (required by the execd upload API).
|
|
222
|
+
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filesystemAdapter.d.ts","sourceRoot":"","sources":["../../src/adapters/filesystemAdapter.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAE7D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAE9D,OAAO,KAAK,EACV,mBAAmB,EACnB,QAAQ,EAGR,SAAS,EAIT,WAAW,EACX,mBAAmB,EACnB,kBAAkB,EAClB,UAAU,EACX,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"filesystemAdapter.d.ts","sourceRoot":"","sources":["../../src/adapters/filesystemAdapter.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAE7D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAE9D,OAAO,KAAK,EACV,mBAAmB,EACnB,QAAQ,EAGR,SAAS,EAIT,WAAW,EACX,mBAAmB,EACnB,kBAAkB,EAClB,UAAU,EACX,MAAM,yBAAyB,CAAC;AA8IjC,MAAM,WAAW,wBAAwB;IACvC;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAcD;;;;;;;GAOG;AACH,qBAAa,iBAAkB,YAAW,YAAY;IAoBlD,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,IAAI;IApBvB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAe;IAErC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAczB;gBAGiB,MAAM,EAAE,WAAW,EACnB,IAAI,EAAE,wBAAwB;IAKjD,OAAO,CAAC,YAAY;IAWpB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CACsC;IAE1E,OAAO,CAAC,cAAc;IAoBhB,WAAW,CAA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@ -35,6 +35,44 @@ function isReadableStream(v) {
|
|
|
35
35
|
function isAsyncIterable(v) {
|
|
36
36
|
return !!v && typeof v[Symbol.asyncIterator] === "function";
|
|
37
37
|
}
|
|
38
|
+
function isNodeRuntime() {
|
|
39
|
+
const p = globalThis?.process;
|
|
40
|
+
return !!(p?.versions?.node);
|
|
41
|
+
}
|
|
42
|
+
async function collectBytes(source) {
|
|
43
|
+
const chunks = [];
|
|
44
|
+
let total = 0;
|
|
45
|
+
if (isReadableStream(source)) {
|
|
46
|
+
const reader = source.getReader();
|
|
47
|
+
try {
|
|
48
|
+
while (true) {
|
|
49
|
+
const { done, value } = await reader.read();
|
|
50
|
+
if (done)
|
|
51
|
+
break;
|
|
52
|
+
if (value) {
|
|
53
|
+
chunks.push(value);
|
|
54
|
+
total += value.length;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
finally {
|
|
59
|
+
reader.releaseLock();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
for await (const chunk of source) {
|
|
64
|
+
chunks.push(chunk);
|
|
65
|
+
total += chunk.length;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const out = new Uint8Array(total);
|
|
69
|
+
let offset = 0;
|
|
70
|
+
for (const chunk of chunks) {
|
|
71
|
+
out.set(chunk, offset);
|
|
72
|
+
offset += chunk.length;
|
|
73
|
+
}
|
|
74
|
+
return out;
|
|
75
|
+
}
|
|
38
76
|
function toReadableStream(it) {
|
|
39
77
|
const RS = ReadableStream;
|
|
40
78
|
if (typeof RS?.from === "function")
|
|
@@ -252,6 +290,12 @@ export class FilesystemAdapter {
|
|
|
252
290
|
const metadataJson = JSON.stringify(meta);
|
|
253
291
|
// Streaming path (large files): build multipart body manually to avoid buffering.
|
|
254
292
|
if (isReadableStream(data) || isAsyncIterable(data)) {
|
|
293
|
+
// Browsers do not allow streaming multipart requests with custom boundaries.
|
|
294
|
+
// Fall back to in-memory uploads when streaming is unavailable.
|
|
295
|
+
if (!isNodeRuntime()) {
|
|
296
|
+
const bytes = await collectBytes(data);
|
|
297
|
+
return await this.uploadFile(meta, bytes);
|
|
298
|
+
}
|
|
255
299
|
const boundary = `opensandbox_${Math.random()
|
|
256
300
|
.toString(16)
|
|
257
301
|
.slice(2)}_${Date.now()}`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../../src/adapters/sse.ts"],"names":[],"mappings":"AAwBA;;;;GAIG;AACH,wBAAuB,oBAAoB,CAAC,CAAC,EAC3C,GAAG,EAAE,QAAQ,EACb,IAAI,CAAC,EAAE;IAAE,oBAAoB,CAAC,EAAE,MAAM,CAAA;CAAE,GACvC,aAAa,CAAC,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../../src/adapters/sse.ts"],"names":[],"mappings":"AAwBA;;;;GAIG;AACH,wBAAuB,oBAAoB,CAAC,CAAC,EAC3C,GAAG,EAAE,QAAQ,EACb,IAAI,CAAC,EAAE;IAAE,oBAAoB,CAAC,EAAE,MAAM,CAAA;CAAE,GACvC,aAAa,CAAC,CAAC,CAAC,CA8DlB"}
|
package/dist/adapters/sse.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../src/config/connection.ts"],"names":[],"mappings":"AAcA,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,OAAO,CAAC;AAElD;;;;GAIG;AACH,MAAM,WAAW,uBAAuB;IACtC;;;;;;;;OAQG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,kBAAkB,CAAC;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEjC;;;OAGG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;
|
|
1
|
+
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../src/config/connection.ts"],"names":[],"mappings":"AAcA,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,OAAO,CAAC;AAElD;;;;GAIG;AACH,MAAM,WAAW,uBAAuB;IACtC;;;;;;;;OAQG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,kBAAkB,CAAC;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEjC;;;OAGG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AA2KD,qBAAa,gBAAgB;IAC3B,QAAQ,CAAC,QAAQ,EAAE,kBAAkB,CAAC;IACtC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACzC,QAAQ,CAAC,KAAK,EAAE,OAAO,KAAK,CAAC;IAC7B;;;;;;OAMG;IACH,QAAQ,CAAC,QAAQ,EAAE,OAAO,KAAK,CAAC;IAChC,QAAQ,CAAC,qBAAqB,EAAE,MAAM,CAAC;IACvC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAA8B;IAExD;;;;;;OAMG;gBACS,IAAI,GAAE,uBAA4B;IAyD9C,UAAU,IAAI,MAAM;CAUrB"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// Copyright 2026 Alibaba Group Holding Ltd.
|
|
2
|
-
//
|
|
2
|
+
//
|
|
3
3
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
4
|
// you may not use this file except in compliance with the License.
|
|
5
5
|
// You may obtain a copy of the License at
|
|
6
|
-
//
|
|
6
|
+
//
|
|
7
7
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
//
|
|
8
|
+
//
|
|
9
9
|
// Unless required by applicable law or agreed to in writing, software
|
|
10
10
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
11
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
// limitations under the License.
|
|
14
14
|
function isNodeRuntime() {
|
|
15
15
|
const p = globalThis?.process;
|
|
16
|
-
return !!
|
|
16
|
+
return !!p?.versions?.node;
|
|
17
17
|
}
|
|
18
18
|
function redactHeaders(headers) {
|
|
19
19
|
const out = { ...headers };
|
|
@@ -35,6 +35,7 @@ function stripV1Suffix(s) {
|
|
|
35
35
|
const trimmed = stripTrailingSlashes(s);
|
|
36
36
|
return trimmed.endsWith("/v1") ? trimmed.slice(0, -3) : trimmed;
|
|
37
37
|
}
|
|
38
|
+
const DEFAULT_KEEPALIVE_TIMEOUT_MS = 15_000;
|
|
38
39
|
function normalizeDomainBase(input) {
|
|
39
40
|
// Accept a full URL and preserve its path prefix (if any).
|
|
40
41
|
if (input.startsWith("http://") || input.startsWith("https://")) {
|
|
@@ -47,6 +48,42 @@ function normalizeDomainBase(input) {
|
|
|
47
48
|
// No scheme: treat as "host[:port]" or "host[:port]/prefix" and normalize trailing "/v1" or "/".
|
|
48
49
|
return { domainBase: stripV1Suffix(input) };
|
|
49
50
|
}
|
|
51
|
+
function createNodeFetch() {
|
|
52
|
+
if (!isNodeRuntime()) {
|
|
53
|
+
return fetch;
|
|
54
|
+
}
|
|
55
|
+
let dispatcher;
|
|
56
|
+
let dispatcherPromise = null;
|
|
57
|
+
const baseFetch = fetch;
|
|
58
|
+
return async (input, init) => {
|
|
59
|
+
dispatcherPromise ??= (async () => {
|
|
60
|
+
try {
|
|
61
|
+
const mod = await import("undici");
|
|
62
|
+
const Agent = mod
|
|
63
|
+
.Agent;
|
|
64
|
+
if (!Agent) {
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
dispatcher = new Agent({
|
|
68
|
+
keepAliveTimeout: DEFAULT_KEEPALIVE_TIMEOUT_MS,
|
|
69
|
+
keepAliveMaxTimeout: DEFAULT_KEEPALIVE_TIMEOUT_MS,
|
|
70
|
+
});
|
|
71
|
+
return dispatcher;
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
})();
|
|
77
|
+
if (dispatcherPromise) {
|
|
78
|
+
await dispatcherPromise;
|
|
79
|
+
}
|
|
80
|
+
if (dispatcher) {
|
|
81
|
+
const mergedInit = { ...(init ?? {}), dispatcher };
|
|
82
|
+
return baseFetch(input, mergedInit);
|
|
83
|
+
}
|
|
84
|
+
return baseFetch(input, init);
|
|
85
|
+
};
|
|
86
|
+
}
|
|
50
87
|
function createTimedFetch(opts) {
|
|
51
88
|
const baseFetch = opts.baseFetch;
|
|
52
89
|
const timeoutSeconds = opts.timeoutSeconds;
|
|
@@ -55,7 +92,9 @@ function createTimedFetch(opts) {
|
|
|
55
92
|
const label = opts.label;
|
|
56
93
|
return async (input, init) => {
|
|
57
94
|
const method = init?.method ?? "GET";
|
|
58
|
-
const url = typeof input === "string"
|
|
95
|
+
const url = typeof input === "string"
|
|
96
|
+
? input
|
|
97
|
+
: input?.toString?.() ?? String(input);
|
|
59
98
|
const ac = new AbortController();
|
|
60
99
|
const timeoutMs = Math.floor(timeoutSeconds * 1000);
|
|
61
100
|
const t = Number.isFinite(timeoutMs) && timeoutMs > 0
|
|
@@ -73,7 +112,10 @@ function createTimedFetch(opts) {
|
|
|
73
112
|
signal: ac.signal,
|
|
74
113
|
};
|
|
75
114
|
if (debug) {
|
|
76
|
-
const mergedHeaders = {
|
|
115
|
+
const mergedHeaders = {
|
|
116
|
+
...defaultHeaders,
|
|
117
|
+
...(init?.headers ?? {}),
|
|
118
|
+
};
|
|
77
119
|
// eslint-disable-next-line no-console
|
|
78
120
|
console.log(`[opensandbox:${label}] ->`, method, url, redactHeaders(mergedHeaders));
|
|
79
121
|
}
|
|
@@ -126,9 +168,10 @@ export class ConnectionConfig {
|
|
|
126
168
|
this.protocol = normalized.protocol ?? opts.protocol ?? "http";
|
|
127
169
|
this.domain = normalized.domainBase;
|
|
128
170
|
this.apiKey = opts.apiKey ?? envApiKey;
|
|
129
|
-
this.requestTimeoutSeconds =
|
|
130
|
-
|
|
131
|
-
|
|
171
|
+
this.requestTimeoutSeconds =
|
|
172
|
+
typeof opts.requestTimeoutSeconds === "number"
|
|
173
|
+
? opts.requestTimeoutSeconds
|
|
174
|
+
: 30;
|
|
132
175
|
this.debug = !!opts.debug;
|
|
133
176
|
const headers = { ...(opts.headers ?? {}) };
|
|
134
177
|
// Attach API key via header unless the user already provided one.
|
|
@@ -136,14 +179,17 @@ export class ConnectionConfig {
|
|
|
136
179
|
headers["OPEN-SANDBOX-API-KEY"] = this.apiKey;
|
|
137
180
|
}
|
|
138
181
|
// Best-effort user-agent (Node only).
|
|
139
|
-
if (isNodeRuntime() &&
|
|
182
|
+
if (isNodeRuntime() &&
|
|
183
|
+
this.userAgent &&
|
|
184
|
+
!headers["user-agent"] &&
|
|
185
|
+
!headers["User-Agent"]) {
|
|
140
186
|
headers["user-agent"] = this.userAgent;
|
|
141
187
|
}
|
|
142
188
|
this.headers = headers;
|
|
143
189
|
// Node SDK: do not expose custom fetch in ConnectionConfigOptions.
|
|
144
|
-
// Use
|
|
145
|
-
const baseFetch =
|
|
146
|
-
const baseSseFetch =
|
|
190
|
+
// Use a node-scoped fetch with a dedicated dispatcher (keep-alive 30s).
|
|
191
|
+
const baseFetch = createNodeFetch();
|
|
192
|
+
const baseSseFetch = baseFetch;
|
|
147
193
|
// Normal HTTP calls: apply requestTimeoutSeconds.
|
|
148
194
|
this.fetch = createTimedFetch({
|
|
149
195
|
baseFetch,
|
|
@@ -163,7 +209,8 @@ export class ConnectionConfig {
|
|
|
163
209
|
}
|
|
164
210
|
getBaseUrl() {
|
|
165
211
|
// If `domain` already contains a scheme, treat it as a full base URL prefix.
|
|
166
|
-
if (this.domain.startsWith("http://") ||
|
|
212
|
+
if (this.domain.startsWith("http://") ||
|
|
213
|
+
this.domain.startsWith("https://")) {
|
|
167
214
|
return `${stripV1Suffix(this.domain)}/v1`;
|
|
168
215
|
}
|
|
169
216
|
return `${this.protocol}://${stripV1Suffix(this.domain)}/v1`;
|
package/dist/sandbox.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sandbox.d.ts","sourceRoot":"","sources":["../src/sandbox.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,gBAAgB,EAAE,KAAK,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AACxF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAE7D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAElE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,KAAK,EAEV,QAAQ,EACR,8BAA8B,EAC9B,SAAS,EACT,WAAW,EACZ,MAAM,uBAAuB,CAAC;AAG/B,MAAM,WAAW,oBAAoB;IACnC;;OAEG;IACH,gBAAgB,CAAC,EAAE,gBAAgB,GAAG,uBAAuB,CAAC;IAC9D;;OAEG;IACH,cAAc,CAAC,EAAE,cAAc,CAAC;IAEhC;;OAEG;IACH,KAAK,EACD,MAAM,GACN;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE;YAAE,QA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AAE,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;KAC5D,GAAG,OAAO,CAAC,IAAI,CAAC;CAwBlB"}
|
package/dist/sandbox.js
CHANGED
|
@@ -73,41 +73,55 @@ export class Sandbox {
|
|
|
73
73
|
const req = {
|
|
74
74
|
image: toImageSpec(opts.image),
|
|
75
75
|
entrypoint: opts.entrypoint ?? DEFAULT_ENTRYPOINT,
|
|
76
|
-
timeout: Math.
|
|
76
|
+
timeout: Math.floor(opts.timeoutSeconds ?? DEFAULT_TIMEOUT_SECONDS),
|
|
77
77
|
resourceLimits: opts.resource ?? DEFAULT_RESOURCE_LIMITS,
|
|
78
78
|
env: opts.env ?? {},
|
|
79
79
|
metadata: opts.metadata ?? {},
|
|
80
80
|
extensions: opts.extensions ?? {},
|
|
81
81
|
};
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
connectionConfig
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
await sbx.waitUntilReady({
|
|
104
|
-
readyTimeoutSeconds: opts.readyTimeoutSeconds ?? DEFAULT_READY_TIMEOUT_SECONDS,
|
|
105
|
-
pollingIntervalMillis: opts.healthCheckPollingInterval ??
|
|
106
|
-
DEFAULT_HEALTH_CHECK_POLLING_INTERVAL_MILLIS,
|
|
107
|
-
healthCheck: opts.healthCheck,
|
|
82
|
+
let sandboxId;
|
|
83
|
+
try {
|
|
84
|
+
const created = await sandboxes.createSandbox(req);
|
|
85
|
+
sandboxId = created.id;
|
|
86
|
+
const endpoint = await sandboxes.getSandboxEndpoint(sandboxId, DEFAULT_EXECD_PORT);
|
|
87
|
+
const execdBaseUrl = `${connectionConfig.protocol}://${endpoint.endpoint}`;
|
|
88
|
+
const { commands, files, health, metrics } = adapterFactory.createExecdStack({
|
|
89
|
+
connectionConfig,
|
|
90
|
+
execdBaseUrl,
|
|
91
|
+
});
|
|
92
|
+
const sbx = new Sandbox({
|
|
93
|
+
id: sandboxId,
|
|
94
|
+
connectionConfig,
|
|
95
|
+
adapterFactory,
|
|
96
|
+
lifecycleBaseUrl,
|
|
97
|
+
execdBaseUrl,
|
|
98
|
+
sandboxes,
|
|
99
|
+
commands,
|
|
100
|
+
files,
|
|
101
|
+
health,
|
|
102
|
+
metrics,
|
|
108
103
|
});
|
|
104
|
+
if (!(opts.skipHealthCheck ?? false)) {
|
|
105
|
+
await sbx.waitUntilReady({
|
|
106
|
+
readyTimeoutSeconds: opts.readyTimeoutSeconds ?? DEFAULT_READY_TIMEOUT_SECONDS,
|
|
107
|
+
pollingIntervalMillis: opts.healthCheckPollingInterval ??
|
|
108
|
+
DEFAULT_HEALTH_CHECK_POLLING_INTERVAL_MILLIS,
|
|
109
|
+
healthCheck: opts.healthCheck,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
return sbx;
|
|
113
|
+
}
|
|
114
|
+
catch (err) {
|
|
115
|
+
if (sandboxId) {
|
|
116
|
+
try {
|
|
117
|
+
await sandboxes.deleteSandbox(sandboxId);
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
// Ignore cleanup failure; surface original error.
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
throw err;
|
|
109
124
|
}
|
|
110
|
-
return sbx;
|
|
111
125
|
}
|
|
112
126
|
static async connect(opts) {
|
|
113
127
|
const connectionConfig = opts.connectionConfig instanceof ConnectionConfig
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alibaba-group/opensandbox",
|
|
3
|
-
"version": "0.1.0-
|
|
3
|
+
"version": "0.1.0-dev3",
|
|
4
4
|
"description": "OpenSandbox TypeScript/JavaScript SDK (sandbox lifecycle + execd APIs)",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -33,7 +33,8 @@
|
|
|
33
33
|
"node": ">=20"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"openapi-fetch": "^0.13.8"
|
|
36
|
+
"openapi-fetch": "^0.13.8",
|
|
37
|
+
"undici": "^7.18.2"
|
|
37
38
|
},
|
|
38
39
|
"devDependencies": {
|
|
39
40
|
"@eslint/js": "^9.39.2",
|