@ynhcj/xiaoyi-channel 0.0.89-beta → 0.0.89-next
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.d.ts +6 -9
- package/dist/index.js +26 -21
- package/dist/src/bot.js +27 -4
- package/dist/src/channel.js +2 -16
- package/dist/src/client.js +31 -22
- package/dist/src/cspl/call-api.js +6 -5
- package/dist/src/file-download.js +4 -3
- package/dist/src/file-upload.js +19 -18
- package/dist/src/heartbeat.js +1 -1
- package/dist/src/login-token-handler.d.ts +8 -0
- package/dist/src/login-token-handler.js +60 -0
- package/dist/src/message-queue.d.ts +17 -0
- package/dist/src/message-queue.js +51 -0
- package/dist/src/monitor.js +75 -13
- package/dist/src/outbound.js +19 -18
- package/dist/src/provider.d.ts +2 -1
- package/dist/src/provider.js +443 -34
- package/dist/src/push.js +16 -15
- package/dist/src/reply-dispatcher.js +4 -3
- package/dist/src/runtime.d.ts +3 -11
- package/dist/src/runtime.js +6 -18
- package/dist/src/self-evolution-handler.d.ts +7 -0
- package/dist/src/self-evolution-handler.js +140 -0
- package/dist/src/self-evolution-keyword.d.ts +9 -0
- package/dist/src/self-evolution-keyword.js +147 -0
- package/dist/src/self-evolution-tool-result-nudge.d.ts +3 -0
- package/dist/src/self-evolution-tool-result-nudge.js +96 -0
- package/dist/src/skill-retriever/config.d.ts +4 -0
- package/dist/src/skill-retriever/config.js +23 -0
- package/dist/src/skill-retriever/hooks.d.ts +22 -0
- package/dist/src/skill-retriever/hooks.js +83 -0
- package/dist/src/skill-retriever/tool-search.d.ts +16 -0
- package/dist/src/skill-retriever/tool-search.js +173 -0
- package/dist/src/skill-retriever/types.d.ts +36 -0
- package/dist/src/skill-retriever/types.js +1 -0
- package/dist/src/steer-injector.js +1 -1
- package/dist/src/task-manager.d.ts +4 -0
- package/dist/src/task-manager.js +12 -1
- package/dist/src/tools/calendar-tool.d.ts +2 -1
- package/dist/src/tools/calendar-tool.js +112 -116
- package/dist/src/tools/call-device-tool.d.ts +2 -1
- package/dist/src/tools/call-device-tool.js +126 -99
- package/dist/src/tools/call-phone-tool.d.ts +2 -1
- package/dist/src/tools/call-phone-tool.js +109 -113
- package/dist/src/tools/create-alarm-tool.d.ts +2 -1
- package/dist/src/tools/create-alarm-tool.js +227 -231
- package/dist/src/tools/create-all-tools.d.ts +16 -0
- package/dist/src/tools/create-all-tools.js +50 -0
- package/dist/src/tools/delete-alarm-tool.d.ts +2 -1
- package/dist/src/tools/delete-alarm-tool.js +131 -135
- package/dist/src/tools/get-alarm-tool-schema.d.ts +2 -1
- package/dist/src/tools/get-alarm-tool-schema.js +16 -10
- package/dist/src/tools/get-calendar-tool-schema.d.ts +2 -1
- package/dist/src/tools/get-calendar-tool-schema.js +12 -8
- package/dist/src/tools/get-collection-tool-schema.d.ts +2 -1
- package/dist/src/tools/get-collection-tool-schema.js +11 -9
- package/dist/src/tools/get-contact-tool-schema.d.ts +2 -1
- package/dist/src/tools/get-contact-tool-schema.js +16 -10
- package/dist/src/tools/get-device-file-tool-schema.d.ts +2 -1
- package/dist/src/tools/get-device-file-tool-schema.js +13 -9
- package/dist/src/tools/get-email-tool-schema.d.ts +17 -0
- package/dist/src/tools/get-email-tool-schema.js +12 -0
- package/dist/src/tools/get-note-tool-schema.d.ts +2 -1
- package/dist/src/tools/get-note-tool-schema.js +14 -9
- package/dist/src/tools/get-photo-tool-schema.d.ts +2 -1
- package/dist/src/tools/get-photo-tool-schema.js +12 -9
- package/dist/src/tools/image-reading-tool.d.ts +2 -1
- package/dist/src/tools/image-reading-tool.js +86 -90
- package/dist/src/tools/location-tool.d.ts +2 -1
- package/dist/src/tools/location-tool.js +87 -91
- package/dist/src/tools/login-token-tool.d.ts +6 -0
- package/dist/src/tools/login-token-tool.js +133 -0
- package/dist/src/tools/modify-alarm-tool.d.ts +2 -1
- package/dist/src/tools/modify-alarm-tool.js +232 -236
- package/dist/src/tools/modify-note-tool.d.ts +2 -1
- package/dist/src/tools/modify-note-tool.js +104 -108
- package/dist/src/tools/note-tool.d.ts +2 -1
- package/dist/src/tools/note-tool.js +103 -107
- package/dist/src/tools/query-app-message-tool.d.ts +5 -0
- package/dist/src/tools/query-app-message-tool.js +135 -0
- package/dist/src/tools/query-memory-data-tool.d.ts +5 -0
- package/dist/src/tools/query-memory-data-tool.js +151 -0
- package/dist/src/tools/query-todo-task-tool.d.ts +5 -0
- package/dist/src/tools/query-todo-task-tool.js +130 -0
- package/dist/src/tools/save-file-to-phone-tool.d.ts +2 -1
- package/dist/src/tools/save-file-to-phone-tool.js +127 -131
- package/dist/src/tools/save-media-to-gallery-tool.d.ts +2 -1
- package/dist/src/tools/save-media-to-gallery-tool.js +134 -138
- package/dist/src/tools/save-self-evolution-skill-tool.d.ts +2 -0
- package/dist/src/tools/save-self-evolution-skill-tool.js +410 -0
- package/dist/src/tools/search-alarm-tool.d.ts +2 -1
- package/dist/src/tools/search-alarm-tool.js +171 -175
- package/dist/src/tools/search-calendar-tool.d.ts +2 -1
- package/dist/src/tools/search-calendar-tool.js +145 -149
- package/dist/src/tools/search-contact-tool.d.ts +2 -1
- package/dist/src/tools/search-contact-tool.js +98 -102
- package/dist/src/tools/search-email-tool.d.ts +2 -1
- package/dist/src/tools/search-email-tool.js +107 -111
- package/dist/src/tools/search-file-tool.d.ts +2 -1
- package/dist/src/tools/search-file-tool.js +99 -103
- package/dist/src/tools/search-message-tool.d.ts +2 -1
- package/dist/src/tools/search-message-tool.js +100 -104
- package/dist/src/tools/search-note-tool.d.ts +2 -1
- package/dist/src/tools/search-note-tool.js +95 -99
- package/dist/src/tools/search-photo-gallery-tool.d.ts +2 -1
- package/dist/src/tools/search-photo-gallery-tool.js +34 -38
- package/dist/src/tools/send-email-tool.d.ts +5 -0
- package/dist/src/tools/send-email-tool.js +131 -0
- package/dist/src/tools/send-file-to-user-tool.d.ts +2 -1
- package/dist/src/tools/send-file-to-user-tool.js +154 -155
- package/dist/src/tools/send-message-tool.d.ts +2 -1
- package/dist/src/tools/send-message-tool.js +119 -123
- package/dist/src/tools/session-manager.d.ts +21 -6
- package/dist/src/tools/session-manager.js +147 -18
- package/dist/src/tools/upload-file-tool.d.ts +2 -1
- package/dist/src/tools/upload-file-tool.js +78 -82
- package/dist/src/tools/upload-photo-tool.d.ts +2 -1
- package/dist/src/tools/upload-photo-tool.js +69 -73
- package/dist/src/tools/xiaoyi-add-collection-tool.d.ts +2 -1
- package/dist/src/tools/xiaoyi-add-collection-tool.js +143 -147
- package/dist/src/tools/xiaoyi-collection-tool.d.ts +2 -1
- package/dist/src/tools/xiaoyi-collection-tool.js +111 -115
- package/dist/src/tools/xiaoyi-delete-collection-tool.d.ts +2 -1
- package/dist/src/tools/xiaoyi-delete-collection-tool.js +124 -128
- package/dist/src/tools/xiaoyi-gui-tool.d.ts +2 -1
- package/dist/src/tools/xiaoyi-gui-tool.js +84 -88
- package/dist/src/utils/runtime-manager.js +24 -2
- package/dist/src/utils/self-evolution-manager.d.ts +10 -0
- package/dist/src/utils/self-evolution-manager.js +69 -0
- package/dist/src/utils/tool-call-nudge-manager.d.ts +16 -0
- package/dist/src/utils/tool-call-nudge-manager.js +47 -0
- package/dist/src/websocket.d.ts +3 -0
- package/dist/src/websocket.js +97 -25
- package/openclaw.plugin.json +21 -0
- package/package.json +3 -3
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { getXYWebSocketManager } from "../client.js";
|
|
2
2
|
import { sendCommand } from "../formatter.js";
|
|
3
|
-
import { getCurrentSessionContext } from "./session-manager.js";
|
|
4
3
|
import { XYFileUploadService } from "../file-upload.js";
|
|
5
4
|
/**
|
|
6
5
|
* Duck-typed ToolInputError: openclaw 按 .name 字段匹配,不用 instanceof。
|
|
@@ -17,10 +16,12 @@ class ToolInputError extends Error {
|
|
|
17
16
|
/**
|
|
18
17
|
* XY add collection tool - adds data to user's XiaoYi collection.
|
|
19
18
|
*/
|
|
20
|
-
export
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
export function createXiaoyiAddCollectionTool(ctx) {
|
|
20
|
+
const { config, sessionId, taskId, messageId } = ctx;
|
|
21
|
+
return {
|
|
22
|
+
name: "add_collection",
|
|
23
|
+
label: "Add XiaoYi Collection",
|
|
24
|
+
description: `向小艺收藏中添加公共知识数据,可以给用户提供个性化体验。任何用户希望保存到个人化知识库中的数据都可以调用本技能。不同类型的数据对应的数据要求如下:
|
|
24
25
|
请求入参说明:
|
|
25
26
|
● content:必填字段,数据类型为string,功能描述是该字段是用户添加收藏的链接url或文本原文。适用于HYPER_LINK和TEXT类型。
|
|
26
27
|
● uri:必填字段,数据类型为string,功能描述是该字段是图片或文件的端存储地址链接。适用于IMAGE和FILE类型。
|
|
@@ -36,157 +37,152 @@ export const xiaoyiAddCollectionTool = {
|
|
|
36
37
|
|
|
37
38
|
回复约束:如果工具返回没有授权或者其他报错,只需要完整描述没有授权或者其他报错内容即可,不需要主动给用户提供解决方案,例如告诉用户如何授权,如何解决报错等都是不需要的,请严格遵守。
|
|
38
39
|
`,
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
40
|
+
parameters: {
|
|
41
|
+
type: "object",
|
|
42
|
+
properties: {
|
|
43
|
+
content: {
|
|
44
|
+
type: "string",
|
|
45
|
+
description: "必填字段(HYPER_LINK/TEXT类型时)。用户添加收藏的链接url或文本原文。",
|
|
46
|
+
},
|
|
47
|
+
uri: {
|
|
48
|
+
type: "string",
|
|
49
|
+
description: `必填字段(IMAGE/FILE类型时)。图片或文件的地址链接。
|
|
49
50
|
uri具备三种严格的格式
|
|
50
51
|
(1) http或者https开头的公网链接,一般是用户通过联网搜索获取的文件地址,不允许自行编造,此类链接填入时必须确保真实
|
|
51
52
|
(2) file://开头的链接,此类链接必须来源于query_collection结果或者search_file或者search_photo_gallery的结果,不允许自行编造
|
|
52
53
|
(3) 本地路径例,如/tmp/xy_channel/xxx,此类路径是文件保存在当前openclaw运行环境的本地目录,可以直接填入,不要擅自拼接http://或者file://前缀`,
|
|
54
|
+
},
|
|
55
|
+
sourceAppBundleName: {
|
|
56
|
+
type: "string",
|
|
57
|
+
description: "非必填字段。标识该数据的来源应用。",
|
|
58
|
+
},
|
|
59
|
+
dataType: {
|
|
60
|
+
type: "string",
|
|
61
|
+
description: "必填字段。标识数据类型:HYPER_LINK表示网页,TEXT表示文本,IMAGE表示图片,FILE表示文件。",
|
|
62
|
+
},
|
|
63
|
+
title: {
|
|
64
|
+
type: "string",
|
|
65
|
+
description: "非必填字段。标识文件类型数据的文件名称。适用于FILE类型。",
|
|
66
|
+
},
|
|
53
67
|
},
|
|
54
|
-
|
|
55
|
-
type: "string",
|
|
56
|
-
description: "非必填字段。标识该数据的来源应用。",
|
|
57
|
-
},
|
|
58
|
-
dataType: {
|
|
59
|
-
type: "string",
|
|
60
|
-
description: "必填字段。标识数据类型:HYPER_LINK表示网页,TEXT表示文本,IMAGE表示图片,FILE表示文件。",
|
|
61
|
-
},
|
|
62
|
-
title: {
|
|
63
|
-
type: "string",
|
|
64
|
-
description: "非必填字段。标识文件类型数据的文件名称。适用于FILE类型。",
|
|
65
|
-
},
|
|
68
|
+
required: ["dataType"],
|
|
66
69
|
},
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
if (!dataType || !validTypes.includes(dataType)) {
|
|
74
|
-
throw new ToolInputError(`dataType必填且必须为 HYPER_LINK、TEXT、IMAGE、FILE 之一,当前值: ${dataType}`);
|
|
75
|
-
}
|
|
76
|
-
if ((dataType === "HYPER_LINK" || dataType === "TEXT") && (!content || typeof content !== "string")) {
|
|
77
|
-
throw new ToolInputError(`dataType为${dataType}时,content字段必填且不能为空`);
|
|
78
|
-
}
|
|
79
|
-
if ((dataType === "IMAGE" || dataType === "FILE") && (!uri || typeof uri !== "string")) {
|
|
80
|
-
throw new ToolInputError(`dataType为${dataType}时,uri字段必填且不能为空`);
|
|
81
|
-
}
|
|
82
|
-
// Get session context
|
|
83
|
-
const sessionContext = getCurrentSessionContext();
|
|
84
|
-
if (!sessionContext) {
|
|
85
|
-
throw new Error("No active XY session found. AddCollection tool can only be used during an active conversation.");
|
|
86
|
-
}
|
|
87
|
-
const { config, sessionId, taskId, messageId } = sessionContext;
|
|
88
|
-
// Get WebSocket manager
|
|
89
|
-
const wsManager = getXYWebSocketManager(config);
|
|
90
|
-
// Handle uri: upload local paths to get public URL
|
|
91
|
-
let publicUri = uri;
|
|
92
|
-
if (uri && !uri.startsWith("http://") && !uri.startsWith("https://") && !uri.startsWith("file://")) {
|
|
93
|
-
const uploadService = new XYFileUploadService(config.fileUploadUrl, config.apiKey, config.uid);
|
|
94
|
-
publicUri = await uploadService.uploadFileAndGetUrl(uri);
|
|
95
|
-
if (!publicUri) {
|
|
96
|
-
throw new Error("本地文件上传失败,无法获取公网URL");
|
|
70
|
+
async execute(toolCallId, params) {
|
|
71
|
+
// Validate parameters
|
|
72
|
+
const { content, uri, sourceAppBundleName, dataType, title } = params;
|
|
73
|
+
const validTypes = ["HYPER_LINK", "TEXT", "IMAGE", "FILE"];
|
|
74
|
+
if (!dataType || !validTypes.includes(dataType)) {
|
|
75
|
+
throw new ToolInputError(`dataType必填且必须为 HYPER_LINK、TEXT、IMAGE、FILE 之一,当前值: ${dataType}`);
|
|
97
76
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
dataType
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
77
|
+
if ((dataType === "HYPER_LINK" || dataType === "TEXT") && (!content || typeof content !== "string")) {
|
|
78
|
+
throw new ToolInputError(`dataType为${dataType}时,content字段必填且不能为空`);
|
|
79
|
+
}
|
|
80
|
+
if ((dataType === "IMAGE" || dataType === "FILE") && (!uri || typeof uri !== "string")) {
|
|
81
|
+
throw new ToolInputError(`dataType为${dataType}时,uri字段必填且不能为空`);
|
|
82
|
+
}
|
|
83
|
+
// Get WebSocket manager
|
|
84
|
+
const wsManager = getXYWebSocketManager(config);
|
|
85
|
+
// Handle uri: upload local paths to get public URL
|
|
86
|
+
let publicUri = uri;
|
|
87
|
+
if (uri && !uri.startsWith("http://") && !uri.startsWith("https://") && !uri.startsWith("file://")) {
|
|
88
|
+
const uploadService = new XYFileUploadService(config.fileUploadUrl, config.apiKey, config.uid);
|
|
89
|
+
publicUri = await uploadService.uploadFileAndGetUrl(uri);
|
|
90
|
+
if (!publicUri) {
|
|
91
|
+
throw new Error("本地文件上传失败,无法获取公网URL");
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
// Build intentParam
|
|
95
|
+
const intentParam = {
|
|
96
|
+
dataType,
|
|
97
|
+
};
|
|
98
|
+
if (content) {
|
|
99
|
+
intentParam.content = content;
|
|
100
|
+
}
|
|
101
|
+
if (publicUri) {
|
|
102
|
+
intentParam.uri = publicUri;
|
|
103
|
+
}
|
|
104
|
+
if (sourceAppBundleName) {
|
|
105
|
+
intentParam.sourceAppBundleName = sourceAppBundleName;
|
|
106
|
+
}
|
|
107
|
+
if (title) {
|
|
108
|
+
intentParam.title = title;
|
|
109
|
+
}
|
|
110
|
+
// Build AddCollection command
|
|
111
|
+
const command = {
|
|
112
|
+
header: {
|
|
113
|
+
namespace: "Common",
|
|
114
|
+
name: "Action",
|
|
134
115
|
},
|
|
135
|
-
|
|
136
|
-
{
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
116
|
+
payload: {
|
|
117
|
+
cardParam: {},
|
|
118
|
+
executeParam: {
|
|
119
|
+
executeMode: "background",
|
|
120
|
+
intentName: "AddCollection",
|
|
121
|
+
bundleName: "com.huawei.hmos.vassistant",
|
|
122
|
+
needUnlock: true,
|
|
123
|
+
actionResponse: true,
|
|
124
|
+
appType: "OHOS_APP",
|
|
125
|
+
timeOut: 5,
|
|
126
|
+
intentParam,
|
|
127
|
+
permissionId: [],
|
|
128
|
+
achieveType: "INTENT",
|
|
140
129
|
},
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}
|
|
153
|
-
//
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
clearTimeout(timeout);
|
|
130
|
+
responses: [
|
|
131
|
+
{
|
|
132
|
+
resultCode: "",
|
|
133
|
+
displayText: "",
|
|
134
|
+
ttsText: "",
|
|
135
|
+
},
|
|
136
|
+
],
|
|
137
|
+
needUploadResult: true,
|
|
138
|
+
noHalfPage: false,
|
|
139
|
+
pageControlRelated: false,
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
// Send command and wait for response (60 second timeout)
|
|
143
|
+
return new Promise((resolve, reject) => {
|
|
144
|
+
const timeout = setTimeout(() => {
|
|
157
145
|
wsManager.off("data-event", handler);
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
146
|
+
reject(new Error("添加小艺收藏超时(60秒)"));
|
|
147
|
+
}, 60000);
|
|
148
|
+
// Listen for data events from WebSocket
|
|
149
|
+
const handler = (event) => {
|
|
150
|
+
if (event.intentName === "AddCollection") {
|
|
151
|
+
clearTimeout(timeout);
|
|
152
|
+
wsManager.off("data-event", handler);
|
|
153
|
+
if (event.status === "success" && event.outputs) {
|
|
154
|
+
resolve({
|
|
155
|
+
content: [
|
|
156
|
+
{
|
|
157
|
+
type: "text",
|
|
158
|
+
text: JSON.stringify(event.outputs),
|
|
159
|
+
}
|
|
160
|
+
]
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
reject(new Error(`添加小艺收藏失败: ${event.status}`));
|
|
165
|
+
}
|
|
167
166
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
clearTimeout(timeout);
|
|
187
|
-
wsManager.off("data-event", handler);
|
|
188
|
-
reject(error);
|
|
167
|
+
};
|
|
168
|
+
// Register event handler
|
|
169
|
+
wsManager.on("data-event", handler);
|
|
170
|
+
// Send the command
|
|
171
|
+
sendCommand({
|
|
172
|
+
config,
|
|
173
|
+
sessionId,
|
|
174
|
+
taskId,
|
|
175
|
+
messageId,
|
|
176
|
+
command,
|
|
177
|
+
})
|
|
178
|
+
.then(() => {
|
|
179
|
+
})
|
|
180
|
+
.catch((error) => {
|
|
181
|
+
clearTimeout(timeout);
|
|
182
|
+
wsManager.off("data-event", handler);
|
|
183
|
+
reject(error);
|
|
184
|
+
});
|
|
189
185
|
});
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
186
|
+
},
|
|
187
|
+
};
|
|
188
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { SessionContext } from "./session-manager.js";
|
|
1
2
|
/**
|
|
2
3
|
* XY collection tool - retrieves user's collection data from XiaoYi.
|
|
3
4
|
* Returns personalized knowledge data saved in user's collection.
|
|
4
5
|
*/
|
|
5
|
-
export declare
|
|
6
|
+
export declare function createXiaoyiCollectionTool(ctx: SessionContext): any;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { getXYWebSocketManager } from "../client.js";
|
|
2
2
|
import { sendCommand } from "../formatter.js";
|
|
3
|
-
import { getCurrentSessionContext } from "./session-manager.js";
|
|
4
3
|
/**
|
|
5
4
|
* Duck-typed ToolInputError: openclaw 按 .name 字段匹配,不用 instanceof。
|
|
6
5
|
* 抛出此错误会让 openclaw 返回 HTTP 400 而非 500,
|
|
@@ -17,10 +16,12 @@ class ToolInputError extends Error {
|
|
|
17
16
|
* XY collection tool - retrieves user's collection data from XiaoYi.
|
|
18
17
|
* Returns personalized knowledge data saved in user's collection.
|
|
19
18
|
*/
|
|
20
|
-
export
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
export function createXiaoyiCollectionTool(ctx) {
|
|
20
|
+
const { config, sessionId, taskId, messageId } = ctx;
|
|
21
|
+
return {
|
|
22
|
+
name: "query_collection",
|
|
23
|
+
label: "XiaoYi Collection",
|
|
24
|
+
description: `检索用户在小艺收藏中记下来的公共知识数据,本技能支持查询用户收藏的公共知识数据,也可以根据特定语义化描述进行特定内容的检索,通过参数进行控制。本技能返回结果中,linkTitle是收藏内容的标题,description是对收藏内容的总结,label是收藏内容的标签,linkUrl是可以直接访问的原始内容链接。如果你认为某条数据对用户交互有用,可以通过linkUrl抓取更加丰富的原始数据。
|
|
24
25
|
注意:
|
|
25
26
|
a. 操作超时时间为60秒,请勿重复调用此工具
|
|
26
27
|
b. 如果遇到各类调用失败场景,最多只能重试一次,不可以重复调用多次。
|
|
@@ -29,120 +30,115 @@ export const xiaoyiCollectionTool = {
|
|
|
29
30
|
|
|
30
31
|
回复约束:如果工具返回没有授权或者其他报错,只需要完整描述没有授权或者其他报错内容即可,不需要主动给用户提供解决方案,例如告诉用户如何授权,如何解决报错等都是不需要的,请严格遵守。
|
|
31
32
|
`,
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
33
|
+
parameters: {
|
|
34
|
+
type: "object",
|
|
35
|
+
properties: {
|
|
36
|
+
queryAll: {
|
|
37
|
+
type: "string",
|
|
38
|
+
description: "非必填参数,描述是否需要查询用户所有收藏数据。如果填入true则表示获取用户所有公共知识数据,其他参数无效。",
|
|
39
|
+
},
|
|
40
|
+
query: {
|
|
41
|
+
type: "string",
|
|
42
|
+
description: "非必填参数,queryAll不填或者为false则必填。用户的查询条件,可按照用户query进行检索。",
|
|
43
|
+
},
|
|
42
44
|
},
|
|
45
|
+
required: [],
|
|
43
46
|
},
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
intentParam.queryAll = "false";
|
|
68
|
-
intentParam.query = query;
|
|
69
|
-
}
|
|
70
|
-
// Build QueryCollection command
|
|
71
|
-
const command = {
|
|
72
|
-
header: {
|
|
73
|
-
namespace: "Common",
|
|
74
|
-
name: "Action",
|
|
75
|
-
},
|
|
76
|
-
payload: {
|
|
77
|
-
cardParam: {},
|
|
78
|
-
executeParam: {
|
|
79
|
-
executeMode: "background",
|
|
80
|
-
intentName: "QueryCollection",
|
|
81
|
-
bundleName: "com.huawei.hmos.vassistant",
|
|
82
|
-
needUnlock: true,
|
|
83
|
-
actionResponse: true,
|
|
84
|
-
appType: "OHOS_APP",
|
|
85
|
-
timeOut: 5,
|
|
86
|
-
intentParam,
|
|
87
|
-
permissionId: [],
|
|
88
|
-
achieveType: "INTENT",
|
|
47
|
+
async execute(toolCallId, params) {
|
|
48
|
+
// Validate parameters
|
|
49
|
+
const queryAll = params.queryAll;
|
|
50
|
+
const query = params.query;
|
|
51
|
+
if (queryAll !== "true" && (!query || typeof query !== "string")) {
|
|
52
|
+
throw new ToolInputError("queryAll不为true时,query参数必填");
|
|
53
|
+
}
|
|
54
|
+
// Get WebSocket manager
|
|
55
|
+
const wsManager = getXYWebSocketManager(config);
|
|
56
|
+
// Build intentParam
|
|
57
|
+
const intentParam = {};
|
|
58
|
+
if (queryAll === "true") {
|
|
59
|
+
intentParam.queryAll = "true";
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
intentParam.queryAll = "false";
|
|
63
|
+
intentParam.query = query;
|
|
64
|
+
}
|
|
65
|
+
// Build QueryCollection command
|
|
66
|
+
const command = {
|
|
67
|
+
header: {
|
|
68
|
+
namespace: "Common",
|
|
69
|
+
name: "Action",
|
|
89
70
|
},
|
|
90
|
-
|
|
91
|
-
{
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
71
|
+
payload: {
|
|
72
|
+
cardParam: {},
|
|
73
|
+
executeParam: {
|
|
74
|
+
executeMode: "background",
|
|
75
|
+
intentName: "QueryCollection",
|
|
76
|
+
bundleName: "com.huawei.hmos.vassistant",
|
|
77
|
+
needUnlock: true,
|
|
78
|
+
actionResponse: true,
|
|
79
|
+
appType: "OHOS_APP",
|
|
80
|
+
timeOut: 5,
|
|
81
|
+
intentParam,
|
|
82
|
+
permissionId: [],
|
|
83
|
+
achieveType: "INTENT",
|
|
95
84
|
},
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
//
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
clearTimeout(timeout);
|
|
85
|
+
responses: [
|
|
86
|
+
{
|
|
87
|
+
resultCode: "",
|
|
88
|
+
displayText: "",
|
|
89
|
+
ttsText: "",
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
needUploadResult: true,
|
|
93
|
+
noHalfPage: false,
|
|
94
|
+
pageControlRelated: false,
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
// Send command and wait for response (60 second timeout)
|
|
98
|
+
return new Promise((resolve, reject) => {
|
|
99
|
+
const timeout = setTimeout(() => {
|
|
112
100
|
wsManager.off("data-event", handler);
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
101
|
+
reject(new Error("查询小艺收藏超时(60秒)"));
|
|
102
|
+
}, 60000);
|
|
103
|
+
// Listen for data events from WebSocket
|
|
104
|
+
const handler = (event) => {
|
|
105
|
+
if (event.intentName === "QueryCollection") {
|
|
106
|
+
clearTimeout(timeout);
|
|
107
|
+
wsManager.off("data-event", handler);
|
|
108
|
+
if (event.status === "success" && event.outputs) {
|
|
109
|
+
// 成功,直接返回完整的 event.outputs JSON 字符串
|
|
110
|
+
resolve({
|
|
111
|
+
content: [
|
|
112
|
+
{
|
|
113
|
+
type: "text",
|
|
114
|
+
text: JSON.stringify(event.outputs),
|
|
115
|
+
}
|
|
116
|
+
]
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
reject(new Error(`查询小艺收藏失败: ${event.status}`));
|
|
121
|
+
}
|
|
126
122
|
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
123
|
+
};
|
|
124
|
+
// Register event handler
|
|
125
|
+
wsManager.on("data-event", handler);
|
|
126
|
+
// Send the command
|
|
127
|
+
sendCommand({
|
|
128
|
+
config,
|
|
129
|
+
sessionId,
|
|
130
|
+
taskId,
|
|
131
|
+
messageId,
|
|
132
|
+
command,
|
|
133
|
+
})
|
|
134
|
+
.then(() => {
|
|
135
|
+
})
|
|
136
|
+
.catch((error) => {
|
|
137
|
+
clearTimeout(timeout);
|
|
138
|
+
wsManager.off("data-event", handler);
|
|
139
|
+
reject(error);
|
|
140
|
+
});
|
|
145
141
|
});
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
142
|
+
},
|
|
143
|
+
};
|
|
144
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
+
import type { SessionContext } from "./session-manager.js";
|
|
1
2
|
/**
|
|
2
3
|
* XY delete collection tool - deletes data from user's XiaoYi collection.
|
|
3
4
|
*/
|
|
4
|
-
export declare
|
|
5
|
+
export declare function createXiaoyiDeleteCollectionTool(ctx: SessionContext): any;
|