test-wuying-agentbay-sdk 0.13.0-beta.20251209195417 → 0.13.0-beta.20251209211023
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.cjs +125 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +47 -16
- package/dist/index.d.ts +47 -16
- package/dist/index.mjs +125 -21
- package/dist/index.mjs.map +1 -1
- package/docs/api/common-features/basics/command.md +34 -17
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -5471,14 +5471,28 @@ var _Command = class _Command {
|
|
|
5471
5471
|
return errorString.replace(/Bearer\s+[^\s]+/g, "Bearer [REDACTED]");
|
|
5472
5472
|
}
|
|
5473
5473
|
/**
|
|
5474
|
-
*
|
|
5474
|
+
* Execute a shell command with optional working directory and environment variables.
|
|
5475
5475
|
*
|
|
5476
|
-
*
|
|
5477
|
-
*
|
|
5476
|
+
* Executes a shell command in the session environment with configurable timeout,
|
|
5477
|
+
* working directory, and environment variables. The command runs with session
|
|
5478
|
+
* user permissions in a Linux shell environment.
|
|
5479
|
+
*
|
|
5480
|
+
* @param command - The shell command to execute
|
|
5481
|
+
* @param timeoutMs - Timeout in milliseconds (default: 1000ms/1s). Maximum allowed
|
|
5482
|
+
* timeout is 50000ms (50s). If a larger value is provided,
|
|
5483
|
+
* it will be automatically limited to 50000ms
|
|
5484
|
+
* @param cwd - The working directory for command execution. If not specified,
|
|
5485
|
+
* the command runs in the default session directory
|
|
5486
|
+
* @param envs - Environment variables as a dictionary of key-value pairs.
|
|
5487
|
+
* These variables are set for the command execution only
|
|
5478
5488
|
*
|
|
5479
5489
|
* @returns Promise resolving to CommandResult containing:
|
|
5480
|
-
* - success: Whether the command executed successfully
|
|
5481
|
-
* - output:
|
|
5490
|
+
* - success: Whether the command executed successfully (exitCode === 0)
|
|
5491
|
+
* - output: Command output for backward compatibility (stdout + stderr)
|
|
5492
|
+
* - exitCode: The exit code of the command execution (0 for success)
|
|
5493
|
+
* - stdout: Standard output from the command execution
|
|
5494
|
+
* - stderr: Standard error from the command execution
|
|
5495
|
+
* - traceId: Trace ID for error tracking (only present when exitCode !== 0)
|
|
5482
5496
|
* - requestId: Unique identifier for this API request
|
|
5483
5497
|
* - errorMessage: Error description if execution failed
|
|
5484
5498
|
*
|
|
@@ -5487,34 +5501,124 @@ var _Command = class _Command {
|
|
|
5487
5501
|
* const agentBay = new AgentBay({ apiKey: 'your_api_key' });
|
|
5488
5502
|
* const result = await agentBay.create();
|
|
5489
5503
|
* if (result.success) {
|
|
5490
|
-
* const cmdResult = await result.session.command.executeCommand('echo "Hello"',
|
|
5504
|
+
* const cmdResult = await result.session.command.executeCommand('echo "Hello"', 5000);
|
|
5491
5505
|
* console.log('Command output:', cmdResult.output);
|
|
5506
|
+
* console.log('Exit code:', cmdResult.exitCode);
|
|
5507
|
+
* console.log('Stdout:', cmdResult.stdout);
|
|
5492
5508
|
* await result.session.delete();
|
|
5493
5509
|
* }
|
|
5494
5510
|
* ```
|
|
5495
5511
|
*
|
|
5496
|
-
* @
|
|
5497
|
-
*
|
|
5498
|
-
*
|
|
5499
|
-
*
|
|
5500
|
-
*
|
|
5501
|
-
*
|
|
5502
|
-
*
|
|
5503
|
-
*
|
|
5512
|
+
* @example
|
|
5513
|
+
* ```typescript
|
|
5514
|
+
* const agentBay = new AgentBay({ apiKey: 'your_api_key' });
|
|
5515
|
+
* const result = await agentBay.create();
|
|
5516
|
+
* if (result.success) {
|
|
5517
|
+
* const cmdResult = await result.session.command.executeCommand(
|
|
5518
|
+
* 'pwd',
|
|
5519
|
+
* 5000,
|
|
5520
|
+
* '/tmp',
|
|
5521
|
+
* { TEST_VAR: 'test_value' }
|
|
5522
|
+
* );
|
|
5523
|
+
* console.log('Working directory:', cmdResult.stdout);
|
|
5524
|
+
* await result.session.delete();
|
|
5525
|
+
* }
|
|
5526
|
+
* ```
|
|
5504
5527
|
*/
|
|
5505
|
-
async executeCommand(command, timeoutMs = 1e3) {
|
|
5528
|
+
async executeCommand(command, timeoutMs = 1e3, cwd, envs) {
|
|
5529
|
+
if (envs !== void 0) {
|
|
5530
|
+
const invalidVars = [];
|
|
5531
|
+
for (const [key, value] of Object.entries(envs)) {
|
|
5532
|
+
if (typeof key !== "string") {
|
|
5533
|
+
invalidVars.push(`key '${key}' (type: ${typeof key})`);
|
|
5534
|
+
}
|
|
5535
|
+
if (typeof value !== "string") {
|
|
5536
|
+
invalidVars.push(`value for key '${key}' (type: ${typeof value})`);
|
|
5537
|
+
}
|
|
5538
|
+
}
|
|
5539
|
+
if (invalidVars.length > 0) {
|
|
5540
|
+
throw new Error(
|
|
5541
|
+
`Invalid environment variables: all keys and values must be strings. Found invalid entries: ${invalidVars.join(", ")}`
|
|
5542
|
+
);
|
|
5543
|
+
}
|
|
5544
|
+
}
|
|
5506
5545
|
try {
|
|
5546
|
+
const MAX_TIMEOUT_MS = 5e4;
|
|
5547
|
+
if (timeoutMs > MAX_TIMEOUT_MS) {
|
|
5548
|
+
timeoutMs = MAX_TIMEOUT_MS;
|
|
5549
|
+
}
|
|
5507
5550
|
const args = {
|
|
5508
5551
|
command,
|
|
5509
5552
|
timeout_ms: timeoutMs
|
|
5510
5553
|
};
|
|
5554
|
+
if (cwd !== void 0) {
|
|
5555
|
+
args.cwd = cwd;
|
|
5556
|
+
}
|
|
5557
|
+
if (envs !== void 0) {
|
|
5558
|
+
args.envs = envs;
|
|
5559
|
+
}
|
|
5511
5560
|
const result = await this.session.callMcpTool("shell", args);
|
|
5512
|
-
|
|
5513
|
-
|
|
5514
|
-
|
|
5515
|
-
|
|
5516
|
-
|
|
5517
|
-
|
|
5561
|
+
if (result.success) {
|
|
5562
|
+
try {
|
|
5563
|
+
let dataJson;
|
|
5564
|
+
if (typeof result.data === "string") {
|
|
5565
|
+
dataJson = JSON.parse(result.data);
|
|
5566
|
+
} else {
|
|
5567
|
+
dataJson = result.data;
|
|
5568
|
+
}
|
|
5569
|
+
const stdout = dataJson.stdout || "";
|
|
5570
|
+
const stderr = dataJson.stderr || "";
|
|
5571
|
+
const errorCode = dataJson.errorCode || 0;
|
|
5572
|
+
const traceId = dataJson.traceId || "";
|
|
5573
|
+
const success = errorCode === 0;
|
|
5574
|
+
const output = stdout + stderr;
|
|
5575
|
+
return {
|
|
5576
|
+
requestId: result.requestId,
|
|
5577
|
+
success,
|
|
5578
|
+
output,
|
|
5579
|
+
exitCode: errorCode,
|
|
5580
|
+
stdout,
|
|
5581
|
+
stderr,
|
|
5582
|
+
traceId: traceId || void 0,
|
|
5583
|
+
errorMessage: result.errorMessage
|
|
5584
|
+
};
|
|
5585
|
+
} catch (parseError) {
|
|
5586
|
+
return {
|
|
5587
|
+
requestId: result.requestId,
|
|
5588
|
+
success: true,
|
|
5589
|
+
output: typeof result.data === "string" ? result.data : String(result.data),
|
|
5590
|
+
errorMessage: result.errorMessage
|
|
5591
|
+
};
|
|
5592
|
+
}
|
|
5593
|
+
} else {
|
|
5594
|
+
try {
|
|
5595
|
+
const errorData = typeof result.errorMessage === "string" ? JSON.parse(result.errorMessage) : result.errorMessage;
|
|
5596
|
+
if (errorData && typeof errorData === "object") {
|
|
5597
|
+
const stdout = errorData.stdout || "";
|
|
5598
|
+
const stderr = errorData.stderr || "";
|
|
5599
|
+
const errorCode = errorData.errorCode || 0;
|
|
5600
|
+
const traceId = errorData.traceId || "";
|
|
5601
|
+
const output = stdout + stderr;
|
|
5602
|
+
return {
|
|
5603
|
+
requestId: result.requestId,
|
|
5604
|
+
success: false,
|
|
5605
|
+
output,
|
|
5606
|
+
exitCode: errorCode,
|
|
5607
|
+
stdout,
|
|
5608
|
+
stderr,
|
|
5609
|
+
traceId: traceId || void 0,
|
|
5610
|
+
errorMessage: stderr || result.errorMessage
|
|
5611
|
+
};
|
|
5612
|
+
}
|
|
5613
|
+
} catch (e6) {
|
|
5614
|
+
}
|
|
5615
|
+
return {
|
|
5616
|
+
requestId: result.requestId,
|
|
5617
|
+
success: false,
|
|
5618
|
+
output: "",
|
|
5619
|
+
errorMessage: result.errorMessage || "Failed to execute command"
|
|
5620
|
+
};
|
|
5621
|
+
}
|
|
5518
5622
|
} catch (error) {
|
|
5519
5623
|
return {
|
|
5520
5624
|
requestId: "",
|