cortico-world-hands 0.1.0 → 0.1.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.
Files changed (2) hide show
  1. package/dist/index.js +24 -11
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -4,6 +4,7 @@ var HANDS_DEFAULTS = {
4
4
  enabled: false,
5
5
  actuator: "auto",
6
6
  eyesPort: 17898,
7
+ handPort: 0,
7
8
  sensePort: 17899,
8
9
  rootCommand: "su",
9
10
  shellCommand: "",
@@ -82,6 +83,14 @@ var HANDS_CONFIG_GROUP = {
82
83
  description: "\u622A\u5C4F\u3001\u8BFB\u5B57\u548C\u624B\u52BF\u7AEF\u70B9\u90FD\u5728\u8FD9\u4E2A\u53E3\u4E0A\uFF0C\u968F\u5305\u7684\u65E0\u969C\u788D\u670D\u52A1\u7528 17898\u3002",
83
84
  "x-hot": false
84
85
  },
86
+ [`${K}.handPort`]: {
87
+ type: "integer",
88
+ title: "\u624B\u52BF\u7AEF\u53E3",
89
+ minimum: 0,
90
+ maximum: 65535,
91
+ description: "\u72EC\u7ACB\u624B\u52BF App\uFF08\u624B\uFF09\u7684\u7AEF\u53E3\uFF0C\u9ED8\u8BA4 17897\u3002\u586B 0 \u8868\u793A\u548C\u773C\u775B\u540C\u7AEF\u53E3\u2014\u2014\u90A3\u662F\u628A /hand/* \u8865\u8FDB Coopanin \u65E0\u969C\u788D\u670D\u52A1\u7684\u88C5\u6CD5\u3002",
92
+ "x-hot": false
93
+ },
85
94
  [`${K}.sensePort`]: {
86
95
  type: "integer",
87
96
  title: "\u611F\u89C9\u7AEF\u53E3",
@@ -469,11 +478,18 @@ var Hands = class {
469
478
  this.eyes = new EyesClient(() => this.port(this.cfg().eyesPort));
470
479
  this.rootActuator = new RootActuator(() => this.cfg().rootCommand, () => this.log);
471
480
  this.shellActuator = new ShellActuator(() => this.cfg().shellCommand, () => this.log);
472
- this.eyesActuator = new EyesActuator(() => this.port(this.cfg().eyesPort), () => this.readToken(), () => this.log);
481
+ this.eyesActuator = new EyesActuator(() => this.handPort(), () => this.readToken(), () => this.log);
473
482
  }
474
- port(value) {
483
+ port(value, fallback = 17898) {
475
484
  const n = Math.round(Number(value));
476
- return Number.isFinite(n) && n >= 1024 && n <= 65535 ? n : 17898;
485
+ return Number.isFinite(n) && n >= 1024 && n <= 65535 ? n : fallback;
486
+ }
487
+ /** 手势端点在哪:handPort 为 0 时和眼睛同一个口。 */
488
+ handPort() {
489
+ const cfg = this.cfg();
490
+ const explicit = Math.round(Number(cfg.handPort));
491
+ if (Number.isFinite(explicit) && explicit >= 1024 && explicit <= 65535) return explicit;
492
+ return this.port(cfg.eyesPort);
477
493
  }
478
494
  /** 世界挂上以后把日志接进来;探测和动作都写在这里。 */
479
495
  attachLog(log) {
@@ -558,21 +574,18 @@ var Hands = class {
558
574
  if (!picked) throw new HandError(`\u624B\u73B0\u5728\u52A8\u4E0D\u4E86\uFF1A${state.detail}`);
559
575
  return picked;
560
576
  }
561
- /** 屏幕尺寸;拿不到就不校验边界(root 通道下常见)。 */
577
+ /**
578
+ * 屏幕尺寸。只认手势端点报的(眼睛报的是上一次截图的尺寸,常被 max= 缩过,拿来判越界会误拒)。
579
+ * 拿不到就不校验边界。
580
+ */
562
581
  async screenSize() {
563
582
  if (this.screen && Date.now() - this.lastScreenAt < 6e4) return this.screen;
564
- const health = await this.eyes.health();
583
+ const health = await getJson(this.handPort(), "/health", 4e3);
565
584
  if (health?.ok && health.frameWidth && health.frameHeight) {
566
585
  this.screen = { w: health.frameWidth, h: health.frameHeight };
567
586
  this.lastScreenAt = Date.now();
568
587
  return this.screen;
569
588
  }
570
- const frame = await this.eyes.frame(240, 30);
571
- if (frame && frame.width > 0 && frame.height > 0) {
572
- this.screen = { w: frame.width, h: frame.height };
573
- this.lastScreenAt = Date.now();
574
- return this.screen;
575
- }
576
589
  return null;
577
590
  }
578
591
  prune() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cortico-world-hands",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "description": "Cortico World: hands for the desktop pet — looks at the phone screen, then taps, swipes, types and presses keys through whatever actuator the device actually has",
6
6
  "license": "MIT",