@lingyao037/openclaw-lingyao-cli 0.9.3 → 0.9.4

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/cli.mjs +48 -0
  2. package/package.json +1 -1
package/cli.mjs CHANGED
@@ -478,7 +478,52 @@ class LingyaoInstaller {
478
478
  }
479
479
 
480
480
  // HTTP helpers
481
+ hasProxyEnv() {
482
+ return Boolean(
483
+ process.env.HTTPS_PROXY ||
484
+ process.env.https_proxy ||
485
+ process.env.HTTP_PROXY ||
486
+ process.env.http_proxy ||
487
+ process.env.ALL_PROXY ||
488
+ process.env.all_proxy
489
+ );
490
+ }
491
+
492
+ curlJson(method, path, body = null) {
493
+ return new Promise((resolve, reject) => {
494
+ const url = `${LINGYAO_API}${path}`;
495
+ const args = ['-sS', '-X', method, url, '-H', 'Content-Type: application/json'];
496
+ if (this.gatewayToken) {
497
+ args.push('-H', `Authorization: Bearer ${this.gatewayToken}`);
498
+ }
499
+ if (body !== null) {
500
+ args.push('-d', JSON.stringify(body));
501
+ }
502
+
503
+ const child = spawn('curl', args, { stdio: ['ignore', 'pipe', 'pipe'], shell: false });
504
+ let stdout = '';
505
+ let stderr = '';
506
+ child.stdout.on('data', (chunk) => { stdout += chunk.toString(); });
507
+ child.stderr.on('data', (chunk) => { stderr += chunk.toString(); });
508
+ child.on('error', (error) => reject(error));
509
+ child.on('close', (code) => {
510
+ if (code !== 0) {
511
+ reject(new Error(stderr.trim() || `curl exited with code ${code}`));
512
+ return;
513
+ }
514
+ try {
515
+ resolve(JSON.parse(stdout));
516
+ } catch {
517
+ reject(new Error(`Invalid JSON: ${stdout}`));
518
+ }
519
+ });
520
+ });
521
+ }
522
+
481
523
  httpsPost(path, body) {
524
+ if (this.hasProxyEnv()) {
525
+ return this.curlJson('POST', path, body);
526
+ }
482
527
  return new Promise((resolve, reject) => {
483
528
  const data = JSON.stringify(body);
484
529
  const url = `${LINGYAO_API}${path}`;
@@ -504,6 +549,9 @@ class LingyaoInstaller {
504
549
  }
505
550
 
506
551
  httpsGet(path) {
552
+ if (this.hasProxyEnv()) {
553
+ return this.curlJson('GET', path, null);
554
+ }
507
555
  return new Promise((resolve, reject) => {
508
556
  const url = `${LINGYAO_API}${path}`;
509
557
  const req = https.get(url, { timeout: 10000 }, (res) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingyao037/openclaw-lingyao-cli",
3
- "version": "0.9.3",
3
+ "version": "0.9.4",
4
4
  "description": "Lingyao Channel Plugin for OpenClaw - bidirectional sync via lingyao.live server relay",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",