shellx-ai 1.0.5 → 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.
package/dist/index.js CHANGED
@@ -57,7 +57,7 @@ exports.DEFAULT_CONFIG = {
57
57
  onError: () => { },
58
58
  onReconnectFailed: () => { },
59
59
  };
60
- const cbor_x_1 = require("cbor-x");
60
+ const cbor_1 = require("cbor");
61
61
  // 安全地获取环境变量,兼容浏览器和Node.js环境
62
62
  let authKey = (0, utils_1.getEnvVar)('SHELLX_AUTH_KEY');
63
63
  /**
@@ -171,7 +171,7 @@ class WebSocketTaskClient {
171
171
  const authMessage = { authenticate: authKey };
172
172
  console.log('📤 [Auth] 发送认证消息:', { authenticate: authKey });
173
173
  if (this.ws && this.wsConnected) {
174
- this.ws.send((0, cbor_x_1.encode)(authMessage));
174
+ this.ws.send((0, cbor_1.encode)(authMessage));
175
175
  }
176
176
  else {
177
177
  console.error('❌ [Auth] WebSocket未连接,无法发送认证消息');
@@ -199,7 +199,7 @@ class WebSocketTaskClient {
199
199
  this.processServerMessage(serverMessage);
200
200
  return;
201
201
  }
202
- serverMessage = (0, cbor_x_1.decode)(binaryData);
202
+ serverMessage = (0, cbor_1.decode)(binaryData);
203
203
  this.processServerMessage(serverMessage);
204
204
  }
205
205
  catch (cborError) {
@@ -321,7 +321,7 @@ class WebSocketTaskClient {
321
321
  if (this.shellxConnected && this.ws) {
322
322
  try {
323
323
  console.log('📤 [ShellX] 发送消息:', message);
324
- this.ws.send((0, cbor_x_1.encode)(message));
324
+ this.ws.send((0, cbor_1.encode)(message));
325
325
  if (!taskType)
326
326
  resolve(undefined); // For fire-and-forget messages
327
327
  }
@@ -506,7 +506,7 @@ class WebSocketTaskClient {
506
506
  if (this.shellxConnected && this.ws) {
507
507
  try {
508
508
  console.log('📤 [ShellX] 发送消息:', message);
509
- this.ws.send((0, cbor_x_1.encode)(message));
509
+ this.ws.send((0, cbor_1.encode)(message));
510
510
  const promise = new Promise((promiseResolve, promiseReject) => {
511
511
  if (taskType) {
512
512
  if (taskId != null) {
@@ -543,7 +543,7 @@ class WebSocketTaskClient {
543
543
  console.log('🏓 [ShellX] 开始心跳检测...');
544
544
  this.pingIntervalId = setInterval(() => {
545
545
  if (this.ws && this.shellxConnected) {
546
- this.ws.send((0, cbor_x_1.encode)({ ping: BigInt(Date.now()) }));
546
+ this.ws.send((0, cbor_1.encode)({ ping: BigInt(Date.now()) }));
547
547
  }
548
548
  }, this.config.pingInterval);
549
549
  }
@@ -573,7 +573,7 @@ class WebSocketTaskClient {
573
573
  if (message) {
574
574
  try {
575
575
  console.log('flushQueue Sending message:', message);
576
- this.ws.send((0, cbor_x_1.encode)(message));
576
+ this.ws.send((0, cbor_1.encode)(message));
577
577
  }
578
578
  catch (error) {
579
579
  console.error('Failed to send queued message:', error);
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.5",
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",
@@ -30,7 +30,7 @@
30
30
  "author": "10cl <notice@toscl.com>",
31
31
  "license": "MIT",
32
32
  "dependencies": {
33
- "cbor-x": "^1.6.0",
33
+ "cbor": "^9.0.0",
34
34
  "dotenv": "^16.4.5",
35
35
  "ofetch": "^1.4.1",
36
36
  "uuid": "^11.1.0"