oblien 1.3.0 → 2.0.1
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 +482 -422
- package/dist/client.d.ts +31 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +33 -0
- package/dist/client.js.map +1 -0
- package/dist/error.d.ts +29 -0
- package/dist/error.d.ts.map +1 -0
- package/dist/error.js +52 -0
- package/dist/error.js.map +1 -0
- package/dist/http.d.ts +20 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +108 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/resources/api-access.d.ts +21 -0
- package/dist/resources/api-access.d.ts.map +1 -0
- package/dist/resources/api-access.js +32 -0
- package/dist/resources/api-access.js.map +1 -0
- package/dist/resources/base.d.ts +17 -0
- package/dist/resources/base.d.ts.map +1 -0
- package/dist/resources/base.js +21 -0
- package/dist/resources/base.js.map +1 -0
- package/dist/resources/images.d.ts +11 -0
- package/dist/resources/images.d.ts.map +1 -0
- package/dist/resources/images.js +16 -0
- package/dist/resources/images.js.map +1 -0
- package/dist/resources/lifecycle.d.ts +23 -0
- package/dist/resources/lifecycle.d.ts.map +1 -0
- package/dist/resources/lifecycle.js +32 -0
- package/dist/resources/lifecycle.js.map +1 -0
- package/dist/resources/logs.d.ts +25 -0
- package/dist/resources/logs.d.ts.map +1 -0
- package/dist/resources/logs.js +51 -0
- package/dist/resources/logs.js.map +1 -0
- package/dist/resources/metadata.d.ts +15 -0
- package/dist/resources/metadata.d.ts.map +1 -0
- package/dist/resources/metadata.js +20 -0
- package/dist/resources/metadata.js.map +1 -0
- package/dist/resources/metrics.d.ts +17 -0
- package/dist/resources/metrics.d.ts.map +1 -0
- package/dist/resources/metrics.js +27 -0
- package/dist/resources/metrics.js.map +1 -0
- package/dist/resources/network.d.ts +17 -0
- package/dist/resources/network.d.ts.map +1 -0
- package/dist/resources/network.js +20 -0
- package/dist/resources/network.js.map +1 -0
- package/dist/resources/public-access.d.ts +15 -0
- package/dist/resources/public-access.d.ts.map +1 -0
- package/dist/resources/public-access.js +21 -0
- package/dist/resources/public-access.js.map +1 -0
- package/dist/resources/resources.d.ts +15 -0
- package/dist/resources/resources.d.ts.map +1 -0
- package/dist/resources/resources.js +20 -0
- package/dist/resources/resources.js.map +1 -0
- package/dist/resources/snapshots.d.ts +27 -0
- package/dist/resources/snapshots.d.ts.map +1 -0
- package/dist/resources/snapshots.js +45 -0
- package/dist/resources/snapshots.js.map +1 -0
- package/dist/resources/ssh.d.ts +19 -0
- package/dist/resources/ssh.d.ts.map +1 -0
- package/dist/resources/ssh.js +28 -0
- package/dist/resources/ssh.js.map +1 -0
- package/dist/resources/usage.d.ts +25 -0
- package/dist/resources/usage.d.ts.map +1 -0
- package/dist/resources/usage.js +44 -0
- package/dist/resources/usage.js.map +1 -0
- package/dist/resources/workloads.d.ts +39 -0
- package/dist/resources/workloads.d.ts.map +1 -0
- package/dist/resources/workloads.js +83 -0
- package/dist/resources/workloads.js.map +1 -0
- package/dist/runtime/exec.d.ts +71 -0
- package/dist/runtime/exec.d.ts.map +1 -0
- package/dist/runtime/exec.js +163 -0
- package/dist/runtime/exec.js.map +1 -0
- package/dist/runtime/files.d.ts +39 -0
- package/dist/runtime/files.d.ts.map +1 -0
- package/dist/runtime/files.js +143 -0
- package/dist/runtime/files.js.map +1 -0
- package/dist/runtime/search.d.ts +23 -0
- package/dist/runtime/search.d.ts.map +1 -0
- package/dist/runtime/search.js +65 -0
- package/dist/runtime/search.js.map +1 -0
- package/dist/runtime/terminal.d.ts +29 -0
- package/dist/runtime/terminal.d.ts.map +1 -0
- package/dist/runtime/terminal.js +58 -0
- package/dist/runtime/terminal.js.map +1 -0
- package/dist/runtime/watcher.d.ts +27 -0
- package/dist/runtime/watcher.d.ts.map +1 -0
- package/dist/runtime/watcher.js +53 -0
- package/dist/runtime/watcher.js.map +1 -0
- package/dist/runtime/ws.d.ts +92 -0
- package/dist/runtime/ws.d.ts.map +1 -0
- package/dist/runtime/ws.js +228 -0
- package/dist/runtime/ws.js.map +1 -0
- package/dist/runtime-http.d.ts +35 -0
- package/dist/runtime-http.d.ts.map +1 -0
- package/dist/runtime-http.js +99 -0
- package/dist/runtime-http.js.map +1 -0
- package/dist/runtime.d.ts +77 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +97 -0
- package/dist/runtime.js.map +1 -0
- package/dist/types/client.d.ts +7 -0
- package/dist/types/client.d.ts.map +1 -0
- package/dist/types/client.js +3 -0
- package/dist/types/client.js.map +1 -0
- package/dist/types/common.d.ts +13 -0
- package/dist/types/common.d.ts.map +1 -0
- package/dist/types/common.js +3 -0
- package/dist/types/common.js.map +1 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/network.d.ts +15 -0
- package/dist/types/network.d.ts.map +1 -0
- package/dist/types/network.js +3 -0
- package/dist/types/network.js.map +1 -0
- package/dist/types/resources.d.ts +10 -0
- package/dist/types/resources.d.ts.map +1 -0
- package/dist/types/resources.js +3 -0
- package/dist/types/resources.js.map +1 -0
- package/dist/types/runtime.d.ts +302 -0
- package/dist/types/runtime.d.ts.map +1 -0
- package/dist/types/runtime.js +3 -0
- package/dist/types/runtime.js.map +1 -0
- package/dist/types/workspace-resources.d.ts +186 -0
- package/dist/types/workspace-resources.d.ts.map +1 -0
- package/dist/types/workspace-resources.js +3 -0
- package/dist/types/workspace-resources.js.map +1 -0
- package/dist/types/workspace.d.ts +41 -0
- package/dist/types/workspace.d.ts.map +1 -0
- package/dist/types/workspace.js +3 -0
- package/dist/types/workspace.js.map +1 -0
- package/dist/workspace.d.ts +135 -0
- package/dist/workspace.d.ts.map +1 -0
- package/dist/workspace.js +194 -0
- package/dist/workspace.js.map +1 -0
- package/package.json +30 -69
- package/LICENSE +0 -21
- package/agents.js +0 -14
- package/browser.js +0 -6
- package/cdn.js +0 -6
- package/chat.js +0 -21
- package/credits.js +0 -11
- package/icons.js +0 -11
- package/index.d.ts +0 -986
- package/index.js +0 -63
- package/namespaces.js +0 -12
- package/sandbox.js +0 -12
- package/search.js +0 -11
- package/src/agents/agent.js +0 -229
- package/src/agents/index.js +0 -227
- package/src/agents/settings.js +0 -100
- package/src/agents/tools.js +0 -155
- package/src/browser/index.js +0 -474
- package/src/cdn/index.js +0 -769
- package/src/chat/index.js +0 -724
- package/src/chat/session.js +0 -93
- package/src/client.js +0 -175
- package/src/credits/index.js +0 -492
- package/src/icons/index.js +0 -185
- package/src/namespaces/index.js +0 -236
- package/src/namespaces/namespace.js +0 -274
- package/src/sandbox/core/api/base.js +0 -89
- package/src/sandbox/core/api/database.js +0 -340
- package/src/sandbox/core/api/files.js +0 -141
- package/src/sandbox/core/api/git.js +0 -174
- package/src/sandbox/core/api/search.js +0 -29
- package/src/sandbox/core/api/snapshots.js +0 -132
- package/src/sandbox/core/api/terminal.js +0 -20
- package/src/sandbox/core/auth.js +0 -256
- package/src/sandbox/core/client.js +0 -197
- package/src/sandbox/core/index.js +0 -22
- package/src/sandbox/core/managers/terminal.js +0 -453
- package/src/sandbox/core/managers/watcher.js +0 -197
- package/src/sandbox/core/types.js +0 -92
- package/src/sandbox/core/utils/http.js +0 -89
- package/src/sandbox/core/websocket/connection.js +0 -479
- package/src/sandbox/index.d.ts +0 -542
- package/src/sandbox/index.js +0 -234
- package/src/sandbox/sandbox.js +0 -313
- package/src/search/index.js +0 -206
- package/src/utils/guest-manager.js +0 -454
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import { BaseAPI } from './base.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Snapshots API - Handle snapshot/checkpoint operations
|
|
5
|
-
*/
|
|
6
|
-
export class SnapshotsAPI extends BaseAPI {
|
|
7
|
-
/**
|
|
8
|
-
* Create a checkpoint
|
|
9
|
-
* @param {Object} options - Checkpoint options
|
|
10
|
-
* @param {string} options.message - Commit message
|
|
11
|
-
* @returns {Promise<Object>} Checkpoint result
|
|
12
|
-
*/
|
|
13
|
-
async commit(options) {
|
|
14
|
-
return this.post('/snapshots/commit', options);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Go to a specific commit
|
|
19
|
-
* @param {Object} options - Goto options
|
|
20
|
-
* @param {string} options.commitHash - Commit hash to go to
|
|
21
|
-
* @returns {Promise<Object>} Goto result
|
|
22
|
-
*/
|
|
23
|
-
async goto(options) {
|
|
24
|
-
return this.post('/snapshots/goto', options);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* List all checkpoints
|
|
29
|
-
* @param {Object} [options] - List options
|
|
30
|
-
* @param {number} [options.limit=20] - Max number of checkpoints
|
|
31
|
-
* @returns {Promise<Object>} Checkpoints list
|
|
32
|
-
*/
|
|
33
|
-
async listCheckpoints(options = {}) {
|
|
34
|
-
const limit = options.limit || 20;
|
|
35
|
-
return this.get(`/snapshots/checkpoints?limit=${limit}`);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Get checkpoint info
|
|
40
|
-
* @param {string} commitHash - Commit hash
|
|
41
|
-
* @returns {Promise<Object>} Checkpoint info
|
|
42
|
-
*/
|
|
43
|
-
async getCheckpoint(commitHash) {
|
|
44
|
-
return this.get(`/snapshots/checkpoint/${commitHash}`);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Get current checkpoint
|
|
49
|
-
* @returns {Promise<Object>} Current checkpoint
|
|
50
|
-
*/
|
|
51
|
-
async getCurrentCheckpoint() {
|
|
52
|
-
return this.get('/snapshots/current-checkpoint');
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Cleanup all checkpoints
|
|
57
|
-
* @returns {Promise<Object>} Cleanup result
|
|
58
|
-
*/
|
|
59
|
-
async cleanup() {
|
|
60
|
-
return this.post('/snapshots/cleanup', {});
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Delete commits after a specific hash
|
|
65
|
-
* @param {Object} options - Delete options
|
|
66
|
-
* @param {string} options.commitHash - Commit hash
|
|
67
|
-
* @returns {Promise<Object>} Delete result
|
|
68
|
-
*/
|
|
69
|
-
async deleteAfter(options) {
|
|
70
|
-
return this.post('/snapshots/delete', options);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// Snapshot Archive methods
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Archive current repository
|
|
77
|
-
* @param {Object} options - Archive options
|
|
78
|
-
* @param {string} options.id - Archive ID
|
|
79
|
-
* @param {Object} [options.options] - Additional options
|
|
80
|
-
* @returns {Promise<Object>} Archive result
|
|
81
|
-
*/
|
|
82
|
-
async archive(options) {
|
|
83
|
-
return this.post('/snapshot-archive/archive', options);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Restore archived repository
|
|
88
|
-
* @param {Object} options - Restore options
|
|
89
|
-
* @param {string} options.id - Archive ID
|
|
90
|
-
* @param {boolean} [options.override=false] - Override existing
|
|
91
|
-
* @returns {Promise<Object>} Restore result
|
|
92
|
-
*/
|
|
93
|
-
async restore(options) {
|
|
94
|
-
return this.post('/snapshot-archive/restore-archive', options);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* List all archives
|
|
99
|
-
* @returns {Promise<Object>} Archives list
|
|
100
|
-
*/
|
|
101
|
-
async listArchives() {
|
|
102
|
-
return this.get('/snapshot-archive/archives');
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Get archive info
|
|
107
|
-
* @param {string} id - Archive ID
|
|
108
|
-
* @returns {Promise<Object>} Archive info
|
|
109
|
-
*/
|
|
110
|
-
async getArchive(id) {
|
|
111
|
-
return this.get(`/snapshot-archive/archive/${id}`);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Delete archive
|
|
116
|
-
* @param {string} id - Archive ID
|
|
117
|
-
* @returns {Promise<Object>} Delete result
|
|
118
|
-
*/
|
|
119
|
-
async deleteArchive(id) {
|
|
120
|
-
return this.delete(`/snapshot-archive/archive/${id}`);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Cleanup archives
|
|
125
|
-
* @param {Object} [options] - Cleanup options
|
|
126
|
-
* @returns {Promise<Object>} Cleanup result
|
|
127
|
-
*/
|
|
128
|
-
async cleanupArchives(options = {}) {
|
|
129
|
-
return this.post('/snapshot-archive/cleanup-archives', options);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { BaseAPI } from './base.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Terminal API - Handle terminal operations
|
|
5
|
-
*/
|
|
6
|
-
export class TerminalAPI extends BaseAPI {
|
|
7
|
-
/**
|
|
8
|
-
* Execute a terminal command
|
|
9
|
-
* @param {Object} options - Terminal options
|
|
10
|
-
* @param {string} options.command - Command to execute
|
|
11
|
-
* @param {string} [options.cwd] - Working directory
|
|
12
|
-
* @param {Object} [options.env] - Environment variables
|
|
13
|
-
* @param {number} [options.timeout] - Execution timeout
|
|
14
|
-
* @returns {Promise<Object>} Command result
|
|
15
|
-
*/
|
|
16
|
-
async execute(options) {
|
|
17
|
-
return this.post('/terminal', options);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
package/src/sandbox/core/auth.js
DELETED
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
import * as http from './utils/http.js';
|
|
2
|
-
import { SandboxClient } from './client.js';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Authentication client for managing Oblien account and sandboxes
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```javascript
|
|
9
|
-
* import { OblienClient } from 'agent-sandbox';
|
|
10
|
-
*
|
|
11
|
-
* const client = new OblienClient({
|
|
12
|
-
* clientId: process.env.OBLIEN_CLIENT_ID,
|
|
13
|
-
* clientSecret: process.env.OBLIEN_CLIENT_SECRET
|
|
14
|
-
* });
|
|
15
|
-
*
|
|
16
|
-
* // Create a sandbox and get ready-to-use client
|
|
17
|
-
* const sandbox = await client.createSandbox({
|
|
18
|
-
* name: 'my-sandbox',
|
|
19
|
-
* region: 'us-east-1'
|
|
20
|
-
* });
|
|
21
|
-
*
|
|
22
|
-
* // Now use it directly
|
|
23
|
-
* await sandbox.files.list({ dirPath: '/opt/app' });
|
|
24
|
-
* await sandbox.git.clone({ url: '...', targetDir: '/opt/app' });
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
export class OblienClient {
|
|
28
|
-
/**
|
|
29
|
-
* Create a new OblienClient instance
|
|
30
|
-
* @param {Object} config - Client configuration
|
|
31
|
-
* @param {string} config.clientId - Your Oblien client ID
|
|
32
|
-
* @param {string} config.clientSecret - Your Oblien client secret
|
|
33
|
-
* @param {string} [apiURL='https://api.oblien.com/sandbox'] - API base URL
|
|
34
|
-
*/
|
|
35
|
-
constructor(config, apiURL = 'https://api.oblien.com/sandbox') {
|
|
36
|
-
if (!config.clientId && !config.headers) {
|
|
37
|
-
throw new Error('clientId is required');
|
|
38
|
-
}
|
|
39
|
-
if (!config.clientSecret && !config.headers) {
|
|
40
|
-
throw new Error('clientSecret is required');
|
|
41
|
-
}
|
|
42
|
-
this.headers = config.headers || {};
|
|
43
|
-
this.clientId = config.clientId;
|
|
44
|
-
this.clientSecret = config.clientSecret;
|
|
45
|
-
this.apiURL = apiURL.replace(/\/$/, '');
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Sandboxes API (low-level access)
|
|
49
|
-
* @type {SandboxesAPI}
|
|
50
|
-
*/
|
|
51
|
-
this.sandboxes = new SandboxesAPI(this);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Create a new sandbox and return a ready-to-use SandboxClient
|
|
56
|
-
*
|
|
57
|
-
* @param {Object} [options] - Sandbox options
|
|
58
|
-
* @param {string} [options.name] - Sandbox name
|
|
59
|
-
* @param {string} [options.region] - Region (us-east-1, eu-west-1, etc.)
|
|
60
|
-
* @param {string} [options.template] - Template to use
|
|
61
|
-
* @param {Object} [options.config] - Additional configuration
|
|
62
|
-
* @returns {Promise<SandboxClient>} Ready-to-use SandboxClient instance
|
|
63
|
-
*
|
|
64
|
-
* @example
|
|
65
|
-
* ```javascript
|
|
66
|
-
* const sandbox = await client.createSandbox({
|
|
67
|
-
* name: 'my-dev-sandbox',
|
|
68
|
-
* region: 'us-east-1'
|
|
69
|
-
* });
|
|
70
|
-
*
|
|
71
|
-
* // Use it immediately
|
|
72
|
-
* await sandbox.files.list({ dirPath: '/opt/app' });
|
|
73
|
-
* ```
|
|
74
|
-
*/
|
|
75
|
-
async createSandbox(options = {}) {
|
|
76
|
-
const sandboxInfo = await this.sandboxes.create(options);
|
|
77
|
-
return new SandboxClient({
|
|
78
|
-
baseURL: sandboxInfo.url,
|
|
79
|
-
token: sandboxInfo.token,
|
|
80
|
-
sandboxId: sandboxInfo.id,
|
|
81
|
-
sandboxName: sandboxInfo.name
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Connect to an existing sandbox by ID
|
|
87
|
-
*
|
|
88
|
-
* @param {string} sandboxId - Sandbox ID
|
|
89
|
-
* @returns {Promise<SandboxClient>} Ready-to-use SandboxClient instance
|
|
90
|
-
*
|
|
91
|
-
* @example
|
|
92
|
-
* ```javascript
|
|
93
|
-
* const sandbox = await client.sandbox('sandbox_abc123');
|
|
94
|
-
* await sandbox.files.list({ dirPath: '/opt/app' });
|
|
95
|
-
* ```
|
|
96
|
-
*/
|
|
97
|
-
async sandbox(sandboxId) {
|
|
98
|
-
const sandboxInfo = await this.sandboxes.get(sandboxId);
|
|
99
|
-
if (!sandboxInfo.success) {
|
|
100
|
-
throw new Error(JSON.stringify(sandboxInfo));
|
|
101
|
-
}
|
|
102
|
-
return new SandboxClient({
|
|
103
|
-
baseURL: sandboxInfo.sandbox.url,
|
|
104
|
-
token: sandboxInfo.sandbox.token,
|
|
105
|
-
sandboxId: sandboxInfo.sandbox.id,
|
|
106
|
-
sandboxName: sandboxInfo.sandbox.name
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Get authorization headers with client credentials
|
|
112
|
-
* @returns {Object} Headers with client credentials
|
|
113
|
-
*/
|
|
114
|
-
getAuthHeaders() {
|
|
115
|
-
return {
|
|
116
|
-
'X-Client-ID': this.clientId,
|
|
117
|
-
'X-Client-Secret': this.clientSecret,
|
|
118
|
-
...this.headers
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Make authenticated GET request
|
|
124
|
-
* @param {string} path - API path
|
|
125
|
-
* @returns {Promise<any>} Response data
|
|
126
|
-
*/
|
|
127
|
-
async get(path) {
|
|
128
|
-
const headers = this.getAuthHeaders();
|
|
129
|
-
return http.get(`${this.apiURL}${path}`, headers);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Make authenticated POST request
|
|
134
|
-
* @param {string} path - API path
|
|
135
|
-
* @param {Object} body - Request body
|
|
136
|
-
* @returns {Promise<any>} Response data
|
|
137
|
-
*/
|
|
138
|
-
async post(path, body = {}) {
|
|
139
|
-
const headers = this.getAuthHeaders();
|
|
140
|
-
return http.post(`${this.apiURL}${path}`, body, headers);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Make authenticated DELETE request
|
|
145
|
-
* @param {string} path - API path
|
|
146
|
-
* @returns {Promise<any>} Response data
|
|
147
|
-
*/
|
|
148
|
-
async delete(path) {
|
|
149
|
-
const headers = this.getAuthHeaders();
|
|
150
|
-
return http.del(`${this.apiURL}${path}`, headers);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Sandboxes API - Manage sandbox instances
|
|
156
|
-
*/
|
|
157
|
-
class SandboxesAPI {
|
|
158
|
-
/**
|
|
159
|
-
* @param {OblienClient} client - OblienClient instance
|
|
160
|
-
*/
|
|
161
|
-
constructor(client) {
|
|
162
|
-
this.client = client;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Create a new sandbox
|
|
167
|
-
* @param {Object} options - Sandbox options
|
|
168
|
-
* @param {string} [options.name] - Sandbox name
|
|
169
|
-
* @param {string} [options.region] - Region (us-east-1, eu-west-1, etc.)
|
|
170
|
-
* @param {string} [options.template] - Template to use
|
|
171
|
-
* @param {Object} [options.config] - Additional configuration
|
|
172
|
-
* @returns {Promise<Object>} Sandbox details {id, token, url, name, status}
|
|
173
|
-
*/
|
|
174
|
-
async create(options = {}) {
|
|
175
|
-
const response = await this.client.post('/', options);
|
|
176
|
-
return response.sandbox;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* List all sandboxes
|
|
181
|
-
* @param {Object} [options] - List options
|
|
182
|
-
* @param {number} [options.page=1] - Page number
|
|
183
|
-
* @param {number} [options.limit=20] - Items per page
|
|
184
|
-
* @param {string} [options.status] - Filter by status (active, stopped, etc.)
|
|
185
|
-
* @returns {Promise<Object>} Sandboxes list
|
|
186
|
-
*/
|
|
187
|
-
async list(options = {}) {
|
|
188
|
-
const params = new URLSearchParams(options).toString();
|
|
189
|
-
const path = `/${params ? '?' + params : ''}`;
|
|
190
|
-
return this.client.get(path);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* Get sandbox details
|
|
195
|
-
* @param {string} sandboxId - Sandbox ID
|
|
196
|
-
* @returns {Promise<Object>} Sandbox details
|
|
197
|
-
*/
|
|
198
|
-
async get(sandboxId) {
|
|
199
|
-
return this.client.get(`/${sandboxId}`);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* Delete a sandbox
|
|
204
|
-
* @param {string} sandboxId - Sandbox ID
|
|
205
|
-
* @returns {Promise<Object>} Delete confirmation
|
|
206
|
-
*/
|
|
207
|
-
async delete(sandboxId) {
|
|
208
|
-
return this.client.delete(`/${sandboxId}`);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* Start a stopped sandbox
|
|
213
|
-
* @param {string} sandboxId - Sandbox ID
|
|
214
|
-
* @returns {Promise<Object>} Sandbox details
|
|
215
|
-
*/
|
|
216
|
-
async start(sandboxId) {
|
|
217
|
-
return this.client.post(`/${sandboxId}/start`);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* Stop a running sandbox
|
|
222
|
-
* @param {string} sandboxId - Sandbox ID
|
|
223
|
-
* @returns {Promise<Object>} Sandbox details
|
|
224
|
-
*/
|
|
225
|
-
async stop(sandboxId) {
|
|
226
|
-
return this.client.post(`/${sandboxId}/stop`);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* Restart a sandbox
|
|
231
|
-
* @param {string} sandboxId - Sandbox ID
|
|
232
|
-
* @returns {Promise<Object>} Sandbox details
|
|
233
|
-
*/
|
|
234
|
-
async restart(sandboxId) {
|
|
235
|
-
return this.client.post(`/${sandboxId}/restart`);
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* Regenerate sandbox token
|
|
240
|
-
* @param {string} sandboxId - Sandbox ID
|
|
241
|
-
* @returns {Promise<Object>} New token details
|
|
242
|
-
*/
|
|
243
|
-
async regenerateToken(sandboxId) {
|
|
244
|
-
return this.client.post(`/${sandboxId}/regenerate-token`);
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* Get sandbox metrics
|
|
249
|
-
* @param {string} sandboxId - Sandbox ID
|
|
250
|
-
* @returns {Promise<Object>} Metrics data
|
|
251
|
-
*/
|
|
252
|
-
async metrics(sandboxId) {
|
|
253
|
-
return this.client.get(`/${sandboxId}/metrics`);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
|
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
import { FilesAPI } from './api/files.js';
|
|
2
|
-
import { GitAPI } from './api/git.js';
|
|
3
|
-
import { SearchAPI } from './api/search.js';
|
|
4
|
-
import { TerminalAPI } from './api/terminal.js';
|
|
5
|
-
import { SnapshotsAPI } from './api/snapshots.js';
|
|
6
|
-
import { DatabaseAPI } from './api/database.js';
|
|
7
|
-
import { WebSocketConnection } from './websocket/connection.js';
|
|
8
|
-
import { TerminalManager } from './managers/terminal.js';
|
|
9
|
-
import { WatcherManager } from './managers/watcher.js';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Sandbox API Client - Interact with a specific sandbox instance
|
|
13
|
-
*
|
|
14
|
-
* This client is used to interact with an individual sandbox after it has been created.
|
|
15
|
-
* The token is obtained when creating a sandbox via OblienClient.
|
|
16
|
-
*
|
|
17
|
-
* Full documentation: https://oblien.com/docs/agent-sandbox
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```javascript
|
|
21
|
-
* import { SandboxClient } from 'agent-sandbox';
|
|
22
|
-
*
|
|
23
|
-
* // Token obtained from sandbox creation
|
|
24
|
-
* const sandbox = new SandboxClient({
|
|
25
|
-
* baseURL: 'https://sandbox.oblien.com',
|
|
26
|
-
* token: 'sandbox_token_here'
|
|
27
|
-
* });
|
|
28
|
-
*
|
|
29
|
-
* // List files
|
|
30
|
-
* const files = await sandbox.files.list({ dirPath: '/opt/app' });
|
|
31
|
-
*
|
|
32
|
-
* // Read a file
|
|
33
|
-
* const content = await sandbox.files.get({ filePath: '/opt/app/index.js' });
|
|
34
|
-
*
|
|
35
|
-
* // Create a file
|
|
36
|
-
* await sandbox.files.create({
|
|
37
|
-
* fullPath: '/opt/app/newfile.js',
|
|
38
|
-
* content: 'console.log("Hello World");'
|
|
39
|
-
* });
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
export class SandboxClient {
|
|
43
|
-
/**
|
|
44
|
-
* Create a new SandboxClient instance
|
|
45
|
-
*
|
|
46
|
-
* Note: Prefer using `client.createSandbox()` or `client.sandbox(id)` from OblienClient
|
|
47
|
-
* for automatic setup. Use this constructor directly only if you have a token already.
|
|
48
|
-
*
|
|
49
|
-
* @param {Object} config - Client configuration
|
|
50
|
-
* @param {string} config.baseURL - Base URL of the sandbox instance
|
|
51
|
-
* @param {string} config.token - Sandbox authentication token
|
|
52
|
-
* @param {string} [config.sandboxId] - Sandbox ID (optional)
|
|
53
|
-
* @param {string} [config.sandboxName] - Sandbox name (optional)
|
|
54
|
-
*/
|
|
55
|
-
constructor(config) {
|
|
56
|
-
const { baseURL = 'https://sandbox.oblien.com', token, sandboxId, sandboxName, oblienClient } = config;
|
|
57
|
-
|
|
58
|
-
// Token can be null if oblienClient is provided (dynamic fetching)
|
|
59
|
-
if (!token && !oblienClient) {
|
|
60
|
-
throw new Error('token or oblienClient is required');
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
this.baseURL = baseURL;
|
|
64
|
-
this.token = token;
|
|
65
|
-
this.sandboxId = sandboxId;
|
|
66
|
-
this.sandboxName = sandboxName;
|
|
67
|
-
this.oblienClient = oblienClient;
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Shared WebSocket connection (ONE connection for everything)
|
|
71
|
-
* @type {WebSocketConnection}
|
|
72
|
-
* @private
|
|
73
|
-
*/
|
|
74
|
-
this._wsConnection = new WebSocketConnection({
|
|
75
|
-
baseURL,
|
|
76
|
-
token,
|
|
77
|
-
sandboxId,
|
|
78
|
-
onStatusCheck: async () => {
|
|
79
|
-
// Check if sandbox is active before connecting
|
|
80
|
-
if (this.oblienClient && this.sandboxId) {
|
|
81
|
-
try {
|
|
82
|
-
const result = await this.oblienClient.sandboxes.get(this.sandboxId);
|
|
83
|
-
if (!result.success) return false;
|
|
84
|
-
const status = result.sandbox?.status;
|
|
85
|
-
return status === 'active' || status === 'running';
|
|
86
|
-
} catch (error) {
|
|
87
|
-
console.warn('[Sandbox] Status check failed:', error.message);
|
|
88
|
-
return true; // Allow connection attempt if check fails
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
return true;
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Files API (token resolved dynamically)
|
|
97
|
-
* @type {FilesAPI}
|
|
98
|
-
*/
|
|
99
|
-
this.files = new FilesAPI(this);
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Git API (token resolved dynamically)
|
|
103
|
-
* @type {GitAPI}
|
|
104
|
-
*/
|
|
105
|
-
this.git = new GitAPI(this);
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Search API (token resolved dynamically)
|
|
109
|
-
* @type {SearchAPI}
|
|
110
|
-
*/
|
|
111
|
-
this.search = new SearchAPI(this);
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Terminal API (token resolved dynamically)
|
|
115
|
-
* @type {TerminalAPI}
|
|
116
|
-
*/
|
|
117
|
-
this.staticTerminal = new TerminalAPI(this);
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Snapshots API (token resolved dynamically)
|
|
121
|
-
* @type {SnapshotsAPI}
|
|
122
|
-
*/
|
|
123
|
-
this.snapshots = new SnapshotsAPI(this);
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Database API (token resolved dynamically)
|
|
127
|
-
* @type {DatabaseAPI}
|
|
128
|
-
*/
|
|
129
|
-
this.database = new DatabaseAPI(this);
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Terminal Manager - Real-time terminal via shared WebSocket
|
|
133
|
-
* @type {TerminalManager}
|
|
134
|
-
*/
|
|
135
|
-
this.terminal = new TerminalManager(this._wsConnection);
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* File Watcher - Real-time file watching via shared WebSocket
|
|
139
|
-
* @type {WatcherManager}
|
|
140
|
-
*/
|
|
141
|
-
this.watcher = new WatcherManager(this._wsConnection);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Get base URL for APIs
|
|
146
|
-
* @returns {string}
|
|
147
|
-
*/
|
|
148
|
-
getBaseURL() {
|
|
149
|
-
return this.baseURL;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Get token for APIs (can be overridden for dynamic fetching)
|
|
154
|
-
* @returns {Promise<string>}
|
|
155
|
-
*/
|
|
156
|
-
async getToken() {
|
|
157
|
-
return this.token;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Test connection to the sandbox API
|
|
162
|
-
* @returns {Promise<boolean>} True if connection is successful
|
|
163
|
-
*/
|
|
164
|
-
async testConnection() {
|
|
165
|
-
try {
|
|
166
|
-
const response = await fetch(this.files.baseURL);
|
|
167
|
-
const data = await response.json();
|
|
168
|
-
return data.success === true;
|
|
169
|
-
} catch (error) {
|
|
170
|
-
return false;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* Connect to WebSocket (terminal/watcher auto-connect when used)
|
|
176
|
-
* @returns {Promise<void>}
|
|
177
|
-
*/
|
|
178
|
-
async connect() {
|
|
179
|
-
await this._wsConnection.connect();
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Disconnect from WebSocket
|
|
184
|
-
*/
|
|
185
|
-
disconnect() {
|
|
186
|
-
this._wsConnection.disconnect();
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* Check if WebSocket is connected
|
|
191
|
-
* @returns {boolean}
|
|
192
|
-
*/
|
|
193
|
-
get connected() {
|
|
194
|
-
return this._wsConnection.connected;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* agent-sandbox
|
|
3
|
-
*
|
|
4
|
-
* An isolated, intelligent environment where AI agents can build, run, and manage things
|
|
5
|
-
*
|
|
6
|
-
* Full documentation: https://oblien.com/docs/agent-sandbox
|
|
7
|
-
*
|
|
8
|
-
* @module agent-sandbox
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
export { OblienClient } from './auth.js';
|
|
12
|
-
export { SandboxClient } from './client.js';
|
|
13
|
-
export { FilesAPI } from './api/files.js';
|
|
14
|
-
export { GitAPI } from './api/git.js';
|
|
15
|
-
export { SearchAPI } from './api/search.js';
|
|
16
|
-
export { TerminalAPI } from './api/terminal.js';
|
|
17
|
-
export { SnapshotsAPI } from './api/snapshots.js';
|
|
18
|
-
export { DatabaseAPI } from './api/database.js';
|
|
19
|
-
export { TerminalManager, Terminal } from './managers/terminal.js';
|
|
20
|
-
export { WatcherManager } from './managers/watcher.js';
|
|
21
|
-
export { WebSocketConnection } from './websocket/connection.js';
|
|
22
|
-
|