wuying-agentbay-sdk 0.5.0 → 0.6.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 +84 -153
- package/dist/index.cjs +1153 -167
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +3585 -3163
- package/dist/index.d.ts +3585 -3163
- package/dist/index.mjs +1140 -154
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,185 +1,116 @@
|
|
|
1
|
-
#
|
|
1
|
+
# AgentBay SDK for TypeScript
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> Execute commands, manipulate files, and run code in cloud environments
|
|
4
4
|
|
|
5
|
-
##
|
|
6
|
-
|
|
7
|
-
- Node.js (v14 or later)
|
|
8
|
-
- npm (v6 or later)
|
|
9
|
-
|
|
10
|
-
## Installation
|
|
11
|
-
|
|
12
|
-
### For Development
|
|
13
|
-
|
|
14
|
-
Clone the repository and install dependencies:
|
|
15
|
-
|
|
16
|
-
```bash
|
|
17
|
-
git clone https://github.com/aliyun/wuying-agentbay-sdk.git
|
|
18
|
-
cd wuying-agentbay-sdk/typescript
|
|
19
|
-
npm install
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
### For Usage in Your Project
|
|
5
|
+
## 📦 Installation
|
|
23
6
|
|
|
24
7
|
```bash
|
|
25
8
|
npm install wuying-agentbay-sdk
|
|
26
9
|
```
|
|
27
10
|
|
|
28
|
-
##
|
|
29
|
-
|
|
30
|
-
- **Build the project**:
|
|
31
|
-
```bash
|
|
32
|
-
npm run build
|
|
33
|
-
```
|
|
11
|
+
## 🚀 Prerequisites
|
|
34
12
|
|
|
35
|
-
|
|
36
|
-
```bash
|
|
37
|
-
npm test
|
|
38
|
-
```
|
|
13
|
+
Before using the SDK, you need to:
|
|
39
14
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
## Examples
|
|
46
|
-
|
|
47
|
-
You can find examples in the `docs/examples/typescript` directory, including:
|
|
48
|
-
|
|
49
|
-
- Basic SDK usage
|
|
50
|
-
- Context management
|
|
51
|
-
- Command execution
|
|
52
|
-
- File system operations
|
|
53
|
-
- UI interaction
|
|
54
|
-
- Application management
|
|
55
|
-
- Window management
|
|
56
|
-
- Session management
|
|
57
|
-
|
|
58
|
-
To run the examples:
|
|
59
|
-
|
|
60
|
-
```bash
|
|
61
|
-
npx ts-node docs/examples/typescript/basic-usage.ts
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
## TypeScript-Specific Usage
|
|
15
|
+
1. Register an Alibaba Cloud account: [https://aliyun.com](https://aliyun.com)
|
|
16
|
+
2. Get API credentials: [AgentBay Console](https://agentbay.console.aliyun.com/service-management)
|
|
17
|
+
3. Set environment variable: `export AGENTBAY_API_KEY=your_api_key`
|
|
65
18
|
|
|
19
|
+
## 🚀 Quick Start
|
|
66
20
|
```typescript
|
|
67
|
-
import { AgentBay
|
|
21
|
+
import { AgentBay } from 'wuying-agentbay-sdk';
|
|
68
22
|
|
|
69
23
|
async function main() {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
24
|
+
// Create session
|
|
25
|
+
const agentBay = new AgentBay();
|
|
26
|
+
const result = await agentBay.create();
|
|
27
|
+
|
|
28
|
+
if (result.success) {
|
|
29
|
+
const session = result.session;
|
|
30
|
+
|
|
31
|
+
// Execute command
|
|
32
|
+
const cmdResult = await session.command.executeCommand("ls -la");
|
|
33
|
+
console.log(cmdResult.output);
|
|
34
|
+
|
|
35
|
+
// File operations
|
|
36
|
+
await session.fileSystem.writeFile("/tmp/test.txt", "Hello World");
|
|
37
|
+
const content = await session.fileSystem.readFile("/tmp/test.txt");
|
|
38
|
+
console.log(content.data);
|
|
80
39
|
}
|
|
81
|
-
});
|
|
82
|
-
const session = createResponse.session;
|
|
83
|
-
|
|
84
|
-
// Execute a command
|
|
85
|
-
const commandResponse = await session.command.executeCommand('ls -la');
|
|
86
|
-
|
|
87
|
-
// Run code
|
|
88
|
-
const codeResponse = await session.code.runCode('print("Hello World")', 'python');
|
|
89
|
-
|
|
90
|
-
// File operations
|
|
91
|
-
const fileContent = await session.fileSystem.readFile('/etc/hosts');
|
|
92
|
-
await session.fileSystem.writeFile('/tmp/test.txt', 'Hello World');
|
|
93
|
-
|
|
94
|
-
// UI operations
|
|
95
|
-
const screenshot = await session.ui.screenshot();
|
|
96
|
-
|
|
97
|
-
// Application management
|
|
98
|
-
const installedApps = await session.application.getInstalledApps(true, false, true);
|
|
99
|
-
const visibleApps = await session.application.listVisibleApps();
|
|
100
|
-
|
|
101
|
-
// Window management
|
|
102
|
-
const windows = await session.window.listRootWindows();
|
|
103
|
-
const activeWindow = await session.window.getActiveWindow();
|
|
104
|
-
|
|
105
|
-
// Session management
|
|
106
|
-
await session.setLabels({ environment: 'production' });
|
|
107
|
-
const labels = await session.getLabels();
|
|
108
|
-
const info = await session.info();
|
|
109
|
-
|
|
110
|
-
// Context management
|
|
111
|
-
const contexts = await agentBay.context.list();
|
|
112
|
-
|
|
113
|
-
// Clean up
|
|
114
|
-
await agentBay.delete(session);
|
|
115
40
|
}
|
|
116
|
-
```
|
|
117
41
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
### Session Management
|
|
121
|
-
|
|
122
|
-
- Create sessions with optional parameters (imageId, contextId, labels)
|
|
123
|
-
- List sessions with pagination and filtering by labels
|
|
124
|
-
- Delete sessions and clean up resources
|
|
125
|
-
- Manage session labels
|
|
126
|
-
- Get session information and links
|
|
127
|
-
|
|
128
|
-
### Command Execution
|
|
129
|
-
|
|
130
|
-
- Execute shell commands
|
|
131
|
-
- Run code in various languages
|
|
132
|
-
- Get command output and execution status
|
|
42
|
+
main().catch(console.error);
|
|
43
|
+
```
|
|
133
44
|
|
|
134
|
-
|
|
45
|
+
## 📖 Complete Documentation
|
|
135
46
|
|
|
136
|
-
|
|
137
|
-
-
|
|
138
|
-
-
|
|
139
|
-
-
|
|
47
|
+
### 🆕 New Users
|
|
48
|
+
- [📚 Quick Start Tutorial](https://github.com/aliyun/wuying-agentbay-sdk/tree/main/docs/quickstart) - Get started in 5 minutes
|
|
49
|
+
- [🎯 Core Concepts](https://github.com/aliyun/wuying-agentbay-sdk/tree/main/docs/quickstart/basic-concepts.md) - Understanding cloud environments and sessions
|
|
50
|
+
- [💡 Best Practices](https://github.com/aliyun/wuying-agentbay-sdk/tree/main/docs/quickstart/best-practices.md) - Common patterns and techniques
|
|
140
51
|
|
|
141
|
-
###
|
|
52
|
+
### 🚀 Experienced Users
|
|
53
|
+
- [📖 Feature Guides](https://github.com/aliyun/wuying-agentbay-sdk/tree/main/docs/guides) - Complete feature introduction
|
|
54
|
+
- [🔧 TypeScript API Reference](docs/api/) - Detailed API documentation
|
|
55
|
+
- [💻 TypeScript Examples](docs/examples/) - Complete example code
|
|
142
56
|
|
|
143
|
-
|
|
144
|
-
-
|
|
145
|
-
-
|
|
146
|
-
-
|
|
147
|
-
-
|
|
148
|
-
- Send key events
|
|
57
|
+
### 🆘 Need Help
|
|
58
|
+
- [❓ FAQ](https://github.com/aliyun/wuying-agentbay-sdk/tree/main/docs/quickstart/faq.md) - Quick answers
|
|
59
|
+
- [🔧 Troubleshooting](https://github.com/aliyun/wuying-agentbay-sdk/tree/main/docs/quickstart/troubleshooting.md) - Problem diagnosis
|
|
60
|
+
- [🔧 TypeScript API Reference](docs/api/README.md) - Local API documentation
|
|
61
|
+
- [💡 TypeScript Examples](docs/examples/README.md) - Local example code
|
|
149
62
|
|
|
150
|
-
|
|
63
|
+
## 🔧 Core Features Quick Reference
|
|
151
64
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
65
|
+
### Session Management
|
|
66
|
+
```typescript
|
|
67
|
+
// Create session
|
|
68
|
+
const session = (await agentBay.create()).session;
|
|
156
69
|
|
|
157
|
-
|
|
70
|
+
// List sessions
|
|
71
|
+
const sessions = await agentBay.list();
|
|
158
72
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
- Get window properties
|
|
73
|
+
// Connect to existing session
|
|
74
|
+
const session = await agentBay.connect("session_id");
|
|
75
|
+
```
|
|
163
76
|
|
|
164
|
-
###
|
|
77
|
+
### File Operations
|
|
78
|
+
```typescript
|
|
79
|
+
// Read and write files
|
|
80
|
+
await session.fileSystem.writeFile("/path/file.txt", "content");
|
|
81
|
+
const content = await session.fileSystem.readFile("/path/file.txt");
|
|
165
82
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
- Get context information
|
|
83
|
+
// List directory
|
|
84
|
+
const files = await session.fileSystem.listDirectory("/path");
|
|
85
|
+
```
|
|
170
86
|
|
|
171
|
-
###
|
|
87
|
+
### Command Execution
|
|
88
|
+
```typescript
|
|
89
|
+
// Execute command
|
|
90
|
+
const result = await session.command.executeCommand("node script.js");
|
|
91
|
+
console.log(result.output);
|
|
92
|
+
```
|
|
172
93
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
94
|
+
### Data Persistence
|
|
95
|
+
```typescript
|
|
96
|
+
// Create context
|
|
97
|
+
const context = (await agentBay.context.get("my-project", true)).context;
|
|
98
|
+
|
|
99
|
+
// Create session with context
|
|
100
|
+
import { ContextSync, SyncPolicy } from 'wuying-agentbay-sdk';
|
|
101
|
+
const contextSync = new ContextSync({
|
|
102
|
+
contextId: context.id,
|
|
103
|
+
path: "/mnt/data",
|
|
104
|
+
policy: SyncPolicy.default()
|
|
105
|
+
});
|
|
106
|
+
const session = (await agentBay.create({ contextSync: [contextSync] })).session;
|
|
107
|
+
```
|
|
176
108
|
|
|
177
|
-
##
|
|
109
|
+
## 🆘 Get Help
|
|
178
110
|
|
|
179
|
-
|
|
111
|
+
- [GitHub Issues](https://github.com/aliyun/wuying-agentbay-sdk/issues)
|
|
112
|
+
- [Complete Documentation](https://github.com/aliyun/wuying-agentbay-sdk/tree/main/docs)
|
|
180
113
|
|
|
181
|
-
|
|
182
|
-
- `success`: A boolean indicating whether the operation was successful
|
|
183
|
-
- Operation-specific data (varies by method)
|
|
114
|
+
## 📄 License
|
|
184
115
|
|
|
185
|
-
|
|
116
|
+
This project is licensed under the Apache License 2.0 - see the [LICENSE](../LICENSE) file for details.
|