cortico-world-hands 0.1.2 → 0.1.3

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 +89 -0
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -670,6 +670,38 @@ var Hands = class {
670
670
  const ms = milliseconds(opts.ms, 900);
671
671
  return this.perform({ kind: "drag", x1: a, y1: b, x2: c, y2: d, ms });
672
672
  }
673
+ /** 留言板:写一条。 */
674
+ async noteAdd(text) {
675
+ const cfg = this.cfg();
676
+ const token = cfg.handToken ? `&t=${encodeURIComponent(cfg.handToken)}` : "";
677
+ const path = `/hand/note?text=${encodeURIComponent(text)}${token}`;
678
+ const res = await get(this.port(cfg.handPort), path, ACTION_TIMEOUT_MS);
679
+ let body = {};
680
+ try {
681
+ body = JSON.parse(res.body.toString("utf8"));
682
+ } catch {
683
+ }
684
+ return { ok: res.status === 200 && body.ok !== false, detail: flat(body.detail || body.error || "", 80) };
685
+ }
686
+ /** 留言板:全部留言。 */
687
+ async noteList() {
688
+ const cfg = this.cfg();
689
+ const token = cfg.handToken ? `?t=${encodeURIComponent(cfg.handToken)}` : "";
690
+ const res = await get(this.port(cfg.handPort), `/hand/notes${token}`, ACTION_TIMEOUT_MS);
691
+ try {
692
+ const body = JSON.parse(res.body.toString("utf8"));
693
+ return Array.isArray(body.notes) ? body.notes : [];
694
+ } catch {
695
+ return [];
696
+ }
697
+ }
698
+ /** 留言板:划掉一条。 */
699
+ async noteDone(id) {
700
+ const cfg = this.cfg();
701
+ const token = cfg.handToken ? `&t=${encodeURIComponent(cfg.handToken)}` : "";
702
+ const res = await get(this.port(cfg.handPort), `/hand/note/done?id=${encodeURIComponent(id)}${token}`, ACTION_TIMEOUT_MS);
703
+ return res.status === 200;
704
+ }
673
705
  /** 一屏屏翻着找文字(只查不点)。 */
