wuying-agentbay-sdk 0.5.1 → 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 CHANGED
@@ -1,185 +1,116 @@
1
- # TypeScript SDK for Wuying AgentBay
1
+ # AgentBay SDK for TypeScript
2
2
 
3
- This directory contains the TypeScript implementation of the Wuying AgentBay SDK.
3
+ > Execute commands, manipulate files, and run code in cloud environments
4
4
 
5
- ## Prerequisites
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
- ## Development Scripts
29
-
30
- - **Build the project**:
31
- ```bash
32
- npm run build
33
- ```
11
+ ## 🚀 Prerequisites
34
12
 
35
- - **Run tests**:
36
- ```bash
37
- npm test
38
- ```
13
+ Before using the SDK, you need to:
39
14
 
40
- - **Lint the code**:
41
- ```bash
42
- npm run lint
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, ListSessionParams } from 'wuying-agentbay-sdk';
21
+ import { AgentBay } from 'wuying-agentbay-sdk';
68
22
 
69
23
  async function main() {
70
- // Initialize with API key
71
- const agentBay = new AgentBay({ apiKey: 'your_api_key' });
72
-
73
- // Create a session with optional parameters
74
- const createResponse = await agentBay.create({
75
- imageId: 'linux_latest', // Optional: specify the image to use
76
- contextId: 'your_context_id', // Optional: bind to an existing context
77
- labels: {
78
- purpose: 'demo',
79
- environment: 'development'
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
- ## Key Features
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
- ### File System Operations
45
+ ## 📖 Complete Documentation
135
46
 
136
- - Read and write files
137
- - List directory contents
138
- - Create and delete files and directories
139
- - Get file information
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
- ### UI Interaction
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
- - Take screenshots
144
- - Find UI elements by criteria
145
- - Click on UI elements
146
- - Send text input
147
- - Perform swipe gestures
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
- ### Application Management
63
+ ## 🔧 Core Features Quick Reference
151
64
 
152
- - Get installed applications
153
- - List running applications
154
- - Start and stop applications
155
- - Get application information
65
+ ### Session Management
66
+ ```typescript
67
+ // Create session
68
+ const session = (await agentBay.create()).session;
156
69
 
157
- ### Window Management
70
+ // List sessions
71
+ const sessions = await agentBay.list();
158
72
 
159
- - List windows
160
- - Get active window
161
- - Focus, resize, and move windows
162
- - Get window properties
73
+ // Connect to existing session
74
+ const session = await agentBay.connect("session_id");
75
+ ```
163
76
 
164
- ### Context Management
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
- - Create, list, and delete contexts
167
- - Bind sessions to contexts
168
- - Synchronize context data
169
- - Get context information
83
+ // List directory
84
+ const files = await session.fileSystem.listDirectory("/path");
85
+ ```
170
86
 
171
- ### OSS Integration
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
- - Upload files to OSS
174
- - Download files from OSS
175
- - Initialize OSS environment
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
- ## Response Format
109
+ ## 🆘 Get Help
178
110
 
179
- All API methods return responses that include:
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
- - `requestId`: A unique identifier for the request
182
- - `success`: A boolean indicating whether the operation was successful
183
- - Operation-specific data (varies by method)
114
+ ## 📄 License
184
115
 
185
- For more detailed documentation, refer to the [SDK Documentation](../docs/README.md).
116
+ This project is licensed under the Apache License 2.0 - see the [LICENSE](../LICENSE) file for details.