cortico-world-hands 0.8.0 → 0.10.0

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 +82 -0
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1063,6 +1063,30 @@ var Hands = class {
1063
1063
  }
1064
1064
  return { ok: res.status === 200 && body.ok !== false, detail: flat(body.detail || body.error || "", 80) };
1065
1065
  }
1066
+ /** 唤醒屏幕(用 Shizuku 的 input keyevent 224)。 */
1067
+ async wakeScreen() {
1068
+ const cfg = this.cfg();
1069
+ const credential = this.readToken();
1070
+ const t = credential ? `t=${encodeURIComponent(credential)}` : "";
1071
+ const res = await post(this.port(cfg.handPort), `/hand/wake?${t}`, "", 15e3);
1072
+ return res.body.toString("utf8");
1073
+ }
1074
+ /** 解锁锁屏:密码由主人放在本机文件里,这里只触发,不接触密码。 */
1075
+ async unlockScreen() {
1076
+ const cfg = this.cfg();
1077
+ const credential = this.readToken();
1078
+ const t = credential ? `t=${encodeURIComponent(credential)}` : "";
1079
+ const res = await post(this.port(cfg.handPort), `/hand/unlock?${t}`, "", 3e4);
1080
+ return res.body.toString("utf8");
1081
+ }
1082
+ /** 息屏(可选,用来自己测唤醒)。 */
1083
+ async sleepScreen() {
1084
+ const cfg = this.cfg();
1085
+ const credential = this.readToken();
1086
+ const t = credential ? `t=${encodeURIComponent(credential)}` : "";
1087
+ const res = await post(this.port(cfg.handPort), `/hand/sleep?${t}`, "", 15e3);
1088
+ return res.body.toString("utf8");
1089
+ }
1066
1090
  /** 画板:新开一张。 */
1067
1091
  async canvasNew(w = 512, h = 512, bg = "transparent") {
1068
1092
  const cfg = this.cfg();
@@ -1442,6 +1466,24 @@ var HANDS_TOOL_DECLS = [
1442
1466
  description: "\u770B\u624B\u81EA\u5DF1\u7684\u72B6\u6001\uFF1A\u8D70\u54EA\u6761\u901A\u9053\u3001\u901A\u4E0D\u901A\u3001\u8FD9\u4E00\u5206\u949F\u52A8\u4E86\u51E0\u4E2A\u52A8\u4F5C\u3001\u521A\u624D\u90A3\u4E00\u4E0B\u6210\u4E86\u6CA1\u6709\u3002\u5BF9\u65B9\u95EE\u300C\u624B\u80FD\u7528\u5417\u300D\u300C\u4F60\u521A\u624D\u70B9\u4E86\u4EC0\u4E48\u300D\u65F6\u7528\u5B83\u3002",
1443
1467
  parameters: { type: "object", properties: {}, required: [] }
1444
1468
  },
1469
+ {
1470
+ name: "screen_wake",
1471
+ tags: ["act"],
1472
+ description: "\u70B9\u4EAE\u5C4F\u5E55\uFF1A\u5C4F\u5E55\u9ED1\u7740\u4E5F\u80FD\u5524\u9192\uFF08\u7528 Shizuku \u7684\u7CFB\u7EDF\u6309\u952E\uFF0Croot/Shizuku \u4EFB\u4E00\u901A\u9053\uFF09\u3002\u4E3B\u4EBA\u8BF4\u300C\u4EAE\u4E00\u4E0B\u5C4F\u300D\u300C\u5E2E\u6211\u628A\u5C4F\u5E55\u70B9\u4EAE\u300D\u65F6\u7528\u5B83\uFF1B\u5931\u8D25\u4F1A\u8FD4\u56DE\u539F\u56E0\u3002",
1473
+ parameters: { type: "object", properties: {} }
1474
+ },
1475
+ {
1476
+ name: "screen_unlock",
1477
+ tags: ["act"],
1478
+ description: "\u89E3\u9501\u9501\u5C4F\uFF1A\u53EA\u5728\u5C4F\u5E55\u9501\u7740\u65F6\u7528\u3002\u5BC6\u7801\u7531\u4E3B\u4EBA\u81EA\u5DF1\u586B\u5728\u672C\u673A\u6587\u4EF6\u91CC\uFF08/sdcard/Download/DSHA/\u9501\u5C4F\u5BC6\u7801.txt\uFF09\uFF0C\u8FD9\u4E2A\u5DE5\u5177\u53EA\u8D1F\u8D23\u89E6\u53D1\uFF0C\u8BFB\u4E0D\u5230\u5BC6\u7801\u4F1A\u544A\u8BC9\u4F60\u6587\u4EF6\u5728\u54EA\u3002\u5931\u8D25\u4F1A\u8FD4\u56DE\u539F\u56E0\u3002",
1479
+ parameters: { type: "object", properties: {} }
1480
+ },
1481
+ {
1482
+ name: "screen_sleep",
1483
+ tags: ["act"],
1484
+ description: "\u628A\u5C4F\u5E55\u5173\u6389\uFF08\u606F\u5C4F\uFF09\u3002\u4E3B\u4EBA\u8BF4\u8981\u5173\u5C4F\u3001\u6216\u8005\u4F60\u60F3\u81EA\u5DF1\u6D4B\u4E00\u4E0B\u5524\u9192\u662F\u5426\u7BA1\u7528\u65F6\u7528\u5B83\u3002",
1485
+ parameters: { type: "object", properties: {} }
1486
+ },
1445
1487
  {
1446
1488
  name: "canvas_new",
1447
1489
  tags: ["act"],
@@ -1901,6 +1943,12 @@ ${lines.join("\n")}
1901
1943
  return await this.diaryRead(args);
1902
1944
  case "skin_install":
1903
1945
  return await this.skinInstall(args);
1946
+ case "screen_wake":
1947
+ return await this.screenWake();
1948
+ case "screen_unlock":
1949
+ return await this.screenUnlock();
1950
+ case "screen_sleep":
1951
+ return await this.screenSleep();
1904
1952
  case "canvas_new":
1905
1953
  return await this.canvasNew(args);
1906
1954
  case "canvas_stroke":
@@ -2025,6 +2073,40 @@ ${lines.join("\n")}
2025
2073
  }
2026
2074
  return `\u8BB0\u7262\u4E86\uFF1A\u300C${key}\u300D\u2192 ${value}${cloud}`;
2027
2075
  }
