computesdk 1.0.0 → 1.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/dist/index.d.mts +467 -0
- package/dist/index.d.ts +467 -0
- package/dist/index.js +534 -1
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +494 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +69 -24
- package/README.md +0 -185
package/README.md
DELETED
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
# ComputeSDK Documentation
|
|
2
|
-
|
|
3
|
-
The ComputeSDK provides a powerful interface for interacting with remote compute environments, enabling terminal access, file operations, and process execution in a secure containerized environment.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npm install computesdk
|
|
9
|
-
# or
|
|
10
|
-
yarn add computesdk
|
|
11
|
-
# or
|
|
12
|
-
pnpm add computesdk
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
## Quick Start
|
|
16
|
-
|
|
17
|
-
```javascript
|
|
18
|
-
import { ComputeClient } from 'computesdk';
|
|
19
|
-
|
|
20
|
-
async function main() {
|
|
21
|
-
// Create a new compute client
|
|
22
|
-
const client = new ComputeClient();
|
|
23
|
-
|
|
24
|
-
// Create a new compute instance
|
|
25
|
-
const compute = await client.create();
|
|
26
|
-
|
|
27
|
-
// Listen for server ready events
|
|
28
|
-
compute.onServerReady((port, url) => {
|
|
29
|
-
console.log(`Server is ready on port ${port} at ${url}`);
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
## Core Components
|
|
35
|
-
|
|
36
|
-
### ComputeClient
|
|
37
|
-
|
|
38
|
-
The main entry point for creating and managing compute instances.
|
|
39
|
-
|
|
40
|
-
```javascript
|
|
41
|
-
const client = new ComputeClient({
|
|
42
|
-
baseUrl: 'https://api.computesdk.com' // Optional, defaults to this value
|
|
43
|
-
});
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
Methods:
|
|
47
|
-
- `create()`: Creates a new compute instance and returns a `Compute` object
|
|
48
|
-
```javascript
|
|
49
|
-
// Create a new compute instance
|
|
50
|
-
const compute = await client.create();
|
|
51
|
-
|
|
52
|
-
// The returned compute object provides:
|
|
53
|
-
// - WebSocket connection to the compute environment
|
|
54
|
-
// - Terminal operations
|
|
55
|
-
// - File system operations
|
|
56
|
-
// - Process execution capabilities
|
|
57
|
-
|
|
58
|
-
// Returns: Promise<Compute>
|
|
59
|
-
// Throws: Error if compute creation fails
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
- `delete(computeId)`: Terminates and removes a compute instance
|
|
63
|
-
```javascript
|
|
64
|
-
// Delete a specific compute instance
|
|
65
|
-
await client.delete(compute.computeId);
|
|
66
|
-
|
|
67
|
-
// Parameters:
|
|
68
|
-
// - computeId: string (required) - The ID of the compute instance to delete
|
|
69
|
-
|
|
70
|
-
// Returns: Promise<void>
|
|
71
|
-
// Throws: Error if deletion fails or computeId is invalid
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
Note: It's recommended to use the `compute.teardown()` method instead of calling `delete()` directly, as it properly closes WebSocket connections and handles cleanup.
|
|
75
|
-
|
|
76
|
-
### Compute
|
|
77
|
-
|
|
78
|
-
Represents a compute instance with capabilities for file management, terminal operations, and process execution.
|
|
79
|
-
|
|
80
|
-
#### File Operations
|
|
81
|
-
|
|
82
|
-
```javascript
|
|
83
|
-
// Watch files for changes
|
|
84
|
-
const watcher = compute.watchFiles({
|
|
85
|
-
path: '/home/project',
|
|
86
|
-
includeContent: false, // Optional: include file contents in change events
|
|
87
|
-
ignored: ['**/node_modules/**'] // Optional: patterns to ignore
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
watcher.onChanged(data => console.log('File changed:', data));
|
|
91
|
-
|
|
92
|
-
// Read file contents
|
|
93
|
-
const content = await compute.readFile('/path/to/file');
|
|
94
|
-
|
|
95
|
-
// Write to a file
|
|
96
|
-
await compute.writeFile('/path/to/file', 'content');
|
|
97
|
-
|
|
98
|
-
// Create directories
|
|
99
|
-
await compute.mkdir('/path/to/dir', {
|
|
100
|
-
recursive: true // Optional: create parent directories if they don't exist
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
// Delete files
|
|
104
|
-
await compute.deleteFile('/path/to/file');
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
#### Terminal Operations
|
|
108
|
-
|
|
109
|
-
```javascript
|
|
110
|
-
// Create a new terminal
|
|
111
|
-
const terminal = await compute.createTerminal({
|
|
112
|
-
rows: 24, // Optional
|
|
113
|
-
cols: 80, // Optional
|
|
114
|
-
command: null, // Optional
|
|
115
|
-
args: [] // Optional
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
// Terminal event handlers
|
|
119
|
-
terminal.onData(data => console.log('Received:', data));
|
|
120
|
-
terminal.onExit(({ exitCode, signal }) => console.log('Terminal exited'));
|
|
121
|
-
|
|
122
|
-
// Send input to terminal
|
|
123
|
-
terminal.write('echo "Hello World"\n');
|
|
124
|
-
|
|
125
|
-
// Resize terminal
|
|
126
|
-
terminal.resize(100, 30);
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
#### Process Execution
|
|
130
|
-
|
|
131
|
-
```javascript
|
|
132
|
-
// Execute commands
|
|
133
|
-
const result = await compute.exec('npm install');
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
#### Event Handlers
|
|
137
|
-
|
|
138
|
-
```javascript
|
|
139
|
-
// Connection events
|
|
140
|
-
compute.onConnected(() => console.log('Connected to compute instance'));
|
|
141
|
-
compute.onError(error => console.error('Error:', error));
|
|
142
|
-
|
|
143
|
-
// Port and server events
|
|
144
|
-
compute.onPortOpened((port, url) => console.log(`Port ${port} opened at ${url}`));
|
|
145
|
-
compute.onServerReady((port, url) => console.log(`Server ready on port ${port} at ${url}`));
|
|
146
|
-
```
|
|
147
|
-
|
|
148
|
-
## WebSocket Communication
|
|
149
|
-
|
|
150
|
-
The SDK uses WebSocket connections for real-time communication with compute instances. It automatically handles:
|
|
151
|
-
- Secure WebSocket connections (wss:// for https, ws:// for http)
|
|
152
|
-
- Connection retries (up to 3 attempts with exponential backoff)
|
|
153
|
-
- Automatic reconnection on unexpected disconnections
|
|
154
|
-
|
|
155
|
-
## Debug Mode
|
|
156
|
-
|
|
157
|
-
Enable debug logging by setting localStorage.DEBUG to 'true' in the browser:
|
|
158
|
-
|
|
159
|
-
```javascript
|
|
160
|
-
localStorage.setItem('DEBUG', 'true');
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
## Cleanup
|
|
164
|
-
|
|
165
|
-
To properly clean up resources:
|
|
166
|
-
|
|
167
|
-
```javascript
|
|
168
|
-
await compute.teardown(); // Closes WebSocket and deletes compute instance
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
## Security Notes
|
|
172
|
-
|
|
173
|
-
- The SDK automatically handles secure WebSocket connections when using HTTPS
|
|
174
|
-
- All file paths should be properly sanitized before use
|
|
175
|
-
- Node modules are automatically ignored in file watching operations
|
|
176
|
-
- The SDK includes automatic cleanup on window unload in browser environments
|
|
177
|
-
|
|
178
|
-
## Error Handling
|
|
179
|
-
|
|
180
|
-
The SDK provides comprehensive error handling through:
|
|
181
|
-
- Promise rejections for async operations
|
|
182
|
-
- Error events through the onError handler
|
|
183
|
-
- Detailed console logging in debug mode
|
|
184
|
-
|
|
185
|
-
For more information and advanced usage, please refer to the API documentation or contact support.
|