@ynhcj/xiaoyi-channel 0.0.30-beta → 0.0.31-beta
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/src/tools/note-tool.js +27 -6
- package/package.json +1 -1
|
@@ -2,6 +2,18 @@ import { getXYWebSocketManager } from "../client.js";
|
|
|
2
2
|
import { sendCommand } from "../formatter.js";
|
|
3
3
|
import { getCurrentSessionContext } from "./session-manager.js";
|
|
4
4
|
import { logger } from "../utils/logger.js";
|
|
5
|
+
/**
|
|
6
|
+
* Duck-typed ToolInputError: openclaw 按 .name 字段匹配,不用 instanceof。
|
|
7
|
+
* 抛出此错误会让 openclaw 返回 HTTP 400 而非 500,
|
|
8
|
+
* LLM 会将其识别为参数错误而非瞬时故障,不会触发重试。
|
|
9
|
+
*/
|
|
10
|
+
class ToolInputError extends Error {
|
|
11
|
+
status = 400;
|
|
12
|
+
constructor(message) {
|
|
13
|
+
super(message);
|
|
14
|
+
this.name = "ToolInputError";
|
|
15
|
+
}
|
|
16
|
+
}
|
|
5
17
|
/**
|
|
6
18
|
* XY note tool - creates a note on user's device.
|
|
7
19
|
* Requires title and content parameters.
|
|
@@ -9,26 +21,35 @@ import { logger } from "../utils/logger.js";
|
|
|
9
21
|
export const noteTool = {
|
|
10
22
|
name: "create_note",
|
|
11
23
|
label: "Create Note",
|
|
12
|
-
description:
|
|
24
|
+
description: `在用户设备上创建备忘录。需要提供备忘录标题和内容。
|
|
25
|
+
注意:
|
|
26
|
+
a. 操作超时时间为60秒,请勿重复调用此工具
|
|
27
|
+
b. 如果遇到各类调用失败场景,最多只能重试一次,不可以重复调用多次。
|
|
28
|
+
c. 调用工具前需认真检查调用参数是否满足工具要求
|
|
29
|
+
`,
|
|
13
30
|
parameters: {
|
|
14
31
|
type: "object",
|
|
15
32
|
properties: {
|
|
16
33
|
title: {
|
|
17
34
|
type: "string",
|
|
18
|
-
description: "
|
|
35
|
+
description: "备忘录标题,必填",
|
|
19
36
|
},
|
|
20
37
|
content: {
|
|
21
38
|
type: "string",
|
|
22
|
-
description: "
|
|
39
|
+
description: "备忘录内容,必填",
|
|
23
40
|
},
|
|
24
41
|
},
|
|
25
42
|
required: ["title", "content"],
|
|
26
43
|
},
|
|
27
44
|
async execute(toolCallId, params) {
|
|
28
45
|
logger.debug("Executing note tool, toolCallId:", toolCallId);
|
|
29
|
-
// Validate parameters
|
|
30
|
-
|
|
31
|
-
|
|
46
|
+
// Validate parameters — 抛 ToolInputError 而非普通 Error,
|
|
47
|
+
// 让 openclaw 返回 400 而非 500,明确告知 LLM 这是参数错误,不应重试。
|
|
48
|
+
if (typeof params.title !== "string" || !params.title) {
|
|
49
|
+
throw new ToolInputError("缺少必填参数 title(备忘录标题)");
|
|
50
|
+
}
|
|
51
|
+
if (typeof params.content !== "string" || !params.content) {
|
|
52
|
+
throw new ToolInputError("缺少必填参数 content(备忘录内容)");
|
|
32
53
|
}
|
|
33
54
|
// Get session context
|
|
34
55
|
const sessionContext = getCurrentSessionContext();
|