cortico-world-hands 0.1.2 → 0.1.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/dist/index.js +105 -0
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -670,6 +670,39 @@ 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, kind) {
675
+ const cfg = this.cfg();
676
+ const token = cfg.handToken ? `&t=${encodeURIComponent(cfg.handToken)}` : "";
677
+ const k = kind ? `&kind=${encodeURIComponent(kind)}` : "";
678
+ const path = `/hand/note?text=${encodeURIComponent(text)}${k}${token}`;
679
+ const res = await get(this.port(cfg.handPort), path, ACTION_TIMEOUT_MS);
680
+ let body = {};
681
+ try {
682
+ body = JSON.parse(res.body.toString("utf8"));
683
+ } catch {
684
+ }
685
+ return { ok: res.status === 200 && body.ok !== false, detail: flat(body.detail || body.error || "", 80) };
686
+ }
687
+ /** 留言板:全部留言。 */
688
+ async noteList() {
689
+ const cfg = this.cfg();
690
+ const token = cfg.handToken ? `?t=${encodeURIComponent(cfg.handToken)}` : "";
691
+ const res = await get(this.port(cfg.handPort), `/hand/notes${token}`, ACTION_TIMEOUT_MS);
692
+ try {
693
+ const body = JSON.parse(res.body.toString("utf8"));
694
+ return Array.isArray(body.notes) ? body.notes : [];
695
+ } catch {
696
+ return [];
697
+ }
698
+ }
699
+ /** 留言板:划掉一条。 */
700
+ async noteDone(id) {
701
+ const cfg = this.cfg();
702
+ const token = cfg.handToken ? `&t=${encodeURIComponent(cfg.handToken)}` : "";
703
+ const res = await get(this.port(cfg.handPort), `/hand/note/done?id=${encodeURIComponent(id)}${token}`, ACTION_TIMEOUT_MS);
704
+ return res.status === 200;
705
+ }
673
706
  /** 一屏屏翻着找文字(只查不点)。 */
674
707
  async findItem(text, opts = {}) {
675
708
  const cfg = this.cfg();
@@ -915,6 +948,47 @@ var HANDS_TOOL_DECLS = [
915
948
  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
949
  parameters: { type: "object", properties: {}, required: [] }
917
950
  },
951
+ {
952
+ name: "note_add",
953
+ tags: ["act"],
954
+ 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",
955
+ parameters: {
956
+ type: "object",
957
+ properties: {
958
+ text: { type: "string", description: "\u8981\u5199\u4E0B\u7684\u5185\u5BB9\u3002" },
959
+ kind: {
960
+ type: "string",
961
+ enum: ["todo", "say", "think"],
962
+ description: "\u5206\u7C7B\uFF1Atodo=\u5F85\u529E\uFF08\u8981\u505A\u7684\u4E8B\uFF0C\u4F1A\u88AB\u6BCF\u5929\u63D0\u9192\uFF09\u3001say=\u60F3\u5BF9\u4E3B\u4EBA\u8BF4\u7684\u8BDD\u3001think=\u788E\u788E\u5FF5\u3002\u9ED8\u8BA4 todo\u3002"
963
+ }
964
+ },
965
+ required: ["text"]
966
+ }
967
+ },
968
+ {
969
+ name: "note_list",
970
+ tags: ["read"],
971
+ 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",
972
+ parameters: {
973
+ type: "object",
974
+ properties: {
975
+ kind: { type: "string", enum: ["todo", "say", "think"], description: "\u53EA\u770B\u67D0\u4E00\u7C7B\uFF08\u53EF\u7701\u7565\uFF09\u3002" }
976
+ },
977
+ required: []
978
+ }
979
+ },
980
+ {
981
+ name: "note_done",
982
+ tags: ["act"],
983
+ 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",
984
+ parameters: {
985
+ type: "object",
986
+ properties: {
987
+ id: { type: "string", description: "\u7559\u8A00\u7684 id\uFF08note_list \u91CC\u80FD\u770B\u5230\uFF09\u3002" }
988
+ },
989
+ required: ["id"]
990
+ }
991
+ },
918
992
  {
919
993
  name: "hand_stop",
920
994
  tags: ["flow"],
@@ -1001,6 +1075,12 @@ var HandsWorld = class {
1001
1075
  return await this.key(args);
1002
1076
  case "hand_status":
1003
1077
  return this.statusText();
1078
+ case "note_add":
1079
+ return await this.noteAdd(args);
1080
+ case "note_list":
1081
+ return await this.noteList(args);
1082
+ case "note_done":
1083
+ return await this.noteDone(args);
1004
1084
  case "hand_stop":
1005
1085
  return this.stopHands();
1006
1086
  default:
@@ -1031,6 +1111,31 @@ var HandsWorld = class {
1031
1111
  return { text: report.text, ...blobs.length ? { blobs } : {} };
1032
1112
  }
1033
1113
  /** 给文字就先在屏幕上找,找到唯一一处才点;给坐标就直接点。 */
1114
+ async noteAdd(args) {
1115
+ const text = typeof args.text === "string" ? args.text.trim() : "";
1116
+ if (!text) return failed("\u8981\u5199\u4EC0\u4E48\uFF1F\u7ED9 text\u3002");
1117
+ const kind = typeof args.kind === "string" ? args.kind : void 0;
1118
+ const result = await this.hands.noteAdd(text, kind);
1119
+ if (!result.ok) return failed(`\u6CA1\u5199\u8FDB\u7559\u8A00\u677F\uFF1A${result.detail || "\u624B\u6CA1\u54CD\u5E94"}`);
1120
+ return `\u5199\u5728\u7559\u8A00\u677F\u4E0A\u4E86\uFF1A\u300C${text}\u300D`;
1121
+ }
1122
+ async noteList(args = {}) {
1123
+ const all = await this.hands.noteList();
1124
+ const kind = typeof args.kind === "string" ? args.kind : "";
1125
+ const notes = kind ? all.filter((n) => (n.kind || "todo") === kind) : all;
1126
+ if (notes.length === 0) return "\u7559\u8A00\u677F\u662F\u7A7A\u7684\uFF1B\u8981\u4E0D\u518D\u8BB0\u70B9\u4EC0\u4E48\u3002";
1127
+ const open = notes.filter((n) => !n.done);
1128
+ const label = (k) => k === "say" ? "\u60F3\u8BF4\u7684" : k === "think" ? "\u788E\u788E\u5FF5" : "\u5F85\u529E";
1129
+ const lines = open.map((n) => `- [${n.id}] ${label(n.kind || "todo")} ${n.ts} ${n.text}`).join("\n");
1130
+ return `\u7559\u8A00\u677F\u4E0A\u6709 ${notes.length} \u6761\uFF0C\u672A\u5B8C ${open.length} \u6761\uFF1A
1131
+ ${lines || "\uFF08\u90FD\u5212\u6389\u4E86\uFF09"}`;
1132
+ }
1133
+ async noteDone(args) {
1134
+ const id = typeof args.id === "string" ? args.id.trim() : "";
1135
+ if (!id) return failed("\u8981\u5212\u6389\u54EA\u6761\uFF1F\u7ED9 id\uFF08note_list \u91CC\u80FD\u770B\u5230\uFF09\u3002");
1136
+ const ok = await this.hands.noteDone(id);
1137
+ return ok ? `\u5212\u6389\u4E86 ${id}\u3002` : failed(`\u6CA1\u627E\u5230 id=${id} \u7684\u7559\u8A00\u3002`);
1138
+ }
1034
1139
  async pinch(args) {
1035
1140
  const scale = Number(args.scale);
1036
1141
  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.4",
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",