@ynhcj/xiaoyi-channel 0.0.87-beta → 0.0.87-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 +26 -3
- package/dist/src/channel.js +2 -30
- package/dist/src/client.js +7 -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 +64 -4
- package/dist/src/provider.d.ts +2 -1
- package/dist/src/provider.js +440 -31
- package/dist/src/reply-dispatcher.js +6 -0
- 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 +82 -0
- package/dist/src/skill-retriever/tool-search.d.ts +16 -0
- package/dist/src/skill-retriever/tool-search.js +172 -0
- package/dist/src/skill-retriever/types.d.ts +36 -0
- package/dist/src/skill-retriever/types.js +1 -0
- 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 +6 -0
- package/dist/src/tools/call-device-tool.js +153 -0
- 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/device-tool-map.js +2 -0
- package/dist/src/tools/get-alarm-tool-schema.d.ts +17 -0
- package/dist/src/tools/get-alarm-tool-schema.js +17 -0
- package/dist/src/tools/get-calendar-tool-schema.d.ts +17 -0
- package/dist/src/tools/get-calendar-tool-schema.js +13 -0
- package/dist/src/tools/get-collection-tool-schema.d.ts +17 -0
- package/dist/src/tools/get-collection-tool-schema.js +12 -0
- package/dist/src/tools/get-contact-tool-schema.d.ts +17 -0
- package/dist/src/tools/get-contact-tool-schema.js +17 -0
- package/dist/src/tools/get-device-file-tool-schema.d.ts +17 -0
- package/dist/src/tools/get-device-file-tool-schema.js +14 -0
- 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 +17 -0
- package/dist/src/tools/get-note-tool-schema.js +15 -0
- package/dist/src/tools/get-photo-tool-schema.d.ts +17 -0
- package/dist/src/tools/get-photo-tool-schema.js +13 -0
- 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/schema-tool-factory.d.ts +27 -0
- package/dist/src/tools/schema-tool-factory.js +32 -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 +153 -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 +135 -18
- package/dist/src/tools/upload-file-tool.d.ts +2 -1
- package/dist/src/tools/upload-file-tool.js +79 -83
- package/dist/src/tools/upload-photo-tool.d.ts +2 -1
- package/dist/src/tools/upload-photo-tool.js +70 -74
- 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 +112 -116
- 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 +68 -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 +94 -24
- 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
|
/**
|
|
5
4
|
* Duck-typed ToolInputError: openclaw 按 .name 字段匹配,不用 instanceof。
|
|
6
5
|
* 抛出此错误会让 openclaw 返回 HTTP 400 而非 500,
|
|
@@ -16,10 +15,12 @@ class ToolInputError extends Error {
|
|
|
16
15
|
/**
|
|
17
16
|
* XY delete collection tool - deletes data from user's XiaoYi collection.
|
|
18
17
|
*/
|
|
19
|
-
export
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
export function createXiaoyiDeleteCollectionTool(ctx) {
|
|
19
|
+
const { config, sessionId, taskId, messageId } = ctx;
|
|
20
|
+
return {
|
|
21
|
+
name: "delete_collection",
|
|
22
|
+
label: "Delete XiaoYi Collection",
|
|
23
|
+
description: `从小艺收藏中删除之前已保存的公共知识数据。任何用户希望删除已保存到个人知识库的数据都可以调用本技能。如果用户想更新之前的收藏数据,需要先query获取itemId然后再delete,最后执行Add,按照这个步骤完成收藏数据更新。
|
|
23
24
|
注意:
|
|
24
25
|
a. 操作超时时间为60秒,请勿重复调用此工具
|
|
25
26
|
b. 如果遇到各类调用失败场景,最多只能重试一次,不可以重复调用多次。
|
|
@@ -27,137 +28,132 @@ export const xiaoyiDeleteCollectionTool = {
|
|
|
27
28
|
|
|
28
29
|
回复约束:如果工具返回没有授权或者其他报错,只需要完整描述没有授权或者其他报错内容即可,不需要主动给用户提供解决方案,例如告诉用户如何授权,如何解决报错等都是不需要的,请严格遵守。
|
|
29
30
|
`,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
parameters: {
|
|
32
|
+
type: "object",
|
|
33
|
+
properties: {
|
|
34
|
+
itemIds: {
|
|
35
|
+
// 不指定 type,允许传入数组或 JSON 字符串
|
|
36
|
+
// 具体的类型验证和转换在 execute 函数内部进行
|
|
37
|
+
description: "准备删除的数据的itemId合集。itemId可以由用户指定,也可以从之前检索回来的收藏数据项的itemId字段获取。",
|
|
38
|
+
},
|
|
37
39
|
},
|
|
40
|
+
required: ["itemIds"],
|
|
38
41
|
},
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
42
|
+
async execute(toolCallId, params) {
|
|
43
|
+
// ===== 参数规范化:兼容数组和 JSON 字符串 =====
|
|
44
|
+
let itemIds = null;
|
|
45
|
+
if (!params.itemIds) {
|
|
46
|
+
throw new ToolInputError("缺少必填参数: itemIds");
|
|
47
|
+
}
|
|
48
|
+
// 情况1: 已经是数组
|
|
49
|
+
if (Array.isArray(params.itemIds)) {
|
|
50
|
+
itemIds = params.itemIds;
|
|
51
|
+
}
|
|
52
|
+
// 情况2: 是字符串,尝试解析为 JSON 数组
|
|
53
|
+
else if (typeof params.itemIds === 'string') {
|
|
54
|
+
try {
|
|
55
|
+
const parsed = JSON.parse(params.itemIds);
|
|
56
|
+
if (Array.isArray(parsed)) {
|
|
57
|
+
itemIds = parsed;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
throw new ToolInputError("itemIds must be an array or a JSON string representing an array");
|
|
61
|
+
}
|
|
57
62
|
}
|
|
58
|
-
|
|
59
|
-
|
|
63
|
+
catch (parseError) {
|
|
64
|
+
if (parseError instanceof ToolInputError)
|
|
65
|
+
throw parseError;
|
|
66
|
+
throw new ToolInputError(`itemIds must be a valid JSON array string. Parse error: ${parseError instanceof Error ? parseError.message : String(parseError)}`);
|
|
60
67
|
}
|
|
61
68
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
throw new ToolInputError(`itemIds must be a valid JSON array string. Parse error: ${parseError instanceof Error ? parseError.message : String(parseError)}`);
|
|
69
|
+
// 情况3: 其他类型,报错
|
|
70
|
+
else {
|
|
71
|
+
throw new ToolInputError(`itemIds must be an array or a JSON string, got ${typeof params.itemIds}`);
|
|
66
72
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
if (!sessionContext) {
|
|
79
|
-
throw new Error("No active XY session found. DeleteCollection tool can only be used during an active conversation.");
|
|
80
|
-
}
|
|
81
|
-
const { config, sessionId, taskId, messageId } = sessionContext;
|
|
82
|
-
// Get WebSocket manager
|
|
83
|
-
const wsManager = getXYWebSocketManager(config);
|
|
84
|
-
// Build DeleteCollection command
|
|
85
|
-
const command = {
|
|
86
|
-
header: {
|
|
87
|
-
namespace: "Common",
|
|
88
|
-
name: "Action",
|
|
89
|
-
},
|
|
90
|
-
payload: {
|
|
91
|
-
cardParam: {},
|
|
92
|
-
executeParam: {
|
|
93
|
-
executeMode: "background",
|
|
94
|
-
intentName: "DeleteCollection",
|
|
95
|
-
bundleName: "com.huawei.hmos.vassistant",
|
|
96
|
-
needUnlock: true,
|
|
97
|
-
actionResponse: true,
|
|
98
|
-
appType: "OHOS_APP",
|
|
99
|
-
timeOut: 5,
|
|
100
|
-
intentParam: {
|
|
101
|
-
itemIds,
|
|
102
|
-
},
|
|
103
|
-
permissionId: [],
|
|
104
|
-
achieveType: "INTENT",
|
|
73
|
+
// 验证数组非空
|
|
74
|
+
if (!itemIds || itemIds.length === 0) {
|
|
75
|
+
throw new ToolInputError("itemIds array cannot be empty");
|
|
76
|
+
}
|
|
77
|
+
// Get WebSocket manager
|
|
78
|
+
const wsManager = getXYWebSocketManager(config);
|
|
79
|
+
// Build DeleteCollection command
|
|
80
|
+
const command = {
|
|
81
|
+
header: {
|
|
82
|
+
namespace: "Common",
|
|
83
|
+
name: "Action",
|
|
105
84
|
},
|
|
106
|
-
|
|
107
|
-
{
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
85
|
+
payload: {
|
|
86
|
+
cardParam: {},
|
|
87
|
+
executeParam: {
|
|
88
|
+
executeMode: "background",
|
|
89
|
+
intentName: "DeleteCollection",
|
|
90
|
+
bundleName: "com.huawei.hmos.vassistant",
|
|
91
|
+
needUnlock: true,
|
|
92
|
+
actionResponse: true,
|
|
93
|
+
appType: "OHOS_APP",
|
|
94
|
+
timeOut: 5,
|
|
95
|
+
intentParam: {
|
|
96
|
+
itemIds,
|
|
97
|
+
},
|
|
98
|
+
permissionId: [],
|
|
99
|
+
achieveType: "INTENT",
|
|
111
100
|
},
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
}
|
|
124
|
-
//
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
clearTimeout(timeout);
|
|
101
|
+
responses: [
|
|
102
|
+
{
|
|
103
|
+
resultCode: "",
|
|
104
|
+
displayText: "",
|
|
105
|
+
ttsText: "",
|
|
106
|
+
},
|
|
107
|
+
],
|
|
108
|
+
needUploadResult: true,
|
|
109
|
+
noHalfPage: false,
|
|
110
|
+
pageControlRelated: false,
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
// Send command and wait for response (60 second timeout)
|
|
114
|
+
return new Promise((resolve, reject) => {
|
|
115
|
+
const timeout = setTimeout(() => {
|
|
128
116
|
wsManager.off("data-event", handler);
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
117
|
+
reject(new Error("删除小艺收藏超时(60秒)"));
|
|
118
|
+
}, 60000);
|
|
119
|
+
// Listen for data events from WebSocket
|
|
120
|
+
const handler = (event) => {
|
|
121
|
+
if (event.intentName === "DeleteCollection") {
|
|
122
|
+
clearTimeout(timeout);
|
|
123
|
+
wsManager.off("data-event", handler);
|
|
124
|
+
if (event.status === "success" && event.outputs) {
|
|
125
|
+
resolve({
|
|
126
|
+
content: [
|
|
127
|
+
{
|
|
128
|
+
type: "text",
|
|
129
|
+
text: JSON.stringify(event.outputs),
|
|
130
|
+
}
|
|
131
|
+
]
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
reject(new Error(`删除小艺收藏失败: ${event.status}`));
|
|
136
|
+
}
|
|
138
137
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
clearTimeout(timeout);
|
|
158
|
-
wsManager.off("data-event", handler);
|
|
159
|
-
reject(error);
|
|
138
|
+
};
|
|
139
|
+
// Register event handler
|
|
140
|
+
wsManager.on("data-event", handler);
|
|
141
|
+
// Send the command
|
|
142
|
+
sendCommand({
|
|
143
|
+
config,
|
|
144
|
+
sessionId,
|
|
145
|
+
taskId,
|
|
146
|
+
messageId,
|
|
147
|
+
command,
|
|
148
|
+
})
|
|
149
|
+
.then(() => {
|
|
150
|
+
})
|
|
151
|
+
.catch((error) => {
|
|
152
|
+
clearTimeout(timeout);
|
|
153
|
+
wsManager.off("data-event", handler);
|
|
154
|
+
reject(error);
|
|
155
|
+
});
|
|
160
156
|
});
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import type { SessionContext } from "./session-manager.js";
|
|
1
2
|
/**
|
|
2
3
|
* XiaoYi GUI tool - executes phone app interactions through GUI agent.
|
|
3
4
|
* Simulates user interactions on phone screen (click, swipe, input, navigation, etc.)
|
|
4
5
|
* to complete tasks that cannot be done through internet APIs.
|
|
5
6
|
*/
|
|
6
|
-
export declare
|
|
7
|
+
export declare function createXiaoyiGuiTool(ctx: SessionContext): any;
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
// XiaoYi GUI tool implementation - simulates phone screen interactions
|
|
2
2
|
import { getXYWebSocketManager } from "../client.js";
|
|
3
3
|
import { sendCommand } from "../formatter.js";
|
|
4
|
-
import { getCurrentSessionContext } from "./session-manager.js";
|
|
5
4
|
/**
|
|
6
5
|
* XiaoYi GUI tool - executes phone app interactions through GUI agent.
|
|
7
6
|
* Simulates user interactions on phone screen (click, swipe, input, navigation, etc.)
|
|
8
7
|
* to complete tasks that cannot be done through internet APIs.
|
|
9
8
|
*/
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
export function createXiaoyiGuiTool(ctx) {
|
|
10
|
+
const { config, sessionId, taskId, messageId } = ctx;
|
|
11
|
+
return {
|
|
12
|
+
name: "xiaoyi_gui_agent",
|
|
13
|
+
label: "XiaoYi GUI Agent",
|
|
14
|
+
description: `通过模拟人在手机屏幕上的交互行为(点击、滑动、输入、页面导航等),自动完成手机APP中的各类任务。
|
|
14
15
|
|
|
15
16
|
该工具操作方式类似真实用户在手机上的操作,因此可以完成许多无法通过互联网API实现的任务,例如:
|
|
16
17
|
- 任务需要真实操作手机APP界面
|
|
@@ -26,92 +27,87 @@ export const xiaoyiGuiTool = {
|
|
|
26
27
|
- 该工具执行期间不要执行别的工具调用,必须等到该工具有结果返回或者超时之后才能执行别的操作,无论是新的文本回复还是下一步的工具调用,在此工具执行期间必须严格等待
|
|
27
28
|
- 如果超时或失败,最多重试一次
|
|
28
29
|
- 如果用户指令中包含备忘录读写,日程查看,不需要将这类操作放在gui tool的query参数中,需要使用预置的note相关工具与calendar相关工具完成相关操作`,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
parameters: {
|
|
31
|
+
type: "object",
|
|
32
|
+
properties: {
|
|
33
|
+
query: {
|
|
34
|
+
type: "string",
|
|
35
|
+
description: "操作手机的指令以及期望返回的结果。",
|
|
36
|
+
},
|
|
35
37
|
},
|
|
38
|
+
required: ["query"],
|
|
36
39
|
},
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
text: streamContent,
|
|
86
|
-
}
|
|
87
|
-
]
|
|
88
|
-
});
|
|
40
|
+
async execute(toolCallId, params) {
|
|
41
|
+
// Validate parameters
|
|
42
|
+
if (!params.query || typeof params.query !== "string") {
|
|
43
|
+
throw new Error("Missing or invalid required parameter: query must be a non-empty string");
|
|
44
|
+
}
|
|
45
|
+
// Get WebSocket manager
|
|
46
|
+
const wsManager = getXYWebSocketManager(config);
|
|
47
|
+
// Build InvokeJarvisGUIAgentRequest command
|
|
48
|
+
const command = {
|
|
49
|
+
header: {
|
|
50
|
+
namespace: "ClawAgent",
|
|
51
|
+
name: "InvokeJarvisGUIAgentRequest",
|
|
52
|
+
},
|
|
53
|
+
payload: {
|
|
54
|
+
query: params.query,
|
|
55
|
+
sessionId: sessionId,
|
|
56
|
+
interactionId: taskId, // taskId corresponds to interactionId
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
// Send command and wait for response (5 minute timeout)
|
|
60
|
+
return new Promise((resolve, reject) => {
|
|
61
|
+
const timeout = setTimeout(() => {
|
|
62
|
+
wsManager.off("gui-agent-response", handler);
|
|
63
|
+
reject(new Error("XiaoYi GUI Agent 操作超时(5分钟)"));
|
|
64
|
+
}, 180000); // 5 minutes timeout
|
|
65
|
+
// Listen for GUI agent response events
|
|
66
|
+
const handler = (event) => {
|
|
67
|
+
// Check if this is the InvokeJarvisGUIAgentResponse we're waiting for
|
|
68
|
+
if (event.header?.namespace === "ClawAgent" &&
|
|
69
|
+
event.header?.name === "InvokeJarvisGUIAgentResponse") {
|
|
70
|
+
// According to the spec, we only get one response (isFinal: true)
|
|
71
|
+
if (event.payload?.isFinal === true) {
|
|
72
|
+
clearTimeout(timeout);
|
|
73
|
+
wsManager.off("gui-agent-response", handler);
|
|
74
|
+
const streamContent = event.payload?.streamInfo?.streamContent;
|
|
75
|
+
if (streamContent) {
|
|
76
|
+
resolve({
|
|
77
|
+
content: [
|
|
78
|
+
{
|
|
79
|
+
type: "text",
|
|
80
|
+
text: streamContent,
|
|
81
|
+
}
|
|
82
|
+
]
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
reject(new Error("XiaoYi GUI Agent 响应格式错误:缺少 streamContent"));
|
|
87
|
+
}
|
|
89
88
|
}
|
|
90
|
-
else {
|
|
91
|
-
|
|
89
|
+
else if (event.payload?.isFinal === false) {
|
|
90
|
+
// According to spec, we shouldn't get intermediate responses, but log if we do
|
|
92
91
|
}
|
|
93
92
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
clearTimeout(timeout);
|
|
112
|
-
wsManager.off("gui-agent-response", handler);
|
|
113
|
-
reject(error);
|
|
93
|
+
};
|
|
94
|
+
// Register event handler
|
|
95
|
+
// Note: The WebSocket manager needs to emit 'gui-agent-response' when receiving this type of response
|
|
96
|
+
wsManager.on("gui-agent-response", handler);
|
|
97
|
+
// Send the command
|
|
98
|
+
sendCommand({
|
|
99
|
+
config,
|
|
100
|
+
sessionId,
|
|
101
|
+
taskId,
|
|
102
|
+
messageId,
|
|
103
|
+
command,
|
|
104
|
+
}).then(() => {
|
|
105
|
+
}).catch((error) => {
|
|
106
|
+
clearTimeout(timeout);
|
|
107
|
+
wsManager.off("gui-agent-response", handler);
|
|
108
|
+
reject(error);
|
|
109
|
+
});
|
|
114
110
|
});
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
}
|
|
@@ -28,8 +28,30 @@ export async function saveRuntimeInfo(webSocketSessionId, conversationId, taskId
|
|
|
28
28
|
}
|
|
29
29
|
try {
|
|
30
30
|
await ensureDirectoryExists(RUNTIME_FILE);
|
|
31
|
-
const
|
|
32
|
-
|
|
31
|
+
const updates = {
|
|
32
|
+
SESSION_ID: webSocketSessionId,
|
|
33
|
+
CONVERSATION_ID: conversationId,
|
|
34
|
+
TASK_ID: taskId,
|
|
35
|
+
};
|
|
36
|
+
let lines = [];
|
|
37
|
+
try {
|
|
38
|
+
const content = await fs.readFile(RUNTIME_FILE, "utf-8");
|
|
39
|
+
lines = content.split("\n");
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
// File doesn't exist yet
|
|
43
|
+
}
|
|
44
|
+
for (const [key, value] of Object.entries(updates)) {
|
|
45
|
+
const index = lines.findIndex((line) => line.startsWith(`${key}=`));
|
|
46
|
+
if (index !== -1) {
|
|
47
|
+
lines[index] = `${key}=${value}`;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
lines.push(`${key}=${value}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const result = lines.filter((line) => line.trim() !== "").join("\n") + "\n";
|
|
54
|
+
await fs.writeFile(RUNTIME_FILE, result, "utf-8");
|
|
33
55
|
logger.log(`[RuntimeManager] ✅ Saved runtime info to .xiaoyiruntime`);
|
|
34
56
|
logger.log(`[RuntimeManager] - SESSION_ID: ${webSocketSessionId}`);
|
|
35
57
|
logger.log(`[RuntimeManager] - CONVERSATION_ID: ${conversationId}`);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
declare class SelfEvolutionManager {
|
|
2
|
+
/**
|
|
3
|
+
* Synchronous read for hot paths (e.g. tool_result_persist — must not return a Promise).
|
|
4
|
+
*/
|
|
5
|
+
isEnabledSync(): boolean;
|
|
6
|
+
private parseEnabledFromEnvText;
|
|
7
|
+
isEnabled(): Promise<boolean>;
|
|
8
|
+
}
|
|
9
|
+
export declare const selfEvolutionManager: SelfEvolutionManager;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import fsp from "node:fs/promises";
|
|
3
|
+
const SELF_EVOLUTION_ENV_FILE = "/home/sandbox/.openclaw/.xiaoyiruntime";
|
|
4
|
+
const SELF_EVOLUTION_ENV_KEY = "selfEvolutionState";
|
|
5
|
+
function parseBooleanLike(value) {
|
|
6
|
+
const normalized = value.trim().toLowerCase();
|
|
7
|
+
if (normalized === "true") {
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
if (normalized === "false") {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
class SelfEvolutionManager {
|
|
16
|
+
/**
|
|
17
|
+
* Synchronous read for hot paths (e.g. tool_result_persist — must not return a Promise).
|
|
18
|
+
*/
|
|
19
|
+
isEnabledSync() {
|
|
20
|
+
try {
|
|
21
|
+
const envData = fs.readFileSync(SELF_EVOLUTION_ENV_FILE, "utf-8");
|
|
22
|
+
return this.parseEnabledFromEnvText(envData);
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
const code = error && typeof error === "object" && "code" in error ? error.code : undefined;
|
|
26
|
+
if (code !== "ENOENT") {
|
|
27
|
+
console.error(`[SELF_EVOLUTION] Failed to read ${SELF_EVOLUTION_ENV_FILE}:`, error);
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
parseEnabledFromEnvText(envData) {
|
|
33
|
+
for (const line of envData.split(/\r?\n/u)) {
|
|
34
|
+
const trimmed = line.trim();
|
|
35
|
+
if (!trimmed || trimmed.startsWith("#")) {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
const eqIndex = trimmed.indexOf("=");
|
|
39
|
+
if (eqIndex === -1) {
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
const key = trimmed.slice(0, eqIndex).trim();
|
|
43
|
+
if (key !== SELF_EVOLUTION_ENV_KEY) {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const value = trimmed.slice(eqIndex + 1).trim();
|
|
47
|
+
const parsed = parseBooleanLike(value);
|
|
48
|
+
if (parsed !== null) {
|
|
49
|
+
return parsed;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
async isEnabled() {
|
|
55
|
+
try {
|
|
56
|
+
const envData = await fsp.readFile(SELF_EVOLUTION_ENV_FILE, "utf-8");
|
|
57
|
+
return this.parseEnabledFromEnvText(envData);
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
const code = error && typeof error === "object" && "code" in error ? error.code : undefined;
|
|
61
|
+
if (code !== "ENOENT") {
|
|
62
|
+
console.error(`[SELF_EVOLUTION] Failed to read ${SELF_EVOLUTION_ENV_FILE}:`, error);
|
|
63
|
+
}
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
export const selfEvolutionManager = new SelfEvolutionManager();
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
type RecordToolCallResult = {
|
|
2
|
+
count: number;
|
|
3
|
+
shouldNudge: boolean;
|
|
4
|
+
};
|
|
5
|
+
declare class ToolCallNudgeManager {
|
|
6
|
+
private readonly threshold;
|
|
7
|
+
private readonly sessions;
|
|
8
|
+
constructor(threshold?: number);
|
|
9
|
+
private getSessionState;
|
|
10
|
+
recordToolCall(sessionKey: string): RecordToolCallResult;
|
|
11
|
+
tryMarkKeywordNudge(sessionKey: string): boolean;
|
|
12
|
+
clearSession(sessionKey: string): void;
|
|
13
|
+
}
|
|
14
|
+
export declare const TOOL_CALL_NUDGE_THRESHOLD = 6;
|
|
15
|
+
export declare const toolCallNudgeManager: ToolCallNudgeManager;
|
|
16
|
+
export {};
|