cortico-world-hands 0.20.39 → 0.20.41
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.
- package/dist/index.js +88 -9
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1465,7 +1465,7 @@ var Hands = class {
|
|
|
1465
1465
|
return res.body.toString("utf8");
|
|
1466
1466
|
}
|
|
1467
1467
|
/** 画板:画一笔。 */
|
|
1468
|
-
async canvasStroke(points, color = "#111111", width = 4) {
|
|
1468
|
+
async canvasStroke(points, color = "#111111", width = 4, tool = "pen") {
|
|
1469
1469
|
const cfg = this.cfg();
|
|
1470
1470
|
const credential = this.readToken();
|
|
1471
1471
|
const t = credential ? `t=${encodeURIComponent(credential)}` : "";
|
|
@@ -1473,6 +1473,22 @@ var Hands = class {
|
|
|
1473
1473
|
const res = await post(this.port(cfg.handPort), `/canvas/stroke?${t}`, body, ACTION_TIMEOUT_MS);
|
|
1474
1474
|
return res.body.toString("utf8");
|
|
1475
1475
|
}
|
|
1476
|
+
/** 画板:油漆桶填充。 */
|
|
1477
|
+
async canvasFill(x, y, color = "#6BFFB0") {
|
|
1478
|
+
const cfg = this.cfg();
|
|
1479
|
+
const t = cfg.token ? `t=${encodeURIComponent(cfg.token)}` : "";
|
|
1480
|
+
const body = JSON.stringify({ x, y, color });
|
|
1481
|
+
const res = await post(this.port(cfg.handPort), `/canvas/fill?${t}`, body, ACTION_TIMEOUT_MS);
|
|
1482
|
+
return res.text;
|
|
1483
|
+
}
|
|
1484
|
+
/** 画板:写文字(支持中文)。 */
|
|
1485
|
+
async canvasText(text, x = 24, y = 72, size = 32, color = "#111111") {
|
|
1486
|
+
const cfg = this.cfg();
|
|
1487
|
+
const t = cfg.token ? `t=${encodeURIComponent(cfg.token)}` : "";
|
|
1488
|
+
const body = JSON.stringify({ text, x, y, size, color });
|
|
1489
|
+
const res = await post(this.port(cfg.handPort), `/canvas/text?${t}`, body, ACTION_TIMEOUT_MS);
|
|
1490
|
+
return res.text;
|
|
1491
|
+
}
|
|
1476
1492
|
/** 画板:撤销 / 清空 / 保存 / 列表。 */
|
|
1477
1493
|
async canvasOp(op) {
|
|
1478
1494
|
const cfg = this.cfg();
|
|
@@ -1654,7 +1670,18 @@ var Hands = class {
|
|
|
1654
1670
|
throw new HandError(`\u773C\u775B\u6CA1\u5F00\uFF1A${health?.error ?? "\u65E0\u969C\u788D\u670D\u52A1\u6CA1\u5728\u8DD1\uFF08\u7CFB\u7EDF\u8BBE\u7F6E \u2192 \u65E0\u969C\u788D\uFF09"}\u3002`);
|
|
1655
1671
|
}
|
|
1656
1672
|
const state = await this.eyes.state(this.port(cfg.sensePort));
|
|
1657
|
-
|
|
1673
|
+
let uiPkg = "";
|
|
1674
|
+
let uiItems = [];
|
|
1675
|
+
try {
|
|
1676
|
+
const u = await this.eyes.ui();
|
|
1677
|
+
if (u && u.ok) {
|
|
1678
|
+
uiPkg = (u.pkg || "").trim();
|
|
1679
|
+
uiItems = u.items || [];
|
|
1680
|
+
}
|
|
1681
|
+
} catch {
|
|
1682
|
+
}
|
|
1683
|
+
const pkgNow = (state?.appPkg || "").trim() || uiPkg;
|
|
1684
|
+
const where = state?.appLabel && state.appPkg ? `${state.appLabel}\uFF08${state.appPkg}\uFF09` : pkgNow || "\u8FD9\u4E2A\u754C\u9762\uFF08\u8BFB\u4E0D\u5230\u5E94\u7528\u540D\uFF09";
|
|
1658
1685
|
const parts = [`\u73B0\u5728\u524D\u53F0\u662F ${where}\u3002`];
|
|
1659
1686
|
if (state) {
|
|
1660
1687
|
parts.push(`${state.screenOn ? "\u5C4F\u5E55\u4EAE\u7740" : "\u5C4F\u5E55\u9ED1\u7740"}\u3001${state.locked ? "\u9501\u7740" : "\u6CA1\u9501"}${typeof state.battery === "number" ? `\u3001\u7535\u91CF ${state.battery}%` : ""}\u3002`);
|
|
@@ -1674,9 +1701,9 @@ var Hands = class {
|
|
|
1674
1701
|
}
|
|
1675
1702
|
}
|
|
1676
1703
|
if (detail !== "screen") {
|
|
1677
|
-
const
|
|
1678
|
-
if (
|
|
1679
|
-
const lines =
|
|
1704
|
+
const items = uiItems;
|
|
1705
|
+
if (items.length) {
|
|
1706
|
+
const lines = items.slice(0, 40).map((item) => {
|
|
1680
1707
|
const spot = item.center ? `@(${item.center.x},${item.center.y})` : "";
|
|
1681
1708
|
return `- \u300C${item.text}\u300D${spot}`;
|
|
1682
1709
|
});
|
|
@@ -1925,17 +1952,48 @@ var HANDS_TOOL_DECLS = [
|
|
|
1925
1952
|
{
|
|
1926
1953
|
name: "canvas_stroke",
|
|
1927
1954
|
tags: ["act"],
|
|
1928
|
-
description: "\u5728\u753B\u5E03\u4E0A\u753B\u4E00\u7B14\uFF1A\u7ED9\u4E00\u4E32\u5750\u6807\u70B9\u3001\u989C\u8272\u3001\u7C97\u7EC6\u3002\
|
|
1955
|
+
description: "\u5728\u753B\u5E03\u4E0A\u753B\u4E00\u7B14\uFF1A\u7ED9\u4E00\u4E32\u5750\u6807\u70B9\u3001\u989C\u8272\u3001\u7C97\u7EC6\u3002\u7EBF\u6761\u4F1A\u81EA\u52A8\u5E73\u6ED1\uFF08\u5706\u80FD\u753B\u5706\uFF09\uFF0C\u4E0D\u7528\u5BC6\u96C6\u70B9\u63CF\u3002tool=eraser \u65F6\u5F53\u6A61\u76AE\u3002",
|
|
1929
1956
|
parameters: {
|
|
1930
1957
|
type: "object",
|
|
1931
1958
|
properties: {
|
|
1932
|
-
points: { type: "array", description: "\u5750\u6807 [[x,y],[x,y],\u2026]\uFF0C\u539F\u70B9\u662F\u753B\u5E03\u5DE6\u4E0A\u89D2" },
|
|
1959
|
+
points: { type: "array", description: "\u5750\u6807 [[x,y],[x,y],\u2026]\uFF0C\u539F\u70B9\u662F\u753B\u5E03\u5DE6\u4E0A\u89D2\uFF1B\u753B\u5706\u7ED9 6\uFF5E10 \u4E2A\u70B9\u5C31\u591F" },
|
|
1933
1960
|
color: { type: "string", description: "\u989C\u8272\uFF0C#RRGGBB" },
|
|
1934
|
-
width: { type: "integer", description: "\u7B14\u753B\u7C97\u7EC6\uFF0C\u9ED8\u8BA4 4" }
|
|
1961
|
+
width: { type: "integer", description: "\u7B14\u753B\u7C97\u7EC6\uFF0C\u9ED8\u8BA4 4" },
|
|
1962
|
+
tool: { type: "string", enum: ["pen", "eraser"], description: "pen=\u753B\u7B14\uFF0Ceraser=\u6A61\u76AE" }
|
|
1935
1963
|
},
|
|
1936
1964
|
required: ["points"]
|
|
1937
1965
|
}
|
|
1938
1966
|
},
|
|
1967
|
+
{
|
|
1968
|
+
name: "canvas_fill",
|
|
1969
|
+
tags: ["act"],
|
|
1970
|
+
description: "\u6CB9\u6F06\u6876\uFF1A\u70B9\u4E00\u4E0B\u628A\u76F8\u8FDE\u7684\u540C\u8272\u533A\u57DF\u586B\u6210\u6307\u5B9A\u989C\u8272\uFF08\u7ED9 XY \u548C\u989C\u8272\uFF09\u3002",
|
|
1971
|
+
parameters: {
|
|
1972
|
+
type: "object",
|
|
1973
|
+
properties: {
|
|
1974
|
+
x: { type: "integer", description: "\u8981\u586B\u8272\u4F4D\u7F6E\u7684 x" },
|
|
1975
|
+
y: { type: "integer", description: "\u8981\u586B\u8272\u4F4D\u7F6E\u7684 y" },
|
|
1976
|
+
color: { type: "string", description: "\u989C\u8272 #RRGGBB" }
|
|
1977
|
+
},
|
|
1978
|
+
required: ["x", "y"]
|
|
1979
|
+
}
|
|
1980
|
+
},
|
|
1981
|
+
{
|
|
1982
|
+
name: "canvas_text",
|
|
1983
|
+
tags: ["act"],
|
|
1984
|
+
description: "\u5728\u753B\u5E03\u4E0A\u5199\u5B57\uFF08\u652F\u6301\u4E2D\u6587\uFF09\uFF0C\u6309\u57FA\u7EBF\u4F4D\u7F6E\u653E\u3002",
|
|
1985
|
+
parameters: {
|
|
1986
|
+
type: "object",
|
|
1987
|
+
properties: {
|
|
1988
|
+
text: { type: "string", description: "\u8981\u5199\u7684\u5B57" },
|
|
1989
|
+
x: { type: "integer", description: "\u5DE6\u4E0B\u8D77\u70B9 x\uFF0C\u9ED8\u8BA4 24" },
|
|
1990
|
+
y: { type: "integer", description: "\u57FA\u7EBF y\uFF0C\u9ED8\u8BA4 72" },
|
|
1991
|
+
size: { type: "integer", description: "\u5B57\u53F7\uFF0C\u9ED8\u8BA4 32" },
|
|
1992
|
+
color: { type: "string", description: "\u989C\u8272 #RRGGBB" }
|
|
1993
|
+
},
|
|
1994
|
+
required: ["text"]
|
|
1995
|
+
}
|
|
1996
|
+
},
|
|
1939
1997
|
{
|
|
1940
1998
|
name: "canvas_undo",
|
|
1941
1999
|
tags: ["act"],
|
|
@@ -3116,6 +3174,10 @@ ${text.slice(0, 2200)}`;
|
|
|
3116
3174
|
return await this.canvasNew(args);
|
|
3117
3175
|
case "canvas_stroke":
|
|
3118
3176
|
return await this.canvasStroke(args);
|
|
3177
|
+
case "canvas_fill":
|
|
3178
|
+
return await this.canvasFill(args);
|
|
3179
|
+
case "canvas_text":
|
|
3180
|
+
return await this.canvasText(args);
|
|
3119
3181
|
case "canvas_undo":
|
|
3120
3182
|
return await this.canvasSimple("undo");
|
|
3121
3183
|
case "canvas_clear":
|
|
@@ -3380,7 +3442,24 @@ ${text.slice(0, 2200)}`;
|
|
|
3380
3442
|
if (points.length === 0) return failed("points \u91CC\u6CA1\u6709\u5408\u6CD5\u5750\u6807\u3002");
|
|
3381
3443
|
const color = typeof args.color === "string" && /^#[0-9a-fA-F]{6}$/.test(args.color) ? args.color : "#111111";
|
|
3382
3444
|
const width = args.width === void 0 ? 4 : Math.max(1, Math.min(40, Math.round(Number(args.width))));
|
|
3383
|
-
|
|
3445
|
+
const tool = args.tool === "eraser" ? "eraser" : "pen";
|
|
3446
|
+
return await this.hands.canvasStroke(points, color, width, tool);
|
|
3447
|
+
}
|
|
3448
|
+
async canvasFill(args) {
|
|
3449
|
+
const x = Math.round(Number(args.x));
|
|
3450
|
+
const y = Math.round(Number(args.y));
|
|
3451
|
+
if (!Number.isFinite(x) || !Number.isFinite(y)) return failed("\u8981 x\u3001y\u3002");
|
|
3452
|
+
const color = typeof args.color === "string" && /^#[0-9a-fA-F]{6}$/.test(args.color) ? args.color : "#6BFFB0";
|
|
3453
|
+
return await this.hands.canvasFill(x, y, color);
|
|
3454
|
+
}
|
|
3455
|
+
async canvasText(args) {
|
|
3456
|
+
const text = typeof args.text === "string" ? args.text.trim() : "";
|
|
3457
|
+
if (!text) return failed("\u8981 text\u3002");
|
|
3458
|
+
const x = args.x === void 0 ? 24 : Math.round(Number(args.x));
|
|
3459
|
+
const y = args.y === void 0 ? 72 : Math.round(Number(args.y));
|
|
3460
|
+
const size = args.size === void 0 ? 32 : Math.max(10, Math.min(120, Math.round(Number(args.size))));
|
|
3461
|
+
const color = typeof args.color === "string" && /^#[0-9a-fA-F]{6}$/.test(args.color) ? args.color : "#111111";
|
|
3462
|
+
return await this.hands.canvasText(text, x, y, size, color);
|
|
3384
3463
|
}
|
|
3385
3464
|
async canvasSimple(op) {
|
|
3386
3465
|
return await this.hands.canvasOp(op);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cortico-world-hands",
|
|
3
|
-
"version": "0.20.
|
|
3
|
+
"version": "0.20.41",
|
|
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",
|