@alibaba-group/opensandbox 0.1.0 → 0.1.1-dev0
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/adapters/commandsAdapter.js +1 -0
- package/dist/adapters/commandsAdapter.js.map +1 -0
- package/dist/adapters/filesystemAdapter.js +1 -0
- package/dist/adapters/filesystemAdapter.js.map +1 -0
- package/dist/adapters/healthAdapter.js +1 -0
- package/dist/adapters/healthAdapter.js.map +1 -0
- package/dist/adapters/metricsAdapter.js +1 -0
- package/dist/adapters/metricsAdapter.js.map +1 -0
- package/dist/adapters/openapiError.js +1 -0
- package/dist/adapters/openapiError.js.map +1 -0
- package/dist/adapters/sandboxesAdapter.js +1 -0
- package/dist/adapters/sandboxesAdapter.js.map +1 -0
- package/dist/adapters/sse.js +1 -0
- package/dist/adapters/sse.js.map +1 -0
- package/dist/api/execd.js +1 -0
- package/dist/api/execd.js.map +1 -0
- package/dist/api/lifecycle.js +1 -0
- package/dist/api/lifecycle.js.map +1 -0
- package/dist/config/connection.d.ts.map +1 -1
- package/dist/config/connection.js +5 -2
- package/dist/config/connection.js.map +1 -0
- package/dist/core/constants.js +1 -0
- package/dist/core/constants.js.map +1 -0
- package/dist/core/exceptions.js +1 -0
- package/dist/core/exceptions.js.map +1 -0
- package/dist/factory/adapterFactory.js +1 -0
- package/dist/factory/adapterFactory.js.map +1 -0
- package/dist/factory/defaultAdapterFactory.js +1 -0
- package/dist/factory/defaultAdapterFactory.js.map +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -0
- package/dist/internal.js +1 -0
- package/dist/internal.js.map +1 -0
- package/dist/manager.js +1 -0
- package/dist/manager.js.map +1 -0
- package/dist/models/execd.js +1 -0
- package/dist/models/execd.js.map +1 -0
- package/dist/models/execution.js +1 -0
- package/dist/models/execution.js.map +1 -0
- package/dist/models/executionEventDispatcher.js +1 -0
- package/dist/models/executionEventDispatcher.js.map +1 -0
- package/dist/models/filesystem.js +1 -0
- package/dist/models/filesystem.js.map +1 -0
- package/dist/models/sandboxes.js +1 -0
- package/dist/models/sandboxes.js.map +1 -0
- package/dist/openapi/execdClient.js +1 -0
- package/dist/openapi/execdClient.js.map +1 -0
- package/dist/openapi/lifecycleClient.js +1 -0
- package/dist/openapi/lifecycleClient.js.map +1 -0
- package/dist/sandbox.js +1 -0
- package/dist/sandbox.js.map +1 -0
- package/dist/services/execdCommands.js +1 -0
- package/dist/services/execdCommands.js.map +1 -0
- package/dist/services/execdHealth.js +1 -0
- package/dist/services/execdHealth.js.map +1 -0
- package/dist/services/execdMetrics.js +1 -0
- package/dist/services/execdMetrics.js.map +1 -0
- package/dist/services/filesystem.js +1 -0
- package/dist/services/filesystem.js.map +1 -0
- package/dist/services/sandboxes.js +1 -0
- package/dist/services/sandboxes.js.map +1 -0
- package/package.json +3 -2
- package/src/adapters/commandsAdapter.ts +112 -0
- package/src/adapters/filesystemAdapter.ts +575 -0
- package/src/adapters/healthAdapter.ts +27 -0
- package/src/adapters/metricsAdapter.ts +51 -0
- package/src/adapters/openapiError.ts +42 -0
- package/src/adapters/sandboxesAdapter.ts +187 -0
- package/src/adapters/sse.ts +95 -0
- package/src/api/execd.ts +1569 -0
- package/src/api/lifecycle.ts +801 -0
- package/src/config/connection.ts +377 -0
- package/src/core/constants.ts +29 -0
- package/src/core/exceptions.ts +134 -0
- package/src/factory/adapterFactory.ts +51 -0
- package/src/factory/defaultAdapterFactory.ts +69 -0
- package/src/index.ts +108 -0
- package/src/internal.ts +39 -0
- package/src/manager.ts +111 -0
- package/src/models/execd.ts +90 -0
- package/src/models/execution.ts +71 -0
- package/src/models/executionEventDispatcher.ts +97 -0
- package/src/models/filesystem.ts +103 -0
- package/src/models/sandboxes.ts +142 -0
- package/src/openapi/execdClient.ts +49 -0
- package/src/openapi/lifecycleClient.ts +70 -0
- package/src/sandbox.ts +459 -0
- package/src/services/execdCommands.ts +35 -0
- package/src/services/execdHealth.ts +17 -0
- package/src/services/execdMetrics.ts +19 -0
- package/src/services/filesystem.ts +47 -0
- package/src/services/sandboxes.ts +42 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// Copyright 2026 Alibaba Group Holding Ltd.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Domain models for sandbox lifecycle.
|
|
17
|
+
*
|
|
18
|
+
* IMPORTANT:
|
|
19
|
+
* - These are NOT OpenAPI-generated types.
|
|
20
|
+
* - They are intentionally stable and JS-friendly.
|
|
21
|
+
*
|
|
22
|
+
* The internal OpenAPI schemas may change frequently; adapters map responses into these models.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
export type SandboxId = string;
|
|
26
|
+
|
|
27
|
+
export interface ImageAuth extends Record<string, unknown> {
|
|
28
|
+
username?: string;
|
|
29
|
+
password?: string;
|
|
30
|
+
token?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface ImageSpec {
|
|
34
|
+
uri: string;
|
|
35
|
+
auth?: ImageAuth;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type ResourceLimits = Record<string, string>;
|
|
39
|
+
|
|
40
|
+
export type SandboxState =
|
|
41
|
+
| "Creating"
|
|
42
|
+
| "Running"
|
|
43
|
+
| "Pausing"
|
|
44
|
+
| "Paused"
|
|
45
|
+
| "Resuming"
|
|
46
|
+
| "Deleting"
|
|
47
|
+
| "Deleted"
|
|
48
|
+
| "Error"
|
|
49
|
+
| string;
|
|
50
|
+
|
|
51
|
+
export interface SandboxStatus extends Record<string, unknown> {
|
|
52
|
+
state: SandboxState;
|
|
53
|
+
reason?: string;
|
|
54
|
+
message?: string;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface SandboxInfo extends Record<string, unknown> {
|
|
58
|
+
id: SandboxId;
|
|
59
|
+
image: ImageSpec;
|
|
60
|
+
entrypoint: string[];
|
|
61
|
+
metadata?: Record<string, string>;
|
|
62
|
+
status: SandboxStatus;
|
|
63
|
+
/**
|
|
64
|
+
* Sandbox creation time.
|
|
65
|
+
*/
|
|
66
|
+
createdAt: Date;
|
|
67
|
+
/**
|
|
68
|
+
* Sandbox expiration time (server-side TTL).
|
|
69
|
+
*/
|
|
70
|
+
expiresAt: Date;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface CreateSandboxRequest extends Record<string, unknown> {
|
|
74
|
+
image: ImageSpec;
|
|
75
|
+
entrypoint: string[];
|
|
76
|
+
/**
|
|
77
|
+
* Timeout in seconds (server semantics).
|
|
78
|
+
*/
|
|
79
|
+
timeout: number;
|
|
80
|
+
resourceLimits: ResourceLimits;
|
|
81
|
+
env?: Record<string, string>;
|
|
82
|
+
metadata?: Record<string, string>;
|
|
83
|
+
extensions?: Record<string, unknown>;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface CreateSandboxResponse extends Record<string, unknown> {
|
|
87
|
+
id: SandboxId;
|
|
88
|
+
status: SandboxStatus;
|
|
89
|
+
metadata?: Record<string, string>;
|
|
90
|
+
/**
|
|
91
|
+
* Sandbox expiration time after creation.
|
|
92
|
+
*/
|
|
93
|
+
expiresAt: Date;
|
|
94
|
+
/**
|
|
95
|
+
* Sandbox creation time.
|
|
96
|
+
*/
|
|
97
|
+
createdAt: Date;
|
|
98
|
+
entrypoint: string[];
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export interface PaginationInfo extends Record<string, unknown> {
|
|
102
|
+
page: number;
|
|
103
|
+
pageSize: number;
|
|
104
|
+
totalItems: number;
|
|
105
|
+
totalPages: number;
|
|
106
|
+
hasNextPage: boolean;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export interface ListSandboxesResponse extends Record<string, unknown> {
|
|
110
|
+
items: SandboxInfo[];
|
|
111
|
+
pagination?: PaginationInfo;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export interface RenewSandboxExpirationRequest {
|
|
115
|
+
expiresAt: string;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export interface RenewSandboxExpirationResponse extends Record<string, unknown> {
|
|
119
|
+
/**
|
|
120
|
+
* Updated expiration time (if the server returns it).
|
|
121
|
+
*/
|
|
122
|
+
expiresAt?: Date;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export interface Endpoint extends Record<string, unknown> {
|
|
126
|
+
endpoint: string;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export interface ListSandboxesParams {
|
|
130
|
+
/**
|
|
131
|
+
* Filter by lifecycle state (the API supports multiple `state` query params).
|
|
132
|
+
* Example: `{ states: ["Running", "Paused"] }`
|
|
133
|
+
*/
|
|
134
|
+
states?: string[];
|
|
135
|
+
/**
|
|
136
|
+
* Filter by metadata key-value pairs.
|
|
137
|
+
* NOTE: This will be encoded to a single `metadata` query parameter as described in the spec.
|
|
138
|
+
*/
|
|
139
|
+
metadata?: Record<string, string>;
|
|
140
|
+
page?: number;
|
|
141
|
+
pageSize?: number;
|
|
142
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Copyright 2026 Alibaba Group Holding Ltd.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
import createClient from "openapi-fetch";
|
|
16
|
+
import type { Client } from "openapi-fetch";
|
|
17
|
+
|
|
18
|
+
import type { paths as ExecdPaths } from "../api/execd.js";
|
|
19
|
+
|
|
20
|
+
export type ExecdClient = Client<ExecdPaths>;
|
|
21
|
+
|
|
22
|
+
export interface CreateExecdClientOptions {
|
|
23
|
+
/**
|
|
24
|
+
* Base URL to the Execd API (no `/v1` prefix).
|
|
25
|
+
* Examples:
|
|
26
|
+
* - `http://localhost:44772`
|
|
27
|
+
* - `http://api.opensandbox.io/sandboxes/<id>/port/44772`
|
|
28
|
+
*/
|
|
29
|
+
baseUrl: string;
|
|
30
|
+
/**
|
|
31
|
+
* Extra headers applied to every request.
|
|
32
|
+
*/
|
|
33
|
+
headers?: Record<string, string>;
|
|
34
|
+
/**
|
|
35
|
+
* Custom fetch implementation.
|
|
36
|
+
*
|
|
37
|
+
* Useful for proxies, custom TLS, request tracing, retries, or running in environments
|
|
38
|
+
* where a global `fetch` is not available.
|
|
39
|
+
*/
|
|
40
|
+
fetch?: typeof fetch;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function createExecdClient(opts: CreateExecdClientOptions): ExecdClient {
|
|
44
|
+
return createClient<ExecdPaths>({
|
|
45
|
+
baseUrl: opts.baseUrl,
|
|
46
|
+
headers: opts.headers,
|
|
47
|
+
fetch: opts.fetch,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// Copyright 2026 Alibaba Group Holding Ltd.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
import createClient from "openapi-fetch";
|
|
16
|
+
import type { Client } from "openapi-fetch";
|
|
17
|
+
|
|
18
|
+
import type { paths as LifecyclePaths } from "../api/lifecycle.js";
|
|
19
|
+
|
|
20
|
+
export type LifecycleClient = Client<LifecyclePaths>;
|
|
21
|
+
|
|
22
|
+
export interface CreateLifecycleClientOptions {
|
|
23
|
+
/**
|
|
24
|
+
* Base URL to OpenSandbox Lifecycle API, including the `/v1` prefix.
|
|
25
|
+
* Example: `http://localhost:8080/v1`
|
|
26
|
+
*/
|
|
27
|
+
baseUrl?: string;
|
|
28
|
+
/**
|
|
29
|
+
* API key for `OPEN-SANDBOX-API-KEY` header.
|
|
30
|
+
* If omitted, reads from `process.env.OPEN_SANDBOX_API_KEY` when available.
|
|
31
|
+
*/
|
|
32
|
+
apiKey?: string;
|
|
33
|
+
/**
|
|
34
|
+
* Extra headers applied to every request.
|
|
35
|
+
*/
|
|
36
|
+
headers?: Record<string, string>;
|
|
37
|
+
/**
|
|
38
|
+
* Custom fetch implementation.
|
|
39
|
+
*
|
|
40
|
+
* Useful for proxies, custom TLS, request tracing, retries, or running in environments
|
|
41
|
+
* where a global `fetch` is not available.
|
|
42
|
+
*/
|
|
43
|
+
fetch?: typeof fetch;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function readEnvApiKey(): string | undefined {
|
|
47
|
+
// Avoid requiring @types/node by not referencing `process` directly.
|
|
48
|
+
// In Node, `globalThis.process.env` exists; in browsers it won't.
|
|
49
|
+
const env = (globalThis as any)?.process?.env;
|
|
50
|
+
const v = env?.OPEN_SANDBOX_API_KEY;
|
|
51
|
+
return typeof v === "string" && v.length ? v : undefined;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function createLifecycleClient(opts: CreateLifecycleClientOptions = {}): LifecycleClient {
|
|
55
|
+
const apiKey = opts.apiKey ?? readEnvApiKey();
|
|
56
|
+
|
|
57
|
+
const headers: Record<string, string> = {
|
|
58
|
+
...(opts.headers ?? {}),
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
if (apiKey && !headers["OPEN-SANDBOX-API-KEY"]) {
|
|
62
|
+
headers["OPEN-SANDBOX-API-KEY"] = apiKey;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return createClient<LifecyclePaths>({
|
|
66
|
+
baseUrl: opts.baseUrl ?? "http://localhost:8080/v1",
|
|
67
|
+
headers,
|
|
68
|
+
fetch: opts.fetch,
|
|
69
|
+
});
|
|
70
|
+
}
|