cortico-world-hands 0.20.12 → 0.20.14

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 +26 -7
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -132,6 +132,18 @@ var HANDS_CONFIG_GROUP = {
132
132
  description: "\u586B\u4E86\u5C31\u5728\u4E16\u754C\u542F\u52A8\u65F6\u81EA\u52A8\u88C5\uFF08\u672C\u5730 HTTP \u4E5F\u884C\uFF0C\u6BD4\u5982 http://127.0.0.1:18080\uFF09\u3002",
133
133
  "x-hot": true
134
134
  },
135
+ [`${K}.mediaKeepDays`]: {
136
+ type: "number",
137
+ title: "\u9644\u4EF6\u4FDD\u7559\u51E0\u5929",
138
+ description: "\u622A\u56FE\u3001\u56FE\u7247\u8FD9\u4E9B\u9644\u4EF6\u5728\u8FD9\u4E2A\u76EE\u5F55\u91CC\u7559\u51E0\u5929\uFF0C\u8D85\u8FC7\u5C31\u5220\uFF08\u9ED8\u8BA4 1 \u5929\uFF09\u3002",
139
+ "x-hot": true
140
+ },
141
+ [`${K}.mediaCleanHour`]: {
142
+ type: "integer",
143
+ title: "\u6BCF\u5929\u51E0\u70B9\u6E05\u9644\u4EF6",
144
+ description: "\u7559\u7A7A/0 \u8868\u793A\u6BCF 6 \u5C0F\u65F6\u68C0\u67E5\u4E00\u6B21\uFF0C\u8D85\u671F\u5C31\u6E05\u3002",
145
+ "x-hot": true
146
+ },
135
147
  [`${K}.qqSelf`]: {
136
148
  type: "string",
137
149
  title: "\u5979\u81EA\u5DF1\u7684 QQ \u540D\u5B57\uFF08\u7FA4\u91CC @ \u8FD9\u4E2A\u624D\u53EB\u5979\uFF09",
@@ -2493,12 +2505,12 @@ ${lines.join("\n")}
2493
2505
  const keepDays = cfg.mediaKeepDays ?? 1;
2494
2506
  const hour = cfg.mediaCleanHour ?? 4;
2495
2507
  const now = /* @__PURE__ */ new Date();
2496
- if (now.getHours() !== hour) return;
2497
- const day = now.toISOString().slice(0, 10);
2498
- if (this.lastMediaDay === day) return;
2508
+ if (hour >= 0 && now.getHours() !== hour) return;
2509
+ const slot = Math.floor(now.getTime() / (6 * 3600 * 1e3));
2510
+ if (this.lastMediaDay === slot) return;
2499
2511
  const dir = this.mediaDir();
2500
2512
  if (!dir) return;
2501
- this.lastMediaDay = day;
2513
+ this.lastMediaDay = slot;
2502
2514
  const r = cleanMedia(dir, { keepDays, maxMB: cfg.mediaMaxMB ?? 0 });
2503
2515
  this.log?.info(`\u9644\u4EF6\u6E05\u7406\uFF1A\u5220 ${r.removed} \u4E2A\uFF0C\u91CA\u653E ${r.freedMB}MB\uFF0C\u5269 ${r.kept} \u4E2A`);
2504
2516
  }
@@ -2673,7 +2685,7 @@ ${text.slice(0, 2200)}`;
2673
2685
  if (f) {
2674
2686
  return {
2675
2687
  text: `\u300C${hit.text}\u300D\u5B57\u592A\u5C0F\uFF08\u9AD8 ${h}px\uFF09\uFF0C\u6211\u628A\u8FD9\u5757\u653E\u5927\u4E86`,
2676
- blobs: [{ bytes: f.bytes, mime: "image/jpeg", name: "zoom.jpg", fallbackText: "\uFF08\u8FD9\u4E00\u5757\u7684\u653E\u5927\u56FE\uFF09" }]
2688
+ blobs: this.looksLikeImage(f.bytes) ? [{ bytes: f.bytes, mime: "image/jpeg", name: "zoom.jpg", fallbackText: "\uFF08\u8FD9\u4E00\u5757\u7684\u653E\u5927\u56FE\uFF09" }] : []
2677
2689
  };
2678
2690
  }
2679
2691
  }
@@ -2687,7 +2699,7 @@ ${text.slice(0, 2200)}`;
2687
2699
  if (!f) return failed("\u8FD9\u4E00\u5757\u6CA1\u622A\u5230\uFF08\u5750\u6807\u53EF\u80FD\u8D85\u51FA\u5C4F\u5E55\uFF09");
2688
2700
  return {
2689
2701
  text: `\u653E\u5927\u770B @(${x},${y}) ${w}\xD7${h}`,
2690
- blobs: [{ bytes: f.bytes, mime: "image/jpeg", name: "zoom.jpg", fallbackText: "\uFF08\u8FD9\u662F\u4ED6\u6307\u5B9A\u90A3\u4E00\u5757\u653E\u5927\u540E\u7684\u622A\u56FE\uFF09" }]
2702
+ blobs: this.looksLikeImage(f.bytes) ? [{ bytes: f.bytes, mime: "image/jpeg", name: "zoom.jpg", fallbackText: "\uFF08\u8FD9\u662F\u4ED6\u6307\u5B9A\u90A3\u4E00\u5757\u653E\u5927\u540E\u7684\u622A\u56FE\uFF09" }] : []
2691
2703
  };
2692
2704
  }
2693
2705
  case "hand_see":
@@ -2880,10 +2892,17 @@ ${text.slice(0, 2200)}`;
2880
2892
  async see() {
2881
2893
  return await this.hands.look("text").then((r) => r.text);
2882
2894
  }
2895
+ /** 只认真正的 JPEG/PNG,防止坏图进上下文把整轮 400 掉。 */
2896
+ looksLikeImage(bytes) {
2897
+ if (!bytes || bytes.length < 2e3) return false;
2898
+ const jpg = bytes[0] === 255 && bytes[1] === 216;
2899
+ const png = bytes[0] === 137 && bytes[1] === 80 && bytes[2] === 78 && bytes[3] === 71;
2900
+ return jpg || png;
2901
+ }
2883
2902
  async look(args) {
2884
2903
  const detail = args.detail === "screen" || args.detail === "text" ? args.detail : "both";
2885
2904
  const report = await this.hands.look(detail);
2886
- const blobs = report.blob ? [report.blob] : [];
2905
+ const blobs = report.blob && this.looksLikeImage(report.blob.bytes) ? [report.blob] : [];
2887
2906
  return { text: report.text, ...blobs.length ? { blobs } : {} };
2888
2907
  }
2889
2908
  /** 给文字就先在屏幕上找,找到唯一一处才点;给坐标就直接点。 */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cortico-world-hands",
3
- "version": "0.20.12",
3
+ "version": "0.20.14",
4
4
  "type": "module",
5
5
  "description": "Cortico World: hands for the desktop pet — looks at the phone screen, then taps, swipes, pinches, drags, types and presses keys through whatever actuator the device actually has",
6
6
  "license": "MIT",