wuying-agentbay-sdk 0.3.0 → 0.3.6

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
@@ -44,99 +44,142 @@ npm install wuying-agentbay-sdk
44
44
 
45
45
  ## Examples
46
46
 
47
- The SDK includes several examples demonstrating various features:
47
+ You can find examples in the `docs/examples/typescript` directory, including:
48
48
 
49
- - **basic-usage.ts**: Basic SDK usage
50
- - **session-creation/**: Session creation and management
51
- - **session-params/**: Using session parameters and labels
52
- - **context-management/**: Context creation and management
53
- - **application-window/**: Application and window management
54
- - **command-example/**: Command execution and code running
55
- - **filesystem-example/**: File system operations
56
- - **ui-example/**: UI interactions
57
- - **label-management/**: Session label management
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
58
57
 
59
- ## Running Examples
60
-
61
- You can run the example file using ts-node:
58
+ To run the examples:
62
59
 
63
60
  ```bash
64
- npx ts-node examples/basic-usage.ts
61
+ npx ts-node docs/examples/typescript/basic-usage.ts
65
62
  ```
66
63
 
67
64
  ## TypeScript-Specific Usage
68
65
 
69
66
  ```typescript
70
- import { AgentBay } from 'wuying-agentbay-sdk';
67
+ import { AgentBay, ListSessionParams } from 'wuying-agentbay-sdk';
71
68
 
72
69
  async function main() {
73
70
  // Initialize with API key
74
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'
80
+ }
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();
75
104
 
76
- try {
77
- // Create a session with labels
78
- const session = await agentBay.create({
79
- labels: {
80
- purpose: 'demo',
81
- environment: 'development'
82
- }
83
- });
84
- log(`Session created with ID: ${session.sessionId}`);
85
-
86
- // Execute a command
87
- const result = await session.command.executeCommand('ls -la');
88
- log(`Command result: ${result}`);
89
-
90
- // Read a file
91
- const content = await session.filesystem.readFile('/path/to/file.txt');
92
- log(`File content: ${content}`);
93
-
94
- // Run code
95
- const pythonCode = `
96
- import os
97
- import platform
98
-
99
- print(f"Current working directory: {os.getcwd()}")
100
- print(f"Python version: {platform.python_version()}")
101
- `;
102
- const codeResult = await session.command.runCode(pythonCode, 'python');
103
- log(`Code execution result: ${codeResult}`);
104
-
105
- // Get installed applications
106
- const apps = await session.application.getInstalledApps(true, false, true);
107
- log(`Found ${apps.length} installed applications`);
108
-
109
- // List visible applications
110
- const processes = await session.application.listVisibleApps();
111
- log(`Found ${processes.length} visible applications`);
112
-
113
- // List root windows
114
- const windows = await session.window.listRootWindows();
115
- log(`Found ${windows.length} root windows`);
116
-
117
- // Get active window
118
- const activeWindow = await session.window.getActiveWindow();
119
- log(`Active window: ${activeWindow.title}`);
120
-
121
- // Get session labels
122
- const labels = await session.getLabels();
123
- log(`Session labels: ${JSON.stringify(labels)}`);
124
-
125
- // List sessions by labels
126
- const filteredSessions = await agentBay.listByLabels({
127
- purpose: 'demo'
128
- });
129
- log(`Found ${filteredSessions.length} matching sessions`);
130
-
131
- // Clean up
132
- await agentBay.delete(session);
133
- log('Session deleted successfully');
134
- } catch (error) {
135
- logError('Error:', error);
136
- }
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);
137
115
  }
138
-
139
- main();
140
116
  ```
141
117
 
142
- For more detailed documentation, please refer to the main [README](../README.md) and [SDK Documentation](../docs/README.md) in the project root.
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
133
+
134
+ ### File System Operations
135
+
136
+ - Read and write files
137
+ - List directory contents
138
+ - Create and delete files and directories
139
+ - Get file information
140
+
141
+ ### UI Interaction
142
+
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
149
+
150
+ ### Application Management
151
+
152
+ - Get installed applications
153
+ - List running applications
154
+ - Start and stop applications
155
+ - Get application information
156
+
157
+ ### Window Management
158
+
159
+ - List windows
160
+ - Get active window
161
+ - Focus, resize, and move windows
162
+ - Get window properties
163
+
164
+ ### Context Management
165
+
166
+ - Create, list, and delete contexts
167
+ - Bind sessions to contexts
168
+ - Synchronize context data
169
+ - Get context information
170
+
171
+ ### OSS Integration
172
+
173
+ - Upload files to OSS
174
+ - Download files from OSS
175
+ - Initialize OSS environment
176
+
177
+ ## Response Format
178
+
179
+ All API methods return responses that include:
180
+
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)
184
+
185
+ For more detailed documentation, refer to the [SDK Documentation](../docs/README.md).