shellx-ai 1.0.0 → 1.0.1

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/README.md CHANGED
@@ -24,6 +24,16 @@
24
24
  npm install shellx-ai
25
25
  ```
26
26
 
27
+ ### Node.js Version Compatibility
28
+
29
+ ShellX supports Node.js 14+ with automatic fetch polyfill:
30
+
31
+ - **Node.js 18+**: Uses built-in `fetch` API
32
+ - **Node.js 14-17**: Automatically falls back to `node-fetch` or built-in `https` module
33
+ - **Browser**: Uses native `fetch` API
34
+
35
+ No additional configuration needed - ShellX handles environment detection automatically!
36
+
27
37
  ### Basic Setup
28
38
 
29
39
  ```typescript
@@ -288,7 +298,6 @@ ShellX automatically handles service availability:
288
298
 
289
299
  Check out the [examples directory](./examples/) for comprehensive use cases:
290
300
 
291
- - **[paytm.ts](./examples/paytm.ts)** - PayTM app automation with bill analysis
292
301
  - **[basic.ts](./examples/basic.ts)** - Basic automation operations
293
302
  - **[shell-commands-demo.ts](./examples/shell-commands-demo.ts)** - Shell command execution
294
303
  - **[find-elements-demo.ts](./examples/find-elements-demo.ts)** - Element finding strategies
package/dist/shellx.js CHANGED
@@ -1,4 +1,37 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
36
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
37
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -793,6 +826,65 @@ exports.AutomationHelpers = ShellX;
793
826
  function createShellX(client) {
794
827
  return new ShellX(client);
795
828
  }
829
+ /**
830
+ * 获取适合当前环境的fetch函数
831
+ */
832
+ function getFetch() {
833
+ return __awaiter(this, void 0, void 0, function* () {
834
+ // 检查是否已有全局fetch(Node.js 18+或浏览器环境)
835
+ if (typeof globalThis.fetch !== 'undefined') {
836
+ return globalThis.fetch;
837
+ }
838
+ // Node.js环境下动态导入node-fetch
839
+ try {
840
+ const { default: fetch } = yield Promise.resolve().then(() => __importStar(require('node-fetch')));
841
+ return fetch;
842
+ }
843
+ catch (error) {
844
+ // 如果node-fetch不可用,尝试使用内置的https模块
845
+ console.warn('⚠️ [Auth] node-fetch不可用,使用内置https模块');
846
+ return createNodeFetch();
847
+ }
848
+ });
849
+ }
850
+ /**
851
+ * 使用Node.js内置模块创建fetch替代函数
852
+ */
853
+ function createNodeFetch() {
854
+ return (url, options) => __awaiter(this, void 0, void 0, function* () {
855
+ const https = yield Promise.resolve().then(() => __importStar(require('https')));
856
+ const { URL } = yield Promise.resolve().then(() => __importStar(require('url')));
857
+ return new Promise((resolve, reject) => {
858
+ const parsedUrl = new URL(url);
859
+ const requestOptions = {
860
+ hostname: parsedUrl.hostname,
861
+ port: parsedUrl.port || 443,
862
+ path: parsedUrl.pathname + parsedUrl.search,
863
+ method: (options === null || options === void 0 ? void 0 : options.method) || 'GET',
864
+ headers: (options === null || options === void 0 ? void 0 : options.headers) || {}
865
+ };
866
+ const req = https.request(requestOptions, (res) => {
867
+ let data = '';
868
+ res.on('data', (chunk) => data += chunk);
869
+ res.on('end', () => {
870
+ const response = {
871
+ ok: res.statusCode ? res.statusCode >= 200 && res.statusCode < 300 : false,
872
+ status: res.statusCode || 0,
873
+ statusText: res.statusMessage || '',
874
+ json: () => __awaiter(this, void 0, void 0, function* () { return JSON.parse(data); }),
875
+ text: () => __awaiter(this, void 0, void 0, function* () { return data; })
876
+ };
877
+ resolve(response);
878
+ });
879
+ });
880
+ req.on('error', reject);
881
+ if (options === null || options === void 0 ? void 0 : options.body) {
882
+ req.write(options.body);
883
+ }
884
+ req.end();
885
+ });
886
+ });
887
+ }
796
888
  /**
797
889
  * 从ShellX.ai服务认证并获取WebSocket连接信息
798
890
  */
@@ -804,7 +896,9 @@ function authenticateDevice() {
804
896
  }
805
897
  try {
806
898
  console.log('🔑 [Auth] 正在认证设备...');
807
- const response = yield fetch(`https://shellx.ai/api/device/${authKey}`, {
899
+ // 获取适合当前环境的fetch函数
900
+ const fetchFn = yield getFetch();
901
+ const response = yield fetchFn(`https://shellx.ai/api/device/${authKey}`, {
808
902
  method: 'GET',
809
903
  headers: {
810
904
  'Content-Type': 'application/json',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shellx-ai",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
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",
@@ -23,7 +23,8 @@
23
23
  "test:shellx-ai": "ts-node -r dotenv/config examples/shellx.ai/index.ts",
24
24
  "test:shell-commands": "ts-node -r dotenv/config examples/shell-commands-demo.ts",
25
25
  "test:no-output": "ts-node -r dotenv/config examples/no-output-command-test.ts",
26
- "test:find-elements": "ts-node -r dotenv/config examples/find-elements-demo.ts"
26
+ "test:find-elements": "ts-node -r dotenv/config examples/find-elements-demo.ts",
27
+ "test:api": "ts-node test-shellx.ts"
27
28
  },
28
29
  "keywords": [
29
30
  "websocket",
@@ -42,6 +43,9 @@
42
43
  "dotenv": "^16.4.5",
43
44
  "uuid": "^11.1.0"
44
45
  },
46
+ "optionalDependencies": {
47
+ "node-fetch": "^3.3.2"
48
+ },
45
49
  "devDependencies": {
46
50
  "@types/jest": "^30.0.0",
47
51
  "@types/node": "^24.0.13",