674
706
  async findItem(text, opts = {}) {
675
707
  const cfg = this.cfg();
@@ -915,6 +947,36 @@ var HANDS_TOOL_DECLS = [
915
947
  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",
916
948
  parameters: { type: "object", properties: {}, required: [] }
917
949
  },
950
+ {
951
+ name: "note_add",
952
+ tags: ["act"],
953
+ description: "\u5728\u7559\u8A00\u677F\u4E0A\u5199\u4E00\u6761\uFF1A\u60F3\u8BF4\u7684\u8BDD\u3001\u60F3\u8BB0\u7684\u4E8B\u3001\u5F85\u529E\u3001\u7ED9\u81EA\u5DF1\u7684\u63D0\u9192\u3002\u60F3\u8BB0\u5C31\u8BB0\uFF0C\u4E0D\u7528\u7B49\u5BF9\u65B9\u540C\u610F\uFF1B\u4E00\u6761\u522B\u592A\u957F\uFF08\u4E00\u53E5\u8BDD\u6700\u597D\uFF09\u3002",
954
+ parameters: {
955
+ type: "object",
956
+ properties: {
957
+ text: { type: "string", description: "\u8981\u5199\u4E0B\u7684\u5185\u5BB9\u3002" }
958
+ },
959
+ required: ["text"]
960
+ }
961
+ },
962
+ {
963
+ name: "note_list",
964
+ tags: ["read"],
965
+ description: "\u770B\u7559\u8A00\u677F\uFF1A\u6709\u54EA\u4E9B\u6CA1\u5212\u6389\u7684\u3001\u90FD\u5199\u4E86\u4EC0\u4E48\u3002\u5BF9\u65B9\u95EE\u300C\u4F60\u8BB0\u4E86\u4EC0\u4E48\u300D\u300C\u7559\u8A00\u677F\u4E0A\u6709\u5565\u300D\u65F6\u7528\u5B83\u3002",
966
+ parameters: { type: "object", properties: {}, required: [] }
967
+ },
968
+ {
969
+ name: "note_done",
970
+ tags: ["act"],
971
+ description: "\u628A\u7559\u8A00\u677F\u4E0A\u67D0\u4E00\u6761\u5212\u6389\uFF08\u505A\u5B8C\u4E86/\u4E0D\u7528\u4E86\uFF09\u3002\u5148\u7528 note_list \u62FF\u5230 id\u3002",
972
+ parameters: {
973
+ type: "object",
974
+ properties: {
975
+ id: { type: "string", description: "\u7559\u8A00\u7684 id\uFF08note_list \u91CC\u80FD\u770B\u5230\uFF09\u3002" }
976
+ },
977
+ required: ["id"]
978
+ }
979
+ },
918
980
  {
919
981
  name: "hand_stop",
920
982
  tags: ["flow"],
@@ -1001,6 +1063,12 @@ var HandsWorld = class {
1001
1063
  return await this.key(args);
1002
1064
  case "hand_status":
1003
1065
  return this.statusText();
1066
+ case "note_add":
1067
+ return await this.noteAdd(args);
1068
+ case "note_list":
1069
+ return await this.noteList();
1070
+ case "note_done":
1071
+ return await this.noteDone(args);
1004
1072
  case "hand_stop":
1005
1073
  return this.stopHands();
1006
1074
  default:
@@ -1031,6 +1099,27 @@ var HandsWorld = class {
1031
1099
  return { text: report.text, ...blobs.length ? { blobs } : {} };
1032
1100
  }
1033
1101
  /** 给文字就先在屏幕上找,找到唯一一处才点;给坐标就直接点。 */
1102
+ async noteAdd(args) {
1103
+ const text = typeof args.text === "string" ? args.text.trim() : "";
1104
+ if (!text) return failed("\u8981\u5199\u4EC0\u4E48\uFF1F\u7ED9 text\u3002");
1105
+ const result = await this.hands.noteAdd(text);
1106
+ if (!result.ok) return failed(`\u6CA1\u5199\u8FDB\u7559\u8A00\u677F\uFF1A${result.detail || "\u624B\u6CA1\u54CD\u5E94"}`);
1107
+ return `\u5199\u5728\u7559\u8A00\u677F\u4E0A\u4E86\uFF1A\u300C${text}\u300D`;
1108
+ }
1109
+ async noteList() {
1110
+ const notes = await this.hands.noteList();
1111
+ if (notes.length === 0) return "\u7559\u8A00\u677F\u662F\u7A7A\u7684\u3002";
1112
+ const open = notes.filter((n) => !n.done);
1113
+ const lines = open.map((n) => `- [${n.id}] ${n.ts} ${n.text}`).join("\n");
1114
+ return `\u7559\u8A00\u677F\u4E0A\u6709 ${notes.length} \u6761\uFF0C\u672A\u5B8C ${open.length} \u6761\uFF1A
1115
+ ${lines || "\uFF08\u90FD\u5212\u6389\u4E86\uFF09"}`;
1116
+ }
1117
+ async noteDone(args) {
1118
+ const id = typeof args.id === "string" ? args.id.trim() : "";
1119
+ if (!id) return failed("\u8981\u5212\u6389\u54EA\u6761\uFF1F\u7ED9 id\uFF08note_list \u91CC\u80FD\u770B\u5230\uFF09\u3002");
1120
+ const ok = await this.hands.noteDone(id);
1121
+ return ok ? `\u5212\u6389\u4E86 ${id}\u3002` : failed(`\u6CA1\u627E\u5230 id=${id} \u7684\u7559\u8A00\u3002`);
1122
+ }
1034
1123
  async pinch(args) {
1035
1124
  const scale = Number(args.scale);
1036
1125
  if (!Number.isFinite(scale) || scale <= 0) return failed("scale \u8981\u662F\u6B63\u6570\uFF0C\u6BD4\u5982 1.5 \u653E\u5927\u30010.6 \u7F29\u5C0F\u3002");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cortico-world-hands",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
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",