wuying-agentbay-sdk 0.12.0 → 0.13.0
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/{chunk-BVWUCG4J.mjs → chunk-P2CXYF4T.mjs} +400 -163
- package/dist/chunk-P2CXYF4T.mjs.map +1 -0
- package/dist/{chunk-SL5GCAQE.cjs → chunk-WVWGLZDT.cjs} +337 -100
- package/dist/chunk-WVWGLZDT.cjs.map +1 -0
- package/dist/index.cjs +6789 -752
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +637 -165
- package/dist/index.d.ts +637 -165
- package/dist/index.mjs +6654 -617
- package/dist/index.mjs.map +1 -1
- package/dist/{model-LGWQJWKQ.mjs → model-BRLR6F3P.mjs} +16 -2
- package/dist/model-KJHN3WYY.cjs +214 -0
- package/dist/{model-CNCGFWJH.cjs.map → model-KJHN3WYY.cjs.map} +1 -1
- package/docs/api/README.md +6 -0
- package/docs/api/browser-use/browser-agent.md +188 -0
- package/docs/api/browser-use/browser.md +1 -1
- package/docs/api/browser-use/fingerprint.md +154 -0
- package/docs/api/codespace/code.md +3 -0
- package/docs/api/common-features/advanced/agent.md +7 -63
- package/docs/api/common-features/advanced/browser-use-agent.md +118 -0
- package/docs/api/common-features/advanced/computer-use-agent.md +85 -0
- package/docs/api/common-features/basics/agentbay.md +3 -2
- package/docs/api/common-features/basics/command.md +35 -18
- package/docs/api/common-features/basics/filesystem.md +36 -0
- package/docs/api/common-features/basics/session-params.md +382 -0
- package/docs/api/common-features/basics/session.md +0 -2
- package/docs/api/computer-use/computer.md +25 -25
- package/docs/api/mobile-use/mobile-simulate.md +135 -0
- package/docs/examples/browser-use/browser/basic-usage.ts +31 -24
- package/docs/examples/browser-use/browser/browser-type-example.ts +3 -4
- package/docs/examples/browser-use/browser/captcha_tongcheng.ts +60 -28
- package/docs/examples/browser-use/browser/run-2048.ts +47 -37
- package/docs/examples/browser-use/browser/run-sudoku.ts +55 -36
- package/docs/examples/browser-use/browser/screenshot-example.ts +6 -6
- package/docs/examples/browser-use/extension-example/extension-example.ts +1 -2
- package/docs/examples/codespace/enhanced_code/index.ts +86 -0
- package/docs/examples/common-features/advanced/agent-module-example.ts +1 -1
- package/docs/examples/common-features/advanced/archive-upload-mode-example/README.md +1 -1
- package/docs/examples/common-features/advanced/archive-upload-mode-example/archive-upload-mode-example.ts +5 -6
- package/docs/examples/common-features/basics/archive-upload-mode-example/README.md +1 -1
- package/docs/examples/common-features/basics/archive-upload-mode-example/main.ts +1 -1
- package/docs/examples/common-features/basics/filesystem-example/filesystem-example.ts +13 -0
- package/docs/examples/common-features/basics/filesystem-example/filesystem-filetransfer-example.ts +6 -7
- package/docs/examples/common-features/basics/filesystem-example/watch-directory-example.ts +1 -1
- package/docs/examples/mobile-use/mobile-get-adb-url/index.ts +1 -1
- package/package.json +4 -4
- package/dist/chunk-BVWUCG4J.mjs.map +0 -1
- package/dist/chunk-SL5GCAQE.cjs.map +0 -1
- package/dist/model-CNCGFWJH.cjs +0 -200
- package/docs/examples/mobile-use/mobile-get-adb-url/package-lock.json +0 -279
- package/docs/examples/mobile-use/mobile-get-adb-url/package.json +0 -18
- /package/dist/{model-LGWQJWKQ.mjs.map → model-BRLR6F3P.mjs.map} +0 -0
|
@@ -6,20 +6,28 @@
|
|
|
6
6
|
* - Utilize PageUseAgent to run sudoku game
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
9
|
+
import {
|
|
10
|
+
AgentBay,
|
|
11
|
+
CreateSessionParams,
|
|
12
|
+
BrowserOption,
|
|
13
|
+
ExtractOptions,
|
|
14
|
+
ActOptions,
|
|
15
|
+
} from "wuying-agentbay-sdk";
|
|
16
|
+
|
|
17
|
+
import { chromium } from "playwright";
|
|
18
|
+
import { z } from "zod";
|
|
19
|
+
|
|
20
|
+
const SudokuBoardSchema = z.object({
|
|
21
|
+
board: z.array(z.array(z.number())),
|
|
22
|
+
});
|
|
23
|
+
type SudokuBoardType = z.infer<typeof SudokuBoardSchema>;
|
|
24
|
+
|
|
25
|
+
const SudokuSolutionSchema = z.object({
|
|
26
|
+
solution: z.array(z.array(z.number())),
|
|
27
|
+
});
|
|
28
|
+
type SudokuSolutionType = z.infer<typeof SudokuSolutionSchema>;
|
|
21
29
|
function formatBoardForLlm(board: number[][]): string {
|
|
22
|
-
return board.map(row => ` [${row.join(
|
|
30
|
+
return board.map((row) => ` [${row.join(", ")}]`).join("\n");
|
|
23
31
|
}
|
|
24
32
|
|
|
25
33
|
async function main() {
|
|
@@ -52,7 +60,7 @@ async function main() {
|
|
|
52
60
|
|
|
53
61
|
const browser = await chromium.connectOverCDP(endpointUrl);
|
|
54
62
|
try {
|
|
55
|
-
const context = browser.contexts()[0]
|
|
63
|
+
const context = browser.contexts()[0];
|
|
56
64
|
const page = await context.newPage();
|
|
57
65
|
console.log("🌐 Navigating to Sudoku site...");
|
|
58
66
|
const url = "https://widget.websudoku.com/";
|
|
@@ -65,27 +73,31 @@ async function main() {
|
|
|
65
73
|
|
|
66
74
|
while (!success) {
|
|
67
75
|
console.log("📊 Extracting sudoku board...");
|
|
68
|
-
const options: ExtractOptions<
|
|
69
|
-
instruction:
|
|
70
|
-
|
|
71
|
-
|
|
76
|
+
const options: ExtractOptions<typeof SudokuBoardSchema> = {
|
|
77
|
+
instruction:
|
|
78
|
+
"Extract the current sudoku board as a 9x9 array. Each cell should be a number (1-9) if filled, or 0 if empty.",
|
|
79
|
+
schema: SudokuBoardSchema,
|
|
80
|
+
use_text_extract: false,
|
|
72
81
|
};
|
|
73
82
|
|
|
74
|
-
const [extractSuccess,
|
|
75
|
-
|
|
83
|
+
const [extractSuccess, boardObj] =
|
|
84
|
+
await session.browser.agent.extract(options, page);
|
|
85
|
+
if (extractSuccess && boardObj) {
|
|
76
86
|
success = true;
|
|
77
|
-
board =
|
|
87
|
+
board = boardObj.board;
|
|
78
88
|
} else {
|
|
79
89
|
console.log("❌ Failed to extract sudoku board, retry extracting");
|
|
80
|
-
await new Promise(resolve => setTimeout(resolve, 3000));
|
|
90
|
+
await new Promise((resolve) => setTimeout(resolve, 3000));
|
|
81
91
|
}
|
|
82
92
|
}
|
|
83
93
|
|
|
84
|
-
console.log(
|
|
85
|
-
|
|
94
|
+
console.log(
|
|
95
|
+
"Current Board:\n" + board.map((row) => row.join(" ")).join("\n")
|
|
96
|
+
);
|
|
97
|
+
const originalBoard = board.map((row) => [...row]);
|
|
86
98
|
|
|
87
99
|
// 2. Solve the sudoku
|
|
88
|
-
const solutionOptions: ExtractOptions<
|
|
100
|
+
const solutionOptions: ExtractOptions<typeof SudokuSolutionSchema> = {
|
|
89
101
|
instruction: `You are an expert sudoku solver. Given the following sudoku board as a 9x9 array (0 means empty), solve the sudoku and return the completed 9x9 array as 'solution'.
|
|
90
102
|
|
|
91
103
|
Sudoku rules:
|
|
@@ -103,39 +115,46 @@ Return:
|
|
|
103
115
|
{
|
|
104
116
|
solution: number[][] // 9x9, all filled, valid sudoku
|
|
105
117
|
}`,
|
|
106
|
-
schema:
|
|
107
|
-
use_text_extract: false
|
|
118
|
+
schema: SudokuSolutionSchema,
|
|
119
|
+
use_text_extract: false,
|
|
108
120
|
};
|
|
109
121
|
|
|
110
|
-
const [solutionSuccess,
|
|
111
|
-
|
|
122
|
+
const [solutionSuccess, solutionObj] =
|
|
123
|
+
await session.browser.agent.extract(solutionOptions, page);
|
|
124
|
+
if (!solutionSuccess || !solutionObj) {
|
|
112
125
|
console.log("❌ Failed to solve sudoku");
|
|
113
126
|
return;
|
|
114
127
|
}
|
|
115
128
|
|
|
116
|
-
const solution =
|
|
117
|
-
console.log(
|
|
129
|
+
const solution = solutionObj.solution;
|
|
130
|
+
console.log(
|
|
131
|
+
"Solved Board:\n" +
|
|
132
|
+
solution.map((row: any) => row.join(" ")).join("\n")
|
|
133
|
+
);
|
|
118
134
|
|
|
119
135
|
// 3. Fill the solution
|
|
120
136
|
for (let row = 0; row < 9; row++) {
|
|
121
137
|
for (let col = 0; col < 9; col++) {
|
|
122
138
|
if (originalBoard[row][col] === 0) {
|
|
123
139
|
const inputId = `f${col}${row}`;
|
|
124
|
-
console.log(
|
|
140
|
+
console.log(
|
|
141
|
+
`Type '${solution[row][col]}' into the cell with id '${inputId}'`
|
|
142
|
+
);
|
|
125
143
|
|
|
126
144
|
// Use the act method for natural language action
|
|
127
145
|
const actOptions: ActOptions = {
|
|
128
|
-
action: `Enter '${solution[row][col]}' into the input element where the attribute id is exactly '${inputId}' (for example, if id='f53', you must match the full string 'f53', not just the number 53; do not split or extract numbers from the id)
|
|
146
|
+
action: `Enter '${solution[row][col]}' into the input element where the attribute id is exactly '${inputId}' (for example, if id='f53', you must match the full string 'f53', not just the number 53; do not split or extract numbers from the id)`,
|
|
129
147
|
};
|
|
130
148
|
|
|
131
149
|
await session.browser.agent.act(actOptions, page);
|
|
132
|
-
await new Promise(resolve => setTimeout(resolve, 500));
|
|
150
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
133
151
|
}
|
|
134
152
|
}
|
|
135
153
|
}
|
|
136
154
|
|
|
137
|
-
console.log(
|
|
138
|
-
|
|
155
|
+
console.log(
|
|
156
|
+
"✅ Finished! The board has been solved and filled in the browser."
|
|
157
|
+
);
|
|
139
158
|
} catch (error) {
|
|
140
159
|
console.log(`❌ Error in game loop: ${error}`);
|
|
141
160
|
}
|
|
@@ -75,8 +75,8 @@ async function main() {
|
|
|
75
75
|
// console.log(`✅ Browser screenshot captured (${screenshotData.length} bytes)`);
|
|
76
76
|
|
|
77
77
|
// Save the screenshot to a file
|
|
78
|
-
// await writeFile("
|
|
79
|
-
|
|
78
|
+
// await writeFile("temp_browser_screenshot.png", Buffer.from(screenshotData));
|
|
79
|
+
// console.log("✅ Browser screenshot saved as temp_browser_screenshot.png");
|
|
80
80
|
|
|
81
81
|
// Take a full page screenshot with custom options
|
|
82
82
|
// const fullPageData = await session.browser.screenshot(
|
|
@@ -90,8 +90,8 @@ async function main() {
|
|
|
90
90
|
// console.log(`✅ Browser full page screenshot captured (${fullPageData.length} bytes)`);
|
|
91
91
|
|
|
92
92
|
// Save the full page screenshot
|
|
93
|
-
// await writeFile("
|
|
94
|
-
|
|
93
|
+
// await writeFile("temp_browser_full_page_screenshot.jpg", Buffer.from(fullPageData));
|
|
94
|
+
// console.log("✅ Browser full page screenshot saved as temp_browser_full_page_screenshot.jpg");
|
|
95
95
|
|
|
96
96
|
// Take a screenshot with custom viewport settings
|
|
97
97
|
// const customScreenshot = await session.browser.screenshot(
|
|
@@ -105,8 +105,8 @@ async function main() {
|
|
|
105
105
|
// console.log(`✅ Browser custom screenshot captured (${customScreenshot.length} bytes)`);
|
|
106
106
|
|
|
107
107
|
// Save the custom screenshot
|
|
108
|
-
// await writeFile("
|
|
109
|
-
|
|
108
|
+
// await writeFile("temp_browser_custom_screenshot.png", Buffer.from(customScreenshot));
|
|
109
|
+
// console.log("✅ Browser custom screenshot saved as temp_browser_custom_screenshot.png");
|
|
110
110
|
|
|
111
111
|
await browser.close();
|
|
112
112
|
|
|
@@ -12,7 +12,6 @@
|
|
|
12
12
|
* - Error handling and cleanup
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
// @ts-nocheck
|
|
16
15
|
import { AgentBay, ExtensionsService, Extension, ExtensionOption, BrowserContext } from "wuying-agentbay-sdk";
|
|
17
16
|
import * as fs from "fs";
|
|
18
17
|
|
|
@@ -33,7 +32,7 @@ async function basicExtensionExample(): Promise<boolean> {
|
|
|
33
32
|
|
|
34
33
|
try {
|
|
35
34
|
// Example extension path (update with your actual extension)
|
|
36
|
-
const extensionPath = "/
|
|
35
|
+
const extensionPath = "/path/to/your-extension.zip";
|
|
37
36
|
|
|
38
37
|
if (!fs.existsSync(extensionPath)) {
|
|
39
38
|
console.log(`❌ Extension file not found: ${extensionPath}`);
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { AgentBay } from 'wuying-agentbay-sdk';
|
|
2
|
+
|
|
3
|
+
async function main() {
|
|
4
|
+
const apiKey = process.env.AGENTBAY_API_KEY;
|
|
5
|
+
if (!apiKey) {
|
|
6
|
+
console.error("Please set AGENTBAY_API_KEY environment variable");
|
|
7
|
+
process.exit(1);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const agentBay = new AgentBay({ apiKey });
|
|
11
|
+
|
|
12
|
+
console.log("Creating session...");
|
|
13
|
+
const sessionResult = await agentBay.create({ imageId: "code_latest" });
|
|
14
|
+
if (!sessionResult.success || !sessionResult.session) {
|
|
15
|
+
console.error("Failed to create session:", sessionResult.errorMessage);
|
|
16
|
+
process.exit(1);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const session = sessionResult.session;
|
|
20
|
+
console.log(`Session created: ${session.sessionId}`);
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
// 1. Logs Capture
|
|
24
|
+
console.log("\n--- Logs Capture Test ---");
|
|
25
|
+
const logsCode = `
|
|
26
|
+
import sys
|
|
27
|
+
print("This goes to stdout")
|
|
28
|
+
print("This goes to stderr", file=sys.stderr)
|
|
29
|
+
`;
|
|
30
|
+
const logsResult = await session.code.runCode(logsCode, "python");
|
|
31
|
+
printResult(logsResult);
|
|
32
|
+
|
|
33
|
+
// 2. Rich Output (HTML)
|
|
34
|
+
console.log("\n--- Rich Output (HTML) Test ---");
|
|
35
|
+
const htmlCode = `
|
|
36
|
+
from IPython.display import display, HTML
|
|
37
|
+
display(HTML("<h1>Hello from AgentBay</h1>"))
|
|
38
|
+
`;
|
|
39
|
+
const htmlResult = await session.code.runCode(htmlCode, "python");
|
|
40
|
+
printResult(htmlResult);
|
|
41
|
+
|
|
42
|
+
// 3. Error Handling
|
|
43
|
+
console.log("\n--- Error Handling Test ---");
|
|
44
|
+
const errorCode = `
|
|
45
|
+
raise ValueError("Something went wrong")
|
|
46
|
+
`;
|
|
47
|
+
const errorResult = await session.code.runCode(errorCode, "python");
|
|
48
|
+
printResult(errorResult);
|
|
49
|
+
|
|
50
|
+
} finally {
|
|
51
|
+
console.log("\nCleaning up...");
|
|
52
|
+
await session.delete();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function printResult(result: any) {
|
|
57
|
+
if (result.success) {
|
|
58
|
+
console.log("Success: true");
|
|
59
|
+
if (result.logs) {
|
|
60
|
+
if (result.logs.stdout.length > 0) {
|
|
61
|
+
console.log("Stdout:", JSON.stringify(result.logs.stdout));
|
|
62
|
+
}
|
|
63
|
+
if (result.logs.stderr.length > 0) {
|
|
64
|
+
console.log("Stderr:", JSON.stringify(result.logs.stderr));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (result.results) {
|
|
68
|
+
console.log("Results count:", result.results.length);
|
|
69
|
+
result.results.forEach((item: any, index: number) => {
|
|
70
|
+
const types = Object.keys(item).filter(k => k !== 'isMainResult');
|
|
71
|
+
console.log(`Result [${index}] types:`, types.join(", "));
|
|
72
|
+
if (item.text) console.log(` Text: ${item.text.substring(0, 50)}...`);
|
|
73
|
+
if (item.html) console.log(` HTML: ${item.html.substring(0, 50)}...`);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
} else {
|
|
77
|
+
console.log("Success: false");
|
|
78
|
+
console.log("Error Message:", result.errorMessage);
|
|
79
|
+
if (result.error) {
|
|
80
|
+
console.log("Error Details:", JSON.stringify(result.error));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
main().catch(console.error);
|
|
86
|
+
|
|
@@ -33,7 +33,7 @@ async function main() {
|
|
|
33
33
|
const taskDescription = "Calculate the square root of 144";
|
|
34
34
|
console.log(`Executing task: ${taskDescription}`);
|
|
35
35
|
|
|
36
|
-
const executionResult = await session.agent.executeTask(taskDescription, 5);
|
|
36
|
+
const executionResult = await session.agent.computer.executeTask(taskDescription, 5);
|
|
37
37
|
|
|
38
38
|
if (executionResult.success) {
|
|
39
39
|
console.log("Task completed successfully!");
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AgentBay, CreateSessionParams, Session, newContextSync, newSyncPolicy, FileSystem } from "wuying-agentbay-sdk";
|
|
1
|
+
import { AgentBay, CreateSessionParams, Session, newContextSync, newSyncPolicy, FileSystem, UploadMode } from "wuying-agentbay-sdk";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Archive Upload Mode Context Sync Example
|
|
@@ -57,10 +57,9 @@ async function archiveUploadModeExample(): Promise<void> {
|
|
|
57
57
|
// Step 2: Configure sync policy with Archive upload mode
|
|
58
58
|
console.log("\n⚙️ Step 2: Configuring sync policy with Archive upload mode...");
|
|
59
59
|
const syncPolicy = newSyncPolicy();
|
|
60
|
-
syncPolicy.uploadPolicy!.uploadMode =
|
|
61
|
-
|
|
62
|
-
console.log(`✅ Sync policy configured with uploadMode: ${syncPolicy.uploadPolicy!.uploadMode}`);
|
|
60
|
+
syncPolicy.uploadPolicy!.uploadMode = UploadMode.Archive;
|
|
63
61
|
|
|
62
|
+
console.log(`✅ Sync policy configured with uploadMode: ${syncPolicy.uploadPolicy!.uploadMode}`);
|
|
64
63
|
// Step 3: Create context sync configuration
|
|
65
64
|
console.log("\n🔧 Step 3: Creating context sync configuration...");
|
|
66
65
|
const contextSync = newContextSync(
|
|
@@ -76,7 +75,7 @@ async function archiveUploadModeExample(): Promise<void> {
|
|
|
76
75
|
|
|
77
76
|
// Step 4: Create session with Archive mode context sync
|
|
78
77
|
console.log("\n🏗️ Step 4: Creating session with Archive mode context sync...");
|
|
79
|
-
const sessionParams
|
|
78
|
+
const sessionParams = {
|
|
80
79
|
labels: {
|
|
81
80
|
example: `archive-mode-${uniqueId}`,
|
|
82
81
|
type: "archive-upload-demo",
|
|
@@ -173,7 +172,7 @@ async function archiveUploadModeExample(): Promise<void> {
|
|
|
173
172
|
console.log("\n🎉 Archive upload mode example completed successfully!");
|
|
174
173
|
console.log("✅ All operations completed without errors.");
|
|
175
174
|
|
|
176
|
-
|
|
175
|
+
} catch (error) {
|
|
177
176
|
console.error("\n❌ Error occurred during example execution:");
|
|
178
177
|
console.error(error);
|
|
179
178
|
} finally {
|
|
@@ -76,7 +76,7 @@ async function archiveUploadModeExample(): Promise<void> {
|
|
|
76
76
|
|
|
77
77
|
// Step 4: Create session with Archive mode context sync
|
|
78
78
|
console.log("\n🏗️ Step 4: Creating session with Archive mode context sync...");
|
|
79
|
-
const sessionParams
|
|
79
|
+
const sessionParams = {
|
|
80
80
|
labels: {
|
|
81
81
|
example: `archive-mode-${uniqueId}`,
|
|
82
82
|
type: "archive-upload-demo",
|
|
@@ -145,6 +145,19 @@ async function main() {
|
|
|
145
145
|
} catch (error) {
|
|
146
146
|
log(`Error moving file: ${error}`);
|
|
147
147
|
}
|
|
148
|
+
|
|
149
|
+
// 9. Delete file
|
|
150
|
+
log(`\nDeleting file: ${newFilePath}`);
|
|
151
|
+
try {
|
|
152
|
+
const deleteResponse = await session.fileSystem.deleteFile(newFilePath);
|
|
153
|
+
log(`File deleted successfully: ${deleteResponse.success}`);
|
|
154
|
+
log(`Delete File RequestId: ${deleteResponse.requestId}`);
|
|
155
|
+
|
|
156
|
+
const infoAfterDelete = await session.fileSystem.getFileInfo(newFilePath);
|
|
157
|
+
log(`Get File Info After Delete: success=${infoAfterDelete.success}`);
|
|
158
|
+
} catch (error) {
|
|
159
|
+
log(`Error deleting file: ${error}`);
|
|
160
|
+
}
|
|
148
161
|
} finally {
|
|
149
162
|
// Clean up by deleting the session when we're done
|
|
150
163
|
log('\nDeleting the session...');
|
package/docs/examples/common-features/basics/filesystem-example/filesystem-filetransfer-example.ts
CHANGED
|
@@ -30,7 +30,7 @@ async function main() {
|
|
|
30
30
|
const createResponse = await agentBay.create({
|
|
31
31
|
imageId: 'code_latest'
|
|
32
32
|
});
|
|
33
|
-
|
|
33
|
+
|
|
34
34
|
if (!createResponse.success || !createResponse.session) {
|
|
35
35
|
log(`Failed to create session: ${createResponse.errorMessage}`);
|
|
36
36
|
return;
|
|
@@ -39,13 +39,12 @@ async function main() {
|
|
|
39
39
|
const session = createResponse.session;
|
|
40
40
|
log(`\nSession created with ID: ${session.sessionId}`);
|
|
41
41
|
log(`Create Session RequestId: ${createResponse.requestId}`);
|
|
42
|
-
log(`Session fileTransferContextId: ${session.fileTransferContextId}`);
|
|
43
42
|
|
|
44
43
|
try {
|
|
45
44
|
// 1. Upload a file
|
|
46
45
|
const remotePath = '/tmp/file_transfer_test/uploaded-file.txt';
|
|
47
46
|
log(`\nUploading file from ${localUploadPath} to ${remotePath}`);
|
|
48
|
-
|
|
47
|
+
|
|
49
48
|
// Create the remote directory first
|
|
50
49
|
const dirPath = path.dirname(remotePath);
|
|
51
50
|
const createDirResult = await session.fileSystem.createDirectory(dirPath);
|
|
@@ -69,7 +68,7 @@ async function main() {
|
|
|
69
68
|
log(`Bytes sent: ${uploadResult.bytesSent}`);
|
|
70
69
|
log(`Request ID (upload URL): ${uploadResult.requestIdUploadUrl}`);
|
|
71
70
|
log(`Request ID (sync): ${uploadResult.requestIdSync}`);
|
|
72
|
-
|
|
71
|
+
|
|
73
72
|
// Verify the file exists in remote location
|
|
74
73
|
const listResult = await session.fileSystem.listDirectory(dirPath);
|
|
75
74
|
if (listResult.success) {
|
|
@@ -87,7 +86,7 @@ async function main() {
|
|
|
87
86
|
// 2. Create a file in the remote location for download
|
|
88
87
|
const remoteDownloadPath = '/tmp/file_transfer_test/download-test.txt';
|
|
89
88
|
const downloadContent = "This is a test file for AgentBay FileTransfer download functionality.\n".repeat(15);
|
|
90
|
-
|
|
89
|
+
|
|
91
90
|
log(`\nCreating remote file for download: ${remoteDownloadPath}`);
|
|
92
91
|
const writeResult = await session.fileSystem.writeFile(remoteDownloadPath, downloadContent);
|
|
93
92
|
if (writeResult.success) {
|
|
@@ -99,7 +98,7 @@ async function main() {
|
|
|
99
98
|
// 3. Download the file
|
|
100
99
|
const localDownloadPath = path.join(tempDir, 'downloaded-file.txt');
|
|
101
100
|
log(`\nDownloading file from ${remoteDownloadPath} to ${localDownloadPath}`);
|
|
102
|
-
|
|
101
|
+
|
|
103
102
|
const downloadResult = await session.fileSystem.downloadFile(
|
|
104
103
|
remoteDownloadPath,
|
|
105
104
|
localDownloadPath,
|
|
@@ -115,7 +114,7 @@ async function main() {
|
|
|
115
114
|
log(`Bytes received: ${downloadResult.bytesReceived}`);
|
|
116
115
|
log(`Request ID (download URL): ${downloadResult.requestIdDownloadUrl}`);
|
|
117
116
|
log(`Request ID (sync): ${downloadResult.requestIdSync}`);
|
|
118
|
-
|
|
117
|
+
|
|
119
118
|
// Verify downloaded file content
|
|
120
119
|
const downloadedContent = fs.readFileSync(localDownloadPath, 'utf-8');
|
|
121
120
|
if (downloadedContent === downloadContent) {
|
|
@@ -25,7 +25,7 @@ async function main(): Promise<void> {
|
|
|
25
25
|
console.log("✅ AgentBay client initialized");
|
|
26
26
|
|
|
27
27
|
// Create session with code_latest ImageId
|
|
28
|
-
const sessionParams
|
|
28
|
+
const sessionParams = { imageId: "code_latest" };
|
|
29
29
|
const sessionResult = await agentbay.create(sessionParams);
|
|
30
30
|
|
|
31
31
|
if (!sessionResult.success) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wuying-agentbay-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "TypeScript SDK for interacting with the Wuying AgentBay cloud runtime environment",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -64,11 +64,11 @@
|
|
|
64
64
|
"prettier": "^2.8.4",
|
|
65
65
|
"sinon": "^15.2.0",
|
|
66
66
|
"ts-jest": "^26.5.6",
|
|
67
|
-
"ts-node": "^10.9.2",
|
|
68
67
|
"tsup": "^8.5.0",
|
|
69
|
-
"typedoc": "^0.25.0",
|
|
70
68
|
"typedoc-plugin-markdown": "^3.16.0",
|
|
71
|
-
"typescript": "4.9.5"
|
|
69
|
+
"typescript": "^4.9.5",
|
|
70
|
+
"zod": "^3.25.76",
|
|
71
|
+
"zod-to-json-schema": "^3.22.4"
|
|
72
72
|
},
|
|
73
73
|
"dependencies": {
|
|
74
74
|
"@alicloud/openapi-core": "^1.0.4",
|