shellx-ai 1.0.6 → 1.0.7

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.
Files changed (2) hide show
  1. package/dist/shellx.js +32 -29
  2. package/package.json +1 -1
package/dist/shellx.js CHANGED
@@ -56,6 +56,7 @@ const utils_1 = require("./utils");
56
56
  const index_1 = __importDefault(require("./index"));
57
57
  // 安全地获取环境变量,兼容浏览器和Node.js环境
58
58
  let authKey = (0, utils_1.getEnvVar)('SHELLX_AUTH_KEY');
59
+ const COMMAND_PTY_SID = 999;
59
60
  /**
60
61
  * ShellX automation utilities for common patterns
61
62
  */
@@ -90,38 +91,40 @@ class ShellX {
90
91
  */
91
92
  handleShellOutput(chunks) {
92
93
  const [sessionId, len, dataArrays] = chunks;
93
- try {
94
- // 将 Uint8Array 数组转换为字符串
95
- let output = '';
96
- for (const data of dataArrays) {
97
- output += new TextDecoder().decode(data);
98
- }
99
- console.log(`📟 [Shell] 收到输出 (Session ${sessionId}): ${output.trim()}`);
100
- // 为每个等待的命令累积输出
101
- for (const [commandKey, commandPromise] of this.shellCommandPromises.entries()) {
102
- // 检查是否该命令相关的输出
103
- if (this.isOutputForCommand(output, commandPromise.command, sessionId)) {
104
- // 存储该 session 的输出
105
- if (!commandPromise.sessionOutputs.has(sessionId)) {
106
- commandPromise.sessionOutputs.set(sessionId, '');
107
- }
108
- const currentSessionOutput = commandPromise.sessionOutputs.get(sessionId) || '';
109
- commandPromise.sessionOutputs.set(sessionId, currentSessionOutput + output);
110
- // 更新总输出
111
- commandPromise.output = this.combineSessionOutputs(commandPromise.sessionOutputs);
112
- console.log(`📊 [Shell] 命令 ${commandKey} 累积输出长度: ${commandPromise.output.length}`);
113
- // 调用输出回调(传递清理后的输出)
114
- if (commandPromise.options.onOutput) {
115
- const cleanOutput = this.cleanCommandOutput(output, commandPromise.command);
116
- commandPromise.options.onOutput(cleanOutput);
94
+ if (sessionId === COMMAND_PTY_SID) {
95
+ try {
96
+ // Uint8Array 数组转换为字符串
97
+ let output = '';
98
+ for (const data of dataArrays) {
99
+ output += new TextDecoder().decode(data);
100
+ }
101
+ console.log(`📟 [Shell] 收到输出 (Session ${sessionId}): ${output.trim()}`);
102
+ // 为每个等待的命令累积输出
103
+ for (const [commandKey, commandPromise] of this.shellCommandPromises.entries()) {
104
+ // 检查是否该命令相关的输出
105
+ if (this.isOutputForCommand(output, commandPromise.command, sessionId)) {
106
+ // 存储该 session 的输出
107
+ if (!commandPromise.sessionOutputs.has(sessionId)) {
108
+ commandPromise.sessionOutputs.set(sessionId, '');
109
+ }
110
+ const currentSessionOutput = commandPromise.sessionOutputs.get(sessionId) || '';
111
+ commandPromise.sessionOutputs.set(sessionId, currentSessionOutput + output);
112
+ // 更新总输出
113
+ commandPromise.output = this.combineSessionOutputs(commandPromise.sessionOutputs);
114
+ console.log(`📊 [Shell] 命令 ${commandKey} 累积输出长度: ${commandPromise.output.length}`);
115
+ // 调用输出回调(传递清理后的输出)
116
+ if (commandPromise.options.onOutput) {
117
+ const cleanOutput = this.cleanCommandOutput(output, commandPromise.command);
118
+ commandPromise.options.onOutput(cleanOutput);
119
+ }
120
+ // 检查是否满足完成条件
121
+ this.checkCommandCompletion(commandKey, commandPromise, output);
117
122
  }
118
- // 检查是否满足完成条件
119
- this.checkCommandCompletion(commandKey, commandPromise, output);
120
123
  }
121
124
  }
122
- }
123
- catch (error) {
124
- console.error(`❌ [Shell] 处理输出数据失败:`, error);
125
+ catch (error) {
126
+ console.error(`❌ [Shell] 处理输出数据失败:`, error);
127
+ }
125
128
  }
126
129
  }
127
130
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shellx-ai",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "shellx is a powerful WebSocket-based client for controlling shell commands and UI automation on remote devices.",
5
5
  "repository": {
6
6
  "url": "git+https://github.com/10cl/shellx.git",