@ynhcj/xiaoyi-channel 0.0.185-beta → 0.0.185-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.js +141 -1
- package/dist/src/acp-session-binding.d.ts +37 -0
- package/dist/src/acp-session-binding.js +237 -0
- package/dist/src/bot.js +62 -33
- package/dist/src/channel.js +68 -64
- package/dist/src/client.d.ts +5 -0
- package/dist/src/client.js +10 -0
- package/dist/src/cron-command.d.ts +2 -0
- package/dist/src/cron-command.js +14 -8
- package/dist/src/cron-query-handler.js +36 -0
- package/dist/src/cspl/call_api.js +4 -2
- package/dist/src/cspl/sentinel_hook.js +9 -8
- package/dist/src/cspl/upload_file.js +2 -2
- package/dist/src/formatter.js +72 -36
- package/dist/src/log-reporter/config-loader.d.ts +11 -0
- package/dist/src/log-reporter/config-loader.js +68 -0
- package/dist/src/log-reporter/cursor-store.d.ts +5 -0
- package/dist/src/log-reporter/cursor-store.js +26 -0
- package/dist/src/log-reporter/index.d.ts +10 -0
- package/dist/src/log-reporter/index.js +77 -0
- package/dist/src/log-reporter/reporter.d.ts +6 -0
- package/dist/src/log-reporter/reporter.js +17 -0
- package/dist/src/log-reporter/scanner.d.ts +6 -0
- package/dist/src/log-reporter/scanner.js +82 -0
- package/dist/src/log-reporter/types.d.ts +59 -0
- package/dist/src/log-reporter/types.js +2 -0
- package/dist/src/log-reporter/uploader.d.ts +6 -0
- package/dist/src/log-reporter/uploader.js +32 -0
- package/dist/src/memory-query-handler.d.ts +1 -0
- package/dist/src/memory-query-handler.js +283 -0
- package/dist/src/monitor.js +29 -9
- package/dist/src/outbound.js +5 -0
- package/dist/src/parser.d.ts +12 -0
- package/dist/src/parser.js +39 -13
- package/dist/src/provider.js +79 -16
- package/dist/src/reply-dispatcher.d.ts +3 -0
- package/dist/src/reply-dispatcher.js +166 -164
- package/dist/src/self-evolution-handler.js +2 -1
- package/dist/src/task-manager.d.ts +5 -6
- package/dist/src/task-manager.js +5 -9
- package/dist/src/tools/agent-as-skill-tool.d.ts +41 -2
- package/dist/src/tools/agent-as-skill-tool.js +144 -151
- package/dist/src/tools/calendar-tool.d.ts +24 -2
- package/dist/src/tools/calendar-tool.js +115 -117
- package/dist/src/tools/call-device-tool.d.ts +20 -6
- package/dist/src/tools/call-device-tool.js +116 -138
- package/dist/src/tools/call-phone-tool.d.ts +21 -2
- package/dist/src/tools/call-phone-tool.js +112 -114
- package/dist/src/tools/check-plugin-privilege-tool.d.ts +16 -2
- package/dist/src/tools/check-plugin-privilege-tool.js +141 -143
- package/dist/src/tools/create-alarm-tool.d.ts +39 -2
- package/dist/src/tools/create-alarm-tool.js +229 -231
- package/dist/src/tools/create-all-tools.js +8 -4
- package/dist/src/tools/delete-alarm-tool.d.ts +15 -2
- package/dist/src/tools/delete-alarm-tool.js +134 -136
- package/dist/src/tools/device-tool-map.d.ts +1 -1
- package/dist/src/tools/device-tool-map.js +9 -2
- package/dist/src/tools/discover-cross-devices-tool.d.ts +16 -2
- package/dist/src/tools/discover-cross-devices-tool.js +121 -124
- package/dist/src/tools/display-a2ui-card-bypath-tool.d.ts +21 -0
- package/dist/src/tools/display-a2ui-card-bypath-tool.js +65 -0
- package/dist/src/tools/get-alarm-tool-schema.d.ts +1 -2
- package/dist/src/tools/get-alarm-tool-schema.js +10 -16
- package/dist/src/tools/get-calendar-tool-schema.d.ts +1 -2
- package/dist/src/tools/get-calendar-tool-schema.js +8 -12
- package/dist/src/tools/get-collection-tool-schema.d.ts +1 -2
- package/dist/src/tools/get-collection-tool-schema.js +9 -11
- package/dist/src/tools/get-contact-tool-schema.d.ts +1 -2
- package/dist/src/tools/get-contact-tool-schema.js +10 -16
- package/dist/src/tools/get-device-file-tool-schema.d.ts +1 -2
- package/dist/src/tools/get-device-file-tool-schema.js +9 -13
- package/dist/src/tools/get-email-tool-schema.d.ts +1 -2
- package/dist/src/tools/get-email-tool-schema.js +8 -11
- package/dist/src/tools/get-note-tool-schema.d.ts +1 -2
- package/dist/src/tools/get-note-tool-schema.js +9 -14
- package/dist/src/tools/get-photo-tool-schema.d.ts +1 -2
- package/dist/src/tools/get-photo-tool-schema.js +9 -12
- package/dist/src/tools/image-reading-tool.d.ts +28 -2
- package/dist/src/tools/image-reading-tool.js +76 -76
- package/dist/src/tools/location-tool.d.ts +11 -2
- package/dist/src/tools/location-tool.js +93 -92
- package/dist/src/tools/login-token-tool.d.ts +20 -2
- package/dist/src/tools/login-token-tool.js +123 -125
- package/dist/src/tools/modify-alarm-tool.d.ts +47 -2
- package/dist/src/tools/modify-alarm-tool.js +250 -252
- package/dist/src/tools/modify-note-tool.d.ts +20 -2
- package/dist/src/tools/modify-note-tool.js +107 -109
- package/dist/src/tools/note-tool.d.ts +20 -2
- package/dist/src/tools/note-tool.js +106 -108
- package/dist/src/tools/query-app-message-tool.d.ts +28 -2
- package/dist/src/tools/query-app-message-tool.js +111 -113
- package/dist/src/tools/query-memory-data-tool.d.ts +28 -2
- package/dist/src/tools/query-memory-data-tool.js +112 -114
- package/dist/src/tools/query-todo-task-tool.d.ts +24 -2
- package/dist/src/tools/query-todo-task-tool.js +106 -108
- package/dist/src/tools/save-file-to-phone-tool.d.ts +24 -2
- package/dist/src/tools/save-file-to-phone-tool.js +130 -132
- package/dist/src/tools/save-media-to-gallery-tool.d.ts +24 -2
- package/dist/src/tools/save-media-to-gallery-tool.js +137 -139
- package/dist/src/tools/save-self-evolution-skill-tool.d.ts +54 -2
- package/dist/src/tools/save-self-evolution-skill-tool.js +194 -194
- package/dist/src/tools/search-alarm-tool.d.ts +34 -2
- package/dist/src/tools/search-alarm-tool.js +174 -176
- package/dist/src/tools/search-calendar-tool.d.ts +24 -2
- package/dist/src/tools/search-calendar-tool.js +148 -150
- package/dist/src/tools/search-contact-tool.d.ts +16 -2
- package/dist/src/tools/search-contact-tool.js +101 -103
- package/dist/src/tools/search-email-tool.d.ts +21 -2
- package/dist/src/tools/search-email-tool.js +110 -112
- package/dist/src/tools/search-file-tool.d.ts +16 -2
- package/dist/src/tools/search-file-tool.js +104 -106
- package/dist/src/tools/search-message-tool.d.ts +16 -2
- package/dist/src/tools/search-message-tool.js +103 -105
- package/dist/src/tools/search-note-tool.d.ts +16 -2
- package/dist/src/tools/search-note-tool.js +98 -100
- package/dist/src/tools/search-photo-gallery-tool.d.ts +21 -2
- package/dist/src/tools/search-photo-gallery-tool.js +35 -37
- package/dist/src/tools/send-cross-device-task-tool.d.ts +35 -2
- package/dist/src/tools/send-cross-device-task-tool.js +216 -150
- package/dist/src/tools/send-email-tool.d.ts +24 -2
- package/dist/src/tools/send-email-tool.js +108 -110
- package/dist/src/tools/send-file-to-user-tool.d.ts +20 -2
- package/dist/src/tools/send-file-to-user-tool.js +174 -178
- package/dist/src/tools/send-html-card-tool.d.ts +20 -2
- package/dist/src/tools/send-html-card-tool.js +85 -87
- package/dist/src/tools/send-message-tool.d.ts +20 -2
- package/dist/src/tools/send-message-tool.js +122 -124
- package/dist/src/tools/session-manager.d.ts +19 -52
- package/dist/src/tools/session-manager.js +95 -247
- package/dist/src/tools/upload-file-tool.d.ts +20 -2
- package/dist/src/tools/upload-file-tool.js +80 -82
- package/dist/src/tools/upload-photo-tool.d.ts +20 -2
- package/dist/src/tools/upload-photo-tool.js +68 -70
- package/dist/src/tools/xiaoyi-add-collection-tool.d.ts +32 -2
- package/dist/src/tools/xiaoyi-add-collection-tool.js +146 -148
- package/dist/src/tools/xiaoyi-collection-tool.d.ts +20 -2
- package/dist/src/tools/xiaoyi-collection-tool.js +114 -116
- package/dist/src/tools/xiaoyi-delete-collection-tool.d.ts +15 -2
- package/dist/src/tools/xiaoyi-delete-collection-tool.js +127 -129
- package/dist/src/tools/xiaoyi-gui-tool.d.ts +16 -2
- package/dist/src/tools/xiaoyi-gui-tool.js +92 -95
- package/dist/src/types.d.ts +6 -6
- package/dist/src/utils/config-manager.d.ts +3 -2
- package/dist/src/utils/config-manager.js +22 -2
- package/dist/src/utils/cron-push-map.d.ts +26 -0
- package/dist/src/utils/cron-push-map.js +131 -0
- package/dist/src/utils/logger.js +3 -14
- package/dist/src/websocket.d.ts +1 -1
- package/dist/src/websocket.js +29 -13
- package/package.json +1 -1
|
@@ -1,20 +1,17 @@
|
|
|
1
1
|
// XiaoYi GUI tool implementation - simulates phone screen interactions
|
|
2
|
-
import {
|
|
2
|
+
import { getCachedXYWebSocketManager } from "../client.js";
|
|
3
3
|
import { sendCommand } from "../formatter.js";
|
|
4
|
-
import {
|
|
5
|
-
import { isCronToolCall } from "./session-manager.js";
|
|
4
|
+
import { isCronToolCall, getCurrentSessionContext } from './session-manager.js';
|
|
6
5
|
import { logger } from "../utils/logger.js";
|
|
7
6
|
/**
|
|
8
7
|
* XiaoYi GUI tool - executes phone app interactions through GUI agent.
|
|
9
8
|
* Simulates user interactions on phone screen (click, swipe, input, navigation, etc.)
|
|
10
9
|
* to complete tasks that cannot be done through internet APIs.
|
|
11
10
|
*/
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
label: "XiaoYi GUI Agent",
|
|
17
|
-
description: `通过模拟人在手机屏幕上的交互行为(点击、滑动、输入、页面导航等),自动完成手机APP中的各类任务。
|
|
11
|
+
export const xiaoyiGuiTool = {
|
|
12
|
+
name: "xiaoyi_gui_agent",
|
|
13
|
+
label: "XiaoYi GUI Agent",
|
|
14
|
+
description: `通过模拟人在手机屏幕上的交互行为(点击、滑动、输入、页面导航等),自动完成手机APP中的各类任务。
|
|
18
15
|
|
|
19
16
|
该工具操作方式类似真实用户在手机上的操作,因此可以完成许多无法通过互联网API实现的任务,例如:
|
|
20
17
|
- 任务需要真实操作手机APP界面
|
|
@@ -30,95 +27,95 @@ export function createXiaoyiGuiTool(ctx) {
|
|
|
30
27
|
- 该工具执行期间不要执行别的工具调用,必须等到该工具有结果返回或者超时之后才能执行别的操作,无论是新的文本回复还是下一步的工具调用,在此工具执行期间必须严格等待
|
|
31
28
|
- 如果超时或失败,最多重试一次
|
|
32
29
|
- 如果用户指令中包含备忘录读写,日程查看,不需要将这类操作放在gui tool的query参数中,需要使用预置的note相关工具与calendar相关工具完成相关操作`,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
},
|
|
30
|
+
parameters: {
|
|
31
|
+
type: "object",
|
|
32
|
+
properties: {
|
|
33
|
+
query: {
|
|
34
|
+
type: "string",
|
|
35
|
+
description: "操作手机的指令以及期望返回的结果。",
|
|
40
36
|
},
|
|
41
|
-
required: ["query"],
|
|
42
37
|
},
|
|
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
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
38
|
+
required: ["query"],
|
|
39
|
+
},
|
|
40
|
+
async execute(toolCallId, params) {
|
|
41
|
+
const _c = getCurrentSessionContext();
|
|
42
|
+
const { config, sessionId, taskId, messageId } = _c;
|
|
43
|
+
// Dynamic lookup: use latest taskId from task-manager (handles steer/interrupt)
|
|
44
|
+
// Validate parameters
|
|
45
|
+
if (!params.query || typeof params.query !== "string") {
|
|
46
|
+
throw new Error("Missing or invalid required parameter: query must be a non-empty string");
|
|
47
|
+
}
|
|
48
|
+
// GUI agent only works in active WebSocket sessions — reject cron-triggered calls
|
|
49
|
+
if (sessionId.startsWith("cron-") || isCronToolCall(toolCallId)) {
|
|
50
|
+
throw new Error("xiaoyi_gui_agent 不支持定时任务触发,只能在活跃对话中使用");
|
|
51
|
+
}
|
|
52
|
+
// Get WebSocket manager
|
|
53
|
+
const wsManager = getCachedXYWebSocketManager();
|
|
54
|
+
// Build InvokeJarvisGUIAgentRequest command
|
|
55
|
+
const command = {
|
|
56
|
+
header: {
|
|
57
|
+
namespace: "ClawAgent",
|
|
58
|
+
name: "InvokeJarvisGUIAgentRequest",
|
|
59
|
+
},
|
|
60
|
+
payload: {
|
|
61
|
+
query: params.query,
|
|
62
|
+
sessionId: sessionId,
|
|
63
|
+
interactionId: taskId, // taskId corresponds to interactionId; use dynamic lookup for steer safety
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
// Send command and wait for response (5 minute timeout)
|
|
67
|
+
return new Promise((resolve, reject) => {
|
|
68
|
+
const timeout = setTimeout(() => {
|
|
69
|
+
wsManager.off("gui-agent-response", handler);
|
|
70
|
+
logger.error("超时: XiaoYi GUI Agent 操作超时(5分钟)", { toolCallId });
|
|
71
|
+
reject(new Error("XiaoYi GUI Agent 操作超时(5分钟)"));
|
|
72
|
+
}, 300000); // 5 minutes timeout
|
|
73
|
+
// Listen for GUI agent response events
|
|
74
|
+
const handler = (event) => {
|
|
75
|
+
// Check if this is the InvokeJarvisGUIAgentResponse we're waiting for
|
|
76
|
+
if (event.header?.namespace === "ClawAgent" &&
|
|
77
|
+
event.header?.name === "InvokeJarvisGUIAgentResponse") {
|
|
78
|
+
// According to the spec, we only get one response (isFinal: true)
|
|
79
|
+
if (event.payload?.isFinal === true) {
|
|
80
|
+
clearTimeout(timeout);
|
|
81
|
+
wsManager.off("gui-agent-response", handler);
|
|
82
|
+
const streamContent = event.payload?.streamInfo?.streamContent;
|
|
83
|
+
if (streamContent) {
|
|
84
|
+
resolve({
|
|
85
|
+
content: [
|
|
86
|
+
{
|
|
87
|
+
type: "text",
|
|
88
|
+
text: streamContent,
|
|
89
|
+
}
|
|
90
|
+
]
|
|
91
|
+
});
|
|
98
92
|
}
|
|
99
|
-
else
|
|
100
|
-
|
|
93
|
+
else {
|
|
94
|
+
reject(new Error("XiaoYi GUI Agent 响应格式错误:缺少 streamContent"));
|
|
101
95
|
}
|
|
102
96
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
97
|
+
else if (event.payload?.isFinal === false) {
|
|
98
|
+
// According to spec, we shouldn't get intermediate responses, but log if we do
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
// Register event handler
|
|
103
|
+
// Note: The WebSocket manager needs to emit 'gui-agent-response' when receiving this type of response
|
|
104
|
+
wsManager.on("gui-agent-response", handler);
|
|
105
|
+
// Send the command
|
|
106
|
+
sendCommand({
|
|
107
|
+
config,
|
|
108
|
+
sessionId,
|
|
109
|
+
taskId,
|
|
110
|
+
messageId,
|
|
111
|
+
command,
|
|
112
|
+
toolCallId,
|
|
113
|
+
}).then(() => {
|
|
114
|
+
}).catch((error) => {
|
|
115
|
+
clearTimeout(timeout);
|
|
116
|
+
wsManager.off("gui-agent-response", handler);
|
|
117
|
+
reject(error);
|
|
121
118
|
});
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
119
|
+
});
|
|
120
|
+
},
|
|
121
|
+
};
|
package/dist/src/types.d.ts
CHANGED
|
@@ -68,7 +68,7 @@ export interface CrossDeviceTaskResultEvent {
|
|
|
68
68
|
sessionId: string;
|
|
69
69
|
code: string;
|
|
70
70
|
message: string;
|
|
71
|
-
sentFiles:
|
|
71
|
+
sentFiles: SentFileCard[];
|
|
72
72
|
status: "success" | "failed";
|
|
73
73
|
rawEvent: any;
|
|
74
74
|
}
|
|
@@ -78,13 +78,13 @@ export interface RunCrossTaskContext {
|
|
|
78
78
|
isDistributed: boolean;
|
|
79
79
|
networkId: string;
|
|
80
80
|
isSupportAgent: boolean;
|
|
81
|
-
sentFiles:
|
|
81
|
+
sentFiles: SentFileCard[];
|
|
82
82
|
rawContext: any;
|
|
83
83
|
}
|
|
84
|
-
export interface
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
84
|
+
export interface SentFileCard {
|
|
85
|
+
fileName: string;
|
|
86
|
+
fileId: string;
|
|
87
|
+
mimeType?: string;
|
|
88
88
|
}
|
|
89
89
|
export interface A2ATaskArtifactUpdateEvent {
|
|
90
90
|
taskId: string;
|
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
* Specifically handles pushId which can be updated per-session.
|
|
4
4
|
*/
|
|
5
5
|
declare class ConfigManager {
|
|
6
|
-
private sessionPushIds;
|
|
7
|
-
private globalPushId;
|
|
6
|
+
private get sessionPushIds();
|
|
7
|
+
private get globalPushId();
|
|
8
|
+
private set globalPushId(value);
|
|
8
9
|
/**
|
|
9
10
|
* Update push ID for a specific session.
|
|
10
11
|
*/
|
|
@@ -1,12 +1,32 @@
|
|
|
1
1
|
// Dynamic configuration manager for runtime updates
|
|
2
|
+
//
|
|
3
|
+
// NOTE: xy_channel is loaded from multiple module resolution paths
|
|
4
|
+
// (plugin entry vs tool registration), which duplicates class instances.
|
|
5
|
+
// sessionPushIds and globalPushId must live on globalThis so all copies
|
|
6
|
+
// share the same Map — same reason activeSessions is on globalThis in
|
|
7
|
+
// session-manager.ts.
|
|
2
8
|
import { logger } from "./logger.js";
|
|
9
|
+
const _g = globalThis;
|
|
10
|
+
if (!_g.__xyConfigSessionPushIds) {
|
|
11
|
+
_g.__xyConfigSessionPushIds = new Map();
|
|
12
|
+
}
|
|
13
|
+
if (!_g.__xyConfigGlobalPushId) {
|
|
14
|
+
_g.__xyConfigGlobalPushId = null;
|
|
15
|
+
}
|
|
3
16
|
/**
|
|
4
17
|
* Manages dynamic configuration updates that can change at runtime.
|
|
5
18
|
* Specifically handles pushId which can be updated per-session.
|
|
6
19
|
*/
|
|
7
20
|
class ConfigManager {
|
|
8
|
-
sessionPushIds
|
|
9
|
-
|
|
21
|
+
get sessionPushIds() {
|
|
22
|
+
return _g.__xyConfigSessionPushIds;
|
|
23
|
+
}
|
|
24
|
+
get globalPushId() {
|
|
25
|
+
return _g.__xyConfigGlobalPushId;
|
|
26
|
+
}
|
|
27
|
+
set globalPushId(value) {
|
|
28
|
+
_g.__xyConfigGlobalPushId = value;
|
|
29
|
+
}
|
|
10
30
|
/**
|
|
11
31
|
* Update push ID for a specific session.
|
|
12
32
|
*/
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** 映射来源,区分两种创建路径。 */
|
|
2
|
+
export type CronPushMapSource = "conversation" | "cron-query" | "exec-cli";
|
|
3
|
+
export interface CronPushMapEntry {
|
|
4
|
+
pushId: string;
|
|
5
|
+
/** 创建该 cron 时的 xy sessionId,便于同进程兜底。 */
|
|
6
|
+
sessionId?: string;
|
|
7
|
+
/** 冗余记录设备类型,fire 时可按设备类型做差异化处理。 */
|
|
8
|
+
deviceType?: string;
|
|
9
|
+
source?: CronPushMapSource;
|
|
10
|
+
createdAt: number;
|
|
11
|
+
}
|
|
12
|
+
export interface CronPushMapFile {
|
|
13
|
+
version: 1;
|
|
14
|
+
entries: Record<string, CronPushMapEntry>;
|
|
15
|
+
}
|
|
16
|
+
/** 写入/更新一条 jobId → pushId 映射。 */
|
|
17
|
+
export declare function setJobPushId(jobId: string, entry: Omit<CronPushMapEntry, "createdAt">): Promise<void>;
|
|
18
|
+
/** fire 时主查询:按 jobId 取 pushId。 */
|
|
19
|
+
export declare function getPushIdByJobId(jobId: string): Promise<{
|
|
20
|
+
pushId: string;
|
|
21
|
+
entry: CronPushMapEntry;
|
|
22
|
+
} | null>;
|
|
23
|
+
/** 删除一条映射(cron job 被移除时清理)。 */
|
|
24
|
+
export declare function removeJob(jobId: string): Promise<void>;
|
|
25
|
+
/** 对账:删除 openclaw 里已不存在的 job,避免映射无限增长。 */
|
|
26
|
+
export declare function pruneStale(existingJobIds: Set<string>): Promise<void>;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// Cron job ↔ pushId 持久化映射
|
|
2
|
+
//
|
|
3
|
+
// 背景:cron 定时任务触发时,工具调用走 push 通道(sendCommandViaPush),
|
|
4
|
+
// 需要正确的 pushId 才能推到"创建该任务的那台设备"。pushIdList.json 是
|
|
5
|
+
// 扁平去重数组,无法区分设备;本文件按真实 jobId 保存创建时的 pushId,
|
|
6
|
+
// fire 时通过 jobId 反查即可定位到正确设备。
|
|
7
|
+
//
|
|
8
|
+
// jobId 的两端来源(均为真实 jobId,无需规范化反解):
|
|
9
|
+
// - 写入:after_tool_call 拦 cron/add → event.result.id;
|
|
10
|
+
// cron-query-handler inline → result.id
|
|
11
|
+
// - 读取:provider.ts extractCronUuid(context.messages) → "[cron:<jobId> ...]"
|
|
12
|
+
import { promises as fs } from "fs";
|
|
13
|
+
import * as path from "path";
|
|
14
|
+
import { logger } from "./logger.js";
|
|
15
|
+
const CRON_PUSH_MAP_FILE = "/home/sandbox/.openclaw/cron-push-map.json";
|
|
16
|
+
async function ensureDirectoryExists(filePath) {
|
|
17
|
+
const dir = path.dirname(filePath);
|
|
18
|
+
try {
|
|
19
|
+
await fs.mkdir(dir, { recursive: true });
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
logger.error(`[CronPushMap] Failed to create directory ${dir}:`, error);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async function readMap() {
|
|
26
|
+
try {
|
|
27
|
+
await ensureDirectoryExists(CRON_PUSH_MAP_FILE);
|
|
28
|
+
const content = await fs.readFile(CRON_PUSH_MAP_FILE, "utf-8");
|
|
29
|
+
const parsed = JSON.parse(content);
|
|
30
|
+
if (parsed &&
|
|
31
|
+
typeof parsed === "object" &&
|
|
32
|
+
parsed.version === 1 &&
|
|
33
|
+
parsed.entries &&
|
|
34
|
+
typeof parsed.entries === "object") {
|
|
35
|
+
return parsed;
|
|
36
|
+
}
|
|
37
|
+
logger.warn(`[CronPushMap] Unexpected file shape, returning empty map`);
|
|
38
|
+
return { version: 1, entries: {} };
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
if (error.code === "ENOENT") {
|
|
42
|
+
return { version: 1, entries: {} };
|
|
43
|
+
}
|
|
44
|
+
logger.error(`[CronPushMap] Failed to read map:`, error);
|
|
45
|
+
return { version: 1, entries: {} };
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
async function writeMap(map) {
|
|
49
|
+
try {
|
|
50
|
+
await ensureDirectoryExists(CRON_PUSH_MAP_FILE);
|
|
51
|
+
await fs.writeFile(CRON_PUSH_MAP_FILE, JSON.stringify(map, null, 2), "utf-8");
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
logger.error(`[CronPushMap] Failed to write map:`, error);
|
|
55
|
+
throw error;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/** 写入/更新一条 jobId → pushId 映射。 */
|
|
59
|
+
export async function setJobPushId(jobId, entry) {
|
|
60
|
+
if (!jobId || typeof jobId !== "string") {
|
|
61
|
+
logger.warn(`[CronPushMap] Invalid jobId: ${jobId}`);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (!entry.pushId || typeof entry.pushId !== "string") {
|
|
65
|
+
logger.warn(`[CronPushMap] Skipping setJobPushId: missing pushId for jobId=${jobId}`);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
try {
|
|
69
|
+
const map = await readMap();
|
|
70
|
+
map.entries[jobId] = { ...entry, createdAt: Date.now() };
|
|
71
|
+
await writeMap(map);
|
|
72
|
+
logger.log(`[CronPushMap] Saved jobId=${jobId}, source=${entry.source ?? "?"}, pushId=${entry.pushId.substring(0, 20)}...`);
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
logger.error(`[CronPushMap] Failed to setJobPushId:`, error);
|
|
76
|
+
// 不抛出,避免影响主流程
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/** fire 时主查询:按 jobId 取 pushId。 */
|
|
80
|
+
export async function getPushIdByJobId(jobId) {
|
|
81
|
+
if (!jobId)
|
|
82
|
+
return null;
|
|
83
|
+
try {
|
|
84
|
+
const map = await readMap();
|
|
85
|
+
const entry = map.entries[jobId];
|
|
86
|
+
if (entry && entry.pushId) {
|
|
87
|
+
return { pushId: entry.pushId, entry };
|
|
88
|
+
}
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
logger.error(`[CronPushMap] Failed to getPushIdByJobId:`, error);
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/** 删除一条映射(cron job 被移除时清理)。 */
|
|
97
|
+
export async function removeJob(jobId) {
|
|
98
|
+
if (!jobId)
|
|
99
|
+
return;
|
|
100
|
+
try {
|
|
101
|
+
const map = await readMap();
|
|
102
|
+
if (map.entries[jobId]) {
|
|
103
|
+
delete map.entries[jobId];
|
|
104
|
+
await writeMap(map);
|
|
105
|
+
logger.log(`[CronPushMap] Removed jobId=${jobId}`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
logger.error(`[CronPushMap] Failed to removeJob:`, error);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/** 对账:删除 openclaw 里已不存在的 job,避免映射无限增长。 */
|
|
113
|
+
export async function pruneStale(existingJobIds) {
|
|
114
|
+
try {
|
|
115
|
+
const map = await readMap();
|
|
116
|
+
let removed = 0;
|
|
117
|
+
for (const key of Object.keys(map.entries)) {
|
|
118
|
+
if (!existingJobIds.has(key)) {
|
|
119
|
+
delete map.entries[key];
|
|
120
|
+
removed++;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (removed > 0) {
|
|
124
|
+
await writeMap(map);
|
|
125
|
+
logger.log(`[CronPushMap] Pruned ${removed} stale entries`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
logger.error(`[CronPushMap] Failed to pruneStale:`, error);
|
|
130
|
+
}
|
|
131
|
+
}
|
package/dist/src/utils/logger.js
CHANGED
|
@@ -66,29 +66,18 @@ function checkRotation() {
|
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
// ── Session context from globalThis (avoids circular dep with session-manager) ──
|
|
69
|
+
// Pure ALS: the global Map fallback was removed when session-manager switched
|
|
70
|
+
// to AsyncLocalStorage-only. Outside a runWithSessionContext scope (cron,
|
|
71
|
+
// startup), getSessionInfo returns empty strings.
|
|
69
72
|
function getSessionInfo() {
|
|
70
73
|
try {
|
|
71
74
|
const g = globalThis;
|
|
72
|
-
// Try AsyncLocalStorage first (correct for concurrent sessions)
|
|
73
75
|
const als = g.__xyAsyncLocalStorage;
|
|
74
76
|
if (als) {
|
|
75
77
|
const store = als.getStore();
|
|
76
78
|
if (store?.sessionId)
|
|
77
79
|
return { sessionId: store.sessionId, taskId: store.taskId ?? "" };
|
|
78
80
|
}
|
|
79
|
-
// Fallback to activeSessions map
|
|
80
|
-
const sessions = g.__xyActiveSessions;
|
|
81
|
-
if (sessions && sessions.size > 0) {
|
|
82
|
-
const lastKey = g.__xyLastRegisteredSessionKey;
|
|
83
|
-
if (lastKey) {
|
|
84
|
-
const entry = sessions.get(lastKey);
|
|
85
|
-
if (entry?.sessionId)
|
|
86
|
-
return { sessionId: entry.sessionId, taskId: entry.taskId ?? "" };
|
|
87
|
-
}
|
|
88
|
-
const entry = sessions.values().next().value;
|
|
89
|
-
if (entry?.sessionId)
|
|
90
|
-
return { sessionId: entry.sessionId, taskId: entry.taskId ?? "" };
|
|
91
|
-
}
|
|
92
81
|
}
|
|
93
82
|
catch { }
|
|
94
83
|
return { sessionId: "", taskId: "" };
|
package/dist/src/websocket.d.ts
CHANGED
package/dist/src/websocket.js
CHANGED
|
@@ -7,6 +7,7 @@ import { HeartbeatManager } from "./heartbeat.js";
|
|
|
7
7
|
import { MessageQueue } from "./message-queue.js";
|
|
8
8
|
import { v4 as uuidv4 } from "uuid";
|
|
9
9
|
const RUN_CROSS_TASK_LOG_TAG = "[RunCrossTask]";
|
|
10
|
+
const SEND_CROSS_RESULT_LOG_TAG = "[SendCrossResult]";
|
|
10
11
|
const RUN_CROSS_TASK_QUERY_PREFIX = `# 跨设备协作接收模式<br/><br/>你当前正在接收来自其他设备的协作请求。请注意以下角色转换规则:<br/><br/>## 角色转换规则<br/><br/>- 指令中的"我" = 发送请求的远程用户<br/>- 你是执行协作任务的本地智能体<br/>- 任务完成后结果会自动回传给请求来源设备<br/><br/>## 核心执行规则<br/><br/>### ✅ 正确行为<br/>1. **识别本机任务**:当指令提到你所在的设备类型(PC/手机/平板),理解为"我自己"<br/>2. **本地执行**:直接使用本地工具完成任务,不要转发<br/>3. **结果回传**:执行完成后,结果会通过软总线自动回传给请求来源设备<br/><br/>### <span class="emoji emoji2716"></span> 禁止行为<br/>1. 禁止再次调用 \`send_cross_device_task\`(你已经是目标设备)<br/>2. 禁止设备澄清(指令已明确指定目标设备)<br/>3. 禁止无限循环(只能执行或回复,不能转发)<br/><br/>## 📁 文件操作规范(核心)<br/><br/>### 强制使用 search_file 的场景<br/>**以下场景必须先使用 \`search_file\` 工具确认文件路径:**<br/><br/>1. **指令包含设备关键词**:PC、电脑、手机、平板、Pad、笔记本等<br/>2. **涉及文件操作**:读取、编辑、删除、移动、复制、查找文件<br/><br/>### 执行流程<br/>\`\`\`<br/>收到文件操作指令<br/> ↓<br/>检测设备关键词(PC/电脑/手机/平板/Pad等)<br/> ↓<br/>使用 search_file 搜索文件 ← 必须步骤<br/> ↓<br/>确认文件实际路径<br/> ↓<br/>执行文件操作<br/> ↓<br/>返回结果<br/>\`\`\`<br/><br/>### 禁止行为<br/>- <span class="emoji emoji2716"></span> 禁止猜测文件路径<br/>- <span class="emoji emoji2716"></span> 禁止假设文件位置<br/>- <span class="emoji emoji2716"></span> 禁止跳过 search_file 步骤<br/><br/>## 示例<br/><br/>### 示例1:文件操作<br/>**指令**:"帮我到PC上下载昨天晚上写的PPT"<br/><br/>**执行流程**:<br/>1. ✅ 检测到"PC" → 使用 \`search_file\` 搜索 "*.ppt" 或 "*.pptx"<br/>2. 确认文件路径(如:D:\\Documents\\报告.pptx)<br/>3. 执行下载操作<br/><br/>### 示例2:文件编辑<br/>**指令**:"帮我修改电脑上的配置文件config.json"<br/><br/>**执行流程**:<br/>1. ✅ 检测到"电脑" → 使用 \`search_file\` 搜索 "config.json"<br/>2. 确认文件路径(如:C:\\Project\\config.json)<br/>3. 读取并修改文件<br/><br/>### 示例3:文件查找<br/>**指令**:"在平板上找一下我的PDF文档"<br/><br/>**执行流程**:<br/>1. ✅ 检测到"平板" → 使用 \`search_file\` 搜索 "*.pdf"<br/>2. 列出搜索结果供用户选择<br/><br/>## 判断流程<br/><br/>\`\`\`<br/>收到协作指令<br/> ↓<br/>检查目标设备<br/> ↓<br/>目标设备 == 本机?<br/> ↓<br/>是 → 本地执行(禁止send_cross_device_task)<br/> ↓<br/> 涉及文件? → 先用search_file确认路径<br/> ↓<br/>否 → 检查是否需要转发<br/> ↓<br/>需要转发 → 调用send_cross_device_task<br/>不需要 → 回复"无法处理"<br/>\`\`\``;
|
|
11
12
|
/**
|
|
12
13
|
* Manages single WebSocket connection to XY server.
|
|
@@ -397,26 +398,23 @@ export class XYWebSocketManager extends EventEmitter {
|
|
|
397
398
|
if (!entry || typeof entry !== "object") {
|
|
398
399
|
return null;
|
|
399
400
|
}
|
|
400
|
-
const
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
const
|
|
404
|
-
|
|
405
|
-
: [];
|
|
406
|
-
const fileNames = Array.isArray(entry.fileNames)
|
|
407
|
-
? entry.fileNames.filter((name) => typeof name === "string" && name.length > 0)
|
|
408
|
-
: [];
|
|
409
|
-
if (fileLocalUrls.length === 0 && fileRemoteUrls.length === 0) {
|
|
401
|
+
const candidate = entry;
|
|
402
|
+
const fileName = typeof candidate.fileName === "string" ? candidate.fileName.trim() : "";
|
|
403
|
+
const fileId = typeof candidate.fileId === "string" ? candidate.fileId.trim() : "";
|
|
404
|
+
const mimeType = typeof candidate.mimeType === "string" ? candidate.mimeType.trim() : "";
|
|
405
|
+
if (!fileName || !fileId) {
|
|
410
406
|
return null;
|
|
411
407
|
}
|
|
412
408
|
return {
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
...(
|
|
409
|
+
fileName,
|
|
410
|
+
fileId,
|
|
411
|
+
...(mimeType ? { mimeType } : {}),
|
|
416
412
|
};
|
|
417
413
|
}).filter((entry) => entry !== null)
|
|
418
414
|
: [];
|
|
419
415
|
const status = code === "0" ? "success" : "failed";
|
|
416
|
+
const fileCardCount = sentFiles.length;
|
|
417
|
+
this.log(`${SEND_CROSS_RESULT_LOG_TAG} normalized CrossTaskExecuteResult, sessionId=${sessionId}, status=${status}, code=${code}, fileCardCount=${fileCardCount}, messageLength=${message.length}`);
|
|
420
418
|
const event = {
|
|
421
419
|
sessionId,
|
|
422
420
|
code,
|
|
@@ -632,6 +630,15 @@ export class XYWebSocketManager extends EventEmitter {
|
|
|
632
630
|
messageId: a2aRequest.id,
|
|
633
631
|
});
|
|
634
632
|
}
|
|
633
|
+
else if (item.header?.namespace === "AgentEvent" && item.header?.name === "MemoryQuery") {
|
|
634
|
+
log.log("[XY] AgentEvent.MemoryQuery detected, emitting memory-query-event");
|
|
635
|
+
this.emit("memory-query-event", {
|
|
636
|
+
...(item.payload ?? {}),
|
|
637
|
+
sessionId,
|
|
638
|
+
taskId: a2aRequest.params?.id,
|
|
639
|
+
messageId: a2aRequest.id,
|
|
640
|
+
});
|
|
641
|
+
}
|
|
635
642
|
else if (item.header?.namespace === "System" && item.header?.name === "ExecuteAgentAsSkillResponse") {
|
|
636
643
|
log.log("[XY] ExecuteAgentAsSkillResponse detected, emitting agent-as-skill-response");
|
|
637
644
|
this.emit("agent-as-skill-response", item);
|
|
@@ -721,6 +728,15 @@ export class XYWebSocketManager extends EventEmitter {
|
|
|
721
728
|
messageId: a2aRequest.id,
|
|
722
729
|
});
|
|
723
730
|
}
|
|
731
|
+
else if (item.header?.namespace === "AgentEvent" && item.header?.name === "MemoryQuery") {
|
|
732
|
+
log.log("[XY] AgentEvent.MemoryQuery detected (wrapped format), emitting memory-query-event");
|
|
733
|
+
this.emit("memory-query-event", {
|
|
734
|
+
...(item.payload ?? {}),
|
|
735
|
+
sessionId: inboundMsg.sessionId || a2aRequest.params?.sessionId,
|
|
736
|
+
taskId: inboundMsg.taskId || a2aRequest.params?.id,
|
|
737
|
+
messageId: a2aRequest.id,
|
|
738
|
+
});
|
|
739
|
+
}
|
|
724
740
|
else if (item.header?.namespace === "System" && item.header?.name === "ExecuteAgentAsSkillResponse") {
|
|
725
741
|
log.log("[XY] ExecuteAgentAsSkillResponse detected (wrapped format), emitting agent-as-skill-response");
|
|
726
742
|
this.emit("agent-as-skill-response", item);
|