test-wuying-agentbay-sdk 0.13.0-beta.20251209195417 → 0.13.0-beta.20251209225815
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.d.mts
CHANGED
|
@@ -133,10 +133,18 @@ interface CommandResult extends ApiResponse {
|
|
|
133
133
|
requestId: string;
|
|
134
134
|
/** Whether the command execution was successful */
|
|
135
135
|
success: boolean;
|
|
136
|
-
/** The command output */
|
|
136
|
+
/** The command output (for backward compatibility, equals stdout + stderr) */
|
|
137
137
|
output: string;
|
|
138
138
|
/** Optional error message if the operation failed */
|
|
139
139
|
errorMessage?: string;
|
|
140
|
+
/** The exit code of the command execution. Default is 0. */
|
|
141
|
+
exitCode?: number;
|
|
142
|
+
/** Standard output from the command execution */
|
|
143
|
+
stdout?: string;
|
|
144
|
+
/** Standard error from the command execution */
|
|
145
|
+
stderr?: string;
|
|
146
|
+
/** Trace ID for error tracking. Only present when errorCode != 0. Used for quick problem localization. */
|
|
147
|
+
traceId?: string;
|
|
140
148
|
}
|
|
141
149
|
/**
|
|
142
150
|
* Interface for code execution operation responses
|
|
@@ -3687,14 +3695,28 @@ declare class Command {
|
|
|
3687
3695
|
*/
|
|
3688
3696
|
private sanitizeError;
|
|
3689
3697
|
/**
|
|
3690
|
-
*
|
|
3698
|
+
* Execute a shell command with optional working directory and environment variables.
|
|
3691
3699
|
*
|
|
3692
|
-
*
|
|
3693
|
-
*
|
|
3700
|
+
* Executes a shell command in the session environment with configurable timeout,
|
|
3701
|
+
* working directory, and environment variables. The command runs with session
|
|
3702
|
+
* user permissions in a Linux shell environment.
|
|
3703
|
+
*
|
|
3704
|
+
* @param command - The shell command to execute
|
|
3705
|
+
* @param timeoutMs - Timeout in milliseconds (default: 1000ms/1s). Maximum allowed
|
|
3706
|
+
* timeout is 50000ms (50s). If a larger value is provided,
|
|
3707
|
+
* it will be automatically limited to 50000ms
|
|
3708
|
+
* @param cwd - The working directory for command execution. If not specified,
|
|
3709
|
+
* the command runs in the default session directory
|
|
3710
|
+
* @param envs - Environment variables as a dictionary of key-value pairs.
|
|
3711
|
+
* These variables are set for the command execution only
|
|
3694
3712
|
*
|
|
3695
3713
|
* @returns Promise resolving to CommandResult containing:
|
|
3696
|
-
* - success: Whether the command executed successfully
|
|
3697
|
-
* - output:
|
|
3714
|
+
* - success: Whether the command executed successfully (exitCode === 0)
|
|
3715
|
+
* - output: Command output for backward compatibility (stdout + stderr)
|
|
3716
|
+
* - exitCode: The exit code of the command execution (0 for success)
|
|
3717
|
+
* - stdout: Standard output from the command execution
|
|
3718
|
+
* - stderr: Standard error from the command execution
|
|
3719
|
+
* - traceId: Trace ID for error tracking (only present when exitCode !== 0)
|
|
3698
3720
|
* - requestId: Unique identifier for this API request
|
|
3699
3721
|
* - errorMessage: Error description if execution failed
|
|
3700
3722
|
*
|
|
@@ -3703,22 +3725,31 @@ declare class Command {
|
|
|
3703
3725
|
* const agentBay = new AgentBay({ apiKey: 'your_api_key' });
|
|
3704
3726
|
* const result = await agentBay.create();
|
|
3705
3727
|
* if (result.success) {
|
|
3706
|
-
* const cmdResult = await result.session.command.executeCommand('echo "Hello"',
|
|
3728
|
+
* const cmdResult = await result.session.command.executeCommand('echo "Hello"', 5000);
|
|
3707
3729
|
* console.log('Command output:', cmdResult.output);
|
|
3730
|
+
* console.log('Exit code:', cmdResult.exitCode);
|
|
3731
|
+
* console.log('Stdout:', cmdResult.stdout);
|
|
3708
3732
|
* await result.session.delete();
|
|
3709
3733
|
* }
|
|
3710
3734
|
* ```
|
|
3711
3735
|
*
|
|
3712
|
-
* @
|
|
3713
|
-
*
|
|
3714
|
-
*
|
|
3715
|
-
*
|
|
3716
|
-
*
|
|
3717
|
-
*
|
|
3718
|
-
*
|
|
3719
|
-
*
|
|
3736
|
+
* @example
|
|
3737
|
+
* ```typescript
|
|
3738
|
+
* const agentBay = new AgentBay({ apiKey: 'your_api_key' });
|
|
3739
|
+
* const result = await agentBay.create();
|
|
3740
|
+
* if (result.success) {
|
|
3741
|
+
* const cmdResult = await result.session.command.executeCommand(
|
|
3742
|
+
* 'pwd',
|
|
3743
|
+
* 5000,
|
|
3744
|
+
* '/tmp',
|
|
3745
|
+
* { TEST_VAR: 'test_value' }
|
|
3746
|
+
* );
|
|
3747
|
+
* console.log('Working directory:', cmdResult.stdout);
|
|
3748
|
+
* await result.session.delete();
|
|
3749
|
+
* }
|
|
3750
|
+
* ```
|
|
3720
3751
|
*/
|
|
3721
|
-
executeCommand(command: string, timeoutMs?: number): Promise<CommandResult>;
|
|
3752
|
+
executeCommand(command: string, timeoutMs?: number, cwd?: string, envs?: Record<string, string>): Promise<CommandResult>;
|
|
3722
3753
|
}
|
|
3723
3754
|
|
|
3724
3755
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -133,10 +133,18 @@ interface CommandResult extends ApiResponse {
|
|
|
133
133
|
requestId: string;
|
|
134
134
|
/** Whether the command execution was successful */
|
|
135
135
|
success: boolean;
|
|
136
|
-
/** The command output */
|
|
136
|
+
/** The command output (for backward compatibility, equals stdout + stderr) */
|
|
137
137
|
output: string;
|
|
138
138
|
/** Optional error message if the operation failed */
|
|
139
139
|
errorMessage?: string;
|
|
140
|
+
/** The exit code of the command execution. Default is 0. */
|
|
141
|
+
exitCode?: number;
|
|
142
|
+
/** Standard output from the command execution */
|
|
143
|
+
stdout?: string;
|
|
144
|
+
/** Standard error from the command execution */
|
|
145
|
+
stderr?: string;
|
|
146
|
+
/** Trace ID for error tracking. Only present when errorCode != 0. Used for quick problem localization. */
|
|
147
|
+
traceId?: string;
|
|
140
148
|
}
|
|
141
149
|
/**
|
|
142
150
|
* Interface for code execution operation responses
|
|
@@ -3687,14 +3695,28 @@ declare class Command {
|
|
|
3687
3695
|
*/
|
|
3688
3696
|
private sanitizeError;
|
|
3689
3697
|
/**
|
|
3690
|
-
*
|
|
3698
|
+
* Execute a shell command with optional working directory and environment variables.
|
|
3691
3699
|
*
|
|
3692
|
-
*
|
|
3693
|
-
*
|
|
3700
|
+
* Executes a shell command in the session environment with configurable timeout,
|
|
3701
|
+
* working directory, and environment variables. The command runs with session
|
|
3702
|
+
* user permissions in a Linux shell environment.
|
|
3703
|
+
*
|
|
3704
|
+
* @param command - The shell command to execute
|
|
3705
|
+
* @param timeoutMs - Timeout in milliseconds (default: 1000ms/1s). Maximum allowed
|
|
3706
|
+
* timeout is 50000ms (50s). If a larger value is provided,
|
|
3707
|
+
* it will be automatically limited to 50000ms
|
|
3708
|
+
* @param cwd - The working directory for command execution. If not specified,
|
|
3709
|
+
* the command runs in the default session directory
|
|
3710
|
+
* @param envs - Environment variables as a dictionary of key-value pairs.
|
|
3711
|
+
* These variables are set for the command execution only
|
|
3694
3712
|
*
|
|
3695
3713
|
* @returns Promise resolving to CommandResult containing:
|
|
3696
|
-
* - success: Whether the command executed successfully
|
|
3697
|
-
* - output:
|
|
3714
|
+
* - success: Whether the command executed successfully (exitCode === 0)
|
|
3715
|
+
* - output: Command output for backward compatibility (stdout + stderr)
|
|
3716
|
+
* - exitCode: The exit code of the command execution (0 for success)
|
|
3717
|
+
* - stdout: Standard output from the command execution
|
|
3718
|
+
* - stderr: Standard error from the command execution
|
|
3719
|
+
* - traceId: Trace ID for error tracking (only present when exitCode !== 0)
|
|
3698
3720
|
* - requestId: Unique identifier for this API request
|
|
3699
3721
|
* - errorMessage: Error description if execution failed
|
|
3700
3722
|
*
|
|
@@ -3703,22 +3725,31 @@ declare class Command {
|
|
|
3703
3725
|
* const agentBay = new AgentBay({ apiKey: 'your_api_key' });
|
|
3704
3726
|
* const result = await agentBay.create();
|
|
3705
3727
|
* if (result.success) {
|
|
3706
|
-
* const cmdResult = await result.session.command.executeCommand('echo "Hello"',
|
|
3728
|
+
* const cmdResult = await result.session.command.executeCommand('echo "Hello"', 5000);
|
|
3707
3729
|
* console.log('Command output:', cmdResult.output);
|
|
3730
|
+
* console.log('Exit code:', cmdResult.exitCode);
|
|
3731
|
+
* console.log('Stdout:', cmdResult.stdout);
|
|
3708
3732
|
* await result.session.delete();
|
|
3709
3733
|
* }
|
|
3710
3734
|
* ```
|
|
3711
3735
|
*
|
|
3712
|
-
* @
|
|
3713
|
-
*
|
|
3714
|
-
*
|
|
3715
|
-
*
|
|
3716
|
-
*
|
|
3717
|
-
*
|
|
3718
|
-
*
|
|
3719
|
-
*
|
|
3736
|
+
* @example
|
|
3737
|
+
* ```typescript
|
|
3738
|
+
* const agentBay = new AgentBay({ apiKey: 'your_api_key' });
|
|
3739
|
+
* const result = await agentBay.create();
|
|
3740
|
+
* if (result.success) {
|
|
3741
|
+
* const cmdResult = await result.session.command.executeCommand(
|
|
3742
|
+
* 'pwd',
|
|
3743
|
+
* 5000,
|
|
3744
|
+
* '/tmp',
|
|
3745
|
+
* { TEST_VAR: 'test_value' }
|
|
3746
|
+
* );
|
|
3747
|
+
* console.log('Working directory:', cmdResult.stdout);
|
|
3748
|
+
* await result.session.delete();
|
|
3749
|
+
* }
|
|
3750
|
+
* ```
|
|
3720
3751
|
*/
|
|
3721
|
-
executeCommand(command: string, timeoutMs?: number): Promise<CommandResult>;
|
|
3752
|
+
executeCommand(command: string, timeoutMs?: number, cwd?: string, envs?: Record<string, string>): Promise<CommandResult>;
|
|
3722
3753
|
}
|
|
3723
3754
|
|
|
3724
3755
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -5485,14 +5485,28 @@ var _Command = class _Command {
|
|
|
5485
5485
|
return errorString.replace(/Bearer\s+[^\s]+/g, "Bearer [REDACTED]");
|
|
5486
5486
|
}
|
|
5487
5487
|
/**
|
|
5488
|
-
*
|
|
5488
|
+
* Execute a shell command with optional working directory and environment variables.
|
|
5489
5489
|
*
|
|
5490
|
-
*
|
|
5491
|
-
*
|
|
5490
|
+
* Executes a shell command in the session environment with configurable timeout,
|
|
5491
|
+
* working directory, and environment variables. The command runs with session
|
|
5492
|
+
* user permissions in a Linux shell environment.
|
|
5493
|
+
*
|
|
5494
|
+
* @param command - The shell command to execute
|
|
5495
|
+
* @param timeoutMs - Timeout in milliseconds (default: 1000ms/1s). Maximum allowed
|
|
5496
|
+
* timeout is 50000ms (50s). If a larger value is provided,
|
|
5497
|
+
* it will be automatically limited to 50000ms
|
|
5498
|
+
* @param cwd - The working directory for command execution. If not specified,
|
|
5499
|
+
* the command runs in the default session directory
|
|
5500
|
+
* @param envs - Environment variables as a dictionary of key-value pairs.
|
|
5501
|
+
* These variables are set for the command execution only
|
|
5492
5502
|
*
|
|
5493
5503
|
* @returns Promise resolving to CommandResult containing:
|
|
5494
|
-
* - success: Whether the command executed successfully
|
|
5495
|
-
* - output:
|
|
5504
|
+
* - success: Whether the command executed successfully (exitCode === 0)
|
|
5505
|
+
* - output: Command output for backward compatibility (stdout + stderr)
|
|
5506
|
+
* - exitCode: The exit code of the command execution (0 for success)
|
|
5507
|
+
* - stdout: Standard output from the command execution
|
|
5508
|
+
* - stderr: Standard error from the command execution
|
|
5509
|
+
* - traceId: Trace ID for error tracking (only present when exitCode !== 0)
|
|
5496
5510
|
* - requestId: Unique identifier for this API request
|
|
5497
5511
|
* - errorMessage: Error description if execution failed
|
|
5498
5512
|
*
|
|
@@ -5501,34 +5515,124 @@ var _Command = class _Command {
|
|
|
5501
5515
|
* const agentBay = new AgentBay({ apiKey: 'your_api_key' });
|
|
5502
5516
|
* const result = await agentBay.create();
|
|
5503
5517
|
* if (result.success) {
|
|
5504
|
-
* const cmdResult = await result.session.command.executeCommand('echo "Hello"',
|
|
5518
|
+
* const cmdResult = await result.session.command.executeCommand('echo "Hello"', 5000);
|
|
5505
5519
|
* console.log('Command output:', cmdResult.output);
|
|
5520
|
+
* console.log('Exit code:', cmdResult.exitCode);
|
|
5521
|
+
* console.log('Stdout:', cmdResult.stdout);
|
|
5506
5522
|
* await result.session.delete();
|
|
5507
5523
|
* }
|
|
5508
5524
|
* ```
|
|
5509
5525
|
*
|
|
5510
|
-
* @
|
|
5511
|
-
*
|
|
5512
|
-
*
|
|
5513
|
-
*
|
|
5514
|
-
*
|
|
5515
|
-
*
|
|
5516
|
-
*
|
|
5517
|
-
*
|
|
5526
|
+
* @example
|
|
5527
|
+
* ```typescript
|
|
5528
|
+
* const agentBay = new AgentBay({ apiKey: 'your_api_key' });
|
|
5529
|
+
* const result = await agentBay.create();
|
|
5530
|
+
* if (result.success) {
|
|
5531
|
+
* const cmdResult = await result.session.command.executeCommand(
|
|
5532
|
+
* 'pwd',
|
|
5533
|
+
* 5000,
|
|
5534
|
+
* '/tmp',
|
|
5535
|
+
* { TEST_VAR: 'test_value' }
|
|
5536
|
+
* );
|
|
5537
|
+
* console.log('Working directory:', cmdResult.stdout);
|
|
5538
|
+
* await result.session.delete();
|
|
5539
|
+
* }
|
|
5540
|
+
* ```
|
|
5518
5541
|
*/
|
|
5519
|
-
async executeCommand(command, timeoutMs = 1e3) {
|
|
5542
|
+
async executeCommand(command, timeoutMs = 1e3, cwd, envs) {
|
|
5543
|
+
if (envs !== void 0) {
|
|
5544
|
+
const invalidVars = [];
|
|
5545
|
+
for (const [key, value] of Object.entries(envs)) {
|
|
5546
|
+
if (typeof key !== "string") {
|
|
5547
|
+
invalidVars.push(`key '${key}' (type: ${typeof key})`);
|
|
5548
|
+
}
|
|
5549
|
+
if (typeof value !== "string") {
|
|
5550
|
+
invalidVars.push(`value for key '${key}' (type: ${typeof value})`);
|
|
5551
|
+
}
|
|
5552
|
+
}
|
|
5553
|
+
if (invalidVars.length > 0) {
|
|
5554
|
+
throw new Error(
|
|
5555
|
+
`Invalid environment variables: all keys and values must be strings. Found invalid entries: ${invalidVars.join(", ")}`
|
|
5556
|
+
);
|
|
5557
|
+
}
|
|
5558
|
+
}
|
|
5520
5559
|
try {
|
|
5560
|
+
const MAX_TIMEOUT_MS = 5e4;
|
|
5561
|
+
if (timeoutMs > MAX_TIMEOUT_MS) {
|
|
5562
|
+
timeoutMs = MAX_TIMEOUT_MS;
|
|
5563
|
+
}
|
|
5521
5564
|
const args = {
|
|
5522
5565
|
command,
|
|
5523
5566
|
timeout_ms: timeoutMs
|
|
5524
5567
|
};
|
|
5568
|
+
if (cwd !== void 0) {
|
|
5569
|
+
args.cwd = cwd;
|
|
5570
|
+
}
|
|
5571
|
+
if (envs !== void 0) {
|
|
5572
|
+
args.envs = envs;
|
|
5573
|
+
}
|
|
5525
5574
|
const result = await this.session.callMcpTool("shell", args);
|
|
5526
|
-
|
|
5527
|
-
|
|
5528
|
-
|
|
5529
|
-
|
|
5530
|
-
|
|
5531
|
-
|
|
5575
|
+
if (result.success) {
|
|
5576
|
+
try {
|
|
5577
|
+
let dataJson;
|
|
5578
|
+
if (typeof result.data === "string") {
|
|
5579
|
+
dataJson = JSON.parse(result.data);
|
|
5580
|
+
} else {
|
|
5581
|
+
dataJson = result.data;
|
|
5582
|
+
}
|
|
5583
|
+
const stdout = dataJson.stdout || "";
|
|
5584
|
+
const stderr = dataJson.stderr || "";
|
|
5585
|
+
const errorCode = dataJson.errorCode || 0;
|
|
5586
|
+
const traceId = dataJson.traceId || "";
|
|
5587
|
+
const success = errorCode === 0;
|
|
5588
|
+
const output = stdout + stderr;
|
|
5589
|
+
return {
|
|
5590
|
+
requestId: result.requestId,
|
|
5591
|
+
success,
|
|
5592
|
+
output,
|
|
5593
|
+
exitCode: errorCode,
|
|
5594
|
+
stdout,
|
|
5595
|
+
stderr,
|
|
5596
|
+
traceId: traceId || void 0,
|
|
5597
|
+
errorMessage: result.errorMessage
|
|
5598
|
+
};
|
|
5599
|
+
} catch (parseError) {
|
|
5600
|
+
return {
|
|
5601
|
+
requestId: result.requestId,
|
|
5602
|
+
success: true,
|
|
5603
|
+
output: typeof result.data === "string" ? result.data : String(result.data),
|
|
5604
|
+
errorMessage: result.errorMessage
|
|
5605
|
+
};
|
|
5606
|
+
}
|
|
5607
|
+
} else {
|
|
5608
|
+
try {
|
|
5609
|
+
const errorData = typeof result.errorMessage === "string" ? JSON.parse(result.errorMessage) : result.errorMessage;
|
|
5610
|
+
if (errorData && typeof errorData === "object") {
|
|
5611
|
+
const stdout = errorData.stdout || "";
|
|
5612
|
+
const stderr = errorData.stderr || "";
|
|
5613
|
+
const errorCode = errorData.errorCode || 0;
|
|
5614
|
+
const traceId = errorData.traceId || "";
|
|
5615
|
+
const output = stdout + stderr;
|
|
5616
|
+
return {
|
|
5617
|
+
requestId: result.requestId,
|
|
5618
|
+
success: false,
|
|
5619
|
+
output,
|
|
5620
|
+
exitCode: errorCode,
|
|
5621
|
+
stdout,
|
|
5622
|
+
stderr,
|
|
5623
|
+
traceId: traceId || void 0,
|
|
5624
|
+
errorMessage: stderr || result.errorMessage
|
|
5625
|
+
};
|
|
5626
|
+
}
|
|
5627
|
+
} catch {
|
|
5628
|
+
}
|
|
5629
|
+
return {
|
|
5630
|
+
requestId: result.requestId,
|
|
5631
|
+
success: false,
|
|
5632
|
+
output: "",
|
|
5633
|
+
errorMessage: result.errorMessage || "Failed to execute command"
|
|
5634
|
+
};
|
|
5635
|
+
}
|
|
5532
5636
|
} catch (error) {
|
|
5533
5637
|
return {
|
|
5534
5638
|
requestId: "",
|