@ynhcj/xiaoyi-channel 0.0.166-beta → 0.0.166-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/bot.js +60 -5
- package/dist/src/cron-command.d.ts +2 -0
- package/dist/src/cron-command.js +14 -8
- package/dist/src/cron-query-handler.js +45 -8
- package/dist/src/cspl/call_api.js +2 -2
- package/dist/src/cspl/sentinel_hook.js +9 -4
- package/dist/src/cspl/upload_file.js +2 -2
- package/dist/src/cspl/utils.d.ts +9 -3
- package/dist/src/cspl/utils.js +15 -9
- package/dist/src/file-upload.d.ts +5 -0
- package/dist/src/file-upload.js +102 -0
- package/dist/src/formatter.d.ts +29 -0
- package/dist/src/formatter.js +100 -2
- package/dist/src/monitor.js +35 -23
- package/dist/src/parser.d.ts +6 -0
- package/dist/src/parser.js +23 -13
- package/dist/src/provider.js +41 -1
- package/dist/src/reply-dispatcher.js +34 -16
- package/dist/src/self-evolution-handler.d.ts +1 -1
- package/dist/src/self-evolution-handler.js +12 -1
- package/dist/src/tools/check-plugin-privilege-tool.d.ts +6 -0
- package/dist/src/tools/check-plugin-privilege-tool.js +182 -0
- package/dist/src/tools/create-all-tools.js +4 -0
- package/dist/src/tools/device-tool-map.d.ts +1 -1
- package/dist/src/tools/device-tool-map.js +8 -1
- package/dist/src/tools/modify-alarm-tool.js +17 -0
- package/dist/src/tools/send-cross-device-task-tool.js +84 -15
- package/dist/src/tools/send-file-to-user-tool.js +9 -11
- package/dist/src/tools/send-html-card-tool.d.ts +7 -0
- package/dist/src/tools/send-html-card-tool.js +113 -0
- package/dist/src/tools/session-manager.d.ts +11 -2
- package/dist/src/tools/session-manager.js +65 -18
- package/dist/src/tools/xiaoyi-gui-tool.js +1 -1
- package/dist/src/types.d.ts +9 -7
- 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/websocket.js +11 -13
- package/package.json +1 -1
|
@@ -48,6 +48,32 @@ export function isCronToolCall(toolCallId) {
|
|
|
48
48
|
export function clearCronToolCall(toolCallId) {
|
|
49
49
|
cronToolCallMap.delete(toolCallId);
|
|
50
50
|
}
|
|
51
|
+
// ── Cron session ↔ jobId bridge ────────────────────────────────────
|
|
52
|
+
// fire 期 jobId 传递桥。provider.ts 在 isCron 分支从首条消息
|
|
53
|
+
// `[cron:<jobId> ...]` 解析出真实 jobId,写入合成 cron sessionId;
|
|
54
|
+
// sendCommand/formatter 凭同一合成 sessionId 反查 jobId,再去
|
|
55
|
+
// cron-push-map 取对应设备的 pushId。同一 cron run 内 ALS 上下文共享,
|
|
56
|
+
// 合成 sessionId 在 provider 与 sendCommand 之间一致。
|
|
57
|
+
if (!_g.__xyCronSessionJobId) {
|
|
58
|
+
_g.__xyCronSessionJobId = new Map();
|
|
59
|
+
}
|
|
60
|
+
const cronSessionJobIdMap = _g.__xyCronSessionJobId;
|
|
61
|
+
/** 把 fire 期解析出的 jobId 绑定到当前 cron run 的合成 sessionId。 */
|
|
62
|
+
export function setCurrentCronJobId(cronSessionId, jobId) {
|
|
63
|
+
if (cronSessionId && jobId) {
|
|
64
|
+
cronSessionJobIdMap.set(cronSessionId, jobId);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/** 凭合成 cron sessionId 取本次 run 的 jobId(供 sendCommand 反查 pushId)。 */
|
|
68
|
+
export function getCurrentCronJobId(cronSessionId) {
|
|
69
|
+
if (!cronSessionId)
|
|
70
|
+
return undefined;
|
|
71
|
+
return cronSessionJobIdMap.get(cronSessionId);
|
|
72
|
+
}
|
|
73
|
+
/** cron run 结束后清理。 */
|
|
74
|
+
export function clearCronJobId(cronSessionId) {
|
|
75
|
+
cronSessionJobIdMap.delete(cronSessionId);
|
|
76
|
+
}
|
|
51
77
|
// AsyncLocalStorage for thread-safe session context isolation
|
|
52
78
|
export const asyncLocalStorage = new AsyncLocalStorage();
|
|
53
79
|
// Export AsyncLocalStorage to globalThis so logger.ts can access it
|
|
@@ -64,9 +90,17 @@ export function registerSession(sessionKey, context) {
|
|
|
64
90
|
setLastRegisteredKey(sessionKey);
|
|
65
91
|
const existing = activeSessions.get(sessionKey);
|
|
66
92
|
if (existing) {
|
|
67
|
-
//
|
|
93
|
+
// 更新上下文(全量同步所有字段,避免 global Map 残留旧值,
|
|
94
|
+
// 当 ALS 丢失回退到 Map 时拿到过期的 modelName / deviceType)
|
|
95
|
+
existing.config = context.config;
|
|
96
|
+
existing.sessionId = context.sessionId;
|
|
97
|
+
existing.distributionSessionId = context.distributionSessionId;
|
|
68
98
|
existing.taskId = context.taskId;
|
|
69
99
|
existing.messageId = context.messageId;
|
|
100
|
+
existing.agentId = context.agentId;
|
|
101
|
+
existing.deviceType = context.deviceType;
|
|
102
|
+
existing.modelName = context.modelName;
|
|
103
|
+
existing.runCrossTaskContext = context.runCrossTaskContext;
|
|
70
104
|
existing.refCount++;
|
|
71
105
|
existing.createdAt = Date.now(); // 刷新存活时间,长对话不受 TTL 影响
|
|
72
106
|
}
|
|
@@ -237,36 +271,49 @@ export function cleanupStaleSessions() {
|
|
|
237
271
|
export function getActiveSessionCount() {
|
|
238
272
|
return activeSessions.size;
|
|
239
273
|
}
|
|
240
|
-
function
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
const
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
? params.fileNames.filter((name) => typeof name === "string" && name.length > 0)
|
|
249
|
-
: [];
|
|
250
|
-
if (fileLocalUrls.length === 0 && fileRemoteUrls.length === 0) {
|
|
274
|
+
function normalizeSentFileCard(card) {
|
|
275
|
+
if (!card || typeof card !== "object") {
|
|
276
|
+
return null;
|
|
277
|
+
}
|
|
278
|
+
const fileName = typeof card.fileName === "string" ? card.fileName.trim() : "";
|
|
279
|
+
const fileId = typeof card.fileId === "string" ? card.fileId.trim() : "";
|
|
280
|
+
const mimeType = typeof card.mimeType === "string" ? card.mimeType.trim() : "";
|
|
281
|
+
if (!fileName || !fileId) {
|
|
251
282
|
return null;
|
|
252
283
|
}
|
|
253
284
|
return {
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
...(
|
|
285
|
+
fileName,
|
|
286
|
+
fileId,
|
|
287
|
+
...(mimeType ? { mimeType } : {}),
|
|
257
288
|
};
|
|
258
289
|
}
|
|
290
|
+
function dedupeSentFilesByFileId(existing, incoming) {
|
|
291
|
+
const knownFileIds = new Set();
|
|
292
|
+
for (const card of existing) {
|
|
293
|
+
if (card.fileId) {
|
|
294
|
+
knownFileIds.add(card.fileId);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
return incoming.filter((card) => {
|
|
298
|
+
if (knownFileIds.has(card.fileId)) {
|
|
299
|
+
return false;
|
|
300
|
+
}
|
|
301
|
+
knownFileIds.add(card.fileId);
|
|
302
|
+
return true;
|
|
303
|
+
});
|
|
304
|
+
}
|
|
259
305
|
export function appendRunCrossTaskSentFiles(sentFiles, explicitRunCrossTaskContext) {
|
|
260
306
|
const context = asyncLocalStorage.getStore() ?? null;
|
|
261
307
|
const runCrossTaskContext = explicitRunCrossTaskContext ?? context?.runCrossTaskContext;
|
|
262
308
|
const normalizedSentFiles = sentFiles
|
|
263
|
-
.map((
|
|
264
|
-
.filter((
|
|
309
|
+
.map((card) => normalizeSentFileCard(card))
|
|
310
|
+
.filter((card) => card !== null);
|
|
265
311
|
if (!runCrossTaskContext || normalizedSentFiles.length === 0) {
|
|
266
312
|
return runCrossTaskContext?.sentFiles ?? [];
|
|
267
313
|
}
|
|
268
314
|
const existing = Array.isArray(runCrossTaskContext.sentFiles) ? runCrossTaskContext.sentFiles : [];
|
|
269
|
-
const
|
|
315
|
+
const dedupedSentFiles = dedupeSentFilesByFileId(existing, normalizedSentFiles);
|
|
316
|
+
const merged = [...existing, ...dedupedSentFiles];
|
|
270
317
|
runCrossTaskContext.sentFiles = merged;
|
|
271
318
|
const sessionWithRef = Array.from(activeSessions.values()).find((session) => session.runCrossTaskContext === runCrossTaskContext);
|
|
272
319
|
if (sessionWithRef?.runCrossTaskContext) {
|
|
@@ -71,7 +71,7 @@ export function createXiaoyiGuiTool(ctx) {
|
|
|
71
71
|
wsManager.off("gui-agent-response", handler);
|
|
72
72
|
logger.error("超时: XiaoYi GUI Agent 操作超时(5分钟)", { toolCallId });
|
|
73
73
|
reject(new Error("XiaoYi GUI Agent 操作超时(5分钟)"));
|
|
74
|
-
},
|
|
74
|
+
}, 300000); // 5 minutes timeout
|
|
75
75
|
// Listen for GUI agent response events
|
|
76
76
|
const handler = (event) => {
|
|
77
77
|
// Check if this is the InvokeJarvisGUIAgentResponse we're waiting for
|
package/dist/src/types.d.ts
CHANGED
|
@@ -13,8 +13,10 @@ export interface XYChannelConfig {
|
|
|
13
13
|
export interface A2AJsonRpcRequest {
|
|
14
14
|
jsonrpc: "2.0";
|
|
15
15
|
method: string;
|
|
16
|
-
params
|
|
16
|
+
params?: A2ARequestParams;
|
|
17
17
|
id: string;
|
|
18
|
+
/** Top-level sessionId for clearContext/tasks/cancel (no params field) */
|
|
19
|
+
sessionId?: string;
|
|
18
20
|
}
|
|
19
21
|
export interface A2AJsonRpcResponse {
|
|
20
22
|
jsonrpc: "2.0";
|
|
@@ -66,7 +68,7 @@ export interface CrossDeviceTaskResultEvent {
|
|
|
66
68
|
sessionId: string;
|
|
67
69
|
code: string;
|
|
68
70
|
message: string;
|
|
69
|
-
sentFiles:
|
|
71
|
+
sentFiles: SentFileCard[];
|
|
70
72
|
status: "success" | "failed";
|
|
71
73
|
rawEvent: any;
|
|
72
74
|
}
|
|
@@ -76,13 +78,13 @@ export interface RunCrossTaskContext {
|
|
|
76
78
|
isDistributed: boolean;
|
|
77
79
|
networkId: string;
|
|
78
80
|
isSupportAgent: boolean;
|
|
79
|
-
sentFiles:
|
|
81
|
+
sentFiles: SentFileCard[];
|
|
80
82
|
rawContext: any;
|
|
81
83
|
}
|
|
82
|
-
export interface
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
84
|
+
export interface SentFileCard {
|
|
85
|
+
fileName: string;
|
|
86
|
+
fileId: string;
|
|
87
|
+
mimeType?: string;
|
|
86
88
|
}
|
|
87
89
|
export interface A2ATaskArtifactUpdateEvent {
|
|
88
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/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,
|