2076
+ /** 点亮屏幕:成功说清楚,失败给原因。 */
2077
+ async screenWake() {
2078
+ const raw = await this.hands.wakeScreen();
2079
+ try {
2080
+ const r = JSON.parse(raw);
2081
+ if (r.ok) {
2082
+ return r.litBefore ? "\u5C4F\u5E55\u672C\u6765\u5C31\u662F\u4EAE\u7684\u3002" : "\u5C4F\u5E55\u70B9\u4EAE\u4E86\u3002";
2083
+ }
2084
+ return failed(r.error || "\u6CA1\u70B9\u4EAE\uFF0C\u539F\u56E0\u4E0D\u660E");
2085
+ } catch {
2086
+ return failed(raw.slice(0, 120));
2087
+ }
2088
+ }
2089
+ /** 解锁:成功/没锁/失败都给人话。 */
2090
+ async screenUnlock() {
2091
+ const raw = await this.hands.unlockScreen();
2092
+ try {
2093
+ const r = JSON.parse(raw);
2094
+ if (r.ok) return r.detail || "\u89E3\u5F00\u4E86";
2095
+ if (r.needFile) return failed(`${r.error}\uFF08\u6587\u4EF6\uFF1A${r.file}\uFF09`);
2096
+ return failed(r.error || "\u6CA1\u89E3\u5F00\uFF0C\u539F\u56E0\u4E0D\u660E");
2097
+ } catch {
2098
+ return failed(raw.slice(0, 120));
2099
+ }
2100
+ }
2101
+ async screenSleep() {
2102
+ const raw = await this.hands.sleepScreen();
2103
+ try {
2104
+ const r = JSON.parse(raw);
2105
+ return r.ok ? "\u5C4F\u5E55\u5173\u6389\u4E86\u3002" : failed(r.error || "\u6CA1\u5173\u6389\uFF0C\u539F\u56E0\u4E0D\u660E");
2106
+ } catch {
2107
+ return failed(raw.slice(0, 120));
2108
+ }
2109
+ }
2028
2110
  async canvasNew(args) {
2029
2111
  const w = args.w === void 0 ? 512 : Math.max(64, Math.min(2048, Math.round(Number(args.w))));
2030
2112
  const h = args.h === void 0 ? 512 : Math.max(64, Math.min(2048, Math.round(Number(args.h))));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cortico-world-hands",
3
- "version": "0.8.0",
3
+ "version": "0.10.0",
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",